bam.c 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122
  1. /* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. /* Bus-Access-Manager (BAM) Hardware manager. */
  13. #include <linux/types.h> /* u32 */
  14. #include <linux/kernel.h> /* pr_info() */
  15. #include <linux/io.h> /* ioread32() */
  16. #include <linux/bitops.h> /* find_first_bit() */
  17. #include <linux/errno.h> /* ENODEV */
  18. #include <linux/memory.h>
  19. #include "bam.h"
  20. #include "sps_bam.h"
  21. /**
  22. * Valid BAM Hardware version.
  23. *
  24. */
  25. #define BAM_MIN_VERSION 2
  26. #define BAM_MAX_VERSION 0x2f
  27. #ifdef CONFIG_SPS_SUPPORT_NDP_BAM
  28. /* Maximum number of execution environment */
  29. #define BAM_MAX_EES 8
  30. /**
  31. * BAM Hardware registers bitmask.
  32. * format: <register>_<field>
  33. *
  34. */
  35. /* CTRL */
  36. #define BAM_MESS_ONLY_CANCEL_WB 0x100000
  37. #define CACHE_MISS_ERR_RESP_EN 0x80000
  38. #define LOCAL_CLK_GATING 0x60000
  39. #define IBC_DISABLE 0x10000
  40. #define BAM_CACHED_DESC_STORE 0x8000
  41. #define BAM_DESC_CACHE_SEL 0x6000
  42. #define BAM_EN_ACCUM 0x10
  43. #define BAM_EN 0x2
  44. #define BAM_SW_RST 0x1
  45. /* REVISION */
  46. #define BAM_INACTIV_TMR_BASE 0xff000000
  47. #define BAM_CMD_DESC_EN 0x800000
  48. #define BAM_DESC_CACHE_DEPTH 0x600000
  49. #define BAM_NUM_INACTIV_TMRS 0x100000
  50. #define BAM_INACTIV_TMRS_EXST 0x80000
  51. #define BAM_HIGH_FREQUENCY_BAM 0x40000
  52. #define BAM_HAS_NO_BYPASS 0x20000
  53. #define BAM_SECURED 0x10000
  54. #define BAM_USE_VMIDMT 0x8000
  55. #define BAM_AXI_ACTIVE 0x4000
  56. #define BAM_CE_BUFFER_SIZE 0x3000
  57. #define BAM_NUM_EES 0xf00
  58. #define BAM_REVISION 0xff
  59. /* SW_REVISION */
  60. #define BAM_MAJOR 0xf0000000
  61. #define BAM_MINOR 0xfff0000
  62. #define BAM_STEP 0xffff
  63. /* NUM_PIPES */
  64. #define BAM_NON_PIPE_GRP 0xff000000
  65. #define BAM_PERIPH_NON_PIPE_GRP 0xff0000
  66. #define BAM_DATA_ADDR_BUS_WIDTH 0xC000
  67. #define BAM_NUM_PIPES 0xff
  68. /* TIMER */
  69. #define BAM_TIMER 0xffff
  70. /* TIMER_CTRL */
  71. #define TIMER_RST 0x80000000
  72. #define TIMER_RUN 0x40000000
  73. #define TIMER_MODE 0x20000000
  74. #define TIMER_TRSHLD 0xffff
  75. /* DESC_CNT_TRSHLD */
  76. #define BAM_DESC_CNT_TRSHLD 0xffff
  77. /* IRQ_SRCS */
  78. #define BAM_IRQ 0x80000000
  79. #define P_IRQ 0x7fffffff
  80. /* IRQ_STTS */
  81. #define IRQ_STTS_BAM_TIMER_IRQ 0x10
  82. #define IRQ_STTS_BAM_EMPTY_IRQ 0x8
  83. #define IRQ_STTS_BAM_ERROR_IRQ 0x4
  84. #define IRQ_STTS_BAM_HRESP_ERR_IRQ 0x2
  85. /* IRQ_CLR */
  86. #define IRQ_CLR_BAM_TIMER_IRQ 0x10
  87. #define IRQ_CLR_BAM_EMPTY_CLR 0x8
  88. #define IRQ_CLR_BAM_ERROR_CLR 0x4
  89. #define IRQ_CLR_BAM_HRESP_ERR_CLR 0x2
  90. /* IRQ_EN */
  91. #define IRQ_EN_BAM_TIMER_IRQ 0x10
  92. #define IRQ_EN_BAM_EMPTY_EN 0x8
  93. #define IRQ_EN_BAM_ERROR_EN 0x4
  94. #define IRQ_EN_BAM_HRESP_ERR_EN 0x2
  95. /* AHB_MASTER_ERR_CTRLS */
  96. #define AHB_MASTER_ERR_CTRLS_BAM_ERR_HVMID 0x7c0000
  97. #define AHB_MASTER_ERR_CTRLS_BAM_ERR_DIRECT_MODE 0x20000
  98. #define AHB_MASTER_ERR_CTRLS_BAM_ERR_HCID 0x1f000
  99. #define AHB_MASTER_ERR_CTRLS_BAM_ERR_HPROT 0xf00
  100. #define AHB_MASTER_ERR_CTRLS_BAM_ERR_HBURST 0xe0
  101. #define AHB_MASTER_ERR_CTRLS_BAM_ERR_HSIZE 0x18
  102. #define AHB_MASTER_ERR_CTRLS_BAM_ERR_HWRITE 0x4
  103. #define AHB_MASTER_ERR_CTRLS_BAM_ERR_HTRANS 0x3
  104. /* TRUST_REG */
  105. #define LOCK_EE_CTRL 0x2000
  106. #define BAM_VMID 0x1f00
  107. #define BAM_RST_BLOCK 0x80
  108. #define BAM_EE 0x7
  109. /* TEST_BUS_SEL */
  110. #define BAM_SW_EVENTS_ZERO 0x200000
  111. #define BAM_SW_EVENTS_SEL 0x180000
  112. #define BAM_DATA_ERASE 0x40000
  113. #define BAM_DATA_FLUSH 0x20000
  114. #define BAM_CLK_ALWAYS_ON 0x10000
  115. #define BAM_TESTBUS_SEL 0x7f
  116. /* CNFG_BITS */
  117. #define CNFG_BITS_AOS_OVERFLOW_PRVNT 0x80000000
  118. #define CNFG_BITS_MULTIPLE_EVENTS_DESC_AVAIL_EN 0x40000000
  119. #define CNFG_BITS_MULTIPLE_EVENTS_SIZE_EN 0x20000000
  120. #define CNFG_BITS_BAM_ZLT_W_CD_SUPPORT 0x10000000
  121. #define CNFG_BITS_BAM_CD_ENABLE 0x8000000
  122. #define CNFG_BITS_BAM_AU_ACCUMED 0x4000000
  123. #define CNFG_BITS_BAM_PSM_P_HD_DATA 0x2000000
  124. #define CNFG_BITS_BAM_REG_P_EN 0x1000000
  125. #define CNFG_BITS_BAM_WB_DSC_AVL_P_RST 0x800000
  126. #define CNFG_BITS_BAM_WB_RETR_SVPNT 0x400000
  127. #define CNFG_BITS_BAM_WB_CSW_ACK_IDL 0x200000
  128. #define CNFG_BITS_BAM_WB_BLK_CSW 0x100000
  129. #define CNFG_BITS_BAM_WB_P_RES 0x80000
  130. #define CNFG_BITS_BAM_SI_P_RES 0x40000
  131. #define CNFG_BITS_BAM_AU_P_RES 0x20000
  132. #define CNFG_BITS_BAM_PSM_P_RES 0x10000
  133. #define CNFG_BITS_BAM_PSM_CSW_REQ 0x8000
  134. #define CNFG_BITS_BAM_SB_CLK_REQ 0x4000
  135. #define CNFG_BITS_BAM_IBC_DISABLE 0x2000
  136. #define CNFG_BITS_BAM_NO_EXT_P_RST 0x1000
  137. #define CNFG_BITS_BAM_FULL_PIPE 0x800
  138. #define CNFG_BITS_BAM_PIPE_CNFG 0x4
  139. /* PIPE_ATTR_EEn*/
  140. #define BAM_ENABLED 0x80000000
  141. #define P_ATTR 0x7fffffff
  142. /* P_ctrln */
  143. #define P_LOCK_GROUP 0x1f0000
  144. #define P_WRITE_NWD 0x800
  145. #define P_PREFETCH_LIMIT 0x600
  146. #define P_AUTO_EOB_SEL 0x180
  147. #define P_AUTO_EOB 0x40
  148. #define P_SYS_MODE 0x20
  149. #define P_SYS_STRM 0x10
  150. #define P_DIRECTION 0x8
  151. #define P_EN 0x2
  152. /* P_RSTn */
  153. #define P_RST_P_SW_RST 0x1
  154. /* P_HALTn */
  155. #define P_HALT_P_PROD_HALTED 0x2
  156. #define P_HALT_P_HALT 0x1
  157. /* P_TRUST_REGn */
  158. #define BAM_P_VMID 0x1f00
  159. #define BAM_P_SUP_GROUP 0xf8
  160. #define BAM_P_EE 0x7
  161. /* P_IRQ_STTSn */
  162. #define P_IRQ_STTS_P_HRESP_ERR_IRQ 0x80
  163. #define P_IRQ_STTS_P_PIPE_RST_ERR_IRQ 0x40
  164. #define P_IRQ_STTS_P_TRNSFR_END_IRQ 0x20
  165. #define P_IRQ_STTS_P_ERR_IRQ 0x10
  166. #define P_IRQ_STTS_P_OUT_OF_DESC_IRQ 0x8
  167. #define P_IRQ_STTS_P_WAKE_IRQ 0x4
  168. #define P_IRQ_STTS_P_TIMER_IRQ 0x2
  169. #define P_IRQ_STTS_P_PRCSD_DESC_IRQ 0x1
  170. /* P_IRQ_CLRn */
  171. #define P_IRQ_CLR_P_HRESP_ERR_CLR 0x80
  172. #define P_IRQ_CLR_P_PIPE_RST_ERR_CLR 0x40
  173. #define P_IRQ_CLR_P_TRNSFR_END_CLR 0x20
  174. #define P_IRQ_CLR_P_ERR_CLR 0x10
  175. #define P_IRQ_CLR_P_OUT_OF_DESC_CLR 0x8
  176. #define P_IRQ_CLR_P_WAKE_CLR 0x4
  177. #define P_IRQ_CLR_P_TIMER_CLR 0x2
  178. #define P_IRQ_CLR_P_PRCSD_DESC_CLR 0x1
  179. /* P_IRQ_ENn */
  180. #define P_IRQ_EN_P_HRESP_ERR_EN 0x80
  181. #define P_IRQ_EN_P_PIPE_RST_ERR_EN 0x40
  182. #define P_IRQ_EN_P_TRNSFR_END_EN 0x20
  183. #define P_IRQ_EN_P_ERR_EN 0x10
  184. #define P_IRQ_EN_P_OUT_OF_DESC_EN 0x8
  185. #define P_IRQ_EN_P_WAKE_EN 0x4
  186. #define P_IRQ_EN_P_TIMER_EN 0x2
  187. #define P_IRQ_EN_P_PRCSD_DESC_EN 0x1
  188. /* P_TIMERn */
  189. #define P_TIMER_P_TIMER 0xffff
  190. /* P_TIMER_ctrln */
  191. #define P_TIMER_RST 0x80000000
  192. #define P_TIMER_RUN 0x40000000
  193. #define P_TIMER_MODE 0x20000000
  194. #define P_TIMER_TRSHLD 0xffff
  195. /* P_PRDCR_SDBNDn */
  196. #define P_PRDCR_SDBNDn_BAM_P_SB_UPDATED 0x1000000
  197. #define P_PRDCR_SDBNDn_BAM_P_TOGGLE 0x100000
  198. #define P_PRDCR_SDBNDn_BAM_P_CTRL 0xf0000
  199. #define P_PRDCR_SDBNDn_BAM_P_BYTES_FREE 0xffff
  200. /* P_CNSMR_SDBNDn */
  201. #define P_CNSMR_SDBNDn_BAM_P_SB_UPDATED 0x1000000
  202. #define P_CNSMR_SDBNDn_BAM_P_WAIT_4_ACK 0x800000
  203. #define P_CNSMR_SDBNDn_BAM_P_ACK_TOGGLE 0x400000
  204. #define P_CNSMR_SDBNDn_BAM_P_ACK_TOGGLE_R 0x200000
  205. #define P_CNSMR_SDBNDn_BAM_P_TOGGLE 0x100000
  206. #define P_CNSMR_SDBNDn_BAM_P_CTRL 0xf0000
  207. #define P_CNSMR_SDBNDn_BAM_P_BYTES_AVAIL 0xffff
  208. /* P_EVNT_regn */
  209. #define P_BYTES_CONSUMED 0xffff0000
  210. #define P_DESC_FIFO_PEER_OFST 0xffff
  211. /* P_SW_ofstsn */
  212. #define SW_OFST_IN_DESC 0xffff0000
  213. #define SW_DESC_OFST 0xffff
  214. /* P_EVNT_GEN_TRSHLDn */
  215. #define P_EVNT_GEN_TRSHLD_P_TRSHLD 0xffff
  216. /* P_FIFO_sizesn */
  217. #define P_DATA_FIFO_SIZE 0xffff0000
  218. #define P_DESC_FIFO_SIZE 0xffff
  219. #define P_RETR_CNTXT_RETR_DESC_OFST 0xffff0000
  220. #define P_RETR_CNTXT_RETR_OFST_IN_DESC 0xffff
  221. #define P_SI_CNTXT_SI_DESC_OFST 0xffff
  222. #define P_DF_CNTXT_WB_ACCUMULATED 0xffff0000
  223. #define P_DF_CNTXT_DF_DESC_OFST 0xffff
  224. #define P_AU_PSM_CNTXT_1_AU_PSM_ACCUMED 0xffff0000
  225. #define P_AU_PSM_CNTXT_1_AU_ACKED 0xffff
  226. #define P_PSM_CNTXT_2_PSM_DESC_VALID 0x80000000
  227. #define P_PSM_CNTXT_2_PSM_DESC_IRQ 0x40000000
  228. #define P_PSM_CNTXT_2_PSM_DESC_IRQ_DONE 0x20000000
  229. #define P_PSM_CNTXT_2_PSM_GENERAL_BITS 0x1e000000
  230. #define P_PSM_CNTXT_2_PSM_CONS_STATE 0x1c00000
  231. #define P_PSM_CNTXT_2_PSM_PROD_SYS_STATE 0x380000
  232. #define P_PSM_CNTXT_2_PSM_PROD_B2B_STATE 0x70000
  233. #define P_PSM_CNTXT_2_PSM_DESC_SIZE 0xffff
  234. #define P_PSM_CNTXT_4_PSM_DESC_OFST 0xffff0000
  235. #define P_PSM_CNTXT_4_PSM_SAVED_ACCUMED_SIZE 0xffff
  236. #define P_PSM_CNTXT_5_PSM_BLOCK_BYTE_CNT 0xffff0000
  237. #define P_PSM_CNTXT_5_PSM_OFST_IN_DESC 0xffff
  238. #else
  239. /* Maximum number of execution environment */
  240. #define BAM_MAX_EES 4
  241. /**
  242. * BAM Hardware registers bitmask.
  243. * format: <register>_<field>
  244. *
  245. */
  246. /* CTRL */
  247. #define IBC_DISABLE 0x10000
  248. #define BAM_CACHED_DESC_STORE 0x8000
  249. #define BAM_DESC_CACHE_SEL 0x6000
  250. /* BAM_PERIPH_IRQ_SIC_SEL is an obsolete field; This bit is reserved now */
  251. #define BAM_PERIPH_IRQ_SIC_SEL 0x1000
  252. #define BAM_EN_ACCUM 0x10
  253. #define BAM_EN 0x2
  254. #define BAM_SW_RST 0x1
  255. /* REVISION */
  256. #define BAM_INACTIV_TMR_BASE 0xff000000
  257. #define BAM_INACTIV_TMRS_EXST 0x80000
  258. #define BAM_HIGH_FREQUENCY_BAM 0x40000
  259. #define BAM_HAS_NO_BYPASS 0x20000
  260. #define BAM_SECURED 0x10000
  261. #define BAM_NUM_EES 0xf00
  262. #define BAM_REVISION 0xff
  263. /* NUM_PIPES */
  264. #define BAM_NON_PIPE_GRP 0xff000000
  265. #define BAM_PERIPH_NON_PIPE_GRP 0xff0000
  266. #define BAM_DATA_ADDR_BUS_WIDTH 0xC000
  267. #define BAM_NUM_PIPES 0xff
  268. /* DESC_CNT_TRSHLD */
  269. #define BAM_DESC_CNT_TRSHLD 0xffff
  270. /* IRQ_SRCS */
  271. #define BAM_IRQ 0x80000000
  272. #define P_IRQ 0x7fffffff
  273. #define IRQ_STTS_BAM_EMPTY_IRQ 0x8
  274. #define IRQ_STTS_BAM_ERROR_IRQ 0x4
  275. #define IRQ_STTS_BAM_HRESP_ERR_IRQ 0x2
  276. #define IRQ_CLR_BAM_EMPTY_CLR 0x8
  277. #define IRQ_CLR_BAM_ERROR_CLR 0x4
  278. #define IRQ_CLR_BAM_HRESP_ERR_CLR 0x2
  279. #define IRQ_EN_BAM_EMPTY_EN 0x8
  280. #define IRQ_EN_BAM_ERROR_EN 0x4
  281. #define IRQ_EN_BAM_HRESP_ERR_EN 0x2
  282. #define IRQ_SIC_SEL_BAM_IRQ_SIC_SEL 0x80000000
  283. #define IRQ_SIC_SEL_P_IRQ_SIC_SEL 0x7fffffff
  284. #define AHB_MASTER_ERR_CTRLS_BAM_ERR_HVMID 0x7c0000
  285. #define AHB_MASTER_ERR_CTRLS_BAM_ERR_DIRECT_MODE 0x20000
  286. #define AHB_MASTER_ERR_CTRLS_BAM_ERR_HCID 0x1f000
  287. #define AHB_MASTER_ERR_CTRLS_BAM_ERR_HPROT 0xf00
  288. #define AHB_MASTER_ERR_CTRLS_BAM_ERR_HBURST 0xe0
  289. #define AHB_MASTER_ERR_CTRLS_BAM_ERR_HSIZE 0x18
  290. #define AHB_MASTER_ERR_CTRLS_BAM_ERR_HWRITE 0x4
  291. #define AHB_MASTER_ERR_CTRLS_BAM_ERR_HTRANS 0x3
  292. #define CNFG_BITS_BAM_AU_ACCUMED 0x4000000
  293. #define CNFG_BITS_BAM_PSM_P_HD_DATA 0x2000000
  294. #define CNFG_BITS_BAM_REG_P_EN 0x1000000
  295. #define CNFG_BITS_BAM_WB_DSC_AVL_P_RST 0x800000
  296. #define CNFG_BITS_BAM_WB_RETR_SVPNT 0x400000
  297. #define CNFG_BITS_BAM_WB_CSW_ACK_IDL 0x200000
  298. #define CNFG_BITS_BAM_WB_BLK_CSW 0x100000
  299. #define CNFG_BITS_BAM_WB_P_RES 0x80000
  300. #define CNFG_BITS_BAM_SI_P_RES 0x40000
  301. #define CNFG_BITS_BAM_AU_P_RES 0x20000
  302. #define CNFG_BITS_BAM_PSM_P_RES 0x10000
  303. #define CNFG_BITS_BAM_PSM_CSW_REQ 0x8000
  304. #define CNFG_BITS_BAM_SB_CLK_REQ 0x4000
  305. #define CNFG_BITS_BAM_IBC_DISABLE 0x2000
  306. #define CNFG_BITS_BAM_NO_EXT_P_RST 0x1000
  307. #define CNFG_BITS_BAM_FULL_PIPE 0x800
  308. #define CNFG_BITS_BAM_PIPE_CNFG 0x4
  309. /* TEST_BUS_SEL */
  310. #define BAM_DATA_ERASE 0x40000
  311. #define BAM_DATA_FLUSH 0x20000
  312. #define BAM_CLK_ALWAYS_ON 0x10000
  313. #define BAM_TESTBUS_SEL 0x7f
  314. /* TRUST_REG */
  315. #define BAM_VMID 0x1f00
  316. #define BAM_RST_BLOCK 0x80
  317. #define BAM_EE 0x3
  318. /* P_TRUST_REGn */
  319. #define BAM_P_VMID 0x1f00
  320. #define BAM_P_EE 0x3
  321. /* P_PRDCR_SDBNDn */
  322. #define P_PRDCR_SDBNDn_BAM_P_SB_UPDATED 0x1000000
  323. #define P_PRDCR_SDBNDn_BAM_P_TOGGLE 0x100000
  324. #define P_PRDCR_SDBNDn_BAM_P_CTRL 0xf0000
  325. #define P_PRDCR_SDBNDn_BAM_P_BYTES_FREE 0xffff
  326. /* P_CNSMR_SDBNDn */
  327. #define P_CNSMR_SDBNDn_BAM_P_SB_UPDATED 0x1000000
  328. #define P_CNSMR_SDBNDn_BAM_P_WAIT_4_ACK 0x800000
  329. #define P_CNSMR_SDBNDn_BAM_P_ACK_TOGGLE 0x400000
  330. #define P_CNSMR_SDBNDn_BAM_P_ACK_TOGGLE_R 0x200000
  331. #define P_CNSMR_SDBNDn_BAM_P_TOGGLE 0x100000
  332. #define P_CNSMR_SDBNDn_BAM_P_CTRL 0xf0000
  333. #define P_CNSMR_SDBNDn_BAM_P_BYTES_AVAIL 0xffff
  334. /* P_ctrln */
  335. #define P_PREFETCH_LIMIT 0x600
  336. #define P_AUTO_EOB_SEL 0x180
  337. #define P_AUTO_EOB 0x40
  338. #define P_SYS_MODE 0x20
  339. #define P_SYS_STRM 0x10
  340. #define P_DIRECTION 0x8
  341. #define P_EN 0x2
  342. #define P_RST_P_SW_RST 0x1
  343. #define P_HALT_P_PROD_HALTED 0x2
  344. #define P_HALT_P_HALT 0x1
  345. #define P_IRQ_STTS_P_TRNSFR_END_IRQ 0x20
  346. #define P_IRQ_STTS_P_ERR_IRQ 0x10
  347. #define P_IRQ_STTS_P_OUT_OF_DESC_IRQ 0x8
  348. #define P_IRQ_STTS_P_WAKE_IRQ 0x4
  349. #define P_IRQ_STTS_P_TIMER_IRQ 0x2
  350. #define P_IRQ_STTS_P_PRCSD_DESC_IRQ 0x1
  351. #define P_IRQ_CLR_P_TRNSFR_END_CLR 0x20
  352. #define P_IRQ_CLR_P_ERR_CLR 0x10
  353. #define P_IRQ_CLR_P_OUT_OF_DESC_CLR 0x8
  354. #define P_IRQ_CLR_P_WAKE_CLR 0x4
  355. #define P_IRQ_CLR_P_TIMER_CLR 0x2
  356. #define P_IRQ_CLR_P_PRCSD_DESC_CLR 0x1
  357. #define P_IRQ_EN_P_TRNSFR_END_EN 0x20
  358. #define P_IRQ_EN_P_ERR_EN 0x10
  359. #define P_IRQ_EN_P_OUT_OF_DESC_EN 0x8
  360. #define P_IRQ_EN_P_WAKE_EN 0x4
  361. #define P_IRQ_EN_P_TIMER_EN 0x2
  362. #define P_IRQ_EN_P_PRCSD_DESC_EN 0x1
  363. #define P_TIMER_P_TIMER 0xffff
  364. /* P_TIMER_ctrln */
  365. #define P_TIMER_RST 0x80000000
  366. #define P_TIMER_RUN 0x40000000
  367. #define P_TIMER_MODE 0x20000000
  368. #define P_TIMER_TRSHLD 0xffff
  369. /* P_EVNT_regn */
  370. #define P_BYTES_CONSUMED 0xffff0000
  371. #define P_DESC_FIFO_PEER_OFST 0xffff
  372. /* P_SW_ofstsn */
  373. #define SW_OFST_IN_DESC 0xffff0000
  374. #define SW_DESC_OFST 0xffff
  375. #define P_EVNT_GEN_TRSHLD_P_TRSHLD 0xffff
  376. /* P_FIFO_sizesn */
  377. #define P_DATA_FIFO_SIZE 0xffff0000
  378. #define P_DESC_FIFO_SIZE 0xffff
  379. #define P_RETR_CNTXT_RETR_DESC_OFST 0xffff0000
  380. #define P_RETR_CNTXT_RETR_OFST_IN_DESC 0xffff
  381. #define P_SI_CNTXT_SI_DESC_OFST 0xffff
  382. #define P_AU_PSM_CNTXT_1_AU_PSM_ACCUMED 0xffff0000
  383. #define P_AU_PSM_CNTXT_1_AU_ACKED 0xffff
  384. #define P_PSM_CNTXT_2_PSM_DESC_VALID 0x80000000
  385. #define P_PSM_CNTXT_2_PSM_DESC_IRQ 0x40000000
  386. #define P_PSM_CNTXT_2_PSM_DESC_IRQ_DONE 0x20000000
  387. #define P_PSM_CNTXT_2_PSM_GENERAL_BITS 0x1e000000
  388. #define P_PSM_CNTXT_2_PSM_CONS_STATE 0x1c00000
  389. #define P_PSM_CNTXT_2_PSM_PROD_SYS_STATE 0x380000
  390. #define P_PSM_CNTXT_2_PSM_PROD_B2B_STATE 0x70000
  391. #define P_PSM_CNTXT_2_PSM_DESC_SIZE 0xffff
  392. #define P_PSM_CNTXT_4_PSM_DESC_OFST 0xffff0000
  393. #define P_PSM_CNTXT_4_PSM_SAVED_ACCUMED_SIZE 0xffff
  394. #define P_PSM_CNTXT_5_PSM_BLOCK_BYTE_CNT 0xffff0000
  395. #define P_PSM_CNTXT_5_PSM_OFST_IN_DESC 0xffff
  396. #endif
  397. #define BAM_ERROR (-1)
  398. enum bam_regs {
  399. CTRL,
  400. REVISION,
  401. SW_REVISION,
  402. NUM_PIPES,
  403. TIMER,
  404. TIMER_CTRL,
  405. DESC_CNT_TRSHLD,
  406. IRQ_SRCS,
  407. IRQ_SRCS_MSK,
  408. IRQ_SRCS_UNMASKED,
  409. IRQ_STTS,
  410. IRQ_CLR,
  411. IRQ_EN,
  412. IRQ_SIC_SEL,
  413. AHB_MASTER_ERR_CTRLS,
  414. AHB_MASTER_ERR_ADDR,
  415. AHB_MASTER_ERR_ADDR_MSB,
  416. AHB_MASTER_ERR_DATA,
  417. IRQ_DEST,
  418. PERIPH_IRQ_DEST,
  419. TRUST_REG,
  420. TEST_BUS_SEL,
  421. TEST_BUS_REG,
  422. CNFG_BITS,
  423. IRQ_SRCS_EE,
  424. IRQ_SRCS_MSK_EE,
  425. IRQ_SRCS_UNMASKED_EE,
  426. PIPE_ATTR_EE,
  427. P_CTRL,
  428. P_RST,
  429. P_HALT,
  430. P_IRQ_STTS,
  431. P_IRQ_CLR,
  432. P_IRQ_EN,
  433. P_TIMER,
  434. P_TIMER_CTRL,
  435. P_PRDCR_SDBND,
  436. P_CNSMR_SDBND,
  437. P_EVNT_DEST_ADDR,
  438. P_EVNT_DEST_ADDR_MSB,
  439. P_EVNT_REG,
  440. P_SW_OFSTS,
  441. P_DATA_FIFO_ADDR,
  442. P_DATA_FIFO_ADDR_MSB,
  443. P_DESC_FIFO_ADDR,
  444. P_DESC_FIFO_ADDR_MSB,
  445. P_EVNT_GEN_TRSHLD,
  446. P_FIFO_SIZES,
  447. P_IRQ_DEST_ADDR,
  448. P_RETR_CNTXT,
  449. P_SI_CNTXT,
  450. P_DF_CNTXT,
  451. P_AU_PSM_CNTXT_1,
  452. P_PSM_CNTXT_2,
  453. P_PSM_CNTXT_3,
  454. P_PSM_CNTXT_3_MSB,
  455. P_PSM_CNTXT_4,
  456. P_PSM_CNTXT_5,
  457. P_TRUST_REG,
  458. BAM_MAX_REGS,
  459. };
  460. static u32 bam_regmap[][BAM_MAX_REGS] = {
  461. { /* LEGACY BAM*/
  462. [CTRL] = 0xf80,
  463. [REVISION] = 0xf84,
  464. [NUM_PIPES] = 0xfbc,
  465. [DESC_CNT_TRSHLD] = 0xf88,
  466. [IRQ_SRCS] = 0xf8c,
  467. [IRQ_SRCS_MSK] = 0xf90,
  468. [IRQ_SRCS_UNMASKED] = 0xfb0,
  469. [IRQ_STTS] = 0xf94,
  470. [IRQ_CLR] = 0xf98,
  471. [IRQ_EN] = 0xf9c,
  472. [IRQ_SIC_SEL] = 0xfa0,
  473. [AHB_MASTER_ERR_CTRLS] = 0xfa4,
  474. [AHB_MASTER_ERR_ADDR] = 0xfa8,
  475. [AHB_MASTER_ERR_DATA] = 0xfac,
  476. [IRQ_DEST] = 0xfb4,
  477. [PERIPH_IRQ_DEST] = 0xfb8,
  478. [TRUST_REG] = 0xff0,
  479. [TEST_BUS_SEL] = 0xff4,
  480. [TEST_BUS_REG] = 0xff8,
  481. [CNFG_BITS] = 0xffc,
  482. [IRQ_SRCS_EE] = 0x1800,
  483. [IRQ_SRCS_MSK_EE] = 0x1804,
  484. [IRQ_SRCS_UNMASKED_EE] = 0x1808,
  485. [P_CTRL] = 0x0,
  486. [P_RST] = 0x4,
  487. [P_HALT] = 0x8,
  488. [P_IRQ_STTS] = 0x10,
  489. [P_IRQ_CLR] = 0x14,
  490. [P_IRQ_EN] = 0x18,
  491. [P_TIMER] = 0x1c,
  492. [P_TIMER_CTRL] = 0x20,
  493. [P_PRDCR_SDBND] = 0x24,
  494. [P_CNSMR_SDBND] = 0x28,
  495. [P_EVNT_DEST_ADDR] = 0x102c,
  496. [P_EVNT_REG] = 0x1018,
  497. [P_SW_OFSTS] = 0x1000,
  498. [P_DATA_FIFO_ADDR] = 0x1024,
  499. [P_DESC_FIFO_ADDR] = 0x101c,
  500. [P_EVNT_GEN_TRSHLD] = 0x1028,
  501. [P_FIFO_SIZES] = 0x1020,
  502. [P_IRQ_DEST_ADDR] = 0x103c,
  503. [P_RETR_CNTXT] = 0x1034,
  504. [P_SI_CNTXT] = 0x1038,
  505. [P_AU_PSM_CNTXT_1] = 0x1004,
  506. [P_PSM_CNTXT_2] = 0x1008,
  507. [P_PSM_CNTXT_3] = 0x100c,
  508. [P_PSM_CNTXT_4] = 0x1010,
  509. [P_PSM_CNTXT_5] = 0x1014,
  510. [P_TRUST_REG] = 0x30,
  511. },
  512. { /* NDP BAM */
  513. [CTRL] = 0x0,
  514. [REVISION] = 0x4,
  515. [SW_REVISION] = 0x80,
  516. [NUM_PIPES] = 0x3c,
  517. [TIMER] = 0x40,
  518. [TIMER_CTRL] = 0x44,
  519. [DESC_CNT_TRSHLD] = 0x8,
  520. [IRQ_SRCS] = 0xc,
  521. [IRQ_SRCS_MSK] = 0x10,
  522. [IRQ_SRCS_UNMASKED] = 0x30,
  523. [IRQ_STTS] = 0x14,
  524. [IRQ_CLR] = 0x18,
  525. [IRQ_EN] = 0x1c,
  526. [AHB_MASTER_ERR_CTRLS] = 0x24,
  527. [AHB_MASTER_ERR_ADDR] = 0x28,
  528. [AHB_MASTER_ERR_ADDR_MSB] = 0x104,
  529. [AHB_MASTER_ERR_DATA] = 0x2c,
  530. [TRUST_REG] = 0x70,
  531. [TEST_BUS_SEL] = 0x74,
  532. [TEST_BUS_REG] = 0x78,
  533. [CNFG_BITS] = 0x7c,
  534. [IRQ_SRCS_EE] = 0x800,
  535. [IRQ_SRCS_MSK_EE] = 0x804,
  536. [IRQ_SRCS_UNMASKED_EE] = 0x808,
  537. [PIPE_ATTR_EE] = 0x80c,
  538. [P_CTRL] = 0x1000,
  539. [P_RST] = 0x1004,
  540. [P_HALT] = 0x1008,
  541. [P_IRQ_STTS] = 0x1010,
  542. [P_IRQ_CLR] = 0x1014,
  543. [P_IRQ_EN] = 0x1018,
  544. [P_TIMER] = 0x101c,
  545. [P_TIMER_CTRL] = 0x1020,
  546. [P_PRDCR_SDBND] = 0x1024,
  547. [P_CNSMR_SDBND] = 0x1028,
  548. [P_EVNT_DEST_ADDR] = 0x182c,
  549. [P_EVNT_DEST_ADDR_MSB] = 0x1934,
  550. [P_EVNT_REG] = 0x1818,
  551. [P_SW_OFSTS] = 0x1800,
  552. [P_DATA_FIFO_ADDR] = 0x1824,
  553. [P_DATA_FIFO_ADDR_MSB] = 0x1924,
  554. [P_DESC_FIFO_ADDR] = 0x181c,
  555. [P_DESC_FIFO_ADDR_MSB] = 0x1914,
  556. [P_EVNT_GEN_TRSHLD] = 0x1828,
  557. [P_FIFO_SIZES] = 0x1820,
  558. [P_RETR_CNTXT] = 0x1834,
  559. [P_SI_CNTXT] = 0x1838,
  560. [P_DF_CNTXT] = 0x1830,
  561. [P_AU_PSM_CNTXT_1] = 0x1804,
  562. [P_PSM_CNTXT_2] = 0x1808,
  563. [P_PSM_CNTXT_3] = 0x180c,
  564. [P_PSM_CNTXT_3_MSB] = 0x1904,
  565. [P_PSM_CNTXT_4] = 0x1810,
  566. [P_PSM_CNTXT_5] = 0x1814,
  567. [P_TRUST_REG] = 0x1030,
  568. },
  569. { /* 4K OFFSETs*/
  570. [CTRL] = 0x0,
  571. [REVISION] = 0x1000,
  572. [SW_REVISION] = 0x1004,
  573. [NUM_PIPES] = 0x1008,
  574. [TIMER] = 0x40,
  575. [TIMER_CTRL] = 0x44,
  576. [DESC_CNT_TRSHLD] = 0x8,
  577. [IRQ_SRCS] = 0x3010,
  578. [IRQ_SRCS_MSK] = 0x3014,
  579. [IRQ_SRCS_UNMASKED] = 0x3018,
  580. [IRQ_STTS] = 0x14,
  581. [IRQ_CLR] = 0x18,
  582. [IRQ_EN] = 0x1c,
  583. [AHB_MASTER_ERR_CTRLS] = 0x1024,
  584. [AHB_MASTER_ERR_ADDR] = 0x1028,
  585. [AHB_MASTER_ERR_ADDR_MSB] = 0x1104,
  586. [AHB_MASTER_ERR_DATA] = 0x102c,
  587. [TRUST_REG] = 0x2000,
  588. [TEST_BUS_SEL] = 0x1010,
  589. [TEST_BUS_REG] = 0x1014,
  590. [CNFG_BITS] = 0x7c,
  591. [IRQ_SRCS_EE] = 0x3000,
  592. [IRQ_SRCS_MSK_EE] = 0x3004,
  593. [IRQ_SRCS_UNMASKED_EE] = 0x3008,
  594. [PIPE_ATTR_EE] = 0x300c,
  595. [P_CTRL] = 0x13000,
  596. [P_RST] = 0x13004,
  597. [P_HALT] = 0x13008,
  598. [P_IRQ_STTS] = 0x13010,
  599. [P_IRQ_CLR] = 0x13014,
  600. [P_IRQ_EN] = 0x13018,
  601. [P_TIMER] = 0x1301c,
  602. [P_TIMER_CTRL] = 0x13020,
  603. [P_PRDCR_SDBND] = 0x13024,
  604. [P_CNSMR_SDBND] = 0x13028,
  605. [P_EVNT_DEST_ADDR] = 0x1382c,
  606. [P_EVNT_DEST_ADDR_MSB] = 0x13934,
  607. [P_EVNT_REG] = 0x13818,
  608. [P_SW_OFSTS] = 0x13800,
  609. [P_DATA_FIFO_ADDR] = 0x13824,
  610. [P_DATA_FIFO_ADDR_MSB] = 0x13924,
  611. [P_DESC_FIFO_ADDR] = 0x1381c,
  612. [P_DESC_FIFO_ADDR_MSB] = 0x13914,
  613. [P_EVNT_GEN_TRSHLD] = 0x13828,
  614. [P_FIFO_SIZES] = 0x13820,
  615. [P_RETR_CNTXT] = 0x13834,
  616. [P_SI_CNTXT] = 0x13838,
  617. [P_DF_CNTXT] = 0x13830,
  618. [P_AU_PSM_CNTXT_1] = 0x13804,
  619. [P_PSM_CNTXT_2] = 0x13808,
  620. [P_PSM_CNTXT_3] = 0x1380c,
  621. [P_PSM_CNTXT_3_MSB] = 0x13904,
  622. [P_PSM_CNTXT_4] = 0x13810,
  623. [P_PSM_CNTXT_5] = 0x13814,
  624. [P_TRUST_REG] = 0x2020,
  625. },
  626. };
  627. /* AHB buffer error control */
  628. enum bam_nonsecure_reset {
  629. BAM_NONSECURE_RESET_ENABLE = 0,
  630. BAM_NONSECURE_RESET_DISABLE = 1,
  631. };
  632. static inline u32 bam_get_register_offset(enum bam_regs reg, u32 param)
  633. {
  634. u32 index = BAM_ERROR, offset = 0;
  635. u32 *ptr_reg = bam_regmap[bam_type];
  636. if (reg >= CTRL && reg < IRQ_SRCS_EE)
  637. index = 0;
  638. if (reg >= IRQ_SRCS_EE && reg < P_CTRL)
  639. index = (bam_type == SPS_BAM_NDP_4K) ? 0x1000 : 0x80;
  640. if (reg >= P_CTRL && reg < P_TRUST_REG) {
  641. if (bam_type == SPS_BAM_LEGACY) {
  642. if (reg >= P_EVNT_DEST_ADDR)
  643. index = 0x40;
  644. else
  645. index = 0x80;
  646. } else
  647. index = 0x1000;
  648. } else if (P_TRUST_REG == reg) {
  649. if (bam_type == SPS_BAM_LEGACY)
  650. index = 0x80;
  651. else
  652. index = (bam_type == SPS_BAM_NDP_4K) ? 0x4 : 0x1000;
  653. }
  654. if (index < 0) {
  655. SPS_ERR("Failed to find register offset index\n");
  656. return index;
  657. }
  658. offset = *(ptr_reg + reg) + (index * param);
  659. SPS_DBG("sps:offset_index:0x%x;offset:0x%x\n", index, offset);
  660. return offset;
  661. }
  662. /**
  663. *
  664. * Read register with debug info.
  665. *
  666. * @base - bam base virtual address.
  667. * @offset - register offset.
  668. *
  669. * @return u32
  670. */
  671. static inline u32 bam_read_reg(void *base, enum bam_regs reg, u32 param)
  672. {
  673. u32 val, offset = 0;
  674. offset = bam_get_register_offset(reg, param);
  675. if (offset < 0) {
  676. SPS_ERR("Failed to get the register offset\n");
  677. return offset;
  678. }
  679. val = ioread32(base + offset);
  680. SPS_DBG("sps:bam 0x%p(va) offset 0x%x reg 0x%x r_val 0x%x.\n",
  681. base, offset, reg, val);
  682. return val;
  683. }
  684. /**
  685. * Read register masked field with debug info.
  686. *
  687. * @base - bam base virtual address.
  688. * @offset - register offset.
  689. * @mask - register bitmask.
  690. *
  691. * @return u32
  692. */
  693. static inline u32 bam_read_reg_field(void *base, enum bam_regs reg, u32 param,
  694. const u32 mask)
  695. {
  696. u32 val;
  697. u32 shift = find_first_bit((void *)&mask, 32);
  698. u32 offset = bam_get_register_offset(reg, param);
  699. if (offset < 0) {
  700. SPS_ERR("Failed to get the register offset\n");
  701. return offset;
  702. }
  703. val = ioread32(base + offset);
  704. val &= mask; /* clear other bits */
  705. val >>= shift;
  706. SPS_DBG("sps:bam 0x%p(va) read reg 0x%x mask 0x%x r_val 0x%x.\n",
  707. base, offset, mask, val);
  708. return val;
  709. }
  710. /**
  711. *
  712. * Write register with debug info.
  713. *
  714. * @base - bam base virtual address.
  715. * @offset - register offset.
  716. * @val - value to write.
  717. *
  718. */
  719. static inline void bam_write_reg(void *base, enum bam_regs reg,
  720. u32 param, u32 val)
  721. {
  722. u32 offset = bam_get_register_offset(reg, param);
  723. if (offset < 0) {
  724. SPS_ERR("Failed to get the register offset\n");
  725. return;
  726. }
  727. iowrite32(val, base + offset);
  728. SPS_DBG("sps:bam 0x%p(va) write reg 0x%x w_val 0x%x.\n",
  729. base, offset, val);
  730. }
  731. /**
  732. * Write register masked field with debug info.
  733. *
  734. * @base - bam base virtual address.
  735. * @offset - register offset.
  736. * @mask - register bitmask.
  737. * @val - value to write.
  738. *
  739. */
  740. static inline void bam_write_reg_field(void *base, enum bam_regs reg,
  741. u32 param, const u32 mask, u32 val)
  742. {
  743. u32 tmp;
  744. u32 shift = find_first_bit((void *)&mask, 32);
  745. u32 offset = bam_get_register_offset(reg, param);
  746. if (offset < 0) {
  747. SPS_ERR("Failed to get the register offset\n");
  748. return;
  749. }
  750. tmp = ioread32(base + offset);
  751. tmp &= ~mask; /* clear written bits */
  752. val = tmp | (val << shift);
  753. iowrite32(val, base + offset);
  754. SPS_DBG("sps:bam 0x%p(va) write reg 0x%x w_val 0x%x.\n",
  755. base, offset, val);
  756. }
  757. /**
  758. * Initialize a BAM device
  759. *
  760. */
  761. int bam_init(void *base, u32 ee,
  762. u16 summing_threshold,
  763. u32 irq_mask, u32 *version,
  764. u32 *num_pipes, u32 options)
  765. {
  766. u32 cfg_bits;
  767. u32 ver = 0;
  768. SPS_DBG2("sps:%s:bam=0x%p(va).ee=%d.", __func__, base, ee);
  769. ver = bam_read_reg_field(base, REVISION, 0, BAM_REVISION);
  770. if ((ver < BAM_MIN_VERSION) || (ver > BAM_MAX_VERSION)) {
  771. SPS_ERR("sps:bam 0x%p(va) Invalid BAM REVISION 0x%x.\n",
  772. base, ver);
  773. return -ENODEV;
  774. } else
  775. SPS_DBG("sps:REVISION of BAM 0x%p is 0x%x.\n",
  776. base, ver);
  777. if (summing_threshold == 0) {
  778. summing_threshold = 4;
  779. SPS_ERR(
  780. "sps:bam 0x%p(va) summing_threshold is zero, "
  781. "use default 4.\n", base);
  782. }
  783. if (options & SPS_BAM_NO_EXT_P_RST)
  784. cfg_bits = 0xffffffff & ~(3 << 11);
  785. else
  786. cfg_bits = 0xffffffff & ~(1 << 11);
  787. bam_write_reg_field(base, CTRL, 0, BAM_SW_RST, 1);
  788. /* No delay needed */
  789. bam_write_reg_field(base, CTRL, 0, BAM_SW_RST, 0);
  790. bam_write_reg_field(base, CTRL, 0, BAM_EN, 1);
  791. #ifdef CONFIG_SPS_SUPPORT_NDP_BAM
  792. bam_write_reg_field(base, CTRL, 0, CACHE_MISS_ERR_RESP_EN, 0);
  793. if (options & SPS_BAM_NO_LOCAL_CLK_GATING)
  794. bam_write_reg_field(base, CTRL, 0, LOCAL_CLK_GATING, 0);
  795. else
  796. bam_write_reg_field(base, CTRL, 0, LOCAL_CLK_GATING, 1);
  797. if (enhd_pipe) {
  798. if (options & SPS_BAM_CANCEL_WB)
  799. bam_write_reg_field(base, CTRL, 0,
  800. BAM_MESS_ONLY_CANCEL_WB, 1);
  801. else
  802. bam_write_reg_field(base, CTRL, 0,
  803. BAM_MESS_ONLY_CANCEL_WB, 0);
  804. }
  805. #endif
  806. bam_write_reg(base, DESC_CNT_TRSHLD, 0, summing_threshold);
  807. bam_write_reg(base, CNFG_BITS, 0, cfg_bits);
  808. /*
  809. * Enable Global BAM Interrupt - for error reasons ,
  810. * filter with mask.
  811. * Note: Pipes interrupts are disabled until BAM_P_IRQ_enn is set
  812. */
  813. bam_write_reg_field(base, IRQ_SRCS_MSK_EE, ee, BAM_IRQ, 1);
  814. bam_write_reg(base, IRQ_EN, 0, irq_mask);
  815. *num_pipes = bam_read_reg_field(base, NUM_PIPES, 0, BAM_NUM_PIPES);
  816. *version = ver;
  817. return 0;
  818. }
  819. /**
  820. * Set BAM global execution environment
  821. *
  822. * @base - BAM virtual base address
  823. *
  824. * @ee - BAM execution environment index
  825. *
  826. * @vmid - virtual master identifier
  827. *
  828. * @reset - enable/disable BAM global software reset
  829. */
  830. static void bam_set_ee(void *base, u32 ee, u32 vmid,
  831. enum bam_nonsecure_reset reset)
  832. {
  833. bam_write_reg_field(base, TRUST_REG, 0, BAM_EE, ee);
  834. bam_write_reg_field(base, TRUST_REG, 0, BAM_VMID, vmid);
  835. bam_write_reg_field(base, TRUST_REG, 0, BAM_RST_BLOCK, reset);
  836. }
  837. /**
  838. * Set the pipe execution environment
  839. *
  840. * @base - BAM virtual base address
  841. *
  842. * @pipe - pipe index
  843. *
  844. * @ee - BAM execution environment index
  845. *
  846. * @vmid - virtual master identifier
  847. */
  848. static void bam_pipe_set_ee(void *base, u32 pipe, u32 ee, u32 vmid)
  849. {
  850. bam_write_reg_field(base, P_TRUST_REG, pipe, BAM_P_EE, ee);
  851. bam_write_reg_field(base, P_TRUST_REG, pipe, BAM_P_VMID, vmid);
  852. }
  853. /**
  854. * Initialize BAM device security execution environment
  855. */
  856. int bam_security_init(void *base, u32 ee, u32 vmid, u32 pipe_mask)
  857. {
  858. u32 version;
  859. u32 num_pipes;
  860. u32 mask;
  861. u32 pipe;
  862. SPS_DBG2("sps:%s:bam=0x%p(va).", __func__, base);
  863. /*
  864. * Discover the hardware version number and the number of pipes
  865. * supported by this BAM
  866. */
  867. version = bam_read_reg_field(base, REVISION, 0, BAM_REVISION);
  868. num_pipes = bam_read_reg_field(base, NUM_PIPES, 0, BAM_NUM_PIPES);
  869. if (version < 3 || version > 0x1F) {
  870. SPS_ERR(
  871. "sps:bam 0x%p(va) security is not supported for this "
  872. "BAM version 0x%x.\n", base, version);
  873. return -ENODEV;
  874. }
  875. if (num_pipes > BAM_MAX_PIPES) {
  876. SPS_ERR(
  877. "sps:bam 0x%p(va) the number of pipes is more than "
  878. "the maximum number allowed.\n", base);
  879. return -ENODEV;
  880. }
  881. for (pipe = 0, mask = 1; pipe < num_pipes; pipe++, mask <<= 1)
  882. if ((mask & pipe_mask) != 0)
  883. bam_pipe_set_ee(base, pipe, ee, vmid);
  884. /* If MSbit is set, assign top-level interrupt to this EE */
  885. mask = 1UL << 31;
  886. if ((mask & pipe_mask) != 0)
  887. bam_set_ee(base, ee, vmid, BAM_NONSECURE_RESET_ENABLE);
  888. return 0;
  889. }
  890. #ifdef CONFIG_SPS_SUPPORT_NDP_BAM
  891. static inline u32 bam_get_pipe_attr(void *base, u32 ee, bool global)
  892. {
  893. u32 val;
  894. if (global)
  895. val = bam_read_reg_field(base, PIPE_ATTR_EE, ee, BAM_ENABLED);
  896. else
  897. val = bam_read_reg_field(base, PIPE_ATTR_EE, ee, P_ATTR);
  898. return val;
  899. }
  900. #else
  901. static inline u32 bam_get_pipe_attr(void *base, u32 ee, bool global)
  902. {
  903. return 0;
  904. }
  905. #endif
  906. /**
  907. * Verify that a BAM device is enabled and gathers the hardware
  908. * configuration.
  909. *
  910. */
  911. int bam_check(void *base, u32 *version, u32 ee, u32 *num_pipes)
  912. {
  913. u32 ver = 0;
  914. u32 enabled = 0;
  915. SPS_DBG2("sps:%s:bam=0x%p(va).", __func__, base);
  916. if (!enhd_pipe)
  917. enabled = bam_read_reg_field(base, CTRL, 0, BAM_EN);
  918. else
  919. enabled = bam_get_pipe_attr(base, ee, true);
  920. if (!enabled) {
  921. SPS_ERR("sps:%s:bam 0x%p(va) is not enabled.\n",
  922. __func__, base);
  923. return -ENODEV;
  924. }
  925. ver = bam_read_reg(base, REVISION, 0) & BAM_REVISION;
  926. /*
  927. * Discover the hardware version number and the number of pipes
  928. * supported by this BAM
  929. */
  930. *num_pipes = bam_read_reg_field(base, NUM_PIPES, 0, BAM_NUM_PIPES);
  931. *version = ver;
  932. /* Check BAM version */
  933. if ((ver < BAM_MIN_VERSION) || (ver > BAM_MAX_VERSION)) {
  934. SPS_ERR("sps:%s:bam 0x%p(va) Invalid BAM version 0x%x.\n",
  935. __func__, base, ver);
  936. return -ENODEV;
  937. }
  938. return 0;
  939. }
  940. /**
  941. * Disable a BAM device
  942. *
  943. */
  944. void bam_exit(void *base, u32 ee)
  945. {
  946. SPS_DBG2("sps:%s:bam=0x%p(va).ee=%d.", __func__, base, ee);
  947. bam_write_reg_field(base, IRQ_SRCS_MSK_EE, ee, BAM_IRQ, 0);
  948. bam_write_reg(base, IRQ_EN, 0, 0);
  949. /* Disable the BAM */
  950. bam_write_reg_field(base, CTRL, 0, BAM_EN, 0);
  951. }
  952. /**
  953. * Output BAM register content
  954. * including the TEST_BUS register content under
  955. * different TEST_BUS_SEL values.
  956. */
  957. void bam_output_register_content(void *base, u32 ee)
  958. {
  959. u32 num_pipes;
  960. u32 i;
  961. u32 pipe_attr = 0;
  962. print_bam_test_bus_reg(base, 0);
  963. print_bam_selected_reg(base, BAM_MAX_EES);
  964. num_pipes = bam_read_reg_field(base, NUM_PIPES, 0,
  965. BAM_NUM_PIPES);
  966. SPS_INFO("sps:bam 0x%p(va) has %d pipes.",
  967. base, num_pipes);
  968. pipe_attr = enhd_pipe ?
  969. bam_get_pipe_attr(base, ee, false) : 0x0;
  970. if (!enhd_pipe || !pipe_attr)
  971. for (i = 0; i < num_pipes; i++)
  972. print_bam_pipe_selected_reg(base, i);
  973. else {
  974. for (i = 0; i < num_pipes; i++) {
  975. if (pipe_attr & (1UL << i))
  976. print_bam_pipe_selected_reg(base, i);
  977. }
  978. }
  979. }
  980. /**
  981. * Get BAM IRQ source and clear global IRQ status
  982. */
  983. u32 bam_check_irq_source(void *base, u32 ee, u32 mask,
  984. enum sps_callback_case *cb_case)
  985. {
  986. u32 source = bam_read_reg(base, IRQ_SRCS_EE, ee);
  987. u32 clr = source & (1UL << 31);
  988. if (clr) {
  989. u32 status = 0;
  990. status = bam_read_reg(base, IRQ_STTS, 0);
  991. if (status & IRQ_STTS_BAM_ERROR_IRQ) {
  992. SPS_ERR("sps:bam 0x%p(va);bam irq status="
  993. "0x%x.\nsps: BAM_ERROR_IRQ\n",
  994. base, status);
  995. bam_output_register_content(base, ee);
  996. *cb_case = SPS_CALLBACK_BAM_ERROR_IRQ;
  997. } else if (status & IRQ_STTS_BAM_HRESP_ERR_IRQ) {
  998. SPS_ERR("sps:bam 0x%p(va);bam irq status="
  999. "0x%x.\nsps: BAM_HRESP_ERR_IRQ\n",
  1000. base, status);
  1001. bam_output_register_content(base, ee);
  1002. *cb_case = SPS_CALLBACK_BAM_HRESP_ERR_IRQ;
  1003. #ifdef CONFIG_SPS_SUPPORT_NDP_BAM
  1004. } else if (status & IRQ_STTS_BAM_TIMER_IRQ) {
  1005. SPS_DBG1("sps:bam 0x%p(va);receive BAM_TIMER_IRQ\n",
  1006. base);
  1007. *cb_case = SPS_CALLBACK_BAM_TIMER_IRQ;
  1008. #endif
  1009. } else
  1010. SPS_INFO("sps:bam 0x%p(va);bam irq status=0x%x.\n",
  1011. base, status);
  1012. bam_write_reg(base, IRQ_CLR, 0, status);
  1013. }
  1014. source &= (mask|(1UL << 31));
  1015. return source;
  1016. }
  1017. /*
  1018. * Reset a BAM pipe
  1019. */
  1020. void bam_pipe_reset(void *base, u32 pipe)
  1021. {
  1022. SPS_DBG2("sps:%s:bam=0x%p(va).pipe=%d.", __func__, base, pipe);
  1023. bam_write_reg(base, P_RST, pipe, 1);
  1024. wmb(); /* ensure pipe is reset */
  1025. bam_write_reg(base, P_RST, pipe, 0);
  1026. wmb(); /* ensure pipe reset is de-asserted*/
  1027. }
  1028. /**
  1029. * Initialize a BAM pipe
  1030. */
  1031. int bam_pipe_init(void *base, u32 pipe, struct bam_pipe_parameters *param,
  1032. u32 ee)
  1033. {
  1034. SPS_DBG2("sps:%s:bam=0x%p(va).pipe=%d.", __func__, base, pipe);
  1035. /* Reset the BAM pipe */
  1036. bam_write_reg(base, P_RST, pipe, 1);
  1037. /* No delay needed */
  1038. bam_write_reg(base, P_RST, pipe, 0);
  1039. /* Enable the Pipe Interrupt at the BAM level */
  1040. bam_write_reg_field(base, IRQ_SRCS_MSK_EE, ee, (1 << pipe), 1);
  1041. bam_write_reg(base, P_IRQ_EN, pipe, param->pipe_irq_mask);
  1042. bam_write_reg_field(base, P_CTRL, pipe, P_DIRECTION, param->dir);
  1043. bam_write_reg_field(base, P_CTRL, pipe, P_SYS_MODE, param->mode);
  1044. bam_write_reg(base, P_EVNT_GEN_TRSHLD, pipe, param->event_threshold);
  1045. bam_write_reg(base, P_DESC_FIFO_ADDR, pipe,
  1046. SPS_GET_LOWER_ADDR(param->desc_base));
  1047. bam_write_reg_field(base, P_FIFO_SIZES, pipe, P_DESC_FIFO_SIZE,
  1048. param->desc_size);
  1049. bam_write_reg_field(base, P_CTRL, pipe, P_SYS_STRM,
  1050. param->stream_mode);
  1051. #ifdef CONFIG_SPS_SUPPORT_NDP_BAM
  1052. if (SPS_LPAE)
  1053. bam_write_reg(base, P_DESC_FIFO_ADDR_MSB, pipe,
  1054. SPS_GET_UPPER_ADDR(param->desc_base));
  1055. bam_write_reg_field(base, P_CTRL, pipe, P_LOCK_GROUP,
  1056. param->lock_group);
  1057. SPS_DBG("sps:bam=0x%p(va).pipe=%d.lock_group=%d.\n",
  1058. base, pipe, param->lock_group);
  1059. #endif
  1060. if (param->mode == BAM_PIPE_MODE_BAM2BAM) {
  1061. u32 peer_dest_addr = param->peer_phys_addr +
  1062. bam_get_register_offset(P_EVNT_REG,
  1063. param->peer_pipe);
  1064. bam_write_reg(base, P_DATA_FIFO_ADDR, pipe,
  1065. SPS_GET_LOWER_ADDR(param->data_base));
  1066. bam_write_reg_field(base, P_FIFO_SIZES, pipe,
  1067. P_DATA_FIFO_SIZE, param->data_size);
  1068. bam_write_reg(base, P_EVNT_DEST_ADDR, pipe, peer_dest_addr);
  1069. SPS_DBG2("sps:bam=0x%p(va).pipe=%d.peer_bam=0x%x."
  1070. "peer_pipe=%d.\n",
  1071. base, pipe,
  1072. (u32) param->peer_phys_addr,
  1073. param->peer_pipe);
  1074. #ifdef CONFIG_SPS_SUPPORT_NDP_BAM
  1075. if (SPS_LPAE) {
  1076. bam_write_reg(base, P_EVNT_DEST_ADDR_MSB, pipe, 0x0);
  1077. bam_write_reg(base, P_DATA_FIFO_ADDR_MSB, pipe,
  1078. SPS_GET_UPPER_ADDR(param->data_base));
  1079. }
  1080. bam_write_reg_field(base, P_CTRL, pipe, P_WRITE_NWD,
  1081. param->write_nwd);
  1082. SPS_DBG("sps:%s WRITE_NWD bit for this bam2bam pipe.",
  1083. param->write_nwd ? "Set" : "Do not set");
  1084. #endif
  1085. }
  1086. /* Pipe Enable - at last */
  1087. bam_write_reg_field(base, P_CTRL, pipe, P_EN, 1);
  1088. return 0;
  1089. }
  1090. /**
  1091. * Reset the BAM pipe
  1092. *
  1093. */
  1094. void bam_pipe_exit(void *base, u32 pipe, u32 ee)
  1095. {
  1096. SPS_DBG2("sps:%s:bam=0x%p(va).pipe=%d.", __func__, base, pipe);
  1097. bam_write_reg(base, P_IRQ_EN, pipe, 0);
  1098. /* Disable the Pipe Interrupt at the BAM level */
  1099. bam_write_reg_field(base, IRQ_SRCS_MSK_EE, ee, (1 << pipe), 0);
  1100. /* Pipe Disable */
  1101. bam_write_reg_field(base, P_CTRL, pipe, P_EN, 0);
  1102. }
  1103. /**
  1104. * Enable a BAM pipe
  1105. *
  1106. */
  1107. void bam_pipe_enable(void *base, u32 pipe)
  1108. {
  1109. SPS_DBG2("sps:%s:bam=0x%p(va).pipe=%d.", __func__, base, pipe);
  1110. if (bam_read_reg_field(base, P_CTRL, pipe, P_EN))
  1111. SPS_DBG2("sps:bam=0x%p(va).pipe=%d is already enabled.\n",
  1112. base, pipe);
  1113. else
  1114. bam_write_reg_field(base, P_CTRL, pipe, P_EN, 1);
  1115. }
  1116. /**
  1117. * Diasble a BAM pipe
  1118. *
  1119. */
  1120. void bam_pipe_disable(void *base, u32 pipe)
  1121. {
  1122. SPS_DBG2("sps:%s:bam=0x%p(va).pipe=%d.", __func__, base, pipe);
  1123. bam_write_reg_field(base, P_CTRL, pipe, P_EN, 0);
  1124. }
  1125. /**
  1126. * Check if a BAM pipe is enabled.
  1127. *
  1128. */
  1129. int bam_pipe_is_enabled(void *base, u32 pipe)
  1130. {
  1131. return bam_read_reg_field(base, P_CTRL, pipe, P_EN);
  1132. }
  1133. /**
  1134. * Configure interrupt for a BAM pipe
  1135. *
  1136. */
  1137. void bam_pipe_set_irq(void *base, u32 pipe, enum bam_enable irq_en,
  1138. u32 src_mask, u32 ee)
  1139. {
  1140. SPS_DBG2("sps:%s:bam=0x%p(va).pipe=%d.", __func__, base, pipe);
  1141. if (src_mask & BAM_PIPE_IRQ_RST_ERROR) {
  1142. if (enhd_pipe)
  1143. bam_write_reg_field(base, IRQ_EN, 0,
  1144. IRQ_EN_BAM_ERROR_EN, 0);
  1145. else {
  1146. src_mask &= ~BAM_PIPE_IRQ_RST_ERROR;
  1147. SPS_DBG2("sps: SPS_O_RST_ERROR is not supported\n");
  1148. }
  1149. }
  1150. if (src_mask & BAM_PIPE_IRQ_HRESP_ERROR) {
  1151. if (enhd_pipe)
  1152. bam_write_reg_field(base, IRQ_EN, 0,
  1153. IRQ_EN_BAM_HRESP_ERR_EN, 0);
  1154. else {
  1155. src_mask &= ~BAM_PIPE_IRQ_HRESP_ERROR;
  1156. SPS_DBG2("sps: SPS_O_HRESP_ERROR is not supported\n");
  1157. }
  1158. }
  1159. bam_write_reg(base, P_IRQ_EN, pipe, src_mask);
  1160. bam_write_reg_field(base, IRQ_SRCS_MSK_EE, ee, (1 << pipe), irq_en);
  1161. }
  1162. /**
  1163. * Configure a BAM pipe for satellite MTI use
  1164. *
  1165. */
  1166. void bam_pipe_satellite_mti(void *base, u32 pipe, u32 irq_gen_addr, u32 ee)
  1167. {
  1168. bam_write_reg(base, P_IRQ_EN, pipe, 0);
  1169. #ifndef CONFIG_SPS_SUPPORT_NDP_BAM
  1170. bam_write_reg(base, P_IRQ_DEST_ADDR, pipe, irq_gen_addr);
  1171. bam_write_reg_field(base, IRQ_SIC_SEL, 0, (1 << pipe), 1);
  1172. #endif
  1173. bam_write_reg_field(base, IRQ_SRCS_MSK, 0, (1 << pipe), 1);
  1174. }
  1175. /**
  1176. * Configure MTI for a BAM pipe
  1177. *
  1178. */
  1179. void bam_pipe_set_mti(void *base, u32 pipe, enum bam_enable irq_en,
  1180. u32 src_mask, u32 irq_gen_addr)
  1181. {
  1182. /*
  1183. * MTI use is only supported on BAMs when global config is controlled
  1184. * by a remote processor.
  1185. * Consequently, the global configuration register to enable SIC (MTI)
  1186. * support cannot be accessed.
  1187. * The remote processor must be relied upon to enable the SIC and the
  1188. * interrupt. Since the remote processor enable both SIC and interrupt,
  1189. * the interrupt enable mask must be set to zero for polling mode.
  1190. */
  1191. #ifndef CONFIG_SPS_SUPPORT_NDP_BAM
  1192. bam_write_reg(base, P_IRQ_DEST_ADDR, pipe, irq_gen_addr);
  1193. #endif
  1194. if (!irq_en)
  1195. src_mask = 0;
  1196. bam_write_reg(base, P_IRQ_EN, pipe, src_mask);
  1197. }
  1198. /**
  1199. * Get and Clear BAM pipe IRQ status
  1200. *
  1201. */
  1202. u32 bam_pipe_get_and_clear_irq_status(void *base, u32 pipe)
  1203. {
  1204. u32 status = 0;
  1205. status = bam_read_reg(base, P_IRQ_STTS, pipe);
  1206. bam_write_reg(base, P_IRQ_CLR, pipe, status);
  1207. return status;
  1208. }
  1209. /**
  1210. * Set write offset for a BAM pipe
  1211. *
  1212. */
  1213. void bam_pipe_set_desc_write_offset(void *base, u32 pipe, u32 next_write)
  1214. {
  1215. /*
  1216. * It is not necessary to perform a read-modify-write masking to write
  1217. * the P_DESC_FIFO_PEER_OFST value, since the other field in the
  1218. * register (P_BYTES_CONSUMED) is read-only.
  1219. */
  1220. bam_write_reg_field(base, P_EVNT_REG, pipe, P_DESC_FIFO_PEER_OFST,
  1221. next_write);
  1222. }
  1223. /**
  1224. * Get write offset for a BAM pipe
  1225. *
  1226. */
  1227. u32 bam_pipe_get_desc_write_offset(void *base, u32 pipe)
  1228. {
  1229. return bam_read_reg_field(base, P_EVNT_REG, pipe,
  1230. P_DESC_FIFO_PEER_OFST);
  1231. }
  1232. /**
  1233. * Get read offset for a BAM pipe
  1234. *
  1235. */
  1236. u32 bam_pipe_get_desc_read_offset(void *base, u32 pipe)
  1237. {
  1238. return bam_read_reg_field(base, P_SW_OFSTS, pipe, SW_DESC_OFST);
  1239. }
  1240. /**
  1241. * Configure inactivity timer count for a BAM pipe
  1242. *
  1243. */
  1244. void bam_pipe_timer_config(void *base, u32 pipe, enum bam_pipe_timer_mode mode,
  1245. u32 timeout_count)
  1246. {
  1247. u32 for_all_pipes = 0;
  1248. #ifdef CONFIG_SPS_SUPPORT_NDP_BAM
  1249. for_all_pipes = bam_read_reg_field(base, REVISION, 0,
  1250. BAM_NUM_INACTIV_TMRS);
  1251. #endif
  1252. if (for_all_pipes) {
  1253. #ifdef CONFIG_SPS_SUPPORT_NDP_BAM
  1254. bam_write_reg_field(base, TIMER_CTRL, 0, TIMER_MODE, mode);
  1255. bam_write_reg_field(base, TIMER_CTRL, 0, TIMER_TRSHLD,
  1256. timeout_count);
  1257. #endif
  1258. } else {
  1259. bam_write_reg_field(base, P_TIMER_CTRL, pipe, P_TIMER_MODE,
  1260. mode);
  1261. bam_write_reg_field(base, P_TIMER_CTRL, pipe, P_TIMER_TRSHLD,
  1262. timeout_count);
  1263. }
  1264. }
  1265. /**
  1266. * Reset inactivity timer for a BAM pipe
  1267. *
  1268. */
  1269. void bam_pipe_timer_reset(void *base, u32 pipe)
  1270. {
  1271. u32 for_all_pipes = 0;
  1272. #ifdef CONFIG_SPS_SUPPORT_NDP_BAM
  1273. for_all_pipes = bam_read_reg_field(base, REVISION, 0,
  1274. BAM_NUM_INACTIV_TMRS);
  1275. #endif
  1276. if (for_all_pipes) {
  1277. #ifdef CONFIG_SPS_SUPPORT_NDP_BAM
  1278. /* reset */
  1279. bam_write_reg_field(base, TIMER_CTRL, 0, TIMER_RST, 0);
  1280. /* active */
  1281. bam_write_reg_field(base, TIMER_CTRL, 0, TIMER_RST, 1);
  1282. #endif
  1283. } else {
  1284. /* reset */
  1285. bam_write_reg_field(base, P_TIMER_CTRL, pipe, P_TIMER_RST, 0);
  1286. /* active */
  1287. bam_write_reg_field(base, P_TIMER_CTRL, pipe, P_TIMER_RST, 1);
  1288. }
  1289. }
  1290. /**
  1291. * Get inactivity timer count for a BAM pipe
  1292. *
  1293. */
  1294. u32 bam_pipe_timer_get_count(void *base, u32 pipe)
  1295. {
  1296. return bam_read_reg(base, P_TIMER, pipe);
  1297. }
  1298. /* halt and un-halt a pipe */
  1299. void bam_pipe_halt(void *base, u32 pipe, bool halt)
  1300. {
  1301. if (halt)
  1302. bam_write_reg_field(base, P_HALT, pipe, P_HALT_P_HALT, 1);
  1303. else
  1304. bam_write_reg_field(base, P_HALT, pipe, P_HALT_P_HALT, 0);
  1305. }
  1306. /* output the content of BAM-level registers */
  1307. void print_bam_reg(void *virt_addr)
  1308. {
  1309. int i, n, index = 0;
  1310. u32 *bam = (u32 *) virt_addr;
  1311. u32 ctrl;
  1312. u32 ver;
  1313. u32 pipes;
  1314. u32 offset = 0;
  1315. if (bam == NULL)
  1316. return;
  1317. #ifdef CONFIG_SPS_SUPPORT_NDP_BAM
  1318. if (bam_type == SPS_BAM_NDP_4K) {
  1319. ctrl = bam[0x0 / 4];
  1320. ver = bam[0x1000 / 4];
  1321. pipes = bam[0x1008 / 4];
  1322. } else {
  1323. ctrl = bam[0x0 / 4];
  1324. ver = bam[0x4 / 4];
  1325. pipes = bam[0x3c / 4];
  1326. }
  1327. #else
  1328. ctrl = bam[0xf80 / 4];
  1329. ver = bam[0xf84 / 4];
  1330. pipes = bam[0xfbc / 4];
  1331. #endif
  1332. SPS_INFO("\nsps:<bam-begin> --- Content of BAM-level registers---\n");
  1333. SPS_INFO("BAM_CTRL: 0x%x.\n", ctrl);
  1334. SPS_INFO("BAM_REVISION: 0x%x.\n", ver);
  1335. SPS_INFO("NUM_PIPES: 0x%x.\n", pipes);
  1336. #ifdef CONFIG_SPS_SUPPORT_NDP_BAM
  1337. if (bam_type == SPS_BAM_NDP_4K)
  1338. offset = 0x301c;
  1339. else
  1340. offset = 0x80;
  1341. for (i = 0x0; i < offset; i += 0x10)
  1342. #else
  1343. for (i = 0xf80; i < 0x1000; i += 0x10)
  1344. #endif
  1345. SPS_INFO("bam addr 0x%x: 0x%x,0x%x,0x%x,0x%x.\n", i,
  1346. bam[i / 4], bam[(i / 4) + 1],
  1347. bam[(i / 4) + 2], bam[(i / 4) + 3]);
  1348. #ifdef CONFIG_SPS_SUPPORT_NDP_BAM
  1349. if (bam_type == SPS_BAM_NDP_4K) {
  1350. offset = 0x3000;
  1351. index = 0x1000;
  1352. } else {
  1353. offset = 0x800;
  1354. index = 0x80;
  1355. }
  1356. for (i = offset, n = 0; n++ < 8; i += index)
  1357. #else
  1358. for (i = 0x1800, n = 0; n++ < 4; i += 0x80)
  1359. #endif
  1360. SPS_INFO("bam addr 0x%x: 0x%x,0x%x,0x%x,0x%x.\n", i,
  1361. bam[i / 4], bam[(i / 4) + 1],
  1362. bam[(i / 4) + 2], bam[(i / 4) + 3]);
  1363. SPS_INFO("\nsps:<bam-begin> --- Content of BAM-level registers ---\n");
  1364. }
  1365. /* output the content of BAM pipe registers */
  1366. void print_bam_pipe_reg(void *virt_addr, u32 pipe_index)
  1367. {
  1368. int i;
  1369. u32 *bam = (u32 *) virt_addr;
  1370. u32 pipe = pipe_index;
  1371. u32 offset = 0;
  1372. if (bam == NULL)
  1373. return;
  1374. SPS_INFO("\nsps:<pipe-begin> --- Content of Pipe %d registers ---\n",
  1375. pipe);
  1376. SPS_INFO("-- Pipe Management Registers --\n");
  1377. #ifdef CONFIG_SPS_SUPPORT_NDP_BAM
  1378. if (bam_type == SPS_BAM_NDP_4K)
  1379. offset = 0x13000;
  1380. else
  1381. offset = 0x1000;
  1382. for (i = offset + 0x1000 * pipe; i < offset + 0x1000 * pipe + 0x80;
  1383. i += 0x10)
  1384. #else
  1385. for (i = 0x0000 + 0x80 * pipe; i < 0x0000 + 0x80 * (pipe + 1);
  1386. i += 0x10)
  1387. #endif
  1388. SPS_INFO("bam addr 0x%x: 0x%x,0x%x,0x%x,0x%x.\n", i,
  1389. bam[i / 4], bam[(i / 4) + 1],
  1390. bam[(i / 4) + 2], bam[(i / 4) + 3]);
  1391. SPS_INFO("-- Pipe Configuration and Internal State Registers --\n");
  1392. #ifdef CONFIG_SPS_SUPPORT_NDP_BAM
  1393. if (bam_type == SPS_BAM_NDP_4K)
  1394. offset = 0x13800;
  1395. else
  1396. offset = 0x1800;
  1397. for (i = offset + 0x1000 * pipe; i < offset + 0x1000 * pipe + 0x40;
  1398. i += 0x10)
  1399. #else
  1400. for (i = 0x1000 + 0x40 * pipe; i < 0x1000 + 0x40 * (pipe + 1);
  1401. i += 0x10)
  1402. #endif
  1403. SPS_INFO("bam addr 0x%x: 0x%x,0x%x,0x%x,0x%x.\n", i,
  1404. bam[i / 4], bam[(i / 4) + 1],
  1405. bam[(i / 4) + 2], bam[(i / 4) + 3]);
  1406. SPS_INFO("\nsps:<pipe-end> --- Content of Pipe %d registers ---\n",
  1407. pipe);
  1408. }
  1409. /* output the content of selected BAM-level registers */
  1410. void print_bam_selected_reg(void *virt_addr, u32 ee)
  1411. {
  1412. void *base = virt_addr;
  1413. u32 bam_ctrl;
  1414. u32 bam_revision;
  1415. u32 bam_rev_num;
  1416. u32 bam_rev_ee_num;
  1417. u32 bam_num_pipes;
  1418. u32 bam_pipe_num;
  1419. u32 bam_data_addr_bus_width;
  1420. u32 bam_desc_cnt_trshld;
  1421. u32 bam_desc_cnt_trd_val;
  1422. u32 bam_irq_en;
  1423. u32 bam_irq_stts;
  1424. u32 bam_irq_src_ee = 0;
  1425. u32 bam_irq_msk_ee = 0;
  1426. u32 bam_irq_unmsk_ee = 0;
  1427. u32 bam_pipe_attr_ee = 0;
  1428. u32 bam_ahb_err_ctrl;
  1429. u32 bam_ahb_err_addr;
  1430. u32 bam_ahb_err_data;
  1431. u32 bam_cnfg_bits;
  1432. u32 bam_sw_rev = 0;
  1433. u32 bam_timer = 0;
  1434. u32 bam_timer_ctrl = 0;
  1435. u32 bam_ahb_err_addr_msb = 0;
  1436. if (base == NULL)
  1437. return;
  1438. bam_ctrl = bam_read_reg(base, CTRL, 0);
  1439. bam_revision = bam_read_reg(base, REVISION, 0);
  1440. bam_rev_num = bam_read_reg_field(base, REVISION, 0, BAM_REVISION);
  1441. bam_rev_ee_num = bam_read_reg_field(base, REVISION, 0, BAM_NUM_EES);
  1442. bam_num_pipes = bam_read_reg(base, NUM_PIPES, 0);
  1443. bam_pipe_num = bam_read_reg_field(base, NUM_PIPES, 0, BAM_NUM_PIPES);
  1444. bam_data_addr_bus_width = bam_read_reg_field(base, NUM_PIPES, 0,
  1445. BAM_DATA_ADDR_BUS_WIDTH);
  1446. bam_desc_cnt_trshld = bam_read_reg(base, DESC_CNT_TRSHLD, 0);
  1447. bam_desc_cnt_trd_val = bam_read_reg_field(base, DESC_CNT_TRSHLD, 0,
  1448. BAM_DESC_CNT_TRSHLD);
  1449. bam_irq_en = bam_read_reg(base, IRQ_EN, 0);
  1450. bam_irq_stts = bam_read_reg(base, IRQ_STTS, 0);
  1451. if (ee < BAM_MAX_EES) {
  1452. bam_irq_src_ee = bam_read_reg(base, IRQ_SRCS_EE, ee);
  1453. bam_irq_msk_ee = bam_read_reg(base, IRQ_SRCS_MSK_EE, ee);
  1454. bam_irq_unmsk_ee = bam_read_reg(base, IRQ_SRCS_UNMASKED_EE, ee);
  1455. }
  1456. bam_ahb_err_ctrl = bam_read_reg(base, AHB_MASTER_ERR_CTRLS, 0);
  1457. bam_ahb_err_addr = bam_read_reg(base, AHB_MASTER_ERR_ADDR, 0);
  1458. bam_ahb_err_data = bam_read_reg(base, AHB_MASTER_ERR_DATA, 0);
  1459. bam_cnfg_bits = bam_read_reg(base, CNFG_BITS, 0);
  1460. #ifdef CONFIG_SPS_SUPPORT_NDP_BAM
  1461. bam_sw_rev = bam_read_reg(base, SW_REVISION, 0);
  1462. bam_timer = bam_read_reg(base, TIMER, 0);
  1463. bam_timer_ctrl = bam_read_reg(base, TIMER_CTRL, 0);
  1464. bam_ahb_err_addr_msb = SPS_LPAE ?
  1465. bam_read_reg(base, AHB_MASTER_ERR_ADDR_MSB, 0) : 0;
  1466. if (ee < BAM_MAX_EES)
  1467. bam_pipe_attr_ee = enhd_pipe ?
  1468. bam_read_reg(base, PIPE_ATTR_EE, ee) : 0x0;
  1469. #endif
  1470. SPS_INFO("\nsps:<bam-begin> --- BAM-level registers ---\n\n");
  1471. SPS_INFO("BAM_CTRL: 0x%x\n", bam_ctrl);
  1472. SPS_INFO("BAM_REVISION: 0x%x\n", bam_revision);
  1473. SPS_INFO(" REVISION: 0x%x\n", bam_rev_num);
  1474. SPS_INFO(" NUM_EES: %d\n", bam_rev_ee_num);
  1475. SPS_INFO("BAM_SW_REVISION: 0x%x\n", bam_sw_rev);
  1476. SPS_INFO("BAM_NUM_PIPES: %d\n", bam_num_pipes);
  1477. SPS_INFO("BAM_DATA_ADDR_BUS_WIDTH: %d\n",
  1478. ((bam_data_addr_bus_width == 0x0) ? 32 : 36));
  1479. SPS_INFO(" NUM_PIPES: %d\n", bam_pipe_num);
  1480. SPS_INFO("BAM_DESC_CNT_TRSHLD: 0x%x\n", bam_desc_cnt_trshld);
  1481. SPS_INFO(" DESC_CNT_TRSHLD: 0x%x (%d)\n", bam_desc_cnt_trd_val,
  1482. bam_desc_cnt_trd_val);
  1483. SPS_INFO("BAM_IRQ_EN: 0x%x\n", bam_irq_en);
  1484. SPS_INFO("BAM_IRQ_STTS: 0x%x\n", bam_irq_stts);
  1485. if (ee < BAM_MAX_EES) {
  1486. SPS_INFO("BAM_IRQ_SRCS_EE(%d): 0x%x\n", ee, bam_irq_src_ee);
  1487. SPS_INFO("BAM_IRQ_SRCS_MSK_EE(%d): 0x%x\n", ee, bam_irq_msk_ee);
  1488. SPS_INFO("BAM_IRQ_SRCS_UNMASKED_EE(%d): 0x%x\n", ee,
  1489. bam_irq_unmsk_ee);
  1490. SPS_INFO("BAM_PIPE_ATTR_EE(%d): 0x%x\n", ee, bam_pipe_attr_ee);
  1491. }
  1492. SPS_INFO("BAM_AHB_MASTER_ERR_CTRLS: 0x%x\n", bam_ahb_err_ctrl);
  1493. SPS_INFO("BAM_AHB_MASTER_ERR_ADDR: 0x%x\n", bam_ahb_err_addr);
  1494. SPS_INFO("BAM_AHB_MASTER_ERR_ADDR_MSB: 0x%x\n", bam_ahb_err_addr_msb);
  1495. SPS_INFO("BAM_AHB_MASTER_ERR_DATA: 0x%x\n", bam_ahb_err_data);
  1496. SPS_INFO("BAM_CNFG_BITS: 0x%x\n", bam_cnfg_bits);
  1497. SPS_INFO("BAM_TIMER: 0x%x\n", bam_timer);
  1498. SPS_INFO("BAM_TIMER_CTRL: 0x%x\n", bam_timer_ctrl);
  1499. SPS_INFO("\nsps:<bam-end> --- BAM-level registers ---\n\n");
  1500. }
  1501. /* output the content of selected BAM pipe registers */
  1502. void print_bam_pipe_selected_reg(void *virt_addr, u32 pipe_index)
  1503. {
  1504. void *base = virt_addr;
  1505. u32 pipe = pipe_index;
  1506. u32 p_ctrl;
  1507. u32 p_sys_mode;
  1508. u32 p_direction;
  1509. u32 p_lock_group = 0;
  1510. u32 p_irq_en;
  1511. u32 p_irq_stts;
  1512. u32 p_irq_stts_eot;
  1513. u32 p_irq_stts_int;
  1514. u32 p_prd_sdbd;
  1515. u32 p_bytes_free;
  1516. u32 p_prd_ctrl;
  1517. u32 p_prd_toggle;
  1518. u32 p_prd_sb_updated;
  1519. u32 p_con_sdbd;
  1520. u32 p_bytes_avail;
  1521. u32 p_con_ctrl;
  1522. u32 p_con_toggle;
  1523. u32 p_con_ack_toggle;
  1524. u32 p_con_ack_toggle_r;
  1525. u32 p_con_wait_4_ack;
  1526. u32 p_con_sb_updated;
  1527. u32 p_sw_offset;
  1528. u32 p_read_pointer;
  1529. u32 p_evnt_reg;
  1530. u32 p_write_pointer;
  1531. u32 p_evnt_dest;
  1532. u32 p_evnt_dest_msb = 0;
  1533. u32 p_desc_fifo_addr;
  1534. u32 p_desc_fifo_addr_msb = 0;
  1535. u32 p_desc_fifo_size;
  1536. u32 p_data_fifo_addr;
  1537. u32 p_data_fifo_addr_msb = 0;
  1538. u32 p_data_fifo_size;
  1539. u32 p_fifo_sizes;
  1540. u32 p_evnt_trd;
  1541. u32 p_evnt_trd_val;
  1542. u32 p_retr_ct;
  1543. u32 p_retr_offset;
  1544. u32 p_si_ct;
  1545. u32 p_si_offset;
  1546. u32 p_df_ct = 0;
  1547. u32 p_df_offset = 0;
  1548. u32 p_au_ct1;
  1549. u32 p_psm_ct2;
  1550. u32 p_psm_ct3;
  1551. u32 p_psm_ct3_msb = 0;
  1552. u32 p_psm_ct4;
  1553. u32 p_psm_ct5;
  1554. u32 p_timer;
  1555. u32 p_timer_ctrl;
  1556. if (base == NULL)
  1557. return;
  1558. p_ctrl = bam_read_reg(base, P_CTRL, pipe);
  1559. p_sys_mode = bam_read_reg_field(base, P_CTRL, pipe, P_SYS_MODE);
  1560. p_direction = bam_read_reg_field(base, P_CTRL, pipe, P_DIRECTION);
  1561. p_irq_en = bam_read_reg(base, P_IRQ_EN, pipe);
  1562. p_irq_stts = bam_read_reg(base, P_IRQ_STTS, pipe);
  1563. p_irq_stts_eot = bam_read_reg_field(base, P_IRQ_STTS, pipe,
  1564. P_IRQ_STTS_P_TRNSFR_END_IRQ);
  1565. p_irq_stts_int = bam_read_reg_field(base, P_IRQ_STTS, pipe,
  1566. P_IRQ_STTS_P_PRCSD_DESC_IRQ);
  1567. p_prd_sdbd = bam_read_reg(base, P_PRDCR_SDBND, pipe);
  1568. p_bytes_free = bam_read_reg_field(base, P_PRDCR_SDBND, pipe,
  1569. P_PRDCR_SDBNDn_BAM_P_BYTES_FREE);
  1570. p_prd_ctrl = bam_read_reg_field(base, P_PRDCR_SDBND, pipe,
  1571. P_PRDCR_SDBNDn_BAM_P_CTRL);
  1572. p_prd_toggle = bam_read_reg_field(base, P_PRDCR_SDBND, pipe,
  1573. P_PRDCR_SDBNDn_BAM_P_TOGGLE);
  1574. p_prd_sb_updated = bam_read_reg_field(base, P_PRDCR_SDBND, pipe,
  1575. P_PRDCR_SDBNDn_BAM_P_SB_UPDATED);
  1576. p_con_sdbd = bam_read_reg(base, P_CNSMR_SDBND, pipe);
  1577. p_bytes_avail = bam_read_reg_field(base, P_CNSMR_SDBND, pipe,
  1578. P_CNSMR_SDBNDn_BAM_P_BYTES_AVAIL);
  1579. p_con_ctrl = bam_read_reg_field(base, P_CNSMR_SDBND, pipe,
  1580. P_CNSMR_SDBNDn_BAM_P_CTRL);
  1581. p_con_toggle = bam_read_reg_field(base, P_CNSMR_SDBND, pipe,
  1582. P_CNSMR_SDBNDn_BAM_P_TOGGLE);
  1583. p_con_ack_toggle = bam_read_reg_field(base, P_CNSMR_SDBND, pipe,
  1584. P_CNSMR_SDBNDn_BAM_P_ACK_TOGGLE);
  1585. p_con_ack_toggle_r = bam_read_reg_field(base, P_CNSMR_SDBND, pipe,
  1586. P_CNSMR_SDBNDn_BAM_P_ACK_TOGGLE_R);
  1587. p_con_wait_4_ack = bam_read_reg_field(base, P_CNSMR_SDBND, pipe,
  1588. P_CNSMR_SDBNDn_BAM_P_WAIT_4_ACK);
  1589. p_con_sb_updated = bam_read_reg_field(base, P_CNSMR_SDBND, pipe,
  1590. P_CNSMR_SDBNDn_BAM_P_SB_UPDATED);
  1591. p_sw_offset = bam_read_reg(base, P_SW_OFSTS, pipe);
  1592. p_read_pointer = bam_read_reg_field(base, P_SW_OFSTS, pipe,
  1593. SW_DESC_OFST);
  1594. p_evnt_reg = bam_read_reg(base, P_EVNT_REG, pipe);
  1595. p_write_pointer = bam_read_reg_field(base, P_EVNT_REG, pipe,
  1596. P_DESC_FIFO_PEER_OFST);
  1597. p_evnt_dest = bam_read_reg(base, P_EVNT_DEST_ADDR, pipe);
  1598. p_desc_fifo_addr = bam_read_reg(base, P_DESC_FIFO_ADDR, pipe);
  1599. p_desc_fifo_size = bam_read_reg_field(base, P_FIFO_SIZES, pipe,
  1600. P_DESC_FIFO_SIZE);
  1601. p_data_fifo_addr = bam_read_reg(base, P_DATA_FIFO_ADDR, pipe);
  1602. p_data_fifo_size = bam_read_reg_field(base, P_FIFO_SIZES, pipe,
  1603. P_DATA_FIFO_SIZE);
  1604. p_fifo_sizes = bam_read_reg(base, P_FIFO_SIZES, pipe);
  1605. p_evnt_trd = bam_read_reg(base, P_EVNT_GEN_TRSHLD, pipe);
  1606. p_evnt_trd_val = bam_read_reg_field(base, P_EVNT_GEN_TRSHLD, pipe,
  1607. P_EVNT_GEN_TRSHLD_P_TRSHLD);
  1608. p_retr_ct = bam_read_reg(base, P_RETR_CNTXT, pipe);
  1609. p_retr_offset = bam_read_reg_field(base, P_RETR_CNTXT, pipe,
  1610. P_RETR_CNTXT_RETR_DESC_OFST);
  1611. p_si_ct = bam_read_reg(base, P_SI_CNTXT, pipe);
  1612. p_si_offset = bam_read_reg_field(base, P_SI_CNTXT, pipe,
  1613. P_SI_CNTXT_SI_DESC_OFST);
  1614. p_au_ct1 = bam_read_reg(base, P_AU_PSM_CNTXT_1, pipe);
  1615. p_psm_ct2 = bam_read_reg(base, P_PSM_CNTXT_2, pipe);
  1616. p_psm_ct3 = bam_read_reg(base, P_PSM_CNTXT_3, pipe);
  1617. p_psm_ct4 = bam_read_reg(base, P_PSM_CNTXT_4, pipe);
  1618. p_psm_ct5 = bam_read_reg(base, P_PSM_CNTXT_5, pipe);
  1619. p_timer = bam_read_reg(base, P_TIMER, pipe);
  1620. p_timer_ctrl = bam_read_reg(base, P_TIMER_CTRL, pipe);
  1621. #ifdef CONFIG_SPS_SUPPORT_NDP_BAM
  1622. p_evnt_dest_msb = SPS_LPAE ?
  1623. bam_read_reg(base, P_EVNT_DEST_ADDR_MSB, pipe) : 0;
  1624. p_desc_fifo_addr_msb = SPS_LPAE ?
  1625. bam_read_reg(base, P_DESC_FIFO_ADDR_MSB, pipe) : 0;
  1626. p_data_fifo_addr_msb = SPS_LPAE ?
  1627. bam_read_reg(base, P_DATA_FIFO_ADDR_MSB, pipe) : 0;
  1628. p_psm_ct3_msb = SPS_LPAE ? bam_read_reg(base, P_PSM_CNTXT_3, pipe) : 0;
  1629. p_lock_group = bam_read_reg_field(base, P_CTRL, pipe, P_LOCK_GROUP);
  1630. p_df_ct = bam_read_reg(base, P_DF_CNTXT, pipe);
  1631. p_df_offset = bam_read_reg_field(base, P_DF_CNTXT, pipe,
  1632. P_DF_CNTXT_DF_DESC_OFST);
  1633. #endif
  1634. SPS_INFO("\nsps:<pipe-begin> --- Registers of Pipe %d ---\n\n", pipe);
  1635. SPS_INFO("BAM_P_CTRL: 0x%x\n", p_ctrl);
  1636. SPS_INFO(" SYS_MODE: %d\n", p_sys_mode);
  1637. if (p_direction)
  1638. SPS_INFO(" DIRECTION:%d->Producer\n", p_direction);
  1639. else
  1640. SPS_INFO(" DIRECTION:%d->Consumer\n", p_direction);
  1641. SPS_INFO(" LOCK_GROUP: 0x%x (%d)\n", p_lock_group, p_lock_group);
  1642. SPS_INFO("BAM_P_IRQ_EN: 0x%x\n", p_irq_en);
  1643. SPS_INFO("BAM_P_IRQ_STTS: 0x%x\n", p_irq_stts);
  1644. SPS_INFO(" TRNSFR_END_IRQ(EOT): 0x%x\n", p_irq_stts_eot);
  1645. SPS_INFO(" PRCSD_DESC_IRQ(INT): 0x%x\n", p_irq_stts_int);
  1646. SPS_INFO("BAM_P_PRDCR_SDBND: 0x%x\n", p_prd_sdbd);
  1647. SPS_INFO(" BYTES_FREE: 0x%x (%d)\n", p_bytes_free, p_bytes_free);
  1648. SPS_INFO(" CTRL: 0x%x\n", p_prd_ctrl);
  1649. SPS_INFO(" TOGGLE: %d\n", p_prd_toggle);
  1650. SPS_INFO(" SB_UPDATED: %d\n", p_prd_sb_updated);
  1651. SPS_INFO("BAM_P_CNSMR_SDBND: 0x%x\n", p_con_sdbd);
  1652. SPS_INFO(" WAIT_4_ACK: %d\n", p_con_wait_4_ack);
  1653. SPS_INFO(" BYTES_AVAIL: 0x%x (%d)\n", p_bytes_avail, p_bytes_avail);
  1654. SPS_INFO(" CTRL: 0x%x\n", p_con_ctrl);
  1655. SPS_INFO(" TOGGLE: %d\n", p_con_toggle);
  1656. SPS_INFO(" ACK_TOGGLE: %d\n", p_con_ack_toggle);
  1657. SPS_INFO(" ACK_TOGGLE_R: %d\n", p_con_ack_toggle_r);
  1658. SPS_INFO(" SB_UPDATED: %d\n", p_con_sb_updated);
  1659. SPS_INFO("BAM_P_SW_DESC_OFST: 0x%x\n", p_sw_offset);
  1660. SPS_INFO(" SW_DESC_OFST: 0x%x\n", p_read_pointer);
  1661. SPS_INFO("BAM_P_EVNT_REG: 0x%x\n", p_evnt_reg);
  1662. SPS_INFO(" DESC_FIFO_PEER_OFST: 0x%x\n", p_write_pointer);
  1663. SPS_INFO("BAM_P_RETR_CNTXT: 0x%x\n", p_retr_ct);
  1664. SPS_INFO(" RETR_OFFSET: 0x%x\n", p_retr_offset);
  1665. SPS_INFO("BAM_P_SI_CNTXT: 0x%x\n", p_si_ct);
  1666. SPS_INFO(" SI_OFFSET: 0x%x\n", p_si_offset);
  1667. SPS_INFO("BAM_P_DF_CNTXT: 0x%x\n", p_df_ct);
  1668. SPS_INFO(" DF_OFFSET: 0x%x\n", p_df_offset);
  1669. SPS_INFO("BAM_P_DESC_FIFO_ADDR: 0x%x\n", p_desc_fifo_addr);
  1670. SPS_INFO("BAM_P_DESC_FIFO_ADDR_MSB: 0x%x\n", p_desc_fifo_addr_msb);
  1671. SPS_INFO("BAM_P_DATA_FIFO_ADDR: 0x%x\n", p_data_fifo_addr);
  1672. SPS_INFO("BAM_P_DATA_FIFO_ADDR_MSB: 0x%x\n", p_data_fifo_addr_msb);
  1673. SPS_INFO("BAM_P_FIFO_SIZES: 0x%x\n", p_fifo_sizes);
  1674. SPS_INFO(" DESC_FIFO_SIZE: 0x%x (%d)\n", p_desc_fifo_size,
  1675. p_desc_fifo_size);
  1676. SPS_INFO(" DATA_FIFO_SIZE: 0x%x (%d)\n", p_data_fifo_size,
  1677. p_data_fifo_size);
  1678. SPS_INFO("BAM_P_EVNT_DEST_ADDR: 0x%x\n", p_evnt_dest);
  1679. SPS_INFO("BAM_P_EVNT_DEST_ADDR_MSB: 0x%x\n", p_evnt_dest_msb);
  1680. SPS_INFO("BAM_P_EVNT_GEN_TRSHLD: 0x%x\n", p_evnt_trd);
  1681. SPS_INFO(" EVNT_GEN_TRSHLD: 0x%x (%d)\n", p_evnt_trd_val,
  1682. p_evnt_trd_val);
  1683. SPS_INFO("BAM_P_AU_PSM_CNTXT_1: 0x%x\n", p_au_ct1);
  1684. SPS_INFO("BAM_P_PSM_CNTXT_2: 0x%x\n", p_psm_ct2);
  1685. SPS_INFO("BAM_P_PSM_CNTXT_3: 0x%x\n", p_psm_ct3);
  1686. SPS_INFO("BAM_P_PSM_CNTXT_3_MSB: 0x%x\n", p_psm_ct3_msb);
  1687. SPS_INFO("BAM_P_PSM_CNTXT_4: 0x%x\n", p_psm_ct4);
  1688. SPS_INFO("BAM_P_PSM_CNTXT_5: 0x%x\n", p_psm_ct5);
  1689. SPS_INFO("BAM_P_TIMER: 0x%x\n", p_timer);
  1690. SPS_INFO("BAM_P_TIMER_CTRL: 0x%x\n", p_timer_ctrl);
  1691. SPS_INFO("\nsps:<pipe-end> --- Registers of Pipe %d ---\n\n", pipe);
  1692. }
  1693. /* output descriptor FIFO of a pipe */
  1694. void print_bam_pipe_desc_fifo(void *virt_addr, u32 pipe_index, u32 option)
  1695. {
  1696. void *base = virt_addr;
  1697. u32 pipe = pipe_index;
  1698. u32 desc_fifo_addr;
  1699. u32 desc_fifo_size;
  1700. u32 *desc_fifo;
  1701. int i;
  1702. char desc_info[MAX_MSG_LEN];
  1703. if (base == NULL)
  1704. return;
  1705. desc_fifo_addr = bam_read_reg(base, P_DESC_FIFO_ADDR, pipe);
  1706. desc_fifo_size = bam_read_reg_field(base, P_FIFO_SIZES, pipe,
  1707. P_DESC_FIFO_SIZE);
  1708. if (desc_fifo_addr == 0) {
  1709. SPS_ERR("sps:%s:desc FIFO address of Pipe %d is NULL.\n",
  1710. __func__, pipe);
  1711. return;
  1712. } else if (desc_fifo_size == 0) {
  1713. SPS_ERR("sps:%s:desc FIFO size of Pipe %d is 0.\n",
  1714. __func__, pipe);
  1715. return;
  1716. }
  1717. SPS_INFO("\nsps:<desc-begin> --- descriptor FIFO of Pipe %d -----\n\n",
  1718. pipe);
  1719. SPS_INFO("BAM_P_DESC_FIFO_ADDR: 0x%x\n"
  1720. "BAM_P_DESC_FIFO_SIZE: 0x%x (%d)\n\n",
  1721. desc_fifo_addr, desc_fifo_size, desc_fifo_size);
  1722. desc_fifo = (u32 *) phys_to_virt(desc_fifo_addr);
  1723. if (option == 100) {
  1724. SPS_INFO("----- start of data blocks -----\n");
  1725. for (i = 0; i < desc_fifo_size; i += 8) {
  1726. u32 *data_block_vir;
  1727. u32 data_block_phy = desc_fifo[i / 4];
  1728. if (data_block_phy) {
  1729. data_block_vir =
  1730. (u32 *) phys_to_virt(data_block_phy);
  1731. SPS_INFO("desc addr:0x%x; data addr:0x%x:\n",
  1732. desc_fifo_addr + i, data_block_phy);
  1733. SPS_INFO("0x%x, 0x%x, 0x%x, 0x%x\n",
  1734. data_block_vir[0], data_block_vir[1],
  1735. data_block_vir[2], data_block_vir[3]);
  1736. SPS_INFO("0x%x, 0x%x, 0x%x, 0x%x\n",
  1737. data_block_vir[4], data_block_vir[5],
  1738. data_block_vir[6], data_block_vir[7]);
  1739. SPS_INFO("0x%x, 0x%x, 0x%x, 0x%x\n",
  1740. data_block_vir[8], data_block_vir[9],
  1741. data_block_vir[10], data_block_vir[11]);
  1742. SPS_INFO("0x%x, 0x%x, 0x%x, 0x%x\n\n",
  1743. data_block_vir[12], data_block_vir[13],
  1744. data_block_vir[14], data_block_vir[15]);
  1745. }
  1746. }
  1747. SPS_INFO("----- end of data blocks -----\n");
  1748. } else if (option) {
  1749. u32 size = option * 128;
  1750. u32 current_desc = bam_pipe_get_desc_read_offset(base,
  1751. pipe_index);
  1752. u32 begin = 0;
  1753. u32 end = desc_fifo_size;
  1754. if (current_desc > size / 2)
  1755. begin = current_desc - size / 2;
  1756. if (desc_fifo_size > current_desc + size / 2)
  1757. end = current_desc + size / 2;
  1758. SPS_INFO("------------ begin of partial FIFO ------------\n\n");
  1759. SPS_INFO("desc addr; desc content; desc flags\n");
  1760. for (i = begin; i < end; i += 0x8) {
  1761. u32 offset;
  1762. u32 flags = desc_fifo[(i / 4) + 1] >> 16;
  1763. memset(desc_info, 0, sizeof(desc_info));
  1764. offset = scnprintf(desc_info, 40, "0x%x: 0x%x, 0x%x: ",
  1765. desc_fifo_addr + i,
  1766. desc_fifo[i / 4], desc_fifo[(i / 4) + 1]);
  1767. if (flags & SPS_IOVEC_FLAG_INT)
  1768. offset += scnprintf(desc_info + offset, 5,
  1769. "INT ");
  1770. if (flags & SPS_IOVEC_FLAG_EOT)
  1771. offset += scnprintf(desc_info + offset, 5,
  1772. "EOT ");
  1773. if (flags & SPS_IOVEC_FLAG_EOB)
  1774. offset += scnprintf(desc_info + offset, 5,
  1775. "EOB ");
  1776. if (flags & SPS_IOVEC_FLAG_NWD)
  1777. offset += scnprintf(desc_info + offset, 5,
  1778. "NWD ");
  1779. if (flags & SPS_IOVEC_FLAG_CMD)
  1780. offset += scnprintf(desc_info + offset, 5,
  1781. "CMD ");
  1782. if (flags & SPS_IOVEC_FLAG_LOCK)
  1783. offset += scnprintf(desc_info + offset, 5,
  1784. "LCK ");
  1785. if (flags & SPS_IOVEC_FLAG_UNLOCK)
  1786. offset += scnprintf(desc_info + offset, 5,
  1787. "UNL ");
  1788. if (flags & SPS_IOVEC_FLAG_IMME)
  1789. offset += scnprintf(desc_info + offset, 5,
  1790. "IMM ");
  1791. SPS_INFO("%s\n", desc_info);
  1792. }
  1793. SPS_INFO("\n------------ end of partial FIFO ------------\n");
  1794. } else {
  1795. SPS_INFO("---------------- begin of FIFO ----------------\n\n");
  1796. for (i = 0; i < desc_fifo_size; i += 0x10)
  1797. SPS_INFO("addr 0x%x: 0x%x, 0x%x, 0x%x, 0x%x.\n",
  1798. desc_fifo_addr + i,
  1799. desc_fifo[i / 4], desc_fifo[(i / 4) + 1],
  1800. desc_fifo[(i / 4) + 2], desc_fifo[(i / 4) + 3]);
  1801. SPS_INFO("\n---------------- end of FIFO ----------------\n");
  1802. }
  1803. SPS_INFO("\nsps:<desc-end> --- descriptor FIFO of Pipe %d -----\n\n",
  1804. pipe);
  1805. }
  1806. /* output BAM_TEST_BUS_REG with specified TEST_BUS_SEL */
  1807. void print_bam_test_bus_reg(void *base, u32 tb_sel)
  1808. {
  1809. u32 i;
  1810. u32 test_bus_selection[] = {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
  1811. 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf,
  1812. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  1813. 0x20, 0x21, 0x22, 0x23,
  1814. 0x41, 0x42, 0x43, 0x44, 0x45, 0x46};
  1815. u32 size = sizeof(test_bus_selection) / sizeof(u32);
  1816. if (base == NULL) {
  1817. SPS_ERR("sps:%s:BAM is NULL.\n", __func__);
  1818. return;
  1819. }
  1820. if (tb_sel) {
  1821. SPS_INFO("\nsps:Specified TEST_BUS_SEL value: 0x%x\n", tb_sel);
  1822. bam_write_reg_field(base, TEST_BUS_SEL, 0, BAM_TESTBUS_SEL,
  1823. tb_sel);
  1824. SPS_INFO("sps:BAM_TEST_BUS_REG:0x%x for TEST_BUS_SEL:0x%x\n\n",
  1825. bam_read_reg(base, TEST_BUS_REG, 0),
  1826. bam_read_reg_field(base, TEST_BUS_SEL, 0,
  1827. BAM_TESTBUS_SEL));
  1828. }
  1829. SPS_INFO("\nsps:<testbus-begin> --- BAM TEST_BUS dump -----\n\n");
  1830. /* output other selections */
  1831. for (i = 0; i < size; i++) {
  1832. bam_write_reg_field(base, TEST_BUS_SEL, 0, BAM_TESTBUS_SEL,
  1833. test_bus_selection[i]);
  1834. SPS_INFO("sps:TEST_BUS_REG:0x%x\t TEST_BUS_SEL:0x%x\n",
  1835. bam_read_reg(base, TEST_BUS_REG, 0),
  1836. bam_read_reg_field(base, TEST_BUS_SEL, 0,
  1837. BAM_TESTBUS_SEL));
  1838. }
  1839. SPS_INFO("\nsps:<testbus-end> --- BAM TEST_BUS dump -----\n\n");
  1840. }