11556Srgrimes/*-
21556Srgrimes * APM (Advanced Power Management) BIOS Device Driver
31556Srgrimes *
41556Srgrimes * Copyright (c) 1994-1995 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
51556Srgrimes *
61556Srgrimes * This software may be used, modified, copied, and distributed, in
71556Srgrimes * both source and binary form provided that the above copyright and
81556Srgrimes * these terms are retained. Under no circumstances is the author
91556Srgrimes * responsible for the proper functioning of this software, nor does
101556Srgrimes * the author assume any responsibility for damages incurred with its
111556Srgrimes * use.
121556Srgrimes *
131556Srgrimes * Aug, 1994	Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
141556Srgrimes *
151556Srgrimes * $FreeBSD$
161556Srgrimes */
171556Srgrimes
181556Srgrimes#ifndef _X86_APM_BIOS_H_
191556Srgrimes#define	_X86_APM_BIOS_H_
201556Srgrimes
211556Srgrimes#ifndef _KERNEL
221556Srgrimes#include <sys/types.h>
231556Srgrimes#endif
241556Srgrimes#include <sys/ioccom.h>
251556Srgrimes
261556Srgrimes/* BIOS id */
271556Srgrimes#define APM_BIOS		0x53
281556Srgrimes#define APM_INT			0x15
291556Srgrimes
301556Srgrimes/* APM flags */
311556Srgrimes#define APM_16BIT_SUPPORT	0x01
321556Srgrimes#define APM_32BIT_SUPPORT	0x02
331556Srgrimes#define APM_CPUIDLE_SLOW	0x04
3420425Ssteve#define APM_DISABLED		0x08
351556Srgrimes#define APM_DISENGAGED		0x10
361556Srgrimes
371556Srgrimes/* APM initializer physical address */
381556Srgrimes#define APM_OURADDR		0x00080000
391556Srgrimes
4036150Scharnier/* APM functions */
4136150Scharnier#define APM_INSTCHECK		0x00
4236150Scharnier#define APM_REALCONNECT		0x01
431556Srgrimes#define APM_PROT16CONNECT	0x02
4499110Sobrien#define APM_PROT32CONNECT	0x03
4599110Sobrien#define APM_DISCONNECT		0x04
461556Srgrimes#define APM_CPUIDLE		0x05
471556Srgrimes#define APM_CPUBUSY		0x06
481556Srgrimes#define APM_SETPWSTATE		0x07
491556Srgrimes#define APM_ENABLEDISABLEPM	0x08
501556Srgrimes#define APM_RESTOREDEFAULT	0x09
511556Srgrimes#define	APM_GETPWSTATUS		0x0a
5217987Speter#define APM_GETPMEVENT		0x0b
531556Srgrimes#define APM_GETPWSTATE		0x0c
5417987Speter#define APM_ENABLEDISABLEDPM	0x0d
551556Srgrimes#define APM_DRVVERSION		0x0e
561556Srgrimes#define APM_ENGAGEDISENGAGEPM	0x0f
571556Srgrimes#define APM_GETCAPABILITIES	0x10
581556Srgrimes#define APM_RESUMETIMER		0x11
591556Srgrimes#define APM_RESUMEONRING	0x12
601556Srgrimes#define APM_TIMERREQUESTS	0x13
6117987Speter#define APM_OEMFUNC		0x80
6217987Speter
631556Srgrimes/* error code */
641556Srgrimes#define APME_OK			0x00
6553891Scracauer#define APME_PMDISABLED		0x01
661556Srgrimes#define APME_REALESTABLISHED	0x02
671556Srgrimes#define APME_NOTCONNECTED	0x03
681556Srgrimes#define APME_PROT16ESTABLISHED	0x05
691556Srgrimes#define APME_PROT16NOTSUPPORTED	0x06
7020425Ssteve#define APME_PROT32ESTABLISHED	0x07
711556Srgrimes#define APME_PROT32NOTDUPPORTED	0x08
721556Srgrimes#define APME_UNKNOWNDEVICEID	0x09
731556Srgrimes#define APME_OUTOFRANGE		0x0a
741556Srgrimes#define APME_NOTENGAGED		0x0b
751556Srgrimes#define APME_CANTENTERSTATE	0x60
761556Srgrimes#define APME_NOPMEVENT		0x80
771556Srgrimes#define APME_NOAPMPRESENT	0x86
781556Srgrimes
791556Srgrimes
801556Srgrimes/* device code */
811556Srgrimes#define PMDV_APMBIOS		0x0000
821556Srgrimes#define PMDV_ALLDEV		0x0001
831556Srgrimes#define PMDV_DISP0		0x0100
841556Srgrimes#define PMDV_DISP1		0x0101
851556Srgrimes#define PMDV_DISPALL		0x01ff
861556Srgrimes#define PMDV_2NDSTORAGE0	0x0200
871556Srgrimes#define PMDV_2NDSTORAGE1	0x0201
881556Srgrimes#define PMDV_2NDSTORAGE2	0x0202
891556Srgrimes#define PMDV_2NDSTORAGE3	0x0203
901556Srgrimes#define PMDV_PARALLEL0		0x0300
911556Srgrimes#define PMDV_PARALLEL1		0x0301
928855Srgrimes#define PMDV_SERIAL0		0x0400
931556Srgrimes#define PMDV_SERIAL1		0x0401
941556Srgrimes#define PMDV_SERIAL2		0x0402
951556Srgrimes#define PMDV_SERIAL3		0x0403
961556Srgrimes#define PMDV_SERIAL4		0x0404
971556Srgrimes#define PMDV_SERIAL5		0x0405
981556Srgrimes#define PMDV_SERIAL6		0x0406
991556Srgrimes#define PMDV_SERIAL7		0x0407
1001556Srgrimes#define PMDV_NET0		0x0500
1011556Srgrimes#define PMDV_NET1		0x0501
1021556Srgrimes#define PMDV_NET2		0x0502
1031556Srgrimes#define PMDV_NET3		0x0503
1041556Srgrimes#define PMDV_PCMCIA0		0x0600
1051556Srgrimes#define PMDV_PCMCIA1		0x0601
1061556Srgrimes#define PMDV_PCMCIA2		0x0602
1071556Srgrimes#define PMDV_PCMCIA3		0x0603
10820425Ssteve/* 0x0700 - 0x7fff	Reserved			*/
1091556Srgrimes#define PMDV_BATT_BASE		0x8000
1101556Srgrimes#define PMDV_BATT0		0x8001
1111556Srgrimes#define PMDV_BATT1		0x8002
1121556Srgrimes#define PMDV_BATT_ALL		0x80ff
1131556Srgrimes/* 0x8100 - 0xdfff	Reserved			*/
1141556Srgrimes/* 0xe000 - 0xefff	OEM-defined power device IDs	*/
1151556Srgrimes/* 0xf000 - 0xffff	Reserved			*/
1161556Srgrimes
1171556Srgrimes/* Power state */
1181556Srgrimes#define PMST_APMENABLED		0x0000
1191556Srgrimes#define PMST_STANDBY		0x0001
1201556Srgrimes#define PMST_SUSPEND		0x0002
1211556Srgrimes#define PMST_OFF		0x0003
1221556Srgrimes#define PMST_LASTREQNOTIFY	0x0004
1231556Srgrimes#define PMST_LASTREQREJECT	0x0005
1241556Srgrimes/* 0x0006 - 0x001f	Reserved system states		*/
1251556Srgrimes/* 0x0020 - 0x003f	OEM-defined system states	*/
1261556Srgrimes/* 0x0040 - 0x007f	OEM-defined device states	*/
1271556Srgrimes/* 0x0080 - 0xffff	Reserved device states		*/
1281556Srgrimes
1291556Srgrimes#if !defined(ASSEMBLER) && !defined(INITIALIZER)
1301556Srgrimes
1311556Srgrimes/* C definitions */
1321556Srgrimesstruct apmhook {
1331556Srgrimes	struct apmhook	*ah_next;
1341556Srgrimes	int		(*ah_fun)(void *ah_arg);
1351556Srgrimes	void		*ah_arg;
136149019Sstefanf	const char	*ah_name;
137149019Sstefanf	int		ah_order;
138149019Sstefanf};
139149019Sstefanf#define APM_HOOK_NONE		(-1)
1401556Srgrimes#define APM_HOOK_SUSPEND        0
1411556Srgrimes#define APM_HOOK_RESUME         1
1421556Srgrimes#define NAPM_HOOK               2
1431556Srgrimes
1441556Srgrimes#ifdef _KERNEL
1451556Srgrimes
1461556Srgrimesvoid apm_suspend(int state);
1471556Srgrimesstruct apmhook *apm_hook_establish (int apmh, struct apmhook *);
1481556Srgrimesvoid apm_hook_disestablish (int apmh, struct apmhook *);
1491556Srgrimesvoid apm_cpu_idle(void);
1501556Srgrimesvoid apm_cpu_busy(void);
15190111Simp
15290111Simp#endif
15390111Simp
15490111Simp#endif /* !ASSEMBLER && !INITIALIZER */
15590111Simp
15690111Simp#define APM_MIN_ORDER		0x00
15790111Simp#define APM_MID_ORDER		0x80
15890111Simp#define APM_MAX_ORDER		0xff
15990111Simp
16090111Simp/* power management event code */
16190111Simp#define PMEV_NOEVENT		0x0000
162193221Srse#define PMEV_STANDBYREQ		0x0001
16390111Simp#define PMEV_SUSPENDREQ		0x0002
16490111Simp#define PMEV_NORMRESUME		0x0003
1651556Srgrimes#define PMEV_CRITRESUME		0x0004
1661556Srgrimes#define PMEV_BATTERYLOW		0x0005
1671556Srgrimes#define PMEV_POWERSTATECHANGE	0x0006
16817987Speter#define PMEV_UPDATETIME		0x0007
16990111Simp#define PMEV_CRITSUSPEND	0x0008
17017987Speter#define PMEV_USERSTANDBYREQ	0x0009
1711556Srgrimes#define PMEV_USERSUSPENDREQ	0x000a
1721556Srgrimes#define PMEV_STANDBYRESUME	0x000b
1731556Srgrimes#define PMEV_CAPABILITIESCHANGE 0x000c
1741556Srgrimes/* 0x000d - 0x00ff	Reserved system events	*/
175149019Sstefanf/* 0x0100 - 0x01ff	Reserved device events	*/
17617987Speter/* 0x0200 - 0x02ff	OEM-defined APM events	*/
1771556Srgrimes/* 0x0300 - 0xffff	Reserved		*/
1781556Srgrimes#define PMEV_DEFAULT		0xffffffff	/* used for customization */
17920425Ssteve
18017987Speter#if !defined(ASSEMBLER) && !defined(INITIALIZER)
1811556Srgrimes
1821556Srgrimes/*
1831556Srgrimes * Old apm_info structure, returned by the APMIO_GETINFO_OLD ioctl.  This
1841556Srgrimes * is for backward compatibility with old executables.
1851556Srgrimes */
1861556Srgrimestypedef struct apm_info_old {
1871556Srgrimes	u_int	ai_major;	/* APM major version */
1881556Srgrimes	u_int	ai_minor;	/* APM minor version */
18990111Simp	u_int	ai_acline;	/* AC line status */
19090111Simp	u_int	ai_batt_stat;	/* Battery status */
1911556Srgrimes	u_int	ai_batt_life;	/* Remaining battery life */
19220425Ssteve	u_int	ai_status;	/* Status of APM support (enabled/disabled) */
1931556Srgrimes} *apm_info_old_t;
1941556Srgrimes
1951556Srgrimes/*
1961556Srgrimes * Structure returned by the APMIO_GETINFO ioctl.
1971556Srgrimes *
1981556Srgrimes * In the comments below, the parenthesized numbers indicate the minimum
1991556Srgrimes * value of ai_infoversion for which each field is valid.
2001556Srgrimes */
2011556Srgrimestypedef struct apm_info {
2021556Srgrimes	u_int	ai_infoversion;	/* Indicates which fields are valid */
2031556Srgrimes	u_int	ai_major;	/* APM major version (0) */
2041556Srgrimes	u_int	ai_minor;	/* APM minor version (0) */
2051556Srgrimes	u_int	ai_acline;	/* AC line status (0) */
2061556Srgrimes	u_int	ai_batt_stat;	/* Battery status (0) */
2071556Srgrimes	u_int	ai_batt_life;	/* Remaining battery life in percent (0) */
2081556Srgrimes	int	ai_batt_time;	/* Remaining battery time in seconds (0) */
2091556Srgrimes	u_int	ai_status;	/* True if enabled (0) */
2101556Srgrimes	u_int	ai_batteries;	/* Number of batteries (1) */
21111113Sjoerg	u_int	ai_capabilities;/* APM Capabilities (1) */
21211113Sjoerg	u_int	ai_spare[6];	/* For future expansion */
21320425Ssteve} *apm_info_t;
21420425Ssteve
21511113Sjoerg/* Battery flag */
21611113Sjoerg#define APM_BATT_HIGH		0x01
21720425Ssteve#define APM_BATT_LOW		0x02
21820425Ssteve#define APM_BATT_CRITICAL	0x04
21911113Sjoerg#define APM_BATT_CHARGING	0x08
22020425Ssteve#define APM_BATT_NOT_PRESENT	0x10
22111113Sjoerg#define APM_BATT_NO_SYSTEM	0x80
22220425Ssteve
22311113Sjoergtypedef struct apm_pwstatus {
22411113Sjoerg	u_int	ap_device;	/* Device code of battery */
2251556Srgrimes	u_int	ap_acline;	/* AC line status (0) */
22611113Sjoerg	u_int	ap_batt_stat;	/* Battery status (0) */
2271556Srgrimes	u_int	ap_batt_flag;	/* Battery flag (0) */
2281556Srgrimes	u_int	ap_batt_life;	/* Remaining battery life in percent (0) */
2291556Srgrimes	int	ap_batt_time;	/* Remaining battery time in seconds (0) */
2301556Srgrimes} *apm_pwstatus_t;
2311556Srgrimes
2321556Srgrimesstruct apm_bios_arg {
23390111Simp        uint32_t eax;
23417987Speter        uint32_t ebx;
23525222Ssteve        uint32_t ecx;
2361556Srgrimes        uint32_t edx;
2371556Srgrimes        uint32_t esi;
2381556Srgrimes        uint32_t edi;
2391556Srgrimes};
2401556Srgrimes
2411556Srgrimesstruct apm_event_info {
2421556Srgrimes	u_int type;
2431556Srgrimes	u_int index;
2441556Srgrimes	u_int spare[8];
2451556Srgrimes};
2461556Srgrimes
2471556Srgrimes#define APMIO_SUSPEND		_IO('P', 1)
2481556Srgrimes#define APMIO_GETINFO_OLD	_IOR('P', 2, struct apm_info_old)
24990111Simp#define APMIO_ENABLE		_IO('P', 5)
25017987Speter#define APMIO_DISABLE		_IO('P', 6)
25125222Ssteve#define APMIO_HALTCPU		_IO('P', 7)
2521556Srgrimes#define APMIO_NOTHALTCPU	_IO('P', 8)
2531556Srgrimes#define APMIO_DISPLAY		_IOW('P', 9, int)
2541556Srgrimes#define APMIO_BIOS		_IOWR('P', 10, struct apm_bios_arg)
2551556Srgrimes#define APMIO_GETINFO		_IOR('P', 11, struct apm_info)
2561556Srgrimes#define APMIO_STANDBY		_IO('P', 12)
2571556Srgrimes#define APMIO_GETPWSTATUS	_IOWR('P', 13, struct apm_pwstatus)
2581556Srgrimes/* for /dev/apmctl */
2591556Srgrimes#define APMIO_NEXTEVENT		_IOR('A', 100, struct apm_event_info)
2601556Srgrimes#define APMIO_REJECTLASTREQ	_IO('P', 101)
2611556Srgrimes
2621556Srgrimes#endif /* !ASSEMBLER && !INITIALIZER */
2631556Srgrimes
2641556Srgrimes#endif /* !_X86_APM_BIOS_H_ */
2651556Srgrimes