Alsa-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [alsa-devel] [PATCH] ASoC: SOF: Intel: work around snd_hdac_aligned_read link failure
@ 2019-09-09 19:51 Arnd Bergmann
  2019-09-09 20:38 ` Pierre-Louis Bossart
  0 siblings, 1 reply; 6+ messages in thread
From: Arnd Bergmann @ 2019-09-09 19:51 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown
  Cc: alsa-devel, Arnd Bergmann, Pan Xiuli, Pierre-Louis Bossart,
	Evan Green, linux-kernel

When CONFIG_SND_HDA_ALIGNED_MMIO is selected by another driver
(i.e. Tegra) that selects CONFIG_SND_HDA_CORE as a loadable
module, but SND_SOC_SOF_HDA_COMMON is built-in, we get a
link failure from some functions that access the hda register:

sound/soc/sof/intel/hda.o: In function `hda_ipc_irq_dump':
hda.c:(.text+0x784): undefined reference to `snd_hdac_aligned_read'
sound/soc/sof/intel/hda-stream.o: In function `hda_dsp_stream_threaded_handler':
hda-stream.c:(.text+0x12e4): undefined reference to `snd_hdac_aligned_read'
hda-stream.c:(.text+0x12f8): undefined reference to `snd_hdac_aligned_write'

Add an explicit 'select' statement as a workaround. This is
not a great solution, but it's the easiest way I could come
up with.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 sound/soc/sof/intel/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sound/soc/sof/intel/Kconfig b/sound/soc/sof/intel/Kconfig
index 479ba249e219..9180184026e1 100644
--- a/sound/soc/sof/intel/Kconfig
+++ b/sound/soc/sof/intel/Kconfig
@@ -248,6 +248,7 @@ config SND_SOC_SOF_HDA_COMMON
 	tristate
 	select SND_SOC_SOF_INTEL_COMMON
 	select SND_SOC_SOF_HDA_LINK_BASELINE
+	select SND_HDA_CORE if SND_HDA_ALIGNED_MMIO
 	help
 	  This option is not user-selectable but automagically handled by
 	  'select' statements at a higher level
-- 
2.20.0

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

* Re: [alsa-devel] [PATCH] ASoC: SOF: Intel: work around snd_hdac_aligned_read link failure
  2019-09-09 19:51 [alsa-devel] [PATCH] ASoC: SOF: Intel: work around snd_hdac_aligned_read link failure Arnd Bergmann
@ 2019-09-09 20:38 ` Pierre-Louis Bossart
  2019-09-09 20:51   ` Arnd Bergmann
  0 siblings, 1 reply; 6+ messages in thread
From: Pierre-Louis Bossart @ 2019-09-09 20:38 UTC (permalink / raw)
  To: Arnd Bergmann, Liam Girdwood, Mark Brown
  Cc: alsa-devel, Pan Xiuli, linux-kernel, Evan Green

