Skip to contentSkip to conversation

drm/amdgpu: refactor code to reuse system information

PATCH Superseded Sunil Khatri 5 participants 12 messages Mar 19, 2024

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: refactor code to reuse system information

Refactor the code so debugfs and devcoredump can reuse the common information and avoid unnecessary copy of it.

created a new file which would be the right place to hold functions which will be used between sysfs, debugfs and devcoredump.

Cc Christian König <[email protected]>
Cc Alex Deucher <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/Makefile         |   2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu.h         |   1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c | 151 ++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c     | 118 +--------------
 4 files changed, 157 insertions(+), 115 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
drivers/gpu/drm/amd/amdgpu/Makefile +1 -1
index 4536c8ad0e11..05d34f4b18f5 100644
@@ -80,7 +80,7 @@ amdgpu-y += amdgpu_device.o amdgpu_doorbell_mgr.o amdgpu_kms.o \
 	amdgpu_umc.o smu_v11_0_i2c.o amdgpu_fru_eeprom.o amdgpu_rap.o \
 	amdgpu_fw_attestation.o amdgpu_securedisplay.o \
 	amdgpu_eeprom.o amdgpu_mca.o amdgpu_psp_ta.o amdgpu_lsdma.o \
-	amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o
+	amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o amdgpu_devinfo.o
 
 amdgpu-$(CONFIG_PROC_FS) += amdgpu_fdinfo.o
 
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index 9c62552bec34..0267870aa9b1 100644
@@ -1609,4 +1609,5 @@ extern const struct attribute_group amdgpu_vram_mgr_attr_group;
 extern const struct attribute_group amdgpu_gtt_mgr_attr_group;
 extern const struct attribute_group amdgpu_flash_attr_group;
 
+int amdgpu_device_info(struct amdgpu_device *adev, struct drm_amdgpu_info_device *dev_info);
 #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +151 -0

151 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +4 -114

129 lines not on this page · raw message

Signature · 1 line
2.34.1
#1 lore raw

Validated the code by using the function in same way as ioctl would use in devcoredump and getting the valid values.

Also this would be the container of the information that we need to share between ioctl, debugfs and devcoredump and keep updating this based on information needed.

Quoted 332 lines · Sunil Khatri

Refactor the code so debugfs and devcoredump can reuse the common information and avoid unnecessary copy of it.

created a new file which would be the right place to hold functions which will be used between sysfs, debugfs and devcoredump.

Cc Christian König <[email protected]>
Cc Alex Deucher <[email protected]>
---
  drivers/gpu/drm/amd/amdgpu/Makefile         |   2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu.h         |   1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c | 151 ++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c     | 118 +--------------
  4 files changed, 157 insertions(+), 115 deletions(-)

create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c

drivers/gpu/drm/amd/amdgpu/Makefile +1 -1
index 4536c8ad0e11..05d34f4b18f5 100644
@@ -80,7 +80,7 @@ amdgpu-y += amdgpu_device.o amdgpu_doorbell_mgr.o amdgpu_kms.o \
  	amdgpu_umc.o smu_v11_0_i2c.o amdgpu_fru_eeprom.o amdgpu_rap.o \
  	amdgpu_fw_attestation.o amdgpu_securedisplay.o \
  	amdgpu_eeprom.o amdgpu_mca.o amdgpu_psp_ta.o amdgpu_lsdma.o \
-	amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o
+	amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o amdgpu_devinfo.o
 
  amdgpu-$(CONFIG_PROC_FS) += amdgpu_fdinfo.o
 
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index 9c62552bec34..0267870aa9b1 100644
@@ -1609,4 +1609,5 @@ extern const struct attribute_group amdgpu_vram_mgr_attr_group;
  extern const struct attribute_group amdgpu_gtt_mgr_attr_group;
  extern const struct attribute_group amdgpu_flash_attr_group;
 
+int amdgpu_device_info(struct amdgpu_device *adev, struct drm_amdgpu_info_device *dev_info);
  #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +151 -0
new file mode 100644
index 000000000000..d2c15a1dcb0d
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2024 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include "amdgpu.h"
+#include "amd_pcie.h"
+
+#include <drm/amdgpu_drm.h>
+
+int amdgpu_device_info(struct amdgpu_device *adev, struct drm_amdgpu_info_device *dev_info)
+{
+	int ret;
+	uint64_t vm_size;
+	uint32_t pcie_gen_mask;
+
+	if (dev_info == NULL)
+		return -EINVAL;
+
+	dev_info->device_id = adev->pdev->device;
+	dev_info->chip_rev = adev->rev_id;
+	dev_info->external_rev = adev->external_rev_id;
+	dev_info->pci_rev = adev->pdev->revision;
+	dev_info->family = adev->family;
+	dev_info->num_shader_engines = adev->gfx.config.max_shader_engines;
+	dev_info->num_shader_arrays_per_engine = adev->gfx.config.max_sh_per_se;
+	/* return all clocks in KHz */
+	dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
+	if (adev->pm.dpm_enabled) {
+		dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev, false) * 10;
+		dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev, false) * 10;
+		dev_info->min_engine_clock = amdgpu_dpm_get_sclk(adev, true) * 10;
+		dev_info->min_memory_clock = amdgpu_dpm_get_mclk(adev, true) * 10;
+	} else {
+		dev_info->max_engine_clock =
+			dev_info->min_engine_clock =
+				adev->clock.default_sclk * 10;
+		dev_info->max_memory_clock =
+			dev_info->min_memory_clock =
+				adev->clock.default_mclk * 10;
+		}
+	dev_info->enabled_rb_pipes_mask = adev->gfx.config.backend_enable_mask;
+	dev_info->num_rb_pipes = adev->gfx.config.max_backends_per_se *
+		adev->gfx.config.max_shader_engines;
+	dev_info->num_hw_gfx_contexts = adev->gfx.config.max_hw_contexts;
+	dev_info->ids_flags = 0;
+	if (adev->flags & AMD_IS_APU)
+		dev_info->ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
+	if (adev->gfx.mcbp)
+		dev_info->ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
+	if (amdgpu_is_tmz(adev))
+		dev_info->ids_flags |= AMDGPU_IDS_FLAGS_TMZ;
+	if (adev->gfx.config.ta_cntl2_truncate_coord_mode)
+		dev_info->ids_flags |= AMDGPU_IDS_FLAGS_CONFORMANT_TRUNC_COORD;
+
+	vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
+	vm_size -= AMDGPU_VA_RESERVED_TOP;
+
+	/* Older VCE FW versions are buggy and can handle only 40bits */
+	if (adev->vce.fw_version && adev->vce.fw_version < AMDGPU_VCE_FW_53_45)
+		vm_size = min(vm_size, 1ULL << 40);
+
+	dev_info->virtual_address_offset = AMDGPU_VA_RESERVED_BOTTOM;
+	dev_info->virtual_address_max = min(vm_size, AMDGPU_GMC_HOLE_START);
+
+	if (vm_size > AMDGPU_GMC_HOLE_START) {
+		dev_info->high_va_offset = AMDGPU_GMC_HOLE_END;
+		dev_info->high_va_max = AMDGPU_GMC_HOLE_END | vm_size;
+	}
+	dev_info->virtual_address_alignment = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
+	dev_info->pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
+	dev_info->gart_page_size = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
+	dev_info->cu_active_number = adev->gfx.cu_info.number;
+	dev_info->cu_ao_mask = adev->gfx.cu_info.ao_cu_mask;
+	dev_info->ce_ram_size = adev->gfx.ce_ram_size;
+	memcpy(&dev_info->cu_ao_bitmap[0], &adev->gfx.cu_info.ao_cu_bitmap[0],
+	       sizeof(adev->gfx.cu_info.ao_cu_bitmap));
+	memcpy(&dev_info->cu_bitmap[0], &adev->gfx.cu_info.bitmap[0],
+	       sizeof(dev_info->cu_bitmap));
+	dev_info->vram_type = adev->gmc.vram_type;
+	dev_info->vram_bit_width = adev->gmc.vram_width;
+	dev_info->vce_harvest_config = adev->vce.harvest_config;
+	dev_info->gc_double_offchip_lds_buf =
+		adev->gfx.config.double_offchip_lds_buf;
+	dev_info->wave_front_size = adev->gfx.cu_info.wave_front_size;
+	dev_info->num_shader_visible_vgprs = adev->gfx.config.max_gprs;
+	dev_info->num_cu_per_sh = adev->gfx.config.max_cu_per_sh;
+	dev_info->num_tcc_blocks = adev->gfx.config.max_texture_channel_caches;
+	dev_info->gs_vgt_table_depth = adev->gfx.config.gs_vgt_table_depth;
+	dev_info->gs_prim_buffer_depth = adev->gfx.config.gs_prim_buffer_depth;
+	dev_info->max_gs_waves_per_vgt = adev->gfx.config.max_gs_threads;
+
+	if (adev->family >= AMDGPU_FAMILY_NV)
+		dev_info->pa_sc_tile_steering_override =
+			adev->gfx.config.pa_sc_tile_steering_override;
+
+	dev_info->tcc_disabled_mask = adev->gfx.config.tcc_disabled_mask;
+
+	/* Combine the chip gen mask with the platform (CPU/mobo) mask. */
+	pcie_gen_mask = adev->pm.pcie_gen_mask & (adev->pm.pcie_gen_mask >> 16);
+	dev_info->pcie_gen = fls(pcie_gen_mask);
+	dev_info->pcie_num_lanes =
+		adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 ? 32 :
+		adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 ? 16 :
+		adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 ? 12 :
+		adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 ? 8 :
+		adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 ? 4 :
+		adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 ? 2 : 1;
+
+	dev_info->tcp_cache_size = adev->gfx.config.gc_tcp_l1_size;
+	dev_info->num_sqc_per_wgp = adev->gfx.config.gc_num_sqc_per_wgp;
+	dev_info->sqc_data_cache_size = adev->gfx.config.gc_l1_data_cache_size_per_sqc;
+	dev_info->sqc_inst_cache_size = adev->gfx.config.gc_l1_instruction_cache_size_per_sqc;
+	dev_info->gl1c_cache_size = adev->gfx.config.gc_gl1c_size_per_instance *
+				    adev->gfx.config.gc_gl1c_per_sa;
+	dev_info->gl2c_cache_size = adev->gfx.config.gc_gl2c_per_gpu;
+	dev_info->mall_size = adev->gmc.mall_size;
+
+
+	if (adev->gfx.funcs->get_gfx_shadow_info) {
+		struct amdgpu_gfx_shadow_info shadow_info;
+
+		ret = amdgpu_gfx_get_gfx_shadow_info(adev, &shadow_info);
+		if (!ret) {
+			dev_info->shadow_size = shadow_info.shadow_size;
+			dev_info->shadow_alignment = shadow_info.shadow_alignment;
+			dev_info->csa_size = shadow_info.csa_size;
+			dev_info->csa_alignment = shadow_info.csa_alignment;
+		}
+	}
+	return ret;
+}
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +4 -114
index a66d47865e3b..24f775c68a51 100644
@@ -850,125 +850,15 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
  	}
  	case AMDGPU_INFO_DEV_INFO: {
  		struct drm_amdgpu_info_device *dev_info;
-		uint64_t vm_size;
-		uint32_t pcie_gen_mask;
 
  		dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL);
  		if (!dev_info)
  			return -ENOMEM;
 
-		dev_info->device_id = adev->pdev->device;
-		dev_info->chip_rev = adev->rev_id;
-		dev_info->external_rev = adev->external_rev_id;
-		dev_info->pci_rev = adev->pdev->revision;
-		dev_info->family = adev->family;
-		dev_info->num_shader_engines = adev->gfx.config.max_shader_engines;
-		dev_info->num_shader_arrays_per_engine = adev->gfx.config.max_sh_per_se;
-		/* return all clocks in KHz */
-		dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
-		if (adev->pm.dpm_enabled) {
-			dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev, false) * 10;
-			dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev, false) * 10;
-			dev_info->min_engine_clock = amdgpu_dpm_get_sclk(adev, true) * 10;
-			dev_info->min_memory_clock = amdgpu_dpm_get_mclk(adev, true) * 10;
-		} else {
-			dev_info->max_engine_clock =
-				dev_info->min_engine_clock =
-					adev->clock.default_sclk * 10;
-			dev_info->max_memory_clock =
-				dev_info->min_memory_clock =
-					adev->clock.default_mclk * 10;
-		}
-		dev_info->enabled_rb_pipes_mask = adev->gfx.config.backend_enable_mask;
-		dev_info->num_rb_pipes = adev->gfx.config.max_backends_per_se *
-			adev->gfx.config.max_shader_engines;
-		dev_info->num_hw_gfx_contexts = adev->gfx.config.max_hw_contexts;
-		dev_info->ids_flags = 0;
-		if (adev->flags & AMD_IS_APU)
-			dev_info->ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
-		if (adev->gfx.mcbp)
-			dev_info->ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
-		if (amdgpu_is_tmz(adev))
-			dev_info->ids_flags |= AMDGPU_IDS_FLAGS_TMZ;
-		if (adev->gfx.config.ta_cntl2_truncate_coord_mode)
-			dev_info->ids_flags |= AMDGPU_IDS_FLAGS_CONFORMANT_TRUNC_COORD;
-
-		vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
-		vm_size -= AMDGPU_VA_RESERVED_TOP;
-
-		/* Older VCE FW versions are buggy and can handle only 40bits */
-		if (adev->vce.fw_version &&
-		    adev->vce.fw_version < AMDGPU_VCE_FW_53_45)
-			vm_size = min(vm_size, 1ULL << 40);
-
-		dev_info->virtual_address_offset = AMDGPU_VA_RESERVED_BOTTOM;
-		dev_info->virtual_address_max =
-			min(vm_size, AMDGPU_GMC_HOLE_START);
-
-		if (vm_size > AMDGPU_GMC_HOLE_START) {
-			dev_info->high_va_offset = AMDGPU_GMC_HOLE_END;
-			dev_info->high_va_max = AMDGPU_GMC_HOLE_END | vm_size;
-		}
-		dev_info->virtual_address_alignment = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
-		dev_info->pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
-		dev_info->gart_page_size = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
-		dev_info->cu_active_number = adev->gfx.cu_info.number;
-		dev_info->cu_ao_mask = adev->gfx.cu_info.ao_cu_mask;
-		dev_info->ce_ram_size = adev->gfx.ce_ram_size;
-		memcpy(&dev_info->cu_ao_bitmap[0], &adev->gfx.cu_info.ao_cu_bitmap[0],
-		       sizeof(adev->gfx.cu_info.ao_cu_bitmap));
-		memcpy(&dev_info->cu_bitmap[0], &adev->gfx.cu_info.bitmap[0],
-		       sizeof(dev_info->cu_bitmap));
-		dev_info->vram_type = adev->gmc.vram_type;
-		dev_info->vram_bit_width = adev->gmc.vram_width;
-		dev_info->vce_harvest_config = adev->vce.harvest_config;
-		dev_info->gc_double_offchip_lds_buf =
-			adev->gfx.config.double_offchip_lds_buf;
-		dev_info->wave_front_size = adev->gfx.cu_info.wave_front_size;
-		dev_info->num_shader_visible_vgprs = adev->gfx.config.max_gprs;
-		dev_info->num_cu_per_sh = adev->gfx.config.max_cu_per_sh;
-		dev_info->num_tcc_blocks = adev->gfx.config.max_texture_channel_caches;
-		dev_info->gs_vgt_table_depth = adev->gfx.config.gs_vgt_table_depth;
-		dev_info->gs_prim_buffer_depth = adev->gfx.config.gs_prim_buffer_depth;
-		dev_info->max_gs_waves_per_vgt = adev->gfx.config.max_gs_threads;
-
-		if (adev->family >= AMDGPU_FAMILY_NV)
-			dev_info->pa_sc_tile_steering_override =
-				adev->gfx.config.pa_sc_tile_steering_override;
-
-		dev_info->tcc_disabled_mask = adev->gfx.config.tcc_disabled_mask;
-
-		/* Combine the chip gen mask with the platform (CPU/mobo) mask. */
-		pcie_gen_mask = adev->pm.pcie_gen_mask & (adev->pm.pcie_gen_mask >> 16);
-		dev_info->pcie_gen = fls(pcie_gen_mask);
-		dev_info->pcie_num_lanes =
-			adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 ? 32 :
-			adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 ? 16 :
-			adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 ? 12 :
-			adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 ? 8 :
-			adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 ? 4 :
-			adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 ? 2 : 1;
-
-		dev_info->tcp_cache_size = adev->gfx.config.gc_tcp_l1_size;
-		dev_info->num_sqc_per_wgp = adev->gfx.config.gc_num_sqc_per_wgp;
-		dev_info->sqc_data_cache_size = adev->gfx.config.gc_l1_data_cache_size_per_sqc;
-		dev_info->sqc_inst_cache_size = adev->gfx.config.gc_l1_instruction_cache_size_per_sqc;
-		dev_info->gl1c_cache_size = adev->gfx.config.gc_gl1c_size_per_instance *
-					    adev->gfx.config.gc_gl1c_per_sa;
-		dev_info->gl2c_cache_size = adev->gfx.config.gc_gl2c_per_gpu;
-		dev_info->mall_size = adev->gmc.mall_size;
-
-
-		if (adev->gfx.funcs->get_gfx_shadow_info) {
-			struct amdgpu_gfx_shadow_info shadow_info;
-
-			ret = amdgpu_gfx_get_gfx_shadow_info(adev, &shadow_info);
-			if (!ret) {
-				dev_info->shadow_size = shadow_info.shadow_size;
-				dev_info->shadow_alignment = shadow_info.shadow_alignment;
-				dev_info->csa_size = shadow_info.csa_size;
-				dev_info->csa_alignment = shadow_info.csa_alignment;
-			}
+		ret = amdgpu_device_info(adev, dev_info);
+		if (!ret) {
+			kfree(dev_info);
+			return ret;
  		}
 
  		ret = copy_to_user(out, dev_info,
#2 lore raw
In reply to Sunil Khatri
Quoted 179 lines · Sunil Khatri

Refactor the code so debugfs and devcoredump can reuse the common information and avoid unnecessary copy of it.

created a new file which would be the right place to hold functions which will be used between sysfs, debugfs and devcoredump.

Cc Christian König <[email protected]>
Cc Alex Deucher <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/Makefile         |   2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu.h         |   1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c | 151 ++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c     | 118 +--------------
 4 files changed, 157 insertions(+), 115 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
drivers/gpu/drm/amd/amdgpu/Makefile +1 -1
index 4536c8ad0e11..05d34f4b18f5 100644
@@ -80,7 +80,7 @@ amdgpu-y += amdgpu_device.o amdgpu_doorbell_mgr.o amdgpu_kms.o \
 	amdgpu_umc.o smu_v11_0_i2c.o amdgpu_fru_eeprom.o amdgpu_rap.o \
 	amdgpu_fw_attestation.o amdgpu_securedisplay.o \
 	amdgpu_eeprom.o amdgpu_mca.o amdgpu_psp_ta.o amdgpu_lsdma.o \
-	amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o
+	amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o amdgpu_devinfo.o
 
 amdgpu-$(CONFIG_PROC_FS) += amdgpu_fdinfo.o
 
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index 9c62552bec34..0267870aa9b1 100644
@@ -1609,4 +1609,5 @@ extern const struct attribute_group amdgpu_vram_mgr_attr_group;
 extern const struct attribute_group amdgpu_gtt_mgr_attr_group;
 extern const struct attribute_group amdgpu_flash_attr_group;
 
+int amdgpu_device_info(struct amdgpu_device *adev, struct drm_amdgpu_info_device *dev_info);
 #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +132 -0
new file mode 100644
index 000000000000..d2c15a1dcb0d
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2024 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include "amdgpu.h"
+#include "amd_pcie.h"
+
+#include <drm/amdgpu_drm.h>
+
+int amdgpu_device_info(struct amdgpu_device *adev, struct drm_amdgpu_info_device *dev_info)
+{
+	int ret;
+	uint64_t vm_size;
+	uint32_t pcie_gen_mask;
+
+	if (dev_info == NULL)
+		return -EINVAL;
+
+	dev_info->device_id = adev->pdev->device;
+	dev_info->chip_rev = adev->rev_id;
+	dev_info->external_rev = adev->external_rev_id;
+	dev_info->pci_rev = adev->pdev->revision;
+	dev_info->family = adev->family;
+	dev_info->num_shader_engines = adev->gfx.config.max_shader_engines;
+	dev_info->num_shader_arrays_per_engine = adev->gfx.config.max_sh_per_se;
+	/* return all clocks in KHz */
+	dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
+	if (adev->pm.dpm_enabled) {
+		dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev, false) * 10;
+		dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev, false) * 10;
+		dev_info->min_engine_clock = amdgpu_dpm_get_sclk(adev, true) * 10;
+		dev_info->min_memory_clock = amdgpu_dpm_get_mclk(adev, true) * 10;
+	} else {
+		dev_info->max_engine_clock =
+			dev_info->min_engine_clock =
+				adev->clock.default_sclk * 10;
+		dev_info->max_memory_clock =
+			dev_info->min_memory_clock =
+				adev->clock.default_mclk * 10;
+		}
+	dev_info->enabled_rb_pipes_mask = adev->gfx.config.backend_enable_mask;
+	dev_info->num_rb_pipes = adev->gfx.config.max_backends_per_se *
+		adev->gfx.config.max_shader_engines;
+	dev_info->num_hw_gfx_contexts = adev->gfx.config.max_hw_contexts;
+	dev_info->ids_flags = 0;
+	if (adev->flags & AMD_IS_APU)
+		dev_info->ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
+	if (adev->gfx.mcbp)
+		dev_info->ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
+	if (amdgpu_is_tmz(adev))
+		dev_info->ids_flags |= AMDGPU_IDS_FLAGS_TMZ;
+	if (adev->gfx.config.ta_cntl2_truncate_coord_mode)
+		dev_info->ids_flags |= AMDGPU_IDS_FLAGS_CONFORMANT_TRUNC_COORD;
+
+	vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
+	vm_size -= AMDGPU_VA_RESERVED_TOP;
+
+	/* Older VCE FW versions are buggy and can handle only 40bits */
+	if (adev->vce.fw_version && adev->vce.fw_version < AMDGPU_VCE_FW_53_45)
+		vm_size = min(vm_size, 1ULL << 40);
+
+	dev_info->virtual_address_offset = AMDGPU_VA_RESERVED_BOTTOM;
+	dev_info->virtual_address_max = min(vm_size, AMDGPU_GMC_HOLE_START);
+
+	if (vm_size > AMDGPU_GMC_HOLE_START) {
+		dev_info->high_va_offset = AMDGPU_GMC_HOLE_END;
+		dev_info->high_va_max = AMDGPU_GMC_HOLE_END | vm_size;
+	}
+	dev_info->virtual_address_alignment = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
+	dev_info->pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
+	dev_info->gart_page_size = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
+	dev_info->cu_active_number = adev->gfx.cu_info.number;
+	dev_info->cu_ao_mask = adev->gfx.cu_info.ao_cu_mask;
+	dev_info->ce_ram_size = adev->gfx.ce_ram_size;
+	memcpy(&dev_info->cu_ao_bitmap[0], &adev->gfx.cu_info.ao_cu_bitmap[0],
+	       sizeof(adev->gfx.cu_info.ao_cu_bitmap));
+	memcpy(&dev_info->cu_bitmap[0], &adev->gfx.cu_info.bitmap[0],
+	       sizeof(dev_info->cu_bitmap));
+	dev_info->vram_type = adev->gmc.vram_type;
+	dev_info->vram_bit_width = adev->gmc.vram_width;
+	dev_info->vce_harvest_config = adev->vce.harvest_config;
+	dev_info->gc_double_offchip_lds_buf =
+		adev->gfx.config.double_offchip_lds_buf;
+	dev_info->wave_front_size = adev->gfx.cu_info.wave_front_size;
+	dev_info->num_shader_visible_vgprs = adev->gfx.config.max_gprs;
+	dev_info->num_cu_per_sh = adev->gfx.config.max_cu_per_sh;
+	dev_info->num_tcc_blocks = adev->gfx.config.max_texture_channel_caches;
+	dev_info->gs_vgt_table_depth = adev->gfx.config.gs_vgt_table_depth;
+	dev_info->gs_prim_buffer_depth = adev->gfx.config.gs_prim_buffer_depth;
+	dev_info->max_gs_waves_per_vgt = adev->gfx.config.max_gs_threads;
+
+	if (adev->family >= AMDGPU_FAMILY_NV)
+		dev_info->pa_sc_tile_steering_override =
+			adev->gfx.config.pa_sc_tile_steering_override;
+
+	dev_info->tcc_disabled_mask = adev->gfx.config.tcc_disabled_mask;
+
+	/* Combine the chip gen mask with the platform (CPU/mobo) mask. */
+	pcie_gen_mask = adev->pm.pcie_gen_mask & (adev->pm.pcie_gen_mask >> 16);
+	dev_info->pcie_gen = fls(pcie_gen_mask);
+	dev_info->pcie_num_lanes =
+		adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 ? 32 :
+		adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 ? 16 :
+		adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 ? 12 :
+		adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 ? 8 :
+		adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 ? 4 :
+		adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 ? 2 : 1;
+
+	dev_info->tcp_cache_size = adev->gfx.config.gc_tcp_l1_size;
+	dev_info->num_sqc_per_wgp = adev->gfx.config.gc_num_sqc_per_wgp;
+	dev_info->sqc_data_cache_size = adev->gfx.config.gc_l1_data_cache_size_per_sqc;
+	dev_info->sqc_inst_cache_size = adev->gfx.config.gc_l1_instruction_cache_size_per_sqc;

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c line 142

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +10 -0
+	dev_info->gl1c_cache_size = adev->gfx.config.gc_gl1c_size_per_instance *
+				    adev->gfx.config.gc_gl1c_per_sa;
+	dev_info->gl2c_cache_size = adev->gfx.config.gc_gl2c_per_gpu;
+	dev_info->mall_size = adev->gmc.mall_size;
+
+
+	if (adev->gfx.funcs->get_gfx_shadow_info) {
+		struct amdgpu_gfx_shadow_info shadow_info;
+
+		ret = amdgpu_gfx_get_gfx_shadow_info(adev, &shadow_info);

This failure is ignored in the present logic and rest of the information is filled. Probably, need to continue the same way.

Thanks,
Lijo

Quoted 143 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +9 -0
+		if (!ret) {
+			dev_info->shadow_size = shadow_info.shadow_size;
+			dev_info->shadow_alignment = shadow_info.shadow_alignment;
+			dev_info->csa_size = shadow_info.csa_size;
+			dev_info->csa_alignment = shadow_info.csa_alignment;
+		}
+	}
+	return ret;
+}
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +4 -114
index a66d47865e3b..24f775c68a51 100644
@@ -850,125 +850,15 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 	}
 	case AMDGPU_INFO_DEV_INFO: {
 		struct drm_amdgpu_info_device *dev_info;
-		uint64_t vm_size;
-		uint32_t pcie_gen_mask;
 
 		dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL);
 		if (!dev_info)
 			return -ENOMEM;
 
