Skip to contentSkip to conversation

sound: Use -EPROBE_DEFER instead of i915 module loading.

PATCH Superseded Maarten Lankhorst 5 participants 24 messages Aug 7, 2023 – Aug 18, 2023

Subsystems (4)

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v3 cover sound: Use -EPROBE_DEFER instead of i915 module loading.

From: Maarten Lankhorst <[email protected]>

Explicitly loading i915 becomes a problem when upstreaming the new intel driver for Tiger Lake and higher graphics (xe). By loading i915, it doesn't wait for driver load of xe, and will fail completely before it loads.

-EPROBE_DEFER has to be returned before any device is created in probe(), otherwise the removal of the device will cause EPROBE_DEFER to try again in an infinite loop.

The conversion is done in gradual steps. First I add an argument to snd_hdac_i915_init to allow for -EPROBE_DEFER so I can convert each driver separately. Then I convert each driver to move snd_hdac_i915_init out of the workqueue. Finally I drop the ability to choose modprobe behavior after the last user is converted.

I suspect the avs and skylake drivers used snd_hdac_i915_init purely for the modprobe, but I don't have the hardware to test if it can be safely removed. It can still be done easily in a followup patch to simplify probing.

---
Changes since previous version:
- Keep the workqueue for soc/sof/intel, instead only move out snd_hdac_i915_init. (Patch 8/9) Rest of patches unchanged.

Cc Jaroslav Kysela <[email protected]>
Cc Takashi Iwai <[email protected]>
Cc Cezary Rojewski <[email protected]>
Cc Pierre-Louis Bossart <[email protected]>
Cc Liam Girdwood <[email protected]>
Cc Peter Ujfalusi <[email protected]>
Cc Bard Liao <[email protected]>
Cc Ranjani Sridharan <[email protected]>
Cc Kai Vehmanen <[email protected]>
Cc Mark Brown <[email protected]>
Cc Daniel Baluta <[email protected]>

Maarten Lankhorst (9):
ALSA: hda/intel: Fix error handling in azx_probe()
ALSA: hda/i915: Allow override of gpu binding.
ALSA: hda/i915: Add an allow_modprobe argument to snd_hdac_i915_init
ALSA: hda/i915: Allow xe as match for i915_component_master_match
ASoC: Intel: avs: Move snd_hdac_i915_init to before probe_work.
ASoC: Intel: Skylake: Move snd_hdac_i915_init to before probe_work.
ALSA: hda/intel: Move snd_hdac_i915_init to before probe_work.
ASoC: SOF: Intel: Move binding to display driver outside of deferred
probe
ALSA: hda/i915: Remove extra argument from snd_hdac_i915_init

 sound/hda/hdac_i915.c         | 25 ++++++++-------
 sound/pci/hda/hda_intel.c     | 60 ++++++++++++++++++-----------------
 sound/soc/intel/avs/core.c    | 13 +++++---
 sound/soc/intel/skylake/skl.c | 31 ++++++------------
 sound/soc/sof/core.c          | 19 ++++-------
 5 files changed, 70 insertions(+), 78 deletions(-)
Signature · 1 line
2.39.2
#1 lore raw

PATCH v3 1/9 ALSA: hda/intel: Fix error handling in azx_probe()

Add missing pci_set_drv to NULL call on error.

---
 sound/pci/hda/hda_intel.c | 1 +
 1 file changed, 1 insertion(+)
sound/pci/hda/hda_intel.c +1 -0
index ef831770ca7d..0d2d6bc6c75e 100644
@@ -2188,6 +2188,7 @@ static int azx_probe(struct pci_dev *pci,
 	return 0;
 
 out_free:
+	pci_set_drvdata(pci, NULL);
 	snd_card_free(card);
 	return err;
 }
Signature · 1 line
2.39.2
#2 lore raw

PATCH v3 2/9 ALSA: hda/i915: Allow override of gpu binding.

In reply to Maarten Lankhorst

Selecting CONFIG_DRM selects CONFIG_VIDEO_NOMODESET, which exports video_firmware_drivers_only(). This can be used as a first approximation on whether i915 will be available. It's safe to use as this is only built when CONFIG_SND_HDA_I915 is selected by CONFIG_I915.

It's not completely fool proof, as you can boot with "nomodeset i915.modeset=1" to make i915 load regardless, or use "i915.force_probe=!*" to never load i915, but the common case of booting with nomodeset to disable all GPU drivers this will work as intended.

Because of this, we add an extra module parameter, snd_hda_core.gpu_bind that can be used to signal users intent. -1 follows nomodeset, 0 disables binding, 1 forces wait/-EPROBE_DEFER on binding.

---
 sound/hda/hdac_i915.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
sound/hda/hdac_i915.c +10 -0
index 161a9711cd63..c32709fa4115 100644
@@ -11,6 +11,13 @@
 #include <sound/hda_i915.h>
 #include <sound/hda_register.h>
 
+#include <video/nomodeset.h>
+
+static int gpu_bind = -1;
+module_param(gpu_bind, int, 0644);
+MODULE_PARM_DESC(gpu_bind, "Whether to bind sound component to GPU "
+			   "(1=always, 0=never, -1=on nomodeset(default))");
+
 #define IS_HSW_CONTROLLER(pci) (((pci)->device == 0x0a0c) || \
 				((pci)->device == 0x0c0c) || \
 				((pci)->device == 0x0d0c) || \
