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
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
29 * Advanced Power Management
35 #include <ipxe/reboot.h>
38 * Power off the computer using APM
40 * @ret rc Return status code
42 static int apm_poweroff ( void ) {
44 uint16_t apm_signature;
49 __asm__ __volatile__ ( REAL_CODE ( "int $0x15\n\t"
51 : "=a" ( apm_version ), "=b" ( apm_signature ),
52 "=c" ( apm_flags ), "=d" ( carry )
53 : "a" ( 0x5300 ), "b" ( 0x0000 ),
56 DBG ( "APM not present\n" );
59 if ( apm_signature != 0x504d ) { /* signature 'PM' */
60 DBG ( "APM not present\n" );
63 if ( apm_version < 0x0101 ) { /* Need version 1.1+ */
64 DBG ( "APM 1.1+ not supported\n" );
67 if ( ( apm_flags & 0x8 ) == 0x8 ) {
68 DBG ( "APM power management disabled\n" );
71 DBG2 ( "APM check completed\n" );
73 /* APM initialisation */
74 __asm__ __volatile__ ( REAL_CODE ( "int $0x15\n\t"
77 : "a" ( 0x5301 ), "b" ( 0x0000 ),
80 DBG ( "APM initialisation failed\n" );
83 DBG2 ( "APM initialisation completed\n" );
85 /* Set APM driver version */
86 __asm__ __volatile__ ( REAL_CODE ( "int $0x15\n\t"
89 : "a" ( 0x530e ), "b" ( 0x0000 ),
90 "c" ( 0x0101 ), "d" ( 0x0000 ) );
92 DBG ( "APM setting driver version failed\n" );
95 DBG2 ( "APM driver version set\n" );
97 /* Setting power state to off */
98 __asm__ __volatile__ ( REAL_CODE ( "int $0x15\n\t"
101 : "a" ( 0x5307 ), "b" ( 0x0001 ),
102 "c" ( 0x0003 ), "d" ( 0x0000) );
104 DBG ( "APM setting power state failed\n" );
108 /* Should never happen */
112 PROVIDE_REBOOT ( pcbios, poweroff, apm_poweroff );