[PATCH 4/4] drm/amdkfd: Implement image tiling mode support

Oded Gabbay oded.gabbay at gmail.com
Sun Aug 13 09:08:05 UTC 2017


On Sat, Aug 12, 2017 at 7:47 AM, Felix Kuehling <Felix.Kuehling at amd.com> wrote:
> From: Yong Zhao <yong.zhao at amd.com>
>
> Signed-off-by: Yong Zhao <yong.zhao at amd.com>
> Signed-off-by: Felix Kuehling <Felix.Kuehling at amd.com>
> ---
>  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 43 ++++++++++++++++++++++++++++++++
>  include/uapi/linux/kfd_ioctl.h           | 37 ++++++++++++++++++++++++++-
>  2 files changed, 79 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> index 6be1bba..68ec830 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> @@ -890,6 +890,46 @@ static int kfd_ioctl_alloc_scratch_memory(struct file *filep,
>         return -EFAULT;
>  }
>
> +static int kfd_ioctl_get_tile_config(struct file *filep,
> +               struct kfd_process *p, void *data)
> +{
> +       struct kfd_ioctl_get_tile_config_args *args = data;
> +       struct kfd_dev *dev;
> +       struct tile_config config;
> +       int err = 0;
> +
> +       dev = kfd_device_by_id(args->gpu_id);
> +
> +       dev->kfd2kgd->get_tile_config(dev->kgd, &config);
> +
> +       args->gb_addr_config = config.gb_addr_config;
> +       args->num_banks = config.num_banks;
> +       args->num_ranks = config.num_ranks;
> +
> +       if (args->num_tile_configs > config.num_tile_configs)
> +               args->num_tile_configs = config.num_tile_configs;
> +       err = copy_to_user((void __user *)args->tile_config_ptr,
> +                       config.tile_config_ptr,
> +                       args->num_tile_configs * sizeof(uint32_t));
> +       if (err) {
> +               args->num_tile_configs = 0;
> +               return -EFAULT;
> +       }
> +
> +       if (args->num_macro_tile_configs > config.num_macro_tile_configs)
> +               args->num_macro_tile_configs =
> +                               config.num_macro_tile_configs;
> +       err = copy_to_user((void __user *)args->macro_tile_config_ptr,
> +                       config.macro_tile_config_ptr,
> +                       args->num_macro_tile_configs * sizeof(uint32_t));
> +       if (err) {
> +               args->num_macro_tile_configs = 0;
> +               return -EFAULT;
> +       }
> +
> +       return 0;
> +}
> +
>  #define AMDKFD_IOCTL_DEF(ioctl, _func, _flags) \
>         [_IOC_NR(ioctl)] = {.cmd = ioctl, .func = _func, .flags = _flags, \
>                             .cmd_drv = 0, .name = #ioctl}
> @@ -946,6 +986,9 @@ static const struct amdkfd_ioctl_desc amdkfd_ioctls[] = {
>
>         AMDKFD_IOCTL_DEF(AMDKFD_IOC_ALLOC_MEMORY_OF_SCRATCH,
>                         kfd_ioctl_alloc_scratch_memory, 0),
> +
> +       AMDKFD_IOCTL_DEF(AMDKFD_IOC_GET_TILE_CONFIG,
> +                       kfd_ioctl_get_tile_config, 0)
>  };
>
>  #define AMDKFD_CORE_IOCTL_COUNT        ARRAY_SIZE(amdkfd_ioctls)
> diff --git a/include/uapi/linux/kfd_ioctl.h b/include/uapi/linux/kfd_ioctl.h
> index 3dd86e1..10dcdc6 100644
> --- a/include/uapi/linux/kfd_ioctl.h
> +++ b/include/uapi/linux/kfd_ioctl.h
> @@ -239,6 +239,29 @@ struct kfd_ioctl_alloc_memory_of_scratch_args {
>         uint32_t pad;
>  };
>
> +struct kfd_ioctl_get_tile_config_args {
> +       /* to KFD: pointer to tile array */
> +       uint64_t tile_config_ptr;
> +       /* to KFD: pointer to macro tile array */
> +       uint64_t macro_tile_config_ptr;
> +       /* to KFD: array size allocated by user mode
> +        * from KFD: array size filled by kernel
> +        */
> +       uint32_t num_tile_configs;
> +       /* to KFD: array size allocated by user mode
> +        * from KFD: array size filled by kernel
> +        */
> +       uint32_t num_macro_tile_configs;
> +
> +       uint32_t gpu_id;                /* to KFD */
> +       uint32_t gb_addr_config;        /* from KFD */
> +       uint32_t num_banks;             /* from KFD */
> +       uint32_t num_ranks;             /* from KFD */
> +       /* struct size can be extended later if needed
> +        * without breaking ABI compatibility
> +        */
> +};
> +
>  #define AMDKFD_IOCTL_BASE 'K'
>  #define AMDKFD_IO(nr)                  _IO(AMDKFD_IOCTL_BASE, nr)
>  #define AMDKFD_IOR(nr, type)           _IOR(AMDKFD_IOCTL_BASE, nr, type)
> @@ -303,7 +326,19 @@ struct kfd_ioctl_alloc_memory_of_scratch_args {
>  #define AMDKFD_IOC_ALLOC_MEMORY_OF_SCRATCH     \
>                 AMDKFD_IOWR(0x15, struct kfd_ioctl_alloc_memory_of_scratch_args)
>
> +/* TODO:
> + * - AMDKFD_IOC_SET_CU_MASK
> + * - AMDKFD_IOC_SET_PROCESS_DGPU_APERTURE
> + * - AMDKFD_IOC_SET_TRAP_HANDLER
> + * - AMDKFD_IOC_GET_PROCESS_APERTURES_NEW
> + * - AMDKFD_IOC_GET_DMABUF_INFO
> + * - AMDKFD_IOC_IMPORT_DMABUF
> + */
> +
> +#define AMDKFD_IOC_GET_TILE_CONFIG                                      \
> +               AMDKFD_IOWR(0x1C, struct kfd_ioctl_get_tile_config_args)
> +
>  #define AMDKFD_COMMAND_START           0x01
> -#define AMDKFD_COMMAND_END             0x16
> +#define AMDKFD_COMMAND_END             0x1D

As in the previous patch, there is a hole here in the IOCTLs
numbering. I suggest that when you upstream new IOCTLs, you will put
them in consecutive numbers per the upstream driver, and then take
that change downstream because you can easily change it in your
driver.

Oded

>
>  #endif
> --
> 2.7.4
>

With the above fixed, this patch is:
Reviewed-by: Oded Gabbay <oded.gabbay at gmail.com>


More information about the amd-gfx mailing list