2 * Copyright 2014 Advanced Micro Devices, Inc.
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:
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.
21 * The above copyright notice and this permission notice (including the
22 * next paragraph) shall be included in all copies or substantial portions
25 * Authors: Christian König <christian.koenig@amd.com>
28 #include <linux/firmware.h>
31 #include "amdgpu_vce.h"
33 #include "vce/vce_3_0_d.h"
34 #include "vce/vce_3_0_sh_mask.h"
35 #include "oss/oss_3_0_d.h"
36 #include "oss/oss_3_0_sh_mask.h"
37 #include "gca/gfx_8_0_d.h"
38 #include "smu/smu_7_1_2_d.h"
39 #include "smu/smu_7_1_2_sh_mask.h"
40 #include "gca/gfx_8_0_sh_mask.h"
41 #include "ivsrcid/ivsrcid_vislands30.h"
44 #define GRBM_GFX_INDEX__VCE_INSTANCE__SHIFT 0x04
45 #define GRBM_GFX_INDEX__VCE_INSTANCE_MASK 0x10
46 #define GRBM_GFX_INDEX__VCE_ALL_PIPE 0x07
48 #define mmVCE_LMI_VCPU_CACHE_40BIT_BAR0 0x8616
49 #define mmVCE_LMI_VCPU_CACHE_40BIT_BAR1 0x8617
50 #define mmVCE_LMI_VCPU_CACHE_40BIT_BAR2 0x8618
51 #define mmGRBM_GFX_INDEX_DEFAULT 0xE0000000
53 #define VCE_STATUS_VCPU_REPORT_FW_LOADED_MASK 0x02
55 #define VCE_V3_0_FW_SIZE (384 * 1024)
56 #define VCE_V3_0_STACK_SIZE (64 * 1024)
57 #define VCE_V3_0_DATA_SIZE ((16 * 1024 * AMDGPU_MAX_VCE_HANDLES) + (52 * 1024))
59 #define FW_52_8_3 ((52 << 24) | (8 << 16) | (3 << 8))
61 #define GET_VCE_INSTANCE(i) ((i) << GRBM_GFX_INDEX__VCE_INSTANCE__SHIFT \
62 | GRBM_GFX_INDEX__VCE_ALL_PIPE)
64 static void vce_v3_0_mc_resume(struct amdgpu_device
*adev
, int idx
);
65 static void vce_v3_0_set_ring_funcs(struct amdgpu_device
*adev
);
66 static void vce_v3_0_set_irq_funcs(struct amdgpu_device
*adev
);
67 static int vce_v3_0_wait_for_idle(void *handle
);
68 static int vce_v3_0_set_clockgating_state(void *handle
,
69 enum amd_clockgating_state state
);
71 * vce_v3_0_ring_get_rptr - get read pointer
73 * @ring: amdgpu_ring pointer
75 * Returns the current hardware read pointer
77 static uint64_t vce_v3_0_ring_get_rptr(struct amdgpu_ring
*ring
)
79 struct amdgpu_device
*adev
= ring
->adev
;
82 mutex_lock(&adev
->grbm_idx_mutex
);
83 if (adev
->vce
.harvest_config
== 0 ||
84 adev
->vce
.harvest_config
== AMDGPU_VCE_HARVEST_VCE1
)
85 WREG32(mmGRBM_GFX_INDEX
, GET_VCE_INSTANCE(0));
86 else if (adev
->vce
.harvest_config
== AMDGPU_VCE_HARVEST_VCE0
)
87 WREG32(mmGRBM_GFX_INDEX
, GET_VCE_INSTANCE(1));
90 v
= RREG32(mmVCE_RB_RPTR
);
91 else if (ring
->me
== 1)
92 v
= RREG32(mmVCE_RB_RPTR2
);
94 v
= RREG32(mmVCE_RB_RPTR3
);
96 WREG32(mmGRBM_GFX_INDEX
, mmGRBM_GFX_INDEX_DEFAULT
);
97 mutex_unlock(&adev
->grbm_idx_mutex
);
103 * vce_v3_0_ring_get_wptr - get write pointer
105 * @ring: amdgpu_ring pointer
107 * Returns the current hardware write pointer
109 static uint64_t vce_v3_0_ring_get_wptr(struct amdgpu_ring
*ring
)
111 struct amdgpu_device
*adev
= ring
->adev
;
114 mutex_lock(&adev
->grbm_idx_mutex
);
115 if (adev
->vce
.harvest_config
== 0 ||
116 adev
->vce
.harvest_config
== AMDGPU_VCE_HARVEST_VCE1
)
117 WREG32(mmGRBM_GFX_INDEX
, GET_VCE_INSTANCE(0));
118 else if (adev
->vce
.harvest_config
== AMDGPU_VCE_HARVEST_VCE0
)
119 WREG32(mmGRBM_GFX_INDEX
, GET_VCE_INSTANCE(1));
122 v
= RREG32(mmVCE_RB_WPTR
);
123 else if (ring
->me
== 1)
124 v
= RREG32(mmVCE_RB_WPTR2
);
126 v
= RREG32(mmVCE_RB_WPTR3
);
128 WREG32(mmGRBM_GFX_INDEX
, mmGRBM_GFX_INDEX_DEFAULT
);
129 mutex_unlock(&adev
->grbm_idx_mutex
);
135 * vce_v3_0_ring_set_wptr - set write pointer
137 * @ring: amdgpu_ring pointer
139 * Commits the write pointer to the hardware
141 static void vce_v3_0_ring_set_wptr(struct amdgpu_ring
*ring
)
143 struct amdgpu_device
*adev
= ring
->adev
;
145 mutex_lock(&adev
->grbm_idx_mutex
);
146 if (adev
->vce
.harvest_config
== 0 ||
147 adev
->vce
.harvest_config
== AMDGPU_VCE_HARVEST_VCE1
)
148 WREG32(mmGRBM_GFX_INDEX
, GET_VCE_INSTANCE(0));
149 else if (adev
->vce
.harvest_config
== AMDGPU_VCE_HARVEST_VCE0
)
150 WREG32(mmGRBM_GFX_INDEX
, GET_VCE_INSTANCE(1));
153 WREG32(mmVCE_RB_WPTR
, lower_32_bits(ring
->wptr
));
154 else if (ring
->me
== 1)
155 WREG32(mmVCE_RB_WPTR2
, lower_32_bits(ring
->wptr
));
157 WREG32(mmVCE_RB_WPTR3
, lower_32_bits(ring
->wptr
));
159 WREG32(mmGRBM_GFX_INDEX
, mmGRBM_GFX_INDEX_DEFAULT
);
160 mutex_unlock(&adev
->grbm_idx_mutex
);
163 static void vce_v3_0_override_vce_clock_gating(struct amdgpu_device
*adev
, bool override
)
165 WREG32_FIELD(VCE_RB_ARB_CTRL
, VCE_CGTT_OVERRIDE
, override
? 1 : 0);
168 static void vce_v3_0_set_vce_sw_clock_gating(struct amdgpu_device
*adev
,
173 /* Set Override to disable Clock Gating */
174 vce_v3_0_override_vce_clock_gating(adev
, true);
176 /* This function enables MGCG which is controlled by firmware.
177 With the clocks in the gated state the core is still
178 accessible but the firmware will throttle the clocks on the
182 data
= RREG32(mmVCE_CLOCK_GATING_B
);
185 WREG32(mmVCE_CLOCK_GATING_B
, data
);
187 data
= RREG32(mmVCE_UENC_CLOCK_GATING
);
190 WREG32(mmVCE_UENC_CLOCK_GATING
, data
);
192 data
= RREG32(mmVCE_UENC_CLOCK_GATING_2
);
195 WREG32(mmVCE_UENC_CLOCK_GATING_2
, data
);
197 data
= RREG32(mmVCE_UENC_REG_CLOCK_GATING
);
199 WREG32(mmVCE_UENC_REG_CLOCK_GATING
, data
);
201 data
= RREG32(mmVCE_UENC_DMA_DCLK_CTRL
);
202 data
|= VCE_UENC_DMA_DCLK_CTRL__WRDMCLK_FORCEON_MASK
|
203 VCE_UENC_DMA_DCLK_CTRL__RDDMCLK_FORCEON_MASK
|
204 VCE_UENC_DMA_DCLK_CTRL__REGCLK_FORCEON_MASK
|
206 WREG32(mmVCE_UENC_DMA_DCLK_CTRL
, data
);
208 data
= RREG32(mmVCE_CLOCK_GATING_B
);
211 WREG32(mmVCE_CLOCK_GATING_B
, data
);
213 data
= RREG32(mmVCE_UENC_CLOCK_GATING
);
215 WREG32(mmVCE_UENC_CLOCK_GATING
, data
);
217 data
= RREG32(mmVCE_UENC_CLOCK_GATING_2
);
219 WREG32(mmVCE_UENC_CLOCK_GATING_2
, data
);
221 data
= RREG32(mmVCE_UENC_REG_CLOCK_GATING
);
223 WREG32(mmVCE_UENC_REG_CLOCK_GATING
, data
);
225 data
= RREG32(mmVCE_UENC_DMA_DCLK_CTRL
);
226 data
&= ~(VCE_UENC_DMA_DCLK_CTRL__WRDMCLK_FORCEON_MASK
|
227 VCE_UENC_DMA_DCLK_CTRL__RDDMCLK_FORCEON_MASK
|
228 VCE_UENC_DMA_DCLK_CTRL__REGCLK_FORCEON_MASK
|
230 WREG32(mmVCE_UENC_DMA_DCLK_CTRL
, data
);
232 vce_v3_0_override_vce_clock_gating(adev
, false);
235 static int vce_v3_0_firmware_loaded(struct amdgpu_device
*adev
)
239 for (i
= 0; i
< 10; ++i
) {
240 for (j
= 0; j
< 100; ++j
) {
241 uint32_t status
= RREG32(mmVCE_STATUS
);
243 if (status
& VCE_STATUS_VCPU_REPORT_FW_LOADED_MASK
)
248 DRM_ERROR("VCE not responding, trying to reset the ECPU!!!\n");
249 WREG32_FIELD(VCE_SOFT_RESET
, ECPU_SOFT_RESET
, 1);
251 WREG32_FIELD(VCE_SOFT_RESET
, ECPU_SOFT_RESET
, 0);
259 * vce_v3_0_start - start VCE block
261 * @adev: amdgpu_device pointer
263 * Setup and start the VCE block
265 static int vce_v3_0_start(struct amdgpu_device
*adev
)
267 struct amdgpu_ring
*ring
;
270 mutex_lock(&adev
->grbm_idx_mutex
);
271 for (idx
= 0; idx
< 2; ++idx
) {
272 if (adev
->vce
.harvest_config
& (1 << idx
))
275 WREG32(mmGRBM_GFX_INDEX
, GET_VCE_INSTANCE(idx
));
277 /* Program instance 0 reg space for two instances or instance 0 case
278 program instance 1 reg space for only instance 1 available case */
279 if (idx
!= 1 || adev
->vce
.harvest_config
== AMDGPU_VCE_HARVEST_VCE0
) {
280 ring
= &adev
->vce
.ring
[0];
281 WREG32(mmVCE_RB_RPTR
, lower_32_bits(ring
->wptr
));
282 WREG32(mmVCE_RB_WPTR
, lower_32_bits(ring
->wptr
));
283 WREG32(mmVCE_RB_BASE_LO
, ring
->gpu_addr
);
284 WREG32(mmVCE_RB_BASE_HI
, upper_32_bits(ring
->gpu_addr
));
285 WREG32(mmVCE_RB_SIZE
, ring
->ring_size
/ 4);
287 ring
= &adev
->vce
.ring
[1];
288 WREG32(mmVCE_RB_RPTR2
, lower_32_bits(ring
->wptr
));
289 WREG32(mmVCE_RB_WPTR2
, lower_32_bits(ring
->wptr
));
290 WREG32(mmVCE_RB_BASE_LO2
, ring
->gpu_addr
);
291 WREG32(mmVCE_RB_BASE_HI2
, upper_32_bits(ring
->gpu_addr
));
292 WREG32(mmVCE_RB_SIZE2
, ring
->ring_size
/ 4);
294 ring
= &adev
->vce
.ring
[2];
295 WREG32(mmVCE_RB_RPTR3
, lower_32_bits(ring
->wptr
));
296 WREG32(mmVCE_RB_WPTR3
, lower_32_bits(ring
->wptr
));
297 WREG32(mmVCE_RB_BASE_LO3
, ring
->gpu_addr
);
298 WREG32(mmVCE_RB_BASE_HI3
, upper_32_bits(ring
->gpu_addr
));
299 WREG32(mmVCE_RB_SIZE3
, ring
->ring_size
/ 4);
302 vce_v3_0_mc_resume(adev
, idx
);
303 WREG32_FIELD(VCE_STATUS
, JOB_BUSY
, 1);
305 if (adev
->asic_type
>= CHIP_STONEY
)
306 WREG32_P(mmVCE_VCPU_CNTL
, 1, ~0x200001);
308 WREG32_FIELD(VCE_VCPU_CNTL
, CLK_EN
, 1);
310 WREG32_FIELD(VCE_SOFT_RESET
, ECPU_SOFT_RESET
, 0);
313 r
= vce_v3_0_firmware_loaded(adev
);
315 /* clear BUSY flag */
316 WREG32_FIELD(VCE_STATUS
, JOB_BUSY
, 0);
319 DRM_ERROR("VCE not responding, giving up!!!\n");
320 mutex_unlock(&adev
->grbm_idx_mutex
);
325 WREG32(mmGRBM_GFX_INDEX
, mmGRBM_GFX_INDEX_DEFAULT
);
326 mutex_unlock(&adev
->grbm_idx_mutex
);
331 static int vce_v3_0_stop(struct amdgpu_device
*adev
)
335 mutex_lock(&adev
->grbm_idx_mutex
);
336 for (idx
= 0; idx
< 2; ++idx
) {
337 if (adev
->vce
.harvest_config
& (1 << idx
))
340 WREG32(mmGRBM_GFX_INDEX
, GET_VCE_INSTANCE(idx
));
342 if (adev
->asic_type
>= CHIP_STONEY
)
343 WREG32_P(mmVCE_VCPU_CNTL
, 0, ~0x200001);
345 WREG32_FIELD(VCE_VCPU_CNTL
, CLK_EN
, 0);
348 WREG32_FIELD(VCE_SOFT_RESET
, ECPU_SOFT_RESET
, 1);
350 /* clear VCE STATUS */
351 WREG32(mmVCE_STATUS
, 0);
354 WREG32(mmGRBM_GFX_INDEX
, mmGRBM_GFX_INDEX_DEFAULT
);
355 mutex_unlock(&adev
->grbm_idx_mutex
);
360 #define ixVCE_HARVEST_FUSE_MACRO__ADDRESS 0xC0014074
361 #define VCE_HARVEST_FUSE_MACRO__SHIFT 27
362 #define VCE_HARVEST_FUSE_MACRO__MASK 0x18000000
364 static unsigned vce_v3_0_get_harvest_config(struct amdgpu_device
*adev
)
368 if ((adev
->asic_type
== CHIP_FIJI
) ||
369 (adev
->asic_type
== CHIP_STONEY
))
370 return AMDGPU_VCE_HARVEST_VCE1
;
372 if (adev
->flags
& AMD_IS_APU
)
373 tmp
= (RREG32_SMC(ixVCE_HARVEST_FUSE_MACRO__ADDRESS
) &
374 VCE_HARVEST_FUSE_MACRO__MASK
) >>
375 VCE_HARVEST_FUSE_MACRO__SHIFT
;
377 tmp
= (RREG32_SMC(ixCC_HARVEST_FUSES
) &
378 CC_HARVEST_FUSES__VCE_DISABLE_MASK
) >>
379 CC_HARVEST_FUSES__VCE_DISABLE__SHIFT
;
383 return AMDGPU_VCE_HARVEST_VCE0
;
385 return AMDGPU_VCE_HARVEST_VCE1
;
387 return AMDGPU_VCE_HARVEST_VCE0
| AMDGPU_VCE_HARVEST_VCE1
;
389 if ((adev
->asic_type
== CHIP_POLARIS10
) ||
390 (adev
->asic_type
== CHIP_POLARIS11
) ||
391 (adev
->asic_type
== CHIP_POLARIS12
) ||
392 (adev
->asic_type
== CHIP_VEGAM
))
393 return AMDGPU_VCE_HARVEST_VCE1
;
399 static int vce_v3_0_early_init(void *handle
)
401 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
403 adev
->vce
.harvest_config
= vce_v3_0_get_harvest_config(adev
);
405 if ((adev
->vce
.harvest_config
&
406 (AMDGPU_VCE_HARVEST_VCE0
| AMDGPU_VCE_HARVEST_VCE1
)) ==
407 (AMDGPU_VCE_HARVEST_VCE0
| AMDGPU_VCE_HARVEST_VCE1
))
410 adev
->vce
.num_rings
= 3;
412 vce_v3_0_set_ring_funcs(adev
);
413 vce_v3_0_set_irq_funcs(adev
);
418 static int vce_v3_0_sw_init(void *handle
)
420 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
421 struct amdgpu_ring
*ring
;
425 r
= amdgpu_irq_add_id(adev
, AMDGPU_IRQ_CLIENTID_LEGACY
, VISLANDS30_IV_SRCID_VCE_TRAP
, &adev
->vce
.irq
);
429 r
= amdgpu_vce_sw_init(adev
, VCE_V3_0_FW_SIZE
+
430 (VCE_V3_0_STACK_SIZE
+ VCE_V3_0_DATA_SIZE
) * 2);
434 /* 52.8.3 required for 3 ring support */
435 if (adev
->vce
.fw_version
< FW_52_8_3
)
436 adev
->vce
.num_rings
= 2;
438 r
= amdgpu_vce_resume(adev
);
442 for (i
= 0; i
< adev
->vce
.num_rings
; i
++) {
443 ring
= &adev
->vce
.ring
[i
];
444 sprintf(ring
->name
, "vce%d", i
);
445 r
= amdgpu_ring_init(adev
, ring
, 512, &adev
->vce
.irq
, 0);
450 r
= amdgpu_vce_entity_init(adev
);
455 static int vce_v3_0_sw_fini(void *handle
)
458 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
460 r
= amdgpu_vce_suspend(adev
);
464 return amdgpu_vce_sw_fini(adev
);
467 static int vce_v3_0_hw_init(void *handle
)
470 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
472 vce_v3_0_override_vce_clock_gating(adev
, true);
474 amdgpu_asic_set_vce_clocks(adev
, 10000, 10000);
476 for (i
= 0; i
< adev
->vce
.num_rings
; i
++) {
477 r
= amdgpu_ring_test_helper(&adev
->vce
.ring
[i
]);
482 DRM_INFO("VCE initialized successfully.\n");
487 static int vce_v3_0_hw_fini(void *handle
)
490 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
492 r
= vce_v3_0_wait_for_idle(handle
);
497 return vce_v3_0_set_clockgating_state(adev
, AMD_CG_STATE_GATE
);
500 static int vce_v3_0_suspend(void *handle
)
503 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
505 r
= vce_v3_0_hw_fini(adev
);
509 return amdgpu_vce_suspend(adev
);
512 static int vce_v3_0_resume(void *handle
)
515 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
517 r
= amdgpu_vce_resume(adev
);
521 return vce_v3_0_hw_init(adev
);
524 static void vce_v3_0_mc_resume(struct amdgpu_device
*adev
, int idx
)
526 uint32_t offset
, size
;
528 WREG32_P(mmVCE_CLOCK_GATING_A
, 0, ~(1 << 16));
529 WREG32_P(mmVCE_UENC_CLOCK_GATING
, 0x1FF000, ~0xFF9FF000);
530 WREG32_P(mmVCE_UENC_REG_CLOCK_GATING
, 0x3F, ~0x3F);
531 WREG32(mmVCE_CLOCK_GATING_B
, 0x1FF);
533 WREG32(mmVCE_LMI_CTRL
, 0x00398000);
534 WREG32_P(mmVCE_LMI_CACHE_CTRL
, 0x0, ~0x1);
535 WREG32(mmVCE_LMI_SWAP_CNTL
, 0);
536 WREG32(mmVCE_LMI_SWAP_CNTL1
, 0);
537 WREG32(mmVCE_LMI_VM_CTRL
, 0);
538 WREG32_OR(mmVCE_VCPU_CNTL
, 0x00100000);
540 if (adev
->asic_type
>= CHIP_STONEY
) {
541 WREG32(mmVCE_LMI_VCPU_CACHE_40BIT_BAR0
, (adev
->vce
.gpu_addr
>> 8));
542 WREG32(mmVCE_LMI_VCPU_CACHE_40BIT_BAR1
, (adev
->vce
.gpu_addr
>> 8));
543 WREG32(mmVCE_LMI_VCPU_CACHE_40BIT_BAR2
, (adev
->vce
.gpu_addr
>> 8));
545 WREG32(mmVCE_LMI_VCPU_CACHE_40BIT_BAR
, (adev
->vce
.gpu_addr
>> 8));
546 offset
= AMDGPU_VCE_FIRMWARE_OFFSET
;
547 size
= VCE_V3_0_FW_SIZE
;
548 WREG32(mmVCE_VCPU_CACHE_OFFSET0
, offset
& 0x7fffffff);
549 WREG32(mmVCE_VCPU_CACHE_SIZE0
, size
);
553 size
= VCE_V3_0_STACK_SIZE
;
554 WREG32(mmVCE_VCPU_CACHE_OFFSET1
, offset
& 0x7fffffff);
555 WREG32(mmVCE_VCPU_CACHE_SIZE1
, size
);
557 size
= VCE_V3_0_DATA_SIZE
;
558 WREG32(mmVCE_VCPU_CACHE_OFFSET2
, offset
& 0x7fffffff);
559 WREG32(mmVCE_VCPU_CACHE_SIZE2
, size
);
561 offset
+= size
+ VCE_V3_0_STACK_SIZE
+ VCE_V3_0_DATA_SIZE
;
562 size
= VCE_V3_0_STACK_SIZE
;
563 WREG32(mmVCE_VCPU_CACHE_OFFSET1
, offset
& 0xfffffff);
564 WREG32(mmVCE_VCPU_CACHE_SIZE1
, size
);
566 size
= VCE_V3_0_DATA_SIZE
;
567 WREG32(mmVCE_VCPU_CACHE_OFFSET2
, offset
& 0xfffffff);
568 WREG32(mmVCE_VCPU_CACHE_SIZE2
, size
);
571 WREG32_P(mmVCE_LMI_CTRL2
, 0x0, ~0x100);
572 WREG32_FIELD(VCE_SYS_INT_EN
, VCE_SYS_INT_TRAP_INTERRUPT_EN
, 1);
575 static bool vce_v3_0_is_idle(void *handle
)
577 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
580 mask
|= (adev
->vce
.harvest_config
& AMDGPU_VCE_HARVEST_VCE0
) ? 0 : SRBM_STATUS2__VCE0_BUSY_MASK
;
581 mask
|= (adev
->vce
.harvest_config
& AMDGPU_VCE_HARVEST_VCE1
) ? 0 : SRBM_STATUS2__VCE1_BUSY_MASK
;
583 return !(RREG32(mmSRBM_STATUS2
) & mask
);
586 static int vce_v3_0_wait_for_idle(void *handle
)
589 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
591 for (i
= 0; i
< adev
->usec_timeout
; i
++)
592 if (vce_v3_0_is_idle(handle
))
598 #define VCE_STATUS_VCPU_REPORT_AUTO_BUSY_MASK 0x00000008L /* AUTO_BUSY */
599 #define VCE_STATUS_VCPU_REPORT_RB0_BUSY_MASK 0x00000010L /* RB0_BUSY */
600 #define VCE_STATUS_VCPU_REPORT_RB1_BUSY_MASK 0x00000020L /* RB1_BUSY */
601 #define AMDGPU_VCE_STATUS_BUSY_MASK (VCE_STATUS_VCPU_REPORT_AUTO_BUSY_MASK | \
602 VCE_STATUS_VCPU_REPORT_RB0_BUSY_MASK)
604 static bool vce_v3_0_check_soft_reset(void *handle
)
606 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
607 u32 srbm_soft_reset
= 0;
609 /* According to VCE team , we should use VCE_STATUS instead
610 * SRBM_STATUS.VCE_BUSY bit for busy status checking.
611 * GRBM_GFX_INDEX.INSTANCE_INDEX is used to specify which VCE
612 * instance's registers are accessed
613 * (0 for 1st instance, 10 for 2nd instance).
616 *|UENC|ACPI|AUTO ACTIVE|RB1 |RB0 |RB2 | |FW_LOADED|JOB |
617 *|----+----+-----------+----+----+----+----------+---------+----|
618 *|bit8|bit7| bit6 |bit5|bit4|bit3| bit2 | bit1 |bit0|
620 * VCE team suggest use bit 3--bit 6 for busy status check
622 mutex_lock(&adev
->grbm_idx_mutex
);
623 WREG32(mmGRBM_GFX_INDEX
, GET_VCE_INSTANCE(0));
624 if (RREG32(mmVCE_STATUS
) & AMDGPU_VCE_STATUS_BUSY_MASK
) {
625 srbm_soft_reset
= REG_SET_FIELD(srbm_soft_reset
, SRBM_SOFT_RESET
, SOFT_RESET_VCE0
, 1);
626 srbm_soft_reset
= REG_SET_FIELD(srbm_soft_reset
, SRBM_SOFT_RESET
, SOFT_RESET_VCE1
, 1);
628 WREG32(mmGRBM_GFX_INDEX
, GET_VCE_INSTANCE(1));
629 if (RREG32(mmVCE_STATUS
) & AMDGPU_VCE_STATUS_BUSY_MASK
) {
630 srbm_soft_reset
= REG_SET_FIELD(srbm_soft_reset
, SRBM_SOFT_RESET
, SOFT_RESET_VCE0
, 1);
631 srbm_soft_reset
= REG_SET_FIELD(srbm_soft_reset
, SRBM_SOFT_RESET
, SOFT_RESET_VCE1
, 1);
633 WREG32(mmGRBM_GFX_INDEX
, GET_VCE_INSTANCE(0));
634 mutex_unlock(&adev
->grbm_idx_mutex
);
636 if (srbm_soft_reset
) {
637 adev
->vce
.srbm_soft_reset
= srbm_soft_reset
;
640 adev
->vce
.srbm_soft_reset
= 0;
645 static int vce_v3_0_soft_reset(void *handle
)
647 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
650 if (!adev
->vce
.srbm_soft_reset
)
652 srbm_soft_reset
= adev
->vce
.srbm_soft_reset
;
654 if (srbm_soft_reset
) {
657 tmp
= RREG32(mmSRBM_SOFT_RESET
);
658 tmp
|= srbm_soft_reset
;
659 dev_info(adev
->dev
, "SRBM_SOFT_RESET=0x%08X\n", tmp
);
660 WREG32(mmSRBM_SOFT_RESET
, tmp
);
661 tmp
= RREG32(mmSRBM_SOFT_RESET
);
665 tmp
&= ~srbm_soft_reset
;
666 WREG32(mmSRBM_SOFT_RESET
, tmp
);
667 tmp
= RREG32(mmSRBM_SOFT_RESET
);
669 /* Wait a little for things to settle down */
676 static int vce_v3_0_pre_soft_reset(void *handle
)
678 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
680 if (!adev
->vce
.srbm_soft_reset
)
685 return vce_v3_0_suspend(adev
);
689 static int vce_v3_0_post_soft_reset(void *handle
)
691 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
693 if (!adev
->vce
.srbm_soft_reset
)
698 return vce_v3_0_resume(adev
);
701 static int vce_v3_0_set_interrupt_state(struct amdgpu_device
*adev
,
702 struct amdgpu_irq_src
*source
,
704 enum amdgpu_interrupt_state state
)
708 if (state
== AMDGPU_IRQ_STATE_ENABLE
)
709 val
|= VCE_SYS_INT_EN__VCE_SYS_INT_TRAP_INTERRUPT_EN_MASK
;
711 WREG32_P(mmVCE_SYS_INT_EN
, val
, ~VCE_SYS_INT_EN__VCE_SYS_INT_TRAP_INTERRUPT_EN_MASK
);
715 static int vce_v3_0_process_interrupt(struct amdgpu_device
*adev
,
716 struct amdgpu_irq_src
*source
,
717 struct amdgpu_iv_entry
*entry
)
719 DRM_DEBUG("IH: VCE\n");
721 WREG32_FIELD(VCE_SYS_INT_STATUS
, VCE_SYS_INT_TRAP_INTERRUPT_INT
, 1);
723 switch (entry
->src_data
[0]) {
727 amdgpu_fence_process(&adev
->vce
.ring
[entry
->src_data
[0]]);
730 DRM_ERROR("Unhandled interrupt: %d %d\n",
731 entry
->src_id
, entry
->src_data
[0]);
738 static int vce_v3_0_set_clockgating_state(void *handle
,
739 enum amd_clockgating_state state
)
741 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
742 bool enable
= (state
== AMD_CG_STATE_GATE
) ? true : false;
745 if (!(adev
->cg_flags
& AMD_CG_SUPPORT_VCE_MGCG
))
748 mutex_lock(&adev
->grbm_idx_mutex
);
749 for (i
= 0; i
< 2; i
++) {
750 /* Program VCE Instance 0 or 1 if not harvested */
751 if (adev
->vce
.harvest_config
& (1 << i
))
754 WREG32(mmGRBM_GFX_INDEX
, GET_VCE_INSTANCE(i
));
757 /* initialize VCE_CLOCK_GATING_A: Clock ON/OFF delay */
758 uint32_t data
= RREG32(mmVCE_CLOCK_GATING_A
);
759 data
&= ~(0xf | 0xff0);
760 data
|= ((0x0 << 0) | (0x04 << 4));
761 WREG32(mmVCE_CLOCK_GATING_A
, data
);
763 /* initialize VCE_UENC_CLOCK_GATING: Clock ON/OFF delay */
764 data
= RREG32(mmVCE_UENC_CLOCK_GATING
);
765 data
&= ~(0xf | 0xff0);
766 data
|= ((0x0 << 0) | (0x04 << 4));
767 WREG32(mmVCE_UENC_CLOCK_GATING
, data
);
770 vce_v3_0_set_vce_sw_clock_gating(adev
, enable
);
773 WREG32(mmGRBM_GFX_INDEX
, mmGRBM_GFX_INDEX_DEFAULT
);
774 mutex_unlock(&adev
->grbm_idx_mutex
);
779 static int vce_v3_0_set_powergating_state(void *handle
,
780 enum amd_powergating_state state
)
782 /* This doesn't actually powergate the VCE block.
783 * That's done in the dpm code via the SMC. This
784 * just re-inits the block as necessary. The actual
785 * gating still happens in the dpm code. We should
786 * revisit this when there is a cleaner line between
787 * the smc and the hw blocks
789 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
792 if (state
== AMD_PG_STATE_GATE
) {
793 ret
= vce_v3_0_stop(adev
);
797 ret
= vce_v3_0_start(adev
);
806 static void vce_v3_0_get_clockgating_state(void *handle
, u32
*flags
)
808 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
811 mutex_lock(&adev
->pm
.mutex
);
813 if (adev
->flags
& AMD_IS_APU
)
814 data
= RREG32_SMC(ixCURRENT_PG_STATUS_APU
);
816 data
= RREG32_SMC(ixCURRENT_PG_STATUS
);
818 if (data
& CURRENT_PG_STATUS__VCE_PG_STATUS_MASK
) {
819 DRM_INFO("Cannot get clockgating state when VCE is powergated.\n");
823 WREG32_FIELD(GRBM_GFX_INDEX
, VCE_INSTANCE
, 0);
825 /* AMD_CG_SUPPORT_VCE_MGCG */
826 data
= RREG32(mmVCE_CLOCK_GATING_A
);
827 if (data
& (0x04 << 4))
828 *flags
|= AMD_CG_SUPPORT_VCE_MGCG
;
831 mutex_unlock(&adev
->pm
.mutex
);
834 static void vce_v3_0_ring_emit_ib(struct amdgpu_ring
*ring
,
835 struct amdgpu_job
*job
,
836 struct amdgpu_ib
*ib
,
839 unsigned vmid
= AMDGPU_JOB_GET_VMID(job
);
841 amdgpu_ring_write(ring
, VCE_CMD_IB_VM
);
842 amdgpu_ring_write(ring
, vmid
);
843 amdgpu_ring_write(ring
, lower_32_bits(ib
->gpu_addr
));
844 amdgpu_ring_write(ring
, upper_32_bits(ib
->gpu_addr
));
845 amdgpu_ring_write(ring
, ib
->length_dw
);
848 static void vce_v3_0_emit_vm_flush(struct amdgpu_ring
*ring
,
849 unsigned int vmid
, uint64_t pd_addr
)
851 amdgpu_ring_write(ring
, VCE_CMD_UPDATE_PTB
);
852 amdgpu_ring_write(ring
, vmid
);
853 amdgpu_ring_write(ring
, pd_addr
>> 12);
855 amdgpu_ring_write(ring
, VCE_CMD_FLUSH_TLB
);
856 amdgpu_ring_write(ring
, vmid
);
857 amdgpu_ring_write(ring
, VCE_CMD_END
);
860 static void vce_v3_0_emit_pipeline_sync(struct amdgpu_ring
*ring
)
862 uint32_t seq
= ring
->fence_drv
.sync_seq
;
863 uint64_t addr
= ring
->fence_drv
.gpu_addr
;
865 amdgpu_ring_write(ring
, VCE_CMD_WAIT_GE
);
866 amdgpu_ring_write(ring
, lower_32_bits(addr
));
867 amdgpu_ring_write(ring
, upper_32_bits(addr
));
868 amdgpu_ring_write(ring
, seq
);
871 static const struct amd_ip_funcs vce_v3_0_ip_funcs
= {
873 .early_init
= vce_v3_0_early_init
,
875 .sw_init
= vce_v3_0_sw_init
,
876 .sw_fini
= vce_v3_0_sw_fini
,
877 .hw_init
= vce_v3_0_hw_init
,
878 .hw_fini
= vce_v3_0_hw_fini
,
879 .suspend
= vce_v3_0_suspend
,
880 .resume
= vce_v3_0_resume
,
881 .is_idle
= vce_v3_0_is_idle
,
882 .wait_for_idle
= vce_v3_0_wait_for_idle
,
883 .check_soft_reset
= vce_v3_0_check_soft_reset
,
884 .pre_soft_reset
= vce_v3_0_pre_soft_reset
,
885 .soft_reset
= vce_v3_0_soft_reset
,
886 .post_soft_reset
= vce_v3_0_post_soft_reset
,
887 .set_clockgating_state
= vce_v3_0_set_clockgating_state
,
888 .set_powergating_state
= vce_v3_0_set_powergating_state
,
889 .get_clockgating_state
= vce_v3_0_get_clockgating_state
,
892 static const struct amdgpu_ring_funcs vce_v3_0_ring_phys_funcs
= {
893 .type
= AMDGPU_RING_TYPE_VCE
,
895 .nop
= VCE_CMD_NO_OP
,
896 .support_64bit_ptrs
= false,
897 .get_rptr
= vce_v3_0_ring_get_rptr
,
898 .get_wptr
= vce_v3_0_ring_get_wptr
,
899 .set_wptr
= vce_v3_0_ring_set_wptr
,
900 .parse_cs
= amdgpu_vce_ring_parse_cs
,
902 4 + /* vce_v3_0_emit_pipeline_sync */
903 6, /* amdgpu_vce_ring_emit_fence x1 no user fence */
904 .emit_ib_size
= 4, /* amdgpu_vce_ring_emit_ib */
905 .emit_ib
= amdgpu_vce_ring_emit_ib
,
906 .emit_fence
= amdgpu_vce_ring_emit_fence
,
907 .test_ring
= amdgpu_vce_ring_test_ring
,
908 .test_ib
= amdgpu_vce_ring_test_ib
,
909 .insert_nop
= amdgpu_ring_insert_nop
,
910 .pad_ib
= amdgpu_ring_generic_pad_ib
,
911 .begin_use
= amdgpu_vce_ring_begin_use
,
912 .end_use
= amdgpu_vce_ring_end_use
,
915 static const struct amdgpu_ring_funcs vce_v3_0_ring_vm_funcs
= {
916 .type
= AMDGPU_RING_TYPE_VCE
,
918 .nop
= VCE_CMD_NO_OP
,
919 .support_64bit_ptrs
= false,
920 .get_rptr
= vce_v3_0_ring_get_rptr
,
921 .get_wptr
= vce_v3_0_ring_get_wptr
,
922 .set_wptr
= vce_v3_0_ring_set_wptr
,
923 .parse_cs
= amdgpu_vce_ring_parse_cs_vm
,
925 6 + /* vce_v3_0_emit_vm_flush */
926 4 + /* vce_v3_0_emit_pipeline_sync */
927 6 + 6, /* amdgpu_vce_ring_emit_fence x2 vm fence */
928 .emit_ib_size
= 5, /* vce_v3_0_ring_emit_ib */
929 .emit_ib
= vce_v3_0_ring_emit_ib
,
930 .emit_vm_flush
= vce_v3_0_emit_vm_flush
,
931 .emit_pipeline_sync
= vce_v3_0_emit_pipeline_sync
,
932 .emit_fence
= amdgpu_vce_ring_emit_fence
,
933 .test_ring
= amdgpu_vce_ring_test_ring
,
934 .test_ib
= amdgpu_vce_ring_test_ib
,
935 .insert_nop
= amdgpu_ring_insert_nop
,
936 .pad_ib
= amdgpu_ring_generic_pad_ib
,
937 .begin_use
= amdgpu_vce_ring_begin_use
,
938 .end_use
= amdgpu_vce_ring_end_use
,
941 static void vce_v3_0_set_ring_funcs(struct amdgpu_device
*adev
)
945 if (adev
->asic_type
>= CHIP_STONEY
) {
946 for (i
= 0; i
< adev
->vce
.num_rings
; i
++) {
947 adev
->vce
.ring
[i
].funcs
= &vce_v3_0_ring_vm_funcs
;
948 adev
->vce
.ring
[i
].me
= i
;
950 DRM_INFO("VCE enabled in VM mode\n");
952 for (i
= 0; i
< adev
->vce
.num_rings
; i
++) {
953 adev
->vce
.ring
[i
].funcs
= &vce_v3_0_ring_phys_funcs
;
954 adev
->vce
.ring
[i
].me
= i
;
956 DRM_INFO("VCE enabled in physical mode\n");
960 static const struct amdgpu_irq_src_funcs vce_v3_0_irq_funcs
= {
961 .set
= vce_v3_0_set_interrupt_state
,
962 .process
= vce_v3_0_process_interrupt
,
965 static void vce_v3_0_set_irq_funcs(struct amdgpu_device
*adev
)
967 adev
->vce
.irq
.num_types
= 1;
968 adev
->vce
.irq
.funcs
= &vce_v3_0_irq_funcs
;
971 const struct amdgpu_ip_block_version vce_v3_0_ip_block
=
973 .type
= AMD_IP_BLOCK_TYPE_VCE
,
977 .funcs
= &vce_v3_0_ip_funcs
,
980 const struct amdgpu_ip_block_version vce_v3_1_ip_block
=
982 .type
= AMD_IP_BLOCK_TYPE_VCE
,
986 .funcs
= &vce_v3_0_ip_funcs
,
989 const struct amdgpu_ip_block_version vce_v3_4_ip_block
=
991 .type
= AMD_IP_BLOCK_TYPE_VCE
,
995 .funcs
= &vce_v3_0_ip_funcs
,