2 * Copyright 2016 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.
24 #include <linux/firmware.h>
27 #include "amdgpu_uvd.h"
30 #include "soc15_common.h"
31 #include "mmsch_v1_0.h"
33 #include "uvd/uvd_7_0_offset.h"
34 #include "uvd/uvd_7_0_sh_mask.h"
35 #include "vce/vce_4_0_offset.h"
36 #include "vce/vce_4_0_default.h"
37 #include "vce/vce_4_0_sh_mask.h"
38 #include "nbif/nbif_6_1_offset.h"
39 #include "hdp/hdp_4_0_offset.h"
40 #include "mmhub/mmhub_1_0_offset.h"
41 #include "mmhub/mmhub_1_0_sh_mask.h"
42 #include "ivsrcid/uvd/irqsrcs_uvd_7_0.h"
44 #define mmUVD_PG0_CC_UVD_HARVESTING 0x00c7
45 #define mmUVD_PG0_CC_UVD_HARVESTING_BASE_IDX 1
46 //UVD_PG0_CC_UVD_HARVESTING
47 #define UVD_PG0_CC_UVD_HARVESTING__UVD_DISABLE__SHIFT 0x1
48 #define UVD_PG0_CC_UVD_HARVESTING__UVD_DISABLE_MASK 0x00000002L
50 #define UVD7_MAX_HW_INSTANCES_VEGA20 2
52 static void uvd_v7_0_set_ring_funcs(struct amdgpu_device
*adev
);
53 static void uvd_v7_0_set_enc_ring_funcs(struct amdgpu_device
*adev
);
54 static void uvd_v7_0_set_irq_funcs(struct amdgpu_device
*adev
);
55 static int uvd_v7_0_start(struct amdgpu_device
*adev
);
56 static void uvd_v7_0_stop(struct amdgpu_device
*adev
);
57 static int uvd_v7_0_sriov_start(struct amdgpu_device
*adev
);
59 static int amdgpu_ih_clientid_uvds
[] = {
60 SOC15_IH_CLIENTID_UVD
,
61 SOC15_IH_CLIENTID_UVD1
65 * uvd_v7_0_ring_get_rptr - get read pointer
67 * @ring: amdgpu_ring pointer
69 * Returns the current hardware read pointer
71 static uint64_t uvd_v7_0_ring_get_rptr(struct amdgpu_ring
*ring
)
73 struct amdgpu_device
*adev
= ring
->adev
;
75 return RREG32_SOC15(UVD
, ring
->me
, mmUVD_RBC_RB_RPTR
);
79 * uvd_v7_0_enc_ring_get_rptr - get enc read pointer
81 * @ring: amdgpu_ring pointer
83 * Returns the current hardware enc read pointer
85 static uint64_t uvd_v7_0_enc_ring_get_rptr(struct amdgpu_ring
*ring
)
87 struct amdgpu_device
*adev
= ring
->adev
;
89 if (ring
== &adev
->uvd
.inst
[ring
->me
].ring_enc
[0])
90 return RREG32_SOC15(UVD
, ring
->me
, mmUVD_RB_RPTR
);
92 return RREG32_SOC15(UVD
, ring
->me
, mmUVD_RB_RPTR2
);
96 * uvd_v7_0_ring_get_wptr - get write pointer
98 * @ring: amdgpu_ring pointer
100 * Returns the current hardware write pointer
102 static uint64_t uvd_v7_0_ring_get_wptr(struct amdgpu_ring
*ring
)
104 struct amdgpu_device
*adev
= ring
->adev
;
106 return RREG32_SOC15(UVD
, ring
->me
, mmUVD_RBC_RB_WPTR
);
110 * uvd_v7_0_enc_ring_get_wptr - get enc write pointer
112 * @ring: amdgpu_ring pointer
114 * Returns the current hardware enc write pointer
116 static uint64_t uvd_v7_0_enc_ring_get_wptr(struct amdgpu_ring
*ring
)
118 struct amdgpu_device
*adev
= ring
->adev
;
120 if (ring
->use_doorbell
)
121 return adev
->wb
.wb
[ring
->wptr_offs
];
123 if (ring
== &adev
->uvd
.inst
[ring
->me
].ring_enc
[0])
124 return RREG32_SOC15(UVD
, ring
->me
, mmUVD_RB_WPTR
);
126 return RREG32_SOC15(UVD
, ring
->me
, mmUVD_RB_WPTR2
);
130 * uvd_v7_0_ring_set_wptr - set write pointer
132 * @ring: amdgpu_ring pointer
134 * Commits the write pointer to the hardware
136 static void uvd_v7_0_ring_set_wptr(struct amdgpu_ring
*ring
)
138 struct amdgpu_device
*adev
= ring
->adev
;
140 WREG32_SOC15(UVD
, ring
->me
, mmUVD_RBC_RB_WPTR
, lower_32_bits(ring
->wptr
));
144 * uvd_v7_0_enc_ring_set_wptr - set enc write pointer
146 * @ring: amdgpu_ring pointer
148 * Commits the enc write pointer to the hardware
150 static void uvd_v7_0_enc_ring_set_wptr(struct amdgpu_ring
*ring
)
152 struct amdgpu_device
*adev
= ring
->adev
;
154 if (ring
->use_doorbell
) {
155 /* XXX check if swapping is necessary on BE */
156 adev
->wb
.wb
[ring
->wptr_offs
] = lower_32_bits(ring
->wptr
);
157 WDOORBELL32(ring
->doorbell_index
, lower_32_bits(ring
->wptr
));
161 if (ring
== &adev
->uvd
.inst
[ring
->me
].ring_enc
[0])
162 WREG32_SOC15(UVD
, ring
->me
, mmUVD_RB_WPTR
,
163 lower_32_bits(ring
->wptr
));
165 WREG32_SOC15(UVD
, ring
->me
, mmUVD_RB_WPTR2
,
166 lower_32_bits(ring
->wptr
));
170 * uvd_v7_0_enc_ring_test_ring - test if UVD ENC ring is working
172 * @ring: the engine to test on
175 static int uvd_v7_0_enc_ring_test_ring(struct amdgpu_ring
*ring
)
177 struct amdgpu_device
*adev
= ring
->adev
;
178 uint32_t rptr
= amdgpu_ring_get_rptr(ring
);
182 if (amdgpu_sriov_vf(adev
))
185 r
= amdgpu_ring_alloc(ring
, 16);
188 amdgpu_ring_write(ring
, HEVC_ENC_CMD_END
);
189 amdgpu_ring_commit(ring
);
191 for (i
= 0; i
< adev
->usec_timeout
; i
++) {
192 if (amdgpu_ring_get_rptr(ring
) != rptr
)
197 if (i
>= adev
->usec_timeout
)
204 * uvd_v7_0_enc_get_create_msg - generate a UVD ENC create msg
206 * @adev: amdgpu_device pointer
207 * @ring: ring we should submit the msg to
208 * @handle: session handle to use
209 * @fence: optional fence to return
211 * Open up a stream for HW test
213 static int uvd_v7_0_enc_get_create_msg(struct amdgpu_ring
*ring
, uint32_t handle
,
214 struct dma_fence
**fence
)
216 const unsigned ib_size_dw
= 16;
217 struct amdgpu_job
*job
;
218 struct amdgpu_ib
*ib
;
219 struct dma_fence
*f
= NULL
;
223 r
= amdgpu_job_alloc_with_ib(ring
->adev
, ib_size_dw
* 4, &job
);
228 dummy
= ib
->gpu_addr
+ 1024;
231 ib
->ptr
[ib
->length_dw
++] = 0x00000018;
232 ib
->ptr
[ib
->length_dw
++] = 0x00000001; /* session info */
233 ib
->ptr
[ib
->length_dw
++] = handle
;
234 ib
->ptr
[ib
->length_dw
++] = 0x00000000;
235 ib
->ptr
[ib
->length_dw
++] = upper_32_bits(dummy
);
236 ib
->ptr
[ib
->length_dw
++] = dummy
;
238 ib
->ptr
[ib
->length_dw
++] = 0x00000014;
239 ib
->ptr
[ib
->length_dw
++] = 0x00000002; /* task info */
240 ib
->ptr
[ib
->length_dw
++] = 0x0000001c;
241 ib
->ptr
[ib
->length_dw
++] = 0x00000000;
242 ib
->ptr
[ib
->length_dw
++] = 0x00000000;
244 ib
->ptr
[ib
->length_dw
++] = 0x00000008;
245 ib
->ptr
[ib
->length_dw
++] = 0x08000001; /* op initialize */
247 for (i
= ib
->length_dw
; i
< ib_size_dw
; ++i
)
250 r
= amdgpu_job_submit_direct(job
, ring
, &f
);
255 *fence
= dma_fence_get(f
);
260 amdgpu_job_free(job
);
265 * uvd_v7_0_enc_get_destroy_msg - generate a UVD ENC destroy msg
267 * @adev: amdgpu_device pointer
268 * @ring: ring we should submit the msg to
269 * @handle: session handle to use
270 * @fence: optional fence to return
272 * Close up a stream for HW test or if userspace failed to do so
274 static int uvd_v7_0_enc_get_destroy_msg(struct amdgpu_ring
*ring
, uint32_t handle
,
275 struct dma_fence
**fence
)
277 const unsigned ib_size_dw
= 16;
278 struct amdgpu_job
*job
;
279 struct amdgpu_ib
*ib
;
280 struct dma_fence
*f
= NULL
;
284 r
= amdgpu_job_alloc_with_ib(ring
->adev
, ib_size_dw
* 4, &job
);
289 dummy
= ib
->gpu_addr
+ 1024;
292 ib
->ptr
[ib
->length_dw
++] = 0x00000018;
293 ib
->ptr
[ib
->length_dw
++] = 0x00000001;
294 ib
->ptr
[ib
->length_dw
++] = handle
;
295 ib
->ptr
[ib
->length_dw
++] = 0x00000000;
296 ib
->ptr
[ib
->length_dw
++] = upper_32_bits(dummy
);
297 ib
->ptr
[ib
->length_dw
++] = dummy
;
299 ib
->ptr
[ib
->length_dw
++] = 0x00000014;
300 ib
->ptr
[ib
->length_dw
++] = 0x00000002;
301 ib
->ptr
[ib
->length_dw
++] = 0x0000001c;
302 ib
->ptr
[ib
->length_dw
++] = 0x00000000;
303 ib
->ptr
[ib
->length_dw
++] = 0x00000000;
305 ib
->ptr
[ib
->length_dw
++] = 0x00000008;
306 ib
->ptr
[ib
->length_dw
++] = 0x08000002; /* op close session */
308 for (i
= ib
->length_dw
; i
< ib_size_dw
; ++i
)
311 r
= amdgpu_job_submit_direct(job
, ring
, &f
);
316 *fence
= dma_fence_get(f
);
321 amdgpu_job_free(job
);
326 * uvd_v7_0_enc_ring_test_ib - test if UVD ENC IBs are working
328 * @ring: the engine to test on
331 static int uvd_v7_0_enc_ring_test_ib(struct amdgpu_ring
*ring
, long timeout
)
333 struct dma_fence
*fence
= NULL
;
336 r
= uvd_v7_0_enc_get_create_msg(ring
, 1, NULL
);
340 r
= uvd_v7_0_enc_get_destroy_msg(ring
, 1, &fence
);
344 r
= dma_fence_wait_timeout(fence
, false, timeout
);
351 dma_fence_put(fence
);
355 static int uvd_v7_0_early_init(void *handle
)
357 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
359 if (adev
->asic_type
== CHIP_VEGA20
) {
363 adev
->uvd
.num_uvd_inst
= UVD7_MAX_HW_INSTANCES_VEGA20
;
364 for (i
= 0; i
< adev
->uvd
.num_uvd_inst
; i
++) {
365 harvest
= RREG32_SOC15(UVD
, i
, mmUVD_PG0_CC_UVD_HARVESTING
);
366 if (harvest
& UVD_PG0_CC_UVD_HARVESTING__UVD_DISABLE_MASK
) {
367 adev
->uvd
.harvest_config
|= 1 << i
;
370 if (adev
->uvd
.harvest_config
== (AMDGPU_UVD_HARVEST_UVD0
|
371 AMDGPU_UVD_HARVEST_UVD1
))
372 /* both instances are harvested, disable the block */
375 adev
->uvd
.num_uvd_inst
= 1;
378 if (amdgpu_sriov_vf(adev
))
379 adev
->uvd
.num_enc_rings
= 1;
381 adev
->uvd
.num_enc_rings
= 2;
382 uvd_v7_0_set_ring_funcs(adev
);
383 uvd_v7_0_set_enc_ring_funcs(adev
);
384 uvd_v7_0_set_irq_funcs(adev
);
389 static int uvd_v7_0_sw_init(void *handle
)
391 struct amdgpu_ring
*ring
;
394 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
396 for (j
= 0; j
< adev
->uvd
.num_uvd_inst
; j
++) {
397 if (adev
->uvd
.harvest_config
& (1 << j
))
400 r
= amdgpu_irq_add_id(adev
, amdgpu_ih_clientid_uvds
[j
], UVD_7_0__SRCID__UVD_SYSTEM_MESSAGE_INTERRUPT
, &adev
->uvd
.inst
[j
].irq
);
405 for (i
= 0; i
< adev
->uvd
.num_enc_rings
; ++i
) {
406 r
= amdgpu_irq_add_id(adev
, amdgpu_ih_clientid_uvds
[j
], i
+ UVD_7_0__SRCID__UVD_ENC_GEN_PURP
, &adev
->uvd
.inst
[j
].irq
);
412 r
= amdgpu_uvd_sw_init(adev
);
416 if (adev
->firmware
.load_type
== AMDGPU_FW_LOAD_PSP
) {
417 const struct common_firmware_header
*hdr
;
418 hdr
= (const struct common_firmware_header
*)adev
->uvd
.fw
->data
;
419 adev
->firmware
.ucode
[AMDGPU_UCODE_ID_UVD
].ucode_id
= AMDGPU_UCODE_ID_UVD
;
420 adev
->firmware
.ucode
[AMDGPU_UCODE_ID_UVD
].fw
= adev
->uvd
.fw
;
421 adev
->firmware
.fw_size
+=
422 ALIGN(le32_to_cpu(hdr
->ucode_size_bytes
), PAGE_SIZE
);
424 if (adev
->uvd
.num_uvd_inst
== UVD7_MAX_HW_INSTANCES_VEGA20
) {
425 adev
->firmware
.ucode
[AMDGPU_UCODE_ID_UVD1
].ucode_id
= AMDGPU_UCODE_ID_UVD1
;
426 adev
->firmware
.ucode
[AMDGPU_UCODE_ID_UVD1
].fw
= adev
->uvd
.fw
;
427 adev
->firmware
.fw_size
+=
428 ALIGN(le32_to_cpu(hdr
->ucode_size_bytes
), PAGE_SIZE
);
430 DRM_INFO("PSP loading UVD firmware\n");
433 for (j
= 0; j
< adev
->uvd
.num_uvd_inst
; j
++) {
434 if (adev
->uvd
.harvest_config
& (1 << j
))
436 if (!amdgpu_sriov_vf(adev
)) {
437 ring
= &adev
->uvd
.inst
[j
].ring
;
438 sprintf(ring
->name
, "uvd_%d", ring
->me
);
439 r
= amdgpu_ring_init(adev
, ring
, 512, &adev
->uvd
.inst
[j
].irq
, 0);
444 for (i
= 0; i
< adev
->uvd
.num_enc_rings
; ++i
) {
445 ring
= &adev
->uvd
.inst
[j
].ring_enc
[i
];
446 sprintf(ring
->name
, "uvd_enc_%d.%d", ring
->me
, i
);
447 if (amdgpu_sriov_vf(adev
)) {
448 ring
->use_doorbell
= true;
450 /* currently only use the first enconding ring for
451 * sriov, so set unused location for other unused rings.
454 ring
->doorbell_index
= adev
->doorbell_index
.uvd_vce
.uvd_ring0_1
* 2;
456 ring
->doorbell_index
= adev
->doorbell_index
.uvd_vce
.uvd_ring2_3
* 2 + 1;
458 r
= amdgpu_ring_init(adev
, ring
, 512, &adev
->uvd
.inst
[j
].irq
, 0);
464 r
= amdgpu_uvd_resume(adev
);
468 r
= amdgpu_uvd_entity_init(adev
);
472 r
= amdgpu_virt_alloc_mm_table(adev
);
479 static int uvd_v7_0_sw_fini(void *handle
)
482 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
484 amdgpu_virt_free_mm_table(adev
);
486 r
= amdgpu_uvd_suspend(adev
);
490 for (j
= 0; j
< adev
->uvd
.num_uvd_inst
; ++j
) {
491 if (adev
->uvd
.harvest_config
& (1 << j
))
493 for (i
= 0; i
< adev
->uvd
.num_enc_rings
; ++i
)
494 amdgpu_ring_fini(&adev
->uvd
.inst
[j
].ring_enc
[i
]);
496 return amdgpu_uvd_sw_fini(adev
);
500 * uvd_v7_0_hw_init - start and test UVD block
502 * @adev: amdgpu_device pointer
504 * Initialize the hardware, boot up the VCPU and do some testing
506 static int uvd_v7_0_hw_init(void *handle
)
508 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
509 struct amdgpu_ring
*ring
;
513 if (amdgpu_sriov_vf(adev
))
514 r
= uvd_v7_0_sriov_start(adev
);
516 r
= uvd_v7_0_start(adev
);
520 for (j
= 0; j
< adev
->uvd
.num_uvd_inst
; ++j
) {
521 if (adev
->uvd
.harvest_config
& (1 << j
))
523 ring
= &adev
->uvd
.inst
[j
].ring
;
525 if (!amdgpu_sriov_vf(adev
)) {
526 r
= amdgpu_ring_test_helper(ring
);
530 r
= amdgpu_ring_alloc(ring
, 10);
532 DRM_ERROR("amdgpu: (%d)ring failed to lock UVD ring (%d).\n", j
, r
);
536 tmp
= PACKET0(SOC15_REG_OFFSET(UVD
, j
,
537 mmUVD_SEMA_WAIT_FAULT_TIMEOUT_CNTL
), 0);
538 amdgpu_ring_write(ring
, tmp
);
539 amdgpu_ring_write(ring
, 0xFFFFF);
541 tmp
= PACKET0(SOC15_REG_OFFSET(UVD
, j
,
542 mmUVD_SEMA_WAIT_INCOMPLETE_TIMEOUT_CNTL
), 0);
543 amdgpu_ring_write(ring
, tmp
);
544 amdgpu_ring_write(ring
, 0xFFFFF);
546 tmp
= PACKET0(SOC15_REG_OFFSET(UVD
, j
,
547 mmUVD_SEMA_SIGNAL_INCOMPLETE_TIMEOUT_CNTL
), 0);
548 amdgpu_ring_write(ring
, tmp
);
549 amdgpu_ring_write(ring
, 0xFFFFF);
551 /* Clear timeout status bits */
552 amdgpu_ring_write(ring
, PACKET0(SOC15_REG_OFFSET(UVD
, j
,
553 mmUVD_SEMA_TIMEOUT_STATUS
), 0));
554 amdgpu_ring_write(ring
, 0x8);
556 amdgpu_ring_write(ring
, PACKET0(SOC15_REG_OFFSET(UVD
, j
,
557 mmUVD_SEMA_CNTL
), 0));
558 amdgpu_ring_write(ring
, 3);
560 amdgpu_ring_commit(ring
);
563 for (i
= 0; i
< adev
->uvd
.num_enc_rings
; ++i
) {
564 ring
= &adev
->uvd
.inst
[j
].ring_enc
[i
];
565 r
= amdgpu_ring_test_helper(ring
);
572 DRM_INFO("UVD and UVD ENC initialized successfully.\n");
578 * uvd_v7_0_hw_fini - stop the hardware block
580 * @adev: amdgpu_device pointer
582 * Stop the UVD block, mark ring as not ready any more
584 static int uvd_v7_0_hw_fini(void *handle
)
586 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
589 if (!amdgpu_sriov_vf(adev
))
592 /* full access mode, so don't touch any UVD register */
593 DRM_DEBUG("For SRIOV client, shouldn't do anything.\n");
596 for (i
= 0; i
< adev
->uvd
.num_uvd_inst
; ++i
) {
597 if (adev
->uvd
.harvest_config
& (1 << i
))
599 adev
->uvd
.inst
[i
].ring
.sched
.ready
= false;
605 static int uvd_v7_0_suspend(void *handle
)
608 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
610 r
= uvd_v7_0_hw_fini(adev
);
614 return amdgpu_uvd_suspend(adev
);
617 static int uvd_v7_0_resume(void *handle
)
620 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
622 r
= amdgpu_uvd_resume(adev
);
626 return uvd_v7_0_hw_init(adev
);
630 * uvd_v7_0_mc_resume - memory controller programming
632 * @adev: amdgpu_device pointer
634 * Let the UVD memory controller know it's offsets
636 static void uvd_v7_0_mc_resume(struct amdgpu_device
*adev
)
638 uint32_t size
= AMDGPU_UVD_FIRMWARE_SIZE(adev
);
642 for (i
= 0; i
< adev
->uvd
.num_uvd_inst
; ++i
) {
643 if (adev
->uvd
.harvest_config
& (1 << i
))
645 if (adev
->firmware
.load_type
== AMDGPU_FW_LOAD_PSP
) {
646 WREG32_SOC15(UVD
, i
, mmUVD_LMI_VCPU_CACHE_64BIT_BAR_LOW
,
648 adev
->firmware
.ucode
[AMDGPU_UCODE_ID_UVD
].tmr_mc_addr_lo
:
649 adev
->firmware
.ucode
[AMDGPU_UCODE_ID_UVD1
].tmr_mc_addr_lo
);
650 WREG32_SOC15(UVD
, i
, mmUVD_LMI_VCPU_CACHE_64BIT_BAR_HIGH
,
652 adev
->firmware
.ucode
[AMDGPU_UCODE_ID_UVD
].tmr_mc_addr_hi
:
653 adev
->firmware
.ucode
[AMDGPU_UCODE_ID_UVD1
].tmr_mc_addr_hi
);
654 WREG32_SOC15(UVD
, i
, mmUVD_VCPU_CACHE_OFFSET0
, 0);
657 WREG32_SOC15(UVD
, i
, mmUVD_LMI_VCPU_CACHE_64BIT_BAR_LOW
,
658 lower_32_bits(adev
->uvd
.inst
[i
].gpu_addr
));
659 WREG32_SOC15(UVD
, i
, mmUVD_LMI_VCPU_CACHE_64BIT_BAR_HIGH
,
660 upper_32_bits(adev
->uvd
.inst
[i
].gpu_addr
));
662 WREG32_SOC15(UVD
, i
, mmUVD_VCPU_CACHE_OFFSET0
,
663 AMDGPU_UVD_FIRMWARE_OFFSET
>> 3);
666 WREG32_SOC15(UVD
, i
, mmUVD_VCPU_CACHE_SIZE0
, size
);
668 WREG32_SOC15(UVD
, i
, mmUVD_LMI_VCPU_CACHE1_64BIT_BAR_LOW
,
669 lower_32_bits(adev
->uvd
.inst
[i
].gpu_addr
+ offset
));
670 WREG32_SOC15(UVD
, i
, mmUVD_LMI_VCPU_CACHE1_64BIT_BAR_HIGH
,
671 upper_32_bits(adev
->uvd
.inst
[i
].gpu_addr
+ offset
));
672 WREG32_SOC15(UVD
, i
, mmUVD_VCPU_CACHE_OFFSET1
, (1 << 21));
673 WREG32_SOC15(UVD
, i
, mmUVD_VCPU_CACHE_SIZE1
, AMDGPU_UVD_HEAP_SIZE
);
675 WREG32_SOC15(UVD
, i
, mmUVD_LMI_VCPU_CACHE2_64BIT_BAR_LOW
,
676 lower_32_bits(adev
->uvd
.inst
[i
].gpu_addr
+ offset
+ AMDGPU_UVD_HEAP_SIZE
));
677 WREG32_SOC15(UVD
, i
, mmUVD_LMI_VCPU_CACHE2_64BIT_BAR_HIGH
,
678 upper_32_bits(adev
->uvd
.inst
[i
].gpu_addr
+ offset
+ AMDGPU_UVD_HEAP_SIZE
));
679 WREG32_SOC15(UVD
, i
, mmUVD_VCPU_CACHE_OFFSET2
, (2 << 21));
680 WREG32_SOC15(UVD
, i
, mmUVD_VCPU_CACHE_SIZE2
,
681 AMDGPU_UVD_STACK_SIZE
+ (AMDGPU_UVD_SESSION_SIZE
* 40));
683 WREG32_SOC15(UVD
, i
, mmUVD_UDEC_ADDR_CONFIG
,
684 adev
->gfx
.config
.gb_addr_config
);
685 WREG32_SOC15(UVD
, i
, mmUVD_UDEC_DB_ADDR_CONFIG
,
686 adev
->gfx
.config
.gb_addr_config
);
687 WREG32_SOC15(UVD
, i
, mmUVD_UDEC_DBW_ADDR_CONFIG
,
688 adev
->gfx
.config
.gb_addr_config
);
690 WREG32_SOC15(UVD
, i
, mmUVD_GP_SCRATCH4
, adev
->uvd
.max_handles
);
694 static int uvd_v7_0_mmsch_start(struct amdgpu_device
*adev
,
695 struct amdgpu_mm_table
*table
)
697 uint32_t data
= 0, loop
;
698 uint64_t addr
= table
->gpu_addr
;
699 struct mmsch_v1_0_init_header
*header
= (struct mmsch_v1_0_init_header
*)table
->cpu_addr
;
703 size
= header
->header_size
+ header
->vce_table_size
+ header
->uvd_table_size
;
705 /* 1, write to vce_mmsch_vf_ctx_addr_lo/hi register with GPU mc addr of memory descriptor location */
706 WREG32_SOC15(VCE
, 0, mmVCE_MMSCH_VF_CTX_ADDR_LO
, lower_32_bits(addr
));
707 WREG32_SOC15(VCE
, 0, mmVCE_MMSCH_VF_CTX_ADDR_HI
, upper_32_bits(addr
));
709 /* 2, update vmid of descriptor */
710 data
= RREG32_SOC15(VCE
, 0, mmVCE_MMSCH_VF_VMID
);
711 data
&= ~VCE_MMSCH_VF_VMID__VF_CTX_VMID_MASK
;
712 data
|= (0 << VCE_MMSCH_VF_VMID__VF_CTX_VMID__SHIFT
); /* use domain0 for MM scheduler */
713 WREG32_SOC15(VCE
, 0, mmVCE_MMSCH_VF_VMID
, data
);
715 /* 3, notify mmsch about the size of this descriptor */
716 WREG32_SOC15(VCE
, 0, mmVCE_MMSCH_VF_CTX_SIZE
, size
);
718 /* 4, set resp to zero */
719 WREG32_SOC15(VCE
, 0, mmVCE_MMSCH_VF_MAILBOX_RESP
, 0);
721 for (i
= 0; i
< adev
->uvd
.num_uvd_inst
; ++i
) {
722 if (adev
->uvd
.harvest_config
& (1 << i
))
724 WDOORBELL32(adev
->uvd
.inst
[i
].ring_enc
[0].doorbell_index
, 0);
725 adev
->wb
.wb
[adev
->uvd
.inst
[i
].ring_enc
[0].wptr_offs
] = 0;
726 adev
->uvd
.inst
[i
].ring_enc
[0].wptr
= 0;
727 adev
->uvd
.inst
[i
].ring_enc
[0].wptr_old
= 0;
729 /* 5, kick off the initialization and wait until VCE_MMSCH_VF_MAILBOX_RESP becomes non-zero */
730 WREG32_SOC15(VCE
, 0, mmVCE_MMSCH_VF_MAILBOX_HOST
, 0x10000001);
732 data
= RREG32_SOC15(VCE
, 0, mmVCE_MMSCH_VF_MAILBOX_RESP
);
734 while ((data
& 0x10000002) != 0x10000002) {
736 data
= RREG32_SOC15(VCE
, 0, mmVCE_MMSCH_VF_MAILBOX_RESP
);
743 dev_err(adev
->dev
, "failed to init MMSCH, mmVCE_MMSCH_VF_MAILBOX_RESP = %x\n", data
);
750 static int uvd_v7_0_sriov_start(struct amdgpu_device
*adev
)
752 struct amdgpu_ring
*ring
;
753 uint32_t offset
, size
, tmp
;
754 uint32_t table_size
= 0;
755 struct mmsch_v1_0_cmd_direct_write direct_wt
= { {0} };
756 struct mmsch_v1_0_cmd_direct_read_modify_write direct_rd_mod_wt
= { {0} };
757 struct mmsch_v1_0_cmd_direct_polling direct_poll
= { {0} };
758 struct mmsch_v1_0_cmd_end end
= { {0} };
759 uint32_t *init_table
= adev
->virt
.mm_table
.cpu_addr
;
760 struct mmsch_v1_0_init_header
*header
= (struct mmsch_v1_0_init_header
*)init_table
;
763 direct_wt
.cmd_header
.command_type
= MMSCH_COMMAND__DIRECT_REG_WRITE
;
764 direct_rd_mod_wt
.cmd_header
.command_type
= MMSCH_COMMAND__DIRECT_REG_READ_MODIFY_WRITE
;
765 direct_poll
.cmd_header
.command_type
= MMSCH_COMMAND__DIRECT_REG_POLLING
;
766 end
.cmd_header
.command_type
= MMSCH_COMMAND__END
;
768 if (header
->uvd_table_offset
== 0 && header
->uvd_table_size
== 0) {
769 header
->version
= MMSCH_VERSION
;
770 header
->header_size
= sizeof(struct mmsch_v1_0_init_header
) >> 2;
772 if (header
->vce_table_offset
== 0 && header
->vce_table_size
== 0)
773 header
->uvd_table_offset
= header
->header_size
;
775 header
->uvd_table_offset
= header
->vce_table_size
+ header
->vce_table_offset
;
777 init_table
+= header
->uvd_table_offset
;
779 for (i
= 0; i
< adev
->uvd
.num_uvd_inst
; ++i
) {
780 if (adev
->uvd
.harvest_config
& (1 << i
))
782 ring
= &adev
->uvd
.inst
[i
].ring
;
784 size
= AMDGPU_GPU_PAGE_ALIGN(adev
->uvd
.fw
->size
+ 4);
786 MMSCH_V1_0_INSERT_DIRECT_RD_MOD_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_STATUS
),
787 0xFFFFFFFF, 0x00000004);
789 if (adev
->firmware
.load_type
== AMDGPU_FW_LOAD_PSP
) {
790 MMSCH_V1_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_LMI_VCPU_CACHE_64BIT_BAR_LOW
),
791 lower_32_bits(adev
->firmware
.ucode
[AMDGPU_UCODE_ID_UVD
].mc_addr
));
792 MMSCH_V1_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_LMI_VCPU_CACHE_64BIT_BAR_HIGH
),
793 upper_32_bits(adev
->firmware
.ucode
[AMDGPU_UCODE_ID_UVD
].mc_addr
));
796 MMSCH_V1_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_LMI_VCPU_CACHE_64BIT_BAR_LOW
),
797 lower_32_bits(adev
->uvd
.inst
[i
].gpu_addr
));
798 MMSCH_V1_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_LMI_VCPU_CACHE_64BIT_BAR_HIGH
),
799 upper_32_bits(adev
->uvd
.inst
[i
].gpu_addr
));
803 MMSCH_V1_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_VCPU_CACHE_OFFSET0
),
804 AMDGPU_UVD_FIRMWARE_OFFSET
>> 3);
805 MMSCH_V1_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_VCPU_CACHE_SIZE0
), size
);
807 MMSCH_V1_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_LMI_VCPU_CACHE1_64BIT_BAR_LOW
),
808 lower_32_bits(adev
->uvd
.inst
[i
].gpu_addr
+ offset
));
809 MMSCH_V1_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_LMI_VCPU_CACHE1_64BIT_BAR_HIGH
),
810 upper_32_bits(adev
->uvd
.inst
[i
].gpu_addr
+ offset
));
811 MMSCH_V1_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_VCPU_CACHE_OFFSET1
), (1 << 21));
812 MMSCH_V1_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_VCPU_CACHE_SIZE1
), AMDGPU_UVD_HEAP_SIZE
);
814 MMSCH_V1_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_LMI_VCPU_CACHE2_64BIT_BAR_LOW
),
815 lower_32_bits(adev
->uvd
.inst
[i
].gpu_addr
+ offset
+ AMDGPU_UVD_HEAP_SIZE
));
816 MMSCH_V1_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_LMI_VCPU_CACHE2_64BIT_BAR_HIGH
),
817 upper_32_bits(adev
->uvd
.inst
[i
].gpu_addr
+ offset
+ AMDGPU_UVD_HEAP_SIZE
));
818 MMSCH_V1_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_VCPU_CACHE_OFFSET2
), (2 << 21));
819 MMSCH_V1_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_VCPU_CACHE_SIZE2
),
820 AMDGPU_UVD_STACK_SIZE
+ (AMDGPU_UVD_SESSION_SIZE
* 40));
822 MMSCH_V1_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_GP_SCRATCH4
), adev
->uvd
.max_handles
);
825 /* disable clock gating */
826 MMSCH_V1_0_INSERT_DIRECT_RD_MOD_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_CGC_CTRL
),
827 ~UVD_CGC_CTRL__DYN_CLOCK_MODE_MASK
, 0);
829 /* disable interupt */
830 MMSCH_V1_0_INSERT_DIRECT_RD_MOD_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_MASTINT_EN
),
831 ~UVD_MASTINT_EN__VCPU_EN_MASK
, 0);
833 /* stall UMC and register bus before resetting VCPU */
834 MMSCH_V1_0_INSERT_DIRECT_RD_MOD_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_LMI_CTRL2
),
835 ~UVD_LMI_CTRL2__STALL_ARB_UMC_MASK
,
836 UVD_LMI_CTRL2__STALL_ARB_UMC_MASK
);
838 /* put LMI, VCPU, RBC etc... into reset */
839 MMSCH_V1_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_SOFT_RESET
),
840 (uint32_t)(UVD_SOFT_RESET__LMI_SOFT_RESET_MASK
|
841 UVD_SOFT_RESET__VCPU_SOFT_RESET_MASK
|
842 UVD_SOFT_RESET__LBSI_SOFT_RESET_MASK
|
843 UVD_SOFT_RESET__RBC_SOFT_RESET_MASK
|
844 UVD_SOFT_RESET__CSM_SOFT_RESET_MASK
|
845 UVD_SOFT_RESET__CXW_SOFT_RESET_MASK
|
846 UVD_SOFT_RESET__TAP_SOFT_RESET_MASK
|
847 UVD_SOFT_RESET__LMI_UMC_SOFT_RESET_MASK
));
849 /* initialize UVD memory controller */
850 MMSCH_V1_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_LMI_CTRL
),
851 (uint32_t)((0x40 << UVD_LMI_CTRL__WRITE_CLEAN_TIMER__SHIFT
) |
852 UVD_LMI_CTRL__WRITE_CLEAN_TIMER_EN_MASK
|
853 UVD_LMI_CTRL__DATA_COHERENCY_EN_MASK
|
854 UVD_LMI_CTRL__VCPU_DATA_COHERENCY_EN_MASK
|
855 UVD_LMI_CTRL__REQ_MODE_MASK
|
858 /* take all subblocks out of reset, except VCPU */
859 MMSCH_V1_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_SOFT_RESET
),
860 UVD_SOFT_RESET__VCPU_SOFT_RESET_MASK
);
862 /* enable VCPU clock */
863 MMSCH_V1_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_VCPU_CNTL
),
864 UVD_VCPU_CNTL__CLK_EN_MASK
);
866 /* enable master interrupt */
867 MMSCH_V1_0_INSERT_DIRECT_RD_MOD_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_MASTINT_EN
),
868 ~(UVD_MASTINT_EN__VCPU_EN_MASK
|UVD_MASTINT_EN__SYS_EN_MASK
),
869 (UVD_MASTINT_EN__VCPU_EN_MASK
|UVD_MASTINT_EN__SYS_EN_MASK
));
871 /* clear the bit 4 of UVD_STATUS */
872 MMSCH_V1_0_INSERT_DIRECT_RD_MOD_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_STATUS
),
873 ~(2 << UVD_STATUS__VCPU_REPORT__SHIFT
), 0);
875 /* force RBC into idle state */
876 size
= order_base_2(ring
->ring_size
);
877 tmp
= REG_SET_FIELD(0, UVD_RBC_RB_CNTL
, RB_BUFSZ
, size
);
878 tmp
= REG_SET_FIELD(tmp
, UVD_RBC_RB_CNTL
, RB_NO_FETCH
, 1);
879 MMSCH_V1_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_RBC_RB_CNTL
), tmp
);
881 ring
= &adev
->uvd
.inst
[i
].ring_enc
[0];
883 MMSCH_V1_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_RB_BASE_LO
), ring
->gpu_addr
);
884 MMSCH_V1_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_RB_BASE_HI
), upper_32_bits(ring
->gpu_addr
));
885 MMSCH_V1_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_RB_SIZE
), ring
->ring_size
/ 4);
887 /* boot up the VCPU */
888 MMSCH_V1_0_INSERT_DIRECT_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_SOFT_RESET
), 0);
891 MMSCH_V1_0_INSERT_DIRECT_RD_MOD_WT(SOC15_REG_OFFSET(UVD
, i
, mmUVD_LMI_CTRL2
),
892 ~UVD_LMI_CTRL2__STALL_ARB_UMC_MASK
, 0);
894 MMSCH_V1_0_INSERT_DIRECT_POLL(SOC15_REG_OFFSET(UVD
, i
, mmUVD_STATUS
), 0x02, 0x02);
897 memcpy((void *)init_table
, &end
, sizeof(struct mmsch_v1_0_cmd_end
));
898 table_size
+= sizeof(struct mmsch_v1_0_cmd_end
) / 4;
899 header
->uvd_table_size
= table_size
;
902 return uvd_v7_0_mmsch_start(adev
, &adev
->virt
.mm_table
);
906 * uvd_v7_0_start - start UVD block
908 * @adev: amdgpu_device pointer
910 * Setup and start the UVD block
912 static int uvd_v7_0_start(struct amdgpu_device
*adev
)
914 struct amdgpu_ring
*ring
;
915 uint32_t rb_bufsz
, tmp
;
916 uint32_t lmi_swap_cntl
;
917 uint32_t mp_swap_cntl
;
920 for (k
= 0; k
< adev
->uvd
.num_uvd_inst
; ++k
) {
921 if (adev
->uvd
.harvest_config
& (1 << k
))
924 WREG32_P(SOC15_REG_OFFSET(UVD
, k
, mmUVD_POWER_STATUS
), 0,
925 ~UVD_POWER_STATUS__UVD_PG_MODE_MASK
);
928 /* disable byte swapping */
932 uvd_v7_0_mc_resume(adev
);
934 for (k
= 0; k
< adev
->uvd
.num_uvd_inst
; ++k
) {
935 if (adev
->uvd
.harvest_config
& (1 << k
))
937 ring
= &adev
->uvd
.inst
[k
].ring
;
938 /* disable clock gating */
939 WREG32_P(SOC15_REG_OFFSET(UVD
, k
, mmUVD_CGC_CTRL
), 0,
940 ~UVD_CGC_CTRL__DYN_CLOCK_MODE_MASK
);
942 /* disable interupt */
943 WREG32_P(SOC15_REG_OFFSET(UVD
, k
, mmUVD_MASTINT_EN
), 0,
944 ~UVD_MASTINT_EN__VCPU_EN_MASK
);
946 /* stall UMC and register bus before resetting VCPU */
947 WREG32_P(SOC15_REG_OFFSET(UVD
, k
, mmUVD_LMI_CTRL2
),
948 UVD_LMI_CTRL2__STALL_ARB_UMC_MASK
,
949 ~UVD_LMI_CTRL2__STALL_ARB_UMC_MASK
);
952 /* put LMI, VCPU, RBC etc... into reset */
953 WREG32_SOC15(UVD
, k
, mmUVD_SOFT_RESET
,
954 UVD_SOFT_RESET__LMI_SOFT_RESET_MASK
|
955 UVD_SOFT_RESET__VCPU_SOFT_RESET_MASK
|
956 UVD_SOFT_RESET__LBSI_SOFT_RESET_MASK
|
957 UVD_SOFT_RESET__RBC_SOFT_RESET_MASK
|
958 UVD_SOFT_RESET__CSM_SOFT_RESET_MASK
|
959 UVD_SOFT_RESET__CXW_SOFT_RESET_MASK
|
960 UVD_SOFT_RESET__TAP_SOFT_RESET_MASK
|
961 UVD_SOFT_RESET__LMI_UMC_SOFT_RESET_MASK
);
964 /* initialize UVD memory controller */
965 WREG32_SOC15(UVD
, k
, mmUVD_LMI_CTRL
,
966 (0x40 << UVD_LMI_CTRL__WRITE_CLEAN_TIMER__SHIFT
) |
967 UVD_LMI_CTRL__WRITE_CLEAN_TIMER_EN_MASK
|
968 UVD_LMI_CTRL__DATA_COHERENCY_EN_MASK
|
969 UVD_LMI_CTRL__VCPU_DATA_COHERENCY_EN_MASK
|
970 UVD_LMI_CTRL__REQ_MODE_MASK
|
974 /* swap (8 in 32) RB and IB */
978 WREG32_SOC15(UVD
, k
, mmUVD_LMI_SWAP_CNTL
, lmi_swap_cntl
);
979 WREG32_SOC15(UVD
, k
, mmUVD_MP_SWAP_CNTL
, mp_swap_cntl
);
981 WREG32_SOC15(UVD
, k
, mmUVD_MPC_SET_MUXA0
, 0x40c2040);
982 WREG32_SOC15(UVD
, k
, mmUVD_MPC_SET_MUXA1
, 0x0);
983 WREG32_SOC15(UVD
, k
, mmUVD_MPC_SET_MUXB0
, 0x40c2040);
984 WREG32_SOC15(UVD
, k
, mmUVD_MPC_SET_MUXB1
, 0x0);
985 WREG32_SOC15(UVD
, k
, mmUVD_MPC_SET_ALU
, 0);
986 WREG32_SOC15(UVD
, k
, mmUVD_MPC_SET_MUX
, 0x88);
988 /* take all subblocks out of reset, except VCPU */
989 WREG32_SOC15(UVD
, k
, mmUVD_SOFT_RESET
,
990 UVD_SOFT_RESET__VCPU_SOFT_RESET_MASK
);
993 /* enable VCPU clock */
994 WREG32_SOC15(UVD
, k
, mmUVD_VCPU_CNTL
,
995 UVD_VCPU_CNTL__CLK_EN_MASK
);
998 WREG32_P(SOC15_REG_OFFSET(UVD
, k
, mmUVD_LMI_CTRL2
), 0,
999 ~UVD_LMI_CTRL2__STALL_ARB_UMC_MASK
);
1001 /* boot up the VCPU */
1002 WREG32_SOC15(UVD
, k
, mmUVD_SOFT_RESET
, 0);
1005 for (i
= 0; i
< 10; ++i
) {
1008 for (j
= 0; j
< 100; ++j
) {
1009 status
= RREG32_SOC15(UVD
, k
, mmUVD_STATUS
);
1018 DRM_ERROR("UVD(%d) not responding, trying to reset the VCPU!!!\n", k
);
1019 WREG32_P(SOC15_REG_OFFSET(UVD
, k
, mmUVD_SOFT_RESET
),
1020 UVD_SOFT_RESET__VCPU_SOFT_RESET_MASK
,
1021 ~UVD_SOFT_RESET__VCPU_SOFT_RESET_MASK
);
1023 WREG32_P(SOC15_REG_OFFSET(UVD
, k
, mmUVD_SOFT_RESET
), 0,
1024 ~UVD_SOFT_RESET__VCPU_SOFT_RESET_MASK
);
1030 DRM_ERROR("UVD(%d) not responding, giving up!!!\n", k
);
1033 /* enable master interrupt */
1034 WREG32_P(SOC15_REG_OFFSET(UVD
, k
, mmUVD_MASTINT_EN
),
1035 (UVD_MASTINT_EN__VCPU_EN_MASK
|UVD_MASTINT_EN__SYS_EN_MASK
),
1036 ~(UVD_MASTINT_EN__VCPU_EN_MASK
|UVD_MASTINT_EN__SYS_EN_MASK
));
1038 /* clear the bit 4 of UVD_STATUS */
1039 WREG32_P(SOC15_REG_OFFSET(UVD
, k
, mmUVD_STATUS
), 0,
1040 ~(2 << UVD_STATUS__VCPU_REPORT__SHIFT
));
1042 /* force RBC into idle state */
1043 rb_bufsz
= order_base_2(ring
->ring_size
);
1044 tmp
= REG_SET_FIELD(0, UVD_RBC_RB_CNTL
, RB_BUFSZ
, rb_bufsz
);
1045 tmp
= REG_SET_FIELD(tmp
, UVD_RBC_RB_CNTL
, RB_BLKSZ
, 1);
1046 tmp
= REG_SET_FIELD(tmp
, UVD_RBC_RB_CNTL
, RB_NO_FETCH
, 1);
1047 tmp
= REG_SET_FIELD(tmp
, UVD_RBC_RB_CNTL
, RB_WPTR_POLL_EN
, 0);
1048 tmp
= REG_SET_FIELD(tmp
, UVD_RBC_RB_CNTL
, RB_NO_UPDATE
, 1);
1049 tmp
= REG_SET_FIELD(tmp
, UVD_RBC_RB_CNTL
, RB_RPTR_WR_EN
, 1);
1050 WREG32_SOC15(UVD
, k
, mmUVD_RBC_RB_CNTL
, tmp
);
1052 /* set the write pointer delay */
1053 WREG32_SOC15(UVD
, k
, mmUVD_RBC_RB_WPTR_CNTL
, 0);
1055 /* set the wb address */
1056 WREG32_SOC15(UVD
, k
, mmUVD_RBC_RB_RPTR_ADDR
,
1057 (upper_32_bits(ring
->gpu_addr
) >> 2));
1059 /* programm the RB_BASE for ring buffer */
1060 WREG32_SOC15(UVD
, k
, mmUVD_LMI_RBC_RB_64BIT_BAR_LOW
,
1061 lower_32_bits(ring
->gpu_addr
));
1062 WREG32_SOC15(UVD
, k
, mmUVD_LMI_RBC_RB_64BIT_BAR_HIGH
,
1063 upper_32_bits(ring
->gpu_addr
));
1065 /* Initialize the ring buffer's read and write pointers */
1066 WREG32_SOC15(UVD
, k
, mmUVD_RBC_RB_RPTR
, 0);
1068 ring
->wptr
= RREG32_SOC15(UVD
, k
, mmUVD_RBC_RB_RPTR
);
1069 WREG32_SOC15(UVD
, k
, mmUVD_RBC_RB_WPTR
,
1070 lower_32_bits(ring
->wptr
));
1072 WREG32_P(SOC15_REG_OFFSET(UVD
, k
, mmUVD_RBC_RB_CNTL
), 0,
1073 ~UVD_RBC_RB_CNTL__RB_NO_FETCH_MASK
);
1075 ring
= &adev
->uvd
.inst
[k
].ring_enc
[0];
1076 WREG32_SOC15(UVD
, k
, mmUVD_RB_RPTR
, lower_32_bits(ring
->wptr
));
1077 WREG32_SOC15(UVD
, k
, mmUVD_RB_WPTR
, lower_32_bits(ring
->wptr
));
1078 WREG32_SOC15(UVD
, k
, mmUVD_RB_BASE_LO
, ring
->gpu_addr
);
1079 WREG32_SOC15(UVD
, k
, mmUVD_RB_BASE_HI
, upper_32_bits(ring
->gpu_addr
));
1080 WREG32_SOC15(UVD
, k
, mmUVD_RB_SIZE
, ring
->ring_size
/ 4);
1082 ring
= &adev
->uvd
.inst
[k
].ring_enc
[1];
1083 WREG32_SOC15(UVD
, k
, mmUVD_RB_RPTR2
, lower_32_bits(ring
->wptr
));
1084 WREG32_SOC15(UVD
, k
, mmUVD_RB_WPTR2
, lower_32_bits(ring
->wptr
));
1085 WREG32_SOC15(UVD
, k
, mmUVD_RB_BASE_LO2
, ring
->gpu_addr
);
1086 WREG32_SOC15(UVD
, k
, mmUVD_RB_BASE_HI2
, upper_32_bits(ring
->gpu_addr
));
1087 WREG32_SOC15(UVD
, k
, mmUVD_RB_SIZE2
, ring
->ring_size
/ 4);
1093 * uvd_v7_0_stop - stop UVD block
1095 * @adev: amdgpu_device pointer
1097 * stop the UVD block
1099 static void uvd_v7_0_stop(struct amdgpu_device
*adev
)
1103 for (i
= 0; i
< adev
->uvd
.num_uvd_inst
; ++i
) {
1104 if (adev
->uvd
.harvest_config
& (1 << i
))
1106 /* force RBC into idle state */
1107 WREG32_SOC15(UVD
, i
, mmUVD_RBC_RB_CNTL
, 0x11010101);
1109 /* Stall UMC and register bus before resetting VCPU */
1110 WREG32_P(SOC15_REG_OFFSET(UVD
, i
, mmUVD_LMI_CTRL2
),
1111 UVD_LMI_CTRL2__STALL_ARB_UMC_MASK
,
1112 ~UVD_LMI_CTRL2__STALL_ARB_UMC_MASK
);
1115 /* put VCPU into reset */
1116 WREG32_SOC15(UVD
, i
, mmUVD_SOFT_RESET
,
1117 UVD_SOFT_RESET__VCPU_SOFT_RESET_MASK
);
1120 /* disable VCPU clock */
1121 WREG32_SOC15(UVD
, i
, mmUVD_VCPU_CNTL
, 0x0);
1123 /* Unstall UMC and register bus */
1124 WREG32_P(SOC15_REG_OFFSET(UVD
, i
, mmUVD_LMI_CTRL2
), 0,
1125 ~UVD_LMI_CTRL2__STALL_ARB_UMC_MASK
);
1130 * uvd_v7_0_ring_emit_fence - emit an fence & trap command
1132 * @ring: amdgpu_ring pointer
1133 * @fence: fence to emit
1135 * Write a fence and a trap command to the ring.
1137 static void uvd_v7_0_ring_emit_fence(struct amdgpu_ring
*ring
, u64 addr
, u64 seq
,
1140 struct amdgpu_device
*adev
= ring
->adev
;
1142 WARN_ON(flags
& AMDGPU_FENCE_FLAG_64BIT
);
1144 amdgpu_ring_write(ring
,
1145 PACKET0(SOC15_REG_OFFSET(UVD
, ring
->me
, mmUVD_CONTEXT_ID
), 0));
1146 amdgpu_ring_write(ring
, seq
);
1147 amdgpu_ring_write(ring
,
1148 PACKET0(SOC15_REG_OFFSET(UVD
, ring
->me
, mmUVD_GPCOM_VCPU_DATA0
), 0));
1149 amdgpu_ring_write(ring
, addr
& 0xffffffff);
1150 amdgpu_ring_write(ring
,
1151 PACKET0(SOC15_REG_OFFSET(UVD
, ring
->me
, mmUVD_GPCOM_VCPU_DATA1
), 0));
1152 amdgpu_ring_write(ring
, upper_32_bits(addr
) & 0xff);
1153 amdgpu_ring_write(ring
,
1154 PACKET0(SOC15_REG_OFFSET(UVD
, ring
->me
, mmUVD_GPCOM_VCPU_CMD
), 0));
1155 amdgpu_ring_write(ring
, 0);
1157 amdgpu_ring_write(ring
,
1158 PACKET0(SOC15_REG_OFFSET(UVD
, ring
->me
, mmUVD_GPCOM_VCPU_DATA0
), 0));
1159 amdgpu_ring_write(ring
, 0);
1160 amdgpu_ring_write(ring
,
1161 PACKET0(SOC15_REG_OFFSET(UVD
, ring
->me
, mmUVD_GPCOM_VCPU_DATA1
), 0));
1162 amdgpu_ring_write(ring
, 0);
1163 amdgpu_ring_write(ring
,
1164 PACKET0(SOC15_REG_OFFSET(UVD
, ring
->me
, mmUVD_GPCOM_VCPU_CMD
), 0));
1165 amdgpu_ring_write(ring
, 2);
1169 * uvd_v7_0_enc_ring_emit_fence - emit an enc fence & trap command
1171 * @ring: amdgpu_ring pointer
1172 * @fence: fence to emit
1174 * Write enc a fence and a trap command to the ring.
1176 static void uvd_v7_0_enc_ring_emit_fence(struct amdgpu_ring
*ring
, u64 addr
,
1177 u64 seq
, unsigned flags
)
1180 WARN_ON(flags
& AMDGPU_FENCE_FLAG_64BIT
);
1182 amdgpu_ring_write(ring
, HEVC_ENC_CMD_FENCE
);
1183 amdgpu_ring_write(ring
, addr
);
1184 amdgpu_ring_write(ring
, upper_32_bits(addr
));
1185 amdgpu_ring_write(ring
, seq
);
1186 amdgpu_ring_write(ring
, HEVC_ENC_CMD_TRAP
);
1190 * uvd_v7_0_ring_emit_hdp_flush - skip HDP flushing
1192 * @ring: amdgpu_ring pointer
1194 static void uvd_v7_0_ring_emit_hdp_flush(struct amdgpu_ring
*ring
)
1196 /* The firmware doesn't seem to like touching registers at this point. */
1200 * uvd_v7_0_ring_test_ring - register write test
1202 * @ring: amdgpu_ring pointer
1204 * Test if we can successfully write to the context register
1206 static int uvd_v7_0_ring_test_ring(struct amdgpu_ring
*ring
)
1208 struct amdgpu_device
*adev
= ring
->adev
;
1213 WREG32_SOC15(UVD
, ring
->me
, mmUVD_CONTEXT_ID
, 0xCAFEDEAD);
1214 r
= amdgpu_ring_alloc(ring
, 3);
1218 amdgpu_ring_write(ring
,
1219 PACKET0(SOC15_REG_OFFSET(UVD
, ring
->me
, mmUVD_CONTEXT_ID
), 0));
1220 amdgpu_ring_write(ring
, 0xDEADBEEF);
1221 amdgpu_ring_commit(ring
);
1222 for (i
= 0; i
< adev
->usec_timeout
; i
++) {
1223 tmp
= RREG32_SOC15(UVD
, ring
->me
, mmUVD_CONTEXT_ID
);
1224 if (tmp
== 0xDEADBEEF)
1229 if (i
>= adev
->usec_timeout
)
1236 * uvd_v7_0_ring_patch_cs_in_place - Patch the IB for command submission.
1238 * @p: the CS parser with the IBs
1239 * @ib_idx: which IB to patch
1242 static int uvd_v7_0_ring_patch_cs_in_place(struct amdgpu_cs_parser
*p
,
1245 struct amdgpu_ring
*ring
= to_amdgpu_ring(p
->entity
->rq
->sched
);
1246 struct amdgpu_ib
*ib
= &p
->job
->ibs
[ib_idx
];
1249 /* No patching necessary for the first instance */
1253 for (i
= 0; i
< ib
->length_dw
; i
+= 2) {
1254 uint32_t reg
= amdgpu_get_ib_value(p
, ib_idx
, i
);
1256 reg
-= p
->adev
->reg_offset
[UVD_HWIP
][0][1];
1257 reg
+= p
->adev
->reg_offset
[UVD_HWIP
][1][1];
1259 amdgpu_set_ib_value(p
, ib_idx
, i
, reg
);
1265 * uvd_v7_0_ring_emit_ib - execute indirect buffer
1267 * @ring: amdgpu_ring pointer
1268 * @ib: indirect buffer to execute
1270 * Write ring commands to execute the indirect buffer
1272 static void uvd_v7_0_ring_emit_ib(struct amdgpu_ring
*ring
,
1273 struct amdgpu_job
*job
,
1274 struct amdgpu_ib
*ib
,
1277 struct amdgpu_device
*adev
= ring
->adev
;
1278 unsigned vmid
= AMDGPU_JOB_GET_VMID(job
);
1280 amdgpu_ring_write(ring
,
1281 PACKET0(SOC15_REG_OFFSET(UVD
, ring
->me
, mmUVD_LMI_RBC_IB_VMID
), 0));
1282 amdgpu_ring_write(ring
, vmid
);
1284 amdgpu_ring_write(ring
,
1285 PACKET0(SOC15_REG_OFFSET(UVD
, ring
->me
, mmUVD_LMI_RBC_IB_64BIT_BAR_LOW
), 0));
1286 amdgpu_ring_write(ring
, lower_32_bits(ib
->gpu_addr
));
1287 amdgpu_ring_write(ring
,
1288 PACKET0(SOC15_REG_OFFSET(UVD
, ring
->me
, mmUVD_LMI_RBC_IB_64BIT_BAR_HIGH
), 0));
1289 amdgpu_ring_write(ring
, upper_32_bits(ib
->gpu_addr
));
1290 amdgpu_ring_write(ring
,
1291 PACKET0(SOC15_REG_OFFSET(UVD
, ring
->me
, mmUVD_RBC_IB_SIZE
), 0));
1292 amdgpu_ring_write(ring
, ib
->length_dw
);
1296 * uvd_v7_0_enc_ring_emit_ib - enc execute indirect buffer
1298 * @ring: amdgpu_ring pointer
1299 * @ib: indirect buffer to execute
1301 * Write enc ring commands to execute the indirect buffer
1303 static void uvd_v7_0_enc_ring_emit_ib(struct amdgpu_ring
*ring
,
1304 struct amdgpu_job
*job
,
1305 struct amdgpu_ib
*ib
,
1308 unsigned vmid
= AMDGPU_JOB_GET_VMID(job
);
1310 amdgpu_ring_write(ring
, HEVC_ENC_CMD_IB_VM
);
1311 amdgpu_ring_write(ring
, vmid
);
1312 amdgpu_ring_write(ring
, lower_32_bits(ib
->gpu_addr
));
1313 amdgpu_ring_write(ring
, upper_32_bits(ib
->gpu_addr
));
1314 amdgpu_ring_write(ring
, ib
->length_dw
);
1317 static void uvd_v7_0_ring_emit_wreg(struct amdgpu_ring
*ring
,
1318 uint32_t reg
, uint32_t val
)
1320 struct amdgpu_device
*adev
= ring
->adev
;
1322 amdgpu_ring_write(ring
,
1323 PACKET0(SOC15_REG_OFFSET(UVD
, ring
->me
, mmUVD_GPCOM_VCPU_DATA0
), 0));
1324 amdgpu_ring_write(ring
, reg
<< 2);
1325 amdgpu_ring_write(ring
,
1326 PACKET0(SOC15_REG_OFFSET(UVD
, ring
->me
, mmUVD_GPCOM_VCPU_DATA1
), 0));
1327 amdgpu_ring_write(ring
, val
);
1328 amdgpu_ring_write(ring
,
1329 PACKET0(SOC15_REG_OFFSET(UVD
, ring
->me
, mmUVD_GPCOM_VCPU_CMD
), 0));
1330 amdgpu_ring_write(ring
, 8);
1333 static void uvd_v7_0_ring_emit_reg_wait(struct amdgpu_ring
*ring
, uint32_t reg
,
1334 uint32_t val
, uint32_t mask
)
1336 struct amdgpu_device
*adev
= ring
->adev
;
1338 amdgpu_ring_write(ring
,
1339 PACKET0(SOC15_REG_OFFSET(UVD
, ring
->me
, mmUVD_GPCOM_VCPU_DATA0
), 0));
1340 amdgpu_ring_write(ring
, reg
<< 2);
1341 amdgpu_ring_write(ring
,
1342 PACKET0(SOC15_REG_OFFSET(UVD
, ring
->me
, mmUVD_GPCOM_VCPU_DATA1
), 0));
1343 amdgpu_ring_write(ring
, val
);
1344 amdgpu_ring_write(ring
,
1345 PACKET0(SOC15_REG_OFFSET(UVD
, ring
->me
, mmUVD_GP_SCRATCH8
), 0));
1346 amdgpu_ring_write(ring
, mask
);
1347 amdgpu_ring_write(ring
,
1348 PACKET0(SOC15_REG_OFFSET(UVD
, ring
->me
, mmUVD_GPCOM_VCPU_CMD
), 0));
1349 amdgpu_ring_write(ring
, 12);
1352 static void uvd_v7_0_ring_emit_vm_flush(struct amdgpu_ring
*ring
,
1353 unsigned vmid
, uint64_t pd_addr
)
1355 struct amdgpu_vmhub
*hub
= &ring
->adev
->vmhub
[ring
->funcs
->vmhub
];
1356 uint32_t data0
, data1
, mask
;
1358 pd_addr
= amdgpu_gmc_emit_flush_gpu_tlb(ring
, vmid
, pd_addr
);
1360 /* wait for reg writes */
1361 data0
= hub
->ctx0_ptb_addr_lo32
+ vmid
* 2;
1362 data1
= lower_32_bits(pd_addr
);
1364 uvd_v7_0_ring_emit_reg_wait(ring
, data0
, data1
, mask
);
1367 static void uvd_v7_0_ring_insert_nop(struct amdgpu_ring
*ring
, uint32_t count
)
1369 struct amdgpu_device
*adev
= ring
->adev
;
1372 WARN_ON(ring
->wptr
% 2 || count
% 2);
1374 for (i
= 0; i
< count
/ 2; i
++) {
1375 amdgpu_ring_write(ring
, PACKET0(SOC15_REG_OFFSET(UVD
, ring
->me
, mmUVD_NO_OP
), 0));
1376 amdgpu_ring_write(ring
, 0);
1380 static void uvd_v7_0_enc_ring_insert_end(struct amdgpu_ring
*ring
)
1382 amdgpu_ring_write(ring
, HEVC_ENC_CMD_END
);
1385 static void uvd_v7_0_enc_ring_emit_reg_wait(struct amdgpu_ring
*ring
,
1386 uint32_t reg
, uint32_t val
,
1389 amdgpu_ring_write(ring
, HEVC_ENC_CMD_REG_WAIT
);
1390 amdgpu_ring_write(ring
, reg
<< 2);
1391 amdgpu_ring_write(ring
, mask
);
1392 amdgpu_ring_write(ring
, val
);
1395 static void uvd_v7_0_enc_ring_emit_vm_flush(struct amdgpu_ring
*ring
,
1396 unsigned int vmid
, uint64_t pd_addr
)
1398 struct amdgpu_vmhub
*hub
= &ring
->adev
->vmhub
[ring
->funcs
->vmhub
];
1400 pd_addr
= amdgpu_gmc_emit_flush_gpu_tlb(ring
, vmid
, pd_addr
);
1402 /* wait for reg writes */
1403 uvd_v7_0_enc_ring_emit_reg_wait(ring
, hub
->ctx0_ptb_addr_lo32
+ vmid
* 2,
1404 lower_32_bits(pd_addr
), 0xffffffff);
1407 static void uvd_v7_0_enc_ring_emit_wreg(struct amdgpu_ring
*ring
,
1408 uint32_t reg
, uint32_t val
)
1410 amdgpu_ring_write(ring
, HEVC_ENC_CMD_REG_WRITE
);
1411 amdgpu_ring_write(ring
, reg
<< 2);
1412 amdgpu_ring_write(ring
, val
);
1416 static bool uvd_v7_0_is_idle(void *handle
)
1418 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
1420 return !(RREG32(mmSRBM_STATUS
) & SRBM_STATUS__UVD_BUSY_MASK
);
1423 static int uvd_v7_0_wait_for_idle(void *handle
)
1426 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
1428 for (i
= 0; i
< adev
->usec_timeout
; i
++) {
1429 if (uvd_v7_0_is_idle(handle
))
1435 #define AMDGPU_UVD_STATUS_BUSY_MASK 0xfd
1436 static bool uvd_v7_0_check_soft_reset(void *handle
)
1438 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
1439 u32 srbm_soft_reset
= 0;
1440 u32 tmp
= RREG32(mmSRBM_STATUS
);
1442 if (REG_GET_FIELD(tmp
, SRBM_STATUS
, UVD_RQ_PENDING
) ||
1443 REG_GET_FIELD(tmp
, SRBM_STATUS
, UVD_BUSY
) ||
1444 (RREG32_SOC15(UVD
, ring
->me
, mmUVD_STATUS
) &
1445 AMDGPU_UVD_STATUS_BUSY_MASK
))
1446 srbm_soft_reset
= REG_SET_FIELD(srbm_soft_reset
,
1447 SRBM_SOFT_RESET
, SOFT_RESET_UVD
, 1);
1449 if (srbm_soft_reset
) {
1450 adev
->uvd
.inst
[ring
->me
].srbm_soft_reset
= srbm_soft_reset
;
1453 adev
->uvd
.inst
[ring
->me
].srbm_soft_reset
= 0;
1458 static int uvd_v7_0_pre_soft_reset(void *handle
)
1460 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
1462 if (!adev
->uvd
.inst
[ring
->me
].srbm_soft_reset
)
1465 uvd_v7_0_stop(adev
);
1469 static int uvd_v7_0_soft_reset(void *handle
)
1471 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
1472 u32 srbm_soft_reset
;
1474 if (!adev
->uvd
.inst
[ring
->me
].srbm_soft_reset
)
1476 srbm_soft_reset
= adev
->uvd
.inst
[ring
->me
].srbm_soft_reset
;
1478 if (srbm_soft_reset
) {
1481 tmp
= RREG32(mmSRBM_SOFT_RESET
);
1482 tmp
|= srbm_soft_reset
;
1483 dev_info(adev
->dev
, "SRBM_SOFT_RESET=0x%08X\n", tmp
);
1484 WREG32(mmSRBM_SOFT_RESET
, tmp
);
1485 tmp
= RREG32(mmSRBM_SOFT_RESET
);
1489 tmp
&= ~srbm_soft_reset
;
1490 WREG32(mmSRBM_SOFT_RESET
, tmp
);
1491 tmp
= RREG32(mmSRBM_SOFT_RESET
);
1493 /* Wait a little for things to settle down */
1500 static int uvd_v7_0_post_soft_reset(void *handle
)
1502 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
1504 if (!adev
->uvd
.inst
[ring
->me
].srbm_soft_reset
)
1509 return uvd_v7_0_start(adev
);
1513 static int uvd_v7_0_set_interrupt_state(struct amdgpu_device
*adev
,
1514 struct amdgpu_irq_src
*source
,
1516 enum amdgpu_interrupt_state state
)
1522 static int uvd_v7_0_process_interrupt(struct amdgpu_device
*adev
,
1523 struct amdgpu_irq_src
*source
,
1524 struct amdgpu_iv_entry
*entry
)
1526 uint32_t ip_instance
;
1528 switch (entry
->client_id
) {
1529 case SOC15_IH_CLIENTID_UVD
:
1532 case SOC15_IH_CLIENTID_UVD1
:
1536 DRM_ERROR("Unhandled client id: %d\n", entry
->client_id
);
1540 DRM_DEBUG("IH: UVD TRAP\n");
1542 switch (entry
->src_id
) {
1544 amdgpu_fence_process(&adev
->uvd
.inst
[ip_instance
].ring
);
1547 amdgpu_fence_process(&adev
->uvd
.inst
[ip_instance
].ring_enc
[0]);
1550 if (!amdgpu_sriov_vf(adev
))
1551 amdgpu_fence_process(&adev
->uvd
.inst
[ip_instance
].ring_enc
[1]);
1554 DRM_ERROR("Unhandled interrupt: %d %d\n",
1555 entry
->src_id
, entry
->src_data
[0]);
1563 static void uvd_v7_0_set_sw_clock_gating(struct amdgpu_device
*adev
)
1565 uint32_t data
, data1
, data2
, suvd_flags
;
1567 data
= RREG32_SOC15(UVD
, ring
->me
, mmUVD_CGC_CTRL
);
1568 data1
= RREG32_SOC15(UVD
, ring
->me
, mmUVD_SUVD_CGC_GATE
);
1569 data2
= RREG32_SOC15(UVD
, ring
->me
, mmUVD_SUVD_CGC_CTRL
);
1571 data
&= ~(UVD_CGC_CTRL__CLK_OFF_DELAY_MASK
|
1572 UVD_CGC_CTRL__CLK_GATE_DLY_TIMER_MASK
);
1574 suvd_flags
= UVD_SUVD_CGC_GATE__SRE_MASK
|
1575 UVD_SUVD_CGC_GATE__SIT_MASK
|
1576 UVD_SUVD_CGC_GATE__SMP_MASK
|
1577 UVD_SUVD_CGC_GATE__SCM_MASK
|
1578 UVD_SUVD_CGC_GATE__SDB_MASK
;
1580 data
|= UVD_CGC_CTRL__DYN_CLOCK_MODE_MASK
|
1581 (1 << REG_FIELD_SHIFT(UVD_CGC_CTRL
, CLK_GATE_DLY_TIMER
)) |
1582 (4 << REG_FIELD_SHIFT(UVD_CGC_CTRL
, CLK_OFF_DELAY
));
1584 data
&= ~(UVD_CGC_CTRL__UDEC_RE_MODE_MASK
|
1585 UVD_CGC_CTRL__UDEC_CM_MODE_MASK
|
1586 UVD_CGC_CTRL__UDEC_IT_MODE_MASK
|
1587 UVD_CGC_CTRL__UDEC_DB_MODE_MASK
|
1588 UVD_CGC_CTRL__UDEC_MP_MODE_MASK
|
1589 UVD_CGC_CTRL__SYS_MODE_MASK
|
1590 UVD_CGC_CTRL__UDEC_MODE_MASK
|
1591 UVD_CGC_CTRL__MPEG2_MODE_MASK
|
1592 UVD_CGC_CTRL__REGS_MODE_MASK
|
1593 UVD_CGC_CTRL__RBC_MODE_MASK
|
1594 UVD_CGC_CTRL__LMI_MC_MODE_MASK
|
1595 UVD_CGC_CTRL__LMI_UMC_MODE_MASK
|
1596 UVD_CGC_CTRL__IDCT_MODE_MASK
|
1597 UVD_CGC_CTRL__MPRD_MODE_MASK
|
1598 UVD_CGC_CTRL__MPC_MODE_MASK
|
1599 UVD_CGC_CTRL__LBSI_MODE_MASK
|
1600 UVD_CGC_CTRL__LRBBM_MODE_MASK
|
1601 UVD_CGC_CTRL__WCB_MODE_MASK
|
1602 UVD_CGC_CTRL__VCPU_MODE_MASK
|
1603 UVD_CGC_CTRL__JPEG_MODE_MASK
|
1604 UVD_CGC_CTRL__JPEG2_MODE_MASK
|
1605 UVD_CGC_CTRL__SCPU_MODE_MASK
);
1606 data2
&= ~(UVD_SUVD_CGC_CTRL__SRE_MODE_MASK
|
1607 UVD_SUVD_CGC_CTRL__SIT_MODE_MASK
|
1608 UVD_SUVD_CGC_CTRL__SMP_MODE_MASK
|
1609 UVD_SUVD_CGC_CTRL__SCM_MODE_MASK
|
1610 UVD_SUVD_CGC_CTRL__SDB_MODE_MASK
);
1611 data1
|= suvd_flags
;
1613 WREG32_SOC15(UVD
, ring
->me
, mmUVD_CGC_CTRL
, data
);
1614 WREG32_SOC15(UVD
, ring
->me
, mmUVD_CGC_GATE
, 0);
1615 WREG32_SOC15(UVD
, ring
->me
, mmUVD_SUVD_CGC_GATE
, data1
);
1616 WREG32_SOC15(UVD
, ring
->me
, mmUVD_SUVD_CGC_CTRL
, data2
);
1619 static void uvd_v7_0_set_hw_clock_gating(struct amdgpu_device
*adev
)
1621 uint32_t data
, data1
, cgc_flags
, suvd_flags
;
1623 data
= RREG32_SOC15(UVD
, ring
->me
, mmUVD_CGC_GATE
);
1624 data1
= RREG32_SOC15(UVD
, ring
->me
, mmUVD_SUVD_CGC_GATE
);
1626 cgc_flags
= UVD_CGC_GATE__SYS_MASK
|
1627 UVD_CGC_GATE__UDEC_MASK
|
1628 UVD_CGC_GATE__MPEG2_MASK
|
1629 UVD_CGC_GATE__RBC_MASK
|
1630 UVD_CGC_GATE__LMI_MC_MASK
|
1631 UVD_CGC_GATE__IDCT_MASK
|
1632 UVD_CGC_GATE__MPRD_MASK
|
1633 UVD_CGC_GATE__MPC_MASK
|
1634 UVD_CGC_GATE__LBSI_MASK
|
1635 UVD_CGC_GATE__LRBBM_MASK
|
1636 UVD_CGC_GATE__UDEC_RE_MASK
|
1637 UVD_CGC_GATE__UDEC_CM_MASK
|
1638 UVD_CGC_GATE__UDEC_IT_MASK
|
1639 UVD_CGC_GATE__UDEC_DB_MASK
|
1640 UVD_CGC_GATE__UDEC_MP_MASK
|
1641 UVD_CGC_GATE__WCB_MASK
|
1642 UVD_CGC_GATE__VCPU_MASK
|
1643 UVD_CGC_GATE__SCPU_MASK
|
1644 UVD_CGC_GATE__JPEG_MASK
|
1645 UVD_CGC_GATE__JPEG2_MASK
;
1647 suvd_flags
= UVD_SUVD_CGC_GATE__SRE_MASK
|
1648 UVD_SUVD_CGC_GATE__SIT_MASK
|
1649 UVD_SUVD_CGC_GATE__SMP_MASK
|
1650 UVD_SUVD_CGC_GATE__SCM_MASK
|
1651 UVD_SUVD_CGC_GATE__SDB_MASK
;
1654 data1
|= suvd_flags
;
1656 WREG32_SOC15(UVD
, ring
->me
, mmUVD_CGC_GATE
, data
);
1657 WREG32_SOC15(UVD
, ring
->me
, mmUVD_SUVD_CGC_GATE
, data1
);
1660 static void uvd_v7_0_set_bypass_mode(struct amdgpu_device
*adev
, bool enable
)
1662 u32 tmp
= RREG32_SMC(ixGCK_DFS_BYPASS_CNTL
);
1665 tmp
|= (GCK_DFS_BYPASS_CNTL__BYPASSDCLK_MASK
|
1666 GCK_DFS_BYPASS_CNTL__BYPASSVCLK_MASK
);
1668 tmp
&= ~(GCK_DFS_BYPASS_CNTL__BYPASSDCLK_MASK
|
1669 GCK_DFS_BYPASS_CNTL__BYPASSVCLK_MASK
);
1671 WREG32_SMC(ixGCK_DFS_BYPASS_CNTL
, tmp
);
1675 static int uvd_v7_0_set_clockgating_state(void *handle
,
1676 enum amd_clockgating_state state
)
1678 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
1679 bool enable
= (state
== AMD_CG_STATE_GATE
) ? true : false;
1681 uvd_v7_0_set_bypass_mode(adev
, enable
);
1683 if (!(adev
->cg_flags
& AMD_CG_SUPPORT_UVD_MGCG
))
1687 /* disable HW gating and enable Sw gating */
1688 uvd_v7_0_set_sw_clock_gating(adev
);
1690 /* wait for STATUS to clear */
1691 if (uvd_v7_0_wait_for_idle(handle
))
1694 /* enable HW gates because UVD is idle */
1695 /* uvd_v7_0_set_hw_clock_gating(adev); */
1701 static int uvd_v7_0_set_powergating_state(void *handle
,
1702 enum amd_powergating_state state
)
1704 /* This doesn't actually powergate the UVD block.
1705 * That's done in the dpm code via the SMC. This
1706 * just re-inits the block as necessary. The actual
1707 * gating still happens in the dpm code. We should
1708 * revisit this when there is a cleaner line between
1709 * the smc and the hw blocks
1711 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
1713 if (!(adev
->pg_flags
& AMD_PG_SUPPORT_UVD
))
1716 WREG32_SOC15(UVD
, ring
->me
, mmUVD_POWER_STATUS
, UVD_POWER_STATUS__UVD_PG_EN_MASK
);
1718 if (state
== AMD_PG_STATE_GATE
) {
1719 uvd_v7_0_stop(adev
);
1722 return uvd_v7_0_start(adev
);
1727 static int uvd_v7_0_set_clockgating_state(void *handle
,
1728 enum amd_clockgating_state state
)
1730 /* needed for driver unload*/
1734 const struct amd_ip_funcs uvd_v7_0_ip_funcs
= {
1736 .early_init
= uvd_v7_0_early_init
,
1738 .sw_init
= uvd_v7_0_sw_init
,
1739 .sw_fini
= uvd_v7_0_sw_fini
,
1740 .hw_init
= uvd_v7_0_hw_init
,
1741 .hw_fini
= uvd_v7_0_hw_fini
,
1742 .suspend
= uvd_v7_0_suspend
,
1743 .resume
= uvd_v7_0_resume
,
1744 .is_idle
= NULL
/* uvd_v7_0_is_idle */,
1745 .wait_for_idle
= NULL
/* uvd_v7_0_wait_for_idle */,
1746 .check_soft_reset
= NULL
/* uvd_v7_0_check_soft_reset */,
1747 .pre_soft_reset
= NULL
/* uvd_v7_0_pre_soft_reset */,
1748 .soft_reset
= NULL
/* uvd_v7_0_soft_reset */,
1749 .post_soft_reset
= NULL
/* uvd_v7_0_post_soft_reset */,
1750 .set_clockgating_state
= uvd_v7_0_set_clockgating_state
,
1751 .set_powergating_state
= NULL
/* uvd_v7_0_set_powergating_state */,
1754 static const struct amdgpu_ring_funcs uvd_v7_0_ring_vm_funcs
= {
1755 .type
= AMDGPU_RING_TYPE_UVD
,
1757 .support_64bit_ptrs
= false,
1758 .vmhub
= AMDGPU_MMHUB
,
1759 .get_rptr
= uvd_v7_0_ring_get_rptr
,
1760 .get_wptr
= uvd_v7_0_ring_get_wptr
,
1761 .set_wptr
= uvd_v7_0_ring_set_wptr
,
1762 .patch_cs_in_place
= uvd_v7_0_ring_patch_cs_in_place
,
1764 6 + /* hdp invalidate */
1765 SOC15_FLUSH_GPU_TLB_NUM_WREG
* 6 +
1766 SOC15_FLUSH_GPU_TLB_NUM_REG_WAIT
* 8 +
1767 8 + /* uvd_v7_0_ring_emit_vm_flush */
1768 14 + 14, /* uvd_v7_0_ring_emit_fence x2 vm fence */
1769 .emit_ib_size
= 8, /* uvd_v7_0_ring_emit_ib */
1770 .emit_ib
= uvd_v7_0_ring_emit_ib
,
1771 .emit_fence
= uvd_v7_0_ring_emit_fence
,
1772 .emit_vm_flush
= uvd_v7_0_ring_emit_vm_flush
,
1773 .emit_hdp_flush
= uvd_v7_0_ring_emit_hdp_flush
,
1774 .test_ring
= uvd_v7_0_ring_test_ring
,
1775 .test_ib
= amdgpu_uvd_ring_test_ib
,
1776 .insert_nop
= uvd_v7_0_ring_insert_nop
,
1777 .pad_ib
= amdgpu_ring_generic_pad_ib
,
1778 .begin_use
= amdgpu_uvd_ring_begin_use
,
1779 .end_use
= amdgpu_uvd_ring_end_use
,
1780 .emit_wreg
= uvd_v7_0_ring_emit_wreg
,
1781 .emit_reg_wait
= uvd_v7_0_ring_emit_reg_wait
,
1782 .emit_reg_write_reg_wait
= amdgpu_ring_emit_reg_write_reg_wait_helper
,
1785 static const struct amdgpu_ring_funcs uvd_v7_0_enc_ring_vm_funcs
= {
1786 .type
= AMDGPU_RING_TYPE_UVD_ENC
,
1788 .nop
= HEVC_ENC_CMD_NO_OP
,
1789 .support_64bit_ptrs
= false,
1790 .vmhub
= AMDGPU_MMHUB
,
1791 .get_rptr
= uvd_v7_0_enc_ring_get_rptr
,
1792 .get_wptr
= uvd_v7_0_enc_ring_get_wptr
,
1793 .set_wptr
= uvd_v7_0_enc_ring_set_wptr
,
1795 3 + 3 + /* hdp flush / invalidate */
1796 SOC15_FLUSH_GPU_TLB_NUM_WREG
* 3 +
1797 SOC15_FLUSH_GPU_TLB_NUM_REG_WAIT
* 4 +
1798 4 + /* uvd_v7_0_enc_ring_emit_vm_flush */
1799 5 + 5 + /* uvd_v7_0_enc_ring_emit_fence x2 vm fence */
1800 1, /* uvd_v7_0_enc_ring_insert_end */
1801 .emit_ib_size
= 5, /* uvd_v7_0_enc_ring_emit_ib */
1802 .emit_ib
= uvd_v7_0_enc_ring_emit_ib
,
1803 .emit_fence
= uvd_v7_0_enc_ring_emit_fence
,
1804 .emit_vm_flush
= uvd_v7_0_enc_ring_emit_vm_flush
,
1805 .test_ring
= uvd_v7_0_enc_ring_test_ring
,
1806 .test_ib
= uvd_v7_0_enc_ring_test_ib
,
1807 .insert_nop
= amdgpu_ring_insert_nop
,
1808 .insert_end
= uvd_v7_0_enc_ring_insert_end
,
1809 .pad_ib
= amdgpu_ring_generic_pad_ib
,
1810 .begin_use
= amdgpu_uvd_ring_begin_use
,
1811 .end_use
= amdgpu_uvd_ring_end_use
,
1812 .emit_wreg
= uvd_v7_0_enc_ring_emit_wreg
,
1813 .emit_reg_wait
= uvd_v7_0_enc_ring_emit_reg_wait
,
1814 .emit_reg_write_reg_wait
= amdgpu_ring_emit_reg_write_reg_wait_helper
,
1817 static void uvd_v7_0_set_ring_funcs(struct amdgpu_device
*adev
)
1821 for (i
= 0; i
< adev
->uvd
.num_uvd_inst
; i
++) {
1822 if (adev
->uvd
.harvest_config
& (1 << i
))
1824 adev
->uvd
.inst
[i
].ring
.funcs
= &uvd_v7_0_ring_vm_funcs
;
1825 adev
->uvd
.inst
[i
].ring
.me
= i
;
1826 DRM_INFO("UVD(%d) is enabled in VM mode\n", i
);
1830 static void uvd_v7_0_set_enc_ring_funcs(struct amdgpu_device
*adev
)
1834 for (j
= 0; j
< adev
->uvd
.num_uvd_inst
; j
++) {
1835 if (adev
->uvd
.harvest_config
& (1 << j
))
1837 for (i
= 0; i
< adev
->uvd
.num_enc_rings
; ++i
) {
1838 adev
->uvd
.inst
[j
].ring_enc
[i
].funcs
= &uvd_v7_0_enc_ring_vm_funcs
;
1839 adev
->uvd
.inst
[j
].ring_enc
[i
].me
= j
;
1842 DRM_INFO("UVD(%d) ENC is enabled in VM mode\n", j
);
1846 static const struct amdgpu_irq_src_funcs uvd_v7_0_irq_funcs
= {
1847 .set
= uvd_v7_0_set_interrupt_state
,
1848 .process
= uvd_v7_0_process_interrupt
,
1851 static void uvd_v7_0_set_irq_funcs(struct amdgpu_device
*adev
)
1855 for (i
= 0; i
< adev
->uvd
.num_uvd_inst
; i
++) {
1856 if (adev
->uvd
.harvest_config
& (1 << i
))
1858 adev
->uvd
.inst
[i
].irq
.num_types
= adev
->uvd
.num_enc_rings
+ 1;
1859 adev
->uvd
.inst
[i
].irq
.funcs
= &uvd_v7_0_irq_funcs
;
1863 const struct amdgpu_ip_block_version uvd_v7_0_ip_block
=
1865 .type
= AMD_IP_BLOCK_TYPE_UVD
,
1869 .funcs
= &uvd_v7_0_ip_funcs
,