]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Drivers/CpuDxe/CpuDxe.c
ArmPkg: Create MpCoreInfo PPI and HOB to describe CPU Cores on a MPCore platform
[mirror_edk2.git] / ArmPkg / Drivers / CpuDxe / CpuDxe.c
CommitLineData
2ef2b01e
A
1/** @file\r
2\r
d6ebcab7 3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
8513037f 4 Copyright (c) 2011, ARM Limited. All rights reserved.\r
2ef2b01e 5 \r
d6ebcab7 6 This program and the accompanying materials\r
2ef2b01e
A
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 "CpuDxe.h"\r
17\r
8513037f 18#include <Guid/IdleLoopEvent.h>\r
19\r
8a4d81e6
A
20BOOLEAN mInterruptState = FALSE;\r
21\r
f659880b
A
22\r
23/**\r
24 This function flushes the range of addresses from Start to Start+Length \r
25 from the processor's data cache. If Start is not aligned to a cache line \r
26 boundary, then the bytes before Start to the preceding cache line boundary \r
27 are also flushed. If Start+Length is not aligned to a cache line boundary, \r
28 then the bytes past Start+Length to the end of the next cache line boundary \r
29 are also flushed. The FlushType of EfiCpuFlushTypeWriteBackInvalidate must be \r
30 supported. If the data cache is fully coherent with all DMA operations, then \r
31 this function can just return EFI_SUCCESS. If the processor does not support \r
32 flushing a range of the data cache, then the entire data cache can be flushed.\r
33\r
34 @param This The EFI_CPU_ARCH_PROTOCOL instance.\r
35 @param Start The beginning physical address to flush from the processor's data\r
36 cache.\r
37 @param Length The number of bytes to flush from the processor's data cache. This\r
38 function may flush more bytes than Length specifies depending upon\r
39 the granularity of the flush operation that the processor supports.\r
40 @param FlushType Specifies the type of flush operation to perform.\r
41\r
42 @retval EFI_SUCCESS The address range from Start to Start+Length was flushed from\r
43 the processor's data cache.\r
44 @retval EFI_UNSUPPORTEDT The processor does not support the cache flush type specified\r
45 by FlushType.\r
46 @retval EFI_DEVICE_ERROR The address range from Start to Start+Length could not be flushed\r
47 from the processor's data cache.\r
48\r
49**/\r
2ef2b01e
A
50EFI_STATUS\r
51EFIAPI\r
52CpuFlushCpuDataCache (\r
53 IN EFI_CPU_ARCH_PROTOCOL *This,\r
54 IN EFI_PHYSICAL_ADDRESS Start,\r
55 IN UINT64 Length,\r
56 IN EFI_CPU_FLUSH_TYPE FlushType\r
57 )\r
58{\r
f659880b 59\r
2ef2b01e
A
60 switch (FlushType) {\r
61 case EfiCpuFlushTypeWriteBack:\r
8a4d81e6 62 WriteBackDataCacheRange ((VOID *)(UINTN)Start, (UINTN)Length);\r
2ef2b01e
A
63 break;\r
64 case EfiCpuFlushTypeInvalidate:\r
8a4d81e6 65 InvalidateDataCacheRange ((VOID *)(UINTN)Start, (UINTN)Length);\r
2ef2b01e
A
66 break;\r
67 case EfiCpuFlushTypeWriteBackInvalidate:\r
8a4d81e6 68 WriteBackInvalidateDataCacheRange ((VOID *)(UINTN)Start, (UINTN)Length);\r
2ef2b01e
A
69 break;\r
70 default:\r
71 return EFI_INVALID_PARAMETER;\r
72 }\r
73 \r
74 return EFI_SUCCESS;\r
75}\r
76\r
f659880b
A
77\r
78/**\r
79 This function enables interrupt processing by the processor. \r
80\r
81 @param This The EFI_CPU_ARCH_PROTOCOL instance.\r
82\r
83 @retval EFI_SUCCESS Interrupts are enabled on the processor.\r
84 @retval EFI_DEVICE_ERROR Interrupts could not be enabled on the processor.\r
85\r
86**/\r
2ef2b01e
A
87EFI_STATUS\r
88EFIAPI\r
89CpuEnableInterrupt (\r
90 IN EFI_CPU_ARCH_PROTOCOL *This\r
91 )\r
92{\r
d213712d 93 ArmEnableInterrupts ();\r
8a4d81e6
A
94\r
95 mInterruptState = TRUE;\r
2ef2b01e
A
96 return EFI_SUCCESS;\r
97}\r
98\r
99\r
f659880b
A
100/**\r
101 This function disables interrupt processing by the processor.\r
102\r
103 @param This The EFI_CPU_ARCH_PROTOCOL instance.\r
104\r
105 @retval EFI_SUCCESS Interrupts are disabled on the processor.\r
106 @retval EFI_DEVICE_ERROR Interrupts could not be disabled on the processor.\r
107\r
108**/\r
2ef2b01e
A
109EFI_STATUS\r
110EFIAPI\r
111CpuDisableInterrupt (\r
112 IN EFI_CPU_ARCH_PROTOCOL *This\r
113 )\r
114{\r
d213712d 115 ArmDisableInterrupts ();\r
8a4d81e6
A
116\r
117 mInterruptState = FALSE;\r
2ef2b01e
A
118 return EFI_SUCCESS;\r
119}\r
120\r
f659880b
A
121\r
122/**\r
123 This function retrieves the processor's current interrupt state a returns it in \r
124 State. If interrupts are currently enabled, then TRUE is returned. If interrupts \r
125 are currently disabled, then FALSE is returned.\r
126\r
127 @param This The EFI_CPU_ARCH_PROTOCOL instance.\r
128 @param State A pointer to the processor's current interrupt state. Set to TRUE if\r
129 interrupts are enabled and FALSE if interrupts are disabled.\r
130\r
131 @retval EFI_SUCCESS The processor's current interrupt state was returned in State.\r
132 @retval EFI_INVALID_PARAMETER State is NULL.\r
133\r
134**/\r
2ef2b01e
A
135EFI_STATUS\r
136EFIAPI\r
137CpuGetInterruptState (\r
138 IN EFI_CPU_ARCH_PROTOCOL *This,\r
139 OUT BOOLEAN *State\r
140 )\r
141{\r
142 if (State == NULL) {\r
143 return EFI_INVALID_PARAMETER;\r
144 }\r
145\r
8a4d81e6 146 *State = mInterruptState;\r
2ef2b01e
A
147 return EFI_SUCCESS;\r
148}\r
149\r
f659880b
A
150\r
151/**\r
152 This function generates an INIT on the processor. If this function succeeds, then the\r
153 processor will be reset, and control will not be returned to the caller. If InitType is \r
154 not supported by this processor, or the processor cannot programmatically generate an \r
155 INIT without help from external hardware, then EFI_UNSUPPORTED is returned. If an error \r
156 occurs attempting to generate an INIT, then EFI_DEVICE_ERROR is returned.\r
157\r
158 @param This The EFI_CPU_ARCH_PROTOCOL instance.\r
159 @param InitType The type of processor INIT to perform.\r
160\r
161 @retval EFI_SUCCESS The processor INIT was performed. This return code should never be seen.\r
162 @retval EFI_UNSUPPORTED The processor INIT operation specified by InitType is not supported\r
163 by this processor.\r
164 @retval EFI_DEVICE_ERROR The processor INIT failed.\r
165\r
166**/\r
2ef2b01e
A
167EFI_STATUS\r
168EFIAPI\r
169CpuInit (\r
170 IN EFI_CPU_ARCH_PROTOCOL *This,\r
171 IN EFI_CPU_INIT_TYPE InitType\r
172 )\r
173{\r
174 return EFI_UNSUPPORTED;\r
175}\r
176\r
177EFI_STATUS\r
178EFIAPI\r
179CpuRegisterInterruptHandler (\r
180 IN EFI_CPU_ARCH_PROTOCOL *This,\r
181 IN EFI_EXCEPTION_TYPE InterruptType,\r
182 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler\r
183 )\r
184{\r
8a4d81e6 185 return RegisterInterruptHandler (InterruptType, InterruptHandler);\r
2ef2b01e
A
186}\r
187\r
188EFI_STATUS\r
189EFIAPI\r
190CpuGetTimerValue (\r
191 IN EFI_CPU_ARCH_PROTOCOL *This,\r
192 IN UINT32 TimerIndex,\r
193 OUT UINT64 *TimerValue,\r
194 OUT UINT64 *TimerPeriod OPTIONAL\r
195 )\r
196{\r
197 return EFI_UNSUPPORTED;\r
198}\r
199\r
8513037f 200/**\r
201 Callback function for idle events.\r
202 \r
203 @param Event Event whose notification function is being invoked.\r
204 @param Context The pointer to the notification function's context,\r
205 which is implementation-dependent.\r
206\r
207**/\r
208VOID\r
209EFIAPI\r
210IdleLoopEventCallback (\r
211 IN EFI_EVENT Event,\r
212 IN VOID *Context\r
213 )\r
214{\r
215 CpuSleep ();\r
216}\r
2ef2b01e
A
217\r
218//\r
219// Globals used to initialize the protocol\r
220//\r
221EFI_HANDLE mCpuHandle = NULL;\r
222EFI_CPU_ARCH_PROTOCOL mCpu = {\r
223 CpuFlushCpuDataCache,\r
224 CpuEnableInterrupt,\r
225 CpuDisableInterrupt,\r
226 CpuGetInterruptState,\r
227 CpuInit,\r
228 CpuRegisterInterruptHandler,\r
229 CpuGetTimerValue,\r
230 CpuSetMemoryAttributes,\r
231 0, // NumberOfTimers\r
232 4, // DmaBufferAlignment\r
233};\r
234\r
235EFI_STATUS\r
236CpuDxeInitialize (\r
237 IN EFI_HANDLE ImageHandle,\r
238 IN EFI_SYSTEM_TABLE *SystemTable\r
239 )\r
f659880b
A
240{\r
241 EFI_STATUS Status;\r
8513037f 242 EFI_EVENT IdleLoopEvent;\r
f659880b 243\r
8a4d81e6 244 InitializeExceptions (&mCpu); \r
f659880b 245 \r
f659880b
A
246 Status = gBS->InstallMultipleProtocolInterfaces (\r
247 &mCpuHandle, \r
248 &gEfiCpuArchProtocolGuid, &mCpu, \r
249 &gVirtualUncachedPagesProtocolGuid, &gVirtualUncachedPages,\r
250 NULL\r
251 );\r
252 \r
253 //\r
254 // Make sure GCD and MMU settings match. This API calls gDS->SetMemorySpaceAttributes ()\r
255 // and that calls EFI_CPU_ARCH_PROTOCOL.SetMemoryAttributes, so this code needs to go\r
256 // after the protocol is installed\r
257 //\r
258 SyncCacheConfig (&mCpu);\r
259 \r
44788bae 260 // If the platform is a MPCore system then install the Configuration Table describing the\r
261 // secondary core states\r
262 if (ArmIsMPCore()) {\r
263 PublishArmProcessorTable();\r
264 }\r
265\r
8513037f 266 //\r
267 // Setup a callback for idle events\r
268 //\r
269 Status = gBS->CreateEventEx (\r
270 EVT_NOTIFY_SIGNAL,\r
271 TPL_NOTIFY,\r
272 IdleLoopEventCallback,\r
273 NULL,\r
274 &gIdleLoopEventGuid,\r
275 &IdleLoopEvent\r
276 );\r
277 ASSERT_EFI_ERROR (Status);\r
278\r
f659880b 279 return Status;\r
2ef2b01e 280}\r