a6xx_gpu.c 26 KB

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