adreno_a6xx_snapshot.c 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #include "adreno.h"
  7. #include "adreno_a6xx.h"
  8. #include "adreno_snapshot.h"
  9. #define A6XX_NUM_CTXTS 2
  10. #define A6XX_NUM_AXI_ARB_BLOCKS 2
  11. #define A6XX_NUM_XIN_AXI_BLOCKS 5
  12. #define A6XX_NUM_XIN_CORE_BLOCKS 4
  13. static const unsigned int a6xx_gras_cluster[] = {
  14. 0x8000, 0x8006, 0x8010, 0x8092, 0x8094, 0x809D, 0x80A0, 0x80A6,
  15. 0x80AF, 0x80F1, 0x8100, 0x8107, 0x8109, 0x8109, 0x8110, 0x8110,
  16. 0x8400, 0x840B,
  17. };
  18. static const unsigned int a6xx_ps_cluster_rac[] = {
  19. 0x8800, 0x8806, 0x8809, 0x8811, 0x8818, 0x881E, 0x8820, 0x8865,
  20. 0x8870, 0x8879, 0x8880, 0x8889, 0x8890, 0x8891, 0x8898, 0x8898,
  21. 0x88C0, 0x88C1, 0x88D0, 0x88E3, 0x8900, 0x890C, 0x890F, 0x891A,
  22. 0x8C00, 0x8C01, 0x8C08, 0x8C10, 0x8C17, 0x8C1F, 0x8C26, 0x8C33,
  23. };
  24. static const unsigned int a6xx_ps_cluster_rbp[] = {
  25. 0x88F0, 0x88F3, 0x890D, 0x890E, 0x8927, 0x8928, 0x8BF0, 0x8BF1,
  26. 0x8C02, 0x8C07, 0x8C11, 0x8C16, 0x8C20, 0x8C25,
  27. };
  28. static const unsigned int a6xx_vpc_ps_cluster[] = {
  29. 0x9200, 0x9216, 0x9218, 0x9236, 0x9300, 0x9306,
  30. };
  31. static const unsigned int a6xx_fe_cluster[] = {
  32. 0x9300, 0x9306, 0x9800, 0x9806, 0x9B00, 0x9B07, 0xA000, 0xA009,
  33. 0xA00E, 0xA0EF, 0xA0F8, 0xA0F8,
  34. };
  35. static const unsigned int a660_fe_cluster[] = {
  36. 0x9807, 0x9807,
  37. };
  38. static const unsigned int a6xx_pc_vs_cluster[] = {
  39. 0x9100, 0x9108, 0x9300, 0x9306, 0x9980, 0x9981, 0x9B00, 0x9B07,
  40. };
  41. static const unsigned int a650_isense_registers[] = {
  42. 0x22C00, 0x22C19, 0x22C26, 0x22C2D, 0x22C2F, 0x22C36, 0x22C40, 0x22C44,
  43. 0x22C50, 0x22C57, 0x22C60, 0x22C67, 0x22C80, 0x22C87, 0x22D25, 0x22D2A,
  44. 0x22D2C, 0x22D32, 0x22D3E, 0x22D3F, 0x22D4E, 0x22D55, 0x22D58, 0x22D60,
  45. 0x22D64, 0x22D64, 0x22D66, 0x22D66, 0x22D68, 0x22D6B, 0x22D6E, 0x22D76,
  46. 0x22D78, 0x22D78, 0x22D80, 0x22D87, 0x22D90, 0x22D97, 0x22DA0, 0x22DA0,
  47. 0x22DB0, 0x22DB7, 0x22DC0, 0x22DC2, 0x22DC4, 0x22DE3, 0x2301A, 0x2301A,
  48. 0x2301D, 0x2302A, 0x23120, 0x23121, 0x23133, 0x23133, 0x23156, 0x23157,
  49. 0x23165, 0x23165, 0x2316D, 0x2316D, 0x23180, 0x23191,
  50. };
  51. static const struct sel_reg {
  52. unsigned int host_reg;
  53. unsigned int cd_reg;
  54. unsigned int val;
  55. } _a6xx_rb_rac_aperture = {
  56. .host_reg = A6XX_RB_RB_SUB_BLOCK_SEL_CNTL_HOST,
  57. .cd_reg = A6XX_RB_RB_SUB_BLOCK_SEL_CNTL_CD,
  58. .val = 0x0,
  59. },
  60. _a6xx_rb_rbp_aperture = {
  61. .host_reg = A6XX_RB_RB_SUB_BLOCK_SEL_CNTL_HOST,
  62. .cd_reg = A6XX_RB_RB_SUB_BLOCK_SEL_CNTL_CD,
  63. .val = 0x9,
  64. };
  65. static struct a6xx_cluster_registers {
  66. unsigned int id;
  67. const unsigned int *regs;
  68. unsigned int num_sets;
  69. const struct sel_reg *sel;
  70. unsigned int offset0;
  71. unsigned int offset1;
  72. } a6xx_clusters[] = {
  73. { CP_CLUSTER_GRAS, a6xx_gras_cluster, ARRAY_SIZE(a6xx_gras_cluster)/2,
  74. NULL },
  75. { CP_CLUSTER_PS, a6xx_ps_cluster_rac, ARRAY_SIZE(a6xx_ps_cluster_rac)/2,
  76. &_a6xx_rb_rac_aperture },
  77. { CP_CLUSTER_PS, a6xx_ps_cluster_rbp, ARRAY_SIZE(a6xx_ps_cluster_rbp)/2,
  78. &_a6xx_rb_rbp_aperture },
  79. { CP_CLUSTER_PS, a6xx_vpc_ps_cluster, ARRAY_SIZE(a6xx_vpc_ps_cluster)/2,
  80. NULL },
  81. { CP_CLUSTER_FE, a6xx_fe_cluster, ARRAY_SIZE(a6xx_fe_cluster)/2,
  82. NULL },
  83. { CP_CLUSTER_PC_VS, a6xx_pc_vs_cluster,
  84. ARRAY_SIZE(a6xx_pc_vs_cluster)/2, NULL },
  85. { CP_CLUSTER_FE, a660_fe_cluster, ARRAY_SIZE(a660_fe_cluster)/2,
  86. NULL },
  87. };
  88. struct a6xx_cluster_regs_info {
  89. struct a6xx_cluster_registers *cluster;
  90. unsigned int ctxt_id;
  91. };
  92. static const unsigned int a6xx_sp_vs_hlsq_cluster[] = {
  93. 0xB800, 0xB803, 0xB820, 0xB822,
  94. };
  95. static const unsigned int a6xx_sp_vs_sp_cluster[] = {
  96. 0xA800, 0xA824, 0xA830, 0xA83C, 0xA840, 0xA864, 0xA870, 0xA895,
  97. 0xA8A0, 0xA8AF, 0xA8C0, 0xA8C3,
  98. };
  99. static const unsigned int a6xx_hlsq_duplicate_cluster[] = {
  100. 0xBB10, 0xBB11, 0xBB20, 0xBB29,
  101. };
  102. static const unsigned int a6xx_sp_duplicate_cluster[] = {
  103. 0xAB00, 0xAB00, 0xAB04, 0xAB05, 0xAB10, 0xAB1B, 0xAB20, 0xAB20,
  104. };
  105. static const unsigned int a6xx_tp_duplicate_cluster[] = {
  106. 0xB300, 0xB307, 0xB309, 0xB309, 0xB380, 0xB382,
  107. };
  108. static const unsigned int a6xx_sp_ps_hlsq_cluster[] = {
  109. 0xB980, 0xB980, 0xB982, 0xB987, 0xB990, 0xB99B, 0xB9A0, 0xB9A2,
  110. 0xB9C0, 0xB9C9,
  111. };
  112. static const unsigned int a6xx_sp_ps_sp_cluster[] = {
  113. 0xA980, 0xA9A8, 0xA9B0, 0xA9BC, 0xA9D0, 0xA9D3, 0xA9E0, 0xA9F3,
  114. 0xAA00, 0xAA00, 0xAA30, 0xAA31, 0xAAF2, 0xAAF2,
  115. };
  116. static const unsigned int a6xx_sp_ps_sp_2d_cluster[] = {
  117. 0xACC0, 0xACC0,
  118. };
  119. static const unsigned int a6xx_sp_ps_tp_cluster[] = {
  120. 0xB180, 0xB183, 0xB190, 0xB191,
  121. };
  122. static const unsigned int a6xx_sp_ps_tp_2d_cluster[] = {
  123. 0xB4C0, 0xB4D1,
  124. };
  125. static struct a6xx_cluster_dbgahb_registers {
  126. unsigned int id;
  127. unsigned int regbase;
  128. unsigned int statetype;
  129. const unsigned int *regs;
  130. unsigned int num_sets;
  131. unsigned int offset0;
  132. unsigned int offset1;
  133. } a6xx_dbgahb_ctx_clusters[] = {
  134. { CP_CLUSTER_SP_VS, 0x0002E000, 0x41, a6xx_sp_vs_hlsq_cluster,
  135. ARRAY_SIZE(a6xx_sp_vs_hlsq_cluster) / 2 },
  136. { CP_CLUSTER_SP_VS, 0x0002A000, 0x21, a6xx_sp_vs_sp_cluster,
  137. ARRAY_SIZE(a6xx_sp_vs_sp_cluster) / 2 },
  138. { CP_CLUSTER_SP_VS, 0x0002E000, 0x41, a6xx_hlsq_duplicate_cluster,
  139. ARRAY_SIZE(a6xx_hlsq_duplicate_cluster) / 2 },
  140. { CP_CLUSTER_SP_VS, 0x0002A000, 0x21, a6xx_sp_duplicate_cluster,
  141. ARRAY_SIZE(a6xx_sp_duplicate_cluster) / 2 },
  142. { CP_CLUSTER_SP_VS, 0x0002C000, 0x1, a6xx_tp_duplicate_cluster,
  143. ARRAY_SIZE(a6xx_tp_duplicate_cluster) / 2 },
  144. { CP_CLUSTER_SP_PS, 0x0002E000, 0x42, a6xx_sp_ps_hlsq_cluster,
  145. ARRAY_SIZE(a6xx_sp_ps_hlsq_cluster) / 2 },
  146. { CP_CLUSTER_SP_PS, 0x0002A000, 0x22, a6xx_sp_ps_sp_cluster,
  147. ARRAY_SIZE(a6xx_sp_ps_sp_cluster) / 2 },
  148. { CP_CLUSTER_SP_PS, 0x0002B000, 0x26, a6xx_sp_ps_sp_2d_cluster,
  149. ARRAY_SIZE(a6xx_sp_ps_sp_2d_cluster) / 2 },
  150. { CP_CLUSTER_SP_PS, 0x0002C000, 0x2, a6xx_sp_ps_tp_cluster,
  151. ARRAY_SIZE(a6xx_sp_ps_tp_cluster) / 2 },
  152. { CP_CLUSTER_SP_PS, 0x0002D000, 0x6, a6xx_sp_ps_tp_2d_cluster,
  153. ARRAY_SIZE(a6xx_sp_ps_tp_2d_cluster) / 2 },
  154. { CP_CLUSTER_SP_PS, 0x0002E000, 0x42, a6xx_hlsq_duplicate_cluster,
  155. ARRAY_SIZE(a6xx_hlsq_duplicate_cluster) / 2 },
  156. { CP_CLUSTER_SP_PS, 0x0002A000, 0x22, a6xx_sp_duplicate_cluster,
  157. ARRAY_SIZE(a6xx_sp_duplicate_cluster) / 2 },
  158. { CP_CLUSTER_SP_PS, 0x0002C000, 0x2, a6xx_tp_duplicate_cluster,
  159. ARRAY_SIZE(a6xx_tp_duplicate_cluster) / 2 },
  160. };
  161. struct a6xx_cluster_dbgahb_regs_info {
  162. struct a6xx_cluster_dbgahb_registers *cluster;
  163. unsigned int ctxt_id;
  164. };
  165. static const unsigned int a6xx_hlsq_non_ctx_registers[] = {
  166. 0xBE00, 0xBE01, 0xBE04, 0xBE05, 0xBE08, 0xBE09, 0xBE10, 0xBE15,
  167. 0xBE20, 0xBE23,
  168. };
  169. static const unsigned int a6xx_sp_non_ctx_registers[] = {
  170. 0xAE00, 0xAE04, 0xAE0C, 0xAE0C, 0xAE0F, 0xAE2B, 0xAE30, 0xAE32,
  171. 0xAE35, 0xAE35, 0xAE3A, 0xAE3F, 0xAE50, 0xAE52,
  172. };
  173. static const unsigned int a6xx_tp_non_ctx_registers[] = {
  174. 0xB600, 0xB601, 0xB604, 0xB605, 0xB610, 0xB61B, 0xB620, 0xB623,
  175. };
  176. static struct a6xx_non_ctx_dbgahb_registers {
  177. unsigned int regbase;
  178. unsigned int statetype;
  179. const unsigned int *regs;
  180. unsigned int num_sets;
  181. unsigned int offset;
  182. } a6xx_non_ctx_dbgahb[] = {
  183. { 0x0002F800, 0x40, a6xx_hlsq_non_ctx_registers,
  184. ARRAY_SIZE(a6xx_hlsq_non_ctx_registers) / 2 },
  185. { 0x0002B800, 0x20, a6xx_sp_non_ctx_registers,
  186. ARRAY_SIZE(a6xx_sp_non_ctx_registers) / 2 },
  187. { 0x0002D800, 0x0, a6xx_tp_non_ctx_registers,
  188. ARRAY_SIZE(a6xx_tp_non_ctx_registers) / 2 },
  189. };
  190. static const unsigned int a6xx_vbif_registers[] = {
  191. /* VBIF */
  192. 0x3000, 0x3007, 0x300C, 0x3014, 0x3018, 0x302D, 0x3030, 0x3031,
  193. 0x3034, 0x3036, 0x303C, 0x303D, 0x3040, 0x3040, 0x3042, 0x3042,
  194. 0x3049, 0x3049, 0x3058, 0x3058, 0x305A, 0x3061, 0x3064, 0x3068,
  195. 0x306C, 0x306D, 0x3080, 0x3088, 0x308B, 0x308C, 0x3090, 0x3094,
  196. 0x3098, 0x3098, 0x309C, 0x309C, 0x30C0, 0x30C0, 0x30C8, 0x30C8,
  197. 0x30D0, 0x30D0, 0x30D8, 0x30D8, 0x30E0, 0x30E0, 0x3100, 0x3100,
  198. 0x3108, 0x3108, 0x3110, 0x3110, 0x3118, 0x3118, 0x3120, 0x3120,
  199. 0x3124, 0x3125, 0x3129, 0x3129, 0x3131, 0x3131, 0x3154, 0x3154,
  200. 0x3156, 0x3156, 0x3158, 0x3158, 0x315A, 0x315A, 0x315C, 0x315C,
  201. 0x315E, 0x315E, 0x3160, 0x3160, 0x3162, 0x3162, 0x340C, 0x340C,
  202. 0x3410, 0x3410, 0x3800, 0x3801,
  203. };
  204. static const unsigned int a6xx_gbif_registers[] = {
  205. /* GBIF */
  206. 0x3C00, 0X3C0B, 0X3C40, 0X3C47, 0X3CC0, 0X3CD1, 0xE3A, 0xE3A,
  207. };
  208. static const unsigned int a6xx_gbif_reinit_registers[] = {
  209. /* GBIF with REINIT */
  210. 0x3C00, 0X3C0B, 0X3C40, 0X3C47, 0X3C49, 0X3C4A, 0X3CC0, 0X3CD1,
  211. 0xE3A, 0xE3A, 0x0016, 0x0017,
  212. };
  213. static const unsigned int a6xx_rb_rac_registers[] = {
  214. 0x8E04, 0x8E05, 0x8E07, 0x8E08, 0x8E10, 0x8E1C, 0x8E20, 0x8E25,
  215. 0x8E28, 0x8E28, 0x8E2C, 0x8E2F, 0x8E50, 0x8E52,
  216. };
  217. static const unsigned int a6xx_rb_rbp_registers[] = {
  218. 0x8E01, 0x8E01, 0x8E0C, 0x8E0C, 0x8E3B, 0x8E3E, 0x8E40, 0x8E43,
  219. 0x8E53, 0x8E5F, 0x8E70, 0x8E77,
  220. };
  221. /*
  222. * Set of registers to dump for A6XX on snapshot.
  223. * Registers in pairs - first value is the start offset, second
  224. * is the stop offset (inclusive)
  225. */
  226. static const unsigned int a6xx_registers[] = {
  227. /* RBBM */
  228. 0x0000, 0x0002, 0x0010, 0x0010, 0x0012, 0x0012, 0x0018, 0x001B,
  229. 0x001e, 0x0032, 0x0038, 0x003C, 0x0042, 0x0042, 0x0044, 0x0044,
  230. 0x0047, 0x0047, 0x0056, 0x0056, 0x00AD, 0x00AE, 0x00B0, 0x00FB,
  231. 0x0100, 0x011D, 0x0200, 0x020D, 0x0218, 0x023D, 0x0400, 0x04F9,
  232. 0x0500, 0x0500, 0x0505, 0x050B, 0x050E, 0x0511, 0x0533, 0x0533,
  233. 0x0540, 0x0555,
  234. /* CP */
  235. 0x0800, 0x0803, 0x0806, 0x0808, 0x0810, 0x0813, 0x0820, 0x0821,
  236. 0x0823, 0x0824, 0x0826, 0x0827, 0x0830, 0x0833, 0x0840, 0x0845,
  237. 0x084F, 0x086F, 0x0880, 0x088A, 0x08A0, 0x08AB, 0x08C0, 0x08C4,
  238. 0x08D0, 0x08DD, 0x08F0, 0x08F3, 0x0900, 0x0903, 0x0908, 0x0911,
  239. 0x0928, 0x093E, 0x0942, 0x094D, 0x0980, 0x0984, 0x098D, 0x0996,
  240. 0x0998, 0x099E, 0x09A0, 0x09A6, 0x09A8, 0x09AE, 0x09B0, 0x09B1,
  241. 0x09C2, 0x09C8, 0x0A00, 0x0A03,
  242. /* VSC */
  243. 0x0C00, 0x0C04, 0x0C06, 0x0C06, 0x0C10, 0x0CD9, 0x0E00, 0x0E0E,
  244. /* UCHE */
  245. 0x0E10, 0x0E13, 0x0E17, 0x0E19, 0x0E1C, 0x0E2B, 0x0E30, 0x0E32,
  246. 0x0E38, 0x0E39,
  247. /* GRAS */
  248. 0x8600, 0x8601, 0x8610, 0x861B, 0x8620, 0x8620, 0x8628, 0x862B,
  249. 0x8630, 0x8637,
  250. /* VPC */
  251. 0x9600, 0x9604, 0x9624, 0x9637,
  252. /* PC */
  253. 0x9E00, 0x9E01, 0x9E03, 0x9E0E, 0x9E11, 0x9E16, 0x9E19, 0x9E19,
  254. 0x9E1C, 0x9E1C, 0x9E20, 0x9E23, 0x9E30, 0x9E31, 0x9E34, 0x9E34,
  255. 0x9E70, 0x9E72, 0x9E78, 0x9E79, 0x9E80, 0x9FFF,
  256. /* VFD */
  257. 0xA600, 0xA601, 0xA603, 0xA603, 0xA60A, 0xA60A, 0xA610, 0xA617,
  258. 0xA630, 0xA630,
  259. /* HLSQ */
  260. 0xD002, 0xD003,
  261. };
  262. static const unsigned int a660_registers[] = {
  263. /* UCHE */
  264. 0x0E3C, 0x0E3C,
  265. /* LPAC RBBM */
  266. 0x05FC, 0x05FF,
  267. /* LPAC CP */
  268. 0x0B00, 0x0B40, 0x0B80, 0x0B83,
  269. };
  270. /*
  271. * Set of registers to dump for A6XX before actually triggering crash dumper.
  272. * Registers in pairs - first value is the start offset, second
  273. * is the stop offset (inclusive)
  274. */
  275. static const unsigned int a6xx_pre_crashdumper_registers[] = {
  276. /* RBBM: RBBM_STATUS - RBBM_STATUS3 */
  277. 0x210, 0x213,
  278. /* CP: CP_STATUS_1 */
  279. 0x825, 0x825,
  280. };
  281. static const unsigned int a6xx_gmu_wrapper_registers[] = {
  282. /* GMU CX */
  283. 0x1f840, 0x1f840, 0x1f844, 0x1f845, 0x1f887, 0x1f889, 0x1f8d0, 0x1f8d0,
  284. /* GMU AO*/
  285. 0x23b0C, 0x23b0E, 0x23b15, 0x23b15,
  286. };
  287. static const unsigned int a6xx_holi_gmu_wrapper_registers[] = {
  288. /* GMU SPTPRAC */
  289. 0x1a880, 0x1a881,
  290. /* GMU CX */
  291. 0x1f840, 0x1f840, 0x1f844, 0x1f845, 0x1f887, 0x1f889, 0x1f8d0, 0x1f8d0,
  292. /* GMU AO*/
  293. 0x23b0c, 0x23b0e, 0x23b15, 0x23b15,
  294. };
  295. enum a6xx_debugbus_id {
  296. A6XX_DBGBUS_CP = 0x1,
  297. A6XX_DBGBUS_RBBM = 0x2,
  298. A6XX_DBGBUS_VBIF = 0x3,
  299. A6XX_DBGBUS_HLSQ = 0x4,
  300. A6XX_DBGBUS_UCHE = 0x5,
  301. A6XX_DBGBUS_DPM = 0x6,
  302. A6XX_DBGBUS_TESS = 0x7,
  303. A6XX_DBGBUS_PC = 0x8,
  304. A6XX_DBGBUS_VFDP = 0x9,
  305. A6XX_DBGBUS_VPC = 0xa,
  306. A6XX_DBGBUS_TSE = 0xb,
  307. A6XX_DBGBUS_RAS = 0xc,
  308. A6XX_DBGBUS_VSC = 0xd,
  309. A6XX_DBGBUS_COM = 0xe,
  310. A6XX_DBGBUS_LRZ = 0x10,
  311. A6XX_DBGBUS_A2D = 0x11,
  312. A6XX_DBGBUS_CCUFCHE = 0x12,
  313. A6XX_DBGBUS_GMU_CX = 0x13,
  314. A6XX_DBGBUS_RBP = 0x14,
  315. A6XX_DBGBUS_DCS = 0x15,
  316. A6XX_DBGBUS_RBBM_CFG = 0x16,
  317. A6XX_DBGBUS_CX = 0x17,
  318. A6XX_DBGBUS_GMU_GX = 0x18,
  319. A6XX_DBGBUS_TPFCHE = 0x19,
  320. A6XX_DBGBUS_GBIF_GX = 0x1a,
  321. A6XX_DBGBUS_GPC = 0x1d,
  322. A6XX_DBGBUS_LARC = 0x1e,
  323. A6XX_DBGBUS_HLSQ_SPTP = 0x1f,
  324. A6XX_DBGBUS_RB_0 = 0x20,
  325. A6XX_DBGBUS_RB_1 = 0x21,
  326. A6XX_DBGBUS_RB_2 = 0x22,
  327. A6XX_DBGBUS_UCHE_WRAPPER = 0x24,
  328. A6XX_DBGBUS_CCU_0 = 0x28,
  329. A6XX_DBGBUS_CCU_1 = 0x29,
  330. A6XX_DBGBUS_CCU_2 = 0x2a,
  331. A6XX_DBGBUS_VFD_0 = 0x38,
  332. A6XX_DBGBUS_VFD_1 = 0x39,
  333. A6XX_DBGBUS_VFD_2 = 0x3a,
  334. A6XX_DBGBUS_VFD_3 = 0x3b,
  335. A6XX_DBGBUS_VFD_4 = 0x3c,
  336. A6XX_DBGBUS_VFD_5 = 0x3d,
  337. A6XX_DBGBUS_SP_0 = 0x40,
  338. A6XX_DBGBUS_SP_1 = 0x41,
  339. A6XX_DBGBUS_SP_2 = 0x42,
  340. A6XX_DBGBUS_TPL1_0 = 0x48,
  341. A6XX_DBGBUS_TPL1_1 = 0x49,
  342. A6XX_DBGBUS_TPL1_2 = 0x4a,
  343. A6XX_DBGBUS_TPL1_3 = 0x4b,
  344. A6XX_DBGBUS_TPL1_4 = 0x4c,
  345. A6XX_DBGBUS_TPL1_5 = 0x4d,
  346. A6XX_DBGBUS_SPTP_0 = 0x58,
  347. A6XX_DBGBUS_SPTP_1 = 0x59,
  348. A6XX_DBGBUS_SPTP_2 = 0x5a,
  349. A6XX_DBGBUS_SPTP_3 = 0x5b,
  350. A6XX_DBGBUS_SPTP_4 = 0x5c,
  351. A6XX_DBGBUS_SPTP_5 = 0x5d,
  352. };
  353. static const struct adreno_debugbus_block a6xx_dbgc_debugbus_blocks[] = {
  354. { A6XX_DBGBUS_CP, 0x100, },
  355. { A6XX_DBGBUS_RBBM, 0x100, },
  356. { A6XX_DBGBUS_HLSQ, 0x100, },
  357. { A6XX_DBGBUS_UCHE, 0x100, },
  358. { A6XX_DBGBUS_DPM, 0x100, },
  359. { A6XX_DBGBUS_TESS, 0x100, },
  360. { A6XX_DBGBUS_PC, 0x100, },
  361. { A6XX_DBGBUS_VFDP, 0x100, },
  362. { A6XX_DBGBUS_VPC, 0x100, },
  363. { A6XX_DBGBUS_TSE, 0x100, },
  364. { A6XX_DBGBUS_RAS, 0x100, },
  365. { A6XX_DBGBUS_VSC, 0x100, },
  366. { A6XX_DBGBUS_COM, 0x100, },
  367. { A6XX_DBGBUS_LRZ, 0x100, },
  368. { A6XX_DBGBUS_A2D, 0x100, },
  369. { A6XX_DBGBUS_CCUFCHE, 0x100, },
  370. { A6XX_DBGBUS_RBP, 0x100, },
  371. { A6XX_DBGBUS_DCS, 0x100, },
  372. { A6XX_DBGBUS_RBBM_CFG, 0x100, },
  373. { A6XX_DBGBUS_GMU_GX, 0x100, },
  374. { A6XX_DBGBUS_TPFCHE, 0x100, },
  375. { A6XX_DBGBUS_GPC, 0x100, },
  376. { A6XX_DBGBUS_LARC, 0x100, },
  377. { A6XX_DBGBUS_HLSQ_SPTP, 0x100, },
  378. { A6XX_DBGBUS_RB_0, 0x100, },
  379. { A6XX_DBGBUS_RB_1, 0x100, },
  380. { A6XX_DBGBUS_UCHE_WRAPPER, 0x100, },
  381. { A6XX_DBGBUS_CCU_0, 0x100, },
  382. { A6XX_DBGBUS_CCU_1, 0x100, },
  383. { A6XX_DBGBUS_VFD_0, 0x100, },
  384. { A6XX_DBGBUS_VFD_1, 0x100, },
  385. { A6XX_DBGBUS_VFD_2, 0x100, },
  386. { A6XX_DBGBUS_VFD_3, 0x100, },
  387. { A6XX_DBGBUS_SP_0, 0x100, },
  388. { A6XX_DBGBUS_SP_1, 0x100, },
  389. { A6XX_DBGBUS_TPL1_0, 0x100, },
  390. { A6XX_DBGBUS_TPL1_1, 0x100, },
  391. { A6XX_DBGBUS_TPL1_2, 0x100, },
  392. { A6XX_DBGBUS_TPL1_3, 0x100, },
  393. };
  394. static const struct adreno_debugbus_block a6xx_vbif_debugbus_blocks = {
  395. A6XX_DBGBUS_VBIF, 0x100,
  396. };
  397. static const struct adreno_debugbus_block a6xx_cx_dbgc_debugbus_blocks[] = {
  398. { A6XX_DBGBUS_GMU_CX, 0x100, },
  399. { A6XX_DBGBUS_CX, 0x100, },
  400. };
  401. static const struct adreno_debugbus_block a650_dbgc_debugbus_blocks[] = {
  402. { A6XX_DBGBUS_RB_2, 0x100, },
  403. { A6XX_DBGBUS_CCU_2, 0x100, },
  404. { A6XX_DBGBUS_VFD_4, 0x100, },
  405. { A6XX_DBGBUS_VFD_5, 0x100, },
  406. { A6XX_DBGBUS_SP_2, 0x100, },
  407. { A6XX_DBGBUS_TPL1_4, 0x100, },
  408. { A6XX_DBGBUS_TPL1_5, 0x100, },
  409. { A6XX_DBGBUS_SPTP_0, 0x100, },
  410. { A6XX_DBGBUS_SPTP_1, 0x100, },
  411. { A6XX_DBGBUS_SPTP_2, 0x100, },
  412. { A6XX_DBGBUS_SPTP_3, 0x100, },
  413. { A6XX_DBGBUS_SPTP_4, 0x100, },
  414. { A6XX_DBGBUS_SPTP_5, 0x100, },
  415. };
  416. #define A6XX_NUM_SHADER_BANKS 3
  417. #define A6XX_SHADER_STATETYPE_SHIFT 8
  418. enum a6xx_shader_obj {
  419. A6XX_TP0_TMO_DATA = 0x9,
  420. A6XX_TP0_SMO_DATA = 0xa,
  421. A6XX_TP0_MIPMAP_BASE_DATA = 0xb,
  422. A6XX_TP1_TMO_DATA = 0x19,
  423. A6XX_TP1_SMO_DATA = 0x1a,
  424. A6XX_TP1_MIPMAP_BASE_DATA = 0x1b,
  425. A6XX_SP_INST_DATA = 0x29,
  426. A6XX_SP_LB_0_DATA = 0x2a,
  427. A6XX_SP_LB_1_DATA = 0x2b,
  428. A6XX_SP_LB_2_DATA = 0x2c,
  429. A6XX_SP_LB_3_DATA = 0x2d,
  430. A6XX_SP_LB_4_DATA = 0x2e,
  431. A6XX_SP_LB_5_DATA = 0x2f,
  432. A6XX_SP_CB_BINDLESS_DATA = 0x30,
  433. A6XX_SP_CB_LEGACY_DATA = 0x31,
  434. A6XX_SP_UAV_DATA = 0x32,
  435. A6XX_SP_INST_TAG = 0x33,
  436. A6XX_SP_CB_BINDLESS_TAG = 0x34,
  437. A6XX_SP_TMO_UMO_TAG = 0x35,
  438. A6XX_SP_SMO_TAG = 0x36,
  439. A6XX_SP_STATE_DATA = 0x37,
  440. A6XX_HLSQ_CHUNK_CVS_RAM = 0x49,
  441. A6XX_HLSQ_CHUNK_CPS_RAM = 0x4a,
  442. A6XX_HLSQ_CHUNK_CVS_RAM_TAG = 0x4b,
  443. A6XX_HLSQ_CHUNK_CPS_RAM_TAG = 0x4c,
  444. A6XX_HLSQ_ICB_CVS_CB_BASE_TAG = 0x4d,
  445. A6XX_HLSQ_ICB_CPS_CB_BASE_TAG = 0x4e,
  446. A6XX_HLSQ_CVS_MISC_RAM = 0x50,
  447. A6XX_HLSQ_CPS_MISC_RAM = 0x51,
  448. A6XX_HLSQ_INST_RAM = 0x52,
  449. A6XX_HLSQ_GFX_CVS_CONST_RAM = 0x53,
  450. A6XX_HLSQ_GFX_CPS_CONST_RAM = 0x54,
  451. A6XX_HLSQ_CVS_MISC_RAM_TAG = 0x55,
  452. A6XX_HLSQ_CPS_MISC_RAM_TAG = 0x56,
  453. A6XX_HLSQ_INST_RAM_TAG = 0x57,
  454. A6XX_HLSQ_GFX_CVS_CONST_RAM_TAG = 0x58,
  455. A6XX_HLSQ_GFX_CPS_CONST_RAM_TAG = 0x59,
  456. A6XX_HLSQ_PWR_REST_RAM = 0x5a,
  457. A6XX_HLSQ_PWR_REST_TAG = 0x5b,
  458. A6XX_HLSQ_DATAPATH_META = 0x60,
  459. A6XX_HLSQ_FRONTEND_META = 0x61,
  460. A6XX_HLSQ_INDIRECT_META = 0x62,
  461. A6XX_HLSQ_BACKEND_META = 0x63,
  462. A6XX_SP_LB_6_DATA = 0x70,
  463. A6XX_SP_LB_7_DATA = 0x71,
  464. A6XX_HLSQ_INST_RAM_1 = 0x73,
  465. };
  466. struct a6xx_shader_block {
  467. unsigned int statetype;
  468. unsigned int sz;
  469. uint64_t offset;
  470. };
  471. struct a6xx_shader_block_info {
  472. struct a6xx_shader_block *block;
  473. unsigned int bank;
  474. uint64_t offset;
  475. };
  476. static struct a6xx_shader_block a6xx_shader_blocks[] = {
  477. {A6XX_TP0_TMO_DATA, 0x200},
  478. {A6XX_TP0_SMO_DATA, 0x80,},
  479. {A6XX_TP0_MIPMAP_BASE_DATA, 0x3C0},
  480. {A6XX_TP1_TMO_DATA, 0x200},
  481. {A6XX_TP1_SMO_DATA, 0x80,},
  482. {A6XX_TP1_MIPMAP_BASE_DATA, 0x3C0},
  483. {A6XX_SP_INST_DATA, 0x800},
  484. {A6XX_SP_LB_0_DATA, 0x800},
  485. {A6XX_SP_LB_1_DATA, 0x800},
  486. {A6XX_SP_LB_2_DATA, 0x800},
  487. {A6XX_SP_LB_3_DATA, 0x800},
  488. {A6XX_SP_LB_4_DATA, 0x800},
  489. {A6XX_SP_LB_5_DATA, 0x200},
  490. {A6XX_SP_CB_BINDLESS_DATA, 0x800},
  491. {A6XX_SP_CB_LEGACY_DATA, 0x280,},
  492. {A6XX_SP_UAV_DATA, 0x80,},
  493. {A6XX_SP_INST_TAG, 0x80,},
  494. {A6XX_SP_CB_BINDLESS_TAG, 0x80,},
  495. {A6XX_SP_TMO_UMO_TAG, 0x80,},
  496. {A6XX_SP_SMO_TAG, 0x80},
  497. {A6XX_SP_STATE_DATA, 0x3F},
  498. {A6XX_HLSQ_CHUNK_CVS_RAM, 0x1C0},
  499. {A6XX_HLSQ_CHUNK_CPS_RAM, 0x280},
  500. {A6XX_HLSQ_CHUNK_CVS_RAM_TAG, 0x40,},
  501. {A6XX_HLSQ_CHUNK_CPS_RAM_TAG, 0x40,},
  502. {A6XX_HLSQ_ICB_CVS_CB_BASE_TAG, 0x4,},
  503. {A6XX_HLSQ_ICB_CPS_CB_BASE_TAG, 0x4,},
  504. {A6XX_HLSQ_CVS_MISC_RAM, 0x1C0},
  505. {A6XX_HLSQ_CPS_MISC_RAM, 0x580},
  506. {A6XX_HLSQ_INST_RAM, 0x800},
  507. {A6XX_HLSQ_GFX_CVS_CONST_RAM, 0x800},
  508. {A6XX_HLSQ_GFX_CPS_CONST_RAM, 0x800},
  509. {A6XX_HLSQ_CVS_MISC_RAM_TAG, 0x8,},
  510. {A6XX_HLSQ_CPS_MISC_RAM_TAG, 0x4,},
  511. {A6XX_HLSQ_INST_RAM_TAG, 0x80,},
  512. {A6XX_HLSQ_GFX_CVS_CONST_RAM_TAG, 0xC,},
  513. {A6XX_HLSQ_GFX_CPS_CONST_RAM_TAG, 0x10},
  514. {A6XX_HLSQ_PWR_REST_RAM, 0x28},
  515. {A6XX_HLSQ_PWR_REST_TAG, 0x14},
  516. {A6XX_HLSQ_DATAPATH_META, 0x40,},
  517. {A6XX_HLSQ_FRONTEND_META, 0x40},
  518. {A6XX_HLSQ_INDIRECT_META, 0x40,},
  519. {A6XX_SP_LB_6_DATA, 0x200},
  520. {A6XX_SP_LB_7_DATA, 0x200},
  521. {A6XX_HLSQ_INST_RAM_1, 0x200},
  522. };
  523. static struct kgsl_memdesc *a6xx_capturescript;
  524. static struct kgsl_memdesc *a6xx_crashdump_registers;
  525. static bool crash_dump_valid;
  526. static u32 *a6xx_cd_reg_end;
  527. static struct reg_list {
  528. const unsigned int *regs;
  529. unsigned int count;
  530. const struct sel_reg *sel;
  531. uint64_t offset;
  532. } a6xx_reg_list[] = {
  533. { a6xx_registers, ARRAY_SIZE(a6xx_registers) / 2, NULL },
  534. { a660_registers, ARRAY_SIZE(a660_registers) / 2, NULL },
  535. { a6xx_rb_rac_registers, ARRAY_SIZE(a6xx_rb_rac_registers) / 2,
  536. &_a6xx_rb_rac_aperture },
  537. { a6xx_rb_rbp_registers, ARRAY_SIZE(a6xx_rb_rbp_registers) / 2,
  538. &_a6xx_rb_rbp_aperture },
  539. };
  540. #define REG_PAIR_COUNT(_a, _i) \
  541. (((_a)[(2 * (_i)) + 1] - (_a)[2 * (_i)]) + 1)
  542. static size_t a6xx_legacy_snapshot_registers(struct kgsl_device *device,
  543. u8 *buf, size_t remain, struct reg_list *regs)
  544. {
  545. struct kgsl_snapshot_registers snapshot_regs = {
  546. .regs = regs->regs,
  547. .count = regs->count,
  548. };
  549. if (regs->sel)
  550. kgsl_regwrite(device, regs->sel->host_reg, regs->sel->val);
  551. return kgsl_snapshot_dump_registers(device, buf, remain,
  552. &snapshot_regs);
  553. }
  554. static size_t a6xx_snapshot_registers(struct kgsl_device *device, u8 *buf,
  555. size_t remain, void *priv)
  556. {
  557. struct kgsl_snapshot_regs *header = (struct kgsl_snapshot_regs *)buf;
  558. struct reg_list *regs = (struct reg_list *)priv;
  559. unsigned int *data = (unsigned int *)(buf + sizeof(*header));
  560. unsigned int *src;
  561. unsigned int j, k;
  562. unsigned int count = 0;
  563. if (!crash_dump_valid)
  564. return a6xx_legacy_snapshot_registers(device, buf, remain,
  565. regs);
  566. if (remain < sizeof(*header)) {
  567. SNAPSHOT_ERR_NOMEM(device, "REGISTERS");
  568. return 0;
  569. }
  570. src = a6xx_crashdump_registers->hostptr + regs->offset;
  571. remain -= sizeof(*header);
  572. for (j = 0; j < regs->count; j++) {
  573. unsigned int start = regs->regs[2 * j];
  574. unsigned int end = regs->regs[(2 * j) + 1];
  575. if (remain < ((end - start) + 1) * 8) {
  576. SNAPSHOT_ERR_NOMEM(device, "REGISTERS");
  577. goto out;
  578. }
  579. remain -= ((end - start) + 1) * 8;
  580. for (k = start; k <= end; k++, count++) {
  581. *data++ = k;
  582. *data++ = *src++;
  583. }
  584. }
  585. out:
  586. header->count = count;
  587. /* Return the size of the section */
  588. return (count * 8) + sizeof(*header);
  589. }
  590. static size_t a6xx_snapshot_pre_crashdump_regs(struct kgsl_device *device,
  591. u8 *buf, size_t remain, void *priv)
  592. {
  593. struct kgsl_snapshot_registers pre_cdregs = {
  594. .regs = a6xx_pre_crashdumper_registers,
  595. .count = ARRAY_SIZE(a6xx_pre_crashdumper_registers)/2,
  596. };
  597. return kgsl_snapshot_dump_registers(device, buf, remain, &pre_cdregs);
  598. }
  599. static size_t a6xx_legacy_snapshot_shader(struct kgsl_device *device,
  600. u8 *buf, size_t remain, void *priv)
  601. {
  602. struct kgsl_snapshot_shader *header =
  603. (struct kgsl_snapshot_shader *) buf;
  604. struct a6xx_shader_block_info *info =
  605. (struct a6xx_shader_block_info *) priv;
  606. struct a6xx_shader_block *block = info->block;
  607. unsigned int *data = (unsigned int *)(buf + sizeof(*header));
  608. unsigned int read_sel, val;
  609. int i;
  610. if (!device->snapshot_legacy)
  611. return 0;
  612. if (remain < SHADER_SECTION_SZ(block->sz)) {
  613. SNAPSHOT_ERR_NOMEM(device, "SHADER MEMORY");
  614. return 0;
  615. }
  616. /*
  617. * If crashdumper times out, accessing some readback states from
  618. * AHB path might fail. Hence, skip SP_INST_TAG and SP_INST_DATA
  619. * state types during snapshot dump in legacy flow.
  620. */
  621. if (adreno_is_a660(ADRENO_DEVICE(device)) &&
  622. (block->statetype == A6XX_SP_INST_TAG ||
  623. block->statetype == A6XX_SP_INST_DATA))
  624. return 0;
  625. header->type = block->statetype;
  626. header->index = info->bank;
  627. header->size = block->sz;
  628. read_sel = (block->statetype << A6XX_SHADER_STATETYPE_SHIFT) |
  629. info->bank;
  630. kgsl_regwrite(device, A6XX_HLSQ_DBG_READ_SEL, read_sel);
  631. /*
  632. * An explicit barrier is needed so that reads do not happen before
  633. * the register write.
  634. */
  635. mb();
  636. for (i = 0; i < block->sz; i++) {
  637. kgsl_regread(device, (A6XX_HLSQ_DBG_AHB_READ_APERTURE + i),
  638. &val);
  639. *data++ = val;
  640. }
  641. return SHADER_SECTION_SZ(block->sz);
  642. }
  643. static size_t a6xx_snapshot_shader_memory(struct kgsl_device *device,
  644. u8 *buf, size_t remain, void *priv)
  645. {
  646. struct kgsl_snapshot_shader *header =
  647. (struct kgsl_snapshot_shader *) buf;
  648. struct a6xx_shader_block_info *info =
  649. (struct a6xx_shader_block_info *) priv;
  650. struct a6xx_shader_block *block = info->block;
  651. unsigned int *data = (unsigned int *) (buf + sizeof(*header));
  652. if (!crash_dump_valid)
  653. return a6xx_legacy_snapshot_shader(device, buf, remain, priv);
  654. if (remain < SHADER_SECTION_SZ(block->sz)) {
  655. SNAPSHOT_ERR_NOMEM(device, "SHADER MEMORY");
  656. return 0;
  657. }
  658. header->type = block->statetype;
  659. header->index = info->bank;
  660. header->size = block->sz;
  661. memcpy(data, a6xx_crashdump_registers->hostptr + info->offset,
  662. block->sz * sizeof(unsigned int));
  663. return SHADER_SECTION_SZ(block->sz);
  664. }
  665. static void a6xx_snapshot_shader(struct kgsl_device *device,
  666. struct kgsl_snapshot *snapshot)
  667. {
  668. unsigned int i, j;
  669. struct a6xx_shader_block_info info;
  670. for (i = 0; i < ARRAY_SIZE(a6xx_shader_blocks); i++) {
  671. for (j = 0; j < A6XX_NUM_SHADER_BANKS; j++) {
  672. info.block = &a6xx_shader_blocks[i];
  673. info.bank = j;
  674. info.offset = a6xx_shader_blocks[i].offset +
  675. (j * a6xx_shader_blocks[i].sz);
  676. /* Shader working/shadow memory */
  677. kgsl_snapshot_add_section(device,
  678. KGSL_SNAPSHOT_SECTION_SHADER,
  679. snapshot, a6xx_snapshot_shader_memory, &info);
  680. }
  681. }
  682. }
  683. static void a650_snapshot_mempool(struct kgsl_device *device,
  684. struct kgsl_snapshot *snapshot)
  685. {
  686. u32 val;
  687. /* set CP_CHICKEN_DBG[StabilizeMVC] to stabilize it while dumping */
  688. kgsl_regread(device, A6XX_CP_CHICKEN_DBG, &val);
  689. kgsl_regwrite(device, A6XX_CP_CHICKEN_DBG, val | BIT(2));
  690. kgsl_snapshot_indexed_registers(device, snapshot,
  691. A6XX_CP_MEM_POOL_DBG_ADDR, A6XX_CP_MEM_POOL_DBG_DATA,
  692. 0, 0x2100);
  693. kgsl_regwrite(device, A6XX_CP_CHICKEN_DBG, val);
  694. }
  695. static void a6xx_snapshot_mempool(struct kgsl_device *device,
  696. struct kgsl_snapshot *snapshot)
  697. {
  698. unsigned int pool_size;
  699. u8 *buf = snapshot->ptr;
  700. /* Set the mempool size to 0 to stabilize it while dumping */
  701. kgsl_regread(device, A6XX_CP_MEM_POOL_SIZE, &pool_size);
  702. kgsl_regwrite(device, A6XX_CP_MEM_POOL_SIZE, 0);
  703. kgsl_snapshot_indexed_registers(device, snapshot,
  704. A6XX_CP_MEM_POOL_DBG_ADDR, A6XX_CP_MEM_POOL_DBG_DATA,
  705. 0, 0x2100);
  706. /*
  707. * Data at offset 0x2000 in the mempool section is the mempool size.
  708. * Since we set it to 0, patch in the original size so that the data
  709. * is consistent.
  710. */
  711. if (buf < snapshot->ptr) {
  712. unsigned int *data;
  713. /* Skip over the headers */
  714. buf += sizeof(struct kgsl_snapshot_section_header) +
  715. sizeof(struct kgsl_snapshot_indexed_regs);
  716. data = (unsigned int *)buf + 0x2000;
  717. *data = pool_size;
  718. }
  719. /* Restore the saved mempool size */
  720. kgsl_regwrite(device, A6XX_CP_MEM_POOL_SIZE, pool_size);
  721. }
  722. static inline unsigned int a6xx_read_dbgahb(struct kgsl_device *device,
  723. unsigned int regbase, unsigned int reg)
  724. {
  725. unsigned int read_reg = A6XX_HLSQ_DBG_AHB_READ_APERTURE +
  726. reg - regbase / 4;
  727. unsigned int val;
  728. kgsl_regread(device, read_reg, &val);
  729. return val;
  730. }
  731. static size_t a6xx_legacy_snapshot_cluster_dbgahb(struct kgsl_device *device,
  732. u8 *buf, size_t remain, void *priv)
  733. {
  734. struct kgsl_snapshot_mvc_regs *header =
  735. (struct kgsl_snapshot_mvc_regs *)buf;
  736. struct a6xx_cluster_dbgahb_regs_info *info =
  737. (struct a6xx_cluster_dbgahb_regs_info *)priv;
  738. struct a6xx_cluster_dbgahb_registers *cur_cluster = info->cluster;
  739. unsigned int read_sel;
  740. unsigned int data_size = 0;
  741. unsigned int *data = (unsigned int *)(buf + sizeof(*header));
  742. int i, j;
  743. if (!device->snapshot_legacy)
  744. return 0;
  745. if (remain < sizeof(*header)) {
  746. SNAPSHOT_ERR_NOMEM(device, "REGISTERS");
  747. return 0;
  748. }
  749. remain -= sizeof(*header);
  750. header->ctxt_id = info->ctxt_id;
  751. header->cluster_id = cur_cluster->id;
  752. read_sel = ((cur_cluster->statetype + info->ctxt_id * 2) & 0xff) << 8;
  753. kgsl_regwrite(device, A6XX_HLSQ_DBG_READ_SEL, read_sel);
  754. /*
  755. * An explicit barrier is needed so that reads do not happen before
  756. * the register write.
  757. */
  758. mb();
  759. for (i = 0; i < cur_cluster->num_sets; i++) {
  760. unsigned int start = cur_cluster->regs[2 * i];
  761. unsigned int end = cur_cluster->regs[2 * i + 1];
  762. if (remain < (end - start + 3) * 4) {
  763. SNAPSHOT_ERR_NOMEM(device, "MVC REGISTERS");
  764. goto out;
  765. }
  766. remain -= (end - start + 3) * 4;
  767. data_size += (end - start + 3) * 4;
  768. *data++ = start | (1 << 31);
  769. *data++ = end;
  770. for (j = start; j <= end; j++) {
  771. unsigned int val;
  772. val = a6xx_read_dbgahb(device, cur_cluster->regbase, j);
  773. *data++ = val;
  774. }
  775. }
  776. out:
  777. return data_size + sizeof(*header);
  778. }
  779. static size_t a6xx_snapshot_cluster_dbgahb(struct kgsl_device *device, u8 *buf,
  780. size_t remain, void *priv)
  781. {
  782. struct kgsl_snapshot_mvc_regs *header =
  783. (struct kgsl_snapshot_mvc_regs *)buf;
  784. struct a6xx_cluster_dbgahb_regs_info *info =
  785. (struct a6xx_cluster_dbgahb_regs_info *)priv;
  786. struct a6xx_cluster_dbgahb_registers *cluster = info->cluster;
  787. unsigned int data_size = 0;
  788. unsigned int *data = (unsigned int *)(buf + sizeof(*header));
  789. int i, j;
  790. unsigned int *src;
  791. if (!crash_dump_valid)
  792. return a6xx_legacy_snapshot_cluster_dbgahb(device, buf, remain,
  793. info);
  794. if (remain < sizeof(*header)) {
  795. SNAPSHOT_ERR_NOMEM(device, "REGISTERS");
  796. return 0;
  797. }
  798. remain -= sizeof(*header);
  799. header->ctxt_id = info->ctxt_id;
  800. header->cluster_id = cluster->id;
  801. src = a6xx_crashdump_registers->hostptr +
  802. (header->ctxt_id ? cluster->offset1 : cluster->offset0);
  803. for (i = 0; i < cluster->num_sets; i++) {
  804. unsigned int start;
  805. unsigned int end;
  806. start = cluster->regs[2 * i];
  807. end = cluster->regs[2 * i + 1];
  808. if (remain < (end - start + 3) * 4) {
  809. SNAPSHOT_ERR_NOMEM(device, "MVC REGISTERS");
  810. goto out;
  811. }
  812. remain -= (end - start + 3) * 4;
  813. data_size += (end - start + 3) * 4;
  814. *data++ = start | (1 << 31);
  815. *data++ = end;
  816. for (j = start; j <= end; j++)
  817. *data++ = *src++;
  818. }
  819. out:
  820. return data_size + sizeof(*header);
  821. }
  822. static size_t a6xx_legacy_snapshot_non_ctx_dbgahb(struct kgsl_device *device,
  823. u8 *buf, size_t remain, void *priv)
  824. {
  825. struct kgsl_snapshot_regs *header =
  826. (struct kgsl_snapshot_regs *)buf;
  827. struct a6xx_non_ctx_dbgahb_registers *regs =
  828. (struct a6xx_non_ctx_dbgahb_registers *)priv;
  829. unsigned int *data = (unsigned int *)(buf + sizeof(*header));
  830. int count = 0;
  831. unsigned int read_sel;
  832. int i, j;
  833. if (!device->snapshot_legacy)
  834. return 0;
  835. /* Figure out how many registers we are going to dump */
  836. for (i = 0; i < regs->num_sets; i++) {
  837. int start = regs->regs[i * 2];
  838. int end = regs->regs[i * 2 + 1];
  839. count += (end - start + 1);
  840. }
  841. if (remain < (count * 8) + sizeof(*header)) {
  842. SNAPSHOT_ERR_NOMEM(device, "REGISTERS");
  843. return 0;
  844. }
  845. header->count = count;
  846. read_sel = (regs->statetype & 0xff) << 8;
  847. kgsl_regwrite(device, A6XX_HLSQ_DBG_READ_SEL, read_sel);
  848. for (i = 0; i < regs->num_sets; i++) {
  849. unsigned int start = regs->regs[2 * i];
  850. unsigned int end = regs->regs[2 * i + 1];
  851. for (j = start; j <= end; j++) {
  852. unsigned int val;
  853. val = a6xx_read_dbgahb(device, regs->regbase, j);
  854. *data++ = j;
  855. *data++ = val;
  856. }
  857. }
  858. return (count * 8) + sizeof(*header);
  859. }
  860. static size_t a6xx_snapshot_non_ctx_dbgahb(struct kgsl_device *device, u8 *buf,
  861. size_t remain, void *priv)
  862. {
  863. struct kgsl_snapshot_regs *header =
  864. (struct kgsl_snapshot_regs *)buf;
  865. struct a6xx_non_ctx_dbgahb_registers *regs =
  866. (struct a6xx_non_ctx_dbgahb_registers *)priv;
  867. unsigned int count = 0;
  868. unsigned int *data = (unsigned int *)(buf + sizeof(*header));
  869. unsigned int i, k;
  870. unsigned int *src;
  871. if (!crash_dump_valid)
  872. return a6xx_legacy_snapshot_non_ctx_dbgahb(device, buf, remain,
  873. regs);
  874. if (remain < sizeof(*header)) {
  875. SNAPSHOT_ERR_NOMEM(device, "REGISTERS");
  876. return 0;
  877. }
  878. remain -= sizeof(*header);
  879. src = a6xx_crashdump_registers->hostptr + regs->offset;
  880. for (i = 0; i < regs->num_sets; i++) {
  881. unsigned int start;
  882. unsigned int end;
  883. start = regs->regs[2 * i];
  884. end = regs->regs[(2 * i) + 1];
  885. if (remain < (end - start + 1) * 8) {
  886. SNAPSHOT_ERR_NOMEM(device, "REGISTERS");
  887. goto out;
  888. }
  889. remain -= ((end - start) + 1) * 8;
  890. for (k = start; k <= end; k++, count++) {
  891. *data++ = k;
  892. *data++ = *src++;
  893. }
  894. }
  895. out:
  896. header->count = count;
  897. /* Return the size of the section */
  898. return (count * 8) + sizeof(*header);
  899. }
  900. static void a6xx_snapshot_dbgahb_regs(struct kgsl_device *device,
  901. struct kgsl_snapshot *snapshot)
  902. {
  903. int i, j;
  904. for (i = 0; i < ARRAY_SIZE(a6xx_dbgahb_ctx_clusters); i++) {
  905. struct a6xx_cluster_dbgahb_registers *cluster =
  906. &a6xx_dbgahb_ctx_clusters[i];
  907. struct a6xx_cluster_dbgahb_regs_info info;
  908. info.cluster = cluster;
  909. for (j = 0; j < A6XX_NUM_CTXTS; j++) {
  910. info.ctxt_id = j;
  911. kgsl_snapshot_add_section(device,
  912. KGSL_SNAPSHOT_SECTION_MVC, snapshot,
  913. a6xx_snapshot_cluster_dbgahb, &info);
  914. }
  915. }
  916. for (i = 0; i < ARRAY_SIZE(a6xx_non_ctx_dbgahb); i++) {
  917. kgsl_snapshot_add_section(device,
  918. KGSL_SNAPSHOT_SECTION_REGS, snapshot,
  919. a6xx_snapshot_non_ctx_dbgahb, &a6xx_non_ctx_dbgahb[i]);
  920. }
  921. }
  922. static size_t a6xx_legacy_snapshot_mvc(struct kgsl_device *device, u8 *buf,
  923. size_t remain, void *priv)
  924. {
  925. struct kgsl_snapshot_mvc_regs *header =
  926. (struct kgsl_snapshot_mvc_regs *)buf;
  927. struct a6xx_cluster_regs_info *info =
  928. (struct a6xx_cluster_regs_info *)priv;
  929. struct a6xx_cluster_registers *cur_cluster = info->cluster;
  930. unsigned int *data = (unsigned int *)(buf + sizeof(*header));
  931. unsigned int ctxt = info->ctxt_id;
  932. unsigned int start, end, i, j, aperture_cntl = 0;
  933. unsigned int data_size = 0;
  934. if (remain < sizeof(*header)) {
  935. SNAPSHOT_ERR_NOMEM(device, "MVC REGISTERS");
  936. return 0;
  937. }
  938. remain -= sizeof(*header);
  939. header->ctxt_id = info->ctxt_id;
  940. header->cluster_id = cur_cluster->id;
  941. /*
  942. * Set the AHB control for the Host to read from the
  943. * cluster/context for this iteration.
  944. */
  945. aperture_cntl = ((cur_cluster->id & 0x7) << 8) | (ctxt << 4) | ctxt;
  946. kgsl_regwrite(device, A6XX_CP_APERTURE_CNTL_HOST, aperture_cntl);
  947. if (cur_cluster->sel)
  948. kgsl_regwrite(device, cur_cluster->sel->host_reg,
  949. cur_cluster->sel->val);
  950. for (i = 0; i < cur_cluster->num_sets; i++) {
  951. start = cur_cluster->regs[2 * i];
  952. end = cur_cluster->regs[2 * i + 1];
  953. if (remain < (end - start + 3) * 4) {
  954. SNAPSHOT_ERR_NOMEM(device, "MVC REGISTERS");
  955. goto out;
  956. }
  957. remain -= (end - start + 3) * 4;
  958. data_size += (end - start + 3) * 4;
  959. *data++ = start | (1 << 31);
  960. *data++ = end;
  961. for (j = start; j <= end; j++) {
  962. unsigned int val;
  963. kgsl_regread(device, j, &val);
  964. *data++ = val;
  965. }
  966. }
  967. out:
  968. return data_size + sizeof(*header);
  969. }
  970. static size_t a6xx_snapshot_mvc(struct kgsl_device *device, u8 *buf,
  971. size_t remain, void *priv)
  972. {
  973. struct kgsl_snapshot_mvc_regs *header =
  974. (struct kgsl_snapshot_mvc_regs *)buf;
  975. struct a6xx_cluster_regs_info *info =
  976. (struct a6xx_cluster_regs_info *)priv;
  977. struct a6xx_cluster_registers *cluster = info->cluster;
  978. unsigned int *data = (unsigned int *)(buf + sizeof(*header));
  979. unsigned int *src;
  980. int i, j;
  981. unsigned int start, end;
  982. size_t data_size = 0;
  983. if (!crash_dump_valid)
  984. return a6xx_legacy_snapshot_mvc(device, buf, remain, info);
  985. if (remain < sizeof(*header)) {
  986. SNAPSHOT_ERR_NOMEM(device, "MVC REGISTERS");
  987. return 0;
  988. }
  989. remain -= sizeof(*header);
  990. header->ctxt_id = info->ctxt_id;
  991. header->cluster_id = cluster->id;
  992. src = a6xx_crashdump_registers->hostptr +
  993. (header->ctxt_id ? cluster->offset1 : cluster->offset0);
  994. for (i = 0; i < cluster->num_sets; i++) {
  995. start = cluster->regs[2 * i];
  996. end = cluster->regs[2 * i + 1];
  997. if (remain < (end - start + 3) * 4) {
  998. SNAPSHOT_ERR_NOMEM(device, "MVC REGISTERS");
  999. goto out;
  1000. }
  1001. remain -= (end - start + 3) * 4;
  1002. data_size += (end - start + 3) * 4;
  1003. *data++ = start | (1 << 31);
  1004. *data++ = end;
  1005. for (j = start; j <= end; j++)
  1006. *data++ = *src++;
  1007. }
  1008. out:
  1009. return data_size + sizeof(*header);
  1010. }
  1011. static void a6xx_snapshot_mvc_regs(struct kgsl_device *device,
  1012. struct kgsl_snapshot *snapshot)
  1013. {
  1014. int i, j;
  1015. struct a6xx_cluster_regs_info info;
  1016. for (i = 0; i < ARRAY_SIZE(a6xx_clusters); i++) {
  1017. struct a6xx_cluster_registers *cluster = &a6xx_clusters[i];
  1018. /* Skip registers that dont exists on targets other than A660 */
  1019. if (!adreno_is_a660(ADRENO_DEVICE(device)) &&
  1020. (cluster->regs == a660_fe_cluster))
  1021. continue;
  1022. info.cluster = cluster;
  1023. for (j = 0; j < A6XX_NUM_CTXTS; j++) {
  1024. info.ctxt_id = j;
  1025. kgsl_snapshot_add_section(device,
  1026. KGSL_SNAPSHOT_SECTION_MVC, snapshot,
  1027. a6xx_snapshot_mvc, &info);
  1028. }
  1029. }
  1030. }
  1031. /* a6xx_dbgc_debug_bus_read() - Read data from trace bus */
  1032. static void a6xx_dbgc_debug_bus_read(struct kgsl_device *device,
  1033. unsigned int block_id, unsigned int index, unsigned int *val)
  1034. {
  1035. unsigned int reg;
  1036. reg = (block_id << A6XX_DBGC_CFG_DBGBUS_SEL_PING_BLK_SEL_SHIFT) |
  1037. (index << A6XX_DBGC_CFG_DBGBUS_SEL_PING_INDEX_SHIFT);
  1038. kgsl_regwrite(device, A6XX_DBGC_CFG_DBGBUS_SEL_A, reg);
  1039. kgsl_regwrite(device, A6XX_DBGC_CFG_DBGBUS_SEL_B, reg);
  1040. kgsl_regwrite(device, A6XX_DBGC_CFG_DBGBUS_SEL_C, reg);
  1041. kgsl_regwrite(device, A6XX_DBGC_CFG_DBGBUS_SEL_D, reg);
  1042. /*
  1043. * There needs to be a delay of 1 us to ensure enough time for correct
  1044. * data is funneled into the trace buffer
  1045. */
  1046. udelay(1);
  1047. kgsl_regread(device, A6XX_DBGC_CFG_DBGBUS_TRACE_BUF2, val);
  1048. val++;
  1049. kgsl_regread(device, A6XX_DBGC_CFG_DBGBUS_TRACE_BUF1, val);
  1050. }
  1051. /* a6xx_snapshot_dbgc_debugbus_block() - Capture debug data for a gpu block */
  1052. static size_t a6xx_snapshot_dbgc_debugbus_block(struct kgsl_device *device,
  1053. u8 *buf, size_t remain, void *priv)
  1054. {
  1055. struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
  1056. struct kgsl_snapshot_debugbus *header =
  1057. (struct kgsl_snapshot_debugbus *)buf;
  1058. struct adreno_debugbus_block *block = priv;
  1059. int i;
  1060. unsigned int *data = (unsigned int *)(buf + sizeof(*header));
  1061. unsigned int dwords;
  1062. unsigned int block_id;
  1063. size_t size;
  1064. dwords = block->dwords;
  1065. /* For a6xx each debug bus data unit is 2 DWORDS */
  1066. size = (dwords * sizeof(unsigned int) * 2) + sizeof(*header);
  1067. if (remain < size) {
  1068. SNAPSHOT_ERR_NOMEM(device, "DEBUGBUS");
  1069. return 0;
  1070. }
  1071. header->id = block->block_id;
  1072. if ((block->block_id == A6XX_DBGBUS_VBIF) && !adreno_is_a630(adreno_dev))
  1073. header->id = A6XX_DBGBUS_GBIF_GX;
  1074. header->count = dwords * 2;
  1075. block_id = block->block_id;
  1076. /* GMU_GX data is read using the GMU_CX block id on A630 */
  1077. if ((adreno_is_a630(adreno_dev) || adreno_is_a615_family(adreno_dev)) &&
  1078. (block_id == A6XX_DBGBUS_GMU_GX))
  1079. block_id = A6XX_DBGBUS_GMU_CX;
  1080. for (i = 0; i < dwords; i++)
  1081. a6xx_dbgc_debug_bus_read(device, block_id, i, &data[i*2]);
  1082. return size;
  1083. }
  1084. /* a6xx_snapshot_vbif_debugbus_block() - Capture debug data for VBIF block */
  1085. static size_t a6xx_snapshot_vbif_debugbus_block(struct kgsl_device *device,
  1086. u8 *buf, size_t remain, void *priv)
  1087. {
  1088. struct kgsl_snapshot_debugbus *header =
  1089. (struct kgsl_snapshot_debugbus *)buf;
  1090. struct adreno_debugbus_block *block = priv;
  1091. int i, j;
  1092. /*
  1093. * Total number of VBIF data words considering 3 sections:
  1094. * 2 arbiter blocks of 16 words
  1095. * 5 AXI XIN blocks of 18 dwords each
  1096. * 4 core clock side XIN blocks of 12 dwords each
  1097. */
  1098. unsigned int dwords = (16 * A6XX_NUM_AXI_ARB_BLOCKS) +
  1099. (18 * A6XX_NUM_XIN_AXI_BLOCKS) +
  1100. (12 * A6XX_NUM_XIN_CORE_BLOCKS);
  1101. unsigned int *data = (unsigned int *)(buf + sizeof(*header));
  1102. size_t size;
  1103. unsigned int reg_clk;
  1104. size = (dwords * sizeof(unsigned int)) + sizeof(*header);
  1105. if (remain < size) {
  1106. SNAPSHOT_ERR_NOMEM(device, "DEBUGBUS");
  1107. return 0;
  1108. }
  1109. header->id = block->block_id;
  1110. header->count = dwords;
  1111. kgsl_regread(device, A6XX_VBIF_CLKON, &reg_clk);
  1112. kgsl_regwrite(device, A6XX_VBIF_CLKON, reg_clk |
  1113. (A6XX_VBIF_CLKON_FORCE_ON_TESTBUS_MASK <<
  1114. A6XX_VBIF_CLKON_FORCE_ON_TESTBUS_SHIFT));
  1115. kgsl_regwrite(device, A6XX_VBIF_TEST_BUS1_CTRL0, 0);
  1116. kgsl_regwrite(device, A6XX_VBIF_TEST_BUS_OUT_CTRL,
  1117. (A6XX_VBIF_TEST_BUS_OUT_CTRL_EN_MASK <<
  1118. A6XX_VBIF_TEST_BUS_OUT_CTRL_EN_SHIFT));
  1119. for (i = 0; i < A6XX_NUM_AXI_ARB_BLOCKS; i++) {
  1120. kgsl_regwrite(device, A6XX_VBIF_TEST_BUS2_CTRL0,
  1121. (1 << (i + 16)));
  1122. for (j = 0; j < 16; j++) {
  1123. kgsl_regwrite(device, A6XX_VBIF_TEST_BUS2_CTRL1,
  1124. ((j & A6XX_VBIF_TEST_BUS2_CTRL1_DATA_SEL_MASK)
  1125. << A6XX_VBIF_TEST_BUS2_CTRL1_DATA_SEL_SHIFT));
  1126. kgsl_regread(device, A6XX_VBIF_TEST_BUS_OUT,
  1127. data);
  1128. data++;
  1129. }
  1130. }
  1131. /* XIN blocks AXI side */
  1132. for (i = 0; i < A6XX_NUM_XIN_AXI_BLOCKS; i++) {
  1133. kgsl_regwrite(device, A6XX_VBIF_TEST_BUS2_CTRL0, 1 << i);
  1134. for (j = 0; j < 18; j++) {
  1135. kgsl_regwrite(device, A6XX_VBIF_TEST_BUS2_CTRL1,
  1136. ((j & A6XX_VBIF_TEST_BUS2_CTRL1_DATA_SEL_MASK)
  1137. << A6XX_VBIF_TEST_BUS2_CTRL1_DATA_SEL_SHIFT));
  1138. kgsl_regread(device, A6XX_VBIF_TEST_BUS_OUT,
  1139. data);
  1140. data++;
  1141. }
  1142. }
  1143. kgsl_regwrite(device, A6XX_VBIF_TEST_BUS2_CTRL0, 0);
  1144. /* XIN blocks core clock side */
  1145. for (i = 0; i < A6XX_NUM_XIN_CORE_BLOCKS; i++) {
  1146. kgsl_regwrite(device, A6XX_VBIF_TEST_BUS1_CTRL0, 1 << i);
  1147. for (j = 0; j < 12; j++) {
  1148. kgsl_regwrite(device, A6XX_VBIF_TEST_BUS1_CTRL1,
  1149. ((j & A6XX_VBIF_TEST_BUS1_CTRL1_DATA_SEL_MASK)
  1150. << A6XX_VBIF_TEST_BUS1_CTRL1_DATA_SEL_SHIFT));
  1151. kgsl_regread(device, A6XX_VBIF_TEST_BUS_OUT,
  1152. data);
  1153. data++;
  1154. }
  1155. }
  1156. /* restore the clock of VBIF */
  1157. kgsl_regwrite(device, A6XX_VBIF_CLKON, reg_clk);
  1158. return size;
  1159. }
  1160. /* a6xx_cx_dbgc_debug_bus_read() - Read data from trace bus */
  1161. static void a6xx_cx_debug_bus_read(struct kgsl_device *device,
  1162. unsigned int block_id, unsigned int index, unsigned int *val)
  1163. {
  1164. unsigned int reg;
  1165. reg = (block_id << A6XX_CX_DBGC_CFG_DBGBUS_SEL_PING_BLK_SEL_SHIFT) |
  1166. (index << A6XX_CX_DBGC_CFG_DBGBUS_SEL_PING_INDEX_SHIFT);
  1167. kgsl_regwrite(device, A6XX_CX_DBGC_CFG_DBGBUS_SEL_A, reg);
  1168. kgsl_regwrite(device, A6XX_CX_DBGC_CFG_DBGBUS_SEL_B, reg);
  1169. kgsl_regwrite(device, A6XX_CX_DBGC_CFG_DBGBUS_SEL_C, reg);
  1170. kgsl_regwrite(device, A6XX_CX_DBGC_CFG_DBGBUS_SEL_D, reg);
  1171. /*
  1172. * There needs to be a delay of 1 us to ensure enough time for correct
  1173. * data is funneled into the trace buffer
  1174. */
  1175. udelay(1);
  1176. kgsl_regread(device, A6XX_CX_DBGC_CFG_DBGBUS_TRACE_BUF2, val);
  1177. val++;
  1178. kgsl_regread(device, A6XX_CX_DBGC_CFG_DBGBUS_TRACE_BUF1, val);
  1179. }
  1180. /*
  1181. * a6xx_snapshot_cx_dbgc_debugbus_block() - Capture debug data for a gpu
  1182. * block from the CX DBGC block
  1183. */
  1184. static size_t a6xx_snapshot_cx_dbgc_debugbus_block(struct kgsl_device *device,
  1185. u8 *buf, size_t remain, void *priv)
  1186. {
  1187. struct kgsl_snapshot_debugbus *header =
  1188. (struct kgsl_snapshot_debugbus *)buf;
  1189. struct adreno_debugbus_block *block = priv;
  1190. int i;
  1191. unsigned int *data = (unsigned int *)(buf + sizeof(*header));
  1192. unsigned int dwords;
  1193. size_t size;
  1194. dwords = block->dwords;
  1195. /* For a6xx each debug bus data unit is 2 DWRODS */
  1196. size = (dwords * sizeof(unsigned int) * 2) + sizeof(*header);
  1197. if (remain < size) {
  1198. SNAPSHOT_ERR_NOMEM(device, "DEBUGBUS");
  1199. return 0;
  1200. }
  1201. header->id = block->block_id;
  1202. header->count = dwords * 2;
  1203. for (i = 0; i < dwords; i++)
  1204. a6xx_cx_debug_bus_read(device, block->block_id, i,
  1205. &data[i*2]);
  1206. return size;
  1207. }
  1208. /* a6xx_snapshot_debugbus() - Capture debug bus data */
  1209. static void a6xx_snapshot_debugbus(struct adreno_device *adreno_dev,
  1210. struct kgsl_snapshot *snapshot)
  1211. {
  1212. int i;
  1213. struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
  1214. kgsl_regwrite(device, A6XX_DBGC_CFG_DBGBUS_CNTLT,
  1215. (0xf << A6XX_DBGC_CFG_DBGBUS_CNTLT_SEGT_SHIFT) |
  1216. (0x0 << A6XX_DBGC_CFG_DBGBUS_CNTLT_GRANU_SHIFT) |
  1217. (0x0 << A6XX_DBGC_CFG_DBGBUS_CNTLT_TRACEEN_SHIFT));
  1218. kgsl_regwrite(device, A6XX_DBGC_CFG_DBGBUS_CNTLM,
  1219. 0xf << A6XX_DBGC_CFG_DBGBUS_CTLTM_ENABLE_SHIFT);
  1220. kgsl_regwrite(device, A6XX_DBGC_CFG_DBGBUS_IVTL_0, 0);
  1221. kgsl_regwrite(device, A6XX_DBGC_CFG_DBGBUS_IVTL_1, 0);
  1222. kgsl_regwrite(device, A6XX_DBGC_CFG_DBGBUS_IVTL_2, 0);
  1223. kgsl_regwrite(device, A6XX_DBGC_CFG_DBGBUS_IVTL_3, 0);
  1224. kgsl_regwrite(device, A6XX_DBGC_CFG_DBGBUS_BYTEL_0,
  1225. (0 << A6XX_DBGC_CFG_DBGBUS_BYTEL0_SHIFT) |
  1226. (1 << A6XX_DBGC_CFG_DBGBUS_BYTEL1_SHIFT) |
  1227. (2 << A6XX_DBGC_CFG_DBGBUS_BYTEL2_SHIFT) |
  1228. (3 << A6XX_DBGC_CFG_DBGBUS_BYTEL3_SHIFT) |
  1229. (4 << A6XX_DBGC_CFG_DBGBUS_BYTEL4_SHIFT) |
  1230. (5 << A6XX_DBGC_CFG_DBGBUS_BYTEL5_SHIFT) |
  1231. (6 << A6XX_DBGC_CFG_DBGBUS_BYTEL6_SHIFT) |
  1232. (7 << A6XX_DBGC_CFG_DBGBUS_BYTEL7_SHIFT));
  1233. kgsl_regwrite(device, A6XX_DBGC_CFG_DBGBUS_BYTEL_1,
  1234. (8 << A6XX_DBGC_CFG_DBGBUS_BYTEL8_SHIFT) |
  1235. (9 << A6XX_DBGC_CFG_DBGBUS_BYTEL9_SHIFT) |
  1236. (10 << A6XX_DBGC_CFG_DBGBUS_BYTEL10_SHIFT) |
  1237. (11 << A6XX_DBGC_CFG_DBGBUS_BYTEL11_SHIFT) |
  1238. (12 << A6XX_DBGC_CFG_DBGBUS_BYTEL12_SHIFT) |
  1239. (13 << A6XX_DBGC_CFG_DBGBUS_BYTEL13_SHIFT) |
  1240. (14 << A6XX_DBGC_CFG_DBGBUS_BYTEL14_SHIFT) |
  1241. (15 << A6XX_DBGC_CFG_DBGBUS_BYTEL15_SHIFT));
  1242. kgsl_regwrite(device, A6XX_DBGC_CFG_DBGBUS_MASKL_0, 0);
  1243. kgsl_regwrite(device, A6XX_DBGC_CFG_DBGBUS_MASKL_1, 0);
  1244. kgsl_regwrite(device, A6XX_DBGC_CFG_DBGBUS_MASKL_2, 0);
  1245. kgsl_regwrite(device, A6XX_DBGC_CFG_DBGBUS_MASKL_3, 0);
  1246. kgsl_regwrite(device, A6XX_CX_DBGC_CFG_DBGBUS_CNTLT,
  1247. (0xf << A6XX_DBGC_CFG_DBGBUS_CNTLT_SEGT_SHIFT) |
  1248. (0x0 << A6XX_DBGC_CFG_DBGBUS_CNTLT_GRANU_SHIFT) |
  1249. (0x0 << A6XX_DBGC_CFG_DBGBUS_CNTLT_TRACEEN_SHIFT));
  1250. kgsl_regwrite(device, A6XX_CX_DBGC_CFG_DBGBUS_CNTLM,
  1251. 0xf << A6XX_CX_DBGC_CFG_DBGBUS_CNTLM_ENABLE_SHIFT);
  1252. kgsl_regwrite(device, A6XX_CX_DBGC_CFG_DBGBUS_IVTL_0, 0);
  1253. kgsl_regwrite(device, A6XX_CX_DBGC_CFG_DBGBUS_IVTL_1, 0);
  1254. kgsl_regwrite(device, A6XX_CX_DBGC_CFG_DBGBUS_IVTL_2, 0);
  1255. kgsl_regwrite(device, A6XX_CX_DBGC_CFG_DBGBUS_IVTL_3, 0);
  1256. kgsl_regwrite(device, A6XX_CX_DBGC_CFG_DBGBUS_BYTEL_0,
  1257. (0 << A6XX_CX_DBGC_CFG_DBGBUS_BYTEL0_SHIFT) |
  1258. (1 << A6XX_CX_DBGC_CFG_DBGBUS_BYTEL1_SHIFT) |
  1259. (2 << A6XX_CX_DBGC_CFG_DBGBUS_BYTEL2_SHIFT) |
  1260. (3 << A6XX_CX_DBGC_CFG_DBGBUS_BYTEL3_SHIFT) |
  1261. (4 << A6XX_CX_DBGC_CFG_DBGBUS_BYTEL4_SHIFT) |
  1262. (5 << A6XX_CX_DBGC_CFG_DBGBUS_BYTEL5_SHIFT) |
  1263. (6 << A6XX_CX_DBGC_CFG_DBGBUS_BYTEL6_SHIFT) |
  1264. (7 << A6XX_CX_DBGC_CFG_DBGBUS_BYTEL7_SHIFT));
  1265. kgsl_regwrite(device, A6XX_CX_DBGC_CFG_DBGBUS_BYTEL_1,
  1266. (8 << A6XX_CX_DBGC_CFG_DBGBUS_BYTEL8_SHIFT) |
  1267. (9 << A6XX_CX_DBGC_CFG_DBGBUS_BYTEL9_SHIFT) |
  1268. (10 << A6XX_CX_DBGC_CFG_DBGBUS_BYTEL10_SHIFT) |
  1269. (11 << A6XX_CX_DBGC_CFG_DBGBUS_BYTEL11_SHIFT) |
  1270. (12 << A6XX_CX_DBGC_CFG_DBGBUS_BYTEL12_SHIFT) |
  1271. (13 << A6XX_CX_DBGC_CFG_DBGBUS_BYTEL13_SHIFT) |
  1272. (14 << A6XX_CX_DBGC_CFG_DBGBUS_BYTEL14_SHIFT) |
  1273. (15 << A6XX_CX_DBGC_CFG_DBGBUS_BYTEL15_SHIFT));
  1274. kgsl_regwrite(device, A6XX_CX_DBGC_CFG_DBGBUS_MASKL_0, 0);
  1275. kgsl_regwrite(device, A6XX_CX_DBGC_CFG_DBGBUS_MASKL_1, 0);
  1276. kgsl_regwrite(device, A6XX_CX_DBGC_CFG_DBGBUS_MASKL_2, 0);
  1277. kgsl_regwrite(device, A6XX_CX_DBGC_CFG_DBGBUS_MASKL_3, 0);
  1278. for (i = 0; i < ARRAY_SIZE(a6xx_dbgc_debugbus_blocks); i++) {
  1279. kgsl_snapshot_add_section(device,
  1280. KGSL_SNAPSHOT_SECTION_DEBUGBUS,
  1281. snapshot, a6xx_snapshot_dbgc_debugbus_block,
  1282. (void *) &a6xx_dbgc_debugbus_blocks[i]);
  1283. }
  1284. if (adreno_is_a650_family(adreno_dev)) {
  1285. for (i = 0; i < ARRAY_SIZE(a650_dbgc_debugbus_blocks); i++) {
  1286. kgsl_snapshot_add_section(device,
  1287. KGSL_SNAPSHOT_SECTION_DEBUGBUS,
  1288. snapshot, a6xx_snapshot_dbgc_debugbus_block,
  1289. (void *) &a650_dbgc_debugbus_blocks[i]);
  1290. }
  1291. }
  1292. /*
  1293. * GBIF has same debugbus as of other GPU blocks hence fall back to
  1294. * default path if GPU uses GBIF.
  1295. * GBIF uses exactly same ID as of VBIF so use it as it is.
  1296. */
  1297. if (!adreno_is_a630(adreno_dev))
  1298. kgsl_snapshot_add_section(device,
  1299. KGSL_SNAPSHOT_SECTION_DEBUGBUS,
  1300. snapshot, a6xx_snapshot_dbgc_debugbus_block,
  1301. (void *) &a6xx_vbif_debugbus_blocks);
  1302. else
  1303. kgsl_snapshot_add_section(device,
  1304. KGSL_SNAPSHOT_SECTION_DEBUGBUS,
  1305. snapshot, a6xx_snapshot_vbif_debugbus_block,
  1306. (void *) &a6xx_vbif_debugbus_blocks);
  1307. /* Dump the CX debugbus data if the block exists */
  1308. if (kgsl_regmap_valid_offset(&device->regmap, A6XX_CX_DBGC_CFG_DBGBUS_SEL_A)) {
  1309. for (i = 0; i < ARRAY_SIZE(a6xx_cx_dbgc_debugbus_blocks); i++) {
  1310. kgsl_snapshot_add_section(device,
  1311. KGSL_SNAPSHOT_SECTION_DEBUGBUS,
  1312. snapshot, a6xx_snapshot_cx_dbgc_debugbus_block,
  1313. (void *) &a6xx_cx_dbgc_debugbus_blocks[i]);
  1314. }
  1315. /*
  1316. * Get debugbus for GBIF CX part if GPU has GBIF block
  1317. * GBIF uses exactly same ID as of VBIF so use
  1318. * it as it is.
  1319. */
  1320. if (!adreno_is_a630(adreno_dev))
  1321. kgsl_snapshot_add_section(device,
  1322. KGSL_SNAPSHOT_SECTION_DEBUGBUS,
  1323. snapshot,
  1324. a6xx_snapshot_cx_dbgc_debugbus_block,
  1325. (void *) &a6xx_vbif_debugbus_blocks);
  1326. }
  1327. }
  1328. /* a6xx_snapshot_sqe() - Dump SQE data in snapshot */
  1329. static size_t a6xx_snapshot_sqe(struct kgsl_device *device, u8 *buf,
  1330. size_t remain, void *priv)
  1331. {
  1332. struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
  1333. struct kgsl_snapshot_debug *header = (struct kgsl_snapshot_debug *)buf;
  1334. unsigned int *data = (unsigned int *)(buf + sizeof(*header));
  1335. struct adreno_firmware *fw = ADRENO_FW(adreno_dev, ADRENO_FW_SQE);
  1336. if (remain < DEBUG_SECTION_SZ(1)) {
  1337. SNAPSHOT_ERR_NOMEM(device, "SQE VERSION DEBUG");
  1338. return 0;
  1339. }
  1340. /* Dump the SQE firmware version */
  1341. header->type = SNAPSHOT_DEBUG_SQE_VERSION;
  1342. header->size = 1;
  1343. *data = fw->version;
  1344. return DEBUG_SECTION_SZ(1);
  1345. }
  1346. static void _a6xx_do_crashdump(struct kgsl_device *device)
  1347. {
  1348. u32 val = 0;
  1349. ktime_t timeout;
  1350. crash_dump_valid = false;
  1351. if (!device->snapshot_crashdumper)
  1352. return;
  1353. if (IS_ERR_OR_NULL(a6xx_capturescript) ||
  1354. IS_ERR_OR_NULL(a6xx_crashdump_registers))
  1355. return;
  1356. /* IF the SMMU is stalled we cannot do a crash dump */
  1357. if (adreno_smmu_is_stalled(ADRENO_DEVICE(device)))
  1358. return;
  1359. /* Turn on APRIV for legacy targets so we can access the buffers */
  1360. if (!ADRENO_FEATURE(ADRENO_DEVICE(device), ADRENO_APRIV))
  1361. kgsl_regwrite(device, A6XX_CP_MISC_CNTL, 1);
  1362. kgsl_regwrite(device, A6XX_CP_CRASH_SCRIPT_BASE_LO,
  1363. lower_32_bits(a6xx_capturescript->gpuaddr));
  1364. kgsl_regwrite(device, A6XX_CP_CRASH_SCRIPT_BASE_HI,
  1365. upper_32_bits(a6xx_capturescript->gpuaddr));
  1366. kgsl_regwrite(device, A6XX_CP_CRASH_DUMP_CNTL, 1);
  1367. timeout = ktime_add_ms(ktime_get(), CP_CRASH_DUMPER_TIMEOUT);
  1368. if (!device->snapshot_atomic)
  1369. might_sleep();
  1370. for (;;) {
  1371. /* make sure we're reading the latest value */
  1372. rmb();
  1373. if ((*a6xx_cd_reg_end) != 0xaaaaaaaa)
  1374. break;
  1375. if (ktime_compare(ktime_get(), timeout) > 0)
  1376. break;
  1377. /* Wait 1msec to avoid unnecessary looping */
  1378. if (!device->snapshot_atomic)
  1379. usleep_range(100, 1000);
  1380. }
  1381. kgsl_regread(device, A6XX_CP_CRASH_DUMP_STATUS, &val);
  1382. if (!ADRENO_FEATURE(ADRENO_DEVICE(device), ADRENO_APRIV))
  1383. kgsl_regwrite(device, A6XX_CP_MISC_CNTL, 0);
  1384. if (!(val & 0x2)) {
  1385. dev_err(device->dev, "Crash dump timed out: 0x%X\n", val);
  1386. return;
  1387. }
  1388. crash_dump_valid = true;
  1389. }
  1390. static size_t a6xx_snapshot_isense_registers(struct kgsl_device *device,
  1391. u8 *buf, size_t remain, void *priv)
  1392. {
  1393. struct kgsl_snapshot_regs *header = (struct kgsl_snapshot_regs *)buf;
  1394. struct kgsl_snapshot_registers *regs = priv;
  1395. unsigned int *data = (unsigned int *)(buf + sizeof(*header));
  1396. int count = 0, j, k;
  1397. struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
  1398. /* Figure out how many registers we are going to dump */
  1399. for (j = 0; j < regs->count; j++) {
  1400. int start = regs->regs[j * 2];
  1401. int end = regs->regs[j * 2 + 1];
  1402. count += (end - start + 1);
  1403. }
  1404. if (remain < (count * 8) + sizeof(*header)) {
  1405. SNAPSHOT_ERR_NOMEM(device, "ISENSE REGISTERS");
  1406. return 0;
  1407. }
  1408. for (j = 0; j < regs->count; j++) {
  1409. unsigned int start = regs->regs[j * 2];
  1410. unsigned int end = regs->regs[j * 2 + 1];
  1411. for (k = start; k <= end; k++) {
  1412. unsigned int val;
  1413. adreno_isense_regread(adreno_dev,
  1414. k - (adreno_dev->isense_base >> 2), &val);
  1415. *data++ = k;
  1416. *data++ = val;
  1417. }
  1418. }
  1419. header->count = count;
  1420. /* Return the size of the section */
  1421. return (count * 8) + sizeof(*header);
  1422. }
  1423. /* Snapshot the preemption related buffers */
  1424. static size_t snapshot_preemption_record(struct kgsl_device *device,
  1425. u8 *buf, size_t remain, void *priv)
  1426. {
  1427. struct kgsl_memdesc *memdesc = priv;
  1428. struct kgsl_snapshot_gpu_object_v2 *header =
  1429. (struct kgsl_snapshot_gpu_object_v2 *)buf;
  1430. u8 *ptr = buf + sizeof(*header);
  1431. const struct adreno_a6xx_core *gpucore = to_a6xx_core(ADRENO_DEVICE(device));
  1432. u64 ctxt_record_size = A6XX_CP_CTXRECORD_SIZE_IN_BYTES;
  1433. if (gpucore->ctxt_record_size)
  1434. ctxt_record_size = gpucore->ctxt_record_size;
  1435. ctxt_record_size = min_t(u64, ctxt_record_size, device->snapshot_ctxt_record_size);
  1436. if (remain < (ctxt_record_size + sizeof(*header))) {
  1437. SNAPSHOT_ERR_NOMEM(device, "PREEMPTION RECORD");
  1438. return 0;
  1439. }
  1440. header->size = ctxt_record_size >> 2;
  1441. header->gpuaddr = memdesc->gpuaddr;
  1442. header->ptbase =
  1443. kgsl_mmu_pagetable_get_ttbr0(device->mmu.defaultpagetable);
  1444. header->type = SNAPSHOT_GPU_OBJECT_GLOBAL;
  1445. memcpy(ptr, memdesc->hostptr, ctxt_record_size);
  1446. return ctxt_record_size + sizeof(*header);
  1447. }
  1448. static size_t a6xx_snapshot_cp_roq(struct kgsl_device *device, u8 *buf,
  1449. size_t remain, void *priv)
  1450. {
  1451. struct kgsl_snapshot_debug *header = (struct kgsl_snapshot_debug *) buf;
  1452. u32 size, *data = (u32 *) (buf + sizeof(*header));
  1453. int i;
  1454. kgsl_regread(device, A6XX_CP_ROQ_THRESHOLDS_2, &size);
  1455. size >>= 14;
  1456. if (remain < DEBUG_SECTION_SZ(size)) {
  1457. SNAPSHOT_ERR_NOMEM(device, "CP ROQ DEBUG");
  1458. return 0;
  1459. }
  1460. header->type = SNAPSHOT_DEBUG_CP_ROQ;
  1461. header->size = size;
  1462. kgsl_regwrite(device, A6XX_CP_ROQ_DBG_ADDR, 0x0);
  1463. for (i = 0; i < size; i++)
  1464. kgsl_regread(device, A6XX_CP_ROQ_DBG_DATA, &data[i]);
  1465. return DEBUG_SECTION_SZ(size);
  1466. }
  1467. static inline bool a6xx_has_gbif_reinit(struct adreno_device *adreno_dev)
  1468. {
  1469. /*
  1470. * Some targets in a6xx do not have reinit support in hardware.
  1471. * This check is only for hardware capability and not for finding
  1472. * whether gbif reinit sequence in software is enabled or not.
  1473. */
  1474. return !(adreno_is_a630(adreno_dev) || adreno_is_a615_family(adreno_dev) ||
  1475. adreno_is_a640_family(adreno_dev));
  1476. }
  1477. /*
  1478. * a6xx_snapshot() - A6XX GPU snapshot function
  1479. * @adreno_dev: Device being snapshotted
  1480. * @snapshot: Pointer to the snapshot instance
  1481. *
  1482. * This is where all of the A6XX specific bits and pieces are grabbed
  1483. * into the snapshot memory
  1484. */
  1485. void a6xx_snapshot(struct adreno_device *adreno_dev,
  1486. struct kgsl_snapshot *snapshot)
  1487. {
  1488. struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
  1489. struct adreno_ringbuffer *rb;
  1490. bool sptprac_on;
  1491. unsigned int i;
  1492. u32 hi, lo;
  1493. /*
  1494. * Dump debugbus data here to capture it for both
  1495. * GMU and GPU snapshot. Debugbus data can be accessed
  1496. * even if the gx headswitch or sptprac is off. If gx
  1497. * headswitch is off, data for gx blocks will show as
  1498. * 0x5c00bd00.
  1499. */
  1500. a6xx_snapshot_debugbus(adreno_dev, snapshot);
  1501. /* RSCC registers are on cx */
  1502. if (adreno_is_a650_family(adreno_dev)) {
  1503. struct kgsl_snapshot_registers r;
  1504. r.regs = a650_isense_registers;
  1505. r.count = ARRAY_SIZE(a650_isense_registers) / 2;
  1506. kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_REGS,
  1507. snapshot, a6xx_snapshot_isense_registers, &r);
  1508. }
  1509. if (!gmu_core_isenabled(device)) {
  1510. if (adreno_is_a619_holi(adreno_dev))
  1511. adreno_snapshot_registers(device, snapshot,
  1512. a6xx_holi_gmu_wrapper_registers,
  1513. ARRAY_SIZE(a6xx_holi_gmu_wrapper_registers) / 2);
  1514. else
  1515. adreno_snapshot_registers(device, snapshot,
  1516. a6xx_gmu_wrapper_registers,
  1517. ARRAY_SIZE(a6xx_gmu_wrapper_registers) / 2);
  1518. }
  1519. sptprac_on = a6xx_gmu_sptprac_is_on(adreno_dev);
  1520. /* SQE Firmware */
  1521. kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_DEBUG,
  1522. snapshot, a6xx_snapshot_sqe, NULL);
  1523. if (!adreno_gx_is_on(adreno_dev))
  1524. return;
  1525. kgsl_regread(device, A6XX_CP_IB1_BASE, &lo);
  1526. kgsl_regread(device, A6XX_CP_IB1_BASE_HI, &hi);
  1527. snapshot->ib1base = (((u64) hi) << 32) | lo;
  1528. kgsl_regread(device, A6XX_CP_IB2_BASE, &lo);
  1529. kgsl_regread(device, A6XX_CP_IB2_BASE_HI, &hi);
  1530. snapshot->ib2base = (((u64) hi) << 32) | lo;
  1531. kgsl_regread(device, A6XX_CP_IB1_REM_SIZE, &snapshot->ib1size);
  1532. kgsl_regread(device, A6XX_CP_IB2_REM_SIZE, &snapshot->ib2size);
  1533. /* Assert the isStatic bit before triggering snapshot */
  1534. if (adreno_is_a660(adreno_dev))
  1535. kgsl_regwrite(device, A6XX_RBBM_SNAPSHOT_STATUS, 0x1);
  1536. /* Dump the registers which get affected by crash dumper trigger */
  1537. kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_REGS,
  1538. snapshot, a6xx_snapshot_pre_crashdump_regs, NULL);
  1539. /* Dump vbif registers as well which get affected by crash dumper */
  1540. if (adreno_is_a630(adreno_dev))
  1541. SNAPSHOT_REGISTERS(device, snapshot, a6xx_vbif_registers);
  1542. else if (a6xx_has_gbif_reinit(adreno_dev))
  1543. adreno_snapshot_registers(device, snapshot,
  1544. a6xx_gbif_reinit_registers,
  1545. ARRAY_SIZE(a6xx_gbif_reinit_registers) / 2);
  1546. else
  1547. adreno_snapshot_registers(device, snapshot,
  1548. a6xx_gbif_registers,
  1549. ARRAY_SIZE(a6xx_gbif_registers) / 2);
  1550. /* Try to run the crash dumper */
  1551. if (sptprac_on)
  1552. _a6xx_do_crashdump(device);
  1553. for (i = 0; i < ARRAY_SIZE(a6xx_reg_list); i++) {
  1554. /* Skip registers that dont exists on targets other than A660 */
  1555. if (!adreno_is_a660(adreno_dev) &&
  1556. (a6xx_reg_list[i].regs == a660_registers))
  1557. continue;
  1558. kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_REGS,
  1559. snapshot, a6xx_snapshot_registers, &a6xx_reg_list[i]);
  1560. }
  1561. /* CP_SQE indexed registers */
  1562. kgsl_snapshot_indexed_registers(device, snapshot,
  1563. A6XX_CP_SQE_STAT_ADDR, A6XX_CP_SQE_STAT_DATA, 0, 0x33);
  1564. /* CP_DRAW_STATE */
  1565. kgsl_snapshot_indexed_registers(device, snapshot,
  1566. A6XX_CP_DRAW_STATE_ADDR, A6XX_CP_DRAW_STATE_DATA,
  1567. 0, 0x100);
  1568. /* SQE_UCODE Cache */
  1569. kgsl_snapshot_indexed_registers(device, snapshot,
  1570. A6XX_CP_SQE_UCODE_DBG_ADDR, A6XX_CP_SQE_UCODE_DBG_DATA,
  1571. 0, 0x8000);
  1572. /* CP LPAC indexed registers */
  1573. if (adreno_is_a660(adreno_dev)) {
  1574. u32 roq_size;
  1575. kgsl_snapshot_indexed_registers(device, snapshot,
  1576. A6XX_CP_SQE_AC_STAT_ADDR, A6XX_CP_SQE_AC_STAT_DATA,
  1577. 0, 0x33);
  1578. kgsl_snapshot_indexed_registers(device, snapshot,
  1579. A6XX_CP_LPAC_DRAW_STATE_ADDR,
  1580. A6XX_CP_LPAC_DRAW_STATE_DATA, 0, 0x100);
  1581. kgsl_snapshot_indexed_registers(device, snapshot,
  1582. A6XX_CP_SQE_AC_UCODE_DBG_ADDR,
  1583. A6XX_CP_SQE_AC_UCODE_DBG_DATA, 0, 0x8000);
  1584. kgsl_regread(device, A6XX_CP_LPAC_ROQ_THRESHOLDS_2, &roq_size);
  1585. roq_size = roq_size >> 14;
  1586. kgsl_snapshot_indexed_registers(device, snapshot,
  1587. A6XX_CP_LPAC_ROQ_DBG_ADDR,
  1588. A6XX_CP_LPAC_ROQ_DBG_DATA, 0, roq_size);
  1589. kgsl_snapshot_indexed_registers(device, snapshot,
  1590. A6XX_CP_LPAC_FIFO_DBG_ADDR, A6XX_CP_LPAC_FIFO_DBG_DATA,
  1591. 0, 0x40);
  1592. }
  1593. /*
  1594. * CP ROQ dump units is 4dwords. The number of units is stored
  1595. * in CP_ROQ_THRESHOLDS_2[31:16]. Read the value and convert to
  1596. * dword units.
  1597. */
  1598. kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_DEBUG,
  1599. snapshot, a6xx_snapshot_cp_roq, NULL);
  1600. /* Mempool debug data */
  1601. if (adreno_is_a650_family(adreno_dev))
  1602. a650_snapshot_mempool(device, snapshot);
  1603. else
  1604. a6xx_snapshot_mempool(device, snapshot);
  1605. if (sptprac_on) {
  1606. /* MVC register section */
  1607. a6xx_snapshot_mvc_regs(device, snapshot);
  1608. /* registers dumped through DBG AHB */
  1609. a6xx_snapshot_dbgahb_regs(device, snapshot);
  1610. /* Shader memory */
  1611. a6xx_snapshot_shader(device, snapshot);
  1612. if (!adreno_smmu_is_stalled(adreno_dev))
  1613. memset(a6xx_crashdump_registers->hostptr, 0xaa,
  1614. a6xx_crashdump_registers->size);
  1615. }
  1616. if (adreno_is_a660(adreno_dev)) {
  1617. u32 val;
  1618. kgsl_regread(device, A6XX_RBBM_SNAPSHOT_STATUS, &val);
  1619. if (!val)
  1620. dev_err(device->dev,
  1621. "Interface signals may have changed during snapshot\n");
  1622. kgsl_regwrite(device, A6XX_RBBM_SNAPSHOT_STATUS, 0x0);
  1623. }
  1624. /* Preemption record */
  1625. if (adreno_is_preemption_enabled(adreno_dev)) {
  1626. FOR_EACH_RINGBUFFER(adreno_dev, rb, i) {
  1627. kgsl_snapshot_add_section(device,
  1628. KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2,
  1629. snapshot, snapshot_preemption_record,
  1630. rb->preemption_desc);
  1631. }
  1632. }
  1633. }
  1634. static int _a6xx_crashdump_init_mvc(struct adreno_device *adreno_dev,
  1635. uint64_t *ptr, uint64_t *offset)
  1636. {
  1637. int qwords = 0;
  1638. unsigned int i, j, k;
  1639. unsigned int count;
  1640. for (i = 0; i < ARRAY_SIZE(a6xx_clusters); i++) {
  1641. struct a6xx_cluster_registers *cluster = &a6xx_clusters[i];
  1642. /* Skip registers that dont exists on targets other than A660 */
  1643. if (!adreno_is_a660(adreno_dev) &&
  1644. (cluster->regs == a660_fe_cluster))
  1645. continue;
  1646. /* The VPC registers are driven by VPC_PS cluster on a650 */
  1647. if (adreno_is_a650_family(adreno_dev) &&
  1648. (cluster->regs == a6xx_vpc_ps_cluster))
  1649. cluster->id = CP_CLUSTER_VPC_PS;
  1650. if (cluster->sel) {
  1651. ptr[qwords++] = cluster->sel->val;
  1652. ptr[qwords++] = ((uint64_t)cluster->sel->cd_reg << 44) |
  1653. (1 << 21) | 1;
  1654. }
  1655. cluster->offset0 = *offset;
  1656. for (j = 0; j < A6XX_NUM_CTXTS; j++) {
  1657. if (j == 1)
  1658. cluster->offset1 = *offset;
  1659. ptr[qwords++] = (cluster->id << 8) | (j << 4) | j;
  1660. ptr[qwords++] =
  1661. ((uint64_t)A6XX_CP_APERTURE_CNTL_CD << 44) |
  1662. (1 << 21) | 1;
  1663. for (k = 0; k < cluster->num_sets; k++) {
  1664. count = REG_PAIR_COUNT(cluster->regs, k);
  1665. ptr[qwords++] =
  1666. a6xx_crashdump_registers->gpuaddr + *offset;
  1667. ptr[qwords++] =
  1668. (((uint64_t)cluster->regs[2 * k]) << 44) |
  1669. count;
  1670. *offset += count * sizeof(unsigned int);
  1671. }
  1672. }
  1673. }
  1674. return qwords;
  1675. }
  1676. static int _a6xx_crashdump_init_shader(struct a6xx_shader_block *block,
  1677. uint64_t *ptr, uint64_t *offset)
  1678. {
  1679. int qwords = 0;
  1680. unsigned int j;
  1681. /* Capture each bank in the block */
  1682. for (j = 0; j < A6XX_NUM_SHADER_BANKS; j++) {
  1683. /* Program the aperture */
  1684. ptr[qwords++] =
  1685. (block->statetype << A6XX_SHADER_STATETYPE_SHIFT) | j;
  1686. ptr[qwords++] = (((uint64_t) A6XX_HLSQ_DBG_READ_SEL << 44)) |
  1687. (1 << 21) | 1;
  1688. /* Read all the data in one chunk */
  1689. ptr[qwords++] = a6xx_crashdump_registers->gpuaddr + *offset;
  1690. ptr[qwords++] =
  1691. (((uint64_t) A6XX_HLSQ_DBG_AHB_READ_APERTURE << 44)) |
  1692. block->sz;
  1693. /* Remember the offset of the first bank for easy access */
  1694. if (j == 0)
  1695. block->offset = *offset;
  1696. *offset += block->sz * sizeof(unsigned int);
  1697. }
  1698. return qwords;
  1699. }
  1700. static int _a6xx_crashdump_init_ctx_dbgahb(uint64_t *ptr, uint64_t *offset)
  1701. {
  1702. int qwords = 0;
  1703. unsigned int i, j, k;
  1704. unsigned int count;
  1705. for (i = 0; i < ARRAY_SIZE(a6xx_dbgahb_ctx_clusters); i++) {
  1706. struct a6xx_cluster_dbgahb_registers *cluster =
  1707. &a6xx_dbgahb_ctx_clusters[i];
  1708. cluster->offset0 = *offset;
  1709. for (j = 0; j < A6XX_NUM_CTXTS; j++) {
  1710. if (j == 1)
  1711. cluster->offset1 = *offset;
  1712. /* Program the aperture */
  1713. ptr[qwords++] =
  1714. ((cluster->statetype + j * 2) & 0xff) << 8;
  1715. ptr[qwords++] =
  1716. (((uint64_t)A6XX_HLSQ_DBG_READ_SEL << 44)) |
  1717. (1 << 21) | 1;
  1718. for (k = 0; k < cluster->num_sets; k++) {
  1719. unsigned int start = cluster->regs[2 * k];
  1720. count = REG_PAIR_COUNT(cluster->regs, k);
  1721. ptr[qwords++] =
  1722. a6xx_crashdump_registers->gpuaddr + *offset;
  1723. ptr[qwords++] =
  1724. (((uint64_t)(A6XX_HLSQ_DBG_AHB_READ_APERTURE +
  1725. start - cluster->regbase / 4) << 44)) |
  1726. count;
  1727. *offset += count * sizeof(unsigned int);
  1728. }
  1729. }
  1730. }
  1731. return qwords;
  1732. }
  1733. static int _a6xx_crashdump_init_non_ctx_dbgahb(uint64_t *ptr, uint64_t *offset)
  1734. {
  1735. int qwords = 0;
  1736. unsigned int i, k;
  1737. unsigned int count;
  1738. for (i = 0; i < ARRAY_SIZE(a6xx_non_ctx_dbgahb); i++) {
  1739. struct a6xx_non_ctx_dbgahb_registers *regs =
  1740. &a6xx_non_ctx_dbgahb[i];
  1741. regs->offset = *offset;
  1742. /* Program the aperture */
  1743. ptr[qwords++] = (regs->statetype & 0xff) << 8;
  1744. ptr[qwords++] = (((uint64_t)A6XX_HLSQ_DBG_READ_SEL << 44)) |
  1745. (1 << 21) | 1;
  1746. for (k = 0; k < regs->num_sets; k++) {
  1747. unsigned int start = regs->regs[2 * k];
  1748. count = REG_PAIR_COUNT(regs->regs, k);
  1749. ptr[qwords++] =
  1750. a6xx_crashdump_registers->gpuaddr + *offset;
  1751. ptr[qwords++] =
  1752. (((uint64_t)(A6XX_HLSQ_DBG_AHB_READ_APERTURE +
  1753. start - regs->regbase / 4) << 44)) |
  1754. count;
  1755. *offset += count * sizeof(unsigned int);
  1756. }
  1757. }
  1758. return qwords;
  1759. }
  1760. void a6xx_crashdump_init(struct adreno_device *adreno_dev)
  1761. {
  1762. struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
  1763. unsigned int script_size = 0;
  1764. unsigned int data_size = 0;
  1765. unsigned int i, j, k, ret;
  1766. uint64_t *ptr;
  1767. uint64_t offset = 0;
  1768. if (!IS_ERR_OR_NULL(a6xx_capturescript) &&
  1769. !IS_ERR_OR_NULL(a6xx_crashdump_registers))
  1770. return;
  1771. /*
  1772. * We need to allocate two buffers:
  1773. * 1 - the buffer to hold the draw script
  1774. * 2 - the buffer to hold the data
  1775. */
  1776. /*
  1777. * To save the registers, we need 16 bytes per register pair for the
  1778. * script and a dword for each register in the data
  1779. */
  1780. for (i = 0; i < ARRAY_SIZE(a6xx_reg_list); i++) {
  1781. struct reg_list *regs = &a6xx_reg_list[i];
  1782. /* Skip registers that dont exists on targets other than A660 */
  1783. if (!adreno_is_a660(adreno_dev) &&
  1784. (regs->regs == a660_registers))
  1785. continue;
  1786. /* 16 bytes for programming the aperture */
  1787. if (regs->sel)
  1788. script_size += 16;
  1789. /* Each pair needs 16 bytes (2 qwords) */
  1790. script_size += regs->count * 16;
  1791. /* Each register needs a dword in the data */
  1792. for (j = 0; j < regs->count; j++)
  1793. data_size += REG_PAIR_COUNT(regs->regs, j) *
  1794. sizeof(unsigned int);
  1795. }
  1796. /*
  1797. * To save the shader blocks for each block in each type we need 32
  1798. * bytes for the script (16 bytes to program the aperture and 16 to
  1799. * read the data) and then a block specific number of bytes to hold
  1800. * the data
  1801. */
  1802. for (i = 0; i < ARRAY_SIZE(a6xx_shader_blocks); i++) {
  1803. script_size += 32 * A6XX_NUM_SHADER_BANKS;
  1804. data_size += a6xx_shader_blocks[i].sz * sizeof(unsigned int) *
  1805. A6XX_NUM_SHADER_BANKS;
  1806. }
  1807. /* Calculate the script and data size for MVC registers */
  1808. for (i = 0; i < ARRAY_SIZE(a6xx_clusters); i++) {
  1809. struct a6xx_cluster_registers *cluster = &a6xx_clusters[i];
  1810. /* Skip registers that dont exists on targets other than A660 */
  1811. if (!adreno_is_a660(adreno_dev) &&
  1812. (cluster->regs == a660_fe_cluster))
  1813. continue;
  1814. /* 16 bytes if cluster sel exists */
  1815. if (cluster->sel)
  1816. script_size += 16;
  1817. for (j = 0; j < A6XX_NUM_CTXTS; j++) {
  1818. /* 16 bytes for programming the aperture */
  1819. script_size += 16;
  1820. /* Reading each pair of registers takes 16 bytes */
  1821. script_size += 16 * cluster->num_sets;
  1822. /* A dword per register read from the cluster list */
  1823. for (k = 0; k < cluster->num_sets; k++)
  1824. data_size += REG_PAIR_COUNT(cluster->regs, k) *
  1825. sizeof(unsigned int);
  1826. }
  1827. }
  1828. /* Calculate the script and data size for debug AHB registers */
  1829. for (i = 0; i < ARRAY_SIZE(a6xx_dbgahb_ctx_clusters); i++) {
  1830. struct a6xx_cluster_dbgahb_registers *cluster =
  1831. &a6xx_dbgahb_ctx_clusters[i];
  1832. for (j = 0; j < A6XX_NUM_CTXTS; j++) {
  1833. /* 16 bytes for programming the aperture */
  1834. script_size += 16;
  1835. /* Reading each pair of registers takes 16 bytes */
  1836. script_size += 16 * cluster->num_sets;
  1837. /* A dword per register read from the cluster list */
  1838. for (k = 0; k < cluster->num_sets; k++)
  1839. data_size += REG_PAIR_COUNT(cluster->regs, k) *
  1840. sizeof(unsigned int);
  1841. }
  1842. }
  1843. /*
  1844. * Calculate the script and data size for non context debug
  1845. * AHB registers
  1846. */
  1847. for (i = 0; i < ARRAY_SIZE(a6xx_non_ctx_dbgahb); i++) {
  1848. struct a6xx_non_ctx_dbgahb_registers *regs =
  1849. &a6xx_non_ctx_dbgahb[i];
  1850. /* 16 bytes for programming the aperture */
  1851. script_size += 16;
  1852. /* Reading each pair of registers takes 16 bytes */
  1853. script_size += 16 * regs->num_sets;
  1854. /* A dword per register read from the cluster list */
  1855. for (k = 0; k < regs->num_sets; k++)
  1856. data_size += REG_PAIR_COUNT(regs->regs, k) *
  1857. sizeof(unsigned int);
  1858. }
  1859. /* 16 bytes (2 qwords) for last entry in CD script */
  1860. script_size += 16;
  1861. /* Increment data size to store last entry in CD */
  1862. data_size += sizeof(unsigned int);
  1863. /* Now allocate the script and data buffers */
  1864. /* The script buffers needs 2 extra qwords on the end */
  1865. ret = adreno_allocate_global(device, &a6xx_capturescript,
  1866. script_size + 16, 0, KGSL_MEMFLAGS_GPUREADONLY,
  1867. KGSL_MEMDESC_PRIVILEGED, "capturescript");
  1868. if (ret)
  1869. return;
  1870. ret = adreno_allocate_global(device, &a6xx_crashdump_registers,
  1871. data_size, 0, 0, KGSL_MEMDESC_PRIVILEGED,
  1872. "capturescript_regs");
  1873. if (ret)
  1874. return;
  1875. /* Build the crash script */
  1876. ptr = (uint64_t *)a6xx_capturescript->hostptr;
  1877. /* For the registers, program a read command for each pair */
  1878. for (i = 0; i < ARRAY_SIZE(a6xx_reg_list); i++) {
  1879. struct reg_list *regs = &a6xx_reg_list[i];
  1880. /* Skip registers that dont exists on targets other than A660 */
  1881. if (!adreno_is_a660(adreno_dev) &&
  1882. (regs->regs == a660_registers))
  1883. continue;
  1884. regs->offset = offset;
  1885. /* Program the SEL_CNTL_CD register appropriately */
  1886. if (regs->sel) {
  1887. *ptr++ = regs->sel->val;
  1888. *ptr++ = (((uint64_t)regs->sel->cd_reg << 44)) |
  1889. (1 << 21) | 1;
  1890. }
  1891. for (j = 0; j < regs->count; j++) {
  1892. unsigned int r = REG_PAIR_COUNT(regs->regs, j);
  1893. *ptr++ = a6xx_crashdump_registers->gpuaddr + offset;
  1894. *ptr++ = (((uint64_t) regs->regs[2 * j]) << 44) | r;
  1895. offset += r * sizeof(unsigned int);
  1896. }
  1897. }
  1898. /* Program each shader block */
  1899. for (i = 0; i < ARRAY_SIZE(a6xx_shader_blocks); i++) {
  1900. ptr += _a6xx_crashdump_init_shader(&a6xx_shader_blocks[i], ptr,
  1901. &offset);
  1902. }
  1903. /* Program the capturescript for the MVC regsiters */
  1904. ptr += _a6xx_crashdump_init_mvc(adreno_dev, ptr, &offset);
  1905. if (!adreno_is_a663(adreno_dev)) {
  1906. ptr += _a6xx_crashdump_init_ctx_dbgahb(ptr, &offset);
  1907. ptr += _a6xx_crashdump_init_non_ctx_dbgahb(ptr, &offset);
  1908. }
  1909. /* Save CD register end pointer to check CD status completion */
  1910. a6xx_cd_reg_end = a6xx_crashdump_registers->hostptr + offset;
  1911. memset(a6xx_crashdump_registers->hostptr, 0xaa,
  1912. a6xx_crashdump_registers->size);
  1913. /* Program the capturescript to read the last register entry */
  1914. *ptr++ = a6xx_crashdump_registers->gpuaddr + offset;
  1915. *ptr++ = (((uint64_t) A6XX_CP_CRASH_DUMP_STATUS) << 44) | (uint64_t) 1;
  1916. *ptr++ = 0;
  1917. *ptr++ = 0;
  1918. }