]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Compatibility/MpServicesOnFrameworkMpServicesThunk/MpServicesOnFrameworkMpServicesThunk.h
Fix a issue to support the callback related to framework IFR REF opcode. Its callback...
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / MpServicesOnFrameworkMpServicesThunk / MpServicesOnFrameworkMpServicesThunk.h
CommitLineData
768e2a90 1/** @file\r
2Include file for PI MP Services Protocol Thunk.\r
3\r
4Copyright (c) 2009 Intel Corporation. <BR>\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12Module Name:\r
13\r
14**/\r
15\r
16#ifndef _MP_SERVICES_ON_FRAMEWORK_MP_SERVICES_THUNK_\r
17#define _MP_SERVICES_ON_FRAMEWORK_MP_SERVICES_THUNK_\r
18\r
19#include <Protocol/MpService.h>\r
20#include <Protocol/FrameworkMpService.h>\r
21#include <Protocol/GenericMemoryTest.h>\r
22\r
23#include <Library/BaseLib.h>\r
24#include <Library/SynchronizationLib.h>\r
25#include <Library/DebugLib.h>\r
26#include <Library/UefiLib.h>\r
27#include <Library/BaseMemoryLib.h>\r
28#include <Library/UefiDriverEntryPoint.h>\r
29#include <Library/MemoryAllocationLib.h>\r
30#include <Library/UefiBootServicesTableLib.h>\r
31#include <Library/DxeServicesTableLib.h>\r
32#include <Library/IoLib.h>\r
33#include <Library/TimerLib.h>\r
34\r
35#define AP_STACK_SIZE 0x8000\r
36#define MAX_CPU_NUMBER 256\r
37\r
38//\r
39// Bit definition for IPI\r
40//\r
41#define BROADCAST_MODE_ALL_EXCLUDING_SELF_BIT 0xC0000\r
42#define SPECIFY_CPU_MODE_BIT 0x00000\r
43#define TRIGGER_MODE_LEVEL_BIT 0x08000\r
44#define ASSERT_BIT 0x04000\r
45\r
46//\r
47// Local APIC register definition for IPI.\r
48//\r
49#define APIC_REGISTER_ICR_LOW_OFFSET 0x300\r
50#define APIC_REGISTER_ICR_HIGH_OFFSET 0x310\r
51\r
52typedef struct {\r
53 UINTN Lock;\r
54 VOID *StackStart;\r
55 UINTN StackSize;\r
56 VOID *ApFunction;\r
57 IA32_DESCRIPTOR GdtrProfile;\r
58 UINT32 BufferStart;\r
59 UINT32 Cr3;\r
60} MP_CPU_EXCHANGE_INFO;\r
61\r
62typedef struct {\r
63 UINT8 *RendezvousFunnelAddress;\r
64 UINTN PModeEntryOffset;\r
65 UINTN FlatJumpOffset;\r
66 UINTN LModeEntryOffset;\r
67 UINTN LongJumpOffset;\r
68 UINTN Size;\r
69} MP_ASSEMBLY_ADDRESS_MAP;\r
70\r
71typedef enum {\r
72 CpuStateIdle,\r
73 CpuStateReady,\r
74 CpuStateBusy,\r
75 CpuStateFinished,\r
76 CpuStateDisabled\r
77} CPU_STATE;\r
78\r
79//\r
80// Define Individual Processor Data block.\r
81//\r
82typedef struct {\r
83 EFI_AP_PROCEDURE volatile Procedure;\r
84 VOID* volatile Parameter;\r
85\r
86 EFI_EVENT WaitEvent;\r
87 BOOLEAN *Finished;\r
88 UINT64 ExpectedTime;\r
89 UINT64 CurrentTime;\r
90 UINT64 TotalTime;\r
91\r
92 SPIN_LOCK CpuDataLock;\r
93 CPU_STATE volatile State;\r
94\r
95} CPU_DATA_BLOCK;\r
96\r
97//\r
98// Define MP data block which consumes individual processor block.\r
99//\r
100typedef struct {\r
101 SPIN_LOCK APSerializeLock;\r
102\r
103 EFI_EVENT CheckAPsEvent;\r
104\r
105 UINTN FinishCount;\r
106 UINTN StartCount;\r
107\r
108 BOOLEAN CpuList[MAX_CPU_NUMBER];\r
109\r
110 EFI_AP_PROCEDURE Procedure;\r
111 VOID *ProcArguments;\r
112 BOOLEAN SingleThread;\r
113 EFI_EVENT WaitEvent;\r
114 UINTN **FailedCpuList;\r
115 UINT64 ExpectedTime;\r
116 UINT64 CurrentTime;\r
117 UINT64 TotalTime;\r
118\r
119 CPU_DATA_BLOCK CpuData[MAX_CPU_NUMBER];\r
120} MP_SYSTEM_DATA;\r
121\r
122/**\r
123 Implementation of GetNumberOfProcessors() service of MP Services Protocol.\r
124\r
125 This service retrieves the number of logical processor in the platform\r
126 and the number of those logical processors that are enabled on this boot.\r
127 This service may only be called from the BSP.\r
128\r
129 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.\r
130 @param NumberOfProcessors Pointer to the total number of logical processors in the system,\r
131 including the BSP and disabled APs.\r
132 @param NumberOfEnabledProcessors Pointer to the number of enabled logical processors that exist\r
133 in system, including the BSP.\r
134\r
135 @retval EFI_SUCCESS Number of logical processors and enabled logical processors retrieved..\r
136 @retval EFI_DEVICE_ERROR Caller processor is AP.\r
137 @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL\r
138 @retval EFI_INVALID_PARAMETER NumberOfEnabledProcessors is NULL\r
139\r
140**/\r
141EFI_STATUS\r
142EFIAPI\r
143GetNumberOfProcessors (\r
144 IN EFI_MP_SERVICES_PROTOCOL *This,\r
145 OUT UINTN *NumberOfProcessors,\r
146 OUT UINTN *NumberOfEnabledProcessors\r
147 );\r
148\r
149/**\r
150 Implementation of GetNumberOfProcessors() service of MP Services Protocol.\r
151\r
152 Gets detailed MP-related information on the requested processor at the\r
153 instant this call is made. This service may only be called from the BSP.\r
154\r
155 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.\r
156 @param ProcessorNumber The handle number of processor.\r
157 @param ProcessorInfoBuffer A pointer to the buffer where information for the requested processor is deposited.\r
158\r
159 @retval EFI_SUCCESS Processor information successfully returned.\r
160 @retval EFI_DEVICE_ERROR Caller processor is AP.\r
161 @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL\r
162 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber does not exist. \r
163\r
164**/\r
165EFI_STATUS\r
166EFIAPI\r
167GetProcessorInfo (\r
168 IN EFI_MP_SERVICES_PROTOCOL *This,\r
169 IN UINTN ProcessorNumber,\r
170 OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer\r
171 );\r
172\r
173/**\r
174 Implementation of StartupAllAPs() service of MP Services Protocol.\r
175\r
176 This service lets the caller get all enabled APs to execute a caller-provided function.\r
177 This service may only be called from the BSP.\r
178\r
179 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.\r
180 @param Procedure A pointer to the function to be run on enabled APs of the system.\r
181 @param SingleThread Indicates whether to execute the function simultaneously or one by one..\r
182 @param WaitEvent The event created by the caller.\r
183 If it is NULL, then execute in blocking mode.\r
184 If it is not NULL, then execute in non-blocking mode.\r
185 @param TimeoutInMicroSeconds The time limit in microseconds for this AP to finish the function.\r
186 Zero means infinity.\r
187 @param ProcedureArgument Pointer to the optional parameter of the assigned function.\r
188 @param FailedCpuList The list of processor numbers that fail to finish the function before\r
189 TimeoutInMicrosecsond expires.\r
190\r
191 @retval EFI_SUCCESS In blocking mode, all APs have finished before the timeout expired. \r
192 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched to all enabled APs.\r
193 @retval EFI_DEVICE_ERROR Caller processor is AP.\r
194 @retval EFI_NOT_STARTED No enabled AP exists in the system.\r
195 @retval EFI_NOT_READY Any enabled AP is busy.\r
196 @retval EFI_TIMEOUT In blocking mode, The timeout expired before all enabled APs have finished.\r
197 @retval EFI_INVALID_PARAMETER Procedure is NULL.\r
198\r
199**/\r
200EFI_STATUS\r
201EFIAPI\r
202StartupAllAPs (\r
203 IN EFI_MP_SERVICES_PROTOCOL *This,\r
204 IN EFI_AP_PROCEDURE Procedure,\r
205 IN BOOLEAN SingleThread,\r
206 IN EFI_EVENT WaitEvent OPTIONAL,\r
207 IN UINTN TimeoutInMicroSeconds,\r
208 IN VOID *ProcedureArgument OPTIONAL,\r
209 OUT UINTN **FailedCpuList OPTIONAL\r
210 );\r
211\r
212/**\r
213 Implementation of StartupThisAP() service of MP Services Protocol.\r
214\r
215 This service lets the caller get one enabled AP to execute a caller-provided function.\r
216 This service may only be called from the BSP.\r
217\r
218 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.\r
219 @param Procedure A pointer to the function to be run on the designated AP.\r
220 @param ProcessorNumber The handle number of AP..\r
221 @param WaitEvent The event created by the caller.\r
222 If it is NULL, then execute in blocking mode.\r
223 If it is not NULL, then execute in non-blocking mode.\r
224 @param TimeoutInMicroseconds The time limit in microseconds for this AP to finish the function.\r
225 Zero means infinity.\r
226 @param ProcedureArgument Pointer to the optional parameter of the assigned function.\r
227 @param Finished Indicates whether AP has finished assigned function.\r
228 In blocking mode, it is ignored.\r
229\r
230 @retval EFI_SUCCESS In blocking mode, specified AP has finished before the timeout expires.\r
231 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched to specified AP.\r
232 @retval EFI_DEVICE_ERROR Caller processor is AP.\r
233 @retval EFI_TIMEOUT In blocking mode, the timeout expires before specified AP has finished.\r
234 @retval EFI_NOT_READY Specified AP is busy.\r
235 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber does not exist.\r
236 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.\r
237 @retval EFI_INVALID_PARAMETER Procedure is NULL.\r
238\r
239**/\r
240EFI_STATUS\r
241EFIAPI\r
242StartupThisAP (\r
243 IN EFI_MP_SERVICES_PROTOCOL *This,\r
244 IN EFI_AP_PROCEDURE Procedure,\r
245 IN UINTN ProcessorNumber,\r
246 IN EFI_EVENT WaitEvent OPTIONAL,\r
247 IN UINTN TimeoutInMicroseconds,\r
248 IN VOID *ProcedureArgument OPTIONAL,\r
249 OUT BOOLEAN *Finished OPTIONAL\r
250 );\r
251\r
252/**\r
253 Implementation of SwitchBSP() service of MP Services Protocol.\r
254\r
255 This service switches the requested AP to be the BSP from that point onward.\r
256 This service may only be called from the current BSP.\r
257\r
258 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.\r
259 @param ProcessorNumber The handle number of processor.\r
260 @param EnableOldBSP Whether to enable or disable the original BSP.\r
261\r
262 @retval EFI_SUCCESS BSP successfully switched.\r
263 @retval EFI_DEVICE_ERROR Caller processor is AP.\r
264 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber does not exist.\r
265 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.\r
266 @retval EFI_NOT_READY Specified AP is busy.\r
267\r
268**/\r
269EFI_STATUS\r
270EFIAPI\r
271SwitchBSP (\r
272 IN EFI_MP_SERVICES_PROTOCOL *This,\r
273 IN UINTN ProcessorNumber,\r
274 IN BOOLEAN EnableOldBSP\r
275 );\r
276\r
277/**\r
278 Implementation of EnableDisableAP() service of MP Services Protocol.\r
279\r
280 This service lets the caller enable or disable an AP.\r
281 This service may only be called from the BSP.\r
282\r
283 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.\r
284 @param ProcessorNumber The handle number of processor.\r
285 @param EnableAP Indicates whether the newstate of the AP is enabled or disabled.\r
286 @param HealthFlag Indicates new health state of the AP..\r
287\r
288 @retval EFI_SUCCESS AP successfully enabled or disabled.\r
289 @retval EFI_DEVICE_ERROR Caller processor is AP.\r
290 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber does not exist.\r
291 @retval EFI_INVALID_PARAMETERS ProcessorNumber specifies the BSP.\r
292 \r
293**/\r
294EFI_STATUS\r
295EFIAPI\r
296EnableDisableAP (\r
297 IN EFI_MP_SERVICES_PROTOCOL *This,\r
298 IN UINTN ProcessorNumber,\r
299 IN BOOLEAN EnableAP,\r
300 IN UINT32 *HealthFlag OPTIONAL\r
301 );\r
302\r
303/**\r
304 Implementation of WhoAmI() service of MP Services Protocol.\r
305\r
306 This service lets the caller processor get its handle number.\r
307 This service may be called from the BSP and APs.\r
308\r
309 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.\r
310 @param ProcessorNumber Pointer to the handle number of AP.\r
311\r
312 @retval EFI_SUCCESS Processor number successfully returned.\r
313 @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL\r
314\r
315**/\r
316EFI_STATUS\r
317EFIAPI\r
318WhoAmI (\r
319 IN EFI_MP_SERVICES_PROTOCOL *This,\r
320 OUT UINTN *ProcessorNumber\r
321 );\r
322\r
323/**\r
324 Checks APs' status periodically.\r
325\r
326 This function is triggerred by timer perodically to check the\r
327 state of APs for StartupAllAPs() and StartupThisAP() executed\r
328 in non-blocking mode.\r
329\r
330 @param Event Event triggered.\r
331 @param Context Parameter passed with the event.\r
332\r
333**/\r
334VOID\r
335EFIAPI\r
336CheckAPsStatus (\r
337 IN EFI_EVENT Event,\r
338 IN VOID *Context\r
339 );\r
340\r
341/**\r
342 Checks status of all APs.\r
343\r
344 This function checks whether all APs have finished task assigned by StartupAllAPs(),\r
345 and whether timeout expires.\r
346\r
347 @retval EFI_SUCCESS All APs have finished task assigned by StartupAllAPs().\r
348 @retval EFI_TIMEOUT The timeout expires.\r
349 @retval EFI_NOT_READY APs have not finished task and timeout has not expired.\r
350\r
351**/\r
352EFI_STATUS\r
353CheckAllAPs (\r
354 VOID\r
355 );\r
356\r
357/**\r
358 Checks status of specified AP.\r
359\r
360 This function checks whether specified AP has finished task assigned by StartupThisAP(),\r
361 and whether timeout expires.\r
362\r
363 @param ProcessorNumber The handle number of processor.\r
364\r
365 @retval EFI_SUCCESS Specified AP has finished task assigned by StartupThisAPs().\r
366 @retval EFI_TIMEOUT The timeout expires.\r
367 @retval EFI_NOT_READY Specified AP has not finished task and timeout has not expired.\r
368\r
369**/\r
370EFI_STATUS\r
371CheckThisAP (\r
372 UINTN ProcessorNumber\r
373 );\r
374\r
375/**\r
376 Calculate timeout value and return the current performance counter value.\r
377\r
378 Calculate the number of performance counter ticks required for a timeout.\r
379 If TimeoutInMicroseconds is 0, return value is also 0, which is recognized\r
380 as infinity.\r
381\r
382 @param TimeoutInMicroseconds Timeout value in microseconds.\r
383 @param CurrentTime Returns the current value of the performance counter.\r
384\r
385 @return Expected timestamp counter for timeout.\r
386 If TimeoutInMicroseconds is 0, return value is also 0, which is recognized\r
387 as infinity.\r
388\r
389**/\r
390UINT64\r
391CalculateTimeout (\r
392 IN UINTN TimeoutInMicroseconds,\r
393 OUT UINT64 *CurrentTime\r
394 );\r
395\r
396/**\r
397 Checks whether timeout expires.\r
398\r
399 Check whether the number of ellapsed performance counter ticks required for a timeout condition\r
400 has been reached. If Timeout is zero, which means infinity, return value is always FALSE.\r
401\r
402 @param PreviousTime On input, the value of the performance counter when it was last read.\r
403 On output, the current value of the performance counter\r
404 @param TotalTime The total amount of ellapsed time in performance counter ticks.\r
405 @param Timeout The number of performance counter ticks required to reach a timeout condition.\r
406\r
407 @retval TRUE A timeout condition has been reached.\r
408 @retval FALSE A timeout condition has not been reached.\r
409\r
410**/\r
411BOOLEAN\r
412CheckTimeout (\r
413 IN OUT UINT64 *PreviousTime,\r
414 IN UINT64 *TotalTime,\r
415 IN UINT64 Timeout\r
416 );\r
417\r
418/**\r
419 Searches for the next waiting AP.\r
420\r
421 Search for the next AP that is put in waiting state by single-threaded StartupAllAPs().\r
422\r
423 @param NextProcessorNumber Pointer to the processor number of the next waiting AP.\r
424\r
425 @retval EFI_SUCCESS The next waiting AP has been found.\r
426 @retval EFI_NOT_FOUND No waiting AP exists.\r
427\r
428**/\r
429EFI_STATUS\r
430GetNextWaitingProcessorNumber (\r
431 OUT UINTN *NextProcessorNumber\r
432 );\r
433\r
434/**\r
435 Wrapper function for all procedures assigned to AP.\r
436\r
437 Wrapper function for all procedures assigned to AP via MP service protocol.\r
438 It controls states of AP and invokes assigned precedure.\r
439\r
440**/\r
441VOID\r
442ApProcWrapper (\r
443 VOID\r
444 );\r
445\r
446/**\r
447 Function to wake up a specified AP and assign procedure to it.\r
448 \r
449 @param ProcessorNumber Handle number of the specified processor.\r
450 @param Procedure Procedure to assign.\r
451 @param ProcArguments Argument for Procedure.\r
452\r
453**/\r
454VOID\r
455WakeUpAp (\r
456 IN UINTN ProcessorNumber,\r
457 IN EFI_AP_PROCEDURE Procedure,\r
458 IN VOID *ProcArguments\r
459 );\r
460\r
461/**\r
462 Terminate AP's task and set it to idle state.\r
463 \r
464 This function terminates AP's task due to timeout by sending INIT-SIPI,\r
465 and sends it to idle state.\r
466\r
467 @param ProcessorNumber Handle number of the specified processor.\r
468\r
469**/\r
470VOID\r
471ResetProcessorToIdleState (\r
472 UINTN ProcessorNumber\r
473 );\r
474\r
475/**\r
476 Worker function of EnableDisableAP ()\r
477\r
478 Worker function of EnableDisableAP (). Changes state of specified processor.\r
479\r
480 @param ProcessorNumber Processor number of specified AP.\r
481 @param NewState Desired state of the specified AP.\r
482\r
483 @retval EFI_SUCCESS AP's state successfully changed.\r
484\r
485**/\r
486EFI_STATUS\r
487ChangeCpuState (\r
488 IN UINTN ProcessorNumber,\r
489 IN BOOLEAN NewState\r
490 );\r
491\r
492/**\r
493 Gets the processor number of BSP.\r
494 \r
495 @return The processor number of BSP.\r
496\r
497**/\r
498UINTN\r
499GetBspNumber (\r
500 VOID\r
501 );\r
502\r
503/**\r
504 Get address map of RendezvousFunnelProc.\r
505\r
506 This function gets address map of RendezvousFunnelProc.\r
507\r
508 @param AddressMap Output buffer for address map information\r
509\r
510**/\r
511VOID\r
512AsmGetAddressMap (\r
513 OUT MP_ASSEMBLY_ADDRESS_MAP *AddressMap\r
514 );\r
515\r
516#endif\r