1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31#include <linux/seq_file.h>
32#include <linux/atomic.h>
33#include <linux/wait.h>
34#include <linux/kref.h>
35#include <linux/slab.h>
36#include <linux/firmware.h>
37#include <drm/drmP.h>
38#include "radeon_reg.h"
39#include "radeon.h"
40#include "radeon_trace.h"
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62static void radeon_fence_write(struct radeon_device *rdev, u32 seq, int ring)
63{
64 struct radeon_fence_driver *drv = &rdev->fence_drv[ring];
65 if (likely(rdev->wb.enabled || !drv->scratch_reg)) {
66 if (drv->cpu_addr) {
67 *drv->cpu_addr = cpu_to_le32(seq);
68 }
69 } else {
70 WREG32(drv->scratch_reg, seq);
71 }
72}
73
74
75
76
77
78
79
80
81
82
83static u32 radeon_fence_read(struct radeon_device *rdev, int ring)
84{
85 struct radeon_fence_driver *drv = &rdev->fence_drv[ring];
86 u32 seq = 0;
87
88 if (likely(rdev->wb.enabled || !drv->scratch_reg)) {
89 if (drv->cpu_addr) {
90 seq = le32_to_cpu(*drv->cpu_addr);
91 } else {
92 seq = lower_32_bits(atomic64_read(&drv->last_seq));
93 }
94 } else {
95 seq = RREG32(drv->scratch_reg);
96 }
97 return seq;
98}
99
100
101
102
103
104
105
106
107
108static void radeon_fence_schedule_check(struct radeon_device *rdev, int ring)
109{
110
111
112
113
114 queue_delayed_work(system_power_efficient_wq,
115 &rdev->fence_drv[ring].lockup_work,
116 RADEON_FENCE_JIFFIES_TIMEOUT);
117}
118
119
120
121
122
123
124
125
126
127
128
129int radeon_fence_emit(struct radeon_device *rdev,
130 struct radeon_fence **fence,
131 int ring)
132{
133 u64 seq;
134
135
136 *fence = kmalloc(sizeof(struct radeon_fence), GFP_KERNEL);
137 if ((*fence) == NULL) {
138 return -ENOMEM;
139 }
140 (*fence)->rdev = rdev;
141 (*fence)->seq = seq = ++rdev->fence_drv[ring].sync_seq[ring];
142 (*fence)->ring = ring;
143 (*fence)->is_vm_update = false;
144 dma_fence_init(&(*fence)->base, &radeon_fence_ops,
145 &rdev->fence_queue.lock,
146 rdev->fence_context + ring,
147 seq);
148 radeon_fence_ring_emit(rdev, ring, *fence);
149 trace_radeon_fence_emit(rdev->ddev, ring, (*fence)->seq);
150 radeon_fence_schedule_check(rdev, ring);
151 return 0;
152}
153
154
155
156
157
158
159
160
161static int radeon_fence_check_signaled(wait_queue_entry_t *wait, unsigned mode, int flags, void *key)
162{
163 struct radeon_fence *fence;
164 u64 seq;
165
166 fence = container_of(wait, struct radeon_fence, fence_wake);
167
168
169
170
171
172 seq = atomic64_read(&fence->rdev->fence_drv[fence->ring].last_seq);
173 if (seq >= fence->seq) {
174 int ret = dma_fence_signal_locked(&fence->base);
175
176 if (!ret)
177 DMA_FENCE_TRACE(&fence->base, "signaled from irq context\n");
178 else
179 DMA_FENCE_TRACE(&fence->base, "was already signaled\n");
180
181 radeon_irq_kms_sw_irq_put(fence->rdev, fence->ring);
182 __remove_wait_queue(&fence->rdev->fence_queue, &fence->fence_wake);
183 dma_fence_put(&fence->base);
184 } else
185 DMA_FENCE_TRACE(&fence->base, "pending\n");
186 return 0;
187}
188
189
190
191
192
193
194
195
196
197
198
199static bool radeon_fence_activity(struct radeon_device *rdev, int ring)
200{
201 uint64_t seq, last_seq, last_emitted;
202 unsigned count_loop = 0;
203 bool wake = false;
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226 last_seq = atomic64_read(&rdev->fence_drv[ring].last_seq);
227 do {
228 last_emitted = rdev->fence_drv[ring].sync_seq[ring];
229 seq = radeon_fence_read(rdev, ring);
230 seq |= last_seq & 0xffffffff00000000LL;
231 if (seq < last_seq) {
232 seq &= 0xffffffff;
233 seq |= last_emitted & 0xffffffff00000000LL;
234 }
235
236 if (seq <= last_seq || seq > last_emitted) {
237 break;
238 }
239
240
241
242
243 wake = true;
244 last_seq = seq;
245 if ((count_loop++) > 10) {
246
247
248
249
250
251 break;
252 }
253 } while (atomic64_xchg(&rdev->fence_drv[ring].last_seq, seq) > seq);
254
255 if (seq < last_emitted)
256 radeon_fence_schedule_check(rdev, ring);
257
258 return wake;
259}
260
261
262
263
264
265
266
267
268
269static void radeon_fence_check_lockup(struct work_struct *work)
270{
271 struct radeon_fence_driver *fence_drv;
272 struct radeon_device *rdev;
273 int ring;
274
275 fence_drv = container_of(work, struct radeon_fence_driver,
276 lockup_work.work);
277 rdev = fence_drv->rdev;
278 ring = fence_drv - &rdev->fence_drv[0];
279
280 if (!down_read_trylock(&rdev->exclusive_lock)) {
281
282 radeon_fence_schedule_check(rdev, ring);
283 return;
284 }
285
286 if (fence_drv->delayed_irq && rdev->ddev->irq_enabled) {
287 unsigned long irqflags;
288
289 fence_drv->delayed_irq = false;
290 spin_lock_irqsave(&rdev->irq.lock, irqflags);
291 radeon_irq_set(rdev);
292 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
293 }
294
295 if (radeon_fence_activity(rdev, ring))
296 wake_up_all(&rdev->fence_queue);
297
298 else if (radeon_ring_is_lockup(rdev, ring, &rdev->ring[ring])) {
299
300
301 dev_warn(rdev->dev, "GPU lockup (current fence id "
302 "0x%016llx last fence id 0x%016llx on ring %d)\n",
303 (uint64_t)atomic64_read(&fence_drv->last_seq),
304 fence_drv->sync_seq[ring], ring);
305
306
307 rdev->needs_reset = true;
308 wake_up_all(&rdev->fence_queue);
309 }
310 up_read(&rdev->exclusive_lock);
311}
312
313
314
315
316
317
318
319
320
321
322void radeon_fence_process(struct radeon_device *rdev, int ring)
323{
324 if (radeon_fence_activity(rdev, ring))
325 wake_up_all(&rdev->fence_queue);
326}
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342static bool radeon_fence_seq_signaled(struct radeon_device *rdev,
343 u64 seq, unsigned ring)
344{
345 if (atomic64_read(&rdev->fence_drv[ring].last_seq) >= seq) {
346 return true;
347 }
348
349 radeon_fence_process(rdev, ring);
350 if (atomic64_read(&rdev->fence_drv[ring].last_seq) >= seq) {
351 return true;
352 }
353 return false;
354}
355
356static bool radeon_fence_is_signaled(struct dma_fence *f)
357{
358 struct radeon_fence *fence = to_radeon_fence(f);
359 struct radeon_device *rdev = fence->rdev;
360 unsigned ring = fence->ring;
361 u64 seq = fence->seq;
362
363 if (atomic64_read(&rdev->fence_drv[ring].last_seq) >= seq) {
364 return true;
365 }
366
367 if (down_read_trylock(&rdev->exclusive_lock)) {
368 radeon_fence_process(rdev, ring);
369 up_read(&rdev->exclusive_lock);
370
371 if (atomic64_read(&rdev->fence_drv[ring].last_seq) >= seq) {
372 return true;
373 }
374 }
375 return false;
376}
377
378
379
380
381
382
383
384
385
386static bool radeon_fence_enable_signaling(struct dma_fence *f)
387{
388 struct radeon_fence *fence = to_radeon_fence(f);
389 struct radeon_device *rdev = fence->rdev;
390
391 if (atomic64_read(&rdev->fence_drv[fence->ring].last_seq) >= fence->seq)
392 return false;
393
394 if (down_read_trylock(&rdev->exclusive_lock)) {
395 radeon_irq_kms_sw_irq_get(rdev, fence->ring);
396
397 if (radeon_fence_activity(rdev, fence->ring))
398 wake_up_all_locked(&rdev->fence_queue);
399
400
401 if (atomic64_read(&rdev->fence_drv[fence->ring].last_seq) >= fence->seq) {
402 radeon_irq_kms_sw_irq_put(rdev, fence->ring);
403 up_read(&rdev->exclusive_lock);
404 return false;
405 }
406
407 up_read(&rdev->exclusive_lock);
408 } else {
409
410 if (radeon_irq_kms_sw_irq_get_delayed(rdev, fence->ring))
411 rdev->fence_drv[fence->ring].delayed_irq = true;
412 radeon_fence_schedule_check(rdev, fence->ring);
413 }
414
415 fence->fence_wake.flags = 0;
416 fence->fence_wake.private = NULL;
417 fence->fence_wake.func = radeon_fence_check_signaled;
418 __add_wait_queue(&rdev->fence_queue, &fence->fence_wake);
419 dma_fence_get(f);
420
421 DMA_FENCE_TRACE(&fence->base, "armed on ring %i!\n", fence->ring);
422 return true;
423}
424
425
426
427
428
429
430
431
432
433bool radeon_fence_signaled(struct radeon_fence *fence)
434{
435 if (!fence)
436 return true;
437
438 if (radeon_fence_seq_signaled(fence->rdev, fence->seq, fence->ring)) {
439 int ret;
440
441 ret = dma_fence_signal(&fence->base);
442 if (!ret)
443 DMA_FENCE_TRACE(&fence->base, "signaled from radeon_fence_signaled\n");
444 return true;
445 }
446 return false;
447}
448
449
450
451
452
453
454
455
456
457
458
459
460static bool radeon_fence_any_seq_signaled(struct radeon_device *rdev, u64 *seq)
461{
462 unsigned i;
463
464 for (i = 0; i < RADEON_NUM_RINGS; ++i) {
465 if (seq[i] && radeon_fence_seq_signaled(rdev, seq[i], i))
466 return true;
467 }
468 return false;
469}
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488static long radeon_fence_wait_seq_timeout(struct radeon_device *rdev,
489 u64 *target_seq, bool intr,
490 long timeout)
491{
492 long r;
493 int i;
494
495 if (radeon_fence_any_seq_signaled(rdev, target_seq))
496 return timeout;
497
498
499 for (i = 0; i < RADEON_NUM_RINGS; ++i) {
500 if (!target_seq[i])
501 continue;
502
503 trace_radeon_fence_wait_begin(rdev->ddev, i, target_seq[i]);
504 radeon_irq_kms_sw_irq_get(rdev, i);
505 }
506
507 if (intr) {
508 r = wait_event_interruptible_timeout(rdev->fence_queue, (
509 radeon_fence_any_seq_signaled(rdev, target_seq)
510 || rdev->needs_reset), timeout);
511 } else {
512 r = wait_event_timeout(rdev->fence_queue, (
513 radeon_fence_any_seq_signaled(rdev, target_seq)
514 || rdev->needs_reset), timeout);
515 }
516
517 if (rdev->needs_reset)
518 r = -EDEADLK;
519
520 for (i = 0; i < RADEON_NUM_RINGS; ++i) {
521 if (!target_seq[i])
522 continue;
523
524 radeon_irq_kms_sw_irq_put(rdev, i);
525 trace_radeon_fence_wait_end(rdev->ddev, i, target_seq[i]);
526 }
527
528 return r;
529}
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544long radeon_fence_wait_timeout(struct radeon_fence *fence, bool intr, long timeout)
545{
546 uint64_t seq[RADEON_NUM_RINGS] = {};
547 long r;
548 int r_sig;
549
550
551
552
553
554
555
556 if (WARN_ON_ONCE(!to_radeon_fence(&fence->base)))
557 return dma_fence_wait(&fence->base, intr);
558
559 seq[fence->ring] = fence->seq;
560 r = radeon_fence_wait_seq_timeout(fence->rdev, seq, intr, timeout);
561 if (r <= 0) {
562 return r;
563 }
564
565 r_sig = dma_fence_signal(&fence->base);
566 if (!r_sig)
567 DMA_FENCE_TRACE(&fence->base, "signaled from fence_wait\n");
568 return r;
569}
570
571
572
573
574
575
576
577
578
579
580
581
582int radeon_fence_wait(struct radeon_fence *fence, bool intr)
583{
584 long r = radeon_fence_wait_timeout(fence, intr, MAX_SCHEDULE_TIMEOUT);
585 if (r > 0) {
586 return 0;
587 } else {
588 return r;
589 }
590}
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605int radeon_fence_wait_any(struct radeon_device *rdev,
606 struct radeon_fence **fences,
607 bool intr)
608{
609 uint64_t seq[RADEON_NUM_RINGS];
610 unsigned i, num_rings = 0;
611 long r;
612
613 for (i = 0; i < RADEON_NUM_RINGS; ++i) {
614 seq[i] = 0;
615
616 if (!fences[i]) {
617 continue;
618 }
619
620 seq[i] = fences[i]->seq;
621 ++num_rings;
622 }
623
624
625 if (num_rings == 0)
626 return -ENOENT;
627
628 r = radeon_fence_wait_seq_timeout(rdev, seq, intr, MAX_SCHEDULE_TIMEOUT);
629 if (r < 0) {
630 return r;
631 }
632 return 0;
633}
634
635
636
637
638
639
640
641
642
643
644
645int radeon_fence_wait_next(struct radeon_device *rdev, int ring)
646{
647 uint64_t seq[RADEON_NUM_RINGS] = {};
648 long r;
649
650 seq[ring] = atomic64_read(&rdev->fence_drv[ring].last_seq) + 1ULL;
651 if (seq[ring] >= rdev->fence_drv[ring].sync_seq[ring]) {
652
653
654 return -ENOENT;
655 }
656 r = radeon_fence_wait_seq_timeout(rdev, seq, false, MAX_SCHEDULE_TIMEOUT);
657 if (r < 0)
658 return r;
659 return 0;
660}
661
662
663
664
665
666
667
668
669
670
671
672int radeon_fence_wait_empty(struct radeon_device *rdev, int ring)
673{
674 uint64_t seq[RADEON_NUM_RINGS] = {};
675 long r;
676
677 seq[ring] = rdev->fence_drv[ring].sync_seq[ring];
678 if (!seq[ring])
679 return 0;
680
681 r = radeon_fence_wait_seq_timeout(rdev, seq, false, MAX_SCHEDULE_TIMEOUT);
682 if (r < 0) {
683 if (r == -EDEADLK)
684 return -EDEADLK;
685
686 dev_err(rdev->dev, "error waiting for ring[%d] to become idle (%ld)\n",
687 ring, r);
688 }
689 return 0;
690}
691
692
693
694
695
696
697
698
699
700struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence)
701{
702 dma_fence_get(&fence->base);
703 return fence;
704}
705
706
707
708
709
710
711
712
713void radeon_fence_unref(struct radeon_fence **fence)
714{
715 struct radeon_fence *tmp = *fence;
716
717 *fence = NULL;
718 if (tmp) {
719 dma_fence_put(&tmp->base);
720 }
721}
722
723
724
725
726
727
728
729
730
731
732
733unsigned radeon_fence_count_emitted(struct radeon_device *rdev, int ring)
734{
735 uint64_t emitted;
736
737
738
739
740 radeon_fence_process(rdev, ring);
741 emitted = rdev->fence_drv[ring].sync_seq[ring]
742 - atomic64_read(&rdev->fence_drv[ring].last_seq);
743
744 if (emitted > 0x10000000) {
745 emitted = 0x10000000;
746 }
747 return (unsigned)emitted;
748}
749
750
751
752
753
754
755
756
757
758
759
760
761bool radeon_fence_need_sync(struct radeon_fence *fence, int dst_ring)
762{
763 struct radeon_fence_driver *fdrv;
764
765 if (!fence) {
766 return false;
767 }
768
769 if (fence->ring == dst_ring) {
770 return false;
771 }
772
773
774 fdrv = &fence->rdev->fence_drv[dst_ring];
775 if (fence->seq <= fdrv->sync_seq[fence->ring]) {
776 return false;
777 }
778
779 return true;
780}
781
782
783
784
785
786
787
788
789
790
791void radeon_fence_note_sync(struct radeon_fence *fence, int dst_ring)
792{
793 struct radeon_fence_driver *dst, *src;
794 unsigned i;
795
796 if (!fence) {
797 return;
798 }
799
800 if (fence->ring == dst_ring) {
801 return;
802 }
803
804
805 src = &fence->rdev->fence_drv[fence->ring];
806 dst = &fence->rdev->fence_drv[dst_ring];
807 for (i = 0; i < RADEON_NUM_RINGS; ++i) {
808 if (i == dst_ring) {
809 continue;
810 }
811 dst->sync_seq[i] = max(dst->sync_seq[i], src->sync_seq[i]);
812 }
813}
814
815
816
817
818
819
820
821
822
823
824
825
826
827int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring)
828{
829 uint64_t index;
830 int r;
831
832 radeon_scratch_free(rdev, rdev->fence_drv[ring].scratch_reg);
833 if (rdev->wb.use_event || !radeon_ring_supports_scratch_reg(rdev, &rdev->ring[ring])) {
834 rdev->fence_drv[ring].scratch_reg = 0;
835 if (ring != R600_RING_TYPE_UVD_INDEX) {
836 index = R600_WB_EVENT_OFFSET + ring * 4;
837 rdev->fence_drv[ring].cpu_addr = &rdev->wb.wb[index/4];
838 rdev->fence_drv[ring].gpu_addr = rdev->wb.gpu_addr +
839 index;
840
841 } else {
842
843 index = ALIGN(rdev->uvd_fw->size, 8);
844 rdev->fence_drv[ring].cpu_addr = rdev->uvd.cpu_addr + index;
845 rdev->fence_drv[ring].gpu_addr = rdev->uvd.gpu_addr + index;
846 }
847
848 } else {
849 r = radeon_scratch_get(rdev, &rdev->fence_drv[ring].scratch_reg);
850 if (r) {
851 dev_err(rdev->dev, "fence failed to get scratch register\n");
852 return r;
853 }
854 index = RADEON_WB_SCRATCH_OFFSET +
855 rdev->fence_drv[ring].scratch_reg -
856 rdev->scratch.reg_base;
857 rdev->fence_drv[ring].cpu_addr = &rdev->wb.wb[index/4];
858 rdev->fence_drv[ring].gpu_addr = rdev->wb.gpu_addr + index;
859 }
860 radeon_fence_write(rdev, atomic64_read(&rdev->fence_drv[ring].last_seq), ring);
861 rdev->fence_drv[ring].initialized = true;
862 dev_info(rdev->dev, "fence driver on ring %d use gpu addr 0x%016llx and cpu addr 0x%p\n",
863 ring, rdev->fence_drv[ring].gpu_addr, rdev->fence_drv[ring].cpu_addr);
864 return 0;
865}
866
867
868
869
870
871
872
873
874
875
876
877static void radeon_fence_driver_init_ring(struct radeon_device *rdev, int ring)
878{
879 int i;
880
881 rdev->fence_drv[ring].scratch_reg = -1;
882 rdev->fence_drv[ring].cpu_addr = NULL;
883 rdev->fence_drv[ring].gpu_addr = 0;
884 for (i = 0; i < RADEON_NUM_RINGS; ++i)
885 rdev->fence_drv[ring].sync_seq[i] = 0;
886 atomic64_set(&rdev->fence_drv[ring].last_seq, 0);
887 rdev->fence_drv[ring].initialized = false;
888 INIT_DELAYED_WORK(&rdev->fence_drv[ring].lockup_work,
889 radeon_fence_check_lockup);
890 rdev->fence_drv[ring].rdev = rdev;
891}
892
893
894
895
896
897
898
899
900
901
902
903
904
905int radeon_fence_driver_init(struct radeon_device *rdev)
906{
907 int ring;
908
909 init_waitqueue_head(&rdev->fence_queue);
910 for (ring = 0; ring < RADEON_NUM_RINGS; ring++) {
911 radeon_fence_driver_init_ring(rdev, ring);
912 }
913 if (radeon_debugfs_fence_init(rdev)) {
914 dev_err(rdev->dev, "fence debugfs file creation failed\n");
915 }
916 return 0;
917}
918
919
920
921
922
923
924
925
926
927void radeon_fence_driver_fini(struct radeon_device *rdev)
928{
929 int ring, r;
930
931 mutex_lock(&rdev->ring_lock);
932 for (ring = 0; ring < RADEON_NUM_RINGS; ring++) {
933 if (!rdev->fence_drv[ring].initialized)
934 continue;
935 r = radeon_fence_wait_empty(rdev, ring);
936 if (r) {
937
938 radeon_fence_driver_force_completion(rdev, ring);
939 }
940 cancel_delayed_work_sync(&rdev->fence_drv[ring].lockup_work);
941 wake_up_all(&rdev->fence_queue);
942 radeon_scratch_free(rdev, rdev->fence_drv[ring].scratch_reg);
943 rdev->fence_drv[ring].initialized = false;
944 }
945 mutex_unlock(&rdev->ring_lock);
946}
947
948
949
950
951
952
953
954
955
956
957void radeon_fence_driver_force_completion(struct radeon_device *rdev, int ring)
958{
959 if (rdev->fence_drv[ring].initialized) {
960 radeon_fence_write(rdev, rdev->fence_drv[ring].sync_seq[ring], ring);
961 cancel_delayed_work_sync(&rdev->fence_drv[ring].lockup_work);
962 }
963}
964
965
966
967
968
969#if defined(CONFIG_DEBUG_FS)
970static int radeon_debugfs_fence_info(struct seq_file *m, void *data)
971{
972 struct drm_info_node *node = (struct drm_info_node *)m->private;
973 struct drm_device *dev = node->minor->dev;
974 struct radeon_device *rdev = dev->dev_private;
975 int i, j;
976
977 for (i = 0; i < RADEON_NUM_RINGS; ++i) {
978 if (!rdev->fence_drv[i].initialized)
979 continue;
980
981 radeon_fence_process(rdev, i);
982
983 seq_printf(m, "--- ring %d ---\n", i);
984 seq_printf(m, "Last signaled fence 0x%016llx\n",
985 (unsigned long long)atomic64_read(&rdev->fence_drv[i].last_seq));
986 seq_printf(m, "Last emitted 0x%016llx\n",
987 rdev->fence_drv[i].sync_seq[i]);
988
989 for (j = 0; j < RADEON_NUM_RINGS; ++j) {
990 if (i != j && rdev->fence_drv[j].initialized)
991 seq_printf(m, "Last sync to ring %d 0x%016llx\n",
992 j, rdev->fence_drv[i].sync_seq[j]);
993 }
994 }
995 return 0;
996}
997
998
999
1000
1001
1002
1003static int radeon_debugfs_gpu_reset(struct seq_file *m, void *data)
1004{
1005 struct drm_info_node *node = (struct drm_info_node *) m->private;
1006 struct drm_device *dev = node->minor->dev;
1007 struct radeon_device *rdev = dev->dev_private;
1008
1009 down_read(&rdev->exclusive_lock);
1010 seq_printf(m, "%d\n", rdev->needs_reset);
1011 rdev->needs_reset = true;
1012 wake_up_all(&rdev->fence_queue);
1013 up_read(&rdev->exclusive_lock);
1014
1015 return 0;
1016}
1017
1018static struct drm_info_list radeon_debugfs_fence_list[] = {
1019 {"radeon_fence_info", &radeon_debugfs_fence_info, 0, NULL},
1020 {"radeon_gpu_reset", &radeon_debugfs_gpu_reset, 0, NULL}
1021};
1022#endif
1023
1024int radeon_debugfs_fence_init(struct radeon_device *rdev)
1025{
1026#if defined(CONFIG_DEBUG_FS)
1027 return radeon_debugfs_add_files(rdev, radeon_debugfs_fence_list, 2);
1028#else
1029 return 0;
1030#endif
1031}
1032
1033static const char *radeon_fence_get_driver_name(struct dma_fence *fence)
1034{
1035 return "radeon";
1036}
1037
1038static const char *radeon_fence_get_timeline_name(struct dma_fence *f)
1039{
1040 struct radeon_fence *fence = to_radeon_fence(f);
1041 switch (fence->ring) {
1042 case RADEON_RING_TYPE_GFX_INDEX: return "radeon.gfx";
1043 case CAYMAN_RING_TYPE_CP1_INDEX: return "radeon.cp1";
1044 case CAYMAN_RING_TYPE_CP2_INDEX: return "radeon.cp2";
1045 case R600_RING_TYPE_DMA_INDEX: return "radeon.dma";
1046 case CAYMAN_RING_TYPE_DMA1_INDEX: return "radeon.dma1";
1047 case R600_RING_TYPE_UVD_INDEX: return "radeon.uvd";
1048 case TN_RING_TYPE_VCE1_INDEX: return "radeon.vce1";
1049 case TN_RING_TYPE_VCE2_INDEX: return "radeon.vce2";
1050 default: WARN_ON_ONCE(1); return "radeon.unk";
1051 }
1052}
1053
1054static inline bool radeon_test_signaled(struct radeon_fence *fence)
1055{
1056 return test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->base.flags);
1057}
1058
1059struct radeon_wait_cb {
1060 struct dma_fence_cb base;
1061 struct task_struct *task;
1062};
1063
1064static void
1065radeon_fence_wait_cb(struct dma_fence *fence, struct dma_fence_cb *cb)
1066{
1067 struct radeon_wait_cb *wait =
1068 container_of(cb, struct radeon_wait_cb, base);
1069
1070 wake_up_process(wait->task);
1071}
1072
1073static signed long radeon_fence_default_wait(struct dma_fence *f, bool intr,
1074 signed long t)
1075{
1076 struct radeon_fence *fence = to_radeon_fence(f);
1077 struct radeon_device *rdev = fence->rdev;
1078 struct radeon_wait_cb cb;
1079
1080 cb.task = current;
1081
1082 if (dma_fence_add_callback(f, &cb.base, radeon_fence_wait_cb))
1083 return t;
1084
1085 while (t > 0) {
1086 if (intr)
1087 set_current_state(TASK_INTERRUPTIBLE);
1088 else
1089 set_current_state(TASK_UNINTERRUPTIBLE);
1090
1091
1092
1093
1094
1095 if (radeon_test_signaled(fence))
1096 break;
1097
1098 if (rdev->needs_reset) {
1099 t = -EDEADLK;
1100 break;
1101 }
1102
1103 t = schedule_timeout(t);
1104
1105 if (t > 0 && intr && signal_pending(current))
1106 t = -ERESTARTSYS;
1107 }
1108
1109 __set_current_state(TASK_RUNNING);
1110 dma_fence_remove_callback(f, &cb.base);
1111
1112 return t;
1113}
1114
1115const struct dma_fence_ops radeon_fence_ops = {
1116 .get_driver_name = radeon_fence_get_driver_name,
1117 .get_timeline_name = radeon_fence_get_timeline_name,
1118 .enable_signaling = radeon_fence_enable_signaling,
1119 .signaled = radeon_fence_is_signaled,
1120 .wait = radeon_fence_default_wait,
1121 .release = NULL,
1122};
1123