vce_v2_0.c 16 KB

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