All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laura Abbott <labbott@redhat.com>
To: Chris Wilson <chris@chris-wilson.co.uk>, dri-devel@lists.freedesktop.org
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>, intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/vgem: Convert to a struct drm_device subclass
Date: Tue, 9 May 2017 12:20:32 -0700	[thread overview]
Message-ID: <489c5616-030f-74d1-94a4-e35c5bee8973@redhat.com> (raw)
In-Reply-To: <20170508132228.9509-1-chris@chris-wilson.co.uk>

On 05/08/2017 06:22 AM, Chris Wilson wrote:
> With Laura's introduction of the fake platform device for importing
> dmabuf, we add a second static that is logically tied to the vgem_device.
> Convert vgem over to using the struct drm_device subclassing, so that
> the platform device is stored inside its owner.
> 
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Laura Abbott <labbott@redhat.com>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> ---
>   drivers/gpu/drm/vgem/vgem_drv.c | 63 +++++++++++++++++++++++++++--------------
>   1 file changed, 41 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/gpu/drm/vgem/vgem_drv.c b/drivers/gpu/drm/vgem/vgem_drv.c
> index c9381d457a03..4b23ba049632 100644
> --- a/drivers/gpu/drm/vgem/vgem_drv.c
> +++ b/drivers/gpu/drm/vgem/vgem_drv.c
> @@ -42,7 +42,10 @@
>   #define DRIVER_MAJOR	1
>   #define DRIVER_MINOR	0
>   
> -static struct platform_device *vgem_platform;
> +static struct vgem_device {
> +	struct drm_device drm;
> +	struct platform_device *platform;
> +} *vgem_device;
>   
>   static void vgem_gem_free_object(struct drm_gem_object *obj)
>   {
> @@ -307,7 +310,9 @@ static struct sg_table *vgem_prime_get_sg_table(struct drm_gem_object *obj)
>   static struct drm_gem_object* vgem_prime_import(struct drm_device *dev,
>   						struct dma_buf *dma_buf)
>   {
> -	return drm_gem_prime_import_dev(dev, dma_buf, &vgem_platform->dev);
> +	struct vgem_device *vgem = container_of(dev, typeof(*vgem), drm);
> +
> +	return drm_gem_prime_import_dev(dev, dma_buf, &vgem->platform->dev);
>   }
>   
>   static struct drm_gem_object *vgem_prime_import_sg_table(struct drm_device *dev,
> @@ -377,8 +382,19 @@ static int vgem_prime_mmap(struct drm_gem_object *obj,
>   	return 0;
>   }
>   
> +static void vgem_release(struct drm_device *dev)
> +{
> +	struct vgem_device *vgem = container_of(dev, typeof(*vgem), drm);
> +
> +	platform_device_unregister(vgem->platform);
> +	drm_dev_fini(&vgem->drm);
> +
> +	kfree(vgem);
> +}
> +
>   static struct drm_driver vgem_driver = {
>   	.driver_features		= DRIVER_GEM | DRIVER_PRIME,
> +	.release			= vgem_release,
>   	.open				= vgem_open,
>   	.postclose			= vgem_postclose,
>   	.gem_free_object_unlocked	= vgem_gem_free_object,
> @@ -408,45 +424,48 @@ static struct drm_driver vgem_driver = {
>   	.minor	= DRIVER_MINOR,
>   };
>   
> -static struct drm_device *vgem_device;
> -
>   static int __init vgem_init(void)
>   {
>   	int ret;
>   
> -	vgem_device = drm_dev_alloc(&vgem_driver, NULL);
> -	if (IS_ERR(vgem_device))
> -		return PTR_ERR(vgem_device);
> +	vgem_device = kzalloc(sizeof(*vgem_device), GFP_KERNEL);
> +	if (!vgem_device)
> +		return -ENOMEM;
>   
> -	vgem_platform = platform_device_register_simple("vgem",
> -					-1, NULL, 0);
> +	ret = drm_dev_init(&vgem_device->drm, &vgem_driver, NULL);
> +	if (ret)
> +		goto out_free;
>   
> -	if (!vgem_platform) {
> +	vgem_device->platform =
> +		platform_device_register_simple("vgem", -1, NULL, 0);
> +	if (!vgem_device->platform) {
>   		ret = -ENODEV;
> -		goto out;
> +		goto out_fini;
>   	}
>   
> -	dma_coerce_mask_and_coherent(&vgem_platform->dev,
> -					DMA_BIT_MASK(64));
> +	dma_coerce_mask_and_coherent(&vgem_device->platform->dev,
> +				     DMA_BIT_MASK(64));
>   
> -	ret  = drm_dev_register(vgem_device, 0);
> +	/* Final step: expose the device/driver to userspace */
> +	ret  = drm_dev_register(&vgem_device->drm, 0);
>   	if (ret)
> -		goto out_unref;
> +		goto out_unregister;
>   
>   	return 0;
>   
> -out_unref:
> -	platform_device_unregister(vgem_platform);
> -out:
> -	drm_dev_unref(vgem_device);
> +out_unregister:
> +	platform_device_unregister(vgem_device->platform);
> +out_fini:
> +	drm_dev_fini(&vgem_device->drm > +out_free:
> +	kfree(vgem_device);
>   	return ret;
>   }
>   
>   static void __exit vgem_exit(void)
>   {
> -	platform_device_unregister(vgem_platform);
> -	drm_dev_unregister(vgem_device);
> -	drm_dev_unref(vgem_device);
> +	drm_dev_unregister(&vgem_device->drm);
> +	drm_dev_unref(&vgem_device->drm);
>   }
>   
>   module_init(vgem_init);
> 

Reviewed-by: Laura Abbott <labbott@redhat.com>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2017-05-09 19:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-08 13:22 [PATCH] drm/vgem: Convert to a struct drm_device subclass Chris Wilson
2017-05-08 13:43 ` ✓ Fi.CI.BAT: success for " Patchwork
2017-05-09 19:20 ` Laura Abbott [this message]
2017-05-10  8:15   ` [PATCH] " Daniel Vetter
2017-05-10 14:40     ` [PATCH] drm/prime: include device.h Laura Abbott
2017-05-10 14:40       ` Laura Abbott
2017-05-10 14:48       ` Chris Wilson
2017-05-10 14:48         ` Chris Wilson
2017-05-10 17:05         ` [PATCHv2] drm/prime: Forward declare struct device Laura Abbott
2017-05-10 17:05           ` Laura Abbott
2017-05-10 17:13           ` Sumit Semwal
2017-05-10 14:59     ` ✗ Fi.CI.BAT: failure for drm/prime: include device.h Patchwork
2017-05-10 17:16     ` ✓ Fi.CI.BAT: success " Patchwork
2017-05-10 17:35 ` ✓ Fi.CI.BAT: success for drm/vgem: Convert to a struct drm_device subclass (rev2) Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=489c5616-030f-74d1-94a4-e35c5bee8973@redhat.com \
    --to=labbott@redhat.com \
    --cc=chris@chris-wilson.co.uk \
    --cc=daniel.vetter@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.