From: Joris Verhaegen <verhaegen@google.com>
To: Vinod Koul <vkoul@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
Takashi Iwai <tiwai@suse.com>,
Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>,
Charles Keepax <ckeepax@opensource.cirrus.com>,
Richard Fitzgerald <rf@opensource.cirrus.com>,
David Rhodes <david.rhodes@cirrus.com>,
Cezary Rojewski <cezary.rojewski@intel.com>,
Peter Ujfalusi <peter.ujfalusi@linux.intel.com>,
Bard Liao <yung-chuan.liao@linux.intel.com>,
Ranjani Sridharan <ranjani.sridharan@linux.intel.com>,
Kai Vehmanen <kai.vehmanen@linux.intel.com>,
Pierre-Louis Bossart <pierre-louis.bossart@linux.dev>,
Srinivas Kandagatla <srini@kernel.org>,
Daniel Baluta <daniel.baluta@nxp.com>,
Orson Zhai <orsonzhai@gmail.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Chunyan Zhang <zhang.lyra@gmail.com>,
Kunihiko Hayashi <hayashi.kunihiko@socionext.com>,
Masami Hiramatsu <mhiramat@kernel.org>
Cc: Joris Verhaegen <verhaegen@google.com>,
kernel-team@android.com, linux-sound@vger.kernel.org,
linux-kernel@vger.kernel.org, patches@opensource.cirrus.com,
linux-arm-msm@vger.kernel.org,
sound-open-firmware@alsa-project.org,
linux-arm-kernel@lists.infradead.org,
David Li <dvdli@google.com>,
Miller Liang <millerliang@google.com>
Subject: [PATCH v2 3/4] ALSA: compress_offload: Add SNDRV_COMPRESS_AVAIL64 ioctl
Date: Fri, 11 Jul 2025 10:36:29 +0100 [thread overview]
Message-ID: <20250711093636.28204-4-verhaegen@google.com> (raw)
In-Reply-To: <20250711093636.28204-1-verhaegen@google.com>
Previous patches introduced ioctl for fetching a 64-bit timestamp via
SNDRV_COMPRESS_TSTAMP64. To provide a consistent API, a 64-bit
version of SNDRV_COMPRESS_AVAIL ioctl is required.
Define a new struct snd_compr_avail64, which embeds the 64-bit
timestamp struct, and define the corresponding SNDRV_COMPRESS_AVAIL64
ioctl command in the UAPI header.
Signed-off-by: Joris Verhaegen <verhaegen@google.com>
Tested-by: Joris Verhaegen <verhaegen@google.com>
Reviewed-by: David Li <dvdli@google.com>
Reviewed-by: Miller Liang <millerliang@google.com>
---
include/uapi/sound/compress_offload.h | 11 ++++
sound/core/compress_offload.c | 88 +++++++++++++++++++++------
2 files changed, 79 insertions(+), 20 deletions(-)
diff --git a/include/uapi/sound/compress_offload.h b/include/uapi/sound/compress_offload.h
index 2758d9ee3d91..48525a87d98f 100644
--- a/include/uapi/sound/compress_offload.h
+++ b/include/uapi/sound/compress_offload.h
@@ -85,6 +85,16 @@ struct snd_compr_avail {
struct snd_compr_tstamp tstamp;
} __attribute__((packed, aligned(4)));
+/**
+ * struct snd_compr_avail64 - avail descriptor with tstamp in 64 bit format
+ * @avail: Number of bytes available in ring buffer for writing/reading
+ * @tstamp: timestamp information
+ */
+struct snd_compr_avail64 {
+ __u64 avail;
+ struct snd_compr_tstamp64 tstamp;
+} __attribute__((packed, aligned(4)));
+
enum snd_compr_direction {
SND_COMPRESS_PLAYBACK = 0,
SND_COMPRESS_CAPTURE,
@@ -232,6 +242,7 @@ struct snd_compr_task_status {
#define SNDRV_COMPRESS_TSTAMP _IOR('C', 0x20, struct snd_compr_tstamp)
#define SNDRV_COMPRESS_AVAIL _IOR('C', 0x21, struct snd_compr_avail)
#define SNDRV_COMPRESS_TSTAMP64 _IOR('C', 0x22, struct snd_compr_tstamp64)
+#define SNDRV_COMPRESS_AVAIL64 _IOR('C', 0x23, struct snd_compr_avail64)
#define SNDRV_COMPRESS_PAUSE _IO('C', 0x30)
#define SNDRV_COMPRESS_RESUME _IO('C', 0x31)
#define SNDRV_COMPRESS_START _IO('C', 0x32)
diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c
index 40c1e69961b7..78ba86e0d74f 100644
--- a/sound/core/compress_offload.c
+++ b/sound/core/compress_offload.c
@@ -257,12 +257,11 @@ static int snd_compr_update_tstamp64(struct snd_compr_stream *stream,
return 0;
}
-static size_t snd_compr_calc_avail(struct snd_compr_stream *stream,
- struct snd_compr_avail *avail)
+static size_t snd_compr_calc_avail_internal(struct snd_compr_stream *stream,
+ struct snd_compr_avail *avail32,
+ struct snd_compr_avail64 *avail64)
{
- memset(avail, 0, sizeof(*avail));
- snd_compr_update_tstamp32(stream, &avail->tstamp);
- /* Still need to return avail even if tstamp can't be filled in */
+ u64 avail;
if (stream->runtime->total_bytes_available == 0 &&
stream->runtime->state == SNDRV_PCM_STATE_SETUP &&
@@ -284,33 +283,68 @@ static size_t snd_compr_calc_avail(struct snd_compr_stream *stream,
}
}
- avail->avail = stream->runtime->total_bytes_available -
- stream->runtime->total_bytes_transferred;
+ avail = stream->runtime->total_bytes_available -
+ stream->runtime->total_bytes_transferred;
if (stream->direction == SND_COMPRESS_PLAYBACK)
- avail->avail = stream->runtime->buffer_size - avail->avail;
+ avail = stream->runtime->buffer_size - avail;
+
+ if (avail32)
+ avail32->avail = avail;
+ if (avail64)
+ avail64->avail = avail;
+
+ pr_debug("ret avail %llu as %zu\n", avail, (size_t)avail);
+ return avail;
+}
+
+static size_t snd_compr_calc_avail32(struct snd_compr_stream *stream,
+ struct snd_compr_avail *avail)
+{
+ memset(avail, 0, sizeof(*avail));
+ snd_compr_update_tstamp32(stream, &avail->tstamp);
+ /* Still need to return avail even if tstamp can't be filled in */
- pr_debug("ret avail as %llu\n", avail->avail);
- return avail->avail;
+ return snd_compr_calc_avail_internal(stream, avail, NULL);
+}
+
+static size_t snd_compr_calc_avail64(struct snd_compr_stream *stream,
+ struct snd_compr_avail64 *avail)
+{
+ memset(avail, 0, sizeof(*avail));
+ snd_compr_update_tstamp64(stream, &avail->tstamp);
+ /* Still need to return avail even if tstamp can't be filled in */
+
+ return snd_compr_calc_avail_internal(stream, NULL, avail);
}
static inline size_t snd_compr_get_avail(struct snd_compr_stream *stream)
{
struct snd_compr_avail avail;
- return snd_compr_calc_avail(stream, &avail);
+ return snd_compr_calc_avail32(stream, &avail);
}
-static int
-snd_compr_ioctl_avail(struct snd_compr_stream *stream, unsigned long arg)
+static int snd_compr_ioctl_avail(struct snd_compr_stream *stream,
+ unsigned long arg, bool is_64bit)
{
- struct snd_compr_avail ioctl_avail;
- size_t avail;
+ union {
+ struct snd_compr_avail avail32;
+ struct snd_compr_avail64 avail64;
+ } ioctrl_avail_u;
+ size_t avail, ioctrl_avail_size;
if (stream->direction == SND_COMPRESS_ACCEL)
return -EBADFD;
- avail = snd_compr_calc_avail(stream, &ioctl_avail);
- ioctl_avail.avail = avail;
+ if (is_64bit) {
+ avail = snd_compr_calc_avail64(stream, &ioctrl_avail_u.avail64);
+ ioctrl_avail_u.avail64.avail = avail;
+ ioctrl_avail_size = sizeof(ioctrl_avail_u.avail64);
+ } else {
+ avail = snd_compr_calc_avail32(stream, &ioctrl_avail_u.avail32);
+ ioctrl_avail_u.avail32.avail = avail;
+ ioctrl_avail_size = sizeof(ioctrl_avail_u.avail32);
+ }
switch (stream->runtime->state) {
case SNDRV_PCM_STATE_OPEN:
@@ -321,12 +355,24 @@ snd_compr_ioctl_avail(struct snd_compr_stream *stream, unsigned long arg)
break;
}
- if (copy_to_user((__u64 __user *)arg,
- &ioctl_avail, sizeof(ioctl_avail)))
+ if (copy_to_user((__u64 __user *)arg, &ioctrl_avail_u,
+ ioctrl_avail_size))
return -EFAULT;
return 0;
}
+static int snd_compr_ioctl_avail32(struct snd_compr_stream *stream,
+ unsigned long arg)
+{
+ return snd_compr_ioctl_avail(stream, arg, false);
+}
+
+static int snd_compr_ioctl_avail64(struct snd_compr_stream *stream,
+ unsigned long arg)
+{
+ return snd_compr_ioctl_avail(stream, arg, true);
+}
+
static int snd_compr_write_data(struct snd_compr_stream *stream,
const char __user *buf, size_t count)
{
@@ -1393,7 +1439,9 @@ static long snd_compr_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
case _IOC_NR(SNDRV_COMPRESS_TSTAMP64):
return snd_compr_tstamp64(stream, arg);
case _IOC_NR(SNDRV_COMPRESS_AVAIL):
- return snd_compr_ioctl_avail(stream, arg);
+ return snd_compr_ioctl_avail32(stream, arg);
+ case _IOC_NR(SNDRV_COMPRESS_AVAIL64):
+ return snd_compr_ioctl_avail64(stream, arg);
case _IOC_NR(SNDRV_COMPRESS_PAUSE):
return snd_compr_pause(stream);
case _IOC_NR(SNDRV_COMPRESS_RESUME):
--
2.50.0.727.gbf7dc18ff4-goog
next prev parent reply other threads:[~2025-07-11 10:24 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-11 9:36 [PATCH v2 0/4] ALSA: compress_offload: Add 64-bit safe timestamp API Joris Verhaegen
2025-07-11 9:36 ` [PATCH v2 1/4] ALSA: compress_offload: Add 64-bit safe timestamp infrastructure Joris Verhaegen
2025-07-11 9:36 ` [PATCH v2 2/4] ALSA: compress_offload: Add SNDRV_COMPRESS_TSTAMP64 ioctl Joris Verhaegen
2025-07-11 12:45 ` Takashi Iwai
2025-07-11 9:36 ` Joris Verhaegen [this message]
2025-07-11 9:36 ` [PATCH v2 4/4] ASoC: codecs: Implement 64-bit pointer operation Joris Verhaegen
2025-07-11 10:10 ` Richard Fitzgerald
2025-07-15 13:07 ` kernel test robot
2025-07-11 11:56 ` [PATCH v2 0/4] ALSA: compress_offload: Add 64-bit safe timestamp API Charles Keepax
2025-07-11 12:41 ` Takashi Iwai
2025-07-11 13:00 ` Takashi Iwai
2025-07-15 12:39 ` Vinod Koul
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=20250711093636.28204-4-verhaegen@google.com \
--to=verhaegen@google.com \
--cc=baolin.wang@linux.alibaba.com \
--cc=broonie@kernel.org \
--cc=cezary.rojewski@intel.com \
--cc=ckeepax@opensource.cirrus.com \
--cc=daniel.baluta@nxp.com \
--cc=david.rhodes@cirrus.com \
--cc=dvdli@google.com \
--cc=hayashi.kunihiko@socionext.com \
--cc=kai.vehmanen@linux.intel.com \
--cc=kernel-team@android.com \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=millerliang@google.com \
--cc=orsonzhai@gmail.com \
--cc=patches@opensource.cirrus.com \
--cc=perex@perex.cz \
--cc=peter.ujfalusi@linux.intel.com \
--cc=pierre-louis.bossart@linux.dev \
--cc=ranjani.sridharan@linux.intel.com \
--cc=rf@opensource.cirrus.com \
--cc=sound-open-firmware@alsa-project.org \
--cc=srini@kernel.org \
--cc=tiwai@suse.com \
--cc=vkoul@kernel.org \
--cc=yung-chuan.liao@linux.intel.com \
--cc=zhang.lyra@gmail.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 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.