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>
23 #include <Ppi/SecPlatformInformation.h>
24 #include <Ppi/SecPlatformInformation2.h>
26 #include <Library/UefiDriverEntryPoint.h>
27 #include <Library/UefiBootServicesTableLib.h>
28 #include <Library/DxeServicesTableLib.h>
29 #include <Library/BaseLib.h>
30 #include <Library/CpuLib.h>
31 #include <Library/BaseMemoryLib.h>
32 #include <Library/MemoryAllocationLib.h>
33 #include <Library/DebugLib.h>
34 #include <Library/MtrrLib.h>
35 #include <Library/LocalApicLib.h>
36 #include <Library/UefiCpuLib.h>
37 #include <Library/UefiLib.h>
38 #include <Library/CpuExceptionHandlerLib.h>
39 #include <Library/HobLib.h>
40 #include <Library/ReportStatusCodeLib.h>
41 #include <Library/MpInitLib.h>
42 #include <Library/TimerLib.h>
44 #include <Guid/IdleLoopEvent.h>
45 #include <Guid/VectorHandoffTable.h>
47 #define EFI_MEMORY_CACHETYPE_MASK (EFI_MEMORY_UC | \
56 Flush CPU data cache. If the instruction cache is fully coherent
57 with all DMA operations then function can just return EFI_SUCCESS.
59 @param This Protocol instance structure
60 @param Start Physical address to start flushing from.
61 @param Length Number of bytes to flush. Round up to chipset
63 @param FlushType Specifies the type of flush operation to perform.
65 @retval EFI_SUCCESS If cache was flushed
66 @retval EFI_UNSUPPORTED If flush type is not supported.
67 @retval EFI_DEVICE_ERROR If requested range could not be flushed.
72 CpuFlushCpuDataCache (
73 IN EFI_CPU_ARCH_PROTOCOL
*This
,
74 IN EFI_PHYSICAL_ADDRESS Start
,
76 IN EFI_CPU_FLUSH_TYPE FlushType
80 Enables CPU interrupts.
82 @param This Protocol instance structure
84 @retval EFI_SUCCESS If interrupts were enabled in the CPU
85 @retval EFI_DEVICE_ERROR If interrupts could not be enabled on the CPU.
91 IN EFI_CPU_ARCH_PROTOCOL
*This
95 Disables CPU interrupts.
97 @param This Protocol instance structure
99 @retval EFI_SUCCESS If interrupts were disabled in the CPU.
100 @retval EFI_DEVICE_ERROR If interrupts could not be disabled on the CPU.
105 CpuDisableInterrupt (
106 IN EFI_CPU_ARCH_PROTOCOL
*This
110 Return the state of interrupts.
112 @param This Protocol instance structure
113 @param State Pointer to the CPU's current interrupt state
115 @retval EFI_SUCCESS If interrupts were disabled in the CPU.
116 @retval EFI_INVALID_PARAMETER State is NULL.
121 CpuGetInterruptState (
122 IN EFI_CPU_ARCH_PROTOCOL
*This
,
127 Generates an INIT to the CPU.
129 @param This Protocol instance structure
130 @param InitType Type of CPU INIT to perform
132 @retval EFI_SUCCESS If CPU INIT occurred. This value should never be
134 @retval EFI_DEVICE_ERROR If CPU INIT failed.
135 @retval EFI_UNSUPPORTED Requested type of CPU INIT not supported.
141 IN EFI_CPU_ARCH_PROTOCOL
*This
,
142 IN EFI_CPU_INIT_TYPE InitType
146 Registers a function to be called from the CPU interrupt handler.
148 @param This Protocol instance structure
149 @param InterruptType Defines which interrupt to hook. IA-32
150 valid range is 0x00 through 0xFF
151 @param InterruptHandler A pointer to a function of type
152 EFI_CPU_INTERRUPT_HANDLER that is called
153 when a processor interrupt occurs. A null
154 pointer is an error condition.
156 @retval EFI_SUCCESS If handler installed or uninstalled.
157 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler
158 for InterruptType was previously installed.
159 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for
160 InterruptType was not previously installed.
161 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType
167 CpuRegisterInterruptHandler (
168 IN EFI_CPU_ARCH_PROTOCOL
*This
,
169 IN EFI_EXCEPTION_TYPE InterruptType
,
170 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
174 Returns a timer value from one of the CPU's internal timers. There is no
175 inherent time interval between ticks but is a function of the CPU frequency.
177 @param This - Protocol instance structure.
178 @param TimerIndex - Specifies which CPU timer is requested.
179 @param TimerValue - Pointer to the returned timer value.
180 @param TimerPeriod - A pointer to the amount of time that passes
181 in femtoseconds (10-15) for each increment
182 of TimerValue. If TimerValue does not
183 increment at a predictable rate, then 0 is
184 returned. The amount of time that has
185 passed between two calls to GetTimerValue()
186 can be calculated with the formula
187 (TimerValue2 - TimerValue1) * TimerPeriod.
188 This parameter is optional and may be NULL.
190 @retval EFI_SUCCESS - If the CPU timer count was returned.
191 @retval EFI_UNSUPPORTED - If the CPU does not have any readable timers.
192 @retval EFI_DEVICE_ERROR - If an error occurred while reading the timer.
193 @retval EFI_INVALID_PARAMETER - TimerIndex is not valid or TimerValue is NULL.
199 IN EFI_CPU_ARCH_PROTOCOL
*This
,
200 IN UINT32 TimerIndex
,
201 OUT UINT64
*TimerValue
,
202 OUT UINT64
*TimerPeriod OPTIONAL
206 Set memory cacheability attributes for given range of memeory.
208 @param This Protocol instance structure
209 @param BaseAddress Specifies the start address of the
211 @param Length Specifies the length of the memory range
212 @param Attributes The memory cacheability for the memory range
214 @retval EFI_SUCCESS If the cacheability of that memory range is
216 @retval EFI_UNSUPPORTED If the desired operation cannot be done
217 @retval EFI_INVALID_PARAMETER The input parameter is not correct,
223 CpuSetMemoryAttributes (
224 IN EFI_CPU_ARCH_PROTOCOL
*This
,
225 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
231 Initialize Global Descriptor Table.
235 InitGlobalDescriptorTable (
240 Sets the code selector (CS).
242 @param Selector Value of code selector.
252 Sets the data selector (DS).
254 @param Selector Value of data selector.