Merge branch 'for-linus' of git://git390.osdl.marist.edu/pub/scm/linux-2.6
[pandora-kernel.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 far
87 #define far
88 #endif
89
90 #ifndef _pascal
91 #define _pascal
92 #endif
93
94 #ifndef _loadds
95 #define _loadds
96 #endif
97
98 #ifndef _cdecl
99 #define _cdecl
100 #endif
101
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
111
112 #define MAX_MEM_TYPE            10
113
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)
123
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)
133
134 #if !defined(DIM)
135 #define DIM(array)  (sizeof (array)/sizeof ((array)[0]))
136 #endif
137
138 #define DIVA_INVALID_FILE_HANDLE  ((dword)(-1))
139
140 #define DIVAS_CONTAINING_RECORD(address, type, field) \
141         ((type *)((char*)(address) - (char*)(&((type *)0)->field)))
142
143 extern int sprintf(char *, const char*, ...);
144
145 typedef void* LIST_ENTRY;
146
147 typedef char    DEVICE_NAME[64];
148 typedef struct _ISDN_ADAPTER   ISDN_ADAPTER;
149 typedef struct _ISDN_ADAPTER* PISDN_ADAPTER;
150
151 typedef void (* DIVA_DI_PRINTF) (unsigned char *, ...);
152 #include "debuglib.h"
153
154 #define dtrc(p) DBG_PRV0(p)
155 #define dbug(a,p) DBG_PRV1(p)
156
157
158 typedef struct e_info_s E_INFO ;
159
160 typedef char diva_os_dependent_devica_name_t[64];
161 typedef void* PDEVICE_OBJECT;
162
163 struct _diva_os_soft_isr;
164 struct _diva_os_timer;
165 struct _ISDN_ADAPTER;
166
167 void diva_log_info(unsigned char *, ...);
168
169 /*
170 **  XDI DIDD Interface
171 */
172 void diva_xdi_didd_register_adapter (int card);
173 void diva_xdi_didd_remove_adapter (int card);
174
175 /*
176 ** memory allocation
177 */
178 static __inline__ void* diva_os_malloc (unsigned long flags, unsigned long size)
179 {
180         void *ret = NULL;
181
182         if (size) {
183                 ret = (void *) vmalloc((unsigned int) size);
184         }
185         return (ret);
186 }
187 static __inline__ void  diva_os_free   (unsigned long flags, void* ptr)
188 {
189         vfree(ptr);
190 }
191
192 /*
193 ** use skbuffs for message buffer
194 */
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
200
201 /*
202 ** mSeconds waiting
203 */
204 static __inline__ void diva_os_sleep(dword mSec)
205 {
206         msleep(mSec);
207 }
208 static __inline__ void diva_os_wait(dword mSec)
209 {
210         mdelay(mSec);
211 }
212
213 /*
214 **  PCI Configuration space access
215 */
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);
218
219 /*
220 **  I/O Port utilities
221 */
222 int diva_os_register_io_port (void *adapter, int register, unsigned long port,
223                                 unsigned long length, const char* name, int id);
224 /*
225 **  I/O port access abstraction
226 */
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);
233
234 /*
235 **  IRQ 
236 */
237 typedef struct _diva_os_adapter_irq_info {
238         byte irq_nr;
239         int  registered;
240         char irq_name[24];
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);
244
245 #define diva_os_in_irq() in_irq()
246
247 /*
248 **  Spin Lock framework
249 */
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); }
260
261 #define diva_os_destroy_spin_lock(a,b) do { } while(0)
262
263 /*
264 **  Deffered processing framework
265 */
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);
268
269 typedef struct _diva_os_soft_isr {
270   void* object;
271   diva_os_soft_isr_callback_t callback;
272   void* callback_context;
273   char dpc_thread_name[24];
274 } diva_os_soft_isr_t;
275
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);
280
281 /*
282   Get time service
283   */
284 void diva_os_get_time (dword* sec, dword* usec);
285
286 /*
287 **  atomic operation, fake because we use threads
288 */
289 typedef int diva_os_atomic_t;
290 static diva_os_atomic_t __inline__
291 diva_os_atomic_increment(diva_os_atomic_t* pv)
292 {
293   *pv += 1;
294   return (*pv);
295 }
296 static diva_os_atomic_t __inline__
297 diva_os_atomic_decrement(diva_os_atomic_t* pv)
298 {
299   *pv -= 1;
300   return (*pv);
301 }
302
303 /* 
304 **  CAPI SECTION
305 */
306 #define NO_CORNETN
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
320
321 #define IMPLEMENT_MARKED_OK_AFTER_FC 1
322
323 #define DIVA_IDI_RX_DMA 1
324
325 /*
326 ** endian macros
327 **
328 ** If only...  In some cases we did use them for endianness conversion;
329 ** unfortunately, other uses were real iomem accesses.
330 */
331 #define READ_BYTE(addr)   readb(addr)
332 #define READ_WORD(addr)   readw(addr)
333 #define READ_DWORD(addr)  readl(addr)
334
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)
338
339 static inline __u16 GET_WORD(void *addr)
340 {
341         return le16_to_cpu(*(__le16 *)addr);
342 }
343 static inline __u32 GET_DWORD(void *addr)
344 {
345         return le32_to_cpu(*(__le32 *)addr);
346 }
347 static inline void PUT_WORD(void *addr, __u16 v)
348 {
349         *(__le16 *)addr = cpu_to_le16(v);
350 }
351 static inline void PUT_DWORD(void *addr, __u32 v)
352 {
353         *(__le32 *)addr = cpu_to_le32(v);
354 }
355
356 /*
357 ** 32/64 bit macors
358 */
359 #ifdef BITS_PER_LONG
360  #if BITS_PER_LONG > 32 
361   #define PLATFORM_GT_32BIT
362   #define ULongToPtr(x) (void *)(unsigned long)(x)
363  #endif
364 #endif
365
366 /*
367 ** undef os definitions of macros we use
368 */
369 #undef ID_MASK
370 #undef N_DATA
371 #undef ADDR
372
373 /*
374 ** dump file
375 */
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)
379
380 /*
381 ** size of internal arrays
382 */
383 #define MAX_DESCRIPTORS 64
384
385 #endif  /* __PLATFORM_H__ */