Bug Summary

File:dev/pci/drm/amd/amdgpu/uvd_v6_0.c
Warning:line 1189, column 3
Value stored to 'tmp' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name uvd_v6_0.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -ffreestanding -mcmodel=kernel -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -target-feature -sse2 -target-feature -sse -target-feature -3dnow -target-feature -mmx -target-feature +save-args -disable-red-zone -no-implicit-float -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/sys/arch/amd64/compile/GENERIC.MP/obj -nostdsysteminc -nobuiltininc -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/sys -I /usr/src/sys/arch/amd64/compile/GENERIC.MP/obj -I /usr/src/sys/arch -I /usr/src/sys/dev/pci/drm/include -I /usr/src/sys/dev/pci/drm/include/uapi -I /usr/src/sys/dev/pci/drm/amd/include/asic_reg -I /usr/src/sys/dev/pci/drm/amd/include -I /usr/src/sys/dev/pci/drm/amd/amdgpu -I /usr/src/sys/dev/pci/drm/amd/display -I /usr/src/sys/dev/pci/drm/amd/display/include -I /usr/src/sys/dev/pci/drm/amd/display/dc -I /usr/src/sys/dev/pci/drm/amd/display/amdgpu_dm -I /usr/src/sys/dev/pci/drm/amd/pm/inc -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/smu11 -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/smu12 -I /usr/src/sys/dev/pci/drm/amd/pm/powerplay -I /usr/src/sys/dev/pci/drm/amd/pm/powerplay/hwmgr -I /usr/src/sys/dev/pci/drm/amd/pm/powerplay/smumgr -I /usr/src/sys/dev/pci/drm/amd/display/dc/inc -I /usr/src/sys/dev/pci/drm/amd/display/dc/inc/hw -I /usr/src/sys/dev/pci/drm/amd/display/dc/clk_mgr -I /usr/src/sys/dev/pci/drm/amd/display/modules/inc -I /usr/src/sys/dev/pci/drm/amd/display/modules/hdcp -I /usr/src/sys/dev/pci/drm/amd/display/dmub/inc -I /usr/src/sys/dev/pci/drm/i915 -D DDB -D DIAGNOSTIC -D KTRACE -D ACCOUNTING -D KMEMSTATS -D PTRACE -D POOL_DEBUG -D CRYPTO -D SYSVMSG -D SYSVSEM -D SYSVSHM -D UVM_SWAP_ENCRYPT -D FFS -D FFS2 -D FFS_SOFTUPDATES -D UFS_DIRHASH -D QUOTA -D EXT2FS -D MFS -D NFSCLIENT -D NFSSERVER -D CD9660 -D UDF -D MSDOSFS -D FIFO -D FUSE -D SOCKET_SPLICE -D TCP_ECN -D TCP_SIGNATURE -D INET6 -D IPSEC -D PPP_BSDCOMP -D PPP_DEFLATE -D PIPEX -D MROUTING -D MPLS -D BOOT_CONFIG -D USER_PCICONF -D APERTURE -D MTRR -D NTFS -D HIBERNATE -D PCIVERBOSE -D USBVERBOSE -D WSDISPLAY_COMPAT_USL -D WSDISPLAY_COMPAT_RAWKBD -D WSDISPLAY_DEFAULTSCREENS=6 -D X86EMU -D ONEWIREVERBOSE -D MULTIPROCESSOR -D MAXUSERS=80 -D _KERNEL -D CONFIG_DRM_AMD_DC_DCN3_0 -O2 -Wno-pointer-sign -Wno-address-of-packed-member -Wno-constant-conversion -Wno-unused-but-set-variable -Wno-gnu-folding-constant -fdebug-compilation-dir=/usr/src/sys/arch/amd64/compile/GENERIC.MP/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -o /usr/obj/sys/arch/amd64/compile/GENERIC.MP/scan-build/2022-01-12-131800-47421-1 -x c /usr/src/sys/dev/pci/drm/amd/amdgpu/uvd_v6_0.c
1/*
2 * Copyright 2014 Advanced Micro Devices, Inc.
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
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.
21 *
22 * Authors: Christian König <christian.koenig@amd.com>
23 */
24
25#include <linux/firmware.h>
26
27#include "amdgpu.h"
28#include "amdgpu_uvd.h"
29#include "vid.h"
30#include "uvd/uvd_6_0_d.h"
31#include "uvd/uvd_6_0_sh_mask.h"
32#include "oss/oss_2_0_d.h"
33#include "oss/oss_2_0_sh_mask.h"
34#include "smu/smu_7_1_3_d.h"
35#include "smu/smu_7_1_3_sh_mask.h"
36#include "bif/bif_5_1_d.h"
37#include "gmc/gmc_8_1_d.h"
38#include "vi.h"
39#include "ivsrcid/ivsrcid_vislands30.h"
40
41/* Polaris10/11/12 firmware version */
42#define FW_1_130_16((1 << 24) | (130 << 16) | (16 << 8)) ((1 << 24) | (130 << 16) | (16 << 8))
43
44static void uvd_v6_0_set_ring_funcs(struct amdgpu_device *adev);
45static void uvd_v6_0_set_enc_ring_funcs(struct amdgpu_device *adev);
46
47static void uvd_v6_0_set_irq_funcs(struct amdgpu_device *adev);
48static int uvd_v6_0_start(struct amdgpu_device *adev);
49static void uvd_v6_0_stop(struct amdgpu_device *adev);
50static void uvd_v6_0_set_sw_clock_gating(struct amdgpu_device *adev);
51static int uvd_v6_0_set_clockgating_state(void *handle,
52 enum amd_clockgating_state state);
53static void uvd_v6_0_enable_mgcg(struct amdgpu_device *adev,
54 bool_Bool enable);
55
56/**
57* uvd_v6_0_enc_support - get encode support status
58*
59* @adev: amdgpu_device pointer
60*
61* Returns the current hardware encode support status
62*/
63static inline bool_Bool uvd_v6_0_enc_support(struct amdgpu_device *adev)
64{
65 return ((adev->asic_type >= CHIP_POLARIS10) &&
66 (adev->asic_type <= CHIP_VEGAM) &&
67 (!adev->uvd.fw_version || adev->uvd.fw_version >= FW_1_130_16((1 << 24) | (130 << 16) | (16 << 8))));
68}
69
70/**
71 * uvd_v6_0_ring_get_rptr - get read pointer
72 *
73 * @ring: amdgpu_ring pointer
74 *
75 * Returns the current hardware read pointer
76 */
77static uint64_t uvd_v6_0_ring_get_rptr(struct amdgpu_ring *ring)
78{
79 struct amdgpu_device *adev = ring->adev;
80
81 return RREG32(mmUVD_RBC_RB_RPTR)amdgpu_device_rreg(adev, (0x3da4), 0);
82}
83
84/**
85 * uvd_v6_0_enc_ring_get_rptr - get enc read pointer
86 *
87 * @ring: amdgpu_ring pointer
88 *
89 * Returns the current hardware enc read pointer
90 */
91static uint64_t uvd_v6_0_enc_ring_get_rptr(struct amdgpu_ring *ring)
92{
93 struct amdgpu_device *adev = ring->adev;
94
95 if (ring == &adev->uvd.inst->ring_enc[0])
96 return RREG32(mmUVD_RB_RPTR)amdgpu_device_rreg(adev, (0x3c29), 0);
97 else
98 return RREG32(mmUVD_RB_RPTR2)amdgpu_device_rreg(adev, (0x3c24), 0);
99}
100/**
101 * uvd_v6_0_ring_get_wptr - get write pointer
102 *
103 * @ring: amdgpu_ring pointer
104 *
105 * Returns the current hardware write pointer
106 */
107static uint64_t uvd_v6_0_ring_get_wptr(struct amdgpu_ring *ring)
108{
109 struct amdgpu_device *adev = ring->adev;
110
111 return RREG32(mmUVD_RBC_RB_WPTR)amdgpu_device_rreg(adev, (0x3da5), 0);
112}
113
114/**
115 * uvd_v6_0_enc_ring_get_wptr - get enc write pointer
116 *
117 * @ring: amdgpu_ring pointer
118 *
119 * Returns the current hardware enc write pointer
120 */
121static uint64_t uvd_v6_0_enc_ring_get_wptr(struct amdgpu_ring *ring)
122{
123 struct amdgpu_device *adev = ring->adev;
124
125 if (ring == &adev->uvd.inst->ring_enc[0])
126 return RREG32(mmUVD_RB_WPTR)amdgpu_device_rreg(adev, (0x3c2a), 0);
127 else
128 return RREG32(mmUVD_RB_WPTR2)amdgpu_device_rreg(adev, (0x3c25), 0);
129}
130
131/**
132 * uvd_v6_0_ring_set_wptr - set write pointer
133 *
134 * @ring: amdgpu_ring pointer
135 *
136 * Commits the write pointer to the hardware
137 */
138static void uvd_v6_0_ring_set_wptr(struct amdgpu_ring *ring)
139{
140 struct amdgpu_device *adev = ring->adev;
141
142 WREG32(mmUVD_RBC_RB_WPTR, lower_32_bits(ring->wptr))amdgpu_device_wreg(adev, (0x3da5), (((u32)(ring->wptr))), 0
)
;
143}
144
145/**
146 * uvd_v6_0_enc_ring_set_wptr - set enc write pointer
147 *
148 * @ring: amdgpu_ring pointer
149 *
150 * Commits the enc write pointer to the hardware
151 */
152static void uvd_v6_0_enc_ring_set_wptr(struct amdgpu_ring *ring)
153{
154 struct amdgpu_device *adev = ring->adev;
155
156 if (ring == &adev->uvd.inst->ring_enc[0])
157 WREG32(mmUVD_RB_WPTR,amdgpu_device_wreg(adev, (0x3c2a), (((u32)(ring->wptr))), 0
)
158 lower_32_bits(ring->wptr))amdgpu_device_wreg(adev, (0x3c2a), (((u32)(ring->wptr))), 0
)
;
159 else
160 WREG32(mmUVD_RB_WPTR2,amdgpu_device_wreg(adev, (0x3c25), (((u32)(ring->wptr))), 0
)
161 lower_32_bits(ring->wptr))amdgpu_device_wreg(adev, (0x3c25), (((u32)(ring->wptr))), 0
)
;
162}
163
164/**
165 * uvd_v6_0_enc_ring_test_ring - test if UVD ENC ring is working
166 *
167 * @ring: the engine to test on
168 *
169 */
170static int uvd_v6_0_enc_ring_test_ring(struct amdgpu_ring *ring)
171{
172 struct amdgpu_device *adev = ring->adev;
173 uint32_t rptr;
174 unsigned i;
175 int r;
176
177 r = amdgpu_ring_alloc(ring, 16);
178 if (r)
179 return r;
180
181 rptr = amdgpu_ring_get_rptr(ring)(ring)->funcs->get_rptr((ring));
182
183 amdgpu_ring_write(ring, HEVC_ENC_CMD_END0x00000001);
184 amdgpu_ring_commit(ring);
185
186 for (i = 0; i < adev->usec_timeout; i++) {
187 if (amdgpu_ring_get_rptr(ring)(ring)->funcs->get_rptr((ring)) != rptr)
188 break;
189 udelay(1);
190 }
191
192 if (i >= adev->usec_timeout)
193 r = -ETIMEDOUT60;
194
195 return r;
196}
197
198/**
199 * uvd_v6_0_enc_get_create_msg - generate a UVD ENC create msg
200 *
201 * @adev: amdgpu_device pointer
202 * @ring: ring we should submit the msg to
203 * @handle: session handle to use
204 * @fence: optional fence to return
205 *
206 * Open up a stream for HW test
207 */
208static int uvd_v6_0_enc_get_create_msg(struct amdgpu_ring *ring, uint32_t handle,
209 struct amdgpu_bo *bo,
210 struct dma_fence **fence)
211{
212 const unsigned ib_size_dw = 16;
213 struct amdgpu_job *job;
214 struct amdgpu_ib *ib;
215 struct dma_fence *f = NULL((void *)0);
216 uint64_t addr;
217 int i, r;
218
219 r = amdgpu_job_alloc_with_ib(ring->adev, ib_size_dw * 4,
220 AMDGPU_IB_POOL_DIRECT, &job);
221 if (r)
222 return r;
223
224 ib = &job->ibs[0];
225 addr = amdgpu_bo_gpu_offset(bo);
226
227 ib->length_dw = 0;
228 ib->ptr[ib->length_dw++] = 0x00000018;
229 ib->ptr[ib->length_dw++] = 0x00000001; /* session info */
230 ib->ptr[ib->length_dw++] = handle;
231 ib->ptr[ib->length_dw++] = 0x00010000;
232 ib->ptr[ib->length_dw++] = upper_32_bits(addr)((u32)(((addr) >> 16) >> 16));
233 ib->ptr[ib->length_dw++] = addr;
234
235 ib->ptr[ib->length_dw++] = 0x00000014;
236 ib->ptr[ib->length_dw++] = 0x00000002; /* task info */
237 ib->ptr[ib->length_dw++] = 0x0000001c;
238 ib->ptr[ib->length_dw++] = 0x00000001;
239 ib->ptr[ib->length_dw++] = 0x00000000;
240
241 ib->ptr[ib->length_dw++] = 0x00000008;
242 ib->ptr[ib->length_dw++] = 0x08000001; /* op initialize */
243
244 for (i = ib->length_dw; i < ib_size_dw; ++i)
245 ib->ptr[i] = 0x0;
246
247 r = amdgpu_job_submit_direct(job, ring, &f);
248 if (r)
249 goto err;
250
251 if (fence)
252 *fence = dma_fence_get(f);
253 dma_fence_put(f);
254 return 0;
255
256err:
257 amdgpu_job_free(job);
258 return r;
259}
260
261/**
262 * uvd_v6_0_enc_get_destroy_msg - generate a UVD ENC destroy msg
263 *
264 * @adev: amdgpu_device pointer
265 * @ring: ring we should submit the msg to
266 * @handle: session handle to use
267 * @fence: optional fence to return
268 *
269 * Close up a stream for HW test or if userspace failed to do so
270 */
271static int uvd_v6_0_enc_get_destroy_msg(struct amdgpu_ring *ring,
272 uint32_t handle,
273 struct amdgpu_bo *bo,
274 struct dma_fence **fence)
275{
276 const unsigned ib_size_dw = 16;
277 struct amdgpu_job *job;
278 struct amdgpu_ib *ib;
279 struct dma_fence *f = NULL((void *)0);
280 uint64_t addr;
281 int i, r;
282
283 r = amdgpu_job_alloc_with_ib(ring->adev, ib_size_dw * 4,
284 AMDGPU_IB_POOL_DIRECT, &job);
285 if (r)
286 return r;
287
288 ib = &job->ibs[0];
289 addr = amdgpu_bo_gpu_offset(bo);
290
291 ib->length_dw = 0;
292 ib->ptr[ib->length_dw++] = 0x00000018;
293 ib->ptr[ib->length_dw++] = 0x00000001; /* session info */
294 ib->ptr[ib->length_dw++] = handle;
295 ib->ptr[ib->length_dw++] = 0x00010000;
296 ib->ptr[ib->length_dw++] = upper_32_bits(addr)((u32)(((addr) >> 16) >> 16));
297 ib->ptr[ib->length_dw++] = addr;
298
299 ib->ptr[ib->length_dw++] = 0x00000014;
300 ib->ptr[ib->length_dw++] = 0x00000002; /* task info */
301 ib->ptr[ib->length_dw++] = 0x0000001c;
302 ib->ptr[ib->length_dw++] = 0x00000001;
303 ib->ptr[ib->length_dw++] = 0x00000000;
304
305 ib->ptr[ib->length_dw++] = 0x00000008;
306 ib->ptr[ib->length_dw++] = 0x08000002; /* op close session */
307
308 for (i = ib->length_dw; i < ib_size_dw; ++i)
309 ib->ptr[i] = 0x0;
310
311 r = amdgpu_job_submit_direct(job, ring, &f);
312 if (r)
313 goto err;
314
315 if (fence)
316 *fence = dma_fence_get(f);
317 dma_fence_put(f);
318 return 0;
319
320err:
321 amdgpu_job_free(job);
322 return r;
323}
324
325/**
326 * uvd_v6_0_enc_ring_test_ib - test if UVD ENC IBs are working
327 *
328 * @ring: the engine to test on
329 *
330 */
331static int uvd_v6_0_enc_ring_test_ib(struct amdgpu_ring *ring, long timeout)
332{
333 struct dma_fence *fence = NULL((void *)0);
334 struct amdgpu_bo *bo = NULL((void *)0);
335 long r;
336
337 r = amdgpu_bo_create_reserved(ring->adev, 128 * 1024, PAGE_SIZE(1 << 12),
338 AMDGPU_GEM_DOMAIN_VRAM0x4,
339 &bo, NULL((void *)0), NULL((void *)0));
340 if (r)
341 return r;
342
343 r = uvd_v6_0_enc_get_create_msg(ring, 1, bo, NULL((void *)0));
344 if (r)
345 goto error;
346
347 r = uvd_v6_0_enc_get_destroy_msg(ring, 1, bo, &fence);
348 if (r)
349 goto error;
350
351 r = dma_fence_wait_timeout(fence, false0, timeout);
352 if (r == 0)
353 r = -ETIMEDOUT60;
354 else if (r > 0)
355 r = 0;
356
357error:
358 dma_fence_put(fence);
359 amdgpu_bo_unpin(bo);
360 amdgpu_bo_unreserve(bo);
361 amdgpu_bo_unref(&bo);
362 return r;
363}
364
365static int uvd_v6_0_early_init(void *handle)
366{
367 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
368 adev->uvd.num_uvd_inst = 1;
369
370 if (!(adev->flags & AMD_IS_APU) &&
371 (RREG32_SMC(ixCC_HARVEST_FUSES)adev->smc_rreg(adev, (0xc00c0028)) & CC_HARVEST_FUSES__UVD_DISABLE_MASK0x10))
372 return -ENOENT2;
373
374 uvd_v6_0_set_ring_funcs(adev);
375
376 if (uvd_v6_0_enc_support(adev)) {
377 adev->uvd.num_enc_rings = 2;
378 uvd_v6_0_set_enc_ring_funcs(adev);
379 }
380
381 uvd_v6_0_set_irq_funcs(adev);
382
383 return 0;
384}
385
386static int uvd_v6_0_sw_init(void *handle)
387{
388 struct amdgpu_ring *ring;
389 int i, r;
390 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
391
392 /* UVD TRAP */
393 r = amdgpu_irq_add_id(adev, AMDGPU_IRQ_CLIENTID_LEGACY0, VISLANDS30_IV_SRCID_UVD_SYSTEM_MESSAGE0x0000007c, &adev->uvd.inst->irq);
394 if (r)
395 return r;
396
397 /* UVD ENC TRAP */
398 if (uvd_v6_0_enc_support(adev)) {
399 for (i = 0; i < adev->uvd.num_enc_rings; ++i) {
400 r = amdgpu_irq_add_id(adev, AMDGPU_IRQ_CLIENTID_LEGACY0, i + VISLANDS30_IV_SRCID_UVD_ENC_GEN_PURP0x00000077, &adev->uvd.inst->irq);
401 if (r)
402 return r;
403 }
404 }
405
406 r = amdgpu_uvd_sw_init(adev);
407 if (r)
408 return r;
409
410 if (!uvd_v6_0_enc_support(adev)) {
411 for (i = 0; i < adev->uvd.num_enc_rings; ++i)
412 adev->uvd.inst->ring_enc[i].funcs = NULL((void *)0);
413
414 adev->uvd.inst->irq.num_types = 1;
415 adev->uvd.num_enc_rings = 0;
416
417 DRM_INFO("UVD ENC is disabled\n")printk("\0016" "[" "drm" "] " "UVD ENC is disabled\n");
418 }
419
420 ring = &adev->uvd.inst->ring;
421 snprintf(ring->name, sizeof(ring->name), "uvd");
422 r = amdgpu_ring_init(adev, ring, 512, &adev->uvd.inst->irq, 0,
423 AMDGPU_RING_PRIO_DEFAULT1);
424 if (r)
425 return r;
426
427 r = amdgpu_uvd_resume(adev);
428 if (r)
429 return r;
430
431 if (uvd_v6_0_enc_support(adev)) {
432 for (i = 0; i < adev->uvd.num_enc_rings; ++i) {
433 ring = &adev->uvd.inst->ring_enc[i];
434 snprintf(ring->name, sizeof(ring->name), "uvd_enc%d", i);
435 r = amdgpu_ring_init(adev, ring, 512,
436 &adev->uvd.inst->irq, 0,
437 AMDGPU_RING_PRIO_DEFAULT1);
438 if (r)
439 return r;
440 }
441 }
442
443 r = amdgpu_uvd_entity_init(adev);
444
445 return r;
446}
447
448static int uvd_v6_0_sw_fini(void *handle)
449{
450 int i, r;
451 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
452
453 r = amdgpu_uvd_suspend(adev);
454 if (r)
455 return r;
456
457 if (uvd_v6_0_enc_support(adev)) {
458 for (i = 0; i < adev->uvd.num_enc_rings; ++i)
459 amdgpu_ring_fini(&adev->uvd.inst->ring_enc[i]);
460 }
461
462 return amdgpu_uvd_sw_fini(adev);
463}
464
465/**
466 * uvd_v6_0_hw_init - start and test UVD block
467 *
468 * @adev: amdgpu_device pointer
469 *
470 * Initialize the hardware, boot up the VCPU and do some testing
471 */
472static int uvd_v6_0_hw_init(void *handle)
473{
474 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
475 struct amdgpu_ring *ring = &adev->uvd.inst->ring;
476 uint32_t tmp;
477 int i, r;
478
479 amdgpu_asic_set_uvd_clocks(adev, 10000, 10000)(adev)->asic_funcs->set_uvd_clocks((adev), (10000), (10000
))
;
480 uvd_v6_0_set_clockgating_state(adev, AMD_CG_STATE_UNGATE);
481 uvd_v6_0_enable_mgcg(adev, true1);
482
483 r = amdgpu_ring_test_helper(ring);
484 if (r)
485 goto done;
486
487 r = amdgpu_ring_alloc(ring, 10);
488 if (r) {
489 DRM_ERROR("amdgpu: ring failed to lock UVD ring (%d).\n", r)__drm_err("amdgpu: ring failed to lock UVD ring (%d).\n", r);
490 goto done;
491 }
492
493 tmp = PACKET0(mmUVD_SEMA_WAIT_FAULT_TIMEOUT_CNTL, 0)((0 << 30) | ((0x3db2) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
;
494 amdgpu_ring_write(ring, tmp);
495 amdgpu_ring_write(ring, 0xFFFFF);
496
497 tmp = PACKET0(mmUVD_SEMA_WAIT_INCOMPLETE_TIMEOUT_CNTL, 0)((0 << 30) | ((0x3db1) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
;
498 amdgpu_ring_write(ring, tmp);
499 amdgpu_ring_write(ring, 0xFFFFF);
500
501 tmp = PACKET0(mmUVD_SEMA_SIGNAL_INCOMPLETE_TIMEOUT_CNTL, 0)((0 << 30) | ((0x3db3) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
;
502 amdgpu_ring_write(ring, tmp);
503 amdgpu_ring_write(ring, 0xFFFFF);
504
505 /* Clear timeout status bits */
506 amdgpu_ring_write(ring, PACKET0(mmUVD_SEMA_TIMEOUT_STATUS, 0)((0 << 30) | ((0x3db0) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
);
507 amdgpu_ring_write(ring, 0x8);
508
509 amdgpu_ring_write(ring, PACKET0(mmUVD_SEMA_CNTL, 0)((0 << 30) | ((0x3d00) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
);
510 amdgpu_ring_write(ring, 3);
511
512 amdgpu_ring_commit(ring);
513
514 if (uvd_v6_0_enc_support(adev)) {
515 for (i = 0; i < adev->uvd.num_enc_rings; ++i) {
516 ring = &adev->uvd.inst->ring_enc[i];
517 r = amdgpu_ring_test_helper(ring);
518 if (r)
519 goto done;
520 }
521 }
522
523done:
524 if (!r) {
525 if (uvd_v6_0_enc_support(adev))
526 DRM_INFO("UVD and UVD ENC initialized successfully.\n")printk("\0016" "[" "drm" "] " "UVD and UVD ENC initialized successfully.\n"
)
;
527 else
528 DRM_INFO("UVD initialized successfully.\n")printk("\0016" "[" "drm" "] " "UVD initialized successfully.\n"
)
;
529 }
530
531 return r;
532}
533
534/**
535 * uvd_v6_0_hw_fini - stop the hardware block
536 *
537 * @adev: amdgpu_device pointer
538 *
539 * Stop the UVD block, mark ring as not ready any more
540 */
541static int uvd_v6_0_hw_fini(void *handle)
542{
543 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
544
545 if (RREG32(mmUVD_STATUS)amdgpu_device_rreg(adev, (0x3daf), 0) != 0)
546 uvd_v6_0_stop(adev);
547
548 return 0;
549}
550
551static int uvd_v6_0_suspend(void *handle)
552{
553 int r;
554 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
555
556 r = uvd_v6_0_hw_fini(adev);
557 if (r)
558 return r;
559
560 return amdgpu_uvd_suspend(adev);
561}
562
563static int uvd_v6_0_resume(void *handle)
564{
565 int r;
566 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
567
568 r = amdgpu_uvd_resume(adev);
569 if (r)
570 return r;
571
572 return uvd_v6_0_hw_init(adev);
573}
574
575/**
576 * uvd_v6_0_mc_resume - memory controller programming
577 *
578 * @adev: amdgpu_device pointer
579 *
580 * Let the UVD memory controller know it's offsets
581 */
582static void uvd_v6_0_mc_resume(struct amdgpu_device *adev)
583{
584 uint64_t offset;
585 uint32_t size;
586
587 /* program memory controller bits 0-27 */
588 WREG32(mmUVD_LMI_VCPU_CACHE_64BIT_BAR_LOW,amdgpu_device_wreg(adev, (0x3c5f), (((u32)(adev->uvd.inst->
gpu_addr))), 0)
589 lower_32_bits(adev->uvd.inst->gpu_addr))amdgpu_device_wreg(adev, (0x3c5f), (((u32)(adev->uvd.inst->
gpu_addr))), 0)
;
590 WREG32(mmUVD_LMI_VCPU_CACHE_64BIT_BAR_HIGH,amdgpu_device_wreg(adev, (0x3c5e), (((u32)(((adev->uvd.inst
->gpu_addr) >> 16) >> 16))), 0)
591 upper_32_bits(adev->uvd.inst->gpu_addr))amdgpu_device_wreg(adev, (0x3c5e), (((u32)(((adev->uvd.inst
->gpu_addr) >> 16) >> 16))), 0)
;
592
593 offset = AMDGPU_UVD_FIRMWARE_OFFSET256;
594 size = AMDGPU_UVD_FIRMWARE_SIZE(adev)((((((__uint32_t)(((const struct common_firmware_header *)(adev
)->uvd.fw->data)->ucode_size_bytes)) + 8) + (4096 - 1
)) & ~(4096 - 1)) - 256)
;
595 WREG32(mmUVD_VCPU_CACHE_OFFSET0, offset >> 3)amdgpu_device_wreg(adev, (0x3d82), (offset >> 3), 0);
596 WREG32(mmUVD_VCPU_CACHE_SIZE0, size)amdgpu_device_wreg(adev, (0x3d83), (size), 0);
597
598 offset += size;
599 size = AMDGPU_UVD_HEAP_SIZE(256*1024);
600 WREG32(mmUVD_VCPU_CACHE_OFFSET1, offset >> 3)amdgpu_device_wreg(adev, (0x3d84), (offset >> 3), 0);
601 WREG32(mmUVD_VCPU_CACHE_SIZE1, size)amdgpu_device_wreg(adev, (0x3d85), (size), 0);
602
603 offset += size;
604 size = AMDGPU_UVD_STACK_SIZE(200*1024) +
605 (AMDGPU_UVD_SESSION_SIZE(50*1024) * adev->uvd.max_handles);
606 WREG32(mmUVD_VCPU_CACHE_OFFSET2, offset >> 3)amdgpu_device_wreg(adev, (0x3d86), (offset >> 3), 0);
607 WREG32(mmUVD_VCPU_CACHE_SIZE2, size)amdgpu_device_wreg(adev, (0x3d87), (size), 0);
608
609 WREG32(mmUVD_UDEC_ADDR_CONFIG, adev->gfx.config.gb_addr_config)amdgpu_device_wreg(adev, (0x3bd3), (adev->gfx.config.gb_addr_config
), 0)
;
610 WREG32(mmUVD_UDEC_DB_ADDR_CONFIG, adev->gfx.config.gb_addr_config)amdgpu_device_wreg(adev, (0x3bd4), (adev->gfx.config.gb_addr_config
), 0)
;
611 WREG32(mmUVD_UDEC_DBW_ADDR_CONFIG, adev->gfx.config.gb_addr_config)amdgpu_device_wreg(adev, (0x3bd5), (adev->gfx.config.gb_addr_config
), 0)
;
612
613 WREG32(mmUVD_GP_SCRATCH4, adev->uvd.max_handles)amdgpu_device_wreg(adev, (0x3d38), (adev->uvd.max_handles)
, 0)
;
614}
615
616#if 0
617static void cz_set_uvd_clock_gating_branches(struct amdgpu_device *adev,
618 bool_Bool enable)
619{
620 u32 data, data1;
621
622 data = RREG32(mmUVD_CGC_GATE)amdgpu_device_rreg(adev, (0x3d2a), 0);
623 data1 = RREG32(mmUVD_SUVD_CGC_GATE)amdgpu_device_rreg(adev, (0x3be4), 0);
624 if (enable) {
625 data |= UVD_CGC_GATE__SYS_MASK0x1 |
626 UVD_CGC_GATE__UDEC_MASK0x2 |
627 UVD_CGC_GATE__MPEG2_MASK0x4 |
628 UVD_CGC_GATE__RBC_MASK0x10 |
629 UVD_CGC_GATE__LMI_MC_MASK0x20 |
630 UVD_CGC_GATE__IDCT_MASK0x80 |
631 UVD_CGC_GATE__MPRD_MASK0x100 |
632 UVD_CGC_GATE__MPC_MASK0x200 |
633 UVD_CGC_GATE__LBSI_MASK0x400 |
634 UVD_CGC_GATE__LRBBM_MASK0x800 |
635 UVD_CGC_GATE__UDEC_RE_MASK0x1000 |
636 UVD_CGC_GATE__UDEC_CM_MASK0x2000 |
637 UVD_CGC_GATE__UDEC_IT_MASK0x4000 |
638 UVD_CGC_GATE__UDEC_DB_MASK0x8000 |
639 UVD_CGC_GATE__UDEC_MP_MASK0x10000 |
640 UVD_CGC_GATE__WCB_MASK0x20000 |
641 UVD_CGC_GATE__VCPU_MASK0x40000 |
642 UVD_CGC_GATE__SCPU_MASK0x80000;
643 data1 |= UVD_SUVD_CGC_GATE__SRE_MASK0x1 |
644 UVD_SUVD_CGC_GATE__SIT_MASK0x2 |
645 UVD_SUVD_CGC_GATE__SMP_MASK0x4 |
646 UVD_SUVD_CGC_GATE__SCM_MASK0x8 |
647 UVD_SUVD_CGC_GATE__SDB_MASK0x10 |
648 UVD_SUVD_CGC_GATE__SRE_H264_MASK0x20 |
649 UVD_SUVD_CGC_GATE__SRE_HEVC_MASK0x40 |
650 UVD_SUVD_CGC_GATE__SIT_H264_MASK0x80 |
651 UVD_SUVD_CGC_GATE__SIT_HEVC_MASK0x100 |
652 UVD_SUVD_CGC_GATE__SCM_H264_MASK0x200 |
653 UVD_SUVD_CGC_GATE__SCM_HEVC_MASK0x400 |
654 UVD_SUVD_CGC_GATE__SDB_H264_MASK0x800 |
655 UVD_SUVD_CGC_GATE__SDB_HEVC_MASK0x1000;
656 } else {
657 data &= ~(UVD_CGC_GATE__SYS_MASK0x1 |
658 UVD_CGC_GATE__UDEC_MASK0x2 |
659 UVD_CGC_GATE__MPEG2_MASK0x4 |
660 UVD_CGC_GATE__RBC_MASK0x10 |
661 UVD_CGC_GATE__LMI_MC_MASK0x20 |
662 UVD_CGC_GATE__LMI_UMC_MASK0x40 |
663 UVD_CGC_GATE__IDCT_MASK0x80 |
664 UVD_CGC_GATE__MPRD_MASK0x100 |
665 UVD_CGC_GATE__MPC_MASK0x200 |
666 UVD_CGC_GATE__LBSI_MASK0x400 |
667 UVD_CGC_GATE__LRBBM_MASK0x800 |
668 UVD_CGC_GATE__UDEC_RE_MASK0x1000 |
669 UVD_CGC_GATE__UDEC_CM_MASK0x2000 |
670 UVD_CGC_GATE__UDEC_IT_MASK0x4000 |
671 UVD_CGC_GATE__UDEC_DB_MASK0x8000 |
672 UVD_CGC_GATE__UDEC_MP_MASK0x10000 |
673 UVD_CGC_GATE__WCB_MASK0x20000 |
674 UVD_CGC_GATE__VCPU_MASK0x40000 |
675 UVD_CGC_GATE__SCPU_MASK0x80000);
676 data1 &= ~(UVD_SUVD_CGC_GATE__SRE_MASK0x1 |
677 UVD_SUVD_CGC_GATE__SIT_MASK0x2 |
678 UVD_SUVD_CGC_GATE__SMP_MASK0x4 |
679 UVD_SUVD_CGC_GATE__SCM_MASK0x8 |
680 UVD_SUVD_CGC_GATE__SDB_MASK0x10 |
681 UVD_SUVD_CGC_GATE__SRE_H264_MASK0x20 |
682 UVD_SUVD_CGC_GATE__SRE_HEVC_MASK0x40 |
683 UVD_SUVD_CGC_GATE__SIT_H264_MASK0x80 |
684 UVD_SUVD_CGC_GATE__SIT_HEVC_MASK0x100 |
685 UVD_SUVD_CGC_GATE__SCM_H264_MASK0x200 |
686 UVD_SUVD_CGC_GATE__SCM_HEVC_MASK0x400 |
687 UVD_SUVD_CGC_GATE__SDB_H264_MASK0x800 |
688 UVD_SUVD_CGC_GATE__SDB_HEVC_MASK0x1000);
689 }
690 WREG32(mmUVD_CGC_GATE, data)amdgpu_device_wreg(adev, (0x3d2a), (data), 0);
691 WREG32(mmUVD_SUVD_CGC_GATE, data1)amdgpu_device_wreg(adev, (0x3be4), (data1), 0);
692}
693#endif
694
695/**
696 * uvd_v6_0_start - start UVD block
697 *
698 * @adev: amdgpu_device pointer
699 *
700 * Setup and start the UVD block
701 */
702static int uvd_v6_0_start(struct amdgpu_device *adev)
703{
704 struct amdgpu_ring *ring = &adev->uvd.inst->ring;
705 uint32_t rb_bufsz, tmp;
706 uint32_t lmi_swap_cntl;
707 uint32_t mp_swap_cntl;
708 int i, j, r;
709
710 /* disable DPG */
711 WREG32_P(mmUVD_POWER_STATUS, 0, ~UVD_POWER_STATUS__UVD_PG_MODE_MASK)do { uint32_t tmp_ = amdgpu_device_rreg(adev, (0x38c4), 0); tmp_
&= (~0x4); tmp_ |= ((0) & ~(~0x4)); amdgpu_device_wreg
(adev, (0x38c4), (tmp_), 0); } while (0)
;
712
713 /* disable byte swapping */
714 lmi_swap_cntl = 0;
715 mp_swap_cntl = 0;
716
717 uvd_v6_0_mc_resume(adev);
718
719 /* disable interupt */
720 WREG32_FIELD(UVD_MASTINT_EN, VCPU_EN, 0)amdgpu_device_wreg(adev, (0x3d40), ((amdgpu_device_rreg(adev,
(0x3d40), 0) & ~0x2) | (0) << 0x1), 0)
;
721
722 /* stall UMC and register bus before resetting VCPU */
723 WREG32_FIELD(UVD_LMI_CTRL2, STALL_ARB_UMC, 1)amdgpu_device_wreg(adev, (0x3d3d), ((amdgpu_device_rreg(adev,
(0x3d3d), 0) & ~0x100) | (1) << 0x8), 0)
;
724 mdelay(1);
725
726 /* put LMI, VCPU, RBC etc... into reset */
727 WREG32(mmUVD_SOFT_RESET,amdgpu_device_wreg(adev, (0x3da0), (0x4 | 0x8 | 0x2 | 0x1 | 0x20
| 0x40 | 0x80 | 0x2000), 0)
728 UVD_SOFT_RESET__LMI_SOFT_RESET_MASK |amdgpu_device_wreg(adev, (0x3da0), (0x4 | 0x8 | 0x2 | 0x1 | 0x20
| 0x40 | 0x80 | 0x2000), 0)
729 UVD_SOFT_RESET__VCPU_SOFT_RESET_MASK |amdgpu_device_wreg(adev, (0x3da0), (0x4 | 0x8 | 0x2 | 0x1 | 0x20
| 0x40 | 0x80 | 0x2000), 0)
730 UVD_SOFT_RESET__LBSI_SOFT_RESET_MASK |amdgpu_device_wreg(adev, (0x3da0), (0x4 | 0x8 | 0x2 | 0x1 | 0x20
| 0x40 | 0x80 | 0x2000), 0)
731 UVD_SOFT_RESET__RBC_SOFT_RESET_MASK |amdgpu_device_wreg(adev, (0x3da0), (0x4 | 0x8 | 0x2 | 0x1 | 0x20
| 0x40 | 0x80 | 0x2000), 0)
732 UVD_SOFT_RESET__CSM_SOFT_RESET_MASK |amdgpu_device_wreg(adev, (0x3da0), (0x4 | 0x8 | 0x2 | 0x1 | 0x20
| 0x40 | 0x80 | 0x2000), 0)
733 UVD_SOFT_RESET__CXW_SOFT_RESET_MASK |amdgpu_device_wreg(adev, (0x3da0), (0x4 | 0x8 | 0x2 | 0x1 | 0x20
| 0x40 | 0x80 | 0x2000), 0)
734 UVD_SOFT_RESET__TAP_SOFT_RESET_MASK |amdgpu_device_wreg(adev, (0x3da0), (0x4 | 0x8 | 0x2 | 0x1 | 0x20
| 0x40 | 0x80 | 0x2000), 0)
735 UVD_SOFT_RESET__LMI_UMC_SOFT_RESET_MASK)amdgpu_device_wreg(adev, (0x3da0), (0x4 | 0x8 | 0x2 | 0x1 | 0x20
| 0x40 | 0x80 | 0x2000), 0)
;
736 mdelay(5);
737
738 /* take UVD block out of reset */
739 WREG32_FIELD(SRBM_SOFT_RESET, SOFT_RESET_UVD, 0)amdgpu_device_wreg(adev, (0x398), ((amdgpu_device_rreg(adev, (
0x398), 0) & ~0x40000) | (0) << 0x12), 0)
;
740 mdelay(5);
741
742 /* initialize UVD memory controller */
743 WREG32(mmUVD_LMI_CTRL,amdgpu_device_wreg(adev, (0x3d66), ((0x40 << 0x0) | 0x100
| 0x2000 | 0x200000 | 0x200 | 0x100000), 0)
744 (0x40 << UVD_LMI_CTRL__WRITE_CLEAN_TIMER__SHIFT) |amdgpu_device_wreg(adev, (0x3d66), ((0x40 << 0x0) | 0x100
| 0x2000 | 0x200000 | 0x200 | 0x100000), 0)
745 UVD_LMI_CTRL__WRITE_CLEAN_TIMER_EN_MASK |amdgpu_device_wreg(adev, (0x3d66), ((0x40 << 0x0) | 0x100
| 0x2000 | 0x200000 | 0x200 | 0x100000), 0)
746 UVD_LMI_CTRL__DATA_COHERENCY_EN_MASK |amdgpu_device_wreg(adev, (0x3d66), ((0x40 << 0x0) | 0x100
| 0x2000 | 0x200000 | 0x200 | 0x100000), 0)
747 UVD_LMI_CTRL__VCPU_DATA_COHERENCY_EN_MASK |amdgpu_device_wreg(adev, (0x3d66), ((0x40 << 0x0) | 0x100
| 0x2000 | 0x200000 | 0x200 | 0x100000), 0)
748 UVD_LMI_CTRL__REQ_MODE_MASK |amdgpu_device_wreg(adev, (0x3d66), ((0x40 << 0x0) | 0x100
| 0x2000 | 0x200000 | 0x200 | 0x100000), 0)
749 UVD_LMI_CTRL__DISABLE_ON_FWV_FAIL_MASK)amdgpu_device_wreg(adev, (0x3d66), ((0x40 << 0x0) | 0x100
| 0x2000 | 0x200000 | 0x200 | 0x100000), 0)
;
750
751#ifdef __BIG_ENDIAN
752 /* swap (8 in 32) RB and IB */
753 lmi_swap_cntl = 0xa;
754 mp_swap_cntl = 0;
755#endif
756 WREG32(mmUVD_LMI_SWAP_CNTL, lmi_swap_cntl)amdgpu_device_wreg(adev, (0x3d6d), (lmi_swap_cntl), 0);
757 WREG32(mmUVD_MP_SWAP_CNTL, mp_swap_cntl)amdgpu_device_wreg(adev, (0x3d6f), (mp_swap_cntl), 0);
758
759 WREG32(mmUVD_MPC_SET_MUXA0, 0x40c2040)amdgpu_device_wreg(adev, (0x3d79), (0x40c2040), 0);
760 WREG32(mmUVD_MPC_SET_MUXA1, 0x0)amdgpu_device_wreg(adev, (0x3d7a), (0x0), 0);
761 WREG32(mmUVD_MPC_SET_MUXB0, 0x40c2040)amdgpu_device_wreg(adev, (0x3d7b), (0x40c2040), 0);
762 WREG32(mmUVD_MPC_SET_MUXB1, 0x0)amdgpu_device_wreg(adev, (0x3d7c), (0x0), 0);
763 WREG32(mmUVD_MPC_SET_ALU, 0)amdgpu_device_wreg(adev, (0x3d7e), (0), 0);
764 WREG32(mmUVD_MPC_SET_MUX, 0x88)amdgpu_device_wreg(adev, (0x3d7d), (0x88), 0);
765
766 /* take all subblocks out of reset, except VCPU */
767 WREG32(mmUVD_SOFT_RESET, UVD_SOFT_RESET__VCPU_SOFT_RESET_MASK)amdgpu_device_wreg(adev, (0x3da0), (0x8), 0);
768 mdelay(5);
769
770 /* enable VCPU clock */
771 WREG32(mmUVD_VCPU_CNTL, UVD_VCPU_CNTL__CLK_EN_MASK)amdgpu_device_wreg(adev, (0x3d98), (0x200), 0);
772
773 /* enable UMC */
774 WREG32_FIELD(UVD_LMI_CTRL2, STALL_ARB_UMC, 0)amdgpu_device_wreg(adev, (0x3d3d), ((amdgpu_device_rreg(adev,
(0x3d3d), 0) & ~0x100) | (0) << 0x8), 0)
;
775
776 /* boot up the VCPU */
777 WREG32(mmUVD_SOFT_RESET, 0)amdgpu_device_wreg(adev, (0x3da0), (0), 0);
778 mdelay(10);
779
780 for (i = 0; i < 10; ++i) {
781 uint32_t status;
782
783 for (j = 0; j < 100; ++j) {
784 status = RREG32(mmUVD_STATUS)amdgpu_device_rreg(adev, (0x3daf), 0);
785 if (status & 2)
786 break;
787 mdelay(10);
788 }
789 r = 0;
790 if (status & 2)
791 break;
792
793 DRM_ERROR("UVD not responding, trying to reset the VCPU!!!\n")__drm_err("UVD not responding, trying to reset the VCPU!!!\n"
)
;
794 WREG32_FIELD(UVD_SOFT_RESET, VCPU_SOFT_RESET, 1)amdgpu_device_wreg(adev, (0x3da0), ((amdgpu_device_rreg(adev,
(0x3da0), 0) & ~0x8) | (1) << 0x3), 0)
;
795 mdelay(10);
796 WREG32_FIELD(UVD_SOFT_RESET, VCPU_SOFT_RESET, 0)amdgpu_device_wreg(adev, (0x3da0), ((amdgpu_device_rreg(adev,
(0x3da0), 0) & ~0x8) | (0) << 0x3), 0)
;
797 mdelay(10);
798 r = -1;
799 }
800
801 if (r) {
802 DRM_ERROR("UVD not responding, giving up!!!\n")__drm_err("UVD not responding, giving up!!!\n");
803 return r;
804 }
805 /* enable master interrupt */
806 WREG32_P(mmUVD_MASTINT_EN,do { uint32_t tmp_ = amdgpu_device_rreg(adev, (0x3d40), 0); tmp_
&= (~(0x2|0x4)); tmp_ |= (((0x2|0x4)) & ~(~(0x2|0x4)
)); amdgpu_device_wreg(adev, (0x3d40), (tmp_), 0); } while (0
)
807 (UVD_MASTINT_EN__VCPU_EN_MASK|UVD_MASTINT_EN__SYS_EN_MASK),do { uint32_t tmp_ = amdgpu_device_rreg(adev, (0x3d40), 0); tmp_
&= (~(0x2|0x4)); tmp_ |= (((0x2|0x4)) & ~(~(0x2|0x4)
)); amdgpu_device_wreg(adev, (0x3d40), (tmp_), 0); } while (0
)
808 ~(UVD_MASTINT_EN__VCPU_EN_MASK|UVD_MASTINT_EN__SYS_EN_MASK))do { uint32_t tmp_ = amdgpu_device_rreg(adev, (0x3d40), 0); tmp_
&= (~(0x2|0x4)); tmp_ |= (((0x2|0x4)) & ~(~(0x2|0x4)
)); amdgpu_device_wreg(adev, (0x3d40), (tmp_), 0); } while (0
)
;
809
810 /* clear the bit 4 of UVD_STATUS */
811 WREG32_P(mmUVD_STATUS, 0, ~(2 << UVD_STATUS__VCPU_REPORT__SHIFT))do { uint32_t tmp_ = amdgpu_device_rreg(adev, (0x3daf), 0); tmp_
&= (~(2 << 0x1)); tmp_ |= ((0) & ~(~(2 <<
0x1))); amdgpu_device_wreg(adev, (0x3daf), (tmp_), 0); } while
(0)
;
812
813 /* force RBC into idle state */
814 rb_bufsz = order_base_2(ring->ring_size)drm_order(ring->ring_size);
815 tmp = REG_SET_FIELD(0, UVD_RBC_RB_CNTL, RB_BUFSZ, rb_bufsz)(((0) & ~0x1f) | (0x1f & ((rb_bufsz) << 0x0)));
816 tmp = REG_SET_FIELD(tmp, UVD_RBC_RB_CNTL, RB_BLKSZ, 1)(((tmp) & ~0x1f00) | (0x1f00 & ((1) << 0x8)));
817 tmp = REG_SET_FIELD(tmp, UVD_RBC_RB_CNTL, RB_NO_FETCH, 1)(((tmp) & ~0x10000) | (0x10000 & ((1) << 0x10))
)
;
818 tmp = REG_SET_FIELD(tmp, UVD_RBC_RB_CNTL, RB_WPTR_POLL_EN, 0)(((tmp) & ~0x100000) | (0x100000 & ((0) << 0x14
)))
;
819 tmp = REG_SET_FIELD(tmp, UVD_RBC_RB_CNTL, RB_NO_UPDATE, 1)(((tmp) & ~0x1000000) | (0x1000000 & ((1) << 0x18
)))
;
820 tmp = REG_SET_FIELD(tmp, UVD_RBC_RB_CNTL, RB_RPTR_WR_EN, 1)(((tmp) & ~0x10000000) | (0x10000000 & ((1) << 0x1c
)))
;
821 WREG32(mmUVD_RBC_RB_CNTL, tmp)amdgpu_device_wreg(adev, (0x3da9), (tmp), 0);
822
823 /* set the write pointer delay */
824 WREG32(mmUVD_RBC_RB_WPTR_CNTL, 0)amdgpu_device_wreg(adev, (0x3da6), (0), 0);
825
826 /* set the wb address */
827 WREG32(mmUVD_RBC_RB_RPTR_ADDR, (upper_32_bits(ring->gpu_addr) >> 2))amdgpu_device_wreg(adev, (0x3daa), ((((u32)(((ring->gpu_addr
) >> 16) >> 16)) >> 2)), 0)
;
828
829 /* program the RB_BASE for ring buffer */
830 WREG32(mmUVD_LMI_RBC_RB_64BIT_BAR_LOW,amdgpu_device_wreg(adev, (0x3c69), (((u32)(ring->gpu_addr)
)), 0)
831 lower_32_bits(ring->gpu_addr))amdgpu_device_wreg(adev, (0x3c69), (((u32)(ring->gpu_addr)
)), 0)
;
832 WREG32(mmUVD_LMI_RBC_RB_64BIT_BAR_HIGH,amdgpu_device_wreg(adev, (0x3c68), (((u32)(((ring->gpu_addr
) >> 16) >> 16))), 0)
833 upper_32_bits(ring->gpu_addr))amdgpu_device_wreg(adev, (0x3c68), (((u32)(((ring->gpu_addr
) >> 16) >> 16))), 0)
;
834
835 /* Initialize the ring buffer's read and write pointers */
836 WREG32(mmUVD_RBC_RB_RPTR, 0)amdgpu_device_wreg(adev, (0x3da4), (0), 0);
837
838 ring->wptr = RREG32(mmUVD_RBC_RB_RPTR)amdgpu_device_rreg(adev, (0x3da4), 0);
839 WREG32(mmUVD_RBC_RB_WPTR, lower_32_bits(ring->wptr))amdgpu_device_wreg(adev, (0x3da5), (((u32)(ring->wptr))), 0
)
;
840
841 WREG32_FIELD(UVD_RBC_RB_CNTL, RB_NO_FETCH, 0)amdgpu_device_wreg(adev, (0x3da9), ((amdgpu_device_rreg(adev,
(0x3da9), 0) & ~0x10000) | (0) << 0x10), 0)
;
842
843 if (uvd_v6_0_enc_support(adev)) {
844 ring = &adev->uvd.inst->ring_enc[0];
845 WREG32(mmUVD_RB_RPTR, lower_32_bits(ring->wptr))amdgpu_device_wreg(adev, (0x3c29), (((u32)(ring->wptr))), 0
)
;
846 WREG32(mmUVD_RB_WPTR, lower_32_bits(ring->wptr))amdgpu_device_wreg(adev, (0x3c2a), (((u32)(ring->wptr))), 0
)
;
847 WREG32(mmUVD_RB_BASE_LO, ring->gpu_addr)amdgpu_device_wreg(adev, (0x3c26), (ring->gpu_addr), 0);
848 WREG32(mmUVD_RB_BASE_HI, upper_32_bits(ring->gpu_addr))amdgpu_device_wreg(adev, (0x3c27), (((u32)(((ring->gpu_addr
) >> 16) >> 16))), 0)
;
849 WREG32(mmUVD_RB_SIZE, ring->ring_size / 4)amdgpu_device_wreg(adev, (0x3c28), (ring->ring_size / 4), 0
)
;
850
851 ring = &adev->uvd.inst->ring_enc[1];
852 WREG32(mmUVD_RB_RPTR2, lower_32_bits(ring->wptr))amdgpu_device_wreg(adev, (0x3c24), (((u32)(ring->wptr))), 0
)
;
853 WREG32(mmUVD_RB_WPTR2, lower_32_bits(ring->wptr))amdgpu_device_wreg(adev, (0x3c25), (((u32)(ring->wptr))), 0
)
;
854 WREG32(mmUVD_RB_BASE_LO2, ring->gpu_addr)amdgpu_device_wreg(adev, (0x3c21), (ring->gpu_addr), 0);
855 WREG32(mmUVD_RB_BASE_HI2, upper_32_bits(ring->gpu_addr))amdgpu_device_wreg(adev, (0x3c22), (((u32)(((ring->gpu_addr
) >> 16) >> 16))), 0)
;
856 WREG32(mmUVD_RB_SIZE2, ring->ring_size / 4)amdgpu_device_wreg(adev, (0x3c23), (ring->ring_size / 4), 0
)
;
857 }
858
859 return 0;
860}
861
862/**
863 * uvd_v6_0_stop - stop UVD block
864 *
865 * @adev: amdgpu_device pointer
866 *
867 * stop the UVD block
868 */
869static void uvd_v6_0_stop(struct amdgpu_device *adev)
870{
871 /* force RBC into idle state */
872 WREG32(mmUVD_RBC_RB_CNTL, 0x11010101)amdgpu_device_wreg(adev, (0x3da9), (0x11010101), 0);
873
874 /* Stall UMC and register bus before resetting VCPU */
875 WREG32_P(mmUVD_LMI_CTRL2, 1 << 8, ~(1 << 8))do { uint32_t tmp_ = amdgpu_device_rreg(adev, (0x3d3d), 0); tmp_
&= (~(1 << 8)); tmp_ |= ((1 << 8) & ~(~(
1 << 8))); amdgpu_device_wreg(adev, (0x3d3d), (tmp_), 0
); } while (0)
;
876 mdelay(1);
877
878 /* put VCPU into reset */
879 WREG32(mmUVD_SOFT_RESET, UVD_SOFT_RESET__VCPU_SOFT_RESET_MASK)amdgpu_device_wreg(adev, (0x3da0), (0x8), 0);
880 mdelay(5);
881
882 /* disable VCPU clock */
883 WREG32(mmUVD_VCPU_CNTL, 0x0)amdgpu_device_wreg(adev, (0x3d98), (0x0), 0);
884
885 /* Unstall UMC and register bus */
886 WREG32_P(mmUVD_LMI_CTRL2, 0, ~(1 << 8))do { uint32_t tmp_ = amdgpu_device_rreg(adev, (0x3d3d), 0); tmp_
&= (~(1 << 8)); tmp_ |= ((0) & ~(~(1 << 8
))); amdgpu_device_wreg(adev, (0x3d3d), (tmp_), 0); } while (
0)
;
887
888 WREG32(mmUVD_STATUS, 0)amdgpu_device_wreg(adev, (0x3daf), (0), 0);
889}
890
891/**
892 * uvd_v6_0_ring_emit_fence - emit an fence & trap command
893 *
894 * @ring: amdgpu_ring pointer
895 * @fence: fence to emit
896 *
897 * Write a fence and a trap command to the ring.
898 */
899static void uvd_v6_0_ring_emit_fence(struct amdgpu_ring *ring, u64 addr, u64 seq,
900 unsigned flags)
901{
902 WARN_ON(flags & AMDGPU_FENCE_FLAG_64BIT)({ int __ret = !!(flags & (1 << 0)); if (__ret) printf
("WARNING %s failed at %s:%d\n", "flags & (1 << 0)"
, "/usr/src/sys/dev/pci/drm/amd/amdgpu/uvd_v6_0.c", 902); __builtin_expect
(!!(__ret), 0); })
;
903
904 amdgpu_ring_write(ring, PACKET0(mmUVD_CONTEXT_ID, 0)((0 << 30) | ((0x3dbd) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
);
905 amdgpu_ring_write(ring, seq);
906 amdgpu_ring_write(ring, PACKET0(mmUVD_GPCOM_VCPU_DATA0, 0)((0 << 30) | ((0x3bc4) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
);
907 amdgpu_ring_write(ring, addr & 0xffffffff);
908 amdgpu_ring_write(ring, PACKET0(mmUVD_GPCOM_VCPU_DATA1, 0)((0 << 30) | ((0x3bc5) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
);
909 amdgpu_ring_write(ring, upper_32_bits(addr)((u32)(((addr) >> 16) >> 16)) & 0xff);
910 amdgpu_ring_write(ring, PACKET0(mmUVD_GPCOM_VCPU_CMD, 0)((0 << 30) | ((0x3bc3) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
);
911 amdgpu_ring_write(ring, 0);
912
913 amdgpu_ring_write(ring, PACKET0(mmUVD_GPCOM_VCPU_DATA0, 0)((0 << 30) | ((0x3bc4) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
);
914 amdgpu_ring_write(ring, 0);
915 amdgpu_ring_write(ring, PACKET0(mmUVD_GPCOM_VCPU_DATA1, 0)((0 << 30) | ((0x3bc5) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
);
916 amdgpu_ring_write(ring, 0);
917 amdgpu_ring_write(ring, PACKET0(mmUVD_GPCOM_VCPU_CMD, 0)((0 << 30) | ((0x3bc3) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
);
918 amdgpu_ring_write(ring, 2);
919}
920
921/**
922 * uvd_v6_0_enc_ring_emit_fence - emit an enc fence & trap command
923 *
924 * @ring: amdgpu_ring pointer
925 * @fence: fence to emit
926 *
927 * Write enc a fence and a trap command to the ring.
928 */
929static void uvd_v6_0_enc_ring_emit_fence(struct amdgpu_ring *ring, u64 addr,
930 u64 seq, unsigned flags)
931{
932 WARN_ON(flags & AMDGPU_FENCE_FLAG_64BIT)({ int __ret = !!(flags & (1 << 0)); if (__ret) printf
("WARNING %s failed at %s:%d\n", "flags & (1 << 0)"
, "/usr/src/sys/dev/pci/drm/amd/amdgpu/uvd_v6_0.c", 932); __builtin_expect
(!!(__ret), 0); })
;
933
934 amdgpu_ring_write(ring, HEVC_ENC_CMD_FENCE0x00000003);
935 amdgpu_ring_write(ring, addr);
936 amdgpu_ring_write(ring, upper_32_bits(addr)((u32)(((addr) >> 16) >> 16)));
937 amdgpu_ring_write(ring, seq);
938 amdgpu_ring_write(ring, HEVC_ENC_CMD_TRAP0x00000004);
939}
940
941/**
942 * uvd_v6_0_ring_emit_hdp_flush - skip HDP flushing
943 *
944 * @ring: amdgpu_ring pointer
945 */
946static void uvd_v6_0_ring_emit_hdp_flush(struct amdgpu_ring *ring)
947{
948 /* The firmware doesn't seem to like touching registers at this point. */
949}
950
951/**
952 * uvd_v6_0_ring_test_ring - register write test
953 *
954 * @ring: amdgpu_ring pointer
955 *
956 * Test if we can successfully write to the context register
957 */
958static int uvd_v6_0_ring_test_ring(struct amdgpu_ring *ring)
959{
960 struct amdgpu_device *adev = ring->adev;
961 uint32_t tmp = 0;
962 unsigned i;
963 int r;
964
965 WREG32(mmUVD_CONTEXT_ID, 0xCAFEDEAD)amdgpu_device_wreg(adev, (0x3dbd), (0xCAFEDEAD), 0);
966 r = amdgpu_ring_alloc(ring, 3);
967 if (r)
968 return r;
969
970 amdgpu_ring_write(ring, PACKET0(mmUVD_CONTEXT_ID, 0)((0 << 30) | ((0x3dbd) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
);
971 amdgpu_ring_write(ring, 0xDEADBEEF);
972 amdgpu_ring_commit(ring);
973 for (i = 0; i < adev->usec_timeout; i++) {
974 tmp = RREG32(mmUVD_CONTEXT_ID)amdgpu_device_rreg(adev, (0x3dbd), 0);
975 if (tmp == 0xDEADBEEF)
976 break;
977 udelay(1);
978 }
979
980 if (i >= adev->usec_timeout)
981 r = -ETIMEDOUT60;
982
983 return r;
984}
985
986/**
987 * uvd_v6_0_ring_emit_ib - execute indirect buffer
988 *
989 * @ring: amdgpu_ring pointer
990 * @ib: indirect buffer to execute
991 *
992 * Write ring commands to execute the indirect buffer
993 */
994static void uvd_v6_0_ring_emit_ib(struct amdgpu_ring *ring,
995 struct amdgpu_job *job,
996 struct amdgpu_ib *ib,
997 uint32_t flags)
998{
999 unsigned vmid = AMDGPU_JOB_GET_VMID(job)((job) ? (job)->vmid : 0);
1000
1001 amdgpu_ring_write(ring, PACKET0(mmUVD_LMI_RBC_IB_VMID, 0)((0 << 30) | ((0x3da1) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
);
1002 amdgpu_ring_write(ring, vmid);
1003
1004 amdgpu_ring_write(ring, PACKET0(mmUVD_LMI_RBC_IB_64BIT_BAR_LOW, 0)((0 << 30) | ((0x3c67) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
);
1005 amdgpu_ring_write(ring, lower_32_bits(ib->gpu_addr)((u32)(ib->gpu_addr)));
1006 amdgpu_ring_write(ring, PACKET0(mmUVD_LMI_RBC_IB_64BIT_BAR_HIGH, 0)((0 << 30) | ((0x3c66) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
);
1007 amdgpu_ring_write(ring, upper_32_bits(ib->gpu_addr)((u32)(((ib->gpu_addr) >> 16) >> 16)));
1008 amdgpu_ring_write(ring, PACKET0(mmUVD_RBC_IB_SIZE, 0)((0 << 30) | ((0x3da2) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
);
1009 amdgpu_ring_write(ring, ib->length_dw);
1010}
1011
1012/**
1013 * uvd_v6_0_enc_ring_emit_ib - enc execute indirect buffer
1014 *
1015 * @ring: amdgpu_ring pointer
1016 * @ib: indirect buffer to execute
1017 *
1018 * Write enc ring commands to execute the indirect buffer
1019 */
1020static void uvd_v6_0_enc_ring_emit_ib(struct amdgpu_ring *ring,
1021 struct amdgpu_job *job,
1022 struct amdgpu_ib *ib,
1023 uint32_t flags)
1024{
1025 unsigned vmid = AMDGPU_JOB_GET_VMID(job)((job) ? (job)->vmid : 0);
1026
1027 amdgpu_ring_write(ring, HEVC_ENC_CMD_IB_VM0x00000102);
1028 amdgpu_ring_write(ring, vmid);
1029 amdgpu_ring_write(ring, lower_32_bits(ib->gpu_addr)((u32)(ib->gpu_addr)));
1030 amdgpu_ring_write(ring, upper_32_bits(ib->gpu_addr)((u32)(((ib->gpu_addr) >> 16) >> 16)));
1031 amdgpu_ring_write(ring, ib->length_dw);
1032}
1033
1034static void uvd_v6_0_ring_emit_wreg(struct amdgpu_ring *ring,
1035 uint32_t reg, uint32_t val)
1036{
1037 amdgpu_ring_write(ring, PACKET0(mmUVD_GPCOM_VCPU_DATA0, 0)((0 << 30) | ((0x3bc4) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
);
1038 amdgpu_ring_write(ring, reg << 2);
1039 amdgpu_ring_write(ring, PACKET0(mmUVD_GPCOM_VCPU_DATA1, 0)((0 << 30) | ((0x3bc5) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
);
1040 amdgpu_ring_write(ring, val);
1041 amdgpu_ring_write(ring, PACKET0(mmUVD_GPCOM_VCPU_CMD, 0)((0 << 30) | ((0x3bc3) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
);
1042 amdgpu_ring_write(ring, 0x8);
1043}
1044
1045static void uvd_v6_0_ring_emit_vm_flush(struct amdgpu_ring *ring,
1046 unsigned vmid, uint64_t pd_addr)
1047{
1048 amdgpu_gmc_emit_flush_gpu_tlb(ring, vmid, pd_addr)(ring)->adev->gmc.gmc_funcs->emit_flush_gpu_tlb((ring
), (vmid), (pd_addr))
;
1049
1050 amdgpu_ring_write(ring, PACKET0(mmUVD_GPCOM_VCPU_DATA0, 0)((0 << 30) | ((0x3bc4) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
);
1051 amdgpu_ring_write(ring, mmVM_INVALIDATE_REQUEST0x51e << 2);
1052 amdgpu_ring_write(ring, PACKET0(mmUVD_GPCOM_VCPU_DATA1, 0)((0 << 30) | ((0x3bc5) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
);
1053 amdgpu_ring_write(ring, 0);
1054 amdgpu_ring_write(ring, PACKET0(mmUVD_GP_SCRATCH8, 0)((0 << 30) | ((0x3c0a) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
);
1055 amdgpu_ring_write(ring, 1 << vmid); /* mask */
1056 amdgpu_ring_write(ring, PACKET0(mmUVD_GPCOM_VCPU_CMD, 0)((0 << 30) | ((0x3bc3) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
);
1057 amdgpu_ring_write(ring, 0xC);
1058}
1059
1060static void uvd_v6_0_ring_emit_pipeline_sync(struct amdgpu_ring *ring)
1061{
1062 uint32_t seq = ring->fence_drv.sync_seq;
1063 uint64_t addr = ring->fence_drv.gpu_addr;
1064
1065 amdgpu_ring_write(ring, PACKET0(mmUVD_GPCOM_VCPU_DATA0, 0)((0 << 30) | ((0x3bc4) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
);
1066 amdgpu_ring_write(ring, lower_32_bits(addr)((u32)(addr)));
1067 amdgpu_ring_write(ring, PACKET0(mmUVD_GPCOM_VCPU_DATA1, 0)((0 << 30) | ((0x3bc5) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
);
1068 amdgpu_ring_write(ring, upper_32_bits(addr)((u32)(((addr) >> 16) >> 16)));
1069 amdgpu_ring_write(ring, PACKET0(mmUVD_GP_SCRATCH8, 0)((0 << 30) | ((0x3c0a) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
);
1070 amdgpu_ring_write(ring, 0xffffffff); /* mask */
1071 amdgpu_ring_write(ring, PACKET0(mmUVD_GP_SCRATCH9, 0)((0 << 30) | ((0x3c0b) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
);
1072 amdgpu_ring_write(ring, seq);
1073 amdgpu_ring_write(ring, PACKET0(mmUVD_GPCOM_VCPU_CMD, 0)((0 << 30) | ((0x3bc3) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
);
1074 amdgpu_ring_write(ring, 0xE);
1075}
1076
1077static void uvd_v6_0_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count)
1078{
1079 int i;
1080
1081 WARN_ON(ring->wptr % 2 || count % 2)({ int __ret = !!(ring->wptr % 2 || count % 2); if (__ret)
printf("WARNING %s failed at %s:%d\n", "ring->wptr % 2 || count % 2"
, "/usr/src/sys/dev/pci/drm/amd/amdgpu/uvd_v6_0.c", 1081); __builtin_expect
(!!(__ret), 0); })
;
1082
1083 for (i = 0; i < count / 2; i++) {
1084 amdgpu_ring_write(ring, PACKET0(mmUVD_NO_OP, 0)((0 << 30) | ((0x3bff) & 0xFFFF) | ((0) & 0x3FFF
) << 16)
);
1085 amdgpu_ring_write(ring, 0);
1086 }
1087}
1088
1089static void uvd_v6_0_enc_ring_emit_pipeline_sync(struct amdgpu_ring *ring)
1090{
1091 uint32_t seq = ring->fence_drv.sync_seq;
1092 uint64_t addr = ring->fence_drv.gpu_addr;
1093
1094 amdgpu_ring_write(ring, HEVC_ENC_CMD_WAIT_GE0x00000106);
1095 amdgpu_ring_write(ring, lower_32_bits(addr)((u32)(addr)));
1096 amdgpu_ring_write(ring, upper_32_bits(addr)((u32)(((addr) >> 16) >> 16)));
1097 amdgpu_ring_write(ring, seq);
1098}
1099
1100static void uvd_v6_0_enc_ring_insert_end(struct amdgpu_ring *ring)
1101{
1102 amdgpu_ring_write(ring, HEVC_ENC_CMD_END0x00000001);
1103}
1104
1105static void uvd_v6_0_enc_ring_emit_vm_flush(struct amdgpu_ring *ring,
1106 unsigned int vmid, uint64_t pd_addr)
1107{
1108 amdgpu_ring_write(ring, HEVC_ENC_CMD_UPDATE_PTB0x00000107);
1109 amdgpu_ring_write(ring, vmid);
1110 amdgpu_ring_write(ring, pd_addr >> 12);
1111
1112 amdgpu_ring_write(ring, HEVC_ENC_CMD_FLUSH_TLB0x00000108);
1113 amdgpu_ring_write(ring, vmid);
1114}
1115
1116static bool_Bool uvd_v6_0_is_idle(void *handle)
1117{
1118 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1119
1120 return !(RREG32(mmSRBM_STATUS)amdgpu_device_rreg(adev, (0x394), 0) & SRBM_STATUS__UVD_BUSY_MASK0x80000);
1121}
1122
1123static int uvd_v6_0_wait_for_idle(void *handle)
1124{
1125 unsigned i;
1126 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1127
1128 for (i = 0; i < adev->usec_timeout; i++) {
1129 if (uvd_v6_0_is_idle(handle))
1130 return 0;
1131 }
1132 return -ETIMEDOUT60;
1133}
1134
1135#define AMDGPU_UVD_STATUS_BUSY_MASK0xfd 0xfd
1136static bool_Bool uvd_v6_0_check_soft_reset(void *handle)
1137{
1138 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1139 u32 srbm_soft_reset = 0;
1140 u32 tmp = RREG32(mmSRBM_STATUS)amdgpu_device_rreg(adev, (0x394), 0);
1141
1142 if (REG_GET_FIELD(tmp, SRBM_STATUS, UVD_RQ_PENDING)(((tmp) & 0x2) >> 0x1) ||
1143 REG_GET_FIELD(tmp, SRBM_STATUS, UVD_BUSY)(((tmp) & 0x80000) >> 0x13) ||
1144 (RREG32(mmUVD_STATUS)amdgpu_device_rreg(adev, (0x3daf), 0) & AMDGPU_UVD_STATUS_BUSY_MASK0xfd))
1145 srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET, SOFT_RESET_UVD, 1)(((srbm_soft_reset) & ~0x40000) | (0x40000 & ((1) <<
0x12)))
;
1146
1147 if (srbm_soft_reset) {
1148 adev->uvd.inst->srbm_soft_reset = srbm_soft_reset;
1149 return true1;
1150 } else {
1151 adev->uvd.inst->srbm_soft_reset = 0;
1152 return false0;
1153 }
1154}
1155
1156static int uvd_v6_0_pre_soft_reset(void *handle)
1157{
1158 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1159
1160 if (!adev->uvd.inst->srbm_soft_reset)
1161 return 0;
1162
1163 uvd_v6_0_stop(adev);
1164 return 0;
1165}
1166
1167static int uvd_v6_0_soft_reset(void *handle)
1168{
1169 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1170 u32 srbm_soft_reset;
1171
1172 if (!adev->uvd.inst->srbm_soft_reset)
1173 return 0;
1174 srbm_soft_reset = adev->uvd.inst->srbm_soft_reset;
1175
1176 if (srbm_soft_reset) {
1177 u32 tmp;
1178
1179 tmp = RREG32(mmSRBM_SOFT_RESET)amdgpu_device_rreg(adev, (0x398), 0);
1180 tmp |= srbm_soft_reset;
1181 dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp)do { } while(0);
1182 WREG32(mmSRBM_SOFT_RESET, tmp)amdgpu_device_wreg(adev, (0x398), (tmp), 0);
1183 tmp = RREG32(mmSRBM_SOFT_RESET)amdgpu_device_rreg(adev, (0x398), 0);
1184
1185 udelay(50);
1186
1187 tmp &= ~srbm_soft_reset;
1188 WREG32(mmSRBM_SOFT_RESET, tmp)amdgpu_device_wreg(adev, (0x398), (tmp), 0);
1189 tmp = RREG32(mmSRBM_SOFT_RESET)amdgpu_device_rreg(adev, (0x398), 0);
Value stored to 'tmp' is never read
1190
1191 /* Wait a little for things to settle down */
1192 udelay(50);
1193 }
1194
1195 return 0;
1196}
1197
1198static int uvd_v6_0_post_soft_reset(void *handle)
1199{
1200 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1201
1202 if (!adev->uvd.inst->srbm_soft_reset)
1203 return 0;
1204
1205 mdelay(5);
1206
1207 return uvd_v6_0_start(adev);
1208}
1209
1210static int uvd_v6_0_set_interrupt_state(struct amdgpu_device *adev,
1211 struct amdgpu_irq_src *source,
1212 unsigned type,
1213 enum amdgpu_interrupt_state state)
1214{
1215 // TODO
1216 return 0;
1217}
1218
1219static int uvd_v6_0_process_interrupt(struct amdgpu_device *adev,
1220 struct amdgpu_irq_src *source,
1221 struct amdgpu_iv_entry *entry)
1222{
1223 bool_Bool int_handled = true1;
1224 DRM_DEBUG("IH: UVD TRAP\n")__drm_dbg(DRM_UT_CORE, "IH: UVD TRAP\n");
1225
1226 switch (entry->src_id) {
1227 case 124:
1228 amdgpu_fence_process(&adev->uvd.inst->ring);
1229 break;
1230 case 119:
1231 if (likely(uvd_v6_0_enc_support(adev))__builtin_expect(!!(uvd_v6_0_enc_support(adev)), 1))
1232 amdgpu_fence_process(&adev->uvd.inst->ring_enc[0]);
1233 else
1234 int_handled = false0;
1235 break;
1236 case 120:
1237 if (likely(uvd_v6_0_enc_support(adev))__builtin_expect(!!(uvd_v6_0_enc_support(adev)), 1))
1238 amdgpu_fence_process(&adev->uvd.inst->ring_enc[1]);
1239 else
1240 int_handled = false0;
1241 break;
1242 }
1243
1244 if (!int_handled)
1245 DRM_ERROR("Unhandled interrupt: %d %d\n",__drm_err("Unhandled interrupt: %d %d\n", entry->src_id, entry
->src_data[0])
1246 entry->src_id, entry->src_data[0])__drm_err("Unhandled interrupt: %d %d\n", entry->src_id, entry
->src_data[0])
;
1247
1248 return 0;
1249}
1250
1251static void uvd_v6_0_enable_clock_gating(struct amdgpu_device *adev, bool_Bool enable)
1252{
1253 uint32_t data1, data3;
1254
1255 data1 = RREG32(mmUVD_SUVD_CGC_GATE)amdgpu_device_rreg(adev, (0x3be4), 0);
1256 data3 = RREG32(mmUVD_CGC_GATE)amdgpu_device_rreg(adev, (0x3d2a), 0);
1257
1258 data1 |= UVD_SUVD_CGC_GATE__SRE_MASK0x1 |
1259 UVD_SUVD_CGC_GATE__SIT_MASK0x2 |
1260 UVD_SUVD_CGC_GATE__SMP_MASK0x4 |
1261 UVD_SUVD_CGC_GATE__SCM_MASK0x8 |
1262 UVD_SUVD_CGC_GATE__SDB_MASK0x10 |
1263 UVD_SUVD_CGC_GATE__SRE_H264_MASK0x20 |
1264 UVD_SUVD_CGC_GATE__SRE_HEVC_MASK0x40 |
1265 UVD_SUVD_CGC_GATE__SIT_H264_MASK0x80 |
1266 UVD_SUVD_CGC_GATE__SIT_HEVC_MASK0x100 |
1267 UVD_SUVD_CGC_GATE__SCM_H264_MASK0x200 |
1268 UVD_SUVD_CGC_GATE__SCM_HEVC_MASK0x400 |
1269 UVD_SUVD_CGC_GATE__SDB_H264_MASK0x800 |
1270 UVD_SUVD_CGC_GATE__SDB_HEVC_MASK0x1000;
1271
1272 if (enable) {
1273 data3 |= (UVD_CGC_GATE__SYS_MASK0x1 |
1274 UVD_CGC_GATE__UDEC_MASK0x2 |
1275 UVD_CGC_GATE__MPEG2_MASK0x4 |
1276 UVD_CGC_GATE__RBC_MASK0x10 |
1277 UVD_CGC_GATE__LMI_MC_MASK0x20 |
1278 UVD_CGC_GATE__LMI_UMC_MASK0x40 |
1279 UVD_CGC_GATE__IDCT_MASK0x80 |
1280 UVD_CGC_GATE__MPRD_MASK0x100 |
1281 UVD_CGC_GATE__MPC_MASK0x200 |
1282 UVD_CGC_GATE__LBSI_MASK0x400 |
1283 UVD_CGC_GATE__LRBBM_MASK0x800 |
1284 UVD_CGC_GATE__UDEC_RE_MASK0x1000 |
1285 UVD_CGC_GATE__UDEC_CM_MASK0x2000 |
1286 UVD_CGC_GATE__UDEC_IT_MASK0x4000 |
1287 UVD_CGC_GATE__UDEC_DB_MASK0x8000 |
1288 UVD_CGC_GATE__UDEC_MP_MASK0x10000 |
1289 UVD_CGC_GATE__WCB_MASK0x20000 |
1290 UVD_CGC_GATE__JPEG_MASK0x100000 |
1291 UVD_CGC_GATE__SCPU_MASK0x80000 |
1292 UVD_CGC_GATE__JPEG2_MASK0x200000);
1293 /* only in pg enabled, we can gate clock to vcpu*/
1294 if (adev->pg_flags & AMD_PG_SUPPORT_UVD(1 << 3))
1295 data3 |= UVD_CGC_GATE__VCPU_MASK0x40000;
1296
1297 data3 &= ~UVD_CGC_GATE__REGS_MASK0x8;
1298 } else {
1299 data3 = 0;
1300 }
1301
1302 WREG32(mmUVD_SUVD_CGC_GATE, data1)amdgpu_device_wreg(adev, (0x3be4), (data1), 0);
1303 WREG32(mmUVD_CGC_GATE, data3)amdgpu_device_wreg(adev, (0x3d2a), (data3), 0);
1304}
1305
1306static void uvd_v6_0_set_sw_clock_gating(struct amdgpu_device *adev)
1307{
1308 uint32_t data, data2;
1309
1310 data = RREG32(mmUVD_CGC_CTRL)amdgpu_device_rreg(adev, (0x3d2c), 0);
1311 data2 = RREG32(mmUVD_SUVD_CGC_CTRL)amdgpu_device_rreg(adev, (0x3be6), 0);
1312
1313
1314 data &= ~(UVD_CGC_CTRL__CLK_OFF_DELAY_MASK0x7c0 |
1315 UVD_CGC_CTRL__CLK_GATE_DLY_TIMER_MASK0x3c);
1316
1317
1318 data |= UVD_CGC_CTRL__DYN_CLOCK_MODE_MASK0x1 |
1319 (1 << REG_FIELD_SHIFT(UVD_CGC_CTRL, CLK_GATE_DLY_TIMER)0x2) |
1320 (4 << REG_FIELD_SHIFT(UVD_CGC_CTRL, CLK_OFF_DELAY)0x6);
1321
1322 data &= ~(UVD_CGC_CTRL__UDEC_RE_MODE_MASK0x800 |
1323 UVD_CGC_CTRL__UDEC_CM_MODE_MASK0x1000 |
1324 UVD_CGC_CTRL__UDEC_IT_MODE_MASK0x2000 |
1325 UVD_CGC_CTRL__UDEC_DB_MODE_MASK0x4000 |
1326 UVD_CGC_CTRL__UDEC_MP_MODE_MASK0x8000 |
1327 UVD_CGC_CTRL__SYS_MODE_MASK0x10000 |
1328 UVD_CGC_CTRL__UDEC_MODE_MASK0x20000 |
1329 UVD_CGC_CTRL__MPEG2_MODE_MASK0x40000 |
1330 UVD_CGC_CTRL__REGS_MODE_MASK0x80000 |
1331 UVD_CGC_CTRL__RBC_MODE_MASK0x100000 |
1332 UVD_CGC_CTRL__LMI_MC_MODE_MASK0x200000 |
1333 UVD_CGC_CTRL__LMI_UMC_MODE_MASK0x400000 |
1334 UVD_CGC_CTRL__IDCT_MODE_MASK0x800000 |
1335 UVD_CGC_CTRL__MPRD_MODE_MASK0x1000000 |
1336 UVD_CGC_CTRL__MPC_MODE_MASK0x2000000 |
1337 UVD_CGC_CTRL__LBSI_MODE_MASK0x4000000 |
1338 UVD_CGC_CTRL__LRBBM_MODE_MASK0x8000000 |
1339 UVD_CGC_CTRL__WCB_MODE_MASK0x10000000 |
1340 UVD_CGC_CTRL__VCPU_MODE_MASK0x20000000 |
1341 UVD_CGC_CTRL__JPEG_MODE_MASK0x80000000 |
1342 UVD_CGC_CTRL__SCPU_MODE_MASK0x40000000 |
1343 UVD_CGC_CTRL__JPEG2_MODE_MASK0x2);
1344 data2 &= ~(UVD_SUVD_CGC_CTRL__SRE_MODE_MASK0x1 |
1345 UVD_SUVD_CGC_CTRL__SIT_MODE_MASK0x2 |
1346 UVD_SUVD_CGC_CTRL__SMP_MODE_MASK0x4 |
1347 UVD_SUVD_CGC_CTRL__SCM_MODE_MASK0x8 |
1348 UVD_SUVD_CGC_CTRL__SDB_MODE_MASK0x10);
1349
1350 WREG32(mmUVD_CGC_CTRL, data)amdgpu_device_wreg(adev, (0x3d2c), (data), 0);
1351 WREG32(mmUVD_SUVD_CGC_CTRL, data2)amdgpu_device_wreg(adev, (0x3be6), (data2), 0);
1352}
1353
1354#if 0
1355static void uvd_v6_0_set_hw_clock_gating(struct amdgpu_device *adev)
1356{
1357 uint32_t data, data1, cgc_flags, suvd_flags;
1358
1359 data = RREG32(mmUVD_CGC_GATE)amdgpu_device_rreg(adev, (0x3d2a), 0);
1360 data1 = RREG32(mmUVD_SUVD_CGC_GATE)amdgpu_device_rreg(adev, (0x3be4), 0);
1361
1362 cgc_flags = UVD_CGC_GATE__SYS_MASK0x1 |
1363 UVD_CGC_GATE__UDEC_MASK0x2 |
1364 UVD_CGC_GATE__MPEG2_MASK0x4 |
1365 UVD_CGC_GATE__RBC_MASK0x10 |
1366 UVD_CGC_GATE__LMI_MC_MASK0x20 |
1367 UVD_CGC_GATE__IDCT_MASK0x80 |
1368 UVD_CGC_GATE__MPRD_MASK0x100 |
1369 UVD_CGC_GATE__MPC_MASK0x200 |
1370 UVD_CGC_GATE__LBSI_MASK0x400 |
1371 UVD_CGC_GATE__LRBBM_MASK0x800 |
1372 UVD_CGC_GATE__UDEC_RE_MASK0x1000 |
1373 UVD_CGC_GATE__UDEC_CM_MASK0x2000 |
1374 UVD_CGC_GATE__UDEC_IT_MASK0x4000 |
1375 UVD_CGC_GATE__UDEC_DB_MASK0x8000 |
1376 UVD_CGC_GATE__UDEC_MP_MASK0x10000 |
1377 UVD_CGC_GATE__WCB_MASK0x20000 |
1378 UVD_CGC_GATE__VCPU_MASK0x40000 |
1379 UVD_CGC_GATE__SCPU_MASK0x80000 |
1380 UVD_CGC_GATE__JPEG_MASK0x100000 |
1381 UVD_CGC_GATE__JPEG2_MASK0x200000;
1382
1383 suvd_flags = UVD_SUVD_CGC_GATE__SRE_MASK0x1 |
1384 UVD_SUVD_CGC_GATE__SIT_MASK0x2 |
1385 UVD_SUVD_CGC_GATE__SMP_MASK0x4 |
1386 UVD_SUVD_CGC_GATE__SCM_MASK0x8 |
1387 UVD_SUVD_CGC_GATE__SDB_MASK0x10;
1388
1389 data |= cgc_flags;
1390 data1 |= suvd_flags;
1391
1392 WREG32(mmUVD_CGC_GATE, data)amdgpu_device_wreg(adev, (0x3d2a), (data), 0);
1393 WREG32(mmUVD_SUVD_CGC_GATE, data1)amdgpu_device_wreg(adev, (0x3be4), (data1), 0);
1394}
1395#endif
1396
1397static void uvd_v6_0_enable_mgcg(struct amdgpu_device *adev,
1398 bool_Bool enable)
1399{
1400 u32 orig, data;
1401
1402 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_UVD_MGCG(1 << 13))) {
1403 data = RREG32_UVD_CTX(ixUVD_CGC_MEM_CTRL)adev->uvd_ctx_rreg(adev, (0xc0));
1404 data |= 0xfff;
1405 WREG32_UVD_CTX(ixUVD_CGC_MEM_CTRL, data)adev->uvd_ctx_wreg(adev, (0xc0), (data));
1406
1407 orig = data = RREG32(mmUVD_CGC_CTRL)amdgpu_device_rreg(adev, (0x3d2c), 0);
1408 data |= UVD_CGC_CTRL__DYN_CLOCK_MODE_MASK0x1;
1409 if (orig != data)
1410 WREG32(mmUVD_CGC_CTRL, data)amdgpu_device_wreg(adev, (0x3d2c), (data), 0);
1411 } else {
1412 data = RREG32_UVD_CTX(ixUVD_CGC_MEM_CTRL)adev->uvd_ctx_rreg(adev, (0xc0));
1413 data &= ~0xfff;
1414 WREG32_UVD_CTX(ixUVD_CGC_MEM_CTRL, data)adev->uvd_ctx_wreg(adev, (0xc0), (data));
1415
1416 orig = data = RREG32(mmUVD_CGC_CTRL)amdgpu_device_rreg(adev, (0x3d2c), 0);
1417 data &= ~UVD_CGC_CTRL__DYN_CLOCK_MODE_MASK0x1;
1418 if (orig != data)
1419 WREG32(mmUVD_CGC_CTRL, data)amdgpu_device_wreg(adev, (0x3d2c), (data), 0);
1420 }
1421}
1422
1423static int uvd_v6_0_set_clockgating_state(void *handle,
1424 enum amd_clockgating_state state)
1425{
1426 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1427 bool_Bool enable = (state == AMD_CG_STATE_GATE);
1428
1429 if (enable) {
1430 /* wait for STATUS to clear */
1431 if (uvd_v6_0_wait_for_idle(handle))
1432 return -EBUSY16;
1433 uvd_v6_0_enable_clock_gating(adev, true1);
1434 /* enable HW gates because UVD is idle */
1435/* uvd_v6_0_set_hw_clock_gating(adev); */
1436 } else {
1437 /* disable HW gating and enable Sw gating */
1438 uvd_v6_0_enable_clock_gating(adev, false0);
1439 }
1440 uvd_v6_0_set_sw_clock_gating(adev);
1441 return 0;
1442}
1443
1444static int uvd_v6_0_set_powergating_state(void *handle,
1445 enum amd_powergating_state state)
1446{
1447 /* This doesn't actually powergate the UVD block.
1448 * That's done in the dpm code via the SMC. This
1449 * just re-inits the block as necessary. The actual
1450 * gating still happens in the dpm code. We should
1451 * revisit this when there is a cleaner line between
1452 * the smc and the hw blocks
1453 */
1454 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1455 int ret = 0;
1456
1457 WREG32(mmUVD_POWER_STATUS, UVD_POWER_STATUS__UVD_PG_EN_MASK)amdgpu_device_wreg(adev, (0x38c4), (0x100), 0);
1458
1459 if (state == AMD_PG_STATE_GATE) {
1460 uvd_v6_0_stop(adev);
1461 } else {
1462 ret = uvd_v6_0_start(adev);
1463 if (ret)
1464 goto out;
1465 }
1466
1467out:
1468 return ret;
1469}
1470
1471static void uvd_v6_0_get_clockgating_state(void *handle, u32 *flags)
1472{
1473 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1474 int data;
1475
1476 mutex_lock(&adev->pm.mutex)rw_enter_write(&adev->pm.mutex);
1477
1478 if (adev->flags & AMD_IS_APU)
1479 data = RREG32_SMC(ixCURRENT_PG_STATUS_APU)adev->smc_rreg(adev, (0xd020029c));
1480 else
1481 data = RREG32_SMC(ixCURRENT_PG_STATUS)adev->smc_rreg(adev, (0xc020029c));
1482
1483 if (data & CURRENT_PG_STATUS__UVD_PG_STATUS_MASK0x00000004) {
1484 DRM_INFO("Cannot get clockgating state when UVD is powergated.\n")printk("\0016" "[" "drm" "] " "Cannot get clockgating state when UVD is powergated.\n"
)
;
1485 goto out;
1486 }
1487
1488 /* AMD_CG_SUPPORT_UVD_MGCG */
1489 data = RREG32(mmUVD_CGC_CTRL)amdgpu_device_rreg(adev, (0x3d2c), 0);
1490 if (data & UVD_CGC_CTRL__DYN_CLOCK_MODE_MASK0x1)
1491 *flags |= AMD_CG_SUPPORT_UVD_MGCG(1 << 13);
1492
1493out:
1494 mutex_unlock(&adev->pm.mutex)rw_exit_write(&adev->pm.mutex);
1495}
1496
1497static const struct amd_ip_funcs uvd_v6_0_ip_funcs = {
1498 .name = "uvd_v6_0",
1499 .early_init = uvd_v6_0_early_init,
1500 .late_init = NULL((void *)0),
1501 .sw_init = uvd_v6_0_sw_init,
1502 .sw_fini = uvd_v6_0_sw_fini,
1503 .hw_init = uvd_v6_0_hw_init,
1504 .hw_fini = uvd_v6_0_hw_fini,
1505 .suspend = uvd_v6_0_suspend,
1506 .resume = uvd_v6_0_resume,
1507 .is_idle = uvd_v6_0_is_idle,
1508 .wait_for_idle = uvd_v6_0_wait_for_idle,
1509 .check_soft_reset = uvd_v6_0_check_soft_reset,
1510 .pre_soft_reset = uvd_v6_0_pre_soft_reset,
1511 .soft_reset = uvd_v6_0_soft_reset,
1512 .post_soft_reset = uvd_v6_0_post_soft_reset,
1513 .set_clockgating_state = uvd_v6_0_set_clockgating_state,
1514 .set_powergating_state = uvd_v6_0_set_powergating_state,
1515 .get_clockgating_state = uvd_v6_0_get_clockgating_state,
1516};
1517
1518static const struct amdgpu_ring_funcs uvd_v6_0_ring_phys_funcs = {
1519 .type = AMDGPU_RING_TYPE_UVD,
1520 .align_mask = 0xf,
1521 .support_64bit_ptrs = false0,
1522 .no_user_fence = true1,
1523 .get_rptr = uvd_v6_0_ring_get_rptr,
1524 .get_wptr = uvd_v6_0_ring_get_wptr,
1525 .set_wptr = uvd_v6_0_ring_set_wptr,
1526 .parse_cs = amdgpu_uvd_ring_parse_cs,
1527 .emit_frame_size =
1528 6 + /* hdp invalidate */
1529 10 + /* uvd_v6_0_ring_emit_pipeline_sync */
1530 14, /* uvd_v6_0_ring_emit_fence x1 no user fence */
1531 .emit_ib_size = 8, /* uvd_v6_0_ring_emit_ib */
1532 .emit_ib = uvd_v6_0_ring_emit_ib,
1533 .emit_fence = uvd_v6_0_ring_emit_fence,
1534 .emit_hdp_flush = uvd_v6_0_ring_emit_hdp_flush,
1535 .test_ring = uvd_v6_0_ring_test_ring,
1536 .test_ib = amdgpu_uvd_ring_test_ib,
1537 .insert_nop = uvd_v6_0_ring_insert_nop,
1538 .pad_ib = amdgpu_ring_generic_pad_ib,
1539 .begin_use = amdgpu_uvd_ring_begin_use,
1540 .end_use = amdgpu_uvd_ring_end_use,
1541 .emit_wreg = uvd_v6_0_ring_emit_wreg,
1542};
1543
1544static const struct amdgpu_ring_funcs uvd_v6_0_ring_vm_funcs = {
1545 .type = AMDGPU_RING_TYPE_UVD,
1546 .align_mask = 0xf,
1547 .support_64bit_ptrs = false0,
1548 .no_user_fence = true1,
1549 .get_rptr = uvd_v6_0_ring_get_rptr,
1550 .get_wptr = uvd_v6_0_ring_get_wptr,
1551 .set_wptr = uvd_v6_0_ring_set_wptr,
1552 .emit_frame_size =
1553 6 + /* hdp invalidate */
1554 10 + /* uvd_v6_0_ring_emit_pipeline_sync */
1555 VI_FLUSH_GPU_TLB_NUM_WREG3 * 6 + 8 + /* uvd_v6_0_ring_emit_vm_flush */
1556 14 + 14, /* uvd_v6_0_ring_emit_fence x2 vm fence */
1557 .emit_ib_size = 8, /* uvd_v6_0_ring_emit_ib */
1558 .emit_ib = uvd_v6_0_ring_emit_ib,
1559 .emit_fence = uvd_v6_0_ring_emit_fence,
1560 .emit_vm_flush = uvd_v6_0_ring_emit_vm_flush,
1561 .emit_pipeline_sync = uvd_v6_0_ring_emit_pipeline_sync,
1562 .emit_hdp_flush = uvd_v6_0_ring_emit_hdp_flush,
1563 .test_ring = uvd_v6_0_ring_test_ring,
1564 .test_ib = amdgpu_uvd_ring_test_ib,
1565 .insert_nop = uvd_v6_0_ring_insert_nop,
1566 .pad_ib = amdgpu_ring_generic_pad_ib,
1567 .begin_use = amdgpu_uvd_ring_begin_use,
1568 .end_use = amdgpu_uvd_ring_end_use,
1569 .emit_wreg = uvd_v6_0_ring_emit_wreg,
1570};
1571
1572static const struct amdgpu_ring_funcs uvd_v6_0_enc_ring_vm_funcs = {
1573 .type = AMDGPU_RING_TYPE_UVD_ENC,
1574 .align_mask = 0x3f,
1575 .nop = HEVC_ENC_CMD_NO_OP0x00000000,
1576 .support_64bit_ptrs = false0,
1577 .no_user_fence = true1,
1578 .get_rptr = uvd_v6_0_enc_ring_get_rptr,
1579 .get_wptr = uvd_v6_0_enc_ring_get_wptr,
1580 .set_wptr = uvd_v6_0_enc_ring_set_wptr,
1581 .emit_frame_size =
1582 4 + /* uvd_v6_0_enc_ring_emit_pipeline_sync */
1583 5 + /* uvd_v6_0_enc_ring_emit_vm_flush */
1584 5 + 5 + /* uvd_v6_0_enc_ring_emit_fence x2 vm fence */
1585 1, /* uvd_v6_0_enc_ring_insert_end */
1586 .emit_ib_size = 5, /* uvd_v6_0_enc_ring_emit_ib */
1587 .emit_ib = uvd_v6_0_enc_ring_emit_ib,
1588 .emit_fence = uvd_v6_0_enc_ring_emit_fence,
1589 .emit_vm_flush = uvd_v6_0_enc_ring_emit_vm_flush,
1590 .emit_pipeline_sync = uvd_v6_0_enc_ring_emit_pipeline_sync,
1591 .test_ring = uvd_v6_0_enc_ring_test_ring,
1592 .test_ib = uvd_v6_0_enc_ring_test_ib,
1593 .insert_nop = amdgpu_ring_insert_nop,
1594 .insert_end = uvd_v6_0_enc_ring_insert_end,
1595 .pad_ib = amdgpu_ring_generic_pad_ib,
1596 .begin_use = amdgpu_uvd_ring_begin_use,
1597 .end_use = amdgpu_uvd_ring_end_use,
1598};
1599
1600static void uvd_v6_0_set_ring_funcs(struct amdgpu_device *adev)
1601{
1602 if (adev->asic_type >= CHIP_POLARIS10) {
1603 adev->uvd.inst->ring.funcs = &uvd_v6_0_ring_vm_funcs;
1604 DRM_INFO("UVD is enabled in VM mode\n")printk("\0016" "[" "drm" "] " "UVD is enabled in VM mode\n");
1605 } else {
1606 adev->uvd.inst->ring.funcs = &uvd_v6_0_ring_phys_funcs;
1607 DRM_INFO("UVD is enabled in physical mode\n")printk("\0016" "[" "drm" "] " "UVD is enabled in physical mode\n"
)
;
1608 }
1609}
1610
1611static void uvd_v6_0_set_enc_ring_funcs(struct amdgpu_device *adev)
1612{
1613 int i;
1614
1615 for (i = 0; i < adev->uvd.num_enc_rings; ++i)
1616 adev->uvd.inst->ring_enc[i].funcs = &uvd_v6_0_enc_ring_vm_funcs;
1617
1618 DRM_INFO("UVD ENC is enabled in VM mode\n")printk("\0016" "[" "drm" "] " "UVD ENC is enabled in VM mode\n"
)
;
1619}
1620
1621static const struct amdgpu_irq_src_funcs uvd_v6_0_irq_funcs = {
1622 .set = uvd_v6_0_set_interrupt_state,
1623 .process = uvd_v6_0_process_interrupt,
1624};
1625
1626static void uvd_v6_0_set_irq_funcs(struct amdgpu_device *adev)
1627{
1628 if (uvd_v6_0_enc_support(adev))
1629 adev->uvd.inst->irq.num_types = adev->uvd.num_enc_rings + 1;
1630 else
1631 adev->uvd.inst->irq.num_types = 1;
1632
1633 adev->uvd.inst->irq.funcs = &uvd_v6_0_irq_funcs;
1634}
1635
1636const struct amdgpu_ip_block_version uvd_v6_0_ip_block =
1637{
1638 .type = AMD_IP_BLOCK_TYPE_UVD,
1639 .major = 6,
1640 .minor = 0,
1641 .rev = 0,
1642 .funcs = &uvd_v6_0_ip_funcs,
1643};
1644
1645const struct amdgpu_ip_block_version uvd_v6_2_ip_block =
1646{
1647 .type = AMD_IP_BLOCK_TYPE_UVD,
1648 .major = 6,
1649 .minor = 2,
1650 .rev = 0,
1651 .funcs = &uvd_v6_0_ip_funcs,
1652};
1653
1654const struct amdgpu_ip_block_version uvd_v6_3_ip_block =
1655{
1656 .type = AMD_IP_BLOCK_TYPE_UVD,
1657 .major = 6,
1658 .minor = 3,
1659 .rev = 0,
1660 .funcs = &uvd_v6_0_ip_funcs,
1661};