-		dev_info->device_id = adev->pdev->device;
-		dev_info->chip_rev = adev->rev_id;
-		dev_info->external_rev = adev->external_rev_id;
-		dev_info->pci_rev = adev->pdev->revision;
-		dev_info->family = adev->family;
-		dev_info->num_shader_engines = adev->gfx.config.max_shader_engines;
-		dev_info->num_shader_arrays_per_engine = adev->gfx.config.max_sh_per_se;
-		/* return all clocks in KHz */
-		dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
-		if (adev->pm.dpm_enabled) {
-			dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev, false) * 10;
-			dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev, false) * 10;
-			dev_info->min_engine_clock = amdgpu_dpm_get_sclk(adev, true) * 10;
-			dev_info->min_memory_clock = amdgpu_dpm_get_mclk(adev, true) * 10;
-		} else {
-			dev_info->max_engine_clock =
-				dev_info->min_engine_clock =
-					adev->clock.default_sclk * 10;
-			dev_info->max_memory_clock =
-				dev_info->min_memory_clock =
-					adev->clock.default_mclk * 10;
-		}
-		dev_info->enabled_rb_pipes_mask = adev->gfx.config.backend_enable_mask;
-		dev_info->num_rb_pipes = adev->gfx.config.max_backends_per_se *
-			adev->gfx.config.max_shader_engines;
-		dev_info->num_hw_gfx_contexts = adev->gfx.config.max_hw_contexts;
-		dev_info->ids_flags = 0;
-		if (adev->flags & AMD_IS_APU)
-			dev_info->ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
-		if (adev->gfx.mcbp)
-			dev_info->ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
-		if (amdgpu_is_tmz(adev))
-			dev_info->ids_flags |= AMDGPU_IDS_FLAGS_TMZ;
-		if (adev->gfx.config.ta_cntl2_truncate_coord_mode)
-			dev_info->ids_flags |= AMDGPU_IDS_FLAGS_CONFORMANT_TRUNC_COORD;
-
-		vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
-		vm_size -= AMDGPU_VA_RESERVED_TOP;
-
-		/* Older VCE FW versions are buggy and can handle only 40bits */
-		if (adev->vce.fw_version &&
-		    adev->vce.fw_version < AMDGPU_VCE_FW_53_45)
-			vm_size = min(vm_size, 1ULL << 40);
-
-		dev_info->virtual_address_offset = AMDGPU_VA_RESERVED_BOTTOM;
-		dev_info->virtual_address_max =
-			min(vm_size, AMDGPU_GMC_HOLE_START);
-
-		if (vm_size > AMDGPU_GMC_HOLE_START) {
-			dev_info->high_va_offset = AMDGPU_GMC_HOLE_END;
-			dev_info->high_va_max = AMDGPU_GMC_HOLE_END | vm_size;
-		}
-		dev_info->virtual_address_alignment = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
-		dev_info->pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
-		dev_info->gart_page_size = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
-		dev_info->cu_active_number = adev->gfx.cu_info.number;
-		dev_info->cu_ao_mask = adev->gfx.cu_info.ao_cu_mask;
-		dev_info->ce_ram_size = adev->gfx.ce_ram_size;
-		memcpy(&dev_info->cu_ao_bitmap[0], &adev->gfx.cu_info.ao_cu_bitmap[0],
-		       sizeof(adev->gfx.cu_info.ao_cu_bitmap));
-		memcpy(&dev_info->cu_bitmap[0], &adev->gfx.cu_info.bitmap[0],
-		       sizeof(dev_info->cu_bitmap));
-		dev_info->vram_type = adev->gmc.vram_type;
-		dev_info->vram_bit_width = adev->gmc.vram_width;
-		dev_info->vce_harvest_config = adev->vce.harvest_config;
-		dev_info->gc_double_offchip_lds_buf =
-			adev->gfx.config.double_offchip_lds_buf;
-		dev_info->wave_front_size = adev->gfx.cu_info.wave_front_size;
-		dev_info->num_shader_visible_vgprs = adev->gfx.config.max_gprs;
-		dev_info->num_cu_per_sh = adev->gfx.config.max_cu_per_sh;
-		dev_info->num_tcc_blocks = adev->gfx.config.max_texture_channel_caches;
-		dev_info->gs_vgt_table_depth = adev->gfx.config.gs_vgt_table_depth;
-		dev_info->gs_prim_buffer_depth = adev->gfx.config.gs_prim_buffer_depth;
-		dev_info->max_gs_waves_per_vgt = adev->gfx.config.max_gs_threads;
-
-		if (adev->family >= AMDGPU_FAMILY_NV)
-			dev_info->pa_sc_tile_steering_override =
-				adev->gfx.config.pa_sc_tile_steering_override;
-
-		dev_info->tcc_disabled_mask = adev->gfx.config.tcc_disabled_mask;
-
-		/* Combine the chip gen mask with the platform (CPU/mobo) mask. */
-		pcie_gen_mask = adev->pm.pcie_gen_mask & (adev->pm.pcie_gen_mask >> 16);
-		dev_info->pcie_gen = fls(pcie_gen_mask);
-		dev_info->pcie_num_lanes =
-			adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 ? 32 :
-			adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 ? 16 :
-			adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 ? 12 :
-			adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 ? 8 :
-			adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 ? 4 :
-			adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 ? 2 : 1;
-
-		dev_info->tcp_cache_size = adev->gfx.config.gc_tcp_l1_size;
-		dev_info->num_sqc_per_wgp = adev->gfx.config.gc_num_sqc_per_wgp;
-		dev_info->sqc_data_cache_size = adev->gfx.config.gc_l1_data_cache_size_per_sqc;
-		dev_info->sqc_inst_cache_size = adev->gfx.config.gc_l1_instruction_cache_size_per_sqc;
-		dev_info->gl1c_cache_size = adev->gfx.config.gc_gl1c_size_per_instance *
-					    adev->gfx.config.gc_gl1c_per_sa;
-		dev_info->gl2c_cache_size = adev->gfx.config.gc_gl2c_per_gpu;
-		dev_info->mall_size = adev->gmc.mall_size;
-
-
-		if (adev->gfx.funcs->get_gfx_shadow_info) {
-			struct amdgpu_gfx_shadow_info shadow_info;
-
-			ret = amdgpu_gfx_get_gfx_shadow_info(adev, &shadow_info);
-			if (!ret) {
-				dev_info->shadow_size = shadow_info.shadow_size;
-				dev_info->shadow_alignment = shadow_info.shadow_alignment;
-				dev_info->csa_size = shadow_info.csa_size;
-				dev_info->csa_alignment = shadow_info.csa_alignment;
-			}
+		ret = amdgpu_device_info(adev, dev_info);
+		if (!ret) {
+			kfree(dev_info);
+			return ret;
 		}
 
 		ret = copy_to_user(out, dev_info,
#3 lore raw
Quoted 185 lines · Lijo
Quoted 183 lines · Sunil Khatri

Refactor the code so debugfs and devcoredump can reuse the common information and avoid unnecessary copy of it.

created a new file which would be the right place to hold functions which will be used between sysfs, debugfs and devcoredump.

Cc Christian König <[email protected]>
Cc Alex Deucher <[email protected]>
---
  drivers/gpu/drm/amd/amdgpu/Makefile         |   2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu.h         |   1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c | 151 ++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c     | 118 +--------------
  4 files changed, 157 insertions(+), 115 deletions(-)

create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c

drivers/gpu/drm/amd/amdgpu/Makefile +1 -1
index 4536c8ad0e11..05d34f4b18f5 100644
@@ -80,7 +80,7 @@ amdgpu-y += amdgpu_device.o amdgpu_doorbell_mgr.o amdgpu_kms.o \
  	amdgpu_umc.o smu_v11_0_i2c.o amdgpu_fru_eeprom.o amdgpu_rap.o \
  	amdgpu_fw_attestation.o amdgpu_securedisplay.o \
  	amdgpu_eeprom.o amdgpu_mca.o amdgpu_psp_ta.o amdgpu_lsdma.o \
-	amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o
+	amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o amdgpu_devinfo.o
 
  amdgpu-$(CONFIG_PROC_FS) += amdgpu_fdinfo.o
 
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index 9c62552bec34..0267870aa9b1 100644
@@ -1609,4 +1609,5 @@ extern const struct attribute_group amdgpu_vram_mgr_attr_group;
  extern const struct attribute_group amdgpu_gtt_mgr_attr_group;
  extern const struct attribute_group amdgpu_flash_attr_group;
 
+int amdgpu_device_info(struct amdgpu_device *adev, struct drm_amdgpu_info_device *dev_info);
  #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +136 -0
new file mode 100644
index 000000000000..d2c15a1dcb0d
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2024 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include "amdgpu.h"
+#include "amd_pcie.h"
+
+#include <drm/amdgpu_drm.h>
+
+int amdgpu_device_info(struct amdgpu_device *adev, struct drm_amdgpu_info_device *dev_info)
+{
+	int ret;
+	uint64_t vm_size;
+	uint32_t pcie_gen_mask;
+
+	if (dev_info == NULL)
+		return -EINVAL;
+
+	dev_info->device_id = adev->pdev->device;
+	dev_info->chip_rev = adev->rev_id;
+	dev_info->external_rev = adev->external_rev_id;
+	dev_info->pci_rev = adev->pdev->revision;
+	dev_info->family = adev->family;
+	dev_info->num_shader_engines = adev->gfx.config.max_shader_engines;
+	dev_info->num_shader_arrays_per_engine = adev->gfx.config.max_sh_per_se;
+	/* return all clocks in KHz */
+	dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
+	if (adev->pm.dpm_enabled) {
+		dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev, false) * 10;
+		dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev, false) * 10;
+		dev_info->min_engine_clock = amdgpu_dpm_get_sclk(adev, true) * 10;
+		dev_info->min_memory_clock = amdgpu_dpm_get_mclk(adev, true) * 10;
+	} else {
+		dev_info->max_engine_clock =
+			dev_info->min_engine_clock =
+				adev->clock.default_sclk * 10;
+		dev_info->max_memory_clock =
+			dev_info->min_memory_clock =
+				adev->clock.default_mclk * 10;
+		}
+	dev_info->enabled_rb_pipes_mask = adev->gfx.config.backend_enable_mask;
+	dev_info->num_rb_pipes = adev->gfx.config.max_backends_per_se *
+		adev->gfx.config.max_shader_engines;
+	dev_info->num_hw_gfx_contexts = adev->gfx.config.max_hw_contexts;
+	dev_info->ids_flags = 0;
+	if (adev->flags & AMD_IS_APU)
+		dev_info->ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
+	if (adev->gfx.mcbp)
+		dev_info->ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
+	if (amdgpu_is_tmz(adev))
+		dev_info->ids_flags |= AMDGPU_IDS_FLAGS_TMZ;
+	if (adev->gfx.config.ta_cntl2_truncate_coord_mode)
+		dev_info->ids_flags |= AMDGPU_IDS_FLAGS_CONFORMANT_TRUNC_COORD;
+
+	vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
+	vm_size -= AMDGPU_VA_RESERVED_TOP;
+
+	/* Older VCE FW versions are buggy and can handle only 40bits */
+	if (adev->vce.fw_version && adev->vce.fw_version < AMDGPU_VCE_FW_53_45)
+		vm_size = min(vm_size, 1ULL << 40);
+
+	dev_info->virtual_address_offset = AMDGPU_VA_RESERVED_BOTTOM;
+	dev_info->virtual_address_max = min(vm_size, AMDGPU_GMC_HOLE_START);
+
+	if (vm_size > AMDGPU_GMC_HOLE_START) {
+		dev_info->high_va_offset = AMDGPU_GMC_HOLE_END;
+		dev_info->high_va_max = AMDGPU_GMC_HOLE_END | vm_size;
+	}
+	dev_info->virtual_address_alignment = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
+	dev_info->pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
+	dev_info->gart_page_size = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
+	dev_info->cu_active_number = adev->gfx.cu_info.number;
+	dev_info->cu_ao_mask = adev->gfx.cu_info.ao_cu_mask;
+	dev_info->ce_ram_size = adev->gfx.ce_ram_size;
+	memcpy(&dev_info->cu_ao_bitmap[0], &adev->gfx.cu_info.ao_cu_bitmap[0],
+	       sizeof(adev->gfx.cu_info.ao_cu_bitmap));
+	memcpy(&dev_info->cu_bitmap[0], &adev->gfx.cu_info.bitmap[0],
+	       sizeof(dev_info->cu_bitmap));
+	dev_info->vram_type = adev->gmc.vram_type;
+	dev_info->vram_bit_width = adev->gmc.vram_width;
+	dev_info->vce_harvest_config = adev->vce.harvest_config;
+	dev_info->gc_double_offchip_lds_buf =
+		adev->gfx.config.double_offchip_lds_buf;
+	dev_info->wave_front_size = adev->gfx.cu_info.wave_front_size;
+	dev_info->num_shader_visible_vgprs = adev->gfx.config.max_gprs;
+	dev_info->num_cu_per_sh = adev->gfx.config.max_cu_per_sh;
+	dev_info->num_tcc_blocks = adev->gfx.config.max_texture_channel_caches;
+	dev_info->gs_vgt_table_depth = adev->gfx.config.gs_vgt_table_depth;
+	dev_info->gs_prim_buffer_depth = adev->gfx.config.gs_prim_buffer_depth;
+	dev_info->max_gs_waves_per_vgt = adev->gfx.config.max_gs_threads;
+
+	if (adev->family >= AMDGPU_FAMILY_NV)
+		dev_info->pa_sc_tile_steering_override =
+			adev->gfx.config.pa_sc_tile_steering_override;
+
+	dev_info->tcc_disabled_mask = adev->gfx.config.tcc_disabled_mask;
+
+	/* Combine the chip gen mask with the platform (CPU/mobo) mask. */
+	pcie_gen_mask = adev->pm.pcie_gen_mask & (adev->pm.pcie_gen_mask >> 16);
+	dev_info->pcie_gen = fls(pcie_gen_mask);
+	dev_info->pcie_num_lanes =
+		adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 ? 32 :
+		adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 ? 16 :
+		adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 ? 12 :
+		adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 ? 8 :
+		adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 ? 4 :
+		adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 ? 2 : 1;
+
+	dev_info->tcp_cache_size = adev->gfx.config.gc_tcp_l1_size;
+	dev_info->num_sqc_per_wgp = adev->gfx.config.gc_num_sqc_per_wgp;
+	dev_info->sqc_data_cache_size = adev->gfx.config.gc_l1_data_cache_size_per_sqc;
+	dev_info->sqc_inst_cache_size = adev->gfx.config.gc_l1_instruction_cache_size_per_sqc;
+	dev_info->gl1c_cache_size = adev->gfx.config.gc_gl1c_size_per_instance *
+				    adev->gfx.config.gc_gl1c_per_sa;
+	dev_info->gl2c_cache_size = adev->gfx.config.gc_gl2c_per_gpu;
+	dev_info->mall_size = adev->gmc.mall_size;
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c line 142

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +6 -0
+
+
+	if (adev->gfx.funcs->get_gfx_shadow_info) {
+		struct amdgpu_gfx_shadow_info shadow_info;
+
+		ret = amdgpu_gfx_get_gfx_shadow_info(adev, &shadow_info);

This failure is ignored in the present logic and rest of the information is filled. Probably, need to continue the same way.

Since this is the information that we are sharing with user and on any failure we just decide not to populate those fields. By default all the members are initialized to zero and they

are updated when we have valid values. To me seems the right logic instead of failing the complete call, we provide the information what we have.

Regards
Sunil

Quoted 147 lines

Thanks,
Lijo

Quoted 143 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +9 -0
+		if (!ret) {
+			dev_info->shadow_size = shadow_info.shadow_size;
+			dev_info->shadow_alignment = shadow_info.shadow_alignment;
+			dev_info->csa_size = shadow_info.csa_size;
+			dev_info->csa_alignment = shadow_info.csa_alignment;
+		}
+	}
+	return ret;
+}
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +4 -114
index a66d47865e3b..24f775c68a51 100644
@@ -850,125 +850,15 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
  	}
  	case AMDGPU_INFO_DEV_INFO: {
  		struct drm_amdgpu_info_device *dev_info;
-		uint64_t vm_size;
-		uint32_t pcie_gen_mask;
 
  		dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL);
  		if (!dev_info)
  			return -ENOMEM;
 
