Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[cmdline] Add "poweroff" command
Modified-by: Michael Brown <mcb30@ipxe.org> Signed-off-by: Marin Hannache <git@mareo.fr> Signed-off-by: Michael Brown <mcb30@ipxe.org>
- Loading branch information
Showing
9 changed files
with
226 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* Copyright (C) 2013 Marin Hannache <ipxe@mareo.fr>. | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation; either version 2 of the | ||
* License, or any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
* 02110-1301, USA. | ||
*/ | ||
|
||
FILE_LICENCE ( GPL2_OR_LATER ); | ||
|
||
/** | ||
* @file | ||
* | ||
* Advanced Power Management | ||
* | ||
*/ | ||
|
||
#include <errno.h> | ||
#include <realmode.h> | ||
#include <ipxe/reboot.h> | ||
|
||
/** | ||
* Power off the computer using APM | ||
* | ||
* @ret rc Return status code | ||
*/ | ||
static int apm_poweroff ( void ) { | ||
uint16_t apm_version; | ||
uint16_t apm_signature; | ||
uint16_t apm_flags; | ||
uint16_t carry; | ||
|
||
/* APM check */ | ||
__asm__ __volatile__ ( REAL_CODE ( "int $0x15\n\t" | ||
"adc %%edx,0\n\t" ) | ||
: "=a" ( apm_version ), "=b" ( apm_signature ), | ||
"=c" ( apm_flags ), "=d" ( carry ) | ||
: "a" ( 0x5300 ), "b" ( 0x0000 ), | ||
"d" ( 0x0000 ) ); | ||
if ( carry ) { | ||
DBG ( "APM not present\n" ); | ||
return -ENOTSUP; | ||
} | ||
if ( apm_signature != 0x504d ) { /* signature 'PM' */ | ||
DBG ( "APM not present\n" ); | ||
return -ENOTSUP; | ||
} | ||
if ( apm_version < 0x0101 ) { /* Need version 1.1+ */ | ||
DBG ( "APM 1.1+ not supported\n" ); | ||
return -ENOTSUP; | ||
} | ||
if ( ( apm_flags & 0x8 ) == 0x8 ) { | ||
DBG ( "APM power management disabled\n" ); | ||
return -EPERM; | ||
} | ||
DBG2 ( "APM check completed\n" ); | ||
|
||
/* APM initialisation */ | ||
__asm__ __volatile__ ( REAL_CODE ( "int $0x15\n\t" | ||
"adc %%edx,0\n\t" ) | ||
: "=d" ( carry ) | ||
: "a" ( 0x5301 ), "b" ( 0x0000 ), | ||
"d" ( 0x0000 ) ); | ||
if ( carry ) { | ||
DBG ( "APM initialisation failed\n" ); | ||
return -EIO; | ||
} | ||
DBG2 ( "APM initialisation completed\n" ); | ||
|
||
/* Set APM driver version */ | ||
__asm__ __volatile__ ( REAL_CODE ( "int $0x15\n\t" | ||
"adc %%edx,0\n\t" ) | ||
: "=d" ( carry ) | ||
: "a" ( 0x530e ), "b" ( 0x0000 ), | ||
"c" ( 0x0101 ), "d" ( 0x0000 ) ); | ||
if ( carry ) { | ||
DBG ( "APM setting driver version failed\n" ); | ||
return -EIO; | ||
} | ||
DBG2 ( "APM driver version set\n" ); | ||
|
||
/* Setting power state to off */ | ||
__asm__ __volatile__ ( REAL_CODE ( "int $0x15\n\t" | ||
"adc %%edx,0\n\t" ) | ||
: "=d" ( carry ) | ||
: "a" ( 0x5307 ), "b" ( 0x0001 ), | ||
"c" ( 0x0003 ), "d" ( 0x0000) ); | ||
if ( carry ) { | ||
DBG ( "APM setting power state failed\n" ); | ||
return -ENOTTY; | ||
} | ||
|
||
/* Should never happen */ | ||
return -ECANCELED; | ||
} | ||
|
||
PROVIDE_REBOOT ( pcbios, poweroff, apm_poweroff ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (C) 2013 Marin Hannache <ipxe@mareo.fr>. | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation; either version 2 of the | ||
* License, or any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
* 02110-1301, USA. | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
#include <getopt.h> | ||
#include <ipxe/command.h> | ||
#include <ipxe/parseopt.h> | ||
#include <ipxe/reboot.h> | ||
|
||
FILE_LICENCE ( GPL2_OR_LATER ); | ||
|
||
/** @file | ||
* | ||
* Power off command | ||
* | ||
*/ | ||
|
||
/** "poweroff" options */ | ||
struct poweroff_options {}; | ||
|
||
/** "poweroff" option list */ | ||
static struct option_descriptor poweroff_opts[] = {}; | ||
|
||
/** "poweroff" command descriptor */ | ||
static struct command_descriptor poweroff_cmd = | ||
COMMAND_DESC ( struct poweroff_options, poweroff_opts, 0, 0, "" ); | ||
|
||
/** | ||
* The "poweroff" command | ||
* | ||
* @v argc Argument count | ||
* @v argv Argument list | ||
* @ret rc Return status code | ||
*/ | ||
static int poweroff_exec ( int argc, char **argv ) { | ||
struct poweroff_options opts; | ||
int rc; | ||
|
||
/* Parse options */ | ||
if ( ( rc = parse_options ( argc, argv, &poweroff_cmd, &opts ) ) != 0 ) | ||
return rc; | ||
|
||
/* Power off system */ | ||
rc = poweroff(); | ||
if ( rc != 0 ) | ||
printf ( "Could not power off: %s\n", strerror ( rc ) ); | ||
|
||
return rc; | ||
} | ||
|
||
/** "poweroff" command */ | ||
struct command poweroff_command __command = { | ||
.name = "poweroff", | ||
.exec = poweroff_exec, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters