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