CpuDxe.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /** @file
  2. RISC-V CPU DXE module header file.
  3. Copyright (c) 2016 - 2022, Hewlett Packard Enterprise Development LP. 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 <Library/BaseLib.h>
  11. #include <Library/CpuExceptionHandlerLib.h>
  12. #include <Library/DebugLib.h>
  13. #include <Library/RiscVCpuLib.h>
  14. #include <Library/UefiBootServicesTableLib.h>
  15. #include <Library/UefiDriverEntryPoint.h>
  16. /**
  17. Flush CPU data cache. If the instruction cache is fully coherent
  18. with all DMA operations then function can just return EFI_SUCCESS.
  19. @param This Protocol instance structure
  20. @param Start Physical address to start flushing from.
  21. @param Length Number of bytes to flush. Round up to chipset
  22. granularity.
  23. @param FlushType Specifies the type of flush operation to perform.
  24. @retval EFI_SUCCESS If cache was flushed
  25. @retval EFI_UNSUPPORTED If flush type is not supported.
  26. @retval EFI_DEVICE_ERROR If requested range could not be flushed.
  27. **/
  28. EFI_STATUS
  29. EFIAPI
  30. CpuFlushCpuDataCache (
  31. IN EFI_CPU_ARCH_PROTOCOL *This,
  32. IN EFI_PHYSICAL_ADDRESS Start,
  33. IN UINT64 Length,
  34. IN EFI_CPU_FLUSH_TYPE FlushType
  35. );
  36. /**
  37. Enables CPU interrupts.
  38. @param This Protocol instance structure
  39. @retval EFI_SUCCESS If interrupts were enabled in the CPU
  40. @retval EFI_DEVICE_ERROR If interrupts could not be enabled on the CPU.
  41. **/
  42. EFI_STATUS
  43. EFIAPI
  44. CpuEnableInterrupt (
  45. IN EFI_CPU_ARCH_PROTOCOL *This
  46. );
  47. /**
  48. Disables CPU interrupts.
  49. @param This Protocol instance structure
  50. @retval EFI_SUCCESS If interrupts were disabled in the CPU.
  51. @retval EFI_DEVICE_ERROR If interrupts could not be disabled on the CPU.
  52. **/
  53. EFI_STATUS
  54. EFIAPI
  55. CpuDisableInterrupt (
  56. IN EFI_CPU_ARCH_PROTOCOL *This
  57. );
  58. /**
  59. Return the state of interrupts.
  60. @param This Protocol instance structure
  61. @param State Pointer to the CPU's current interrupt state
  62. @retval EFI_SUCCESS If interrupts were disabled in the CPU.
  63. @retval EFI_INVALID_PARAMETER State is NULL.
  64. **/
  65. EFI_STATUS
  66. EFIAPI
  67. CpuGetInterruptState (
  68. IN EFI_CPU_ARCH_PROTOCOL *This,
  69. OUT BOOLEAN *State
  70. );
  71. /**
  72. Generates an INIT to the CPU.
  73. @param This Protocol instance structure
  74. @param InitType Type of CPU INIT to perform
  75. @retval EFI_SUCCESS If CPU INIT occurred. This value should never be
  76. seen.
  77. @retval EFI_DEVICE_ERROR If CPU INIT failed.
  78. @retval EFI_UNSUPPORTED Requested type of CPU INIT not supported.
  79. **/
  80. EFI_STATUS
  81. EFIAPI
  82. CpuInit (
  83. IN EFI_CPU_ARCH_PROTOCOL *This,
  84. IN EFI_CPU_INIT_TYPE InitType
  85. );
  86. /**
  87. Registers a function to be called from the CPU interrupt handler.
  88. @param This Protocol instance structure
  89. @param InterruptType Defines which interrupt to hook. IA-32
  90. valid range is 0x00 through 0xFF
  91. @param InterruptHandler A pointer to a function of type
  92. EFI_CPU_INTERRUPT_HANDLER that is called
  93. when a processor interrupt occurs. A null
  94. pointer is an error condition.
  95. @retval EFI_SUCCESS If handler installed or uninstalled.
  96. @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler
  97. for InterruptType was previously installed.
  98. @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for
  99. InterruptType was not previously installed.
  100. @retval EFI_UNSUPPORTED The interrupt specified by InterruptType
  101. is not supported.
  102. **/
  103. EFI_STATUS
  104. EFIAPI
  105. CpuRegisterInterruptHandler (
  106. IN EFI_CPU_ARCH_PROTOCOL *This,
  107. IN EFI_EXCEPTION_TYPE InterruptType,
  108. IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
  109. );
  110. /**
  111. Returns a timer value from one of the CPU's internal timers. There is no
  112. inherent time interval between ticks but is a function of the CPU frequency.
  113. @param This - Protocol instance structure.
  114. @param TimerIndex - Specifies which CPU timer is requested.
  115. @param TimerValue - Pointer to the returned timer value.
  116. @param TimerPeriod - A pointer to the amount of time that passes
  117. in femtoseconds (10-15) for each increment
  118. of TimerValue. If TimerValue does not
  119. increment at a predictable rate, then 0 is
  120. returned. The amount of time that has
  121. passed between two calls to GetTimerValue()
  122. can be calculated with the formula
  123. (TimerValue2 - TimerValue1) * TimerPeriod.
  124. This parameter is optional and may be NULL.
  125. @retval EFI_SUCCESS - If the CPU timer count was returned.
  126. @retval EFI_UNSUPPORTED - If the CPU does not have any readable timers.
  127. @retval EFI_DEVICE_ERROR - If an error occurred while reading the timer.
  128. @retval EFI_INVALID_PARAMETER - TimerIndex is not valid or TimerValue is NULL.
  129. **/
  130. EFI_STATUS
  131. EFIAPI
  132. CpuGetTimerValue (
  133. IN EFI_CPU_ARCH_PROTOCOL *This,
  134. IN UINT32 TimerIndex,
  135. OUT UINT64 *TimerValue,
  136. OUT UINT64 *TimerPeriod OPTIONAL
  137. );
  138. /**
  139. Set memory cacheability attributes for given range of memeory.
  140. @param This Protocol instance structure
  141. @param BaseAddress Specifies the start address of the
  142. memory range
  143. @param Length Specifies the length of the memory range
  144. @param Attributes The memory cacheability for the memory range
  145. @retval EFI_SUCCESS If the cacheability of that memory range is
  146. set successfully
  147. @retval EFI_UNSUPPORTED If the desired operation cannot be done
  148. @retval EFI_INVALID_PARAMETER The input parameter is not correct,
  149. such as Length = 0
  150. **/
  151. EFI_STATUS
  152. EFIAPI
  153. CpuSetMemoryAttributes (
  154. IN EFI_CPU_ARCH_PROTOCOL *This,
  155. IN EFI_PHYSICAL_ADDRESS BaseAddress,
  156. IN UINT64 Length,
  157. IN UINT64 Attributes
  158. );
  159. #endif