Commit f6c2e46d authored by Matt Fleming's avatar Matt Fleming Committed by Luis Henriques

efi/reboot: Allow powering off machines using EFI

commit 0c5ed61a upstream.

Not only can EfiResetSystem() be used to reboot, it can also be used to
power down machines.

By and large, this functionality doesn't work very well across the range
of EFI machines in the wild, so it should definitely only be used as a
last resort. In an ideal world, this wouldn't be needed at all.

Unfortunately, we're starting to see machines where EFI is the *only*
reliable way to power down, and nothing else, not PCI, not ACPI, works.

efi_poweroff_required() should be implemented on a per-architecture
basis, since exactly when we should be using EFI runtime services is a
platform-specific decision. There's no analogue for reboot because each
architecture handles reboot very differently - the x86 code in
particular is pretty complex.

Patches to enable this for specific classes of hardware will be
submitted separately.
Tested-by: default avatarMark Salter <msalter@redhat.com>
Signed-off-by: default avatarMatt Fleming <matt.fleming@intel.com>
Cc: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent c4bb687a
...@@ -24,3 +24,25 @@ void efi_reboot(enum reboot_mode reboot_mode, const char *__unused) ...@@ -24,3 +24,25 @@ void efi_reboot(enum reboot_mode reboot_mode, const char *__unused)
efi.reset_system(efi_mode, EFI_SUCCESS, 0, NULL); efi.reset_system(efi_mode, EFI_SUCCESS, 0, NULL);
} }
bool __weak efi_poweroff_required(void)
{
return false;
}
static void efi_power_off(void)
{
efi.reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL);
}
static int __init efi_shutdown_init(void)
{
if (!efi_enabled(EFI_RUNTIME_SERVICES))
return -ENODEV;
if (efi_poweroff_required())
pm_power_off = efi_power_off;
return 0;
}
late_initcall(efi_shutdown_init);
...@@ -876,6 +876,8 @@ extern void efi_reserve_boot_services(void); ...@@ -876,6 +876,8 @@ extern void efi_reserve_boot_services(void);
extern int efi_get_fdt_params(struct efi_fdt_params *params, int verbose); extern int efi_get_fdt_params(struct efi_fdt_params *params, int verbose);
extern struct efi_memory_map memmap; extern struct efi_memory_map memmap;
extern bool efi_poweroff_required(void);
/* Iterate through an efi_memory_map */ /* Iterate through an efi_memory_map */
#define for_each_efi_memory_desc(m, md) \ #define for_each_efi_memory_desc(m, md) \
for ((md) = (m)->map; \ for ((md) = (m)->map; \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment