drm/amdgpu: Fetch NPS mode for GCv9.4.3 VFs
Subsystems (2)
PATCH 1/2 drm/amdgpu: Fetch NPS mode for GCv9.4.3 VFs
Use the memory ranges published in discovery table to deduce NPS mode of GC v9.4.3 VFs.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 12 +++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h | 2 +- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 30 +++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +7 -5
@@ -1256,14 +1256,14 @@ void amdgpu_gmc_sysfs_fini(struct amdgpu_device *adev)int amdgpu_gmc_get_nps_memranges (struct amdgpu_device *adev,struct amdgpu_mem_partition_info *mem_ranges, -int exp_ranges) +uint8_t *exp_ranges) {struct amdgpu_gmc_memrange *ranges;int range_cnt, ret, i, j;uint32_t nps_type;bool refresh; -if (!mem_ranges) +if (!mem_ranges || !exp_ranges)return -EINVAL ; refresh = (adev->init_lvl->level != AMDGPU_INIT_LEVEL_MINIMAL_XGMI) &&
@@ -1277,16 +1277,16 @@ int amdgpu_gmc_get_nps_memranges(struct amdgpu_device *adev,/* TODO: For now, expect ranges and partition count to be the same. * Adjust if there are holes expected in any NPS domain. */ -if (range_cnt != exp_ranges) { +if (*exp_ranges && (range_cnt != *exp_ranges)) {dev_warn ( adev->dev,"NPS config mismatch - expected ranges: %d discovery - nps mode: %d, nps ranges: %d" , - exp_ranges, nps_type, range_cnt); + *exp_ranges, nps_type, range_cnt); ret = -EINVAL ; goto err; } -for (i =0 ; i < exp_ranges; ++i) { +for (i =0 ; i < range_cnt; ++i) {if (ranges[i].base_address >= ranges[i].limit_address) { dev_warn( adev->dev,
@@ -1327,6 +1327,8 @@ int amdgpu_gmc_get_nps_memranges(struct amdgpu_device *adev, ranges[i].limit_address - ranges[i].base_address +1 ; } +if (!*exp_ranges) + *exp_ranges = range_cnt; err:kfree (ranges);
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +1 -1
@@ -467,7 +467,7 @@ void amdgpu_gmc_sysfs_fini(struct amdgpu_device *adev);int amdgpu_gmc_get_nps_memranges (struct amdgpu_device *adev,struct amdgpu_mem_partition_info *mem_ranges, -int exp_ranges); +uint8_t *exp_ranges);int amdgpu_gmc_request_memory_partition (struct amdgpu_device *adev,int nps_mode);
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +28 -2
@@ -1386,11 +1386,30 @@ gmc_v9_0_get_memory_partition(struct amdgpu_device *adev, u32 *supp_modes)return mode; } +static enum amdgpu_memory_partition +gmc_v9_0_query_vf_memory_partition (struct amdgpu_device *adev) +{ +switch (adev->gmc.num_mem_partitions) { +case 0 : +return UNKNOWN_MEMORY_PARTITION_MODE ; +case 1 : +return AMDGPU_NPS1_PARTITION_MODE ; +case 2 : +return AMDGPU_NPS2_PARTITION_MODE ; +case 4 : +return AMDGPU_NPS4_PARTITION_MODE ; +default : +return AMDGPU_NPS1_PARTITION_MODE ; + } + +return AMDGPU_NPS1_PARTITION_MODE ; +} +static enum amdgpu_memory_partition gmc_v9_0_query_memory_partition (struct amdgpu_device *adev) {if (amdgpu_sriov_vf (adev)) -return AMDGPU_NPS1_PARTITION_MODE ; +return gmc_v9_0_query_vf_memory_partition (adev);return gmc_v9_0_get_memory_partition (adev,NULL ); }
@@ -1935,6 +1954,8 @@ gmc_v9_0_init_sw_mem_ranges(struct amdgpu_device *adev,switch (mode) {case UNKNOWN_MEMORY_PARTITION_MODE : + adev->gmc.num_mem_partitions =0 ; +break ;case AMDGPU_NPS1_PARTITION_MODE : adev->gmc.num_mem_partitions =1 ;break ;
@@ -1954,7 +1975,7 @@ gmc_v9_0_init_sw_mem_ranges(struct amdgpu_device *adev,/* Use NPS range info, if populated */ r =amdgpu_gmc_get_nps_memranges (adev, mem_ranges, - adev->gmc.num_mem_partitions); + &adev->gmc.num_mem_partitions);if (!r) { l =0 ;for (i =1 ; i < adev->gmc.num_mem_partitions; ++i) {
@@ -1964,6 +1985,11 @@ gmc_v9_0_init_sw_mem_ranges(struct amdgpu_device *adev, } }else { +if (!adev->gmc.num_mem_partitions) { +dev_err (adev->dev, +"Not able to detect NPS mode, fall back to NPS1" ); + adev->gmc.num_mem_partitions =1 ; + }/* Fallback to sw based calculation */ size = (adev->gmc.real_vram_size +SZ_16M ) >>AMDGPU_GPU_PAGE_SHIFT ; size /= adev->gmc.num_mem_partitions;
Signature · 1 line
2.25.1
PATCH 2/2 drm/amdgpu: Show current compute partition on VF
Enable sysfs node for current compute partition mode on VFs also.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 29 +++++++++++++++++++++++-- drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 12 ++++------ 2 files changed, 31 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +27 -2
@@ -1612,21 +1612,46 @@ static DEVICE_ATTR(available_compute_partition, 0444,int amdgpu_gfx_sysfs_init (struct amdgpu_device *adev) { +struct amdgpu_xcp_mgr *xcp_mgr = adev->xcp_mgr; +bool xcp_switch_supported;int r; +if (!xcp_mgr) +return 0 ; + + xcp_switch_supported = + (xcp_mgr->funcs && xcp_mgr->funcs->switch_partition_mode); + +if (!xcp_switch_supported) + dev_attr_current_compute_partition.attr.mode &= + ~(S_IWUSR |S_IWGRP |S_IWOTH ); + r =device_create_file (adev->dev, &dev_attr_current_compute_partition);if (r)return r; - r =device_create_file (adev->dev, &dev_attr_available_compute_partition); +if (xcp_switch_supported) + r =device_create_file (adev->dev, + &dev_attr_available_compute_partition);return r; }void amdgpu_gfx_sysfs_fini (struct amdgpu_device *adev) { +struct amdgpu_xcp_mgr *xcp_mgr = adev->xcp_mgr; +bool xcp_switch_supported; + +if (!xcp_mgr) +return ; + + xcp_switch_supported = + (xcp_mgr->funcs && xcp_mgr->funcs->switch_partition_mode);device_remove_file (adev->dev, &dev_attr_current_compute_partition); -device_remove_file (adev->dev, &dev_attr_available_compute_partition); + +if (xcp_switch_supported) +device_remove_file (adev->dev, + &dev_attr_available_compute_partition); }int amdgpu_gfx_sysfs_isolation_shader_init (struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +4 -8
@@ -1165,12 +1165,9 @@ static int gfx_v9_4_3_sw_init(void *handle)if (r)return r; - -if (!amdgpu_sriov_vf (adev)) { - r =amdgpu_gfx_sysfs_init (adev); -if (r) -return r; - } + r =amdgpu_gfx_sysfs_init (adev); +if (r) +return r;gfx_v9_4_3_alloc_ip_dump (adev);
@@ -1201,8 +1198,7 @@ static int gfx_v9_4_3_sw_fini(void *handle)gfx_v9_4_3_mec_fini (adev);amdgpu_bo_unref (&adev->gfx.rlc.clear_state_obj);gfx_v9_4_3_free_microcode (adev); -if (!amdgpu_sriov_vf (adev)) -amdgpu_gfx_sysfs_fini (adev); +amdgpu_gfx_sysfs_fini (adev);amdgpu_gfx_sysfs_isolation_shader_fini (adev);kfree (adev->gfx.ip_dump_core);
Signature · 1 line
2.25.1
Re: [PATCH 2/2] drm/amdgpu: Show current compute partition on VF
[AMD Official Use Only - AMD Internal Distribution Only]
________________________________
From: Lijo Lazar <[email protected]>
Sent: Tuesday, September 24, 2024 2:02:50 AM
To: [email protected] <[email protected]>
Cc: Zhang, Hawking <[email protected]>; Deucher, Alexander <[email protected]>; Chander, Vignesh <[email protected]>
Subject: [PATCH 2/2] drm/amdgpu: Show current compute partition on VF
Enable sysfs node for current compute partition mode on VFs also.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 29 +++++++++++++++++++++++-- drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 12 ++++------ 2 files changed, 31 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +27 -2
@@ -1612,21 +1612,46 @@ static DEVICE_ATTR(available_compute_partition, 0444,int amdgpu_gfx_sysfs_init (struct amdgpu_device *adev) { +struct amdgpu_xcp_mgr *xcp_mgr = adev->xcp_mgr; +bool xcp_switch_supported;int r; +if (!xcp_mgr) +return 0 ; + + xcp_switch_supported = + (xcp_mgr->funcs && xcp_mgr->funcs->switch_partition_mode); + +if (!xcp_switch_supported) + dev_attr_current_compute_partition.attr.mode &= + ~(S_IWUSR |S_IWGRP |S_IWOTH ); + r =device_create_file (adev->dev, &dev_attr_current_compute_partition);if (r)return r; - r =device_create_file (adev->dev, &dev_attr_available_compute_partition); +if (xcp_switch_supported) + r =device_create_file (adev->dev, + &dev_attr_available_compute_partition);return r; }void amdgpu_gfx_sysfs_fini (struct amdgpu_device *adev) { +struct amdgpu_xcp_mgr *xcp_mgr = adev->xcp_mgr; +bool xcp_switch_supported; + +if (!xcp_mgr) +return ; + + xcp_switch_supported = + (xcp_mgr->funcs && xcp_mgr->funcs->switch_partition_mode);device_remove_file (adev->dev, &dev_attr_current_compute_partition); -device_remove_file (adev->dev, &dev_attr_available_compute_partition); + +if (xcp_switch_supported) +device_remove_file (adev->dev, + &dev_attr_available_compute_partition); }int amdgpu_gfx_sysfs_isolation_shader_init (struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +4 -8
@@ -1165,12 +1165,9 @@ static int gfx_v9_4_3_sw_init(void *handle)if (r)return r; - -if (!amdgpu_sriov_vf (adev)) { - r =amdgpu_gfx_sysfs_init (adev); -if (r) -return r; - } + r =amdgpu_gfx_sysfs_init (adev); +if (r) +return r;gfx_v9_4_3_alloc_ip_dump (adev);
@@ -1201,8 +1198,7 @@ static int gfx_v9_4_3_sw_fini(void *handle)gfx_v9_4_3_mec_fini (adev);amdgpu_bo_unref (&adev->gfx.rlc.clear_state_obj);gfx_v9_4_3_free_microcode (adev); -if (!amdgpu_sriov_vf (adev)) -amdgpu_gfx_sysfs_fini (adev); +amdgpu_gfx_sysfs_fini (adev);amdgpu_gfx_sysfs_isolation_shader_fini (adev);kfree (adev->gfx.ip_dump_core);
--
2.25.1
[AMD Official Use Only - AMD Internal Distribution Only]
________________________________
From: Lijo Lazar <[email protected]>
Sent: Tuesday, September 24, 2024 2:02:49 AM
To: [email protected] <[email protected]>
Cc: Zhang, Hawking <[email protected]>; Deucher, Alexander <[email protected]>; Chander, Vignesh <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu: Fetch NPS mode for GCv9.4.3 VFs
Use the memory ranges published in discovery table to deduce NPS mode of GC v9.4.3 VFs.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 12 +++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h | 2 +- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 30 +++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +7 -5
@@ -1256,14 +1256,14 @@ void amdgpu_gmc_sysfs_fini(struct amdgpu_device *adev)int amdgpu_gmc_get_nps_memranges (struct amdgpu_device *adev,struct amdgpu_mem_partition_info *mem_ranges, -int exp_ranges) +uint8_t *exp_ranges) {struct amdgpu_gmc_memrange *ranges;int range_cnt, ret, i, j;uint32_t nps_type;bool refresh; -if (!mem_ranges) +if (!mem_ranges || !exp_ranges)return -EINVAL ; refresh = (adev->init_lvl->level != AMDGPU_INIT_LEVEL_MINIMAL_XGMI) &&
@@ -1277,16 +1277,16 @@ int amdgpu_gmc_get_nps_memranges(struct amdgpu_device *adev,/* TODO: For now, expect ranges and partition count to be the same. * Adjust if there are holes expected in any NPS domain. */ -if (range_cnt != exp_ranges) { +if (*exp_ranges && (range_cnt != *exp_ranges)) {dev_warn ( adev->dev,"NPS config mismatch - expected ranges: %d discovery - nps mode: %d, nps ranges: %d" , - exp_ranges, nps_type, range_cnt); + *exp_ranges, nps_type, range_cnt); ret = -EINVAL ; goto err; } -for (i =0 ; i < exp_ranges; ++i) { +for (i =0 ; i < range_cnt; ++i) {if (ranges[i].base_address >= ranges[i].limit_address) { dev_warn( adev->dev,
@@ -1327,6 +1327,8 @@ int amdgpu_gmc_get_nps_memranges(struct amdgpu_device *adev, ranges[i].limit_address - ranges[i].base_address +1 ; } +if (!*exp_ranges) + *exp_ranges = range_cnt; err:kfree (ranges);
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +1 -1
@@ -467,7 +467,7 @@ void amdgpu_gmc_sysfs_fini(struct amdgpu_device *adev);int amdgpu_gmc_get_nps_memranges (struct amdgpu_device *adev,struct amdgpu_mem_partition_info *mem_ranges, -int exp_ranges); +uint8_t *exp_ranges);int amdgpu_gmc_request_memory_partition (struct amdgpu_device *adev,int nps_mode);
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +28 -2
@@ -1386,11 +1386,30 @@ gmc_v9_0_get_memory_partition(struct amdgpu_device *adev, u32 *supp_modes)return mode; } +static enum amdgpu_memory_partition +gmc_v9_0_query_vf_memory_partition (struct amdgpu_device *adev) +{ +switch (adev->gmc.num_mem_partitions) { +case 0 : +return UNKNOWN_MEMORY_PARTITION_MODE ; +case 1 : +return AMDGPU_NPS1_PARTITION_MODE ; +case 2 : +return AMDGPU_NPS2_PARTITION_MODE ; +case 4 : +return AMDGPU_NPS4_PARTITION_MODE ; +default : +return AMDGPU_NPS1_PARTITION_MODE ; + } + +return AMDGPU_NPS1_PARTITION_MODE ; +} +static enum amdgpu_memory_partition gmc_v9_0_query_memory_partition (struct amdgpu_device *adev) {if (amdgpu_sriov_vf (adev)) -return AMDGPU_NPS1_PARTITION_MODE ; +return gmc_v9_0_query_vf_memory_partition (adev);return gmc_v9_0_get_memory_partition (adev,NULL ); }
@@ -1935,6 +1954,8 @@ gmc_v9_0_init_sw_mem_ranges(struct amdgpu_device *adev,switch (mode) {case UNKNOWN_MEMORY_PARTITION_MODE : + adev->gmc.num_mem_partitions =0 ; +break ;case AMDGPU_NPS1_PARTITION_MODE : adev->gmc.num_mem_partitions =1 ;break ;
@@ -1954,7 +1975,7 @@ gmc_v9_0_init_sw_mem_ranges(struct amdgpu_device *adev,/* Use NPS range info, if populated */ r =amdgpu_gmc_get_nps_memranges (adev, mem_ranges, - adev->gmc.num_mem_partitions); + &adev->gmc.num_mem_partitions);if (!r) { l =0 ;for (i =1 ; i < adev->gmc.num_mem_partitions; ++i) {
@@ -1964,6 +1985,11 @@ gmc_v9_0_init_sw_mem_ranges(struct amdgpu_device *adev, } }else { +if (!adev->gmc.num_mem_partitions) { +dev_err (adev->dev, +"Not able to detect NPS mode, fall back to NPS1" ); + adev->gmc.num_mem_partitions =1 ; + }/* Fallback to sw based calculation */ size = (adev->gmc.real_vram_size +SZ_16M ) >>AMDGPU_GPU_PAGE_SHIFT ; size /= adev->gmc.num_mem_partitions;
--
2.25.1