Merge from vendor branch OPENSSH:
[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  * $DragonFly: src/sys/i386/gnu/isa/sound/Attic/awe_compat.h,v 1.2 2004/02/12 23:33:26 joerg Exp $
24  */
25
26 /*----------------------------------------------------------------
27  * compatibility macros for AWE32 driver
28  *----------------------------------------------------------------*/
29
30 /* redefine following macros */
31 #undef IOCTL_IN
32 #undef IOCTL_OUT
33 #undef OUTW
34 #undef COPY_FROM_USER
35 #undef COPY_TO_USER
36 #undef GET_BYTE_FROM_USER
37 #undef GET_SHORT_FROM_USER
38 #undef IOCTL_TO_USER
39   
40 #ifdef linux
41
42 /*================================================================
43  * Linux macros
44  *================================================================*/
45
46 /* use inline prefix */
47 #define INLINE  inline
48
49 /*----------------------------------------------------------------
50  * memory management for linux
51  *----------------------------------------------------------------*/
52
53 #ifdef AWE_OBSOLETE_VOXWARE
54 /* old type linux system */
55
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 */
60
61 static int _mem_start;  /* memory pointer for permanent buffers */
62
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 */
67
68 static void *my_malloc(int size)
69 {
70         char *ptr;
71         PERMANENT_MALLOC(ptr, char*, size, _mem_start);
72         return (void*)ptr;
73 }
74
75 /* allocate buffer only once */
76 #define INIT_TABLE(buffer,index,nums,type) {\
77 buffer = my_malloc(sizeof(type) * (nums)); index = (nums);\
78 }
79
80 #else
81
82 #define AWE_DYNAMIC_BUFFER
83
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);}
88
89 static void *my_realloc(void *buf, int oldsize, int size)
90 {
91         void *ptr;
92         if ((ptr = vmalloc(size)) == NULL)
93                 return NULL;
94         memcpy(ptr, buf, ((oldsize < size) ? oldsize : size) );
95         vfree(buf);
96         return ptr;
97 }
98
99 /* do not allocate buffer at beginning */
100 #define INIT_TABLE(buffer,index,nums,type) {buffer=NULL; index=0;}
101
102 /* old type macro */
103 #define RET_ERROR(err)          -err
104
105 #endif
106
107 /*----------------------------------------------------------------
108  * i/o interfaces for linux
109  *----------------------------------------------------------------*/
110
111 #define OUTW(data,addr)         outw(data, addr)
112
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]))
120 #ifdef AWE_OSS38
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)
124 #else
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))
132
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)
146
147 #endif /* AWE_NEW_KERNEL_INTERFACE */
148
149 #define BZERO(target,len)       memset(target, 0, len)
150 #define MEMCPY(dst,src,len)     memcpy(dst, src, len)
151
152
153 #elif defined(__DragonFly__) || defined(__FreeBSD__)
154
155 /*================================================================
156  * FreeBSD macros
157  *================================================================*/
158
159 /* inline is not checked yet.. maybe it'll work */
160 #define INLINE  /*inline*/
161
162 /*----------------------------------------------------------------
163  * memory management for freebsd
164  *----------------------------------------------------------------*/
165
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 */
170
171 #define AWE_DYNAMIC_BUFFER
172
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);}
177
178 #define INIT_TABLE(buffer,index,nums,type) {buffer=NULL; index=0;}
179
180 /* it should be realloc? */
181 static void *my_realloc(void *buf, int oldsize, int size)
182 {
183         void *ptr;
184         if ((ptr = my_malloc(size)) == NULL)
185                 return NULL;
186         memcpy(ptr, buf, ((oldsize < size) ? oldsize : size) );
187         my_free(buf);
188         return ptr;
189 }
190
191 /*----------------------------------------------------------------
192  * i/o interfaces for freebsd
193  *----------------------------------------------------------------*/
194
195 /* according to linux rule; the arguments are swapped */
196 #define OUTW(data,addr)         outw(addr, data)
197
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)
213
214 #ifndef AWE_OBSOLETE_VOXWARE
215 #  define printk printf
216 #  define RET_ERROR(err)                -err
217 #endif
218
219 #endif
220