1 /* $Id: platform.h,v 1.37.4.6 2005/01/31 12:22:20 armin Exp $
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/module.h>
22 #include <linux/init.h>
23 #include <linux/kernel.h>
24 #include <linux/sched.h>
25 #include <linux/skbuff.h>
26 #include <linux/vmalloc.h>
27 #include <linux/proc_fs.h>
28 #include <linux/interrupt.h>
29 #include <linux/smp_lock.h>
30 #include <linux/delay.h>
31 #include <linux/list.h>
32 #include <asm/types.h>
37 /* activate debuglib for modules only */
39 #define DIVA_NO_DEBUGLIB
42 #define DIVA_INIT_FUNCTION __init
43 #define DIVA_EXIT_FUNCTION __exit
45 #define DIVA_USER_MODE_CARD_CONFIG 1
46 #define USE_EXTENDED_DEBUGS 1
48 #define MAX_ADAPTER 32
50 #define DIVA_ISTREAM 1
52 #define MEMORY_SPACE_TYPE 0
53 #define PORT_SPACE_TYPE 1
56 #include <linux/string.h>
83 #define NULL ((void *) 0)
102 #define MEM_TYPE_RAM 0
103 #define MEM_TYPE_PORT 1
104 #define MEM_TYPE_PROM 2
105 #define MEM_TYPE_CTLREG 3
106 #define MEM_TYPE_RESET 4
107 #define MEM_TYPE_CFG 5
108 #define MEM_TYPE_ADDRESS 6
109 #define MEM_TYPE_CONFIG 7
110 #define MEM_TYPE_CONTROL 8
112 #define MAX_MEM_TYPE 10
114 #define DIVA_OS_MEM_ATTACH_RAM(a) ((a)->ram)
115 #define DIVA_OS_MEM_ATTACH_PORT(a) ((a)->port)
116 #define DIVA_OS_MEM_ATTACH_PROM(a) ((a)->prom)
117 #define DIVA_OS_MEM_ATTACH_CTLREG(a) ((a)->ctlReg)
118 #define DIVA_OS_MEM_ATTACH_RESET(a) ((a)->reset)
119 #define DIVA_OS_MEM_ATTACH_CFG(a) ((a)->cfg)
120 #define DIVA_OS_MEM_ATTACH_ADDRESS(a) ((a)->Address)
121 #define DIVA_OS_MEM_ATTACH_CONFIG(a) ((a)->Config)
122 #define DIVA_OS_MEM_ATTACH_CONTROL(a) ((a)->Control)
124 #define DIVA_OS_MEM_DETACH_RAM(a, x) do { } while(0)
125 #define DIVA_OS_MEM_DETACH_PORT(a, x) do { } while(0)
126 #define DIVA_OS_MEM_DETACH_PROM(a, x) do { } while(0)
127 #define DIVA_OS_MEM_DETACH_CTLREG(a, x) do { } while(0)
128 #define DIVA_OS_MEM_DETACH_RESET(a, x) do { } while(0)
129 #define DIVA_OS_MEM_DETACH_CFG(a, x) do { } while(0)
130 #define DIVA_OS_MEM_DETACH_ADDRESS(a, x) do { } while(0)
131 #define DIVA_OS_MEM_DETACH_CONFIG(a, x) do { } while(0)
132 #define DIVA_OS_MEM_DETACH_CONTROL(a, x) do { } while(0)
135 #define DIM(array) (sizeof (array)/sizeof ((array)[0]))
138 #define DIVA_INVALID_FILE_HANDLE ((dword)(-1))
140 #define DIVAS_CONTAINING_RECORD(address, type, field) \
141 ((type *)((char*)(address) - (char*)(&((type *)0)->field)))
143 extern int sprintf(char *, const char*, ...);
145 typedef void* LIST_ENTRY;
147 typedef char DEVICE_NAME[64];
148 typedef struct _ISDN_ADAPTER ISDN_ADAPTER;
149 typedef struct _ISDN_ADAPTER* PISDN_ADAPTER;
151 typedef void (* DIVA_DI_PRINTF) (unsigned char *, ...);
152 #include "debuglib.h"
154 #define dtrc(p) DBG_PRV0(p)
155 #define dbug(a,p) DBG_PRV1(p)
158 typedef struct e_info_s E_INFO ;
160 typedef char diva_os_dependent_devica_name_t[64];
161 typedef void* PDEVICE_OBJECT;
163 struct _diva_os_soft_isr;
164 struct _diva_os_timer;
165 struct _ISDN_ADAPTER;
167 void diva_log_info(unsigned char *, ...);
170 ** XDI DIDD Interface
172 void diva_xdi_didd_register_adapter (int card);
173 void diva_xdi_didd_remove_adapter (int card);
178 static __inline__ void* diva_os_malloc (unsigned long flags, unsigned long size)
183 ret = (void *) vmalloc((unsigned int) size);
187 static __inline__ void diva_os_free (unsigned long flags, void* ptr)
193 ** use skbuffs for message buffer
195 typedef struct sk_buff diva_os_message_buffer_s;
196 diva_os_message_buffer_s *diva_os_alloc_message_buffer(unsigned long size, void **data_buf);
197 void diva_os_free_message_buffer(diva_os_message_buffer_s *dmb);
198 #define DIVA_MESSAGE_BUFFER_LEN(x) x->len
199 #define DIVA_MESSAGE_BUFFER_DATA(x) x->data
204 static __inline__ void diva_os_sleep(dword mSec)
208 static __inline__ void diva_os_wait(dword mSec)
214 ** PCI Configuration space access
216 void PCIwrite (byte bus, byte func, int offset, void* data, int length, void* pci_dev_handle);
217 void PCIread (byte bus, byte func, int offset, void* data, int length, void* pci_dev_handle);
220 ** I/O Port utilities
222 int diva_os_register_io_port (void *adapter, int register, unsigned long port,
223 unsigned long length, const char* name, int id);
225 ** I/O port access abstraction
227 byte inpp (void __iomem *);
228 word inppw (void __iomem *);
229 void inppw_buffer (void __iomem *, void*, int);
230 void outppw (void __iomem *, word);
231 void outppw_buffer (void __iomem * , void*, int);
232 void outpp (void __iomem *, word);
237 typedef struct _diva_os_adapter_irq_info {
241 } diva_os_adapter_irq_info_t;
242 int diva_os_register_irq (void* context, byte irq, const char* name);
243 void diva_os_remove_irq (void* context, byte irq);
245 #define diva_os_in_irq() in_irq()
248 ** Spin Lock framework
250 typedef long diva_os_spin_lock_magic_t;
251 typedef spinlock_t diva_os_spin_lock_t;
252 static __inline__ int diva_os_initialize_spin_lock (spinlock_t *lock, void * unused) { \
253 spin_lock_init (lock); return(0); }
254 static __inline__ void diva_os_enter_spin_lock (diva_os_spin_lock_t* a, \
255 diva_os_spin_lock_magic_t* old_irql, \
256 void* dbg) { spin_lock_bh(a); }
257 static __inline__ void diva_os_leave_spin_lock (diva_os_spin_lock_t* a, \
258 diva_os_spin_lock_magic_t* old_irql, \
259 void* dbg) { spin_unlock_bh(a); }
261 #define diva_os_destroy_spin_lock(a,b) do { } while(0)
264 ** Deffered processing framework
266 typedef int (*diva_os_isr_callback_t)(struct _ISDN_ADAPTER*);
267 typedef void (*diva_os_soft_isr_callback_t)(struct _diva_os_soft_isr* psoft_isr, void* context);
269 typedef struct _diva_os_soft_isr {
271 diva_os_soft_isr_callback_t callback;
272 void* callback_context;
273 char dpc_thread_name[24];
274 } diva_os_soft_isr_t;
276 int diva_os_initialize_soft_isr (diva_os_soft_isr_t* psoft_isr, diva_os_soft_isr_callback_t callback, void* callback_context);
277 int diva_os_schedule_soft_isr (diva_os_soft_isr_t* psoft_isr);
278 int diva_os_cancel_soft_isr (diva_os_soft_isr_t* psoft_isr);
279 void diva_os_remove_soft_isr (diva_os_soft_isr_t* psoft_isr);
284 void diva_os_get_time (dword* sec, dword* usec);
287 ** atomic operation, fake because we use threads
289 typedef int diva_os_atomic_t;
290 static diva_os_atomic_t __inline__
291 diva_os_atomic_increment(diva_os_atomic_t* pv)
296 static diva_os_atomic_t __inline__
297 diva_os_atomic_decrement(diva_os_atomic_t* pv)
307 #define IMPLEMENT_DTMF 1
308 #define IMPLEMENT_ECHO_CANCELLER 1
309 #define IMPLEMENT_RTP 1
310 #define IMPLEMENT_T38 1
311 #define IMPLEMENT_FAX_SUB_SEP_PWD 1
312 #define IMPLEMENT_V18 1
313 #define IMPLEMENT_DTMF_TONE 1
314 #define IMPLEMENT_PIAFS 1
315 #define IMPLEMENT_FAX_PAPER_FORMATS 1
316 #define IMPLEMENT_VOWN 1
317 #define IMPLEMENT_CAPIDTMF 1
318 #define IMPLEMENT_FAX_NONSTANDARD 1
319 #define VSWITCH_SUPPORT 1
321 #define IMPLEMENT_MARKED_OK_AFTER_FC 1
323 #define DIVA_IDI_RX_DMA 1
328 ** If only... In some cases we did use them for endianness conversion;
329 ** unfortunately, other uses were real iomem accesses.
331 #define READ_BYTE(addr) readb(addr)
332 #define READ_WORD(addr) readw(addr)
333 #define READ_DWORD(addr) readl(addr)
335 #define WRITE_BYTE(addr,v) writeb(v,addr)
336 #define WRITE_WORD(addr,v) writew(v,addr)
337 #define WRITE_DWORD(addr,v) writel(v,addr)
339 static inline __u16 GET_WORD(void *addr)
341 return le16_to_cpu(*(__le16 *)addr);
343 static inline __u32 GET_DWORD(void *addr)
345 return le32_to_cpu(*(__le32 *)addr);
347 static inline void PUT_WORD(void *addr, __u16 v)
349 *(__le16 *)addr = cpu_to_le16(v);
351 static inline void PUT_DWORD(void *addr, __u32 v)
353 *(__le32 *)addr = cpu_to_le32(v);
360 #if BITS_PER_LONG > 32
361 #define PLATFORM_GT_32BIT
362 #define ULongToPtr(x) (void *)(unsigned long)(x)
367 ** undef os definitions of macros we use
376 #define diva_os_dump_file_t char
377 #define diva_os_board_trace_t char
378 #define diva_os_dump_file(__x__) do { } while(0)
381 ** size of internal arrays
383 #define MAX_DESCRIPTORS 64
385 #endif /* __PLATFORM_H__ */