* [PATCH] ASoC: mediatek: re-enable buffer pre-allocation on some platforms
@ 2025-04-01 8:56 Chen-Yu Tsai
2025-04-01 10:12 ` AngeloGioacchino Del Regno
0 siblings, 1 reply; 5+ messages in thread
From: Chen-Yu Tsai @ 2025-04-01 8:56 UTC (permalink / raw)
To: Mark Brown, Jaroslav Kysela, Takashi Iwai, Matthias Brugger,
AngeloGioacchino Del Regno
Cc: Chen-Yu Tsai, linux-sound, linux-mediatek, linux-arm-kernel,
linux-kernel, treapking, yuanhsinte
In commit 32c9c06adb5b ("ASoC: mediatek: disable buffer pre-allocation")
buffer pre-allocation was disabled to accommodate newer platforms that
have a limited reserved memory region for the audio frontend.
Turns out disabling pre-allocation across the board impacts platforms
that don't have this reserved memory region. Buffer allocation failures
have been observed on MT8173 and MT8183 based Chromebooks under low
memory conditions, which results in no audio playback for the user.
Reinstate the original policy of pre-allocating audio buffers at probe
time on MT8173, MT8183, and MT8186 platforms. These platforms do not
have reserved memory for the audio frontend.
Fixes: 32c9c06adb5b ("ASoC: mediatek: disable buffer pre-allocation")
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
sound/soc/mediatek/common/mtk-afe-platform-driver.c | 4 +++-
sound/soc/mediatek/common/mtk-base-afe.h | 1 +
sound/soc/mediatek/mt8173/mt8173-afe-pcm.c | 1 +
sound/soc/mediatek/mt8183/mt8183-afe-pcm.c | 1 +
sound/soc/mediatek/mt8186/mt8186-afe-pcm.c | 1 +
5 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/sound/soc/mediatek/common/mtk-afe-platform-driver.c b/sound/soc/mediatek/common/mtk-afe-platform-driver.c
index 6b6330583941..70fd05d5ff48 100644
--- a/sound/soc/mediatek/common/mtk-afe-platform-driver.c
+++ b/sound/soc/mediatek/common/mtk-afe-platform-driver.c
@@ -120,7 +120,9 @@ int mtk_afe_pcm_new(struct snd_soc_component *component,
struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
size = afe->mtk_afe_hardware->buffer_bytes_max;
- snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, afe->dev, 0, size);
+ snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, afe->dev,
+ afe->preallocate_buffers ? size : 0,
+ size);
return 0;
}
diff --git a/sound/soc/mediatek/common/mtk-base-afe.h b/sound/soc/mediatek/common/mtk-base-afe.h
index f51578b6c50a..a406f2e3e7a8 100644
--- a/sound/soc/mediatek/common/mtk-base-afe.h
+++ b/sound/soc/mediatek/common/mtk-base-afe.h
@@ -117,6 +117,7 @@ struct mtk_base_afe {
struct mtk_base_afe_irq *irqs;
int irqs_size;
int memif_32bit_supported;
+ bool preallocate_buffers;
struct list_head sub_dais;
struct snd_soc_dai_driver *dai_drivers;
diff --git a/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c b/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c
index 04ed0cfec174..37b20ec80829 100644
--- a/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c
+++ b/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c
@@ -1114,6 +1114,7 @@ static int mt8173_afe_pcm_dev_probe(struct platform_device *pdev)
afe->mtk_afe_hardware = &mt8173_afe_hardware;
afe->memif_fs = mt8173_memif_fs;
afe->irq_fs = mt8173_irq_fs;
+ afe->preallocate_buffers = true;
platform_set_drvdata(pdev, afe);
diff --git a/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c b/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c
index d083b4bf0f95..0ef07fb2898d 100644
--- a/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c
+++ b/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c
@@ -1214,6 +1214,7 @@ static int mt8183_afe_pcm_dev_probe(struct platform_device *pdev)
afe->mtk_afe_hardware = &mt8183_afe_hardware;
afe->memif_fs = mt8183_memif_fs;
afe->irq_fs = mt8183_irq_fs;
+ afe->preallocate_buffers = true;
afe->runtime_resume = mt8183_afe_runtime_resume;
afe->runtime_suspend = mt8183_afe_runtime_suspend;
diff --git a/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c b/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
index db7c93401bee..c588a68d672d 100644
--- a/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
+++ b/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
@@ -2935,6 +2935,7 @@ static int mt8186_afe_pcm_dev_probe(struct platform_device *pdev)
afe->irq_fs = mt8186_irq_fs;
afe->get_dai_fs = mt8186_get_dai_fs;
afe->get_memif_pbuf_size = mt8186_get_memif_pbuf_size;
+ afe->preallocate_buffers = true;
afe->runtime_resume = mt8186_afe_runtime_resume;
afe->runtime_suspend = mt8186_afe_runtime_suspend;
--
2.49.0.472.ge94155a9ec-goog
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] ASoC: mediatek: re-enable buffer pre-allocation on some platforms
2025-04-01 8:56 [PATCH] ASoC: mediatek: re-enable buffer pre-allocation on some platforms Chen-Yu Tsai
@ 2025-04-01 10:12 ` AngeloGioacchino Del Regno
2025-04-01 10:38 ` Chen-Yu Tsai
0 siblings, 1 reply; 5+ messages in thread
From: AngeloGioacchino Del Regno @ 2025-04-01 10:12 UTC (permalink / raw)
To: Chen-Yu Tsai, Mark Brown, Jaroslav Kysela, Takashi Iwai,
Matthias Brugger
Cc: linux-sound, linux-mediatek, linux-arm-kernel, linux-kernel,
treapking, yuanhsinte
Il 01/04/25 10:56, Chen-Yu Tsai ha scritto:
> In commit 32c9c06adb5b ("ASoC: mediatek: disable buffer pre-allocation")
> buffer pre-allocation was disabled to accommodate newer platforms that
> have a limited reserved memory region for the audio frontend.
>
> Turns out disabling pre-allocation across the board impacts platforms
> that don't have this reserved memory region. Buffer allocation failures
> have been observed on MT8173 and MT8183 based Chromebooks under low
> memory conditions, which results in no audio playback for the user.
>
> Reinstate the original policy of pre-allocating audio buffers at probe
> time on MT8173, MT8183, and MT8186 platforms. These platforms do not
> have reserved memory for the audio frontend.
>
> Fixes: 32c9c06adb5b ("ASoC: mediatek: disable buffer pre-allocation")
> Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
Have you tried to add the reserved memory regions to the MT8173/83/86 AFE?
This means not only devicetree but also the driver - that should be simple
enough, and would allow to eventually add a layer of further commonization
between the AFE PCM drivers of all those MediaTek SoCs.
Cheers,
Angelo
> ---
> sound/soc/mediatek/common/mtk-afe-platform-driver.c | 4 +++-
> sound/soc/mediatek/common/mtk-base-afe.h | 1 +
> sound/soc/mediatek/mt8173/mt8173-afe-pcm.c | 1 +
> sound/soc/mediatek/mt8183/mt8183-afe-pcm.c | 1 +
> sound/soc/mediatek/mt8186/mt8186-afe-pcm.c | 1 +
> 5 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/sound/soc/mediatek/common/mtk-afe-platform-driver.c b/sound/soc/mediatek/common/mtk-afe-platform-driver.c
> index 6b6330583941..70fd05d5ff48 100644
> --- a/sound/soc/mediatek/common/mtk-afe-platform-driver.c
> +++ b/sound/soc/mediatek/common/mtk-afe-platform-driver.c
> @@ -120,7 +120,9 @@ int mtk_afe_pcm_new(struct snd_soc_component *component,
> struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
>
> size = afe->mtk_afe_hardware->buffer_bytes_max;
> - snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, afe->dev, 0, size);
> + snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, afe->dev,
> + afe->preallocate_buffers ? size : 0,
> + size);
>
> return 0;
> }
> diff --git a/sound/soc/mediatek/common/mtk-base-afe.h b/sound/soc/mediatek/common/mtk-base-afe.h
> index f51578b6c50a..a406f2e3e7a8 100644
> --- a/sound/soc/mediatek/common/mtk-base-afe.h
> +++ b/sound/soc/mediatek/common/mtk-base-afe.h
> @@ -117,6 +117,7 @@ struct mtk_base_afe {
> struct mtk_base_afe_irq *irqs;
> int irqs_size;
> int memif_32bit_supported;
> + bool preallocate_buffers;
>
> struct list_head sub_dais;
> struct snd_soc_dai_driver *dai_drivers;
> diff --git a/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c b/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c
> index 04ed0cfec174..37b20ec80829 100644
> --- a/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c
> +++ b/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c
> @@ -1114,6 +1114,7 @@ static int mt8173_afe_pcm_dev_probe(struct platform_device *pdev)
> afe->mtk_afe_hardware = &mt8173_afe_hardware;
> afe->memif_fs = mt8173_memif_fs;
> afe->irq_fs = mt8173_irq_fs;
> + afe->preallocate_buffers = true;
>
> platform_set_drvdata(pdev, afe);
>
> diff --git a/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c b/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c
> index d083b4bf0f95..0ef07fb2898d 100644
> --- a/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c
> +++ b/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c
> @@ -1214,6 +1214,7 @@ static int mt8183_afe_pcm_dev_probe(struct platform_device *pdev)
> afe->mtk_afe_hardware = &mt8183_afe_hardware;
> afe->memif_fs = mt8183_memif_fs;
> afe->irq_fs = mt8183_irq_fs;
> + afe->preallocate_buffers = true;
>
> afe->runtime_resume = mt8183_afe_runtime_resume;
> afe->runtime_suspend = mt8183_afe_runtime_suspend;
> diff --git a/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c b/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
> index db7c93401bee..c588a68d672d 100644
> --- a/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
> +++ b/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
> @@ -2935,6 +2935,7 @@ static int mt8186_afe_pcm_dev_probe(struct platform_device *pdev)
> afe->irq_fs = mt8186_irq_fs;
> afe->get_dai_fs = mt8186_get_dai_fs;
> afe->get_memif_pbuf_size = mt8186_get_memif_pbuf_size;
> + afe->preallocate_buffers = true;
>
> afe->runtime_resume = mt8186_afe_runtime_resume;
> afe->runtime_suspend = mt8186_afe_runtime_suspend;
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] ASoC: mediatek: re-enable buffer pre-allocation on some platforms
2025-04-01 10:12 ` AngeloGioacchino Del Regno
@ 2025-04-01 10:38 ` Chen-Yu Tsai
2025-04-01 10:39 ` Chen-Yu Tsai
2025-04-01 10:45 ` AngeloGioacchino Del Regno
0 siblings, 2 replies; 5+ messages in thread
From: Chen-Yu Tsai @ 2025-04-01 10:38 UTC (permalink / raw)
To: AngeloGioacchino Del Regno
Cc: Mark Brown, Jaroslav Kysela, Takashi Iwai, Matthias Brugger,
linux-sound, linux-mediatek, linux-arm-kernel, linux-kernel,
treapking, yuanhsinte
On Tue, Apr 1, 2025 at 6:12 PM AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com> wrote:
>
> Il 01/04/25 10:56, Chen-Yu Tsai ha scritto:
> > In commit 32c9c06adb5b ("ASoC: mediatek: disable buffer pre-allocation")
> > buffer pre-allocation was disabled to accommodate newer platforms that
> > have a limited reserved memory region for the audio frontend.
> >
> > Turns out disabling pre-allocation across the board impacts platforms
> > that don't have this reserved memory region. Buffer allocation failures
> > have been observed on MT8173 and MT8183 based Chromebooks under low
> > memory conditions, which results in no audio playback for the user.
> >
> > Reinstate the original policy of pre-allocating audio buffers at probe
> > time on MT8173, MT8183, and MT8186 platforms. These platforms do not
> > have reserved memory for the audio frontend.
> >
> > Fixes: 32c9c06adb5b ("ASoC: mediatek: disable buffer pre-allocation")
> > Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
>
> Have you tried to add the reserved memory regions to the MT8173/83/86 AFE?
I haven't tried it, though I'm fairly certain that would work as well.
> This means not only devicetree but also the driver - that should be simple
> enough, and would allow to eventually add a layer of further commonization
> between the AFE PCM drivers of all those MediaTek SoCs.
I think no driver changes are necessary? It's a single memory region,
so it would automatically be picked by the driver core for all coherent
DMA allocations.
I picked the driver route because it restores old behavior.
ChenYu
> Cheers,
> Angelo
>
> > ---
> > sound/soc/mediatek/common/mtk-afe-platform-driver.c | 4 +++-
> > sound/soc/mediatek/common/mtk-base-afe.h | 1 +
> > sound/soc/mediatek/mt8173/mt8173-afe-pcm.c | 1 +
> > sound/soc/mediatek/mt8183/mt8183-afe-pcm.c | 1 +
> > sound/soc/mediatek/mt8186/mt8186-afe-pcm.c | 1 +
> > 5 files changed, 7 insertions(+), 1 deletion(-)
> >
> > diff --git a/sound/soc/mediatek/common/mtk-afe-platform-driver.c b/sound/soc/mediatek/common/mtk-afe-platform-driver.c
> > index 6b6330583941..70fd05d5ff48 100644
> > --- a/sound/soc/mediatek/common/mtk-afe-platform-driver.c
> > +++ b/sound/soc/mediatek/common/mtk-afe-platform-driver.c
> > @@ -120,7 +120,9 @@ int mtk_afe_pcm_new(struct snd_soc_component *component,
> > struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
> >
> > size = afe->mtk_afe_hardware->buffer_bytes_max;
> > - snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, afe->dev, 0, size);
> > + snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, afe->dev,
> > + afe->preallocate_buffers ? size : 0,
> > + size);
> >
> > return 0;
> > }
> > diff --git a/sound/soc/mediatek/common/mtk-base-afe.h b/sound/soc/mediatek/common/mtk-base-afe.h
> > index f51578b6c50a..a406f2e3e7a8 100644
> > --- a/sound/soc/mediatek/common/mtk-base-afe.h
> > +++ b/sound/soc/mediatek/common/mtk-base-afe.h
> > @@ -117,6 +117,7 @@ struct mtk_base_afe {
> > struct mtk_base_afe_irq *irqs;
> > int irqs_size;
> > int memif_32bit_supported;
> > + bool preallocate_buffers;
> >
> > struct list_head sub_dais;
> > struct snd_soc_dai_driver *dai_drivers;
> > diff --git a/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c b/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c
> > index 04ed0cfec174..37b20ec80829 100644
> > --- a/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c
> > +++ b/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c
> > @@ -1114,6 +1114,7 @@ static int mt8173_afe_pcm_dev_probe(struct platform_device *pdev)
> > afe->mtk_afe_hardware = &mt8173_afe_hardware;
> > afe->memif_fs = mt8173_memif_fs;
> > afe->irq_fs = mt8173_irq_fs;
> > + afe->preallocate_buffers = true;
> >
> > platform_set_drvdata(pdev, afe);
> >
> > diff --git a/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c b/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c
> > index d083b4bf0f95..0ef07fb2898d 100644
> > --- a/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c
> > +++ b/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c
> > @@ -1214,6 +1214,7 @@ static int mt8183_afe_pcm_dev_probe(struct platform_device *pdev)
> > afe->mtk_afe_hardware = &mt8183_afe_hardware;
> > afe->memif_fs = mt8183_memif_fs;
> > afe->irq_fs = mt8183_irq_fs;
> > + afe->preallocate_buffers = true;
> >
> > afe->runtime_resume = mt8183_afe_runtime_resume;
> > afe->runtime_suspend = mt8183_afe_runtime_suspend;
> > diff --git a/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c b/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
> > index db7c93401bee..c588a68d672d 100644
> > --- a/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
> > +++ b/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
> > @@ -2935,6 +2935,7 @@ static int mt8186_afe_pcm_dev_probe(struct platform_device *pdev)
> > afe->irq_fs = mt8186_irq_fs;
> > afe->get_dai_fs = mt8186_get_dai_fs;
> > afe->get_memif_pbuf_size = mt8186_get_memif_pbuf_size;
> > + afe->preallocate_buffers = true;
> >
> > afe->runtime_resume = mt8186_afe_runtime_resume;
> > afe->runtime_suspend = mt8186_afe_runtime_suspend;
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] ASoC: mediatek: re-enable buffer pre-allocation on some platforms
2025-04-01 10:38 ` Chen-Yu Tsai
@ 2025-04-01 10:39 ` Chen-Yu Tsai
2025-04-01 10:45 ` AngeloGioacchino Del Regno
1 sibling, 0 replies; 5+ messages in thread
From: Chen-Yu Tsai @ 2025-04-01 10:39 UTC (permalink / raw)
To: AngeloGioacchino Del Regno
Cc: Mark Brown, Jaroslav Kysela, Takashi Iwai, Matthias Brugger,
linux-sound, linux-mediatek, linux-arm-kernel, linux-kernel,
treapking, yuanhsinte
On Tue, Apr 1, 2025 at 6:38 PM Chen-Yu Tsai <wenst@chromium.org> wrote:
>
> On Tue, Apr 1, 2025 at 6:12 PM AngeloGioacchino Del Regno
> <angelogioacchino.delregno@collabora.com> wrote:
> >
> > Il 01/04/25 10:56, Chen-Yu Tsai ha scritto:
> > > In commit 32c9c06adb5b ("ASoC: mediatek: disable buffer pre-allocation")
> > > buffer pre-allocation was disabled to accommodate newer platforms that
> > > have a limited reserved memory region for the audio frontend.
> > >
> > > Turns out disabling pre-allocation across the board impacts platforms
> > > that don't have this reserved memory region. Buffer allocation failures
> > > have been observed on MT8173 and MT8183 based Chromebooks under low
> > > memory conditions, which results in no audio playback for the user.
> > >
> > > Reinstate the original policy of pre-allocating audio buffers at probe
> > > time on MT8173, MT8183, and MT8186 platforms. These platforms do not
> > > have reserved memory for the audio frontend.
> > >
> > > Fixes: 32c9c06adb5b ("ASoC: mediatek: disable buffer pre-allocation")
> > > Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
> >
> > Have you tried to add the reserved memory regions to the MT8173/83/86 AFE?
>
> I haven't tried it, though I'm fairly certain that would work as well.
>
> > This means not only devicetree but also the driver - that should be simple
> > enough, and would allow to eventually add a layer of further commonization
> > between the AFE PCM drivers of all those MediaTek SoCs.
>
> I think no driver changes are necessary? It's a single memory region,
> so it would automatically be picked by the driver core for all coherent
> DMA allocations.
>
> I picked the driver route because it restores old behavior.
Also because one setting policy in the device tree, while the other
is in the implementation.
>
> ChenYu
>
> > Cheers,
> > Angelo
> >
> > > ---
> > > sound/soc/mediatek/common/mtk-afe-platform-driver.c | 4 +++-
> > > sound/soc/mediatek/common/mtk-base-afe.h | 1 +
> > > sound/soc/mediatek/mt8173/mt8173-afe-pcm.c | 1 +
> > > sound/soc/mediatek/mt8183/mt8183-afe-pcm.c | 1 +
> > > sound/soc/mediatek/mt8186/mt8186-afe-pcm.c | 1 +
> > > 5 files changed, 7 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/sound/soc/mediatek/common/mtk-afe-platform-driver.c b/sound/soc/mediatek/common/mtk-afe-platform-driver.c
> > > index 6b6330583941..70fd05d5ff48 100644
> > > --- a/sound/soc/mediatek/common/mtk-afe-platform-driver.c
> > > +++ b/sound/soc/mediatek/common/mtk-afe-platform-driver.c
> > > @@ -120,7 +120,9 @@ int mtk_afe_pcm_new(struct snd_soc_component *component,
> > > struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
> > >
> > > size = afe->mtk_afe_hardware->buffer_bytes_max;
> > > - snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, afe->dev, 0, size);
> > > + snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, afe->dev,
> > > + afe->preallocate_buffers ? size : 0,
> > > + size);
> > >
> > > return 0;
> > > }
> > > diff --git a/sound/soc/mediatek/common/mtk-base-afe.h b/sound/soc/mediatek/common/mtk-base-afe.h
> > > index f51578b6c50a..a406f2e3e7a8 100644
> > > --- a/sound/soc/mediatek/common/mtk-base-afe.h
> > > +++ b/sound/soc/mediatek/common/mtk-base-afe.h
> > > @@ -117,6 +117,7 @@ struct mtk_base_afe {
> > > struct mtk_base_afe_irq *irqs;
> > > int irqs_size;
> > > int memif_32bit_supported;
> > > + bool preallocate_buffers;
> > >
> > > struct list_head sub_dais;
> > > struct snd_soc_dai_driver *dai_drivers;
> > > diff --git a/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c b/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c
> > > index 04ed0cfec174..37b20ec80829 100644
> > > --- a/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c
> > > +++ b/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c
> > > @@ -1114,6 +1114,7 @@ static int mt8173_afe_pcm_dev_probe(struct platform_device *pdev)
> > > afe->mtk_afe_hardware = &mt8173_afe_hardware;
> > > afe->memif_fs = mt8173_memif_fs;
> > > afe->irq_fs = mt8173_irq_fs;
> > > + afe->preallocate_buffers = true;
> > >
> > > platform_set_drvdata(pdev, afe);
> > >
> > > diff --git a/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c b/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c
> > > index d083b4bf0f95..0ef07fb2898d 100644
> > > --- a/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c
> > > +++ b/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c
> > > @@ -1214,6 +1214,7 @@ static int mt8183_afe_pcm_dev_probe(struct platform_device *pdev)
> > > afe->mtk_afe_hardware = &mt8183_afe_hardware;
> > > afe->memif_fs = mt8183_memif_fs;
> > > afe->irq_fs = mt8183_irq_fs;
> > > + afe->preallocate_buffers = true;
> > >
> > > afe->runtime_resume = mt8183_afe_runtime_resume;
> > > afe->runtime_suspend = mt8183_afe_runtime_suspend;
> > > diff --git a/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c b/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
> > > index db7c93401bee..c588a68d672d 100644
> > > --- a/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
> > > +++ b/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
> > > @@ -2935,6 +2935,7 @@ static int mt8186_afe_pcm_dev_probe(struct platform_device *pdev)
> > > afe->irq_fs = mt8186_irq_fs;
> > > afe->get_dai_fs = mt8186_get_dai_fs;
> > > afe->get_memif_pbuf_size = mt8186_get_memif_pbuf_size;
> > > + afe->preallocate_buffers = true;
> > >
> > > afe->runtime_resume = mt8186_afe_runtime_resume;
> > > afe->runtime_suspend = mt8186_afe_runtime_suspend;
> >
> >
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] ASoC: mediatek: re-enable buffer pre-allocation on some platforms
2025-04-01 10:38 ` Chen-Yu Tsai
2025-04-01 10:39 ` Chen-Yu Tsai
@ 2025-04-01 10:45 ` AngeloGioacchino Del Regno
1 sibling, 0 replies; 5+ messages in thread
From: AngeloGioacchino Del Regno @ 2025-04-01 10:45 UTC (permalink / raw)
To: Chen-Yu Tsai
Cc: Mark Brown, Jaroslav Kysela, Takashi Iwai, Matthias Brugger,
linux-sound, linux-mediatek, linux-arm-kernel, linux-kernel,
treapking, yuanhsinte
Il 01/04/25 12:38, Chen-Yu Tsai ha scritto:
> On Tue, Apr 1, 2025 at 6:12 PM AngeloGioacchino Del Regno
> <angelogioacchino.delregno@collabora.com> wrote:
>>
>> Il 01/04/25 10:56, Chen-Yu Tsai ha scritto:
>>> In commit 32c9c06adb5b ("ASoC: mediatek: disable buffer pre-allocation")
>>> buffer pre-allocation was disabled to accommodate newer platforms that
>>> have a limited reserved memory region for the audio frontend.
>>>
>>> Turns out disabling pre-allocation across the board impacts platforms
>>> that don't have this reserved memory region. Buffer allocation failures
>>> have been observed on MT8173 and MT8183 based Chromebooks under low
>>> memory conditions, which results in no audio playback for the user.
>>>
>>> Reinstate the original policy of pre-allocating audio buffers at probe
>>> time on MT8173, MT8183, and MT8186 platforms. These platforms do not
>>> have reserved memory for the audio frontend.
>>>
>>> Fixes: 32c9c06adb5b ("ASoC: mediatek: disable buffer pre-allocation")
>>> Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
>>
>> Have you tried to add the reserved memory regions to the MT8173/83/86 AFE?
>
> I haven't tried it, though I'm fairly certain that would work as well.
>
>> This means not only devicetree but also the driver - that should be simple
>> enough, and would allow to eventually add a layer of further commonization
>> between the AFE PCM drivers of all those MediaTek SoCs.
>
> I think no driver changes are necessary? It's a single memory region,
> so it would automatically be picked by the driver core for all coherent
> DMA allocations.
>
> I picked the driver route because it restores old behavior.
That makes sense, yes, but I'd still like to get them all behaving the same
instead of having some doing this, and some others doing that - especially
because we can...
So while I agree on that we should have this fix, I'd really like to see it
done properly, so that if there is no reserved memory assigned in devicetree
the probe function sets preallocate_buffers = true.
That's why I said driver changes... (and sorry I've been a bit cryptic!)
Hint: If of_reserved_mem_device_init() fails, no memory region was assigned!
Angelo
>
>
> ChenYu
>
>> Cheers,
>> Angelo
>>
>>> ---
>>> sound/soc/mediatek/common/mtk-afe-platform-driver.c | 4 +++-
>>> sound/soc/mediatek/common/mtk-base-afe.h | 1 +
>>> sound/soc/mediatek/mt8173/mt8173-afe-pcm.c | 1 +
>>> sound/soc/mediatek/mt8183/mt8183-afe-pcm.c | 1 +
>>> sound/soc/mediatek/mt8186/mt8186-afe-pcm.c | 1 +
>>> 5 files changed, 7 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/sound/soc/mediatek/common/mtk-afe-platform-driver.c b/sound/soc/mediatek/common/mtk-afe-platform-driver.c
>>> index 6b6330583941..70fd05d5ff48 100644
>>> --- a/sound/soc/mediatek/common/mtk-afe-platform-driver.c
>>> +++ b/sound/soc/mediatek/common/mtk-afe-platform-driver.c
>>> @@ -120,7 +120,9 @@ int mtk_afe_pcm_new(struct snd_soc_component *component,
>>> struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
>>>
>>> size = afe->mtk_afe_hardware->buffer_bytes_max;
>>> - snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, afe->dev, 0, size);
>>> + snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, afe->dev,
>>> + afe->preallocate_buffers ? size : 0,
>>> + size);
>>>
>>> return 0;
>>> }
>>> diff --git a/sound/soc/mediatek/common/mtk-base-afe.h b/sound/soc/mediatek/common/mtk-base-afe.h
>>> index f51578b6c50a..a406f2e3e7a8 100644
>>> --- a/sound/soc/mediatek/common/mtk-base-afe.h
>>> +++ b/sound/soc/mediatek/common/mtk-base-afe.h
>>> @@ -117,6 +117,7 @@ struct mtk_base_afe {
>>> struct mtk_base_afe_irq *irqs;
>>> int irqs_size;
>>> int memif_32bit_supported;
>>> + bool preallocate_buffers;
>>>
>>> struct list_head sub_dais;
>>> struct snd_soc_dai_driver *dai_drivers;
>>> diff --git a/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c b/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c
>>> index 04ed0cfec174..37b20ec80829 100644
>>> --- a/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c
>>> +++ b/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c
>>> @@ -1114,6 +1114,7 @@ static int mt8173_afe_pcm_dev_probe(struct platform_device *pdev)
>>> afe->mtk_afe_hardware = &mt8173_afe_hardware;
>>> afe->memif_fs = mt8173_memif_fs;
>>> afe->irq_fs = mt8173_irq_fs;
>>> + afe->preallocate_buffers = true;
>>>
>>> platform_set_drvdata(pdev, afe);
>>>
>>> diff --git a/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c b/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c
>>> index d083b4bf0f95..0ef07fb2898d 100644
>>> --- a/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c
>>> +++ b/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c
>>> @@ -1214,6 +1214,7 @@ static int mt8183_afe_pcm_dev_probe(struct platform_device *pdev)
>>> afe->mtk_afe_hardware = &mt8183_afe_hardware;
>>> afe->memif_fs = mt8183_memif_fs;
>>> afe->irq_fs = mt8183_irq_fs;
>>> + afe->preallocate_buffers = true;
>>>
>>> afe->runtime_resume = mt8183_afe_runtime_resume;
>>> afe->runtime_suspend = mt8183_afe_runtime_suspend;
>>> diff --git a/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c b/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
>>> index db7c93401bee..c588a68d672d 100644
>>> --- a/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
>>> +++ b/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
>>> @@ -2935,6 +2935,7 @@ static int mt8186_afe_pcm_dev_probe(struct platform_device *pdev)
>>> afe->irq_fs = mt8186_irq_fs;
>>> afe->get_dai_fs = mt8186_get_dai_fs;
>>> afe->get_memif_pbuf_size = mt8186_get_memif_pbuf_size;
>>> + afe->preallocate_buffers = true;
>>>
>>> afe->runtime_resume = mt8186_afe_runtime_resume;
>>> afe->runtime_suspend = mt8186_afe_runtime_suspend;
>>
>>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-04-01 10:45 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-01 8:56 [PATCH] ASoC: mediatek: re-enable buffer pre-allocation on some platforms Chen-Yu Tsai
2025-04-01 10:12 ` AngeloGioacchino Del Regno
2025-04-01 10:38 ` Chen-Yu Tsai
2025-04-01 10:39 ` Chen-Yu Tsai
2025-04-01 10:45 ` AngeloGioacchino Del Regno
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®