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