Re: [PATCH] drm/ast: Replace struct ast_framebuffer with GEM framebuffer helpers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jun 27, 2019 at 07:34:10PM +0200, Thomas Zimmermann wrote:
> The ast driver's struct ast_framebuffer is a buffer object with GEM
> interface. There are already GEM framebuffer helpers that implement
> the same functionality. Convert ast to these.
> 
> Signed-off-by: Thomas Zimmermann <tzimmermann@xxxxxxx>

MOar refactoring, yes!!

Acked-by: Daniel Vetter <daniel.vetter@xxxxxxxx>

> ---
>  drivers/gpu/drm/ast/ast_drv.h  | 12 -------
>  drivers/gpu/drm/ast/ast_fb.c   | 27 ++++++--------
>  drivers/gpu/drm/ast/ast_main.c | 65 ++--------------------------------
>  drivers/gpu/drm/ast/ast_mode.c | 22 +++++-------
>  4 files changed, 22 insertions(+), 104 deletions(-)
> 
> diff --git a/drivers/gpu/drm/ast/ast_drv.h b/drivers/gpu/drm/ast/ast_drv.h
> index 684e15e64a62..ca794a3fcf8f 100644
> --- a/drivers/gpu/drm/ast/ast_drv.h
> +++ b/drivers/gpu/drm/ast/ast_drv.h
> @@ -239,14 +239,8 @@ struct ast_encoder {
>  	struct drm_encoder base;
>  };
>  
> -struct ast_framebuffer {
> -	struct drm_framebuffer base;
> -	struct drm_gem_object *obj;
> -};
> -
>  struct ast_fbdev {
>  	struct drm_fb_helper helper; /* must be first */
> -	struct ast_framebuffer afb;
>  	void *sysram;
>  	int size;
>  	int x1, y1, x2, y2; /* dirty rect */
> @@ -256,7 +250,6 @@ struct ast_fbdev {
>  #define to_ast_crtc(x) container_of(x, struct ast_crtc, base)
>  #define to_ast_connector(x) container_of(x, struct ast_connector, base)
>  #define to_ast_encoder(x) container_of(x, struct ast_encoder, base)
> -#define to_ast_framebuffer(x) container_of(x, struct ast_framebuffer, base)
>  
>  struct ast_vbios_stdtable {
>  	u8 misc;
> @@ -296,11 +289,6 @@ struct ast_vbios_mode_info {
>  extern int ast_mode_init(struct drm_device *dev);
>  extern void ast_mode_fini(struct drm_device *dev);
>  
> -int ast_framebuffer_init(struct drm_device *dev,
> -			 struct ast_framebuffer *ast_fb,
> -			 const struct drm_mode_fb_cmd2 *mode_cmd,
> -			 struct drm_gem_object *obj);
> -
>  int ast_fbdev_init(struct drm_device *dev);
>  void ast_fbdev_fini(struct drm_device *dev);
>  void ast_fbdev_set_suspend(struct drm_device *dev, int state);
> diff --git a/drivers/gpu/drm/ast/ast_fb.c b/drivers/gpu/drm/ast/ast_fb.c
> index 8200b25dad16..a849e58b40bc 100644
> --- a/drivers/gpu/drm/ast/ast_fb.c
> +++ b/drivers/gpu/drm/ast/ast_fb.c
> @@ -38,9 +38,10 @@
>  
>  #include <drm/drmP.h>
>  #include <drm/drm_crtc.h>
> +#include <drm/drm_crtc_helper.h>
>  #include <drm/drm_fb_helper.h>
> +#include <drm/drm_gem_framebuffer_helper.h>
>  #include <drm/drm_util.h>
> -#include <drm/drm_crtc_helper.h>
>  
>  #include "ast_drv.h"
>  
> @@ -50,15 +51,16 @@ static void ast_dirty_update(struct ast_fbdev *afbdev,
>  	int i;
>  	struct drm_gem_vram_object *gbo;
>  	int src_offset, dst_offset;
> -	int bpp = afbdev->afb.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 = afbdev->helper.fb;
> +	int bpp = fb->format->cpp[0];
>  
> -	gbo = drm_gem_vram_of_gem(afbdev->afb.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
> @@ -116,8 +118,7 @@ static void ast_dirty_update(struct ast_fbdev *afbdev,
>  
>  	for (i = y; i <= y2; i++) {
>  		/* assume equal stride for now */
> -		src_offset = dst_offset =
> -			i * afbdev->afb.base.pitches[0] + (x * bpp);
> +		src_offset = dst_offset = i * fb->pitches[0] + (x * bpp);
>  		memcpy_toio(dst + dst_offset, afbdev->sysram + src_offset,
>  			    (x2 - x + 1) * bpp);
>  	}
> @@ -222,14 +223,15 @@ static int astfb_create(struct drm_fb_helper *helper,
>  		ret = PTR_ERR(info);
>  		goto out;
>  	}
> -	ret = ast_framebuffer_init(dev, &afbdev->afb, &mode_cmd, gobj);
> -	if (ret)
> +	fb = drm_gem_fbdev_fb_create(dev, sizes, 0, gobj, NULL);
> +	if (IS_ERR(fb)) {
> +		ret = PTR_ERR(fb);
>  		goto out;
> +	}
>  
>  	afbdev->sysram = sysram;
>  	afbdev->size = size;
>  
> -	fb = &afbdev->afb.base;
>  	afbdev->helper.fb = fb;
>  
>  	info->fbops = &astfb_ops;
> @@ -261,20 +263,13 @@ static const struct drm_fb_helper_funcs ast_fb_helper_funcs = {
>  static void ast_fbdev_destroy(struct drm_device *dev,
>  			      struct ast_fbdev *afbdev)
>  {
> -	struct ast_framebuffer *afb = &afbdev->afb;
> -
>  	drm_helper_force_disable_all(dev);
>  	drm_fb_helper_unregister_fbi(&afbdev->helper);
>  
> -	if (afb->obj) {
> -		drm_gem_object_put_unlocked(afb->obj);
> -		afb->obj = NULL;
> -	}
>  	drm_fb_helper_fini(&afbdev->helper);
> +	drm_framebuffer_put(afbdev->helper.fb);
>  
>  	vfree(afbdev->sysram);
> -	drm_framebuffer_unregister_private(&afb->base);
> -	drm_framebuffer_cleanup(&afb->base);
>  }
>  
>  int ast_fbdev_init(struct drm_device *dev)
> diff --git a/drivers/gpu/drm/ast/ast_main.c b/drivers/gpu/drm/ast/ast_main.c
> index 4c7e31cb45ff..1bd61696e509 100644
> --- a/drivers/gpu/drm/ast/ast_main.c
> +++ b/drivers/gpu/drm/ast/ast_main.c
> @@ -28,9 +28,9 @@
>  #include <drm/drmP.h>
>  #include "ast_drv.h"
>  
> -
> -#include <drm/drm_fb_helper.h>
>  #include <drm/drm_crtc_helper.h>
> +#include <drm/drm_fb_helper.h>
> +#include <drm/drm_gem_framebuffer_helper.h>
>  
>  void ast_set_index_reg_mask(struct ast_private *ast,
>  			    uint32_t base, uint8_t index,
> @@ -383,67 +383,8 @@ static int ast_get_dram_info(struct drm_device *dev)
>  	return 0;
>  }
>  
> -static void ast_user_framebuffer_destroy(struct drm_framebuffer *fb)
> -{
> -	struct ast_framebuffer *ast_fb = to_ast_framebuffer(fb);
> -
> -	drm_gem_object_put_unlocked(ast_fb->obj);
> -	drm_framebuffer_cleanup(fb);
> -	kfree(ast_fb);
> -}
> -
> -static const struct drm_framebuffer_funcs ast_fb_funcs = {
> -	.destroy = ast_user_framebuffer_destroy,
> -};
> -
> -
> -int ast_framebuffer_init(struct drm_device *dev,
> -			 struct ast_framebuffer *ast_fb,
> -			 const struct drm_mode_fb_cmd2 *mode_cmd,
> -			 struct drm_gem_object *obj)
> -{
> -	int ret;
> -
> -	drm_helper_mode_fill_fb_struct(dev, &ast_fb->base, mode_cmd);
> -	ast_fb->obj = obj;
> -	ret = drm_framebuffer_init(dev, &ast_fb->base, &ast_fb_funcs);
> -	if (ret) {
> -		DRM_ERROR("framebuffer init failed %d\n", ret);
> -		return ret;
> -	}
> -	return 0;
> -}
> -
> -static struct drm_framebuffer *
> -ast_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 ast_framebuffer *ast_fb;
> -	int ret;
> -
> -	obj = drm_gem_object_lookup(filp, mode_cmd->handles[0]);
> -	if (obj == NULL)
> -		return ERR_PTR(-ENOENT);
> -
> -	ast_fb = kzalloc(sizeof(*ast_fb), GFP_KERNEL);
> -	if (!ast_fb) {
> -		drm_gem_object_put_unlocked(obj);
> -		return ERR_PTR(-ENOMEM);
> -	}
> -
> -	ret = ast_framebuffer_init(dev, ast_fb, mode_cmd, obj);
> -	if (ret) {
> -		drm_gem_object_put_unlocked(obj);
> -		kfree(ast_fb);
> -		return ERR_PTR(ret);
> -	}
> -	return &ast_fb->base;
> -}
> -
>  static const struct drm_mode_config_funcs ast_mode_funcs = {
> -	.fb_create = ast_user_framebuffer_create,
> +	.fb_create = drm_gem_fb_create
>  };
>  
>  static u32 ast_get_vram_info(struct drm_device *dev)
> diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c
> index ffccbef962a4..c48249df758e 100644
> --- a/drivers/gpu/drm/ast/ast_mode.c
> +++ b/drivers/gpu/drm/ast/ast_mode.c
> @@ -526,27 +526,21 @@ static int ast_crtc_do_set_base(struct drm_crtc *crtc,
>  				int x, int y, int atomic)
>  {
>  	struct ast_private *ast = crtc->dev->dev_private;
> -	struct drm_gem_object *obj;
> -	struct ast_framebuffer *ast_fb;
>  	struct drm_gem_vram_object *gbo;
>  	int ret;
>  	s64 gpu_addr;
>  	void *base;
>  
>  	if (!atomic && fb) {
> -		ast_fb = to_ast_framebuffer(fb);
> -		obj = ast_fb->obj;
> -		gbo = drm_gem_vram_of_gem(obj);
> +		gbo = drm_gem_vram_of_gem(fb->obj[0]);
>  
>  		/* unmap if console */
> -		if (&ast->fbdev->afb == ast_fb)
> +		if (ast->fbdev->helper.fb == fb)
>  			drm_gem_vram_kunmap(gbo);
>  		drm_gem_vram_unpin(gbo);
>  	}
>  
> -	ast_fb = to_ast_framebuffer(crtc->primary->fb);
> -	obj = ast_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)
> @@ -557,7 +551,7 @@ static int ast_crtc_do_set_base(struct drm_crtc *crtc,
>  		goto err_drm_gem_vram_unpin;
>  	}
>  
> -	if (&ast->fbdev->afb == ast_fb) {
> +	if (ast->fbdev->helper.fb == crtc->primary->fb) {
>  		/* if pushing console in kmap it */
>  		base = drm_gem_vram_kmap(gbo, true, NULL);
>  		if (IS_ERR(base)) {
> @@ -625,12 +619,12 @@ static void ast_crtc_disable(struct drm_crtc *crtc)
>  	ast_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
>  	if (crtc->primary->fb) {
>  		struct ast_private *ast = crtc->dev->dev_private;
> -		struct ast_framebuffer *ast_fb = to_ast_framebuffer(crtc->primary->fb);
> -		struct drm_gem_object *obj = ast_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 (&ast->fbdev->afb == ast_fb)
> +		if (ast->fbdev->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




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux