]> Git Repo - J-u-boot.git/blame - lib/efi_loader/efi_watchdog.c
common: Drop log.h from common header
[J-u-boot.git] / lib / efi_loader / efi_watchdog.c
CommitLineData
f739fcd8 1// SPDX-License-Identifier: GPL-2.0+
b3d60900
HS
2/*
3 * EFI watchdog
4 *
5 * Copyright (c) 2017 Heinrich Schuchardt
b3d60900
HS
6 */
7
8#include <common.h>
9#include <efi_loader.h>
10
11/* Conversion factor from seconds to multiples of 100ns */
12#define EFI_SECONDS_TO_100NS 10000000ULL
13
14static struct efi_event *watchdog_timer_event;
15
540faca8
HS
16/**
17 * efi_watchdog_timer_notify() - resets system upon watchdog event
18 *
b3d60900
HS
19 * Reset the system when the watchdog event is notified.
20 *
21 * @event: the watchdog event
22 * @context: not used
23 */
24static void EFIAPI efi_watchdog_timer_notify(struct efi_event *event,
25 void *context)
26{
27 EFI_ENTRY("%p, %p", event, context);
28
29 printf("\nEFI: Watchdog timeout\n");
30 EFI_CALL_VOID(efi_runtime_services.reset_system(EFI_RESET_COLD,
31 EFI_SUCCESS, 0, NULL));
32
33 EFI_EXIT(EFI_UNSUPPORTED);
34}
35
540faca8
HS
36/**
37 * efi_set_watchdog() - resets the watchdog timer
b3d60900
HS
38 *
39 * This function is used by the SetWatchdogTimer service.
40 *
41 * @timeout: seconds before reset by watchdog
540faca8 42 * Return: status code
b3d60900
HS
43 */
44efi_status_t efi_set_watchdog(unsigned long timeout)
45{
46 efi_status_t r;
47
48 if (timeout)
49 /* Reset watchdog */
50 r = efi_set_timer(watchdog_timer_event, EFI_TIMER_RELATIVE,
51 EFI_SECONDS_TO_100NS * timeout);
52 else
53 /* Deactivate watchdog */
54 r = efi_set_timer(watchdog_timer_event, EFI_TIMER_STOP, 0);
55 return r;
56}
57
540faca8
HS
58/**
59 * efi_watchdog_register() - initializes the EFI watchdog
60 *
61 * This function is called by efi_init_obj_list().
b3d60900 62 *
540faca8 63 * Return: status code
b3d60900 64 */
d7b181d5 65efi_status_t efi_watchdog_register(void)
b3d60900
HS
66{
67 efi_status_t r;
68
69 /*
70 * Create a timer event.
71 */
72 r = efi_create_event(EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_CALLBACK,
b095f3c8 73 efi_watchdog_timer_notify, NULL, NULL,
b3d60900
HS
74 &watchdog_timer_event);
75 if (r != EFI_SUCCESS) {
76 printf("ERROR: Failed to register watchdog event\n");
77 return r;
78 }
79 /*
80 * The UEFI standard requires that the watchdog timer is set to five
81 * minutes when invoking an EFI boot option.
82 *
83 * Unified Extensible Firmware Interface (UEFI), version 2.7 Errata A
84 * 7.5. Miscellaneous Boot Services - EFI_BOOT_SERVICES.SetWatchdogTimer
85 */
86 r = efi_set_watchdog(300);
87 if (r != EFI_SUCCESS) {
88 printf("ERROR: Failed to set watchdog timer\n");
89 return r;
90 }
d7b181d5 91 return EFI_SUCCESS;
b3d60900 92}
This page took 0.135269 seconds and 4 git commands to generate.