amdgpu_fence.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. /*
  2. * Copyright 2009 Jerome Glisse.
  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. */
  26. /*
  27. * Authors:
  28. * Jerome Glisse <glisse@freedesktop.org>
  29. * Dave Airlie
  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 "amdgpu.h"
  39. #include "amdgpu_trace.h"
  40. /*
  41. * Fences
  42. * Fences mark an event in the GPUs pipeline and are used
  43. * for GPU/CPU synchronization. When the fence is written,
  44. * it is expected that all buffers associated with that fence
  45. * are no longer in use by the associated ring on the GPU and
  46. * that the the relevant GPU caches have been flushed.
  47. */
  48. struct amdgpu_fence {
  49. struct dma_fence base;
  50. /* RB, DMA, etc. */
  51. struct amdgpu_ring *ring;
  52. };
  53. static struct kmem_cache *amdgpu_fence_slab;
  54. int amdgpu_fence_slab_init(void)
  55. {
  56. amdgpu_fence_slab = kmem_cache_create(
  57. "amdgpu_fence", sizeof(struct amdgpu_fence), 0,
  58. SLAB_HWCACHE_ALIGN, NULL);
  59. if (!amdgpu_fence_slab)
  60. return -ENOMEM;
  61. return 0;
  62. }
  63. void amdgpu_fence_slab_fini(void)
  64. {
  65. rcu_barrier();
  66. kmem_cache_destroy(amdgpu_fence_slab);
  67. }
  68. /*
  69. * Cast helper
  70. */
  71. static const struct dma_fence_ops amdgpu_fence_ops;
  72. static inline struct amdgpu_fence *to_amdgpu_fence(struct dma_fence *f)
  73. {
  74. struct amdgpu_fence *__f = container_of(f, struct amdgpu_fence, base);
  75. if (__f->base.ops == &amdgpu_fence_ops)
  76. return __f;
  77. return NULL;
  78. }
  79. /**
  80. * amdgpu_fence_write - write a fence value
  81. *
  82. * @ring: ring the fence is associated with
  83. * @seq: sequence number to write
  84. *
  85. * Writes a fence value to memory (all asics).
  86. */
  87. static void amdgpu_fence_write(struct amdgpu_ring *ring, u32 seq)
  88. {
  89. struct amdgpu_fence_driver *drv = &ring->fence_drv;
  90. if (drv->cpu_addr)
  91. *drv->cpu_addr = cpu_to_le32(seq);
  92. }
  93. /**
  94. * amdgpu_fence_read - read a fence value
  95. *
  96. * @ring: ring the fence is associated with
  97. *
  98. * Reads a fence value from memory (all asics).
  99. * Returns the value of the fence read from memory.
  100. */
  101. static u32 amdgpu_fence_read(struct amdgpu_ring *ring)
  102. {
  103. struct amdgpu_fence_driver *drv = &ring->fence_drv;
  104. u32 seq = 0;
  105. if (drv->cpu_addr)
  106. seq = le32_to_cpu(*drv->cpu_addr);
  107. else
  108. seq = atomic_read(&drv->last_seq);
  109. return seq;
  110. }
  111. /**
  112. * amdgpu_fence_emit - emit a fence on the requested ring
  113. *
  114. * @ring: ring the fence is associated with
  115. * @f: resulting fence object
  116. *
  117. * Emits a fence command on the requested ring (all asics).
  118. * Returns 0 on success, -ENOMEM on failure.
  119. */
  120. int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **f,
  121. unsigned flags)
  122. {
  123. struct amdgpu_device *adev = ring->adev;
  124. struct amdgpu_fence *fence;
  125. struct dma_fence *old, **ptr;
  126. uint32_t seq;
  127. fence = kmem_cache_alloc(amdgpu_fence_slab, GFP_KERNEL);
  128. if (fence == NULL)
  129. return -ENOMEM;
  130. seq = ++ring->fence_drv.sync_seq;
  131. fence->ring = ring;
  132. dma_fence_init(&fence->base, &amdgpu_fence_ops,
  133. &ring->fence_drv.lock,
  134. adev->fence_context + ring->idx,
  135. seq);
  136. amdgpu_ring_emit_fence(ring, ring->fence_drv.gpu_addr,
  137. seq, flags | AMDGPU_FENCE_FLAG_INT);
  138. ptr = &ring->fence_drv.fences[seq & ring->fence_drv.num_fences_mask];
  139. /* This function can't be called concurrently anyway, otherwise
  140. * emitting the fence would mess up the hardware ring buffer.
  141. */
  142. old = rcu_dereference_protected(*ptr, 1);
  143. if (old && !dma_fence_is_signaled(old)) {
  144. DRM_INFO("rcu slot is busy\n");
  145. dma_fence_wait(old, false);
  146. }
  147. rcu_assign_pointer(*ptr, dma_fence_get(&fence->base));
  148. *f = &fence->base;
  149. return 0;
  150. }
  151. /**
  152. * amdgpu_fence_emit_polling - emit a fence on the requeste ring
  153. *
  154. * @ring: ring the fence is associated with
  155. * @s: resulting sequence number
  156. *
  157. * Emits a fence command on the requested ring (all asics).
  158. * Used For polling fence.
  159. * Returns 0 on success, -ENOMEM on failure.
  160. */
  161. int amdgpu_fence_emit_polling(struct amdgpu_ring *ring, uint32_t *s)
  162. {
  163. uint32_t seq;
  164. if (!s)
  165. return -EINVAL;
  166. seq = ++ring->fence_drv.sync_seq;
  167. amdgpu_ring_emit_fence(ring, ring->fence_drv.gpu_addr,
  168. seq, 0);
  169. *s = seq;
  170. return 0;
  171. }
  172. /**
  173. * amdgpu_fence_process - check for fence activity
  174. *
  175. * @ring: pointer to struct amdgpu_ring
  176. *
  177. * Checks the current fence value and calculates the last
  178. * signalled fence value. Wakes the fence queue if the
  179. * sequence number has increased.
  180. */
  181. void amdgpu_fence_process(struct amdgpu_ring *ring)
  182. {
  183. struct amdgpu_fence_driver *drv = &ring->fence_drv;
  184. uint32_t seq, last_seq;
  185. int r;
  186. do {
  187. last_seq = atomic_read(&ring->fence_drv.last_seq);
  188. seq = amdgpu_fence_read(ring);
  189. } while (atomic_cmpxchg(&drv->last_seq, last_seq, seq) != last_seq);
  190. if (unlikely(seq == last_seq))
  191. return;
  192. last_seq &= drv->num_fences_mask;
  193. seq &= drv->num_fences_mask;
  194. do {
  195. struct dma_fence *fence, **ptr;
  196. ++last_seq;
  197. last_seq &= drv->num_fences_mask;
  198. ptr = &drv->fences[last_seq];
  199. /* There is always exactly one thread signaling this fence slot */
  200. fence = rcu_dereference_protected(*ptr, 1);
  201. RCU_INIT_POINTER(*ptr, NULL);
  202. if (!fence)
  203. continue;
  204. r = dma_fence_signal(fence);
  205. if (!r)
  206. DMA_FENCE_TRACE(fence, "signaled from irq context\n");
  207. else
  208. BUG();
  209. dma_fence_put(fence);
  210. } while (last_seq != seq);
  211. }
  212. /**
  213. * amdgpu_fence_wait_empty - wait for all fences to signal
  214. *
  215. * @adev: amdgpu device pointer
  216. * @ring: ring index the fence is associated with
  217. *
  218. * Wait for all fences on the requested ring to signal (all asics).
  219. * Returns 0 if the fences have passed, error for all other cases.
  220. */
  221. int amdgpu_fence_wait_empty(struct amdgpu_ring *ring)
  222. {
  223. uint64_t seq = READ_ONCE(ring->fence_drv.sync_seq);
  224. struct dma_fence *fence, **ptr;
  225. int r;
  226. if (!seq)
  227. return 0;
  228. ptr = &ring->fence_drv.fences[seq & ring->fence_drv.num_fences_mask];
  229. rcu_read_lock();
  230. fence = rcu_dereference(*ptr);
  231. if (!fence || !dma_fence_get_rcu(fence)) {
  232. rcu_read_unlock();
  233. return 0;
  234. }
  235. rcu_read_unlock();
  236. r = dma_fence_wait(fence, false);
  237. dma_fence_put(fence);
  238. return r;
  239. }
  240. /**
  241. * amdgpu_fence_wait_polling - busy wait for givn sequence number
  242. *
  243. * @ring: ring index the fence is associated with
  244. * @wait_seq: sequence number to wait
  245. * @timeout: the timeout for waiting in usecs
  246. *
  247. * Wait for all fences on the requested ring to signal (all asics).
  248. * Returns left time if no timeout, 0 or minus if timeout.
  249. */
  250. signed long amdgpu_fence_wait_polling(struct amdgpu_ring *ring,
  251. uint32_t wait_seq,
  252. signed long timeout)
  253. {
  254. uint32_t seq;
  255. do {
  256. seq = amdgpu_fence_read(ring);
  257. udelay(5);
  258. timeout -= 5;
  259. } while ((int32_t)(wait_seq - seq) > 0 && timeout > 0);
  260. return timeout > 0 ? timeout : 0;
  261. }
  262. /**
  263. * amdgpu_fence_count_emitted - get the count of emitted fences
  264. *
  265. * @ring: ring the fence is associated with
  266. *
  267. * Get the number of fences emitted on the requested ring (all asics).
  268. * Returns the number of emitted fences on the ring. Used by the
  269. * dynpm code to ring track activity.
  270. */
  271. unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring)
  272. {
  273. uint64_t emitted;
  274. /* We are not protected by ring lock when reading the last sequence
  275. * but it's ok to report slightly wrong fence count here.
  276. */
  277. amdgpu_fence_process(ring);
  278. emitted = 0x100000000ull;
  279. emitted -= atomic_read(&ring->fence_drv.last_seq);
  280. emitted += READ_ONCE(ring->fence_drv.sync_seq);
  281. return lower_32_bits(emitted);
  282. }
  283. /**
  284. * amdgpu_fence_driver_start_ring - make the fence driver
  285. * ready for use on the requested ring.
  286. *
  287. * @ring: ring to start the fence driver on
  288. * @irq_src: interrupt source to use for this ring
  289. * @irq_type: interrupt type to use for this ring
  290. *
  291. * Make the fence driver ready for processing (all asics).
  292. * Not all asics have all rings, so each asic will only
  293. * start the fence driver on the rings it has.
  294. * Returns 0 for success, errors for failure.
  295. */
  296. int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
  297. struct amdgpu_irq_src *irq_src,
  298. unsigned irq_type)
  299. {
  300. struct amdgpu_device *adev = ring->adev;
  301. uint64_t index;
  302. if (ring->funcs->type != AMDGPU_RING_TYPE_UVD) {
  303. ring->fence_drv.cpu_addr = &adev->wb.wb[ring->fence_offs];
  304. ring->fence_drv.gpu_addr = adev->wb.gpu_addr + (ring->fence_offs * 4);
  305. } else {
  306. /* put fence directly behind firmware */
  307. index = ALIGN(adev->uvd.fw->size, 8);
  308. ring->fence_drv.cpu_addr = adev->uvd.inst[ring->me].cpu_addr + index;
  309. ring->fence_drv.gpu_addr = adev->uvd.inst[ring->me].gpu_addr + index;
  310. }
  311. amdgpu_fence_write(ring, atomic_read(&ring->fence_drv.last_seq));
  312. amdgpu_irq_get(adev, irq_src, irq_type);
  313. ring->fence_drv.irq_src = irq_src;
  314. ring->fence_drv.irq_type = irq_type;
  315. ring->fence_drv.initialized = true;
  316. dev_dbg(adev->dev, "fence driver on ring %d use gpu addr 0x%016llx, "
  317. "cpu addr 0x%p\n", ring->idx,
  318. ring->fence_drv.gpu_addr, ring->fence_drv.cpu_addr);
  319. return 0;
  320. }
  321. /**
  322. * amdgpu_fence_driver_init_ring - init the fence driver
  323. * for the requested ring.
  324. *
  325. * @ring: ring to init the fence driver on
  326. * @num_hw_submission: number of entries on the hardware queue
  327. *
  328. * Init the fence driver for the requested ring (all asics).
  329. * Helper function for amdgpu_fence_driver_init().
  330. */
  331. int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
  332. unsigned num_hw_submission)
  333. {
  334. long timeout;
  335. int r;
  336. /* Check that num_hw_submission is a power of two */
  337. if ((num_hw_submission & (num_hw_submission - 1)) != 0)
  338. return -EINVAL;
  339. ring->fence_drv.cpu_addr = NULL;
  340. ring->fence_drv.gpu_addr = 0;
  341. ring->fence_drv.sync_seq = 0;
  342. atomic_set(&ring->fence_drv.last_seq, 0);
  343. ring->fence_drv.initialized = false;
  344. ring->fence_drv.num_fences_mask = num_hw_submission * 2 - 1;
  345. spin_lock_init(&ring->fence_drv.lock);
  346. ring->fence_drv.fences = kcalloc(num_hw_submission * 2, sizeof(void *),
  347. GFP_KERNEL);
  348. if (!ring->fence_drv.fences)
  349. return -ENOMEM;
  350. /* No need to setup the GPU scheduler for KIQ ring */
  351. if (ring->funcs->type != AMDGPU_RING_TYPE_KIQ) {
  352. /* for non-sriov case, no timeout enforce on compute ring */
  353. if ((ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE)
  354. && !amdgpu_sriov_vf(ring->adev))
  355. timeout = MAX_SCHEDULE_TIMEOUT;
  356. else
  357. timeout = msecs_to_jiffies(amdgpu_lockup_timeout);
  358. r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
  359. num_hw_submission, amdgpu_job_hang_limit,
  360. timeout, ring->name);
  361. if (r) {
  362. DRM_ERROR("Failed to create scheduler on ring %s.\n",
  363. ring->name);
  364. return r;
  365. }
  366. }
  367. return 0;
  368. }
  369. /**
  370. * amdgpu_fence_driver_init - init the fence driver
  371. * for all possible rings.
  372. *
  373. * @adev: amdgpu device pointer
  374. *
  375. * Init the fence driver for all possible rings (all asics).
  376. * Not all asics have all rings, so each asic will only
  377. * start the fence driver on the rings it has using
  378. * amdgpu_fence_driver_start_ring().
  379. * Returns 0 for success.
  380. */
  381. int amdgpu_fence_driver_init(struct amdgpu_device *adev)
  382. {
  383. if (amdgpu_debugfs_fence_init(adev))
  384. dev_err(adev->dev, "fence debugfs file creation failed\n");
  385. return 0;
  386. }
  387. /**
  388. * amdgpu_fence_driver_fini - tear down the fence driver
  389. * for all possible rings.
  390. *
  391. * @adev: amdgpu device pointer
  392. *
  393. * Tear down the fence driver for all possible rings (all asics).
  394. */
  395. void amdgpu_fence_driver_fini(struct amdgpu_device *adev)
  396. {
  397. unsigned i, j;
  398. int r;
  399. for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
  400. struct amdgpu_ring *ring = adev->rings[i];
  401. if (!ring || !ring->fence_drv.initialized)
  402. continue;
  403. r = amdgpu_fence_wait_empty(ring);
  404. if (r) {
  405. /* no need to trigger GPU reset as we are unloading */
  406. amdgpu_fence_driver_force_completion(ring);
  407. }
  408. amdgpu_irq_put(adev, ring->fence_drv.irq_src,
  409. ring->fence_drv.irq_type);
  410. drm_sched_fini(&ring->sched);
  411. for (j = 0; j <= ring->fence_drv.num_fences_mask; ++j)
  412. dma_fence_put(ring->fence_drv.fences[j]);
  413. kfree(ring->fence_drv.fences);
  414. ring->fence_drv.fences = NULL;
  415. ring->fence_drv.initialized = false;
  416. }
  417. }
  418. /**
  419. * amdgpu_fence_driver_suspend - suspend the fence driver
  420. * for all possible rings.
  421. *
  422. * @adev: amdgpu device pointer
  423. *
  424. * Suspend the fence driver for all possible rings (all asics).
  425. */
  426. void amdgpu_fence_driver_suspend(struct amdgpu_device *adev)
  427. {
  428. int i, r;
  429. for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
  430. struct amdgpu_ring *ring = adev->rings[i];
  431. if (!ring || !ring->fence_drv.initialized)
  432. continue;
  433. /* wait for gpu to finish processing current batch */
  434. r = amdgpu_fence_wait_empty(ring);
  435. if (r) {
  436. /* delay GPU reset to resume */
  437. amdgpu_fence_driver_force_completion(ring);
  438. }
  439. /* disable the interrupt */
  440. amdgpu_irq_put(adev, ring->fence_drv.irq_src,
  441. ring->fence_drv.irq_type);
  442. }
  443. }
  444. /**
  445. * amdgpu_fence_driver_resume - resume the fence driver
  446. * for all possible rings.
  447. *
  448. * @adev: amdgpu device pointer
  449. *
  450. * Resume the fence driver for all possible rings (all asics).
  451. * Not all asics have all rings, so each asic will only
  452. * start the fence driver on the rings it has using
  453. * amdgpu_fence_driver_start_ring().
  454. * Returns 0 for success.
  455. */
  456. void amdgpu_fence_driver_resume(struct amdgpu_device *adev)
  457. {
  458. int i;
  459. for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
  460. struct amdgpu_ring *ring = adev->rings[i];
  461. if (!ring || !ring->fence_drv.initialized)
  462. continue;
  463. /* enable the interrupt */
  464. amdgpu_irq_get(adev, ring->fence_drv.irq_src,
  465. ring->fence_drv.irq_type);
  466. }
  467. }
  468. /**
  469. * amdgpu_fence_driver_force_completion - force signal latest fence of ring
  470. *
  471. * @ring: fence of the ring to signal
  472. *
  473. */
  474. void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring)
  475. {
  476. amdgpu_fence_write(ring, ring->fence_drv.sync_seq);
  477. amdgpu_fence_process(ring);
  478. }
  479. /*
  480. * Common fence implementation
  481. */
  482. static const char *amdgpu_fence_get_driver_name(struct dma_fence *fence)
  483. {
  484. return "amdgpu";
  485. }
  486. static const char *amdgpu_fence_get_timeline_name(struct dma_fence *f)
  487. {
  488. struct amdgpu_fence *fence = to_amdgpu_fence(f);
  489. return (const char *)fence->ring->name;
  490. }
  491. /**
  492. * amdgpu_fence_free - free up the fence memory
  493. *
  494. * @rcu: RCU callback head
  495. *
  496. * Free up the fence memory after the RCU grace period.
  497. */
  498. static void amdgpu_fence_free(struct rcu_head *rcu)
  499. {
  500. struct dma_fence *f = container_of(rcu, struct dma_fence, rcu);
  501. struct amdgpu_fence *fence = to_amdgpu_fence(f);
  502. kmem_cache_free(amdgpu_fence_slab, fence);
  503. }
  504. /**
  505. * amdgpu_fence_release - callback that fence can be freed
  506. *
  507. * @fence: fence
  508. *
  509. * This function is called when the reference count becomes zero.
  510. * It just RCU schedules freeing up the fence.
  511. */
  512. static void amdgpu_fence_release(struct dma_fence *f)
  513. {
  514. call_rcu(&f->rcu, amdgpu_fence_free);
  515. }
  516. static const struct dma_fence_ops amdgpu_fence_ops = {
  517. .get_driver_name = amdgpu_fence_get_driver_name,
  518. .get_timeline_name = amdgpu_fence_get_timeline_name,
  519. .release = amdgpu_fence_release,
  520. };
  521. /*
  522. * Fence debugfs
  523. */
  524. #if defined(CONFIG_DEBUG_FS)
  525. static int amdgpu_debugfs_fence_info(struct seq_file *m, void *data)
  526. {
  527. struct drm_info_node *node = (struct drm_info_node *)m->private;
  528. struct drm_device *dev = node->minor->dev;
  529. struct amdgpu_device *adev = dev->dev_private;
  530. int i;
  531. for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
  532. struct amdgpu_ring *ring = adev->rings[i];
  533. if (!ring || !ring->fence_drv.initialized)
  534. continue;
  535. amdgpu_fence_process(ring);
  536. seq_printf(m, "--- ring %d (%s) ---\n", i, ring->name);
  537. seq_printf(m, "Last signaled fence 0x%08x\n",
  538. atomic_read(&ring->fence_drv.last_seq));
  539. seq_printf(m, "Last emitted 0x%08x\n",
  540. ring->fence_drv.sync_seq);
  541. if (ring->funcs->type != AMDGPU_RING_TYPE_GFX)
  542. continue;
  543. /* set in CP_VMID_PREEMPT and preemption occurred */
  544. seq_printf(m, "Last preempted 0x%08x\n",
  545. le32_to_cpu(*(ring->fence_drv.cpu_addr + 2)));
  546. /* set in CP_VMID_RESET and reset occurred */
  547. seq_printf(m, "Last reset 0x%08x\n",
  548. le32_to_cpu(*(ring->fence_drv.cpu_addr + 4)));
  549. /* Both preemption and reset occurred */
  550. seq_printf(m, "Last both 0x%08x\n",
  551. le32_to_cpu(*(ring->fence_drv.cpu_addr + 6)));
  552. }
  553. return 0;
  554. }
  555. /**
  556. * amdgpu_debugfs_gpu_recover - manually trigger a gpu reset & recover
  557. *
  558. * Manually trigger a gpu reset at the next fence wait.
  559. */
  560. static int amdgpu_debugfs_gpu_recover(struct seq_file *m, void *data)
  561. {
  562. struct drm_info_node *node = (struct drm_info_node *) m->private;
  563. struct drm_device *dev = node->minor->dev;
  564. struct amdgpu_device *adev = dev->dev_private;
  565. seq_printf(m, "gpu recover\n");
  566. amdgpu_device_gpu_recover(adev, NULL);
  567. return 0;
  568. }
  569. static const struct drm_info_list amdgpu_debugfs_fence_list[] = {
  570. {"amdgpu_fence_info", &amdgpu_debugfs_fence_info, 0, NULL},
  571. {"amdgpu_gpu_recover", &amdgpu_debugfs_gpu_recover, 0, NULL}
  572. };
  573. static const struct drm_info_list amdgpu_debugfs_fence_list_sriov[] = {
  574. {"amdgpu_fence_info", &amdgpu_debugfs_fence_info, 0, NULL},
  575. };
  576. #endif
  577. int amdgpu_debugfs_fence_init(struct amdgpu_device *adev)
  578. {
  579. #if defined(CONFIG_DEBUG_FS)
  580. if (amdgpu_sriov_vf(adev))
  581. return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_fence_list_sriov, 1);
  582. return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_fence_list, 2);
  583. #else
  584. return 0;
  585. #endif
  586. }