a6xx_gpu_state.c 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. */
  3. #include <linux/ascii85.h>
  4. #include "msm_gem.h"
  5. #include "a6xx_gpu.h"
  6. #include "a6xx_gmu.h"
  7. #include "a6xx_gpu_state.h"
  8. #include "a6xx_gmu.xml.h"
  9. static const unsigned int *gen7_0_0_external_core_regs[] __always_unused;
  10. static const unsigned int *gen7_2_0_external_core_regs[] __always_unused;
  11. static const unsigned int *gen7_9_0_external_core_regs[] __always_unused;
  12. static struct gen7_sptp_cluster_registers gen7_9_0_sptp_clusters[] __always_unused;
  13. static const u32 gen7_9_0_cx_debugbus_blocks[] __always_unused;
  14. #include "adreno_gen7_0_0_snapshot.h"
  15. #include "adreno_gen7_2_0_snapshot.h"
  16. #include "adreno_gen7_9_0_snapshot.h"
  17. struct a6xx_gpu_state_obj {
  18. const void *handle;
  19. u32 *data;
  20. u32 count; /* optional, used when count potentially read from hw */
  21. };
  22. struct a6xx_gpu_state {
  23. struct msm_gpu_state base;
  24. struct a6xx_gpu_state_obj *gmu_registers;
  25. int nr_gmu_registers;
  26. struct a6xx_gpu_state_obj *registers;
  27. int nr_registers;
  28. struct a6xx_gpu_state_obj *shaders;
  29. int nr_shaders;
  30. struct a6xx_gpu_state_obj *clusters;
  31. int nr_clusters;
  32. struct a6xx_gpu_state_obj *dbgahb_clusters;
  33. int nr_dbgahb_clusters;
  34. struct a6xx_gpu_state_obj *indexed_regs;
  35. int nr_indexed_regs;
  36. struct a6xx_gpu_state_obj *debugbus;
  37. int nr_debugbus;
  38. struct a6xx_gpu_state_obj *vbif_debugbus;
  39. struct a6xx_gpu_state_obj *cx_debugbus;
  40. int nr_cx_debugbus;
  41. struct msm_gpu_state_bo *gmu_log;
  42. struct msm_gpu_state_bo *gmu_hfi;
  43. struct msm_gpu_state_bo *gmu_debug;
  44. s32 hfi_queue_history[2][HFI_HISTORY_SZ];
  45. struct list_head objs;
  46. bool gpu_initialized;
  47. };
  48. static inline int CRASHDUMP_WRITE(u64 *in, u32 reg, u32 val)
  49. {
  50. in[0] = val;
  51. in[1] = (((u64) reg) << 44 | (1 << 21) | 1);
  52. return 2;
  53. }
  54. static inline int CRASHDUMP_READ(u64 *in, u32 reg, u32 dwords, u64 target)
  55. {
  56. in[0] = target;
  57. in[1] = (((u64) reg) << 44 | dwords);
  58. return 2;
  59. }
  60. static inline int CRASHDUMP_FINI(u64 *in)
  61. {
  62. in[0] = 0;
  63. in[1] = 0;
  64. return 2;
  65. }
  66. struct a6xx_crashdumper {
  67. void *ptr;
  68. struct drm_gem_object *bo;
  69. u64 iova;
  70. };
  71. struct a6xx_state_memobj {
  72. struct list_head node;
  73. unsigned long long data[];
  74. };
  75. static void *state_kcalloc(struct a6xx_gpu_state *a6xx_state, int nr, size_t objsize)
  76. {
  77. struct a6xx_state_memobj *obj =
  78. kvzalloc((nr * objsize) + sizeof(*obj), GFP_KERNEL);
  79. if (!obj)
  80. return NULL;
  81. list_add_tail(&obj->node, &a6xx_state->objs);
  82. return &obj->data;
  83. }
  84. static void *state_kmemdup(struct a6xx_gpu_state *a6xx_state, void *src,
  85. size_t size)
  86. {
  87. void *dst = state_kcalloc(a6xx_state, 1, size);
  88. if (dst)
  89. memcpy(dst, src, size);
  90. return dst;
  91. }
  92. /*
  93. * Allocate 1MB for the crashdumper scratch region - 8k for the script and
  94. * the rest for the data
  95. */
  96. #define A6XX_CD_DATA_OFFSET 8192
  97. #define A6XX_CD_DATA_SIZE (SZ_1M - 8192)
  98. static int a6xx_crashdumper_init(struct msm_gpu *gpu,
  99. struct a6xx_crashdumper *dumper)
  100. {
  101. dumper->ptr = msm_gem_kernel_new(gpu->dev,
  102. SZ_1M, MSM_BO_WC, gpu->aspace,
  103. &dumper->bo, &dumper->iova);
  104. if (!IS_ERR(dumper->ptr))
  105. msm_gem_object_set_name(dumper->bo, "crashdump");
  106. return PTR_ERR_OR_ZERO(dumper->ptr);
  107. }
  108. static int a6xx_crashdumper_run(struct msm_gpu *gpu,
  109. struct a6xx_crashdumper *dumper)
  110. {
  111. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  112. struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
  113. u32 val;
  114. int ret;
  115. if (IS_ERR_OR_NULL(dumper->ptr))
  116. return -EINVAL;
  117. if (!a6xx_gmu_sptprac_is_on(&a6xx_gpu->gmu))
  118. return -EINVAL;
  119. /* Make sure all pending memory writes are posted */
  120. wmb();
  121. gpu_write64(gpu, REG_A6XX_CP_CRASH_SCRIPT_BASE, dumper->iova);
  122. gpu_write(gpu, REG_A6XX_CP_CRASH_DUMP_CNTL, 1);
  123. ret = gpu_poll_timeout(gpu, REG_A6XX_CP_CRASH_DUMP_STATUS, val,
  124. val & 0x02, 100, 10000);
  125. gpu_write(gpu, REG_A6XX_CP_CRASH_DUMP_CNTL, 0);
  126. return ret;
  127. }
  128. /* read a value from the GX debug bus */
  129. static int debugbus_read(struct msm_gpu *gpu, u32 block, u32 offset,
  130. u32 *data)
  131. {
  132. u32 reg = A6XX_DBGC_CFG_DBGBUS_SEL_D_PING_INDEX(offset) |
  133. A6XX_DBGC_CFG_DBGBUS_SEL_D_PING_BLK_SEL(block);
  134. gpu_write(gpu, REG_A6XX_DBGC_CFG_DBGBUS_SEL_A, reg);
  135. gpu_write(gpu, REG_A6XX_DBGC_CFG_DBGBUS_SEL_B, reg);
  136. gpu_write(gpu, REG_A6XX_DBGC_CFG_DBGBUS_SEL_C, reg);
  137. gpu_write(gpu, REG_A6XX_DBGC_CFG_DBGBUS_SEL_D, reg);
  138. /* Wait 1 us to make sure the data is flowing */
  139. udelay(1);
  140. data[0] = gpu_read(gpu, REG_A6XX_DBGC_CFG_DBGBUS_TRACE_BUF2);
  141. data[1] = gpu_read(gpu, REG_A6XX_DBGC_CFG_DBGBUS_TRACE_BUF1);
  142. return 2;
  143. }
  144. #define cxdbg_write(ptr, offset, val) \
  145. writel((val), (ptr) + ((offset) << 2))
  146. #define cxdbg_read(ptr, offset) \
  147. readl((ptr) + ((offset) << 2))
  148. /* read a value from the CX debug bus */
  149. static int cx_debugbus_read(void __iomem *cxdbg, u32 block, u32 offset,
  150. u32 *data)
  151. {
  152. u32 reg = A6XX_CX_DBGC_CFG_DBGBUS_SEL_A_PING_INDEX(offset) |
  153. A6XX_CX_DBGC_CFG_DBGBUS_SEL_A_PING_BLK_SEL(block);
  154. cxdbg_write(cxdbg, REG_A6XX_CX_DBGC_CFG_DBGBUS_SEL_A, reg);
  155. cxdbg_write(cxdbg, REG_A6XX_CX_DBGC_CFG_DBGBUS_SEL_B, reg);
  156. cxdbg_write(cxdbg, REG_A6XX_CX_DBGC_CFG_DBGBUS_SEL_C, reg);
  157. cxdbg_write(cxdbg, REG_A6XX_CX_DBGC_CFG_DBGBUS_SEL_D, reg);
  158. /* Wait 1 us to make sure the data is flowing */
  159. udelay(1);
  160. data[0] = cxdbg_read(cxdbg, REG_A6XX_CX_DBGC_CFG_DBGBUS_TRACE_BUF2);
  161. data[1] = cxdbg_read(cxdbg, REG_A6XX_CX_DBGC_CFG_DBGBUS_TRACE_BUF1);
  162. return 2;
  163. }
  164. /* Read a chunk of data from the VBIF debug bus */
  165. static int vbif_debugbus_read(struct msm_gpu *gpu, u32 ctrl0, u32 ctrl1,
  166. u32 reg, int count, u32 *data)
  167. {
  168. int i;
  169. gpu_write(gpu, ctrl0, reg);
  170. for (i = 0; i < count; i++) {
  171. gpu_write(gpu, ctrl1, i);
  172. data[i] = gpu_read(gpu, REG_A6XX_VBIF_TEST_BUS_OUT);
  173. }
  174. return count;
  175. }
  176. #define AXI_ARB_BLOCKS 2
  177. #define XIN_AXI_BLOCKS 5
  178. #define XIN_CORE_BLOCKS 4
  179. #define VBIF_DEBUGBUS_BLOCK_SIZE \
  180. ((16 * AXI_ARB_BLOCKS) + \
  181. (18 * XIN_AXI_BLOCKS) + \
  182. (12 * XIN_CORE_BLOCKS))
  183. static void a6xx_get_vbif_debugbus_block(struct msm_gpu *gpu,
  184. struct a6xx_gpu_state *a6xx_state,
  185. struct a6xx_gpu_state_obj *obj)
  186. {
  187. u32 clk, *ptr;
  188. int i;
  189. obj->data = state_kcalloc(a6xx_state, VBIF_DEBUGBUS_BLOCK_SIZE,
  190. sizeof(u32));
  191. if (!obj->data)
  192. return;
  193. obj->handle = NULL;
  194. /* Get the current clock setting */
  195. clk = gpu_read(gpu, REG_A6XX_VBIF_CLKON);
  196. /* Force on the bus so we can read it */
  197. gpu_write(gpu, REG_A6XX_VBIF_CLKON,
  198. clk | A6XX_VBIF_CLKON_FORCE_ON_TESTBUS);
  199. /* We will read from BUS2 first, so disable BUS1 */
  200. gpu_write(gpu, REG_A6XX_VBIF_TEST_BUS1_CTRL0, 0);
  201. /* Enable the VBIF bus for reading */
  202. gpu_write(gpu, REG_A6XX_VBIF_TEST_BUS_OUT_CTRL, 1);
  203. ptr = obj->data;
  204. for (i = 0; i < AXI_ARB_BLOCKS; i++)
  205. ptr += vbif_debugbus_read(gpu,
  206. REG_A6XX_VBIF_TEST_BUS2_CTRL0,
  207. REG_A6XX_VBIF_TEST_BUS2_CTRL1,
  208. 1 << (i + 16), 16, ptr);
  209. for (i = 0; i < XIN_AXI_BLOCKS; i++)
  210. ptr += vbif_debugbus_read(gpu,
  211. REG_A6XX_VBIF_TEST_BUS2_CTRL0,
  212. REG_A6XX_VBIF_TEST_BUS2_CTRL1,
  213. 1 << i, 18, ptr);
  214. /* Stop BUS2 so we can turn on BUS1 */
  215. gpu_write(gpu, REG_A6XX_VBIF_TEST_BUS2_CTRL0, 0);
  216. for (i = 0; i < XIN_CORE_BLOCKS; i++)
  217. ptr += vbif_debugbus_read(gpu,
  218. REG_A6XX_VBIF_TEST_BUS1_CTRL0,
  219. REG_A6XX_VBIF_TEST_BUS1_CTRL1,
  220. 1 << i, 12, ptr);
  221. /* Restore the VBIF clock setting */
  222. gpu_write(gpu, REG_A6XX_VBIF_CLKON, clk);
  223. }
  224. static void a6xx_get_debugbus_block(struct msm_gpu *gpu,
  225. struct a6xx_gpu_state *a6xx_state,
  226. const struct a6xx_debugbus_block *block,
  227. struct a6xx_gpu_state_obj *obj)
  228. {
  229. int i;
  230. u32 *ptr;
  231. obj->data = state_kcalloc(a6xx_state, block->count, sizeof(u64));
  232. if (!obj->data)
  233. return;
  234. obj->handle = block;
  235. for (ptr = obj->data, i = 0; i < block->count; i++)
  236. ptr += debugbus_read(gpu, block->id, i, ptr);
  237. }
  238. static void a6xx_get_cx_debugbus_block(void __iomem *cxdbg,
  239. struct a6xx_gpu_state *a6xx_state,
  240. const struct a6xx_debugbus_block *block,
  241. struct a6xx_gpu_state_obj *obj)
  242. {
  243. int i;
  244. u32 *ptr;
  245. obj->data = state_kcalloc(a6xx_state, block->count, sizeof(u64));
  246. if (!obj->data)
  247. return;
  248. obj->handle = block;
  249. for (ptr = obj->data, i = 0; i < block->count; i++)
  250. ptr += cx_debugbus_read(cxdbg, block->id, i, ptr);
  251. }
  252. static void a6xx_get_debugbus_blocks(struct msm_gpu *gpu,
  253. struct a6xx_gpu_state *a6xx_state)
  254. {
  255. int nr_debugbus_blocks = ARRAY_SIZE(a6xx_debugbus_blocks) +
  256. (a6xx_has_gbif(to_adreno_gpu(gpu)) ? 1 : 0);
  257. if (adreno_is_a650_family(to_adreno_gpu(gpu)))
  258. nr_debugbus_blocks += ARRAY_SIZE(a650_debugbus_blocks);
  259. a6xx_state->debugbus = state_kcalloc(a6xx_state, nr_debugbus_blocks,
  260. sizeof(*a6xx_state->debugbus));
  261. if (a6xx_state->debugbus) {
  262. int i;
  263. for (i = 0; i < ARRAY_SIZE(a6xx_debugbus_blocks); i++)
  264. a6xx_get_debugbus_block(gpu,
  265. a6xx_state,
  266. &a6xx_debugbus_blocks[i],
  267. &a6xx_state->debugbus[i]);
  268. a6xx_state->nr_debugbus = ARRAY_SIZE(a6xx_debugbus_blocks);
  269. /*
  270. * GBIF has same debugbus as of other GPU blocks, fall back to
  271. * default path if GPU uses GBIF, also GBIF uses exactly same
  272. * ID as of VBIF.
  273. */
  274. if (a6xx_has_gbif(to_adreno_gpu(gpu))) {
  275. a6xx_get_debugbus_block(gpu, a6xx_state,
  276. &a6xx_gbif_debugbus_block,
  277. &a6xx_state->debugbus[i]);
  278. a6xx_state->nr_debugbus += 1;
  279. }
  280. if (adreno_is_a650_family(to_adreno_gpu(gpu))) {
  281. for (i = 0; i < ARRAY_SIZE(a650_debugbus_blocks); i++)
  282. a6xx_get_debugbus_block(gpu,
  283. a6xx_state,
  284. &a650_debugbus_blocks[i],
  285. &a6xx_state->debugbus[i]);
  286. }
  287. }
  288. }
  289. static void a7xx_get_debugbus_blocks(struct msm_gpu *gpu,
  290. struct a6xx_gpu_state *a6xx_state)
  291. {
  292. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  293. int debugbus_blocks_count, gbif_debugbus_blocks_count, total_debugbus_blocks;
  294. const u32 *debugbus_blocks, *gbif_debugbus_blocks;
  295. int i;
  296. if (adreno_gpu->info->family == ADRENO_7XX_GEN1) {
  297. debugbus_blocks = gen7_0_0_debugbus_blocks;
  298. debugbus_blocks_count = ARRAY_SIZE(gen7_0_0_debugbus_blocks);
  299. gbif_debugbus_blocks = a7xx_gbif_debugbus_blocks;
  300. gbif_debugbus_blocks_count = ARRAY_SIZE(a7xx_gbif_debugbus_blocks);
  301. } else if (adreno_gpu->info->family == ADRENO_7XX_GEN2) {
  302. debugbus_blocks = gen7_2_0_debugbus_blocks;
  303. debugbus_blocks_count = ARRAY_SIZE(gen7_2_0_debugbus_blocks);
  304. gbif_debugbus_blocks = a7xx_gbif_debugbus_blocks;
  305. gbif_debugbus_blocks_count = ARRAY_SIZE(a7xx_gbif_debugbus_blocks);
  306. } else {
  307. BUG_ON(adreno_gpu->info->family != ADRENO_7XX_GEN3);
  308. debugbus_blocks = gen7_9_0_debugbus_blocks;
  309. debugbus_blocks_count = ARRAY_SIZE(gen7_9_0_debugbus_blocks);
  310. gbif_debugbus_blocks = gen7_9_0_gbif_debugbus_blocks;
  311. gbif_debugbus_blocks_count = ARRAY_SIZE(gen7_9_0_gbif_debugbus_blocks);
  312. }
  313. total_debugbus_blocks = debugbus_blocks_count + gbif_debugbus_blocks_count;
  314. a6xx_state->debugbus = state_kcalloc(a6xx_state, total_debugbus_blocks,
  315. sizeof(*a6xx_state->debugbus));
  316. if (a6xx_state->debugbus) {
  317. for (i = 0; i < debugbus_blocks_count; i++) {
  318. a6xx_get_debugbus_block(gpu,
  319. a6xx_state, &a7xx_debugbus_blocks[debugbus_blocks[i]],
  320. &a6xx_state->debugbus[i]);
  321. }
  322. for (i = 0; i < gbif_debugbus_blocks_count; i++) {
  323. a6xx_get_debugbus_block(gpu,
  324. a6xx_state, &a7xx_debugbus_blocks[gbif_debugbus_blocks[i]],
  325. &a6xx_state->debugbus[i + debugbus_blocks_count]);
  326. }
  327. }
  328. }
  329. static void a6xx_get_debugbus(struct msm_gpu *gpu,
  330. struct a6xx_gpu_state *a6xx_state)
  331. {
  332. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  333. struct resource *res;
  334. void __iomem *cxdbg = NULL;
  335. /* Set up the GX debug bus */
  336. gpu_write(gpu, REG_A6XX_DBGC_CFG_DBGBUS_CNTLT,
  337. A6XX_DBGC_CFG_DBGBUS_CNTLT_SEGT(0xf));
  338. gpu_write(gpu, REG_A6XX_DBGC_CFG_DBGBUS_CNTLM,
  339. A6XX_DBGC_CFG_DBGBUS_CNTLM_ENABLE(0xf));
  340. gpu_write(gpu, REG_A6XX_DBGC_CFG_DBGBUS_IVTL_0, 0);
  341. gpu_write(gpu, REG_A6XX_DBGC_CFG_DBGBUS_IVTL_1, 0);
  342. gpu_write(gpu, REG_A6XX_DBGC_CFG_DBGBUS_IVTL_2, 0);
  343. gpu_write(gpu, REG_A6XX_DBGC_CFG_DBGBUS_IVTL_3, 0);
  344. gpu_write(gpu, REG_A6XX_DBGC_CFG_DBGBUS_BYTEL_0, 0x76543210);
  345. gpu_write(gpu, REG_A6XX_DBGC_CFG_DBGBUS_BYTEL_1, 0xFEDCBA98);
  346. gpu_write(gpu, REG_A6XX_DBGC_CFG_DBGBUS_MASKL_0, 0);
  347. gpu_write(gpu, REG_A6XX_DBGC_CFG_DBGBUS_MASKL_1, 0);
  348. gpu_write(gpu, REG_A6XX_DBGC_CFG_DBGBUS_MASKL_2, 0);
  349. gpu_write(gpu, REG_A6XX_DBGC_CFG_DBGBUS_MASKL_3, 0);
  350. /* Set up the CX debug bus - it lives elsewhere in the system so do a
  351. * temporary ioremap for the registers
  352. */
  353. res = platform_get_resource_byname(gpu->pdev, IORESOURCE_MEM,
  354. "cx_dbgc");
  355. if (res)
  356. cxdbg = ioremap(res->start, resource_size(res));
  357. if (cxdbg) {
  358. cxdbg_write(cxdbg, REG_A6XX_CX_DBGC_CFG_DBGBUS_CNTLT,
  359. A6XX_DBGC_CFG_DBGBUS_CNTLT_SEGT(0xf));
  360. cxdbg_write(cxdbg, REG_A6XX_CX_DBGC_CFG_DBGBUS_CNTLM,
  361. A6XX_DBGC_CFG_DBGBUS_CNTLM_ENABLE(0xf));
  362. cxdbg_write(cxdbg, REG_A6XX_CX_DBGC_CFG_DBGBUS_IVTL_0, 0);
  363. cxdbg_write(cxdbg, REG_A6XX_CX_DBGC_CFG_DBGBUS_IVTL_1, 0);
  364. cxdbg_write(cxdbg, REG_A6XX_CX_DBGC_CFG_DBGBUS_IVTL_2, 0);
  365. cxdbg_write(cxdbg, REG_A6XX_CX_DBGC_CFG_DBGBUS_IVTL_3, 0);
  366. cxdbg_write(cxdbg, REG_A6XX_CX_DBGC_CFG_DBGBUS_BYTEL_0,
  367. 0x76543210);
  368. cxdbg_write(cxdbg, REG_A6XX_CX_DBGC_CFG_DBGBUS_BYTEL_1,
  369. 0xFEDCBA98);
  370. cxdbg_write(cxdbg, REG_A6XX_CX_DBGC_CFG_DBGBUS_MASKL_0, 0);
  371. cxdbg_write(cxdbg, REG_A6XX_CX_DBGC_CFG_DBGBUS_MASKL_1, 0);
  372. cxdbg_write(cxdbg, REG_A6XX_CX_DBGC_CFG_DBGBUS_MASKL_2, 0);
  373. cxdbg_write(cxdbg, REG_A6XX_CX_DBGC_CFG_DBGBUS_MASKL_3, 0);
  374. }
  375. if (adreno_is_a7xx(adreno_gpu)) {
  376. a7xx_get_debugbus_blocks(gpu, a6xx_state);
  377. } else {
  378. a6xx_get_debugbus_blocks(gpu, a6xx_state);
  379. }
  380. /* Dump the VBIF debugbus on applicable targets */
  381. if (!a6xx_has_gbif(adreno_gpu)) {
  382. a6xx_state->vbif_debugbus =
  383. state_kcalloc(a6xx_state, 1,
  384. sizeof(*a6xx_state->vbif_debugbus));
  385. if (a6xx_state->vbif_debugbus)
  386. a6xx_get_vbif_debugbus_block(gpu, a6xx_state,
  387. a6xx_state->vbif_debugbus);
  388. }
  389. if (cxdbg) {
  390. unsigned nr_cx_debugbus_blocks;
  391. const struct a6xx_debugbus_block *cx_debugbus_blocks;
  392. if (adreno_is_a7xx(adreno_gpu)) {
  393. BUG_ON(adreno_gpu->info->family > ADRENO_7XX_GEN3);
  394. cx_debugbus_blocks = a7xx_cx_debugbus_blocks;
  395. nr_cx_debugbus_blocks = ARRAY_SIZE(a7xx_cx_debugbus_blocks);
  396. } else {
  397. cx_debugbus_blocks = a6xx_cx_debugbus_blocks;
  398. nr_cx_debugbus_blocks = ARRAY_SIZE(a6xx_cx_debugbus_blocks);
  399. }
  400. a6xx_state->cx_debugbus =
  401. state_kcalloc(a6xx_state,
  402. nr_cx_debugbus_blocks,
  403. sizeof(*a6xx_state->cx_debugbus));
  404. if (a6xx_state->cx_debugbus) {
  405. int i;
  406. for (i = 0; i < nr_cx_debugbus_blocks; i++)
  407. a6xx_get_cx_debugbus_block(cxdbg,
  408. a6xx_state,
  409. &cx_debugbus_blocks[i],
  410. &a6xx_state->cx_debugbus[i]);
  411. a6xx_state->nr_cx_debugbus =
  412. nr_cx_debugbus_blocks;
  413. }
  414. iounmap(cxdbg);
  415. }
  416. }
  417. #define RANGE(reg, a) ((reg)[(a) + 1] - (reg)[(a)] + 1)
  418. /* Read a data cluster from behind the AHB aperture */
  419. static void a6xx_get_dbgahb_cluster(struct msm_gpu *gpu,
  420. struct a6xx_gpu_state *a6xx_state,
  421. const struct a6xx_dbgahb_cluster *dbgahb,
  422. struct a6xx_gpu_state_obj *obj,
  423. struct a6xx_crashdumper *dumper)
  424. {
  425. u64 *in = dumper->ptr;
  426. u64 out = dumper->iova + A6XX_CD_DATA_OFFSET;
  427. size_t datasize;
  428. int i, regcount = 0;
  429. for (i = 0; i < A6XX_NUM_CONTEXTS; i++) {
  430. int j;
  431. in += CRASHDUMP_WRITE(in, REG_A6XX_HLSQ_DBG_READ_SEL,
  432. (dbgahb->statetype + i * 2) << 8);
  433. for (j = 0; j < dbgahb->count; j += 2) {
  434. int count = RANGE(dbgahb->registers, j);
  435. u32 offset = REG_A6XX_HLSQ_DBG_AHB_READ_APERTURE +
  436. dbgahb->registers[j] - (dbgahb->base >> 2);
  437. in += CRASHDUMP_READ(in, offset, count, out);
  438. out += count * sizeof(u32);
  439. if (i == 0)
  440. regcount += count;
  441. }
  442. }
  443. CRASHDUMP_FINI(in);
  444. datasize = regcount * A6XX_NUM_CONTEXTS * sizeof(u32);
  445. if (WARN_ON(datasize > A6XX_CD_DATA_SIZE))
  446. return;
  447. if (a6xx_crashdumper_run(gpu, dumper))
  448. return;
  449. obj->handle = dbgahb;
  450. obj->data = state_kmemdup(a6xx_state, dumper->ptr + A6XX_CD_DATA_OFFSET,
  451. datasize);
  452. }
  453. static void a7xx_get_dbgahb_cluster(struct msm_gpu *gpu,
  454. struct a6xx_gpu_state *a6xx_state,
  455. const struct gen7_sptp_cluster_registers *dbgahb,
  456. struct a6xx_gpu_state_obj *obj,
  457. struct a6xx_crashdumper *dumper)
  458. {
  459. u64 *in = dumper->ptr;
  460. u64 out = dumper->iova + A6XX_CD_DATA_OFFSET;
  461. size_t datasize;
  462. int i, regcount = 0;
  463. in += CRASHDUMP_WRITE(in, REG_A7XX_SP_READ_SEL,
  464. A7XX_SP_READ_SEL_LOCATION(dbgahb->location_id) |
  465. A7XX_SP_READ_SEL_PIPE(dbgahb->pipe_id) |
  466. A7XX_SP_READ_SEL_STATETYPE(dbgahb->statetype));
  467. for (i = 0; dbgahb->regs[i] != UINT_MAX; i += 2) {
  468. int count = RANGE(dbgahb->regs, i);
  469. u32 offset = REG_A7XX_SP_AHB_READ_APERTURE +
  470. dbgahb->regs[i] - dbgahb->regbase;
  471. in += CRASHDUMP_READ(in, offset, count, out);
  472. out += count * sizeof(u32);
  473. regcount += count;
  474. }
  475. CRASHDUMP_FINI(in);
  476. datasize = regcount * sizeof(u32);
  477. if (WARN_ON(datasize > A6XX_CD_DATA_SIZE))
  478. return;
  479. if (a6xx_crashdumper_run(gpu, dumper))
  480. return;
  481. obj->handle = dbgahb;
  482. obj->data = state_kmemdup(a6xx_state, dumper->ptr + A6XX_CD_DATA_OFFSET,
  483. datasize);
  484. }
  485. static void a6xx_get_dbgahb_clusters(struct msm_gpu *gpu,
  486. struct a6xx_gpu_state *a6xx_state,
  487. struct a6xx_crashdumper *dumper)
  488. {
  489. int i;
  490. a6xx_state->dbgahb_clusters = state_kcalloc(a6xx_state,
  491. ARRAY_SIZE(a6xx_dbgahb_clusters),
  492. sizeof(*a6xx_state->dbgahb_clusters));
  493. if (!a6xx_state->dbgahb_clusters)
  494. return;
  495. a6xx_state->nr_dbgahb_clusters = ARRAY_SIZE(a6xx_dbgahb_clusters);
  496. for (i = 0; i < ARRAY_SIZE(a6xx_dbgahb_clusters); i++)
  497. a6xx_get_dbgahb_cluster(gpu, a6xx_state,
  498. &a6xx_dbgahb_clusters[i],
  499. &a6xx_state->dbgahb_clusters[i], dumper);
  500. }
  501. static void a7xx_get_dbgahb_clusters(struct msm_gpu *gpu,
  502. struct a6xx_gpu_state *a6xx_state,
  503. struct a6xx_crashdumper *dumper)
  504. {
  505. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  506. int i;
  507. const struct gen7_sptp_cluster_registers *dbgahb_clusters;
  508. unsigned dbgahb_clusters_size;
  509. if (adreno_gpu->info->family == ADRENO_7XX_GEN1) {
  510. dbgahb_clusters = gen7_0_0_sptp_clusters;
  511. dbgahb_clusters_size = ARRAY_SIZE(gen7_0_0_sptp_clusters);
  512. } else if (adreno_gpu->info->family == ADRENO_7XX_GEN2) {
  513. dbgahb_clusters = gen7_2_0_sptp_clusters;
  514. dbgahb_clusters_size = ARRAY_SIZE(gen7_2_0_sptp_clusters);
  515. } else {
  516. BUG_ON(adreno_gpu->info->family != ADRENO_7XX_GEN3);
  517. dbgahb_clusters = gen7_9_0_sptp_clusters;
  518. dbgahb_clusters_size = ARRAY_SIZE(gen7_9_0_sptp_clusters);
  519. }
  520. a6xx_state->dbgahb_clusters = state_kcalloc(a6xx_state,
  521. dbgahb_clusters_size,
  522. sizeof(*a6xx_state->dbgahb_clusters));
  523. if (!a6xx_state->dbgahb_clusters)
  524. return;
  525. a6xx_state->nr_dbgahb_clusters = dbgahb_clusters_size;
  526. for (i = 0; i < dbgahb_clusters_size; i++)
  527. a7xx_get_dbgahb_cluster(gpu, a6xx_state,
  528. &dbgahb_clusters[i],
  529. &a6xx_state->dbgahb_clusters[i], dumper);
  530. }
  531. /* Read a data cluster from the CP aperture with the crashdumper */
  532. static void a6xx_get_cluster(struct msm_gpu *gpu,
  533. struct a6xx_gpu_state *a6xx_state,
  534. const struct a6xx_cluster *cluster,
  535. struct a6xx_gpu_state_obj *obj,
  536. struct a6xx_crashdumper *dumper)
  537. {
  538. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  539. u64 *in = dumper->ptr;
  540. u64 out = dumper->iova + A6XX_CD_DATA_OFFSET;
  541. size_t datasize;
  542. int i, regcount = 0;
  543. u32 id = cluster->id;
  544. /* Skip registers that are not present on older generation */
  545. if (!adreno_is_a660_family(adreno_gpu) &&
  546. cluster->registers == a660_fe_cluster)
  547. return;
  548. if (adreno_is_a650_family(adreno_gpu) &&
  549. cluster->registers == a6xx_ps_cluster)
  550. id = CLUSTER_VPC_PS;
  551. /* Some clusters need a selector register to be programmed too */
  552. if (cluster->sel_reg)
  553. in += CRASHDUMP_WRITE(in, cluster->sel_reg, cluster->sel_val);
  554. for (i = 0; i < A6XX_NUM_CONTEXTS; i++) {
  555. int j;
  556. in += CRASHDUMP_WRITE(in, REG_A6XX_CP_APERTURE_CNTL_CD,
  557. (id << 8) | (i << 4) | i);
  558. for (j = 0; j < cluster->count; j += 2) {
  559. int count = RANGE(cluster->registers, j);
  560. in += CRASHDUMP_READ(in, cluster->registers[j],
  561. count, out);
  562. out += count * sizeof(u32);
  563. if (i == 0)
  564. regcount += count;
  565. }
  566. }
  567. CRASHDUMP_FINI(in);
  568. datasize = regcount * A6XX_NUM_CONTEXTS * sizeof(u32);
  569. if (WARN_ON(datasize > A6XX_CD_DATA_SIZE))
  570. return;
  571. if (a6xx_crashdumper_run(gpu, dumper))
  572. return;
  573. obj->handle = cluster;
  574. obj->data = state_kmemdup(a6xx_state, dumper->ptr + A6XX_CD_DATA_OFFSET,
  575. datasize);
  576. }
  577. static void a7xx_get_cluster(struct msm_gpu *gpu,
  578. struct a6xx_gpu_state *a6xx_state,
  579. const struct gen7_cluster_registers *cluster,
  580. struct a6xx_gpu_state_obj *obj,
  581. struct a6xx_crashdumper *dumper)
  582. {
  583. u64 *in = dumper->ptr;
  584. u64 out = dumper->iova + A6XX_CD_DATA_OFFSET;
  585. size_t datasize;
  586. int i, regcount = 0;
  587. /* Some clusters need a selector register to be programmed too */
  588. if (cluster->sel)
  589. in += CRASHDUMP_WRITE(in, cluster->sel->cd_reg, cluster->sel->val);
  590. in += CRASHDUMP_WRITE(in, REG_A7XX_CP_APERTURE_CNTL_CD,
  591. A7XX_CP_APERTURE_CNTL_CD_PIPE(cluster->pipe_id) |
  592. A7XX_CP_APERTURE_CNTL_CD_CLUSTER(cluster->cluster_id) |
  593. A7XX_CP_APERTURE_CNTL_CD_CONTEXT(cluster->context_id));
  594. for (i = 0; cluster->regs[i] != UINT_MAX; i += 2) {
  595. int count = RANGE(cluster->regs, i);
  596. in += CRASHDUMP_READ(in, cluster->regs[i],
  597. count, out);
  598. out += count * sizeof(u32);
  599. regcount += count;
  600. }
  601. CRASHDUMP_FINI(in);
  602. datasize = regcount * sizeof(u32);
  603. if (WARN_ON(datasize > A6XX_CD_DATA_SIZE))
  604. return;
  605. if (a6xx_crashdumper_run(gpu, dumper))
  606. return;
  607. obj->handle = cluster;
  608. obj->data = state_kmemdup(a6xx_state, dumper->ptr + A6XX_CD_DATA_OFFSET,
  609. datasize);
  610. }
  611. static void a6xx_get_clusters(struct msm_gpu *gpu,
  612. struct a6xx_gpu_state *a6xx_state,
  613. struct a6xx_crashdumper *dumper)
  614. {
  615. int i;
  616. a6xx_state->clusters = state_kcalloc(a6xx_state,
  617. ARRAY_SIZE(a6xx_clusters), sizeof(*a6xx_state->clusters));
  618. if (!a6xx_state->clusters)
  619. return;
  620. a6xx_state->nr_clusters = ARRAY_SIZE(a6xx_clusters);
  621. for (i = 0; i < ARRAY_SIZE(a6xx_clusters); i++)
  622. a6xx_get_cluster(gpu, a6xx_state, &a6xx_clusters[i],
  623. &a6xx_state->clusters[i], dumper);
  624. }
  625. static void a7xx_get_clusters(struct msm_gpu *gpu,
  626. struct a6xx_gpu_state *a6xx_state,
  627. struct a6xx_crashdumper *dumper)
  628. {
  629. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  630. int i;
  631. const struct gen7_cluster_registers *clusters;
  632. unsigned clusters_size;
  633. if (adreno_gpu->info->family == ADRENO_7XX_GEN1) {
  634. clusters = gen7_0_0_clusters;
  635. clusters_size = ARRAY_SIZE(gen7_0_0_clusters);
  636. } else if (adreno_gpu->info->family == ADRENO_7XX_GEN2) {
  637. clusters = gen7_2_0_clusters;
  638. clusters_size = ARRAY_SIZE(gen7_2_0_clusters);
  639. } else {
  640. BUG_ON(adreno_gpu->info->family != ADRENO_7XX_GEN3);
  641. clusters = gen7_9_0_clusters;
  642. clusters_size = ARRAY_SIZE(gen7_9_0_clusters);
  643. }
  644. a6xx_state->clusters = state_kcalloc(a6xx_state,
  645. clusters_size, sizeof(*a6xx_state->clusters));
  646. if (!a6xx_state->clusters)
  647. return;
  648. a6xx_state->nr_clusters = clusters_size;
  649. for (i = 0; i < clusters_size; i++)
  650. a7xx_get_cluster(gpu, a6xx_state, &clusters[i],
  651. &a6xx_state->clusters[i], dumper);
  652. }
  653. /* Read a shader / debug block from the HLSQ aperture with the crashdumper */
  654. static void a6xx_get_shader_block(struct msm_gpu *gpu,
  655. struct a6xx_gpu_state *a6xx_state,
  656. const struct a6xx_shader_block *block,
  657. struct a6xx_gpu_state_obj *obj,
  658. struct a6xx_crashdumper *dumper)
  659. {
  660. u64 *in = dumper->ptr;
  661. u64 out = dumper->iova + A6XX_CD_DATA_OFFSET;
  662. size_t datasize = block->size * A6XX_NUM_SHADER_BANKS * sizeof(u32);
  663. int i;
  664. if (WARN_ON(datasize > A6XX_CD_DATA_SIZE))
  665. return;
  666. for (i = 0; i < A6XX_NUM_SHADER_BANKS; i++) {
  667. in += CRASHDUMP_WRITE(in, REG_A6XX_HLSQ_DBG_READ_SEL,
  668. (block->type << 8) | i);
  669. in += CRASHDUMP_READ(in, REG_A6XX_HLSQ_DBG_AHB_READ_APERTURE,
  670. block->size, out);
  671. out += block->size * sizeof(u32);
  672. }
  673. CRASHDUMP_FINI(in);
  674. if (a6xx_crashdumper_run(gpu, dumper))
  675. return;
  676. obj->handle = block;
  677. obj->data = state_kmemdup(a6xx_state, dumper->ptr + A6XX_CD_DATA_OFFSET,
  678. datasize);
  679. }
  680. static void a7xx_get_shader_block(struct msm_gpu *gpu,
  681. struct a6xx_gpu_state *a6xx_state,
  682. const struct gen7_shader_block *block,
  683. struct a6xx_gpu_state_obj *obj,
  684. struct a6xx_crashdumper *dumper)
  685. {
  686. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  687. u64 *in = dumper->ptr;
  688. u64 out = dumper->iova + A6XX_CD_DATA_OFFSET;
  689. size_t datasize = block->size * block->num_sps * block->num_usptps * sizeof(u32);
  690. int i, j;
  691. if (WARN_ON(datasize > A6XX_CD_DATA_SIZE))
  692. return;
  693. if (adreno_gpu->info->family == ADRENO_7XX_GEN1) {
  694. gpu_rmw(gpu, REG_A7XX_SP_DBG_CNTL, GENMASK(1, 0), 3);
  695. }
  696. for (i = 0; i < block->num_sps; i++) {
  697. for (j = 0; j < block->num_usptps; j++) {
  698. in += CRASHDUMP_WRITE(in, REG_A7XX_SP_READ_SEL,
  699. A7XX_SP_READ_SEL_LOCATION(block->location) |
  700. A7XX_SP_READ_SEL_PIPE(block->pipeid) |
  701. A7XX_SP_READ_SEL_STATETYPE(block->statetype) |
  702. A7XX_SP_READ_SEL_USPTP(j) |
  703. A7XX_SP_READ_SEL_SPTP(i));
  704. in += CRASHDUMP_READ(in, REG_A7XX_SP_AHB_READ_APERTURE,
  705. block->size, out);
  706. out += block->size * sizeof(u32);
  707. }
  708. }
  709. CRASHDUMP_FINI(in);
  710. if (a6xx_crashdumper_run(gpu, dumper))
  711. goto out;
  712. obj->handle = block;
  713. obj->data = state_kmemdup(a6xx_state, dumper->ptr + A6XX_CD_DATA_OFFSET,
  714. datasize);
  715. out:
  716. if (adreno_gpu->info->family == ADRENO_7XX_GEN1) {
  717. gpu_rmw(gpu, REG_A7XX_SP_DBG_CNTL, GENMASK(1, 0), 0);
  718. }
  719. }
  720. static void a6xx_get_shaders(struct msm_gpu *gpu,
  721. struct a6xx_gpu_state *a6xx_state,
  722. struct a6xx_crashdumper *dumper)
  723. {
  724. int i;
  725. a6xx_state->shaders = state_kcalloc(a6xx_state,
  726. ARRAY_SIZE(a6xx_shader_blocks), sizeof(*a6xx_state->shaders));
  727. if (!a6xx_state->shaders)
  728. return;
  729. a6xx_state->nr_shaders = ARRAY_SIZE(a6xx_shader_blocks);
  730. for (i = 0; i < ARRAY_SIZE(a6xx_shader_blocks); i++)
  731. a6xx_get_shader_block(gpu, a6xx_state, &a6xx_shader_blocks[i],
  732. &a6xx_state->shaders[i], dumper);
  733. }
  734. static void a7xx_get_shaders(struct msm_gpu *gpu,
  735. struct a6xx_gpu_state *a6xx_state,
  736. struct a6xx_crashdumper *dumper)
  737. {
  738. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  739. const struct gen7_shader_block *shader_blocks;
  740. unsigned num_shader_blocks;
  741. int i;
  742. if (adreno_gpu->info->family == ADRENO_7XX_GEN1) {
  743. shader_blocks = gen7_0_0_shader_blocks;
  744. num_shader_blocks = ARRAY_SIZE(gen7_0_0_shader_blocks);
  745. } else if (adreno_gpu->info->family == ADRENO_7XX_GEN2) {
  746. shader_blocks = gen7_2_0_shader_blocks;
  747. num_shader_blocks = ARRAY_SIZE(gen7_2_0_shader_blocks);
  748. } else {
  749. BUG_ON(adreno_gpu->info->family != ADRENO_7XX_GEN3);
  750. shader_blocks = gen7_9_0_shader_blocks;
  751. num_shader_blocks = ARRAY_SIZE(gen7_9_0_shader_blocks);
  752. }
  753. a6xx_state->shaders = state_kcalloc(a6xx_state,
  754. num_shader_blocks, sizeof(*a6xx_state->shaders));
  755. if (!a6xx_state->shaders)
  756. return;
  757. a6xx_state->nr_shaders = num_shader_blocks;
  758. for (i = 0; i < num_shader_blocks; i++)
  759. a7xx_get_shader_block(gpu, a6xx_state, &shader_blocks[i],
  760. &a6xx_state->shaders[i], dumper);
  761. }
  762. /* Read registers from behind the HLSQ aperture with the crashdumper */
  763. static void a6xx_get_crashdumper_hlsq_registers(struct msm_gpu *gpu,
  764. struct a6xx_gpu_state *a6xx_state,
  765. const struct a6xx_registers *regs,
  766. struct a6xx_gpu_state_obj *obj,
  767. struct a6xx_crashdumper *dumper)
  768. {
  769. u64 *in = dumper->ptr;
  770. u64 out = dumper->iova + A6XX_CD_DATA_OFFSET;
  771. int i, regcount = 0;
  772. in += CRASHDUMP_WRITE(in, REG_A6XX_HLSQ_DBG_READ_SEL, regs->val1);
  773. for (i = 0; i < regs->count; i += 2) {
  774. u32 count = RANGE(regs->registers, i);
  775. u32 offset = REG_A6XX_HLSQ_DBG_AHB_READ_APERTURE +
  776. regs->registers[i] - (regs->val0 >> 2);
  777. in += CRASHDUMP_READ(in, offset, count, out);
  778. out += count * sizeof(u32);
  779. regcount += count;
  780. }
  781. CRASHDUMP_FINI(in);
  782. if (WARN_ON((regcount * sizeof(u32)) > A6XX_CD_DATA_SIZE))
  783. return;
  784. if (a6xx_crashdumper_run(gpu, dumper))
  785. return;
  786. obj->handle = regs;
  787. obj->data = state_kmemdup(a6xx_state, dumper->ptr + A6XX_CD_DATA_OFFSET,
  788. regcount * sizeof(u32));
  789. }
  790. /* Read a block of registers using the crashdumper */
  791. static void a6xx_get_crashdumper_registers(struct msm_gpu *gpu,
  792. struct a6xx_gpu_state *a6xx_state,
  793. const struct a6xx_registers *regs,
  794. struct a6xx_gpu_state_obj *obj,
  795. struct a6xx_crashdumper *dumper)
  796. {
  797. u64 *in = dumper->ptr;
  798. u64 out = dumper->iova + A6XX_CD_DATA_OFFSET;
  799. int i, regcount = 0;
  800. /* Skip unsupported registers on older generations */
  801. if (!adreno_is_a660_family(to_adreno_gpu(gpu)) &&
  802. (regs->registers == a660_registers))
  803. return;
  804. /* Some blocks might need to program a selector register first */
  805. if (regs->val0)
  806. in += CRASHDUMP_WRITE(in, regs->val0, regs->val1);
  807. for (i = 0; i < regs->count; i += 2) {
  808. u32 count = RANGE(regs->registers, i);
  809. in += CRASHDUMP_READ(in, regs->registers[i], count, out);
  810. out += count * sizeof(u32);
  811. regcount += count;
  812. }
  813. CRASHDUMP_FINI(in);
  814. if (WARN_ON((regcount * sizeof(u32)) > A6XX_CD_DATA_SIZE))
  815. return;
  816. if (a6xx_crashdumper_run(gpu, dumper))
  817. return;
  818. obj->handle = regs;
  819. obj->data = state_kmemdup(a6xx_state, dumper->ptr + A6XX_CD_DATA_OFFSET,
  820. regcount * sizeof(u32));
  821. }
  822. static void a7xx_get_crashdumper_registers(struct msm_gpu *gpu,
  823. struct a6xx_gpu_state *a6xx_state,
  824. const struct gen7_reg_list *regs,
  825. struct a6xx_gpu_state_obj *obj,
  826. struct a6xx_crashdumper *dumper)
  827. {
  828. u64 *in = dumper->ptr;
  829. u64 out = dumper->iova + A6XX_CD_DATA_OFFSET;
  830. int i, regcount = 0;
  831. /* Some blocks might need to program a selector register first */
  832. if (regs->sel)
  833. in += CRASHDUMP_WRITE(in, regs->sel->cd_reg, regs->sel->val);
  834. for (i = 0; regs->regs[i] != UINT_MAX; i += 2) {
  835. u32 count = RANGE(regs->regs, i);
  836. in += CRASHDUMP_READ(in, regs->regs[i], count, out);
  837. out += count * sizeof(u32);
  838. regcount += count;
  839. }
  840. CRASHDUMP_FINI(in);
  841. if (WARN_ON((regcount * sizeof(u32)) > A6XX_CD_DATA_SIZE))
  842. return;
  843. if (a6xx_crashdumper_run(gpu, dumper))
  844. return;
  845. obj->handle = regs->regs;
  846. obj->data = state_kmemdup(a6xx_state, dumper->ptr + A6XX_CD_DATA_OFFSET,
  847. regcount * sizeof(u32));
  848. }
  849. /* Read a block of registers via AHB */
  850. static void a6xx_get_ahb_gpu_registers(struct msm_gpu *gpu,
  851. struct a6xx_gpu_state *a6xx_state,
  852. const struct a6xx_registers *regs,
  853. struct a6xx_gpu_state_obj *obj)
  854. {
  855. int i, regcount = 0, index = 0;
  856. /* Skip unsupported registers on older generations */
  857. if (!adreno_is_a660_family(to_adreno_gpu(gpu)) &&
  858. (regs->registers == a660_registers))
  859. return;
  860. for (i = 0; i < regs->count; i += 2)
  861. regcount += RANGE(regs->registers, i);
  862. obj->handle = (const void *) regs;
  863. obj->data = state_kcalloc(a6xx_state, regcount, sizeof(u32));
  864. if (!obj->data)
  865. return;
  866. for (i = 0; i < regs->count; i += 2) {
  867. u32 count = RANGE(regs->registers, i);
  868. int j;
  869. for (j = 0; j < count; j++)
  870. obj->data[index++] = gpu_read(gpu,
  871. regs->registers[i] + j);
  872. }
  873. }
  874. static void a7xx_get_ahb_gpu_registers(struct msm_gpu *gpu,
  875. struct a6xx_gpu_state *a6xx_state,
  876. const u32 *regs,
  877. struct a6xx_gpu_state_obj *obj)
  878. {
  879. int i, regcount = 0, index = 0;
  880. for (i = 0; regs[i] != UINT_MAX; i += 2)
  881. regcount += RANGE(regs, i);
  882. obj->handle = (const void *) regs;
  883. obj->data = state_kcalloc(a6xx_state, regcount, sizeof(u32));
  884. if (!obj->data)
  885. return;
  886. for (i = 0; regs[i] != UINT_MAX; i += 2) {
  887. u32 count = RANGE(regs, i);
  888. int j;
  889. for (j = 0; j < count; j++)
  890. obj->data[index++] = gpu_read(gpu, regs[i] + j);
  891. }
  892. }
  893. static void a7xx_get_ahb_gpu_reglist(struct msm_gpu *gpu,
  894. struct a6xx_gpu_state *a6xx_state,
  895. const struct gen7_reg_list *regs,
  896. struct a6xx_gpu_state_obj *obj)
  897. {
  898. if (regs->sel)
  899. gpu_write(gpu, regs->sel->host_reg, regs->sel->val);
  900. a7xx_get_ahb_gpu_registers(gpu, a6xx_state, regs->regs, obj);
  901. }
  902. /* Read a block of GMU registers */
  903. static void _a6xx_get_gmu_registers(struct msm_gpu *gpu,
  904. struct a6xx_gpu_state *a6xx_state,
  905. const struct a6xx_registers *regs,
  906. struct a6xx_gpu_state_obj *obj,
  907. bool rscc)
  908. {
  909. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  910. struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
  911. struct a6xx_gmu *gmu = &a6xx_gpu->gmu;
  912. int i, regcount = 0, index = 0;
  913. for (i = 0; i < regs->count; i += 2)
  914. regcount += RANGE(regs->registers, i);
  915. obj->handle = (const void *) regs;
  916. obj->data = state_kcalloc(a6xx_state, regcount, sizeof(u32));
  917. if (!obj->data)
  918. return;
  919. for (i = 0; i < regs->count; i += 2) {
  920. u32 count = RANGE(regs->registers, i);
  921. int j;
  922. for (j = 0; j < count; j++) {
  923. u32 offset = regs->registers[i] + j;
  924. u32 val;
  925. if (rscc)
  926. val = gmu_read_rscc(gmu, offset);
  927. else
  928. val = gmu_read(gmu, offset);
  929. obj->data[index++] = val;
  930. }
  931. }
  932. }
  933. static void a6xx_get_gmu_registers(struct msm_gpu *gpu,
  934. struct a6xx_gpu_state *a6xx_state)
  935. {
  936. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  937. struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
  938. a6xx_state->gmu_registers = state_kcalloc(a6xx_state,
  939. 3, sizeof(*a6xx_state->gmu_registers));
  940. if (!a6xx_state->gmu_registers)
  941. return;
  942. a6xx_state->nr_gmu_registers = 3;
  943. /* Get the CX GMU registers from AHB */
  944. _a6xx_get_gmu_registers(gpu, a6xx_state, &a6xx_gmu_reglist[0],
  945. &a6xx_state->gmu_registers[0], false);
  946. _a6xx_get_gmu_registers(gpu, a6xx_state, &a6xx_gmu_reglist[1],
  947. &a6xx_state->gmu_registers[1], true);
  948. if (!a6xx_gmu_gx_is_on(&a6xx_gpu->gmu))
  949. return;
  950. /* Set the fence to ALLOW mode so we can access the registers */
  951. gpu_write(gpu, REG_A6XX_GMU_AO_AHB_FENCE_CTRL, 0);
  952. _a6xx_get_gmu_registers(gpu, a6xx_state, &a6xx_gmu_reglist[2],
  953. &a6xx_state->gmu_registers[2], false);
  954. }
  955. static struct msm_gpu_state_bo *a6xx_snapshot_gmu_bo(
  956. struct a6xx_gpu_state *a6xx_state, struct a6xx_gmu_bo *bo)
  957. {
  958. struct msm_gpu_state_bo *snapshot;
  959. if (!bo->size)
  960. return NULL;
  961. snapshot = state_kcalloc(a6xx_state, 1, sizeof(*snapshot));
  962. if (!snapshot)
  963. return NULL;
  964. snapshot->iova = bo->iova;
  965. snapshot->size = bo->size;
  966. snapshot->data = kvzalloc(snapshot->size, GFP_KERNEL);
  967. if (!snapshot->data)
  968. return NULL;
  969. memcpy(snapshot->data, bo->virt, bo->size);
  970. return snapshot;
  971. }
  972. static void a6xx_snapshot_gmu_hfi_history(struct msm_gpu *gpu,
  973. struct a6xx_gpu_state *a6xx_state)
  974. {
  975. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  976. struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
  977. struct a6xx_gmu *gmu = &a6xx_gpu->gmu;
  978. unsigned i, j;
  979. BUILD_BUG_ON(ARRAY_SIZE(gmu->queues) != ARRAY_SIZE(a6xx_state->hfi_queue_history));
  980. for (i = 0; i < ARRAY_SIZE(gmu->queues); i++) {
  981. struct a6xx_hfi_queue *queue = &gmu->queues[i];
  982. for (j = 0; j < HFI_HISTORY_SZ; j++) {
  983. unsigned idx = (j + queue->history_idx) % HFI_HISTORY_SZ;
  984. a6xx_state->hfi_queue_history[i][j] = queue->history[idx];
  985. }
  986. }
  987. }
  988. #define A6XX_REGLIST_SIZE 1
  989. #define A6XX_GBIF_REGLIST_SIZE 1
  990. static void a6xx_get_registers(struct msm_gpu *gpu,
  991. struct a6xx_gpu_state *a6xx_state,
  992. struct a6xx_crashdumper *dumper)
  993. {
  994. int i, count = A6XX_REGLIST_SIZE +
  995. ARRAY_SIZE(a6xx_reglist) +
  996. ARRAY_SIZE(a6xx_hlsq_reglist) + A6XX_GBIF_REGLIST_SIZE;
  997. int index = 0;
  998. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  999. a6xx_state->registers = state_kcalloc(a6xx_state,
  1000. count, sizeof(*a6xx_state->registers));
  1001. if (!a6xx_state->registers)
  1002. return;
  1003. a6xx_state->nr_registers = count;
  1004. a6xx_get_ahb_gpu_registers(gpu,
  1005. a6xx_state, &a6xx_ahb_reglist,
  1006. &a6xx_state->registers[index++]);
  1007. if (a6xx_has_gbif(adreno_gpu))
  1008. a6xx_get_ahb_gpu_registers(gpu,
  1009. a6xx_state, &a6xx_gbif_reglist,
  1010. &a6xx_state->registers[index++]);
  1011. else
  1012. a6xx_get_ahb_gpu_registers(gpu,
  1013. a6xx_state, &a6xx_vbif_reglist,
  1014. &a6xx_state->registers[index++]);
  1015. if (!dumper) {
  1016. /*
  1017. * We can't use the crashdumper when the SMMU is stalled,
  1018. * because the GPU has no memory access until we resume
  1019. * translation (but we don't want to do that until after
  1020. * we have captured as much useful GPU state as possible).
  1021. * So instead collect registers via the CPU:
  1022. */
  1023. for (i = 0; i < ARRAY_SIZE(a6xx_reglist); i++)
  1024. a6xx_get_ahb_gpu_registers(gpu,
  1025. a6xx_state, &a6xx_reglist[i],
  1026. &a6xx_state->registers[index++]);
  1027. return;
  1028. }
  1029. for (i = 0; i < ARRAY_SIZE(a6xx_reglist); i++)
  1030. a6xx_get_crashdumper_registers(gpu,
  1031. a6xx_state, &a6xx_reglist[i],
  1032. &a6xx_state->registers[index++],
  1033. dumper);
  1034. for (i = 0; i < ARRAY_SIZE(a6xx_hlsq_reglist); i++)
  1035. a6xx_get_crashdumper_hlsq_registers(gpu,
  1036. a6xx_state, &a6xx_hlsq_reglist[i],
  1037. &a6xx_state->registers[index++],
  1038. dumper);
  1039. }
  1040. #define A7XX_PRE_CRASHDUMPER_SIZE 1
  1041. #define A7XX_POST_CRASHDUMPER_SIZE 1
  1042. static void a7xx_get_registers(struct msm_gpu *gpu,
  1043. struct a6xx_gpu_state *a6xx_state,
  1044. struct a6xx_crashdumper *dumper)
  1045. {
  1046. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  1047. int i, count;
  1048. int index = 0;
  1049. const u32 *pre_crashdumper_regs;
  1050. const struct gen7_reg_list *reglist;
  1051. if (adreno_gpu->info->family == ADRENO_7XX_GEN1) {
  1052. reglist = gen7_0_0_reg_list;
  1053. pre_crashdumper_regs = gen7_0_0_pre_crashdumper_gpu_registers;
  1054. } else if (adreno_gpu->info->family == ADRENO_7XX_GEN2) {
  1055. reglist = gen7_2_0_reg_list;
  1056. pre_crashdumper_regs = gen7_0_0_pre_crashdumper_gpu_registers;
  1057. } else {
  1058. BUG_ON(adreno_gpu->info->family != ADRENO_7XX_GEN3);
  1059. reglist = gen7_9_0_reg_list;
  1060. pre_crashdumper_regs = gen7_9_0_pre_crashdumper_gpu_registers;
  1061. }
  1062. count = A7XX_PRE_CRASHDUMPER_SIZE + A7XX_POST_CRASHDUMPER_SIZE;
  1063. /* The downstream reglist contains registers in other memory regions
  1064. * (cx_misc/cx_mem and cx_dbgc) and we need to plumb through their
  1065. * offsets and map them to read them on the CPU. For now only read the
  1066. * first region which is the main one.
  1067. */
  1068. if (dumper) {
  1069. for (i = 0; reglist[i].regs; i++)
  1070. count++;
  1071. } else {
  1072. count++;
  1073. }
  1074. a6xx_state->registers = state_kcalloc(a6xx_state,
  1075. count, sizeof(*a6xx_state->registers));
  1076. if (!a6xx_state->registers)
  1077. return;
  1078. a6xx_state->nr_registers = count;
  1079. a7xx_get_ahb_gpu_registers(gpu, a6xx_state, pre_crashdumper_regs,
  1080. &a6xx_state->registers[index++]);
  1081. if (!dumper) {
  1082. a7xx_get_ahb_gpu_reglist(gpu,
  1083. a6xx_state, &reglist[0],
  1084. &a6xx_state->registers[index++]);
  1085. return;
  1086. }
  1087. for (i = 0; reglist[i].regs; i++)
  1088. a7xx_get_crashdumper_registers(gpu,
  1089. a6xx_state, &reglist[i],
  1090. &a6xx_state->registers[index++],
  1091. dumper);
  1092. }
  1093. static void a7xx_get_post_crashdumper_registers(struct msm_gpu *gpu,
  1094. struct a6xx_gpu_state *a6xx_state)
  1095. {
  1096. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  1097. const u32 *regs;
  1098. BUG_ON(adreno_gpu->info->family > ADRENO_7XX_GEN3);
  1099. regs = gen7_0_0_post_crashdumper_registers;
  1100. a7xx_get_ahb_gpu_registers(gpu,
  1101. a6xx_state, regs,
  1102. &a6xx_state->registers[a6xx_state->nr_registers - 1]);
  1103. }
  1104. static u32 a6xx_get_cp_roq_size(struct msm_gpu *gpu)
  1105. {
  1106. /* The value at [16:31] is in 4dword units. Convert it to dwords */
  1107. return gpu_read(gpu, REG_A6XX_CP_ROQ_THRESHOLDS_2) >> 14;
  1108. }
  1109. static u32 a7xx_get_cp_roq_size(struct msm_gpu *gpu)
  1110. {
  1111. /*
  1112. * The value at CP_ROQ_THRESHOLDS_2[20:31] is in 4dword units.
  1113. * That register however is not directly accessible from APSS on A7xx.
  1114. * Program the SQE_UCODE_DBG_ADDR with offset=0x70d3 and read the value.
  1115. */
  1116. gpu_write(gpu, REG_A6XX_CP_SQE_UCODE_DBG_ADDR, 0x70d3);
  1117. return 4 * (gpu_read(gpu, REG_A6XX_CP_SQE_UCODE_DBG_DATA) >> 20);
  1118. }
  1119. /* Read a block of data from an indexed register pair */
  1120. static void a6xx_get_indexed_regs(struct msm_gpu *gpu,
  1121. struct a6xx_gpu_state *a6xx_state,
  1122. const struct a6xx_indexed_registers *indexed,
  1123. struct a6xx_gpu_state_obj *obj)
  1124. {
  1125. u32 count = indexed->count;
  1126. int i;
  1127. obj->handle = (const void *) indexed;
  1128. if (indexed->count_fn)
  1129. count = indexed->count_fn(gpu);
  1130. obj->data = state_kcalloc(a6xx_state, count, sizeof(u32));
  1131. obj->count = count;
  1132. if (!obj->data)
  1133. return;
  1134. /* All the indexed banks start at address 0 */
  1135. gpu_write(gpu, indexed->addr, 0);
  1136. /* Read the data - each read increments the internal address by 1 */
  1137. for (i = 0; i < count; i++)
  1138. obj->data[i] = gpu_read(gpu, indexed->data);
  1139. }
  1140. static void a6xx_get_indexed_registers(struct msm_gpu *gpu,
  1141. struct a6xx_gpu_state *a6xx_state)
  1142. {
  1143. u32 mempool_size;
  1144. int count = ARRAY_SIZE(a6xx_indexed_reglist) + 1;
  1145. int i;
  1146. a6xx_state->indexed_regs = state_kcalloc(a6xx_state, count,
  1147. sizeof(*a6xx_state->indexed_regs));
  1148. if (!a6xx_state->indexed_regs)
  1149. return;
  1150. for (i = 0; i < ARRAY_SIZE(a6xx_indexed_reglist); i++)
  1151. a6xx_get_indexed_regs(gpu, a6xx_state, &a6xx_indexed_reglist[i],
  1152. &a6xx_state->indexed_regs[i]);
  1153. if (adreno_is_a650_family(to_adreno_gpu(gpu))) {
  1154. u32 val;
  1155. val = gpu_read(gpu, REG_A6XX_CP_CHICKEN_DBG);
  1156. gpu_write(gpu, REG_A6XX_CP_CHICKEN_DBG, val | 4);
  1157. /* Get the contents of the CP mempool */
  1158. a6xx_get_indexed_regs(gpu, a6xx_state, &a6xx_cp_mempool_indexed,
  1159. &a6xx_state->indexed_regs[i]);
  1160. gpu_write(gpu, REG_A6XX_CP_CHICKEN_DBG, val);
  1161. a6xx_state->nr_indexed_regs = count;
  1162. return;
  1163. }
  1164. /* Set the CP mempool size to 0 to stabilize it while dumping */
  1165. mempool_size = gpu_read(gpu, REG_A6XX_CP_MEM_POOL_SIZE);
  1166. gpu_write(gpu, REG_A6XX_CP_MEM_POOL_SIZE, 0);
  1167. /* Get the contents of the CP mempool */
  1168. a6xx_get_indexed_regs(gpu, a6xx_state, &a6xx_cp_mempool_indexed,
  1169. &a6xx_state->indexed_regs[i]);
  1170. /*
  1171. * Offset 0x2000 in the mempool is the size - copy the saved size over
  1172. * so the data is consistent
  1173. */
  1174. a6xx_state->indexed_regs[i].data[0x2000] = mempool_size;
  1175. /* Restore the size in the hardware */
  1176. gpu_write(gpu, REG_A6XX_CP_MEM_POOL_SIZE, mempool_size);
  1177. a6xx_state->nr_indexed_regs = count;
  1178. }
  1179. static void a7xx_get_indexed_registers(struct msm_gpu *gpu,
  1180. struct a6xx_gpu_state *a6xx_state)
  1181. {
  1182. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  1183. const struct a6xx_indexed_registers *indexed_regs;
  1184. int i, indexed_count, mempool_count;
  1185. if (adreno_gpu->info->family <= ADRENO_7XX_GEN2) {
  1186. indexed_regs = a7xx_indexed_reglist;
  1187. indexed_count = ARRAY_SIZE(a7xx_indexed_reglist);
  1188. } else {
  1189. BUG_ON(adreno_gpu->info->family != ADRENO_7XX_GEN3);
  1190. indexed_regs = gen7_9_0_cp_indexed_reg_list;
  1191. indexed_count = ARRAY_SIZE(gen7_9_0_cp_indexed_reg_list);
  1192. }
  1193. mempool_count = ARRAY_SIZE(a7xx_cp_bv_mempool_indexed);
  1194. a6xx_state->indexed_regs = state_kcalloc(a6xx_state,
  1195. indexed_count + mempool_count,
  1196. sizeof(*a6xx_state->indexed_regs));
  1197. if (!a6xx_state->indexed_regs)
  1198. return;
  1199. a6xx_state->nr_indexed_regs = indexed_count + mempool_count;
  1200. /* First read the common regs */
  1201. for (i = 0; i < indexed_count; i++)
  1202. a6xx_get_indexed_regs(gpu, a6xx_state, &indexed_regs[i],
  1203. &a6xx_state->indexed_regs[i]);
  1204. gpu_rmw(gpu, REG_A6XX_CP_CHICKEN_DBG, 0, BIT(2));
  1205. gpu_rmw(gpu, REG_A7XX_CP_BV_CHICKEN_DBG, 0, BIT(2));
  1206. /* Get the contents of the CP_BV mempool */
  1207. for (i = 0; i < mempool_count; i++)
  1208. a6xx_get_indexed_regs(gpu, a6xx_state, &a7xx_cp_bv_mempool_indexed[i],
  1209. &a6xx_state->indexed_regs[indexed_count + i]);
  1210. gpu_rmw(gpu, REG_A6XX_CP_CHICKEN_DBG, BIT(2), 0);
  1211. gpu_rmw(gpu, REG_A7XX_CP_BV_CHICKEN_DBG, BIT(2), 0);
  1212. return;
  1213. }
  1214. struct msm_gpu_state *a6xx_gpu_state_get(struct msm_gpu *gpu)
  1215. {
  1216. struct a6xx_crashdumper _dumper = { 0 }, *dumper = NULL;
  1217. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  1218. struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
  1219. struct a6xx_gpu_state *a6xx_state = kzalloc(sizeof(*a6xx_state),
  1220. GFP_KERNEL);
  1221. bool stalled = !!(gpu_read(gpu, REG_A6XX_RBBM_STATUS3) &
  1222. A6XX_RBBM_STATUS3_SMMU_STALLED_ON_FAULT);
  1223. if (!a6xx_state)
  1224. return ERR_PTR(-ENOMEM);
  1225. INIT_LIST_HEAD(&a6xx_state->objs);
  1226. /* Get the generic state from the adreno core */
  1227. adreno_gpu_state_get(gpu, &a6xx_state->base);
  1228. if (!adreno_has_gmu_wrapper(adreno_gpu)) {
  1229. a6xx_get_gmu_registers(gpu, a6xx_state);
  1230. a6xx_state->gmu_log = a6xx_snapshot_gmu_bo(a6xx_state, &a6xx_gpu->gmu.log);
  1231. a6xx_state->gmu_hfi = a6xx_snapshot_gmu_bo(a6xx_state, &a6xx_gpu->gmu.hfi);
  1232. a6xx_state->gmu_debug = a6xx_snapshot_gmu_bo(a6xx_state, &a6xx_gpu->gmu.debug);
  1233. a6xx_snapshot_gmu_hfi_history(gpu, a6xx_state);
  1234. }
  1235. /* If GX isn't on the rest of the data isn't going to be accessible */
  1236. if (!adreno_has_gmu_wrapper(adreno_gpu) && !a6xx_gmu_gx_is_on(&a6xx_gpu->gmu))
  1237. return &a6xx_state->base;
  1238. /* Get the banks of indexed registers */
  1239. if (adreno_is_a7xx(adreno_gpu))
  1240. a7xx_get_indexed_registers(gpu, a6xx_state);
  1241. else
  1242. a6xx_get_indexed_registers(gpu, a6xx_state);
  1243. /*
  1244. * Try to initialize the crashdumper, if we are not dumping state
  1245. * with the SMMU stalled. The crashdumper needs memory access to
  1246. * write out GPU state, so we need to skip this when the SMMU is
  1247. * stalled in response to an iova fault
  1248. */
  1249. if (!stalled && !gpu->needs_hw_init &&
  1250. !a6xx_crashdumper_init(gpu, &_dumper)) {
  1251. dumper = &_dumper;
  1252. }
  1253. if (adreno_is_a7xx(adreno_gpu)) {
  1254. a7xx_get_registers(gpu, a6xx_state, dumper);
  1255. if (dumper) {
  1256. a7xx_get_shaders(gpu, a6xx_state, dumper);
  1257. a7xx_get_clusters(gpu, a6xx_state, dumper);
  1258. a7xx_get_dbgahb_clusters(gpu, a6xx_state, dumper);
  1259. msm_gem_kernel_put(dumper->bo, gpu->aspace);
  1260. }
  1261. a7xx_get_post_crashdumper_registers(gpu, a6xx_state);
  1262. } else {
  1263. a6xx_get_registers(gpu, a6xx_state, dumper);
  1264. if (dumper) {
  1265. a6xx_get_shaders(gpu, a6xx_state, dumper);
  1266. a6xx_get_clusters(gpu, a6xx_state, dumper);
  1267. a6xx_get_dbgahb_clusters(gpu, a6xx_state, dumper);
  1268. msm_gem_kernel_put(dumper->bo, gpu->aspace);
  1269. }
  1270. }
  1271. if (snapshot_debugbus)
  1272. a6xx_get_debugbus(gpu, a6xx_state);
  1273. a6xx_state->gpu_initialized = !gpu->needs_hw_init;
  1274. return &a6xx_state->base;
  1275. }
  1276. static void a6xx_gpu_state_destroy(struct kref *kref)
  1277. {
  1278. struct a6xx_state_memobj *obj, *tmp;
  1279. struct msm_gpu_state *state = container_of(kref,
  1280. struct msm_gpu_state, ref);
  1281. struct a6xx_gpu_state *a6xx_state = container_of(state,
  1282. struct a6xx_gpu_state, base);
  1283. if (a6xx_state->gmu_log)
  1284. kvfree(a6xx_state->gmu_log->data);
  1285. if (a6xx_state->gmu_hfi)
  1286. kvfree(a6xx_state->gmu_hfi->data);
  1287. if (a6xx_state->gmu_debug)
  1288. kvfree(a6xx_state->gmu_debug->data);
  1289. list_for_each_entry_safe(obj, tmp, &a6xx_state->objs, node) {
  1290. list_del(&obj->node);
  1291. kvfree(obj);
  1292. }
  1293. adreno_gpu_state_destroy(state);
  1294. kfree(a6xx_state);
  1295. }
  1296. int a6xx_gpu_state_put(struct msm_gpu_state *state)
  1297. {
  1298. if (IS_ERR_OR_NULL(state))
  1299. return 1;
  1300. return kref_put(&state->ref, a6xx_gpu_state_destroy);
  1301. }
  1302. static void a6xx_show_registers(const u32 *registers, u32 *data, size_t count,
  1303. struct drm_printer *p)
  1304. {
  1305. int i, index = 0;
  1306. if (!data)
  1307. return;
  1308. for (i = 0; i < count; i += 2) {
  1309. u32 count = RANGE(registers, i);
  1310. u32 offset = registers[i];
  1311. int j;
  1312. for (j = 0; j < count; index++, offset++, j++) {
  1313. if (data[index] == 0xdeafbead)
  1314. continue;
  1315. drm_printf(p, " - { offset: 0x%06x, value: 0x%08x }\n",
  1316. offset << 2, data[index]);
  1317. }
  1318. }
  1319. }
  1320. static void a7xx_show_registers_indented(const u32 *registers, u32 *data,
  1321. struct drm_printer *p, unsigned indent)
  1322. {
  1323. int i, index = 0;
  1324. for (i = 0; registers[i] != UINT_MAX; i += 2) {
  1325. u32 count = RANGE(registers, i);
  1326. u32 offset = registers[i];
  1327. int j;
  1328. for (j = 0; j < count; index++, offset++, j++) {
  1329. int k;
  1330. if (data[index] == 0xdeafbead)
  1331. continue;
  1332. for (k = 0; k < indent; k++)
  1333. drm_printf(p, " ");
  1334. drm_printf(p, "- { offset: 0x%06x, value: 0x%08x }\n",
  1335. offset << 2, data[index]);
  1336. }
  1337. }
  1338. }
  1339. static void a7xx_show_registers(const u32 *registers, u32 *data, struct drm_printer *p)
  1340. {
  1341. a7xx_show_registers_indented(registers, data, p, 1);
  1342. }
  1343. static void print_ascii85(struct drm_printer *p, size_t len, u32 *data)
  1344. {
  1345. char out[ASCII85_BUFSZ];
  1346. long i, l, datalen = 0;
  1347. for (i = 0; i < len >> 2; i++) {
  1348. if (data[i])
  1349. datalen = (i + 1) << 2;
  1350. }
  1351. if (datalen == 0)
  1352. return;
  1353. drm_puts(p, " data: !!ascii85 |\n");
  1354. drm_puts(p, " ");
  1355. l = ascii85_encode_len(datalen);
  1356. for (i = 0; i < l; i++)
  1357. drm_puts(p, ascii85_encode(data[i], out));
  1358. drm_puts(p, "\n");
  1359. }
  1360. static void print_name(struct drm_printer *p, const char *fmt, const char *name)
  1361. {
  1362. drm_puts(p, fmt);
  1363. drm_puts(p, name);
  1364. drm_puts(p, "\n");
  1365. }
  1366. static void a6xx_show_shader(struct a6xx_gpu_state_obj *obj,
  1367. struct drm_printer *p)
  1368. {
  1369. const struct a6xx_shader_block *block = obj->handle;
  1370. int i;
  1371. if (!obj->handle)
  1372. return;
  1373. print_name(p, " - type: ", block->name);
  1374. for (i = 0; i < A6XX_NUM_SHADER_BANKS; i++) {
  1375. drm_printf(p, " - bank: %d\n", i);
  1376. drm_printf(p, " size: %d\n", block->size);
  1377. if (!obj->data)
  1378. continue;
  1379. print_ascii85(p, block->size << 2,
  1380. obj->data + (block->size * i));
  1381. }
  1382. }
  1383. static void a7xx_show_shader(struct a6xx_gpu_state_obj *obj,
  1384. struct drm_printer *p)
  1385. {
  1386. const struct gen7_shader_block *block = obj->handle;
  1387. int i, j;
  1388. u32 *data = obj->data;
  1389. if (!obj->handle)
  1390. return;
  1391. print_name(p, " - type: ", a7xx_statetype_names[block->statetype]);
  1392. print_name(p, " - pipe: ", a7xx_pipe_names[block->pipeid]);
  1393. for (i = 0; i < block->num_sps; i++) {
  1394. drm_printf(p, " - sp: %d\n", i);
  1395. for (j = 0; j < block->num_usptps; j++) {
  1396. drm_printf(p, " - usptp: %d\n", j);
  1397. drm_printf(p, " size: %d\n", block->size);
  1398. if (!obj->data)
  1399. continue;
  1400. print_ascii85(p, block->size << 2, data);
  1401. data += block->size;
  1402. }
  1403. }
  1404. }
  1405. static void a6xx_show_cluster_data(const u32 *registers, int size, u32 *data,
  1406. struct drm_printer *p)
  1407. {
  1408. int ctx, index = 0;
  1409. for (ctx = 0; ctx < A6XX_NUM_CONTEXTS; ctx++) {
  1410. int j;
  1411. drm_printf(p, " - context: %d\n", ctx);
  1412. for (j = 0; j < size; j += 2) {
  1413. u32 count = RANGE(registers, j);
  1414. u32 offset = registers[j];
  1415. int k;
  1416. for (k = 0; k < count; index++, offset++, k++) {
  1417. if (data[index] == 0xdeafbead)
  1418. continue;
  1419. drm_printf(p, " - { offset: 0x%06x, value: 0x%08x }\n",
  1420. offset << 2, data[index]);
  1421. }
  1422. }
  1423. }
  1424. }
  1425. static void a6xx_show_dbgahb_cluster(struct a6xx_gpu_state_obj *obj,
  1426. struct drm_printer *p)
  1427. {
  1428. const struct a6xx_dbgahb_cluster *dbgahb = obj->handle;
  1429. if (dbgahb) {
  1430. print_name(p, " - cluster-name: ", dbgahb->name);
  1431. a6xx_show_cluster_data(dbgahb->registers, dbgahb->count,
  1432. obj->data, p);
  1433. }
  1434. }
  1435. static void a6xx_show_cluster(struct a6xx_gpu_state_obj *obj,
  1436. struct drm_printer *p)
  1437. {
  1438. const struct a6xx_cluster *cluster = obj->handle;
  1439. if (cluster) {
  1440. print_name(p, " - cluster-name: ", cluster->name);
  1441. a6xx_show_cluster_data(cluster->registers, cluster->count,
  1442. obj->data, p);
  1443. }
  1444. }
  1445. static void a7xx_show_dbgahb_cluster(struct a6xx_gpu_state_obj *obj,
  1446. struct drm_printer *p)
  1447. {
  1448. const struct gen7_sptp_cluster_registers *dbgahb = obj->handle;
  1449. if (dbgahb) {
  1450. print_name(p, " - pipe: ", a7xx_pipe_names[dbgahb->pipe_id]);
  1451. print_name(p, " - cluster-name: ", a7xx_cluster_names[dbgahb->cluster_id]);
  1452. drm_printf(p, " - context: %d\n", dbgahb->context_id);
  1453. a7xx_show_registers_indented(dbgahb->regs, obj->data, p, 4);
  1454. }
  1455. }
  1456. static void a7xx_show_cluster(struct a6xx_gpu_state_obj *obj,
  1457. struct drm_printer *p)
  1458. {
  1459. const struct gen7_cluster_registers *cluster = obj->handle;
  1460. if (cluster) {
  1461. int context = (cluster->context_id == STATE_FORCE_CTXT_1) ? 1 : 0;
  1462. print_name(p, " - pipe: ", a7xx_pipe_names[cluster->pipe_id]);
  1463. print_name(p, " - cluster-name: ", a7xx_cluster_names[cluster->cluster_id]);
  1464. drm_printf(p, " - context: %d\n", context);
  1465. a7xx_show_registers_indented(cluster->regs, obj->data, p, 4);
  1466. }
  1467. }
  1468. static void a6xx_show_indexed_regs(struct a6xx_gpu_state_obj *obj,
  1469. struct drm_printer *p)
  1470. {
  1471. const struct a6xx_indexed_registers *indexed = obj->handle;
  1472. if (!indexed)
  1473. return;
  1474. print_name(p, " - regs-name: ", indexed->name);
  1475. drm_printf(p, " dwords: %d\n", obj->count);
  1476. print_ascii85(p, obj->count << 2, obj->data);
  1477. }
  1478. static void a6xx_show_debugbus_block(const struct a6xx_debugbus_block *block,
  1479. u32 *data, struct drm_printer *p)
  1480. {
  1481. if (block) {
  1482. print_name(p, " - debugbus-block: ", block->name);
  1483. /*
  1484. * count for regular debugbus data is in quadwords,
  1485. * but print the size in dwords for consistency
  1486. */
  1487. drm_printf(p, " count: %d\n", block->count << 1);
  1488. print_ascii85(p, block->count << 3, data);
  1489. }
  1490. }
  1491. static void a6xx_show_debugbus(struct a6xx_gpu_state *a6xx_state,
  1492. struct drm_printer *p)
  1493. {
  1494. int i;
  1495. for (i = 0; i < a6xx_state->nr_debugbus; i++) {
  1496. struct a6xx_gpu_state_obj *obj = &a6xx_state->debugbus[i];
  1497. a6xx_show_debugbus_block(obj->handle, obj->data, p);
  1498. }
  1499. if (a6xx_state->vbif_debugbus) {
  1500. struct a6xx_gpu_state_obj *obj = a6xx_state->vbif_debugbus;
  1501. drm_puts(p, " - debugbus-block: A6XX_DBGBUS_VBIF\n");
  1502. drm_printf(p, " count: %d\n", VBIF_DEBUGBUS_BLOCK_SIZE);
  1503. /* vbif debugbus data is in dwords. Confusing, huh? */
  1504. print_ascii85(p, VBIF_DEBUGBUS_BLOCK_SIZE << 2, obj->data);
  1505. }
  1506. for (i = 0; i < a6xx_state->nr_cx_debugbus; i++) {
  1507. struct a6xx_gpu_state_obj *obj = &a6xx_state->cx_debugbus[i];
  1508. a6xx_show_debugbus_block(obj->handle, obj->data, p);
  1509. }
  1510. }
  1511. void a6xx_show(struct msm_gpu *gpu, struct msm_gpu_state *state,
  1512. struct drm_printer *p)
  1513. {
  1514. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  1515. struct a6xx_gpu_state *a6xx_state = container_of(state,
  1516. struct a6xx_gpu_state, base);
  1517. int i;
  1518. if (IS_ERR_OR_NULL(state))
  1519. return;
  1520. drm_printf(p, "gpu-initialized: %d\n", a6xx_state->gpu_initialized);
  1521. adreno_show(gpu, state, p);
  1522. drm_puts(p, "gmu-log:\n");
  1523. if (a6xx_state->gmu_log) {
  1524. struct msm_gpu_state_bo *gmu_log = a6xx_state->gmu_log;
  1525. drm_printf(p, " iova: 0x%016llx\n", gmu_log->iova);
  1526. drm_printf(p, " size: %zu\n", gmu_log->size);
  1527. adreno_show_object(p, &gmu_log->data, gmu_log->size,
  1528. &gmu_log->encoded);
  1529. }
  1530. drm_puts(p, "gmu-hfi:\n");
  1531. if (a6xx_state->gmu_hfi) {
  1532. struct msm_gpu_state_bo *gmu_hfi = a6xx_state->gmu_hfi;
  1533. unsigned i, j;
  1534. drm_printf(p, " iova: 0x%016llx\n", gmu_hfi->iova);
  1535. drm_printf(p, " size: %zu\n", gmu_hfi->size);
  1536. for (i = 0; i < ARRAY_SIZE(a6xx_state->hfi_queue_history); i++) {
  1537. drm_printf(p, " queue-history[%u]:", i);
  1538. for (j = 0; j < HFI_HISTORY_SZ; j++) {
  1539. drm_printf(p, " %d", a6xx_state->hfi_queue_history[i][j]);
  1540. }
  1541. drm_printf(p, "\n");
  1542. }
  1543. adreno_show_object(p, &gmu_hfi->data, gmu_hfi->size,
  1544. &gmu_hfi->encoded);
  1545. }
  1546. drm_puts(p, "gmu-debug:\n");
  1547. if (a6xx_state->gmu_debug) {
  1548. struct msm_gpu_state_bo *gmu_debug = a6xx_state->gmu_debug;
  1549. drm_printf(p, " iova: 0x%016llx\n", gmu_debug->iova);
  1550. drm_printf(p, " size: %zu\n", gmu_debug->size);
  1551. adreno_show_object(p, &gmu_debug->data, gmu_debug->size,
  1552. &gmu_debug->encoded);
  1553. }
  1554. drm_puts(p, "registers:\n");
  1555. for (i = 0; i < a6xx_state->nr_registers; i++) {
  1556. struct a6xx_gpu_state_obj *obj = &a6xx_state->registers[i];
  1557. if (!obj->handle)
  1558. continue;
  1559. if (adreno_is_a7xx(adreno_gpu)) {
  1560. a7xx_show_registers(obj->handle, obj->data, p);
  1561. } else {
  1562. const struct a6xx_registers *regs = obj->handle;
  1563. a6xx_show_registers(regs->registers, obj->data, regs->count, p);
  1564. }
  1565. }
  1566. drm_puts(p, "registers-gmu:\n");
  1567. for (i = 0; i < a6xx_state->nr_gmu_registers; i++) {
  1568. struct a6xx_gpu_state_obj *obj = &a6xx_state->gmu_registers[i];
  1569. const struct a6xx_registers *regs = obj->handle;
  1570. if (!obj->handle)
  1571. continue;
  1572. a6xx_show_registers(regs->registers, obj->data, regs->count, p);
  1573. }
  1574. drm_puts(p, "indexed-registers:\n");
  1575. for (i = 0; i < a6xx_state->nr_indexed_regs; i++)
  1576. a6xx_show_indexed_regs(&a6xx_state->indexed_regs[i], p);
  1577. drm_puts(p, "shader-blocks:\n");
  1578. for (i = 0; i < a6xx_state->nr_shaders; i++) {
  1579. if (adreno_is_a7xx(adreno_gpu))
  1580. a7xx_show_shader(&a6xx_state->shaders[i], p);
  1581. else
  1582. a6xx_show_shader(&a6xx_state->shaders[i], p);
  1583. }
  1584. drm_puts(p, "clusters:\n");
  1585. for (i = 0; i < a6xx_state->nr_clusters; i++) {
  1586. if (adreno_is_a7xx(adreno_gpu))
  1587. a7xx_show_cluster(&a6xx_state->clusters[i], p);
  1588. else
  1589. a6xx_show_cluster(&a6xx_state->clusters[i], p);
  1590. }
  1591. for (i = 0; i < a6xx_state->nr_dbgahb_clusters; i++) {
  1592. if (adreno_is_a7xx(adreno_gpu))
  1593. a7xx_show_dbgahb_cluster(&a6xx_state->dbgahb_clusters[i], p);
  1594. else
  1595. a6xx_show_dbgahb_cluster(&a6xx_state->dbgahb_clusters[i], p);
  1596. }
  1597. drm_puts(p, "debugbus:\n");
  1598. a6xx_show_debugbus(a6xx_state, p);
  1599. }