On 9/9/19 2:51 PM, Arnd Bergmann wrote:
> When CONFIG_SND_HDA_ALIGNED_MMIO is selected by another driver
> (i.e. Tegra) that selects CONFIG_SND_HDA_CORE as a loadable
> module, but SND_SOC_SOF_HDA_COMMON is built-in, we get a
> link failure from some functions that access the hda register:
> 
> sound/soc/sof/intel/hda.o: In function `hda_ipc_irq_dump':
> hda.c:(.text+0x784): undefined reference to `snd_hdac_aligned_read'
> sound/soc/sof/intel/hda-stream.o: In function `hda_dsp_stream_threaded_handler':
> hda-stream.c:(.text+0x12e4): undefined reference to `snd_hdac_aligned_read'
> hda-stream.c:(.text+0x12f8): undefined reference to `snd_hdac_aligned_write'
> 
> Add an explicit 'select' statement as a workaround. This is
> not a great solution, but it's the easiest way I could come
> up with.

Thanks for spotting this, I don't think anyone on the SOF team looked at 
this. Maybe we can filter with depends on !TEGRA or 
!SND_HDA_ALIGNED_MMIO at the SOF Intel top-level instead?

If you can share your config off-list I can try to simplify this further.

> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>   sound/soc/sof/intel/Kconfig | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/sound/soc/sof/intel/Kconfig b/sound/soc/sof/intel/Kconfig
> index 479ba249e219..9180184026e1 100644
> --- a/sound/soc/sof/intel/Kconfig
> +++ b/sound/soc/sof/intel/Kconfig
> @@ -248,6 +248,7 @@ config SND_SOC_SOF_HDA_COMMON
>   	tristate
>   	select SND_SOC_SOF_INTEL_COMMON
>   	select SND_SOC_SOF_HDA_LINK_BASELINE
> +	select SND_HDA_CORE if SND_HDA_ALIGNED_MMIO
>   	help
>   	  This option is not user-selectable but automagically handled by
>   	  'select' statements at a higher level
> 

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

* Re: [alsa-devel] [PATCH] ASoC: SOF: Intel: work around snd_hdac_aligned_read link failure
  2019-09-09 20:38 ` Pierre-Louis Bossart
@ 2019-09-09 20:51   ` Arnd Bergmann
  2019-09-10  7:06     ` Takashi Iwai
  0 siblings, 1 reply; 6+ messages in thread
From: Arnd Bergmann @ 2019-09-09 20:51 UTC (permalink / raw)
  To: Pierre-Louis Bossart
  Cc: ALSA Development Mailing List, Pan Xiuli, Liam Girdwood,
	Evan Green, linux-kernel, Mark Brown

On Mon, Sep 9, 2019 at 10:39 PM Pierre-Louis Bossart
<pierre-louis.bossart@linux.intel.com> wrote:
>
> On 9/9/19 2:51 PM, Arnd Bergmann wrote:
> > When CONFIG_SND_HDA_ALIGNED_MMIO is selected by another driver
> > (i.e. Tegra) that selects CONFIG_SND_HDA_CORE as a loadable
> > module, but SND_SOC_SOF_HDA_COMMON is built-in, we get a
> > link failure from some functions that access the hda register:
> >
> > sound/soc/sof/intel/hda.o: In function `hda_ipc_irq_dump':
> > hda.c:(.text+0x784): undefined reference to `snd_hdac_aligned_read'
> > sound/soc/sof/intel/hda-stream.o: In function `hda_dsp_stream_threaded_handler':
> > hda-stream.c:(.text+0x12e4): undefined reference to `snd_hdac_aligned_read'
> > hda-stream.c:(.text+0x12f8): undefined reference to `snd_hdac_aligned_write'
> >
> > Add an explicit 'select' statement as a workaround. This is
> > not a great solution, but it's the easiest way I could come
> > up with.
>
> Thanks for spotting this, I don't think anyone on the SOF team looked at
> this. Maybe we can filter with depends on !TEGRA or
> !SND_HDA_ALIGNED_MMIO at the SOF Intel top-level instead?

That doesn't sound much better than my approach, but could also work.
One idea that I had but did not manage to implement was to move out
the snd_hdac_aligned_read/write functions from the core hda code
into a separate file. I think that would be the cleanest solution,
as it decouples the problem from any drivers.

> If you can share your config off-list I can try to simplify this further.

I uploaded the .config to https://pastebin.com/raw/RMBGXTky
for reference now. This is with the latest linux-next kernel, plus
a series of patches that I keep around for fixing other build
problems.

      Arnd
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

* Re: [alsa-devel] [PATCH] ASoC: SOF: Intel: work around snd_hdac_aligned_read link failure
  2019-09-09 20:51   ` Arnd Bergmann
@ 2019-09-10  7:06     ` Takashi Iwai
  2019-09-10  7:52       ` Arnd Bergmann
  0 siblings, 1 reply; 6+ messages in thread
From: Takashi Iwai @ 2019-09-10  7:06 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: ALSA Development Mailing List, Liam Girdwood, Pan Xiuli,
	linux-kernel, Evan Green, Pierre-Louis Bossart, Mark Brown

On Mon, 09 Sep 2019 22:51:23 +0200,
Arnd Bergmann wrote:
> 
> On Mon, Sep 9, 2019 at 10:39 PM Pierre-Louis Bossart
> <pierre-louis.bossart@linux.intel.com> wrote:
> >
> > On 9/9/19 2:51 PM, Arnd Bergmann wrote:
> > > When CONFIG_SND_HDA_ALIGNED_MMIO is selected by another driver
> > > (i.e. Tegra) that selects CONFIG_SND_HDA_CORE as a loadable
> > > module, but SND_SOC_SOF_HDA_COMMON is built-in, we get a
> > > link failure from some functions that access the hda register:
> > >
> > > sound/soc/sof/intel/hda.o: In function `hda_ipc_irq_dump':
> > > hda.c:(.text+0x784): undefined reference to `snd_hdac_aligned_read'
> > > sound/soc/sof/intel/hda-stream.o: In function `hda_dsp_stream_threaded_handler':
> > > hda-stream.c:(.text+0x12e4): undefined reference to `snd_hdac_aligned_read'
> > > hda-stream.c:(.text+0x12f8): undefined reference to `snd_hdac_aligned_write'
> > >
> > > Add an explicit 'select' statement as a workaround. This is
> > > not a great solution, but it's the easiest way I could come
> > > up with.
> >
> > Thanks for spotting this, I don't think anyone on the SOF team looked at
> > this. Maybe we can filter with depends on !TEGRA or
> > !SND_HDA_ALIGNED_MMIO at the SOF Intel top-level instead?
> 
> That doesn't sound much better than my approach, but could also work.
> One idea that I had but did not manage to implement was to move out
> the snd_hdac_aligned_read/write functions from the core hda code
> into a separate file. I think that would be the cleanest solution,
> as it decouples the problem from any drivers.

Yeah, that's a tricky problem because of the reverse-selection, as
usual...

Another solution would be to just avoid byte/word access but use only
long access, i.e. replace snd_hdac_chip_readb() with
snd_hdac_chip_readl() with the aligned register and bit shift.
The aligned access helper is needed only for the register that isn't
aligned with 4 bytes offset.

And, one remaining question is whether it makes sense to enable
CONFIG_SND_SOC_SOF_HDA without CONFIG_SND_HDA_EXT_CORE (that selects
CONFIG_SND_HDA_CORE, too).  Currently it seems conditionally selected,
but many codes do depend on snd_hdac_ext_*() and other helper code
with CONFIG_SND_SOC_SOF_HDA-ifdef.


thanks,

Takashi
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

* Re: [alsa-devel] [PATCH] ASoC: SOF: Intel: work around snd_hdac_aligned_read link failure
  2019-09-10  7:06     ` Takashi Iwai
@ 2019-09-10  7:52       ` Arnd Bergmann
  2019-09-10  8:20         ` Takashi Iwai
  0 siblings, 1 reply; 6+ messages in thread
From: Arnd Bergmann @ 2019-09-10  7:52 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: ALSA Development Mailing List, Liam Girdwood, Pan Xiuli,
	linux-kernel, Evan Green, Pierre-Louis Bossart, Mark Brown

On Tue, Sep 10, 2019 at 9:06 AM Takashi Iwai <tiwai@suse.de> wrote:
> On Mon, 09 Sep 2019 22:51:23 +0200, Arnd Bergmann wrote:
> >
> > On Mon, Sep 9, 2019 at 10:39 PM Pierre-Louis Bossart
> > <pierre-louis.bossart@linux.intel.com> wrote:
> > >
> > > On 9/9/19 2:51 PM, Arnd Bergmann wrote:
> > > > When CONFIG_SND_HDA_ALIGNED_MMIO is selected by another driver
> > > > (i.e. Tegra) that selects CONFIG_SND_HDA_CORE as a loadable
> > > > module, but SND_SOC_SOF_HDA_COMMON is built-in, we get a
> > > > link failure from some functions that access the hda register:
> > > >
> > > > sound/soc/sof/intel/hda.o: In function `hda_ipc_irq_dump':
> > > > hda.c:(.text+0x784): undefined reference to `snd_hdac_aligned_read'
> > > > sound/soc/sof/intel/hda-stream.o: In function `hda_dsp_stream_threaded_handler':
> > > > hda-stream.c:(.text+0x12e4): undefined reference to `snd_hdac_aligned_read'
> > > > hda-stream.c:(.text+0x12f8): undefined reference to `snd_hdac_aligned_write'
> > > >
> > > > Add an explicit 'select' statement as a workaround. This is
> > > > not a great solution, but it's the easiest way I could come
> > > > up with.
> > >
> > > Thanks for spotting this, I don't think anyone on the SOF team looked at
> > > this. Maybe we can filter with depends on !TEGRA or
> > > !SND_HDA_ALIGNED_MMIO at the SOF Intel top-level instead?
> >
> > That doesn't sound much better than my approach, but could also work.
> > One idea that I had but did not manage to implement was to move out
> > the snd_hdac_aligned_read/write functions from the core hda code
> > into a separate file. I think that would be the cleanest solution,
> > as it decouples the problem from any drivers.
>
> Yeah, that's a tricky problem because of the reverse-selection, as
> usual...
>
> Another solution would be to just avoid byte/word access but use only
> long access, i.e. replace snd_hdac_chip_readb() with
> snd_hdac_chip_readl() with the aligned register and bit shift.
> The aligned access helper is needed only for the register that isn't
> aligned with 4 bytes offset.

Ok, so basically open-coding the aligned access to RIRBSTS?
That sounds like a much nicer workaround. So in place of

                        sd_status = snd_hdac_stream_readb(s, SD_STS);
                        dev_vdbg(bus->dev, "stream %d status 0x%x\n",
                                 s->index, sd_status);
                        snd_hdac_stream_writeb(s, SD_STS, sd_status);

I suppose one could just readl/writel SOF_HDA_ADSP_REG_CL_SD_CTL
and print the shifted value, right?

While I know nothing about the underlying requirements, I wonder
about two things that stick out to me:

1. the existing code just writes back the same byte it has read. If
    this write has no side-effects, why write it at all? OTOH, if it has
    side-effects, isn't the aligned implementation of writing the whole
    word in snd_hdac_aligned_write()  fundamentally flawed?

2. Doesn't the read-modify-write cycle in snd_hdac_aligned_write()
   need locking to work correctly?

          Arnd
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

* Re: [alsa-devel] [PATCH] ASoC: SOF: Intel: work around snd_hdac_aligned_read link failure
  2019-09-10  7:52       ` Arnd Bergmann
