4 Copyright (c) 2008 - 2014, 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.
18 UINTN gMaxLogicalProcessorNumber
;
21 MP_SYSTEM_DATA mMpSystemData
;
23 VOID
*mCommonStack
= 0;
24 VOID
*mTopOfApCommonStack
= 0;
25 VOID
*mApStackStart
= 0;
27 EFI_MP_SERVICES_PROTOCOL mMpServicesTemplate
= {
28 GetNumberOfProcessors
,
30 NULL
, // StartupAllAPs,
31 NULL
, // StartupThisAP,
33 NULL
, // EnableDisableAP,
38 Check whether caller processor is BSP.
40 @retval TRUE the caller is BSP
41 @retval FALSE the caller is AP
50 CPU_DATA_BLOCK
*CpuData
;
54 WhoAmI (&mMpServicesTemplate
, &CpuIndex
);
55 CpuData
= &mMpSystemData
.CpuDatas
[CpuIndex
];
57 return CpuData
->Info
.StatusFlag
& PROCESSOR_AS_BSP_BIT
? TRUE
: FALSE
;
61 This service retrieves the number of logical processor in the platform
62 and the number of those logical processors that are enabled on this boot.
63 This service may only be called from the BSP.
65 This function is used to retrieve the following information:
66 - The number of logical processors that are present in the system.
67 - The number of enabled logical processors in the system at the instant
70 Because MP Service Protocol provides services to enable and disable processors
71 dynamically, the number of enabled logical processors may vary during the
72 course of a boot session.
74 If this service is called from an AP, then EFI_DEVICE_ERROR is returned.
75 If NumberOfProcessors or NumberOfEnabledProcessors is NULL, then
76 EFI_INVALID_PARAMETER is returned. Otherwise, the total number of processors
77 is returned in NumberOfProcessors, the number of currently enabled processor
78 is returned in NumberOfEnabledProcessors, and EFI_SUCCESS is returned.
80 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL
82 @param[out] NumberOfProcessors Pointer to the total number of logical
83 processors in the system, including the BSP
85 @param[out] NumberOfEnabledProcessors Pointer to the number of enabled logical
86 processors that exist in system, including
89 @retval EFI_SUCCESS The number of logical processors and enabled
90 logical processors was retrieved.
91 @retval EFI_DEVICE_ERROR The calling processor is an AP.
92 @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL.
93 @retval EFI_INVALID_PARAMETER NumberOfEnabledProcessors is NULL.
98 GetNumberOfProcessors (
99 IN EFI_MP_SERVICES_PROTOCOL
*This
,
100 OUT UINTN
*NumberOfProcessors
,
101 OUT UINTN
*NumberOfEnabledProcessors
104 if ((NumberOfProcessors
== NULL
) || (NumberOfEnabledProcessors
== NULL
)) {
105 return EFI_INVALID_PARAMETER
;
109 return EFI_DEVICE_ERROR
;
112 *NumberOfProcessors
= mMpSystemData
.NumberOfProcessors
;
113 *NumberOfEnabledProcessors
= mMpSystemData
.NumberOfEnabledProcessors
;
118 Gets detailed MP-related information on the requested processor at the
119 instant this call is made. This service may only be called from the BSP.
121 This service retrieves detailed MP-related information about any processor
122 on the platform. Note the following:
123 - The processor information may change during the course of a boot session.
124 - The information presented here is entirely MP related.
126 Information regarding the number of caches and their sizes, frequency of operation,
127 slot numbers is all considered platform-related information and is not provided
130 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL
132 @param[in] ProcessorNumber The handle number of processor.
133 @param[out] ProcessorInfoBuffer A pointer to the buffer where information for
134 the requested processor is deposited.
136 @retval EFI_SUCCESS Processor information was returned.
137 @retval EFI_DEVICE_ERROR The calling processor is an AP.
138 @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL.
139 @retval EFI_NOT_FOUND The processor with the handle specified by
140 ProcessorNumber does not exist in the platform.
146 IN EFI_MP_SERVICES_PROTOCOL
*This
,
147 IN UINTN ProcessorNumber
,
148 OUT EFI_PROCESSOR_INFORMATION
*ProcessorInfoBuffer
151 if (ProcessorInfoBuffer
== NULL
) {
152 return EFI_INVALID_PARAMETER
;
156 return EFI_DEVICE_ERROR
;
159 if (ProcessorNumber
>= mMpSystemData
.NumberOfProcessors
) {
160 return EFI_NOT_FOUND
;
163 CopyMem (ProcessorInfoBuffer
, &mMpSystemData
.CpuDatas
[ProcessorNumber
], sizeof (EFI_PROCESSOR_INFORMATION
));
168 This return the handle number for the calling processor. This service may be
169 called from the BSP and APs.
171 This service returns the processor handle number for the calling processor.
172 The returned value is in the range from 0 to the total number of logical
173 processors minus 1. The total number of logical processors can be retrieved
174 with EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors(). This service may be
175 called from the BSP and APs. If ProcessorNumber is NULL, then EFI_INVALID_PARAMETER
176 is returned. Otherwise, the current processors handle number is returned in
177 ProcessorNumber, and EFI_SUCCESS is returned.
179 @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
180 @param[out] ProcessorNumber The handle number of AP that is to become the new
181 BSP. The range is from 0 to the total number of
182 logical processors minus 1. The total number of
183 logical processors can be retrieved by
184 EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
186 @retval EFI_SUCCESS The current processor handle number was returned
188 @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL.
194 IN EFI_MP_SERVICES_PROTOCOL
*This
,
195 OUT UINTN
*ProcessorNumber
201 if (ProcessorNumber
== NULL
) {
202 return EFI_INVALID_PARAMETER
;
205 ProcessorId
= GetApicId ();
206 for (Index
= 0; Index
< mMpSystemData
.NumberOfProcessors
; Index
++) {
207 if (mMpSystemData
.CpuDatas
[Index
].Info
.ProcessorId
== ProcessorId
) {
212 *ProcessorNumber
= Index
;
217 Application Processors do loop routine
218 after switch to its own stack.
220 @param Context1 A pointer to the context to pass into the function.
221 @param Context2 A pointer to the context to pass into the function.
225 ProcessorToIdleState (
226 IN VOID
*Context1
, OPTIONAL
227 IN VOID
*Context2 OPTIONAL
230 DEBUG ((DEBUG_INFO
, "Ap apicid is %d\n", GetApicId ()));
232 AsmApDoneWithCommonStack ();
239 Application Processor C code entry point.
250 FillInProcessorInformation (FALSE
, mMpSystemData
.NumberOfProcessors
);
251 TopOfApStack
= (UINT8
*)mApStackStart
+ gApStackSize
;
252 mApStackStart
= TopOfApStack
;
254 mMpSystemData
.NumberOfProcessors
++;
257 (SWITCH_STACK_ENTRY_POINT
)(UINTN
)ProcessorToIdleState
,
264 This function is called by all processors (both BSP and AP) once and collects MP related data.
266 @param Bsp TRUE if the CPU is BSP
267 @param ProcessorNumber The specific processor number
269 @retval EFI_SUCCESS Data for the processor collected and filled in
273 FillInProcessorInformation (
275 IN UINTN ProcessorNumber
278 CPU_DATA_BLOCK
*CpuData
;
281 CpuData
= &mMpSystemData
.CpuDatas
[ProcessorNumber
];
282 ProcessorId
= GetApicId ();
283 CpuData
->Info
.ProcessorId
= ProcessorId
;
284 CpuData
->Info
.StatusFlag
= PROCESSOR_ENABLED_BIT
| PROCESSOR_HEALTH_STATUS_BIT
;
286 CpuData
->Info
.StatusFlag
|= PROCESSOR_AS_BSP_BIT
;
288 CpuData
->Info
.Location
.Package
= ProcessorId
;
289 CpuData
->Info
.Location
.Core
= 0;
290 CpuData
->Info
.Location
.Thread
= 0;
291 CpuData
->State
= Bsp
? CpuStateBuzy
: CpuStateIdle
;
293 CpuData
->Procedure
= NULL
;
294 CpuData
->Parameter
= NULL
;
295 InitializeSpinLock (&CpuData
->CpuDataLock
);
301 Prepare the System Data.
303 @retval EFI_SUCCESS the System Data finished initilization.
311 ZeroMem (&mMpSystemData
, sizeof (MP_SYSTEM_DATA
));
313 mMpSystemData
.NumberOfProcessors
= 1;
314 mMpSystemData
.NumberOfEnabledProcessors
= 1;
316 mMpSystemData
.CpuDatas
= AllocateZeroPool (sizeof (CPU_DATA_BLOCK
) * gMaxLogicalProcessorNumber
);
317 ASSERT(mMpSystemData
.CpuDatas
!= NULL
);
322 FillInProcessorInformation (TRUE
, 0);
328 Initialize Multi-processor support.
332 InitializeMpSupport (
336 gMaxLogicalProcessorNumber
= (UINTN
) PcdGet32 (PcdCpuMaxLogicalProcessorNumber
);
337 if (gMaxLogicalProcessorNumber
< 1) {
338 DEBUG ((DEBUG_ERROR
, "Setting PcdCpuMaxLogicalProcessorNumber should be more than zero.\n"));
342 if (gMaxLogicalProcessorNumber
== 1) {
346 gApStackSize
= (UINTN
) PcdGet32 (PcdCpuApStackSize
);
347 ASSERT ((gApStackSize
& (SIZE_4KB
- 1)) == 0);
349 mApStackStart
= AllocatePages (EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber
* gApStackSize
));
350 ASSERT (mApStackStart
!= NULL
);
353 // the first buffer of stack size used for common stack, when the amount of AP
354 // more than 1, we should never free the common stack which maybe used for AP reset.
356 mCommonStack
= mApStackStart
;
357 mTopOfApCommonStack
= (UINT8
*) mApStackStart
+ gApStackSize
;
358 mApStackStart
= mTopOfApCommonStack
;
362 if (mMpSystemData
.NumberOfProcessors
== 1) {
363 FreePages (mCommonStack
, EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber
* gApStackSize
));
367 if (mMpSystemData
.NumberOfProcessors
< gMaxLogicalProcessorNumber
) {
368 FreePages (mApStackStart
, EFI_SIZE_TO_PAGES (
369 (gMaxLogicalProcessorNumber
- mMpSystemData
.NumberOfProcessors
) *