-		dev_info->device_id = adev->pdev->device;
-		dev_info->chip_rev = adev->rev_id;
-		dev_info->external_rev = adev->external_rev_id;
-		dev_info->pci_rev = adev->pdev->revision;
-		dev_info->family = adev->family;
-		dev_info->num_shader_engines = adev->gfx.config.max_shader_engines;
-		dev_info->num_shader_arrays_per_engine = adev->gfx.config.max_sh_per_se;
-		/* return all clocks in KHz */
-		dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
-		if (adev->pm.dpm_enabled) {
-			dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev, false) * 10;
-			dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev, false) * 10;
-			dev_info->min_engine_clock = amdgpu_dpm_get_sclk(adev, true) * 10;
-			dev_info->min_memory_clock = amdgpu_dpm_get_mclk(adev, true) * 10;
-		} else {
-			dev_info->max_engine_clock =
-				dev_info->min_engine_clock =
-					adev->clock.default_sclk * 10;
-			dev_info->max_memory_clock =
-				dev_info->min_memory_clock =
-					adev->clock.default_mclk * 10;
-		}
-		dev_info->enabled_rb_pipes_mask = adev->gfx.config.backend_enable_mask;
-		dev_info->num_rb_pipes = adev->gfx.config.max_backends_per_se *
-			adev->gfx.config.max_shader_engines;
-		dev_info->num_hw_gfx_contexts = adev->gfx.config.max_hw_contexts;
-		dev_info->ids_flags = 0;
-		if (adev->flags & AMD_IS_APU)
-			dev_info->ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
-		if (adev->gfx.mcbp)
-			dev_info->ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
-		if (amdgpu_is_tmz(adev))
-			dev_info->ids_flags |= AMDGPU_IDS_FLAGS_TMZ;
-		if (adev->gfx.config.ta_cntl2_truncate_coord_mode)
-			dev_info->ids_flags |= AMDGPU_IDS_FLAGS_CONFORMANT_TRUNC_COORD;
-
-		vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
-		vm_size -= AMDGPU_VA_RESERVED_TOP;
-
-		/* Older VCE FW versions are buggy and can handle only 40bits */
-		if (adev->vce.fw_version &&
-		    adev->vce.fw_version < AMDGPU_VCE_FW_53_45)
-			vm_size = min(vm_size, 1ULL << 40);
-
-		dev_info->virtual_address_offset = AMDGPU_VA_RESERVED_BOTTOM;
-		dev_info->virtual_address_max =
-			min(vm_size, AMDGPU_GMC_HOLE_START);
-
-		if (vm_size > AMDGPU_GMC_HOLE_START) {
-			dev_info->high_va_offset = AMDGPU_GMC_HOLE_END;
-			dev_info->high_va_max = AMDGPU_GMC_HOLE_END | vm_size;
-		}
-		dev_info->virtual_address_alignment = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
-		dev_info->pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
-		dev_info->gart_page_size = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
-		dev_info->cu_active_number = adev->gfx.cu_info.number;
-		dev_info->cu_ao_mask = adev->gfx.cu_info.ao_cu_mask;
-		dev_info->ce_ram_size = adev->gfx.ce_ram_size;
-		memcpy(&dev_info->cu_ao_bitmap[0], &adev->gfx.cu_info.ao_cu_bitmap[0],
-		       sizeof(adev->gfx.cu_info.ao_cu_bitmap));
-		memcpy(&dev_info->cu_bitmap[0], &adev->gfx.cu_info.bitmap[0],
-		       sizeof(dev_info->cu_bitmap));
-		dev_info->vram_type = adev->gmc.vram_type;
-		dev_info->vram_bit_width = adev->gmc.vram_width;
-		dev_info->vce_harvest_config = adev->vce.harvest_config;
-		dev_info->gc_double_offchip_lds_buf =
-			adev->gfx.config.double_offchip_lds_buf;
-		dev_info->wave_front_size = adev->gfx.cu_info.wave_front_size;
-		dev_info->num_shader_visible_vgprs = adev->gfx.config.max_gprs;
-		dev_info->num_cu_per_sh = adev->gfx.config.max_cu_per_sh;
-		dev_info->num_tcc_blocks = adev->gfx.config.max_texture_channel_caches;
-		dev_info->gs_vgt_table_depth = adev->gfx.config.gs_vgt_table_depth;
-		dev_info->gs_prim_buffer_depth = adev->gfx.config.gs_prim_buffer_depth;
-		dev_info->max_gs_waves_per_vgt = adev->gfx.config.max_gs_threads;
-
-		if (adev->family >= AMDGPU_FAMILY_NV)
-			dev_info->pa_sc_tile_steering_override =
-				adev->gfx.config.pa_sc_tile_steering_override;
-
-		dev_info->tcc_disabled_mask = adev->gfx.config.tcc_disabled_mask;
-
-		/* Combine the chip gen mask with the platform (CPU/mobo) mask. */
-		pcie_gen_mask = adev->pm.pcie_gen_mask & (adev->pm.pcie_gen_mask >> 16);
-		dev_info->pcie_gen = fls(pcie_gen_mask);
-		dev_info->pcie_num_lanes =
-			adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 ? 32 :
-			adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 ? 16 :
-			adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 ? 12 :
-			adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 ? 8 :
-			adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 ? 4 :
-			adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 ? 2 : 1;
-
-		dev_info->tcp_cache_size = adev->gfx.config.gc_tcp_l1_size;
-		dev_info->num_sqc_per_wgp = adev->gfx.config.gc_num_sqc_per_wgp;
-		dev_info->sqc_data_cache_size = adev->gfx.config.gc_l1_data_cache_size_per_sqc;
-		dev_info->sqc_inst_cache_size = adev->gfx.config.gc_l1_instruction_cache_size_per_sqc;
-		dev_info->gl1c_cache_size = adev->gfx.config.gc_gl1c_size_per_instance *
-					    adev->gfx.config.gc_gl1c_per_sa;
-		dev_info->gl2c_cache_size = adev->gfx.config.gc_gl2c_per_gpu;
-		dev_info->mall_size = adev->gmc.mall_size;
-
-
-		if (adev->gfx.funcs->get_gfx_shadow_info) {
-			struct amdgpu_gfx_shadow_info shadow_info;
-
-			ret = amdgpu_gfx_get_gfx_shadow_info(adev, &shadow_info);
-			if (!ret) {
-				dev_info->shadow_size = shadow_info.shadow_size;
-				dev_info->shadow_alignment = shadow_info.shadow_alignment;
-				dev_info->csa_size = shadow_info.csa_size;
-				dev_info->csa_alignment = shadow_info.csa_alignment;
-			}
+		ret = amdgpu_device_info(adev, dev_info);
+		if (!ret) {
+			kfree(dev_info);
+			return ret;
  		}
 
  		ret = copy_to_user(out, dev_info,
#4 lore raw
Quoted 235 lines · Sunil
Quoted 224 lines · Lijo
Quoted 222 lines · Sunil Khatri

Refactor the code so debugfs and devcoredump can reuse the common information and avoid unnecessary copy of it.

created a new file which would be the right place to hold functions which will be used between sysfs, debugfs and devcoredump.

Cc Christian König <[email protected]>
Cc Alex Deucher <[email protected]>

---
  drivers/gpu/drm/amd/amdgpu/Makefile         |   2 +- drivers/gpu/drm/amd/amdgpu/amdgpu.h         |   1 + drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c | 151 ++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c     | 118 +--------------

  4 files changed, 157 insertions(+), 115 deletions(-)

  create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c

drivers/gpu/drm/amd/amdgpu/Makefile +1 -1
index 4536c8ad0e11..05d34f4b18f5 100644
@@ -80,7 +80,7 @@ amdgpu-y += amdgpu_device.o amdgpu_doorbell_mgr.o
 amdgpu_kms.o \
       amdgpu_umc.o smu_v11_0_i2c.o amdgpu_fru_eeprom.o amdgpu_rap.o \
       amdgpu_fw_attestation.o amdgpu_securedisplay.o \
       amdgpu_eeprom.o amdgpu_mca.o amdgpu_psp_ta.o amdgpu_lsdma.o \
-    amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o
+    amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o

amdgpu_devinfo.o
    amdgpu-$(CONFIG_PROC_FS) += amdgpu_fdinfo.o diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h index 9c62552bec34..0267870aa9b1 100644

drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
@@ -1609,4 +1609,5 @@ extern const struct attribute_group
 amdgpu_vram_mgr_attr_group;
   extern const struct attribute_group amdgpu_gtt_mgr_attr_group;
   extern const struct attribute_group amdgpu_flash_attr_group;

  +int amdgpu_device_info(struct amdgpu_device *adev, struct drm_amdgpu_info_device *dev_info);
  #endif

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +5 -0
new file mode 100644
index 000000000000..d2c15a1dcb0d
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2024 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +7 -0
+
+#include "amdgpu.h"
+#include "amd_pcie.h"
+
+#include <drm/amdgpu_drm.h>
+
+int amdgpu_device_info(struct amdgpu_device *adev, struct

drm_amdgpu_info_device *dev_info)

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +15 -0
+{
+    int ret;
+    uint64_t vm_size;
+    uint32_t pcie_gen_mask;
+
+    if (dev_info == NULL)
+        return -EINVAL;
+
+    dev_info->device_id = adev->pdev->device;
+    dev_info->chip_rev = adev->rev_id;
+    dev_info->external_rev = adev->external_rev_id;
+    dev_info->pci_rev = adev->pdev->revision;
+    dev_info->family = adev->family;
+    dev_info->num_shader_engines = adev->gfx.config.max_shader_engines;
+    dev_info->num_shader_arrays_per_engine =

adev->gfx.config.max_sh_per_se;
+    /* return all clocks in KHz */
+    dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10; +    if (adev->pm.dpm_enabled) {
+        dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev, false) * 10;
+        dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev, false) * 10;
+        dev_info->min_engine_clock = amdgpu_dpm_get_sclk(adev, true)
* 10;
+        dev_info->min_memory_clock = amdgpu_dpm_get_mclk(adev, true)
* 10;
+    } else {
+        dev_info->max_engine_clock =
+            dev_info->min_engine_clock =
+                adev->clock.default_sclk * 10;
+        dev_info->max_memory_clock =
+            dev_info->min_memory_clock =
+                adev->clock.default_mclk * 10;
+        }
+    dev_info->enabled_rb_pipes_mask = adev->gfx.config.backend_enable_mask;
+    dev_info->num_rb_pipes = adev->gfx.config.max_backends_per_se * +        adev->gfx.config.max_shader_engines;
+    dev_info->num_hw_gfx_contexts = adev->gfx.config.max_hw_contexts; +    dev_info->ids_flags = 0;
+    if (adev->flags & AMD_IS_APU)
+        dev_info->ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
+    if (adev->gfx.mcbp)
+        dev_info->ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION; +    if (amdgpu_is_tmz(adev))
+        dev_info->ids_flags |= AMDGPU_IDS_FLAGS_TMZ;
+    if (adev->gfx.config.ta_cntl2_truncate_coord_mode)
+        dev_info->ids_flags |= AMDGPU_IDS_FLAGS_CONFORMANT_TRUNC_COORD;

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +6 -0
+
+    vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
+    vm_size -= AMDGPU_VA_RESERVED_TOP;
+
+    /* Older VCE FW versions are buggy and can handle only 40bits */
+    if (adev->vce.fw_version && adev->vce.fw_version <

AMDGPU_VCE_FW_53_45)
+        vm_size = min(vm_size, 1ULL << 40);
+
+    dev_info->virtual_address_offset = AMDGPU_VA_RESERVED_BOTTOM; +    dev_info->virtual_address_max = min(vm_size, AMDGPU_GMC_HOLE_START);
+
+    if (vm_size > AMDGPU_GMC_HOLE_START) {
+        dev_info->high_va_offset = AMDGPU_GMC_HOLE_END;
+        dev_info->high_va_max = AMDGPU_GMC_HOLE_END | vm_size; +    }
+    dev_info->virtual_address_alignment = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
+    dev_info->pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
+    dev_info->gart_page_size = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
+    dev_info->cu_active_number = adev->gfx.cu_info.number; +    dev_info->cu_ao_mask = adev->gfx.cu_info.ao_cu_mask;
+    dev_info->ce_ram_size = adev->gfx.ce_ram_size;
+    memcpy(&dev_info->cu_ao_bitmap[0], &adev->gfx.cu_info.ao_cu_bitmap[0],
+           sizeof(adev->gfx.cu_info.ao_cu_bitmap));
+    memcpy(&dev_info->cu_bitmap[0], &adev->gfx.cu_info.bitmap[0], +           sizeof(dev_info->cu_bitmap));
+    dev_info->vram_type = adev->gmc.vram_type;
+    dev_info->vram_bit_width = adev->gmc.vram_width;
+    dev_info->vce_harvest_config = adev->vce.harvest_config; +    dev_info->gc_double_offchip_lds_buf =
+        adev->gfx.config.double_offchip_lds_buf;
+    dev_info->wave_front_size = adev->gfx.cu_info.wave_front_size; +    dev_info->num_shader_visible_vgprs = adev->gfx.config.max_gprs; +    dev_info->num_cu_per_sh = adev->gfx.config.max_cu_per_sh; +    dev_info->num_tcc_blocks = adev->gfx.config.max_texture_channel_caches;
+    dev_info->gs_vgt_table_depth = adev->gfx.config.gs_vgt_table_depth; +    dev_info->gs_prim_buffer_depth = adev->gfx.config.gs_prim_buffer_depth;
+    dev_info->max_gs_waves_per_vgt = adev->gfx.config.max_gs_threads;

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +9 -0
+
+    if (adev->family >= AMDGPU_FAMILY_NV)
+        dev_info->pa_sc_tile_steering_override =
+            adev->gfx.config.pa_sc_tile_steering_override;
+
+    dev_info->tcc_disabled_mask = adev->gfx.config.tcc_disabled_mask;
+
+    /* Combine the chip gen mask with the platform (CPU/mobo) mask. */
+    pcie_gen_mask = adev->pm.pcie_gen_mask & (adev->pm.pcie_gen_mask
Quoted 1 line
Quoted 1 line

16);

+    dev_info->pcie_gen = fls(pcie_gen_mask);
+    dev_info->pcie_num_lanes =
+        adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 ? 32 :
+        adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 ? 16 :
+        adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 ? 12 :
+        adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 ? 8 :
+        adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 ? 4 :
+        adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 ? 2 : 1;
+
+    dev_info->tcp_cache_size = adev->gfx.config.gc_tcp_l1_size; +    dev_info->num_sqc_per_wgp = adev->gfx.config.gc_num_sqc_per_wgp; +    dev_info->sqc_data_cache_size = adev->gfx.config.gc_l1_data_cache_size_per_sqc;
+    dev_info->sqc_inst_cache_size = adev->gfx.config.gc_l1_instruction_cache_size_per_sqc;
+    dev_info->gl1c_cache_size = adev->gfx.config.gc_gl1c_size_per_instance *
+                    adev->gfx.config.gc_gl1c_per_sa;
+    dev_info->gl2c_cache_size = adev->gfx.config.gc_gl2c_per_gpu; +    dev_info->mall_size = adev->gmc.mall_size;

Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c line 142

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +6 -0
+
+
+    if (adev->gfx.funcs->get_gfx_shadow_info) {
+        struct amdgpu_gfx_shadow_info shadow_info;
+
+        ret = amdgpu_gfx_get_gfx_shadow_info(adev, &shadow_info);

This failure is ignored in the present logic and rest of the information is filled. Probably, need to continue the same way.

Quoted 8 lines

Since this is the information that we are sharing with user and on any failure we just decide not to populate those fields. By default all the members are initialized to zero and they

are updated when we have valid values. To me seems the right logic instead of failing the complete call, we provide the information what we have.

Actually, this is not what is really done. If you fail here, then this happens down the call. It doesn't copy, instead frees without copying to userspace.

+ ret = amdgpu_device_info(adev, dev_info);
+ if (!ret) {

Thanks,
Lijo

Quoted 181 lines

Regards
Sunil

Quoted 178 lines

Thanks,
Lijo

Quoted 174 lines

+        if (!ret) {
+            dev_info->shadow_size = shadow_info.shadow_size; +            dev_info->shadow_alignment = shadow_info.shadow_alignment; +            dev_info->csa_size = shadow_info.csa_size;
+            dev_info->csa_alignment = shadow_info.csa_alignment; +        }
+    }
+    return ret;

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +1 -0
+}
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -27
index a66d47865e3b..24f775c68a51 100644
@@ -850,125 +850,15 @@ int amdgpu_info_ioctl(struct drm_device *dev,
 void *data, struct drm_file *filp)
       }
       case AMDGPU_INFO_DEV_INFO: {
           struct drm_amdgpu_info_device *dev_info;
-        uint64_t vm_size;
-        uint32_t pcie_gen_mask;
             dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL);
           if (!dev_info)
               return -ENOMEM;
   -        dev_info->device_id = adev->pdev->device;
-        dev_info->chip_rev = adev->rev_id;
-        dev_info->external_rev = adev->external_rev_id;
-        dev_info->pci_rev = adev->pdev->revision;
-        dev_info->family = adev->family;
-        dev_info->num_shader_engines =
 adev->gfx.config.max_shader_engines;
-        dev_info->num_shader_arrays_per_engine =
 adev->gfx.config.max_sh_per_se;
-        /* return all clocks in KHz */
-        dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
-        if (adev->pm.dpm_enabled) {
-            dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev,
 false) * 10;
-            dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev,
 false) * 10;
-            dev_info->min_engine_clock = amdgpu_dpm_get_sclk(adev,
 true) * 10;
-            dev_info->min_memory_clock = amdgpu_dpm_get_mclk(adev,
 true) * 10;
-        } else {
-            dev_info->max_engine_clock =
-                dev_info->min_engine_clock =
-                    adev->clock.default_sclk * 10;
-            dev_info->max_memory_clock =
-                dev_info->min_memory_clock =
-                    adev->clock.default_mclk * 10;
-        }
-        dev_info->enabled_rb_pipes_mask =
 adev->gfx.config.backend_enable_mask;
-        dev_info->num_rb_pipes = adev->gfx.config.max_backends_per_se *
-            adev->gfx.config.max_shader_engines;
-        dev_info->num_hw_gfx_contexts =

adev->gfx.config.max_hw_contexts;
-        dev_info->ids_flags = 0;
-        if (adev->flags & AMD_IS_APU)
-            dev_info->ids_flags |= AMDGPU_IDS_FLAGS_FUSION; -        if (adev->gfx.mcbp)
-            dev_info->ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION; -        if (amdgpu_is_tmz(adev))
-            dev_info->ids_flags |= AMDGPU_IDS_FLAGS_TMZ; -        if (adev->gfx.config.ta_cntl2_truncate_coord_mode) -            dev_info->ids_flags |= AMDGPU_IDS_FLAGS_CONFORMANT_TRUNC_COORD;

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -5
-
-        vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
-        vm_size -= AMDGPU_VA_RESERVED_TOP;
-
-        /* Older VCE FW versions are buggy and can handle only

40bits */
-        if (adev->vce.fw_version &&
-            adev->vce.fw_version < AMDGPU_VCE_FW_53_45) -            vm_size = min(vm_size, 1ULL << 40);

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -10
-
-        dev_info->virtual_address_offset = AMDGPU_VA_RESERVED_BOTTOM;
-        dev_info->virtual_address_max =
-            min(vm_size, AMDGPU_GMC_HOLE_START);
-
-        if (vm_size > AMDGPU_GMC_HOLE_START) {
-            dev_info->high_va_offset = AMDGPU_GMC_HOLE_END;
-            dev_info->high_va_max = AMDGPU_GMC_HOLE_END | vm_size;
-        }
-        dev_info->virtual_address_alignment = max_t(u32, PAGE_SIZE,

AMDGPU_GPU_PAGE_SIZE);
-        dev_info->pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
-        dev_info->gart_page_size = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
-        dev_info->cu_active_number = adev->gfx.cu_info.number; -        dev_info->cu_ao_mask = adev->gfx.cu_info.ao_cu_mask; -        dev_info->ce_ram_size = adev->gfx.ce_ram_size;
-        memcpy(&dev_info->cu_ao_bitmap[0], &adev->gfx.cu_info.ao_cu_bitmap[0],
-               sizeof(adev->gfx.cu_info.ao_cu_bitmap));
-        memcpy(&dev_info->cu_bitmap[0], &adev->gfx.cu_info.bitmap[0], -               sizeof(dev_info->cu_bitmap));
-        dev_info->vram_type = adev->gmc.vram_type;
-        dev_info->vram_bit_width = adev->gmc.vram_width;
-        dev_info->vce_harvest_config = adev->vce.harvest_config; -        dev_info->gc_double_offchip_lds_buf =
-            adev->gfx.config.double_offchip_lds_buf;
-        dev_info->wave_front_size = adev->gfx.cu_info.wave_front_size; -        dev_info->num_shader_visible_vgprs = adev->gfx.config.max_gprs; -        dev_info->num_cu_per_sh = adev->gfx.config.max_cu_per_sh; -        dev_info->num_tcc_blocks = adev->gfx.config.max_texture_channel_caches;
-        dev_info->gs_vgt_table_depth = adev->gfx.config.gs_vgt_table_depth;
-        dev_info->gs_prim_buffer_depth = adev->gfx.config.gs_prim_buffer_depth;
-        dev_info->max_gs_waves_per_vgt = adev->gfx.config.max_gs_threads;

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -6
-
-        if (adev->family >= AMDGPU_FAMILY_NV)
-            dev_info->pa_sc_tile_steering_override =
-                adev->gfx.config.pa_sc_tile_steering_override;
-
-        dev_info->tcc_disabled_mask =

