All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4 V6] Power-well API implementation for Haswell
@ 2013-05-27  9:15 Wang Xingchao
  2013-05-27  9:15 ` [PATCH 1/4 V6] ALSA: hda - Fix runtime PM check Wang Xingchao
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Wang Xingchao @ 2013-05-27  9:15 UTC (permalink / raw)
  To: daniel, tiwai
  Cc: alsa-devel, jocelyn.li, intel-gfx, Wang Xingchao,
	liam.r.girdwood, david.henningsson

Hi all,

   This is V6 and here're some changes notes:

   change from V5-->V6:
   - Remove duplication code in new introduced probe work
   - move duplication code in azx_probe_continue
   - remove unused #ifdef
   - replace request_module with symbol_request
   - replace spin_lock_irq with spin_lock_irqsave in gfx side
   - other typo fixes 
   (review by Takashi)

   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

Takashi Iwai (1):
  ALSA: hda - Move azx_first_init() into azx_probe_continue()

Wang Xingchao (3):
  ALSA: hda - Fix runtime PM check
  ALSA: hda - Add power-welll support for haswell HDA
  i915/drm: Add private api for power well usage

 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           |    2 +
 sound/pci/hda/hda_i915.c         |   75 +++++++++++++++++++++++++++++++
 sound/pci/hda/hda_i915.h         |   35 +++++++++++++++
 sound/pci/hda/hda_intel.c        |   87 ++++++++++++++++++++++++++++-------
 10 files changed, 335 insertions(+), 24 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

-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/4 V6] ALSA: hda - Fix runtime PM check
  2013-05-27  9:15 [PATCH 0/4 V6] Power-well API implementation for Haswell Wang Xingchao
@ 2013-05-27  9:15 ` Wang Xingchao
  2013-05-27  9:15 ` [PATCH 2/4] ALSA: hda - Move azx_first_init() into azx_probe_continue() Wang Xingchao
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Wang Xingchao @ 2013-05-27  9:15 UTC (permalink / raw)
  To: daniel, tiwai
  Cc: alsa-devel, jocelyn.li, intel-gfx, Wang Xingchao,
	liam.r.girdwood, david.henningsson

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 <xingchao.wang@linux.intel.com>
---
 sound/pci/hda/hda_intel.c |   14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 418bfc0..cf3d36c 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -3091,8 +3091,13 @@ static int register_vga_switcheroo(struct azx *chip)
  */
 static int azx_free(struct azx *chip)
 {
+	struct pci_dev *pci = chip->pci;
 	int i;
 
+	if ((chip->driver_caps & AZX_DCAPS_PM_RUNTIME)
+			&& chip->running)
+		pm_runtime_get_noresume(&pci->dev);
+
 	azx_del_card_list(chip);
 
 	azx_notifier_unregister(chip);
@@ -3726,9 +3731,6 @@ static int azx_probe(struct pci_dev *pci,
 			goto out_free;
 	}
 
-	if (pci_dev_run_wake(pci))
-		pm_runtime_put_noidle(&pci->dev);
-
 	dev++;
 	complete_all(&chip->probe_wait);
 	return 0;
@@ -3741,6 +3743,7 @@ out_free:
 
 static int azx_probe_continue(struct azx *chip)
 {
+	struct pci_dev *pci = chip->pci;
 	int dev = chip->dev_index;
 	int err;
 
@@ -3788,6 +3791,8 @@ static int azx_probe_continue(struct azx *chip)
 	power_down_all_codecs(chip);
 	azx_notifier_register(chip);
 	azx_add_card_list(chip);
+	if (chip->driver_caps & AZX_DCAPS_PM_RUNTIME)
+		pm_runtime_put_noidle(&pci->dev);
 
 	return 0;
 
@@ -3800,9 +3805,6 @@ static void azx_remove(struct pci_dev *pci)
 {
 	struct snd_card *card = pci_get_drvdata(pci);
 
-	if (pci_dev_run_wake(pci))
-		pm_runtime_get_noresume(&pci->dev);
-
 	if (card)
 		snd_card_free(card);
 	pci_set_drvdata(pci, NULL);
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/4] ALSA: hda - Move azx_first_init() into azx_probe_continue()
  2013-05-27  9:15 [PATCH 0/4 V6] Power-well API implementation for Haswell Wang Xingchao
  2013-05-27  9:15 ` [PATCH 1/4 V6] ALSA: hda - Fix runtime PM check Wang Xingchao
