Skip to contentSkip to conversation

drm/i915: backlight locking, cleanup

PATCH Applied Jani Nikula 4 participants 20 messages Apr 12, 2013 – Apr 25, 2013

Subsystems (2)
lore
Share & tools
lore
#10 lore raw

PATCH 3/4 drm/i915: ensure single initialization and cleanup of backlight device

In reply to Jani Nikula

Backlight cleanup in the eDP connector destroy callback caused the backlight device to be removed on some systems that first initialized LVDS and then attempted to initialize eDP. Prevent multiple backlight initializations, and ensure backlight cleanup is only done once by moving it to modeset cleanup.

A small wrinkle is the introduced asymmetry in backlight setup/cleanup. This could be solved by adding refcounting, but it seems overkill considering that there should only ever be one backlight device.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=55701

---
 drivers/gpu/drm/i915/intel_display.c |    3 +++
 drivers/gpu/drm/i915/intel_dp.c      |    5 +----
 drivers/gpu/drm/i915/intel_lvds.c    |    1 -
 drivers/gpu/drm/i915/intel_panel.c   |    7 ++++++-
 4 files changed, 10 insertions(+), 6 deletions(-)
drivers/gpu/drm/i915/intel_display.c +3 -0
index 457a0a0..712b0af 100644
@@ -9419,6 +9419,9 @@ void intel_modeset_cleanup(struct drm_device *dev)
 	/* flush any delayed tasks or pending work */
 	flush_scheduled_work();
 
+	/* destroy backlight, if any, before the connectors */
+	intel_panel_destroy_backlight(dev);
+
 	drm_mode_config_cleanup(dev);
 
 	intel_cleanup_overlay(dev);
