Skip to contentSkip to conversation

drm/i915: check for power well in redisable VGA with generic fn

PATCH In review Jesse Barnes 2 participants 5 messages Oct 11, 2013

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

PATCH 1/2 drm/i915: check for power well in redisable VGA with generic fn

Rather than using a HSW specific check.

---
 drivers/gpu/drm/i915/intel_display.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_display.c +1 -2
index 53c4ea8..5452b34 100644
@@ -10667,8 +10667,7 @@ void i915_redisable_vga(struct drm_device *dev)
 	 * level, just check if the power well is enabled instead of trying to
 	 * follow the "don't touch the power well if we don't need it" policy
 	 * the rest of the driver uses. */
-	if (HAS_POWER_WELL(dev) &&
-	    (I915_READ(HSW_PWR_WELL_DRIVER) & HSW_PWR_WELL_STATE_ENABLED) == 0)
+	if (!intel_display_power_enabled(dev, POWER_DOMAIN_VGA))
 		return;
 
 	if (I915_READ(vga_reg) != VGA_DISP_DISABLE) {
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 2/2 drm/i915: move gt powersave init out of save_state and modeset_init_hw

We need to do this at init and resume time, but it's not modeset related. Since we'll need the modeset functions for managing save/restore after the power well is toggled, we want to keep them separate from GT related state save/restore to keep from affecting GT activity while the display is off.

---
 drivers/gpu/drm/i915/i915_dma.c      | 2 ++
 drivers/gpu/drm/i915/i915_drv.c      | 3 +++
 drivers/gpu/drm/i915/i915_suspend.c  | 2 --
 drivers/gpu/drm/i915/intel_display.c | 4 ----
 4 files changed, 5 insertions(+), 6 deletions(-)
drivers/gpu/drm/i915/i915_dma.c +2 -0
index f221631..313a8c9 100644
@@ -1331,6 +1331,8 @@ static int i915_load_modeset_init(struct drm_device *dev)
 
 	intel_modeset_gem_init(dev);
 
+	intel_enable_gt_powersave(dev);
+
 	/* Always safe in the mode setting case. */
 	/* FIXME: do pre/post-mode set stuff in core KMS code */
 	dev->vblank_disable_allowed = 1;
drivers/gpu/drm/i915/i915_drv.c +3 -0
index 0fc9658..82a1d53 100644
@@ -507,6 +507,8 @@ static int i915_drm_freeze(struct drm_device *dev)
 
 	i915_save_state(dev);
 
+	intel_disable_gt_powersave(dev);
+
 	intel_opregion_fini(dev);
 
 	console_lock();
@@ -604,6 +606,7 @@ static int __i915_drm_thaw(struct drm_device *dev, bool restore_gtt_mappings)
 		mutex_lock(&dev->struct_mutex);
 
 		error = i915_gem_init_hw(dev);
+		intel_enable_gt_powersave(dev);
 		mutex_unlock(&dev->struct_mutex);
 
 		/* We need working interrupts for modeset enabling ... */
drivers/gpu/drm/i915/i915_suspend.c +0 -2
index 98790c7..cd28fd5 100644
@@ -395,8 +395,6 @@ int i915_save_state(struct drm_device *dev)
 		}
 	}
 
-	intel_disable_gt_powersave(dev);
-
 	/* Cache mode state */
 	if (INTEL_INFO(dev)->gen < 7)
 		dev_priv->regfile.saveCACHE_MODE_0 = I915_READ(CACHE_MODE_0);
drivers/gpu/drm/i915/intel_display.c +0 -4
index 5452b34..4835c51 100644
@@ -10403,10 +10403,6 @@ void intel_modeset_init_hw(struct drm_device *dev)
 			   DPLL_INTEGRATED_CRI_CLK_VLV);
 
 	intel_init_dpio(dev);
-
-	mutex_lock(&dev->struct_mutex);
-	intel_enable_gt_powersave(dev);
-	mutex_unlock(&dev->struct_mutex);
 }
 
 void intel_modeset_suspend_hw(struct drm_device *dev)
Signature · 1 line
1.8.3.1
#2 lore raw
In reply to Jesse Barnes

2013/10/11 Jesse Barnes <[email protected]>:

Quoted 12 lines

Rather than using a HSW specific check.

---
 drivers/gpu/drm/i915/intel_display.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_display.c +0 -0
index 53c4ea8..5452b34 100644

drivers/gpu/drm/i915/intel_display.c void i915_redisable_vga(struct drm_device *dev) · line 10670

Quoted 6 lines
drivers/gpu/drm/i915/intel_display.c +1 -2
@@ -10667,8 +10667,7 @@ void i915_redisable_vga(struct drm_device *dev)
         * level, just check if the power well is enabled instead of trying to
         * follow the "don't touch the power well if we don't need it" policy
         * the rest of the driver uses. */
-       if (HAS_POWER_WELL(dev) &&
-           (I915_READ(HSW_PWR_WELL_DRIVER) & HSW_PWR_WELL_STATE_ENABLED) == 0)
+       if (!intel_display_power_enabled(dev, POWER_DOMAIN_VGA))

See the big comment. With your patch we're not only going to return in case the power well is disabled, we're going to return in case it's disabled _or_ we promised to not touch it (even if it's enabled). I originally made the same mistake, then Ville spotted it on the code review. This function should assume the BIOS is being an idiot and is trying to mess with us.

