sound/usb/midi.c
Source file repositories/reference/linux-study-clean/sound/usb/midi.c
File Facts
- System
- Linux kernel
- Corpus path
sound/usb/midi.c- Extension
.c- Size
- 76160 bytes
- Lines
- 2654
- Domain
- Driver Families
- Bucket
- sound/usb
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/types.hlinux/bitops.hlinux/interrupt.hlinux/spinlock.hlinux/string.hlinux/init.hlinux/slab.hlinux/timer.hlinux/usb.hlinux/wait.hlinux/usb/audio.hlinux/usb/midi.hlinux/module.hsound/core.hsound/control.hsound/rawmidi.hsound/asequencer.husbaudio.hmidi.hpower.hhelper.h
Detected Declarations
struct snd_usb_midi_in_endpointstruct snd_usb_midi_out_endpointstruct snd_usb_midi_endpointstruct usb_protocol_opsstruct snd_usb_midistruct snd_usb_midi_endpointstruct snd_usb_midi_out_endpointstruct out_urb_contextstruct usbmidi_out_portstruct snd_usb_midi_in_endpointstruct usbmidi_in_portfunction snd_usbmidi_submit_urbfunction snd_usbmidi_urb_errorfunction snd_usbmidi_input_datafunction dump_urbfunction snd_usbmidi_in_urb_completefunction snd_usbmidi_out_urb_completefunction scoped_guardfunction snd_usbmidi_do_outputfunction snd_usbmidi_out_workfunction snd_usbmidi_error_timerfunction send_bulk_static_datafunction snd_usbmidi_standard_inputfunction snd_usbmidi_midiman_inputfunction snd_usbmidi_maudio_broken_running_status_inputfunction ch345_broken_sysex_inputfunction snd_usbmidi_cme_inputfunction snd_usbmidi_output_standard_packetfunction snd_usbmidi_output_midiman_packetfunction snd_usbmidi_transmit_bytefunction snd_usbmidi_standard_outputfunction portfunction snd_usbmidi_akai_outputfunction snd_usbmidi_novation_inputfunction snd_usbmidi_novation_outputfunction snd_usbmidi_raw_inputfunction snd_usbmidi_raw_outputfunction snd_usbmidi_ftdi_inputfunction snd_usbmidi_us122l_inputfunction snd_usbmidi_us122l_outputfunction snd_usbmidi_emagic_init_outfunction snd_usbmidi_emagic_finish_outfunction snd_usbmidi_emagic_inputfunction snd_usbmidi_emagic_outputfunction update_roland_altsettingfunction substream_openfunction snd_usbmidi_output_openfunction snd_usbmidi_output_close
Annotated Snippet
struct usb_protocol_ops {
void (*input)(struct snd_usb_midi_in_endpoint*, uint8_t*, int);
void (*output)(struct snd_usb_midi_out_endpoint *ep, struct urb *urb);
void (*output_packet)(struct urb*, uint8_t, uint8_t, uint8_t, uint8_t);
void (*init_out_endpoint)(struct snd_usb_midi_out_endpoint *);
void (*finish_out_endpoint)(struct snd_usb_midi_out_endpoint *);
};
struct snd_usb_midi {
struct usb_device *dev;
struct snd_card *card;
struct usb_interface *iface;
const struct snd_usb_audio_quirk *quirk;
struct snd_rawmidi *rmidi;
const struct usb_protocol_ops *usb_protocol_ops;
struct list_head list;
struct timer_list error_timer;
spinlock_t disc_lock;
struct rw_semaphore disc_rwsem;
struct mutex mutex;
u32 usb_id;
int next_midi_device;
struct snd_usb_midi_endpoint {
struct snd_usb_midi_out_endpoint *out;
struct snd_usb_midi_in_endpoint *in;
} endpoints[MIDI_MAX_ENDPOINTS];
unsigned long input_triggered;
unsigned int opened[2];
unsigned char disconnected;
unsigned char input_running;
struct snd_kcontrol *roland_load_ctl;
};
struct snd_usb_midi_out_endpoint {
struct snd_usb_midi *umidi;
struct out_urb_context {
struct urb *urb;
struct snd_usb_midi_out_endpoint *ep;
} urbs[OUTPUT_URBS];
unsigned int active_urbs;
unsigned int drain_urbs;
int max_transfer; /* size of urb buffer */
struct work_struct work;
unsigned int next_urb;
spinlock_t buffer_lock;
struct usbmidi_out_port {
struct snd_usb_midi_out_endpoint *ep;
struct snd_rawmidi_substream *substream;
int active;
uint8_t cable; /* cable number << 4 */
uint8_t state;
#define STATE_UNKNOWN 0
#define STATE_1PARAM 1
#define STATE_2PARAM_1 2
#define STATE_2PARAM_2 3
#define STATE_SYSEX_0 4
#define STATE_SYSEX_1 5
#define STATE_SYSEX_2 6
uint8_t data[2];
} ports[0x10];
int current_port;
wait_queue_head_t drain_wait;
};
struct snd_usb_midi_in_endpoint {
struct snd_usb_midi *umidi;
struct urb *urbs[INPUT_URBS];
struct usbmidi_in_port {
struct snd_rawmidi_substream *substream;
u8 running_status_length;
} ports[0x10];
u8 seen_f5;
bool in_sysex;
u8 last_cin;
u8 error_resubmit;
int current_port;
};
static void snd_usbmidi_do_output(struct snd_usb_midi_out_endpoint *ep);
static const uint8_t snd_usbmidi_cin_length[] = {
0, 0, 2, 3, 3, 1, 2, 3, 3, 3, 3, 3, 2, 2, 3, 1
};
/*
* Submits the URB, with error handling.
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/types.h`, `linux/bitops.h`, `linux/interrupt.h`, `linux/spinlock.h`, `linux/string.h`, `linux/init.h`, `linux/slab.h`.
- Detected declarations: `struct snd_usb_midi_in_endpoint`, `struct snd_usb_midi_out_endpoint`, `struct snd_usb_midi_endpoint`, `struct usb_protocol_ops`, `struct snd_usb_midi`, `struct snd_usb_midi_endpoint`, `struct snd_usb_midi_out_endpoint`, `struct out_urb_context`, `struct usbmidi_out_port`, `struct snd_usb_midi_in_endpoint`.
- Atlas domain: Driver Families / sound/usb.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.