1b843c749SSergey Zigachev /*
2b843c749SSergey Zigachev * Copyright 2009 Jerome Glisse.
3b843c749SSergey Zigachev * All Rights Reserved.
4b843c749SSergey Zigachev *
5b843c749SSergey Zigachev * Permission is hereby granted, free of charge, to any person obtaining a
6b843c749SSergey Zigachev * copy of this software and associated documentation files (the
7b843c749SSergey Zigachev * "Software"), to deal in the Software without restriction, including
8b843c749SSergey Zigachev * without limitation the rights to use, copy, modify, merge, publish,
9b843c749SSergey Zigachev * distribute, sub license, and/or sell copies of the Software, and to
10b843c749SSergey Zigachev * permit persons to whom the Software is furnished to do so, subject to
11b843c749SSergey Zigachev * the following conditions:
12b843c749SSergey Zigachev *
13b843c749SSergey Zigachev * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14b843c749SSergey Zigachev * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15b843c749SSergey Zigachev * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
16b843c749SSergey Zigachev * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
17b843c749SSergey Zigachev * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
18b843c749SSergey Zigachev * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
19b843c749SSergey Zigachev * USE OR OTHER DEALINGS IN THE SOFTWARE.
20b843c749SSergey Zigachev *
21b843c749SSergey Zigachev * The above copyright notice and this permission notice (including the
22b843c749SSergey Zigachev * next paragraph) shall be included in all copies or substantial portions
23b843c749SSergey Zigachev * of the Software.
24b843c749SSergey Zigachev *
25b843c749SSergey Zigachev */
26b843c749SSergey Zigachev /*
27b843c749SSergey Zigachev * Authors:
28b843c749SSergey Zigachev * Jerome Glisse <glisse@freedesktop.org>
29b843c749SSergey Zigachev * Dave Airlie
30b843c749SSergey Zigachev */
31b843c749SSergey Zigachev #include <linux/seq_file.h>
32b843c749SSergey Zigachev #include <linux/atomic.h>
33b843c749SSergey Zigachev #include <linux/wait.h>
34b843c749SSergey Zigachev #include <linux/kref.h>
35b843c749SSergey Zigachev #include <linux/slab.h>
36b843c749SSergey Zigachev #include <linux/firmware.h>
37b843c749SSergey Zigachev #include <drm/drmP.h>
38b843c749SSergey Zigachev #include "amdgpu.h"
39b843c749SSergey Zigachev #include "amdgpu_trace.h"
40b843c749SSergey Zigachev
41b843c749SSergey Zigachev /*
42b843c749SSergey Zigachev * Fences
43b843c749SSergey Zigachev * Fences mark an event in the GPUs pipeline and are used
44b843c749SSergey Zigachev * for GPU/CPU synchronization. When the fence is written,
45b843c749SSergey Zigachev * it is expected that all buffers associated with that fence
46b843c749SSergey Zigachev * are no longer in use by the associated ring on the GPU and
47b843c749SSergey Zigachev * that the the relevant GPU caches have been flushed.
48b843c749SSergey Zigachev */
49b843c749SSergey Zigachev
50b843c749SSergey Zigachev struct amdgpu_fence {
51b843c749SSergey Zigachev struct dma_fence base;
52b843c749SSergey Zigachev
53b843c749SSergey Zigachev /* RB, DMA, etc. */
54b843c749SSergey Zigachev struct amdgpu_ring *ring;
55b843c749SSergey Zigachev };
56b843c749SSergey Zigachev
57b843c749SSergey Zigachev static struct kmem_cache *amdgpu_fence_slab;
58b843c749SSergey Zigachev
amdgpu_fence_slab_init(void)59b843c749SSergey Zigachev int amdgpu_fence_slab_init(void)
60b843c749SSergey Zigachev {
61b843c749SSergey Zigachev amdgpu_fence_slab = kmem_cache_create(
62b843c749SSergey Zigachev "amdgpu_fence", sizeof(struct amdgpu_fence), 0,
63b843c749SSergey Zigachev SLAB_HWCACHE_ALIGN, NULL);
64b843c749SSergey Zigachev if (!amdgpu_fence_slab)
65b843c749SSergey Zigachev return -ENOMEM;
66b843c749SSergey Zigachev return 0;
67b843c749SSergey Zigachev }
68b843c749SSergey Zigachev
amdgpu_fence_slab_fini(void)69b843c749SSergey Zigachev void amdgpu_fence_slab_fini(void)
70b843c749SSergey Zigachev {
71b843c749SSergey Zigachev rcu_barrier();
72b843c749SSergey Zigachev kmem_cache_destroy(amdgpu_fence_slab);
73b843c749SSergey Zigachev }
74b843c749SSergey Zigachev /*
75b843c749SSergey Zigachev * Cast helper
76b843c749SSergey Zigachev */
77b843c749SSergey Zigachev static const struct dma_fence_ops amdgpu_fence_ops;
to_amdgpu_fence(struct dma_fence * f)78b843c749SSergey Zigachev static inline struct amdgpu_fence *to_amdgpu_fence(struct dma_fence *f)
79b843c749SSergey Zigachev {
80b843c749SSergey Zigachev struct amdgpu_fence *__f = container_of(f, struct amdgpu_fence, base);
81b843c749SSergey Zigachev
82b843c749SSergey Zigachev if (__f->base.ops == &amdgpu_fence_ops)
83b843c749SSergey Zigachev return __f;
84b843c749SSergey Zigachev
85b843c749SSergey Zigachev return NULL;
86b843c749SSergey Zigachev }
87b843c749SSergey Zigachev
88b843c749SSergey Zigachev /**
89b843c749SSergey Zigachev * amdgpu_fence_write - write a fence value
90b843c749SSergey Zigachev *
91b843c749SSergey Zigachev * @ring: ring the fence is associated with
92b843c749SSergey Zigachev * @seq: sequence number to write
93b843c749SSergey Zigachev *
94b843c749SSergey Zigachev * Writes a fence value to memory (all asics).
95b843c749SSergey Zigachev */
amdgpu_fence_write(struct amdgpu_ring * ring,u32 seq)96b843c749SSergey Zigachev static void amdgpu_fence_write(struct amdgpu_ring *ring, u32 seq)
97b843c749SSergey Zigachev {
98b843c749SSergey Zigachev struct amdgpu_fence_driver *drv = &ring->fence_drv;
99b843c749SSergey Zigachev
100b843c749SSergey Zigachev if (drv->cpu_addr)
101b843c749SSergey Zigachev *drv->cpu_addr = cpu_to_le32(seq);
102b843c749SSergey Zigachev }
103b843c749SSergey Zigachev
104b843c749SSergey Zigachev /**
105b843c749SSergey Zigachev * amdgpu_fence_read - read a fence value
106b843c749SSergey Zigachev *
107b843c749SSergey Zigachev * @ring: ring the fence is associated with
108b843c749SSergey Zigachev *
109b843c749SSergey Zigachev * Reads a fence value from memory (all asics).
110b843c749SSergey Zigachev * Returns the value of the fence read from memory.
111b843c749SSergey Zigachev */
amdgpu_fence_read(struct amdgpu_ring * ring)112b843c749SSergey Zigachev static u32 amdgpu_fence_read(struct amdgpu_ring *ring)
113b843c749SSergey Zigachev {
114b843c749SSergey Zigachev struct amdgpu_fence_driver *drv = &ring->fence_drv;
115b843c749SSergey Zigachev u32 seq = 0;
116b843c749SSergey Zigachev
117b843c749SSergey Zigachev if (drv->cpu_addr)
118b843c749SSergey Zigachev seq = le32_to_cpu(*drv->cpu_addr);
119b843c749SSergey Zigachev else
120b843c749SSergey Zigachev seq = atomic_read(&drv->last_seq);
121b843c749SSergey Zigachev
122b843c749SSergey Zigachev return seq;
123b843c749SSergey Zigachev }
124b843c749SSergey Zigachev
125b843c749SSergey Zigachev /**
126b843c749SSergey Zigachev * amdgpu_fence_emit - emit a fence on the requested ring
127b843c749SSergey Zigachev *
128b843c749SSergey Zigachev * @ring: ring the fence is associated with
129b843c749SSergey Zigachev * @f: resulting fence object
130b843c749SSergey Zigachev *
131b843c749SSergey Zigachev * Emits a fence command on the requested ring (all asics).
132b843c749SSergey Zigachev * Returns 0 on success, -ENOMEM on failure.
133b843c749SSergey Zigachev */
amdgpu_fence_emit(struct amdgpu_ring * ring,struct dma_fence ** f,unsigned flags)134b843c749SSergey Zigachev int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **f,
135b843c749SSergey Zigachev unsigned flags)
136b843c749SSergey Zigachev {
137b843c749SSergey Zigachev struct amdgpu_device *adev = ring->adev;
138b843c749SSergey Zigachev struct amdgpu_fence *fence;
139b843c749SSergey Zigachev struct dma_fence __rcu **ptr;
140b843c749SSergey Zigachev uint32_t seq;
141b843c749SSergey Zigachev int r;
142b843c749SSergey Zigachev
143b843c749SSergey Zigachev fence = kmem_cache_alloc(amdgpu_fence_slab, GFP_KERNEL);
144b843c749SSergey Zigachev if (fence == NULL)
145b843c749SSergey Zigachev return -ENOMEM;
146b843c749SSergey Zigachev
147b843c749SSergey Zigachev seq = ++ring->fence_drv.sync_seq;
148b843c749SSergey Zigachev fence->ring = ring;
149b843c749SSergey Zigachev dma_fence_init(&fence->base, &amdgpu_fence_ops,
150b843c749SSergey Zigachev &ring->fence_drv.lock,
151b843c749SSergey Zigachev adev->fence_context + ring->idx,
152b843c749SSergey Zigachev seq);
153b843c749SSergey Zigachev amdgpu_ring_emit_fence(ring, ring->fence_drv.gpu_addr,
154b843c749SSergey Zigachev seq, flags | AMDGPU_FENCE_FLAG_INT);
155b843c749SSergey Zigachev
156b843c749SSergey Zigachev ptr = &ring->fence_drv.fences[seq & ring->fence_drv.num_fences_mask];
157b843c749SSergey Zigachev if (unlikely(rcu_dereference_protected(*ptr, 1))) {
158b843c749SSergey Zigachev struct dma_fence *old;
159b843c749SSergey Zigachev
160b843c749SSergey Zigachev rcu_read_lock();
161b843c749SSergey Zigachev old = dma_fence_get_rcu_safe(ptr);
162b843c749SSergey Zigachev rcu_read_unlock();
163b843c749SSergey Zigachev
164b843c749SSergey Zigachev if (old) {
165b843c749SSergey Zigachev r = dma_fence_wait(old, false);
166b843c749SSergey Zigachev dma_fence_put(old);
167b843c749SSergey Zigachev if (r)
168b843c749SSergey Zigachev return r;
169b843c749SSergey Zigachev }
170b843c749SSergey Zigachev }
171b843c749SSergey Zigachev
172b843c749SSergey Zigachev /* This function can't be called concurrently anyway, otherwise
173b843c749SSergey Zigachev * emitting the fence would mess up the hardware ring buffer.
174b843c749SSergey Zigachev */
175b843c749SSergey Zigachev rcu_assign_pointer(*ptr, dma_fence_get(&fence->base));
176b843c749SSergey Zigachev
177b843c749SSergey Zigachev *f = &fence->base;
178b843c749SSergey Zigachev
179b843c749SSergey Zigachev return 0;
180b843c749SSergey Zigachev }
181b843c749SSergey Zigachev
182b843c749SSergey Zigachev /**
183b843c749SSergey Zigachev * amdgpu_fence_emit_polling - emit a fence on the requeste ring
184b843c749SSergey Zigachev *
185b843c749SSergey Zigachev * @ring: ring the fence is associated with
186b843c749SSergey Zigachev * @s: resulting sequence number
187b843c749SSergey Zigachev *
188b843c749SSergey Zigachev * Emits a fence command on the requested ring (all asics).
189b843c749SSergey Zigachev * Used For polling fence.
190b843c749SSergey Zigachev * Returns 0 on success, -ENOMEM on failure.
191b843c749SSergey Zigachev */
amdgpu_fence_emit_polling(struct amdgpu_ring * ring,uint32_t * s)192b843c749SSergey Zigachev int amdgpu_fence_emit_polling(struct amdgpu_ring *ring, uint32_t *s)
193b843c749SSergey Zigachev {
194b843c749SSergey Zigachev uint32_t seq;
195b843c749SSergey Zigachev
196b843c749SSergey Zigachev if (!s)
197b843c749SSergey Zigachev return -EINVAL;
198b843c749SSergey Zigachev
199b843c749SSergey Zigachev seq = ++ring->fence_drv.sync_seq;
200b843c749SSergey Zigachev amdgpu_ring_emit_fence(ring, ring->fence_drv.gpu_addr,
201b843c749SSergey Zigachev seq, 0);
202b843c749SSergey Zigachev
203b843c749SSergey Zigachev *s = seq;
204b843c749SSergey Zigachev
205b843c749SSergey Zigachev return 0;
206b843c749SSergey Zigachev }
207b843c749SSergey Zigachev
208b843c749SSergey Zigachev /**
209b843c749SSergey Zigachev * amdgpu_fence_schedule_fallback - schedule fallback check
210b843c749SSergey Zigachev *
211b843c749SSergey Zigachev * @ring: pointer to struct amdgpu_ring
212b843c749SSergey Zigachev *
213b843c749SSergey Zigachev * Start a timer as fallback to our interrupts.
214b843c749SSergey Zigachev */
amdgpu_fence_schedule_fallback(struct amdgpu_ring * ring)215b843c749SSergey Zigachev static void amdgpu_fence_schedule_fallback(struct amdgpu_ring *ring)
216b843c749SSergey Zigachev {
217b843c749SSergey Zigachev mod_timer(&ring->fence_drv.fallback_timer,
218b843c749SSergey Zigachev jiffies + AMDGPU_FENCE_JIFFIES_TIMEOUT);
219b843c749SSergey Zigachev }
220b843c749SSergey Zigachev
221b843c749SSergey Zigachev /**
222b843c749SSergey Zigachev * amdgpu_fence_process - check for fence activity
223b843c749SSergey Zigachev *
224b843c749SSergey Zigachev * @ring: pointer to struct amdgpu_ring
225b843c749SSergey Zigachev *
226b843c749SSergey Zigachev * Checks the current fence value and calculates the last
227b843c749SSergey Zigachev * signalled fence value. Wakes the fence queue if the
228b843c749SSergey Zigachev * sequence number has increased.
229b843c749SSergey Zigachev */
amdgpu_fence_process(struct amdgpu_ring * ring)230b843c749SSergey Zigachev void amdgpu_fence_process(struct amdgpu_ring *ring)
231b843c749SSergey Zigachev {
232b843c749SSergey Zigachev struct amdgpu_fence_driver *drv = &ring->fence_drv;
233b843c749SSergey Zigachev uint32_t seq, last_seq;
234b843c749SSergey Zigachev int r;
235b843c749SSergey Zigachev do {
236b843c749SSergey Zigachev last_seq = atomic_read(&ring->fence_drv.last_seq);
237b843c749SSergey Zigachev seq = amdgpu_fence_read(ring);
238b843c749SSergey Zigachev } while (atomic_cmpxchg(&drv->last_seq, last_seq, seq) != last_seq);
239b843c749SSergey Zigachev if (seq != ring->fence_drv.sync_seq)
240b843c749SSergey Zigachev amdgpu_fence_schedule_fallback(ring);
241b843c749SSergey Zigachev if (unlikely(seq == last_seq))
242b843c749SSergey Zigachev return;
243b843c749SSergey Zigachev
244b843c749SSergey Zigachev last_seq &= drv->num_fences_mask;
245b843c749SSergey Zigachev seq &= drv->num_fences_mask;
246b843c749SSergey Zigachev do {
247b843c749SSergey Zigachev struct dma_fence *fence, **ptr;
248b843c749SSergey Zigachev
249b843c749SSergey Zigachev ++last_seq;
250b843c749SSergey Zigachev last_seq &= drv->num_fences_mask;
251b843c749SSergey Zigachev ptr = &drv->fences[last_seq];
252b843c749SSergey Zigachev
253b843c749SSergey Zigachev /* There is always exactly one thread signaling this fence slot */
254b843c749SSergey Zigachev fence = rcu_dereference_protected(*ptr, 1);
255b843c749SSergey Zigachev RCU_INIT_POINTER(*ptr, NULL);
256b843c749SSergey Zigachev
257b843c749SSergey Zigachev if (!fence)
258b843c749SSergey Zigachev continue;
259b843c749SSergey Zigachev r = dma_fence_signal(fence);
260b843c749SSergey Zigachev if (!r)
261b843c749SSergey Zigachev DMA_FENCE_TRACE(fence, "signaled from irq context\n");
262b843c749SSergey Zigachev else
263b843c749SSergey Zigachev BUG();
264b843c749SSergey Zigachev dma_fence_put(fence);
265b843c749SSergey Zigachev } while (last_seq != seq);
266b843c749SSergey Zigachev }
267b843c749SSergey Zigachev
268b843c749SSergey Zigachev /**
269b843c749SSergey Zigachev * amdgpu_fence_fallback - fallback for hardware interrupts
270b843c749SSergey Zigachev *
271b843c749SSergey Zigachev * @work: delayed work item
272b843c749SSergey Zigachev *
273b843c749SSergey Zigachev * Checks for fence activity.
274b843c749SSergey Zigachev */
amdgpu_fence_fallback(struct timer_list * t)275b843c749SSergey Zigachev static void amdgpu_fence_fallback(struct timer_list *t)
276b843c749SSergey Zigachev {
277b843c749SSergey Zigachev struct amdgpu_ring *ring = from_timer(ring, t,
278b843c749SSergey Zigachev fence_drv.fallback_timer);
279b843c749SSergey Zigachev
280b843c749SSergey Zigachev amdgpu_fence_process(ring);
281b843c749SSergey Zigachev }
282b843c749SSergey Zigachev
283b843c749SSergey Zigachev /**
284b843c749SSergey Zigachev * amdgpu_fence_wait_empty - wait for all fences to signal
285b843c749SSergey Zigachev *
286b843c749SSergey Zigachev * @adev: amdgpu device pointer
287b843c749SSergey Zigachev * @ring: ring index the fence is associated with
288b843c749SSergey Zigachev *
289b843c749SSergey Zigachev * Wait for all fences on the requested ring to signal (all asics).
290b843c749SSergey Zigachev * Returns 0 if the fences have passed, error for all other cases.
291b843c749SSergey Zigachev */
amdgpu_fence_wait_empty(struct amdgpu_ring * ring)292b843c749SSergey Zigachev int amdgpu_fence_wait_empty(struct amdgpu_ring *ring)
293b843c749SSergey Zigachev {
294b843c749SSergey Zigachev uint64_t seq = READ_ONCE(ring->fence_drv.sync_seq);
295b843c749SSergey Zigachev struct dma_fence *fence, **ptr;
296b843c749SSergey Zigachev int r;
297b843c749SSergey Zigachev
298b843c749SSergey Zigachev if (!seq)
299b843c749SSergey Zigachev return 0;
300b843c749SSergey Zigachev
301b843c749SSergey Zigachev ptr = &ring->fence_drv.fences[seq & ring->fence_drv.num_fences_mask];
302b843c749SSergey Zigachev rcu_read_lock();
303b843c749SSergey Zigachev fence = rcu_dereference(*ptr);
304b843c749SSergey Zigachev if (!fence || !dma_fence_get_rcu(fence)) {
305b843c749SSergey Zigachev rcu_read_unlock();
306b843c749SSergey Zigachev return 0;
307b843c749SSergey Zigachev }
308b843c749SSergey Zigachev rcu_read_unlock();
309b843c749SSergey Zigachev
310b843c749SSergey Zigachev r = dma_fence_wait(fence, false);
311b843c749SSergey Zigachev dma_fence_put(fence);
312b843c749SSergey Zigachev return r;
313b843c749SSergey Zigachev }
314b843c749SSergey Zigachev
315b843c749SSergey Zigachev /**
316b843c749SSergey Zigachev * amdgpu_fence_wait_polling - busy wait for givn sequence number
317b843c749SSergey Zigachev *
318b843c749SSergey Zigachev * @ring: ring index the fence is associated with
319b843c749SSergey Zigachev * @wait_seq: sequence number to wait
320b843c749SSergey Zigachev * @timeout: the timeout for waiting in usecs
321b843c749SSergey Zigachev *
322b843c749SSergey Zigachev * Wait for all fences on the requested ring to signal (all asics).
323b843c749SSergey Zigachev * Returns left time if no timeout, 0 or minus if timeout.
324b843c749SSergey Zigachev */
amdgpu_fence_wait_polling(struct amdgpu_ring * ring,uint32_t wait_seq,signed long timeout)325b843c749SSergey Zigachev signed long amdgpu_fence_wait_polling(struct amdgpu_ring *ring,
326b843c749SSergey Zigachev uint32_t wait_seq,
327b843c749SSergey Zigachev signed long timeout)
328b843c749SSergey Zigachev {
329b843c749SSergey Zigachev uint32_t seq;
330b843c749SSergey Zigachev
331b843c749SSergey Zigachev do {
332b843c749SSergey Zigachev seq = amdgpu_fence_read(ring);
333b843c749SSergey Zigachev udelay(5);
334b843c749SSergey Zigachev timeout -= 5;
335b843c749SSergey Zigachev } while ((int32_t)(wait_seq - seq) > 0 && timeout > 0);
336b843c749SSergey Zigachev
337b843c749SSergey Zigachev return timeout > 0 ? timeout : 0;
338b843c749SSergey Zigachev }
339b843c749SSergey Zigachev /**
340b843c749SSergey Zigachev * amdgpu_fence_count_emitted - get the count of emitted fences
341b843c749SSergey Zigachev *
342b843c749SSergey Zigachev * @ring: ring the fence is associated with
343b843c749SSergey Zigachev *
344b843c749SSergey Zigachev * Get the number of fences emitted on the requested ring (all asics).
345b843c749SSergey Zigachev * Returns the number of emitted fences on the ring. Used by the
346b843c749SSergey Zigachev * dynpm code to ring track activity.
347b843c749SSergey Zigachev */
amdgpu_fence_count_emitted(struct amdgpu_ring * ring)348b843c749SSergey Zigachev unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring)
349b843c749SSergey Zigachev {
350b843c749SSergey Zigachev uint64_t emitted;
351b843c749SSergey Zigachev
352b843c749SSergey Zigachev /* We are not protected by ring lock when reading the last sequence
353b843c749SSergey Zigachev * but it's ok to report slightly wrong fence count here.
354b843c749SSergey Zigachev */
355b843c749SSergey Zigachev amdgpu_fence_process(ring);
356b843c749SSergey Zigachev emitted = 0x100000000ull;
357b843c749SSergey Zigachev emitted -= atomic_read(&ring->fence_drv.last_seq);
358b843c749SSergey Zigachev emitted += READ_ONCE(ring->fence_drv.sync_seq);
359b843c749SSergey Zigachev return lower_32_bits(emitted);
360b843c749SSergey Zigachev }
361b843c749SSergey Zigachev
362b843c749SSergey Zigachev /**
363b843c749SSergey Zigachev * amdgpu_fence_driver_start_ring - make the fence driver
364b843c749SSergey Zigachev * ready for use on the requested ring.
365b843c749SSergey Zigachev *
366b843c749SSergey Zigachev * @ring: ring to start the fence driver on
367b843c749SSergey Zigachev * @irq_src: interrupt source to use for this ring
368b843c749SSergey Zigachev * @irq_type: interrupt type to use for this ring
369b843c749SSergey Zigachev *
370b843c749SSergey Zigachev * Make the fence driver ready for processing (all asics).
371b843c749SSergey Zigachev * Not all asics have all rings, so each asic will only
372b843c749SSergey Zigachev * start the fence driver on the rings it has.
373b843c749SSergey Zigachev * Returns 0 for success, errors for failure.
374b843c749SSergey Zigachev */
amdgpu_fence_driver_start_ring(struct amdgpu_ring * ring,struct amdgpu_irq_src * irq_src,unsigned irq_type)375b843c749SSergey Zigachev int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
376b843c749SSergey Zigachev struct amdgpu_irq_src *irq_src,
377b843c749SSergey Zigachev unsigned irq_type)
378b843c749SSergey Zigachev {
379b843c749SSergey Zigachev struct amdgpu_device *adev = ring->adev;
380b843c749SSergey Zigachev uint64_t index;
381b843c749SSergey Zigachev
382b843c749SSergey Zigachev if (ring->funcs->type != AMDGPU_RING_TYPE_UVD) {
383b843c749SSergey Zigachev ring->fence_drv.cpu_addr = &adev->wb.wb[ring->fence_offs];
384b843c749SSergey Zigachev ring->fence_drv.gpu_addr = adev->wb.gpu_addr + (ring->fence_offs * 4);
385b843c749SSergey Zigachev } else {
386b843c749SSergey Zigachev /* put fence directly behind firmware */
387*78973132SSergey Zigachev index = ALIGN(adev->uvd.fw->datasize, 8);
388b843c749SSergey Zigachev ring->fence_drv.cpu_addr = adev->uvd.inst[ring->me].cpu_addr + index;
389b843c749SSergey Zigachev ring->fence_drv.gpu_addr = adev->uvd.inst[ring->me].gpu_addr + index;
390b843c749SSergey Zigachev }
391b843c749SSergey Zigachev amdgpu_fence_write(ring, atomic_read(&ring->fence_drv.last_seq));
392b843c749SSergey Zigachev
393b843c749SSergey Zigachev if (irq_src)
394b843c749SSergey Zigachev amdgpu_irq_get(adev, irq_src, irq_type);
395b843c749SSergey Zigachev
396b843c749SSergey Zigachev ring->fence_drv.irq_src = irq_src;
397b843c749SSergey Zigachev ring->fence_drv.irq_type = irq_type;
398b843c749SSergey Zigachev ring->fence_drv.initialized = true;
399b843c749SSergey Zigachev
400*78973132SSergey Zigachev dev_dbg(adev->dev, "fence driver on ring %d use gpu addr 0x%016jx, "
401b843c749SSergey Zigachev "cpu addr 0x%p\n", ring->idx,
402b843c749SSergey Zigachev ring->fence_drv.gpu_addr, ring->fence_drv.cpu_addr);
403b843c749SSergey Zigachev return 0;
404b843c749SSergey Zigachev }
405b843c749SSergey Zigachev
406b843c749SSergey Zigachev /**
407b843c749SSergey Zigachev * amdgpu_fence_driver_init_ring - init the fence driver
408b843c749SSergey Zigachev * for the requested ring.
409b843c749SSergey Zigachev *
410b843c749SSergey Zigachev * @ring: ring to init the fence driver on
411b843c749SSergey Zigachev * @num_hw_submission: number of entries on the hardware queue
412b843c749SSergey Zigachev *
413b843c749SSergey Zigachev * Init the fence driver for the requested ring (all asics).
414b843c749SSergey Zigachev * Helper function for amdgpu_fence_driver_init().
415b843c749SSergey Zigachev */
amdgpu_fence_driver_init_ring(struct amdgpu_ring * ring,unsigned num_hw_submission)416b843c749SSergey Zigachev int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
417b843c749SSergey Zigachev unsigned num_hw_submission)
418b843c749SSergey Zigachev {
419b843c749SSergey Zigachev long timeout;
420b843c749SSergey Zigachev int r;
421b843c749SSergey Zigachev
422b843c749SSergey Zigachev /* Check that num_hw_submission is a power of two */
423b843c749SSergey Zigachev if ((num_hw_submission & (num_hw_submission - 1)) != 0)
424b843c749SSergey Zigachev return -EINVAL;
425b843c749SSergey Zigachev
426b843c749SSergey Zigachev ring->fence_drv.cpu_addr = NULL;
427b843c749SSergey Zigachev ring->fence_drv.gpu_addr = 0;
428b843c749SSergey Zigachev ring->fence_drv.sync_seq = 0;
429b843c749SSergey Zigachev atomic_set(&ring->fence_drv.last_seq, 0);
430b843c749SSergey Zigachev ring->fence_drv.initialized = false;
431b843c749SSergey Zigachev
432b843c749SSergey Zigachev timer_setup(&ring->fence_drv.fallback_timer, amdgpu_fence_fallback, 0);
433b843c749SSergey Zigachev
434b843c749SSergey Zigachev ring->fence_drv.num_fences_mask = num_hw_submission * 2 - 1;
435*78973132SSergey Zigachev lockinit(&ring->fence_drv.lock, "agrfdl", 0, LK_CANRECURSE);
436b843c749SSergey Zigachev ring->fence_drv.fences = kcalloc(num_hw_submission * 2, sizeof(void *),
437b843c749SSergey Zigachev GFP_KERNEL);
438b843c749SSergey Zigachev if (!ring->fence_drv.fences)
439b843c749SSergey Zigachev return -ENOMEM;
440b843c749SSergey Zigachev
441b843c749SSergey Zigachev /* No need to setup the GPU scheduler for KIQ ring */
442b843c749SSergey Zigachev if (ring->funcs->type != AMDGPU_RING_TYPE_KIQ) {
443b843c749SSergey Zigachev /* for non-sriov case, no timeout enforce on compute ring */
444b843c749SSergey Zigachev if ((ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE)
445b843c749SSergey Zigachev && !amdgpu_sriov_vf(ring->adev))
446b843c749SSergey Zigachev timeout = MAX_SCHEDULE_TIMEOUT;
447b843c749SSergey Zigachev else
448b843c749SSergey Zigachev timeout = msecs_to_jiffies(amdgpu_lockup_timeout);
449b843c749SSergey Zigachev
450b843c749SSergey Zigachev r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
451b843c749SSergey Zigachev num_hw_submission, amdgpu_job_hang_limit,
452b843c749SSergey Zigachev timeout, ring->name);
453b843c749SSergey Zigachev if (r) {
454b843c749SSergey Zigachev DRM_ERROR("Failed to create scheduler on ring %s.\n",
455b843c749SSergey Zigachev ring->name);
456b843c749SSergey Zigachev return r;
457b843c749SSergey Zigachev }
458b843c749SSergey Zigachev }
459b843c749SSergey Zigachev
460b843c749SSergey Zigachev return 0;
461b843c749SSergey Zigachev }
462b843c749SSergey Zigachev
463b843c749SSergey Zigachev /**
464b843c749SSergey Zigachev * amdgpu_fence_driver_init - init the fence driver
465b843c749SSergey Zigachev * for all possible rings.
466b843c749SSergey Zigachev *
467b843c749SSergey Zigachev * @adev: amdgpu device pointer
468b843c749SSergey Zigachev *
469b843c749SSergey Zigachev * Init the fence driver for all possible rings (all asics).
470b843c749SSergey Zigachev * Not all asics have all rings, so each asic will only
471b843c749SSergey Zigachev * start the fence driver on the rings it has using
472b843c749SSergey Zigachev * amdgpu_fence_driver_start_ring().
473b843c749SSergey Zigachev * Returns 0 for success.
474b843c749SSergey Zigachev */
amdgpu_fence_driver_init(struct amdgpu_device * adev)475b843c749SSergey Zigachev int amdgpu_fence_driver_init(struct amdgpu_device *adev)
476b843c749SSergey Zigachev {
477b843c749SSergey Zigachev if (amdgpu_debugfs_fence_init(adev))
478b843c749SSergey Zigachev dev_err(adev->dev, "fence debugfs file creation failed\n");
479b843c749SSergey Zigachev
480b843c749SSergey Zigachev return 0;
481b843c749SSergey Zigachev }
482b843c749SSergey Zigachev
483b843c749SSergey Zigachev /**
484b843c749SSergey Zigachev * amdgpu_fence_driver_fini - tear down the fence driver
485b843c749SSergey Zigachev * for all possible rings.
486b843c749SSergey Zigachev *
487b843c749SSergey Zigachev * @adev: amdgpu device pointer
488b843c749SSergey Zigachev *
489b843c749SSergey Zigachev * Tear down the fence driver for all possible rings (all asics).
490b843c749SSergey Zigachev */
amdgpu_fence_driver_fini(struct amdgpu_device * adev)491b843c749SSergey Zigachev void amdgpu_fence_driver_fini(struct amdgpu_device *adev)
492b843c749SSergey Zigachev {
493b843c749SSergey Zigachev unsigned i, j;
494b843c749SSergey Zigachev int r;
495b843c749SSergey Zigachev
496b843c749SSergey Zigachev for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
497b843c749SSergey Zigachev struct amdgpu_ring *ring = adev->rings[i];
498b843c749SSergey Zigachev
499b843c749SSergey Zigachev if (!ring || !ring->fence_drv.initialized)
500b843c749SSergey Zigachev continue;
501b843c749SSergey Zigachev r = amdgpu_fence_wait_empty(ring);
502b843c749SSergey Zigachev if (r) {
503b843c749SSergey Zigachev /* no need to trigger GPU reset as we are unloading */
504b843c749SSergey Zigachev amdgpu_fence_driver_force_completion(ring);
505b843c749SSergey Zigachev }
506b843c749SSergey Zigachev if (ring->fence_drv.irq_src)
507b843c749SSergey Zigachev amdgpu_irq_put(adev, ring->fence_drv.irq_src,
508b843c749SSergey Zigachev ring->fence_drv.irq_type);
509b843c749SSergey Zigachev drm_sched_fini(&ring->sched);
510b843c749SSergey Zigachev del_timer_sync(&ring->fence_drv.fallback_timer);
511b843c749SSergey Zigachev for (j = 0; j <= ring->fence_drv.num_fences_mask; ++j)
512b843c749SSergey Zigachev dma_fence_put(ring->fence_drv.fences[j]);
513b843c749SSergey Zigachev kfree(ring->fence_drv.fences);
514b843c749SSergey Zigachev ring->fence_drv.fences = NULL;
515b843c749SSergey Zigachev ring->fence_drv.initialized = false;
516b843c749SSergey Zigachev }
517b843c749SSergey Zigachev }
518b843c749SSergey Zigachev
519b843c749SSergey Zigachev /**
520b843c749SSergey Zigachev * amdgpu_fence_driver_suspend - suspend the fence driver
521b843c749SSergey Zigachev * for all possible rings.
522b843c749SSergey Zigachev *
523b843c749SSergey Zigachev * @adev: amdgpu device pointer
524b843c749SSergey Zigachev *
525b843c749SSergey Zigachev * Suspend the fence driver for all possible rings (all asics).
526b843c749SSergey Zigachev */
amdgpu_fence_driver_suspend(struct amdgpu_device * adev)527b843c749SSergey Zigachev void amdgpu_fence_driver_suspend(struct amdgpu_device *adev)
528b843c749SSergey Zigachev {
529b843c749SSergey Zigachev int i, r;
530b843c749SSergey Zigachev
531b843c749SSergey Zigachev for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
532b843c749SSergey Zigachev struct amdgpu_ring *ring = adev->rings[i];
533b843c749SSergey Zigachev if (!ring || !ring->fence_drv.initialized)
534b843c749SSergey Zigachev continue;
535b843c749SSergey Zigachev
536b843c749SSergey Zigachev /* wait for gpu to finish processing current batch */
537b843c749SSergey Zigachev r = amdgpu_fence_wait_empty(ring);
538b843c749SSergey Zigachev if (r) {
539b843c749SSergey Zigachev /* delay GPU reset to resume */
540b843c749SSergey Zigachev amdgpu_fence_driver_force_completion(ring);
541b843c749SSergey Zigachev }
542b843c749SSergey Zigachev
543b843c749SSergey Zigachev /* disable the interrupt */
544b843c749SSergey Zigachev if (ring->fence_drv.irq_src)
545b843c749SSergey Zigachev amdgpu_irq_put(adev, ring->fence_drv.irq_src,
546b843c749SSergey Zigachev ring->fence_drv.irq_type);
547b843c749SSergey Zigachev }
548b843c749SSergey Zigachev }
549b843c749SSergey Zigachev
550b843c749SSergey Zigachev /**
551b843c749SSergey Zigachev * amdgpu_fence_driver_resume - resume the fence driver
552b843c749SSergey Zigachev * for all possible rings.
553b843c749SSergey Zigachev *
554b843c749SSergey Zigachev * @adev: amdgpu device pointer
555b843c749SSergey Zigachev *
556b843c749SSergey Zigachev * Resume the fence driver for all possible rings (all asics).
557b843c749SSergey Zigachev * Not all asics have all rings, so each asic will only
558b843c749SSergey Zigachev * start the fence driver on the rings it has using
559b843c749SSergey Zigachev * amdgpu_fence_driver_start_ring().
560b843c749SSergey Zigachev * Returns 0 for success.
561b843c749SSergey Zigachev */
amdgpu_fence_driver_resume(struct amdgpu_device * adev)562b843c749SSergey Zigachev void amdgpu_fence_driver_resume(struct amdgpu_device *adev)
563b843c749SSergey Zigachev {
564b843c749SSergey Zigachev int i;
565b843c749SSergey Zigachev
566b843c749SSergey Zigachev for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
567b843c749SSergey Zigachev struct amdgpu_ring *ring = adev->rings[i];
568b843c749SSergey Zigachev if (!ring || !ring->fence_drv.initialized)
569b843c749SSergey Zigachev continue;
570b843c749SSergey Zigachev
571b843c749SSergey Zigachev /* enable the interrupt */
572b843c749SSergey Zigachev if (ring->fence_drv.irq_src)
573b843c749SSergey Zigachev amdgpu_irq_get(adev, ring->fence_drv.irq_src,
574b843c749SSergey Zigachev ring->fence_drv.irq_type);
575b843c749SSergey Zigachev }
576b843c749SSergey Zigachev }
577b843c749SSergey Zigachev
578b843c749SSergey Zigachev /**
579b843c749SSergey Zigachev * amdgpu_fence_driver_force_completion - force signal latest fence of ring
580b843c749SSergey Zigachev *
581b843c749SSergey Zigachev * @ring: fence of the ring to signal
582b843c749SSergey Zigachev *
583b843c749SSergey Zigachev */
amdgpu_fence_driver_force_completion(struct amdgpu_ring * ring)584b843c749SSergey Zigachev void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring)
585b843c749SSergey Zigachev {
586b843c749SSergey Zigachev amdgpu_fence_write(ring, ring->fence_drv.sync_seq);
587b843c749SSergey Zigachev amdgpu_fence_process(ring);
588b843c749SSergey Zigachev }
589b843c749SSergey Zigachev
590b843c749SSergey Zigachev /*
591b843c749SSergey Zigachev * Common fence implementation
592b843c749SSergey Zigachev */
593b843c749SSergey Zigachev
amdgpu_fence_get_driver_name(struct dma_fence * fence)594b843c749SSergey Zigachev static const char *amdgpu_fence_get_driver_name(struct dma_fence *fence)
595b843c749SSergey Zigachev {
596b843c749SSergey Zigachev return "amdgpu";
597b843c749SSergey Zigachev }
598b843c749SSergey Zigachev
amdgpu_fence_get_timeline_name(struct dma_fence * f)599b843c749SSergey Zigachev static const char *amdgpu_fence_get_timeline_name(struct dma_fence *f)
600b843c749SSergey Zigachev {
601b843c749SSergey Zigachev struct amdgpu_fence *fence = to_amdgpu_fence(f);
602b843c749SSergey Zigachev return (const char *)fence->ring->name;
603b843c749SSergey Zigachev }
604b843c749SSergey Zigachev
605b843c749SSergey Zigachev /**
606b843c749SSergey Zigachev * amdgpu_fence_enable_signaling - enable signalling on fence
607b843c749SSergey Zigachev * @fence: fence
608b843c749SSergey Zigachev *
609b843c749SSergey Zigachev * This function is called with fence_queue lock held, and adds a callback
610b843c749SSergey Zigachev * to fence_queue that checks if this fence is signaled, and if so it
611b843c749SSergey Zigachev * signals the fence and removes itself.
612b843c749SSergey Zigachev */
amdgpu_fence_enable_signaling(struct dma_fence * f)613b843c749SSergey Zigachev static bool amdgpu_fence_enable_signaling(struct dma_fence *f)
614b843c749SSergey Zigachev {
615b843c749SSergey Zigachev struct amdgpu_fence *fence = to_amdgpu_fence(f);
616b843c749SSergey Zigachev struct amdgpu_ring *ring = fence->ring;
617b843c749SSergey Zigachev
618b843c749SSergey Zigachev if (!timer_pending(&ring->fence_drv.fallback_timer))
619b843c749SSergey Zigachev amdgpu_fence_schedule_fallback(ring);
620b843c749SSergey Zigachev
621b843c749SSergey Zigachev DMA_FENCE_TRACE(&fence->base, "armed on ring %i!\n", ring->idx);
622b843c749SSergey Zigachev
623b843c749SSergey Zigachev return true;
624b843c749SSergey Zigachev }
625b843c749SSergey Zigachev
626b843c749SSergey Zigachev /**
627b843c749SSergey Zigachev * amdgpu_fence_free - free up the fence memory
628b843c749SSergey Zigachev *
629b843c749SSergey Zigachev * @rcu: RCU callback head
630b843c749SSergey Zigachev *
631b843c749SSergey Zigachev * Free up the fence memory after the RCU grace period.
632b843c749SSergey Zigachev */
amdgpu_fence_free(struct rcu_head * rcu)633b843c749SSergey Zigachev static void amdgpu_fence_free(struct rcu_head *rcu)
634b843c749SSergey Zigachev {
635b843c749SSergey Zigachev struct dma_fence *f = container_of(rcu, struct dma_fence, rcu);
636b843c749SSergey Zigachev struct amdgpu_fence *fence = to_amdgpu_fence(f);
637b843c749SSergey Zigachev kmem_cache_free(amdgpu_fence_slab, fence);
638b843c749SSergey Zigachev }
639b843c749SSergey Zigachev
640b843c749SSergey Zigachev /**
641b843c749SSergey Zigachev * amdgpu_fence_release - callback that fence can be freed
642b843c749SSergey Zigachev *
643b843c749SSergey Zigachev * @fence: fence
644b843c749SSergey Zigachev *
645b843c749SSergey Zigachev * This function is called when the reference count becomes zero.
646b843c749SSergey Zigachev * It just RCU schedules freeing up the fence.
647b843c749SSergey Zigachev */
amdgpu_fence_release(struct dma_fence * f)648b843c749SSergey Zigachev static void amdgpu_fence_release(struct dma_fence *f)
649b843c749SSergey Zigachev {
650b843c749SSergey Zigachev call_rcu(&f->rcu, amdgpu_fence_free);
651b843c749SSergey Zigachev }
652b843c749SSergey Zigachev
653b843c749SSergey Zigachev static const struct dma_fence_ops amdgpu_fence_ops = {
654b843c749SSergey Zigachev .get_driver_name = amdgpu_fence_get_driver_name,
655b843c749SSergey Zigachev .get_timeline_name = amdgpu_fence_get_timeline_name,
656b843c749SSergey Zigachev .enable_signaling = amdgpu_fence_enable_signaling,
657b843c749SSergey Zigachev .release = amdgpu_fence_release,
658b843c749SSergey Zigachev };
659b843c749SSergey Zigachev
660b843c749SSergey Zigachev /*
661b843c749SSergey Zigachev * Fence debugfs
662b843c749SSergey Zigachev */
663b843c749SSergey Zigachev #if defined(CONFIG_DEBUG_FS)
amdgpu_debugfs_fence_info(struct seq_file * m,void * data)664b843c749SSergey Zigachev static int amdgpu_debugfs_fence_info(struct seq_file *m, void *data)
665b843c749SSergey Zigachev {
666b843c749SSergey Zigachev struct drm_info_node *node = (struct drm_info_node *)m->private;
667b843c749SSergey Zigachev struct drm_device *dev = node->minor->dev;
668b843c749SSergey Zigachev struct amdgpu_device *adev = dev->dev_private;
669b843c749SSergey Zigachev int i;
670b843c749SSergey Zigachev
671b843c749SSergey Zigachev for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
672b843c749SSergey Zigachev struct amdgpu_ring *ring = adev->rings[i];
673b843c749SSergey Zigachev if (!ring || !ring->fence_drv.initialized)
674b843c749SSergey Zigachev continue;
675b843c749SSergey Zigachev
676b843c749SSergey Zigachev amdgpu_fence_process(ring);
677b843c749SSergey Zigachev
678b843c749SSergey Zigachev seq_printf(m, "--- ring %d (%s) ---\n", i, ring->name);
679b843c749SSergey Zigachev seq_printf(m, "Last signaled fence 0x%08x\n",
680b843c749SSergey Zigachev atomic_read(&ring->fence_drv.last_seq));
681b843c749SSergey Zigachev seq_printf(m, "Last emitted 0x%08x\n",
682b843c749SSergey Zigachev ring->fence_drv.sync_seq);
683b843c749SSergey Zigachev
684b843c749SSergey Zigachev if (ring->funcs->type != AMDGPU_RING_TYPE_GFX)
685b843c749SSergey Zigachev continue;
686b843c749SSergey Zigachev
687b843c749SSergey Zigachev /* set in CP_VMID_PREEMPT and preemption occurred */
688b843c749SSergey Zigachev seq_printf(m, "Last preempted 0x%08x\n",
689b843c749SSergey Zigachev le32_to_cpu(*(ring->fence_drv.cpu_addr + 2)));
690b843c749SSergey Zigachev /* set in CP_VMID_RESET and reset occurred */
691b843c749SSergey Zigachev seq_printf(m, "Last reset 0x%08x\n",
692b843c749SSergey Zigachev le32_to_cpu(*(ring->fence_drv.cpu_addr + 4)));
693b843c749SSergey Zigachev /* Both preemption and reset occurred */
694b843c749SSergey Zigachev seq_printf(m, "Last both 0x%08x\n",
695b843c749SSergey Zigachev le32_to_cpu(*(ring->fence_drv.cpu_addr + 6)));
696b843c749SSergey Zigachev }
697b843c749SSergey Zigachev return 0;
698b843c749SSergey Zigachev }
699b843c749SSergey Zigachev
700b843c749SSergey Zigachev /**
701b843c749SSergey Zigachev * amdgpu_debugfs_gpu_recover - manually trigger a gpu reset & recover
702b843c749SSergey Zigachev *
703b843c749SSergey Zigachev * Manually trigger a gpu reset at the next fence wait.
704b843c749SSergey Zigachev */
amdgpu_debugfs_gpu_recover(struct seq_file * m,void * data)705b843c749SSergey Zigachev static int amdgpu_debugfs_gpu_recover(struct seq_file *m, void *data)
706b843c749SSergey Zigachev {
707b843c749SSergey Zigachev struct drm_info_node *node = (struct drm_info_node *) m->private;
708b843c749SSergey Zigachev struct drm_device *dev = node->minor->dev;
709b843c749SSergey Zigachev struct amdgpu_device *adev = dev->dev_private;
710b843c749SSergey Zigachev
711b843c749SSergey Zigachev seq_printf(m, "gpu recover\n");
712b843c749SSergey Zigachev amdgpu_device_gpu_recover(adev, NULL, true);
713b843c749SSergey Zigachev
714b843c749SSergey Zigachev return 0;
715b843c749SSergey Zigachev }
716b843c749SSergey Zigachev
717b843c749SSergey Zigachev static const struct drm_info_list amdgpu_debugfs_fence_list[] = {
718b843c749SSergey Zigachev {"amdgpu_fence_info", &amdgpu_debugfs_fence_info, 0, NULL},
719b843c749SSergey Zigachev {"amdgpu_gpu_recover", &amdgpu_debugfs_gpu_recover, 0, NULL}
720b843c749SSergey Zigachev };
721b843c749SSergey Zigachev
722b843c749SSergey Zigachev static const struct drm_info_list amdgpu_debugfs_fence_list_sriov[] = {
723b843c749SSergey Zigachev {"amdgpu_fence_info", &amdgpu_debugfs_fence_info, 0, NULL},
724b843c749SSergey Zigachev };
725b843c749SSergey Zigachev #endif
726b843c749SSergey Zigachev
amdgpu_debugfs_fence_init(struct amdgpu_device * adev)727b843c749SSergey Zigachev int amdgpu_debugfs_fence_init(struct amdgpu_device *adev)
728b843c749SSergey Zigachev {
729b843c749SSergey Zigachev #if defined(CONFIG_DEBUG_FS)
730b843c749SSergey Zigachev if (amdgpu_sriov_vf(adev))
731b843c749SSergey Zigachev return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_fence_list_sriov, 1);
732b843c749SSergey Zigachev return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_fence_list, 2);
733b843c749SSergey Zigachev #else
734b843c749SSergey Zigachev return 0;
735b843c749SSergey Zigachev #endif
736b843c749SSergey Zigachev }
737b843c749SSergey Zigachev
738