@ 2013-05-27  9:15 ` Wang Xingchao
  2013-05-27  9:15 ` [PATCH 3/4 V6] ALSA: hda - Add power-welll support for haswell HDA Wang Xingchao
  2013-05-27  9:15 ` [PATCH 4/4 V6] i915/drm: Add private api for power well usage Wang Xingchao
  3 siblings, 0 replies; 7+ messages in thread
From: Wang Xingchao @ 2013-05-27  9:15 UTC (permalink / raw)
  To: daniel, tiwai
  Cc: alsa-devel, jocelyn.li, intel-gfx, liam.r.girdwood, david.henningsson

From: Takashi Iwai <tiwai@suse.de>

This is a preliminary work for the upcoming Haswell HDMI audio fixes.

azx_first_init() function can be safely called after the f/w loader,
since the f/w loader doesn't require the sound hardware initialization
beforehand.  Moving it into azx_probe_continue() cleans up the code
flow a bit.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/pci/hda/hda_intel.c |   13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index cf3d36c..49cc942 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -2977,7 +2977,6 @@ static void azx_notifier_unregister(struct azx *chip)
 		unregister_reboot_notifier(&chip->reboot_notifier);
 }
 
-static int azx_first_init(struct azx *chip);
 static int azx_probe_continue(struct azx *chip);
 
 #ifdef SUPPORT_VGA_SWITCHEROO
@@ -3004,8 +3003,7 @@ static void azx_vs_set_state(struct pci_dev *pci,
 			snd_printk(KERN_INFO SFX
 				   "%s: Start delayed initialization\n",
 				   pci_name(chip->pci));
-			if (azx_first_init(chip) < 0 ||
-			    azx_probe_continue(chip) < 0) {
+			if (azx_probe_continue(chip) < 0) {
 				snd_printk(KERN_ERR SFX
 					   "%s: initialization error\n",
 					   pci_name(chip->pci));
@@ -3706,11 +3704,6 @@ static int azx_probe(struct pci_dev *pci,
 	}
 
 	probe_now = !chip->disabled;
-	if (probe_now) {
-		err = azx_first_init(chip);
-		if (err < 0)
-			goto out_free;
-	}
 
 #ifdef CONFIG_SND_HDA_PATCH_LOADER
 	if (patch[dev] && *patch[dev]) {
@@ -3747,6 +3740,10 @@ static int azx_probe_continue(struct azx *chip)
 	int dev = chip->dev_index;
 	int err;
 
+	err = azx_first_init(chip);
+	if (err < 0)
+		goto out_free;
+
 #ifdef CONFIG_SND_HDA_INPUT_BEEP
 	chip->beep_mode = beep_mode[dev];
 #endif
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/4 V6] ALSA: hda - Add power-welll support for haswell HDA
  2013-05-27  9:15 [PATCH 0/4 V6] Power-well API implementation for Haswell Wang Xingchao
  2013-05-27  9:15 ` [PATCH 1/4 V6] ALSA: hda - Fix runtime PM check Wang Xingchao
  2013-05-27  9:15 ` [PATCH 2/4] ALSA: hda - Move azx_first_init() into azx_probe_continue() Wang Xingchao
@ 2013-05-27  9:15 ` Wang Xingchao
  2013-05-27  9:15 ` [PATCH 4/4 V6] i915/drm: Add private api for power well usage Wang Xingchao
  3 siblings, 0 replies; 7+ messages in thread
From: Wang Xingchao @ 2013-05-27  9:15 UTC (permalink / raw)
  To: daniel, tiwai
  Cc: alsa-devel, jocelyn.li, intel-gfx, Wang Xingchao,
	liam.r.girdwood, david.henningsson

For 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.

There'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.

Signed-off-by: Wang Xingchao <xingchao.wang@linux.intel.com>
---
 sound/pci/hda/Kconfig     |   10 ++++++
 sound/pci/hda/Makefile    |    2 ++
 sound/pci/hda/hda_i915.c  |   75 +++++++++++++++++++++++++++++++++++++++++++++
 sound/pci/hda/hda_i915.h  |   35 +++++++++++++++++++++
 sound/pci/hda/hda_intel.c |   60 ++++++++++++++++++++++++++++++++++--
 5 files changed, 179 insertions(+), 3 deletions(-)
 create mode 100644 sound/pci/hda/hda_i915.c
 create mode 100644 sound/pci/hda/hda_i915.h

diff --git a/sound/pci/hda/Kconfig b/sound/pci/hda/Kconfig
index 80a7d44..c5a872c 100644
--- a/sound/pci/hda/Kconfig
+++ b/sound/pci/hda/Kconfig
@@ -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
diff --git a/sound/pci/hda/Makefile b/sound/pci/hda/Makefile
index 24a2514..c091438 100644
--- a/sound/pci/hda/Makefile
+++ b/sound/pci/hda/Makefile
@@ -1,4 +1,6 @@
 snd-hda-intel-objs := hda_intel.o
+# for haswell power well
+snd-hda-intel-$(CONFIG_SND_HDA_I915) +=	hda_i915.o
 
 snd-hda-codec-y := hda_codec.o hda_jack.o hda_auto_parser.o
 snd-hda-codec-$(CONFIG_SND_HDA_GENERIC) += hda_generic.o
diff --git a/sound/pci/hda/hda_i915.c b/sound/pci/hda/hda_i915.c
new file mode 100644
index 0000000..76c13d5
--- /dev/null
+++ b/sound/pci/hda/hda_i915.c
@@ -0,0 +1,75 @@
+/*
+ *  hda_i915.c - routines for Haswell HDA controller power well support
+ *
+ *  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.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <sound/core.h>
+#include <drm/i915_powerwell.h>
+#include "hda_i915.h"
+
+static void (*get_power)(void);
+static void (*put_power)(void);
+
+void hda_display_power(bool enable)
+{
+	if (!get_power || !put_power)
+		return;
+
+	snd_printdd("HDA display power %s \n",
+			enable ? "Enable" : "Disable");
+	if (enable)
+		get_power();
+	else
+		put_power();
+}
+
+int hda_i915_init(void)
+{
+	int err = 0;
+
+	get_power = symbol_request(i915_request_power_well);
+	if (!get_power) {
+		snd_printk(KERN_WARNING "hda-i915: get_power symbol get fail\n");
+		return -ENODEV;
+	}
+
+	put_power = symbol_request(i915_release_power_well);
+	if (!put_power) {
+		symbol_put(i915_request_power_well);
+		get_power = NULL;
+		return -ENODEV;
+	}
+
+	snd_printd("HDA driver get symbol successfully from i915 module\n");
+
+	return err;
+}
+
+int hda_i915_exit(void)
+{
+	if (get_power) {
+		symbol_put(i915_request_power_well);
+		get_power = NULL;
+	}
+	if (put_power) {
+		symbol_put(i915_release_power_well);
+		put_power = NULL;
+	}
+
+	return 0;
+}
diff --git a/sound/pci/hda/hda_i915.h b/sound/pci/hda/hda_i915.h
new file mode 100644
index 0000000..5a63da2
--- /dev/null
+++ b/sound/pci/hda/hda_i915.h
@@ -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
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 49cc942..1dedcb1 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -62,6 +62,7 @@
 #include <linux/vga_switcheroo.h>
 #include <linux/firmware.h>
 #include "hda_codec.h"
+#include "hda_i915.h"
 
 
 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
@@ -541,6 +542,10 @@ struct azx {
 	/* for pending irqs */
 	struct work_struct irq_pending_work;
 
+#ifdef CONFIG_SND_HDA_I915
+	struct work_struct probe_work;
+#endif
+
 	/* reboot notifier (for mysterious hangup problem at power-down) */
 	struct notifier_block reboot_notifier;
 
@@ -594,6 +599,7 @@ enum {
 #define AZX_DCAPS_4K_BDLE_BOUNDARY (1 << 23)	/* BDLE in 4k boundary */
 #define AZX_DCAPS_COUNT_LPIB_DELAY  (1 << 25)	/* Take LPIB as delay */
 #define AZX_DCAPS_PM_RUNTIME	(1 << 26)	/* runtime PM support */
+#define AZX_DCAPS_I915_POWERWELL (1 << 27)	/* HSW i915 power well support */
 
 /* quirks for Intel PCH */
 #define AZX_DCAPS_INTEL_PCH_NOPM \
@@ -2869,6 +2875,8 @@ static int azx_suspend(struct device *dev)
 	pci_disable_device(pci);
 	pci_save_state(pci);
 	pci_set_power_state(pci, PCI_D3hot);
+	if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
+		hda_display_power(false);
 	return 0;
 }
 
@@ -2881,6 +2889,8 @@ static int azx_resume(struct device *dev)
 	if (chip->disabled)
 		return 0;
 
+	if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
+		hda_display_power(true);
 	pci_set_power_state(pci, PCI_D0);
 	pci_restore_state(pci);
 	if (pci_enable_device(pci) < 0) {
@@ -2913,6 +2923,8 @@ static int azx_runtime_suspend(struct device *dev)
 
 	azx_stop_chip(chip);
 	azx_clear_irq_pending(chip);
+	if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
+		hda_display_power(false);
 	return 0;
 }
 
@@ -2921,6 +2933,8 @@ static int azx_runtime_resume(struct device *dev)
 	struct snd_card *card = dev_get_drvdata(dev);
 	struct azx *chip = card->private_data;
 
+	if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
+		hda_display_power(true);
 	azx_init_pci(chip);
 	azx_init_chip(chip, 1);
 	return 0;
@@ -3147,6 +3161,10 @@ static int azx_free(struct azx *chip)
 	if (chip->fw)
 		release_firmware(chip->fw);
 #endif
+	if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
+		hda_display_power(false);
+		hda_i915_exit();
+	}
 	kfree(chip);
 
 	return 0;
@@ -3372,6 +3390,13 @@ static void azx_check_snoop_available(struct azx *chip)
 	}
 }
 
+#ifdef CONFIG_SND_HDA_I915
+static void azx_probe_work(struct work_struct *work)
+{
+	azx_probe_continue(container_of(work, struct azx, probe_work));
+}
+#endif
+
 /*
  * constructor
  */
@@ -3447,7 +3472,13 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci,
 		return err;
 	}
 
+#ifdef CONFIG_SND_HDA_I915
+	/* continue probing in work context as may trigger request module */
+	INIT_WORK(&chip->probe_work, azx_probe_work);
+#endif
+
 	*rchip = chip;
+
 	return 0;
 }
 
@@ -3718,6 +3749,16 @@ static int azx_probe(struct pci_dev *pci,
 	}
 #endif /* CONFIG_SND_HDA_PATCH_LOADER */
 
+	/* continue probing in work context, avoid request_module deadlock */
+	if (probe_now && (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)) {
+#ifdef CONFIG_SND_HDA_I915
+		probe_now = false;
+		schedule_work(&chip->probe_work);
+#else
+		snd_printk(KERN_ERR SFX "Haswell must build in CONFIG_SND_HDA_I915\n");
+#endif
+	}
+
 	if (probe_now) {
 		err = azx_probe_continue(chip);
 		if (err < 0)
@@ -3740,6 +3781,16 @@ static int azx_probe_continue(struct azx *chip)
 	int dev = chip->dev_index;
 	int err;
 
+	/* Request power well for Haswell HDA controller and codec */
+	if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
+		err = hda_i915_init();
+		if (err < 0) {
+			snd_printk(KERN_ERR SFX "Error request power-well from i915\n");
+			goto out_free;
+		}
+		hda_display_power(true);
+	}
+
 	err = azx_first_init(chip);
 	if (err < 0)
 		goto out_free;
@@ -3834,11 +3885,14 @@ static DEFINE_PCI_DEVICE_TABLE(azx_ids) = {
 	  .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
 	/* Haswell */
 	{ PCI_DEVICE(0x8086, 0x0a0c),
-	  .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH },
+	  .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH |
+	  AZX_DCAPS_I915_POWERWELL },
 	{ PCI_DEVICE(0x8086, 0x0c0c),
-	  .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH },
+	  .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH |
+	  AZX_DCAPS_I915_POWERWELL },
 	{ PCI_DEVICE(0x8086, 0x0d0c),
-	  .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH },
+	  .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH |
+	  AZX_DCAPS_I915_POWERWELL },
 	/* 5 Series/3400 */
 	{ PCI_DEVICE(0x8086, 0x3b56),
 	  .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM },
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/4 V6] i915/drm: Add private api for power well usage
  2013-05-27  9:15 [PATCH 0/4 V6] Power-well API implementation for Haswell Wang Xingchao
                   ` (2 preceding siblings ...)
  2013-05-27  9:15 ` [PATCH 3/4 V6] ALSA: hda - Add power-welll support for haswell HDA Wang Xingchao
@ 2013-05-27  9:15 ` Wang Xingchao
  2013-05-29 18:10   ` Damien Lespiau
  3 siblings, 1 reply; 7+ messages in thread
From: Wang Xingchao @ 2013-05-27  9:15 UTC (permalink / raw)
  To: daniel, tiwai
  Cc: alsa-devel, jocelyn.li, intel-gfx, Wang Xingchao, xingchao.wang,
	liam.r.girdwood, david.henningsson

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 <xingchao.wang@linux.intel.com>
---
 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

diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
index f5addac..b702915 100644
--- a/drivers/gpu/drm/i915/i915_dma.c
+++ b/drivers/gpu/drm/i915/i915_dma.c
@@ -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)
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 14817de..ea94e5e 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -720,6 +720,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;
@@ -1073,6 +1082,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;
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index 0f35545..8b5017d 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -754,6 +754,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_display_power_enabled(struct drm_device *dev,
 					enum intel_display_power_domain domain);
 extern void intel_init_power_well(struct drm_device *dev);
diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
index 1a76572..f429347 100644
--- a/drivers/gpu/drm/i915/intel_pm.c
+++ b/drivers/gpu/drm/i915/intel_pm.c
@@ -4502,18 +4502,12 @@ bool intel_display_power_enabled(struct drm_device *dev,
 	}
 }
 
-void intel_set_power_well(struct drm_device *dev, bool enable)
+static void __intel_set_power_well(struct drm_device *dev, bool enable)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	bool is_enabled, enable_requested;
 	uint32_t tmp;
 
-	if (!HAS_POWER_WELL(dev))
-		return;
-
-	if (!i915_disable_power_well && !enable)
-		return;
-
 	tmp = I915_READ(HSW_PWR_WELL_DRIVER);
 	is_enabled = tmp & HSW_PWR_WELL_STATE;
 	enable_requested = tmp & HSW_PWR_WELL_ENABLE;
@@ -4536,6 +4530,90 @@ void intel_set_power_well(struct drm_device *dev, bool enable)
 	}
 }
 
+static struct i915_power_well *hsw_pwr;
+
+/* Display audio driver power well request */
+void i915_request_power_well(void)
+{
+	if (hsw_pwr == NULL)
+		return;
+
+	spin_lock_irq(&hsw_pwr->lock);
+	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);
+	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;
+
+	hsw_pwr = kzalloc(sizeof *hsw_pwr, GFP_KERNEL);
+	if (hsw_pwr == NULL)
+		return -ENOMEM;
+
+	dev_priv->hsw_pwr = hsw_pwr;
+
+	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;
+
+	kfree(dev_priv->hsw_pwr);
+	dev_priv->hsw_pwr = NULL;
+	hsw_pwr = NULL;
+}
+
+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
diff --git a/include/drm/i915_powerwell.h b/include/drm/i915_powerwell.h
new file mode 100644
index 0000000..cfdc884
--- /dev/null
+++ b/include/drm/i915_powerwell.h
@@ -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_ */
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 4/4 V6] i915/drm: Add private api for power well usage
  2013-05-27  9:15 ` [PATCH 4/4 V6] i915/drm: Add private api for power well usage Wang Xingchao
@ 2013-05-29 18:10   ` Damien Lespiau
  2013-05-30 11:21     ` Wang, Xingchao
  0 siblings, 1 reply; 7+ messages in thread
From: Damien Lespiau @ 2013-05-29 18:10 UTC (permalink / raw)
  To: Wang Xingchao
  Cc: alsa-devel, liam.r.girdwood, tiwai, intel-gfx, jocelyn.li,
	david.henningsson

On Mon, May 27, 2013 at 05:15:16PM +0800, Wang Xingchao wrote:
> 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 <xingchao.wang@linux.intel.com>

Daniel, you probably want to give your opinion on the "2 APIs to manage
the power well" discussion below.

In case, the logic seems correct so: with or without the two nitpicks
below (that we can address later if deemed necessary):

Reviewed-by: Damien Lespiau <damien.lespiau@intel.com>

-- 
Damien

> ---
>  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
> 
> diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
> index f5addac..b702915 100644
> --- a/drivers/gpu/drm/i915/i915_dma.c
> +++ b/drivers/gpu/drm/i915/i915_dma.c
> @@ -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)
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index 14817de..ea94e5e 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -720,6 +720,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;
> @@ -1073,6 +1082,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;
> +

We usually just put the structure inside struct drm_i915_private and
pass it's pointer around instead of an allocation for a few bytes.

