CpuDxe.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /** @file
  2. CPU DXE Module to produce CPU ARCH Protocol and CPU MP Protocol.
  3. Copyright (c) 2008 - 2019, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef _CPU_DXE_H_
  7. #define _CPU_DXE_H_
  8. #include <PiDxe.h>
  9. #include <Protocol/Cpu.h>
  10. #include <Protocol/MpService.h>
  11. #include <Register/Intel/Msr.h>
  12. #include <Ppi/SecPlatformInformation.h>
  13. #include <Ppi/SecPlatformInformation2.h>
  14. #include <Library/UefiDriverEntryPoint.h>
  15. #include <Library/UefiBootServicesTableLib.h>
  16. #include <Library/DxeServicesTableLib.h>
  17. #include <Library/BaseLib.h>
  18. #include <Library/CpuLib.h>
  19. #include <Library/BaseMemoryLib.h>
  20. #include <Library/MemoryAllocationLib.h>
  21. #include <Library/DebugLib.h>
  22. #include <Library/MtrrLib.h>
  23. #include <Library/LocalApicLib.h>
  24. #include <Library/UefiCpuLib.h>
  25. #include <Library/UefiLib.h>
  26. #include <Library/CpuExceptionHandlerLib.h>
  27. #include <Library/HobLib.h>
  28. #include <Library/ReportStatusCodeLib.h>
  29. #include <Library/MpInitLib.h>
  30. #include <Library/TimerLib.h>
  31. #include <Guid/IdleLoopEvent.h>
  32. #include <Guid/VectorHandoffTable.h>
  33. #define HEAP_GUARD_NONSTOP_MODE \
  34. ((PcdGet8 (PcdHeapGuardPropertyMask) & (BIT6|BIT4|BIT1|BIT0)) > BIT6)
  35. #define NULL_DETECTION_NONSTOP_MODE \
  36. ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & (BIT6|BIT0)) > BIT6)
  37. /**
  38. Flush CPU data cache. If the instruction cache is fully coherent
  39. with all DMA operations then function can just return EFI_SUCCESS.
  40. @param This Protocol instance structure
  41. @param Start Physical address to start flushing from.
  42. @param Length Number of bytes to flush. Round up to chipset
  43. granularity.
  44. @param FlushType Specifies the type of flush operation to perform.
  45. @retval EFI_SUCCESS If cache was flushed
  46. @retval EFI_UNSUPPORTED If flush type is not supported.
  47. @retval EFI_DEVICE_ERROR If requested range could not be flushed.
  48. **/
  49. EFI_STATUS
  50. EFIAPI
  51. CpuFlushCpuDataCache (
  52. IN EFI_CPU_ARCH_PROTOCOL *This,
  53. IN EFI_PHYSICAL_ADDRESS Start,
  54. IN UINT64 Length,
  55. IN EFI_CPU_FLUSH_TYPE FlushType
  56. );
  57. /**
  58. Enables CPU interrupts.
  59. @param This Protocol instance structure
  60. @retval EFI_SUCCESS If interrupts were enabled in the CPU
  61. @retval EFI_DEVICE_ERROR If interrupts could not be enabled on the CPU.
  62. **/
  63. EFI_STATUS
  64. EFIAPI
  65. CpuEnableInterrupt (
  66. IN EFI_CPU_ARCH_PROTOCOL *This
  67. );
  68. /**
  69. Disables CPU interrupts.
  70. @param This Protocol instance structure
  71. @retval EFI_SUCCESS If interrupts were disabled in the CPU.
  72. @retval EFI_DEVICE_ERROR If interrupts could not be disabled on the CPU.
  73. **/
  74. EFI_STATUS
  75. EFIAPI
  76. CpuDisableInterrupt (
  77. IN EFI_CPU_ARCH_PROTOCOL *This
  78. );
  79. /**
  80. Return the state of interrupts.
  81. @param This Protocol instance structure
  82. @param State Pointer to the CPU's current interrupt state
  83. @retval EFI_SUCCESS If interrupts were disabled in the CPU.
  84. @retval EFI_INVALID_PARAMETER State is NULL.
  85. **/
  86. EFI_STATUS
  87. EFIAPI
  88. CpuGetInterruptState (
  89. IN EFI_CPU_ARCH_PROTOCOL *This,
  90. OUT BOOLEAN *State
  91. );
  92. /**
  93. Generates an INIT to the CPU.
  94. @param This Protocol instance structure
  95. @param InitType Type of CPU INIT to perform
  96. @retval EFI_SUCCESS If CPU INIT occurred. This value should never be
  97. seen.
  98. @retval EFI_DEVICE_ERROR If CPU INIT failed.
  99. @retval EFI_UNSUPPORTED Requested type of CPU INIT not supported.
  100. **/
  101. EFI_STATUS
  102. EFIAPI
  103. CpuInit (
  104. IN EFI_CPU_ARCH_PROTOCOL *This,
  105. IN EFI_CPU_INIT_TYPE InitType
  106. );
  107. /**
  108. Registers a function to be called from the CPU interrupt handler.
  109. @param This Protocol instance structure
  110. @param InterruptType Defines which interrupt to hook. IA-32
  111. valid range is 0x00 through 0xFF
  112. @param InterruptHandler A pointer to a function of type
  113. EFI_CPU_INTERRUPT_HANDLER that is called
  114. when a processor interrupt occurs. A null
  115. pointer is an error condition.
  116. @retval EFI_SUCCESS If handler installed or uninstalled.
  117. @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler
  118. for InterruptType was previously installed.
  119. @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for
  120. InterruptType was not previously installed.
  121. @retval EFI_UNSUPPORTED The interrupt specified by InterruptType
  122. is not supported.
  123. **/
  124. EFI_STATUS
  125. EFIAPI
  126. CpuRegisterInterruptHandler (
  127. IN EFI_CPU_ARCH_PROTOCOL *This,
  128. IN EFI_EXCEPTION_TYPE InterruptType,
  129. IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
  130. );
  131. /**
  132. Returns a timer value from one of the CPU's internal timers. There is no
  133. inherent time interval between ticks but is a function of the CPU frequency.
  134. @param This - Protocol instance structure.
  135. @param TimerIndex - Specifies which CPU timer is requested.
  136. @param TimerValue - Pointer to the returned timer value.
  137. @param TimerPeriod - A pointer to the amount of time that passes
  138. in femtoseconds (10-15) for each increment
  139. of TimerValue. If TimerValue does not
  140. increment at a predictable rate, then 0 is
  141. returned. The amount of time that has
  142. passed between two calls to GetTimerValue()
  143. can be calculated with the formula
  144. (TimerValue2 - TimerValue1) * TimerPeriod.
  145. This parameter is optional and may be NULL.
  146. @retval EFI_SUCCESS - If the CPU timer count was returned.
  147. @retval EFI_UNSUPPORTED - If the CPU does not have any readable timers.
  148. @retval EFI_DEVICE_ERROR - If an error occurred while reading the timer.
  149. @retval EFI_INVALID_PARAMETER - TimerIndex is not valid or TimerValue is NULL.
  150. **/
  151. EFI_STATUS
  152. EFIAPI
  153. CpuGetTimerValue (
  154. IN EFI_CPU_ARCH_PROTOCOL *This,
  155. IN UINT32 TimerIndex,
  156. OUT UINT64 *TimerValue,
  157. OUT UINT64 *TimerPeriod OPTIONAL
  158. );
  159. /**
  160. Set memory cacheability attributes for given range of memory.
  161. @param This Protocol instance structure
  162. @param BaseAddress Specifies the start address of the
  163. memory range
  164. @param Length Specifies the length of the memory range
  165. @param Attributes The memory cacheability for the memory range
  166. @retval EFI_SUCCESS If the cacheability of that memory range is
  167. set successfully
  168. @retval EFI_UNSUPPORTED If the desired operation cannot be done
  169. @retval EFI_INVALID_PARAMETER The input parameter is not correct,
  170. such as Length = 0
  171. **/
  172. EFI_STATUS
  173. EFIAPI
  174. CpuSetMemoryAttributes (
  175. IN EFI_CPU_ARCH_PROTOCOL *This,
  176. IN EFI_PHYSICAL_ADDRESS BaseAddress,
  177. IN UINT64 Length,
  178. IN UINT64 Attributes
  179. );
  180. /**
  181. Initialize Global Descriptor Table.
  182. **/
  183. VOID
  184. InitGlobalDescriptorTable (
  185. VOID
  186. );
  187. /**
  188. Sets the code selector (CS).
  189. @param Selector Value of code selector.
  190. **/
  191. VOID
  192. EFIAPI
  193. SetCodeSelector (
  194. UINT16 Selector
  195. );
  196. /**
  197. Sets the data selector (DS).
  198. @param Selector Value of data selector.
  199. **/
  200. VOID
  201. EFIAPI
  202. SetDataSelectors (
  203. UINT16 Selector
  204. );
  205. /**
  206. Update GCD memory space attributes according to current page table setup.
  207. **/
  208. VOID
  209. RefreshGcdMemoryAttributesFromPaging (
  210. VOID
  211. );
  212. /**
  213. Special handler for #DB exception, which will restore the page attributes
  214. (not-present). It should work with #PF handler which will set pages to
  215. 'present'.
  216. @param ExceptionType Exception type.
  217. @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
  218. **/
  219. VOID
  220. EFIAPI
  221. DebugExceptionHandler (
  222. IN EFI_EXCEPTION_TYPE ExceptionType,
  223. IN EFI_SYSTEM_CONTEXT SystemContext
  224. );
  225. /**
  226. Special handler for #PF exception, which will set the pages which caused
  227. #PF to be 'present'. The attribute of those pages should be restored in
  228. the subsequent #DB handler.
  229. @param ExceptionType Exception type.
  230. @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
  231. **/
  232. VOID
  233. EFIAPI
  234. PageFaultExceptionHandler (
  235. IN EFI_EXCEPTION_TYPE ExceptionType,
  236. IN EFI_SYSTEM_CONTEXT SystemContext
  237. );
  238. extern BOOLEAN mIsAllocatingPageTable;
  239. extern UINTN mNumberOfProcessors;
  240. #endif