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_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 70#ifndef NULL 71#define NULL ((void *) 0) 72#endif 73 74#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 112#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) 121 122#define DIVA_INVALID_FILE_HANDLE ((dword)(-1)) 123 124#define DIVAS_CONTAINING_RECORD(address, type, field) \ 125 ((type *)((char *)(address) - (char *)(&((type *)0)->field))) 126 127extern int sprintf(char *, const char *, ...); 128 129typedef void *LIST_ENTRY; 130 131typedef char DEVICE_NAME[64]; 132typedef struct _ISDN_ADAPTER ISDN_ADAPTER; 133typedef struct _ISDN_ADAPTER *PISDN_ADAPTER; 134 135typedef void (*DIVA_DI_PRINTF)(unsigned char *, ...); 136#include "debuglib.h" 137 138#define dtrc(p) DBG_PRV0(p) 139#define dbug(a, p) DBG_PRV1(p) 140 141 142typedef struct e_info_s E_INFO; 143 144typedef char diva_os_dependent_devica_name_t[64]; 145typedef void *PDEVICE_OBJECT; 146 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*/ 156void diva_xdi_didd_register_adapter(int card); 157void diva_xdi_didd_remove_adapter(int card); 158 159/* 160** memory allocation 161*/ 162static __inline__ void *diva_os_malloc(unsigned long flags, unsigned long size) 163{ 164 void *ret = NULL; 165 166 if (size) { 167 ret = (void *) vmalloc((unsigned int) size); 168 } 169 return (ret); 170} 171static __inline__ void diva_os_free(unsigned long flags, void *ptr) 172{ 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*/ 200void 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); 202 203/* 204** I/O Port utilities 205*/ 206int diva_os_register_io_port(void *adapter, int register, unsigned long port, 207 unsigned long length, const char *name, int id); 208/* 209** I/O port access abstraction 210*/ 211byte 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); 217 218/* 219** IRQ 220*/ 221typedef struct _diva_os_adapter_irq_info { 222 byte irq_nr; 223 int registered; 224 char irq_name[24]; 225} diva_os_adapter_irq_info_t; 226int diva_os_register_irq(void *context, byte irq, const char *name); 227void diva_os_remove_irq(void *context, byte irq); 228 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; 236static __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); } 244 245#define diva_os_destroy_spin_lock(a, b) do { } while (0) 246 247/* 248** Deffered processing framework 249*/ 250typedef 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); 252 253typedef struct _diva_os_soft_isr { 254 void *object; 255 diva_os_soft_isr_callback_t callback; 256 void *callback_context; 257 char dpc_thread_name[24]; 258} diva_os_soft_isr_t; 259 260int 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); 264 265/* 266 Get time service 267*/ 268void diva_os_get_time(dword *sec, dword *usec); 269 270/* 271** atomic operation, fake because we use threads 272*/ 273typedef int diva_os_atomic_t; 274static diva_os_atomic_t __inline__ 275diva_os_atomic_increment(diva_os_atomic_t *pv) 276{ 277 *pv += 1; 278 return (*pv); 279} 280static diva_os_atomic_t __inline__ 281diva_os_atomic_decrement(diva_os_atomic_t *pv) 282{ 283 *pv -= 1; 284 return (*pv); 285} 286 287/* 288** 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 319#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) 322 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 344#if BITS_PER_LONG > 32 345#define PLATFORM_GT_32BIT 346#define ULongToPtr(x) (void *)(unsigned long)(x) 347#endif 348#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 362#define diva_os_dump_file(__x__) do { } while (0) 363 364/* 365** size of internal arrays 366*/ 367#define MAX_DESCRIPTORS 64 368 369#endif /* __PLATFORM_H__ */ 370