[RFC PATCH 3/3] drm: add dedicated minor for accelerator devices
Jiho Chu
jiho.chu at samsung.com
Tue Oct 25 06:43:30 UTC 2022
On Sun, 23 Oct 2022 00:46:22 +0300
Oded Gabbay <ogabbay at kernel.org> wrote:
> diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
> index b58ffb1433d6..c13701a8d4be 100644
> --- a/drivers/gpu/drm/drm_drv.c
> +++ b/drivers/gpu/drm/drm_drv.c
> @@ -56,6 +56,9 @@ MODULE_LICENSE("GPL and additional rights");
> static DEFINE_SPINLOCK(drm_minor_lock);
> static struct idr drm_minors_idr;
>
> +static DEFINE_SPINLOCK(accel_minor_lock);
> +static struct idr accel_minors_idr;
> +
> /*
> * If the drm core fails to init for whatever reason,
> * we should prevent any drivers from registering with it.
> @@ -94,6 +97,8 @@ static struct drm_minor **drm_minor_get_slot(struct drm_device *dev,
> return &dev->primary;
> case DRM_MINOR_RENDER:
> return &dev->render;
> + case DRM_MINOR_ACCEL:
> + return &dev->accel;
> default:
> BUG();
> }
> @@ -108,9 +113,15 @@ static void drm_minor_alloc_release(struct drm_device *dev, void *data)
>
> put_device(minor->kdev);
>
> - spin_lock_irqsave(&drm_minor_lock, flags);
> - idr_remove(&drm_minors_idr, minor->index);
> - spin_unlock_irqrestore(&drm_minor_lock, flags);
> + if (minor->type == DRM_MINOR_ACCEL) {
> + spin_lock_irqsave(&accel_minor_lock, flags);
> + idr_remove(&accel_minors_idr, minor->index);
> + spin_unlock_irqrestore(&accel_minor_lock, flags);
> + } else {
> + spin_lock_irqsave(&drm_minor_lock, flags);
> + idr_remove(&drm_minors_idr, minor->index);
> + spin_unlock_irqrestore(&drm_minor_lock, flags);
> + }
> }
>
> static int drm_minor_alloc(struct drm_device *dev, unsigned int type)
> @@ -127,13 +138,23 @@ static int drm_minor_alloc(struct drm_device *dev, unsigned int type)
> minor->dev = dev;
>
> idr_preload(GFP_KERNEL);
> - spin_lock_irqsave(&drm_minor_lock, flags);
> - r = idr_alloc(&drm_minors_idr,
> - NULL,
> - 64 * type,
> - 64 * (type + 1),
> - GFP_NOWAIT);
> - spin_unlock_irqrestore(&drm_minor_lock, flags);
> + if (type == DRM_MINOR_ACCEL) {
> + spin_lock_irqsave(&accel_minor_lock, flags);
> + r = idr_alloc(&accel_minors_idr,
> + NULL,
> + 64 * (type - DRM_MINOR_ACCEL),
> + 64 * (type - DRM_MINOR_ACCEL + 1),
> + GFP_NOWAIT);
> + spin_unlock_irqrestore(&accel_minor_lock, flags);
> + } else {
> + spin_lock_irqsave(&drm_minor_lock, flags);
> + r = idr_alloc(&drm_minors_idr,
> + NULL,
> + 64 * type,
> + 64 * (type + 1),
> + GFP_NOWAIT);
> + spin_unlock_irqrestore(&drm_minor_lock, flags);
> + }
Hi,
There are many functions which checks drm type and decides its behaviors. It's good to
re-use exiting codes, but accel devices use totally different major/minor, and so it needs to be moved to
/drvier/accel/ (maybe later..). How about seperating functions for alloc/release minor (accel_minor_alloc..)?
also, for others which have drm type related codes.
> @@ -607,6 +652,14 @@ static int drm_dev_init(struct drm_device *dev,
> /* no per-device feature limits by default */
> dev->driver_features = ~0u;
>
> + if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL) &&
> + (drm_core_check_feature(dev, DRIVER_RENDER) ||
> + drm_core_check_feature(dev, DRIVER_MODESET))) {
> +
> + DRM_ERROR("DRM driver can't be both a compute acceleration and graphics driver\n");
> + return -EINVAL;
> + }
> +
It's fine for the device only for acceleration, but can't graphic devices have acceleration feature?
Thanks,
Jiho Chu
More information about the dri-devel
mailing list