3 * @author Intel Corporation
6 * @brief description goes here
11 * IXP400 SW Release version 2.0
13 * -- Copyright Notice --
16 * Copyright 2001-2005, Intel Corporation.
17 * All rights reserved.
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
23 * 1. Redistributions of source code must retain the above copyright
24 * notice, this list of conditions and the following disclaimer.
25 * 2. Redistributions in binary form must reproduce the above copyright
26 * notice, this list of conditions and the following disclaimer in the
27 * documentation and/or other materials provided with the distribution.
28 * 3. Neither the name of the Intel Corporation nor the names of its contributors
29 * may be used to endorse or promote products derived from this software
30 * without specific prior written permission.
33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
34 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
37 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
38 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
39 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
41 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
42 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 * -- End of Copyright Notice --
54 * Decide OS and Endianess, such as IX_OSAL_VXWORKS_LE.
56 #include "IxOsalEndianess.h"
59 * @defgroup IxOsalIoMem Osal IoMem module
61 * @brief I/O memory and endianess support.
66 /* Low-level conversion macros - DO NOT USE UNLESS ABSOLUTELY NEEDED */
71 * Private function to swap word
74 static __inline__ UINT32
75 ixOsalCoreWordSwap (UINT32 wordIn)
78 * Storage for the swapped word
85 __asm__ (" eor r1, %1, %1, ror #16;" /* R1 = A^C, B^D, C^A, D^B */
86 " bic r1, r1, #0x00ff0000;" /* R1 = A^C, 0 , C^A, D^B */
87 " mov %0, %1, ror #8;" /* wordOut = D, A, B, C */
88 " eor %0, %0, r1, lsr #8;" /* wordOut = D, C, B, A */
89 : "=r" (wordOut): "r" (wordIn):"r1");
94 #define IX_OSAL_SWAP_LONG(wData) (ixOsalCoreWordSwap(wData))
96 #define IX_OSAL_SWAP_LONG(wData) ((wData >> 24) | (((wData >> 16) & 0xFF) << 8) | (((wData >> 8) & 0xFF) << 16) | ((wData & 0xFF) << 24))
99 #else /* ndef __wince */
100 #define IX_OSAL_SWAP_LONG(wData) ((((UINT32)wData << 24) | ((UINT32)wData >> 24)) | (((wData << 8) & 0xff0000) | ((wData >> 8) & 0xff00)))
101 #endif /* ndef __wince */
103 #define IX_OSAL_SWAP_SHORT(sData) ((sData >> 8) | ((sData & 0xFF) << 8))
104 #define IX_OSAL_SWAP_SHORT_ADDRESS(sAddr) ((sAddr) ^ 0x2)
105 #define IX_OSAL_SWAP_BYTE_ADDRESS(bAddr) ((bAddr) ^ 0x3)
107 #define IX_OSAL_BE_XSTOBUSL(wData) (wData)
108 #define IX_OSAL_BE_XSTOBUSS(sData) (sData)
109 #define IX_OSAL_BE_XSTOBUSB(bData) (bData)
110 #define IX_OSAL_BE_BUSTOXSL(wData) (wData)
111 #define IX_OSAL_BE_BUSTOXSS(sData) (sData)
112 #define IX_OSAL_BE_BUSTOXSB(bData) (bData)
114 #define IX_OSAL_LE_AC_XSTOBUSL(wAddr) (wAddr)
115 #define IX_OSAL_LE_AC_XSTOBUSS(sAddr) IX_OSAL_SWAP_SHORT_ADDRESS(sAddr)
116 #define IX_OSAL_LE_AC_XSTOBUSB(bAddr) IX_OSAL_SWAP_BYTE_ADDRESS(bAddr)
117 #define IX_OSAL_LE_AC_BUSTOXSL(wAddr) (wAddr)
118 #define IX_OSAL_LE_AC_BUSTOXSS(sAddr) IX_OSAL_SWAP_SHORT_ADDRESS(sAddr)
119 #define IX_OSAL_LE_AC_BUSTOXSB(bAddr) IX_OSAL_SWAP_BYTE_ADDRESS(bAddr)
121 #define IX_OSAL_LE_DC_XSTOBUSL(wData) IX_OSAL_SWAP_LONG(wData)
122 #define IX_OSAL_LE_DC_XSTOBUSS(sData) IX_OSAL_SWAP_SHORT(sData)
123 #define IX_OSAL_LE_DC_XSTOBUSB(bData) (bData)
124 #define IX_OSAL_LE_DC_BUSTOXSL(wData) IX_OSAL_SWAP_LONG(wData)
125 #define IX_OSAL_LE_DC_BUSTOXSS(sData) IX_OSAL_SWAP_SHORT(sData)
126 #define IX_OSAL_LE_DC_BUSTOXSB(bData) (bData)
130 * Decide SDRAM mapping, then implement read/write
132 #include "IxOsalMemAccess.h"
136 * @ingroup IxOsalIoMem
137 * @enum IxOsalMapEntryType
138 * @brief This is an emum for OSAL I/O mem map type.
142 IX_OSAL_STATIC_MAP = 0, /**<Set map entry type to static map */
143 IX_OSAL_DYNAMIC_MAP /**<Set map entry type to dynamic map */
144 } IxOsalMapEntryType;
148 * @ingroup IxOsalIoMem
149 * @enum IxOsalMapEndianessType
150 * @brief This is an emum for OSAL I/O mem Endianess and Coherency mode.
154 IX_OSAL_BE = 0x1, /**<Set map endian mode to Big Endian */
155 IX_OSAL_LE_AC = 0x2, /**<Set map endian mode to Little Endian, Address Coherent */
156 IX_OSAL_LE_DC = 0x4, /**<Set map endian mode to Little Endian, Data Coherent */
157 IX_OSAL_LE = 0x8 /**<Set map endian mode to Little Endian without specifying coherency mode */
158 } IxOsalMapEndianessType;
162 * @struct IxOsalMemoryMap
163 * @brief IxOsalMemoryMap structure
165 typedef struct _IxOsalMemoryMap
167 IxOsalMapEntryType type; /**< map type - IX_OSAL_STATIC_MAP or IX_OSAL_DYNAMIC_MAP */
169 UINT32 physicalAddress; /**< physical address of the memory mapped I/O zone */
171 UINT32 size; /**< size of the map */
173 UINT32 virtualAddress; /**< virtual address of the zone; must be predefined
174 in the global memory map for static maps and has
175 to be NULL for dynamic maps (populated on allocation)
178 * pointer to a map function called to map a dynamic map;
179 * will populate the virtualAddress field
181 void (*mapFunction) (struct _IxOsalMemoryMap * map); /**< pointer to a map function called to map a dynamic map */
184 * pointer to a map function called to unmap a dynamic map;
185 * will reset the virtualAddress field to NULL
187 void (*unmapFunction) (struct _IxOsalMemoryMap * map); /**< pointer to a map function called to unmap a dynamic map */
190 * reference count describing how many components share this map;
191 * actual allocation/deallocation for dynamic maps is done only
192 * between 0 <=> 1 transitions of the counter
194 UINT32 refCount; /**< reference count describing how many components share this map */
197 * memory endian type for the map; can be a combination of IX_OSAL_BE (Big
198 * Endian) and IX_OSAL_LE or IX_OSAL_LE_AC or IX_OSAL_LE_DC
199 * (Little Endian, Address Coherent or Data Coherent). Any combination is
200 * allowed provided it contains at most one LE flag - e.g.
201 * (IX_OSAL_BE), (IX_OSAL_LE_AC), (IX_OSAL_BE | IX_OSAL_LE_DC) are valid
202 * combinations while (IX_OSAL_BE | IX_OSAL_LE_DC | IX_OSAL_LE_AC) is not.
204 IxOsalMapEndianessType mapEndianType; /**< memory endian type for the map */
206 char *name; /**< user-friendly name */
212 /* Internal function to map a memory zone
213 * NOTE - This should not be called by the user.
214 * Use the macro IX_OSAL_MEM_MAP instead
216 PUBLIC void *ixOsalIoMemMap (UINT32 requestedAddress,
218 IxOsalMapEndianessType requestedCoherency);
221 /* Internal function to unmap a memory zone mapped with ixOsalIoMemMap
222 * NOTE - This should not be called by the user.
223 * Use the macro IX_OSAL_MEM_UNMAP instead
225 PUBLIC void ixOsalIoMemUnmap (UINT32 requestedAddress, UINT32 coherency);
228 /* Internal function to convert virtual address to physical address
229 * NOTE - This should not be called by the user.
230 * Use the macro IX_OSAL_MMAP_VIRT_TO_PHYS */
231 PUBLIC UINT32 ixOsalIoMemVirtToPhys (UINT32 virtualAddress, UINT32 coherency);
234 /* Internal function to convert physical address to virtual address
235 * NOTE - This should not be called by the user.
236 * Use the macro IX_OSAL_MMAP_PHYS_TO_VIRT */
238 ixOsalIoMemPhysToVirt (UINT32 physicalAddress, UINT32 coherency);
241 * @ingroup IxOsalIoMem
243 * @def IX_OSAL_MEM_MAP(physAddr, size)
245 * @brief Map an I/O mapped physical memory zone to virtual zone and return virtual
247 * @param physAddr - the physical address
248 * @param size - the size
249 * @return start address of the virtual memory zone.
251 * @note This function maps an I/O mapped physical memory zone of the given size
252 * into a virtual memory zone accessible by the caller and returns a cookie -
253 * the start address of the virtual memory zone.
254 * IX_OSAL_MMAP_PHYS_TO_VIRT should NOT therefore be used on the returned
256 * The memory zone is to be unmapped using IX_OSAL_MEM_UNMAP once the caller has
257 * finished using this zone (e.g. on driver unload) using the cookie as
259 * The IX_OSAL_READ/WRITE_LONG/SHORT macros should be used to read and write
260 * the mapped memory, adding the necessary offsets to the address cookie.
262 #define IX_OSAL_MEM_MAP(physAddr, size) \
263 ixOsalIoMemMap((physAddr), (size), IX_OSAL_COMPONENT_MAPPING)
267 * @ingroup IxOsalIoMem
269 * @def IX_OSAL_MEM_UNMAP(virtAddr)
271 * @brief Unmap a previously mapped I/O memory zone using virtual pointer obtained
272 * during the mapping operation.
274 * @param virtAddr - the virtual pointer to the zone to be unmapped.
277 * @note This function unmaps a previously mapped I/O memory zone using
278 * the cookie obtained in the mapping operation. The memory zone in question
279 * becomes unavailable to the caller once unmapped and the cookie should be
282 * This function cannot fail if the given parameter is correct and does not
285 #define IX_OSAL_MEM_UNMAP(virtAddr) \
286 ixOsalIoMemUnmap ((virtAddr), IX_OSAL_COMPONENT_MAPPING)
289 * @ingroup IxOsalIoMem
291 * @def IX_OSAL_MMAP_VIRT_TO_PHYS(virtAddr)
293 * @brief This function Converts a virtual address into a physical
294 * address, including the dynamically mapped memory.
296 * @param virtAddr - virtual address to convert
297 * Return value: corresponding physical address, or NULL
299 #define IX_OSAL_MMAP_VIRT_TO_PHYS(virtAddr) \
300 ixOsalIoMemVirtToPhys(virtAddr, IX_OSAL_COMPONENT_MAPPING)
304 * @ingroup IxOsalIoMem
306 * @def IX_OSAL_MMAP_PHYS_TO_VIRT(physAddr)
308 * @brief This function Converts a virtual address into a physical
309 * address, including the dynamically mapped memory.
311 * @param physAddr - physical address to convert
312 * Return value: corresponding virtual address, or NULL
315 #define IX_OSAL_MMAP_PHYS_TO_VIRT(physAddr) \
316 ixOsalIoMemPhysToVirt(physAddr, IX_OSAL_COMPONENT_MAPPING)
322 #endif /* IxOsalIoMem_H */