blob: a3a71242ae900ca580ffd6c12a4b9f4b675559a4 [file] [log] [blame]
Wolfgang Denk4646d2a2006-05-30 15:56:48 +02001/*
2 * @file IxOsalIoMem.h
3 * @author Intel Corporation
4 * @date 25-08-2004
5 *
6 * @brief description goes here
7 */
8
9/**
10 * @par
11 * IXP400 SW Release version 2.0
12 *
13 * -- Copyright Notice --
14 *
15 * @par
16 * Copyright 2001-2005, Intel Corporation.
17 * All rights reserved.
18 *
19 * @par
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
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.
31 *
32 * @par
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
43 * SUCH DAMAGE.
44 *
45 * @par
46 * -- End of Copyright Notice --
47 */
48
49#ifndef IxOsalIoMem_H
50#define IxOsalIoMem_H
51
52
53/*
54 * Decide OS and Endianess, such as IX_OSAL_VXWORKS_LE.
55 */
56#include "IxOsalEndianess.h"
57
58/**
59 * @defgroup IxOsalIoMem Osal IoMem module
60 *
61 * @brief I/O memory and endianess support.
62 *
63 * @{
64 */
65
66
67/* Low-level conversion macros - DO NOT USE UNLESS ABSOLUTELY NEEDED */
68#ifndef __wince
69
70
71/*
72 * Private function to swap word*//*
73 */
74#ifdef __XSCALE__
75static __inline__ UINT32
76ixOsalCoreWordSwap (UINT32 wordIn)
77{
78 /*
79 * Storage for the swapped word
80 */
81 UINT32 wordOut;
82
83 /*
84 * wordIn = A, B, C, D
85 */
86 __asm__ (" eor r1, %1, %1, ror #16;" /* R1 = A^C, B^D, C^A, D^B */
87 " bic r1, r1, #0x00ff0000;" /* R1 = A^C, 0 , C^A, D^B */
88 " mov %0, %1, ror #8;" /* wordOut = D, A, B, C */
89 " eor %0, %0, r1, lsr #8;" /* wordOut = D, C, B, A */
90 : "=r" (wordOut): "r" (wordIn):"r1");
91
92 return wordOut;
93}
94
95
96#define IX_OSAL_SWAP_LONG(wData) (ixOsalCoreWordSwap(wData))
97#else
98#define IX_OSAL_SWAP_LONG(wData) ((wData >> 24) | (((wData >> 16) & 0xFF) << 8) | (((wData >> 8) & 0xFF) << 16) | ((wData & 0xFF) << 24))
99#endif
100
101#else /* ndef __wince */
102#define IX_OSAL_SWAP_LONG(wData) ((((UINT32)wData << 24) | ((UINT32)wData >> 24)) | (((wData << 8) & 0xff0000) | ((wData >> 8) & 0xff00)))
103#endif /* ndef __wince */
104
105#define IX_OSAL_SWAP_SHORT(sData) ((sData >> 8) | ((sData & 0xFF) << 8))
106#define IX_OSAL_SWAP_SHORT_ADDRESS(sAddr) ((sAddr) ^ 0x2)
107#define IX_OSAL_SWAP_BYTE_ADDRESS(bAddr) ((bAddr) ^ 0x3)
108
109#define IX_OSAL_BE_XSTOBUSL(wData) (wData)
110#define IX_OSAL_BE_XSTOBUSS(sData) (sData)
111#define IX_OSAL_BE_XSTOBUSB(bData) (bData)
112#define IX_OSAL_BE_BUSTOXSL(wData) (wData)
113#define IX_OSAL_BE_BUSTOXSS(sData) (sData)
114#define IX_OSAL_BE_BUSTOXSB(bData) (bData)
115
116#define IX_OSAL_LE_AC_XSTOBUSL(wAddr) (wAddr)
117#define IX_OSAL_LE_AC_XSTOBUSS(sAddr) IX_OSAL_SWAP_SHORT_ADDRESS(sAddr)
118#define IX_OSAL_LE_AC_XSTOBUSB(bAddr) IX_OSAL_SWAP_BYTE_ADDRESS(bAddr)
119#define IX_OSAL_LE_AC_BUSTOXSL(wAddr) (wAddr)
120#define IX_OSAL_LE_AC_BUSTOXSS(sAddr) IX_OSAL_SWAP_SHORT_ADDRESS(sAddr)
121#define IX_OSAL_LE_AC_BUSTOXSB(bAddr) IX_OSAL_SWAP_BYTE_ADDRESS(bAddr)
122
123#define IX_OSAL_LE_DC_XSTOBUSL(wData) IX_OSAL_SWAP_LONG(wData)
124#define IX_OSAL_LE_DC_XSTOBUSS(sData) IX_OSAL_SWAP_SHORT(sData)
125#define IX_OSAL_LE_DC_XSTOBUSB(bData) (bData)
126#define IX_OSAL_LE_DC_BUSTOXSL(wData) IX_OSAL_SWAP_LONG(wData)
127#define IX_OSAL_LE_DC_BUSTOXSS(sData) IX_OSAL_SWAP_SHORT(sData)
128#define IX_OSAL_LE_DC_BUSTOXSB(bData) (bData)
129
130
131/*
132 * Decide SDRAM mapping, then implement read/write
133 */
134#include "IxOsalMemAccess.h"
135
136
137/**
138 * @ingroup IxOsalIoMem
139 * @enum IxOsalMapEntryType
140 * @brief This is an emum for OSAL I/O mem map type.
141 */
142typedef enum
143{
144 IX_OSAL_STATIC_MAP = 0, /**<Set map entry type to static map */
145 IX_OSAL_DYNAMIC_MAP /**<Set map entry type to dynamic map */
146} IxOsalMapEntryType;
147
148
149/**
150 * @ingroup IxOsalIoMem
151 * @enum IxOsalMapEndianessType
152 * @brief This is an emum for OSAL I/O mem Endianess and Coherency mode.
153 */
154typedef enum
155{
156 IX_OSAL_BE = 0x1, /**<Set map endian mode to Big Endian */
157 IX_OSAL_LE_AC = 0x2, /**<Set map endian mode to Little Endian, Address Coherent */
158 IX_OSAL_LE_DC = 0x4, /**<Set map endian mode to Little Endian, Data Coherent */
159 IX_OSAL_LE = 0x8 /**<Set map endian mode to Little Endian without specifying coherency mode */
160} IxOsalMapEndianessType;
161
162
163/**
164 * @struct IxOsalMemoryMap
165 * @brief IxOsalMemoryMap structure
166 */
167typedef struct _IxOsalMemoryMap
168{
169 IxOsalMapEntryType type; /**< map type - IX_OSAL_STATIC_MAP or IX_OSAL_DYNAMIC_MAP */
170
171 UINT32 physicalAddress; /**< physical address of the memory mapped I/O zone */
172
173 UINT32 size; /**< size of the map */
174
175
176 UINT32 virtualAddress; /**< virtual address of the zone; must be predefined
177 in the global memory map for static maps and has
178 to be NULL for dynamic maps (populated on allocation)
179 */
180 /*
181 * pointer to a map function called to map a dynamic map;
182 * will populate the virtualAddress field
183 */
184 void (*mapFunction) (struct _IxOsalMemoryMap * map); /**< pointer to a map function called to map a dynamic map */
185
186 /*
187 * pointer to a map function called to unmap a dynamic map;
188 * will reset the virtualAddress field to NULL
189 */
190 void (*unmapFunction) (struct _IxOsalMemoryMap * map); /**< pointer to a map function called to unmap a dynamic map */
191
192 /*
193 * reference count describing how many components share this map;
194 * actual allocation/deallocation for dynamic maps is done only
195 * between 0 <=> 1 transitions of the counter
196 */
197 UINT32 refCount; /**< reference count describing how many components share this map */
198
199 /*
200 * memory endian type for the map; can be a combination of IX_OSAL_BE (Big
201 * Endian) and IX_OSAL_LE or IX_OSAL_LE_AC or IX_OSAL_LE_DC
202 * (Little Endian, Address Coherent or Data Coherent). Any combination is
203 * allowed provided it contains at most one LE flag - e.g.
204 * (IX_OSAL_BE), (IX_OSAL_LE_AC), (IX_OSAL_BE | IX_OSAL_LE_DC) are valid
205 * combinations while (IX_OSAL_BE | IX_OSAL_LE_DC | IX_OSAL_LE_AC) is not.
206 */
207 IxOsalMapEndianessType mapEndianType; /**< memory endian type for the map */
208
209 char *name; /**< user-friendly name */
210} IxOsalMemoryMap;
211
212
213
214
215/* Internal function to map a memory zone
216 * NOTE - This should not be called by the user.
217 * Use the macro IX_OSAL_MEM_MAP instead
218 */
219PUBLIC void *ixOsalIoMemMap (UINT32 requestedAddress,
220 UINT32 size,
221 IxOsalMapEndianessType requestedCoherency);
222
223
224/* Internal function to unmap a memory zone mapped with ixOsalIoMemMap
225 * NOTE - This should not be called by the user.
226 * Use the macro IX_OSAL_MEM_UNMAP instead
227 */
228PUBLIC void ixOsalIoMemUnmap (UINT32 requestedAddress, UINT32 coherency);
229
230
231/* Internal function to convert virtual address to physical address
232 * NOTE - This should not be called by the user.
233 * Use the macro IX_OSAL_MMAP_VIRT_TO_PHYS */
234PUBLIC UINT32 ixOsalIoMemVirtToPhys (UINT32 virtualAddress, UINT32 coherency);
235
236
237/* Internal function to convert physical address to virtual address
238 * NOTE - This should not be called by the user.
239 * Use the macro IX_OSAL_MMAP_PHYS_TO_VIRT */
240PUBLIC UINT32
241ixOsalIoMemPhysToVirt (UINT32 physicalAddress, UINT32 coherency);
242
243/**
244 * @ingroup IxOsalIoMem
245 *
246 * @def IX_OSAL_MEM_MAP(physAddr, size)
247 *
248 * @brief Map an I/O mapped physical memory zone to virtual zone and return virtual
249 * pointer.
250 * @param physAddr - the physical address
251 * @param size - the size
252 * @return start address of the virtual memory zone.
253 *
254 * @note This function maps an I/O mapped physical memory zone of the given size
255 * into a virtual memory zone accessible by the caller and returns a cookie -
256 * the start address of the virtual memory zone.
257 * IX_OSAL_MMAP_PHYS_TO_VIRT should NOT therefore be used on the returned
258 * virtual address.
259 * The memory zone is to be unmapped using IX_OSAL_MEM_UNMAP once the caller has
260 * finished using this zone (e.g. on driver unload) using the cookie as
261 * parameter.
262 * The IX_OSAL_READ/WRITE_LONG/SHORT macros should be used to read and write
263 * the mapped memory, adding the necessary offsets to the address cookie.
264 */
265#define IX_OSAL_MEM_MAP(physAddr, size) \
266 ixOsalIoMemMap((physAddr), (size), IX_OSAL_COMPONENT_MAPPING)
267
268
269/**
270 * @ingroup IxOsalIoMem
271 *
272 * @def IX_OSAL_MEM_UNMAP(virtAddr)
273 *
274 * @brief Unmap a previously mapped I/O memory zone using virtual pointer obtained
275 * during the mapping operation.
276 * pointer.
277 * @param virtAddr - the virtual pointer to the zone to be unmapped.
278 * @return none
279 *
280 * @note This function unmaps a previously mapped I/O memory zone using
281 * the cookie obtained in the mapping operation. The memory zone in question
282 * becomes unavailable to the caller once unmapped and the cookie should be
283 * discarded.
284 *
285 * This function cannot fail if the given parameter is correct and does not
286 * return a value.
287 */
288#define IX_OSAL_MEM_UNMAP(virtAddr) \
289 ixOsalIoMemUnmap ((virtAddr), IX_OSAL_COMPONENT_MAPPING)
290
291/**
292 * @ingroup IxOsalIoMem
293 *
294 * @def IX_OSAL_MMAP_VIRT_TO_PHYS(virtAddr)
295 *
296 * @brief This function Converts a virtual address into a physical
297 * address, including the dynamically mapped memory.
298 *
299 * @param virtAddr - virtual address to convert
300 * Return value: corresponding physical address, or NULL
301 */
302#define IX_OSAL_MMAP_VIRT_TO_PHYS(virtAddr) \
303 ixOsalIoMemVirtToPhys(virtAddr, IX_OSAL_COMPONENT_MAPPING)
304
305
306/**
307 * @ingroup IxOsalIoMem
308 *
309 * @def IX_OSAL_MMAP_PHYS_TO_VIRT(physAddr)
310 *
311 * @brief This function Converts a virtual address into a physical
312 * address, including the dynamically mapped memory.
313 *
314 * @param physAddr - physical address to convert
315 * Return value: corresponding virtual address, or NULL
316 *
317 */
318#define IX_OSAL_MMAP_PHYS_TO_VIRT(physAddr) \
319 ixOsalIoMemPhysToVirt(physAddr, IX_OSAL_COMPONENT_MAPPING)
320
321
322/**
323 * @} IxOsalIoMem
324 */
325
326#endif /* IxOsalIoMem_H */