1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright (c) 2017 Heinrich Schuchardt
9 #include <efi_loader.h>
11 /* Conversion factor from seconds to multiples of 100ns */
12 #define EFI_SECONDS_TO_100NS 10000000ULL
14 static struct efi_event *watchdog_timer_event;
17 * efi_watchdog_timer_notify() - resets system upon watchdog event
19 * Reset the system when the watchdog event is notified.
21 * @event: the watchdog event
24 static void EFIAPI efi_watchdog_timer_notify(struct efi_event *event,
27 EFI_ENTRY("%p, %p", event, context);
29 printf("\nEFI: Watchdog timeout\n");
30 EFI_CALL_VOID(efi_runtime_services.reset_system(EFI_RESET_COLD,
31 EFI_SUCCESS, 0, NULL));
33 EFI_EXIT(EFI_UNSUPPORTED);
37 * efi_set_watchdog() - resets the watchdog timer
39 * This function is used by the SetWatchdogTimer service.
41 * @timeout: seconds before reset by watchdog
44 efi_status_t efi_set_watchdog(unsigned long timeout)
50 r = efi_set_timer(watchdog_timer_event, EFI_TIMER_RELATIVE,
51 EFI_SECONDS_TO_100NS * timeout);
53 /* Deactivate watchdog */
54 r = efi_set_timer(watchdog_timer_event, EFI_TIMER_STOP, 0);
59 * efi_watchdog_register() - initializes the EFI watchdog
61 * This function is called by efi_init_obj_list().
65 efi_status_t efi_watchdog_register(void)
70 * Create a timer event.
72 r = efi_create_event(EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_CALLBACK,
73 efi_watchdog_timer_notify, NULL, NULL,
74 &watchdog_timer_event);
75 if (r != EFI_SUCCESS) {
76 printf("ERROR: Failed to register watchdog event\n");
80 * The UEFI standard requires that the watchdog timer is set to five
81 * minutes when invoking an EFI boot option.
83 * Unified Extensible Firmware Interface (UEFI), version 2.7 Errata A
84 * 7.5. Miscellaneous Boot Services - EFI_BOOT_SERVICES.SetWatchdogTimer
86 r = efi_set_watchdog(300);
87 if (r != EFI_SUCCESS) {
88 printf("ERROR: Failed to set watchdog timer\n");