ALSA: Add MIDI 2.0 support
Subsystems (4)
v2 cover ALSA: Add MIDI 2.0 support
Hi,
this is a revised patch set for adding the support of MIDI 2.0 functionality. Only a few minor updates since v1 as below:
* Bump CTL protocol version to 2.0.9
* Add two more ioctls for control API to receive UMP EP and block info
* Minor compile warning fixes
* Documentation fix and addition of two new ioctls
* Put acks
The latest code is found in topic/midi20 branch of sound git tree.
And below is the cover letter of v1, which is still valid:
Hi,
this is a (largish) patch set for adding the support of MIDI 2.0 functionality, mainly targeted for USB devices. MIDI 2.0 is a complete overhaul of the 40-years old MIDI 1.0. Unlike MIDI 1.0 byte stream, MIDI 2.0 uses packets in 32bit words for Universal MIDI Packet (UMP) protocol. It supports both MIDI 1.0 commands for compatibility and the extended MIDI 2.0 commands for higher resolutions and more functions.
For supporting the UMP, the patch set extends the existing ALSA rawmidi and sequencer interfaces, and adds the USB MIDI 2.0 support to the standard USB-audio driver.
The rawmidi for UMP has a different device name (/dev/snd/umpC*D*) and it reads/writes UMP packet data in 32bit CPU-native endianness. For the old MIDI 1.0 applications, the legacy rawmidi interface is provided, too.
As default, USB-audio driver will take the alternate setting for MIDI 2.0 interface, and the compatibility with MIDI 1.0 is provided via the rawmidi common layer. However, user may let the driver falling back to the old MIDI 1.0 interface by a module option, too.
A UMP-capable rawmidi device can create the corresponding ALSA sequencer client(s) to support the UMP Endpoint and UMP Group connections. As a nature of ALSA sequencer, arbitrary connections between clients/ports are allowed, and the ALSA sequencer core performs the automatic conversions for the connections between a new UMP sequencer client and a legacy MIDI 1.0 sequencer client. It allows the existing application to use MIDI 2.0 devices without changes.
The MIDI-CI, which is another major extension in MIDI 2.0, isn't covered by this patch set. It would be implemented rather in user-space.
Roughly speaking, the first half of this patch set is for extending the rawmidi and USB-audio, and the second half is for extending the ALSA sequencer interface.
The patch set is based on 6.4-rc2 kernel, but all patches can be cleanly applicable on 6.2 and 6.3 kernels, too (while 6.1 and older kernels would need minor adjustment for uapi header changes).
The updates for alsa-lib and alsa-utils will follow shortly later.
The author thanks members of MIDI Association OS/API Working Group, especially Andrew Mee, for great helps for the initial design and debugging / testing the drivers.
Takashi
---
Takashi Iwai (37):
ALSA: rawmidi: Pass rawmidi directly to snd_rawmidi_kernel_open()
ALSA: rawmidi: Add ioctl callback to snd_rawmidi_global_ops
ALSA: rawmidi: UMP support
ALSA: rawmidi: Skip UMP devices at SNDRV_CTL_IOCTL_RAWMIDI_NEXT_DEVICE
ALSA: ump: Add ioctls to inquiry UMP EP and Block info via control API
ALSA: ump: Additional proc output
ALSA: usb-audio: Manage number of rawmidis globally
ALSA: usb-audio: Define USB MIDI 2.0 specs
ALSA: usb-audio: USB MIDI 2.0 UMP support
ALSA: usb-audio: Get UMP EP name string from USB interface
ALSA: usb-audio: Trim superfluous "MIDI" suffix from UMP EP name
ALSA: usb-audio: Create UMP blocks from USB MIDI GTBs
ALSA: ump: Redirect rawmidi substream access via own helpers
ALSA: ump: Add legacy raw MIDI support
ALSA: usb-audio: Enable the legacy raw MIDI support
ALSA: usb-audio: Inform inconsistent protocols in GTBs
ALSA: seq: Clear padded bytes at expanding events
ALSA: seq: Add snd_seq_expand_var_event_at() helper
ALSA: seq: Treat snd_seq_client object directly in client drivers
ALSA: seq: Drop dead code for the old broadcast support
ALSA: seq: Check the conflicting port at port creation
ALSA: seq: Check validity before creating a port object
ALSA: seq: Prohibit creating ports with special numbers
ALSA: seq: Introduce SNDRV_SEQ_IOCTL_USER_PVERSION ioctl
ALSA: seq: Add UMP support
ALSA: seq: Add port inactive flag
ALSA: seq: Support MIDI 2.0 UMP Endpoint port
ALSA: seq: Add port direction to snd_seq_port_info
ALSA: seq: Add UMP group number to snd_seq_port_info
ALSA: seq: Automatic conversion of UMP events
ALSA: seq: Allow suppressing UMP conversions
ALSA: seq: Bind UMP device
ALSA: seq: ump: Create UMP Endpoint port for broadcast
ALSA: seq: Add ioctls for client UMP info query and setup
ALSA: seq: Print UMP Endpoint and Block information in proc outputs
ALSA: seq: Add UMP group filter
ALSA: docs: Add MIDI 2.0 documentation
Documentation/sound/designs/index.rst | 1 + Documentation/sound/designs/midi-2.0.rst | 351 +++++++ include/linux/usb/midi-v2.h | 94 ++ include/sound/asequencer.h | 4 + include/sound/rawmidi.h | 15 +- include/sound/seq_device.h | 1 + include/sound/seq_kernel.h | 10 + include/sound/ump.h | 175 ++++ include/sound/ump_msg.h | 540 ++++++++++ include/uapi/sound/asequencer.h | 83 +- include/uapi/sound/asound.h | 62 +- sound/core/Kconfig | 13 + sound/core/Makefile | 3 + sound/core/rawmidi.c | 264 +++-- sound/core/rawmidi_compat.c | 4 + sound/core/seq/Kconfig | 14 + sound/core/seq/Makefile | 3 + sound/core/seq/seq_clientmgr.c | 577 +++++++---- sound/core/seq/seq_clientmgr.h | 27 +- sound/core/seq/seq_compat.c | 3 + sound/core/seq/seq_dummy.c | 9 + sound/core/seq/seq_memory.c | 98 +- sound/core/seq/seq_memory.h | 19 +- sound/core/seq/seq_midi.c | 12 +- sound/core/seq/seq_ports.c | 47 +- sound/core/seq/seq_ports.h | 23 +- sound/core/seq/seq_ump_client.c | 464 +++++++++ sound/core/seq/seq_ump_convert.c | 1203 ++++++++++++++++++++++ sound/core/seq/seq_ump_convert.h | 22 + sound/core/seq/seq_virmidi.c | 1 + sound/core/ump.c | 668 ++++++++++++ sound/core/ump_convert.c | 520 ++++++++++ sound/core/ump_convert.h | 43 + sound/usb/Kconfig | 11 + sound/usb/Makefile | 1 + sound/usb/card.c | 12 +- sound/usb/midi.c | 7 +- sound/usb/midi.h | 5 +- sound/usb/midi2.c | 1190 +++++++++++++++++++++ sound/usb/midi2.h | 33 + sound/usb/quirks.c | 8 +- sound/usb/usbaudio.h | 2 + 42 files changed, 6306 insertions(+), 336 deletions(-) create mode 100644 Documentation/sound/designs/midi-2.0.rst create mode 100644 include/linux/usb/midi-v2.h create mode 100644 include/sound/ump.h create mode 100644 include/sound/ump_msg.h create mode 100644 sound/core/seq/seq_ump_client.c create mode 100644 sound/core/seq/seq_ump_convert.c create mode 100644 sound/core/seq/seq_ump_convert.h create mode 100644 sound/core/ump.c create mode 100644 sound/core/ump_convert.c create mode 100644 sound/core/ump_convert.h create mode 100644 sound/usb/midi2.c create mode 100644 sound/usb/midi2.h
Signature · 1 line
2.35.3
PATCH v2 1/37 ALSA: rawmidi: Pass rawmidi directly to snd_rawmidi_kernel_open()
snd_rawmidi_kernel_open() is used only internally from ALSA sequencer, so far, and parsing the card / device matching table at each open is redundant, as each sequencer client already gets the rawmidi object beforehand.
This patch optimizes the path by passing the rawmidi object directly at snd_rawmidi_kernel_open(). This is also a preparation for the upcoming UMP rawmidi I/O support.
--- include/sound/rawmidi.h | 2 +- sound/core/rawmidi.c | 17 ++++------------- sound/core/seq/seq_midi.c | 8 ++++---- 3 files changed, 9 insertions(+), 18 deletions(-)
include/sound/rawmidi.h +1 -1
@@ -161,7 +161,7 @@ int snd_rawmidi_proceed(struct snd_rawmidi_substream *substream);/* main midi functions */ int snd_rawmidi_info_select (struct snd_card *card,struct snd_rawmidi_info *info); -int snd_rawmidi_kernel_open (struct snd_card *card,int device,int subdevice, +int snd_rawmidi_kernel_open (struct snd_rawmidi *rmidi,int subdevice,int mode,struct snd_rawmidi_file *rfile);int snd_rawmidi_kernel_release (struct snd_rawmidi_file *rfile); int snd_rawmidi_output_params(struct snd_rawmidi_substream *substream,
sound/core/rawmidi.c +4 -13
@@ -406,24 +406,15 @@ static int rawmidi_open_priv(struct snd_rawmidi *rmidi, int subdevice, int mode, }/* called from sound/core/seq/seq_midi.c */ -int snd_rawmidi_kernel_open (struct snd_card *card,int device,int subdevice, +int snd_rawmidi_kernel_open (struct snd_rawmidi *rmidi,int subdevice,int mode,struct snd_rawmidi_file *rfile) { -struct snd_rawmidi *rmidi; -int err =0 ; +int err;if (snd_BUG_ON (!rfile))return -EINVAL ; - -mutex_lock (®ister_mutex); - rmidi =snd_rawmidi_search (card, device); -if (!rmidi) - err = -ENODEV ; -else if (!try_module_get (rmidi->card->module)) - err = -ENXIO ; -mutex_unlock (®ister_mutex); -if (err <0 ) -return err; +if (!try_module_get (rmidi->card->module)) +return -ENXIO ;mutex_lock (&rmidi->open_mutex); err =rawmidi_open_priv (rmidi, subdevice, mode, rfile);
sound/core/seq/seq_midi.c +4 -4
@@ -38,6 +38,7 @@ MODULE_PARM_DESC(input_buffer_size, "Input buffer size in bytes.");/* data for this midi synth driver */ struct seq_midisynth {struct snd_card *card; +struct snd_rawmidi *rmidi;int device;int subdevice;struct snd_rawmidi_file input_rfile;
@@ -168,8 +169,7 @@ static int midisynth_subscribe(void *private_data, struct snd_seq_port_subscribestruct snd_rawmidi_params params;/* open midi port */ - err =snd_rawmidi_kernel_open (msynth->card, msynth->device, - msynth->subdevice, + err =snd_rawmidi_kernel_open (msynth->rmidi, msynth->subdevice,SNDRV_RAWMIDI_LFLG_INPUT , &msynth->input_rfile);if (err <0 ) {
@@ -212,8 +212,7 @@ static int midisynth_use(void *private_data, struct snd_seq_port_subscribe *infostruct snd_rawmidi_params params;/* open midi port */ - err =snd_rawmidi_kernel_open (msynth->card, msynth->device, - msynth->subdevice, + err =snd_rawmidi_kernel_open (msynth->rmidi, msynth->subdevice,SNDRV_RAWMIDI_LFLG_OUTPUT , &msynth->output_rfile);if (err <0 ) {
@@ -328,6 +327,7 @@ snd_seq_midisynth_probe(struct device *_dev)for (p =0 ; p < ports; p++) { ms = &msynth[p]; + ms->rmidi = rmidi;if (snd_seq_midisynth_new (ms, card, device, p) <0 ) goto __nomem;
Signature · 1 line
2.35.3
PATCH v2 2/37 ALSA: rawmidi: Add ioctl callback to snd_rawmidi_global_ops
In reply to Takashi IwaiA new callback, ioctl, is added to snd_rawmidi_global_ops for allowing the driver to deal with the own ioctls. This is another preparation patch for the upcoming UMP support.
--- include/sound/rawmidi.h | 2 ++ sound/core/rawmidi.c | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-)
include/sound/rawmidi.h +2 -0
@@ -47,6 +47,8 @@ struct snd_rawmidi_global_ops {int (*dev_unregister) (struct snd_rawmidi * rmidi);void (*get_port_info)(struct snd_rawmidi *rmidi,int number,struct snd_seq_port_info *info); +long (*ioctl)(struct snd_rawmidi *rmidi,unsigned int cmd, +void __user *argp); };struct snd_rawmidi_runtime {
sound/core/rawmidi.c +5 -2
@@ -893,6 +893,7 @@ static int snd_rawmidi_ioctl_status64(struct snd_rawmidi_file *rfile,static long snd_rawmidi_ioctl (struct file *file,unsigned int cmd,unsigned long arg) {struct snd_rawmidi_file *rfile; +struct snd_rawmidi *rmidi;void __user *argp = (void __user *)arg; rfile = file->private_data;
@@ -984,8 +985,10 @@ static long snd_rawmidi_ioctl(struct file *file, unsigned int cmd, unsigned long } }default : -rmidi_dbg (rfile->rmidi, -"rawmidi: unknown command = 0x%x\n" , cmd); + rmidi = rfile->rmidi; +if (rmidi->ops && rmidi->ops->ioctl) +return rmidi->ops->ioctl (rmidi, cmd, argp); +rmidi_dbg (rmidi,"rawmidi: unknown command = 0x%x\n" , cmd); }return -ENOTTY ; }
Signature · 1 line
2.35.3
PATCH v2 3/37 ALSA: rawmidi: UMP support
In reply to Takashi IwaiThis patch adds the support helpers for UMP (Universal MIDI Packet) in ALSA core.
The basic design is that a rawmidi instance is assigned to each UMP Endpoint. A UMP Endpoint provides a UMP stream, typically bidirectional (but can be also uni-directional, too), which may hold up to 16 UMP Groups, where each UMP (input/output) Group corresponds to the traditional MIDI I/O Endpoint.
Additionally, the ALSA UMP abstraction provides the multiple UMP Blocks that can be assigned to each UMP Endpoint. A UMP Block is a metadata to hold the UMP Group clusters, and can represent the functions assigned to each UMP Group. A typical implementation of UMP Block is the Group Terminal Blocks of USB MIDI 2.0 specification.
For distinguishing from the legacy byte-stream MIDI device, a new device "umpC*D*" will be created, instead of the standard (MIDI 1.0) devices "midiC*D*". The UMP instance can be identified by the new rawmidi info bit SNDRV_RAWMIDI_INFO_UMP, too.
A UMP rawmidi device reads/writes only in 4-bytes words alignment, stored in CPU native endianness.
The transmit and receive functions take care of the input/out data alignment, and may return zero or aligned size, and the params ioctl may return -EINVAL when the given input/output buffer size isn't aligned.
A few new UMP-specific ioctls are added for obtaining the new UMP endpoint and block information.
As of this commit, no ALSA sequencer instance is attached to UMP devices yet. They will be supported by later patches.
Along with those changes, the protocol version for rawmidi is bumped to 2.0.3.
--- include/sound/rawmidi.h | 8 ++ include/sound/ump.h | 118 ++++++++++++++++++ include/uapi/sound/asound.h | 57 ++++++++- sound/core/Kconfig | 4 + sound/core/Makefile | 2 + sound/core/rawmidi.c | 155 ++++++++++++++++-------- sound/core/rawmidi_compat.c | 4 + sound/core/ump.c | 230 ++++++++++++++++++++++++++++++++++++ 8 files changed, 529 insertions(+), 49 deletions(-) create mode 100644 include/sound/ump.h create mode 100644 sound/core/ump.c
include/sound/rawmidi.h +8 -0
@@ -63,6 +63,7 @@ struct snd_rawmidi_runtime {size_t avail_min;/* min avail for wakeup */ size_t avail;/* max used buffer for wakeup */ size_t xruns;/* over/underruns counter */ +size_t align;/* alignment (0 = byte stream, 3 = UMP) */ int buffer_ref;/* buffer reference count */ /* misc */ wait_queue_head_t sleep;
@@ -148,6 +149,13 @@ int snd_rawmidi_new(struct snd_card *card, char *id, int device,void snd_rawmidi_set_ops (struct snd_rawmidi *rmidi,int stream,const struct snd_rawmidi_ops *ops); +/* internal */ +int snd_rawmidi_init (struct snd_rawmidi *rmidi, +struct snd_card *card,char *id,int device, +int output_count,int input_count, +unsigned int info_flags); +int snd_rawmidi_free (struct snd_rawmidi *rmidi); +/* callbacks */ int snd_rawmidi_receive(struct snd_rawmidi_substream *substream,
include/sound/ump.h new file +118 -0
118 lines not on this page · raw message
include/uapi/sound/asound.h +56 -1
81 lines not on this page · raw message
sound/core/Kconfig +4 -0
@@ -26,6 +26,10 @@ config SND_RAWMIDI tristate select SND_SEQ_DEVICE if SND_SEQUENCER != n +config SND_UMP + tristate + select SND_RAWMIDI + config SND_COMPRESS_OFFLOAD tristate
sound/core/Makefile +2 -0
@@ -28,6 +28,7 @@ snd-pcm-dmaengine-objs := pcm_dmaengine.o snd-ctl-led-objs := control_led.o snd-rawmidi-objs := rawmidi.o +snd-ump-objs := ump.o snd-timer-objs := timer.o snd-hrtimer-objs := hrtimer.o snd-rtctimer-objs := rtctimer.o
@@ -45,6 +46,7 @@ obj-$(CONFIG_SND_PCM) += snd-pcm.o obj-$(CONFIG_SND_DMAENGINE_PCM) += snd-pcm-dmaengine.o obj-$(CONFIG_SND_SEQ_DEVICE) += snd-seq-device.o obj-$(CONFIG_SND_RAWMIDI) += snd-rawmidi.o +obj-$(CONFIG_SND_UMP) += snd-ump.o obj-$(CONFIG_SND_OSSEMUL) += oss/ obj-$(CONFIG_SND_SEQUENCER) += seq/
sound/core/rawmidi.c +107 -48
292 lines not on this page · raw message
sound/core/rawmidi_compat.c +4 -0
@@ -111,6 +111,10 @@ static long snd_rawmidi_ioctl_compat(struct file *file, unsigned int cmd, unsigncase SNDRV_RAWMIDI_IOCTL_INFO :case SNDRV_RAWMIDI_IOCTL_DROP :case SNDRV_RAWMIDI_IOCTL_DRAIN : +#if IS_ENABLED (CONFIG_SND_UMP ) +case SNDRV_UMP_IOCTL_ENDPOINT_INFO : +case SNDRV_UMP_IOCTL_BLOCK_INFO : +#endif return snd_rawmidi_ioctl (file, cmd, (unsigned long )argp);case SNDRV_RAWMIDI_IOCTL_PARAMS32 :return snd_rawmidi_ioctl_params_compat (rfile, argp);
sound/core/ump.c new file +230 -0
230 lines not on this page · raw message
Signature · 1 line
2.35.3
PATCH v2 4/37 ALSA: rawmidi: Skip UMP devices at SNDRV_CTL_IOCTL_RAWMIDI_NEXT_DEVICE
In reply to Takashi IwaiApplications may look for rawmidi devices with the ioctl SNDRV_CTL_IOCTL_RAWMIDI_NEXT_DEVICE. Returning a UMP device from this ioctl may confuse the existing applications that support only the legacy rawmidi.
This patch changes the code to skip the UMP devices from the lookup for avoiding the confusion, and introduces a new ioctl to look for the UMP devices instead.
Along with this change, bump the CTL protocol version to 2.0.9.
--- include/uapi/sound/asound.h | 3 +- sound/core/rawmidi.c | 57 +++++++++++++++++++++++-------------- 2 files changed, 38 insertions(+), 22 deletions(-)
include/uapi/sound/asound.h +2 -1
@@ -1016,7 +1016,7 @@ struct snd_timer_tread {* * ****************************************************************************/ -#define SNDRV_CTL_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 8) +#define SNDRV_CTL_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 9)struct snd_ctl_card_info {int card;/* card number */
@@ -1177,6 +1177,7 @@ struct snd_ctl_tlv {#define SNDRV_CTL_IOCTL_RAWMIDI_NEXT_DEVICE _IOWR('U', 0x40, int)#define SNDRV_CTL_IOCTL_RAWMIDI_INFO _IOWR('U', 0x41, struct snd_rawmidi_info)#define SNDRV_CTL_IOCTL_RAWMIDI_PREFER_SUBDEVICE _IOW('U', 0x42, int) +#define SNDRV_CTL_IOCTL_UMP_NEXT_DEVICE _IOWR('U', 0x43, int)#define SNDRV_CTL_IOCTL_POWER _IOWR('U', 0xd0, int)#define SNDRV_CTL_IOCTL_POWER_STATE _IOR('U', 0xd1, int)
sound/core/rawmidi.c +36 -21
69 lines not on this page · raw message
Signature · 1 line
2.35.3
PATCH v2 5/37 ALSA: ump: Add ioctls to inquiry UMP EP and Block info via control API
In reply to Takashi IwaiIt'd be convenient to have ioctls to inquiry the UMP Endpoint and UMP Block information directly via the control API without opening the rawmidi interface, just like SNDRV_CTL_IOCTL_RAWMIDI_INFO.
This patch extends the rawmidi ioctl handler to support those; new ioctls, SNDRV_CTL_IOCTL_UMP_ENDPOINT_INFO and SNDRV_CTL_IOCTL_UMP_BLOCK_INFO, return the snd_ump_endpoint and snd_ump_block data that is specified by the device field, respectively.
--- include/uapi/sound/asound.h | 2 ++ sound/core/rawmidi.c | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+)
include/uapi/sound/asound.h +2 -0
@@ -1178,6 +1178,8 @@ struct snd_ctl_tlv {#define SNDRV_CTL_IOCTL_RAWMIDI_INFO _IOWR('U', 0x41, struct snd_rawmidi_info)#define SNDRV_CTL_IOCTL_RAWMIDI_PREFER_SUBDEVICE _IOW('U', 0x42, int)#define SNDRV_CTL_IOCTL_UMP_NEXT_DEVICE _IOWR('U', 0x43, int) +#define SNDRV_CTL_IOCTL_UMP_ENDPOINT_INFO _IOWR('U', 0x44, struct snd_ump_endpoint_info) +#define SNDRV_CTL_IOCTL_UMP_BLOCK_INFO _IOWR('U', 0x45, struct snd_ump_block_info)#define SNDRV_CTL_IOCTL_POWER _IOWR('U', 0xd0, int)#define SNDRV_CTL_IOCTL_POWER_STATE _IOR('U', 0xd1, int)
sound/core/rawmidi.c +26 -0
@@ -1043,6 +1043,28 @@ static int snd_rawmidi_next_device(struct snd_card *card, int __user *argp,return 0 ; } +#if IS_ENABLED (CONFIG_SND_UMP ) +/* inquiry of UMP endpoint and block info via control API */ +static int snd_rawmidi_call_ump_ioctl (struct snd_card *card,int cmd, +void __user *argp) +{ +struct snd_ump_endpoint_info __user *info = argp; +struct snd_rawmidi *rmidi; +int device, ret; + +if (get_user (device, &info->device)) +return -EFAULT ; +mutex_lock (®ister_mutex); + rmidi =snd_rawmidi_search (card, device); +if (rmidi && rmidi->ops && rmidi->ops->ioctl) + ret = rmidi->ops->ioctl (rmidi, cmd, argp); +else + ret = -ENXIO ; +mutex_unlock (®ister_mutex); +return ret; +} +#endif + static int snd_rawmidi_control_ioctl(struct snd_card *card, struct snd_ctl_file *control, unsigned int cmd,
@@ -1056,6 +1078,10 @@ static int snd_rawmidi_control_ioctl(struct snd_card *card,#if IS_ENABLED (CONFIG_SND_UMP )case SNDRV_CTL_IOCTL_UMP_NEXT_DEVICE :return snd_rawmidi_next_device (card, argp, true); +case SNDRV_CTL_IOCTL_UMP_ENDPOINT_INFO : +return snd_rawmidi_call_ump_ioctl (card,SNDRV_UMP_IOCTL_ENDPOINT_INFO , argp); +case SNDRV_CTL_IOCTL_UMP_BLOCK_INFO : +return snd_rawmidi_call_ump_ioctl (card,SNDRV_UMP_IOCTL_BLOCK_INFO , argp);#endif case SNDRV_CTL_IOCTL_RAWMIDI_PREFER_SUBDEVICE : {
Signature · 1 line
2.35.3
PATCH v2 6/37 ALSA: ump: Additional proc output
In reply to Takashi IwaiUMP devices may have more interesting information than the traditional rawmidi. Extend the rawmidi_global_ops to allow the optional proc info output and show some more bits in the proc file for UMP.
Note that the "Groups" field shows the first and the last UMP Groups, and both numbers are 1-based (i.e. the first group is 1).
--- include/sound/rawmidi.h | 3 +++ sound/core/rawmidi.c | 2 ++ sound/core/ump.c | 49 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+)
include/sound/rawmidi.h +3 -0
@@ -18,6 +18,7 @@#if IS_ENABLED (CONFIG_SND_SEQUENCER )#include <sound/seq_device.h> #endif +#include <sound/info.h> /* * Raw MIDI interface
@@ -49,6 +50,8 @@ struct snd_rawmidi_global_ops { struct snd_seq_port_info *info);long (*ioctl)(struct snd_rawmidi *rmidi,unsigned int cmd,void __user *argp); +void (*proc_read)(struct snd_info_entry *entry, +struct snd_info_buffer *buf); };struct snd_rawmidi_runtime {
sound/core/rawmidi.c +2 -0
@@ -1770,6 +1770,8 @@ static void snd_rawmidi_proc_info_read(struct snd_info_entry *entry,if (IS_ENABLED (CONFIG_SND_UMP ))snd_iprintf (buffer,"Type: %s\n" ,rawmidi_is_ump (rmidi) ?"UMP" :"Legacy" ); +if (rmidi->ops->proc_read) + rmidi->ops->proc_read (entry, buffer);mutex_lock (&rmidi->open_mutex);if (rmidi->info_flags &SNDRV_RAWMIDI_INFO_OUTPUT ) { list_for_each_entry(substream,
sound/core/ump.c +49 -0
65 lines not on this page · raw message
Signature · 1 line
2.35.3
PATCH v2 7/37 ALSA: usb-audio: Manage number of rawmidis globally
In reply to Takashi IwaiWe're going to create rawmidi objects for MIDI 2.0 in a different code from the current code for USB-MIDI 1.0. As a preliminary work, this patch adds the number of rawmidi objects to keep globally in a USB-audio card instance, so that it can be referred from both MIDI 1.0 and 2.0 code.
--- sound/usb/card.c | 5 +++-- sound/usb/midi.c | 7 ++++++- sound/usb/midi.h | 5 +++-- sound/usb/quirks.c | 5 +++-- sound/usb/usbaudio.h | 1 + 5 files changed, 16 insertions(+), 7 deletions(-)
sound/usb/card.c +3 -2
@@ -179,8 +179,9 @@ static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int int altsd->bInterfaceClass == USB_CLASS_VENDOR_SPEC) && altsd->bInterfaceSubClass == USB_SUBCLASS_MIDISTREAMING) {int err =__snd_usbmidi_create (chip->card, iface, - &chip->midi_list,NULL , - chip->usb_id); + &chip->midi_list,NULL , + chip->usb_id, + &chip->num_rawmidis);if (err <0 ) { dev_err(&dev->dev, "%u:%d: cannot create sequencer device\n",
sound/usb/midi.c +6 -1
@@ -2461,7 +2461,8 @@ int __snd_usbmidi_create(struct snd_card *card,struct usb_interface *iface, struct list_head *midi_list, const struct snd_usb_audio_quirk *quirk, - unsigned int usb_id) + unsigned int usb_id, + unsigned int *num_rawmidis) { struct snd_usb_midi *umidi;struct snd_usb_midi_endpoint_info endpoints[MIDI_MAX_ENDPOINTS ];
@@ -2476,6 +2477,8 @@ int __snd_usbmidi_create(struct snd_card *card, umidi->iface = iface; umidi->quirk = quirk; umidi->usb_protocol_ops = &snd_usbmidi_standard_ops; +if (num_rawmidis) + umidi->next_midi_device = *num_rawmidis;spin_lock_init (&umidi->disc_lock);init_rwsem (&umidi->disc_rwsem);mutex_init (&umidi->mutex);
@@ -2595,6 +2598,8 @@ int __snd_usbmidi_create(struct snd_card *card,usb_autopm_get_interface_no_resume (umidi->iface);list_add_tail (&umidi->list, midi_list); +if (num_rawmidis) + *num_rawmidis = umidi->next_midi_device;return 0 ; free_midi:
sound/usb/midi.h +3 -2
@@ -46,14 +46,15 @@ int __snd_usbmidi_create(struct snd_card *card,struct usb_interface *iface, struct list_head *midi_list, const struct snd_usb_audio_quirk *quirk, - unsigned int usb_id); + unsigned int usb_id, + unsigned int *num_rawmidis);static inline int snd_usbmidi_create (struct snd_card *card,struct usb_interface *iface,struct list_head *midi_list,const struct snd_usb_audio_quirk *quirk) { -return __snd_usbmidi_create (card, iface, midi_list, quirk,0 ); +return __snd_usbmidi_create (card, iface, midi_list, quirk,0 ,NULL ); }void snd_usbmidi_input_stop (struct list_head *p);
sound/usb/quirks.c +3 -2
@@ -436,8 +436,9 @@ static int create_uaxx_quirk(struct snd_usb_audio *chip, chip->usb_id ==USB_ID (0x0582 ,0x002b ) ? &ua700_quirk : &uaxx_quirk;return __snd_usbmidi_create (chip->card, iface, - &chip->midi_list, quirk, - chip->usb_id); + &chip->midi_list, quirk, + chip->usb_id, + &chip->num_rawmidis); }if (altsd->bNumEndpoints !=1 )
sound/usb/usbaudio.h +1 -0
@@ -49,6 +49,7 @@ struct snd_usb_audio {struct list_head clock_ref_list;/* list of clock refcounts */ int pcm_devs; +unsigned int num_rawmidis;/* number of created rawmidi devices */ struct list_head midi_list;/* list of midi interfaces */ struct list_head mixer_list;/* list of mixer interfaces */
Signature · 1 line
2.35.3
PATCH v2 8/37 ALSA: usb-audio: Define USB MIDI 2.0 specs
In reply to Takashi IwaiDefine new structs and constants from USB MIDI 2.0 specification, to be used in the upcoming MIDI 2.0 support in USB-audio driver.
A new class-specific endpoint descriptor and group terminal block descriptors are defined.
--- include/linux/usb/midi-v2.h | 94 +++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 include/linux/usb/midi-v2.h
include/linux/usb/midi-v2.h new file +94 -0
@@ -0,0 +1,94 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* <linux/usb/midi-v2.h> -- USB MIDI 2.0 definitions. +*/ + +#ifndef __LINUX_USB_MIDI_V2_H +#define __LINUX_USB_MIDI_V2_H + +#include <linux/types.h> +#include <linux/usb/midi.h> + +/* A.1 MS Class-Specific Interface Descriptor Types */ +#define USB_DT_CS_GR_TRM_BLOCK 0x26 + +/* A.1 MS Class-Specific Interface Descriptor Subtypes */ +/* same as MIDI 1.0 */ + +/* A.2 MS Class-Specific Endpoint Descriptor Subtypes */ +#define USB_MS_GENERAL_2_0 0x02 + +/* A.3 MS Class-Specific Group Terminal Block Descriptor Subtypes */ +#define USB_MS_GR_TRM_BLOCK_UNDEFINED 0x00 +#define USB_MS_GR_TRM_BLOCK_HEADER 0x01 +#define USB_MS_GR_TRM_BLOCK 0x02 + +/* A.4 MS Interface Header MIDIStreaming Class Revision */ +#define USB_MS_REV_MIDI_1_0 0x0100 +#define USB_MS_REV_MIDI_2_0 0x0200 + +/* A.5 MS MIDI IN and OUT Jack Types */ +/* same as MIDI 1.0 */ + +/* A.6 Group Terminal Block Types */ +#define USB_MS_GR_TRM_BLOCK_TYPE_BIDIRECTIONAL 0x00 +#define USB_MS_GR_TRM_BLOCK_TYPE_INPUT_ONLY 0x01 +#define USB_MS_GR_TRM_BLOCK_TYPE_OUTPUT_ONLY 0x02 + +/* A.7 Group Terminal Default MIDI Protocol */ +#define USB_MS_MIDI_PROTO_UNKNOWN 0x00/* Unknown (Use MIDI-CI) */ +#define USB_MS_MIDI_PROTO_1_0_64 0x01/* MIDI 1.0, UMP up to 64bits */ +#define USB_MS_MIDI_PROTO_1_0_64_JRTS 0x02/* MIDI 1.0, UMP up to 64bits, Jitter Reduction Timestamps */ +#define USB_MS_MIDI_PROTO_1_0_128 0x03/* MIDI 1.0, UMP up to 128bits */ +#define USB_MS_MIDI_PROTO_1_0_128_JRTS 0x04/* MIDI 1.0, UMP up to 128bits, Jitter Reduction Timestamps */ +#define USB_MS_MIDI_PROTO_2_0 0x11/* MIDI 2.0 */ +#define USB_MS_MIDI_PROTO_2_0_JRTS 0x12/* MIDI 2.0, Jitter Reduction Timestamps */ + +/* 5.2.2.1 Class-Specific MS Interface Header Descriptor */ +/* Same as MIDI 1.0, use struct usb_ms_header_descriptor */ + +/* 5.3.2 Class-Specific MIDI Streaming Data Endpoint Descriptor */ +struct usb_ms20_endpoint_descriptor { +__u8 bLength;/* 4+n */ +__u8 bDescriptorType;/* USB_DT_CS_ENDPOINT */ +__u8 bDescriptorSubtype;/* USB_MS_GENERAL_2_0 */ +__u8 bNumGrpTrmBlock;/* Number of Group Terminal Blocks: n */ +__u8 baAssoGrpTrmBlkID[];/* ID of the Group Terminal Blocks [n] */ +} __packed; + +#define USB_DT_MS20_ENDPOINT_SIZE (n) (4 + (n)) + +/* As above, but more useful for defining your own descriptors: */ +#define DECLARE_USB_MS20_ENDPOINT_DESCRIPTOR (n) \ +struct usb_ms20_endpoint_descriptor_##n { \ + __u8 bLength; \ + __u8 bDescriptorType; \ + __u8 bDescriptorSubtype; \ + __u8 bNumGrpTrmBlock; \ + __u8 baAssoGrpTrmBlkID[n]; \ +} __packed + +/* 5.4.1 Class-Specific Group Terminal Block Header Descriptor */ +struct usb_ms20_gr_trm_block_header_descriptor { +__u8 bLength;/* 5 */ +__u8 bDescriptorType;/* USB_DT_CS_GR_TRM_BLOCK */ +__u8 bDescriptorSubtype;/* USB_MS_GR_TRM_BLOCK_HEADER */ +__u16 wTotalLength;/* Total number of bytes */ +} __packed; + +/* 5.4.2.1 Group Terminal Block Descriptor */ +struct usb_ms20_gr_trm_block_descriptor { +__u8 bLength;/* 13 */ +__u8 bDescriptorType;/* USB_DT_CS_GR_TRM_BLOCK */ +__u8 bDescriptorSubtype;/* USB_MS_GR_TRM_BLOCK */ +__u8 bGrpTrmBlkID;/* ID of this Group Terminal Block */ +__u8 bGrpTrmBlkType;/* Group Terminal Block Type */ +__u8 nGroupTrm;/* The first member Group Terminal in this block */ +__u8 nNumGroupTrm;/* Number of member Group Terminals spanned */ +__u8 iBlockItem;/* String ID of Block item */ +__u8 bMIDIProtocol;/* Default MIDI protocol */ +__u16 wMaxInputBandwidth;/* Max input bandwidth capability in 4kB/s */ +__u16 wMaxOutputBandwidth;/* Max output bandwidth capability in 4kB/s */ +} __packed; + +#endif /* __LINUX_USB_MIDI_V2_H */
Signature · 1 line
2.35.3
PATCH v2 9/37 ALSA: usb-audio: USB MIDI 2.0 UMP support
In reply to Takashi IwaiThis patch provides a basic support for USB MIDI 2.0. As of this patch, the driver creates a UMP device per MIDI I/O endpoints, which serves as a dumb terminal to read/write UMP streams.
A new Kconfig CONFIG_SND_USB_AUDIO_MIDI_V2 manages whether to enable or disable the MIDI 2.0 support. Also, the driver provides a new module option, midi2_enable, to allow disabling the MIDI 2.0 at runtime, too. When MIDI 2.0 support is disabled, the driver tries to fall back to the already existing MIDI 1.0 device (each MIDI 2.0 device is supposed to provide the MIDI 1.0 interface at the altset 0).
For now, the driver doesn't manage any MIDI-CI or other protocol setups by itself, but relies on the default protocol given via the group terminal block descriptors.
The MIDI 1.0 messages on MIDI 2.0 device will be automatically converted in ALSA sequencer in a later patch. As of this commit, the driver accepts merely the rawmidi UMP accesses.
The driver builds up the topology in the following way:
- Create an object for each MIDI endpoint belonging to the USB interface
- Find MIDI EP "pairs" that share the same GTB;
note that MIDI EP is unidirectional, while UMP is (normally) bidirectional, so two MIDI EPs can form a single UMP EP
- A UMP endpoint object is created for each I/O pair
- For remaining "solo" MIDI EPs, create unidirectional UMP EPs
- Finally, parse GTBs and fill the protocol bits on each UMP
So the driver may support multiple UMP Endpoints in theory, although most devices are supposed to have a single UMP EP that can contain up to 16 groups -- which should be large enough.
--- sound/usb/Kconfig | 11 + sound/usb/Makefile | 1 + sound/usb/card.c | 13 +- sound/usb/midi2.c | 1052 ++++++++++++++++++++++++++++++++++++++++++ sound/usb/midi2.h | 33 ++ sound/usb/quirks.c | 3 +- sound/usb/usbaudio.h | 1 + 7 files changed, 1109 insertions(+), 5 deletions(-) create mode 100644 sound/usb/midi2.c create mode 100644 sound/usb/midi2.h
sound/usb/Kconfig +11 -0
@@ -15,6 +15,7 @@ config SND_USB_AUDIO select SND_HWDEP select SND_RAWMIDI select SND_PCM + select SND_UMP if SND_USB_AUDIO_MIDI_V2 select BITREVERSE select SND_USB_AUDIO_USE_MEDIA_CONTROLLER if MEDIA_CONTROLLER && (MEDIA_SUPPORT=y || MEDIA_SUPPORT=SND_USB_AUDIO) help
@@ -24,6 +25,16 @@ config SND_USB_AUDIO To compile this driver as a module, choose M here: the module will be called snd-usb-audio. +config SND_USB_AUDIO_MIDI_V2 + bool "MIDI 2.0 support by USB Audio driver" + depends on SND_USB_AUDIO + help + Say Y here to include the support for MIDI 2.0 by USB Audio driver. + When the config is set, the driver tries to probe MIDI 2.0 interface + at first, then falls back to MIDI 1.0 interface as default. + The MIDI 2.0 support can be disabled dynamically via midi2_enable + module option, too. + config SND_USB_AUDIO_USE_MEDIA_CONTROLLER bool
sound/usb/Makefile +1 -0
@@ -22,6 +22,7 @@ snd-usb-audio-objs := card.o \ stream.o \ validate.o +snd-usb-audio-$(CONFIG_SND_USB_AUDIO_MIDI_V2) += midi2.o snd-usb-audio-$(CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER) += media.o snd-usbmidi-lib-objs := midi.o
sound/usb/card.c +9 -4
@@ -44,6 +44,7 @@#include "usbaudio.h" #include "card.h" #include "midi.h" +#include "midi2.h" #include "mixer.h" #include "proc.h" #include "quirks.h"
@@ -178,10 +179,8 @@ static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int intif ((altsd->bInterfaceClass ==USB_CLASS_AUDIO || altsd->bInterfaceClass ==USB_CLASS_VENDOR_SPEC ) && altsd->bInterfaceSubClass ==USB_SUBCLASS_MIDISTREAMING ) { -int err =__snd_usbmidi_create (chip->card, iface, - &chip->midi_list,NULL , - chip->usb_id, - &chip->num_rawmidis); +int err =snd_usb_midi_v2_create (chip, iface,NULL , + chip->usb_id);if (err <0 ) { dev_err(&dev->dev, "%u:%d: cannot create sequencer device\n",
@@ -486,6 +485,7 @@ static void snd_usb_audio_free(struct snd_card *card)struct snd_usb_audio *chip = card->private_data;snd_usb_endpoint_free_all (chip); +snd_usb_midi_v2_free_all (chip);mutex_destroy (&chip->mutex);if (!atomic_read (&chip->shutdown))
@@ -645,6 +645,7 @@ static int snd_usb_audio_create(struct usb_interface *intf,INIT_LIST_HEAD (&chip->iface_ref_list);INIT_LIST_HEAD (&chip->clock_ref_list);INIT_LIST_HEAD (&chip->midi_list); +INIT_LIST_HEAD (&chip->midi_v2_list);INIT_LIST_HEAD (&chip->mixer_list);if (quirk_flags[idx])
@@ -969,6 +970,7 @@ static void usb_audio_disconnect(struct usb_interface *intf)list_for_each (p, &chip->midi_list) {snd_usbmidi_disconnect (p); } +snd_usb_midi_v2_disconnect_all (chip);/* * Nice to check quirk && quirk->shares_media_device and * then call the snd_media_device_delete(). Don't have
@@ -1080,6 +1082,7 @@ static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message)snd_usbmidi_suspend (p);list_for_each_entry (mixer, &chip->mixer_list, list)snd_usb_mixer_suspend (mixer); +snd_usb_midi_v2_suspend_all (chip); }if (!PMSG_IS_AUTO (message) && !chip->system_suspend) {
@@ -1125,6 +1128,8 @@ static int usb_audio_resume(struct usb_interface *intf)snd_usbmidi_resume (p); } +snd_usb_midi_v2_resume_all (chip); + out:if (chip->num_suspended_intf == chip->system_suspend) {snd_power_change_state (chip->card,SNDRV_CTL_POWER_D0 );
sound/usb/midi2.c new file +1052 -0
1,052 lines not on this page · raw message
sound/usb/midi2.h new file +33 -0
@@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef __USB_AUDIO_MIDI2_H +#define __USB_AUDIO_MIDI2_H + +#include "midi.h" + +#if IS_ENABLED (CONFIG_SND_USB_AUDIO_MIDI_V2 ) +int snd_usb_midi_v2_create (struct snd_usb_audio *chip, +struct usb_interface *iface, +const struct snd_usb_audio_quirk *quirk, +unsigned int usb_id); +void snd_usb_midi_v2_suspend_all (struct snd_usb_audio *chip); +void snd_usb_midi_v2_resume_all (struct snd_usb_audio *chip); +void snd_usb_midi_v2_disconnect_all (struct snd_usb_audio *chip); +void snd_usb_midi_v2_free_all (struct snd_usb_audio *chip); +#else /* CONFIG_SND_USB_AUDIO_MIDI_V2 */ +/* fallback to MIDI 1.0 creation */ +static inline int snd_usb_midi_v2_create (struct snd_usb_audio *chip, +struct usb_interface *iface, +const struct snd_usb_audio_quirk *quirk, +unsigned int usb_id) +{ +return __snd_usbmidi_create (chip->card, iface, &chip->midi_list, + quirk, usb_id, &chip->num_rawmidis); +} + +static inline void snd_usb_midi_v2_suspend_all (struct snd_usb_audio *chip) {} +static inline void snd_usb_midi_v2_resume_all (struct snd_usb_audio *chip) {} +static inline void snd_usb_midi_v2_disconnect_all (struct snd_usb_audio *chip) {} +static inline void snd_usb_midi_v2_free_all (struct snd_usb_audio *chip) {} +#endif /* CONFIG_SND_USB_AUDIO_MIDI_V2 */ + +#endif /* __USB_AUDIO_MIDI2_H */
sound/usb/quirks.c +2 -1
@@ -19,6 +19,7 @@#include "mixer.h" #include "mixer_quirks.h" #include "midi.h" +#include "midi2.h" #include "quirks.h" #include "helper.h" #include "endpoint.h"
@@ -80,7 +81,7 @@ static int create_any_midi_quirk(struct snd_usb_audio *chip,struct usb_driver *driver, const struct snd_usb_audio_quirk *quirk) { - return snd_usbmidi_create(chip->card, intf, &chip->midi_list, quirk); + return snd_usb_midi_v2_create(chip, intf, quirk, 0); }/*
sound/usb/usbaudio.h +1 -0
@@ -51,6 +51,7 @@ struct snd_usb_audio {unsigned int num_rawmidis;/* number of created rawmidi devices */ struct list_head midi_list;/* list of midi interfaces */ +struct list_head midi_v2_list;/* list of MIDI 2 interfaces */ struct list_head mixer_list;/* list of mixer interfaces */
Signature · 1 line
2.35.3
PATCH v2 10/37 ALSA: usb-audio: Get UMP EP name string from USB interface
In reply to Takashi IwaiUSB descriptor may provide a nicer name for USB interface, and we may take it as the UMP Endpoint name. The UMP EP name is copied as the rawmidi name, too.
Also, fill the UMP block product_id field from the iSerialNumber string of the USB device descriptor as a recommended unique id, too.
--- sound/usb/midi2.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-)
sound/usb/midi2.c +27 -3
@@ -892,15 +892,39 @@ static int set_altset(struct snd_usb_midi2_interface *umidi) umidi->hostif->desc.bAlternateSetting); } +/* fill UMP Endpoint name string from USB descriptor */ +static void fill_ump_ep_name (struct snd_ump_endpoint *ump, +struct usb_device *dev,int id) +{ +usb_string (dev, id, ump->info.name,sizeof (ump->info.name)); +} +/* fill the fallback name string for each rawmidi instance */ static void set_fallback_rawmidi_names (struct snd_usb_midi2_interface *umidi) { +struct usb_device *dev = umidi->chip->dev;struct snd_usb_midi2_ump *rmidi; +struct snd_ump_endpoint *ump;list_for_each_entry (rmidi, &umidi->rawmidi_list, list) { -if (!*rmidi->ump->core.name) -sprintf (rmidi->ump->core.name,"USB MIDI %d" , - rmidi->index); + ump = rmidi->ump; +/* fill UMP EP name from USB descriptors */ +if (!*ump->info.name && umidi->hostif->desc.iInterface) +fill_ump_ep_name (ump, dev, umidi->hostif->desc.iInterface); +else if (!*ump->info.name && dev->descriptor.iProduct) +fill_ump_ep_name (ump, dev, dev->descriptor.iProduct); +/* fill fallback name */ +if (!*ump->info.name) +sprintf (ump->info.name,"USB MIDI %d" , rmidi->index); +/* copy as rawmidi name if not set */ +if (!*ump->core.name) +strscpy (ump->core.name, ump->info.name, +sizeof (ump->core.name)); +/* use serial number string as unique UMP product id */ +if (!*ump->info.product_id && dev->descriptor.iSerialNumber) +usb_string (dev, dev->descriptor.iSerialNumber, + ump->info.product_id, +sizeof (ump->info.product_id)); } }
Signature · 1 line
2.35.3
PATCH v2 11/37 ALSA: usb-audio: Trim superfluous "MIDI" suffix from UMP EP name
In reply to Takashi IwaiA single USB audio device may have multiple interfaces for different purposes (e.g. audio, MIDI and HID), where the iInterface descriptor of each interface may contain an own suffix, e.g. "MIDI" for a MIDI interface. as such a suffix is superfluous as a rawmidi and UMP Endpoint name, this patch trims the superfluous "MIDI" suffix from the name string.
--- sound/usb/midi2.c | 7 +++++++ 1 file changed, 7 insertions(+)
sound/usb/midi2.c +7 -0
@@ -896,7 +896,14 @@ static int set_altset(struct snd_usb_midi2_interface *umidi)static void fill_ump_ep_name (struct snd_ump_endpoint *ump,struct usb_device *dev,int id) { +int len; +usb_string (dev, id, ump->info.name,sizeof (ump->info.name)); + +/* trim superfluous "MIDI" suffix */ + len =strlen (ump->info.name); +if (len >5 && !strcmp (ump->info.name + len -5 ," MIDI" )) + ump->info.name[len -5 ] =0 ; }/* fill the fallback name string for each rawmidi instance */
Signature · 1 line
2.35.3
PATCH v2 12/37 ALSA: usb-audio: Create UMP blocks from USB MIDI GTBs
In reply to Takashi IwaiUSB MIDI spec defines the Group Terminal Blocks (GTB) that associate multiple UMP Groups. Those correspond to snd_ump_block entities in ALSA UMP abstraction, and now we create those UMP Block objects for each UMP Endpoint from the parsed GTB information.
--- sound/usb/midi2.c | 100 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 94 insertions(+), 6 deletions(-)
sound/usb/midi2.c +94 -6
@@ -599,14 +599,8 @@ find_group_terminal_block(struct snd_usb_midi2_interface *umidi, int id)static int parse_group_terminal_block (struct snd_usb_midi2_ump *rmidi,const struct usb_ms20_gr_trm_block_descriptor *desc) { -struct snd_usb_audio *chip = rmidi->umidi->chip;struct snd_ump_endpoint *ump = rmidi->ump; -usb_audio_dbg (chip, -"GTB id %d: groups = %d / %d, type = %d\n" , - desc->bGrpTrmBlkID, desc->nGroupTrm, desc->nNumGroupTrm, - desc->bGrpTrmBlkType); -/* set default protocol */ switch (desc->bMIDIProtocol) {case USB_MS_MIDI_PROTO_1_0_64 :
@@ -798,6 +792,94 @@ static int find_matching_ep_partner(struct snd_usb_midi2_interface *umidi,return 0 ; } +/* create a UMP block from a GTB entry */ +static int create_gtb_block (struct snd_usb_midi2_ump *rmidi,int dir,int blk) +{ +struct snd_usb_midi2_interface *umidi = rmidi->umidi; +const struct usb_ms20_gr_trm_block_descriptor *desc; +struct snd_ump_block *fb; +int type, err; + + desc =find_group_terminal_block (umidi, blk); +if (!desc) +return 0 ; + +usb_audio_dbg (umidi->chip, +"GTB %d: type=%d, group=%d/%d, protocol=%d, in bw=%d, out bw=%d\n" , + blk, desc->bGrpTrmBlkType, desc->nGroupTrm, + desc->nNumGroupTrm, desc->bMIDIProtocol, +__le16_to_cpu (desc->wMaxInputBandwidth), +__le16_to_cpu (desc->wMaxOutputBandwidth)); + +/* assign the direction */ +switch (desc->bGrpTrmBlkType) { +case USB_MS_GR_TRM_BLOCK_TYPE_BIDIRECTIONAL : + type =SNDRV_UMP_DIR_BIDIRECTION ; +break ; +case USB_MS_GR_TRM_BLOCK_TYPE_INPUT_ONLY : + type =SNDRV_UMP_DIR_INPUT ; +break ; +case USB_MS_GR_TRM_BLOCK_TYPE_OUTPUT_ONLY : + type =SNDRV_UMP_DIR_OUTPUT ; +break ; +default : +usb_audio_dbg (umidi->chip,"Unsupported GTB type %d\n" , + desc->bGrpTrmBlkType); +return 0 ;/* unsupported */ + } + +/* guess work: set blk-1 as the (0-based) block ID */ + err =snd_ump_block_new (rmidi->ump, blk -1 , type, + desc->nGroupTrm, desc->nNumGroupTrm, + &fb); +if (err == -EBUSY ) +return 0 ;/* already present */ +else if (err) +return err; + +if (desc->iBlockItem) +usb_string (rmidi->dev, desc->iBlockItem, + fb->info.name,sizeof (fb->info.name)); + +if (__le16_to_cpu (desc->wMaxInputBandwidth) ==1 || +__le16_to_cpu (desc->wMaxOutputBandwidth) ==1 ) + fb->info.flags |=SNDRV_UMP_BLOCK_IS_MIDI1 | +SNDRV_UMP_BLOCK_IS_LOWSPEED ; + +usb_audio_dbg (umidi->chip, +"Created a UMP block %d from GTB, name=%s\n" , + blk, fb->info.name); +return 0 ; +} + +/* Create UMP blocks for each UMP EP */ +static int create_blocks_from_gtb (struct snd_usb_midi2_interface *umidi) +{ +struct snd_usb_midi2_ump *rmidi; +int i, blk, err, dir; + +list_for_each_entry (rmidi, &umidi->rawmidi_list, list) { +if (!rmidi->ump) +continue ; +/* Blocks have been already created? */ +if (rmidi->ump->info.num_blocks) +continue ; +/* loop over GTBs */ +for (dir =0 ; dir <2 ; dir++) { +if (!rmidi->eps[dir]) +continue ; +for (i =0 ; i < rmidi->eps[dir]->ms_ep->bNumGrpTrmBlock; i++) { + blk = rmidi->eps[dir]->ms_ep->baAssoGrpTrmBlkID[i]; + err =create_gtb_block (rmidi, dir, blk); +if (err <0 ) +return err; + } + } + } + +return 0 ; +} +static void snd_usb_midi_v2_free (struct snd_usb_midi2_interface *umidi) {free_all_midi2_endpoints (umidi);
@@ -1009,6 +1091,12 @@ int snd_usb_midi_v2_create(struct snd_usb_audio *chip, goto error; } + err =create_blocks_from_gtb (umidi); +if (err <0 ) { +usb_audio_err (chip,"Failed to create GTB blocks\n" ); + goto error; + } +set_fallback_rawmidi_names (umidi);return 0 ;
Signature · 1 line
2.35.3
PATCH v2 13/37 ALSA: ump: Redirect rawmidi substream access via own helpers
In reply to Takashi IwaiThis is a code refactoring for abstracting the rawmidi access to the UMP's own helpers. It's a preliminary work for the later code refactoring of the UMP layer.
Until now, we access to the rawmidi substream directly from the driver via rawmidi access helpers, but after this change, the driver is supposed to access via the newly introduced snd_ump_ops and receive/transmit via snd_ump_receive() and snd_ump_transmit() helpers. As of this commit, those are merely wrappers for the rawmidi substream, and no much function change is seen here.
--- include/sound/ump.h | 14 ++++++ sound/core/ump.c | 111 ++++++++++++++++++++++++++++++++++++++++++++ sound/usb/midi2.c | 71 ++++++++++------------------ 3 files changed, 149 insertions(+), 47 deletions(-)
include/sound/ump.h +14 -0
@@ -9,18 +9,30 @@struct snd_ump_endpoint ;struct snd_ump_block ; +struct snd_ump_ops ;struct snd_ump_endpoint {struct snd_rawmidi core;/* raw UMP access */ struct snd_ump_endpoint_info info; +const struct snd_ump_ops *ops;/* UMP ops set by the driver */ +struct snd_rawmidi_substream *substreams[2 ];/* opened substreams */ +void *private_data;void (*private_free)(struct snd_ump_endpoint *ump);struct list_head block_list;/* list of snd_ump_block objects */ }; +/* ops filled by UMP drivers */ +struct snd_ump_ops { +int (*open)(struct snd_ump_endpoint *ump,int dir); +void (*close)(struct snd_ump_endpoint *ump,int dir); +void (*trigger)(struct snd_ump_endpoint *ump,int dir,int up); +void (*drain)(struct snd_ump_endpoint *ump,int dir); +}; +struct snd_ump_block {struct snd_ump_block_info info;struct snd_ump_endpoint *ump;
@@ -39,6 +51,8 @@ int snd_ump_endpoint_new(struct snd_card *card, char *id, int device,int snd_ump_block_new (struct snd_ump_endpoint *ump,unsigned int blk,unsigned int direction,unsigned int first_group,unsigned int num_groups,struct snd_ump_block **blk_ret); +int snd_ump_receive (struct snd_ump_endpoint *ump,const u32 *buffer,int count); +int snd_ump_transmit (struct snd_ump_endpoint *ump,u32 *buffer,int count);/* * Some definitions for UMP
sound/core/ump.c +111 -0
135 lines not on this page · raw message
sound/usb/midi2.c +24 -47
162 lines not on this page · raw message
Signature · 1 line
2.35.3
PATCH v2 14/37 ALSA: ump: Add legacy raw MIDI support
In reply to Takashi IwaiThis patch extends the UMP core code to support the legacy MIDI 1.0 rawmidi devices. When the new kconfig CONFIG_SND_UMP_LEGACY_RAWMIDI is set, the UMP core allows to attach an additional rawmidi device for each UMP Endpoint. The rawmidi device contains 16 substreams where each substream corresponds to a UMP Group belonging to the EP. The device reads/writes the legacy MIDI 1.0 byte streams and translates from/to UMP packets.
The legacy rawmidi devices are exclusive with the UMP rawmidi devices, hence both of them can't be opened at the same time unless the UMP rawmidi is opened in APPEND mode.
--- include/sound/ump.h | 30 +++ include/sound/ump_msg.h | 540 +++++++++++++++++++++++++++++++++++++++ sound/core/Kconfig | 9 + sound/core/Makefile | 1 + sound/core/ump.c | 258 ++++++++++++++++++- sound/core/ump_convert.c | 520 +++++++++++++++++++++++++++++++++++++ sound/core/ump_convert.h | 43 ++++ 7 files changed, 1398 insertions(+), 3 deletions(-) create mode 100644 include/sound/ump_msg.h create mode 100644 sound/core/ump_convert.c create mode 100644 sound/core/ump_convert.h
include/sound/ump.h +30 -0
@@ -10,6 +10,7 @@struct snd_ump_endpoint ;struct snd_ump_block ;struct snd_ump_ops ; +struct ump_cvt_to_ump ;struct snd_ump_endpoint {struct snd_rawmidi core;/* raw UMP access */
@@ -23,6 +24,24 @@ struct snd_ump_endpoint {void (*private_free)(struct snd_ump_endpoint *ump);struct list_head block_list;/* list of snd_ump_block objects */ + +/* intermediate buffer for UMP input */ +u32 input_buf[4 ]; +int input_buf_head; +int input_pending; + +#if IS_ENABLED (CONFIG_SND_UMP_LEGACY_RAWMIDI ) +struct mutex open_mutex; + +spinlock_t legacy_locks[2 ]; +struct snd_rawmidi *legacy_rmidi; +struct snd_rawmidi_substream *legacy_substreams[2 ][SNDRV_UMP_MAX_GROUPS ]; + +/* for legacy output; need to open the actual substream unlike input */ +int legacy_out_opens; +struct snd_rawmidi_file legacy_out_rfile; +struct ump_cvt_to_ump *out_cvts; +#endif };/* ops filled by UMP drivers */
@@ -54,6 +73,17 @@ int snd_ump_block_new(struct snd_ump_endpoint *ump, unsigned int blk,int snd_ump_receive (struct snd_ump_endpoint *ump,const u32 *buffer,int count);int snd_ump_transmit (struct snd_ump_endpoint *ump,u32 *buffer,int count); +#if IS_ENABLED (CONFIG_SND_UMP_LEGACY_RAWMIDI ) +int snd_ump_attach_legacy_rawmidi (struct snd_ump_endpoint *ump, +char *id,int device); +#else +static inline int snd_ump_attach_legacy_rawmidi (struct snd_ump_endpoint *ump, +char *id,int device) +{ +return 0 ; +} +#endif +/* * Some definitions for UMP */
include/sound/ump_msg.h new file +540 -0
540 lines not on this page · raw message
sound/core/Kconfig +9 -0
@@ -30,6 +30,15 @@ config SND_UMP tristate select SND_RAWMIDI +config SND_UMP_LEGACY_RAWMIDI + bool "Legacy raw MIDI support for UMP streams" + depends on SND_UMP + help + This option enables the legacy raw MIDI support for UMP streams. + When this option is set, an additional rawmidi device for the + legacy MIDI 1.0 byte streams is created for each UMP Endpoint. + The device contains 16 substreams corresponding to UMP groups. + config SND_COMPRESS_OFFLOAD tristate
sound/core/Makefile +1 -0
@@ -29,6 +29,7 @@ snd-pcm-dmaengine-objs := pcm_dmaengine.o snd-ctl-led-objs := control_led.o snd-rawmidi-objs := rawmidi.o snd-ump-objs := ump.o +snd-ump-$(CONFIG_SND_UMP_LEGACY_RAWMIDI) += ump_convert.o snd-timer-objs := timer.o snd-hrtimer-objs := hrtimer.o snd-rtctimer-objs := rtctimer.o
sound/core/ump.c +255 -3
309 lines not on this page · raw message
sound/core/ump_convert.c new file +520 -0
520 lines not on this page · raw message
sound/core/ump_convert.h new file +43 -0
43 lines not on this page · raw message
Signature · 1 line
2.35.3
PATCH v2 15/37 ALSA: usb-audio: Enable the legacy raw MIDI support
In reply to Takashi IwaiAttach the legacy rawmidi devices when enabled in Kconfig accordingly.
--- sound/usb/midi2.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-)
sound/usb/midi2.c +26 -1
@@ -857,6 +857,25 @@ static int create_blocks_from_gtb(struct snd_usb_midi2_interface *umidi)return 0 ; } +/* attach legacy rawmidis */ +static int attach_legacy_rawmidi (struct snd_usb_midi2_interface *umidi) +{ +#if IS_ENABLED (CONFIG_SND_UMP_LEGACY_RAWMIDI ) +struct snd_usb_midi2_ump *rmidi; +int err; + +list_for_each_entry (rmidi, &umidi->rawmidi_list, list) { + err =snd_ump_attach_legacy_rawmidi (rmidi->ump, +"Legacy MIDI" , + umidi->chip->num_rawmidis); +if (err <0 ) +return err; + umidi->chip->num_rawmidis++; + } +#endif +return 0 ; +} +static void snd_usb_midi_v2_free (struct snd_usb_midi2_interface *umidi) {free_all_midi2_endpoints (umidi);
@@ -922,7 +941,7 @@ static int parse_midi_2_0(struct snd_usb_midi2_interface *umidi) } } -return 0 ; +return attach_legacy_rawmidi (umidi); }/* is the given interface for MIDI 2.0? */
@@ -991,6 +1010,12 @@ static void set_fallback_rawmidi_names(struct snd_usb_midi2_interface *umidi)usb_string (dev, dev->descriptor.iSerialNumber, ump->info.product_id,sizeof (ump->info.product_id)); +#if IS_ENABLED (CONFIG_SND_UMP_LEGACY_RAWMIDI ) +if (ump->legacy_rmidi && !*ump->legacy_rmidi->name) +snprintf (ump->legacy_rmidi->name, +sizeof (ump->legacy_rmidi->name), +"%s (MIDI 1.0)" , ump->info.name); +#endif } }
Signature · 1 line
2.35.3
PATCH v2 16/37 ALSA: usb-audio: Inform inconsistent protocols in GTBs
In reply to Takashi IwaiWhen parsing Group Terminal Blocks, we overwrote the preferred protocol and the protocol capabilities silently from the last parsed GTB. This patch adds the information print indicating the unexpected overrides instead of silent action.
--- sound/usb/midi2.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-)
sound/usb/midi2.c +21 -4
@@ -581,6 +581,7 @@ static int parse_group_terminal_block(struct snd_usb_midi2_ump *rmidi, const struct usb_ms20_gr_trm_block_descriptor *desc) {struct snd_ump_endpoint *ump = rmidi->ump; +unsigned int protocol, protocol_caps;/* set default protocol */ switch (desc->bMIDIProtocol) {
@@ -588,24 +589,40 @@ static int parse_group_terminal_block(struct snd_usb_midi2_ump *rmidi,case USB_MS_MIDI_PROTO_1_0_64_JRTS :case USB_MS_MIDI_PROTO_1_0_128 :case USB_MS_MIDI_PROTO_1_0_128_JRTS : - ump->info.protocol =SNDRV_UMP_EP_INFO_PROTO_MIDI1 ; + protocol =SNDRV_UMP_EP_INFO_PROTO_MIDI1 ;break ;case USB_MS_MIDI_PROTO_2_0 :case USB_MS_MIDI_PROTO_2_0_JRTS : - ump->info.protocol =SNDRV_UMP_EP_INFO_PROTO_MIDI2 ; + protocol =SNDRV_UMP_EP_INFO_PROTO_MIDI2 ;break ; +default : +return 0 ; } - ump->info.protocol_caps = ump->info.protocol; +if (ump->info.protocol && ump->info.protocol != protocol) +usb_audio_info (rmidi->umidi->chip, +"Overriding preferred MIDI protocol in GTB %d: %x -> %x\n" , + rmidi->usb_block_id, ump->info.protocol, + protocol); + ump->info.protocol = protocol; + + protocol_caps = protocol;switch (desc->bMIDIProtocol) {case USB_MS_MIDI_PROTO_1_0_64_JRTS :case USB_MS_MIDI_PROTO_1_0_128_JRTS :case USB_MS_MIDI_PROTO_2_0_JRTS : - ump->info.protocol_caps |=SNDRV_UMP_EP_INFO_PROTO_JRTS_TX | + protocol_caps |=SNDRV_UMP_EP_INFO_PROTO_JRTS_TX |SNDRV_UMP_EP_INFO_PROTO_JRTS_RX ;break ; } +if (ump->info.protocol_caps && ump->info.protocol_caps != protocol_caps) +usb_audio_info (rmidi->umidi->chip, +"Overriding MIDI protocol caps in GTB %d: %x -> %x\n" , + rmidi->usb_block_id, ump->info.protocol_caps, + protocol_caps); + ump->info.protocol_caps = protocol_caps; +return 0 ; }
Signature · 1 line
2.35.3
PATCH v2 17/37 ALSA: seq: Clear padded bytes at expanding events
In reply to Takashi IwaiThere can be a small memory hole that may not be cleared at expanding an event with the variable length type. Make sure to clear it.
--- sound/core/seq/seq_memory.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
sound/core/seq/seq_memory.c +9 -5
@@ -152,12 +152,16 @@ int snd_seq_expand_var_event(const struct snd_seq_event *event, int count, charreturn -EINVAL ;if (copy_from_user (buf, (void __force __user *)event->data.ext.ptr, len))return -EFAULT ; -return newlen; + }else { + err =snd_seq_dump_var_event (event, + in_kernel ? seq_copy_in_kernel : seq_copy_in_user, + &buf); +if (err <0 ) +return err; } - err =snd_seq_dump_var_event (event, - in_kernel ? seq_copy_in_kernel : seq_copy_in_user, - &buf); -return err <0 ? err : newlen; +if (len != newlen) +memset (buf + len,0 , newlen - len); +return newlen; }EXPORT_SYMBOL (snd_seq_expand_var_event);
Signature · 1 line
2.35.3
PATCH v2 18/37 ALSA: seq: Add snd_seq_expand_var_event_at() helper
In reply to Takashi IwaiCreate a new variant of snd_seq_expand_var_event() for expanding the data starting from the given byte offset. It'll be used by the new UMP sequencer code later.
--- include/sound/seq_kernel.h | 2 + sound/core/seq/seq_memory.c | 86 +++++++++++++++++++++++++++++-------- 2 files changed, 69 insertions(+), 19 deletions(-)
include/sound/seq_kernel.h +2 -0
@@ -70,6 +70,8 @@ int snd_seq_kernel_client_ctl(int client, unsigned int cmd, void *arg);typedef int (*snd_seq_dump_func_t )(void *ptr,void *buf,int count);int snd_seq_expand_var_event (const struct snd_seq_event *event,int count,char *buf,int in_kernel,int size_aligned); +int snd_seq_expand_var_event_at (const struct snd_seq_event *event,int count, +char *buf,int offset);int snd_seq_dump_var_event (const struct snd_seq_event *event,snd_seq_dump_func_t func,void *private_data);
sound/core/seq/seq_memory.c +67 -19
141 lines not on this page · raw message
Signature · 1 line
2.35.3
PATCH v2 19/37 ALSA: seq: Treat snd_seq_client object directly in client drivers
In reply to Takashi IwaiIntroduce the new helpers, snd_seq_kernel_client_get() and _put() for kernel client drivers to treat the snd_seq_client more directly. This allows us to reduce the exported symbols and APIs at each time we need to access some field in future.
--- sound/core/seq/seq_clientmgr.c | 15 +++++++++++++++ sound/core/seq/seq_clientmgr.h | 4 ++++ 2 files changed, 19 insertions(+)
sound/core/seq/seq_clientmgr.c +15 -0
@@ -2390,6 +2390,21 @@ int snd_seq_kernel_client_write_poll(int clientid, struct file *file, poll_table }EXPORT_SYMBOL (snd_seq_kernel_client_write_poll); +/* get a sequencer client object; for internal use from a kernel client */ +struct snd_seq_client *snd_seq_kernel_client_get (int id) +{ +return snd_seq_client_use_ptr (id); +} +EXPORT_SYMBOL_GPL (snd_seq_kernel_client_get); + +/* put a sequencer client object; for internal use from a kernel client */ +void snd_seq_kernel_client_put (struct snd_seq_client *cptr) +{ +if (cptr) +snd_seq_client_unlock (cptr); +} +EXPORT_SYMBOL_GPL (snd_seq_kernel_client_put); +/*---------------------------------------------------------------------------*/ #ifdef CONFIG_SND_PROC_FS
sound/core/seq/seq_clientmgr.h +4 -0
@@ -88,4 +88,8 @@ void snd_seq_client_ioctl_unlock(int clientid);extern int seq_client_load[15 ]; +/* for internal use between kernel sequencer clients */ +struct snd_seq_client *snd_seq_kernel_client_get (int client); +void snd_seq_kernel_client_put (struct snd_seq_client *cptr); +#endif
Signature · 1 line
2.35.3
PATCH v2 20/37 ALSA: seq: Drop dead code for the old broadcast support
In reply to Takashi IwaiThe broadcast and multicast supports have been never enabled. Let's drop the dead code.
--- sound/core/seq/seq_clientmgr.c | 105 +-------------------------------- 1 file changed, 1 insertion(+), 104 deletions(-)
sound/core/seq/seq_clientmgr.c +1 -104
@@ -711,93 +711,6 @@ static int deliver_to_subscribers(struct snd_seq_client *client,return (result <0 ) ? result : num_ev; } - -#ifdef SUPPORT_BROADCAST -/* -* broadcast to all ports: -*/ -static int port_broadcast_event (struct snd_seq_client *client, -struct snd_seq_event *event, -int atomic,int hop) -{ -int num_ev =0 , err, result =0 ; -struct snd_seq_client *dest_client; -struct snd_seq_client_port *port; - - dest_client =get_event_dest_client (event,SNDRV_SEQ_FILTER_BROADCAST ); -if (dest_client ==NULL ) -return 0 ;/* no matching destination */ - -read_lock (&dest_client->ports_lock); -list_for_each_entry (port, &dest_client->ports_list_head, list) { - event->dest.port = port->addr.port; -/* pass NULL as source client to avoid error bounce */ - err =snd_seq_deliver_single_event (NULL , event, -SNDRV_SEQ_FILTER_BROADCAST , - atomic, hop); -if (err <0 ) { -/* save first error that occurs and continue */ -if (!result) - result = err; -continue ; - } - num_ev++; - } -read_unlock (&dest_client->ports_lock); -snd_seq_client_unlock (dest_client); - event->dest.port =SNDRV_SEQ_ADDRESS_BROADCAST ;/* restore */ -return (result <0 ) ? result : num_ev; -} - -/* -* send the event to all clients: -* if destination port is also ADDRESS_BROADCAST, deliver to all ports. -*/ -static int broadcast_event (struct snd_seq_client *client, -struct snd_seq_event *event,int atomic,int hop) -{ -int err, result =0 , num_ev =0 ; -int dest; -struct snd_seq_addr addr; - - addr = event->dest;/* save */ - -for (dest =0 ; dest <SNDRV_SEQ_MAX_CLIENTS ; dest++) { -/* don't send to itself */ -if (dest == client->number) -continue ; - event->dest.client = dest; - event->dest.port = addr.port; -if (addr.port ==SNDRV_SEQ_ADDRESS_BROADCAST ) - err =port_broadcast_event (client, event, atomic, hop); -else -/* pass NULL as source client to avoid error bounce */ - err =snd_seq_deliver_single_event (NULL , event, -SNDRV_SEQ_FILTER_BROADCAST , - atomic, hop); -if (err <0 ) { -/* save first error that occurs and continue */ -if (!result) - result = err; -continue ; - } - num_ev += err; - } - event->dest = addr;/* restore */ -return (result <0 ) ? result : num_ev; -} - - -/* multicast - not supported yet */ -static int multicast_event (struct snd_seq_client *client,struct snd_seq_event *event, -int atomic,int hop) -{ -pr_debug ("ALSA: seq: multicast not supported yet.\n" ); -return 0 ;/* ignored */ -} -#endif /* SUPPORT_BROADCAST */ - -/* deliver an event to the destination port(s). * if the event is to subscribers or broadcast, the event is dispatched * to multiple targets.
@@ -826,15 +739,6 @@ static int snd_seq_deliver_event(struct snd_seq_client *client, struct snd_seq_eif (event->queue ==SNDRV_SEQ_ADDRESS_SUBSCRIBERS || event->dest.client ==SNDRV_SEQ_ADDRESS_SUBSCRIBERS ) result =deliver_to_subscribers (client, event, atomic, hop); -#ifdef SUPPORT_BROADCAST - else if (event->queue == SNDRV_SEQ_ADDRESS_BROADCAST || - event->dest.client == SNDRV_SEQ_ADDRESS_BROADCAST) - result =broadcast_event (client, event, atomic, hop); - else if (event->dest.client >= SNDRV_SEQ_MAX_CLIENTS) - result =multicast_event (client, event, atomic, hop); - else if (event->dest.port == SNDRV_SEQ_ADDRESS_BROADCAST) - result =port_broadcast_event (client, event, atomic, hop); -#endif else result =snd_seq_deliver_single_event (client, event,0 , atomic, hop);
@@ -936,14 +840,7 @@ static int snd_seq_client_enqueue_event(struct snd_seq_client *client,if (event->queue ==SNDRV_SEQ_ADDRESS_SUBSCRIBERS ) { event->dest.client =SNDRV_SEQ_ADDRESS_SUBSCRIBERS ; event->queue =SNDRV_SEQ_QUEUE_DIRECT ; - } else -#ifdef SUPPORT_BROADCAST -if (event->queue ==SNDRV_SEQ_ADDRESS_BROADCAST ) { - event->dest.client =SNDRV_SEQ_ADDRESS_BROADCAST ; - event->queue =SNDRV_SEQ_QUEUE_DIRECT ; - } -#endif -if (event->dest.client ==SNDRV_SEQ_ADDRESS_SUBSCRIBERS ) { + }else if (event->dest.client ==SNDRV_SEQ_ADDRESS_SUBSCRIBERS ) {/* check presence of source port */ struct snd_seq_client_port *src_port =snd_seq_port_use_ptr (client, event->source.port);if (src_port ==NULL )
Signature · 1 line
2.35.3
PATCH v2 21/37 ALSA: seq: Check the conflicting port at port creation
In reply to Takashi IwaiWe didn't check if a port with the given port number has been already present at creating a new port. Check it and return -EBUSY properly if the port number conflicts.
--- sound/core/seq/seq_clientmgr.c | 12 ++++++++---- sound/core/seq/seq_ports.c | 25 ++++++++++++++++--------- sound/core/seq/seq_ports.h | 5 +++-- 3 files changed, 27 insertions(+), 15 deletions(-)
sound/core/seq/seq_clientmgr.c +8 -4
@@ -1194,15 +1194,19 @@ static int snd_seq_ioctl_create_port(struct snd_seq_client *client, void *arg)struct snd_seq_port_info *info = arg;struct snd_seq_client_port *port;struct snd_seq_port_callback *callback; -int port_idx; +int port_idx, err;/* it is not allowed to create the port for an another client */ if (info->addr.client != client->number)return -EPERM ; - port =snd_seq_create_port (client, (info->flags &SNDRV_SEQ_PORT_FLG_GIVEN_PORT ) ? info->addr.port :-1 ); -if (port ==NULL ) -return -ENOMEM ; +if (info->flags &SNDRV_SEQ_PORT_FLG_GIVEN_PORT ) + port_idx = info->addr.port; +else + port_idx =-1 ; + err =snd_seq_create_port (client, port_idx, &port); +if (err <0 ) +return err;if (client->type ==USER_CLIENT && info->kernel) { port_idx = port->addr.port;
sound/core/seq/seq_ports.c +16 -9
@@ -107,33 +107,34 @@ static void port_subs_info_init(struct snd_seq_port_subs_info *grp) } -/* create a port, port number is returned (-1 on failure); +/* create a port, port number or a negative error code is returned * the caller needs to unref the port via snd_seq_port_unlock() appropriately */ -struct snd_seq_client_port *snd_seq_create_port (struct snd_seq_client *client, -int port) +int snd_seq_create_port (struct snd_seq_client *client,int port, +struct snd_seq_client_port **port_ret) {struct snd_seq_client_port *new_port, *p; -int num =-1 ; +int num; + *port_ret =NULL ; +/* sanity check */ if (snd_BUG_ON (!client)) -return NULL ; +return -EINVAL ;if (client->num_ports >=SNDRV_SEQ_MAX_PORTS ) {pr_warn ("ALSA: seq: too many ports for client %d\n" , client->number); -return NULL ; +return -EINVAL ; }/* create a new port */ new_port =kzalloc (sizeof (*new_port),GFP_KERNEL );if (!new_port) -return NULL ;/* failure, out of memory */ +return -ENOMEM ;/* failure, out of memory */ /* init port data */ new_port->addr.client = client->number; new_port->addr.port =-1 ; new_port->owner =THIS_MODULE ; -sprintf (new_port->name,"port-%d" , num);snd_use_lock_init (&new_port->use_lock);port_subs_info_init (&new_port->c_src);port_subs_info_init (&new_port->c_dest);
@@ -143,6 +144,10 @@ struct snd_seq_client_port *snd_seq_create_port(struct snd_seq_client *client,mutex_lock (&client->ports_mutex);write_lock_irq (&client->ports_lock);list_for_each_entry (p, &client->ports_list_head, list) { +if (p->addr.port == port) { + num = -EBUSY ; + goto unlock; + }if (p->addr.port > num)break ;if (port <0 )/* auto-probe mode */
@@ -153,10 +158,12 @@ struct snd_seq_client_port *snd_seq_create_port(struct snd_seq_client *client, client->num_ports++; new_port->addr.port = num;/* store the port number in the port */ sprintf (new_port->name,"port-%d" , num); + *port_ret = new_port; + unlock:write_unlock_irq (&client->ports_lock);mutex_unlock (&client->ports_mutex); -return new_port; +return num; }/* */
sound/core/seq/seq_ports.h +3 -2
@@ -86,8 +86,9 @@ struct snd_seq_client_port *snd_seq_port_query_nearest(struct snd_seq_client *cl/* unlock the port */ #define snd_seq_port_unlock (port) snd_use_lock_free(&(port)->use_lock) -/* create a port, port number is returned (-1 on failure) */ -struct snd_seq_client_port *snd_seq_create_port (struct snd_seq_client *client,int port_index); +/* create a port, port number or a negative error code is returned */ +int snd_seq_create_port (struct snd_seq_client *client,int port_index, +struct snd_seq_client_port **port_ret);/* delete a port */ int snd_seq_delete_port (struct snd_seq_client *client,int port);
Signature · 1 line
2.35.3
PATCH v2 22/37 ALSA: seq: Check validity before creating a port object
In reply to Takashi IwaiThe client type and the port info validity check should be done before actually creating a port, instead of unnecessary create-and-scratch.
--- sound/core/seq/seq_clientmgr.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
sound/core/seq/seq_clientmgr.c +2 -6
@@ -1199,6 +1199,8 @@ static int snd_seq_ioctl_create_port(struct snd_seq_client *client, void *arg)/* it is not allowed to create the port for an another client */ if (info->addr.client != client->number)return -EPERM ; +if (client->type ==USER_CLIENT && info->kernel) +return -EINVAL ;if (info->flags &SNDRV_SEQ_PORT_FLG_GIVEN_PORT ) port_idx = info->addr.port;
@@ -1208,12 +1210,6 @@ static int snd_seq_ioctl_create_port(struct snd_seq_client *client, void *arg)if (err <0 )return err; -if (client->type ==USER_CLIENT && info->kernel) { - port_idx = port->addr.port; -snd_seq_port_unlock (port); -snd_seq_delete_port (client, port_idx); -return -EINVAL ; - }if (client->type ==KERNEL_CLIENT ) { callback = info->kernel;if (callback) {
Signature · 1 line
2.35.3
PATCH v2 23/37 ALSA: seq: Prohibit creating ports with special numbers
In reply to Takashi IwaiSome port numbers are special, such as 254 for subscribers and 255 for broadcast. Return error if application tries to create such a port.
--- sound/core/seq/seq_clientmgr.c | 2 ++ 1 file changed, 2 insertions(+)
sound/core/seq/seq_clientmgr.c +2 -0
@@ -1206,6 +1206,8 @@ static int snd_seq_ioctl_create_port(struct snd_seq_client *client, void *arg) port_idx = info->addr.port; else port_idx =-1 ; +if (port_idx >=SNDRV_SEQ_ADDRESS_UNKNOWN ) +return -EINVAL ; err =snd_seq_create_port (client, port_idx, &port);if (err <0 )return err;
Signature · 1 line
2.35.3
PATCH v2 24/37 ALSA: seq: Introduce SNDRV_SEQ_IOCTL_USER_PVERSION ioctl
In reply to Takashi IwaiFor the future extension of ALSA sequencer ABI, introduce a new ioctl SNDRV_SEQ_IOCTL_USER_PVERSION. This is similar like the ioctls used in PCM and other interfaces, for an application to specify its supporting ABI version.
The use of this ioctl will be mandatory for the upcoming UMP support.
--- include/uapi/sound/asequencer.h | 1 + sound/core/seq/seq_clientmgr.c | 8 ++++++++ sound/core/seq/seq_clientmgr.h | 1 + sound/core/seq/seq_compat.c | 1 + 4 files changed, 11 insertions(+)
include/uapi/sound/asequencer.h +1 -0
@@ -561,6 +561,7 @@ struct snd_seq_query_subs {#define SNDRV_SEQ_IOCTL_CLIENT_ID _IOR ('S', 0x01, int)#define SNDRV_SEQ_IOCTL_SYSTEM_INFO _IOWR('S', 0x02, struct snd_seq_system_info)#define SNDRV_SEQ_IOCTL_RUNNING_MODE _IOWR('S', 0x03, struct snd_seq_running_info) +#define SNDRV_SEQ_IOCTL_USER_PVERSION _IOW('S', 0x04, int)#define SNDRV_SEQ_IOCTL_GET_CLIENT_INFO _IOWR('S', 0x10, struct snd_seq_client_info)#define SNDRV_SEQ_IOCTL_SET_CLIENT_INFO _IOW ('S', 0x11, struct snd_seq_client_info)
sound/core/seq/seq_clientmgr.c +8 -0
@@ -1056,6 +1056,12 @@ static int snd_seq_ioctl_pversion(struct snd_seq_client *client, void *arg)return 0 ; } +static int snd_seq_ioctl_user_pversion (struct snd_seq_client *client,void *arg) +{ + client->user_pversion = *(unsigned int *)arg; +return 0 ; +} +static int snd_seq_ioctl_client_id (struct snd_seq_client *client,void *arg) {int *client_id = arg;
@@ -1985,6 +1991,7 @@ static const struct ioctl_handler {int (*func)(struct snd_seq_client *client,void *arg); } ioctl_handlers[] = { { SNDRV_SEQ_IOCTL_PVERSION, snd_seq_ioctl_pversion }, + { SNDRV_SEQ_IOCTL_USER_PVERSION, snd_seq_ioctl_user_pversion }, { SNDRV_SEQ_IOCTL_CLIENT_ID, snd_seq_ioctl_client_id }, { SNDRV_SEQ_IOCTL_SYSTEM_INFO, snd_seq_ioctl_system_info }, { SNDRV_SEQ_IOCTL_RUNNING_MODE, snd_seq_ioctl_running_mode },
@@ -2125,6 +2132,7 @@ int snd_seq_create_kernel_client(struct snd_card *card, int client_index, client->accept_input =1 ; client->accept_output =1 ; client->data.kernel.card = card; + client->user_pversion =SNDRV_SEQ_VERSION ;va_start (args, name_fmt);vsnprintf (client->name,sizeof (client->name), name_fmt, args);
sound/core/seq/seq_clientmgr.h +1 -0
@@ -35,6 +35,7 @@ struct snd_seq_client {snd_seq_client_type_t type; unsigned int accept_input: 1, accept_output: 1; +unsigned int user_pversion;char name[64 ];/* client name */ int number;/* client number */ unsigned int filter;/* filter flags */
sound/core/seq/seq_compat.c +1 -0
@@ -81,6 +81,7 @@ static long snd_seq_ioctl_compat(struct file *file, unsigned int cmd, unsigned lswitch (cmd) {case SNDRV_SEQ_IOCTL_PVERSION : +case SNDRV_SEQ_IOCTL_USER_PVERSION :case SNDRV_SEQ_IOCTL_CLIENT_ID :case SNDRV_SEQ_IOCTL_SYSTEM_INFO :case SNDRV_SEQ_IOCTL_GET_CLIENT_INFO :
Signature · 1 line
2.35.3
PATCH v2 25/37 ALSA: seq: Add UMP support
In reply to Takashi IwaiStarting from this commit, we add the basic support of UMP (Universal MIDI Packet) events on ALSA sequencer infrastructure. The biggest change here is that, for transferring UMP packets that are up to 128 bits, we extend the data payload of ALSA sequencer event record when the client is declared to support for the new UMP events.
A new event flag bit, SNDRV_SEQ_EVENT_UMP, is defined and it shall be set for the UMP packet events that have the larger payload of 128 bits, defined as struct snd_seq_ump_event.
For controlling the UMP feature enablement in kernel, a new Kconfig, CONFIG_SND_SEQ_UMP is introduced. The extended event for UMP is available only when this Kconfig item is set. Similarly, the size of the internal snd_seq_event_cell also increases (in 4 bytes) when the Kconfig item is set. (But the size increase is effective only for 32bit architectures; 64bit archs already have padding there.) Overall, when CONFIG_SND_SEQ_UMP isn't set, there is no change in the event and cell, keeping the old sizes.
For applications that want to access the UMP packets, first of all, a sequencer client has to declare the user-protocol to match with the latest one via the new SNDRV_SEQ_IOCTL_USER_PVERSION; otherwise it's treated as if a legacy client without UMP support.
Then the client can switch to the new UMP mode (MIDI 1.0 or MIDI 2.0) with a new field, midi_version, in snd_seq_client_info. When switched to UMP mode (midi_version = 1 or 2), the client can write the UMP events with SNDRV_SEQ_EVENT_UMP flag. For reads, the alignment size is changed from snd_seq_event (28 bytes) to snd_seq_ump_event (32 bytes). When a UMP sequencer event is delivered to a legacy sequencer client, it's ignored or handled as an error.
Conceptually, ALSA sequencer client and port correspond to the UMP Endpoint and Group, respectively; each client may have multiple ports and each port has the fixed number (16) of channels, total up to 256 channels.
As of this commit, ALSA sequencer core just sends and receives the UMP events as-is from/to clients. The automatic conversions between the legacy events and the new UMP events will be implemented in a later patch.
Along with this commit, bump the sequencer protocol version to 1.0.3.
--- include/sound/asequencer.h | 4 + include/sound/seq_kernel.h | 8 ++ include/uapi/sound/asequencer.h | 53 +++++++---- sound/core/seq/Kconfig | 7 ++ sound/core/seq/seq_clientmgr.c | 156 +++++++++++++++++++++++--------- sound/core/seq/seq_clientmgr.h | 1 + sound/core/seq/seq_memory.c | 10 +- sound/core/seq/seq_memory.h | 19 +++- 8 files changed, 194 insertions(+), 64 deletions(-)
include/sound/asequencer.h +4 -0
@@ -65,6 +65,10 @@#define snd_seq_ev_is_abstime (ev) (snd_seq_ev_timemode_type(ev) == SNDRV_SEQ_TIME_MODE_ABS)#define snd_seq_ev_is_reltime (ev) (snd_seq_ev_timemode_type(ev) == SNDRV_SEQ_TIME_MODE_REL) +/* check whether the given event is a UMP event */ +#define snd_seq_ev_is_ump (ev) \ + (IS_ENABLED(CONFIG_SND_SEQ_UMP) && ((ev)->flags & SNDRV_SEQ_EVENT_UMP)) +/* queue sync port */ #define snd_seq_queue_sync_port (q) ((q) + 16)
include/sound/seq_kernel.h +8 -0
@@ -75,6 +75,14 @@ int snd_seq_expand_var_event_at(const struct snd_seq_event *event, int count,int snd_seq_dump_var_event (const struct snd_seq_event *event,snd_seq_dump_func_t func,void *private_data); +/* size of the event packet; it can be greater than snd_seq_event size */ +static inline size_t snd_seq_event_packet_size (struct snd_seq_event *ev) +{ +if (snd_seq_ev_is_ump (ev)) +return sizeof (struct snd_seq_ump_event ); +return sizeof (struct snd_seq_event ); +} +/* interface for OSS emulation */ int snd_seq_set_queue_tempo (int client,struct snd_seq_queue_tempo *tempo);
include/uapi/sound/asequencer.h +37 -16
90 lines not on this page · raw message
sound/core/seq/Kconfig +7 -0
@@ -60,4 +60,11 @@ config SND_SEQ_MIDI_EMUL config SND_SEQ_VIRMIDI tristate +config SND_SEQ_UMP + bool "Support for UMP events" + help + Say Y here to enable the support for handling UMP (Universal MIDI + Packet) events via ALSA sequencer infrastructure, which is an + essential feature for enabling MIDI 2.0 support. + endif # SND_SEQUENCER
sound/core/seq/seq_clientmgr.c +111 -45
315 lines not on this page · raw message
sound/core/seq/seq_clientmgr.h +1 -0
@@ -35,6 +35,7 @@ struct snd_seq_client {snd_seq_client_type_t type; unsigned int accept_input: 1, accept_output: 1; +unsigned int midi_version;unsigned int user_pversion;char name[64 ];/* client name */ int number;/* client number */
sound/core/seq/seq_memory.c +8 -2
@@ -340,6 +340,7 @@ int snd_seq_event_dup(struct snd_seq_pool *pool, struct snd_seq_event *event,int ncells, err;unsigned int extlen;struct snd_seq_event_cell *cell; +int size; *cellp =NULL ;
@@ -357,7 +358,12 @@ int snd_seq_event_dup(struct snd_seq_pool *pool, struct snd_seq_event *event,return err;/* copy the event */ - cell->event = *event; + size =snd_seq_event_packet_size (event); +memcpy (&cell->ump, event, size); +#if IS_ENABLED (CONFIG_SND_SEQ_UMP ) +if (size <sizeof (cell->event)) + cell->ump.raw.extra =0 ; +#endif /* decompose */ if (snd_seq_ev_is_variable (event)) {
@@ -375,7 +381,7 @@ int snd_seq_event_dup(struct snd_seq_pool *pool, struct snd_seq_event *event, tail =NULL ;while (ncells-- >0 ) { -int size =sizeof (struct snd_seq_event ); + size =sizeof (struct snd_seq_event );if (len < size) size = len; err = snd_seq_cell_alloc(pool, &tmp, nonblock, file,
sound/core/seq/seq_memory.h +18 -1
@@ -11,9 +11,26 @@struct snd_info_buffer ; +/* aliasing for legacy and UMP event packet handling */ +union __snd_seq_event { +struct snd_seq_event legacy; +#if IS_ENABLED (CONFIG_SND_SEQ_UMP ) +struct snd_seq_ump_event ump; +#endif +struct { +struct snd_seq_event event; +#if IS_ENABLED (CONFIG_SND_SEQ_UMP ) +u32 extra; +#endif + } __packed raw; +}; +/* container for sequencer event (internal use) */ struct snd_seq_event_cell { -struct snd_seq_event event; +union { +struct snd_seq_event event; +union __snd_seq_event ump; + };struct snd_seq_pool *pool;/* used pool */ struct snd_seq_event_cell *next;/* next cell */ };
Signature · 1 line
2.35.3
PATCH v2 26/37 ALSA: seq: Add port inactive flag
In reply to Takashi IwaiThis extends the ALSA sequencer port capability bit to indicate the "inactive" flag. When this flag is set, the port is essentially invisible, and doesn't appear in the port query ioctls, while the direct access and the connection to this port are still allowed. The active/inactive state can be flipped dynamically, so that it can be visible at any time later.
This feature is introduced basically for UMP; some UMP Groups in a UMP Block may be unassigned, hence those are practically invisible. On ALSA sequencer, the corresponding sequencer ports will get this new "inactive" flag to indicate the invisible state.
--- include/uapi/sound/asequencer.h | 1 + sound/core/seq/seq_clientmgr.c | 2 ++ sound/core/seq/seq_ports.c | 4 ++++ 3 files changed, 7 insertions(+)
include/uapi/sound/asequencer.h +1 -0
@@ -427,6 +427,7 @@ struct snd_seq_remove_events {#define SNDRV_SEQ_PORT_CAP_SUBS_READ (1<<5)/* allow read subscription */ #define SNDRV_SEQ_PORT_CAP_SUBS_WRITE (1<<6)/* allow write subscription */ #define SNDRV_SEQ_PORT_CAP_NO_EXPORT (1<<7)/* routing not allowed */ +#define SNDRV_SEQ_PORT_CAP_INACTIVE (1<<8)/* inactive port */ /* port type */ #define SNDRV_SEQ_PORT_TYPE_SPECIFIC (1<<0)/* hardware specific */
sound/core/seq/seq_clientmgr.c +2 -0
@@ -2416,6 +2416,8 @@ static void snd_seq_info_dump_ports(struct snd_info_buffer *buffer,mutex_lock (&client->ports_mutex);list_for_each_entry (p, &client->ports_list_head, list) { +if (p->capability &SNDRV_SEQ_PORT_CAP_INACTIVE ) +continue ; snd_iprintf(buffer, " Port %3d : \"%s\" (%c%c%c%c)\n", p->addr.port, p->name, FLAG_PERM_RD(p->capability),
sound/core/seq/seq_ports.c +4 -0
@@ -69,11 +69,15 @@ struct snd_seq_client_port *snd_seq_port_query_nearest(struct snd_seq_client *cl {int num;struct snd_seq_client_port *port, *found; +bool check_inactive = (pinfo->capability &SNDRV_SEQ_PORT_CAP_INACTIVE ); num = pinfo->addr.port; found =NULL ;read_lock (&client->ports_lock);list_for_each_entry (port, &client->ports_list_head, list) { +if ((port->capability &SNDRV_SEQ_PORT_CAP_INACTIVE ) && + !check_inactive) +continue ;/* skip inactive ports */ if (port->addr.port < num)continue ;if (port->addr.port == num) {
Signature · 1 line
2.35.3
PATCH v2 27/37 ALSA: seq: Support MIDI 2.0 UMP Endpoint port
In reply to Takashi IwaiThis is an extension to ALSA sequencer infrastructure to support the MIDI 2.0 UMP Endpoint port. It's a "catch-all" port that is supposed to be present for each UMP Endpoint. When this port is read via subscription, it sends any events from all ports (UMP Groups) found in the same client.
A UMP Endpoint port can be created with the new capability bit SNDRV_SEQ_PORT_CAP_UMP_ENDPOINT. Although the port assignment isn't strictly defined, it should be the port number 0.
--- include/uapi/sound/asequencer.h | 1 + sound/core/seq/seq_clientmgr.c | 47 +++++++++++++++++++++++++++------ sound/core/seq/seq_clientmgr.h | 1 + 3 files changed, 41 insertions(+), 8 deletions(-)
include/uapi/sound/asequencer.h +1 -0
@@ -428,6 +428,7 @@ struct snd_seq_remove_events {#define SNDRV_SEQ_PORT_CAP_SUBS_WRITE (1<<6)/* allow write subscription */ #define SNDRV_SEQ_PORT_CAP_NO_EXPORT (1<<7)/* routing not allowed */ #define SNDRV_SEQ_PORT_CAP_INACTIVE (1<<8)/* inactive port */ +#define SNDRV_SEQ_PORT_CAP_UMP_ENDPOINT (1<<9)/* MIDI 2.0 UMP Endpoint port */ /* port type */ #define SNDRV_SEQ_PORT_TYPE_SPECIFIC (1<<0)/* hardware specific */
sound/core/seq/seq_clientmgr.c +39 -8
91 lines not on this page · raw message
sound/core/seq/seq_clientmgr.h +1 -0
@@ -50,6 +50,7 @@ struct snd_seq_client {struct mutex ports_mutex;struct mutex ioctl_mutex;int convert32;/* convert 32->64bit */ +int ump_endpoint_port;/* output pool */ struct snd_seq_pool *pool;/* memory pool for this client */
Signature · 1 line
2.35.3
PATCH v2 28/37 ALSA: seq: Add port direction to snd_seq_port_info
In reply to Takashi IwaiAdd a new field "direction" to snd_seq_port_info for allowing a client to tell the expected direction of the port access. A port might still allow subscriptions for read/write (e.g. for MIDI-CI) even if the primary usage of the port is a single direction (either input or output only). This new "direction" field can help to indicate such cases.
When the direction is unspecified at creating a port and the port has either read or write capability, the corresponding direction bits are set automatically as default.
--- include/uapi/sound/asequencer.h | 9 ++++++++- sound/core/seq/seq_clientmgr.c | 16 ++++++++++++++-- sound/core/seq/seq_dummy.c | 1 + sound/core/seq/seq_midi.c | 4 ++++ sound/core/seq/seq_ports.c | 13 +++++++++++++ sound/core/seq/seq_ports.h | 2 ++ sound/core/seq/seq_virmidi.c | 1 + 7 files changed, 43 insertions(+), 3 deletions(-)
include/uapi/sound/asequencer.h +8 -1
@@ -455,6 +455,12 @@ struct snd_seq_remove_events {#define SNDRV_SEQ_PORT_FLG_TIMESTAMP (1<<1)#define SNDRV_SEQ_PORT_FLG_TIME_REAL (1<<2) +/* port direction */ +#define SNDRV_SEQ_PORT_DIR_UNKNOWN 0 +#define SNDRV_SEQ_PORT_DIR_INPUT 1 +#define SNDRV_SEQ_PORT_DIR_OUTPUT 2 +#define SNDRV_SEQ_PORT_DIR_BIDIRECTION 3 +struct snd_seq_port_info {struct snd_seq_addr addr;/* client/port numbers */ char name[64 ];/* port name */
@@ -471,7 +477,8 @@ struct snd_seq_port_info {void *kernel;/* reserved for kernel use (must be NULL) */ unsigned int flags;/* misc. conditioning */ unsigned char time_queue;/* queue # for timestamping */ -char reserved[59 ];/* for future use */ +unsigned char direction;/* port usage direction (r/w/bidir) */ +char reserved[58 ];/* for future use */ };
sound/core/seq/seq_clientmgr.c +14 -2
@@ -2440,6 +2440,17 @@ static void snd_seq_info_dump_subscribers(struct snd_info_buffer *buffer,#define FLAG_PERM_DUPLEX (perm) ((perm) & SNDRV_SEQ_PORT_CAP_DUPLEX ? 'X' : '-') +static const char *port_direction_name (unsigned char dir) +{ +static const char *names[4 ] = { +"-" ,"In" ,"Out" ,"In/Out" + }; + +if (dir >SNDRV_SEQ_PORT_DIR_BIDIRECTION ) +return "Invalid" ; +return names[dir]; +} +static void snd_seq_info_dump_ports (struct snd_info_buffer *buffer,struct snd_seq_client *client) {
@@ -2449,12 +2460,13 @@ static void snd_seq_info_dump_ports(struct snd_info_buffer *buffer,list_for_each_entry (p, &client->ports_list_head, list) {if (p->capability &SNDRV_SEQ_PORT_CAP_INACTIVE )continue ; -snd_iprintf (buffer," Port %3d : \"%s\" (%c%c%c%c)\n" , +snd_iprintf (buffer," Port %3d : \"%s\" (%c%c%c%c) [%s]\n" , p->addr.port, p->name,FLAG_PERM_RD (p->capability),FLAG_PERM_WR (p->capability),FLAG_PERM_EX (p->capability), -FLAG_PERM_DUPLEX (p->capability)); +FLAG_PERM_DUPLEX (p->capability), +port_direction_name (p->direction));snd_seq_info_dump_subscribers (buffer, &p->c_src,1 ," Connecting To: " );snd_seq_info_dump_subscribers (buffer, &p->c_dest,0 ," Connected From: " ); }
sound/core/seq/seq_dummy.c +1 -0
@@ -127,6 +127,7 @@ create_port(int idx, int type) pinfo.capability |=SNDRV_SEQ_PORT_CAP_WRITE |SNDRV_SEQ_PORT_CAP_SUBS_WRITE ;if (duplex) pinfo.capability |=SNDRV_SEQ_PORT_CAP_DUPLEX ; + pinfo.direction =SNDRV_SEQ_PORT_DIR_BIDIRECTION ; pinfo.type =SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC |SNDRV_SEQ_PORT_TYPE_SOFTWARE |SNDRV_SEQ_PORT_TYPE_PORT ;
sound/core/seq/seq_midi.c +4 -0
@@ -367,6 +367,10 @@ snd_seq_midisynth_probe(struct device *_dev)if ((port->capability & (SNDRV_SEQ_PORT_CAP_WRITE |SNDRV_SEQ_PORT_CAP_READ )) == (SNDRV_SEQ_PORT_CAP_WRITE |SNDRV_SEQ_PORT_CAP_READ ) && info->flags &SNDRV_RAWMIDI_INFO_DUPLEX ) port->capability |=SNDRV_SEQ_PORT_CAP_DUPLEX ; +if (port->capability &SNDRV_SEQ_PORT_CAP_READ ) + port->direction |=SNDRV_SEQ_PORT_DIR_INPUT ; +if (port->capability &SNDRV_SEQ_PORT_CAP_WRITE ) + port->direction |=SNDRV_SEQ_PORT_DIR_OUTPUT ; port->type =SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC |SNDRV_SEQ_PORT_TYPE_HARDWARE |SNDRV_SEQ_PORT_TYPE_PORT ;
sound/core/seq/seq_ports.c +13 -0
@@ -356,6 +356,16 @@ int snd_seq_set_port_info(struct snd_seq_client_port * port, port->time_real = (info->flags &SNDRV_SEQ_PORT_FLG_TIME_REAL ) ?1 :0 ; port->time_queue = info->time_queue; +/* direction */ + port->direction = info->direction; +/* fill default port direction */ +if (!port->direction) { +if (info->capability &SNDRV_SEQ_PORT_CAP_READ ) + port->direction |=SNDRV_SEQ_PORT_DIR_INPUT ; +if (info->capability &SNDRV_SEQ_PORT_CAP_WRITE ) + port->direction |=SNDRV_SEQ_PORT_DIR_OUTPUT ; + } +return 0 ; }
@@ -393,6 +403,9 @@ int snd_seq_get_port_info(struct snd_seq_client_port * port, info->time_queue = port->time_queue; } +/* direction */ + info->direction = port->direction; +return 0 ; }
sound/core/seq/seq_ports.h +2 -0
@@ -72,6 +72,8 @@ struct snd_seq_client_port {int midi_voices;int synth_voices; +/* direction */ +unsigned char direction; };struct snd_seq_client ;
sound/core/seq/seq_virmidi.c +1 -0
@@ -385,6 +385,7 @@ static int snd_virmidi_dev_attach_seq(struct snd_virmidi_dev *rdev) pinfo->capability |=SNDRV_SEQ_PORT_CAP_WRITE |SNDRV_SEQ_PORT_CAP_SYNC_WRITE |SNDRV_SEQ_PORT_CAP_SUBS_WRITE ; pinfo->capability |=SNDRV_SEQ_PORT_CAP_READ |SNDRV_SEQ_PORT_CAP_SYNC_READ |SNDRV_SEQ_PORT_CAP_SUBS_READ ; pinfo->capability |=SNDRV_SEQ_PORT_CAP_DUPLEX ; + pinfo->direction =SNDRV_SEQ_PORT_DIR_BIDIRECTION ; pinfo->type =SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC |SNDRV_SEQ_PORT_TYPE_SOFTWARE |SNDRV_SEQ_PORT_TYPE_PORT ;
Signature · 1 line
2.35.3
PATCH v2 29/37 ALSA: seq: Add UMP group number to snd_seq_port_info
In reply to Takashi IwaiAdd yet more new filed "ump_group" to snd_seq_port_info for specifying the associated UMP Group number for each sequencer port. This will be referred in the upcoming automatic UMP conversion in sequencer core.
--- include/uapi/sound/asequencer.h | 3 ++- sound/core/seq/seq_ports.c | 9 +++++++-- sound/core/seq/seq_ports.h | 3 ++- 3 files changed, 11 insertions(+), 4 deletions(-)
include/uapi/sound/asequencer.h +2 -1
@@ -478,7 +478,8 @@ struct snd_seq_port_info {unsigned int flags;/* misc. conditioning */ unsigned char time_queue;/* queue # for timestamping */ unsigned char direction;/* port usage direction (r/w/bidir) */ -char reserved[58 ];/* for future use */ +unsigned char ump_group;/* 0 = UMP EP (no conversion), 1-16 = UMP group number */ +char reserved[57 ];/* for future use */ };
sound/core/seq/seq_ports.c +7 -2
@@ -356,8 +356,12 @@ int snd_seq_set_port_info(struct snd_seq_client_port * port, port->time_real = (info->flags &SNDRV_SEQ_PORT_FLG_TIME_REAL ) ?1 :0 ; port->time_queue = info->time_queue; -/* direction */ +/* UMP direction and group */ port->direction = info->direction; + port->ump_group = info->ump_group; +if (port->ump_group >SNDRV_UMP_MAX_GROUPS ) + port->ump_group =0 ; +/* fill default port direction */ if (!port->direction) {if (info->capability &SNDRV_SEQ_PORT_CAP_READ )
@@ -403,8 +407,9 @@ int snd_seq_get_port_info(struct snd_seq_client_port * port, info->time_queue = port->time_queue; } -/* direction */ +/* UMP direction and group */ info->direction = port->direction; + info->ump_group = port->ump_group;return 0 ; }
sound/core/seq/seq_ports.h +2 -1
@@ -72,8 +72,9 @@ struct snd_seq_client_port {int midi_voices;int synth_voices; -/* direction */ +/* UMP direction and group */ unsigned char direction; +unsigned char ump_group; };struct snd_seq_client ;
Signature · 1 line
2.35.3
PATCH v2 30/37 ALSA: seq: Automatic conversion of UMP events
In reply to Takashi IwaiThis patch enables the automatic conversion of UMP events from/to the legacy ALSA sequencer MIDI events. Also, as UMP itself has two different modes (MIDI 1.0 and MIDI 2.0), yet another converters between them are needed, too. Namely, we have conversions between the legacy and UMP like:
- seq legacy event -> seq UMP MIDI 1.0 event
- seq legacy event -> seq UMP MIDI 2.0 event
- seq UMP MIDI 1.0 event -> seq legacy event
- seq UMP MIDI 2.0 event -> seq legacy event
and the conversions between UMP MIDI 1.0 and 2.0 clients like:
- seq UMP MIDI 1.0 event -> seq UMP MIDI 2.0 event
- seq UMP MIDI 2.0 event -> seq UMP MIDI 1.0 event
The translation is per best-effort; some MIDI 2.0 specific events are ignored when translated to MIDI 1.0.
--- sound/core/seq/Kconfig | 2 + sound/core/seq/Makefile | 1 + sound/core/seq/seq_clientmgr.c | 50 +- sound/core/seq/seq_clientmgr.h | 15 + sound/core/seq/seq_ports.h | 15 + sound/core/seq/seq_ump_convert.c | 1190 ++++++++++++++++++++++++++++++ sound/core/seq/seq_ump_convert.h | 22 + 7 files changed, 1280 insertions(+), 15 deletions(-) create mode 100644 sound/core/seq/seq_ump_convert.c create mode 100644 sound/core/seq/seq_ump_convert.h
sound/core/seq/Kconfig +2 -0
@@ -66,5 +66,7 @@ config SND_SEQ_UMP Say Y here to enable the support for handling UMP (Universal MIDI Packet) events via ALSA sequencer infrastructure, which is an essential feature for enabling MIDI 2.0 support. + It includes the automatic conversion of ALSA sequencer events + among legacy and UMP clients. endif # SND_SEQUENCER
sound/core/seq/Makefile +1 -0
@@ -8,6 +8,7 @@ snd-seq-objs := seq.o seq_lock.o seq_clientmgr.o seq_memory.o seq_queue.o \ seq_fifo.o seq_prioq.o seq_timer.o \ seq_system.o seq_ports.o snd-seq-$(CONFIG_SND_PROC_FS) += seq_info.o +snd-seq-$(CONFIG_SND_SEQ_UMP) += seq_ump_convert.o snd-seq-midi-objs := seq_midi.o snd-seq-midi-emul-objs := seq_midi_emul.o snd-seq-midi-event-objs := seq_midi_event.o
sound/core/seq/seq_clientmgr.c +35 -15
69 lines not on this page · raw message
sound/core/seq/seq_clientmgr.h +15 -0
@@ -85,6 +85,11 @@ int snd_seq_kernel_client_write_poll(int clientid, struct file *file, poll_tableint snd_seq_client_notify_subscription (int client,int port,struct snd_seq_port_subscribe *info,int evtype); +int __snd_seq_deliver_single_event (struct snd_seq_client *dest, +struct snd_seq_client_port *dest_port, +struct snd_seq_event *event, +int atomic,int hop); +/* only for OSS sequencer */ bool snd_seq_client_ioctl_lock (int clientid);void snd_seq_client_ioctl_unlock (int clientid);
@@ -95,4 +100,14 @@ extern int seq_client_load[15];struct snd_seq_client *snd_seq_kernel_client_get (int client);void snd_seq_kernel_client_put (struct snd_seq_client *cptr); +static inline bool snd_seq_client_is_ump (struct snd_seq_client *c) +{ +return c->midi_version !=SNDRV_SEQ_CLIENT_LEGACY_MIDI ; +} + +static inline bool snd_seq_client_is_midi2 (struct snd_seq_client *c) +{ +return c->midi_version ==SNDRV_SEQ_CLIENT_UMP_MIDI_2_0 ; +} +#endif
sound/core/seq/seq_ports.h +15 -0
@@ -42,6 +42,17 @@ struct snd_seq_port_subs_info {int (*close)(void *private_data,struct snd_seq_port_subscribe *info); }; +/* context for converting from legacy control event to UMP packet */ +struct snd_seq_ump_midi2_bank { +bool rpn_set; +bool nrpn_set; +bool bank_set; +unsigned char cc_rpn_msb, cc_rpn_lsb; +unsigned char cc_nrpn_msb, cc_nrpn_lsb; +unsigned char cc_data_msb, cc_data_lsb; +unsigned char cc_bank_msb, cc_bank_lsb; +}; +struct snd_seq_client_port {struct snd_seq_addr addr;/* client/port number */
@@ -75,6 +86,10 @@ struct snd_seq_client_port {/* UMP direction and group */ unsigned char direction;unsigned char ump_group; + +#if IS_ENABLED (CONFIG_SND_SEQ_UMP ) +struct snd_seq_ump_midi2_bank midi2_bank[16 ];/* per channel */ +#endif };struct snd_seq_client ;
sound/core/seq/seq_ump_convert.c new file +1190 -0
1,190 lines not on this page · raw message
sound/core/seq/seq_ump_convert.h new file +22 -0
@@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* ALSA sequencer event conversion between UMP and legacy clients +*/ +#ifndef __SEQ_UMP_CONVERT_H +#define __SEQ_UMP_CONVERT_H + +#include "seq_clientmgr.h" +#include "seq_ports.h" + +int snd_seq_deliver_from_ump (struct snd_seq_client *source, +struct snd_seq_client *dest, +struct snd_seq_client_port *dest_port, +struct snd_seq_event *event, +int atomic,int hop); +int snd_seq_deliver_to_ump (struct snd_seq_client *source, +struct snd_seq_client *dest, +struct snd_seq_client_port *dest_port, +struct snd_seq_event *event, +int atomic,int hop); + +#endif /* __SEQ_UMP_CONVERT_H */
Signature · 1 line
2.35.3
PATCH v2 31/37 ALSA: seq: Allow suppressing UMP conversions
In reply to Takashi IwaiA sequencer client like seq_dummy rather doesn't want to convert UMP events but receives / sends as is. Add a new event filter flag to suppress the automatic UMP conversion and applies accordingly.
--- include/uapi/sound/asequencer.h | 1 + sound/core/seq/seq_clientmgr.c | 18 ++++++++++-------- sound/core/seq/seq_dummy.c | 8 ++++++++ 3 files changed, 19 insertions(+), 8 deletions(-)
include/uapi/sound/asequencer.h +1 -0
@@ -347,6 +347,7 @@ typedef int __bitwise snd_seq_client_type_t;#define SNDRV_SEQ_FILTER_BROADCAST (1U<<0)/* accept broadcast messages */ #define SNDRV_SEQ_FILTER_MULTICAST (1U<<1)/* accept multicast messages */ #define SNDRV_SEQ_FILTER_BOUNCE (1U<<2)/* accept bounce event in error */ +#define SNDRV_SEQ_FILTER_NO_CONVERT (1U<<30)/* don't convert UMP events */ #define SNDRV_SEQ_FILTER_USE_EVENT (1U<<31)/* use event filter */ struct snd_seq_client_info {
sound/core/seq/seq_clientmgr.c +10 -8
@@ -671,14 +671,16 @@ static int snd_seq_deliver_single_event(struct snd_seq_client *client, dest_port->time_real);#if IS_ENABLED (CONFIG_SND_SEQ_UMP ) -if (snd_seq_ev_is_ump (event)) { - result =snd_seq_deliver_from_ump (client, dest, dest_port, - event, atomic, hop); - goto __skip; - }else if (snd_seq_client_is_ump (dest)) { - result =snd_seq_deliver_to_ump (client, dest, dest_port, - event, atomic, hop); - goto __skip; +if (!(dest->filter &SNDRV_SEQ_FILTER_NO_CONVERT )) { +if (snd_seq_ev_is_ump (event)) { + result =snd_seq_deliver_from_ump (client, dest, dest_port, + event, atomic, hop); + goto __skip; + }else if (snd_seq_client_is_ump (dest)) { + result =snd_seq_deliver_to_ump (client, dest, dest_port, + event, atomic, hop); + goto __skip; + } }#endif /* CONFIG_SND_SEQ_UMP */
sound/core/seq/seq_dummy.c +8 -0
@@ -152,6 +152,7 @@ static int __initregister_client (void) {struct snd_seq_dummy_port *rec1, *rec2; +struct snd_seq_client *client;int i;if (ports <1 ) {
@@ -165,6 +166,13 @@ register_client(void)if (my_client <0 )return my_client; +/* don't convert events but just pass-through */ + client =snd_seq_kernel_client_get (my_client); +if (!client) +return -EINVAL ; + client->filter =SNDRV_SEQ_FILTER_NO_CONVERT ; +snd_seq_kernel_client_put (client); +/* create ports */ for (i =0 ; i < ports; i++) { rec1 =create_port (i,0 );
Signature · 1 line
2.35.3
PATCH v2 32/37 ALSA: seq: Bind UMP device
In reply to Takashi IwaiThis patch introduces a new ALSA sequencer client for the kernel UMP object, snd-seq-ump-client. It's a UMP version of snd-seq-midi driver, while this driver creates a sequencer client per UMP endpoint which contains (fixed) 16 ports.
The UMP rawmidi device is opened in APPEND mode for output, so that multiple sequencer clients can share the same UMP endpoint, as well as the legacy UMP rawmidi devices that are opened in APPEND mode, too. For input, on the other hand, the incoming data is processed on the fly in the dedicated hook, hence it doesn't open a rawmidi device.
The UMP packet group is updated upon delivery depending on the target sequencer port (which corresponds to the actual UMP group).
Each sequencer port sets a new port type bit, SNDRV_SEQ_PORT_TYPE_MIDI_UMP, in addition to the other standard types for MIDI.
--- include/sound/seq_device.h | 1 + include/sound/ump.h | 15 +- include/uapi/sound/asequencer.h | 1 + sound/core/seq/Kconfig | 5 + sound/core/seq/Makefile | 2 + sound/core/seq/seq_ump_client.c | 389 ++++++++++++++++++++++++++++++++ sound/core/ump.c | 28 ++- 7 files changed, 439 insertions(+), 2 deletions(-) create mode 100644 sound/core/seq/seq_ump_client.c
include/sound/seq_device.h +1 -0
@@ -78,5 +78,6 @@ void snd_seq_driver_unregister(struct snd_seq_driver *drv);*/ #define SNDRV_SEQ_DEV_ID_MIDISYNTH "seq-midi"#define SNDRV_SEQ_DEV_ID_OPL3 "opl3-synth" +#define SNDRV_SEQ_DEV_ID_UMP "seq-ump-client"#endif /* __SOUND_SEQ_DEVICE_H */
include/sound/ump.h +14 -1
@@ -11,6 +11,7 @@ struct snd_ump_endpoint;struct snd_ump_block ;struct snd_ump_ops ;struct ump_cvt_to_ump ; +struct snd_seq_ump_ops ;struct snd_ump_endpoint {struct snd_rawmidi core;/* raw UMP access */
@@ -30,9 +31,9 @@ struct snd_ump_endpoint {int input_buf_head;int input_pending; -#if IS_ENABLED (CONFIG_SND_UMP_LEGACY_RAWMIDI )struct mutex open_mutex; +#if IS_ENABLED (CONFIG_SND_UMP_LEGACY_RAWMIDI )spinlock_t legacy_locks[2 ];struct snd_rawmidi *legacy_rmidi;struct snd_rawmidi_substream *legacy_substreams[2 ][SNDRV_UMP_MAX_GROUPS ];
@@ -42,6 +43,12 @@ struct snd_ump_endpoint {struct snd_rawmidi_file legacy_out_rfile;struct ump_cvt_to_ump *out_cvts;#endif + +#if IS_ENABLED (CONFIG_SND_SEQUENCER ) +struct snd_seq_device *seq_dev; +const struct snd_seq_ump_ops *seq_ops; +void *seq_client; +#endif };/* ops filled by UMP drivers */
@@ -52,6 +59,12 @@ struct snd_ump_ops {void (*drain)(struct snd_ump_endpoint *ump,int dir); }; +/* ops filled by sequencer binding */ +struct snd_seq_ump_ops { +void (*input_receive)(struct snd_ump_endpoint *ump, +const u32 *data,int words); +}; +struct snd_ump_block {struct snd_ump_block_info info;struct snd_ump_endpoint *ump;
include/uapi/sound/asequencer.h +1 -0
@@ -439,6 +439,7 @@ struct snd_seq_remove_events {#define SNDRV_SEQ_PORT_TYPE_MIDI_XG (1<<4)/* XG compatible device */ #define SNDRV_SEQ_PORT_TYPE_MIDI_MT32 (1<<5)/* MT-32 compatible device */ #define SNDRV_SEQ_PORT_TYPE_MIDI_GM2 (1<<6)/* General MIDI 2 compatible device */ +#define SNDRV_SEQ_PORT_TYPE_MIDI_UMP (1<<7)/* UMP */ /* other standards...*/ #define SNDRV_SEQ_PORT_TYPE_SYNTH (1<<10)/* Synth device (no MIDI compatible - direct wavetable) */
sound/core/seq/Kconfig +5 -0
@@ -62,6 +62,7 @@ config SND_SEQ_VIRMIDI config SND_SEQ_UMP bool "Support for UMP events" + default y if SND_SEQ_UMP_CLIENT help Say Y here to enable the support for handling UMP (Universal MIDI Packet) events via ALSA sequencer infrastructure, which is an
@@ -69,4 +70,8 @@ config SND_SEQ_UMP It includes the automatic conversion of ALSA sequencer events among legacy and UMP clients. +config SND_SEQ_UMP_CLIENT + tristate + def_tristate SND_UMP + endif # SND_SEQUENCER
sound/core/seq/Makefile +2 -0
@@ -14,12 +14,14 @@ snd-seq-midi-emul-objs := seq_midi_emul.o snd-seq-midi-event-objs := seq_midi_event.o snd-seq-dummy-objs := seq_dummy.o snd-seq-virmidi-objs := seq_virmidi.o +snd-seq-ump-client-objs := seq_ump_client.o obj-$(CONFIG_SND_SEQUENCER) += snd-seq.o obj-$(CONFIG_SND_SEQUENCER_OSS) += oss/ obj-$(CONFIG_SND_SEQ_DUMMY) += snd-seq-dummy.o obj-$(CONFIG_SND_SEQ_MIDI) += snd-seq-midi.o +obj-$(CONFIG_SND_SEQ_UMP_CLIENT) += snd-seq-ump-client.o obj-$(CONFIG_SND_SEQ_MIDI_EMUL) += snd-seq-midi-emul.o obj-$(CONFIG_SND_SEQ_MIDI_EVENT) += snd-seq-midi-event.o obj-$(CONFIG_SND_SEQ_VIRMIDI) += snd-seq-virmidi.o
sound/core/seq/seq_ump_client.c new file +389 -0
389 lines not on this page · raw message
sound/core/ump.c +27 -1
@@ -132,8 +132,8 @@ int snd_ump_endpoint_new(struct snd_card *card, char *id, int device,if (!ump)return -ENOMEM ;INIT_LIST_HEAD (&ump->block_list); -#if IS_ENABLED (CONFIG_SND_UMP_LEGACY_RAWMIDI )mutex_init (&ump->open_mutex); +#if IS_ENABLED (CONFIG_SND_UMP_LEGACY_RAWMIDI )spin_lock_init (&ump->legacy_locks[0 ]);spin_lock_init (&ump->legacy_locks[1 ]);#endif
@@ -166,8 +166,30 @@ EXPORT_SYMBOL_GPL(snd_ump_endpoint_new);* Device register / unregister hooks; * do nothing, placeholders for avoiding the default rawmidi handling */ + +#if IS_ENABLED (CONFIG_SND_SEQUENCER ) +static void snd_ump_dev_seq_free (struct snd_seq_device *device) +{ +struct snd_ump_endpoint *ump = device->private_data; + + ump->seq_dev =NULL ; +} +#endif +static int snd_ump_dev_register (struct snd_rawmidi *rmidi) { +#if IS_ENABLED (CONFIG_SND_SEQUENCER ) +struct snd_ump_endpoint *ump =rawmidi_to_ump (rmidi); +int err; + + err =snd_seq_device_new (ump->core.card, ump->core.device, +SNDRV_SEQ_DEV_ID_UMP ,0 , &ump->seq_dev); +if (err <0 ) +return err; + ump->seq_dev->private_data = ump; + ump->seq_dev->private_free = snd_ump_dev_seq_free; +snd_device_register (ump->core.card, ump->seq_dev); +#endif return 0 ; }
@@ -280,6 +302,10 @@ int snd_ump_receive(struct snd_ump_endpoint *ump, const u32 *buffer, int count) n =snd_ump_receive_ump_val (ump, *p++);if (!n)continue ; +#if IS_ENABLED (CONFIG_SND_SEQUENCER ) +if (ump->seq_ops) + ump->seq_ops->input_receive (ump, ump->input_buf, n); +#endif process_legacy_input (ump, ump->input_buf, n); }
Signature · 1 line
2.35.3
PATCH v2 33/37 ALSA: seq: ump: Create UMP Endpoint port for broadcast
In reply to Takashi IwaiCreate a sequencer port for broadcasting the all group inputs at the port number 0. This corresponds to a UMP Endpoint connection; application can read all UMP events from this port no matter which group the UMP packet belongs to.
Unlike seq ports for other UMP groups, a UMP Endpoint port has no SND_SEQ_PORT_TYPE_MIDI_GENERIC bit, so that it won't be treated as a normal MIDI 1.0 device from legacy applications.
The port is named as "MIDI 2.0" to align with representations on other operation systems.
--- sound/core/seq/seq_ump_client.c | 60 +++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+)
sound/core/seq/seq_ump_client.c +60 -0
@@ -290,6 +290,62 @@ static void update_group_attrs(struct seq_ump_client *client) } } +/* create a UMP Endpoint port */ +static int create_ump_endpoint_port (struct seq_ump_client *client) +{ +struct snd_seq_port_info *port; +struct snd_seq_port_callback pcallbacks; +unsigned int rawmidi_info = client->ump->core.info_flags; +int err; + + port =kzalloc (sizeof (*port),GFP_KERNEL ); +if (!port) +return -ENOMEM ; + + port->addr.client = client->seq_client; + port->addr.port =0 ;/* fixed */ + port->flags =SNDRV_SEQ_PORT_FLG_GIVEN_PORT ; + port->capability =SNDRV_SEQ_PORT_CAP_UMP_ENDPOINT ; +if (rawmidi_info &SNDRV_RAWMIDI_INFO_INPUT ) { + port->capability |=SNDRV_SEQ_PORT_CAP_READ | +SNDRV_SEQ_PORT_CAP_SYNC_READ | +SNDRV_SEQ_PORT_CAP_SUBS_READ ; + port->direction |=SNDRV_SEQ_PORT_DIR_INPUT ; + } +if (rawmidi_info &SNDRV_RAWMIDI_INFO_OUTPUT ) { + port->capability |=SNDRV_SEQ_PORT_CAP_WRITE | +SNDRV_SEQ_PORT_CAP_SYNC_WRITE | +SNDRV_SEQ_PORT_CAP_SUBS_WRITE ; + port->direction |=SNDRV_SEQ_PORT_DIR_OUTPUT ; + } +if (rawmidi_info &SNDRV_RAWMIDI_INFO_DUPLEX ) + port->capability |=SNDRV_SEQ_PORT_CAP_DUPLEX ; + port->ump_group =0 ;/* no associated group, no conversion */ + port->type =SNDRV_SEQ_PORT_TYPE_MIDI_UMP | +SNDRV_SEQ_PORT_TYPE_HARDWARE | +SNDRV_SEQ_PORT_TYPE_PORT ; + port->midi_channels =16 ; +strcpy (port->name,"MIDI 2.0" ); +memset (&pcallbacks,0 ,sizeof (pcallbacks)); + pcallbacks.owner =THIS_MODULE ; + pcallbacks.private_data = client; +if (rawmidi_info &SNDRV_RAWMIDI_INFO_INPUT ) { + pcallbacks.subscribe = seq_ump_subscribe; + pcallbacks.unsubscribe = seq_ump_unsubscribe; + } +if (rawmidi_info &SNDRV_RAWMIDI_INFO_OUTPUT ) { + pcallbacks.use = seq_ump_use; + pcallbacks.unuse = seq_ump_unuse; + pcallbacks.event_input = seq_ump_process_event; + } + port->kernel = &pcallbacks; + err =snd_seq_kernel_client_ctl (client->seq_client, +SNDRV_SEQ_IOCTL_CREATE_PORT , + port); +kfree (port); +return err; +} +/* release the client resources */ static void seq_ump_client_free (struct seq_ump_client *client) {
@@ -353,6 +409,10 @@ static int snd_seq_ump_probe(struct device *_dev) goto error; } + err =create_ump_endpoint_port (client); +if (err <0 ) + goto error; + ump->seq_client = client; ump->seq_ops = &seq_ump_ops;return 0 ;
Signature · 1 line
2.35.3
PATCH v2 34/37 ALSA: seq: Add ioctls for client UMP info query and setup
In reply to Takashi IwaiAdd new ioctls for sequencer clients to query and set the UMP endpoint and block information.
As a sequencer client corresponds to a UMP Endpoint, one UMP Endpoint information can be assigned at most to a single sequencer client while multiple UMP block infos can be assigned by passing the type with the offset of block id (i.e. type = block_id + 1).
For the kernel client, only SNDRV_SEQ_IOCTL_GET_CLIENT_UMP_INFO is allowed.
--- include/uapi/sound/asequencer.h | 14 ++++ sound/core/seq/seq_clientmgr.c | 120 +++++++++++++++++++++++++++++++- sound/core/seq/seq_clientmgr.h | 4 +- sound/core/seq/seq_compat.c | 2 + sound/core/seq/seq_ump_client.c | 15 ++++ 5 files changed, 153 insertions(+), 2 deletions(-)
include/uapi/sound/asequencer.h +14 -0
@@ -585,6 +585,18 @@ struct snd_seq_query_subs {char reserved[64 ];/* for future use */ }; +/* +* UMP-specific information +*/ +/* type of UMP info query */ +#define SNDRV_SEQ_CLIENT_UMP_INFO_ENDPOINT 0 +#define SNDRV_SEQ_CLIENT_UMP_INFO_BLOCK 1 + +struct snd_seq_client_ump_info { +int client;/* client number to inquire/set */ +int type;/* type to inquire/set */ +unsigned char info[512 ];/* info (either UMP ep or block info) */ +} __packed;/* * IOCTL commands
@@ -598,6 +610,8 @@ struct snd_seq_query_subs {#define SNDRV_SEQ_IOCTL_GET_CLIENT_INFO _IOWR('S', 0x10, struct snd_seq_client_info)#define SNDRV_SEQ_IOCTL_SET_CLIENT_INFO _IOW ('S', 0x11, struct snd_seq_client_info) +#define SNDRV_SEQ_IOCTL_GET_CLIENT_UMP_INFO _IOWR('S', 0x12, struct snd_seq_client_ump_info) +#define SNDRV_SEQ_IOCTL_SET_CLIENT_UMP_INFO _IOWR('S', 0x13, struct snd_seq_client_ump_info)#define SNDRV_SEQ_IOCTL_CREATE_PORT _IOWR('S', 0x20, struct snd_seq_port_info)#define SNDRV_SEQ_IOCTL_DELETE_PORT _IOW ('S', 0x21, struct snd_seq_port_info)
sound/core/seq/seq_clientmgr.c +119 -1
156 lines not on this page · raw message
sound/core/seq/seq_clientmgr.h +3 -1
@@ -12,7 +12,6 @@#include "seq_ports.h" #include "seq_lock.h" -/* client manager */ struct snd_seq_user_client {
@@ -59,6 +58,9 @@ struct snd_seq_client {struct snd_seq_user_client user;struct snd_seq_kernel_client kernel; } data; + +/* for UMP */ +void **ump_info; };/* usage statistics */
sound/core/seq/seq_compat.c +2 -0
@@ -86,6 +86,8 @@ static long snd_seq_ioctl_compat(struct file *file, unsigned int cmd, unsigned lcase SNDRV_SEQ_IOCTL_SYSTEM_INFO :case SNDRV_SEQ_IOCTL_GET_CLIENT_INFO :case SNDRV_SEQ_IOCTL_SET_CLIENT_INFO : +case SNDRV_SEQ_IOCTL_GET_CLIENT_UMP_INFO : +case SNDRV_SEQ_IOCTL_SET_CLIENT_UMP_INFO :case SNDRV_SEQ_IOCTL_SUBSCRIBE_PORT :case SNDRV_SEQ_IOCTL_UNSUBSCRIBE_PORT :case SNDRV_SEQ_IOCTL_CREATE_QUEUE :
sound/core/seq/seq_ump_client.c +15 -0
@@ -47,6 +47,7 @@ struct seq_ump_client {struct snd_rawmidi_file out_rfile;/* rawmidi for output */ struct seq_ump_input_buffer input;/* input parser context */ struct seq_ump_group groups[SNDRV_UMP_MAX_GROUPS ];/* table of groups */ +void *ump_info[SNDRV_UMP_MAX_BLOCKS +1 ];/* shadow of seq client ump_info */ };/* number of 32bit words for each UMP message type */
@@ -384,6 +385,8 @@ static int snd_seq_ump_probe(struct device *_dev)struct snd_ump_endpoint *ump = dev->private_data;struct snd_card *card = dev->card;struct seq_ump_client *client; +struct snd_ump_block *fb; +struct snd_seq_client *cptr;int p, err; client =kzalloc (sizeof (*client),GFP_KERNEL );
@@ -400,6 +403,10 @@ static int snd_seq_ump_probe(struct device *_dev) goto error; } + client->ump_info[0 ] = &ump->info; +list_for_each_entry (fb, &ump->block_list, list) + client->ump_info[fb->info.block_id +1 ] = &fb->info; +setup_client_midi_version (client);update_group_attrs (client);
@@ -413,6 +420,14 @@ static int snd_seq_ump_probe(struct device *_dev)if (err <0 ) goto error; + cptr =snd_seq_kernel_client_get (client->seq_client); +if (!cptr) { + err = -EINVAL ; + goto error; + } + cptr->ump_info = client->ump_info; +snd_seq_kernel_client_put (cptr); + ump->seq_client = client; ump->seq_ops = &seq_ump_ops;return 0 ;
Signature · 1 line
2.35.3
PATCH v2 35/37 ALSA: seq: Print UMP Endpoint and Block information in proc outputs
In reply to Takashi IwaiThis patch enhances the /proc/asound/seq/clients output to show a few more information about the assigned UMP Endpoint and Blocks.
The "Groups" are shown in 1-based group number to align with the sequencer client name and port number.
--- sound/core/seq/seq_clientmgr.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
sound/core/seq/seq_clientmgr.c +30 -0
@@ -2120,6 +2120,33 @@ static void terminate_ump_info_strings(void *p, int type) } } +#ifdef CONFIG_SND_PROC_FS +static void dump_ump_info (struct snd_info_buffer *buffer, +struct snd_seq_client *client) +{ +struct snd_ump_endpoint_info *ep; +struct snd_ump_block_info *bp; +int i; + +if (!client->ump_info) +return ; + ep = client->ump_info[SNDRV_SEQ_CLIENT_UMP_INFO_ENDPOINT ]; +if (ep && *ep->name) +snd_iprintf (buffer," UMP Endpoint: \"%s\"\n" , ep->name); +for (i =0 ; i <SNDRV_UMP_MAX_BLOCKS ; i++) { + bp = client->ump_info[i +1 ]; +if (bp && *bp->name) { +snd_iprintf (buffer," UMP Block %d: \"%s\" [%s]\n" , + i, bp->name, + bp->active ?"Active" :"Inactive" ); +snd_iprintf (buffer," Groups: %d-%d\n" , + bp->first_group +1 , + bp->first_group + bp->num_groups); + } + } +} +#endif +/* UMP-specific ioctls -- called directly without data copy */ static int snd_seq_ioctl_client_ump_info(struct snd_seq_client *caller, unsigned int cmd,
@@ -2654,6 +2681,9 @@ void snd_seq_info_clients_read(struct snd_info_entry *entry, c, client->name, client->type ==USER_CLIENT ?"User" :"Kernel" , midi_version_string(client->midi_version)); +#if IS_ENABLED (CONFIG_SND_SEQ_UMP ) +dump_ump_info (buffer, client); +#endif snd_seq_info_dump_ports (buffer, client);if (snd_seq_write_pool_allocated (client)) {snd_iprintf (buffer," Output pool :\n" );
Signature · 1 line
2.35.3
PATCH v2 36/37 ALSA: seq: Add UMP group filter
In reply to Takashi IwaiAdd a new filter bitmap for UMP groups for reducing the unnecessary read/write when the client is connected to UMP EP seq port.
The new group_filter field contains the bitmap for the groups, i.e. when the bit is set, the corresponding group is filtered out and the messages to that group won't be delivered.
The filter bitmap consists of each bit of 1-based UMP Group number. The bit 0 is reserved for the future use.
--- include/uapi/sound/asequencer.h | 3 ++- sound/core/seq/seq_clientmgr.c | 2 ++ sound/core/seq/seq_clientmgr.h | 1 + sound/core/seq/seq_ump_convert.c | 13 +++++++++++++ 4 files changed, 18 insertions(+), 1 deletion(-)
include/uapi/sound/asequencer.h +2 -1
@@ -362,7 +362,8 @@ struct snd_seq_client_info {int card;/* RO: card number[kernel] */ int pid;/* RO: pid[user] */ unsigned int midi_version;/* MIDI version */ -char reserved[52 ];/* for future use */ +unsigned int group_filter;/* UMP group filter bitmap (for 1-based Group indices) */ +char reserved[48 ];/* for future use */ };/* MIDI version numbers in client info */
sound/core/seq/seq_clientmgr.c +2 -0
@@ -1229,6 +1229,7 @@ static void get_client_info(struct snd_seq_client *cptr, info->filter = cptr->filter; info->event_lost = cptr->event_lost;memcpy (info->event_filter, cptr->event_filter,32 ); + info->group_filter = cptr->group_filter; info->num_ports = cptr->num_ports;if (cptr->type ==USER_CLIENT )
@@ -1290,6 +1291,7 @@ static int snd_seq_ioctl_set_client_info(struct snd_seq_client *client,if (client->user_pversion >=SNDRV_PROTOCOL_VERSION (1 ,0 ,3 )) client->midi_version = client_info->midi_version;memcpy (client->event_filter, client_info->event_filter,32 ); + client->group_filter = client_info->group_filter;return 0 ; }
sound/core/seq/seq_clientmgr.h +1 -0
@@ -40,6 +40,7 @@ struct snd_seq_client {int number;/* client number */ unsigned int filter;/* filter flags */ DECLARE_BITMAP (event_filter,256 ); +unsigned short group_filter;snd_use_lock_t use_lock;int event_lost;/* ports */
sound/core/seq/seq_ump_convert.c +13 -0
@@ -527,6 +527,17 @@ static int deliver_with_group_convert(struct snd_seq_client *dest, atomic, hop); } +/* apply the UMP event filter; return true to skip the event */ +static bool ump_event_filtered (struct snd_seq_client *dest, +const struct snd_seq_ump_event *ev) +{ +unsigned char group; + + group =ump_message_group (ev->ump[0 ]); +/* check the bitmap for 1-based group number */ +return dest->group_filter & (1U << (group +1 )); +} +/* Convert from UMP packet and deliver */ int snd_seq_deliver_from_ump(struct snd_seq_client *source, struct snd_seq_client *dest,
@@ -539,6 +550,8 @@ int snd_seq_deliver_from_ump(struct snd_seq_client *source,if (snd_seq_ev_is_variable (event))return 0 ;// skip, no variable event for UMP, so far +if (ump_event_filtered (dest, ump_ev)) +return 0 ;// skip if group filter is set and matching type =ump_message_type (ump_ev->ump[0 ]);if (snd_seq_client_is_ump (dest)) {
Signature · 1 line
2.35.3
PATCH v2 37/37 ALSA: docs: Add MIDI 2.0 documentation
In reply to Takashi IwaiAdd the brief document for describing the MIDI 2.0 implementation on Linux kernel. Both rawmidi and sequencer API extensions are described.
--- Documentation/sound/designs/index.rst | 1 + Documentation/sound/designs/midi-2.0.rst | 351 +++++++++++++++++++++++ 2 files changed, 352 insertions(+) create mode 100644 Documentation/sound/designs/midi-2.0.rst
Documentation/sound/designs/index.rst +1 -0
@@ -15,3 +15,4 @@ Designs and Implementations oss-emulation seq-oss jack-injection + midi-2.0
Documentation/sound/designs/midi-2.0.rst new file +351 -0
351 lines not on this page · raw message
Signature · 1 line
2.35.3
Hello I have a few questions:
1. As default, USB-audio driver will take the alternate setting for MIDI 2.0 interface: Does this mean that the ALSA driver will default to Alt Function 1 if it exists ?
2. What happens when using a kernel that does not support Alt Function 1 (MIDI 2.0) and device with a (much longer) MIDI 2.0 descriptor is attached ?
3. " However, user may let the driver falling back to the old MIDI 1.0 interface by a module option, too."
Can or how it this done via the ALSA API ? If the switch is made, does an ALSA client require to re-enumerate all the ports ?
4. Is there a way to force a specific device (port) to Legacy MIDI 1.0 ?
5. Is there a way , via ALSA, to select UMP MIDI 1.0 protocol instead of MIDI 2.0 UMP protocol.
6. To which protocol does the driver default ? UMP MIDI 1.0 or UMP MIDI 2.0 ?
7. Does the driver do anything related to Jitter Reduction ? How/is this supported via the ALSA API ?a
8. Does the driver do anything related to Bandwidth restriction ? How/is this supported via the ALSA API ?
9. Are/will UMP streaming messages be supported ? (new feature in MIDI 2.0 specification), if yes, how ?
10. Is function block information supported via ALSA, i.e added in the ALSA Port information ?
Quoted 4 lines · On Tue, 13 Jun 2023 14:41:07 +0200, [email protected] wrote:
Hello I have a few questions:
1. As default, USB-audio driver will take the alternate setting for MIDI 2.0 interface: Does this mean that the ALSA driver will default to Alt Function 1 if it exists ?
Yes.
Quoted 1 line
2. What happens when using a kernel that does not support Alt Function 1 (MIDI 2.0) and device with a (much longer) MIDI 2.0 descriptor is attached ?
It falls back to MIDI 1.0 interface.
Quoted 2 lines
3. " However, user may let the driver falling back to the old MIDI 1.0 interface by a module option, too." Can or how it this done via the ALSA API ?
You can't. Only via a module option or kconfig.
Quoted 2 lines
If the switch is made, does an ALSA client require to re-enumerate all the ports ?
4. Is there a way to force a specific device (port) to Legacy MIDI 1.0 ?
If demanded, we can implement a device-specific quirk for that.
Quoted 1 line
5. Is there a way , via ALSA, to select UMP MIDI 1.0 protocol instead of MIDI 2.0 UMP protocol.
Use the UMP 1.1 Streaming command to switch the protocol.
Quoted 1 line
6. To which protocol does the driver default ? UMP MIDI 1.0 or UMP MIDI 2.0 ?
Whatever the device sets as default.
Quoted 1 line
7. Does the driver do anything related to Jitter Reduction ? How/is this supported via the ALSA API ?a
JRTS is sent as normal UMP packet (also as sequencer events). No particular API is provided for JRTS, so far.
Quoted 1 line
8. Does the driver do anything related to Bandwidth restriction ? How/is this supported via the ALSA API ?
Currently no restriction is.
The bandwidth is provided via the API, but it's only for information.
Quoted 1 line
9. Are/will UMP streaming messages be supported ? (new feature in MIDI 2.0 specification), if yes, how ?
It was already implemented in kernel UMP core. See the recent posts.
Quoted 1 line
10. Is function block information supported via ALSA, i.e added in the ALSA Port information ?
Ditto.
Takashi
Many thanks, it seems that you already receive the new specs :-)
BTW I just joined this list, any my email address is shown in posts instead of the username as for other member is there a contact for this list (webmaster) to discuss this ? I could not find any contact for the admin.
Item 5. assume this is 7.1.6.2 Stream Configuration Request / 7.1.6.4 Stream Configuration Notification. Can it be done via the ALSA API ?
Quoted 2 lines · Happy Debugging
Many thanks, it seems that you already receive the new specs :-)
Yes, I was involved with the spec definition, too.
And, Linux/ALSA patches have been internally reviewed and discussed with MAA MIDI 2.0 WG for months before publishing.
Quoted 2 lines
BTW I just joined this list, any my email address is shown in posts instead of the username as for other member is there a contact for this list (webmaster) to discuss this ? I could not find any contact for the admin.
I guess it's rather your mailer setup?
Quoted 2 lines
Item 5. assume this is 7.1.6.2 Stream Configuration Request / 7.1.6.4 Stream Configuration Notification. Can it be done via the ALSA API ?
You can send a UMP packet.
Takashi
So great that the Linux community got involved early. :-) Mailer issue resolved, It seems it needs some time to take effect. "You can send an UMP packet" => it means to the raw midi device /dev/snd/umpC*D* ? That is not via an ALSA API call (yet) ?
I could not find the changes and UMP source files on https://github.com/torvalds/linux/tree/master/sound, is that correct ? I am trying to build a kernel with UMP support for testing UMP on a custom made development board.
Quoted 3 lines · Symbolic Debugger
I could not find the changes and UMP source files on https://github.com/torvalds/linux/tree/master/sound, is that correct ? I am trying to build a kernel with UMP support for testing UMP on a custom made development board.
All MIDI 2.0 stuff will be merged to 6.5 kernel. Currently it's found in linux-next or sound.git subsystem tree.
In sound.git tree, you can find some branches for the use on older kernels, too (topic/midi20, topic/midi20-6.1.y, topic/midi20-5.15.y, topic/midi20-5.10.y, topic/midi20-5.4.y).
Takashi
Quoted 7 lines · Takashi Iwai
Quoted 3 lines · Symbolic Debugger
I could not find the changes and UMP source files on https://github.com/torvalds/linux/tree/master/sound, is that correct ? I am trying to build a kernel with UMP support for testing UMP on a custom made development board.
Quoted 6 lines
All MIDI 2.0 stuff will be merged to 6.5 kernel. Currently it's found in linux-next or sound.git subsystem tree.
In sound.git tree, you can find some branches for the use on older kernels, too (topic/midi20, topic/midi20-6.1.y, topic/midi20-5.15.y, topic/midi20-5.10.y, topic/midi20-5.4.y).
FWIW, sound.git tree is found at:
https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git/
Takashi
That was indeed worth a lot. Built this sound.git on two machines:
make menuconfig
enabled:
* MIDI 2.0 Support by USB audio driver
* Support for UMP Events
Save to .config
make
Found to .ko files in usb folder:
snd-usb-audio.ko
sndmidi-lib.ko
Ubuntu 22.04 LTS (Linux H3 5.19.0-43-generic #44~22.04.1-Ubuntu) with 5.19 HWE Stack Option sudo insmod snd-usb-audio.ko
insmod: ERROR: could not insert module snd-usb-audio.ko: Invalid module format
Ubuntu 23.04 (runs in KVM) (Linux Ubuntu 6.2.0-20-generic)
sudo insmod snd-usb-audio.ko
insmod: ERROR: could not insert module snd-usb-audio.ko: Unknown symbol in module
[37207.309239] snd_usb_audio: Unknown symbol snd_ump_receive (err -2) [37207.309275] snd_usb_audio: Unknown symbol media_entity_pads_init (err -2) [37207.309289] snd_usb_audio: Unknown symbol media_remove_intf_link (err -2) [37207.309311] snd_usb_audio: Unknown symbol snd_usbmidi_resume (err -2) [37207.309420] snd_usb_audio: Unknown symbol media_device_delete (err -2) [37207.309434] snd_usb_audio: Unknown symbol snd_ump_endpoint_new (err -2) [37207.309440] snd_usb_audio: Unknown symbol media_devnode_create (err -2) [37207.309449] snd_usb_audio: Unknown symbol media_device_unregister_entity (err -2) [37207.309460] snd_usb_audio: Unknown symbol snd_usbmidi_disconnect (err -2) [37207.309468] snd_usb_audio: Unknown symbol media_device_usb_allocate (err -2)
Can it be done on 6.2 or 5.15 ?
How to insert the new module or build it so it can be used with a current kernel ?
How to proceed in case the existing module is use (rmmod) ? Canoncial does not provide kernel sources for newer kernels than 6.2 , like 6.4.0.rc2 of this sound.git, at least could not find them, but I did successfully built the 6.2 and 5.15 Ubuntu distro kernels already from their respective sources. Just copy the sound/usb and sound/core files over the current kernel sources, recompile it (of-course with and updated version number).
Well never mind... Finally !
uname -a
Linux Ubuntu 6.4.0-rc6-next-20230615 #3 SMP PREEMPT_DYNAMIC Fri Jun 16 17:48:44 CST 2023 x86_64 x86_64 x86_64 GNU/Linux
Quoted 5 lines · Symbolic Debugger
Well never mind... Finally !
uname -a
Linux Ubuntu 6.4.0-rc6-next-20230615 #3 SMPPREEMPT_DYNAMICFri Jun 16 17:48:44 CST 2023x86_64x86_64x86_64GNU/Linux
Good to hear that you made it :)
Actually, backporting the patches to 6.2 should be trivial, too. You can simply rebase the commits between v6.4-rc2..topic/midi20 onto 6.2 or 6.3 base.
As mentioned, the backports for other LTS branches are found on sound.git tree, which required a few more pieces and some corrections.
Takashi
Thanks a lot for the reply. I could try to re-base/backport the change onto the 6.2 kernel, but I am not very versed in git.. If there is a pointer to where how to do this backport, would be great. Now that I am on 6.4, the first step is to let the umpCxDx USB MIDI 2.0 device show up and then enumerate the ALSA ports (RAW or Sequencer) [ just C code] to find it there as well. P.S: I am not sure if this is the right place for the long conversation and support on this. I could create a server/channel on Discord.
An Attempt to replay the changes to 6.2 :
starting with linux-next (On branch next-20230614) as master
According to tag 6.4-rc2 the commit for it is f81fe2a4874338a1bfc599cae903a6101217b0a5
# reset the master to 6.4-rc2: $git reset --hard 581fe2a4874338a1bfc599cae903a6101217b0a5 $git checkout v6.2 Previous HEAD position was f1fcbaa18b28 Linux 6.4-rc2 HEAD is now at c9c3395d5e3d Linux 6.2 $git rebase master Successfully rebased and updated detached HEAD. $git checkout master Switched to branch 'master' Your branch is up to date with 'origin/master'. $git merge master Already up to date. Running menuconfig, there are no option for MIDI 2.0 / UMP, though the Makefile shows 6.4-rc6 and the ump files are in the source tree.
Quoted 4 lines · Symbolic Debugger
An Attempt to replay the changes to 6.2 :
starting with linux-next (On branch next-20230614) as master
According to tag 6.4-rc2 the commit for it isf81fe2a4874338a1bfc599cae903a6101217b0a5
Quoted 13 lines
# reset the master to 6.4-rc2: $git reset --hard 581fe2a4874338a1bfc599cae903a6101217b0a5 $git checkout v6.2 Previous HEAD position was f1fcbaa18b28 Linux 6.4-rc2 HEAD is now at c9c3395d5e3d Linux 6.2 $git rebase master Successfully rebased and updated detached HEAD. $git checkout master Switched to branch 'master' Your branch is up to date with 'origin/master'. $git merge master Already up to date. Running menuconfig, there are no option for MIDI 2.0 / UMP, though the Makefile shows 6.4-rc6 and the ump files are in the source tree.
Try the following:
% cd /somewhere/linux-next
% git reset --hard febdfa0e9c8a5d3a3d895245d1c294c26787daef % git rebase --onto v6.2 v6.4-rc2
The commit febdfa is the topmost commit of MIDI 2.0 stuff. This will plant the MIDI 2.0 stuff onto 6.2.
Alternatively:
% cd /somewhere/linux-stable
% git fetch /somewhere/linux-next febdfa0e9c8a5d3a3d895245d1c294c26787daef % git reset --hard FETCH_HEAD
% git rebase --onto origin/linux-6.2.y v6.4-rc2
This will be onto the latest 6.2.y stable, instead. If v6.4-rc2 tag isn't found, replace it with f1fcbaa18b28.
Takashi
All kernel 6.2 files build successfully ! P.S. I saw a reference to you on the NAMM booth. :-) Thank you so much !
I have a few question on the implementation
1. As stated above: So the driver may support multiple UMP Endpoints in theory, although most devices are supposed to have a single UMP EP that can contain up to 16 groups -- which should be large enough.
I read (forgot where) that Windows will only supports 1 endpoint) . This would results in maximum 16 I/O ports when using one group terminal block per endpoint. Correct ? In that case manufacturers may not create devices with multiple endpoints ... :-) ?
Per USB spec, One endpoint can support maximum 16 terminal blocks with each 16 groups so one endpoint in theory could support 256 (bi directional) groups and thus 512 ports (256 in/ 256 out)
2. If there is one in and and out terminal in an endpoint, then this will be presented as one in and one output port (in ALSA) ? Correct ?
3. bGrpTrmBlkType: are 0x00, 0x01 and 0x02 all supported ?
4. At the MIDI device, should OUT endpoints be BULK, and IN endpoints be INTERRUPT or BOTH BULK ? Page 21 of MIDI spec shows BULK for in and out but the descriptor example shows interrupt for IN. Page 19 states: MIDI Streaming Data Endpoints use bulk or interrupt transfers to exchange data with the Host
5. Are more than 1 Group Terminal Blocks supported by the driver for one endpoint ?
6. The current driver already uses the Group Terminal Blocks Descriptors Request ?
Quoted 7 lines · Symbolic Debugger
I have a few question on the implementation
1. As stated above: So the driver may support multiple UMP Endpoints in theory, although most devices are supposed to have a single UMP EP that can contain up to 16 groups -- which should be large enough.
I read (forgot where) that Windows will only supports 1 endpoint) . This would results in maximum 16 I/O ports when using one group terminal block per endpoint. Correct ? In that case manufacturers may not create devices with multiple endpoints ... :-) ?
Yes, that's my point in the above. It's not much expected that there will be multiple (UMP) Endpoints on a single device. In theory it's still possible, and the Linux driver supports it, but for now, it's supposed to be exceptional. Other OS don't seem supporting multiple EPs, in anyway.
Quoted 1 line
Per USB spec, One endpoint can support maximum 16 terminal blocks with each 16 groups so one endpoint in theory could support 256 (bi directional) groups and thus 512 ports (256 in/ 256 out)
One UMP EP can have up to 32 Function Blocks. But the actual limitation is rather the max number of UMP Groups (16) contained in a single EP.
Quoted 1 line
2. If there is one in and and out terminal in an endpoint, then this will be presented as one in and one output port (in ALSA) ? Correct ?
Not really, GTB or FB are merely meta data representing the associations of UMP Groups on a UMP Endpoint. The Groups included in a FB can be even changed dynamically during the runtime, too. The actual input and output entities are UMP Groups, which correspond to the former MIDI ports. GTB and FB indicate how those are tied.
BTW, a UMP Endpoint represents the bidirectional I/O by itself, so it's a pair of USB Endpoints.
Quoted 1 line
3. bGrpTrmBlkType: are
0x00,0x01and0x02all supported ?
Yes.
Quoted 1 line
4. At the MIDI device, should OUT endpoints be BULK, and IN endpoints be INTERRUPT or BOTH BULK ? Page 21 of MIDI spec shows BULK for in and out but the descriptor example shows interrupt for IN. Page 19 states: MIDI Streaming Data Endpoints use bulk or interrupt transfers to exchange data with the Host
AFAIK, in most cases, INT is used for MIDI 2.0 USB Input Endpoint, while BULK is used for USB Output Endpoint. (On USB MIDI 1.0 spec, both are BULK, although there have been a few vendor-specific variants, too). But the driver can work in ether way. It just depends on the USB descriptor.
Quoted 1 line
5. Are more than 1 Group Terminal Blocks supported by the driver for one endpoint ?
Yes, and that's the very key point of MIDI 2.0.
Quoted 1 line
6. The current driver already uses the Group Terminal Blocks Descriptors Request ?
Yes and no. On Linux driver, GTBs are referred at first only to find out a MIDI Endpoint pair. Then, the driver tries to issue the new UMP 1.1 Stream message to obtain the UMP Endpoint and Function Block information. On older devices that don't under those UMP 1.1 messages, the driver falls back and uses GTBs as the primary source for building a topology.
Takashi
Thanks for the notes. I read the (USB) spec again page 27/28. (well multiple times) and as I understood 1 endpoint has 1 or more multiple Group Terminal Blocks for which GTB each has 1 to 16 groups (group = in/out or bi = similar to one or two midi cables/ports) per terminal block The spec I have is from May 5th, 2020. i wonder how the driver get the Function Block information function blocks are not mentioned in the USB spec. Is there a a newer USB spec? if yes, it may make no sense to develop a device now if the descriptors and USB functions calls changed. Page 28 still refers to MIDI -CI protocol negotiation which already has been removed. It's a bit confusing. Would have been better to first release the updated USB spec before releasing the updated MIDI specs.
Quoted 2 lines · Symbolic Debugger
Thanks for the notes. I read the (USB) spec again page 27/28. (well multiple times) and as I understood 1 endpoint has 1 or more multiple Group Terminal Blocks for which GTB each has 1 to 16 groups (group = in/out or bi = similar to one or two midi cables/ports) per terminal block The spec I have is from May 5th, 2020. i wonder how the driver get the Function Block information function blocks are not mentioned in the USB spec. Is there a a newer USB spec? if yes, it may make no sense to develop a device now if the descriptors and USB functions calls changed. Page 28 still refers to MIDI -CI protocol negotiation which already has been removed. It's a bit confusing. Would have been better to first release the updated USB spec before releasing the updated MIDI specs.
Basically a UMP EP can have up to 16 groups, and GTB indicates which groups out of those can be managed together. And for the old USB MIDI 2.0 spec, groups in multiple GTBs have to be unique; i.e. if GTB#1 contains the group#1, the group#1 can't be found in another GTBs.
OTOH, the new UMP 1.1 spec allows the shared groups by multiple Function Blocks. For explicitly disallowing this new (rather confusing) behavior, "static block" flag was added in the FB info. When this bit is set, the FB is fixed and doesn't overlap, so that it's more or less compatible with GTB.
Note that Function Block is a new thing that was defined in UMP 1.1 spec. Naturally it didn't exist in the old USB MIDI 2.0 spec of year 2020. But, the concept of Function Block (and implementation) is rather about UMP, and it's independent from the transport layer; that is, USB MIDI 2.0 spec still applies as is, and won't be updated soon, AFAIK. It's a matter of the driver which information is used as the primary source: FB or GTB. The device should provide both info, in somehow compatible ways.
Takashi
Thanks again for your time to reply . I think my coin has dropped :-)
1 .So basically, we have GTB in the device descriptor and the FB information is an UMP call to the device by the ALSA driver. "The device should provide both info, in somehow compatible ways." . The process would be [a]. driver gets USB device descriptors, [b]. driver issues USB call to retrieve USB GTB descriptors and then [c] driver issues UMP stream call to retrieve the function block information. (if N/A, driver falls back on the GTB information). This information should be consistent with the groups defined in the GTB.
2. When creating the device descriptors and GTB descriptors based on the 2020 USB 2.0 spec, it should work ? Would those port show up in ALSA or can only be access via /dev/umpC*D*
3. w/o duplicates with 2 GTB's and for 32 groups, for example, it would be 1st GTB has group 1~16 and 2nd GTB 17~23 ?. A FB could use the groups from both GTB's for example Group1 and 17.
4. If two functions uses all 16 groups, that would use up all 32 FB's , correct ?
Quoted 4 lines · Symbolic Debugger
Thanks again for your time to reply . I think my coin has dropped :-)
1 .So basically, we have GTB in the device descriptor and the FB information is an UMP call to the device by the ALSA driver. "The device should provide both info, in somehow compatible ways." . The process would be [a]. driver gets USB device descriptors, [b]. driver issues USB call to retrieve USB GTB descriptors and then [c] driver issues UMP stream call to retrieve the function block information. (if N/A, driver falls back on the GTB information). This information should be consistent with the groups defined in the GTB.
Correct.
Quoted 1 line
2. When creating the device descriptors and GTB descriptors based on the 2020 USB 2.0 spec, it should work ? Would those port show up in ALSA or can only be access via
/dev/umpC*D*
Yes, there has been no change about the GTB itself; USB MIDI spec is unchanged. The recent MIDI 2.0 spec extended only UMP and MIDI-CI.
Quoted 1 line
3. w/o duplicates with 2 GTB's and for 32 groups, for example, it would be 1st GTB has group 1~16 and 2nd GTB 17~23 ?. A FB could use the groups from both GTB's for example Group1 and 17.
First of all: you can't have more than 16 groups (per direction) on a single EP. It's a hard limitation. So there can be no "Group 17". (A UMP Group can be bidirectional.)
Imagine other way round: you have max 16 in and 16 out UMP Groups where each Group has 16 channels, and GTB and FB just define how those Groups are assigned to which actual I/O. Some multiple Groups may belong to the I/O for the same purpose, and in that case, those Groups can be put into a single FB / GTB.
Quoted 1 line
4. If two functions uses all 16 groups, that would use up all 32 FB's , correct ?
If each FB contains one (single direction) Group and you have 16 in and 16 out Groups, then yes, it'll be up to 32 FBs and GTBs, which is the max number defined in the spec. But a FB / GTB can contain multiple Groups for the same purpose, so I guess taking all 32 FBs would be rather a rare case.
Takashi
Thanks again. Its getting much clearer now. To summarize:
[a] more than 1 Group Terminal Blocks are supported by the driver for one endpoint, but [b] you can't have more than 16 groups (per direction) on a single EP. and [c] if devices (mainly due to Windows) only support 1 EP, that would mean when using two GTB for 16 groups, one device cannot go beyond the 16 group limit. That would mean - in a rare corner case - to design ay a USB UMP (MIDI 1.0) interface that has legacy DIN I/O it can't go beyond 16 in and 16 OUT DIN connectors.
Perhaps a logical use for multiple GTB is to use one GTB per function, but on the others hand designers would probably won't take all that hassle if that if they can do with one GTB for all the functions, and mostly devices have two functions, one for voice data an one for firmware updates or other non-voice purposes.
I wish to program (C) against the new ALSA drivers. Understandably the current alsa-lib one is for the current kernel (up to 6.4) but since I have the kernel installed, I don't have the .h and .so files and distro's may include the packages (libasound) even later. Is there a interim library available before the kernel and distro's are updated ?
Quoted 2 lines · Symbolic Debugger
I wish to program (C) against the new ALSA drivers. Understandably the current alsa-lib one is for the current kernel (up to 6.4) but since I have the kernel installed, I don't have the .h and .so files and distro's may include the packages (libasound) even later. Is there a interim library available before the kernel and distro's are updated ?
The build of alsa-lib doesn't rely on the kernel headers installed on your system, as it has its own copies in the tree. You just need to update alsa-lib from the latest git version.
Takashi
That's what I thought and checked, but did not see newfile, but now I do, Perhaps I checked a wrong repo. I pulled the latest repo, compiled (gitcompile) but it did not generate .so but it reports lot of .lo files. I wish not to overwrite the current libasound.so., so should it be : make install with --libdir=<my directory> to generate the .so files ?
Quoted 2 lines · Symbolic Debugger
That's what I thought and checked, but did not see newfile, but now I do, Perhaps I checked a wrong repo. I pulled the latest repo, compiled (gitcompile) but it did not generate .so but it reports lot of .lo files. I wish not to overwrite the current libasound.so., so should it be : make install with --libdir=<my directory> to generate the .so files ?
You can try to install it to a temporary directory specified via DESTDIR variable as a test. Also, the libasound.so.2.0.0 can be found under src/.libs directory after the build. You can simply copy that, too.
But, for general build issues, better to ask your distro. Someone might have already a package built from the git repo, too.
Takashi
Great ! Found the files. Thanks so much. BTW found the discrepancy. I downloaded the 1.2.9 alsa-lib (tar) files from the alsa website which did not have ump files as they do in the git 1.2.9 repo. I found this https://packages.ubuntu.com/search?keywords=asound Seems libasound2-dev is based on 1.2.9 but is for the next distro release (23.10) . Strangely, in the file list there are no ump files.
Quoted 2 lines · Symbolic Debugger
Great ! Found the files. Thanks so much. BTW found the discrepancy. I downloaded the 1.2.9 alsa-lib (tar) files from the alsa website which did not have ump files as they do in the git 1.2.9 repo. I found this https://packages.ubuntu.com/search?keywords=asound Seems libasound2-dev is based on 1.2.9 but is for the next distro release (23.10) . Strangely, in the file list there are no ump files.
1.2.9 is the already released one. The UMP support *will* be included in 1.2.10, once when released. The git version is a bleeding edge code, that is, would-be-1.2.10.
Takashi
Thank you much. I should have everything now to start building.
A question about the implementation of notification messages (name, endpoint and function blocks)
The spec defines that these notification only get sent upon receiving a Discovery message.
Does this mean that the ALSA driver will poll at specific intervals to send a discover message or can the device send a notification even without a discovery message from the ALSA driver ? I could imagine a function block info / name, or endpoint info/ name or endpoint info change (i.e when the device changes the number of function block)
Quoted 6 lines · Symbolic Debugger
A question about the implementation of notification messages (name, endpoint and function blocks)
The spec defines that these notification only get sent upon receiving a Discovery message.
Does this mean that the ALSA driver will poll at specific intervals to send a discover message or can the device send a notification even without a discovery message from the ALSA driver ? I could imagine a function block info / name, or endpoint info/ name or endpoint info change (i.e when the device changes the number of function block)
It's handled in ALSA UMP core code. It doesn't poll but just interprets each incoming UMP messages and responds to it (e.g. when a notification comes from the device, ALSA core will update the information accordingly to be visible to user-space).
The change of FB info is indeed allowed by the device, AFAIK. And, this can notify via the corresponding UMP Stream messages. For example, reassigning UMP Groups in a FB is a valid scenario, and this will be informed via UMP Stream messages. For the FBs that will never change Groups, there is a "static blocks" flag (which was quite recently introduced). I guess most of devices mark this, as it's compatible with the former MIDI 2.0 USB devices.
BTW, the USB MIDI 2.0 gadget function driver is under development. It's almost ready, and my plan is to submit likely for 6.6 kernel (that is, in the next week or so). You can find the patches in topic/midi20-gadget branch of my sound.git tree.
Takashi