2018-05-07 21:02:21 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-10-18 16:13:04 +00:00
|
|
|
/*
|
|
|
|
* EFI watchdog
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 Heinrich Schuchardt
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <efi_loader.h>
|
|
|
|
|
|
|
|
/* Conversion factor from seconds to multiples of 100ns */
|
|
|
|
#define EFI_SECONDS_TO_100NS 10000000ULL
|
|
|
|
|
|
|
|
static struct efi_event *watchdog_timer_event;
|
|
|
|
|
2020-04-10 15:51:56 +00:00
|
|
|
/**
|
|
|
|
* efi_watchdog_timer_notify() - resets system upon watchdog event
|
|
|
|
*
|
2017-10-18 16:13:04 +00:00
|
|
|
* Reset the system when the watchdog event is notified.
|
|
|
|
*
|
|
|
|
* @event: the watchdog event
|
|
|
|
* @context: not used
|
|
|
|
*/
|
|
|
|
static void EFIAPI efi_watchdog_timer_notify(struct efi_event *event,
|
|
|
|
void *context)
|
|
|
|
{
|
|
|
|
EFI_ENTRY("%p, %p", event, context);
|
|
|
|
|
|
|
|
printf("\nEFI: Watchdog timeout\n");
|
|
|
|
EFI_CALL_VOID(efi_runtime_services.reset_system(EFI_RESET_COLD,
|
|
|
|
EFI_SUCCESS, 0, NULL));
|
|
|
|
|
|
|
|
EFI_EXIT(EFI_UNSUPPORTED);
|
|
|
|
}
|
|
|
|
|
2020-04-10 15:51:56 +00:00
|
|
|
/**
|
|
|
|
* efi_set_watchdog() - resets the watchdog timer
|
2017-10-18 16:13:04 +00:00
|
|
|
*
|
|
|
|
* This function is used by the SetWatchdogTimer service.
|
|
|
|
*
|
|
|
|
* @timeout: seconds before reset by watchdog
|
2020-04-10 15:51:56 +00:00
|
|
|
* Return: status code
|
2017-10-18 16:13:04 +00:00
|
|
|
*/
|
|
|
|
efi_status_t efi_set_watchdog(unsigned long timeout)
|
|
|
|
{
|
|
|
|
efi_status_t r;
|
|
|
|
|
|
|
|
if (timeout)
|
|
|
|
/* Reset watchdog */
|
|
|
|
r = efi_set_timer(watchdog_timer_event, EFI_TIMER_RELATIVE,
|
|
|
|
EFI_SECONDS_TO_100NS * timeout);
|
|
|
|
else
|
|
|
|
/* Deactivate watchdog */
|
|
|
|
r = efi_set_timer(watchdog_timer_event, EFI_TIMER_STOP, 0);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2020-04-10 15:51:56 +00:00
|
|
|
/**
|
|
|
|
* efi_watchdog_register() - initializes the EFI watchdog
|
|
|
|
*
|
|
|
|
* This function is called by efi_init_obj_list().
|
2017-10-18 16:13:04 +00:00
|
|
|
*
|
2020-04-10 15:51:56 +00:00
|
|
|
* Return: status code
|
2017-10-18 16:13:04 +00:00
|
|
|
*/
|
2018-03-03 14:28:57 +00:00
|
|
|
efi_status_t efi_watchdog_register(void)
|
2017-10-18 16:13:04 +00:00
|
|
|
{
|
|
|
|
efi_status_t r;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a timer event.
|
|
|
|
*/
|
|
|
|
r = efi_create_event(EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_CALLBACK,
|
2018-02-18 14:17:52 +00:00
|
|
|
efi_watchdog_timer_notify, NULL, NULL,
|
2017-10-18 16:13:04 +00:00
|
|
|
&watchdog_timer_event);
|
|
|
|
if (r != EFI_SUCCESS) {
|
|
|
|
printf("ERROR: Failed to register watchdog event\n");
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* The UEFI standard requires that the watchdog timer is set to five
|
|
|
|
* minutes when invoking an EFI boot option.
|
|
|
|
*
|
|
|
|
* Unified Extensible Firmware Interface (UEFI), version 2.7 Errata A
|
|
|
|
* 7.5. Miscellaneous Boot Services - EFI_BOOT_SERVICES.SetWatchdogTimer
|
|
|
|
*/
|
|
|
|
r = efi_set_watchdog(300);
|
|
|
|
if (r != EFI_SUCCESS) {
|
|
|
|
printf("ERROR: Failed to set watchdog timer\n");
|
|
|
|
return r;
|
|
|
|
}
|
2018-03-03 14:28:57 +00:00
|
|
|
return EFI_SUCCESS;
|
2017-10-18 16:13:04 +00:00
|
|
|
}
|