1 /* $Id: platform.h,v 1.37 2004/03/20 17:44:29 armin Exp $
6 * Copyright 2000-2003 by Armin Schindler (mac@melware.de)
7 * Copyright 2000 Eicon Networks
9 * This software may be used and distributed according to the terms
10 * of the GNU General Public License, incorporated herein by reference.
14 #ifndef __PLATFORM_H__
15 #define __PLATFORM_H__
17 #if !defined(DIVA_BUILD)
18 #define DIVA_BUILD "local"
21 #include <linux/config.h>
22 #include <linux/module.h>
23 #include <linux/init.h>
24 #include <linux/kernel.h>
25 #include <linux/sched.h>
26 #include <linux/skbuff.h>
27 #include <linux/vmalloc.h>
28 #include <linux/proc_fs.h>
29 #include <linux/interrupt.h>
30 #include <linux/smp_lock.h>
31 #include <linux/delay.h>
32 #include <linux/list.h>
33 #include <asm/types.h>
38 /* activate debuglib for modules only */
40 #define DIVA_NO_DEBUGLIB
43 #define DIVA_INIT_FUNCTION __init
44 #define DIVA_EXIT_FUNCTION __exit
46 #define DIVA_USER_MODE_CARD_CONFIG 1
47 #define USE_EXTENDED_DEBUGS 1
49 #define MAX_ADAPTER 32
51 #define DIVA_ISTREAM 1
53 #define MEMORY_SPACE_TYPE 0
54 #define PORT_SPACE_TYPE 1
57 #include <linux/string.h>
84 #define NULL ((void *) 0)
88 #define MIN(a,b) ((a)>(b) ? (b) : (a))
92 #define MAX(a,b) ((a)>(b) ? (a) : (b))
111 #define MEM_TYPE_RAM 0
112 #define MEM_TYPE_PORT 1
113 #define MEM_TYPE_PROM 2
114 #define MEM_TYPE_CTLREG 3
115 #define MEM_TYPE_RESET 4
116 #define MEM_TYPE_CFG 5
117 #define MEM_TYPE_ADDRESS 6
118 #define MEM_TYPE_CONFIG 7
119 #define MEM_TYPE_CONTROL 8
121 #define MAX_MEM_TYPE 10
123 #define DIVA_OS_MEM_ATTACH_RAM(a) ((a)->ram)
124 #define DIVA_OS_MEM_ATTACH_PORT(a) ((a)->port)
125 #define DIVA_OS_MEM_ATTACH_PROM(a) ((a)->prom)
126 #define DIVA_OS_MEM_ATTACH_CTLREG(a) ((a)->ctlReg)
127 #define DIVA_OS_MEM_ATTACH_RESET(a) ((a)->reset)
128 #define DIVA_OS_MEM_ATTACH_CFG(a) ((a)->cfg)
129 #define DIVA_OS_MEM_ATTACH_ADDRESS(a) ((a)->Address)
130 #define DIVA_OS_MEM_ATTACH_CONFIG(a) ((a)->Config)
131 #define DIVA_OS_MEM_ATTACH_CONTROL(a) ((a)->Control)
133 #define DIVA_OS_MEM_DETACH_RAM(a, x) do { } while(0)
134 #define DIVA_OS_MEM_DETACH_PORT(a, x) do { } while(0)
135 #define DIVA_OS_MEM_DETACH_PROM(a, x) do { } while(0)
136 #define DIVA_OS_MEM_DETACH_CTLREG(a, x) do { } while(0)
137 #define DIVA_OS_MEM_DETACH_RESET(a, x) do { } while(0)
138 #define DIVA_OS_MEM_DETACH_CFG(a, x) do { } while(0)
139 #define DIVA_OS_MEM_DETACH_ADDRESS(a, x) do { } while(0)
140 #define DIVA_OS_MEM_DETACH_CONFIG(a, x) do { } while(0)
141 #define DIVA_OS_MEM_DETACH_CONTROL(a, x) do { } while(0)
144 #define DIM(array) (sizeof (array)/sizeof ((array)[0]))
147 #define DIVA_INVALID_FILE_HANDLE ((dword)(-1))
149 #define DIVAS_CONTAINING_RECORD(address, type, field) \
150 ((type *)((char*)(address) - (char*)(&((type *)0)->field)))
152 extern int sprintf(char *, const char*, ...);
154 typedef void* LIST_ENTRY;
156 typedef char DEVICE_NAME[64];
157 typedef struct _ISDN_ADAPTER ISDN_ADAPTER;
158 typedef struct _ISDN_ADAPTER* PISDN_ADAPTER;
160 typedef void (* DIVA_DI_PRINTF) (unsigned char *, ...);
161 #include "debuglib.h"
163 #define dtrc(p) DBG_PRV0(p)
164 #define dbug(a,p) DBG_PRV1(p)
167 typedef struct e_info_s E_INFO ;
169 typedef char diva_os_dependent_devica_name_t[64];
170 typedef void* PDEVICE_OBJECT;
172 struct _diva_os_soft_isr;
173 struct _diva_os_timer;
174 struct _ISDN_ADAPTER;
176 void diva_log_info(unsigned char *, ...);
179 ** XDI DIDD Interface
181 void diva_xdi_didd_register_adapter (int card);
182 void diva_xdi_didd_remove_adapter (int card);
187 static __inline__ void* diva_os_malloc (unsigned long flags, unsigned long size)
192 ret = (void *) vmalloc((unsigned int) size);
196 static __inline__ void diva_os_free (unsigned long flags, void* ptr)
204 ** use skbuffs for message buffer
206 typedef struct sk_buff diva_os_message_buffer_s;
207 diva_os_message_buffer_s *diva_os_alloc_message_buffer(unsigned long size, void **data_buf);
208 void diva_os_free_message_buffer(diva_os_message_buffer_s *dmb);
209 #define DIVA_MESSAGE_BUFFER_LEN(x) x->len
210 #define DIVA_MESSAGE_BUFFER_DATA(x) x->data
215 static __inline__ void diva_os_sleep(dword mSec)
217 unsigned long timeout = HZ * mSec / 1000 + 1;
219 set_current_state(TASK_UNINTERRUPTIBLE);
220 schedule_timeout(timeout);
222 static __inline__ void diva_os_wait(dword mSec)
228 ** PCI Configuration space access
230 void PCIwrite (byte bus, byte func, int offset, void* data, int length, void* pci_dev_handle);
231 void PCIread (byte bus, byte func, int offset, void* data, int length, void* pci_dev_handle);
234 ** I/O Port utilities
236 int diva_os_register_io_port (void *adapter, int register, unsigned long port,
237 unsigned long length, const char* name, int id);
239 ** I/O port access abstraction
243 void inppw_buffer (void*, void*, int);
244 void outppw (void*, word);
245 void outppw_buffer (void* , void*, int);
246 void outpp (void*, word);
251 typedef struct _diva_os_adapter_irq_info {
255 } diva_os_adapter_irq_info_t;
256 int diva_os_register_irq (void* context, byte irq, const char* name);
257 void diva_os_remove_irq (void* context, byte irq);
259 #define diva_os_in_irq() in_irq()
262 ** Spin Lock framework
264 typedef long diva_os_spin_lock_magic_t;
265 typedef spinlock_t diva_os_spin_lock_t;
266 static __inline__ int diva_os_initialize_spin_lock (spinlock_t *lock, void * unused) { \
267 spin_lock_init (lock); return(0); }
268 static __inline__ void diva_os_enter_spin_lock (diva_os_spin_lock_t* a, \
269 diva_os_spin_lock_magic_t* old_irql, \
270 void* dbg) { spin_lock_bh(a); }
271 static __inline__ void diva_os_leave_spin_lock (diva_os_spin_lock_t* a, \
272 diva_os_spin_lock_magic_t* old_irql, \
273 void* dbg) { spin_unlock_bh(a); }
275 static __inline__ void diva_os_enter_spin_lock_hard (diva_os_spin_lock_t* a, \
276 diva_os_spin_lock_magic_t* old_irql, \
278 unsigned long flags; \
279 spin_lock_irqsave (a, flags); \
280 *old_irql = (diva_os_spin_lock_magic_t)flags; \
282 static __inline__ void diva_os_leave_spin_lock_hard (diva_os_spin_lock_t* a, \
283 diva_os_spin_lock_magic_t* old_irql, \
285 unsigned long flags = (unsigned long)*old_irql; \
286 spin_unlock_irqrestore (a, flags); \
289 #define diva_os_destroy_spin_lock(a,b) do { } while(0)
292 ** Deffered processing framework
294 typedef int (*diva_os_isr_callback_t)(struct _ISDN_ADAPTER*);
295 typedef void (*diva_os_soft_isr_callback_t)(struct _diva_os_soft_isr* psoft_isr, void* context);
297 typedef struct _diva_os_soft_isr {
299 diva_os_soft_isr_callback_t callback;
300 void* callback_context;
301 char dpc_thread_name[24];
302 } diva_os_soft_isr_t;
304 int diva_os_initialize_soft_isr (diva_os_soft_isr_t* psoft_isr, diva_os_soft_isr_callback_t callback, void* callback_context);
305 int diva_os_schedule_soft_isr (diva_os_soft_isr_t* psoft_isr);
306 int diva_os_cancel_soft_isr (diva_os_soft_isr_t* psoft_isr);
307 void diva_os_remove_soft_isr (diva_os_soft_isr_t* psoft_isr);
312 void diva_os_get_time (dword* sec, dword* usec);
315 ** atomic operation, fake because we use threads
317 typedef int diva_os_atomic_t;
318 static diva_os_atomic_t __inline__
319 diva_os_atomic_increment(diva_os_atomic_t* pv)
324 static diva_os_atomic_t __inline__
325 diva_os_atomic_decrement(diva_os_atomic_t* pv)
335 #define IMPLEMENT_DTMF 1
336 #define IMPLEMENT_ECHO_CANCELLER 1
337 #define IMPLEMENT_RTP 1
338 #define IMPLEMENT_T38 1
339 #define IMPLEMENT_FAX_SUB_SEP_PWD 1
340 #define IMPLEMENT_V18 1
341 #define IMPLEMENT_DTMF_TONE 1
342 #define IMPLEMENT_PIAFS 1
343 #define IMPLEMENT_FAX_PAPER_FORMATS 1
344 #define IMPLEMENT_VOWN 1
345 #define IMPLEMENT_CAPIDTMF 1
346 #define IMPLEMENT_FAX_NONSTANDARD 1
347 #define VSWITCH_SUPPORT 1
349 #define IMPLEMENT_MARKED_OK_AFTER_FC 1
351 #define DIVA_IDI_RX_DMA 1
353 #define READ_WORD(addr) readw(addr)
354 #define READ_DWORD(addr) readl(addr)
356 #define WRITE_WORD(addr,v) writew(v,addr)
357 #define WRITE_DWORD(addr,v) writel(v,addr)
360 #if BITS_PER_LONG > 32
361 #define PLATFORM_GT_32BIT
362 #define ULongToPtr(x) (void *)(unsigned long)(x)
370 #endif /* __PLATFORM_H__ */