1 | /** @file
|
---|
2 | Support ResetSystem Runtime call using PSCI calls
|
---|
3 |
|
---|
4 | Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
|
---|
5 | Copyright (c) 2013, ARM Ltd. All rights reserved.<BR>
|
---|
6 | Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>
|
---|
7 | Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
|
---|
8 | Copyright (c) 2024, Google Llc. All rights reserved.<BR>
|
---|
9 |
|
---|
10 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
11 |
|
---|
12 | **/
|
---|
13 |
|
---|
14 | #include <PiDxe.h>
|
---|
15 |
|
---|
16 | #include <IndustryStandard/ArmStdSmc.h>
|
---|
17 |
|
---|
18 | #include <Library/ArmMonitorLib.h>
|
---|
19 | #include <Library/BaseLib.h>
|
---|
20 | #include <Library/DebugLib.h>
|
---|
21 | #include <Library/ResetSystemLib.h>
|
---|
22 | #include <Library/UefiBootServicesTableLib.h>
|
---|
23 |
|
---|
24 | /**
|
---|
25 | Library constructor. This function does nothing, but this library may depend
|
---|
26 | on other libraries that do have a non-trivial constructor, which the
|
---|
27 | BaseToools fail to account for if a library has no constructor at all.
|
---|
28 | **/
|
---|
29 | RETURN_STATUS
|
---|
30 | EFIAPI
|
---|
31 | ArmPsciResetSystemLibConstructor (
|
---|
32 | VOID
|
---|
33 | )
|
---|
34 | {
|
---|
35 | return EFI_SUCCESS;
|
---|
36 | }
|
---|
37 |
|
---|
38 | /**
|
---|
39 | This function causes a system-wide reset (cold reset), in which
|
---|
40 | all circuitry within the system returns to its initial state. This type of reset
|
---|
41 | is asynchronous to system operation and operates without regard to
|
---|
42 | cycle boundaries.
|
---|
43 |
|
---|
44 | If this function returns, it means that the system does not support cold reset.
|
---|
45 | **/
|
---|
46 | VOID
|
---|
47 | EFIAPI
|
---|
48 | ResetCold (
|
---|
49 | VOID
|
---|
50 | )
|
---|
51 | {
|
---|
52 | ARM_MONITOR_ARGS Args;
|
---|
53 |
|
---|
54 | // Send a PSCI 0.2 SYSTEM_RESET command
|
---|
55 | Args.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET;
|
---|
56 |
|
---|
57 | ArmMonitorCall (&Args);
|
---|
58 | }
|
---|
59 |
|
---|
60 | /**
|
---|
61 | This function causes a system-wide initialization (warm reset), in which all processors
|
---|
62 | are set to their initial state. Pending cycles are not corrupted.
|
---|
63 |
|
---|
64 | If this function returns, it means that the system does not support warm reset.
|
---|
65 | **/
|
---|
66 | VOID
|
---|
67 | EFIAPI
|
---|
68 | ResetWarm (
|
---|
69 | VOID
|
---|
70 | )
|
---|
71 | {
|
---|
72 | ARM_MONITOR_ARGS Args;
|
---|
73 |
|
---|
74 | Args.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET2_AARCH64;
|
---|
75 |
|
---|
76 | // Is SYSTEM_RESET2 supported?
|
---|
77 | ArmMonitorCall (&Args);
|
---|
78 | if (Args.Arg0 == ARM_SMC_PSCI_RET_SUCCESS) {
|
---|
79 | // Send PSCI SYSTEM_RESET2 command
|
---|
80 | Args.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET2_AARCH64;
|
---|
81 |
|
---|
82 | ArmMonitorCall (&Args);
|
---|
83 | } else {
|
---|
84 | // Map a warm reset into a cold reset
|
---|
85 | DEBUG ((
|
---|
86 | DEBUG_INFO,
|
---|
87 | "Warm reboot not supported by platform, issuing cold reboot\n"
|
---|
88 | ));
|
---|
89 | ResetCold ();
|
---|
90 | }
|
---|
91 | }
|
---|
92 |
|
---|
93 | /**
|
---|
94 | This function causes the system to enter a power state equivalent
|
---|
95 | to the ACPI G2/S5 or G3 states.
|
---|
96 |
|
---|
97 | If this function returns, it means that the system does not support shutdown reset.
|
---|
98 | **/
|
---|
99 | VOID
|
---|
100 | EFIAPI
|
---|
101 | ResetShutdown (
|
---|
102 | VOID
|
---|
103 | )
|
---|
104 | {
|
---|
105 | ARM_MONITOR_ARGS Args;
|
---|
106 |
|
---|
107 | // Send a PSCI 0.2 SYSTEM_RESET command
|
---|
108 | Args.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_OFF;
|
---|
109 |
|
---|
110 | ArmMonitorCall (&Args);
|
---|
111 | }
|
---|
112 |
|
---|
113 | /**
|
---|
114 | This function causes a systemwide reset. The exact type of the reset is
|
---|
115 | defined by the EFI_GUID that follows the Null-terminated Unicode string passed
|
---|
116 | into ResetData. If the platform does not recognize the EFI_GUID in ResetData
|
---|
117 | the platform must pick a supported reset type to perform.The platform may
|
---|
118 | optionally log the parameters from any non-normal reset that occurs.
|
---|
119 |
|
---|
120 | @param[in] DataSize The size, in bytes, of ResetData.
|
---|
121 | @param[in] ResetData The data buffer starts with a Null-terminated string,
|
---|
122 | followed by the EFI_GUID.
|
---|
123 | **/
|
---|
124 | VOID
|
---|
125 | EFIAPI
|
---|
126 | ResetPlatformSpecific (
|
---|
127 | IN UINTN DataSize,
|
---|
128 | IN VOID *ResetData
|
---|
129 | )
|
---|
130 | {
|
---|
131 | // Map the platform specific reset as reboot
|
---|
132 | ResetCold ();
|
---|
133 | }
|
---|
134 |
|
---|
135 | /**
|
---|
136 | The ResetSystem function resets the entire platform.
|
---|
137 |
|
---|
138 | @param[in] ResetType The type of reset to perform.
|
---|
139 | @param[in] ResetStatus The status code for the reset.
|
---|
140 | @param[in] DataSize The size, in bytes, of ResetData.
|
---|
141 | @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or EfiResetShutdown
|
---|
142 | the data buffer starts with a Null-terminated string, optionally
|
---|
143 | followed by additional binary data. The string is a description
|
---|
144 | that the caller may use to further indicate the reason for the
|
---|
145 | system reset.
|
---|
146 | **/
|
---|
147 | VOID
|
---|
148 | EFIAPI
|
---|
149 | ResetSystem (
|
---|
150 | IN EFI_RESET_TYPE ResetType,
|
---|
151 | IN EFI_STATUS ResetStatus,
|
---|
152 | IN UINTN DataSize,
|
---|
153 | IN VOID *ResetData OPTIONAL
|
---|
154 | )
|
---|
155 | {
|
---|
156 | switch (ResetType) {
|
---|
157 | case EfiResetWarm:
|
---|
158 | ResetWarm ();
|
---|
159 | break;
|
---|
160 |
|
---|
161 | case EfiResetCold:
|
---|
162 | ResetCold ();
|
---|
163 | break;
|
---|
164 |
|
---|
165 | case EfiResetShutdown:
|
---|
166 | ResetShutdown ();
|
---|
167 | return;
|
---|
168 |
|
---|
169 | case EfiResetPlatformSpecific:
|
---|
170 | ResetPlatformSpecific (DataSize, ResetData);
|
---|
171 | return;
|
---|
172 |
|
---|
173 | default:
|
---|
174 | return;
|
---|
175 | }
|
---|
176 | }
|
---|