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 NULL
, // GetNumberOfProcessors,
29 NULL
, // GetProcessorInfo,
30 NULL
, // StartupAllAPs,
31 NULL
, // StartupThisAP,
33 NULL
, // EnableDisableAP,
38 Application Processors do loop routine
39 after switch to its own stack.
41 @param Context1 A pointer to the context to pass into the function.
42 @param Context2 A pointer to the context to pass into the function.
46 ProcessorToIdleState (
47 IN VOID
*Context1
, OPTIONAL
48 IN VOID
*Context2 OPTIONAL
51 DEBUG ((DEBUG_INFO
, "Ap apicid is %d\n", GetApicId ()));
53 AsmApDoneWithCommonStack ();
60 Application Processor C code entry point.
71 FillInProcessorInformation (FALSE
, mMpSystemData
.NumberOfProcessors
);
72 TopOfApStack
= (UINT8
*)mApStackStart
+ gApStackSize
;
73 mApStackStart
= TopOfApStack
;
75 mMpSystemData
.NumberOfProcessors
++;
78 (SWITCH_STACK_ENTRY_POINT
)(UINTN
)ProcessorToIdleState
,
85 This function is called by all processors (both BSP and AP) once and collects MP related data.
87 @param Bsp TRUE if the CPU is BSP
88 @param ProcessorNumber The specific processor number
90 @retval EFI_SUCCESS Data for the processor collected and filled in
94 FillInProcessorInformation (
96 IN UINTN ProcessorNumber
99 CPU_DATA_BLOCK
*CpuData
;
102 CpuData
= &mMpSystemData
.CpuDatas
[ProcessorNumber
];
103 ProcessorId
= GetApicId ();
104 CpuData
->Info
.ProcessorId
= ProcessorId
;
105 CpuData
->Info
.StatusFlag
= PROCESSOR_ENABLED_BIT
| PROCESSOR_HEALTH_STATUS_BIT
;
107 CpuData
->Info
.StatusFlag
|= PROCESSOR_AS_BSP_BIT
;
109 CpuData
->Info
.Location
.Package
= ProcessorId
;
110 CpuData
->Info
.Location
.Core
= 0;
111 CpuData
->Info
.Location
.Thread
= 0;
112 CpuData
->State
= Bsp
? CpuStateBuzy
: CpuStateIdle
;
114 CpuData
->Procedure
= NULL
;
115 CpuData
->Parameter
= NULL
;
116 InitializeSpinLock (&CpuData
->CpuDataLock
);
122 Prepare the System Data.
124 @retval EFI_SUCCESS the System Data finished initilization.
132 ZeroMem (&mMpSystemData
, sizeof (MP_SYSTEM_DATA
));
134 mMpSystemData
.NumberOfProcessors
= 1;
135 mMpSystemData
.NumberOfEnabledProcessors
= 1;
137 mMpSystemData
.CpuDatas
= AllocateZeroPool (sizeof (CPU_DATA_BLOCK
) * gMaxLogicalProcessorNumber
);
138 ASSERT(mMpSystemData
.CpuDatas
!= NULL
);
143 FillInProcessorInformation (TRUE
, 0);
149 Initialize Multi-processor support.
153 InitializeMpSupport (
157 gMaxLogicalProcessorNumber
= (UINTN
) PcdGet32 (PcdCpuMaxLogicalProcessorNumber
);
158 if (gMaxLogicalProcessorNumber
< 1) {
159 DEBUG ((DEBUG_ERROR
, "Setting PcdCpuMaxLogicalProcessorNumber should be more than zero.\n"));
163 if (gMaxLogicalProcessorNumber
== 1) {
167 gApStackSize
= (UINTN
) PcdGet32 (PcdCpuApStackSize
);
168 ASSERT ((gApStackSize
& (SIZE_4KB
- 1)) == 0);
170 mApStackStart
= AllocatePages (EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber
* gApStackSize
));
171 ASSERT (mApStackStart
!= NULL
);
174 // the first buffer of stack size used for common stack, when the amount of AP
175 // more than 1, we should never free the common stack which maybe used for AP reset.
177 mCommonStack
= mApStackStart
;
178 mTopOfApCommonStack
= (UINT8
*) mApStackStart
+ gApStackSize
;
179 mApStackStart
= mTopOfApCommonStack
;
183 if (mMpSystemData
.NumberOfProcessors
== 1) {
184 FreePages (mCommonStack
, EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber
* gApStackSize
));
188 if (mMpSystemData
.NumberOfProcessors
< gMaxLogicalProcessorNumber
) {
189 FreePages (mApStackStart
, EFI_SIZE_TO_PAGES (
190 (gMaxLogicalProcessorNumber
- mMpSystemData
.NumberOfProcessors
) *