]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/CpuDxe/CpuMp.c
UefiCpuPkg/CpuDxe: introduce two PCD value
[mirror_edk2.git] / UefiCpuPkg / CpuDxe / CpuMp.c
1 /** @file
2 CPU DXE Module.
3
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
9
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.
12
13 **/
14
15 #include "CpuDxe.h"
16 #include "CpuMp.h"
17
18 UINTN gMaxLogicalProcessorNumber;
19 UINTN gApStackSize;
20
21 VOID *mCommonStack = 0;
22 VOID *mTopOfApCommonStack = 0;
23 VOID *mApStackStart = 0;
24
25 volatile UINTN mNumberOfProcessors;
26
27 /**
28 Application Processor C code entry point.
29
30 **/
31 VOID
32 EFIAPI
33 ApEntryPointInC (
34 VOID
35 )
36 {
37 mNumberOfProcessors++;
38 }
39
40
41 /**
42 Initialize Multi-processor support.
43
44 **/
45 VOID
46 InitializeMpSupport (
47 VOID
48 )
49 {
50 gMaxLogicalProcessorNumber = (UINTN) PcdGet32 (PcdCpuMaxLogicalProcessorNumber);
51 if (gMaxLogicalProcessorNumber < 1) {
52 DEBUG ((DEBUG_ERROR, "Setting PcdCpuMaxLogicalProcessorNumber should be more than zero.\n"));
53 return;
54 }
55
56 if (gMaxLogicalProcessorNumber == 1) {
57 return;
58 }
59
60 gApStackSize = (UINTN) PcdGet32 (PcdCpuApStackSize);
61 ASSERT ((gApStackSize & (SIZE_4KB - 1)) == 0);
62
63 mApStackStart = AllocatePages (EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber * gApStackSize));
64 ASSERT (mApStackStart != NULL);
65
66 //
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.
69 //
70 mCommonStack = mApStackStart;
71 mTopOfApCommonStack = (UINT8*) mApStackStart + gApStackSize;
72 mApStackStart = mTopOfApCommonStack;
73
74 mNumberOfProcessors = 1;
75
76 if (mNumberOfProcessors == 1) {
77 FreePages (mCommonStack, EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber * gApStackSize));
78 return;
79 }
80
81 if (mNumberOfProcessors < gMaxLogicalProcessorNumber) {
82 FreePages (mApStackStart, EFI_SIZE_TO_PAGES ((gMaxLogicalProcessorNumber - mNumberOfProcessors) *
83 gApStackSize));
84 }
85 }