[PATCH v2 3/3] drm/mgag200: Map fbdev framebuffer while it's being displayed

Deucher, Alexander Alexander.Deucher at amd.com
Wed Sep 11 16:13:31 UTC 2019

Please use C style comments rather than C++.

From: Thomas Zimmermann <tzimmermann at suse.de>
Sent: Wednesday, September 4, 2019 7:56 AM
To: daniel at ffwll.ch <daniel at ffwll.ch>; noralf at tronnes.org <noralf at tronnes.org>; airlied at linux.ie <airlied at linux.ie>; rong.a.chen at intel.com <rong.a.chen at intel.com>; feng.tang at intel.com <feng.tang at intel.com>; ying.huang at intel.com <ying.huang at intel.com>; sean at poorly.run <sean at poorly.run>; maxime.ripard at bootlin.com <maxime.ripard at bootlin.com>; maarten.lankhorst at linux.intel.com <maarten.lankhorst at linux.intel.com>; dave at stgolabs.net <dave at stgolabs.net>
Cc: dri-devel at lists.freedesktop.org <dri-devel at lists.freedesktop.org>; Thomas Zimmermann <tzimmermann at suse.de>; Dave Airlie <airlied at redhat.com>; Greg Kroah-Hartman <gregkh at linuxfoundation.org>; Thomas Gleixner <tglx at linutronix.de>; Gerd Hoffmann <kraxel at redhat.com>; Deucher, Alexander <Alexander.Deucher at amd.com>; Koenig, Christian <Christian.Koenig at amd.com>; Sam Ravnborg <sam at ravnborg.org>; Daniel Vetter <daniel.vetter at ffwll.ch>; Huang, Ray <Ray.Huang at amd.com>; Bartlomiej Zolnierkiewicz <b.zolnierkie at samsung.com>; Michał Mirosław <mirq-linux at rere.qmqm.pl>; Armijn Hemel <armijn at tjaldur.nl>
Subject: [PATCH v2 3/3] drm/mgag200: Map fbdev framebuffer while it's being displayed

The generic fbdev emulation will map and unmap the framebuffer's memory
if required. As consoles are most often updated while being on screen,
we map the fbdev buffer while it's being displayed. This avoids frequent
map/unmap operations in the fbdev code. The original fbdev code in mgag200
used the same trick to improve performance.

        * fix typo in comment

Signed-off-by: Thomas Zimmermann <tzimmermann at suse.de>
Fixes: 90f479ae51af ("drm/mgag200: Replace struct mga_fbdev with generic framebuffer emulation")
Cc: Thomas Zimmermann <tzimmermann at suse.de>
Cc: Noralf Trønnes <noralf at tronnes.org>
Cc: Dave Airlie <airlied at redhat.com>
Cc: Greg Kroah-Hartman <gregkh at linuxfoundation.org>
Cc: Thomas Gleixner <tglx at linutronix.de>
Cc: Gerd Hoffmann <kraxel at redhat.com>
Cc: Alex Deucher <alexander.deucher at amd.com>
Cc: "Christian König" <christian.koenig at amd.com>
Cc: Sam Ravnborg <sam at ravnborg.org>
Cc: Daniel Vetter <daniel.vetter at ffwll.ch>
Cc: Huang Rui <ray.huang at amd.com>
Cc: Bartlomiej Zolnierkiewicz <b.zolnierkie at samsung.com>
Cc: "Michał Mirosław" <mirq-linux at rere.qmqm.pl>
Cc: Armijn Hemel <armijn at tjaldur.nl>
Cc: Rong Chen <rong.a.chen at intel.com>
Cc: Feng Tang <feng.tang at intel.com>
Cc: Huang Ying <ying.huang at intel.com>
Cc: Davidlohr Bueso <dave at stgolabs.net>
 drivers/gpu/drm/mgag200/mgag200_mode.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/gpu/drm/mgag200/mgag200_mode.c b/drivers/gpu/drm/mgag200/mgag200_mode.c
index 5e778b5f1a10..7b95c59341f5 100644
--- a/drivers/gpu/drm/mgag200/mgag200_mode.c
+++ b/drivers/gpu/drm/mgag200/mgag200_mode.c
@@ -860,13 +860,20 @@ static int mga_crtc_do_set_base(struct drm_crtc *crtc,
                                 struct drm_framebuffer *fb,
                                 int x, int y, int atomic)
+       struct drm_fb_helper *fb_helper = crtc->dev->fb_helper;
         struct drm_gem_vram_object *gbo;
         int ret;
         s64 gpu_addr;
+       void *base;

         if (!atomic && fb) {
                 gbo = drm_gem_vram_of_gem(fb->obj[0]);
+               // Unmap fbdev FB if it's not being displayed
+               // any longer.
+               if (fb == fb_helper->buffer->fb)
+                       drm_gem_vram_kunmap(gbo);

         gbo = drm_gem_vram_of_gem(crtc->primary->fb->obj[0]);
@@ -882,6 +889,14 @@ static int mga_crtc_do_set_base(struct drm_crtc *crtc,

         mga_set_start_address(crtc, (u32)gpu_addr);

+       // Map fbdev FB while it's being displayed. This avoids frequent
+       // mapping and unmapping within the fbdev code.
+       if (crtc->primary->fb == fb_helper->buffer->fb) {
+               base = drm_gem_vram_kmap(gbo, true, NULL);
+               if (IS_ERR(base))
+                       DRM_ERROR("failed to kmap fbcon\n");
+       }
         return 0;

@@ -1403,9 +1418,14 @@ static void mga_crtc_disable(struct drm_crtc *crtc)
         mga_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
         if (crtc->primary->fb) {
+               struct drm_fb_helper *fb_helper = crtc->dev->fb_helper;
                 struct drm_framebuffer *fb = crtc->primary->fb;
                 struct drm_gem_vram_object *gbo =
+               // Unmap if it's the fbdev FB.
+               if (fb == fb_helper->buffer->fb)
+                       drm_gem_vram_kunmap(gbo);
         crtc->primary->fb = NULL;

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/dri-devel/attachments/20190911/88d60b96/attachment.html>

More information about the dri-devel mailing list