iPXE
efi_reboot.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2013 Michael Brown <mbrown@fensystems.co.uk>.
3 *
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.
8 *
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.
13 *
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
17 * 02110-1301, USA.
18 *
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.
22 */
23
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25FILE_SECBOOT ( PERMITTED );
26
27/**
28 * @file
29 *
30 * EFI reboot mechanism
31 *
32 */
33
34#include <errno.h>
35#include <string.h>
36#include <ipxe/efi/efi.h>
38#include <ipxe/reboot.h>
39
40/**
41 * Reboot system
42 *
43 * @v flags Reboot flags
44 */
45static void efi_reboot ( int flags ) {
46 EFI_RUNTIME_SERVICES *rs = efi_systab->RuntimeServices;
48 UINT64 osind;
49 UINT32 attrs;
51 EFI_STATUS efirc;
52 int rc;
53
54 /* Request boot to firmware setup, if applicable */
55 if ( flags & REBOOT_SETUP ) {
60 if ( ( efirc = rs->SetVariable ( wname, &efi_global_variable,
61 attrs, sizeof ( osind ),
62 &osind ) ) != 0 ) {
63 rc = -EEFI ( efirc );
64 DBGC ( efi_systab, "EFI could not set %ls: %s\n",
65 wname, strerror ( rc ) );
66 /* Continue to reboot anyway */
67 }
68 }
69
70 /* Use runtime services to reset system */
72 rs->ResetSystem ( type, 0, 0, NULL );
73}
74
75/**
76 * Power off system
77 *
78 * @ret rc Return status code
79 */
80static int efi_poweroff ( void ) {
81 EFI_RUNTIME_SERVICES *rs = efi_systab->RuntimeServices;
82
83 /* Use runtime services to power off system */
84 rs->ResetSystem ( EfiResetShutdown, 0, 0, NULL );
85
86 /* Should never happen */
87 return -ECANCELED;
88}
89
unsigned long long UINT64
8-byte unsigned value.
unsigned short CHAR16
2-byte Character.
unsigned int UINT32
4-byte unsigned value.
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
GUID for EFI (NVRAM) Variables.
#define EFI_OS_INDICATIONS_VARIABLE_NAME
Allows the OS to request the firmware to enable certain features and to take certain actions.
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
#define EFI_VARIABLE_BOOTSERVICE_ACCESS
#define EFI_VARIABLE_RUNTIME_ACCESS
EFI_RESET_TYPE
Enumeration of reset types.
@ EfiResetCold
Used to induce a system-wide reset.
@ EfiResetShutdown
Used to induce an entry into a power state equivalent to the ACPI G2/S5 or G3 state.
@ EfiResetWarm
Used to induce a system-wide initialization.
#define EFI_VARIABLE_NON_VOLATILE
Attributes of variable.
#define EFI_OS_INDICATIONS_BOOT_TO_FW_UI
Definition UefiSpec.h:1844
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
EFI_GUID efi_global_variable
Global variable GUID.
Definition efi_guid.c:469
static void efi_reboot(int flags)
Reboot system.
Definition efi_reboot.c:45
static int efi_poweroff(void)
Power off system.
Definition efi_reboot.c:80
uint32_t type
Operating system type.
Definition ena.h:1
uint8_t flags
Flags.
Definition ena.h:7
Error codes.
#define DBGC(...)
Definition compiler.h:505
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define ECANCELED
Operation canceled.
Definition errno.h:344
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
EFI API.
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition efi.h:175
EFI_SYSTEM_TABLE * efi_systab
iPXE reboot API
#define REBOOT_SETUP
Reboot to firmware setup.
Definition reboot.h:60
#define PROVIDE_REBOOT(_subsys, _api_func, _func)
Provide an reboot API implementation.
Definition reboot.h:33
int poweroff(void)
Power off system.
void reboot(int flags)
Reboot system.
#define REBOOT_WARM
Perform a warm reboot.
Definition reboot.h:59
String functions.
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
EFI Runtime Services Table.
Definition UefiSpec.h:1880
EFI_SET_VARIABLE SetVariable
Definition UefiSpec.h:1905
EFI_RESET_SYSTEM ResetSystem
Definition UefiSpec.h:1911