]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/CpuDxe/CpuDxe.h
UefiCpuPkg/CpuDxe: implement non-stop mode for uefi
[mirror_edk2.git] / UefiCpuPkg / CpuDxe / CpuDxe.h
1 /** @file
2 CPU DXE Module to produce CPU ARCH Protocol and CPU MP Protocol.
3
4 Copyright (c) 2008 - 2017, 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 _CPU_DXE_H_
16 #define _CPU_DXE_H_
17
18 #include <PiDxe.h>
19
20 #include <Protocol/Cpu.h>
21 #include <Protocol/MpService.h>
22 #include <Register/Msr.h>
23
24 #include <Ppi/SecPlatformInformation.h>
25 #include <Ppi/SecPlatformInformation2.h>
26
27 #include <Library/UefiDriverEntryPoint.h>
28 #include <Library/UefiBootServicesTableLib.h>
29 #include <Library/DxeServicesTableLib.h>
30 #include <Library/BaseLib.h>
31 #include <Library/CpuLib.h>
32 #include <Library/BaseMemoryLib.h>
33 #include <Library/MemoryAllocationLib.h>
34 #include <Library/DebugLib.h>
35 #include <Library/MtrrLib.h>
36 #include <Library/LocalApicLib.h>
37 #include <Library/UefiCpuLib.h>
38 #include <Library/UefiLib.h>
39 #include <Library/CpuExceptionHandlerLib.h>
40 #include <Library/HobLib.h>
41 #include <Library/ReportStatusCodeLib.h>
42 #include <Library/MpInitLib.h>
43 #include <Library/TimerLib.h>
44
45 #include <Guid/IdleLoopEvent.h>
46 #include <Guid/VectorHandoffTable.h>
47
48 #define EFI_MEMORY_CACHETYPE_MASK (EFI_MEMORY_UC | \
49 EFI_MEMORY_WC | \
50 EFI_MEMORY_WT | \
51 EFI_MEMORY_WB | \
52 EFI_MEMORY_UCE \
53 )
54
55 #define EFI_MEMORY_PAGETYPE_MASK (EFI_MEMORY_RP | \
56 EFI_MEMORY_XP | \
57 EFI_MEMORY_RO \
58 )
59
60 #define HEAP_GUARD_NONSTOP_MODE \
61 ((PcdGet8 (PcdHeapGuardPropertyMask) & (BIT6|BIT1|BIT0)) > BIT6)
62
63 #define NULL_DETECTION_NONSTOP_MODE \
64 ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & (BIT6|BIT0)) > BIT6)
65
66 /**
67 Flush CPU data cache. If the instruction cache is fully coherent
68 with all DMA operations then function can just return EFI_SUCCESS.
69
70 @param This Protocol instance structure
71 @param Start Physical address to start flushing from.
72 @param Length Number of bytes to flush. Round up to chipset
73 granularity.
74 @param FlushType Specifies the type of flush operation to perform.
75
76 @retval EFI_SUCCESS If cache was flushed
77 @retval EFI_UNSUPPORTED If flush type is not supported.
78 @retval EFI_DEVICE_ERROR If requested range could not be flushed.
79
80 **/
81 EFI_STATUS
82 EFIAPI
83 CpuFlushCpuDataCache (
84 IN EFI_CPU_ARCH_PROTOCOL *This,
85 IN EFI_PHYSICAL_ADDRESS Start,
86 IN UINT64 Length,
87 IN EFI_CPU_FLUSH_TYPE FlushType
88 );
89
90 /**
91 Enables CPU interrupts.
92
93 @param This Protocol instance structure
94
95 @retval EFI_SUCCESS If interrupts were enabled in the CPU
96 @retval EFI_DEVICE_ERROR If interrupts could not be enabled on the CPU.
97
98 **/
99 EFI_STATUS
100 EFIAPI
101 CpuEnableInterrupt (
102 IN EFI_CPU_ARCH_PROTOCOL *This
103 );
104
105 /**
106 Disables CPU interrupts.
107
108 @param This Protocol instance structure
109
110 @retval EFI_SUCCESS If interrupts were disabled in the CPU.
111 @retval EFI_DEVICE_ERROR If interrupts could not be disabled on the CPU.
112
113 **/
114 EFI_STATUS
115 EFIAPI
116 CpuDisableInterrupt (
117 IN EFI_CPU_ARCH_PROTOCOL *This
118 );
119
120 /**
121 Return the state of interrupts.
122
123 @param This Protocol instance structure
124 @param State Pointer to the CPU's current interrupt state
125
126 @retval EFI_SUCCESS If interrupts were disabled in the CPU.
127 @retval EFI_INVALID_PARAMETER State is NULL.
128
129 **/
130 EFI_STATUS
131 EFIAPI
132 CpuGetInterruptState (
133 IN EFI_CPU_ARCH_PROTOCOL *This,
134 OUT BOOLEAN *State
135 );
136
137 /**
138 Generates an INIT to the CPU.
139
140 @param This Protocol instance structure
141 @param InitType Type of CPU INIT to perform
142
143 @retval EFI_SUCCESS If CPU INIT occurred. This value should never be
144 seen.
145 @retval EFI_DEVICE_ERROR If CPU INIT failed.
146 @retval EFI_UNSUPPORTED Requested type of CPU INIT not supported.
147
148 **/
149 EFI_STATUS
150 EFIAPI
151 CpuInit (
152 IN EFI_CPU_ARCH_PROTOCOL *This,
153 IN EFI_CPU_INIT_TYPE InitType
154 );
155
156 /**
157 Registers a function to be called from the CPU interrupt handler.
158
159 @param This Protocol instance structure
160 @param InterruptType Defines which interrupt to hook. IA-32
161 valid range is 0x00 through 0xFF
162 @param InterruptHandler A pointer to a function of type
163 EFI_CPU_INTERRUPT_HANDLER that is called
164 when a processor interrupt occurs. A null
165 pointer is an error condition.
166
167 @retval EFI_SUCCESS If handler installed or uninstalled.
168 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler
169 for InterruptType was previously installed.
170 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for
171 InterruptType was not previously installed.
172 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType
173 is not supported.
174
175 **/
176 EFI_STATUS
177 EFIAPI
178 CpuRegisterInterruptHandler (
179 IN EFI_CPU_ARCH_PROTOCOL *This,
180 IN EFI_EXCEPTION_TYPE InterruptType,
181 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
182 );
183
184 /**
185 Returns a timer value from one of the CPU's internal timers. There is no
186 inherent time interval between ticks but is a function of the CPU frequency.
187
188 @param This - Protocol instance structure.
189 @param TimerIndex - Specifies which CPU timer is requested.
190 @param TimerValue - Pointer to the returned timer value.
191 @param TimerPeriod - A pointer to the amount of time that passes
192 in femtoseconds (10-15) for each increment
193 of TimerValue. If TimerValue does not
194 increment at a predictable rate, then 0 is
195 returned. The amount of time that has
196 passed between two calls to GetTimerValue()
197 can be calculated with the formula
198 (TimerValue2 - TimerValue1) * TimerPeriod.
199 This parameter is optional and may be NULL.
200
201 @retval EFI_SUCCESS - If the CPU timer count was returned.
202 @retval EFI_UNSUPPORTED - If the CPU does not have any readable timers.
203 @retval EFI_DEVICE_ERROR - If an error occurred while reading the timer.
204 @retval EFI_INVALID_PARAMETER - TimerIndex is not valid or TimerValue is NULL.
205
206 **/
207 EFI_STATUS
208 EFIAPI
209 CpuGetTimerValue (
210 IN EFI_CPU_ARCH_PROTOCOL *This,
211 IN UINT32 TimerIndex,
212 OUT UINT64 *TimerValue,
213 OUT UINT64 *TimerPeriod OPTIONAL
214 );
215
216 /**
217 Set memory cacheability attributes for given range of memeory.
218
219 @param This Protocol instance structure
220 @param BaseAddress Specifies the start address of the
221 memory range
222 @param Length Specifies the length of the memory range
223 @param Attributes The memory cacheability for the memory range
224
225 @retval EFI_SUCCESS If the cacheability of that memory range is
226 set successfully
227 @retval EFI_UNSUPPORTED If the desired operation cannot be done
228 @retval EFI_INVALID_PARAMETER The input parameter is not correct,
229 such as Length = 0
230
231 **/
232 EFI_STATUS
233 EFIAPI
234 CpuSetMemoryAttributes (
235 IN EFI_CPU_ARCH_PROTOCOL *This,
236 IN EFI_PHYSICAL_ADDRESS BaseAddress,
237 IN UINT64 Length,
238 IN UINT64 Attributes
239 );
240
241 /**
242 Initialize Global Descriptor Table.
243
244 **/
245 VOID
246 InitGlobalDescriptorTable (
247 VOID
248 );
249
250 /**
251 Sets the code selector (CS).
252
253 @param Selector Value of code selector.
254
255 **/
256 VOID
257 EFIAPI
258 SetCodeSelector (
259 UINT16 Selector
260 );
261
262 /**
263 Sets the data selector (DS).
264
265 @param Selector Value of data selector.
266
267 **/
268 VOID
269 EFIAPI
270 SetDataSelectors (
271 UINT16 Selector
272 );
273
274 /**
275 Update GCD memory space attributes according to current page table setup.
276 **/
277 VOID
278 RefreshGcdMemoryAttributesFromPaging (
279 VOID
280 );
281
282 /**
283 Special handler for #DB exception, which will restore the page attributes
284 (not-present). It should work with #PF handler which will set pages to
285 'present'.
286
287 @param ExceptionType Exception type.
288 @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
289
290 **/
291 VOID
292 EFIAPI
293 DebugExceptionHandler (
294 IN EFI_EXCEPTION_TYPE InterruptType,
295 IN EFI_SYSTEM_CONTEXT SystemContext
296 );
297
298 /**
299 Special handler for #PF exception, which will set the pages which caused
300 #PF to be 'present'. The attribute of those pages should be restored in
301 the subsequent #DB handler.
302
303 @param ExceptionType Exception type.
304 @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
305
306 **/
307 VOID
308 EFIAPI
309 PageFaultExceptionHandler (
310 IN EFI_EXCEPTION_TYPE InterruptType,
311 IN EFI_SYSTEM_CONTEXT SystemContext
312 );
313
314 extern BOOLEAN mIsAllocatingPageTable;
315 extern UINTN mNumberOfProcessors;
316
317 #endif
318