xref: /freebsd/sys/sys/power.h (revision e779891327b1d9b9ab10ba482e59f498790505a7)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2001 Mitsuru IWASAKI
5  * All rights reserved.
6  * Copyright (c) 2025 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 #ifdef _KERNEL
36 
37 #include <sys/_eventhandler.h>
38 #include <sys/types.h>
39 
40 /* Power management system type */
41 #define POWER_PM_TYPE_ACPI		0x01
42 #define POWER_PM_TYPE_NONE		0xff
43 
44 /* Commands for Power management function */
45 #define POWER_CMD_SUSPEND		0x00
46 
47 /*
48  * Sleep state.
49  *
50  * These are high-level sleep states that the system can enter.  They map to
51  * a specific generic sleep type (enum power_stype).
52  */
53 #define POWER_SLEEP_STATE_STANDBY	0x00
54 #define POWER_SLEEP_STATE_SUSPEND	0x01
55 #define POWER_SLEEP_STATE_HIBERNATE	0x02
56 
57 /*
58  * Sleep type.
59  *
60  * These are the specific generic methods of entering a sleep state.  E.g.
61  * POWER_SLEEP_STATE_SUSPEND could be set to enter either suspend-to-RAM (which
62  * is S3 on ACPI systems), or suspend-to-idle (S0ix on ACPI systems).  This
63  * would be done through the kern.power.suspend sysctl.
64  */
65 enum power_stype {
66 	POWER_STYPE_AWAKE,
67 	POWER_STYPE_STANDBY,
68 	POWER_STYPE_SUSPEND_TO_MEM,
69 	POWER_STYPE_SUSPEND_TO_IDLE,
70 	POWER_STYPE_HIBERNATE,
71 	POWER_STYPE_POWEROFF,
72 	POWER_STYPE_COUNT,
73 	POWER_STYPE_UNKNOWN,
74 };
75 
76 static const char * const power_stype_names[POWER_STYPE_COUNT] = {
77 	[POWER_STYPE_AWAKE]		= "awake",
78 	[POWER_STYPE_STANDBY]		= "standby",
79 	[POWER_STYPE_SUSPEND_TO_MEM]	= "s2mem",
80 	[POWER_STYPE_SUSPEND_TO_IDLE]	= "s2idle",
81 	[POWER_STYPE_HIBERNATE]		= "hibernate",
82 	[POWER_STYPE_POWEROFF]		= "poweroff",
83 };
84 
85 extern enum power_stype	 power_standby_stype;
86 extern enum power_stype	 power_suspend_stype;
87 extern enum power_stype	 power_hibernate_stype;
88 
89 extern enum power_stype	 power_name_to_stype(const char *_name);
90 extern const char	*power_stype_to_name(enum power_stype _stype);
91 
92 typedef int (*power_pm_fn_t)(u_long _cmd, void* _arg, enum power_stype _stype);
93 extern int	 power_pm_register(u_int _pm_type, power_pm_fn_t _pm_fn,
94 			void *_pm_arg,
95 			bool _pm_supported[static POWER_STYPE_COUNT]);
96 extern u_int	 power_pm_get_type(void);
97 extern void	 power_pm_suspend(int);
98 
99 /*
100  * System power API.
101  */
102 #define POWER_PROFILE_PERFORMANCE        0
103 #define POWER_PROFILE_ECONOMY            1
104 
105 extern int	power_profile_get_state(void);
106 extern void	power_profile_set_state(int);
107 
108 typedef void (*power_profile_change_hook)(void *, int);
109 EVENTHANDLER_DECLARE(power_profile_change, power_profile_change_hook);
110 
111 #endif	/* _KERNEL */
112 #endif	/* !_SYS_POWER_H_ */
113