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