Power-well API implementation for Haswell
Subsystems (3)
v5 cover Power-well API implementation for Haswell
Hi all,
This is V5 and here're some changes notes:
change from V4-->V5:
- fix reference count bug
- new patch on general runtime pm support for audio pci device
- new patch to avoid request_module() deadlock
change between V3-->V4:
- add new structure i915_power_well
- initialize drm_device pointer at module init time
- change function name
change between V2-->V3:
- make SND_HDA_I915 selectable
- use snd_printdd to output message
- add return error code check
- use symbol_request to replace symbol_get
- release power_well at azx_free
- some typo fixes
changes between V1-->V2:
- use reference count to track power-well usage
- remove external module, compiled into snd-hda-intel instead
- manage symbols and module loading properly
- remove IS_HSW macro, use flag instead
- remove audio callback for gfx driver to avoid dependency
- split whole patch into two pieces for easy review
- more typo fixes
Wang Xingchao (4):
i915/drm: Add private api for power well usage
ALSA: hda - Add power-welll support for haswell HDA
ALSA: hda - Fix runtime PM check
ALSA: hda - Continue probe in work context to avoid request_module
deadlock
drivers/gpu/drm/i915/i915_dma.c | 6 ++ drivers/gpu/drm/i915/i915_drv.h | 12 ++++ drivers/gpu/drm/i915/intel_drv.h | 4 ++ drivers/gpu/drm/i915/intel_pm.c | 92 ++++++++++++++++++++++++--- include/drm/i915_powerwell.h | 36 +++++++++++ sound/pci/hda/Kconfig | 10 +++ sound/pci/hda/Makefile | 3 + sound/pci/hda/hda_i915.c | 75 ++++++++++++++++++++++ sound/pci/hda/hda_i915.h | 35 +++++++++++ sound/pci/hda/hda_intel.c | 132 ++++++++++++++++++++++++++++----------- 10 files changed, 360 insertions(+), 45 deletions(-) create mode 100644 include/drm/i915_powerwell.h create mode 100644 sound/pci/hda/hda_i915.c create mode 100644 sound/pci/hda/hda_i915.h
Signature · 1 line
1.8.1.2
PATCH v5 1/4 i915/drm: Add private api for power well usage
Haswell Display audio depends on power well in graphic side, it should request power well before use it and release power well after use. I915 will not shutdown power well if it detects audio is using. This patch protects display audio crash for Intel Haswell C3 stepping board.
--- drivers/gpu/drm/i915/i915_dma.c | 6 +++ drivers/gpu/drm/i915/i915_drv.h | 12 ++++++ drivers/gpu/drm/i915/intel_drv.h | 4 ++ drivers/gpu/drm/i915/intel_pm.c | 92 +++++++++++++++++++++++++++++++++++++--- include/drm/i915_powerwell.h | 36 ++++++++++++++++ 5 files changed, 143 insertions(+), 7 deletions(-) create mode 100644 include/drm/i915_powerwell.h
drivers/gpu/drm/i915/i915_dma.c +6 -0
@@ -1652,6 +1652,9 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)/* Start out suspended */ dev_priv->mm.suspended =1 ; +if (IS_HASWELL (dev)) +i915_init_power_well (dev); +if (drm_core_check_feature (dev,DRIVER_MODESET )) { ret =i915_load_modeset_init (dev);if (ret <0 ) {
@@ -1708,6 +1711,9 @@ int i915_driver_unload(struct drm_device *dev)intel_gpu_ips_teardown (); +if (IS_HASWELL (dev)) +i915_remove_power_well (dev); +i915_teardown_sysfs (dev);if (dev_priv->mm.inactive_shrinker.shrink)
drivers/gpu/drm/i915/i915_drv.h +12 -0
@@ -702,6 +702,15 @@ struct intel_ilk_power_mgmt {struct drm_i915_gem_object *renderctx; }; +/* Power well structure for haswell */ +struct i915_power_well { +struct drm_device *device; +spinlock_t lock; +/* power well enable/disable usage count */ +int count; +int i915_request; +}; +struct i915_dri1_state {unsigned allow_batchbuffer :1 ;u32 __iomem *gfx_hws_cpu_addr;
@@ -1048,6 +1057,9 @@ typedef struct drm_i915_private {* mchdev_lock in intel_pm.c */ struct intel_ilk_power_mgmt ips; +/* Haswell power well */ +struct i915_power_well *hsw_pwr; +enum no_fbc_reason no_fbc_reason;struct drm_mm_node *compressed_fb;
drivers/gpu/drm/i915/intel_drv.h +4 -0
@@ -759,6 +759,10 @@ extern void intel_update_fbc(struct drm_device *dev);extern void intel_gpu_ips_init (struct drm_i915_private *dev_priv);extern void intel_gpu_ips_teardown (void ); +/* Power well */ +extern int i915_init_power_well (struct drm_device *dev); +extern void i915_remove_power_well (struct drm_device *dev); +extern bool intel_using_power_well (struct drm_device *dev);extern void intel_init_power_well (struct drm_device *dev);extern void intel_set_power_well (struct drm_device *dev,bool enable);
drivers/gpu/drm/i915/intel_pm.c +85 -7
109 lines not on this page · raw message
include/drm/i915_powerwell.h new file +36 -0
@@ -0,0 +1,36 @@ +/************************************************************************** +* +* Copyright 2013 Intel Inc. +* All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sub license, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice (including the +* next paragraph) shall be included in all copies or substantial portions +* of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +* USE OR OTHER DEALINGS IN THE SOFTWARE. +* +* +**************************************************************************/ + +#ifndef _I915_POWERWELL_H_ +#define _I915_POWERWELL_H_ + +/* For use by hda_i915 driver */ +extern void i915_request_power_well (void ); +extern void i915_release_power_well (void ); + +#endif /* _I915_POWERWELL_H_ */
Signature · 1 line
1.8.1.2
Re: [PATCH 1/4 V5] i915/drm: Add private api for power well usage
At Thu, 23 May 2013 01:04:13 +0800,
Quoted 7 lines · Wang Xingchao
Haswell Display audio depends on power well in graphic side, it should request power well before use it and release power well after use. I915 will not shutdown power well if it detects audio is using. This patch protects display audio crash for Intel Haswell C3 stepping board.
Signed-off-by Wang Xingchao <[email protected]>
Just minor points:
drivers/gpu/drm/i915/intel_pm.c void intel_set_power_well(struct drm_device *dev, bool enable) · line 4383
Quoted 7 lines
drivers/gpu/drm/i915/intel_pm.c +7
-0+/* Display audio driver power well request */ +void i915_request_power_well (void ) +{ +if (hsw_pwr ==NULL ) +return ; + +spin_lock_irq (&hsw_pwr->lock);
If both functions are supposed to be called only in non-sleepable state, there is no merit to use _irq version of spinlock. OTOH, if this function can be called from non-sleepable context, spin_lock_irq() is wrong.
That is, the lock here should be either spin_lock() (supposing all places are not from interrupt context) or spin_lock_irqsave() (allowing from interrupt context).
Quoted 15 lines
drivers/gpu/drm/i915/intel_pm.c +15
-0+if (!hsw_pwr->count++ && + !hsw_pwr->i915_request) +__intel_set_power_well (hsw_pwr->device, true); +spin_unlock_irq (&hsw_pwr->lock); +} +EXPORT_SYMBOL_GPL (i915_request_power_well); + +/* Display audio driver power well release */ +void i915_release_power_well (void ) +{ +if (hsw_pwr ==NULL ) +return ; + +spin_lock_irq (&hsw_pwr->lock); +WARN_ON (!hsw_pwr->count);
drivers/gpu/drm/i915/intel_pm.c void intel_set_power_well(struct drm_device *dev, bool enable) · line 4408
Quoted 10 lines
drivers/gpu/drm/i915/intel_pm.c +10
-0+if (!--hsw_pwr->count && + !hsw_pwr->i915_request) +__intel_set_power_well (hsw_pwr->device, false); +spin_unlock_irq (&hsw_pwr->lock); +} +EXPORT_SYMBOL_GPL (i915_release_power_well); + +int i915_init_power_well (struct drm_device *dev) +{ +struct drm_i915_private *dev_priv = dev->dev_private;
Since this is a global variable that must be initialized only once, safer to have
WARN_ON(hsw_pwr);
Quoted 6 lines
drivers/gpu/drm/i915/intel_pm.c +6
-0+ hsw_pwr =kzalloc (sizeof *hsw_pwr,GFP_KERNEL ); +if (hsw_pwr ==NULL ) +return -ENOMEM ; + + dev_priv->hsw_pwr = hsw_pwr; +
drivers/gpu/drm/i915/intel_pm.c void intel_set_power_well(struct drm_device *dev, bool enable) · line 4425
Quoted 10 lines
drivers/gpu/drm/i915/intel_pm.c +10
-0+ hsw_pwr->device = dev; +spin_lock_init (&hsw_pwr->lock); + hsw_pwr->count =0 ; + +return 0 ; +} + +void i915_remove_power_well (struct drm_device *dev) +{ +struct drm_i915_private *dev_priv = dev->dev_private;
... and
WARN_ON(hsw_ptr != dev_priv->hsw_pwr);
drivers/gpu/drm/i915/intel_pm.c void intel_set_power_well(struct drm_device *dev, bool enable) · line 4430
Quoted 4 lines
drivers/gpu/drm/i915/intel_pm.c +4
-0+kfree (dev_priv->hsw_pwr); + dev_priv->hsw_pwr =NULL ; + hsw_pwr =NULL ; +}
Takashi
Quoted 76 lines
drivers/gpu/drm/i915/intel_pm.c +28
-0+ +void intel_set_power_well (struct drm_device *dev,bool enable) +{ +struct drm_i915_private *dev_priv = dev->dev_private; +struct i915_power_well *power_well = dev_priv->hsw_pwr; + +if (!HAS_POWER_WELL (dev)) +return ; + +if (!i915_disable_power_well && !enable) +return ; + +if (!power_well) +return ; + +spin_lock_irq (&power_well->lock); + power_well->i915_request = enable; + +/* only reject "disable" power well request */ +if (power_well->count && !enable) { +spin_unlock_irq (&power_well->lock); +return ; + } + +__intel_set_power_well (dev, enable); +spin_unlock_irq (&power_well->lock); +} +/* * Starting with Haswell, we have a "Power Down Well" that can be turned off * when not needed anymore. We have 4 registers that can request the power well include/drm/i915_powerwell.h new file +36
-0@@ -0,0 +1,36 @@ +/************************************************************************** +* +* Copyright 2013 Intel Inc. +* All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sub license, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice (including the +* next paragraph) shall be included in all copies or substantial portions +* of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +* USE OR OTHER DEALINGS IN THE SOFTWARE. +* +* +**************************************************************************/ + +#ifndef _I915_POWERWELL_H_ +#define _I915_POWERWELL_H_ + +/* For use by hda_i915 driver */ +extern void i915_request_power_well (void ); +extern void i915_release_power_well (void ); + +#endif /* _I915_POWERWELL_H_ */ Signature · 1 line
1.8.1.2
PATCH v5 2/4 ALSA: hda - Add power-welll support for haswell HDA
In reply to Wang XingchaoFor Intel Haswell chip, HDA controller and codec have power well dependency from GPU side. This patch added support to request/release power well in audio driver. Power save feature should be enabled to get runtime power saving.
--- sound/pci/hda/Kconfig | 10 +++++++ sound/pci/hda/Makefile | 3 ++ sound/pci/hda/hda_i915.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++ sound/pci/hda/hda_i915.h | 35 ++++++++++++++++++++++ sound/pci/hda/hda_intel.c | 51 +++++++++++++++++++++++++++----- 5 files changed, 167 insertions(+), 7 deletions(-) create mode 100644 sound/pci/hda/hda_i915.c create mode 100644 sound/pci/hda/hda_i915.h
sound/pci/hda/Kconfig +10 -0
@@ -152,6 +152,16 @@ config SND_HDA_CODEC_HDMI snd-hda-codec-hdmi. This module is automatically loaded at probing. +config SND_HDA_I915 + bool "Build Display HD-audio controller/codec power well support for i915 cards" + depends on DRM_I915 + help + Say Y here to include full HDMI and DisplayPort HD-audio controller/codec + power-well support for Intel Haswell graphics cards based on the i915 driver. + + Note that this option must be enabled for Intel Haswell C+ stepping machines, otherwise + the GPU audio controller/codecs will not be initialized or damaged when exit from S3 mode. + config SND_HDA_CODEC_CIRRUS bool "Build Cirrus Logic codec support" default y
sound/pci/hda/Makefile +3 -0
@@ -6,6 +6,9 @@ snd-hda-codec-$(CONFIG_PROC_FS) += hda_proc.o snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o snd-hda-codec-$(CONFIG_SND_HDA_INPUT_BEEP) += hda_beep.o +# for haswell power well +snd-hda-intel-$(CONFIG_SND_HDA_I915) += hda_i915.o + # for trace-points CFLAGS_hda_codec.o := -I$(src) CFLAGS_hda_intel.o := -I$(src)
sound/pci/hda/hda_i915.c new file +75 -0
75 lines not on this page · raw message
sound/pci/hda/hda_i915.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the Free +* Software Foundation; either version 2 of the License, or (at your option) +* any later version. +* +* This program is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; if not, write to the Free Software Foundation, Inc., 59 +* Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ +#ifndef __SOUND_HDA_I915_H +#define __SOUND_HDA_I915_H + +#ifdef CONFIG_SND_HDA_I915 +void hda_display_power (bool enable); +int hda_i915_init (void ); +int hda_i915_exit (void ); +#else +static inline void hda_display_power (bool enable) {} +static inline int hda_i915_init (void ) +{ +return -ENODEV ; +} +static inline int hda_i915_exit (void ) +{ +return 0 ; +} +#endif + +#endif
sound/pci/hda/hda_intel.c +44 -7
141 lines not on this page · raw message
Signature · 1 line
1.8.1.2
PATCH v5 3/4 ALSA: hda - Fix runtime PM check
In reply to Wang XingchaoThe device can support runtime PM no matter whether it support signal wakeup or not. For some chips like Haswell which doesnot support PME by default, this patch let haswell Display HD-A controller enter runtime suspend, and bring more power saving whith power-well feature enabled.
--- sound/pci/hda/hda_intel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/pci/hda/hda_intel.c +2 -2
@@ -3755,7 +3755,7 @@ static int azx_probe(struct pci_dev *pci, goto out_free_power; } -if (pci_dev_run_wake (pci)) +if (chip->driver_caps &AZX_DCAPS_PM_RUNTIME )pm_runtime_put_noidle (&pci->dev); dev++;
@@ -3834,7 +3834,7 @@ static void azx_remove(struct pci_dev *pci)struct snd_card *card =pci_get_drvdata (pci);struct azx *chip = card->private_data; -if (pci_dev_run_wake (pci)) +if (chip->driver_caps &AZX_DCAPS_PM_RUNTIME )pm_runtime_get_noresume (&pci->dev);if (card)
Signature · 1 line
1.8.1.2
Re: [PATCH 3/4] ALSA: hda - Fix runtime PM check
At Thu, 23 May 2013 01:04:15 +0800,
Quoted 7 lines · Wang Xingchao
The device can support runtime PM no matter whether it support signal wakeup or not. For some chips like Haswell which doesnot support PME by default, this patch let haswell Display HD-A controller enter runtime suspend, and bring more power saving whith power-well feature enabled.
Signed-off-by Wang Xingchao <[email protected]>
This change has nothing to do with the power well fix, thus no reason to put in the series.
Takashi
Quoted 29 lines
--- sound/pci/hda/hda_intel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)sound/pci/hda/hda_intel.c +2
-2@@ -3755,7 +3755,7 @@ static int azx_probe(struct pci_dev *pci, goto out_free_power; } -if (pci_dev_run_wake (pci)) +if (chip->driver_caps &AZX_DCAPS_PM_RUNTIME )pm_runtime_put_noidle (&pci->dev); dev++;@@ -3834,7 +3834,7 @@ static void azx_remove(struct pci_dev *pci)struct snd_card *card =pci_get_drvdata (pci);struct azx *chip = card->private_data; -if (pci_dev_run_wake (pci)) +if (chip->driver_caps &AZX_DCAPS_PM_RUNTIME )pm_runtime_get_noresume (&pci->dev);if (card)Signature · 1 line
1.8.1.2
Re: [PATCH 3/4] ALSA: hda - Fix runtime PM check
Hi Takashi,
Quoted 19 lines
-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Thursday, May 23, 2013 2:03 PM
To: Wang Xingchao
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Girdwood, Liam R; Li, Jocelyn; Wang, Xingchao
Subject: Re: [PATCH 3/4] ALSA: hda - Fix runtime PM checkAt Thu, 23 May 2013 01:04:15 +0800,
Quoted 7 lines · Wang Xingchao
The device can support runtime PM no matter whether it support signal wakeup or not. For some chips like Haswell which doesnot support PME by default, this patch let haswell Display HD-A controller enter runtime suspend, and bring more power saving whith power-well feature enabled.
Signed-off-by Wang Xingchao <[email protected]>
Quoted 2 lines
This change has nothing to do with the power well fix, thus no reason to put in the series.
But power-well feature depends on HD-A controller's power-save enabling, without this patch, Power-well would not be shutdown automatically, thus cause more power. So I thought it should be part of the patchset. Anyway it's a more general fix not only for Haswell, so better to leave it alone. I will split it from the patchset in next version.
Thanks
--xingchao
Quoted 33 lines
Takashi
Quoted 29 lines
--- sound/pci/hda/hda_intel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)sound/pci/hda/hda_intel.c +2
-3@@ -3755,7 +3755,7 @@ static int azx_probe(struct pci_dev *pci, goto out_free_power; } -if (pci_dev_run_wake (pci)) +if (chip->driver_caps &AZX_DCAPS_PM_RUNTIME )pm_runtime_put_noidle (&pci->dev); dev++;@@ -3834,7 +3834,7 @@ static void azx_remove(struct pci_dev *pci)struct snd_card *card =pci_get_drvdata (pci);struct azx *chip = card->private_data; -if (pci_dev_run_wake (pci)) +if (chip->driver_caps &AZX_DCAPS_PM_RUNTIME )pm_runtime_get_noresume (&pci->dev);if (card) --1.8.1.2
Re: [PATCH 3/4] ALSA: hda - Fix runtime PM check
At Thu, 23 May 2013 07:53:00 +0000,
Quoted 22 lines · Xingchao
Hi Takashi,
Quoted 19 lines
-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Thursday, May 23, 2013 2:03 PM
To: Wang Xingchao
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Girdwood, Liam R; Li, Jocelyn; Wang, Xingchao
Subject: Re: [PATCH 3/4] ALSA: hda - Fix runtime PM checkAt Thu, 23 May 2013 01:04:15 +0800,
Quoted 7 lines · Wang Xingchao
The device can support runtime PM no matter whether it support signal wakeup or not. For some chips like Haswell which doesnot support PME by default, this patch let haswell Display HD-A controller enter runtime suspend, and bring more power saving whith power-well feature enabled.
Signed-off-by Wang Xingchao <[email protected]>
Quoted 6 lines
Quoted 2 lines
This change has nothing to do with the power well fix, thus no reason to put in the series.
But power-well feature depends on HD-A controller's power-save enabling, without this patch, Power-well would not be shutdown automatically, thus cause more
power.
Then the fix order is wrong. Fix this first, then the rest.
Takashi
Quoted 40 lines
So I thought it should
be part of the patchset. Anyway it's a more general fix not only for Haswell, so better to leave it alone. I will split it from the patchset in next version.Thanks
--xingchaoQuoted 33 lines
Takashi
Quoted 29 lines
--- sound/pci/hda/hda_intel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)sound/pci/hda/hda_intel.c +2
-3@@ -3755,7 +3755,7 @@ static int azx_probe(struct pci_dev *pci, goto out_free_power; } -if (pci_dev_run_wake (pci)) +if (chip->driver_caps &AZX_DCAPS_PM_RUNTIME )pm_runtime_put_noidle (&pci->dev); dev++;@@ -3834,7 +3834,7 @@ static void azx_remove(struct pci_dev *pci)struct snd_card *card =pci_get_drvdata (pci);struct azx *chip = card->private_data; -if (pci_dev_run_wake (pci)) +if (chip->driver_caps &AZX_DCAPS_PM_RUNTIME )pm_runtime_get_noresume (&pci->dev);if (card) --1.8.1.2
Re: [PATCH 3/4] ALSA: hda - Fix runtime PM check
Quoted 35 lines
-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Thursday, May 23, 2013 4:10 PM
To: Wang, Xingchao
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Girdwood, Liam R; Li, Jocelyn; Wang Xingchao
Subject: Re: [PATCH 3/4] ALSA: hda - Fix runtime PM checkAt Thu, 23 May 2013 07:53:00 +0000,
Quoted 22 lines · Xingchao
Hi Takashi,
Quoted 19 lines
-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Thursday, May 23, 2013 2:03 PM
To: Wang Xingchao
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Girdwood, Liam R; Li, Jocelyn; Wang, Xingchao
Subject: Re: [PATCH 3/4] ALSA: hda - Fix runtime PM checkAt Thu, 23 May 2013 01:04:15 +0800,
Quoted 7 lines · Wang Xingchao
The device can support runtime PM no matter whether it support signal wakeup or not. For some chips like Haswell which doesnot support PME by default, this patch let haswell Display HD-A controller enter runtime suspend, and bring more power saving whith power-well feature enabled.
Signed-off-by Wang Xingchao <[email protected]>
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
This change has nothing to do with the power well fix, thus no reason to put in the series.
But power-well feature depends on HD-A controller's power-save enabling, without this patch, Power-well would not be shutdown automatically, thus cause more power.
Then the fix order is wrong. Fix this first, then the rest.
Okay, I see.
thanks
--xingchao
Quoted 44 lines
Takashi
Quoted 2 lines
So I thought it should
be part of the patchset. Anyway it's a more general fix not only for Haswell,so better to leave it alone.
Quoted 38 lines
I will split it from the patchset in next version.
Thanks
--xingchaoQuoted 33 lines
Takashi
Quoted 29 lines
--- sound/pci/hda/hda_intel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)sound/pci/hda/hda_intel.c +2
-3@@ -3755,7 +3755,7 @@ static int azx_probe(struct pci_dev *pci, goto out_free_power; } -if (pci_dev_run_wake (pci)) +if (chip->driver_caps &AZX_DCAPS_PM_RUNTIME )pm_runtime_put_noidle (&pci->dev); dev++;@@ -3834,7 +3834,7 @@ static void azx_remove(struct pci_dev *pci)struct snd_card *card =pci_get_drvdata (pci);struct azx *chip = card->private_data; -if (pci_dev_run_wake (pci)) +if (chip->driver_caps &AZX_DCAPS_PM_RUNTIME )pm_runtime_get_noresume (&pci->dev);if (card) --1.8.1.2
Re: [PATCH 3/4] ALSA: hda - Fix runtime PM check
In reply to Wang XingchaoQuoted 15 lines · Wang Xingchao
The device can support runtime PM no matter whether it support signal wakeup or not. For some chips like Haswell which doesnot support PME by default, this patch let haswell Display HD-A controller enter runtime suspend, and bring more power saving whith power-well feature enabled.
Signed-off-by Wang Xingchao <[email protected]>--- sound/pci/hda/hda_intel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)sound/pci/hda/hda_intel.c +0
-0
sound/pci/hda/hda_intel.c static int azx_probe(struct pci_dev *pci, · line 3758
Quoted 5 lines
sound/pci/hda/hda_intel.c +1
-1@@ -3755,7 +3755,7 @@ static int azx_probe(struct pci_dev *pci, goto out_free_power; } -if (pci_dev_run_wake (pci)) +if (chip->driver_caps &AZX_DCAPS_PM_RUNTIME )
I'm not sure, but shouldn't this be
if (pci_dev_run_wake(pci) || (chip->driver_caps & AZX_DCAPS_PM_RUNTIME))
...in order not to regress power performance of devices which have pci_dev_run_wake(pci) but not runtime PM?
Quoted 13 lines
sound/pci/hda/hda_intel.c +1
-1pm_runtime_put_noidle (&pci->dev); dev++;@@ -3834,7 +3834,7 @@ static void azx_remove(struct pci_dev *pci)struct snd_card *card =pci_get_drvdata (pci);struct azx *chip = card->private_data; -if (pci_dev_run_wake (pci)) +if (chip->driver_caps &AZX_DCAPS_PM_RUNTIME )pm_runtime_get_noresume (&pci->dev);if (card)
Signature · 2 lines
David Henningsson, Canonical Ltd. https://launchpad.net/~diwic
Re: [alsa-devel] [PATCH 3/4] ALSA: hda - Fix runtime PM check
At Thu, 23 May 2013 14:34:09 +0200,
Quoted 25 lines · David Henningsson
Quoted 15 lines · Wang Xingchao
The device can support runtime PM no matter whether it support signal wakeup or not. For some chips like Haswell which doesnot support PME by default, this patch let haswell Display HD-A controller enter runtime suspend, and bring more power saving whith power-well feature enabled.
Signed-off-by Wang Xingchao <[email protected]>--- sound/pci/hda/hda_intel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)sound/pci/hda/hda_intel.c +0
-0sound/pci/hda/hda_intel.c static int azx_probe(struct pci_dev *pci, · line 3758
Quoted 5 lines
sound/pci/hda/hda_intel.c +1
-1@@ -3755,7 +3755,7 @@ static int azx_probe(struct pci_dev *pci, goto out_free_power; } -if (pci_dev_run_wake (pci)) +if (chip->driver_caps &AZX_DCAPS_PM_RUNTIME )I'm not sure, but shouldn't this be
Quoted 4 lines
if (
pci_dev_run_wake(pci)|| (chip->driver_caps&AZX_DCAPS_PM_RUNTIME))...in order not to regress power performance of devices which have
pci_dev_run_wake(pci)but not runtime PM?
If driver_caps isn't set, azx_runtime_idle() returns -EBUSY, i.e. essentially the runtime PM is disabled in that case.
Takashi
Quoted 24 lines
Quoted 13 lines
sound/pci/hda/hda_intel.c +1
-1pm_runtime_put_noidle (&pci->dev); dev++;@@ -3834,7 +3834,7 @@ static void azx_remove(struct pci_dev *pci)struct snd_card *card =pci_get_drvdata (pci);struct azx *chip = card->private_data; -if (pci_dev_run_wake (pci)) +if (chip->driver_caps &AZX_DCAPS_PM_RUNTIME )pm_runtime_get_noresume (&pci->dev);if (card)Signature · 6 lines
David Henningsson, Canonical Ltd. https://launchpad.net/~diwic _______________________________________________ Alsa-devel mailing list [email protected] http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
PATCH v5 4/4 ALSA: hda - Continue probe in work context to avoid request_module deadlock
In reply to Wang XingchaoThere's deadlock when request_module(i915) in azx_probe.
It looks like:device_lock(audio pci device) -> azx_probe -> module_request (or symbol_request) -> modprobe (userspace) -> i915 init -> drm_pci_init -> pci_register_driver -> bus_add_driver -> driver_attach -> which in turn tries all locks on pci bus, and when it tries the one on the audio device, it will deadlock.
This patch introduce a work to store remaining probe stuff, and let request_module run in safe work context.
--- sound/pci/hda/hda_intel.c | 105 +++++++++++++++++++++++++++------------------- 1 file changed, 62 insertions(+), 43 deletions(-)
sound/pci/hda/hda_intel.c +62 -43
@@ -76,6 +76,7 @@ static int probe_only[SNDRV_CARDS];static int jackpoll_ms[SNDRV_CARDS ];static bool single_cmd;static int enable_msi =-1 ; +static int dev;#ifdef CONFIG_SND_HDA_PATCH_LOADER static char *patch[SNDRV_CARDS ];#endif
@@ -542,6 +543,8 @@ struct azx {/* for pending irqs */ struct work_struct irq_pending_work; +struct delayed_work probe_work; +/* reboot notifier (for mysterious hangup problem at power-down) */ struct notifier_block reboot_notifier;
@@ -3670,58 +3673,22 @@ static void azx_firmware_cb(const struct firmware *fw, void *context) }#endif -static int azx_probe (struct pci_dev *pci, -const struct pci_device_id *pci_id) +static void azx_probe_work (struct work_struct *work) { -static int dev; -struct snd_card *card; -struct azx *chip; +struct azx *chip = + container_of(work, struct azx, probe_work.work); +struct snd_card *card = chip->card; +struct pci_dev *pci = chip->pci;bool probe_now;int err; -if (dev >=SNDRV_CARDS ) -return -ENODEV ; -if (!enable[dev]) { - dev++; -return -ENOENT ; - } - - err =snd_card_create (index[dev], id[dev],THIS_MODULE ,0 , &card); -if (err <0 ) { -snd_printk (KERN_ERR "hda-intel: Error creating card!\n" ); -return err; - } - -snd_card_set_dev (card, &pci->dev); - - err =azx_create (card, pci, dev, pci_id->driver_data, &chip); -if (err <0 ) - goto out_free; - card->private_data = chip; - -pci_set_drvdata (pci, card); - - err =register_vga_switcheroo (chip); -if (err <0 ) { - snd_printk(KERN_ERR SFX - "%s: Error registering VGA-switcheroo client\n", pci_name(pci)); - goto out_free; - } - -if (check_hdmi_disabled (pci)) { - snd_printk(KERN_INFO SFX "%s: VGA controller is disabled\n", - pci_name(pci)); - snd_printk(KERN_INFO SFX "%s: Delaying initialization\n", pci_name(pci)); - chip->disabled = true; - } -/* Request power well for Haswell HDA controller and codec */ if (chip->driver_caps &AZX_DCAPS_I915_POWERWELL ) {#ifdef CONFIG_SND_HDA_I915 err =hda_i915_init ();if (err <0 ) { snd_printk(KERN_ERR SFX "Error request power-well from i915\n"); -return err; + goto out_free; }hda_display_power (true);#else
@@ -3760,7 +3727,7 @@ static int azx_probe(struct pci_dev *pci, dev++;complete_all (&chip->probe_wait); -return 0 ; +return ; out_free_power:if (chip->driver_caps &AZX_DCAPS_I915_POWERWELL ) {hda_display_power (false);
@@ -3769,6 +3736,58 @@ out_free_power: out_free:snd_card_free (card);pci_set_drvdata (pci,NULL ); +} + +static int azx_probe (struct pci_dev *pci, +const struct pci_device_id *pci_id) +{ +struct snd_card *card; +struct azx *chip; +int err; + +if (dev >=SNDRV_CARDS ) +return -ENODEV ; +if (!enable[dev]) { + dev++; +return -ENOENT ; + } + + err =snd_card_create (index[dev], id[dev],THIS_MODULE ,0 , &card); +if (err <0 ) { +snd_printk (KERN_ERR "hda-intel: Error creating card!\n" ); +return err; + } + +snd_card_set_dev (card, &pci->dev); + + err =azx_create (card, pci, dev, pci_id->driver_data, &chip); +if (err <0 ) + goto out_free; + card->private_data = chip; + +pci_set_drvdata (pci, card); + + err =register_vga_switcheroo (chip); +if (err <0 ) { + snd_printk(KERN_ERR SFX + "%s: Error registering VGA-switcheroo client\n", pci_name(pci)); + goto out_free; + } + +if (check_hdmi_disabled (pci)) { + snd_printk(KERN_INFO SFX "%s: VGA controller is disabled\n", + pci_name(pci)); + snd_printk(KERN_INFO SFX "%s: Delaying initialization\n", pci_name(pci)); + chip->disabled = true; + } + +/* continue probing in work context as may trigger request module */ +INIT_DELAYED_WORK (&chip->probe_work, azx_probe_work); +schedule_delayed_work (&chip->probe_work,0 ); +return 0 ; +out_free: +snd_card_free (card); +pci_set_drvdata (pci,NULL );return err; }
Signature · 1 line
1.8.1.2
Re: [PATCH 4/4] ALSA: hda - Continue probe in work context to avoid request_module deadlock
At Thu, 23 May 2013 01:04:16 +0800,
Quoted 11 lines · Wang Xingchao
There's deadlock when
request_module(i915)inazx_probe.
It looks like:device_lock(audio pci device)->azx_probe->module_request(orsymbol_request) -> modprobe (userspace) -> i915 init ->drm_pci_init->pci_register_driver->bus_add_driver->driver_attach-> which in turn tries all locks on pci bus, and when it tries the one on the audio device, it will deadlock.This patch introduce a work to store remaining probe stuff, and let
request_modulerun in safe work context.
The bug is introduced by your patch, so better to fold into it. Moreover...
Quoted 11 lines
Signed-off-by Wang Xingchao <[email protected]>--- sound/pci/hda/hda_intel.c | 105 +++++++++++++++++++++++++++------------------- 1 file changed, 62 insertions(+), 43 deletions(-)sound/pci/hda/hda_intel.c +0
-0
sound/pci/hda/hda_intel.c static int probe_only[SNDRV_CARDS]; · line 79
Quoted 4 lines
sound/pci/hda/hda_intel.c +1
-0@@ -76,6 +76,7 @@ static int probe_only[SNDRV_CARDS];static int jackpoll_ms[SNDRV_CARDS ];static bool single_cmd;static int enable_msi =-1 ; +static int dev;
Don't do this.
Quoted 127 lines
sound/pci/hda/hda_intel.c +46
-43#ifdef CONFIG_SND_HDA_PATCH_LOADER static char *patch[SNDRV_CARDS ];#endif @@ -542,6 +543,8 @@ struct azx {/* for pending irqs */ struct work_struct irq_pending_work; +struct delayed_work probe_work; +/* reboot notifier (for mysterious hangup problem at power-down) */ struct notifier_block reboot_notifier;@@ -3670,58 +3673,22 @@ static void azx_firmware_cb(const struct firmware *fw, void *context) }#endif -static int azx_probe (struct pci_dev *pci, -const struct pci_device_id *pci_id) +static void azx_probe_work (struct work_struct *work) { -static int dev; -struct snd_card *card; -struct azx *chip; +struct azx *chip = + container_of(work, struct azx, probe_work.work); +struct snd_card *card = chip->card; +struct pci_dev *pci = chip->pci;bool probe_now;int err; -if (dev >=SNDRV_CARDS ) -return -ENODEV ; -if (!enable[dev]) { - dev++; -return -ENOENT ; - } - - err =snd_card_create (index[dev], id[dev],THIS_MODULE ,0 , &card); -if (err <0 ) { -snd_printk (KERN_ERR "hda-intel: Error creating card!\n" ); -return err; - } - -snd_card_set_dev (card, &pci->dev); - - err =azx_create (card, pci, dev, pci_id->driver_data, &chip); -if (err <0 ) - goto out_free; - card->private_data = chip; - -pci_set_drvdata (pci, card); - - err =register_vga_switcheroo (chip); -if (err <0 ) { - snd_printk(KERN_ERR SFX - "%s: Error registering VGA-switcheroo client\n", pci_name(pci)); - goto out_free; - } - -if (check_hdmi_disabled (pci)) { - snd_printk(KERN_INFO SFX "%s: VGA controller is disabled\n", - pci_name(pci)); - snd_printk(KERN_INFO SFX "%s: Delaying initialization\n", pci_name(pci)); - chip->disabled = true; - } -/* Request power well for Haswell HDA controller and codec */ if (chip->driver_caps &AZX_DCAPS_I915_POWERWELL ) {#ifdef CONFIG_SND_HDA_I915 err =hda_i915_init ();if (err <0 ) { snd_printk(KERN_ERR SFX "Error request power-well from i915\n"); -return err; + goto out_free; }hda_display_power (true);#else @@ -3760,7 +3727,7 @@ static int azx_probe(struct pci_dev *pci, dev++;complete_all (&chip->probe_wait); -return 0 ; +return ; out_free_power:if (chip->driver_caps &AZX_DCAPS_I915_POWERWELL ) {hda_display_power (false);@@ -3769,6 +3736,58 @@ out_free_power: out_free:snd_card_free (card);pci_set_drvdata (pci,NULL ); +} + +static int azx_probe (struct pci_dev *pci, +const struct pci_device_id *pci_id) +{ +struct snd_card *card; +struct azx *chip; +int err; + +if (dev >=SNDRV_CARDS ) +return -ENODEV ; +if (!enable[dev]) { + dev++; +return -ENOENT ; + } + + err =snd_card_create (index[dev], id[dev],THIS_MODULE ,0 , &card); +if (err <0 ) { +snd_printk (KERN_ERR "hda-intel: Error creating card!\n" ); +return err; + } + +snd_card_set_dev (card, &pci->dev); + + err =azx_create (card, pci, dev, pci_id->driver_data, &chip); +if (err <0 ) + goto out_free; + card->private_data = chip; + +pci_set_drvdata (pci, card); + + err =register_vga_switcheroo (chip); +if (err <0 ) { + snd_printk(KERN_ERR SFX + "%s: Error registering VGA-switcheroo client\n", pci_name(pci)); + goto out_free; + }
sound/pci/hda/hda_intel.c out_free_power: · line 3785
Quoted 10 lines
sound/pci/hda/hda_intel.c +10
-0+ +if (check_hdmi_disabled (pci)) { + snd_printk(KERN_INFO SFX "%s: VGA controller is disabled\n", + pci_name(pci)); + snd_printk(KERN_INFO SFX "%s: Delaying initialization\n", pci_name(pci)); + chip->disabled = true; + } + +/* continue probing in work context as may trigger request module */ +INIT_DELAYED_WORK (&chip->probe_work, azx_probe_work);
The initialization must be done earlier, in azx_create().
sound/pci/hda/hda_intel.c out_free_power: · line 3786
Quoted 1 line
sound/pci/hda/hda_intel.c +1
-0+schedule_delayed_work (&chip->probe_work,0 );
You shouldn't do async probe unless needed.
That is, this is required only for Haswell.
Also, if you delay the call of hda_i915_init(), you need to have a flag to indicate whether this initialization has been done, and call the counterpart in azx_free() only if the flag is set. Otherwise, you might call hda_i915_exit() & co even before calling hda_i915_init().
Another point to fix is to make sure to cancel the leftover work in destructor.
Last not but least, I guess the call of pm_runtime_put_noidle() in azx_probe() might be problematic. In theory it allows the runtime suspend before hda_i915_init() is done.
Maybe we should move pm_runtime_put_noidle() into azx_probe_continue(). And put the counterpart to azx_free() conditionally called with chip->running, or so.
But, this doesn't exclude the explicit suspend/resume -- you are calling hda_display_power() and this might be also before the actual initialization. Again, this must be conditional, too.
Takashi
Quoted 6 lines
sound/pci/hda/hda_intel.c +4
-0+return 0 ; +out_free: +snd_card_free (card); +pci_set_drvdata (pci,NULL );return err; }