2 Include file for PI MP Services Protocol Thunk.
4 Copyright (c) 2009 Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #ifndef _MP_SERVICES_ON_FRAMEWORK_MP_SERVICES_THUNK_
17 #define _MP_SERVICES_ON_FRAMEWORK_MP_SERVICES_THUNK_
19 #include <Protocol/MpService.h>
20 #include <Protocol/FrameworkMpService.h>
21 #include <Protocol/GenericMemoryTest.h>
23 #include <Library/BaseLib.h>
24 #include <Library/SynchronizationLib.h>
25 #include <Library/DebugLib.h>
26 #include <Library/UefiLib.h>
27 #include <Library/BaseMemoryLib.h>
28 #include <Library/UefiDriverEntryPoint.h>
29 #include <Library/MemoryAllocationLib.h>
30 #include <Library/UefiBootServicesTableLib.h>
31 #include <Library/DxeServicesTableLib.h>
32 #include <Library/IoLib.h>
33 #include <Library/TimerLib.h>
35 #define AP_STACK_SIZE 0x8000
36 #define MAX_CPU_NUMBER 256
39 // Bit definition for IPI
41 #define BROADCAST_MODE_ALL_EXCLUDING_SELF_BIT 0xC0000
42 #define SPECIFY_CPU_MODE_BIT 0x00000
43 #define TRIGGER_MODE_LEVEL_BIT 0x08000
44 #define ASSERT_BIT 0x04000
47 // Local APIC register definition for IPI.
49 #define APIC_REGISTER_ICR_LOW_OFFSET 0x300
50 #define APIC_REGISTER_ICR_HIGH_OFFSET 0x310
57 IA32_DESCRIPTOR GdtrProfile
;
60 } MP_CPU_EXCHANGE_INFO
;
63 UINT8
*RendezvousFunnelAddress
;
64 UINTN PModeEntryOffset
;
66 UINTN LModeEntryOffset
;
69 } MP_ASSEMBLY_ADDRESS_MAP
;
80 // Define Individual Processor Data block.
83 EFI_AP_PROCEDURE
volatile Procedure
;
84 VOID
* volatile Parameter
;
92 SPIN_LOCK CpuDataLock
;
93 CPU_STATE
volatile State
;
98 // Define MP data block which consumes individual processor block.
101 SPIN_LOCK APSerializeLock
;
103 EFI_EVENT CheckAPsEvent
;
108 BOOLEAN CpuList
[MAX_CPU_NUMBER
];
110 EFI_AP_PROCEDURE Procedure
;
112 BOOLEAN SingleThread
;
114 UINTN
**FailedCpuList
;
119 CPU_DATA_BLOCK CpuData
[MAX_CPU_NUMBER
];
123 Implementation of GetNumberOfProcessors() service of MP Services Protocol.
125 This service retrieves the number of logical processor in the platform
126 and the number of those logical processors that are enabled on this boot.
127 This service may only be called from the BSP.
129 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
130 @param NumberOfProcessors Pointer to the total number of logical processors in the system,
131 including the BSP and disabled APs.
132 @param NumberOfEnabledProcessors Pointer to the number of enabled logical processors that exist
133 in system, including the BSP.
135 @retval EFI_SUCCESS Number of logical processors and enabled logical processors retrieved..
136 @retval EFI_DEVICE_ERROR Caller processor is AP.
137 @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL
138 @retval EFI_INVALID_PARAMETER NumberOfEnabledProcessors is NULL
143 GetNumberOfProcessors (
144 IN EFI_MP_SERVICES_PROTOCOL
*This
,
145 OUT UINTN
*NumberOfProcessors
,
146 OUT UINTN
*NumberOfEnabledProcessors
150 Implementation of GetNumberOfProcessors() service of MP Services Protocol.
152 Gets detailed MP-related information on the requested processor at the
153 instant this call is made. This service may only be called from the BSP.
155 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
156 @param ProcessorNumber The handle number of processor.
157 @param ProcessorInfoBuffer A pointer to the buffer where information for the requested processor is deposited.
159 @retval EFI_SUCCESS Processor information successfully returned.
160 @retval EFI_DEVICE_ERROR Caller processor is AP.
161 @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL
162 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber does not exist.
168 IN EFI_MP_SERVICES_PROTOCOL
*This
,
169 IN UINTN ProcessorNumber
,
170 OUT EFI_PROCESSOR_INFORMATION
*ProcessorInfoBuffer
174 Implementation of StartupAllAPs() service of MP Services Protocol.
176 This service lets the caller get all enabled APs to execute a caller-provided function.
177 This service may only be called from the BSP.
179 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
180 @param Procedure A pointer to the function to be run on enabled APs of the system.
181 @param SingleThread Indicates whether to execute the function simultaneously or one by one..
182 @param WaitEvent The event created by the caller.
183 If it is NULL, then execute in blocking mode.
184 If it is not NULL, then execute in non-blocking mode.
185 @param TimeoutInMicroSeconds The time limit in microseconds for this AP to finish the function.
187 @param ProcedureArgument Pointer to the optional parameter of the assigned function.
188 @param FailedCpuList The list of processor numbers that fail to finish the function before
189 TimeoutInMicrosecsond expires.
191 @retval EFI_SUCCESS In blocking mode, all APs have finished before the timeout expired.
192 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched to all enabled APs.
193 @retval EFI_DEVICE_ERROR Caller processor is AP.
194 @retval EFI_NOT_STARTED No enabled AP exists in the system.
195 @retval EFI_NOT_READY Any enabled AP is busy.
196 @retval EFI_TIMEOUT In blocking mode, The timeout expired before all enabled APs have finished.
197 @retval EFI_INVALID_PARAMETER Procedure is NULL.
203 IN EFI_MP_SERVICES_PROTOCOL
*This
,
204 IN EFI_AP_PROCEDURE Procedure
,
205 IN BOOLEAN SingleThread
,
206 IN EFI_EVENT WaitEvent OPTIONAL
,
207 IN UINTN TimeoutInMicroSeconds
,
208 IN VOID
*ProcedureArgument OPTIONAL
,
209 OUT UINTN
**FailedCpuList OPTIONAL
213 Implementation of StartupThisAP() service of MP Services Protocol.
215 This service lets the caller get one enabled AP to execute a caller-provided function.
216 This service may only be called from the BSP.
218 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
219 @param Procedure A pointer to the function to be run on the designated AP.
220 @param ProcessorNumber The handle number of AP..
221 @param WaitEvent The event created by the caller.
222 If it is NULL, then execute in blocking mode.
223 If it is not NULL, then execute in non-blocking mode.
224 @param TimeoutInMicroseconds The time limit in microseconds for this AP to finish the function.
226 @param ProcedureArgument Pointer to the optional parameter of the assigned function.
227 @param Finished Indicates whether AP has finished assigned function.
228 In blocking mode, it is ignored.
230 @retval EFI_SUCCESS In blocking mode, specified AP has finished before the timeout expires.
231 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched to specified AP.
232 @retval EFI_DEVICE_ERROR Caller processor is AP.
233 @retval EFI_TIMEOUT In blocking mode, the timeout expires before specified AP has finished.
234 @retval EFI_NOT_READY Specified AP is busy.
235 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber does not exist.
236 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
237 @retval EFI_INVALID_PARAMETER Procedure is NULL.
243 IN EFI_MP_SERVICES_PROTOCOL
*This
,
244 IN EFI_AP_PROCEDURE Procedure
,
245 IN UINTN ProcessorNumber
,
246 IN EFI_EVENT WaitEvent OPTIONAL
,
247 IN UINTN TimeoutInMicroseconds
,
248 IN VOID
*ProcedureArgument OPTIONAL
,
249 OUT BOOLEAN
*Finished OPTIONAL
253 Implementation of SwitchBSP() service of MP Services Protocol.
255 This service switches the requested AP to be the BSP from that point onward.
256 This service may only be called from the current BSP.
258 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
259 @param ProcessorNumber The handle number of processor.
260 @param EnableOldBSP Whether to enable or disable the original BSP.
262 @retval EFI_SUCCESS BSP successfully switched.
263 @retval EFI_DEVICE_ERROR Caller processor is AP.
264 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber does not exist.
265 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
266 @retval EFI_NOT_READY Specified AP is busy.
272 IN EFI_MP_SERVICES_PROTOCOL
*This
,
273 IN UINTN ProcessorNumber
,
274 IN BOOLEAN EnableOldBSP
278 Implementation of EnableDisableAP() service of MP Services Protocol.
280 This service lets the caller enable or disable an AP.
281 This service may only be called from the BSP.
283 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
284 @param ProcessorNumber The handle number of processor.
285 @param EnableAP Indicates whether the newstate of the AP is enabled or disabled.
286 @param HealthFlag Indicates new health state of the AP..
288 @retval EFI_SUCCESS AP successfully enabled or disabled.
289 @retval EFI_DEVICE_ERROR Caller processor is AP.
290 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber does not exist.
291 @retval EFI_INVALID_PARAMETERS ProcessorNumber specifies the BSP.
297 IN EFI_MP_SERVICES_PROTOCOL
*This
,
298 IN UINTN ProcessorNumber
,
300 IN UINT32
*HealthFlag OPTIONAL
304 Implementation of WhoAmI() service of MP Services Protocol.
306 This service lets the caller processor get its handle number.
307 This service may be called from the BSP and APs.
309 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
310 @param ProcessorNumber Pointer to the handle number of AP.
312 @retval EFI_SUCCESS Processor number successfully returned.
313 @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL
319 IN EFI_MP_SERVICES_PROTOCOL
*This
,
320 OUT UINTN
*ProcessorNumber
324 Checks APs' status periodically.
326 This function is triggerred by timer perodically to check the
327 state of APs for StartupAllAPs() and StartupThisAP() executed
328 in non-blocking mode.
330 @param Event Event triggered.
331 @param Context Parameter passed with the event.
342 Checks status of all APs.
344 This function checks whether all APs have finished task assigned by StartupAllAPs(),
345 and whether timeout expires.
347 @retval EFI_SUCCESS All APs have finished task assigned by StartupAllAPs().
348 @retval EFI_TIMEOUT The timeout expires.
349 @retval EFI_NOT_READY APs have not finished task and timeout has not expired.
358 Checks status of specified AP.
360 This function checks whether specified AP has finished task assigned by StartupThisAP(),
361 and whether timeout expires.
363 @param ProcessorNumber The handle number of processor.
365 @retval EFI_SUCCESS Specified AP has finished task assigned by StartupThisAPs().
366 @retval EFI_TIMEOUT The timeout expires.
367 @retval EFI_NOT_READY Specified AP has not finished task and timeout has not expired.
372 UINTN ProcessorNumber
376 Calculate timeout value and return the current performance counter value.
378 Calculate the number of performance counter ticks required for a timeout.
379 If TimeoutInMicroseconds is 0, return value is also 0, which is recognized
382 @param TimeoutInMicroseconds Timeout value in microseconds.
383 @param CurrentTime Returns the current value of the performance counter.
385 @return Expected timestamp counter for timeout.
386 If TimeoutInMicroseconds is 0, return value is also 0, which is recognized
392 IN UINTN TimeoutInMicroseconds
,
393 OUT UINT64
*CurrentTime
397 Checks whether timeout expires.
399 Check whether the number of ellapsed performance counter ticks required for a timeout condition
400 has been reached. If Timeout is zero, which means infinity, return value is always FALSE.
402 @param PreviousTime On input, the value of the performance counter when it was last read.
403 On output, the current value of the performance counter
404 @param TotalTime The total amount of ellapsed time in performance counter ticks.
405 @param Timeout The number of performance counter ticks required to reach a timeout condition.
407 @retval TRUE A timeout condition has been reached.
408 @retval FALSE A timeout condition has not been reached.
413 IN OUT UINT64
*PreviousTime
,
414 IN UINT64
*TotalTime
,
419 Searches for the next waiting AP.
421 Search for the next AP that is put in waiting state by single-threaded StartupAllAPs().
423 @param NextProcessorNumber Pointer to the processor number of the next waiting AP.
425 @retval EFI_SUCCESS The next waiting AP has been found.
426 @retval EFI_NOT_FOUND No waiting AP exists.
430 GetNextWaitingProcessorNumber (
431 OUT UINTN
*NextProcessorNumber
435 Wrapper function for all procedures assigned to AP.
437 Wrapper function for all procedures assigned to AP via MP service protocol.
438 It controls states of AP and invokes assigned precedure.
447 Function to wake up a specified AP and assign procedure to it.
449 @param ProcessorNumber Handle number of the specified processor.
450 @param Procedure Procedure to assign.
451 @param ProcArguments Argument for Procedure.
456 IN UINTN ProcessorNumber
,
457 IN EFI_AP_PROCEDURE Procedure
,
458 IN VOID
*ProcArguments
462 Terminate AP's task and set it to idle state.
464 This function terminates AP's task due to timeout by sending INIT-SIPI,
465 and sends it to idle state.
467 @param ProcessorNumber Handle number of the specified processor.
471 ResetProcessorToIdleState (
472 UINTN ProcessorNumber
476 Worker function of EnableDisableAP ()
478 Worker function of EnableDisableAP (). Changes state of specified processor.
480 @param ProcessorNumber Processor number of specified AP.
481 @param NewState Desired state of the specified AP.
483 @retval EFI_SUCCESS AP's state successfully changed.
488 IN UINTN ProcessorNumber
,
493 Gets the processor number of BSP.
495 @return The processor number of BSP.
504 Get address map of RendezvousFunnelProc.
506 This function gets address map of RendezvousFunnelProc.
508 @param AddressMap Output buffer for address map information
513 OUT MP_ASSEMBLY_ADDRESS_MAP
*AddressMap