We also try quite hard to not be platform specific but feature specific
in our code (eg. HAS_POWER_WELL() and not IS_HASWELL()). hsw_pwr should
probably be renamed to power_well.

>  	enum no_fbc_reason no_fbc_reason;
>  
>  	struct drm_mm_node *compressed_fb;
> diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
> index 0f35545..8b5017d 100644
> --- a/drivers/gpu/drm/i915/intel_drv.h
> +++ b/drivers/gpu/drm/i915/intel_drv.h
> @@ -754,6 +754,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_display_power_enabled(struct drm_device *dev,
>  					enum intel_display_power_domain domain);
>  extern void intel_init_power_well(struct drm_device *dev);
> diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
> index 1a76572..f429347 100644
> --- a/drivers/gpu/drm/i915/intel_pm.c
> +++ b/drivers/gpu/drm/i915/intel_pm.c
> @@ -4502,18 +4502,12 @@ bool intel_display_power_enabled(struct drm_device *dev,
>  	}
>  }
>  
> -void intel_set_power_well(struct drm_device *dev, bool enable)
> +static void __intel_set_power_well(struct drm_device *dev, bool enable)
>  {
>  	struct drm_i915_private *dev_priv = dev->dev_private;
>  	bool is_enabled, enable_requested;
>  	uint32_t tmp;
>  
> -	if (!HAS_POWER_WELL(dev))
> -		return;
> -
> -	if (!i915_disable_power_well && !enable)
> -		return;
> -
>  	tmp = I915_READ(HSW_PWR_WELL_DRIVER);
>  	is_enabled = tmp & HSW_PWR_WELL_STATE;
>  	enable_requested = tmp & HSW_PWR_WELL_ENABLE;
> @@ -4536,6 +4530,90 @@ void intel_set_power_well(struct drm_device *dev, bool enable)
>  	}
>  }
>  
> +static struct i915_power_well *hsw_pwr;
> +
> +/* Display audio driver power well request */
> +void i915_request_power_well(void)
> +{
> +	if (hsw_pwr == NULL)
> +		return;
> +
> +	spin_lock_irq(&hsw_pwr->lock);
> +	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);
> +	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;
> +
> +	hsw_pwr = kzalloc(sizeof *hsw_pwr, GFP_KERNEL);
> +	if (hsw_pwr == NULL)
> +		return -ENOMEM;
> +
> +	dev_priv->hsw_pwr = hsw_pwr;
> +
> +	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;
> +
> +	kfree(dev_priv->hsw_pwr);
> +	dev_priv->hsw_pwr = NULL;
> +	hsw_pwr = NULL;
> +}
> +
> +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);
> +}
> +

