Home | History | Annotate | Line # | Download | only in include
apmvar.h revision 1.7
      1 /*	$NetBSD: apmvar.h,v 1.7 1998/08/31 23:54:33 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 /*
     41  * APM info bits from BIOS
     42  */
     43 #define APM_16BIT_SUPPORT	0x01
     44 #define APM_32BIT_SUPPORT	0x02
     45 #define APM_CPUIDLE_SLOW	0x04
     46 #define APM_DISABLED		0x08
     47 #define APM_DISENGAGED		0x10
     48 
     49 #define	APM_ERR_CODE(regs)	(((regs)->AX & 0xff00) >> 8)
     50 #define	APM_ERR_PM_DISABLED	0x01
     51 #define	APM_ERR_REALALREADY	0x02
     52 #define	APM_ERR_NOTCONN		0x03
     53 #define	APM_ERR_16ALREADY	0x05
     54 #define	APM_ERR_16NOTSUPP	0x06
     55 #define	APM_ERR_32ALREADY	0x07
     56 #define	APM_ERR_32NOTSUPP	0x08
     57 #define	APM_ERR_UNRECOG_DEV	0x09
     58 #define	APM_ERR_ERANGE		0x0A
     59 #define	APM_ERR_NOTENGAGED	0x0B
     60 #define	APM_ERR_EOPNOTSUPP	0x0C
     61 #define	APM_ERR_RTIMER_DISABLED	0x0D
     62 #define APM_ERR_UNABLE		0x60
     63 #define APM_ERR_NOEVENTS	0x80
     64 #define	APM_ERR_NOT_PRESENT	0x86
     65 
     66 #define APM_DEV_APM_BIOS	0x0000
     67 #define APM_DEV_ALLDEVS		0x0001
     68 /* device classes are high byte; device IDs go in low byte */
     69 #define		APM_DEV_DISPLAY(x)	(0x0100|((x)&0xff))
     70 #define		APM_DEV_DISK(x)		(0x0200|((x)&0xff))
     71 #define		APM_DEV_PARALLEL(x)	(0x0300|((x)&0xff))
     72 #define		APM_DEV_SERIAL(x)	(0x0400|((x)&0xff))
     73 #define		APM_DEV_NETWORK(x)	(0x0500|((x)&0xff))
     74 #define		APM_DEV_PCMCIA(x)	(0x0600|((x)&0xff))
     75 #define		APM_DEV_ALLUNITS	0xff
     76 
     77 #define	APM_INSTALLATION_CHECK	0x00	/* int15 only */
     78 #define		APM_INSTALL_SIGNATURE	0x504d	/* %bh = 'P', %bl = 'M' */
     79 #define	APM_REALMODE_CONNECT	0x01	/* int15 only */
     80 #define	APM_16BIT_CONNECT	0x02	/* int15 only */
     81 #define	APM_32BIT_CONNECT	0x03	/* int15 only */
     82 #define APM_DISCONNECT		0x04	/* %bx = APM_DEV_APM_BIOS */
     83 #define APM_CPU_IDLE		0x05
     84 #define APM_CPU_BUSY		0x06
     85 #define APM_SET_PWR_STATE	0x07
     86 #define		APM_SYS_READY	0x0000	/* %cx */
     87 #define		APM_SYS_STANDBY	0x0001
     88 #define		APM_SYS_SUSPEND	0x0002
     89 #define		APM_SYS_OFF	0x0003
     90 #define		APM_LASTREQ_INPROG	0x0004
     91 #define		APM_LASTREQ_REJECTED	0x0005
     92 
     93 /* system standby is device ID (%bx) 0x0001, APM_SYS_STANDBY */
     94 /* system suspend is device ID (%bx) 0x0001, APM_SYS_SUSPEND */
     95 
     96 #define APM_PWR_MGT_ENABLE	0x08
     97 #define		APM_MGT_ALL	0xffff	/* %bx */
     98 #define		APM_MGT_DISABLE	0x0	/* %cx */
     99 #define		APM_MGT_ENABLE	0x1
    100 
    101 #define APM_SYSTEM_DEFAULTS	0x09
    102 #define		APM_DEFAULTS_ALL	0xffff	/* %bx */
    103 #define		APM_DEFAULTS_ALL_V12	0x0001	/* %bx */
    104 
    105 #define APM_POWER_STATUS	0x0a
    106 #define		APM_AC_OFF		0x00
    107 #define		APM_AC_ON		0x01
    108 #define		APM_AC_BACKUP		0x02
    109 #define		APM_AC_UNKNOWN		0xff
    110 /* the first set of battery constants is 1.0 style values;
    111    the second set is 1.1 style bit definitions */
    112 #define		APM_BATT_HIGH		0x00
    113 #define		APM_BATT_LOW		0x01
    114 #define		APM_BATT_CRITICAL	0x02
    115 #define		APM_BATT_CHARGING	0x03
    116 #define		APM_BATT_ABSENT		0x04 /* Software only--not in spec! */
    117 #define		APM_BATT_UNKNOWN	0xff
    118 
    119 #define		APM_BATT_FLAG_HIGH	0x01
    120 #define		APM_BATT_FLAG_LOW	0x02
    121 #define		APM_BATT_FLAG_CRITICAL	0x04
    122 #define		APM_BATT_FLAG_CHARGING	0x08
    123 #define		APM_BATT_FLAG_NOBATTERY	0x10
    124 #define		APM_BATT_FLAG_NO_SYSTEM_BATTERY	0x80
    125 #define		APM_BATT_FLAG_UNKNOWN	0xff
    126 
    127 #define		APM_BATT_LIFE_UNKNOWN	0xff
    128 #define		APM_BATT_STATE(regp) ((regp)->BX & 0xff)
    129 #define		APM_BATT_FLAGS(regp) (((regp)->CX & 0xff00) >> 8)
    130 #define		APM_AC_STATE(regp) (((regp)->BX & 0xff00) >> 8)
    131 #define		APM_BATT_LIFE(regp) ((regp)->CX & 0xff) /* in % */
    132 /* BATT_REMAINING returns minutes remaining */
    133 #define		APM_BATT_REMAINING(regp) (((regp)->DX & 0x8000) ? \
    134 					  ((regp)->DX & 0x7fff) : \
    135 					  ((regp)->DX & 0x7fff)/60)
    136 #define		APM_BATT_REM_VALID(regp) (((regp)->DX & 0xffff) != 0xffff)
    137 #define		APM_BATTERY_COUNT(regp) ((regp)->SI)
    138 
    139 #define	APM_GET_PM_EVENT	0x0b
    140 #define		APM_STANDBY_REQ		0x0001 /* %bx on return */
    141 #define		APM_SUSPEND_REQ		0x0002
    142 #define		APM_NORMAL_RESUME	0x0003
    143 #define		APM_CRIT_RESUME		0x0004 /* suspend/resume happened
    144 						  without us */
    145      /* If set, the pccard sockets were powered off in the
    146 	suspend/standby state (V1.2 only) */
    147 #define		APM_PCCARD_POWEREDOFF(regp) ((regp)->CX & 0x0001)
    148 
    149 #define		APM_BATTERY_LOW		0x0005
    150 #define		APM_POWER_CHANGE	0x0006
    151 #define		APM_UPDATE_TIME		0x0007
    152 #define		APM_CRIT_SUSPEND_REQ	0x0008
    153 #define		APM_USER_STANDBY_REQ	0x0009
    154 #define		APM_USER_SUSPEND_REQ	0x000A
    155 #define		APM_SYS_STANDBY_RESUME	0x000B
    156 
    157 #define	APM_GET_POWER_STATE	0x0c
    158      /* device to query in %bx */
    159      /* returns power states in %cx */
    160 #define	APM_DEVICE_MGMT_ENABLE	0x0d
    161      /* device to enable/disable in %bx */
    162 
    163 #define	APM_DRIVER_VERSION	0x0e
    164 /* %bx should be DEV value (APM_DEV_APM_BIOS)
    165    %ch = driver major vno
    166    %cl = driver minor vno
    167    return: %ah = conn major; %al = conn minor
    168    */
    169 #define		APM_CONN_MINOR(regp) ((regp)->AX & 0xff)
    170 #define		APM_CONN_MAJOR(regp) (((regp)->AX & 0xff00) >> 8)
    171 
    172 #define APM_PWR_MGT_ENGAGE	0x0F
    173      /* device in %bx */
    174 #define		APM_MGT_DISENGAGE	0x0	/* %cx */
    175 #define		APM_MGT_ENGAGE		0x1
    176 
    177 #define APM_GET_CAPABILITIES	0x10
    178      /* device in %bx (APM_DEV_APM_BIOS) */
    179      /* %bl: number of batteries */
    180 #define		APM_NBATTERIES(regp) ((regp)->BX & 0xff)
    181      /* %cx capabilities */
    182 #define		APM_GLOBAL_STANDBY	0x0001
    183 #define		APM_GLOBAL_SUSPEND	0x0002
    184 #define		APM_RTIMER_STANDBY	0x0004 /* resume timer wakes standby */
    185 #define		APM_RTIMER_SUSPEND	0x0008 /* resume timer wakes suspend */
    186 #define		APM_IRRING_SUSPEND	0x0010 /* internal ring wakes suspend */
    187 #define		APM_IRRING_STANDBY	0x0020 /* internal ring wakes standby */
    188 #define		APM_PCRING_SUSPEND	0x0040 /* pccard ring wakes suspend */
    189 #define		APM_PCRING_STANDBY	0x0080 /* pccard ring wakes standby */
    190 
    191 #define	APM_RESUME_TIMER_CTL	0x11	/* get/set/disable resume timer */
    192      /* device in %bx (APM_DEV_APM_BIOS) */
    193      /* function code in %cl */
    194 #define		APM_RTIMER_DISABLE	0x00
    195 #define		APM_RTIMER_GET		0x01
    196 #define		APM_RTIMER_SET		0x02
    197      /* if %cl = set, or %cl = get, then: */
    198      /* %ch: seconds */
    199      /* %dh: hours */
    200      /* %dl: minutes */
    201      /* %sih: month (bcd), %sil: day (bcd) */
    202      /* %di: year (bcd, 4 digits) */
    203 #define APM_RESUME_RING_CTL		0x12
    204      /* device in %bx (APM_DEV_APM_BIOS) */
    205      /* %cx: function code */
    206 #define		APM_RRING_DISABLE	0x0000
    207 #define		APM_RRING_ENABLE	0x0001
    208 #define		APM_RRING_GET		0x0002
    209      /* returns state in %cx */
    210 #define		APM_RRING_DISABLED	0x0000
    211 #define		APM_RRING_ENABLED	0x0001
    212 
    213 #define APM_TIMER_REQS_CTL	0x13
    214      /* device in %bx (APM_DEV_APM_BIOS) */
    215      /* %cx: function code */
    216 #define		APM_TIMER_REQS_DISABLE	0x0000
    217 #define		APM_TIMER_REQS_ENABLE	0x0001
    218 #define		APM_TIMER_REQS_GET	0x0002
    219      /* returns state in %cx */
    220 #define		APM_TIMER_REQS_DISABLED	0x0000
    221 #define		APM_TIEMR_REQS_ENABLED	0x0001
    222 
    223 #define APM_OEM			0x80
    224 
    225 /*
    226  * APM info word from the real-mode handler is adjusted to put
    227  * major/minor version in low half and support bits in upper half.
    228  */
    229 #define	APM_MAJOR_VERS(info) (((info)&0xff00)>>8)
    230 #define	APM_MINOR_VERS(info) ((info)&0xff)
    231 
    232 #define APM_16BIT_SUPPORTED	(APM_16BIT_SUPPORT << 16)
    233 #define APM_32BIT_SUPPORTED	(APM_32BIT_SUPPORT << 16)
    234 #define APM_IDLE_SLOWS		(APM_CPUIDLE_SLOW << 16)
    235 #define APM_BIOS_PM_DISABLED	(APM_DISABLED << 16)
    236 #define APM_BIOS_PM_DISENGAGED	(APM_DISENGAGED << 16)
    237 
    238 /*
    239  * virtual & physical address of the trampoline
    240  * that we use: page 1.
    241  */
    242 #define APM_BIOSTRAMP	NBPG
    243 
    244 
    245 #ifndef _LOCORE
    246 
    247 /* filled in by apmcall */
    248 
    249 struct apm_connect_info {
    250 	u_int apm_code32_seg_base;	/* real-mode style segment selector */
    251 	u_int apm_code16_seg_base;
    252 	u_int apm_data_seg_base;
    253 	u_int apm_entrypt;
    254 	u_short	apm_segsel;		/* segment selector for APM */
    255 	u_short _pad1;
    256 	u_int apm_code32_seg_len;
    257 	u_int apm_code16_seg_len;
    258 	u_int apm_data_seg_len;
    259 	u_int apm_detail;
    260 };
    261 
    262 struct apm_event_info {
    263 	u_int type;
    264 	u_int index;
    265 	u_int spare[8];
    266 };
    267 
    268 struct apm_power_info {
    269 	u_char battery_state;
    270 	u_char ac_state;
    271 	u_char battery_life;
    272 	u_char spare1;
    273 	u_int minutes_left;		/* estimate */
    274 	u_int spare2[6];
    275 };
    276 
    277 struct apm_ctl {
    278 	u_int dev;
    279 	u_int mode;
    280 };
    281 
    282 #define	APM_IOC_REJECT	_IOW('A', 0, struct apm_event_info) /* reject request # */
    283 #define	APM_IOC_STANDBY	_IO('A', 1)	/* put system into standby */
    284 #define	APM_IOC_SUSPEND	_IO('A', 2)	/* put system into suspend */
    285 #define	APM_IOC_GETPOWER _IOR('A', 3, struct apm_power_info) /* fetch battery state */
    286 #define	APM_IOC_NEXTEVENT _IOR('A', 4, struct apm_event_info) /* fetch event */
    287 #define	APM_IOC_DEV_CTL	_IOW('A', 5, struct apm_ctl) /* put device into mode */
    288 
    289 struct apm_attach_args {
    290 	char *aaa_busname;
    291 };
    292 
    293 #ifdef _KERNEL
    294 extern struct apm_connect_info apminfo;	/* in locore */
    295 extern int apmpresent;
    296 extern int apmcall __P((int function, struct bioscallregs *regs));
    297 extern void bioscall __P((int function, struct bioscallregs *regs));
    298 extern void apm_cpu_busy __P((void));
    299 extern void apm_cpu_idle __P((void));
    300 extern void apminit __P((void));
    301 int apm_set_powstate __P((u_int devid, u_int powstate));
    302 extern int apm_busprobe __P((void));
    303 #endif /* _KERNEL */
    304 #endif /* _LOCORE */
    305 #endif /* __i386_apm_h__ */
    306