From: scooper@psi.rutgers.edu (Simon P. Cooper)
Newsgroups: comp.os.linux
Subject: Making Linux APM compliant for laptops?
Date: 31 Aug 92 23:52:27 GMT
Organization: Rutgers Univ., New Brunswick, N.J.
X-Mn-Key: NORMAL
X-Mn-Key: LAPTOPS

I mailed this to "linux-activists".  Others may be interested...
(There is a laptops thread on linux-activists)

> Date: Fri, 28 Aug 92 23:27:58 -0400
> From: tytso@athena.mit.edu (Theodore Ts'o)
> Sender: owner-linux-activists@joker.cs.hut.fi
> X-Note1: Remember to put 'X-Mn-Key: normal' to your mail body or header
> X-Mn-Key: NORMAL
> Address: 1 Amherst St., Cambridge, MA 02139
> Phone: (617) 253-8091
>
>    Date: 	Sat, 29 Aug 1992 06:01:15 +0300
>    From: Ed Carp <erc@khijol.upl.com>
>
>    I wonder how much hassle it would be to make linux APM-compliant?
>
>    For those who don't know, APM is the Intel/Microsoft name for Advanced
>    Power Management, a system that works to significantly increase battery
>    life in laptops.
>
> Does anyone know where to find the *specs* for APM?  Hopefully APM is
> speced out at a hardware level (send value X to port Y), instead of at
> the BIOS level (do INT 23 with AL set to 5).  If it's the second, it
> would be much harder to support APM than if it had a consistent hardware
> interface.  Unfortunately, knowing Intel/Microsoft, I doubt they did the
> right thing....
>
>							   - Ted

   I have already spent a few hours snooping about.  The only place I
found information so far is the excellent: "Comprehensive list of
interrupt calls" by Ralf Brown.  I also skimmed the "pink coloured
cover" edition of the "PC sourcebook" by Thom Hoggan (sp?) but didn't
find anything useful.  I'd be the first to admit that this cannot be
considered thorough research on the problem!  Anyway here is the little
I've found out so far...

---rbrown.txt---
Public Domain/Freeware/Shareware by Ralf Brown:

The MSDOS Interrupt List
        A comprehensive listing of more than 4070 functions available
        through interrupt calls on IBM PCs and compatibles.  Includes both
        documented and undocumented functions.
        Current version: INTER31A (release 31, 7/12/92)
                         INTER31B
                         INTER31C (conversion programs)
....
----------------

You can get your own copy from,

	wuarchive.wustl.edu:/mirrors/msdos/info/inter31{a,b,c}.zip

   There are some listings for power management routines.  (I have
attached the text for some of the core functions at the end of my
message ...)  The support is in the BIOS :(, fear not though - there are
provisions for 32 bit protected mode operation.

   The beast I am working on is a Zenith ZNOTE-320L and the INSTALLATION
CHECK interrupt claims that 32 bit protected mode support exists :) :)

    However, not knowing exactly how all the functions are supposed to
operate together I am "debugging" a live Laptop under DOS and making
notes and tweeks.  Quite a bit seems to be going on :)

NOTE: To any listening vendors that sell laptops: If I get power
management working on your laptop I just might rush out and buy one.  I
suspect many others would do likewise!  Offer to send me the specs if I
call :).  I have called Zenith, but I think that they misunderstood my
questions :( Persistence is a virtue!

   I've created a "laptops" thread.  I am guessing that there are number
of people interested in this line of development ...

   If anyone reading this happens to have a copy of the APM spec in a
machine readable form then I'd appreciate a copy.

Simon Cooper
Systems Coordinator
Laboratory for Visiometrics and Modeling
-------------------------------------------------------------------------------
Snail-mail: CAIP Center, Rutgers University, E-mail: scooper@vizlab.rutgers.edu
	    Frelinghuysen Road, PO Box 1390
	    Piscataway. NJ 08855-1390
Telephone: (+1) 908 932 0540                    Fax: (+1) 908 932 4775
-------------------------------------------------------------------------------

Reproduced without permission from Ralf Brown's interrupt list...

----------155300BX0000-----------------------
INT 15 - Advanced Power Management Specification - INSTALLATION CHECK
	AX = 5300h
	BX = 0000h (device ID of system BIOS)
Return: CF clear if successful
	    AH = major version (BCD)
	    AL = minor version (BCD)
	    BX = 504Dh ("PM")
	    CX = flags
	        bit 0: 16-bit protected mode interface supported
		bit 1: 32-bit protected mode interface supported
		bit 2: CPU idle call reduces processor speed
		bit 3: BIOS power management disabled
		bits 4-7 reserved
	CF set on error
	    AH = error code (86h) (see below)

Values for error code:
 01h	power management functionality disabled
 02h	interface connection already in effect
 03h	interface not connected
 04h	real-mode interface not connected
 05h	16-bit protected-mode interface already connected
 06h	16-bit protected-mode interface not supported
 07h	32-bit protected-mode interface already connected
 08h	32-bit protected-mode interface not supported
 09h	unrecognized device ID
 0Ah	invalid parameter value in CX
 0Bh-1Fh reserved for other interface and general errors
 20h-3Fh reserved for CPU errors
 40h-5Fh reserved for device errors
 60h	can't enter requested state
 61h-7Fh reserved for other system errors
 80h	no power management events pending
 81h-85h reserved for other power management event errors
 86h	APM not present
 87h-9Fh reserved for other power management event errors
----------155301BX0000-----------------------
INT 15 - Advanced Power Management Specification - CONNECT REAL-MODE INTERFACE
	AX = 5301h
	BX = 0000h (device ID of system BIOS)
Return: CF clear if successful
	CF set on error
	    AH = error code (02h,09h) (see AX=5300h)
SeeAlso: AX=5302h,AX=5303h,AX=5304h
----------155302BX0000-----------------------
INT 15 R - Advanced Power Management Spec - CONNECT 16-BIT PROTMODE INTERFACE
	AX = 5302h
	BX = 0000h (device ID of system BIOS)
Return: CF clear if successful
	    AX = real-mode segment base address of protected-mode 16-bit code
	    	segment
	    BX = offset of entry point
	    CX = real-mode segment base address of protected-mode 16-bit data
	    	segment
	CF set on error
	    AH = error code (05h,06h,09h) (see AX=5300h)
Notes:	the caller must initialize two consecutive descriptors with the
	  returned segment base addresses; these descriptors must be valid
	  whenever the protected-mode interface is called, and will have
	  their limits arbitrarily set to 64K.
	the protected mode interface is invoked by making a far call with the
	  same register values as for INT 15; it must be invoked while CPL=0,
	  the code segment descriptor must have a DPL of 0, the stack must be
	  in a 16-bit segment and have enough room for BIOS use and possible
	  interrupts, and the current I/O permission bit map must allow access
	  to the I/O ports used for power management.
	functions 00h-03h are not available from protected mode
SeeAlso: AX=5301h,AX=5303h,AX=5304h
----------155303BX0000-----------------------
INT 15 - Advanced Power Management Spec - CONNECT 32-BIT PROTMODE INTERFACE
	AX = 5303h
	BX = 0000h (device ID of system BIOS)
Return: CF clear if successful
	    AX = real-mode segment base address of protected-mode 32-bit code
	    	segment
	    EBX = offset of entry point
	    CX = real-mode segment base address of protected-mode 16-bit code
	    	segment
	    DX = real-mode segment base address of protected-mode 16-bit data
	    	segment
	CF set on error
	    AH = error code (07h,08h,09h) (see AX=5300h)
Notes:	the caller must initialize three consecutive descriptors with the
	  returned segment base addresses for 32-bit code, 16-bit code, and
	  16-bit data, respectively; these descriptors must be valid whenever
	  the protected-mode interface is called, and will have their limits
	  arbitrarily set to 64K.
	the protected mode interface is invoked by making a far call to the
	  32-bit code segment with the same register values as for INT 15; it
	  must be invoked while CPL=0, the code segment descriptor must have a
	  DPL of 0, the stack must be in a 32-bit segment and have enough room
	  for BIOS use and possible interrupts, and the current I/O permission
	  bit map must allow access to the I/O ports used for power management.
	functions 00h-03h are not available from protected mode
SeeAlso: AX=5301h,AX=5302h,AX=5304h
----------155304BX0000-----------------------
INT 15 - Advanced Power Management Specification - DISCONNECT INTERFACE
	AX = 5304h
	BX = 0000h (device ID of system BIOS)
Return: CF clear if successful
	CF set on error
	    AH = error code (03h,09h) (see AX=5300h)
SeeAlso: AX=5301h,AX=5302h,AX=5303h
----------155305-----------------------------
INT 15 - Advanced Power Management Specification - CPU IDLE
	AX = 5305h
Return: after system leaves idle state
	CF clear
Notes:	call when the system is idle and should be suspended until the next
	  system event or interrupt
	should not be called from within a hardware interrupt handler to avoid
	  reentrance problems
	if an interrupt causes the system to resume normal processing, the
	  interrupt may or may not have been handled when the BIOS returns
	  from this call; thus, the caller should allow interrupts on return
	interrupt handlers may not retain control if the BIOS allows
	  interrupts while in idle mode even if they are able to determine
	  that they were called from idle mode
	the caller should issue this call continuously in a loop until it needs
	  to perform some processing of its own
SeeAlso: AX=1000h,AX=5306h,INT 2F/AX=1680h
----------155306-----------------------------
INT 15 - Advanced Power Management Specification - CPU BUSY
	AX = 5306h
Return: CF clear
Notes:	called to ensure that the system runs at full speed even on systems
	  where the BIOS is unable to recognize increased activity (especially
	  if interrupts are hooked by other programs and not chained to the
	  BIOS)
	this call may be made even when the system is already running at full
	  speed, but it will create unnecessary overhead
	should not be called from within a hardware interrupt handler to avoid
	  reentrance problems
SeeAlso: AX=5305h
----------155307-----------------------------
INT 15 - Advanced Power Management Specification - SET POWER STATE
	AX = 5307h
	BX = device ID (see below)
	CX = system state ID
	    0000h ready (not supported for device ID 0001h)
	    0001h stand-by
	    0002h suspend
	    0003h off (not supported for device ID 0001h)
	    0004h-FFFFh reserved
Return: CF clear if successful
	CF set on error
	    AH = error code (01h,09h,0Ah,60h) (see AX=5300h)
Note:	should not be called from within a hardware interrupt handler to avoid
	  reentrance problems

Values for device IDs:
 0000h	system BIOS
 0001h	all devices for which the system BIOS manages power
 01xxh	display (01FFh for all attached display devices)
 02xxh	secondary storage (02FFh for all attached secondary storage devices)
 03xxh	parallel ports (03FFh for all attached parallel ports)
 04xxh	serial ports (04FFh for all attached serial ports)
 0500h-FFFFh reserved
----------155307BX0001-----------------------
INT 15 - Advanced Power Management Specification - SYSTEM STAND-BY
	AX = 5307h
	BX = 0001h
	CX = 0001h
Return: CF clear
Notes:	puts the entire system into stand-by mode; normally called in response
	  to a System Stand-by Request notification after any necessary
	  processing, but may also be invoked at the caller's discretion
	should not be called from within a hardware interrupt handler to avoid
	  reentrance problems
	the stand-by state is typically exited on an interrupt
SeeAlso: AX=4280h,AX=5307h/BX=0001h/CX=0002h,AX=530Bh
----------155307BX0001-----------------------
INT 15 - Advanced Power Management Specification - SUSPEND SYSTEM
	AX = 5307h
	BX = 0001h
	CX = 0002h
Return: after system is resumed
	CF clear
Notes:	puts the entire system into a low-power suspended state; normally
	  called in response to a Suspend System Request notification after
	  any necessary processing, but may also be invoked at the caller's
	  discretion
	should not be called from within a hardware interrupt handler to avoid
	  reentrance problems
	the caller may need to update its date and time values because the
	  system could have been suspended for a long period of time
SeeAlso: AX=5307h/BX=0001h/CX=0001h,AX=530Bh
----------155308BXFFFF-----------------------
INT 15 - Advanced Power Management Spec - ENABLE/DISABLE POWER MANAGEMENT
	AX = 5308h
	BX = FFFFh
	CX = new state
	    0000h disabled
	    0001h enabled
Return: CF clear if successful
	CF set on error
	    AH = error code (01h,09h,0Ah) (see AX=5300h)
Notes:	when power management is disabled, the system BIOS will not
	  automatically power down devices, enter stand-by or suspended mode,
	  or perform any power-saving actions in response to AX=5305h calls
	should not be called from within a hardware interrupt handler to avoid
	  reentrance problems
SeeAlso: AX=5309h
----------155309BXFFFF-----------------------
INT 15 - Advanced Power Management Specification - RESTORE POWER-ON DEFAULTS
	AX = 5309h
	BX = FFFFh
Return: CF clear if successful
	CF set on error
	    AH = error code (09h) (see AX=5300h)
Note:	should not be called from within a hardware interrupt handler to avoid
	  reentrance problems
SeeAlso: AX=5308h
----------15530ABX0001-----------------------
INT 15 - Advanced Power Management Specification - GET POWER STATUS
	AX = 530Ah
	BX = 0001h
Return: CF clear if successful
	    BH = AC line status
	        00h off-line
		01h on-line
		FFh unknown
		other reserved
	    BL = battery status
	        00h high
		01h low
		02h critical
		03h charging
		FFh unknown
		other reserved
	    CL = remaining battery life
	        00h-64h (0-100) percentage of full charge
		FFh unknown
	CF set on error
	    AH = error code (09h) (see AX=5300h)
Note:	should not be called from within a hardware interrupt handler to avoid
	  reentrance problems
----------15530B-----------------------------
INT 15 - Advanced Power Management Specification - GET POWER MANAGEMENT EVENT
	AX = 530Bh
Return: CF clear if successful
	    BX = event code
	        0001h system stand-by request
		0002h system suspend request
		0003h normal resume system notification
		0004h critical resume system notification
		0005h battery low notification
	CF set on error
	    AH = error code (03h,80h) (see AX=5300h)
Notes:	although power management events are often asynchronous, notification
	  will not be made until polled via this call to permit software to
	  only receive event notification when it is prepared to process
	  power management events; since these events are not very time-
	  critical, it should be sufficient to poll once or twice per second
	the critical resume notification is made after the system resumes
	  from an emergency suspension; normally, the system BIOS only notifies
	  its partner that it wishes to suspend and relies on the partner to
	  actually request the suspension, but no notification is made on an
	  emergency suspension
	should not be called from within a hardware interrupt handler to avoid
	  reentrance problems
SeeAlso: AX=5307h,AX=5307h/BX=0001h/CX=0001h,AX=5307h/BX=0001h/CX=0002h
Newsgroups: comp.os.linux