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