[PATCH] drm/amdgpu: add new AMDGPU_INFO subquery for fw objects

Alex Deucher alexdeucher at gmail.com
Tue Oct 8 17:05:21 UTC 2024


On Tue, Oct 8, 2024 at 11:30 AM Shashank Sharma <shashank.sharma at amd.com> wrote:
>
> Currently, the shadow FW space size and alignment information is
> protected under a flag (adev->gfx.cp_gfx_shadow) which gets set
> only in case of SRIOV setups.
> if (amdgpu_sriov_vf(adev))
>         adev->gfx.cp_gfx_shadow = true;
>
> But we need this information for GFX Userqueues, so that user can
> create these objects while creating userqueue. This patch series
> creates a method to get this information bypassing the dependency
> on this check.
>
> This patch:
>  - adds a new subquery (AMDGPU_INFO_FW_OBJ_SZ) in
>    AMDGPU_INFO_IOCTL to get the size and alignment of shadow
>    and csa objects from the FW setup.
>  - adds a new input parameter flag to the gfx.funcs->get_gfx_shadow_info
>    fptr definition, so that it can accommodate the information without the
>    check (adev->gfx.cp_gfx_shadow) on request.
>  - updates the existing definition of amdgpu_gfx_get_gfx_shadow_info to
>    adjust with this new flag.
>
> Cc: Alex Deucher <alexander.deucher at amd.com>
> Cc: Christian Koenig <christian.koenig at amd.com>
> Cc: Arvind Yadav <arvind.yadav at amd.com>
> Signed-off-by: Shashank Sharma <shashank.sharma at amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h |  5 +++--
>  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 14 ++++++++++++++
>  drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c  | 19 +++++++++++++------
>  include/uapi/drm/amdgpu_drm.h           |  2 ++
>  4 files changed, 32 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
> index f710178a21bc..efea172c41b8 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
> @@ -302,7 +302,8 @@ struct amdgpu_gfx_funcs {
>         void (*init_spm_golden)(struct amdgpu_device *adev);
>         void (*update_perfmon_mgcg)(struct amdgpu_device *adev, bool enable);
>         int (*get_gfx_shadow_info)(struct amdgpu_device *adev,
> -                                  struct amdgpu_gfx_shadow_info *shadow_info);
> +                                  struct amdgpu_gfx_shadow_info *shadow_info,
> +                                  bool skip_check);
>         enum amdgpu_gfx_partition
>                         (*query_partition_mode)(struct amdgpu_device *adev);
>         int (*switch_partition_mode)(struct amdgpu_device *adev,
> @@ -491,7 +492,7 @@ struct amdgpu_gfx_ras_mem_id_entry {
>  #define amdgpu_gfx_select_se_sh(adev, se, sh, instance, xcc_id) ((adev)->gfx.funcs->select_se_sh((adev), (se), (sh), (instance), (xcc_id)))
>  #define amdgpu_gfx_select_me_pipe_q(adev, me, pipe, q, vmid, xcc_id) ((adev)->gfx.funcs->select_me_pipe_q((adev), (me), (pipe), (q), (vmid), (xcc_id)))
>  #define amdgpu_gfx_init_spm_golden(adev) (adev)->gfx.funcs->init_spm_golden((adev))
> -#define amdgpu_gfx_get_gfx_shadow_info(adev, si) ((adev)->gfx.funcs->get_gfx_shadow_info((adev), (si)))
> +#define amdgpu_gfx_get_gfx_shadow_info(adev, si) ((adev)->gfx.funcs->get_gfx_shadow_info((adev), (si), false))
>
>  /**
>   * amdgpu_gfx_create_bitmask - create a bitmask
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index b53c35992152..8521b62cc136 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -1282,6 +1282,20 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
>                 return copy_to_user(out, &gpuvm_fault,
>                                     min((size_t)size, sizeof(gpuvm_fault))) ? -EFAULT : 0;
>         }
> +       case AMDGPU_INFO_FW_OBJ_SZ: {
> +               struct amdgpu_gfx_shadow_info shadow_info;
> +
> +               memset(&shadow_info, 0, sizeof(shadow_info));
> +               if (adev->gfx.funcs->get_gfx_shadow_info) {
> +                       adev->gfx.funcs->get_gfx_shadow_info(adev, &shadow_info, true);
> +                       ret = copy_to_user(out, &shadow_info,
> +                                         min((size_t)size, sizeof(shadow_info))) ? -EFAULT : 0;
> +               } else {
> +                       ret = -EOPNOTSUPP;
> +               }
> +
> +               return ret;
> +       }
>         default:
>                 DRM_DEBUG_KMS("Invalid request %d\n", info->query);
>                 return -EINVAL;
> diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
> index 1d5c873876f5..e5f5de8804b4 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
> @@ -1034,14 +1034,21 @@ static void gfx_v11_0_select_me_pipe_q(struct amdgpu_device *adev,
>  #define MQD_FWWORKAREA_SIZE       484
>  #define MQD_FWWORKAREA_ALIGNMENT  256
>
> -static int gfx_v11_0_get_gfx_shadow_info(struct amdgpu_device *adev,
> +static void gfx_v11_0_get_gfx_shadow_info_nocheck(struct amdgpu_device *adev,
>                                          struct amdgpu_gfx_shadow_info *shadow_info)
>  {
> -       if (adev->gfx.cp_gfx_shadow) {
> -               shadow_info->shadow_size = MQD_SHADOW_BASE_SIZE;
> -               shadow_info->shadow_alignment = MQD_SHADOW_BASE_ALIGNMENT;
> -               shadow_info->csa_size = MQD_FWWORKAREA_SIZE;
> -               shadow_info->csa_alignment = MQD_FWWORKAREA_ALIGNMENT;
> +       shadow_info->shadow_size = MQD_SHADOW_BASE_SIZE;
> +       shadow_info->shadow_alignment = MQD_SHADOW_BASE_ALIGNMENT;
> +       shadow_info->csa_size = MQD_FWWORKAREA_SIZE;
> +       shadow_info->csa_alignment = MQD_FWWORKAREA_ALIGNMENT;
> +}
> +
> +static int gfx_v11_0_get_gfx_shadow_info(struct amdgpu_device *adev,
> +                                        struct amdgpu_gfx_shadow_info *shadow_info,
> +                                        bool skip_check)
> +{
> +       if (adev->gfx.cp_gfx_shadow || skip_check) {
> +               gfx_v11_0_get_gfx_shadow_info_nocheck(adev, shadow_info);
>                 return 0;
>         } else {
>                 memset(shadow_info, 0, sizeof(struct amdgpu_gfx_shadow_info));
> diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h
> index d9bff1c3b326..ad35b41be250 100644
> --- a/include/uapi/drm/amdgpu_drm.h
> +++ b/include/uapi/drm/amdgpu_drm.h
> @@ -1052,6 +1052,8 @@ struct drm_amdgpu_cs_chunk_cp_gfx_shadow {
>  #define AMDGPU_INFO_MAX_IBS                    0x22
>  /* query last page fault info */
>  #define AMDGPU_INFO_GPUVM_FAULT                        0x23
> +/* query FW object size and alignment */
> +#define AMDGPU_INFO_FW_OBJ_SZ                  0x24

Maybe something like:
AMDGPU_INFO_UQ_METADATA to make it clearer what it's for.  Also I
think we want to make the input the IP type so we can extend this to
other IPs in the future if necessary.  We should also be explicit with
the output format so it's clear to userspace how to use the query.
Something like the attached patch.

Alex


>
>  #define AMDGPU_INFO_MMR_SE_INDEX_SHIFT 0
>  #define AMDGPU_INFO_MMR_SE_INDEX_MASK  0xff
> --
> 2.46.0
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: uq_metadata.diff
Type: text/x-patch
Size: 1243 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/amd-gfx/attachments/20241008/4344706e/attachment.bin>


More information about the amd-gfx mailing list