apmvar.h revision 1.1 1 /* $NetBSD: apmvar.h,v 1.1 1996/08/25 23:39:50 jtk Exp $ */
2 /*
3 * Copyright (c) 1995 John T. Kohl
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
21 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 */
30 #ifndef __I386_APM_H__
31 #define __I386_APM_H__
32
33 /* Advanced Power Management (v1.0 and v1.1 specification)
34 * functions/defines/etc.
35 */
36 #define APM_BIOS_FNCODE (0x53)
37 #define APM_SYSTEM_BIOS (0x15)
38 #define APM_BIOS_FN(x) ((APM_BIOS_FNCODE<<8)|(x))
39 /*
40 * APM info word from boot loader
41 */
42 #define APM_MAJOR_VERS(info) (((info)&0xff00)>>8)
43 #define APM_MINOR_VERS(info) ((info)&0xff)
44 #define APM_16BIT_SUPPORTED 0x00010000
45 #define APM_32BIT_SUPPORTED 0x00020000
46 #define APM_IDLE_SLOWS 0x00040000
47 #define APM_BIOS_PM_DISABLED 0x00080000
48 #define APM_BIOS_PM_DISENGAGED 0x00100000
49
50 #define APM_ERR_CODE(regs) (((regs)->ax & 0xff00) >> 8)
51 #define APM_ERR_PM_DISABLED 0x01
52 #define APM_ERR_REALALREADY 0x02
53 #define APM_ERR_NOTCONN 0x03
54 #define APM_ERR_16ALREADY 0x05
55 #define APM_ERR_16NOTSUPP 0x06
56 #define APM_ERR_32ALREADY 0x07
57 #define APM_ERR_32NOTSUPP 0x08
58 #define APM_ERR_UNRECOG_DEV 0x09
59 #define APM_ERR_ERANGE 0x0A
60 #define APM_ERR_NOTENGAGED 0x0B
61 #define APM_ERR_UNABLE 0x60
62 #define APM_ERR_NOEVENTS 0x80
63 #define APM_ERR_NOT_PRESENT 0x86
64
65 #define APM_DEV_APM_BIOS 0x0000
66 #define APM_DEV_ALLDEVS 0x0001
67 /* device classes are high byte; device IDs go in low byte */
68 #define APM_DEV_DISPLAY(x) (0x0100|((x)&0xff))
69 #define APM_DEV_DISK(x) (0x0200|((x)&0xff))
70 #define APM_DEV_PARALLEL(x) (0x0300|((x)&0xff))
71 #define APM_DEV_SERIAL(x) (0x0400|((x)&0xff))
72 #define APM_DEV_NETWORK(x) (0x0500|((x)&0xff))
73 #define APM_DEV_PCMCIA(x) (0x0600|((x)&0xff))
74 #define APM_DEV_ALLUNITS 0xff
75
76 #define APM_INSTALLATION_CHECK 0x00 /* int15 only */
77 #define APM_REALMODE_CONNECT 0x01 /* int15 only */
78 #define APM_16BIT_CONNECT 0x02 /* int15 only */
79 #define APM_32BIT_CONNECT 0x03 /* int15 only */
80 #define APM_DISCONNECT 0x04 /* %bx = APM_DEV_APM_BIOS */
81 #define APM_CPU_IDLE 0x05
82 #define APM_CPU_BUSY 0x06
83 #define APM_SET_PWR_STATE 0x07
84 #define APM_SYS_READY 0x0000 /* %cx */
85 #define APM_SYS_STANDBY 0x0001
86 #define APM_SYS_SUSPEND 0x0002
87 #define APM_SYS_OFF 0x0003
88 #define APM_LASTREQ_INPROG 0x0004
89 #define APM_LASTREQ_REJECTED 0x0005
90
91 /* system standby is device ID (%bx) 0x0001, APM_SYS_STANDBY */
92 /* system suspend is device ID (%bx) 0x0001, APM_SYS_SUSPEND */
93
94 #define APM_PWR_MGT_ENABLE 0x08
95 #define APM_MGT_ALL 0xffff /* %bx */
96 #define APM_MGT_DISABLE 0x0 /* %cx */
97 #define APM_MGT_ENABLE 0x1
98
99 #define APM_SYSTEM_DEFAULTS 0x09
100 #define APM_DEFAULTS_ALL 0xffff /* %bx */
101
102 #define APM_POWER_STATUS 0x0a
103 #define APM_AC_OFF 0x00
104 #define APM_AC_ON 0x01
105 #define APM_AC_BACKUP 0x02
106 #define APM_AC_UNKNOWN 0xff
107 #define APM_BATT_HIGH 0x00
108 #define APM_BATT_LOW 0x01
109 #define APM_BATT_CRITICAL 0x02
110 #define APM_BATT_CHARGING 0x03
111 #define APM_BATT_UNKNOWN 0xff
112 #define APM_BATT_FLAG_HIGH 0x01
113 #define APM_BATT_FLAG_LOW 0x02
114 #define APM_BATT_FLAG_CRITICAL 0x04
115 #define APM_BATT_FLAG_CHARGING 0x08
116 #define APM_BATT_FLAG_NOBATTERY 0x80
117 #define APM_BATT_LIFE_UNKNOWN 0xff
118 #define BATT_STATE(regp) ((regp)->bx & 0xff)
119 #define BATT_FLAGS(regp) (((regp)->cx & 0xff00) >> 8)
120 #define AC_STATE(regp) (((regp)->bx & 0xff00) >> 8)
121 #define BATT_LIFE(regp) ((regp)->cx & 0xff) /* in % */
122 /* BATT_REMAINING returns minutes remaining */
123 #define BATT_REMAINING(regp) (((regp)->dx & 0x8000) ? \
124 ((regp)->dx & 0x7fff) : \
125 ((regp)->dx & 0x7fff)/60)
126 #define BATT_REM_VALID(regp) (((regp)->dx & 0xffff) != 0xffff)
127 #define APM_GET_PM_EVENT 0x0b
128 #define APM_STANDBY_REQ 0x0001 /* %bx on return */
129 #define APM_SUSPEND_REQ 0x0002
130 #define APM_NORMAL_RESUME 0x0003
131 #define APM_CRIT_RESUME 0x0004 /* suspend/resume happened
132 without us */
133 #define APM_BATTERY_LOW 0x0005
134 #define APM_POWER_CHANGE 0x0006
135 #define APM_UPDATE_TIME 0x0007
136 #define APM_CRIT_SUSPEND_REQ 0x0008
137 #define APM_USER_STANDBY_REQ 0x0009
138 #define APM_USER_SUSPEND_REQ 0x000A
139 #define APM_SYS_STANDBY_RESUME 0x000B
140
141 #define APM_GET_POWER_STATE 0x0c
142 #define APM_DEVICE_MGMT_ENABLE 0x0d
143
144 #define APM_DRIVER_VERSION 0x0e
145 /* %bx should be DEV value (APM_DEV_APM_BIOS)
146 %ch = driver major vno
147 %cl = driver minor vno
148 return: %ah = conn major; %al = conn minor
149 */
150 #define APM_CONN_MINOR(regp) ((regp)->ax & 0xff)
151 #define APM_CONN_MAJOR(regp) (((regp)->ax & 0xff00) >> 8)
152
153 #define APM_PWR_MGT_ENGAGE 0x0F
154 #define APM_MGT_DISENGAGE 0x0 /* %cx */
155 #define APM_MGT_ENGAGE 0x1
156
157 #define APM_OEM 0x80
158
159 #ifdef _LOCORE
160 /*
161 * LP (Laptop Package)
162 *
163 * Copyright (C) 1994 by HOSOKAWA Tatsumi <hosokawa (at) mt.cs.keio.ac.jp>
164 *
165 * This software may be used, modified, copied, and distributed, in
166 * both source and binary form provided that the above copyright and
167 * these terms are retained. Under no circumstances is the author
168 * responsible for the proper functioning of this software, nor does
169 * the author assume any responsibility for damages incurred with its
170 * use.
171 *
172 * Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
173 */
174
175 /* Error code of APM initializer */
176 #define APMINI_CANTFIND 0xffffffff
177 #define APMINI_NOT32BIT 0xfffffffe
178 #define APMINI_CONNECTERR 0xfffffffd
179
180 #define SIZEOF_GDTE 8
181 #define BOOTSTRAP_GDT_NUM 9 /* see i386/boot/table.c */
182
183 #define APM_INIT_CS_INDEX (BOOTSTRAP_GDT_NUM - 3)
184 #define APM_INIT_DS_INDEX (BOOTSTRAP_GDT_NUM - 2)
185 #define APM_INIT_CS16_INDEX (BOOTSTRAP_GDT_NUM - 1)
186 #define APM_INIT_CS_SEL (APM_INIT_CS_INDEX << 3)
187 #define APM_INIT_DS_SEL (APM_INIT_DS_INDEX << 3)
188 #define APM_INIT_CS16_SEL (APM_INIT_CS16_INDEX << 3)
189
190 #define CS32_ATTRIB 0xCF9e
191 #define CS16_ATTRIB 0x0F9e
192 #define DS32_ATTRIB 0xCF92
193
194 #define BOOTSTRAP_DS_SEL 0x10
195 /* APM initializer physical address */
196 #define APM_OURADDR 0x00080000
197 #define APM_RELOC(x) ((x) - _apm_init_image)
198
199 #else /* !_LOCORE */
200
201 /* filled in by apmcall */
202 struct apmregs {
203 u_short ax;
204 u_short bx;
205 u_short cx;
206 u_short dx;
207 };
208
209 struct apm_connect_info {
210 u_int apm_code32_seg_base; /* real-mode style segment selector */
211 u_int apm_code16_seg_base;
212 u_int apm_data_seg_base;
213 u_int apm_entrypt;
214 u_short apm_segsel; /* segment selector for APM */
215 u_short _pad1;
216 u_int apm_code32_seg_len;
217 u_int apm_data_seg_len;
218 u_int apm_detail;
219 };
220
221 struct apm_event_info {
222 u_int type;
223 u_int index;
224 u_int spare[8];
225 };
226
227 #define APM_BATTERY_ABSENT 4
228
229 struct apm_power_info {
230 u_char battery_state;
231 u_char ac_state;
232 u_char battery_life;
233 u_char spare1;
234 u_int minutes_left; /* estimate */
235 u_int spare2[6];
236 };
237
238 struct apm_ctl {
239 u_int dev;
240 u_int mode;
241 };
242
243 #define APM_IOC_REJECT _IOW('A', 0, struct apm_event_info) /* reject request # */
244 #define APM_IOC_STANDBY _IO('A', 1) /* put system into standby */
245 #define APM_IOC_SUSPEND _IO('A', 2) /* put system into suspend */
246 #define APM_IOC_GETPOWER _IOR('A', 3, struct apm_power_info) /* fetch battery state */
247 #define APM_IOC_NEXTEVENT _IOR('A', 4, struct apm_event_info) /* fetch event */
248 #define APM_IOC_DEV_CTL _IOW('A', 5, struct apm_ctl) /* put device into mode */
249
250 struct apm_attach_args {
251 char *aaa_busname;
252 };
253
254 #ifdef _KERNEL
255 extern struct apm_connect_info apminfo; /* in locore */
256 extern int apmpresent;
257 extern int apmcall __P((int function, struct apmregs *regs));
258 extern void apm_cpu_busy __P((void));
259 extern void apm_cpu_idle __P((void));
260 extern void apminit __P((void));
261 int apm_set_powstate __P((u_int devid, u_int powstate));
262 #endif /* _KERNEL */
263 #endif /* _LOCORE */
264 #endif /* __i386_apm_h__ */
265