]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/RiscVVirt/Library/ResetSystemLib/ResetSystemLib.c
OvmfPkg/RiscVVirt: Add ResetSystemLib library
[mirror_edk2.git] / OvmfPkg / RiscVVirt / Library / ResetSystemLib / ResetSystemLib.c
1 /** @file
2 Reset System Library functions for RISC-V
3
4 Copyright (c) 2021, Hewlett Packard Development LP. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <Library/DebugLib.h>
10 #include <Library/ResetSystemLib.h>
11 #include <Library/BaseRiscVSbiLib.h>
12
13 /**
14 This function causes a system-wide reset (cold reset), in which
15 all circuitry within the system returns to its initial state. This type of reset
16 is asynchronous to system operation and operates without regard to
17 cycle boundaries.
18
19 If this function returns, it means that the system does not support cold reset.
20 **/
21 VOID
22 EFIAPI
23 ResetCold (
24 VOID
25 )
26 {
27 // Warm Reset via SBI ecall
28 SbiSystemReset (SBI_SRST_RESET_TYPE_COLD_REBOOT, SBI_SRST_RESET_REASON_NONE);
29 }
30
31 /**
32 This function causes a system-wide initialization (warm reset), in which all processors
33 are set to their initial state. Pending cycles are not corrupted.
34
35 If this function returns, it means that the system does not support warm reset.
36 **/
37 VOID
38 EFIAPI
39 ResetWarm (
40 VOID
41 )
42 {
43 // Warm Reset via SBI ecall
44 SbiSystemReset (SBI_SRST_RESET_TYPE_WARM_REBOOT, SBI_SRST_RESET_REASON_NONE);
45 }
46
47 /**
48 This function causes the system to enter a power state equivalent
49 to the ACPI G2/S5 or G3 states.
50
51 If this function returns, it means that the system does not support shutdown reset.
52 **/
53 VOID
54 EFIAPI
55 ResetShutdown (
56 VOID
57 )
58 {
59 // Shut down via SBI ecall
60 SbiSystemReset (SBI_SRST_RESET_TYPE_SHUTDOWN, SBI_SRST_RESET_REASON_NONE);
61 }
62
63 /**
64 This function causes a systemwide reset. The exact type of the reset is
65 defined by the EFI_GUID that follows the Null-terminated Unicode string passed
66 into ResetData. If the platform does not recognize the EFI_GUID in ResetData
67 the platform must pick a supported reset type to perform. The platform may
68 optionally log the parameters from any non-normal reset that occurs.
69
70 @param[in] DataSize The size, in bytes, of ResetData.
71 @param[in] ResetData The data buffer starts with a Null-terminated string,
72 followed by the EFI_GUID.
73 **/
74 VOID
75 EFIAPI
76 ResetPlatformSpecific (
77 IN UINTN DataSize,
78 IN VOID *ResetData
79 )
80 {
81 //
82 // Can map to OpenSBI vendor or platform specific reset type.
83 //
84 return;
85 }
86
87 /**
88 The ResetSystem function resets the entire platform.
89
90 @param[in] ResetType The type of reset to perform.
91 @param[in] ResetStatus The status code for the reset.
92 @param[in] DataSize The size, in bytes, of ResetData.
93 @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or EfiResetShutdown
94 the data buffer starts with a Null-terminated string, optionally
95 followed by additional binary data. The string is a description
96 that the caller may use to further indicate the reason for the
97 system reset.
98 **/
99 VOID
100 EFIAPI
101 ResetSystem (
102 IN EFI_RESET_TYPE ResetType,
103 IN EFI_STATUS ResetStatus,
104 IN UINTN DataSize,
105 IN VOID *ResetData OPTIONAL
106 )
107 {
108 switch (ResetType) {
109 case EfiResetWarm:
110 ResetWarm ();
111 break;
112
113 case EfiResetCold:
114 ResetCold ();
115 break;
116
117 case EfiResetShutdown:
118 ResetShutdown ();
119 return;
120
121 case EfiResetPlatformSpecific:
122 ResetPlatformSpecific (DataSize, ResetData);
123 return;
124
125 default:
126 return;
127 }
128 }