]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Library/MpInitLib/MpLib.h
UefiCpuPkg/MpInitLib: Initialize CPU_AP_DATA for CPU APs
[mirror_edk2.git] / UefiCpuPkg / Library / MpInitLib / MpLib.h
CommitLineData
3e8ad6bd
JF
1/** @file\r
2 Common header file for MP Initialize Library.\r
3\r
4 Copyright (c) 2016, 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#ifndef _MP_LIB_H_\r
16#define _MP_LIB_H_\r
17\r
18#include <PiPei.h>\r
19\r
20#include <Register/Cpuid.h>\r
21#include <Register/Msr.h>\r
22#include <Register/LocalApic.h>\r
23#include <Register/Microcode.h>\r
24\r
25#include <Library/MpInitLib.h>\r
26#include <Library/BaseLib.h>\r
27#include <Library/BaseMemoryLib.h>\r
28#include <Library/MemoryAllocationLib.h>\r
29#include <Library/DebugLib.h>\r
30#include <Library/LocalApicLib.h>\r
31#include <Library/CpuLib.h>\r
32#include <Library/UefiCpuLib.h>\r
33#include <Library/TimerLib.h>\r
34#include <Library/SynchronizationLib.h>\r
35#include <Library/MtrrLib.h>\r
36#include <Library/HobLib.h>\r
37\r
9ebcf0f4
JF
38//\r
39// AP loop state when APs are in idle state\r
40// It's value is the same with PcdCpuApLoopMode\r
41//\r
42typedef enum {\r
43 ApInHltLoop = 1,\r
44 ApInMwaitLoop = 2,\r
45 ApInRunLoop = 3\r
46} AP_LOOP_MODE;\r
47\r
e59f8f6b
JF
48//\r
49// AP initialization state during APs wakeup\r
50//\r
51typedef enum {\r
52 ApInitConfig = 1,\r
53 ApInitReconfig = 2,\r
54 ApInitDone = 3\r
55} AP_INIT_STATE;\r
56\r
03a1a925
JF
57//\r
58// AP state\r
59//\r
60typedef enum {\r
61 CpuStateIdle,\r
62 CpuStateReady,\r
63 CpuStateBusy,\r
64 CpuStateFinished,\r
65 CpuStateDisabled\r
66} CPU_STATE;\r
67\r
e59f8f6b
JF
68//\r
69// AP related data\r
70//\r
71typedef struct {\r
72 SPIN_LOCK ApLock;\r
73 volatile UINT32 *StartupApSignal;\r
74 volatile UINTN ApFunction;\r
75 volatile UINTN ApFunctionArgument;\r
76 UINT32 InitialApicId;\r
77 UINT32 ApicId;\r
78 UINT32 Health;\r
79 BOOLEAN CpuHealthy;\r
03a1a925 80 volatile CPU_STATE State;\r
e59f8f6b
JF
81 BOOLEAN Waiting;\r
82 BOOLEAN *Finished;\r
83 UINT64 ExpectedTime;\r
84 UINT64 CurrentTime;\r
85 UINT64 TotalTime;\r
86 EFI_EVENT WaitEvent;\r
87} CPU_AP_DATA;\r
88\r
89//\r
90// Basic CPU information saved in Guided HOB.\r
91// Because the contents will be shard between PEI and DXE,\r
92// we need to make sure the each fields offset same in different\r
93// architecture.\r
94//\r
95typedef struct {\r
96 UINT32 InitialApicId;\r
97 UINT32 ApicId;\r
98 UINT32 Health;\r
99} CPU_INFO_IN_HOB;\r
100\r
f7f85d83
JF
101//\r
102// AP reset code information including code address and size,\r
103// this structure will be shared be C code and assembly code.\r
104// It is natural aligned by design.\r
105//\r
106typedef struct {\r
107 UINT8 *RendezvousFunnelAddress;\r
108 UINTN ModeEntryOffset;\r
109 UINTN RendezvousFunnelSize;\r
110 UINT8 *RelocateApLoopFuncAddress;\r
111 UINTN RelocateApLoopFuncSize;\r
112} MP_ASSEMBLY_ADDRESS_MAP;\r
3e8ad6bd 113\r
e59f8f6b
JF
114typedef struct _CPU_MP_DATA CPU_MP_DATA;\r
115\r
d94e5f67
JF
116#pragma pack(1)\r
117\r
118//\r
119// MP CPU exchange information for AP reset code\r
120// This structure is required to be packed because fixed field offsets\r
121// into this structure are used in assembly code in this module\r
122//\r
123typedef struct {\r
124 UINTN Lock;\r
125 UINTN StackStart;\r
126 UINTN StackSize;\r
127 UINTN CFunction;\r
128 IA32_DESCRIPTOR GdtrProfile;\r
129 IA32_DESCRIPTOR IdtrProfile;\r
130 UINTN BufferStart;\r
131 UINTN ModeOffset;\r
132 UINTN NumApsExecuting;\r
133 UINTN CodeSegment;\r
134 UINTN DataSegment;\r
5c66d125 135 UINTN EnableExecuteDisable;\r
d94e5f67 136 UINTN Cr3;\r
e59f8f6b 137 CPU_MP_DATA *CpuMpData;\r
d94e5f67
JF
138} MP_CPU_EXCHANGE_INFO;\r
139\r
140#pragma pack()\r
e59f8f6b
JF
141\r
142//\r
143// CPU MP Data save in memory\r
144//\r
145struct _CPU_MP_DATA {\r
146 UINT64 CpuInfoInHob;\r
147 UINT32 CpuCount;\r
148 UINT32 BspNumber;\r
149 //\r
150 // The above fields data will be passed from PEI to DXE\r
151 // Please make sure the fields offset same in the different\r
152 // architecture.\r
153 //\r
154 SPIN_LOCK MpLock;\r
155 UINTN Buffer;\r
156 UINTN CpuApStackSize;\r
157 MP_ASSEMBLY_ADDRESS_MAP AddressMap;\r
158 UINTN WakeupBuffer;\r
159 UINTN BackupBuffer;\r
160 UINTN BackupBufferSize;\r
161 BOOLEAN EndOfPeiFlag;\r
162\r
163 volatile UINT32 StartCount;\r
164 volatile UINT32 FinishedCount;\r
165 volatile UINT32 RunningCount;\r
166 BOOLEAN SingleThread;\r
167 EFI_AP_PROCEDURE Procedure;\r
168 VOID *ProcArguments;\r
169 BOOLEAN *Finished;\r
170 UINT64 ExpectedTime;\r
171 UINT64 CurrentTime;\r
172 UINT64 TotalTime;\r
173 EFI_EVENT WaitEvent;\r
174 UINTN **FailedCpuList;\r
175\r
176 AP_INIT_STATE InitFlag;\r
177 BOOLEAN X2ApicEnable;\r
178 MTRR_SETTINGS MtrrTable;\r
179 UINT8 ApLoopMode;\r
180 UINT8 ApTargetCState;\r
181 UINT16 PmCodeSegment;\r
182 CPU_AP_DATA *CpuData;\r
183 volatile MP_CPU_EXCHANGE_INFO *MpCpuExchangeInfo;\r
184};\r
76157021
JF
185/**\r
186 Assembly code to place AP into safe loop mode.\r
187\r
188 Place AP into targeted C-State if MONITOR is supported, otherwise\r
189 place AP into hlt state.\r
190 Place AP in protected mode if the current is long mode. Due to AP maybe\r
191 wakeup by some hardware event. It could avoid accessing page table that\r
192 may not available during booting to OS.\r
193\r
194 @param[in] MwaitSupport TRUE indicates MONITOR is supported.\r
195 FALSE indicates MONITOR is not supported.\r
196 @param[in] ApTargetCState Target C-State value.\r
197 @param[in] PmCodeSegment Protected mode code segment value.\r
198**/\r
199typedef\r
200VOID\r
201(EFIAPI * ASM_RELOCATE_AP_LOOP) (\r
202 IN BOOLEAN MwaitSupport,\r
203 IN UINTN ApTargetCState,\r
204 IN UINTN PmCodeSegment\r
205 );\r
f7f85d83
JF
206\r
207/**\r
208 Assembly code to get starting address and size of the rendezvous entry for APs.\r
209 Information for fixing a jump instruction in the code is also returned.\r
210\r
211 @param[out] AddressMap Output buffer for address map information.\r
212**/\r
213VOID\r
214EFIAPI\r
215AsmGetAddressMap (\r
216 OUT MP_ASSEMBLY_ADDRESS_MAP *AddressMap\r
217 );\r
218\r
3e8ad6bd
JF
219#endif\r
220\r