1 /* $NetBSD: power.h,v 1.17 2012/07/15 18:31:35 pgoyette Exp $ */ 2 3 /* 4 * Copyright (c) 2003 Wasabi Systems, Inc. 5 * All rights reserved. 6 * 7 * Written by Jason R. Thorpe for Wasabi Systems, Inc. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed for the NetBSD Project by 20 * Wasabi Systems, Inc. 21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22 * or promote products derived from this software without specific prior 23 * written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 * POSSIBILITY OF SUCH DAMAGE. 36 */ 37 38 /* 39 * Definitions for power management. 40 */ 41 42 #ifndef _SYS_POWER_H_ 43 #define _SYS_POWER_H_ 44 45 #include <sys/ioccom.h> 46 47 #ifndef _KERNEL 48 #include <stdint.h> 49 #endif 50 51 /* 52 * Power Switches: 53 * 54 * Power switches are devices on the system that are used by the system 55 * operator to cause certain types of power management events to happen. 56 * This may be the closing of a laptop lid, the pressing of a power button, 57 * or some other type of user-initiated hardware event. 58 * 59 * We define the following types of power switches: 60 * 61 * Power button This is the "on/off" button on a system, 62 * or another button which provides a similar 63 * function. If there is no power management 64 * daemon present, an event on this button will 65 * cause a semi-graceful shutdown of the system 66 * to occur. This kind of button doesn't keep 67 * state; we only know (care) if an event occurs. 68 * 69 * Reset button This is the "reset" button on a system, or 70 * another button which provides a similar 71 * function. If there is no power management 72 * daemon present, an event on this button will 73 * cause a semi-graceful reboot of the system 74 * to occur. This kind of button doesn't keep 75 * state; we only know (care) if an event occurs. 76 * 77 * Sleep button This is a button which is dedicated to a 78 * "sleep" function. This kind of button doesn't 79 * keep state; we only know (care) if an event 80 * occurs. 81 * 82 * Lid switch This is e.g. the lid of a laptop. This kind 83 * of switch has state. We know if it is open 84 * or closed. 85 * 86 */ 87 88 #define PSWITCH_TYPE_POWER 0 /* power button */ 89 #define PSWITCH_TYPE_SLEEP 1 /* sleep button */ 90 #define PSWITCH_TYPE_LID 2 /* lid switch */ 91 #define PSWITCH_TYPE_RESET 3 /* reset button */ 92 #define PSWITCH_TYPE_ACADAPTER 4 /* AC adapter presence */ 93 #define PSWITCH_TYPE_HOTKEY 5 /* hotkey button */ 94 #define PSWITCH_HK_DISPLAY_CYCLE "display-cycle" 95 #define PSWITCH_HK_LOCK_SCREEN "lock-screen" 96 #define PSWITCH_HK_BATTERY_INFO "battery-info" 97 #define PSWITCH_HK_EJECT_BUTTON "eject-button" 98 #define PSWITCH_HK_ZOOM_BUTTON "zoom-button" 99 #define PSWITCH_HK_VENDOR_BUTTON "vendor-button" 100 101 #define PSWITCH_EVENT_PRESSED 0 /* button pressed, lid closed, AC off */ 102 #define PSWITCH_EVENT_RELEASED 1 /* button released, lid open, AC on */ 103 104 /* 105 * This structure describes the state of a power switch. 106 */ 107 struct pswitch_state { 108 char psws_name[16]; /* power switch name */ 109 int32_t psws_type; /* type of switch (qualifier) */ 110 int32_t psws_state; /* state of the switch/event */ 111 }; 112 113 /* 114 * envsys(4) events: 115 * 116 * envsys events are sent by the sysmon envsys framework when 117 * a warning or critical condition happens in a sensor. 118 * 119 * We define the folowing types of envsys events: 120 * 121 * sensor temperature To handle temperature sensors. 122 * 123 * sensor voltage To handle voltage sensors (AC/DC). 124 * 125 * sensor power To handle power sensors (W/Ampere). 126 * 127 * sensor resistance To handle resistance sensors (Ohms). 128 * 129 * sensor battery To handle battery sensors (Ah/Wh). 130 * 131 * sensor fan To handle fan sensors. 132 * 133 * sensor drive To handle drive sensors. 134 * 135 * sensor indicator To handle indicator/integer sensors. 136 */ 137 138 #define PENVSYS_TYPE_TEMP 10 139 #define PENVSYS_TYPE_VOLTAGE 11 140 #define PENVSYS_TYPE_POWER 12 141 #define PENVSYS_TYPE_RESISTANCE 13 142 #define PENVSYS_TYPE_BATTERY 14 143 #define PENVSYS_TYPE_FAN 15 144 #define PENVSYS_TYPE_DRIVE 16 145 #define PENVSYS_TYPE_INDICATOR 17 146 147 /* 148 * The following events apply for temperatures, power, resistance, 149 * voltages, battery and fan sensors: 150 * 151 * PENVSYS_EVENT_CRITICAL A critical limit. 152 * 153 * PENVSYS_EVENT_CRITOVER A critical over limit. 154 * 155 * PENVSYS_EVENT_CRITUNDER A critical under limit. 156 * 157 * PENVSYS_EVENT_WARNOVER A warning under limit. 158 * 159 * PENVSYS_EVENT_WARNUNDER A warning over limit. 160 * 161 * The folowing event applies to all sensors, when the state is 162 * valid or the warning or critical limit is not valid anymore: 163 * 164 * PENVSYS_EVENT_NORMAL Normal state in the sensor. 165 */ 166 167 #define PENVSYS_EVENT_NORMAL 90 168 #define PENVSYS_EVENT_CRITICAL 100 169 #define PENVSYS_EVENT_CRITOVER 110 170 #define PENVSYS_EVENT_CRITUNDER 120 171 #define PENVSYS_EVENT_WARNOVER 130 172 #define PENVSYS_EVENT_WARNUNDER 140 173 174 /* 175 * The following events apply for battery sensors: 176 * 177 * PENVSYS_EVENT_BATT_CRIT User critical capacity. 178 * 179 * PENVSYS_EVENT_BATT_WARN User warning capacity. 180 * 181 * PENVSYS_EVENT_BATT_HIGH User high capacity. 182 * 183 * PENVSYS_EVENT_BATT_MAX User maximum capacity. 184 * 185 * PENVSYS_EVENT_LOW_POWER AC Adapter is OFF and all batteries 186 * are discharged. 187 */ 188 189 #define PENVSYS_EVENT_BATT_CRIT 170 190 #define PENVSYS_EVENT_BATT_WARN 175 191 #define PENVSYS_EVENT_BATT_HIGH 177 192 #define PENVSYS_EVENT_BATT_MAX 178 193 #define PENVSYS_EVENT_LOW_POWER 180 194 195 /* 196 * The following event apply for battery state and drive sensors: 197 * 198 * PENVSYS_EVENT_STATE_CHANGED State has changed. 199 * 200 */ 201 #define PENVSYS_EVENT_STATE_CHANGED 190 202 203 /* 204 * The following events are used internally to associate multiple 205 * external states with a single event monitor 206 */ 207 #define PENVSYS_EVENT_LIMITS 200 208 #define PENVSYS_EVENT_CAPACITY 210 209 210 /* 211 * The following pseudo-event is used to force refreshing of a 212 * sensor that provides rnd(4) entropy, even if the sensor is not 213 * otherwise being monitored. 214 */ 215 #define PENVSYS_EVENT_NULL 220 216 217 /* 218 * This structure defines the properties of an envsys event. 219 */ 220 struct penvsys_state { 221 char pes_dvname[16]; /* device name */ 222 char pes_sensname[32]; /* sensor name */ 223 char pes_statedesc[64]; /* sensor state description */ 224 int32_t pes_type; /* envsys power type */ 225 }; 226 227 /* 228 * Power management event messages: 229 * 230 * We ensure that a message is always exactly 32 bytes long, so that 231 * userland doesn't need to issue multiple reads to get a single event. 232 */ 233 #define POWER_EVENT_MSG_SIZE 32 234 235 #define POWER_EVENT_SWITCH_STATE_CHANGE 0 236 #define POWER_EVENT_ENVSYS_STATE_CHANGE 1 237 238 typedef struct power_event { 239 int32_t pev_type; /* power event type */ 240 union { 241 int32_t _pev_d_space[(POWER_EVENT_MSG_SIZE / 242 sizeof(int32_t)) - 1]; 243 244 /* 245 * This field is used for: 246 * 247 * POWER_EVENT_SWITCH_STATE_CHANGE 248 */ 249 struct pswitch_state _pev_d_switch; 250 } _pev_data; 251 } power_event_t; 252 253 #define pev_switch _pev_data._pev_d_switch 254 255 #define POWER_EVENT_RECVDICT _IOWR('P', 1, struct plistref) 256 257 /* 258 * POWER_IOC_GET_TYPE: 259 * 260 * Get the power management back-end type. 261 */ 262 struct power_type { 263 char power_type[32]; 264 }; 265 #define POWER_IOC_GET_TYPE _IOR('P', 0, struct power_type) 266 #define POWER_IOC_GET_TYPE_WITH_LOSSAGE _IOR('P', 0, sizeof(struct power_type)) 267 268 #endif /* _SYS_POWER_H_ */ 269