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