IxOsalIoMem.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /*
  2. * @file IxOsalIoMem.h
  3. * @author Intel Corporation
  4. * @date 25-08-2004
  5. *
  6. * @brief description goes here
  7. */
  8. /**
  9. * @par
  10. * IXP400 SW Release version 2.0
  11. *
  12. * -- Copyright Notice --
  13. *
  14. * @par
  15. * Copyright 2001-2005, Intel Corporation.
  16. * All rights reserved.
  17. *
  18. * @par
  19. * Redistribution and use in source and binary forms, with or without
  20. * modification, are permitted provided that the following conditions
  21. * are met:
  22. * 1. Redistributions of source code must retain the above copyright
  23. * notice, this list of conditions and the following disclaimer.
  24. * 2. Redistributions in binary form must reproduce the above copyright
  25. * notice, this list of conditions and the following disclaimer in the
  26. * documentation and/or other materials provided with the distribution.
  27. * 3. Neither the name of the Intel Corporation nor the names of its contributors
  28. * may be used to endorse or promote products derived from this software
  29. * without specific prior written permission.
  30. *
  31. * @par
  32. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
  33. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  34. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  35. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  36. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  37. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  38. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  39. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  40. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  41. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  42. * SUCH DAMAGE.
  43. *
  44. * @par
  45. * -- End of Copyright Notice --
  46. */
  47. #ifndef IxOsalIoMem_H
  48. #define IxOsalIoMem_H
  49. /*
  50. * Decide OS and Endianess, such as IX_OSAL_VXWORKS_LE.
  51. */
  52. #include "IxOsalEndianess.h"
  53. /**
  54. * @defgroup IxOsalIoMem Osal IoMem module
  55. *
  56. * @brief I/O memory and endianess support.
  57. *
  58. * @{
  59. */
  60. /* Low-level conversion macros - DO NOT USE UNLESS ABSOLUTELY NEEDED */
  61. #ifndef __wince
  62. /*
  63. * Private function to swap word
  64. */
  65. #ifdef __XSCALE__
  66. static __inline__ UINT32
  67. ixOsalCoreWordSwap (UINT32 wordIn)
  68. {
  69. /*
  70. * Storage for the swapped word
  71. */
  72. UINT32 wordOut;
  73. /*
  74. * wordIn = A, B, C, D
  75. */
  76. __asm__ (" eor r1, %1, %1, ror #16;" /* R1 = A^C, B^D, C^A, D^B */
  77. " bic r1, r1, #0x00ff0000;" /* R1 = A^C, 0 , C^A, D^B */
  78. " mov %0, %1, ror #8;" /* wordOut = D, A, B, C */
  79. " eor %0, %0, r1, lsr #8;" /* wordOut = D, C, B, A */
  80. : "=r" (wordOut): "r" (wordIn):"r1");
  81. return wordOut;
  82. }
  83. #define IX_OSAL_SWAP_LONG(wData) (ixOsalCoreWordSwap(wData))
  84. #else
  85. #define IX_OSAL_SWAP_LONG(wData) ((wData >> 24) | (((wData >> 16) & 0xFF) << 8) | (((wData >> 8) & 0xFF) << 16) | ((wData & 0xFF) << 24))
  86. #endif
  87. #else /* ndef __wince */
  88. #define IX_OSAL_SWAP_LONG(wData) ((((UINT32)wData << 24) | ((UINT32)wData >> 24)) | (((wData << 8) & 0xff0000) | ((wData >> 8) & 0xff00)))
  89. #endif /* ndef __wince */
  90. #define IX_OSAL_SWAP_SHORT(sData) ((sData >> 8) | ((sData & 0xFF) << 8))
  91. #define IX_OSAL_SWAP_SHORT_ADDRESS(sAddr) ((sAddr) ^ 0x2)
  92. #define IX_OSAL_SWAP_BYTE_ADDRESS(bAddr) ((bAddr) ^ 0x3)
  93. #define IX_OSAL_BE_XSTOBUSL(wData) (wData)
  94. #define IX_OSAL_BE_XSTOBUSS(sData) (sData)
  95. #define IX_OSAL_BE_XSTOBUSB(bData) (bData)
  96. #define IX_OSAL_BE_BUSTOXSL(wData) (wData)
  97. #define IX_OSAL_BE_BUSTOXSS(sData) (sData)
  98. #define IX_OSAL_BE_BUSTOXSB(bData) (bData)
  99. #define IX_OSAL_LE_AC_XSTOBUSL(wAddr) (wAddr)
  100. #define IX_OSAL_LE_AC_XSTOBUSS(sAddr) IX_OSAL_SWAP_SHORT_ADDRESS(sAddr)
  101. #define IX_OSAL_LE_AC_XSTOBUSB(bAddr) IX_OSAL_SWAP_BYTE_ADDRESS(bAddr)
  102. #define IX_OSAL_LE_AC_BUSTOXSL(wAddr) (wAddr)
  103. #define IX_OSAL_LE_AC_BUSTOXSS(sAddr) IX_OSAL_SWAP_SHORT_ADDRESS(sAddr)
  104. #define IX_OSAL_LE_AC_BUSTOXSB(bAddr) IX_OSAL_SWAP_BYTE_ADDRESS(bAddr)
  105. #define IX_OSAL_LE_DC_XSTOBUSL(wData) IX_OSAL_SWAP_LONG(wData)
  106. #define IX_OSAL_LE_DC_XSTOBUSS(sData) IX_OSAL_SWAP_SHORT(sData)
  107. #define IX_OSAL_LE_DC_XSTOBUSB(bData) (bData)
  108. #define IX_OSAL_LE_DC_BUSTOXSL(wData) IX_OSAL_SWAP_LONG(wData)
  109. #define IX_OSAL_LE_DC_BUSTOXSS(sData) IX_OSAL_SWAP_SHORT(sData)
  110. #define IX_OSAL_LE_DC_BUSTOXSB(bData) (bData)
  111. /*
  112. * Decide SDRAM mapping, then implement read/write
  113. */
  114. #include "IxOsalMemAccess.h"
  115. /**
  116. * @ingroup IxOsalIoMem
  117. * @enum IxOsalMapEntryType
  118. * @brief This is an emum for OSAL I/O mem map type.
  119. */
  120. typedef enum
  121. {
  122. IX_OSAL_STATIC_MAP = 0, /**<Set map entry type to static map */
  123. IX_OSAL_DYNAMIC_MAP /**<Set map entry type to dynamic map */
  124. } IxOsalMapEntryType;
  125. /**
  126. * @ingroup IxOsalIoMem
  127. * @enum IxOsalMapEndianessType
  128. * @brief This is an emum for OSAL I/O mem Endianess and Coherency mode.
  129. */
  130. typedef enum
  131. {
  132. IX_OSAL_BE = 0x1, /**<Set map endian mode to Big Endian */
  133. IX_OSAL_LE_AC = 0x2, /**<Set map endian mode to Little Endian, Address Coherent */
  134. IX_OSAL_LE_DC = 0x4, /**<Set map endian mode to Little Endian, Data Coherent */
  135. IX_OSAL_LE = 0x8 /**<Set map endian mode to Little Endian without specifying coherency mode */
  136. } IxOsalMapEndianessType;
  137. /**
  138. * @struct IxOsalMemoryMap
  139. * @brief IxOsalMemoryMap structure
  140. */
  141. typedef struct _IxOsalMemoryMap
  142. {
  143. IxOsalMapEntryType type; /**< map type - IX_OSAL_STATIC_MAP or IX_OSAL_DYNAMIC_MAP */
  144. UINT32 physicalAddress; /**< physical address of the memory mapped I/O zone */
  145. UINT32 size; /**< size of the map */
  146. UINT32 virtualAddress; /**< virtual address of the zone; must be predefined
  147. in the global memory map for static maps and has
  148. to be NULL for dynamic maps (populated on allocation)
  149. */
  150. /*
  151. * pointer to a map function called to map a dynamic map;
  152. * will populate the virtualAddress field
  153. */
  154. void (*mapFunction) (struct _IxOsalMemoryMap * map); /**< pointer to a map function called to map a dynamic map */
  155. /*
  156. * pointer to a map function called to unmap a dynamic map;
  157. * will reset the virtualAddress field to NULL
  158. */
  159. void (*unmapFunction) (struct _IxOsalMemoryMap * map); /**< pointer to a map function called to unmap a dynamic map */
  160. /*
  161. * reference count describing how many components share this map;
  162. * actual allocation/deallocation for dynamic maps is done only
  163. * between 0 <=> 1 transitions of the counter
  164. */
  165. UINT32 refCount; /**< reference count describing how many components share this map */
  166. /*
  167. * memory endian type for the map; can be a combination of IX_OSAL_BE (Big
  168. * Endian) and IX_OSAL_LE or IX_OSAL_LE_AC or IX_OSAL_LE_DC
  169. * (Little Endian, Address Coherent or Data Coherent). Any combination is
  170. * allowed provided it contains at most one LE flag - e.g.
  171. * (IX_OSAL_BE), (IX_OSAL_LE_AC), (IX_OSAL_BE | IX_OSAL_LE_DC) are valid
  172. * combinations while (IX_OSAL_BE | IX_OSAL_LE_DC | IX_OSAL_LE_AC) is not.
  173. */
  174. IxOsalMapEndianessType mapEndianType; /**< memory endian type for the map */
  175. char *name; /**< user-friendly name */
  176. } IxOsalMemoryMap;
  177. /* Internal function to map a memory zone
  178. * NOTE - This should not be called by the user.
  179. * Use the macro IX_OSAL_MEM_MAP instead
  180. */
  181. PUBLIC void *ixOsalIoMemMap (UINT32 requestedAddress,
  182. UINT32 size,
  183. IxOsalMapEndianessType requestedCoherency);
  184. /* Internal function to unmap a memory zone mapped with ixOsalIoMemMap
  185. * NOTE - This should not be called by the user.
  186. * Use the macro IX_OSAL_MEM_UNMAP instead
  187. */
  188. PUBLIC void ixOsalIoMemUnmap (UINT32 requestedAddress, UINT32 coherency);
  189. /* Internal function to convert virtual address to physical address
  190. * NOTE - This should not be called by the user.
  191. * Use the macro IX_OSAL_MMAP_VIRT_TO_PHYS */
  192. PUBLIC UINT32 ixOsalIoMemVirtToPhys (UINT32 virtualAddress, UINT32 coherency);
  193. /* Internal function to convert physical address to virtual address
  194. * NOTE - This should not be called by the user.
  195. * Use the macro IX_OSAL_MMAP_PHYS_TO_VIRT */
  196. PUBLIC UINT32
  197. ixOsalIoMemPhysToVirt (UINT32 physicalAddress, UINT32 coherency);
  198. /**
  199. * @ingroup IxOsalIoMem
  200. *
  201. * @def IX_OSAL_MEM_MAP(physAddr, size)
  202. *
  203. * @brief Map an I/O mapped physical memory zone to virtual zone and return virtual
  204. * pointer.
  205. * @param physAddr - the physical address
  206. * @param size - the size
  207. * @return start address of the virtual memory zone.
  208. *
  209. * @note This function maps an I/O mapped physical memory zone of the given size
  210. * into a virtual memory zone accessible by the caller and returns a cookie -
  211. * the start address of the virtual memory zone.
  212. * IX_OSAL_MMAP_PHYS_TO_VIRT should NOT therefore be used on the returned
  213. * virtual address.
  214. * The memory zone is to be unmapped using IX_OSAL_MEM_UNMAP once the caller has
  215. * finished using this zone (e.g. on driver unload) using the cookie as
  216. * parameter.
  217. * The IX_OSAL_READ/WRITE_LONG/SHORT macros should be used to read and write
  218. * the mapped memory, adding the necessary offsets to the address cookie.
  219. */
  220. #define IX_OSAL_MEM_MAP(physAddr, size) \
  221. ixOsalIoMemMap((physAddr), (size), IX_OSAL_COMPONENT_MAPPING)
  222. /**
  223. * @ingroup IxOsalIoMem
  224. *
  225. * @def IX_OSAL_MEM_UNMAP(virtAddr)
  226. *
  227. * @brief Unmap a previously mapped I/O memory zone using virtual pointer obtained
  228. * during the mapping operation.
  229. * pointer.
  230. * @param virtAddr - the virtual pointer to the zone to be unmapped.
  231. * @return none
  232. *
  233. * @note This function unmaps a previously mapped I/O memory zone using
  234. * the cookie obtained in the mapping operation. The memory zone in question
  235. * becomes unavailable to the caller once unmapped and the cookie should be
  236. * discarded.
  237. *
  238. * This function cannot fail if the given parameter is correct and does not
  239. * return a value.
  240. */
  241. #define IX_OSAL_MEM_UNMAP(virtAddr) \
  242. ixOsalIoMemUnmap ((virtAddr), IX_OSAL_COMPONENT_MAPPING)
  243. /**
  244. * @ingroup IxOsalIoMem
  245. *
  246. * @def IX_OSAL_MMAP_VIRT_TO_PHYS(virtAddr)
  247. *
  248. * @brief This function Converts a virtual address into a physical
  249. * address, including the dynamically mapped memory.
  250. *
  251. * @param virtAddr - virtual address to convert
  252. * Return value: corresponding physical address, or NULL
  253. */
  254. #define IX_OSAL_MMAP_VIRT_TO_PHYS(virtAddr) \
  255. ixOsalIoMemVirtToPhys(virtAddr, IX_OSAL_COMPONENT_MAPPING)
  256. /**
  257. * @ingroup IxOsalIoMem
  258. *
  259. * @def IX_OSAL_MMAP_PHYS_TO_VIRT(physAddr)
  260. *
  261. * @brief This function Converts a virtual address into a physical
  262. * address, including the dynamically mapped memory.
  263. *
  264. * @param physAddr - physical address to convert
  265. * Return value: corresponding virtual address, or NULL
  266. *
  267. */
  268. #define IX_OSAL_MMAP_PHYS_TO_VIRT(physAddr) \
  269. ixOsalIoMemPhysToVirt(physAddr, IX_OSAL_COMPONENT_MAPPING)
  270. /**
  271. * @} IxOsalIoMem
  272. */
  273. #endif /* IxOsalIoMem_H */