drm/amd/amdgpu: Fix potential ioremap() memory leaks in amdgpu_device_init()
[linux-2.6-block.git] / drivers / gpu / drm / amd / amdgpu / vce_v3_0.c
CommitLineData
aaa36a97
AD
1/*
2 * Copyright 2014 Advanced Micro Devices, Inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
16 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
17 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
18 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
19 * USE OR OTHER DEALINGS IN THE SOFTWARE.
20 *
21 * The above copyright notice and this permission notice (including the
22 * next paragraph) shall be included in all copies or substantial portions
23 * of the Software.
24 *
25 * Authors: Christian König <christian.koenig@amd.com>
26 */
27
28#include <linux/firmware.h>
47b757fb 29
aaa36a97
AD
30#include "amdgpu.h"
31#include "amdgpu_vce.h"
32#include "vid.h"
33#include "vce/vce_3_0_d.h"
34#include "vce/vce_3_0_sh_mask.h"
be4f38e2
AD
35#include "oss/oss_3_0_d.h"
36#include "oss/oss_3_0_sh_mask.h"
5bbc553a 37#include "gca/gfx_8_0_d.h"
6a585777
AD
38#include "smu/smu_7_1_2_d.h"
39#include "smu/smu_7_1_2_sh_mask.h"
115933a5 40#include "gca/gfx_8_0_sh_mask.h"
091aec0b 41#include "ivsrcid/ivsrcid_vislands30.h"
115933a5 42
5bbc553a
LL
43
44#define GRBM_GFX_INDEX__VCE_INSTANCE__SHIFT 0x04
45#define GRBM_GFX_INDEX__VCE_INSTANCE_MASK 0x10
50a1ebc7
RZ
46#define GRBM_GFX_INDEX__VCE_ALL_PIPE 0x07
47
edf600da
CK
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
50a1ebc7
RZ
51#define mmGRBM_GFX_INDEX_DEFAULT 0xE0000000
52
567e6e29 53#define VCE_STATUS_VCPU_REPORT_FW_LOADED_MASK 0x02
aaa36a97 54
e9822622
LL
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))
58
ef6239e0
AD
59#define FW_52_8_3 ((52 << 24) | (8 << 16) | (3 << 8))
60
50a1ebc7
RZ
61#define GET_VCE_INSTANCE(i) ((i) << GRBM_GFX_INDEX__VCE_INSTANCE__SHIFT \
62 | GRBM_GFX_INDEX__VCE_ALL_PIPE)
63
5bbc553a 64static void vce_v3_0_mc_resume(struct amdgpu_device *adev, int idx);
aaa36a97
AD
65static void vce_v3_0_set_ring_funcs(struct amdgpu_device *adev);
66static void vce_v3_0_set_irq_funcs(struct amdgpu_device *adev);
567e6e29 67static int vce_v3_0_wait_for_idle(void *handle);
26679899
RZ
68static int vce_v3_0_set_clockgating_state(void *handle,
69 enum amd_clockgating_state state);
aaa36a97
AD
70/**
71 * vce_v3_0_ring_get_rptr - get read pointer
72 *
73 * @ring: amdgpu_ring pointer
74 *
75 * Returns the current hardware read pointer
76 */
536fbf94 77static uint64_t vce_v3_0_ring_get_rptr(struct amdgpu_ring *ring)
aaa36a97
AD
78{
79 struct amdgpu_device *adev = ring->adev;
45cc6586
LL
80 u32 v;
81
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));
aaa36a97 88
5d4af988 89 if (ring->me == 0)
45cc6586 90 v = RREG32(mmVCE_RB_RPTR);
5d4af988 91 else if (ring->me == 1)
45cc6586 92 v = RREG32(mmVCE_RB_RPTR2);
6f0359ff 93 else
45cc6586
LL
94 v = RREG32(mmVCE_RB_RPTR3);
95
96 WREG32(mmGRBM_GFX_INDEX, mmGRBM_GFX_INDEX_DEFAULT);
97 mutex_unlock(&adev->grbm_idx_mutex);
98
99 return v;
aaa36a97
AD
100}
101
102/**
103 * vce_v3_0_ring_get_wptr - get write pointer
104 *
105 * @ring: amdgpu_ring pointer
106 *
107 * Returns the current hardware write pointer
108 */
536fbf94 109static uint64_t vce_v3_0_ring_get_wptr(struct amdgpu_ring *ring)
aaa36a97
AD
110{
111 struct amdgpu_device *adev = ring->adev;
45cc6586
LL
112 u32 v;
113
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));
aaa36a97 120
5d4af988 121 if (ring->me == 0)
45cc6586 122 v = RREG32(mmVCE_RB_WPTR);
5d4af988 123 else if (ring->me == 1)
45cc6586 124 v = RREG32(mmVCE_RB_WPTR2);
6f0359ff 125 else
45cc6586
LL
126 v = RREG32(mmVCE_RB_WPTR3);
127
128 WREG32(mmGRBM_GFX_INDEX, mmGRBM_GFX_INDEX_DEFAULT);
129 mutex_unlock(&adev->grbm_idx_mutex);
130
131 return v;
aaa36a97
AD
132}
133
134/**
135 * vce_v3_0_ring_set_wptr - set write pointer
136 *
137 * @ring: amdgpu_ring pointer
138 *
139 * Commits the write pointer to the hardware
140 */
141static void vce_v3_0_ring_set_wptr(struct amdgpu_ring *ring)
142{
143 struct amdgpu_device *adev = ring->adev;
144
45cc6586
LL
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));
151
5d4af988 152 if (ring->me == 0)
536fbf94 153 WREG32(mmVCE_RB_WPTR, lower_32_bits(ring->wptr));
5d4af988 154 else if (ring->me == 1)
536fbf94 155 WREG32(mmVCE_RB_WPTR2, lower_32_bits(ring->wptr));
6f0359ff 156 else
536fbf94 157 WREG32(mmVCE_RB_WPTR3, lower_32_bits(ring->wptr));
45cc6586
LL
158
159 WREG32(mmGRBM_GFX_INDEX, mmGRBM_GFX_INDEX_DEFAULT);
160 mutex_unlock(&adev->grbm_idx_mutex);
aaa36a97
AD
161}
162
0689a570
EH
163static void vce_v3_0_override_vce_clock_gating(struct amdgpu_device *adev, bool override)
164{
f3f0ea95 165 WREG32_FIELD(VCE_RB_ARB_CTRL, VCE_CGTT_OVERRIDE, override ? 1 : 0);
0689a570
EH
166}
167
168static void vce_v3_0_set_vce_sw_clock_gating(struct amdgpu_device *adev,
169 bool gated)
170{
f3f0ea95 171 u32 data;
f16fe6d3 172
0689a570
EH
173 /* Set Override to disable Clock Gating */
174 vce_v3_0_override_vce_clock_gating(adev, true);
175
6f906814
TSD
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
179 fly as necessary.
180 */
ecc2cf7c 181 if (!gated) {
f3f0ea95 182 data = RREG32(mmVCE_CLOCK_GATING_B);
0689a570
EH
183 data |= 0x1ff;
184 data &= ~0xef0000;
f3f0ea95 185 WREG32(mmVCE_CLOCK_GATING_B, data);
0689a570 186
f3f0ea95 187 data = RREG32(mmVCE_UENC_CLOCK_GATING);
0689a570
EH
188 data |= 0x3ff000;
189 data &= ~0xffc00000;
f3f0ea95 190 WREG32(mmVCE_UENC_CLOCK_GATING, data);
0689a570 191
f3f0ea95 192 data = RREG32(mmVCE_UENC_CLOCK_GATING_2);
0689a570 193 data |= 0x2;
6f906814 194 data &= ~0x00010000;
f3f0ea95 195 WREG32(mmVCE_UENC_CLOCK_GATING_2, data);
0689a570 196
f3f0ea95 197 data = RREG32(mmVCE_UENC_REG_CLOCK_GATING);
0689a570 198 data |= 0x37f;
f3f0ea95 199 WREG32(mmVCE_UENC_REG_CLOCK_GATING, data);
0689a570 200
f3f0ea95 201 data = RREG32(mmVCE_UENC_DMA_DCLK_CTRL);
0689a570 202 data |= VCE_UENC_DMA_DCLK_CTRL__WRDMCLK_FORCEON_MASK |
f16fe6d3
TSD
203 VCE_UENC_DMA_DCLK_CTRL__RDDMCLK_FORCEON_MASK |
204 VCE_UENC_DMA_DCLK_CTRL__REGCLK_FORCEON_MASK |
205 0x8;
f3f0ea95 206 WREG32(mmVCE_UENC_DMA_DCLK_CTRL, data);
0689a570 207 } else {
f3f0ea95 208 data = RREG32(mmVCE_CLOCK_GATING_B);
0689a570
EH
209 data &= ~0x80010;
210 data |= 0xe70008;
f3f0ea95 211 WREG32(mmVCE_CLOCK_GATING_B, data);
6f906814 212
f3f0ea95 213 data = RREG32(mmVCE_UENC_CLOCK_GATING);
0689a570 214 data |= 0xffc00000;
f3f0ea95 215 WREG32(mmVCE_UENC_CLOCK_GATING, data);
6f906814 216
f3f0ea95 217 data = RREG32(mmVCE_UENC_CLOCK_GATING_2);
0689a570 218 data |= 0x10000;
f3f0ea95 219 WREG32(mmVCE_UENC_CLOCK_GATING_2, data);
6f906814 220
f3f0ea95 221 data = RREG32(mmVCE_UENC_REG_CLOCK_GATING);
e05208de 222 data &= ~0x3ff;
f3f0ea95 223 WREG32(mmVCE_UENC_REG_CLOCK_GATING, data);
6f906814 224
f3f0ea95 225 data = RREG32(mmVCE_UENC_DMA_DCLK_CTRL);
0689a570 226 data &= ~(VCE_UENC_DMA_DCLK_CTRL__WRDMCLK_FORCEON_MASK |
f16fe6d3
TSD
227 VCE_UENC_DMA_DCLK_CTRL__RDDMCLK_FORCEON_MASK |
228 VCE_UENC_DMA_DCLK_CTRL__REGCLK_FORCEON_MASK |
229 0x8);
f3f0ea95 230 WREG32(mmVCE_UENC_DMA_DCLK_CTRL, data);
0689a570
EH
231 }
232 vce_v3_0_override_vce_clock_gating(adev, false);
233}
234
567e6e29 235static int vce_v3_0_firmware_loaded(struct amdgpu_device *adev)
236{
237 int i, j;
567e6e29 238
239 for (i = 0; i < 10; ++i) {
240 for (j = 0; j < 100; ++j) {
b7e2e9f7 241 uint32_t status = RREG32(mmVCE_STATUS);
242
567e6e29 243 if (status & VCE_STATUS_VCPU_REPORT_FW_LOADED_MASK)
244 return 0;
245 mdelay(10);
246 }
247
248 DRM_ERROR("VCE not responding, trying to reset the ECPU!!!\n");
f3f0ea95 249 WREG32_FIELD(VCE_SOFT_RESET, ECPU_SOFT_RESET, 1);
567e6e29 250 mdelay(10);
f3f0ea95 251 WREG32_FIELD(VCE_SOFT_RESET, ECPU_SOFT_RESET, 0);
567e6e29 252 mdelay(10);
253 }
254
255 return -ETIMEDOUT;
256}
257
aaa36a97
AD
258/**
259 * vce_v3_0_start - start VCE block
260 *
261 * @adev: amdgpu_device pointer
262 *
263 * Setup and start the VCE block
264 */
265static int vce_v3_0_start(struct amdgpu_device *adev)
266{
267 struct amdgpu_ring *ring;
567e6e29 268 int idx, r;
269
5bbc553a
LL
270 mutex_lock(&adev->grbm_idx_mutex);
271 for (idx = 0; idx < 2; ++idx) {
6a585777
AD
272 if (adev->vce.harvest_config & (1 << idx))
273 continue;
274
50a1ebc7 275 WREG32(mmGRBM_GFX_INDEX, GET_VCE_INSTANCE(idx));
45cc6586
LL
276
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);
286
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);
293
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);
300 }
301
5bbc553a 302 vce_v3_0_mc_resume(adev, idx);
f3f0ea95 303 WREG32_FIELD(VCE_STATUS, JOB_BUSY, 1);
567e6e29 304
3c0ff9f1
LL
305 if (adev->asic_type >= CHIP_STONEY)
306 WREG32_P(mmVCE_VCPU_CNTL, 1, ~0x200001);
307 else
f3f0ea95 308 WREG32_FIELD(VCE_VCPU_CNTL, CLK_EN, 1);
5bbc553a 309
f3f0ea95 310 WREG32_FIELD(VCE_SOFT_RESET, ECPU_SOFT_RESET, 0);
567e6e29 311 mdelay(100);
312
313 r = vce_v3_0_firmware_loaded(adev);
5bbc553a
LL
314
315 /* clear BUSY flag */
f3f0ea95 316 WREG32_FIELD(VCE_STATUS, JOB_BUSY, 0);
aaa36a97 317
5bbc553a
LL
318 if (r) {
319 DRM_ERROR("VCE not responding, giving up!!!\n");
320 mutex_unlock(&adev->grbm_idx_mutex);
321 return r;
322 }
323 }
aaa36a97 324
50a1ebc7 325 WREG32(mmGRBM_GFX_INDEX, mmGRBM_GFX_INDEX_DEFAULT);
5bbc553a 326 mutex_unlock(&adev->grbm_idx_mutex);
aaa36a97 327
567e6e29 328 return 0;
329}
aaa36a97 330
567e6e29 331static int vce_v3_0_stop(struct amdgpu_device *adev)
332{
333 int idx;
334
335 mutex_lock(&adev->grbm_idx_mutex);
336 for (idx = 0; idx < 2; ++idx) {
337 if (adev->vce.harvest_config & (1 << idx))
338 continue;
339
50a1ebc7 340 WREG32(mmGRBM_GFX_INDEX, GET_VCE_INSTANCE(idx));
567e6e29 341
342 if (adev->asic_type >= CHIP_STONEY)
343 WREG32_P(mmVCE_VCPU_CNTL, 0, ~0x200001);
344 else
f3f0ea95
TSD
345 WREG32_FIELD(VCE_VCPU_CNTL, CLK_EN, 0);
346
567e6e29 347 /* hold on ECPU */
f3f0ea95 348 WREG32_FIELD(VCE_SOFT_RESET, ECPU_SOFT_RESET, 1);
567e6e29 349
26679899
RZ
350 /* clear VCE STATUS */
351 WREG32(mmVCE_STATUS, 0);
567e6e29 352 }
353
50a1ebc7 354 WREG32(mmGRBM_GFX_INDEX, mmGRBM_GFX_INDEX_DEFAULT);
567e6e29 355 mutex_unlock(&adev->grbm_idx_mutex);
aaa36a97 356
aaa36a97
AD
357 return 0;
358}
359
6a585777
AD
360#define ixVCE_HARVEST_FUSE_MACRO__ADDRESS 0xC0014074
361#define VCE_HARVEST_FUSE_MACRO__SHIFT 27
362#define VCE_HARVEST_FUSE_MACRO__MASK 0x18000000
363
364static unsigned vce_v3_0_get_harvest_config(struct amdgpu_device *adev)
365{
366 u32 tmp;
6a585777 367
cfaba566 368 if ((adev->asic_type == CHIP_FIJI) ||
32bec2af 369 (adev->asic_type == CHIP_STONEY))
1dab5f06 370 return AMDGPU_VCE_HARVEST_VCE1;
188a9bcd 371
2f7d10b3 372 if (adev->flags & AMD_IS_APU)
6a585777
AD
373 tmp = (RREG32_SMC(ixVCE_HARVEST_FUSE_MACRO__ADDRESS) &
374 VCE_HARVEST_FUSE_MACRO__MASK) >>
375 VCE_HARVEST_FUSE_MACRO__SHIFT;
376 else
377 tmp = (RREG32_SMC(ixCC_HARVEST_FUSES) &
378 CC_HARVEST_FUSES__VCE_DISABLE_MASK) >>
379 CC_HARVEST_FUSES__VCE_DISABLE__SHIFT;
380
381 switch (tmp) {
382 case 1:
1dab5f06 383 return AMDGPU_VCE_HARVEST_VCE0;
6a585777 384 case 2:
1dab5f06 385 return AMDGPU_VCE_HARVEST_VCE1;
6a585777 386 case 3:
1dab5f06 387 return AMDGPU_VCE_HARVEST_VCE0 | AMDGPU_VCE_HARVEST_VCE1;
6a585777 388 default:
32bec2af
LL
389 if ((adev->asic_type == CHIP_POLARIS10) ||
390 (adev->asic_type == CHIP_POLARIS11) ||
a7712897
LL
391 (adev->asic_type == CHIP_POLARIS12) ||
392 (adev->asic_type == CHIP_VEGAM))
32bec2af
LL
393 return AMDGPU_VCE_HARVEST_VCE1;
394
1dab5f06 395 return 0;
6a585777 396 }
6a585777
AD
397}
398
5fc3aeeb 399static int vce_v3_0_early_init(void *handle)
aaa36a97 400{
5fc3aeeb 401 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
402
6a585777
AD
403 adev->vce.harvest_config = vce_v3_0_get_harvest_config(adev);
404
405 if ((adev->vce.harvest_config &
406 (AMDGPU_VCE_HARVEST_VCE0 | AMDGPU_VCE_HARVEST_VCE1)) ==
407 (AMDGPU_VCE_HARVEST_VCE0 | AMDGPU_VCE_HARVEST_VCE1))
408 return -ENOENT;
409
6f0359ff 410 adev->vce.num_rings = 3;
75c65480 411
aaa36a97
AD
412 vce_v3_0_set_ring_funcs(adev);
413 vce_v3_0_set_irq_funcs(adev);
414
415 return 0;
416}
417
5fc3aeeb 418static int vce_v3_0_sw_init(void *handle)
aaa36a97 419{
5fc3aeeb 420 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
aaa36a97 421 struct amdgpu_ring *ring;
75c65480 422 int r, i;
aaa36a97
AD
423
424 /* VCE */
1ffdeca6 425 r = amdgpu_irq_add_id(adev, AMDGPU_IRQ_CLIENTID_LEGACY, VISLANDS30_IV_SRCID_VCE_TRAP, &adev->vce.irq);
aaa36a97
AD
426 if (r)
427 return r;
428
e9822622
LL
429 r = amdgpu_vce_sw_init(adev, VCE_V3_0_FW_SIZE +
430 (VCE_V3_0_STACK_SIZE + VCE_V3_0_DATA_SIZE) * 2);
aaa36a97
AD
431 if (r)
432 return r;
433
ef6239e0
AD
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;
aaa36a97
AD
437
438 r = amdgpu_vce_resume(adev);
439 if (r)
440 return r;
441
75c65480 442 for (i = 0; i < adev->vce.num_rings; i++) {
080e613c
SS
443 enum amdgpu_ring_priority_level hw_prio = amdgpu_vce_get_ring_prio(i);
444
75c65480
AD
445 ring = &adev->vce.ring[i];
446 sprintf(ring->name, "vce%d", i);
1c6d567b 447 r = amdgpu_ring_init(adev, ring, 512, &adev->vce.irq, 0,
080e613c 448 hw_prio, NULL);
75c65480
AD
449 if (r)
450 return r;
451 }
aaa36a97
AD
452
453 return r;
454}
455
5fc3aeeb 456static int vce_v3_0_sw_fini(void *handle)
aaa36a97
AD
457{
458 int r;
5fc3aeeb 459 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
aaa36a97
AD
460
461 r = amdgpu_vce_suspend(adev);
462 if (r)
463 return r;
464
50237287 465 return amdgpu_vce_sw_fini(adev);
aaa36a97
AD
466}
467
5fc3aeeb 468static int vce_v3_0_hw_init(void *handle)
aaa36a97 469{
691ca86a 470 int r, i;
5fc3aeeb 471 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
aaa36a97 472
6fc11b0e 473 vce_v3_0_override_vce_clock_gating(adev, true);
08ebb6e9
RZ
474
475 amdgpu_asic_set_vce_clocks(adev, 10000, 10000);
aaa36a97 476
75c65480 477 for (i = 0; i < adev->vce.num_rings; i++) {
c66ed765 478 r = amdgpu_ring_test_helper(&adev->vce.ring[i]);
691ca86a
TSD
479 if (r)
480 return r;
aaa36a97
AD
481 }
482
483 DRM_INFO("VCE initialized successfully.\n");
484
485 return 0;
486}
487
5fc3aeeb 488static int vce_v3_0_hw_fini(void *handle)
aaa36a97 489{
567e6e29 490 int r;
491 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
492
d82e2c24
AG
493 cancel_delayed_work_sync(&adev->vce.idle_work);
494
495 r = vce_v3_0_wait_for_idle(handle);
496 if (r)
497 return r;
498
499 vce_v3_0_stop(adev);
500 return vce_v3_0_set_clockgating_state(adev, AMD_CG_STATE_GATE);
501}
502
503static int vce_v3_0_suspend(void *handle)
504{
505 int r;
506 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
507
bf756fb8
EQ
508 /*
509 * Proper cleanups before halting the HW engine:
510 * - cancel the delayed idle work
511 * - enable powergating
512 * - enable clockgating
513 * - disable dpm
514 *
515 * TODO: to align with the VCN implementation, move the
516 * jobs for clockgating/powergating/dpm setting to
517 * ->set_powergating_state().
518 */
519 cancel_delayed_work_sync(&adev->vce.idle_work);
520
521 if (adev->pm.dpm_enabled) {
522 amdgpu_dpm_enable_vce(adev, false);
523 } else {
524 amdgpu_asic_set_vce_clocks(adev, 0, 0);
525 amdgpu_device_ip_set_powergating_state(adev, AMD_IP_BLOCK_TYPE_VCE,
526 AMD_PG_STATE_GATE);
527 amdgpu_device_ip_set_clockgating_state(adev, AMD_IP_BLOCK_TYPE_VCE,
528 AMD_CG_STATE_GATE);
529 }
530
aaa36a97
AD
531 r = vce_v3_0_hw_fini(adev);
532 if (r)
533 return r;
534
50237287 535 return amdgpu_vce_suspend(adev);
aaa36a97
AD
536}
537
5fc3aeeb 538static int vce_v3_0_resume(void *handle)
aaa36a97
AD
539{
540 int r;
5fc3aeeb 541 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
aaa36a97
AD
542
543 r = amdgpu_vce_resume(adev);
544 if (r)
545 return r;
546
50237287 547 return vce_v3_0_hw_init(adev);
aaa36a97
AD
548}
549
5bbc553a 550static void vce_v3_0_mc_resume(struct amdgpu_device *adev, int idx)
aaa36a97
AD
551{
552 uint32_t offset, size;
553
554 WREG32_P(mmVCE_CLOCK_GATING_A, 0, ~(1 << 16));
555 WREG32_P(mmVCE_UENC_CLOCK_GATING, 0x1FF000, ~0xFF9FF000);
556 WREG32_P(mmVCE_UENC_REG_CLOCK_GATING, 0x3F, ~0x3F);
6f906814 557 WREG32(mmVCE_CLOCK_GATING_B, 0x1FF);
aaa36a97
AD
558
559 WREG32(mmVCE_LMI_CTRL, 0x00398000);
560 WREG32_P(mmVCE_LMI_CACHE_CTRL, 0x0, ~0x1);
561 WREG32(mmVCE_LMI_SWAP_CNTL, 0);
562 WREG32(mmVCE_LMI_SWAP_CNTL1, 0);
563 WREG32(mmVCE_LMI_VM_CTRL, 0);
d50e5c24
AH
564 WREG32_OR(mmVCE_VCPU_CNTL, 0x00100000);
565
3c0ff9f1
LL
566 if (adev->asic_type >= CHIP_STONEY) {
567 WREG32(mmVCE_LMI_VCPU_CACHE_40BIT_BAR0, (adev->vce.gpu_addr >> 8));
568 WREG32(mmVCE_LMI_VCPU_CACHE_40BIT_BAR1, (adev->vce.gpu_addr >> 8));
569 WREG32(mmVCE_LMI_VCPU_CACHE_40BIT_BAR2, (adev->vce.gpu_addr >> 8));
570 } else
571 WREG32(mmVCE_LMI_VCPU_CACHE_40BIT_BAR, (adev->vce.gpu_addr >> 8));
aaa36a97 572 offset = AMDGPU_VCE_FIRMWARE_OFFSET;
e9822622 573 size = VCE_V3_0_FW_SIZE;
aaa36a97
AD
574 WREG32(mmVCE_VCPU_CACHE_OFFSET0, offset & 0x7fffffff);
575 WREG32(mmVCE_VCPU_CACHE_SIZE0, size);
576
5bbc553a
LL
577 if (idx == 0) {
578 offset += size;
579 size = VCE_V3_0_STACK_SIZE;
580 WREG32(mmVCE_VCPU_CACHE_OFFSET1, offset & 0x7fffffff);
581 WREG32(mmVCE_VCPU_CACHE_SIZE1, size);
582 offset += size;
583 size = VCE_V3_0_DATA_SIZE;
584 WREG32(mmVCE_VCPU_CACHE_OFFSET2, offset & 0x7fffffff);
585 WREG32(mmVCE_VCPU_CACHE_SIZE2, size);
586 } else {
587 offset += size + VCE_V3_0_STACK_SIZE + VCE_V3_0_DATA_SIZE;
588 size = VCE_V3_0_STACK_SIZE;
589 WREG32(mmVCE_VCPU_CACHE_OFFSET1, offset & 0xfffffff);
590 WREG32(mmVCE_VCPU_CACHE_SIZE1, size);
591 offset += size;
592 size = VCE_V3_0_DATA_SIZE;
593 WREG32(mmVCE_VCPU_CACHE_OFFSET2, offset & 0xfffffff);
594 WREG32(mmVCE_VCPU_CACHE_SIZE2, size);
595 }
aaa36a97
AD
596
597 WREG32_P(mmVCE_LMI_CTRL2, 0x0, ~0x100);
f3f0ea95 598 WREG32_FIELD(VCE_SYS_INT_EN, VCE_SYS_INT_TRAP_INTERRUPT_EN, 1);
aaa36a97
AD
599}
600
5fc3aeeb 601static bool vce_v3_0_is_idle(void *handle)
aaa36a97 602{
5fc3aeeb 603 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
be4f38e2 604 u32 mask = 0;
be4f38e2 605
74af1276
TSD
606 mask |= (adev->vce.harvest_config & AMDGPU_VCE_HARVEST_VCE0) ? 0 : SRBM_STATUS2__VCE0_BUSY_MASK;
607 mask |= (adev->vce.harvest_config & AMDGPU_VCE_HARVEST_VCE1) ? 0 : SRBM_STATUS2__VCE1_BUSY_MASK;
be4f38e2
AD
608
609 return !(RREG32(mmSRBM_STATUS2) & mask);
aaa36a97
AD
610}
611
5fc3aeeb 612static int vce_v3_0_wait_for_idle(void *handle)
aaa36a97
AD
613{
614 unsigned i;
5fc3aeeb 615 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
be4f38e2 616
92988e60
TSD
617 for (i = 0; i < adev->usec_timeout; i++)
618 if (vce_v3_0_is_idle(handle))
aaa36a97 619 return 0;
92988e60 620
aaa36a97
AD
621 return -ETIMEDOUT;
622}
623
ac8e3f30
RZ
624#define VCE_STATUS_VCPU_REPORT_AUTO_BUSY_MASK 0x00000008L /* AUTO_BUSY */
625#define VCE_STATUS_VCPU_REPORT_RB0_BUSY_MASK 0x00000010L /* RB0_BUSY */
626#define VCE_STATUS_VCPU_REPORT_RB1_BUSY_MASK 0x00000020L /* RB1_BUSY */
627#define AMDGPU_VCE_STATUS_BUSY_MASK (VCE_STATUS_VCPU_REPORT_AUTO_BUSY_MASK | \
628 VCE_STATUS_VCPU_REPORT_RB0_BUSY_MASK)
115933a5 629
da146d3b 630static bool vce_v3_0_check_soft_reset(void *handle)
115933a5
CZ
631{
632 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
633 u32 srbm_soft_reset = 0;
115933a5 634
115933a5
CZ
635 /* According to VCE team , we should use VCE_STATUS instead
636 * SRBM_STATUS.VCE_BUSY bit for busy status checking.
637 * GRBM_GFX_INDEX.INSTANCE_INDEX is used to specify which VCE
638 * instance's registers are accessed
639 * (0 for 1st instance, 10 for 2nd instance).
640 *
641 *VCE_STATUS
642 *|UENC|ACPI|AUTO ACTIVE|RB1 |RB0 |RB2 | |FW_LOADED|JOB |
643 *|----+----+-----------+----+----+----+----------+---------+----|
644 *|bit8|bit7| bit6 |bit5|bit4|bit3| bit2 | bit1 |bit0|
645 *
646 * VCE team suggest use bit 3--bit 6 for busy status check
647 */
9aeb774c 648 mutex_lock(&adev->grbm_idx_mutex);
50a1ebc7 649 WREG32(mmGRBM_GFX_INDEX, GET_VCE_INSTANCE(0));
115933a5
CZ
650 if (RREG32(mmVCE_STATUS) & AMDGPU_VCE_STATUS_BUSY_MASK) {
651 srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET, SOFT_RESET_VCE0, 1);
652 srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET, SOFT_RESET_VCE1, 1);
653 }
50a1ebc7 654 WREG32(mmGRBM_GFX_INDEX, GET_VCE_INSTANCE(1));
115933a5
CZ
655 if (RREG32(mmVCE_STATUS) & AMDGPU_VCE_STATUS_BUSY_MASK) {
656 srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET, SOFT_RESET_VCE0, 1);
657 srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET, SOFT_RESET_VCE1, 1);
658 }
50a1ebc7 659 WREG32(mmGRBM_GFX_INDEX, GET_VCE_INSTANCE(0));
da146d3b 660 mutex_unlock(&adev->grbm_idx_mutex);
115933a5 661
115933a5 662 if (srbm_soft_reset) {
115933a5 663 adev->vce.srbm_soft_reset = srbm_soft_reset;
da146d3b 664 return true;
115933a5 665 } else {
115933a5 666 adev->vce.srbm_soft_reset = 0;
da146d3b 667 return false;
115933a5 668 }
115933a5
CZ
669}
670
5fc3aeeb 671static int vce_v3_0_soft_reset(void *handle)
aaa36a97 672{
5fc3aeeb 673 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
115933a5
CZ
674 u32 srbm_soft_reset;
675
da146d3b 676 if (!adev->vce.srbm_soft_reset)
115933a5
CZ
677 return 0;
678 srbm_soft_reset = adev->vce.srbm_soft_reset;
679
680 if (srbm_soft_reset) {
681 u32 tmp;
be4f38e2 682
115933a5
CZ
683 tmp = RREG32(mmSRBM_SOFT_RESET);
684 tmp |= srbm_soft_reset;
685 dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
686 WREG32(mmSRBM_SOFT_RESET, tmp);
687 tmp = RREG32(mmSRBM_SOFT_RESET);
688
689 udelay(50);
690
691 tmp &= ~srbm_soft_reset;
692 WREG32(mmSRBM_SOFT_RESET, tmp);
693 tmp = RREG32(mmSRBM_SOFT_RESET);
694
695 /* Wait a little for things to settle down */
696 udelay(50);
697 }
698
699 return 0;
700}
701
702static int vce_v3_0_pre_soft_reset(void *handle)
703{
704 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
705
da146d3b 706 if (!adev->vce.srbm_soft_reset)
115933a5
CZ
707 return 0;
708
709 mdelay(5);
710
711 return vce_v3_0_suspend(adev);
712}
713
714
715static int vce_v3_0_post_soft_reset(void *handle)
716{
717 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
718
da146d3b 719 if (!adev->vce.srbm_soft_reset)
115933a5 720 return 0;
5fc3aeeb 721
aaa36a97
AD
722 mdelay(5);
723
115933a5 724 return vce_v3_0_resume(adev);
aaa36a97
AD
725}
726
aaa36a97
AD
727static int vce_v3_0_set_interrupt_state(struct amdgpu_device *adev,
728 struct amdgpu_irq_src *source,
729 unsigned type,
730 enum amdgpu_interrupt_state state)
731{
732 uint32_t val = 0;
733
734 if (state == AMDGPU_IRQ_STATE_ENABLE)
735 val |= VCE_SYS_INT_EN__VCE_SYS_INT_TRAP_INTERRUPT_EN_MASK;
736
737 WREG32_P(mmVCE_SYS_INT_EN, val, ~VCE_SYS_INT_EN__VCE_SYS_INT_TRAP_INTERRUPT_EN_MASK);
738 return 0;
739}
740
741static int vce_v3_0_process_interrupt(struct amdgpu_device *adev,
742 struct amdgpu_irq_src *source,
743 struct amdgpu_iv_entry *entry)
744{
745 DRM_DEBUG("IH: VCE\n");
d6c29c30 746
f3f0ea95 747 WREG32_FIELD(VCE_SYS_INT_STATUS, VCE_SYS_INT_TRAP_INTERRUPT_INT, 1);
d6c29c30 748
7ccf5aa8 749 switch (entry->src_data[0]) {
aaa36a97 750 case 0:
aaa36a97 751 case 1:
6f0359ff 752 case 2:
7ccf5aa8 753 amdgpu_fence_process(&adev->vce.ring[entry->src_data[0]]);
aaa36a97
AD
754 break;
755 default:
756 DRM_ERROR("Unhandled interrupt: %d %d\n",
7ccf5aa8 757 entry->src_id, entry->src_data[0]);
aaa36a97
AD
758 break;
759 }
760
761 return 0;
762}
763
5fc3aeeb 764static int vce_v3_0_set_clockgating_state(void *handle,
765 enum amd_clockgating_state state)
aaa36a97 766{
0689a570 767 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
a9d4fe2f 768 bool enable = (state == AMD_CG_STATE_GATE);
0689a570
EH
769 int i;
770
e3b04bc7 771 if (!(adev->cg_flags & AMD_CG_SUPPORT_VCE_MGCG))
0689a570
EH
772 return 0;
773
774 mutex_lock(&adev->grbm_idx_mutex);
775 for (i = 0; i < 2; i++) {
776 /* Program VCE Instance 0 or 1 if not harvested */
777 if (adev->vce.harvest_config & (1 << i))
778 continue;
779
50a1ebc7 780 WREG32(mmGRBM_GFX_INDEX, GET_VCE_INSTANCE(i));
0689a570 781
26679899 782 if (!enable) {
0689a570
EH
783 /* initialize VCE_CLOCK_GATING_A: Clock ON/OFF delay */
784 uint32_t data = RREG32(mmVCE_CLOCK_GATING_A);
785 data &= ~(0xf | 0xff0);
786 data |= ((0x0 << 0) | (0x04 << 4));
787 WREG32(mmVCE_CLOCK_GATING_A, data);
788
789 /* initialize VCE_UENC_CLOCK_GATING: Clock ON/OFF delay */
790 data = RREG32(mmVCE_UENC_CLOCK_GATING);
791 data &= ~(0xf | 0xff0);
792 data |= ((0x0 << 0) | (0x04 << 4));
793 WREG32(mmVCE_UENC_CLOCK_GATING, data);
794 }
795
796 vce_v3_0_set_vce_sw_clock_gating(adev, enable);
797 }
798
50a1ebc7 799 WREG32(mmGRBM_GFX_INDEX, mmGRBM_GFX_INDEX_DEFAULT);
0689a570
EH
800 mutex_unlock(&adev->grbm_idx_mutex);
801
aaa36a97
AD
802 return 0;
803}
804
5fc3aeeb 805static int vce_v3_0_set_powergating_state(void *handle,
806 enum amd_powergating_state state)
aaa36a97
AD
807{
808 /* This doesn't actually powergate the VCE block.
809 * That's done in the dpm code via the SMC. This
810 * just re-inits the block as necessary. The actual
811 * gating still happens in the dpm code. We should
812 * revisit this when there is a cleaner line between
813 * the smc and the hw blocks
814 */
5fc3aeeb 815 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
c79b5561 816 int ret = 0;
5fc3aeeb 817
c79b5561 818 if (state == AMD_PG_STATE_GATE) {
6fc11b0e
RZ
819 ret = vce_v3_0_stop(adev);
820 if (ret)
821 goto out;
c79b5561
HR
822 } else {
823 ret = vce_v3_0_start(adev);
824 if (ret)
825 goto out;
c79b5561
HR
826 }
827
828out:
829 return ret;
830}
831
25faeddc 832static void vce_v3_0_get_clockgating_state(void *handle, u64 *flags)
c79b5561
HR
833{
834 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
835 int data;
836
837 mutex_lock(&adev->pm.mutex);
838
1c622002
RZ
839 if (adev->flags & AMD_IS_APU)
840 data = RREG32_SMC(ixCURRENT_PG_STATUS_APU);
841 else
842 data = RREG32_SMC(ixCURRENT_PG_STATUS);
843
844 if (data & CURRENT_PG_STATUS__VCE_PG_STATUS_MASK) {
c79b5561
HR
845 DRM_INFO("Cannot get clockgating state when VCE is powergated.\n");
846 goto out;
847 }
848
849 WREG32_FIELD(GRBM_GFX_INDEX, VCE_INSTANCE, 0);
850
851 /* AMD_CG_SUPPORT_VCE_MGCG */
852 data = RREG32(mmVCE_CLOCK_GATING_A);
853 if (data & (0x04 << 4))
854 *flags |= AMD_CG_SUPPORT_VCE_MGCG;
855
856out:
857 mutex_unlock(&adev->pm.mutex);
aaa36a97
AD
858}
859
ea4a8c1d 860static void vce_v3_0_ring_emit_ib(struct amdgpu_ring *ring,
34955e03
RZ
861 struct amdgpu_job *job,
862 struct amdgpu_ib *ib,
c4c905ec 863 uint32_t flags)
ea4a8c1d 864{
34955e03
RZ
865 unsigned vmid = AMDGPU_JOB_GET_VMID(job);
866
ea4a8c1d 867 amdgpu_ring_write(ring, VCE_CMD_IB_VM);
c4f46f22 868 amdgpu_ring_write(ring, vmid);
ea4a8c1d
MSB
869 amdgpu_ring_write(ring, lower_32_bits(ib->gpu_addr));
870 amdgpu_ring_write(ring, upper_32_bits(ib->gpu_addr));
871 amdgpu_ring_write(ring, ib->length_dw);
872}
873
874static void vce_v3_0_emit_vm_flush(struct amdgpu_ring *ring,
c633c00b 875 unsigned int vmid, uint64_t pd_addr)
ea4a8c1d
MSB
876{
877 amdgpu_ring_write(ring, VCE_CMD_UPDATE_PTB);
c4f46f22 878 amdgpu_ring_write(ring, vmid);
ea4a8c1d
MSB
879 amdgpu_ring_write(ring, pd_addr >> 12);
880
881 amdgpu_ring_write(ring, VCE_CMD_FLUSH_TLB);
c4f46f22 882 amdgpu_ring_write(ring, vmid);
ea4a8c1d
MSB
883 amdgpu_ring_write(ring, VCE_CMD_END);
884}
885
886static void vce_v3_0_emit_pipeline_sync(struct amdgpu_ring *ring)
887{
888 uint32_t seq = ring->fence_drv.sync_seq;
889 uint64_t addr = ring->fence_drv.gpu_addr;
890
891 amdgpu_ring_write(ring, VCE_CMD_WAIT_GE);
892 amdgpu_ring_write(ring, lower_32_bits(addr));
893 amdgpu_ring_write(ring, upper_32_bits(addr));
894 amdgpu_ring_write(ring, seq);
895}
896
a1255107 897static const struct amd_ip_funcs vce_v3_0_ip_funcs = {
88a907d6 898 .name = "vce_v3_0",
aaa36a97
AD
899 .early_init = vce_v3_0_early_init,
900 .late_init = NULL,
901 .sw_init = vce_v3_0_sw_init,
902 .sw_fini = vce_v3_0_sw_fini,
903 .hw_init = vce_v3_0_hw_init,
904 .hw_fini = vce_v3_0_hw_fini,
905 .suspend = vce_v3_0_suspend,
906 .resume = vce_v3_0_resume,
907 .is_idle = vce_v3_0_is_idle,
908 .wait_for_idle = vce_v3_0_wait_for_idle,
115933a5
CZ
909 .check_soft_reset = vce_v3_0_check_soft_reset,
910 .pre_soft_reset = vce_v3_0_pre_soft_reset,
aaa36a97 911 .soft_reset = vce_v3_0_soft_reset,
115933a5 912 .post_soft_reset = vce_v3_0_post_soft_reset,
aaa36a97
AD
913 .set_clockgating_state = vce_v3_0_set_clockgating_state,
914 .set_powergating_state = vce_v3_0_set_powergating_state,
c79b5561 915 .get_clockgating_state = vce_v3_0_get_clockgating_state,
aaa36a97
AD
916};
917
ea4a8c1d 918static const struct amdgpu_ring_funcs vce_v3_0_ring_phys_funcs = {
21cd942e 919 .type = AMDGPU_RING_TYPE_VCE,
79887142
CK
920 .align_mask = 0xf,
921 .nop = VCE_CMD_NO_OP,
536fbf94 922 .support_64bit_ptrs = false,
f61334b5 923 .no_user_fence = true,
aaa36a97
AD
924 .get_rptr = vce_v3_0_ring_get_rptr,
925 .get_wptr = vce_v3_0_ring_get_wptr,
926 .set_wptr = vce_v3_0_ring_set_wptr,
927 .parse_cs = amdgpu_vce_ring_parse_cs,
e12f3d7a
CK
928 .emit_frame_size =
929 4 + /* vce_v3_0_emit_pipeline_sync */
930 6, /* amdgpu_vce_ring_emit_fence x1 no user fence */
3413accb 931 .emit_ib_size = 4, /* amdgpu_vce_ring_emit_ib */
aaa36a97
AD
932 .emit_ib = amdgpu_vce_ring_emit_ib,
933 .emit_fence = amdgpu_vce_ring_emit_fence,
aaa36a97
AD
934 .test_ring = amdgpu_vce_ring_test_ring,
935 .test_ib = amdgpu_vce_ring_test_ib,
edff0e28 936 .insert_nop = amdgpu_ring_insert_nop,
9e5d5309 937 .pad_ib = amdgpu_ring_generic_pad_ib,
ebff485e
CK
938 .begin_use = amdgpu_vce_ring_begin_use,
939 .end_use = amdgpu_vce_ring_end_use,
aaa36a97
AD
940};
941
ea4a8c1d 942static const struct amdgpu_ring_funcs vce_v3_0_ring_vm_funcs = {
21cd942e 943 .type = AMDGPU_RING_TYPE_VCE,
79887142
CK
944 .align_mask = 0xf,
945 .nop = VCE_CMD_NO_OP,
536fbf94 946 .support_64bit_ptrs = false,
f61334b5 947 .no_user_fence = true,
ea4a8c1d
MSB
948 .get_rptr = vce_v3_0_ring_get_rptr,
949 .get_wptr = vce_v3_0_ring_get_wptr,
950 .set_wptr = vce_v3_0_ring_set_wptr,
98614701 951 .parse_cs = amdgpu_vce_ring_parse_cs_vm,
e12f3d7a
CK
952 .emit_frame_size =
953 6 + /* vce_v3_0_emit_vm_flush */
954 4 + /* vce_v3_0_emit_pipeline_sync */
955 6 + 6, /* amdgpu_vce_ring_emit_fence x2 vm fence */
3413accb 956 .emit_ib_size = 5, /* vce_v3_0_ring_emit_ib */
ea4a8c1d
MSB
957 .emit_ib = vce_v3_0_ring_emit_ib,
958 .emit_vm_flush = vce_v3_0_emit_vm_flush,
959 .emit_pipeline_sync = vce_v3_0_emit_pipeline_sync,
960 .emit_fence = amdgpu_vce_ring_emit_fence,
961 .test_ring = amdgpu_vce_ring_test_ring,
962 .test_ib = amdgpu_vce_ring_test_ib,
963 .insert_nop = amdgpu_ring_insert_nop,
964 .pad_ib = amdgpu_ring_generic_pad_ib,
965 .begin_use = amdgpu_vce_ring_begin_use,
966 .end_use = amdgpu_vce_ring_end_use,
967};
968
aaa36a97
AD
969static void vce_v3_0_set_ring_funcs(struct amdgpu_device *adev)
970{
75c65480
AD
971 int i;
972
ea4a8c1d 973 if (adev->asic_type >= CHIP_STONEY) {
5d4af988 974 for (i = 0; i < adev->vce.num_rings; i++) {
ea4a8c1d 975 adev->vce.ring[i].funcs = &vce_v3_0_ring_vm_funcs;
5d4af988
AD
976 adev->vce.ring[i].me = i;
977 }
ea4a8c1d
MSB
978 DRM_INFO("VCE enabled in VM mode\n");
979 } else {
5d4af988 980 for (i = 0; i < adev->vce.num_rings; i++) {
ea4a8c1d 981 adev->vce.ring[i].funcs = &vce_v3_0_ring_phys_funcs;
5d4af988
AD
982 adev->vce.ring[i].me = i;
983 }
ea4a8c1d
MSB
984 DRM_INFO("VCE enabled in physical mode\n");
985 }
aaa36a97
AD
986}
987
988static const struct amdgpu_irq_src_funcs vce_v3_0_irq_funcs = {
989 .set = vce_v3_0_set_interrupt_state,
990 .process = vce_v3_0_process_interrupt,
991};
992
993static void vce_v3_0_set_irq_funcs(struct amdgpu_device *adev)
994{
995 adev->vce.irq.num_types = 1;
996 adev->vce.irq.funcs = &vce_v3_0_irq_funcs;
997};
a1255107 998
042a70e4 999const struct amdgpu_ip_block_version vce_v3_0_ip_block = {
a1255107
AD
1000 .type = AMD_IP_BLOCK_TYPE_VCE,
1001 .major = 3,
1002 .minor = 0,
1003 .rev = 0,
1004 .funcs = &vce_v3_0_ip_funcs,
1005};
1006
042a70e4 1007const struct amdgpu_ip_block_version vce_v3_1_ip_block = {
a1255107
AD
1008 .type = AMD_IP_BLOCK_TYPE_VCE,
1009 .major = 3,
1010 .minor = 1,
1011 .rev = 0,
1012 .funcs = &vce_v3_0_ip_funcs,
1013};
1014
042a70e4 1015const struct amdgpu_ip_block_version vce_v3_4_ip_block = {
a1255107
AD
1016 .type = AMD_IP_BLOCK_TYPE_VCE,
1017 .major = 3,
1018 .minor = 4,
1019 .rev = 0,
1020 .funcs = &vce_v3_0_ip_funcs,
1021};