From nobody Tue Oct 7 10:15:22 2025 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 11DB927CCEB for ; Fri, 11 Jul 2025 09:37:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752226651; cv=none; b=jnkOtNCFmTp0PedyhL+RBii07KBrzTJePAhc1U6YNmXR3vbY+tsDztdtfNyCxWvs2+5fXI1H0iuHyIsQURAP/Bt+VMtptTHkSnz0ayP+W3BVSxO14co02DRudzfGEU9VgFao84fOj8jJiAQHr0h3f4wxo8bQ7En9sTaReoqBM3s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752226651; c=relaxed/simple; bh=M1dujzqlrViBX5eAVMXNVdNoKPO5BUR0diMllLgPzjc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=JsnBFjaQZpqv9RXZm+1xIGaqSAOwfOWFkCAGdHlxbw7pLSSJyzdTkdB+6lye3CTZ5cqfi4fiu1t/UiUPjlqZzTxV9Ob8qDFpZI3TFRlkqtYZdStiQ9KkY+ckT/0TLgEAxbdXRPn8Bm4q3g0xPXflol0hyn7WdH4YfupnI1zw6pw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--verhaegen.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ncTRiXyH; arc=none smtp.client-ip=209.85.221.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--verhaegen.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ncTRiXyH" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-3a4eb6fcd88so1336237f8f.1 for ; Fri, 11 Jul 2025 02:37:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752226648; x=1752831448; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=WywIvLAv4IB9b6g8T96e6Qsk8BIfajnf2gbyC1P4AZo=; b=ncTRiXyH73I23H8AxSM5gLuUsBLk5YgNBE9QIYBtHQOjs5Dbt5ya03CH/Pucbmcy2+ uTWjNXMTQFwUfkpI7wgUcLm0BUfhTpAHEpFH3ANNky4KbfTgs/P2Tkj1SLeiYRYX9/tM LgSU5fHoZwLaz6Vkk1foZ7Cbdh6iz5mPNeQLSHqCMFf5vX6RMuzMY1vtn1k1c5Yl1UBA Ith/8IS1KKCPjApt0t+7rifg0YoSbRa3NXQIA3YtTgcfaKpoRnNHkzGXjW97mfRGSLf8 KkQCfymQUhsaTAmbFFY0KUwKPDQWej8c8QCKCSIBm9N7ssdmtkBfqLtV7kVmQqP90seL MWTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752226648; x=1752831448; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WywIvLAv4IB9b6g8T96e6Qsk8BIfajnf2gbyC1P4AZo=; b=UNndNYujYjoqFd5Bwee5G99T2g8c1QqxZ9rmaXW/wOUXpUPzdFToohEybACbCNq3o1 wRvvQtPxVZIwFDk2rUQORQwslxGsZh5/l9qux5j3dmELymvSfzdRD+WbX/JHPMpznHlQ a0vINRIUqGjXYxymho3HexWiG9DO0KNwm8+kXuCeBSantJKGfscweuXekOXmUk771XZ+ XfA8PX1z5GR2xgCLzUSe3dlrhfcvaIdFZo+4J1AIIobgg5KrzsEzsDxItQq1lOhv3zwS k0ADWGjwdvXFB9+AofRzmRu6mXtEw6BBqErC6aMAKoihZWRMjD/UZnEOcpf5xhgnS/5w BNPQ== X-Forwarded-Encrypted: i=1; AJvYcCUM4tsfzo8LBn9M4H1lQpL4qa9uuRYtkehDNMfBbSOMnmbcCYagfnjI78aD7/73+QIEaJxbtHpL78+WuMg=@vger.kernel.org X-Gm-Message-State: AOJu0YxVIbvdjM0XQy9zAtyNronsd7I1zmq9pHSsf3QuhlVXzjt85jBT E+d6AZ2P7nuhmb8IX+YmnsFxKYs3h+G2tQEgBaFCsX2NkcIbP2L611J3WJRjLpDpnUlCnkFXFAD QMqW9QZhi6LhuTha+Ag== X-Google-Smtp-Source: AGHT+IEmEE9dNv4iiepa6OEju/MJzJFG2hiRPgxw7iu3SiyhF7OruOUvPAPmCsUrMtbUZ8nFQRE0HzcU37l0TXw= X-Received: from wmbea14.prod.google.com ([2002:a05:600c:674e:b0:43d:9035:df36]) (user=verhaegen job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:18a3:b0:3a8:6262:6ef5 with SMTP id ffacd0b85a97d-3b5f2db15bemr1466223f8f.10.1752226648115; Fri, 11 Jul 2025 02:37:28 -0700 (PDT) Date: Fri, 11 Jul 2025 10:36:29 +0100 In-Reply-To: <20250711093636.28204-1-verhaegen@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250711093636.28204-1-verhaegen@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250711093636.28204-4-verhaegen@google.com> Subject: [PATCH v2 3/4] ALSA: compress_offload: Add SNDRV_COMPRESS_AVAIL64 ioctl From: Joris Verhaegen To: Vinod Koul , Jaroslav Kysela , Takashi Iwai , Liam Girdwood , Mark Brown , Charles Keepax , Richard Fitzgerald , David Rhodes , Cezary Rojewski , Peter Ujfalusi , Bard Liao , Ranjani Sridharan , Kai Vehmanen , Pierre-Louis Bossart , Srinivas Kandagatla , Daniel Baluta , Orson Zhai , Baolin Wang , Chunyan Zhang , Kunihiko Hayashi , Masami Hiramatsu Cc: Joris Verhaegen , 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 , Miller Liang Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Tested-by: Joris Verhaegen Reviewed-by: David Li Reviewed-by: Miller Liang --- 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/com= press_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))); =20 +/** + * 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 =3D 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; } =20 -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 *strea= m, + 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; =20 if (stream->runtime->total_bytes_available =3D=3D 0 && stream->runtime->state =3D=3D SNDRV_PCM_STATE_SETUP && @@ -284,33 +283,68 @@ static size_t snd_compr_calc_avail(struct snd_compr_s= tream *stream, } } =20 - avail->avail =3D stream->runtime->total_bytes_available - - stream->runtime->total_bytes_transferred; + avail =3D stream->runtime->total_bytes_available - + stream->runtime->total_bytes_transferred; if (stream->direction =3D=3D SND_COMPRESS_PLAYBACK) - avail->avail =3D stream->runtime->buffer_size - avail->avail; + avail =3D stream->runtime->buffer_size - avail; + + if (avail32) + avail32->avail =3D avail; + if (avail64) + avail64->avail =3D 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 */ =20 - 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); } =20 static inline size_t snd_compr_get_avail(struct snd_compr_stream *stream) { struct snd_compr_avail avail; =20 - return snd_compr_calc_avail(stream, &avail); + return snd_compr_calc_avail32(stream, &avail); } =20 -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; =20 if (stream->direction =3D=3D SND_COMPRESS_ACCEL) return -EBADFD; =20 - avail =3D snd_compr_calc_avail(stream, &ioctl_avail); - ioctl_avail.avail =3D avail; + if (is_64bit) { + avail =3D snd_compr_calc_avail64(stream, &ioctrl_avail_u.avail64); + ioctrl_avail_u.avail64.avail =3D avail; + ioctrl_avail_size =3D sizeof(ioctrl_avail_u.avail64); + } else { + avail =3D snd_compr_calc_avail32(stream, &ioctrl_avail_u.avail32); + ioctrl_avail_u.avail32.avail =3D avail; + ioctrl_avail_size =3D sizeof(ioctrl_avail_u.avail32); + } =20 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; } =20 - 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; } =20 +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): --=20 2.50.0.727.gbf7dc18ff4-goog