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.
23 * $DragonFly: src/sys/i386/gnu/isa/sound/Attic/awe_compat.h,v 1.2 2004/02/12 23:33:26 joerg Exp $
26 /*----------------------------------------------------------------
27 * compatibility macros for AWE32 driver
28 *----------------------------------------------------------------*/
30 /* redefine following macros */
36 #undef GET_BYTE_FROM_USER
37 #undef GET_SHORT_FROM_USER
42 /*================================================================
44 *================================================================*/
46 /* use inline prefix */
49 /*----------------------------------------------------------------
50 * memory management for linux
51 *----------------------------------------------------------------*/
53 #ifdef AWE_OBSOLETE_VOXWARE
54 /* old type linux system */
56 /* i/o requests; nothing */
57 #define awe_check_port() 0 /* always false */
58 #define awe_request_region() /* nothing */
59 #define awe_release_region() /* nothing */
61 static int _mem_start; /* memory pointer for permanent buffers */
63 #define my_malloc_init(memptr) _mem_start = (memptr)
64 #define my_malloc_memptr() _mem_start
65 #define my_free(ptr) /* do nothing */
66 #define my_realloc(buf,oldsize,size) NULL /* no realloc */
68 static void *my_malloc(int size)
71 PERMANENT_MALLOC(ptr, char*, size, _mem_start);
75 /* allocate buffer only once */
76 #define INIT_TABLE(buffer,index,nums,type) {\
77 buffer = my_malloc(sizeof(type) * (nums)); index = (nums);\
82 #define AWE_DYNAMIC_BUFFER
84 #define my_malloc_init(ptr) /* nothing */
85 #define my_malloc_memptr() 0
86 #define my_malloc(size) vmalloc(size)
87 #define my_free(ptr) if (ptr) {vfree(ptr);}
89 static void *my_realloc(void *buf, int oldsize, int size)
92 if ((ptr = vmalloc(size)) == NULL)
94 memcpy(ptr, buf, ((oldsize < size) ? oldsize : size) );
99 /* do not allocate buffer at beginning */
100 #define INIT_TABLE(buffer,index,nums,type) {buffer=NULL; index=0;}
103 #define RET_ERROR(err) -err
107 /*----------------------------------------------------------------
108 * i/o interfaces for linux
109 *----------------------------------------------------------------*/
111 #define OUTW(data,addr) outw(data, addr)
113 #ifdef AWE_NEW_KERNEL_INTERFACE
114 #define COPY_FROM_USER(target,source,offs,count) \
115 copy_from_user(target, (source)+(offs), count)
116 #define GET_BYTE_FROM_USER(target,addr,offs) \
117 get_user(target, (unsigned char*)&((addr)[offs]))
118 #define GET_SHORT_FROM_USER(target,addr,offs) \
119 get_user(target, (unsigned short*)&((addr)[offs]))
121 #define IOCTL_TO_USER(target,offs,source,count) \
122 memcpy(target, (source)+(offs), count)
123 #define IO_WRITE_CHECK(cmd) (_SIOC_DIR(cmd) & _IOC_WRITE)
125 #define IOCTL_TO_USER(target,offs,source,count) \
126 copy_to_user(target, (source)+(offs), count)
127 #define IO_WRITE_CHECK(cmd) (_IOC_DIR(cmd) & _IOC_WRITE)
128 #endif /* AWE_OSS38 */
129 #define COPY_TO_USER IOCTL_TO_USER
130 #define IOCTL_IN(arg) (*(int*)(arg))
131 #define IOCTL_OUT(arg,val) (*(int*)(arg) = (val))
133 #else /* old type i/o */
134 #define COPY_FROM_USER(target,source,offs,count) \
135 memcpy_fromfs(target, (source)+(offs), (count))
136 #define GET_BYTE_FROM_USER(target,addr,offs) \
137 *((char *)&(target)) = get_fs_byte((addr)+(offs))
138 #define GET_SHORT_FROM_USER(target,addr,offs) \
139 *((short *)&(target)) = get_fs_word((addr)+(offs))
140 #define IOCTL_TO_USER(target,offs,source,count) \
141 memcpy_tofs(target, (source)+(offs), (count))
142 #define COPY_TO_USER IOCTL_TO_USER
143 #define IO_WRITE_CHECK(cmd) (cmd & IOC_IN)
144 #define IOCTL_IN(arg) get_fs_long((long *)(arg))
145 #define IOCTL_OUT(arg,ret) snd_ioctl_return((int *)arg, ret)
147 #endif /* AWE_NEW_KERNEL_INTERFACE */
149 #define BZERO(target,len) memset(target, 0, len)
150 #define MEMCPY(dst,src,len) memcpy(dst, src, len)
153 #elif defined(__DragonFly__) || defined(__FreeBSD__)
155 /*================================================================
157 *================================================================*/
159 /* inline is not checked yet.. maybe it'll work */
160 #define INLINE /*inline*/
162 /*----------------------------------------------------------------
163 * memory management for freebsd
164 *----------------------------------------------------------------*/
166 /* i/o requests; nothing */
167 #define awe_check_port() 0 /* always false */
168 #define awe_request_region() /* nothing */
169 #define awe_release_region() /* nothing */
171 #define AWE_DYNAMIC_BUFFER
173 #define my_malloc_init(ptr) /* nothing */
174 #define my_malloc_memptr() 0
175 #define my_malloc(size) malloc(size, M_TEMP, M_WAITOK)
176 #define my_free(ptr) if (ptr) {free(ptr, M_TEMP);}
178 #define INIT_TABLE(buffer,index,nums,type) {buffer=NULL; index=0;}
180 /* it should be realloc? */
181 static void *my_realloc(void *buf, int oldsize, int size)
184 if ((ptr = my_malloc(size)) == NULL)
186 memcpy(ptr, buf, ((oldsize < size) ? oldsize : size) );
191 /*----------------------------------------------------------------
192 * i/o interfaces for freebsd
193 *----------------------------------------------------------------*/
195 /* according to linux rule; the arguments are swapped */
196 #define OUTW(data,addr) outw(addr, data)
198 #define COPY_FROM_USER(target,source,offs,count) \
199 uiomove(((caddr_t)(target)),(count),((struct uio *)(source)))
200 #define COPY_TO_USER(target,source,offs,count) \
201 uiomove(((caddr_t)(source)),(count),((struct uio *)(target)))
202 #define GET_BYTE_FROM_USER(target,addr,offs) \
203 uiomove(((char*)&(target)), 1, ((struct uio *)(addr)))
204 #define GET_SHORT_FROM_USER(target,addr,offs) \
205 uiomove(((char*)&(target)), 2, ((struct uio *)(addr)))
206 #define IOCTL_TO_USER(target,offs,source,count) \
207 memcpy(&((target)[offs]), (source), (count))
208 #define IO_WRITE_CHECK(cmd) (cmd & IOC_IN)
209 #define IOCTL_IN(arg) (*(int*)(arg))
210 #define IOCTL_OUT(arg,val) (*(int*)(arg) = (val))
211 #define BZERO(target,len) bzero((caddr_t)target, len)
212 #define MEMCPY(dst,src,len) bcopy((caddr_t)src, (caddr_t)dst, len)
214 #ifndef AWE_OBSOLETE_VOXWARE
215 # define printk printf
216 # define RET_ERROR(err) -err