You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Cpu.h 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /** @file
  2. CPU Architectural Protocol as defined in PI spec Volume 2 DXE
  3. This code abstracts the DXE core from processor implementation details.
  4. Copyright (c) 2006 - 2008, Intel Corporation
  5. All rights reserved. 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
  9. THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
  11. **/
  12. #ifndef __ARCH_PROTOCOL_CPU_H__
  13. #define __ARCH_PROTOCOL_CPU_H__
  14. #include <gpxe/efi/Protocol/DebugSupport.h>
  15. #define EFI_CPU_ARCH_PROTOCOL_GUID \
  16. { 0x26baccb1, 0x6f42, 0x11d4, {0xbc, 0xe7, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } }
  17. typedef struct _EFI_CPU_ARCH_PROTOCOL EFI_CPU_ARCH_PROTOCOL;
  18. typedef enum {
  19. EfiCpuFlushTypeWriteBackInvalidate,
  20. EfiCpuFlushTypeWriteBack,
  21. EfiCpuFlushTypeInvalidate,
  22. EfiCpuMaxFlushType
  23. } EFI_CPU_FLUSH_TYPE;
  24. typedef enum {
  25. EfiCpuInit,
  26. EfiCpuMaxInitType
  27. } EFI_CPU_INIT_TYPE;
  28. /**
  29. EFI_CPU_INTERRUPT_HANDLER that is called when a processor interrupt occurs.
  30. @param InterruptType Defines the type of interrupt or exception that
  31. occurred on the processor.This parameter is processor architecture specific.
  32. @param SystemContext A pointer to the processor context when
  33. the interrupt occurred on the processor.
  34. @return None
  35. **/
  36. typedef
  37. VOID
  38. (EFIAPI *EFI_CPU_INTERRUPT_HANDLER)(
  39. IN CONST EFI_EXCEPTION_TYPE InterruptType,
  40. IN CONST EFI_SYSTEM_CONTEXT SystemContext
  41. );
  42. /**
  43. This function flushes the range of addresses from Start to Start+Length
  44. from the processor's data cache. If Start is not aligned to a cache line
  45. boundary, then the bytes before Start to the preceding cache line boundary
  46. are also flushed. If Start+Length is not aligned to a cache line boundary,
  47. then the bytes past Start+Length to the end of the next cache line boundary
  48. are also flushed. The FlushType of EfiCpuFlushTypeWriteBackInvalidate must be
  49. supported. If the data cache is fully coherent with all DMA operations, then
  50. this function can just return EFI_SUCCESS. If the processor does not support
  51. flushing a range of the data cache, then the entire data cache can be flushed.
  52. @param This The EFI_CPU_ARCH_PROTOCOL instance.
  53. @param Start The beginning physical address to flush from the processor's data
  54. cache.
  55. @param Length The number of bytes to flush from the processor's data cache. This
  56. function may flush more bytes than Length specifies depending upon
  57. the granularity of the flush operation that the processor supports.
  58. @param FlushType Specifies the type of flush operation to perform.
  59. @retval EFI_SUCCESS The address range from Start to Start+Length was flushed from
  60. the processor's data cache.
  61. @retval EFI_UNSUPPORTEDT The processor does not support the cache flush type specified
  62. by FlushType.
  63. @retval EFI_DEVICE_ERROR The address range from Start to Start+Length could not be flushed
  64. from the processor's data cache.
  65. **/
  66. typedef
  67. EFI_STATUS
  68. (EFIAPI *EFI_CPU_FLUSH_DATA_CACHE)(
  69. IN EFI_CPU_ARCH_PROTOCOL *This,
  70. IN EFI_PHYSICAL_ADDRESS Start,
  71. IN UINT64 Length,
  72. IN EFI_CPU_FLUSH_TYPE FlushType
  73. );
  74. /**
  75. This function enables interrupt processing by the processor.
  76. @param This The EFI_CPU_ARCH_PROTOCOL instance.
  77. @retval EFI_SUCCESS Interrupts are enabled on the processor.
  78. @retval EFI_DEVICE_ERROR Interrupts could not be enabled on the processor.
  79. **/
  80. typedef
  81. EFI_STATUS
  82. (EFIAPI *EFI_CPU_ENABLE_INTERRUPT)(
  83. IN EFI_CPU_ARCH_PROTOCOL *This
  84. );
  85. /**
  86. This function disables interrupt processing by the processor.
  87. @param This The EFI_CPU_ARCH_PROTOCOL instance.
  88. @retval EFI_SUCCESS Interrupts are disabled on the processor.
  89. @retval EFI_DEVICE_ERROR Interrupts could not be disabled on the processor.
  90. **/
  91. typedef
  92. EFI_STATUS
  93. (EFIAPI *EFI_CPU_DISABLE_INTERRUPT)(
  94. IN EFI_CPU_ARCH_PROTOCOL *This
  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. @param This The EFI_CPU_ARCH_PROTOCOL instance.
  101. @param State A pointer to the processor's current interrupt state. Set to TRUE if
  102. interrupts are enabled and FALSE if interrupts are disabled.
  103. @retval EFI_SUCCESS The processor's current interrupt state was returned in State.
  104. @retval EFI_INVALID_PARAMETER State is NULL.
  105. **/
  106. typedef
  107. EFI_STATUS
  108. (EFIAPI *EFI_CPU_GET_INTERRUPT_STATE)(
  109. IN EFI_CPU_ARCH_PROTOCOL *This,
  110. OUT BOOLEAN *State
  111. );
  112. /**
  113. This function generates an INIT on the processor. If this function succeeds, then the
  114. processor will be reset, and control will not be returned to the caller. If InitType is
  115. not supported by this processor, or the processor cannot programmatically generate an
  116. INIT without help from external hardware, then EFI_UNSUPPORTED is returned. If an error
  117. occurs attempting to generate an INIT, then EFI_DEVICE_ERROR is returned.
  118. @param This The EFI_CPU_ARCH_PROTOCOL instance.
  119. @param InitType The type of processor INIT to perform.
  120. @retval EFI_SUCCESS The processor INIT was performed. This return code should never be seen.
  121. @retval EFI_UNSUPPORTED The processor INIT operation specified by InitType is not supported
  122. by this processor.
  123. @retval EFI_DEVICE_ERROR The processor INIT failed.
  124. **/
  125. typedef
  126. EFI_STATUS
  127. (EFIAPI *EFI_CPU_INIT)(
  128. IN EFI_CPU_ARCH_PROTOCOL *This,
  129. IN EFI_CPU_INIT_TYPE InitType
  130. );
  131. /**
  132. This function registers and enables the handler specified by InterruptHandler for a processor
  133. interrupt or exception type specified by InterruptType. If InterruptHandler is NULL, then the
  134. handler for the processor interrupt or exception type specified by InterruptType is uninstalled.
  135. The installed handler is called once for each processor interrupt or exception.
  136. @param This The EFI_CPU_ARCH_PROTOCOL instance.
  137. @param InterruptType A pointer to the processor's current interrupt state. Set to TRUE if interrupts
  138. are enabled and FALSE if interrupts are disabled.
  139. @param InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called
  140. when a processor interrupt occurs. If this parameter is NULL, then the handler
  141. will be uninstalled.
  142. @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.
  143. @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was
  144. previously installed.
  145. @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not
  146. previously installed.
  147. @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported.
  148. **/
  149. typedef
  150. EFI_STATUS
  151. (EFIAPI *EFI_CPU_REGISTER_INTERRUPT_HANDLER)(
  152. IN EFI_CPU_ARCH_PROTOCOL *This,
  153. IN EFI_EXCEPTION_TYPE InterruptType,
  154. IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
  155. );
  156. /**
  157. This function reads the processor timer specified by TimerIndex and returns it in TimerValue.
  158. @param This The EFI_CPU_ARCH_PROTOCOL instance.
  159. @param TimerIndex Specifies which processor timer is to be returned in TimerValue. This parameter
  160. must be between 0 and NumberOfTimers-1.
  161. @param TimerValue Pointer to the returned timer value.
  162. @param TimerPeriod A pointer to the amount of time that passes in femtoseconds for each increment
  163. of TimerValue.
  164. @retval EFI_SUCCESS The processor timer value specified by TimerIndex was returned in TimerValue.
  165. @retval EFI_DEVICE_ERROR An error occurred attempting to read one of the processor's timers.
  166. @retval EFI_INVALID_PARAMETER TimerValue is NULL or TimerIndex is not valid.
  167. @retval EFI_UNSUPPORTED The processor does not have any readable timers.
  168. **/
  169. typedef
  170. EFI_STATUS
  171. (EFIAPI *EFI_CPU_GET_TIMER_VALUE)(
  172. IN EFI_CPU_ARCH_PROTOCOL *This,
  173. IN UINT32 TimerIndex,
  174. OUT UINT64 *TimerValue,
  175. OUT UINT64 *TimerPeriod OPTIONAL
  176. );
  177. /**
  178. This function modifies the attributes for the memory region specified by BaseAddress and
  179. Length from their current attributes to the attributes specified by Attributes.
  180. @param This The EFI_CPU_ARCH_PROTOCOL instance.
  181. @param BaseAddress The physical address that is the start address of a memory region.
  182. @param Length The size in bytes of the memory region.
  183. @param Attributes The bit mask of attributes to set for the memory region.
  184. @retval EFI_SUCCESS The attributes were set for the memory region.
  185. @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by
  186. BaseAddress and Length cannot be modified.
  187. @retval EFI_INVALID_PARAMETER Length is zero.
  188. @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of
  189. the memory resource range.
  190. @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory
  191. resource range specified by BaseAddress and Length.
  192. The bit mask of attributes is not support for the memory resource
  193. range specified by BaseAddress and Length.
  194. **/
  195. typedef
  196. EFI_STATUS
  197. (EFIAPI *EFI_CPU_SET_MEMORY_ATTRIBUTES)(
  198. IN EFI_CPU_ARCH_PROTOCOL *This,
  199. IN EFI_PHYSICAL_ADDRESS BaseAddress,
  200. IN UINT64 Length,
  201. IN UINT64 Attributes
  202. );
  203. ///
  204. /// The EFI_CPU_ARCH_PROTOCOL is used to abstract processor-specific functions from the DXE
  205. /// Foundation. This includes flushing caches, enabling and disabling interrupts, hooking interrupt
  206. /// vectors and exception vectors, reading internal processor timers, resetting the processor, and
  207. /// determining the processor frequency.
  208. ///
  209. struct _EFI_CPU_ARCH_PROTOCOL {
  210. EFI_CPU_FLUSH_DATA_CACHE FlushDataCache;
  211. EFI_CPU_ENABLE_INTERRUPT EnableInterrupt;
  212. EFI_CPU_DISABLE_INTERRUPT DisableInterrupt;
  213. EFI_CPU_GET_INTERRUPT_STATE GetInterruptState;
  214. EFI_CPU_INIT Init;
  215. EFI_CPU_REGISTER_INTERRUPT_HANDLER RegisterInterruptHandler;
  216. EFI_CPU_GET_TIMER_VALUE GetTimerValue;
  217. EFI_CPU_SET_MEMORY_ATTRIBUTES SetMemoryAttributes;
  218. ///
  219. /// The number of timers that are available in a processor. The value in this
  220. /// field is a constant that must not be modified after the CPU Architectural
  221. /// Protocol is installed. All consumers must treat this as a read-only field.
  222. ///
  223. UINT32 NumberOfTimers;
  224. ///
  225. /// The size, in bytes, of the alignment required for DMA buffer allocations.
  226. /// This is typically the size of the largest data cache line in the platform.
  227. /// The value in this field is a constant that must not be modified after the
  228. /// CPU Architectural Protocol is installed. All consumers must treat this as
  229. /// a read-only field.
  230. ///
  231. UINT32 DmaBufferAlignment;
  232. };
  233. extern EFI_GUID gEfiCpuArchProtocolGuid;
  234. #endif