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 VOID
*mCommonStack
= 0;
22 VOID
*mTopOfApCommonStack
= 0;
23 VOID
*mApStackStart
= 0;
25 volatile UINTN mNumberOfProcessors
;
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.
69 mNumberOfProcessors
++;
70 mApStackStart
= (UINT8
*)mApStackStart
+ gApStackSize
;
73 (SWITCH_STACK_ENTRY_POINT
)(UINTN
)ProcessorToIdleState
,
81 Initialize Multi-processor support.
89 gMaxLogicalProcessorNumber
= (UINTN
) PcdGet32 (PcdCpuMaxLogicalProcessorNumber
);
90 if (gMaxLogicalProcessorNumber
< 1) {
91 DEBUG ((DEBUG_ERROR
, "Setting PcdCpuMaxLogicalProcessorNumber should be more than zero.\n"));
95 if (gMaxLogicalProcessorNumber
== 1) {
99 gApStackSize
= (UINTN
) PcdGet32 (PcdCpuApStackSize
);
100 ASSERT ((gApStackSize
& (SIZE_4KB
- 1)) == 0);
102 mApStackStart
= AllocatePages (EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber
* gApStackSize
));
103 ASSERT (mApStackStart
!= NULL
);
106 // the first buffer of stack size used for common stack, when the amount of AP
107 // more than 1, we should never free the common stack which maybe used for AP reset.
109 mCommonStack
= mApStackStart
;
110 mTopOfApCommonStack
= (UINT8
*) mApStackStart
+ gApStackSize
;
111 mApStackStart
= mTopOfApCommonStack
;
113 mNumberOfProcessors
= 1;
115 if (mNumberOfProcessors
== 1) {
116 FreePages (mCommonStack
, EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber
* gApStackSize
));
120 if (mNumberOfProcessors
< gMaxLogicalProcessorNumber
) {
121 FreePages (mApStackStart
, EFI_SIZE_TO_PAGES ((gMaxLogicalProcessorNumber
- mNumberOfProcessors
) *