2 * Copyright 2012 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
23 #ifndef __AMDGPU_UCODE_H__
24 #define __AMDGPU_UCODE_H__
26 #include "amdgpu_socbb.h"
28 struct common_firmware_header {
29 uint32_t size_bytes; /* size of the entire header+image(s) in bytes */
30 uint32_t header_size_bytes; /* size of just the header in bytes */
31 uint16_t header_version_major; /* header version */
32 uint16_t header_version_minor; /* header version */
33 uint16_t ip_version_major; /* IP version */
34 uint16_t ip_version_minor; /* IP version */
35 uint32_t ucode_version;
36 uint32_t ucode_size_bytes; /* size of ucode in bytes */
37 uint32_t ucode_array_offset_bytes; /* payload offset from the start of the header */
38 uint32_t crc32; /* crc32 checksum of the payload */
41 /* version_major=1, version_minor=0 */
42 struct mc_firmware_header_v1_0 {
43 struct common_firmware_header header;
44 uint32_t io_debug_size_bytes; /* size of debug array in dwords */
45 uint32_t io_debug_array_offset_bytes; /* payload offset from the start of the header */
48 /* version_major=1, version_minor=0 */
49 struct smc_firmware_header_v1_0 {
50 struct common_firmware_header header;
51 uint32_t ucode_start_addr;
54 /* version_major=2, version_minor=0 */
55 struct smc_firmware_header_v2_0 {
56 struct smc_firmware_header_v1_0 v1_0;
57 uint32_t ppt_offset_bytes; /* soft pptable offset */
58 uint32_t ppt_size_bytes; /* soft pptable size */
61 struct smc_soft_pptable_entry {
63 uint32_t ppt_offset_bytes;
64 uint32_t ppt_size_bytes;
67 /* version_major=2, version_minor=1 */
68 struct smc_firmware_header_v2_1 {
69 struct smc_firmware_header_v1_0 v1_0;
70 uint32_t pptable_count;
71 uint32_t pptable_entry_offset;
74 struct psp_fw_legacy_bin_desc {
76 uint32_t offset_bytes;
80 /* version_major=1, version_minor=0 */
81 struct psp_firmware_header_v1_0 {
82 struct common_firmware_header header;
83 struct psp_fw_legacy_bin_desc sos;
86 /* version_major=1, version_minor=1 */
87 struct psp_firmware_header_v1_1 {
88 struct psp_firmware_header_v1_0 v1_0;
89 struct psp_fw_legacy_bin_desc toc;
90 struct psp_fw_legacy_bin_desc kdb;
93 /* version_major=1, version_minor=2 */
94 struct psp_firmware_header_v1_2 {
95 struct psp_firmware_header_v1_0 v1_0;
96 struct psp_fw_legacy_bin_desc res;
97 struct psp_fw_legacy_bin_desc kdb;
100 /* version_major=1, version_minor=3 */
101 struct psp_firmware_header_v1_3 {
102 struct psp_firmware_header_v1_1 v1_1;
103 struct psp_fw_legacy_bin_desc spl;
104 struct psp_fw_legacy_bin_desc rl;
105 struct psp_fw_legacy_bin_desc sys_drv_aux;
106 struct psp_fw_legacy_bin_desc sos_aux;
109 struct psp_fw_bin_desc {
112 uint32_t offset_bytes;
119 PSP_FW_TYPE_PSP_SYS_DRV,
126 /* version_major=2, version_minor=0 */
127 struct psp_firmware_header_v2_0 {
128 struct common_firmware_header header;
129 uint32_t psp_fw_bin_count;
130 struct psp_fw_bin_desc psp_fw_bin[];
133 /* version_major=1, version_minor=0 */
134 struct ta_firmware_header_v1_0 {
135 struct common_firmware_header header;
136 uint32_t ta_xgmi_ucode_version;
137 uint32_t ta_xgmi_offset_bytes;
138 uint32_t ta_xgmi_size_bytes;
139 uint32_t ta_ras_ucode_version;
140 uint32_t ta_ras_offset_bytes;
141 uint32_t ta_ras_size_bytes;
142 uint32_t ta_hdcp_ucode_version;
143 uint32_t ta_hdcp_offset_bytes;
144 uint32_t ta_hdcp_size_bytes;
145 uint32_t ta_dtm_ucode_version;
146 uint32_t ta_dtm_offset_bytes;
147 uint32_t ta_dtm_size_bytes;
148 uint32_t ta_securedisplay_ucode_version;
149 uint32_t ta_securedisplay_offset_bytes;
150 uint32_t ta_securedisplay_size_bytes;
161 TA_FW_TYPE_PSP_SECUREDISPLAY,
162 TA_FW_TYPE_MAX_INDEX,
165 /* version_major=2, version_minor=0 */
166 struct ta_firmware_header_v2_0 {
167 struct common_firmware_header header;
168 uint32_t ta_fw_bin_count;
169 struct psp_fw_bin_desc ta_fw_bin[];
172 /* version_major=1, version_minor=0 */
173 struct gfx_firmware_header_v1_0 {
174 struct common_firmware_header header;
175 uint32_t ucode_feature_version;
176 uint32_t jt_offset; /* jt location */
177 uint32_t jt_size; /* size of jt */
180 /* version_major=1, version_minor=0 */
181 struct mes_firmware_header_v1_0 {
182 struct common_firmware_header header;
183 uint32_t mes_ucode_version;
184 uint32_t mes_ucode_size_bytes;
185 uint32_t mes_ucode_offset_bytes;
186 uint32_t mes_ucode_data_version;
187 uint32_t mes_ucode_data_size_bytes;
188 uint32_t mes_ucode_data_offset_bytes;
189 uint32_t mes_uc_start_addr_lo;
190 uint32_t mes_uc_start_addr_hi;
191 uint32_t mes_data_start_addr_lo;
192 uint32_t mes_data_start_addr_hi;
195 /* version_major=1, version_minor=0 */
196 struct rlc_firmware_header_v1_0 {
197 struct common_firmware_header header;
198 uint32_t ucode_feature_version;
199 uint32_t save_and_restore_offset;
200 uint32_t clear_state_descriptor_offset;
201 uint32_t avail_scratch_ram_locations;
202 uint32_t master_pkt_description_offset;
205 /* version_major=2, version_minor=0 */
206 struct rlc_firmware_header_v2_0 {
207 struct common_firmware_header header;
208 uint32_t ucode_feature_version;
209 uint32_t jt_offset; /* jt location */
210 uint32_t jt_size; /* size of jt */
211 uint32_t save_and_restore_offset;
212 uint32_t clear_state_descriptor_offset;
213 uint32_t avail_scratch_ram_locations;
214 uint32_t reg_restore_list_size;
215 uint32_t reg_list_format_start;
216 uint32_t reg_list_format_separate_start;
217 uint32_t starting_offsets_start;
218 uint32_t reg_list_format_size_bytes; /* size of reg list format array in bytes */
219 uint32_t reg_list_format_array_offset_bytes; /* payload offset from the start of the header */
220 uint32_t reg_list_size_bytes; /* size of reg list array in bytes */
221 uint32_t reg_list_array_offset_bytes; /* payload offset from the start of the header */
222 uint32_t reg_list_format_separate_size_bytes; /* size of reg list format array in bytes */
223 uint32_t reg_list_format_separate_array_offset_bytes; /* payload offset from the start of the header */
224 uint32_t reg_list_separate_size_bytes; /* size of reg list array in bytes */
225 uint32_t reg_list_separate_array_offset_bytes; /* payload offset from the start of the header */
228 /* version_major=2, version_minor=1 */
229 struct rlc_firmware_header_v2_1 {
230 struct rlc_firmware_header_v2_0 v2_0;
231 uint32_t reg_list_format_direct_reg_list_length; /* length of direct reg list format array */
232 uint32_t save_restore_list_cntl_ucode_ver;
233 uint32_t save_restore_list_cntl_feature_ver;
234 uint32_t save_restore_list_cntl_size_bytes;
235 uint32_t save_restore_list_cntl_offset_bytes;
236 uint32_t save_restore_list_gpm_ucode_ver;
237 uint32_t save_restore_list_gpm_feature_ver;
238 uint32_t save_restore_list_gpm_size_bytes;
239 uint32_t save_restore_list_gpm_offset_bytes;
240 uint32_t save_restore_list_srm_ucode_ver;
241 uint32_t save_restore_list_srm_feature_ver;
242 uint32_t save_restore_list_srm_size_bytes;
243 uint32_t save_restore_list_srm_offset_bytes;
246 /* version_major=2, version_minor=1 */
247 struct rlc_firmware_header_v2_2 {
248 struct rlc_firmware_header_v2_1 v2_1;
249 uint32_t rlc_iram_ucode_size_bytes;
250 uint32_t rlc_iram_ucode_offset_bytes;
251 uint32_t rlc_dram_ucode_size_bytes;
252 uint32_t rlc_dram_ucode_offset_bytes;
255 /* version_major=1, version_minor=0 */
256 struct sdma_firmware_header_v1_0 {
257 struct common_firmware_header header;
258 uint32_t ucode_feature_version;
259 uint32_t ucode_change_version;
260 uint32_t jt_offset; /* jt location */
261 uint32_t jt_size; /* size of jt */
264 /* version_major=1, version_minor=1 */
265 struct sdma_firmware_header_v1_1 {
266 struct sdma_firmware_header_v1_0 v1_0;
267 uint32_t digest_size;
270 /* gpu info payload */
271 struct gpu_info_firmware_v1_0 {
273 uint32_t gc_num_cu_per_sh;
274 uint32_t gc_num_sh_per_se;
275 uint32_t gc_num_rb_per_se;
276 uint32_t gc_num_tccs;
277 uint32_t gc_num_gprs;
278 uint32_t gc_num_max_gs_thds;
279 uint32_t gc_gs_table_depth;
280 uint32_t gc_gsprim_buff_depth;
281 uint32_t gc_parameter_cache_depth;
282 uint32_t gc_double_offchip_lds_buffer;
283 uint32_t gc_wave_size;
284 uint32_t gc_max_waves_per_simd;
285 uint32_t gc_max_scratch_slots_per_cu;
286 uint32_t gc_lds_size;
289 struct gpu_info_firmware_v1_1 {
290 struct gpu_info_firmware_v1_0 v1_0;
291 uint32_t num_sc_per_sh;
292 uint32_t num_packer_per_sc;
296 * version_major=1, version_minor=1 */
297 struct gpu_info_firmware_v1_2 {
298 struct gpu_info_firmware_v1_1 v1_1;
299 struct gpu_info_soc_bounding_box_v1_0 soc_bounding_box;
302 /* version_major=1, version_minor=0 */
303 struct gpu_info_firmware_header_v1_0 {
304 struct common_firmware_header header;
305 uint16_t version_major; /* version */
306 uint16_t version_minor; /* version */
309 /* version_major=1, version_minor=0 */
310 struct dmcu_firmware_header_v1_0 {
311 struct common_firmware_header header;
312 uint32_t intv_offset_bytes; /* interrupt vectors offset from end of header, in bytes */
313 uint32_t intv_size_bytes; /* size of interrupt vectors, in bytes */
316 /* version_major=1, version_minor=0 */
317 struct dmcub_firmware_header_v1_0 {
318 struct common_firmware_header header;
319 uint32_t inst_const_bytes; /* size of instruction region, in bytes */
320 uint32_t bss_data_bytes; /* size of bss/data region, in bytes */
323 /* header is fixed size */
324 union amdgpu_firmware_header {
325 struct common_firmware_header common;
326 struct mc_firmware_header_v1_0 mc;
327 struct smc_firmware_header_v1_0 smc;
328 struct smc_firmware_header_v2_0 smc_v2_0;
329 struct psp_firmware_header_v1_0 psp;
330 struct psp_firmware_header_v1_1 psp_v1_1;
331 struct psp_firmware_header_v1_3 psp_v1_3;
332 struct psp_firmware_header_v2_0 psp_v2_0;
333 struct ta_firmware_header_v1_0 ta;
334 struct ta_firmware_header_v2_0 ta_v2_0;
335 struct gfx_firmware_header_v1_0 gfx;
336 struct rlc_firmware_header_v1_0 rlc;
337 struct rlc_firmware_header_v2_0 rlc_v2_0;
338 struct rlc_firmware_header_v2_1 rlc_v2_1;
339 struct sdma_firmware_header_v1_0 sdma;
340 struct sdma_firmware_header_v1_1 sdma_v1_1;
341 struct gpu_info_firmware_header_v1_0 gpu_info;
342 struct dmcu_firmware_header_v1_0 dmcu;
343 struct dmcub_firmware_header_v1_0 dmcub;
347 #define UCODE_MAX_PSP_PACKAGING ((sizeof(union amdgpu_firmware_header) - sizeof(struct common_firmware_header) - 4) / sizeof(struct psp_fw_bin_desc))
352 enum AMDGPU_UCODE_ID {
353 AMDGPU_UCODE_ID_SDMA0 = 0,
354 AMDGPU_UCODE_ID_SDMA1,
355 AMDGPU_UCODE_ID_SDMA2,
356 AMDGPU_UCODE_ID_SDMA3,
357 AMDGPU_UCODE_ID_SDMA4,
358 AMDGPU_UCODE_ID_SDMA5,
359 AMDGPU_UCODE_ID_SDMA6,
360 AMDGPU_UCODE_ID_SDMA7,
361 AMDGPU_UCODE_ID_CP_CE,
362 AMDGPU_UCODE_ID_CP_PFP,
363 AMDGPU_UCODE_ID_CP_ME,
364 AMDGPU_UCODE_ID_CP_MEC1,
365 AMDGPU_UCODE_ID_CP_MEC1_JT,
366 AMDGPU_UCODE_ID_CP_MEC2,
367 AMDGPU_UCODE_ID_CP_MEC2_JT,
368 AMDGPU_UCODE_ID_CP_MES,
369 AMDGPU_UCODE_ID_CP_MES_DATA,
370 AMDGPU_UCODE_ID_RLC_RESTORE_LIST_CNTL,
371 AMDGPU_UCODE_ID_RLC_RESTORE_LIST_GPM_MEM,
372 AMDGPU_UCODE_ID_RLC_RESTORE_LIST_SRM_MEM,
373 AMDGPU_UCODE_ID_RLC_IRAM,
374 AMDGPU_UCODE_ID_RLC_DRAM,
375 AMDGPU_UCODE_ID_RLC_G,
376 AMDGPU_UCODE_ID_STORAGE,
379 AMDGPU_UCODE_ID_UVD1,
382 AMDGPU_UCODE_ID_VCN1,
383 AMDGPU_UCODE_ID_DMCU_ERAM,
384 AMDGPU_UCODE_ID_DMCU_INTV,
385 AMDGPU_UCODE_ID_VCN0_RAM,
386 AMDGPU_UCODE_ID_VCN1_RAM,
387 AMDGPU_UCODE_ID_DMCUB,
388 AMDGPU_UCODE_ID_MAXIMUM,
391 /* engine firmware status */
392 enum AMDGPU_UCODE_STATUS {
393 AMDGPU_UCODE_STATUS_INVALID,
394 AMDGPU_UCODE_STATUS_NOT_LOADED,
395 AMDGPU_UCODE_STATUS_LOADED,
398 enum amdgpu_firmware_load_type {
399 AMDGPU_FW_LOAD_DIRECT = 0,
402 AMDGPU_FW_LOAD_RLC_BACKDOOR_AUTO,
405 /* conform to smu_ucode_xfer_cz.h */
406 #define AMDGPU_SDMA0_UCODE_LOADED 0x00000001
407 #define AMDGPU_SDMA1_UCODE_LOADED 0x00000002
408 #define AMDGPU_CPCE_UCODE_LOADED 0x00000004
409 #define AMDGPU_CPPFP_UCODE_LOADED 0x00000008
410 #define AMDGPU_CPME_UCODE_LOADED 0x00000010
411 #define AMDGPU_CPMEC1_UCODE_LOADED 0x00000020
412 #define AMDGPU_CPMEC2_UCODE_LOADED 0x00000040
413 #define AMDGPU_CPRLC_UCODE_LOADED 0x00000100
415 /* amdgpu firmware info */
416 struct amdgpu_firmware_info {
418 enum AMDGPU_UCODE_ID ucode_id;
419 /* request_firmware */
420 const struct firmware *fw;
421 /* starting mc address */
423 /* kernel linear address */
425 /* ucode_size_bytes */
427 /* starting tmr mc address */
428 uint32_t tmr_mc_addr_lo;
429 uint32_t tmr_mc_addr_hi;
432 struct amdgpu_firmware {
433 struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
434 enum amdgpu_firmware_load_type load_type;
435 struct amdgpu_bo *fw_buf;
436 unsigned int fw_size;
437 unsigned int max_ucodes;
438 /* firmwares are loaded by psp instead of smu from vega10 */
439 const struct amdgpu_psp_funcs *funcs;
440 struct amdgpu_bo *rbuf;
443 /* gpu info firmware data pointer */
444 const struct firmware *gpu_info_fw;
450 void amdgpu_ucode_print_mc_hdr(const struct common_firmware_header *hdr);
451 void amdgpu_ucode_print_smc_hdr(const struct common_firmware_header *hdr);
452 void amdgpu_ucode_print_gfx_hdr(const struct common_firmware_header *hdr);
453 void amdgpu_ucode_print_rlc_hdr(const struct common_firmware_header *hdr);
454 void amdgpu_ucode_print_sdma_hdr(const struct common_firmware_header *hdr);
455 void amdgpu_ucode_print_psp_hdr(const struct common_firmware_header *hdr);
456 void amdgpu_ucode_print_gpu_info_hdr(const struct common_firmware_header *hdr);
457 int amdgpu_ucode_validate(const struct firmware *fw);
458 bool amdgpu_ucode_hdr_version(union amdgpu_firmware_header *hdr,
459 uint16_t hdr_major, uint16_t hdr_minor);
461 int amdgpu_ucode_init_bo(struct amdgpu_device *adev);
462 int amdgpu_ucode_create_bo(struct amdgpu_device *adev);
463 int amdgpu_ucode_sysfs_init(struct amdgpu_device *adev);
464 void amdgpu_ucode_free_bo(struct amdgpu_device *adev);
465 void amdgpu_ucode_sysfs_fini(struct amdgpu_device *adev);
467 enum amdgpu_firmware_load_type
468 amdgpu_ucode_get_load_type(struct amdgpu_device *adev, int load_type);
470 const char *amdgpu_ucode_name(enum AMDGPU_UCODE_ID ucode_id);