1 /*- 2 * APM (Advanced Power Management) BIOS Device Driver 3 * 4 * Copyright (c) 1994-1995 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp> 5 * 6 * This software may be used, modified, copied, and distributed, in 7 * both source and binary form provided that the above copyright and 8 * these terms are retained. Under no circumstances is the author 9 * responsible for the proper functioning of this software, nor does 10 * the author assume any responsibility for damages incurred with its 11 * use. 12 * 13 * Aug, 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) 14 */ 15 16 #ifndef _X86_APM_BIOS_H_ 17 #define _X86_APM_BIOS_H_ 18 19 #ifndef _KERNEL 20 #include <sys/types.h> 21 #endif 22 #include <sys/ioccom.h> 23 24 /* BIOS id */ 25 #define APM_BIOS 0x53 26 #define APM_INT 0x15 27 28 /* APM flags */ 29 #define APM_16BIT_SUPPORT 0x01 30 #define APM_32BIT_SUPPORT 0x02 31 #define APM_CPUIDLE_SLOW 0x04 32 #define APM_DISABLED 0x08 33 #define APM_DISENGAGED 0x10 34 35 /* APM initializer physical address */ 36 #define APM_OURADDR 0x00080000 37 38 /* APM functions */ 39 #define APM_INSTCHECK 0x00 40 #define APM_REALCONNECT 0x01 41 #define APM_PROT16CONNECT 0x02 42 #define APM_PROT32CONNECT 0x03 43 #define APM_DISCONNECT 0x04 44 #define APM_CPUIDLE 0x05 45 #define APM_CPUBUSY 0x06 46 #define APM_SETPWSTATE 0x07 47 #define APM_ENABLEDISABLEPM 0x08 48 #define APM_RESTOREDEFAULT 0x09 49 #define APM_GETPWSTATUS 0x0a 50 #define APM_GETPMEVENT 0x0b 51 #define APM_GETPWSTATE 0x0c 52 #define APM_ENABLEDISABLEDPM 0x0d 53 #define APM_DRVVERSION 0x0e 54 #define APM_ENGAGEDISENGAGEPM 0x0f 55 #define APM_GETCAPABILITIES 0x10 56 #define APM_RESUMETIMER 0x11 57 #define APM_RESUMEONRING 0x12 58 #define APM_TIMERREQUESTS 0x13 59 #define APM_OEMFUNC 0x80 60 61 /* error code */ 62 #define APME_OK 0x00 63 #define APME_PMDISABLED 0x01 64 #define APME_REALESTABLISHED 0x02 65 #define APME_NOTCONNECTED 0x03 66 #define APME_PROT16ESTABLISHED 0x05 67 #define APME_PROT16NOTSUPPORTED 0x06 68 #define APME_PROT32ESTABLISHED 0x07 69 #define APME_PROT32NOTDUPPORTED 0x08 70 #define APME_UNKNOWNDEVICEID 0x09 71 #define APME_OUTOFRANGE 0x0a 72 #define APME_NOTENGAGED 0x0b 73 #define APME_CANTENTERSTATE 0x60 74 #define APME_NOPMEVENT 0x80 75 #define APME_NOAPMPRESENT 0x86 76 77 /* device code */ 78 #define PMDV_APMBIOS 0x0000 79 #define PMDV_ALLDEV 0x0001 80 #define PMDV_DISP0 0x0100 81 #define PMDV_DISP1 0x0101 82 #define PMDV_DISPALL 0x01ff 83 #define PMDV_2NDSTORAGE0 0x0200 84 #define PMDV_2NDSTORAGE1 0x0201 85 #define PMDV_2NDSTORAGE2 0x0202 86 #define PMDV_2NDSTORAGE3 0x0203 87 #define PMDV_PARALLEL0 0x0300 88 #define PMDV_PARALLEL1 0x0301 89 #define PMDV_SERIAL0 0x0400 90 #define PMDV_SERIAL1 0x0401 91 #define PMDV_SERIAL2 0x0402 92 #define PMDV_SERIAL3 0x0403 93 #define PMDV_SERIAL4 0x0404 94 #define PMDV_SERIAL5 0x0405 95 #define PMDV_SERIAL6 0x0406 96 #define PMDV_SERIAL7 0x0407 97 #define PMDV_NET0 0x0500 98 #define PMDV_NET1 0x0501 99 #define PMDV_NET2 0x0502 100 #define PMDV_NET3 0x0503 101 #define PMDV_PCMCIA0 0x0600 102 #define PMDV_PCMCIA1 0x0601 103 #define PMDV_PCMCIA2 0x0602 104 #define PMDV_PCMCIA3 0x0603 105 /* 0x0700 - 0x7fff Reserved */ 106 #define PMDV_BATT_BASE 0x8000 107 #define PMDV_BATT0 0x8001 108 #define PMDV_BATT1 0x8002 109 #define PMDV_BATT_ALL 0x80ff 110 /* 0x8100 - 0xdfff Reserved */ 111 /* 0xe000 - 0xefff OEM-defined power device IDs */ 112 /* 0xf000 - 0xffff Reserved */ 113 114 /* Power state */ 115 #define PMST_APMENABLED 0x0000 116 #define PMST_STANDBY 0x0001 117 #define PMST_SUSPEND 0x0002 118 #define PMST_OFF 0x0003 119 #define PMST_LASTREQNOTIFY 0x0004 120 #define PMST_LASTREQREJECT 0x0005 121 /* 0x0006 - 0x001f Reserved system states */ 122 /* 0x0020 - 0x003f OEM-defined system states */ 123 /* 0x0040 - 0x007f OEM-defined device states */ 124 /* 0x0080 - 0xffff Reserved device states */ 125 126 #if !defined(ASSEMBLER) && !defined(INITIALIZER) 127 128 /* C definitions */ 129 struct apmhook { 130 struct apmhook *ah_next; 131 int (*ah_fun)(void *ah_arg); 132 void *ah_arg; 133 const char *ah_name; 134 int ah_order; 135 }; 136 #define APM_HOOK_NONE (-1) 137 #define APM_HOOK_SUSPEND 0 138 #define APM_HOOK_RESUME 1 139 #define NAPM_HOOK 2 140 141 #ifdef _KERNEL 142 143 void apm_suspend(int state); 144 struct apmhook *apm_hook_establish (int apmh, struct apmhook *); 145 void apm_hook_disestablish (int apmh, struct apmhook *); 146 void apm_cpu_idle(void); 147 void apm_cpu_busy(void); 148 149 #endif 150 151 #endif /* !ASSEMBLER && !INITIALIZER */ 152 153 #define APM_MIN_ORDER 0x00 154 #define APM_MID_ORDER 0x80 155 #define APM_MAX_ORDER 0xff 156 157 /* power management event code */ 158 #define PMEV_NOEVENT 0x0000 159 #define PMEV_STANDBYREQ 0x0001 160 #define PMEV_SUSPENDREQ 0x0002 161 #define PMEV_NORMRESUME 0x0003 162 #define PMEV_CRITRESUME 0x0004 163 #define PMEV_BATTERYLOW 0x0005 164 #define PMEV_POWERSTATECHANGE 0x0006 165 #define PMEV_UPDATETIME 0x0007 166 #define PMEV_CRITSUSPEND 0x0008 167 #define PMEV_USERSTANDBYREQ 0x0009 168 #define PMEV_USERSUSPENDREQ 0x000a 169 #define PMEV_STANDBYRESUME 0x000b 170 #define PMEV_CAPABILITIESCHANGE 0x000c 171 /* 0x000d - 0x00ff Reserved system events */ 172 /* 0x0100 - 0x01ff Reserved device events */ 173 /* 0x0200 - 0x02ff OEM-defined APM events */ 174 /* 0x0300 - 0xffff Reserved */ 175 #define PMEV_DEFAULT 0xffffffff /* used for customization */ 176 177 #if !defined(ASSEMBLER) && !defined(INITIALIZER) 178 179 /* 180 * Old apm_info structure, returned by the APMIO_GETINFO_OLD ioctl. This 181 * is for backward compatibility with old executables. 182 */ 183 typedef struct apm_info_old { 184 u_int ai_major; /* APM major version */ 185 u_int ai_minor; /* APM minor version */ 186 u_int ai_acline; /* AC line status */ 187 u_int ai_batt_stat; /* Battery status */ 188 u_int ai_batt_life; /* Remaining battery life */ 189 u_int ai_status; /* Status of APM support (enabled/disabled) */ 190 } *apm_info_old_t; 191 192 /* 193 * Structure returned by the APMIO_GETINFO ioctl. 194 * 195 * In the comments below, the parenthesized numbers indicate the minimum 196 * value of ai_infoversion for which each field is valid. 197 */ 198 typedef struct apm_info { 199 u_int ai_infoversion; /* Indicates which fields are valid */ 200 u_int ai_major; /* APM major version (0) */ 201 u_int ai_minor; /* APM minor version (0) */ 202 u_int ai_acline; /* AC line status (0) */ 203 u_int ai_batt_stat; /* Battery status (0) */ 204 u_int ai_batt_life; /* Remaining battery life in percent (0) */ 205 int ai_batt_time; /* Remaining battery time in seconds (0) */ 206 u_int ai_status; /* True if enabled (0) */ 207 u_int ai_batteries; /* Number of batteries (1) */ 208 u_int ai_capabilities;/* APM Capabilities (1) */ 209 u_int ai_spare[6]; /* For future expansion */ 210 } *apm_info_t; 211 212 /* Battery flag */ 213 #define APM_BATT_HIGH 0x01 214 #define APM_BATT_LOW 0x02 215 #define APM_BATT_CRITICAL 0x04 216 #define APM_BATT_CHARGING 0x08 217 #define APM_BATT_NOT_PRESENT 0x10 218 #define APM_BATT_NO_SYSTEM 0x80 219 220 typedef struct apm_pwstatus { 221 u_int ap_device; /* Device code of battery */ 222 u_int ap_acline; /* AC line status (0) */ 223 u_int ap_batt_stat; /* Battery status (0) */ 224 u_int ap_batt_flag; /* Battery flag (0) */ 225 u_int ap_batt_life; /* Remaining battery life in percent (0) */ 226 int ap_batt_time; /* Remaining battery time in seconds (0) */ 227 } *apm_pwstatus_t; 228 229 struct apm_bios_arg { 230 uint32_t eax; 231 uint32_t ebx; 232 uint32_t ecx; 233 uint32_t edx; 234 uint32_t esi; 235 uint32_t edi; 236 }; 237 238 struct apm_event_info { 239 u_int type; 240 u_int index; 241 u_int spare[8]; 242 }; 243 244 #define APMIO_SUSPEND _IO('P', 1) 245 #define APMIO_GETINFO_OLD _IOR('P', 2, struct apm_info_old) 246 #define APMIO_ENABLE _IO('P', 5) 247 #define APMIO_DISABLE _IO('P', 6) 248 #define APMIO_HALTCPU _IO('P', 7) 249 #define APMIO_NOTHALTCPU _IO('P', 8) 250 #define APMIO_DISPLAY _IOW('P', 9, int) 251 #define APMIO_BIOS _IOWR('P', 10, struct apm_bios_arg) 252 #define APMIO_GETINFO _IOR('P', 11, struct apm_info) 253 #define APMIO_STANDBY _IO('P', 12) 254 #define APMIO_GETPWSTATUS _IOWR('P', 13, struct apm_pwstatus) 255 /* for /dev/apmctl */ 256 #define APMIO_NEXTEVENT _IOR('A', 100, struct apm_event_info) 257 #define APMIO_REJECTLASTREQ _IO('P', 101) 258 259 #endif /* !ASSEMBLER && !INITIALIZER */ 260 261 #endif /* !_X86_APM_BIOS_H_ */ 262