drm/fb-helper: Don't clobber the display palette when fbdev isn't bound
Subsystems (10)
PATCH v2 1/3 drm/fb-helper: Don't clobber the display palette when fbdev isn't bound
From: Ville Syrjälä <[email protected]>
Perform the drm_fb_helper_is_bound() check to avoid clobbering the display palette of some other KMS client.
While at it, fix up the locking by grabbing all modeset locks for the duration of the fb_setcmap operation.
v2: Make a note of the locking changes in the commit message
--- drivers/gpu/drm/drm_fb_helper.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_fb_helper.c +10 -1
@@ -626,12 +626,19 @@ static int setcolreg(struct drm_crtc *crtc, u16 red, u16 green,int drm_fb_helper_setcmap (struct fb_cmap *cmap,struct fb_info *info) {struct drm_fb_helper *fb_helper = info->par; +struct drm_device *dev = fb_helper->dev;struct drm_crtc_helper_funcs *crtc_funcs;u16 *red, *green, *blue, *transp;struct drm_crtc *crtc;int i, j, rc =0 ;int start; +drm_modeset_lock_all (dev); +if (!drm_fb_helper_is_bound (fb_helper)) { +drm_modeset_unlock_all (dev); +return -EBUSY ; + } +for (i =0 ; i < fb_helper->crtc_count; i++) { crtc = fb_helper->crtc_info[i].mode_set.crtc; crtc_funcs = crtc->helper_private;
@@ -654,10 +661,12 @@ int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info) rc =setcolreg (crtc, hred, hgreen, hblue, start++, info);if (rc) -return rc; + goto out; } crtc_funcs->load_lut (crtc); } + out: +drm_modeset_unlock_all (dev);return rc; }EXPORT_SYMBOL (drm_fb_helper_setcmap);
Signature · 6 lines
1.8.1.5 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/3 drm/fb-helper: Make load_lut and gamma_set/gamma_get hooks optional
From: Ville Syrjälä <[email protected]>
Check whether the crtc provides the load_lut callback before calling it. This allows the driver to provide the hook only for those CRTCs that actually have the hardware support for it.
Also check whether the driver provided the fb_helper gamma_set/gamma_get hooks. It's a driver bug if it allows non-truecolor fbdev visuals w/o these hooks, but auditing all the drivers is too tedious. So just slap a big WARN_ON() there and bail out before things start to explode.
--- drivers/gpu/drm/drm_fb_helper.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_fb_helper.c +13 -1
@@ -168,6 +168,9 @@ static void drm_fb_helper_save_lut_atomic(struct drm_crtc *crtc, struct drm_fb_huint16_t *r_base, *g_base, *b_base;int i; +if (helper->funcs->gamma_get ==NULL ) +return ; + r_base = crtc->gamma_store; g_base = r_base + crtc->gamma_size; b_base = g_base + crtc->gamma_size;
@@ -583,6 +586,14 @@ static int setcolreg(struct drm_crtc *crtc, u16 red, u16 green,return 0 ; } +/* +* The driver really shouldn't advertise pseudo/directcolor +* visuals if it can't deal with the palette. +*/ +if (WARN_ON (!fb_helper->funcs->gamma_set || + !fb_helper->funcs->gamma_get)) +return -EINVAL ; + pindex = regno;if (fb->bits_per_pixel ==16 ) {
@@ -663,7 +674,8 @@ int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info)if (rc) goto out; } - crtc_funcs->load_lut (crtc); +if (crtc_funcs->load_lut) + crtc_funcs->load_lut (crtc); } out:drm_modeset_unlock_all (dev);
Signature · 6 lines
1.8.1.5 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 3/3 drm: Drop all the stub gamma_get, gamma_set, load_lut functions from drivers
In reply to [email protected]From: Ville Syrjälä <[email protected]>
Many of the drivers didn't implement palette/gamma handling, but were forced to provide stubs for the hooks to avoid drm_fb_helper from oopsing. Now that the hooks are optional, we can eliminate all the stubs.
--- drivers/gpu/drm/exynos/exynos_drm_crtc.c | 7 ------- drivers/gpu/drm/omapdrm/omap_crtc.c | 5 ----- drivers/gpu/drm/omapdrm/omap_fbdev.c | 14 -------------- drivers/gpu/drm/qxl/qxl_display.c | 13 ------------- drivers/gpu/drm/qxl/qxl_fb.c | 4 ---- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 5 ----- drivers/gpu/drm/udl/udl_fb.c | 15 --------------- drivers/gpu/drm/udl/udl_modeset.c | 5 ----- drivers/staging/imx-drm/ipuv3-crtc.c | 5 ----- 9 files changed, 73 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_crtc.c +0 -7
@@ -160,12 +160,6 @@ static int exynos_drm_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,return 0 ; } -static void exynos_drm_crtc_load_lut (struct drm_crtc *crtc) -{ -DRM_DEBUG_KMS ("%s\n" , __FILE__); -/* drm framework doesn't check NULL */ -} -static void exynos_drm_crtc_disable (struct drm_crtc *crtc) {struct exynos_drm_crtc *exynos_crtc =to_exynos_crtc (crtc);
@@ -183,7 +177,6 @@ static struct drm_crtc_helper_funcs exynos_crtc_helper_funcs = { .mode_fixup = exynos_drm_crtc_mode_fixup, .mode_set = exynos_drm_crtc_mode_set, .mode_set_base = exynos_drm_crtc_mode_set_base, - .load_lut = exynos_drm_crtc_load_lut, .disable = exynos_drm_crtc_disable, };
drivers/gpu/drm/omapdrm/omap_crtc.c +0 -5
@@ -253,10 +253,6 @@ static int omap_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, NULL, NULL); } -static void omap_crtc_load_lut (struct drm_crtc *crtc) -{ -} -static void vblank_cb (void *arg) {struct drm_crtc *crtc = arg;
@@ -366,7 +362,6 @@ static const struct drm_crtc_helper_funcs omap_crtc_helper_funcs = { .prepare = omap_crtc_prepare, .commit = omap_crtc_commit, .mode_set_base = omap_crtc_mode_set_base, - .load_lut = omap_crtc_load_lut, };const struct omap_video_timings *omap_crtc_timings (struct drm_crtc *crtc)
drivers/gpu/drm/omapdrm/omap_fbdev.c +0 -14
@@ -281,21 +281,7 @@ fail:return ret; } -static void omap_crtc_fb_gamma_set (struct drm_crtc *crtc, -u16 red,u16 green,u16 blue,int regno) -{ -DBG ("fbdev: set gamma" ); -} - -static void omap_crtc_fb_gamma_get (struct drm_crtc *crtc, -u16 *red,u16 *green,u16 *blue,int regno) -{ -DBG ("fbdev: get gamma" ); -} -static struct drm_fb_helper_funcs omap_fb_helper_funcs = { - .gamma_set = omap_crtc_fb_gamma_set, - .gamma_get = omap_crtc_fb_gamma_get, .fb_probe = omap_fbdev_create, };
drivers/gpu/drm/qxl/qxl_display.c +0 -13
@@ -222,12 +222,6 @@ static int qxl_add_common_modes(struct drm_connector *connector)return i -1 ; } -static void qxl_crtc_gamma_set (struct drm_crtc *crtc,u16 *red,u16 *green, -u16 *blue,uint32_t start,uint32_t size) -{ -/* TODO */ -} -static void qxl_crtc_destroy (struct drm_crtc *crtc) {struct qxl_crtc *qxl_crtc =to_qxl_crtc (crtc);
@@ -399,7 +393,6 @@ static int qxl_crtc_cursor_move(struct drm_crtc *crtc,static const struct drm_crtc_funcs qxl_crtc_funcs = { .cursor_set = qxl_crtc_cursor_set, .cursor_move = qxl_crtc_cursor_move, - .gamma_set = qxl_crtc_gamma_set, .set_config = drm_crtc_helper_set_config, .destroy = qxl_crtc_destroy, };
@@ -619,18 +612,12 @@ static void qxl_crtc_commit(struct drm_crtc *crtc)DRM_DEBUG ("\n" ); } -static void qxl_crtc_load_lut (struct drm_crtc *crtc) -{ -DRM_DEBUG ("\n" ); -} -static const struct drm_crtc_helper_funcs qxl_crtc_helper_funcs = { .dpms = qxl_crtc_dpms, .mode_fixup = qxl_crtc_mode_fixup, .mode_set = qxl_crtc_mode_set, .prepare = qxl_crtc_prepare, .commit = qxl_crtc_commit, - .load_lut = qxl_crtc_load_lut, };static int qdev_crtc_init (struct drm_device *dev,int num_crtc)
drivers/gpu/drm/qxl/qxl_fb.c +0 -4
@@ -520,10 +520,6 @@ static int qxl_fbdev_destroy(struct drm_device *dev, struct qxl_fbdev *qfbdev) }static struct drm_fb_helper_funcs qxl_fb_helper_funcs = { -/* TODO -.gamma_set = qxl_crtc_fb_gamma_set, -.gamma_get = qxl_crtc_fb_gamma_get, -*/ .fb_probe = qxl_fb_find_or_create_single, };
drivers/gpu/drm/tilcdc/tilcdc_crtc.c +0 -5
@@ -384,10 +384,6 @@ static int tilcdc_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,return 0 ; } -static void tilcdc_crtc_load_lut (struct drm_crtc *crtc) -{ -} -static const struct drm_crtc_funcs tilcdc_crtc_funcs = { .destroy = tilcdc_crtc_destroy, .set_config = drm_crtc_helper_set_config,
@@ -401,7 +397,6 @@ static const struct drm_crtc_helper_funcs tilcdc_crtc_helper_funcs = { .commit = tilcdc_crtc_commit, .mode_set = tilcdc_crtc_mode_set, .mode_set_base = tilcdc_crtc_mode_set_base, - .load_lut = tilcdc_crtc_load_lut, };int tilcdc_crtc_max_width (struct drm_crtc *crtc)
drivers/gpu/drm/udl/udl_fb.c +0 -15
@@ -393,19 +393,6 @@ static struct fb_ops udlfb_ops = { .fb_release = udl_fb_release, }; -static void udl_crtc_fb_gamma_set (struct drm_crtc *crtc,u16 red,u16 green, -u16 blue,int regno) -{ -} - -static void udl_crtc_fb_gamma_get (struct drm_crtc *crtc,u16 *red,u16 *green, -u16 *blue,int regno) -{ - *red =0 ; - *green =0 ; - *blue =0 ; -} - static int udl_user_framebuffer_dirty(struct drm_framebuffer *fb, struct drm_file *file, unsigned flags, unsigned color,
@@ -558,8 +545,6 @@ out: }static struct drm_fb_helper_funcs udl_fb_helper_funcs = { - .gamma_set = udl_crtc_fb_gamma_set, - .gamma_get = udl_crtc_fb_gamma_get, .fb_probe = udlfb_create, };
drivers/gpu/drm/udl/udl_modeset.c +0 -5
@@ -363,10 +363,6 @@ static void udl_crtc_destroy(struct drm_crtc *crtc)kfree (crtc); } -static void udl_load_lut (struct drm_crtc *crtc) -{ -} -static void udl_crtc_prepare (struct drm_crtc *crtc) { }
@@ -383,7 +379,6 @@ static struct drm_crtc_helper_funcs udl_helper_funcs = { .prepare = udl_crtc_prepare, .commit = udl_crtc_commit, .disable = udl_crtc_disable, - .load_lut = udl_load_lut, };static const struct drm_crtc_funcs udl_crtc_funcs = {
drivers/staging/imx-drm/ipuv3-crtc.c +0 -5
@@ -381,17 +381,12 @@ static void ipu_crtc_commit(struct drm_crtc *crtc)ipu_fb_enable (ipu_crtc); } -static void ipu_crtc_load_lut (struct drm_crtc *crtc) -{ -} -static struct drm_crtc_helper_funcs ipu_helper_funcs = { .dpms = ipu_crtc_dpms, .mode_fixup = ipu_crtc_mode_fixup, .mode_set = ipu_crtc_mode_set, .prepare = ipu_crtc_prepare, .commit = ipu_crtc_commit, - .load_lut = ipu_crtc_load_lut, };static int ipu_enable_vblank (struct drm_crtc *crtc)
Signature · 6 lines
1.8.1.5 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 3/3] drm: Drop all the stub gamma_get, gamma_set, load_lut functions from drivers
Quoted 7 lines · On Mon, May 27, 2013 at 08:19:58PM +0300, [email protected] wrote:
From: Ville Syrjälä <[email protected]>
Many of the drivers didn't implement palette/gamma handling, but were forced to provide stubs for the hooks to avoid
drm_fb_helperfrom oopsing. Now that the hooks are optional, we can eliminate all the stubs.Signed-off-by Ville Syrjälä <[email protected]>
On the series:
Quoted 253 lines
--- drivers/gpu/drm/exynos/exynos_drm_crtc.c | 7 ------- drivers/gpu/drm/omapdrm/omap_crtc.c | 5 ----- drivers/gpu/drm/omapdrm/omap_fbdev.c | 14 -------------- drivers/gpu/drm/qxl/qxl_display.c | 13 ------------- drivers/gpu/drm/qxl/qxl_fb.c | 4 ---- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 5 ----- drivers/gpu/drm/udl/udl_fb.c | 15 --------------- drivers/gpu/drm/udl/udl_modeset.c | 5 ----- drivers/staging/imx-drm/ipuv3-crtc.c | 5 ----- 9 files changed, 73 deletions(-)drivers/gpu/drm/exynos/exynos_drm_crtc.c +0
-7@@ -160,12 +160,6 @@ static int exynos_drm_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,return 0 ; } -static void exynos_drm_crtc_load_lut (struct drm_crtc *crtc) -{ -DRM_DEBUG_KMS ("%s\n" , __FILE__); -/* drm framework doesn't check NULL */ -} -static void exynos_drm_crtc_disable (struct drm_crtc *crtc) {struct exynos_drm_crtc *exynos_crtc =to_exynos_crtc (crtc);@@ -183,7 +177,6 @@ static struct drm_crtc_helper_funcs exynos_crtc_helper_funcs = { .mode_fixup = exynos_drm_crtc_mode_fixup, .mode_set = exynos_drm_crtc_mode_set, .mode_set_base = exynos_drm_crtc_mode_set_base, - .load_lut = exynos_drm_crtc_load_lut, .disable = exynos_drm_crtc_disable, };drivers/gpu/drm/omapdrm/omap_crtc.c +0
-5@@ -253,10 +253,6 @@ static int omap_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, NULL, NULL); } -static void omap_crtc_load_lut (struct drm_crtc *crtc) -{ -} -static void vblank_cb (void *arg) {struct drm_crtc *crtc = arg;@@ -366,7 +362,6 @@ static const struct drm_crtc_helper_funcs omap_crtc_helper_funcs = { .prepare = omap_crtc_prepare, .commit = omap_crtc_commit, .mode_set_base = omap_crtc_mode_set_base, - .load_lut = omap_crtc_load_lut, };const struct omap_video_timings *omap_crtc_timings (struct drm_crtc *crtc)drivers/gpu/drm/omapdrm/omap_fbdev.c +0
-14@@ -281,21 +281,7 @@ fail:return ret; } -static void omap_crtc_fb_gamma_set (struct drm_crtc *crtc, -u16 red,u16 green,u16 blue,int regno) -{ -DBG ("fbdev: set gamma" ); -} - -static void omap_crtc_fb_gamma_get (struct drm_crtc *crtc, -u16 *red,u16 *green,u16 *blue,int regno) -{ -DBG ("fbdev: get gamma" ); -} -static struct drm_fb_helper_funcs omap_fb_helper_funcs = { - .gamma_set = omap_crtc_fb_gamma_set, - .gamma_get = omap_crtc_fb_gamma_get, .fb_probe = omap_fbdev_create, };drivers/gpu/drm/qxl/qxl_display.c +0
-13@@ -222,12 +222,6 @@ static int qxl_add_common_modes(struct drm_connector *connector)return i -1 ; } -static void qxl_crtc_gamma_set (struct drm_crtc *crtc,u16 *red,u16 *green, -u16 *blue,uint32_t start,uint32_t size) -{ -/* TODO */ -} -static void qxl_crtc_destroy (struct drm_crtc *crtc) {struct qxl_crtc *qxl_crtc =to_qxl_crtc (crtc);@@ -399,7 +393,6 @@ static int qxl_crtc_cursor_move(struct drm_crtc *crtc,static const struct drm_crtc_funcs qxl_crtc_funcs = { .cursor_set = qxl_crtc_cursor_set, .cursor_move = qxl_crtc_cursor_move, - .gamma_set = qxl_crtc_gamma_set, .set_config = drm_crtc_helper_set_config, .destroy = qxl_crtc_destroy, };@@ -619,18 +612,12 @@ static void qxl_crtc_commit(struct drm_crtc *crtc)DRM_DEBUG ("\n" ); } -static void qxl_crtc_load_lut (struct drm_crtc *crtc) -{ -DRM_DEBUG ("\n" ); -} -static const struct drm_crtc_helper_funcs qxl_crtc_helper_funcs = { .dpms = qxl_crtc_dpms, .mode_fixup = qxl_crtc_mode_fixup, .mode_set = qxl_crtc_mode_set, .prepare = qxl_crtc_prepare, .commit = qxl_crtc_commit, - .load_lut = qxl_crtc_load_lut, };static int qdev_crtc_init (struct drm_device *dev,int num_crtc)drivers/gpu/drm/qxl/qxl_fb.c +0
-4@@ -520,10 +520,6 @@ static int qxl_fbdev_destroy(struct drm_device *dev, struct qxl_fbdev *qfbdev) }static struct drm_fb_helper_funcs qxl_fb_helper_funcs = { -/* TODO -.gamma_set = qxl_crtc_fb_gamma_set, -.gamma_get = qxl_crtc_fb_gamma_get, -*/ .fb_probe = qxl_fb_find_or_create_single, };drivers/gpu/drm/tilcdc/tilcdc_crtc.c +0
-5@@ -384,10 +384,6 @@ static int tilcdc_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,return 0 ; } -static void tilcdc_crtc_load_lut (struct drm_crtc *crtc) -{ -} -static const struct drm_crtc_funcs tilcdc_crtc_funcs = { .destroy = tilcdc_crtc_destroy, .set_config = drm_crtc_helper_set_config,@@ -401,7 +397,6 @@ static const struct drm_crtc_helper_funcs tilcdc_crtc_helper_funcs = { .commit = tilcdc_crtc_commit, .mode_set = tilcdc_crtc_mode_set, .mode_set_base = tilcdc_crtc_mode_set_base, - .load_lut = tilcdc_crtc_load_lut, };int tilcdc_crtc_max_width (struct drm_crtc *crtc)drivers/gpu/drm/udl/udl_fb.c +0
-15@@ -393,19 +393,6 @@ static struct fb_ops udlfb_ops = { .fb_release = udl_fb_release, }; -static void udl_crtc_fb_gamma_set (struct drm_crtc *crtc,u16 red,u16 green, -u16 blue,int regno) -{ -} - -static void udl_crtc_fb_gamma_get (struct drm_crtc *crtc,u16 *red,u16 *green, -u16 *blue,int regno) -{ - *red =0 ; - *green =0 ; - *blue =0 ; -} - static int udl_user_framebuffer_dirty(struct drm_framebuffer *fb, struct drm_file *file, unsigned flags, unsigned color,@@ -558,8 +545,6 @@ out: }static struct drm_fb_helper_funcs udl_fb_helper_funcs = { - .gamma_set = udl_crtc_fb_gamma_set, - .gamma_get = udl_crtc_fb_gamma_get, .fb_probe = udlfb_create, };drivers/gpu/drm/udl/udl_modeset.c +0
-5@@ -363,10 +363,6 @@ static void udl_crtc_destroy(struct drm_crtc *crtc)kfree (crtc); } -static void udl_load_lut (struct drm_crtc *crtc) -{ -} -static void udl_crtc_prepare (struct drm_crtc *crtc) { }@@ -383,7 +379,6 @@ static struct drm_crtc_helper_funcs udl_helper_funcs = { .prepare = udl_crtc_prepare, .commit = udl_crtc_commit, .disable = udl_crtc_disable, - .load_lut = udl_load_lut, };static const struct drm_crtc_funcs udl_crtc_funcs = {drivers/staging/imx-drm/ipuv3-crtc.c +0
-5@@ -381,17 +381,12 @@ static void ipu_crtc_commit(struct drm_crtc *crtc)ipu_fb_enable (ipu_crtc); } -static void ipu_crtc_load_lut (struct drm_crtc *crtc) -{ -} -static struct drm_crtc_helper_funcs ipu_helper_funcs = { .dpms = ipu_crtc_dpms, .mode_fixup = ipu_crtc_mode_fixup, .mode_set = ipu_crtc_mode_set, .prepare = ipu_crtc_prepare, .commit = ipu_crtc_commit, - .load_lut = ipu_crtc_load_lut, };static int ipu_enable_vblank (struct drm_crtc *crtc)Signature · 6 lines
1.8.1.5 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch