APM

From OSDev.wiki
Jump to navigation Jump to search

APM (Advanced Power Management) is a Power Management standard, developed by Intel and Microsoft, which allows the operating system to control the amount of power sent to devices. ACPI replaces APM as the main power management system for operating systems, mainly because SMP and APM do not mix well.

APM Initialization

The APM standard defines three interfaces through which it the APM BIOS and the operating system can communicate. They are the Real Mode Interface, the 16bit Protected Mode Interface, and the 32bit Protected Mode Interface. Only one of the interfaces may be in use at any given time. Before any of the interfaces can be used, the operating system must check if AMP is actually supported (many very new computers don't support AMP anymore) and if it is, connect to one of its interfaces. It is a good idea to send a disconnect command prior to connecting to an interface.

Installation Check

This function checks if AMP is even supported. It must be preformed in Real Mode (or vm86 mode).

;preform an installation check
mov ah,53h            ;this is an APM command
mov al,00h            ;installation check command
xor bx,bx             ;device id (0 = APM BIOS)
int 15h               ;call the BIOS function through interrupt 15h
jc APM_error          ;if the carry flag is set there was an error
                      ;the function was successful
                      ;AX = APM version number
                          ;AH = Major revision number (in BCD format)
                          ;AL = Minor revision number (also BCD format)
                      ;BX = ASCII characters "P" (in BH) and "M" (in BL)
                      ;CX = APM flags (see the official documentation for more details)

Connecting to an interface

This function connects to an APM interface based on the value of interface_number which should be one of the following:

01h = Real Mode Interface
02h = 16bit Protected Mode Interface
03h = 32bit Protected Mode Interface

It must be preformed in Real Mode (or vm86 mode).

;connect to an APM interface
mov ah,53h               ;this is an APM command
mov al,[interface_number];see above description
xor bx,bx                ;device id (0 = APM BIOS)
int 15h                  ;call the BIOS function through interrupt 15h
jc APM_error             ;if the carry flag is set there was an error
                         ;the function was successful
                         ;The return values are different for each interface.
                         ;The Real Mode Interface returns nothing.
                         ;See the official documentation for the 
                         ;return values for the protected mode interfaces.

Disconnecting from an Interface

This function will disconnect from whatever interface is connected when it is called. If no interface is connected or an error occurs it will set the carry flag upon return. It may be preformed in any APM interface mode.

;disconnect from any APM interface
mov ah,53h               ;this is an APM command
mov al,04h               ;interface disconnect command
xor bx,bx                ;device id (0 = APM BIOS)
int 15h                  ;call the BIOS function through interrupt 15h
jc .disconnect_error            ;if the carry flag is set see what the fuss is about. 
jmp .no_error

.disconnect_error:       ;the error code is in ah.
cmp ah,03h               ;if the error code is anything but 03h there was an error.
jne APM_error            ;the error code 03h means that no interface was connected in the first place.
                         
.no_error:
                         ;the function was successful
                         ;Nothing is returned.

Controlling Devices

After the operating system has connected to an APM interface it can begin to control the power state of various devices in the computer. Before a given device can be controlled, however, power management for that device must be enabled. Only then can the actual power state of the device be set.

Enabling Power Management

This function will enable power management for all devices. This is, by far, faster than enabling power management for each device separately.

;Enable power management for all devices
mov ah,53h              ;this is an APM command
mov al,08h              ;Change the state of power management...
mov bx,0001h            ;...on all devices to...
mov cx,0001h            ;...power management on.
int 15h                 ;call the BIOS function through interrupt 15h
jc APM_error            ;if the carry flag is set there was an error	

To enable power management for a specific device, find the device number for the device in the APM documentation, and put the device number in bx instead of 0001h.

Setting Power States

This function will set the power state of every device to the value of power_state which may be one of the following.

01h = Standby
02h = Suspend
03h = Off

20h...7Fh = OEM-defined power states 

To set the power state for a specific device, find the device number for the device in the APM documentation, and put the device number in bx instead of 0001h.

;Set the power state for all devices
mov ah,53h              ;this is an APM command
mov al,07h              ;Set the power state...
mov bx,0001h            ;...on all devices to...
mov cx,[power_state]    ;see above
int 15h                 ;call the BIOS function through interrupt 15h
jc APM_error            ;if the carry flag is set there was an error	

APM Reliability

Because APM is used by calling BIOS functions, it is much simpler to implement in an operating system. These BIOS functions, however, may be buggy or broken on some BIOSes. This is one of the main reasons why ACPI has succeeded.

See Also

Articles

External Links