drm/amdgpu: Move GEM BO to drm_framebuffer
authorDaniel Stone <daniels@collabora.com>
Fri, 30 Mar 2018 14:11:38 +0000 (15:11 +0100)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 11 Apr 2018 18:07:56 +0000 (13:07 -0500)
Since drm_framebuffer can now store GEM objects directly, place them
there rather than in our own subclass. As this makes the framebuffer
create_handle and destroy functions the same as the GEM framebuffer
helper, we can reuse those.

Acked-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Daniel Stone <daniels@collabora.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: David (ChunMing) Zhou <David1.Zhou@amd.com>
Cc: amd-gfx@lists.freedesktop.org
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h
drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
drivers/gpu/drm/amd/amdgpu/dce_virtual.c
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

index a53926580b3d0329fbe4a3bddbe973e6f2bb7e70..e0d6b1ddd2134661d4d0eb7312cd71ff0057af21 100644 (file)
@@ -2541,7 +2541,7 @@ int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon)
        /* unpin the front buffers and cursors */
        list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
                struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
-               struct amdgpu_framebuffer *rfb = to_amdgpu_framebuffer(crtc->primary->fb);
+               struct drm_framebuffer *fb = crtc->primary->fb;
                struct amdgpu_bo *robj;
 
                if (amdgpu_crtc->cursor_bo) {
@@ -2553,10 +2553,10 @@ int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon)
                        }
                }
 
