3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
4 Copyright (c) 2011, ARM Limited. All rights reserved.
6 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #include <Guid/IdleLoopEvent.h>
14 BOOLEAN mIsFlushingGCD
;
17 This function flushes the range of addresses from Start to Start+Length
18 from the processor's data cache. If Start is not aligned to a cache line
19 boundary, then the bytes before Start to the preceding cache line boundary
20 are also flushed. If Start+Length is not aligned to a cache line boundary,
21 then the bytes past Start+Length to the end of the next cache line boundary
22 are also flushed. The FlushType of EfiCpuFlushTypeWriteBackInvalidate must be
23 supported. If the data cache is fully coherent with all DMA operations, then
24 this function can just return EFI_SUCCESS. If the processor does not support
25 flushing a range of the data cache, then the entire data cache can be flushed.
27 @param This The EFI_CPU_ARCH_PROTOCOL instance.
28 @param Start The beginning physical address to flush from the processor's data
30 @param Length The number of bytes to flush from the processor's data cache. This
31 function may flush more bytes than Length specifies depending upon
32 the granularity of the flush operation that the processor supports.
33 @param FlushType Specifies the type of flush operation to perform.
35 @retval EFI_SUCCESS The address range from Start to Start+Length was flushed from
36 the processor's data cache.
37 @retval EFI_UNSUPPORTED The processor does not support the cache flush type specified
39 @retval EFI_DEVICE_ERROR The address range from Start to Start+Length could not be flushed
40 from the processor's data cache.
45 CpuFlushCpuDataCache (
46 IN EFI_CPU_ARCH_PROTOCOL
*This
,
47 IN EFI_PHYSICAL_ADDRESS Start
,
49 IN EFI_CPU_FLUSH_TYPE FlushType
53 case EfiCpuFlushTypeWriteBack
:
54 WriteBackDataCacheRange ((VOID
*)(UINTN
)Start
, (UINTN
)Length
);
56 case EfiCpuFlushTypeInvalidate
:
57 InvalidateDataCacheRange ((VOID
*)(UINTN
)Start
, (UINTN
)Length
);
59 case EfiCpuFlushTypeWriteBackInvalidate
:
60 WriteBackInvalidateDataCacheRange ((VOID
*)(UINTN
)Start
, (UINTN
)Length
);
63 return EFI_INVALID_PARAMETER
;
70 This function enables interrupt processing by the processor.
72 @param This The EFI_CPU_ARCH_PROTOCOL instance.
74 @retval EFI_SUCCESS Interrupts are enabled on the processor.
75 @retval EFI_DEVICE_ERROR Interrupts could not be enabled on the processor.
81 IN EFI_CPU_ARCH_PROTOCOL
*This
84 ArmEnableInterrupts ();
90 This function disables interrupt processing by the processor.
92 @param This The EFI_CPU_ARCH_PROTOCOL instance.
94 @retval EFI_SUCCESS Interrupts are disabled on the processor.
95 @retval EFI_DEVICE_ERROR Interrupts could not be disabled on the processor.
100 CpuDisableInterrupt (
101 IN EFI_CPU_ARCH_PROTOCOL
*This
104 ArmDisableInterrupts ();
110 This function retrieves the processor's current interrupt state a returns it in
111 State. If interrupts are currently enabled, then TRUE is returned. If interrupts
112 are currently disabled, then FALSE is returned.
114 @param This The EFI_CPU_ARCH_PROTOCOL instance.
115 @param State A pointer to the processor's current interrupt state. Set to TRUE if
116 interrupts are enabled and FALSE if interrupts are disabled.
118 @retval EFI_SUCCESS The processor's current interrupt state was returned in State.
119 @retval EFI_INVALID_PARAMETER State is NULL.
124 CpuGetInterruptState (
125 IN EFI_CPU_ARCH_PROTOCOL
*This
,
130 return EFI_INVALID_PARAMETER
;
133 *State
= ArmGetInterruptState ();
138 This function generates an INIT on the processor. If this function succeeds, then the
139 processor will be reset, and control will not be returned to the caller. If InitType is
140 not supported by this processor, or the processor cannot programmatically generate an
141 INIT without help from external hardware, then EFI_UNSUPPORTED is returned. If an error
142 occurs attempting to generate an INIT, then EFI_DEVICE_ERROR is returned.
144 @param This The EFI_CPU_ARCH_PROTOCOL instance.
145 @param InitType The type of processor INIT to perform.
147 @retval EFI_SUCCESS The processor INIT was performed. This return code should never be seen.
148 @retval EFI_UNSUPPORTED The processor INIT operation specified by InitType is not supported
150 @retval EFI_DEVICE_ERROR The processor INIT failed.
156 IN EFI_CPU_ARCH_PROTOCOL
*This
,
157 IN EFI_CPU_INIT_TYPE InitType
160 return EFI_UNSUPPORTED
;
165 CpuRegisterInterruptHandler (
166 IN EFI_CPU_ARCH_PROTOCOL
*This
,
167 IN EFI_EXCEPTION_TYPE InterruptType
,
168 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
171 return RegisterInterruptHandler (InterruptType
, InterruptHandler
);
177 IN EFI_CPU_ARCH_PROTOCOL
*This
,
178 IN UINT32 TimerIndex
,
179 OUT UINT64
*TimerValue
,
180 OUT UINT64
*TimerPeriod OPTIONAL
183 return EFI_UNSUPPORTED
;
187 Callback function for idle events.
189 @param Event Event whose notification function is being invoked.
190 @param Context The pointer to the notification function's context,
191 which is implementation-dependent.
196 IdleLoopEventCallback (
205 // Globals used to initialize the protocol
207 EFI_HANDLE mCpuHandle
= NULL
;
208 EFI_CPU_ARCH_PROTOCOL mCpu
= {
209 CpuFlushCpuDataCache
,
212 CpuGetInterruptState
,
214 CpuRegisterInterruptHandler
,
216 CpuSetMemoryAttributes
,
218 2048, // DmaBufferAlignment
224 IN OUT EFI_CPU_ARCH_PROTOCOL
*CpuArchProtocol
227 CpuArchProtocol
->DmaBufferAlignment
= ArmCacheWritebackGranule ();
232 IN EFI_HANDLE ImageHandle
,
233 IN EFI_SYSTEM_TABLE
*SystemTable
237 EFI_EVENT IdleLoopEvent
;
239 InitializeExceptions (&mCpu
);
241 InitializeDma (&mCpu
);
243 Status
= gBS
->InstallMultipleProtocolInterfaces (
245 &gEfiCpuArchProtocolGuid
,
251 // Make sure GCD and MMU settings match. This API calls gDS->SetMemorySpaceAttributes ()
252 // and that calls EFI_CPU_ARCH_PROTOCOL.SetMemoryAttributes, so this code needs to go
253 // after the protocol is installed
255 mIsFlushingGCD
= TRUE
;
256 SyncCacheConfig (&mCpu
);
257 mIsFlushingGCD
= FALSE
;
260 // Setup a callback for idle events
262 Status
= gBS
->CreateEventEx (
265 IdleLoopEventCallback
,
270 ASSERT_EFI_ERROR (Status
);