vce_v2_0.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  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 "smu/smu_7_0_1_d.h"
  35. #include "smu/smu_7_0_1_sh_mask.h"
  36. #include "oss/oss_2_0_d.h"
  37. #include "oss/oss_2_0_sh_mask.h"
  38. #define VCE_V2_0_FW_SIZE (256 * 1024)
  39. #define VCE_V2_0_STACK_SIZE (64 * 1024)
  40. #define VCE_V2_0_DATA_SIZE (23552 * AMDGPU_MAX_VCE_HANDLES)
  41. #define VCE_STATUS_VCPU_REPORT_FW_LOADED_MASK 0x02
  42. static void vce_v2_0_set_ring_funcs(struct amdgpu_device *adev);
  43. static void vce_v2_0_set_irq_funcs(struct amdgpu_device *adev);
  44. /**
  45. * vce_v2_0_ring_get_rptr - get read pointer
  46. *
  47. * @ring: amdgpu_ring pointer
  48. *
  49. * Returns the current hardware read pointer
  50. */
  51. static uint64_t vce_v2_0_ring_get_rptr(struct amdgpu_ring *ring)
  52. {
  53. struct amdgpu_device *adev = ring->adev;
  54. if (ring == &adev->vce.ring[0])
  55. return RREG32(mmVCE_RB_RPTR);
  56. else
  57. return RREG32(mmVCE_RB_RPTR2);
  58. }
  59. /**
  60. * vce_v2_0_ring_get_wptr - get write pointer
  61. *
  62. * @ring: amdgpu_ring pointer
  63. *
  64. * Returns the current hardware write pointer
  65. */
  66. static uint64_t vce_v2_0_ring_get_wptr(struct amdgpu_ring *ring)
  67. {
  68. struct amdgpu_device *adev = ring->adev;
  69. if (ring == &adev->vce.ring[0])
  70. return RREG32(mmVCE_RB_WPTR);
  71. else
  72. return RREG32(mmVCE_RB_WPTR2);
  73. }
  74. /**
  75. * vce_v2_0_ring_set_wptr - set write pointer
  76. *
  77. * @ring: amdgpu_ring pointer
  78. *
  79. * Commits the write pointer to the hardware
  80. */
  81. static void vce_v2_0_ring_set_wptr(struct amdgpu_ring *ring)
  82. {
  83. struct amdgpu_device *adev = ring->adev;
  84. if (ring == &adev->vce.ring[0])
  85. WREG32(mmVCE_RB_WPTR, lower_32_bits(ring->wptr));
  86. else
  87. WREG32(mmVCE_RB_WPTR2, lower_32_bits(ring->wptr));
  88. }
  89. static int vce_v2_0_lmi_clean(struct amdgpu_device *adev)
  90. {
  91. int i, j;
  92. for (i = 0; i < 10; ++i) {
  93. for (j = 0; j < 100; ++j) {
  94. uint32_t status = RREG32(mmVCE_LMI_STATUS);
  95. if (status & 0x337f)
  96. return 0;
  97. mdelay(10);
  98. }
  99. }
  100. return -ETIMEDOUT;
  101. }
  102. static int vce_v2_0_firmware_loaded(struct amdgpu_device *adev)
  103. {
  104. int i, j;
  105. for (i = 0; i < 10; ++i) {
  106. for (j = 0; j < 100; ++j) {
  107. uint32_t status = RREG32(mmVCE_STATUS);
  108. if (status & VCE_STATUS_VCPU_REPORT_FW_LOADED_MASK)
  109. return 0;
  110. mdelay(10);
  111. }
  112. DRM_ERROR("VCE not responding, trying to reset the ECPU!!!\n");
  113. WREG32_P(mmVCE_SOFT_RESET,
  114. VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK,
  115. ~VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK);
  116. mdelay(10);
  117. WREG32_P(mmVCE_SOFT_RESET, 0,
  118. ~VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK);
  119. mdelay(10);
  120. }
  121. return -ETIMEDOUT;
  122. }
  123. static void vce_v2_0_disable_cg(struct amdgpu_device *adev)
  124. {
  125. WREG32(mmVCE_CGTT_CLK_OVERRIDE, 7);
  126. }
  127. static void vce_v2_0_init_cg(struct amdgpu_device *adev)
  128. {
  129. u32 tmp;
  130. tmp = RREG32(mmVCE_CLOCK_GATING_A);
  131. tmp &= ~0xfff;
  132. tmp |= ((0 << 0) | (4 << 4));
  133. tmp |= 0x40000;
  134. WREG32(mmVCE_CLOCK_GATING_A, tmp);
  135. tmp = RREG32(mmVCE_UENC_CLOCK_GATING);
  136. tmp &= ~0xfff;
  137. tmp |= ((0 << 0) | (4 << 4));
  138. WREG32(mmVCE_UENC_CLOCK_GATING, tmp);
  139. tmp = RREG32(mmVCE_CLOCK_GATING_B);
  140. tmp |= 0x10;
  141. tmp &= ~0x100000;
  142. WREG32(mmVCE_CLOCK_GATING_B, tmp);
  143. }
  144. static void vce_v2_0_mc_resume(struct amdgpu_device *adev)
  145. {
  146. uint32_t size, offset;
  147. WREG32_P(mmVCE_CLOCK_GATING_A, 0, ~(1 << 16));
  148. WREG32_P(mmVCE_UENC_CLOCK_GATING, 0x1FF000, ~0xFF9FF000);
  149. WREG32_P(mmVCE_UENC_REG_CLOCK_GATING, 0x3F, ~0x3F);
  150. WREG32(mmVCE_CLOCK_GATING_B, 0xf7);
  151. WREG32(mmVCE_LMI_CTRL, 0x00398000);
  152. WREG32_P(mmVCE_LMI_CACHE_CTRL, 0x0, ~0x1);
  153. WREG32(mmVCE_LMI_SWAP_CNTL, 0);
  154. WREG32(mmVCE_LMI_SWAP_CNTL1, 0);
  155. WREG32(mmVCE_LMI_VM_CTRL, 0);
  156. WREG32(mmVCE_LMI_VCPU_CACHE_40BIT_BAR, (adev->vce.gpu_addr >> 8));
  157. offset = AMDGPU_VCE_FIRMWARE_OFFSET;
  158. size = VCE_V2_0_FW_SIZE;
  159. WREG32(mmVCE_VCPU_CACHE_OFFSET0, offset & 0x7fffffff);
  160. WREG32(mmVCE_VCPU_CACHE_SIZE0, size);
  161. offset += size;
  162. size = VCE_V2_0_STACK_SIZE;
  163. WREG32(mmVCE_VCPU_CACHE_OFFSET1, offset & 0x7fffffff);
  164. WREG32(mmVCE_VCPU_CACHE_SIZE1, size);
  165. offset += size;
  166. size = VCE_V2_0_DATA_SIZE;
  167. WREG32(mmVCE_VCPU_CACHE_OFFSET2, offset & 0x7fffffff);
  168. WREG32(mmVCE_VCPU_CACHE_SIZE2, size);
  169. WREG32_P(mmVCE_LMI_CTRL2, 0x0, ~0x100);
  170. WREG32_FIELD(VCE_SYS_INT_EN, VCE_SYS_INT_TRAP_INTERRUPT_EN, 1);
  171. }
  172. static bool vce_v2_0_is_idle(void *handle)
  173. {
  174. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  175. return !(RREG32(mmSRBM_STATUS2) & SRBM_STATUS2__VCE_BUSY_MASK);
  176. }
  177. static int vce_v2_0_wait_for_idle(void *handle)
  178. {
  179. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  180. unsigned i;
  181. for (i = 0; i < adev->usec_timeout; i++) {
  182. if (vce_v2_0_is_idle(handle))
  183. return 0;
  184. }
  185. return -ETIMEDOUT;
  186. }
  187. /**
  188. * vce_v2_0_start - start VCE block
  189. *
  190. * @adev: amdgpu_device pointer
  191. *
  192. * Setup and start the VCE block
  193. */
  194. static int vce_v2_0_start(struct amdgpu_device *adev)
  195. {
  196. struct amdgpu_ring *ring;
  197. int r;
  198. /* set BUSY flag */
  199. WREG32_P(mmVCE_STATUS, 1, ~1);
  200. vce_v2_0_init_cg(adev);
  201. vce_v2_0_disable_cg(adev);
  202. vce_v2_0_mc_resume(adev);
  203. ring = &adev->vce.ring[0];
  204. WREG32(mmVCE_RB_RPTR, lower_32_bits(ring->wptr));
  205. WREG32(mmVCE_RB_WPTR, lower_32_bits(ring->wptr));
  206. WREG32(mmVCE_RB_BASE_LO, ring->gpu_addr);
  207. WREG32(mmVCE_RB_BASE_HI, upper_32_bits(ring->gpu_addr));
  208. WREG32(mmVCE_RB_SIZE, ring->ring_size / 4);
  209. ring = &adev->vce.ring[1];
  210. WREG32(mmVCE_RB_RPTR2, lower_32_bits(ring->wptr));
  211. WREG32(mmVCE_RB_WPTR2, lower_32_bits(ring->wptr));
  212. WREG32(mmVCE_RB_BASE_LO2, ring->gpu_addr);
  213. WREG32(mmVCE_RB_BASE_HI2, upper_32_bits(ring->gpu_addr));
  214. WREG32(mmVCE_RB_SIZE2, ring->ring_size / 4);
  215. WREG32_FIELD(VCE_VCPU_CNTL, CLK_EN, 1);
  216. WREG32_FIELD(VCE_SOFT_RESET, ECPU_SOFT_RESET, 1);
  217. mdelay(100);
  218. WREG32_FIELD(VCE_SOFT_RESET, ECPU_SOFT_RESET, 0);
  219. r = vce_v2_0_firmware_loaded(adev);
  220. /* clear BUSY flag */
  221. WREG32_P(mmVCE_STATUS, 0, ~1);
  222. if (r) {
  223. DRM_ERROR("VCE not responding, giving up!!!\n");
  224. return r;
  225. }
  226. return 0;
  227. }
  228. static int vce_v2_0_stop(struct amdgpu_device *adev)
  229. {
  230. int i, j;
  231. int status;
  232. if (vce_v2_0_lmi_clean(adev)) {
  233. DRM_INFO("vce is not idle \n");
  234. return 0;
  235. }
  236. /*
  237. for (i = 0; i < 10; ++i) {
  238. for (j = 0; j < 100; ++j) {
  239. status = RREG32(mmVCE_FW_REG_STATUS);
  240. if (!(status & 1))
  241. break;
  242. mdelay(1);
  243. }
  244. break;
  245. }
  246. */
  247. if (vce_v2_0_wait_for_idle(adev)) {
  248. DRM_INFO("VCE is busy, Can't set clock gateing");
  249. return 0;
  250. }
  251. /* Stall UMC and register bus before resetting VCPU */
  252. WREG32_P(mmVCE_LMI_CTRL2, 1 << 8, ~(1 << 8));
  253. for (i = 0; i < 10; ++i) {
  254. for (j = 0; j < 100; ++j) {
  255. status = RREG32(mmVCE_LMI_STATUS);
  256. if (status & 0x240)
  257. break;
  258. mdelay(1);
  259. }
  260. break;
  261. }
  262. WREG32_P(mmVCE_VCPU_CNTL, 0, ~0x80001);
  263. /* put LMI, VCPU, RBC etc... into reset */
  264. WREG32_P(mmVCE_SOFT_RESET, 1, ~0x1);
  265. WREG32(mmVCE_STATUS, 0);
  266. return 0;
  267. }
  268. static void vce_v2_0_set_sw_cg(struct amdgpu_device *adev, bool gated)
  269. {
  270. u32 tmp;
  271. if (gated) {
  272. tmp = RREG32(mmVCE_CLOCK_GATING_B);
  273. tmp |= 0xe70000;
  274. WREG32(mmVCE_CLOCK_GATING_B, tmp);
  275. tmp = RREG32(mmVCE_UENC_CLOCK_GATING);
  276. tmp |= 0xff000000;
  277. WREG32(mmVCE_UENC_CLOCK_GATING, tmp);
  278. tmp = RREG32(mmVCE_UENC_REG_CLOCK_GATING);
  279. tmp &= ~0x3fc;
  280. WREG32(mmVCE_UENC_REG_CLOCK_GATING, tmp);
  281. WREG32(mmVCE_CGTT_CLK_OVERRIDE, 0);
  282. } else {
  283. tmp = RREG32(mmVCE_CLOCK_GATING_B);
  284. tmp |= 0xe7;
  285. tmp &= ~0xe70000;
  286. WREG32(mmVCE_CLOCK_GATING_B, tmp);
  287. tmp = RREG32(mmVCE_UENC_CLOCK_GATING);
  288. tmp |= 0x1fe000;
  289. tmp &= ~0xff000000;
  290. WREG32(mmVCE_UENC_CLOCK_GATING, tmp);
  291. tmp = RREG32(mmVCE_UENC_REG_CLOCK_GATING);
  292. tmp |= 0x3fc;
  293. WREG32(mmVCE_UENC_REG_CLOCK_GATING, tmp);
  294. }
  295. }
  296. static void vce_v2_0_set_dyn_cg(struct amdgpu_device *adev, bool gated)
  297. {
  298. u32 orig, tmp;
  299. /* LMI_MC/LMI_UMC always set in dynamic,
  300. * set {CGC_*_GATE_MODE, CGC_*_SW_GATE} = {0, 0}
  301. */
  302. tmp = RREG32(mmVCE_CLOCK_GATING_B);
  303. tmp &= ~0x00060006;
  304. /* Exception for ECPU, IH, SEM, SYS blocks needs to be turned on/off by SW */
  305. if (gated) {
  306. tmp |= 0xe10000;
  307. WREG32(mmVCE_CLOCK_GATING_B, tmp);
  308. } else {
  309. tmp |= 0xe1;
  310. tmp &= ~0xe10000;
  311. WREG32(mmVCE_CLOCK_GATING_B, tmp);
  312. }
  313. orig = tmp = RREG32(mmVCE_UENC_CLOCK_GATING);
  314. tmp &= ~0x1fe000;
  315. tmp &= ~0xff000000;
  316. if (tmp != orig)
  317. WREG32(mmVCE_UENC_CLOCK_GATING, tmp);
  318. orig = tmp = RREG32(mmVCE_UENC_REG_CLOCK_GATING);
  319. tmp &= ~0x3fc;
  320. if (tmp != orig)
  321. WREG32(mmVCE_UENC_REG_CLOCK_GATING, tmp);
  322. /* set VCE_UENC_REG_CLOCK_GATING always in dynamic mode */
  323. WREG32(mmVCE_UENC_REG_CLOCK_GATING, 0x00);
  324. if(gated)
  325. WREG32(mmVCE_CGTT_CLK_OVERRIDE, 0);
  326. }
  327. static void vce_v2_0_enable_mgcg(struct amdgpu_device *adev, bool enable,
  328. bool sw_cg)
  329. {
  330. if (enable && (adev->cg_flags & AMD_CG_SUPPORT_VCE_MGCG)) {
  331. if (sw_cg)
  332. vce_v2_0_set_sw_cg(adev, true);
  333. else
  334. vce_v2_0_set_dyn_cg(adev, true);
  335. } else {
  336. vce_v2_0_disable_cg(adev);
  337. if (sw_cg)
  338. vce_v2_0_set_sw_cg(adev, false);
  339. else
  340. vce_v2_0_set_dyn_cg(adev, false);
  341. }
  342. }
  343. static int vce_v2_0_early_init(void *handle)
  344. {
  345. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  346. adev->vce.num_rings = 2;
  347. vce_v2_0_set_ring_funcs(adev);
  348. vce_v2_0_set_irq_funcs(adev);
  349. return 0;
  350. }
  351. static int vce_v2_0_sw_init(void *handle)
  352. {
  353. struct amdgpu_ring *ring;
  354. int r, i;
  355. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  356. /* VCE */
  357. r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_LEGACY, 167, &adev->vce.irq);
  358. if (r)
  359. return r;
  360. r = amdgpu_vce_sw_init(adev, VCE_V2_0_FW_SIZE +
  361. VCE_V2_0_STACK_SIZE + VCE_V2_0_DATA_SIZE);
  362. if (r)
  363. return r;
  364. r = amdgpu_vce_resume(adev);
  365. if (r)
  366. return r;
  367. for (i = 0; i < adev->vce.num_rings; i++) {
  368. ring = &adev->vce.ring[i];
  369. sprintf(ring->name, "vce%d", i);
  370. r = amdgpu_ring_init(adev, ring, 512,
  371. &adev->vce.irq, 0);
  372. if (r)
  373. return r;
  374. }
  375. return r;
  376. }
  377. static int vce_v2_0_sw_fini(void *handle)
  378. {
  379. int r;
  380. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  381. r = amdgpu_vce_suspend(adev);
  382. if (r)
  383. return r;
  384. r = amdgpu_vce_sw_fini(adev);
  385. if (r)
  386. return r;
  387. return r;
  388. }
  389. static int vce_v2_0_hw_init(void *handle)
  390. {
  391. int r, i;
  392. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  393. amdgpu_asic_set_vce_clocks(adev, 10000, 10000);
  394. vce_v2_0_enable_mgcg(adev, true, false);
  395. for (i = 0; i < adev->vce.num_rings; i++)
  396. adev->vce.ring[i].ready = false;
  397. for (i = 0; i < adev->vce.num_rings; i++) {
  398. r = amdgpu_ring_test_ring(&adev->vce.ring[i]);
  399. if (r)
  400. return r;
  401. else
  402. adev->vce.ring[i].ready = true;
  403. }
  404. DRM_INFO("VCE initialized successfully.\n");
  405. return 0;
  406. }
  407. static int vce_v2_0_hw_fini(void *handle)
  408. {
  409. return 0;
  410. }
  411. static int vce_v2_0_suspend(void *handle)
  412. {
  413. int r;
  414. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  415. r = vce_v2_0_hw_fini(adev);
  416. if (r)
  417. return r;
  418. r = amdgpu_vce_suspend(adev);
  419. if (r)
  420. return r;
  421. return r;
  422. }
  423. static int vce_v2_0_resume(void *handle)
  424. {
  425. int r;
  426. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  427. r = amdgpu_vce_resume(adev);
  428. if (r)
  429. return r;
  430. r = vce_v2_0_hw_init(adev);
  431. if (r)
  432. return r;
  433. return r;
  434. }
  435. static int vce_v2_0_soft_reset(void *handle)
  436. {
  437. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  438. WREG32_FIELD(SRBM_SOFT_RESET, SOFT_RESET_VCE, 1);
  439. mdelay(5);
  440. return vce_v2_0_start(adev);
  441. }
  442. static int vce_v2_0_set_interrupt_state(struct amdgpu_device *adev,
  443. struct amdgpu_irq_src *source,
  444. unsigned type,
  445. enum amdgpu_interrupt_state state)
  446. {
  447. uint32_t val = 0;
  448. if (state == AMDGPU_IRQ_STATE_ENABLE)
  449. val |= VCE_SYS_INT_EN__VCE_SYS_INT_TRAP_INTERRUPT_EN_MASK;
  450. WREG32_P(mmVCE_SYS_INT_EN, val, ~VCE_SYS_INT_EN__VCE_SYS_INT_TRAP_INTERRUPT_EN_MASK);
  451. return 0;
  452. }
  453. static int vce_v2_0_process_interrupt(struct amdgpu_device *adev,
  454. struct amdgpu_irq_src *source,
  455. struct amdgpu_iv_entry *entry)
  456. {
  457. DRM_DEBUG("IH: VCE\n");
  458. switch (entry->src_data[0]) {
  459. case 0:
  460. case 1:
  461. amdgpu_fence_process(&adev->vce.ring[entry->src_data[0]]);
  462. break;
  463. default:
  464. DRM_ERROR("Unhandled interrupt: %d %d\n",
  465. entry->src_id, entry->src_data[0]);
  466. break;
  467. }
  468. return 0;
  469. }
  470. static int vce_v2_0_set_clockgating_state(void *handle,
  471. enum amd_clockgating_state state)
  472. {
  473. bool gate = false;
  474. bool sw_cg = false;
  475. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  476. if (state == AMD_CG_STATE_GATE) {
  477. gate = true;
  478. sw_cg = true;
  479. }
  480. vce_v2_0_enable_mgcg(adev, gate, sw_cg);
  481. return 0;
  482. }
  483. static int vce_v2_0_set_powergating_state(void *handle,
  484. enum amd_powergating_state state)
  485. {
  486. /* This doesn't actually powergate the VCE block.
  487. * That's done in the dpm code via the SMC. This
  488. * just re-inits the block as necessary. The actual
  489. * gating still happens in the dpm code. We should
  490. * revisit this when there is a cleaner line between
  491. * the smc and the hw blocks
  492. */
  493. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  494. if (state == AMD_PG_STATE_GATE)
  495. return vce_v2_0_stop(adev);
  496. else
  497. return vce_v2_0_start(adev);
  498. }
  499. static const struct amd_ip_funcs vce_v2_0_ip_funcs = {
  500. .name = "vce_v2_0",
  501. .early_init = vce_v2_0_early_init,
  502. .late_init = NULL,
  503. .sw_init = vce_v2_0_sw_init,
  504. .sw_fini = vce_v2_0_sw_fini,
  505. .hw_init = vce_v2_0_hw_init,
  506. .hw_fini = vce_v2_0_hw_fini,
  507. .suspend = vce_v2_0_suspend,
  508. .resume = vce_v2_0_resume,
  509. .is_idle = vce_v2_0_is_idle,
  510. .wait_for_idle = vce_v2_0_wait_for_idle,
  511. .soft_reset = vce_v2_0_soft_reset,
  512. .set_clockgating_state = vce_v2_0_set_clockgating_state,
  513. .set_powergating_state = vce_v2_0_set_powergating_state,
  514. };
  515. static const struct amdgpu_ring_funcs vce_v2_0_ring_funcs = {
  516. .type = AMDGPU_RING_TYPE_VCE,
  517. .align_mask = 0xf,
  518. .nop = VCE_CMD_NO_OP,
  519. .support_64bit_ptrs = false,
  520. .get_rptr = vce_v2_0_ring_get_rptr,
  521. .get_wptr = vce_v2_0_ring_get_wptr,
  522. .set_wptr = vce_v2_0_ring_set_wptr,
  523. .parse_cs = amdgpu_vce_ring_parse_cs,
  524. .emit_frame_size = 6, /* amdgpu_vce_ring_emit_fence x1 no user fence */
  525. .emit_ib_size = 4, /* amdgpu_vce_ring_emit_ib */
  526. .emit_ib = amdgpu_vce_ring_emit_ib,
  527. .emit_fence = amdgpu_vce_ring_emit_fence,
  528. .test_ring = amdgpu_vce_ring_test_ring,
  529. .test_ib = amdgpu_vce_ring_test_ib,
  530. .insert_nop = amdgpu_ring_insert_nop,
  531. .pad_ib = amdgpu_ring_generic_pad_ib,
  532. .begin_use = amdgpu_vce_ring_begin_use,
  533. .end_use = amdgpu_vce_ring_end_use,
  534. };
  535. static void vce_v2_0_set_ring_funcs(struct amdgpu_device *adev)
  536. {
  537. int i;
  538. for (i = 0; i < adev->vce.num_rings; i++)
  539. adev->vce.ring[i].funcs = &vce_v2_0_ring_funcs;
  540. }
  541. static const struct amdgpu_irq_src_funcs vce_v2_0_irq_funcs = {
  542. .set = vce_v2_0_set_interrupt_state,
  543. .process = vce_v2_0_process_interrupt,
  544. };
  545. static void vce_v2_0_set_irq_funcs(struct amdgpu_device *adev)
  546. {
  547. adev->vce.irq.num_types = 1;
  548. adev->vce.irq.funcs = &vce_v2_0_irq_funcs;
  549. };
  550. const struct amdgpu_ip_block_version vce_v2_0_ip_block =
  551. {
  552. .type = AMD_IP_BLOCK_TYPE_VCE,
  553. .major = 2,
  554. .minor = 0,
  555. .rev = 0,
  556. .funcs = &vce_v2_0_ip_funcs,
  557. };