Commit 5d177189 authored by Thomas Zimmermann's avatar Thomas Zimmermann

drm/mgag200: Replace struct mga_framebuffer with GEM framebuffer helpers

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: default avatarThomas Zimmermann <tzimmermann@suse.de>
Acked-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20190627080909.30471-1-tzimmermann@suse.de
parent fdb29b73
...@@ -100,16 +100,9 @@ ...@@ -100,16 +100,9 @@
#define to_mga_crtc(x) container_of(x, struct mga_crtc, base) #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_encoder(x) container_of(x, struct mga_encoder, base)
#define to_mga_connector(x) container_of(x, struct mga_connector, 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;
};
struct mga_fbdev { struct mga_fbdev {
struct drm_fb_helper helper; /* must be first */ struct drm_fb_helper helper; /* must be first */
struct mga_framebuffer mfb;
void *sysram; void *sysram;
int size; int size;
int x1, y1, x2, y2; /* dirty rect */ int x1, y1, x2, y2; /* dirty rect */
...@@ -215,12 +208,6 @@ int mgag200_fbdev_init(struct mga_device *mdev); ...@@ -215,12 +208,6 @@ int mgag200_fbdev_init(struct mga_device *mdev);
void mgag200_fbdev_fini(struct mga_device *mdev); void mgag200_fbdev_fini(struct mga_device *mdev);
/* mgag200_main.c */ /* 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); int mgag200_driver_load(struct drm_device *dev, unsigned long flags);
void mgag200_driver_unload(struct drm_device *dev); void mgag200_driver_unload(struct drm_device *dev);
int mgag200_gem_create(struct drm_device *dev, int mgag200_gem_create(struct drm_device *dev,
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <drm/drmP.h> #include <drm/drmP.h>
#include <drm/drm_util.h> #include <drm/drm_util.h>
#include <drm/drm_fb_helper.h> #include <drm/drm_fb_helper.h>
#include <drm/drm_gem_framebuffer_helper.h>
#include <drm/drm_crtc_helper.h> #include <drm/drm_crtc_helper.h>
#include "mgag200_drv.h" #include "mgag200_drv.h"
...@@ -19,19 +20,18 @@ static void mga_dirty_update(struct mga_fbdev *mfbdev, ...@@ -19,19 +20,18 @@ static void mga_dirty_update(struct mga_fbdev *mfbdev,
int x, int y, int width, int height) int x, int y, int width, int height)
{ {
int i; int i;
struct drm_gem_object *obj;
struct drm_gem_vram_object *gbo; struct drm_gem_vram_object *gbo;
int src_offset, dst_offset; int src_offset, dst_offset;
int bpp = mfbdev->mfb.base.format->cpp[0];
int ret; int ret;
u8 *dst; u8 *dst;
bool unmap = false; bool unmap = false;
bool store_for_later = false; bool store_for_later = false;
int x2, y2; int x2, y2;
unsigned long flags; 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(fb->obj[0]);
gbo = drm_gem_vram_of_gem(obj);
if (drm_can_sleep()) { if (drm_can_sleep()) {
/* We pin the BO so it won't be moved during the /* 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, ...@@ -89,8 +89,7 @@ static void mga_dirty_update(struct mga_fbdev *mfbdev,
for (i = y; i <= y2; i++) { for (i = y; i <= y2; i++) {
/* assume equal stride for now */ /* assume equal stride for now */
src_offset = dst_offset = src_offset = dst_offset = i * fb->pitches[0] + (x * bpp);
i * mfbdev->mfb.base.pitches[0] + (x * bpp);
memcpy_toio(dst + dst_offset, mfbdev->sysram + src_offset, memcpy_toio(dst + dst_offset, mfbdev->sysram + src_offset,
(x2 - x + 1) * bpp); (x2 - x + 1) * bpp);
} }
...@@ -192,24 +191,24 @@ static int mgag200fb_create(struct drm_fb_helper *helper, ...@@ -192,24 +191,24 @@ static int mgag200fb_create(struct drm_fb_helper *helper,
sysram = vmalloc(size); sysram = vmalloc(size);
if (!sysram) { if (!sysram) {
ret = -ENOMEM; ret = -ENOMEM;
goto err_sysram; goto err_drm_gem_object_put_unlocked;
} }
info = drm_fb_helper_alloc_fbi(helper); info = drm_fb_helper_alloc_fbi(helper);
if (IS_ERR(info)) { if (IS_ERR(info)) {
ret = PTR_ERR(info); ret = PTR_ERR(info);
goto err_alloc_fbi; goto err_vfree;
} }
ret = mgag200_framebuffer_init(dev, &mfbdev->mfb, &mode_cmd, gobj); fb = drm_gem_fbdev_fb_create(dev, sizes, 0, gobj, NULL);
if (ret) if (IS_ERR(fb)) {
goto err_alloc_fbi; ret = PTR_ERR(fb);
goto err_vfree;
}
mfbdev->sysram = sysram; mfbdev->sysram = sysram;
mfbdev->size = size; mfbdev->size = size;
fb = &mfbdev->mfb.base;
/* setup helper */ /* setup helper */
mfbdev->helper.fb = fb; mfbdev->helper.fb = fb;
...@@ -230,29 +229,21 @@ static int mgag200fb_create(struct drm_fb_helper *helper, ...@@ -230,29 +229,21 @@ static int mgag200fb_create(struct drm_fb_helper *helper,
return 0; return 0;
err_alloc_fbi: err_vfree:
vfree(sysram); vfree(sysram);
err_sysram: err_drm_gem_object_put_unlocked:
drm_gem_object_put_unlocked(gobj); drm_gem_object_put_unlocked(gobj);
return ret; return ret;
} }
static int mga_fbdev_destroy(struct drm_device *dev, static int mga_fbdev_destroy(struct drm_device *dev,
struct mga_fbdev *mfbdev) struct mga_fbdev *mfbdev)
{ {
struct mga_framebuffer *mfb = &mfbdev->mfb;
drm_fb_helper_unregister_fbi(&mfbdev->helper); 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_fb_helper_fini(&mfbdev->helper);
drm_framebuffer_put(mfbdev->helper.fb);
vfree(mfbdev->sysram); vfree(mfbdev->sysram);
drm_framebuffer_unregister_private(&mfb->base);
drm_framebuffer_cleanup(&mfb->base);
return 0; return 0;
} }
......
...@@ -9,68 +9,11 @@ ...@@ -9,68 +9,11 @@
*/ */
#include <drm/drmP.h> #include <drm/drmP.h>
#include <drm/drm_crtc_helper.h> #include <drm/drm_crtc_helper.h>
#include <drm/drm_gem_framebuffer_helper.h>
#include "mgag200_drv.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 = { 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) static int mga_probe_vram(struct mga_device *mdev, void __iomem *mem)
......
...@@ -860,27 +860,21 @@ static int mga_crtc_do_set_base(struct drm_crtc *crtc, ...@@ -860,27 +860,21 @@ static int mga_crtc_do_set_base(struct drm_crtc *crtc,
int x, int y, int atomic) int x, int y, int atomic)
{ {
struct mga_device *mdev = crtc->dev->dev_private; struct mga_device *mdev = crtc->dev->dev_private;
struct drm_gem_object *obj;
struct mga_framebuffer *mga_fb;
struct drm_gem_vram_object *gbo; struct drm_gem_vram_object *gbo;
int ret; int ret;
s64 gpu_addr; s64 gpu_addr;
void *base; void *base;
if (!atomic && fb) { if (!atomic && fb) {
mga_fb = to_mga_framebuffer(fb); gbo = drm_gem_vram_of_gem(fb->obj[0]);
obj = mga_fb->obj;
gbo = drm_gem_vram_of_gem(obj);
/* unmap if console */ /* unmap if console */
if (&mdev->mfbdev->mfb == mga_fb) if (mdev->mfbdev->helper.fb == fb)
drm_gem_vram_kunmap(gbo); drm_gem_vram_kunmap(gbo);
drm_gem_vram_unpin(gbo); drm_gem_vram_unpin(gbo);
} }
mga_fb = to_mga_framebuffer(crtc->primary->fb); gbo = drm_gem_vram_of_gem(crtc->primary->fb->obj[0]);
obj = mga_fb->obj;
gbo = drm_gem_vram_of_gem(obj);
ret = drm_gem_vram_pin(gbo, DRM_GEM_VRAM_PL_FLAG_VRAM); ret = drm_gem_vram_pin(gbo, DRM_GEM_VRAM_PL_FLAG_VRAM);
if (ret) if (ret)
...@@ -891,7 +885,7 @@ static int mga_crtc_do_set_base(struct drm_crtc *crtc, ...@@ -891,7 +885,7 @@ static int mga_crtc_do_set_base(struct drm_crtc *crtc,
goto err_drm_gem_vram_unpin; 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 */ /* if pushing console in kmap it */
base = drm_gem_vram_kmap(gbo, true, NULL); base = drm_gem_vram_kmap(gbo, true, NULL);
if (IS_ERR(base)) { if (IS_ERR(base)) {
...@@ -1424,12 +1418,12 @@ static void mga_crtc_disable(struct drm_crtc *crtc) ...@@ -1424,12 +1418,12 @@ static void mga_crtc_disable(struct drm_crtc *crtc)
mga_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); mga_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
if (crtc->primary->fb) { if (crtc->primary->fb) {
struct mga_device *mdev = crtc->dev->dev_private; struct mga_device *mdev = crtc->dev->dev_private;
struct mga_framebuffer *mga_fb = to_mga_framebuffer(crtc->primary->fb); struct drm_framebuffer *fb = crtc->primary->fb;
struct drm_gem_object *obj = mga_fb->obj; struct drm_gem_vram_object *gbo =
struct drm_gem_vram_object *gbo = drm_gem_vram_of_gem(obj); drm_gem_vram_of_gem(fb->obj[0]);
/* unmap if console */ /* unmap if console */
if (&mdev->mfbdev->mfb == mga_fb) if (mdev->mfbdev->helper.fb == fb)
drm_gem_vram_kunmap(gbo); drm_gem_vram_kunmap(gbo);
drm_gem_vram_unpin(gbo); drm_gem_vram_unpin(gbo);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment