2 * Copyright (C) 2001-2003 by NBMK Encryption Technologies.
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>.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are
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 /*****************************************************************************
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
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.
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
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
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
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 ****************************************************************************/
102 * DBG(("format string...", arg1, arg2, ...));
109 #include "n8_pub_common.h"
117 #include <netinet/in.h>
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 ****************************************************************************/
130 #include <sched.h> /* for sched_yield */
133 #include <stdio.h> /* for printf */
134 #include <netinet/in.h> /* for ntohs */
135 #include <pthread.h> /* for the pthread mutex operations */
138 #define DBG(_args) { printf("DEBUG <%s:%d>: ", \
139 __FILE__,__LINE__); printf _args; }
143 #define N8_open(x,y,z) open(x,y)
144 #define N8_mkdir(p,m) mkdir(p,m)
145 #define N8_PRINT printf
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)
161 #define N8_THREAD_INIT(entry, parm, thread) (thread = (N8_Thread_t)0)
165 #include <asm/atomic.h>
168 #define DBG(_args) { printk("DEBUG: <%s:%i> ", \
169 __FILE__, __LINE__); printk _args; }
173 #define N8_PRINT printk
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)
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
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 */
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> */
209 /* according to X/OPEN we have to define it ourselves */
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 */
219 /*****************************************************************************
220 * VxWorks specific macros
221 ****************************************************************************/
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)
230 #define N8_mkdir(p,m) mkdir(p)
233 #define DBG(_args) { printf("DEBUG <%s:%d>: ", \
234 __FILE__,__LINE__); printf _args; }
239 #define N8_PRINT printf
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 ****************************************************************************/
262 #include <sys/ioccom.h> /* ioctl defines: _IOWR, IOC */
263 #include <sys/param.h>
265 #include <stdio.h> /* for printf */
272 #define DBG(_args) { printf("DEBUG <%s:%d>: ", \
273 __FILE__,__LINE__); printf _args; }
277 #define N8_PRINT printf
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)
298 /* We didn't see memcpy in bsd. */
299 #define memcpy(dst,src,len) bcopy((src),(dst),(len))
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))
311 /*****************************************************************************
312 * NetBSD specific macros
313 ****************************************************************************/
316 #include <sys/ioccom.h> /* ioctl defines: _IOWR, IOC */
317 #include <sys/param.h>
319 #include <stdio.h> /* for printf */
326 #define DBG(_args) { printf("DEBUG <%s:%d>: ", \
327 __FILE__,__LINE__); printf _args; }
331 #define N8_PRINT printf
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)
353 /* We didn't see memcpy in bsd. */
354 #define memcpy(dst,src,len) bcopy((src),(dst),(len))
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))
367 #define n8_delay_ms(ms) DELAY((ms*1000))
369 #endif /* __NetBSD__ */
371 #endif /* N8_OS_INTF_H */