platform.h 8.9 KB

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