From patchwork Wed Sep 26 19:42:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 10616715 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1BD2B13A4 for ; Wed, 26 Sep 2018 19:43:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0ABEE280FC for ; Wed, 26 Sep 2018 19:43:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F34B1284A3; Wed, 26 Sep 2018 19:43:23 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 67867280FC for ; Wed, 26 Sep 2018 19:43:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 036846E4BC; Wed, 26 Sep 2018 19:42:33 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by gabe.freedesktop.org (Postfix) with ESMTPS id E6C966E4B6 for ; Wed, 26 Sep 2018 19:42:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8436F30820DD; Wed, 26 Sep 2018 19:42:30 +0000 (UTC) Received: from shalem.localdomain.com (ovpn-116-104.ams2.redhat.com [10.36.116.104]) by smtp.corp.redhat.com (Postfix) with ESMTP id 66B2410021B2; Wed, 26 Sep 2018 19:42:29 +0000 (UTC) From: Hans de Goede To: Greg Kroah-Hartman Subject: [PATCH 15/15] staging: vboxvideo: Use more drm_fb_helper functions Date: Wed, 26 Sep 2018 21:42:06 +0200 Message-Id: <20180926194206.23517-16-hdegoede@redhat.com> In-Reply-To: <20180926194206.23517-1-hdegoede@redhat.com> References: <20180926194206.23517-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 26 Sep 2018 19:42:30 +0000 (UTC) X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devel@driverdev.osuosl.org, Hans de Goede , Michael Thayer , dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Store fbhelper and afb struct directly in vbox_private and use drm_fb_helper_fbdev_setup to replace vbox_fbdev_init, note we cannot use drm_fb_helper_fbdev_teardown since we use a private framebuffer for the fbdev. And replace vbox_driver_lastclose with drm_fb_helper_lastclose. Signed-off-by: Hans de Goede --- drivers/staging/vboxvideo/vbox_drv.c | 10 +++- drivers/staging/vboxvideo/vbox_drv.h | 28 +++-------- drivers/staging/vboxvideo/vbox_fb.c | 70 ++++++--------------------- drivers/staging/vboxvideo/vbox_main.c | 12 ----- drivers/staging/vboxvideo/vbox_mode.c | 2 +- 5 files changed, 31 insertions(+), 91 deletions(-) diff --git a/drivers/staging/vboxvideo/vbox_drv.c b/drivers/staging/vboxvideo/vbox_drv.c index c3e14107da0d..257030460fb6 100644 --- a/drivers/staging/vboxvideo/vbox_drv.c +++ b/drivers/staging/vboxvideo/vbox_drv.c @@ -49,6 +49,10 @@ static const struct pci_device_id pciidlist[] = { }; MODULE_DEVICE_TABLE(pci, pciidlist); +static struct drm_fb_helper_funcs vbox_fb_helper_funcs = { + .fb_probe = vboxfb_create, +}; + static int vbox_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { struct vbox_private *vbox; @@ -92,7 +96,9 @@ static int vbox_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if (ret) goto err_mode_fini; - ret = vbox_fbdev_init(vbox); + ret = drm_fb_helper_fbdev_setup(&vbox->ddev, &vbox->fb_helper, + &vbox_fb_helper_funcs, 32, + vbox->num_crtcs); if (ret) goto err_irq_fini; @@ -257,7 +263,7 @@ static struct drm_driver driver = { DRIVER_PRIME | DRIVER_ATOMIC, .dev_priv_size = 0, - .lastclose = vbox_driver_lastclose, + .lastclose = drm_fb_helper_lastclose, .master_set = vbox_master_set, .master_drop = vbox_master_drop, diff --git a/drivers/staging/vboxvideo/vbox_drv.h b/drivers/staging/vboxvideo/vbox_drv.h index 9cc20c182df1..73395a7536c5 100644 --- a/drivers/staging/vboxvideo/vbox_drv.h +++ b/drivers/staging/vboxvideo/vbox_drv.h @@ -72,11 +72,16 @@ sizeof(struct hgsmi_host_flags)) #define HOST_FLAGS_OFFSET GUEST_HEAP_USABLE_SIZE -struct vbox_fbdev; +struct vbox_framebuffer { + struct drm_framebuffer base; + struct drm_gem_object *obj; +}; struct vbox_private { /* Must be first; or we must define our own release callback */ struct drm_device ddev; + struct drm_fb_helper fb_helper; + struct vbox_framebuffer afb; u8 __iomem *guest_heap; u8 __iomem *vbva_buffers; @@ -91,8 +96,6 @@ struct vbox_private { /** Array of structures for receiving mode hints. */ struct vbva_modehint *last_mode_hints; - struct vbox_fbdev *fbdev; - int fb_mtrr; struct { @@ -122,8 +125,6 @@ struct vbox_private { #undef CURSOR_PIXEL_COUNT #undef CURSOR_DATA_SIZE -void vbox_driver_lastclose(struct drm_device *dev); - struct vbox_gem_object; struct vbox_connector { @@ -171,20 +172,6 @@ struct vbox_encoder { struct drm_encoder base; }; -struct vbox_framebuffer { - struct drm_framebuffer base; - struct drm_gem_object *obj; -}; - -struct vbox_fbdev { - struct drm_fb_helper helper; - struct vbox_framebuffer afb; - int size; - struct ttm_bo_kmap_obj mapping; - int x1, y1, x2, y2; /* dirty rect */ - spinlock_t dirty_lock; -}; - #define to_vbox_crtc(x) container_of(x, struct vbox_crtc, base) #define to_vbox_connector(x) container_of(x, struct vbox_connector, base) #define to_vbox_encoder(x) container_of(x, struct vbox_encoder, base) @@ -212,7 +199,8 @@ int vbox_framebuffer_init(struct vbox_private *vbox, const struct DRM_MODE_FB_CMD *mode_cmd, struct drm_gem_object *obj); -int vbox_fbdev_init(struct vbox_private *vbox); +int vboxfb_create(struct drm_fb_helper *helper, + struct drm_fb_helper_surface_size *sizes); void vbox_fbdev_fini(struct vbox_private *vbox); struct vbox_bo { diff --git a/drivers/staging/vboxvideo/vbox_fb.c b/drivers/staging/vboxvideo/vbox_fb.c index 8a9d56762659..ee25f3a03934 100644 --- a/drivers/staging/vboxvideo/vbox_fb.c +++ b/drivers/staging/vboxvideo/vbox_fb.c @@ -66,13 +66,11 @@ static struct fb_ops vboxfb_ops = { .fb_debug_leave = drm_fb_helper_debug_leave, }; -static int vboxfb_create(struct drm_fb_helper *helper, - struct drm_fb_helper_surface_size *sizes) +int vboxfb_create(struct drm_fb_helper *helper, + struct drm_fb_helper_surface_size *sizes) { - struct vbox_fbdev *fbdev = - container_of(helper, struct vbox_fbdev, helper); - struct vbox_private *vbox = container_of(fbdev->helper.dev, - struct vbox_private, ddev); + struct vbox_private *vbox = + container_of(helper, struct vbox_private, fb_helper); struct pci_dev *pdev = vbox->ddev.pdev; struct DRM_MODE_FB_CMD mode_cmd; struct drm_framebuffer *fb; @@ -98,7 +96,7 @@ static int vboxfb_create(struct drm_fb_helper *helper, return ret; } - ret = vbox_framebuffer_init(vbox, &fbdev->afb, &mode_cmd, gobj); + ret = vbox_framebuffer_init(vbox, &vbox->afb, &mode_cmd, gobj); if (ret) return ret; @@ -117,12 +115,10 @@ static int vboxfb_create(struct drm_fb_helper *helper, if (IS_ERR(info->screen_base)) return PTR_ERR(info->screen_base); - info->par = fbdev; + info->par = helper; - fbdev->size = size; - - fb = &fbdev->afb.base; - fbdev->helper.fb = fb; + fb = &vbox->afb.base; + helper->fb = fb; strcpy(info->fix.id, "vboxdrmfb"); @@ -142,7 +138,7 @@ static int vboxfb_create(struct drm_fb_helper *helper, info->apertures->ranges[0].size = pci_resource_len(pdev, 0); drm_fb_helper_fill_fix(info, fb->pitches[0], fb->format->depth); - drm_fb_helper_fill_var(info, &fbdev->helper, sizes->fb_width, + drm_fb_helper_fill_var(info, helper, sizes->fb_width, sizes->fb_height); gpu_addr = vbox_bo_gpu_offset(bo); @@ -161,21 +157,16 @@ static int vboxfb_create(struct drm_fb_helper *helper, return 0; } -static struct drm_fb_helper_funcs vbox_fb_helper_funcs = { - .fb_probe = vboxfb_create, -}; - void vbox_fbdev_fini(struct vbox_private *vbox) { - struct vbox_fbdev *fbdev = vbox->fbdev; - struct vbox_framebuffer *afb = &fbdev->afb; + struct vbox_framebuffer *afb = &vbox->afb; #ifdef CONFIG_DRM_KMS_FB_HELPER - if (fbdev->helper.fbdev && fbdev->helper.fbdev->fbdefio) - fb_deferred_io_cleanup(fbdev->helper.fbdev); + if (vbox->fb_helper.fbdev && vbox->fb_helper.fbdev->fbdefio) + fb_deferred_io_cleanup(vbox->fb_helper.fbdev); #endif - drm_fb_helper_unregister_fbi(&fbdev->helper); + drm_fb_helper_unregister_fbi(&vbox->fb_helper); if (afb->obj) { struct vbox_bo *bo = gem_to_vbox_bo(afb->obj); @@ -188,41 +179,8 @@ void vbox_fbdev_fini(struct vbox_private *vbox) drm_gem_object_put_unlocked(afb->obj); afb->obj = NULL; } - drm_fb_helper_fini(&fbdev->helper); + drm_fb_helper_fini(&vbox->fb_helper); drm_framebuffer_unregister_private(&afb->base); drm_framebuffer_cleanup(&afb->base); } - -int vbox_fbdev_init(struct vbox_private *vbox) -{ - struct drm_device *dev = &vbox->ddev; - struct vbox_fbdev *fbdev; - int ret; - - fbdev = devm_kzalloc(dev->dev, sizeof(*fbdev), GFP_KERNEL); - if (!fbdev) - return -ENOMEM; - - vbox->fbdev = fbdev; - spin_lock_init(&fbdev->dirty_lock); - - drm_fb_helper_prepare(dev, &fbdev->helper, &vbox_fb_helper_funcs); - ret = drm_fb_helper_init(dev, &fbdev->helper, vbox->num_crtcs); - if (ret) - return ret; - - ret = drm_fb_helper_single_add_all_connectors(&fbdev->helper); - if (ret) - goto err_fini; - - ret = drm_fb_helper_initial_config(&fbdev->helper, 32); - if (ret) - goto err_fini; - - return 0; - -err_fini: - drm_fb_helper_fini(&fbdev->helper); - return ret; -} diff --git a/drivers/staging/vboxvideo/vbox_main.c b/drivers/staging/vboxvideo/vbox_main.c index 3b82d483ab51..7466c1103ff6 100644 --- a/drivers/staging/vboxvideo/vbox_main.c +++ b/drivers/staging/vboxvideo/vbox_main.c @@ -322,18 +322,6 @@ void vbox_hw_fini(struct vbox_private *vbox) pci_iounmap(vbox->ddev.pdev, vbox->guest_heap); } -/** - * @note this is described in the DRM framework documentation. AST does not - * have it, but we get an oops on driver unload if it is not present. - */ -void vbox_driver_lastclose(struct drm_device *dev) -{ - struct vbox_private *vbox = dev->dev_private; - - if (vbox->fbdev) - drm_fb_helper_restore_fbdev_mode_unlocked(&vbox->fbdev->helper); -} - int vbox_gem_create(struct vbox_private *vbox, u32 size, bool iskernel, struct drm_gem_object **obj) { diff --git a/drivers/staging/vboxvideo/vbox_mode.c b/drivers/staging/vboxvideo/vbox_mode.c index 756544b53600..042e4f384df9 100644 --- a/drivers/staging/vboxvideo/vbox_mode.c +++ b/drivers/staging/vboxvideo/vbox_mode.c @@ -153,7 +153,7 @@ static bool vbox_set_up_input_mapping(struct vbox_private *vbox) if (!fb1) { fb1 = fb; - if (to_vbox_framebuffer(fb1) == &vbox->fbdev->afb) + if (to_vbox_framebuffer(fb1) == &vbox->afb) break; } else if (fb != fb1) { single_framebuffer = false;