ALSA/ASoC: Prepare for boot-time page size selection on arm64
Subsystems (10)
v2 cover ALSA/ASoC: Prepare for boot-time page size selection on arm64
From: Eric Curtin <[email protected]>
This series is part of the boot-time page size selection work for arm64, posted as RFC [1]. With CONFIG_ARM64_BOOT_TIME_PAGE_SIZE=y, PAGE_SIZE, PAGE_SHIFT and PAGE_MASK are variables chosen at boot with arm64.pagesize=, so code that needs a compile-time constant (array sizes, struct layouts, static initialisers, BUILD_BUG_ON(), case labels, #if) has to use the new PAGE_SIZE_MIN/PAGE_SIZE_MAX limits or a run-time value instead. For fixed page sizes both limits equal PAGE_SIZE, so behaviour should not change.
The patches here convert ALSA/ASoC sound code. They apply on top of the core series [1], whose patch 1 adds PAGE_SIZE_MIN/MAX, and are otherwise independent of each other. Patches authored by Ryan Roberts come from his v1 [2], updated for v7.4-rc5. The full tree is at:
https://github.com/ericcurtin/linux/tree/boot-time-page-size-v2
Testing: allmodconfig with the option enabled builds cleanly on arm64 with all of these applied, and the defconfig kernel boots to userspace with 4K, 16K and 64K pages under QEMU/KVM (details in [1]). The code in this series is not otherwise exercised on hardware.
Tool use: these conversions were prepared with an LLM coding assistant (opencode with Claude Sonnet), driven by build errors and followed by an automated review pass. I have not hand-audited every patch, so please review with that in mind and tell me where you would prefer a different approach for your subsystem.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
Eric Curtin (1):
ALSA: Handle run-time PAGE_SIZE in PCM hardware tables and #if checks
Ryan Roberts (2):
ASoC: tegra: Initialise PCM hardware limits at boot for page size
ASoC: codecs: Initialise PCM hardware tables at boot for page size
RFC PATCH v2 1/3 ALSA: Handle run-time PAGE_SIZE in PCM hardware tables and #if checks
From: Eric Curtin <[email protected]>
With arm64 boot-time page size selection PAGE_SIZE is not a compile-time constant, so it cannot be used in #if, in static const initialisers, or to initialise module parameter defaults.
- seq_midi: define output_buffer_size and input_buffer_size with DEFINE_GLOBAL_PAGE_SIZE_VAR(), so the module parameters default to the run-time page size.
- Define the static snd_pcm_hardware tables in riptide, bcm63xx, rt5677-spi, sprd, stm32 i2s, sai and spdifrx and adfsdm, and the snd_dmaengine_pcm_config in stm32_i2s, with DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST().
- echoaudio: test PAGE_SIZE_MIN in the page size #if.
- emu10k1 and trident: select the fixed-page-size fast paths only if PAGE_SIZE_MIN and PAGE_SIZE_MAX both match the hardware page size.
- ua101: use PAGE_SIZE_MIN in MAX_MEMORY_BUFFERS, since the smallest page needs the most buffers.
No functional change for compile-time page sizes.
--- sound/core/seq/seq_midi.c | 4 ++-- sound/pci/echoaudio/echoaudio_dsp.c | 2 +- sound/pci/emu10k1/memory.c | 3 ++- sound/pci/riptide/riptide.c | 10 ++++++---- sound/pci/trident/trident_memory.c | 4 ++-- sound/soc/bcm/bcm63xx-pcm-whistler.c | 5 +++-- sound/soc/codecs/rt5677-spi.c | 5 +++-- sound/soc/sprd/sprd-pcm-dma.c | 5 +++-- sound/soc/stm/stm32_adfsdm.c | 5 +++-- sound/soc/stm/stm32_i2s.c | 10 ++++++---- sound/soc/stm/stm32_sai_sub.c | 10 ++++++---- sound/soc/stm/stm32_spdifrx.c | 5 +++-- sound/usb/misc/ua101.c | 2 +- 13 files changed, 41 insertions(+), 29 deletions(-)
sound/core/seq/seq_midi.c +2 -2
@@ -29,10 +29,10 @@ Possible options for midisynth module:MODULE_AUTHOR ("Frank van de Pol <[email protected]>, Jaroslav Kysela <[email protected]>" );MODULE_DESCRIPTION ("Advanced Linux Sound Architecture sequencer MIDI synth." );MODULE_LICENSE ("GPL" ); -static int output_buffer_size =PAGE_SIZE ; +static DEFINE_GLOBAL_PAGE_SIZE_VAR(int, output_buffer_size, PAGE_SIZE);module_param (output_buffer_size, int,0644 );MODULE_PARM_DESC (output_buffer_size,"Output buffer size in bytes." ); -static int input_buffer_size =PAGE_SIZE ; +static DEFINE_GLOBAL_PAGE_SIZE_VAR(int, input_buffer_size, PAGE_SIZE);module_param (input_buffer_size, int,0644 );MODULE_PARM_DESC (input_buffer_size,"Input buffer size in bytes." );
sound/pci/echoaudio/echoaudio_dsp.c +1 -1
@@ -13,7 +13,7 @@****************************************************************************/ -#if PAGE_SIZE <4096 +#if PAGE_SIZE_MIN <4096 #error PAGE_SIZE is < 4k#endif
sound/pci/emu10k1/memory.c +2 -1
@@ -32,7 +32,8 @@/* get offset address from aligned page */ #define aligned_page_offset (page) ((page) << PAGE_SHIFT) -#if PAGE_SIZE ==EMUPAGESIZE && !IS_ENABLED (CONFIG_DYNAMIC_DEBUG ) +#if PAGE_SIZE_MIN ==EMUPAGESIZE &&PAGE_SIZE_MAX ==EMUPAGESIZE && \ + !IS_ENABLED (CONFIG_DYNAMIC_DEBUG )/* fill PTB entrie(s) corresponding to page with addr */ #define set_ptb_entry (emu,page,addr) __set_ptb_entry(emu,page,addr)/* fill PTB entrie(s) corresponding to page with silence pointer */
sound/pci/riptide/riptide.c +6 -4
@@ -1301,7 +1301,8 @@ static int riptide_reset(struct cmdif *cif, struct snd_riptide *chip)return 0 ; } -static const struct snd_pcm_hardware snd_riptide_playback = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, + snd_riptide_playback, { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_MMAP_VALID),
@@ -1319,8 +1320,9 @@ static const struct snd_pcm_hardware snd_riptide_playback = { .periods_min = 2, .periods_max = 64, .fifo_size = 0, -}; -static const struct snd_pcm_hardware snd_riptide_capture = { +}); +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, + snd_riptide_capture, { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_MMAP_VALID),
@@ -1338,7 +1340,7 @@ static const struct snd_pcm_hardware snd_riptide_capture = { .periods_min = 2, .periods_max = 64, .fifo_size = 0, -}; +});static snd_pcm_uframes_t snd_riptide_pointer (struct snd_pcm_substream *substream)
sound/pci/trident/trident_memory.c +2 -2
@@ -24,7 +24,7 @@#define __tlb_to_addr (trident,page) \ (dma_addr_t)le32_to_cpu((trident->tlb.entries[page]) & ~(SNDRV_TRIDENT_PAGE_SIZE - 1)) -#if PAGE_SIZE ==4096 +#if PAGE_SIZE_MIN ==4096 &&PAGE_SIZE_MAX ==4096 /* page size == SNDRV_TRIDENT_PAGE_SIZE */ #define ALIGN_PAGE_SIZE PAGE_SIZE/* minimum page size for allocation */ #define MAX_ALIGN_PAGES SNDRV_TRIDENT_MAX_PAGES/* maximum aligned pages */
@@ -39,7 +39,7 @@/* get PCI physical address from aligned page */ #define page_to_addr (trident,page) __tlb_to_addr(trident, page) -#elif PAGE_SIZE ==8192 +#elif PAGE_SIZE_MIN ==8192 &&PAGE_SIZE_MAX ==8192 /* page size == SNDRV_TRIDENT_PAGE_SIZE x 2*/ #define ALIGN_PAGE_SIZE PAGE_SIZE#define MAX_ALIGN_PAGES (SNDRV_TRIDENT_MAX_PAGES / 2)
sound/soc/bcm/bcm63xx-pcm-whistler.c +3 -2
@@ -27,7 +27,8 @@ struct bcm63xx_runtime_data {dma_addr_t dma_addr_next; }; -static const struct snd_pcm_hardware bcm63xx_pcm_hardware = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, + bcm63xx_pcm_hardware, { .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_INTERLEAVED |
@@ -39,7 +40,7 @@ static const struct snd_pcm_hardware bcm63xx_pcm_hardware = { .periods_max = PAGE_SIZE/sizeof(struct i2s_dma_desc), .buffer_bytes_max = 128 * 1024, .fifo_size = 32, -}; +}); static int bcm63xx_pcm_hw_params(struct snd_soc_component *component, struct snd_pcm_substream *substream,
sound/soc/codecs/rt5677-spi.c +3 -2
@@ -72,7 +72,8 @@ struct rt5677_dsp {bool new_hotword;/* a new hotword is fired */ }; -static const struct snd_pcm_hardware rt5677_spi_pcm_hardware = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, + rt5677_spi_pcm_hardware, { .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_INTERLEAVED,
@@ -84,7 +85,7 @@ static const struct snd_pcm_hardware rt5677_spi_pcm_hardware = { .channels_min = 1, .channels_max = 1, .buffer_bytes_max = RT5677_BUF_BYTES_TOTAL, -}; +});static struct snd_soc_dai_driver rt5677_spi_dai = {/* The DAI name "rt5677-dsp-cpu-dai" is not used. The actual DAI name
sound/soc/sprd/sprd-pcm-dma.c +3 -2
@@ -34,7 +34,8 @@ struct sprd_pcm_dma_private {int dma_addr_offset; }; -static const struct snd_pcm_hardware sprd_pcm_hardware = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, + sprd_pcm_hardware, { .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_NO_PERIOD_WAKEUP,
@@ -44,7 +45,7 @@ static const struct snd_pcm_hardware sprd_pcm_hardware = { .periods_min = 1, .periods_max = PAGE_SIZE / SPRD_PCM_DMA_LINKLIST_SIZE, .buffer_bytes_max = 64 * 1024, -}; +});static int sprd_pcm_open (struct snd_soc_component *component,struct snd_pcm_substream *substream)
sound/soc/stm/stm32_adfsdm.c +3 -2
@@ -42,7 +42,8 @@ struct stm32_adfsdm_priv {struct mutex lock;/* protect against race condition on iio state */ }; -static const struct snd_pcm_hardware stm32_adfsdm_pcm_hw = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, + stm32_adfsdm_pcm_hw, { .info = SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_PAUSE, .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE,
@@ -55,7 +56,7 @@ static const struct snd_pcm_hardware stm32_adfsdm_pcm_hw = { .period_bytes_max = DFSDM_MAX_PERIOD_SIZE, .buffer_bytes_max =DFSDM_MAX_PERIODS *DFSDM_MAX_PERIOD_SIZE -}; +});static void stm32_adfsdm_shutdown (struct snd_pcm_substream *substream,struct snd_soc_dai *dai)
sound/soc/stm/stm32_i2s.c +6 -4
@@ -1111,20 +1111,22 @@ static const struct snd_soc_dai_ops stm32_i2s_pcm_dai_ops = { .num_auto_selectable_formats = 1, }; -static const struct snd_pcm_hardware stm32_i2s_pcm_hw = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, + stm32_i2s_pcm_hw, { .info = SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP, .buffer_bytes_max = 8 * PAGE_SIZE, .period_bytes_min = 1024, .period_bytes_max = 4 * PAGE_SIZE, .periods_min = 2, .periods_max = 8, -}; +}); -static const struct snd_dmaengine_pcm_config stm32_i2s_pcm_config = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_dmaengine_pcm_config, + stm32_i2s_pcm_config, { .pcm_hardware = &stm32_i2s_pcm_hw, .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config, .prealloc_buffer_size = PAGE_SIZE * 8, -}; +});static const struct snd_soc_component_driver stm32_i2s_component = { .name ="stm32-i2s" ,
sound/soc/stm/stm32_sai_sub.c +6 -4
@@ -1433,23 +1433,25 @@ static int stm32_sai_pcm_process_spdif(struct snd_pcm_substream *substream, }/* No support of mmap in S/PDIF mode */ -static const struct snd_pcm_hardware stm32_sai_pcm_hw_spdif = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, + stm32_sai_pcm_hw_spdif, { .info = SNDRV_PCM_INFO_INTERLEAVED, .buffer_bytes_max = 8 * PAGE_SIZE, .period_bytes_min = 1024, .period_bytes_max = PAGE_SIZE, .periods_min = 2, .periods_max = 8, -}; +}); -static const struct snd_pcm_hardware stm32_sai_pcm_hw = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, + stm32_sai_pcm_hw, { .info = SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP, .buffer_bytes_max = 8 * PAGE_SIZE, .period_bytes_min = 1024, /* 5ms at 48kHz */ .period_bytes_max = PAGE_SIZE, .periods_min = 2, .periods_max = 8, -}; +});static struct snd_soc_dai_driver stm32_sai_playback_dai = { .id =1 ,/* avoid call to fmt_single_name() */
sound/soc/stm/stm32_spdifrx.c +3 -2
@@ -864,14 +864,15 @@ static struct snd_soc_dai_driver stm32_spdifrx_dai[] = { } }; -static const struct snd_pcm_hardware stm32_spdifrx_pcm_hw = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, + stm32_spdifrx_pcm_hw, { .info = SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP, .buffer_bytes_max = 8 * PAGE_SIZE, .period_bytes_min = 1024, .period_bytes_max = 4 * PAGE_SIZE, .periods_min = 2, .periods_max = 8, -}; +});static const struct snd_soc_component_driver stm32_spdifrx_component = { .name ="stm32-spdifrx" ,
sound/usb/misc/ua101.c +1 -1
@@ -37,7 +37,7 @@ MODULE_LICENSE("GPL v2");#define MAX_PACKET_SIZE 672/* hardware specific */ #define MAX_MEMORY_BUFFERS DIV_ROUND_UP(MAX_QUEUE_LENGTH, \ - PAGE_SIZE / MAX_PACKET_SIZE) + PAGE_SIZE_MIN / MAX_PACKET_SIZE)static int index[SNDRV_CARDS ] =SNDRV_DEFAULT_IDX ;static char *id[SNDRV_CARDS ] =SNDRV_DEFAULT_STR ;
[email protected]
AI reviewRe: [RFC PATCH v2 1/3] ALSA: Handle run-time PAGE_SIZE in PCM hardware tables and #if checks
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] ALSA: undefined PAGE_SIZE_MIN/MAX and DEFINE_GLOBAL_PAGE_SIZE_VAR macros - [High] ALSA: seq_midi…
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [High] ALSA: undefined PAGE_SIZE_MIN/MAX and DEFINE_GLOBAL_PAGE_SIZE_VAR macros
- [High] ALSA: seq_midi: DEFINE_GLOBAL_PAGE_SIZE_VAR incompatible with module_param()
- [High] ASoC: stm32: non-constant PCM hardware addresses in static const configs
--
commit d082150f9e50604189f172c34889dabc193b0410
Author: Eric Curtin <[email protected]>
ALSA: Handle run-time PAGE_SIZE in PCM hardware tables and #if checks
This commit converts ALSA module parameters, static PCM hardware and DMA configuration tables, and preprocessor page size checks to use DEFINE_GLOBAL_PAGE_SIZE_VAR, DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST, PAGE_SIZE_MIN, and PAGE_SIZE_MAX for boot-time page size selection.
Quoted 6 lines
sound/core/seq/seq_midi.c +0
-0@@ -29,10 +29,10 @@ Possible options for midisynth module:MODULE_AUTHOR ("Frank van de Pol <[email protected]>, Jaroslav Kysela <[email protected]>" );
sound/core/seq/seq_midi.c Possible options for midisynth module: · line 37
Quoted 10 lines
sound/core/seq/seq_midi.c +2
-2MODULE_DESCRIPTION ("Advanced Linux Sound Architecture sequencer MIDI synth." );MODULE_LICENSE ("GPL" ); -static int output_buffer_size =PAGE_SIZE ; +static DEFINE_GLOBAL_PAGE_SIZE_VAR(int, output_buffer_size, PAGE_SIZE);module_param (output_buffer_size, int,0644 );MODULE_PARM_DESC (output_buffer_size,"Output buffer size in bytes." ); -static int input_buffer_size =PAGE_SIZE ; +static DEFINE_GLOBAL_PAGE_SIZE_VAR(int, input_buffer_size, PAGE_SIZE);module_param (input_buffer_size, int,0644 );MODULE_PARM_DESC (input_buffer_size,"Input buffer size in bytes." );
[Severity: High]
Can output_buffer_size and input_buffer_size be defined with DEFINE_GLOBAL_PAGE_SIZE_VAR() when they are passed to module_param()?
With boot-time PAGE_SIZE, DEFINE_GLOBAL_PAGE_SIZE_VAR() defines the variable name as a macro expanding to a dereferenced accessor call. module_param() expands its first argument before passing it to module_param_named(), breaking token pasting on __param_str_##name and failing to compile because &(value) in the static struct kernel_param initializer is no longer a compile-time constant address. In addition, the module parameter code reads and writes the underlying storage directly without running the lazy initializer, so sysfs reads before first access would see 0 and user-supplied parameter values would be overwritten on first lazy initialization.
sound/pci/echoaudio/echoaudio_dsp.c line 18
Quoted 12 lines
sound/pci/echoaudio/echoaudio_dsp.c +1
-1@@ -13,7 +13,7 @@****************************************************************************/ -#if PAGE_SIZE <4096 +#if PAGE_SIZE_MIN <4096 #error PAGE_SIZE is < 4k#endif
[Severity: High]
Are the prerequisite definitions for PAGE_SIZE_MIN, PAGE_SIZE_MAX, DEFINE_GLOBAL_PAGE_SIZE_VAR(), and DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST() missing from this tree?
None of these macros are defined in include/vdso/page.h or anywhere else, causing build failures across all 13 modified drivers. In preprocessor directives, undefined PAGE_SIZE_MIN and PAGE_SIZE_MAX evaluate to 0 (with -Wundef warnings), triggering this #error unconditionally in echoaudio_dsp.c and disabling the 4 KiB and 8 KiB fast paths in sound/pci/emu10k1/memory.c and sound/pci/trident/trident_memory.c.
[ ... ]
Quoted 21 lines
sound/soc/stm/stm32_sai_sub.c +3
-3@@ -1433,23 +1433,25 @@ static int stm32_sai_pcm_process_spdif(struct snd_pcm_substream *substream, }/* No support of mmap in S/PDIF mode */ -static const struct snd_pcm_hardware stm32_sai_pcm_hw_spdif = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, + stm32_sai_pcm_hw_spdif, { .info = SNDRV_PCM_INFO_INTERLEAVED, .buffer_bytes_max = 8 * PAGE_SIZE, .period_bytes_min = 1024, .period_bytes_max = PAGE_SIZE, .periods_min = 2, .periods_max = 8, -}; +}); -static const struct snd_pcm_hardware stm32_sai_pcm_hw = {
sound/soc/stm/stm32_sai_sub.c static int stm32_sai_pcm_process_spdif(struct snd_pcm_substream *substream, · line 1454
Quoted 10 lines
sound/soc/stm/stm32_sai_sub.c +3
-1+static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, + stm32_sai_pcm_hw, { .info = SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP, .buffer_bytes_max = 8 * PAGE_SIZE, .period_bytes_min = 1024, /* 5ms at 48kHz */ .period_bytes_max = PAGE_SIZE, .periods_min = 2, .periods_max = 8, -}; +});
[Severity: High]
Does converting stm32_sai_pcm_hw_spdif, stm32_sai_pcm_hw, and stm32_spdifrx_pcm_hw to DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST() break the static initializers of stm32_sai_pcm_config, stm32_sai_pcm_config_spdif, and stm32_spdifrx_pcm_config when PAGE_SIZE is not a compile-time constant?
Unlike stm32_i2s_pcm_config in sound/soc/stm/stm32_i2s.c, those three struct snd_dmaengine_pcm_config tables remain plain static const variables:
sound/soc/stm/stm32_sai_sub.c:
static const struct snd_dmaengine_pcm_config stm32_sai_pcm_config = {
.pcm_hardware = &stm32_sai_pcm_hw,
.prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
};static const struct snd_dmaengine_pcm_config stm32_sai_pcm_config_spdif = {
.pcm_hardware = &stm32_sai_pcm_hw_spdif, .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config, .process = stm32_sai_pcm_process_spdif,
};
When boot-time page size selection is enabled, &stm32_sai_pcm_hw, &stm32_sai_pcm_hw_spdif, and &stm32_spdifrx_pcm_hw expand to the address of a dereferenced accessor call rather than a compile-time constant address, failing compilation.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [RFC PATCH v2 1/3] ALSA: Handle run-time PAGE_SIZE in PCM hardware tables and #if checks
In reply to Eric CurtinQuoted 10 lines · Eric Curtin
From: Eric Curtin <[email protected]>
With arm64 boot-time page size selection
PAGE_SIZEis not a compile-time constant, so it cannot be used in #if, in static const initialisers, or to initialise module parameter defaults.-
seq_midi: defineoutput_buffer_sizeandinput_buffer_sizewithDEFINE_GLOBAL_PAGE_SIZE_VAR(), so the module parameters default to the run-time page size.
I believe this should be rather replaced with a constant 4096 (better define some constant, of course). Those buffer sizes have nothing to do with the actual page size.
Quoted 4 lines
- Define the static
snd_pcm_hardwaretables in riptide, bcm63xx, rt5677-spi, sprd, stm32 i2s, sai and spdifrx and adfsdm, and thesnd_dmaengine_pcm_configinstm32_i2s, withDEFINE_GLOBAL_PAGE_SIZE_VAR_CONST().
I guess those could be replaced with PAGE_SIZE_MIN. It can be more consistent.
thanks,
Takashi
Quoted 318 lines
- echoaudio: test
PAGE_SIZE_MINin the page size #if.
- emu10k1 and trident: select the fixed-page-size fast paths only ifPAGE_SIZE_MINandPAGE_SIZE_MAXboth match the hardware page size.
- ua101: usePAGE_SIZE_MINinMAX_MEMORY_BUFFERS, since the smallest page needs the most buffers.No functional change for compile-time page sizes.
Signed-off-by Eric Curtin <[email protected]>--- sound/core/seq/seq_midi.c | 4 ++-- sound/pci/echoaudio/echoaudio_dsp.c | 2 +- sound/pci/emu10k1/memory.c | 3 ++- sound/pci/riptide/riptide.c | 10 ++++++---- sound/pci/trident/trident_memory.c | 4 ++-- sound/soc/bcm/bcm63xx-pcm-whistler.c | 5 +++-- sound/soc/codecs/rt5677-spi.c | 5 +++-- sound/soc/sprd/sprd-pcm-dma.c | 5 +++-- sound/soc/stm/stm32_adfsdm.c | 5 +++-- sound/soc/stm/stm32_i2s.c | 10 ++++++---- sound/soc/stm/stm32_sai_sub.c | 10 ++++++---- sound/soc/stm/stm32_spdifrx.c | 5 +++-- sound/usb/misc/ua101.c | 2 +- 13 files changed, 41 insertions(+), 29 deletions(-)sound/core/seq/seq_midi.c +2
-2@@ -29,10 +29,10 @@ Possible options for midisynth module:MODULE_AUTHOR ("Frank van de Pol <[email protected]>, Jaroslav Kysela <[email protected]>" );MODULE_DESCRIPTION ("Advanced Linux Sound Architecture sequencer MIDI synth." );MODULE_LICENSE ("GPL" ); -static int output_buffer_size =PAGE_SIZE ; +static DEFINE_GLOBAL_PAGE_SIZE_VAR(int, output_buffer_size, PAGE_SIZE);module_param (output_buffer_size, int,0644 );MODULE_PARM_DESC (output_buffer_size,"Output buffer size in bytes." ); -static int input_buffer_size =PAGE_SIZE ; +static DEFINE_GLOBAL_PAGE_SIZE_VAR(int, input_buffer_size, PAGE_SIZE);module_param (input_buffer_size, int,0644 );MODULE_PARM_DESC (input_buffer_size,"Input buffer size in bytes." );sound/pci/echoaudio/echoaudio_dsp.c +1
-1@@ -13,7 +13,7 @@****************************************************************************/ -#if PAGE_SIZE <4096 +#if PAGE_SIZE_MIN <4096 #error PAGE_SIZE is < 4k#endif sound/pci/emu10k1/memory.c +2
-1@@ -32,7 +32,8 @@/* get offset address from aligned page */ #define aligned_page_offset (page) ((page) << PAGE_SHIFT) -#if PAGE_SIZE ==EMUPAGESIZE && !IS_ENABLED (CONFIG_DYNAMIC_DEBUG ) +#if PAGE_SIZE_MIN ==EMUPAGESIZE &&PAGE_SIZE_MAX ==EMUPAGESIZE && \ + !IS_ENABLED (CONFIG_DYNAMIC_DEBUG )/* fill PTB entrie(s) corresponding to page with addr */ #define set_ptb_entry (emu,page,addr) __set_ptb_entry(emu,page,addr)/* fill PTB entrie(s) corresponding to page with silence pointer */ sound/pci/riptide/riptide.c +6
-4@@ -1301,7 +1301,8 @@ static int riptide_reset(struct cmdif *cif, struct snd_riptide *chip)return 0 ; } -static const struct snd_pcm_hardware snd_riptide_playback = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, + snd_riptide_playback, { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_MMAP_VALID),@@ -1319,8 +1320,9 @@ static const struct snd_pcm_hardware snd_riptide_playback = { .periods_min = 2, .periods_max = 64, .fifo_size = 0, -}; -static const struct snd_pcm_hardware snd_riptide_capture = { +}); +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, + snd_riptide_capture, { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_MMAP_VALID),@@ -1338,7 +1340,7 @@ static const struct snd_pcm_hardware snd_riptide_capture = { .periods_min = 2, .periods_max = 64, .fifo_size = 0, -}; +});static snd_pcm_uframes_t snd_riptide_pointer (struct snd_pcm_substream *substream)sound/pci/trident/trident_memory.c +2
-2@@ -24,7 +24,7 @@#define __tlb_to_addr (trident,page) \ (dma_addr_t)le32_to_cpu((trident->tlb.entries[page]) & ~(SNDRV_TRIDENT_PAGE_SIZE - 1)) -#if PAGE_SIZE ==4096 +#if PAGE_SIZE_MIN ==4096 &&PAGE_SIZE_MAX ==4096 /* page size == SNDRV_TRIDENT_PAGE_SIZE */ #define ALIGN_PAGE_SIZE PAGE_SIZE/* minimum page size for allocation */ #define MAX_ALIGN_PAGES SNDRV_TRIDENT_MAX_PAGES/* maximum aligned pages */ @@ -39,7 +39,7 @@/* get PCI physical address from aligned page */ #define page_to_addr (trident,page) __tlb_to_addr(trident, page) -#elif PAGE_SIZE ==8192 +#elif PAGE_SIZE_MIN ==8192 &&PAGE_SIZE_MAX ==8192 /* page size == SNDRV_TRIDENT_PAGE_SIZE x 2*/ #define ALIGN_PAGE_SIZE PAGE_SIZE#define MAX_ALIGN_PAGES (SNDRV_TRIDENT_MAX_PAGES / 2)sound/soc/bcm/bcm63xx-pcm-whistler.c +3
-2@@ -27,7 +27,8 @@ struct bcm63xx_runtime_data {dma_addr_t dma_addr_next; }; -static const struct snd_pcm_hardware bcm63xx_pcm_hardware = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, + bcm63xx_pcm_hardware, { .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_INTERLEAVED |@@ -39,7 +40,7 @@ static const struct snd_pcm_hardware bcm63xx_pcm_hardware = { .periods_max = PAGE_SIZE/sizeof(struct i2s_dma_desc), .buffer_bytes_max = 128 * 1024, .fifo_size = 32, -}; +}); static int bcm63xx_pcm_hw_params(struct snd_soc_component *component, struct snd_pcm_substream *substream,sound/soc/codecs/rt5677-spi.c +3
-2@@ -72,7 +72,8 @@ struct rt5677_dsp {bool new_hotword;/* a new hotword is fired */ }; -static const struct snd_pcm_hardware rt5677_spi_pcm_hardware = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, + rt5677_spi_pcm_hardware, { .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_INTERLEAVED,@@ -84,7 +85,7 @@ static const struct snd_pcm_hardware rt5677_spi_pcm_hardware = { .channels_min = 1, .channels_max = 1, .buffer_bytes_max = RT5677_BUF_BYTES_TOTAL, -}; +});static struct snd_soc_dai_driver rt5677_spi_dai = {/* The DAI name "rt5677-dsp-cpu-dai" is not used. The actual DAI name sound/soc/sprd/sprd-pcm-dma.c +3
-2@@ -34,7 +34,8 @@ struct sprd_pcm_dma_private {int dma_addr_offset; }; -static const struct snd_pcm_hardware sprd_pcm_hardware = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, + sprd_pcm_hardware, { .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_NO_PERIOD_WAKEUP,@@ -44,7 +45,7 @@ static const struct snd_pcm_hardware sprd_pcm_hardware = { .periods_min = 1, .periods_max = PAGE_SIZE / SPRD_PCM_DMA_LINKLIST_SIZE, .buffer_bytes_max = 64 * 1024, -}; +});static int sprd_pcm_open (struct snd_soc_component *component,struct snd_pcm_substream *substream)sound/soc/stm/stm32_adfsdm.c +3
-2@@ -42,7 +42,8 @@ struct stm32_adfsdm_priv {struct mutex lock;/* protect against race condition on iio state */ }; -static const struct snd_pcm_hardware stm32_adfsdm_pcm_hw = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, + stm32_adfsdm_pcm_hw, { .info = SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_PAUSE, .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE,@@ -55,7 +56,7 @@ static const struct snd_pcm_hardware stm32_adfsdm_pcm_hw = { .period_bytes_max = DFSDM_MAX_PERIOD_SIZE, .buffer_bytes_max =DFSDM_MAX_PERIODS *DFSDM_MAX_PERIOD_SIZE -}; +});static void stm32_adfsdm_shutdown (struct snd_pcm_substream *substream,struct snd_soc_dai *dai)sound/soc/stm/stm32_i2s.c +6
-4@@ -1111,20 +1111,22 @@ static const struct snd_soc_dai_ops stm32_i2s_pcm_dai_ops = { .num_auto_selectable_formats = 1, }; -static const struct snd_pcm_hardware stm32_i2s_pcm_hw = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, + stm32_i2s_pcm_hw, { .info = SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP, .buffer_bytes_max = 8 * PAGE_SIZE, .period_bytes_min = 1024, .period_bytes_max = 4 * PAGE_SIZE, .periods_min = 2, .periods_max = 8, -}; +}); -static const struct snd_dmaengine_pcm_config stm32_i2s_pcm_config = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_dmaengine_pcm_config, + stm32_i2s_pcm_config, { .pcm_hardware = &stm32_i2s_pcm_hw, .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config, .prealloc_buffer_size = PAGE_SIZE * 8, -}; +});static const struct snd_soc_component_driver stm32_i2s_component = { .name ="stm32-i2s" ,sound/soc/stm/stm32_sai_sub.c +6
-4@@ -1433,23 +1433,25 @@ static int stm32_sai_pcm_process_spdif(struct snd_pcm_substream *substream, }/* No support of mmap in S/PDIF mode */ -static const struct snd_pcm_hardware stm32_sai_pcm_hw_spdif = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, + stm32_sai_pcm_hw_spdif, { .info = SNDRV_PCM_INFO_INTERLEAVED, .buffer_bytes_max = 8 * PAGE_SIZE, .period_bytes_min = 1024, .period_bytes_max = PAGE_SIZE, .periods_min = 2, .periods_max = 8, -}; +}); -static const struct snd_pcm_hardware stm32_sai_pcm_hw = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, + stm32_sai_pcm_hw, { .info = SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP, .buffer_bytes_max = 8 * PAGE_SIZE, .period_bytes_min = 1024, /* 5ms at 48kHz */ .period_bytes_max = PAGE_SIZE, .periods_min = 2, .periods_max = 8, -}; +});static struct snd_soc_dai_driver stm32_sai_playback_dai = { .id =1 ,/* avoid call to fmt_single_name() */ sound/soc/stm/stm32_spdifrx.c +3
-2@@ -864,14 +864,15 @@ static struct snd_soc_dai_driver stm32_spdifrx_dai[] = { } }; -static const struct snd_pcm_hardware stm32_spdifrx_pcm_hw = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, + stm32_spdifrx_pcm_hw, { .info = SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP, .buffer_bytes_max = 8 * PAGE_SIZE, .period_bytes_min = 1024, .period_bytes_max = 4 * PAGE_SIZE, .periods_min = 2, .periods_max = 8, -}; +});static const struct snd_soc_component_driver stm32_spdifrx_component = { .name ="stm32-spdifrx" ,sound/usb/misc/ua101.c +1
-1@@ -37,7 +37,7 @@ MODULE_LICENSE("GPL v2");#define MAX_PACKET_SIZE 672/* hardware specific */ #define MAX_MEMORY_BUFFERS DIV_ROUND_UP(MAX_QUEUE_LENGTH, \ - PAGE_SIZE / MAX_PACKET_SIZE) + PAGE_SIZE_MIN / MAX_PACKET_SIZE)static int index[SNDRV_CARDS ] =SNDRV_DEFAULT_IDX ;static char *id[SNDRV_CARDS ] =SNDRV_DEFAULT_STR ;
RFC PATCH v2 2/3 ASoC: tegra: Initialise PCM hardware limits at boot for page size
In reply to Eric CurtinFrom: Ryan Roberts <[email protected]>
tegra_pcm_hardware and tegra_dmaengine_pcm_config use PAGE_SIZE in their initialisers, which is not a constant expression with arm64 boot-time page size selection.
Define both with DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(), which keeps a normal const initialiser for a fixed page size and otherwise fills them in once the page size is known at boot.
--- sound/soc/tegra/tegra_pcm.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
sound/soc/tegra/tegra_pcm.c +6 -4
@@ -24,7 +24,8 @@#include <sound/dmaengine_pcm.h> #include "tegra_pcm.h" -static const struct snd_pcm_hardware tegra_pcm_hardware = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, + tegra_pcm_hardware, { .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_INTERLEAVED,
@@ -34,13 +35,14 @@ static const struct snd_pcm_hardware tegra_pcm_hardware = { .periods_max = 8, .buffer_bytes_max = PAGE_SIZE * 8, .fifo_size = 4, -}; +}); -static const struct snd_dmaengine_pcm_config tegra_dmaengine_pcm_config = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_dmaengine_pcm_config, + tegra_dmaengine_pcm_config, { .pcm_hardware = &tegra_pcm_hardware, .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config, .prealloc_buffer_size = PAGE_SIZE * 8, -}; +});int tegra_pcm_platform_register (struct device *dev) {
[email protected]
AI reviewRe: [RFC PATCH v2 2/3] ASoC: tegra: Initialise PCM hardware limits at boot for page size
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] ASoC: tegra: build failure from undefined DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] ASoC: tegra: build failure from undefined DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST
--
commit 441dd3749331e159481ddc8e8e434e0e57f51521
Author: Ryan Roberts <[email protected]>
ASoC: tegra: Initialise PCM hardware limits at boot for page size
This commit switches tegra_pcm_hardware and tegra_dmaengine_pcm_config to DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST() so their PAGE_SIZE-derived fields can be initialized at boot when boot-time page size selection is enabled.
Quoted 19 lines
sound/soc/tegra/tegra_pcm.c +2
-2@@ -24,7 +24,8 @@#include <sound/dmaengine_pcm.h> #include "tegra_pcm.h" -static const struct snd_pcm_hardware tegra_pcm_hardware = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, + tegra_pcm_hardware, { .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_INTERLEAVED,@@ -34,13 +35,14 @@ static const struct snd_pcm_hardware tegra_pcm_hardware = { .periods_max = 8, .buffer_bytes_max = PAGE_SIZE * 8, .fifo_size = 4, -};
sound/soc/tegra/tegra_pcm.c static const struct snd_pcm_hardware tegra_pcm_hardware = { · line 45
Quoted 10 lines
sound/soc/tegra/tegra_pcm.c +4
-2+}); -static const struct snd_dmaengine_pcm_config tegra_dmaengine_pcm_config = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_dmaengine_pcm_config, + tegra_dmaengine_pcm_config, { .pcm_hardware = &tegra_pcm_hardware, .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config, .prealloc_buffer_size = PAGE_SIZE * 8, -}; +});
[Severity: High]
Does this break the build when CONFIG_SND_SOC_TEGRA is enabled?
DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST() is not defined anywhere in the tree, so compiling sound/soc/tegra/tegra_pcm.c fails with a syntax error and leaves tegra_pcm_hardware and tegra_dmaengine_pcm_config undeclared. Also, since these PCM period and buffer limits are audio buffer sizes rather than MMU page size limits, could they use SZ_4K and SZ_32K instead of PAGE_SIZE?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Mark Brown
maintainerRe: [RFC PATCH v2 2/3] ASoC: tegra: Initialise PCM hardware limits at boot for page size
In reply to Eric CurtinQuoted 7 lines
tegra_pcm_hardwareandtegra_dmaengine_pcm_configusePAGE_SIZEin their initialisers, which is not a constant expression with arm64 boot-time page size selection.Define both with
DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(), which keeps a normal const initialiser for a fixed page size and otherwise fills them in once the page size is known at boot.
It would be easier to submit stuff like this once that macro is available...
Quoted 11 lines
sound/soc/tegra/tegra_pcm.c +2
-2-static const struct snd_pcm_hardware tegra_pcm_hardware = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, + tegra_pcm_hardware, { .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_INTERLEAVED,@@ -34,13 +35,14 @@ static const struct snd_pcm_hardware tegra_pcm_hardware = { .periods_max = 8, .buffer_bytes_max = PAGE_SIZE * 8, .fifo_size = 4, -};
sound/soc/tegra/tegra_pcm.c static const struct snd_pcm_hardware tegra_pcm_hardware = { · line 45
Quoted 10 lines
sound/soc/tegra/tegra_pcm.c +4
-2+}); -static const struct snd_dmaengine_pcm_config tegra_dmaengine_pcm_config = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_dmaengine_pcm_config, + tegra_dmaengine_pcm_config, { .pcm_hardware = &tegra_pcm_hardware, .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config, .prealloc_buffer_size = PAGE_SIZE * 8, -}; +});
Especially for the preallocted buffer why doees it make sense to scale this with page size, is a system with 64k pages really more likely to play 8 times more audio? It'd be good to check if the hardware is influenced by the MMU configuration here.
Signature · 1 line
Mark Brown <[email protected]>
RFC PATCH v2 3/3 ASoC: codecs: Initialise PCM hardware tables at boot for page size
In reply to Eric CurtinFrom: Ryan Roberts <[email protected]>
The snd_pcm_hardware tables in cros_ec_codec.c and rt5514-spi.c use PAGE_SIZE in their initialisers. That is not a constant expression with arm64 boot-time page size selection, so the tables cannot be static initialisers.
Define them with DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(), which keeps a normal const initialiser for a fixed page size and otherwise fills the table in once the page size is known at boot. In cros_ec_codec.c the table was local to wov_pcm_open(), so it moves to file scope.
--- sound/soc/codecs/cros_ec_codec.c | 30 +++++++++++++++--------------- sound/soc/codecs/rt5514-spi.c | 5 +++-- 2 files changed, 18 insertions(+), 17 deletions(-)
sound/soc/codecs/cros_ec_codec.c +15 -15
@@ -874,24 +874,24 @@ static void wov_remove(struct snd_soc_component *component) &priv->ec_device->event_notifier, &priv->wov_notifier); } +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, hw_param, { + .info = SNDRV_PCM_INFO_MMAP | + SNDRV_PCM_INFO_INTERLEAVED | + SNDRV_PCM_INFO_MMAP_VALID, + .formats = SNDRV_PCM_FMTBIT_S16_LE, + .rates = SNDRV_PCM_RATE_16000, + .channels_min = 1, + .channels_max = 1, + .period_bytes_min = PAGE_SIZE, + .period_bytes_max = 0x20000 / 8, + .periods_min = 8, + .periods_max = 8, + .buffer_bytes_max = 0x20000, +}); +static int wov_pcm_open (struct snd_soc_component *component,struct snd_pcm_substream *substream) { -static const struct snd_pcm_hardware hw_param = { - .info =SNDRV_PCM_INFO_MMAP | -SNDRV_PCM_INFO_INTERLEAVED | -SNDRV_PCM_INFO_MMAP_VALID , - .formats =SNDRV_PCM_FMTBIT_S16_LE , - .rates =SNDRV_PCM_RATE_16000 , - .channels_min =1 , - .channels_max =1 , - .period_bytes_min =PAGE_SIZE , - .period_bytes_max =0x20000 /8 , - .periods_min =8 , - .periods_max =8 , - .buffer_bytes_max =0x20000 , - }; -return snd_soc_set_runtime_hwparams (substream, &hw_param); }
sound/soc/codecs/rt5514-spi.c +3 -2
@@ -46,7 +46,8 @@ struct rt5514_dsp {int irq; }; -static const struct snd_pcm_hardware rt5514_spi_pcm_hardware = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, + rt5514_spi_pcm_hardware, { .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_INTERLEAVED,
@@ -58,7 +59,7 @@ static const struct snd_pcm_hardware rt5514_spi_pcm_hardware = { .channels_min = 1, .channels_max = 1, .buffer_bytes_max = 0x20000, -}; +});static struct snd_soc_dai_driver rt5514_spi_dai = { .name ="rt5514-dsp-cpu-dai" ,
[email protected]
AI reviewRe: [RFC PATCH v2 3/3] ASoC: codecs: Initialise PCM hardware tables at boot for page size
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] ASoC: codecs: undefined DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST() breaks build --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] ASoC: codecs: undefined DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST() breaks build
--
commit 202833e59f958a583de89e2f5513331103c9d6c9
Author: Ryan Roberts <[email protected]>
ASoC: codecs: Initialise PCM hardware tables at boot for page size
This commit converts the snd_pcm_hardware tables in cros_ec_codec.c and rt5514-spi.c to use DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST() so they can be initialised when PAGE_SIZE is selected at boot.
Quoted 59 lines
sound/soc/codecs/cros_ec_codec.c +15
-15@@ -874,24 +874,24 @@ static void wov_remove(struct snd_soc_component *component) &priv->ec_device->event_notifier, &priv->wov_notifier); } +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, hw_param, { + .info = SNDRV_PCM_INFO_MMAP | + SNDRV_PCM_INFO_INTERLEAVED | + SNDRV_PCM_INFO_MMAP_VALID, + .formats = SNDRV_PCM_FMTBIT_S16_LE, + .rates = SNDRV_PCM_RATE_16000, + .channels_min = 1, + .channels_max = 1, + .period_bytes_min = PAGE_SIZE, + .period_bytes_max = 0x20000 / 8, + .periods_min = 8, + .periods_max = 8, + .buffer_bytes_max = 0x20000, +}); +static int wov_pcm_open (struct snd_soc_component *component,struct snd_pcm_substream *substream) { -static const struct snd_pcm_hardware hw_param = { - .info =SNDRV_PCM_INFO_MMAP | -SNDRV_PCM_INFO_INTERLEAVED | -SNDRV_PCM_INFO_MMAP_VALID , - .formats =SNDRV_PCM_FMTBIT_S16_LE , - .rates =SNDRV_PCM_RATE_16000 , - .channels_min =1 , - .channels_max =1 , - .period_bytes_min =PAGE_SIZE , - .period_bytes_max =0x20000 /8 , - .periods_min =8 , - .periods_max =8 , - .buffer_bytes_max =0x20000 , - }; -return snd_soc_set_runtime_hwparams (substream, &hw_param); }sound/soc/codecs/rt5514-spi.c +2
-1@@ -46,7 +46,8 @@ struct rt5514_dsp {int irq; }; -static const struct snd_pcm_hardware rt5514_spi_pcm_hardware = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, + rt5514_spi_pcm_hardware, { .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_INTERLEAVED,
sound/soc/codecs/rt5514-spi.c static const struct snd_pcm_hardware rt5514_spi_pcm_hardware = { · line 62
Quoted 5 lines
sound/soc/codecs/rt5514-spi.c +1
-1@@ -58,7 +59,7 @@ static const struct snd_pcm_hardware rt5514_spi_pcm_hardware = { .channels_min = 1, .channels_max = 1, .buffer_bytes_max = 0x20000, -}; +});
[Severity: High]
Where is DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST() defined? No header in the tree provides this macro, so building cros_ec_codec.c or rt5514-spi.c fails with syntax errors at the declarations and undeclared identifier errors for hw_param and rt5514_spi_pcm_hardware.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Tzung-Bi Shih
maintainerRe: [RFC PATCH v2 3/3] ASoC: codecs: Initialise PCM hardware tables at boot for page size
In reply to Eric CurtinQuoted 11 lines · Eric Curtin
From: Ryan Roberts <[email protected]>
The
snd_pcm_hardwaretables incros_ec_codec.candrt5514-spi.cusePAGE_SIZEin their initialisers. That is not a constant expression with arm64 boot-time page size selection, so the tables cannot be static initialisers.Define them with
DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(), which keeps a normal const initialiser for a fixed page size and otherwise fills the table in once the page size is known at boot. Incros_ec_codec.cthe table was local towov_pcm_open(), so it moves to file scope.
The cover letter [1] should be sent to the recipients of the patch as well, so the context is easier to find.
[1] https://lore.kernel.org/all/[email protected]
Quoted 12 lines
sound/soc/codecs/cros_ec_codec.c +4
-0@@ -874,24 +874,24 @@ static void wov_remove(struct snd_soc_component *component) &priv->ec_device->event_notifier, &priv->wov_notifier); } +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, hw_param, { + .info = SNDRV_PCM_INFO_MMAP | + SNDRV_PCM_INFO_INTERLEAVED | + SNDRV_PCM_INFO_MMAP_VALID,
sound/soc/codecs/cros_ec_codec.c static void wov_remove(struct snd_soc_component *component) · line 890
Quoted 10 lines
sound/soc/codecs/cros_ec_codec.c +10
-0+ .formats = SNDRV_PCM_FMTBIT_S16_LE, + .rates = SNDRV_PCM_RATE_16000, + .channels_min = 1, + .channels_max = 1, + .period_bytes_min = PAGE_SIZE, + .period_bytes_max = 0x20000 / 8, + .periods_min = 8, + .periods_max = 8, + .buffer_bytes_max = 0x20000, +});
If keeping it this way, hw_param is moved from function scope to file scope and needs a prefix, e.g., wov_hw_param.
Quoted 9 lines
sound/soc/codecs/cros_ec_codec.c +1
-5+static int wov_pcm_open (struct snd_soc_component *component,struct snd_pcm_substream *substream) { -static const struct snd_pcm_hardware hw_param = { - .info =SNDRV_PCM_INFO_MMAP | -SNDRV_PCM_INFO_INTERLEAVED | -SNDRV_PCM_INFO_MMAP_VALID , - .formats =SNDRV_PCM_FMTBIT_S16_LE ,
sound/soc/codecs/cros_ec_codec.c static void wov_remove(struct snd_soc_component *component) · line 894
Quoted 10 lines
sound/soc/codecs/cros_ec_codec.c +0
-10- .rates = SNDRV_PCM_RATE_16000, - .channels_min = 1, - .channels_max = 1, - .period_bytes_min = PAGE_SIZE, - .period_bytes_max = 0x20000 / 8, - .periods_min = 8, - .periods_max = 8, - .buffer_bytes_max = 0x20000, - }; -
Overall, I think this is overkill. Replacing PAGE_SIZE here with SZ_4K would be the simplest fix. At least cros_ec_codec was written and tested assuming PAGE_SIZE is 4K.
Mark Brown
maintainerRe: [RFC PATCH v2 3/3] ASoC: codecs: Initialise PCM hardware tables at boot for page size
In reply to Eric CurtinQuoted 5 lines
The
snd_pcm_hardwaretables incros_ec_codec.candrt5514-spi.cusePAGE_SIZEin their initialisers. That is not a constant expression with arm64 boot-time page size selection, so the tables cannot be static initialisers.
sound/soc/codecs/cros_ec_codec.c static void wov_remove(struct snd_soc_component *component) · line 886
Quoted 10 lines
sound/soc/codecs/cros_ec_codec.c +10
-0+static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, hw_param, { + .info = SNDRV_PCM_INFO_MMAP | + SNDRV_PCM_INFO_INTERLEAVED | + SNDRV_PCM_INFO_MMAP_VALID, + .formats = SNDRV_PCM_FMTBIT_S16_LE, + .rates = SNDRV_PCM_RATE_16000, + .channels_min = 1, + .channels_max = 1, + .period_bytes_min = PAGE_SIZE, + .period_bytes_max = 0x20000 / 8,
These numbers don't work for 64k pages, we have a minimum of 64k and a maximum lower than that.
Signature · 1 line
Mark Brown <[email protected]>