2 Include file for PI MP Services Protocol Thunk.
4 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
5 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>
34 #include <Library/DebugAgentLib.h>
36 #define AP_STACK_SIZE 0x8000
37 #define MAX_CPU_NUMBER 256
40 // Bit definition for IPI
42 #define BROADCAST_MODE_ALL_EXCLUDING_SELF_BIT 0xC0000
43 #define SPECIFY_CPU_MODE_BIT 0x00000
44 #define TRIGGER_MODE_LEVEL_BIT 0x08000
45 #define ASSERT_BIT 0x04000
48 // Local APIC register definition for IPI.
50 #define APIC_REGISTER_SPURIOUS_VECTOR_OFFSET 0xF0
51 #define APIC_REGISTER_ICR_LOW_OFFSET 0x300
52 #define APIC_REGISTER_ICR_HIGH_OFFSET 0x310
53 #define APIC_REGISTER_LVT_TIMER 0x320
54 #define APIC_REGISTER_TIMER_INIT_COUNT 0x380
55 #define APIC_REGISTER_LINT0_VECTOR_OFFSET 0x350
56 #define APIC_REGISTER_LINT1_VECTOR_OFFSET 0x360
57 #define APIC_REGISTER_TIMER_COUNT 0x390
58 #define APIC_REGISTER_TIMER_DIVIDE 0x3E0
61 // Definition for MSR address
63 #define MSR_IA32_TIME_STAMP_COUNTER 0x10
64 #define MSR_IA32_APIC_BASE 0x1B
71 IA32_DESCRIPTOR GdtrProfile
;
72 IA32_DESCRIPTOR IdtrProfile
;
75 UINT32 ProcessorNumber
[MAX_CPU_NUMBER
];
76 } MP_CPU_EXCHANGE_INFO
;
79 UINT8
*RendezvousFunnelAddress
;
80 UINTN PModeEntryOffset
;
82 UINTN LModeEntryOffset
;
85 } MP_ASSEMBLY_ADDRESS_MAP
;
96 // Define Individual Processor Data block.
99 EFI_AP_PROCEDURE
volatile Procedure
;
100 VOID
* volatile Parameter
;
108 SPIN_LOCK CpuDataLock
;
109 CPU_STATE
volatile State
;
114 // Define MP data block which consumes individual processor block.
117 SPIN_LOCK APSerializeLock
;
119 EFI_EVENT CheckAPsEvent
;
124 BOOLEAN CpuList
[MAX_CPU_NUMBER
];
126 EFI_AP_PROCEDURE Procedure
;
128 BOOLEAN SingleThread
;
130 UINTN
**FailedCpuList
;
135 CPU_DATA_BLOCK CpuData
[MAX_CPU_NUMBER
];
139 Implementation of GetNumberOfProcessors() service of MP Services Protocol.
141 This service retrieves the number of logical processor in the platform
142 and the number of those logical processors that are enabled on this boot.
143 This service may only be called from the BSP.
145 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
146 @param NumberOfProcessors Pointer to the total number of logical processors in the system,
147 including the BSP and disabled APs.
148 @param NumberOfEnabledProcessors Pointer to the number of enabled logical processors that exist
149 in system, including the BSP.
151 @retval EFI_SUCCESS Number of logical processors and enabled logical processors retrieved..
152 @retval EFI_DEVICE_ERROR Caller processor is AP.
153 @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL
154 @retval EFI_INVALID_PARAMETER NumberOfEnabledProcessors is NULL
159 GetNumberOfProcessors (
160 IN EFI_MP_SERVICES_PROTOCOL
*This
,
161 OUT UINTN
*NumberOfProcessors
,
162 OUT UINTN
*NumberOfEnabledProcessors
166 Implementation of GetNumberOfProcessors() service of MP Services Protocol.
168 Gets detailed MP-related information on the requested processor at the
169 instant this call is made. This service may only be called from the BSP.
171 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
172 @param ProcessorNumber The handle number of processor.
173 @param ProcessorInfoBuffer A pointer to the buffer where information for the requested processor is deposited.
175 @retval EFI_SUCCESS Processor information successfully returned.
176 @retval EFI_DEVICE_ERROR Caller processor is AP.
177 @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL
178 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber does not exist.
184 IN EFI_MP_SERVICES_PROTOCOL
*This
,
185 IN UINTN ProcessorNumber
,
186 OUT EFI_PROCESSOR_INFORMATION
*ProcessorInfoBuffer
190 Implementation of StartupAllAPs() service of MP Services Protocol.
192 This service lets the caller get all enabled APs to execute a caller-provided function.
193 This service may only be called from the BSP.
195 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
196 @param Procedure A pointer to the function to be run on enabled APs of the system.
197 @param SingleThread Indicates whether to execute the function simultaneously or one by one..
198 @param WaitEvent The event created by the caller.
199 If it is NULL, then execute in blocking mode.
200 If it is not NULL, then execute in non-blocking mode.
201 @param TimeoutInMicroSeconds The time limit in microseconds for this AP to finish the function.
203 @param ProcedureArgument Pointer to the optional parameter of the assigned function.
204 @param FailedCpuList The list of processor numbers that fail to finish the function before
205 TimeoutInMicrosecsond expires.
207 @retval EFI_SUCCESS In blocking mode, all APs have finished before the timeout expired.
208 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched to all enabled APs.
209 @retval EFI_DEVICE_ERROR Caller processor is AP.
210 @retval EFI_NOT_STARTED No enabled AP exists in the system.
211 @retval EFI_NOT_READY Any enabled AP is busy.
212 @retval EFI_TIMEOUT In blocking mode, The timeout expired before all enabled APs have finished.
213 @retval EFI_INVALID_PARAMETER Procedure is NULL.
219 IN EFI_MP_SERVICES_PROTOCOL
*This
,
220 IN EFI_AP_PROCEDURE Procedure
,
221 IN BOOLEAN SingleThread
,
222 IN EFI_EVENT WaitEvent OPTIONAL
,
223 IN UINTN TimeoutInMicroSeconds
,
224 IN VOID
*ProcedureArgument OPTIONAL
,
225 OUT UINTN
**FailedCpuList OPTIONAL
229 Implementation of StartupThisAP() service of MP Services Protocol.
231 This service lets the caller get one enabled AP to execute a caller-provided function.
232 This service may only be called from the BSP.
234 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
235 @param Procedure A pointer to the function to be run on the designated AP.
236 @param ProcessorNumber The handle number of AP..
237 @param WaitEvent The event created by the caller.
238 If it is NULL, then execute in blocking mode.
239 If it is not NULL, then execute in non-blocking mode.
240 @param TimeoutInMicroseconds The time limit in microseconds for this AP to finish the function.
242 @param ProcedureArgument Pointer to the optional parameter of the assigned function.
243 @param Finished Indicates whether AP has finished assigned function.
244 In blocking mode, it is ignored.
246 @retval EFI_SUCCESS In blocking mode, specified AP has finished before the timeout expires.
247 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched to specified AP.
248 @retval EFI_DEVICE_ERROR Caller processor is AP.
249 @retval EFI_TIMEOUT In blocking mode, the timeout expires before specified AP has finished.
250 @retval EFI_NOT_READY Specified AP is busy.
251 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber does not exist.
252 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
253 @retval EFI_INVALID_PARAMETER Procedure is NULL.
259 IN EFI_MP_SERVICES_PROTOCOL
*This
,
260 IN EFI_AP_PROCEDURE Procedure
,
261 IN UINTN ProcessorNumber
,
262 IN EFI_EVENT WaitEvent OPTIONAL
,
263 IN UINTN TimeoutInMicroseconds
,
264 IN VOID
*ProcedureArgument OPTIONAL
,
265 OUT BOOLEAN
*Finished OPTIONAL
269 Implementation of SwitchBSP() service of MP Services Protocol.
271 This service switches the requested AP to be the BSP from that point onward.
272 This service may only be called from the current BSP.
274 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
275 @param ProcessorNumber The handle number of processor.
276 @param EnableOldBSP Whether to enable or disable the original BSP.
278 @retval EFI_SUCCESS BSP successfully switched.
279 @retval EFI_DEVICE_ERROR Caller processor is AP.
280 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber does not exist.
281 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
282 @retval EFI_NOT_READY Specified AP is busy.
288 IN EFI_MP_SERVICES_PROTOCOL
*This
,
289 IN UINTN ProcessorNumber
,
290 IN BOOLEAN EnableOldBSP
294 Implementation of EnableDisableAP() service of MP Services Protocol.
296 This service lets the caller enable or disable an AP.
297 This service may only be called from the BSP.
299 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
300 @param ProcessorNumber The handle number of processor.
301 @param EnableAP Indicates whether the newstate of the AP is enabled or disabled.
302 @param HealthFlag Indicates new health state of the AP..
304 @retval EFI_SUCCESS AP successfully enabled or disabled.
305 @retval EFI_DEVICE_ERROR Caller processor is AP.
306 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber does not exist.
307 @retval EFI_INVALID_PARAMETERS ProcessorNumber specifies the BSP.
313 IN EFI_MP_SERVICES_PROTOCOL
*This
,
314 IN UINTN ProcessorNumber
,
316 IN UINT32
*HealthFlag OPTIONAL
320 Implementation of WhoAmI() service of MP Services Protocol.
322 This service lets the caller processor get its handle number.
323 This service may be called from the BSP and APs.
325 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
326 @param ProcessorNumber Pointer to the handle number of AP.
328 @retval EFI_SUCCESS Processor number successfully returned.
329 @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL
335 IN EFI_MP_SERVICES_PROTOCOL
*This
,
336 OUT UINTN
*ProcessorNumber
340 Checks APs' status periodically.
342 This function is triggerred by timer perodically to check the
343 state of APs for StartupAllAPs() and StartupThisAP() executed
344 in non-blocking mode.
346 @param Event Event triggered.
347 @param Context Parameter passed with the event.
358 Checks status of all APs.
360 This function checks whether all APs have finished task assigned by StartupAllAPs(),
361 and whether timeout expires.
363 @retval EFI_SUCCESS All APs have finished task assigned by StartupAllAPs().
364 @retval EFI_TIMEOUT The timeout expires.
365 @retval EFI_NOT_READY APs have not finished task and timeout has not expired.
374 Checks status of specified AP.
376 This function checks whether specified AP has finished task assigned by StartupThisAP(),
377 and whether timeout expires.
379 @param ProcessorNumber The handle number of processor.
381 @retval EFI_SUCCESS Specified AP has finished task assigned by StartupThisAPs().
382 @retval EFI_TIMEOUT The timeout expires.
383 @retval EFI_NOT_READY Specified AP has not finished task and timeout has not expired.
388 UINTN ProcessorNumber
392 Calculate timeout value and return the current performance counter value.
394 Calculate the number of performance counter ticks required for a timeout.
395 If TimeoutInMicroseconds is 0, return value is also 0, which is recognized
398 @param TimeoutInMicroseconds Timeout value in microseconds.
399 @param CurrentTime Returns the current value of the performance counter.
401 @return Expected timestamp counter for timeout.
402 If TimeoutInMicroseconds is 0, return value is also 0, which is recognized
408 IN UINTN TimeoutInMicroseconds
,
409 OUT UINT64
*CurrentTime
413 Checks whether timeout expires.
415 Check whether the number of ellapsed performance counter ticks required for a timeout condition
416 has been reached. If Timeout is zero, which means infinity, return value is always FALSE.
418 @param PreviousTime On input, the value of the performance counter when it was last read.
419 On output, the current value of the performance counter
420 @param TotalTime The total amount of ellapsed time in performance counter ticks.
421 @param Timeout The number of performance counter ticks required to reach a timeout condition.
423 @retval TRUE A timeout condition has been reached.
424 @retval FALSE A timeout condition has not been reached.
429 IN OUT UINT64
*PreviousTime
,
430 IN UINT64
*TotalTime
,
435 Searches for the next waiting AP.
437 Search for the next AP that is put in waiting state by single-threaded StartupAllAPs().
439 @param NextProcessorNumber Pointer to the processor number of the next waiting AP.
441 @retval EFI_SUCCESS The next waiting AP has been found.
442 @retval EFI_NOT_FOUND No waiting AP exists.
446 GetNextWaitingProcessorNumber (
447 OUT UINTN
*NextProcessorNumber
451 Wrapper function for all procedures assigned to AP.
453 Wrapper function for all procedures assigned to AP via MP service protocol.
454 It controls states of AP and invokes assigned precedure.
463 Function to wake up a specified AP and assign procedure to it.
465 @param ProcessorNumber Handle number of the specified processor.
466 @param Procedure Procedure to assign.
467 @param ProcArguments Argument for Procedure.
472 IN UINTN ProcessorNumber
,
473 IN EFI_AP_PROCEDURE Procedure
,
474 IN VOID
*ProcArguments
478 Terminate AP's task and set it to idle state.
480 This function terminates AP's task due to timeout by sending INIT-SIPI,
481 and sends it to idle state.
483 @param ProcessorNumber Handle number of the specified processor.
487 ResetProcessorToIdleState (
488 UINTN ProcessorNumber
492 Worker function of EnableDisableAP ()
494 Worker function of EnableDisableAP (). Changes state of specified processor.
496 @param ProcessorNumber Processor number of specified AP.
497 @param NewState Desired state of the specified AP.
499 @retval EFI_SUCCESS AP's state successfully changed.
504 IN UINTN ProcessorNumber
,
509 Gets the processor number of BSP.
511 @return The processor number of BSP.
520 Get address map of RendezvousFunnelProc.
522 This function gets address map of RendezvousFunnelProc.
524 @param AddressMap Output buffer for address map information
529 OUT MP_ASSEMBLY_ADDRESS_MAP
*AddressMap