]> git.proxmox.com Git - mirror_edk2.git/blob - ArmVirtPkg/Library/ArmVirtPsciResetSystemLib/ArmVirtPsciResetSystemLib.c
ArmVirtPkg: Replace BSD License with BSD+Patent License
[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 SPDX-License-Identifier: BSD-2-Clause-Patent
13
14 **/
15
16 #include <PiDxe.h>
17
18 #include <Library/BaseLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/ResetSystemLib.h>
21 #include <Library/ArmSmcLib.h>
22 #include <Library/ArmHvcLib.h>
23 #include <Library/UefiBootServicesTableLib.h>
24
25 #include <IndustryStandard/ArmStdSmc.h>
26
27 #include <Protocol/FdtClient.h>
28
29 STATIC UINT32 mArmPsciMethod;
30
31 RETURN_STATUS
32 EFIAPI
33 ArmPsciResetSystemLibConstructor (
34 VOID
35 )
36 {
37 EFI_STATUS Status;
38 FDT_CLIENT_PROTOCOL *FdtClient;
39 CONST VOID *Prop;
40
41 Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,
42 (VOID **)&FdtClient);
43 ASSERT_EFI_ERROR (Status);
44
45 Status = FdtClient->FindCompatibleNodeProperty (FdtClient, "arm,psci-0.2",
46 "method", &Prop, NULL);
47 if (EFI_ERROR (Status)) {
48 return Status;
49 }
50
51 if (AsciiStrnCmp (Prop, "hvc", 3) == 0) {
52 mArmPsciMethod = 1;
53 } else if (AsciiStrnCmp (Prop, "smc", 3) == 0) {
54 mArmPsciMethod = 2;
55 } else {
56 DEBUG ((EFI_D_ERROR, "%a: Unknown PSCI method \"%a\"\n", __FUNCTION__,
57 Prop));
58 return EFI_NOT_FOUND;
59 }
60 return EFI_SUCCESS;
61 }
62
63 /**
64 This function causes a system-wide reset (cold reset), in which
65 all circuitry within the system returns to its initial state. This type of reset
66 is asynchronous to system operation and operates without regard to
67 cycle boundaries.
68
69 If this function returns, it means that the system does not support cold reset.
70 **/
71 VOID
72 EFIAPI
73 ResetCold (
74 VOID
75 )
76 {
77 ARM_SMC_ARGS ArmSmcArgs;
78 ARM_HVC_ARGS ArmHvcArgs;
79
80 // Send a PSCI 0.2 SYSTEM_RESET command
81 ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET;
82 ArmHvcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET;
83
84 switch (mArmPsciMethod) {
85 case 1:
86 ArmCallHvc (&ArmHvcArgs);
87 break;
88
89 case 2:
90 ArmCallSmc (&ArmSmcArgs);
91 break;
92
93 default:
94 DEBUG ((EFI_D_ERROR, "%a: no PSCI method defined\n", __FUNCTION__));
95 }
96 }
97
98 /**
99 This function causes a system-wide initialization (warm reset), in which all processors
100 are set to their initial state. Pending cycles are not corrupted.
101
102 If this function returns, it means that the system does not support warm reset.
103 **/
104 VOID
105 EFIAPI
106 ResetWarm (
107 VOID
108 )
109 {
110 // Map a warm reset into a cold reset
111 ResetCold ();
112 }
113
114 /**
115 This function causes the system to enter a power state equivalent
116 to the ACPI G2/S5 or G3 states.
117
118 If this function returns, it means that the system does not support shutdown reset.
119 **/
120 VOID
121 EFIAPI
122 ResetShutdown (
123 VOID
124 )
125 {
126 ARM_SMC_ARGS ArmSmcArgs;
127 ARM_HVC_ARGS ArmHvcArgs;
128
129 // Send a PSCI 0.2 SYSTEM_OFF command
130 ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_OFF;
131 ArmHvcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_OFF;
132
133 switch (mArmPsciMethod) {
134 case 1:
135 ArmCallHvc (&ArmHvcArgs);
136 break;
137
138 case 2:
139 ArmCallSmc (&ArmSmcArgs);
140 break;
141
142 default:
143 DEBUG ((EFI_D_ERROR, "%a: no PSCI method defined\n", __FUNCTION__));
144 }
145 }
146
147 /**
148 This function causes the system to enter S3 and then wake up immediately.
149
150 If this function returns, it means that the system does not support S3 feature.
151 **/
152 VOID
153 EFIAPI
154 EnterS3WithImmediateWake (
155 VOID
156 )
157 {
158 // not implemented
159 }
160
161 /**
162 This function causes a systemwide reset. The exact type of the reset is
163 defined by the EFI_GUID that follows the Null-terminated Unicode string passed
164 into ResetData. If the platform does not recognize the EFI_GUID in ResetData
165 the platform must pick a supported reset type to perform.The platform may
166 optionally log the parameters from any non-normal reset that occurs.
167
168 @param[in] DataSize The size, in bytes, of ResetData.
169 @param[in] ResetData The data buffer starts with a Null-terminated string,
170 followed by the EFI_GUID.
171 **/
172 VOID
173 EFIAPI
174 ResetPlatformSpecific (
175 IN UINTN DataSize,
176 IN VOID *ResetData
177 )
178 {
179 // Map the platform specific reset as reboot
180 ResetCold ();
181 }