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