HALhwio.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. /*
  2. * Copyright (c) 2016-2017 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #ifndef HAL_HWIO_H
  19. #define HAL_HWIO_H
  20. /*
  21. ===========================================================================
  22. */
  23. /**
  24. @file HALhwio.h
  25. Public interface include file for accessing the HWIO HAL definitions.
  26. The HALhwio.h file is the public API interface to the HW I/O (HWIO)
  27. register access definitions.
  28. */
  29. /*=========================================================================
  30. Include Files
  31. ==========================================================================*/
  32. /*
  33. * Common types.
  34. */
  35. #include "HALcomdef.h"
  36. /* -----------------------------------------------------------------------
  37. ** Macros
  38. ** ----------------------------------------------------------------------- */
  39. /**
  40. @addtogroup macros
  41. @{
  42. */
  43. /**
  44. * Map a base name to the pointer to access the base.
  45. *
  46. * This macro maps a base name to the pointer to access the base.
  47. * This is generally just used internally.
  48. *
  49. */
  50. #define HWIO_BASE_PTR(base) base##_BASE_PTR
  51. /**
  52. * Declare a HWIO base pointer.
  53. *
  54. * This macro will declare a HWIO base pointer data structure. The pointer
  55. * will always be declared as a weak symbol so multiple declarations will
  56. * resolve correctly to the same data at link-time.
  57. */
  58. #ifdef __ARMCC_VERSION
  59. #define DECLARE_HWIO_BASE_PTR(base) __weak uint8 *HWIO_BASE_PTR(base)
  60. #else
  61. #define DECLARE_HWIO_BASE_PTR(base) uint8 *HWIO_BASE_PTR(base)
  62. #endif
  63. /**
  64. @}
  65. */
  66. /**
  67. @addtogroup hwio_macros
  68. @{
  69. */
  70. /**
  71. * @name Address Macros
  72. *
  73. * Macros for getting register addresses.
  74. * These macros are used for retrieving the address of a register.
  75. * HWIO_ADDR* will return the directly accessible address (virtual or physical based
  76. * on environment), HWIO_PHYS* will always return the physical address.
  77. * The offset from the base region can be retrieved using HWIO_OFFS*.
  78. * The "X" extension is used for explicit addressing where the base address of
  79. * the module in question is provided as an argument to the macro.
  80. *
  81. * @{
  82. */
  83. #define HWIO_ADDR(hwiosym) __msmhwio_addr(hwiosym)
  84. #define HWIO_ADDRI(hwiosym, index) __msmhwio_addri(hwiosym, index)
  85. #define HWIO_ADDRI2(hwiosym, index1, index2) __msmhwio_addri2(hwiosym, index1, index2)
  86. #define HWIO_ADDRI3(hwiosym, index1, index2, index3) __msmhwio_addri3(hwiosym, index1, index2, index3)
  87. #define HWIO_ADDRX(base, hwiosym) __msmhwio_addrx(base, hwiosym)
  88. #define HWIO_ADDRXI(base, hwiosym, index) __msmhwio_addrxi(base, hwiosym, index)
  89. #define HWIO_ADDRXI2(base, hwiosym, index1, index2) __msmhwio_addrxi2(base, hwiosym, index1, index2)
  90. #define HWIO_ADDRXI3(base, hwiosym, index1, index2, index3) __msmhwio_addrxi3(base, hwiosym, index1, index2, index3)
  91. #define HWIO_PHYS(hwiosym) __msmhwio_phys(hwiosym)
  92. #define HWIO_PHYSI(hwiosym, index) __msmhwio_physi(hwiosym, index)
  93. #define HWIO_PHYSI2(hwiosym, index1, index2) __msmhwio_physi2(hwiosym, index1, index2)
  94. #define HWIO_PHYSI3(hwiosym, index1, index2, index3) __msmhwio_physi3(hwiosym, index1, index2, index3)
  95. #define HWIO_PHYSX(base, hwiosym) __msmhwio_physx(base, hwiosym)
  96. #define HWIO_PHYSXI(base, hwiosym, index) __msmhwio_physxi(base, hwiosym, index)
  97. #define HWIO_PHYSXI2(base, hwiosym, index1, index2) __msmhwio_physxi2(base, hwiosym, index1, index2)
  98. #define HWIO_PHYSXI3(base, hwiosym, index1, index2, index3) __msmhwio_physxi3(base, hwiosym, index1, index2, index3)
  99. #define HWIO_OFFS(hwiosym) __msmhwio_offs(hwiosym)
  100. #define HWIO_OFFSI(hwiosym, index) __msmhwio_offsi(hwiosym, index)
  101. #define HWIO_OFFSI2(hwiosym, index1, index2) __msmhwio_offsi2(hwiosym, index1, index2)
  102. #define HWIO_OFFSI3(hwiosym, index1, index2, index3) __msmhwio_offsi3(hwiosym, index1, index2, index3)
  103. /** @} */
  104. /**
  105. * @name Input Macros
  106. *
  107. * These macros are used for reading from a named hardware register. Register
  108. * arrays ("indexed") use the macros with the "I" suffix. The "M" suffix
  109. * indicates that the input will be masked with the supplied mask. The HWIO_INF*
  110. * macros take a field name and will do the appropriate masking and shifting
  111. * to return just the value of that field.
  112. * The "X" extension is used for explicit addressing where the base address of
  113. * the module in question is provided as an argument to the macro.
  114. *
  115. * Generally you want to use either HWIO_IN or HWIO_INF (with required indexing).
  116. *
  117. * @{
  118. */
  119. #define HWIO_IN(hwiosym) __msmhwio_in(hwiosym)
  120. #define HWIO_INI(hwiosym, index) __msmhwio_ini(hwiosym, index)
  121. #define HWIO_INI2(hwiosym, index1, index2) __msmhwio_ini2(hwiosym, index1, index2)
  122. #define HWIO_INI3(hwiosym, index1, index2, index3) __msmhwio_ini3(hwiosym, index1, index2, index3)
  123. #define HWIO_INM(hwiosym, mask) __msmhwio_inm(hwiosym, mask)
  124. #define HWIO_INMI(hwiosym, index, mask) __msmhwio_inmi(hwiosym, index, mask)
  125. #define HWIO_INMI2(hwiosym, index1, index2, mask) __msmhwio_inmi2(hwiosym, index1, index2, mask)
  126. #define HWIO_INMI3(hwiosym, index1, index2, index3, mask) __msmhwio_inmi3(hwiosym, index1, index2, index3, mask)
  127. #define HWIO_INF(io, field) (HWIO_INM(io, HWIO_FMSK(io, field)) >> HWIO_SHFT(io, field))
  128. #define HWIO_INFI(io, index, field) (HWIO_INMI(io, index, HWIO_FMSK(io, field)) >> HWIO_SHFT(io, field))
  129. #define HWIO_INFI2(io, index1, index2, field) (HWIO_INMI2(io, index1, index2, HWIO_FMSK(io, field)) >> HWIO_SHFT(io, field))
  130. #define HWIO_INFI3(io, index1, index2, index3, field) (HWIO_INMI3(io, index1, index2, index3, HWIO_FMSK(io, field)) >> HWIO_SHFT(io, field))
  131. #define HWIO_INX(base, hwiosym) __msmhwio_inx(base, hwiosym)
  132. #define HWIO_INXI(base, hwiosym, index) __msmhwio_inxi(base, hwiosym, index)
  133. #define HWIO_INXI2(base, hwiosym, index1, index2) __msmhwio_inxi2(base, hwiosym, index1, index2)
  134. #define HWIO_INXI3(base, hwiosym, index1, index2, index3) __msmhwio_inxi3(base, hwiosym, index1, index2, index3)
  135. #define HWIO_INXM(base, hwiosym, mask) __msmhwio_inxm(base, hwiosym, mask)
  136. #define HWIO_INXMI(base, hwiosym, index, mask) __msmhwio_inxmi(base, hwiosym, index, mask)
  137. #define HWIO_INXMI2(base, hwiosym, index1, index2, mask) __msmhwio_inxmi2(base, hwiosym, index1, index2, mask)
  138. #define HWIO_INXMI3(base, hwiosym, index1, index2, index3, mask) __msmhwio_inxmi3(base, hwiosym, index1, index2, index3, mask)
  139. #define HWIO_INXF(base, io, field) (HWIO_INXM(base, io, HWIO_FMSK(io, field)) >> HWIO_SHFT(io, field))
  140. #define HWIO_INXFI(base, io, index, field) (HWIO_INXMI(base, io, index, HWIO_FMSK(io, field)) >> HWIO_SHFT(io, field))
  141. #define HWIO_INXFI2(base, io, index1, index2, field) (HWIO_INXMI2(base, io, index1, index2, HWIO_FMSK(io, field)) >> HWIO_SHFT(io, field))
  142. #define HWIO_INXFI3(base, io, index1, index2, index3, field) (HWIO_INXMI3(base, io, index1, index2, index3, HWIO_FMSK(io, field)) >> HWIO_SHFT(io, field))
  143. /** @} */
  144. /**
  145. * @name Output Macros
  146. *
  147. * These macros are used for writing to a named hardware register. Register
  148. * arrays ("indexed") use the macros with the "I" suffix. The "M" suffix
  149. * indicates that the output will be masked with the supplied mask (meaning these
  150. * macros do a read first, mask in the supplied data, then write it back).
  151. * The "X" extension is used for explicit addressing where the base address of
  152. * the module in question is provided as an argument to the macro.
  153. * The HWIO_OUTF* macros take a field name and will do the appropriate masking
  154. * and shifting to output just the value of that field.
  155. * HWIO_OUTV* registers take a named value instead of a numeric value and
  156. * do the same masking/shifting as HWIO_OUTF.
  157. *
  158. * Generally you want to use either HWIO_OUT or HWIO_OUTF (with required indexing).
  159. *
  160. * @{
  161. */
  162. #define HWIO_OUT(hwiosym, val) __msmhwio_out(hwiosym, val)
  163. #define HWIO_OUTI(hwiosym, index, val) __msmhwio_outi(hwiosym, index, val)
  164. #define HWIO_OUTI2(hwiosym, index1, index2, val) __msmhwio_outi2(hwiosym, index1, index2, val)
  165. #define HWIO_OUTI3(hwiosym, index1, index2, index3, val) __msmhwio_outi3(hwiosym, index1, index2, index3, val)
  166. #define HWIO_OUTM(hwiosym, mask, val) __msmhwio_outm(hwiosym, mask, val)
  167. #define HWIO_OUTMI(hwiosym, index, mask, val) __msmhwio_outmi(hwiosym, index, mask, val)
  168. #define HWIO_OUTMI2(hwiosym, index1, index2, mask, val) __msmhwio_outmi2(hwiosym, index1, index2, mask, val)
  169. #define HWIO_OUTMI3(hwiosym, index1, index2, index3, mask, val) __msmhwio_outmi3(hwiosym, index1, index2, index3, mask, val)
  170. #define HWIO_OUTF(io, field, val) HWIO_OUTM(io, HWIO_FMSK(io, field), (uint32)(val) << HWIO_SHFT(io, field))
  171. #define HWIO_OUTFI(io, index, field, val) HWIO_OUTMI(io, index, HWIO_FMSK(io, field), (uint32)(val) << HWIO_SHFT(io, field))
  172. #define HWIO_OUTFI2(io, index1, index2, field, val) HWIO_OUTMI2(io, index1, index2, HWIO_FMSK(io, field), (uint32)(val) << HWIO_SHFT(io, field))
  173. #define HWIO_OUTFI3(io, index1, index2, index3, field, val) HWIO_OUTMI3(io, index1, index2, index3, HWIO_FMSK(io, field), (uint32)(val) << HWIO_SHFT(io, field))
  174. #define HWIO_OUTV(io, field, val) HWIO_OUTM(io, HWIO_FMSK(io, field), (uint32)(HWIO_VAL(io, field, val)) << HWIO_SHFT(io, field))
  175. #define HWIO_OUTVI(io, index, field, val) HWIO_OUTMI(io, index, HWIO_FMSK(io, field), (uint32)(HWIO_VAL(io, field, val)) << HWIO_SHFT(io, field))
  176. #define HWIO_OUTVI2(io, index1, index2, field, val) HWIO_OUTMI2(io, index1, index2, HWIO_FMSK(io, field), (uint32)(HWIO_VAL(io, field, val)) << HWIO_SHFT(io, field))
  177. #define HWIO_OUTVI3(io, index1, index2, index3, field, val) HWIO_OUTMI3(io, index1, index2, index3, HWIO_FMSK(io, field), (uint32)(HWIO_VAL(io, field, val)) << HWIO_SHFT(io, field))
  178. #define HWIO_OUTX(base, hwiosym, val) __msmhwio_outx(base, hwiosym, val)
  179. #define HWIO_OUTXI(base, hwiosym, index, val) __msmhwio_outxi(base, hwiosym, index, val)
  180. #define HWIO_OUTXI2(base, hwiosym, index1, index2, val) __msmhwio_outxi2(base, hwiosym, index1, index2, val)
  181. #define HWIO_OUTXI3(base, hwiosym, index1, index2, index3, val) __msmhwio_outxi3(base, hwiosym, index1, index2, index3, val)
  182. #define HWIO_OUTXM(base, hwiosym, mask, val) __msmhwio_outxm(base, hwiosym, mask, val)
  183. #define HWIO_OUTXM2(base, hwiosym, mask1, mask2, val1, val2) __msmhwio_outxm2(base, hwiosym, mask1, mask2, val1, val2)
  184. #define HWIO_OUTXM3(base, hwiosym, mask1, mask2, mask3, val1, val2, val3) __msmhwio_outxm3(base, hwiosym, mask1, mask2, mask3, val1, val2, val3)
  185. #define HWIO_OUTXM4(base, hwiosym, mask1, mask2, mask3, mask4, val1, val2, val3, val4) __msmhwio_outxm4(base, hwiosym, mask1, mask2, mask3, mask4, val1, val2, val3, val4)
  186. #define HWIO_OUTXMI(base, hwiosym, index, mask, val) __msmhwio_outxmi(base, hwiosym, index, mask, val)
  187. #define HWIO_OUTXMI2(base, hwiosym, index1, index2, mask, val) __msmhwio_outxmi2(base, hwiosym, index1, index2, mask, val)
  188. #define HWIO_OUTXMI3(base, hwiosym, index1, index2, index3, mask, val) __msmhwio_outxmi3(base, hwiosym, index1, index2, index3, mask, val)
  189. #define HWIO_OUTXF(base, io, field, val) HWIO_OUTXM(base, io, HWIO_FMSK(io, field), (uint32)(val) << HWIO_SHFT(io, field))
  190. #define HWIO_OUTX2F(base, io, field1, field2, val1, val2) HWIO_OUTXM2(base, io, HWIO_FMSK(io, field1), HWIO_FMSK(io, field2), (uint32)(val1) << HWIO_SHFT(io, field1), (uint32)(val2) << HWIO_SHFT(io, field2))
  191. #define HWIO_OUTX3F(base, io, field1, field2, field3, val1, val2, val3) HWIO_OUTXM3(base, io, HWIO_FMSK(io, field1), HWIO_FMSK(io, field2), HWIO_FMSK(io, field3),(uint32)(val1) << HWIO_SHFT(io, field1), (uint32)(val2) << HWIO_SHFT(io, field2), (uint32)(val3) << HWIO_SHFT(io, field3) )
  192. #define HWIO_OUTX4F(base, io, field1, field2, field3, field4, val1, val2, val3, val4) HWIO_OUTXM4(base, io, HWIO_FMSK(io, field1), HWIO_FMSK(io, field2), HWIO_FMSK(io, field3), HWIO_FMSK(io, field4), (uint32)(val1) << HWIO_SHFT(io, field1) , (uint32)(val2) << HWIO_SHFT(io, field2), (uint32)(val3) << HWIO_SHFT(io, field3), (uint32)(val4) << HWIO_SHFT(io, field4) )
  193. #define HWIO_OUTXFI(base, io, index, field, val) HWIO_OUTXMI(base, io, index, HWIO_FMSK(io, field), (uint32)(val) << HWIO_SHFT(io, field))
  194. #define HWIO_OUTXFI2(base, io, index1, index2, field, val) HWIO_OUTXMI2(base, io, index1, index2, HWIO_FMSK(io, field), (uint32)(val) << HWIO_SHFT(io, field))
  195. #define HWIO_OUTXFI3(base, io, index1, index2, index3, field, val) HWIO_OUTXMI3(base, io, index1, index2, index3, HWIO_FMSK(io, field), (uint32)(val) << HWIO_SHFT(io, field))
  196. #define HWIO_OUTXV(base, io, field, val) HWIO_OUTXM(base, io, HWIO_FMSK(io, field), (uint32)(HWIO_VAL(io, field, val)) << HWIO_SHFT(io, field))
  197. #define HWIO_OUTXVI(base, io, index, field, val) HWIO_OUTXMI(base, io, index, HWIO_FMSK(io, field), (uint32)(HWIO_VAL(io, field, val)) << HWIO_SHFT(io, field))
  198. #define HWIO_OUTXVI2(base, io, index1, index2, field, val) HWIO_OUTXMI2(base, io, index1, index2, HWIO_FMSK(io, field), (uint32)(HWIO_VAL(io, field, val)) << HWIO_SHFT(io, field))
  199. #define HWIO_OUTXVI3(base, io, index1, index2, index3, field, val) HWIO_OUTXMI3(base, io, index1, index2, index3, HWIO_FMSK(io, field), (uint32)(HWIO_VAL(io, field, val)) << HWIO_SHFT(io, field))
  200. /** @} */
  201. /**
  202. * @name Shift and Mask Macros
  203. *
  204. * Macros for getting shift and mask values for fields and registers.
  205. * HWIO_RMSK: The mask value for accessing an entire register. For example:
  206. * @code
  207. * HWIO_RMSK(REG) -> 0xFFFFFFFF
  208. * @endcode
  209. * HWIO_RSHFT: The right-shift value for an entire register (rarely necessary).\n
  210. * HWIO_SHFT: The right-shift value for accessing a field in a register. For example:
  211. * @code
  212. * HWIO_SHFT(REG, FLD) -> 8
  213. * @endcode
  214. * HWIO_FMSK: The mask value for accessing a field in a register. For example:
  215. * @code
  216. * HWIO_FMSK(REG, FLD) -> 0xFF00
  217. * @endcode
  218. * HWIO_VAL: The value for a field in a register. For example:
  219. * @code
  220. * HWIO_VAL(REG, FLD, ON) -> 0x1
  221. * @endcode
  222. * HWIO_FVAL: This macro takes a numerical value and will shift and mask it into
  223. * the given field position. For example:
  224. * @code
  225. * HWIO_FVAL(REG, FLD, 0x1) -> 0x100
  226. * @endcode
  227. * HWIO_FVALV: This macro takes a logical (named) value and will shift and mask it
  228. * into the given field position. For example:
  229. * @code
  230. * HWIO_FVALV(REG, FLD, ON) -> 0x100
  231. * @endcode
  232. *
  233. * @{
  234. */
  235. #define HWIO_RMSK(hwiosym) __msmhwio_rmsk(hwiosym)
  236. #define HWIO_RMSKI(hwiosym, index) __msmhwio_rmski(hwiosym, index)
  237. #define HWIO_RSHFT(hwiosym) __msmhwio_rshft(hwiosym)
  238. #define HWIO_SHFT(hwio_regsym, hwio_fldsym) __msmhwio_shft(hwio_regsym, hwio_fldsym)
  239. #define HWIO_FMSK(hwio_regsym, hwio_fldsym) __msmhwio_fmsk(hwio_regsym, hwio_fldsym)
  240. #define HWIO_VAL(io, field, val) __msmhwio_val(io, field, val)
  241. #define HWIO_FVAL(io, field, val) (((uint32)(val) << HWIO_SHFT(io, field)) & HWIO_FMSK(io, field))
  242. #define HWIO_FVALV(io, field, val) (((uint32)(HWIO_VAL(io, field, val)) << HWIO_SHFT(io, field)) & HWIO_FMSK(io, field))
  243. /** @} */
  244. /**
  245. * @name Shadow Register Macros
  246. *
  247. * These macros are used for directly reading the value stored in a
  248. * shadow register.
  249. * Shadow registers are defined for write-only registers. Generally these
  250. * macros should not be necessary as HWIO_OUTM* macros will automatically use
  251. * the shadow values internally.
  252. *
  253. * @{
  254. */
  255. #define HWIO_SHDW(hwiosym) __msmhwio_shdw(hwiosym)
  256. #define HWIO_SHDWI(hwiosym, index) __msmhwio_shdwi(hwiosym, index)
  257. /** @} */
  258. /**
  259. @}
  260. */ /* end_group */
  261. /** @cond */
  262. /*
  263. * Map to final symbols. This remapping is done to allow register
  264. * redefinitions. If we just define HWIO_IN(xreg) as HWIO_##xreg##_IN
  265. * then remappings like "#define xreg xregnew" do not work as expected.
  266. */
  267. #define __msmhwio_in(hwiosym) HWIO_##hwiosym##_IN
  268. #define __msmhwio_ini(hwiosym, index) HWIO_##hwiosym##_INI(index)
  269. #define __msmhwio_ini2(hwiosym, index1, index2) HWIO_##hwiosym##_INI2(index1, index2)
  270. #define __msmhwio_ini3(hwiosym, index1, index2, index3) HWIO_##hwiosym##_INI3(index1, index2, index3)
  271. #define __msmhwio_inm(hwiosym, mask) HWIO_##hwiosym##_INM(mask)
  272. #define __msmhwio_inmi(hwiosym, index, mask) HWIO_##hwiosym##_INMI(index, mask)
  273. #define __msmhwio_inmi2(hwiosym, index1, index2, mask) HWIO_##hwiosym##_INMI2(index1, index2, mask)
  274. #define __msmhwio_inmi3(hwiosym, index1, index2, index3, mask) HWIO_##hwiosym##_INMI3(index1, index2, index3, mask)
  275. #define __msmhwio_out(hwiosym, val) HWIO_##hwiosym##_OUT(val)
  276. #define __msmhwio_outi(hwiosym, index, val) HWIO_##hwiosym##_OUTI(index,val)
  277. #define __msmhwio_outi2(hwiosym, index1, index2, val) HWIO_##hwiosym##_OUTI2(index1, index2, val)
  278. #define __msmhwio_outi3(hwiosym, index1, index2, index3, val) HWIO_##hwiosym##_OUTI2(index1, index2, index3, val)
  279. #define __msmhwio_outm(hwiosym, mask, val) HWIO_##hwiosym##_OUTM(mask, val)
  280. #define __msmhwio_outmi(hwiosym, index, mask, val) HWIO_##hwiosym##_OUTMI(index, mask, val)
  281. #define __msmhwio_outmi2(hwiosym, idx1, idx2, mask, val) HWIO_##hwiosym##_OUTMI2(idx1, idx2, mask, val)
  282. #define __msmhwio_outmi3(hwiosym, idx1, idx2, idx3, mask, val) HWIO_##hwiosym##_OUTMI3(idx1, idx2, idx3, mask, val)
  283. #define __msmhwio_addr(hwiosym) HWIO_##hwiosym##_ADDR
  284. #define __msmhwio_addri(hwiosym, index) HWIO_##hwiosym##_ADDR(index)
  285. #define __msmhwio_addri2(hwiosym, idx1, idx2) HWIO_##hwiosym##_ADDR(idx1, idx2)
  286. #define __msmhwio_addri3(hwiosym, idx1, idx2, idx3) HWIO_##hwiosym##_ADDR(idx1, idx2, idx3)
  287. #define __msmhwio_phys(hwiosym) HWIO_##hwiosym##_PHYS
  288. #define __msmhwio_physi(hwiosym, index) HWIO_##hwiosym##_PHYS(index)
  289. #define __msmhwio_physi2(hwiosym, idx1, idx2) HWIO_##hwiosym##_PHYS(idx1, idx2)
  290. #define __msmhwio_physi3(hwiosym, idx1, idx2, idx3) HWIO_##hwiosym##_PHYS(idx1, idx2, idx3)
  291. #define __msmhwio_offs(hwiosym) HWIO_##hwiosym##_OFFS
  292. #define __msmhwio_offsi(hwiosym, index) HWIO_##hwiosym##_OFFS(index)
  293. #define __msmhwio_offsi2(hwiosym, idx1, idx2) HWIO_##hwiosym##_OFFS(idx1, idx2)
  294. #define __msmhwio_offsi3(hwiosym, idx1, idx2, idx3) HWIO_##hwiosym##_OFFS(idx1, idx2, idx3)
  295. #define __msmhwio_rmsk(hwiosym) HWIO_##hwiosym##_RMSK
  296. #define __msmhwio_rmski(hwiosym, index) HWIO_##hwiosym##_RMSK(index)
  297. #define __msmhwio_fmsk(hwiosym, hwiofldsym) HWIO_##hwiosym##_##hwiofldsym##_BMSK
  298. #define __msmhwio_rshft(hwiosym) HWIO_##hwiosym##_SHFT
  299. #define __msmhwio_shft(hwiosym, hwiofldsym) HWIO_##hwiosym##_##hwiofldsym##_SHFT
  300. #define __msmhwio_shdw(hwiosym) HWIO_##hwiosym##_shadow
  301. #define __msmhwio_shdwi(hwiosym, index) HWIO_##hwiosym##_SHDW(index)
  302. #define __msmhwio_val(hwiosym, hwiofld, hwioval) HWIO_##hwiosym##_##hwiofld##_##hwioval##_FVAL
  303. #define __msmhwio_inx(base, hwiosym) HWIO_##hwiosym##_IN(base)
  304. #define __msmhwio_inxi(base, hwiosym, index) HWIO_##hwiosym##_INI(base, index)
  305. #define __msmhwio_inxi2(base, hwiosym, index1, index2) HWIO_##hwiosym##_INI2(base, index1, index2)
  306. #define __msmhwio_inxi3(base, hwiosym, index1, index2, index3) HWIO_##hwiosym##_INI3(base, index1, index2, index3)
  307. #define __msmhwio_inxm(base, hwiosym, mask) HWIO_##hwiosym##_INM(base, mask)
  308. #define __msmhwio_inxmi(base, hwiosym, index, mask) HWIO_##hwiosym##_INMI(base, index, mask)
  309. #define __msmhwio_inxmi2(base, hwiosym, index1, index2, mask) HWIO_##hwiosym##_INMI2(base, index1, index2, mask)
  310. #define __msmhwio_inxmi3(base, hwiosym, index1, index2, index3, mask) HWIO_##hwiosym##_INMI3(base, index1, index2, index3, mask)
  311. #define __msmhwio_outx(base, hwiosym, val) HWIO_##hwiosym##_OUT(base, val)
  312. #define __msmhwio_outxi(base, hwiosym, index, val) HWIO_##hwiosym##_OUTI(base, index,val)
  313. #define __msmhwio_outxi2(base, hwiosym, index1, index2, val) HWIO_##hwiosym##_OUTI2(base, index1, index2, val)
  314. #define __msmhwio_outxi3(base, hwiosym, index1, index2, index3, val) HWIO_##hwiosym##_OUTI2(base, index1, index2, index3, val)
  315. #define __msmhwio_outxm(base, hwiosym, mask, val) HWIO_##hwiosym##_OUTM(base, mask, val)
  316. #define __msmhwio_outxm2(base, hwiosym, mask1, mask2, val1, val2) { \
  317. HWIO_##hwiosym##_OUTM(base, mask1, val1); \
  318. HWIO_##hwiosym##_OUTM(base, mask2, val2); \
  319. }
  320. #define __msmhwio_outxm3(base, hwiosym, mask1, mask2, mask3, val1, val2, val3) { \
  321. HWIO_##hwiosym##_OUTM(base, mask1, val1); \
  322. HWIO_##hwiosym##_OUTM(base, mask2, val2); \
  323. HWIO_##hwiosym##_OUTM(base, mask3, val3); \
  324. }
  325. #define __msmhwio_outxm4(base, hwiosym, mask1, mask2, mask3, mask4, val1, val2, val3, val4) { \
  326. HWIO_##hwiosym##_OUTM(base, mask1, val1); \
  327. HWIO_##hwiosym##_OUTM(base, mask2, val2); \
  328. HWIO_##hwiosym##_OUTM(base, mask3, val3); \
  329. HWIO_##hwiosym##_OUTM(base, mask4, val4); \
  330. }
  331. #define __msmhwio_outxmi(base, hwiosym, index, mask, val) HWIO_##hwiosym##_OUTMI(base, index, mask, val)
  332. #define __msmhwio_outxmi2(base, hwiosym, idx1, idx2, mask, val) HWIO_##hwiosym##_OUTMI2(base, idx1, idx2, mask, val)
  333. #define __msmhwio_outxmi3(base, hwiosym, idx1, idx2, idx3, mask, val) HWIO_##hwiosym##_OUTMI3(base, idx1, idx2, idx3, mask, val)
  334. #define __msmhwio_addrx(base, hwiosym) HWIO_##hwiosym##_ADDR(base)
  335. #define __msmhwio_addrxi(base, hwiosym, index) HWIO_##hwiosym##_ADDR(base, index)
  336. #define __msmhwio_addrxi2(base, hwiosym, idx1, idx2) HWIO_##hwiosym##_ADDR(base, idx1, idx2)
  337. #define __msmhwio_addrxi3(base, hwiosym, idx1, idx2, idx3) HWIO_##hwiosym##_ADDR(base, idx1, idx2, idx3)
  338. #define __msmhwio_physx(base, hwiosym) HWIO_##hwiosym##_PHYS(base)
  339. #define __msmhwio_physxi(base, hwiosym, index) HWIO_##hwiosym##_PHYS(base, index)
  340. #define __msmhwio_physxi2(base, hwiosym, idx1, idx2) HWIO_##hwiosym##_PHYS(base, idx1, idx2)
  341. #define __msmhwio_physxi3(base, hwiosym, idx1, idx2, idx3) HWIO_##hwiosym##_PHYS(base, idx1, idx2, idx3)
  342. /*
  343. * HWIO_INTLOCK
  344. *
  345. * Macro used by autogenerated code for mutual exclusion around
  346. * read-mask-write operations. This is not supported in HAL
  347. * code but can be overridden by non-HAL code.
  348. */
  349. #define HWIO_INTLOCK()
  350. #define HWIO_INTFREE()
  351. #if defined(VISUAL_STUDIO) || defined(TEST_FRAMEWORK)
  352. extern unsigned int registerRead(unsigned int port);
  353. extern void registerWrite(unsigned int port, unsigned int val);
  354. #define __inp(port) registerRead(port)
  355. #define __inpw(port) registerRead(port)
  356. #define __inpdw(port) registerRead(port)
  357. #define __outp(port, val) registerWrite(port, val)
  358. #define __outpw(port, val) registerWrite(port, val)
  359. #define __outpdw(port, val) registerWrite(port, val)
  360. #else
  361. #if defined(CONFIG_SIMHW)
  362. extern unsigned char * simhw_get_mac_addr(void);
  363. extern uint8 __sim_inp(uint32 addr);
  364. extern uint16 __sim_inpw(uint32 addr);
  365. extern uint32 __sim_inpdw(uint32 addr);
  366. extern void __sim_outp(uint32 addr, uint8 data);
  367. extern void __sim_outpw(uint32 addr, uint16 data);
  368. extern void __sim_outpdw(uint32 addr, uint32 data);
  369. #define __inp(port) __sim_inp((unsigned int)port)
  370. #define __inpw(port) __sim_inpw((unsigned int)port)
  371. #define __inpdw(port) __sim_inpdw((unsigned int)port)
  372. #define __outp(port, val) __sim_outp((unsigned int)port, val)
  373. #define __outpw(port, val) __sim_outpw((unsigned int)port, val)
  374. #define __outpdw(port, val) __sim_outpdw((unsigned int)port, val)
  375. #define registerRead(port) __sim_inpdw(port)
  376. #define registerWrite(port, val) __sim_outpdw(port, val)
  377. #else // CONFIG_SIMHW
  378. #ifdef FPGA
  379. #define MAC_ADDRESS_POWER_CHECK
  380. #else
  381. #undef MAC_ADDRESS_POWER_CHECK
  382. #endif
  383. #ifdef MAC_ADDRESS_POWER_CHECK
  384. extern void whal_pwr_debug_register_address_check(uint32 addr, int is_write);
  385. #endif
  386. /*
  387. * Input/output port macros for memory mapped IO.
  388. */
  389. #define __inp(port) (*((volatile uint8 *) ((uint32)(port))))
  390. #define __inpw(port) (*((volatile uint16 *) ((uint32)(port))))
  391. #ifdef MAC_ADDRESS_POWER_CHECK
  392. static inline uint32 __inpdw(uint32 port){
  393. whal_pwr_debug_register_address_check(port, FALSE);
  394. return (*((volatile uint32 *) (port)));
  395. }
  396. #else
  397. #define __inpdw(port) (*((volatile uint32 *) ((uint32)(port))))
  398. #endif
  399. extern void busywait(uint32 pause_time_us);
  400. #define __outp(port, val) (*((volatile uint8 *) ((uint32)(port))) = ((uint8) (val)))
  401. #define __outpw(port, val) (*((volatile uint16 *) ((uint32)(port))) = ((uint16) (val)))
  402. #ifdef MAC_ADDRESS_POWER_CHECK
  403. static inline void __outpdw(uint32 port ,uint32 val){
  404. whal_pwr_debug_register_address_check(port, TRUE);
  405. (*((volatile uint32 *) (port)) = ((uint32) (val)));
  406. }
  407. #else
  408. static inline void __outpdw(uint32 port ,uint32 val){
  409. (*((volatile uint32 *) (port)) = ((uint32) (val)));
  410. busywait(1);
  411. }
  412. #endif
  413. #define registerRead(port) (*((volatile uint32 *) ((uint32)(port) )))
  414. #define registerWrite(port, val) (*((volatile uint32 *) ((uint32)(port) )) = ((uint32) (val)))
  415. #endif // CONFIG_SIMHW
  416. #endif
  417. #ifdef HAL_HWIO_EXTERNAL
  418. /*
  419. * Replace macros with externally supplied functions.
  420. */
  421. #undef __inp
  422. #undef __inpw
  423. #undef __inpdw
  424. #undef __outp
  425. #undef __outpw
  426. #undef __outpdw
  427. #define __inp(port) __inp_extern(port)
  428. #define __inpw(port) __inpw_extern(port)
  429. #define __inpdw(port) __inpdw_extern(port)
  430. #define __outp(port, val) __outp_extern(port, val)
  431. #define __outpw(port, val) __outpw_extern(port, val)
  432. #define __outpdw(port, val) __outpdw_extern(port, val)
  433. extern uint8 __inp_extern ( uint32 nAddr );
  434. extern uint16 __inpw_extern ( uint32 nAddr );
  435. extern uint32 __inpdw_extern ( uint32 nAddr );
  436. extern void __outp_extern ( uint32 nAddr, uint8 nData );
  437. extern void __outpw_extern ( uint32 nAddr, uint16 nData );
  438. extern void __outpdw_extern ( uint32 nAddr, uint32 nData );
  439. #endif /* HAL_HWIO_EXTERNAL */
  440. /*
  441. * Base 8-bit byte accessing macros.
  442. */
  443. #define in_byte(addr) (__inp(addr))
  444. #define in_byte_masked(addr, mask) (__inp(addr) & (mask))
  445. #define out_byte(addr, val) __outp(addr,val)
  446. #define out_byte_masked(io, mask, val, shadow) \
  447. HWIO_INTLOCK(); \
  448. out_byte( io, shadow); \
  449. shadow = (shadow & (uint16)(~(mask))) | ((uint16)((val) & (mask))); \
  450. HWIO_INTFREE()
  451. #define out_byte_masked_ns(io, mask, val, current_reg_content) \
  452. out_byte( io, ((current_reg_content & (uint16)(~(mask))) | \
  453. ((uint16)((val) & (mask)))) )
  454. /*
  455. * Base 16-bit word accessing macros.
  456. */
  457. #define in_word(addr) (__inpw(addr))
  458. #define in_word_masked(addr, mask) (__inpw(addr) & (mask))
  459. #define out_word(addr, val) __outpw(addr,val)
  460. #define out_word_masked(io, mask, val, shadow) \
  461. HWIO_INTLOCK( ); \
  462. shadow = (shadow & (uint16)(~(mask))) | ((uint16)((val) & (mask))); \
  463. out_word( io, shadow); \
  464. HWIO_INTFREE( )
  465. #define out_word_masked_ns(io, mask, val, current_reg_content) \
  466. out_word( io, ((current_reg_content & (uint16)(~(mask))) | \
  467. ((uint16)((val) & (mask)))) )
  468. /*
  469. * Base 32-bit double-word accessing macros.
  470. */
  471. #ifdef MAC_ADDRESS_POWER_CHECK
  472. #define in_dword(addr) (__inpdw((uint32)addr))
  473. #define in_dword_masked(addr, mask) (__inpdw((uint32)addr) & (mask))
  474. #define out_dword(addr, val) __outpdw((uint32)addr,val)
  475. #else
  476. #define in_dword(addr) (__inpdw(addr))
  477. #define in_dword_masked(addr, mask) (__inpdw(addr) & (mask))
  478. #define out_dword(addr, val) __outpdw((uint32)addr,val)
  479. #endif
  480. #define out_dword_masked(io, mask, val, shadow) \
  481. HWIO_INTLOCK(); \
  482. shadow = (shadow & (uint32)(~(mask))) | ((uint32)((val) & (mask))); \
  483. out_dword( io, shadow); \
  484. HWIO_INTFREE()
  485. #define out_dword_masked_ns(io, mask, val, current_reg_content) \
  486. out_dword( io, ((current_reg_content & (uint32)(~(mask))) | \
  487. ((uint32)((val) & (mask)))) )
  488. #define out_dword_masked_ns_shift(io, mask, val, current_reg_content, shift) \
  489. out_dword( io, ((current_reg_content & (uint32)(~(mask))) | \
  490. (((uint32)((val) & (mask))) << shift )) )
  491. /** @endcond */
  492. #endif /* HAL_HWIO_H */