Based on your previous feedback it seems that we don't yet have a
balanced number of calls to set_power_well() in the i915 driver (we
didn't need to), so blindy replacing the set_power_well() calls get
get()/put() doesn't work.

We probably want that to work at some point, but it needs someone to
have a look at where we want to put the callers on our side.

I think we can live with the transition period where we have these two
APIs, until we go back and fix this on the i915 side. But Daniel may be
of a different opinion.

On a side note, could you describe your test case so we can check we're
not regressing while doing some refactoring?

>  /*
>   * 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
> diff --git a/include/drm/i915_powerwell.h b/include/drm/i915_powerwell.h
> new file mode 100644
> index 0000000..cfdc884
> --- /dev/null
> +++ b/include/drm/i915_powerwell.h
> @@ -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);

Note that, to be fully future proof, this interface is likely to change
to add an enum intel_display_power_domain parameter (and add another
power domain enum for Audio). We don't need to do that now, but a patch
will follow at some point (and probably from me), you've been warned :)

-- 
Damien

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 4/4 V6] i915/drm: Add private api for power well usage
  2013-05-29 18:10   ` Damien Lespiau
@ 2013-05-30 11:21     ` Wang, Xingchao
  0 siblings, 0 replies; 7+ messages in thread
From: Wang, Xingchao @ 2013-05-30 11:21 UTC (permalink / raw)
  To: Lespiau, Damien
  Cc: alsa-devel, tiwai, intel-gfx, Li, Jocelyn, Girdwood, Liam R,
	david.henningsson

Hi Damien,

Thanks your review, comments inline. :)


> -----Original Message-----
> From: intel-gfx-bounces+xingchao.wang=intel.com@lists.freedesktop.org
> [mailto:intel-gfx-bounces+xingchao.wang=intel.com@lists.freedesktop.org] On
> Behalf Of Damien Lespiau
> Sent: Thursday, May 30, 2013 2:11 AM
> To: Wang Xingchao
> Cc: alsa-devel@alsa-project.org; Girdwood, Liam R; tiwai@suse.de;
> intel-gfx@lists.freedesktop.org; Li, Jocelyn; david.henningsson@canonical.com
> Subject: Re: [Intel-gfx] [PATCH 4/4 V6] i915/drm: Add private api for power well
> usage
> 
> On Mon, May 27, 2013 at 05:15:16PM +0800, Wang Xingchao wrote:
> > 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 <xingchao.wang@linux.intel.com>
> 
> Daniel, you probably want to give your opinion on the "2 APIs to manage the
> power well" discussion below.
> 
> In case, the logic seems correct so: with or without the two nitpicks below
> (that we can address later if deemed necessary):
> 
> Reviewed-by: Damien Lespiau <damien.lespiau@intel.com>
> 
> --
> Damien
> 
> > ---
> >  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
> >
> > diff --git a/drivers/gpu/drm/i915/i915_dma.c
> > b/drivers/gpu/drm/i915/i915_dma.c index f5addac..b702915 100644
> > --- a/drivers/gpu/drm/i915/i915_dma.c
> > +++ b/drivers/gpu/drm/i915/i915_dma.c
> > @@ -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)
> > diff --git a/drivers/gpu/drm/i915/i915_drv.h
> > b/drivers/gpu/drm/i915/i915_drv.h index 14817de..ea94e5e 100644
> > --- a/drivers/gpu/drm/i915/i915_drv.h
> > +++ b/drivers/gpu/drm/i915/i915_drv.h
> > @@ -720,6 +720,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;
> > @@ -1073,6 +1082,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;
> > +
> 
> We usually just put the structure inside struct drm_i915_private and pass it's
> pointer around instead of an allocation for a few bytes.
> 
> We also try quite hard to not be platform specific but feature specific in our
> code (eg. HAS_POWER_WELL() and not IS_HASWELL()). hsw_pwr should
> probably be renamed to power_well.

Good point. I will make changes accordingly in next version.

> 
> >  	enum no_fbc_reason no_fbc_reason;
> >
> >  	struct drm_mm_node *compressed_fb;
> > diff --git a/drivers/gpu/drm/i915/intel_drv.h
> > b/drivers/gpu/drm/i915/intel_drv.h
> > index 0f35545..8b5017d 100644
> > --- a/drivers/gpu/drm/i915/intel_drv.h
> > +++ b/drivers/gpu/drm/i915/intel_drv.h
> > @@ -754,6 +754,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_display_power_enabled(struct drm_device *dev,
> >  					enum intel_display_power_domain domain);  extern
> void
> > intel_init_power_well(struct drm_device *dev); diff --git
> > a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
> > index 1a76572..f429347 100644
> > --- a/drivers/gpu/drm/i915/intel_pm.c
> > +++ b/drivers/gpu/drm/i915/intel_pm.c
> > @@ -4502,18 +4502,12 @@ bool intel_display_power_enabled(struct
> drm_device *dev,
> >  	}
> >  }
> >
> > -void intel_set_power_well(struct drm_device *dev, bool enable)
> > +static void __intel_set_power_well(struct drm_device *dev, bool
> > +enable)
> >  {
> >  	struct drm_i915_private *dev_priv = dev->dev_private;
> >  	bool is_enabled, enable_requested;
> >  	uint32_t tmp;
> >
> > -	if (!HAS_POWER_WELL(dev))
> > -		return;
> > -
> > -	if (!i915_disable_power_well && !enable)
> > -		return;
> > -
> >  	tmp = I915_READ(HSW_PWR_WELL_DRIVER);
> >  	is_enabled = tmp & HSW_PWR_WELL_STATE;
> >  	enable_requested = tmp & HSW_PWR_WELL_ENABLE; @@ -4536,6
> +4530,90 @@
> > void intel_set_power_well(struct drm_device *dev, bool enable)
> >  	}
> >  }
> >
> > +static struct i915_power_well *hsw_pwr;
> > +
> > +/* Display audio driver power well request */ void
> > +i915_request_power_well(void) {
> > +	if (hsw_pwr == NULL)
> > +		return;
> > +
> > +	spin_lock_irq(&hsw_pwr->lock);
> > +	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);
> > +	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;
> > +
> > +	hsw_pwr = kzalloc(sizeof *hsw_pwr, GFP_KERNEL);
> > +	if (hsw_pwr == NULL)
> > +		return -ENOMEM;
> > +
> > +	dev_priv->hsw_pwr = hsw_pwr;
> > +
> > +	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;
> > +
> > +	kfree(dev_priv->hsw_pwr);
> > +	dev_priv->hsw_pwr = NULL;
> > +	hsw_pwr = NULL;
> > +}
> > +
> > +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);
> > +}
> > +
> 
> Based on your previous feedback it seems that we don't yet have a balanced
> number of calls to set_power_well() in the i915 driver (we didn't need to), so
> blindy replacing the set_power_well() calls get
> get()/put() doesn't work.

Yes that's true. That's why we introduce "i915_request" for protection. We can make
sure the audio side calling the APIs in balanced way but cannot guanrantee gfx side.
In fact it would shut down power well from gfx side without such protection, and audio driver
become unaccessible after losing power.

> 
> We probably want that to work at some point, but it needs someone to have a
> look at where we want to put the callers on our side.
> 
> I think we can live with the transition period where we have these two APIs,
> until we go back and fix this on the i915 side. But Daniel may be of a different
> opinion.
> 
> On a side note, could you describe your test case so we can check we're not
> regressing while doing some refactoring?

I tested the cases with Haswell eDP enabled(you can test with HDMI/DP monitor or else).
Please note you should test in below three ways to make sure power-well is working well along with audio.

Test 1: Bootup test
The patchset could fix dependency between i915 module and snd_hda_intel module. In case i915 module loaded
after snd_hda_i915, audio driver would try to load i915 module manually and make sure the symbol exported from
gfx side exist.

After bootup, Please check step 4 at below "Test 2", make sure the codec info are there.

Test 2: runtime test
Audio side would enter runtime suspend mode automatically and release power-well to avoid causing too 
Much power usage. And when exit from suspend mode, it would request power-well if it was shutdown.

1). enable power well feature by:
Echo 1 > /sys/module/i915/parameters/disable_power_well

