Project

General

Profile

Statistics
| Revision:

root / lab4 / .minix-src / include / sys / power.h @ 13

History | View | Annotate | Download (9.1 KB)

1 13 up20180614
/*        $NetBSD: power.h,v 1.20 2015/01/06 15:39:54 bouyer 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
 *        Radio switch                This is e.g. the switch of the transmitter
87
 *                                 of a wifi interface. We know if it is
88
 *                                on or off.
89
 *
90
 */
91
92
#define        PSWITCH_TYPE_POWER        0        /* power button */
93
#define        PSWITCH_TYPE_SLEEP        1        /* sleep button */
94
#define        PSWITCH_TYPE_LID        2        /* lid switch */
95
#define        PSWITCH_TYPE_RESET        3        /* reset button */
96
#define        PSWITCH_TYPE_ACADAPTER        4        /* AC adapter presence */
97
#define        PSWITCH_TYPE_HOTKEY        5        /* hotkey button */
98
#define                PSWITCH_HK_DISPLAY_CYCLE        "display-cycle"
99
#define                PSWITCH_HK_LOCK_SCREEN                "lock-screen"
100
#define                PSWITCH_HK_BATTERY_INFO                "battery-info"
101
#define                PSWITCH_HK_EJECT_BUTTON                "eject-button"
102
#define                PSWITCH_HK_ZOOM_BUTTON                "zoom-button"
103
#define                PSWITCH_HK_VENDOR_BUTTON        "vendor-button"
104
#ifndef THINKPAD_NORMAL_HOTKEYS
105
#define                PSWITCH_HK_FNF1_BUTTON                "fnf1-button"
106
#define                PSWITCH_HK_WIRELESS_BUTTON        "wireless-button"
107
#define                PSWITCH_HK_WWAN_BUTTON                "wWAN-button"
108
#define                PSWITCH_HK_POINTER_BUTTON        "pointer-button"
109
#define                PSWITCH_HK_FNF10_BUTTON                "fnf10-button"
110
#define                PSWITCH_HK_FNF11_BUTTON                "fnf11-button"
111
#define                PSWITCH_HK_BRIGHTNESS_UP        "brightness-up"
112
#define                PSWITCH_HK_BRIGHTNESS_DOWN        "brightness-down"
113
#define                PSWITCH_HK_THINKLIGHT                "thinklight"
114
#define                PSWITCH_HK_VOLUME_UP                "volume-up"
115
#define                PSWITCH_HK_VOLUME_DOWN                "volume-down"
116
#define                PSWITCH_HK_VOLUME_MUTE                "volume-mute"
117
#endif /* THINKPAD_NORMAL_HOTKEYS */
118
#define        PSWITCH_TYPE_RADIO        6        /* radio switch */
119
120
#define        PSWITCH_EVENT_PRESSED        0        /* button pressed, lid closed, AC off */
121
#define        PSWITCH_EVENT_RELEASED        1        /* button released, lid open, AC on */
122
123
/*
124
 * This structure describes the state of a power switch.
125
 */
126
struct pswitch_state {
127
        char        psws_name[16];                /* power switch name */
128
        int32_t        psws_type;                /* type of switch (qualifier) */
129
        int32_t        psws_state;                /* state of the switch/event */
130
};
131
132
/*
133
 * envsys(4) events:
134
 *
135
 * envsys events are sent by the sysmon envsys framework when
136
 * a warning or critical condition happens in a sensor.
137
 *
138
 * We define the folowing types of envsys events:
139
 *
140
 *        sensor temperature        To handle temperature sensors.
141
 *
142
 *        sensor voltage                To handle voltage sensors (AC/DC).
143
 *
144
 *        sensor power                To handle power sensors (W/Ampere).
145
 *
146
 *        sensor resistance        To handle resistance sensors (Ohms).
147
 *
148
 *        sensor battery                To handle battery sensors (Ah/Wh).
149
 *
150
 *        sensor fan                To handle fan sensors.
151
 *
152
 *        sensor drive                To handle drive sensors.
153
 *
154
 *         sensor indicator        To handle indicator/integer sensors.
155
 */
156
157
#define PENVSYS_TYPE_TEMP                10
158
#define PENVSYS_TYPE_VOLTAGE                11
159
#define PENVSYS_TYPE_POWER                12
160
#define PENVSYS_TYPE_RESISTANCE         13
161
#define PENVSYS_TYPE_BATTERY                14
162
#define PENVSYS_TYPE_FAN                15
163
#define PENVSYS_TYPE_DRIVE                16
164
#define PENVSYS_TYPE_INDICATOR                17
165
166
/*
167
 * The following events apply for temperatures, power, resistance,
168
 * voltages, battery and fan sensors:
169
 *
170
 *         PENVSYS_EVENT_CRITICAL                A critical limit.
171
 *
172
 *         PENVSYS_EVENT_CRITOVER                A critical over limit.
173
 *
174
 *         PENVSYS_EVENT_CRITUNDER                A critical under limit.
175
 *
176
 *         PENVSYS_EVENT_WARNOVER                A warning under limit.
177
 *
178
 *         PENVSYS_EVENT_WARNUNDER                A warning over limit.
179
 *
180
 * The folowing event applies to all sensors, when the state is
181
 * valid or the warning or critical limit is not valid anymore:
182
 *
183
 *         PENVSYS_EVENT_NORMAL                Normal state in the sensor.
184
 */
185
186
#define PENVSYS_EVENT_NORMAL                 90
187
#define PENVSYS_EVENT_CRITICAL                 100
188
#define PENVSYS_EVENT_CRITOVER                 110
189
#define PENVSYS_EVENT_CRITUNDER         120
190
#define PENVSYS_EVENT_WARNOVER                 130
191
#define PENVSYS_EVENT_WARNUNDER         140
192
193
/*
194
 * The following events apply for battery sensors:
195
 *
196
 *         PENVSYS_EVENT_BATT_CRIT                User critical capacity.
197
 *
198
 *        PENVSYS_EVENT_BATT_WARN                User warning capacity.
199
 *
200
 *        PENVSYS_EVENT_BATT_HIGH                User high capacity.
201
 *
202
 *        PENVSYS_EVENT_BATT_MAX                User maximum capacity.
203
 *
204
 *         PENVSYS_EVENT_LOW_POWER                AC Adapter is OFF and all batteries
205
 *                                         are discharged.
206
 */
207
208
#define PENVSYS_EVENT_BATT_CRIT                170
209
#define PENVSYS_EVENT_BATT_WARN                175
210
#define PENVSYS_EVENT_BATT_HIGH                177
211
#define PENVSYS_EVENT_BATT_MAX                178
212
#define PENVSYS_EVENT_LOW_POWER                180
213
214
/*
215
 * The following event apply for battery state and drive sensors:
216
 *
217
 *         PENVSYS_EVENT_STATE_CHANGED        State has changed.
218
 *
219
 */
220
#define PENVSYS_EVENT_STATE_CHANGED         190
221
222
/*
223
 * The following events are used internally to associate multiple
224
 * external states with a single event monitor
225
 */
226
#define PENVSYS_EVENT_LIMITS                200
227
#define PENVSYS_EVENT_CAPACITY                210
228
229
/*
230
 * The following pseudo-event is used to force refreshing of a
231
 * sensor that provides rnd(4) entropy, even if the sensor is not
232
 * otherwise being monitored.
233
 */
234
#define PENVSYS_EVENT_NULL                220
235
236
/*
237
 * This structure defines the properties of an envsys event.
238
 */
239
struct penvsys_state {
240
        char        pes_dvname[16];                /* device name */
241
        char        pes_sensname[32];        /* sensor name */
242
        char        pes_statedesc[64];        /* sensor state description */
243
        int32_t        pes_type;                /* envsys power type */
244
};
245
246
/*
247
 * Power management event messages:
248
 *
249
 * We ensure that a message is always exactly 32 bytes long, so that
250
 * userland doesn't need to issue multiple reads to get a single event.
251
 */
252
#define        POWER_EVENT_MSG_SIZE        32
253
254
#define        POWER_EVENT_SWITCH_STATE_CHANGE                0
255
#define POWER_EVENT_ENVSYS_STATE_CHANGE                1
256
257
typedef struct power_event {
258
        int32_t                pev_type;        /* power event type */
259
        union {
260
                int32_t         _pev_d_space[(POWER_EVENT_MSG_SIZE /
261
                                       sizeof(int32_t)) - 1];
262
263
                /*
264
                 * This field is used for:
265
                 *
266
                 *         POWER_EVENT_SWITCH_STATE_CHANGE
267
                 */
268
                struct pswitch_state _pev_d_switch;
269
        } _pev_data;
270
} power_event_t;
271
272
#define pev_switch        _pev_data._pev_d_switch
273
274
#define POWER_EVENT_RECVDICT        _IOWR('P', 1, struct plistref)
275
276
/*
277
 * POWER_IOC_GET_TYPE:
278
 *
279
 *        Get the power management back-end type.
280
 */
281
struct power_type {
282
        char        power_type[32];
283
};
284
#define        POWER_IOC_GET_TYPE        _IOR('P', 0, struct power_type)
285
#define        POWER_IOC_GET_TYPE_WITH_LOSSAGE _IOR('P', 0, sizeof(struct power_type))
286
287
#endif /* _SYS_POWER_H_ */