1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2001 Mitsuru IWASAKI 5 * All rights reserved. 6 * Copyright (c) 2025-2026 The FreeBSD Foundation 7 * 8 * Portions of this software were developed by Aymeric Wibo 9 * <obiwac@freebsd.org> under sponsorship from the FreeBSD Foundation. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 33 #ifndef _SYS_POWER_H_ 34 #define _SYS_POWER_H_ 35 36 #include <sys/types.h> 37 #include <sys/ioccom.h> 38 39 /* 40 * Sleep state transition requests. 41 * 42 * These are high-level sleep states that the system can enter. They map to 43 * a specific generic sleep type (enum power_stype), depending on the 44 * kern.power.* sysctls. 45 */ 46 enum power_transition { 47 POWER_TRANSITION_STANDBY, 48 POWER_TRANSITION_SUSPEND, 49 POWER_TRANSITION_HIBERNATE, 50 POWER_TRANSITION_COUNT, 51 }; 52 53 /* 54 * Power ioctls. 55 */ 56 #define PIOTRANSITION _IOW('T', 1, uint32_t) 57 58 #ifdef _KERNEL 59 60 #include <sys/_eventhandler.h> 61 62 /* Power management system type */ 63 #define POWER_PM_TYPE_ACPI 0x01 64 #define POWER_PM_TYPE_NONE 0xff 65 66 /* Commands for Power management function */ 67 #define POWER_CMD_SUSPEND 0x00 68 69 /* 70 * Sleep type. 71 * 72 * These are the specific generic methods of entering a sleep state. E.g. 73 * POWER_TRANSITION_SUSPEND could be set to enter either firmware suspend (which 74 * is suspend-to-RAM or S3 on ACPI systems), or suspend-to-idle (S0ix on ACPI 75 * platforms). This would be done through the kern.power.suspend sysctl. 76 */ 77 enum power_stype { 78 POWER_STYPE_AWAKE, 79 POWER_STYPE_STANDBY, 80 POWER_STYPE_FW_SUSPEND, 81 POWER_STYPE_SUSPEND_TO_IDLE, 82 POWER_STYPE_FW_HIBERNATE, 83 POWER_STYPE_POWEROFF, 84 POWER_STYPE_COUNT, 85 POWER_STYPE_UNKNOWN, 86 }; 87 88 /* XXX NUL terminator is included in this number */ 89 #define POWER_STYPE_NAME_LEN 16 90 91 static const char power_stype_names[POWER_STYPE_COUNT][POWER_STYPE_NAME_LEN] = { 92 [POWER_STYPE_AWAKE] = "awake", 93 [POWER_STYPE_STANDBY] = "standby", 94 [POWER_STYPE_FW_SUSPEND] = "fw_suspend", 95 [POWER_STYPE_SUSPEND_TO_IDLE] = "suspend_to_idle", 96 [POWER_STYPE_FW_HIBERNATE] = "fw_hibernate", 97 [POWER_STYPE_POWEROFF] = "poweroff", 98 }; 99 100 extern enum power_stype power_standby_stype; 101 extern enum power_stype power_suspend_stype; 102 extern enum power_stype power_hibernate_stype; 103 104 extern enum power_stype power_name_to_stype(const char *_name); 105 extern const char *power_stype_to_name(enum power_stype _stype); 106 107 typedef int (*power_pm_fn_t)(u_long _cmd, void* _arg, enum power_stype _stype); 108 extern int power_pm_register(u_int _pm_type, power_pm_fn_t _pm_fn, 109 void *_pm_arg, 110 bool _pm_supported[static POWER_STYPE_COUNT]); 111 extern u_int power_pm_get_type(void); 112 extern int power_pm_suspend(enum power_transition _trans); 113 114 /* 115 * System power API. 116 */ 117 #define POWER_PROFILE_PERFORMANCE 0 118 #define POWER_PROFILE_ECONOMY 1 119 120 extern int power_profile_get_state(void); 121 extern void power_profile_set_state(int); 122 123 typedef void (*power_profile_change_hook)(void *, int); 124 EVENTHANDLER_DECLARE(power_profile_change, power_profile_change_hook); 125 126 #endif /* _KERNEL */ 127 #endif /* !_SYS_POWER_H_ */ 128