4 Copyright (c) 2008 - 2011, 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>
22 #include <Library/UefiDriverEntryPoint.h>
23 #include <Library/UefiBootServicesTableLib.h>
24 #include <Library/DxeServicesTableLib.h>
25 #include <Library/BaseLib.h>
26 #include <Library/CpuLib.h>
27 #include <Library/BaseMemoryLib.h>
28 #include <Library/MemoryAllocationLib.h>
29 #include <Library/DebugLib.h>
30 #include <Library/MtrrLib.h>
31 #include <Guid/IdleLoopEvent.h>
36 #define INTERRUPT_VECTOR_NUMBER 256
38 #define EFI_MEMORY_CACHETYPE_MASK (EFI_MEMORY_UC | \
47 Flush CPU data cache. If the instruction cache is fully coherent
48 with all DMA operations then function can just return EFI_SUCCESS.
50 @param This Protocol instance structure
51 @param Start Physical address to start flushing from.
52 @param Length Number of bytes to flush. Round up to chipset
54 @param FlushType Specifies the type of flush operation to perform.
56 @retval EFI_SUCCESS If cache was flushed
57 @retval EFI_UNSUPPORTED If flush type is not supported.
58 @retval EFI_DEVICE_ERROR If requested range could not be flushed.
63 CpuFlushCpuDataCache (
64 IN EFI_CPU_ARCH_PROTOCOL
*This
,
65 IN EFI_PHYSICAL_ADDRESS Start
,
67 IN EFI_CPU_FLUSH_TYPE FlushType
71 Enables CPU interrupts.
73 @param This Protocol instance structure
75 @retval EFI_SUCCESS If interrupts were enabled in the CPU
76 @retval EFI_DEVICE_ERROR If interrupts could not be enabled on the CPU.
82 IN EFI_CPU_ARCH_PROTOCOL
*This
86 Disables CPU interrupts.
88 @param This Protocol instance structure
90 @retval EFI_SUCCESS If interrupts were disabled in the CPU.
91 @retval EFI_DEVICE_ERROR If interrupts could not be disabled on the CPU.
97 IN EFI_CPU_ARCH_PROTOCOL
*This
101 Return the state of interrupts.
103 @param This Protocol instance structure
104 @param State Pointer to the CPU's current interrupt state
106 @retval EFI_SUCCESS If interrupts were disabled in the CPU.
107 @retval EFI_INVALID_PARAMETER State is NULL.
112 CpuGetInterruptState (
113 IN EFI_CPU_ARCH_PROTOCOL
*This
,
118 Generates an INIT to the CPU.
120 @param This Protocol instance structure
121 @param InitType Type of CPU INIT to perform
123 @retval EFI_SUCCESS If CPU INIT occurred. This value should never be
125 @retval EFI_DEVICE_ERROR If CPU INIT failed.
126 @retval EFI_UNSUPPORTED Requested type of CPU INIT not supported.
132 IN EFI_CPU_ARCH_PROTOCOL
*This
,
133 IN EFI_CPU_INIT_TYPE InitType
137 Registers a function to be called from the CPU interrupt handler.
139 @param This Protocol instance structure
140 @param InterruptType Defines which interrupt to hook. IA-32
141 valid range is 0x00 through 0xFF
142 @param InterruptHandler A pointer to a function of type
143 EFI_CPU_INTERRUPT_HANDLER that is called
144 when a processor interrupt occurs. A null
145 pointer is an error condition.
147 @retval EFI_SUCCESS If handler installed or uninstalled.
148 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler
149 for InterruptType was previously installed.
150 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for
151 InterruptType was not previously installed.
152 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType
158 CpuRegisterInterruptHandler (
159 IN EFI_CPU_ARCH_PROTOCOL
*This
,
160 IN EFI_EXCEPTION_TYPE InterruptType
,
161 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
165 Returns a timer value from one of the CPU's internal timers. There is no
166 inherent time interval between ticks but is a function of the CPU frequency.
168 @param This - Protocol instance structure.
169 @param TimerIndex - Specifies which CPU timer is requested.
170 @param TimerValue - Pointer to the returned timer value.
171 @param TimerPeriod - A pointer to the amount of time that passes
172 in femtoseconds (10-15) for each increment
173 of TimerValue. If TimerValue does not
174 increment at a predictable rate, then 0 is
175 returned. The amount of time that has
176 passed between two calls to GetTimerValue()
177 can be calculated with the formula
178 (TimerValue2 - TimerValue1) * TimerPeriod.
179 This parameter is optional and may be NULL.
181 @retval EFI_SUCCESS - If the CPU timer count was returned.
182 @retval EFI_UNSUPPORTED - If the CPU does not have any readable timers.
183 @retval EFI_DEVICE_ERROR - If an error occurred while reading the timer.
184 @retval EFI_INVALID_PARAMETER - TimerIndex is not valid or TimerValue is NULL.
190 IN EFI_CPU_ARCH_PROTOCOL
*This
,
191 IN UINT32 TimerIndex
,
192 OUT UINT64
*TimerValue
,
193 OUT UINT64
*TimerPeriod OPTIONAL
197 Set memory cacheability attributes for given range of memeory.
199 @param This Protocol instance structure
200 @param BaseAddress Specifies the start address of the
202 @param Length Specifies the length of the memory range
203 @param Attributes The memory cacheability for the memory range
205 @retval EFI_SUCCESS If the cacheability of that memory range is
207 @retval EFI_UNSUPPORTED If the desired operation cannot be done
208 @retval EFI_INVALID_PARAMETER The input parameter is not correct,
214 CpuSetMemoryAttributes (
215 IN EFI_CPU_ARCH_PROTOCOL
*This
,
216 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
222 Label of base address of IDT vector 0.
224 This is just a label of base address of IDT vector 0.
234 Initializes the pointer to the external interrupt vector table.
236 @param VectorTable Address of the external interrupt vector table.
241 InitializeExternalVectorTablePtr (
242 EFI_CPU_INTERRUPT_HANDLER
*VectorTable
246 Initialize Global Descriptor Table.
250 InitGlobalDescriptorTable (
255 Sets the code selector (CS).
257 @param Selector Value of code selector.
267 Sets the data selector (DS).
269 @param Selector Value of data selector.
279 Restore original Interrupt Descriptor Table Handler Address.
281 @param Index The Index of the interrupt descriptor table handle.
285 RestoreInterruptDescriptorTableHandlerAddress (