This source file includes following definitions.
- pmgr_open
- pmgr_release
- pmgr_read
- pmgr_write
- pmgr_access
- pmgr_inform
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 #define PATMGR_C
31 #include "sound_config.h"
32
33 #if defined(CONFIGURE_SOUNDCARD) && !defined(EXCLUDE_SEQUENCER)
34
35 static struct wait_queue *server_procs[MAX_SYNTH_DEV] =
36 {NULL};
37 static volatile struct snd_wait server_wait_flag[MAX_SYNTH_DEV] =
38 {
39 {0}};
40
41 static struct patmgr_info *mbox[MAX_SYNTH_DEV] =
42 {NULL};
43 static volatile int msg_direction[MAX_SYNTH_DEV] =
44 {0};
45
46 static int pmgr_opened[MAX_SYNTH_DEV] =
47 {0};
48
49 #define A_TO_S 1
50 #define S_TO_A 2
51
52 static struct wait_queue *appl_proc = NULL;
53 static volatile struct snd_wait appl_wait_flag =
54 {0};
55
56 int
57 pmgr_open (int dev)
58 {
59 if (dev < 0 || dev >= num_synths)
60 return -ENXIO;
61
62 if (pmgr_opened[dev])
63 return -EBUSY;
64 pmgr_opened[dev] = 1;
65
66 {
67 server_wait_flag[dev].aborting = 0;
68 server_wait_flag[dev].mode = WK_NONE;
69 };
70
71 return 0;
72 }
73
74 void
75 pmgr_release (int dev)
76 {
77
78 if (mbox[dev])
79
80
81 {
82
83 mbox[dev]->key = PM_ERROR;
84 mbox[dev]->parm1 = -EIO;
85
86 if ((appl_wait_flag.mode & WK_SLEEP))
87 {
88 appl_wait_flag.mode = WK_WAKEUP;
89 wake_up (&appl_proc);
90 };
91 }
92
93 pmgr_opened[dev] = 0;
94 }
95
96 int
97 pmgr_read (int dev, struct fileinfo *file, snd_rw_buf * buf, int count)
98 {
99 unsigned long flags;
100 int ok = 0;
101
102 if (count != sizeof (struct patmgr_info))
103 {
104 printk ("PATMGR%d: Invalid read count\n", dev);
105 return -EIO;
106 }
107
108 while (!ok && !((current->signal & ~current->blocked)))
109 {
110 save_flags (flags);
111 cli ();
112
113 while (!(mbox[dev] && msg_direction[dev] == A_TO_S) &&
114 !((current->signal & ~current->blocked)))
115 {
116
117 {
118 unsigned long tl;
119
120 if (0)
121 tl = current->timeout = jiffies + (0);
122 else
123 tl = 0xffffffff;
124 server_wait_flag[dev].mode = WK_SLEEP;
125 interruptible_sleep_on (&server_procs[dev]);
126 if (!(server_wait_flag[dev].mode & WK_WAKEUP))
127 {
128 if (current->signal & ~current->blocked)
129 server_wait_flag[dev].aborting = 1;
130 else if (jiffies >= tl)
131 server_wait_flag[dev].mode |= WK_TIMEOUT;
132 }
133 server_wait_flag[dev].mode &= ~WK_SLEEP;
134 };
135 }
136
137 if (mbox[dev] && msg_direction[dev] == A_TO_S)
138 {
139 memcpy_tofs (&((buf)[0]), (char *) mbox[dev], count);
140 msg_direction[dev] = 0;
141 ok = 1;
142 }
143
144 restore_flags (flags);
145
146 }
147
148 if (!ok)
149 return -EINTR;
150 return count;
151 }
152
153 int
154 pmgr_write (int dev, struct fileinfo *file, const snd_rw_buf * buf, int count)
155 {
156 unsigned long flags;
157
158 if (count < 4)
159 {
160 printk ("PATMGR%d: Write count < 4\n", dev);
161 return -EIO;
162 }
163
164 memcpy_fromfs (mbox[dev], &((buf)[0]), 4);
165
166 if (*(unsigned char *) mbox[dev] == SEQ_FULLSIZE)
167 {
168 int tmp_dev;
169
170 tmp_dev = ((unsigned short *) mbox[dev])[2];
171 if (tmp_dev != dev)
172 return -ENXIO;
173
174 return synth_devs[dev]->load_patch (dev, *(unsigned short *) mbox[dev],
175 buf, 4, count, 1);
176 }
177
178 if (count != sizeof (struct patmgr_info))
179 {
180 printk ("PATMGR%d: Invalid write count\n", dev);
181 return -EIO;
182 }
183
184
185
186
187
188
189 save_flags (flags);
190 cli ();
191
192 if (mbox[dev] && !msg_direction[dev])
193 {
194 memcpy_fromfs (&((char *) mbox[dev])[4], &((buf)[4]), count - 4);
195 msg_direction[dev] = S_TO_A;
196
197 if ((appl_wait_flag.mode & WK_SLEEP))
198 {
199 {
200 appl_wait_flag.mode = WK_WAKEUP;
201 wake_up (&appl_proc);
202 };
203 }
204 }
205
206 restore_flags (flags);
207
208 return count;
209 }
210
211 int
212 pmgr_access (int dev, struct patmgr_info *rec)
213 {
214 unsigned long flags;
215 int err = 0;
216
217 save_flags (flags);
218 cli ();
219
220 if (mbox[dev])
221 printk (" PATMGR: Server %d mbox full. Why?\n", dev);
222 else
223 {
224 rec->key = PM_K_COMMAND;
225 mbox[dev] = rec;
226 msg_direction[dev] = A_TO_S;
227
228 if ((server_wait_flag[dev].mode & WK_SLEEP))
229 {
230 {
231 server_wait_flag[dev].mode = WK_WAKEUP;
232 wake_up (&server_procs[dev]);
233 };
234 }
235
236
237 {
238 unsigned long tl;
239
240 if (0)
241 tl = current->timeout = jiffies + (0);
242 else
243 tl = 0xffffffff;
244 appl_wait_flag.mode = WK_SLEEP;
245 interruptible_sleep_on (&appl_proc);
246 if (!(appl_wait_flag.mode & WK_WAKEUP))
247 {
248 if (current->signal & ~current->blocked)
249 appl_wait_flag.aborting = 1;
250 else if (jiffies >= tl)
251 appl_wait_flag.mode |= WK_TIMEOUT;
252 }
253 appl_wait_flag.mode &= ~WK_SLEEP;
254 };
255
256 if (msg_direction[dev] != S_TO_A)
257 {
258 rec->key = PM_ERROR;
259 rec->parm1 = -EIO;
260 }
261 else if (rec->key == PM_ERROR)
262 {
263 err = rec->parm1;
264 if (err > 0)
265 err = -err;
266 }
267
268 mbox[dev] = NULL;
269 msg_direction[dev] = 0;
270 }
271
272 restore_flags (flags);
273
274 return err;
275 }
276
277 int
278 pmgr_inform (int dev, int event, unsigned long p1, unsigned long p2,
279 unsigned long p3, unsigned long p4)
280 {
281 unsigned long flags;
282 int err = 0;
283
284 if (!pmgr_opened[dev])
285 return 0;
286
287 save_flags (flags);
288 cli ();
289
290 if (mbox[dev])
291 printk (" PATMGR: Server %d mbox full. Why?\n", dev);
292 else
293 {
294 if ((mbox[dev] =
295 (struct patmgr_info *) kmalloc (sizeof (struct patmgr_info), GFP_KERNEL)) == NULL)
296 {
297 printk ("pmgr: Couldn't allocate memory for a message\n");
298 return 0;
299 }
300
301 mbox[dev]->key = PM_K_EVENT;
302 mbox[dev]->command = event;
303 mbox[dev]->parm1 = p1;
304 mbox[dev]->parm2 = p2;
305 mbox[dev]->parm3 = p3;
306 msg_direction[dev] = A_TO_S;
307
308 if ((server_wait_flag[dev].mode & WK_SLEEP))
309 {
310 {
311 server_wait_flag[dev].mode = WK_WAKEUP;
312 wake_up (&server_procs[dev]);
313 };
314 }
315
316
317 {
318 unsigned long tl;
319
320 if (0)
321 tl = current->timeout = jiffies + (0);
322 else
323 tl = 0xffffffff;
324 appl_wait_flag.mode = WK_SLEEP;
325 interruptible_sleep_on (&appl_proc);
326 if (!(appl_wait_flag.mode & WK_WAKEUP))
327 {
328 if (current->signal & ~current->blocked)
329 appl_wait_flag.aborting = 1;
330 else if (jiffies >= tl)
331 appl_wait_flag.mode |= WK_TIMEOUT;
332 }
333 appl_wait_flag.mode &= ~WK_SLEEP;
334 };
335 if (mbox[dev])
336 kfree (mbox[dev]);
337 mbox[dev] = NULL;
338 msg_direction[dev] = 0;
339 }
340
341 restore_flags (flags);
342
343 return err;
344 }
345
346 #endif