]>
Commit | Line | Data |
---|---|---|
9180ab73 OM |
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 | |
7b1dc6c5 | 26 | #include <Library/ResetSystemLib.h>\r |
9180ab73 OM |
27 | #include <Library/ArmSmcLib.h>\r |
28 | #include <Library/ArmHvcLib.h>\r | |
93f9a23f | 29 | #include <Library/UefiBootServicesTableLib.h>\r |
9180ab73 OM |
30 | \r |
31 | #include <IndustryStandard/ArmStdSmc.h>\r | |
32 | \r | |
93f9a23f AB |
33 | #include <Protocol/FdtClient.h>\r |
34 | \r | |
9180ab73 OM |
35 | STATIC UINT32 mArmPsciMethod;\r |
36 | \r | |
37 | RETURN_STATUS\r | |
38 | EFIAPI\r | |
39 | ArmPsciResetSystemLibConstructor (\r | |
40 | VOID\r | |
41 | )\r | |
42 | {\r | |
93f9a23f AB |
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 | |
9180ab73 OM |
67 | }\r |
68 | \r | |
69 | /**\r | |
7b1dc6c5 AB |
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 | |
9180ab73 | 74 | \r |
7b1dc6c5 | 75 | If this function returns, it means that the system does not support cold reset.\r |
9180ab73 | 76 | **/\r |
7b1dc6c5 | 77 | VOID\r |
9180ab73 | 78 | EFIAPI\r |
7b1dc6c5 AB |
79 | ResetCold (\r |
80 | VOID\r | |
9180ab73 OM |
81 | )\r |
82 | {\r | |
83 | ARM_SMC_ARGS ArmSmcArgs;\r | |
84 | ARM_HVC_ARGS ArmHvcArgs;\r | |
85 | \r | |
7b1dc6c5 AB |
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 | |
9180ab73 | 89 | \r |
7b1dc6c5 AB |
90 | switch (mArmPsciMethod) {\r |
91 | case 1:\r | |
92 | ArmCallHvc (&ArmHvcArgs);\r | |
9180ab73 | 93 | break;\r |
7b1dc6c5 AB |
94 | \r |
95 | case 2:\r | |
96 | ArmCallSmc (&ArmSmcArgs);\r | |
9180ab73 | 97 | break;\r |
7b1dc6c5 | 98 | \r |
9180ab73 | 99 | default:\r |
7b1dc6c5 | 100 | DEBUG ((EFI_D_ERROR, "%a: no PSCI method defined\n", __FUNCTION__));\r |
9180ab73 | 101 | }\r |
7b1dc6c5 AB |
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 | |
110 | VOID\r | |
111 | EFIAPI\r | |
112 | ResetWarm (\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 | |
126 | VOID\r | |
127 | EFIAPI\r | |
128 | ResetShutdown (\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 | |
9180ab73 OM |
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 | |
9180ab73 | 150 | }\r |
9180ab73 OM |
151 | }\r |
152 | \r | |
153 | /**\r | |
7b1dc6c5 | 154 | This function causes the system to enter S3 and then wake up immediately.\r |
9180ab73 | 155 | \r |
7b1dc6c5 AB |
156 | If this function returns, it means that the system does not support S3 feature.\r |
157 | **/\r | |
158 | VOID\r | |
159 | EFIAPI\r | |
160 | EnterS3WithImmediateWake (\r | |
161 | VOID\r | |
162 | )\r | |
163 | {\r | |
164 | // not implemented\r | |
165 | }\r | |
9180ab73 | 166 | \r |
7b1dc6c5 AB |
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 | |
9180ab73 | 177 | **/\r |
7b1dc6c5 | 178 | VOID\r |
9180ab73 | 179 | EFIAPI\r |
7b1dc6c5 AB |
180 | ResetPlatformSpecific (\r |
181 | IN UINTN DataSize,\r | |
182 | IN VOID *ResetData\r | |
9180ab73 OM |
183 | )\r |
184 | {\r | |
7b1dc6c5 AB |
185 | // Map the platform specific reset as reboot\r |
186 | ResetCold ();\r | |
9180ab73 | 187 | }\r |