amdgpu_ucode.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*
  2. * Copyright 2012 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 __AMDGPU_UCODE_H__
  24. #define __AMDGPU_UCODE_H__
  25. struct common_firmware_header {
  26. uint32_t size_bytes; /* size of the entire header+image(s) in bytes */
  27. uint32_t header_size_bytes; /* size of just the header in bytes */
  28. uint16_t header_version_major; /* header version */
  29. uint16_t header_version_minor; /* header version */
  30. uint16_t ip_version_major; /* IP version */
  31. uint16_t ip_version_minor; /* IP version */
  32. uint32_t ucode_version;
  33. uint32_t ucode_size_bytes; /* size of ucode in bytes */
  34. uint32_t ucode_array_offset_bytes; /* payload offset from the start of the header */
  35. uint32_t crc32; /* crc32 checksum of the payload */
  36. };
  37. /* version_major=1, version_minor=0 */
  38. struct mc_firmware_header_v1_0 {
  39. struct common_firmware_header header;
  40. uint32_t io_debug_size_bytes; /* size of debug array in dwords */
  41. uint32_t io_debug_array_offset_bytes; /* payload offset from the start of the header */
  42. };
  43. /* version_major=1, version_minor=0 */
  44. struct smc_firmware_header_v1_0 {
  45. struct common_firmware_header header;
  46. uint32_t ucode_start_addr;
  47. };
  48. /* version_major=1, version_minor=0 */
  49. struct psp_firmware_header_v1_0 {
  50. struct common_firmware_header header;
  51. uint32_t ucode_feature_version;
  52. uint32_t sos_offset_bytes;
  53. uint32_t sos_size_bytes;
  54. };
  55. /* version_major=1, version_minor=0 */
  56. struct gfx_firmware_header_v1_0 {
  57. struct common_firmware_header header;
  58. uint32_t ucode_feature_version;
  59. uint32_t jt_offset; /* jt location */
  60. uint32_t jt_size; /* size of jt */
  61. };
  62. /* version_major=1, version_minor=0 */
  63. struct rlc_firmware_header_v1_0 {
  64. struct common_firmware_header header;
  65. uint32_t ucode_feature_version;
  66. uint32_t save_and_restore_offset;
  67. uint32_t clear_state_descriptor_offset;
  68. uint32_t avail_scratch_ram_locations;
  69. uint32_t master_pkt_description_offset;
  70. };
  71. /* version_major=2, version_minor=0 */
  72. struct rlc_firmware_header_v2_0 {
  73. struct common_firmware_header header;
  74. uint32_t ucode_feature_version;
  75. uint32_t jt_offset; /* jt location */
  76. uint32_t jt_size; /* size of jt */
  77. uint32_t save_and_restore_offset;
  78. uint32_t clear_state_descriptor_offset;
  79. uint32_t avail_scratch_ram_locations;
  80. uint32_t reg_restore_list_size;
  81. uint32_t reg_list_format_start;
  82. uint32_t reg_list_format_separate_start;
  83. uint32_t starting_offsets_start;
  84. uint32_t reg_list_format_size_bytes; /* size of reg list format array in bytes */
  85. uint32_t reg_list_format_array_offset_bytes; /* payload offset from the start of the header */
  86. uint32_t reg_list_size_bytes; /* size of reg list array in bytes */
  87. uint32_t reg_list_array_offset_bytes; /* payload offset from the start of the header */
  88. uint32_t reg_list_format_separate_size_bytes; /* size of reg list format array in bytes */
  89. uint32_t reg_list_format_separate_array_offset_bytes; /* payload offset from the start of the header */
  90. uint32_t reg_list_separate_size_bytes; /* size of reg list array in bytes */
  91. uint32_t reg_list_separate_array_offset_bytes; /* payload offset from the start of the header */
  92. };
  93. /* version_major=1, version_minor=0 */
  94. struct sdma_firmware_header_v1_0 {
  95. struct common_firmware_header header;
  96. uint32_t ucode_feature_version;
  97. uint32_t ucode_change_version;
  98. uint32_t jt_offset; /* jt location */
  99. uint32_t jt_size; /* size of jt */
  100. };
  101. /* version_major=1, version_minor=1 */
  102. struct sdma_firmware_header_v1_1 {
  103. struct sdma_firmware_header_v1_0 v1_0;
  104. uint32_t digest_size;
  105. };
  106. /* gpu info payload */
  107. struct gpu_info_firmware_v1_0 {
  108. uint32_t gc_num_se;
  109. uint32_t gc_num_cu_per_sh;
  110. uint32_t gc_num_sh_per_se;
  111. uint32_t gc_num_rb_per_se;
  112. uint32_t gc_num_tccs;
  113. uint32_t gc_num_gprs;
  114. uint32_t gc_num_max_gs_thds;
  115. uint32_t gc_gs_table_depth;
  116. uint32_t gc_gsprim_buff_depth;
  117. uint32_t gc_parameter_cache_depth;
  118. uint32_t gc_double_offchip_lds_buffer;
  119. uint32_t gc_wave_size;
  120. uint32_t gc_max_waves_per_simd;
  121. uint32_t gc_max_scratch_slots_per_cu;
  122. uint32_t gc_lds_size;
  123. };
  124. /* version_major=1, version_minor=0 */
  125. struct gpu_info_firmware_header_v1_0 {
  126. struct common_firmware_header header;
  127. uint16_t version_major; /* version */
  128. uint16_t version_minor; /* version */
  129. };
  130. /* header is fixed size */
  131. union amdgpu_firmware_header {
  132. struct common_firmware_header common;
  133. struct mc_firmware_header_v1_0 mc;
  134. struct smc_firmware_header_v1_0 smc;
  135. struct psp_firmware_header_v1_0 psp;
  136. struct gfx_firmware_header_v1_0 gfx;
  137. struct rlc_firmware_header_v1_0 rlc;
  138. struct rlc_firmware_header_v2_0 rlc_v2_0;
  139. struct sdma_firmware_header_v1_0 sdma;
  140. struct sdma_firmware_header_v1_1 sdma_v1_1;
  141. struct gpu_info_firmware_header_v1_0 gpu_info;
  142. uint8_t raw[0x100];
  143. };
  144. /*
  145. * fw loading support
  146. */
  147. enum AMDGPU_UCODE_ID {
  148. AMDGPU_UCODE_ID_SDMA0 = 0,
  149. AMDGPU_UCODE_ID_SDMA1,
  150. AMDGPU_UCODE_ID_CP_CE,
  151. AMDGPU_UCODE_ID_CP_PFP,
  152. AMDGPU_UCODE_ID_CP_ME,
  153. AMDGPU_UCODE_ID_CP_MEC1,
  154. AMDGPU_UCODE_ID_CP_MEC1_JT,
  155. AMDGPU_UCODE_ID_CP_MEC2,
  156. AMDGPU_UCODE_ID_CP_MEC2_JT,
  157. AMDGPU_UCODE_ID_RLC_G,
  158. AMDGPU_UCODE_ID_STORAGE,
  159. AMDGPU_UCODE_ID_SMC,
  160. AMDGPU_UCODE_ID_UVD,
  161. AMDGPU_UCODE_ID_VCE,
  162. AMDGPU_UCODE_ID_VCN,
  163. AMDGPU_UCODE_ID_MAXIMUM,
  164. };
  165. /* engine firmware status */
  166. enum AMDGPU_UCODE_STATUS {
  167. AMDGPU_UCODE_STATUS_INVALID,
  168. AMDGPU_UCODE_STATUS_NOT_LOADED,
  169. AMDGPU_UCODE_STATUS_LOADED,
  170. };
  171. /* conform to smu_ucode_xfer_cz.h */
  172. #define AMDGPU_SDMA0_UCODE_LOADED 0x00000001
  173. #define AMDGPU_SDMA1_UCODE_LOADED 0x00000002
  174. #define AMDGPU_CPCE_UCODE_LOADED 0x00000004
  175. #define AMDGPU_CPPFP_UCODE_LOADED 0x00000008
  176. #define AMDGPU_CPME_UCODE_LOADED 0x00000010
  177. #define AMDGPU_CPMEC1_UCODE_LOADED 0x00000020
  178. #define AMDGPU_CPMEC2_UCODE_LOADED 0x00000040
  179. #define AMDGPU_CPRLC_UCODE_LOADED 0x00000100
  180. /* amdgpu firmware info */
  181. struct amdgpu_firmware_info {
  182. /* ucode ID */
  183. enum AMDGPU_UCODE_ID ucode_id;
  184. /* request_firmware */
  185. const struct firmware *fw;
  186. /* starting mc address */
  187. uint64_t mc_addr;
  188. /* kernel linear address */
  189. void *kaddr;
  190. /* ucode_size_bytes */
  191. uint32_t ucode_size;
  192. /* starting tmr mc address */
  193. uint32_t tmr_mc_addr_lo;
  194. uint32_t tmr_mc_addr_hi;
  195. };
  196. void amdgpu_ucode_print_mc_hdr(const struct common_firmware_header *hdr);
  197. void amdgpu_ucode_print_smc_hdr(const struct common_firmware_header *hdr);
  198. void amdgpu_ucode_print_gfx_hdr(const struct common_firmware_header *hdr);
  199. void amdgpu_ucode_print_rlc_hdr(const struct common_firmware_header *hdr);
  200. void amdgpu_ucode_print_sdma_hdr(const struct common_firmware_header *hdr);
  201. void amdgpu_ucode_print_gpu_info_hdr(const struct common_firmware_header *hdr);
  202. int amdgpu_ucode_validate(const struct firmware *fw);
  203. bool amdgpu_ucode_hdr_version(union amdgpu_firmware_header *hdr,
  204. uint16_t hdr_major, uint16_t hdr_minor);
  205. int amdgpu_ucode_init_bo(struct amdgpu_device *adev);
  206. int amdgpu_ucode_fini_bo(struct amdgpu_device *adev);
  207. enum amdgpu_firmware_load_type
  208. amdgpu_ucode_get_load_type(struct amdgpu_device *adev, int load_type);
  209. #endif