iPXE
efi_watchdog.c File Reference

EFI watchdog holdoff timer. More...

#include <errno.h>
#include <string.h>
#include <ipxe/retry.h>
#include <ipxe/timer.h>
#include <ipxe/init.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_watchdog.h>

Go to the source code of this file.

Macros

#define WATCHDOG_HOLDOFF_SECS   10
 Watchdog holdoff interval (in seconds)
#define WATCHDOG_TIMEOUT_SECS   ( 5 * 60 )
 Watchdog timeout (in seconds)
#define WATCHDOG_CODE   0x6950584544454144ULL
 Watchdog code (to be logged on watchdog timeout)
#define WATCHDOG_DATA   L"iPXE";
 Watchdog data (to be logged on watchdog timeout)

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
static void efi_watchdog_expired (struct retry_timer *timer, int over __unused)
 Hold off watchdog timer.
static void efi_watchdog_shutdown (int booting)
 Disable watching when shutting down to boot an operating system.
struct startup_fn efi_watchdog_startup_fn __startup_fn (STARTUP_EARLY)
 Watchdog startup/shutdown function.

Variables

struct retry_timer efi_watchdog = TIMER_INIT ( efi_watchdog_expired )
 Watchdog holdoff timer.

Detailed Description

EFI watchdog holdoff timer.

Definition in file efi_watchdog.c.

Macro Definition Documentation

◆ WATCHDOG_HOLDOFF_SECS

#define WATCHDOG_HOLDOFF_SECS   10

Watchdog holdoff interval (in seconds)

Definition at line 43 of file efi_watchdog.c.

Referenced by efi_watchdog_expired().

◆ WATCHDOG_TIMEOUT_SECS

#define WATCHDOG_TIMEOUT_SECS   ( 5 * 60 )

Watchdog timeout (in seconds)

Definition at line 46 of file efi_watchdog.c.

Referenced by efi_watchdog_expired().

◆ WATCHDOG_CODE

#define WATCHDOG_CODE   0x6950584544454144ULL

Watchdog code (to be logged on watchdog timeout)

Definition at line 49 of file efi_watchdog.c.

Referenced by efi_watchdog_expired().

◆ WATCHDOG_DATA

#define WATCHDOG_DATA   L"iPXE";

Watchdog data (to be logged on watchdog timeout)

Definition at line 52 of file efi_watchdog.c.

Referenced by efi_watchdog_expired().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ efi_watchdog_expired()

void efi_watchdog_expired ( struct retry_timer * timer,
int over __unused )
static

Hold off watchdog timer.

Parameters
retryRetry timer
overFailure indicator

Definition at line 60 of file efi_watchdog.c.

61 {
62 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
63 static CHAR16 data[] = WATCHDOG_DATA;
64 EFI_STATUS efirc;
65 int rc;
66
67 DBGC2 ( timer, "EFI holding off watchdog timer\n" );
68
69 /* Restart this holdoff timer */
71
72 /* Reset watchdog timer */
73 if ( ( efirc = bs->SetWatchdogTimer ( WATCHDOG_TIMEOUT_SECS,
74 WATCHDOG_CODE, sizeof ( data ),
75 data ) ) != 0 ) {
76 rc = -EEFI ( efirc );
77 DBGC ( timer, "EFI could not set watchdog timer: %s\n",
78 strerror ( rc ) );
79 return;
80 }
81}
unsigned short CHAR16
2-byte Character.
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
#define WATCHDOG_DATA
Watchdog data (to be logged on watchdog timeout)
#define WATCHDOG_TIMEOUT_SECS
Watchdog timeout (in seconds)
#define WATCHDOG_HOLDOFF_SECS
Watchdog holdoff interval (in seconds)
#define WATCHDOG_CODE
Watchdog code (to be logged on watchdog timeout)
uint8_t data[48]
Additional event data.
Definition ena.h:11
#define DBGC2(...)
Definition compiler.h:522
#define DBGC(...)
Definition compiler.h:505
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition efi.h:175
EFI_SYSTEM_TABLE * efi_systab
#define TICKS_PER_SEC
Number of ticks per second.
Definition timer.h:16
void start_timer_fixed(struct retry_timer *timer, unsigned long timeout)
Start timer with a specified timeout.
Definition retry.c:65
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
EFI Boot Services Table.
Definition UefiSpec.h:1931
EFI_SET_WATCHDOG_TIMER SetWatchdogTimer
Definition UefiSpec.h:1989
A timer.
Definition timer.h:29

References __unused, data, DBGC, DBGC2, EEFI, efi_systab, rc, EFI_BOOT_SERVICES::SetWatchdogTimer, start_timer_fixed(), strerror(), TICKS_PER_SEC, WATCHDOG_CODE, WATCHDOG_DATA, WATCHDOG_HOLDOFF_SECS, and WATCHDOG_TIMEOUT_SECS.

◆ efi_watchdog_shutdown()

void efi_watchdog_shutdown ( int booting)
static

Disable watching when shutting down to boot an operating system.

Parameters
bootingSystem is shutting down for OS boot

Definition at line 91 of file efi_watchdog.c.

91 {
92 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
93 EFI_STATUS efirc;
94 int rc;
95
96 /* If we are shutting down to boot an operating system, then
97 * disable the boot services watchdog timer. The UEFI
98 * specification mandates that the platform firmware does this
99 * as part of the ExitBootServices() call, but some platforms
100 * (e.g. Hyper-V) are observed to occasionally forget to do
101 * so, resulting in a reboot approximately five minutes after
102 * starting the operating system.
103 */
104 if ( booting &&
105 ( ( efirc = bs->SetWatchdogTimer ( 0, 0, 0, NULL ) ) != 0 ) ) {
106 rc = -EEFI ( efirc );
107 DBGC ( &efi_watchdog, "EFI could not disable watchdog timer: "
108 "%s\n", strerror ( rc ) );
109 /* Nothing we can do */
110 }
111}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
struct retry_timer efi_watchdog
Watchdog holdoff timer.

References DBGC, EEFI, efi_systab, efi_watchdog, NULL, rc, EFI_BOOT_SERVICES::SetWatchdogTimer, and strerror().

Referenced by __startup_fn().

◆ __startup_fn()

struct startup_fn efi_watchdog_startup_fn __startup_fn ( STARTUP_EARLY )

Watchdog startup/shutdown function.

References __startup_fn, efi_watchdog_shutdown(), and STARTUP_EARLY.

Variable Documentation

◆ efi_watchdog

struct retry_timer efi_watchdog = TIMER_INIT ( efi_watchdog_expired )

Watchdog holdoff timer.

Definition at line 84 of file efi_watchdog.c.

Referenced by efi_watchdog_shutdown(), efi_watchdog_start(), efi_watchdog_stop(), and FILE_SECBOOT().