Skip to contentSkip to conversation

drm/fb-helper: Don't clobber the display palette when fbdev isn't bound

PATCH Superseded [email protected] 2 participants 5 messages May 27, 2013

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 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.

---
 drivers/gpu/drm/drm_fb_helper.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_fb_helper.c +10 -1
index b78cbe7..1b6ca23 100644
@@ -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
#1 lore raw

PATCH 2/2 drm/fb-helper: Don't load the display palette if the CRTC is disabled

From: Ville Syrjälä <[email protected]>

Often the hardware needs certain clocks running when accessing the palette, so don't go poking at it if the CRTC is disabled. We still call the fb_helper gamma_set hooks to update the driver's notion of what the palette should contain, so that if/when CRTC gets enabled, the driver will load the correct palette.

---
The other option would of course to put the check into the load_lut function itself. I don't really care which way we do it as long as the check is somewhere...

 drivers/gpu/drm/drm_fb_helper.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_fb_helper.c +3 -1
index 1b6ca23..4ecf128 100644
@@ -663,7 +663,9 @@ int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info)
 			if (rc)
 				goto out;
 		}
-		crtc_funcs->load_lut(crtc);
+
+		if (crtc->enabled)
+			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
#2 lore raw

Re: [PATCH 2/2] drm/fb-helper: Don't load the display palette if the CRTC is disabled

Quoted 8 lines · On Mon, May 27, 2013 at 06:44:57PM +0300, [email protected] wrote:

From: Ville Syrjälä <[email protected]>

Often the hardware needs certain clocks running when accessing the palette, so don't go poking at it if the CRTC is disabled. We still call the fb_helper gamma_set hooks to update the driver's notion of what the palette should contain, so that if/when CRTC gets enabled, the driver will load the correct palette.

Quoted 5 lines

---
The other option would of course to put the check into the load_lut function itself. I don't really care which way we do it as long as the check is somewhere...

And I just realized we already have the check in i915 load_lut at least. Not sure how I failed to notice it before. So feel free to ignore this patch. Patch 1/2 still seems relevant though.

Quoted 21 lines
 drivers/gpu/drm/drm_fb_helper.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_fb_helper.c +3 -1
index 1b6ca23..4ecf128 100644
@@ -663,7 +663,9 @@ int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info)
 			if (rc)
 				goto out;
 		}
-		crtc_funcs->load_lut(crtc);
+
+		if (crtc->enabled)
+			crtc_funcs->load_lut(crtc);
 	}
  out:
 	drm_modeset_unlock_all(dev);
Signature · 1 line
1.8.1.5
Signature · 2 lines
Ville Syrjälä
Intel OTC
Acked-by on v1 2/2
#3 lore raw

Re: [PATCH 2/2] drm/fb-helper: Don't load the display palette if the CRTC is disabled

In reply to [email protected]
Quoted 22 lines · On Mon, May 27, 2013 at 06:44:57PM +0300, [email protected] wrote:

From: Ville Syrjälä <[email protected]>

Often the hardware needs certain clocks running when accessing the palette, so don't go poking at it if the CRTC is disabled. We still call the fb_helper gamma_set hooks to update the driver's notion of what the palette should contain, so that if/when CRTC gets enabled, the driver will load the correct palette.

---
The other option would of course to put the check into the load_lut function itself. I don't really care which way we do it as long as the check is somewhere...

 drivers/gpu/drm/drm_fb_helper.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_fb_helper.c +0 -0
index 1b6ca23..4ecf128 100644

drivers/gpu/drm/drm_fb_helper.c int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info) · line 667

Quoted 6 lines
drivers/gpu/drm/drm_fb_helper.c +2 -1
@@ -663,7 +663,9 @@ int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info)
 			if (rc)
 				goto out;
 		}
-		crtc_funcs->load_lut(crtc);
+
+		if (crtc->enabled)

I'd vote for if (crtc->enabled && crtc_funcs->load_lut) since a lot of kms drivers only implement dummy ->load_lut functions.

Then please also throw a pile of driver patches on top to kill all the now redundant crtc->enabled checks and all the dummy load_lut functions. With that fixed this is

Quoted 11 lines
drivers/gpu/drm/drm_fb_helper.c +1 -0
+			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
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
Reviewed-by on v1 1/2
#4 lore raw
In reply to [email protected]
Quoted 6 lines · On Mon, May 27, 2013 at 06:44:56PM +0300, [email protected] wrote:

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.

You might want to mention that you're also fixing up the locking a bit ;-) The lack of that would be much more obvious if the fbdev helper would use the real kms gamma interface instead of it's own driver backdoor. But that's a different patch to write.

Quoted 49 lines
---
 drivers/gpu/drm/drm_fb_helper.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_fb_helper.c +10 -1
index b78cbe7..1b6ca23 100644
@@ -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
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch