Linux-2.6.12-rc2
[safe/jmp/linux-2.6] / drivers / isdn / hardware / eicon / platform.h
1 /* $Id: platform.h,v 1.37.4.6 2005/01/31 12:22:20 armin Exp $
2  *
3  * platform.h
4  * 
5  *
6  * Copyright 2000-2003  by Armin Schindler (mac@melware.de)
7  * Copyright 2000  Eicon Networks 
8  *
9  * This software may be used and distributed according to the terms
10  * of the GNU General Public License, incorporated herein by reference.
11  */
12
13
14 #ifndef __PLATFORM_H__
15 #define __PLATFORM_H__
16
17 #if !defined(DIVA_BUILD)
18 #define DIVA_BUILD "local"
19 #endif
20
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>
34 #include <asm/io.h>
35
36 #include "cardtype.h"
37
38 /* activate debuglib for modules only */
39 #ifndef MODULE
40 #define DIVA_NO_DEBUGLIB
41 #endif
42
43 #define DIVA_INIT_FUNCTION  __init
44 #define DIVA_EXIT_FUNCTION  __exit
45
46 #define DIVA_USER_MODE_CARD_CONFIG 1
47 #define USE_EXTENDED_DEBUGS 1
48
49 #define MAX_ADAPTER     32
50
51 #define DIVA_ISTREAM 1
52
53 #define MEMORY_SPACE_TYPE  0
54 #define PORT_SPACE_TYPE    1
55
56
57 #include <linux/string.h>
58
59 #ifndef byte
60 #define byte   u8
61 #endif
62
63 #ifndef word
64 #define word   u16
65 #endif
66
67 #ifndef dword
68 #define dword  u32
69 #endif
70
71 #ifndef qword
72 #define qword  u64
73 #endif
74
75 #ifndef TRUE
76 #define TRUE    1
77 #endif
78
79 #ifndef FALSE
80 #define FALSE   0
81 #endif
82
83 #ifndef NULL
84 #define NULL    ((void *) 0)
85 #endif
86
87 #ifndef MIN
88 #define MIN(a,b)        ((a)>(b) ? (b) : (a))
89 #endif
90
91 #ifndef MAX
92 #define MAX(a,b)        ((a)>(b) ? (a) : (b))
93 #endif
94
95 #ifndef far
96 #define far
97 #endif
98
99 #ifndef _pascal
100 #define _pascal
101 #endif
102
103 #ifndef _loadds
104 #define _loadds
105 #endif
106
107 #ifndef _cdecl
108 #define _cdecl
109 #endif
110
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
120
121 #define MAX_MEM_TYPE            10
122
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)
132
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)
142
143 #if !defined(DIM)
144 #define DIM(array)  (sizeof (array)/sizeof ((array)[0]))
145 #endif
146
147 #define DIVA_INVALID_FILE_HANDLE  ((dword)(-1))
148
149 #define DIVAS_CONTAINING_RECORD(address, type, field) \
150         ((type *)((char*)(address) - (char*)(&((type *)0)->field)))
151
152 extern int sprintf(char *, const char*, ...);
153
154 typedef void* LIST_ENTRY;
155
156 typedef char    DEVICE_NAME[64];
157 typedef struct _ISDN_ADAPTER   ISDN_ADAPTER;
158 typedef struct _ISDN_ADAPTER* PISDN_ADAPTER;
159
160 typedef void (* DIVA_DI_PRINTF) (unsigned char *, ...);
161 #include "debuglib.h"
162
163 #define dtrc(p) DBG_PRV0(p)
164 #define dbug(a,p) DBG_PRV1(p)
165
166
167 typedef struct e_info_s E_INFO ;
168
169 typedef char diva_os_dependent_devica_name_t[64];
170 typedef void* PDEVICE_OBJECT;
171
172 struct _diva_os_soft_isr;
173 struct _diva_os_timer;
174 struct _ISDN_ADAPTER;
175
176 void diva_log_info(unsigned char *, ...);
177
178 /*
179 **  XDI DIDD Interface
180 */
181 void diva_xdi_didd_register_adapter (int card);
182 void diva_xdi_didd_remove_adapter (int card);
183
184 /*
185 ** memory allocation
186 */
187 static __inline__ void* diva_os_malloc (unsigned long flags, unsigned long size)
188 {
189         void *ret = NULL;
190
191         if (size) {
192                 ret = (void *) vmalloc((unsigned int) size);
193         }
194         return (ret);
195 }
196 static __inline__ void  diva_os_free   (unsigned long flags, void* ptr)
197 {
198         vfree(ptr);
199 }
200
201 /*
202 ** use skbuffs for message buffer
203 */
204 typedef struct sk_buff diva_os_message_buffer_s;
205 diva_os_message_buffer_s *diva_os_alloc_message_buffer(unsigned long size, void **data_buf);
206 void diva_os_free_message_buffer(diva_os_message_buffer_s *dmb);
207 #define DIVA_MESSAGE_BUFFER_LEN(x) x->len
208 #define DIVA_MESSAGE_BUFFER_DATA(x) x->data
209
210 /*
211 ** mSeconds waiting
212 */
213 static __inline__ void diva_os_sleep(dword mSec)
214 {
215         msleep(mSec);
216 }
217 static __inline__ void diva_os_wait(dword mSec)
218 {
219         mdelay(mSec);
220 }
221
222 /*
223 **  PCI Configuration space access
224 */
225 void PCIwrite (byte bus, byte func, int offset, void* data, int length, void* pci_dev_handle);
226 void PCIread (byte bus, byte func, int offset, void* data, int length, void* pci_dev_handle);
227
228 /*
229 **  I/O Port utilities
230 */
231 int diva_os_register_io_port (void *adapter, int register, unsigned long port,
232                                 unsigned long length, const char* name, int id);
233 /*
234 **  I/O port access abstraction
235 */
236 byte inpp (void __iomem *);
237 word inppw (void __iomem *);
238 void inppw_buffer (void __iomem *, void*, int);
239 void outppw (void __iomem *, word);
240 void outppw_buffer (void __iomem * , void*, int);
241 void outpp (void __iomem *, word);
242
243 /*
244 **  IRQ 
245 */
246 typedef struct _diva_os_adapter_irq_info {
247         byte irq_nr;
248         int  registered;
249         char irq_name[24];
250 } diva_os_adapter_irq_info_t;
251 int diva_os_register_irq (void* context, byte irq, const char* name);
252 void diva_os_remove_irq (void* context, byte irq);
253
254 #define diva_os_in_irq() in_irq()
255
256 /*
257 **  Spin Lock framework
258 */
259 typedef long diva_os_spin_lock_magic_t;
260 typedef spinlock_t diva_os_spin_lock_t;
261 static __inline__ int diva_os_initialize_spin_lock (spinlock_t *lock, void * unused) { \
262   spin_lock_init (lock); return(0); }
263 static __inline__ void diva_os_enter_spin_lock (diva_os_spin_lock_t* a, \
264                               diva_os_spin_lock_magic_t* old_irql, \
265                               void* dbg) { spin_lock_bh(a); }
266 static __inline__ void diva_os_leave_spin_lock (diva_os_spin_lock_t* a, \
267                               diva_os_spin_lock_magic_t* old_irql, \
268                               void* dbg) { spin_unlock_bh(a); }
269
270 #define diva_os_destroy_spin_lock(a,b) do { } while(0)
271
272 /*
273 **  Deffered processing framework
274 */
275 typedef int (*diva_os_isr_callback_t)(struct _ISDN_ADAPTER*);
276 typedef void (*diva_os_soft_isr_callback_t)(struct _diva_os_soft_isr* psoft_isr, void* context);
277
278 typedef struct _diva_os_soft_isr {
279   void* object;
280   diva_os_soft_isr_callback_t callback;
281   void* callback_context;
282   char dpc_thread_name[24];
283 } diva_os_soft_isr_t;
284
285 int diva_os_initialize_soft_isr (diva_os_soft_isr_t* psoft_isr, diva_os_soft_isr_callback_t callback, void*   callback_context);
286 int diva_os_schedule_soft_isr (diva_os_soft_isr_t* psoft_isr);
287 int diva_os_cancel_soft_isr (diva_os_soft_isr_t* psoft_isr);
288 void diva_os_remove_soft_isr (diva_os_soft_isr_t* psoft_isr);
289
290 /*
291   Get time service
292   */
293 void diva_os_get_time (dword* sec, dword* usec);
294
295 /*
296 **  atomic operation, fake because we use threads
297 */
298 typedef int diva_os_atomic_t;
299 static diva_os_atomic_t __inline__
300 diva_os_atomic_increment(diva_os_atomic_t* pv)
301 {
302   *pv += 1;
303   return (*pv);
304 }
305 static diva_os_atomic_t __inline__
306 diva_os_atomic_decrement(diva_os_atomic_t* pv)
307 {
308   *pv -= 1;
309   return (*pv);
310 }
311
312 /* 
313 **  CAPI SECTION
314 */
315 #define NO_CORNETN
316 #define IMPLEMENT_DTMF 1
317 #define IMPLEMENT_ECHO_CANCELLER 1
318 #define IMPLEMENT_RTP 1
319 #define IMPLEMENT_T38 1
320 #define IMPLEMENT_FAX_SUB_SEP_PWD 1
321 #define IMPLEMENT_V18 1
322 #define IMPLEMENT_DTMF_TONE 1
323 #define IMPLEMENT_PIAFS 1
324 #define IMPLEMENT_FAX_PAPER_FORMATS 1
325 #define IMPLEMENT_VOWN 1
326 #define IMPLEMENT_CAPIDTMF 1
327 #define IMPLEMENT_FAX_NONSTANDARD 1
328 #define VSWITCH_SUPPORT 1
329
330 #define IMPLEMENT_MARKED_OK_AFTER_FC 1
331
332 #define DIVA_IDI_RX_DMA 1
333
334 /*
335 ** endian macros
336 **
337 ** If only...  In some cases we did use them for endianness conversion;
338 ** unfortunately, other uses were real iomem accesses.
339 */
340 #define READ_BYTE(addr)   readb(addr)
341 #define READ_WORD(addr)   readw(addr)
342 #define READ_DWORD(addr)  readl(addr)
343
344 #define WRITE_BYTE(addr,v)  writeb(v,addr)
345 #define WRITE_WORD(addr,v)  writew(v,addr)
346 #define WRITE_DWORD(addr,v) writel(v,addr)
347
348 static inline __u16 GET_WORD(void *addr)
349 {
350         return le16_to_cpu(*(__le16 *)addr);
351 }
352 static inline __u32 GET_DWORD(void *addr)
353 {
354         return le32_to_cpu(*(__le32 *)addr);
355 }
356 static inline void PUT_WORD(void *addr, __u16 v)
357 {
358         *(__le16 *)addr = cpu_to_le16(v);
359 }
360 static inline void PUT_DWORD(void *addr, __u32 v)
361 {
362         *(__le32 *)addr = cpu_to_le32(v);
363 }
364
365 /*
366 ** 32/64 bit macors
367 */
368 #ifdef BITS_PER_LONG
369  #if BITS_PER_LONG > 32 
370   #define PLATFORM_GT_32BIT
371   #define ULongToPtr(x) (void *)(unsigned long)(x)
372  #endif
373 #endif
374
375 /*
376 ** undef os definitions of macros we use
377 */
378 #undef ID_MASK
379 #undef N_DATA
380 #undef ADDR
381
382 /*
383 ** dump file
384 */
385 #define diva_os_dump_file_t char
386 #define diva_os_board_trace_t char
387 #define diva_os_dump_file(__x__) do { } while(0)
388
389 /*
390 ** size of internal arrays
391 */
392 #define MAX_DESCRIPTORS 64
393
394 #endif  /* __PLATFORM_H__ */