amdgpu_fence.c 17 KB

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