1 /* $NetBSD: power.h,v 1.15 2010/02/15 22:32:04 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 /* 48 * Power Switches: 49 * 50 * Power switches are devices on the system that are used by the system 51 * operator to cause certain types of power management events to happen. 52 * This may be the closing of a laptop lid, the pressing of a power button, 53 * or some other type of user-initiated hardware event. 54 * 55 * We define the following types of power switches: 56 * 57 * Power button This is the "on/off" button on a system, 58 * or another button which provides a similar 59 * function. If there is no power management 60 * daemon present, an event on this button will 61 * cause a semi-graceful shutdown of the system 62 * to occur. This kind of button doesn't keep 63 * state; we only know (care) if an event occurs. 64 * 65 * Reset button This is the "reset" button on a system, or 66 * another button which provides a similar 67 * function. If there is no power management 68 * daemon present, an event on this button will 69 * cause a semi-graceful reboot of the system 70 * to occur. This kind of button doesn't keep 71 * state; we only know (care) if an event occurs. 72 * 73 * Sleep button This is a button which is dedicated to a 74 * "sleep" function. This kind of button doesn't 75 * keep state; we only know (care) if an event 76 * occurs. 77 * 78 * Lid switch This is e.g. the lid of a laptop. This kind 79 * of switch has state. We know if it is open 80 * or closed. 81 * 82 */ 83 84 #define PSWITCH_TYPE_POWER 0 /* power button */ 85 #define PSWITCH_TYPE_SLEEP 1 /* sleep button */ 86 #define PSWITCH_TYPE_LID 2 /* lid switch */ 87 #define PSWITCH_TYPE_RESET 3 /* reset button */ 88 #define PSWITCH_TYPE_ACADAPTER 4 /* AC adapter presence */ 89 #define PSWITCH_TYPE_HOTKEY 5 /* hotkey button */ 90 #define PSWITCH_HK_DISPLAY_CYCLE "display-cycle" 91 #define PSWITCH_HK_LOCK_SCREEN "lock-screen" 92 #define PSWITCH_HK_BATTERY_INFO "battery-info" 93 #define PSWITCH_HK_EJECT_BUTTON "eject-button" 94 #define PSWITCH_HK_ZOOM_BUTTON "zoom-button" 95 #define PSWITCH_HK_VENDOR_BUTTON "vendor-button" 96 97 #define PSWITCH_EVENT_PRESSED 0 /* button pressed, lid closed, AC off */ 98 #define PSWITCH_EVENT_RELEASED 1 /* button released, lid open, AC on */ 99 100 /* 101 * This structure describes the state of a power switch. 102 */ 103 struct pswitch_state { 104 char psws_name[16]; /* power switch name */ 105 int32_t psws_type; /* type of switch (qualifier) */ 106 int32_t psws_state; /* state of the switch/event */ 107 }; 108 109 /* 110 * envsys(4) events: 111 * 112 * envsys events are sent by the sysmon envsys framework when 113 * a warning or critical condition happens in a sensor. 114 * 115 * We define the folowing types of envsys events: 116 * 117 * sensor temperature To handle temperature sensors. 118 * 119 * sensor voltage To handle voltage sensors (AC/DC). 120 * 121 * sensor power To handle power sensors (W/Ampere). 122 * 123 * sensor resistance To handle resistance sensors (Ohms). 124 * 125 * sensor battery To handle battery sensors (Ah/Wh). 126 * 127 * sensor fan To handle fan sensors. 128 * 129 * sensor drive To handle drive sensors. 130 * 131 * sensor indicator To handle indicator/integer sensors. 132 */ 133 134 #define PENVSYS_TYPE_TEMP 10 135 #define PENVSYS_TYPE_VOLTAGE 11 136 #define PENVSYS_TYPE_POWER 12 137 #define PENVSYS_TYPE_RESISTANCE 13 138 #define PENVSYS_TYPE_BATTERY 14 139 #define PENVSYS_TYPE_FAN 15 140 #define PENVSYS_TYPE_DRIVE 16 141 #define PENVSYS_TYPE_INDICATOR 17 142 143 /* 144 * The following events apply for temperatures, power, resistance, 145 * voltages, battery and fan sensors: 146 * 147 * PENVSYS_EVENT_CRITICAL A critical limit. 148 * 149 * PENVSYS_EVENT_CRITOVER A critical over limit. 150 * 151 * PENVSYS_EVENT_CRITUNDER A critical under limit. 152 * 153 * PENVSYS_EVENT_WARNOVER A warning under limit. 154 * 155 * PENVSYS_EVENT_WARNUNDER A warning over limit. 156 * 157 * The folowing event applies to all sensors, when the state is 158 * valid or the warning or critical limit is not valid anymore: 159 * 160 * PENVSYS_EVENT_NORMAL Normal state in the sensor. 161 */ 162 163 #define PENVSYS_EVENT_NORMAL 90 164 #define PENVSYS_EVENT_CRITICAL 100 165 #define PENVSYS_EVENT_CRITOVER 110 166 #define PENVSYS_EVENT_CRITUNDER 120 167 #define PENVSYS_EVENT_WARNOVER 130 168 #define PENVSYS_EVENT_WARNUNDER 140 169 170 /* 171 * The following events apply for battery sensors: 172 * 173 * PENVSYS_EVENT_BATT_CRIT User critical capacity. 174 * 175 * PENVSYS_EVENT_BATT_WARN User warning capacity. 176 * 177 * PENVSYS_EVENT_BATT_HIGH User high capacity. 178 * 179 * PENVSYS_EVENT_BATT_MAX User maximum capacity. 180 * 181 * PENVSYS_EVENT_LOW_POWER AC Adapter is OFF and all batteries 182 * are discharged. 183 */ 184 185 #define PENVSYS_EVENT_BATT_CRIT 170 186 #define PENVSYS_EVENT_BATT_WARN 175 187 #define PENVSYS_EVENT_BATT_HIGH 177 188 #define PENVSYS_EVENT_BATT_MAX 178 189 #define PENVSYS_EVENT_LOW_POWER 180 190 191 /* 192 * The following event apply for battery state and drive sensors: 193 * 194 * PENVSYS_EVENT_STATE_CHANGED State has changed. 195 * 196 */ 197 #define PENVSYS_EVENT_STATE_CHANGED 190 198 199 /* 200 * The following events are used internally to associate multiple 201 * external states with a single event monitor 202 */ 203 #define PENVSYS_EVENT_LIMITS 200 204 #define PENVSYS_EVENT_CAPACITY 210 205 206 /* 207 * This structure defines the properties of an envsys event. 208 */ 209 struct penvsys_state { 210 char pes_dvname[16]; /* device name */ 211 char pes_sensname[32]; /* sensor name */ 212 char pes_statedesc[64]; /* sensor state description */ 213 int32_t pes_type; /* envsys power type */ 214 }; 215 216 /* 217 * Power management event messages: 218 * 219 * We ensure that a message is always exactly 32 bytes long, so that 220 * userland doesn't need to issue multiple reads to get a single event. 221 */ 222 #define POWER_EVENT_MSG_SIZE 32 223 224 #define POWER_EVENT_SWITCH_STATE_CHANGE 0 225 #define POWER_EVENT_ENVSYS_STATE_CHANGE 1 226 227 typedef struct power_event { 228 int32_t pev_type; /* power event type */ 229 union { 230 int32_t _pev_d_space[(POWER_EVENT_MSG_SIZE / 231 sizeof(int32_t)) - 1]; 232 233 /* 234 * This field is used for: 235 * 236 * POWER_EVENT_SWITCH_STATE_CHANGE 237 */ 238 struct pswitch_state _pev_d_switch; 239 } _pev_data; 240 } power_event_t; 241 242 #define pev_switch _pev_data._pev_d_switch 243 244 #define POWER_EVENT_RECVDICT _IOWR('P', 1, struct plistref) 245 246 /* 247 * POWER_IOC_GET_TYPE: 248 * 249 * Get the power management back-end type. 250 */ 251 struct power_type { 252 char power_type[32]; 253 }; 254 #define POWER_IOC_GET_TYPE _IOR('P', 0, struct power_type) 255 #define POWER_IOC_GET_TYPE_WITH_LOSSAGE _IOR('P', 0, sizeof(struct power_type)) 256 257 #endif /* _SYS_POWER_H_ */ 258