]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / ArmPkg / Library / ArmSmcPsciResetSystemLib / ArmSmcPsciResetSystemLib.c
1 /** @file
2 ResetSystemLib implementation using PSCI calls
3
4 Copyright (c) 2017 - 2018, Linaro Ltd. All rights reserved.<BR>
5 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
6 Copyright (c) 2022, Arm Limited. All rights reserved.<BR>
7
8 SPDX-License-Identifier: BSD-2-Clause-Patent
9
10 **/
11
12 #include <PiDxe.h>
13
14 #include <Library/ArmSmcLib.h>
15 #include <Library/BaseLib.h>
16 #include <Library/DebugLib.h>
17 #include <Library/ResetSystemLib.h>
18
19 #include <IndustryStandard/ArmStdSmc.h>
20
21 /**
22 This function causes a system-wide reset (cold reset), in which
23 all circuitry within the system returns to its initial state. This type of reset
24 is asynchronous to system operation and operates without regard to
25 cycle boundaries.
26
27 If this function returns, it means that the system does not support cold reset.
28 **/
29 VOID
30 EFIAPI
31 ResetCold (
32 VOID
33 )
34 {
35 // Send a PSCI 0.2 SYSTEM_RESET command
36 ArmCallSmc0 (ARM_SMC_ID_PSCI_SYSTEM_RESET, NULL, NULL, NULL);
37 }
38
39 /**
40 This function causes a system-wide initialization (warm reset), in which all processors
41 are set to their initial state. Pending cycles are not corrupted.
42
43 If this function returns, it means that the system does not support warm reset.
44 **/
45 VOID
46 EFIAPI
47 ResetWarm (
48 VOID
49 )
50 {
51 UINTN Arg1;
52 UINTN Ret;
53
54 Arg1 = ARM_SMC_ID_PSCI_SYSTEM_RESET2_AARCH64;
55
56 // Is SYSTEM_RESET2 supported?
57 Ret = ArmCallSmc0 (ARM_SMC_ID_PSCI_FEATURES, &Arg1, NULL, NULL);
58 if (Ret == ARM_SMC_PSCI_RET_SUCCESS) {
59 // Send PSCI SYSTEM_RESET2 command
60 ArmCallSmc0 (Arg1, NULL, NULL, NULL);
61 } else {
62 // Map a warm reset into a cold reset
63 DEBUG ((
64 DEBUG_INFO,
65 "Warm reboot not supported by platform, issuing cold reboot\n"
66 ));
67 ResetCold ();
68 }
69 }
70
71 /**
72 This function causes the system to enter a power state equivalent
73 to the ACPI G2/S5 or G3 states.
74
75 If this function returns, it means that the system does not support shutdown reset.
76 **/
77 VOID
78 EFIAPI
79 ResetShutdown (
80 VOID
81 )
82 {
83 // Send a PSCI 0.2 SYSTEM_OFF command
84 ArmCallSmc0 (ARM_SMC_ID_PSCI_SYSTEM_OFF, NULL, NULL, NULL);
85 }
86
87 /**
88 This function causes a systemwide reset. The exact type of the reset is
89 defined by the EFI_GUID that follows the Null-terminated Unicode string passed
90 into ResetData. If the platform does not recognize the EFI_GUID in ResetData
91 the platform must pick a supported reset type to perform.The platform may
92 optionally log the parameters from any non-normal reset that occurs.
93
94 @param[in] DataSize The size, in bytes, of ResetData.
95 @param[in] ResetData The data buffer starts with a Null-terminated string,
96 followed by the EFI_GUID.
97 **/
98 VOID
99 EFIAPI
100 ResetPlatformSpecific (
101 IN UINTN DataSize,
102 IN VOID *ResetData
103 )
104 {
105 // Map the platform specific reset as reboot
106 ResetCold ();
107 }
108
109 /**
110 The ResetSystem function resets the entire platform.
111
112 @param[in] ResetType The type of reset to perform.
113 @param[in] ResetStatus The status code for the reset.
114 @param[in] DataSize The size, in bytes, of ResetData.
115 @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or EfiResetShutdown
116 the data buffer starts with a Null-terminated string, optionally
117 followed by additional binary data. The string is a description
118 that the caller may use to further indicate the reason for the
119 system reset.
120 **/
121 VOID
122 EFIAPI
123 ResetSystem (
124 IN EFI_RESET_TYPE ResetType,
125 IN EFI_STATUS ResetStatus,
126 IN UINTN DataSize,
127 IN VOID *ResetData OPTIONAL
128 )
129 {
130 switch (ResetType) {
131 case EfiResetWarm:
132 ResetWarm ();
133 break;
134
135 case EfiResetCold:
136 ResetCold ();
137 break;
138
139 case EfiResetShutdown:
140 ResetShutdown ();
141 return;
142
143 case EfiResetPlatformSpecific:
144 ResetPlatformSpecific (DataSize, ResetData);
145 return;
146
147 default:
148 return;
149 }
150 }