2 CPU DXE Module to produce CPU ARCH Protocol and CPU MP Protocol.
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
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.
20 #include <Protocol/Cpu.h>
21 #include <Protocol/MpService.h>
22 #include <Register/Msr.h>
24 #include <Ppi/SecPlatformInformation.h>
25 #include <Ppi/SecPlatformInformation2.h>
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>
45 #include <Guid/IdleLoopEvent.h>
46 #include <Guid/VectorHandoffTable.h>
48 #define EFI_MEMORY_CACHETYPE_MASK (EFI_MEMORY_UC | \
55 #define EFI_MEMORY_PAGETYPE_MASK (EFI_MEMORY_RP | \
61 Flush CPU data cache. If the instruction cache is fully coherent
62 with all DMA operations then function can just return EFI_SUCCESS.
64 @param This Protocol instance structure
65 @param Start Physical address to start flushing from.
66 @param Length Number of bytes to flush. Round up to chipset
68 @param FlushType Specifies the type of flush operation to perform.
70 @retval EFI_SUCCESS If cache was flushed
71 @retval EFI_UNSUPPORTED If flush type is not supported.
72 @retval EFI_DEVICE_ERROR If requested range could not be flushed.
77 CpuFlushCpuDataCache (
78 IN EFI_CPU_ARCH_PROTOCOL
*This
,
79 IN EFI_PHYSICAL_ADDRESS Start
,
81 IN EFI_CPU_FLUSH_TYPE FlushType
85 Enables CPU interrupts.
87 @param This Protocol instance structure
89 @retval EFI_SUCCESS If interrupts were enabled in the CPU
90 @retval EFI_DEVICE_ERROR If interrupts could not be enabled on the CPU.
96 IN EFI_CPU_ARCH_PROTOCOL
*This
100 Disables CPU interrupts.
102 @param This Protocol instance structure
104 @retval EFI_SUCCESS If interrupts were disabled in the CPU.
105 @retval EFI_DEVICE_ERROR If interrupts could not be disabled on the CPU.
110 CpuDisableInterrupt (
111 IN EFI_CPU_ARCH_PROTOCOL
*This
115 Return the state of interrupts.
117 @param This Protocol instance structure
118 @param State Pointer to the CPU's current interrupt state
120 @retval EFI_SUCCESS If interrupts were disabled in the CPU.
121 @retval EFI_INVALID_PARAMETER State is NULL.
126 CpuGetInterruptState (
127 IN EFI_CPU_ARCH_PROTOCOL
*This
,
132 Generates an INIT to the CPU.
134 @param This Protocol instance structure
135 @param InitType Type of CPU INIT to perform
137 @retval EFI_SUCCESS If CPU INIT occurred. This value should never be
139 @retval EFI_DEVICE_ERROR If CPU INIT failed.
140 @retval EFI_UNSUPPORTED Requested type of CPU INIT not supported.
146 IN EFI_CPU_ARCH_PROTOCOL
*This
,
147 IN EFI_CPU_INIT_TYPE InitType
151 Registers a function to be called from the CPU interrupt handler.
153 @param This Protocol instance structure
154 @param InterruptType Defines which interrupt to hook. IA-32
155 valid range is 0x00 through 0xFF
156 @param InterruptHandler A pointer to a function of type
157 EFI_CPU_INTERRUPT_HANDLER that is called
158 when a processor interrupt occurs. A null
159 pointer is an error condition.
161 @retval EFI_SUCCESS If handler installed or uninstalled.
162 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler
163 for InterruptType was previously installed.
164 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for
165 InterruptType was not previously installed.
166 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType
172 CpuRegisterInterruptHandler (
173 IN EFI_CPU_ARCH_PROTOCOL
*This
,
174 IN EFI_EXCEPTION_TYPE InterruptType
,
175 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
179 Returns a timer value from one of the CPU's internal timers. There is no
180 inherent time interval between ticks but is a function of the CPU frequency.
182 @param This - Protocol instance structure.
183 @param TimerIndex - Specifies which CPU timer is requested.
184 @param TimerValue - Pointer to the returned timer value.
185 @param TimerPeriod - A pointer to the amount of time that passes
186 in femtoseconds (10-15) for each increment
187 of TimerValue. If TimerValue does not
188 increment at a predictable rate, then 0 is
189 returned. The amount of time that has
190 passed between two calls to GetTimerValue()
191 can be calculated with the formula
192 (TimerValue2 - TimerValue1) * TimerPeriod.
193 This parameter is optional and may be NULL.
195 @retval EFI_SUCCESS - If the CPU timer count was returned.
196 @retval EFI_UNSUPPORTED - If the CPU does not have any readable timers.
197 @retval EFI_DEVICE_ERROR - If an error occurred while reading the timer.
198 @retval EFI_INVALID_PARAMETER - TimerIndex is not valid or TimerValue is NULL.
204 IN EFI_CPU_ARCH_PROTOCOL
*This
,
205 IN UINT32 TimerIndex
,
206 OUT UINT64
*TimerValue
,
207 OUT UINT64
*TimerPeriod OPTIONAL
211 Set memory cacheability attributes for given range of memeory.
213 @param This Protocol instance structure
214 @param BaseAddress Specifies the start address of the
216 @param Length Specifies the length of the memory range
217 @param Attributes The memory cacheability for the memory range
219 @retval EFI_SUCCESS If the cacheability of that memory range is
221 @retval EFI_UNSUPPORTED If the desired operation cannot be done
222 @retval EFI_INVALID_PARAMETER The input parameter is not correct,
228 CpuSetMemoryAttributes (
229 IN EFI_CPU_ARCH_PROTOCOL
*This
,
230 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
236 Initialize Global Descriptor Table.
240 InitGlobalDescriptorTable (
245 Sets the code selector (CS).
247 @param Selector Value of code selector.
257 Sets the data selector (DS).
259 @param Selector Value of data selector.
269 Update GCD memory space attributes according to current page table setup.
272 RefreshGcdMemoryAttributesFromPaging (