]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/MpInitLib/MpLib.h
e605f8de41edd830f7ed12f57fdb72cf4900cb32
[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 related data
59 //
60 typedef struct {
61 SPIN_LOCK ApLock;
62 volatile UINT32 *StartupApSignal;
63 volatile UINTN ApFunction;
64 volatile UINTN ApFunctionArgument;
65 UINT32 InitialApicId;
66 UINT32 ApicId;
67 UINT32 Health;
68 BOOLEAN CpuHealthy;
69 BOOLEAN Waiting;
70 BOOLEAN *Finished;
71 UINT64 ExpectedTime;
72 UINT64 CurrentTime;
73 UINT64 TotalTime;
74 EFI_EVENT WaitEvent;
75 } CPU_AP_DATA;
76
77 //
78 // Basic CPU information saved in Guided HOB.
79 // Because the contents will be shard between PEI and DXE,
80 // we need to make sure the each fields offset same in different
81 // architecture.
82 //
83 typedef struct {
84 UINT32 InitialApicId;
85 UINT32 ApicId;
86 UINT32 Health;
87 } CPU_INFO_IN_HOB;
88
89 //
90 // AP reset code information including code address and size,
91 // this structure will be shared be C code and assembly code.
92 // It is natural aligned by design.
93 //
94 typedef struct {
95 UINT8 *RendezvousFunnelAddress;
96 UINTN ModeEntryOffset;
97 UINTN RendezvousFunnelSize;
98 UINT8 *RelocateApLoopFuncAddress;
99 UINTN RelocateApLoopFuncSize;
100 } MP_ASSEMBLY_ADDRESS_MAP;
101
102 typedef struct _CPU_MP_DATA CPU_MP_DATA;
103
104 #pragma pack(1)
105
106 //
107 // MP CPU exchange information for AP reset code
108 // This structure is required to be packed because fixed field offsets
109 // into this structure are used in assembly code in this module
110 //
111 typedef struct {
112 UINTN Lock;
113 UINTN StackStart;
114 UINTN StackSize;
115 UINTN CFunction;
116 IA32_DESCRIPTOR GdtrProfile;
117 IA32_DESCRIPTOR IdtrProfile;
118 UINTN BufferStart;
119 UINTN ModeOffset;
120 UINTN NumApsExecuting;
121 UINTN CodeSegment;
122 UINTN DataSegment;
123 UINTN EnableExecuteDisable;
124 UINTN Cr3;
125 CPU_MP_DATA *CpuMpData;
126 } MP_CPU_EXCHANGE_INFO;
127
128 #pragma pack()
129
130 //
131 // CPU MP Data save in memory
132 //
133 struct _CPU_MP_DATA {
134 UINT64 CpuInfoInHob;
135 UINT32 CpuCount;
136 UINT32 BspNumber;
137 //
138 // The above fields data will be passed from PEI to DXE
139 // Please make sure the fields offset same in the different
140 // architecture.
141 //
142 SPIN_LOCK MpLock;
143 UINTN Buffer;
144 UINTN CpuApStackSize;
145 MP_ASSEMBLY_ADDRESS_MAP AddressMap;
146 UINTN WakeupBuffer;
147 UINTN BackupBuffer;
148 UINTN BackupBufferSize;
149 BOOLEAN EndOfPeiFlag;
150
151 volatile UINT32 StartCount;
152 volatile UINT32 FinishedCount;
153 volatile UINT32 RunningCount;
154 BOOLEAN SingleThread;
155 EFI_AP_PROCEDURE Procedure;
156 VOID *ProcArguments;
157 BOOLEAN *Finished;
158 UINT64 ExpectedTime;
159 UINT64 CurrentTime;
160 UINT64 TotalTime;
161 EFI_EVENT WaitEvent;
162 UINTN **FailedCpuList;
163
164 AP_INIT_STATE InitFlag;
165 BOOLEAN X2ApicEnable;
166 MTRR_SETTINGS MtrrTable;
167 UINT8 ApLoopMode;
168 UINT8 ApTargetCState;
169 UINT16 PmCodeSegment;
170 CPU_AP_DATA *CpuData;
171 volatile MP_CPU_EXCHANGE_INFO *MpCpuExchangeInfo;
172 };
173 /**
174 Assembly code to place AP into safe loop mode.
175
176 Place AP into targeted C-State if MONITOR is supported, otherwise
177 place AP into hlt state.
178 Place AP in protected mode if the current is long mode. Due to AP maybe
179 wakeup by some hardware event. It could avoid accessing page table that
180 may not available during booting to OS.
181
182 @param[in] MwaitSupport TRUE indicates MONITOR is supported.
183 FALSE indicates MONITOR is not supported.
184 @param[in] ApTargetCState Target C-State value.
185 @param[in] PmCodeSegment Protected mode code segment value.
186 **/
187 typedef
188 VOID
189 (EFIAPI * ASM_RELOCATE_AP_LOOP) (
190 IN BOOLEAN MwaitSupport,
191 IN UINTN ApTargetCState,
192 IN UINTN PmCodeSegment
193 );
194
195 /**
196 Assembly code to get starting address and size of the rendezvous entry for APs.
197 Information for fixing a jump instruction in the code is also returned.
198
199 @param[out] AddressMap Output buffer for address map information.
200 **/
201 VOID
202 EFIAPI
203 AsmGetAddressMap (
204 OUT MP_ASSEMBLY_ADDRESS_MAP *AddressMap
205 );
206
207 #endif
208