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