Skip to content

Commit e3e84b0

Browse files
Marek Olšákalexdeucher
authored andcommitted
drm/amdgpu: return the PCIe gen and lanes from the INFO ioctl
For computing PCIe bandwidth in userspace and troubleshooting PCIe bandwidth issues. Note that this intentionally fills holes and padding in drm_amdgpu_info_device. Mesa MR: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20790 Signed-off-by: Marek Olšák <marek.olsak@amd.com> Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 26fd808 commit e3e84b0

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,10 @@
107107
* - 3.49.0 - Add gang submit into CS IOCTL
108108
* - 3.50.0 - Update AMDGPU_INFO_DEV_INFO IOCTL for minimum engine and memory clock
109109
* Update AMDGPU_INFO_SENSOR IOCTL for PEAK_PSTATE engine and memory clock
110+
* 3.51.0 - Return the PCIe gen and lanes from the INFO ioctl
110111
*/
111112
#define KMS_DRIVER_MAJOR 3
112-
#define KMS_DRIVER_MINOR 50
113+
#define KMS_DRIVER_MINOR 51
113114
#define KMS_DRIVER_PATCHLEVEL 0
114115

115116
unsigned int amdgpu_vram_limit = UINT_MAX;

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "amdgpu_gem.h"
4444
#include "amdgpu_display.h"
4545
#include "amdgpu_ras.h"
46+
#include "amd_pcie.h"
4647

4748
void amdgpu_unregister_gpu_instance(struct amdgpu_device *adev)
4849
{
@@ -767,6 +768,7 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
767768
case AMDGPU_INFO_DEV_INFO: {
768769
struct drm_amdgpu_info_device *dev_info;
769770
uint64_t vm_size;
771+
uint32_t pcie_gen_mask;
770772
int ret;
771773

772774
dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL);
@@ -799,7 +801,6 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
799801
dev_info->num_rb_pipes = adev->gfx.config.max_backends_per_se *
800802
adev->gfx.config.max_shader_engines;
801803
dev_info->num_hw_gfx_contexts = adev->gfx.config.max_hw_contexts;
802-
dev_info->_pad = 0;
803804
dev_info->ids_flags = 0;
804805
if (adev->flags & AMD_IS_APU)
805806
dev_info->ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
@@ -853,6 +854,17 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
853854

854855
dev_info->tcc_disabled_mask = adev->gfx.config.tcc_disabled_mask;
855856

857+
/* Combine the chip gen mask with the platform (CPU/mobo) mask. */
858+
pcie_gen_mask = adev->pm.pcie_gen_mask & (adev->pm.pcie_gen_mask >> 16);
859+
dev_info->pcie_gen = fls(pcie_gen_mask);
860+
dev_info->pcie_num_lanes =
861+
adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 ? 32 :
862+
adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 ? 16 :
863+
adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 ? 12 :
864+
adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 ? 8 :
865+
adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 ? 4 :
866+
adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 ? 2 : 1;
867+
856868
ret = copy_to_user(out, dev_info,
857869
min((size_t)size, sizeof(*dev_info))) ? -EFAULT : 0;
858870
kfree(dev_info);

include/uapi/drm/amdgpu_drm.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,8 @@ struct drm_amdgpu_info_device {
10531053
__u32 enabled_rb_pipes_mask;
10541054
__u32 num_rb_pipes;
10551055
__u32 num_hw_gfx_contexts;
1056-
__u32 _pad;
1056+
/* PCIe version (the smaller of the GPU and the CPU/motherboard) */
1057+
__u32 pcie_gen;
10571058
__u64 ids_flags;
10581059
/** Starting virtual address for UMDs. */
10591060
__u64 virtual_address_offset;
@@ -1100,7 +1101,8 @@ struct drm_amdgpu_info_device {
11001101
__u32 gs_prim_buffer_depth;
11011102
/* max gs wavefront per vgt*/
11021103
__u32 max_gs_waves_per_vgt;
1103-
__u32 _pad1;
1104+
/* PCIe number of lanes (the smaller of the GPU and the CPU/motherboard) */
1105+
__u32 pcie_num_lanes;
11041106
/* always on cu bitmap */
11051107
__u32 cu_ao_bitmap[4][4];
11061108
/** Starting high virtual address for UMDs. */

0 commit comments

Comments
 (0)