vce_v3_0.c 18 KB

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