uboot/cpu/ixp/npe/include/IxOsalIoMem.h
<<
>>
Prefs
   1/*
   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/* Low-level conversion macros - DO NOT USE UNLESS ABSOLUTELY NEEDED */
  67#ifndef __wince
  68
  69
  70/* 
  71 * Private function to swap word
  72 */
  73#ifdef __XSCALE__
  74static __inline__ UINT32
  75ixOsalCoreWordSwap (UINT32 wordIn)
  76{
  77    /*
  78     * Storage for the swapped word 
  79     */
  80    UINT32 wordOut;
  81
  82    /*
  83     * wordIn = A, B, C, D 
  84     */
  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");
  90
  91    return wordOut;
  92}
  93
  94#define IX_OSAL_SWAP_LONG(wData)          (ixOsalCoreWordSwap(wData))
  95#else
  96#define IX_OSAL_SWAP_LONG(wData)          ((wData >> 24) | (((wData >> 16) & 0xFF) << 8) | (((wData >> 8) & 0xFF) << 16) | ((wData & 0xFF) << 24))
  97#endif
  98
  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 */
 102
 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)
 106
 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)
 113
 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)
 120
 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)
 127
 128
 129/*
 130 * Decide SDRAM mapping, then implement read/write
 131 */
 132#include "IxOsalMemAccess.h"
 133
 134
 135/**
 136 * @ingroup IxOsalIoMem
 137 * @enum IxOsalMapEntryType
 138 * @brief This is an emum for OSAL I/O mem map type. 
 139 */
 140typedef enum
 141{
 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;
 145
 146
 147/**
 148 * @ingroup IxOsalIoMem
 149 * @enum IxOsalMapEndianessType
 150 * @brief This is an emum for OSAL I/O mem Endianess and Coherency mode.
 151 */
 152typedef enum
 153{
 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;
 159
 160
 161/**
 162 * @struct IxOsalMemoryMap 
 163 * @brief IxOsalMemoryMap structure
 164 */
 165typedef struct _IxOsalMemoryMap
 166{
 167    IxOsalMapEntryType type;   /**< map type - IX_OSAL_STATIC_MAP or IX_OSAL_DYNAMIC_MAP */
 168
 169    UINT32 physicalAddress;    /**< physical address of the memory mapped I/O zone */
 170
 171    UINT32 size;               /**< size of the map */
 172
 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)
 176                                                                */
 177    /*
 178     * pointer to a map function called to map a dynamic map; 
 179     * will populate the virtualAddress field 
 180     */
 181    void (*mapFunction) (struct _IxOsalMemoryMap * map);   /**< pointer to a map function called to map a dynamic map */
 182
 183    /*
 184     * pointer to a map function called to unmap a dynamic map; 
 185     * will reset the virtualAddress field to NULL 
 186     */
 187    void (*unmapFunction) (struct _IxOsalMemoryMap * map); /**< pointer to a map function called to unmap a dynamic map */
 188
 189    /*
 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 
 193     */
 194    UINT32 refCount;   /**< reference count describing how many components share this map */
 195
 196    /*
 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. 
 203     */
 204    IxOsalMapEndianessType mapEndianType; /**< memory endian type for the map */
 205
 206    char *name;      /**< user-friendly name */
 207} IxOsalMemoryMap;
 208
 209
 210
 211
 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
 215 */
 216PUBLIC void *ixOsalIoMemMap (UINT32 requestedAddress,
 217                             UINT32 size,
 218                             IxOsalMapEndianessType requestedCoherency);
 219
 220
 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
 224 */
 225PUBLIC void ixOsalIoMemUnmap (UINT32 requestedAddress, UINT32 coherency);
 226
 227
 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 */
 231PUBLIC UINT32 ixOsalIoMemVirtToPhys (UINT32 virtualAddress, UINT32 coherency);
 232
 233
 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 */
 237PUBLIC UINT32
 238ixOsalIoMemPhysToVirt (UINT32 physicalAddress, UINT32 coherency);
 239
 240/**
 241 * @ingroup IxOsalIoMem
 242 *
 243 * @def IX_OSAL_MEM_MAP(physAddr, size)
 244 *
 245 * @brief Map an I/O mapped physical memory zone to virtual zone and return virtual
 246 *        pointer.
 247 * @param  physAddr - the physical address
 248 * @param  size     - the size
 249 * @return start address of the virtual memory zone.
 250 *
 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 
 255 * virtual address.
 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 
 258 * parameter.
 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.
 261 */
 262#define IX_OSAL_MEM_MAP(physAddr, size) \
 263    ixOsalIoMemMap((physAddr), (size), IX_OSAL_COMPONENT_MAPPING)
 264
 265
 266/**
 267 * @ingroup IxOsalIoMem
 268 *
 269 * @def IX_OSAL_MEM_UNMAP(virtAddr)
 270 *
 271 * @brief Unmap a previously mapped I/O memory zone using virtual pointer obtained
 272 *        during the mapping operation.
 273 *        pointer.
 274 * @param  virtAddr - the virtual pointer to the zone to be unmapped.
 275 * @return none
 276 *
 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
 280 * discarded.
 281 *
 282 * This function cannot fail if the given parameter is correct and does not
 283 * return a value.
 284 */
 285#define IX_OSAL_MEM_UNMAP(virtAddr) \
 286    ixOsalIoMemUnmap ((virtAddr), IX_OSAL_COMPONENT_MAPPING)
 287
 288/**
 289 * @ingroup IxOsalIoMem
 290 *
 291 * @def IX_OSAL_MMAP_VIRT_TO_PHYS(virtAddr)
 292 *
 293 * @brief This function Converts a virtual address into a physical 
 294 * address, including the dynamically mapped memory.
 295 *
 296 * @param  virtAddr - virtual address to convert
 297 * Return value: corresponding physical address, or NULL
 298 */
 299#define IX_OSAL_MMAP_VIRT_TO_PHYS(virtAddr) \
 300    ixOsalIoMemVirtToPhys(virtAddr, IX_OSAL_COMPONENT_MAPPING)
 301
 302
 303/**
 304 * @ingroup IxOsalIoMem
 305 *
 306 * @def IX_OSAL_MMAP_PHYS_TO_VIRT(physAddr)
 307 *
 308 * @brief  This function Converts a virtual address into a physical 
 309 * address, including the dynamically mapped memory.
 310 *
 311 * @param  physAddr - physical address to convert
 312 * Return value: corresponding virtual address, or NULL
 313 *
 314 */
 315#define IX_OSAL_MMAP_PHYS_TO_VIRT(physAddr) \
 316    ixOsalIoMemPhysToVirt(physAddr, IX_OSAL_COMPONENT_MAPPING)
 317
 318/**
 319 * @} IxOsalIoMem
 320 */
 321
 322#endif /* IxOsalIoMem_H */
 323