2 * Copyright 2016 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.
24 #include <drm/amdgpu_drm.h>
26 #include "atomfirmware.h"
27 #include "amdgpu_atomfirmware.h"
30 #include "soc15_hw_ip.h"
33 struct atom_firmware_info_v3_1 v31;
34 struct atom_firmware_info_v3_2 v32;
35 struct atom_firmware_info_v3_3 v33;
36 struct atom_firmware_info_v3_4 v34;
37 struct atom_firmware_info_v3_5 v35;
41 * Helper function to query firmware capability
43 * @adev: amdgpu_device pointer
45 * Return firmware_capability in firmwareinfo table on success or 0 if not
47 uint32_t amdgpu_atomfirmware_query_firmware_capability(struct amdgpu_device *adev)
49 struct amdgpu_mode_info *mode_info = &adev->mode_info;
51 u16 data_offset, size;
52 union firmware_info *firmware_info;
56 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
59 if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context,
60 index, &size, &frev, &crev, &data_offset)) {
61 /* support firmware_info 3.1 + */
62 if ((frev == 3 && crev >= 1) || (frev > 3)) {
63 firmware_info = (union firmware_info *)
64 (mode_info->atom_context->bios + data_offset);
65 fw_cap = le32_to_cpu(firmware_info->v31.firmware_capability);
73 * Helper function to query gpu virtualizaiton capability
75 * @adev: amdgpu_device pointer
77 * Return true if gpu virtualization is supported or false if not
79 bool amdgpu_atomfirmware_gpu_virtualization_supported(struct amdgpu_device *adev)
83 fw_cap = adev->mode_info.firmware_flags;
85 return (fw_cap & ATOM_FIRMWARE_CAP_GPU_VIRTUALIZATION) ? true : false;
88 void amdgpu_atomfirmware_scratch_regs_init(struct amdgpu_device *adev)
90 int index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
94 if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context, index, NULL,
95 NULL, NULL, &data_offset)) {
96 struct atom_firmware_info_v3_1 *firmware_info =
97 (struct atom_firmware_info_v3_1 *)(adev->mode_info.atom_context->bios +
100 adev->bios_scratch_reg_offset =
101 le32_to_cpu(firmware_info->bios_scratch_reg_startaddr);
105 static int amdgpu_atomfirmware_allocate_fb_v2_1(struct amdgpu_device *adev,
106 struct vram_usagebyfirmware_v2_1 *fw_usage, int *usage_bytes)
108 u32 start_addr, fw_size, drv_size;
110 start_addr = le32_to_cpu(fw_usage->start_address_in_kb);
111 fw_size = le16_to_cpu(fw_usage->used_by_firmware_in_kb);
112 drv_size = le16_to_cpu(fw_usage->used_by_driver_in_kb);
114 DRM_DEBUG("atom firmware v2_1 requested %08x %dkb fw %dkb drv\n",
119 if ((start_addr & ATOM_VRAM_OPERATION_FLAGS_MASK) ==
120 (u32)(ATOM_VRAM_BLOCK_SRIOV_MSG_SHARE_RESERVATION <<
121 ATOM_VRAM_OPERATION_FLAGS_SHIFT)) {
122 /* Firmware request VRAM reservation for SR-IOV */
123 adev->mman.fw_vram_usage_start_offset = (start_addr &
124 (~ATOM_VRAM_OPERATION_FLAGS_MASK)) << 10;
125 adev->mman.fw_vram_usage_size = fw_size << 10;
126 /* Use the default scratch size */
129 *usage_bytes = drv_size << 10;
134 static int amdgpu_atomfirmware_allocate_fb_v2_2(struct amdgpu_device *adev,
135 struct vram_usagebyfirmware_v2_2 *fw_usage, int *usage_bytes)
137 u32 fw_start_addr, fw_size, drv_start_addr, drv_size;
139 fw_start_addr = le32_to_cpu(fw_usage->fw_region_start_address_in_kb);
140 fw_size = le16_to_cpu(fw_usage->used_by_firmware_in_kb);
142 drv_start_addr = le32_to_cpu(fw_usage->driver_region0_start_address_in_kb);
143 drv_size = le32_to_cpu(fw_usage->used_by_driver_region0_in_kb);
145 DRM_DEBUG("atom requested fw start at %08x %dkb and drv start at %08x %dkb\n",
151 if (amdgpu_sriov_vf(adev) &&
152 ((fw_start_addr & (ATOM_VRAM_BLOCK_NEEDS_NO_RESERVATION <<
153 ATOM_VRAM_OPERATION_FLAGS_SHIFT)) == 0)) {
154 /* Firmware request VRAM reservation for SR-IOV */
155 adev->mman.fw_vram_usage_start_offset = (fw_start_addr &
156 (~ATOM_VRAM_OPERATION_FLAGS_MASK)) << 10;
157 adev->mman.fw_vram_usage_size = fw_size << 10;
160 if (amdgpu_sriov_vf(adev) &&
161 ((drv_start_addr & (ATOM_VRAM_BLOCK_NEEDS_NO_RESERVATION <<
162 ATOM_VRAM_OPERATION_FLAGS_SHIFT)) == 0)) {
163 /* driver request VRAM reservation for SR-IOV */
164 adev->mman.drv_vram_usage_start_offset = (drv_start_addr &
165 (~ATOM_VRAM_OPERATION_FLAGS_MASK)) << 10;
166 adev->mman.drv_vram_usage_size = drv_size << 10;
173 int amdgpu_atomfirmware_allocate_fb_scratch(struct amdgpu_device *adev)
175 struct atom_context *ctx = adev->mode_info.atom_context;
176 int index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
177 vram_usagebyfirmware);
178 struct vram_usagebyfirmware_v2_1 *fw_usage_v2_1;
179 struct vram_usagebyfirmware_v2_2 *fw_usage_v2_2;
184 if (amdgpu_atom_parse_data_header(ctx, index, NULL, &frev, &crev, &data_offset)) {
185 if (frev == 2 && crev == 1) {
187 (struct vram_usagebyfirmware_v2_1 *)(ctx->bios + data_offset);
188 amdgpu_atomfirmware_allocate_fb_v2_1(adev,
191 } else if (frev >= 2 && crev >= 2) {
193 (struct vram_usagebyfirmware_v2_2 *)(ctx->bios + data_offset);
194 amdgpu_atomfirmware_allocate_fb_v2_2(adev,
200 ctx->scratch_size_bytes = 0;
201 if (usage_bytes == 0)
202 usage_bytes = 20 * 1024;
203 /* allocate some scratch memory */
204 ctx->scratch = kzalloc(usage_bytes, GFP_KERNEL);
207 ctx->scratch_size_bytes = usage_bytes;
212 struct atom_integrated_system_info_v1_11 v11;
213 struct atom_integrated_system_info_v1_12 v12;
214 struct atom_integrated_system_info_v2_1 v21;
215 struct atom_integrated_system_info_v2_3 v23;
219 struct atom_umc_info_v3_1 v31;
220 struct atom_umc_info_v3_2 v32;
221 struct atom_umc_info_v3_3 v33;
222 struct atom_umc_info_v4_0 v40;
226 struct atom_vram_info_header_v2_3 v23;
227 struct atom_vram_info_header_v2_4 v24;
228 struct atom_vram_info_header_v2_5 v25;
229 struct atom_vram_info_header_v2_6 v26;
230 struct atom_vram_info_header_v3_0 v30;
234 struct atom_vram_module_v9 v9;
235 struct atom_vram_module_v10 v10;
236 struct atom_vram_module_v11 v11;
237 struct atom_vram_module_v3_0 v30;
240 static int convert_atom_mem_type_to_vram_type(struct amdgpu_device *adev,
245 if (adev->flags & AMD_IS_APU) {
246 switch (atom_mem_type) {
249 vram_type = AMDGPU_VRAM_TYPE_DDR2;
253 vram_type = AMDGPU_VRAM_TYPE_DDR3;
256 vram_type = AMDGPU_VRAM_TYPE_DDR4;
259 vram_type = AMDGPU_VRAM_TYPE_LPDDR4;
262 vram_type = AMDGPU_VRAM_TYPE_DDR5;
265 vram_type = AMDGPU_VRAM_TYPE_LPDDR5;
268 vram_type = AMDGPU_VRAM_TYPE_UNKNOWN;
272 switch (atom_mem_type) {
273 case ATOM_DGPU_VRAM_TYPE_GDDR5:
274 vram_type = AMDGPU_VRAM_TYPE_GDDR5;
276 case ATOM_DGPU_VRAM_TYPE_HBM2:
277 case ATOM_DGPU_VRAM_TYPE_HBM2E:
278 case ATOM_DGPU_VRAM_TYPE_HBM3:
279 vram_type = AMDGPU_VRAM_TYPE_HBM;
281 case ATOM_DGPU_VRAM_TYPE_GDDR6:
282 vram_type = AMDGPU_VRAM_TYPE_GDDR6;
285 vram_type = AMDGPU_VRAM_TYPE_UNKNOWN;
295 amdgpu_atomfirmware_get_vram_info(struct amdgpu_device *adev,
296 int *vram_width, int *vram_type,
299 struct amdgpu_mode_info *mode_info = &adev->mode_info;
301 u16 data_offset, size;
302 union igp_info *igp_info;
303 union vram_info *vram_info;
304 union vram_module *vram_module;
308 u32 mem_channel_number;
309 u32 mem_channel_width;
312 if (adev->flags & AMD_IS_APU)
313 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
314 integratedsysteminfo);
316 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
319 if (amdgpu_atom_parse_data_header(mode_info->atom_context,
321 &frev, &crev, &data_offset)) {
322 if (adev->flags & AMD_IS_APU) {
323 igp_info = (union igp_info *)
324 (mode_info->atom_context->bios + data_offset);
330 mem_channel_number = igp_info->v11.umachannelnumber;
331 if (!mem_channel_number)
332 mem_channel_number = 1;
333 mem_type = igp_info->v11.memorytype;
334 if (mem_type == LpDdr5MemType)
335 mem_channel_width = 32;
337 mem_channel_width = 64;
339 *vram_width = mem_channel_number * mem_channel_width;
341 *vram_type = convert_atom_mem_type_to_vram_type(adev, mem_type);
351 mem_channel_number = igp_info->v21.umachannelnumber;
352 if (!mem_channel_number)
353 mem_channel_number = 1;
354 mem_type = igp_info->v21.memorytype;
355 if (mem_type == LpDdr5MemType)
356 mem_channel_width = 32;
358 mem_channel_width = 64;
360 *vram_width = mem_channel_number * mem_channel_width;
362 *vram_type = convert_atom_mem_type_to_vram_type(adev, mem_type);
365 mem_channel_number = igp_info->v23.umachannelnumber;
366 if (!mem_channel_number)
367 mem_channel_number = 1;
368 mem_type = igp_info->v23.memorytype;
369 if (mem_type == LpDdr5MemType)
370 mem_channel_width = 32;
372 mem_channel_width = 64;
374 *vram_width = mem_channel_number * mem_channel_width;
376 *vram_type = convert_atom_mem_type_to_vram_type(adev, mem_type);
386 vram_info = (union vram_info *)
387 (mode_info->atom_context->bios + data_offset);
388 module_id = (RREG32(adev->bios_scratch_reg_offset + 4) & 0x00ff0000) >> 16;
393 vram_module = (union vram_module *)vram_info->v30.vram_module;
394 mem_vendor = (vram_module->v30.dram_vendor_id) & 0xF;
396 *vram_vendor = mem_vendor;
397 mem_type = vram_info->v30.memory_type;
399 *vram_type = convert_atom_mem_type_to_vram_type(adev, mem_type);
400 mem_channel_number = vram_info->v30.channel_num;
401 mem_channel_width = vram_info->v30.channel_width;
403 *vram_width = mem_channel_number * (1 << mem_channel_width);
408 } else if (frev == 2) {
412 if (module_id > vram_info->v23.vram_module_num)
414 vram_module = (union vram_module *)vram_info->v23.vram_module;
415 while (i < module_id) {
416 vram_module = (union vram_module *)
417 ((u8 *)vram_module + vram_module->v9.vram_module_size);
420 mem_type = vram_module->v9.memory_type;
422 *vram_type = convert_atom_mem_type_to_vram_type(adev, mem_type);
423 mem_channel_number = vram_module->v9.channel_num;
424 mem_channel_width = vram_module->v9.channel_width;
426 *vram_width = mem_channel_number * (1 << mem_channel_width);
427 mem_vendor = (vram_module->v9.vender_rev_id) & 0xF;
429 *vram_vendor = mem_vendor;
433 if (module_id > vram_info->v24.vram_module_num)
435 vram_module = (union vram_module *)vram_info->v24.vram_module;
436 while (i < module_id) {
437 vram_module = (union vram_module *)
438 ((u8 *)vram_module + vram_module->v10.vram_module_size);
441 mem_type = vram_module->v10.memory_type;
443 *vram_type = convert_atom_mem_type_to_vram_type(adev, mem_type);
444 mem_channel_number = vram_module->v10.channel_num;
445 mem_channel_width = vram_module->v10.channel_width;
447 *vram_width = mem_channel_number * (1 << mem_channel_width);
448 mem_vendor = (vram_module->v10.vender_rev_id) & 0xF;
450 *vram_vendor = mem_vendor;
454 if (module_id > vram_info->v25.vram_module_num)
456 vram_module = (union vram_module *)vram_info->v25.vram_module;
457 while (i < module_id) {
458 vram_module = (union vram_module *)
459 ((u8 *)vram_module + vram_module->v11.vram_module_size);
462 mem_type = vram_module->v11.memory_type;
464 *vram_type = convert_atom_mem_type_to_vram_type(adev, mem_type);
465 mem_channel_number = vram_module->v11.channel_num;
466 mem_channel_width = vram_module->v11.channel_width;
468 *vram_width = mem_channel_number * (1 << mem_channel_width);
469 mem_vendor = (vram_module->v11.vender_rev_id) & 0xF;
471 *vram_vendor = mem_vendor;
475 if (module_id > vram_info->v26.vram_module_num)
477 vram_module = (union vram_module *)vram_info->v26.vram_module;
478 while (i < module_id) {
479 vram_module = (union vram_module *)
480 ((u8 *)vram_module + vram_module->v9.vram_module_size);
483 mem_type = vram_module->v9.memory_type;
485 *vram_type = convert_atom_mem_type_to_vram_type(adev, mem_type);
486 mem_channel_number = vram_module->v9.channel_num;
487 mem_channel_width = vram_module->v9.channel_width;
489 *vram_width = mem_channel_number * (1 << mem_channel_width);
490 mem_vendor = (vram_module->v9.vender_rev_id) & 0xF;
492 *vram_vendor = mem_vendor;
509 * Return true if vbios enabled ecc by default, if umc info table is available
510 * or false if ecc is not enabled or umc info table is not available
512 bool amdgpu_atomfirmware_mem_ecc_supported(struct amdgpu_device *adev)
514 struct amdgpu_mode_info *mode_info = &adev->mode_info;
516 u16 data_offset, size;
517 union umc_info *umc_info;
519 bool ecc_default_enabled = false;
523 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
526 if (amdgpu_atom_parse_data_header(mode_info->atom_context,
527 index, &size, &frev, &crev, &data_offset)) {
528 umc_info = (union umc_info *)(mode_info->atom_context->bios + data_offset);
532 umc_config = le32_to_cpu(umc_info->v31.umc_config);
533 ecc_default_enabled =
534 (umc_config & UMC_CONFIG__DEFAULT_MEM_ECC_ENABLE) ? true : false;
537 umc_config = le32_to_cpu(umc_info->v32.umc_config);
538 ecc_default_enabled =
539 (umc_config & UMC_CONFIG__DEFAULT_MEM_ECC_ENABLE) ? true : false;
542 umc_config = le32_to_cpu(umc_info->v33.umc_config);
543 umc_config1 = le32_to_cpu(umc_info->v33.umc_config1);
544 ecc_default_enabled =
545 ((umc_config & UMC_CONFIG__DEFAULT_MEM_ECC_ENABLE) ||
546 (umc_config1 & UMC_CONFIG1__ENABLE_ECC_CAPABLE)) ? true : false;
549 /* unsupported crev */
552 } else if (frev == 4) {
555 umc_config1 = le32_to_cpu(umc_info->v40.umc_config1);
556 ecc_default_enabled =
557 (umc_config1 & UMC_CONFIG1__ENABLE_ECC_CAPABLE) ? true : false;
560 /* unsupported crev */
564 /* unsupported frev */
569 return ecc_default_enabled;
573 * Helper function to query sram ecc capablity
575 * @adev: amdgpu_device pointer
577 * Return true if vbios supports sram ecc or false if not
579 bool amdgpu_atomfirmware_sram_ecc_supported(struct amdgpu_device *adev)
583 fw_cap = adev->mode_info.firmware_flags;
585 return (fw_cap & ATOM_FIRMWARE_CAP_SRAM_ECC) ? true : false;
589 * Helper function to query dynamic boot config capability
591 * @adev: amdgpu_device pointer
593 * Return true if vbios supports dynamic boot config or false if not
595 bool amdgpu_atomfirmware_dynamic_boot_config_supported(struct amdgpu_device *adev)
599 fw_cap = adev->mode_info.firmware_flags;
601 return (fw_cap & ATOM_FIRMWARE_CAP_DYNAMIC_BOOT_CFG_ENABLE) ? true : false;
605 * amdgpu_atomfirmware_ras_rom_addr -- Get the RAS EEPROM addr from VBIOS
606 * @adev: amdgpu_device pointer
607 * @i2c_address: pointer to u8; if not NULL, will contain
608 * the RAS EEPROM address if the function returns true
610 * Return true if VBIOS supports RAS EEPROM address reporting,
611 * else return false. If true and @i2c_address is not NULL,
612 * will contain the RAS ROM address.
614 bool amdgpu_atomfirmware_ras_rom_addr(struct amdgpu_device *adev,
617 struct amdgpu_mode_info *mode_info = &adev->mode_info;
619 u16 data_offset, size;
620 union firmware_info *firmware_info;
623 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
626 if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context,
627 index, &size, &frev, &crev,
629 /* support firmware_info 3.4 + */
630 if ((frev == 3 && crev >= 4) || (frev > 3)) {
631 firmware_info = (union firmware_info *)
632 (mode_info->atom_context->bios + data_offset);
633 /* The ras_rom_i2c_slave_addr should ideally
634 * be a 19-bit EEPROM address, which would be
635 * used as is by the driver; see top of
638 * When this is the case, 0 is of course a
639 * valid RAS EEPROM address, in which case,
640 * we'll drop the first "if (firm...)" and only
641 * leave the check for the pointer.
643 * The reason this works right now is because
644 * ras_rom_i2c_slave_addr contains the EEPROM
645 * device type qualifier 1010b in the top 4
648 if (firmware_info->v34.ras_rom_i2c_slave_addr) {
650 *i2c_address = firmware_info->v34.ras_rom_i2c_slave_addr;
661 struct atom_smu_info_v3_1 v31;
662 struct atom_smu_info_v4_0 v40;
666 struct atom_gfx_info_v2_2 v22;
667 struct atom_gfx_info_v2_4 v24;
668 struct atom_gfx_info_v2_7 v27;
669 struct atom_gfx_info_v3_0 v30;
672 int amdgpu_atomfirmware_get_clock_info(struct amdgpu_device *adev)
674 struct amdgpu_mode_info *mode_info = &adev->mode_info;
675 struct amdgpu_pll *spll = &adev->clock.spll;
676 struct amdgpu_pll *mpll = &adev->clock.mpll;
678 uint16_t data_offset;
679 int ret = -EINVAL, index;
681 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
683 if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
684 &frev, &crev, &data_offset)) {
685 union firmware_info *firmware_info =
686 (union firmware_info *)(mode_info->atom_context->bios +
689 adev->clock.default_sclk =
690 le32_to_cpu(firmware_info->v31.bootup_sclk_in10khz);
691 adev->clock.default_mclk =
692 le32_to_cpu(firmware_info->v31.bootup_mclk_in10khz);
694 adev->pm.current_sclk = adev->clock.default_sclk;
695 adev->pm.current_mclk = adev->clock.default_mclk;
700 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
702 if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
703 &frev, &crev, &data_offset)) {
704 union smu_info *smu_info =
705 (union smu_info *)(mode_info->atom_context->bios +
710 spll->reference_freq = le32_to_cpu(smu_info->v31.core_refclk_10khz);
712 spll->reference_freq = le32_to_cpu(smu_info->v40.core_refclk_10khz);
714 spll->reference_div = 0;
715 spll->min_post_div = 1;
716 spll->max_post_div = 1;
717 spll->min_ref_div = 2;
718 spll->max_ref_div = 0xff;
719 spll->min_feedback_div = 4;
720 spll->max_feedback_div = 0xff;
726 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
728 if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
729 &frev, &crev, &data_offset)) {
730 union umc_info *umc_info =
731 (union umc_info *)(mode_info->atom_context->bios +
735 mpll->reference_freq = le32_to_cpu(umc_info->v31.mem_refclk_10khz);
737 mpll->reference_div = 0;
738 mpll->min_post_div = 1;
739 mpll->max_post_div = 1;
740 mpll->min_ref_div = 2;
741 mpll->max_ref_div = 0xff;
742 mpll->min_feedback_div = 4;
743 mpll->max_feedback_div = 0xff;
749 /* if asic is Navi+, the rlc reference clock is used for system clock
750 * from vbios gfx_info table */
751 if (adev->asic_type >= CHIP_NAVI10) {
752 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
754 if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
755 &frev, &crev, &data_offset)) {
756 union gfx_info *gfx_info = (union gfx_info *)
757 (mode_info->atom_context->bios + data_offset);
759 (frev == 2 && crev == 6)) {
760 spll->reference_freq = le32_to_cpu(gfx_info->v30.golden_tsc_count_lower_refclk);
762 } else if ((frev == 2) &&
765 spll->reference_freq = le32_to_cpu(gfx_info->v22.rlc_gpu_timer_refclk);
776 int amdgpu_atomfirmware_get_gfx_info(struct amdgpu_device *adev)
778 struct amdgpu_mode_info *mode_info = &adev->mode_info;
781 uint16_t data_offset;
783 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
785 if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
786 &frev, &crev, &data_offset)) {
787 union gfx_info *gfx_info = (union gfx_info *)
788 (mode_info->atom_context->bios + data_offset);
792 adev->gfx.config.max_shader_engines = gfx_info->v24.max_shader_engines;
793 adev->gfx.config.max_cu_per_sh = gfx_info->v24.max_cu_per_sh;
794 adev->gfx.config.max_sh_per_se = gfx_info->v24.max_sh_per_se;
795 adev->gfx.config.max_backends_per_se = gfx_info->v24.max_backends_per_se;
796 adev->gfx.config.max_texture_channel_caches = gfx_info->v24.max_texture_channel_caches;
797 adev->gfx.config.max_gprs = le16_to_cpu(gfx_info->v24.gc_num_gprs);
798 adev->gfx.config.max_gs_threads = gfx_info->v24.gc_num_max_gs_thds;
799 adev->gfx.config.gs_vgt_table_depth = gfx_info->v24.gc_gs_table_depth;
800 adev->gfx.config.gs_prim_buffer_depth =
801 le16_to_cpu(gfx_info->v24.gc_gsprim_buff_depth);
802 adev->gfx.config.double_offchip_lds_buf =
803 gfx_info->v24.gc_double_offchip_lds_buffer;
804 adev->gfx.cu_info.wave_front_size = le16_to_cpu(gfx_info->v24.gc_wave_size);
805 adev->gfx.cu_info.max_waves_per_simd = le16_to_cpu(gfx_info->v24.gc_max_waves_per_simd);
806 adev->gfx.cu_info.max_scratch_slots_per_cu = gfx_info->v24.gc_max_scratch_slots_per_cu;
807 adev->gfx.cu_info.lds_size = le16_to_cpu(gfx_info->v24.gc_lds_size);
810 adev->gfx.config.max_shader_engines = gfx_info->v27.max_shader_engines;
811 adev->gfx.config.max_cu_per_sh = gfx_info->v27.max_cu_per_sh;
812 adev->gfx.config.max_sh_per_se = gfx_info->v27.max_sh_per_se;
813 adev->gfx.config.max_backends_per_se = gfx_info->v27.max_backends_per_se;
814 adev->gfx.config.max_texture_channel_caches = gfx_info->v27.max_texture_channel_caches;
815 adev->gfx.config.max_gprs = le16_to_cpu(gfx_info->v27.gc_num_gprs);
816 adev->gfx.config.max_gs_threads = gfx_info->v27.gc_num_max_gs_thds;
817 adev->gfx.config.gs_vgt_table_depth = gfx_info->v27.gc_gs_table_depth;
818 adev->gfx.config.gs_prim_buffer_depth = le16_to_cpu(gfx_info->v27.gc_gsprim_buff_depth);
819 adev->gfx.config.double_offchip_lds_buf = gfx_info->v27.gc_double_offchip_lds_buffer;
820 adev->gfx.cu_info.wave_front_size = le16_to_cpu(gfx_info->v27.gc_wave_size);
821 adev->gfx.cu_info.max_waves_per_simd = le16_to_cpu(gfx_info->v27.gc_max_waves_per_simd);
822 adev->gfx.cu_info.max_scratch_slots_per_cu = gfx_info->v27.gc_max_scratch_slots_per_cu;
823 adev->gfx.cu_info.lds_size = le16_to_cpu(gfx_info->v27.gc_lds_size);
828 } else if (frev == 3) {
831 adev->gfx.config.max_shader_engines = gfx_info->v30.max_shader_engines;
832 adev->gfx.config.max_cu_per_sh = gfx_info->v30.max_cu_per_sh;
833 adev->gfx.config.max_sh_per_se = gfx_info->v30.max_sh_per_se;
834 adev->gfx.config.max_backends_per_se = gfx_info->v30.max_backends_per_se;
835 adev->gfx.config.max_texture_channel_caches = gfx_info->v30.max_texture_channel_caches;
849 * Helper function to query two stage mem training capability
851 * @adev: amdgpu_device pointer
853 * Return true if two stage mem training is supported or false if not
855 bool amdgpu_atomfirmware_mem_training_supported(struct amdgpu_device *adev)
859 fw_cap = adev->mode_info.firmware_flags;
861 return (fw_cap & ATOM_FIRMWARE_CAP_ENABLE_2STAGE_BIST_TRAINING) ? true : false;
864 int amdgpu_atomfirmware_get_fw_reserved_fb_size(struct amdgpu_device *adev)
866 struct atom_context *ctx = adev->mode_info.atom_context;
867 union firmware_info *firmware_info;
869 u16 data_offset, size;
871 int fw_reserved_fb_size;
873 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
876 if (!amdgpu_atom_parse_data_header(ctx, index, &size,
877 &frev, &crev, &data_offset))
878 /* fail to parse data_header */
881 firmware_info = (union firmware_info *)(ctx->bios + data_offset);
888 fw_reserved_fb_size =
889 (firmware_info->v34.fw_reserved_size_in_kb << 10);
892 fw_reserved_fb_size =
893 (firmware_info->v35.fw_reserved_size_in_kb << 10);
896 fw_reserved_fb_size = 0;
900 return fw_reserved_fb_size;
904 * Helper function to execute asic_init table
906 * @adev: amdgpu_device pointer
907 * @fb_reset: flag to indicate whether fb is reset or not
909 * Return 0 if succeed, otherwise failed
911 int amdgpu_atomfirmware_asic_init(struct amdgpu_device *adev, bool fb_reset)
913 struct amdgpu_mode_info *mode_info = &adev->mode_info;
914 struct atom_context *ctx;
916 uint16_t data_offset;
917 uint32_t bootup_sclk_in10khz, bootup_mclk_in10khz;
918 struct asic_init_ps_allocation_v2_1 asic_init_ps_v2_1;
924 ctx = mode_info->atom_context;
928 /* query bootup sclk/mclk from firmware_info table */
929 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
931 if (amdgpu_atom_parse_data_header(ctx, index, NULL,
932 &frev, &crev, &data_offset)) {
933 union firmware_info *firmware_info =
934 (union firmware_info *)(ctx->bios +
937 bootup_sclk_in10khz =
938 le32_to_cpu(firmware_info->v31.bootup_sclk_in10khz);
939 bootup_mclk_in10khz =
940 le32_to_cpu(firmware_info->v31.bootup_mclk_in10khz);
945 index = get_index_into_master_table(atom_master_list_of_command_functions_v2_1,
947 if (amdgpu_atom_parse_cmd_header(mode_info->atom_context, index, &frev, &crev)) {
948 if (frev == 2 && crev >= 1) {
949 memset(&asic_init_ps_v2_1, 0, sizeof(asic_init_ps_v2_1));
950 asic_init_ps_v2_1.param.engineparam.sclkfreqin10khz = bootup_sclk_in10khz;
951 asic_init_ps_v2_1.param.memparam.mclkfreqin10khz = bootup_mclk_in10khz;
952 asic_init_ps_v2_1.param.engineparam.engineflag = b3NORMAL_ENGINE_INIT;
954 asic_init_ps_v2_1.param.memparam.memflag = b3DRAM_SELF_REFRESH_EXIT;
956 asic_init_ps_v2_1.param.memparam.memflag = 0;
964 return amdgpu_atom_execute_table(ctx, ATOM_CMD_INIT, (uint32_t *)&asic_init_ps_v2_1,
965 sizeof(asic_init_ps_v2_1));