psp_gfx_if.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /*
  2. * Copyright 2017 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. */
  23. #ifndef _PSP_TEE_GFX_IF_H_
  24. #define _PSP_TEE_GFX_IF_H_
  25. #define PSP_GFX_CMD_BUF_VERSION 0x00000001
  26. #define GFX_CMD_STATUS_MASK 0x0000FFFF
  27. #define GFX_CMD_ID_MASK 0x000F0000
  28. #define GFX_CMD_RESERVED_MASK 0x7FF00000
  29. #define GFX_CMD_RESPONSE_MASK 0x80000000
  30. /* TEE Gfx Command IDs for the register interface.
  31. * Command ID must be between 0x00010000 and 0x000F0000.
  32. */
  33. enum psp_gfx_crtl_cmd_id
  34. {
  35. GFX_CTRL_CMD_ID_INIT_RBI_RING = 0x00010000, /* initialize RBI ring */
  36. GFX_CTRL_CMD_ID_INIT_GPCOM_RING = 0x00020000, /* initialize GPCOM ring */
  37. GFX_CTRL_CMD_ID_DESTROY_RINGS = 0x00030000, /* destroy rings */
  38. GFX_CTRL_CMD_ID_CAN_INIT_RINGS = 0x00040000, /* is it allowed to initialized the rings */
  39. GFX_CTRL_CMD_ID_MAX = 0x000F0000, /* max command ID */
  40. };
  41. /* Control registers of the TEE Gfx interface. These are located in
  42. * SRBM-to-PSP mailbox registers (total 8 registers).
  43. */
  44. struct psp_gfx_ctrl
  45. {
  46. volatile uint32_t cmd_resp; /* +0 Command/Response register for Gfx commands */
  47. volatile uint32_t rbi_wptr; /* +4 Write pointer (index) of RBI ring */
  48. volatile uint32_t rbi_rptr; /* +8 Read pointer (index) of RBI ring */
  49. volatile uint32_t gpcom_wptr; /* +12 Write pointer (index) of GPCOM ring */
  50. volatile uint32_t gpcom_rptr; /* +16 Read pointer (index) of GPCOM ring */
  51. volatile uint32_t ring_addr_lo; /* +20 bits [31:0] of physical address of ring buffer */
  52. volatile uint32_t ring_addr_hi; /* +24 bits [63:32] of physical address of ring buffer */
  53. volatile uint32_t ring_buf_size; /* +28 Ring buffer size (in bytes) */
  54. };
  55. /* Response flag is set in the command when command is completed by PSP.
  56. * Used in the GFX_CTRL.CmdResp.
  57. * When PSP GFX I/F is initialized, the flag is set.
  58. */
  59. #define GFX_FLAG_RESPONSE 0x80000000
  60. /* TEE Gfx Command IDs for the ring buffer interface. */
  61. enum psp_gfx_cmd_id
  62. {
  63. GFX_CMD_ID_LOAD_TA = 0x00000001, /* load TA */
  64. GFX_CMD_ID_UNLOAD_TA = 0x00000002, /* unload TA */
  65. GFX_CMD_ID_INVOKE_CMD = 0x00000003, /* send command to TA */
  66. GFX_CMD_ID_LOAD_ASD = 0x00000004, /* load ASD Driver */
  67. GFX_CMD_ID_SETUP_TMR = 0x00000005, /* setup TMR region */
  68. GFX_CMD_ID_LOAD_IP_FW = 0x00000006, /* load HW IP FW */
  69. };
  70. /* Command to load Trusted Application binary into PSP OS. */
  71. struct psp_gfx_cmd_load_ta
  72. {
  73. uint32_t app_phy_addr_lo; /* bits [31:0] of the physical address of the TA binary (must be 4 KB aligned) */
  74. uint32_t app_phy_addr_hi; /* bits [63:32] of the physical address of the TA binary */
  75. uint32_t app_len; /* length of the TA binary in bytes */
  76. uint32_t cmd_buf_phy_addr_lo; /* bits [31:0] of the physical address of CMD buffer (must be 4 KB aligned) */
  77. uint32_t cmd_buf_phy_addr_hi; /* bits [63:32] of the physical address of CMD buffer */
  78. uint32_t cmd_buf_len; /* length of the CMD buffer in bytes; must be multiple of 4 KB */
  79. /* Note: CmdBufLen can be set to 0. In this case no persistent CMD buffer is provided
  80. * for the TA. Each InvokeCommand can have dinamically mapped CMD buffer instead
  81. * of using global persistent buffer.
  82. */
  83. };
  84. /* Command to Unload Trusted Application binary from PSP OS. */
  85. struct psp_gfx_cmd_unload_ta
  86. {
  87. uint32_t session_id; /* Session ID of the loaded TA to be unloaded */
  88. };
  89. /* Shared buffers for InvokeCommand.
  90. */
  91. struct psp_gfx_buf_desc
  92. {
  93. uint32_t buf_phy_addr_lo; /* bits [31:0] of physical address of the buffer (must be 4 KB aligned) */
  94. uint32_t buf_phy_addr_hi; /* bits [63:32] of physical address of the buffer */
  95. uint32_t buf_size; /* buffer size in bytes (must be multiple of 4 KB and no bigger than 64 MB) */
  96. };
  97. /* Max number of descriptors for one shared buffer (in how many different
  98. * physical locations one shared buffer can be stored). If buffer is too much
  99. * fragmented, error will be returned.
  100. */
  101. #define GFX_BUF_MAX_DESC 64
  102. struct psp_gfx_buf_list
  103. {
  104. uint32_t num_desc; /* number of buffer descriptors in the list */
  105. uint32_t total_size; /* total size of all buffers in the list in bytes (must be multiple of 4 KB) */
  106. struct psp_gfx_buf_desc buf_desc[GFX_BUF_MAX_DESC]; /* list of buffer descriptors */
  107. /* total 776 bytes */
  108. };
  109. /* Command to execute InvokeCommand entry point of the TA. */
  110. struct psp_gfx_cmd_invoke_cmd
  111. {
  112. uint32_t session_id; /* Session ID of the TA to be executed */
  113. uint32_t ta_cmd_id; /* Command ID to be sent to TA */
  114. struct psp_gfx_buf_list buf; /* one indirect buffer (scatter/gather list) */
  115. };
  116. /* Command to setup TMR region. */
  117. struct psp_gfx_cmd_setup_tmr
  118. {
  119. uint32_t buf_phy_addr_lo; /* bits [31:0] of physical address of TMR buffer (must be 4 KB aligned) */
  120. uint32_t buf_phy_addr_hi; /* bits [63:32] of physical address of TMR buffer */
  121. uint32_t buf_size; /* buffer size in bytes (must be multiple of 4 KB) */
  122. };
  123. /* FW types for GFX_CMD_ID_LOAD_IP_FW command. Limit 31. */
  124. enum psp_gfx_fw_type
  125. {
  126. GFX_FW_TYPE_NONE = 0,
  127. GFX_FW_TYPE_CP_ME = 1,
  128. GFX_FW_TYPE_CP_PFP = 2,
  129. GFX_FW_TYPE_CP_CE = 3,
  130. GFX_FW_TYPE_CP_MEC = 4,
  131. GFX_FW_TYPE_CP_MEC_ME1 = 5,
  132. GFX_FW_TYPE_CP_MEC_ME2 = 6,
  133. GFX_FW_TYPE_RLC_V = 7,
  134. GFX_FW_TYPE_RLC_G = 8,
  135. GFX_FW_TYPE_SDMA0 = 9,
  136. GFX_FW_TYPE_SDMA1 = 10,
  137. GFX_FW_TYPE_DMCU_ERAM = 11,
  138. GFX_FW_TYPE_DMCU_ISR = 12,
  139. GFX_FW_TYPE_VCN = 13,
  140. GFX_FW_TYPE_UVD = 14,
  141. GFX_FW_TYPE_VCE = 15,
  142. GFX_FW_TYPE_ISP = 16,
  143. GFX_FW_TYPE_ACP = 17,
  144. GFX_FW_TYPE_SMU = 18,
  145. };
  146. /* Command to load HW IP FW. */
  147. struct psp_gfx_cmd_load_ip_fw
  148. {
  149. uint32_t fw_phy_addr_lo; /* bits [31:0] of physical address of FW location (must be 4 KB aligned) */
  150. uint32_t fw_phy_addr_hi; /* bits [63:32] of physical address of FW location */
  151. uint32_t fw_size; /* FW buffer size in bytes */
  152. enum psp_gfx_fw_type fw_type; /* FW type */
  153. };
  154. /* All GFX ring buffer commands. */
  155. union psp_gfx_commands
  156. {
  157. struct psp_gfx_cmd_load_ta cmd_load_ta;
  158. struct psp_gfx_cmd_unload_ta cmd_unload_ta;
  159. struct psp_gfx_cmd_invoke_cmd cmd_invoke_cmd;
  160. struct psp_gfx_cmd_setup_tmr cmd_setup_tmr;
  161. struct psp_gfx_cmd_load_ip_fw cmd_load_ip_fw;
  162. };
  163. /* Structure of GFX Response buffer.
  164. * For GPCOM I/F it is part of GFX_CMD_RESP buffer, for RBI
  165. * it is separate buffer.
  166. */
  167. struct psp_gfx_resp
  168. {
  169. uint32_t status; /* +0 status of command execution */
  170. uint32_t session_id; /* +4 session ID in response to LoadTa command */
  171. uint32_t fw_addr_lo; /* +8 bits [31:0] of FW address within TMR (in response to cmd_load_ip_fw command) */
  172. uint32_t fw_addr_hi; /* +12 bits [63:32] of FW address within TMR (in response to cmd_load_ip_fw command) */
  173. uint32_t reserved[4];
  174. /* total 32 bytes */
  175. };
  176. /* Structure of Command buffer pointed by psp_gfx_rb_frame.cmd_buf_addr_hi
  177. * and psp_gfx_rb_frame.cmd_buf_addr_lo.
  178. */
  179. struct psp_gfx_cmd_resp
  180. {
  181. uint32_t buf_size; /* +0 total size of the buffer in bytes */
  182. uint32_t buf_version; /* +4 version of the buffer strusture; must be PSP_GFX_CMD_BUF_VERSION */
  183. uint32_t cmd_id; /* +8 command ID */
  184. /* These fields are used for RBI only. They are all 0 in GPCOM commands
  185. */
  186. uint32_t resp_buf_addr_lo; /* +12 bits [31:0] of physical address of response buffer (must be 4 KB aligned) */
  187. uint32_t resp_buf_addr_hi; /* +16 bits [63:32] of physical address of response buffer */
  188. uint32_t resp_offset; /* +20 offset within response buffer */
  189. uint32_t resp_buf_size; /* +24 total size of the response buffer in bytes */
  190. union psp_gfx_commands cmd; /* +28 command specific structures */
  191. uint8_t reserved_1[864 - sizeof(union psp_gfx_commands) - 28];
  192. /* Note: Resp is part of this buffer for GPCOM ring. For RBI ring the response
  193. * is separate buffer pointed by resp_buf_addr_hi and resp_buf_addr_lo.
  194. */
  195. struct psp_gfx_resp resp; /* +864 response */
  196. uint8_t reserved_2[1024 - 864 - sizeof(struct psp_gfx_resp)];
  197. /* total size 1024 bytes */
  198. };
  199. #define FRAME_TYPE_DESTROY 1 /* frame sent by KMD driver when UMD Scheduler context is destroyed*/
  200. /* Structure of the Ring Buffer Frame */
  201. struct psp_gfx_rb_frame
  202. {
  203. uint32_t cmd_buf_addr_lo; /* +0 bits [31:0] of physical address of command buffer (must be 4 KB aligned) */
  204. uint32_t cmd_buf_addr_hi; /* +4 bits [63:32] of physical address of command buffer */
  205. uint32_t cmd_buf_size; /* +8 command buffer size in bytes */
  206. uint32_t fence_addr_lo; /* +12 bits [31:0] of physical address of Fence for this frame */
  207. uint32_t fence_addr_hi; /* +16 bits [63:32] of physical address of Fence for this frame */
  208. uint32_t fence_value; /* +20 Fence value */
  209. uint32_t sid_lo; /* +24 bits [31:0] of SID value (used only for RBI frames) */
  210. uint32_t sid_hi; /* +28 bits [63:32] of SID value (used only for RBI frames) */
  211. uint8_t vmid; /* +32 VMID value used for mapping of all addresses for this frame */
  212. uint8_t frame_type; /* +33 1: destory context frame, 0: all other frames; used only for RBI frames */
  213. uint8_t reserved1[2]; /* +34 reserved, must be 0 */
  214. uint32_t reserved2[7]; /* +40 reserved, must be 0 */
  215. /* total 64 bytes */
  216. };
  217. #endif /* _PSP_TEE_GFX_IF_H_ */