Commit b112481b authored by Daniel Vetter's avatar Daniel Vetter

drm/cma-helper: simplify setup for drivers with ->dirty callbacks

If we store the fb funcs pointer, we can remove a bit of boilerplate.
Also remove the _fbdev_ in the example code, since the fb_funcs->dirty
callback has nothing to do with fbdev. It's a KMS feature, only
used by the fbdev deferred_io support to implement flushing/upload.

Cc: Noralf Trønnes <noralf@tronnes.org>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
[danvet: Move the misplaced kerneldoc change from a later patch to
this one here.]
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/1483044517-5770-11-git-send-email-daniel.vetter@ffwll.ch
parent 7357f899
...@@ -39,6 +39,7 @@ struct drm_fb_cma { ...@@ -39,6 +39,7 @@ struct drm_fb_cma {
struct drm_fbdev_cma { struct drm_fbdev_cma {
struct drm_fb_helper fb_helper; struct drm_fb_helper fb_helper;
struct drm_fb_cma *fb; struct drm_fb_cma *fb;
const struct drm_framebuffer_funcs *fb_funcs;
}; };
/** /**
...@@ -58,7 +59,7 @@ struct drm_fbdev_cma { ...@@ -58,7 +59,7 @@ struct drm_fbdev_cma {
* *
* Example fbdev deferred io code:: * Example fbdev deferred io code::
* *
* static int driver_fbdev_fb_dirty(struct drm_framebuffer *fb, * static int driver_fb_dirty(struct drm_framebuffer *fb,
* struct drm_file *file_priv, * struct drm_file *file_priv,
* unsigned flags, unsigned color, * unsigned flags, unsigned color,
* struct drm_clip_rect *clips, * struct drm_clip_rect *clips,
...@@ -69,28 +70,18 @@ struct drm_fbdev_cma { ...@@ -69,28 +70,18 @@ struct drm_fbdev_cma {
* return 0; * return 0;
* } * }
* *
* static struct drm_framebuffer_funcs driver_fbdev_fb_funcs = { * static struct drm_framebuffer_funcs driver_fb_funcs = {
* .destroy = drm_fb_cma_destroy, * .destroy = drm_fb_cma_destroy,
* .create_handle = drm_fb_cma_create_handle, * .create_handle = drm_fb_cma_create_handle,
* .dirty = driver_fbdev_fb_dirty, * .dirty = driver_fb_dirty,
* }; * };
* *
* static int driver_fbdev_create(struct drm_fb_helper *helper, * Initialize::
* struct drm_fb_helper_surface_size *sizes)
* {
* return drm_fbdev_cma_create_with_funcs(helper, sizes,
* &driver_fbdev_fb_funcs);
* }
*
* static const struct drm_fb_helper_funcs driver_fb_helper_funcs = {
* .fb_probe = driver_fbdev_create,
* };
* *
* Initialize:
* fbdev = drm_fbdev_cma_init_with_funcs(dev, 16, * fbdev = drm_fbdev_cma_init_with_funcs(dev, 16,
* dev->mode_config.num_crtc, * dev->mode_config.num_crtc,
* dev->mode_config.num_connector, * dev->mode_config.num_connector,
* &driver_fb_helper_funcs); * &driver_fb_funcs);
* *
*/ */
...@@ -408,13 +399,9 @@ static void drm_fbdev_cma_defio_fini(struct fb_info *fbi) ...@@ -408,13 +399,9 @@ static void drm_fbdev_cma_defio_fini(struct fb_info *fbi)
kfree(fbi->fbops); kfree(fbi->fbops);
} }
/* static int
* For use in a (struct drm_fb_helper_funcs *)->fb_probe callback function that drm_fbdev_cma_create(struct drm_fb_helper *helper,
* needs custom struct drm_framebuffer_funcs, like dirty() for deferred_io use. struct drm_fb_helper_surface_size *sizes)
*/
int drm_fbdev_cma_create_with_funcs(struct drm_fb_helper *helper,
struct drm_fb_helper_surface_size *sizes,
const struct drm_framebuffer_funcs *funcs)
{ {
struct drm_fbdev_cma *fbdev_cma = to_fbdev_cma(helper); struct drm_fbdev_cma *fbdev_cma = to_fbdev_cma(helper);
struct drm_mode_fb_cmd2 mode_cmd = { 0 }; struct drm_mode_fb_cmd2 mode_cmd = { 0 };
...@@ -450,7 +437,8 @@ int drm_fbdev_cma_create_with_funcs(struct drm_fb_helper *helper, ...@@ -450,7 +437,8 @@ int drm_fbdev_cma_create_with_funcs(struct drm_fb_helper *helper,
goto err_gem_free_object; goto err_gem_free_object;
} }
fbdev_cma->fb = drm_fb_cma_alloc(dev, &mode_cmd, &obj, 1, funcs); fbdev_cma->fb = drm_fb_cma_alloc(dev, &mode_cmd, &obj, 1,
fbdev_cma->fb_funcs);
if (IS_ERR(fbdev_cma->fb)) { if (IS_ERR(fbdev_cma->fb)) {
dev_err(dev->dev, "Failed to allocate DRM framebuffer.\n"); dev_err(dev->dev, "Failed to allocate DRM framebuffer.\n");
ret = PTR_ERR(fbdev_cma->fb); ret = PTR_ERR(fbdev_cma->fb);
...@@ -476,7 +464,7 @@ int drm_fbdev_cma_create_with_funcs(struct drm_fb_helper *helper, ...@@ -476,7 +464,7 @@ int drm_fbdev_cma_create_with_funcs(struct drm_fb_helper *helper,
fbi->screen_size = size; fbi->screen_size = size;
fbi->fix.smem_len = size; fbi->fix.smem_len = size;
if (funcs->dirty) { if (fbdev_cma->fb_funcs->dirty) {
ret = drm_fbdev_cma_defio_init(fbi, obj); ret = drm_fbdev_cma_defio_init(fbi, obj);
if (ret) if (ret)
goto err_cma_destroy; goto err_cma_destroy;
...@@ -493,13 +481,6 @@ int drm_fbdev_cma_create_with_funcs(struct drm_fb_helper *helper, ...@@ -493,13 +481,6 @@ int drm_fbdev_cma_create_with_funcs(struct drm_fb_helper *helper,
drm_gem_object_unreference_unlocked(&obj->base); drm_gem_object_unreference_unlocked(&obj->base);
return ret; return ret;
} }
EXPORT_SYMBOL(drm_fbdev_cma_create_with_funcs);
static int drm_fbdev_cma_create(struct drm_fb_helper *helper,
struct drm_fb_helper_surface_size *sizes)
{
return drm_fbdev_cma_create_with_funcs(helper, sizes, &drm_fb_cma_funcs);
}
static const struct drm_fb_helper_funcs drm_fb_cma_helper_funcs = { static const struct drm_fb_helper_funcs drm_fb_cma_helper_funcs = {
.fb_probe = drm_fbdev_cma_create, .fb_probe = drm_fbdev_cma_create,
...@@ -511,13 +492,13 @@ static const struct drm_fb_helper_funcs drm_fb_cma_helper_funcs = { ...@@ -511,13 +492,13 @@ static const struct drm_fb_helper_funcs drm_fb_cma_helper_funcs = {
* @preferred_bpp: Preferred bits per pixel for the device * @preferred_bpp: Preferred bits per pixel for the device
* @num_crtc: Number of CRTCs * @num_crtc: Number of CRTCs
* @max_conn_count: Maximum number of connectors * @max_conn_count: Maximum number of connectors
* @funcs: fb helper functions, in particular fb_probe() * @funcs: fb helper functions, in particular a custom dirty() callback
* *
* Returns a newly allocated drm_fbdev_cma struct or a ERR_PTR. * Returns a newly allocated drm_fbdev_cma struct or a ERR_PTR.
*/ */
struct drm_fbdev_cma *drm_fbdev_cma_init_with_funcs(struct drm_device *dev, struct drm_fbdev_cma *drm_fbdev_cma_init_with_funcs(struct drm_device *dev,
unsigned int preferred_bpp, unsigned int num_crtc, unsigned int preferred_bpp, unsigned int num_crtc,
unsigned int max_conn_count, const struct drm_fb_helper_funcs *funcs) unsigned int max_conn_count, const struct drm_framebuffer_funcs *funcs)
{ {
struct drm_fbdev_cma *fbdev_cma; struct drm_fbdev_cma *fbdev_cma;
struct drm_fb_helper *helper; struct drm_fb_helper *helper;
...@@ -528,10 +509,11 @@ struct drm_fbdev_cma *drm_fbdev_cma_init_with_funcs(struct drm_device *dev, ...@@ -528,10 +509,11 @@ struct drm_fbdev_cma *drm_fbdev_cma_init_with_funcs(struct drm_device *dev,
dev_err(dev->dev, "Failed to allocate drm fbdev.\n"); dev_err(dev->dev, "Failed to allocate drm fbdev.\n");
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
fbdev_cma->fb_funcs = funcs;
helper = &fbdev_cma->fb_helper; helper = &fbdev_cma->fb_helper;
drm_fb_helper_prepare(dev, helper, funcs); drm_fb_helper_prepare(dev, helper, &drm_fb_cma_helper_funcs);
ret = drm_fb_helper_init(dev, helper, num_crtc, max_conn_count); ret = drm_fb_helper_init(dev, helper, num_crtc, max_conn_count);
if (ret < 0) { if (ret < 0) {
...@@ -577,7 +559,7 @@ struct drm_fbdev_cma *drm_fbdev_cma_init(struct drm_device *dev, ...@@ -577,7 +559,7 @@ struct drm_fbdev_cma *drm_fbdev_cma_init(struct drm_device *dev,
unsigned int max_conn_count) unsigned int max_conn_count)
{ {
return drm_fbdev_cma_init_with_funcs(dev, preferred_bpp, num_crtc, return drm_fbdev_cma_init_with_funcs(dev, preferred_bpp, num_crtc,
max_conn_count, &drm_fb_cma_helper_funcs); max_conn_count, &drm_fb_cma_funcs);
} }
EXPORT_SYMBOL_GPL(drm_fbdev_cma_init); EXPORT_SYMBOL_GPL(drm_fbdev_cma_init);
......
...@@ -17,7 +17,7 @@ struct drm_plane_state; ...@@ -17,7 +17,7 @@ struct drm_plane_state;
struct drm_fbdev_cma *drm_fbdev_cma_init_with_funcs(struct drm_device *dev, struct drm_fbdev_cma *drm_fbdev_cma_init_with_funcs(struct drm_device *dev,
unsigned int preferred_bpp, unsigned int num_crtc, unsigned int preferred_bpp, unsigned int num_crtc,
unsigned int max_conn_count, const struct drm_fb_helper_funcs *funcs); unsigned int max_conn_count, const struct drm_framebuffer_funcs *funcs);
struct drm_fbdev_cma *drm_fbdev_cma_init(struct drm_device *dev, struct drm_fbdev_cma *drm_fbdev_cma_init(struct drm_device *dev,
unsigned int preferred_bpp, unsigned int num_crtc, unsigned int preferred_bpp, unsigned int num_crtc,
unsigned int max_conn_count); unsigned int max_conn_count);
...@@ -26,9 +26,6 @@ void drm_fbdev_cma_fini(struct drm_fbdev_cma *fbdev_cma); ...@@ -26,9 +26,6 @@ void drm_fbdev_cma_fini(struct drm_fbdev_cma *fbdev_cma);
void drm_fbdev_cma_restore_mode(struct drm_fbdev_cma *fbdev_cma); void drm_fbdev_cma_restore_mode(struct drm_fbdev_cma *fbdev_cma);
void drm_fbdev_cma_hotplug_event(struct drm_fbdev_cma *fbdev_cma); void drm_fbdev_cma_hotplug_event(struct drm_fbdev_cma *fbdev_cma);
void drm_fbdev_cma_set_suspend(struct drm_fbdev_cma *fbdev_cma, int state); void drm_fbdev_cma_set_suspend(struct drm_fbdev_cma *fbdev_cma, int state);
int drm_fbdev_cma_create_with_funcs(struct drm_fb_helper *helper,
struct drm_fb_helper_surface_size *sizes,
const struct drm_framebuffer_funcs *funcs);
void drm_fb_cma_destroy(struct drm_framebuffer *fb); void drm_fb_cma_destroy(struct drm_framebuffer *fb);
int drm_fb_cma_create_handle(struct drm_framebuffer *fb, int drm_fb_cma_create_handle(struct drm_framebuffer *fb,
......
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