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