a4xx_gpu.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* Copyright (c) 2014 The Linux Foundation. All rights reserved.
  3. */
  4. #include "a4xx_gpu.h"
  5. #define A4XX_INT0_MASK \
  6. (A4XX_INT0_RBBM_AHB_ERROR | \
  7. A4XX_INT0_RBBM_ATB_BUS_OVERFLOW | \
  8. A4XX_INT0_CP_T0_PACKET_IN_IB | \
  9. A4XX_INT0_CP_OPCODE_ERROR | \
  10. A4XX_INT0_CP_RESERVED_BIT_ERROR | \
  11. A4XX_INT0_CP_HW_FAULT | \
  12. A4XX_INT0_CP_IB1_INT | \
  13. A4XX_INT0_CP_IB2_INT | \
  14. A4XX_INT0_CP_RB_INT | \
  15. A4XX_INT0_CP_REG_PROTECT_FAULT | \
  16. A4XX_INT0_CP_AHB_ERROR_HALT | \
  17. A4XX_INT0_CACHE_FLUSH_TS | \
  18. A4XX_INT0_UCHE_OOB_ACCESS)
  19. extern bool hang_debug;
  20. static void a4xx_dump(struct msm_gpu *gpu);
  21. static bool a4xx_idle(struct msm_gpu *gpu);
  22. static void a4xx_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit)
  23. {
  24. struct msm_ringbuffer *ring = submit->ring;
  25. unsigned int i;
  26. for (i = 0; i < submit->nr_cmds; i++) {
  27. switch (submit->cmd[i].type) {
  28. case MSM_SUBMIT_CMD_IB_TARGET_BUF:
  29. /* ignore IB-targets */
  30. break;
  31. case MSM_SUBMIT_CMD_CTX_RESTORE_BUF:
  32. /* ignore if there has not been a ctx switch: */
  33. if (ring->cur_ctx_seqno == submit->queue->ctx->seqno)
  34. break;
  35. fallthrough;
  36. case MSM_SUBMIT_CMD_BUF:
  37. OUT_PKT3(ring, CP_INDIRECT_BUFFER_PFE, 2);
  38. OUT_RING(ring, lower_32_bits(submit->cmd[i].iova));
  39. OUT_RING(ring, submit->cmd[i].size);
  40. OUT_PKT2(ring);
  41. break;
  42. }
  43. }
  44. OUT_PKT0(ring, REG_AXXX_CP_SCRATCH_REG2, 1);
  45. OUT_RING(ring, submit->seqno);
  46. /* Flush HLSQ lazy updates to make sure there is nothing
  47. * pending for indirect loads after the timestamp has
  48. * passed:
  49. */
  50. OUT_PKT3(ring, CP_EVENT_WRITE, 1);
  51. OUT_RING(ring, HLSQ_FLUSH);
  52. /* wait for idle before cache flush/interrupt */
  53. OUT_PKT3(ring, CP_WAIT_FOR_IDLE, 1);
  54. OUT_RING(ring, 0x00000000);
  55. /* BIT(31) of CACHE_FLUSH_TS triggers CACHE_FLUSH_TS IRQ from GPU */
  56. OUT_PKT3(ring, CP_EVENT_WRITE, 3);
  57. OUT_RING(ring, CACHE_FLUSH_TS | CP_EVENT_WRITE_0_IRQ);
  58. OUT_RING(ring, rbmemptr(ring, fence));
  59. OUT_RING(ring, submit->seqno);
  60. adreno_flush(gpu, ring, REG_A4XX_CP_RB_WPTR);
  61. }
  62. /*
  63. * a4xx_enable_hwcg() - Program the clock control registers
  64. * @device: The adreno device pointer
  65. */
  66. static void a4xx_enable_hwcg(struct msm_gpu *gpu)
  67. {
  68. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  69. unsigned int i;
  70. for (i = 0; i < 4; i++)
  71. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL_TP(i), 0x02222202);
  72. for (i = 0; i < 4; i++)
  73. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL2_TP(i), 0x00002222);
  74. for (i = 0; i < 4; i++)
  75. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_HYST_TP(i), 0x0E739CE7);
  76. for (i = 0; i < 4; i++)
  77. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_DELAY_TP(i), 0x00111111);
  78. for (i = 0; i < 4; i++)
  79. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL_SP(i), 0x22222222);
  80. for (i = 0; i < 4; i++)
  81. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL2_SP(i), 0x00222222);
  82. for (i = 0; i < 4; i++)
  83. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_HYST_SP(i), 0x00000104);
  84. for (i = 0; i < 4; i++)
  85. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_DELAY_SP(i), 0x00000081);
  86. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL_UCHE, 0x22222222);
  87. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL2_UCHE, 0x02222222);
  88. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL3_UCHE, 0x00000000);
  89. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL4_UCHE, 0x00000000);
  90. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_HYST_UCHE, 0x00004444);
  91. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_DELAY_UCHE, 0x00001112);
  92. for (i = 0; i < 4; i++)
  93. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL_RB(i), 0x22222222);
  94. /* Disable L1 clocking in A420 due to CCU issues with it */
  95. for (i = 0; i < 4; i++) {
  96. if (adreno_is_a420(adreno_gpu)) {
  97. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL2_RB(i),
  98. 0x00002020);
  99. } else {
  100. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL2_RB(i),
  101. 0x00022020);
  102. }
  103. }
  104. /* No CCU for A405 */
  105. if (!adreno_is_a405(adreno_gpu)) {
  106. for (i = 0; i < 4; i++) {
  107. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL_MARB_CCU(i),
  108. 0x00000922);
  109. }
  110. for (i = 0; i < 4; i++) {
  111. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_HYST_RB_MARB_CCU(i),
  112. 0x00000000);
  113. }
  114. for (i = 0; i < 4; i++) {
  115. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_DELAY_RB_MARB_CCU_L1(i),
  116. 0x00000001);
  117. }
  118. }
  119. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_MODE_GPC, 0x02222222);
  120. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_HYST_GPC, 0x04100104);
  121. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_DELAY_GPC, 0x00022222);
  122. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL_COM_DCOM, 0x00000022);
  123. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_HYST_COM_DCOM, 0x0000010F);
  124. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_DELAY_COM_DCOM, 0x00000022);
  125. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL_TSE_RAS_RBBM, 0x00222222);
  126. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_HYST_TSE_RAS_RBBM, 0x00004104);
  127. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_DELAY_TSE_RAS_RBBM, 0x00000222);
  128. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL_HLSQ , 0x00000000);
  129. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_HYST_HLSQ, 0x00000000);
  130. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_DELAY_HLSQ, 0x00220000);
  131. /* Early A430's have a timing issue with SP/TP power collapse;
  132. disabling HW clock gating prevents it. */
  133. if (adreno_is_a430(adreno_gpu) && adreno_patchid(adreno_gpu) < 2)
  134. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL, 0);
  135. else
  136. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL, 0xAAAAAAAA);
  137. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL2, 0);
  138. }
  139. static bool a4xx_me_init(struct msm_gpu *gpu)
  140. {
  141. struct msm_ringbuffer *ring = gpu->rb[0];
  142. OUT_PKT3(ring, CP_ME_INIT, 17);
  143. OUT_RING(ring, 0x000003f7);
  144. OUT_RING(ring, 0x00000000);
  145. OUT_RING(ring, 0x00000000);
  146. OUT_RING(ring, 0x00000000);
  147. OUT_RING(ring, 0x00000080);
  148. OUT_RING(ring, 0x00000100);
  149. OUT_RING(ring, 0x00000180);
  150. OUT_RING(ring, 0x00006600);
  151. OUT_RING(ring, 0x00000150);
  152. OUT_RING(ring, 0x0000014e);
  153. OUT_RING(ring, 0x00000154);
  154. OUT_RING(ring, 0x00000001);
  155. OUT_RING(ring, 0x00000000);
  156. OUT_RING(ring, 0x00000000);
  157. OUT_RING(ring, 0x00000000);
  158. OUT_RING(ring, 0x00000000);
  159. OUT_RING(ring, 0x00000000);
  160. adreno_flush(gpu, ring, REG_A4XX_CP_RB_WPTR);
  161. return a4xx_idle(gpu);
  162. }
  163. static int a4xx_hw_init(struct msm_gpu *gpu)
  164. {
  165. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  166. struct a4xx_gpu *a4xx_gpu = to_a4xx_gpu(adreno_gpu);
  167. uint32_t *ptr, len;
  168. int i, ret;
  169. if (adreno_is_a405(adreno_gpu)) {
  170. gpu_write(gpu, REG_A4XX_VBIF_ROUND_ROBIN_QOS_ARB, 0x00000003);
  171. } else if (adreno_is_a420(adreno_gpu)) {
  172. gpu_write(gpu, REG_A4XX_VBIF_ABIT_SORT, 0x0001001F);
  173. gpu_write(gpu, REG_A4XX_VBIF_ABIT_SORT_CONF, 0x000000A4);
  174. gpu_write(gpu, REG_A4XX_VBIF_GATE_OFF_WRREQ_EN, 0x00000001);
  175. gpu_write(gpu, REG_A4XX_VBIF_IN_RD_LIM_CONF0, 0x18181818);
  176. gpu_write(gpu, REG_A4XX_VBIF_IN_RD_LIM_CONF1, 0x00000018);
  177. gpu_write(gpu, REG_A4XX_VBIF_IN_WR_LIM_CONF0, 0x18181818);
  178. gpu_write(gpu, REG_A4XX_VBIF_IN_WR_LIM_CONF1, 0x00000018);
  179. gpu_write(gpu, REG_A4XX_VBIF_ROUND_ROBIN_QOS_ARB, 0x00000003);
  180. } else if (adreno_is_a430(adreno_gpu)) {
  181. gpu_write(gpu, REG_A4XX_VBIF_GATE_OFF_WRREQ_EN, 0x00000001);
  182. gpu_write(gpu, REG_A4XX_VBIF_IN_RD_LIM_CONF0, 0x18181818);
  183. gpu_write(gpu, REG_A4XX_VBIF_IN_RD_LIM_CONF1, 0x00000018);
  184. gpu_write(gpu, REG_A4XX_VBIF_IN_WR_LIM_CONF0, 0x18181818);
  185. gpu_write(gpu, REG_A4XX_VBIF_IN_WR_LIM_CONF1, 0x00000018);
  186. gpu_write(gpu, REG_A4XX_VBIF_ROUND_ROBIN_QOS_ARB, 0x00000003);
  187. } else {
  188. BUG();
  189. }
  190. /* Make all blocks contribute to the GPU BUSY perf counter */
  191. gpu_write(gpu, REG_A4XX_RBBM_GPU_BUSY_MASKED, 0xffffffff);
  192. /* Tune the hystersis counters for SP and CP idle detection */
  193. gpu_write(gpu, REG_A4XX_RBBM_SP_HYST_CNT, 0x10);
  194. gpu_write(gpu, REG_A4XX_RBBM_WAIT_IDLE_CLOCKS_CTL, 0x10);
  195. if (adreno_is_a430(adreno_gpu)) {
  196. gpu_write(gpu, REG_A4XX_RBBM_WAIT_IDLE_CLOCKS_CTL2, 0x30);
  197. }
  198. /* Enable the RBBM error reporting bits */
  199. gpu_write(gpu, REG_A4XX_RBBM_AHB_CTL0, 0x00000001);
  200. /* Enable AHB error reporting*/
  201. gpu_write(gpu, REG_A4XX_RBBM_AHB_CTL1, 0xa6ffffff);
  202. /* Enable power counters*/
  203. gpu_write(gpu, REG_A4XX_RBBM_RBBM_CTL, 0x00000030);
  204. /*
  205. * Turn on hang detection - this spews a lot of useful information
  206. * into the RBBM registers on a hang:
  207. */
  208. gpu_write(gpu, REG_A4XX_RBBM_INTERFACE_HANG_INT_CTL,
  209. (1 << 30) | 0xFFFF);
  210. gpu_write(gpu, REG_A4XX_RB_GMEM_BASE_ADDR,
  211. (unsigned int)(a4xx_gpu->ocmem.base >> 14));
  212. /* Turn on performance counters: */
  213. gpu_write(gpu, REG_A4XX_RBBM_PERFCTR_CTL, 0x01);
  214. /* use the first CP counter for timestamp queries.. userspace may set
  215. * this as well but it selects the same counter/countable:
  216. */
  217. gpu_write(gpu, REG_A4XX_CP_PERFCTR_CP_SEL_0, CP_ALWAYS_COUNT);
  218. if (adreno_is_a430(adreno_gpu))
  219. gpu_write(gpu, REG_A4XX_UCHE_CACHE_WAYS_VFD, 0x07);
  220. /* Disable L2 bypass to avoid UCHE out of bounds errors */
  221. gpu_write(gpu, REG_A4XX_UCHE_TRAP_BASE_LO, lower_32_bits(adreno_gpu->uche_trap_base));
  222. gpu_write(gpu, REG_A4XX_UCHE_TRAP_BASE_HI, upper_32_bits(adreno_gpu->uche_trap_base));
  223. gpu_write(gpu, REG_A4XX_CP_DEBUG, (1 << 25) |
  224. (adreno_is_a420(adreno_gpu) ? (1 << 29) : 0));
  225. /* On A430 enable SP regfile sleep for power savings */
  226. /* TODO downstream does this for !420, so maybe applies for 405 too? */
  227. if (!adreno_is_a420(adreno_gpu)) {
  228. gpu_write(gpu, REG_A4XX_RBBM_SP_REGFILE_SLEEP_CNTL_0,
  229. 0x00000441);
  230. gpu_write(gpu, REG_A4XX_RBBM_SP_REGFILE_SLEEP_CNTL_1,
  231. 0x00000441);
  232. }
  233. a4xx_enable_hwcg(gpu);
  234. /*
  235. * For A420 set RBBM_CLOCK_DELAY_HLSQ.CGC_HLSQ_TP_EARLY_CYC >= 2
  236. * due to timing issue with HLSQ_TP_CLK_EN
  237. */
  238. if (adreno_is_a420(adreno_gpu)) {
  239. unsigned int val;
  240. val = gpu_read(gpu, REG_A4XX_RBBM_CLOCK_DELAY_HLSQ);
  241. val &= ~A4XX_CGC_HLSQ_EARLY_CYC__MASK;
  242. val |= 2 << A4XX_CGC_HLSQ_EARLY_CYC__SHIFT;
  243. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_DELAY_HLSQ, val);
  244. }
  245. /* setup access protection: */
  246. gpu_write(gpu, REG_A4XX_CP_PROTECT_CTRL, 0x00000007);
  247. /* RBBM registers */
  248. gpu_write(gpu, REG_A4XX_CP_PROTECT(0), 0x62000010);
  249. gpu_write(gpu, REG_A4XX_CP_PROTECT(1), 0x63000020);
  250. gpu_write(gpu, REG_A4XX_CP_PROTECT(2), 0x64000040);
  251. gpu_write(gpu, REG_A4XX_CP_PROTECT(3), 0x65000080);
  252. gpu_write(gpu, REG_A4XX_CP_PROTECT(4), 0x66000100);
  253. gpu_write(gpu, REG_A4XX_CP_PROTECT(5), 0x64000200);
  254. /* CP registers */
  255. gpu_write(gpu, REG_A4XX_CP_PROTECT(6), 0x67000800);
  256. gpu_write(gpu, REG_A4XX_CP_PROTECT(7), 0x64001600);
  257. /* RB registers */
  258. gpu_write(gpu, REG_A4XX_CP_PROTECT(8), 0x60003300);
  259. /* HLSQ registers */
  260. gpu_write(gpu, REG_A4XX_CP_PROTECT(9), 0x60003800);
  261. /* VPC registers */
  262. gpu_write(gpu, REG_A4XX_CP_PROTECT(10), 0x61003980);
  263. /* SMMU registers */
  264. gpu_write(gpu, REG_A4XX_CP_PROTECT(11), 0x6e010000);
  265. gpu_write(gpu, REG_A4XX_RBBM_INT_0_MASK, A4XX_INT0_MASK);
  266. ret = adreno_hw_init(gpu);
  267. if (ret)
  268. return ret;
  269. /*
  270. * Use the default ringbuffer size and block size but disable the RPTR
  271. * shadow
  272. */
  273. gpu_write(gpu, REG_A4XX_CP_RB_CNTL,
  274. MSM_GPU_RB_CNTL_DEFAULT | AXXX_CP_RB_CNTL_NO_UPDATE);
  275. /* Set the ringbuffer address */
  276. gpu_write(gpu, REG_A4XX_CP_RB_BASE, lower_32_bits(gpu->rb[0]->iova));
  277. /* Load PM4: */
  278. ptr = (uint32_t *)(adreno_gpu->fw[ADRENO_FW_PM4]->data);
  279. len = adreno_gpu->fw[ADRENO_FW_PM4]->size / 4;
  280. DBG("loading PM4 ucode version: %u", ptr[0]);
  281. gpu_write(gpu, REG_A4XX_CP_ME_RAM_WADDR, 0);
  282. for (i = 1; i < len; i++)
  283. gpu_write(gpu, REG_A4XX_CP_ME_RAM_DATA, ptr[i]);
  284. /* Load PFP: */
  285. ptr = (uint32_t *)(adreno_gpu->fw[ADRENO_FW_PFP]->data);
  286. len = adreno_gpu->fw[ADRENO_FW_PFP]->size / 4;
  287. DBG("loading PFP ucode version: %u", ptr[0]);
  288. gpu_write(gpu, REG_A4XX_CP_PFP_UCODE_ADDR, 0);
  289. for (i = 1; i < len; i++)
  290. gpu_write(gpu, REG_A4XX_CP_PFP_UCODE_DATA, ptr[i]);
  291. /* clear ME_HALT to start micro engine */
  292. gpu_write(gpu, REG_A4XX_CP_ME_CNTL, 0);
  293. return a4xx_me_init(gpu) ? 0 : -EINVAL;
  294. }
  295. static void a4xx_recover(struct msm_gpu *gpu)
  296. {
  297. int i;
  298. adreno_dump_info(gpu);
  299. for (i = 0; i < 8; i++) {
  300. printk("CP_SCRATCH_REG%d: %u\n", i,
  301. gpu_read(gpu, REG_AXXX_CP_SCRATCH_REG0 + i));
  302. }
  303. /* dump registers before resetting gpu, if enabled: */
  304. if (hang_debug)
  305. a4xx_dump(gpu);
  306. gpu_write(gpu, REG_A4XX_RBBM_SW_RESET_CMD, 1);
  307. gpu_read(gpu, REG_A4XX_RBBM_SW_RESET_CMD);
  308. gpu_write(gpu, REG_A4XX_RBBM_SW_RESET_CMD, 0);
  309. adreno_recover(gpu);
  310. }
  311. static void a4xx_destroy(struct msm_gpu *gpu)
  312. {
  313. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  314. struct a4xx_gpu *a4xx_gpu = to_a4xx_gpu(adreno_gpu);
  315. DBG("%s", gpu->name);
  316. adreno_gpu_cleanup(adreno_gpu);
  317. adreno_gpu_ocmem_cleanup(&a4xx_gpu->ocmem);
  318. kfree(a4xx_gpu);
  319. }
  320. static bool a4xx_idle(struct msm_gpu *gpu)
  321. {
  322. /* wait for ringbuffer to drain: */
  323. if (!adreno_idle(gpu, gpu->rb[0]))
  324. return false;
  325. /* then wait for GPU to finish: */
  326. if (spin_until(!(gpu_read(gpu, REG_A4XX_RBBM_STATUS) &
  327. A4XX_RBBM_STATUS_GPU_BUSY))) {
  328. DRM_ERROR("%s: timeout waiting for GPU to idle!\n", gpu->name);
  329. /* TODO maybe we need to reset GPU here to recover from hang? */
  330. return false;
  331. }
  332. return true;
  333. }
  334. static irqreturn_t a4xx_irq(struct msm_gpu *gpu)
  335. {
  336. uint32_t status;
  337. status = gpu_read(gpu, REG_A4XX_RBBM_INT_0_STATUS);
  338. DBG("%s: Int status %08x", gpu->name, status);
  339. if (status & A4XX_INT0_CP_REG_PROTECT_FAULT) {
  340. uint32_t reg = gpu_read(gpu, REG_A4XX_CP_PROTECT_STATUS);
  341. printk("CP | Protected mode error| %s | addr=%x\n",
  342. reg & (1 << 24) ? "WRITE" : "READ",
  343. (reg & 0xFFFFF) >> 2);
  344. }
  345. gpu_write(gpu, REG_A4XX_RBBM_INT_CLEAR_CMD, status);
  346. msm_gpu_retire(gpu);
  347. return IRQ_HANDLED;
  348. }
  349. static const unsigned int a4xx_registers[] = {
  350. /* RBBM */
  351. 0x0000, 0x0002, 0x0004, 0x0021, 0x0023, 0x0024, 0x0026, 0x0026,
  352. 0x0028, 0x002B, 0x002E, 0x0034, 0x0037, 0x0044, 0x0047, 0x0066,
  353. 0x0068, 0x0095, 0x009C, 0x0170, 0x0174, 0x01AF,
  354. /* CP */
  355. 0x0200, 0x0233, 0x0240, 0x0250, 0x04C0, 0x04DD, 0x0500, 0x050B,
  356. 0x0578, 0x058F,
  357. /* VSC */
  358. 0x0C00, 0x0C03, 0x0C08, 0x0C41, 0x0C50, 0x0C51,
  359. /* GRAS */
  360. 0x0C80, 0x0C81, 0x0C88, 0x0C8F,
  361. /* RB */
  362. 0x0CC0, 0x0CC0, 0x0CC4, 0x0CD2,
  363. /* PC */
  364. 0x0D00, 0x0D0C, 0x0D10, 0x0D17, 0x0D20, 0x0D23,
  365. /* VFD */
  366. 0x0E40, 0x0E4A,
  367. /* VPC */
  368. 0x0E60, 0x0E61, 0x0E63, 0x0E68,
  369. /* UCHE */
  370. 0x0E80, 0x0E84, 0x0E88, 0x0E95,
  371. /* VMIDMT */
  372. 0x1000, 0x1000, 0x1002, 0x1002, 0x1004, 0x1004, 0x1008, 0x100A,
  373. 0x100C, 0x100D, 0x100F, 0x1010, 0x1012, 0x1016, 0x1024, 0x1024,
  374. 0x1027, 0x1027, 0x1100, 0x1100, 0x1102, 0x1102, 0x1104, 0x1104,
  375. 0x1110, 0x1110, 0x1112, 0x1116, 0x1124, 0x1124, 0x1300, 0x1300,
  376. 0x1380, 0x1380,
  377. /* GRAS CTX 0 */
  378. 0x2000, 0x2004, 0x2008, 0x2067, 0x2070, 0x2078, 0x207B, 0x216E,
  379. /* PC CTX 0 */
  380. 0x21C0, 0x21C6, 0x21D0, 0x21D0, 0x21D9, 0x21D9, 0x21E5, 0x21E7,
  381. /* VFD CTX 0 */
  382. 0x2200, 0x2204, 0x2208, 0x22A9,
  383. /* GRAS CTX 1 */
  384. 0x2400, 0x2404, 0x2408, 0x2467, 0x2470, 0x2478, 0x247B, 0x256E,
  385. /* PC CTX 1 */
  386. 0x25C0, 0x25C6, 0x25D0, 0x25D0, 0x25D9, 0x25D9, 0x25E5, 0x25E7,
  387. /* VFD CTX 1 */
  388. 0x2600, 0x2604, 0x2608, 0x26A9,
  389. /* XPU */
  390. 0x2C00, 0x2C01, 0x2C10, 0x2C10, 0x2C12, 0x2C16, 0x2C1D, 0x2C20,
  391. 0x2C28, 0x2C28, 0x2C30, 0x2C30, 0x2C32, 0x2C36, 0x2C40, 0x2C40,
  392. 0x2C50, 0x2C50, 0x2C52, 0x2C56, 0x2C80, 0x2C80, 0x2C94, 0x2C95,
  393. /* VBIF */
  394. 0x3000, 0x3007, 0x300C, 0x3014, 0x3018, 0x301D, 0x3020, 0x3022,
  395. 0x3024, 0x3026, 0x3028, 0x302A, 0x302C, 0x302D, 0x3030, 0x3031,
  396. 0x3034, 0x3036, 0x3038, 0x3038, 0x303C, 0x303D, 0x3040, 0x3040,
  397. 0x3049, 0x3049, 0x3058, 0x3058, 0x305B, 0x3061, 0x3064, 0x3068,
  398. 0x306C, 0x306D, 0x3080, 0x3088, 0x308B, 0x308C, 0x3090, 0x3094,
  399. 0x3098, 0x3098, 0x309C, 0x309C, 0x30C0, 0x30C0, 0x30C8, 0x30C8,
  400. 0x30D0, 0x30D0, 0x30D8, 0x30D8, 0x30E0, 0x30E0, 0x3100, 0x3100,
  401. 0x3108, 0x3108, 0x3110, 0x3110, 0x3118, 0x3118, 0x3120, 0x3120,
  402. 0x3124, 0x3125, 0x3129, 0x3129, 0x3131, 0x3131, 0x330C, 0x330C,
  403. 0x3310, 0x3310, 0x3400, 0x3401, 0x3410, 0x3410, 0x3412, 0x3416,
  404. 0x341D, 0x3420, 0x3428, 0x3428, 0x3430, 0x3430, 0x3432, 0x3436,
  405. 0x3440, 0x3440, 0x3450, 0x3450, 0x3452, 0x3456, 0x3480, 0x3480,
  406. 0x3494, 0x3495, 0x4000, 0x4000, 0x4002, 0x4002, 0x4004, 0x4004,
  407. 0x4008, 0x400A, 0x400C, 0x400D, 0x400F, 0x4012, 0x4014, 0x4016,
  408. 0x401D, 0x401D, 0x4020, 0x4027, 0x4060, 0x4062, 0x4200, 0x4200,
  409. 0x4300, 0x4300, 0x4400, 0x4400, 0x4500, 0x4500, 0x4800, 0x4802,
  410. 0x480F, 0x480F, 0x4811, 0x4811, 0x4813, 0x4813, 0x4815, 0x4816,
  411. 0x482B, 0x482B, 0x4857, 0x4857, 0x4883, 0x4883, 0x48AF, 0x48AF,
  412. 0x48C5, 0x48C5, 0x48E5, 0x48E5, 0x4905, 0x4905, 0x4925, 0x4925,
  413. 0x4945, 0x4945, 0x4950, 0x4950, 0x495B, 0x495B, 0x4980, 0x498E,
  414. 0x4B00, 0x4B00, 0x4C00, 0x4C00, 0x4D00, 0x4D00, 0x4E00, 0x4E00,
  415. 0x4E80, 0x4E80, 0x4F00, 0x4F00, 0x4F08, 0x4F08, 0x4F10, 0x4F10,
  416. 0x4F18, 0x4F18, 0x4F20, 0x4F20, 0x4F30, 0x4F30, 0x4F60, 0x4F60,
  417. 0x4F80, 0x4F81, 0x4F88, 0x4F89, 0x4FEE, 0x4FEE, 0x4FF3, 0x4FF3,
  418. 0x6000, 0x6001, 0x6008, 0x600F, 0x6014, 0x6016, 0x6018, 0x601B,
  419. 0x61FD, 0x61FD, 0x623C, 0x623C, 0x6380, 0x6380, 0x63A0, 0x63A0,
  420. 0x63C0, 0x63C1, 0x63C8, 0x63C9, 0x63D0, 0x63D4, 0x63D6, 0x63D6,
  421. 0x63EE, 0x63EE, 0x6400, 0x6401, 0x6408, 0x640F, 0x6414, 0x6416,
  422. 0x6418, 0x641B, 0x65FD, 0x65FD, 0x663C, 0x663C, 0x6780, 0x6780,
  423. 0x67A0, 0x67A0, 0x67C0, 0x67C1, 0x67C8, 0x67C9, 0x67D0, 0x67D4,
  424. 0x67D6, 0x67D6, 0x67EE, 0x67EE, 0x6800, 0x6801, 0x6808, 0x680F,
  425. 0x6814, 0x6816, 0x6818, 0x681B, 0x69FD, 0x69FD, 0x6A3C, 0x6A3C,
  426. 0x6B80, 0x6B80, 0x6BA0, 0x6BA0, 0x6BC0, 0x6BC1, 0x6BC8, 0x6BC9,
  427. 0x6BD0, 0x6BD4, 0x6BD6, 0x6BD6, 0x6BEE, 0x6BEE,
  428. ~0 /* sentinel */
  429. };
  430. static const unsigned int a405_registers[] = {
  431. /* RBBM */
  432. 0x0000, 0x0002, 0x0004, 0x0021, 0x0023, 0x0024, 0x0026, 0x0026,
  433. 0x0028, 0x002B, 0x002E, 0x0034, 0x0037, 0x0044, 0x0047, 0x0066,
  434. 0x0068, 0x0095, 0x009C, 0x0170, 0x0174, 0x01AF,
  435. /* CP */
  436. 0x0200, 0x0233, 0x0240, 0x0250, 0x04C0, 0x04DD, 0x0500, 0x050B,
  437. 0x0578, 0x058F,
  438. /* VSC */
  439. 0x0C00, 0x0C03, 0x0C08, 0x0C41, 0x0C50, 0x0C51,
  440. /* GRAS */
  441. 0x0C80, 0x0C81, 0x0C88, 0x0C8F,
  442. /* RB */
  443. 0x0CC0, 0x0CC0, 0x0CC4, 0x0CD2,
  444. /* PC */
  445. 0x0D00, 0x0D0C, 0x0D10, 0x0D17, 0x0D20, 0x0D23,
  446. /* VFD */
  447. 0x0E40, 0x0E4A,
  448. /* VPC */
  449. 0x0E60, 0x0E61, 0x0E63, 0x0E68,
  450. /* UCHE */
  451. 0x0E80, 0x0E84, 0x0E88, 0x0E95,
  452. /* GRAS CTX 0 */
  453. 0x2000, 0x2004, 0x2008, 0x2067, 0x2070, 0x2078, 0x207B, 0x216E,
  454. /* PC CTX 0 */
  455. 0x21C0, 0x21C6, 0x21D0, 0x21D0, 0x21D9, 0x21D9, 0x21E5, 0x21E7,
  456. /* VFD CTX 0 */
  457. 0x2200, 0x2204, 0x2208, 0x22A9,
  458. /* GRAS CTX 1 */
  459. 0x2400, 0x2404, 0x2408, 0x2467, 0x2470, 0x2478, 0x247B, 0x256E,
  460. /* PC CTX 1 */
  461. 0x25C0, 0x25C6, 0x25D0, 0x25D0, 0x25D9, 0x25D9, 0x25E5, 0x25E7,
  462. /* VFD CTX 1 */
  463. 0x2600, 0x2604, 0x2608, 0x26A9,
  464. /* VBIF version 0x20050000*/
  465. 0x3000, 0x3007, 0x302C, 0x302C, 0x3030, 0x3030, 0x3034, 0x3036,
  466. 0x3038, 0x3038, 0x303C, 0x303D, 0x3040, 0x3040, 0x3049, 0x3049,
  467. 0x3058, 0x3058, 0x305B, 0x3061, 0x3064, 0x3068, 0x306C, 0x306D,
  468. 0x3080, 0x3088, 0x308B, 0x308C, 0x3090, 0x3094, 0x3098, 0x3098,
  469. 0x309C, 0x309C, 0x30C0, 0x30C0, 0x30C8, 0x30C8, 0x30D0, 0x30D0,
  470. 0x30D8, 0x30D8, 0x30E0, 0x30E0, 0x3100, 0x3100, 0x3108, 0x3108,
  471. 0x3110, 0x3110, 0x3118, 0x3118, 0x3120, 0x3120, 0x3124, 0x3125,
  472. 0x3129, 0x3129, 0x340C, 0x340C, 0x3410, 0x3410,
  473. ~0 /* sentinel */
  474. };
  475. static struct msm_gpu_state *a4xx_gpu_state_get(struct msm_gpu *gpu)
  476. {
  477. struct msm_gpu_state *state = kzalloc_obj(*state);
  478. if (!state)
  479. return ERR_PTR(-ENOMEM);
  480. adreno_gpu_state_get(gpu, state);
  481. state->rbbm_status = gpu_read(gpu, REG_A4XX_RBBM_STATUS);
  482. return state;
  483. }
  484. static void a4xx_dump(struct msm_gpu *gpu)
  485. {
  486. printk("status: %08x\n",
  487. gpu_read(gpu, REG_A4XX_RBBM_STATUS));
  488. adreno_dump(gpu);
  489. }
  490. static int a4xx_pm_resume(struct msm_gpu *gpu) {
  491. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  492. int ret;
  493. ret = msm_gpu_pm_resume(gpu);
  494. if (ret)
  495. return ret;
  496. if (adreno_is_a430(adreno_gpu)) {
  497. unsigned int reg;
  498. /* Set the default register values; set SW_COLLAPSE to 0 */
  499. gpu_write(gpu, REG_A4XX_RBBM_POWER_CNTL_IP, 0x778000);
  500. do {
  501. udelay(5);
  502. reg = gpu_read(gpu, REG_A4XX_RBBM_POWER_STATUS);
  503. } while (!(reg & A4XX_RBBM_POWER_CNTL_IP_SP_TP_PWR_ON));
  504. }
  505. return 0;
  506. }
  507. static int a4xx_pm_suspend(struct msm_gpu *gpu) {
  508. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  509. int ret;
  510. ret = msm_gpu_pm_suspend(gpu);
  511. if (ret)
  512. return ret;
  513. if (adreno_is_a430(adreno_gpu)) {
  514. /* Set the default register values; set SW_COLLAPSE to 1 */
  515. gpu_write(gpu, REG_A4XX_RBBM_POWER_CNTL_IP, 0x778001);
  516. }
  517. return 0;
  518. }
  519. static int a4xx_get_timestamp(struct msm_gpu *gpu, uint64_t *value)
  520. {
  521. *value = gpu_read64(gpu, REG_A4XX_RBBM_PERFCTR_CP_0_LO);
  522. return 0;
  523. }
  524. static u64 a4xx_gpu_busy(struct msm_gpu *gpu, unsigned long *out_sample_rate)
  525. {
  526. u64 busy_cycles;
  527. busy_cycles = gpu_read64(gpu, REG_A4XX_RBBM_PERFCTR_RBBM_1_LO);
  528. *out_sample_rate = clk_get_rate(gpu->core_clk);
  529. return busy_cycles;
  530. }
  531. static u32 a4xx_get_rptr(struct msm_gpu *gpu, struct msm_ringbuffer *ring)
  532. {
  533. ring->memptrs->rptr = gpu_read(gpu, REG_A4XX_CP_RB_RPTR);
  534. return ring->memptrs->rptr;
  535. }
  536. static struct msm_gpu *a4xx_gpu_init(struct drm_device *dev)
  537. {
  538. struct a4xx_gpu *a4xx_gpu = NULL;
  539. struct adreno_gpu *adreno_gpu;
  540. struct msm_gpu *gpu;
  541. struct msm_drm_private *priv = dev->dev_private;
  542. struct platform_device *pdev = priv->gpu_pdev;
  543. struct adreno_platform_config *config = pdev->dev.platform_data;
  544. struct icc_path *ocmem_icc_path;
  545. struct icc_path *icc_path;
  546. int ret;
  547. if (!pdev) {
  548. DRM_DEV_ERROR(dev->dev, "no a4xx device\n");
  549. ret = -ENXIO;
  550. goto fail;
  551. }
  552. a4xx_gpu = kzalloc_obj(*a4xx_gpu);
  553. if (!a4xx_gpu) {
  554. ret = -ENOMEM;
  555. goto fail;
  556. }
  557. adreno_gpu = &a4xx_gpu->base;
  558. gpu = &adreno_gpu->base;
  559. gpu->perfcntrs = NULL;
  560. gpu->num_perfcntrs = 0;
  561. ret = adreno_gpu_init(dev, pdev, adreno_gpu, config->info->funcs, 1);
  562. if (ret)
  563. goto fail;
  564. adreno_gpu->registers = adreno_is_a405(adreno_gpu) ? a405_registers :
  565. a4xx_registers;
  566. /* if needed, allocate gmem: */
  567. ret = adreno_gpu_ocmem_init(dev->dev, adreno_gpu,
  568. &a4xx_gpu->ocmem);
  569. if (ret)
  570. goto fail;
  571. adreno_gpu->uche_trap_base = 0xffff0000ffff0000ull;
  572. icc_path = devm_of_icc_get(&pdev->dev, "gfx-mem");
  573. if (IS_ERR(icc_path)) {
  574. ret = PTR_ERR(icc_path);
  575. goto fail;
  576. }
  577. ocmem_icc_path = devm_of_icc_get(&pdev->dev, "ocmem");
  578. if (IS_ERR(ocmem_icc_path)) {
  579. ret = PTR_ERR(ocmem_icc_path);
  580. /* allow -ENODATA, ocmem icc is optional */
  581. if (ret != -ENODATA)
  582. goto fail;
  583. ocmem_icc_path = NULL;
  584. }
  585. /*
  586. * Set the ICC path to maximum speed for now by multiplying the fastest
  587. * frequency by the bus width (8). We'll want to scale this later on to
  588. * improve battery life.
  589. */
  590. icc_set_bw(icc_path, 0, Bps_to_icc(gpu->fast_rate) * 8);
  591. icc_set_bw(ocmem_icc_path, 0, Bps_to_icc(gpu->fast_rate) * 8);
  592. return gpu;
  593. fail:
  594. if (a4xx_gpu)
  595. a4xx_destroy(&a4xx_gpu->base.base);
  596. return ERR_PTR(ret);
  597. }
  598. const struct adreno_gpu_funcs a4xx_gpu_funcs = {
  599. .base = {
  600. .get_param = adreno_get_param,
  601. .set_param = adreno_set_param,
  602. .hw_init = a4xx_hw_init,
  603. .pm_suspend = a4xx_pm_suspend,
  604. .pm_resume = a4xx_pm_resume,
  605. .recover = a4xx_recover,
  606. .submit = a4xx_submit,
  607. .active_ring = adreno_active_ring,
  608. .irq = a4xx_irq,
  609. .destroy = a4xx_destroy,
  610. #if defined(CONFIG_DEBUG_FS) || defined(CONFIG_DEV_COREDUMP)
  611. .show = adreno_show,
  612. #endif
  613. .gpu_busy = a4xx_gpu_busy,
  614. .gpu_state_get = a4xx_gpu_state_get,
  615. .gpu_state_put = adreno_gpu_state_put,
  616. .create_vm = adreno_create_vm,
  617. .get_rptr = a4xx_get_rptr,
  618. },
  619. .init = a4xx_gpu_init,
  620. .get_timestamp = a4xx_get_timestamp,
  621. };