CpuDxe.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /** @file
  2. CPU DXE Module to produce CPU ARCH Protocol and CPU MP Protocol
  3. Copyright (c) 2022 Loongson Technology Corporation Limited. 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 <Protocol/Cpu.h>
  9. /**
  10. This function registers and enables the handler specified by InterruptHandler for a processor
  11. interrupt or exception type specified by InteruptNum. If InterruptHandler is NULL, then the
  12. handler for the processor interrupt or exception type specified by InteruptNum is uninstalled.
  13. The installed handler is called once for each processor interrupt or exception.
  14. @param InteruptNum A number of the processor's current interrupt.
  15. @param InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called
  16. when a processor interrupt occurs. If this parameter is NULL, then the handler
  17. will be uninstalled.
  18. @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.
  19. @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InteruptNum was
  20. previously installed.
  21. @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InteruptNum was not
  22. previously installed.
  23. @retval EFI_UNSUPPORTED The interrupt specified by InteruptNum is not supported.
  24. **/
  25. EFI_STATUS
  26. RegisterInterruptHandler (
  27. IN EFI_EXCEPTION_TYPE InteruptNum,
  28. IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
  29. );
  30. /**
  31. This function registers and enables the handler specified by InterruptHandler for a processor
  32. interrupt or exception type specified by InteruptNum. If InterruptHandler is NULL, then the
  33. handler for the processor interrupt or exception type specified by InteruptNum is uninstalled.
  34. The installed handler is called once for each processor interrupt or exception.
  35. @param InteruptNum A number of the processor's current interrupt.
  36. @param InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called
  37. when a processor interrupt occurs. If this parameter is NULL, then the handler
  38. will be uninstalled.
  39. @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.
  40. @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InteruptNum was
  41. previously installed.
  42. @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InteruptNum was not
  43. previously installed.
  44. @retval EFI_UNSUPPORTED The interrupt specified by InteruptNum is not supported.
  45. **/
  46. EFI_STATUS
  47. RegisterDebuggerInterruptHandler (
  48. IN EFI_EXCEPTION_TYPE InteruptNum,
  49. IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
  50. );
  51. /**
  52. This function modifies the attributes for the memory region specified by BaseAddress and
  53. Length from their current attributes to the attributes specified by Attributes.
  54. @param This The EFI_CPU_ARCH_PROTOCOL instance.
  55. @param BaseAddress The physical address that is the start address of a memory region.
  56. @param Length The size in bytes of the memory region.
  57. @param Attributes The bit mask of attributes to set for the memory region.
  58. @retval EFI_SUCCESS The attributes were set for the memory region.
  59. @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by
  60. BaseAddress and Length cannot be modified.
  61. @retval EFI_INVALID_PARAMETER Length is zero.
  62. @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of
  63. the memory resource range.
  64. @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory
  65. resource range specified by BaseAddress and Length.
  66. The bit mask of attributes is not support for the memory resource
  67. range specified by BaseAddress and Length.
  68. **/
  69. EFI_STATUS
  70. EFIAPI
  71. CpuSetMemoryAttributes (
  72. IN EFI_CPU_ARCH_PROTOCOL *This,
  73. IN EFI_PHYSICAL_ADDRESS BaseAddress,
  74. IN UINT64 Length,
  75. IN UINT64 Attributes
  76. );
  77. /** Exception module initialization
  78. This function sets the exception base address.
  79. @param Cpu A pointer to the CPU architecture protocol structure.
  80. @retval EFI_SUCCESS Initialization succeeded
  81. @retval EFI_NOT_FOUND Could not Found resources.
  82. @retval EFI_OUT_OF_RESOURCES No enough resources.
  83. **/
  84. EFI_STATUS
  85. InitializeExceptions (
  86. IN EFI_CPU_ARCH_PROTOCOL *Cpu
  87. );
  88. /** Common exception entry
  89. Exception handling is the entry point for the C environment,
  90. This function does different things depending on the exception type.
  91. @param SystemContext The system context at the time of the exception.
  92. @retval VOID.
  93. **/
  94. VOID
  95. EFIAPI
  96. CommonExceptionEntry (
  97. IN OUT EFI_SYSTEM_CONTEXT SystemContext
  98. );
  99. extern CHAR8 LoongArchException[], LoongArchExceptionEnd[];
  100. /** Set Exception Base Address
  101. @param addr Exception Base Address.
  102. @retval The Old Exception Base Address.
  103. **/
  104. extern
  105. UINT64
  106. SetEbase (
  107. EFI_PHYSICAL_ADDRESS addr
  108. );
  109. /*
  110. Load the FPU with signalling NANS. This bit pattern we're using has
  111. the property that no matter whether considered as single or as double
  112. precision represents signaling NANS.
  113. @param fcsr The value to initialize FCSR0
  114. @retval The Old Exception Base Address.
  115. */
  116. extern
  117. VOID
  118. InitFpu (
  119. UINT32 fcsr
  120. );
  121. /*
  122. Read Csr EUEN register.
  123. @param CsrEuen Pointer to the variable used to store the EUEN register value
  124. @retval none
  125. */
  126. extern
  127. VOID
  128. LoongArchReadqCsrEuen (
  129. UINT64 *CsrEuen
  130. );
  131. /*
  132. Write Csr EUEN register.
  133. @param The value used to write to the EUEN register
  134. @retval none
  135. */
  136. extern
  137. VOID
  138. LoongArchWriteqCsrEuen (
  139. UINT64 CsrEuen
  140. );
  141. /*
  142. Enables floating-point unit
  143. @param VOID
  144. @retval VOID
  145. */
  146. extern
  147. VOID
  148. LoongArchEnableFpu (
  149. VOID
  150. );
  151. /*
  152. Disable floating-point unit
  153. @param VOID
  154. @retval VOID
  155. */
  156. extern
  157. VOID
  158. LoongArchDisableFpu (
  159. VOID
  160. );
  161. #endif // CPU_DXE_H_