4 * Compat defines for the AWE32/Sound Blaster 32 wave table synth. driver
5 * version 0.4.2c; Oct. 7, 1997
7 * Copyright (C) 1996,1997 Takashi Iwai
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.
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.
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.
24 /*----------------------------------------------------------------
25 * compatibility macros for AWE32 driver
26 *----------------------------------------------------------------*/
28 /* redefine following macros */
34 #undef GET_BYTE_FROM_USER
35 #undef GET_SHORT_FROM_USER
40 /*================================================================
42 *================================================================*/
44 /* use inline prefix */
47 /*----------------------------------------------------------------
48 * memory management for linux
49 *----------------------------------------------------------------*/
51 #ifdef AWE_OBSOLETE_VOXWARE
52 /* old type linux system */
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 */
59 static int _mem_start; /* memory pointer for permanent buffers */
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 */
66 static void *my_malloc(int size)
69 PERMANENT_MALLOC(ptr, char*, size, _mem_start);
73 /* allocate buffer only once */
74 #define INIT_TABLE(buffer,index,nums,type) {\
75 buffer = my_malloc(sizeof(type) * (nums)); index = (nums);\
80 #define AWE_DYNAMIC_BUFFER
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);}
87 static void *my_realloc(void *buf, int oldsize, int size)
90 if ((ptr = vmalloc(size)) == NULL)
92 memcpy(ptr, buf, ((oldsize < size) ? oldsize : size) );
97 /* do not allocate buffer at beginning */
98 #define INIT_TABLE(buffer,index,nums,type) {buffer=NULL; index=0;}
101 #define RET_ERROR(err) -err
105 /*----------------------------------------------------------------
106 * i/o interfaces for linux
107 *----------------------------------------------------------------*/
109 #define OUTW(data,addr) outw(data, addr)
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]))
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)
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))
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)
145 #endif /* AWE_NEW_KERNEL_INTERFACE */
147 #define BZERO(target,len) memset(target, 0, len)
148 #define MEMCPY(dst,src,len) memcpy(dst, src, len)
151 #elif defined(__FreeBSD__)
153 /*================================================================
155 *================================================================*/
157 /* inline is not checked yet.. maybe it'll work */
158 #define INLINE /*inline*/
160 /*----------------------------------------------------------------
161 * memory management for freebsd
162 *----------------------------------------------------------------*/
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 */
169 #define AWE_DYNAMIC_BUFFER
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);}
176 #define INIT_TABLE(buffer,index,nums,type) {buffer=NULL; index=0;}
178 /* it should be realloc? */
179 static void *my_realloc(void *buf, int oldsize, int size)
182 if ((ptr = my_malloc(size)) == NULL)
184 memcpy(ptr, buf, ((oldsize < size) ? oldsize : size) );
189 /*----------------------------------------------------------------
190 * i/o interfaces for freebsd
191 *----------------------------------------------------------------*/
193 /* according to linux rule; the arguments are swapped */
194 #define OUTW(data,addr) outw(addr, data)
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)
212 #ifndef AWE_OBSOLETE_VOXWARE
213 # define printk printf
214 # define RET_ERROR(err) -err