bam.c 66 KB

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