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
;
28 Application Processors do loop routine
29 after switch to its own stack.
31 @param Context1 A pointer to the context to pass into the function.
32 @param Context2 A pointer to the context to pass into the function.
36 ProcessorToIdleState (
37 IN VOID
*Context1
, OPTIONAL
38 IN VOID
*Context2 OPTIONAL
41 DEBUG ((DEBUG_INFO
, "Ap apicid is %d\n", GetApicId ()));
43 AsmApDoneWithCommonStack ();
50 Application Processor C code entry point.
59 mNumberOfProcessors
++;
60 mApStackStart
= (UINT8
*)mApStackStart
+ gApStackSize
;
63 (SWITCH_STACK_ENTRY_POINT
)(UINTN
)ProcessorToIdleState
,
71 Initialize Multi-processor support.
79 gMaxLogicalProcessorNumber
= (UINTN
) PcdGet32 (PcdCpuMaxLogicalProcessorNumber
);
80 if (gMaxLogicalProcessorNumber
< 1) {
81 DEBUG ((DEBUG_ERROR
, "Setting PcdCpuMaxLogicalProcessorNumber should be more than zero.\n"));
85 if (gMaxLogicalProcessorNumber
== 1) {
89 gApStackSize
= (UINTN
) PcdGet32 (PcdCpuApStackSize
);
90 ASSERT ((gApStackSize
& (SIZE_4KB
- 1)) == 0);
92 mApStackStart
= AllocatePages (EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber
* gApStackSize
));
93 ASSERT (mApStackStart
!= NULL
);
96 // the first buffer of stack size used for common stack, when the amount of AP
97 // more than 1, we should never free the common stack which maybe used for AP reset.
99 mCommonStack
= mApStackStart
;
100 mTopOfApCommonStack
= (UINT8
*) mApStackStart
+ gApStackSize
;
101 mApStackStart
= mTopOfApCommonStack
;
103 mNumberOfProcessors
= 1;
105 if (mNumberOfProcessors
== 1) {
106 FreePages (mCommonStack
, EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber
* gApStackSize
));
110 if (mNumberOfProcessors
< gMaxLogicalProcessorNumber
) {
111 FreePages (mApStackStart
, EFI_SIZE_TO_PAGES ((gMaxLogicalProcessorNumber
- mNumberOfProcessors
) *