root/drivers/sound/patmgr.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. pmgr_open
  2. pmgr_release
  3. pmgr_read
  4. pmgr_write
  5. pmgr_access
  6. pmgr_inform

   1 /*
   2  * sound/patmgr.c
   3  *
   4  * The patch maneger interface for the /dev/sequencer
   5  *
   6  * Copyright by Hannu Savolainen 1993
   7  *
   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.
  15  *
  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
  26  * SUCH DAMAGE.
  27  *
  28  */
  29 
  30 #define PATMGR_C
  31 #include "sound_config.h"
  32 
  33 #if defined(CONFIG_SEQUENCER)
  34 
  35 static wait_handle *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 wait_handle *appl_proc = NULL;
  53 static volatile struct snd_wait appl_wait_flag =
  54 {0};
  55 
  56 int
  57 pmgr_open (int dev)
     /* [previous][next][first][last][top][bottom][index][help] */
  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   server_wait_flag[dev].mode = WK_NONE;
  67 
  68   return 0;
  69 }
  70 
  71 void
  72 pmgr_release (int dev)
     /* [previous][next][first][last][top][bottom][index][help] */
  73 {
  74 
  75   if (mbox[dev])                /*
  76                                  * Killed in action. Inform the client
  77                                  */
  78     {
  79 
  80       mbox[dev]->key = PM_ERROR;
  81       mbox[dev]->parm1 = -EIO;
  82 
  83       if ((appl_wait_flag.mode & WK_SLEEP))
  84         {
  85           appl_wait_flag.mode = WK_WAKEUP;
  86           module_wake_up (&appl_proc);
  87         };
  88     }
  89 
  90   pmgr_opened[dev] = 0;
  91 }
  92 
  93 int
  94 pmgr_read (int dev, struct fileinfo *file, snd_rw_buf * buf, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
  95 {
  96   unsigned long   flags;
  97   int             ok = 0;
  98 
  99   if (count != sizeof (struct patmgr_info))
 100     {
 101       printk ("PATMGR%d: Invalid read count\n", dev);
 102       return -EIO;
 103     }
 104 
 105   while (!ok && !current_got_fatal_signal ())
 106     {
 107       save_flags (flags);
 108       cli ();
 109 
 110       while (!(mbox[dev] && msg_direction[dev] == A_TO_S) &&
 111              !current_got_fatal_signal ())
 112         {
 113 
 114           server_wait_flag[dev].mode = WK_SLEEP;
 115           module_interruptible_sleep_on (&server_procs[dev]);
 116           server_wait_flag[dev].mode &= ~WK_SLEEP;;
 117         }
 118 
 119       if (mbox[dev] && msg_direction[dev] == A_TO_S)
 120         {
 121           memcpy_tofs (&((buf)[0]), (char *) mbox[dev], count);
 122           msg_direction[dev] = 0;
 123           ok = 1;
 124         }
 125 
 126       restore_flags (flags);
 127 
 128     }
 129 
 130   if (!ok)
 131     return -EINTR;
 132   return count;
 133 }
 134 
 135 int
 136 pmgr_write (int dev, struct fileinfo *file, const snd_rw_buf * buf, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
 137 {
 138   unsigned long   flags;
 139 
 140   if (count < 4)
 141     {
 142       printk ("PATMGR%d: Write count < 4\n", dev);
 143       return -EIO;
 144     }
 145 
 146   memcpy_fromfs ((char *) mbox[dev], &((buf)[0]), 4);
 147 
 148   if (*(unsigned char *) mbox[dev] == SEQ_FULLSIZE)
 149     {
 150       int             tmp_dev;
 151 
 152       tmp_dev = ((unsigned short *) mbox[dev])[2];
 153       if (tmp_dev != dev)
 154         return -ENXIO;
 155 
 156       return synth_devs[dev]->load_patch (dev, *(unsigned short *) mbox[dev],
 157                                           buf, 4, count, 1);
 158     }
 159 
 160   if (count != sizeof (struct patmgr_info))
 161     {
 162       printk ("PATMGR%d: Invalid write count\n", dev);
 163       return -EIO;
 164     }
 165 
 166   /*
 167    * If everything went OK, there should be a preallocated buffer in the
 168    * mailbox and a client waiting.
 169    */
 170 
 171   save_flags (flags);
 172   cli ();
 173 
 174   if (mbox[dev] && !msg_direction[dev])
 175     {
 176       memcpy_fromfs (&((char *) mbox[dev])[4], &((buf)[4]), count - 4);
 177       msg_direction[dev] = S_TO_A;
 178 
 179       if ((appl_wait_flag.mode & WK_SLEEP))
 180         {
 181           {
 182             appl_wait_flag.mode = WK_WAKEUP;
 183             module_wake_up (&appl_proc);
 184           };
 185         }
 186     }
 187 
 188   restore_flags (flags);
 189 
 190   return count;
 191 }
 192 
 193 int
 194 pmgr_access (int dev, struct patmgr_info *rec)
     /* [previous][next][first][last][top][bottom][index][help] */
 195 {
 196   unsigned long   flags;
 197   int             err = 0;
 198 
 199   save_flags (flags);
 200   cli ();
 201 
 202   if (mbox[dev])
 203     printk ("  PATMGR: Server %d mbox full. Why?\n", dev);
 204   else
 205     {
 206       rec->key = PM_K_COMMAND;
 207       mbox[dev] = rec;
 208       msg_direction[dev] = A_TO_S;
 209 
 210       if ((server_wait_flag[dev].mode & WK_SLEEP))
 211         {
 212           {
 213             server_wait_flag[dev].mode = WK_WAKEUP;
 214             module_wake_up (&server_procs[dev]);
 215           };
 216         }
 217 
 218 
 219       appl_wait_flag.mode = WK_SLEEP;
 220       module_interruptible_sleep_on (&appl_proc);
 221       appl_wait_flag.mode &= ~WK_SLEEP;;
 222 
 223       if (msg_direction[dev] != S_TO_A)
 224         {
 225           rec->key = PM_ERROR;
 226           rec->parm1 = -EIO;
 227         }
 228       else if (rec->key == PM_ERROR)
 229         {
 230           err = rec->parm1;
 231           if (err > 0)
 232             err = -err;
 233         }
 234 
 235       mbox[dev] = NULL;
 236       msg_direction[dev] = 0;
 237     }
 238 
 239   restore_flags (flags);
 240 
 241   return err;
 242 }
 243 
 244 int
 245 pmgr_inform (int dev, int event, unsigned long p1, unsigned long p2,
     /* [previous][next][first][last][top][bottom][index][help] */
 246              unsigned long p3, unsigned long p4)
 247 {
 248   unsigned long   flags;
 249   int             err = 0;
 250 
 251   struct patmgr_info *tmp_mbox;
 252 
 253   if (!pmgr_opened[dev])
 254     return 0;
 255 
 256   tmp_mbox = (struct patmgr_info *) kmalloc (sizeof (struct patmgr_info), GFP_KERNEL);
 257 
 258   if (tmp_mbox == NULL)
 259     {
 260       printk ("pmgr: Couldn't allocate memory for a message\n");
 261       return 0;
 262     }
 263 
 264   save_flags (flags);
 265   cli ();
 266 
 267   if (mbox[dev])
 268     printk ("  PATMGR: Server %d mbox full. Why?\n", dev);
 269   else
 270     {
 271 
 272       mbox[dev] = tmp_mbox;
 273       mbox[dev]->key = PM_K_EVENT;
 274       mbox[dev]->command = event;
 275       mbox[dev]->parm1 = p1;
 276       mbox[dev]->parm2 = p2;
 277       mbox[dev]->parm3 = p3;
 278       msg_direction[dev] = A_TO_S;
 279 
 280       if ((server_wait_flag[dev].mode & WK_SLEEP))
 281         {
 282           {
 283             server_wait_flag[dev].mode = WK_WAKEUP;
 284             module_wake_up (&server_procs[dev]);
 285           };
 286         }
 287 
 288 
 289       appl_wait_flag.mode = WK_SLEEP;
 290       module_interruptible_sleep_on (&appl_proc);
 291       appl_wait_flag.mode &= ~WK_SLEEP;;
 292       mbox[dev] = NULL;
 293       msg_direction[dev] = 0;
 294     }
 295 
 296   restore_flags (flags);
 297   kfree (tmp_mbox);
 298 
 299   return err;
 300 }
 301 
 302 #endif

/* [previous][next][first][last][top][bottom][index][help] */