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 | \
57 Flush CPU data cache. If the instruction cache is fully coherent
58 with all DMA operations then function can just return EFI_SUCCESS.
60 @param This Protocol instance structure
61 @param Start Physical address to start flushing from.
62 @param Length Number of bytes to flush. Round up to chipset
64 @param FlushType Specifies the type of flush operation to perform.
66 @retval EFI_SUCCESS If cache was flushed
67 @retval EFI_UNSUPPORTED If flush type is not supported.
68 @retval EFI_DEVICE_ERROR If requested range could not be flushed.
73 CpuFlushCpuDataCache (
74 IN EFI_CPU_ARCH_PROTOCOL
*This
,
75 IN EFI_PHYSICAL_ADDRESS Start
,
77 IN EFI_CPU_FLUSH_TYPE FlushType
81 Enables CPU interrupts.
83 @param This Protocol instance structure
85 @retval EFI_SUCCESS If interrupts were enabled in the CPU
86 @retval EFI_DEVICE_ERROR If interrupts could not be enabled on the CPU.
92 IN EFI_CPU_ARCH_PROTOCOL
*This
96 Disables CPU interrupts.
98 @param This Protocol instance structure
100 @retval EFI_SUCCESS If interrupts were disabled in the CPU.
101 @retval EFI_DEVICE_ERROR If interrupts could not be disabled on the CPU.
106 CpuDisableInterrupt (
107 IN EFI_CPU_ARCH_PROTOCOL
*This
111 Return the state of interrupts.
113 @param This Protocol instance structure
114 @param State Pointer to the CPU's current interrupt state
116 @retval EFI_SUCCESS If interrupts were disabled in the CPU.
117 @retval EFI_INVALID_PARAMETER State is NULL.
122 CpuGetInterruptState (
123 IN EFI_CPU_ARCH_PROTOCOL
*This
,
128 Generates an INIT to the CPU.
130 @param This Protocol instance structure
131 @param InitType Type of CPU INIT to perform
133 @retval EFI_SUCCESS If CPU INIT occurred. This value should never be
135 @retval EFI_DEVICE_ERROR If CPU INIT failed.
136 @retval EFI_UNSUPPORTED Requested type of CPU INIT not supported.
142 IN EFI_CPU_ARCH_PROTOCOL
*This
,
143 IN EFI_CPU_INIT_TYPE InitType
147 Registers a function to be called from the CPU interrupt handler.
149 @param This Protocol instance structure
150 @param InterruptType Defines which interrupt to hook. IA-32
151 valid range is 0x00 through 0xFF
152 @param InterruptHandler A pointer to a function of type
153 EFI_CPU_INTERRUPT_HANDLER that is called
154 when a processor interrupt occurs. A null
155 pointer is an error condition.
157 @retval EFI_SUCCESS If handler installed or uninstalled.
158 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler
159 for InterruptType was previously installed.
160 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for
161 InterruptType was not previously installed.
162 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType
168 CpuRegisterInterruptHandler (
169 IN EFI_CPU_ARCH_PROTOCOL
*This
,
170 IN EFI_EXCEPTION_TYPE InterruptType
,
171 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
175 Returns a timer value from one of the CPU's internal timers. There is no
176 inherent time interval between ticks but is a function of the CPU frequency.
178 @param This - Protocol instance structure.
179 @param TimerIndex - Specifies which CPU timer is requested.
180 @param TimerValue - Pointer to the returned timer value.
181 @param TimerPeriod - A pointer to the amount of time that passes
182 in femtoseconds (10-15) for each increment
183 of TimerValue. If TimerValue does not
184 increment at a predictable rate, then 0 is
185 returned. The amount of time that has
186 passed between two calls to GetTimerValue()
187 can be calculated with the formula
188 (TimerValue2 - TimerValue1) * TimerPeriod.
189 This parameter is optional and may be NULL.
191 @retval EFI_SUCCESS - If the CPU timer count was returned.
192 @retval EFI_UNSUPPORTED - If the CPU does not have any readable timers.
193 @retval EFI_DEVICE_ERROR - If an error occurred while reading the timer.
194 @retval EFI_INVALID_PARAMETER - TimerIndex is not valid or TimerValue is NULL.
200 IN EFI_CPU_ARCH_PROTOCOL
*This
,
201 IN UINT32 TimerIndex
,
202 OUT UINT64
*TimerValue
,
203 OUT UINT64
*TimerPeriod OPTIONAL
207 Set memory cacheability attributes for given range of memeory.
209 @param This Protocol instance structure
210 @param BaseAddress Specifies the start address of the
212 @param Length Specifies the length of the memory range
213 @param Attributes The memory cacheability for the memory range
215 @retval EFI_SUCCESS If the cacheability of that memory range is
217 @retval EFI_UNSUPPORTED If the desired operation cannot be done
218 @retval EFI_INVALID_PARAMETER The input parameter is not correct,
224 CpuSetMemoryAttributes (
225 IN EFI_CPU_ARCH_PROTOCOL
*This
,
226 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
232 Initialize Global Descriptor Table.
236 InitGlobalDescriptorTable (
241 Sets the code selector (CS).
243 @param Selector Value of code selector.
253 Sets the data selector (DS).
255 @param Selector Value of data selector.