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 Processor C code entry point.
37 mNumberOfProcessors
++;
42 Initialize Multi-processor support.
50 gMaxLogicalProcessorNumber
= (UINTN
) PcdGet32 (PcdCpuMaxLogicalProcessorNumber
);
51 if (gMaxLogicalProcessorNumber
< 1) {
52 DEBUG ((DEBUG_ERROR
, "Setting PcdCpuMaxLogicalProcessorNumber should be more than zero.\n"));
56 if (gMaxLogicalProcessorNumber
== 1) {
60 gApStackSize
= (UINTN
) PcdGet32 (PcdCpuApStackSize
);
61 ASSERT ((gApStackSize
& (SIZE_4KB
- 1)) == 0);
63 mApStackStart
= AllocatePages (EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber
* gApStackSize
));
64 ASSERT (mApStackStart
!= NULL
);
67 // the first buffer of stack size used for common stack, when the amount of AP
68 // more than 1, we should never free the common stack which maybe used for AP reset.
70 mCommonStack
= mApStackStart
;
71 mTopOfApCommonStack
= (UINT8
*) mApStackStart
+ gApStackSize
;
72 mApStackStart
= mTopOfApCommonStack
;
74 mNumberOfProcessors
= 1;
76 if (mNumberOfProcessors
== 1) {
77 FreePages (mCommonStack
, EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber
* gApStackSize
));
81 if (mNumberOfProcessors
< gMaxLogicalProcessorNumber
) {
82 FreePages (mApStackStart
, EFI_SIZE_TO_PAGES ((gMaxLogicalProcessorNumber
- mNumberOfProcessors
) *