/*- * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2001 Mitsuru IWASAKI * All rights reserved. * Copyright (c) 2025-2026 The FreeBSD Foundation * * Portions of this software were developed by Aymeric Wibo * <obiwac@freebsd.org> under sponsorship from the FreeBSD Foundation. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef _SYS_POWER_H_ #define _SYS_POWER_H_ #include <sys/types.h> #include <sys/ioccom.h> /* * Sleep state transition requests. * * These are high-level sleep states that the system can enter. They map to * a specific generic sleep type (enum power_stype), depending on the * kern.power.* sysctls. */ enum power_transition { POWER_TRANSITION_STANDBY, POWER_TRANSITION_SUSPEND, POWER_TRANSITION_HIBERNATE, POWER_TRANSITION_COUNT, }; /* * Power ioctls. */ #define PIOTRANSITION _IOW('T', 1, uint32_t) #ifdef _KERNEL #include <sys/_eventhandler.h> /* Power management system type */ #define POWER_PM_TYPE_ACPI 0x01 #define POWER_PM_TYPE_NONE 0xff /* Commands for Power management function */ #define POWER_CMD_SUSPEND 0x00 /* * Sleep type. * * These are the specific generic methods of entering a sleep state. E.g. * POWER_TRANSITION_SUSPEND could be set to enter either firmware suspend (which * is suspend-to-RAM or S3 on ACPI systems), or suspend-to-idle (S0ix on ACPI * platforms). This would be done through the kern.power.suspend sysctl. */ enum power_stype { POWER_STYPE_AWAKE, POWER_STYPE_STANDBY, POWER_STYPE_FW_SUSPEND, POWER_STYPE_SUSPEND_TO_IDLE, POWER_STYPE_FW_HIBERNATE, POWER_STYPE_POWEROFF, POWER_STYPE_UNKNOWN, POWER_STYPE_COUNT = POWER_STYPE_UNKNOWN, }; /* XXX NUL terminator is included in this number */ #define POWER_STYPE_NAME_LEN 16 static const char power_stype_names[POWER_STYPE_COUNT][POWER_STYPE_NAME_LEN] = { [POWER_STYPE_AWAKE] = "awake", [POWER_STYPE_STANDBY] = "standby", [POWER_STYPE_FW_SUSPEND] = "fw_suspend", [POWER_STYPE_SUSPEND_TO_IDLE] = "suspend_to_idle", [POWER_STYPE_FW_HIBERNATE] = "fw_hibernate", [POWER_STYPE_POWEROFF] = "poweroff", }; extern enum power_stype power_standby_stype; extern enum power_stype power_suspend_stype; extern enum power_stype power_hibernate_stype; extern enum power_stype power_name_to_stype(const char *_name); extern const char *power_stype_to_name(enum power_stype _stype); typedef int (*power_pm_fn_t)(u_long _cmd, void* _arg, enum power_stype _stype); extern int power_pm_register(u_int _pm_type, power_pm_fn_t _pm_fn, void *_pm_arg, const bool _pm_supported[static POWER_STYPE_COUNT]); extern u_int power_pm_get_type(void); extern int power_pm_suspend(enum power_transition _trans); /* * System power API. */ #define POWER_PROFILE_PERFORMANCE 0 #define POWER_PROFILE_ECONOMY 1 extern int power_profile_get_state(void); extern void power_profile_set_state(int); typedef void (*power_profile_change_hook)(void *, int); EVENTHANDLER_DECLARE(power_profile_change, power_profile_change_hook); #endif /* _KERNEL */ #endif /* !_SYS_POWER_H_ */