diff mbox series

[alsa-lib,v2,03/10] rawmidi: Add UMP ioctl support

Message ID 20230523122247.11744-4-tiwai@suse.de
State New
Headers show
Series Add MIDI 2.0 support | expand

Commit Message

Takashi Iwai May 23, 2023, 12:22 p.m. UTC
Just implement internal callbacks for two new ioctls for UMP
(ump_endpoint_info and ump_block_info).  No public API functions are
added yet here.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 src/rawmidi/rawmidi.c       | 19 +++++++++++++++++++
 src/rawmidi/rawmidi_hw.c    | 26 +++++++++++++++++++++++++-
 src/rawmidi/rawmidi_local.h |  5 +++++
 3 files changed, 49 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/src/rawmidi/rawmidi.c b/src/rawmidi/rawmidi.c
index 570e06755456..8dca9312c6d9 100644
--- a/src/rawmidi/rawmidi.c
+++ b/src/rawmidi/rawmidi.c
@@ -1120,3 +1120,22 @@  ssize_t snd_rawmidi_tread(snd_rawmidi_t *rawmidi, struct timespec *tstamp, void
 		return -ENOTSUP;
 	return (rawmidi->ops->tread)(rawmidi, tstamp, buffer, size);
 }
+
+#ifndef DOXYGEN
+/*
+ * internal API functions for obtaining UMP info from rawmidi instance
+ */
+int _snd_rawmidi_ump_endpoint_info(snd_rawmidi_t *rmidi, void *info)
+{
+	if (!rmidi->ops->ump_endpoint_info)
+		return -ENXIO;
+	return rmidi->ops->ump_endpoint_info(rmidi, info);
+}
+
+int _snd_rawmidi_ump_block_info(snd_rawmidi_t *rmidi, void *info)
+{
+	if (!rmidi->ops->ump_block_info)
+		return -ENXIO;
+	return rmidi->ops->ump_block_info(rmidi, info);
+}
+#endif /* DOXYGEN */
diff --git a/src/rawmidi/rawmidi_hw.c b/src/rawmidi/rawmidi_hw.c
index e5bb3ee3b31c..69e5e02f1d6a 100644
--- a/src/rawmidi/rawmidi_hw.c
+++ b/src/rawmidi/rawmidi_hw.c
@@ -272,6 +272,28 @@  static ssize_t snd_rawmidi_hw_tread(snd_rawmidi_t *rmidi, struct timespec *tstam
 	return ret + result;
 }
 
+static int snd_rawmidi_hw_ump_endpoint_info(snd_rawmidi_t *rmidi, void *buf)
+{
+	snd_rawmidi_hw_t *hw = rmidi->private_data;
+
+	if (rmidi->version < SNDRV_PROTOCOL_VERSION(2, 0, 3))
+		return -ENXIO;
+	if (ioctl(hw->fd, SNDRV_UMP_IOCTL_ENDPOINT_INFO, buf) < 0)
+		return -errno;
+	return 0;
+}
+
+static int snd_rawmidi_hw_ump_block_info(snd_rawmidi_t *rmidi, void *buf)
+{
+	snd_rawmidi_hw_t *hw = rmidi->private_data;
+
+	if (rmidi->version < SNDRV_PROTOCOL_VERSION(2, 0, 3))
+		return -ENXIO;
+	if (ioctl(hw->fd, SNDRV_UMP_IOCTL_BLOCK_INFO, buf) < 0)
+		return -errno;
+	return 0;
+}
+
 static const snd_rawmidi_ops_t snd_rawmidi_hw_ops = {
 	.close = snd_rawmidi_hw_close,
 	.nonblock = snd_rawmidi_hw_nonblock,
@@ -282,7 +304,9 @@  static const snd_rawmidi_ops_t snd_rawmidi_hw_ops = {
 	.drain = snd_rawmidi_hw_drain,
 	.write = snd_rawmidi_hw_write,
 	.read = snd_rawmidi_hw_read,
-	.tread = snd_rawmidi_hw_tread
+	.tread = snd_rawmidi_hw_tread,
+	.ump_endpoint_info = snd_rawmidi_hw_ump_endpoint_info,
+	.ump_block_info = snd_rawmidi_hw_ump_block_info,
 };
 
 
diff --git a/src/rawmidi/rawmidi_local.h b/src/rawmidi/rawmidi_local.h
index 4a88e7e4a5ba..7025542f6774 100644
--- a/src/rawmidi/rawmidi_local.h
+++ b/src/rawmidi/rawmidi_local.h
@@ -35,6 +35,8 @@  typedef struct {
 	ssize_t (*write)(snd_rawmidi_t *rawmidi, const void *buffer, size_t size);
 	ssize_t (*read)(snd_rawmidi_t *rawmidi, void *buffer, size_t size);
 	ssize_t (*tread)(snd_rawmidi_t *rawmidi, struct timespec *tstamp, void *buffer, size_t size);
+	int (*ump_endpoint_info)(snd_rawmidi_t *rmidi, void *buf);
+	int (*ump_block_info)(snd_rawmidi_t *rmidi, void *buf);
 } snd_rawmidi_ops_t;
 
 struct _snd_rawmidi {
@@ -62,3 +64,6 @@  int snd_rawmidi_virtual_open(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp,
 			     int merge, int mode);
 
 #define snd_rawmidi_conf_generic_id(id)	_snd_conf_generic_id(id)
+
+int _snd_rawmidi_ump_endpoint_info(snd_rawmidi_t *rmidi, void *info);
+int _snd_rawmidi_ump_block_info(snd_rawmidi_t *rmidi, void *info);