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