linux_osl.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. /*
  2. * Linux OS Independent Layer
  3. *
  4. * Portions of this code are copyright (c) 2020 Cypress Semiconductor Corporation
  5. *
  6. * Copyright (C) 1999-2020, Broadcom Corporation
  7. *
  8. * Unless you and Broadcom execute a separate written software license
  9. * agreement governing use of this software, this software is licensed to you
  10. * under the terms of the GNU General Public License version 2 (the "GPL"),
  11. * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  12. * following added to such license:
  13. *
  14. * As a special exception, the copyright holders of this software give you
  15. * permission to link this software with independent modules, and to copy and
  16. * distribute the resulting executable under terms of your choice, provided that
  17. * you also meet, for each linked independent module, the terms and conditions of
  18. * the license of that module. An independent module is a module which is not
  19. * derived from this software. The special exception does not apply to any
  20. * modifications of the software.
  21. *
  22. * Notwithstanding the above, under no circumstances may you combine this
  23. * software in any way with any other Broadcom software provided under a license
  24. * other than the GPL, without Broadcom's express prior written consent.
  25. *
  26. *
  27. * <<Broadcom-WL-IPTag/Open:>>
  28. *
  29. * $Id: linux_osl.h 692391 2017-03-28 00:29:04Z $
  30. */
  31. #ifndef _linux_osl_h_
  32. #define _linux_osl_h_
  33. #include <typedefs.h>
  34. #define DECLSPEC_ALIGN(x) __attribute__ ((aligned(x)))
  35. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 1))
  36. #include <linux/time64.h>
  37. void do_gettimeofday(struct timeval *tv);
  38. #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 1) */
  39. /* Linux Kernel: File Operations: start */
  40. extern void * osl_os_open_image(char * filename);
  41. extern int osl_os_get_image_block(char * buf, int len, void * image);
  42. extern void osl_os_close_image(void * image);
  43. extern int osl_os_image_size(void *image);
  44. /* Linux Kernel: File Operations: end */
  45. #ifdef BCMDRIVER
  46. /* OSL initialization */
  47. extern osl_t *osl_attach(void *pdev, uint bustype, bool pkttag);
  48. extern void osl_detach(osl_t *osh);
  49. extern int osl_static_mem_init(osl_t *osh, void *adapter);
  50. extern int osl_static_mem_deinit(osl_t *osh, void *adapter);
  51. extern void osl_set_bus_handle(osl_t *osh, void *bus_handle);
  52. extern void* osl_get_bus_handle(osl_t *osh);
  53. #ifdef DHD_MAP_LOGGING
  54. extern void osl_dma_map_dump(osl_t *osh);
  55. #define OSL_DMA_MAP_DUMP(osh) osl_dma_map_dump(osh)
  56. #else
  57. #define OSL_DMA_MAP_DUMP(osh) do {} while (0)
  58. #endif /* DHD_MAP_LOGGING */
  59. /* Global ASSERT type */
  60. extern uint32 g_assert_type;
  61. #ifdef CONFIG_PHYS_ADDR_T_64BIT
  62. #define PRI_FMT_x "llx"
  63. #define PRI_FMT_X "llX"
  64. #define PRI_FMT_o "llo"
  65. #define PRI_FMT_d "lld"
  66. #else
  67. #define PRI_FMT_x "x"
  68. #define PRI_FMT_X "X"
  69. #define PRI_FMT_o "o"
  70. #define PRI_FMT_d "d"
  71. #endif /* CONFIG_PHYS_ADDR_T_64BIT */
  72. /* ASSERT */
  73. #ifndef ASSERT
  74. #if defined(BCMASSERT_LOG)
  75. #define ASSERT(exp) \
  76. do { if (!(exp)) osl_assert(#exp, __FILE__, __LINE__); } while (0)
  77. extern void osl_assert(const char *exp, const char *file, int line);
  78. #else
  79. #ifdef __GNUC__
  80. #define GCC_VERSION \
  81. (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
  82. #if GCC_VERSION > 30100
  83. #define ASSERT(exp) do {} while (0)
  84. #else
  85. /* ASSERT could cause segmentation fault on GCC3.1, use empty instead */
  86. #define ASSERT(exp)
  87. #endif /* GCC_VERSION > 30100 */
  88. #endif /* __GNUC__ */
  89. #endif // endif
  90. #endif /* ASSERT */
  91. /* bcm_prefetch_32B */
  92. static inline void bcm_prefetch_32B(const uint8 *addr, const int cachelines_32B)
  93. {
  94. #if (defined(STB) && defined(__arm__)) && (__LINUX_ARM_ARCH__ >= 5)
  95. switch (cachelines_32B) {
  96. case 4: __asm__ __volatile__("pld\t%a0" :: "p"(addr + 96) : "cc");
  97. case 3: __asm__ __volatile__("pld\t%a0" :: "p"(addr + 64) : "cc");
  98. case 2: __asm__ __volatile__("pld\t%a0" :: "p"(addr + 32) : "cc");
  99. case 1: __asm__ __volatile__("pld\t%a0" :: "p"(addr + 0) : "cc");
  100. }
  101. #endif // endif
  102. }
  103. /* microsecond delay */
  104. #define OSL_DELAY(usec) osl_delay(usec)
  105. extern void osl_delay(uint usec);
  106. #define OSL_SLEEP(ms) osl_sleep(ms)
  107. extern void osl_sleep(uint ms);
  108. #define OSL_PCMCIA_READ_ATTR(osh, offset, buf, size) \
  109. osl_pcmcia_read_attr((osh), (offset), (buf), (size))
  110. #define OSL_PCMCIA_WRITE_ATTR(osh, offset, buf, size) \
  111. osl_pcmcia_write_attr((osh), (offset), (buf), (size))
  112. extern void osl_pcmcia_read_attr(osl_t *osh, uint offset, void *buf, int size);
  113. extern void osl_pcmcia_write_attr(osl_t *osh, uint offset, void *buf, int size);
  114. /* PCI configuration space access macros */
  115. #define OSL_PCI_READ_CONFIG(osh, offset, size) \
  116. osl_pci_read_config((osh), (offset), (size))
  117. #define OSL_PCI_WRITE_CONFIG(osh, offset, size, val) \
  118. osl_pci_write_config((osh), (offset), (size), (val))
  119. extern uint32 osl_pci_read_config(osl_t *osh, uint offset, uint size);
  120. extern void osl_pci_write_config(osl_t *osh, uint offset, uint size, uint val);
  121. /* PCI device bus # and slot # */
  122. #define OSL_PCI_BUS(osh) osl_pci_bus(osh)
  123. #define OSL_PCI_SLOT(osh) osl_pci_slot(osh)
  124. #define OSL_PCIE_DOMAIN(osh) osl_pcie_domain(osh)
  125. #define OSL_PCIE_BUS(osh) osl_pcie_bus(osh)
  126. extern uint osl_pci_bus(osl_t *osh);
  127. extern uint osl_pci_slot(osl_t *osh);
  128. extern uint osl_pcie_domain(osl_t *osh);
  129. extern uint osl_pcie_bus(osl_t *osh);
  130. extern struct pci_dev *osl_pci_device(osl_t *osh);
  131. #define OSL_ACP_COHERENCE (1<<1L)
  132. #define OSL_FWDERBUF (1<<2L)
  133. /* Pkttag flag should be part of public information */
  134. typedef struct {
  135. bool pkttag;
  136. bool mmbus; /**< Bus supports memory-mapped register accesses */
  137. pktfree_cb_fn_t tx_fn; /**< Callback function for PKTFREE */
  138. void *tx_ctx; /**< Context to the callback function */
  139. void *unused[3];
  140. void (*rx_fn)(void *rx_ctx, void *p);
  141. void *rx_ctx;
  142. } osl_pubinfo_t;
  143. extern void osl_flag_set(osl_t *osh, uint32 mask);
  144. extern void osl_flag_clr(osl_t *osh, uint32 mask);
  145. extern bool osl_is_flag_set(osl_t *osh, uint32 mask);
  146. #define PKTFREESETCB(osh, _tx_fn, _tx_ctx) \
  147. do { \
  148. ((osl_pubinfo_t*)osh)->tx_fn = _tx_fn; \
  149. ((osl_pubinfo_t*)osh)->tx_ctx = _tx_ctx; \
  150. } while (0)
  151. #define PKTFREESETRXCB(osh, _rx_fn, _rx_ctx) \
  152. do { \
  153. ((osl_pubinfo_t*)osh)->rx_fn = _rx_fn; \
  154. ((osl_pubinfo_t*)osh)->rx_ctx = _rx_ctx; \
  155. } while (0)
  156. /* host/bus architecture-specific byte swap */
  157. #define BUS_SWAP32(v) (v)
  158. #define MALLOC(osh, size) osl_malloc((osh), (size))
  159. #define MALLOCZ(osh, size) osl_mallocz((osh), (size))
  160. #define MFREE(osh, addr, size) osl_mfree((osh), (addr), (size))
  161. #define VMALLOC(osh, size) osl_vmalloc((osh), (size))
  162. #define VMALLOCZ(osh, size) osl_vmallocz((osh), (size))
  163. #define VMFREE(osh, addr, size) osl_vmfree((osh), (addr), (size))
  164. #define MALLOCED(osh) osl_malloced((osh))
  165. #define MEMORY_LEFTOVER(osh) osl_check_memleak(osh)
  166. extern void *osl_malloc(osl_t *osh, uint size);
  167. extern void *osl_mallocz(osl_t *osh, uint size);
  168. extern void osl_mfree(osl_t *osh, void *addr, uint size);
  169. extern void *osl_vmalloc(osl_t *osh, uint size);
  170. extern void *osl_vmallocz(osl_t *osh, uint size);
  171. extern void osl_vmfree(osl_t *osh, void *addr, uint size);
  172. extern uint osl_malloced(osl_t *osh);
  173. extern uint osl_check_memleak(osl_t *osh);
  174. #define MALLOC_FAILED(osh) osl_malloc_failed((osh))
  175. extern uint osl_malloc_failed(osl_t *osh);
  176. /* allocate/free shared (dma-able) consistent memory */
  177. #define DMA_CONSISTENT_ALIGN osl_dma_consistent_align()
  178. #define DMA_ALLOC_CONSISTENT(osh, size, align, tot, pap, dmah) \
  179. osl_dma_alloc_consistent((osh), (size), (align), (tot), (pap))
  180. #define DMA_FREE_CONSISTENT(osh, va, size, pa, dmah) \
  181. osl_dma_free_consistent((osh), (void*)(va), (size), (pa))
  182. #define DMA_ALLOC_CONSISTENT_FORCE32(osh, size, align, tot, pap, dmah) \
  183. osl_dma_alloc_consistent((osh), (size), (align), (tot), (pap))
  184. #define DMA_FREE_CONSISTENT_FORCE32(osh, va, size, pa, dmah) \
  185. osl_dma_free_consistent((osh), (void*)(va), (size), (pa))
  186. extern uint osl_dma_consistent_align(void);
  187. extern void *osl_dma_alloc_consistent(osl_t *osh, uint size, uint16 align,
  188. uint *tot, dmaaddr_t *pap);
  189. extern void osl_dma_free_consistent(osl_t *osh, void *va, uint size, dmaaddr_t pa);
  190. /* map/unmap direction */
  191. #define DMA_NO 0 /* Used to skip cache op */
  192. #define DMA_TX 1 /* TX direction for DMA */
  193. #define DMA_RX 2 /* RX direction for DMA */
  194. /* map/unmap shared (dma-able) memory */
  195. #define DMA_UNMAP(osh, pa, size, direction, p, dmah) \
  196. osl_dma_unmap((osh), (pa), (size), (direction))
  197. extern void osl_dma_flush(osl_t *osh, void *va, uint size, int direction, void *p,
  198. hnddma_seg_map_t *txp_dmah);
  199. extern dmaaddr_t osl_dma_map(osl_t *osh, void *va, uint size, int direction, void *p,
  200. hnddma_seg_map_t *txp_dmah);
  201. extern void osl_dma_unmap(osl_t *osh, dmaaddr_t pa, uint size, int direction);
  202. #ifndef PHYS_TO_VIRT
  203. #define PHYS_TO_VIRT(pa) osl_phys_to_virt(pa)
  204. #endif // endif
  205. #ifndef VIRT_TO_PHYS
  206. #define VIRT_TO_PHYS(va) osl_virt_to_phys(va)
  207. #endif // endif
  208. extern void * osl_phys_to_virt(void * pa);
  209. extern void * osl_virt_to_phys(void * va);
  210. /* API for DMA addressing capability */
  211. #define OSL_DMADDRWIDTH(osh, addrwidth) ({BCM_REFERENCE(osh); BCM_REFERENCE(addrwidth);})
  212. #define OSL_SMP_WMB() smp_wmb()
  213. /* API for CPU relax */
  214. extern void osl_cpu_relax(void);
  215. #define OSL_CPU_RELAX() osl_cpu_relax()
  216. extern void osl_preempt_disable(osl_t *osh);
  217. extern void osl_preempt_enable(osl_t *osh);
  218. #define OSL_DISABLE_PREEMPTION(osh) osl_preempt_disable(osh)
  219. #define OSL_ENABLE_PREEMPTION(osh) osl_preempt_enable(osh)
  220. #if (!defined(DHD_USE_COHERENT_MEM_FOR_RING) && defined(__ARM_ARCH_7A__)) || \
  221. defined(STB_SOC_WIFI)
  222. extern void osl_cache_flush(void *va, uint size);
  223. extern void osl_cache_inv(void *va, uint size);
  224. extern void osl_prefetch(const void *ptr);
  225. #define OSL_CACHE_FLUSH(va, len) osl_cache_flush((void *)(va), len)
  226. #define OSL_CACHE_INV(va, len) osl_cache_inv((void *)(va), len)
  227. #define OSL_PREFETCH(ptr) osl_prefetch(ptr)
  228. #if defined(__ARM_ARCH_7A__) || defined(STB_SOC_WIFI)
  229. extern int osl_arch_is_coherent(void);
  230. #define OSL_ARCH_IS_COHERENT() osl_arch_is_coherent()
  231. extern int osl_acp_war_enab(void);
  232. #define OSL_ACP_WAR_ENAB() osl_acp_war_enab()
  233. #else /* !__ARM_ARCH_7A__ */
  234. #define OSL_ARCH_IS_COHERENT() NULL
  235. #define OSL_ACP_WAR_ENAB() NULL
  236. #endif /* !__ARM_ARCH_7A__ */
  237. #else /* !__mips__ && !__ARM_ARCH_7A__ */
  238. #define OSL_CACHE_FLUSH(va, len) BCM_REFERENCE(va)
  239. #define OSL_CACHE_INV(va, len) BCM_REFERENCE(va)
  240. #define OSL_PREFETCH(ptr) BCM_REFERENCE(ptr)
  241. #define OSL_ARCH_IS_COHERENT() NULL
  242. #define OSL_ACP_WAR_ENAB() NULL
  243. #endif // endif
  244. #ifdef BCM_BACKPLANE_TIMEOUT
  245. extern void osl_set_bpt_cb(osl_t *osh, void *bpt_cb, void *bpt_ctx);
  246. extern void osl_bpt_rreg(osl_t *osh, ulong addr, volatile void *v, uint size);
  247. #endif /* BCM_BACKPLANE_TIMEOUT */
  248. #if (defined(STB) && defined(__arm__))
  249. extern void osl_pcie_rreg(osl_t *osh, ulong addr, volatile void *v, uint size);
  250. #endif // endif
  251. /* register access macros */
  252. #if defined(BCMSDIO)
  253. #include <bcmsdh.h>
  254. #define OSL_WRITE_REG(osh, r, v) (bcmsdh_reg_write(osl_get_bus_handle(osh), \
  255. (uintptr)(r), sizeof(*(r)), (v)))
  256. #define OSL_READ_REG(osh, r) (bcmsdh_reg_read(osl_get_bus_handle(osh), \
  257. (uintptr)(r), sizeof(*(r))))
  258. #elif defined(BCM_BACKPLANE_TIMEOUT)
  259. #define OSL_READ_REG(osh, r) \
  260. ({\
  261. __typeof(*(r)) __osl_v; \
  262. osl_bpt_rreg(osh, (uintptr)(r), &__osl_v, sizeof(*(r))); \
  263. __osl_v; \
  264. })
  265. #elif (defined(STB) && defined(__arm__))
  266. #define OSL_READ_REG(osh, r) \
  267. ({\
  268. __typeof(*(r)) __osl_v; \
  269. osl_pcie_rreg(osh, (uintptr)(r), &__osl_v, sizeof(*(r))); \
  270. __osl_v; \
  271. })
  272. #endif // endif
  273. #if defined(BCM_BACKPLANE_TIMEOUT) || (defined(STB) && defined(__arm__))
  274. #define SELECT_BUS_WRITE(osh, mmap_op, bus_op) ({BCM_REFERENCE(osh); mmap_op;})
  275. #define SELECT_BUS_READ(osh, mmap_op, bus_op) ({BCM_REFERENCE(osh); bus_op;})
  276. #else /* !BCM47XX_CA9 && !BCM_BACKPLANE_TIMEOUT && !(STB && __arm__) */
  277. #if defined(BCMSDIO)
  278. #define SELECT_BUS_WRITE(osh, mmap_op, bus_op) if (((osl_pubinfo_t*)(osh))->mmbus) \
  279. mmap_op else bus_op
  280. #define SELECT_BUS_READ(osh, mmap_op, bus_op) (((osl_pubinfo_t*)(osh))->mmbus) ? \
  281. mmap_op : bus_op
  282. #else
  283. #define SELECT_BUS_WRITE(osh, mmap_op, bus_op) ({BCM_REFERENCE(osh); mmap_op;})
  284. #define SELECT_BUS_READ(osh, mmap_op, bus_op) ({BCM_REFERENCE(osh); mmap_op;})
  285. #endif // endif
  286. #endif // endif
  287. #define OSL_ERROR(bcmerror) osl_error(bcmerror)
  288. extern int osl_error(int bcmerror);
  289. /* the largest reasonable packet buffer driver uses for ethernet MTU in bytes */
  290. #define PKTBUFSZ 2048 /* largest reasonable packet buffer, driver uses for ethernet MTU */
  291. #define OSH_NULL NULL
  292. /*
  293. * BINOSL selects the slightly slower function-call-based binary compatible osl.
  294. * Macros expand to calls to functions defined in linux_osl.c .
  295. */
  296. #include <linuxver.h> /* use current 2.4.x calling conventions */
  297. #include <linux/kernel.h> /* for vsn/printf's */
  298. #include <linux/string.h> /* for mem*, str* */
  299. extern uint64 osl_sysuptime_us(void);
  300. #define OSL_SYSUPTIME() ((uint32)jiffies_to_msecs(jiffies))
  301. #define OSL_SYSUPTIME_US() osl_sysuptime_us()
  302. extern uint64 osl_localtime_ns(void);
  303. extern void osl_get_localtime(uint64 *sec, uint64 *usec);
  304. extern uint64 osl_systztime_us(void);
  305. #define OSL_LOCALTIME_NS() osl_localtime_ns()
  306. #define OSL_GET_LOCALTIME(sec, usec) osl_get_localtime((sec), (usec))
  307. #define OSL_SYSTZTIME_US() osl_systztime_us()
  308. #define printf(fmt, args...) printk(fmt , ## args)
  309. #include <linux/kernel.h> /* for vsn/printf's */
  310. #include <linux/string.h> /* for mem*, str* */
  311. /* bcopy's: Linux kernel doesn't provide these (anymore) */
  312. #define bcopy_hw(src, dst, len) memcpy((dst), (src), (len))
  313. #define bcopy_hw_async(src, dst, len) memcpy((dst), (src), (len))
  314. #define bcopy_hw_poll_for_completion()
  315. #define bcopy(src, dst, len) memcpy((dst), (src), (len))
  316. #define bcmp(b1, b2, len) memcmp((b1), (b2), (len))
  317. #define bzero(b, len) memset((b), '\0', (len))
  318. /* register access macros */
  319. #ifdef CONFIG_64BIT
  320. /* readq is defined only for 64 bit platform */
  321. #define R_REG(osh, r) (\
  322. SELECT_BUS_READ(osh, \
  323. ({ \
  324. __typeof(*(r)) __osl_v = 0; \
  325. BCM_REFERENCE(osh); \
  326. switch (sizeof(*(r))) { \
  327. case sizeof(uint8): __osl_v = \
  328. readb((volatile uint8*)(r)); break; \
  329. case sizeof(uint16): __osl_v = \
  330. readw((volatile uint16*)(r)); break; \
  331. case sizeof(uint32): __osl_v = \
  332. readl((volatile uint32*)(r)); break; \
  333. case sizeof(uint64): __osl_v = \
  334. readq((volatile uint64*)(r)); break; \
  335. } \
  336. __osl_v; \
  337. }), \
  338. OSL_READ_REG(osh, r)) \
  339. )
  340. #else /* !CONFIG_64BIT */
  341. #define R_REG(osh, r) (\
  342. SELECT_BUS_READ(osh, \
  343. ({ \
  344. __typeof(*(r)) __osl_v = 0; \
  345. switch (sizeof(*(r))) { \
  346. case sizeof(uint8): __osl_v = \
  347. readb((volatile uint8*)(r)); break; \
  348. case sizeof(uint16): __osl_v = \
  349. readw((volatile uint16*)(r)); break; \
  350. case sizeof(uint32): __osl_v = \
  351. readl((volatile uint32*)(r)); break; \
  352. } \
  353. __osl_v; \
  354. }), \
  355. OSL_READ_REG(osh, r)) \
  356. )
  357. #endif /* CONFIG_64BIT */
  358. #ifdef CONFIG_64BIT
  359. /* writeq is defined only for 64 bit platform */
  360. #define W_REG(osh, r, v) do { \
  361. SELECT_BUS_WRITE(osh, \
  362. switch (sizeof(*(r))) { \
  363. case sizeof(uint8): writeb((uint8)(v), (volatile uint8*)(r)); break; \
  364. case sizeof(uint16): writew((uint16)(v), (volatile uint16*)(r)); break; \
  365. case sizeof(uint32): writel((uint32)(v), (volatile uint32*)(r)); break; \
  366. case sizeof(uint64): writeq((uint64)(v), (volatile uint64*)(r)); break; \
  367. }, \
  368. (OSL_WRITE_REG(osh, r, v))); \
  369. } while (0)
  370. #else /* !CONFIG_64BIT */
  371. #define W_REG(osh, r, v) do { \
  372. SELECT_BUS_WRITE(osh, \
  373. switch (sizeof(*(r))) { \
  374. case sizeof(uint8): writeb((uint8)(v), (volatile uint8*)(r)); break; \
  375. case sizeof(uint16): writew((uint16)(v), (volatile uint16*)(r)); break; \
  376. case sizeof(uint32): writel((uint32)(v), (volatile uint32*)(r)); break; \
  377. }, \
  378. (OSL_WRITE_REG(osh, r, v))); \
  379. } while (0)
  380. #endif /* CONFIG_64BIT */
  381. #define AND_REG(osh, r, v) W_REG(osh, (r), R_REG(osh, r) & (v))
  382. #define OR_REG(osh, r, v) W_REG(osh, (r), R_REG(osh, r) | (v))
  383. /* bcopy, bcmp, and bzero functions */
  384. #define bcopy(src, dst, len) memcpy((dst), (src), (len))
  385. #define bcmp(b1, b2, len) memcmp((b1), (b2), (len))
  386. #define bzero(b, len) memset((b), '\0', (len))
  387. /* uncached/cached virtual address */
  388. #define OSL_UNCACHED(va) ((void *)va)
  389. #define OSL_CACHED(va) ((void *)va)
  390. #define OSL_PREF_RANGE_LD(va, sz) BCM_REFERENCE(va)
  391. #define OSL_PREF_RANGE_ST(va, sz) BCM_REFERENCE(va)
  392. /* get processor cycle count */
  393. #if defined(__i386__)
  394. #define OSL_GETCYCLES(x) rdtscl((x))
  395. #else
  396. #define OSL_GETCYCLES(x) ((x) = 0)
  397. #endif // endif
  398. /* dereference an address that may cause a bus exception */
  399. #define BUSPROBE(val, addr) ({ (val) = R_REG(NULL, (addr)); 0; })
  400. /* map/unmap physical to virtual I/O */
  401. #if !defined(CONFIG_MMC_MSM7X00A)
  402. #define REG_MAP(pa, size) ioremap_nocache((unsigned long)(pa), (unsigned long)(size))
  403. #else
  404. #define REG_MAP(pa, size) (void *)(0)
  405. #endif /* !defined(CONFIG_MMC_MSM7X00A */
  406. #define REG_UNMAP(va) iounmap((va))
  407. /* shared (dma-able) memory access macros */
  408. #define R_SM(r) *(r)
  409. #define W_SM(r, v) (*(r) = (v))
  410. #define BZERO_SM(r, len) memset((r), '\0', (len))
  411. /* Because the non BINOSL implemenation of the PKT OSL routines are macros (for
  412. * performance reasons), we need the Linux headers.
  413. */
  414. #include <linuxver.h> /* use current 2.4.x calling conventions */
  415. #define OSL_RAND() osl_rand()
  416. extern uint32 osl_rand(void);
  417. #define DMA_FLUSH(osh, va, size, direction, p, dmah) \
  418. osl_dma_flush((osh), (va), (size), (direction), (p), (dmah))
  419. #if !defined(BCM_SECURE_DMA)
  420. #define DMA_MAP(osh, va, size, direction, p, dmah) \
  421. osl_dma_map((osh), (va), (size), (direction), (p), (dmah))
  422. #endif /* !(defined(BCM_SECURE_DMA)) */
  423. #else /* ! BCMDRIVER */
  424. /* ASSERT */
  425. #define ASSERT(exp) do {} while (0)
  426. /* MALLOC and MFREE */
  427. #define MALLOC(o, l) malloc(l)
  428. #define MFREE(o, p, l) free(p)
  429. #include <stdlib.h>
  430. /* str* and mem* functions */
  431. #include <string.h>
  432. /* *printf functions */
  433. #include <stdio.h>
  434. /* bcopy, bcmp, and bzero */
  435. extern void bcopy(const void *src, void *dst, size_t len);
  436. extern int bcmp(const void *b1, const void *b2, size_t len);
  437. extern void bzero(void *b, size_t len);
  438. #endif /* ! BCMDRIVER */
  439. /* Current STB 7445D1 doesn't use ACP and it is non-coherrent.
  440. * Adding these dummy values for build apss only
  441. * When we revisit need to change these.
  442. */
  443. #ifdef BCM_SECURE_DMA
  444. #define SECURE_DMA_MAP(osh, va, size, direction, p, dmah, pcma, offset) \
  445. osl_sec_dma_map((osh), (va), (size), (direction), (p), (dmah), (pcma), (offset))
  446. #define SECURE_DMA_DD_MAP(osh, va, size, direction, p, dmah) \
  447. osl_sec_dma_dd_map((osh), (va), (size), (direction), (p), (dmah))
  448. #define SECURE_DMA_MAP_TXMETA(osh, va, size, direction, p, dmah, pcma) \
  449. osl_sec_dma_map_txmeta((osh), (va), (size), (direction), (p), (dmah), (pcma))
  450. #define SECURE_DMA_UNMAP(osh, pa, size, direction, p, dmah, pcma, offset) \
  451. osl_sec_dma_unmap((osh), (pa), (size), (direction), (p), (dmah), (pcma), (offset))
  452. #define SECURE_DMA_UNMAP_ALL(osh, pcma) \
  453. osl_sec_dma_unmap_all((osh), (pcma))
  454. #define DMA_MAP(osh, va, size, direction, p, dmah)
  455. typedef struct sec_cma_info {
  456. struct sec_mem_elem *sec_alloc_list;
  457. struct sec_mem_elem *sec_alloc_list_tail;
  458. } sec_cma_info_t;
  459. #if defined(__ARM_ARCH_7A__)
  460. #define CMA_BUFSIZE_4K 4096
  461. #define CMA_BUFSIZE_2K 2048
  462. #define CMA_BUFSIZE_512 512
  463. #define CMA_BUFNUM 2048
  464. #define SEC_CMA_COHERENT_BLK 0x8000 /* 32768 */
  465. #define SEC_CMA_COHERENT_MAX 278
  466. #define CMA_DMA_DESC_MEMBLOCK (SEC_CMA_COHERENT_BLK * SEC_CMA_COHERENT_MAX)
  467. #define CMA_DMA_DATA_MEMBLOCK (CMA_BUFSIZE_4K*CMA_BUFNUM)
  468. #define CMA_MEMBLOCK (CMA_DMA_DESC_MEMBLOCK + CMA_DMA_DATA_MEMBLOCK)
  469. #define CONT_REGION 0x02 /* Region CMA */
  470. #else
  471. #define CONT_REGION 0x00 /* To access the MIPs mem, Not yet... */
  472. #endif /* !defined __ARM_ARCH_7A__ */
  473. #define SEC_DMA_ALIGN (1<<16)
  474. typedef struct sec_mem_elem {
  475. size_t size;
  476. int direction;
  477. phys_addr_t pa_cma; /**< physical address */
  478. void *va; /**< virtual address of driver pkt */
  479. dma_addr_t dma_handle; /**< bus address assign by linux */
  480. void *vac; /**< virtual address of cma buffer */
  481. struct page *pa_cma_page; /* phys to page address */
  482. struct sec_mem_elem *next;
  483. } sec_mem_elem_t;
  484. extern dma_addr_t osl_sec_dma_map(osl_t *osh, void *va, uint size, int direction, void *p,
  485. hnddma_seg_map_t *dmah, void *ptr_cma_info, uint offset);
  486. extern dma_addr_t osl_sec_dma_dd_map(osl_t *osh, void *va, uint size, int direction, void *p,
  487. hnddma_seg_map_t *dmah);
  488. extern dma_addr_t osl_sec_dma_map_txmeta(osl_t *osh, void *va, uint size,
  489. int direction, void *p, hnddma_seg_map_t *dmah, void *ptr_cma_info);
  490. extern void osl_sec_dma_unmap(osl_t *osh, dma_addr_t dma_handle, uint size, int direction,
  491. void *p, hnddma_seg_map_t *map, void *ptr_cma_info, uint offset);
  492. extern void osl_sec_dma_unmap_all(osl_t *osh, void *ptr_cma_info);
  493. #endif /* BCM_SECURE_DMA */
  494. typedef struct sk_buff_head PKT_LIST;
  495. #define PKTLIST_INIT(x) skb_queue_head_init((x))
  496. #define PKTLIST_ENQ(x, y) skb_queue_head((struct sk_buff_head *)(x), (struct sk_buff *)(y))
  497. #define PKTLIST_DEQ(x) skb_dequeue((struct sk_buff_head *)(x))
  498. #define PKTLIST_UNLINK(x, y) skb_unlink((struct sk_buff *)(y), (struct sk_buff_head *)(x))
  499. #define PKTLIST_FINI(x) skb_queue_purge((struct sk_buff_head *)(x))
  500. #ifndef _linuxver_h_
  501. typedef struct timer_list_compat timer_list_compat_t;
  502. #endif /* _linuxver_h_ */
  503. typedef struct osl_timer {
  504. timer_list_compat_t *timer;
  505. bool set;
  506. } osl_timer_t;
  507. typedef void (*linux_timer_fn)(ulong arg);
  508. extern osl_timer_t * osl_timer_init(osl_t *osh, const char *name, void (*fn)(void *arg), void *arg);
  509. extern void osl_timer_add(osl_t *osh, osl_timer_t *t, uint32 ms, bool periodic);
  510. extern void osl_timer_update(osl_t *osh, osl_timer_t *t, uint32 ms, bool periodic);
  511. extern bool osl_timer_del(osl_t *osh, osl_timer_t *t);
  512. typedef atomic_t osl_atomic_t;
  513. #define OSL_ATOMIC_SET(osh, v, x) atomic_set(v, x)
  514. #define OSL_ATOMIC_INIT(osh, v) atomic_set(v, 0)
  515. #define OSL_ATOMIC_INC(osh, v) atomic_inc(v)
  516. #define OSL_ATOMIC_INC_RETURN(osh, v) atomic_inc_return(v)
  517. #define OSL_ATOMIC_DEC(osh, v) atomic_dec(v)
  518. #define OSL_ATOMIC_DEC_RETURN(osh, v) atomic_dec_return(v)
  519. #define OSL_ATOMIC_READ(osh, v) atomic_read(v)
  520. #define OSL_ATOMIC_ADD(osh, v, x) atomic_add(v, x)
  521. #ifndef atomic_set_mask
  522. #define OSL_ATOMIC_OR(osh, v, x) atomic_or(x, v)
  523. #define OSL_ATOMIC_AND(osh, v, x) atomic_and(x, v)
  524. #else
  525. #define OSL_ATOMIC_OR(osh, v, x) atomic_set_mask(x, v)
  526. #define OSL_ATOMIC_AND(osh, v, x) atomic_clear_mask(~x, v)
  527. #endif // endif
  528. #include <linux/rbtree.h>
  529. typedef struct rb_node osl_rb_node_t;
  530. typedef struct rb_root osl_rb_root_t;
  531. #define OSL_RB_ENTRY(ptr, type, member) rb_entry(ptr, type, member)
  532. #define OSL_RB_INSERT_COLOR(root, node) rb_insert_color(root, node)
  533. #define OSL_RB_ERASE(node, root) rb_erase(node, root)
  534. #define OSL_RB_FIRST(root) rb_first(root)
  535. #define OSL_RB_LAST(root) rb_last(root)
  536. #define OSL_RB_LINK_NODE(node, parent, rb_link) \
  537. rb_link_node(node, parent, rb_link)
  538. extern void *osl_spin_lock_init(osl_t *osh);
  539. extern void osl_spin_lock_deinit(osl_t *osh, void *lock);
  540. extern unsigned long osl_spin_lock(void *lock);
  541. extern void osl_spin_unlock(void *lock, unsigned long flags);
  542. #endif /* _linux_osl_h_ */