4 * The patch maneger interface for the /dev/sequencer
6 * Copyright by Hannu Savolainen 1993
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met: 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 2.
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <i386/isa/sound/sound_config.h>
33 #if defined(CONFIG_SEQUENCER)
35 static int *server_procs[MAX_SYNTH_DEV] = {NULL};
36 static volatile struct snd_wait server_wait_flag[MAX_SYNTH_DEV] = { {0}};
38 static struct patmgr_info *mbox[MAX_SYNTH_DEV] = {NULL};
39 static volatile int msg_direction[MAX_SYNTH_DEV] = {0};
41 static int pmgr_opened[MAX_SYNTH_DEV] = {0};
46 static int *appl_proc = NULL;
47 static volatile struct snd_wait appl_wait_flag =
53 if (dev < 0 || dev >= num_synths)
60 server_wait_flag[dev].aborting = 0;
61 server_wait_flag[dev].mode = WK_NONE;
70 if (mbox[dev]) { /* Killed in action. Inform the client */
72 mbox[dev]->key = PM_ERROR;
73 mbox[dev]->parm1 = -(EIO);
75 if ((appl_wait_flag.mode & WK_SLEEP)) {
76 appl_wait_flag.mode = WK_WAKEUP;
84 pmgr_read(int dev, struct fileinfo * file, snd_rw_buf * buf, int count)
89 if (count != sizeof(struct patmgr_info)) {
90 printf("PATMGR%d: Invalid read count\n", dev);
93 while (!ok && !(server_wait_flag[dev].aborting)) {
96 while (!(mbox[dev] && msg_direction[dev] == A_TO_S) &&
97 !(server_wait_flag[dev].aborting)) {
100 server_procs[dev] = &chn;
101 DO_SLEEP(chn, server_wait_flag[dev], 0);
105 if (mbox[dev] && msg_direction[dev] == A_TO_S) {
107 if (uiomove((char *) mbox[dev], count, buf)) {
108 printf("sb: Bad copyout()!\n");
110 msg_direction[dev] = 0;
123 pmgr_write(int dev, struct fileinfo * file, snd_rw_buf * buf, int count)
128 printf("PATMGR%d: Write count < 4\n", dev);
131 if (uiomove((char *) mbox[dev], 4, buf)) {
132 printf("sb: Bad copyin()!\n");
135 if (*(u_char *) mbox[dev] == SEQ_FULLSIZE) {
138 tmp_dev = ((u_short *) mbox[dev])[2];
142 return synth_devs[dev]->load_patch(dev, *(u_short *) mbox[dev],
145 if (count != sizeof(struct patmgr_info)) {
146 printf("PATMGR%d: Invalid write count\n", dev);
150 * If everything went OK, there should be a preallocated buffer in
151 * the mailbox and a client waiting.
156 if (mbox[dev] && !msg_direction[dev]) {
158 if (uiomove(&((char *) mbox[dev])[4], count - 4, buf)) {
159 printf("sb: Bad copyin()!\n");
161 msg_direction[dev] = S_TO_A;
163 if ((appl_wait_flag.mode & WK_SLEEP)) {
164 appl_wait_flag.mode = WK_WAKEUP;
174 pmgr_access(int dev, struct patmgr_info * rec)
182 printf(" PATMGR: Server %d mbox full. Why?\n", dev);
186 rec->key = PM_K_COMMAND;
188 msg_direction[dev] = A_TO_S;
190 if ((server_wait_flag[dev].mode & WK_SLEEP)) {
191 server_wait_flag[dev].mode = WK_WAKEUP;
192 wakeup(server_procs[dev]);
197 DO_SLEEP(chn, appl_wait_flag, 0);
199 if (msg_direction[dev] != S_TO_A) {
202 } else if (rec->key == PM_ERROR) {
208 msg_direction[dev] = 0;
217 pmgr_inform(int dev, int event, u_long p1, u_long p2, u_long p3, u_long p4)
222 struct patmgr_info *tmp_mbox;
224 if (!pmgr_opened[dev])
227 tmp_mbox = (struct patmgr_info *) malloc(sizeof(struct patmgr_info), M_TEMP, M_WAITOK);
229 if (tmp_mbox == NULL) {
230 printf("pmgr: Couldn't allocate memory for a message\n");
236 printf(" PATMGR: Server %d mbox full. Why?\n", dev);
240 mbox[dev] = tmp_mbox;
241 mbox[dev]->key = PM_K_EVENT;
242 mbox[dev]->command = event;
243 mbox[dev]->parm1 = p1;
244 mbox[dev]->parm2 = p2;
245 mbox[dev]->parm3 = p3;
246 msg_direction[dev] = A_TO_S;
248 if ((server_wait_flag[dev].mode & WK_SLEEP)) {
249 server_wait_flag[dev].mode = WK_WAKEUP;
250 wakeup(server_procs[dev]);
255 DO_SLEEP(chn, appl_wait_flag, 0);
258 msg_direction[dev] = 0;
262 free(tmp_mbox, M_TEMP);