Lines Matching defs:ump
13 #include <sound/ump.h>
16 #define ump_err(ump, fmt, args...) dev_err((ump)->core.dev, fmt, ##args)
17 #define ump_warn(ump, fmt, args...) dev_warn((ump)->core.dev, fmt, ##args)
18 #define ump_info(ump, fmt, args...) dev_info((ump)->core.dev, fmt, ##args)
19 #define ump_dbg(ump, fmt, args...) dev_dbg((ump)->core.dev, fmt, ##args)
33 static void ump_handle_stream_msg(struct snd_ump_endpoint *ump,
36 static int process_legacy_output(struct snd_ump_endpoint *ump,
38 static void process_legacy_input(struct snd_ump_endpoint *ump, const u32 *src,
41 static inline int process_legacy_output(struct snd_ump_endpoint *ump,
46 static inline void process_legacy_input(struct snd_ump_endpoint *ump,
74 struct snd_ump_endpoint *ump = rawmidi_to_ump(rmidi);
77 while (!list_empty(&ump->block_list)) {
78 fb = list_first_entry(&ump->block_list, struct snd_ump_block,
86 if (ump->private_free)
87 ump->private_free(ump);
90 kfree(ump->out_cvts);
123 struct snd_ump_endpoint *ump;
133 ump = kzalloc(sizeof(*ump), GFP_KERNEL);
134 if (!ump)
136 INIT_LIST_HEAD(&ump->block_list);
137 mutex_init(&ump->open_mutex);
138 init_waitqueue_head(&ump->stream_wait);
140 spin_lock_init(&ump->legacy_locks[0]);
141 spin_lock_init(&ump->legacy_locks[1]);
143 err = snd_rawmidi_init(&ump->core, card, id, device,
146 snd_rawmidi_free(&ump->core);
150 ump->info.card = card->number;
151 ump->info.device = device;
153 ump->core.private_free = snd_ump_endpoint_free;
154 ump->core.ops = &snd_ump_rawmidi_ops;
156 snd_rawmidi_set_ops(&ump->core, SNDRV_RAWMIDI_STREAM_INPUT,
159 snd_rawmidi_set_ops(&ump->core, SNDRV_RAWMIDI_STREAM_OUTPUT,
162 ump_dbg(ump, "Created a UMP EP #%d (%s)\n", device, id);
163 *ump_ret = ump;
176 struct snd_ump_endpoint *ump = device->private_data;
178 ump->seq_dev = NULL;
185 struct snd_ump_endpoint *ump = rawmidi_to_ump(rmidi);
188 err = snd_seq_device_new(ump->core.card, ump->core.device,
189 SNDRV_SEQ_DEV_ID_UMP, 0, &ump->seq_dev);
192 ump->seq_dev->private_data = ump;
193 ump->seq_dev->private_free = snd_ump_dev_seq_free;
194 snd_device_register(ump->core.card, ump->seq_dev);
205 snd_ump_get_block(struct snd_ump_endpoint *ump, unsigned char id)
209 list_for_each_entry(fb, &ump->block_list, list) {
221 struct snd_ump_endpoint *ump = rawmidi_to_ump(substream->rmidi);
225 if (ump->substreams[dir])
227 err = ump->ops->open(ump, dir);
230 ump->substreams[dir] = substream;
236 struct snd_ump_endpoint *ump = rawmidi_to_ump(substream->rmidi);
239 ump->substreams[dir] = NULL;
240 ump->ops->close(ump, dir);
247 struct snd_ump_endpoint *ump = rawmidi_to_ump(substream->rmidi);
250 ump->ops->trigger(ump, dir, up);
255 struct snd_ump_endpoint *ump = rawmidi_to_ump(substream->rmidi);
257 if (ump->ops->drain)
258 ump->ops->drain(ump, SNDRV_RAWMIDI_STREAM_OUTPUT);
268 * @ump: UMP endpoint
271 * The data is copied onto ump->input_buf[].
275 int snd_ump_receive_ump_val(struct snd_ump_endpoint *ump, u32 val)
279 if (!ump->input_pending)
280 ump->input_pending = ump_packet_words[ump_message_type(val)];
282 ump->input_buf[ump->input_buf_head++] = val;
283 ump->input_pending--;
284 if (!ump->input_pending) {
285 words = ump->input_buf_head;
286 ump->input_buf_head = 0;
295 * @ump: the UMP endpoint
303 int snd_ump_receive(struct snd_ump_endpoint *ump, const u32 *buffer, int count)
310 n = snd_ump_receive_ump_val(ump, *p++);
313 ump_handle_stream_msg(ump, ump->input_buf, n);
315 if (ump->seq_ops)
316 ump->seq_ops->input_receive(ump, ump->input_buf, n);
318 process_legacy_input(ump, ump->input_buf, n);
321 substream = ump->substreams[SNDRV_RAWMIDI_STREAM_INPUT];
330 * @ump: the UMP endpoint
338 int snd_ump_transmit(struct snd_ump_endpoint *ump, u32 *buffer, int count)
341 ump->substreams[SNDRV_RAWMIDI_STREAM_OUTPUT];
350 return process_legacy_output(ump, buffer, count);
356 * @ump: UMP object
363 int snd_ump_block_new(struct snd_ump_endpoint *ump, unsigned int blk,
372 if (snd_ump_get_block(ump, blk))
379 fb->ump = ump;
380 fb->info.card = ump->info.card;
381 fb->info.device = ump->info.device;
383 if (blk >= ump->info.num_blocks)
384 ump->info.num_blocks = blk + 1;
394 list_for_each_entry(p, &ump->block_list, list) {
400 list_add_tail(&fb->list, &ump->block_list);
403 ump_dbg(ump, "Created a UMP Block #%d (%s)\n", blk, fb->info.name);
409 static int snd_ump_ioctl_block(struct snd_ump_endpoint *ump,
417 fb = snd_ump_get_block(ump, id);
431 struct snd_ump_endpoint *ump = rawmidi_to_ump(rmidi);
435 if (copy_to_user(argp, &ump->info, sizeof(ump->info)))
439 return snd_ump_ioctl_block(ump, argp);
441 ump_dbg(ump, "rawmidi: unknown command = 0x%x\n", cmd);
479 struct snd_ump_endpoint *ump = rawmidi_to_ump(rmidi);
482 snd_iprintf(buffer, "EP Name: %s\n", ump->info.name);
483 snd_iprintf(buffer, "EP Product ID: %s\n", ump->info.product_id);
484 snd_iprintf(buffer, "UMP Version: 0x%04x\n", ump->info.version);
485 snd_iprintf(buffer, "Protocol Caps: 0x%08x\n", ump->info.protocol_caps);
486 snd_iprintf(buffer, "Protocol: 0x%08x\n", ump->info.protocol);
487 if (ump->info.version) {
489 ump->info.manufacturer_id);
490 snd_iprintf(buffer, "Family ID: 0x%04x\n", ump->info.family_id);
491 snd_iprintf(buffer, "Model ID: 0x%04x\n", ump->info.model_id);
493 ump->info.sw_revision[0],
494 ump->info.sw_revision[1],
495 ump->info.sw_revision[2],
496 ump->info.sw_revision[3]);
499 (ump->info.flags & SNDRV_UMP_EP_INFO_STATIC_BLOCKS) ? "Yes" : "No");
500 snd_iprintf(buffer, "Num Blocks: %d\n\n", ump->info.num_blocks);
502 list_for_each_entry(fb, &ump->block_list, list) {
515 if (ump->info.version) {
532 static int ump_request_open(struct snd_ump_endpoint *ump)
534 return snd_rawmidi_kernel_open(&ump->core, 0,
536 &ump->stream_rfile);
539 static void ump_request_close(struct snd_ump_endpoint *ump)
541 snd_rawmidi_kernel_release(&ump->stream_rfile);
548 static int ump_req_msg(struct snd_ump_endpoint *ump, u32 req1, u32 req2,
553 ump_dbg(ump, "%s: request %08x %08x, wait-for %08x\n",
558 ump->stream_finished = 0;
559 ump->stream_wait_for = reply;
560 snd_rawmidi_kernel_write(ump->stream_rfile.output,
562 wait_event_timeout(ump->stream_wait, ump->stream_finished,
564 if (!READ_ONCE(ump->stream_finished)) {
565 ump_dbg(ump, "%s: request timed out\n", __func__);
568 ump->stream_finished = 0;
569 ump_dbg(ump, "%s: reply: %08x %08x %08x %08x\n",
577 static int ump_append_string(struct snd_ump_endpoint *ump, char *dest,
606 static int ump_handle_ep_info_msg(struct snd_ump_endpoint *ump,
609 ump->info.version = (buf->ep_info.ump_version_major << 8) |
611 ump->info.num_blocks = buf->ep_info.num_function_blocks;
612 if (ump->info.num_blocks > SNDRV_UMP_MAX_BLOCKS) {
613 ump_info(ump, "Invalid function blocks %d, fallback to 1\n",
614 ump->info.num_blocks);
615 ump->info.num_blocks = 1;
619 ump->info.flags |= SNDRV_UMP_EP_INFO_STATIC_BLOCKS;
621 ump->info.protocol_caps = (buf->ep_info.protocol << 8) |
624 ump_dbg(ump, "EP info: version=%x, num_blocks=%x, proto_caps=%x\n",
625 ump->info.version, ump->info.num_blocks, ump->info.protocol_caps);
630 static int ump_handle_device_info_msg(struct snd_ump_endpoint *ump,
633 ump->info.manufacturer_id = buf->device_info.manufacture_id & 0x7f7f7f;
634 ump->info.family_id = (buf->device_info.family_msb << 8) |
636 ump->info.model_id = (buf->device_info.model_msb << 8) |
638 ump->info.sw_revision[0] = (buf->device_info.sw_revision >> 24) & 0x7f;
639 ump->info.sw_revision[1] = (buf->device_info.sw_revision >> 16) & 0x7f;
640 ump->info.sw_revision[2] = (buf->device_info.sw_revision >> 8) & 0x7f;
641 ump->info.sw_revision[3] = buf->device_info.sw_revision & 0x7f;
642 ump_dbg(ump, "EP devinfo: manid=%08x, family=%04x, model=%04x, sw=%02x%02x%02x%02x\n",
643 ump->info.manufacturer_id,
644 ump->info.family_id,
645 ump->info.model_id,
646 ump->info.sw_revision[0],
647 ump->info.sw_revision[1],
648 ump->info.sw_revision[2],
649 ump->info.sw_revision[3]);
654 static int ump_handle_ep_name_msg(struct snd_ump_endpoint *ump,
657 return ump_append_string(ump, ump->info.name, sizeof(ump->info.name),
662 static int ump_handle_product_id_msg(struct snd_ump_endpoint *ump,
665 return ump_append_string(ump, ump->info.product_id,
666 sizeof(ump->info.product_id),
671 static void seq_notify_protocol(struct snd_ump_endpoint *ump)
674 if (ump->seq_ops && ump->seq_ops->switch_protocol)
675 ump->seq_ops->switch_protocol(ump);
681 * @ump: UMP endpoint
686 int snd_ump_switch_protocol(struct snd_ump_endpoint *ump, unsigned int protocol)
688 protocol &= ump->info.protocol_caps;
689 if (protocol == ump->info.protocol)
692 ump->info.protocol = protocol;
693 ump_dbg(ump, "New protocol = %x (caps = %x)\n",
694 protocol, ump->info.protocol_caps);
695 seq_notify_protocol(ump);
701 static int ump_handle_stream_cfg_msg(struct snd_ump_endpoint *ump,
707 snd_ump_switch_protocol(ump, protocol);
712 static void fill_fb_info(struct snd_ump_endpoint *ump,
725 ump_dbg(ump, "FB %d: dir=%d, active=%d, first_gp=%d, num_gp=%d, midici=%d, sysex8=%d, flags=0x%x\n",
732 static bool is_fb_info_updated(struct snd_ump_endpoint *ump,
738 if (ump->info.flags & SNDRV_UMP_EP_INFO_STATIC_BLOCKS) {
739 ump_info(ump, "Skipping static FB info update (blk#%d)\n",
745 fill_fb_info(ump, (struct snd_ump_block_info *)tmpbuf, buf);
750 static void seq_notify_fb_change(struct snd_ump_endpoint *ump,
754 if (ump->seq_ops && ump->seq_ops->notify_fb_change)
755 ump->seq_ops->notify_fb_change(ump, fb);
760 static int ump_handle_fb_info_msg(struct snd_ump_endpoint *ump,
767 fb = snd_ump_get_block(ump, blk);
770 if (!fb && ump->parsed) {
771 ump_info(ump, "Function Block Info Update for non-existing block %d\n",
777 if (ump->parsed && !is_fb_info_updated(ump, fb, buf))
781 fill_fb_info(ump, &fb->info, buf);
782 if (ump->parsed)
783 seq_notify_fb_change(ump, fb);
790 static int ump_handle_fb_name_msg(struct snd_ump_endpoint *ump,
798 fb = snd_ump_get_block(ump, blk);
802 ret = ump_append_string(ump, fb->info.name, sizeof(fb->info.name),
805 if (ret > 0 && ump->parsed)
806 seq_notify_fb_change(ump, fb);
810 static int create_block_from_fb_info(struct snd_ump_endpoint *ump, int blk)
815 (const union snd_ump_stream_msg *)ump->input_buf;
822 err = ump_req_msg(ump, msg, 0, UMP_STREAM_MSG_STATUS_FB_INFO);
824 ump_dbg(ump, "Unable to get FB info for block %d\n", blk);
830 ump_dbg(ump, "Inconsistent input: 0x%x\n", *buf->raw);
838 err = snd_ump_block_new(ump, blk, direction, first_group, num_groups,
843 fill_fb_info(ump, &fb->info, buf);
847 err = ump_req_msg(ump, msg, 0, UMP_STREAM_MSG_STATUS_FB_NAME);
849 ump_dbg(ump, "Unable to get UMP FB name string #%d\n", blk);
855 static void ump_handle_stream_msg(struct snd_ump_endpoint *ump,
863 if (ump->no_process_stream)
867 ump_dbg(ump, "Stream msg: %08x %08x %08x %08x\n",
877 ret = ump_handle_ep_info_msg(ump, msg);
880 ret = ump_handle_device_info_msg(ump, msg);
883 ret = ump_handle_ep_name_msg(ump, msg);
886 ret = ump_handle_product_id_msg(ump, msg);
889 ret = ump_handle_stream_cfg_msg(ump, msg);
892 ret = ump_handle_fb_info_msg(ump, msg);
895 ret = ump_handle_fb_name_msg(ump, msg);
902 if (ret > 0 && ump->stream_wait_for == status) {
903 WRITE_ONCE(ump->stream_finished, 1);
904 wake_up(&ump->stream_wait);
910 * @ump: UMP object
915 int snd_ump_parse_endpoint(struct snd_ump_endpoint *ump)
920 if (!(ump->core.info_flags & SNDRV_RAWMIDI_INFO_DUPLEX))
923 err = ump_request_open(ump);
925 ump_dbg(ump, "Unable to open rawmidi device: %d\n", err);
932 err = ump_req_msg(ump, msg, UMP_STREAM_MSG_REQUEST_EP_INFO,
935 ump_dbg(ump, "Unable to get UMP EP info\n");
940 err = ump_req_msg(ump, msg, UMP_STREAM_MSG_REQUEST_DEVICE_INFO,
943 ump_dbg(ump, "Unable to get UMP EP device info\n");
946 err = ump_req_msg(ump, msg, UMP_STREAM_MSG_REQUEST_EP_NAME,
949 ump_dbg(ump, "Unable to get UMP EP name string\n");
952 err = ump_req_msg(ump, msg, UMP_STREAM_MSG_REQUEST_PRODUCT_ID,
955 ump_dbg(ump, "Unable to get UMP EP product ID string\n");
958 err = ump_req_msg(ump, msg, UMP_STREAM_MSG_REQUEST_STREAM_CFG,
961 ump_dbg(ump, "Unable to get UMP EP stream config\n");
964 for (blk = 0; blk < ump->info.num_blocks; blk++) {
965 err = create_block_from_fb_info(ump, blk);
971 ump->parsed = true;
972 ump_request_close(ump);
985 struct snd_ump_endpoint *ump = substream->rmidi->private_data;
987 int group = ump->legacy_mapping[substream->number];
990 mutex_lock(&ump->open_mutex);
991 if (ump->legacy_substreams[dir][group]) {
996 if (!ump->legacy_out_opens) {
997 err = snd_rawmidi_kernel_open(&ump->core, 0,
1000 &ump->legacy_out_rfile);
1004 ump->legacy_out_opens++;
1005 snd_ump_convert_reset(&ump->out_cvts[group]);
1007 spin_lock_irq(&ump->legacy_locks[dir]);
1008 ump->legacy_substreams[dir][group] = substream;
1009 spin_unlock_irq(&ump->legacy_locks[dir]);
1011 mutex_unlock(&ump->open_mutex);
1017 struct snd_ump_endpoint *ump = substream->rmidi->private_data;
1019 int group = ump->legacy_mapping[substream->number];
1021 mutex_lock(&ump->open_mutex);
1022 spin_lock_irq(&ump->legacy_locks[dir]);
1023 ump->legacy_substreams[dir][group] = NULL;
1024 spin_unlock_irq(&ump->legacy_locks[dir]);
1026 if (!--ump->legacy_out_opens)
1027 snd_rawmidi_kernel_release(&ump->legacy_out_rfile);
1029 mutex_unlock(&ump->open_mutex);
1036 struct snd_ump_endpoint *ump = substream->rmidi->private_data;
1039 ump->ops->trigger(ump, dir, up);
1044 struct snd_ump_endpoint *ump = substream->rmidi->private_data;
1046 if (ump->ops->drain)
1047 ump->ops->drain(ump, SNDRV_RAWMIDI_STREAM_OUTPUT);
1073 static int process_legacy_output(struct snd_ump_endpoint *ump,
1083 if (!ump->out_cvts || !ump->legacy_out_opens)
1086 spin_lock_irqsave(&ump->legacy_locks[dir], flags);
1088 substream = ump->legacy_substreams[dir][group];
1091 ctx = &ump->out_cvts[group];
1094 snd_ump_convert_to_ump(ctx, group, ump->info.protocol, c);
1097 memcpy(buffer, ctx->ump, size);
1102 spin_unlock_irqrestore(&ump->legacy_locks[dir], flags);
1106 static void process_legacy_input(struct snd_ump_endpoint *ump, const u32 *src,
1119 spin_lock_irqsave(&ump->legacy_locks[dir], flags);
1120 substream = ump->legacy_substreams[dir][group];
1123 spin_unlock_irqrestore(&ump->legacy_locks[dir], flags);
1126 /* Fill ump->legacy_mapping[] for groups to be used for legacy rawmidi */
1127 static int fill_legacy_mapping(struct snd_ump_endpoint *ump)
1133 if (ump->info.flags & SNDRV_UMP_EP_INFO_STATIC_BLOCKS) {
1134 list_for_each_entry(fb, &ump->block_list, list) {
1139 ump_info(ump, "No UMP Group is found in FB\n");
1149 ump->legacy_mapping[num++] = i;
1154 static void fill_substream_names(struct snd_ump_endpoint *ump,
1161 ump->legacy_mapping[s->number] + 1, ump->info.name);
1164 int snd_ump_attach_legacy_rawmidi(struct snd_ump_endpoint *ump,
1171 ump->out_cvts = kcalloc(SNDRV_UMP_MAX_GROUPS,
1172 sizeof(*ump->out_cvts), GFP_KERNEL);
1173 if (!ump->out_cvts)
1176 num = fill_legacy_mapping(ump);
1178 input = ump->core.info_flags & SNDRV_RAWMIDI_INFO_INPUT;
1179 output = ump->core.info_flags & SNDRV_RAWMIDI_INFO_OUTPUT;
1180 err = snd_rawmidi_new(ump->core.card, id, device,
1184 kfree(ump->out_cvts);
1195 ump->info.name);
1196 rmidi->info_flags = ump->core.info_flags & ~SNDRV_RAWMIDI_INFO_UMP;
1198 rmidi->private_data = ump;
1199 ump->legacy_rmidi = rmidi;
1201 fill_substream_names(ump, rmidi, SNDRV_RAWMIDI_STREAM_INPUT);
1203 fill_substream_names(ump, rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT);
1205 ump_dbg(ump, "Created a legacy rawmidi #%d (%s)\n", device, id);