@@ -121,6 +128,9 @@ static int i915_gfx_present(struct pci_dev *hdac_pci)
 {
 	struct pci_dev *display_dev = NULL;
 
+	if (!gpu_bind || (gpu_bind < 0 && video_firmware_drivers_only()))
+		return false;
+
 	for_each_pci_dev(display_dev) {
 		if (display_dev->vendor == PCI_VENDOR_ID_INTEL &&
 		    (display_dev->class >> 16) == PCI_BASE_CLASS_DISPLAY &&
Signature · 1 line
2.39.2
Reviewed-by on v3 2/9
#3 lore raw

Re: [PATCH v3 2/9] ALSA: hda/i915: Allow override of gpu binding.

Quoted 11 lines · Maarten Lankhorst

Selecting CONFIG_DRM selects CONFIG_VIDEO_NOMODESET, which exports video_firmware_drivers_only(). This can be used as a first approximation on whether i915 will be available. It's safe to use as this is only built when CONFIG_SND_HDA_I915 is selected by CONFIG_I915.

It's not completely fool proof, as you can boot with "nomodeset i915.modeset=1" to make i915 load regardless, or use "i915.force_probe=!*" to never load i915, but the common case of booting with nomodeset to disable all GPU drivers this will work as intended.

Quoted 8 lines

Because of this, we add an extra module parameter, snd_hda_core.gpu_bind that can be used to signal users intent. -1 follows nomodeset, 0 disables binding, 1 forces wait/-EPROBE_DEFER on binding.

#4 lore raw

PATCH v3 3/9 ALSA: hda/i915: Add an allow_modprobe argument to snd_hdac_i915_init

In reply to Maarten Lankhorst

Xe is a new GPU driver that re-uses the display (and sound) code from i915. It's no longer possible to load i915, as the GPU can be driven by the xe driver instead.

The new behavior will return -EPROBE_DEFER, and wait for a compatible driver to be loaded instead of modprobing i915.

Converting all drivers at the same time is a lot of work, instead we will convert each user one by one.

Changes since v1:
- Use dev_err_probe to set a probe reason for debugfs' deferred_devices.

---
 include/sound/hda_i915.h        | 4 ++--
 sound/hda/hdac_i915.c           | 8 ++++----
 sound/pci/hda/hda_intel.c       | 2 +-
 sound/soc/intel/avs/core.c      | 2 +-
 sound/soc/intel/skylake/skl.c   | 2 +-
 sound/soc/sof/intel/hda-codec.c | 2 +-
 6 files changed, 10 insertions(+), 10 deletions(-)
include/sound/hda_i915.h +2 -2
index 6b79614a893b..f91bd6636086 100644
@@ -9,12 +9,12 @@
 
 #ifdef CONFIG_SND_HDA_I915
 void snd_hdac_i915_set_bclk(struct hdac_bus *bus);
-int snd_hdac_i915_init(struct hdac_bus *bus);
+int snd_hdac_i915_init(struct hdac_bus *bus, bool allow_modprobe);
 #else
 static inline void snd_hdac_i915_set_bclk(struct hdac_bus *bus)
 {
 }
-static inline int snd_hdac_i915_init(struct hdac_bus *bus)
+static inline int snd_hdac_i915_init(struct hdac_bus *bus, bool allow_modprobe)
 {
 	return -ENODEV;
 }
sound/hda/hdac_i915.c +4 -4
index c32709fa4115..961fcd3397f4 100644
@@ -155,7 +155,7 @@ static int i915_gfx_present(struct pci_dev *hdac_pci)
  *
  * Returns zero for success or a negative error code.
  */
-int snd_hdac_i915_init(struct hdac_bus *bus)
+int snd_hdac_i915_init(struct hdac_bus *bus, bool allow_modprobe)
 {
 	struct drm_audio_component *acomp;
 	int err;
@@ -171,7 +171,7 @@ int snd_hdac_i915_init(struct hdac_bus *bus)
 	acomp = bus->audio_component;
 	if (!acomp)
 		return -ENODEV;
-	if (!acomp->ops) {
+	if (allow_modprobe && !acomp->ops) {
 		if (!IS_ENABLED(CONFIG_MODULES) ||
 		    !request_module("i915")) {
 			/* 60s timeout */
@@ -180,9 +180,9 @@ int snd_hdac_i915_init(struct hdac_bus *bus)
 		}
 	}
 	if (!acomp->ops) {
-		dev_info(bus->dev, "couldn't bind with audio component\n");
+		int err = allow_modprobe ? -ENODEV : -EPROBE_DEFER;
 		snd_hdac_acomp_exit(bus);
-		return -ENODEV;
+		return dev_err_probe(bus->dev, err, "couldn't bind with audio component\n");
 	}
 	return 0;
 }
sound/pci/hda/hda_intel.c +1 -1
index 0d2d6bc6c75e..11cf9907f039 100644
@@ -2277,7 +2277,7 @@ static int azx_probe_continue(struct azx *chip)
 
 	/* bind with i915 if needed */
 	if (chip->driver_caps & AZX_DCAPS_I915_COMPONENT) {
-		err = snd_hdac_i915_init(bus);
+		err = snd_hdac_i915_init(bus, true);
 		if (err < 0) {
 			/* if the controller is bound only with HDMI/DP
 			 * (for HSW and BDW), we need to abort the probe;
sound/soc/intel/avs/core.c +1 -1
index 637501850728..3311a6f14200 100644
@@ -191,7 +191,7 @@ static void avs_hda_probe_work(struct work_struct *work)
 
 	pm_runtime_set_active(bus->dev); /* clear runtime_error flag */
 
-	ret = snd_hdac_i915_init(bus);
+	ret = snd_hdac_i915_init(bus, true);
 	if (ret < 0)
 		dev_info(bus->dev, "i915 init unsuccessful: %d\n", ret);
 
sound/soc/intel/skylake/skl.c +1 -1
index 998bd0232cf1..4d93b8690467 100644
@@ -791,7 +791,7 @@ static int skl_i915_init(struct hdac_bus *bus)
 	 * The HDMI codec is in GPU so we need to ensure that it is powered
 	 * up and ready for probe
 	 */
-	err = snd_hdac_i915_init(bus);
+	err = snd_hdac_i915_init(bus, true);
 	if (err < 0)
 		return err;
 
sound/soc/sof/intel/hda-codec.c +1 -1
index 8a5e99a898ec..f1fd5b44aaac 100644
@@ -415,7 +415,7 @@ int hda_codec_i915_init(struct snd_sof_dev *sdev)
 		return 0;
 
 	/* i915 exposes a HDA codec for HDMI audio */
-	ret = snd_hdac_i915_init(bus);
+	ret = snd_hdac_i915_init(bus, true);
 	if (ret < 0)
 		return ret;
 
Signature · 1 line
2.39.2
Reviewed-by on v3 3/9
#5 lore raw

Re: [PATCH v3 3/9] ALSA: hda/i915: Add an allow_modprobe argument to snd_hdac_i915_init

Quoted 4 lines · Maarten Lankhorst

Xe is a new GPU driver that re-uses the display (and sound) code from i915. It's no longer possible to load i915, as the GPU can be driven by the xe driver instead.

Quoted 8 lines

The new behavior will return -EPROBE_DEFER, and wait for a compatible driver to be loaded instead of modprobing i915.

Converting all drivers at the same time is a lot of work, instead we will convert each user one by one.

Changes since v1:
- Use dev_err_probe to set a probe reason for debugfs' deferred_devices.

You want the changes below the --- line ...

Quoted 3 lines
Quoted 1 line

---

... here

Quoted 7 lines
 include/sound/hda_i915.h        | 4 ++--
 sound/hda/hdac_i915.c           | 8 ++++----
 sound/pci/hda/hda_intel.c       | 2 +-
 sound/soc/intel/avs/core.c      | 2 +-
 sound/soc/intel/skylake/skl.c   | 2 +-
 sound/soc/sof/intel/hda-codec.c | 2 +-
 6 files changed, 10 insertions(+), 10 deletions(-)
#6 lore raw

Re: [PATCH v3 3/9] ALSA: hda/i915: Add an allow_modprobe argument to snd_hdac_i915_init

Quoted 11 lines · Pierre-Louis Bossart
Quoted 7 lines · Maarten Lankhorst

Xe is a new GPU driver that re-uses the display (and sound) code from i915. It's no longer possible to load i915, as the GPU can be driven by the xe driver instead.

The new behavior will return -EPROBE_DEFER, and wait for a compatible driver to be loaded instead of modprobing i915.

Quoted 7 lines
Quoted 5 lines

Converting all drivers at the same time is a lot of work, instead we will convert each user one by one.

Changes since v1:
- Use dev_err_probe to set a probe reason for debugfs' deferred_devices.

You want the changes below the --- line ...

Note that there are subsystems preferring keeping the version change logs in the commit log (typically found in drm trees), although majority of subsystems (including sound) want rather cleaner logs, AFAIK.

Takashi

#7 lore raw

Re: [PATCH v3 3/9] ALSA: hda/i915: Add an allow_modprobe argument to snd_hdac_i915_init

Hey,

Quoted 19 lines · Takashi Iwai
Quoted 17 lines · Pierre-Louis Bossart
Quoted 12 lines · Maarten Lankhorst

Xe is a new GPU driver that re-uses the display (and sound) code from i915. It's no longer possible to load i915, as the GPU can be driven by the xe driver instead.

The new behavior will return -EPROBE_DEFER, and wait for a compatible driver to be loaded instead of modprobing i915.

Converting all drivers at the same time is a lot of work, instead we will convert each user one by one.

Changes since v1:
- Use dev_err_probe to set a probe reason for debugfs' deferred_devices.

Quoted 6 lines
Quoted 1 line

You want the changes below the --- line ...

Note that there are subsystems preferring keeping the version change logs in the commit log (typically found in drm trees), although majority of subsystems (including sound) want rather cleaner logs, AFAIK.

Yeah, I usually maintain stuff in drm. :)

Cheers,
~Maarten

#8 lore raw

PATCH v3 4/9 ALSA: hda/i915: Allow xe as match for i915_component_master_match

In reply to Maarten Lankhorst

xe is a new driver for intel GPU's that shares the sound related code with i915.

Don't allow it to be modprobed though; the module is not upstream yet and we should exclusively use the EPROBE_DEFER mechanism.

---
 sound/hda/hdac_i915.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
sound/hda/hdac_i915.c +2 -1
index 961fcd3397f4..12c1f8d93499 100644
@@ -115,7 +115,8 @@ static int i915_component_master_match(struct device *dev, int subcomponent,
 	hdac_pci = to_pci_dev(bus->dev);
 	i915_pci = to_pci_dev(dev);
 
-	if (!strcmp(dev->driver->name, "i915") &&
+	if ((!strcmp(dev->driver->name, "i915") ||
+		 !strcmp(dev->driver->name, "xe")) &&
 	    subcomponent == I915_COMPONENT_AUDIO &&
 	    connectivity_check(i915_pci, hdac_pci))
 		return 1;
Signature · 1 line
2.39.2
Reviewed-by on v3 4/9
#9 lore raw

Re: [PATCH v3 4/9] ALSA: hda/i915: Allow xe as match for i915_component_master_match

Quoted 5 lines · Maarten Lankhorst

xe is a new driver for intel GPU's that shares the sound related code with i915.

Don't allow it to be modprobed though; the module is not upstream yet and we should exclusively use the EPROBE_DEFER mechanism.

The wording hasn't changed and remains confusing, likely to trigger all paranoia triplines. Consider rewording if there's an update.

Quoted 3 lines
Quoted 18 lines
---
 sound/hda/hdac_i915.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
sound/hda/hdac_i915.c +2 -1
index 961fcd3397f4..12c1f8d93499 100644
@@ -115,7 +115,8 @@ static int i915_component_master_match(struct device *dev, int subcomponent,
 	hdac_pci = to_pci_dev(bus->dev);
 	i915_pci = to_pci_dev(dev);
 
-	if (!strcmp(dev->driver->name, "i915") &&
+	if ((!strcmp(dev->driver->name, "i915") ||
+		 !strcmp(dev->driver->name, "xe")) &&
 	    subcomponent == I915_COMPONENT_AUDIO &&
 	    connectivity_check(i915_pci, hdac_pci))
 		return 1;
#10 lore raw

PATCH v3 5/9 ASoC: Intel: avs: Move snd_hdac_i915_init to before probe_work.

In reply to Maarten Lankhorst

Now that we can use -EPROBE_DEFER, it's no longer required to spin off the snd_hdac_i915_init into a workqueue. It's likely the whole workqueue can be destroyed, but I don't have the means to test this.

Removing the workqueue would simplify init even further, but is left as exercise for the reviewer.

Changes since v1:
- Rename error label.

---
 sound/soc/intel/avs/core.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
sound/soc/intel/avs/core.c +9 -4
index 3311a6f14200..64e7a4e650a8 100644
@@ -191,10 +191,6 @@ static void avs_hda_probe_work(struct work_struct *work)
 
 	pm_runtime_set_active(bus->dev); /* clear runtime_error flag */
 
-	ret = snd_hdac_i915_init(bus, true);
-	if (ret < 0)
-		dev_info(bus->dev, "i915 init unsuccessful: %d\n", ret);
-
 	snd_hdac_display_power(bus, HDA_CODEC_IDX_CONTROLLER, true);
 	avs_hdac_bus_init_chip(bus, true);
 	avs_hdac_bus_probe_codecs(bus);
@@ -465,10 +461,19 @@ static int avs_pci_probe(struct pci_dev *pci, const struct pci_device_id *id)
 	pci_set_drvdata(pci, bus);
 	device_disable_async_suspend(dev);
 
+	ret = snd_hdac_i915_init(bus, false);
+	if (ret == -EPROBE_DEFER)
+		goto err_i915_init;
+	else if (ret < 0)
+		dev_info(bus->dev, "i915 init unsuccessful: %d\n", ret);
+
 	schedule_work(&adev->probe_work);
 
 	return 0;
 
+err_i915_init:
+	pci_clear_master(pci);
+	pci_set_drvdata(pci, NULL);
 err_acquire_irq:
 	snd_hdac_bus_free_stream_pages(bus);
 	snd_hdac_ext_stream_free_all(bus);
Signature · 1 line
2.39.2
#11 lore raw

Re: [PATCH v3 5/9] ASoC: Intel: avs: Move snd_hdac_i915_init to before probe_work.

Quoted 9 lines · Maarten Lankhorst

Now that we can use -EPROBE_DEFER, it's no longer required to spin off the snd_hdac_i915_init into a workqueue. It's likely the whole workqueue can be destroyed, but I don't have the means to test this.

Removing the workqueue would simplify init even further, but is left as exercise for the reviewer.

Changes since v1:
- Rename error label.

same issue with changes, they need to be ...

Quoted 4 lines

...here

Quoted 38 lines
 sound/soc/intel/avs/core.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
sound/soc/intel/avs/core.c +9 -4
index 3311a6f14200..64e7a4e650a8 100644
@@ -191,10 +191,6 @@ static void avs_hda_probe_work(struct work_struct *work)
 
 	pm_runtime_set_active(bus->dev); /* clear runtime_error flag */
 
-	ret = snd_hdac_i915_init(bus, true);
-	if (ret < 0)
-		dev_info(bus->dev, "i915 init unsuccessful: %d\n", ret);
-
 	snd_hdac_display_power(bus, HDA_CODEC_IDX_CONTROLLER, true);
 	avs_hdac_bus_init_chip(bus, true);
 	avs_hdac_bus_probe_codecs(bus);
@@ -465,10 +461,19 @@ static int avs_pci_probe(struct pci_dev *pci, const struct pci_device_id *id)
 	pci_set_drvdata(pci, bus);
 	device_disable_async_suspend(dev);
 
+	ret = snd_hdac_i915_init(bus, false);
+	if (ret == -EPROBE_DEFER)
+		goto err_i915_init;
+	else if (ret < 0)
+		dev_info(bus->dev, "i915 init unsuccessful: %d\n", ret);
+
 	schedule_work(&adev->probe_work);
 
 	return 0;
 
+err_i915_init:
+	pci_clear_master(pci);
+	pci_set_drvdata(pci, NULL);
 err_acquire_irq:
 	snd_hdac_bus_free_stream_pages(bus);
 	snd_hdac_ext_stream_free_all(bus);
#12 lore raw

PATCH v3 6/9 ASoC: Intel: Skylake: Move snd_hdac_i915_init to before probe_work.

In reply to Maarten Lankhorst

Now that we can use -EPROBE_DEFER, it's no longer required to spin off the snd_hdac_i915_init into a workqueue. It's likely the whole workqueue can be destroyed, but I don't have the means to test this.

Removing the workqueue would simplify init even further, but is left as exercise for the reviewer.

---
 sound/soc/intel/skylake/skl.c | 31 +++++++++----------------------
 1 file changed, 9 insertions(+), 22 deletions(-)
sound/soc/intel/skylake/skl.c +9 -22
index 4d93b8690467..ff80d83a9fb7 100644
@@ -783,23 +783,6 @@ static void skl_codec_create(struct hdac_bus *bus)
 	}
 }
 
-static int skl_i915_init(struct hdac_bus *bus)
-{
-	int err;
-
-	/*
-	 * The HDMI codec is in GPU so we need to ensure that it is powered
-	 * up and ready for probe
-	 */
-	err = snd_hdac_i915_init(bus, true);
-	if (err < 0)
-		return err;
-
-	snd_hdac_display_power(bus, HDA_CODEC_IDX_CONTROLLER, true);
-
-	return 0;
-}
-
 static void skl_probe_work(struct work_struct *work)
 {
 	struct skl_dev *skl = container_of(work, struct skl_dev, probe_work);
@@ -807,11 +790,8 @@ static void skl_probe_work(struct work_struct *work)
 	struct hdac_ext_link *hlink;
 	int err;
 
-	if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)) {
-		err = skl_i915_init(bus);
-		if (err < 0)
-			return;
-	}
+	if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI))
+		snd_hdac_display_power(bus, HDA_CODEC_IDX_CONTROLLER, true);
 
 	skl_init_pci(skl);
 	skl_dum_set(bus);
@@ -1075,10 +1055,17 @@ static int skl_probe(struct pci_dev *pci,
 		goto out_dsp_free;
 	}
 
+	if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)) {
+		err = snd_hdac_i915_init(bus, false);
+		if (err < 0)
+			goto out_dmic_unregister;
+	}
 	schedule_work(&skl->probe_work);
 
 	return 0;
 
+out_dmic_unregister:
+	skl_dmic_device_unregister(skl);
 out_dsp_free:
 	skl_free_dsp(skl);
 out_clk_free:
Signature · 1 line
2.39.2
#13 lore raw

PATCH v3 7/9 ALSA: hda/intel: Move snd_hdac_i915_init to before probe_work.

In reply to Maarten Lankhorst

Now that we can use -EPROBE_DEFER, it's no longer required to spin off the snd_hdac_i915_init into a workqueue.

Use the -EPROBE_DEFER mechanism instead, which must be returned in the probe function.

Changes since v1:
- Use dev_err_probe()
- Don't move probed_devs bitmap unnecessarily. (tiwai)
- Move snd_hdac_i915_init slightly upward, to ensure it's always initialised before vga-switcheroo is called.

---
 sound/pci/hda/hda_intel.c | 59 ++++++++++++++++++++-------------------
 1 file changed, 30 insertions(+), 29 deletions(-)
sound/pci/hda/hda_intel.c +30 -29
index 11cf9907f039..e3128d7d742e 100644
@@ -2147,6 +2147,36 @@ static int azx_probe(struct pci_dev *pci,
 
 	pci_set_drvdata(pci, card);
 
+#ifdef CONFIG_SND_HDA_I915
+	/* bind with i915 if needed */
+	if (chip->driver_caps & AZX_DCAPS_I915_COMPONENT) {
+		err = snd_hdac_i915_init(azx_bus(chip), false);
+		if (err < 0) {
+			/* if the controller is bound only with HDMI/DP
+			 * (for HSW and BDW), we need to abort the probe;
+			 * for other chips, still continue probing as other
+			 * codecs can be on the same link.
+			 */
+			if (CONTROLLER_IN_GPU(pci)) {
+				dev_err_probe(card->dev, err,
+					     "HSW/BDW HD-audio HDMI/DP requires binding with gfx driver\n");
+
+				goto out_free;
+			} else {
+				/* don't bother any longer */
+				chip->driver_caps &= ~AZX_DCAPS_I915_COMPONENT;
+			}
+		}
+
+		/* HSW/BDW controllers need this power */
+		if (CONTROLLER_IN_GPU(pci))
+			hda->need_i915_power = true;
+	}
+#else
+	if (CONTROLLER_IN_GPU(pci))
+		dev_err(card->dev, "Haswell/Broadwell HDMI/DP must build in CONFIG_SND_HDA_I915\n");
+#endif
+
 	err = register_vga_switcheroo(chip);
 	if (err < 0) {
 		dev_err(card->dev, "Error registering vga_switcheroo client\n");
@@ -2174,11 +2204,6 @@ static int azx_probe(struct pci_dev *pci,
 	}
 #endif /* CONFIG_SND_HDA_PATCH_LOADER */
 
-#ifndef CONFIG_SND_HDA_I915
-	if (CONTROLLER_IN_GPU(pci))
-		dev_err(card->dev, "Haswell/Broadwell HDMI/DP must build in CONFIG_SND_HDA_I915\n");
-#endif
-
 	if (schedule_probe)
 		schedule_delayed_work(&hda->probe_work, 0);
 
@@ -2275,30 +2300,6 @@ static int azx_probe_continue(struct azx *chip)
 	to_hda_bus(bus)->bus_probing = 1;
 	hda->probe_continued = 1;
 
-	/* bind with i915 if needed */
-	if (chip->driver_caps & AZX_DCAPS_I915_COMPONENT) {
-		err = snd_hdac_i915_init(bus, true);
-		if (err < 0) {
-			/* if the controller is bound only with HDMI/DP
-			 * (for HSW and BDW), we need to abort the probe;
-			 * for other chips, still continue probing as other
-			 * codecs can be on the same link.
-			 */
-			if (CONTROLLER_IN_GPU(pci)) {
-				dev_err(chip->card->dev,
-					"HSW/BDW HD-audio HDMI/DP requires binding with gfx driver\n");
-				goto out_free;
-			} else {
-				/* don't bother any longer */
-				chip->driver_caps &= ~AZX_DCAPS_I915_COMPONENT;
-			}
-		}
-
-		/* HSW/BDW controllers need this power */
-		if (CONTROLLER_IN_GPU(pci))
-			hda->need_i915_power = true;
-	}
-
 	/* Request display power well for the HDA controller or codec. For
 	 * Haswell/Broadwell, both the display HDA controller and codec need
 	 * this power. For other platforms, like Baytrail/Braswell, only the
Signature · 1 line
2.39.2
Reviewed-by on v3 7/9
#14 lore raw

Re: [PATCH v3 7/9] ALSA: hda/intel: Move snd_hdac_i915_init to before probe_work.

Quoted 11 lines · Maarten Lankhorst

Now that we can use -EPROBE_DEFER, it's no longer required to spin off the snd_hdac_i915_init into a workqueue.

Use the -EPROBE_DEFER mechanism instead, which must be returned in the probe function.

Changes since v1:
- Use dev_err_probe()
- Don't move probed_devs bitmap unnecessarily. (tiwai)
- Move snd_hdac_i915_init slightly upward, to ensure it's always initialised before vga-switcheroo is called.

same issue with changes.

Quoted 3 lines
#15 lore raw

PATCH v3 8/9 ASoC: SOF: Intel: Move binding to display driver outside of deferred probe

In reply to Maarten Lankhorst

Now that we can use -EPROBE_DEFER, it's no longer required to spin off the snd_hdac_i915_init into a workqueue.

Use the -EPROBE_DEFER mechanism instead, which must be returned in the probe function.

---
 sound/soc/sof/core.c            | 19 +++++++------------
 sound/soc/sof/intel/hda-codec.c |  2 +-
 2 files changed, 8 insertions(+), 13 deletions(-)
sound/soc/sof/core.c +7 -12
index 30db685cc5f4..cd4d06d1800b 100644
@@ -188,13 +188,6 @@ static int sof_probe_continue(struct snd_sof_dev *sdev)
 	struct snd_sof_pdata *plat_data = sdev->pdata;
 	int ret;
 
-	/* probe the DSP hardware */
-	ret = snd_sof_probe(sdev);
-	if (ret < 0) {
-		dev_err(sdev->dev, "error: failed to probe DSP %d\n", ret);
-		goto probe_err;
-	}
-
 	sof_set_fw_state(sdev, SOF_FW_BOOT_PREPARE);
 
 	/* check machine info */
@@ -325,10 +318,6 @@ static int sof_probe_continue(struct snd_sof_dev *sdev)
 dbg_err:
 	snd_sof_free_debug(sdev);
 dsp_err:
-	snd_sof_remove(sdev);
-probe_err:
-	sof_ops_free(sdev);
-
 	/* all resources freed, update state to match */
 	sof_set_fw_state(sdev, SOF_FW_BOOT_NOT_STARTED);
 	sdev->first_boot = true;
@@ -436,6 +425,12 @@ int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data)
 
 	sof_set_fw_state(sdev, SOF_FW_BOOT_NOT_STARTED);
 
+	ret = snd_sof_probe(sdev);
+	if (ret) {
+		dev_err_probe(sdev->dev, ret, "failed to probe DSP\n");
+		return ret;
+	}
+
 	if (IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)) {
 		INIT_WORK(&sdev->probe_work, sof_probe_work);
 		schedule_work(&sdev->probe_work);
@@ -485,9 +480,9 @@ int snd_sof_device_remove(struct device *dev)
 
 		snd_sof_ipc_free(sdev);
 		snd_sof_free_debug(sdev);
-		snd_sof_remove(sdev);
 	}
 
+	snd_sof_remove(sdev);
 	sof_ops_free(sdev);
 
 	/* release firmware */
sound/soc/sof/intel/hda-codec.c +1 -1
index f1fd5b44aaac..344b61576c0e 100644
@@ -415,7 +415,7 @@ int hda_codec_i915_init(struct snd_sof_dev *sdev)
 		return 0;
 
 	/* i915 exposes a HDA codec for HDMI audio */
-	ret = snd_hdac_i915_init(bus, true);
+	ret = snd_hdac_i915_init(bus, false);
 	if (ret < 0)
 		return ret;
 
Signature · 1 line
2.39.2
#16 lore raw

Re: [PATCH v3 8/9] ASoC: SOF: Intel: Move binding to display driver outside of deferred probe

Quoted 5 lines · Maarten Lankhorst

Now that we can use -EPROBE_DEFER, it's no longer required to spin off the snd_hdac_i915_init into a workqueue.

Use the -EPROBE_DEFER mechanism instead, which must be returned in the probe function.

I don't think this patch is aligned with the previous discussions. What we agreed on is that snd_hdac_i915_init() would be called from and not from the workqueue.

But this patch also moves all codec initialization out of the workqueue.

I think we need two callbacks for device-specific initilization, one that is called from the probe function and one from the workqueue, otherwise we'll have a structure that differs from the snd-hda-intel - which would be rather silly in terms of support/debug.

I realize there's quite a bit of surgery involved, and most likely the SOF folks should provide this patch for you to build on.

Quoted 72 lines
---
 sound/soc/sof/core.c            | 19 +++++++------------
 sound/soc/sof/intel/hda-codec.c |  2 +-
 2 files changed, 8 insertions(+), 13 deletions(-)
sound/soc/sof/core.c +7 -12
index 30db685cc5f4..cd4d06d1800b 100644
@@ -188,13 +188,6 @@ static int sof_probe_continue(struct snd_sof_dev *sdev)
 	struct snd_sof_pdata *plat_data = sdev->pdata;
 	int ret;
 
-	/* probe the DSP hardware */
-	ret = snd_sof_probe(sdev);
-	if (ret < 0) {
-		dev_err(sdev->dev, "error: failed to probe DSP %d\n", ret);
-		goto probe_err;
-	}
-
 	sof_set_fw_state(sdev, SOF_FW_BOOT_PREPARE);
 
 	/* check machine info */
@@ -325,10 +318,6 @@ static int sof_probe_continue(struct snd_sof_dev *sdev)
 dbg_err:
 	snd_sof_free_debug(sdev);
 dsp_err:
-	snd_sof_remove(sdev);
-probe_err:
-	sof_ops_free(sdev);
-
 	/* all resources freed, update state to match */
 	sof_set_fw_state(sdev, SOF_FW_BOOT_NOT_STARTED);
 	sdev->first_boot = true;
@@ -436,6 +425,12 @@ int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data)
 
 	sof_set_fw_state(sdev, SOF_FW_BOOT_NOT_STARTED);
 
+	ret = snd_sof_probe(sdev);
+	if (ret) {
+		dev_err_probe(sdev->dev, ret, "failed to probe DSP\n");
+		return ret;
+	}
+
 	if (IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)) {
 		INIT_WORK(&sdev->probe_work, sof_probe_work);
 		schedule_work(&sdev->probe_work);
@@ -485,9 +480,9 @@ int snd_sof_device_remove(struct device *dev)
 
 		snd_sof_ipc_free(sdev);
 		snd_sof_free_debug(sdev);
-		snd_sof_remove(sdev);
 	}
 
