amdgpu_fence.c 18 KB

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