uvd_v6_0.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  1. /*
  2. * Copyright 2014 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Christian König <christian.koenig@amd.com>
  23. */
  24. #include <linux/firmware.h>
  25. #include <drm/drmP.h>
  26. #include "amdgpu.h"
  27. #include "amdgpu_uvd.h"
  28. #include "vid.h"
  29. #include "uvd/uvd_6_0_d.h"
  30. #include "uvd/uvd_6_0_sh_mask.h"
  31. #include "oss/oss_2_0_d.h"
  32. #include "oss/oss_2_0_sh_mask.h"
  33. static void uvd_v6_0_set_ring_funcs(struct amdgpu_device *adev);
  34. static void uvd_v6_0_set_irq_funcs(struct amdgpu_device *adev);
  35. static int uvd_v6_0_start(struct amdgpu_device *adev);
  36. static void uvd_v6_0_stop(struct amdgpu_device *adev);
  37. /**
  38. * uvd_v6_0_ring_get_rptr - get read pointer
  39. *
  40. * @ring: amdgpu_ring pointer
  41. *
  42. * Returns the current hardware read pointer
  43. */
  44. static uint32_t uvd_v6_0_ring_get_rptr(struct amdgpu_ring *ring)
  45. {
  46. struct amdgpu_device *adev = ring->adev;
  47. return RREG32(mmUVD_RBC_RB_RPTR);
  48. }
  49. /**
  50. * uvd_v6_0_ring_get_wptr - get write pointer
  51. *
  52. * @ring: amdgpu_ring pointer
  53. *
  54. * Returns the current hardware write pointer
  55. */
  56. static uint32_t uvd_v6_0_ring_get_wptr(struct amdgpu_ring *ring)
  57. {
  58. struct amdgpu_device *adev = ring->adev;
  59. return RREG32(mmUVD_RBC_RB_WPTR);
  60. }
  61. /**
  62. * uvd_v6_0_ring_set_wptr - set write pointer
  63. *
  64. * @ring: amdgpu_ring pointer
  65. *
  66. * Commits the write pointer to the hardware
  67. */
  68. static void uvd_v6_0_ring_set_wptr(struct amdgpu_ring *ring)
  69. {
  70. struct amdgpu_device *adev = ring->adev;
  71. WREG32(mmUVD_RBC_RB_WPTR, ring->wptr);
  72. }
  73. static int uvd_v6_0_early_init(void *handle)
  74. {
  75. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  76. uvd_v6_0_set_ring_funcs(adev);
  77. uvd_v6_0_set_irq_funcs(adev);
  78. return 0;
  79. }
  80. static int uvd_v6_0_sw_init(void *handle)
  81. {
  82. struct amdgpu_ring *ring;
  83. int r;
  84. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  85. /* UVD TRAP */
  86. r = amdgpu_irq_add_id(adev, 124, &adev->uvd.irq);
  87. if (r)
  88. return r;
  89. r = amdgpu_uvd_sw_init(adev);
  90. if (r)
  91. return r;
  92. r = amdgpu_uvd_resume(adev);
  93. if (r)
  94. return r;
  95. ring = &adev->uvd.ring;
  96. sprintf(ring->name, "uvd");
  97. r = amdgpu_ring_init(adev, ring, 4096, CP_PACKET2, 0xf,
  98. &adev->uvd.irq, 0, AMDGPU_RING_TYPE_UVD);
  99. return r;
  100. }
  101. static int uvd_v6_0_sw_fini(void *handle)
  102. {
  103. int r;
  104. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  105. r = amdgpu_uvd_suspend(adev);
  106. if (r)
  107. return r;
  108. r = amdgpu_uvd_sw_fini(adev);
  109. if (r)
  110. return r;
  111. return r;
  112. }
  113. /**
  114. * uvd_v6_0_hw_init - start and test UVD block
  115. *
  116. * @adev: amdgpu_device pointer
  117. *
  118. * Initialize the hardware, boot up the VCPU and do some testing
  119. */
  120. static int uvd_v6_0_hw_init(void *handle)
  121. {
  122. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  123. struct amdgpu_ring *ring = &adev->uvd.ring;
  124. uint32_t tmp;
  125. int r;
  126. r = uvd_v6_0_start(adev);
  127. if (r)
  128. goto done;
  129. ring->ready = true;
  130. r = amdgpu_ring_test_ring(ring);
  131. if (r) {
  132. ring->ready = false;
  133. goto done;
  134. }
  135. r = amdgpu_ring_lock(ring, 10);
  136. if (r) {
  137. DRM_ERROR("amdgpu: ring failed to lock UVD ring (%d).\n", r);
  138. goto done;
  139. }
  140. tmp = PACKET0(mmUVD_SEMA_WAIT_FAULT_TIMEOUT_CNTL, 0);
  141. amdgpu_ring_write(ring, tmp);
  142. amdgpu_ring_write(ring, 0xFFFFF);
  143. tmp = PACKET0(mmUVD_SEMA_WAIT_INCOMPLETE_TIMEOUT_CNTL, 0);
  144. amdgpu_ring_write(ring, tmp);
  145. amdgpu_ring_write(ring, 0xFFFFF);
  146. tmp = PACKET0(mmUVD_SEMA_SIGNAL_INCOMPLETE_TIMEOUT_CNTL, 0);
  147. amdgpu_ring_write(ring, tmp);
  148. amdgpu_ring_write(ring, 0xFFFFF);
  149. /* Clear timeout status bits */
  150. amdgpu_ring_write(ring, PACKET0(mmUVD_SEMA_TIMEOUT_STATUS, 0));
  151. amdgpu_ring_write(ring, 0x8);
  152. amdgpu_ring_write(ring, PACKET0(mmUVD_SEMA_CNTL, 0));
  153. amdgpu_ring_write(ring, 3);
  154. amdgpu_ring_unlock_commit(ring);
  155. done:
  156. if (!r)
  157. DRM_INFO("UVD initialized successfully.\n");
  158. return r;
  159. }
  160. /**
  161. * uvd_v6_0_hw_fini - stop the hardware block
  162. *
  163. * @adev: amdgpu_device pointer
  164. *
  165. * Stop the UVD block, mark ring as not ready any more
  166. */
  167. static int uvd_v6_0_hw_fini(void *handle)
  168. {
  169. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  170. struct amdgpu_ring *ring = &adev->uvd.ring;
  171. uvd_v6_0_stop(adev);
  172. ring->ready = false;
  173. return 0;
  174. }
  175. static int uvd_v6_0_suspend(void *handle)
  176. {
  177. int r;
  178. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  179. /* Skip this for APU for now */
  180. if (!(adev->flags & AMD_IS_APU)) {
  181. r = amdgpu_uvd_suspend(adev);
  182. if (r)
  183. return r;
  184. }
  185. r = uvd_v6_0_hw_fini(adev);
  186. if (r)
  187. return r;
  188. return r;
  189. }
  190. static int uvd_v6_0_resume(void *handle)
  191. {
  192. int r;
  193. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  194. /* Skip this for APU for now */
  195. if (!(adev->flags & AMD_IS_APU)) {
  196. r = amdgpu_uvd_resume(adev);
  197. if (r)
  198. return r;
  199. }
  200. r = uvd_v6_0_hw_init(adev);
  201. if (r)
  202. return r;
  203. return r;
  204. }
  205. /**
  206. * uvd_v6_0_mc_resume - memory controller programming
  207. *
  208. * @adev: amdgpu_device pointer
  209. *
  210. * Let the UVD memory controller know it's offsets
  211. */
  212. static void uvd_v6_0_mc_resume(struct amdgpu_device *adev)
  213. {
  214. uint64_t offset;
  215. uint32_t size;
  216. /* programm memory controller bits 0-27 */
  217. WREG32(mmUVD_LMI_VCPU_CACHE_64BIT_BAR_LOW,
  218. lower_32_bits(adev->uvd.gpu_addr));
  219. WREG32(mmUVD_LMI_VCPU_CACHE_64BIT_BAR_HIGH,
  220. upper_32_bits(adev->uvd.gpu_addr));
  221. offset = AMDGPU_UVD_FIRMWARE_OFFSET;
  222. size = AMDGPU_GPU_PAGE_ALIGN(adev->uvd.fw->size + 4);
  223. WREG32(mmUVD_VCPU_CACHE_OFFSET0, offset >> 3);
  224. WREG32(mmUVD_VCPU_CACHE_SIZE0, size);
  225. offset += size;
  226. size = AMDGPU_UVD_STACK_SIZE;
  227. WREG32(mmUVD_VCPU_CACHE_OFFSET1, offset >> 3);
  228. WREG32(mmUVD_VCPU_CACHE_SIZE1, size);
  229. offset += size;
  230. size = AMDGPU_UVD_HEAP_SIZE;
  231. WREG32(mmUVD_VCPU_CACHE_OFFSET2, offset >> 3);
  232. WREG32(mmUVD_VCPU_CACHE_SIZE2, size);
  233. }
  234. /**
  235. * uvd_v6_0_start - start UVD block
  236. *
  237. * @adev: amdgpu_device pointer
  238. *
  239. * Setup and start the UVD block
  240. */
  241. static int uvd_v6_0_start(struct amdgpu_device *adev)
  242. {
  243. struct amdgpu_ring *ring = &adev->uvd.ring;
  244. uint32_t rb_bufsz, tmp;
  245. uint32_t lmi_swap_cntl;
  246. uint32_t mp_swap_cntl;
  247. int i, j, r;
  248. /*disable DPG */
  249. WREG32_P(mmUVD_POWER_STATUS, 0, ~(1 << 2));
  250. /* disable byte swapping */
  251. lmi_swap_cntl = 0;
  252. mp_swap_cntl = 0;
  253. uvd_v6_0_mc_resume(adev);
  254. /* disable clock gating */
  255. WREG32(mmUVD_CGC_GATE, 0);
  256. /* disable interupt */
  257. WREG32_P(mmUVD_MASTINT_EN, 0, ~(1 << 1));
  258. /* stall UMC and register bus before resetting VCPU */
  259. WREG32_P(mmUVD_LMI_CTRL2, 1 << 8, ~(1 << 8));
  260. mdelay(1);
  261. /* put LMI, VCPU, RBC etc... into reset */
  262. WREG32(mmUVD_SOFT_RESET, UVD_SOFT_RESET__LMI_SOFT_RESET_MASK |
  263. UVD_SOFT_RESET__VCPU_SOFT_RESET_MASK | UVD_SOFT_RESET__LBSI_SOFT_RESET_MASK |
  264. UVD_SOFT_RESET__RBC_SOFT_RESET_MASK | UVD_SOFT_RESET__CSM_SOFT_RESET_MASK |
  265. UVD_SOFT_RESET__CXW_SOFT_RESET_MASK | UVD_SOFT_RESET__TAP_SOFT_RESET_MASK |
  266. UVD_SOFT_RESET__LMI_UMC_SOFT_RESET_MASK);
  267. mdelay(5);
  268. /* take UVD block out of reset */
  269. WREG32_P(mmSRBM_SOFT_RESET, 0, ~SRBM_SOFT_RESET__SOFT_RESET_UVD_MASK);
  270. mdelay(5);
  271. /* initialize UVD memory controller */
  272. WREG32(mmUVD_LMI_CTRL, 0x40 | (1 << 8) | (1 << 13) |
  273. (1 << 21) | (1 << 9) | (1 << 20));
  274. #ifdef __BIG_ENDIAN
  275. /* swap (8 in 32) RB and IB */
  276. lmi_swap_cntl = 0xa;
  277. mp_swap_cntl = 0;
  278. #endif
  279. WREG32(mmUVD_LMI_SWAP_CNTL, lmi_swap_cntl);
  280. WREG32(mmUVD_MP_SWAP_CNTL, mp_swap_cntl);
  281. WREG32(mmUVD_MPC_SET_MUXA0, 0x40c2040);
  282. WREG32(mmUVD_MPC_SET_MUXA1, 0x0);
  283. WREG32(mmUVD_MPC_SET_MUXB0, 0x40c2040);
  284. WREG32(mmUVD_MPC_SET_MUXB1, 0x0);
  285. WREG32(mmUVD_MPC_SET_ALU, 0);
  286. WREG32(mmUVD_MPC_SET_MUX, 0x88);
  287. /* take all subblocks out of reset, except VCPU */
  288. WREG32(mmUVD_SOFT_RESET, UVD_SOFT_RESET__VCPU_SOFT_RESET_MASK);
  289. mdelay(5);
  290. /* enable VCPU clock */
  291. WREG32(mmUVD_VCPU_CNTL, 1 << 9);
  292. /* enable UMC */
  293. WREG32_P(mmUVD_LMI_CTRL2, 0, ~(1 << 8));
  294. /* boot up the VCPU */
  295. WREG32(mmUVD_SOFT_RESET, 0);
  296. mdelay(10);
  297. for (i = 0; i < 10; ++i) {
  298. uint32_t status;
  299. for (j = 0; j < 100; ++j) {
  300. status = RREG32(mmUVD_STATUS);
  301. if (status & 2)
  302. break;
  303. mdelay(10);
  304. }
  305. r = 0;
  306. if (status & 2)
  307. break;
  308. DRM_ERROR("UVD not responding, trying to reset the VCPU!!!\n");
  309. WREG32_P(mmUVD_SOFT_RESET, UVD_SOFT_RESET__VCPU_SOFT_RESET_MASK,
  310. ~UVD_SOFT_RESET__VCPU_SOFT_RESET_MASK);
  311. mdelay(10);
  312. WREG32_P(mmUVD_SOFT_RESET, 0,
  313. ~UVD_SOFT_RESET__VCPU_SOFT_RESET_MASK);
  314. mdelay(10);
  315. r = -1;
  316. }
  317. if (r) {
  318. DRM_ERROR("UVD not responding, giving up!!!\n");
  319. return r;
  320. }
  321. /* enable master interrupt */
  322. WREG32_P(mmUVD_MASTINT_EN, 3 << 1, ~(3 << 1));
  323. /* clear the bit 4 of UVD_STATUS */
  324. WREG32_P(mmUVD_STATUS, 0, ~(2 << 1));
  325. rb_bufsz = order_base_2(ring->ring_size);
  326. tmp = 0;
  327. tmp = REG_SET_FIELD(tmp, UVD_RBC_RB_CNTL, RB_BUFSZ, rb_bufsz);
  328. tmp = REG_SET_FIELD(tmp, UVD_RBC_RB_CNTL, RB_BLKSZ, 1);
  329. tmp = REG_SET_FIELD(tmp, UVD_RBC_RB_CNTL, RB_NO_FETCH, 1);
  330. tmp = REG_SET_FIELD(tmp, UVD_RBC_RB_CNTL, RB_WPTR_POLL_EN, 0);
  331. tmp = REG_SET_FIELD(tmp, UVD_RBC_RB_CNTL, RB_NO_UPDATE, 1);
  332. tmp = REG_SET_FIELD(tmp, UVD_RBC_RB_CNTL, RB_RPTR_WR_EN, 1);
  333. /* force RBC into idle state */
  334. WREG32(mmUVD_RBC_RB_CNTL, tmp);
  335. /* set the write pointer delay */
  336. WREG32(mmUVD_RBC_RB_WPTR_CNTL, 0);
  337. /* set the wb address */
  338. WREG32(mmUVD_RBC_RB_RPTR_ADDR, (upper_32_bits(ring->gpu_addr) >> 2));
  339. /* programm the RB_BASE for ring buffer */
  340. WREG32(mmUVD_LMI_RBC_RB_64BIT_BAR_LOW,
  341. lower_32_bits(ring->gpu_addr));
  342. WREG32(mmUVD_LMI_RBC_RB_64BIT_BAR_HIGH,
  343. upper_32_bits(ring->gpu_addr));
  344. /* Initialize the ring buffer's read and write pointers */
  345. WREG32(mmUVD_RBC_RB_RPTR, 0);
  346. ring->wptr = RREG32(mmUVD_RBC_RB_RPTR);
  347. WREG32(mmUVD_RBC_RB_WPTR, ring->wptr);
  348. WREG32_P(mmUVD_RBC_RB_CNTL, 0, ~UVD_RBC_RB_CNTL__RB_NO_FETCH_MASK);
  349. return 0;
  350. }
  351. /**
  352. * uvd_v6_0_stop - stop UVD block
  353. *
  354. * @adev: amdgpu_device pointer
  355. *
  356. * stop the UVD block
  357. */
  358. static void uvd_v6_0_stop(struct amdgpu_device *adev)
  359. {
  360. /* force RBC into idle state */
  361. WREG32(mmUVD_RBC_RB_CNTL, 0x11010101);
  362. /* Stall UMC and register bus before resetting VCPU */
  363. WREG32_P(mmUVD_LMI_CTRL2, 1 << 8, ~(1 << 8));
  364. mdelay(1);
  365. /* put VCPU into reset */
  366. WREG32(mmUVD_SOFT_RESET, UVD_SOFT_RESET__VCPU_SOFT_RESET_MASK);
  367. mdelay(5);
  368. /* disable VCPU clock */
  369. WREG32(mmUVD_VCPU_CNTL, 0x0);
  370. /* Unstall UMC and register bus */
  371. WREG32_P(mmUVD_LMI_CTRL2, 0, ~(1 << 8));
  372. }
  373. /**
  374. * uvd_v6_0_ring_emit_fence - emit an fence & trap command
  375. *
  376. * @ring: amdgpu_ring pointer
  377. * @fence: fence to emit
  378. *
  379. * Write a fence and a trap command to the ring.
  380. */
  381. static void uvd_v6_0_ring_emit_fence(struct amdgpu_ring *ring, u64 addr, u64 seq,
  382. unsigned flags)
  383. {
  384. WARN_ON(flags & AMDGPU_FENCE_FLAG_64BIT);
  385. amdgpu_ring_write(ring, PACKET0(mmUVD_CONTEXT_ID, 0));
  386. amdgpu_ring_write(ring, seq);
  387. amdgpu_ring_write(ring, PACKET0(mmUVD_GPCOM_VCPU_DATA0, 0));
  388. amdgpu_ring_write(ring, addr & 0xffffffff);
  389. amdgpu_ring_write(ring, PACKET0(mmUVD_GPCOM_VCPU_DATA1, 0));
  390. amdgpu_ring_write(ring, upper_32_bits(addr) & 0xff);
  391. amdgpu_ring_write(ring, PACKET0(mmUVD_GPCOM_VCPU_CMD, 0));
  392. amdgpu_ring_write(ring, 0);
  393. amdgpu_ring_write(ring, PACKET0(mmUVD_GPCOM_VCPU_DATA0, 0));
  394. amdgpu_ring_write(ring, 0);
  395. amdgpu_ring_write(ring, PACKET0(mmUVD_GPCOM_VCPU_DATA1, 0));
  396. amdgpu_ring_write(ring, 0);
  397. amdgpu_ring_write(ring, PACKET0(mmUVD_GPCOM_VCPU_CMD, 0));
  398. amdgpu_ring_write(ring, 2);
  399. }
  400. /**
  401. * uvd_v6_0_ring_emit_semaphore - emit semaphore command
  402. *
  403. * @ring: amdgpu_ring pointer
  404. * @semaphore: semaphore to emit commands for
  405. * @emit_wait: true if we should emit a wait command
  406. *
  407. * Emit a semaphore command (either wait or signal) to the UVD ring.
  408. */
  409. static bool uvd_v6_0_ring_emit_semaphore(struct amdgpu_ring *ring,
  410. struct amdgpu_semaphore *semaphore,
  411. bool emit_wait)
  412. {
  413. uint64_t addr = semaphore->gpu_addr;
  414. amdgpu_ring_write(ring, PACKET0(mmUVD_SEMA_ADDR_LOW, 0));
  415. amdgpu_ring_write(ring, (addr >> 3) & 0x000FFFFF);
  416. amdgpu_ring_write(ring, PACKET0(mmUVD_SEMA_ADDR_HIGH, 0));
  417. amdgpu_ring_write(ring, (addr >> 23) & 0x000FFFFF);
  418. amdgpu_ring_write(ring, PACKET0(mmUVD_SEMA_CMD, 0));
  419. amdgpu_ring_write(ring, 0x80 | (emit_wait ? 1 : 0));
  420. return true;
  421. }
  422. /**
  423. * uvd_v6_0_ring_test_ring - register write test
  424. *
  425. * @ring: amdgpu_ring pointer
  426. *
  427. * Test if we can successfully write to the context register
  428. */
  429. static int uvd_v6_0_ring_test_ring(struct amdgpu_ring *ring)
  430. {
  431. struct amdgpu_device *adev = ring->adev;
  432. uint32_t tmp = 0;
  433. unsigned i;
  434. int r;
  435. WREG32(mmUVD_CONTEXT_ID, 0xCAFEDEAD);
  436. r = amdgpu_ring_lock(ring, 3);
  437. if (r) {
  438. DRM_ERROR("amdgpu: cp failed to lock ring %d (%d).\n",
  439. ring->idx, r);
  440. return r;
  441. }
  442. amdgpu_ring_write(ring, PACKET0(mmUVD_CONTEXT_ID, 0));
  443. amdgpu_ring_write(ring, 0xDEADBEEF);
  444. amdgpu_ring_unlock_commit(ring);
  445. for (i = 0; i < adev->usec_timeout; i++) {
  446. tmp = RREG32(mmUVD_CONTEXT_ID);
  447. if (tmp == 0xDEADBEEF)
  448. break;
  449. DRM_UDELAY(1);
  450. }
  451. if (i < adev->usec_timeout) {
  452. DRM_INFO("ring test on %d succeeded in %d usecs\n",
  453. ring->idx, i);
  454. } else {
  455. DRM_ERROR("amdgpu: ring %d test failed (0x%08X)\n",
  456. ring->idx, tmp);
  457. r = -EINVAL;
  458. }
  459. return r;
  460. }
  461. /**
  462. * uvd_v6_0_ring_emit_ib - execute indirect buffer
  463. *
  464. * @ring: amdgpu_ring pointer
  465. * @ib: indirect buffer to execute
  466. *
  467. * Write ring commands to execute the indirect buffer
  468. */
  469. static void uvd_v6_0_ring_emit_ib(struct amdgpu_ring *ring,
  470. struct amdgpu_ib *ib)
  471. {
  472. amdgpu_ring_write(ring, PACKET0(mmUVD_LMI_RBC_IB_64BIT_BAR_LOW, 0));
  473. amdgpu_ring_write(ring, lower_32_bits(ib->gpu_addr));
  474. amdgpu_ring_write(ring, PACKET0(mmUVD_LMI_RBC_IB_64BIT_BAR_HIGH, 0));
  475. amdgpu_ring_write(ring, upper_32_bits(ib->gpu_addr));
  476. amdgpu_ring_write(ring, PACKET0(mmUVD_RBC_IB_SIZE, 0));
  477. amdgpu_ring_write(ring, ib->length_dw);
  478. }
  479. /**
  480. * uvd_v6_0_ring_test_ib - test ib execution
  481. *
  482. * @ring: amdgpu_ring pointer
  483. *
  484. * Test if we can successfully execute an IB
  485. */
  486. static int uvd_v6_0_ring_test_ib(struct amdgpu_ring *ring)
  487. {
  488. struct fence *fence = NULL;
  489. int r;
  490. r = amdgpu_uvd_get_create_msg(ring, 1, NULL);
  491. if (r) {
  492. DRM_ERROR("amdgpu: failed to get create msg (%d).\n", r);
  493. goto error;
  494. }
  495. r = amdgpu_uvd_get_destroy_msg(ring, 1, &fence);
  496. if (r) {
  497. DRM_ERROR("amdgpu: failed to get destroy ib (%d).\n", r);
  498. goto error;
  499. }
  500. r = fence_wait(fence, false);
  501. if (r) {
  502. DRM_ERROR("amdgpu: fence wait failed (%d).\n", r);
  503. goto error;
  504. }
  505. DRM_INFO("ib test on ring %d succeeded\n", ring->idx);
  506. error:
  507. fence_put(fence);
  508. return r;
  509. }
  510. static bool uvd_v6_0_is_idle(void *handle)
  511. {
  512. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  513. return !(RREG32(mmSRBM_STATUS) & SRBM_STATUS__UVD_BUSY_MASK);
  514. }
  515. static int uvd_v6_0_wait_for_idle(void *handle)
  516. {
  517. unsigned i;
  518. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  519. for (i = 0; i < adev->usec_timeout; i++) {
  520. if (!(RREG32(mmSRBM_STATUS) & SRBM_STATUS__UVD_BUSY_MASK))
  521. return 0;
  522. }
  523. return -ETIMEDOUT;
  524. }
  525. static int uvd_v6_0_soft_reset(void *handle)
  526. {
  527. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  528. uvd_v6_0_stop(adev);
  529. WREG32_P(mmSRBM_SOFT_RESET, SRBM_SOFT_RESET__SOFT_RESET_UVD_MASK,
  530. ~SRBM_SOFT_RESET__SOFT_RESET_UVD_MASK);
  531. mdelay(5);
  532. return uvd_v6_0_start(adev);
  533. }
  534. static void uvd_v6_0_print_status(void *handle)
  535. {
  536. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  537. dev_info(adev->dev, "UVD 6.0 registers\n");
  538. dev_info(adev->dev, " UVD_SEMA_ADDR_LOW=0x%08X\n",
  539. RREG32(mmUVD_SEMA_ADDR_LOW));
  540. dev_info(adev->dev, " UVD_SEMA_ADDR_HIGH=0x%08X\n",
  541. RREG32(mmUVD_SEMA_ADDR_HIGH));
  542. dev_info(adev->dev, " UVD_SEMA_CMD=0x%08X\n",
  543. RREG32(mmUVD_SEMA_CMD));
  544. dev_info(adev->dev, " UVD_GPCOM_VCPU_CMD=0x%08X\n",
  545. RREG32(mmUVD_GPCOM_VCPU_CMD));
  546. dev_info(adev->dev, " UVD_GPCOM_VCPU_DATA0=0x%08X\n",
  547. RREG32(mmUVD_GPCOM_VCPU_DATA0));
  548. dev_info(adev->dev, " UVD_GPCOM_VCPU_DATA1=0x%08X\n",
  549. RREG32(mmUVD_GPCOM_VCPU_DATA1));
  550. dev_info(adev->dev, " UVD_ENGINE_CNTL=0x%08X\n",
  551. RREG32(mmUVD_ENGINE_CNTL));
  552. dev_info(adev->dev, " UVD_UDEC_ADDR_CONFIG=0x%08X\n",
  553. RREG32(mmUVD_UDEC_ADDR_CONFIG));
  554. dev_info(adev->dev, " UVD_UDEC_DB_ADDR_CONFIG=0x%08X\n",
  555. RREG32(mmUVD_UDEC_DB_ADDR_CONFIG));
  556. dev_info(adev->dev, " UVD_UDEC_DBW_ADDR_CONFIG=0x%08X\n",
  557. RREG32(mmUVD_UDEC_DBW_ADDR_CONFIG));
  558. dev_info(adev->dev, " UVD_SEMA_CNTL=0x%08X\n",
  559. RREG32(mmUVD_SEMA_CNTL));
  560. dev_info(adev->dev, " UVD_LMI_EXT40_ADDR=0x%08X\n",
  561. RREG32(mmUVD_LMI_EXT40_ADDR));
  562. dev_info(adev->dev, " UVD_CTX_INDEX=0x%08X\n",
  563. RREG32(mmUVD_CTX_INDEX));
  564. dev_info(adev->dev, " UVD_CTX_DATA=0x%08X\n",
  565. RREG32(mmUVD_CTX_DATA));
  566. dev_info(adev->dev, " UVD_CGC_GATE=0x%08X\n",
  567. RREG32(mmUVD_CGC_GATE));
  568. dev_info(adev->dev, " UVD_CGC_CTRL=0x%08X\n",
  569. RREG32(mmUVD_CGC_CTRL));
  570. dev_info(adev->dev, " UVD_LMI_CTRL2=0x%08X\n",
  571. RREG32(mmUVD_LMI_CTRL2));
  572. dev_info(adev->dev, " UVD_MASTINT_EN=0x%08X\n",
  573. RREG32(mmUVD_MASTINT_EN));
  574. dev_info(adev->dev, " UVD_LMI_ADDR_EXT=0x%08X\n",
  575. RREG32(mmUVD_LMI_ADDR_EXT));
  576. dev_info(adev->dev, " UVD_LMI_CTRL=0x%08X\n",
  577. RREG32(mmUVD_LMI_CTRL));
  578. dev_info(adev->dev, " UVD_LMI_SWAP_CNTL=0x%08X\n",
  579. RREG32(mmUVD_LMI_SWAP_CNTL));
  580. dev_info(adev->dev, " UVD_MP_SWAP_CNTL=0x%08X\n",
  581. RREG32(mmUVD_MP_SWAP_CNTL));
  582. dev_info(adev->dev, " UVD_MPC_SET_MUXA0=0x%08X\n",
  583. RREG32(mmUVD_MPC_SET_MUXA0));
  584. dev_info(adev->dev, " UVD_MPC_SET_MUXA1=0x%08X\n",
  585. RREG32(mmUVD_MPC_SET_MUXA1));
  586. dev_info(adev->dev, " UVD_MPC_SET_MUXB0=0x%08X\n",
  587. RREG32(mmUVD_MPC_SET_MUXB0));
  588. dev_info(adev->dev, " UVD_MPC_SET_MUXB1=0x%08X\n",
  589. RREG32(mmUVD_MPC_SET_MUXB1));
  590. dev_info(adev->dev, " UVD_MPC_SET_MUX=0x%08X\n",
  591. RREG32(mmUVD_MPC_SET_MUX));
  592. dev_info(adev->dev, " UVD_MPC_SET_ALU=0x%08X\n",
  593. RREG32(mmUVD_MPC_SET_ALU));
  594. dev_info(adev->dev, " UVD_VCPU_CACHE_OFFSET0=0x%08X\n",
  595. RREG32(mmUVD_VCPU_CACHE_OFFSET0));
  596. dev_info(adev->dev, " UVD_VCPU_CACHE_SIZE0=0x%08X\n",
  597. RREG32(mmUVD_VCPU_CACHE_SIZE0));
  598. dev_info(adev->dev, " UVD_VCPU_CACHE_OFFSET1=0x%08X\n",
  599. RREG32(mmUVD_VCPU_CACHE_OFFSET1));
  600. dev_info(adev->dev, " UVD_VCPU_CACHE_SIZE1=0x%08X\n",
  601. RREG32(mmUVD_VCPU_CACHE_SIZE1));
  602. dev_info(adev->dev, " UVD_VCPU_CACHE_OFFSET2=0x%08X\n",
  603. RREG32(mmUVD_VCPU_CACHE_OFFSET2));
  604. dev_info(adev->dev, " UVD_VCPU_CACHE_SIZE2=0x%08X\n",
  605. RREG32(mmUVD_VCPU_CACHE_SIZE2));
  606. dev_info(adev->dev, " UVD_VCPU_CNTL=0x%08X\n",
  607. RREG32(mmUVD_VCPU_CNTL));
  608. dev_info(adev->dev, " UVD_SOFT_RESET=0x%08X\n",
  609. RREG32(mmUVD_SOFT_RESET));
  610. dev_info(adev->dev, " UVD_RBC_IB_SIZE=0x%08X\n",
  611. RREG32(mmUVD_RBC_IB_SIZE));
  612. dev_info(adev->dev, " UVD_RBC_RB_RPTR=0x%08X\n",
  613. RREG32(mmUVD_RBC_RB_RPTR));
  614. dev_info(adev->dev, " UVD_RBC_RB_WPTR=0x%08X\n",
  615. RREG32(mmUVD_RBC_RB_WPTR));
  616. dev_info(adev->dev, " UVD_RBC_RB_WPTR_CNTL=0x%08X\n",
  617. RREG32(mmUVD_RBC_RB_WPTR_CNTL));
  618. dev_info(adev->dev, " UVD_RBC_RB_CNTL=0x%08X\n",
  619. RREG32(mmUVD_RBC_RB_CNTL));
  620. dev_info(adev->dev, " UVD_STATUS=0x%08X\n",
  621. RREG32(mmUVD_STATUS));
  622. dev_info(adev->dev, " UVD_SEMA_TIMEOUT_STATUS=0x%08X\n",
  623. RREG32(mmUVD_SEMA_TIMEOUT_STATUS));
  624. dev_info(adev->dev, " UVD_SEMA_WAIT_INCOMPLETE_TIMEOUT_CNTL=0x%08X\n",
  625. RREG32(mmUVD_SEMA_WAIT_INCOMPLETE_TIMEOUT_CNTL));
  626. dev_info(adev->dev, " UVD_SEMA_WAIT_FAULT_TIMEOUT_CNTL=0x%08X\n",
  627. RREG32(mmUVD_SEMA_WAIT_FAULT_TIMEOUT_CNTL));
  628. dev_info(adev->dev, " UVD_SEMA_SIGNAL_INCOMPLETE_TIMEOUT_CNTL=0x%08X\n",
  629. RREG32(mmUVD_SEMA_SIGNAL_INCOMPLETE_TIMEOUT_CNTL));
  630. dev_info(adev->dev, " UVD_CONTEXT_ID=0x%08X\n",
  631. RREG32(mmUVD_CONTEXT_ID));
  632. }
  633. static int uvd_v6_0_set_interrupt_state(struct amdgpu_device *adev,
  634. struct amdgpu_irq_src *source,
  635. unsigned type,
  636. enum amdgpu_interrupt_state state)
  637. {
  638. // TODO
  639. return 0;
  640. }
  641. static int uvd_v6_0_process_interrupt(struct amdgpu_device *adev,
  642. struct amdgpu_irq_src *source,
  643. struct amdgpu_iv_entry *entry)
  644. {
  645. DRM_DEBUG("IH: UVD TRAP\n");
  646. amdgpu_fence_process(&adev->uvd.ring);
  647. return 0;
  648. }
  649. static int uvd_v6_0_set_clockgating_state(void *handle,
  650. enum amd_clockgating_state state)
  651. {
  652. return 0;
  653. }
  654. static int uvd_v6_0_set_powergating_state(void *handle,
  655. enum amd_powergating_state state)
  656. {
  657. /* This doesn't actually powergate the UVD block.
  658. * That's done in the dpm code via the SMC. This
  659. * just re-inits the block as necessary. The actual
  660. * gating still happens in the dpm code. We should
  661. * revisit this when there is a cleaner line between
  662. * the smc and the hw blocks
  663. */
  664. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  665. if (state == AMD_PG_STATE_GATE) {
  666. uvd_v6_0_stop(adev);
  667. return 0;
  668. } else {
  669. return uvd_v6_0_start(adev);
  670. }
  671. }
  672. const struct amd_ip_funcs uvd_v6_0_ip_funcs = {
  673. .early_init = uvd_v6_0_early_init,
  674. .late_init = NULL,
  675. .sw_init = uvd_v6_0_sw_init,
  676. .sw_fini = uvd_v6_0_sw_fini,
  677. .hw_init = uvd_v6_0_hw_init,
  678. .hw_fini = uvd_v6_0_hw_fini,
  679. .suspend = uvd_v6_0_suspend,
  680. .resume = uvd_v6_0_resume,
  681. .is_idle = uvd_v6_0_is_idle,
  682. .wait_for_idle = uvd_v6_0_wait_for_idle,
  683. .soft_reset = uvd_v6_0_soft_reset,
  684. .print_status = uvd_v6_0_print_status,
  685. .set_clockgating_state = uvd_v6_0_set_clockgating_state,
  686. .set_powergating_state = uvd_v6_0_set_powergating_state,
  687. };
  688. static const struct amdgpu_ring_funcs uvd_v6_0_ring_funcs = {
  689. .get_rptr = uvd_v6_0_ring_get_rptr,
  690. .get_wptr = uvd_v6_0_ring_get_wptr,
  691. .set_wptr = uvd_v6_0_ring_set_wptr,
  692. .parse_cs = amdgpu_uvd_ring_parse_cs,
  693. .emit_ib = uvd_v6_0_ring_emit_ib,
  694. .emit_fence = uvd_v6_0_ring_emit_fence,
  695. .emit_semaphore = uvd_v6_0_ring_emit_semaphore,
  696. .test_ring = uvd_v6_0_ring_test_ring,
  697. .test_ib = uvd_v6_0_ring_test_ib,
  698. .insert_nop = amdgpu_ring_insert_nop,
  699. };
  700. static void uvd_v6_0_set_ring_funcs(struct amdgpu_device *adev)
  701. {
  702. adev->uvd.ring.funcs = &uvd_v6_0_ring_funcs;
  703. }
  704. static const struct amdgpu_irq_src_funcs uvd_v6_0_irq_funcs = {
  705. .set = uvd_v6_0_set_interrupt_state,
  706. .process = uvd_v6_0_process_interrupt,
  707. };
  708. static void uvd_v6_0_set_irq_funcs(struct amdgpu_device *adev)
  709. {
  710. adev->uvd.irq.num_types = 1;
  711. adev->uvd.irq.funcs = &uvd_v6_0_irq_funcs;
  712. }