2 * Copyright 2020 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
22 * Authors: Sonny Jiang <sonny.jiang@amd.com>
25 #include <linux/firmware.h>
28 #include "amdgpu_uvd.h"
31 #include "uvd/uvd_3_1_d.h"
32 #include "uvd/uvd_3_1_sh_mask.h"
34 #include "oss/oss_1_0_d.h"
35 #include "oss/oss_1_0_sh_mask.h"
38 * uvd_v3_1_ring_get_rptr - get read pointer
40 * @ring: amdgpu_ring pointer
42 * Returns the current hardware read pointer
44 static uint64_t uvd_v3_1_ring_get_rptr(struct amdgpu_ring *ring)
46 struct amdgpu_device *adev = ring->adev;
48 return RREG32(mmUVD_RBC_RB_RPTR);
52 * uvd_v3_1_ring_get_wptr - get write pointer
54 * @ring: amdgpu_ring pointer
56 * Returns the current hardware write pointer
58 static uint64_t uvd_v3_1_ring_get_wptr(struct amdgpu_ring *ring)
60 struct amdgpu_device *adev = ring->adev;
62 return RREG32(mmUVD_RBC_RB_WPTR);
66 * uvd_v3_1_ring_set_wptr - set write pointer
68 * @ring: amdgpu_ring pointer
70 * Commits the write pointer to the hardware
72 static void uvd_v3_1_ring_set_wptr(struct amdgpu_ring *ring)
74 struct amdgpu_device *adev = ring->adev;
76 WREG32(mmUVD_RBC_RB_WPTR, lower_32_bits(ring->wptr));
80 * uvd_v3_1_ring_emit_ib - execute indirect buffer
82 * @ring: amdgpu_ring pointer
83 * @job: iob associated with the indirect buffer
84 * @ib: indirect buffer to execute
85 * @flags: flags associated with the indirect buffer
87 * Write ring commands to execute the indirect buffer
89 static void uvd_v3_1_ring_emit_ib(struct amdgpu_ring *ring,
90 struct amdgpu_job *job,
94 amdgpu_ring_write(ring, PACKET0(mmUVD_RBC_IB_BASE, 0));
95 amdgpu_ring_write(ring, ib->gpu_addr);
96 amdgpu_ring_write(ring, PACKET0(mmUVD_RBC_IB_SIZE, 0));
97 amdgpu_ring_write(ring, ib->length_dw);
101 * uvd_v3_1_ring_emit_fence - emit an fence & trap command
103 * @ring: amdgpu_ring pointer
105 * @seq: sequence number
106 * @flags: fence related flags
108 * Write a fence and a trap command to the ring.
110 static void uvd_v3_1_ring_emit_fence(struct amdgpu_ring *ring, u64 addr, u64 seq,
113 WARN_ON(flags & AMDGPU_FENCE_FLAG_64BIT);
115 amdgpu_ring_write(ring, PACKET0(mmUVD_CONTEXT_ID, 0));
116 amdgpu_ring_write(ring, seq);
117 amdgpu_ring_write(ring, PACKET0(mmUVD_GPCOM_VCPU_DATA0, 0));
118 amdgpu_ring_write(ring, addr & 0xffffffff);
119 amdgpu_ring_write(ring, PACKET0(mmUVD_GPCOM_VCPU_DATA1, 0));
120 amdgpu_ring_write(ring, upper_32_bits(addr) & 0xff);
121 amdgpu_ring_write(ring, PACKET0(mmUVD_GPCOM_VCPU_CMD, 0));
122 amdgpu_ring_write(ring, 0);
124 amdgpu_ring_write(ring, PACKET0(mmUVD_GPCOM_VCPU_DATA0, 0));
125 amdgpu_ring_write(ring, 0);
126 amdgpu_ring_write(ring, PACKET0(mmUVD_GPCOM_VCPU_DATA1, 0));
127 amdgpu_ring_write(ring, 0);
128 amdgpu_ring_write(ring, PACKET0(mmUVD_GPCOM_VCPU_CMD, 0));
129 amdgpu_ring_write(ring, 2);
133 * uvd_v3_1_ring_test_ring - register write test
135 * @ring: amdgpu_ring pointer
137 * Test if we can successfully write to the context register
139 static int uvd_v3_1_ring_test_ring(struct amdgpu_ring *ring)
141 struct amdgpu_device *adev = ring->adev;
146 WREG32(mmUVD_CONTEXT_ID, 0xCAFEDEAD);
147 r = amdgpu_ring_alloc(ring, 3);
151 amdgpu_ring_write(ring, PACKET0(mmUVD_CONTEXT_ID, 0));
152 amdgpu_ring_write(ring, 0xDEADBEEF);
153 amdgpu_ring_commit(ring);
154 for (i = 0; i < adev->usec_timeout; i++) {
155 tmp = RREG32(mmUVD_CONTEXT_ID);
156 if (tmp == 0xDEADBEEF)
161 if (i >= adev->usec_timeout)
167 static void uvd_v3_1_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count)
171 WARN_ON(ring->wptr % 2 || count % 2);
173 for (i = 0; i < count / 2; i++) {
174 amdgpu_ring_write(ring, PACKET0(mmUVD_NO_OP, 0));
175 amdgpu_ring_write(ring, 0);
179 static const struct amdgpu_ring_funcs uvd_v3_1_ring_funcs = {
180 .type = AMDGPU_RING_TYPE_UVD,
182 .support_64bit_ptrs = false,
183 .no_user_fence = true,
184 .get_rptr = uvd_v3_1_ring_get_rptr,
185 .get_wptr = uvd_v3_1_ring_get_wptr,
186 .set_wptr = uvd_v3_1_ring_set_wptr,
187 .parse_cs = amdgpu_uvd_ring_parse_cs,
189 14, /* uvd_v3_1_ring_emit_fence x1 no user fence */
190 .emit_ib_size = 4, /* uvd_v3_1_ring_emit_ib */
191 .emit_ib = uvd_v3_1_ring_emit_ib,
192 .emit_fence = uvd_v3_1_ring_emit_fence,
193 .test_ring = uvd_v3_1_ring_test_ring,
194 .test_ib = amdgpu_uvd_ring_test_ib,
195 .insert_nop = uvd_v3_1_ring_insert_nop,
196 .pad_ib = amdgpu_ring_generic_pad_ib,
197 .begin_use = amdgpu_uvd_ring_begin_use,
198 .end_use = amdgpu_uvd_ring_end_use,
201 static void uvd_v3_1_set_ring_funcs(struct amdgpu_device *adev)
203 adev->uvd.inst->ring.funcs = &uvd_v3_1_ring_funcs;
206 static void uvd_v3_1_set_dcm(struct amdgpu_device *adev,
211 WREG32_FIELD(UVD_CGC_GATE, REGS, 0);
213 tmp = RREG32(mmUVD_CGC_CTRL);
214 tmp &= ~(UVD_CGC_CTRL__CLK_OFF_DELAY_MASK | UVD_CGC_CTRL__CLK_GATE_DLY_TIMER_MASK);
215 tmp |= UVD_CGC_CTRL__DYN_CLOCK_MODE_MASK |
216 (1 << UVD_CGC_CTRL__CLK_GATE_DLY_TIMER__SHIFT) |
217 (4 << UVD_CGC_CTRL__CLK_OFF_DELAY__SHIFT);
221 tmp2 = UVD_CGC_CTRL2__DYN_OCLK_RAMP_EN_MASK |
222 UVD_CGC_CTRL2__DYN_RCLK_RAMP_EN_MASK |
223 (7 << UVD_CGC_CTRL2__GATER_DIV_ID__SHIFT);
229 WREG32(mmUVD_CGC_CTRL, tmp);
230 WREG32_UVD_CTX(ixUVD_CGC_CTRL2, tmp2);
234 * uvd_v3_1_mc_resume - memory controller programming
236 * @adev: amdgpu_device pointer
238 * Let the UVD memory controller know it's offsets
240 static void uvd_v3_1_mc_resume(struct amdgpu_device *adev)
245 /* programm the VCPU memory controller bits 0-27 */
246 addr = (adev->uvd.inst->gpu_addr + AMDGPU_UVD_FIRMWARE_OFFSET) >> 3;
247 size = AMDGPU_UVD_FIRMWARE_SIZE(adev) >> 3;
248 WREG32(mmUVD_VCPU_CACHE_OFFSET0, addr);
249 WREG32(mmUVD_VCPU_CACHE_SIZE0, size);
252 size = AMDGPU_UVD_HEAP_SIZE >> 3;
253 WREG32(mmUVD_VCPU_CACHE_OFFSET1, addr);
254 WREG32(mmUVD_VCPU_CACHE_SIZE1, size);
257 size = (AMDGPU_UVD_STACK_SIZE +
258 (AMDGPU_UVD_SESSION_SIZE * adev->uvd.max_handles)) >> 3;
259 WREG32(mmUVD_VCPU_CACHE_OFFSET2, addr);
260 WREG32(mmUVD_VCPU_CACHE_SIZE2, size);
263 addr = (adev->uvd.inst->gpu_addr >> 28) & 0xF;
264 WREG32(mmUVD_LMI_ADDR_EXT, (addr << 12) | (addr << 0));
267 addr = (adev->uvd.inst->gpu_addr >> 32) & 0xFF;
268 WREG32(mmUVD_LMI_EXT40_ADDR, addr | (0x9 << 16) | (0x1 << 31));
270 WREG32(mmUVD_UDEC_ADDR_CONFIG, adev->gfx.config.gb_addr_config);
271 WREG32(mmUVD_UDEC_DB_ADDR_CONFIG, adev->gfx.config.gb_addr_config);
272 WREG32(mmUVD_UDEC_DBW_ADDR_CONFIG, adev->gfx.config.gb_addr_config);
276 * uvd_v3_1_fw_validate - FW validation operation
278 * @adev: amdgpu_device pointer
280 * Initialate and check UVD validation.
282 static int uvd_v3_1_fw_validate(struct amdgpu_device *adev)
285 uint32_t keysel = adev->uvd.keyselect;
287 WREG32(mmUVD_FW_START, keysel);
289 for (i = 0; i < 10; ++i) {
291 if (RREG32(mmUVD_FW_STATUS) & UVD_FW_STATUS__DONE_MASK)
298 if (!(RREG32(mmUVD_FW_STATUS) & UVD_FW_STATUS__PASS_MASK))
301 for (i = 0; i < 10; ++i) {
303 if (!(RREG32(mmUVD_FW_STATUS) & UVD_FW_STATUS__BUSY_MASK))
314 * uvd_v3_1_start - start UVD block
316 * @adev: amdgpu_device pointer
318 * Setup and start the UVD block
320 static int uvd_v3_1_start(struct amdgpu_device *adev)
322 struct amdgpu_ring *ring = &adev->uvd.inst->ring;
326 /* disable byte swapping */
327 u32 lmi_swap_cntl = 0;
328 u32 mp_swap_cntl = 0;
331 WREG32_P(mmUVD_STATUS, 1<<2, ~(1<<2));
333 uvd_v3_1_set_dcm(adev, true);
334 WREG32(mmUVD_CGC_GATE, 0);
336 /* take UVD block out of reset */
337 WREG32_P(mmSRBM_SOFT_RESET, 0, ~SRBM_SOFT_RESET__SOFT_RESET_UVD_MASK);
340 /* enable VCPU clock */
341 WREG32(mmUVD_VCPU_CNTL, 1 << 9);
343 /* disable interrupt */
344 WREG32_P(mmUVD_MASTINT_EN, 0, ~(1 << 1));
347 /* swap (8 in 32) RB and IB */
351 WREG32(mmUVD_LMI_SWAP_CNTL, lmi_swap_cntl);
352 WREG32(mmUVD_MP_SWAP_CNTL, mp_swap_cntl);
354 /* initialize UVD memory controller */
355 WREG32(mmUVD_LMI_CTRL, 0x40 | (1 << 8) | (1 << 13) |
356 (1 << 21) | (1 << 9) | (1 << 20));
358 tmp = RREG32(mmUVD_MPC_CNTL);
359 WREG32(mmUVD_MPC_CNTL, tmp | 0x10);
361 WREG32(mmUVD_MPC_SET_MUXA0, 0x40c2040);
362 WREG32(mmUVD_MPC_SET_MUXA1, 0x0);
363 WREG32(mmUVD_MPC_SET_MUXB0, 0x40c2040);
364 WREG32(mmUVD_MPC_SET_MUXB1, 0x0);
365 WREG32(mmUVD_MPC_SET_ALU, 0);
366 WREG32(mmUVD_MPC_SET_MUX, 0x88);
368 tmp = RREG32_UVD_CTX(ixUVD_LMI_CACHE_CTRL);
369 WREG32_UVD_CTX(ixUVD_LMI_CACHE_CTRL, tmp & (~0x10));
372 WREG32_P(mmUVD_LMI_CTRL2, 0, ~(1 << 8));
374 WREG32_P(mmUVD_SOFT_RESET, 0, ~UVD_SOFT_RESET__LMI_SOFT_RESET_MASK);
376 WREG32_P(mmUVD_SOFT_RESET, 0, ~UVD_SOFT_RESET__LMI_UMC_SOFT_RESET_MASK);
378 WREG32_P(mmUVD_SOFT_RESET, 0, ~UVD_SOFT_RESET__VCPU_SOFT_RESET_MASK);
382 for (i = 0; i < 10; ++i) {
384 for (j = 0; j < 100; ++j) {
385 status = RREG32(mmUVD_STATUS);
394 DRM_ERROR("UVD not responding, trying to reset the VCPU!!!\n");
395 WREG32_P(mmUVD_SOFT_RESET, UVD_SOFT_RESET__VCPU_SOFT_RESET_MASK,
396 ~UVD_SOFT_RESET__VCPU_SOFT_RESET_MASK);
398 WREG32_P(mmUVD_SOFT_RESET, 0, ~UVD_SOFT_RESET__VCPU_SOFT_RESET_MASK);
404 DRM_ERROR("UVD not responding, giving up!!!\n");
408 /* enable interrupt */
409 WREG32_P(mmUVD_MASTINT_EN, 3<<1, ~(3 << 1));
411 WREG32_P(mmUVD_STATUS, 0, ~(1<<2));
413 /* force RBC into idle state */
414 WREG32(mmUVD_RBC_RB_CNTL, 0x11010101);
416 /* Set the write pointer delay */
417 WREG32(mmUVD_RBC_RB_WPTR_CNTL, 0);
419 /* programm the 4GB memory segment for rptr and ring buffer */
420 WREG32(mmUVD_LMI_EXT40_ADDR, upper_32_bits(ring->gpu_addr) |
421 (0x7 << 16) | (0x1 << 31));
423 /* Initialize the ring buffer's read and write pointers */
424 WREG32(mmUVD_RBC_RB_RPTR, 0x0);
426 ring->wptr = RREG32(mmUVD_RBC_RB_RPTR);
427 WREG32(mmUVD_RBC_RB_WPTR, lower_32_bits(ring->wptr));
429 /* set the ring address */
430 WREG32(mmUVD_RBC_RB_BASE, ring->gpu_addr);
432 /* Set ring buffer size */
433 rb_bufsz = order_base_2(ring->ring_size);
434 rb_bufsz = (0x1 << 8) | rb_bufsz;
435 WREG32_P(mmUVD_RBC_RB_CNTL, rb_bufsz, ~0x11f1f);
441 * uvd_v3_1_stop - stop UVD block
443 * @adev: amdgpu_device pointer
447 static void uvd_v3_1_stop(struct amdgpu_device *adev)
452 WREG32(mmUVD_RBC_RB_CNTL, 0x11010101);
454 for (i = 0; i < 10; ++i) {
455 for (j = 0; j < 100; ++j) {
456 status = RREG32(mmUVD_STATUS);
465 for (i = 0; i < 10; ++i) {
466 for (j = 0; j < 100; ++j) {
467 status = RREG32(mmUVD_LMI_STATUS);
476 /* Stall UMC and register bus before resetting VCPU */
477 WREG32_P(mmUVD_LMI_CTRL2, 1 << 8, ~(1 << 8));
479 for (i = 0; i < 10; ++i) {
480 for (j = 0; j < 100; ++j) {
481 status = RREG32(mmUVD_LMI_STATUS);
490 WREG32_P(0x3D49, 0, ~(1 << 2));
492 WREG32_P(mmUVD_VCPU_CNTL, 0, ~(1 << 9));
494 /* put LMI, VCPU, RBC etc... into reset */
495 WREG32(mmUVD_SOFT_RESET, UVD_SOFT_RESET__LMI_SOFT_RESET_MASK |
496 UVD_SOFT_RESET__VCPU_SOFT_RESET_MASK |
497 UVD_SOFT_RESET__LMI_UMC_SOFT_RESET_MASK);
499 WREG32(mmUVD_STATUS, 0);
501 uvd_v3_1_set_dcm(adev, false);
504 static int uvd_v3_1_set_interrupt_state(struct amdgpu_device *adev,
505 struct amdgpu_irq_src *source,
507 enum amdgpu_interrupt_state state)
512 static int uvd_v3_1_process_interrupt(struct amdgpu_device *adev,
513 struct amdgpu_irq_src *source,
514 struct amdgpu_iv_entry *entry)
516 DRM_DEBUG("IH: UVD TRAP\n");
517 amdgpu_fence_process(&adev->uvd.inst->ring);
522 static const struct amdgpu_irq_src_funcs uvd_v3_1_irq_funcs = {
523 .set = uvd_v3_1_set_interrupt_state,
524 .process = uvd_v3_1_process_interrupt,
527 static void uvd_v3_1_set_irq_funcs(struct amdgpu_device *adev)
529 adev->uvd.inst->irq.num_types = 1;
530 adev->uvd.inst->irq.funcs = &uvd_v3_1_irq_funcs;
534 static int uvd_v3_1_early_init(void *handle)
536 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
537 adev->uvd.num_uvd_inst = 1;
539 uvd_v3_1_set_ring_funcs(adev);
540 uvd_v3_1_set_irq_funcs(adev);
545 static int uvd_v3_1_sw_init(void *handle)
547 struct amdgpu_ring *ring;
548 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
554 r = amdgpu_irq_add_id(adev, AMDGPU_IRQ_CLIENTID_LEGACY, 124, &adev->uvd.inst->irq);
558 r = amdgpu_uvd_sw_init(adev);
562 ring = &adev->uvd.inst->ring;
563 sprintf(ring->name, "uvd");
564 r = amdgpu_ring_init(adev, ring, 512, &adev->uvd.inst->irq, 0,
565 AMDGPU_RING_PRIO_DEFAULT, NULL);
569 r = amdgpu_uvd_resume(adev);
573 /* Retrieval firmware validate key */
574 ptr = adev->uvd.inst[0].cpu_addr;
576 memcpy(&ucode_len, ptr, 4);
578 memcpy(&adev->uvd.keyselect, ptr, 4);
580 r = amdgpu_uvd_entity_init(adev);
585 static int uvd_v3_1_sw_fini(void *handle)
588 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
590 r = amdgpu_uvd_suspend(adev);
594 return amdgpu_uvd_sw_fini(adev);
597 static void uvd_v3_1_enable_mgcg(struct amdgpu_device *adev,
602 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_UVD_MGCG)) {
603 data = RREG32_UVD_CTX(ixUVD_CGC_MEM_CTRL);
605 WREG32_UVD_CTX(ixUVD_CGC_MEM_CTRL, data);
607 orig = data = RREG32(mmUVD_CGC_CTRL);
608 data |= UVD_CGC_CTRL__DYN_CLOCK_MODE_MASK;
610 WREG32(mmUVD_CGC_CTRL, data);
612 data = RREG32_UVD_CTX(ixUVD_CGC_MEM_CTRL);
614 WREG32_UVD_CTX(ixUVD_CGC_MEM_CTRL, data);
616 orig = data = RREG32(mmUVD_CGC_CTRL);
617 data &= ~UVD_CGC_CTRL__DYN_CLOCK_MODE_MASK;
619 WREG32(mmUVD_CGC_CTRL, data);
624 * uvd_v3_1_hw_init - start and test UVD block
626 * @handle: handle used to pass amdgpu_device pointer
628 * Initialize the hardware, boot up the VCPU and do some testing
630 static int uvd_v3_1_hw_init(void *handle)
632 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
633 struct amdgpu_ring *ring = &adev->uvd.inst->ring;
637 uvd_v3_1_mc_resume(adev);
639 r = uvd_v3_1_fw_validate(adev);
641 DRM_ERROR("amdgpu: UVD Firmware validate fail (%d).\n", r);
645 uvd_v3_1_enable_mgcg(adev, true);
646 amdgpu_asic_set_uvd_clocks(adev, 53300, 40000);
648 uvd_v3_1_start(adev);
650 r = amdgpu_ring_test_helper(ring);
652 DRM_ERROR("amdgpu: UVD ring test fail (%d).\n", r);
656 r = amdgpu_ring_alloc(ring, 10);
658 DRM_ERROR("amdgpu: ring failed to lock UVD ring (%d).\n", r);
662 tmp = PACKET0(mmUVD_SEMA_WAIT_FAULT_TIMEOUT_CNTL, 0);
663 amdgpu_ring_write(ring, tmp);
664 amdgpu_ring_write(ring, 0xFFFFF);
666 tmp = PACKET0(mmUVD_SEMA_WAIT_INCOMPLETE_TIMEOUT_CNTL, 0);
667 amdgpu_ring_write(ring, tmp);
668 amdgpu_ring_write(ring, 0xFFFFF);
670 tmp = PACKET0(mmUVD_SEMA_SIGNAL_INCOMPLETE_TIMEOUT_CNTL, 0);
671 amdgpu_ring_write(ring, tmp);
672 amdgpu_ring_write(ring, 0xFFFFF);
674 /* Clear timeout status bits */
675 amdgpu_ring_write(ring, PACKET0(mmUVD_SEMA_TIMEOUT_STATUS, 0));
676 amdgpu_ring_write(ring, 0x8);
678 amdgpu_ring_write(ring, PACKET0(mmUVD_SEMA_CNTL, 0));
679 amdgpu_ring_write(ring, 3);
681 amdgpu_ring_commit(ring);
685 DRM_INFO("UVD initialized successfully.\n");
691 * uvd_v3_1_hw_fini - stop the hardware block
693 * @handle: handle used to pass amdgpu_device pointer
695 * Stop the UVD block, mark ring as not ready any more
697 static int uvd_v3_1_hw_fini(void *handle)
699 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
702 * Proper cleanups before halting the HW engine:
703 * - cancel the delayed idle work
704 * - enable powergating
705 * - enable clockgating
708 * TODO: to align with the VCN implementation, move the
709 * jobs for clockgating/powergating/dpm setting to
710 * ->set_powergating_state().
712 cancel_delayed_work_sync(&adev->uvd.idle_work);
714 if (adev->pm.dpm_enabled) {
715 amdgpu_dpm_enable_uvd(adev, false);
717 amdgpu_asic_set_uvd_clocks(adev, 0, 0);
718 /* shutdown the UVD block */
719 amdgpu_device_ip_set_powergating_state(adev, AMD_IP_BLOCK_TYPE_UVD,
721 amdgpu_device_ip_set_clockgating_state(adev, AMD_IP_BLOCK_TYPE_UVD,
725 if (RREG32(mmUVD_STATUS) != 0)
731 static int uvd_v3_1_suspend(void *handle)
734 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
736 r = uvd_v3_1_hw_fini(adev);
740 return amdgpu_uvd_suspend(adev);
743 static int uvd_v3_1_resume(void *handle)
746 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
748 r = amdgpu_uvd_resume(adev);
752 return uvd_v3_1_hw_init(adev);
755 static bool uvd_v3_1_is_idle(void *handle)
757 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
759 return !(RREG32(mmSRBM_STATUS) & SRBM_STATUS__UVD_BUSY_MASK);
762 static int uvd_v3_1_wait_for_idle(void *handle)
765 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
767 for (i = 0; i < adev->usec_timeout; i++) {
768 if (!(RREG32(mmSRBM_STATUS) & SRBM_STATUS__UVD_BUSY_MASK))
774 static int uvd_v3_1_soft_reset(void *handle)
776 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
780 WREG32_P(mmSRBM_SOFT_RESET, SRBM_SOFT_RESET__SOFT_RESET_UVD_MASK,
781 ~SRBM_SOFT_RESET__SOFT_RESET_UVD_MASK);
784 return uvd_v3_1_start(adev);
787 static int uvd_v3_1_set_clockgating_state(void *handle,
788 enum amd_clockgating_state state)
793 static int uvd_v3_1_set_powergating_state(void *handle,
794 enum amd_powergating_state state)
799 static const struct amd_ip_funcs uvd_v3_1_ip_funcs = {
801 .early_init = uvd_v3_1_early_init,
803 .sw_init = uvd_v3_1_sw_init,
804 .sw_fini = uvd_v3_1_sw_fini,
805 .hw_init = uvd_v3_1_hw_init,
806 .hw_fini = uvd_v3_1_hw_fini,
807 .suspend = uvd_v3_1_suspend,
808 .resume = uvd_v3_1_resume,
809 .is_idle = uvd_v3_1_is_idle,
810 .wait_for_idle = uvd_v3_1_wait_for_idle,
811 .soft_reset = uvd_v3_1_soft_reset,
812 .set_clockgating_state = uvd_v3_1_set_clockgating_state,
813 .set_powergating_state = uvd_v3_1_set_powergating_state,
816 const struct amdgpu_ip_block_version uvd_v3_1_ip_block =
818 .type = AMD_IP_BLOCK_TYPE_UVD,
822 .funcs = &uvd_v3_1_ip_funcs,