amdgpu_psp.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * Copyright 2016 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. * Author: Huang Rui
  23. *
  24. */
  25. #ifndef __AMDGPU_PSP_H__
  26. #define __AMDGPU_PSP_H__
  27. #include "amdgpu.h"
  28. #include "psp_gfx_if.h"
  29. #define PSP_FENCE_BUFFER_SIZE 0x1000
  30. #define PSP_CMD_BUFFER_SIZE 0x1000
  31. #define PSP_ASD_SHARED_MEM_SIZE 0x4000
  32. #define PSP_1_MEG 0x100000
  33. #define PSP_TMR_SIZE 0x400000
  34. struct psp_context;
  35. struct psp_xgmi_topology_info;
  36. enum psp_ring_type
  37. {
  38. PSP_RING_TYPE__INVALID = 0,
  39. /*
  40. * These values map to the way the PSP kernel identifies the
  41. * rings.
  42. */
  43. PSP_RING_TYPE__UM = 1, /* User mode ring (formerly called RBI) */
  44. PSP_RING_TYPE__KM = 2 /* Kernel mode ring (formerly called GPCOM) */
  45. };
  46. struct psp_ring
  47. {
  48. enum psp_ring_type ring_type;
  49. struct psp_gfx_rb_frame *ring_mem;
  50. uint64_t ring_mem_mc_addr;
  51. void *ring_mem_handle;
  52. uint32_t ring_size;
  53. };
  54. struct psp_funcs
  55. {
  56. int (*init_microcode)(struct psp_context *psp);
  57. int (*bootloader_load_sysdrv)(struct psp_context *psp);
  58. int (*bootloader_load_sos)(struct psp_context *psp);
  59. int (*prep_cmd_buf)(struct amdgpu_firmware_info *ucode,
  60. struct psp_gfx_cmd_resp *cmd);
  61. int (*ring_init)(struct psp_context *psp, enum psp_ring_type ring_type);
  62. int (*ring_create)(struct psp_context *psp,
  63. enum psp_ring_type ring_type);
  64. int (*ring_stop)(struct psp_context *psp,
  65. enum psp_ring_type ring_type);
  66. int (*ring_destroy)(struct psp_context *psp,
  67. enum psp_ring_type ring_type);
  68. int (*cmd_submit)(struct psp_context *psp,
  69. struct amdgpu_firmware_info *ucode,
  70. uint64_t cmd_buf_mc_addr, uint64_t fence_mc_addr,
  71. int index);
  72. bool (*compare_sram_data)(struct psp_context *psp,
  73. struct amdgpu_firmware_info *ucode,
  74. enum AMDGPU_UCODE_ID ucode_type);
  75. bool (*smu_reload_quirk)(struct psp_context *psp);
  76. int (*mode1_reset)(struct psp_context *psp);
  77. uint64_t (*xgmi_get_device_id)(struct psp_context *psp);
  78. uint64_t (*xgmi_get_hive_id)(struct psp_context *psp);
  79. int (*xgmi_get_topology_info)(struct psp_context *psp, int number_devices,
  80. struct psp_xgmi_topology_info *topology);
  81. int (*xgmi_set_topology_info)(struct psp_context *psp, int number_devices,
  82. struct psp_xgmi_topology_info *topology);
  83. };
  84. struct psp_context
  85. {
  86. struct amdgpu_device *adev;
  87. struct psp_ring km_ring;
  88. struct psp_gfx_cmd_resp *cmd;
  89. const struct psp_funcs *funcs;
  90. /* fence buffer */
  91. struct amdgpu_bo *fw_pri_bo;
  92. uint64_t fw_pri_mc_addr;
  93. void *fw_pri_buf;
  94. /* sos firmware */
  95. const struct firmware *sos_fw;
  96. uint32_t sos_fw_version;
  97. uint32_t sos_feature_version;
  98. uint32_t sys_bin_size;
  99. uint32_t sos_bin_size;
  100. uint8_t *sys_start_addr;
  101. uint8_t *sos_start_addr;
  102. /* tmr buffer */
  103. struct amdgpu_bo *tmr_bo;
  104. uint64_t tmr_mc_addr;
  105. void *tmr_buf;
  106. /* asd firmware and buffer */
  107. const struct firmware *asd_fw;
  108. uint32_t asd_fw_version;
  109. uint32_t asd_feature_version;
  110. uint32_t asd_ucode_size;
  111. uint8_t *asd_start_addr;
  112. struct amdgpu_bo *asd_shared_bo;
  113. uint64_t asd_shared_mc_addr;
  114. void *asd_shared_buf;
  115. /* fence buffer */
  116. struct amdgpu_bo *fence_buf_bo;
  117. uint64_t fence_buf_mc_addr;
  118. void *fence_buf;
  119. /* cmd buffer */
  120. struct amdgpu_bo *cmd_buf_bo;
  121. uint64_t cmd_buf_mc_addr;
  122. struct psp_gfx_cmd_resp *cmd_buf_mem;
  123. };
  124. struct amdgpu_psp_funcs {
  125. bool (*check_fw_loading_status)(struct amdgpu_device *adev,
  126. enum AMDGPU_UCODE_ID);
  127. };
  128. struct psp_xgmi_topology_info {
  129. /* Generated by PSP to identify the GPU instance within xgmi connection */
  130. uint64_t device_id;
  131. /*
  132. * If all bits set to 0 , driver indicates it wants to retrieve the xgmi
  133. * connection vector topology, but not access enable the connections
  134. * if some or all bits are set to 1, driver indicates it want to retrieve the
  135. * current xgmi topology and access enable the link to GPU[i] associated
  136. * with the bit position in the vector.
  137. * On return,: bits indicated which xgmi links are present/active depending
  138. * on the value passed in. The relative bit offset for the relative GPU index
  139. * within the hive is always marked active.
  140. */
  141. uint32_t connection_mask;
  142. uint32_t reserved; /* must be 0 */
  143. };
  144. #define psp_prep_cmd_buf(ucode, type) (psp)->funcs->prep_cmd_buf((ucode), (type))
  145. #define psp_ring_init(psp, type) (psp)->funcs->ring_init((psp), (type))
  146. #define psp_ring_create(psp, type) (psp)->funcs->ring_create((psp), (type))
  147. #define psp_ring_stop(psp, type) (psp)->funcs->ring_stop((psp), (type))
  148. #define psp_ring_destroy(psp, type) ((psp)->funcs->ring_destroy((psp), (type)))
  149. #define psp_cmd_submit(psp, ucode, cmd_mc, fence_mc, index) \
  150. (psp)->funcs->cmd_submit((psp), (ucode), (cmd_mc), (fence_mc), (index))
  151. #define psp_compare_sram_data(psp, ucode, type) \
  152. (psp)->funcs->compare_sram_data((psp), (ucode), (type))
  153. #define psp_init_microcode(psp) \
  154. ((psp)->funcs->init_microcode ? (psp)->funcs->init_microcode((psp)) : 0)
  155. #define psp_bootloader_load_sysdrv(psp) \
  156. ((psp)->funcs->bootloader_load_sysdrv ? (psp)->funcs->bootloader_load_sysdrv((psp)) : 0)
  157. #define psp_bootloader_load_sos(psp) \
  158. ((psp)->funcs->bootloader_load_sos ? (psp)->funcs->bootloader_load_sos((psp)) : 0)
  159. #define psp_smu_reload_quirk(psp) \
  160. ((psp)->funcs->smu_reload_quirk ? (psp)->funcs->smu_reload_quirk((psp)) : false)
  161. #define psp_mode1_reset(psp) \
  162. ((psp)->funcs->mode1_reset ? (psp)->funcs->mode1_reset((psp)) : false)
  163. #define psp_xgmi_get_device_id(psp) \
  164. ((psp)->funcs->xgmi_get_device_id ? (psp)->funcs->xgmi_get_device_id((psp)) : 0)
  165. #define psp_xgmi_get_hive_id(psp) \
  166. ((psp)->funcs->xgmi_get_hive_id ? (psp)->funcs->xgmi_get_hive_id((psp)) : 0)
  167. #define psp_xgmi_get_topology_info(psp, num_device, topology) \
  168. ((psp)->funcs->xgmi_get_topology_info ? \
  169. (psp)->funcs->xgmi_get_topology_info((psp), (num_device), (topology)) : -EINVAL)
  170. #define psp_xgmi_set_topology_info(psp, num_device, topology) \
  171. ((psp)->funcs->xgmi_set_topology_info ? \
  172. (psp)->funcs->xgmi_set_topology_info((psp), (num_device), (topology)) : -EINVAL)
  173. #define amdgpu_psp_check_fw_loading_status(adev, i) (adev)->firmware.funcs->check_fw_loading_status((adev), (i))
  174. extern const struct amd_ip_funcs psp_ip_funcs;
  175. extern const struct amdgpu_ip_block_version psp_v3_1_ip_block;
  176. extern int psp_wait_for(struct psp_context *psp, uint32_t reg_index,
  177. uint32_t field_val, uint32_t mask, bool check_changed);
  178. extern const struct amdgpu_ip_block_version psp_v10_0_ip_block;
  179. int psp_gpu_reset(struct amdgpu_device *adev);
  180. extern const struct amdgpu_ip_block_version psp_v11_0_ip_block;
  181. #endif