blob: b2edb7590ddadac95811106d664106b58eda7be7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $Id: platform.h,v 1.37.4.6 2005/01/31 12:22:20 armin Exp $
2 *
3 * platform.h
Joe Perches475be4d2012-02-19 19:52:38 -08004 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * Copyright 2000-2003 by Armin Schindler (mac@melware.de)
Joe Perches475be4d2012-02-19 19:52:38 -08007 * Copyright 2000 Eicon Networks
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#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
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#define DIVA_USER_MODE_CARD_CONFIG 1
42#define USE_EXTENDED_DEBUGS 1
43
44#define MAX_ADAPTER 32
45
46#define DIVA_ISTREAM 1
47
48#define MEMORY_SPACE_TYPE 0
49#define PORT_SPACE_TYPE 1
50
51
52#include <linux/string.h>
53
54#ifndef byte
55#define byte u8
56#endif
57
58#ifndef word
59#define word u16
60#endif
61
62#ifndef dword
63#define dword u32
64#endif
65
66#ifndef qword
67#define qword u64
68#endif
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070#ifndef NULL
71#define NULL ((void *) 0)
72#endif
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074#ifndef far
75#define far
76#endif
77
78#ifndef _pascal
79#define _pascal
80#endif
81
82#ifndef _loadds
83#define _loadds
84#endif
85
86#ifndef _cdecl
87#define _cdecl
88#endif
89
90#define MEM_TYPE_RAM 0
91#define MEM_TYPE_PORT 1
92#define MEM_TYPE_PROM 2
93#define MEM_TYPE_CTLREG 3
94#define MEM_TYPE_RESET 4
95#define MEM_TYPE_CFG 5
96#define MEM_TYPE_ADDRESS 6
97#define MEM_TYPE_CONFIG 7
98#define MEM_TYPE_CONTROL 8
99
100#define MAX_MEM_TYPE 10
101
102#define DIVA_OS_MEM_ATTACH_RAM(a) ((a)->ram)
103#define DIVA_OS_MEM_ATTACH_PORT(a) ((a)->port)
104#define DIVA_OS_MEM_ATTACH_PROM(a) ((a)->prom)
105#define DIVA_OS_MEM_ATTACH_CTLREG(a) ((a)->ctlReg)
106#define DIVA_OS_MEM_ATTACH_RESET(a) ((a)->reset)
107#define DIVA_OS_MEM_ATTACH_CFG(a) ((a)->cfg)
108#define DIVA_OS_MEM_ATTACH_ADDRESS(a) ((a)->Address)
109#define DIVA_OS_MEM_ATTACH_CONFIG(a) ((a)->Config)
110#define DIVA_OS_MEM_ATTACH_CONTROL(a) ((a)->Control)
111
Joe Perches475be4d2012-02-19 19:52:38 -0800112#define DIVA_OS_MEM_DETACH_RAM(a, x) do { } while (0)
113#define DIVA_OS_MEM_DETACH_PORT(a, x) do { } while (0)
114#define DIVA_OS_MEM_DETACH_PROM(a, x) do { } while (0)
115#define DIVA_OS_MEM_DETACH_CTLREG(a, x) do { } while (0)
116#define DIVA_OS_MEM_DETACH_RESET(a, x) do { } while (0)
117#define DIVA_OS_MEM_DETACH_CFG(a, x) do { } while (0)
118#define DIVA_OS_MEM_DETACH_ADDRESS(a, x) do { } while (0)
119#define DIVA_OS_MEM_DETACH_CONFIG(a, x) do { } while (0)
120#define DIVA_OS_MEM_DETACH_CONTROL(a, x) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122#define DIVA_INVALID_FILE_HANDLE ((dword)(-1))
123
Joe Perches475be4d2012-02-19 19:52:38 -0800124#define DIVAS_CONTAINING_RECORD(address, type, field) \
125 ((type *)((char *)(address) - (char *)(&((type *)0)->field)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Joe Perches475be4d2012-02-19 19:52:38 -0800127extern int sprintf(char *, const char *, ...);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
Joe Perches475be4d2012-02-19 19:52:38 -0800129typedef void *LIST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Joe Perches475be4d2012-02-19 19:52:38 -0800131typedef char DEVICE_NAME[64];
132typedef struct _ISDN_ADAPTER ISDN_ADAPTER;
133typedef struct _ISDN_ADAPTER *PISDN_ADAPTER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Joe Perches475be4d2012-02-19 19:52:38 -0800135typedef void (*DIVA_DI_PRINTF)(unsigned char *, ...);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136#include "debuglib.h"
137
138#define dtrc(p) DBG_PRV0(p)
Joe Perches475be4d2012-02-19 19:52:38 -0800139#define dbug(a, p) DBG_PRV1(p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141
Joe Perches475be4d2012-02-19 19:52:38 -0800142typedef struct e_info_s E_INFO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144typedef char diva_os_dependent_devica_name_t[64];
Joe Perches475be4d2012-02-19 19:52:38 -0800145typedef void *PDEVICE_OBJECT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
147struct _diva_os_soft_isr;
148struct _diva_os_timer;
149struct _ISDN_ADAPTER;
150
151void diva_log_info(unsigned char *, ...);
152
153/*
154** XDI DIDD Interface
155*/
Joe Perches475be4d2012-02-19 19:52:38 -0800156void diva_xdi_didd_register_adapter(int card);
157void diva_xdi_didd_remove_adapter(int card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
159/*
160** memory allocation
161*/
Joe Perches475be4d2012-02-19 19:52:38 -0800162static __inline__ void *diva_os_malloc(unsigned long flags, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163{
164 void *ret = NULL;
165
166 if (size) {
167 ret = (void *) vmalloc((unsigned int) size);
168 }
169 return (ret);
170}
Joe Perches475be4d2012-02-19 19:52:38 -0800171static __inline__ void diva_os_free(unsigned long flags, void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172{
173 vfree(ptr);
174}
175
176/*
177** use skbuffs for message buffer
178*/
179typedef struct sk_buff diva_os_message_buffer_s;
180diva_os_message_buffer_s *diva_os_alloc_message_buffer(unsigned long size, void **data_buf);
181void diva_os_free_message_buffer(diva_os_message_buffer_s *dmb);
182#define DIVA_MESSAGE_BUFFER_LEN(x) x->len
183#define DIVA_MESSAGE_BUFFER_DATA(x) x->data
184
185/*
186** mSeconds waiting
187*/
188static __inline__ void diva_os_sleep(dword mSec)
189{
190 msleep(mSec);
191}
192static __inline__ void diva_os_wait(dword mSec)
193{
194 mdelay(mSec);
195}
196
197/*
198** PCI Configuration space access
199*/
Joe Perches475be4d2012-02-19 19:52:38 -0800200void PCIwrite(byte bus, byte func, int offset, void *data, int length, void *pci_dev_handle);
201void PCIread(byte bus, byte func, int offset, void *data, int length, void *pci_dev_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
203/*
204** I/O Port utilities
205*/
Joe Perches475be4d2012-02-19 19:52:38 -0800206int diva_os_register_io_port(void *adapter, int register, unsigned long port,
207 unsigned long length, const char *name, int id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208/*
209** I/O port access abstraction
210*/
Joe Perches475be4d2012-02-19 19:52:38 -0800211byte inpp(void __iomem *);
212word inppw(void __iomem *);
213void inppw_buffer(void __iomem *, void *, int);
214void outppw(void __iomem *, word);
215void outppw_buffer(void __iomem * , void*, int);
216void outpp(void __iomem *, word);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
218/*
Joe Perches475be4d2012-02-19 19:52:38 -0800219** IRQ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220*/
221typedef struct _diva_os_adapter_irq_info {
Joe Perches475be4d2012-02-19 19:52:38 -0800222 byte irq_nr;
223 int registered;
224 char irq_name[24];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225} diva_os_adapter_irq_info_t;
Joe Perches475be4d2012-02-19 19:52:38 -0800226int diva_os_register_irq(void *context, byte irq, const char *name);
227void diva_os_remove_irq(void *context, byte irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229#define diva_os_in_irq() in_irq()
230
231/*
232** Spin Lock framework
233*/
234typedef long diva_os_spin_lock_magic_t;
235typedef spinlock_t diva_os_spin_lock_t;
Joe Perches475be4d2012-02-19 19:52:38 -0800236static __inline__ int diva_os_initialize_spin_lock(spinlock_t *lock, void *unused) { \
237 spin_lock_init(lock); return (0); }
238static __inline__ void diva_os_enter_spin_lock(diva_os_spin_lock_t *a, \
239 diva_os_spin_lock_magic_t *old_irql, \
240 void *dbg) { spin_lock_bh(a); }
241static __inline__ void diva_os_leave_spin_lock(diva_os_spin_lock_t *a, \
242 diva_os_spin_lock_magic_t *old_irql, \
243 void *dbg) { spin_unlock_bh(a); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Joe Perches475be4d2012-02-19 19:52:38 -0800245#define diva_os_destroy_spin_lock(a, b) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
247/*
248** Deffered processing framework
249*/
Joe Perches475be4d2012-02-19 19:52:38 -0800250typedef int (*diva_os_isr_callback_t)(struct _ISDN_ADAPTER *);
251typedef void (*diva_os_soft_isr_callback_t)(struct _diva_os_soft_isr *psoft_isr, void *context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
253typedef struct _diva_os_soft_isr {
Joe Perches475be4d2012-02-19 19:52:38 -0800254 void *object;
255 diva_os_soft_isr_callback_t callback;
256 void *callback_context;
257 char dpc_thread_name[24];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258} diva_os_soft_isr_t;
259
Joe Perches475be4d2012-02-19 19:52:38 -0800260int diva_os_initialize_soft_isr(diva_os_soft_isr_t *psoft_isr, diva_os_soft_isr_callback_t callback, void *callback_context);
261int diva_os_schedule_soft_isr(diva_os_soft_isr_t *psoft_isr);
262int diva_os_cancel_soft_isr(diva_os_soft_isr_t *psoft_isr);
263void diva_os_remove_soft_isr(diva_os_soft_isr_t *psoft_isr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
265/*
266 Get time service
Joe Perches475be4d2012-02-19 19:52:38 -0800267*/
268void diva_os_get_time(dword *sec, dword *usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270/*
271** atomic operation, fake because we use threads
272*/
273typedef int diva_os_atomic_t;
274static diva_os_atomic_t __inline__
Joe Perches475be4d2012-02-19 19:52:38 -0800275diva_os_atomic_increment(diva_os_atomic_t *pv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276{
Joe Perches475be4d2012-02-19 19:52:38 -0800277 *pv += 1;
278 return (*pv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279}
280static diva_os_atomic_t __inline__
Joe Perches475be4d2012-02-19 19:52:38 -0800281diva_os_atomic_decrement(diva_os_atomic_t *pv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282{
Joe Perches475be4d2012-02-19 19:52:38 -0800283 *pv -= 1;
284 return (*pv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285}
286
Joe Perches475be4d2012-02-19 19:52:38 -0800287/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288** CAPI SECTION
289*/
290#define NO_CORNETN
291#define IMPLEMENT_DTMF 1
292#define IMPLEMENT_ECHO_CANCELLER 1
293#define IMPLEMENT_RTP 1
294#define IMPLEMENT_T38 1
295#define IMPLEMENT_FAX_SUB_SEP_PWD 1
296#define IMPLEMENT_V18 1
297#define IMPLEMENT_DTMF_TONE 1
298#define IMPLEMENT_PIAFS 1
299#define IMPLEMENT_FAX_PAPER_FORMATS 1
300#define IMPLEMENT_VOWN 1
301#define IMPLEMENT_CAPIDTMF 1
302#define IMPLEMENT_FAX_NONSTANDARD 1
303#define VSWITCH_SUPPORT 1
304
305#define IMPLEMENT_MARKED_OK_AFTER_FC 1
306
307#define DIVA_IDI_RX_DMA 1
308
309/*
310** endian macros
311**
312** If only... In some cases we did use them for endianness conversion;
313** unfortunately, other uses were real iomem accesses.
314*/
315#define READ_BYTE(addr) readb(addr)
316#define READ_WORD(addr) readw(addr)
317#define READ_DWORD(addr) readl(addr)
318
Joe Perches475be4d2012-02-19 19:52:38 -0800319#define WRITE_BYTE(addr, v) writeb(v, addr)
320#define WRITE_WORD(addr, v) writew(v, addr)
321#define WRITE_DWORD(addr, v) writel(v, addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
323static inline __u16 GET_WORD(void *addr)
324{
325 return le16_to_cpu(*(__le16 *)addr);
326}
327static inline __u32 GET_DWORD(void *addr)
328{
329 return le32_to_cpu(*(__le32 *)addr);
330}
331static inline void PUT_WORD(void *addr, __u16 v)
332{
333 *(__le16 *)addr = cpu_to_le16(v);
334}
335static inline void PUT_DWORD(void *addr, __u32 v)
336{
337 *(__le32 *)addr = cpu_to_le32(v);
338}
339
340/*
341** 32/64 bit macors
342*/
343#ifdef BITS_PER_LONG
Joe Perches475be4d2012-02-19 19:52:38 -0800344#if BITS_PER_LONG > 32
345#define PLATFORM_GT_32BIT
346#define ULongToPtr(x) (void *)(unsigned long)(x)
347#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348#endif
349
350/*
351** undef os definitions of macros we use
352*/
353#undef ID_MASK
354#undef N_DATA
355#undef ADDR
356
357/*
358** dump file
359*/
360#define diva_os_dump_file_t char
361#define diva_os_board_trace_t char
Joe Perches475be4d2012-02-19 19:52:38 -0800362#define diva_os_dump_file(__x__) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
364/*
365** size of internal arrays
366*/
367#define MAX_DESCRIPTORS 64
368
369#endif /* __PLATFORM_H__ */