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