+	snd_sof_remove(sdev);
 	sof_ops_free(sdev);
 
 	/* release firmware */
sound/soc/sof/intel/hda-codec.c +1 -1
index f1fd5b44aaac..344b61576c0e 100644
@@ -415,7 +415,7 @@ int hda_codec_i915_init(struct snd_sof_dev *sdev)
 		return 0;
 
 	/* i915 exposes a HDA codec for HDMI audio */
-	ret = snd_hdac_i915_init(bus, true);
+	ret = snd_hdac_i915_init(bus, false);
 	if (ret < 0)
 		return ret;
 
#17 lore raw

Re: [PATCH v3 8/9] ASoC: SOF: Intel: Move binding to display driver outside of deferred probe

Quoted 16 lines · Pierre-Louis Bossart
Quoted 5 lines · Maarten Lankhorst

Now that we can use -EPROBE_DEFER, it's no longer required to spin off the snd_hdac_i915_init into a workqueue.

Use the -EPROBE_DEFER mechanism instead, which must be returned in the probe function.

I don't think this patch is aligned with the previous discussions. What we agreed on is that snd_hdac_i915_init() would be called from and not from the workqueue.

But this patch also moves all codec initialization out of the workqueue.

Quoted 7 lines

I think we need two callbacks for device-specific initilization, one that is called from the probe function and one from the workqueue, otherwise we'll have a structure that differs from the snd-hda-intel - which would be rather silly in terms of support/debug.

