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, Stoney are single pipe */
  178. if ((adev->asic_type == CHIP_FIJI) ||
  179. (adev->asic_type == CHIP_STONEY)){
  180. ret = AMDGPU_VCE_HARVEST_VCE1;
  181. return ret;
  182. }
  183. /* Tonga and CZ are dual or single pipe */
  184. if (adev->flags & AMD_IS_APU)
  185. tmp = (RREG32_SMC(ixVCE_HARVEST_FUSE_MACRO__ADDRESS) &
  186. VCE_HARVEST_FUSE_MACRO__MASK) >>
  187. VCE_HARVEST_FUSE_MACRO__SHIFT;
  188. else
  189. tmp = (RREG32_SMC(ixCC_HARVEST_FUSES) &
  190. CC_HARVEST_FUSES__VCE_DISABLE_MASK) >>
  191. CC_HARVEST_FUSES__VCE_DISABLE__SHIFT;
  192. switch (tmp) {
  193. case 1:
  194. ret = AMDGPU_VCE_HARVEST_VCE0;
  195. break;
  196. case 2:
  197. ret = AMDGPU_VCE_HARVEST_VCE1;
  198. break;
  199. case 3:
  200. ret = AMDGPU_VCE_HARVEST_VCE0 | AMDGPU_VCE_HARVEST_VCE1;
  201. break;
  202. default:
  203. ret = 0;
  204. }
  205. return ret;
  206. }
  207. static int vce_v3_0_early_init(void *handle)
  208. {
  209. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  210. adev->vce.harvest_config = vce_v3_0_get_harvest_config(adev);
  211. if ((adev->vce.harvest_config &
  212. (AMDGPU_VCE_HARVEST_VCE0 | AMDGPU_VCE_HARVEST_VCE1)) ==
  213. (AMDGPU_VCE_HARVEST_VCE0 | AMDGPU_VCE_HARVEST_VCE1))
  214. return -ENOENT;
  215. vce_v3_0_set_ring_funcs(adev);
  216. vce_v3_0_set_irq_funcs(adev);
  217. return 0;
  218. }
  219. static int vce_v3_0_sw_init(void *handle)
  220. {
  221. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  222. struct amdgpu_ring *ring;
  223. int r;
  224. /* VCE */
  225. r = amdgpu_irq_add_id(adev, 167, &adev->vce.irq);
  226. if (r)
  227. return r;
  228. r = amdgpu_vce_sw_init(adev, VCE_V3_0_FW_SIZE +
  229. (VCE_V3_0_STACK_SIZE + VCE_V3_0_DATA_SIZE) * 2);
  230. if (r)
  231. return r;
  232. r = amdgpu_vce_resume(adev);
  233. if (r)
  234. return r;
  235. ring = &adev->vce.ring[0];
  236. sprintf(ring->name, "vce0");
  237. r = amdgpu_ring_init(adev, ring, 4096, VCE_CMD_NO_OP, 0xf,
  238. &adev->vce.irq, 0, AMDGPU_RING_TYPE_VCE);
  239. if (r)
  240. return r;
  241. ring = &adev->vce.ring[1];
  242. sprintf(ring->name, "vce1");
  243. r = amdgpu_ring_init(adev, ring, 4096, VCE_CMD_NO_OP, 0xf,
  244. &adev->vce.irq, 0, AMDGPU_RING_TYPE_VCE);
  245. if (r)
  246. return r;
  247. return r;
  248. }
  249. static int vce_v3_0_sw_fini(void *handle)
  250. {
  251. int r;
  252. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  253. r = amdgpu_vce_suspend(adev);
  254. if (r)
  255. return r;
  256. r = amdgpu_vce_sw_fini(adev);
  257. if (r)
  258. return r;
  259. return r;
  260. }
  261. static int vce_v3_0_hw_init(void *handle)
  262. {
  263. struct amdgpu_ring *ring;
  264. int r;
  265. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  266. r = vce_v3_0_start(adev);
  267. if (r)
  268. return r;
  269. ring = &adev->vce.ring[0];
  270. ring->ready = true;
  271. r = amdgpu_ring_test_ring(ring);
  272. if (r) {
  273. ring->ready = false;
  274. return r;
  275. }
  276. ring = &adev->vce.ring[1];
  277. ring->ready = true;
  278. r = amdgpu_ring_test_ring(ring);
  279. if (r) {
  280. ring->ready = false;
  281. return r;
  282. }
  283. DRM_INFO("VCE initialized successfully.\n");
  284. return 0;
  285. }
  286. static int vce_v3_0_hw_fini(void *handle)
  287. {
  288. return 0;
  289. }
  290. static int vce_v3_0_suspend(void *handle)
  291. {
  292. int r;
  293. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  294. r = vce_v3_0_hw_fini(adev);
  295. if (r)
  296. return r;
  297. r = amdgpu_vce_suspend(adev);
  298. if (r)
  299. return r;
  300. return r;
  301. }
  302. static int vce_v3_0_resume(void *handle)
  303. {
  304. int r;
  305. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  306. r = amdgpu_vce_resume(adev);
  307. if (r)
  308. return r;
  309. r = vce_v3_0_hw_init(adev);
  310. if (r)
  311. return r;
  312. return r;
  313. }
  314. static void vce_v3_0_mc_resume(struct amdgpu_device *adev, int idx)
  315. {
  316. uint32_t offset, size;
  317. WREG32_P(mmVCE_CLOCK_GATING_A, 0, ~(1 << 16));
  318. WREG32_P(mmVCE_UENC_CLOCK_GATING, 0x1FF000, ~0xFF9FF000);
  319. WREG32_P(mmVCE_UENC_REG_CLOCK_GATING, 0x3F, ~0x3F);
  320. WREG32(mmVCE_CLOCK_GATING_B, 0xf7);
  321. WREG32(mmVCE_LMI_CTRL, 0x00398000);
  322. WREG32_P(mmVCE_LMI_CACHE_CTRL, 0x0, ~0x1);
  323. WREG32(mmVCE_LMI_SWAP_CNTL, 0);
  324. WREG32(mmVCE_LMI_SWAP_CNTL1, 0);
  325. WREG32(mmVCE_LMI_VM_CTRL, 0);
  326. WREG32(mmVCE_LMI_VCPU_CACHE_40BIT_BAR, (adev->vce.gpu_addr >> 8));
  327. offset = AMDGPU_VCE_FIRMWARE_OFFSET;
  328. size = VCE_V3_0_FW_SIZE;
  329. WREG32(mmVCE_VCPU_CACHE_OFFSET0, offset & 0x7fffffff);
  330. WREG32(mmVCE_VCPU_CACHE_SIZE0, size);
  331. if (idx == 0) {
  332. offset += size;
  333. size = VCE_V3_0_STACK_SIZE;
  334. WREG32(mmVCE_VCPU_CACHE_OFFSET1, offset & 0x7fffffff);
  335. WREG32(mmVCE_VCPU_CACHE_SIZE1, size);
  336. offset += size;
  337. size = VCE_V3_0_DATA_SIZE;
  338. WREG32(mmVCE_VCPU_CACHE_OFFSET2, offset & 0x7fffffff);
  339. WREG32(mmVCE_VCPU_CACHE_SIZE2, size);
  340. } else {
  341. offset += size + VCE_V3_0_STACK_SIZE + VCE_V3_0_DATA_SIZE;
  342. size = VCE_V3_0_STACK_SIZE;
  343. WREG32(mmVCE_VCPU_CACHE_OFFSET1, offset & 0xfffffff);
  344. WREG32(mmVCE_VCPU_CACHE_SIZE1, size);
  345. offset += size;
  346. size = VCE_V3_0_DATA_SIZE;
  347. WREG32(mmVCE_VCPU_CACHE_OFFSET2, offset & 0xfffffff);
  348. WREG32(mmVCE_VCPU_CACHE_SIZE2, size);
  349. }
  350. WREG32_P(mmVCE_LMI_CTRL2, 0x0, ~0x100);
  351. WREG32_P(mmVCE_SYS_INT_EN, VCE_SYS_INT_EN__VCE_SYS_INT_TRAP_INTERRUPT_EN_MASK,
  352. ~VCE_SYS_INT_EN__VCE_SYS_INT_TRAP_INTERRUPT_EN_MASK);
  353. }
  354. static bool vce_v3_0_is_idle(void *handle)
  355. {
  356. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  357. u32 mask = 0;
  358. int idx;
  359. for (idx = 0; idx < 2; ++idx) {
  360. if (adev->vce.harvest_config & (1 << idx))
  361. continue;
  362. if (idx == 0)
  363. mask |= SRBM_STATUS2__VCE0_BUSY_MASK;
  364. else
  365. mask |= SRBM_STATUS2__VCE1_BUSY_MASK;
  366. }
  367. return !(RREG32(mmSRBM_STATUS2) & mask);
  368. }
  369. static int vce_v3_0_wait_for_idle(void *handle)
  370. {
  371. unsigned i;
  372. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  373. u32 mask = 0;
  374. int idx;
  375. for (idx = 0; idx < 2; ++idx) {
  376. if (adev->vce.harvest_config & (1 << idx))
  377. continue;
  378. if (idx == 0)
  379. mask |= SRBM_STATUS2__VCE0_BUSY_MASK;
  380. else
  381. mask |= SRBM_STATUS2__VCE1_BUSY_MASK;
  382. }
  383. for (i = 0; i < adev->usec_timeout; i++) {
  384. if (!(RREG32(mmSRBM_STATUS2) & mask))
  385. return 0;
  386. }
  387. return -ETIMEDOUT;
  388. }
  389. static int vce_v3_0_soft_reset(void *handle)
  390. {
  391. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  392. u32 mask = 0;
  393. int idx;
  394. for (idx = 0; idx < 2; ++idx) {
  395. if (adev->vce.harvest_config & (1 << idx))
  396. continue;
  397. if (idx == 0)
  398. mask |= SRBM_SOFT_RESET__SOFT_RESET_VCE0_MASK;
  399. else
  400. mask |= SRBM_SOFT_RESET__SOFT_RESET_VCE1_MASK;
  401. }
  402. WREG32_P(mmSRBM_SOFT_RESET, mask,
  403. ~(SRBM_SOFT_RESET__SOFT_RESET_VCE0_MASK |
  404. SRBM_SOFT_RESET__SOFT_RESET_VCE1_MASK));
  405. mdelay(5);
  406. return vce_v3_0_start(adev);
  407. }
  408. static void vce_v3_0_print_status(void *handle)
  409. {
  410. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  411. dev_info(adev->dev, "VCE 3.0 registers\n");
  412. dev_info(adev->dev, " VCE_STATUS=0x%08X\n",
  413. RREG32(mmVCE_STATUS));
  414. dev_info(adev->dev, " VCE_VCPU_CNTL=0x%08X\n",
  415. RREG32(mmVCE_VCPU_CNTL));
  416. dev_info(adev->dev, " VCE_VCPU_CACHE_OFFSET0=0x%08X\n",
  417. RREG32(mmVCE_VCPU_CACHE_OFFSET0));
  418. dev_info(adev->dev, " VCE_VCPU_CACHE_SIZE0=0x%08X\n",
  419. RREG32(mmVCE_VCPU_CACHE_SIZE0));
  420. dev_info(adev->dev, " VCE_VCPU_CACHE_OFFSET1=0x%08X\n",
  421. RREG32(mmVCE_VCPU_CACHE_OFFSET1));
  422. dev_info(adev->dev, " VCE_VCPU_CACHE_SIZE1=0x%08X\n",
  423. RREG32(mmVCE_VCPU_CACHE_SIZE1));
  424. dev_info(adev->dev, " VCE_VCPU_CACHE_OFFSET2=0x%08X\n",
  425. RREG32(mmVCE_VCPU_CACHE_OFFSET2));
  426. dev_info(adev->dev, " VCE_VCPU_CACHE_SIZE2=0x%08X\n",
  427. RREG32(mmVCE_VCPU_CACHE_SIZE2));
  428. dev_info(adev->dev, " VCE_SOFT_RESET=0x%08X\n",
  429. RREG32(mmVCE_SOFT_RESET));
  430. dev_info(adev->dev, " VCE_RB_BASE_LO2=0x%08X\n",
  431. RREG32(mmVCE_RB_BASE_LO2));
  432. dev_info(adev->dev, " VCE_RB_BASE_HI2=0x%08X\n",
  433. RREG32(mmVCE_RB_BASE_HI2));
  434. dev_info(adev->dev, " VCE_RB_SIZE2=0x%08X\n",
  435. RREG32(mmVCE_RB_SIZE2));
  436. dev_info(adev->dev, " VCE_RB_RPTR2=0x%08X\n",
  437. RREG32(mmVCE_RB_RPTR2));
  438. dev_info(adev->dev, " VCE_RB_WPTR2=0x%08X\n",
  439. RREG32(mmVCE_RB_WPTR2));
  440. dev_info(adev->dev, " VCE_RB_BASE_LO=0x%08X\n",
  441. RREG32(mmVCE_RB_BASE_LO));
  442. dev_info(adev->dev, " VCE_RB_BASE_HI=0x%08X\n",
  443. RREG32(mmVCE_RB_BASE_HI));
  444. dev_info(adev->dev, " VCE_RB_SIZE=0x%08X\n",
  445. RREG32(mmVCE_RB_SIZE));
  446. dev_info(adev->dev, " VCE_RB_RPTR=0x%08X\n",
  447. RREG32(mmVCE_RB_RPTR));
  448. dev_info(adev->dev, " VCE_RB_WPTR=0x%08X\n",
  449. RREG32(mmVCE_RB_WPTR));
  450. dev_info(adev->dev, " VCE_CLOCK_GATING_A=0x%08X\n",
  451. RREG32(mmVCE_CLOCK_GATING_A));
  452. dev_info(adev->dev, " VCE_CLOCK_GATING_B=0x%08X\n",
  453. RREG32(mmVCE_CLOCK_GATING_B));
  454. dev_info(adev->dev, " VCE_UENC_CLOCK_GATING=0x%08X\n",
  455. RREG32(mmVCE_UENC_CLOCK_GATING));
  456. dev_info(adev->dev, " VCE_UENC_REG_CLOCK_GATING=0x%08X\n",
  457. RREG32(mmVCE_UENC_REG_CLOCK_GATING));
  458. dev_info(adev->dev, " VCE_SYS_INT_EN=0x%08X\n",
  459. RREG32(mmVCE_SYS_INT_EN));
  460. dev_info(adev->dev, " VCE_LMI_CTRL2=0x%08X\n",
  461. RREG32(mmVCE_LMI_CTRL2));
  462. dev_info(adev->dev, " VCE_LMI_CTRL=0x%08X\n",
  463. RREG32(mmVCE_LMI_CTRL));
  464. dev_info(adev->dev, " VCE_LMI_VM_CTRL=0x%08X\n",
  465. RREG32(mmVCE_LMI_VM_CTRL));
  466. dev_info(adev->dev, " VCE_LMI_SWAP_CNTL=0x%08X\n",
  467. RREG32(mmVCE_LMI_SWAP_CNTL));
  468. dev_info(adev->dev, " VCE_LMI_SWAP_CNTL1=0x%08X\n",
  469. RREG32(mmVCE_LMI_SWAP_CNTL1));
  470. dev_info(adev->dev, " VCE_LMI_CACHE_CTRL=0x%08X\n",
  471. RREG32(mmVCE_LMI_CACHE_CTRL));
  472. }
  473. static int vce_v3_0_set_interrupt_state(struct amdgpu_device *adev,
  474. struct amdgpu_irq_src *source,
  475. unsigned type,
  476. enum amdgpu_interrupt_state state)
  477. {
  478. uint32_t val = 0;
  479. if (state == AMDGPU_IRQ_STATE_ENABLE)
  480. val |= VCE_SYS_INT_EN__VCE_SYS_INT_TRAP_INTERRUPT_EN_MASK;
  481. WREG32_P(mmVCE_SYS_INT_EN, val, ~VCE_SYS_INT_EN__VCE_SYS_INT_TRAP_INTERRUPT_EN_MASK);
  482. return 0;
  483. }
  484. static int vce_v3_0_process_interrupt(struct amdgpu_device *adev,
  485. struct amdgpu_irq_src *source,
  486. struct amdgpu_iv_entry *entry)
  487. {
  488. DRM_DEBUG("IH: VCE\n");
  489. switch (entry->src_data) {
  490. case 0:
  491. amdgpu_fence_process(&adev->vce.ring[0]);
  492. break;
  493. case 1:
  494. amdgpu_fence_process(&adev->vce.ring[1]);
  495. break;
  496. default:
  497. DRM_ERROR("Unhandled interrupt: %d %d\n",
  498. entry->src_id, entry->src_data);
  499. break;
  500. }
  501. return 0;
  502. }
  503. static int vce_v3_0_set_clockgating_state(void *handle,
  504. enum amd_clockgating_state state)
  505. {
  506. return 0;
  507. }
  508. static int vce_v3_0_set_powergating_state(void *handle,
  509. enum amd_powergating_state state)
  510. {
  511. /* This doesn't actually powergate the VCE block.
  512. * That's done in the dpm code via the SMC. This
  513. * just re-inits the block as necessary. The actual
  514. * gating still happens in the dpm code. We should
  515. * revisit this when there is a cleaner line between
  516. * the smc and the hw blocks
  517. */
  518. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  519. if (state == AMD_PG_STATE_GATE)
  520. /* XXX do we need a vce_v3_0_stop()? */
  521. return 0;
  522. else
  523. return vce_v3_0_start(adev);
  524. }
  525. const struct amd_ip_funcs vce_v3_0_ip_funcs = {
  526. .early_init = vce_v3_0_early_init,
  527. .late_init = NULL,
  528. .sw_init = vce_v3_0_sw_init,
  529. .sw_fini = vce_v3_0_sw_fini,
  530. .hw_init = vce_v3_0_hw_init,
  531. .hw_fini = vce_v3_0_hw_fini,
  532. .suspend = vce_v3_0_suspend,
  533. .resume = vce_v3_0_resume,
  534. .is_idle = vce_v3_0_is_idle,
  535. .wait_for_idle = vce_v3_0_wait_for_idle,
  536. .soft_reset = vce_v3_0_soft_reset,
  537. .print_status = vce_v3_0_print_status,
  538. .set_clockgating_state = vce_v3_0_set_clockgating_state,
  539. .set_powergating_state = vce_v3_0_set_powergating_state,
  540. };
  541. static const struct amdgpu_ring_funcs vce_v3_0_ring_funcs = {
  542. .get_rptr = vce_v3_0_ring_get_rptr,
  543. .get_wptr = vce_v3_0_ring_get_wptr,
  544. .set_wptr = vce_v3_0_ring_set_wptr,
  545. .parse_cs = amdgpu_vce_ring_parse_cs,
  546. .emit_ib = amdgpu_vce_ring_emit_ib,
  547. .emit_fence = amdgpu_vce_ring_emit_fence,
  548. .emit_semaphore = amdgpu_vce_ring_emit_semaphore,
  549. .test_ring = amdgpu_vce_ring_test_ring,
  550. .test_ib = amdgpu_vce_ring_test_ib,
  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. };