Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / i386 / gnu / isa / sound / awe_compat.h
1 /*
2  * sound/awe_compat.h
3  *
4  * Compat defines for the AWE32/Sound Blaster 32 wave table synth. driver
5  *   version 0.4.2c; Oct. 7, 1997
6  *
7  * Copyright (C) 1996,1997 Takashi Iwai
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23
24 /*----------------------------------------------------------------
25  * compatibility macros for AWE32 driver
26  *----------------------------------------------------------------*/
27
28 /* redefine following macros */
29 #undef IOCTL_IN
30 #undef IOCTL_OUT
31 #undef OUTW
32 #undef COPY_FROM_USER
33 #undef COPY_TO_USER
34 #undef GET_BYTE_FROM_USER
35 #undef GET_SHORT_FROM_USER
36 #undef IOCTL_TO_USER
37   
38 #ifdef linux
39
40 /*================================================================
41  * Linux macros
42  *================================================================*/
43
44 /* use inline prefix */
45 #define INLINE  inline
46
47 /*----------------------------------------------------------------
48  * memory management for linux
49  *----------------------------------------------------------------*/
50
51 #ifdef AWE_OBSOLETE_VOXWARE
52 /* old type linux system */
53
54 /* i/o requests; nothing */
55 #define awe_check_port()        0       /* always false */
56 #define awe_request_region()    /* nothing */
57 #define awe_release_region()    /* nothing */
58
59 static int _mem_start;  /* memory pointer for permanent buffers */
60
61 #define my_malloc_init(memptr)  _mem_start = (memptr)
62 #define my_malloc_memptr()      _mem_start
63 #define my_free(ptr)    /* do nothing */
64 #define my_realloc(buf,oldsize,size)    NULL    /* no realloc */
65
66 static void *my_malloc(int size)
67 {
68         char *ptr;
69         PERMANENT_MALLOC(ptr, char*, size, _mem_start);
70         return (void*)ptr;
71 }
72
73 /* allocate buffer only once */
74 #define INIT_TABLE(buffer,index,nums,type) {\
75 buffer = my_malloc(sizeof(type) * (nums)); index = (nums);\
76 }
77
78 #else
79
80 #define AWE_DYNAMIC_BUFFER
81
82 #define my_malloc_init(ptr)     /* nothing */
83 #define my_malloc_memptr()      0
84 #define my_malloc(size)         vmalloc(size)
85 #define my_free(ptr)            if (ptr) {vfree(ptr);}
86
87 static void *my_realloc(void *buf, int oldsize, int size)
88 {
89         void *ptr;
90         if ((ptr = vmalloc(size)) == NULL)
91                 return NULL;
92         memcpy(ptr, buf, ((oldsize < size) ? oldsize : size) );
93         vfree(buf);
94         return ptr;
95 }
96
97 /* do not allocate buffer at beginning */
98 #define INIT_TABLE(buffer,index,nums,type) {buffer=NULL; index=0;}
99
100 /* old type macro */
101 #define RET_ERROR(err)          -err
102
103 #endif
104
105 /*----------------------------------------------------------------
106  * i/o interfaces for linux
107  *----------------------------------------------------------------*/
108
109 #define OUTW(data,addr)         outw(data, addr)
110
111 #ifdef AWE_NEW_KERNEL_INTERFACE
112 #define COPY_FROM_USER(target,source,offs,count) \
113         copy_from_user(target, (source)+(offs), count)
114 #define GET_BYTE_FROM_USER(target,addr,offs) \
115         get_user(target, (unsigned char*)&((addr)[offs]))
116 #define GET_SHORT_FROM_USER(target,addr,offs) \
117         get_user(target, (unsigned short*)&((addr)[offs]))
118 #ifdef AWE_OSS38
119 #define IOCTL_TO_USER(target,offs,source,count) \
120         memcpy(target, (source)+(offs), count)
121 #define IO_WRITE_CHECK(cmd)     (_SIOC_DIR(cmd) & _IOC_WRITE)
122 #else
123 #define IOCTL_TO_USER(target,offs,source,count) \
124         copy_to_user(target, (source)+(offs), count)
125 #define IO_WRITE_CHECK(cmd)     (_IOC_DIR(cmd) & _IOC_WRITE)
126 #endif /* AWE_OSS38 */
127 #define COPY_TO_USER    IOCTL_TO_USER
128 #define IOCTL_IN(arg)   (*(int*)(arg))
129 #define IOCTL_OUT(arg,val) (*(int*)(arg) = (val))
130
131 #else /* old type i/o */
132 #define COPY_FROM_USER(target,source,offs,count) \
133         memcpy_fromfs(target, (source)+(offs), (count))
134 #define GET_BYTE_FROM_USER(target,addr,offs) \
135         *((char  *)&(target)) = get_fs_byte((addr)+(offs))
136 #define GET_SHORT_FROM_USER(target,addr,offs) \
137         *((short *)&(target)) = get_fs_word((addr)+(offs))
138 #define IOCTL_TO_USER(target,offs,source,count) \
139         memcpy_tofs(target, (source)+(offs), (count))
140 #define COPY_TO_USER    IOCTL_TO_USER
141 #define IO_WRITE_CHECK(cmd)     (cmd & IOC_IN)
142 #define IOCTL_IN(arg)           get_fs_long((long *)(arg))
143 #define IOCTL_OUT(arg,ret)      snd_ioctl_return((int *)arg, ret)
144
145 #endif /* AWE_NEW_KERNEL_INTERFACE */
146
147 #define BZERO(target,len)       memset(target, 0, len)
148 #define MEMCPY(dst,src,len)     memcpy(dst, src, len)
149
150
151 #elif defined(__FreeBSD__)
152
153 /*================================================================
154  * FreeBSD macros
155  *================================================================*/
156
157 /* inline is not checked yet.. maybe it'll work */
158 #define INLINE  /*inline*/
159
160 /*----------------------------------------------------------------
161  * memory management for freebsd
162  *----------------------------------------------------------------*/
163
164 /* i/o requests; nothing */
165 #define awe_check_port()        0       /* always false */
166 #define awe_request_region()    /* nothing */
167 #define awe_release_region()    /* nothing */
168
169 #define AWE_DYNAMIC_BUFFER
170
171 #define my_malloc_init(ptr)     /* nothing */
172 #define my_malloc_memptr()      0
173 #define my_malloc(size)         malloc(size, M_TEMP, M_WAITOK)
174 #define my_free(ptr)            if (ptr) {free(ptr, M_TEMP);}
175
176 #define INIT_TABLE(buffer,index,nums,type) {buffer=NULL; index=0;}
177
178 /* it should be realloc? */
179 static void *my_realloc(void *buf, int oldsize, int size)
180 {
181         void *ptr;
182         if ((ptr = my_malloc(size)) == NULL)
183                 return NULL;
184         memcpy(ptr, buf, ((oldsize < size) ? oldsize : size) );
185         my_free(buf);
186         return ptr;
187 }
188
189 /*----------------------------------------------------------------
190  * i/o interfaces for freebsd
191  *----------------------------------------------------------------*/
192
193 /* according to linux rule; the arguments are swapped */
194 #define OUTW(data,addr)         outw(addr, data)
195
196 #define COPY_FROM_USER(target,source,offs,count) \
197         uiomove(((caddr_t)(target)),(count),((struct uio *)(source)))
198 #define COPY_TO_USER(target,source,offs,count) \
199         uiomove(((caddr_t)(source)),(count),((struct uio *)(target)))
200 #define GET_BYTE_FROM_USER(target,addr,offs) \
201         uiomove(((char*)&(target)), 1, ((struct uio *)(addr)))
202 #define GET_SHORT_FROM_USER(target,addr,offs) \
203         uiomove(((char*)&(target)), 2, ((struct uio *)(addr)))
204 #define IOCTL_TO_USER(target,offs,source,count) \
205         memcpy(&((target)[offs]), (source), (count))
206 #define IO_WRITE_CHECK(cmd)     (cmd & IOC_IN)
207 #define IOCTL_IN(arg)           (*(int*)(arg))
208 #define IOCTL_OUT(arg,val)      (*(int*)(arg) = (val))
209 #define BZERO(target,len)       bzero((caddr_t)target, len)
210 #define MEMCPY(dst,src,len)     bcopy((caddr_t)src, (caddr_t)dst, len)
211
212 #ifndef AWE_OBSOLETE_VOXWARE
213 #  define printk printf
214 #  define RET_ERROR(err)                -err
215 #endif
216
217 #endif
218