etnaviv_buffer.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2014-2018 Etnaviv Project
  4. */
  5. #include <drm/drm_drv.h>
  6. #include "etnaviv_cmdbuf.h"
  7. #include "etnaviv_gpu.h"
  8. #include "etnaviv_gem.h"
  9. #include "etnaviv_mmu.h"
  10. #include "common.xml.h"
  11. #include "state.xml.h"
  12. #include "state_blt.xml.h"
  13. #include "state_hi.xml.h"
  14. #include "state_3d.xml.h"
  15. #include "cmdstream.xml.h"
  16. /*
  17. * Command Buffer helper:
  18. */
  19. static inline void OUT(struct etnaviv_cmdbuf *buffer, u32 data)
  20. {
  21. u32 *vaddr = (u32 *)buffer->vaddr;
  22. BUG_ON(buffer->user_size >= buffer->size);
  23. vaddr[buffer->user_size / 4] = data;
  24. buffer->user_size += 4;
  25. }
  26. static inline void CMD_LOAD_STATE(struct etnaviv_cmdbuf *buffer,
  27. u32 reg, u32 value)
  28. {
  29. u32 index = reg >> VIV_FE_LOAD_STATE_HEADER_OFFSET__SHR;
  30. buffer->user_size = ALIGN(buffer->user_size, 8);
  31. /* write a register via cmd stream */
  32. OUT(buffer, VIV_FE_LOAD_STATE_HEADER_OP_LOAD_STATE |
  33. VIV_FE_LOAD_STATE_HEADER_COUNT(1) |
  34. VIV_FE_LOAD_STATE_HEADER_OFFSET(index));
  35. OUT(buffer, value);
  36. }
  37. static inline void CMD_END(struct etnaviv_cmdbuf *buffer)
  38. {
  39. buffer->user_size = ALIGN(buffer->user_size, 8);
  40. OUT(buffer, VIV_FE_END_HEADER_OP_END);
  41. }
  42. static inline void CMD_WAIT(struct etnaviv_cmdbuf *buffer,
  43. unsigned int waitcycles)
  44. {
  45. buffer->user_size = ALIGN(buffer->user_size, 8);
  46. OUT(buffer, VIV_FE_WAIT_HEADER_OP_WAIT | waitcycles);
  47. }
  48. static inline void CMD_LINK(struct etnaviv_cmdbuf *buffer,
  49. u16 prefetch, u32 address)
  50. {
  51. buffer->user_size = ALIGN(buffer->user_size, 8);
  52. OUT(buffer, VIV_FE_LINK_HEADER_OP_LINK |
  53. VIV_FE_LINK_HEADER_PREFETCH(prefetch));
  54. OUT(buffer, address);
  55. }
  56. static inline void CMD_STALL(struct etnaviv_cmdbuf *buffer,
  57. u32 from, u32 to)
  58. {
  59. buffer->user_size = ALIGN(buffer->user_size, 8);
  60. OUT(buffer, VIV_FE_STALL_HEADER_OP_STALL);
  61. OUT(buffer, VIV_FE_STALL_TOKEN_FROM(from) | VIV_FE_STALL_TOKEN_TO(to));
  62. }
  63. static inline void CMD_SEM(struct etnaviv_cmdbuf *buffer, u32 from, u32 to)
  64. {
  65. CMD_LOAD_STATE(buffer, VIVS_GL_SEMAPHORE_TOKEN,
  66. VIVS_GL_SEMAPHORE_TOKEN_FROM(from) |
  67. VIVS_GL_SEMAPHORE_TOKEN_TO(to));
  68. }
  69. static void etnaviv_cmd_select_pipe(struct etnaviv_gpu *gpu,
  70. struct etnaviv_cmdbuf *buffer, u8 pipe)
  71. {
  72. u32 flush = 0;
  73. lockdep_assert_held(&gpu->lock);
  74. /*
  75. * This assumes that if we're switching to 2D, we're switching
  76. * away from 3D, and vice versa. Hence, if we're switching to
  77. * the 2D core, we need to flush the 3D depth and color caches,
  78. * otherwise we need to flush the 2D pixel engine cache.
  79. */
  80. if (gpu->exec_state == ETNA_PIPE_2D)
  81. flush = VIVS_GL_FLUSH_CACHE_PE2D;
  82. else if (gpu->exec_state == ETNA_PIPE_3D)
  83. flush = VIVS_GL_FLUSH_CACHE_DEPTH | VIVS_GL_FLUSH_CACHE_COLOR;
  84. CMD_LOAD_STATE(buffer, VIVS_GL_FLUSH_CACHE, flush);
  85. CMD_SEM(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE);
  86. CMD_STALL(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE);
  87. CMD_LOAD_STATE(buffer, VIVS_GL_PIPE_SELECT,
  88. VIVS_GL_PIPE_SELECT_PIPE(pipe));
  89. }
  90. static void etnaviv_buffer_dump(struct etnaviv_gpu *gpu,
  91. struct etnaviv_cmdbuf *buf, u32 off, u32 len)
  92. {
  93. u32 size = buf->size;
  94. u32 *ptr = buf->vaddr + off;
  95. dev_info(gpu->dev, "virt %p phys 0x%08x free 0x%08x\n",
  96. ptr, etnaviv_cmdbuf_get_va(buf,
  97. &gpu->mmu_context->cmdbuf_mapping) +
  98. off, size - len * 4 - off);
  99. print_hex_dump(KERN_INFO, "cmd ", DUMP_PREFIX_OFFSET, 16, 4,
  100. ptr, len * 4, 0);
  101. }
  102. /*
  103. * Safely replace the WAIT of a waitlink with a new command and argument.
  104. * The GPU may be executing this WAIT while we're modifying it, so we have
  105. * to write it in a specific order to avoid the GPU branching to somewhere
  106. * else. 'wl_offset' is the offset to the first byte of the WAIT command.
  107. */
  108. static void etnaviv_buffer_replace_wait(struct etnaviv_cmdbuf *buffer,
  109. unsigned int wl_offset, u32 cmd, u32 arg)
  110. {
  111. u32 *lw = buffer->vaddr + wl_offset;
  112. lw[1] = arg;
  113. mb();
  114. lw[0] = cmd;
  115. mb();
  116. }
  117. /*
  118. * Ensure that there is space in the command buffer to contiguously write
  119. * 'cmd_dwords' 64-bit words into the buffer, wrapping if necessary.
  120. */
  121. static u32 etnaviv_buffer_reserve(struct etnaviv_gpu *gpu,
  122. struct etnaviv_cmdbuf *buffer, unsigned int cmd_dwords)
  123. {
  124. if (buffer->user_size + cmd_dwords * sizeof(u64) > buffer->size)
  125. buffer->user_size = 0;
  126. return etnaviv_cmdbuf_get_va(buffer,
  127. &gpu->mmu_context->cmdbuf_mapping) +
  128. buffer->user_size;
  129. }
  130. u16 etnaviv_buffer_init(struct etnaviv_gpu *gpu)
  131. {
  132. struct etnaviv_cmdbuf *buffer = &gpu->buffer;
  133. lockdep_assert_held(&gpu->lock);
  134. /* initialize buffer */
  135. buffer->user_size = 0;
  136. CMD_WAIT(buffer, gpu->fe_waitcycles);
  137. CMD_LINK(buffer, 2,
  138. etnaviv_cmdbuf_get_va(buffer, &gpu->mmu_context->cmdbuf_mapping)
  139. + buffer->user_size - 4);
  140. return buffer->user_size / 8;
  141. }
  142. u16 etnaviv_buffer_config_mmuv2(struct etnaviv_gpu *gpu, u32 mtlb_addr, u32 safe_addr)
  143. {
  144. struct etnaviv_cmdbuf *buffer = &gpu->buffer;
  145. lockdep_assert_held(&gpu->lock);
  146. buffer->user_size = 0;
  147. if (gpu->identity.features & chipFeatures_PIPE_3D) {
  148. CMD_LOAD_STATE(buffer, VIVS_GL_PIPE_SELECT,
  149. VIVS_GL_PIPE_SELECT_PIPE(ETNA_PIPE_3D));
  150. CMD_LOAD_STATE(buffer, VIVS_MMUv2_CONFIGURATION,
  151. mtlb_addr | VIVS_MMUv2_CONFIGURATION_MODE_MODE4_K);
  152. CMD_LOAD_STATE(buffer, VIVS_MMUv2_SAFE_ADDRESS, safe_addr);
  153. CMD_SEM(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE);
  154. CMD_STALL(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE);
  155. }
  156. if (gpu->identity.features & chipFeatures_PIPE_2D) {
  157. CMD_LOAD_STATE(buffer, VIVS_GL_PIPE_SELECT,
  158. VIVS_GL_PIPE_SELECT_PIPE(ETNA_PIPE_2D));
  159. CMD_LOAD_STATE(buffer, VIVS_MMUv2_CONFIGURATION,
  160. mtlb_addr | VIVS_MMUv2_CONFIGURATION_MODE_MODE4_K);
  161. CMD_LOAD_STATE(buffer, VIVS_MMUv2_SAFE_ADDRESS, safe_addr);
  162. CMD_SEM(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE);
  163. CMD_STALL(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE);
  164. }
  165. CMD_END(buffer);
  166. buffer->user_size = ALIGN(buffer->user_size, 8);
  167. return buffer->user_size / 8;
  168. }
  169. u16 etnaviv_buffer_config_pta(struct etnaviv_gpu *gpu, unsigned short id)
  170. {
  171. struct etnaviv_cmdbuf *buffer = &gpu->buffer;
  172. lockdep_assert_held(&gpu->lock);
  173. buffer->user_size = 0;
  174. CMD_LOAD_STATE(buffer, VIVS_MMUv2_PTA_CONFIG,
  175. VIVS_MMUv2_PTA_CONFIG_INDEX(id));
  176. CMD_END(buffer);
  177. buffer->user_size = ALIGN(buffer->user_size, 8);
  178. return buffer->user_size / 8;
  179. }
  180. void etnaviv_buffer_end(struct etnaviv_gpu *gpu)
  181. {
  182. struct etnaviv_cmdbuf *buffer = &gpu->buffer;
  183. unsigned int waitlink_offset = buffer->user_size - 16;
  184. u32 link_target, flush = 0;
  185. bool has_blt = !!(gpu->identity.minor_features5 &
  186. chipMinorFeatures5_BLT_ENGINE);
  187. lockdep_assert_held(&gpu->lock);
  188. if (gpu->exec_state == ETNA_PIPE_2D)
  189. flush = VIVS_GL_FLUSH_CACHE_PE2D;
  190. else if (gpu->exec_state == ETNA_PIPE_3D)
  191. flush = VIVS_GL_FLUSH_CACHE_DEPTH |
  192. VIVS_GL_FLUSH_CACHE_COLOR |
  193. VIVS_GL_FLUSH_CACHE_TEXTURE |
  194. VIVS_GL_FLUSH_CACHE_TEXTUREVS |
  195. VIVS_GL_FLUSH_CACHE_SHADER_L2;
  196. if (flush) {
  197. unsigned int dwords = 7;
  198. if (has_blt)
  199. dwords += 10;
  200. link_target = etnaviv_buffer_reserve(gpu, buffer, dwords);
  201. CMD_SEM(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE);
  202. CMD_STALL(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE);
  203. if (has_blt) {
  204. CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x1);
  205. CMD_SEM(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_BLT);
  206. CMD_STALL(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_BLT);
  207. CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x0);
  208. }
  209. CMD_LOAD_STATE(buffer, VIVS_GL_FLUSH_CACHE, flush);
  210. if (gpu->exec_state == ETNA_PIPE_3D) {
  211. if (has_blt) {
  212. CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x1);
  213. CMD_LOAD_STATE(buffer, VIVS_BLT_SET_COMMAND, 0x1);
  214. CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x0);
  215. } else {
  216. CMD_LOAD_STATE(buffer, VIVS_TS_FLUSH_CACHE,
  217. VIVS_TS_FLUSH_CACHE_FLUSH);
  218. }
  219. }
  220. CMD_SEM(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE);
  221. CMD_STALL(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE);
  222. if (has_blt) {
  223. CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x1);
  224. CMD_SEM(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_BLT);
  225. CMD_STALL(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_BLT);
  226. CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x0);
  227. }
  228. CMD_END(buffer);
  229. etnaviv_buffer_replace_wait(buffer, waitlink_offset,
  230. VIV_FE_LINK_HEADER_OP_LINK |
  231. VIV_FE_LINK_HEADER_PREFETCH(dwords),
  232. link_target);
  233. } else {
  234. /* Replace the last link-wait with an "END" command */
  235. etnaviv_buffer_replace_wait(buffer, waitlink_offset,
  236. VIV_FE_END_HEADER_OP_END, 0);
  237. }
  238. }
  239. /* Append a 'sync point' to the ring buffer. */
  240. void etnaviv_sync_point_queue(struct etnaviv_gpu *gpu, unsigned int event)
  241. {
  242. struct etnaviv_cmdbuf *buffer = &gpu->buffer;
  243. unsigned int waitlink_offset = buffer->user_size - 16;
  244. u32 dwords, target;
  245. lockdep_assert_held(&gpu->lock);
  246. /*
  247. * We need at most 3 dwords in the return target:
  248. * 1 event + 1 end + 1 wait + 1 link.
  249. */
  250. dwords = 4;
  251. target = etnaviv_buffer_reserve(gpu, buffer, dwords);
  252. /* Signal sync point event */
  253. CMD_LOAD_STATE(buffer, VIVS_GL_EVENT, VIVS_GL_EVENT_EVENT_ID(event) |
  254. VIVS_GL_EVENT_FROM_PE);
  255. /* Stop the FE to 'pause' the GPU */
  256. CMD_END(buffer);
  257. /* Append waitlink */
  258. CMD_WAIT(buffer, gpu->fe_waitcycles);
  259. CMD_LINK(buffer, 2,
  260. etnaviv_cmdbuf_get_va(buffer, &gpu->mmu_context->cmdbuf_mapping)
  261. + buffer->user_size - 4);
  262. /*
  263. * Kick off the 'sync point' command by replacing the previous
  264. * WAIT with a link to the address in the ring buffer.
  265. */
  266. etnaviv_buffer_replace_wait(buffer, waitlink_offset,
  267. VIV_FE_LINK_HEADER_OP_LINK |
  268. VIV_FE_LINK_HEADER_PREFETCH(dwords),
  269. target);
  270. }
  271. /* Append a command buffer to the ring buffer. */
  272. void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, u32 exec_state,
  273. struct etnaviv_iommu_context *mmu_context, unsigned int event,
  274. struct etnaviv_cmdbuf *cmdbuf)
  275. {
  276. struct etnaviv_cmdbuf *buffer = &gpu->buffer;
  277. unsigned int waitlink_offset = buffer->user_size - 16;
  278. u32 return_target, return_dwords;
  279. u32 link_target, link_dwords;
  280. bool switch_context = gpu->exec_state != exec_state;
  281. bool switch_mmu_context = gpu->mmu_context != mmu_context;
  282. unsigned int new_flush_seq = READ_ONCE(gpu->mmu_context->flush_seq);
  283. bool need_flush = switch_mmu_context || gpu->flush_seq != new_flush_seq;
  284. bool has_blt = !!(gpu->identity.minor_features5 &
  285. chipMinorFeatures5_BLT_ENGINE);
  286. lockdep_assert_held(&gpu->lock);
  287. if (drm_debug_enabled(DRM_UT_DRIVER))
  288. etnaviv_buffer_dump(gpu, buffer, 0, 0x50);
  289. link_target = etnaviv_cmdbuf_get_va(cmdbuf,
  290. &gpu->mmu_context->cmdbuf_mapping);
  291. link_dwords = cmdbuf->size / 8;
  292. /*
  293. * If we need maintenance prior to submitting this buffer, we will
  294. * need to append a mmu flush load state, followed by a new
  295. * link to this buffer - a total of four additional words.
  296. */
  297. if (need_flush || switch_context) {
  298. u32 target, extra_dwords;
  299. /* link command */
  300. extra_dwords = 1;
  301. /* flush command */
  302. if (need_flush) {
  303. if (gpu->mmu_context->global->version == ETNAVIV_IOMMU_V1)
  304. extra_dwords += 1;
  305. else
  306. extra_dwords += 3;
  307. }
  308. /* pipe switch commands */
  309. if (switch_context)
  310. extra_dwords += 4;
  311. /* PTA load command */
  312. if (switch_mmu_context && gpu->sec_mode == ETNA_SEC_KERNEL)
  313. extra_dwords += 1;
  314. target = etnaviv_buffer_reserve(gpu, buffer, extra_dwords);
  315. /*
  316. * Switch MMU context if necessary. Must be done after the
  317. * link target has been calculated, as the jump forward in the
  318. * kernel ring still uses the last active MMU context before
  319. * the switch.
  320. */
  321. if (switch_mmu_context) {
  322. struct etnaviv_iommu_context *old_context = gpu->mmu_context;
  323. gpu->mmu_context = etnaviv_iommu_context_get(mmu_context);
  324. etnaviv_iommu_context_put(old_context);
  325. }
  326. if (need_flush) {
  327. /* Add the MMU flush */
  328. if (gpu->mmu_context->global->version == ETNAVIV_IOMMU_V1) {
  329. CMD_LOAD_STATE(buffer, VIVS_GL_FLUSH_MMU,
  330. VIVS_GL_FLUSH_MMU_FLUSH_FEMMU |
  331. VIVS_GL_FLUSH_MMU_FLUSH_UNK1 |
  332. VIVS_GL_FLUSH_MMU_FLUSH_UNK2 |
  333. VIVS_GL_FLUSH_MMU_FLUSH_PEMMU |
  334. VIVS_GL_FLUSH_MMU_FLUSH_UNK4);
  335. } else {
  336. u32 flush = VIVS_MMUv2_CONFIGURATION_MODE_MASK |
  337. VIVS_MMUv2_CONFIGURATION_FLUSH_FLUSH;
  338. if (switch_mmu_context &&
  339. gpu->sec_mode == ETNA_SEC_KERNEL) {
  340. unsigned short id =
  341. etnaviv_iommuv2_get_pta_id(gpu->mmu_context);
  342. CMD_LOAD_STATE(buffer,
  343. VIVS_MMUv2_PTA_CONFIG,
  344. VIVS_MMUv2_PTA_CONFIG_INDEX(id));
  345. }
  346. if (gpu->sec_mode == ETNA_SEC_NONE)
  347. flush |= etnaviv_iommuv2_get_mtlb_addr(gpu->mmu_context);
  348. CMD_LOAD_STATE(buffer, VIVS_MMUv2_CONFIGURATION,
  349. flush);
  350. CMD_SEM(buffer, SYNC_RECIPIENT_FE,
  351. SYNC_RECIPIENT_PE);
  352. CMD_STALL(buffer, SYNC_RECIPIENT_FE,
  353. SYNC_RECIPIENT_PE);
  354. }
  355. gpu->flush_seq = new_flush_seq;
  356. }
  357. if (switch_context) {
  358. etnaviv_cmd_select_pipe(gpu, buffer, exec_state);
  359. gpu->exec_state = exec_state;
  360. }
  361. /* And the link to the submitted buffer */
  362. link_target = etnaviv_cmdbuf_get_va(cmdbuf,
  363. &gpu->mmu_context->cmdbuf_mapping);
  364. CMD_LINK(buffer, link_dwords, link_target);
  365. /* Update the link target to point to above instructions */
  366. link_target = target;
  367. link_dwords = extra_dwords;
  368. }
  369. /*
  370. * Append a LINK to the submitted command buffer to return to
  371. * the ring buffer. return_target is the ring target address.
  372. * We need at most 7 dwords in the return target: 2 cache flush +
  373. * 2 semaphore stall + 1 event + 1 wait + 1 link.
  374. */
  375. return_dwords = 7;
  376. /*
  377. * When the BLT engine is present we need 6 more dwords in the return
  378. * target: 3 enable/flush/disable + 4 enable/semaphore stall/disable,
  379. * but we don't need the normal TS flush state.
  380. */
  381. if (has_blt)
  382. return_dwords += 6;
  383. return_target = etnaviv_buffer_reserve(gpu, buffer, return_dwords);
  384. CMD_LINK(cmdbuf, return_dwords, return_target);
  385. /*
  386. * Append a cache flush, stall, event, wait and link pointing back to
  387. * the wait command to the ring buffer.
  388. */
  389. if (gpu->exec_state == ETNA_PIPE_2D) {
  390. CMD_LOAD_STATE(buffer, VIVS_GL_FLUSH_CACHE,
  391. VIVS_GL_FLUSH_CACHE_PE2D);
  392. } else {
  393. CMD_LOAD_STATE(buffer, VIVS_GL_FLUSH_CACHE,
  394. VIVS_GL_FLUSH_CACHE_DEPTH |
  395. VIVS_GL_FLUSH_CACHE_COLOR |
  396. VIVS_GL_FLUSH_CACHE_SHADER_L1);
  397. if (has_blt) {
  398. CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x1);
  399. CMD_LOAD_STATE(buffer, VIVS_BLT_SET_COMMAND, 0x1);
  400. CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x0);
  401. } else {
  402. CMD_LOAD_STATE(buffer, VIVS_TS_FLUSH_CACHE,
  403. VIVS_TS_FLUSH_CACHE_FLUSH);
  404. }
  405. }
  406. CMD_SEM(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE);
  407. CMD_STALL(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE);
  408. if (has_blt) {
  409. CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x1);
  410. CMD_SEM(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_BLT);
  411. CMD_STALL(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_BLT);
  412. CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x0);
  413. }
  414. CMD_LOAD_STATE(buffer, VIVS_GL_EVENT, VIVS_GL_EVENT_EVENT_ID(event) |
  415. VIVS_GL_EVENT_FROM_PE);
  416. CMD_WAIT(buffer, gpu->fe_waitcycles);
  417. CMD_LINK(buffer, 2,
  418. etnaviv_cmdbuf_get_va(buffer, &gpu->mmu_context->cmdbuf_mapping)
  419. + buffer->user_size - 4);
  420. if (drm_debug_enabled(DRM_UT_DRIVER))
  421. pr_info("stream link to 0x%08x @ 0x%08x %p\n",
  422. return_target,
  423. etnaviv_cmdbuf_get_va(cmdbuf, &gpu->mmu_context->cmdbuf_mapping),
  424. cmdbuf->vaddr);
  425. if (drm_debug_enabled(DRM_UT_DRIVER)) {
  426. print_hex_dump(KERN_INFO, "cmd ", DUMP_PREFIX_OFFSET, 16, 4,
  427. cmdbuf->vaddr, cmdbuf->size, 0);
  428. pr_info("link op: %p\n", buffer->vaddr + waitlink_offset);
  429. pr_info("addr: 0x%08x\n", link_target);
  430. pr_info("back: 0x%08x\n", return_target);
  431. pr_info("event: %d\n", event);
  432. }
  433. /*
  434. * Kick off the submitted command by replacing the previous
  435. * WAIT with a link to the address in the ring buffer.
  436. */
  437. etnaviv_buffer_replace_wait(buffer, waitlink_offset,
  438. VIV_FE_LINK_HEADER_OP_LINK |
  439. VIV_FE_LINK_HEADER_PREFETCH(link_dwords),
  440. link_target);
  441. if (drm_debug_enabled(DRM_UT_DRIVER))
  442. etnaviv_buffer_dump(gpu, buffer, 0, 0x50);
  443. }