forked from Minki/linux
f0133f3c5b
The EFI capsule mechanism allows data blobs to be passed to the EFI firmware. A common use case is performing firmware updates. This patch just introduces the main infrastructure for interacting with the firmware, and a driver that allows users to upload capsules will come in a later patch. Once a capsule has been passed to the firmware, the next reboot must be performed using the ResetSystem() EFI runtime service, which may involve overriding the reboot type specified by reboot=. This ensures the reset value returned by QueryCapsuleCapabilities() is used to reset the system, which is required for the capsule to be processed. efi_capsule_pending() is provided for this purpose. At the moment we only allow a single capsule blob to be sent to the firmware despite the fact that UpdateCapsule() takes a 'CapsuleCount' parameter. This simplifies the API and shouldn't result in any downside since it is still possible to send multiple capsules by repeatedly calling UpdateCapsule(). Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Bryan O'Donoghue <pure.logic@nexus-software.ie> Cc: Kweh Hock Leong <hock.leong.kweh@intel.com> Cc: Mark Salter <msalter@redhat.com> Cc: Peter Jones <pjones@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: joeyli <jlee@suse.com> Cc: linux-efi@vger.kernel.org Link: http://lkml.kernel.org/r/1461614832-17633-28-git-send-email-matt@codeblueprint.co.uk Signed-off-by: Ingo Molnar <mingo@kernel.org>
67 lines
1.4 KiB
C
67 lines
1.4 KiB
C
/*
|
|
* Copyright (C) 2014 Intel Corporation; author Matt Fleming
|
|
* Copyright (c) 2014 Red Hat, Inc., Mark Salter <msalter@redhat.com>
|
|
*/
|
|
#include <linux/efi.h>
|
|
#include <linux/reboot.h>
|
|
|
|
int efi_reboot_quirk_mode = -1;
|
|
|
|
void efi_reboot(enum reboot_mode reboot_mode, const char *__unused)
|
|
{
|
|
const char *str[] = { "cold", "warm", "shutdown", "platform" };
|
|
int efi_mode, cap_reset_mode;
|
|
|
|
if (!efi_enabled(EFI_RUNTIME_SERVICES))
|
|
return;
|
|
|
|
switch (reboot_mode) {
|
|
case REBOOT_WARM:
|
|
case REBOOT_SOFT:
|
|
efi_mode = EFI_RESET_WARM;
|
|
break;
|
|
default:
|
|
efi_mode = EFI_RESET_COLD;
|
|
break;
|
|
}
|
|
|
|
/*
|
|
* If a quirk forced an EFI reset mode, always use that.
|
|
*/
|
|
if (efi_reboot_quirk_mode != -1)
|
|
efi_mode = efi_reboot_quirk_mode;
|
|
|
|
if (efi_capsule_pending(&cap_reset_mode)) {
|
|
if (efi_mode != cap_reset_mode)
|
|
printk(KERN_CRIT "efi: %s reset requested but pending "
|
|
"capsule update requires %s reset... Performing "
|
|
"%s reset.\n", str[efi_mode], str[cap_reset_mode],
|
|
str[cap_reset_mode]);
|
|
efi_mode = cap_reset_mode;
|
|
}
|
|
|
|
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);
|