[PATCH 1/7] drm/amdgpu: Add option to refresh NPS data
Bhardwaj, Rajneesh
rajneesh.bhardwaj at amd.com
Tue Sep 24 17:47:33 UTC 2024
Reviewed-by: Rajneesh Bhardwaj <rajneesh.bhardwaj at amd.com>
On 9/24/2024 1:56 AM, Lijo Lazar wrote:
> In certain use cases, NPS data needs to be refreshed again from
> discovery table. Add API parameter to refresh NPS data from discovery
> table.
>
> Signed-off-by: Lijo Lazar <lijo.lazar at amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 68 +++++++++++++++----
> drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h | 2 +-
> drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 2 +-
> 3 files changed, 55 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> index 4bd61c169ca8..9f9a1867da72 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> @@ -1723,37 +1723,75 @@ union nps_info {
> struct nps_info_v1_0 v1;
> };
>
> +static int amdgpu_discovery_refresh_nps_info(struct amdgpu_device *adev,
> + union nps_info *nps_data)
> +{
> + uint64_t vram_size, pos, offset;
> + struct nps_info_header *nhdr;
> + struct binary_header bhdr;
> + uint16_t checksum;
> +
> + vram_size = (uint64_t)RREG32(mmRCC_CONFIG_MEMSIZE) << 20;
> + pos = vram_size - DISCOVERY_TMR_OFFSET;
> + amdgpu_device_vram_access(adev, pos, &bhdr, sizeof(bhdr), false);
> +
> + offset = le16_to_cpu(bhdr.table_list[NPS_INFO].offset);
> + checksum = le16_to_cpu(bhdr.table_list[NPS_INFO].checksum);
> +
> + amdgpu_device_vram_access(adev, (pos + offset), nps_data,
> + sizeof(*nps_data), false);
> +
> + nhdr = (struct nps_info_header *)(nps_data);
> + if (!amdgpu_discovery_verify_checksum((uint8_t *)nps_data,
> + le32_to_cpu(nhdr->size_bytes),
> + checksum)) {
> + dev_err(adev->dev, "nps data refresh, checksum mismatch\n");
> + return -EINVAL;
> + }
> +
> + return 0;
> +}
> +
> int amdgpu_discovery_get_nps_info(struct amdgpu_device *adev,
> uint32_t *nps_type,
> struct amdgpu_gmc_memrange **ranges,
> - int *range_cnt)
> + int *range_cnt, bool refresh)
> {
> struct amdgpu_gmc_memrange *mem_ranges;
> struct binary_header *bhdr;
> union nps_info *nps_info;
> + union nps_info nps_data;
> u16 offset;
> - int i;
> + int i, r;
>
> if (!nps_type || !range_cnt || !ranges)
> return -EINVAL;
>
> - if (!adev->mman.discovery_bin) {
> - dev_err(adev->dev,
> - "fetch mem range failed, ip discovery uninitialized\n");
> - return -EINVAL;
> - }
> + if (refresh) {
> + r = amdgpu_discovery_refresh_nps_info(adev, &nps_data);
> + if (r)
> + return r;
> + nps_info = &nps_data;
> + } else {
> + if (!adev->mman.discovery_bin) {
> + dev_err(adev->dev,
> + "fetch mem range failed, ip discovery uninitialized\n");
> + return -EINVAL;
> + }
>
> - bhdr = (struct binary_header *)adev->mman.discovery_bin;
> - offset = le16_to_cpu(bhdr->table_list[NPS_INFO].offset);
> + bhdr = (struct binary_header *)adev->mman.discovery_bin;
> + offset = le16_to_cpu(bhdr->table_list[NPS_INFO].offset);
>
> - if (!offset)
> - return -ENOENT;
> + if (!offset)
> + return -ENOENT;
>
> - /* If verification fails, return as if NPS table doesn't exist */
> - if (amdgpu_discovery_verify_npsinfo(adev, bhdr))
> - return -ENOENT;
> + /* If verification fails, return as if NPS table doesn't exist */
> + if (amdgpu_discovery_verify_npsinfo(adev, bhdr))
> + return -ENOENT;
>
> - nps_info = (union nps_info *)(adev->mman.discovery_bin + offset);
> + nps_info =
> + (union nps_info *)(adev->mman.discovery_bin + offset);
> + }
>
> switch (le16_to_cpu(nps_info->v1.header.version_major)) {
> case 1:
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h
> index f5d36525ec3e..b44d56465c5b 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h
> @@ -33,6 +33,6 @@ int amdgpu_discovery_set_ip_blocks(struct amdgpu_device *adev);
> int amdgpu_discovery_get_nps_info(struct amdgpu_device *adev,
> uint32_t *nps_type,
> struct amdgpu_gmc_memrange **ranges,
> - int *range_cnt);
> + int *range_cnt, bool refresh);
>
> #endif /* __AMDGPU_DISCOVERY__ */
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
> index 17a19d49d30a..4f088a5368d8 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
> @@ -1184,7 +1184,7 @@ int amdgpu_gmc_get_nps_memranges(struct amdgpu_device *adev,
> return -EINVAL;
>
> ret = amdgpu_discovery_get_nps_info(adev, &nps_type, &ranges,
> - &range_cnt);
> + &range_cnt, false);
>
> if (ret)
> return ret;
More information about the amd-gfx
mailing list