2 * Copyright 2009 Jerome Glisse.
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
28 * Jerome Glisse <glisse@freedesktop.org>
31 #include <linux/seq_file.h>
32 #include <linux/atomic.h>
33 #include <linux/wait.h>
34 #include <linux/list.h>
35 #include <linux/kref.h>
36 #include <linux/slab.h>
39 #include "radeon_reg.h"
41 #include "radeon_trace.h"
45 * Fences mark an event in the GPUs pipeline and are used
46 * for GPU/CPU synchronization. When the fence is written,
47 * it is expected that all buffers associated with that fence
48 * are no longer in use by the associated ring on the GPU and
49 * that the the relevant GPU caches have been flushed. Whether
50 * we use a scratch register or memory location depends on the asic
51 * and whether writeback is enabled.
55 * radeon_fence_write - write a fence value
57 * @rdev: radeon_device pointer
58 * @seq: sequence number to write
59 * @ring: ring index the fence is associated with
61 * Writes a fence value to memory or a scratch register (all asics).
63 static void radeon_fence_write(struct radeon_device
*rdev
, u32 seq
, int ring
)
65 struct radeon_fence_driver
*drv
= &rdev
->fence_drv
[ring
];
66 if (likely(rdev
->wb
.enabled
|| !drv
->scratch_reg
)) {
67 *drv
->cpu_addr
= cpu_to_le32(seq
);
69 WREG32(drv
->scratch_reg
, seq
);
74 * radeon_fence_read - read a fence value
76 * @rdev: radeon_device pointer
77 * @ring: ring index the fence is associated with
79 * Reads a fence value from memory or a scratch register (all asics).
80 * Returns the value of the fence read from memory or register.
82 static u32
radeon_fence_read(struct radeon_device
*rdev
, int ring
)
84 struct radeon_fence_driver
*drv
= &rdev
->fence_drv
[ring
];
87 if (likely(rdev
->wb
.enabled
|| !drv
->scratch_reg
)) {
88 seq
= le32_to_cpu(*drv
->cpu_addr
);
90 seq
= RREG32(drv
->scratch_reg
);
96 * radeon_fence_emit - emit a fence on the requested ring
98 * @rdev: radeon_device pointer
99 * @fence: radeon fence object
100 * @ring: ring index the fence is associated with
102 * Emits a fence command on the requested ring (all asics).
103 * Returns 0 on success, -ENOMEM on failure.
105 int radeon_fence_emit(struct radeon_device
*rdev
,
106 struct radeon_fence
**fence
,
109 /* we are protected by the ring emission mutex */
110 *fence
= kmalloc(sizeof(struct radeon_fence
), GFP_KERNEL
);
111 if ((*fence
) == NULL
) {
114 kref_init(&((*fence
)->kref
));
115 (*fence
)->rdev
= rdev
;
116 (*fence
)->seq
= ++rdev
->fence_drv
[ring
].sync_seq
[ring
];
117 (*fence
)->ring
= ring
;
118 radeon_fence_ring_emit(rdev
, ring
, *fence
);
119 trace_radeon_fence_emit(rdev
->ddev
, (*fence
)->seq
);
124 * radeon_fence_process - process a fence
126 * @rdev: radeon_device pointer
127 * @ring: ring index the fence is associated with
129 * Checks the current fence value and wakes the fence queue
130 * if the sequence number has increased (all asics).
132 void radeon_fence_process(struct radeon_device
*rdev
, int ring
)
134 uint64_t seq
, last_seq
, last_emitted
;
135 unsigned count_loop
= 0;
138 /* Note there is a scenario here for an infinite loop but it's
139 * very unlikely to happen. For it to happen, the current polling
140 * process need to be interrupted by another process and another
141 * process needs to update the last_seq btw the atomic read and
142 * xchg of the current process.
144 * More over for this to go in infinite loop there need to be
145 * continuously new fence signaled ie radeon_fence_read needs
146 * to return a different value each time for both the currently
147 * polling process and the other process that xchg the last_seq
148 * btw atomic read and xchg of the current process. And the
149 * value the other process set as last seq must be higher than
150 * the seq value we just read. Which means that current process
151 * need to be interrupted after radeon_fence_read and before
154 * To be even more safe we count the number of time we loop and
155 * we bail after 10 loop just accepting the fact that we might
156 * have temporarly set the last_seq not to the true real last
157 * seq but to an older one.
159 last_seq
= atomic64_read(&rdev
->fence_drv
[ring
].last_seq
);
161 last_emitted
= rdev
->fence_drv
[ring
].sync_seq
[ring
];
162 seq
= radeon_fence_read(rdev
, ring
);
163 seq
|= last_seq
& 0xffffffff00000000LL
;
164 if (seq
< last_seq
) {
166 seq
|= last_emitted
& 0xffffffff00000000LL
;
169 if (seq
<= last_seq
|| seq
> last_emitted
) {
172 /* If we loop over we don't want to return without
173 * checking if a fence is signaled as it means that the
174 * seq we just read is different from the previous on.
178 if ((count_loop
++) > 10) {
179 /* We looped over too many time leave with the
180 * fact that we might have set an older fence
181 * seq then the current real last seq as signaled
186 } while (atomic64_xchg(&rdev
->fence_drv
[ring
].last_seq
, seq
) > seq
);
189 rdev
->fence_drv
[ring
].last_activity
= jiffies
;
190 wake_up_all(&rdev
->fence_queue
);
195 * radeon_fence_destroy - destroy a fence
199 * Frees the fence object (all asics).
201 static void radeon_fence_destroy(struct kref
*kref
)
203 struct radeon_fence
*fence
;
205 fence
= container_of(kref
, struct radeon_fence
, kref
);
210 * radeon_fence_seq_signaled - check if a fence sequeuce number has signaled
212 * @rdev: radeon device pointer
213 * @seq: sequence number
214 * @ring: ring index the fence is associated with
216 * Check if the last singled fence sequnce number is >= the requested
217 * sequence number (all asics).
218 * Returns true if the fence has signaled (current fence value
219 * is >= requested value) or false if it has not (current fence
220 * value is < the requested value. Helper function for
221 * radeon_fence_signaled().
223 static bool radeon_fence_seq_signaled(struct radeon_device
*rdev
,
224 u64 seq
, unsigned ring
)
226 if (atomic64_read(&rdev
->fence_drv
[ring
].last_seq
) >= seq
) {
229 /* poll new last sequence at least once */
230 radeon_fence_process(rdev
, ring
);
231 if (atomic64_read(&rdev
->fence_drv
[ring
].last_seq
) >= seq
) {
238 * radeon_fence_signaled - check if a fence has signaled
240 * @fence: radeon fence object
242 * Check if the requested fence has signaled (all asics).
243 * Returns true if the fence has signaled or false if it has not.
245 bool radeon_fence_signaled(struct radeon_fence
*fence
)
250 if (fence
->seq
== RADEON_FENCE_SIGNALED_SEQ
) {
253 if (radeon_fence_seq_signaled(fence
->rdev
, fence
->seq
, fence
->ring
)) {
254 fence
->seq
= RADEON_FENCE_SIGNALED_SEQ
;
261 * radeon_fence_wait_seq - wait for a specific sequence number
263 * @rdev: radeon device pointer
264 * @target_seq: sequence number we want to wait for
265 * @ring: ring index the fence is associated with
266 * @intr: use interruptable sleep
267 * @lock_ring: whether the ring should be locked or not
269 * Wait for the requested sequence number to be written (all asics).
270 * @intr selects whether to use interruptable (true) or non-interruptable
271 * (false) sleep when waiting for the sequence number. Helper function
272 * for radeon_fence_wait(), et al.
273 * Returns 0 if the sequence number has passed, error for all other cases.
274 * -EDEADLK is returned when a GPU lockup has been detected and the ring is
275 * marked as not ready so no further jobs get scheduled until a successful
278 static int radeon_fence_wait_seq(struct radeon_device
*rdev
, u64 target_seq
,
279 unsigned ring
, bool intr
, bool lock_ring
)
281 unsigned long timeout
, last_activity
;
287 while (target_seq
> atomic64_read(&rdev
->fence_drv
[ring
].last_seq
)) {
288 if (!rdev
->ring
[ring
].ready
) {
292 timeout
= jiffies
- RADEON_FENCE_JIFFIES_TIMEOUT
;
293 if (time_after(rdev
->fence_drv
[ring
].last_activity
, timeout
)) {
294 /* the normal case, timeout is somewhere before last_activity */
295 timeout
= rdev
->fence_drv
[ring
].last_activity
- timeout
;
297 /* either jiffies wrapped around, or no fence was signaled in the last 500ms
298 * anyway we will just wait for the minimum amount and then check for a lockup
302 seq
= atomic64_read(&rdev
->fence_drv
[ring
].last_seq
);
303 /* Save current last activity valuee, used to check for GPU lockups */
304 last_activity
= rdev
->fence_drv
[ring
].last_activity
;
306 trace_radeon_fence_wait_begin(rdev
->ddev
, seq
);
307 radeon_irq_kms_sw_irq_get(rdev
, ring
);
309 r
= wait_event_interruptible_timeout(rdev
->fence_queue
,
310 (signaled
= radeon_fence_seq_signaled(rdev
, target_seq
, ring
)),
313 r
= wait_event_timeout(rdev
->fence_queue
,
314 (signaled
= radeon_fence_seq_signaled(rdev
, target_seq
, ring
)),
317 radeon_irq_kms_sw_irq_put(rdev
, ring
);
318 if (unlikely(r
< 0)) {
321 trace_radeon_fence_wait_end(rdev
->ddev
, seq
);
323 if (unlikely(!signaled
)) {
324 /* we were interrupted for some reason and fence
325 * isn't signaled yet, resume waiting */
330 /* check if sequence value has changed since last_activity */
331 if (seq
!= atomic64_read(&rdev
->fence_drv
[ring
].last_seq
)) {
336 mutex_lock(&rdev
->ring_lock
);
339 /* test if somebody else has already decided that this is a lockup */
340 if (last_activity
!= rdev
->fence_drv
[ring
].last_activity
) {
342 mutex_unlock(&rdev
->ring_lock
);
347 if (radeon_ring_is_lockup(rdev
, ring
, &rdev
->ring
[ring
])) {
348 /* good news we believe it's a lockup */
349 dev_warn(rdev
->dev
, "GPU lockup (waiting for 0x%016llx last fence id 0x%016llx)\n",
352 /* change last activity so nobody else think there is a lockup */
353 for (i
= 0; i
< RADEON_NUM_RINGS
; ++i
) {
354 rdev
->fence_drv
[i
].last_activity
= jiffies
;
357 /* mark the ring as not ready any more */
358 rdev
->ring
[ring
].ready
= false;
360 mutex_unlock(&rdev
->ring_lock
);
366 mutex_unlock(&rdev
->ring_lock
);
374 * radeon_fence_wait - wait for a fence to signal
376 * @fence: radeon fence object
377 * @intr: use interruptable sleep
379 * Wait for the requested fence to signal (all asics).
380 * @intr selects whether to use interruptable (true) or non-interruptable
381 * (false) sleep when waiting for the fence.
382 * Returns 0 if the fence has passed, error for all other cases.
384 int radeon_fence_wait(struct radeon_fence
*fence
, bool intr
)
389 WARN(1, "Querying an invalid fence : %p !\n", fence
);
393 r
= radeon_fence_wait_seq(fence
->rdev
, fence
->seq
,
394 fence
->ring
, intr
, true);
398 fence
->seq
= RADEON_FENCE_SIGNALED_SEQ
;
402 bool radeon_fence_any_seq_signaled(struct radeon_device
*rdev
, u64
*seq
)
406 for (i
= 0; i
< RADEON_NUM_RINGS
; ++i
) {
407 if (seq
[i
] && radeon_fence_seq_signaled(rdev
, seq
[i
], i
)) {
415 * radeon_fence_wait_any_seq - wait for a sequence number on any ring
417 * @rdev: radeon device pointer
418 * @target_seq: sequence number(s) we want to wait for
419 * @intr: use interruptable sleep
421 * Wait for the requested sequence number(s) to be written by any ring
422 * (all asics). Sequnce number array is indexed by ring id.
423 * @intr selects whether to use interruptable (true) or non-interruptable
424 * (false) sleep when waiting for the sequence number. Helper function
425 * for radeon_fence_wait_any(), et al.
426 * Returns 0 if the sequence number has passed, error for all other cases.
428 static int radeon_fence_wait_any_seq(struct radeon_device
*rdev
,
429 u64
*target_seq
, bool intr
)
431 unsigned long timeout
, last_activity
, tmp
;
432 unsigned i
, ring
= RADEON_NUM_RINGS
;
436 for (i
= 0, last_activity
= 0; i
< RADEON_NUM_RINGS
; ++i
) {
437 if (!target_seq
[i
]) {
441 /* use the most recent one as indicator */
442 if (time_after(rdev
->fence_drv
[i
].last_activity
, last_activity
)) {
443 last_activity
= rdev
->fence_drv
[i
].last_activity
;
446 /* For lockup detection just pick the lowest ring we are
447 * actively waiting for
454 /* nothing to wait for ? */
455 if (ring
== RADEON_NUM_RINGS
) {
459 while (!radeon_fence_any_seq_signaled(rdev
, target_seq
)) {
460 timeout
= jiffies
- RADEON_FENCE_JIFFIES_TIMEOUT
;
461 if (time_after(last_activity
, timeout
)) {
462 /* the normal case, timeout is somewhere before last_activity */
463 timeout
= last_activity
- timeout
;
465 /* either jiffies wrapped around, or no fence was signaled in the last 500ms
466 * anyway we will just wait for the minimum amount and then check for a lockup
471 trace_radeon_fence_wait_begin(rdev
->ddev
, target_seq
[ring
]);
472 for (i
= 0; i
< RADEON_NUM_RINGS
; ++i
) {
474 radeon_irq_kms_sw_irq_get(rdev
, i
);
478 r
= wait_event_interruptible_timeout(rdev
->fence_queue
,
479 (signaled
= radeon_fence_any_seq_signaled(rdev
, target_seq
)),
482 r
= wait_event_timeout(rdev
->fence_queue
,
483 (signaled
= radeon_fence_any_seq_signaled(rdev
, target_seq
)),
486 for (i
= 0; i
< RADEON_NUM_RINGS
; ++i
) {
488 radeon_irq_kms_sw_irq_put(rdev
, i
);
491 if (unlikely(r
< 0)) {
494 trace_radeon_fence_wait_end(rdev
->ddev
, target_seq
[ring
]);
496 if (unlikely(!signaled
)) {
497 /* we were interrupted for some reason and fence
498 * isn't signaled yet, resume waiting */
503 mutex_lock(&rdev
->ring_lock
);
504 for (i
= 0, tmp
= 0; i
< RADEON_NUM_RINGS
; ++i
) {
505 if (time_after(rdev
->fence_drv
[i
].last_activity
, tmp
)) {
506 tmp
= rdev
->fence_drv
[i
].last_activity
;
509 /* test if somebody else has already decided that this is a lockup */
510 if (last_activity
!= tmp
) {
512 mutex_unlock(&rdev
->ring_lock
);
516 if (radeon_ring_is_lockup(rdev
, ring
, &rdev
->ring
[ring
])) {
517 /* good news we believe it's a lockup */
518 dev_warn(rdev
->dev
, "GPU lockup (waiting for 0x%016llx)\n",
521 /* change last activity so nobody else think there is a lockup */
522 for (i
= 0; i
< RADEON_NUM_RINGS
; ++i
) {
523 rdev
->fence_drv
[i
].last_activity
= jiffies
;
526 /* mark the ring as not ready any more */
527 rdev
->ring
[ring
].ready
= false;
528 mutex_unlock(&rdev
->ring_lock
);
531 mutex_unlock(&rdev
->ring_lock
);
538 * radeon_fence_wait_any - wait for a fence to signal on any ring
540 * @rdev: radeon device pointer
541 * @fences: radeon fence object(s)
542 * @intr: use interruptable sleep
544 * Wait for any requested fence to signal (all asics). Fence
545 * array is indexed by ring id. @intr selects whether to use
546 * interruptable (true) or non-interruptable (false) sleep when
547 * waiting for the fences. Used by the suballocator.
548 * Returns 0 if any fence has passed, error for all other cases.
550 int radeon_fence_wait_any(struct radeon_device
*rdev
,
551 struct radeon_fence
**fences
,
554 uint64_t seq
[RADEON_NUM_RINGS
];
558 for (i
= 0; i
< RADEON_NUM_RINGS
; ++i
) {
565 if (fences
[i
]->seq
== RADEON_FENCE_SIGNALED_SEQ
) {
566 /* something was allready signaled */
570 seq
[i
] = fences
[i
]->seq
;
573 r
= radeon_fence_wait_any_seq(rdev
, seq
, intr
);
581 * radeon_fence_wait_next_locked - wait for the next fence to signal
583 * @rdev: radeon device pointer
584 * @ring: ring index the fence is associated with
586 * Wait for the next fence on the requested ring to signal (all asics).
587 * Returns 0 if the next fence has passed, error for all other cases.
588 * Caller must hold ring lock.
590 int radeon_fence_wait_next_locked(struct radeon_device
*rdev
, int ring
)
594 seq
= atomic64_read(&rdev
->fence_drv
[ring
].last_seq
) + 1ULL;
595 if (seq
>= rdev
->fence_drv
[ring
].sync_seq
[ring
]) {
596 /* nothing to wait for, last_seq is
597 already the last emited fence */
600 return radeon_fence_wait_seq(rdev
, seq
, ring
, false, false);
604 * radeon_fence_wait_empty_locked - wait for all fences to signal
606 * @rdev: radeon device pointer
607 * @ring: ring index the fence is associated with
609 * Wait for all fences on the requested ring to signal (all asics).
610 * Returns 0 if the fences have passed, error for all other cases.
611 * Caller must hold ring lock.
613 void radeon_fence_wait_empty_locked(struct radeon_device
*rdev
, int ring
)
615 uint64_t seq
= rdev
->fence_drv
[ring
].sync_seq
[ring
];
619 r
= radeon_fence_wait_seq(rdev
, seq
, ring
, false, false);
621 mutex_unlock(&rdev
->ring_lock
);
622 r
= radeon_gpu_reset(rdev
);
623 mutex_lock(&rdev
->ring_lock
);
628 dev_err(rdev
->dev
, "error waiting for ring to become"
636 * radeon_fence_ref - take a ref on a fence
638 * @fence: radeon fence object
640 * Take a reference on a fence (all asics).
643 struct radeon_fence
*radeon_fence_ref(struct radeon_fence
*fence
)
645 kref_get(&fence
->kref
);
650 * radeon_fence_unref - remove a ref on a fence
652 * @fence: radeon fence object
654 * Remove a reference on a fence (all asics).
656 void radeon_fence_unref(struct radeon_fence
**fence
)
658 struct radeon_fence
*tmp
= *fence
;
662 kref_put(&tmp
->kref
, radeon_fence_destroy
);
667 * radeon_fence_count_emitted - get the count of emitted fences
669 * @rdev: radeon device pointer
670 * @ring: ring index the fence is associated with
672 * Get the number of fences emitted on the requested ring (all asics).
673 * Returns the number of emitted fences on the ring. Used by the
674 * dynpm code to ring track activity.
676 unsigned radeon_fence_count_emitted(struct radeon_device
*rdev
, int ring
)
680 /* We are not protected by ring lock when reading the last sequence
681 * but it's ok to report slightly wrong fence count here.
683 radeon_fence_process(rdev
, ring
);
684 emitted
= rdev
->fence_drv
[ring
].sync_seq
[ring
]
685 - atomic64_read(&rdev
->fence_drv
[ring
].last_seq
);
686 /* to avoid 32bits warp around */
687 if (emitted
> 0x10000000) {
688 emitted
= 0x10000000;
690 return (unsigned)emitted
;
694 * radeon_fence_need_sync - do we need a semaphore
696 * @fence: radeon fence object
697 * @dst_ring: which ring to check against
699 * Check if the fence needs to be synced against another ring
700 * (all asics). If so, we need to emit a semaphore.
701 * Returns true if we need to sync with another ring, false if
704 bool radeon_fence_need_sync(struct radeon_fence
*fence
, int dst_ring
)
706 struct radeon_fence_driver
*fdrv
;
712 if (fence
->ring
== dst_ring
) {
716 /* we are protected by the ring mutex */
717 fdrv
= &fence
->rdev
->fence_drv
[dst_ring
];
718 if (fence
->seq
<= fdrv
->sync_seq
[fence
->ring
]) {
726 * radeon_fence_note_sync - record the sync point
728 * @fence: radeon fence object
729 * @dst_ring: which ring to check against
731 * Note the sequence number at which point the fence will
732 * be synced with the requested ring (all asics).
734 void radeon_fence_note_sync(struct radeon_fence
*fence
, int dst_ring
)
736 struct radeon_fence_driver
*dst
, *src
;
743 if (fence
->ring
== dst_ring
) {
747 /* we are protected by the ring mutex */
748 src
= &fence
->rdev
->fence_drv
[fence
->ring
];
749 dst
= &fence
->rdev
->fence_drv
[dst_ring
];
750 for (i
= 0; i
< RADEON_NUM_RINGS
; ++i
) {
754 dst
->sync_seq
[i
] = max(dst
->sync_seq
[i
], src
->sync_seq
[i
]);
759 * radeon_fence_driver_start_ring - make the fence driver
760 * ready for use on the requested ring.
762 * @rdev: radeon device pointer
763 * @ring: ring index to start the fence driver on
765 * Make the fence driver ready for processing (all asics).
766 * Not all asics have all rings, so each asic will only
767 * start the fence driver on the rings it has.
768 * Returns 0 for success, errors for failure.
770 int radeon_fence_driver_start_ring(struct radeon_device
*rdev
, int ring
)
775 radeon_scratch_free(rdev
, rdev
->fence_drv
[ring
].scratch_reg
);
776 if (rdev
->wb
.use_event
) {
777 rdev
->fence_drv
[ring
].scratch_reg
= 0;
778 index
= R600_WB_EVENT_OFFSET
+ ring
* 4;
780 r
= radeon_scratch_get(rdev
, &rdev
->fence_drv
[ring
].scratch_reg
);
782 dev_err(rdev
->dev
, "fence failed to get scratch register\n");
785 index
= RADEON_WB_SCRATCH_OFFSET
+
786 rdev
->fence_drv
[ring
].scratch_reg
-
787 rdev
->scratch
.reg_base
;
789 rdev
->fence_drv
[ring
].cpu_addr
= &rdev
->wb
.wb
[index
/4];
790 rdev
->fence_drv
[ring
].gpu_addr
= rdev
->wb
.gpu_addr
+ index
;
791 radeon_fence_write(rdev
, atomic64_read(&rdev
->fence_drv
[ring
].last_seq
), ring
);
792 rdev
->fence_drv
[ring
].initialized
= true;
793 dev_info(rdev
->dev
, "fence driver on ring %d use gpu addr 0x%016llx and cpu addr 0x%p\n",
794 ring
, rdev
->fence_drv
[ring
].gpu_addr
, rdev
->fence_drv
[ring
].cpu_addr
);
799 * radeon_fence_driver_init_ring - init the fence driver
800 * for the requested ring.
802 * @rdev: radeon device pointer
803 * @ring: ring index to start the fence driver on
805 * Init the fence driver for the requested ring (all asics).
806 * Helper function for radeon_fence_driver_init().
808 static void radeon_fence_driver_init_ring(struct radeon_device
*rdev
, int ring
)
812 rdev
->fence_drv
[ring
].scratch_reg
= -1;
813 rdev
->fence_drv
[ring
].cpu_addr
= NULL
;
814 rdev
->fence_drv
[ring
].gpu_addr
= 0;
815 for (i
= 0; i
< RADEON_NUM_RINGS
; ++i
)
816 rdev
->fence_drv
[ring
].sync_seq
[i
] = 0;
817 atomic64_set(&rdev
->fence_drv
[ring
].last_seq
, 0);
818 rdev
->fence_drv
[ring
].last_activity
= jiffies
;
819 rdev
->fence_drv
[ring
].initialized
= false;
823 * radeon_fence_driver_init - init the fence driver
824 * for all possible rings.
826 * @rdev: radeon device pointer
828 * Init the fence driver for all possible rings (all asics).
829 * Not all asics have all rings, so each asic will only
830 * start the fence driver on the rings it has using
831 * radeon_fence_driver_start_ring().
832 * Returns 0 for success.
834 int radeon_fence_driver_init(struct radeon_device
*rdev
)
838 init_waitqueue_head(&rdev
->fence_queue
);
839 for (ring
= 0; ring
< RADEON_NUM_RINGS
; ring
++) {
840 radeon_fence_driver_init_ring(rdev
, ring
);
842 if (radeon_debugfs_fence_init(rdev
)) {
843 dev_err(rdev
->dev
, "fence debugfs file creation failed\n");
849 * radeon_fence_driver_fini - tear down the fence driver
850 * for all possible rings.
852 * @rdev: radeon device pointer
854 * Tear down the fence driver for all possible rings (all asics).
856 void radeon_fence_driver_fini(struct radeon_device
*rdev
)
860 mutex_lock(&rdev
->ring_lock
);
861 for (ring
= 0; ring
< RADEON_NUM_RINGS
; ring
++) {
862 if (!rdev
->fence_drv
[ring
].initialized
)
864 radeon_fence_wait_empty_locked(rdev
, ring
);
865 wake_up_all(&rdev
->fence_queue
);
866 radeon_scratch_free(rdev
, rdev
->fence_drv
[ring
].scratch_reg
);
867 rdev
->fence_drv
[ring
].initialized
= false;
869 mutex_unlock(&rdev
->ring_lock
);
876 #if defined(CONFIG_DEBUG_FS)
877 static int radeon_debugfs_fence_info(struct seq_file
*m
, void *data
)
879 struct drm_info_node
*node
= (struct drm_info_node
*)m
->private;
880 struct drm_device
*dev
= node
->minor
->dev
;
881 struct radeon_device
*rdev
= dev
->dev_private
;
884 for (i
= 0; i
< RADEON_NUM_RINGS
; ++i
) {
885 if (!rdev
->fence_drv
[i
].initialized
)
888 seq_printf(m
, "--- ring %d ---\n", i
);
889 seq_printf(m
, "Last signaled fence 0x%016llx\n",
890 (unsigned long long)atomic64_read(&rdev
->fence_drv
[i
].last_seq
));
891 seq_printf(m
, "Last emitted 0x%016llx\n",
892 rdev
->fence_drv
[i
].sync_seq
[i
]);
894 for (j
= 0; j
< RADEON_NUM_RINGS
; ++j
) {
895 if (i
!= j
&& rdev
->fence_drv
[j
].initialized
)
896 seq_printf(m
, "Last sync to ring %d 0x%016llx\n",
897 j
, rdev
->fence_drv
[i
].sync_seq
[j
]);
903 static struct drm_info_list radeon_debugfs_fence_list
[] = {
904 {"radeon_fence_info", &radeon_debugfs_fence_info
, 0, NULL
},
908 int radeon_debugfs_fence_init(struct radeon_device
*rdev
)
910 #if defined(CONFIG_DEBUG_FS)
911 return radeon_debugfs_add_files(rdev
, radeon_debugfs_fence_list
, 1);