]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c
ArmPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / ArmPkg / Library / ArmSmcPsciResetSystemLib / ArmSmcPsciResetSystemLib.c
CommitLineData
b2c55e73
AB
1/** @file\r
2 ResetSystemLib implementation using PSCI calls\r
3\r
6556224e 4 Copyright (c) 2017 - 2018, Linaro Ltd. All rights reserved.<BR>\r
b2c55e73 5\r
4059386c 6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
b2c55e73
AB
7\r
8**/\r
9\r
10#include <PiDxe.h>\r
11\r
dde2dd64
AB
12#include <Library/ArmMmuLib.h>\r
13#include <Library/ArmSmcLib.h>\r
b2c55e73
AB
14#include <Library/BaseLib.h>\r
15#include <Library/DebugLib.h>\r
16#include <Library/ResetSystemLib.h>\r
dde2dd64
AB
17#include <Library/UefiBootServicesTableLib.h>\r
18#include <Library/UefiRuntimeLib.h>\r
b2c55e73
AB
19\r
20#include <IndustryStandard/ArmStdSmc.h>\r
21\r
22/**\r
23 This function causes a system-wide reset (cold reset), in which\r
24 all circuitry within the system returns to its initial state. This type of reset\r
25 is asynchronous to system operation and operates without regard to\r
26 cycle boundaries.\r
27\r
28 If this function returns, it means that the system does not support cold reset.\r
29**/\r
30VOID\r
31EFIAPI\r
32ResetCold (\r
33 VOID\r
34 )\r
35{\r
36 ARM_SMC_ARGS ArmSmcArgs;\r
37\r
38 // Send a PSCI 0.2 SYSTEM_RESET command\r
39 ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET;\r
40 ArmCallSmc (&ArmSmcArgs);\r
41}\r
42\r
43/**\r
44 This function causes a system-wide initialization (warm reset), in which all processors\r
45 are set to their initial state. Pending cycles are not corrupted.\r
46\r
47 If this function returns, it means that the system does not support warm reset.\r
48**/\r
49VOID\r
50EFIAPI\r
51ResetWarm (\r
52 VOID\r
53 )\r
54{\r
55 // Map a warm reset into a cold reset\r
56 ResetCold ();\r
57}\r
58\r
59/**\r
60 This function causes the system to enter a power state equivalent\r
61 to the ACPI G2/S5 or G3 states.\r
62\r
63 If this function returns, it means that the system does not support shutdown reset.\r
64**/\r
65VOID\r
66EFIAPI\r
67ResetShutdown (\r
68 VOID\r
69 )\r
70{\r
71 ARM_SMC_ARGS ArmSmcArgs;\r
72\r
73 // Send a PSCI 0.2 SYSTEM_OFF command\r
74 ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_OFF;\r
75 ArmCallSmc (&ArmSmcArgs);\r
76}\r
77\r
6556224e
AB
78VOID DisableMmuAndReenterPei (VOID);\r
79\r
b2c55e73
AB
80/**\r
81 This function causes the system to enter S3 and then wake up immediately.\r
82\r
83 If this function returns, it means that the system does not support S3 feature.\r
84**/\r
85VOID\r
86EFIAPI\r
87EnterS3WithImmediateWake (\r
88 VOID\r
89 )\r
90{\r
6556224e
AB
91 EFI_PHYSICAL_ADDRESS Alloc;\r
92 EFI_MEMORY_DESCRIPTOR *MemMap;\r
93 UINTN MemMapSize;\r
94 UINTN MapKey, DescriptorSize;\r
95 UINT32 DescriptorVersion;\r
96 EFI_STATUS Status;\r
dde2dd64
AB
97\r
98 if (FeaturePcdGet (PcdArmReenterPeiForCapsuleWarmReboot) &&\r
99 !EfiAtRuntime ()) {\r
100 //\r
101 // At boot time, we are the only core running, so we can implement the\r
102 // immediate wake (which is used by capsule update) by disabling the MMU\r
103 // and interrupts, and jumping to the PEI entry point.\r
104 //\r
dde2dd64 105\r
6556224e
AB
106 //\r
107 // Obtain the size of the memory map\r
108 //\r
109 MemMapSize = 0;\r
110 MemMap = NULL;\r
111 Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize,\r
112 &DescriptorVersion);\r
113 ASSERT (Status == EFI_BUFFER_TOO_SMALL);\r
114\r
115 //\r
116 // Add some slack to the allocation to cater for changes in the memory\r
117 // map if ExitBootServices () fails the first time around.\r
118 //\r
119 MemMapSize += SIZE_4KB;\r
120 Status = gBS->AllocatePages (AllocateAnyPages, EfiBootServicesData,\r
121 EFI_SIZE_TO_PAGES (MemMapSize), &Alloc);\r
122 ASSERT_EFI_ERROR (Status);\r
123\r
124 MemMap = (EFI_MEMORY_DESCRIPTOR *)(UINTN)Alloc;\r
125\r
126 Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize,\r
127 &DescriptorVersion);\r
128 ASSERT_EFI_ERROR (Status);\r
129\r
130 Status = gBS->ExitBootServices (gImageHandle, MapKey);\r
131 if (EFI_ERROR (Status)) {\r
132 //\r
133 // ExitBootServices () may fail the first time around if an event fired\r
134 // right after the call to GetMemoryMap() which allocated or freed memory.\r
135 // Since that first call to ExitBootServices () will disarm the timer,\r
136 // this is guaranteed not to happen again, so one additional attempt\r
137 // should suffice.\r
138 //\r
139 Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize,\r
140 &DescriptorVersion);\r
141 ASSERT_EFI_ERROR (Status);\r
142\r
143 Status = gBS->ExitBootServices (gImageHandle, MapKey);\r
144 ASSERT_EFI_ERROR (Status);\r
145 }\r
146\r
147 DisableMmuAndReenterPei ();\r
dde2dd64 148 }\r
b2c55e73
AB
149}\r
150\r
151/**\r
152 This function causes a systemwide reset. The exact type of the reset is\r
153 defined by the EFI_GUID that follows the Null-terminated Unicode string passed\r
154 into ResetData. If the platform does not recognize the EFI_GUID in ResetData\r
155 the platform must pick a supported reset type to perform.The platform may\r
156 optionally log the parameters from any non-normal reset that occurs.\r
157\r
158 @param[in] DataSize The size, in bytes, of ResetData.\r
159 @param[in] ResetData The data buffer starts with a Null-terminated string,\r
160 followed by the EFI_GUID.\r
161**/\r
162VOID\r
163EFIAPI\r
164ResetPlatformSpecific (\r
165 IN UINTN DataSize,\r
166 IN VOID *ResetData\r
167 )\r
168{\r
169 // Map the platform specific reset as reboot\r
170 ResetCold ();\r
171}\r