1#ifndef __SOUND_RAWMIDI_H
2#define __SOUND_RAWMIDI_H
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <sound/asound.h>
26#include <linux/interrupt.h>
27#include <linux/spinlock.h>
28#include <linux/wait.h>
29#include <linux/mutex.h>
30#include <linux/workqueue.h>
31
32#if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
33#include <sound/seq_device.h>
34#endif
35
36
37
38
39
40#define SNDRV_RAWMIDI_DEVICES 8
41
42#define SNDRV_RAWMIDI_LFLG_OUTPUT (1<<0)
43#define SNDRV_RAWMIDI_LFLG_INPUT (1<<1)
44#define SNDRV_RAWMIDI_LFLG_OPEN (3<<0)
45#define SNDRV_RAWMIDI_LFLG_APPEND (1<<2)
46
47struct snd_rawmidi;
48struct snd_rawmidi_substream;
49struct snd_seq_port_info;
50struct pid;
51
52struct snd_rawmidi_ops {
53 int (*open) (struct snd_rawmidi_substream * substream);
54 int (*close) (struct snd_rawmidi_substream * substream);
55 void (*trigger) (struct snd_rawmidi_substream * substream, int up);
56 void (*drain) (struct snd_rawmidi_substream * substream);
57};
58
59struct snd_rawmidi_global_ops {
60 int (*dev_register) (struct snd_rawmidi * rmidi);
61 int (*dev_unregister) (struct snd_rawmidi * rmidi);
62 void (*get_port_info)(struct snd_rawmidi *rmidi, int number,
63 struct snd_seq_port_info *info);
64};
65
66struct snd_rawmidi_runtime {
67 struct snd_rawmidi_substream *substream;
68 unsigned int drain: 1,
69 oss: 1;
70
71 unsigned char *buffer;
72 size_t buffer_size;
73 size_t appl_ptr;
74 size_t hw_ptr;
75 size_t avail_min;
76 size_t avail;
77 size_t xruns;
78
79 spinlock_t lock;
80 wait_queue_head_t sleep;
81
82 void (*event)(struct snd_rawmidi_substream *substream);
83
84 struct work_struct event_work;
85
86 void *private_data;
87 void (*private_free)(struct snd_rawmidi_substream *substream);
88};
89
90struct snd_rawmidi_substream {
91 struct list_head list;
92 int stream;
93 int number;
94 unsigned int opened: 1,
95 append: 1,
96 active_sensing: 1;
97 int use_count;
98 size_t bytes;
99 struct snd_rawmidi *rmidi;
100 struct snd_rawmidi_str *pstr;
101 char name[32];
102 struct snd_rawmidi_runtime *runtime;
103 struct pid *pid;
104
105 struct snd_rawmidi_ops *ops;
106};
107
108struct snd_rawmidi_file {
109 struct snd_rawmidi *rmidi;
110 struct snd_rawmidi_substream *input;
111 struct snd_rawmidi_substream *output;
112};
113
114struct snd_rawmidi_str {
115 unsigned int substream_count;
116 unsigned int substream_opened;
117 struct list_head substreams;
118};
119
120struct snd_rawmidi {
121 struct snd_card *card;
122 struct list_head list;
123 unsigned int device;
124 unsigned int info_flags;
125 char id[64];
126 char name[80];
127
128#ifdef CONFIG_SND_OSSEMUL
129 int ossreg;
130#endif
131
132 struct snd_rawmidi_global_ops *ops;
133
134 struct snd_rawmidi_str streams[2];
135
136 void *private_data;
137 void (*private_free) (struct snd_rawmidi *rmidi);
138
139 struct mutex open_mutex;
140 wait_queue_head_t open_wait;
141
142 struct snd_info_entry *dev;
143 struct snd_info_entry *proc_entry;
144
145#if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
146 struct snd_seq_device *seq_dev;
147#endif
148};
149
150
151
152int snd_rawmidi_new(struct snd_card *card, char *id, int device,
153 int output_count, int input_count,
154 struct snd_rawmidi **rmidi);
155void snd_rawmidi_set_ops(struct snd_rawmidi *rmidi, int stream,
156 struct snd_rawmidi_ops *ops);
157
158
159
160void snd_rawmidi_receive_reset(struct snd_rawmidi_substream *substream);
161int snd_rawmidi_receive(struct snd_rawmidi_substream *substream,
162 const unsigned char *buffer, int count);
163void snd_rawmidi_transmit_reset(struct snd_rawmidi_substream *substream);
164int snd_rawmidi_transmit_empty(struct snd_rawmidi_substream *substream);
165int snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream,
166 unsigned char *buffer, int count);
167int snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, int count);
168int snd_rawmidi_transmit(struct snd_rawmidi_substream *substream,
169 unsigned char *buffer, int count);
170
171
172
173int snd_rawmidi_info_select(struct snd_card *card, struct snd_rawmidi_info *info);
174int snd_rawmidi_kernel_open(struct snd_card *card, int device, int subdevice,
175 int mode, struct snd_rawmidi_file *rfile);
176int snd_rawmidi_kernel_release(struct snd_rawmidi_file *rfile);
177int snd_rawmidi_output_params(struct snd_rawmidi_substream *substream,
178 struct snd_rawmidi_params *params);
179int snd_rawmidi_input_params(struct snd_rawmidi_substream *substream,
180 struct snd_rawmidi_params *params);
181int snd_rawmidi_drop_output(struct snd_rawmidi_substream *substream);
182int snd_rawmidi_drain_output(struct snd_rawmidi_substream *substream);
183int snd_rawmidi_drain_input(struct snd_rawmidi_substream *substream);
184long snd_rawmidi_kernel_read(struct snd_rawmidi_substream *substream,
185 unsigned char *buf, long count);
186long snd_rawmidi_kernel_write(struct snd_rawmidi_substream *substream,
187 const unsigned char *buf, long count);
188
189#endif
190