From patchwork Mon May 8 13:22:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9716195 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B3E4D60234 for ; Mon, 8 May 2017 13:22:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A6DB626B39 for ; Mon, 8 May 2017 13:22:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 978C928068; Mon, 8 May 2017 13:22:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C535126B39 for ; Mon, 8 May 2017 13:22:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DB8856E229; Mon, 8 May 2017 13:22:52 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from fireflyinternet.com (mail.fireflyinternet.com [109.228.58.192]) by gabe.freedesktop.org (Postfix) with ESMTPS id 307E96E229; Mon, 8 May 2017 13:22:51 +0000 (UTC) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from haswell.alporthouse.com (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 6711879-1500050 for multiple; Mon, 08 May 2017 14:22:30 +0100 Received: by haswell.alporthouse.com (sSMTP sendmail emulation); Mon, 08 May 2017 14:22:29 +0100 From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH] drm/vgem: Convert to a struct drm_device subclass Date: Mon, 8 May 2017 14:22:28 +0100 Message-Id: <20170508132228.9509-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 X-Originating-IP: 78.156.65.138 X-Country: code=GB country="United Kingdom" ip=78.156.65.138 Cc: Daniel Vetter , intel-gfx@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Cc: Laura Abbott Cc: Daniel Vetter Reviewed-by: Laura Abbott --- 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);