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
28 * $DragonFly: src/sys/dev/sound/isa/i386/Attic/patmgr.c,v 1.2 2003/08/07 21:17:12 dillon Exp $
32 #include "sound_config.h"
34 #if defined(CONFIG_SEQUENCER)
36 static int *server_procs[MAX_SYNTH_DEV] = {NULL};
37 static volatile struct snd_wait server_wait_flag[MAX_SYNTH_DEV] = { {0}};
39 static struct patmgr_info *mbox[MAX_SYNTH_DEV] = {NULL};
40 static volatile int msg_direction[MAX_SYNTH_DEV] = {0};
42 static int pmgr_opened[MAX_SYNTH_DEV] = {0};
47 static int *appl_proc = NULL;
48 static volatile struct snd_wait appl_wait_flag =
54 if (dev < 0 || dev >= num_synths)
61 server_wait_flag[dev].aborting = 0;
62 server_wait_flag[dev].mode = WK_NONE;
71 if (mbox[dev]) { /* Killed in action. Inform the client */
73 mbox[dev]->key = PM_ERROR;
74 mbox[dev]->parm1 = -(EIO);
76 if ((appl_wait_flag.mode & WK_SLEEP)) {
77 appl_wait_flag.mode = WK_WAKEUP;
85 pmgr_read(int dev, struct fileinfo * file, snd_rw_buf * buf, int count)
90 if (count != sizeof(struct patmgr_info)) {
91 printf("PATMGR%d: Invalid read count\n", dev);
94 while (!ok && !(server_wait_flag[dev].aborting)) {
97 while (!(mbox[dev] && msg_direction[dev] == A_TO_S) &&
98 !(server_wait_flag[dev].aborting)) {
101 server_procs[dev] = &chn;
102 DO_SLEEP(chn, server_wait_flag[dev], 0);
106 if (mbox[dev] && msg_direction[dev] == A_TO_S) {
108 if (uiomove((char *) mbox[dev], count, buf)) {
109 printf("sb: Bad copyout()!\n");
111 msg_direction[dev] = 0;
124 pmgr_write(int dev, struct fileinfo * file, snd_rw_buf * buf, int count)
129 printf("PATMGR%d: Write count < 4\n", dev);
132 if (uiomove((char *) mbox[dev], 4, buf)) {
133 printf("sb: Bad copyin()!\n");
136 if (*(u_char *) mbox[dev] == SEQ_FULLSIZE) {
139 tmp_dev = ((u_short *) mbox[dev])[2];
143 return synth_devs[dev]->load_patch(dev, *(u_short *) mbox[dev],
146 if (count != sizeof(struct patmgr_info)) {
147 printf("PATMGR%d: Invalid write count\n", dev);
151 * If everything went OK, there should be a preallocated buffer in
152 * the mailbox and a client waiting.
157 if (mbox[dev] && !msg_direction[dev]) {
159 if (uiomove(&((char *) mbox[dev])[4], count - 4, buf)) {
160 printf("sb: Bad copyin()!\n");
162 msg_direction[dev] = S_TO_A;
164 if ((appl_wait_flag.mode & WK_SLEEP)) {
165 appl_wait_flag.mode = WK_WAKEUP;
175 pmgr_access(int dev, struct patmgr_info * rec)
183 printf(" PATMGR: Server %d mbox full. Why?\n", dev);
187 rec->key = PM_K_COMMAND;
189 msg_direction[dev] = A_TO_S;
191 if ((server_wait_flag[dev].mode & WK_SLEEP)) {
192 server_wait_flag[dev].mode = WK_WAKEUP;
193 wakeup(server_procs[dev]);
198 DO_SLEEP(chn, appl_wait_flag, 0);
200 if (msg_direction[dev] != S_TO_A) {
203 } else if (rec->key == PM_ERROR) {
209 msg_direction[dev] = 0;
218 pmgr_inform(int dev, int event, u_long p1, u_long p2, u_long p3, u_long p4)
223 struct patmgr_info *tmp_mbox;
225 if (!pmgr_opened[dev])
228 tmp_mbox = (struct patmgr_info *) malloc(sizeof(struct patmgr_info), M_TEMP, M_WAITOK);
230 if (tmp_mbox == NULL) {
231 printf("pmgr: Couldn't allocate memory for a message\n");
237 printf(" PATMGR: Server %d mbox full. Why?\n", dev);
241 mbox[dev] = tmp_mbox;
242 mbox[dev]->key = PM_K_EVENT;
243 mbox[dev]->command = event;
244 mbox[dev]->parm1 = p1;
245 mbox[dev]->parm2 = p2;
246 mbox[dev]->parm3 = p3;
247 msg_direction[dev] = A_TO_S;
249 if ((server_wait_flag[dev].mode & WK_SLEEP)) {
250 server_wait_flag[dev].mode = WK_WAKEUP;
251 wakeup(server_procs[dev]);
256 DO_SLEEP(chn, appl_wait_flag, 0);
259 msg_direction[dev] = 0;
263 free(tmp_mbox, M_TEMP);