2 * Copyright 2013 Advanced Micro Devices, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
16 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
17 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
18 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
19 * USE OR OTHER DEALINGS IN THE SOFTWARE.
21 * The above copyright notice and this permission notice (including the
22 * next paragraph) shall be included in all copies or substantial portions
25 * Authors: Christian König <christian.koenig@amd.com>
28 #include <linux/firmware.h>
29 #include <linux/module.h>
34 #include "amdgpu_pm.h"
35 #include "amdgpu_vce.h"
38 /* 1 second timeout */
39 #define VCE_IDLE_TIMEOUT_MS 1000
42 #ifdef CONFIG_DRM_AMDGPU_CIK
43 #define FIRMWARE_BONAIRE "radeon/bonaire_vce.bin"
44 #define FIRMWARE_KABINI "radeon/kabini_vce.bin"
45 #define FIRMWARE_KAVERI "radeon/kaveri_vce.bin"
46 #define FIRMWARE_HAWAII "radeon/hawaii_vce.bin"
47 #define FIRMWARE_MULLINS "radeon/mullins_vce.bin"
49 #define FIRMWARE_TONGA "amdgpu/tonga_vce.bin"
50 #define FIRMWARE_CARRIZO "amdgpu/carrizo_vce.bin"
52 #ifdef CONFIG_DRM_AMDGPU_CIK
53 MODULE_FIRMWARE(FIRMWARE_BONAIRE
);
54 MODULE_FIRMWARE(FIRMWARE_KABINI
);
55 MODULE_FIRMWARE(FIRMWARE_KAVERI
);
56 MODULE_FIRMWARE(FIRMWARE_HAWAII
);
57 MODULE_FIRMWARE(FIRMWARE_MULLINS
);
59 MODULE_FIRMWARE(FIRMWARE_TONGA
);
60 MODULE_FIRMWARE(FIRMWARE_CARRIZO
);
62 static void amdgpu_vce_idle_work_handler(struct work_struct
*work
);
65 * amdgpu_vce_init - allocate memory, load vce firmware
67 * @adev: amdgpu_device pointer
69 * First step to get VCE online, allocate memory and load the firmware
71 int amdgpu_vce_sw_init(struct amdgpu_device
*adev
, unsigned long size
)
74 const struct common_firmware_header
*hdr
;
75 unsigned ucode_version
, version_major
, version_minor
, binary_id
;
78 INIT_DELAYED_WORK(&adev
->vce
.idle_work
, amdgpu_vce_idle_work_handler
);
80 switch (adev
->asic_type
) {
81 #ifdef CONFIG_DRM_AMDGPU_CIK
83 fw_name
= FIRMWARE_BONAIRE
;
86 fw_name
= FIRMWARE_KAVERI
;
89 fw_name
= FIRMWARE_KABINI
;
92 fw_name
= FIRMWARE_HAWAII
;
95 fw_name
= FIRMWARE_MULLINS
;
99 fw_name
= FIRMWARE_TONGA
;
102 fw_name
= FIRMWARE_CARRIZO
;
109 r
= request_firmware(&adev
->vce
.fw
, fw_name
, adev
->dev
);
111 dev_err(adev
->dev
, "amdgpu_vce: Can't load firmware \"%s\"\n",
116 r
= amdgpu_ucode_validate(adev
->vce
.fw
);
118 dev_err(adev
->dev
, "amdgpu_vce: Can't validate firmware \"%s\"\n",
120 release_firmware(adev
->vce
.fw
);
125 hdr
= (const struct common_firmware_header
*)adev
->vce
.fw
->data
;
127 ucode_version
= le32_to_cpu(hdr
->ucode_version
);
128 version_major
= (ucode_version
>> 20) & 0xfff;
129 version_minor
= (ucode_version
>> 8) & 0xfff;
130 binary_id
= ucode_version
& 0xff;
131 DRM_INFO("Found VCE firmware Version: %hhd.%hhd Binary ID: %hhd\n",
132 version_major
, version_minor
, binary_id
);
133 adev
->vce
.fw_version
= ((version_major
<< 24) | (version_minor
<< 16) |
136 /* allocate firmware, stack and heap BO */
138 r
= amdgpu_bo_create(adev
, size
, PAGE_SIZE
, true,
139 AMDGPU_GEM_DOMAIN_VRAM
, 0, NULL
, &adev
->vce
.vcpu_bo
);
141 dev_err(adev
->dev
, "(%d) failed to allocate VCE bo\n", r
);
145 r
= amdgpu_bo_reserve(adev
->vce
.vcpu_bo
, false);
147 amdgpu_bo_unref(&adev
->vce
.vcpu_bo
);
148 dev_err(adev
->dev
, "(%d) failed to reserve VCE bo\n", r
);
152 r
= amdgpu_bo_pin(adev
->vce
.vcpu_bo
, AMDGPU_GEM_DOMAIN_VRAM
,
153 &adev
->vce
.gpu_addr
);
154 amdgpu_bo_unreserve(adev
->vce
.vcpu_bo
);
156 amdgpu_bo_unref(&adev
->vce
.vcpu_bo
);
157 dev_err(adev
->dev
, "(%d) VCE bo pin failed\n", r
);
161 for (i
= 0; i
< AMDGPU_MAX_VCE_HANDLES
; ++i
) {
162 atomic_set(&adev
->vce
.handles
[i
], 0);
163 adev
->vce
.filp
[i
] = NULL
;
170 * amdgpu_vce_fini - free memory
172 * @adev: amdgpu_device pointer
174 * Last step on VCE teardown, free firmware memory
176 int amdgpu_vce_sw_fini(struct amdgpu_device
*adev
)
178 if (adev
->vce
.vcpu_bo
== NULL
)
181 amdgpu_bo_unref(&adev
->vce
.vcpu_bo
);
183 amdgpu_ring_fini(&adev
->vce
.ring
[0]);
184 amdgpu_ring_fini(&adev
->vce
.ring
[1]);
186 release_firmware(adev
->vce
.fw
);
192 * amdgpu_vce_suspend - unpin VCE fw memory
194 * @adev: amdgpu_device pointer
197 int amdgpu_vce_suspend(struct amdgpu_device
*adev
)
201 if (adev
->vce
.vcpu_bo
== NULL
)
204 for (i
= 0; i
< AMDGPU_MAX_VCE_HANDLES
; ++i
)
205 if (atomic_read(&adev
->vce
.handles
[i
]))
208 if (i
== AMDGPU_MAX_VCE_HANDLES
)
211 /* TODO: suspending running encoding sessions isn't supported */
216 * amdgpu_vce_resume - pin VCE fw memory
218 * @adev: amdgpu_device pointer
221 int amdgpu_vce_resume(struct amdgpu_device
*adev
)
224 const struct common_firmware_header
*hdr
;
228 if (adev
->vce
.vcpu_bo
== NULL
)
231 r
= amdgpu_bo_reserve(adev
->vce
.vcpu_bo
, false);
233 dev_err(adev
->dev
, "(%d) failed to reserve VCE bo\n", r
);
237 r
= amdgpu_bo_kmap(adev
->vce
.vcpu_bo
, &cpu_addr
);
239 amdgpu_bo_unreserve(adev
->vce
.vcpu_bo
);
240 dev_err(adev
->dev
, "(%d) VCE map failed\n", r
);
244 hdr
= (const struct common_firmware_header
*)adev
->vce
.fw
->data
;
245 offset
= le32_to_cpu(hdr
->ucode_array_offset_bytes
);
246 memcpy(cpu_addr
, (adev
->vce
.fw
->data
) + offset
,
247 (adev
->vce
.fw
->size
) - offset
);
249 amdgpu_bo_kunmap(adev
->vce
.vcpu_bo
);
251 amdgpu_bo_unreserve(adev
->vce
.vcpu_bo
);
257 * amdgpu_vce_idle_work_handler - power off VCE
259 * @work: pointer to work structure
261 * power of VCE when it's not used any more
263 static void amdgpu_vce_idle_work_handler(struct work_struct
*work
)
265 struct amdgpu_device
*adev
=
266 container_of(work
, struct amdgpu_device
, vce
.idle_work
.work
);
268 if ((amdgpu_fence_count_emitted(&adev
->vce
.ring
[0]) == 0) &&
269 (amdgpu_fence_count_emitted(&adev
->vce
.ring
[1]) == 0)) {
270 if (adev
->pm
.dpm_enabled
) {
271 amdgpu_dpm_enable_vce(adev
, false);
273 amdgpu_asic_set_vce_clocks(adev
, 0, 0);
276 schedule_delayed_work(&adev
->vce
.idle_work
,
277 msecs_to_jiffies(VCE_IDLE_TIMEOUT_MS
));
282 * amdgpu_vce_note_usage - power up VCE
284 * @adev: amdgpu_device pointer
286 * Make sure VCE is powerd up when we want to use it
288 static void amdgpu_vce_note_usage(struct amdgpu_device
*adev
)
290 bool streams_changed
= false;
291 bool set_clocks
= !cancel_delayed_work_sync(&adev
->vce
.idle_work
);
292 set_clocks
&= schedule_delayed_work(&adev
->vce
.idle_work
,
293 msecs_to_jiffies(VCE_IDLE_TIMEOUT_MS
));
295 if (adev
->pm
.dpm_enabled
) {
296 /* XXX figure out if the streams changed */
297 streams_changed
= false;
300 if (set_clocks
|| streams_changed
) {
301 if (adev
->pm
.dpm_enabled
) {
302 amdgpu_dpm_enable_vce(adev
, true);
304 amdgpu_asic_set_vce_clocks(adev
, 53300, 40000);
310 * amdgpu_vce_free_handles - free still open VCE handles
312 * @adev: amdgpu_device pointer
313 * @filp: drm file pointer
315 * Close all VCE handles still open by this file pointer
317 void amdgpu_vce_free_handles(struct amdgpu_device
*adev
, struct drm_file
*filp
)
319 struct amdgpu_ring
*ring
= &adev
->vce
.ring
[0];
321 for (i
= 0; i
< AMDGPU_MAX_VCE_HANDLES
; ++i
) {
322 uint32_t handle
= atomic_read(&adev
->vce
.handles
[i
]);
323 if (!handle
|| adev
->vce
.filp
[i
] != filp
)
326 amdgpu_vce_note_usage(adev
);
328 r
= amdgpu_vce_get_destroy_msg(ring
, handle
, NULL
);
330 DRM_ERROR("Error destroying VCE handle (%d)!\n", r
);
332 adev
->vce
.filp
[i
] = NULL
;
333 atomic_set(&adev
->vce
.handles
[i
], 0);
338 * amdgpu_vce_get_create_msg - generate a VCE create msg
340 * @adev: amdgpu_device pointer
341 * @ring: ring we should submit the msg to
342 * @handle: VCE session handle to use
343 * @fence: optional fence to return
345 * Open up a stream for HW test
347 int amdgpu_vce_get_create_msg(struct amdgpu_ring
*ring
, uint32_t handle
,
348 struct amdgpu_fence
**fence
)
350 const unsigned ib_size_dw
= 1024;
355 r
= amdgpu_ib_get(ring
, NULL
, ib_size_dw
* 4, &ib
);
357 DRM_ERROR("amdgpu: failed to get ib (%d).\n", r
);
361 dummy
= ib
.gpu_addr
+ 1024;
363 /* stitch together an VCE create msg */
365 ib
.ptr
[ib
.length_dw
++] = 0x0000000c; /* len */
366 ib
.ptr
[ib
.length_dw
++] = 0x00000001; /* session cmd */
367 ib
.ptr
[ib
.length_dw
++] = handle
;
369 ib
.ptr
[ib
.length_dw
++] = 0x00000030; /* len */
370 ib
.ptr
[ib
.length_dw
++] = 0x01000001; /* create cmd */
371 ib
.ptr
[ib
.length_dw
++] = 0x00000000;
372 ib
.ptr
[ib
.length_dw
++] = 0x00000042;
373 ib
.ptr
[ib
.length_dw
++] = 0x0000000a;
374 ib
.ptr
[ib
.length_dw
++] = 0x00000001;
375 ib
.ptr
[ib
.length_dw
++] = 0x00000080;
376 ib
.ptr
[ib
.length_dw
++] = 0x00000060;
377 ib
.ptr
[ib
.length_dw
++] = 0x00000100;
378 ib
.ptr
[ib
.length_dw
++] = 0x00000100;
379 ib
.ptr
[ib
.length_dw
++] = 0x0000000c;
380 ib
.ptr
[ib
.length_dw
++] = 0x00000000;
382 ib
.ptr
[ib
.length_dw
++] = 0x00000014; /* len */
383 ib
.ptr
[ib
.length_dw
++] = 0x05000005; /* feedback buffer */
384 ib
.ptr
[ib
.length_dw
++] = upper_32_bits(dummy
);
385 ib
.ptr
[ib
.length_dw
++] = dummy
;
386 ib
.ptr
[ib
.length_dw
++] = 0x00000001;
388 for (i
= ib
.length_dw
; i
< ib_size_dw
; ++i
)
391 r
= amdgpu_ib_schedule(ring
->adev
, 1, &ib
, AMDGPU_FENCE_OWNER_UNDEFINED
);
393 DRM_ERROR("amdgpu: failed to schedule ib (%d).\n", r
);
397 *fence
= amdgpu_fence_ref(ib
.fence
);
399 amdgpu_ib_free(ring
->adev
, &ib
);
405 * amdgpu_vce_get_destroy_msg - generate a VCE destroy msg
407 * @adev: amdgpu_device pointer
408 * @ring: ring we should submit the msg to
409 * @handle: VCE session handle to use
410 * @fence: optional fence to return
412 * Close up a stream for HW test or if userspace failed to do so
414 int amdgpu_vce_get_destroy_msg(struct amdgpu_ring
*ring
, uint32_t handle
,
415 struct amdgpu_fence
**fence
)
417 const unsigned ib_size_dw
= 1024;
422 r
= amdgpu_ib_get(ring
, NULL
, ib_size_dw
* 4, &ib
);
424 DRM_ERROR("amdgpu: failed to get ib (%d).\n", r
);
428 dummy
= ib
.gpu_addr
+ 1024;
430 /* stitch together an VCE destroy msg */
432 ib
.ptr
[ib
.length_dw
++] = 0x0000000c; /* len */
433 ib
.ptr
[ib
.length_dw
++] = 0x00000001; /* session cmd */
434 ib
.ptr
[ib
.length_dw
++] = handle
;
436 ib
.ptr
[ib
.length_dw
++] = 0x00000014; /* len */
437 ib
.ptr
[ib
.length_dw
++] = 0x05000005; /* feedback buffer */
438 ib
.ptr
[ib
.length_dw
++] = upper_32_bits(dummy
);
439 ib
.ptr
[ib
.length_dw
++] = dummy
;
440 ib
.ptr
[ib
.length_dw
++] = 0x00000001;
442 ib
.ptr
[ib
.length_dw
++] = 0x00000008; /* len */
443 ib
.ptr
[ib
.length_dw
++] = 0x02000001; /* destroy cmd */
445 for (i
= ib
.length_dw
; i
< ib_size_dw
; ++i
)
448 r
= amdgpu_ib_schedule(ring
->adev
, 1, &ib
, AMDGPU_FENCE_OWNER_UNDEFINED
);
450 DRM_ERROR("amdgpu: failed to schedule ib (%d).\n", r
);
454 *fence
= amdgpu_fence_ref(ib
.fence
);
456 amdgpu_ib_free(ring
->adev
, &ib
);
462 * amdgpu_vce_cs_reloc - command submission relocation
465 * @lo: address of lower dword
466 * @hi: address of higher dword
467 * @size: minimum size
469 * Patch relocation inside command stream with real buffer address
471 static int amdgpu_vce_cs_reloc(struct amdgpu_cs_parser
*p
, uint32_t ib_idx
,
472 int lo
, int hi
, unsigned size
, uint32_t index
)
474 struct amdgpu_bo_va_mapping
*mapping
;
475 struct amdgpu_ib
*ib
= &p
->ibs
[ib_idx
];
476 struct amdgpu_bo
*bo
;
479 if (index
== 0xffffffff)
482 addr
= ((uint64_t)amdgpu_get_ib_value(p
, ib_idx
, lo
)) |
483 ((uint64_t)amdgpu_get_ib_value(p
, ib_idx
, hi
)) << 32;
484 addr
+= ((uint64_t)size
) * ((uint64_t)index
);
486 mapping
= amdgpu_cs_find_mapping(p
, addr
, &bo
);
487 if (mapping
== NULL
) {
488 DRM_ERROR("Can't find BO for addr 0x%010Lx %d %d %d %d\n",
489 addr
, lo
, hi
, size
, index
);
493 if ((addr
+ (uint64_t)size
) >
494 ((uint64_t)mapping
->it
.last
+ 1) * AMDGPU_GPU_PAGE_SIZE
) {
495 DRM_ERROR("BO to small for addr 0x%010Lx %d %d\n",
500 addr
-= ((uint64_t)mapping
->it
.start
) * AMDGPU_GPU_PAGE_SIZE
;
501 addr
+= amdgpu_bo_gpu_offset(bo
);
502 addr
-= ((uint64_t)size
) * ((uint64_t)index
);
504 ib
->ptr
[lo
] = addr
& 0xFFFFFFFF;
505 ib
->ptr
[hi
] = addr
>> 32;
511 * amdgpu_vce_validate_handle - validate stream handle
514 * @handle: handle to validate
515 * @allocated: allocated a new handle?
517 * Validates the handle and return the found session index or -EINVAL
518 * we we don't have another free session index.
520 static int amdgpu_vce_validate_handle(struct amdgpu_cs_parser
*p
,
521 uint32_t handle
, bool *allocated
)
527 /* validate the handle */
528 for (i
= 0; i
< AMDGPU_MAX_VCE_HANDLES
; ++i
) {
529 if (atomic_read(&p
->adev
->vce
.handles
[i
]) == handle
) {
530 if (p
->adev
->vce
.filp
[i
] != p
->filp
) {
531 DRM_ERROR("VCE handle collision detected!\n");
538 /* handle not found try to alloc a new one */
539 for (i
= 0; i
< AMDGPU_MAX_VCE_HANDLES
; ++i
) {
540 if (!atomic_cmpxchg(&p
->adev
->vce
.handles
[i
], 0, handle
)) {
541 p
->adev
->vce
.filp
[i
] = p
->filp
;
542 p
->adev
->vce
.img_size
[i
] = 0;
548 DRM_ERROR("No more free VCE handles!\n");
553 * amdgpu_vce_cs_parse - parse and validate the command stream
558 int amdgpu_vce_ring_parse_cs(struct amdgpu_cs_parser
*p
, uint32_t ib_idx
)
560 struct amdgpu_ib
*ib
= &p
->ibs
[ib_idx
];
561 unsigned fb_idx
= 0, bs_idx
= 0;
562 int session_idx
= -1;
563 bool destroyed
= false;
564 bool created
= false;
565 bool allocated
= false;
566 uint32_t tmp
, handle
= 0;
567 uint32_t *size
= &tmp
;
568 int i
, r
= 0, idx
= 0;
570 amdgpu_vce_note_usage(p
->adev
);
572 while (idx
< ib
->length_dw
) {
573 uint32_t len
= amdgpu_get_ib_value(p
, ib_idx
, idx
);
574 uint32_t cmd
= amdgpu_get_ib_value(p
, ib_idx
, idx
+ 1);
576 if ((len
< 8) || (len
& 3)) {
577 DRM_ERROR("invalid VCE command length (%d)!\n", len
);
583 DRM_ERROR("No other command allowed after destroy!\n");
589 case 0x00000001: // session
590 handle
= amdgpu_get_ib_value(p
, ib_idx
, idx
+ 2);
591 session_idx
= amdgpu_vce_validate_handle(p
, handle
,
595 size
= &p
->adev
->vce
.img_size
[session_idx
];
598 case 0x00000002: // task info
599 fb_idx
= amdgpu_get_ib_value(p
, ib_idx
, idx
+ 6);
600 bs_idx
= amdgpu_get_ib_value(p
, ib_idx
, idx
+ 7);
603 case 0x01000001: // create
606 DRM_ERROR("Handle already in use!\n");
611 *size
= amdgpu_get_ib_value(p
, ib_idx
, idx
+ 8) *
612 amdgpu_get_ib_value(p
, ib_idx
, idx
+ 10) *
616 case 0x04000001: // config extension
617 case 0x04000002: // pic control
618 case 0x04000005: // rate control
619 case 0x04000007: // motion estimation
620 case 0x04000008: // rdo
621 case 0x04000009: // vui
622 case 0x05000002: // auxiliary buffer
625 case 0x03000001: // encode
626 r
= amdgpu_vce_cs_reloc(p
, ib_idx
, idx
+ 10, idx
+ 9,
631 r
= amdgpu_vce_cs_reloc(p
, ib_idx
, idx
+ 12, idx
+ 11,
637 case 0x02000001: // destroy
641 case 0x05000001: // context buffer
642 r
= amdgpu_vce_cs_reloc(p
, ib_idx
, idx
+ 3, idx
+ 2,
648 case 0x05000004: // video bitstream buffer
649 tmp
= amdgpu_get_ib_value(p
, ib_idx
, idx
+ 4);
650 r
= amdgpu_vce_cs_reloc(p
, ib_idx
, idx
+ 3, idx
+ 2,
656 case 0x05000005: // feedback buffer
657 r
= amdgpu_vce_cs_reloc(p
, ib_idx
, idx
+ 3, idx
+ 2,
664 DRM_ERROR("invalid VCE command (0x%x)!\n", cmd
);
669 if (session_idx
== -1) {
670 DRM_ERROR("no session command at start of IB\n");
678 if (allocated
&& !created
) {
679 DRM_ERROR("New session without create command!\n");
684 if ((!r
&& destroyed
) || (r
&& allocated
)) {
686 * IB contains a destroy msg or we have allocated an
687 * handle and got an error, anyway free the handle
689 for (i
= 0; i
< AMDGPU_MAX_VCE_HANDLES
; ++i
)
690 atomic_cmpxchg(&p
->adev
->vce
.handles
[i
], handle
, 0);
697 * amdgpu_vce_ring_emit_semaphore - emit a semaphore command
699 * @ring: engine to use
700 * @semaphore: address of semaphore
701 * @emit_wait: true=emit wait, false=emit signal
704 bool amdgpu_vce_ring_emit_semaphore(struct amdgpu_ring
*ring
,
705 struct amdgpu_semaphore
*semaphore
,
708 uint64_t addr
= semaphore
->gpu_addr
;
710 amdgpu_ring_write(ring
, VCE_CMD_SEMAPHORE
);
711 amdgpu_ring_write(ring
, (addr
>> 3) & 0x000FFFFF);
712 amdgpu_ring_write(ring
, (addr
>> 23) & 0x000FFFFF);
713 amdgpu_ring_write(ring
, 0x01003000 | (emit_wait
? 1 : 0));
715 amdgpu_ring_write(ring
, VCE_CMD_END
);
721 * amdgpu_vce_ring_emit_ib - execute indirect buffer
723 * @ring: engine to use
724 * @ib: the IB to execute
727 void amdgpu_vce_ring_emit_ib(struct amdgpu_ring
*ring
, struct amdgpu_ib
*ib
)
729 amdgpu_ring_write(ring
, VCE_CMD_IB
);
730 amdgpu_ring_write(ring
, lower_32_bits(ib
->gpu_addr
));
731 amdgpu_ring_write(ring
, upper_32_bits(ib
->gpu_addr
));
732 amdgpu_ring_write(ring
, ib
->length_dw
);
736 * amdgpu_vce_ring_emit_fence - add a fence command to the ring
738 * @ring: engine to use
742 void amdgpu_vce_ring_emit_fence(struct amdgpu_ring
*ring
, u64 addr
, u64 seq
,
745 WARN_ON(flags
& AMDGPU_FENCE_FLAG_64BIT
);
747 amdgpu_ring_write(ring
, VCE_CMD_FENCE
);
748 amdgpu_ring_write(ring
, addr
);
749 amdgpu_ring_write(ring
, upper_32_bits(addr
));
750 amdgpu_ring_write(ring
, seq
);
751 amdgpu_ring_write(ring
, VCE_CMD_TRAP
);
752 amdgpu_ring_write(ring
, VCE_CMD_END
);
756 * amdgpu_vce_ring_test_ring - test if VCE ring is working
758 * @ring: the engine to test on
761 int amdgpu_vce_ring_test_ring(struct amdgpu_ring
*ring
)
763 struct amdgpu_device
*adev
= ring
->adev
;
764 uint32_t rptr
= amdgpu_ring_get_rptr(ring
);
768 r
= amdgpu_ring_lock(ring
, 16);
770 DRM_ERROR("amdgpu: vce failed to lock ring %d (%d).\n",
774 amdgpu_ring_write(ring
, VCE_CMD_END
);
775 amdgpu_ring_unlock_commit(ring
);
777 for (i
= 0; i
< adev
->usec_timeout
; i
++) {
778 if (amdgpu_ring_get_rptr(ring
) != rptr
)
783 if (i
< adev
->usec_timeout
) {
784 DRM_INFO("ring test on %d succeeded in %d usecs\n",
787 DRM_ERROR("amdgpu: ring %d test failed\n",
796 * amdgpu_vce_ring_test_ib - test if VCE IBs are working
798 * @ring: the engine to test on
801 int amdgpu_vce_ring_test_ib(struct amdgpu_ring
*ring
)
803 struct amdgpu_fence
*fence
= NULL
;
806 r
= amdgpu_vce_get_create_msg(ring
, 1, NULL
);
808 DRM_ERROR("amdgpu: failed to get create msg (%d).\n", r
);
812 r
= amdgpu_vce_get_destroy_msg(ring
, 1, &fence
);
814 DRM_ERROR("amdgpu: failed to get destroy ib (%d).\n", r
);
818 r
= amdgpu_fence_wait(fence
, false);
820 DRM_ERROR("amdgpu: fence wait failed (%d).\n", r
);
822 DRM_INFO("ib test on ring %d succeeded\n", ring
->idx
);
825 amdgpu_fence_unref(&fence
);