OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [drivers/] [sound/] [patmgr.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1626 jcastillo
/*
2
 * sound/patmgr.c
3
 *
4
 * The patch manager interface for the /dev/sequencer
5
 */
6
/*
7
 * Copyright (C) by Hannu Savolainen 1993-1996
8
 *
9
 * USS/Lite for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10
 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11
 * for more info.
12
 */
13
#include <linux/config.h>
14
 
15
 
16
#define PATMGR_C
17
#include "sound_config.h"
18
 
19
#if defined(CONFIG_SEQUENCER)
20
 
21
static wait_handle *server_procs[MAX_SYNTH_DEV] =
22
{NULL};
23
static volatile struct snd_wait server_wait_flag[MAX_SYNTH_DEV] =
24
{
25
  {0}};
26
 
27
static struct patmgr_info *mbox[MAX_SYNTH_DEV] =
28
{NULL};
29
static volatile int msg_direction[MAX_SYNTH_DEV] =
30
{0};
31
 
32
static int      pmgr_opened[MAX_SYNTH_DEV] =
33
{0};
34
 
35
#define A_TO_S  1
36
#define S_TO_A  2
37
 
38
static wait_handle *appl_proc = NULL;
39
static volatile struct snd_wait appl_wait_flag =
40
{0};
41
 
42
int
43
pmgr_open (int dev)
44
{
45
  if (dev < 0 || dev >= num_synths)
46
    return -(ENXIO);
47
 
48
  if (pmgr_opened[dev])
49
    return -(EBUSY);
50
  pmgr_opened[dev] = 1;
51
 
52
  server_wait_flag[dev].flags = WK_NONE;
53
 
54
  return 0;
55
}
56
 
57
void
58
pmgr_release (int dev)
59
{
60
 
61
  if (mbox[dev])                /*
62
                                 * Killed in action. Inform the client
63
                                 */
64
    {
65
 
66
      mbox[dev]->key = PM_ERROR;
67
      mbox[dev]->parm1 = -(EIO);
68
 
69
      if ((appl_wait_flag.flags & WK_SLEEP))
70
        {
71
          appl_wait_flag.flags = WK_WAKEUP;
72
          module_wake_up (&appl_proc);
73
        };
74
    }
75
 
76
  pmgr_opened[dev] = 0;
77
}
78
 
79
int
80
pmgr_read (int dev, struct fileinfo *file, char *buf, int count)
81
{
82
  unsigned long   flags;
83
  int             ok = 0;
84
 
85
  if (count != sizeof (struct patmgr_info))
86
    {
87
      printk ("PATMGR%d: Invalid read count\n", dev);
88
      return -(EIO);
89
    }
90
 
91
  while (!ok && !current_got_fatal_signal ())
92
    {
93
      save_flags (flags);
94
      cli ();
95
 
96
      while (!(mbox[dev] && msg_direction[dev] == A_TO_S) &&
97
             !current_got_fatal_signal ())
98
        {
99
 
100
          server_wait_flag[dev].flags = WK_SLEEP;
101
          module_interruptible_sleep_on (&server_procs[dev]);
102
          server_wait_flag[dev].flags &= ~WK_SLEEP;;
103
        }
104
 
105
      if (mbox[dev] && msg_direction[dev] == A_TO_S)
106
        {
107
          memcpy_tofs (&(buf)[0], (char *) mbox[dev], count);
108
          msg_direction[dev] = 0;
109
          ok = 1;
110
        }
111
 
112
      restore_flags (flags);
113
 
114
    }
115
 
116
  if (!ok)
117
    return -(EINTR);
118
  return count;
119
}
120
 
121
int
122
pmgr_write (int dev, struct fileinfo *file, const char *buf, int count)
123
{
124
  unsigned long   flags;
125
 
126
  if (count < 4)
127
    {
128
      printk ("PATMGR%d: Write count < 4\n", dev);
129
      return -(EIO);
130
    }
131
 
132
  memcpy_fromfs ((char *) mbox[dev], &(buf)[0], 4);
133
 
134
  if (*(unsigned char *) mbox[dev] == SEQ_FULLSIZE)
135
    {
136
      int             tmp_dev;
137
 
138
      tmp_dev = ((unsigned short *) mbox[dev])[2];
139
      if (tmp_dev != dev)
140
        return -(ENXIO);
141
 
142
      return synth_devs[dev]->load_patch (dev, *(unsigned short *) mbox[dev],
143
                                          buf, 4, count, 1);
144
    }
145
 
146
  if (count != sizeof (struct patmgr_info))
147
    {
148
      printk ("PATMGR%d: Invalid write count\n", dev);
149
      return -(EIO);
150
    }
151
 
152
  /*
153
   * If everything went OK, there should be a preallocated buffer in the
154
   * mailbox and a client waiting.
155
   */
156
 
157
  save_flags (flags);
158
  cli ();
159
 
160
  if (mbox[dev] && !msg_direction[dev])
161
    {
162
      memcpy_fromfs (&((char *) mbox[dev])[4], &(buf)[4], count - 4);
163
      msg_direction[dev] = S_TO_A;
164
 
165
      if ((appl_wait_flag.flags & WK_SLEEP))
166
        {
167
          {
168
            appl_wait_flag.flags = WK_WAKEUP;
169
            module_wake_up (&appl_proc);
170
          };
171
        }
172
    }
173
 
174
  restore_flags (flags);
175
 
176
  return count;
177
}
178
 
179
int
180
pmgr_access (int dev, struct patmgr_info *rec)
181
{
182
  unsigned long   flags;
183
  int             err = 0;
184
 
185
  save_flags (flags);
186
  cli ();
187
 
188
  if (mbox[dev])
189
    printk ("  PATMGR: Server %d mbox full. Why?\n", dev);
190
  else
191
    {
192
      rec->key = PM_K_COMMAND;
193
      mbox[dev] = rec;
194
      msg_direction[dev] = A_TO_S;
195
 
196
      if ((server_wait_flag[dev].flags & WK_SLEEP))
197
        {
198
          {
199
            server_wait_flag[dev].flags = WK_WAKEUP;
200
            module_wake_up (&server_procs[dev]);
201
          };
202
        }
203
 
204
 
205
      appl_wait_flag.flags = WK_SLEEP;
206
      module_interruptible_sleep_on (&appl_proc);
207
      appl_wait_flag.flags &= ~WK_SLEEP;;
208
 
209
      if (msg_direction[dev] != S_TO_A)
210
        {
211
          rec->key = PM_ERROR;
212
          rec->parm1 = -(EIO);
213
        }
214
      else if (rec->key == PM_ERROR)
215
        {
216
          err = rec->parm1;
217
          if (err > 0)
218
            err = -err;
219
        }
220
 
221
      mbox[dev] = NULL;
222
      msg_direction[dev] = 0;
223
    }
224
 
225
  restore_flags (flags);
226
 
227
  return err;
228
}
229
 
230
int
231
pmgr_inform (int dev, int event, unsigned long p1, unsigned long p2,
232
             unsigned long p3, unsigned long p4)
233
{
234
  unsigned long   flags;
235
  int             err = 0;
236
 
237
  struct patmgr_info *tmp_mbox;
238
 
239
  if (!pmgr_opened[dev])
240
    return 0;
241
 
242
  tmp_mbox = (struct patmgr_info *) vmalloc (sizeof (struct patmgr_info));
243
 
244
  if (tmp_mbox == NULL)
245
    {
246
      printk ("pmgr: Couldn't allocate memory for a message\n");
247
      return 0;
248
    }
249
 
250
  save_flags (flags);
251
  cli ();
252
 
253
  if (mbox[dev])
254
    printk ("  PATMGR: Server %d mbox full. Why?\n", dev);
255
  else
256
    {
257
 
258
      mbox[dev] = tmp_mbox;
259
      mbox[dev]->key = PM_K_EVENT;
260
      mbox[dev]->command = event;
261
      mbox[dev]->parm1 = p1;
262
      mbox[dev]->parm2 = p2;
263
      mbox[dev]->parm3 = p3;
264
      msg_direction[dev] = A_TO_S;
265
 
266
      if ((server_wait_flag[dev].flags & WK_SLEEP))
267
        {
268
          {
269
            server_wait_flag[dev].flags = WK_WAKEUP;
270
            module_wake_up (&server_procs[dev]);
271
          };
272
        }
273
 
274
 
275
      appl_wait_flag.flags = WK_SLEEP;
276
      module_interruptible_sleep_on (&appl_proc);
277
      appl_wait_flag.flags &= ~WK_SLEEP;;
278
      mbox[dev] = NULL;
279
      msg_direction[dev] = 0;
280
    }
281
 
282
  restore_flags (flags);
283
  vfree (tmp_mbox);
284
 
285
  return err;
286
}
287
 
288
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.