@ 2019-09-10  8:20         ` Takashi Iwai
  0 siblings, 0 replies; 6+ messages in thread
From: Takashi Iwai @ 2019-09-10  8:20 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: ALSA Development Mailing List, Liam Girdwood, Pan Xiuli,
	linux-kernel, Evan Green, Pierre-Louis Bossart, Mark Brown

On Tue, 10 Sep 2019 09:52:13 +0200,
Arnd Bergmann wrote:
> 
> On Tue, Sep 10, 2019 at 9:06 AM Takashi Iwai <tiwai@suse.de> wrote:
> > On Mon, 09 Sep 2019 22:51:23 +0200, Arnd Bergmann wrote:
> > >
> > > On Mon, Sep 9, 2019 at 10:39 PM Pierre-Louis Bossart
> > > <pierre-louis.bossart@linux.intel.com> wrote:
> > > >
> > > > On 9/9/19 2:51 PM, Arnd Bergmann wrote:
> > > > > When CONFIG_SND_HDA_ALIGNED_MMIO is selected by another driver
> > > > > (i.e. Tegra) that selects CONFIG_SND_HDA_CORE as a loadable
> > > > > module, but SND_SOC_SOF_HDA_COMMON is built-in, we get a
> > > > > link failure from some functions that access the hda register:
> > > > >
> > > > > sound/soc/sof/intel/hda.o: In function `hda_ipc_irq_dump':
> > > > > hda.c:(.text+0x784): undefined reference to `snd_hdac_aligned_read'
> > > > > sound/soc/sof/intel/hda-stream.o: In function `hda_dsp_stream_threaded_handler':
> > > > > hda-stream.c:(.text+0x12e4): undefined reference to `snd_hdac_aligned_read'
> > > > > hda-stream.c:(.text+0x12f8): undefined reference to `snd_hdac_aligned_write'
> > > > >
> > > > > Add an explicit 'select' statement as a workaround. This is
> > > > > not a great solution, but it's the easiest way I could come
> > > > > up with.
> > > >
> > > > Thanks for spotting this, I don't think anyone on the SOF team looked at
> > > > this. Maybe we can filter with depends on !TEGRA or
> > > > !SND_HDA_ALIGNED_MMIO at the SOF Intel top-level instead?
> > >
> > > That doesn't sound much better than my approach, but could also work.
> > > One idea that I had but did not manage to implement was to move out
> > > the snd_hdac_aligned_read/write functions from the core hda code
> > > into a separate file. I think that would be the cleanest solution,
> > > as it decouples the problem from any drivers.
> >
> > Yeah, that's a tricky problem because of the reverse-selection, as
> > usual...
> >
> > Another solution would be to just avoid byte/word access but use only
> > long access, i.e. replace snd_hdac_chip_readb() with
> > snd_hdac_chip_readl() with the aligned register and bit shift.
> > The aligned access helper is needed only for the register that isn't
> > aligned with 4 bytes offset.
> 
> Ok, so basically open-coding the aligned access to RIRBSTS?
> That sounds like a much nicer workaround. So in place of
> 
>                         sd_status = snd_hdac_stream_readb(s, SD_STS);
>                         dev_vdbg(bus->dev, "stream %d status 0x%x\n",
>                                  s->index, sd_status);
>                         snd_hdac_stream_writeb(s, SD_STS, sd_status);
> 
> I suppose one could just readl/writel SOF_HDA_ADSP_REG_CL_SD_CTL
> and print the shifted value, right?

Yes.

> While I know nothing about the underlying requirements, I wonder
> about two things that stick out to me:
> 
> 1. the existing code just writes back the same byte it has read. If
>     this write has no side-effects, why write it at all? OTOH, if it has
>     side-effects, isn't the aligned implementation of writing the whole
>     word in snd_hdac_aligned_write()  fundamentally flawed?

The aligned read/write does already the whole 4-bytes read/write, so
it should work.  But we need confirmation with the actual hardware.

> 2. Doesn't the read-modify-write cycle in snd_hdac_aligned_write()
>    need locking to work correctly?

The helper doesn't guarantee the atomic write by itself, so a lock
would be required in the caller side if needed.  Luckily there aren't
many places calling the unaligned access.


thanks,

Takashi
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-09 19:51 [alsa-devel] [PATCH] ASoC: SOF: Intel: work around snd_hdac_aligned_read link failure Arnd Bergmann
2019-09-09 20:38 ` Pierre-Louis Bossart
2019-09-09 20:51   ` Arnd Bergmann
2019-09-10  7:06     ` Takashi Iwai
2019-09-10  7:52       ` Arnd Bergmann
2019-09-10  8:20         ` Takashi Iwai

Alsa-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/alsa-devel/0 alsa-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 alsa-devel alsa-devel/ https://lore.kernel.org/alsa-devel \
		alsa-devel@alsa-project.org alsa-devel@archiver.kernel.org
	public-inbox-index alsa-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.alsa-project.alsa-devel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox