]>
Commit | Line | Data |
---|---|---|
e7aac7fc RC |
1 | /** @file\r |
2 | \r | |
3 | Copyright (c) 2022, Qualcomm Innovation Center, Inc. All rights reserved.<BR>\r | |
4 | Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r | |
5 | Portions copyright (c) 2011, Apple Inc. All rights reserved.\r | |
6 | \r | |
7 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
8 | \r | |
9 | **/\r | |
10 | \r | |
11 | #ifndef MP_SERVICES_INTERNAL_H_\r | |
12 | #define MP_SERVICES_INTERNAL_H_\r | |
13 | \r | |
14 | #include <Protocol/Cpu.h>\r | |
15 | #include <Protocol/MpService.h>\r | |
16 | \r | |
17 | #include <Library/BaseLib.h>\r | |
18 | #include <Library/UefiLib.h>\r | |
19 | \r | |
20 | #define AP_STACK_SIZE 0x1000\r | |
21 | \r | |
22 | //\r | |
23 | // Internal Data Structures\r | |
24 | //\r | |
25 | \r | |
26 | //\r | |
27 | // AP state\r | |
28 | //\r | |
29 | // The state transitions for an AP when it processes a procedure are:\r | |
30 | // Idle ----> Ready ----> Busy ----> Finished ----> Idle\r | |
31 | // [BSP] [BSP] [AP] [BSP]\r | |
32 | //\r | |
33 | typedef enum {\r | |
34 | CpuStateIdle,\r | |
35 | CpuStateReady,\r | |
36 | CpuStateBlocked,\r | |
37 | CpuStateBusy,\r | |
38 | CpuStateFinished,\r | |
39 | CpuStateDisabled\r | |
40 | } CPU_STATE;\r | |
41 | \r | |
42 | //\r | |
43 | // Define Individual Processor Data block.\r | |
44 | //\r | |
45 | typedef struct {\r | |
46 | EFI_PROCESSOR_INFORMATION Info;\r | |
47 | EFI_AP_PROCEDURE Procedure;\r | |
48 | VOID *Parameter;\r | |
49 | CPU_STATE State;\r | |
50 | EFI_EVENT CheckThisAPEvent;\r | |
51 | EFI_EVENT WaitEvent;\r | |
52 | UINTN Timeout;\r | |
53 | UINTN TimeTaken;\r | |
54 | BOOLEAN TimeoutActive;\r | |
55 | BOOLEAN *SingleApFinished;\r | |
56 | } CPU_AP_DATA;\r | |
57 | \r | |
58 | //\r | |
59 | // Define MP data block which consumes individual processor block.\r | |
60 | //\r | |
61 | typedef struct {\r | |
62 | UINTN NumberOfProcessors;\r | |
63 | UINTN NumberOfEnabledProcessors;\r | |
64 | EFI_EVENT CheckAllAPsEvent;\r | |
65 | EFI_EVENT AllWaitEvent;\r | |
66 | UINTN FinishCount;\r | |
67 | UINTN StartCount;\r | |
68 | EFI_AP_PROCEDURE Procedure;\r | |
69 | VOID *ProcedureArgument;\r | |
70 | BOOLEAN SingleThread;\r | |
71 | UINTN StartedNumber;\r | |
72 | CPU_AP_DATA *CpuData;\r | |
73 | UINTN *FailedList;\r | |
74 | UINTN FailedListIndex;\r | |
75 | UINTN AllTimeout;\r | |
76 | UINTN AllTimeTaken;\r | |
77 | BOOLEAN AllTimeoutActive;\r | |
78 | } CPU_MP_DATA;\r | |
79 | \r | |
80 | /** Secondary core entry point.\r | |
81 | \r | |
82 | **/\r | |
83 | VOID\r | |
84 | ApEntryPoint (\r | |
85 | VOID\r | |
86 | );\r | |
87 | \r | |
88 | /** C entry-point for the AP.\r | |
89 | This function gets called from the assembly function ApEntryPoint.\r | |
90 | **/\r | |
91 | VOID\r | |
92 | ApProcedure (\r | |
93 | VOID\r | |
94 | );\r | |
95 | \r | |
96 | /** Turns on the specified core using PSCI and executes the user-supplied\r | |
97 | function that's been configured via a previous call to SetApProcedure.\r | |
98 | \r | |
99 | @param ProcessorIndex The index of the core to turn on.\r | |
100 | \r | |
101 | @retval EFI_SUCCESS The processor was successfully turned on.\r | |
102 | @retval EFI_DEVICE_ERROR An error occurred turning the processor on.\r | |
103 | \r | |
104 | **/\r | |
105 | STATIC\r | |
106 | EFI_STATUS\r | |
107 | EFIAPI\r | |
108 | DispatchCpu (\r | |
109 | IN UINTN ProcessorIndex\r | |
110 | );\r | |
111 | \r | |
112 | /** Returns whether the specified processor is the BSP.\r | |
113 | \r | |
114 | @param[in] ProcessorIndex The index the processor to check.\r | |
115 | \r | |
116 | @return TRUE if the processor is the BSP, FALSE otherwise.\r | |
117 | **/\r | |
118 | STATIC\r | |
119 | BOOLEAN\r | |
120 | IsProcessorBSP (\r | |
121 | UINTN ProcessorIndex\r | |
122 | );\r | |
123 | \r | |
124 | /** Returns whether the processor executing this function is the BSP.\r | |
125 | \r | |
126 | @return Whether the current processor is the BSP.\r | |
127 | **/\r | |
128 | STATIC\r | |
129 | BOOLEAN\r | |
130 | IsCurrentProcessorBSP (\r | |
131 | VOID\r | |
132 | );\r | |
133 | \r | |
134 | /** Returns whether the specified processor is enabled.\r | |
135 | \r | |
136 | @param[in] ProcessorIndex The index of the processor to check.\r | |
137 | \r | |
138 | @return TRUE if the processor is enabled, FALSE otherwise.\r | |
139 | **/\r | |
140 | STATIC\r | |
141 | BOOLEAN\r | |
142 | IsProcessorEnabled (\r | |
143 | UINTN ProcessorIndex\r | |
144 | );\r | |
145 | \r | |
146 | /** Configures the processor context with the user-supplied procedure and\r | |
147 | argument.\r | |
148 | \r | |
149 | @param CpuData The processor context.\r | |
150 | @param Procedure The user-supplied procedure.\r | |
151 | @param ProcedureArgument The user-supplied procedure argument.\r | |
152 | \r | |
153 | **/\r | |
154 | STATIC\r | |
155 | VOID\r | |
156 | SetApProcedure (\r | |
157 | IN CPU_AP_DATA *CpuData,\r | |
158 | IN EFI_AP_PROCEDURE Procedure,\r | |
159 | IN VOID *ProcedureArgument\r | |
160 | );\r | |
161 | \r | |
162 | /**\r | |
163 | Get the Application Processors state.\r | |
164 | \r | |
165 | @param[in] CpuData The pointer to CPU_AP_DATA of specified AP\r | |
166 | \r | |
167 | @return The AP status\r | |
168 | **/\r | |
169 | CPU_STATE\r | |
170 | GetApState (\r | |
171 | IN CPU_AP_DATA *CpuData\r | |
172 | );\r | |
173 | \r | |
174 | /** Returns the index of the next processor that is blocked.\r | |
175 | \r | |
176 | @param[out] NextNumber The index of the next blocked processor.\r | |
177 | \r | |
178 | @retval EFI_SUCCESS Successfully found the next blocked processor.\r | |
179 | @retval EFI_NOT_FOUND There are no blocked processors.\r | |
180 | \r | |
181 | **/\r | |
182 | STATIC\r | |
183 | EFI_STATUS\r | |
184 | GetNextBlockedNumber (\r | |
185 | OUT UINTN *NextNumber\r | |
186 | );\r | |
187 | \r | |
188 | /** Stalls the BSP for the minimum of gPollInterval and Timeout.\r | |
189 | \r | |
190 | @param[in] Timeout The time limit in microseconds remaining for\r | |
191 | APs to return from Procedure.\r | |
192 | \r | |
193 | @retval StallTime Time of execution stall.\r | |
194 | **/\r | |
195 | STATIC\r | |
196 | UINTN\r | |
197 | CalculateAndStallInterval (\r | |
198 | IN UINTN Timeout\r | |
199 | );\r | |
200 | \r | |
201 | /** Sets up the state for the StartupAllAPs function.\r | |
202 | \r | |
203 | @param SingleThread Whether the APs will execute sequentially.\r | |
204 | \r | |
205 | **/\r | |
206 | STATIC\r | |
207 | VOID\r | |
208 | StartupAllAPsPrepareState (\r | |
209 | IN BOOLEAN SingleThread\r | |
210 | );\r | |
211 | \r | |
212 | /** Handles execution of StartupAllAPs when a WaitEvent has been specified.\r | |
213 | \r | |
214 | @param Procedure The user-supplied procedure.\r | |
215 | @param ProcedureArgument The user-supplied procedure argument.\r | |
216 | @param WaitEvent The wait event to be signaled when the work is\r | |
217 | complete or a timeout has occurred.\r | |
218 | @param TimeoutInMicroseconds The timeout for the work to be completed. Zero\r | |
219 | indicates an infinite timeout.\r | |
220 | @param SingleThread Whether the APs will execute sequentially.\r | |
221 | @param FailedCpuList User-supplied pointer for list of failed CPUs.\r | |
222 | \r | |
223 | @return EFI_SUCCESS on success.\r | |
224 | **/\r | |
225 | STATIC\r | |
226 | EFI_STATUS\r | |
227 | StartupAllAPsWithWaitEvent (\r | |
228 | IN EFI_AP_PROCEDURE Procedure,\r | |
229 | IN VOID *ProcedureArgument,\r | |
230 | IN EFI_EVENT WaitEvent,\r | |
231 | IN UINTN TimeoutInMicroseconds,\r | |
232 | IN BOOLEAN SingleThread,\r | |
233 | IN UINTN **FailedCpuList\r | |
234 | );\r | |
235 | \r | |
236 | /** Handles execution of StartupAllAPs when no wait event has been specified.\r | |
237 | \r | |
238 | @param Procedure The user-supplied procedure.\r | |
239 | @param ProcedureArgument The user-supplied procedure argument.\r | |
240 | @param TimeoutInMicroseconds The timeout for the work to be completed. Zero\r | |
241 | indicates an infinite timeout.\r | |
242 | @param SingleThread Whether the APs will execute sequentially.\r | |
243 | @param FailedCpuList User-supplied pointer for list of failed CPUs.\r | |
244 | \r | |
245 | @return EFI_SUCCESS on success.\r | |
246 | **/\r | |
247 | STATIC\r | |
248 | EFI_STATUS\r | |
249 | StartupAllAPsNoWaitEvent (\r | |
250 | IN EFI_AP_PROCEDURE Procedure,\r | |
251 | IN VOID *ProcedureArgument,\r | |
252 | IN UINTN TimeoutInMicroseconds,\r | |
253 | IN BOOLEAN SingleThread,\r | |
254 | IN UINTN **FailedCpuList\r | |
255 | );\r | |
256 | \r | |
257 | /** Adds the specified processor the list of failed processors.\r | |
258 | \r | |
259 | @param ProcessorIndex The processor index to add.\r | |
260 | @param ApState Processor state.\r | |
261 | \r | |
262 | **/\r | |
263 | STATIC\r | |
264 | VOID\r | |
265 | AddProcessorToFailedList (\r | |
266 | UINTN ProcessorIndex,\r | |
267 | CPU_STATE ApState\r | |
268 | );\r | |
269 | \r | |
270 | /** Handles the StartupAllAPs case where the timeout has occurred.\r | |
271 | \r | |
272 | **/\r | |
273 | STATIC\r | |
274 | VOID\r | |
275 | ProcessStartupAllAPsTimeout (\r | |
276 | VOID\r | |
277 | );\r | |
278 | \r | |
279 | /**\r | |
280 | If a timeout is specified in StartupAllAps(), a timer is set, which invokes\r | |
281 | this procedure periodically to check whether all APs have finished.\r | |
282 | \r | |
283 | @param[in] Event The WaitEvent the user supplied.\r | |
284 | @param[in] Context The event context.\r | |
285 | **/\r | |
286 | STATIC\r | |
287 | VOID\r | |
288 | EFIAPI\r | |
289 | CheckAllAPsStatus (\r | |
290 | IN EFI_EVENT Event,\r | |
291 | IN VOID *Context\r | |
292 | );\r | |
293 | \r | |
294 | /** Invoked periodically via a timer to check the state of the processor.\r | |
295 | \r | |
296 | @param Event The event supplied by the timer expiration.\r | |
297 | @param Context The processor context.\r | |
298 | \r | |
299 | **/\r | |
300 | STATIC\r | |
301 | VOID\r | |
302 | EFIAPI\r | |
303 | CheckThisAPStatus (\r | |
304 | IN EFI_EVENT Event,\r | |
305 | IN VOID *Context\r | |
306 | );\r | |
307 | \r | |
308 | /**\r | |
309 | This function is called by all processors (both BSP and AP) once and collects\r | |
310 | MP related data.\r | |
311 | \r | |
312 | @param BSP TRUE if the processor is the BSP.\r | |
313 | @param Mpidr The MPIDR for the specified processor. This should be\r | |
314 | the full MPIDR and not only the affinity bits.\r | |
315 | @param ProcessorIndex The index of the processor.\r | |
316 | \r | |
317 | @return EFI_SUCCESS if the data for the processor collected and filled in.\r | |
318 | \r | |
319 | **/\r | |
320 | STATIC\r | |
321 | EFI_STATUS\r | |
322 | FillInProcessorInformation (\r | |
323 | IN BOOLEAN BSP,\r | |
324 | IN UINTN Mpidr,\r | |
325 | IN UINTN ProcessorIndex\r | |
326 | );\r | |
327 | \r | |
328 | /**\r | |
329 | Event notification function called when the EFI_EVENT_GROUP_READY_TO_BOOT is\r | |
330 | signaled. After this point, non-blocking mode is no longer allowed.\r | |
331 | \r | |
332 | @param Event Event whose notification function is being invoked.\r | |
333 | @param Context The pointer to the notification function's context,\r | |
334 | which is implementation-dependent.\r | |
335 | \r | |
336 | **/\r | |
337 | STATIC\r | |
338 | VOID\r | |
339 | EFIAPI\r | |
340 | ReadyToBootSignaled (\r | |
341 | IN EFI_EVENT Event,\r | |
342 | IN VOID *Context\r | |
343 | );\r | |
344 | \r | |
345 | #endif /* MP_SERVICES_INTERNAL_H_ */\r |