root/drivers/sound/os.h

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

INCLUDED FROM


   1 /*
   2  *      OS Specific settings for Linux
   3  * 
   4  * Copyright by Hannu Savolainen 1993
   5  *
   6  * Redistribution and use in source and binary forms, with or without
   7  * modification, are permitted provided that the following conditions
   8  * are met:
   9  * 1. Redistributions of source code must retain the above copyright
  10  *    notice, this list of conditions and the following disclaimer.
  11  * 2. Redistributions in binary form must reproduce the above copyright
  12  *    notice, this list of conditions and the following disclaimer in the
  13  *    documentation and/or other materials provided with the distribution.
  14  *
  15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25  * SUCH DAMAGE.
  26  *
  27  */
  28 
  29 #define ALLOW_SELECT
  30 
  31 #include <linux/param.h>
  32 #include <linux/types.h>
  33 #include <linux/errno.h>
  34 #include <linux/signal.h>
  35 #include <linux/fcntl.h>
  36 #include <linux/sched.h>
  37 #include <linux/timer.h>
  38 #include <linux/tty.h>
  39 #include <linux/ctype.h>
  40 #include <asm/io.h>
  41 #include <asm/segment.h>
  42 #include <asm/system.h>
  43 #include <asm/dma.h>
  44 #include <sys/kd.h>
  45 #include <linux/wait.h>
  46 #include <linux/malloc.h>
  47 #include <linux/string.h>
  48 #include <linux/soundcard.h>
  49 
  50 typedef char snd_rw_buf;
  51 
  52 #define FALSE   0
  53 #define TRUE    1
  54 
  55 #define COPY_FROM_USER(d, s, o, c)      memcpy_fromfs((d), &((s)[o]), (c))
  56 #define COPY_TO_USER(d, o, s, c)        memcpy_tofs(&((d)[o]), (s), (c))
  57 #define IOCTL_FROM_USER(d, s, o, c)     memcpy_fromfs((d), &((s)[o]), (c))
  58 #define IOCTL_TO_USER(d, o, s, c)       memcpy_tofs(&((d)[o]), (s), (c))
  59 
  60 #define GET_BYTE_FROM_USER(target, addr, offs)  target = get_fs_byte(&((addr)[offs]))
  61 #define GET_SHORT_FROM_USER(target, addr, offs) target = get_fs_word(&((addr)[offs]))
  62 #define GET_WORD_FROM_USER(target, addr, offs)  target = get_fs_long((long*)&((addr)[offs]))
  63 #define PUT_WORD_TO_USER(addr, offs, data)      put_fs_long(data, (long*)&((addr)[offs]))
  64 #define IOCTL_IN(arg)                   get_fs_long((long *)(arg))
  65 #define IOCTL_OUT(arg, ret)             snd_ioctl_return((int *)arg, ret)
  66 
  67 struct snd_wait {
  68           int mode; int aborting;
  69         };
  70 
  71 #define DEFINE_WAIT_QUEUE(name, flag) static struct wait_queue *name = NULL; \
  72         static volatile struct snd_wait flag = {0}
  73 #define DEFINE_WAIT_QUEUES(name, flag) static struct wait_queue *name = {NULL}; \
  74         static volatile struct snd_wait flag = {{0}}
  75 #define RESET_WAIT_QUEUE(q, f) {f.aborting = 0;f.mode = WK_NONE;}
  76 #define PROCESS_ABORTING(q, f) (/*f.aborting | */(current->signal & ~current->blocked))
  77 #define SET_ABORT_FLAG(q, f) f.aborting = 1
  78 #define TIMED_OUT(q, f) (f.mode & WK_TIMEOUT)
  79 #define DO_SLEEP(q, f, time_limit)      \
  80         { unsigned long tl;\
  81           if (time_limit) tl = current->timeout = jiffies + (time_limit); \
  82              else tl = 0xffffffff; \
  83           f.mode = WK_SLEEP;interruptible_sleep_on(&q); \
  84           if (!(f.mode & WK_WAKEUP)) \
  85            { \
  86              if (current->signal & ~current->blocked) \
  87                 f.aborting = 1; \
  88              else \
  89                 if (jiffies >= tl) f.mode |= WK_TIMEOUT; \
  90            } \
  91           f.mode &= ~WK_SLEEP; \
  92         }
  93 #define SOMEONE_WAITING(q, f) (f.mode & WK_SLEEP)
  94 #define WAKE_UP(q, f)                   {f.mode = WK_WAKEUP;wake_up(&q);}
  95 
  96 #define ALLOC_DMA_CHN(chn,deviceID)     request_dma(chn,deviceID)
  97 #define RELEASE_DMA_CHN(chn)            free_dma(chn)
  98 
  99 #define GET_TIME()                      jiffies
 100 #define RELEASE_IRQ                     free_irq
 101 #define RET_ERROR(err)                  -err
 102 
 103 /* DISABLE_INTR is used to disable interrupts.
 104    These macros store the current flags to the (unsigned long) variable given
 105    as a parameter. RESTORE_INTR returns the interrupt enable bit to state
 106    before DISABLE_INTR or ENABLE_INTR */
 107 
 108 #define DISABLE_INTR(flags)     __asm__ __volatile__("pushfl ; popl %0 ; cli":"=r" (flags));
 109 #define RESTORE_INTR(flags)     __asm__ __volatile__("pushl %0 ; popfl": \
 110                                                         :"r" (flags));
 111 /* 
 112    KERNEL_MALLOC() allocates requested number of memory  and 
 113    KERNEL_FREE is used to free it. 
 114    These macros are never called from interrupt, in addition the
 115    nbytes will never be more than 4096 bytes. Generally the driver
 116    will allocate memory in blocks of 4k. If the kernel has just a
 117    page level memory allocation, 4K can be safely used as the size
 118    (the nbytes parameter can be ignored).
 119 */
 120 #define KERNEL_MALLOC(nbytes)   kmalloc(nbytes, GFP_KERNEL)
 121 #define KERNEL_FREE(addr)       kfree(addr)
 122 
 123 /*
 124  * The macro PERMANENT_MALLOC(typecast, mem_ptr, size, linux_ptr)
 125  * returns size bytes of
 126  * (kernel virtual) memory which will never get freed by the driver.
 127  * This macro is called only during boot. The linux_ptr is a linux specific
 128  * parameter which should be ignored in other operating systems.
 129  * The mem_ptr is a pointer variable where the macro assigns pointer to the
 130  * memory area. The type is the type of the mem_ptr.
 131  */
 132 #define PERMANENT_MALLOC(typecast, mem_ptr, size, linux_ptr) \
 133   {mem_ptr = (typecast)linux_ptr; \
 134    linux_ptr += (size);}
 135 
 136 /*
 137  * The macro DEFINE_TIMER defines variables for the ACTIVATE_TIMER if
 138  * required. The name is the variable/name to be used and the proc is
 139  * the procedure to be called when the timer expires.
 140  */
 141 
 142 #define DEFINE_TIMER(name, proc) \
 143   static struct timer_list name = \
 144   {NULL, NULL, 0, 0, proc}
 145 
 146 /*
 147  * The ACTIVATE_TIMER requests system to call 'proc' after 'time' ticks.
 148  */
 149 
 150 #define ACTIVATE_TIMER(name, proc, time) \
 151   {name.expires = time; \
 152   add_timer (&name);}
 153 
 154 #define INB     inb
 155 #define OUTB    outb
 156 
 157 /*
 158  * SND_SA_INTERRUPT is required. Otherwise the IRQ number is not passed 
 159  * the handler.
 160  */
 161 #define SND_SA_INTERRUPT

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