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