On Thu, Jun 27, 2019 at 10:09:09AM +0200, Thomas Zimmermann wrote: > The mgag200 driver's struct mga_framebuffer is a buffer object with GEM > interface. There are already GEM framebuffer helpers that implement the > same functionality. Convert mgag200 to these. > > Signed-off-by: Thomas Zimmermann <tzimmermann@xxxxxxx> > --- > drivers/gpu/drm/mgag200/mgag200_drv.h | 13 ------ > drivers/gpu/drm/mgag200/mgag200_fb.c | 41 +++++++---------- > drivers/gpu/drm/mgag200/mgag200_main.c | 61 +------------------------- > drivers/gpu/drm/mgag200/mgag200_mode.c | 22 ++++------ > 4 files changed, 26 insertions(+), 111 deletions(-) > > diff --git a/drivers/gpu/drm/mgag200/mgag200_drv.h b/drivers/gpu/drm/mgag200/mgag200_drv.h > index c47671ce6c48..36862824b567 100644 > --- a/drivers/gpu/drm/mgag200/mgag200_drv.h > +++ b/drivers/gpu/drm/mgag200/mgag200_drv.h > @@ -100,16 +100,9 @@ > #define to_mga_crtc(x) container_of(x, struct mga_crtc, base) > #define to_mga_encoder(x) container_of(x, struct mga_encoder, base) > #define to_mga_connector(x) container_of(x, struct mga_connector, base) > -#define to_mga_framebuffer(x) container_of(x, struct mga_framebuffer, base) > - > -struct mga_framebuffer { > - struct drm_framebuffer base; > - struct drm_gem_object *obj; Yeah we moved the obj pointer to drm_fb a long time ago. Although after mga200g was merged. Acked-by: Daniel Vetter <daniel.vetter@xxxxxxxx> > -}; > > struct mga_fbdev { > struct drm_fb_helper helper; /* must be first */ > - struct mga_framebuffer mfb; > void *sysram; > int size; > int x1, y1, x2, y2; /* dirty rect */ > @@ -215,12 +208,6 @@ int mgag200_fbdev_init(struct mga_device *mdev); > void mgag200_fbdev_fini(struct mga_device *mdev); > > /* mgag200_main.c */ > -int mgag200_framebuffer_init(struct drm_device *dev, > - struct mga_framebuffer *mfb, > - const struct drm_mode_fb_cmd2 *mode_cmd, > - struct drm_gem_object *obj); > - > - > int mgag200_driver_load(struct drm_device *dev, unsigned long flags); > void mgag200_driver_unload(struct drm_device *dev); > int mgag200_gem_create(struct drm_device *dev, > diff --git a/drivers/gpu/drm/mgag200/mgag200_fb.c b/drivers/gpu/drm/mgag200/mgag200_fb.c > index 8adb33228732..e02d5479ea46 100644 > --- a/drivers/gpu/drm/mgag200/mgag200_fb.c > +++ b/drivers/gpu/drm/mgag200/mgag200_fb.c > @@ -11,6 +11,7 @@ > #include <drm/drmP.h> > #include <drm/drm_util.h> > #include <drm/drm_fb_helper.h> > +#include <drm/drm_gem_framebuffer_helper.h> > #include <drm/drm_crtc_helper.h> > > #include "mgag200_drv.h" > @@ -19,19 +20,18 @@ static void mga_dirty_update(struct mga_fbdev *mfbdev, > int x, int y, int width, int height) > { > int i; > - struct drm_gem_object *obj; > struct drm_gem_vram_object *gbo; > int src_offset, dst_offset; > - int bpp = mfbdev->mfb.base.format->cpp[0]; > int ret; > u8 *dst; > bool unmap = false; > bool store_for_later = false; > int x2, y2; > unsigned long flags; > + struct drm_framebuffer *fb = mfbdev->helper.fb; > + int bpp = fb->format->cpp[0]; > > - obj = mfbdev->mfb.obj; > - gbo = drm_gem_vram_of_gem(obj); > + gbo = drm_gem_vram_of_gem(fb->obj[0]); > > if (drm_can_sleep()) { > /* We pin the BO so it won't be moved during the > @@ -89,8 +89,7 @@ static void mga_dirty_update(struct mga_fbdev *mfbdev, > > for (i = y; i <= y2; i++) { > /* assume equal stride for now */ > - src_offset = dst_offset = > - i * mfbdev->mfb.base.pitches[0] + (x * bpp); > + src_offset = dst_offset = i * fb->pitches[0] + (x * bpp); > memcpy_toio(dst + dst_offset, mfbdev->sysram + src_offset, > (x2 - x + 1) * bpp); > } > @@ -192,24 +191,24 @@ static int mgag200fb_create(struct drm_fb_helper *helper, > sysram = vmalloc(size); > if (!sysram) { > ret = -ENOMEM; > - goto err_sysram; > + goto err_drm_gem_object_put_unlocked; > } > > info = drm_fb_helper_alloc_fbi(helper); > if (IS_ERR(info)) { > ret = PTR_ERR(info); > - goto err_alloc_fbi; > + goto err_vfree; > } > > - ret = mgag200_framebuffer_init(dev, &mfbdev->mfb, &mode_cmd, gobj); > - if (ret) > - goto err_alloc_fbi; > + fb = drm_gem_fbdev_fb_create(dev, sizes, 0, gobj, NULL); > + if (IS_ERR(fb)) { > + ret = PTR_ERR(fb); > + goto err_vfree; > + } > > mfbdev->sysram = sysram; > mfbdev->size = size; > > - fb = &mfbdev->mfb.base; > - > /* setup helper */ > mfbdev->helper.fb = fb; > > @@ -230,29 +229,21 @@ static int mgag200fb_create(struct drm_fb_helper *helper, > > return 0; > > -err_alloc_fbi: > +err_vfree: > vfree(sysram); > -err_sysram: > +err_drm_gem_object_put_unlocked: > drm_gem_object_put_unlocked(gobj); > - > return ret; > } > > static int mga_fbdev_destroy(struct drm_device *dev, > struct mga_fbdev *mfbdev) > { > - struct mga_framebuffer *mfb = &mfbdev->mfb; > - > drm_fb_helper_unregister_fbi(&mfbdev->helper); > - > - if (mfb->obj) { > - drm_gem_object_put_unlocked(mfb->obj); > - mfb->obj = NULL; > - } > drm_fb_helper_fini(&mfbdev->helper); > + drm_framebuffer_put(mfbdev->helper.fb); > + > vfree(mfbdev->sysram); > - drm_framebuffer_unregister_private(&mfb->base); > - drm_framebuffer_cleanup(&mfb->base); > > return 0; > } > diff --git a/drivers/gpu/drm/mgag200/mgag200_main.c b/drivers/gpu/drm/mgag200/mgag200_main.c > index dd61ccc5af5c..4936fb8b68ed 100644 > --- a/drivers/gpu/drm/mgag200/mgag200_main.c > +++ b/drivers/gpu/drm/mgag200/mgag200_main.c > @@ -9,68 +9,11 @@ > */ > #include <drm/drmP.h> > #include <drm/drm_crtc_helper.h> > +#include <drm/drm_gem_framebuffer_helper.h> > #include "mgag200_drv.h" > > -static void mga_user_framebuffer_destroy(struct drm_framebuffer *fb) > -{ > - struct mga_framebuffer *mga_fb = to_mga_framebuffer(fb); > - > - drm_gem_object_put_unlocked(mga_fb->obj); > - drm_framebuffer_cleanup(fb); > - kfree(fb); > -} > - > -static const struct drm_framebuffer_funcs mga_fb_funcs = { > - .destroy = mga_user_framebuffer_destroy, > -}; > - > -int mgag200_framebuffer_init(struct drm_device *dev, > - struct mga_framebuffer *gfb, > - const struct drm_mode_fb_cmd2 *mode_cmd, > - struct drm_gem_object *obj) > -{ > - int ret; > - > - drm_helper_mode_fill_fb_struct(dev, &gfb->base, mode_cmd); > - gfb->obj = obj; > - ret = drm_framebuffer_init(dev, &gfb->base, &mga_fb_funcs); > - if (ret) { > - DRM_ERROR("drm_framebuffer_init failed: %d\n", ret); > - return ret; > - } > - return 0; > -} > - > -static struct drm_framebuffer * > -mgag200_user_framebuffer_create(struct drm_device *dev, > - struct drm_file *filp, > - const struct drm_mode_fb_cmd2 *mode_cmd) > -{ > - struct drm_gem_object *obj; > - struct mga_framebuffer *mga_fb; > - int ret; > - > - obj = drm_gem_object_lookup(filp, mode_cmd->handles[0]); > - if (obj == NULL) > - return ERR_PTR(-ENOENT); > - > - mga_fb = kzalloc(sizeof(*mga_fb), GFP_KERNEL); > - if (!mga_fb) { > - drm_gem_object_put_unlocked(obj); > - return ERR_PTR(-ENOMEM); > - } > - > - ret = mgag200_framebuffer_init(dev, mga_fb, mode_cmd, obj); > - if (ret) { > - drm_gem_object_put_unlocked(obj); > - kfree(mga_fb); > - return ERR_PTR(ret); > - } > - return &mga_fb->base; > -} > - > static const struct drm_mode_config_funcs mga_mode_funcs = { > - .fb_create = mgag200_user_framebuffer_create, > + .fb_create = drm_gem_fb_create > }; > > static int mga_probe_vram(struct mga_device *mdev, void __iomem *mem) > diff --git a/drivers/gpu/drm/mgag200/mgag200_mode.c b/drivers/gpu/drm/mgag200/mgag200_mode.c > index a25054015e8c..5e382bf7fc1e 100644 > --- a/drivers/gpu/drm/mgag200/mgag200_mode.c > +++ b/drivers/gpu/drm/mgag200/mgag200_mode.c > @@ -860,27 +860,21 @@ static int mga_crtc_do_set_base(struct drm_crtc *crtc, > int x, int y, int atomic) > { > struct mga_device *mdev = crtc->dev->dev_private; > - struct drm_gem_object *obj; > - struct mga_framebuffer *mga_fb; > struct drm_gem_vram_object *gbo; > int ret; > s64 gpu_addr; > void *base; > > if (!atomic && fb) { > - mga_fb = to_mga_framebuffer(fb); > - obj = mga_fb->obj; > - gbo = drm_gem_vram_of_gem(obj); > + gbo = drm_gem_vram_of_gem(fb->obj[0]); > > /* unmap if console */ > - if (&mdev->mfbdev->mfb == mga_fb) > + if (mdev->mfbdev->helper.fb == fb) > drm_gem_vram_kunmap(gbo); > drm_gem_vram_unpin(gbo); > } > > - mga_fb = to_mga_framebuffer(crtc->primary->fb); > - obj = mga_fb->obj; > - gbo = drm_gem_vram_of_gem(obj); > + gbo = drm_gem_vram_of_gem(crtc->primary->fb->obj[0]); > > ret = drm_gem_vram_pin(gbo, DRM_GEM_VRAM_PL_FLAG_VRAM); > if (ret) > @@ -891,7 +885,7 @@ static int mga_crtc_do_set_base(struct drm_crtc *crtc, > goto err_drm_gem_vram_unpin; > } > > - if (&mdev->mfbdev->mfb == mga_fb) { > + if (mdev->mfbdev->helper.fb == crtc->primary->fb) { > /* if pushing console in kmap it */ > base = drm_gem_vram_kmap(gbo, true, NULL); > if (IS_ERR(base)) { > @@ -1424,12 +1418,12 @@ static void mga_crtc_disable(struct drm_crtc *crtc) > mga_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); > if (crtc->primary->fb) { > struct mga_device *mdev = crtc->dev->dev_private; > - struct mga_framebuffer *mga_fb = to_mga_framebuffer(crtc->primary->fb); > - struct drm_gem_object *obj = mga_fb->obj; > - struct drm_gem_vram_object *gbo = drm_gem_vram_of_gem(obj); > + struct drm_framebuffer *fb = crtc->primary->fb; > + struct drm_gem_vram_object *gbo = > + drm_gem_vram_of_gem(fb->obj[0]); > > /* unmap if console */ > - if (&mdev->mfbdev->mfb == mga_fb) > + if (mdev->mfbdev->helper.fb == fb) > drm_gem_vram_kunmap(gbo); > drm_gem_vram_unpin(gbo); > } > -- > 2.21.0 > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list dri-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/dri-devel