From patchwork Mon Aug 28 17:17:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Noralf_Tr=C3=B8nnes?= X-Patchwork-Id: 9925891 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 5BDB060329 for ; Mon, 28 Aug 2017 17:18:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D00128767 for ; Mon, 28 Aug 2017 17:18:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 422822876A; Mon, 28 Aug 2017 17:18:33 +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 853FB28767 for ; Mon, 28 Aug 2017 17:18:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 110A66E0A6; Mon, 28 Aug 2017 17:18:27 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from smtp.domeneshop.no (smtp.domeneshop.no [IPv6:2a01:5b40:0:3005::1]) by gabe.freedesktop.org (Postfix) with ESMTPS id 77BD46E088 for ; Mon, 28 Aug 2017 17:18:18 +0000 (UTC) Received: from 211.81-166-168.customer.lyse.net ([81.166.168.211]:40244 helo=localhost.localdomain) by smtp.domeneshop.no with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1dmNg0-0005fe-Gk; Mon, 28 Aug 2017 19:18:16 +0200 From: =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= To: dri-devel@lists.freedesktop.org Subject: [PATCH 3/6] drm/fb-cma-helper: Support device unplug Date: Mon, 28 Aug 2017 19:17:45 +0200 Message-Id: <1503940668-25883-4-git-send-email-noralf@tronnes.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503940668-25883-1-git-send-email-noralf@tronnes.org> References: <1503940668-25883-1-git-send-email-noralf@tronnes.org> MIME-Version: 1.0 Cc: daniel.vetter@ffwll.ch, laurent.pinchart@ideasonboard.com, david@lechnology.com 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add drm_fbdev_cma_dev_unplug() and use the drm_fb_helper device unplug support. Pin driver module on fb_open(). Cc: Laurent Pinchart Signed-off-by: Noralf Trønnes --- drivers/gpu/drm/drm_fb_cma_helper.c | 139 +++++++++++++++++------------------- include/drm/drm_fb_cma_helper.h | 1 + 2 files changed, 68 insertions(+), 72 deletions(-) diff --git a/drivers/gpu/drm/drm_fb_cma_helper.c b/drivers/gpu/drm/drm_fb_cma_helper.c index f2ee883..2b044be 100644 --- a/drivers/gpu/drm/drm_fb_cma_helper.c +++ b/drivers/gpu/drm/drm_fb_cma_helper.c @@ -25,8 +25,6 @@ #include #include -#define DEFAULT_FBDEFIO_DELAY_MS 50 - struct drm_fbdev_cma { struct drm_fb_helper fb_helper; const struct drm_framebuffer_funcs *fb_funcs; @@ -238,6 +236,34 @@ int drm_fb_cma_debugfs_show(struct seq_file *m, void *arg) EXPORT_SYMBOL_GPL(drm_fb_cma_debugfs_show); #endif +static int drm_fbdev_cma_fb_open(struct fb_info *info, int user) +{ + struct drm_fb_helper *fb_helper = info->par; + struct drm_device *dev = fb_helper->dev; + + /* + * The fb_ops definition resides in this library, meaning fb_open() + * will take a ref on the library instead of the driver. Make sure the + * driver module is pinned. Skip fbcon (user==0) since it can detach + * itself on unregister_framebuffer(). + */ + if (user && !try_module_get(dev->driver->fops->owner)) + return -ENODEV; + + return 0; +} + +static int drm_fbdev_cma_fb_release(struct fb_info *info, int user) +{ + struct drm_fb_helper *fb_helper = info->par; + struct drm_device *dev = fb_helper->dev; + + if (user) + module_put(dev->driver->fops->owner); + + return 0; +} + static int drm_fb_cma_mmap(struct fb_info *info, struct vm_area_struct *vma) { return dma_mmap_writecombine(info->device, vma, info->screen_base, @@ -247,10 +273,13 @@ static int drm_fb_cma_mmap(struct fb_info *info, struct vm_area_struct *vma) static struct fb_ops drm_fbdev_cma_ops = { .owner = THIS_MODULE, DRM_FB_HELPER_DEFAULT_OPS, + .fb_open = drm_fbdev_cma_fb_open, + .fb_release = drm_fbdev_cma_fb_release, .fb_fillrect = drm_fb_helper_sys_fillrect, .fb_copyarea = drm_fb_helper_sys_copyarea, .fb_imageblit = drm_fb_helper_sys_imageblit, .fb_mmap = drm_fb_cma_mmap, + .fb_destroy = drm_fb_helper_fb_destroy, }; static int drm_fbdev_cma_deferred_io_mmap(struct fb_info *info, @@ -262,52 +291,26 @@ static int drm_fbdev_cma_deferred_io_mmap(struct fb_info *info, return 0; } -static int drm_fbdev_cma_defio_init(struct fb_info *fbi, +static int drm_fbdev_cma_defio_init(struct drm_fb_helper *helper, struct drm_gem_cma_object *cma_obj) { - struct fb_deferred_io *fbdefio; - struct fb_ops *fbops; + struct fb_info *fbi = helper->fbdev; + int ret; - /* - * Per device structures are needed because: - * fbops: fb_deferred_io_cleanup() clears fbops.fb_mmap - * fbdefio: individual delays - */ - fbdefio = kzalloc(sizeof(*fbdefio), GFP_KERNEL); - fbops = kzalloc(sizeof(*fbops), GFP_KERNEL); - if (!fbdefio || !fbops) { - kfree(fbdefio); - kfree(fbops); - return -ENOMEM; - } + ret = drm_fb_helper_defio_init(helper); + if (ret) + return ret; /* can't be offset from vaddr since dirty() uses cma_obj */ fbi->screen_buffer = cma_obj->vaddr; /* fb_deferred_io_fault() needs a physical address */ fbi->fix.smem_start = page_to_phys(virt_to_page(fbi->screen_buffer)); - *fbops = *fbi->fbops; - fbi->fbops = fbops; - - fbdefio->delay = msecs_to_jiffies(DEFAULT_FBDEFIO_DELAY_MS); - fbdefio->deferred_io = drm_fb_helper_deferred_io; - fbi->fbdefio = fbdefio; - fb_deferred_io_init(fbi); fbi->fbops->fb_mmap = drm_fbdev_cma_deferred_io_mmap; return 0; } -static void drm_fbdev_cma_defio_fini(struct fb_info *fbi) -{ - if (!fbi->fbdefio) - return; - - fb_deferred_io_cleanup(fbi); - kfree(fbi->fbdefio); - kfree(fbi->fbops); -} - static int drm_fbdev_cma_create(struct drm_fb_helper *helper, struct drm_fb_helper_surface_size *sizes) @@ -365,7 +368,7 @@ drm_fbdev_cma_create(struct drm_fb_helper *helper, fbi->fix.smem_len = size; if (fbdev_cma->fb_funcs->dirty) { - ret = drm_fbdev_cma_defio_init(fbi, obj); + ret = drm_fbdev_cma_defio_init(helper, obj); if (ret) goto err_cma_destroy; } @@ -399,7 +402,6 @@ struct drm_fbdev_cma *drm_fbdev_cma_init_with_funcs(struct drm_device *dev, const struct drm_framebuffer_funcs *funcs) { struct drm_fbdev_cma *fbdev_cma; - struct drm_fb_helper *helper; int ret; fbdev_cma = kzalloc(sizeof(*fbdev_cma), GFP_KERNEL); @@ -409,37 +411,15 @@ struct drm_fbdev_cma *drm_fbdev_cma_init_with_funcs(struct drm_device *dev, } fbdev_cma->fb_funcs = funcs; - helper = &fbdev_cma->fb_helper; - - drm_fb_helper_prepare(dev, helper, &drm_fb_cma_helper_funcs); - - ret = drm_fb_helper_init(dev, helper, max_conn_count); - if (ret < 0) { - dev_err(dev->dev, "Failed to initialize drm fb helper.\n"); - goto err_free; - } - - ret = drm_fb_helper_single_add_all_connectors(helper); - if (ret < 0) { - dev_err(dev->dev, "Failed to add connectors.\n"); - goto err_drm_fb_helper_fini; - - } - - ret = drm_fb_helper_initial_config(helper, preferred_bpp); - if (ret < 0) { - dev_err(dev->dev, "Failed to set initial hw configuration.\n"); - goto err_drm_fb_helper_fini; + ret = drm_fb_helper_simple_init(dev, &fbdev_cma->fb_helper, + preferred_bpp, max_conn_count, + &drm_fb_cma_helper_funcs); + if (ret) { + kfree(fbdev_cma); + return ERR_PTR(ret); } return fbdev_cma; - -err_drm_fb_helper_fini: - drm_fb_helper_fini(helper); -err_free: - kfree(fbdev_cma); - - return ERR_PTR(ret); } EXPORT_SYMBOL_GPL(drm_fbdev_cma_init_with_funcs); @@ -468,17 +448,15 @@ EXPORT_SYMBOL_GPL(drm_fbdev_cma_init); /** * drm_fbdev_cma_fini() - Free drm_fbdev_cma struct * @fbdev_cma: The drm_fbdev_cma struct + * + * This function calls drm_fb_helper_simple_fini() and frees @fbdev_cma. + * + * Don't use this function together with drm_fbdev_cma_dev_unplug(). */ void drm_fbdev_cma_fini(struct drm_fbdev_cma *fbdev_cma) { - drm_fb_helper_unregister_fbi(&fbdev_cma->fb_helper); - if (fbdev_cma->fb_helper.fbdev) - drm_fbdev_cma_defio_fini(fbdev_cma->fb_helper.fbdev); - - if (fbdev_cma->fb_helper.fb) - drm_framebuffer_remove(fbdev_cma->fb_helper.fb); - - drm_fb_helper_fini(&fbdev_cma->fb_helper); + if (fbdev_cma) + drm_fb_helper_simple_fini(&fbdev_cma->fb_helper); kfree(fbdev_cma); } EXPORT_SYMBOL_GPL(drm_fbdev_cma_fini); @@ -542,3 +520,20 @@ void drm_fbdev_cma_set_suspend_unlocked(struct drm_fbdev_cma *fbdev_cma, state); } EXPORT_SYMBOL(drm_fbdev_cma_set_suspend_unlocked); + +/** + * drm_fbdev_cma_dev_unplug - wrapper around drm_fb_helper_dev_unplug + * @fbdev_cma: The drm_fbdev_cma struct, may be NULL + * + * This unplugs the fbdev emulation for a hotpluggable DRM device. See + * drm_fb_helper_dev_unplug() for details. + * + * Drivers must call drm_mode_config_cleanup() and free @fbdev_cma in their + * &drm_driver->release callback. + */ +void drm_fbdev_cma_dev_unplug(struct drm_fbdev_cma *fbdev_cma) +{ + if (fbdev_cma) + drm_fb_helper_dev_unplug(&fbdev_cma->fb_helper); +} +EXPORT_SYMBOL(drm_fbdev_cma_dev_unplug); diff --git a/include/drm/drm_fb_cma_helper.h b/include/drm/drm_fb_cma_helper.h index a323781..a6aafae 100644 --- a/include/drm/drm_fb_cma_helper.h +++ b/include/drm/drm_fb_cma_helper.h @@ -27,6 +27,7 @@ void drm_fbdev_cma_hotplug_event(struct drm_fbdev_cma *fbdev_cma); void drm_fbdev_cma_set_suspend(struct drm_fbdev_cma *fbdev_cma, bool state); void drm_fbdev_cma_set_suspend_unlocked(struct drm_fbdev_cma *fbdev_cma, bool state); +void drm_fbdev_cma_dev_unplug(struct drm_fbdev_cma *fbdev_cma); void drm_fb_cma_destroy(struct drm_framebuffer *fb); int drm_fb_cma_create_handle(struct drm_framebuffer *fb,