I admit I don't like it, suggestions to further improve this code are welcome. But it seems no one really knows what's the best and safest thing to do here :(

Quoted 10 lines
drivers/gpu/drm/i915/intel_display.c +0 -1
                return;
 
        if (I915_READ(vga_reg) != VGA_DISP_DISABLE) {
--

1.8.3.1

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

Signature · 1 line
Paulo Zanoni
#3 lore raw
Quoted 27 lines · On Fri, 11 Oct 2013 17:16:55 -0300 Paulo Zanoni <[email protected]> wrote:

2013/10/11 Jesse Barnes <[email protected]>:

Quoted 12 lines

Rather than using a HSW specific check.

---
 drivers/gpu/drm/i915/intel_display.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_display.c +0 -0
index 53c4ea8..5452b34 100644

drivers/gpu/drm/i915/intel_display.c void i915_redisable_vga(struct drm_device *dev) · line 10670

Quoted 6 lines
drivers/gpu/drm/i915/intel_display.c +1 -2
@@ -10667,8 +10667,7 @@ void i915_redisable_vga(struct drm_device *dev)
         * level, just check if the power well is enabled instead of trying to
         * follow the "don't touch the power well if we don't need it" policy
         * the rest of the driver uses. */
-       if (HAS_POWER_WELL(dev) &&
-           (I915_READ(HSW_PWR_WELL_DRIVER) & HSW_PWR_WELL_STATE_ENABLED) == 0)
+       if (!intel_display_power_enabled(dev, POWER_DOMAIN_VGA))

See the big comment. With your patch we're not only going to return in case the power well is disabled, we're going to return in case it's disabled _or_ we promised to not touch it (even if it's enabled). I originally made the same mistake, then Ville spotted it on the code review. This function should assume the BIOS is being an idiot and is trying to mess with us.

Quoted 3 lines

I admit I don't like it, suggestions to further improve this code are welcome. But it seems no one really knows what's the best and safest thing to do here :(

Hm I'm not seeing it. For a simple status check we don't depend on the power_well struct at all, we just look at the bits.

In this case do we need to explicitly ignore the
HSW_PWR_WELL_ENABLE_REQUEST bit or something?

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
#4 lore raw

2013/10/11 Jesse Barnes <[email protected]>:

Quoted 30 lines
Quoted 27 lines · On Fri, 11 Oct 2013 17:16:55 -0300 Paulo Zanoni <[email protected]> wrote:

2013/10/11 Jesse Barnes <[email protected]>:

Quoted 12 lines

Rather than using a HSW specific check.

---
 drivers/gpu/drm/i915/intel_display.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_display.c +0 -0
index 53c4ea8..5452b34 100644

drivers/gpu/drm/i915/intel_display.c void i915_redisable_vga(struct drm_device *dev) · line 10670

Quoted 6 lines
drivers/gpu/drm/i915/intel_display.c +1 -2
@@ -10667,8 +10667,7 @@ void i915_redisable_vga(struct drm_device *dev)
         * level, just check if the power well is enabled instead of trying to
         * follow the "don't touch the power well if we don't need it" policy
         * the rest of the driver uses. */
-       if (HAS_POWER_WELL(dev) &&
-           (I915_READ(HSW_PWR_WELL_DRIVER) & HSW_PWR_WELL_STATE_ENABLED) == 0)
+       if (!intel_display_power_enabled(dev, POWER_DOMAIN_VGA))

See the big comment. With your patch we're not only going to return in case the power well is disabled, we're going to return in case it's disabled _or_ we promised to not touch it (even if it's enabled). I originally made the same mistake, then Ville spotted it on the code review. This function should assume the BIOS is being an idiot and is trying to mess with us.

Quoted 6 lines
Quoted 3 lines

I admit I don't like it, suggestions to further improve this code are welcome. But it seems no one really knows what's the best and safest thing to do here :(

Hm I'm not seeing it. For a simple status check we don't depend on the power_well struct at all, we just look at the bits.

Are you suggesting we should just read vga_reg without checking if the power well is enabled? Then we'll hit "unclaimed register" error messages every time we do this and the power well is disabled.

Quoted 3 lines

In this case do we need to explicitly ignore the
HSW_PWR_WELL_ENABLE_REQUEST bit or something?

The thing about the power well is that it can be enabled by not only graphics, but also KVMr and other things (there are 4 power well
registers: one for the BIOS, one for the driver, one for KVMr and one for debug). The idea behind the hardware is: if anybody wants it, it gets enabled. So in theory things like the KVMr could be trying to enable the power well while we're not looking, and this creates a huge amount of possible racing conditions. To avoid most of the racing conditions, our driver has a policy of "if we don't need the power well, we're never going to touch anything inside it", and we respect this policy everywhere in the driver _except_ for the function you're touching.

Why? If you do a "git blame" on this function and see the commits and bugs related, it seems that in some machines the BIOS has this nice idea of re-enabling VGA during some ACPI events. So we concluded that this specific function should try to assume that maybe something else (BIOS, KVMr, Debug) could have enabled the power well, then enabled VGA. So if we just do the "intel_display_power_enabled" check we'll _always_ do the early return on this function and we'll never really check if something else really enabled power_well+VGA while the driver was still keeping its promise of "never touching the power well while we don't need it". I know, it's confusing and sounds like a huge mess. I'm open to suggestions on how to improve it :) You may want to read this paragraph again, maybe 2 or 3 times.

Quoted 3 lines

--
Jesse Barnes, Intel Open Source Technology Center

Signature · 1 line
Paulo Zanoni