a4xx_gpu.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. /* Copyright (c) 2014 The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. */
  13. #include "a4xx_gpu.h"
  14. #ifdef CONFIG_MSM_OCMEM
  15. # include <soc/qcom/ocmem.h>
  16. #endif
  17. #define A4XX_INT0_MASK \
  18. (A4XX_INT0_RBBM_AHB_ERROR | \
  19. A4XX_INT0_RBBM_ATB_BUS_OVERFLOW | \
  20. A4XX_INT0_CP_T0_PACKET_IN_IB | \
  21. A4XX_INT0_CP_OPCODE_ERROR | \
  22. A4XX_INT0_CP_RESERVED_BIT_ERROR | \
  23. A4XX_INT0_CP_HW_FAULT | \
  24. A4XX_INT0_CP_IB1_INT | \
  25. A4XX_INT0_CP_IB2_INT | \
  26. A4XX_INT0_CP_RB_INT | \
  27. A4XX_INT0_CP_REG_PROTECT_FAULT | \
  28. A4XX_INT0_CP_AHB_ERROR_HALT | \
  29. A4XX_INT0_UCHE_OOB_ACCESS)
  30. extern bool hang_debug;
  31. static void a4xx_dump(struct msm_gpu *gpu);
  32. /*
  33. * a4xx_enable_hwcg() - Program the clock control registers
  34. * @device: The adreno device pointer
  35. */
  36. static void a4xx_enable_hwcg(struct msm_gpu *gpu)
  37. {
  38. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  39. unsigned int i;
  40. for (i = 0; i < 4; i++)
  41. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL_TP(i), 0x02222202);
  42. for (i = 0; i < 4; i++)
  43. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL2_TP(i), 0x00002222);
  44. for (i = 0; i < 4; i++)
  45. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_HYST_TP(i), 0x0E739CE7);
  46. for (i = 0; i < 4; i++)
  47. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_DELAY_TP(i), 0x00111111);
  48. for (i = 0; i < 4; i++)
  49. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL_SP(i), 0x22222222);
  50. for (i = 0; i < 4; i++)
  51. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL2_SP(i), 0x00222222);
  52. for (i = 0; i < 4; i++)
  53. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_HYST_SP(i), 0x00000104);
  54. for (i = 0; i < 4; i++)
  55. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_DELAY_SP(i), 0x00000081);
  56. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL_UCHE, 0x22222222);
  57. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL2_UCHE, 0x02222222);
  58. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL3_UCHE, 0x00000000);
  59. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL4_UCHE, 0x00000000);
  60. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_HYST_UCHE, 0x00004444);
  61. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_DELAY_UCHE, 0x00001112);
  62. for (i = 0; i < 4; i++)
  63. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL_RB(i), 0x22222222);
  64. /* Disable L1 clocking in A420 due to CCU issues with it */
  65. for (i = 0; i < 4; i++) {
  66. if (adreno_is_a420(adreno_gpu)) {
  67. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL2_RB(i),
  68. 0x00002020);
  69. } else {
  70. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL2_RB(i),
  71. 0x00022020);
  72. }
  73. }
  74. for (i = 0; i < 4; i++) {
  75. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL_MARB_CCU(i),
  76. 0x00000922);
  77. }
  78. for (i = 0; i < 4; i++) {
  79. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_HYST_RB_MARB_CCU(i),
  80. 0x00000000);
  81. }
  82. for (i = 0; i < 4; i++) {
  83. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_DELAY_RB_MARB_CCU_L1(i),
  84. 0x00000001);
  85. }
  86. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_MODE_GPC, 0x02222222);
  87. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_HYST_GPC, 0x04100104);
  88. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_DELAY_GPC, 0x00022222);
  89. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL_COM_DCOM, 0x00000022);
  90. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_HYST_COM_DCOM, 0x0000010F);
  91. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_DELAY_COM_DCOM, 0x00000022);
  92. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL_TSE_RAS_RBBM, 0x00222222);
  93. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_HYST_TSE_RAS_RBBM, 0x00004104);
  94. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_DELAY_TSE_RAS_RBBM, 0x00000222);
  95. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL_HLSQ , 0x00000000);
  96. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_HYST_HLSQ, 0x00000000);
  97. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_DELAY_HLSQ, 0x00020000);
  98. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL, 0xAAAAAAAA);
  99. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_CTL2, 0);
  100. }
  101. static void a4xx_me_init(struct msm_gpu *gpu)
  102. {
  103. struct msm_ringbuffer *ring = gpu->rb;
  104. OUT_PKT3(ring, CP_ME_INIT, 17);
  105. OUT_RING(ring, 0x000003f7);
  106. OUT_RING(ring, 0x00000000);
  107. OUT_RING(ring, 0x00000000);
  108. OUT_RING(ring, 0x00000000);
  109. OUT_RING(ring, 0x00000080);
  110. OUT_RING(ring, 0x00000100);
  111. OUT_RING(ring, 0x00000180);
  112. OUT_RING(ring, 0x00006600);
  113. OUT_RING(ring, 0x00000150);
  114. OUT_RING(ring, 0x0000014e);
  115. OUT_RING(ring, 0x00000154);
  116. OUT_RING(ring, 0x00000001);
  117. OUT_RING(ring, 0x00000000);
  118. OUT_RING(ring, 0x00000000);
  119. OUT_RING(ring, 0x00000000);
  120. OUT_RING(ring, 0x00000000);
  121. OUT_RING(ring, 0x00000000);
  122. gpu->funcs->flush(gpu);
  123. gpu->funcs->idle(gpu);
  124. }
  125. static int a4xx_hw_init(struct msm_gpu *gpu)
  126. {
  127. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  128. struct a4xx_gpu *a4xx_gpu = to_a4xx_gpu(adreno_gpu);
  129. uint32_t *ptr, len;
  130. int i, ret;
  131. if (adreno_is_a4xx(adreno_gpu)) {
  132. gpu_write(gpu, REG_A4XX_VBIF_ABIT_SORT, 0x0001001F);
  133. gpu_write(gpu, REG_A4XX_VBIF_ABIT_SORT_CONF, 0x000000A4);
  134. gpu_write(gpu, REG_A4XX_VBIF_GATE_OFF_WRREQ_EN, 0x00000001);
  135. gpu_write(gpu, REG_A4XX_VBIF_IN_RD_LIM_CONF0, 0x18181818);
  136. gpu_write(gpu, REG_A4XX_VBIF_IN_RD_LIM_CONF1, 0x00000018);
  137. gpu_write(gpu, REG_A4XX_VBIF_IN_WR_LIM_CONF0, 0x18181818);
  138. gpu_write(gpu, REG_A4XX_VBIF_IN_WR_LIM_CONF1, 0x00000018);
  139. gpu_write(gpu, REG_A4XX_VBIF_ROUND_ROBIN_QOS_ARB, 0x00000003);
  140. } else {
  141. BUG();
  142. }
  143. /* Make all blocks contribute to the GPU BUSY perf counter */
  144. gpu_write(gpu, REG_A4XX_RBBM_GPU_BUSY_MASKED, 0xffffffff);
  145. /* Tune the hystersis counters for SP and CP idle detection */
  146. gpu_write(gpu, REG_A4XX_RBBM_SP_HYST_CNT, 0x10);
  147. gpu_write(gpu, REG_A4XX_RBBM_WAIT_IDLE_CLOCKS_CTL, 0x10);
  148. /* Enable the RBBM error reporting bits */
  149. gpu_write(gpu, REG_A4XX_RBBM_AHB_CTL0, 0x00000001);
  150. /* Enable AHB error reporting*/
  151. gpu_write(gpu, REG_A4XX_RBBM_AHB_CTL1, 0xa6ffffff);
  152. /* Enable power counters*/
  153. gpu_write(gpu, REG_A4XX_RBBM_RBBM_CTL, 0x00000030);
  154. /*
  155. * Turn on hang detection - this spews a lot of useful information
  156. * into the RBBM registers on a hang:
  157. */
  158. gpu_write(gpu, REG_A4XX_RBBM_INTERFACE_HANG_INT_CTL,
  159. (1 << 30) | 0xFFFF);
  160. gpu_write(gpu, REG_A4XX_RB_GMEM_BASE_ADDR,
  161. (unsigned int)(a4xx_gpu->ocmem_base >> 14));
  162. /* Turn on performance counters: */
  163. gpu_write(gpu, REG_A4XX_RBBM_PERFCTR_CTL, 0x01);
  164. /* Disable L2 bypass to avoid UCHE out of bounds errors */
  165. gpu_write(gpu, REG_A4XX_UCHE_TRAP_BASE_LO, 0xffff0000);
  166. gpu_write(gpu, REG_A4XX_UCHE_TRAP_BASE_HI, 0xffff0000);
  167. gpu_write(gpu, REG_A4XX_CP_DEBUG, (1 << 25) |
  168. (adreno_is_a420(adreno_gpu) ? (1 << 29) : 0));
  169. a4xx_enable_hwcg(gpu);
  170. /*
  171. * For A420 set RBBM_CLOCK_DELAY_HLSQ.CGC_HLSQ_TP_EARLY_CYC >= 2
  172. * due to timing issue with HLSQ_TP_CLK_EN
  173. */
  174. if (adreno_is_a420(adreno_gpu)) {
  175. unsigned int val;
  176. val = gpu_read(gpu, REG_A4XX_RBBM_CLOCK_DELAY_HLSQ);
  177. val &= ~A4XX_CGC_HLSQ_EARLY_CYC__MASK;
  178. val |= 2 << A4XX_CGC_HLSQ_EARLY_CYC__SHIFT;
  179. gpu_write(gpu, REG_A4XX_RBBM_CLOCK_DELAY_HLSQ, val);
  180. }
  181. ret = adreno_hw_init(gpu);
  182. if (ret)
  183. return ret;
  184. /* setup access protection: */
  185. gpu_write(gpu, REG_A4XX_CP_PROTECT_CTRL, 0x00000007);
  186. /* RBBM registers */
  187. gpu_write(gpu, REG_A4XX_CP_PROTECT(0), 0x62000010);
  188. gpu_write(gpu, REG_A4XX_CP_PROTECT(1), 0x63000020);
  189. gpu_write(gpu, REG_A4XX_CP_PROTECT(2), 0x64000040);
  190. gpu_write(gpu, REG_A4XX_CP_PROTECT(3), 0x65000080);
  191. gpu_write(gpu, REG_A4XX_CP_PROTECT(4), 0x66000100);
  192. gpu_write(gpu, REG_A4XX_CP_PROTECT(5), 0x64000200);
  193. /* CP registers */
  194. gpu_write(gpu, REG_A4XX_CP_PROTECT(6), 0x67000800);
  195. gpu_write(gpu, REG_A4XX_CP_PROTECT(7), 0x64001600);
  196. /* RB registers */
  197. gpu_write(gpu, REG_A4XX_CP_PROTECT(8), 0x60003300);
  198. /* HLSQ registers */
  199. gpu_write(gpu, REG_A4XX_CP_PROTECT(9), 0x60003800);
  200. /* VPC registers */
  201. gpu_write(gpu, REG_A4XX_CP_PROTECT(10), 0x61003980);
  202. /* SMMU registers */
  203. gpu_write(gpu, REG_A4XX_CP_PROTECT(11), 0x6e010000);
  204. gpu_write(gpu, REG_A4XX_RBBM_INT_0_MASK, A4XX_INT0_MASK);
  205. ret = adreno_hw_init(gpu);
  206. if (ret)
  207. return ret;
  208. /* Load PM4: */
  209. ptr = (uint32_t *)(adreno_gpu->pm4->data);
  210. len = adreno_gpu->pm4->size / 4;
  211. DBG("loading PM4 ucode version: %u", ptr[0]);
  212. gpu_write(gpu, REG_A4XX_CP_ME_RAM_WADDR, 0);
  213. for (i = 1; i < len; i++)
  214. gpu_write(gpu, REG_A4XX_CP_ME_RAM_DATA, ptr[i]);
  215. /* Load PFP: */
  216. ptr = (uint32_t *)(adreno_gpu->pfp->data);
  217. len = adreno_gpu->pfp->size / 4;
  218. DBG("loading PFP ucode version: %u", ptr[0]);
  219. gpu_write(gpu, REG_A4XX_CP_PFP_UCODE_ADDR, 0);
  220. for (i = 1; i < len; i++)
  221. gpu_write(gpu, REG_A4XX_CP_PFP_UCODE_DATA, ptr[i]);
  222. /* clear ME_HALT to start micro engine */
  223. gpu_write(gpu, REG_A4XX_CP_ME_CNTL, 0);
  224. a4xx_me_init(gpu);
  225. return 0;
  226. }
  227. static void a4xx_recover(struct msm_gpu *gpu)
  228. {
  229. adreno_dump_info(gpu);
  230. /* dump registers before resetting gpu, if enabled: */
  231. if (hang_debug)
  232. a4xx_dump(gpu);
  233. gpu_write(gpu, REG_A4XX_RBBM_SW_RESET_CMD, 1);
  234. gpu_read(gpu, REG_A4XX_RBBM_SW_RESET_CMD);
  235. gpu_write(gpu, REG_A4XX_RBBM_SW_RESET_CMD, 0);
  236. adreno_recover(gpu);
  237. }
  238. static void a4xx_destroy(struct msm_gpu *gpu)
  239. {
  240. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  241. struct a4xx_gpu *a4xx_gpu = to_a4xx_gpu(adreno_gpu);
  242. DBG("%s", gpu->name);
  243. adreno_gpu_cleanup(adreno_gpu);
  244. #ifdef CONFIG_MSM_OCMEM
  245. if (a4xx_gpu->ocmem_base)
  246. ocmem_free(OCMEM_GRAPHICS, a4xx_gpu->ocmem_hdl);
  247. #endif
  248. kfree(a4xx_gpu);
  249. }
  250. static void a4xx_idle(struct msm_gpu *gpu)
  251. {
  252. /* wait for ringbuffer to drain: */
  253. adreno_idle(gpu);
  254. /* then wait for GPU to finish: */
  255. if (spin_until(!(gpu_read(gpu, REG_A4XX_RBBM_STATUS) &
  256. A4XX_RBBM_STATUS_GPU_BUSY)))
  257. DRM_ERROR("%s: timeout waiting for GPU to idle!\n", gpu->name);
  258. /* TODO maybe we need to reset GPU here to recover from hang? */
  259. }
  260. static irqreturn_t a4xx_irq(struct msm_gpu *gpu)
  261. {
  262. uint32_t status;
  263. status = gpu_read(gpu, REG_A4XX_RBBM_INT_0_STATUS);
  264. DBG("%s: Int status %08x", gpu->name, status);
  265. gpu_write(gpu, REG_A4XX_RBBM_INT_CLEAR_CMD, status);
  266. msm_gpu_retire(gpu);
  267. return IRQ_HANDLED;
  268. }
  269. static const unsigned int a4xx_registers[] = {
  270. /* RBBM */
  271. 0x0000, 0x0002, 0x0004, 0x0021, 0x0023, 0x0024, 0x0026, 0x0026,
  272. 0x0028, 0x002B, 0x002E, 0x0034, 0x0037, 0x0044, 0x0047, 0x0066,
  273. 0x0068, 0x0095, 0x009C, 0x0170, 0x0174, 0x01AF,
  274. /* CP */
  275. 0x0200, 0x0233, 0x0240, 0x0250, 0x04C0, 0x04DD, 0x0500, 0x050B,
  276. 0x0578, 0x058F,
  277. /* VSC */
  278. 0x0C00, 0x0C03, 0x0C08, 0x0C41, 0x0C50, 0x0C51,
  279. /* GRAS */
  280. 0x0C80, 0x0C81, 0x0C88, 0x0C8F,
  281. /* RB */
  282. 0x0CC0, 0x0CC0, 0x0CC4, 0x0CD2,
  283. /* PC */
  284. 0x0D00, 0x0D0C, 0x0D10, 0x0D17, 0x0D20, 0x0D23,
  285. /* VFD */
  286. 0x0E40, 0x0E4A,
  287. /* VPC */
  288. 0x0E60, 0x0E61, 0x0E63, 0x0E68,
  289. /* UCHE */
  290. 0x0E80, 0x0E84, 0x0E88, 0x0E95,
  291. /* VMIDMT */
  292. 0x1000, 0x1000, 0x1002, 0x1002, 0x1004, 0x1004, 0x1008, 0x100A,
  293. 0x100C, 0x100D, 0x100F, 0x1010, 0x1012, 0x1016, 0x1024, 0x1024,
  294. 0x1027, 0x1027, 0x1100, 0x1100, 0x1102, 0x1102, 0x1104, 0x1104,
  295. 0x1110, 0x1110, 0x1112, 0x1116, 0x1124, 0x1124, 0x1300, 0x1300,
  296. 0x1380, 0x1380,
  297. /* GRAS CTX 0 */
  298. 0x2000, 0x2004, 0x2008, 0x2067, 0x2070, 0x2078, 0x207B, 0x216E,
  299. /* PC CTX 0 */
  300. 0x21C0, 0x21C6, 0x21D0, 0x21D0, 0x21D9, 0x21D9, 0x21E5, 0x21E7,
  301. /* VFD CTX 0 */
  302. 0x2200, 0x2204, 0x2208, 0x22A9,
  303. /* GRAS CTX 1 */
  304. 0x2400, 0x2404, 0x2408, 0x2467, 0x2470, 0x2478, 0x247B, 0x256E,
  305. /* PC CTX 1 */
  306. 0x25C0, 0x25C6, 0x25D0, 0x25D0, 0x25D9, 0x25D9, 0x25E5, 0x25E7,
  307. /* VFD CTX 1 */
  308. 0x2600, 0x2604, 0x2608, 0x26A9,
  309. /* XPU */
  310. 0x2C00, 0x2C01, 0x2C10, 0x2C10, 0x2C12, 0x2C16, 0x2C1D, 0x2C20,
  311. 0x2C28, 0x2C28, 0x2C30, 0x2C30, 0x2C32, 0x2C36, 0x2C40, 0x2C40,
  312. 0x2C50, 0x2C50, 0x2C52, 0x2C56, 0x2C80, 0x2C80, 0x2C94, 0x2C95,
  313. /* VBIF */
  314. 0x3000, 0x3007, 0x300C, 0x3014, 0x3018, 0x301D, 0x3020, 0x3022,
  315. 0x3024, 0x3026, 0x3028, 0x302A, 0x302C, 0x302D, 0x3030, 0x3031,
  316. 0x3034, 0x3036, 0x3038, 0x3038, 0x303C, 0x303D, 0x3040, 0x3040,
  317. 0x3049, 0x3049, 0x3058, 0x3058, 0x305B, 0x3061, 0x3064, 0x3068,
  318. 0x306C, 0x306D, 0x3080, 0x3088, 0x308B, 0x308C, 0x3090, 0x3094,
  319. 0x3098, 0x3098, 0x309C, 0x309C, 0x30C0, 0x30C0, 0x30C8, 0x30C8,
  320. 0x30D0, 0x30D0, 0x30D8, 0x30D8, 0x30E0, 0x30E0, 0x3100, 0x3100,
  321. 0x3108, 0x3108, 0x3110, 0x3110, 0x3118, 0x3118, 0x3120, 0x3120,
  322. 0x3124, 0x3125, 0x3129, 0x3129, 0x3131, 0x3131, 0x330C, 0x330C,
  323. 0x3310, 0x3310, 0x3400, 0x3401, 0x3410, 0x3410, 0x3412, 0x3416,
  324. 0x341D, 0x3420, 0x3428, 0x3428, 0x3430, 0x3430, 0x3432, 0x3436,
  325. 0x3440, 0x3440, 0x3450, 0x3450, 0x3452, 0x3456, 0x3480, 0x3480,
  326. 0x3494, 0x3495, 0x4000, 0x4000, 0x4002, 0x4002, 0x4004, 0x4004,
  327. 0x4008, 0x400A, 0x400C, 0x400D, 0x400F, 0x4012, 0x4014, 0x4016,
  328. 0x401D, 0x401D, 0x4020, 0x4027, 0x4060, 0x4062, 0x4200, 0x4200,
  329. 0x4300, 0x4300, 0x4400, 0x4400, 0x4500, 0x4500, 0x4800, 0x4802,
  330. 0x480F, 0x480F, 0x4811, 0x4811, 0x4813, 0x4813, 0x4815, 0x4816,
  331. 0x482B, 0x482B, 0x4857, 0x4857, 0x4883, 0x4883, 0x48AF, 0x48AF,
  332. 0x48C5, 0x48C5, 0x48E5, 0x48E5, 0x4905, 0x4905, 0x4925, 0x4925,
  333. 0x4945, 0x4945, 0x4950, 0x4950, 0x495B, 0x495B, 0x4980, 0x498E,
  334. 0x4B00, 0x4B00, 0x4C00, 0x4C00, 0x4D00, 0x4D00, 0x4E00, 0x4E00,
  335. 0x4E80, 0x4E80, 0x4F00, 0x4F00, 0x4F08, 0x4F08, 0x4F10, 0x4F10,
  336. 0x4F18, 0x4F18, 0x4F20, 0x4F20, 0x4F30, 0x4F30, 0x4F60, 0x4F60,
  337. 0x4F80, 0x4F81, 0x4F88, 0x4F89, 0x4FEE, 0x4FEE, 0x4FF3, 0x4FF3,
  338. 0x6000, 0x6001, 0x6008, 0x600F, 0x6014, 0x6016, 0x6018, 0x601B,
  339. 0x61FD, 0x61FD, 0x623C, 0x623C, 0x6380, 0x6380, 0x63A0, 0x63A0,
  340. 0x63C0, 0x63C1, 0x63C8, 0x63C9, 0x63D0, 0x63D4, 0x63D6, 0x63D6,
  341. 0x63EE, 0x63EE, 0x6400, 0x6401, 0x6408, 0x640F, 0x6414, 0x6416,
  342. 0x6418, 0x641B, 0x65FD, 0x65FD, 0x663C, 0x663C, 0x6780, 0x6780,
  343. 0x67A0, 0x67A0, 0x67C0, 0x67C1, 0x67C8, 0x67C9, 0x67D0, 0x67D4,
  344. 0x67D6, 0x67D6, 0x67EE, 0x67EE, 0x6800, 0x6801, 0x6808, 0x680F,
  345. 0x6814, 0x6816, 0x6818, 0x681B, 0x69FD, 0x69FD, 0x6A3C, 0x6A3C,
  346. 0x6B80, 0x6B80, 0x6BA0, 0x6BA0, 0x6BC0, 0x6BC1, 0x6BC8, 0x6BC9,
  347. 0x6BD0, 0x6BD4, 0x6BD6, 0x6BD6, 0x6BEE, 0x6BEE,
  348. ~0 /* sentinel */
  349. };
  350. #ifdef CONFIG_DEBUG_FS
  351. static void a4xx_show(struct msm_gpu *gpu, struct seq_file *m)
  352. {
  353. gpu->funcs->pm_resume(gpu);
  354. seq_printf(m, "status: %08x\n",
  355. gpu_read(gpu, REG_A4XX_RBBM_STATUS));
  356. gpu->funcs->pm_suspend(gpu);
  357. adreno_show(gpu, m);
  358. }
  359. #endif
  360. /* Register offset defines for A4XX, in order of enum adreno_regs */
  361. static const unsigned int a4xx_register_offsets[REG_ADRENO_REGISTER_MAX] = {
  362. REG_ADRENO_DEFINE(REG_ADRENO_CP_DEBUG, REG_A4XX_CP_DEBUG),
  363. REG_ADRENO_DEFINE(REG_ADRENO_CP_ME_RAM_WADDR, REG_A4XX_CP_ME_RAM_WADDR),
  364. REG_ADRENO_DEFINE(REG_ADRENO_CP_ME_RAM_DATA, REG_A4XX_CP_ME_RAM_DATA),
  365. REG_ADRENO_DEFINE(REG_ADRENO_CP_PFP_UCODE_DATA,
  366. REG_A4XX_CP_PFP_UCODE_DATA),
  367. REG_ADRENO_DEFINE(REG_ADRENO_CP_PFP_UCODE_ADDR,
  368. REG_A4XX_CP_PFP_UCODE_ADDR),
  369. REG_ADRENO_DEFINE(REG_ADRENO_CP_WFI_PEND_CTR, REG_A4XX_CP_WFI_PEND_CTR),
  370. REG_ADRENO_DEFINE(REG_ADRENO_CP_RB_BASE, REG_A4XX_CP_RB_BASE),
  371. REG_ADRENO_DEFINE(REG_ADRENO_CP_RB_RPTR_ADDR, REG_A4XX_CP_RB_RPTR_ADDR),
  372. REG_ADRENO_DEFINE(REG_ADRENO_CP_RB_RPTR, REG_A4XX_CP_RB_RPTR),
  373. REG_ADRENO_DEFINE(REG_ADRENO_CP_RB_WPTR, REG_A4XX_CP_RB_WPTR),
  374. REG_ADRENO_DEFINE(REG_ADRENO_CP_PROTECT_CTRL, REG_A4XX_CP_PROTECT_CTRL),
  375. REG_ADRENO_DEFINE(REG_ADRENO_CP_ME_CNTL, REG_A4XX_CP_ME_CNTL),
  376. REG_ADRENO_DEFINE(REG_ADRENO_CP_RB_CNTL, REG_A4XX_CP_RB_CNTL),
  377. REG_ADRENO_DEFINE(REG_ADRENO_CP_IB1_BASE, REG_A4XX_CP_IB1_BASE),
  378. REG_ADRENO_DEFINE(REG_ADRENO_CP_IB1_BUFSZ, REG_A4XX_CP_IB1_BUFSZ),
  379. REG_ADRENO_DEFINE(REG_ADRENO_CP_IB2_BASE, REG_A4XX_CP_IB2_BASE),
  380. REG_ADRENO_DEFINE(REG_ADRENO_CP_IB2_BUFSZ, REG_A4XX_CP_IB2_BUFSZ),
  381. REG_ADRENO_DEFINE(REG_ADRENO_CP_TIMESTAMP, REG_AXXX_CP_SCRATCH_REG0),
  382. REG_ADRENO_DEFINE(REG_ADRENO_CP_ME_RAM_RADDR, REG_A4XX_CP_ME_RAM_RADDR),
  383. REG_ADRENO_DEFINE(REG_ADRENO_CP_ROQ_ADDR, REG_A4XX_CP_ROQ_ADDR),
  384. REG_ADRENO_DEFINE(REG_ADRENO_CP_ROQ_DATA, REG_A4XX_CP_ROQ_DATA),
  385. REG_ADRENO_DEFINE(REG_ADRENO_CP_MERCIU_ADDR, REG_A4XX_CP_MERCIU_ADDR),
  386. REG_ADRENO_DEFINE(REG_ADRENO_CP_MERCIU_DATA, REG_A4XX_CP_MERCIU_DATA),
  387. REG_ADRENO_DEFINE(REG_ADRENO_CP_MERCIU_DATA2, REG_A4XX_CP_MERCIU_DATA2),
  388. REG_ADRENO_DEFINE(REG_ADRENO_CP_MEQ_ADDR, REG_A4XX_CP_MEQ_ADDR),
  389. REG_ADRENO_DEFINE(REG_ADRENO_CP_MEQ_DATA, REG_A4XX_CP_MEQ_DATA),
  390. REG_ADRENO_DEFINE(REG_ADRENO_CP_HW_FAULT, REG_A4XX_CP_HW_FAULT),
  391. REG_ADRENO_DEFINE(REG_ADRENO_CP_PROTECT_STATUS,
  392. REG_A4XX_CP_PROTECT_STATUS),
  393. REG_ADRENO_DEFINE(REG_ADRENO_SCRATCH_ADDR, REG_A4XX_CP_SCRATCH_ADDR),
  394. REG_ADRENO_DEFINE(REG_ADRENO_SCRATCH_UMSK, REG_A4XX_CP_SCRATCH_UMASK),
  395. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_STATUS, REG_A4XX_RBBM_STATUS),
  396. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_PERFCTR_CTL,
  397. REG_A4XX_RBBM_PERFCTR_CTL),
  398. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_PERFCTR_LOAD_CMD0,
  399. REG_A4XX_RBBM_PERFCTR_LOAD_CMD0),
  400. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_PERFCTR_LOAD_CMD1,
  401. REG_A4XX_RBBM_PERFCTR_LOAD_CMD1),
  402. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_PERFCTR_LOAD_CMD2,
  403. REG_A4XX_RBBM_PERFCTR_LOAD_CMD2),
  404. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_PERFCTR_PWR_1_LO,
  405. REG_A4XX_RBBM_PERFCTR_PWR_1_LO),
  406. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_INT_0_MASK, REG_A4XX_RBBM_INT_0_MASK),
  407. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_INT_0_STATUS,
  408. REG_A4XX_RBBM_INT_0_STATUS),
  409. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_AHB_ERROR_STATUS,
  410. REG_A4XX_RBBM_AHB_ERROR_STATUS),
  411. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_AHB_CMD, REG_A4XX_RBBM_AHB_CMD),
  412. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_CLOCK_CTL, REG_A4XX_RBBM_CLOCK_CTL),
  413. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_AHB_ME_SPLIT_STATUS,
  414. REG_A4XX_RBBM_AHB_ME_SPLIT_STATUS),
  415. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_AHB_PFP_SPLIT_STATUS,
  416. REG_A4XX_RBBM_AHB_PFP_SPLIT_STATUS),
  417. REG_ADRENO_DEFINE(REG_ADRENO_VPC_DEBUG_RAM_SEL,
  418. REG_A4XX_VPC_DEBUG_RAM_SEL),
  419. REG_ADRENO_DEFINE(REG_ADRENO_VPC_DEBUG_RAM_READ,
  420. REG_A4XX_VPC_DEBUG_RAM_READ),
  421. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_INT_CLEAR_CMD,
  422. REG_A4XX_RBBM_INT_CLEAR_CMD),
  423. REG_ADRENO_DEFINE(REG_ADRENO_VSC_SIZE_ADDRESS,
  424. REG_A4XX_VSC_SIZE_ADDRESS),
  425. REG_ADRENO_DEFINE(REG_ADRENO_VFD_CONTROL_0, REG_A4XX_VFD_CONTROL_0),
  426. REG_ADRENO_DEFINE(REG_ADRENO_SP_VS_PVT_MEM_ADDR_REG,
  427. REG_A4XX_SP_VS_PVT_MEM_ADDR),
  428. REG_ADRENO_DEFINE(REG_ADRENO_SP_FS_PVT_MEM_ADDR_REG,
  429. REG_A4XX_SP_FS_PVT_MEM_ADDR),
  430. REG_ADRENO_DEFINE(REG_ADRENO_SP_VS_OBJ_START_REG,
  431. REG_A4XX_SP_VS_OBJ_START),
  432. REG_ADRENO_DEFINE(REG_ADRENO_SP_FS_OBJ_START_REG,
  433. REG_A4XX_SP_FS_OBJ_START),
  434. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_RBBM_CTL, REG_A4XX_RBBM_RBBM_CTL),
  435. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_SW_RESET_CMD,
  436. REG_A4XX_RBBM_SW_RESET_CMD),
  437. REG_ADRENO_DEFINE(REG_ADRENO_UCHE_INVALIDATE0,
  438. REG_A4XX_UCHE_INVALIDATE0),
  439. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_PERFCTR_LOAD_VALUE_LO,
  440. REG_A4XX_RBBM_PERFCTR_LOAD_VALUE_LO),
  441. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_PERFCTR_LOAD_VALUE_HI,
  442. REG_A4XX_RBBM_PERFCTR_LOAD_VALUE_HI),
  443. };
  444. static void a4xx_dump(struct msm_gpu *gpu)
  445. {
  446. printk("status: %08x\n",
  447. gpu_read(gpu, REG_A4XX_RBBM_STATUS));
  448. adreno_dump(gpu);
  449. }
  450. static const struct adreno_gpu_funcs funcs = {
  451. .base = {
  452. .get_param = adreno_get_param,
  453. .hw_init = a4xx_hw_init,
  454. .pm_suspend = msm_gpu_pm_suspend,
  455. .pm_resume = msm_gpu_pm_resume,
  456. .recover = a4xx_recover,
  457. .last_fence = adreno_last_fence,
  458. .submit = adreno_submit,
  459. .flush = adreno_flush,
  460. .idle = a4xx_idle,
  461. .irq = a4xx_irq,
  462. .destroy = a4xx_destroy,
  463. #ifdef CONFIG_DEBUG_FS
  464. .show = a4xx_show,
  465. #endif
  466. },
  467. };
  468. struct msm_gpu *a4xx_gpu_init(struct drm_device *dev)
  469. {
  470. struct a4xx_gpu *a4xx_gpu = NULL;
  471. struct adreno_gpu *adreno_gpu;
  472. struct msm_gpu *gpu;
  473. struct msm_drm_private *priv = dev->dev_private;
  474. struct platform_device *pdev = priv->gpu_pdev;
  475. int ret;
  476. if (!pdev) {
  477. dev_err(dev->dev, "no a4xx device\n");
  478. ret = -ENXIO;
  479. goto fail;
  480. }
  481. a4xx_gpu = kzalloc(sizeof(*a4xx_gpu), GFP_KERNEL);
  482. if (!a4xx_gpu) {
  483. ret = -ENOMEM;
  484. goto fail;
  485. }
  486. adreno_gpu = &a4xx_gpu->base;
  487. gpu = &adreno_gpu->base;
  488. a4xx_gpu->pdev = pdev;
  489. gpu->perfcntrs = NULL;
  490. gpu->num_perfcntrs = 0;
  491. adreno_gpu->registers = a4xx_registers;
  492. adreno_gpu->reg_offsets = a4xx_register_offsets;
  493. ret = adreno_gpu_init(dev, pdev, adreno_gpu, &funcs);
  494. if (ret)
  495. goto fail;
  496. /* if needed, allocate gmem: */
  497. if (adreno_is_a4xx(adreno_gpu)) {
  498. #ifdef CONFIG_MSM_OCMEM
  499. /* TODO this is different/missing upstream: */
  500. struct ocmem_buf *ocmem_hdl =
  501. ocmem_allocate(OCMEM_GRAPHICS, adreno_gpu->gmem);
  502. a4xx_gpu->ocmem_hdl = ocmem_hdl;
  503. a4xx_gpu->ocmem_base = ocmem_hdl->addr;
  504. adreno_gpu->gmem = ocmem_hdl->len;
  505. DBG("using %dK of OCMEM at 0x%08x", adreno_gpu->gmem / 1024,
  506. a4xx_gpu->ocmem_base);
  507. #endif
  508. }
  509. if (!gpu->mmu) {
  510. /* TODO we think it is possible to configure the GPU to
  511. * restrict access to VRAM carveout. But the required
  512. * registers are unknown. For now just bail out and
  513. * limp along with just modesetting. If it turns out
  514. * to not be possible to restrict access, then we must
  515. * implement a cmdstream validator.
  516. */
  517. dev_err(dev->dev, "No memory protection without IOMMU\n");
  518. ret = -ENXIO;
  519. goto fail;
  520. }
  521. return gpu;
  522. fail:
  523. if (a4xx_gpu)
  524. a4xx_destroy(&a4xx_gpu->base.base);
  525. return ERR_PTR(ret);
  526. }