vce_v2_0.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. /*
  2. * Copyright 2013 Advanced Micro Devices, Inc.
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sub license, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  16. * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  17. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  18. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  19. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. *
  21. * The above copyright notice and this permission notice (including the
  22. * next paragraph) shall be included in all copies or substantial portions
  23. * of the Software.
  24. *
  25. * Authors: Christian König <christian.koenig@amd.com>
  26. */
  27. #include <linux/firmware.h>
  28. #include <drm/drmP.h>
  29. #include "amdgpu.h"
  30. #include "amdgpu_vce.h"
  31. #include "cikd.h"
  32. #include "vce/vce_2_0_d.h"
  33. #include "vce/vce_2_0_sh_mask.h"
  34. #include "oss/oss_2_0_d.h"
  35. #include "oss/oss_2_0_sh_mask.h"
  36. #define VCE_V2_0_FW_SIZE (256 * 1024)
  37. #define VCE_V2_0_STACK_SIZE (64 * 1024)
  38. #define VCE_V2_0_DATA_SIZE (23552 * AMDGPU_MAX_VCE_HANDLES)
  39. static void vce_v2_0_mc_resume(struct amdgpu_device *adev);
  40. static void vce_v2_0_set_ring_funcs(struct amdgpu_device *adev);
  41. static void vce_v2_0_set_irq_funcs(struct amdgpu_device *adev);
  42. /**
  43. * vce_v2_0_ring_get_rptr - get read pointer
  44. *
  45. * @ring: amdgpu_ring pointer
  46. *
  47. * Returns the current hardware read pointer
  48. */
  49. static uint32_t vce_v2_0_ring_get_rptr(struct amdgpu_ring *ring)
  50. {
  51. struct amdgpu_device *adev = ring->adev;
  52. if (ring == &adev->vce.ring[0])
  53. return RREG32(mmVCE_RB_RPTR);
  54. else
  55. return RREG32(mmVCE_RB_RPTR2);
  56. }
  57. /**
  58. * vce_v2_0_ring_get_wptr - get write pointer
  59. *
  60. * @ring: amdgpu_ring pointer
  61. *
  62. * Returns the current hardware write pointer
  63. */
  64. static uint32_t vce_v2_0_ring_get_wptr(struct amdgpu_ring *ring)
  65. {
  66. struct amdgpu_device *adev = ring->adev;
  67. if (ring == &adev->vce.ring[0])
  68. return RREG32(mmVCE_RB_WPTR);
  69. else
  70. return RREG32(mmVCE_RB_WPTR2);
  71. }
  72. /**
  73. * vce_v2_0_ring_set_wptr - set write pointer
  74. *
  75. * @ring: amdgpu_ring pointer
  76. *
  77. * Commits the write pointer to the hardware
  78. */
  79. static void vce_v2_0_ring_set_wptr(struct amdgpu_ring *ring)
  80. {
  81. struct amdgpu_device *adev = ring->adev;
  82. if (ring == &adev->vce.ring[0])
  83. WREG32(mmVCE_RB_WPTR, ring->wptr);
  84. else
  85. WREG32(mmVCE_RB_WPTR2, ring->wptr);
  86. }
  87. /**
  88. * vce_v2_0_start - start VCE block
  89. *
  90. * @adev: amdgpu_device pointer
  91. *
  92. * Setup and start the VCE block
  93. */
  94. static int vce_v2_0_start(struct amdgpu_device *adev)
  95. {
  96. struct amdgpu_ring *ring;
  97. int i, j, r;
  98. vce_v2_0_mc_resume(adev);
  99. /* set BUSY flag */
  100. WREG32_P(mmVCE_STATUS, 1, ~1);
  101. ring = &adev->vce.ring[0];
  102. WREG32(mmVCE_RB_RPTR, ring->wptr);
  103. WREG32(mmVCE_RB_WPTR, ring->wptr);
  104. WREG32(mmVCE_RB_BASE_LO, ring->gpu_addr);
  105. WREG32(mmVCE_RB_BASE_HI, upper_32_bits(ring->gpu_addr));
  106. WREG32(mmVCE_RB_SIZE, ring->ring_size / 4);
  107. ring = &adev->vce.ring[1];
  108. WREG32(mmVCE_RB_RPTR2, ring->wptr);
  109. WREG32(mmVCE_RB_WPTR2, ring->wptr);
  110. WREG32(mmVCE_RB_BASE_LO2, ring->gpu_addr);
  111. WREG32(mmVCE_RB_BASE_HI2, upper_32_bits(ring->gpu_addr));
  112. WREG32(mmVCE_RB_SIZE2, ring->ring_size / 4);
  113. WREG32_P(mmVCE_VCPU_CNTL, VCE_VCPU_CNTL__CLK_EN_MASK, ~VCE_VCPU_CNTL__CLK_EN_MASK);
  114. WREG32_P(mmVCE_SOFT_RESET,
  115. VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK,
  116. ~VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK);
  117. mdelay(100);
  118. WREG32_P(mmVCE_SOFT_RESET, 0, ~VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK);
  119. for (i = 0; i < 10; ++i) {
  120. uint32_t status;
  121. for (j = 0; j < 100; ++j) {
  122. status = RREG32(mmVCE_STATUS);
  123. if (status & 2)
  124. break;
  125. mdelay(10);
  126. }
  127. r = 0;
  128. if (status & 2)
  129. break;
  130. DRM_ERROR("VCE not responding, trying to reset the ECPU!!!\n");
  131. WREG32_P(mmVCE_SOFT_RESET, VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK,
  132. ~VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK);
  133. mdelay(10);
  134. WREG32_P(mmVCE_SOFT_RESET, 0, ~VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK);
  135. mdelay(10);
  136. r = -1;
  137. }
  138. /* clear BUSY flag */
  139. WREG32_P(mmVCE_STATUS, 0, ~1);
  140. if (r) {
  141. DRM_ERROR("VCE not responding, giving up!!!\n");
  142. return r;
  143. }
  144. return 0;
  145. }
  146. static int vce_v2_0_early_init(void *handle)
  147. {
  148. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  149. vce_v2_0_set_ring_funcs(adev);
  150. vce_v2_0_set_irq_funcs(adev);
  151. return 0;
  152. }
  153. static int vce_v2_0_sw_init(void *handle)
  154. {
  155. struct amdgpu_ring *ring;
  156. int r;
  157. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  158. /* VCE */
  159. r = amdgpu_irq_add_id(adev, 167, &adev->vce.irq);
  160. if (r)
  161. return r;
  162. r = amdgpu_vce_sw_init(adev, VCE_V2_0_FW_SIZE +
  163. VCE_V2_0_STACK_SIZE + VCE_V2_0_DATA_SIZE);
  164. if (r)
  165. return r;
  166. r = amdgpu_vce_resume(adev);
  167. if (r)
  168. return r;
  169. ring = &adev->vce.ring[0];
  170. sprintf(ring->name, "vce0");
  171. r = amdgpu_ring_init(adev, ring, 4096, VCE_CMD_NO_OP, 0xf,
  172. &adev->vce.irq, 0, AMDGPU_RING_TYPE_VCE);
  173. if (r)
  174. return r;
  175. ring = &adev->vce.ring[1];
  176. sprintf(ring->name, "vce1");
  177. r = amdgpu_ring_init(adev, ring, 4096, VCE_CMD_NO_OP, 0xf,
  178. &adev->vce.irq, 0, AMDGPU_RING_TYPE_VCE);
  179. if (r)
  180. return r;
  181. return r;
  182. }
  183. static int vce_v2_0_sw_fini(void *handle)
  184. {
  185. int r;
  186. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  187. r = amdgpu_vce_suspend(adev);
  188. if (r)
  189. return r;
  190. r = amdgpu_vce_sw_fini(adev);
  191. if (r)
  192. return r;
  193. return r;
  194. }
  195. static int vce_v2_0_hw_init(void *handle)
  196. {
  197. struct amdgpu_ring *ring;
  198. int r;
  199. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  200. r = vce_v2_0_start(adev);
  201. if (r)
  202. return r;
  203. ring = &adev->vce.ring[0];
  204. ring->ready = true;
  205. r = amdgpu_ring_test_ring(ring);
  206. if (r) {
  207. ring->ready = false;
  208. return r;
  209. }
  210. ring = &adev->vce.ring[1];
  211. ring->ready = true;
  212. r = amdgpu_ring_test_ring(ring);
  213. if (r) {
  214. ring->ready = false;
  215. return r;
  216. }
  217. DRM_INFO("VCE initialized successfully.\n");
  218. return 0;
  219. }
  220. static int vce_v2_0_hw_fini(void *handle)
  221. {
  222. return 0;
  223. }
  224. static int vce_v2_0_suspend(void *handle)
  225. {
  226. int r;
  227. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  228. r = vce_v2_0_hw_fini(adev);
  229. if (r)
  230. return r;
  231. r = amdgpu_vce_suspend(adev);
  232. if (r)
  233. return r;
  234. return r;
  235. }
  236. static int vce_v2_0_resume(void *handle)
  237. {
  238. int r;
  239. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  240. r = amdgpu_vce_resume(adev);
  241. if (r)
  242. return r;
  243. r = vce_v2_0_hw_init(adev);
  244. if (r)
  245. return r;
  246. return r;
  247. }
  248. static void vce_v2_0_set_sw_cg(struct amdgpu_device *adev, bool gated)
  249. {
  250. u32 tmp;
  251. if (gated) {
  252. tmp = RREG32(mmVCE_CLOCK_GATING_B);
  253. tmp |= 0xe70000;
  254. WREG32(mmVCE_CLOCK_GATING_B, tmp);
  255. tmp = RREG32(mmVCE_UENC_CLOCK_GATING);
  256. tmp |= 0xff000000;
  257. WREG32(mmVCE_UENC_CLOCK_GATING, tmp);
  258. tmp = RREG32(mmVCE_UENC_REG_CLOCK_GATING);
  259. tmp &= ~0x3fc;
  260. WREG32(mmVCE_UENC_REG_CLOCK_GATING, tmp);
  261. WREG32(mmVCE_CGTT_CLK_OVERRIDE, 0);
  262. } else {
  263. tmp = RREG32(mmVCE_CLOCK_GATING_B);
  264. tmp |= 0xe7;
  265. tmp &= ~0xe70000;
  266. WREG32(mmVCE_CLOCK_GATING_B, tmp);
  267. tmp = RREG32(mmVCE_UENC_CLOCK_GATING);
  268. tmp |= 0x1fe000;
  269. tmp &= ~0xff000000;
  270. WREG32(mmVCE_UENC_CLOCK_GATING, tmp);
  271. tmp = RREG32(mmVCE_UENC_REG_CLOCK_GATING);
  272. tmp |= 0x3fc;
  273. WREG32(mmVCE_UENC_REG_CLOCK_GATING, tmp);
  274. }
  275. }
  276. static void vce_v2_0_set_dyn_cg(struct amdgpu_device *adev, bool gated)
  277. {
  278. u32 orig, tmp;
  279. tmp = RREG32(mmVCE_CLOCK_GATING_B);
  280. tmp &= ~0x00060006;
  281. if (gated) {
  282. tmp |= 0xe10000;
  283. } else {
  284. tmp |= 0xe1;
  285. tmp &= ~0xe10000;
  286. }
  287. WREG32(mmVCE_CLOCK_GATING_B, tmp);
  288. orig = tmp = RREG32(mmVCE_UENC_CLOCK_GATING);
  289. tmp &= ~0x1fe000;
  290. tmp &= ~0xff000000;
  291. if (tmp != orig)
  292. WREG32(mmVCE_UENC_CLOCK_GATING, tmp);
  293. orig = tmp = RREG32(mmVCE_UENC_REG_CLOCK_GATING);
  294. tmp &= ~0x3fc;
  295. if (tmp != orig)
  296. WREG32(mmVCE_UENC_REG_CLOCK_GATING, tmp);
  297. if (gated)
  298. WREG32(mmVCE_CGTT_CLK_OVERRIDE, 0);
  299. }
  300. static void vce_v2_0_disable_cg(struct amdgpu_device *adev)
  301. {
  302. WREG32(mmVCE_CGTT_CLK_OVERRIDE, 7);
  303. }
  304. static void vce_v2_0_enable_mgcg(struct amdgpu_device *adev, bool enable)
  305. {
  306. bool sw_cg = false;
  307. if (enable && (adev->cg_flags & AMDGPU_CG_SUPPORT_VCE_MGCG)) {
  308. if (sw_cg)
  309. vce_v2_0_set_sw_cg(adev, true);
  310. else
  311. vce_v2_0_set_dyn_cg(adev, true);
  312. } else {
  313. vce_v2_0_disable_cg(adev);
  314. if (sw_cg)
  315. vce_v2_0_set_sw_cg(adev, false);
  316. else
  317. vce_v2_0_set_dyn_cg(adev, false);
  318. }
  319. }
  320. static void vce_v2_0_init_cg(struct amdgpu_device *adev)
  321. {
  322. u32 tmp;
  323. tmp = RREG32(mmVCE_CLOCK_GATING_A);
  324. tmp &= ~0xfff;
  325. tmp |= ((0 << 0) | (4 << 4));
  326. tmp |= 0x40000;
  327. WREG32(mmVCE_CLOCK_GATING_A, tmp);
  328. tmp = RREG32(mmVCE_UENC_CLOCK_GATING);
  329. tmp &= ~0xfff;
  330. tmp |= ((0 << 0) | (4 << 4));
  331. WREG32(mmVCE_UENC_CLOCK_GATING, tmp);
  332. tmp = RREG32(mmVCE_CLOCK_GATING_B);
  333. tmp |= 0x10;
  334. tmp &= ~0x100000;
  335. WREG32(mmVCE_CLOCK_GATING_B, tmp);
  336. }
  337. static void vce_v2_0_mc_resume(struct amdgpu_device *adev)
  338. {
  339. uint64_t addr = adev->vce.gpu_addr;
  340. uint32_t size;
  341. WREG32_P(mmVCE_CLOCK_GATING_A, 0, ~(1 << 16));
  342. WREG32_P(mmVCE_UENC_CLOCK_GATING, 0x1FF000, ~0xFF9FF000);
  343. WREG32_P(mmVCE_UENC_REG_CLOCK_GATING, 0x3F, ~0x3F);
  344. WREG32(mmVCE_CLOCK_GATING_B, 0xf7);
  345. WREG32(mmVCE_LMI_CTRL, 0x00398000);
  346. WREG32_P(mmVCE_LMI_CACHE_CTRL, 0x0, ~0x1);
  347. WREG32(mmVCE_LMI_SWAP_CNTL, 0);
  348. WREG32(mmVCE_LMI_SWAP_CNTL1, 0);
  349. WREG32(mmVCE_LMI_VM_CTRL, 0);
  350. addr += AMDGPU_VCE_FIRMWARE_OFFSET;
  351. size = VCE_V2_0_FW_SIZE;
  352. WREG32(mmVCE_VCPU_CACHE_OFFSET0, addr & 0x7fffffff);
  353. WREG32(mmVCE_VCPU_CACHE_SIZE0, size);
  354. addr += size;
  355. size = VCE_V2_0_STACK_SIZE;
  356. WREG32(mmVCE_VCPU_CACHE_OFFSET1, addr & 0x7fffffff);
  357. WREG32(mmVCE_VCPU_CACHE_SIZE1, size);
  358. addr += size;
  359. size = VCE_V2_0_DATA_SIZE;
  360. WREG32(mmVCE_VCPU_CACHE_OFFSET2, addr & 0x7fffffff);
  361. WREG32(mmVCE_VCPU_CACHE_SIZE2, size);
  362. WREG32_P(mmVCE_LMI_CTRL2, 0x0, ~0x100);
  363. WREG32_P(mmVCE_SYS_INT_EN, VCE_SYS_INT_EN__VCE_SYS_INT_TRAP_INTERRUPT_EN_MASK,
  364. ~VCE_SYS_INT_EN__VCE_SYS_INT_TRAP_INTERRUPT_EN_MASK);
  365. vce_v2_0_init_cg(adev);
  366. }
  367. static bool vce_v2_0_is_idle(void *handle)
  368. {
  369. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  370. return !(RREG32(mmSRBM_STATUS2) & SRBM_STATUS2__VCE_BUSY_MASK);
  371. }
  372. static int vce_v2_0_wait_for_idle(void *handle)
  373. {
  374. unsigned i;
  375. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  376. for (i = 0; i < adev->usec_timeout; i++) {
  377. if (!(RREG32(mmSRBM_STATUS2) & SRBM_STATUS2__VCE_BUSY_MASK))
  378. return 0;
  379. }
  380. return -ETIMEDOUT;
  381. }
  382. static int vce_v2_0_soft_reset(void *handle)
  383. {
  384. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  385. WREG32_P(mmSRBM_SOFT_RESET, SRBM_SOFT_RESET__SOFT_RESET_VCE_MASK,
  386. ~SRBM_SOFT_RESET__SOFT_RESET_VCE_MASK);
  387. mdelay(5);
  388. return vce_v2_0_start(adev);
  389. }
  390. static void vce_v2_0_print_status(void *handle)
  391. {
  392. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  393. dev_info(adev->dev, "VCE 2.0 registers\n");
  394. dev_info(adev->dev, " VCE_STATUS=0x%08X\n",
  395. RREG32(mmVCE_STATUS));
  396. dev_info(adev->dev, " VCE_VCPU_CNTL=0x%08X\n",
  397. RREG32(mmVCE_VCPU_CNTL));
  398. dev_info(adev->dev, " VCE_VCPU_CACHE_OFFSET0=0x%08X\n",
  399. RREG32(mmVCE_VCPU_CACHE_OFFSET0));
  400. dev_info(adev->dev, " VCE_VCPU_CACHE_SIZE0=0x%08X\n",
  401. RREG32(mmVCE_VCPU_CACHE_SIZE0));
  402. dev_info(adev->dev, " VCE_VCPU_CACHE_OFFSET1=0x%08X\n",
  403. RREG32(mmVCE_VCPU_CACHE_OFFSET1));
  404. dev_info(adev->dev, " VCE_VCPU_CACHE_SIZE1=0x%08X\n",
  405. RREG32(mmVCE_VCPU_CACHE_SIZE1));
  406. dev_info(adev->dev, " VCE_VCPU_CACHE_OFFSET2=0x%08X\n",
  407. RREG32(mmVCE_VCPU_CACHE_OFFSET2));
  408. dev_info(adev->dev, " VCE_VCPU_CACHE_SIZE2=0x%08X\n",
  409. RREG32(mmVCE_VCPU_CACHE_SIZE2));
  410. dev_info(adev->dev, " VCE_SOFT_RESET=0x%08X\n",
  411. RREG32(mmVCE_SOFT_RESET));
  412. dev_info(adev->dev, " VCE_RB_BASE_LO2=0x%08X\n",
  413. RREG32(mmVCE_RB_BASE_LO2));
  414. dev_info(adev->dev, " VCE_RB_BASE_HI2=0x%08X\n",
  415. RREG32(mmVCE_RB_BASE_HI2));
  416. dev_info(adev->dev, " VCE_RB_SIZE2=0x%08X\n",
  417. RREG32(mmVCE_RB_SIZE2));
  418. dev_info(adev->dev, " VCE_RB_RPTR2=0x%08X\n",
  419. RREG32(mmVCE_RB_RPTR2));
  420. dev_info(adev->dev, " VCE_RB_WPTR2=0x%08X\n",
  421. RREG32(mmVCE_RB_WPTR2));
  422. dev_info(adev->dev, " VCE_RB_BASE_LO=0x%08X\n",
  423. RREG32(mmVCE_RB_BASE_LO));
  424. dev_info(adev->dev, " VCE_RB_BASE_HI=0x%08X\n",
  425. RREG32(mmVCE_RB_BASE_HI));
  426. dev_info(adev->dev, " VCE_RB_SIZE=0x%08X\n",
  427. RREG32(mmVCE_RB_SIZE));
  428. dev_info(adev->dev, " VCE_RB_RPTR=0x%08X\n",
  429. RREG32(mmVCE_RB_RPTR));
  430. dev_info(adev->dev, " VCE_RB_WPTR=0x%08X\n",
  431. RREG32(mmVCE_RB_WPTR));
  432. dev_info(adev->dev, " VCE_CLOCK_GATING_A=0x%08X\n",
  433. RREG32(mmVCE_CLOCK_GATING_A));
  434. dev_info(adev->dev, " VCE_CLOCK_GATING_B=0x%08X\n",
  435. RREG32(mmVCE_CLOCK_GATING_B));
  436. dev_info(adev->dev, " VCE_CGTT_CLK_OVERRIDE=0x%08X\n",
  437. RREG32(mmVCE_CGTT_CLK_OVERRIDE));
  438. dev_info(adev->dev, " VCE_UENC_CLOCK_GATING=0x%08X\n",
  439. RREG32(mmVCE_UENC_CLOCK_GATING));
  440. dev_info(adev->dev, " VCE_UENC_REG_CLOCK_GATING=0x%08X\n",
  441. RREG32(mmVCE_UENC_REG_CLOCK_GATING));
  442. dev_info(adev->dev, " VCE_SYS_INT_EN=0x%08X\n",
  443. RREG32(mmVCE_SYS_INT_EN));
  444. dev_info(adev->dev, " VCE_LMI_CTRL2=0x%08X\n",
  445. RREG32(mmVCE_LMI_CTRL2));
  446. dev_info(adev->dev, " VCE_LMI_CTRL=0x%08X\n",
  447. RREG32(mmVCE_LMI_CTRL));
  448. dev_info(adev->dev, " VCE_LMI_VM_CTRL=0x%08X\n",
  449. RREG32(mmVCE_LMI_VM_CTRL));
  450. dev_info(adev->dev, " VCE_LMI_SWAP_CNTL=0x%08X\n",
  451. RREG32(mmVCE_LMI_SWAP_CNTL));
  452. dev_info(adev->dev, " VCE_LMI_SWAP_CNTL1=0x%08X\n",
  453. RREG32(mmVCE_LMI_SWAP_CNTL1));
  454. dev_info(adev->dev, " VCE_LMI_CACHE_CTRL=0x%08X\n",
  455. RREG32(mmVCE_LMI_CACHE_CTRL));
  456. }
  457. static int vce_v2_0_set_interrupt_state(struct amdgpu_device *adev,
  458. struct amdgpu_irq_src *source,
  459. unsigned type,
  460. enum amdgpu_interrupt_state state)
  461. {
  462. uint32_t val = 0;
  463. if (state == AMDGPU_IRQ_STATE_ENABLE)
  464. val |= VCE_SYS_INT_EN__VCE_SYS_INT_TRAP_INTERRUPT_EN_MASK;
  465. WREG32_P(mmVCE_SYS_INT_EN, val, ~VCE_SYS_INT_EN__VCE_SYS_INT_TRAP_INTERRUPT_EN_MASK);
  466. return 0;
  467. }
  468. static int vce_v2_0_process_interrupt(struct amdgpu_device *adev,
  469. struct amdgpu_irq_src *source,
  470. struct amdgpu_iv_entry *entry)
  471. {
  472. DRM_DEBUG("IH: VCE\n");
  473. switch (entry->src_data) {
  474. case 0:
  475. amdgpu_fence_process(&adev->vce.ring[0]);
  476. break;
  477. case 1:
  478. amdgpu_fence_process(&adev->vce.ring[1]);
  479. break;
  480. default:
  481. DRM_ERROR("Unhandled interrupt: %d %d\n",
  482. entry->src_id, entry->src_data);
  483. break;
  484. }
  485. return 0;
  486. }
  487. static int vce_v2_0_set_clockgating_state(void *handle,
  488. enum amd_clockgating_state state)
  489. {
  490. bool gate = false;
  491. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  492. if (state == AMD_CG_STATE_GATE)
  493. gate = true;
  494. vce_v2_0_enable_mgcg(adev, gate);
  495. return 0;
  496. }
  497. static int vce_v2_0_set_powergating_state(void *handle,
  498. enum amd_powergating_state state)
  499. {
  500. /* This doesn't actually powergate the VCE block.
  501. * That's done in the dpm code via the SMC. This
  502. * just re-inits the block as necessary. The actual
  503. * gating still happens in the dpm code. We should
  504. * revisit this when there is a cleaner line between
  505. * the smc and the hw blocks
  506. */
  507. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  508. if (state == AMD_PG_STATE_GATE)
  509. /* XXX do we need a vce_v2_0_stop()? */
  510. return 0;
  511. else
  512. return vce_v2_0_start(adev);
  513. }
  514. const struct amd_ip_funcs vce_v2_0_ip_funcs = {
  515. .early_init = vce_v2_0_early_init,
  516. .late_init = NULL,
  517. .sw_init = vce_v2_0_sw_init,
  518. .sw_fini = vce_v2_0_sw_fini,
  519. .hw_init = vce_v2_0_hw_init,
  520. .hw_fini = vce_v2_0_hw_fini,
  521. .suspend = vce_v2_0_suspend,
  522. .resume = vce_v2_0_resume,
  523. .is_idle = vce_v2_0_is_idle,
  524. .wait_for_idle = vce_v2_0_wait_for_idle,
  525. .soft_reset = vce_v2_0_soft_reset,
  526. .print_status = vce_v2_0_print_status,
  527. .set_clockgating_state = vce_v2_0_set_clockgating_state,
  528. .set_powergating_state = vce_v2_0_set_powergating_state,
  529. };
  530. static const struct amdgpu_ring_funcs vce_v2_0_ring_funcs = {
  531. .get_rptr = vce_v2_0_ring_get_rptr,
  532. .get_wptr = vce_v2_0_ring_get_wptr,
  533. .set_wptr = vce_v2_0_ring_set_wptr,
  534. .parse_cs = amdgpu_vce_ring_parse_cs,
  535. .emit_ib = amdgpu_vce_ring_emit_ib,
  536. .emit_fence = amdgpu_vce_ring_emit_fence,
  537. .emit_semaphore = amdgpu_vce_ring_emit_semaphore,
  538. .test_ring = amdgpu_vce_ring_test_ring,
  539. .test_ib = amdgpu_vce_ring_test_ib,
  540. .insert_nop = amdgpu_ring_insert_nop,
  541. };
  542. static void vce_v2_0_set_ring_funcs(struct amdgpu_device *adev)
  543. {
  544. adev->vce.ring[0].funcs = &vce_v2_0_ring_funcs;
  545. adev->vce.ring[1].funcs = &vce_v2_0_ring_funcs;
  546. }
  547. static const struct amdgpu_irq_src_funcs vce_v2_0_irq_funcs = {
  548. .set = vce_v2_0_set_interrupt_state,
  549. .process = vce_v2_0_process_interrupt,
  550. };
  551. static void vce_v2_0_set_irq_funcs(struct amdgpu_device *adev)
  552. {
  553. adev->vce.irq.num_types = 1;
  554. adev->vce.irq.funcs = &vce_v2_0_irq_funcs;
  555. };