drivers/gpu/drm/i915/intel_dp.c +1 -4
index 173add1..8845e82 100644
@@ -2474,17 +2474,14 @@ done:
 static void
 intel_dp_destroy(struct drm_connector *connector)
 {
-	struct drm_device *dev = connector->dev;
 	struct intel_dp *intel_dp = intel_attached_dp(connector);
 	struct intel_connector *intel_connector = to_intel_connector(connector);
 
 	if (!IS_ERR_OR_NULL(intel_connector->edid))
 		kfree(intel_connector->edid);
 
-	if (is_edp(intel_dp)) {
-		intel_panel_destroy_backlight(dev);
+	if (is_edp(intel_dp))
 		intel_panel_fini(&intel_connector->panel);
-	}
 
 	drm_sysfs_connector_remove(connector);
 	drm_connector_cleanup(connector);
drivers/gpu/drm/i915/intel_lvds.c +0 -1
index ca2d903..f36f1ba 100644
@@ -631,7 +631,6 @@ static void intel_lvds_destroy(struct drm_connector *connector)
 	if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
 		kfree(lvds_connector->base.edid);
 
-	intel_panel_destroy_backlight(connector->dev);
 	intel_panel_fini(&lvds_connector->base.panel);
 
 	drm_sysfs_connector_remove(connector);
drivers/gpu/drm/i915/intel_panel.c +6 -1
index 464c3d7..5d3e9d7 100644
@@ -459,6 +459,9 @@ int intel_panel_setup_backlight(struct drm_connector *connector)
 
 	intel_panel_init_backlight(dev);
 
+	if (WARN_ON(dev_priv->backlight.device))
+		return -ENODEV;
+
 	memset(&props, 0, sizeof(props));
 	props.type = BACKLIGHT_RAW;
 	props.brightness = dev_priv->backlight.level;
@@ -488,8 +491,10 @@ int intel_panel_setup_backlight(struct drm_connector *connector)
 void intel_panel_destroy_backlight(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
-	if (dev_priv->backlight.device)
+	if (dev_priv->backlight.device) {
 		backlight_device_unregister(dev_priv->backlight.device);
+		dev_priv->backlight.device = NULL;
+	}
 }
 #else
 int intel_panel_setup_backlight(struct drm_connector *connector)
Signature · 1 line
1.7.9.5
#13 lore raw

PATCH 4/4 drm/i915: hsw backlight registers need transcoder instead of pipe

In reply to Jani Nikula
---
 drivers/gpu/drm/i915/intel_panel.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_panel.c +3 -1
index 5d3e9d7..0362f5c 100644
@@ -344,6 +344,8 @@ void intel_panel_enable_backlight(struct drm_device *dev,
 				  enum pipe pipe)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
+	enum transcoder cpu_transcoder =
+		intel_pipe_to_cpu_transcoder(dev_priv, pipe);
 	unsigned long flags;
 
 	spin_lock_irqsave(&dev_priv->backlight.lock, flags);
@@ -374,7 +376,7 @@ void intel_panel_enable_backlight(struct drm_device *dev,
 		else
 			tmp &= ~BLM_PIPE_SELECT;
 
-		tmp |= BLM_PIPE(pipe);
+		tmp |= BLM_PIPE(cpu_transcoder);
 		tmp &= ~BLM_PWM_ENABLE;
 
 		I915_WRITE(reg, tmp);
Signature · 1 line
1.7.9.5
#0 lore raw

cover drm/i915: backlight locking, cleanup

Patches 1-2 are for locking, 3-4 are related only by being backlight fixes.

I haven't tested these much...

BR,
Jani.

Jani Nikula (4):
drm/i915: keep max backlight internal to intel_panel.c drm/i915: protect backlight registers and data with a spinlock drm/i915: ensure single initialization and cleanup of backlight
device
drm/i915: hsw backlight registers need transcoder instead of pipe

 drivers/gpu/drm/i915/i915_dma.c       |    1 +
 drivers/gpu/drm/i915/i915_drv.h       |    1 +
 drivers/gpu/drm/i915/i915_suspend.c   |   10 ++++
 drivers/gpu/drm/i915/intel_display.c  |    3 ++
 drivers/gpu/drm/i915/intel_dp.c       |    5 +-
 drivers/gpu/drm/i915/intel_drv.h      |    4 +-
 drivers/gpu/drm/i915/intel_lvds.c     |    1 -
 drivers/gpu/drm/i915/intel_opregion.c |    4 +-
 drivers/gpu/drm/i915/intel_panel.c    |   90 ++++++++++++++++++++++++---------
 9 files changed, 85 insertions(+), 34 deletions(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/4 drm/i915: keep max backlight internal to intel_panel.c

In preparation of adding locking to backlight, make max backlight value (the modulation frequency the PWM duty cycle value must not exceed) internal to intel_panel.c.

Have intel_panel_set_backlight() accept a caller defined range for level, and scale input to max backlight value internally.

Clean up intel_panel_get_max_backlight() and usage internally.

---
 drivers/gpu/drm/i915/intel_drv.h      |    4 +--
 drivers/gpu/drm/i915/intel_opregion.c |    4 +--
 drivers/gpu/drm/i915/intel_panel.c    |   51 +++++++++++++++++++--------------
 3 files changed, 32 insertions(+), 27 deletions(-)
drivers/gpu/drm/i915/intel_drv.h +2 -2
index d7bd031..d2238d1 100644
@@ -520,8 +520,8 @@ extern void intel_pch_panel_fitting(struct drm_device *dev,
 				    int fitting_mode,
 				    const struct drm_display_mode *mode,
 				    struct drm_display_mode *adjusted_mode);
-extern u32 intel_panel_get_max_backlight(struct drm_device *dev);
-extern void intel_panel_set_backlight(struct drm_device *dev, u32 level);
+extern void intel_panel_set_backlight(struct drm_device *dev,
+				      u32 level, u32 max);
 extern int intel_panel_setup_backlight(struct drm_connector *connector);
 extern void intel_panel_enable_backlight(struct drm_device *dev,
 					 enum pipe pipe);
drivers/gpu/drm/i915/intel_opregion.c +1 -3
index 4d33874..42faa58 100644
@@ -152,7 +152,6 @@ static u32 asle_set_backlight(struct drm_device *dev, u32 bclp)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct opregion_asle __iomem *asle = dev_priv->opregion.asle;
-	u32 max;
 
 	DRM_DEBUG_DRIVER("bclp = 0x%08x\n", bclp);
 
@@ -163,8 +162,7 @@ static u32 asle_set_backlight(struct drm_device *dev, u32 bclp)
 	if (bclp > 255)
 		return ASLE_BACKLIGHT_FAILED;
 
-	max = intel_panel_get_max_backlight(dev);
-	intel_panel_set_backlight(dev, bclp * max / 255);
+	intel_panel_set_backlight(dev, bclp, 255);
 	iowrite32((bclp*0x64)/0xff | ASLE_CBLV_VALID, &asle->cblv);
 
 	return 0;
drivers/gpu/drm/i915/intel_panel.c +29 -22

102 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#3 lore raw

PATCH 2/4 drm/i915: protect backlight registers and data with a spinlock

In reply to Jani Nikula

Backlight data and registers are fiddled through LVDS/eDP modeset enable/disable hooks, backlight sysfs files, asle interrupts, and register save/restore. Protect the backlight related registers and driver private fields using a spinlock.

The locking in register save/restore covers a little more than is strictly necessary, including non-modeset case, for simplicity.

v2: Cover register access, save/restore, i915_read_blc_pwm_ctl() and code
paths leading there.

---
 drivers/gpu/drm/i915/i915_dma.c     |    1 +
 drivers/gpu/drm/i915/i915_drv.h     |    1 +
 drivers/gpu/drm/i915/i915_suspend.c |   10 ++++++++++
 drivers/gpu/drm/i915/intel_panel.c  |   30 +++++++++++++++++++++++++++++-
 4 files changed, 41 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_dma.c +1 -0
index 3b315ba..7751660 100644
@@ -1629,6 +1629,7 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
 	spin_lock_init(&dev_priv->irq_lock);
 	spin_lock_init(&dev_priv->gpu_error.lock);
 	spin_lock_init(&dev_priv->rps.lock);
+	spin_lock_init(&dev_priv->backlight.lock);
 	mutex_init(&dev_priv->dpio_lock);
 
 	mutex_init(&dev_priv->rps.hw_lock);
drivers/gpu/drm/i915/i915_drv.h +1 -0
index b5a495a..9aa9d60 100644
@@ -952,6 +952,7 @@ typedef struct drm_i915_private {
 	struct {
 		int level;
 		bool enabled;
+		spinlock_t lock; /* bl registers and the above bl fields */
 		struct backlight_device *device;
 	} backlight;
 
drivers/gpu/drm/i915/i915_suspend.c +10 -0
index 41f0fde..88b9a66 100644
@@ -192,6 +192,7 @@ static void i915_restore_vga(struct drm_device *dev)
 static void i915_save_display(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
+	unsigned long flags;
 
 	/* Display arbitration control */
 	if (INTEL_INFO(dev)->gen <= 4)
@@ -202,6 +203,8 @@ static void i915_save_display(struct drm_device *dev)
 	if (!drm_core_check_feature(dev, DRIVER_MODESET))
 		i915_save_display_reg(dev);
 
+	spin_lock_irqsave(&dev_priv->backlight.lock, flags);
+
 	/* LVDS state */
 	if (HAS_PCH_SPLIT(dev)) {
 		dev_priv->regfile.savePP_CONTROL = I915_READ(PCH_PP_CONTROL);
@@ -222,6 +225,8 @@ static void i915_save_display(struct drm_device *dev)
 			dev_priv->regfile.saveLVDS = I915_READ(LVDS);
 	}
 
+	spin_unlock_irqrestore(&dev_priv->backlight.lock, flags);
+
 	if (!IS_I830(dev) && !IS_845G(dev) && !HAS_PCH_SPLIT(dev))
 		dev_priv->regfile.savePFIT_CONTROL = I915_READ(PFIT_CONTROL);
 
@@ -257,6 +262,7 @@ static void i915_restore_display(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	u32 mask = 0xffffffff;
+	unsigned long flags;
 
 	/* Display arbitration */
 	if (INTEL_INFO(dev)->gen <= 4)
@@ -265,6 +271,8 @@ static void i915_restore_display(struct drm_device *dev)
 	if (!drm_core_check_feature(dev, DRIVER_MODESET))
 		i915_restore_display_reg(dev);
 
+	spin_lock_irqsave(&dev_priv->backlight.lock, flags);
+
 	/* LVDS state */
 	if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev))
 		I915_WRITE(BLC_PWM_CTL2, dev_priv->regfile.saveBLC_PWM_CTL2);
@@ -304,6 +312,8 @@ static void i915_restore_display(struct drm_device *dev)
 		I915_WRITE(PP_CONTROL, dev_priv->regfile.savePP_CONTROL);
 	}
 
+	spin_unlock_irqrestore(&dev_priv->backlight.lock, flags);
+
 	/* only restore FBC info on the platform that supports FBC*/
 	intel_disable_fbc(dev);
 	if (I915_HAS_FBC(dev)) {
drivers/gpu/drm/i915/intel_panel.c +29 -1
index acab67c..464c3d7 100644
@@ -138,6 +138,8 @@ static u32 i915_read_blc_pwm_ctl(struct drm_device *dev)
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	u32 val;
 
+	WARN_ON(!spin_is_locked(&dev_priv->backlight.lock));
+
 	/* Restore the CTL value if it lost, e.g. GPU reset */
 
 	if (HAS_PCH_SPLIT(dev_priv->dev)) {
@@ -218,6 +220,9 @@ static u32 intel_panel_get_backlight(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	u32 val;
+	unsigned long flags;
+
+	spin_lock_irqsave(&dev_priv->backlight.lock, flags);
 
 	if (HAS_PCH_SPLIT(dev)) {
 		val = I915_READ(BLC_PWM_CPU_CTL) & BACKLIGHT_DUTY_CYCLE_MASK;
@@ -235,6 +240,9 @@ static u32 intel_panel_get_backlight(struct drm_device *dev)
 	}
 
 	val = intel_panel_compute_brightness(dev, val);
+
+	spin_unlock_irqrestore(&dev_priv->backlight.lock, flags);
+
 	DRM_DEBUG_DRIVER("get backlight PWM = %d\n", val);
 	return val;
 }
@@ -282,11 +290,14 @@ void intel_panel_set_backlight(struct drm_device *dev, u32 level, u32 max)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	u32 freq;
+	unsigned long flags;
+
+	spin_lock_irqsave(&dev_priv->backlight.lock, flags);
 
 	freq = intel_panel_get_max_backlight(dev);
 	if (!freq) {
 		/* we are screwed, bail out */
-		return;
+		goto out;
 	}
 
 	/* scale to hardware */
@@ -298,11 +309,16 @@ void intel_panel_set_backlight(struct drm_device *dev, u32 level, u32 max)
 
 	if (dev_priv->backlight.enabled)
 		intel_panel_actually_set_backlight(dev, level);
+out:
+	spin_unlock_irqrestore(&dev_priv->backlight.lock, flags);
 }
 
 void intel_panel_disable_backlight(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
+	unsigned long flags;
+
+	spin_lock_irqsave(&dev_priv->backlight.lock, flags);
 
 	dev_priv->backlight.enabled = false;
 	intel_panel_actually_set_backlight(dev, 0);
@@ -320,12 +336,17 @@ void intel_panel_disable_backlight(struct drm_device *dev)
 			I915_WRITE(BLC_PWM_PCH_CTL1, tmp);
 		}
 	}
+
+	spin_unlock_irqrestore(&dev_priv->backlight.lock, flags);
 }
 
 void intel_panel_enable_backlight(struct drm_device *dev,
 				  enum pipe pipe)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
+	unsigned long flags;
+
+	spin_lock_irqsave(&dev_priv->backlight.lock, flags);
 
 	if (dev_priv->backlight.level == 0) {
 		dev_priv->backlight.level = intel_panel_get_max_backlight(dev);
@@ -375,6 +396,8 @@ set_level:
 	 */
 	dev_priv->backlight.enabled = true;
 	intel_panel_actually_set_backlight(dev, dev_priv->backlight.level);
+
+	spin_unlock_irqrestore(&dev_priv->backlight.lock, flags);
 }
 
 static void intel_panel_init_backlight(struct drm_device *dev)
@@ -432,13 +455,18 @@ int intel_panel_setup_backlight(struct drm_connector *connector)
 	struct drm_device *dev = connector->dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct backlight_properties props;
+	unsigned long flags;
 
 	intel_panel_init_backlight(dev);
 
 	memset(&props, 0, sizeof(props));
 	props.type = BACKLIGHT_RAW;
 	props.brightness = dev_priv->backlight.level;
+
+	spin_lock_irqsave(&dev_priv->backlight.lock, flags);
 	props.max_brightness = intel_panel_get_max_backlight(dev);
+	spin_unlock_irqrestore(&dev_priv->backlight.lock, flags);
+
 	if (props.max_brightness == 0) {
 		DRM_DEBUG_DRIVER("Failed to get maximum backlight value\n");
 		return -ENODEV;
Signature · 1 line
1.7.9.5
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] drm/i915: keep max backlight internal to intel_panel.c

In reply to Jani Nikula
Quoted 10 lines · Jani Nikula

In preparation of adding locking to backlight, make max backlight value (the modulation frequency the PWM duty cycle value must not exceed) internal to intel_panel.c.

Have intel_panel_set_backlight() accept a caller defined range for level, and scale input to max backlight value internally.

Clean up intel_panel_get_max_backlight() and usage internally.

Nice idea,

-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
author Tested-by Peter Verthez on v1 3/4
#11 lore raw

Re: [PATCH 3/4] drm/i915: ensure single initialization and cleanup of backlight device

In reply to Jani Nikula
Quoted 11 lines · Jani Nikula

Backlight cleanup in the eDP connector destroy callback caused the backlight device to be removed on some systems that first initialized LVDS and then attempted to initialize eDP. Prevent multiple backlight initializations, and ensure backlight cleanup is only done once by moving it to modeset cleanup.

A small wrinkle is the introduced asymmetry in backlight setup/cleanup. This could be solved by adding refcounting, but it seems overkill considering that there should only ever be one backlight device.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=55701

Via bugzilla,

CC Stable?
Quoted 85 lines
---
 drivers/gpu/drm/i915/intel_display.c |    3 +++
 drivers/gpu/drm/i915/intel_dp.c      |    5 +----
 drivers/gpu/drm/i915/intel_lvds.c    |    1 -
 drivers/gpu/drm/i915/intel_panel.c   |    7 ++++++-
 4 files changed, 10 insertions(+), 6 deletions(-)
drivers/gpu/drm/i915/intel_display.c +3 -0
index 457a0a0..712b0af 100644
@@ -9419,6 +9419,9 @@ void intel_modeset_cleanup(struct drm_device *dev)
 	/* flush any delayed tasks or pending work */
 	flush_scheduled_work();
 
+	/* destroy backlight, if any, before the connectors */
+	intel_panel_destroy_backlight(dev);
+
 	drm_mode_config_cleanup(dev);
 
 	intel_cleanup_overlay(dev);
drivers/gpu/drm/i915/intel_dp.c +1 -4
index 173add1..8845e82 100644
@@ -2474,17 +2474,14 @@ done:
 static void
 intel_dp_destroy(struct drm_connector *connector)
 {
-	struct drm_device *dev = connector->dev;
 	struct intel_dp *intel_dp = intel_attached_dp(connector);
 	struct intel_connector *intel_connector = to_intel_connector(connector);
 
 	if (!IS_ERR_OR_NULL(intel_connector->edid))
 		kfree(intel_connector->edid);
 
-	if (is_edp(intel_dp)) {
-		intel_panel_destroy_backlight(dev);
+	if (is_edp(intel_dp))
 		intel_panel_fini(&intel_connector->panel);
-	}
 
 	drm_sysfs_connector_remove(connector);
 	drm_connector_cleanup(connector);
drivers/gpu/drm/i915/intel_lvds.c +0 -1
index ca2d903..f36f1ba 100644
@@ -631,7 +631,6 @@ static void intel_lvds_destroy(struct drm_connector *connector)
 	if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
 		kfree(lvds_connector->base.edid);
 
-	intel_panel_destroy_backlight(connector->dev);
 	intel_panel_fini(&lvds_connector->base.panel);
 
 	drm_sysfs_connector_remove(connector);
drivers/gpu/drm/i915/intel_panel.c +6 -1
index 464c3d7..5d3e9d7 100644
@@ -459,6 +459,9 @@ int intel_panel_setup_backlight(struct drm_connector *connector)
 
 	intel_panel_init_backlight(dev);
 
+	if (WARN_ON(dev_priv->backlight.device))
+		return -ENODEV;
+
 	memset(&props, 0, sizeof(props));
 	props.type = BACKLIGHT_RAW;
 	props.brightness = dev_priv->backlight.level;
@@ -488,8 +491,10 @@ int intel_panel_setup_backlight(struct drm_connector *connector)
 void intel_panel_destroy_backlight(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
-	if (dev_priv->backlight.device)
+	if (dev_priv->backlight.device) {
 		backlight_device_unregister(dev_priv->backlight.device);
+		dev_priv->backlight.device = NULL;
+	}
 }
 #else
 int intel_panel_setup_backlight(struct drm_connector *connector)
Signature · 1 line
1.7.9.5
#12 lore raw

Re: [PATCH 3/4] drm/i915: ensure single initialization and cleanup of backlight device

Quoted 11 lines · Jani Nikula
Quoted 10 lines · Jani Nikula

Backlight cleanup in the eDP connector destroy callback caused the backlight device to be removed on some systems that first initialized LVDS and then attempted to initialize eDP. Prevent multiple backlight initializations, and ensure backlight cleanup is only done once by moving it to modeset cleanup.

A small wrinkle is the introduced asymmetry in backlight setup/cleanup. This could be solved by adding refcounting, but it seems overkill considering that there should only ever be one backlight device.

Quoted 7 lines
Quoted 1 line

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=55701

Via bugzilla,

CC Stable?

Yeah, agreed. Queued for -next, thanks for the patch. -Daniel

Quoted 90 lines
Quoted 86 lines
---
 drivers/gpu/drm/i915/intel_display.c |    3 +++
 drivers/gpu/drm/i915/intel_dp.c      |    5 +----
 drivers/gpu/drm/i915/intel_lvds.c    |    1 -
 drivers/gpu/drm/i915/intel_panel.c   |    7 ++++++-
 4 files changed, 10 insertions(+), 6 deletions(-)
drivers/gpu/drm/i915/intel_display.c +3 -0
index 457a0a0..712b0af 100644
@@ -9419,6 +9419,9 @@ void intel_modeset_cleanup(struct drm_device *dev)
 	/* flush any delayed tasks or pending work */
 	flush_scheduled_work();
 
+	/* destroy backlight, if any, before the connectors */
+	intel_panel_destroy_backlight(dev);
+
 	drm_mode_config_cleanup(dev);
 
 	intel_cleanup_overlay(dev);
drivers/gpu/drm/i915/intel_dp.c +1 -4
index 173add1..8845e82 100644
@@ -2474,17 +2474,14 @@ done:
 static void
 intel_dp_destroy(struct drm_connector *connector)
 {
-	struct drm_device *dev = connector->dev;
 	struct intel_dp *intel_dp = intel_attached_dp(connector);
 	struct intel_connector *intel_connector = to_intel_connector(connector);
 
 	if (!IS_ERR_OR_NULL(intel_connector->edid))
 		kfree(intel_connector->edid);
 
-	if (is_edp(intel_dp)) {
-		intel_panel_destroy_backlight(dev);
+	if (is_edp(intel_dp))
 		intel_panel_fini(&intel_connector->panel);
-	}
 
 	drm_sysfs_connector_remove(connector);
 	drm_connector_cleanup(connector);
drivers/gpu/drm/i915/intel_lvds.c +0 -1
index ca2d903..f36f1ba 100644
@@ -631,7 +631,6 @@ static void intel_lvds_destroy(struct drm_connector *connector)
 	if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
 		kfree(lvds_connector->base.edid);
 
-	intel_panel_destroy_backlight(connector->dev);
 	intel_panel_fini(&lvds_connector->base.panel);
 
 	drm_sysfs_connector_remove(connector);
drivers/gpu/drm/i915/intel_panel.c +6 -1
index 464c3d7..5d3e9d7 100644
@@ -459,6 +459,9 @@ int intel_panel_setup_backlight(struct drm_connector *connector)
 
 	intel_panel_init_backlight(dev);
 
+	if (WARN_ON(dev_priv->backlight.device))
+		return -ENODEV;
+
 	memset(&props, 0, sizeof(props));
 	props.type = BACKLIGHT_RAW;
 	props.brightness = dev_priv->backlight.level;
@@ -488,8 +491,10 @@ int intel_panel_setup_backlight(struct drm_connector *connector)
 void intel_panel_destroy_backlight(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
-	if (dev_priv->backlight.device)
+	if (dev_priv->backlight.device) {
 		backlight_device_unregister(dev_priv->backlight.device);
+		dev_priv->backlight.device = NULL;
+	}
 }
 #else
 int intel_panel_setup_backlight(struct drm_connector *connector)
Signature · 1 line
1.7.9.5

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#4 lore raw

Re: [PATCH 2/4] drm/i915: protect backlight registers and data with a spinlock

In reply to Jani Nikula
Quoted 5 lines · Jani Nikula

Backlight data and registers are fiddled through LVDS/eDP modeset enable/disable hooks, backlight sysfs files, asle interrupts, and register save/restore. Protect the backlight related registers and driver private fields using a spinlock.

Quoted 7 lines

The locking in register save/restore covers a little more than is strictly necessary, including non-modeset case, for simplicity.

v2: Cover register access, save/restore, i915_read_blc_pwm_ctl() and code
paths leading there.

Looks reasonable.

intel_panel_actually_set_backlight() should have a WARN_ON(!spinlocked);

The irqness of the register writes scares me slightly - since the IRQ in question is from ACPI and we have a few bug reports along the lines of "backlight makes the entire system sluggish" i.e. commonly associated with bad interrupt handling. Whilst you are looking at updating the backlight programming, can you look at pushing the writes from out of the interrupt handler?
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#5 lore raw

Re: [PATCH 2/4] drm/i915: protect backlight registers and data with a spinlock

Quoted 16 lines · Chris Wilson
Quoted 5 lines · Jani Nikula

Backlight data and registers are fiddled through LVDS/eDP modeset enable/disable hooks, backlight sysfs files, asle interrupts, and register save/restore. Protect the backlight related registers and driver private fields using a spinlock.

Quoted 7 lines

The locking in register save/restore covers a little more than is strictly necessary, including non-modeset case, for simplicity.

v2: Cover register access, save/restore, i915_read_blc_pwm_ctl() and code
paths leading there.

Looks reasonable.

Quoted 8 lines

intel_panel_actually_set_backlight() should have a WARN_ON(!spinlocked);

The irqness of the register writes scares me slightly - since the IRQ in question is from ACPI and we have a few bug reports along the lines of "backlight makes the entire system sluggish" i.e. commonly associated with bad interrupt handling. Whilst you are looking at updating the backlight programming, can you look at pushing the writes from out of the interrupt handler?

So, add a work to do the register writes, and change the spinlock into a mutex while at it? Should be fairly simple, if you think that's the way to go.

BR,
Jani.

#6 lore raw

Re: [PATCH 2/4] drm/i915: protect backlight registers and data with a spinlock

Quoted 26 lines · Jani Nikula
Quoted 16 lines · Chris Wilson
Quoted 5 lines · Jani Nikula

Backlight data and registers are fiddled through LVDS/eDP modeset enable/disable hooks, backlight sysfs files, asle interrupts, and register save/restore. Protect the backlight related registers and driver private fields using a spinlock.

Quoted 7 lines

The locking in register save/restore covers a little more than is strictly necessary, including non-modeset case, for simplicity.

v2: Cover register access, save/restore, i915_read_blc_pwm_ctl() and code
paths leading there.

Looks reasonable.

Quoted 8 lines

intel_panel_actually_set_backlight() should have a WARN_ON(!spinlocked);

The irqness of the register writes scares me slightly - since the IRQ in question is from ACPI and we have a few bug reports along the lines of "backlight makes the entire system sluggish" i.e. commonly associated with bad interrupt handling. Whilst you are looking at updating the backlight programming, can you look at pushing the writes from out of the interrupt handler?

Quoted 3 lines

So, add a work to do the register writes, and change the spinlock into a mutex while at it? Should be fairly simple, if you think that's the way to go.

I think I'll go ahead with the spinlock fix here for 3.10 and we can look into offloading this all for 3.11. Also, Chris do you remember one of these reports - I've kinda never noticed that particular kind of suck?
-Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

#7 lore raw

Re: [PATCH 2/4] drm/i915: protect backlight registers and data with a spinlock

Quoted 27 lines · Daniel Vetter
Quoted 26 lines · Jani Nikula
Quoted 24 lines · Chris Wilson
Quoted 5 lines · Jani Nikula

Backlight data and registers are fiddled through LVDS/eDP modeset enable/disable hooks, backlight sysfs files, asle interrupts, and register save/restore. Protect the backlight related registers and driver private fields using a spinlock.

Quoted 7 lines

The locking in register save/restore covers a little more than is strictly necessary, including non-modeset case, for simplicity.

v2: Cover register access, save/restore, i915_read_blc_pwm_ctl() and code
paths leading there.

Looks reasonable.

intel_panel_actually_set_backlight() should have a WARN_ON(!spinlocked);

The irqness of the register writes scares me slightly - since the IRQ in question is from ACPI and we have a few bug reports along the lines of "backlight makes the entire system sluggish" i.e. commonly associated with bad interrupt handling. Whilst you are looking at updating the backlight programming, can you look at pushing the writes from out of the interrupt handler?

Quoted 8 lines
Quoted 3 lines

So, add a work to do the register writes, and change the spinlock into a mutex while at it? Should be fairly simple, if you think that's the way to go.

I think I'll go ahead with the spinlock fix here for 3.10 and we can look into offloading this all for 3.11. Also, Chris do you remember one of these reports - I've kinda never noticed that particular kind of suck?

I maybe way off the mark and the cause is likely just to be a sucky ACPI firmware:
https://bugs.launchpad.net/ubuntu/+source/xserver-xorg-video-intel/+bug/1019370

spinlock -> mutex + workqueue would mitigate against any bad firmware being run under irq context.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#8 lore raw

Re: [PATCH 2/4] drm/i915: protect backlight registers and data with a spinlock

Quoted 37 lines · Chris Wilson
Quoted 27 lines · Daniel Vetter
Quoted 26 lines · Jani Nikula
Quoted 24 lines · Chris Wilson
Quoted 5 lines · Jani Nikula

Backlight data and registers are fiddled through LVDS/eDP modeset enable/disable hooks, backlight sysfs files, asle interrupts, and register save/restore. Protect the backlight related registers and driver private fields using a spinlock.

Quoted 7 lines

The locking in register save/restore covers a little more than is strictly necessary, including non-modeset case, for simplicity.

v2: Cover register access, save/restore, i915_read_blc_pwm_ctl() and code
paths leading there.

Looks reasonable.

intel_panel_actually_set_backlight() should have a WARN_ON(!spinlocked);

The irqness of the register writes scares me slightly - since the IRQ in question is from ACPI and we have a few bug reports along the lines of "backlight makes the entire system sluggish" i.e. commonly associated with bad interrupt handling. Whilst you are looking at updating the backlight programming, can you look at pushing the writes from out of the interrupt handler?

Quoted 8 lines
Quoted 3 lines

So, add a work to do the register writes, and change the spinlock into a mutex while at it? Should be fairly simple, if you think that's the way to go.

I think I'll go ahead with the spinlock fix here for 3.10 and we can look into offloading this all for 3.11. Also, Chris do you remember one of these reports - I've kinda never noticed that particular kind of suck?

Quoted 6 lines

I maybe way off the mark and the cause is likely just to be a sucky ACPI firmware:
https://bugs.launchpad.net/ubuntu/+source/xserver-xorg-video-intel/+bug/1019370

spinlock -> mutex + workqueue would mitigate against any bad firmware being run under irq context.

Hm, that's a funny one indeed. Although it's strange that it doesn't happen when not using X. Might be that the user doesn't notice it (since all the interactive stuff - blinking cursor - is done in irq context), but if this is indeed ACPI doing something crazy I have no idea what's it doing ...
-Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

#9 lore raw

Re: [PATCH 2/4] drm/i915: protect backlight registers and data with a spinlock

In reply to Jani Nikula
Quoted 5 lines · Jani Nikula

Backlight data and registers are fiddled through LVDS/eDP modeset enable/disable hooks, backlight sysfs files, asle interrupts, and register save/restore. Protect the backlight related registers and driver private fields using a spinlock.

Quoted 7 lines

The locking in register save/restore covers a little more than is strictly necessary, including non-modeset case, for simplicity.

v2: Cover register access, save/restore, i915_read_blc_pwm_ctl() and code
paths leading there.

Merged the first two patches here for next, I guess we can fix up any other issues here separately.

Thanks, Daniel
----
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

Reviewed-by on v1 4/4
#14 lore raw

Re: [PATCH 4/4] drm/i915: hsw backlight registers need transcoder instead of pipe

In reply to Jani Nikula
Quoted 19 lines · Jani Nikula
---
 drivers/gpu/drm/i915/intel_panel.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_panel.c +2 -0
index 5d3e9d7..0362f5c 100644
@@ -344,6 +344,8 @@ void intel_panel_enable_backlight(struct drm_device *dev,
 				  enum pipe pipe)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
+	enum transcoder cpu_transcoder =
+		intel_pipe_to_cpu_transcoder(dev_priv, pipe);
 	unsigned long flags;
 
 	spin_lock_irqsave(&dev_priv->backlight.lock, flags);

drivers/gpu/drm/i915/intel_panel.c void intel_panel_enable_backlight(struct drm_device *dev, · line 379

Quoted 5 lines
drivers/gpu/drm/i915/intel_panel.c +1 -1
@@ -374,7 +376,7 @@ void intel_panel_enable_backlight(struct drm_device *dev,
 		else
 			tmp &= ~BLM_PIPE_SELECT;
 
-		tmp |= BLM_PIPE(pipe);
+		tmp |= BLM_PIPE(cpu_transcoder);

Imo BLM_PIPE would be clearer checking for TRANSCODER_EDP explicitly, but the code works anyway, so:

Quoted 3 lines
drivers/gpu/drm/i915/intel_panel.c +0 -0
 		tmp &= ~BLM_PWM_ENABLE;
 
 		I915_WRITE(reg, tmp);
#15 lore raw

Re: [PATCH 4/4] drm/i915: hsw backlight registers need transcoder instead of pipe

Quoted 23 lines · Imre Deak
Quoted 22 lines · Jani Nikula
---
 drivers/gpu/drm/i915/intel_panel.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_panel.c +2 -0
index 5d3e9d7..0362f5c 100644
@@ -344,6 +344,8 @@ void intel_panel_enable_backlight(struct drm_device *dev,
 				  enum pipe pipe)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
+	enum transcoder cpu_transcoder =
+		intel_pipe_to_cpu_transcoder(dev_priv, pipe);
 	unsigned long flags;
 
 	spin_lock_irqsave(&dev_priv->backlight.lock, flags);
@@ -374,7 +376,7 @@ void intel_panel_enable_backlight(struct drm_device *dev,
 		else
 			tmp &= ~BLM_PIPE_SELECT;
 
Quoted 6 lines

drivers/gpu/drm/i915/intel_panel.c void intel_panel_enable_backlight(struct drm_device *dev, · line 379

Quoted 2 lines
drivers/gpu/drm/i915/intel_panel.c +1 -1
-		tmp |= BLM_PIPE(pipe);
+		tmp |= BLM_PIPE(cpu_transcoder);

Imo BLM_PIPE would be clearer checking for TRANSCODER_EDP explicitly, but the code works anyway, so:

Atm all the difference between pipe and cpu_transcoder is about transcoder edp. So this feels explicit enough for me.

Queued for -next, thanks for the patch.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#16 lore raw

Re: [PATCH 4/4] drm/i915: hsw backlight registers need transcoder instead of pipe

Quoted 31 lines · Daniel Vetter
Quoted 23 lines · Imre Deak
Quoted 22 lines · Jani Nikula
---
 drivers/gpu/drm/i915/intel_panel.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_panel.c +2 -0
index 5d3e9d7..0362f5c 100644
@@ -344,6 +344,8 @@ void intel_panel_enable_backlight(struct drm_device *dev,
 				  enum pipe pipe)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
+	enum transcoder cpu_transcoder =
+		intel_pipe_to_cpu_transcoder(dev_priv, pipe);
 	unsigned long flags;
 
 	spin_lock_irqsave(&dev_priv->backlight.lock, flags);
@@ -374,7 +376,7 @@ void intel_panel_enable_backlight(struct drm_device *dev,
 		else
 			tmp &= ~BLM_PIPE_SELECT;
 
Quoted 6 lines

drivers/gpu/drm/i915/intel_panel.c void intel_panel_enable_backlight(struct drm_device *dev, · line 379

Quoted 2 lines
drivers/gpu/drm/i915/intel_panel.c +1 -1
-		tmp |= BLM_PIPE(pipe);
+		tmp |= BLM_PIPE(cpu_transcoder);

Imo BLM_PIPE would be clearer checking for TRANSCODER_EDP explicitly, but the code works anyway, so:

Quoted 2 lines

Atm all the difference between pipe and cpu_transcoder is about transcoder edp. So this feels explicit enough for me.

Imre pointed out that his concern is about the truncation, since for eDP this evaluates to (0xf << 29). Which truncates to the right value, but I agree it's a bit too much working-by-accident. Dropped the patch again. -Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#17 lore raw

PATCH v2 1/1 drm/i915: hsw backlight registers need transcoder instead of pipe

v2: Make TRANSCODER_EDP handling more explicit. (Imre)

---
 drivers/gpu/drm/i915/i915_reg.h    |    4 ++++
 drivers/gpu/drm/i915/intel_panel.c |    7 ++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_reg.h +4 -0
index 60e0e19..e79669f 100644
@@ -2087,6 +2087,10 @@
 #define   BLM_PIPE_A			(0 << 29)
 #define   BLM_PIPE_B			(1 << 29)
 #define   BLM_PIPE_C			(2 << 29) /* ivb + */
+#define   BLM_TRANSCODER_A		BLM_PIPE_A /* hsw */
+#define   BLM_TRANSCODER_B		BLM_PIPE_B
+#define   BLM_TRANSCODER_C		BLM_PIPE_C
+#define   BLM_TRANSCODER_EDP		(3 << 29)
 #define   BLM_PIPE(pipe)		((pipe) << 29)
 #define   BLM_POLARITY_I965		(1 << 28) /* gen4 only */
 #define   BLM_PHASE_IN_INTERUPT_STATUS	(1 << 26)
drivers/gpu/drm/i915/intel_panel.c +6 -1
index 5d3e9d7..7f6141d 100644
@@ -344,6 +344,8 @@ void intel_panel_enable_backlight(struct drm_device *dev,
 				  enum pipe pipe)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
+	enum transcoder cpu_transcoder =
+		intel_pipe_to_cpu_transcoder(dev_priv, pipe);
 	unsigned long flags;
 
 	spin_lock_irqsave(&dev_priv->backlight.lock, flags);
@@ -374,7 +376,10 @@ void intel_panel_enable_backlight(struct drm_device *dev,
 		else
 			tmp &= ~BLM_PIPE_SELECT;
 
-		tmp |= BLM_PIPE(pipe);
+		if (cpu_transcoder == TRANSCODER_EDP)
+			tmp |= BLM_TRANSCODER_EDP;
+		else
+			tmp |= BLM_PIPE(cpu_transcoder);
 		tmp &= ~BLM_PWM_ENABLE;
 
 		I915_WRITE(reg, tmp);
Signature · 1 line
1.7.9.5
#18 lore raw

Re: [PATCH v2] drm/i915: hsw backlight registers need transcoder instead of pipe

Quoted 3 lines · Jani Nikula

v2: Make TRANSCODER_EDP handling more explicit. (Imre)

Looks ok, so still applies my r-b.

Quoted 45 lines

--

 drivers/gpu/drm/i915/i915_reg.h    |    4 ++++
 drivers/gpu/drm/i915/intel_panel.c |    7 ++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_reg.h +4 -0
index 60e0e19..e79669f 100644
@@ -2087,6 +2087,10 @@
 #define   BLM_PIPE_A			(0 << 29)
 #define   BLM_PIPE_B			(1 << 29)
 #define   BLM_PIPE_C			(2 << 29) /* ivb + */
+#define   BLM_TRANSCODER_A		BLM_PIPE_A /* hsw */
+#define   BLM_TRANSCODER_B		BLM_PIPE_B
+#define   BLM_TRANSCODER_C		BLM_PIPE_C
+#define   BLM_TRANSCODER_EDP		(3 << 29)
 #define   BLM_PIPE(pipe)		((pipe) << 29)
 #define   BLM_POLARITY_I965		(1 << 28) /* gen4 only */
 #define   BLM_PHASE_IN_INTERUPT_STATUS	(1 << 26)
drivers/gpu/drm/i915/intel_panel.c +6 -1
index 5d3e9d7..7f6141d 100644
@@ -344,6 +344,8 @@ void intel_panel_enable_backlight(struct drm_device *dev,
 				  enum pipe pipe)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
+	enum transcoder cpu_transcoder =
+		intel_pipe_to_cpu_transcoder(dev_priv, pipe);
 	unsigned long flags;
 
 	spin_lock_irqsave(&dev_priv->backlight.lock, flags);
@@ -374,7 +376,10 @@ void intel_panel_enable_backlight(struct drm_device *dev,
 		else
 			tmp &= ~BLM_PIPE_SELECT;
 
-		tmp |= BLM_PIPE(pipe);
+		if (cpu_transcoder == TRANSCODER_EDP)
+			tmp |= BLM_TRANSCODER_EDP;
+		else
+			tmp |= BLM_PIPE(cpu_transcoder);
 		tmp &= ~BLM_PWM_ENABLE;
 
 		I915_WRITE(reg, tmp);
#19 lore raw

Re: [PATCH v2] drm/i915: hsw backlight registers need transcoder instead of pipe

Quoted 6 lines · Imre Deak
Quoted 3 lines · Jani Nikula

v2: Make TRANSCODER_EDP handling more explicit. (Imre)

Looks ok, so still applies my r-b.

Queued for -next, thanks for the patch.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch