From: Codrin Ciubotariu <codrin.ciubotariu@microchip.com> To: <alsa-devel@alsa-project.org>, <linux-kernel@vger.kernel.org> Cc: <perex@perex.cz>, <tiwai@suse.com>, <pierre-louis.bossart@linux.intel.com>, <broonie@kernel.org>, <joe@perches.com>, <lgirdwood@gmail.com>, <lars@metafoo.de>, <kuninori.morimoto.gx@renesas.com>, <nicolas.ferre@microchip.com>, <Cristian.Birsan@microchip.com>, Codrin Ciubotariu <codrin.ciubotariu@microchip.com> Subject: [RFC PATCH 4/6] ALSA: pcm: Create function for snd_pcm_runtime initialization Date: Wed, 19 May 2021 13:48:40 +0300 [thread overview] Message-ID: <20210519104842.977895-5-codrin.ciubotariu@microchip.com> (raw) In-Reply-To: <20210519104842.977895-1-codrin.ciubotariu@microchip.com> Group the setting of snd_pcm_runtime members in a separate function. This allows for code reutilization. Also, check for substream->ops before substream->ops->copy_user . Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com> --- include/sound/pcm.h | 2 + sound/core/pcm_native.c | 108 ++++++++++++++++++++++------------------ 2 files changed, 61 insertions(+), 49 deletions(-) diff --git a/include/sound/pcm.h b/include/sound/pcm.h index 2907ed2b937f..8e6bd4525c02 100644 --- a/include/sound/pcm.h +++ b/include/sound/pcm.h @@ -576,6 +576,8 @@ static inline int snd_pcm_suspend_all(struct snd_pcm *pcm) int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg); struct snd_pcm_runtime *snd_pcm_runtime_alloc(void); void snd_pcm_runtime_free(struct snd_pcm_runtime *runtime); +void snd_pcm_runtime_set(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params); int snd_pcm_open_substream(struct snd_pcm *pcm, int stream, struct file *file, struct snd_pcm_substream **rsubstream); void snd_pcm_release_substream(struct snd_pcm_substream *substream); diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index cb0164d55593..5b0e7ae2b1e7 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -658,13 +658,69 @@ static int snd_pcm_hw_params_choose(struct snd_pcm_substream *pcm, return 0; } +void snd_pcm_runtime_set(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + unsigned int bits; + snd_pcm_uframes_t frames; + + runtime->access = params_access(params); + runtime->format = params_format(params); + runtime->subformat = params_subformat(params); + runtime->channels = params_channels(params); + runtime->rate = params_rate(params); + runtime->period_size = params_period_size(params); + runtime->periods = params_periods(params); + runtime->buffer_size = params_buffer_size(params); + runtime->info = params->info; + runtime->rate_num = params->rate_num; + runtime->rate_den = params->rate_den; + runtime->no_period_wakeup = + (params->info & SNDRV_PCM_INFO_NO_PERIOD_WAKEUP) && + (params->flags & SNDRV_PCM_HW_PARAMS_NO_PERIOD_WAKEUP); + + bits = snd_pcm_format_physical_width(runtime->format); + runtime->sample_bits = bits; + bits *= runtime->channels; + runtime->frame_bits = bits; + frames = 1; + while (bits % 8 != 0) { + bits *= 2; + frames *= 2; + } + runtime->byte_align = bits / 8; + runtime->min_align = frames; + + /* Default sw params */ + runtime->tstamp_mode = SNDRV_PCM_TSTAMP_NONE; + runtime->period_step = 1; + runtime->control->avail_min = runtime->period_size; + runtime->start_threshold = 1; + runtime->stop_threshold = runtime->buffer_size; + runtime->silence_threshold = 0; + runtime->silence_size = 0; + runtime->boundary = runtime->buffer_size; + while (runtime->boundary * 2 <= LONG_MAX - runtime->buffer_size) + runtime->boundary *= 2; + + /* clear the buffer for avoiding possible kernel info leaks */ + if (runtime->dma_area && + !(substream->ops && substream->ops->copy_user)) { + size_t size = runtime->dma_bytes; + + if (runtime->info & SNDRV_PCM_INFO_MMAP) + size = PAGE_ALIGN(size); + memset(runtime->dma_area, 0, size); + } +} +EXPORT_SYMBOL(snd_pcm_runtime_set); + static int snd_pcm_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { struct snd_pcm_runtime *runtime; int err, usecs; - unsigned int bits; - snd_pcm_uframes_t frames; if (PCM_RUNTIME_CHECK(substream)) return -ENXIO; @@ -715,53 +771,7 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *substream, goto _error; } - runtime->access = params_access(params); - runtime->format = params_format(params); - runtime->subformat = params_subformat(params); - runtime->channels = params_channels(params); - runtime->rate = params_rate(params); - runtime->period_size = params_period_size(params); - runtime->periods = params_periods(params); - runtime->buffer_size = params_buffer_size(params); - runtime->info = params->info; - runtime->rate_num = params->rate_num; - runtime->rate_den = params->rate_den; - runtime->no_period_wakeup = - (params->info & SNDRV_PCM_INFO_NO_PERIOD_WAKEUP) && - (params->flags & SNDRV_PCM_HW_PARAMS_NO_PERIOD_WAKEUP); - - bits = snd_pcm_format_physical_width(runtime->format); - runtime->sample_bits = bits; - bits *= runtime->channels; - runtime->frame_bits = bits; - frames = 1; - while (bits % 8 != 0) { - bits *= 2; - frames *= 2; - } - runtime->byte_align = bits / 8; - runtime->min_align = frames; - - /* Default sw params */ - runtime->tstamp_mode = SNDRV_PCM_TSTAMP_NONE; - runtime->period_step = 1; - runtime->control->avail_min = runtime->period_size; - runtime->start_threshold = 1; - runtime->stop_threshold = runtime->buffer_size; - runtime->silence_threshold = 0; - runtime->silence_size = 0; - runtime->boundary = runtime->buffer_size; - while (runtime->boundary * 2 <= LONG_MAX - runtime->buffer_size) - runtime->boundary *= 2; - - /* clear the buffer for avoiding possible kernel info leaks */ - if (runtime->dma_area && !substream->ops->copy_user) { - size_t size = runtime->dma_bytes; - - if (runtime->info & SNDRV_PCM_INFO_MMAP) - size = PAGE_ALIGN(size); - memset(runtime->dma_area, 0, size); - } + snd_pcm_runtime_set(substream, params); snd_pcm_timer_resolution_change(substream); snd_pcm_set_state(substream, SNDRV_PCM_STATE_SETUP); -- 2.27.0
WARNING: multiple messages have this Message-ID (diff)
From: Codrin Ciubotariu <codrin.ciubotariu@microchip.com> To: <alsa-devel@alsa-project.org>, <linux-kernel@vger.kernel.org> Cc: lars@metafoo.de, kuninori.morimoto.gx@renesas.com, tiwai@suse.com, pierre-louis.bossart@linux.intel.com, lgirdwood@gmail.com, broonie@kernel.org, joe@perches.com, Codrin Ciubotariu <codrin.ciubotariu@microchip.com>, Cristian.Birsan@microchip.com, nicolas.ferre@microchip.com Subject: [RFC PATCH 4/6] ALSA: pcm: Create function for snd_pcm_runtime initialization Date: Wed, 19 May 2021 13:48:40 +0300 [thread overview] Message-ID: <20210519104842.977895-5-codrin.ciubotariu@microchip.com> (raw) In-Reply-To: <20210519104842.977895-1-codrin.ciubotariu@microchip.com> Group the setting of snd_pcm_runtime members in a separate function. This allows for code reutilization. Also, check for substream->ops before substream->ops->copy_user . Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com> --- include/sound/pcm.h | 2 + sound/core/pcm_native.c | 108 ++++++++++++++++++++++------------------ 2 files changed, 61 insertions(+), 49 deletions(-) diff --git a/include/sound/pcm.h b/include/sound/pcm.h index 2907ed2b937f..8e6bd4525c02 100644 --- a/include/sound/pcm.h +++ b/include/sound/pcm.h @@ -576,6 +576,8 @@ static inline int snd_pcm_suspend_all(struct snd_pcm *pcm) int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg); struct snd_pcm_runtime *snd_pcm_runtime_alloc(void); void snd_pcm_runtime_free(struct snd_pcm_runtime *runtime); +void snd_pcm_runtime_set(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params); int snd_pcm_open_substream(struct snd_pcm *pcm, int stream, struct file *file, struct snd_pcm_substream **rsubstream); void snd_pcm_release_substream(struct snd_pcm_substream *substream); diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index cb0164d55593..5b0e7ae2b1e7 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -658,13 +658,69 @@ static int snd_pcm_hw_params_choose(struct snd_pcm_substream *pcm, return 0; } +void snd_pcm_runtime_set(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + unsigned int bits; + snd_pcm_uframes_t frames; + + runtime->access = params_access(params); + runtime->format = params_format(params); + runtime->subformat = params_subformat(params); + runtime->channels = params_channels(params); + runtime->rate = params_rate(params); + runtime->period_size = params_period_size(params); + runtime->periods = params_periods(params); + runtime->buffer_size = params_buffer_size(params); + runtime->info = params->info; + runtime->rate_num = params->rate_num; + runtime->rate_den = params->rate_den; + runtime->no_period_wakeup = + (params->info & SNDRV_PCM_INFO_NO_PERIOD_WAKEUP) && + (params->flags & SNDRV_PCM_HW_PARAMS_NO_PERIOD_WAKEUP); + + bits = snd_pcm_format_physical_width(runtime->format); + runtime->sample_bits = bits; + bits *= runtime->channels; + runtime->frame_bits = bits; + frames = 1; + while (bits % 8 != 0) { + bits *= 2; + frames *= 2; + } + runtime->byte_align = bits / 8; + runtime->min_align = frames; + + /* Default sw params */ + runtime->tstamp_mode = SNDRV_PCM_TSTAMP_NONE; + runtime->period_step = 1; + runtime->control->avail_min = runtime->period_size; + runtime->start_threshold = 1; + runtime->stop_threshold = runtime->buffer_size; + runtime->silence_threshold = 0; + runtime->silence_size = 0; + runtime->boundary = runtime->buffer_size; + while (runtime->boundary * 2 <= LONG_MAX - runtime->buffer_size) + runtime->boundary *= 2; + + /* clear the buffer for avoiding possible kernel info leaks */ + if (runtime->dma_area && + !(substream->ops && substream->ops->copy_user)) { + size_t size = runtime->dma_bytes; + + if (runtime->info & SNDRV_PCM_INFO_MMAP) + size = PAGE_ALIGN(size); + memset(runtime->dma_area, 0, size); + } +} +EXPORT_SYMBOL(snd_pcm_runtime_set); + static int snd_pcm_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { struct snd_pcm_runtime *runtime; int err, usecs; - unsigned int bits; - snd_pcm_uframes_t frames; if (PCM_RUNTIME_CHECK(substream)) return -ENXIO; @@ -715,53 +771,7 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *substream, goto _error; } - runtime->access = params_access(params); - runtime->format = params_format(params); - runtime->subformat = params_subformat(params); - runtime->channels = params_channels(params); - runtime->rate = params_rate(params); - runtime->period_size = params_period_size(params); - runtime->periods = params_periods(params); - runtime->buffer_size = params_buffer_size(params); - runtime->info = params->info; - runtime->rate_num = params->rate_num; - runtime->rate_den = params->rate_den; - runtime->no_period_wakeup = - (params->info & SNDRV_PCM_INFO_NO_PERIOD_WAKEUP) && - (params->flags & SNDRV_PCM_HW_PARAMS_NO_PERIOD_WAKEUP); - - bits = snd_pcm_format_physical_width(runtime->format); - runtime->sample_bits = bits; - bits *= runtime->channels; - runtime->frame_bits = bits; - frames = 1; - while (bits % 8 != 0) { - bits *= 2; - frames *= 2; - } - runtime->byte_align = bits / 8; - runtime->min_align = frames; - - /* Default sw params */ - runtime->tstamp_mode = SNDRV_PCM_TSTAMP_NONE; - runtime->period_step = 1; - runtime->control->avail_min = runtime->period_size; - runtime->start_threshold = 1; - runtime->stop_threshold = runtime->buffer_size; - runtime->silence_threshold = 0; - runtime->silence_size = 0; - runtime->boundary = runtime->buffer_size; - while (runtime->boundary * 2 <= LONG_MAX - runtime->buffer_size) - runtime->boundary *= 2; - - /* clear the buffer for avoiding possible kernel info leaks */ - if (runtime->dma_area && !substream->ops->copy_user) { - size_t size = runtime->dma_bytes; - - if (runtime->info & SNDRV_PCM_INFO_MMAP) - size = PAGE_ALIGN(size); - memset(runtime->dma_area, 0, size); - } + snd_pcm_runtime_set(substream, params); snd_pcm_timer_resolution_change(substream); snd_pcm_set_state(substream, SNDRV_PCM_STATE_SETUP); -- 2.27.0
next prev parent reply other threads:[~2021-05-19 10:50 UTC|newest] Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-05-19 10:48 [RFC PATCH 0/6] soc-pcm: Add separate snd_pcm_runtime for BEs Codrin Ciubotariu 2021-05-19 10:48 ` Codrin Ciubotariu 2021-05-19 10:48 ` [RFC PATCH 1/6] ALSA: core: pcm: Create helpers to allocate/free struct snd_pcm_runtime Codrin Ciubotariu 2021-05-19 10:48 ` Codrin Ciubotariu 2021-05-19 10:48 ` [RFC PATCH 2/6] ALSA: pcm: Export constraints initialization functions Codrin Ciubotariu 2021-05-19 10:48 ` Codrin Ciubotariu 2021-05-19 10:48 ` [RFC PATCH 3/6] ALSA: pcm: Check for substream->ops before substream->ops->mmap Codrin Ciubotariu 2021-05-19 10:48 ` Codrin Ciubotariu 2021-05-19 10:48 ` Codrin Ciubotariu [this message] 2021-05-19 10:48 ` [RFC PATCH 4/6] ALSA: pcm: Create function for snd_pcm_runtime initialization Codrin Ciubotariu 2021-05-19 10:48 ` [RFC PATCH 5/6] ASoC: soc-pcm: Create new snd_pcm_runtime for BE DAIs Codrin Ciubotariu 2021-05-19 10:48 ` Codrin Ciubotariu 2021-05-19 10:48 ` [RFC PATCH 6/6] ASoC: dmaengine: Allocate buffer if substream is unmanaged Codrin Ciubotariu 2021-05-19 10:48 ` Codrin Ciubotariu 2021-05-19 14:15 ` [RFC PATCH 0/6] soc-pcm: Add separate snd_pcm_runtime for BEs Takashi Iwai 2021-05-19 14:15 ` Takashi Iwai 2021-05-19 15:08 ` Codrin.Ciubotariu 2021-05-19 15:08 ` Codrin.Ciubotariu 2021-05-19 15:41 ` Takashi Iwai 2021-05-19 15:41 ` Takashi Iwai 2021-05-20 13:59 ` Codrin.Ciubotariu 2021-05-20 13:59 ` Codrin.Ciubotariu 2021-05-21 14:26 ` Takashi Iwai 2021-05-21 14:26 ` Takashi Iwai 2021-05-24 19:33 ` Codrin.Ciubotariu 2021-05-24 19:33 ` Codrin.Ciubotariu
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210519104842.977895-5-codrin.ciubotariu@microchip.com \ --to=codrin.ciubotariu@microchip.com \ --cc=Cristian.Birsan@microchip.com \ --cc=alsa-devel@alsa-project.org \ --cc=broonie@kernel.org \ --cc=joe@perches.com \ --cc=kuninori.morimoto.gx@renesas.com \ --cc=lars@metafoo.de \ --cc=lgirdwood@gmail.com \ --cc=linux-kernel@vger.kernel.org \ --cc=nicolas.ferre@microchip.com \ --cc=perex@perex.cz \ --cc=pierre-louis.bossart@linux.intel.com \ --cc=tiwai@suse.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.