2). enable auto-power save in audio driver side:
Echo 5 > /sys/module/snd_hda_intel/parameters/power_save
(means codec would enter suspend mode after "5" seconds)

3).HSW HD-A controller and codec would enter runtime suspend mode

4) cat /proc/asound/card0/codec#0
Check the full codec info,there should be eight node, like:

cat /proc/asound/card0/codec#0 |grep Node
Node 0x02 [Audio Output] wcaps 0x6611: 8-Channels Digital
Node 0x03 [Audio Output] wcaps 0x6611: 8-Channels Digital
Node 0x04 [Audio Output] wcaps 0x6611: 8-Channels Digital
Node 0x05 [Pin Complex] wcaps 0x40778d: 8-Channels Digital Amp-Out CP
Node 0x06 [Pin Complex] wcaps 0x40778d: 8-Channels Digital Amp-Out CP
Node 0x07 [Pin Complex] wcaps 0x40778d: 8-Channels Digital Amp-Out CP
Node 0x08 [Vendor Defined Widget] wcaps 0xf00000: Mono

Test 3: suspend/resume test 

Echo mem > /sys/power/state

Check codec info when exit from suspend. In the resume routine, if power-well
Was shutdown, audio driver would try to request power-well on.

(Also you can play audio on display port as test case)