-               if (rfb == NULL || rfb->obj == NULL) {
+               if (fb == NULL || fb->obj[0] == NULL) {
                        continue;
                }
-               robj = gem_to_amdgpu_bo(rfb->obj);
+               robj = gem_to_amdgpu_bo(fb->obj[0]);
                /* don't unpin kernel fb objects */
                if (!amdgpu_fbdev_robj_is_fb(adev, robj)) {
                        r = amdgpu_bo_reserve(robj, true);
index 93f700ab1bfbfbd75b29757d9acbff329e88e898..b83ae998fe2764fd54361f0103a80190af4ed30a 100644 (file)
@@ -35,6 +35,7 @@
 #include <linux/pm_runtime.h>
 #include <drm/drm_crtc_helper.h>
 #include <drm/drm_edid.h>
+#include <drm/drm_gem_framebuffer_helper.h>
 #include <drm/drm_fb_helper.h>
 
 static void amdgpu_display_flip_callback(struct dma_fence *f,
@@ -151,8 +152,6 @@ int amdgpu_display_crtc_page_flip_target(struct drm_crtc *crtc,
        struct drm_device *dev = crtc->dev;
        struct amdgpu_device *adev = dev->dev_private;
        struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
-       struct amdgpu_framebuffer *old_amdgpu_fb;
-       struct amdgpu_framebuffer *new_amdgpu_fb;
        struct drm_gem_object *obj;
        struct amdgpu_flip_work *work;
        struct amdgpu_bo *new_abo;
@@ -174,15 +173,13 @@ int amdgpu_display_crtc_page_flip_target(struct drm_crtc *crtc,
        work->async = (page_flip_flags & DRM_MODE_PAGE_FLIP_ASYNC) != 0;
 
        /* schedule unpin of the old buffer */
-       old_amdgpu_fb = to_amdgpu_framebuffer(crtc->primary->fb);
-       obj = old_amdgpu_fb->obj;
+       obj = crtc->primary->fb->obj[0];
 
        /* take a reference to the old object */
        work->old_abo = gem_to_amdgpu_bo(obj);
        amdgpu_bo_ref(work->old_abo);
 
-       new_amdgpu_fb = to_amdgpu_framebuffer(fb);
-       obj = new_amdgpu_fb->obj;
+       obj = fb->obj[0];
        new_abo = gem_to_amdgpu_bo(obj);
 
        /* pin the new buffer */
@@ -482,28 +479,9 @@ bool amdgpu_display_ddc_probe(struct amdgpu_connector *amdgpu_connector,
        return true;
 }
 
-static void amdgpu_display_user_framebuffer_destroy(struct drm_framebuffer *fb)
-{
-       struct amdgpu_framebuffer *amdgpu_fb = to_amdgpu_framebuffer(fb);
-
-       drm_gem_object_put_unlocked(amdgpu_fb->obj);
-       drm_framebuffer_cleanup(fb);
-       kfree(amdgpu_fb);
-}
-
-static int amdgpu_display_user_framebuffer_create_handle(
-                       struct drm_framebuffer *fb,
-                       struct drm_file *file_priv,
-                       unsigned int *handle)
-{
-       struct amdgpu_framebuffer *amdgpu_fb = to_amdgpu_framebuffer(fb);
-
-       return drm_gem_handle_create(file_priv, amdgpu_fb->obj, handle);
-}
-
 static const struct drm_framebuffer_funcs amdgpu_fb_funcs = {
-       .destroy = amdgpu_display_user_framebuffer_destroy,
-       .create_handle = amdgpu_display_user_framebuffer_create_handle,
+       .destroy = drm_gem_fb_destroy,
+       .create_handle = drm_gem_fb_create_handle,
 };
 
 uint32_t amdgpu_display_framebuffer_domains(struct amdgpu_device *adev)
@@ -526,11 +504,11 @@ int amdgpu_display_framebuffer_init(struct drm_device *dev,
                                    struct drm_gem_object *obj)
 {
        int ret;
-       rfb->obj = obj;
+       rfb->base.obj[0] = obj;
        drm_helper_mode_fill_fb_struct(dev, &rfb->base, mode_cmd);
        ret = drm_framebuffer_init(dev, &rfb->base, &amdgpu_fb_funcs);
        if (ret) {
-               rfb->obj = NULL;
+               rfb->base.obj[0] = NULL;
                return ret;
        }
        return 0;
index 12063019751bf4e5221834b046144d2482b5d1c7..ff89e84b34ce89cc8ee262ca2b0608a049fb67b4 100644 (file)
@@ -292,9 +292,9 @@ static int amdgpu_fbdev_destroy(struct drm_device *dev, struct amdgpu_fbdev *rfb
 
        drm_fb_helper_unregister_fbi(&rfbdev->helper);
 
-       if (rfb->obj) {
-               amdgpufb_destroy_pinned_object(rfb->obj);
-               rfb->obj = NULL;
+       if (rfb->base.obj[0]) {
+               amdgpufb_destroy_pinned_object(rfb->base.obj[0]);
+               rfb->base.obj[0] = NULL;
                drm_framebuffer_unregister_private(&rfb->base);
                drm_framebuffer_cleanup(&rfb->base);
        }
@@ -377,7 +377,7 @@ int amdgpu_fbdev_total_size(struct amdgpu_device *adev)
        if (!adev->mode_info.rfbdev)
                return 0;
 
-       robj = gem_to_amdgpu_bo(adev->mode_info.rfbdev->rfb.obj);
+       robj = gem_to_amdgpu_bo(adev->mode_info.rfbdev->rfb.base.obj[0]);
        size += amdgpu_bo_size(robj);
        return size;
 }
@@ -386,7 +386,7 @@ bool amdgpu_fbdev_robj_is_fb(struct amdgpu_device *adev, struct amdgpu_bo *robj)
 {
        if (!adev->mode_info.rfbdev)
                return false;
-       if (robj == gem_to_amdgpu_bo(adev->mode_info.rfbdev->rfb.obj))
+       if (robj == gem_to_amdgpu_bo(adev->mode_info.rfbdev->rfb.base.obj[0]))
                return true;
        return false;
 }
index d6416ee52e3216a9ee8fa024cbeb02c073007860..b9e9e8b02fb756a0d7291c605353d59cd228826e 100644 (file)
@@ -308,7 +308,6 @@ struct amdgpu_display_funcs {
 
 struct amdgpu_framebuffer {
        struct drm_framebuffer base;
-       struct drm_gem_object *obj;
 
        /* caching for later use */
        uint64_t address;
index 452f88ea46a2ed52fa08ccb78497e0f231498c0d..ada241bfeee96c743c93cbfad8f567eaf1eaf6ac 100644 (file)
@@ -1823,7 +1823,6 @@ static int dce_v10_0_crtc_do_set_base(struct drm_crtc *crtc,
        struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
        struct drm_device *dev = crtc->dev;
        struct amdgpu_device *adev = dev->dev_private;
-       struct amdgpu_framebuffer *amdgpu_fb;
        struct drm_framebuffer *target_fb;
        struct drm_gem_object *obj;
        struct amdgpu_bo *abo;
@@ -1842,18 +1841,15 @@ static int dce_v10_0_crtc_do_set_base(struct drm_crtc *crtc,
                return 0;
        }
 
-       if (atomic) {
-               amdgpu_fb = to_amdgpu_framebuffer(fb);
+       if (atomic)
                target_fb = fb;
-       } else {
-               amdgpu_fb = to_amdgpu_framebuffer(crtc->primary->fb);
+       else
                target_fb = crtc->primary->fb;
-       }
 
        /* If atomic, assume fb object is pinned & idle & fenced and
         * just update base pointers
         */
-       obj = amdgpu_fb->obj;
+       obj = target_fb->obj[0];
        abo = gem_to_amdgpu_bo(obj);
        r = amdgpu_bo_reserve(abo, false);
        if (unlikely(r != 0))
@@ -2043,8 +2039,7 @@ static int dce_v10_0_crtc_do_set_base(struct drm_crtc *crtc,
        WREG32(mmMASTER_UPDATE_MODE + amdgpu_crtc->crtc_offset, 0);
 
        if (!atomic && fb && fb != crtc->primary->fb) {
-               amdgpu_fb = to_amdgpu_framebuffer(fb);
-               abo = gem_to_amdgpu_bo(amdgpu_fb->obj);
+               abo = gem_to_amdgpu_bo(fb->obj[0]);
                r = amdgpu_bo_reserve(abo, true);
                if (unlikely(r != 0))
                        return r;
@@ -2526,11 +2521,9 @@ static void dce_v10_0_crtc_disable(struct drm_crtc *crtc)
        dce_v10_0_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
        if (crtc->primary->fb) {
                int r;
-               struct amdgpu_framebuffer *amdgpu_fb;
                struct amdgpu_bo *abo;
 
-               amdgpu_fb = to_amdgpu_framebuffer(crtc->primary->fb);
-               abo = gem_to_amdgpu_bo(amdgpu_fb->obj);
+               abo = gem_to_amdgpu_bo(crtc->primary->fb->obj[0]);
                r = amdgpu_bo_reserve(abo, true);
                if (unlikely(r))
                        DRM_ERROR("failed to reserve abo before unpin\n");
index a7c1c584a1913722ddb1f9a8815fe14d8d3ea0af..d3ae508b2a928ba2e8d3cb67d716c9499fae63bc 100644 (file)
@@ -1862,7 +1862,6 @@ static int dce_v11_0_crtc_do_set_base(struct drm_crtc *crtc,
        struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
        struct drm_device *dev = crtc->dev;
        struct amdgpu_device *adev = dev->dev_private;
-       struct amdgpu_framebuffer *amdgpu_fb;
        struct drm_framebuffer *target_fb;
        struct drm_gem_object *obj;
        struct amdgpu_bo *abo;
@@ -1881,18 +1880,15 @@ static int dce_v11_0_crtc_do_set_base(struct drm_crtc *crtc,
                return 0;
        }
 
-       if (atomic) {
-               amdgpu_fb = to_amdgpu_framebuffer(fb);
+       if (atomic)
                target_fb = fb;
-       } else {
-               amdgpu_fb = to_amdgpu_framebuffer(crtc->primary->fb);
+       else
                target_fb = crtc->primary->fb;
-       }
 
        /* If atomic, assume fb object is pinned & idle & fenced and
         * just update base pointers
         */
-       obj = amdgpu_fb->obj;
+       obj = target_fb->obj[0];
        abo = gem_to_amdgpu_bo(obj);
        r = amdgpu_bo_reserve(abo, false);
        if (unlikely(r != 0))
@@ -2082,8 +2078,7 @@ static int dce_v11_0_crtc_do_set_base(struct drm_crtc *crtc,
        WREG32(mmCRTC_MASTER_UPDATE_MODE + amdgpu_crtc->crtc_offset, 0);
 
        if (!atomic && fb && fb != crtc->primary->fb) {
-               amdgpu_fb = to_amdgpu_framebuffer(fb);
-               abo = gem_to_amdgpu_bo(amdgpu_fb->obj);
+               abo = gem_to_amdgpu_bo(fb->obj[0]);
                r = amdgpu_bo_reserve(abo, true);
                if (unlikely(r != 0))
                        return r;
@@ -2601,11 +2596,9 @@ static void dce_v11_0_crtc_disable(struct drm_crtc *crtc)
        dce_v11_0_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
        if (crtc->primary->fb) {
                int r;
-               struct amdgpu_framebuffer *amdgpu_fb;
                struct amdgpu_bo *abo;
 
-               amdgpu_fb = to_amdgpu_framebuffer(crtc->primary->fb);
-               abo = gem_to_amdgpu_bo(amdgpu_fb->obj);
+               abo = gem_to_amdgpu_bo(crtc->primary->fb->obj[0]);
                r = amdgpu_bo_reserve(abo, true);
                if (unlikely(r))
                        DRM_ERROR("failed to reserve abo before unpin\n");
index 9f67b7fd3487946bfe9065003b9dc26d1fb13224..394cc1e8fe20e22f4131f6697f24fa248f536996 100644 (file)
@@ -1780,7 +1780,6 @@ static int dce_v6_0_crtc_do_set_base(struct drm_crtc *crtc,
        struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
        struct drm_device *dev = crtc->dev;
        struct amdgpu_device *adev = dev->dev_private;
-       struct amdgpu_framebuffer *amdgpu_fb;
        struct drm_framebuffer *target_fb;
        struct drm_gem_object *obj;
        struct amdgpu_bo *abo;
@@ -1798,18 +1797,15 @@ static int dce_v6_0_crtc_do_set_base(struct drm_crtc *crtc,
                return 0;
        }
 
-       if (atomic) {
-               amdgpu_fb = to_amdgpu_framebuffer(fb);
+       if (atomic)
                target_fb = fb;
-       } else {
-               amdgpu_fb = to_amdgpu_framebuffer(crtc->primary->fb);
+       else
                target_fb = crtc->primary->fb;
-       }
 
        /* If atomic, assume fb object is pinned & idle & fenced and
         * just update base pointers
         */
-       obj = amdgpu_fb->obj;
+       obj = target_fb->obj[0];
        abo = gem_to_amdgpu_bo(obj);
        r = amdgpu_bo_reserve(abo, false);
        if (unlikely(r != 0))
@@ -1978,8 +1974,7 @@ static int dce_v6_0_crtc_do_set_base(struct drm_crtc *crtc,
        WREG32(mmMASTER_UPDATE_MODE + amdgpu_crtc->crtc_offset, 0);
 
        if (!atomic && fb && fb != crtc->primary->fb) {
-               amdgpu_fb = to_amdgpu_framebuffer(fb);
-               abo = gem_to_amdgpu_bo(amdgpu_fb->obj);
+               abo = gem_to_amdgpu_bo(fb->obj[0]);
                r = amdgpu_bo_reserve(abo, true);
                if (unlikely(r != 0))
                        return r;
@@ -2414,11 +2409,9 @@ static void dce_v6_0_crtc_disable(struct drm_crtc *crtc)
        dce_v6_0_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
        if (crtc->primary->fb) {
                int r;
-               struct amdgpu_framebuffer *amdgpu_fb;
                struct amdgpu_bo *abo;
 
-               amdgpu_fb = to_amdgpu_framebuffer(crtc->primary->fb);
-               abo = gem_to_amdgpu_bo(amdgpu_fb->obj);
+               abo = gem_to_amdgpu_bo(crtc->primary->fb->obj[0]);
                r = amdgpu_bo_reserve(abo, true);
                if (unlikely(r))
                        DRM_ERROR("failed to reserve abo before unpin\n");
index f55422cbd77abbfb01329d15c6ae907d0f9e0c16..c9b9ab8f1b059a8b0385babc3a2b50547c566450 100644 (file)
@@ -1754,7 +1754,6 @@ static int dce_v8_0_crtc_do_set_base(struct drm_crtc *crtc,
        struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
        struct drm_device *dev = crtc->dev;
        struct amdgpu_device *adev = dev->dev_private;
-       struct amdgpu_framebuffer *amdgpu_fb;
        struct drm_framebuffer *target_fb;
        struct drm_gem_object *obj;
        struct amdgpu_bo *abo;
@@ -1773,18 +1772,15 @@ static int dce_v8_0_crtc_do_set_base(struct drm_crtc *crtc,
                return 0;
        }
 
-       if (atomic) {
-               amdgpu_fb = to_amdgpu_framebuffer(fb);
+       if (atomic)
                target_fb = fb;
-       } else {
-               amdgpu_fb = to_amdgpu_framebuffer(crtc->primary->fb);
+       else
                target_fb = crtc->primary->fb;
-       }
 
        /* If atomic, assume fb object is pinned & idle & fenced and
         * just update base pointers
         */
-       obj = amdgpu_fb->obj;
+       obj = target_fb->obj[0];
        abo = gem_to_amdgpu_bo(obj);
        r = amdgpu_bo_reserve(abo, false);
        if (unlikely(r != 0))
@@ -1955,8 +1951,7 @@ static int dce_v8_0_crtc_do_set_base(struct drm_crtc *crtc,
        WREG32(mmMASTER_UPDATE_MODE + amdgpu_crtc->crtc_offset, 0);
 
        if (!atomic && fb && fb != crtc->primary->fb) {
-               amdgpu_fb = to_amdgpu_framebuffer(fb);
-               abo = gem_to_amdgpu_bo(amdgpu_fb->obj);
+               abo = gem_to_amdgpu_bo(fb->obj[0]);
                r = amdgpu_bo_reserve(abo, true);
                if (unlikely(r != 0))
                        return r;
@@ -2430,11 +2425,9 @@ static void dce_v8_0_crtc_disable(struct drm_crtc *crtc)
        dce_v8_0_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
        if (crtc->primary->fb) {
                int r;
-               struct amdgpu_framebuffer *amdgpu_fb;
                struct amdgpu_bo *abo;
 
-               amdgpu_fb = to_amdgpu_framebuffer(crtc->primary->fb);
-               abo = gem_to_amdgpu_bo(amdgpu_fb->obj);
+               abo = gem_to_amdgpu_bo(crtc->primary->fb->obj[0]);
                r = amdgpu_bo_reserve(abo, true);
                if (unlikely(r))
                        DRM_ERROR("failed to reserve abo before unpin\n");
index b51f05dc9582ced38e3239c9b4d6d154a6c507ff..89b2286a9d6bcf6ebd3a8a81f677768538f0baa4 100644 (file)
@@ -168,11 +168,9 @@ static void dce_virtual_crtc_disable(struct drm_crtc *crtc)
        dce_virtual_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
        if (crtc->primary->fb) {
                int r;
-               struct amdgpu_framebuffer *amdgpu_fb;
                struct amdgpu_bo *abo;
 
-               amdgpu_fb = to_amdgpu_framebuffer(crtc->primary->fb);
-               abo = gem_to_amdgpu_bo(amdgpu_fb->obj);
+               abo = gem_to_amdgpu_bo(crtc->primary->fb->obj[0]);
                r = amdgpu_bo_reserve(abo, true);
                if (unlikely(r))
                        DRM_ERROR("failed to reserve abo before unpin\n");
index 3ff3905eee9ab11b973051b7eb718e6b4abc230f..077ee6793a1c1b2d7b49230d34c5ddd286526f04 100644 (file)
@@ -1819,7 +1819,7 @@ static bool fill_rects_from_plane_state(const struct drm_plane_state *state,
 static int get_fb_info(const struct amdgpu_framebuffer *amdgpu_fb,
                       uint64_t *tiling_flags)
 {
-       struct amdgpu_bo *rbo = gem_to_amdgpu_bo(amdgpu_fb->obj);
+       struct amdgpu_bo *rbo = gem_to_amdgpu_bo(amdgpu_fb->base.obj[0]);
        int r = amdgpu_bo_reserve(rbo, false);
 
        if (unlikely(r)) {
@@ -3028,8 +3028,7 @@ static int dm_plane_helper_prepare_fb(struct drm_plane *plane,
        }
 
        afb = to_amdgpu_framebuffer(new_state->fb);
-
-       obj = afb->obj;
+       obj = new_state->fb->obj[0];
        rbo = gem_to_amdgpu_bo(obj);
        adev = amdgpu_ttm_adev(rbo->tbo.bdev);
        r = amdgpu_bo_reserve(rbo, false);
@@ -3093,14 +3092,12 @@ static void dm_plane_helper_cleanup_fb(struct drm_plane *plane,
                                       struct drm_plane_state *old_state)
 {
        struct amdgpu_bo *rbo;
-       struct amdgpu_framebuffer *afb;
        int r;
 
        if (!old_state->fb)
                return;
 
-       afb = to_amdgpu_framebuffer(old_state->fb);
-       rbo = gem_to_amdgpu_bo(afb->obj);
+       rbo = gem_to_amdgpu_bo(old_state->fb->obj[0]);
        r = amdgpu_bo_reserve(rbo, false);
        if (unlikely(r)) {
                DRM_ERROR("failed to reserve rbo before unpin\n");
@@ -3896,7 +3893,7 @@ static void amdgpu_dm_do_flip(struct drm_crtc *crtc,
        int r, vpos, hpos;
        struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
        struct amdgpu_framebuffer *afb = to_amdgpu_framebuffer(fb);
-       struct amdgpu_bo *abo = gem_to_amdgpu_bo(afb->obj);
+       struct amdgpu_bo *abo = gem_to_amdgpu_bo(fb->obj[0]);
        struct amdgpu_device *adev = crtc->dev->dev_private;
        bool async_flip = (crtc->state->pageflip_flags & DRM_MODE_PAGE_FLIP_ASYNC) != 0;
        struct dc_flip_addrs addr = { {0} };