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 #ifdef MODULE
  32 #include <linux/config.h>
  33 #include <linux/module.h>
  34 #include <linux/version.h>
  35 #endif
  36 
  37 #include <linux/param.h>
  38 #include <linux/types.h>
  39 #include <linux/errno.h>
  40 #include <linux/signal.h>
  41 #include <linux/fcntl.h>
  42 #include <linux/sched.h>
  43 #include <linux/timer.h>
  44 #include <linux/tty.h>
  45 #include <linux/ctype.h>
  46 #include <asm/io.h>
  47 #include <asm/segment.h>
  48 #include <asm/system.h>
  49 #include <asm/dma.h>
  50 #include <sys/kd.h>
  51 #include <linux/wait.h>
  52 #include <linux/malloc.h>
  53 #include <linux/string.h>
  54 
  55 #include <linux/soundcard.h>
  56 
  57 typedef char snd_rw_buf;
  58 
  59 #define FALSE   0
  60 #define TRUE    1
  61 
  62 #define COPY_FROM_USER(d, s, o, c)      memcpy_fromfs((d), &((s)[o]), (c))
  63 #define COPY_TO_USER(d, o, s, c)        memcpy_tofs(&((d)[o]), (s), (c))
  64 #define IOCTL_FROM_USER(d, s, o, c)     memcpy_fromfs((d), &((s)[o]), (c))
  65 #define IOCTL_TO_USER(d, o, s, c)       memcpy_tofs(&((d)[o]), (s), (c))
  66 
  67 #define GET_BYTE_FROM_USER(target, addr, offs)  target = get_fs_byte(&((addr)[offs]))
  68 #define GET_SHORT_FROM_USER(target, addr, offs) target = get_fs_word(&((addr)[offs]))
  69 #define GET_WORD_FROM_USER(target, addr, offs)  target = get_fs_long((long*)&((addr)[offs]))
  70 #define PUT_WORD_TO_USER(addr, offs, data)      put_fs_long(data, (long*)&((addr)[offs]))
  71 #define IOCTL_IN(arg)                   get_fs_long((long *)(arg))
  72 #define IOCTL_OUT(arg, ret)             snd_ioctl_return((int *)arg, ret)
  73 
  74 struct snd_wait {
  75           int mode; int aborting;
  76         };
  77 
  78 #define DEFINE_WAIT_QUEUE(name, flag) static struct wait_queue *name = NULL; \
  79         static volatile struct snd_wait flag = {0}
  80 #define DEFINE_WAIT_QUEUES(name, flag) static struct wait_queue *name = {NULL}; \
  81         static volatile struct snd_wait flag = {{0}}
  82 #define RESET_WAIT_QUEUE(q, f) {f.aborting = 0;f.mode = WK_NONE;}
  83 #define PROCESS_ABORTING(q, f) (/*f.aborting | */(current->signal & ~current->blocked))
  84 #define SET_ABORT_FLAG(q, f) f.aborting = 1
  85 #define TIMED_OUT(q, f) (f.mode & WK_TIMEOUT)
  86 #define DO_SLEEP(q, f, time_limit)      \
  87         { unsigned long tl;\
  88           if (time_limit) tl = current->timeout = jiffies + (time_limit); \
  89              else tl = 0xffffffff; \
  90           f.mode = WK_SLEEP;interruptible_sleep_on(&q); \
  91           if (!(f.mode & WK_WAKEUP)) \
  92            { \
  93              if (current->signal & ~current->blocked) \
  94                 f.aborting = 1; \
  95              else \
  96                 if (jiffies >= tl) f.mode |= WK_TIMEOUT; \
  97            } \
  98           f.mode &= ~WK_SLEEP; \
  99         }
 100 #define SOMEONE_WAITING(q, f) (f.mode & WK_SLEEP)
 101 #define WAKE_UP(q, f)                   {f.mode = WK_WAKEUP;wake_up(&q);}
 102 
 103 #define ALLOC_DMA_CHN(chn,deviceID)     request_dma(chn, deviceID)
 104 #define RELEASE_DMA_CHN(chn)            free_dma(chn)
 105 
 106 #define GET_TIME()                      jiffies
 107 #define RELEASE_IRQ                     free_irq
 108 #define RET_ERROR(err)                  -err
 109 
 110 /* DISABLE_INTR is used to disable interrupts.
 111    These macros store the current flags to the (unsigned long) variable given
 112    as a parameter. RESTORE_INTR returns the interrupt ebable bit to state
 113    before DISABLE_INTR or ENABLE_INTR */
 114 
 115 #define DISABLE_INTR(flags)     __asm__ __volatile__("pushfl ; popl %0 ; cli":"=r" (flags));
 116 #define RESTORE_INTR(flags)     __asm__ __volatile__("pushl %0 ; popfl": \
 117                                                         :"r" (flags));
 118 /* 
 119    KERNEL_MALLOC() allocates requested number of memory  and 
 120    KERNEL_FREE is used to free it. 
 121    These macros are never called from interrupt, in addition the
 122    nbytes will never be more than 4096 bytes. Generally the driver
 123    will allocate memory in blocks of 4k. If the kernel has just a
 124    page level memory allocation, 4K can be safely used as the size
 125    (the nbytes parameter can be ignored).
 126 */
 127 #define KERNEL_MALLOC(nbytes)   kmalloc(nbytes, GFP_KERNEL)
 128 #define KERNEL_FREE(addr)       kfree(addr)
 129 
 130 /*
 131  * The macro PERMANENT_MALLOC(typecast, mem_ptr, size, linux_ptr)
 132  * returns size bytes of
 133  * (kernel virtual) memory which will never get freed by the driver.
 134  * This macro is called only during boot. The linux_ptr is a linux specific
 135  * parameter which should be ignored in other operating systems.
 136  * The mem_ptr is a pointer variable where the macro assigns pointer to the
 137  * memory area. The type is the type of the mem_ptr.
 138  */
 139 #define PERMANENT_MALLOC(typecast, mem_ptr, size, linux_ptr) \
 140   {mem_ptr = (typecast)linux_ptr; \
 141    linux_ptr += (size);}
 142 
 143 /*
 144  * The macro DEFINE_TIMER defines variables for the ACTIVATE_TIMER if
 145  * required. The name is the variable/name to be used and the proc is
 146  * the procedure to be called when the timer expires.
 147  */
 148 
 149 #define DEFINE_TIMER(name, proc) \
 150   static struct timer_list name = \
 151   {NULL, NULL, 0, 0, proc}
 152 
 153 /*
 154  * The ACTIVATE_TIMER requests system to call 'proc' after 'time' ticks.
 155  */
 156 
 157 #define ACTIVATE_TIMER(name, proc, time) \
 158   {name.expires = (time)+jiffies; \
 159   add_timer (&name);}
 160 
 161 #define INB     inb
 162 #define INW     inw
 163 #define OUTB    outb
 164 #define OUTW    outw
 165 
 166 /*
 167  * SND_SA_INTERRUPT is required. Otherwise the IRQ number is not passed 
 168  * the handler.
 169  */
 170 #define SND_SA_INTERRUPT
 171 
 172 /*
 173  * The macro DECLARE_FILE() adds an entry to struct fileinfo referencing the
 174  * connected filestructure.
 175  * This entry must be initialized in sound_open() in soundcard.c
 176  *
 177  * ISSET_FILE_FLAG() allows checking of flags like O_NONBLOCK on files
 178  *
 179  */
 180 
 181 #define DECLARE_FILE()                   struct file *filp
 182 #define ISSET_FILE_FLAG(fileinfo, flag)  (fileinfo->filp->f_flags & (flag) ? \
 183                                           1 : 0)
 184 #define INT_HANDLER_PROTO() void(*hndlr)(int, struct pt_regs *)
 185 #define INT_HANDLER_PARMS(irq, parms) int irq, struct pt_regs *parms
 186 #define INT_HANDLER_CALL(irq) irq, NULL

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