From 8ed447744bec60b05acf452af889f56934275c99 Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Thu, 14 Nov 2019 15:10:25 +0100 Subject: [PATCH] drm/udl: Replace struct udl_framebuffer with generic implementation The udl driver's struct udl_framebuffer stores a DRM framebuffer with an associated GEM object. This functionality is also provided by generic code. Switch udl over. Signed-off-by: Thomas Zimmermann Acked-by: Sam Ravnborg Link: https://patchwork.freedesktop.org/patch/msgid/20191114141025.32198-6-tzimmermann@suse.de --- drivers/gpu/drm/udl/udl_drv.h | 7 ----- drivers/gpu/drm/udl/udl_fb.c | 62 +++++-------------------------------------- 2 files changed, 6 insertions(+), 63 deletions(-) diff --git a/drivers/gpu/drm/udl/udl_drv.h b/drivers/gpu/drm/udl/udl_drv.h index c5e3160..66cbe04 100644 --- a/drivers/gpu/drm/udl/udl_drv.h +++ b/drivers/gpu/drm/udl/udl_drv.h @@ -74,13 +74,6 @@ struct udl_device { #define to_udl(x) container_of(x, struct udl_device, drm) -struct udl_framebuffer { - struct drm_framebuffer base; - struct drm_gem_shmem_object *shmem; -}; - -#define to_udl_fb(x) container_of(x, struct udl_framebuffer, base) - /* modeset */ int udl_modeset_init(struct drm_device *dev); void udl_modeset_restore(struct drm_device *dev); diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c index ad7bf16..c1996ac 100644 --- a/drivers/gpu/drm/udl/udl_fb.c +++ b/drivers/gpu/drm/udl/udl_fb.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -199,68 +200,17 @@ static int udl_user_framebuffer_dirty(struct drm_framebuffer *fb, return ret; } -static void udl_user_framebuffer_destroy(struct drm_framebuffer *fb) -{ - struct udl_framebuffer *ufb = to_udl_fb(fb); - - if (ufb->shmem) - drm_gem_object_put_unlocked(&ufb->shmem->base); - - drm_framebuffer_cleanup(fb); - kfree(ufb); -} - static const struct drm_framebuffer_funcs udlfb_funcs = { - .destroy = udl_user_framebuffer_destroy, - .dirty = udl_user_framebuffer_dirty, + .destroy = drm_gem_fb_destroy, + .create_handle = drm_gem_fb_create_handle, + .dirty = udl_user_framebuffer_dirty, }; - -static int -udl_framebuffer_init(struct drm_device *dev, - struct udl_framebuffer *ufb, - const struct drm_mode_fb_cmd2 *mode_cmd, - struct drm_gem_shmem_object *shmem) -{ - int ret; - - ufb->shmem = shmem; - drm_helper_mode_fill_fb_struct(dev, &ufb->base, mode_cmd); - ret = drm_framebuffer_init(dev, &ufb->base, &udlfb_funcs); - return ret; -} - struct drm_framebuffer * udl_fb_user_fb_create(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { - struct drm_gem_object *obj; - struct udl_framebuffer *ufb; - int ret; - uint32_t size; - - obj = drm_gem_object_lookup(file, mode_cmd->handles[0]); - if (obj == NULL) - return ERR_PTR(-ENOENT); - - size = mode_cmd->pitches[0] * mode_cmd->height; - size = ALIGN(size, PAGE_SIZE); - - if (size > obj->size) { - DRM_ERROR("object size not sufficient for fb %d %zu %d %d\n", size, obj->size, mode_cmd->pitches[0], mode_cmd->height); - return ERR_PTR(-ENOMEM); - } - - ufb = kzalloc(sizeof(*ufb), GFP_KERNEL); - if (ufb == NULL) - return ERR_PTR(-ENOMEM); - - ret = udl_framebuffer_init(dev, ufb, mode_cmd, - to_drm_gem_shmem_obj(obj)); - if (ret) { - kfree(ufb); - return ERR_PTR(-EINVAL); - } - return &ufb->base; + return drm_gem_fb_create_with_funcs(dev, file, mode_cmd, + &udlfb_funcs); } -- 2.7.4