drm/mgag200: Replace mapping code with drm_gem_vram_{kmap/kunmap}()
authorThomas Zimmermann <tzimmermann@suse.de>
Wed, 8 May 2019 08:26:26 +0000 (10:26 +0200)
committerGerd Hoffmann <kraxel@redhat.com>
Wed, 15 May 2019 14:17:08 +0000 (16:17 +0200)
The mgag200 driver establishes several memory mappings for frame buffers
and cursors. This patch converts the driver to use the equivalent
drm_gem_vram_kmap() functions. It removes the dependencies on TTM
and cleans up the code.

v4:
* cleanups from checkpatch.pl

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: http://patchwork.freedesktop.org/patch/msgid/20190508082630.15116-17-tzimmermann@suse.de
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
drivers/gpu/drm/mgag200/mgag200_cursor.c
drivers/gpu/drm/mgag200/mgag200_drv.h
drivers/gpu/drm/mgag200/mgag200_fb.c
drivers/gpu/drm/mgag200/mgag200_mode.c

index cca3922f9f678d775734fc4708c2854069650e97..6c1a9d724d851c5499bfd37e5e340981d814e8f5 100644 (file)
@@ -43,6 +43,7 @@ int mga_crtc_cursor_set(struct drm_crtc *crtc,
        struct drm_gem_object *obj;
        struct drm_gem_vram_object *gbo = NULL;
        int ret = 0;
+       u8 *src, *dst;
        unsigned int i, row, col;
        uint32_t colour_set[16];
        uint32_t *next_space = &colour_set[0];
@@ -126,18 +127,17 @@ int mga_crtc_cursor_set(struct drm_crtc *crtc,
                dev_err(&dev->pdev->dev, "failed to reserve user bo\n");
                goto out1;
        }
-       if (!gbo->kmap.virtual) {
-               ret = ttm_bo_kmap(&gbo->bo, 0, gbo->bo.num_pages, &gbo->kmap);
-               if (ret) {
-                       dev_err(&dev->pdev->dev, "failed to kmap user buffer updates\n");
-                       goto out2;
-               }
+       src = drm_gem_vram_kmap(gbo, true, NULL);
+       if (IS_ERR(src)) {
+               ret = PTR_ERR(src);
+               dev_err(&dev->pdev->dev, "failed to kmap user buffer updates\n");
+               goto out2;
        }
 
        memset(&colour_set[0], 0, sizeof(uint32_t)*16);
        /* width*height*4 = 16384 */
        for (i = 0; i < 16384; i += 4) {
-               this_colour = ioread32(gbo->kmap.virtual + i);
+               this_colour = ioread32(src + i);
                /* No transparency */
                if (this_colour>>24 != 0xff &&
                        this_colour>>24 != 0x0) {
@@ -189,21 +189,18 @@ int mga_crtc_cursor_set(struct drm_crtc *crtc,
        }
 
        /* Map up-coming buffer to write colour indices */
-       if (!pixels_prev->kmap.virtual) {
-               ret = ttm_bo_kmap(&pixels_prev->bo, 0,
-                                 pixels_prev->bo.num_pages,
-                                 &pixels_prev->kmap);
-               if (ret) {
-                       dev_err(&dev->pdev->dev, "failed to kmap cursor updates\n");
-                       goto out3;
-               }
+       dst = drm_gem_vram_kmap(pixels_prev, true, NULL);
+       if (IS_ERR(dst)) {
+               ret = PTR_ERR(dst);
+               dev_err(&dev->pdev->dev, "failed to kmap cursor updates\n");
+               goto out3;
        }
 
        /* now write colour indices into hardware cursor buffer */
        for (row = 0; row < 64; row++) {
                memset(&this_row[0], 0, 48);
                for (col = 0; col < 64; col++) {
-                       this_colour = ioread32(gbo->kmap.virtual + 4*(col + 64*row));
+                       this_colour = ioread32(src + 4*(col + 64*row));
                        /* write transparent pixels */
                        if (this_colour>>24 == 0x0) {
                                this_row[47 - col/8] |= 0x80>>(col%8);
@@ -221,7 +218,7 @@ int mga_crtc_cursor_set(struct drm_crtc *crtc,
                                }
                        }
                }
-               memcpy_toio(pixels_prev->kmap.virtual + row*48, &this_row[0], 48);
+               memcpy_toio(dst + row*48, &this_row[0], 48);
        }
 
        /* Program gpu address of cursor buffer */
@@ -247,9 +244,9 @@ int mga_crtc_cursor_set(struct drm_crtc *crtc,
        }
        ret = 0;
 
-       ttm_bo_kunmap(&pixels_prev->kmap);
+       drm_gem_vram_kunmap(pixels_prev);
  out3:
-       ttm_bo_kunmap(&gbo->kmap);
+       drm_gem_vram_kunmap(gbo);
  out2:
        drm_gem_vram_unreserve(gbo);
  out1:
index 16ce6b338dce9b6d27cb385ea17be2ffbc675d81..6180acbca7caff956757d89c8767aa3e220c3a86 100644 (file)
@@ -115,7 +115,6 @@ struct mga_fbdev {
        struct mga_framebuffer mfb;
        void *sysram;
        int size;
-       struct ttm_bo_kmap_obj mapping;
        int x1, y1, x2, y2; /* dirty rect */
        spinlock_t dirty_lock;
 };
index 1bcf0d65868dc4fcdc01cc64e8440e0aa908f243..87217bdce9f898bcc41f28b70a525b6b52f153da 100644 (file)
@@ -27,6 +27,7 @@ static void mga_dirty_update(struct mga_fbdev *mfbdev,
        int src_offset, dst_offset;
        int bpp = mfbdev->mfb.base.format->cpp[0];
        int ret = -EBUSY;
+       u8 *dst;
        bool unmap = false;
        bool store_for_later = false;
        int x2, y2;
@@ -75,26 +76,31 @@ static void mga_dirty_update(struct mga_fbdev *mfbdev,
        mfbdev->x2 = mfbdev->y2 = 0;
        spin_unlock_irqrestore(&mfbdev->dirty_lock, flags);
 
-       if (!gbo->kmap.virtual) {
-               ret = ttm_bo_kmap(&gbo->bo, 0, gbo->bo.num_pages, &gbo->kmap);
-               if (ret) {
+       dst = drm_gem_vram_kmap(gbo, false, NULL);
+       if (IS_ERR(dst)) {
+               DRM_ERROR("failed to kmap fb updates\n");
+               goto out;
+       } else if (!dst) {
+               dst = drm_gem_vram_kmap(gbo, true, NULL);
+               if (IS_ERR(dst)) {
                        DRM_ERROR("failed to kmap fb updates\n");
-                       drm_gem_vram_unreserve(gbo);
-                       return;
+                       goto out;
                }
                unmap = true;
        }
+
        for (i = y; i <= y2; i++) {
                /* assume equal stride for now */
                src_offset = dst_offset =
                        i * mfbdev->mfb.base.pitches[0] + (x * bpp);
-               memcpy_toio(gbo->kmap.virtual + src_offset,
-                           mfbdev->sysram + dst_offset, (x2 - x + 1) * bpp);
-
+               memcpy_toio(dst + dst_offset, mfbdev->sysram + src_offset,
+                           (x2 - x + 1) * bpp);
        }
+
        if (unmap)
-               ttm_bo_kunmap(&gbo->kmap);
+               drm_gem_vram_kunmap(gbo);
 
+out:
        drm_gem_vram_unreserve(gbo);
 }
 
index 26baae5eeb9bf2e27564fb1f3ad1c9fd25f06e64..3098bf5c174496778a31f3c8609eacb7b8728fc4 100644 (file)
@@ -870,6 +870,7 @@ static int mga_crtc_do_set_base(struct drm_crtc *crtc,
        struct drm_gem_vram_object *gbo;
        int ret;
        s64 gpu_addr;
+       void *base;
 
        /* push the previous fb to system ram */
        if (!atomic && fb) {
@@ -902,11 +903,13 @@ static int mga_crtc_do_set_base(struct drm_crtc *crtc,
 
        if (&mdev->mfbdev->mfb == mga_fb) {
                /* if pushing console in kmap it */
-               ret = ttm_bo_kmap(&gbo->bo, 0, gbo->bo.num_pages, &gbo->kmap);
-               if (ret)
+               base = drm_gem_vram_kmap(gbo, true, NULL);
+               if (IS_ERR(base)) {
+                       ret = PTR_ERR(base);
                        DRM_ERROR("failed to kmap fbcon\n");
-
+               }
        }
+
        drm_gem_vram_unreserve(gbo);
 
        mga_set_start_address(crtc, (u32)gpu_addr);