a6xx_gpu_state.c 55 KB

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