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 DEFINE_WAIT_QUEUES (server_procs[MAX_SYNTH_DEV],
36 server_wait_flag[MAX_SYNTH_DEV]);
37
38 static struct patmgr_info *mbox[MAX_SYNTH_DEV] =
39 {NULL};
40 static volatile int msg_direction[MAX_SYNTH_DEV] =
41 {0};
42
43 static int pmgr_opened[MAX_SYNTH_DEV] =
44 {0};
45
46 #define A_TO_S 1
47 #define S_TO_A 2
48
49 DEFINE_WAIT_QUEUE (appl_proc, appl_wait_flag);
50
51 int
52 pmgr_open (int dev)
53 {
54 if (dev < 0 || dev >= num_synths)
55 return RET_ERROR (ENXIO);
56
57 if (pmgr_opened[dev])
58 return RET_ERROR (EBUSY);
59 pmgr_opened[dev] = 1;
60
61 RESET_WAIT_QUEUE (server_procs[dev], server_wait_flag[dev]);
62
63 return 0;
64 }
65
66 void
67 pmgr_release (int dev)
68 {
69
70 if (mbox[dev])
71
72
73 {
74
75 mbox[dev]->key = PM_ERROR;
76 mbox[dev]->parm1 = RET_ERROR (EIO);
77
78 if (SOMEONE_WAITING (appl_proc, appl_wait_flag))
79 WAKE_UP (appl_proc, appl_wait_flag);
80 }
81
82 pmgr_opened[dev] = 0;
83 }
84
85 int
86 pmgr_read (int dev, struct fileinfo *file, snd_rw_buf * buf, int count)
87 {
88 unsigned long flags;
89 int ok = 0;
90
91 if (count != sizeof (struct patmgr_info))
92 {
93 printk ("PATMGR%d: Invalid read count\n", dev);
94 return RET_ERROR (EIO);
95 }
96
97 while (!ok && !PROCESS_ABORTING (server_procs[dev], server_wait_flag[dev]))
98 {
99 DISABLE_INTR (flags);
100
101 while (!(mbox[dev] && msg_direction[dev] == A_TO_S) &&
102 !PROCESS_ABORTING (server_procs[dev], server_wait_flag[dev]))
103 {
104 DO_SLEEP (server_procs[dev], server_wait_flag[dev], 0);
105 }
106
107 if (mbox[dev] && msg_direction[dev] == A_TO_S)
108 {
109 COPY_TO_USER (buf, 0, (char *) mbox[dev], count);
110 msg_direction[dev] = 0;
111 ok = 1;
112 }
113
114 RESTORE_INTR (flags);
115
116 }
117
118 if (!ok)
119 return RET_ERROR (EINTR);
120 return count;
121 }
122
123 int
124 pmgr_write (int dev, struct fileinfo *file, snd_rw_buf * buf, int count)
125 {
126 unsigned long flags;
127
128 if (count < 4)
129 {
130 printk ("PATMGR%d: Write count < 4\n", dev);
131 return RET_ERROR (EIO);
132 }
133
134 COPY_FROM_USER (mbox[dev], buf, 0, 4);
135
136 if (*(unsigned char *) mbox[dev] == SEQ_FULLSIZE)
137 {
138 int tmp_dev;
139
140 tmp_dev = ((unsigned short *) mbox[dev])[2];
141 if (tmp_dev != dev)
142 return RET_ERROR (ENXIO);
143
144 return synth_devs[dev]->load_patch (dev, *(unsigned short *) mbox[dev],
145 buf, 4, count, 1);
146 }
147
148 if (count != sizeof (struct patmgr_info))
149 {
150 printk ("PATMGR%d: Invalid write count\n", dev);
151 return RET_ERROR (EIO);
152 }
153
154
155
156
157
158
159 DISABLE_INTR (flags);
160
161 if (mbox[dev] && !msg_direction[dev])
162 {
163 COPY_FROM_USER (&((char *) mbox[dev])[4], buf, 4, count - 4);
164 msg_direction[dev] = S_TO_A;
165
166 if (SOMEONE_WAITING (appl_proc, appl_wait_flag))
167 {
168 WAKE_UP (appl_proc, appl_wait_flag);
169 }
170 }
171
172 RESTORE_INTR (flags);
173
174 return count;
175 }
176
177 int
178 pmgr_access (int dev, struct patmgr_info *rec)
179 {
180 unsigned long flags;
181 int err = 0;
182
183 DISABLE_INTR (flags);
184
185 if (mbox[dev])
186 printk (" PATMGR: Server %d mbox full. Why?\n", dev);
187 else
188 {
189 rec->key = PM_K_COMMAND;
190 mbox[dev] = rec;
191 msg_direction[dev] = A_TO_S;
192
193 if (SOMEONE_WAITING (server_procs[dev], server_wait_flag[dev]))
194 {
195 WAKE_UP (server_procs[dev], server_wait_flag[dev]);
196 }
197
198 DO_SLEEP (appl_proc, appl_wait_flag, 0);
199
200 if (msg_direction[dev] != S_TO_A)
201 {
202 rec->key = PM_ERROR;
203 rec->parm1 = RET_ERROR (EIO);
204 }
205 else if (rec->key == PM_ERROR)
206 {
207 err = rec->parm1;
208 if (err > 0)
209 err = -err;
210 }
211
212 mbox[dev] = NULL;
213 msg_direction[dev] = 0;
214 }
215
216 RESTORE_INTR (flags);
217
218 return err;
219 }
220
221 int
222 pmgr_inform (int dev, int event, unsigned long p1, unsigned long p2,
223 unsigned long p3, unsigned long p4)
224 {
225 unsigned long flags;
226 int err = 0;
227
228 if (!pmgr_opened[dev])
229 return 0;
230
231 DISABLE_INTR (flags);
232
233 if (mbox[dev])
234 printk (" PATMGR: Server %d mbox full. Why?\n", dev);
235 else
236 {
237 if ((mbox[dev] =
238 (struct patmgr_info *) KERNEL_MALLOC (sizeof (struct patmgr_info))) == NULL)
239 {
240 printk ("pmgr: Couldn't allocate memory for a message\n");
241 return 0;
242 }
243
244 mbox[dev]->key = PM_K_EVENT;
245 mbox[dev]->command = event;
246 mbox[dev]->parm1 = p1;
247 mbox[dev]->parm2 = p2;
248 mbox[dev]->parm3 = p3;
249 msg_direction[dev] = A_TO_S;
250
251 if (SOMEONE_WAITING (server_procs[dev], server_wait_flag[dev]))
252 {
253 WAKE_UP (server_procs[dev], server_wait_flag[dev]);
254 }
255
256 DO_SLEEP (appl_proc, appl_wait_flag, 0);
257 if (mbox[dev])
258 KERNEL_FREE (mbox[dev]);
259 mbox[dev] = NULL;
260 msg_direction[dev] = 0;
261 }
262
263 RESTORE_INTR (flags);
264
265 return err;
266 }
267
268 #endif