iPXE
efi_reboot.c File Reference

EFI reboot mechanism. More...

#include <errno.h>
#include <string.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/Guid/GlobalVariable.h>
#include <ipxe/reboot.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
static void efi_reboot (int flags)
 Reboot system.
static int efi_poweroff (void)
 Power off system.
 PROVIDE_REBOOT (efi, reboot, efi_reboot)
 PROVIDE_REBOOT (efi, poweroff, efi_poweroff)

Detailed Description

EFI reboot mechanism.

Definition in file efi_reboot.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ efi_reboot()

void efi_reboot ( int flags)
static

Reboot system.

Parameters
flagsReboot flags

Definition at line 45 of file efi_reboot.c.

45 {
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}
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
#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.
@ 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
uint32_t type
Operating system type.
Definition ena.h:1
uint8_t flags
Flags.
Definition ena.h:7
#define DBGC(...)
Definition compiler.h:505
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition efi.h:175
EFI_SYSTEM_TABLE * efi_systab
#define REBOOT_SETUP
Reboot to firmware setup.
Definition reboot.h:60
#define REBOOT_WARM
Perform a warm reboot.
Definition reboot.h:59
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

References DBGC, EEFI, efi_global_variable, EFI_OS_INDICATIONS_BOOT_TO_FW_UI, EFI_OS_INDICATIONS_VARIABLE_NAME, efi_systab, EFI_VARIABLE_BOOTSERVICE_ACCESS, EFI_VARIABLE_NON_VOLATILE, EFI_VARIABLE_RUNTIME_ACCESS, EfiResetCold, EfiResetWarm, flags, NULL, rc, REBOOT_SETUP, REBOOT_WARM, EFI_RUNTIME_SERVICES::ResetSystem, EFI_RUNTIME_SERVICES::SetVariable, strerror(), and type.

Referenced by PROVIDE_REBOOT().

◆ efi_poweroff()

int efi_poweroff ( void )
static

Power off system.

Return values
rcReturn status code

Definition at line 80 of file efi_reboot.c.

80 {
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}
@ EfiResetShutdown
Used to induce an entry into a power state equivalent to the ACPI G2/S5 or G3 state.
#define ECANCELED
Operation canceled.
Definition errno.h:344

References ECANCELED, efi_systab, EfiResetShutdown, NULL, and EFI_RUNTIME_SERVICES::ResetSystem.

Referenced by PROVIDE_REBOOT().

◆ PROVIDE_REBOOT() [1/2]

PROVIDE_REBOOT ( efi ,
reboot ,
efi_reboot  )

References efi_reboot(), and reboot().

◆ PROVIDE_REBOOT() [2/2]

PROVIDE_REBOOT ( efi ,
poweroff ,
efi_poweroff  )

References efi_poweroff(), and poweroff().