adev->gfx.config.tcc_disabled_mask;
-
-        /* Combine the chip gen mask with the platform (CPU/mobo) mask. */
-        pcie_gen_mask = adev->pm.pcie_gen_mask & (adev->pm.pcie_gen_mask >> 16);
-        dev_info->pcie_gen = fls(pcie_gen_mask);
-        dev_info->pcie_num_lanes =
-            adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 ? 32 :
-            adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 ? 16 :
-            adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 ? 12 :
-            adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 ? 8 :
-            adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 ? 4 :
-            adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 ? 2 : 1;
-
-        dev_info->tcp_cache_size = adev->gfx.config.gc_tcp_l1_size; -        dev_info->num_sqc_per_wgp = adev->gfx.config.gc_num_sqc_per_wgp;
-        dev_info->sqc_data_cache_size = adev->gfx.config.gc_l1_data_cache_size_per_sqc;
-        dev_info->sqc_inst_cache_size = adev->gfx.config.gc_l1_instruction_cache_size_per_sqc;
-        dev_info->gl1c_cache_size = adev->gfx.config.gc_gl1c_size_per_instance *
-                        adev->gfx.config.gc_gl1c_per_sa;
-        dev_info->gl2c_cache_size = adev->gfx.config.gc_gl2c_per_gpu; -        dev_info->mall_size = adev->gmc.mall_size;

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -9
-
-
-        if (adev->gfx.funcs->get_gfx_shadow_info) {
-            struct amdgpu_gfx_shadow_info shadow_info;
-
-            ret = amdgpu_gfx_get_gfx_shadow_info(adev, &shadow_info);
-            if (!ret) {
-                dev_info->shadow_size = shadow_info.shadow_size;
-                dev_info->shadow_alignment =

shadow_info.shadow_alignment;
-                dev_info->csa_size = shadow_info.csa_size; -                dev_info->csa_alignment = shadow_info.csa_alignment; -            }
+        ret = amdgpu_device_info(adev, dev_info);
+        if (!ret) {
+            kfree(dev_info);
+            return ret;
          }
            ret = copy_to_user(out, dev_info,

#5 lore raw
Quoted 246 lines · Lijo
Quoted 232 lines · Sunil
Quoted 223 lines · Lijo
Quoted 222 lines · Sunil Khatri

Refactor the code so debugfs and devcoredump can reuse the common information and avoid unnecessary copy of it.

created a new file which would be the right place to hold functions which will be used between sysfs, debugfs and devcoredump.

Cc Christian König<[email protected]>
Cc Alex Deucher<[email protected]>
---
   drivers/gpu/drm/amd/amdgpu/Makefile         |   2 +-
   drivers/gpu/drm/amd/amdgpu/amdgpu.h         |   1 +
   drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c | 151 ++++++++++++++++++++
   drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c     | 118 +--------------
   4 files changed, 157 insertions(+), 115 deletions(-)

  create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c

drivers/gpu/drm/amd/amdgpu/Makefile +1 -1
index 4536c8ad0e11..05d34f4b18f5 100644
@@ -80,7 +80,7 @@ amdgpu-y += amdgpu_device.o amdgpu_doorbell_mgr.o
 amdgpu_kms.o \
       amdgpu_umc.o smu_v11_0_i2c.o amdgpu_fru_eeprom.o amdgpu_rap.o \
       amdgpu_fw_attestation.o amdgpu_securedisplay.o \
       amdgpu_eeprom.o amdgpu_mca.o amdgpu_psp_ta.o amdgpu_lsdma.o \
-    amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o
+    amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o

amdgpu_devinfo.o
    amdgpu-$(CONFIG_PROC_FS) += amdgpu_fdinfo.o diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 9c62552bec34..0267870aa9b1 100644

drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
@@ -1609,4 +1609,5 @@ extern const struct attribute_group
 amdgpu_vram_mgr_attr_group;
   extern const struct attribute_group amdgpu_gtt_mgr_attr_group;
   extern const struct attribute_group amdgpu_flash_attr_group;
   +int amdgpu_device_info(struct amdgpu_device *adev, struct

drm_amdgpu_info_device *dev_info);
  #endif

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +5 -0
new file mode 100644
index 000000000000..d2c15a1dcb0d
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2024 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +7 -0
+
+#include "amdgpu.h"
+#include "amd_pcie.h"
+
+#include <drm/amdgpu_drm.h>
+
+int amdgpu_device_info(struct amdgpu_device *adev, struct

drm_amdgpu_info_device *dev_info)

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +15 -0
+{
+    int ret;
+    uint64_t vm_size;
+    uint32_t pcie_gen_mask;
+
+    if (dev_info == NULL)
+        return -EINVAL;
+
+    dev_info->device_id = adev->pdev->device;
+    dev_info->chip_rev = adev->rev_id;
+    dev_info->external_rev = adev->external_rev_id;
+    dev_info->pci_rev = adev->pdev->revision;
+    dev_info->family = adev->family;
+    dev_info->num_shader_engines = adev->gfx.config.max_shader_engines;
+    dev_info->num_shader_arrays_per_engine =

adev->gfx.config.max_sh_per_se;
+    /* return all clocks in KHz */
+    dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10; +    if (adev->pm.dpm_enabled) {
+        dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev, false) * 10;
+        dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev, false) * 10;
+        dev_info->min_engine_clock = amdgpu_dpm_get_sclk(adev, true)
* 10;
+        dev_info->min_memory_clock = amdgpu_dpm_get_mclk(adev, true)
* 10;
+    } else {
+        dev_info->max_engine_clock =
+            dev_info->min_engine_clock =
+                adev->clock.default_sclk * 10;
+        dev_info->max_memory_clock =
+            dev_info->min_memory_clock =
+                adev->clock.default_mclk * 10;
+        }
+    dev_info->enabled_rb_pipes_mask = adev->gfx.config.backend_enable_mask;
+    dev_info->num_rb_pipes = adev->gfx.config.max_backends_per_se * +        adev->gfx.config.max_shader_engines;
+    dev_info->num_hw_gfx_contexts = adev->gfx.config.max_hw_contexts; +    dev_info->ids_flags = 0;
+    if (adev->flags & AMD_IS_APU)
+        dev_info->ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
+    if (adev->gfx.mcbp)
+        dev_info->ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION; +    if (amdgpu_is_tmz(adev))
+        dev_info->ids_flags |= AMDGPU_IDS_FLAGS_TMZ;
+    if (adev->gfx.config.ta_cntl2_truncate_coord_mode)
+        dev_info->ids_flags |= AMDGPU_IDS_FLAGS_CONFORMANT_TRUNC_COORD;

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +6 -0
+
+    vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
+    vm_size -= AMDGPU_VA_RESERVED_TOP;
+
+    /* Older VCE FW versions are buggy and can handle only 40bits */
+    if (adev->vce.fw_version && adev->vce.fw_version <

AMDGPU_VCE_FW_53_45)
+        vm_size = min(vm_size, 1ULL << 40);
+
+    dev_info->virtual_address_offset = AMDGPU_VA_RESERVED_BOTTOM; +    dev_info->virtual_address_max = min(vm_size, AMDGPU_GMC_HOLE_START);
+
+    if (vm_size > AMDGPU_GMC_HOLE_START) {
+        dev_info->high_va_offset = AMDGPU_GMC_HOLE_END;
+        dev_info->high_va_max = AMDGPU_GMC_HOLE_END | vm_size; +    }
+    dev_info->virtual_address_alignment = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
+    dev_info->pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
+    dev_info->gart_page_size = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
+    dev_info->cu_active_number = adev->gfx.cu_info.number; +    dev_info->cu_ao_mask = adev->gfx.cu_info.ao_cu_mask;
+    dev_info->ce_ram_size = adev->gfx.ce_ram_size;
+    memcpy(&dev_info->cu_ao_bitmap[0], &adev->gfx.cu_info.ao_cu_bitmap[0],
+           sizeof(adev->gfx.cu_info.ao_cu_bitmap));
+    memcpy(&dev_info->cu_bitmap[0], &adev->gfx.cu_info.bitmap[0], +           sizeof(dev_info->cu_bitmap));
+    dev_info->vram_type = adev->gmc.vram_type;
+    dev_info->vram_bit_width = adev->gmc.vram_width;
+    dev_info->vce_harvest_config = adev->vce.harvest_config; +    dev_info->gc_double_offchip_lds_buf =
+        adev->gfx.config.double_offchip_lds_buf;
+    dev_info->wave_front_size = adev->gfx.cu_info.wave_front_size; +    dev_info->num_shader_visible_vgprs = adev->gfx.config.max_gprs; +    dev_info->num_cu_per_sh = adev->gfx.config.max_cu_per_sh; +    dev_info->num_tcc_blocks = adev->gfx.config.max_texture_channel_caches;
+    dev_info->gs_vgt_table_depth = adev->gfx.config.gs_vgt_table_depth; +    dev_info->gs_prim_buffer_depth = adev->gfx.config.gs_prim_buffer_depth;
+    dev_info->max_gs_waves_per_vgt = adev->gfx.config.max_gs_threads;

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +9 -0
+
+    if (adev->family >= AMDGPU_FAMILY_NV)
+        dev_info->pa_sc_tile_steering_override =
+            adev->gfx.config.pa_sc_tile_steering_override;
+
+    dev_info->tcc_disabled_mask = adev->gfx.config.tcc_disabled_mask;
+
+    /* Combine the chip gen mask with the platform (CPU/mobo) mask. */
+    pcie_gen_mask = adev->pm.pcie_gen_mask & (adev->pm.pcie_gen_mask
Quoted 1 line
Quoted 1 line

16);

+    dev_info->pcie_gen = fls(pcie_gen_mask);
+    dev_info->pcie_num_lanes =
+        adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 ? 32 :
+        adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 ? 16 :
+        adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 ? 12 :
+        adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 ? 8 :
+        adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 ? 4 :
+        adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 ? 2 : 1;
+
+    dev_info->tcp_cache_size = adev->gfx.config.gc_tcp_l1_size; +    dev_info->num_sqc_per_wgp = adev->gfx.config.gc_num_sqc_per_wgp; +    dev_info->sqc_data_cache_size = adev->gfx.config.gc_l1_data_cache_size_per_sqc;
+    dev_info->sqc_inst_cache_size = adev->gfx.config.gc_l1_instruction_cache_size_per_sqc;
+    dev_info->gl1c_cache_size = adev->gfx.config.gc_gl1c_size_per_instance *
+                    adev->gfx.config.gc_gl1c_per_sa;
+    dev_info->gl2c_cache_size = adev->gfx.config.gc_gl2c_per_gpu; +    dev_info->mall_size = adev->gmc.mall_size;

Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c line 142

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +6 -0
+
+
+    if (adev->gfx.funcs->get_gfx_shadow_info) {
+        struct amdgpu_gfx_shadow_info shadow_info;
+
+        ret = amdgpu_gfx_get_gfx_shadow_info(adev, &shadow_info);

This failure is ignored in the present logic and rest of the information is filled. Probably, need to continue the same way.

Quoted 8 lines

Since this is the information that we are sharing with user and on any failure we just decide not to populate those fields. By default all the members are initialized to zero and they

are updated when we have valid values. To me seems the right logic instead of failing the complete call, we provide the information what we have.

Actually, this is not what is really done. If you fail here, then this happens down the call. It doesn't copy, instead frees without copying to userspace.

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) · line 859

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +2 -0
+        ret = amdgpu_device_info(adev, dev_info);
+        if (!ret) {

Good point. Actually my intent was only to check the valid memory as amdgpu_device_info will be used in other places too but yes amdgpu_gfx_get_gfx_shadow_infocould also send failure. I propose that to not send the error for amdgpu_gfx_get_gfx_shadow_info. I will update the patch with that information.

Quoted 184 lines

Thanks,
Lijo

Quoted 180 lines

Regards
Sunil

Quoted 177 lines

Thanks,
Lijo

Quoted 174 lines

+        if (!ret) {
+            dev_info->shadow_size = shadow_info.shadow_size; +            dev_info->shadow_alignment = shadow_info.shadow_alignment; +            dev_info->csa_size = shadow_info.csa_size;
+            dev_info->csa_alignment = shadow_info.csa_alignment; +        }
+    }
+    return ret;

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +1 -0
+}
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -27
index a66d47865e3b..24f775c68a51 100644
@@ -850,125 +850,15 @@ int amdgpu_info_ioctl(struct drm_device *dev,
 void *data, struct drm_file *filp)
       }
       case AMDGPU_INFO_DEV_INFO: {
           struct drm_amdgpu_info_device *dev_info;
-        uint64_t vm_size;
-        uint32_t pcie_gen_mask;
             dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL);
           if (!dev_info)
               return -ENOMEM;
   -        dev_info->device_id = adev->pdev->device;
-        dev_info->chip_rev = adev->rev_id;
-        dev_info->external_rev = adev->external_rev_id;
-        dev_info->pci_rev = adev->pdev->revision;
-        dev_info->family = adev->family;
-        dev_info->num_shader_engines =
 adev->gfx.config.max_shader_engines;
-        dev_info->num_shader_arrays_per_engine =
 adev->gfx.config.max_sh_per_se;
-        /* return all clocks in KHz */
-        dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
-        if (adev->pm.dpm_enabled) {
-            dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev,
 false) * 10;
-            dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev,
 false) * 10;
-            dev_info->min_engine_clock = amdgpu_dpm_get_sclk(adev,
 true) * 10;
-            dev_info->min_memory_clock = amdgpu_dpm_get_mclk(adev,
 true) * 10;
-        } else {
-            dev_info->max_engine_clock =
-                dev_info->min_engine_clock =
-                    adev->clock.default_sclk * 10;
-            dev_info->max_memory_clock =
-                dev_info->min_memory_clock =
-                    adev->clock.default_mclk * 10;
-        }
-        dev_info->enabled_rb_pipes_mask =
 adev->gfx.config.backend_enable_mask;
-        dev_info->num_rb_pipes = adev->gfx.config.max_backends_per_se *
-            adev->gfx.config.max_shader_engines;
-        dev_info->num_hw_gfx_contexts =

adev->gfx.config.max_hw_contexts;
-        dev_info->ids_flags = 0;
-        if (adev->flags & AMD_IS_APU)
-            dev_info->ids_flags |= AMDGPU_IDS_FLAGS_FUSION; -        if (adev->gfx.mcbp)
-            dev_info->ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION; -        if (amdgpu_is_tmz(adev))
-            dev_info->ids_flags |= AMDGPU_IDS_FLAGS_TMZ; -        if (adev->gfx.config.ta_cntl2_truncate_coord_mode) -            dev_info->ids_flags |= AMDGPU_IDS_FLAGS_CONFORMANT_TRUNC_COORD;

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -5
-
-        vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
-        vm_size -= AMDGPU_VA_RESERVED_TOP;
-
-        /* Older VCE FW versions are buggy and can handle only

40bits */
-        if (adev->vce.fw_version &&
-            adev->vce.fw_version < AMDGPU_VCE_FW_53_45) -            vm_size = min(vm_size, 1ULL << 40);

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -10
-
-        dev_info->virtual_address_offset = AMDGPU_VA_RESERVED_BOTTOM;
-        dev_info->virtual_address_max =
-            min(vm_size, AMDGPU_GMC_HOLE_START);
-
-        if (vm_size > AMDGPU_GMC_HOLE_START) {
-            dev_info->high_va_offset = AMDGPU_GMC_HOLE_END;
-            dev_info->high_va_max = AMDGPU_GMC_HOLE_END | vm_size;
-        }
-        dev_info->virtual_address_alignment = max_t(u32, PAGE_SIZE,

AMDGPU_GPU_PAGE_SIZE);
-        dev_info->pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
-        dev_info->gart_page_size = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
-        dev_info->cu_active_number = adev->gfx.cu_info.number; -        dev_info->cu_ao_mask = adev->gfx.cu_info.ao_cu_mask; -        dev_info->ce_ram_size = adev->gfx.ce_ram_size;
-        memcpy(&dev_info->cu_ao_bitmap[0], &adev->gfx.cu_info.ao_cu_bitmap[0],
-               sizeof(adev->gfx.cu_info.ao_cu_bitmap));
-        memcpy(&dev_info->cu_bitmap[0], &adev->gfx.cu_info.bitmap[0], -               sizeof(dev_info->cu_bitmap));
-        dev_info->vram_type = adev->gmc.vram_type;
-        dev_info->vram_bit_width = adev->gmc.vram_width;
-        dev_info->vce_harvest_config = adev->vce.harvest_config; -        dev_info->gc_double_offchip_lds_buf =
-            adev->gfx.config.double_offchip_lds_buf;
-        dev_info->wave_front_size = adev->gfx.cu_info.wave_front_size; -        dev_info->num_shader_visible_vgprs = adev->gfx.config.max_gprs; -        dev_info->num_cu_per_sh = adev->gfx.config.max_cu_per_sh; -        dev_info->num_tcc_blocks = adev->gfx.config.max_texture_channel_caches;
-        dev_info->gs_vgt_table_depth = adev->gfx.config.gs_vgt_table_depth;
-        dev_info->gs_prim_buffer_depth = adev->gfx.config.gs_prim_buffer_depth;
-        dev_info->max_gs_waves_per_vgt = adev->gfx.config.max_gs_threads;

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -6
-
-        if (adev->family >= AMDGPU_FAMILY_NV)
-            dev_info->pa_sc_tile_steering_override =
-                adev->gfx.config.pa_sc_tile_steering_override;
-
-        dev_info->tcc_disabled_mask =

adev->gfx.config.tcc_disabled_mask;
-
-        /* Combine the chip gen mask with the platform (CPU/mobo) mask. */
-        pcie_gen_mask = adev->pm.pcie_gen_mask & (adev->pm.pcie_gen_mask >> 16);
-        dev_info->pcie_gen = fls(pcie_gen_mask);
-        dev_info->pcie_num_lanes =
-            adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 ? 32 :
-            adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 ? 16 :
-            adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 ? 12 :
-            adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 ? 8 :
-            adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 ? 4 :
-            adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 ? 2 : 1;
-
-        dev_info->tcp_cache_size = adev->gfx.config.gc_tcp_l1_size; -        dev_info->num_sqc_per_wgp = adev->gfx.config.gc_num_sqc_per_wgp;
-        dev_info->sqc_data_cache_size = adev->gfx.config.gc_l1_data_cache_size_per_sqc;
-        dev_info->sqc_inst_cache_size = adev->gfx.config.gc_l1_instruction_cache_size_per_sqc;
-        dev_info->gl1c_cache_size = adev->gfx.config.gc_gl1c_size_per_instance *
-                        adev->gfx.config.gc_gl1c_per_sa;
-        dev_info->gl2c_cache_size = adev->gfx.config.gc_gl2c_per_gpu; -        dev_info->mall_size = adev->gmc.mall_size;

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -9
-
-
-        if (adev->gfx.funcs->get_gfx_shadow_info) {
-            struct amdgpu_gfx_shadow_info shadow_info;
-
-            ret = amdgpu_gfx_get_gfx_shadow_info(adev, &shadow_info);
-            if (!ret) {
-                dev_info->shadow_size = shadow_info.shadow_size;
-                dev_info->shadow_alignment =

shadow_info.shadow_alignment;
-                dev_info->csa_size = shadow_info.csa_size; -                dev_info->csa_alignment = shadow_info.csa_alignment; -            }
+        ret = amdgpu_device_info(adev, dev_info);
+        if (!ret) {
+            kfree(dev_info);
+            return ret;
          }
            ret = copy_to_user(out, dev_info,

#6 lore raw
In reply to Lazar, Lijo
Quoted 243 lines · Lijo
Quoted 239 lines · Sunil
Quoted 224 lines · Lijo
Quoted 222 lines · Sunil Khatri

Refactor the code so debugfs and devcoredump can reuse the common information and avoid unnecessary copy of it.

created a new file which would be the right place to hold functions which will be used between sysfs, debugfs and devcoredump.

Cc Christian König <[email protected]>
Cc Alex Deucher <[email protected]>
---
  drivers/gpu/drm/amd/amdgpu/Makefile         |   2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu.h         |   1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c | 151 ++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c     | 118 +--------------
  4 files changed, 157 insertions(+), 115 deletions(-)

create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c

drivers/gpu/drm/amd/amdgpu/Makefile +1 -1
index 4536c8ad0e11..05d34f4b18f5 100644
@@ -80,7 +80,7 @@ amdgpu-y += amdgpu_device.o amdgpu_doorbell_mgr.o
 amdgpu_kms.o \
      amdgpu_umc.o smu_v11_0_i2c.o amdgpu_fru_eeprom.o amdgpu_rap.o \
      amdgpu_fw_attestation.o amdgpu_securedisplay.o \
      amdgpu_eeprom.o amdgpu_mca.o amdgpu_psp_ta.o amdgpu_lsdma.o \
-    amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o
+    amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o

amdgpu_devinfo.o

    amdgpu-$(CONFIG_PROC_FS) += amdgpu_fdinfo.o

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h index 9c62552bec34..0267870aa9b1 100644

drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
@@ -1609,4 +1609,5 @@ extern const struct attribute_group
 amdgpu_vram_mgr_attr_group;
  extern const struct attribute_group amdgpu_gtt_mgr_attr_group;
  extern const struct attribute_group amdgpu_flash_attr_group;
  +int amdgpu_device_info(struct amdgpu_device *adev, struct

drm_amdgpu_info_device *dev_info);
#endif

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +5 -0
new file mode 100644
index 000000000000..d2c15a1dcb0d
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2024 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +7 -0
+
+#include "amdgpu.h"
+#include "amd_pcie.h"
+
+#include <drm/amdgpu_drm.h>
+
+int amdgpu_device_info(struct amdgpu_device *adev, struct

drm_amdgpu_info_device *dev_info)

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +15 -0
+{
+    int ret;
+    uint64_t vm_size;
+    uint32_t pcie_gen_mask;
+
+    if (dev_info == NULL)
+        return -EINVAL;
+
+    dev_info->device_id = adev->pdev->device;
+    dev_info->chip_rev = adev->rev_id;
+    dev_info->external_rev = adev->external_rev_id;
+    dev_info->pci_rev = adev->pdev->revision;
+    dev_info->family = adev->family;
+    dev_info->num_shader_engines = adev->gfx.config.max_shader_engines;
+    dev_info->num_shader_arrays_per_engine =

adev->gfx.config.max_sh_per_se;

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +4 -0
+    /* return all clocks in KHz */
+    dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
+    if (adev->pm.dpm_enabled) {
+        dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev,

false) * 10;
+ dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev,
false) * 10;
+ dev_info->min_engine_clock = amdgpu_dpm_get_sclk(adev, true)
* 10;
+ dev_info->min_memory_clock = amdgpu_dpm_get_mclk(adev, true)
* 10;

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +9 -0
+    } else {
+        dev_info->max_engine_clock =
+            dev_info->min_engine_clock =
+                adev->clock.default_sclk * 10;
+        dev_info->max_memory_clock =
+            dev_info->min_memory_clock =
+                adev->clock.default_mclk * 10;
+        }
+    dev_info->enabled_rb_pipes_mask =

adev->gfx.config.backend_enable_mask;

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +18 -0
+    dev_info->num_rb_pipes = adev->gfx.config.max_backends_per_se *
+        adev->gfx.config.max_shader_engines;
+    dev_info->num_hw_gfx_contexts = adev->gfx.config.max_hw_contexts;
+    dev_info->ids_flags = 0;
+    if (adev->flags & AMD_IS_APU)
+        dev_info->ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
+    if (adev->gfx.mcbp)
+        dev_info->ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
+    if (amdgpu_is_tmz(adev))
+        dev_info->ids_flags |= AMDGPU_IDS_FLAGS_TMZ;
+    if (adev->gfx.config.ta_cntl2_truncate_coord_mode)
+        dev_info->ids_flags |= AMDGPU_IDS_FLAGS_CONFORMANT_TRUNC_COORD;
+
+    vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
+    vm_size -= AMDGPU_VA_RESERVED_TOP;
+
+    /* Older VCE FW versions are buggy and can handle only 40bits */
+    if (adev->vce.fw_version && adev->vce.fw_version <

AMDGPU_VCE_FW_53_45)

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +4 -0
+        vm_size = min(vm_size, 1ULL << 40);
+
+    dev_info->virtual_address_offset = AMDGPU_VA_RESERVED_BOTTOM;
+    dev_info->virtual_address_max = min(vm_size,

AMDGPU_GMC_HOLE_START);

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +6 -0
+
+    if (vm_size > AMDGPU_GMC_HOLE_START) {
+        dev_info->high_va_offset = AMDGPU_GMC_HOLE_END;
+        dev_info->high_va_max = AMDGPU_GMC_HOLE_END | vm_size;
+    }
+    dev_info->virtual_address_alignment = max_t(u32, PAGE_SIZE,

AMDGPU_GPU_PAGE_SIZE);
+ dev_info->pte_fragment_size = (1 <<
adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
+ dev_info->gart_page_size = max_t(u32, PAGE_SIZE,
AMDGPU_GPU_PAGE_SIZE);

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +4 -0
+    dev_info->cu_active_number = adev->gfx.cu_info.number;
+    dev_info->cu_ao_mask = adev->gfx.cu_info.ao_cu_mask;
+    dev_info->ce_ram_size = adev->gfx.ce_ram_size;
+    memcpy(&dev_info->cu_ao_bitmap[0],

&adev->gfx.cu_info.ao_cu_bitmap[0],

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +12 -0
+           sizeof(adev->gfx.cu_info.ao_cu_bitmap));
+    memcpy(&dev_info->cu_bitmap[0], &adev->gfx.cu_info.bitmap[0],
+           sizeof(dev_info->cu_bitmap));
+    dev_info->vram_type = adev->gmc.vram_type;
+    dev_info->vram_bit_width = adev->gmc.vram_width;
+    dev_info->vce_harvest_config = adev->vce.harvest_config;
+    dev_info->gc_double_offchip_lds_buf =
+        adev->gfx.config.double_offchip_lds_buf;
+    dev_info->wave_front_size = adev->gfx.cu_info.wave_front_size;
+    dev_info->num_shader_visible_vgprs = adev->gfx.config.max_gprs;
+    dev_info->num_cu_per_sh = adev->gfx.config.max_cu_per_sh;
+    dev_info->num_tcc_blocks =

adev->gfx.config.max_texture_channel_caches;

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +2 -0
+    dev_info->gs_vgt_table_depth = adev->gfx.config.gs_vgt_table_depth;
+    dev_info->gs_prim_buffer_depth =

adev->gfx.config.gs_prim_buffer_depth;

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +10 -0
+    dev_info->max_gs_waves_per_vgt = adev->gfx.config.max_gs_threads;
+
+    if (adev->family >= AMDGPU_FAMILY_NV)
+        dev_info->pa_sc_tile_steering_override =
+            adev->gfx.config.pa_sc_tile_steering_override;
+
+    dev_info->tcc_disabled_mask = adev->gfx.config.tcc_disabled_mask;
+
+    /* Combine the chip gen mask with the platform (CPU/mobo) mask. */
+    pcie_gen_mask = adev->pm.pcie_gen_mask & (adev->pm.pcie_gen_mask
Quoted 1 line
Quoted 1 line

16);

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +3 -0
+    dev_info->pcie_gen = fls(pcie_gen_mask);
+    dev_info->pcie_num_lanes =
+        adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 ?

32 :
+ adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 ?
16 :
+ adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 ?
12 :

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +3 -0
+        adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 ? 8 :
+        adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 ? 4 :
+        adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 ? 2

: 1;

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +4 -0
+
+    dev_info->tcp_cache_size = adev->gfx.config.gc_tcp_l1_size;
+    dev_info->num_sqc_per_wgp = adev->gfx.config.gc_num_sqc_per_wgp;
+    dev_info->sqc_data_cache_size =

adev->gfx.config.gc_l1_data_cache_size_per_sqc;
+ dev_info->sqc_inst_cache_size =
adev->gfx.config.gc_l1_instruction_cache_size_per_sqc;
+ dev_info->gl1c_cache_size =
adev->gfx.config.gc_gl1c_size_per_instance *

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +3 -0
+                    adev->gfx.config.gc_gl1c_per_sa;
+    dev_info->gl2c_cache_size = adev->gfx.config.gc_gl2c_per_gpu;
+    dev_info->mall_size = adev->gmc.mall_size;
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c line 142

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +6 -0
+
+
+    if (adev->gfx.funcs->get_gfx_shadow_info) {
+        struct amdgpu_gfx_shadow_info shadow_info;
+
+        ret = amdgpu_gfx_get_gfx_shadow_info(adev, &shadow_info);

This failure is ignored in the present logic and rest of the information is filled. Probably, need to continue the same way.

Since this is the information that we are sharing with user and on any failure we just decide not to populate those fields. By default all the members are initialized to zero and they

Quoted 8 lines
Quoted 4 lines

are updated when we have valid values. To me seems the right logic instead of failing the complete call, we provide the information what we have.

Actually, this is not what is really done. If you fail here, then this happens down the call. It doesn't copy, instead frees without copying to userspace.

Right. We need to retain the same functionality in the IOCTL.

Alex

Quoted 188 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +2 -0
+        ret = amdgpu_device_info(adev, dev_info);
+        if (!ret) {

Thanks,
Lijo

Quoted 181 lines

Regards
Sunil

Quoted 178 lines

Thanks,
Lijo

Quoted 174 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +9 -0
+        if (!ret) {
+            dev_info->shadow_size = shadow_info.shadow_size;
+            dev_info->shadow_alignment = shadow_info.shadow_alignment;
+            dev_info->csa_size = shadow_info.csa_size;
+            dev_info->csa_alignment = shadow_info.csa_alignment;
+        }
+    }
+    return ret;
+}
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -27
index a66d47865e3b..24f775c68a51 100644
@@ -850,125 +850,15 @@ int amdgpu_info_ioctl(struct drm_device *dev,
 void *data, struct drm_file *filp)
      }
      case AMDGPU_INFO_DEV_INFO: {
          struct drm_amdgpu_info_device *dev_info;
-        uint64_t vm_size;
-        uint32_t pcie_gen_mask;
            dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL);
          if (!dev_info)
              return -ENOMEM;
  -        dev_info->device_id = adev->pdev->device;
-        dev_info->chip_rev = adev->rev_id;
-        dev_info->external_rev = adev->external_rev_id;
-        dev_info->pci_rev = adev->pdev->revision;
-        dev_info->family = adev->family;
-        dev_info->num_shader_engines =
 adev->gfx.config.max_shader_engines;
-        dev_info->num_shader_arrays_per_engine =
 adev->gfx.config.max_sh_per_se;
-        /* return all clocks in KHz */
-        dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
-        if (adev->pm.dpm_enabled) {
-            dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev,
 false) * 10;
-            dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev,
 false) * 10;
