1
2
3
4
5
6
7
8
9#include <common.h>
10#include <efi_loader.h>
11
12
13#define EFI_SECONDS_TO_100NS 10000000ULL
14
15static struct efi_event *watchdog_timer_event;
16
17
18
19
20
21
22
23static void EFIAPI efi_watchdog_timer_notify(struct efi_event *event,
24 void *context)
25{
26 EFI_ENTRY("%p, %p", event, context);
27
28 printf("\nEFI: Watchdog timeout\n");
29 EFI_CALL_VOID(efi_runtime_services.reset_system(EFI_RESET_COLD,
30 EFI_SUCCESS, 0, NULL));
31
32 EFI_EXIT(EFI_UNSUPPORTED);
33}
34
35
36
37
38
39
40
41
42
43efi_status_t efi_set_watchdog(unsigned long timeout)
44{
45 efi_status_t r;
46
47 if (timeout)
48
49 r = efi_set_timer(watchdog_timer_event, EFI_TIMER_RELATIVE,
50 EFI_SECONDS_TO_100NS * timeout);
51 else
52
53 r = efi_set_timer(watchdog_timer_event, EFI_TIMER_STOP, 0);
54 return r;
55}
56
57
58
59
60
61
62int efi_watchdog_register(void)
63{
64 efi_status_t r;
65
66
67
68
69 r = efi_create_event(EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_CALLBACK,
70 efi_watchdog_timer_notify, NULL,
71 &watchdog_timer_event);
72 if (r != EFI_SUCCESS) {
73 printf("ERROR: Failed to register watchdog event\n");
74 return r;
75 }
76
77
78
79
80
81
82
83 r = efi_set_watchdog(300);
84 if (r != EFI_SUCCESS) {
85 printf("ERROR: Failed to set watchdog timer\n");
86 return r;
87 }
88 return 0;
89}
90