> 
> >  /*
> >   * 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 diff --git a/include/drm/i915_powerwell.h
> > b/include/drm/i915_powerwell.h new file mode 100644 index
> > 0000000..cfdc884
> > --- /dev/null
> > +++ b/include/drm/i915_powerwell.h
> > @@ -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);
> 
> Note that, to be fully future proof, this interface is likely to change to add an
> enum intel_display_power_domain parameter (and add another power domain
> enum for Audio). We don't need to do that now, but a patch will follow at some
> point (and probably from me), you've been warned :)
> 

I see. please cc me when you send out the patch. :)
I can help test then and make sure audio works well.
Also if audio side need further improvement, we can cowork then.

Thanks
--xingchao 

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-05-30 11:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-27  9:15 [PATCH 0/4 V6] Power-well API implementation for Haswell Wang Xingchao
2013-05-27  9:15 ` [PATCH 1/4 V6] ALSA: hda - Fix runtime PM check Wang Xingchao
2013-05-27  9:15 ` [PATCH 2/4] ALSA: hda - Move azx_first_init() into azx_probe_continue() Wang Xingchao
2013-05-27  9:15 ` [PATCH 3/4 V6] ALSA: hda - Add power-welll support for haswell HDA Wang Xingchao
2013-05-27  9:15 ` [PATCH 4/4 V6] i915/drm: Add private api for power well usage Wang Xingchao
2013-05-29 18:10   ` Damien Lespiau
2013-05-30 11:21     ` Wang, Xingchao

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.