drivers/usb/gadget/function/f_midi2.c
Source file repositories/reference/linux-study-clean/drivers/usb/gadget/function/f_midi2.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/gadget/function/f_midi2.c- Extension
.c- Size
- 74783 bytes
- Lines
- 2893
- Domain
- Driver Families
- Bucket
- drivers/usb
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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/device.hlinux/kernel.hlinux/module.hlinux/slab.hsound/core.hsound/control.hsound/ump.hsound/ump_msg.hsound/ump_convert.hlinux/usb/ch9.hlinux/usb/func_utils.hlinux/usb/gadget.hlinux/usb/audio.hlinux/usb/midi-v2.hu_midi2.h
Detected Declarations
struct f_midi2struct f_midi2_epstruct f_midi2_usb_epstruct f_midi2_req_ctxstruct f_midi2_usb_epstruct f_midi2_blockstruct f_midi2_midi1_portstruct f_midi2_epstruct midi1_cable_mappingstruct f_midi2struct f_midi2_usb_configfunction put_empty_requestfunction queue_request_ep_rawfunction queue_request_ep_infunction reply_ep_infunction reply_ump_stream_ep_infofunction reply_ump_stream_ep_devicefunction reply_ump_stream_stringfunction reply_ump_stream_ep_namefunction reply_ump_stream_ep_pidfunction reply_ump_stream_ep_configfunction reply_ump_stream_fb_infofunction reply_ump_stream_fb_namefunction process_ump_stream_msgfunction process_umpfunction f_midi2_ep_out_completefunction process_ump_transmitfunction f_midi2_ep_in_completefunction MIDI1function process_midi1_pending_buffunction fill_midi1_pending_buffunction process_midi1_transmitfunction f_midi2_midi1_ep_in_completefunction f_midi2_midi1_ep_out_completefunction f_midi2_start_epfunction f_midi2_drop_reqsfunction f_midi2_alloc_ep_reqsfunction f_midi2_free_ep_reqsfunction f_midi2_init_epfunction f_midi2_free_epfunction f_midi2_queue_out_reqsfunction f_midi2_stop_epsfunction f_midi2_start_epsfunction f_midi2_set_altfunction f_midi2_get_altfunction ump_to_usb_dirfunction assign_block_descriptorsfunction f_midi2_setup
Annotated Snippet
struct f_midi2_req_ctx {
struct f_midi2_usb_ep *usb_ep; /* belonging USB EP */
unsigned int index; /* array index: 0-31 */
struct usb_request *req; /* assigned request */
};
/* Resources for a USB Endpoint */
struct f_midi2_usb_ep {
struct f_midi2 *card; /* belonging card */
struct f_midi2_ep *ep; /* belonging UMP EP (optional) */
struct usb_ep *usb_ep; /* assigned USB EP */
void (*complete)(struct usb_ep *usb_ep, struct usb_request *req);
unsigned long free_reqs; /* bitmap for unused requests */
unsigned int num_reqs; /* number of allocated requests */
struct f_midi2_req_ctx *reqs; /* request context array */
};
/* Resources for UMP Function Block (and USB Group Terminal Block) */
struct f_midi2_block {
struct f_midi2_block_info info; /* FB info, copied from configfs */
struct snd_ump_block *fb; /* assigned FB */
unsigned int gtb_id; /* assigned GTB id */
unsigned int string_id; /* assigned string id */
};
/* Temporary buffer for altset 0 MIDI 1.0 handling */
struct f_midi2_midi1_port {
unsigned int pending; /* pending bytes on the input buffer */
u8 buf[32]; /* raw MIDI 1.0 byte input */
u8 state; /* running status */
u8 data[2]; /* rendered USB MIDI 1.0 packet data */
};
/* MIDI 1.0 message states */
enum {
STATE_INITIAL = 0, /* pseudo state */
STATE_1PARAM,
STATE_2PARAM_1,
STATE_2PARAM_2,
STATE_SYSEX_0,
STATE_SYSEX_1,
STATE_SYSEX_2,
STATE_REAL_TIME,
STATE_FINISHED, /* pseudo state */
};
/* Resources for UMP Endpoint */
struct f_midi2_ep {
struct snd_ump_endpoint *ump; /* assigned UMP EP */
struct f_midi2 *card; /* belonging MIDI 2.0 device */
struct f_midi2_ep_info info; /* UMP EP info, copied from configfs */
unsigned int num_blks; /* number of FBs */
struct f_midi2_block blks[SNDRV_UMP_MAX_BLOCKS]; /* UMP FBs */
struct f_midi2_usb_ep ep_in; /* USB MIDI EP-in */
struct f_midi2_usb_ep ep_out; /* USB MIDI EP-out */
u8 in_group_to_cable[SNDRV_UMP_MAX_GROUPS]; /* map to cable; 1-based! */
};
/* indices for USB strings */
enum {
STR_IFACE = 0,
STR_GTB1 = 1,
};
/* 1-based GTB id to string id */
#define gtb_to_str_id(id) (STR_GTB1 + (id) - 1)
/* mapping from MIDI 1.0 cable to UMP group */
struct midi1_cable_mapping {
struct f_midi2_ep *ep;
unsigned char block;
unsigned char group;
};
/* operation mode */
enum {
MIDI_OP_MODE_UNSET, /* no altset set yet */
MIDI_OP_MODE_MIDI1, /* MIDI 1.0 (altset 0) is used */
MIDI_OP_MODE_MIDI2, /* MIDI 2.0 (altset 1) is used */
};
/* Resources for MIDI 2.0 Device */
struct f_midi2 {
struct usb_function func;
struct usb_gadget *gadget;
struct snd_card *card;
Annotation
- Immediate include surface: `linux/device.h`, `linux/kernel.h`, `linux/module.h`, `linux/slab.h`, `sound/core.h`, `sound/control.h`, `sound/ump.h`, `sound/ump_msg.h`.
- Detected declarations: `struct f_midi2`, `struct f_midi2_ep`, `struct f_midi2_usb_ep`, `struct f_midi2_req_ctx`, `struct f_midi2_usb_ep`, `struct f_midi2_block`, `struct f_midi2_midi1_port`, `struct f_midi2_ep`, `struct midi1_cable_mapping`, `struct f_midi2`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: source 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.