Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / pci / n8 / include_private / n8_OS_intf.h
blob4296a87ff4f5f5737e05e40cdebe0180fcfa0e61
1 /*-
2 * Copyright (C) 2001-2003 by NBMK Encryption Technologies.
3 * All rights reserved.
5 * NBMK Encryption Technologies provides no support of any kind for
6 * this software. Questions or concerns about it may be addressed to
7 * the members of the relevant open-source community at
8 * <tech-crypto@netbsd.org>.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are
12 * met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above
18 * copyright notice, this list of conditions and the following
19 * disclaimer in the documentation and/or other materials provided
20 * with the distribution.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 /*****************************************************************************
36 * @(#) n8_OS_intf.h 1.39@(#)
37 *****************************************************************************/
39 /*****************************************************************************/
40 /** @file n8_OS_intf.h
41 * @brief OS-dependent definitions for NSP2000 Interface
43 * Common header file for root definitions for NSP2000 project
45 *****************************************************************************/
47 /*****************************************************************************
48 * Revision history:
49 * 02/19/04 jpw Added KERN_WARNING to defines for N8_PRINT
50 * 07/28/03 brr Only define N8_THREAD_INIT for user space when
51 * SUPPORT_USER_CALLBACK_PTHREAD is defined. The allows users to
52 * enable kernel callbacks with requiring applications to link
53 * with the pthread library.
54 * 04/29/03 brr Removed support for BSDi.
55 * 03/24/03 brr Added definition for n8_atomic_inc_and_test.
56 * 03/10/03 brr Added macros to support thread initialization.
57 * 12/02/02 brr Only define ioctl macros for user space.
58 * 10/25/02 brr Do not define N8_VirtToPhys for FreeBSD kernel.
59 * 10/11/02 brr Added support for FreeBSD.
60 * 07/19/02 brr Moved definitions of N8_VirtToPhys & N8_PhysToVirt here from
61 * n8_driver_api.h.
62 * 07/02/02 brr Added atomic operations.
63 * 06/12/02 hml Deleted BSD ATOMICLOCK ops as well as the user space
64 * N8_PhysToVirt macros.
65 * 06/11/02 hml VX N8_AtomicLock* removed as promised.
66 * 06/11/02 hml Removed user space versions of N8_AtomicLock* interfaces.
67 * Vx will go next!
68 * 06/10/02 hml Added user space versions of the N8_AtomicLock* interfaces
69 * for Linux and BSD. Also added n8_Lock_t for all OS's.
70 * 06/06/02 brr Moved n8_WaitQueue_t definition to helper.h.
71 * 05/17/02 brr Added n8_WaitQueue_t.
72 * 04/11/02 brr Define N8_YEILD for Linux kernel.
73 * 03/14/02 brr Removed IoctlCode, added N8_IOCTL
74 * 02/25/02 brr Added N8_PRINT.
75 * 02/22/02 spm Cleaned up debug macros so that we use the DBG macro only.
76 * Converted n8_udelay to n8_usleep.
77 * 01/21/02 msz Added N8_YIELD
78 * 01/08/02 brr Added n8_delay and other kernel specific interfaces for 2.1.
79 * 11/28/01 bac Removed #define for usleep for vxworks. Use n8_usleep
80 * instead.
81 * 10/24/01 dkm Moved N8_DEF_MAX_NUM_PARAMS define to n8_pub_common.h
82 * 10/15/01 brr Removed misc warnings and removed semaphore macros.
83 * 10/09/01 msz Added n8_mkdir as VxWorks doesn't have mode_t (permission
84 * flags.)
85 * 08/21/01 msz Deleted COPY_IN, COPY_OUT as they are no longer used,
86 * code uses QMCopy directly.
87 * 08/15/01 brr Added VxWorks semaphores.
88 * 08/13/01 msz Don't define semun if we got _LINUX_SEM_H
89 * 08/08/01 msz Moved semun from n8_semaphore.h
90 * 08/10/01 brr Replaced IoctlCode for VxWorks.
91 * 08/08/01 brr Moved all OS kernel specific macros to helper.h.
92 * 08/01/01 msz Use _IOWR not IOWR for BSDi
93 * 07/31/01 bac Update COPY_IN and COPY_OUT to use QMCopy, renamed MIN/MAX to
94 * N8_MIN/N8_MAX.
95 * 07/30/01 brr Added definition for munmap - VxWorks Mod.
96 * 07/26/01 mel Deleted redefinitions for MALLOC and FREE - we are not using them.
97 * 07/27/01 brr Added definision for printk & KERN_CRIT - VxWorks Mod.
98 * 07/20/01 mel Added definision for usleep - VxWorks Mod.
99 ****************************************************************************/
101 /* DBG usage:
102 * DBG(("format string...", arg1, arg2, ...));
105 #ifndef N8_OS_INTF_H
106 #define N8_OS_INTF_H
108 #ifdef VX_BUILD
109 #include "n8_pub_common.h"
110 #include <vxWorks.h>
111 #include <stdio.h>
112 #include <string.h>
113 #include <time.h>
114 #include <sysLib.h>
115 #include <taskLib.h>
116 #include <usrLib.h>
117 #include <netinet/in.h>
118 #endif
120 #define N8_MIN(x, y) ((x) < (y) ? (x) : (y))
121 #define N8_MAX(x, y) ((x) > (y) ? (x) : (y))
124 /*****************************************************************************
125 * Linux specific macros
126 ****************************************************************************/
127 #ifdef __linux
129 #ifndef __KERNEL__
130 #include <sched.h> /* for sched_yield */
131 #include <malloc.h>
132 #include <string.h>
133 #include <stdio.h> /* for printf */
134 #include <netinet/in.h> /* for ntohs */
135 #include <pthread.h> /* for the pthread mutex operations */
137 #ifdef N8DEBUG
138 #define DBG(_args) { printf("DEBUG <%s:%d>: ", \
139 __FILE__,__LINE__); printf _args; }
140 #else
141 #define DBG(_args)
142 #endif
143 #define N8_open(x,y,z) open(x,y)
144 #define N8_mkdir(p,m) mkdir(p,m)
145 #define N8_PRINT printf
146 #define KERN_CRIT
147 #define N8_YIELD sched_yield()
149 typedef int n8_atomic_t;
150 #define n8_atomic_set(var, value) (var = value)
151 #define n8_atomic_read(var) (var)
152 #define n8_atomic_add(var, value) (var += value)
153 #define n8_atomic_sub(var, value) (var -= value)
155 typedef pthread_t N8_Thread_t;
157 #ifdef SUPPORT_USER_CALLBACK_PTHREAD
158 #define N8_THREAD_INIT(entry, parm, thread) \
159 pthread_create(&thread, NULL, (void *)entry, (void *)parm)
160 #else
161 #define N8_THREAD_INIT(entry, parm, thread) (thread = (N8_Thread_t)0)
162 #endif
163 #else
164 #include <net/ip.h>
165 #include <asm/atomic.h>
167 #ifdef N8DEBUG
168 #define DBG(_args) { printk("DEBUG: <%s:%i> ", \
169 __FILE__, __LINE__); printk _args; }
170 #else
171 #define DBG(_args)
172 #endif
173 #define N8_PRINT printk
174 #define N8_YIELD
176 typedef atomic_t n8_atomic_t;
177 #define n8_atomic_set(var, value) atomic_set(&var, value)
178 #define n8_atomic_read(var) atomic_read(&var)
179 #define n8_atomic_add(var, value) atomic_add(value, &var)
180 #define n8_atomic_sub(var, value) atomic_sub(value, &var)
182 typedef int N8_Thread_t;
183 #define N8_THREAD_INIT(entry, parm,thread) \
184 thread = kernel_thread((int (*)(void *))entry, (void *)parm, \
185 CLONE_FS | CLONE_FILES | CLONE_SIGHAND)
186 #endif
188 extern void *N8_PhysToVirt(unsigned long phys);
189 extern unsigned long N8_VirtToPhys(void * virt);
192 typedef char n8_Lock_t[24];
194 #define N8_IOCTL ioctl
195 #define WHERE " "
197 /* semun defined for linux and n8_semaphore.h. It is already defined */
198 /* in BSDi, so this is a operating system difference. */
199 /* Furthermore semun does seem to be defined for the kernel, in */
200 /* /usr/src/linux/include/linux/sem.h, so it depends on what sem.h */
201 /* is included. */
202 /***********************************************************************
203 * NOTE: Following bit of nastiness taken from the linux semctl man page
204 ***********************************************************************/
205 #if ( defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED) ) \
206 || defined(_LINUX_SEM_H) || defined(__KERNEL__)
207 /* union semun is defined by including <sys/sem.h> */
208 #else
209 /* according to X/OPEN we have to define it ourselves */
210 union semun {
211 int val; /* value for SETVAL */
212 struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */
213 unsigned short int *array; /* array for GETALL, SETALL */
214 struct seminfo *__buf; /* buffer for IPC_INFO */
216 #endif
219 /*****************************************************************************
220 * VxWorks specific macros
221 ****************************************************************************/
222 #elif VX_BUILD
223 int vxProcParms(char *argv[N8_DEF_MAX_NUM_PARAMS], char *testStr);
225 #define sleep(x) taskDelay(x * sysClkRateGet())
227 #define N8_YIELD taskDelay(1)
229 #define WHERE " "
230 #define N8_mkdir(p,m) mkdir(p)
232 #ifdef N8DEBUG
233 #define DBG(_args) { printf("DEBUG <%s:%d>: ", \
234 __FILE__,__LINE__); printf _args; }
235 #else
236 #define DBG(_args)
237 #endif
239 #define N8_PRINT printf
240 #define KERN_CRIT
241 #define KERN_WARNING
243 typedef int n8_atomic_t;
244 #define n8_atomic_set(var, value) (var = value)
245 #define n8_atomic_read(var) (var)
246 #define n8_atomic_add(var, value) (var += value)
247 #define n8_atomic_sub(var, value) (var -= value)
249 typedef SEM_ID n8_Lock_t;
251 #define N8_VirtToPhys(addr) (unsigned long)addr
252 #define N8_PhysToVirt(addr) (void *)addr
254 typedef int N8_Thread_t;
255 #define N8_THREAD_INIT(entry, parm, thread) \
256 thread = sp((FUNCPTR)entry, parm, 0,0,0,0,0,0,0,0)
257 /*****************************************************************************
258 * FreeBSD specific macros
259 ****************************************************************************/
260 #elif __FreeBSD__
262 #include <sys/ioccom.h> /* ioctl defines: _IOWR, IOC */
263 #include <sys/param.h>
264 #ifndef KERNEL
265 #include <stdio.h> /* for printf */
266 #include <pthread.h>
267 #include <string.h>
269 #endif
271 #ifdef N8DEBUG
272 #define DBG(_args) { printf("DEBUG <%s:%d>: ", \
273 __FILE__,__LINE__); printf _args; }
274 #else
275 #define DBG(_args)
276 #endif
277 #define N8_PRINT printf
278 #define KERN_CRIT
279 #define KERN_WARNING
281 #define NSP2000_GROUP_NUM 0x31 /* a non-useful number */
283 #define WHERE __WHERE__
284 #define N8_open(x,y,z) open(x,y)
285 #define N8_mkdir(p,m) mkdir(p,m)
286 #define WakeUp(A) wakeup(A);
288 #define N8_YIELD sched_yield()
290 typedef char n8_Lock_t[24];
291 typedef int n8_atomic_t;
292 #define n8_atomic_set(var, value) (var = value)
293 #define n8_atomic_read(var) (var)
294 #define n8_atomic_add(var, value) (var += value)
295 #define n8_atomic_sub(var, value) (var -= value)
297 #ifdef KERNEL
298 /* We didn't see memcpy in bsd. */
299 #define memcpy(dst,src,len) bcopy((src),(dst),(len))
300 #else
301 extern unsigned long N8_VirtToPhys(void * virt);
303 typedef pthread_t N8_Thread_t;
304 #define N8_THREAD_INIT(entry, parm, thread) \
305 pthread_create(&thread, NULL, (void *)entry, (void *)parm)
307 extern int n8_ioctl(int fd,int command, int parm);
308 #define N8_IOCTL(fd,command,parm) n8_ioctl((fd),(command),(int)(parm))
309 #endif
311 /*****************************************************************************
312 * NetBSD specific macros
313 ****************************************************************************/
314 #elif __NetBSD__
316 #include <sys/ioccom.h> /* ioctl defines: _IOWR, IOC */
317 #include <sys/param.h>
318 #ifndef KERNEL
319 #include <stdio.h> /* for printf */
320 #include <pthread.h>
321 #include <string.h>
323 #endif
325 #ifdef N8DEBUG
326 #define DBG(_args) { printf("DEBUG <%s:%d>: ", \
327 __FILE__,__LINE__); printf _args; }
328 #else
329 #define DBG(_args)
330 #endif
331 #define N8_PRINT printf
332 #define KERN_CRIT
333 #define KERN_WARNING
335 #define NSP2000_GROUP_NUM 0x31 /* a non-useful number */
337 #define WHERE __WHERE__
338 #define N8_open(x,y,z) open(x,y)
339 #define N8_mkdir(p,m) mkdir(p,m)
340 #define WakeUp(A) wakeup(A);
342 #define N8_YIELD sched_yield()
344 typedef char n8_Lock_t[24];
345 typedef int n8_atomic_t;
346 #define n8_atomic_set(var, value) (var = value)
347 #define n8_atomic_read(var) (var)
348 #define n8_atomic_add(var, value) (var += value)
349 #define n8_atomic_sub(var, value) (var -= value)
351 #ifdef KERNEL
352 #if 0
353 /* We didn't see memcpy in bsd. */
354 #define memcpy(dst,src,len) bcopy((src),(dst),(len))
355 #endif
356 #else
357 extern unsigned long N8_VirtToPhys(void * virt);
359 typedef pthread_t N8_Thread_t;
360 #define N8_THREAD_INIT(entry, parm, thread) \
361 pthread_create(&thread, NULL, (void *)entry, (void *)parm)
363 extern int n8_ioctl(int fd,int command, int parm);
364 #define N8_IOCTL(fd,command,parm) n8_ioctl((fd),(command),(int)(parm))
365 #endif
367 #define n8_delay_ms(ms) DELAY((ms*1000))
369 #endif /* __NetBSD__ */
371 #endif /* N8_OS_INTF_H */