-            dev_info->min_engine_clock = amdgpu_dpm_get_sclk(adev,
 true) * 10;
-            dev_info->min_memory_clock = amdgpu_dpm_get_mclk(adev,
 true) * 10;
-        } else {
-            dev_info->max_engine_clock =
-                dev_info->min_engine_clock =
-                    adev->clock.default_sclk * 10;
-            dev_info->max_memory_clock =
-                dev_info->min_memory_clock =
-                    adev->clock.default_mclk * 10;
-        }
-        dev_info->enabled_rb_pipes_mask =
 adev->gfx.config.backend_enable_mask;
-        dev_info->num_rb_pipes = adev->gfx.config.max_backends_per_se *
-            adev->gfx.config.max_shader_engines;
-        dev_info->num_hw_gfx_contexts =

adev->gfx.config.max_hw_contexts;

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -9
-        dev_info->ids_flags = 0;
-        if (adev->flags & AMD_IS_APU)
-            dev_info->ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
-        if (adev->gfx.mcbp)
-            dev_info->ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
-        if (amdgpu_is_tmz(adev))
-            dev_info->ids_flags |= AMDGPU_IDS_FLAGS_TMZ;
-        if (adev->gfx.config.ta_cntl2_truncate_coord_mode)
-            dev_info->ids_flags |=

AMDGPU_IDS_FLAGS_CONFORMANT_TRUNC_COORD;

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -5
-
-        vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
-        vm_size -= AMDGPU_VA_RESERVED_TOP;
-
-        /* Older VCE FW versions are buggy and can handle only

40bits */

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -13
-        if (adev->vce.fw_version &&
-            adev->vce.fw_version < AMDGPU_VCE_FW_53_45)
-            vm_size = min(vm_size, 1ULL << 40);
-
-        dev_info->virtual_address_offset = AMDGPU_VA_RESERVED_BOTTOM;
-        dev_info->virtual_address_max =
-            min(vm_size, AMDGPU_GMC_HOLE_START);
-
-        if (vm_size > AMDGPU_GMC_HOLE_START) {
-            dev_info->high_va_offset = AMDGPU_GMC_HOLE_END;
-            dev_info->high_va_max = AMDGPU_GMC_HOLE_END | vm_size;
-        }
-        dev_info->virtual_address_alignment = max_t(u32, PAGE_SIZE,

AMDGPU_GPU_PAGE_SIZE);
- dev_info->pte_fragment_size = (1 <<
adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
- dev_info->gart_page_size = max_t(u32, PAGE_SIZE,
AMDGPU_GPU_PAGE_SIZE);

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -4
-        dev_info->cu_active_number = adev->gfx.cu_info.number;
-        dev_info->cu_ao_mask = adev->gfx.cu_info.ao_cu_mask;
-        dev_info->ce_ram_size = adev->gfx.ce_ram_size;
-        memcpy(&dev_info->cu_ao_bitmap[0],

&adev->gfx.cu_info.ao_cu_bitmap[0],

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -12
-               sizeof(adev->gfx.cu_info.ao_cu_bitmap));
-        memcpy(&dev_info->cu_bitmap[0], &adev->gfx.cu_info.bitmap[0],
-               sizeof(dev_info->cu_bitmap));
-        dev_info->vram_type = adev->gmc.vram_type;
-        dev_info->vram_bit_width = adev->gmc.vram_width;
-        dev_info->vce_harvest_config = adev->vce.harvest_config;
-        dev_info->gc_double_offchip_lds_buf =
-            adev->gfx.config.double_offchip_lds_buf;
-        dev_info->wave_front_size = adev->gfx.cu_info.wave_front_size;
-        dev_info->num_shader_visible_vgprs = adev->gfx.config.max_gprs;
-        dev_info->num_cu_per_sh = adev->gfx.config.max_cu_per_sh;
-        dev_info->num_tcc_blocks =

adev->gfx.config.max_texture_channel_caches;
- dev_info->gs_vgt_table_depth =
adev->gfx.config.gs_vgt_table_depth;
- dev_info->gs_prim_buffer_depth =
adev->gfx.config.gs_prim_buffer_depth;
- dev_info->max_gs_waves_per_vgt =
adev->gfx.config.max_gs_threads;

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -6
-
-        if (adev->family >= AMDGPU_FAMILY_NV)
-            dev_info->pa_sc_tile_steering_override =
-                adev->gfx.config.pa_sc_tile_steering_override;
-
-        dev_info->tcc_disabled_mask =

adev->gfx.config.tcc_disabled_mask;

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -2
-
-        /* Combine the chip gen mask with the platform (CPU/mobo)

mask. */
- pcie_gen_mask = adev->pm.pcie_gen_mask &
(adev->pm.pcie_gen_mask >> 16);

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -3
-        dev_info->pcie_gen = fls(pcie_gen_mask);
-        dev_info->pcie_num_lanes =
-            adev->pm.pcie_mlw_mask &

CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 ? 32 :
- adev->pm.pcie_mlw_mask &
CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 ? 16 :
- adev->pm.pcie_mlw_mask &
CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 ? 12 :
- adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X8
? 8 :
- adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X4
? 4 :
- adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X2
? 2 : 1;

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -3
-
-        dev_info->tcp_cache_size = adev->gfx.config.gc_tcp_l1_size;
-        dev_info->num_sqc_per_wgp =

adev->gfx.config.gc_num_sqc_per_wgp;
- dev_info->sqc_data_cache_size =
adev->gfx.config.gc_l1_data_cache_size_per_sqc;
- dev_info->sqc_inst_cache_size =
adev->gfx.config.gc_l1_instruction_cache_size_per_sqc;
- dev_info->gl1c_cache_size =
adev->gfx.config.gc_gl1c_size_per_instance *

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -12
-                        adev->gfx.config.gc_gl1c_per_sa;
-        dev_info->gl2c_cache_size = adev->gfx.config.gc_gl2c_per_gpu;
-        dev_info->mall_size = adev->gmc.mall_size;
-
-
-        if (adev->gfx.funcs->get_gfx_shadow_info) {
-            struct amdgpu_gfx_shadow_info shadow_info;
-
-            ret = amdgpu_gfx_get_gfx_shadow_info(adev, &shadow_info);
-            if (!ret) {
-                dev_info->shadow_size = shadow_info.shadow_size;
-                dev_info->shadow_alignment =

shadow_info.shadow_alignment;

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +4 -3
-                dev_info->csa_size = shadow_info.csa_size;
-                dev_info->csa_alignment = shadow_info.csa_alignment;
-            }
+        ret = amdgpu_device_info(adev, dev_info);
+        if (!ret) {
+            kfree(dev_info);
+            return ret;
          }
            ret = copy_to_user(out, dev_info,
#7 lore raw
In reply to Sunil Khatri
Quoted 68 lines · Sunil Khatri

Refactor the code so debugfs and devcoredump can reuse the common information and avoid unnecessary copy of it.

created a new file which would be the right place to hold functions which will be used between sysfs, debugfs and devcoredump.

Cc Christian König <[email protected]>
Cc Alex Deucher <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/Makefile         |   2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu.h         |   1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c | 151 ++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c     | 118 +--------------
 4 files changed, 157 insertions(+), 115 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
drivers/gpu/drm/amd/amdgpu/Makefile +1 -1
index 4536c8ad0e11..05d34f4b18f5 100644
@@ -80,7 +80,7 @@ amdgpu-y += amdgpu_device.o amdgpu_doorbell_mgr.o amdgpu_kms.o \
        amdgpu_umc.o smu_v11_0_i2c.o amdgpu_fru_eeprom.o amdgpu_rap.o \
        amdgpu_fw_attestation.o amdgpu_securedisplay.o \
        amdgpu_eeprom.o amdgpu_mca.o amdgpu_psp_ta.o amdgpu_lsdma.o \
-       amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o
+       amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o amdgpu_devinfo.o
 
 amdgpu-$(CONFIG_PROC_FS) += amdgpu_fdinfo.o
 
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index 9c62552bec34..0267870aa9b1 100644
@@ -1609,4 +1609,5 @@ extern const struct attribute_group amdgpu_vram_mgr_attr_group;
 extern const struct attribute_group amdgpu_gtt_mgr_attr_group;
 extern const struct attribute_group amdgpu_flash_attr_group;
 
+int amdgpu_device_info(struct amdgpu_device *adev, struct drm_amdgpu_info_device *dev_info);
 #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +20 -0
new file mode 100644
index 000000000000..d2c15a1dcb0d
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2024 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c line 30

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +10 -0
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include "amdgpu.h"
+#include "amd_pcie.h"
+
+#include <drm/amdgpu_drm.h>
+
+int amdgpu_device_info(struct amdgpu_device *adev, struct drm_amdgpu_info_device *dev_info)

We can probably keep this in amdgpu_kms.c unless that file is getting too big. I don't think it warrants a new file at this point. If you do keep it in amdgpu_kms.c, I'd recommend renaming it to something like amdgpu_kms_device_info() to keep the naming conventions.

Quoted 111 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +111 -0
+{
+       int ret;
+       uint64_t vm_size;
+       uint32_t pcie_gen_mask;
+
+       if (dev_info == NULL)
+               return -EINVAL;
+
+       dev_info->device_id = adev->pdev->device;
+       dev_info->chip_rev = adev->rev_id;
+       dev_info->external_rev = adev->external_rev_id;
+       dev_info->pci_rev = adev->pdev->revision;
+       dev_info->family = adev->family;
+       dev_info->num_shader_engines = adev->gfx.config.max_shader_engines;
+       dev_info->num_shader_arrays_per_engine = adev->gfx.config.max_sh_per_se;
+       /* return all clocks in KHz */
+       dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
+       if (adev->pm.dpm_enabled) {
+               dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev, false) * 10;
+               dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev, false) * 10;
+               dev_info->min_engine_clock = amdgpu_dpm_get_sclk(adev, true) * 10;
+               dev_info->min_memory_clock = amdgpu_dpm_get_mclk(adev, true) * 10;
+       } else {
+               dev_info->max_engine_clock =
+                       dev_info->min_engine_clock =
+                               adev->clock.default_sclk * 10;
+               dev_info->max_memory_clock =
+                       dev_info->min_memory_clock =
+                               adev->clock.default_mclk * 10;
+               }
+       dev_info->enabled_rb_pipes_mask = adev->gfx.config.backend_enable_mask;
+       dev_info->num_rb_pipes = adev->gfx.config.max_backends_per_se *
+               adev->gfx.config.max_shader_engines;
+       dev_info->num_hw_gfx_contexts = adev->gfx.config.max_hw_contexts;
+       dev_info->ids_flags = 0;
+       if (adev->flags & AMD_IS_APU)
+               dev_info->ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
+       if (adev->gfx.mcbp)
+               dev_info->ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
+       if (amdgpu_is_tmz(adev))
+               dev_info->ids_flags |= AMDGPU_IDS_FLAGS_TMZ;
+       if (adev->gfx.config.ta_cntl2_truncate_coord_mode)
+               dev_info->ids_flags |= AMDGPU_IDS_FLAGS_CONFORMANT_TRUNC_COORD;
+
+       vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
+       vm_size -= AMDGPU_VA_RESERVED_TOP;
+
+       /* Older VCE FW versions are buggy and can handle only 40bits */
+       if (adev->vce.fw_version && adev->vce.fw_version < AMDGPU_VCE_FW_53_45)
+               vm_size = min(vm_size, 1ULL << 40);
+
+       dev_info->virtual_address_offset = AMDGPU_VA_RESERVED_BOTTOM;
+       dev_info->virtual_address_max = min(vm_size, AMDGPU_GMC_HOLE_START);
+
+       if (vm_size > AMDGPU_GMC_HOLE_START) {
+               dev_info->high_va_offset = AMDGPU_GMC_HOLE_END;
+               dev_info->high_va_max = AMDGPU_GMC_HOLE_END | vm_size;
+       }
+       dev_info->virtual_address_alignment = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
+       dev_info->pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
+       dev_info->gart_page_size = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
+       dev_info->cu_active_number = adev->gfx.cu_info.number;
+       dev_info->cu_ao_mask = adev->gfx.cu_info.ao_cu_mask;
+       dev_info->ce_ram_size = adev->gfx.ce_ram_size;
+       memcpy(&dev_info->cu_ao_bitmap[0], &adev->gfx.cu_info.ao_cu_bitmap[0],
+              sizeof(adev->gfx.cu_info.ao_cu_bitmap));
+       memcpy(&dev_info->cu_bitmap[0], &adev->gfx.cu_info.bitmap[0],
+              sizeof(dev_info->cu_bitmap));
+       dev_info->vram_type = adev->gmc.vram_type;
+       dev_info->vram_bit_width = adev->gmc.vram_width;
+       dev_info->vce_harvest_config = adev->vce.harvest_config;
+       dev_info->gc_double_offchip_lds_buf =
+               adev->gfx.config.double_offchip_lds_buf;
+       dev_info->wave_front_size = adev->gfx.cu_info.wave_front_size;
+       dev_info->num_shader_visible_vgprs = adev->gfx.config.max_gprs;
+       dev_info->num_cu_per_sh = adev->gfx.config.max_cu_per_sh;
+       dev_info->num_tcc_blocks = adev->gfx.config.max_texture_channel_caches;
+       dev_info->gs_vgt_table_depth = adev->gfx.config.gs_vgt_table_depth;
+       dev_info->gs_prim_buffer_depth = adev->gfx.config.gs_prim_buffer_depth;
+       dev_info->max_gs_waves_per_vgt = adev->gfx.config.max_gs_threads;
+
+       if (adev->family >= AMDGPU_FAMILY_NV)
+               dev_info->pa_sc_tile_steering_override =
+                       adev->gfx.config.pa_sc_tile_steering_override;
+
+       dev_info->tcc_disabled_mask = adev->gfx.config.tcc_disabled_mask;
+
+       /* Combine the chip gen mask with the platform (CPU/mobo) mask. */
+       pcie_gen_mask = adev->pm.pcie_gen_mask & (adev->pm.pcie_gen_mask >> 16);
+       dev_info->pcie_gen = fls(pcie_gen_mask);
+       dev_info->pcie_num_lanes =
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 ? 32 :
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 ? 16 :
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 ? 12 :
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 ? 8 :
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 ? 4 :
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 ? 2 : 1;
+
+       dev_info->tcp_cache_size = adev->gfx.config.gc_tcp_l1_size;
+       dev_info->num_sqc_per_wgp = adev->gfx.config.gc_num_sqc_per_wgp;
+       dev_info->sqc_data_cache_size = adev->gfx.config.gc_l1_data_cache_size_per_sqc;
+       dev_info->sqc_inst_cache_size = adev->gfx.config.gc_l1_instruction_cache_size_per_sqc;
+       dev_info->gl1c_cache_size = adev->gfx.config.gc_gl1c_size_per_instance *
+                                   adev->gfx.config.gc_gl1c_per_sa;
+       dev_info->gl2c_cache_size = adev->gfx.config.gc_gl2c_per_gpu;
+       dev_info->mall_size = adev->gmc.mall_size;
+
+
+       if (adev->gfx.funcs->get_gfx_shadow_info) {
+               struct amdgpu_gfx_shadow_info shadow_info;
+

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c line 151

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +10 -0
+               ret = amdgpu_gfx_get_gfx_shadow_info(adev, &shadow_info);
+               if (!ret) {
+                       dev_info->shadow_size = shadow_info.shadow_size;
+                       dev_info->shadow_alignment = shadow_info.shadow_alignment;
+                       dev_info->csa_size = shadow_info.csa_size;
+                       dev_info->csa_alignment = shadow_info.csa_alignment;
+               }
+       }
+       return ret;
+}

As noted by Lijo, this should probably be a void function since we want to populate as much information as we can and we can't break the IOCTL interface.

Alex

Quoted 137 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +4 -115
index a66d47865e3b..24f775c68a51 100644
@@ -850,125 +850,15 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
        }
        case AMDGPU_INFO_DEV_INFO: {
                struct drm_amdgpu_info_device *dev_info;
-               uint64_t vm_size;
-               uint32_t pcie_gen_mask;
 
                dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL);
                if (!dev_info)
                        return -ENOMEM;
 
-               dev_info->device_id = adev->pdev->device;
-               dev_info->chip_rev = adev->rev_id;
-               dev_info->external_rev = adev->external_rev_id;
-               dev_info->pci_rev = adev->pdev->revision;
-               dev_info->family = adev->family;
-               dev_info->num_shader_engines = adev->gfx.config.max_shader_engines;
-               dev_info->num_shader_arrays_per_engine = adev->gfx.config.max_sh_per_se;
-               /* return all clocks in KHz */
-               dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
-               if (adev->pm.dpm_enabled) {
-                       dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev, false) * 10;
-                       dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev, false) * 10;
-                       dev_info->min_engine_clock = amdgpu_dpm_get_sclk(adev, true) * 10;
-                       dev_info->min_memory_clock = amdgpu_dpm_get_mclk(adev, true) * 10;
-               } else {
-                       dev_info->max_engine_clock =
-                               dev_info->min_engine_clock =
-                                       adev->clock.default_sclk * 10;
-                       dev_info->max_memory_clock =
-                               dev_info->min_memory_clock =
-                                       adev->clock.default_mclk * 10;
-               }
-               dev_info->enabled_rb_pipes_mask = adev->gfx.config.backend_enable_mask;
-               dev_info->num_rb_pipes = adev->gfx.config.max_backends_per_se *
-                       adev->gfx.config.max_shader_engines;
-               dev_info->num_hw_gfx_contexts = adev->gfx.config.max_hw_contexts;
-               dev_info->ids_flags = 0;
-               if (adev->flags & AMD_IS_APU)
-                       dev_info->ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
-               if (adev->gfx.mcbp)
-                       dev_info->ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
-               if (amdgpu_is_tmz(adev))
-                       dev_info->ids_flags |= AMDGPU_IDS_FLAGS_TMZ;
-               if (adev->gfx.config.ta_cntl2_truncate_coord_mode)
-                       dev_info->ids_flags |= AMDGPU_IDS_FLAGS_CONFORMANT_TRUNC_COORD;
-
-               vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
-               vm_size -= AMDGPU_VA_RESERVED_TOP;
-
-               /* Older VCE FW versions are buggy and can handle only 40bits */
-               if (adev->vce.fw_version &&
-                   adev->vce.fw_version < AMDGPU_VCE_FW_53_45)
-                       vm_size = min(vm_size, 1ULL << 40);
-
-               dev_info->virtual_address_offset = AMDGPU_VA_RESERVED_BOTTOM;
-               dev_info->virtual_address_max =
-                       min(vm_size, AMDGPU_GMC_HOLE_START);
-
-               if (vm_size > AMDGPU_GMC_HOLE_START) {
-                       dev_info->high_va_offset = AMDGPU_GMC_HOLE_END;
-                       dev_info->high_va_max = AMDGPU_GMC_HOLE_END | vm_size;
-               }
-               dev_info->virtual_address_alignment = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
-               dev_info->pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
-               dev_info->gart_page_size = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
-               dev_info->cu_active_number = adev->gfx.cu_info.number;
-               dev_info->cu_ao_mask = adev->gfx.cu_info.ao_cu_mask;
-               dev_info->ce_ram_size = adev->gfx.ce_ram_size;
-               memcpy(&dev_info->cu_ao_bitmap[0], &adev->gfx.cu_info.ao_cu_bitmap[0],
-                      sizeof(adev->gfx.cu_info.ao_cu_bitmap));
-               memcpy(&dev_info->cu_bitmap[0], &adev->gfx.cu_info.bitmap[0],
-                      sizeof(dev_info->cu_bitmap));
-               dev_info->vram_type = adev->gmc.vram_type;
-               dev_info->vram_bit_width = adev->gmc.vram_width;
-               dev_info->vce_harvest_config = adev->vce.harvest_config;
-               dev_info->gc_double_offchip_lds_buf =
-                       adev->gfx.config.double_offchip_lds_buf;
-               dev_info->wave_front_size = adev->gfx.cu_info.wave_front_size;
-               dev_info->num_shader_visible_vgprs = adev->gfx.config.max_gprs;
-               dev_info->num_cu_per_sh = adev->gfx.config.max_cu_per_sh;
-               dev_info->num_tcc_blocks = adev->gfx.config.max_texture_channel_caches;
-               dev_info->gs_vgt_table_depth = adev->gfx.config.gs_vgt_table_depth;
-               dev_info->gs_prim_buffer_depth = adev->gfx.config.gs_prim_buffer_depth;
-               dev_info->max_gs_waves_per_vgt = adev->gfx.config.max_gs_threads;
-
-               if (adev->family >= AMDGPU_FAMILY_NV)
-                       dev_info->pa_sc_tile_steering_override =
-                               adev->gfx.config.pa_sc_tile_steering_override;
-
-               dev_info->tcc_disabled_mask = adev->gfx.config.tcc_disabled_mask;
-
-               /* Combine the chip gen mask with the platform (CPU/mobo) mask. */
-               pcie_gen_mask = adev->pm.pcie_gen_mask & (adev->pm.pcie_gen_mask >> 16);
-               dev_info->pcie_gen = fls(pcie_gen_mask);
-               dev_info->pcie_num_lanes =
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 ? 32 :
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 ? 16 :
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 ? 12 :
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 ? 8 :
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 ? 4 :
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 ? 2 : 1;
-
-               dev_info->tcp_cache_size = adev->gfx.config.gc_tcp_l1_size;
-               dev_info->num_sqc_per_wgp = adev->gfx.config.gc_num_sqc_per_wgp;
-               dev_info->sqc_data_cache_size = adev->gfx.config.gc_l1_data_cache_size_per_sqc;
-               dev_info->sqc_inst_cache_size = adev->gfx.config.gc_l1_instruction_cache_size_per_sqc;
-               dev_info->gl1c_cache_size = adev->gfx.config.gc_gl1c_size_per_instance *
-                                           adev->gfx.config.gc_gl1c_per_sa;
-               dev_info->gl2c_cache_size = adev->gfx.config.gc_gl2c_per_gpu;
-               dev_info->mall_size = adev->gmc.mall_size;
-
-
-               if (adev->gfx.funcs->get_gfx_shadow_info) {
-                       struct amdgpu_gfx_shadow_info shadow_info;
-
-                       ret = amdgpu_gfx_get_gfx_shadow_info(adev, &shadow_info);
-                       if (!ret) {
-                               dev_info->shadow_size = shadow_info.shadow_size;
-                               dev_info->shadow_alignment = shadow_info.shadow_alignment;
-                               dev_info->csa_size = shadow_info.csa_size;
-                               dev_info->csa_alignment = shadow_info.csa_alignment;
-                       }
+               ret = amdgpu_device_info(adev, dev_info);
+               if (!ret) {
+                       kfree(dev_info);
+                       return ret;
                }
 
                ret = copy_to_user(out, dev_info,
--

2.34.1

#8 lore raw

Am 19.03.24 um 15:26 schrieb Alex Deucher:

Quoted 74 lines · Sunil Khatri
Quoted 73 lines

Refactor the code so debugfs and devcoredump can reuse the common information and avoid unnecessary copy of it.

created a new file which would be the right place to hold functions which will be used between sysfs, debugfs and devcoredump.

Cc Christian König <[email protected]>
Cc Alex Deucher <[email protected]>
---
  drivers/gpu/drm/amd/amdgpu/Makefile         |   2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu.h         |   1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c | 151 ++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c     | 118 +--------------
  4 files changed, 157 insertions(+), 115 deletions(-)

create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c

drivers/gpu/drm/amd/amdgpu/Makefile +1 -1
index 4536c8ad0e11..05d34f4b18f5 100644
@@ -80,7 +80,7 @@ amdgpu-y += amdgpu_device.o amdgpu_doorbell_mgr.o amdgpu_kms.o \
         amdgpu_umc.o smu_v11_0_i2c.o amdgpu_fru_eeprom.o amdgpu_rap.o \
         amdgpu_fw_attestation.o amdgpu_securedisplay.o \
         amdgpu_eeprom.o amdgpu_mca.o amdgpu_psp_ta.o amdgpu_lsdma.o \
-       amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o
+       amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o amdgpu_devinfo.o
 
  amdgpu-$(CONFIG_PROC_FS) += amdgpu_fdinfo.o
 
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index 9c62552bec34..0267870aa9b1 100644
@@ -1609,4 +1609,5 @@ extern const struct attribute_group amdgpu_vram_mgr_attr_group;
  extern const struct attribute_group amdgpu_gtt_mgr_attr_group;
  extern const struct attribute_group amdgpu_flash_attr_group;
 
+int amdgpu_device_info(struct amdgpu_device *adev, struct drm_amdgpu_info_device *dev_info);
  #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +26 -0
new file mode 100644
index 000000000000..d2c15a1dcb0d
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2024 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include "amdgpu.h"
+#include "amd_pcie.h"
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c line 30

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +4 -0
+
+#include <drm/amdgpu_drm.h>
+
+int amdgpu_device_info(struct amdgpu_device *adev, struct drm_amdgpu_info_device *dev_info)

We can probably keep this in amdgpu_kms.c unless that file is getting too big. I don't think it warrants a new file at this point. If you do keep it in amdgpu_kms.c, I'd recommend renaming it to something like amdgpu_kms_device_info() to keep the naming conventions.

We should not be using this for anything new in the first place.

A whole bunch of the stuff inside the devinfo structure has been deprecated because we found that putting everything into one structure was a bad idea.

Regards,
Christian.

Quoted 265 lines
Quoted 112 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +111 -0
+{
+       int ret;
+       uint64_t vm_size;
+       uint32_t pcie_gen_mask;
+
+       if (dev_info == NULL)
+               return -EINVAL;
+
+       dev_info->device_id = adev->pdev->device;
+       dev_info->chip_rev = adev->rev_id;
+       dev_info->external_rev = adev->external_rev_id;
+       dev_info->pci_rev = adev->pdev->revision;
+       dev_info->family = adev->family;
+       dev_info->num_shader_engines = adev->gfx.config.max_shader_engines;
+       dev_info->num_shader_arrays_per_engine = adev->gfx.config.max_sh_per_se;
+       /* return all clocks in KHz */
+       dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
+       if (adev->pm.dpm_enabled) {
+               dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev, false) * 10;
+               dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev, false) * 10;
+               dev_info->min_engine_clock = amdgpu_dpm_get_sclk(adev, true) * 10;
+               dev_info->min_memory_clock = amdgpu_dpm_get_mclk(adev, true) * 10;
+       } else {
+               dev_info->max_engine_clock =
+                       dev_info->min_engine_clock =
+                               adev->clock.default_sclk * 10;
+               dev_info->max_memory_clock =
+                       dev_info->min_memory_clock =
+                               adev->clock.default_mclk * 10;
+               }
+       dev_info->enabled_rb_pipes_mask = adev->gfx.config.backend_enable_mask;
+       dev_info->num_rb_pipes = adev->gfx.config.max_backends_per_se *
+               adev->gfx.config.max_shader_engines;
+       dev_info->num_hw_gfx_contexts = adev->gfx.config.max_hw_contexts;
+       dev_info->ids_flags = 0;
+       if (adev->flags & AMD_IS_APU)
+               dev_info->ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
+       if (adev->gfx.mcbp)
+               dev_info->ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
+       if (amdgpu_is_tmz(adev))
+               dev_info->ids_flags |= AMDGPU_IDS_FLAGS_TMZ;
+       if (adev->gfx.config.ta_cntl2_truncate_coord_mode)
+               dev_info->ids_flags |= AMDGPU_IDS_FLAGS_CONFORMANT_TRUNC_COORD;
+
+       vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
+       vm_size -= AMDGPU_VA_RESERVED_TOP;
+
+       /* Older VCE FW versions are buggy and can handle only 40bits */
+       if (adev->vce.fw_version && adev->vce.fw_version < AMDGPU_VCE_FW_53_45)
+               vm_size = min(vm_size, 1ULL << 40);
+
+       dev_info->virtual_address_offset = AMDGPU_VA_RESERVED_BOTTOM;
+       dev_info->virtual_address_max = min(vm_size, AMDGPU_GMC_HOLE_START);
+
+       if (vm_size > AMDGPU_GMC_HOLE_START) {
+               dev_info->high_va_offset = AMDGPU_GMC_HOLE_END;
+               dev_info->high_va_max = AMDGPU_GMC_HOLE_END | vm_size;
+       }
+       dev_info->virtual_address_alignment = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
+       dev_info->pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
+       dev_info->gart_page_size = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
+       dev_info->cu_active_number = adev->gfx.cu_info.number;
+       dev_info->cu_ao_mask = adev->gfx.cu_info.ao_cu_mask;
+       dev_info->ce_ram_size = adev->gfx.ce_ram_size;
+       memcpy(&dev_info->cu_ao_bitmap[0], &adev->gfx.cu_info.ao_cu_bitmap[0],
+              sizeof(adev->gfx.cu_info.ao_cu_bitmap));
+       memcpy(&dev_info->cu_bitmap[0], &adev->gfx.cu_info.bitmap[0],
+              sizeof(dev_info->cu_bitmap));
+       dev_info->vram_type = adev->gmc.vram_type;
+       dev_info->vram_bit_width = adev->gmc.vram_width;
+       dev_info->vce_harvest_config = adev->vce.harvest_config;
+       dev_info->gc_double_offchip_lds_buf =
+               adev->gfx.config.double_offchip_lds_buf;
+       dev_info->wave_front_size = adev->gfx.cu_info.wave_front_size;
+       dev_info->num_shader_visible_vgprs = adev->gfx.config.max_gprs;
+       dev_info->num_cu_per_sh = adev->gfx.config.max_cu_per_sh;
+       dev_info->num_tcc_blocks = adev->gfx.config.max_texture_channel_caches;
+       dev_info->gs_vgt_table_depth = adev->gfx.config.gs_vgt_table_depth;
+       dev_info->gs_prim_buffer_depth = adev->gfx.config.gs_prim_buffer_depth;
+       dev_info->max_gs_waves_per_vgt = adev->gfx.config.max_gs_threads;
+
+       if (adev->family >= AMDGPU_FAMILY_NV)
+               dev_info->pa_sc_tile_steering_override =
+                       adev->gfx.config.pa_sc_tile_steering_override;
+
+       dev_info->tcc_disabled_mask = adev->gfx.config.tcc_disabled_mask;
+
+       /* Combine the chip gen mask with the platform (CPU/mobo) mask. */
+       pcie_gen_mask = adev->pm.pcie_gen_mask & (adev->pm.pcie_gen_mask >> 16);
+       dev_info->pcie_gen = fls(pcie_gen_mask);
+       dev_info->pcie_num_lanes =
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 ? 32 :
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 ? 16 :
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 ? 12 :
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 ? 8 :
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 ? 4 :
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 ? 2 : 1;
+
+       dev_info->tcp_cache_size = adev->gfx.config.gc_tcp_l1_size;
+       dev_info->num_sqc_per_wgp = adev->gfx.config.gc_num_sqc_per_wgp;
+       dev_info->sqc_data_cache_size = adev->gfx.config.gc_l1_data_cache_size_per_sqc;
+       dev_info->sqc_inst_cache_size = adev->gfx.config.gc_l1_instruction_cache_size_per_sqc;
+       dev_info->gl1c_cache_size = adev->gfx.config.gc_gl1c_size_per_instance *
+                                   adev->gfx.config.gc_gl1c_per_sa;
+       dev_info->gl2c_cache_size = adev->gfx.config.gc_gl2c_per_gpu;
+       dev_info->mall_size = adev->gmc.mall_size;
+
+
+       if (adev->gfx.funcs->get_gfx_shadow_info) {
+               struct amdgpu_gfx_shadow_info shadow_info;
+

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c line 151

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +10 -0
+               ret = amdgpu_gfx_get_gfx_shadow_info(adev, &shadow_info);
+               if (!ret) {
+                       dev_info->shadow_size = shadow_info.shadow_size;
+                       dev_info->shadow_alignment = shadow_info.shadow_alignment;
+                       dev_info->csa_size = shadow_info.csa_size;
+                       dev_info->csa_alignment = shadow_info.csa_alignment;
+               }
+       }
+       return ret;
+}

As noted by Lijo, this should probably be a void function since we want to populate as much information as we can and we can't break the IOCTL interface.

Alex

Quoted 137 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +4 -115
index a66d47865e3b..24f775c68a51 100644
@@ -850,125 +850,15 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
         }
         case AMDGPU_INFO_DEV_INFO: {
                 struct drm_amdgpu_info_device *dev_info;
-               uint64_t vm_size;
-               uint32_t pcie_gen_mask;
 
                 dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL);
                 if (!dev_info)
                         return -ENOMEM;
 
-               dev_info->device_id = adev->pdev->device;
-               dev_info->chip_rev = adev->rev_id;
-               dev_info->external_rev = adev->external_rev_id;
-               dev_info->pci_rev = adev->pdev->revision;
-               dev_info->family = adev->family;
-               dev_info->num_shader_engines = adev->gfx.config.max_shader_engines;
-               dev_info->num_shader_arrays_per_engine = adev->gfx.config.max_sh_per_se;
-               /* return all clocks in KHz */
-               dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
-               if (adev->pm.dpm_enabled) {
-                       dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev, false) * 10;
-                       dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev, false) * 10;
-                       dev_info->min_engine_clock = amdgpu_dpm_get_sclk(adev, true) * 10;
-                       dev_info->min_memory_clock = amdgpu_dpm_get_mclk(adev, true) * 10;
-               } else {
-                       dev_info->max_engine_clock =
-                               dev_info->min_engine_clock =
-                                       adev->clock.default_sclk * 10;
-                       dev_info->max_memory_clock =
-                               dev_info->min_memory_clock =
-                                       adev->clock.default_mclk * 10;
-               }
-               dev_info->enabled_rb_pipes_mask = adev->gfx.config.backend_enable_mask;
-               dev_info->num_rb_pipes = adev->gfx.config.max_backends_per_se *
-                       adev->gfx.config.max_shader_engines;
-               dev_info->num_hw_gfx_contexts = adev->gfx.config.max_hw_contexts;
-               dev_info->ids_flags = 0;
-               if (adev->flags & AMD_IS_APU)
-                       dev_info->ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
-               if (adev->gfx.mcbp)
-                       dev_info->ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
-               if (amdgpu_is_tmz(adev))
-                       dev_info->ids_flags |= AMDGPU_IDS_FLAGS_TMZ;
-               if (adev->gfx.config.ta_cntl2_truncate_coord_mode)
-                       dev_info->ids_flags |= AMDGPU_IDS_FLAGS_CONFORMANT_TRUNC_COORD;
-
-               vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
-               vm_size -= AMDGPU_VA_RESERVED_TOP;
-
-               /* Older VCE FW versions are buggy and can handle only 40bits */
-               if (adev->vce.fw_version &&
-                   adev->vce.fw_version < AMDGPU_VCE_FW_53_45)
-                       vm_size = min(vm_size, 1ULL << 40);
-
-               dev_info->virtual_address_offset = AMDGPU_VA_RESERVED_BOTTOM;
-               dev_info->virtual_address_max =
-                       min(vm_size, AMDGPU_GMC_HOLE_START);
-
-               if (vm_size > AMDGPU_GMC_HOLE_START) {
-                       dev_info->high_va_offset = AMDGPU_GMC_HOLE_END;
-                       dev_info->high_va_max = AMDGPU_GMC_HOLE_END | vm_size;
-               }
-               dev_info->virtual_address_alignment = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
-               dev_info->pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
-               dev_info->gart_page_size = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
-               dev_info->cu_active_number = adev->gfx.cu_info.number;
-               dev_info->cu_ao_mask = adev->gfx.cu_info.ao_cu_mask;
-               dev_info->ce_ram_size = adev->gfx.ce_ram_size;
-               memcpy(&dev_info->cu_ao_bitmap[0], &adev->gfx.cu_info.ao_cu_bitmap[0],
-                      sizeof(adev->gfx.cu_info.ao_cu_bitmap));
-               memcpy(&dev_info->cu_bitmap[0], &adev->gfx.cu_info.bitmap[0],
-                      sizeof(dev_info->cu_bitmap));
-               dev_info->vram_type = adev->gmc.vram_type;
-               dev_info->vram_bit_width = adev->gmc.vram_width;
-               dev_info->vce_harvest_config = adev->vce.harvest_config;
-               dev_info->gc_double_offchip_lds_buf =
-                       adev->gfx.config.double_offchip_lds_buf;
-               dev_info->wave_front_size = adev->gfx.cu_info.wave_front_size;
-               dev_info->num_shader_visible_vgprs = adev->gfx.config.max_gprs;
-               dev_info->num_cu_per_sh = adev->gfx.config.max_cu_per_sh;
-               dev_info->num_tcc_blocks = adev->gfx.config.max_texture_channel_caches;
-               dev_info->gs_vgt_table_depth = adev->gfx.config.gs_vgt_table_depth;
-               dev_info->gs_prim_buffer_depth = adev->gfx.config.gs_prim_buffer_depth;
-               dev_info->max_gs_waves_per_vgt = adev->gfx.config.max_gs_threads;
-
-               if (adev->family >= AMDGPU_FAMILY_NV)
-                       dev_info->pa_sc_tile_steering_override =
-                               adev->gfx.config.pa_sc_tile_steering_override;
-
-               dev_info->tcc_disabled_mask = adev->gfx.config.tcc_disabled_mask;
-
-               /* Combine the chip gen mask with the platform (CPU/mobo) mask. */
-               pcie_gen_mask = adev->pm.pcie_gen_mask & (adev->pm.pcie_gen_mask >> 16);
-               dev_info->pcie_gen = fls(pcie_gen_mask);
-               dev_info->pcie_num_lanes =
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 ? 32 :
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 ? 16 :
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 ? 12 :
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 ? 8 :
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 ? 4 :
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 ? 2 : 1;
-
-               dev_info->tcp_cache_size = adev->gfx.config.gc_tcp_l1_size;
-               dev_info->num_sqc_per_wgp = adev->gfx.config.gc_num_sqc_per_wgp;
-               dev_info->sqc_data_cache_size = adev->gfx.config.gc_l1_data_cache_size_per_sqc;
-               dev_info->sqc_inst_cache_size = adev->gfx.config.gc_l1_instruction_cache_size_per_sqc;
-               dev_info->gl1c_cache_size = adev->gfx.config.gc_gl1c_size_per_instance *
-                                           adev->gfx.config.gc_gl1c_per_sa;
-               dev_info->gl2c_cache_size = adev->gfx.config.gc_gl2c_per_gpu;
-               dev_info->mall_size = adev->gmc.mall_size;
-
-
-               if (adev->gfx.funcs->get_gfx_shadow_info) {
-                       struct amdgpu_gfx_shadow_info shadow_info;
-
-                       ret = amdgpu_gfx_get_gfx_shadow_info(adev, &shadow_info);
-                       if (!ret) {
-                               dev_info->shadow_size = shadow_info.shadow_size;
-                               dev_info->shadow_alignment = shadow_info.shadow_alignment;
-                               dev_info->csa_size = shadow_info.csa_size;
-                               dev_info->csa_alignment = shadow_info.csa_alignment;
-                       }
+               ret = amdgpu_device_info(adev, dev_info);
+               if (!ret) {
+                       kfree(dev_info);
+                       return ret;
                 }
 
                 ret = copy_to_user(out, dev_info,
--

2.34.1

#9 lore raw
Quoted 85 lines · Christian König

Am 19.03.24 um 15:26 schrieb Alex Deucher:

Quoted 74 lines · Sunil Khatri
Quoted 73 lines

Refactor the code so debugfs and devcoredump can reuse the common information and avoid unnecessary copy of it.

created a new file which would be the right place to hold functions which will be used between sysfs, debugfs and devcoredump.

Cc Christian König <[email protected]>
Cc Alex Deucher <[email protected]>
---
  drivers/gpu/drm/amd/amdgpu/Makefile         |   2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu.h         |   1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c | 151 ++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c     | 118 +--------------
  4 files changed, 157 insertions(+), 115 deletions(-)

create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c

drivers/gpu/drm/amd/amdgpu/Makefile +1 -1
index 4536c8ad0e11..05d34f4b18f5 100644
@@ -80,7 +80,7 @@ amdgpu-y += amdgpu_device.o amdgpu_doorbell_mgr.o amdgpu_kms.o \
         amdgpu_umc.o smu_v11_0_i2c.o amdgpu_fru_eeprom.o amdgpu_rap.o \
         amdgpu_fw_attestation.o amdgpu_securedisplay.o \
         amdgpu_eeprom.o amdgpu_mca.o amdgpu_psp_ta.o amdgpu_lsdma.o \
-       amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o
+       amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o amdgpu_devinfo.o
 
  amdgpu-$(CONFIG_PROC_FS) += amdgpu_fdinfo.o
 
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index 9c62552bec34..0267870aa9b1 100644
@@ -1609,4 +1609,5 @@ extern const struct attribute_group amdgpu_vram_mgr_attr_group;
  extern const struct attribute_group amdgpu_gtt_mgr_attr_group;
  extern const struct attribute_group amdgpu_flash_attr_group;
 
+int amdgpu_device_info(struct amdgpu_device *adev, struct drm_amdgpu_info_device *dev_info);
  #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +26 -0
new file mode 100644
index 000000000000..d2c15a1dcb0d
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2024 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include "amdgpu.h"
+#include "amd_pcie.h"
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c line 30

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +4 -0
+
+#include <drm/amdgpu_drm.h>
+
+int amdgpu_device_info(struct amdgpu_device *adev, struct drm_amdgpu_info_device *dev_info)

We can probably keep this in amdgpu_kms.c unless that file is getting too big. I don't think it warrants a new file at this point. If you do keep it in amdgpu_kms.c, I'd recommend renaming it to something like amdgpu_kms_device_info() to keep the naming conventions.

Quoted 5 lines

We should not be using this for anything new in the first place.

A whole bunch of the stuff inside the devinfo structure has been deprecated because we found that putting everything into one structure was a bad idea.

It's a convenient way to collect a lot of useful information that we want in the core dump. Plus it's not going anywhere because we need to keep compatibility in the IOCTL.

Alex

Quoted 270 lines

Regards,
Christian.

Quoted 265 lines
Quoted 112 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +111 -0
+{
+       int ret;
+       uint64_t vm_size;
+       uint32_t pcie_gen_mask;
+
+       if (dev_info == NULL)
+               return -EINVAL;
+
+       dev_info->device_id = adev->pdev->device;
+       dev_info->chip_rev = adev->rev_id;
+       dev_info->external_rev = adev->external_rev_id;
+       dev_info->pci_rev = adev->pdev->revision;
+       dev_info->family = adev->family;
+       dev_info->num_shader_engines = adev->gfx.config.max_shader_engines;
+       dev_info->num_shader_arrays_per_engine = adev->gfx.config.max_sh_per_se;
+       /* return all clocks in KHz */
+       dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
+       if (adev->pm.dpm_enabled) {
+               dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev, false) * 10;
+               dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev, false) * 10;
+               dev_info->min_engine_clock = amdgpu_dpm_get_sclk(adev, true) * 10;
+               dev_info->min_memory_clock = amdgpu_dpm_get_mclk(adev, true) * 10;
+       } else {
+               dev_info->max_engine_clock =
+                       dev_info->min_engine_clock =
+                               adev->clock.default_sclk * 10;
+               dev_info->max_memory_clock =
+                       dev_info->min_memory_clock =
+                               adev->clock.default_mclk * 10;
+               }
+       dev_info->enabled_rb_pipes_mask = adev->gfx.config.backend_enable_mask;
+       dev_info->num_rb_pipes = adev->gfx.config.max_backends_per_se *
+               adev->gfx.config.max_shader_engines;
+       dev_info->num_hw_gfx_contexts = adev->gfx.config.max_hw_contexts;
+       dev_info->ids_flags = 0;
+       if (adev->flags & AMD_IS_APU)
+               dev_info->ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
+       if (adev->gfx.mcbp)
+               dev_info->ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
+       if (amdgpu_is_tmz(adev))
+               dev_info->ids_flags |= AMDGPU_IDS_FLAGS_TMZ;
+       if (adev->gfx.config.ta_cntl2_truncate_coord_mode)
+               dev_info->ids_flags |= AMDGPU_IDS_FLAGS_CONFORMANT_TRUNC_COORD;
+
+       vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
+       vm_size -= AMDGPU_VA_RESERVED_TOP;
+
+       /* Older VCE FW versions are buggy and can handle only 40bits */
+       if (adev->vce.fw_version && adev->vce.fw_version < AMDGPU_VCE_FW_53_45)
+               vm_size = min(vm_size, 1ULL << 40);
+
+       dev_info->virtual_address_offset = AMDGPU_VA_RESERVED_BOTTOM;
+       dev_info->virtual_address_max = min(vm_size, AMDGPU_GMC_HOLE_START);
+
+       if (vm_size > AMDGPU_GMC_HOLE_START) {
+               dev_info->high_va_offset = AMDGPU_GMC_HOLE_END;
+               dev_info->high_va_max = AMDGPU_GMC_HOLE_END | vm_size;
+       }
+       dev_info->virtual_address_alignment = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
+       dev_info->pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
+       dev_info->gart_page_size = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
+       dev_info->cu_active_number = adev->gfx.cu_info.number;
+       dev_info->cu_ao_mask = adev->gfx.cu_info.ao_cu_mask;
+       dev_info->ce_ram_size = adev->gfx.ce_ram_size;
+       memcpy(&dev_info->cu_ao_bitmap[0], &adev->gfx.cu_info.ao_cu_bitmap[0],
+              sizeof(adev->gfx.cu_info.ao_cu_bitmap));
+       memcpy(&dev_info->cu_bitmap[0], &adev->gfx.cu_info.bitmap[0],
+              sizeof(dev_info->cu_bitmap));
+       dev_info->vram_type = adev->gmc.vram_type;
+       dev_info->vram_bit_width = adev->gmc.vram_width;
+       dev_info->vce_harvest_config = adev->vce.harvest_config;
+       dev_info->gc_double_offchip_lds_buf =
+               adev->gfx.config.double_offchip_lds_buf;
+       dev_info->wave_front_size = adev->gfx.cu_info.wave_front_size;
+       dev_info->num_shader_visible_vgprs = adev->gfx.config.max_gprs;
+       dev_info->num_cu_per_sh = adev->gfx.config.max_cu_per_sh;
+       dev_info->num_tcc_blocks = adev->gfx.config.max_texture_channel_caches;
+       dev_info->gs_vgt_table_depth = adev->gfx.config.gs_vgt_table_depth;
+       dev_info->gs_prim_buffer_depth = adev->gfx.config.gs_prim_buffer_depth;
+       dev_info->max_gs_waves_per_vgt = adev->gfx.config.max_gs_threads;
+
+       if (adev->family >= AMDGPU_FAMILY_NV)
+               dev_info->pa_sc_tile_steering_override =
+                       adev->gfx.config.pa_sc_tile_steering_override;
+
+       dev_info->tcc_disabled_mask = adev->gfx.config.tcc_disabled_mask;
+
+       /* Combine the chip gen mask with the platform (CPU/mobo) mask. */
+       pcie_gen_mask = adev->pm.pcie_gen_mask & (adev->pm.pcie_gen_mask >> 16);
+       dev_info->pcie_gen = fls(pcie_gen_mask);
+       dev_info->pcie_num_lanes =
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 ? 32 :
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 ? 16 :
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 ? 12 :
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 ? 8 :
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 ? 4 :
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 ? 2 : 1;
+
+       dev_info->tcp_cache_size = adev->gfx.config.gc_tcp_l1_size;
+       dev_info->num_sqc_per_wgp = adev->gfx.config.gc_num_sqc_per_wgp;
+       dev_info->sqc_data_cache_size = adev->gfx.config.gc_l1_data_cache_size_per_sqc;
+       dev_info->sqc_inst_cache_size = adev->gfx.config.gc_l1_instruction_cache_size_per_sqc;
+       dev_info->gl1c_cache_size = adev->gfx.config.gc_gl1c_size_per_instance *
+                                   adev->gfx.config.gc_gl1c_per_sa;
+       dev_info->gl2c_cache_size = adev->gfx.config.gc_gl2c_per_gpu;
+       dev_info->mall_size = adev->gmc.mall_size;
+
+
+       if (adev->gfx.funcs->get_gfx_shadow_info) {
+               struct amdgpu_gfx_shadow_info shadow_info;
+

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c line 151

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +10 -0
+               ret = amdgpu_gfx_get_gfx_shadow_info(adev, &shadow_info);
+               if (!ret) {
+                       dev_info->shadow_size = shadow_info.shadow_size;
+                       dev_info->shadow_alignment = shadow_info.shadow_alignment;
+                       dev_info->csa_size = shadow_info.csa_size;
+                       dev_info->csa_alignment = shadow_info.csa_alignment;
+               }
+       }
+       return ret;
+}

As noted by Lijo, this should probably be a void function since we want to populate as much information as we can and we can't break the IOCTL interface.

Alex

Quoted 137 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +4 -115
index a66d47865e3b..24f775c68a51 100644
@@ -850,125 +850,15 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
         }
         case AMDGPU_INFO_DEV_INFO: {
                 struct drm_amdgpu_info_device *dev_info;
-               uint64_t vm_size;
-               uint32_t pcie_gen_mask;
 
                 dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL);
                 if (!dev_info)
                         return -ENOMEM;
 
-               dev_info->device_id = adev->pdev->device;
-               dev_info->chip_rev = adev->rev_id;
-               dev_info->external_rev = adev->external_rev_id;
-               dev_info->pci_rev = adev->pdev->revision;
-               dev_info->family = adev->family;
-               dev_info->num_shader_engines = adev->gfx.config.max_shader_engines;
-               dev_info->num_shader_arrays_per_engine = adev->gfx.config.max_sh_per_se;
-               /* return all clocks in KHz */
-               dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
-               if (adev->pm.dpm_enabled) {
-                       dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev, false) * 10;
-                       dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev, false) * 10;
-                       dev_info->min_engine_clock = amdgpu_dpm_get_sclk(adev, true) * 10;
-                       dev_info->min_memory_clock = amdgpu_dpm_get_mclk(adev, true) * 10;
-               } else {
-                       dev_info->max_engine_clock =
-                               dev_info->min_engine_clock =
-                                       adev->clock.default_sclk * 10;
-                       dev_info->max_memory_clock =
-                               dev_info->min_memory_clock =
-                                       adev->clock.default_mclk * 10;
-               }
-               dev_info->enabled_rb_pipes_mask = adev->gfx.config.backend_enable_mask;
-               dev_info->num_rb_pipes = adev->gfx.config.max_backends_per_se *
-                       adev->gfx.config.max_shader_engines;
-               dev_info->num_hw_gfx_contexts = adev->gfx.config.max_hw_contexts;
-               dev_info->ids_flags = 0;
-               if (adev->flags & AMD_IS_APU)
-                       dev_info->ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
-               if (adev->gfx.mcbp)
-                       dev_info->ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
-               if (amdgpu_is_tmz(adev))
-                       dev_info->ids_flags |= AMDGPU_IDS_FLAGS_TMZ;
-               if (adev->gfx.config.ta_cntl2_truncate_coord_mode)
-                       dev_info->ids_flags |= AMDGPU_IDS_FLAGS_CONFORMANT_TRUNC_COORD;
-
-               vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
-               vm_size -= AMDGPU_VA_RESERVED_TOP;
-
-               /* Older VCE FW versions are buggy and can handle only 40bits */
-               if (adev->vce.fw_version &&
-                   adev->vce.fw_version < AMDGPU_VCE_FW_53_45)
-                       vm_size = min(vm_size, 1ULL << 40);
-
-               dev_info->virtual_address_offset = AMDGPU_VA_RESERVED_BOTTOM;
-               dev_info->virtual_address_max =
-                       min(vm_size, AMDGPU_GMC_HOLE_START);
-
-               if (vm_size > AMDGPU_GMC_HOLE_START) {
-                       dev_info->high_va_offset = AMDGPU_GMC_HOLE_END;
-                       dev_info->high_va_max = AMDGPU_GMC_HOLE_END | vm_size;
-               }
-               dev_info->virtual_address_alignment = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
-               dev_info->pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
-               dev_info->gart_page_size = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
-               dev_info->cu_active_number = adev->gfx.cu_info.number;
-               dev_info->cu_ao_mask = adev->gfx.cu_info.ao_cu_mask;
-               dev_info->ce_ram_size = adev->gfx.ce_ram_size;
-               memcpy(&dev_info->cu_ao_bitmap[0], &adev->gfx.cu_info.ao_cu_bitmap[0],
-                      sizeof(adev->gfx.cu_info.ao_cu_bitmap));
-               memcpy(&dev_info->cu_bitmap[0], &adev->gfx.cu_info.bitmap[0],
-                      sizeof(dev_info->cu_bitmap));
-               dev_info->vram_type = adev->gmc.vram_type;
-               dev_info->vram_bit_width = adev->gmc.vram_width;
-               dev_info->vce_harvest_config = adev->vce.harvest_config;
-               dev_info->gc_double_offchip_lds_buf =
-                       adev->gfx.config.double_offchip_lds_buf;
-               dev_info->wave_front_size = adev->gfx.cu_info.wave_front_size;
-               dev_info->num_shader_visible_vgprs = adev->gfx.config.max_gprs;
-               dev_info->num_cu_per_sh = adev->gfx.config.max_cu_per_sh;
-               dev_info->num_tcc_blocks = adev->gfx.config.max_texture_channel_caches;
-               dev_info->gs_vgt_table_depth = adev->gfx.config.gs_vgt_table_depth;
-               dev_info->gs_prim_buffer_depth = adev->gfx.config.gs_prim_buffer_depth;
-               dev_info->max_gs_waves_per_vgt = adev->gfx.config.max_gs_threads;
-
-               if (adev->family >= AMDGPU_FAMILY_NV)
-                       dev_info->pa_sc_tile_steering_override =
-                               adev->gfx.config.pa_sc_tile_steering_override;
-
-               dev_info->tcc_disabled_mask = adev->gfx.config.tcc_disabled_mask;
-
-               /* Combine the chip gen mask with the platform (CPU/mobo) mask. */
-               pcie_gen_mask = adev->pm.pcie_gen_mask & (adev->pm.pcie_gen_mask >> 16);
-               dev_info->pcie_gen = fls(pcie_gen_mask);
-               dev_info->pcie_num_lanes =
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 ? 32 :
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 ? 16 :
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 ? 12 :
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 ? 8 :
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 ? 4 :
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 ? 2 : 1;
-
-               dev_info->tcp_cache_size = adev->gfx.config.gc_tcp_l1_size;
-               dev_info->num_sqc_per_wgp = adev->gfx.config.gc_num_sqc_per_wgp;
-               dev_info->sqc_data_cache_size = adev->gfx.config.gc_l1_data_cache_size_per_sqc;
-               dev_info->sqc_inst_cache_size = adev->gfx.config.gc_l1_instruction_cache_size_per_sqc;
-               dev_info->gl1c_cache_size = adev->gfx.config.gc_gl1c_size_per_instance *
-                                           adev->gfx.config.gc_gl1c_per_sa;
-               dev_info->gl2c_cache_size = adev->gfx.config.gc_gl2c_per_gpu;
-               dev_info->mall_size = adev->gmc.mall_size;
-
-
-               if (adev->gfx.funcs->get_gfx_shadow_info) {
-                       struct amdgpu_gfx_shadow_info shadow_info;
-
-                       ret = amdgpu_gfx_get_gfx_shadow_info(adev, &shadow_info);
-                       if (!ret) {
-                               dev_info->shadow_size = shadow_info.shadow_size;
-                               dev_info->shadow_alignment = shadow_info.shadow_alignment;
-                               dev_info->csa_size = shadow_info.csa_size;
-                               dev_info->csa_alignment = shadow_info.csa_alignment;
-                       }
+               ret = amdgpu_device_info(adev, dev_info);
+               if (!ret) {
+                       kfree(dev_info);
+                       return ret;
                 }
 
                 ret = copy_to_user(out, dev_info,
--

2.34.1

#10 lore raw

Am 19.03.24 um 15:59 schrieb Alex Deucher:

Quoted 85 lines
Quoted 83 lines · Christian König

Am 19.03.24 um 15:26 schrieb Alex Deucher:

Quoted 82 lines · Sunil Khatri
Quoted 67 lines

Refactor the code so debugfs and devcoredump can reuse the common information and avoid unnecessary copy of it.

created a new file which would be the right place to hold functions which will be used between sysfs, debugfs and devcoredump.

Cc Christian König <[email protected]>
Cc Alex Deucher <[email protected]>
---
   drivers/gpu/drm/amd/amdgpu/Makefile         |   2 +-
   drivers/gpu/drm/amd/amdgpu/amdgpu.h         |   1 +
   drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c | 151 ++++++++++++++++++++
   drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c     | 118 +--------------
   4 files changed, 157 insertions(+), 115 deletions(-)

create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c

drivers/gpu/drm/amd/amdgpu/Makefile +1 -1
index 4536c8ad0e11..05d34f4b18f5 100644
@@ -80,7 +80,7 @@ amdgpu-y += amdgpu_device.o amdgpu_doorbell_mgr.o amdgpu_kms.o \
          amdgpu_umc.o smu_v11_0_i2c.o amdgpu_fru_eeprom.o amdgpu_rap.o \
          amdgpu_fw_attestation.o amdgpu_securedisplay.o \
          amdgpu_eeprom.o amdgpu_mca.o amdgpu_psp_ta.o amdgpu_lsdma.o \
-       amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o
+       amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o amdgpu_devinfo.o
 
   amdgpu-$(CONFIG_PROC_FS) += amdgpu_fdinfo.o
 
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index 9c62552bec34..0267870aa9b1 100644
@@ -1609,4 +1609,5 @@ extern const struct attribute_group amdgpu_vram_mgr_attr_group;
   extern const struct attribute_group amdgpu_gtt_mgr_attr_group;
   extern const struct attribute_group amdgpu_flash_attr_group;
 
+int amdgpu_device_info(struct amdgpu_device *adev, struct drm_amdgpu_info_device *dev_info);
   #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +20 -0
new file mode 100644
index 000000000000..d2c15a1dcb0d
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2024 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c line 30

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +10 -0
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include "amdgpu.h"
+#include "amd_pcie.h"
+
+#include <drm/amdgpu_drm.h>
+
+int amdgpu_device_info(struct amdgpu_device *adev, struct drm_amdgpu_info_device *dev_info)

We can probably keep this in amdgpu_kms.c unless that file is getting too big. I don't think it warrants a new file at this point. If you do keep it in amdgpu_kms.c, I'd recommend renaming it to something like amdgpu_kms_device_info() to keep the naming conventions.

Quoted 8 lines
Quoted 5 lines

We should not be using this for anything new in the first place.

A whole bunch of the stuff inside the devinfo structure has been deprecated because we found that putting everything into one structure was a bad idea.

It's a convenient way to collect a lot of useful information that we want in the core dump. Plus it's not going anywhere because we need to keep compatibility in the IOCTL.

Yeah and exactly that is what I'm strictly against. The devinfo wasn't used for new stuff because we found that it is way to inflexible.

That's why we have multiple separate IOCTLs for the memory and firmware information for example.

We should really *not* reuse that for the device core dumping.

Rather just use the same information from the different IPs and subsystems directly. E.g. add a function to the VM, GFX etc for printing out devcoredump infos.

Christian.

Quoted 270 lines

Alex

Quoted 267 lines

Regards,
Christian.

Quoted 264 lines
Quoted 111 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +111 -0
+{
+       int ret;
+       uint64_t vm_size;
+       uint32_t pcie_gen_mask;
+
+       if (dev_info == NULL)
+               return -EINVAL;
+
+       dev_info->device_id = adev->pdev->device;
+       dev_info->chip_rev = adev->rev_id;
+       dev_info->external_rev = adev->external_rev_id;
+       dev_info->pci_rev = adev->pdev->revision;
+       dev_info->family = adev->family;
+       dev_info->num_shader_engines = adev->gfx.config.max_shader_engines;
+       dev_info->num_shader_arrays_per_engine = adev->gfx.config.max_sh_per_se;
+       /* return all clocks in KHz */
+       dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
+       if (adev->pm.dpm_enabled) {
+               dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev, false) * 10;
+               dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev, false) * 10;
+               dev_info->min_engine_clock = amdgpu_dpm_get_sclk(adev, true) * 10;
+               dev_info->min_memory_clock = amdgpu_dpm_get_mclk(adev, true) * 10;
+       } else {
+               dev_info->max_engine_clock =
+                       dev_info->min_engine_clock =
+                               adev->clock.default_sclk * 10;
+               dev_info->max_memory_clock =
+                       dev_info->min_memory_clock =
+                               adev->clock.default_mclk * 10;
+               }
+       dev_info->enabled_rb_pipes_mask = adev->gfx.config.backend_enable_mask;
+       dev_info->num_rb_pipes = adev->gfx.config.max_backends_per_se *
+               adev->gfx.config.max_shader_engines;
+       dev_info->num_hw_gfx_contexts = adev->gfx.config.max_hw_contexts;
+       dev_info->ids_flags = 0;
+       if (adev->flags & AMD_IS_APU)
+               dev_info->ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
+       if (adev->gfx.mcbp)
+               dev_info->ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
+       if (amdgpu_is_tmz(adev))
+               dev_info->ids_flags |= AMDGPU_IDS_FLAGS_TMZ;
+       if (adev->gfx.config.ta_cntl2_truncate_coord_mode)
+               dev_info->ids_flags |= AMDGPU_IDS_FLAGS_CONFORMANT_TRUNC_COORD;
+
+       vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
+       vm_size -= AMDGPU_VA_RESERVED_TOP;
+
+       /* Older VCE FW versions are buggy and can handle only 40bits */
+       if (adev->vce.fw_version && adev->vce.fw_version < AMDGPU_VCE_FW_53_45)
+               vm_size = min(vm_size, 1ULL << 40);
+
+       dev_info->virtual_address_offset = AMDGPU_VA_RESERVED_BOTTOM;
+       dev_info->virtual_address_max = min(vm_size, AMDGPU_GMC_HOLE_START);
+
+       if (vm_size > AMDGPU_GMC_HOLE_START) {
+               dev_info->high_va_offset = AMDGPU_GMC_HOLE_END;
+               dev_info->high_va_max = AMDGPU_GMC_HOLE_END | vm_size;
+       }
+       dev_info->virtual_address_alignment = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
+       dev_info->pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
+       dev_info->gart_page_size = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
+       dev_info->cu_active_number = adev->gfx.cu_info.number;
+       dev_info->cu_ao_mask = adev->gfx.cu_info.ao_cu_mask;
+       dev_info->ce_ram_size = adev->gfx.ce_ram_size;
+       memcpy(&dev_info->cu_ao_bitmap[0], &adev->gfx.cu_info.ao_cu_bitmap[0],
+              sizeof(adev->gfx.cu_info.ao_cu_bitmap));
+       memcpy(&dev_info->cu_bitmap[0], &adev->gfx.cu_info.bitmap[0],
+              sizeof(dev_info->cu_bitmap));
+       dev_info->vram_type = adev->gmc.vram_type;
+       dev_info->vram_bit_width = adev->gmc.vram_width;
+       dev_info->vce_harvest_config = adev->vce.harvest_config;
+       dev_info->gc_double_offchip_lds_buf =
+               adev->gfx.config.double_offchip_lds_buf;
+       dev_info->wave_front_size = adev->gfx.cu_info.wave_front_size;
+       dev_info->num_shader_visible_vgprs = adev->gfx.config.max_gprs;
+       dev_info->num_cu_per_sh = adev->gfx.config.max_cu_per_sh;
+       dev_info->num_tcc_blocks = adev->gfx.config.max_texture_channel_caches;
+       dev_info->gs_vgt_table_depth = adev->gfx.config.gs_vgt_table_depth;
+       dev_info->gs_prim_buffer_depth = adev->gfx.config.gs_prim_buffer_depth;
+       dev_info->max_gs_waves_per_vgt = adev->gfx.config.max_gs_threads;
+
+       if (adev->family >= AMDGPU_FAMILY_NV)
+               dev_info->pa_sc_tile_steering_override =
+                       adev->gfx.config.pa_sc_tile_steering_override;
+
+       dev_info->tcc_disabled_mask = adev->gfx.config.tcc_disabled_mask;
+
+       /* Combine the chip gen mask with the platform (CPU/mobo) mask. */
+       pcie_gen_mask = adev->pm.pcie_gen_mask & (adev->pm.pcie_gen_mask >> 16);
+       dev_info->pcie_gen = fls(pcie_gen_mask);
+       dev_info->pcie_num_lanes =
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 ? 32 :
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 ? 16 :
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 ? 12 :
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 ? 8 :
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 ? 4 :
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 ? 2 : 1;
+
+       dev_info->tcp_cache_size = adev->gfx.config.gc_tcp_l1_size;
+       dev_info->num_sqc_per_wgp = adev->gfx.config.gc_num_sqc_per_wgp;
+       dev_info->sqc_data_cache_size = adev->gfx.config.gc_l1_data_cache_size_per_sqc;
+       dev_info->sqc_inst_cache_size = adev->gfx.config.gc_l1_instruction_cache_size_per_sqc;
+       dev_info->gl1c_cache_size = adev->gfx.config.gc_gl1c_size_per_instance *
+                                   adev->gfx.config.gc_gl1c_per_sa;
+       dev_info->gl2c_cache_size = adev->gfx.config.gc_gl2c_per_gpu;
+       dev_info->mall_size = adev->gmc.mall_size;
+
+
+       if (adev->gfx.funcs->get_gfx_shadow_info) {
+               struct amdgpu_gfx_shadow_info shadow_info;
+

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c line 151

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +10 -0
+               ret = amdgpu_gfx_get_gfx_shadow_info(adev, &shadow_info);
+               if (!ret) {
+                       dev_info->shadow_size = shadow_info.shadow_size;
+                       dev_info->shadow_alignment = shadow_info.shadow_alignment;
+                       dev_info->csa_size = shadow_info.csa_size;
+                       dev_info->csa_alignment = shadow_info.csa_alignment;
+               }
+       }
+       return ret;
+}

As noted by Lijo, this should probably be a void function since we want to populate as much information as we can and we can't break the IOCTL interface.

Alex

Quoted 137 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +4 -115
index a66d47865e3b..24f775c68a51 100644
@@ -850,125 +850,15 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
          }
          case AMDGPU_INFO_DEV_INFO: {
                  struct drm_amdgpu_info_device *dev_info;
-               uint64_t vm_size;
-               uint32_t pcie_gen_mask;
 
                  dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL);
                  if (!dev_info)
                          return -ENOMEM;
 
