4 * Copyright (c) 2017 Heinrich Schuchardt
6 * SPDX-License-Identifier: GPL-2.0+
10 #include <efi_loader.h>
12 /* Conversion factor from seconds to multiples of 100ns */
13 #define EFI_SECONDS_TO_100NS 10000000ULL
15 static struct efi_event *watchdog_timer_event;
18 * Reset the system when the watchdog event is notified.
20 * @event: the watchdog event
23 static void EFIAPI efi_watchdog_timer_notify(struct efi_event *event,
26 EFI_ENTRY("%p, %p", event, context);
28 printf("\nEFI: Watchdog timeout\n");
29 EFI_CALL_VOID(efi_runtime_services.reset_system(EFI_RESET_COLD,
30 EFI_SUCCESS, 0, NULL));
32 EFI_EXIT(EFI_UNSUPPORTED);
36 * Reset the watchdog timer.
38 * This function is used by the SetWatchdogTimer service.
40 * @timeout: seconds before reset by watchdog
41 * @return: status code
43 efi_status_t efi_set_watchdog(unsigned long timeout)
49 r = efi_set_timer(watchdog_timer_event, EFI_TIMER_RELATIVE,
50 EFI_SECONDS_TO_100NS * timeout);
52 /* Deactivate watchdog */
53 r = efi_set_timer(watchdog_timer_event, EFI_TIMER_STOP, 0);
58 * Initialize the EFI watchdog.
60 * This function is called by efi_init_obj_list()
62 efi_status_t efi_watchdog_register(void)
67 * Create a timer event.
69 r = efi_create_event(EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_CALLBACK,
70 efi_watchdog_timer_notify, NULL, NULL,
71 &watchdog_timer_event);
72 if (r != EFI_SUCCESS) {
73 printf("ERROR: Failed to register watchdog event\n");
77 * The UEFI standard requires that the watchdog timer is set to five
78 * minutes when invoking an EFI boot option.
80 * Unified Extensible Firmware Interface (UEFI), version 2.7 Errata A
81 * 7.5. Miscellaneous Boot Services - EFI_BOOT_SERVICES.SetWatchdogTimer
83 r = efi_set_watchdog(300);
84 if (r != EFI_SUCCESS) {
85 printf("ERROR: Failed to set watchdog timer\n");