I realize there's quite a bit of surgery involved, and most likely the SOF folks should provide this patch for you to build on.

So this patch looks like the only significant concern in the whole patch set. Can we reach to some agreement for merging to 6.6 in time?

thanks,

Takashi

#18 lore raw

Re: [PATCH v3 8/9] ASoC: SOF: Intel: Move binding to display driver outside of deferred probe

Ping on this?

Quoted 33 lines · Takashi Iwai
Quoted 16 lines · Pierre-Louis Bossart
Quoted 5 lines · Maarten Lankhorst

Now that we can use -EPROBE_DEFER, it's no longer required to spin off the snd_hdac_i915_init into a workqueue.

Use the -EPROBE_DEFER mechanism instead, which must be returned in the probe function.

I don't think this patch is aligned with the previous discussions. What we agreed on is that snd_hdac_i915_init() would be called from and not from the workqueue.

But this patch also moves all codec initialization out of the workqueue.

Quoted 7 lines

I think we need two callbacks for device-specific initilization, one that is called from the probe function and one from the workqueue, otherwise we'll have a structure that differs from the snd-hda-intel - which would be rather silly in terms of support/debug.

I realize there's quite a bit of surgery involved, and most likely the SOF folks should provide this patch for you to build on.

So this patch looks like the only significant concern in the whole patch set. Can we reach to some agreement for merging to 6.6 in time?

