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;
40 * Helper function to query firmware capability
42 * @adev: amdgpu_device pointer
44 * Return firmware_capability in firmwareinfo table on success or 0 if not
46 uint32_t amdgpu_atomfirmware_query_firmware_capability(struct amdgpu_device *adev)
48 struct amdgpu_mode_info *mode_info = &adev->mode_info;
50 u16 data_offset, size;
51 union firmware_info *firmware_info;
55 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
58 if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context,
59 index, &size, &frev, &crev, &data_offset)) {
60 /* support firmware_info 3.1 + */
61 if ((frev == 3 && crev >=1) || (frev > 3)) {
62 firmware_info = (union firmware_info *)
63 (mode_info->atom_context->bios + data_offset);
64 fw_cap = le32_to_cpu(firmware_info->v31.firmware_capability);
72 * Helper function to query gpu virtualizaiton capability
74 * @adev: amdgpu_device pointer
76 * Return true if gpu virtualization is supported or false if not
78 bool amdgpu_atomfirmware_gpu_virtualization_supported(struct amdgpu_device *adev)
82 fw_cap = adev->mode_info.firmware_flags;
84 return (fw_cap & ATOM_FIRMWARE_CAP_GPU_VIRTUALIZATION) ? true : false;
87 void amdgpu_atomfirmware_scratch_regs_init(struct amdgpu_device *adev)
89 int index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
93 if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context, index, NULL,
94 NULL, NULL, &data_offset)) {
95 struct atom_firmware_info_v3_1 *firmware_info =
96 (struct atom_firmware_info_v3_1 *)(adev->mode_info.atom_context->bios +
99 adev->bios_scratch_reg_offset =
100 le32_to_cpu(firmware_info->bios_scratch_reg_startaddr);
104 int amdgpu_atomfirmware_allocate_fb_scratch(struct amdgpu_device *adev)
106 struct atom_context *ctx = adev->mode_info.atom_context;
107 int index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
108 vram_usagebyfirmware);
109 struct vram_usagebyfirmware_v2_1 *firmware_usage;
110 uint32_t start_addr, size;
111 uint16_t data_offset;
114 if (amdgpu_atom_parse_data_header(ctx, index, NULL, NULL, NULL, &data_offset)) {
115 firmware_usage = (struct vram_usagebyfirmware_v2_1 *)(ctx->bios + data_offset);
116 DRM_DEBUG("atom firmware requested %08x %dkb fw %dkb drv\n",
117 le32_to_cpu(firmware_usage->start_address_in_kb),
118 le16_to_cpu(firmware_usage->used_by_firmware_in_kb),
119 le16_to_cpu(firmware_usage->used_by_driver_in_kb));
121 start_addr = le32_to_cpu(firmware_usage->start_address_in_kb);
122 size = le16_to_cpu(firmware_usage->used_by_firmware_in_kb);
124 if ((uint32_t)(start_addr & ATOM_VRAM_OPERATION_FLAGS_MASK) ==
125 (uint32_t)(ATOM_VRAM_BLOCK_SRIOV_MSG_SHARE_RESERVATION <<
126 ATOM_VRAM_OPERATION_FLAGS_SHIFT)) {
127 /* Firmware request VRAM reservation for SR-IOV */
128 adev->mman.fw_vram_usage_start_offset = (start_addr &
129 (~ATOM_VRAM_OPERATION_FLAGS_MASK)) << 10;
130 adev->mman.fw_vram_usage_size = size << 10;
131 /* Use the default scratch size */
134 usage_bytes = le16_to_cpu(firmware_usage->used_by_driver_in_kb) << 10;
137 ctx->scratch_size_bytes = 0;
138 if (usage_bytes == 0)
139 usage_bytes = 20 * 1024;
140 /* allocate some scratch memory */
141 ctx->scratch = kzalloc(usage_bytes, GFP_KERNEL);
144 ctx->scratch_size_bytes = usage_bytes;
149 struct atom_integrated_system_info_v1_11 v11;
150 struct atom_integrated_system_info_v1_12 v12;
151 struct atom_integrated_system_info_v2_1 v21;
155 struct atom_umc_info_v3_1 v31;
156 struct atom_umc_info_v3_2 v32;
157 struct atom_umc_info_v3_3 v33;
161 struct atom_vram_info_header_v2_3 v23;
162 struct atom_vram_info_header_v2_4 v24;
163 struct atom_vram_info_header_v2_5 v25;
164 struct atom_vram_info_header_v2_6 v26;
168 struct atom_vram_module_v9 v9;
169 struct atom_vram_module_v10 v10;
170 struct atom_vram_module_v11 v11;
173 static int convert_atom_mem_type_to_vram_type(struct amdgpu_device *adev,
178 if (adev->flags & AMD_IS_APU) {
179 switch (atom_mem_type) {
182 vram_type = AMDGPU_VRAM_TYPE_DDR2;
186 vram_type = AMDGPU_VRAM_TYPE_DDR3;
190 vram_type = AMDGPU_VRAM_TYPE_DDR4;
194 vram_type = AMDGPU_VRAM_TYPE_DDR5;
197 vram_type = AMDGPU_VRAM_TYPE_UNKNOWN;
201 switch (atom_mem_type) {
202 case ATOM_DGPU_VRAM_TYPE_GDDR5:
203 vram_type = AMDGPU_VRAM_TYPE_GDDR5;
205 case ATOM_DGPU_VRAM_TYPE_HBM2:
206 case ATOM_DGPU_VRAM_TYPE_HBM2E:
207 vram_type = AMDGPU_VRAM_TYPE_HBM;
209 case ATOM_DGPU_VRAM_TYPE_GDDR6:
210 vram_type = AMDGPU_VRAM_TYPE_GDDR6;
213 vram_type = AMDGPU_VRAM_TYPE_UNKNOWN;
223 amdgpu_atomfirmware_get_vram_info(struct amdgpu_device *adev,
224 int *vram_width, int *vram_type,
227 struct amdgpu_mode_info *mode_info = &adev->mode_info;
229 u16 data_offset, size;
230 union igp_info *igp_info;
231 union vram_info *vram_info;
232 union vram_module *vram_module;
236 u32 mem_channel_number;
237 u32 mem_channel_width;
240 if (adev->flags & AMD_IS_APU)
241 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
242 integratedsysteminfo);
244 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
247 if (amdgpu_atom_parse_data_header(mode_info->atom_context,
249 &frev, &crev, &data_offset)) {
250 if (adev->flags & AMD_IS_APU) {
251 igp_info = (union igp_info *)
252 (mode_info->atom_context->bios + data_offset);
258 mem_channel_number = igp_info->v11.umachannelnumber;
259 if (!mem_channel_number)
260 mem_channel_number = 1;
261 /* channel width is 64 */
263 *vram_width = mem_channel_number * 64;
264 mem_type = igp_info->v11.memorytype;
266 *vram_type = convert_atom_mem_type_to_vram_type(adev, mem_type);
276 mem_channel_number = igp_info->v21.umachannelnumber;
277 if (!mem_channel_number)
278 mem_channel_number = 1;
279 /* channel width is 64 */
281 *vram_width = mem_channel_number * 64;
282 mem_type = igp_info->v21.memorytype;
284 *vram_type = convert_atom_mem_type_to_vram_type(adev, mem_type);
294 vram_info = (union vram_info *)
295 (mode_info->atom_context->bios + data_offset);
296 module_id = (RREG32(adev->bios_scratch_reg_offset + 4) & 0x00ff0000) >> 16;
299 if (module_id > vram_info->v23.vram_module_num)
301 vram_module = (union vram_module *)vram_info->v23.vram_module;
302 while (i < module_id) {
303 vram_module = (union vram_module *)
304 ((u8 *)vram_module + vram_module->v9.vram_module_size);
307 mem_type = vram_module->v9.memory_type;
309 *vram_type = convert_atom_mem_type_to_vram_type(adev, mem_type);
310 mem_channel_number = vram_module->v9.channel_num;
311 mem_channel_width = vram_module->v9.channel_width;
313 *vram_width = mem_channel_number * (1 << mem_channel_width);
314 mem_vendor = (vram_module->v9.vender_rev_id) & 0xF;
316 *vram_vendor = mem_vendor;
319 if (module_id > vram_info->v24.vram_module_num)
321 vram_module = (union vram_module *)vram_info->v24.vram_module;
322 while (i < module_id) {
323 vram_module = (union vram_module *)
324 ((u8 *)vram_module + vram_module->v10.vram_module_size);
327 mem_type = vram_module->v10.memory_type;
329 *vram_type = convert_atom_mem_type_to_vram_type(adev, mem_type);
330 mem_channel_number = vram_module->v10.channel_num;
331 mem_channel_width = vram_module->v10.channel_width;
333 *vram_width = mem_channel_number * (1 << mem_channel_width);
334 mem_vendor = (vram_module->v10.vender_rev_id) & 0xF;
336 *vram_vendor = mem_vendor;
339 if (module_id > vram_info->v25.vram_module_num)
341 vram_module = (union vram_module *)vram_info->v25.vram_module;
342 while (i < module_id) {
343 vram_module = (union vram_module *)
344 ((u8 *)vram_module + vram_module->v11.vram_module_size);
347 mem_type = vram_module->v11.memory_type;
349 *vram_type = convert_atom_mem_type_to_vram_type(adev, mem_type);
350 mem_channel_number = vram_module->v11.channel_num;
351 mem_channel_width = vram_module->v11.channel_width;
353 *vram_width = mem_channel_number * (1 << mem_channel_width);
354 mem_vendor = (vram_module->v11.vender_rev_id) & 0xF;
356 *vram_vendor = mem_vendor;
359 if (module_id > vram_info->v26.vram_module_num)
361 vram_module = (union vram_module *)vram_info->v26.vram_module;
362 while (i < module_id) {
363 vram_module = (union vram_module *)
364 ((u8 *)vram_module + vram_module->v9.vram_module_size);
367 mem_type = vram_module->v9.memory_type;
369 *vram_type = convert_atom_mem_type_to_vram_type(adev, mem_type);
370 mem_channel_number = vram_module->v9.channel_num;
371 mem_channel_width = vram_module->v9.channel_width;
373 *vram_width = mem_channel_number * (1 << mem_channel_width);
374 mem_vendor = (vram_module->v9.vender_rev_id) & 0xF;
376 *vram_vendor = mem_vendor;
389 * Return true if vbios enabled ecc by default, if umc info table is available
390 * or false if ecc is not enabled or umc info table is not available
392 bool amdgpu_atomfirmware_mem_ecc_supported(struct amdgpu_device *adev)
394 struct amdgpu_mode_info *mode_info = &adev->mode_info;
396 u16 data_offset, size;
397 union umc_info *umc_info;
399 bool ecc_default_enabled = false;
403 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
406 if (amdgpu_atom_parse_data_header(mode_info->atom_context,
407 index, &size, &frev, &crev, &data_offset)) {
409 umc_info = (union umc_info *)
410 (mode_info->atom_context->bios + data_offset);
413 umc_config = le32_to_cpu(umc_info->v31.umc_config);
414 ecc_default_enabled =
415 (umc_config & UMC_CONFIG__DEFAULT_MEM_ECC_ENABLE) ? true : false;
418 umc_config = le32_to_cpu(umc_info->v32.umc_config);
419 ecc_default_enabled =
420 (umc_config & UMC_CONFIG__DEFAULT_MEM_ECC_ENABLE) ? true : false;
423 umc_config = le32_to_cpu(umc_info->v33.umc_config);
424 umc_config1 = le32_to_cpu(umc_info->v33.umc_config1);
425 ecc_default_enabled =
426 ((umc_config & UMC_CONFIG__DEFAULT_MEM_ECC_ENABLE) ||
427 (umc_config1 & UMC_CONFIG1__ENABLE_ECC_CAPABLE)) ? true : false;
430 /* unsupported crev */
436 return ecc_default_enabled;
440 * Helper function to query sram ecc capablity
442 * @adev: amdgpu_device pointer
444 * Return true if vbios supports sram ecc or false if not
446 bool amdgpu_atomfirmware_sram_ecc_supported(struct amdgpu_device *adev)
450 fw_cap = adev->mode_info.firmware_flags;
452 return (fw_cap & ATOM_FIRMWARE_CAP_SRAM_ECC) ? true : false;
456 struct atom_smu_info_v3_1 v31;
459 int amdgpu_atomfirmware_get_clock_info(struct amdgpu_device *adev)
461 struct amdgpu_mode_info *mode_info = &adev->mode_info;
462 struct amdgpu_pll *spll = &adev->clock.spll;
463 struct amdgpu_pll *mpll = &adev->clock.mpll;
465 uint16_t data_offset;
466 int ret = -EINVAL, index;
468 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
470 if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
471 &frev, &crev, &data_offset)) {
472 union firmware_info *firmware_info =
473 (union firmware_info *)(mode_info->atom_context->bios +
476 adev->clock.default_sclk =
477 le32_to_cpu(firmware_info->v31.bootup_sclk_in10khz);
478 adev->clock.default_mclk =
479 le32_to_cpu(firmware_info->v31.bootup_mclk_in10khz);
481 adev->pm.current_sclk = adev->clock.default_sclk;
482 adev->pm.current_mclk = adev->clock.default_mclk;
487 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
489 if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
490 &frev, &crev, &data_offset)) {
491 union smu_info *smu_info =
492 (union smu_info *)(mode_info->atom_context->bios +
496 spll->reference_freq = le32_to_cpu(smu_info->v31.core_refclk_10khz);
498 spll->reference_div = 0;
499 spll->min_post_div = 1;
500 spll->max_post_div = 1;
501 spll->min_ref_div = 2;
502 spll->max_ref_div = 0xff;
503 spll->min_feedback_div = 4;
504 spll->max_feedback_div = 0xff;
510 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
512 if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
513 &frev, &crev, &data_offset)) {
514 union umc_info *umc_info =
515 (union umc_info *)(mode_info->atom_context->bios +
519 mpll->reference_freq = le32_to_cpu(umc_info->v31.mem_refclk_10khz);
521 mpll->reference_div = 0;
522 mpll->min_post_div = 1;
523 mpll->max_post_div = 1;
524 mpll->min_ref_div = 2;
525 mpll->max_ref_div = 0xff;
526 mpll->min_feedback_div = 4;
527 mpll->max_feedback_div = 0xff;
537 struct atom_gfx_info_v2_4 v24;
538 struct atom_gfx_info_v2_7 v27;
541 int amdgpu_atomfirmware_get_gfx_info(struct amdgpu_device *adev)
543 struct amdgpu_mode_info *mode_info = &adev->mode_info;
546 uint16_t data_offset;
548 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
550 if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
551 &frev, &crev, &data_offset)) {
552 union gfx_info *gfx_info = (union gfx_info *)
553 (mode_info->atom_context->bios + data_offset);
556 adev->gfx.config.max_shader_engines = gfx_info->v24.max_shader_engines;
557 adev->gfx.config.max_cu_per_sh = gfx_info->v24.max_cu_per_sh;
558 adev->gfx.config.max_sh_per_se = gfx_info->v24.max_sh_per_se;
559 adev->gfx.config.max_backends_per_se = gfx_info->v24.max_backends_per_se;
560 adev->gfx.config.max_texture_channel_caches = gfx_info->v24.max_texture_channel_caches;
561 adev->gfx.config.max_gprs = le16_to_cpu(gfx_info->v24.gc_num_gprs);
562 adev->gfx.config.max_gs_threads = gfx_info->v24.gc_num_max_gs_thds;
563 adev->gfx.config.gs_vgt_table_depth = gfx_info->v24.gc_gs_table_depth;
564 adev->gfx.config.gs_prim_buffer_depth =
565 le16_to_cpu(gfx_info->v24.gc_gsprim_buff_depth);
566 adev->gfx.config.double_offchip_lds_buf =
567 gfx_info->v24.gc_double_offchip_lds_buffer;
568 adev->gfx.cu_info.wave_front_size = le16_to_cpu(gfx_info->v24.gc_wave_size);
569 adev->gfx.cu_info.max_waves_per_simd = le16_to_cpu(gfx_info->v24.gc_max_waves_per_simd);
570 adev->gfx.cu_info.max_scratch_slots_per_cu = gfx_info->v24.gc_max_scratch_slots_per_cu;
571 adev->gfx.cu_info.lds_size = le16_to_cpu(gfx_info->v24.gc_lds_size);
574 adev->gfx.config.max_shader_engines = gfx_info->v27.max_shader_engines;
575 adev->gfx.config.max_cu_per_sh = gfx_info->v27.max_cu_per_sh;
576 adev->gfx.config.max_sh_per_se = gfx_info->v27.max_sh_per_se;
577 adev->gfx.config.max_backends_per_se = gfx_info->v27.max_backends_per_se;
578 adev->gfx.config.max_texture_channel_caches = gfx_info->v27.max_texture_channel_caches;
579 adev->gfx.config.max_gprs = le16_to_cpu(gfx_info->v27.gc_num_gprs);
580 adev->gfx.config.max_gs_threads = gfx_info->v27.gc_num_max_gs_thds;
581 adev->gfx.config.gs_vgt_table_depth = gfx_info->v27.gc_gs_table_depth;
582 adev->gfx.config.gs_prim_buffer_depth = le16_to_cpu(gfx_info->v27.gc_gsprim_buff_depth);
583 adev->gfx.config.double_offchip_lds_buf = gfx_info->v27.gc_double_offchip_lds_buffer;
584 adev->gfx.cu_info.wave_front_size = le16_to_cpu(gfx_info->v27.gc_wave_size);
585 adev->gfx.cu_info.max_waves_per_simd = le16_to_cpu(gfx_info->v27.gc_max_waves_per_simd);
586 adev->gfx.cu_info.max_scratch_slots_per_cu = gfx_info->v27.gc_max_scratch_slots_per_cu;
587 adev->gfx.cu_info.lds_size = le16_to_cpu(gfx_info->v27.gc_lds_size);
598 * Helper function to query two stage mem training capability
600 * @adev: amdgpu_device pointer
602 * Return true if two stage mem training is supported or false if not
604 bool amdgpu_atomfirmware_mem_training_supported(struct amdgpu_device *adev)
608 fw_cap = adev->mode_info.firmware_flags;
610 return (fw_cap & ATOM_FIRMWARE_CAP_ENABLE_2STAGE_BIST_TRAINING) ? true : false;
613 int amdgpu_atomfirmware_get_fw_reserved_fb_size(struct amdgpu_device *adev)
615 struct atom_context *ctx = adev->mode_info.atom_context;
616 union firmware_info *firmware_info;
618 u16 data_offset, size;
620 int fw_reserved_fb_size;
622 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
625 if (!amdgpu_atom_parse_data_header(ctx, index, &size,
626 &frev, &crev, &data_offset))
627 /* fail to parse data_header */
630 firmware_info = (union firmware_info *)(ctx->bios + data_offset);
637 fw_reserved_fb_size =
638 (firmware_info->v34.fw_reserved_size_in_kb << 10);
641 fw_reserved_fb_size = 0;
645 return fw_reserved_fb_size;