1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, v.1,  (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://opensource.org/licenses/CDDL-1.0.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 
22 /*
23 * Copyright 2014-2017 Cavium, Inc.
24 * The contents of this file are subject to the terms of the Common Development
25 * and Distribution License, v.1,  (the "License").
26 
27 * You may not use this file except in compliance with the License.
28 
29 * You can obtain a copy of the License at available
30 * at http://opensource.org/licenses/CDDL-1.0
31 
32 * See the License for the specific language governing permissions and
33 * limitations under the License.
34 */
35 
36 #ifndef __ECORE_UTILS_H__
37 #define __ECORE_UTILS_H__
38 
39 /* dma_addr_t manip */
40 /* Suppress "right shift count >= width of type" warning when that quantity is
41  * 32-bits rquires the >> 16) >> 16)
42  */
43 #define PTR_LO(x)		((u32)(((osal_uintptr_t)(x)) & 0xffffffff))
44 #define PTR_HI(x)		((u32)((((osal_uintptr_t)(x)) >> 16) >> 16))
45 
46 #define DMA_LO(x)		((u32)(((dma_addr_t)(x)) & 0xffffffff))
47 #define DMA_HI(x)		((u32)(((dma_addr_t)(x)) >> 32))
48 
49 #define DMA_LO_LE(x)		OSAL_CPU_TO_LE32(DMA_LO(x))
50 #define DMA_HI_LE(x)		OSAL_CPU_TO_LE32(DMA_HI(x))
51 
52 /* It's assumed that whoever includes this has previously included an hsi
53  * file defining the regpair.
54  */
55 #define DMA_REGPAIR_LE(x, val)	(x).hi = DMA_HI_LE((val)); \
56 				(x).lo = DMA_LO_LE((val))
57 
58 #define HILO_GEN(hi, lo, type)	((((type)(hi)) << 32) + (lo))
59 #define HILO_DMA(hi, lo)	HILO_GEN(hi, lo, dma_addr_t)
60 #define HILO_64(hi, lo)		HILO_GEN(hi, lo, u64)
61 #define HILO_DMA_REGPAIR(regpair)	(HILO_DMA(regpair.hi, regpair.lo))
62 #define HILO_64_REGPAIR(regpair)	(HILO_64(regpair.hi, regpair.lo))
63 
64 #endif
65