]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Include/Protocol/Cpu.h
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Include / Protocol / Cpu.h
CommitLineData
d1f95000 1/** @file\r
4ca9b6c4 2 CPU Architectural Protocol as defined in PI spec Volume 2 DXE\r
d1f95000 3\r
4 This code abstracts the DXE core from processor implementation details.\r
5\r
9095d37b 6 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
9344f092 7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
d1f95000 8\r
d1f95000 9**/\r
10\r
11#ifndef __ARCH_PROTOCOL_CPU_H__\r
12#define __ARCH_PROTOCOL_CPU_H__\r
13\r
14#include <Protocol/DebugSupport.h>\r
15\r
16#define EFI_CPU_ARCH_PROTOCOL_GUID \\r
17 { 0x26baccb1, 0x6f42, 0x11d4, {0xbc, 0xe7, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } }\r
18\r
19typedef struct _EFI_CPU_ARCH_PROTOCOL EFI_CPU_ARCH_PROTOCOL;\r
20\r
9319d2c2
LG
21///\r
22/// The type of flush operation\r
23///\r
d1f95000 24typedef enum {\r
25 EfiCpuFlushTypeWriteBackInvalidate,\r
26 EfiCpuFlushTypeWriteBack,\r
27 EfiCpuFlushTypeInvalidate,\r
28 EfiCpuMaxFlushType\r
29} EFI_CPU_FLUSH_TYPE;\r
30\r
9319d2c2
LG
31///\r
32/// The type of processor INIT.\r
33///\r
d1f95000 34typedef enum {\r
35 EfiCpuInit,\r
36 EfiCpuMaxInitType\r
37} EFI_CPU_INIT_TYPE;\r
38\r
39/**\r
40 EFI_CPU_INTERRUPT_HANDLER that is called when a processor interrupt occurs.\r
41\r
42 @param InterruptType Defines the type of interrupt or exception that\r
43 occurred on the processor.This parameter is processor architecture specific.\r
44 @param SystemContext A pointer to the processor context when\r
45 the interrupt occurred on the processor.\r
46\r
47 @return None\r
48\r
49**/\r
50typedef\r
51VOID\r
8b13229b 52(EFIAPI *EFI_CPU_INTERRUPT_HANDLER)(\r
d1f95000 53 IN CONST EFI_EXCEPTION_TYPE InterruptType,\r
54 IN CONST EFI_SYSTEM_CONTEXT SystemContext\r
55 );\r
56\r
57/**\r
9095d37b
LG
58 This function flushes the range of addresses from Start to Start+Length\r
59 from the processor's data cache. If Start is not aligned to a cache line\r
60 boundary, then the bytes before Start to the preceding cache line boundary\r
61 are also flushed. If Start+Length is not aligned to a cache line boundary,\r
62 then the bytes past Start+Length to the end of the next cache line boundary\r
63 are also flushed. The FlushType of EfiCpuFlushTypeWriteBackInvalidate must be\r
64 supported. If the data cache is fully coherent with all DMA operations, then\r
65 this function can just return EFI_SUCCESS. If the processor does not support\r
d1f95000 66 flushing a range of the data cache, then the entire data cache can be flushed.\r
67\r
68 @param This The EFI_CPU_ARCH_PROTOCOL instance.\r
69 @param Start The beginning physical address to flush from the processor's data\r
70 cache.\r
71 @param Length The number of bytes to flush from the processor's data cache. This\r
72 function may flush more bytes than Length specifies depending upon\r
73 the granularity of the flush operation that the processor supports.\r
74 @param FlushType Specifies the type of flush operation to perform.\r
75\r
76 @retval EFI_SUCCESS The address range from Start to Start+Length was flushed from\r
77 the processor's data cache.\r
b88df761 78 @retval EFI_UNSUPPORTED The processor does not support the cache flush type specified\r
d1f95000 79 by FlushType.\r
80 @retval EFI_DEVICE_ERROR The address range from Start to Start+Length could not be flushed\r
81 from the processor's data cache.\r
82\r
83**/\r
84typedef\r
85EFI_STATUS\r
8b13229b 86(EFIAPI *EFI_CPU_FLUSH_DATA_CACHE)(\r
d1f95000 87 IN EFI_CPU_ARCH_PROTOCOL *This,\r
88 IN EFI_PHYSICAL_ADDRESS Start,\r
89 IN UINT64 Length,\r
90 IN EFI_CPU_FLUSH_TYPE FlushType\r
91 );\r
92\r
93\r
94/**\r
9095d37b 95 This function enables interrupt processing by the processor.\r
d1f95000 96\r
97 @param This The EFI_CPU_ARCH_PROTOCOL instance.\r
98\r
99 @retval EFI_SUCCESS Interrupts are enabled on the processor.\r
100 @retval EFI_DEVICE_ERROR Interrupts could not be enabled on the processor.\r
101\r
102**/\r
103typedef\r
104EFI_STATUS\r
8b13229b 105(EFIAPI *EFI_CPU_ENABLE_INTERRUPT)(\r
d1f95000 106 IN EFI_CPU_ARCH_PROTOCOL *This\r
107 );\r
108\r
109\r
110/**\r
111 This function disables interrupt processing by the processor.\r
112\r
113 @param This The EFI_CPU_ARCH_PROTOCOL instance.\r
114\r
115 @retval EFI_SUCCESS Interrupts are disabled on the processor.\r
116 @retval EFI_DEVICE_ERROR Interrupts could not be disabled on the processor.\r
117\r
118**/\r
119typedef\r
120EFI_STATUS\r
8b13229b 121(EFIAPI *EFI_CPU_DISABLE_INTERRUPT)(\r
d1f95000 122 IN EFI_CPU_ARCH_PROTOCOL *This\r
123 );\r
124\r
125\r
126/**\r
9095d37b
LG
127 This function retrieves the processor's current interrupt state a returns it in\r
128 State. If interrupts are currently enabled, then TRUE is returned. If interrupts\r
d1f95000 129 are currently disabled, then FALSE is returned.\r
130\r
131 @param This The EFI_CPU_ARCH_PROTOCOL instance.\r
132 @param State A pointer to the processor's current interrupt state. Set to TRUE if\r
133 interrupts are enabled and FALSE if interrupts are disabled.\r
134\r
135 @retval EFI_SUCCESS The processor's current interrupt state was returned in State.\r
136 @retval EFI_INVALID_PARAMETER State is NULL.\r
137\r
138**/\r
139typedef\r
140EFI_STATUS\r
8b13229b 141(EFIAPI *EFI_CPU_GET_INTERRUPT_STATE)(\r
d1f95000 142 IN EFI_CPU_ARCH_PROTOCOL *This,\r
143 OUT BOOLEAN *State\r
144 );\r
145\r
146\r
147/**\r
148 This function generates an INIT on the processor. If this function succeeds, then the\r
9095d37b
LG
149 processor will be reset, and control will not be returned to the caller. If InitType is\r
150 not supported by this processor, or the processor cannot programmatically generate an\r
151 INIT without help from external hardware, then EFI_UNSUPPORTED is returned. If an error\r
d1f95000 152 occurs attempting to generate an INIT, then EFI_DEVICE_ERROR is returned.\r
153\r
154 @param This The EFI_CPU_ARCH_PROTOCOL instance.\r
155 @param InitType The type of processor INIT to perform.\r
156\r
157 @retval EFI_SUCCESS The processor INIT was performed. This return code should never be seen.\r
158 @retval EFI_UNSUPPORTED The processor INIT operation specified by InitType is not supported\r
159 by this processor.\r
160 @retval EFI_DEVICE_ERROR The processor INIT failed.\r
161\r
162**/\r
163typedef\r
164EFI_STATUS\r
8b13229b 165(EFIAPI *EFI_CPU_INIT)(\r
d1f95000 166 IN EFI_CPU_ARCH_PROTOCOL *This,\r
167 IN EFI_CPU_INIT_TYPE InitType\r
168 );\r
169\r
170\r
171/**\r
9095d37b
LG
172 This function registers and enables the handler specified by InterruptHandler for a processor\r
173 interrupt or exception type specified by InterruptType. If InterruptHandler is NULL, then the\r
174 handler for the processor interrupt or exception type specified by InterruptType is uninstalled.\r
d1f95000 175 The installed handler is called once for each processor interrupt or exception.\r
176\r
177 @param This The EFI_CPU_ARCH_PROTOCOL instance.\r
178 @param InterruptType A pointer to the processor's current interrupt state. Set to TRUE if interrupts\r
179 are enabled and FALSE if interrupts are disabled.\r
180 @param InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called\r
181 when a processor interrupt occurs. If this parameter is NULL, then the handler\r
182 will be uninstalled.\r
183\r
184 @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.\r
185 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was\r
186 previously installed.\r
187 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not\r
188 previously installed.\r
189 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported.\r
190\r
191**/\r
192typedef\r
193EFI_STATUS\r
8b13229b 194(EFIAPI *EFI_CPU_REGISTER_INTERRUPT_HANDLER)(\r
d1f95000 195 IN EFI_CPU_ARCH_PROTOCOL *This,\r
196 IN EFI_EXCEPTION_TYPE InterruptType,\r
197 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler\r
198 );\r
199\r
200\r
201/**\r
202 This function reads the processor timer specified by TimerIndex and returns it in TimerValue.\r
203\r
204 @param This The EFI_CPU_ARCH_PROTOCOL instance.\r
205 @param TimerIndex Specifies which processor timer is to be returned in TimerValue. This parameter\r
206 must be between 0 and NumberOfTimers-1.\r
207 @param TimerValue Pointer to the returned timer value.\r
208 @param TimerPeriod A pointer to the amount of time that passes in femtoseconds for each increment\r
f1004231
LG
209 of TimerValue. If TimerValue does not increment at a predictable rate, then 0 is\r
210 returned. This parameter is optional and may be NULL.\r
d1f95000 211\r
212 @retval EFI_SUCCESS The processor timer value specified by TimerIndex was returned in TimerValue.\r
213 @retval EFI_DEVICE_ERROR An error occurred attempting to read one of the processor's timers.\r
214 @retval EFI_INVALID_PARAMETER TimerValue is NULL or TimerIndex is not valid.\r
215 @retval EFI_UNSUPPORTED The processor does not have any readable timers.\r
216\r
217**/\r
218typedef\r
219EFI_STATUS\r
8b13229b 220(EFIAPI *EFI_CPU_GET_TIMER_VALUE)(\r
d1f95000 221 IN EFI_CPU_ARCH_PROTOCOL *This,\r
222 IN UINT32 TimerIndex,\r
223 OUT UINT64 *TimerValue,\r
224 OUT UINT64 *TimerPeriod OPTIONAL\r
225 );\r
226\r
227\r
228/**\r
229 This function modifies the attributes for the memory region specified by BaseAddress and\r
230 Length from their current attributes to the attributes specified by Attributes.\r
231\r
232 @param This The EFI_CPU_ARCH_PROTOCOL instance.\r
233 @param BaseAddress The physical address that is the start address of a memory region.\r
234 @param Length The size in bytes of the memory region.\r
235 @param Attributes The bit mask of attributes to set for the memory region.\r
236\r
237 @retval EFI_SUCCESS The attributes were set for the memory region.\r
238 @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by\r
239 BaseAddress and Length cannot be modified.\r
240 @retval EFI_INVALID_PARAMETER Length is zero.\r
4ec21e8b 241 Attributes specified an illegal combination of attributes that\r
242 cannot be set together.\r
d1f95000 243 @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of\r
244 the memory resource range.\r
245 @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory\r
246 resource range specified by BaseAddress and Length.\r
247 The bit mask of attributes is not support for the memory resource\r
248 range specified by BaseAddress and Length.\r
249\r
250**/\r
251typedef\r
252EFI_STATUS\r
8b13229b 253(EFIAPI *EFI_CPU_SET_MEMORY_ATTRIBUTES)(\r
d1f95000 254 IN EFI_CPU_ARCH_PROTOCOL *This,\r
255 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
256 IN UINT64 Length,\r
257 IN UINT64 Attributes\r
258 );\r
259\r
260\r
44717a39 261///\r
262/// The EFI_CPU_ARCH_PROTOCOL is used to abstract processor-specific functions from the DXE\r
263/// Foundation. This includes flushing caches, enabling and disabling interrupts, hooking interrupt\r
264/// vectors and exception vectors, reading internal processor timers, resetting the processor, and\r
265/// determining the processor frequency.\r
266///\r
d1f95000 267struct _EFI_CPU_ARCH_PROTOCOL {\r
268 EFI_CPU_FLUSH_DATA_CACHE FlushDataCache;\r
269 EFI_CPU_ENABLE_INTERRUPT EnableInterrupt;\r
270 EFI_CPU_DISABLE_INTERRUPT DisableInterrupt;\r
271 EFI_CPU_GET_INTERRUPT_STATE GetInterruptState;\r
272 EFI_CPU_INIT Init;\r
273 EFI_CPU_REGISTER_INTERRUPT_HANDLER RegisterInterruptHandler;\r
274 EFI_CPU_GET_TIMER_VALUE GetTimerValue;\r
275 EFI_CPU_SET_MEMORY_ATTRIBUTES SetMemoryAttributes;\r
8b6c989b 276 ///\r
9095d37b
LG
277 /// The number of timers that are available in a processor. The value in this\r
278 /// field is a constant that must not be modified after the CPU Architectural\r
8b6c989b 279 /// Protocol is installed. All consumers must treat this as a read-only field.\r
280 ///\r
d1f95000 281 UINT32 NumberOfTimers;\r
8b6c989b 282 ///\r
9095d37b
LG
283 /// The size, in bytes, of the alignment required for DMA buffer allocations.\r
284 /// This is typically the size of the largest data cache line in the platform.\r
285 /// The value in this field is a constant that must not be modified after the\r
286 /// CPU Architectural Protocol is installed. All consumers must treat this as\r
287 /// a read-only field.\r
8b6c989b 288 ///\r
d1f95000 289 UINT32 DmaBufferAlignment;\r
290};\r
291\r
292extern EFI_GUID gEfiCpuArchProtocolGuid;\r
293\r
294#endif\r