thanks,

Takashi

#19 lore raw

Re: [PATCH v3 8/9] ASoC: SOF: Intel: Move binding to display driver outside of deferred probe

Quoted 2 lines · Maarten Lankhorst

Ping on this?

Pierre? Does one of your recent patch sets achieves the suggested thing? Or do we need another rewrite/respin of this series? Currently it's blocking the merge for 6.6.

Takashi

Quoted 35 lines · Takashi Iwai
Quoted 33 lines
Quoted 16 lines · Pierre-Louis Bossart
Quoted 5 lines · Maarten Lankhorst

Now that we can use -EPROBE_DEFER, it's no longer required to spin off the snd_hdac_i915_init into a workqueue.

Use the -EPROBE_DEFER mechanism instead, which must be returned in the probe function.

I don't think this patch is aligned with the previous discussions. What we agreed on is that snd_hdac_i915_init() would be called from and not from the workqueue.

But this patch also moves all codec initialization out of the workqueue.

Quoted 7 lines

I think we need two callbacks for device-specific initilization, one that is called from the probe function and one from the workqueue, otherwise we'll have a structure that differs from the snd-hda-intel - which would be rather silly in terms of support/debug.

I realize there's quite a bit of surgery involved, and most likely the SOF folks should provide this patch for you to build on.

So this patch looks like the only significant concern in the whole patch set. Can we reach to some agreement for merging to 6.6 in time?

thanks,

Takashi

maintainer
#20 lore raw

Re: [PATCH v3 8/9] ASoC: SOF: Intel: Move binding to display driver outside of deferred probe

Hi,

Quoted 8 lines · Takashi Iwai
Quoted 2 lines · Maarten Lankhorst

Ping on this?

Pierre? Does one of your recent patch sets achieves the suggested thing? Or do we need another rewrite/respin of this series? Currently it's blocking the merge for 6.6.

this is likely to require another spin. Pierre did a draft of the new ops at https://github.com/thesofproject/linux/pull/4527
and Maarten is looking to adapt the series to this.

Br, Kai

#21 lore raw

Re: [PATCH v3 8/9] ASoC: SOF: Intel: Move binding to display driver outside of deferred probe

Quoted 10 lines · Kai Vehmanen

Hi,

Quoted 5 lines · Takashi Iwai
Quoted 2 lines · Maarten Lankhorst

Ping on this?

Quoted 7 lines
Quoted 3 lines

Pierre? Does one of your recent patch sets achieves the suggested thing? Or do we need another rewrite/respin of this series? Currently it's blocking the merge for 6.6.

this is likely to require another spin. Pierre did a draft of the new ops at https://github.com/thesofproject/linux/pull/4527
and Maarten is looking to adapt the series to this.

OK, then it can be too late for 6.6, unfortunately.

Takashi

#22 lore raw

PATCH v3 9/9 ALSA: hda/i915: Remove extra argument from snd_hdac_i915_init

In reply to Maarten Lankhorst

Now that all drivers have moved from modprobe loading to handling -EPROBE_DEFER, we can remove the argument again.

Changes since v1:
- Use dev_err_probe() to set reason in debugfs for deferred probe.

---
 include/sound/hda_i915.h        |  4 ++--
 sound/hda/hdac_i915.c           | 14 +++-----------
 sound/pci/hda/hda_intel.c       |  2 +-
 sound/soc/intel/avs/core.c      |  2 +-
 sound/soc/intel/skylake/skl.c   |  2 +-
 sound/soc/sof/intel/hda-codec.c |  2 +-
 6 files changed, 9 insertions(+), 17 deletions(-)
include/sound/hda_i915.h +2 -2
index f91bd6636086..6b79614a893b 100644
@@ -9,12 +9,12 @@
 
 #ifdef CONFIG_SND_HDA_I915
 void snd_hdac_i915_set_bclk(struct hdac_bus *bus);
-int snd_hdac_i915_init(struct hdac_bus *bus, bool allow_modprobe);
+int snd_hdac_i915_init(struct hdac_bus *bus);
 #else
 static inline void snd_hdac_i915_set_bclk(struct hdac_bus *bus)
 {
 }
-static inline int snd_hdac_i915_init(struct hdac_bus *bus, bool allow_modprobe)
+static inline int snd_hdac_i915_init(struct hdac_bus *bus)
 {
 	return -ENODEV;
 }
sound/hda/hdac_i915.c +3 -11
index 12c1f8d93499..ad13f0e2f94f 100644
@@ -156,7 +156,7 @@ static int i915_gfx_present(struct pci_dev *hdac_pci)
  *
  * Returns zero for success or a negative error code.
  */
-int snd_hdac_i915_init(struct hdac_bus *bus, bool allow_modprobe)
+int snd_hdac_i915_init(struct hdac_bus *bus)
 {
 	struct drm_audio_component *acomp;
 	int err;
@@ -172,18 +172,10 @@ int snd_hdac_i915_init(struct hdac_bus *bus, bool allow_modprobe)
 	acomp = bus->audio_component;
 	if (!acomp)
 		return -ENODEV;
-	if (allow_modprobe && !acomp->ops) {
-		if (!IS_ENABLED(CONFIG_MODULES) ||
-		    !request_module("i915")) {
-			/* 60s timeout */
-			wait_for_completion_killable_timeout(&acomp->master_bind_complete,
-							     msecs_to_jiffies(60 * 1000));
-		}
-	}
 	if (!acomp->ops) {
-		int err = allow_modprobe ? -ENODEV : -EPROBE_DEFER;
 		snd_hdac_acomp_exit(bus);
-		return dev_err_probe(bus->dev, err, "couldn't bind with audio component\n");
+		return dev_err_probe(bus->dev, -EPROBE_DEFER,
+				     "couldn't bind with audio component\n");
 	}
 	return 0;
 }
sound/pci/hda/hda_intel.c +1 -1
index e3128d7d742e..b4fa925a992b 100644
@@ -2150,7 +2150,7 @@ static int azx_probe(struct pci_dev *pci,
 #ifdef CONFIG_SND_HDA_I915
 	/* bind with i915 if needed */
 	if (chip->driver_caps & AZX_DCAPS_I915_COMPONENT) {
-		err = snd_hdac_i915_init(azx_bus(chip), false);
+		err = snd_hdac_i915_init(azx_bus(chip));
 		if (err < 0) {
 			/* if the controller is bound only with HDMI/DP
 			 * (for HSW and BDW), we need to abort the probe;
sound/soc/intel/avs/core.c +1 -1
index 64e7a4e650a8..d350204a1d86 100644
@@ -461,7 +461,7 @@ static int avs_pci_probe(struct pci_dev *pci, const struct pci_device_id *id)
 	pci_set_drvdata(pci, bus);
 	device_disable_async_suspend(dev);
 
-	ret = snd_hdac_i915_init(bus, false);
+	ret = snd_hdac_i915_init(bus);
 	if (ret == -EPROBE_DEFER)
 		goto err_i915_init;
 	else if (ret < 0)
sound/soc/intel/skylake/skl.c +1 -1
index ff80d83a9fb7..49147ee3a76d 100644
@@ -1056,7 +1056,7 @@ static int skl_probe(struct pci_dev *pci,
 	}
 
 	if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)) {
-		err = snd_hdac_i915_init(bus, false);
+		err = snd_hdac_i915_init(bus);
 		if (err < 0)
 			goto out_dmic_unregister;
 	}
sound/soc/sof/intel/hda-codec.c +1 -1
index 344b61576c0e..8a5e99a898ec 100644
@@ -415,7 +415,7 @@ int hda_codec_i915_init(struct snd_sof_dev *sdev)
 		return 0;
 
 	/* i915 exposes a HDA codec for HDMI audio */
-	ret = snd_hdac_i915_init(bus, false);
+	ret = snd_hdac_i915_init(bus);
 	if (ret < 0)
 		return ret;
 
Signature · 1 line
2.39.2
#23 lore raw

Re: [PATCH v3 9/9] ALSA: hda/i915: Remove extra argument from snd_hdac_i915_init

sound/hda/hdac_i915.c int snd_hdac_i915_init(struct hdac_bus *bus, bool allow_modprobe) · line 180

Quoted 13 lines
sound/hda/hdac_i915.c +0 -6
@@ -172,18 +172,10 @@ int snd_hdac_i915_init(struct hdac_bus *bus, bool allow_modprobe)
 	acomp = bus->audio_component;
 	if (!acomp)
 		return -ENODEV;
-	if (allow_modprobe && !acomp->ops) {
-		if (!IS_ENABLED(CONFIG_MODULES) ||
-		    !request_module("i915")) {
-			/* 60s timeout */
-			wait_for_completion_killable_timeout(&acomp->master_bind_complete,
-							     msecs_to_jiffies(60 * 1000));

heads-up that I have a conflicting patch to make the 60s delay configurable, see https://github.com/thesofproject/linux/pull/4505

Quoted 11 lines
sound/hda/hdac_i915.c +2 -4
-		}
-	}
 	if (!acomp->ops) {
-		int err = allow_modprobe ? -ENODEV : -EPROBE_DEFER;
 		snd_hdac_acomp_exit(bus);
-		return dev_err_probe(bus->dev, err, "couldn't bind with audio component\n");
+		return dev_err_probe(bus->dev, -EPROBE_DEFER,
+				     "couldn't bind with audio component\n");
 	}
 	return 0;
 }