2
* Copyright (C) 2013 Marin Hannache <ipxe@mareo.fr>.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation; either version 2 of the
7
* License, or any later version.
9
* This program is distributed in the hope that it will be useful, but
10
* WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20
FILE_LICENCE ( GPL2_OR_LATER );
25
* Advanced Power Management
31
#include <ipxe/reboot.h>
34
* Power off the computer using APM
36
* @ret rc Return status code
38
static int apm_poweroff ( void ) {
40
uint16_t apm_signature;
45
__asm__ __volatile__ ( REAL_CODE ( "int $0x15\n\t"
47
: "=a" ( apm_version ), "=b" ( apm_signature ),
48
"=c" ( apm_flags ), "=d" ( carry )
49
: "a" ( 0x5300 ), "b" ( 0x0000 ),
52
DBG ( "APM not present\n" );
55
if ( apm_signature != 0x504d ) { /* signature 'PM' */
56
DBG ( "APM not present\n" );
59
if ( apm_version < 0x0101 ) { /* Need version 1.1+ */
60
DBG ( "APM 1.1+ not supported\n" );
63
if ( ( apm_flags & 0x8 ) == 0x8 ) {
64
DBG ( "APM power management disabled\n" );
67
DBG2 ( "APM check completed\n" );
69
/* APM initialisation */
70
__asm__ __volatile__ ( REAL_CODE ( "int $0x15\n\t"
73
: "a" ( 0x5301 ), "b" ( 0x0000 ),
76
DBG ( "APM initialisation failed\n" );
79
DBG2 ( "APM initialisation completed\n" );
81
/* Set APM driver version */
82
__asm__ __volatile__ ( REAL_CODE ( "int $0x15\n\t"
85
: "a" ( 0x530e ), "b" ( 0x0000 ),
86
"c" ( 0x0101 ), "d" ( 0x0000 ) );
88
DBG ( "APM setting driver version failed\n" );
91
DBG2 ( "APM driver version set\n" );
93
/* Setting power state to off */
94
__asm__ __volatile__ ( REAL_CODE ( "int $0x15\n\t"
97
: "a" ( 0x5307 ), "b" ( 0x0001 ),
98
"c" ( 0x0003 ), "d" ( 0x0000) );
100
DBG ( "APM setting power state failed\n" );
104
/* Should never happen */
108
PROVIDE_REBOOT ( pcbios, poweroff, apm_poweroff );