blob: d130432e313a41345759c29fcc0f5b51d07e2c71 [file] [log] [blame]
Christian Königd93f7932013-05-23 12:10:04 +02001/*
2 * Copyright 2013 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>
29#include <linux/module.h>
30#include <drm/drmP.h>
31#include <drm/drm.h>
32
33#include "radeon.h"
34#include "radeon_asic.h"
35#include "sid.h"
36
Alex Deucher03afe6f2013-08-23 11:56:26 -040037/* 1 second timeout */
38#define VCE_IDLE_TIMEOUT_MS 1000
39
Christian Königd93f7932013-05-23 12:10:04 +020040/* Firmware Names */
41#define FIRMWARE_BONAIRE "radeon/BONAIRE_vce.bin"
42
43MODULE_FIRMWARE(FIRMWARE_BONAIRE);
44
Alex Deucher03afe6f2013-08-23 11:56:26 -040045static void radeon_vce_idle_work_handler(struct work_struct *work);
46
Christian Königd93f7932013-05-23 12:10:04 +020047/**
48 * radeon_vce_init - allocate memory, load vce firmware
49 *
50 * @rdev: radeon_device pointer
51 *
52 * First step to get VCE online, allocate memory and load the firmware
53 */
54int radeon_vce_init(struct radeon_device *rdev)
55{
Christian König98ccc292014-01-23 09:50:49 -070056 static const char *fw_version = "[ATI LIB=VCEFW,";
57 static const char *fb_version = "[ATI LIB=VCEFWSTATS,";
58 unsigned long size;
59 const char *fw_name, *c;
60 uint8_t start, mid, end;
Christian Königd93f7932013-05-23 12:10:04 +020061 int i, r;
62
Alex Deucher03afe6f2013-08-23 11:56:26 -040063 INIT_DELAYED_WORK(&rdev->vce.idle_work, radeon_vce_idle_work_handler);
64
Christian Königd93f7932013-05-23 12:10:04 +020065 switch (rdev->family) {
66 case CHIP_BONAIRE:
67 case CHIP_KAVERI:
68 case CHIP_KABINI:
69 fw_name = FIRMWARE_BONAIRE;
70 break;
71
72 default:
73 return -EINVAL;
74 }
75
76 r = request_firmware(&rdev->vce_fw, fw_name, rdev->dev);
77 if (r) {
78 dev_err(rdev->dev, "radeon_vce: Can't load firmware \"%s\"\n",
79 fw_name);
80 return r;
81 }
82
Christian König98ccc292014-01-23 09:50:49 -070083 /* search for firmware version */
84
85 size = rdev->vce_fw->size - strlen(fw_version) - 9;
86 c = rdev->vce_fw->data;
87 for (;size > 0; --size, ++c)
88 if (strncmp(c, fw_version, strlen(fw_version)) == 0)
89 break;
90
91 if (size == 0)
92 return -EINVAL;
93
94 c += strlen(fw_version);
95 if (sscanf(c, "%2hhd.%2hhd.%2hhd]", &start, &mid, &end) != 3)
96 return -EINVAL;
97
98 /* search for feedback version */
99
100 size = rdev->vce_fw->size - strlen(fb_version) - 3;
101 c = rdev->vce_fw->data;
102 for (;size > 0; --size, ++c)
103 if (strncmp(c, fb_version, strlen(fb_version)) == 0)
104 break;
105
106 if (size == 0)
107 return -EINVAL;
108
109 c += strlen(fb_version);
110 if (sscanf(c, "%2u]", &rdev->vce.fb_version) != 1)
111 return -EINVAL;
112
113 DRM_INFO("Found VCE firmware/feedback version %hhd.%hhd.%hhd / %d!\n",
114 start, mid, end, rdev->vce.fb_version);
115
116 rdev->vce.fw_version = (start << 24) | (mid << 16) | (end << 8);
117
118 /* we can only work with this fw version for now */
119 if (rdev->vce.fw_version != ((40 << 24) | (2 << 16) | (2 << 8)))
120 return -EINVAL;
121
122 /* load firmware into VRAM */
123
124 size = RADEON_GPU_PAGE_ALIGN(rdev->vce_fw->size) +
125 RADEON_VCE_STACK_SIZE + RADEON_VCE_HEAP_SIZE;
126 r = radeon_bo_create(rdev, size, PAGE_SIZE, true,
Christian Königd93f7932013-05-23 12:10:04 +0200127 RADEON_GEM_DOMAIN_VRAM, NULL, &rdev->vce.vcpu_bo);
128 if (r) {
129 dev_err(rdev->dev, "(%d) failed to allocate VCE bo\n", r);
130 return r;
131 }
132
133 r = radeon_vce_resume(rdev);
134 if (r)
135 return r;
136
Christian König98ccc292014-01-23 09:50:49 -0700137 memset(rdev->vce.cpu_addr, 0, size);
Christian Königd93f7932013-05-23 12:10:04 +0200138 memcpy(rdev->vce.cpu_addr, rdev->vce_fw->data, rdev->vce_fw->size);
139
140 r = radeon_vce_suspend(rdev);
141 if (r)
142 return r;
143
144 for (i = 0; i < RADEON_MAX_VCE_HANDLES; ++i) {
145 atomic_set(&rdev->vce.handles[i], 0);
146 rdev->vce.filp[i] = NULL;
147 }
148
149 return 0;
150}
151
152/**
153 * radeon_vce_fini - free memory
154 *
155 * @rdev: radeon_device pointer
156 *
157 * Last step on VCE teardown, free firmware memory
158 */
159void radeon_vce_fini(struct radeon_device *rdev)
160{
161 radeon_vce_suspend(rdev);
162 radeon_bo_unref(&rdev->vce.vcpu_bo);
163}
164
165/**
166 * radeon_vce_suspend - unpin VCE fw memory
167 *
168 * @rdev: radeon_device pointer
169 *
170 * TODO: Test VCE suspend/resume
171 */
172int radeon_vce_suspend(struct radeon_device *rdev)
173{
174 int r;
175
176 if (rdev->vce.vcpu_bo == NULL)
177 return 0;
178
179 r = radeon_bo_reserve(rdev->vce.vcpu_bo, false);
180 if (!r) {
181 radeon_bo_kunmap(rdev->vce.vcpu_bo);
182 radeon_bo_unpin(rdev->vce.vcpu_bo);
183 radeon_bo_unreserve(rdev->vce.vcpu_bo);
184 }
185 return r;
186}
187
188/**
189 * radeon_vce_resume - pin VCE fw memory
190 *
191 * @rdev: radeon_device pointer
192 *
193 * TODO: Test VCE suspend/resume
194 */
195int radeon_vce_resume(struct radeon_device *rdev)
196{
197 int r;
198
199 if (rdev->vce.vcpu_bo == NULL)
200 return -EINVAL;
201
202 r = radeon_bo_reserve(rdev->vce.vcpu_bo, false);
203 if (r) {
204 radeon_bo_unref(&rdev->vce.vcpu_bo);
205 dev_err(rdev->dev, "(%d) failed to reserve VCE bo\n", r);
206 return r;
207 }
208
209 r = radeon_bo_pin(rdev->vce.vcpu_bo, RADEON_GEM_DOMAIN_VRAM,
210 &rdev->vce.gpu_addr);
211 if (r) {
212 radeon_bo_unreserve(rdev->vce.vcpu_bo);
213 radeon_bo_unref(&rdev->vce.vcpu_bo);
214 dev_err(rdev->dev, "(%d) VCE bo pin failed\n", r);
215 return r;
216 }
217
218 r = radeon_bo_kmap(rdev->vce.vcpu_bo, &rdev->vce.cpu_addr);
219 if (r) {
220 dev_err(rdev->dev, "(%d) VCE map failed\n", r);
221 return r;
222 }
223
224 radeon_bo_unreserve(rdev->vce.vcpu_bo);
225
226 return 0;
227}
228
229/**
Alex Deucher03afe6f2013-08-23 11:56:26 -0400230 * radeon_vce_idle_work_handler - power off VCE
231 *
232 * @work: pointer to work structure
233 *
234 * power of VCE when it's not used any more
235 */
236static void radeon_vce_idle_work_handler(struct work_struct *work)
237{
238 struct radeon_device *rdev =
239 container_of(work, struct radeon_device, vce.idle_work.work);
240
241 if ((radeon_fence_count_emitted(rdev, TN_RING_TYPE_VCE1_INDEX) == 0) &&
242 (radeon_fence_count_emitted(rdev, TN_RING_TYPE_VCE2_INDEX) == 0)) {
243 if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) {
244 radeon_dpm_enable_vce(rdev, false);
245 } else {
246 radeon_set_vce_clocks(rdev, 0, 0);
247 }
248 } else {
249 schedule_delayed_work(&rdev->vce.idle_work,
250 msecs_to_jiffies(VCE_IDLE_TIMEOUT_MS));
251 }
252}
253
254/**
255 * radeon_vce_note_usage - power up VCE
256 *
257 * @rdev: radeon_device pointer
258 *
259 * Make sure VCE is powerd up when we want to use it
260 */
261void radeon_vce_note_usage(struct radeon_device *rdev)
262{
263 bool streams_changed = false;
264 bool set_clocks = !cancel_delayed_work_sync(&rdev->vce.idle_work);
265 set_clocks &= schedule_delayed_work(&rdev->vce.idle_work,
266 msecs_to_jiffies(VCE_IDLE_TIMEOUT_MS));
267
268 if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) {
269 /* XXX figure out if the streams changed */
270 streams_changed = false;
271 }
272
273 if (set_clocks || streams_changed) {
274 if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) {
275 radeon_dpm_enable_vce(rdev, true);
276 } else {
277 radeon_set_vce_clocks(rdev, 53300, 40000);
278 }
279 }
280}
281
282/**
Christian Königd93f7932013-05-23 12:10:04 +0200283 * radeon_vce_free_handles - free still open VCE handles
284 *
285 * @rdev: radeon_device pointer
286 * @filp: drm file pointer
287 *
288 * Close all VCE handles still open by this file pointer
289 */
290void radeon_vce_free_handles(struct radeon_device *rdev, struct drm_file *filp)
291{
292 int i, r;
293 for (i = 0; i < RADEON_MAX_VCE_HANDLES; ++i) {
294 uint32_t handle = atomic_read(&rdev->vce.handles[i]);
295 if (!handle || rdev->vce.filp[i] != filp)
296 continue;
297
Alex Deucher03afe6f2013-08-23 11:56:26 -0400298 radeon_vce_note_usage(rdev);
299
Christian Königd93f7932013-05-23 12:10:04 +0200300 r = radeon_vce_get_destroy_msg(rdev, TN_RING_TYPE_VCE1_INDEX,
301 handle, NULL);
302 if (r)
303 DRM_ERROR("Error destroying VCE handle (%d)!\n", r);
304
305 rdev->vce.filp[i] = NULL;
306 atomic_set(&rdev->vce.handles[i], 0);
307 }
308}
309
310/**
311 * radeon_vce_get_create_msg - generate a VCE create msg
312 *
313 * @rdev: radeon_device pointer
314 * @ring: ring we should submit the msg to
315 * @handle: VCE session handle to use
316 * @fence: optional fence to return
317 *
318 * Open up a stream for HW test
319 */
320int radeon_vce_get_create_msg(struct radeon_device *rdev, int ring,
321 uint32_t handle, struct radeon_fence **fence)
322{
323 const unsigned ib_size_dw = 1024;
324 struct radeon_ib ib;
325 uint64_t dummy;
326 int i, r;
327
328 r = radeon_ib_get(rdev, ring, &ib, NULL, ib_size_dw * 4);
329 if (r) {
330 DRM_ERROR("radeon: failed to get ib (%d).\n", r);
331 return r;
332 }
333
334 dummy = ib.gpu_addr + 1024;
335
336 /* stitch together an VCE create msg */
337 ib.length_dw = 0;
338 ib.ptr[ib.length_dw++] = 0x0000000c; /* len */
339 ib.ptr[ib.length_dw++] = 0x00000001; /* session cmd */
340 ib.ptr[ib.length_dw++] = handle;
341
342 ib.ptr[ib.length_dw++] = 0x00000030; /* len */
343 ib.ptr[ib.length_dw++] = 0x01000001; /* create cmd */
344 ib.ptr[ib.length_dw++] = 0x00000000;
345 ib.ptr[ib.length_dw++] = 0x00000042;
346 ib.ptr[ib.length_dw++] = 0x0000000a;
347 ib.ptr[ib.length_dw++] = 0x00000001;
348 ib.ptr[ib.length_dw++] = 0x00000080;
349 ib.ptr[ib.length_dw++] = 0x00000060;
350 ib.ptr[ib.length_dw++] = 0x00000100;
351 ib.ptr[ib.length_dw++] = 0x00000100;
352 ib.ptr[ib.length_dw++] = 0x0000000c;
353 ib.ptr[ib.length_dw++] = 0x00000000;
354
355 ib.ptr[ib.length_dw++] = 0x00000014; /* len */
356 ib.ptr[ib.length_dw++] = 0x05000005; /* feedback buffer */
357 ib.ptr[ib.length_dw++] = upper_32_bits(dummy);
358 ib.ptr[ib.length_dw++] = dummy;
359 ib.ptr[ib.length_dw++] = 0x00000001;
360
361 for (i = ib.length_dw; i < ib_size_dw; ++i)
362 ib.ptr[i] = 0x0;
363
364 r = radeon_ib_schedule(rdev, &ib, NULL);
365 if (r) {
366 DRM_ERROR("radeon: failed to schedule ib (%d).\n", r);
367 }
368
369 if (fence)
370 *fence = radeon_fence_ref(ib.fence);
371
372 radeon_ib_free(rdev, &ib);
373
374 return r;
375}
376
377/**
378 * radeon_vce_get_destroy_msg - generate a VCE destroy msg
379 *
380 * @rdev: radeon_device pointer
381 * @ring: ring we should submit the msg to
382 * @handle: VCE session handle to use
383 * @fence: optional fence to return
384 *
385 * Close up a stream for HW test or if userspace failed to do so
386 */
387int radeon_vce_get_destroy_msg(struct radeon_device *rdev, int ring,
388 uint32_t handle, struct radeon_fence **fence)
389{
390 const unsigned ib_size_dw = 1024;
391 struct radeon_ib ib;
392 uint64_t dummy;
393 int i, r;
394
395 r = radeon_ib_get(rdev, ring, &ib, NULL, ib_size_dw * 4);
396 if (r) {
397 DRM_ERROR("radeon: failed to get ib (%d).\n", r);
398 return r;
399 }
400
401 dummy = ib.gpu_addr + 1024;
402
403 /* stitch together an VCE destroy msg */
404 ib.length_dw = 0;
405 ib.ptr[ib.length_dw++] = 0x0000000c; /* len */
406 ib.ptr[ib.length_dw++] = 0x00000001; /* session cmd */
407 ib.ptr[ib.length_dw++] = handle;
408
409 ib.ptr[ib.length_dw++] = 0x00000014; /* len */
410 ib.ptr[ib.length_dw++] = 0x05000005; /* feedback buffer */
411 ib.ptr[ib.length_dw++] = upper_32_bits(dummy);
412 ib.ptr[ib.length_dw++] = dummy;
413 ib.ptr[ib.length_dw++] = 0x00000001;
414
415 ib.ptr[ib.length_dw++] = 0x00000008; /* len */
416 ib.ptr[ib.length_dw++] = 0x02000001; /* destroy cmd */
417
418 for (i = ib.length_dw; i < ib_size_dw; ++i)
419 ib.ptr[i] = 0x0;
420
421 r = radeon_ib_schedule(rdev, &ib, NULL);
422 if (r) {
423 DRM_ERROR("radeon: failed to schedule ib (%d).\n", r);
424 }
425
426 if (fence)
427 *fence = radeon_fence_ref(ib.fence);
428
429 radeon_ib_free(rdev, &ib);
430
431 return r;
432}
433
434/**
435 * radeon_vce_cs_reloc - command submission relocation
436 *
437 * @p: parser context
438 * @lo: address of lower dword
439 * @hi: address of higher dword
440 *
441 * Patch relocation inside command stream with real buffer address
442 */
443int radeon_vce_cs_reloc(struct radeon_cs_parser *p, int lo, int hi)
444{
445 struct radeon_cs_chunk *relocs_chunk;
446 uint64_t offset;
447 unsigned idx;
448
449 relocs_chunk = &p->chunks[p->chunk_relocs_idx];
450 offset = radeon_get_ib_value(p, lo);
451 idx = radeon_get_ib_value(p, hi);
452
453 if (idx >= relocs_chunk->length_dw) {
454 DRM_ERROR("Relocs at %d after relocations chunk end %d !\n",
455 idx, relocs_chunk->length_dw);
456 return -EINVAL;
457 }
458
459 offset += p->relocs_ptr[(idx / 4)]->lobj.gpu_offset;
460
461 p->ib.ptr[lo] = offset & 0xFFFFFFFF;
462 p->ib.ptr[hi] = offset >> 32;
463
464 return 0;
465}
466
467/**
468 * radeon_vce_cs_parse - parse and validate the command stream
469 *
470 * @p: parser context
471 *
472 */
473int radeon_vce_cs_parse(struct radeon_cs_parser *p)
474{
475 uint32_t handle = 0;
476 bool destroy = false;
477 int i, r;
478
479 while (p->idx < p->chunks[p->chunk_ib_idx].length_dw) {
480 uint32_t len = radeon_get_ib_value(p, p->idx);
481 uint32_t cmd = radeon_get_ib_value(p, p->idx + 1);
482
483 if ((len < 8) || (len & 3)) {
484 DRM_ERROR("invalid VCE command length (%d)!\n", len);
485 return -EINVAL;
486 }
487
488 switch (cmd) {
489 case 0x00000001: // session
490 handle = radeon_get_ib_value(p, p->idx + 2);
491 break;
492
493 case 0x00000002: // task info
494 case 0x01000001: // create
495 case 0x04000001: // config extension
496 case 0x04000002: // pic control
497 case 0x04000005: // rate control
498 case 0x04000007: // motion estimation
499 case 0x04000008: // rdo
500 break;
501
502 case 0x03000001: // encode
503 r = radeon_vce_cs_reloc(p, p->idx + 10, p->idx + 9);
504 if (r)
505 return r;
506
507 r = radeon_vce_cs_reloc(p, p->idx + 12, p->idx + 11);
508 if (r)
509 return r;
510 break;
511
512 case 0x02000001: // destroy
513 destroy = true;
514 break;
515
516 case 0x05000001: // context buffer
517 case 0x05000004: // video bitstream buffer
518 case 0x05000005: // feedback buffer
519 r = radeon_vce_cs_reloc(p, p->idx + 3, p->idx + 2);
520 if (r)
521 return r;
522 break;
523
524 default:
525 DRM_ERROR("invalid VCE command (0x%x)!\n", cmd);
526 return -EINVAL;
527 }
528
529 p->idx += len / 4;
530 }
531
532 if (destroy) {
533 /* IB contains a destroy msg, free the handle */
534 for (i = 0; i < RADEON_MAX_VCE_HANDLES; ++i)
535 atomic_cmpxchg(&p->rdev->vce.handles[i], handle, 0);
536
537 return 0;
538 }
539
540 /* create or encode, validate the handle */
541 for (i = 0; i < RADEON_MAX_VCE_HANDLES; ++i) {
542 if (atomic_read(&p->rdev->vce.handles[i]) == handle)
543 return 0;
544 }
545
546 /* handle not found try to alloc a new one */
547 for (i = 0; i < RADEON_MAX_VCE_HANDLES; ++i) {
548 if (!atomic_cmpxchg(&p->rdev->vce.handles[i], 0, handle)) {
549 p->rdev->vce.filp[i] = p->filp;
550 return 0;
551 }
552 }
553
554 DRM_ERROR("No more free VCE handles!\n");
555 return -EINVAL;
556}
557
558/**
559 * radeon_vce_semaphore_emit - emit a semaphore command
560 *
561 * @rdev: radeon_device pointer
562 * @ring: engine to use
563 * @semaphore: address of semaphore
564 * @emit_wait: true=emit wait, false=emit signal
565 *
566 */
567bool radeon_vce_semaphore_emit(struct radeon_device *rdev,
568 struct radeon_ring *ring,
569 struct radeon_semaphore *semaphore,
570 bool emit_wait)
571{
572 uint64_t addr = semaphore->gpu_addr;
573
574 radeon_ring_write(ring, VCE_CMD_SEMAPHORE);
575 radeon_ring_write(ring, (addr >> 3) & 0x000FFFFF);
576 radeon_ring_write(ring, (addr >> 23) & 0x000FFFFF);
577 radeon_ring_write(ring, 0x01003000 | (emit_wait ? 1 : 0));
578 if (!emit_wait)
579 radeon_ring_write(ring, VCE_CMD_END);
580
581 return true;
582}
583
584/**
585 * radeon_vce_ib_execute - execute indirect buffer
586 *
587 * @rdev: radeon_device pointer
588 * @ib: the IB to execute
589 *
590 */
591void radeon_vce_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
592{
593 struct radeon_ring *ring = &rdev->ring[ib->ring];
594 radeon_ring_write(ring, VCE_CMD_IB);
595 radeon_ring_write(ring, ib->gpu_addr);
596 radeon_ring_write(ring, upper_32_bits(ib->gpu_addr));
597 radeon_ring_write(ring, ib->length_dw);
598}
599
600/**
601 * radeon_vce_fence_emit - add a fence command to the ring
602 *
603 * @rdev: radeon_device pointer
604 * @fence: the fence
605 *
606 */
607void radeon_vce_fence_emit(struct radeon_device *rdev,
608 struct radeon_fence *fence)
609{
610 struct radeon_ring *ring = &rdev->ring[fence->ring];
611 uint32_t addr = rdev->fence_drv[fence->ring].gpu_addr;
612
613 radeon_ring_write(ring, VCE_CMD_FENCE);
614 radeon_ring_write(ring, addr);
615 radeon_ring_write(ring, upper_32_bits(addr));
616 radeon_ring_write(ring, fence->seq);
617 radeon_ring_write(ring, VCE_CMD_TRAP);
618 radeon_ring_write(ring, VCE_CMD_END);
619}
620
621/**
622 * radeon_vce_ring_test - test if VCE ring is working
623 *
624 * @rdev: radeon_device pointer
625 * @ring: the engine to test on
626 *
627 */
628int radeon_vce_ring_test(struct radeon_device *rdev, struct radeon_ring *ring)
629{
630 uint32_t rptr = vce_v1_0_get_rptr(rdev, ring);
631 unsigned i;
632 int r;
633
634 r = radeon_ring_lock(rdev, ring, 16);
635 if (r) {
636 DRM_ERROR("radeon: vce failed to lock ring %d (%d).\n",
637 ring->idx, r);
638 return r;
639 }
640 radeon_ring_write(ring, VCE_CMD_END);
641 radeon_ring_unlock_commit(rdev, ring);
642
643 for (i = 0; i < rdev->usec_timeout; i++) {
644 if (vce_v1_0_get_rptr(rdev, ring) != rptr)
645 break;
646 DRM_UDELAY(1);
647 }
648
649 if (i < rdev->usec_timeout) {
650 DRM_INFO("ring test on %d succeeded in %d usecs\n",
651 ring->idx, i);
652 } else {
653 DRM_ERROR("radeon: ring %d test failed\n",
654 ring->idx);
655 r = -ETIMEDOUT;
656 }
657
658 return r;
659}
660
661/**
662 * radeon_vce_ib_test - test if VCE IBs are working
663 *
664 * @rdev: radeon_device pointer
665 * @ring: the engine to test on
666 *
667 */
668int radeon_vce_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
669{
670 struct radeon_fence *fence = NULL;
671 int r;
672
673 r = radeon_vce_get_create_msg(rdev, ring->idx, 1, NULL);
674 if (r) {
675 DRM_ERROR("radeon: failed to get create msg (%d).\n", r);
676 goto error;
677 }
678
679 r = radeon_vce_get_destroy_msg(rdev, ring->idx, 1, &fence);
680 if (r) {
681 DRM_ERROR("radeon: failed to get destroy ib (%d).\n", r);
682 goto error;
683 }
684
685 r = radeon_fence_wait(fence, false);
686 if (r) {
687 DRM_ERROR("radeon: fence wait failed (%d).\n", r);
688 } else {
689 DRM_INFO("ib test on ring %d succeeded\n", ring->idx);
690 }
691error:
692 radeon_fence_unref(&fence);
693 return r;
694}