From: Cezary Rojewski <cezary.rojewski@intel.com>
To: broonie@kernel.org
Cc: alsa-devel@alsa-project.org, linux-sound@vger.kernel.org,
tiwai@suse.com, perex@perex.cz,
amadeuszx.slawinski@linux.intel.com, hdegoede@redhat.com,
Cezary Rojewski <cezary.rojewski@intel.com>
Subject: [PATCH 13/13] ASoC: Intel: avs: Rule invalid buffer and period sizes out
Date: Fri, 5 Apr 2024 11:09:29 +0200 [thread overview]
Message-ID: <20240405090929.1184068-14-cezary.rojewski@intel.com> (raw)
In-Reply-To: <20240405090929.1184068-1-cezary.rojewski@intel.com>
While HDAudio controller supports buffer packets up to 128 bytes low,
audio format shall be taken into consideration when calculating buffer
and period sizes to avoid undesired xruns.
As *_size in ALSA terms means frames (channels times bit-depth-bytes),
hw_rules can calculate minimal buffer and period sizes solely from
sample rate and the number of milliseconds commonly used on the
AudioDSP firmware side.
Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
---
sound/soc/intel/avs/pcm.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/sound/soc/intel/avs/pcm.c b/sound/soc/intel/avs/pcm.c
index 405de1d58178..77a7e8f93951 100644
--- a/sound/soc/intel/avs/pcm.c
+++ b/sound/soc/intel/avs/pcm.c
@@ -457,6 +457,26 @@ static const struct snd_pcm_hw_constraint_list hw_rates = {
const struct snd_soc_dai_ops avs_dai_fe_ops;
+static int hw_rule_param_size(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule)
+{
+ struct snd_interval *interval = hw_param_interval(params, rule->var);
+ struct snd_interval to;
+
+ snd_interval_any(&to);
+ to.integer = interval->integer;
+ to.max = interval->max;
+ /*
+ * Commonly 2ms buffer size is used in HDA scenarios whereas 4ms is used
+ * when streaming through GPDMA. Align to the latter to account for both.
+ */
+ to.min = params_rate(params) / 1000 * 4;
+
+ if (rule->var == SNDRV_PCM_HW_PARAM_PERIOD_SIZE)
+ to.min /= params_periods(params);
+
+ return snd_interval_refine(interval, &to);
+}
+
static int avs_dai_fe_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
{
struct snd_pcm_runtime *runtime = substream->runtime;
@@ -492,6 +512,14 @@ static int avs_dai_fe_startup(struct snd_pcm_substream *substream, struct snd_so
if (ret < 0)
goto err;
+ /* Adjust buffer and period size based on the audio format. */
+ snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, hw_rule_param_size, NULL,
+ SNDRV_PCM_HW_PARAM_FORMAT, SNDRV_PCM_HW_PARAM_CHANNELS,
+ SNDRV_PCM_HW_PARAM_RATE, -1);
+ snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, hw_rule_param_size, NULL,
+ SNDRV_PCM_HW_PARAM_FORMAT, SNDRV_PCM_HW_PARAM_CHANNELS,
+ SNDRV_PCM_HW_PARAM_RATE, -1);
+
snd_pcm_set_sync(substream);
dev_dbg(dai->dev, "%s fe STARTUP tag %d str %p",
--
2.25.1
next prev parent reply other threads:[~2024-04-05 9:13 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-05 9:09 [PATCH 00/13] ASoC: Intel: avs: Fixes and cleanups for 6.10 Cezary Rojewski
2024-04-05 9:09 ` [PATCH 01/13] ASoC: Intel: avs: Restore stream decoupling on prepare Cezary Rojewski
2024-04-05 9:09 ` [PATCH 02/13] ASoC: Intel: avs: Fix debug-slot offset calculation Cezary Rojewski
2024-04-05 9:09 ` [PATCH 03/13] ASoC: Intel: avs: Silence false-positive memcpy() warnings Cezary Rojewski
2024-04-05 9:09 ` [PATCH 04/13] ASoC: Intel: avs: Fix config_length for config-less copiers Cezary Rojewski
2024-04-05 9:09 ` [PATCH 05/13] ASoC: Intel: avs: Fix ASRC module initialization Cezary Rojewski
2024-04-05 9:09 ` [PATCH 06/13] ASoC: Intel: avs: Replace risky functions with safer variants Cezary Rojewski
2024-04-05 9:09 ` [PATCH 07/13] ASoC: Intel: avs: Fix potential integer overflow Cezary Rojewski
2024-04-05 9:09 ` [PATCH 08/13] ASoC: Intel: avs: Test result of avs_get_module_entry() Cezary Rojewski
2024-04-05 9:09 ` [PATCH 09/13] ASoC: Intel: avs: Remove dead code Cezary Rojewski
2024-04-05 9:09 ` [PATCH 10/13] ASoC: Intel: avs: Wake from D0ix when starting streaming Cezary Rojewski
2024-04-05 9:09 ` [PATCH 11/13] ASoC: Intel: avs: Init debugfs before booting firmware Cezary Rojewski
2024-04-05 9:09 ` [PATCH 12/13] ASoC: Intel: avs: Add assert_static to guarantee ABI sizes Cezary Rojewski
2024-04-05 9:09 ` Cezary Rojewski [this message]
2024-04-05 23:20 ` [PATCH 00/13] ASoC: Intel: avs: Fixes and cleanups for 6.10 Mark Brown
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=20240405090929.1184068-14-cezary.rojewski@intel.com \
--to=cezary.rojewski@intel.com \
--cc=alsa-devel@alsa-project.org \
--cc=amadeuszx.slawinski@linux.intel.com \
--cc=broonie@kernel.org \
--cc=hdegoede@redhat.com \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).