1139790Simp/*- 26512Sphk * APM (Advanced Power Management) BIOS Device Driver 33263Sdg * 46512Sphk * Copyright (c) 1994-1995 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp> 56512Sphk * 63263Sdg * This software may be used, modified, copied, and distributed, in 73263Sdg * both source and binary form provided that the above copyright and 88876Srgrimes * these terms are retained. Under no circumstances is the author 98876Srgrimes * responsible for the proper functioning of this software, nor does 108876Srgrimes * the author assume any responsibility for damages incurred with its 113263Sdg * use. 123263Sdg * 133263Sdg * Aug, 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) 143264Sdg * 1550477Speter * $FreeBSD: releng/11.0/sys/x86/include/apm_bios.h 215140 2010-11-11 19:36:21Z jkim $ 163263Sdg */ 173263Sdg 18215140Sjkim#ifndef _X86_APM_BIOS_H_ 19215140Sjkim#define _X86_APM_BIOS_H_ 203263Sdg 2155205Speter#ifndef _KERNEL 2218444Sbde#include <sys/types.h> 2318444Sbde#endif 2418444Sbde#include <sys/ioccom.h> 2518444Sbde 263263Sdg/* BIOS id */ 273263Sdg#define APM_BIOS 0x53 2849197Smsmith#define APM_INT 0x15 293263Sdg 303263Sdg/* APM flags */ 313263Sdg#define APM_16BIT_SUPPORT 0x01 323263Sdg#define APM_32BIT_SUPPORT 0x02 333263Sdg#define APM_CPUIDLE_SLOW 0x04 343263Sdg#define APM_DISABLED 0x08 353263Sdg#define APM_DISENGAGED 0x10 363263Sdg 373263Sdg/* APM initializer physical address */ 383263Sdg#define APM_OURADDR 0x00080000 393263Sdg 403263Sdg/* APM functions */ 413263Sdg#define APM_INSTCHECK 0x00 423263Sdg#define APM_REALCONNECT 0x01 433263Sdg#define APM_PROT16CONNECT 0x02 443263Sdg#define APM_PROT32CONNECT 0x03 453263Sdg#define APM_DISCONNECT 0x04 463263Sdg#define APM_CPUIDLE 0x05 473263Sdg#define APM_CPUBUSY 0x06 483263Sdg#define APM_SETPWSTATE 0x07 493263Sdg#define APM_ENABLEDISABLEPM 0x08 503263Sdg#define APM_RESTOREDEFAULT 0x09 513263Sdg#define APM_GETPWSTATUS 0x0a 523263Sdg#define APM_GETPMEVENT 0x0b 533263Sdg#define APM_GETPWSTATE 0x0c 543263Sdg#define APM_ENABLEDISABLEDPM 0x0d 553263Sdg#define APM_DRVVERSION 0x0e 563263Sdg#define APM_ENGAGEDISENGAGEPM 0x0f 5737414Simp#define APM_GETCAPABILITIES 0x10 5837414Simp#define APM_RESUMETIMER 0x11 5937414Simp#define APM_RESUMEONRING 0x12 6037414Simp#define APM_TIMERREQUESTS 0x13 613263Sdg#define APM_OEMFUNC 0x80 623263Sdg 633263Sdg/* error code */ 643263Sdg#define APME_OK 0x00 653263Sdg#define APME_PMDISABLED 0x01 663263Sdg#define APME_REALESTABLISHED 0x02 673263Sdg#define APME_NOTCONNECTED 0x03 683263Sdg#define APME_PROT16ESTABLISHED 0x05 693263Sdg#define APME_PROT16NOTSUPPORTED 0x06 703263Sdg#define APME_PROT32ESTABLISHED 0x07 713263Sdg#define APME_PROT32NOTDUPPORTED 0x08 723263Sdg#define APME_UNKNOWNDEVICEID 0x09 733263Sdg#define APME_OUTOFRANGE 0x0a 743263Sdg#define APME_NOTENGAGED 0x0b 753263Sdg#define APME_CANTENTERSTATE 0x60 763263Sdg#define APME_NOPMEVENT 0x80 773263Sdg#define APME_NOAPMPRESENT 0x86 783263Sdg 793263Sdg 803263Sdg/* device code */ 813263Sdg#define PMDV_APMBIOS 0x0000 823263Sdg#define PMDV_ALLDEV 0x0001 833263Sdg#define PMDV_DISP0 0x0100 843263Sdg#define PMDV_DISP1 0x0101 8564251Siwasaki#define PMDV_DISPALL 0x01ff 863263Sdg#define PMDV_2NDSTORAGE0 0x0200 873263Sdg#define PMDV_2NDSTORAGE1 0x0201 883263Sdg#define PMDV_2NDSTORAGE2 0x0202 893263Sdg#define PMDV_2NDSTORAGE3 0x0203 903263Sdg#define PMDV_PARALLEL0 0x0300 913263Sdg#define PMDV_PARALLEL1 0x0301 923263Sdg#define PMDV_SERIAL0 0x0400 933263Sdg#define PMDV_SERIAL1 0x0401 943263Sdg#define PMDV_SERIAL2 0x0402 953263Sdg#define PMDV_SERIAL3 0x0403 963263Sdg#define PMDV_SERIAL4 0x0404 973263Sdg#define PMDV_SERIAL5 0x0405 983263Sdg#define PMDV_SERIAL6 0x0406 993263Sdg#define PMDV_SERIAL7 0x0407 1003263Sdg#define PMDV_NET0 0x0500 1013263Sdg#define PMDV_NET1 0x0501 1023263Sdg#define PMDV_NET2 0x0502 1033263Sdg#define PMDV_NET3 0x0503 1043263Sdg#define PMDV_PCMCIA0 0x0600 1053263Sdg#define PMDV_PCMCIA1 0x0601 1063263Sdg#define PMDV_PCMCIA2 0x0602 1073263Sdg#define PMDV_PCMCIA3 0x0603 10864615Sume/* 0x0700 - 0x7fff Reserved */ 10964615Sume#define PMDV_BATT_BASE 0x8000 11064615Sume#define PMDV_BATT0 0x8001 11164615Sume#define PMDV_BATT1 0x8002 11264615Sume#define PMDV_BATT_ALL 0x80ff 11364615Sume/* 0x8100 - 0xdfff Reserved */ 1143263Sdg/* 0xe000 - 0xefff OEM-defined power device IDs */ 1153263Sdg/* 0xf000 - 0xffff Reserved */ 1163263Sdg 1173263Sdg/* Power state */ 1183263Sdg#define PMST_APMENABLED 0x0000 1193263Sdg#define PMST_STANDBY 0x0001 1203263Sdg#define PMST_SUSPEND 0x0002 1213263Sdg#define PMST_OFF 0x0003 1223263Sdg#define PMST_LASTREQNOTIFY 0x0004 1233263Sdg#define PMST_LASTREQREJECT 0x0005 1243263Sdg/* 0x0006 - 0x001f Reserved system states */ 1253263Sdg/* 0x0020 - 0x003f OEM-defined system states */ 1263263Sdg/* 0x0040 - 0x007f OEM-defined device states */ 1273263Sdg/* 0x0080 - 0xffff Reserved device states */ 1283263Sdg 1296512Sphk#if !defined(ASSEMBLER) && !defined(INITIALIZER) 1303263Sdg 1313263Sdg/* C definitions */ 1326512Sphkstruct apmhook { 1336512Sphk struct apmhook *ah_next; 13492761Salfred int (*ah_fun)(void *ah_arg); 1356512Sphk void *ah_arg; 1366512Sphk const char *ah_name; 1376512Sphk int ah_order; 1386512Sphk}; 1396512Sphk#define APM_HOOK_NONE (-1) 1406512Sphk#define APM_HOOK_SUSPEND 0 1416512Sphk#define APM_HOOK_RESUME 1 1426512Sphk#define NAPM_HOOK 2 1433263Sdg 14455205Speter#ifdef _KERNEL 14537414Simp 14637414Simpvoid apm_suspend(int state); 1476512Sphkstruct apmhook *apm_hook_establish (int apmh, struct apmhook *); 1486512Sphkvoid apm_hook_disestablish (int apmh, struct apmhook *); 1493263Sdgvoid apm_cpu_idle(void); 1503263Sdgvoid apm_cpu_busy(void); 1513263Sdg 15255205Speter#endif 15337414Simp 1546512Sphk#endif /* !ASSEMBLER && !INITIALIZER */ 1553263Sdg 1563263Sdg#define APM_MIN_ORDER 0x00 1573263Sdg#define APM_MID_ORDER 0x80 1583263Sdg#define APM_MAX_ORDER 0xff 1593263Sdg 1603263Sdg/* power management event code */ 1613263Sdg#define PMEV_NOEVENT 0x0000 1623263Sdg#define PMEV_STANDBYREQ 0x0001 1633263Sdg#define PMEV_SUSPENDREQ 0x0002 1643263Sdg#define PMEV_NORMRESUME 0x0003 1653263Sdg#define PMEV_CRITRESUME 0x0004 1663263Sdg#define PMEV_BATTERYLOW 0x0005 1673263Sdg#define PMEV_POWERSTATECHANGE 0x0006 1683263Sdg#define PMEV_UPDATETIME 0x0007 1693263Sdg#define PMEV_CRITSUSPEND 0x0008 1703263Sdg#define PMEV_USERSTANDBYREQ 0x0009 1713263Sdg#define PMEV_USERSUSPENDREQ 0x000a 1723263Sdg#define PMEV_STANDBYRESUME 0x000b 17337414Simp#define PMEV_CAPABILITIESCHANGE 0x000c 17437414Simp/* 0x000d - 0x00ff Reserved system events */ 1753263Sdg/* 0x0100 - 0x01ff Reserved device events */ 1763263Sdg/* 0x0200 - 0x02ff OEM-defined APM events */ 1773263Sdg/* 0x0300 - 0xffff Reserved */ 1783263Sdg#define PMEV_DEFAULT 0xffffffff /* used for customization */ 1793263Sdg 1806512Sphk#if !defined(ASSEMBLER) && !defined(INITIALIZER) 1813263Sdg 18231126Sjdp/* 18331126Sjdp * Old apm_info structure, returned by the APMIO_GETINFO_OLD ioctl. This 18431126Sjdp * is for backward compatibility with old executables. 18531126Sjdp */ 18631126Sjdptypedef struct apm_info_old { 1873263Sdg u_int ai_major; /* APM major version */ 1883263Sdg u_int ai_minor; /* APM minor version */ 1893263Sdg u_int ai_acline; /* AC line status */ 1903263Sdg u_int ai_batt_stat; /* Battery status */ 1913263Sdg u_int ai_batt_life; /* Remaining battery life */ 19214608Snate u_int ai_status; /* Status of APM support (enabled/disabled) */ 19331126Sjdp} *apm_info_old_t; 19431126Sjdp 19531126Sjdp/* 19631126Sjdp * Structure returned by the APMIO_GETINFO ioctl. 19731126Sjdp * 19831126Sjdp * In the comments below, the parenthesized numbers indicate the minimum 19931126Sjdp * value of ai_infoversion for which each field is valid. 20031126Sjdp */ 20131126Sjdptypedef struct apm_info { 20231126Sjdp u_int ai_infoversion; /* Indicates which fields are valid */ 20331126Sjdp u_int ai_major; /* APM major version (0) */ 20431126Sjdp u_int ai_minor; /* APM minor version (0) */ 20531126Sjdp u_int ai_acline; /* AC line status (0) */ 20631126Sjdp u_int ai_batt_stat; /* Battery status (0) */ 20731126Sjdp u_int ai_batt_life; /* Remaining battery life in percent (0) */ 20831126Sjdp int ai_batt_time; /* Remaining battery time in seconds (0) */ 20931126Sjdp u_int ai_status; /* True if enabled (0) */ 21037414Simp u_int ai_batteries; /* Number of batteries (1) */ 21137414Simp u_int ai_capabilities;/* APM Capabilities (1) */ 21237414Simp u_int ai_spare[6]; /* For future expansion */ 2133263Sdg} *apm_info_t; 2143263Sdg 21564615Sume/* Battery flag */ 21664615Sume#define APM_BATT_HIGH 0x01 21764615Sume#define APM_BATT_LOW 0x02 21864615Sume#define APM_BATT_CRITICAL 0x04 21964615Sume#define APM_BATT_CHARGING 0x08 22064615Sume#define APM_BATT_NOT_PRESENT 0x10 22164615Sume#define APM_BATT_NO_SYSTEM 0x80 22264615Sume 22364615Sumetypedef struct apm_pwstatus { 22464615Sume u_int ap_device; /* Device code of battery */ 22564615Sume u_int ap_acline; /* AC line status (0) */ 22664615Sume u_int ap_batt_stat; /* Battery status (0) */ 22764615Sume u_int ap_batt_flag; /* Battery flag (0) */ 22864615Sume u_int ap_batt_life; /* Remaining battery life in percent (0) */ 22964615Sume int ap_batt_time; /* Remaining battery time in seconds (0) */ 23064615Sume} *apm_pwstatus_t; 23164615Sume 23249292Smsmithstruct apm_bios_arg { 233197536Sjkim uint32_t eax; 234197536Sjkim uint32_t ebx; 235197536Sjkim uint32_t ecx; 236197536Sjkim uint32_t edx; 237197536Sjkim uint32_t esi; 238197536Sjkim uint32_t edi; 23949292Smsmith}; 24049292Smsmith 24149197Smsmithstruct apm_event_info { 24249197Smsmith u_int type; 24348735Siwasaki u_int index; 24448735Siwasaki u_int spare[8]; 24548735Siwasaki}; 24648735Siwasaki 2473263Sdg#define APMIO_SUSPEND _IO('P', 1) 24831126Sjdp#define APMIO_GETINFO_OLD _IOR('P', 2, struct apm_info_old) 2493263Sdg#define APMIO_ENABLE _IO('P', 5) 2503263Sdg#define APMIO_DISABLE _IO('P', 6) 2513263Sdg#define APMIO_HALTCPU _IO('P', 7) 2523263Sdg#define APMIO_NOTHALTCPU _IO('P', 8) 25321362Snate#define APMIO_DISPLAY _IOW('P', 9, int) 25449292Smsmith#define APMIO_BIOS _IOWR('P', 10, struct apm_bios_arg) 25531126Sjdp#define APMIO_GETINFO _IOR('P', 11, struct apm_info) 25637414Simp#define APMIO_STANDBY _IO('P', 12) 25764615Sume#define APMIO_GETPWSTATUS _IOWR('P', 13, struct apm_pwstatus) 25848735Siwasaki/* for /dev/apmctl */ 25948735Siwasaki#define APMIO_NEXTEVENT _IOR('A', 100, struct apm_event_info) 26048735Siwasaki#define APMIO_REJECTLASTREQ _IO('P', 101) 2613263Sdg 2626512Sphk#endif /* !ASSEMBLER && !INITIALIZER */ 2633263Sdg 264215140Sjkim#endif /* !_X86_APM_BIOS_H_ */ 265