amdgpu_ucode.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 gfx_firmware_header_v1_0 {
  50. struct common_firmware_header header;
  51. uint32_t ucode_feature_version;
  52. uint32_t jt_offset; /* jt location */
  53. uint32_t jt_size; /* size of jt */
  54. };
  55. /* version_major=1, version_minor=0 */
  56. struct rlc_firmware_header_v1_0 {
  57. struct common_firmware_header header;
  58. uint32_t ucode_feature_version;
  59. uint32_t save_and_restore_offset;
  60. uint32_t clear_state_descriptor_offset;
  61. uint32_t avail_scratch_ram_locations;
  62. uint32_t master_pkt_description_offset;
  63. };
  64. /* version_major=2, version_minor=0 */
  65. struct rlc_firmware_header_v2_0 {
  66. struct common_firmware_header header;
  67. uint32_t ucode_feature_version;
  68. uint32_t jt_offset; /* jt location */
  69. uint32_t jt_size; /* size of jt */
  70. uint32_t save_and_restore_offset;
  71. uint32_t clear_state_descriptor_offset;
  72. uint32_t avail_scratch_ram_locations;
  73. uint32_t reg_restore_list_size;
  74. uint32_t reg_list_format_start;
  75. uint32_t reg_list_format_separate_start;
  76. uint32_t starting_offsets_start;
  77. uint32_t reg_list_format_size_bytes; /* size of reg list format array in bytes */
  78. uint32_t reg_list_format_array_offset_bytes; /* payload offset from the start of the header */
  79. uint32_t reg_list_size_bytes; /* size of reg list array in bytes */
  80. uint32_t reg_list_array_offset_bytes; /* payload offset from the start of the header */
  81. uint32_t reg_list_format_separate_size_bytes; /* size of reg list format array in bytes */
  82. uint32_t reg_list_format_separate_array_offset_bytes; /* payload offset from the start of the header */
  83. uint32_t reg_list_separate_size_bytes; /* size of reg list array in bytes */
  84. uint32_t reg_list_separate_array_offset_bytes; /* payload offset from the start of the header */
  85. };
  86. /* version_major=1, version_minor=0 */
  87. struct sdma_firmware_header_v1_0 {
  88. struct common_firmware_header header;
  89. uint32_t ucode_feature_version;
  90. uint32_t ucode_change_version;
  91. uint32_t jt_offset; /* jt location */
  92. uint32_t jt_size; /* size of jt */
  93. };
  94. /* version_major=1, version_minor=1 */
  95. struct sdma_firmware_header_v1_1 {
  96. struct sdma_firmware_header_v1_0 v1_0;
  97. uint32_t digest_size;
  98. };
  99. /* header is fixed size */
  100. union amdgpu_firmware_header {
  101. struct common_firmware_header common;
  102. struct mc_firmware_header_v1_0 mc;
  103. struct smc_firmware_header_v1_0 smc;
  104. struct gfx_firmware_header_v1_0 gfx;
  105. struct rlc_firmware_header_v1_0 rlc;
  106. struct rlc_firmware_header_v2_0 rlc_v2_0;
  107. struct sdma_firmware_header_v1_0 sdma;
  108. struct sdma_firmware_header_v1_1 sdma_v1_1;
  109. uint8_t raw[0x100];
  110. };
  111. /*
  112. * fw loading support
  113. */
  114. enum AMDGPU_UCODE_ID {
  115. AMDGPU_UCODE_ID_SDMA0 = 0,
  116. AMDGPU_UCODE_ID_SDMA1,
  117. AMDGPU_UCODE_ID_CP_CE,
  118. AMDGPU_UCODE_ID_CP_PFP,
  119. AMDGPU_UCODE_ID_CP_ME,
  120. AMDGPU_UCODE_ID_CP_MEC1,
  121. AMDGPU_UCODE_ID_CP_MEC2,
  122. AMDGPU_UCODE_ID_RLC_G,
  123. AMDGPU_UCODE_ID_MAXIMUM,
  124. };
  125. /* engine firmware status */
  126. enum AMDGPU_UCODE_STATUS {
  127. AMDGPU_UCODE_STATUS_INVALID,
  128. AMDGPU_UCODE_STATUS_NOT_LOADED,
  129. AMDGPU_UCODE_STATUS_LOADED,
  130. };
  131. /* conform to smu_ucode_xfer_cz.h */
  132. #define AMDGPU_SDMA0_UCODE_LOADED 0x00000001
  133. #define AMDGPU_SDMA1_UCODE_LOADED 0x00000002
  134. #define AMDGPU_CPCE_UCODE_LOADED 0x00000004
  135. #define AMDGPU_CPPFP_UCODE_LOADED 0x00000008
  136. #define AMDGPU_CPME_UCODE_LOADED 0x00000010
  137. #define AMDGPU_CPMEC1_UCODE_LOADED 0x00000020
  138. #define AMDGPU_CPMEC2_UCODE_LOADED 0x00000040
  139. #define AMDGPU_CPRLC_UCODE_LOADED 0x00000100
  140. /* amdgpu firmware info */
  141. struct amdgpu_firmware_info {
  142. /* ucode ID */
  143. enum AMDGPU_UCODE_ID ucode_id;
  144. /* request_firmware */
  145. const struct firmware *fw;
  146. /* starting mc address */
  147. uint64_t mc_addr;
  148. /* kernel linear address */
  149. void *kaddr;
  150. };
  151. void amdgpu_ucode_print_mc_hdr(const struct common_firmware_header *hdr);
  152. void amdgpu_ucode_print_smc_hdr(const struct common_firmware_header *hdr);
  153. void amdgpu_ucode_print_gfx_hdr(const struct common_firmware_header *hdr);
  154. void amdgpu_ucode_print_rlc_hdr(const struct common_firmware_header *hdr);
  155. void amdgpu_ucode_print_sdma_hdr(const struct common_firmware_header *hdr);
  156. int amdgpu_ucode_validate(const struct firmware *fw);
  157. bool amdgpu_ucode_hdr_version(union amdgpu_firmware_header *hdr,
  158. uint16_t hdr_major, uint16_t hdr_minor);
  159. int amdgpu_ucode_init_bo(struct amdgpu_device *adev);
  160. int amdgpu_ucode_fini_bo(struct amdgpu_device *adev);
  161. #endif