-               dev_info->device_id = adev->pdev->device;
-               dev_info->chip_rev = adev->rev_id;
-               dev_info->external_rev = adev->external_rev_id;
-               dev_info->pci_rev = adev->pdev->revision;
-               dev_info->family = adev->family;
-               dev_info->num_shader_engines = adev->gfx.config.max_shader_engines;
-               dev_info->num_shader_arrays_per_engine = adev->gfx.config.max_sh_per_se;
-               /* return all clocks in KHz */
-               dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
-               if (adev->pm.dpm_enabled) {
-                       dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev, false) * 10;
-                       dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev, false) * 10;
-                       dev_info->min_engine_clock = amdgpu_dpm_get_sclk(adev, true) * 10;
-                       dev_info->min_memory_clock = amdgpu_dpm_get_mclk(adev, true) * 10;
-               } else {
-                       dev_info->max_engine_clock =
-                               dev_info->min_engine_clock =
-                                       adev->clock.default_sclk * 10;
-                       dev_info->max_memory_clock =
-                               dev_info->min_memory_clock =
-                                       adev->clock.default_mclk * 10;
-               }
-               dev_info->enabled_rb_pipes_mask = adev->gfx.config.backend_enable_mask;
-               dev_info->num_rb_pipes = adev->gfx.config.max_backends_per_se *
-                       adev->gfx.config.max_shader_engines;
-               dev_info->num_hw_gfx_contexts = adev->gfx.config.max_hw_contexts;
-               dev_info->ids_flags = 0;
-               if (adev->flags & AMD_IS_APU)
-                       dev_info->ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
-               if (adev->gfx.mcbp)
-                       dev_info->ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
-               if (amdgpu_is_tmz(adev))
-                       dev_info->ids_flags |= AMDGPU_IDS_FLAGS_TMZ;
-               if (adev->gfx.config.ta_cntl2_truncate_coord_mode)
-                       dev_info->ids_flags |= AMDGPU_IDS_FLAGS_CONFORMANT_TRUNC_COORD;
-
-               vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
-               vm_size -= AMDGPU_VA_RESERVED_TOP;
-
-               /* Older VCE FW versions are buggy and can handle only 40bits */
-               if (adev->vce.fw_version &&
-                   adev->vce.fw_version < AMDGPU_VCE_FW_53_45)
-                       vm_size = min(vm_size, 1ULL << 40);
-
-               dev_info->virtual_address_offset = AMDGPU_VA_RESERVED_BOTTOM;
-               dev_info->virtual_address_max =
-                       min(vm_size, AMDGPU_GMC_HOLE_START);
-
-               if (vm_size > AMDGPU_GMC_HOLE_START) {
-                       dev_info->high_va_offset = AMDGPU_GMC_HOLE_END;
-                       dev_info->high_va_max = AMDGPU_GMC_HOLE_END | vm_size;
-               }
-               dev_info->virtual_address_alignment = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
-               dev_info->pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
-               dev_info->gart_page_size = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
-               dev_info->cu_active_number = adev->gfx.cu_info.number;
-               dev_info->cu_ao_mask = adev->gfx.cu_info.ao_cu_mask;
-               dev_info->ce_ram_size = adev->gfx.ce_ram_size;
-               memcpy(&dev_info->cu_ao_bitmap[0], &adev->gfx.cu_info.ao_cu_bitmap[0],
-                      sizeof(adev->gfx.cu_info.ao_cu_bitmap));
-               memcpy(&dev_info->cu_bitmap[0], &adev->gfx.cu_info.bitmap[0],
-                      sizeof(dev_info->cu_bitmap));
-               dev_info->vram_type = adev->gmc.vram_type;
-               dev_info->vram_bit_width = adev->gmc.vram_width;
-               dev_info->vce_harvest_config = adev->vce.harvest_config;
-               dev_info->gc_double_offchip_lds_buf =
-                       adev->gfx.config.double_offchip_lds_buf;
-               dev_info->wave_front_size = adev->gfx.cu_info.wave_front_size;
-               dev_info->num_shader_visible_vgprs = adev->gfx.config.max_gprs;
-               dev_info->num_cu_per_sh = adev->gfx.config.max_cu_per_sh;
-               dev_info->num_tcc_blocks = adev->gfx.config.max_texture_channel_caches;
-               dev_info->gs_vgt_table_depth = adev->gfx.config.gs_vgt_table_depth;
-               dev_info->gs_prim_buffer_depth = adev->gfx.config.gs_prim_buffer_depth;
-               dev_info->max_gs_waves_per_vgt = adev->gfx.config.max_gs_threads;
-
-               if (adev->family >= AMDGPU_FAMILY_NV)
-                       dev_info->pa_sc_tile_steering_override =
-                               adev->gfx.config.pa_sc_tile_steering_override;
-
-               dev_info->tcc_disabled_mask = adev->gfx.config.tcc_disabled_mask;
-
-               /* Combine the chip gen mask with the platform (CPU/mobo) mask. */
-               pcie_gen_mask = adev->pm.pcie_gen_mask & (adev->pm.pcie_gen_mask >> 16);
-               dev_info->pcie_gen = fls(pcie_gen_mask);
-               dev_info->pcie_num_lanes =
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 ? 32 :
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 ? 16 :
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 ? 12 :
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 ? 8 :
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 ? 4 :
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 ? 2 : 1;
-
-               dev_info->tcp_cache_size = adev->gfx.config.gc_tcp_l1_size;
-               dev_info->num_sqc_per_wgp = adev->gfx.config.gc_num_sqc_per_wgp;
-               dev_info->sqc_data_cache_size = adev->gfx.config.gc_l1_data_cache_size_per_sqc;
-               dev_info->sqc_inst_cache_size = adev->gfx.config.gc_l1_instruction_cache_size_per_sqc;
-               dev_info->gl1c_cache_size = adev->gfx.config.gc_gl1c_size_per_instance *
-                                           adev->gfx.config.gc_gl1c_per_sa;
-               dev_info->gl2c_cache_size = adev->gfx.config.gc_gl2c_per_gpu;
-               dev_info->mall_size = adev->gmc.mall_size;
-
-
-               if (adev->gfx.funcs->get_gfx_shadow_info) {
-                       struct amdgpu_gfx_shadow_info shadow_info;
-
-                       ret = amdgpu_gfx_get_gfx_shadow_info(adev, &shadow_info);
-                       if (!ret) {
-                               dev_info->shadow_size = shadow_info.shadow_size;
-                               dev_info->shadow_alignment = shadow_info.shadow_alignment;
-                               dev_info->csa_size = shadow_info.csa_size;
-                               dev_info->csa_alignment = shadow_info.csa_alignment;
-                       }
+               ret = amdgpu_device_info(adev, dev_info);
+               if (!ret) {
+                       kfree(dev_info);
+                       return ret;
                  }
 
                  ret = copy_to_user(out, dev_info,
--

2.34.1

#11 lore raw

Sent a new patch based on discussion with Alex.

Quoted 114 lines · Christian König

Am 19.03.24 um 15:59 schrieb Alex Deucher:

Quoted 104 lines
Quoted 102 lines · Christian König

Am 19.03.24 um 15:26 schrieb Alex Deucher:

Quoted 101 lines · Sunil Khatri
Quoted 95 lines

Refactor the code so debugfs and devcoredump can reuse the common information and avoid unnecessary copy of it.

created a new file which would be the right place to hold functions which will be used between sysfs, debugfs and devcoredump.

Cc Christian König <[email protected]>
Cc Alex Deucher <[email protected]>

---
   drivers/gpu/drm/amd/amdgpu/Makefile         |   2 +- drivers/gpu/drm/amd/amdgpu/amdgpu.h         |   1 + drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c | 151
++++++++++++++++++++
   drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c     | 118 +--------------

   4 files changed, 157 insertions(+), 115 deletions(-)

   create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c

drivers/gpu/drm/amd/amdgpu/Makefile +1 -1
index 4536c8ad0e11..05d34f4b18f5 100644
@@ -80,7 +80,7 @@ amdgpu-y += amdgpu_device.o 
 amdgpu_doorbell_mgr.o amdgpu_kms.o \
           amdgpu_umc.o smu_v11_0_i2c.o amdgpu_fru_eeprom.o amdgpu_rap.o \
           amdgpu_fw_attestation.o amdgpu_securedisplay.o \
           amdgpu_eeprom.o amdgpu_mca.o amdgpu_psp_ta.o amdgpu_lsdma.o \
-       amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o
+       amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o 

amdgpu_devinfo.o

   amdgpu-$(CONFIG_PROC_FS) += amdgpu_fdinfo.o

drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index 9c62552bec34..0267870aa9b1 100644
@@ -1609,4 +1609,5 @@ extern const struct attribute_group 
 amdgpu_vram_mgr_attr_group;
    extern const struct attribute_group amdgpu_gtt_mgr_attr_group;
    extern const struct attribute_group amdgpu_flash_attr_group;
 
+int amdgpu_device_info(struct amdgpu_device *adev, struct 

drm_amdgpu_info_device *dev_info);
   #endif

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +5 -0
new file mode 100644
index 000000000000..d2c15a1dcb0d
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2024 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person 

obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +7 -0
+
+#include "amdgpu.h"
+#include "amd_pcie.h"
+
+#include <drm/amdgpu_drm.h>
+
+int amdgpu_device_info(struct amdgpu_device *adev, struct 
Quoted 1 line

drm_amdgpu_info_device *dev_info)

We can probably keep this in amdgpu_kms.c unless that file is getting too big.  I don't think it warrants a new file at this point.  If you do keep it in amdgpu_kms.c, I'd recommend renaming it to something like amdgpu_kms_device_info() to keep the naming conventions.

Quoted 8 lines
Quoted 5 lines

We should not be using this for anything new in the first place.

A whole bunch of the stuff inside the devinfo structure has been deprecated because we found that putting everything into one structure was a bad idea.

It's a convenient way to collect a lot of useful information that we want in the core dump.  Plus it's not going anywhere because we need to keep compatibility in the IOCTL.

Quoted 8 lines

Yeah and exactly that is what I'm strictly against. The devinfo wasn't used for new stuff because we found that it is way to inflexible.

That's why we have multiple separate IOCTLs for the memory and firmware information for example.

We should really *not* reuse that for the device core dumping.

Rather just use the same information from the different IPs and subsystems directly. E.g. add a function to the VM, GFX etc for printing out devcoredump infos.

I have pushed new v2 based on some comments on chat with Alex. Now if we need this functionality or not could be debated and will decide to go for this or not based on it.

Regards
Sunil

Quoted 366 lines

Christian.

Quoted 363 lines

Alex

Quoted 360 lines

Regards,
Christian.

Quoted 357 lines
Quoted 154 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +14 -0
+{
+       int ret;
+       uint64_t vm_size;
+       uint32_t pcie_gen_mask;
+
+       if (dev_info == NULL)
+               return -EINVAL;
+
+       dev_info->device_id = adev->pdev->device;
+       dev_info->chip_rev = adev->rev_id;
+       dev_info->external_rev = adev->external_rev_id;
+       dev_info->pci_rev = adev->pdev->revision;
+       dev_info->family = adev->family;
+       dev_info->num_shader_engines = 

adev->gfx.config.max_shader_engines;
+       dev_info->num_shader_arrays_per_engine = adev->gfx.config.max_sh_per_se;
+       /* return all clocks in KHz */
+       dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10; +       if (adev->pm.dpm_enabled) {
+               dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev, false) * 10;
+               dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev, false) * 10;
+               dev_info->min_engine_clock = amdgpu_dpm_get_sclk(adev, true) * 10;
+               dev_info->min_memory_clock = amdgpu_dpm_get_mclk(adev, true) * 10;
+       } else {
+               dev_info->max_engine_clock =
+                       dev_info->min_engine_clock =
+ adev->clock.default_sclk * 10;
+               dev_info->max_memory_clock =
+                       dev_info->min_memory_clock =
+ adev->clock.default_mclk * 10;
+               }
+       dev_info->enabled_rb_pipes_mask = adev->gfx.config.backend_enable_mask;
+       dev_info->num_rb_pipes = adev->gfx.config.max_backends_per_se *
+               adev->gfx.config.max_shader_engines;
+       dev_info->num_hw_gfx_contexts = adev->gfx.config.max_hw_contexts;
+       dev_info->ids_flags = 0;
+       if (adev->flags & AMD_IS_APU)
+               dev_info->ids_flags |= AMDGPU_IDS_FLAGS_FUSION; +       if (adev->gfx.mcbp)
+               dev_info->ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION; +       if (amdgpu_is_tmz(adev))
+               dev_info->ids_flags |= AMDGPU_IDS_FLAGS_TMZ; +       if (adev->gfx.config.ta_cntl2_truncate_coord_mode) +               dev_info->ids_flags |= AMDGPU_IDS_FLAGS_CONFORMANT_TRUNC_COORD;

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +5 -0
+
+       vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
+       vm_size -= AMDGPU_VA_RESERVED_TOP;
+
+       /* Older VCE FW versions are buggy and can handle only 

40bits */
+       if (adev->vce.fw_version && adev->vce.fw_version < AMDGPU_VCE_FW_53_45)
+               vm_size = min(vm_size, 1ULL << 40);
+
+       dev_info->virtual_address_offset = AMDGPU_VA_RESERVED_BOTTOM; +       dev_info->virtual_address_max = min(vm_size, AMDGPU_GMC_HOLE_START);
+
+       if (vm_size > AMDGPU_GMC_HOLE_START) {
+               dev_info->high_va_offset = AMDGPU_GMC_HOLE_END; +               dev_info->high_va_max = AMDGPU_GMC_HOLE_END | vm_size;
+       }
+       dev_info->virtual_address_alignment = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
+       dev_info->pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
+       dev_info->gart_page_size = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
+       dev_info->cu_active_number = adev->gfx.cu_info.number; +       dev_info->cu_ao_mask = adev->gfx.cu_info.ao_cu_mask; +       dev_info->ce_ram_size = adev->gfx.ce_ram_size;
+       memcpy(&dev_info->cu_ao_bitmap[0], &adev->gfx.cu_info.ao_cu_bitmap[0],
+              sizeof(adev->gfx.cu_info.ao_cu_bitmap));
+       memcpy(&dev_info->cu_bitmap[0], &adev->gfx.cu_info.bitmap[0], +              sizeof(dev_info->cu_bitmap));
+       dev_info->vram_type = adev->gmc.vram_type;
+       dev_info->vram_bit_width = adev->gmc.vram_width;
+       dev_info->vce_harvest_config = adev->vce.harvest_config; +       dev_info->gc_double_offchip_lds_buf =
+ adev->gfx.config.double_offchip_lds_buf;
+       dev_info->wave_front_size = adev->gfx.cu_info.wave_front_size;
+       dev_info->num_shader_visible_vgprs = adev->gfx.config.max_gprs;
+       dev_info->num_cu_per_sh = adev->gfx.config.max_cu_per_sh; +       dev_info->num_tcc_blocks = adev->gfx.config.max_texture_channel_caches;
+       dev_info->gs_vgt_table_depth = adev->gfx.config.gs_vgt_table_depth;
+       dev_info->gs_prim_buffer_depth = adev->gfx.config.gs_prim_buffer_depth;
+       dev_info->max_gs_waves_per_vgt = adev->gfx.config.max_gs_threads;

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +6 -0
+
+       if (adev->family >= AMDGPU_FAMILY_NV)
+               dev_info->pa_sc_tile_steering_override =
+ adev->gfx.config.pa_sc_tile_steering_override;
+
+       dev_info->tcc_disabled_mask = 

adev->gfx.config.tcc_disabled_mask;
+
+       /* Combine the chip gen mask with the platform (CPU/mobo) mask. */
+       pcie_gen_mask = adev->pm.pcie_gen_mask & (adev->pm.pcie_gen_mask >> 16);
+       dev_info->pcie_gen = fls(pcie_gen_mask);
+       dev_info->pcie_num_lanes =
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 ? 32 :
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 ? 16 :
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 ? 12 :
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 ? 8 :
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 ? 4 :
+               adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 ? 2 : 1;
+
+       dev_info->tcp_cache_size = adev->gfx.config.gc_tcp_l1_size; +       dev_info->num_sqc_per_wgp = adev->gfx.config.gc_num_sqc_per_wgp;
+       dev_info->sqc_data_cache_size = adev->gfx.config.gc_l1_data_cache_size_per_sqc;
+       dev_info->sqc_inst_cache_size = adev->gfx.config.gc_l1_instruction_cache_size_per_sqc;
+       dev_info->gl1c_cache_size = adev->gfx.config.gc_gl1c_size_per_instance *
+ adev->gfx.config.gc_gl1c_per_sa;
+       dev_info->gl2c_cache_size = adev->gfx.config.gc_gl2c_per_gpu; +       dev_info->mall_size = adev->gmc.mall_size;

drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c new file +6 -0
+
+
+       if (adev->gfx.funcs->get_gfx_shadow_info) {
+               struct amdgpu_gfx_shadow_info shadow_info;
+
+               ret = amdgpu_gfx_get_gfx_shadow_info(adev, 

&shadow_info);
+               if (!ret) {
+                       dev_info->shadow_size = shadow_info.shadow_size;
+                       dev_info->shadow_alignment =

Quoted 8 lines

shadow_info.shadow_alignment;
+                       dev_info->csa_size = shadow_info.csa_size; +                       dev_info->csa_alignment = shadow_info.csa_alignment;
+               }
+       }
+       return ret;
+}

As noted by Lijo, this should probably be a void function since we want to populate as much information as we can and we can't break the IOCTL interface.

Alex

Quoted 189 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -16
index a66d47865e3b..24f775c68a51 100644
@@ -850,125 +850,15 @@ int amdgpu_info_ioctl(struct drm_device 
 *dev, void *data, struct drm_file *filp)
           }
           case AMDGPU_INFO_DEV_INFO: {
                   struct drm_amdgpu_info_device *dev_info;
-               uint64_t vm_size;
-               uint32_t pcie_gen_mask;
 
                   dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL);
                   if (!dev_info)
                           return -ENOMEM;
 
-               dev_info->device_id = adev->pdev->device;
-               dev_info->chip_rev = adev->rev_id;
-               dev_info->external_rev = adev->external_rev_id;
-               dev_info->pci_rev = adev->pdev->revision;
-               dev_info->family = adev->family;
-               dev_info->num_shader_engines = 
 adev->gfx.config.max_shader_engines;
-               dev_info->num_shader_arrays_per_engine = 
 adev->gfx.config.max_sh_per_se;
-               /* return all clocks in KHz */
-               dev_info->gpu_counter_freq = 
 amdgpu_asic_get_xclk(adev) * 10;
-               if (adev->pm.dpm_enabled) {
-                       dev_info->max_engine_clock = 
 amdgpu_dpm_get_sclk(adev, false) * 10;
-                       dev_info->max_memory_clock = 
 amdgpu_dpm_get_mclk(adev, false) * 10;
-                       dev_info->min_engine_clock = 
 amdgpu_dpm_get_sclk(adev, true) * 10;
-                       dev_info->min_memory_clock = 

amdgpu_dpm_get_mclk(adev, true) * 10;
-               } else {
-                       dev_info->max_engine_clock =
- dev_info->min_engine_clock =
- adev->clock.default_sclk * 10;
-                       dev_info->max_memory_clock =
- dev_info->min_memory_clock =
- adev->clock.default_mclk * 10;
-               }
-               dev_info->enabled_rb_pipes_mask = adev->gfx.config.backend_enable_mask;
-               dev_info->num_rb_pipes = adev->gfx.config.max_backends_per_se *
- adev->gfx.config.max_shader_engines;
-               dev_info->num_hw_gfx_contexts = adev->gfx.config.max_hw_contexts;
-               dev_info->ids_flags = 0;
-               if (adev->flags & AMD_IS_APU)
-                       dev_info->ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
-               if (adev->gfx.mcbp)
-                       dev_info->ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
-               if (amdgpu_is_tmz(adev))
-                       dev_info->ids_flags |= AMDGPU_IDS_FLAGS_TMZ; -               if (adev->gfx.config.ta_cntl2_truncate_coord_mode) -                       dev_info->ids_flags |= AMDGPU_IDS_FLAGS_CONFORMANT_TRUNC_COORD;
-
-               vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
-               vm_size -= AMDGPU_VA_RESERVED_TOP;
-
-               /* Older VCE FW versions are buggy and can handle only 40bits */
-               if (adev->vce.fw_version &&
-                   adev->vce.fw_version < AMDGPU_VCE_FW_53_45) -                       vm_size = min(vm_size, 1ULL << 40); -
-               dev_info->virtual_address_offset = AMDGPU_VA_RESERVED_BOTTOM;
-               dev_info->virtual_address_max =
-                       min(vm_size, AMDGPU_GMC_HOLE_START); -
-               if (vm_size > AMDGPU_GMC_HOLE_START) {
-                       dev_info->high_va_offset = AMDGPU_GMC_HOLE_END;
-                       dev_info->high_va_max = AMDGPU_GMC_HOLE_END | vm_size;
-               }
-               dev_info->virtual_address_alignment = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
-               dev_info->pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
-               dev_info->gart_page_size = max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
-               dev_info->cu_active_number = adev->gfx.cu_info.number;
-               dev_info->cu_ao_mask = adev->gfx.cu_info.ao_cu_mask; -               dev_info->ce_ram_size = adev->gfx.ce_ram_size; -               memcpy(&dev_info->cu_ao_bitmap[0], &adev->gfx.cu_info.ao_cu_bitmap[0],
- sizeof(adev->gfx.cu_info.ao_cu_bitmap));
-               memcpy(&dev_info->cu_bitmap[0], &adev->gfx.cu_info.bitmap[0],
-                      sizeof(dev_info->cu_bitmap));
-               dev_info->vram_type = adev->gmc.vram_type; -               dev_info->vram_bit_width = adev->gmc.vram_width; -               dev_info->vce_harvest_config = adev->vce.harvest_config;
-               dev_info->gc_double_offchip_lds_buf =
- adev->gfx.config.double_offchip_lds_buf;
-               dev_info->wave_front_size = adev->gfx.cu_info.wave_front_size;
-               dev_info->num_shader_visible_vgprs = adev->gfx.config.max_gprs;
-               dev_info->num_cu_per_sh = adev->gfx.config.max_cu_per_sh;
-               dev_info->num_tcc_blocks = adev->gfx.config.max_texture_channel_caches;
-               dev_info->gs_vgt_table_depth = adev->gfx.config.gs_vgt_table_depth;
-               dev_info->gs_prim_buffer_depth = adev->gfx.config.gs_prim_buffer_depth;
-               dev_info->max_gs_waves_per_vgt = adev->gfx.config.max_gs_threads;

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -6
-
-               if (adev->family >= AMDGPU_FAMILY_NV)
- dev_info->pa_sc_tile_steering_override =
- adev->gfx.config.pa_sc_tile_steering_override;
-
-               dev_info->tcc_disabled_mask = 

adev->gfx.config.tcc_disabled_mask;
-
-               /* Combine the chip gen mask with the platform (CPU/mobo) mask. */
-               pcie_gen_mask = adev->pm.pcie_gen_mask & (adev->pm.pcie_gen_mask >> 16);
-               dev_info->pcie_gen = fls(pcie_gen_mask); -               dev_info->pcie_num_lanes =
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 ? 32 :
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 ? 16 :
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 ? 12 :
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 ? 8 :
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 ? 4 :
-                       adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 ? 2 : 1;
-
-               dev_info->tcp_cache_size = adev->gfx.config.gc_tcp_l1_size;
-               dev_info->num_sqc_per_wgp = adev->gfx.config.gc_num_sqc_per_wgp;
-               dev_info->sqc_data_cache_size = adev->gfx.config.gc_l1_data_cache_size_per_sqc;
-               dev_info->sqc_inst_cache_size = adev->gfx.config.gc_l1_instruction_cache_size_per_sqc; -               dev_info->gl1c_cache_size = adev->gfx.config.gc_gl1c_size_per_instance *
- adev->gfx.config.gc_gl1c_per_sa;
-               dev_info->gl2c_cache_size = adev->gfx.config.gc_gl2c_per_gpu;
-               dev_info->mall_size = adev->gmc.mall_size;

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -6
-
-
-               if (adev->gfx.funcs->get_gfx_shadow_info) {
-                       struct amdgpu_gfx_shadow_info shadow_info;
-
-                       ret = amdgpu_gfx_get_gfx_shadow_info(adev, 

&shadow_info);
-                       if (!ret) {
-                               dev_info->shadow_size = shadow_info.shadow_size;
- dev_info->shadow_alignment = shadow_info.shadow_alignment; -                               dev_info->csa_size = shadow_info.csa_size;
-                               dev_info->csa_alignment = shadow_info.csa_alignment;
-                       }
+               ret = amdgpu_device_info(adev, dev_info); +               if (!ret) {
+                       kfree(dev_info);
+                       return ret;
                  }

                  ret = copy_to_user(out, dev_info,

Signature · 1 line
2.34.1