a3xx_gpu.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. /*
  2. * Copyright (C) 2013 Red Hat
  3. * Author: Rob Clark <robdclark@gmail.com>
  4. *
  5. * Copyright (c) 2014 The Linux Foundation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifdef CONFIG_MSM_OCMEM
  20. # include <mach/ocmem.h>
  21. #endif
  22. #include "a3xx_gpu.h"
  23. #define A3XX_INT0_MASK \
  24. (A3XX_INT0_RBBM_AHB_ERROR | \
  25. A3XX_INT0_RBBM_ATB_BUS_OVERFLOW | \
  26. A3XX_INT0_CP_T0_PACKET_IN_IB | \
  27. A3XX_INT0_CP_OPCODE_ERROR | \
  28. A3XX_INT0_CP_RESERVED_BIT_ERROR | \
  29. A3XX_INT0_CP_HW_FAULT | \
  30. A3XX_INT0_CP_IB1_INT | \
  31. A3XX_INT0_CP_IB2_INT | \
  32. A3XX_INT0_CP_RB_INT | \
  33. A3XX_INT0_CP_REG_PROTECT_FAULT | \
  34. A3XX_INT0_CP_AHB_ERROR_HALT | \
  35. A3XX_INT0_UCHE_OOB_ACCESS)
  36. extern bool hang_debug;
  37. static void a3xx_dump(struct msm_gpu *gpu);
  38. static void a3xx_me_init(struct msm_gpu *gpu)
  39. {
  40. struct msm_ringbuffer *ring = gpu->rb;
  41. OUT_PKT3(ring, CP_ME_INIT, 17);
  42. OUT_RING(ring, 0x000003f7);
  43. OUT_RING(ring, 0x00000000);
  44. OUT_RING(ring, 0x00000000);
  45. OUT_RING(ring, 0x00000000);
  46. OUT_RING(ring, 0x00000080);
  47. OUT_RING(ring, 0x00000100);
  48. OUT_RING(ring, 0x00000180);
  49. OUT_RING(ring, 0x00006600);
  50. OUT_RING(ring, 0x00000150);
  51. OUT_RING(ring, 0x0000014e);
  52. OUT_RING(ring, 0x00000154);
  53. OUT_RING(ring, 0x00000001);
  54. OUT_RING(ring, 0x00000000);
  55. OUT_RING(ring, 0x00000000);
  56. OUT_RING(ring, 0x00000000);
  57. OUT_RING(ring, 0x00000000);
  58. OUT_RING(ring, 0x00000000);
  59. gpu->funcs->flush(gpu);
  60. gpu->funcs->idle(gpu);
  61. }
  62. static int a3xx_hw_init(struct msm_gpu *gpu)
  63. {
  64. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  65. struct a3xx_gpu *a3xx_gpu = to_a3xx_gpu(adreno_gpu);
  66. uint32_t *ptr, len;
  67. int i, ret;
  68. DBG("%s", gpu->name);
  69. if (adreno_is_a305(adreno_gpu)) {
  70. /* Set up 16 deep read/write request queues: */
  71. gpu_write(gpu, REG_A3XX_VBIF_IN_RD_LIM_CONF0, 0x10101010);
  72. gpu_write(gpu, REG_A3XX_VBIF_IN_RD_LIM_CONF1, 0x10101010);
  73. gpu_write(gpu, REG_A3XX_VBIF_OUT_RD_LIM_CONF0, 0x10101010);
  74. gpu_write(gpu, REG_A3XX_VBIF_OUT_WR_LIM_CONF0, 0x10101010);
  75. gpu_write(gpu, REG_A3XX_VBIF_DDR_OUT_MAX_BURST, 0x0000303);
  76. gpu_write(gpu, REG_A3XX_VBIF_IN_WR_LIM_CONF0, 0x10101010);
  77. gpu_write(gpu, REG_A3XX_VBIF_IN_WR_LIM_CONF1, 0x10101010);
  78. /* Enable WR-REQ: */
  79. gpu_write(gpu, REG_A3XX_VBIF_GATE_OFF_WRREQ_EN, 0x0000ff);
  80. /* Set up round robin arbitration between both AXI ports: */
  81. gpu_write(gpu, REG_A3XX_VBIF_ARB_CTL, 0x00000030);
  82. /* Set up AOOO: */
  83. gpu_write(gpu, REG_A3XX_VBIF_OUT_AXI_AOOO_EN, 0x0000003c);
  84. gpu_write(gpu, REG_A3XX_VBIF_OUT_AXI_AOOO, 0x003c003c);
  85. } else if (adreno_is_a306(adreno_gpu)) {
  86. gpu_write(gpu, REG_A3XX_VBIF_ROUND_ROBIN_QOS_ARB, 0x0003);
  87. gpu_write(gpu, REG_A3XX_VBIF_OUT_RD_LIM_CONF0, 0x0000000a);
  88. gpu_write(gpu, REG_A3XX_VBIF_OUT_WR_LIM_CONF0, 0x0000000a);
  89. } else if (adreno_is_a320(adreno_gpu)) {
  90. /* Set up 16 deep read/write request queues: */
  91. gpu_write(gpu, REG_A3XX_VBIF_IN_RD_LIM_CONF0, 0x10101010);
  92. gpu_write(gpu, REG_A3XX_VBIF_IN_RD_LIM_CONF1, 0x10101010);
  93. gpu_write(gpu, REG_A3XX_VBIF_OUT_RD_LIM_CONF0, 0x10101010);
  94. gpu_write(gpu, REG_A3XX_VBIF_OUT_WR_LIM_CONF0, 0x10101010);
  95. gpu_write(gpu, REG_A3XX_VBIF_DDR_OUT_MAX_BURST, 0x0000303);
  96. gpu_write(gpu, REG_A3XX_VBIF_IN_WR_LIM_CONF0, 0x10101010);
  97. gpu_write(gpu, REG_A3XX_VBIF_IN_WR_LIM_CONF1, 0x10101010);
  98. /* Enable WR-REQ: */
  99. gpu_write(gpu, REG_A3XX_VBIF_GATE_OFF_WRREQ_EN, 0x0000ff);
  100. /* Set up round robin arbitration between both AXI ports: */
  101. gpu_write(gpu, REG_A3XX_VBIF_ARB_CTL, 0x00000030);
  102. /* Set up AOOO: */
  103. gpu_write(gpu, REG_A3XX_VBIF_OUT_AXI_AOOO_EN, 0x0000003c);
  104. gpu_write(gpu, REG_A3XX_VBIF_OUT_AXI_AOOO, 0x003c003c);
  105. /* Enable 1K sort: */
  106. gpu_write(gpu, REG_A3XX_VBIF_ABIT_SORT, 0x000000ff);
  107. gpu_write(gpu, REG_A3XX_VBIF_ABIT_SORT_CONF, 0x000000a4);
  108. } else if (adreno_is_a330v2(adreno_gpu)) {
  109. /*
  110. * Most of the VBIF registers on 8974v2 have the correct
  111. * values at power on, so we won't modify those if we don't
  112. * need to
  113. */
  114. /* Enable 1k sort: */
  115. gpu_write(gpu, REG_A3XX_VBIF_ABIT_SORT, 0x0001003f);
  116. gpu_write(gpu, REG_A3XX_VBIF_ABIT_SORT_CONF, 0x000000a4);
  117. /* Enable WR-REQ: */
  118. gpu_write(gpu, REG_A3XX_VBIF_GATE_OFF_WRREQ_EN, 0x00003f);
  119. gpu_write(gpu, REG_A3XX_VBIF_DDR_OUT_MAX_BURST, 0x0000303);
  120. /* Set up VBIF_ROUND_ROBIN_QOS_ARB: */
  121. gpu_write(gpu, REG_A3XX_VBIF_ROUND_ROBIN_QOS_ARB, 0x0003);
  122. } else if (adreno_is_a330(adreno_gpu)) {
  123. /* Set up 16 deep read/write request queues: */
  124. gpu_write(gpu, REG_A3XX_VBIF_IN_RD_LIM_CONF0, 0x18181818);
  125. gpu_write(gpu, REG_A3XX_VBIF_IN_RD_LIM_CONF1, 0x18181818);
  126. gpu_write(gpu, REG_A3XX_VBIF_OUT_RD_LIM_CONF0, 0x18181818);
  127. gpu_write(gpu, REG_A3XX_VBIF_OUT_WR_LIM_CONF0, 0x18181818);
  128. gpu_write(gpu, REG_A3XX_VBIF_DDR_OUT_MAX_BURST, 0x0000303);
  129. gpu_write(gpu, REG_A3XX_VBIF_IN_WR_LIM_CONF0, 0x18181818);
  130. gpu_write(gpu, REG_A3XX_VBIF_IN_WR_LIM_CONF1, 0x18181818);
  131. /* Enable WR-REQ: */
  132. gpu_write(gpu, REG_A3XX_VBIF_GATE_OFF_WRREQ_EN, 0x00003f);
  133. /* Set up round robin arbitration between both AXI ports: */
  134. gpu_write(gpu, REG_A3XX_VBIF_ARB_CTL, 0x00000030);
  135. /* Set up VBIF_ROUND_ROBIN_QOS_ARB: */
  136. gpu_write(gpu, REG_A3XX_VBIF_ROUND_ROBIN_QOS_ARB, 0x0001);
  137. /* Set up AOOO: */
  138. gpu_write(gpu, REG_A3XX_VBIF_OUT_AXI_AOOO_EN, 0x0000003f);
  139. gpu_write(gpu, REG_A3XX_VBIF_OUT_AXI_AOOO, 0x003f003f);
  140. /* Enable 1K sort: */
  141. gpu_write(gpu, REG_A3XX_VBIF_ABIT_SORT, 0x0001003f);
  142. gpu_write(gpu, REG_A3XX_VBIF_ABIT_SORT_CONF, 0x000000a4);
  143. /* Disable VBIF clock gating. This is to enable AXI running
  144. * higher frequency than GPU:
  145. */
  146. gpu_write(gpu, REG_A3XX_VBIF_CLKON, 0x00000001);
  147. } else {
  148. BUG();
  149. }
  150. /* Make all blocks contribute to the GPU BUSY perf counter: */
  151. gpu_write(gpu, REG_A3XX_RBBM_GPU_BUSY_MASKED, 0xffffffff);
  152. /* Tune the hystersis counters for SP and CP idle detection: */
  153. gpu_write(gpu, REG_A3XX_RBBM_SP_HYST_CNT, 0x10);
  154. gpu_write(gpu, REG_A3XX_RBBM_WAIT_IDLE_CLOCKS_CTL, 0x10);
  155. /* Enable the RBBM error reporting bits. This lets us get
  156. * useful information on failure:
  157. */
  158. gpu_write(gpu, REG_A3XX_RBBM_AHB_CTL0, 0x00000001);
  159. /* Enable AHB error reporting: */
  160. gpu_write(gpu, REG_A3XX_RBBM_AHB_CTL1, 0xa6ffffff);
  161. /* Turn on the power counters: */
  162. gpu_write(gpu, REG_A3XX_RBBM_RBBM_CTL, 0x00030000);
  163. /* Turn on hang detection - this spews a lot of useful information
  164. * into the RBBM registers on a hang:
  165. */
  166. gpu_write(gpu, REG_A3XX_RBBM_INTERFACE_HANG_INT_CTL, 0x00010fff);
  167. /* Enable 64-byte cacheline size. HW Default is 32-byte (0x000000E0): */
  168. gpu_write(gpu, REG_A3XX_UCHE_CACHE_MODE_CONTROL_REG, 0x00000001);
  169. /* Enable Clock gating: */
  170. if (adreno_is_a306(adreno_gpu))
  171. gpu_write(gpu, REG_A3XX_RBBM_CLOCK_CTL, 0xaaaaaaaa);
  172. else if (adreno_is_a320(adreno_gpu))
  173. gpu_write(gpu, REG_A3XX_RBBM_CLOCK_CTL, 0xbfffffff);
  174. else if (adreno_is_a330v2(adreno_gpu))
  175. gpu_write(gpu, REG_A3XX_RBBM_CLOCK_CTL, 0xaaaaaaaa);
  176. else if (adreno_is_a330(adreno_gpu))
  177. gpu_write(gpu, REG_A3XX_RBBM_CLOCK_CTL, 0xbffcffff);
  178. if (adreno_is_a330v2(adreno_gpu))
  179. gpu_write(gpu, REG_A3XX_RBBM_GPR0_CTL, 0x05515455);
  180. else if (adreno_is_a330(adreno_gpu))
  181. gpu_write(gpu, REG_A3XX_RBBM_GPR0_CTL, 0x00000000);
  182. /* Set the OCMEM base address for A330, etc */
  183. if (a3xx_gpu->ocmem_hdl) {
  184. gpu_write(gpu, REG_A3XX_RB_GMEM_BASE_ADDR,
  185. (unsigned int)(a3xx_gpu->ocmem_base >> 14));
  186. }
  187. /* Turn on performance counters: */
  188. gpu_write(gpu, REG_A3XX_RBBM_PERFCTR_CTL, 0x01);
  189. /* Enable the perfcntrs that we use.. */
  190. for (i = 0; i < gpu->num_perfcntrs; i++) {
  191. const struct msm_gpu_perfcntr *perfcntr = &gpu->perfcntrs[i];
  192. gpu_write(gpu, perfcntr->select_reg, perfcntr->select_val);
  193. }
  194. gpu_write(gpu, REG_A3XX_RBBM_INT_0_MASK, A3XX_INT0_MASK);
  195. ret = adreno_hw_init(gpu);
  196. if (ret)
  197. return ret;
  198. /* setup access protection: */
  199. gpu_write(gpu, REG_A3XX_CP_PROTECT_CTRL, 0x00000007);
  200. /* RBBM registers */
  201. gpu_write(gpu, REG_A3XX_CP_PROTECT(0), 0x63000040);
  202. gpu_write(gpu, REG_A3XX_CP_PROTECT(1), 0x62000080);
  203. gpu_write(gpu, REG_A3XX_CP_PROTECT(2), 0x600000cc);
  204. gpu_write(gpu, REG_A3XX_CP_PROTECT(3), 0x60000108);
  205. gpu_write(gpu, REG_A3XX_CP_PROTECT(4), 0x64000140);
  206. gpu_write(gpu, REG_A3XX_CP_PROTECT(5), 0x66000400);
  207. /* CP registers */
  208. gpu_write(gpu, REG_A3XX_CP_PROTECT(6), 0x65000700);
  209. gpu_write(gpu, REG_A3XX_CP_PROTECT(7), 0x610007d8);
  210. gpu_write(gpu, REG_A3XX_CP_PROTECT(8), 0x620007e0);
  211. gpu_write(gpu, REG_A3XX_CP_PROTECT(9), 0x61001178);
  212. gpu_write(gpu, REG_A3XX_CP_PROTECT(10), 0x64001180);
  213. /* RB registers */
  214. gpu_write(gpu, REG_A3XX_CP_PROTECT(11), 0x60003300);
  215. /* VBIF registers */
  216. gpu_write(gpu, REG_A3XX_CP_PROTECT(12), 0x6b00c000);
  217. /* NOTE: PM4/micro-engine firmware registers look to be the same
  218. * for a2xx and a3xx.. we could possibly push that part down to
  219. * adreno_gpu base class. Or push both PM4 and PFP but
  220. * parameterize the pfp ucode addr/data registers..
  221. */
  222. /* Load PM4: */
  223. ptr = (uint32_t *)(adreno_gpu->pm4->data);
  224. len = adreno_gpu->pm4->size / 4;
  225. DBG("loading PM4 ucode version: %x", ptr[1]);
  226. gpu_write(gpu, REG_AXXX_CP_DEBUG,
  227. AXXX_CP_DEBUG_DYNAMIC_CLK_DISABLE |
  228. AXXX_CP_DEBUG_MIU_128BIT_WRITE_ENABLE);
  229. gpu_write(gpu, REG_AXXX_CP_ME_RAM_WADDR, 0);
  230. for (i = 1; i < len; i++)
  231. gpu_write(gpu, REG_AXXX_CP_ME_RAM_DATA, ptr[i]);
  232. /* Load PFP: */
  233. ptr = (uint32_t *)(adreno_gpu->pfp->data);
  234. len = adreno_gpu->pfp->size / 4;
  235. DBG("loading PFP ucode version: %x", ptr[5]);
  236. gpu_write(gpu, REG_A3XX_CP_PFP_UCODE_ADDR, 0);
  237. for (i = 1; i < len; i++)
  238. gpu_write(gpu, REG_A3XX_CP_PFP_UCODE_DATA, ptr[i]);
  239. /* CP ROQ queue sizes (bytes) - RB:16, ST:16, IB1:32, IB2:64 */
  240. if (adreno_is_a305(adreno_gpu) || adreno_is_a306(adreno_gpu) ||
  241. adreno_is_a320(adreno_gpu)) {
  242. gpu_write(gpu, REG_AXXX_CP_QUEUE_THRESHOLDS,
  243. AXXX_CP_QUEUE_THRESHOLDS_CSQ_IB1_START(2) |
  244. AXXX_CP_QUEUE_THRESHOLDS_CSQ_IB2_START(6) |
  245. AXXX_CP_QUEUE_THRESHOLDS_CSQ_ST_START(14));
  246. } else if (adreno_is_a330(adreno_gpu)) {
  247. /* NOTE: this (value take from downstream android driver)
  248. * includes some bits outside of the known bitfields. But
  249. * A330 has this "MERCIU queue" thing too, which might
  250. * explain a new bitfield or reshuffling:
  251. */
  252. gpu_write(gpu, REG_AXXX_CP_QUEUE_THRESHOLDS, 0x003e2008);
  253. }
  254. /* clear ME_HALT to start micro engine */
  255. gpu_write(gpu, REG_AXXX_CP_ME_CNTL, 0);
  256. a3xx_me_init(gpu);
  257. return 0;
  258. }
  259. static void a3xx_recover(struct msm_gpu *gpu)
  260. {
  261. adreno_dump_info(gpu);
  262. /* dump registers before resetting gpu, if enabled: */
  263. if (hang_debug)
  264. a3xx_dump(gpu);
  265. gpu_write(gpu, REG_A3XX_RBBM_SW_RESET_CMD, 1);
  266. gpu_read(gpu, REG_A3XX_RBBM_SW_RESET_CMD);
  267. gpu_write(gpu, REG_A3XX_RBBM_SW_RESET_CMD, 0);
  268. adreno_recover(gpu);
  269. }
  270. static void a3xx_destroy(struct msm_gpu *gpu)
  271. {
  272. struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
  273. struct a3xx_gpu *a3xx_gpu = to_a3xx_gpu(adreno_gpu);
  274. DBG("%s", gpu->name);
  275. adreno_gpu_cleanup(adreno_gpu);
  276. #ifdef CONFIG_MSM_OCMEM
  277. if (a3xx_gpu->ocmem_base)
  278. ocmem_free(OCMEM_GRAPHICS, a3xx_gpu->ocmem_hdl);
  279. #endif
  280. kfree(a3xx_gpu);
  281. }
  282. static void a3xx_idle(struct msm_gpu *gpu)
  283. {
  284. /* wait for ringbuffer to drain: */
  285. adreno_idle(gpu);
  286. /* then wait for GPU to finish: */
  287. if (spin_until(!(gpu_read(gpu, REG_A3XX_RBBM_STATUS) &
  288. A3XX_RBBM_STATUS_GPU_BUSY)))
  289. DRM_ERROR("%s: timeout waiting for GPU to idle!\n", gpu->name);
  290. /* TODO maybe we need to reset GPU here to recover from hang? */
  291. }
  292. static irqreturn_t a3xx_irq(struct msm_gpu *gpu)
  293. {
  294. uint32_t status;
  295. status = gpu_read(gpu, REG_A3XX_RBBM_INT_0_STATUS);
  296. DBG("%s: %08x", gpu->name, status);
  297. // TODO
  298. gpu_write(gpu, REG_A3XX_RBBM_INT_CLEAR_CMD, status);
  299. msm_gpu_retire(gpu);
  300. return IRQ_HANDLED;
  301. }
  302. static const unsigned int a3xx_registers[] = {
  303. 0x0000, 0x0002, 0x0010, 0x0012, 0x0018, 0x0018, 0x0020, 0x0027,
  304. 0x0029, 0x002b, 0x002e, 0x0033, 0x0040, 0x0042, 0x0050, 0x005c,
  305. 0x0060, 0x006c, 0x0080, 0x0082, 0x0084, 0x0088, 0x0090, 0x00e5,
  306. 0x00ea, 0x00ed, 0x0100, 0x0100, 0x0110, 0x0123, 0x01c0, 0x01c1,
  307. 0x01c3, 0x01c5, 0x01c7, 0x01c7, 0x01d5, 0x01d9, 0x01dc, 0x01dd,
  308. 0x01ea, 0x01ea, 0x01ee, 0x01f1, 0x01f5, 0x01f5, 0x01fc, 0x01ff,
  309. 0x0440, 0x0440, 0x0443, 0x0443, 0x0445, 0x0445, 0x044d, 0x044f,
  310. 0x0452, 0x0452, 0x0454, 0x046f, 0x047c, 0x047c, 0x047f, 0x047f,
  311. 0x0578, 0x057f, 0x0600, 0x0602, 0x0605, 0x0607, 0x060a, 0x060e,
  312. 0x0612, 0x0614, 0x0c01, 0x0c02, 0x0c06, 0x0c1d, 0x0c3d, 0x0c3f,
  313. 0x0c48, 0x0c4b, 0x0c80, 0x0c80, 0x0c88, 0x0c8b, 0x0ca0, 0x0cb7,
  314. 0x0cc0, 0x0cc1, 0x0cc6, 0x0cc7, 0x0ce4, 0x0ce5, 0x0e00, 0x0e05,
  315. 0x0e0c, 0x0e0c, 0x0e22, 0x0e23, 0x0e41, 0x0e45, 0x0e64, 0x0e65,
  316. 0x0e80, 0x0e82, 0x0e84, 0x0e89, 0x0ea0, 0x0ea1, 0x0ea4, 0x0ea7,
  317. 0x0ec4, 0x0ecb, 0x0ee0, 0x0ee0, 0x0f00, 0x0f01, 0x0f03, 0x0f09,
  318. 0x2040, 0x2040, 0x2044, 0x2044, 0x2048, 0x204d, 0x2068, 0x2069,
  319. 0x206c, 0x206d, 0x2070, 0x2070, 0x2072, 0x2072, 0x2074, 0x2075,
  320. 0x2079, 0x207a, 0x20c0, 0x20d3, 0x20e4, 0x20ef, 0x2100, 0x2109,
  321. 0x210c, 0x210c, 0x210e, 0x210e, 0x2110, 0x2111, 0x2114, 0x2115,
  322. 0x21e4, 0x21e4, 0x21ea, 0x21ea, 0x21ec, 0x21ed, 0x21f0, 0x21f0,
  323. 0x2200, 0x2212, 0x2214, 0x2217, 0x221a, 0x221a, 0x2240, 0x227e,
  324. 0x2280, 0x228b, 0x22c0, 0x22c0, 0x22c4, 0x22ce, 0x22d0, 0x22d8,
  325. 0x22df, 0x22e6, 0x22e8, 0x22e9, 0x22ec, 0x22ec, 0x22f0, 0x22f7,
  326. 0x22ff, 0x22ff, 0x2340, 0x2343, 0x2348, 0x2349, 0x2350, 0x2356,
  327. 0x2360, 0x2360, 0x2440, 0x2440, 0x2444, 0x2444, 0x2448, 0x244d,
  328. 0x2468, 0x2469, 0x246c, 0x246d, 0x2470, 0x2470, 0x2472, 0x2472,
  329. 0x2474, 0x2475, 0x2479, 0x247a, 0x24c0, 0x24d3, 0x24e4, 0x24ef,
  330. 0x2500, 0x2509, 0x250c, 0x250c, 0x250e, 0x250e, 0x2510, 0x2511,
  331. 0x2514, 0x2515, 0x25e4, 0x25e4, 0x25ea, 0x25ea, 0x25ec, 0x25ed,
  332. 0x25f0, 0x25f0, 0x2600, 0x2612, 0x2614, 0x2617, 0x261a, 0x261a,
  333. 0x2640, 0x267e, 0x2680, 0x268b, 0x26c0, 0x26c0, 0x26c4, 0x26ce,
  334. 0x26d0, 0x26d8, 0x26df, 0x26e6, 0x26e8, 0x26e9, 0x26ec, 0x26ec,
  335. 0x26f0, 0x26f7, 0x26ff, 0x26ff, 0x2740, 0x2743, 0x2748, 0x2749,
  336. 0x2750, 0x2756, 0x2760, 0x2760, 0x300c, 0x300e, 0x301c, 0x301d,
  337. 0x302a, 0x302a, 0x302c, 0x302d, 0x3030, 0x3031, 0x3034, 0x3036,
  338. 0x303c, 0x303c, 0x305e, 0x305f,
  339. ~0 /* sentinel */
  340. };
  341. #ifdef CONFIG_DEBUG_FS
  342. static void a3xx_show(struct msm_gpu *gpu, struct seq_file *m)
  343. {
  344. gpu->funcs->pm_resume(gpu);
  345. seq_printf(m, "status: %08x\n",
  346. gpu_read(gpu, REG_A3XX_RBBM_STATUS));
  347. gpu->funcs->pm_suspend(gpu);
  348. adreno_show(gpu, m);
  349. }
  350. #endif
  351. /* would be nice to not have to duplicate the _show() stuff with printk(): */
  352. static void a3xx_dump(struct msm_gpu *gpu)
  353. {
  354. printk("status: %08x\n",
  355. gpu_read(gpu, REG_A3XX_RBBM_STATUS));
  356. adreno_dump(gpu);
  357. }
  358. /* Register offset defines for A3XX */
  359. static const unsigned int a3xx_register_offsets[REG_ADRENO_REGISTER_MAX] = {
  360. REG_ADRENO_DEFINE(REG_ADRENO_CP_DEBUG, REG_AXXX_CP_DEBUG),
  361. REG_ADRENO_DEFINE(REG_ADRENO_CP_ME_RAM_WADDR, REG_AXXX_CP_ME_RAM_WADDR),
  362. REG_ADRENO_DEFINE(REG_ADRENO_CP_ME_RAM_DATA, REG_AXXX_CP_ME_RAM_DATA),
  363. REG_ADRENO_DEFINE(REG_ADRENO_CP_PFP_UCODE_DATA,
  364. REG_A3XX_CP_PFP_UCODE_DATA),
  365. REG_ADRENO_DEFINE(REG_ADRENO_CP_PFP_UCODE_ADDR,
  366. REG_A3XX_CP_PFP_UCODE_ADDR),
  367. REG_ADRENO_DEFINE(REG_ADRENO_CP_WFI_PEND_CTR, REG_A3XX_CP_WFI_PEND_CTR),
  368. REG_ADRENO_DEFINE(REG_ADRENO_CP_RB_BASE, REG_AXXX_CP_RB_BASE),
  369. REG_ADRENO_DEFINE(REG_ADRENO_CP_RB_RPTR_ADDR, REG_AXXX_CP_RB_RPTR_ADDR),
  370. REG_ADRENO_DEFINE(REG_ADRENO_CP_RB_RPTR, REG_AXXX_CP_RB_RPTR),
  371. REG_ADRENO_DEFINE(REG_ADRENO_CP_RB_WPTR, REG_AXXX_CP_RB_WPTR),
  372. REG_ADRENO_DEFINE(REG_ADRENO_CP_PROTECT_CTRL, REG_A3XX_CP_PROTECT_CTRL),
  373. REG_ADRENO_DEFINE(REG_ADRENO_CP_ME_CNTL, REG_AXXX_CP_ME_CNTL),
  374. REG_ADRENO_DEFINE(REG_ADRENO_CP_RB_CNTL, REG_AXXX_CP_RB_CNTL),
  375. REG_ADRENO_DEFINE(REG_ADRENO_CP_IB1_BASE, REG_AXXX_CP_IB1_BASE),
  376. REG_ADRENO_DEFINE(REG_ADRENO_CP_IB1_BUFSZ, REG_AXXX_CP_IB1_BUFSZ),
  377. REG_ADRENO_DEFINE(REG_ADRENO_CP_IB2_BASE, REG_AXXX_CP_IB2_BASE),
  378. REG_ADRENO_DEFINE(REG_ADRENO_CP_IB2_BUFSZ, REG_AXXX_CP_IB2_BUFSZ),
  379. REG_ADRENO_DEFINE(REG_ADRENO_CP_TIMESTAMP, REG_AXXX_CP_SCRATCH_REG0),
  380. REG_ADRENO_DEFINE(REG_ADRENO_CP_ME_RAM_RADDR, REG_AXXX_CP_ME_RAM_RADDR),
  381. REG_ADRENO_DEFINE(REG_ADRENO_SCRATCH_ADDR, REG_AXXX_SCRATCH_ADDR),
  382. REG_ADRENO_DEFINE(REG_ADRENO_SCRATCH_UMSK, REG_AXXX_SCRATCH_UMSK),
  383. REG_ADRENO_DEFINE(REG_ADRENO_CP_ROQ_ADDR, REG_A3XX_CP_ROQ_ADDR),
  384. REG_ADRENO_DEFINE(REG_ADRENO_CP_ROQ_DATA, REG_A3XX_CP_ROQ_DATA),
  385. REG_ADRENO_DEFINE(REG_ADRENO_CP_MERCIU_ADDR, REG_A3XX_CP_MERCIU_ADDR),
  386. REG_ADRENO_DEFINE(REG_ADRENO_CP_MERCIU_DATA, REG_A3XX_CP_MERCIU_DATA),
  387. REG_ADRENO_DEFINE(REG_ADRENO_CP_MERCIU_DATA2, REG_A3XX_CP_MERCIU_DATA2),
  388. REG_ADRENO_DEFINE(REG_ADRENO_CP_MEQ_ADDR, REG_A3XX_CP_MEQ_ADDR),
  389. REG_ADRENO_DEFINE(REG_ADRENO_CP_MEQ_DATA, REG_A3XX_CP_MEQ_DATA),
  390. REG_ADRENO_DEFINE(REG_ADRENO_CP_HW_FAULT, REG_A3XX_CP_HW_FAULT),
  391. REG_ADRENO_DEFINE(REG_ADRENO_CP_PROTECT_STATUS,
  392. REG_A3XX_CP_PROTECT_STATUS),
  393. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_STATUS, REG_A3XX_RBBM_STATUS),
  394. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_PERFCTR_CTL,
  395. REG_A3XX_RBBM_PERFCTR_CTL),
  396. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_PERFCTR_LOAD_CMD0,
  397. REG_A3XX_RBBM_PERFCTR_LOAD_CMD0),
  398. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_PERFCTR_LOAD_CMD1,
  399. REG_A3XX_RBBM_PERFCTR_LOAD_CMD1),
  400. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_PERFCTR_PWR_1_LO,
  401. REG_A3XX_RBBM_PERFCTR_PWR_1_LO),
  402. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_INT_0_MASK, REG_A3XX_RBBM_INT_0_MASK),
  403. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_INT_0_STATUS,
  404. REG_A3XX_RBBM_INT_0_STATUS),
  405. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_AHB_ERROR_STATUS,
  406. REG_A3XX_RBBM_AHB_ERROR_STATUS),
  407. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_AHB_CMD, REG_A3XX_RBBM_AHB_CMD),
  408. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_INT_CLEAR_CMD,
  409. REG_A3XX_RBBM_INT_CLEAR_CMD),
  410. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_CLOCK_CTL, REG_A3XX_RBBM_CLOCK_CTL),
  411. REG_ADRENO_DEFINE(REG_ADRENO_VPC_DEBUG_RAM_SEL,
  412. REG_A3XX_VPC_VPC_DEBUG_RAM_SEL),
  413. REG_ADRENO_DEFINE(REG_ADRENO_VPC_DEBUG_RAM_READ,
  414. REG_A3XX_VPC_VPC_DEBUG_RAM_READ),
  415. REG_ADRENO_DEFINE(REG_ADRENO_VSC_SIZE_ADDRESS,
  416. REG_A3XX_VSC_SIZE_ADDRESS),
  417. REG_ADRENO_DEFINE(REG_ADRENO_VFD_CONTROL_0, REG_A3XX_VFD_CONTROL_0),
  418. REG_ADRENO_DEFINE(REG_ADRENO_VFD_INDEX_MAX, REG_A3XX_VFD_INDEX_MAX),
  419. REG_ADRENO_DEFINE(REG_ADRENO_SP_VS_PVT_MEM_ADDR_REG,
  420. REG_A3XX_SP_VS_PVT_MEM_ADDR_REG),
  421. REG_ADRENO_DEFINE(REG_ADRENO_SP_FS_PVT_MEM_ADDR_REG,
  422. REG_A3XX_SP_FS_PVT_MEM_ADDR_REG),
  423. REG_ADRENO_DEFINE(REG_ADRENO_SP_VS_OBJ_START_REG,
  424. REG_A3XX_SP_VS_OBJ_START_REG),
  425. REG_ADRENO_DEFINE(REG_ADRENO_SP_FS_OBJ_START_REG,
  426. REG_A3XX_SP_FS_OBJ_START_REG),
  427. REG_ADRENO_DEFINE(REG_ADRENO_PA_SC_AA_CONFIG, REG_A3XX_PA_SC_AA_CONFIG),
  428. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_PM_OVERRIDE2,
  429. REG_A3XX_RBBM_PM_OVERRIDE2),
  430. REG_ADRENO_DEFINE(REG_ADRENO_SCRATCH_REG2, REG_AXXX_CP_SCRATCH_REG2),
  431. REG_ADRENO_DEFINE(REG_ADRENO_SQ_GPR_MANAGEMENT,
  432. REG_A3XX_SQ_GPR_MANAGEMENT),
  433. REG_ADRENO_DEFINE(REG_ADRENO_SQ_INST_STORE_MANAGMENT,
  434. REG_A3XX_SQ_INST_STORE_MANAGMENT),
  435. REG_ADRENO_DEFINE(REG_ADRENO_TP0_CHICKEN, REG_A3XX_TP0_CHICKEN),
  436. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_RBBM_CTL, REG_A3XX_RBBM_RBBM_CTL),
  437. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_SW_RESET_CMD,
  438. REG_A3XX_RBBM_SW_RESET_CMD),
  439. REG_ADRENO_DEFINE(REG_ADRENO_UCHE_INVALIDATE0,
  440. REG_A3XX_UCHE_CACHE_INVALIDATE0_REG),
  441. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_PERFCTR_LOAD_VALUE_LO,
  442. REG_A3XX_RBBM_PERFCTR_LOAD_VALUE_LO),
  443. REG_ADRENO_DEFINE(REG_ADRENO_RBBM_PERFCTR_LOAD_VALUE_HI,
  444. REG_A3XX_RBBM_PERFCTR_LOAD_VALUE_HI),
  445. };
  446. static const struct adreno_gpu_funcs funcs = {
  447. .base = {
  448. .get_param = adreno_get_param,
  449. .hw_init = a3xx_hw_init,
  450. .pm_suspend = msm_gpu_pm_suspend,
  451. .pm_resume = msm_gpu_pm_resume,
  452. .recover = a3xx_recover,
  453. .last_fence = adreno_last_fence,
  454. .submit = adreno_submit,
  455. .flush = adreno_flush,
  456. .idle = a3xx_idle,
  457. .irq = a3xx_irq,
  458. .destroy = a3xx_destroy,
  459. #ifdef CONFIG_DEBUG_FS
  460. .show = a3xx_show,
  461. #endif
  462. },
  463. };
  464. static const struct msm_gpu_perfcntr perfcntrs[] = {
  465. { REG_A3XX_SP_PERFCOUNTER6_SELECT, REG_A3XX_RBBM_PERFCTR_SP_6_LO,
  466. SP_ALU_ACTIVE_CYCLES, "ALUACTIVE" },
  467. { REG_A3XX_SP_PERFCOUNTER7_SELECT, REG_A3XX_RBBM_PERFCTR_SP_7_LO,
  468. SP_FS_FULL_ALU_INSTRUCTIONS, "ALUFULL" },
  469. };
  470. struct msm_gpu *a3xx_gpu_init(struct drm_device *dev)
  471. {
  472. struct a3xx_gpu *a3xx_gpu = NULL;
  473. struct adreno_gpu *adreno_gpu;
  474. struct msm_gpu *gpu;
  475. struct msm_drm_private *priv = dev->dev_private;
  476. struct platform_device *pdev = priv->gpu_pdev;
  477. int ret;
  478. if (!pdev) {
  479. dev_err(dev->dev, "no a3xx device\n");
  480. ret = -ENXIO;
  481. goto fail;
  482. }
  483. a3xx_gpu = kzalloc(sizeof(*a3xx_gpu), GFP_KERNEL);
  484. if (!a3xx_gpu) {
  485. ret = -ENOMEM;
  486. goto fail;
  487. }
  488. adreno_gpu = &a3xx_gpu->base;
  489. gpu = &adreno_gpu->base;
  490. a3xx_gpu->pdev = pdev;
  491. gpu->perfcntrs = perfcntrs;
  492. gpu->num_perfcntrs = ARRAY_SIZE(perfcntrs);
  493. adreno_gpu->registers = a3xx_registers;
  494. adreno_gpu->reg_offsets = a3xx_register_offsets;
  495. ret = adreno_gpu_init(dev, pdev, adreno_gpu, &funcs);
  496. if (ret)
  497. goto fail;
  498. /* if needed, allocate gmem: */
  499. if (adreno_is_a330(adreno_gpu)) {
  500. #ifdef CONFIG_MSM_OCMEM
  501. /* TODO this is different/missing upstream: */
  502. struct ocmem_buf *ocmem_hdl =
  503. ocmem_allocate(OCMEM_GRAPHICS, adreno_gpu->gmem);
  504. a3xx_gpu->ocmem_hdl = ocmem_hdl;
  505. a3xx_gpu->ocmem_base = ocmem_hdl->addr;
  506. adreno_gpu->gmem = ocmem_hdl->len;
  507. DBG("using %dK of OCMEM at 0x%08x", adreno_gpu->gmem / 1024,
  508. a3xx_gpu->ocmem_base);
  509. #endif
  510. }
  511. if (!gpu->mmu) {
  512. /* TODO we think it is possible to configure the GPU to
  513. * restrict access to VRAM carveout. But the required
  514. * registers are unknown. For now just bail out and
  515. * limp along with just modesetting. If it turns out
  516. * to not be possible to restrict access, then we must
  517. * implement a cmdstream validator.
  518. */
  519. dev_err(dev->dev, "No memory protection without IOMMU\n");
  520. ret = -ENXIO;
  521. goto fail;
  522. }
  523. return gpu;
  524. fail:
  525. if (a3xx_gpu)
  526. a3xx_destroy(&a3xx_gpu->base.base);
  527. return ERR_PTR(ret);
  528. }