]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/CpuDxe/CpuMp.c
UefiCpuPkg/CpuDxe: introduce EFI_MP_SERVICES_PROTOCOL
[mirror_edk2.git] / UefiCpuPkg / CpuDxe / CpuMp.c
CommitLineData
6022e28c
JJ
1/** @file\r
2 CPU DXE Module.\r
3\r
4 Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "CpuDxe.h"\r
16#include "CpuMp.h"\r
17\r
6a26a597
CF
18UINTN gMaxLogicalProcessorNumber;\r
19UINTN gApStackSize;\r
20\r
fab82c18
JJ
21VOID *mCommonStack = 0;\r
22VOID *mTopOfApCommonStack = 0;\r
6a26a597 23VOID *mApStackStart = 0;\r
fab82c18 24\r
6a26a597 25volatile UINTN mNumberOfProcessors;\r
fab82c18 26\r
003973d9
CF
27EFI_MP_SERVICES_PROTOCOL mMpServicesTemplate = {\r
28 NULL, // GetNumberOfProcessors,\r
29 NULL, // GetProcessorInfo,\r
30 NULL, // StartupAllAPs,\r
31 NULL, // StartupThisAP,\r
32 NULL, // SwitchBSP,\r
33 NULL, // EnableDisableAP,\r
34 NULL // WhoAmI\r
35};\r
36\r
e343f8f7
CF
37/**\r
38 Application Processors do loop routine\r
39 after switch to its own stack.\r
40\r
41 @param Context1 A pointer to the context to pass into the function.\r
42 @param Context2 A pointer to the context to pass into the function.\r
43\r
44**/\r
45VOID\r
46ProcessorToIdleState (\r
47 IN VOID *Context1, OPTIONAL\r
48 IN VOID *Context2 OPTIONAL\r
49 )\r
50{\r
51 DEBUG ((DEBUG_INFO, "Ap apicid is %d\n", GetApicId ()));\r
52\r
53 AsmApDoneWithCommonStack ();\r
54\r
55 CpuSleep ();\r
56 CpuDeadLoop ();\r
57}\r
58\r
1535c888
JJ
59/**\r
60 Application Processor C code entry point.\r
61\r
62**/\r
63VOID\r
64EFIAPI\r
65ApEntryPointInC (\r
66 VOID\r
67 )\r
68{\r
6a26a597 69 mNumberOfProcessors++;\r
e343f8f7
CF
70 mApStackStart = (UINT8*)mApStackStart + gApStackSize;\r
71\r
72 SwitchStack (\r
73 (SWITCH_STACK_ENTRY_POINT)(UINTN)ProcessorToIdleState,\r
74 NULL,\r
75 NULL,\r
76 mApStackStart);\r
1535c888
JJ
77}\r
78\r
79\r
6022e28c
JJ
80/**\r
81 Initialize Multi-processor support.\r
82\r
83**/\r
84VOID\r
85InitializeMpSupport (\r
86 VOID\r
87 )\r
88{\r
6a26a597
CF
89 gMaxLogicalProcessorNumber = (UINTN) PcdGet32 (PcdCpuMaxLogicalProcessorNumber);\r
90 if (gMaxLogicalProcessorNumber < 1) {\r
91 DEBUG ((DEBUG_ERROR, "Setting PcdCpuMaxLogicalProcessorNumber should be more than zero.\n"));\r
92 return;\r
93 }\r
94\r
95 if (gMaxLogicalProcessorNumber == 1) {\r
96 return;\r
97 }\r
98\r
99 gApStackSize = (UINTN) PcdGet32 (PcdCpuApStackSize);\r
100 ASSERT ((gApStackSize & (SIZE_4KB - 1)) == 0);\r
101\r
102 mApStackStart = AllocatePages (EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber * gApStackSize));\r
103 ASSERT (mApStackStart != NULL);\r
6022e28c 104\r
6a26a597
CF
105 //\r
106 // the first buffer of stack size used for common stack, when the amount of AP\r
107 // more than 1, we should never free the common stack which maybe used for AP reset.\r
108 //\r
109 mCommonStack = mApStackStart;\r
110 mTopOfApCommonStack = (UINT8*) mApStackStart + gApStackSize;\r
111 mApStackStart = mTopOfApCommonStack;\r
112\r
113 mNumberOfProcessors = 1;\r
114\r
115 if (mNumberOfProcessors == 1) {\r
116 FreePages (mCommonStack, EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber * gApStackSize));\r
117 return;\r
118 }\r
119\r
120 if (mNumberOfProcessors < gMaxLogicalProcessorNumber) {\r
121 FreePages (mApStackStart, EFI_SIZE_TO_PAGES ((gMaxLogicalProcessorNumber - mNumberOfProcessors) *\r
122 gApStackSize));\r
123 }\r
124}\r