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