VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/UefiCpuPkg/CpuDxe/LoongArch64/CpuDxe.h@ 108794

Last change on this file since 108794 was 108794, checked in by vboxsync, 2 weeks ago

Devices/EFI/FirmwareNew: Merge edk2-stable202502 from the vendor branch and make it build for the important platforms, bugref:4643

  • Property svn:eol-style set to native
File size: 11.1 KB
Line 
1/** @file CpuDxe.c
2
3 CPU DXE Module to produce CPU ARCH Protocol.
4
5 Copyright (c) 2024, Loongson Technology Corporation Limited. All rights reserved.<BR>
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8**/
9
10#ifndef CPU_DXE_H_
11#define CPU_DXE_H_
12
13#include <Uefi.h>
14#include <Library/BaseMemoryLib.h>
15#include <Library/CacheMaintenanceLib.h>
16#include <Library/CpuLib.h>
17#include <Library/DebugLib.h>
18#include <Library/DxeServicesTableLib.h>
19#include <Library/MpInitLib.h>
20#include <Library/PcdLib.h>
21#include <Library/PeCoffGetEntryPointLib.h>
22#include <Library/UefiBootServicesTableLib.h>
23#include <Library/UefiLib.h>
24
25#include <Guid/DebugImageInfoTable.h>
26#include <Protocol/Cpu.h>
27#include <Protocol/DebugSupport.h>
28#include <Protocol/LoadedImage.h>
29
30/*
31 This function flushes the range of addresses from Start to Start+Length
32 from the processor's data cache. If Start is not aligned to a cache line
33 boundary, then the bytes before Start to the preceding cache line boundary
34 are also flushed. If Start+Length is not aligned to a cache line boundary,
35 then the bytes past Start+Length to the end of the next cache line boundary
36 are also flushed. The FlushType of EfiCpuFlushTypeWriteBackInvalidate must be
37 supported. If the data cache is fully coherent with all DMA operations, then
38 this function can just return EFI_SUCCESS. If the processor does not support
39 flushing a range of the data cache, then the entire data cache can be flushed.
40
41 @param This The EFI_CPU_ARCH_PROTOCOL instance.
42 @param Start The beginning physical address to flush from the processor's data
43 cache.
44 @param Length The number of bytes to flush from the processor's data cache. This
45 function may flush more bytes than Length specifies depending upon
46 the granularity of the flush operation that the processor supports.
47 @param FlushType Specifies the type of flush operation to perform.
48
49 @retval EFI_SUCCESS The address range from Start to Start+Length was flushed from
50 the processor's data cache.
51 @retval EFI_UNSUPPORTEDT The processor does not support the cache flush type specified
52 by FlushType.
53 @retval EFI_DEVICE_ERROR The address range from Start to Start+Length could not be flushed
54 from the processor's data cache.
55
56**/
57EFI_STATUS
58EFIAPI
59CpuFlushCpuDataCache (
60 IN EFI_CPU_ARCH_PROTOCOL *This,
61 IN EFI_PHYSICAL_ADDRESS Start,
62 IN UINT64 Length,
63 IN EFI_CPU_FLUSH_TYPE FlushType
64 );
65
66/**
67 This function enables interrupt processing by the processor.
68
69 @param This The EFI_CPU_ARCH_PROTOCOL instance.
70
71 @retval EFI_SUCCESS Interrupts are enabled on the processor.
72 @retval EFI_DEVICE_ERROR Interrupts could not be enabled on the processor.
73
74**/
75EFI_STATUS
76EFIAPI
77CpuEnableInterrupt (
78 IN EFI_CPU_ARCH_PROTOCOL *This
79 );
80
81/**
82 This function disables interrupt processing by the processor.
83
84 @param This The EFI_CPU_ARCH_PROTOCOL instance.
85
86 @retval EFI_SUCCESS Interrupts are disabled on the processor.
87 @retval EFI_DEVICE_ERROR Interrupts could not be disabled on the processor.
88
89**/
90EFI_STATUS
91EFIAPI
92CpuDisableInterrupt (
93 IN EFI_CPU_ARCH_PROTOCOL *This
94 );
95
96/**
97 This function retrieves the processor's current interrupt state a returns it in
98 State. If interrupts are currently enabled, then TRUE is returned. If interrupts
99 are currently disabled, then FALSE is returned.
100
101 @param This The EFI_CPU_ARCH_PROTOCOL instance.
102 @param State A pointer to the processor's current interrupt state. Set to TRUE if
103 interrupts are enabled and FALSE if interrupts are disabled.
104
105 @retval EFI_SUCCESS The processor's current interrupt state was returned in State.
106 @retval EFI_INVALID_PARAMETER State is NULL.
107
108**/
109EFI_STATUS
110EFIAPI
111CpuGetInterruptState (
112 IN EFI_CPU_ARCH_PROTOCOL *This,
113 OUT BOOLEAN *State
114 );
115
116/**
117 This function generates an INIT on the processor. If this function succeeds, then the
118 processor will be reset, and control will not be returned to the caller. If InitType is
119 not supported by this processor, or the processor cannot programmatically generate an
120 INIT without help from external hardware, then EFI_UNSUPPORTED is returned. If an error
121 occurs attempting to generate an INIT, then EFI_DEVICE_ERROR is returned.
122
123 @param This The EFI_CPU_ARCH_PROTOCOL instance.
124 @param InitType The type of processor INIT to perform.
125
126 @retval EFI_SUCCESS The processor INIT was performed. This return code should never be seen.
127 @retval EFI_UNSUPPORTED The processor INIT operation specified by InitType is not supported
128 by this processor.
129 @retval EFI_DEVICE_ERROR The processor INIT failed.
130
131**/
132EFI_STATUS
133EFIAPI
134CpuInit (
135 IN EFI_CPU_ARCH_PROTOCOL *This,
136 IN EFI_CPU_INIT_TYPE InitType
137 );
138
139/**
140 Registers a function to be called from the CPU interrupt handler.
141
142 @param This Protocol instance structure
143 @param InterruptType Defines which interrupt to hook. IA-32
144 valid range is 0x00 through 0xFF
145 @param InterruptHandler A pointer to a function of type
146 EFI_CPU_INTERRUPT_HANDLER that is called
147 when a processor interrupt occurs. A null
148 pointer is an error condition.
149
150 @retval EFI_SUCCESS If handler installed or uninstalled.
151 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler
152 for InterruptType was previously installed.
153 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for
154 InterruptType was not previously installed.
155 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType
156 is not supported.
157
158**/
159EFI_STATUS
160EFIAPI
161CpuRegisterInterruptHandler (
162 IN EFI_CPU_ARCH_PROTOCOL *This,
163 IN EFI_EXCEPTION_TYPE InterruptType,
164 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
165 );
166
167/**
168 Returns a timer value from one of the CPU's internal timers. There is no
169 inherent time interval between ticks but is a function of the CPU frequency.
170
171 @param This - Protocol instance structure.
172 @param TimerIndex - Specifies which CPU timer is requested.
173 @param TimerValue - Pointer to the returned timer value.
174 @param TimerPeriod - A pointer to the amount of time that passes
175 in femtoseconds (10-15) for each increment
176 of TimerValue. If TimerValue does not
177 increment at a predictable rate, then 0 is
178 returned. The amount of time that has
179 passed between two calls to GetTimerValue()
180 can be calculated with the formula
181 (TimerValue2 - TimerValue1) * TimerPeriod.
182 This parameter is optional and may be NULL.
183
184 @retval EFI_SUCCESS - If the CPU timer count was returned.
185 @retval EFI_UNSUPPORTED - If the CPU does not have any readable timers.
186 @retval EFI_DEVICE_ERROR - If an error occurred while reading the timer.
187 @retval EFI_INVALID_PARAMETER - TimerIndex is not valid or TimerValue is NULL.
188
189**/
190EFI_STATUS
191EFIAPI
192CpuGetTimerValue (
193 IN EFI_CPU_ARCH_PROTOCOL *This,
194 IN UINT32 TimerIndex,
195 OUT UINT64 *TimerValue,
196 OUT UINT64 *TimerPeriod OPTIONAL
197 );
198
199/**
200 This function registers and enables the handler specified by InterruptHandler for a processor
201 interrupt or exception type specified by InterruptType. If InterruptHandler is NULL, then the
202 handler for the processor interrupt or exception type specified by InterruptType is uninstalled.
203 The installed handler is called once for each processor interrupt or exception.
204
205 @param InterruptType A pointer to the processor's current interrupt state. Set to TRUE if interrupts
206 are enabled and FALSE if interrupts are disabled.
207 @param InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called
208 when a processor interrupt occurs. If this parameter is NULL, then the handler
209 will be uninstalled.
210
211 @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.
212 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was
213 previously installed.
214 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not
215 previously installed.
216 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported.
217
218**/
219EFI_STATUS
220RegisterInterruptHandler (
221 IN EFI_EXCEPTION_TYPE InterruptType,
222 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
223 );
224
225/**
226 This function modifies the attributes for the memory region specified by BaseAddress and
227 Length from their current attributes to the attributes specified by Attributes.
228
229 @param This The EFI_CPU_ARCH_PROTOCOL instance.
230 @param BaseAddress The physical address that is the start address of a memory region.
231 @param Length The size in bytes of the memory region.
232 @param Attributes The bit mask of attributes to set for the memory region.
233
234 @retval EFI_SUCCESS The attributes were set for the memory region.
235 @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by
236 BaseAddress and Length cannot be modified.
237 @retval EFI_INVALID_PARAMETER Length is zero.
238 @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of
239 the memory resource range.
240 @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory
241 resource range specified by BaseAddress and Length.
242 The bit mask of attributes is not support for the memory resource
243 range specified by BaseAddress and Length.
244
245**/
246EFI_STATUS
247EFIAPI
248CpuSetMemoryAttributes (
249 IN EFI_CPU_ARCH_PROTOCOL *This,
250 IN EFI_PHYSICAL_ADDRESS BaseAddress,
251 IN UINT64 Length,
252 IN UINT64 Attributes
253 );
254
255/**
256 Initialize interrupt handling for DXE phase.
257
258 @param Cpu A pointer of EFI_CPU_ARCH_PROTOCOL instance.
259
260 @return VOID.
261
262**/
263VOID
264InitializeExceptions (
265 IN EFI_CPU_ARCH_PROTOCOL *gCpu
266 );
267
268/**
269 Converts EFI Attributes to corresponding architecture Attributes.
270
271 @param[in] EfiAttributes Efi Attributes.
272
273 @retval Corresponding architecture attributes.
274**/
275UINTN
276EFIAPI
277EfiAttributeConverse (
278 IN UINTN EfiAttributes
279 );
280
281#endif // CPU_DXE_H_
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette