a6xx_gpu.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright (c) 2017-2018 The Linux Foundation. All rights reserved. */
  3. #include "msm_gem.h"
  4. #include "msm_mmu.h"
  5. #include "a6xx_gpu.h"
  6. #include "a6xx_gmu.xml.h"
  7. #include <linux/devfreq.h>
  8. static inline bool _a6xx_check_idle(struct msm_gpu *gpu)
  9. {
  10. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  11. struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
  12. /* Check that the GMU is idle */
  13. if (!a6xx_gmu_isidle(&a6xx_gpu->gmu))
  14. return false;
  15. /* Check tha the CX master is idle */
  16. if (gpu_read(gpu, REG_A6XX_RBBM_STATUS) &
  17. ~A6XX_RBBM_STATUS_CP_AHB_BUSY_CX_MASTER)
  18. return false;
  19. return !(gpu_read(gpu, REG_A6XX_RBBM_INT_0_STATUS) &
  20. A6XX_RBBM_INT_0_MASK_RBBM_HANG_DETECT);
  21. }
  22. bool a6xx_idle(struct msm_gpu *gpu, struct msm_ringbuffer *ring)
  23. {
  24. /* wait for CP to drain ringbuffer: */
  25. if (!adreno_idle(gpu, ring))
  26. return false;
  27. if (spin_until(_a6xx_check_idle(gpu))) {
  28. DRM_ERROR("%s: %ps: timeout waiting for GPU to idle: status %8.8X irq %8.8X rptr/wptr %d/%d\n",
  29. gpu->name, __builtin_return_address(0),
  30. gpu_read(gpu, REG_A6XX_RBBM_STATUS),
  31. gpu_read(gpu, REG_A6XX_RBBM_INT_0_STATUS),
  32. gpu_read(gpu, REG_A6XX_CP_RB_RPTR),
  33. gpu_read(gpu, REG_A6XX_CP_RB_WPTR));
  34. return false;
  35. }
  36. return true;
  37. }
  38. static void a6xx_flush(struct msm_gpu *gpu, struct msm_ringbuffer *ring)
  39. {
  40. uint32_t wptr;
  41. unsigned long flags;
  42. spin_lock_irqsave(&ring->lock, flags);
  43. /* Copy the shadow to the actual register */
  44. ring->cur = ring->next;
  45. /* Make sure to wrap wptr if we need to */
  46. wptr = get_wptr(ring);
  47. spin_unlock_irqrestore(&ring->lock, flags);
  48. /* Make sure everything is posted before making a decision */
  49. mb();
  50. gpu_write(gpu, REG_A6XX_CP_RB_WPTR, wptr);
  51. }
  52. static void a6xx_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit,
  53. struct msm_file_private *ctx)
  54. {
  55. struct msm_drm_private *priv = gpu->dev->dev_private;
  56. struct msm_ringbuffer *ring = submit->ring;
  57. unsigned int i;
  58. /* Invalidate CCU depth and color */
  59. OUT_PKT7(ring, CP_EVENT_WRITE, 1);
  60. OUT_RING(ring, PC_CCU_INVALIDATE_DEPTH);
  61. OUT_PKT7(ring, CP_EVENT_WRITE, 1);
  62. OUT_RING(ring, PC_CCU_INVALIDATE_COLOR);
  63. /* Submit the commands */
  64. for (i = 0; i < submit->nr_cmds; i++) {
  65. switch (submit->cmd[i].type) {
  66. case MSM_SUBMIT_CMD_IB_TARGET_BUF:
  67. break;
  68. case MSM_SUBMIT_CMD_CTX_RESTORE_BUF:
  69. if (priv->lastctx == ctx)
  70. break;
  71. case MSM_SUBMIT_CMD_BUF:
  72. OUT_PKT7(ring, CP_INDIRECT_BUFFER_PFE, 3);
  73. OUT_RING(ring, lower_32_bits(submit->cmd[i].iova));
  74. OUT_RING(ring, upper_32_bits(submit->cmd[i].iova));
  75. OUT_RING(ring, submit->cmd[i].size);
  76. break;
  77. }
  78. }
  79. /* Write the fence to the scratch register */
  80. OUT_PKT4(ring, REG_A6XX_CP_SCRATCH_REG(2), 1);
  81. OUT_RING(ring, submit->seqno);
  82. /*
  83. * Execute a CACHE_FLUSH_TS event. This will ensure that the
  84. * timestamp is written to the memory and then triggers the interrupt
  85. */
  86. OUT_PKT7(ring, CP_EVENT_WRITE, 4);
  87. OUT_RING(ring, CACHE_FLUSH_TS | (1 << 31));
  88. OUT_RING(ring, lower_32_bits(rbmemptr(ring, fence)));
  89. OUT_RING(ring, upper_32_bits(rbmemptr(ring, fence)));
  90. OUT_RING(ring, submit->seqno);
  91. a6xx_flush(gpu, ring);
  92. }
  93. static const struct {
  94. u32 offset;
  95. u32 value;
  96. } a6xx_hwcg[] = {
  97. {REG_A6XX_RBBM_CLOCK_CNTL_SP0, 0x22222222},
  98. {REG_A6XX_RBBM_CLOCK_CNTL_SP1, 0x22222222},
  99. {REG_A6XX_RBBM_CLOCK_CNTL_SP2, 0x22222222},
  100. {REG_A6XX_RBBM_CLOCK_CNTL_SP3, 0x22222222},
  101. {REG_A6XX_RBBM_CLOCK_CNTL2_SP0, 0x02022220},
  102. {REG_A6XX_RBBM_CLOCK_CNTL2_SP1, 0x02022220},
  103. {REG_A6XX_RBBM_CLOCK_CNTL2_SP2, 0x02022220},
  104. {REG_A6XX_RBBM_CLOCK_CNTL2_SP3, 0x02022220},
  105. {REG_A6XX_RBBM_CLOCK_DELAY_SP0, 0x00000080},
  106. {REG_A6XX_RBBM_CLOCK_DELAY_SP1, 0x00000080},
  107. {REG_A6XX_RBBM_CLOCK_DELAY_SP2, 0x00000080},
  108. {REG_A6XX_RBBM_CLOCK_DELAY_SP3, 0x00000080},
  109. {REG_A6XX_RBBM_CLOCK_HYST_SP0, 0x0000f3cf},
  110. {REG_A6XX_RBBM_CLOCK_HYST_SP1, 0x0000f3cf},
  111. {REG_A6XX_RBBM_CLOCK_HYST_SP2, 0x0000f3cf},
  112. {REG_A6XX_RBBM_CLOCK_HYST_SP3, 0x0000f3cf},
  113. {REG_A6XX_RBBM_CLOCK_CNTL_TP0, 0x02222222},
  114. {REG_A6XX_RBBM_CLOCK_CNTL_TP1, 0x02222222},
  115. {REG_A6XX_RBBM_CLOCK_CNTL_TP2, 0x02222222},
  116. {REG_A6XX_RBBM_CLOCK_CNTL_TP3, 0x02222222},
  117. {REG_A6XX_RBBM_CLOCK_CNTL2_TP0, 0x22222222},
  118. {REG_A6XX_RBBM_CLOCK_CNTL2_TP1, 0x22222222},
  119. {REG_A6XX_RBBM_CLOCK_CNTL2_TP2, 0x22222222},
  120. {REG_A6XX_RBBM_CLOCK_CNTL2_TP3, 0x22222222},
  121. {REG_A6XX_RBBM_CLOCK_CNTL3_TP0, 0x22222222},
  122. {REG_A6XX_RBBM_CLOCK_CNTL3_TP1, 0x22222222},
  123. {REG_A6XX_RBBM_CLOCK_CNTL3_TP2, 0x22222222},
  124. {REG_A6XX_RBBM_CLOCK_CNTL3_TP3, 0x22222222},
  125. {REG_A6XX_RBBM_CLOCK_CNTL4_TP0, 0x00022222},
  126. {REG_A6XX_RBBM_CLOCK_CNTL4_TP1, 0x00022222},
  127. {REG_A6XX_RBBM_CLOCK_CNTL4_TP2, 0x00022222},
  128. {REG_A6XX_RBBM_CLOCK_CNTL4_TP3, 0x00022222},
  129. {REG_A6XX_RBBM_CLOCK_HYST_TP0, 0x77777777},
  130. {REG_A6XX_RBBM_CLOCK_HYST_TP1, 0x77777777},
  131. {REG_A6XX_RBBM_CLOCK_HYST_TP2, 0x77777777},
  132. {REG_A6XX_RBBM_CLOCK_HYST_TP3, 0x77777777},
  133. {REG_A6XX_RBBM_CLOCK_HYST2_TP0, 0x77777777},
  134. {REG_A6XX_RBBM_CLOCK_HYST2_TP1, 0x77777777},
  135. {REG_A6XX_RBBM_CLOCK_HYST2_TP2, 0x77777777},
  136. {REG_A6XX_RBBM_CLOCK_HYST2_TP3, 0x77777777},
  137. {REG_A6XX_RBBM_CLOCK_HYST3_TP0, 0x77777777},
  138. {REG_A6XX_RBBM_CLOCK_HYST3_TP1, 0x77777777},
  139. {REG_A6XX_RBBM_CLOCK_HYST3_TP2, 0x77777777},
  140. {REG_A6XX_RBBM_CLOCK_HYST3_TP3, 0x77777777},
  141. {REG_A6XX_RBBM_CLOCK_HYST4_TP0, 0x00077777},
  142. {REG_A6XX_RBBM_CLOCK_HYST4_TP1, 0x00077777},
  143. {REG_A6XX_RBBM_CLOCK_HYST4_TP2, 0x00077777},
  144. {REG_A6XX_RBBM_CLOCK_HYST4_TP3, 0x00077777},
  145. {REG_A6XX_RBBM_CLOCK_DELAY_TP0, 0x11111111},
  146. {REG_A6XX_RBBM_CLOCK_DELAY_TP1, 0x11111111},
  147. {REG_A6XX_RBBM_CLOCK_DELAY_TP2, 0x11111111},
  148. {REG_A6XX_RBBM_CLOCK_DELAY_TP3, 0x11111111},
  149. {REG_A6XX_RBBM_CLOCK_DELAY2_TP0, 0x11111111},
  150. {REG_A6XX_RBBM_CLOCK_DELAY2_TP1, 0x11111111},
  151. {REG_A6XX_RBBM_CLOCK_DELAY2_TP2, 0x11111111},
  152. {REG_A6XX_RBBM_CLOCK_DELAY2_TP3, 0x11111111},
  153. {REG_A6XX_RBBM_CLOCK_DELAY3_TP0, 0x11111111},
  154. {REG_A6XX_RBBM_CLOCK_DELAY3_TP1, 0x11111111},
  155. {REG_A6XX_RBBM_CLOCK_DELAY3_TP2, 0x11111111},
  156. {REG_A6XX_RBBM_CLOCK_DELAY3_TP3, 0x11111111},
  157. {REG_A6XX_RBBM_CLOCK_DELAY4_TP0, 0x00011111},
  158. {REG_A6XX_RBBM_CLOCK_DELAY4_TP1, 0x00011111},
  159. {REG_A6XX_RBBM_CLOCK_DELAY4_TP2, 0x00011111},
  160. {REG_A6XX_RBBM_CLOCK_DELAY4_TP3, 0x00011111},
  161. {REG_A6XX_RBBM_CLOCK_CNTL_UCHE, 0x22222222},
  162. {REG_A6XX_RBBM_CLOCK_CNTL2_UCHE, 0x22222222},
  163. {REG_A6XX_RBBM_CLOCK_CNTL3_UCHE, 0x22222222},
  164. {REG_A6XX_RBBM_CLOCK_CNTL4_UCHE, 0x00222222},
  165. {REG_A6XX_RBBM_CLOCK_HYST_UCHE, 0x00000004},
  166. {REG_A6XX_RBBM_CLOCK_DELAY_UCHE, 0x00000002},
  167. {REG_A6XX_RBBM_CLOCK_CNTL_RB0, 0x22222222},
  168. {REG_A6XX_RBBM_CLOCK_CNTL_RB1, 0x22222222},
  169. {REG_A6XX_RBBM_CLOCK_CNTL_RB2, 0x22222222},
  170. {REG_A6XX_RBBM_CLOCK_CNTL_RB3, 0x22222222},
  171. {REG_A6XX_RBBM_CLOCK_CNTL2_RB0, 0x00002222},
  172. {REG_A6XX_RBBM_CLOCK_CNTL2_RB1, 0x00002222},
  173. {REG_A6XX_RBBM_CLOCK_CNTL2_RB2, 0x00002222},
  174. {REG_A6XX_RBBM_CLOCK_CNTL2_RB3, 0x00002222},
  175. {REG_A6XX_RBBM_CLOCK_CNTL_CCU0, 0x00002220},
  176. {REG_A6XX_RBBM_CLOCK_CNTL_CCU1, 0x00002220},
  177. {REG_A6XX_RBBM_CLOCK_CNTL_CCU2, 0x00002220},
  178. {REG_A6XX_RBBM_CLOCK_CNTL_CCU3, 0x00002220},
  179. {REG_A6XX_RBBM_CLOCK_HYST_RB_CCU0, 0x00040f00},
  180. {REG_A6XX_RBBM_CLOCK_HYST_RB_CCU1, 0x00040f00},
  181. {REG_A6XX_RBBM_CLOCK_HYST_RB_CCU2, 0x00040f00},
  182. {REG_A6XX_RBBM_CLOCK_HYST_RB_CCU3, 0x00040f00},
  183. {REG_A6XX_RBBM_CLOCK_CNTL_RAC, 0x05022022},
  184. {REG_A6XX_RBBM_CLOCK_CNTL2_RAC, 0x00005555},
  185. {REG_A6XX_RBBM_CLOCK_DELAY_RAC, 0x00000011},
  186. {REG_A6XX_RBBM_CLOCK_HYST_RAC, 0x00445044},
  187. {REG_A6XX_RBBM_CLOCK_CNTL_TSE_RAS_RBBM, 0x04222222},
  188. {REG_A6XX_RBBM_CLOCK_MODE_GPC, 0x00222222},
  189. {REG_A6XX_RBBM_CLOCK_MODE_VFD, 0x00002222},
  190. {REG_A6XX_RBBM_CLOCK_HYST_TSE_RAS_RBBM, 0x00000000},
  191. {REG_A6XX_RBBM_CLOCK_HYST_GPC, 0x04104004},
  192. {REG_A6XX_RBBM_CLOCK_HYST_VFD, 0x00000000},
  193. {REG_A6XX_RBBM_CLOCK_DELAY_HLSQ, 0x00000000},
  194. {REG_A6XX_RBBM_CLOCK_DELAY_TSE_RAS_RBBM, 0x00004000},
  195. {REG_A6XX_RBBM_CLOCK_DELAY_GPC, 0x00000200},
  196. {REG_A6XX_RBBM_CLOCK_DELAY_VFD, 0x00002222},
  197. {REG_A6XX_RBBM_CLOCK_DELAY_HLSQ_2, 0x00000002},
  198. {REG_A6XX_RBBM_CLOCK_MODE_HLSQ, 0x00002222},
  199. {REG_A6XX_RBBM_CLOCK_CNTL_GMU_GX, 0x00000222},
  200. {REG_A6XX_RBBM_CLOCK_DELAY_GMU_GX, 0x00000111},
  201. {REG_A6XX_RBBM_CLOCK_HYST_GMU_GX, 0x00000555}
  202. };
  203. static void a6xx_set_hwcg(struct msm_gpu *gpu, bool state)
  204. {
  205. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  206. struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
  207. struct a6xx_gmu *gmu = &a6xx_gpu->gmu;
  208. unsigned int i;
  209. u32 val;
  210. val = gpu_read(gpu, REG_A6XX_RBBM_CLOCK_CNTL);
  211. /* Don't re-program the registers if they are already correct */
  212. if ((!state && !val) || (state && (val == 0x8aa8aa02)))
  213. return;
  214. /* Disable SP clock before programming HWCG registers */
  215. gmu_rmw(gmu, REG_A6XX_GPU_GMU_GX_SPTPRAC_CLOCK_CONTROL, 1, 0);
  216. for (i = 0; i < ARRAY_SIZE(a6xx_hwcg); i++)
  217. gpu_write(gpu, a6xx_hwcg[i].offset,
  218. state ? a6xx_hwcg[i].value : 0);
  219. /* Enable SP clock */
  220. gmu_rmw(gmu, REG_A6XX_GPU_GMU_GX_SPTPRAC_CLOCK_CONTROL, 0, 1);
  221. gpu_write(gpu, REG_A6XX_RBBM_CLOCK_CNTL, state ? 0x8aa8aa02 : 0);
  222. }
  223. static int a6xx_cp_init(struct msm_gpu *gpu)
  224. {
  225. struct msm_ringbuffer *ring = gpu->rb[0];
  226. OUT_PKT7(ring, CP_ME_INIT, 8);
  227. OUT_RING(ring, 0x0000002f);
  228. /* Enable multiple hardware contexts */
  229. OUT_RING(ring, 0x00000003);
  230. /* Enable error detection */
  231. OUT_RING(ring, 0x20000000);
  232. /* Don't enable header dump */
  233. OUT_RING(ring, 0x00000000);
  234. OUT_RING(ring, 0x00000000);
  235. /* No workarounds enabled */
  236. OUT_RING(ring, 0x00000000);
  237. /* Pad rest of the cmds with 0's */
  238. OUT_RING(ring, 0x00000000);
  239. OUT_RING(ring, 0x00000000);
  240. a6xx_flush(gpu, ring);
  241. return a6xx_idle(gpu, ring) ? 0 : -EINVAL;
  242. }
  243. static int a6xx_ucode_init(struct msm_gpu *gpu)
  244. {
  245. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  246. struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
  247. if (!a6xx_gpu->sqe_bo) {
  248. a6xx_gpu->sqe_bo = adreno_fw_create_bo(gpu,
  249. adreno_gpu->fw[ADRENO_FW_SQE], &a6xx_gpu->sqe_iova);
  250. if (IS_ERR(a6xx_gpu->sqe_bo)) {
  251. int ret = PTR_ERR(a6xx_gpu->sqe_bo);
  252. a6xx_gpu->sqe_bo = NULL;
  253. DRM_DEV_ERROR(&gpu->pdev->dev,
  254. "Could not allocate SQE ucode: %d\n", ret);
  255. return ret;
  256. }
  257. }
  258. gpu_write64(gpu, REG_A6XX_CP_SQE_INSTR_BASE_LO,
  259. REG_A6XX_CP_SQE_INSTR_BASE_HI, a6xx_gpu->sqe_iova);
  260. return 0;
  261. }
  262. #define A6XX_INT_MASK (A6XX_RBBM_INT_0_MASK_CP_AHB_ERROR | \
  263. A6XX_RBBM_INT_0_MASK_RBBM_ATB_ASYNCFIFO_OVERFLOW | \
  264. A6XX_RBBM_INT_0_MASK_CP_HW_ERROR | \
  265. A6XX_RBBM_INT_0_MASK_CP_IB2 | \
  266. A6XX_RBBM_INT_0_MASK_CP_IB1 | \
  267. A6XX_RBBM_INT_0_MASK_CP_RB | \
  268. A6XX_RBBM_INT_0_MASK_CP_CACHE_FLUSH_TS | \
  269. A6XX_RBBM_INT_0_MASK_RBBM_ATB_BUS_OVERFLOW | \
  270. A6XX_RBBM_INT_0_MASK_RBBM_HANG_DETECT | \
  271. A6XX_RBBM_INT_0_MASK_UCHE_OOB_ACCESS | \
  272. A6XX_RBBM_INT_0_MASK_UCHE_TRAP_INTR)
  273. static int a6xx_hw_init(struct msm_gpu *gpu)
  274. {
  275. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  276. struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
  277. int ret;
  278. /* Make sure the GMU keeps the GPU on while we set it up */
  279. a6xx_gmu_set_oob(&a6xx_gpu->gmu, GMU_OOB_GPU_SET);
  280. gpu_write(gpu, REG_A6XX_RBBM_SECVID_TSB_CNTL, 0);
  281. /*
  282. * Disable the trusted memory range - we don't actually supported secure
  283. * memory rendering at this point in time and we don't want to block off
  284. * part of the virtual memory space.
  285. */
  286. gpu_write64(gpu, REG_A6XX_RBBM_SECVID_TSB_TRUSTED_BASE_LO,
  287. REG_A6XX_RBBM_SECVID_TSB_TRUSTED_BASE_HI, 0x00000000);
  288. gpu_write(gpu, REG_A6XX_RBBM_SECVID_TSB_TRUSTED_SIZE, 0x00000000);
  289. /* enable hardware clockgating */
  290. a6xx_set_hwcg(gpu, true);
  291. /* VBIF start */
  292. gpu_write(gpu, REG_A6XX_VBIF_GATE_OFF_WRREQ_EN, 0x00000009);
  293. gpu_write(gpu, REG_A6XX_RBBM_VBIF_CLIENT_QOS_CNTL, 0x3);
  294. /* Make all blocks contribute to the GPU BUSY perf counter */
  295. gpu_write(gpu, REG_A6XX_RBBM_PERFCTR_GPU_BUSY_MASKED, 0xffffffff);
  296. /* Disable L2 bypass in the UCHE */
  297. gpu_write(gpu, REG_A6XX_UCHE_WRITE_RANGE_MAX_LO, 0xffffffc0);
  298. gpu_write(gpu, REG_A6XX_UCHE_WRITE_RANGE_MAX_HI, 0x0001ffff);
  299. gpu_write(gpu, REG_A6XX_UCHE_TRAP_BASE_LO, 0xfffff000);
  300. gpu_write(gpu, REG_A6XX_UCHE_TRAP_BASE_HI, 0x0001ffff);
  301. gpu_write(gpu, REG_A6XX_UCHE_WRITE_THRU_BASE_LO, 0xfffff000);
  302. gpu_write(gpu, REG_A6XX_UCHE_WRITE_THRU_BASE_HI, 0x0001ffff);
  303. /* Set the GMEM VA range [0x100000:0x100000 + gpu->gmem - 1] */
  304. gpu_write64(gpu, REG_A6XX_UCHE_GMEM_RANGE_MIN_LO,
  305. REG_A6XX_UCHE_GMEM_RANGE_MIN_HI, 0x00100000);
  306. gpu_write64(gpu, REG_A6XX_UCHE_GMEM_RANGE_MAX_LO,
  307. REG_A6XX_UCHE_GMEM_RANGE_MAX_HI,
  308. 0x00100000 + adreno_gpu->gmem - 1);
  309. gpu_write(gpu, REG_A6XX_UCHE_FILTER_CNTL, 0x804);
  310. gpu_write(gpu, REG_A6XX_UCHE_CACHE_WAYS, 0x4);
  311. gpu_write(gpu, REG_A6XX_CP_ROQ_THRESHOLDS_2, 0x010000c0);
  312. gpu_write(gpu, REG_A6XX_CP_ROQ_THRESHOLDS_1, 0x8040362c);
  313. /* Setting the mem pool size */
  314. gpu_write(gpu, REG_A6XX_CP_MEM_POOL_SIZE, 128);
  315. /* Setting the primFifo thresholds default values */
  316. gpu_write(gpu, REG_A6XX_PC_DBG_ECO_CNTL, (0x300 << 11));
  317. /* Set the AHB default slave response to "ERROR" */
  318. gpu_write(gpu, REG_A6XX_CP_AHB_CNTL, 0x1);
  319. /* Turn on performance counters */
  320. gpu_write(gpu, REG_A6XX_RBBM_PERFCTR_CNTL, 0x1);
  321. /* Select CP0 to always count cycles */
  322. gpu_write(gpu, REG_A6XX_CP_PERFCTR_CP_SEL_0, PERF_CP_ALWAYS_COUNT);
  323. /* FIXME: not sure if this should live here or in a6xx_gmu.c */
  324. gmu_write(&a6xx_gpu->gmu, REG_A6XX_GPU_GMU_AO_GPU_CX_BUSY_MASK,
  325. 0xff000000);
  326. gmu_rmw(&a6xx_gpu->gmu, REG_A6XX_GMU_CX_GMU_POWER_COUNTER_SELECT_0,
  327. 0xff, 0x20);
  328. gmu_write(&a6xx_gpu->gmu, REG_A6XX_GMU_CX_GMU_POWER_COUNTER_ENABLE,
  329. 0x01);
  330. gpu_write(gpu, REG_A6XX_RB_NC_MODE_CNTL, 2 << 1);
  331. gpu_write(gpu, REG_A6XX_TPL1_NC_MODE_CNTL, 2 << 1);
  332. gpu_write(gpu, REG_A6XX_SP_NC_MODE_CNTL, 2 << 1);
  333. gpu_write(gpu, REG_A6XX_UCHE_MODE_CNTL, 2 << 21);
  334. /* Enable fault detection */
  335. gpu_write(gpu, REG_A6XX_RBBM_INTERFACE_HANG_INT_CNTL,
  336. (1 << 30) | 0x1fffff);
  337. gpu_write(gpu, REG_A6XX_UCHE_CLIENT_PF, 1);
  338. /* Protect registers from the CP */
  339. gpu_write(gpu, REG_A6XX_CP_PROTECT_CNTL, 0x00000003);
  340. gpu_write(gpu, REG_A6XX_CP_PROTECT(0),
  341. A6XX_PROTECT_RDONLY(0x600, 0x51));
  342. gpu_write(gpu, REG_A6XX_CP_PROTECT(1), A6XX_PROTECT_RW(0xae50, 0x2));
  343. gpu_write(gpu, REG_A6XX_CP_PROTECT(2), A6XX_PROTECT_RW(0x9624, 0x13));
  344. gpu_write(gpu, REG_A6XX_CP_PROTECT(3), A6XX_PROTECT_RW(0x8630, 0x8));
  345. gpu_write(gpu, REG_A6XX_CP_PROTECT(4), A6XX_PROTECT_RW(0x9e70, 0x1));
  346. gpu_write(gpu, REG_A6XX_CP_PROTECT(5), A6XX_PROTECT_RW(0x9e78, 0x187));
  347. gpu_write(gpu, REG_A6XX_CP_PROTECT(6), A6XX_PROTECT_RW(0xf000, 0x810));
  348. gpu_write(gpu, REG_A6XX_CP_PROTECT(7),
  349. A6XX_PROTECT_RDONLY(0xfc00, 0x3));
  350. gpu_write(gpu, REG_A6XX_CP_PROTECT(8), A6XX_PROTECT_RW(0x50e, 0x0));
  351. gpu_write(gpu, REG_A6XX_CP_PROTECT(9), A6XX_PROTECT_RDONLY(0x50f, 0x0));
  352. gpu_write(gpu, REG_A6XX_CP_PROTECT(10), A6XX_PROTECT_RW(0x510, 0x0));
  353. gpu_write(gpu, REG_A6XX_CP_PROTECT(11),
  354. A6XX_PROTECT_RDONLY(0x0, 0x4f9));
  355. gpu_write(gpu, REG_A6XX_CP_PROTECT(12),
  356. A6XX_PROTECT_RDONLY(0x501, 0xa));
  357. gpu_write(gpu, REG_A6XX_CP_PROTECT(13),
  358. A6XX_PROTECT_RDONLY(0x511, 0x44));
  359. gpu_write(gpu, REG_A6XX_CP_PROTECT(14), A6XX_PROTECT_RW(0xe00, 0xe));
  360. gpu_write(gpu, REG_A6XX_CP_PROTECT(15), A6XX_PROTECT_RW(0x8e00, 0x0));
  361. gpu_write(gpu, REG_A6XX_CP_PROTECT(16), A6XX_PROTECT_RW(0x8e50, 0xf));
  362. gpu_write(gpu, REG_A6XX_CP_PROTECT(17), A6XX_PROTECT_RW(0xbe02, 0x0));
  363. gpu_write(gpu, REG_A6XX_CP_PROTECT(18),
  364. A6XX_PROTECT_RW(0xbe20, 0x11f3));
  365. gpu_write(gpu, REG_A6XX_CP_PROTECT(19), A6XX_PROTECT_RW(0x800, 0x82));
  366. gpu_write(gpu, REG_A6XX_CP_PROTECT(20), A6XX_PROTECT_RW(0x8a0, 0x8));
  367. gpu_write(gpu, REG_A6XX_CP_PROTECT(21), A6XX_PROTECT_RW(0x8ab, 0x19));
  368. gpu_write(gpu, REG_A6XX_CP_PROTECT(22), A6XX_PROTECT_RW(0x900, 0x4d));
  369. gpu_write(gpu, REG_A6XX_CP_PROTECT(23), A6XX_PROTECT_RW(0x98d, 0x76));
  370. gpu_write(gpu, REG_A6XX_CP_PROTECT(24),
  371. A6XX_PROTECT_RDONLY(0x980, 0x4));
  372. gpu_write(gpu, REG_A6XX_CP_PROTECT(25), A6XX_PROTECT_RW(0xa630, 0x0));
  373. /* Enable interrupts */
  374. gpu_write(gpu, REG_A6XX_RBBM_INT_0_MASK, A6XX_INT_MASK);
  375. ret = adreno_hw_init(gpu);
  376. if (ret)
  377. goto out;
  378. ret = a6xx_ucode_init(gpu);
  379. if (ret)
  380. goto out;
  381. /* Always come up on rb 0 */
  382. a6xx_gpu->cur_ring = gpu->rb[0];
  383. /* Enable the SQE_to start the CP engine */
  384. gpu_write(gpu, REG_A6XX_CP_SQE_CNTL, 1);
  385. ret = a6xx_cp_init(gpu);
  386. if (ret)
  387. goto out;
  388. gpu_write(gpu, REG_A6XX_RBBM_SECVID_TRUST_CNTL, 0x0);
  389. out:
  390. /*
  391. * Tell the GMU that we are done touching the GPU and it can start power
  392. * management
  393. */
  394. a6xx_gmu_clear_oob(&a6xx_gpu->gmu, GMU_OOB_GPU_SET);
  395. /* Take the GMU out of its special boot mode */
  396. a6xx_gmu_clear_oob(&a6xx_gpu->gmu, GMU_OOB_BOOT_SLUMBER);
  397. return ret;
  398. }
  399. static void a6xx_dump(struct msm_gpu *gpu)
  400. {
  401. dev_info(&gpu->pdev->dev, "status: %08x\n",
  402. gpu_read(gpu, REG_A6XX_RBBM_STATUS));
  403. adreno_dump(gpu);
  404. }
  405. #define VBIF_RESET_ACK_TIMEOUT 100
  406. #define VBIF_RESET_ACK_MASK 0x00f0
  407. static void a6xx_recover(struct msm_gpu *gpu)
  408. {
  409. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  410. struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
  411. int i;
  412. adreno_dump_info(gpu);
  413. for (i = 0; i < 8; i++)
  414. dev_info(&gpu->pdev->dev, "CP_SCRATCH_REG%d: %u\n", i,
  415. gpu_read(gpu, REG_A6XX_CP_SCRATCH_REG(i)));
  416. if (hang_debug)
  417. a6xx_dump(gpu);
  418. /*
  419. * Turn off keep alive that might have been enabled by the hang
  420. * interrupt
  421. */
  422. gmu_write(&a6xx_gpu->gmu, REG_A6XX_GMU_GMU_PWR_COL_KEEPALIVE, 0);
  423. gpu->funcs->pm_suspend(gpu);
  424. gpu->funcs->pm_resume(gpu);
  425. msm_gpu_hw_init(gpu);
  426. }
  427. static int a6xx_fault_handler(void *arg, unsigned long iova, int flags)
  428. {
  429. struct msm_gpu *gpu = arg;
  430. pr_warn_ratelimited("*** gpu fault: iova=%08lx, flags=%d (%u,%u,%u,%u)\n",
  431. iova, flags,
  432. gpu_read(gpu, REG_A6XX_CP_SCRATCH_REG(4)),
  433. gpu_read(gpu, REG_A6XX_CP_SCRATCH_REG(5)),
  434. gpu_read(gpu, REG_A6XX_CP_SCRATCH_REG(6)),
  435. gpu_read(gpu, REG_A6XX_CP_SCRATCH_REG(7)));
  436. return -EFAULT;
  437. }
  438. static void a6xx_cp_hw_err_irq(struct msm_gpu *gpu)
  439. {
  440. u32 status = gpu_read(gpu, REG_A6XX_CP_INTERRUPT_STATUS);
  441. if (status & A6XX_CP_INT_CP_OPCODE_ERROR) {
  442. u32 val;
  443. gpu_write(gpu, REG_A6XX_CP_SQE_STAT_ADDR, 1);
  444. val = gpu_read(gpu, REG_A6XX_CP_SQE_STAT_DATA);
  445. dev_err_ratelimited(&gpu->pdev->dev,
  446. "CP | opcode error | possible opcode=0x%8.8X\n",
  447. val);
  448. }
  449. if (status & A6XX_CP_INT_CP_UCODE_ERROR)
  450. dev_err_ratelimited(&gpu->pdev->dev,
  451. "CP ucode error interrupt\n");
  452. if (status & A6XX_CP_INT_CP_HW_FAULT_ERROR)
  453. dev_err_ratelimited(&gpu->pdev->dev, "CP | HW fault | status=0x%8.8X\n",
  454. gpu_read(gpu, REG_A6XX_CP_HW_FAULT));
  455. if (status & A6XX_CP_INT_CP_REGISTER_PROTECTION_ERROR) {
  456. u32 val = gpu_read(gpu, REG_A6XX_CP_PROTECT_STATUS);
  457. dev_err_ratelimited(&gpu->pdev->dev,
  458. "CP | protected mode error | %s | addr=0x%8.8X | status=0x%8.8X\n",
  459. val & (1 << 20) ? "READ" : "WRITE",
  460. (val & 0x3ffff), val);
  461. }
  462. if (status & A6XX_CP_INT_CP_AHB_ERROR)
  463. dev_err_ratelimited(&gpu->pdev->dev, "CP AHB error interrupt\n");
  464. if (status & A6XX_CP_INT_CP_VSD_PARITY_ERROR)
  465. dev_err_ratelimited(&gpu->pdev->dev, "CP VSD decoder parity error\n");
  466. if (status & A6XX_CP_INT_CP_ILLEGAL_INSTR_ERROR)
  467. dev_err_ratelimited(&gpu->pdev->dev, "CP illegal instruction error\n");
  468. }
  469. static void a6xx_fault_detect_irq(struct msm_gpu *gpu)
  470. {
  471. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  472. struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
  473. struct drm_device *dev = gpu->dev;
  474. struct msm_drm_private *priv = dev->dev_private;
  475. struct msm_ringbuffer *ring = gpu->funcs->active_ring(gpu);
  476. /*
  477. * Force the GPU to stay on until after we finish
  478. * collecting information
  479. */
  480. gmu_write(&a6xx_gpu->gmu, REG_A6XX_GMU_GMU_PWR_COL_KEEPALIVE, 1);
  481. DRM_DEV_ERROR(&gpu->pdev->dev,
  482. "gpu fault ring %d fence %x status %8.8X rb %4.4x/%4.4x ib1 %16.16llX/%4.4x ib2 %16.16llX/%4.4x\n",
  483. ring ? ring->id : -1, ring ? ring->seqno : 0,
  484. gpu_read(gpu, REG_A6XX_RBBM_STATUS),
  485. gpu_read(gpu, REG_A6XX_CP_RB_RPTR),
  486. gpu_read(gpu, REG_A6XX_CP_RB_WPTR),
  487. gpu_read64(gpu, REG_A6XX_CP_IB1_BASE, REG_A6XX_CP_IB1_BASE_HI),
  488. gpu_read(gpu, REG_A6XX_CP_IB1_REM_SIZE),
  489. gpu_read64(gpu, REG_A6XX_CP_IB2_BASE, REG_A6XX_CP_IB2_BASE_HI),
  490. gpu_read(gpu, REG_A6XX_CP_IB2_REM_SIZE));
  491. /* Turn off the hangcheck timer to keep it from bothering us */
  492. del_timer(&gpu->hangcheck_timer);
  493. queue_work(priv->wq, &gpu->recover_work);
  494. }
  495. static irqreturn_t a6xx_irq(struct msm_gpu *gpu)
  496. {
  497. u32 status = gpu_read(gpu, REG_A6XX_RBBM_INT_0_STATUS);
  498. gpu_write(gpu, REG_A6XX_RBBM_INT_CLEAR_CMD, status);
  499. if (status & A6XX_RBBM_INT_0_MASK_RBBM_HANG_DETECT)
  500. a6xx_fault_detect_irq(gpu);
  501. if (status & A6XX_RBBM_INT_0_MASK_CP_AHB_ERROR)
  502. dev_err_ratelimited(&gpu->pdev->dev, "CP | AHB bus error\n");
  503. if (status & A6XX_RBBM_INT_0_MASK_CP_HW_ERROR)
  504. a6xx_cp_hw_err_irq(gpu);
  505. if (status & A6XX_RBBM_INT_0_MASK_RBBM_ATB_ASYNCFIFO_OVERFLOW)
  506. dev_err_ratelimited(&gpu->pdev->dev, "RBBM | ATB ASYNC overflow\n");
  507. if (status & A6XX_RBBM_INT_0_MASK_RBBM_ATB_BUS_OVERFLOW)
  508. dev_err_ratelimited(&gpu->pdev->dev, "RBBM | ATB bus overflow\n");
  509. if (status & A6XX_RBBM_INT_0_MASK_UCHE_OOB_ACCESS)
  510. dev_err_ratelimited(&gpu->pdev->dev, "UCHE | Out of bounds access\n");
  511. if (status & A6XX_RBBM_INT_0_MASK_CP_CACHE_FLUSH_TS)
  512. msm_gpu_retire(gpu);
  513. return IRQ_HANDLED;
  514. }
  515. static const u32 a6xx_register_offsets[REG_ADRENO_REGISTER_MAX] = {
  516. REG_ADRENO_DEFINE(REG_ADRENO_CP_RB_BASE, REG_A6XX_CP_RB_BASE),
  517. REG_ADRENO_DEFINE(REG_ADRENO_CP_RB_BASE_HI, REG_A6XX_CP_RB_BASE_HI),
  518. REG_ADRENO_DEFINE(REG_ADRENO_CP_RB_RPTR_ADDR,
  519. REG_A6XX_CP_RB_RPTR_ADDR_LO),
  520. REG_ADRENO_DEFINE(REG_ADRENO_CP_RB_RPTR_ADDR_HI,
  521. REG_A6XX_CP_RB_RPTR_ADDR_HI),
  522. REG_ADRENO_DEFINE(REG_ADRENO_CP_RB_RPTR, REG_A6XX_CP_RB_RPTR),
  523. REG_ADRENO_DEFINE(REG_ADRENO_CP_RB_WPTR, REG_A6XX_CP_RB_WPTR),
  524. REG_ADRENO_DEFINE(REG_ADRENO_CP_RB_CNTL, REG_A6XX_CP_RB_CNTL),
  525. };
  526. static const u32 a6xx_registers[] = {
  527. 0x0000, 0x0002, 0x0010, 0x0010, 0x0012, 0x0012, 0x0018, 0x001b,
  528. 0x001e, 0x0032, 0x0038, 0x003c, 0x0042, 0x0042, 0x0044, 0x0044,
  529. 0x0047, 0x0047, 0x0056, 0x0056, 0x00ad, 0x00ae, 0x00b0, 0x00fb,
  530. 0x0100, 0x011d, 0x0200, 0x020d, 0x0210, 0x0213, 0x0218, 0x023d,
  531. 0x0400, 0x04f9, 0x0500, 0x0500, 0x0505, 0x050b, 0x050e, 0x0511,
  532. 0x0533, 0x0533, 0x0540, 0x0555, 0x0800, 0x0808, 0x0810, 0x0813,
  533. 0x0820, 0x0821, 0x0823, 0x0827, 0x0830, 0x0833, 0x0840, 0x0843,
  534. 0x084f, 0x086f, 0x0880, 0x088a, 0x08a0, 0x08ab, 0x08c0, 0x08c4,
  535. 0x08d0, 0x08dd, 0x08f0, 0x08f3, 0x0900, 0x0903, 0x0908, 0x0911,
  536. 0x0928, 0x093e, 0x0942, 0x094d, 0x0980, 0x0984, 0x098d, 0x0996,
  537. 0x0998, 0x099e, 0x09a0, 0x09a6, 0x09a8, 0x09ae, 0x09b0, 0x09b1,
  538. 0x09c2, 0x09c8, 0x0a00, 0x0a03, 0x0c00, 0x0c04, 0x0c06, 0x0c06,
  539. 0x0c10, 0x0cd9, 0x0e00, 0x0e0e, 0x0e10, 0x0e13, 0x0e17, 0x0e19,
  540. 0x0e1c, 0x0e2b, 0x0e30, 0x0e32, 0x0e38, 0x0e39, 0x8600, 0x8601,
  541. 0x8610, 0x861b, 0x8620, 0x8620, 0x8628, 0x862b, 0x8630, 0x8637,
  542. 0x8e01, 0x8e01, 0x8e04, 0x8e05, 0x8e07, 0x8e08, 0x8e0c, 0x8e0c,
  543. 0x8e10, 0x8e1c, 0x8e20, 0x8e25, 0x8e28, 0x8e28, 0x8e2c, 0x8e2f,
  544. 0x8e3b, 0x8e3e, 0x8e40, 0x8e43, 0x8e50, 0x8e5e, 0x8e70, 0x8e77,
  545. 0x9600, 0x9604, 0x9624, 0x9637, 0x9e00, 0x9e01, 0x9e03, 0x9e0e,
  546. 0x9e11, 0x9e16, 0x9e19, 0x9e19, 0x9e1c, 0x9e1c, 0x9e20, 0x9e23,
  547. 0x9e30, 0x9e31, 0x9e34, 0x9e34, 0x9e70, 0x9e72, 0x9e78, 0x9e79,
  548. 0x9e80, 0x9fff, 0xa600, 0xa601, 0xa603, 0xa603, 0xa60a, 0xa60a,
  549. 0xa610, 0xa617, 0xa630, 0xa630,
  550. ~0
  551. };
  552. static int a6xx_pm_resume(struct msm_gpu *gpu)
  553. {
  554. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  555. struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
  556. int ret;
  557. ret = a6xx_gmu_resume(a6xx_gpu);
  558. gpu->needs_hw_init = true;
  559. msm_gpu_resume_devfreq(gpu);
  560. return ret;
  561. }
  562. static int a6xx_pm_suspend(struct msm_gpu *gpu)
  563. {
  564. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  565. struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
  566. devfreq_suspend_device(gpu->devfreq.devfreq);
  567. /*
  568. * Make sure the GMU is idle before continuing (because some transitions
  569. * may use VBIF
  570. */
  571. a6xx_gmu_wait_for_idle(a6xx_gpu);
  572. /* Clear the VBIF pipe before shutting down */
  573. /* FIXME: This accesses the GPU - do we need to make sure it is on? */
  574. gpu_write(gpu, REG_A6XX_VBIF_XIN_HALT_CTRL0, 0xf);
  575. spin_until((gpu_read(gpu, REG_A6XX_VBIF_XIN_HALT_CTRL1) & 0xf) == 0xf);
  576. gpu_write(gpu, REG_A6XX_VBIF_XIN_HALT_CTRL0, 0);
  577. return a6xx_gmu_stop(a6xx_gpu);
  578. }
  579. static int a6xx_get_timestamp(struct msm_gpu *gpu, uint64_t *value)
  580. {
  581. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  582. struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
  583. /* Force the GPU power on so we can read this register */
  584. a6xx_gmu_set_oob(&a6xx_gpu->gmu, GMU_OOB_GPU_SET);
  585. *value = gpu_read64(gpu, REG_A6XX_RBBM_PERFCTR_CP_0_LO,
  586. REG_A6XX_RBBM_PERFCTR_CP_0_HI);
  587. a6xx_gmu_clear_oob(&a6xx_gpu->gmu, GMU_OOB_GPU_SET);
  588. return 0;
  589. }
  590. #if defined(CONFIG_DEBUG_FS) || defined(CONFIG_DEV_COREDUMP)
  591. static void a6xx_show(struct msm_gpu *gpu, struct msm_gpu_state *state,
  592. struct drm_printer *p)
  593. {
  594. adreno_show(gpu, state, p);
  595. }
  596. #endif
  597. static struct msm_ringbuffer *a6xx_active_ring(struct msm_gpu *gpu)
  598. {
  599. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  600. struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
  601. return a6xx_gpu->cur_ring;
  602. }
  603. static void a6xx_destroy(struct msm_gpu *gpu)
  604. {
  605. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  606. struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
  607. if (a6xx_gpu->sqe_bo) {
  608. if (a6xx_gpu->sqe_iova)
  609. msm_gem_put_iova(a6xx_gpu->sqe_bo, gpu->aspace);
  610. drm_gem_object_put_unlocked(a6xx_gpu->sqe_bo);
  611. }
  612. a6xx_gmu_remove(a6xx_gpu);
  613. adreno_gpu_cleanup(adreno_gpu);
  614. kfree(a6xx_gpu);
  615. }
  616. static unsigned long a6xx_gpu_busy(struct msm_gpu *gpu)
  617. {
  618. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  619. struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
  620. u64 busy_cycles, busy_time;
  621. busy_cycles = gmu_read64(&a6xx_gpu->gmu,
  622. REG_A6XX_GMU_CX_GMU_POWER_COUNTER_XOCLK_0_L,
  623. REG_A6XX_GMU_CX_GMU_POWER_COUNTER_XOCLK_0_H);
  624. busy_time = (busy_cycles - gpu->devfreq.busy_cycles) * 10;
  625. do_div(busy_time, 192);
  626. gpu->devfreq.busy_cycles = busy_cycles;
  627. if (WARN_ON(busy_time > ~0LU))
  628. return ~0LU;
  629. return (unsigned long)busy_time;
  630. }
  631. static const struct adreno_gpu_funcs funcs = {
  632. .base = {
  633. .get_param = adreno_get_param,
  634. .hw_init = a6xx_hw_init,
  635. .pm_suspend = a6xx_pm_suspend,
  636. .pm_resume = a6xx_pm_resume,
  637. .recover = a6xx_recover,
  638. .submit = a6xx_submit,
  639. .flush = a6xx_flush,
  640. .active_ring = a6xx_active_ring,
  641. .irq = a6xx_irq,
  642. .destroy = a6xx_destroy,
  643. #if defined(CONFIG_DEBUG_FS) || defined(CONFIG_DEV_COREDUMP)
  644. .show = a6xx_show,
  645. #endif
  646. .gpu_busy = a6xx_gpu_busy,
  647. .gpu_get_freq = a6xx_gmu_get_freq,
  648. .gpu_set_freq = a6xx_gmu_set_freq,
  649. },
  650. .get_timestamp = a6xx_get_timestamp,
  651. };
  652. struct msm_gpu *a6xx_gpu_init(struct drm_device *dev)
  653. {
  654. struct msm_drm_private *priv = dev->dev_private;
  655. struct platform_device *pdev = priv->gpu_pdev;
  656. struct device_node *node;
  657. struct a6xx_gpu *a6xx_gpu;
  658. struct adreno_gpu *adreno_gpu;
  659. struct msm_gpu *gpu;
  660. int ret;
  661. a6xx_gpu = kzalloc(sizeof(*a6xx_gpu), GFP_KERNEL);
  662. if (!a6xx_gpu)
  663. return ERR_PTR(-ENOMEM);
  664. adreno_gpu = &a6xx_gpu->base;
  665. gpu = &adreno_gpu->base;
  666. adreno_gpu->registers = a6xx_registers;
  667. adreno_gpu->reg_offsets = a6xx_register_offsets;
  668. ret = adreno_gpu_init(dev, pdev, adreno_gpu, &funcs, 1);
  669. if (ret) {
  670. a6xx_destroy(&(a6xx_gpu->base.base));
  671. return ERR_PTR(ret);
  672. }
  673. /* Check if there is a GMU phandle and set it up */
  674. node = of_parse_phandle(pdev->dev.of_node, "qcom,gmu", 0);
  675. /* FIXME: How do we gracefully handle this? */
  676. BUG_ON(!node);
  677. ret = a6xx_gmu_probe(a6xx_gpu, node);
  678. if (ret) {
  679. a6xx_destroy(&(a6xx_gpu->base.base));
  680. return ERR_PTR(ret);
  681. }
  682. if (gpu->aspace)
  683. msm_mmu_set_fault_handler(gpu->aspace->mmu, gpu,
  684. a6xx_fault_handler);
  685. return gpu;
  686. }