vce_v3_0.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. /*
  2. * Copyright 2014 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 "vid.h"
  32. #include "vce/vce_3_0_d.h"
  33. #include "vce/vce_3_0_sh_mask.h"
  34. #include "oss/oss_3_0_d.h"
  35. #include "oss/oss_3_0_sh_mask.h"
  36. #include "gca/gfx_8_0_d.h"
  37. #include "smu/smu_7_1_2_d.h"
  38. #include "smu/smu_7_1_2_sh_mask.h"
  39. #define GRBM_GFX_INDEX__VCE_INSTANCE__SHIFT 0x04
  40. #define GRBM_GFX_INDEX__VCE_INSTANCE_MASK 0x10
  41. #define VCE_V3_0_FW_SIZE (384 * 1024)
  42. #define VCE_V3_0_STACK_SIZE (64 * 1024)
  43. #define VCE_V3_0_DATA_SIZE ((16 * 1024 * AMDGPU_MAX_VCE_HANDLES) + (52 * 1024))
  44. static void vce_v3_0_mc_resume(struct amdgpu_device *adev, int idx);
  45. static void vce_v3_0_set_ring_funcs(struct amdgpu_device *adev);
  46. static void vce_v3_0_set_irq_funcs(struct amdgpu_device *adev);
  47. /**
  48. * vce_v3_0_ring_get_rptr - get read pointer
  49. *
  50. * @ring: amdgpu_ring pointer
  51. *
  52. * Returns the current hardware read pointer
  53. */
  54. static uint32_t vce_v3_0_ring_get_rptr(struct amdgpu_ring *ring)
  55. {
  56. struct amdgpu_device *adev = ring->adev;
  57. if (ring == &adev->vce.ring[0])
  58. return RREG32(mmVCE_RB_RPTR);
  59. else
  60. return RREG32(mmVCE_RB_RPTR2);
  61. }
  62. /**
  63. * vce_v3_0_ring_get_wptr - get write pointer
  64. *
  65. * @ring: amdgpu_ring pointer
  66. *
  67. * Returns the current hardware write pointer
  68. */
  69. static uint32_t vce_v3_0_ring_get_wptr(struct amdgpu_ring *ring)
  70. {
  71. struct amdgpu_device *adev = ring->adev;
  72. if (ring == &adev->vce.ring[0])
  73. return RREG32(mmVCE_RB_WPTR);
  74. else
  75. return RREG32(mmVCE_RB_WPTR2);
  76. }
  77. /**
  78. * vce_v3_0_ring_set_wptr - set write pointer
  79. *
  80. * @ring: amdgpu_ring pointer
  81. *
  82. * Commits the write pointer to the hardware
  83. */
  84. static void vce_v3_0_ring_set_wptr(struct amdgpu_ring *ring)
  85. {
  86. struct amdgpu_device *adev = ring->adev;
  87. if (ring == &adev->vce.ring[0])
  88. WREG32(mmVCE_RB_WPTR, ring->wptr);
  89. else
  90. WREG32(mmVCE_RB_WPTR2, ring->wptr);
  91. }
  92. /**
  93. * vce_v3_0_start - start VCE block
  94. *
  95. * @adev: amdgpu_device pointer
  96. *
  97. * Setup and start the VCE block
  98. */
  99. static int vce_v3_0_start(struct amdgpu_device *adev)
  100. {
  101. struct amdgpu_ring *ring;
  102. int idx, i, j, r;
  103. mutex_lock(&adev->grbm_idx_mutex);
  104. for (idx = 0; idx < 2; ++idx) {
  105. if (adev->vce.harvest_config & (1 << idx))
  106. continue;
  107. if(idx == 0)
  108. WREG32_P(mmGRBM_GFX_INDEX, 0,
  109. ~GRBM_GFX_INDEX__VCE_INSTANCE_MASK);
  110. else
  111. WREG32_P(mmGRBM_GFX_INDEX,
  112. GRBM_GFX_INDEX__VCE_INSTANCE_MASK,
  113. ~GRBM_GFX_INDEX__VCE_INSTANCE_MASK);
  114. vce_v3_0_mc_resume(adev, idx);
  115. /* set BUSY flag */
  116. WREG32_P(mmVCE_STATUS, 1, ~1);
  117. WREG32_P(mmVCE_VCPU_CNTL, VCE_VCPU_CNTL__CLK_EN_MASK,
  118. ~VCE_VCPU_CNTL__CLK_EN_MASK);
  119. WREG32_P(mmVCE_SOFT_RESET,
  120. VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK,
  121. ~VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK);
  122. mdelay(100);
  123. WREG32_P(mmVCE_SOFT_RESET, 0,
  124. ~VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK);
  125. for (i = 0; i < 10; ++i) {
  126. uint32_t status;
  127. for (j = 0; j < 100; ++j) {
  128. status = RREG32(mmVCE_STATUS);
  129. if (status & 2)
  130. break;
  131. mdelay(10);
  132. }
  133. r = 0;
  134. if (status & 2)
  135. break;
  136. DRM_ERROR("VCE not responding, trying to reset the ECPU!!!\n");
  137. WREG32_P(mmVCE_SOFT_RESET,
  138. VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK,
  139. ~VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK);
  140. mdelay(10);
  141. WREG32_P(mmVCE_SOFT_RESET, 0,
  142. ~VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK);
  143. mdelay(10);
  144. r = -1;
  145. }
  146. /* clear BUSY flag */
  147. WREG32_P(mmVCE_STATUS, 0, ~1);
  148. if (r) {
  149. DRM_ERROR("VCE not responding, giving up!!!\n");
  150. mutex_unlock(&adev->grbm_idx_mutex);
  151. return r;
  152. }
  153. }
  154. WREG32_P(mmGRBM_GFX_INDEX, 0, ~GRBM_GFX_INDEX__VCE_INSTANCE_MASK);
  155. mutex_unlock(&adev->grbm_idx_mutex);
  156. ring = &adev->vce.ring[0];
  157. WREG32(mmVCE_RB_RPTR, ring->wptr);
  158. WREG32(mmVCE_RB_WPTR, ring->wptr);
  159. WREG32(mmVCE_RB_BASE_LO, ring->gpu_addr);
  160. WREG32(mmVCE_RB_BASE_HI, upper_32_bits(ring->gpu_addr));
  161. WREG32(mmVCE_RB_SIZE, ring->ring_size / 4);
  162. ring = &adev->vce.ring[1];
  163. WREG32(mmVCE_RB_RPTR2, ring->wptr);
  164. WREG32(mmVCE_RB_WPTR2, ring->wptr);
  165. WREG32(mmVCE_RB_BASE_LO2, ring->gpu_addr);
  166. WREG32(mmVCE_RB_BASE_HI2, upper_32_bits(ring->gpu_addr));
  167. WREG32(mmVCE_RB_SIZE2, ring->ring_size / 4);
  168. return 0;
  169. }
  170. #define ixVCE_HARVEST_FUSE_MACRO__ADDRESS 0xC0014074
  171. #define VCE_HARVEST_FUSE_MACRO__SHIFT 27
  172. #define VCE_HARVEST_FUSE_MACRO__MASK 0x18000000
  173. static unsigned vce_v3_0_get_harvest_config(struct amdgpu_device *adev)
  174. {
  175. u32 tmp;
  176. unsigned ret;
  177. /* Fiji is single pipe */
  178. if (adev->asic_type == CHIP_FIJI) {
  179. ret = AMDGPU_VCE_HARVEST_VCE1;
  180. return ret;
  181. }
  182. /* Tonga and CZ are dual or single pipe */
  183. if (adev->flags & AMD_IS_APU)
  184. tmp = (RREG32_SMC(ixVCE_HARVEST_FUSE_MACRO__ADDRESS) &
  185. VCE_HARVEST_FUSE_MACRO__MASK) >>
  186. VCE_HARVEST_FUSE_MACRO__SHIFT;
  187. else
  188. tmp = (RREG32_SMC(ixCC_HARVEST_FUSES) &
  189. CC_HARVEST_FUSES__VCE_DISABLE_MASK) >>
  190. CC_HARVEST_FUSES__VCE_DISABLE__SHIFT;
  191. switch (tmp) {
  192. case 1:
  193. ret = AMDGPU_VCE_HARVEST_VCE0;
  194. break;
  195. case 2:
  196. ret = AMDGPU_VCE_HARVEST_VCE1;
  197. break;
  198. case 3:
  199. ret = AMDGPU_VCE_HARVEST_VCE0 | AMDGPU_VCE_HARVEST_VCE1;
  200. break;
  201. default:
  202. ret = 0;
  203. }
  204. return ret;
  205. }
  206. static int vce_v3_0_early_init(void *handle)
  207. {
  208. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  209. adev->vce.harvest_config = vce_v3_0_get_harvest_config(adev);
  210. if ((adev->vce.harvest_config &
  211. (AMDGPU_VCE_HARVEST_VCE0 | AMDGPU_VCE_HARVEST_VCE1)) ==
  212. (AMDGPU_VCE_HARVEST_VCE0 | AMDGPU_VCE_HARVEST_VCE1))
  213. return -ENOENT;
  214. vce_v3_0_set_ring_funcs(adev);
  215. vce_v3_0_set_irq_funcs(adev);
  216. return 0;
  217. }
  218. static int vce_v3_0_sw_init(void *handle)
  219. {
  220. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  221. struct amdgpu_ring *ring;
  222. int r;
  223. /* VCE */
  224. r = amdgpu_irq_add_id(adev, 167, &adev->vce.irq);
  225. if (r)
  226. return r;
  227. r = amdgpu_vce_sw_init(adev, VCE_V3_0_FW_SIZE +
  228. (VCE_V3_0_STACK_SIZE + VCE_V3_0_DATA_SIZE) * 2);
  229. if (r)
  230. return r;
  231. r = amdgpu_vce_resume(adev);
  232. if (r)
  233. return r;
  234. ring = &adev->vce.ring[0];
  235. sprintf(ring->name, "vce0");
  236. r = amdgpu_ring_init(adev, ring, 4096, VCE_CMD_NO_OP, 0xf,
  237. &adev->vce.irq, 0, AMDGPU_RING_TYPE_VCE);
  238. if (r)
  239. return r;
  240. ring = &adev->vce.ring[1];
  241. sprintf(ring->name, "vce1");
  242. r = amdgpu_ring_init(adev, ring, 4096, VCE_CMD_NO_OP, 0xf,
  243. &adev->vce.irq, 0, AMDGPU_RING_TYPE_VCE);
  244. if (r)
  245. return r;
  246. return r;
  247. }
  248. static int vce_v3_0_sw_fini(void *handle)
  249. {
  250. int r;
  251. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  252. r = amdgpu_vce_suspend(adev);
  253. if (r)
  254. return r;
  255. r = amdgpu_vce_sw_fini(adev);
  256. if (r)
  257. return r;
  258. return r;
  259. }
  260. static int vce_v3_0_hw_init(void *handle)
  261. {
  262. struct amdgpu_ring *ring;
  263. int r;
  264. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  265. r = vce_v3_0_start(adev);
  266. if (r)
  267. return r;
  268. ring = &adev->vce.ring[0];
  269. ring->ready = true;
  270. r = amdgpu_ring_test_ring(ring);
  271. if (r) {
  272. ring->ready = false;
  273. return r;
  274. }
  275. ring = &adev->vce.ring[1];
  276. ring->ready = true;
  277. r = amdgpu_ring_test_ring(ring);
  278. if (r) {
  279. ring->ready = false;
  280. return r;
  281. }
  282. DRM_INFO("VCE initialized successfully.\n");
  283. return 0;
  284. }
  285. static int vce_v3_0_hw_fini(void *handle)
  286. {
  287. return 0;
  288. }
  289. static int vce_v3_0_suspend(void *handle)
  290. {
  291. int r;
  292. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  293. r = vce_v3_0_hw_fini(adev);
  294. if (r)
  295. return r;
  296. r = amdgpu_vce_suspend(adev);
  297. if (r)
  298. return r;
  299. return r;
  300. }
  301. static int vce_v3_0_resume(void *handle)
  302. {
  303. int r;
  304. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  305. r = amdgpu_vce_resume(adev);
  306. if (r)
  307. return r;
  308. r = vce_v3_0_hw_init(adev);
  309. if (r)
  310. return r;
  311. return r;
  312. }
  313. static void vce_v3_0_mc_resume(struct amdgpu_device *adev, int idx)
  314. {
  315. uint32_t offset, size;
  316. WREG32_P(mmVCE_CLOCK_GATING_A, 0, ~(1 << 16));
  317. WREG32_P(mmVCE_UENC_CLOCK_GATING, 0x1FF000, ~0xFF9FF000);
  318. WREG32_P(mmVCE_UENC_REG_CLOCK_GATING, 0x3F, ~0x3F);
  319. WREG32(mmVCE_CLOCK_GATING_B, 0xf7);
  320. WREG32(mmVCE_LMI_CTRL, 0x00398000);
  321. WREG32_P(mmVCE_LMI_CACHE_CTRL, 0x0, ~0x1);
  322. WREG32(mmVCE_LMI_SWAP_CNTL, 0);
  323. WREG32(mmVCE_LMI_SWAP_CNTL1, 0);
  324. WREG32(mmVCE_LMI_VM_CTRL, 0);
  325. WREG32(mmVCE_LMI_VCPU_CACHE_40BIT_BAR, (adev->vce.gpu_addr >> 8));
  326. offset = AMDGPU_VCE_FIRMWARE_OFFSET;
  327. size = VCE_V3_0_FW_SIZE;
  328. WREG32(mmVCE_VCPU_CACHE_OFFSET0, offset & 0x7fffffff);
  329. WREG32(mmVCE_VCPU_CACHE_SIZE0, size);
  330. if (idx == 0) {
  331. offset += size;
  332. size = VCE_V3_0_STACK_SIZE;
  333. WREG32(mmVCE_VCPU_CACHE_OFFSET1, offset & 0x7fffffff);
  334. WREG32(mmVCE_VCPU_CACHE_SIZE1, size);
  335. offset += size;
  336. size = VCE_V3_0_DATA_SIZE;
  337. WREG32(mmVCE_VCPU_CACHE_OFFSET2, offset & 0x7fffffff);
  338. WREG32(mmVCE_VCPU_CACHE_SIZE2, size);
  339. } else {
  340. offset += size + VCE_V3_0_STACK_SIZE + VCE_V3_0_DATA_SIZE;
  341. size = VCE_V3_0_STACK_SIZE;
  342. WREG32(mmVCE_VCPU_CACHE_OFFSET1, offset & 0xfffffff);
  343. WREG32(mmVCE_VCPU_CACHE_SIZE1, size);
  344. offset += size;
  345. size = VCE_V3_0_DATA_SIZE;
  346. WREG32(mmVCE_VCPU_CACHE_OFFSET2, offset & 0xfffffff);
  347. WREG32(mmVCE_VCPU_CACHE_SIZE2, size);
  348. }
  349. WREG32_P(mmVCE_LMI_CTRL2, 0x0, ~0x100);
  350. WREG32_P(mmVCE_SYS_INT_EN, VCE_SYS_INT_EN__VCE_SYS_INT_TRAP_INTERRUPT_EN_MASK,
  351. ~VCE_SYS_INT_EN__VCE_SYS_INT_TRAP_INTERRUPT_EN_MASK);
  352. }
  353. static bool vce_v3_0_is_idle(void *handle)
  354. {
  355. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  356. u32 mask = 0;
  357. int idx;
  358. for (idx = 0; idx < 2; ++idx) {
  359. if (adev->vce.harvest_config & (1 << idx))
  360. continue;
  361. if (idx == 0)
  362. mask |= SRBM_STATUS2__VCE0_BUSY_MASK;
  363. else
  364. mask |= SRBM_STATUS2__VCE1_BUSY_MASK;
  365. }
  366. return !(RREG32(mmSRBM_STATUS2) & mask);
  367. }
  368. static int vce_v3_0_wait_for_idle(void *handle)
  369. {
  370. unsigned i;
  371. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  372. u32 mask = 0;
  373. int idx;
  374. for (idx = 0; idx < 2; ++idx) {
  375. if (adev->vce.harvest_config & (1 << idx))
  376. continue;
  377. if (idx == 0)
  378. mask |= SRBM_STATUS2__VCE0_BUSY_MASK;
  379. else
  380. mask |= SRBM_STATUS2__VCE1_BUSY_MASK;
  381. }
  382. for (i = 0; i < adev->usec_timeout; i++) {
  383. if (!(RREG32(mmSRBM_STATUS2) & mask))
  384. return 0;
  385. }
  386. return -ETIMEDOUT;
  387. }
  388. static int vce_v3_0_soft_reset(void *handle)
  389. {
  390. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  391. u32 mask = 0;
  392. int idx;
  393. for (idx = 0; idx < 2; ++idx) {
  394. if (adev->vce.harvest_config & (1 << idx))
  395. continue;
  396. if (idx == 0)
  397. mask |= SRBM_SOFT_RESET__SOFT_RESET_VCE0_MASK;
  398. else
  399. mask |= SRBM_SOFT_RESET__SOFT_RESET_VCE1_MASK;
  400. }
  401. WREG32_P(mmSRBM_SOFT_RESET, mask,
  402. ~(SRBM_SOFT_RESET__SOFT_RESET_VCE0_MASK |
  403. SRBM_SOFT_RESET__SOFT_RESET_VCE1_MASK));
  404. mdelay(5);
  405. return vce_v3_0_start(adev);
  406. }
  407. static void vce_v3_0_print_status(void *handle)
  408. {
  409. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  410. dev_info(adev->dev, "VCE 3.0 registers\n");
  411. dev_info(adev->dev, " VCE_STATUS=0x%08X\n",
  412. RREG32(mmVCE_STATUS));
  413. dev_info(adev->dev, " VCE_VCPU_CNTL=0x%08X\n",
  414. RREG32(mmVCE_VCPU_CNTL));
  415. dev_info(adev->dev, " VCE_VCPU_CACHE_OFFSET0=0x%08X\n",
  416. RREG32(mmVCE_VCPU_CACHE_OFFSET0));
  417. dev_info(adev->dev, " VCE_VCPU_CACHE_SIZE0=0x%08X\n",
  418. RREG32(mmVCE_VCPU_CACHE_SIZE0));
  419. dev_info(adev->dev, " VCE_VCPU_CACHE_OFFSET1=0x%08X\n",
  420. RREG32(mmVCE_VCPU_CACHE_OFFSET1));
  421. dev_info(adev->dev, " VCE_VCPU_CACHE_SIZE1=0x%08X\n",
  422. RREG32(mmVCE_VCPU_CACHE_SIZE1));
  423. dev_info(adev->dev, " VCE_VCPU_CACHE_OFFSET2=0x%08X\n",
  424. RREG32(mmVCE_VCPU_CACHE_OFFSET2));
  425. dev_info(adev->dev, " VCE_VCPU_CACHE_SIZE2=0x%08X\n",
  426. RREG32(mmVCE_VCPU_CACHE_SIZE2));
  427. dev_info(adev->dev, " VCE_SOFT_RESET=0x%08X\n",
  428. RREG32(mmVCE_SOFT_RESET));
  429. dev_info(adev->dev, " VCE_RB_BASE_LO2=0x%08X\n",
  430. RREG32(mmVCE_RB_BASE_LO2));
  431. dev_info(adev->dev, " VCE_RB_BASE_HI2=0x%08X\n",
  432. RREG32(mmVCE_RB_BASE_HI2));
  433. dev_info(adev->dev, " VCE_RB_SIZE2=0x%08X\n",
  434. RREG32(mmVCE_RB_SIZE2));
  435. dev_info(adev->dev, " VCE_RB_RPTR2=0x%08X\n",
  436. RREG32(mmVCE_RB_RPTR2));
  437. dev_info(adev->dev, " VCE_RB_WPTR2=0x%08X\n",
  438. RREG32(mmVCE_RB_WPTR2));
  439. dev_info(adev->dev, " VCE_RB_BASE_LO=0x%08X\n",
  440. RREG32(mmVCE_RB_BASE_LO));
  441. dev_info(adev->dev, " VCE_RB_BASE_HI=0x%08X\n",
  442. RREG32(mmVCE_RB_BASE_HI));
  443. dev_info(adev->dev, " VCE_RB_SIZE=0x%08X\n",
  444. RREG32(mmVCE_RB_SIZE));
  445. dev_info(adev->dev, " VCE_RB_RPTR=0x%08X\n",
  446. RREG32(mmVCE_RB_RPTR));
  447. dev_info(adev->dev, " VCE_RB_WPTR=0x%08X\n",
  448. RREG32(mmVCE_RB_WPTR));
  449. dev_info(adev->dev, " VCE_CLOCK_GATING_A=0x%08X\n",
  450. RREG32(mmVCE_CLOCK_GATING_A));
  451. dev_info(adev->dev, " VCE_CLOCK_GATING_B=0x%08X\n",
  452. RREG32(mmVCE_CLOCK_GATING_B));
  453. dev_info(adev->dev, " VCE_UENC_CLOCK_GATING=0x%08X\n",
  454. RREG32(mmVCE_UENC_CLOCK_GATING));
  455. dev_info(adev->dev, " VCE_UENC_REG_CLOCK_GATING=0x%08X\n",
  456. RREG32(mmVCE_UENC_REG_CLOCK_GATING));
  457. dev_info(adev->dev, " VCE_SYS_INT_EN=0x%08X\n",
  458. RREG32(mmVCE_SYS_INT_EN));
  459. dev_info(adev->dev, " VCE_LMI_CTRL2=0x%08X\n",
  460. RREG32(mmVCE_LMI_CTRL2));
  461. dev_info(adev->dev, " VCE_LMI_CTRL=0x%08X\n",
  462. RREG32(mmVCE_LMI_CTRL));
  463. dev_info(adev->dev, " VCE_LMI_VM_CTRL=0x%08X\n",
  464. RREG32(mmVCE_LMI_VM_CTRL));
  465. dev_info(adev->dev, " VCE_LMI_SWAP_CNTL=0x%08X\n",
  466. RREG32(mmVCE_LMI_SWAP_CNTL));
  467. dev_info(adev->dev, " VCE_LMI_SWAP_CNTL1=0x%08X\n",
  468. RREG32(mmVCE_LMI_SWAP_CNTL1));
  469. dev_info(adev->dev, " VCE_LMI_CACHE_CTRL=0x%08X\n",
  470. RREG32(mmVCE_LMI_CACHE_CTRL));
  471. }
  472. static int vce_v3_0_set_interrupt_state(struct amdgpu_device *adev,
  473. struct amdgpu_irq_src *source,
  474. unsigned type,
  475. enum amdgpu_interrupt_state state)
  476. {
  477. uint32_t val = 0;
  478. if (state == AMDGPU_IRQ_STATE_ENABLE)
  479. val |= VCE_SYS_INT_EN__VCE_SYS_INT_TRAP_INTERRUPT_EN_MASK;
  480. WREG32_P(mmVCE_SYS_INT_EN, val, ~VCE_SYS_INT_EN__VCE_SYS_INT_TRAP_INTERRUPT_EN_MASK);
  481. return 0;
  482. }
  483. static int vce_v3_0_process_interrupt(struct amdgpu_device *adev,
  484. struct amdgpu_irq_src *source,
  485. struct amdgpu_iv_entry *entry)
  486. {
  487. DRM_DEBUG("IH: VCE\n");
  488. switch (entry->src_data) {
  489. case 0:
  490. amdgpu_fence_process(&adev->vce.ring[0]);
  491. break;
  492. case 1:
  493. amdgpu_fence_process(&adev->vce.ring[1]);
  494. break;
  495. default:
  496. DRM_ERROR("Unhandled interrupt: %d %d\n",
  497. entry->src_id, entry->src_data);
  498. break;
  499. }
  500. return 0;
  501. }
  502. static int vce_v3_0_set_clockgating_state(void *handle,
  503. enum amd_clockgating_state state)
  504. {
  505. return 0;
  506. }
  507. static int vce_v3_0_set_powergating_state(void *handle,
  508. enum amd_powergating_state state)
  509. {
  510. /* This doesn't actually powergate the VCE block.
  511. * That's done in the dpm code via the SMC. This
  512. * just re-inits the block as necessary. The actual
  513. * gating still happens in the dpm code. We should
  514. * revisit this when there is a cleaner line between
  515. * the smc and the hw blocks
  516. */
  517. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  518. if (state == AMD_PG_STATE_GATE)
  519. /* XXX do we need a vce_v3_0_stop()? */
  520. return 0;
  521. else
  522. return vce_v3_0_start(adev);
  523. }
  524. const struct amd_ip_funcs vce_v3_0_ip_funcs = {
  525. .early_init = vce_v3_0_early_init,
  526. .late_init = NULL,
  527. .sw_init = vce_v3_0_sw_init,
  528. .sw_fini = vce_v3_0_sw_fini,
  529. .hw_init = vce_v3_0_hw_init,
  530. .hw_fini = vce_v3_0_hw_fini,
  531. .suspend = vce_v3_0_suspend,
  532. .resume = vce_v3_0_resume,
  533. .is_idle = vce_v3_0_is_idle,
  534. .wait_for_idle = vce_v3_0_wait_for_idle,
  535. .soft_reset = vce_v3_0_soft_reset,
  536. .print_status = vce_v3_0_print_status,
  537. .set_clockgating_state = vce_v3_0_set_clockgating_state,
  538. .set_powergating_state = vce_v3_0_set_powergating_state,
  539. };
  540. static const struct amdgpu_ring_funcs vce_v3_0_ring_funcs = {
  541. .get_rptr = vce_v3_0_ring_get_rptr,
  542. .get_wptr = vce_v3_0_ring_get_wptr,
  543. .set_wptr = vce_v3_0_ring_set_wptr,
  544. .parse_cs = amdgpu_vce_ring_parse_cs,
  545. .emit_ib = amdgpu_vce_ring_emit_ib,
  546. .emit_fence = amdgpu_vce_ring_emit_fence,
  547. .emit_semaphore = amdgpu_vce_ring_emit_semaphore,
  548. .test_ring = amdgpu_vce_ring_test_ring,
  549. .test_ib = amdgpu_vce_ring_test_ib,
  550. .is_lockup = amdgpu_ring_test_lockup,
  551. .insert_nop = amdgpu_ring_insert_nop,
  552. };
  553. static void vce_v3_0_set_ring_funcs(struct amdgpu_device *adev)
  554. {
  555. adev->vce.ring[0].funcs = &vce_v3_0_ring_funcs;
  556. adev->vce.ring[1].funcs = &vce_v3_0_ring_funcs;
  557. }
  558. static const struct amdgpu_irq_src_funcs vce_v3_0_irq_funcs = {
  559. .set = vce_v3_0_set_interrupt_state,
  560. .process = vce_v3_0_process_interrupt,
  561. };
  562. static void vce_v3_0_set_irq_funcs(struct amdgpu_device *adev)
  563. {
  564. adev->vce.irq.num_types = 1;
  565. adev->vce.irq.funcs = &vce_v3_0_irq_funcs;
  566. };