]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - ArmVirtPkg/Library/ArmVirtPsciResetSystemLib/ArmVirtPsciResetSystemLib.c
ArmVirtPkg: switch to generic ResetSystemRuntimeDxe
[mirror_edk2.git] / ArmVirtPkg / Library / ArmVirtPsciResetSystemLib / ArmVirtPsciResetSystemLib.c
... / ...
CommitLineData
1/** @file\r
2 Support ResetSystem Runtime call using PSCI calls\r
3\r
4 Note: A similar library is implemented in\r
5 ArmPkg/Library/ArmPsciResetSystemLib. Similar issues might\r
6 exist in this implementation too.\r
7\r
8 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
9 Copyright (c) 2013, ARM Ltd. All rights reserved.<BR>\r
10 Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>\r
11\r
12 This program and the accompanying materials\r
13 are licensed and made available under the terms and conditions of the BSD License\r
14 which accompanies this distribution. The full text of the license may be found at\r
15 http://opensource.org/licenses/bsd-license.php\r
16\r
17 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
18 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
19\r
20**/\r
21\r
22#include <PiDxe.h>\r
23\r
24#include <Library/BaseLib.h>\r
25#include <Library/DebugLib.h>\r
26#include <Library/ResetSystemLib.h>\r
27#include <Library/ArmSmcLib.h>\r
28#include <Library/ArmHvcLib.h>\r
29#include <Library/UefiBootServicesTableLib.h>\r
30\r
31#include <IndustryStandard/ArmStdSmc.h>\r
32\r
33#include <Protocol/FdtClient.h>\r
34\r
35STATIC UINT32 mArmPsciMethod;\r
36\r
37RETURN_STATUS\r
38EFIAPI\r
39ArmPsciResetSystemLibConstructor (\r
40 VOID\r
41 )\r
42{\r
43 EFI_STATUS Status;\r
44 FDT_CLIENT_PROTOCOL *FdtClient;\r
45 CONST VOID *Prop;\r
46\r
47 Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,\r
48 (VOID **)&FdtClient);\r
49 ASSERT_EFI_ERROR (Status);\r
50\r
51 Status = FdtClient->FindCompatibleNodeProperty (FdtClient, "arm,psci-0.2",\r
52 "method", &Prop, NULL);\r
53 if (EFI_ERROR (Status)) {\r
54 return Status;\r
55 }\r
56\r
57 if (AsciiStrnCmp (Prop, "hvc", 3) == 0) {\r
58 mArmPsciMethod = 1;\r
59 } else if (AsciiStrnCmp (Prop, "smc", 3) == 0) {\r
60 mArmPsciMethod = 2;\r
61 } else {\r
62 DEBUG ((EFI_D_ERROR, "%a: Unknown PSCI method \"%a\"\n", __FUNCTION__,\r
63 Prop));\r
64 return EFI_NOT_FOUND;\r
65 }\r
66 return EFI_SUCCESS;\r
67}\r
68\r
69/**\r
70 This function causes a system-wide reset (cold reset), in which\r
71 all circuitry within the system returns to its initial state. This type of reset\r
72 is asynchronous to system operation and operates without regard to\r
73 cycle boundaries.\r
74\r
75 If this function returns, it means that the system does not support cold reset.\r
76**/\r
77VOID\r
78EFIAPI\r
79ResetCold (\r
80 VOID\r
81 )\r
82{\r
83 ARM_SMC_ARGS ArmSmcArgs;\r
84 ARM_HVC_ARGS ArmHvcArgs;\r
85\r
86 // Send a PSCI 0.2 SYSTEM_RESET command\r
87 ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET;\r
88 ArmHvcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET;\r
89\r
90 switch (mArmPsciMethod) {\r
91 case 1:\r
92 ArmCallHvc (&ArmHvcArgs);\r
93 break;\r
94\r
95 case 2:\r
96 ArmCallSmc (&ArmSmcArgs);\r
97 break;\r
98\r
99 default:\r
100 DEBUG ((EFI_D_ERROR, "%a: no PSCI method defined\n", __FUNCTION__));\r
101 }\r
102}\r
103\r
104/**\r
105 This function causes a system-wide initialization (warm reset), in which all processors\r
106 are set to their initial state. Pending cycles are not corrupted.\r
107\r
108 If this function returns, it means that the system does not support warm reset.\r
109**/\r
110VOID\r
111EFIAPI\r
112ResetWarm (\r
113 VOID\r
114 )\r
115{\r
116 // Map a warm reset into a cold reset\r
117 ResetCold ();\r
118}\r
119\r
120/**\r
121 This function causes the system to enter a power state equivalent\r
122 to the ACPI G2/S5 or G3 states.\r
123\r
124 If this function returns, it means that the system does not support shutdown reset.\r
125**/\r
126VOID\r
127EFIAPI\r
128ResetShutdown (\r
129 VOID\r
130 )\r
131{\r
132 ARM_SMC_ARGS ArmSmcArgs;\r
133 ARM_HVC_ARGS ArmHvcArgs;\r
134\r
135 // Send a PSCI 0.2 SYSTEM_OFF command\r
136 ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_OFF;\r
137 ArmHvcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_OFF;\r
138\r
139 switch (mArmPsciMethod) {\r
140 case 1:\r
141 ArmCallHvc (&ArmHvcArgs);\r
142 break;\r
143\r
144 case 2:\r
145 ArmCallSmc (&ArmSmcArgs);\r
146 break;\r
147\r
148 default:\r
149 DEBUG ((EFI_D_ERROR, "%a: no PSCI method defined\n", __FUNCTION__));\r
150 }\r
151}\r
152\r
153/**\r
154 This function causes the system to enter S3 and then wake up immediately.\r
155\r
156 If this function returns, it means that the system does not support S3 feature.\r
157**/\r
158VOID\r
159EFIAPI\r
160EnterS3WithImmediateWake (\r
161 VOID\r
162 )\r
163{\r
164 // not implemented\r
165}\r
166\r
167/**\r
168 This function causes a systemwide reset. The exact type of the reset is\r
169 defined by the EFI_GUID that follows the Null-terminated Unicode string passed\r
170 into ResetData. If the platform does not recognize the EFI_GUID in ResetData\r
171 the platform must pick a supported reset type to perform.The platform may\r
172 optionally log the parameters from any non-normal reset that occurs.\r
173\r
174 @param[in] DataSize The size, in bytes, of ResetData.\r
175 @param[in] ResetData The data buffer starts with a Null-terminated string,\r
176 followed by the EFI_GUID.\r
177**/\r
178VOID\r
179EFIAPI\r
180ResetPlatformSpecific (\r
181 IN UINTN DataSize,\r
182 IN VOID *ResetData\r
183 )\r
184{\r
185 // Map the platform specific reset as reboot\r
186 ResetCold ();\r
187}\r