]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Dxe/Misc/SetWatchdogTimer.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Misc / SetWatchdogTimer.c
1 /** @file
2 UEFI Miscellaneous boot Services SetWatchdogTimer service implementation
3
4 Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "DxeMain.h"
10
11 #define WATCHDOG_TIMER_CALIBRATE_PER_SECOND 10000000
12
13 /**
14 Sets the system's watchdog timer.
15
16 @param Timeout The number of seconds to set the watchdog timer to.
17 A value of zero disables the timer.
18 @param WatchdogCode The numeric code to log on a watchdog timer timeout
19 event. The firmware reserves codes 0x0000 to 0xFFFF.
20 Loaders and operating systems may use other timeout
21 codes.
22 @param DataSize The size, in bytes, of WatchdogData.
23 @param WatchdogData A data buffer that includes a Null-terminated Unicode
24 string, optionally followed by additional binary data.
25 The string is a description that the call may use to
26 further indicate the reason to be logged with a
27 watchdog event.
28
29 @return EFI_SUCCESS Timeout has been set
30 @return EFI_NOT_AVAILABLE_YET WatchdogTimer is not available yet
31 @return EFI_UNSUPPORTED System does not have a timer (currently not used)
32 @return EFI_DEVICE_ERROR Could not complete due to hardware error
33
34 **/
35 EFI_STATUS
36 EFIAPI
37 CoreSetWatchdogTimer (
38 IN UINTN Timeout,
39 IN UINT64 WatchdogCode,
40 IN UINTN DataSize,
41 IN CHAR16 *WatchdogData OPTIONAL
42 )
43 {
44 EFI_STATUS Status;
45
46 //
47 // Check our architectural protocol
48 //
49 if (gWatchdogTimer == NULL) {
50 return EFI_NOT_AVAILABLE_YET;
51 }
52
53 //
54 // Attempt to set the timeout
55 //
56 Status = gWatchdogTimer->SetTimerPeriod (gWatchdogTimer, MultU64x32 (Timeout, WATCHDOG_TIMER_CALIBRATE_PER_SECOND));
57
58 //
59 // Check for errors
60 //
61 if (EFI_ERROR (Status)) {
62 return EFI_DEVICE_ERROR;
63 }
64
65 return EFI_SUCCESS;
66 }