xref: /openbsd-src/sys/arch/i386/include/apmvar.h (revision cd56ea097150e82cade6656d44978184e018e288)
1*cd56ea09Sphessler /*	$OpenBSD: apmvar.h,v 1.22 2019/01/22 02:36:30 phessler Exp $	*/
2faa6f1b1Smickey 
398c00878Shvozda /*
498c00878Shvozda  *  Copyright (c) 1995 John T. Kohl
598c00878Shvozda  *  All rights reserved.
698c00878Shvozda  *
798c00878Shvozda  *  Redistribution and use in source and binary forms, with or without
898c00878Shvozda  *  modification, are permitted provided that the following conditions
998c00878Shvozda  *  are met:
1098c00878Shvozda  *  1. Redistributions of source code must retain the above copyright
1198c00878Shvozda  *     notice, this list of conditions and the following disclaimer.
1298c00878Shvozda  *  2. Redistributions in binary form must reproduce the above copyright
1398c00878Shvozda  *     notice, this list of conditions and the following disclaimer in the
1498c00878Shvozda  *     documentation and/or other materials provided with the distribution.
1598c00878Shvozda  *  3. The name of the author may not be used to endorse or promote products
1698c00878Shvozda  *     derived from this software without specific prior written permission.
1798c00878Shvozda  *
1898c00878Shvozda  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
1998c00878Shvozda  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2098c00878Shvozda  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2198c00878Shvozda  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
2298c00878Shvozda  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2398c00878Shvozda  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2498c00878Shvozda  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2598c00878Shvozda  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
2698c00878Shvozda  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
2798c00878Shvozda  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2898c00878Shvozda  * POSSIBILITY OF SUCH DAMAGE.
2998c00878Shvozda  *
3098c00878Shvozda  */
312fa72412Spirofti #ifndef _MACHINE_APMVAR_H_
322fa72412Spirofti #define _MACHINE_APMVAR_H_
3398c00878Shvozda 
3472f91c1dSderaadt #include <sys/ioccom.h>
3572f91c1dSderaadt 
3698c00878Shvozda /* Advanced Power Management (v1.0 and v1.1 specification)
3798c00878Shvozda  * functions/defines/etc.
3898c00878Shvozda  */
39b9a71df3Smickey 
4031425461Smickey #define	APM_VERSION	0x0102
4189442645Smickey 
4298c00878Shvozda /*
4398c00878Shvozda  * APM info word from boot loader
4498c00878Shvozda  */
4598c00878Shvozda #define APM_16BIT_SUPPORTED	0x00010000
4698c00878Shvozda #define APM_32BIT_SUPPORTED	0x00020000
4798c00878Shvozda #define APM_IDLE_SLOWS		0x00040000
4898c00878Shvozda #define APM_BIOS_PM_DISABLED	0x00080000
4998c00878Shvozda #define APM_BIOS_PM_DISENGAGED	0x00100000
5089442645Smickey #define	APM_MAJOR(f)		(((f) >> 8) & 0xff)
5189442645Smickey #define	APM_MINOR(f)		((f) & 0xff)
52902afacdSmickey #define	APM_VERMASK		0x0000ffff
53902afacdSmickey #define	APM_NOCLI		0x00010000
5465514a54Smickey #define	APM_BEBATT		0x00020000
5598c00878Shvozda 
56b9a71df3Smickey /* APM error codes */
5798c00878Shvozda #define	APM_ERR_CODE(regs)	(((regs)->ax & 0xff00) >> 8)
5898c00878Shvozda #define	APM_ERR_PM_DISABLED	0x01
5998c00878Shvozda #define	APM_ERR_REALALREADY	0x02
6098c00878Shvozda #define	APM_ERR_NOTCONN		0x03
6198c00878Shvozda #define	APM_ERR_16ALREADY	0x05
6298c00878Shvozda #define	APM_ERR_16NOTSUPP	0x06
6398c00878Shvozda #define	APM_ERR_32ALREADY	0x07
6498c00878Shvozda #define	APM_ERR_32NOTSUPP	0x08
6598c00878Shvozda #define	APM_ERR_UNRECOG_DEV	0x09
6698c00878Shvozda #define	APM_ERR_ERANGE		0x0A
6798c00878Shvozda #define	APM_ERR_NOTENGAGED	0x0B
6831425461Smickey #define	APM_ERR_EOPNOSUPP	0x0C
6931425461Smickey #define	APM_ERR_RTIMER_DISABLED	0x0D
7098c00878Shvozda #define APM_ERR_UNABLE		0x60
7198c00878Shvozda #define APM_ERR_NOEVENTS	0x80
7298c00878Shvozda #define	APM_ERR_NOT_PRESENT	0x86
7398c00878Shvozda 
7498c00878Shvozda #define APM_DEV_APM_BIOS	0x0000
7598c00878Shvozda #define APM_DEV_ALLDEVS		0x0001
7698c00878Shvozda /* device classes are high byte; device IDs go in low byte */
7798c00878Shvozda #define		APM_DEV_DISPLAY(x)	(0x0100|((x)&0xff))
7898c00878Shvozda #define		APM_DEV_DISK(x)		(0x0200|((x)&0xff))
7998c00878Shvozda #define		APM_DEV_PARALLEL(x)	(0x0300|((x)&0xff))
8098c00878Shvozda #define		APM_DEV_SERIAL(x)	(0x0400|((x)&0xff))
8198c00878Shvozda #define		APM_DEV_NETWORK(x)	(0x0500|((x)&0xff))
8298c00878Shvozda #define		APM_DEV_PCMCIA(x)	(0x0600|((x)&0xff))
8389442645Smickey #define		APM_DEV_BATTERIES(x)	(0x8000|((x)&0xff))
8498c00878Shvozda #define		APM_DEV_ALLUNITS	0xff
8589442645Smickey /* 0x8100-0xDFFF - reserved	*/
8689442645Smickey /* 0xE000-0xEFFF - OEM-defined	*/
8789442645Smickey /* 0xF000-0xFFFF - reserved	*/
8898c00878Shvozda 
89b9a71df3Smickey #define	APM_INSTCHECK		0x5300	/* int15 only */
90b9a71df3Smickey #define		APM_16BIT_SUPPORT	0x01
91b9a71df3Smickey #define		APM_32BIT_SUPPORT	0x02
92b9a71df3Smickey #define		APM_CPUIDLE_SLOW	0x04
93b9a71df3Smickey #define		APM_DISABLED		0x08
94b9a71df3Smickey #define		APM_DISENGAGED		0x10
95b9a71df3Smickey 
96b9a71df3Smickey #define	APM_REAL_CONNECT	0x5301	/* int15 only */
97b9a71df3Smickey #define	APM_PROT16_CONNECT	0x5302	/* int15 only */
98b9a71df3Smickey #define	APM_PROT32_CONNECT	0x5303	/* int15 only */
99b9a71df3Smickey #define APM_DISCONNECT		0x5304	/* %bx = APM_DEV_APM_BIOS */
100b9a71df3Smickey 
101b9a71df3Smickey #define APM_CPU_IDLE		0x5305
102b9a71df3Smickey #define APM_CPU_BUSY		0x5306
103b9a71df3Smickey 
104b9a71df3Smickey #define APM_SET_PWR_STATE	0x5307
10598c00878Shvozda #define		APM_SYS_READY		0x0000	/* %cx */
10698c00878Shvozda #define		APM_SYS_STANDBY		0x0001
10798c00878Shvozda #define		APM_SYS_SUSPEND		0x0002
10898c00878Shvozda #define		APM_SYS_OFF		0x0003
10998c00878Shvozda #define		APM_LASTREQ_INPROG	0x0004
11098c00878Shvozda #define		APM_LASTREQ_REJECTED	0x0005
111b9a71df3Smickey /* 0x0006 - 0x001f	Reserved system states    */
112b9a71df3Smickey /* 0x0020 - 0x003f	OEM-defined system states */
113b9a71df3Smickey /* 0x0040 - 0x007f	OEM-defined device states */
114b9a71df3Smickey /* 0x0080 - 0xffff	Reserved device states    */
11598c00878Shvozda 
11698c00878Shvozda /* system standby is device ID (%bx) 0x0001, APM_SYS_STANDBY */
11798c00878Shvozda /* system suspend is device ID (%bx) 0x0001, APM_SYS_SUSPEND */
11898c00878Shvozda 
119b9a71df3Smickey #define APM_PWR_MGT_ENABLE	0x5308
12098c00878Shvozda #define		APM_MGT_ALL	0xffff	/* %bx */
12198c00878Shvozda #define		APM_MGT_DISABLE	0x0	/* %cx */
12298c00878Shvozda #define		APM_MGT_ENABLE	0x1
12398c00878Shvozda 
124b9a71df3Smickey #define APM_SYSTEM_DEFAULTS	0x5309
12598c00878Shvozda #define		APM_DEFAULTS_ALL	0xffff	/* %bx */
12698c00878Shvozda 
127b9a71df3Smickey #define APM_POWER_STATUS	0x530a
12898c00878Shvozda #define		APM_AC_OFF		0x00
12998c00878Shvozda #define		APM_AC_ON		0x01
13098c00878Shvozda #define		APM_AC_BACKUP		0x02
13198c00878Shvozda #define		APM_AC_UNKNOWN		0xff
13298c00878Shvozda #define		APM_BATT_HIGH		0x00
13398c00878Shvozda #define		APM_BATT_LOW		0x01
13498c00878Shvozda #define		APM_BATT_CRITICAL	0x02
13598c00878Shvozda #define		APM_BATT_CHARGING	0x03
13698c00878Shvozda #define		APM_BATT_UNKNOWN	0xff
13798c00878Shvozda #define		APM_BATT_FLAG_HIGH	0x01
13898c00878Shvozda #define		APM_BATT_FLAG_LOW	0x02
13998c00878Shvozda #define		APM_BATT_FLAG_CRITICAL	0x04
14098c00878Shvozda #define		APM_BATT_FLAG_CHARGING	0x08
14131425461Smickey #define		APM_BATT_FLAG_NOBATTERY	0x10
14231425461Smickey #define		APM_BATT_FLAG_NOSYSBATT	0x80
14398c00878Shvozda #define		APM_BATT_LIFE_UNKNOWN	0xff
14498c00878Shvozda #define		BATT_STATE(regp) ((regp)->bx & 0xff)
14598c00878Shvozda #define		BATT_FLAGS(regp) (((regp)->cx & 0xff00) >> 8)
14698c00878Shvozda #define		AC_STATE(regp) (((regp)->bx & 0xff00) >> 8)
14798c00878Shvozda #define		BATT_LIFE(regp) ((regp)->cx & 0xff) /* in % */
148a545d7afSmarc /* Return time in minutes. According to the APM 1.2 spec:
149a545d7afSmarc 	DX = Remaining battery life -- time units
150a545d7afSmarc 		Bit 15 = 0	Time units are seconds
151a545d7afSmarc 		       = 1 	Time units are minutes
152a545d7afSmarc 		Bits 14-0 =	Number of seconds or minutes */
15398c00878Shvozda #define		BATT_REMAINING(regp) (((regp)->dx & 0x8000) ? \
154a545d7afSmarc 				      ((regp)->dx & 0x7fff) : \
155a545d7afSmarc 				      ((regp)->dx & 0x7fff)/60)
15698c00878Shvozda #define		BATT_REM_VALID(regp) (((regp)->dx & 0xffff) != 0xffff)
15731425461Smickey #define		BATT_COUNT(regp)	((regp)->si)
158b9a71df3Smickey 
159b9a71df3Smickey #define	APM_GET_PM_EVENT	0x530b
160b9a71df3Smickey #define		APM_NOEVENT		0x0000
16198c00878Shvozda #define		APM_STANDBY_REQ		0x0001 /* %bx on return */
16298c00878Shvozda #define		APM_SUSPEND_REQ		0x0002
16398c00878Shvozda #define		APM_NORMAL_RESUME	0x0003
16498c00878Shvozda #define		APM_CRIT_RESUME		0x0004 /* suspend/resume happened
16598c00878Shvozda 						  without us */
16698c00878Shvozda #define		APM_BATTERY_LOW		0x0005
16798c00878Shvozda #define		APM_POWER_CHANGE	0x0006
16898c00878Shvozda #define		APM_UPDATE_TIME		0x0007
16998c00878Shvozda #define		APM_CRIT_SUSPEND_REQ	0x0008
17098c00878Shvozda #define		APM_USER_STANDBY_REQ	0x0009
17198c00878Shvozda #define		APM_USER_SUSPEND_REQ	0x000A
17298c00878Shvozda #define		APM_SYS_STANDBY_RESUME	0x000B
17331425461Smickey #define		APM_CAPABILITY_CHANGE	0x000C	/* apm v1.2 */
17489442645Smickey /* 0x000d - 0x00ff	Reserved system events */
1758d4bc9d5Sdcoppa #define		APM_USER_HIBERNATE_REQ	0x000D
176b9a71df3Smickey /* 0x0100 - 0x01ff	Reserved device events */
177b9a71df3Smickey /* 0x0200 - 0x02ff	OEM-defined APM events */
178b9a71df3Smickey /* 0x0300 - 0xffff	Reserved */
1791e8a3e09Smickey #define		APM_EVENT_MASK		0xffff
1801e8a3e09Smickey 
1811e8a3e09Smickey #define	APM_EVENT_COMPOSE(t,i)	((((i) & 0x7fff) << 16)|((t) & APM_EVENT_MASK))
1821e8a3e09Smickey #define	APM_EVENT_TYPE(e)	((e) & APM_EVENT_MASK)
1831e8a3e09Smickey #define	APM_EVENT_INDEX(e)	((e) >> 16)
18498c00878Shvozda 
185b9a71df3Smickey #define	APM_GET_POWER_STATE	0x530c
186b9a71df3Smickey #define	APM_DEVICE_MGMT_ENABLE	0x530d
18798c00878Shvozda 
188b9a71df3Smickey #define	APM_DRIVER_VERSION	0x530e
18998c00878Shvozda /* %bx should be DEV value (APM_DEV_APM_BIOS)
19098c00878Shvozda    %ch = driver major vno
19198c00878Shvozda    %cl = driver minor vno
19298c00878Shvozda    return: %ah = conn major; %al = conn minor
19398c00878Shvozda    */
19498c00878Shvozda #define		APM_CONN_MINOR(regp) ((regp)->ax & 0xff)
19598c00878Shvozda #define		APM_CONN_MAJOR(regp) (((regp)->ax & 0xff00) >> 8)
19698c00878Shvozda 
197b9a71df3Smickey #define APM_PWR_MGT_ENGAGE	0x530F
19898c00878Shvozda #define		APM_MGT_DISENGAGE	0x0	/* %cx */
19998c00878Shvozda #define		APM_MGT_ENGAGE		0x1
20098c00878Shvozda 
20131425461Smickey /* %bx - APM_DEV_APM_BIOS
20231425461Smickey  * %bl - number of batteries
20331425461Smickey  * %cx - capabilities
20431425461Smickey  */
20589442645Smickey #define	APM_GET_CAPABILITIES	0x5310
20631425461Smickey #define		APM_NBATTERIES(regp)	((regp)->bx)
20731425461Smickey #define		APM_GLOBAL_STANDBY	0x0001
20831425461Smickey #define		APM_GLOBAL_SUSPEND	0x0002
20931425461Smickey #define		APM_RTIMER_STANDBY	0x0004	/* resume time wakes up */
21031425461Smickey #define		APM_RTIMER_SUSPEND	0x0008
21131425461Smickey #define		APM_IRRING_STANDBY	0x0010	/* internal ring wakes up */
21231425461Smickey #define		APM_IRRING_SUSPEND	0x0020
21331425461Smickey #define		APM_PCCARD_STANDBY	0x0040	/* pccard wakes up */
21431425461Smickey #define		APM_PCCARD_SUSPEND	0x0080
21589442645Smickey 
21689442645Smickey /* %bx - APM_DEV_APM_BIOS
21789442645Smickey  * %cl - function
21889442645Smickey  *	for %cl=2 (set resume timer)
21989442645Smickey  * %ch - seconds in BCD
22089442645Smickey  * %dh - hours in BCD
22189442645Smickey  * %dl - minutes in BCD
22289442645Smickey  * %si - month in BCD (high), day in BCD (low)
22389442645Smickey  * %di - year in BCD
22489442645Smickey  */
22589442645Smickey #define	APM_RESUME_TIMER	0x5311
22689442645Smickey #define		APM_RT_DISABLE	0x0
22789442645Smickey #define		APM_RT_GET	0x1
22889442645Smickey #define		APM_RT_SET	0x2
22989442645Smickey 
23089442645Smickey /* %bx - APM_DEV_APM_BIOS
23189442645Smickey  * %cx - function
23289442645Smickey  */
23389442645Smickey #define	APM_RESUME_ON_RING	0x5312
23489442645Smickey #define		APM_ROR_DISABLE	0x0
23589442645Smickey #define		APM_ROR_ENABLE	0x1
23689442645Smickey #define		APM_ROR_STATUS	0x2
23789442645Smickey 
23889442645Smickey /* %bx - APM_EDV_APM_BIOS
23989442645Smickey  * %cx - function
24089442645Smickey  */
24189442645Smickey #define	APM_INACTIVITY_TIMER	0x5313
24289442645Smickey #define		APM_IT_DISABLE	0x0
24389442645Smickey #define		APM_IT_ENABLE	0x1
24489442645Smickey #define		APM_IT_STATUS	0x2
24589442645Smickey 
24689442645Smickey /* %bh - function */
247b9a71df3Smickey #define APM_OEM			0x5380
24889442645Smickey #define		APM_OEM_INSTCHECK	0x7f	/* %bx - OEM ID */
24998c00878Shvozda 
25098c00878Shvozda /*
25198c00878Shvozda  * LP (Laptop Package)
25298c00878Shvozda  *
25398c00878Shvozda  * Copyright (C) 1994 by HOSOKAWA Tatsumi <hosokawa@mt.cs.keio.ac.jp>
25498c00878Shvozda  *
25598c00878Shvozda  * This software may be used, modified, copied, and distributed, in
25698c00878Shvozda  * both source and binary form provided that the above copyright and
25798c00878Shvozda  * these terms are retained. Under no circumstances is the author
25898c00878Shvozda  * responsible for the proper functioning of this software, nor does
25998c00878Shvozda  * the author assume any responsibility for damages incurred with its
26098c00878Shvozda  * use.
26198c00878Shvozda  *
26298c00878Shvozda  * Sep., 1994	Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
26398c00878Shvozda  */
26498c00878Shvozda 
26598c00878Shvozda #define APM_BATTERY_ABSENT 4
26698c00878Shvozda 
26798c00878Shvozda struct apm_power_info {
26898c00878Shvozda 	u_char battery_state;
26998c00878Shvozda 	u_char ac_state;
27098c00878Shvozda 	u_char battery_life;
27198c00878Shvozda 	u_char spare1;
27298c00878Shvozda 	u_int minutes_left;		/* estimate */
27398c00878Shvozda 	u_int spare2[6];
27498c00878Shvozda };
27598c00878Shvozda 
27698c00878Shvozda struct apm_ctl {
27798c00878Shvozda 	u_int dev;
27898c00878Shvozda 	u_int mode;
27998c00878Shvozda };
28098c00878Shvozda 
28198c00878Shvozda #define	APM_IOC_REJECT	_IOW('A', 0, struct apm_event_info) /* reject request # */
28298c00878Shvozda #define	APM_IOC_STANDBY	_IO('A', 1)	/* put system into standby */
28398c00878Shvozda #define	APM_IOC_SUSPEND	_IO('A', 2)	/* put system into suspend */
28498c00878Shvozda #define	APM_IOC_GETPOWER _IOR('A', 3, struct apm_power_info) /* fetch battery state */
28598c00878Shvozda #define	APM_IOC_DEV_CTL	_IOW('A', 5, struct apm_ctl) /* put device into mode */
2863ca38bd5Smarc #define APM_IOC_PRN_CTL _IOW('A', 6, int ) /* driver power status msg */
2873ca38bd5Smarc #define		APM_PRINT_ON	0	/* driver power status displayed */
2883ca38bd5Smarc #define		APM_PRINT_OFF	1	/* driver power status not displayed */
2893ca38bd5Smarc #define		APM_PRINT_PCT	2	/* driver power status only displayed
2903ca38bd5Smarc 					   if the percentage changes */
2917939ba9cSoga #define	APM_IOC_STANDBY_REQ	_IO('A', 7)	/* request standby */
2927939ba9cSoga #define	APM_IOC_SUSPEND_REQ	_IO('A', 8)	/* request suspend */
2933d908d29Sderaadt #define	APM_IOC_HIBERNATE	_IO('A', 9)	/* put system into hibernate */
2947939ba9cSoga 
29598c00878Shvozda 
29698c00878Shvozda #ifdef _KERNEL
297c4071fd1Smillert extern void apm_cpu_busy(void);
298c4071fd1Smillert extern void apm_cpu_idle(void);
299c4071fd1Smillert extern void apminit(void);
300c4071fd1Smillert int apm_set_powstate(u_int devid, u_int powstate);
30198c00878Shvozda #endif /* _KERNEL */
302b9a71df3Smickey 
3032fa72412Spirofti #endif /* _MACHINE_APMVAR_H_ */
304