rgx_riscv.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*************************************************************************/ /*!
  2. @File rgx_riscv.h
  3. @Title
  4. @Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
  5. @Platform RGX
  6. @Description RGX RISCV definitions, kernel/user space
  7. @License Dual MIT/GPLv2
  8. The contents of this file are subject to the MIT license as set out below.
  9. Permission is hereby granted, free of charge, to any person obtaining a copy
  10. of this software and associated documentation files (the "Software"), to deal
  11. in the Software without restriction, including without limitation the rights
  12. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. copies of the Software, and to permit persons to whom the Software is
  14. furnished to do so, subject to the following conditions:
  15. The above copyright notice and this permission notice shall be included in
  16. all copies or substantial portions of the Software.
  17. Alternatively, the contents of this file may be used under the terms of
  18. the GNU General Public License Version 2 ("GPL") in which case the provisions
  19. of GPL are applicable instead of those above.
  20. If you wish to allow use of your version of this file only under the terms of
  21. GPL, and not to allow others to use your version of this file under the terms
  22. of the MIT license, indicate your decision by deleting the provisions above
  23. and replace them with the notice and other provisions required by GPL as set
  24. out in the file called "GPL-COPYING" included in this distribution. If you do
  25. not delete the provisions above, a recipient may use your version of this file
  26. under the terms of either the MIT license or GPL.
  27. This License is also included in this distribution in the file called
  28. "MIT-COPYING".
  29. EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
  30. PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
  31. BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  32. PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
  33. COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  34. IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  35. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  36. */ /**************************************************************************/
  37. #if !defined(RGX_RISCV_H)
  38. #define RGX_RISCV_H
  39. #include "km/rgxdefs_km.h"
  40. /* Utility defines to convert regions to virtual addresses and remaps */
  41. #define RGXRISCVFW_GET_REGION_BASE(r) IMG_UINT32_C((r) << 28)
  42. #define RGXRISCVFW_GET_REGION(a) IMG_UINT32_C((a) >> 28)
  43. #define RGXRISCVFW_MAX_REGION_SIZE IMG_UINT32_C(1 << 28)
  44. #define RGXRISCVFW_GET_REMAP(r) (RGX_CR_FWCORE_ADDR_REMAP_CONFIG0 + ((r) * 8U))
  45. /* RISCV remap output is aligned to 4K */
  46. #define RGXRISCVFW_REMAP_CONFIG_DEVVADDR_ALIGN (0x1000U)
  47. /*
  48. * FW bootloader defines
  49. */
  50. #define RGXRISCVFW_BOOTLDR_CODE_REGION IMG_UINT32_C(0xC)
  51. #define RGXRISCVFW_BOOTLDR_DATA_REGION IMG_UINT32_C(0x5)
  52. #define RGXRISCVFW_BOOTLDR_CODE_BASE (RGXRISCVFW_GET_REGION_BASE(RGXRISCVFW_BOOTLDR_CODE_REGION))
  53. #define RGXRISCVFW_BOOTLDR_DATA_BASE (RGXRISCVFW_GET_REGION_BASE(RGXRISCVFW_BOOTLDR_DATA_REGION))
  54. #define RGXRISCVFW_BOOTLDR_CODE_REMAP (RGXRISCVFW_GET_REMAP(RGXRISCVFW_BOOTLDR_CODE_REGION))
  55. #define RGXRISCVFW_BOOTLDR_DATA_REMAP (RGXRISCVFW_GET_REMAP(RGXRISCVFW_BOOTLDR_DATA_REGION))
  56. /* Bootloader data offset in dwords from the beginning of the FW data allocation */
  57. #define RGXRISCVFW_BOOTLDR_CONF_OFFSET (0x0)
  58. /*
  59. * FW coremem region defines
  60. */
  61. #define RGXRISCVFW_COREMEM_REGION IMG_UINT32_C(0x8)
  62. #define RGXRISCVFW_COREMEM_MAX_SIZE IMG_UINT32_C(0x10000000) /* 256 MB */
  63. #define RGXRISCVFW_COREMEM_BASE (RGXRISCVFW_GET_REGION_BASE(RGXRISCVFW_COREMEM_REGION))
  64. #define RGXRISCVFW_COREMEM_END (RGXRISCVFW_COREMEM_BASE + RGXRISCVFW_COREMEM_MAX_SIZE - 1)
  65. /*
  66. * Host-FW shared data defines
  67. */
  68. #define RGXRISCVFW_SHARED_CACHED_DATA_REGION (0x6UL)
  69. #define RGXRISCVFW_SHARED_UNCACHED_DATA_REGION (0xDUL)
  70. #define RGXRISCVFW_SHARED_CACHED_DATA_BASE (RGXRISCVFW_GET_REGION_BASE(RGXRISCVFW_SHARED_CACHED_DATA_REGION))
  71. #define RGXRISCVFW_SHARED_UNCACHED_DATA_BASE (RGXRISCVFW_GET_REGION_BASE(RGXRISCVFW_SHARED_UNCACHED_DATA_REGION))
  72. #define RGXRISCVFW_SHARED_CACHED_DATA_REMAP (RGXRISCVFW_GET_REMAP(RGXRISCVFW_SHARED_CACHED_DATA_REGION))
  73. #define RGXRISCVFW_SHARED_UNCACHED_DATA_REMAP (RGXRISCVFW_GET_REMAP(RGXRISCVFW_SHARED_UNCACHED_DATA_REGION))
  74. /*
  75. * GPU SOCIF access defines
  76. */
  77. #define RGXRISCVFW_SOCIF_REGION (0x2U)
  78. #define RGXRISCVFW_SOCIF_BASE (RGXRISCVFW_GET_REGION_BASE(RGXRISCVFW_SOCIF_REGION))
  79. /* The things that follow are excluded when compiling assembly sources */
  80. #if !defined(RGXRISCVFW_ASSEMBLY_CODE)
  81. #include "img_types.h"
  82. #define RGXFW_PROCESSOR_RISCV "RISCV"
  83. #define RGXRISCVFW_CORE_ID_VALUE (0x00450B02U)
  84. #define RGXRISCVFW_MISA_ADDR (0x301U)
  85. #define RGXRISCVFW_MISA_VALUE (0x40001104U)
  86. #define RGXRISCVFW_MSCRATCH_ADDR (0x340U)
  87. typedef struct
  88. {
  89. IMG_UINT64 ui64CorememCodeDevVAddr;
  90. IMG_UINT64 ui64CorememDataDevVAddr;
  91. IMG_UINT32 ui32CorememCodeFWAddr;
  92. IMG_UINT32 ui32CorememDataFWAddr;
  93. IMG_UINT32 ui32CorememCodeSize;
  94. IMG_UINT32 ui32CorememDataSize;
  95. IMG_UINT32 ui32Flags;
  96. IMG_UINT32 ui32Reserved;
  97. } RGXRISCVFW_BOOT_DATA;
  98. /*
  99. * List of registers to be printed in debug dump.
  100. * First column: register names (general purpose or control/status registers)
  101. * Second column: register number to be used in abstract access register command
  102. * (see RISC-V debug spec v0.13)
  103. */
  104. #define RGXRISCVFW_DEBUG_DUMP_REGISTERS \
  105. X(pc, 0x7b1) /* dpc */ \
  106. X(ra, 0x1001) \
  107. X(sp, 0x1002) \
  108. X(mepc, 0x341) \
  109. X(mcause, 0x342) \
  110. X(mdseac, 0xfc0) \
  111. X(mstatus, 0x300) \
  112. X(mie, 0x304) \
  113. X(mip, 0x344) \
  114. X(mscratch, 0x340) \
  115. X(mbvnc0, 0xffe) \
  116. X(mbvnc1, 0xfff) \
  117. X(micect, 0x7f0) \
  118. X(mdcect, 0x7f3) \
  119. X(mdcrfct, 0x7f4) \
  120. typedef struct
  121. {
  122. #define X(name, address) \
  123. IMG_UINT32 name;
  124. RGXRISCVFW_DEBUG_DUMP_REGISTERS
  125. #undef X
  126. } RGXRISCVFW_STATE;
  127. #define RGXRISCVFW_MCAUSE_INTERRUPT (1U << 31)
  128. #define RGXRISCVFW_MCAUSE_TABLE \
  129. X(0x00000000U, IMG_FALSE, "NMI pin assertion") /* Also reset value */ \
  130. X(0x00000001U, IMG_TRUE, "Instruction access fault") \
  131. X(0x00000002U, IMG_TRUE, "Illegal instruction") \
  132. X(0x00000003U, IMG_TRUE, "Breakpoint") \
  133. X(0x00000004U, IMG_TRUE, "Load address misaligned") \
  134. X(0x00000005U, IMG_TRUE, "Load access fault") \
  135. X(0x00000006U, IMG_TRUE, "Store/AMO address misaligned") \
  136. X(0x00000007U, IMG_TRUE, "Store/AMO access fault") \
  137. X(0x0000000BU, IMG_TRUE, "Environment call from M-mode (FW assert)") \
  138. X(0x80000007U, IMG_FALSE, "Machine timer interrupt") \
  139. X(0x8000000BU, IMG_FALSE, "Machine external interrupt") \
  140. X(0x8000001EU, IMG_FALSE, "Machine correctable error local interrupt") \
  141. X(0xF0000000U, IMG_TRUE, "Machine D-bus store error NMI") \
  142. X(0xF0000001U, IMG_TRUE, "Machine D-bus non-blocking load error NMI") \
  143. X(0xF0000002U, IMG_TRUE, "dCache unrecoverable NMI")
  144. /* Debug module HW defines */
  145. #define RGXRISCVFW_DMI_COMMAND_ACCESS_REGISTER (0U)
  146. #define RGXRISCVFW_DMI_COMMAND_ACCESS_MEMORY (2U)
  147. #define RGXRISCVFW_DMI_COMMAND_AAxSIZE_32BIT (2UL << 20)
  148. #define RGXRISCVFW_DMI_COMMAND_WRITE (1UL << 16)
  149. #define RGXRISCVFW_DMI_COMMAND_READ (0UL << 16)
  150. #define RGXRISCVFW_DMI_SBCS_SBACCESS_32BIT (2U)
  151. /* Abstract command error codes (descriptions from RISC-V debug spec v0.13) */
  152. typedef enum
  153. {
  154. /* No error. */
  155. RISCV_ABSTRACT_CMD_NO_ERROR = 0,
  156. /*
  157. * An abstract command was executing while command, abstractcs, or abstractauto
  158. * was written, or when one of the data or progbuf registers was read or
  159. * written. This status is only written if cmderr contains 0.
  160. */
  161. RISCV_ABSTRACT_CMD_BUSY = 1,
  162. /*
  163. * The requested command is not supported, regardless of whether
  164. * the hart is running or not.
  165. */
  166. RISCV_ABSTRACT_CMD_NOT_SUPPORTED = 2,
  167. /*
  168. * An exception occurred while executing the command
  169. * (e.g. while executing the Program Buffer).
  170. */
  171. RISCV_ABSTRACT_CMD_EXCEPTION = 3,
  172. /*
  173. * The abstract command couldn't execute because the hart wasn't in the required
  174. * state (running/halted), or unavailable.
  175. */
  176. RISCV_ABSTRACT_CMD_HALT_RESUME = 4,
  177. /*
  178. * The abstract command failed due to a bus error
  179. * (e.g. alignment, access size, or timeout).
  180. */
  181. RISCV_ABSTRACT_CMD_BUS_ERROR = 5,
  182. /* The command failed for another reason. */
  183. RISCV_ABSTRACT_CMD_OTHER_ERROR = 7
  184. } RGXRISCVFW_ABSTRACT_CMD_ERR;
  185. /* System Bus error codes (descriptions from RISC-V debug spec v0.13) */
  186. typedef enum
  187. {
  188. /* There was no bus error. */
  189. RISCV_SYSBUS_NO_ERROR = 0,
  190. /* There was a timeout. */
  191. RISCV_SYSBUS_TIMEOUT = 1,
  192. /* A bad address was accessed. */
  193. RISCV_SYSBUS_BAD_ADDRESS = 2,
  194. /* There was an alignment error. */
  195. RISCV_SYSBUS_BAD_ALIGNMENT = 3,
  196. /* An access of unsupported size was requested. */
  197. RISCV_SYSBUS_UNSUPPORTED_SIZE = 4,
  198. /* Other. */
  199. RISCV_SYSBUS_OTHER_ERROR = 7
  200. } RGXRISCVFW_SYSBUS_ERR;
  201. #endif /* RGXRISCVFW_ASSEMBLY_CODE */
  202. #endif /* RGX_RISCV_H */