radeon_fence.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  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/list.h>
  35. #include <linux/kref.h>
  36. #include <linux/slab.h>
  37. #include "drmP.h"
  38. #include "drm.h"
  39. #include "radeon_reg.h"
  40. #include "radeon.h"
  41. #include "radeon_trace.h"
  42. static void radeon_fence_write(struct radeon_device *rdev, u32 seq, int ring)
  43. {
  44. struct radeon_fence_driver *drv = &rdev->fence_drv[ring];
  45. if (likely(rdev->wb.enabled || !drv->scratch_reg)) {
  46. *drv->cpu_addr = cpu_to_le32(seq);
  47. } else {
  48. WREG32(drv->scratch_reg, seq);
  49. }
  50. }
  51. static u32 radeon_fence_read(struct radeon_device *rdev, int ring)
  52. {
  53. struct radeon_fence_driver *drv = &rdev->fence_drv[ring];
  54. u32 seq = 0;
  55. if (likely(rdev->wb.enabled || !drv->scratch_reg)) {
  56. seq = le32_to_cpu(*drv->cpu_addr);
  57. } else {
  58. seq = RREG32(drv->scratch_reg);
  59. }
  60. return seq;
  61. }
  62. int radeon_fence_emit(struct radeon_device *rdev,
  63. struct radeon_fence **fence,
  64. int ring)
  65. {
  66. /* we are protected by the ring emission mutex */
  67. *fence = kmalloc(sizeof(struct radeon_fence), GFP_KERNEL);
  68. if ((*fence) == NULL) {
  69. return -ENOMEM;
  70. }
  71. kref_init(&((*fence)->kref));
  72. (*fence)->rdev = rdev;
  73. (*fence)->seq = ++rdev->fence_drv[ring].sync_seq[ring];
  74. (*fence)->ring = ring;
  75. radeon_fence_ring_emit(rdev, ring, *fence);
  76. trace_radeon_fence_emit(rdev->ddev, (*fence)->seq);
  77. return 0;
  78. }
  79. void radeon_fence_process(struct radeon_device *rdev, int ring)
  80. {
  81. uint64_t seq, last_seq;
  82. unsigned count_loop = 0;
  83. bool wake = false;
  84. /* Note there is a scenario here for an infinite loop but it's
  85. * very unlikely to happen. For it to happen, the current polling
  86. * process need to be interrupted by another process and another
  87. * process needs to update the last_seq btw the atomic read and
  88. * xchg of the current process.
  89. *
  90. * More over for this to go in infinite loop there need to be
  91. * continuously new fence signaled ie radeon_fence_read needs
  92. * to return a different value each time for both the currently
  93. * polling process and the other process that xchg the last_seq
  94. * btw atomic read and xchg of the current process. And the
  95. * value the other process set as last seq must be higher than
  96. * the seq value we just read. Which means that current process
  97. * need to be interrupted after radeon_fence_read and before
  98. * atomic xchg.
  99. *
  100. * To be even more safe we count the number of time we loop and
  101. * we bail after 10 loop just accepting the fact that we might
  102. * have temporarly set the last_seq not to the true real last
  103. * seq but to an older one.
  104. */
  105. last_seq = atomic64_read(&rdev->fence_drv[ring].last_seq);
  106. do {
  107. seq = radeon_fence_read(rdev, ring);
  108. seq |= last_seq & 0xffffffff00000000LL;
  109. if (seq < last_seq) {
  110. seq += 0x100000000LL;
  111. }
  112. if (seq == last_seq) {
  113. break;
  114. }
  115. /* If we loop over we don't want to return without
  116. * checking if a fence is signaled as it means that the
  117. * seq we just read is different from the previous on.
  118. */
  119. wake = true;
  120. last_seq = seq;
  121. if ((count_loop++) > 10) {
  122. /* We looped over too many time leave with the
  123. * fact that we might have set an older fence
  124. * seq then the current real last seq as signaled
  125. * by the hw.
  126. */
  127. break;
  128. }
  129. } while (atomic64_xchg(&rdev->fence_drv[ring].last_seq, seq) > seq);
  130. if (wake) {
  131. rdev->fence_drv[ring].last_activity = jiffies;
  132. wake_up_all(&rdev->fence_queue);
  133. }
  134. }
  135. static void radeon_fence_destroy(struct kref *kref)
  136. {
  137. struct radeon_fence *fence;
  138. fence = container_of(kref, struct radeon_fence, kref);
  139. kfree(fence);
  140. }
  141. static bool radeon_fence_seq_signaled(struct radeon_device *rdev,
  142. u64 seq, unsigned ring)
  143. {
  144. if (atomic64_read(&rdev->fence_drv[ring].last_seq) >= seq) {
  145. return true;
  146. }
  147. /* poll new last sequence at least once */
  148. radeon_fence_process(rdev, ring);
  149. if (atomic64_read(&rdev->fence_drv[ring].last_seq) >= seq) {
  150. return true;
  151. }
  152. return false;
  153. }
  154. bool radeon_fence_signaled(struct radeon_fence *fence)
  155. {
  156. if (!fence) {
  157. return true;
  158. }
  159. if (fence->seq == RADEON_FENCE_SIGNALED_SEQ) {
  160. return true;
  161. }
  162. if (radeon_fence_seq_signaled(fence->rdev, fence->seq, fence->ring)) {
  163. fence->seq = RADEON_FENCE_SIGNALED_SEQ;
  164. return true;
  165. }
  166. return false;
  167. }
  168. static int radeon_fence_wait_seq(struct radeon_device *rdev, u64 target_seq,
  169. unsigned ring, bool intr, bool lock_ring)
  170. {
  171. unsigned long timeout, last_activity;
  172. uint64_t seq;
  173. unsigned i;
  174. bool signaled;
  175. int r;
  176. while (target_seq > atomic64_read(&rdev->fence_drv[ring].last_seq)) {
  177. if (!rdev->ring[ring].ready) {
  178. return -EBUSY;
  179. }
  180. timeout = jiffies - RADEON_FENCE_JIFFIES_TIMEOUT;
  181. if (time_after(rdev->fence_drv[ring].last_activity, timeout)) {
  182. /* the normal case, timeout is somewhere before last_activity */
  183. timeout = rdev->fence_drv[ring].last_activity - timeout;
  184. } else {
  185. /* either jiffies wrapped around, or no fence was signaled in the last 500ms
  186. * anyway we will just wait for the minimum amount and then check for a lockup
  187. */
  188. timeout = 1;
  189. }
  190. seq = atomic64_read(&rdev->fence_drv[ring].last_seq);
  191. /* Save current last activity valuee, used to check for GPU lockups */
  192. last_activity = rdev->fence_drv[ring].last_activity;
  193. trace_radeon_fence_wait_begin(rdev->ddev, seq);
  194. radeon_irq_kms_sw_irq_get(rdev, ring);
  195. if (intr) {
  196. r = wait_event_interruptible_timeout(rdev->fence_queue,
  197. (signaled = radeon_fence_seq_signaled(rdev, target_seq, ring)),
  198. timeout);
  199. } else {
  200. r = wait_event_timeout(rdev->fence_queue,
  201. (signaled = radeon_fence_seq_signaled(rdev, target_seq, ring)),
  202. timeout);
  203. }
  204. radeon_irq_kms_sw_irq_put(rdev, ring);
  205. if (unlikely(r < 0)) {
  206. return r;
  207. }
  208. trace_radeon_fence_wait_end(rdev->ddev, seq);
  209. if (unlikely(!signaled)) {
  210. /* we were interrupted for some reason and fence
  211. * isn't signaled yet, resume waiting */
  212. if (r) {
  213. continue;
  214. }
  215. /* check if sequence value has changed since last_activity */
  216. if (seq != atomic64_read(&rdev->fence_drv[ring].last_seq)) {
  217. continue;
  218. }
  219. if (lock_ring) {
  220. mutex_lock(&rdev->ring_lock);
  221. }
  222. /* test if somebody else has already decided that this is a lockup */
  223. if (last_activity != rdev->fence_drv[ring].last_activity) {
  224. if (lock_ring) {
  225. mutex_unlock(&rdev->ring_lock);
  226. }
  227. continue;
  228. }
  229. if (radeon_ring_is_lockup(rdev, ring, &rdev->ring[ring])) {
  230. /* good news we believe it's a lockup */
  231. dev_warn(rdev->dev, "GPU lockup (waiting for 0x%016llx last fence id 0x%016llx)\n",
  232. target_seq, seq);
  233. /* change last activity so nobody else think there is a lockup */
  234. for (i = 0; i < RADEON_NUM_RINGS; ++i) {
  235. rdev->fence_drv[i].last_activity = jiffies;
  236. }
  237. /* mark the ring as not ready any more */
  238. rdev->ring[ring].ready = false;
  239. if (lock_ring) {
  240. mutex_unlock(&rdev->ring_lock);
  241. }
  242. return -EDEADLK;
  243. }
  244. if (lock_ring) {
  245. mutex_unlock(&rdev->ring_lock);
  246. }
  247. }
  248. }
  249. return 0;
  250. }
  251. int radeon_fence_wait(struct radeon_fence *fence, bool intr)
  252. {
  253. int r;
  254. if (fence == NULL) {
  255. WARN(1, "Querying an invalid fence : %p !\n", fence);
  256. return -EINVAL;
  257. }
  258. r = radeon_fence_wait_seq(fence->rdev, fence->seq,
  259. fence->ring, intr, true);
  260. if (r) {
  261. return r;
  262. }
  263. fence->seq = RADEON_FENCE_SIGNALED_SEQ;
  264. return 0;
  265. }
  266. bool radeon_fence_any_seq_signaled(struct radeon_device *rdev, u64 *seq)
  267. {
  268. unsigned i;
  269. for (i = 0; i < RADEON_NUM_RINGS; ++i) {
  270. if (seq[i] && radeon_fence_seq_signaled(rdev, seq[i], i)) {
  271. return true;
  272. }
  273. }
  274. return false;
  275. }
  276. static int radeon_fence_wait_any_seq(struct radeon_device *rdev,
  277. u64 *target_seq, bool intr)
  278. {
  279. unsigned long timeout, last_activity, tmp;
  280. unsigned i, ring = RADEON_NUM_RINGS;
  281. bool signaled;
  282. int r;
  283. for (i = 0, last_activity = 0; i < RADEON_NUM_RINGS; ++i) {
  284. if (!target_seq[i]) {
  285. continue;
  286. }
  287. /* use the most recent one as indicator */
  288. if (time_after(rdev->fence_drv[i].last_activity, last_activity)) {
  289. last_activity = rdev->fence_drv[i].last_activity;
  290. }
  291. /* For lockup detection just pick the lowest ring we are
  292. * actively waiting for
  293. */
  294. if (i < ring) {
  295. ring = i;
  296. }
  297. }
  298. /* nothing to wait for ? */
  299. if (ring == RADEON_NUM_RINGS) {
  300. return -ENOENT;
  301. }
  302. while (!radeon_fence_any_seq_signaled(rdev, target_seq)) {
  303. timeout = jiffies - RADEON_FENCE_JIFFIES_TIMEOUT;
  304. if (time_after(last_activity, timeout)) {
  305. /* the normal case, timeout is somewhere before last_activity */
  306. timeout = last_activity - timeout;
  307. } else {
  308. /* either jiffies wrapped around, or no fence was signaled in the last 500ms
  309. * anyway we will just wait for the minimum amount and then check for a lockup
  310. */
  311. timeout = 1;
  312. }
  313. trace_radeon_fence_wait_begin(rdev->ddev, target_seq[ring]);
  314. for (i = 0; i < RADEON_NUM_RINGS; ++i) {
  315. if (target_seq[i]) {
  316. radeon_irq_kms_sw_irq_get(rdev, i);
  317. }
  318. }
  319. if (intr) {
  320. r = wait_event_interruptible_timeout(rdev->fence_queue,
  321. (signaled = radeon_fence_any_seq_signaled(rdev, target_seq)),
  322. timeout);
  323. } else {
  324. r = wait_event_timeout(rdev->fence_queue,
  325. (signaled = radeon_fence_any_seq_signaled(rdev, target_seq)),
  326. timeout);
  327. }
  328. for (i = 0; i < RADEON_NUM_RINGS; ++i) {
  329. if (target_seq[i]) {
  330. radeon_irq_kms_sw_irq_put(rdev, i);
  331. }
  332. }
  333. if (unlikely(r < 0)) {
  334. return r;
  335. }
  336. trace_radeon_fence_wait_end(rdev->ddev, target_seq[ring]);
  337. if (unlikely(!signaled)) {
  338. /* we were interrupted for some reason and fence
  339. * isn't signaled yet, resume waiting */
  340. if (r) {
  341. continue;
  342. }
  343. mutex_lock(&rdev->ring_lock);
  344. for (i = 0, tmp = 0; i < RADEON_NUM_RINGS; ++i) {
  345. if (time_after(rdev->fence_drv[i].last_activity, tmp)) {
  346. tmp = rdev->fence_drv[i].last_activity;
  347. }
  348. }
  349. /* test if somebody else has already decided that this is a lockup */
  350. if (last_activity != tmp) {
  351. last_activity = tmp;
  352. mutex_unlock(&rdev->ring_lock);
  353. continue;
  354. }
  355. if (radeon_ring_is_lockup(rdev, ring, &rdev->ring[ring])) {
  356. /* good news we believe it's a lockup */
  357. dev_warn(rdev->dev, "GPU lockup (waiting for 0x%016llx)\n",
  358. target_seq[ring]);
  359. /* change last activity so nobody else think there is a lockup */
  360. for (i = 0; i < RADEON_NUM_RINGS; ++i) {
  361. rdev->fence_drv[i].last_activity = jiffies;
  362. }
  363. /* mark the ring as not ready any more */
  364. rdev->ring[ring].ready = false;
  365. mutex_unlock(&rdev->ring_lock);
  366. return -EDEADLK;
  367. }
  368. mutex_unlock(&rdev->ring_lock);
  369. }
  370. }
  371. return 0;
  372. }
  373. int radeon_fence_wait_any(struct radeon_device *rdev,
  374. struct radeon_fence **fences,
  375. bool intr)
  376. {
  377. uint64_t seq[RADEON_NUM_RINGS];
  378. unsigned i;
  379. int r;
  380. for (i = 0; i < RADEON_NUM_RINGS; ++i) {
  381. seq[i] = 0;
  382. if (!fences[i]) {
  383. continue;
  384. }
  385. if (fences[i]->seq == RADEON_FENCE_SIGNALED_SEQ) {
  386. /* something was allready signaled */
  387. return 0;
  388. }
  389. seq[i] = fences[i]->seq;
  390. }
  391. r = radeon_fence_wait_any_seq(rdev, seq, intr);
  392. if (r) {
  393. return r;
  394. }
  395. return 0;
  396. }
  397. /* caller must hold ring lock */
  398. int radeon_fence_wait_next_locked(struct radeon_device *rdev, int ring)
  399. {
  400. uint64_t seq;
  401. seq = atomic64_read(&rdev->fence_drv[ring].last_seq) + 1ULL;
  402. if (seq >= rdev->fence_drv[ring].sync_seq[ring]) {
  403. /* nothing to wait for, last_seq is
  404. already the last emited fence */
  405. return -ENOENT;
  406. }
  407. return radeon_fence_wait_seq(rdev, seq, ring, false, false);
  408. }
  409. /* caller must hold ring lock */
  410. void radeon_fence_wait_empty_locked(struct radeon_device *rdev, int ring)
  411. {
  412. uint64_t seq = rdev->fence_drv[ring].sync_seq[ring];
  413. while(1) {
  414. int r;
  415. r = radeon_fence_wait_seq(rdev, seq, ring, false, false);
  416. if (r == -EDEADLK) {
  417. mutex_unlock(&rdev->ring_lock);
  418. r = radeon_gpu_reset(rdev);
  419. mutex_lock(&rdev->ring_lock);
  420. if (!r)
  421. continue;
  422. }
  423. if (r) {
  424. dev_err(rdev->dev, "error waiting for ring to become"
  425. " idle (%d)\n", r);
  426. }
  427. return;
  428. }
  429. }
  430. struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence)
  431. {
  432. kref_get(&fence->kref);
  433. return fence;
  434. }
  435. void radeon_fence_unref(struct radeon_fence **fence)
  436. {
  437. struct radeon_fence *tmp = *fence;
  438. *fence = NULL;
  439. if (tmp) {
  440. kref_put(&tmp->kref, radeon_fence_destroy);
  441. }
  442. }
  443. unsigned radeon_fence_count_emitted(struct radeon_device *rdev, int ring)
  444. {
  445. uint64_t emitted;
  446. /* We are not protected by ring lock when reading the last sequence
  447. * but it's ok to report slightly wrong fence count here.
  448. */
  449. radeon_fence_process(rdev, ring);
  450. emitted = rdev->fence_drv[ring].sync_seq[ring]
  451. - atomic64_read(&rdev->fence_drv[ring].last_seq);
  452. /* to avoid 32bits warp around */
  453. if (emitted > 0x10000000) {
  454. emitted = 0x10000000;
  455. }
  456. return (unsigned)emitted;
  457. }
  458. bool radeon_fence_need_sync(struct radeon_fence *fence, int dst_ring)
  459. {
  460. struct radeon_fence_driver *fdrv;
  461. if (!fence) {
  462. return false;
  463. }
  464. if (fence->ring == dst_ring) {
  465. return false;
  466. }
  467. /* we are protected by the ring mutex */
  468. fdrv = &fence->rdev->fence_drv[dst_ring];
  469. if (fence->seq <= fdrv->sync_seq[fence->ring]) {
  470. return false;
  471. }
  472. return true;
  473. }
  474. void radeon_fence_note_sync(struct radeon_fence *fence, int dst_ring)
  475. {
  476. struct radeon_fence_driver *dst, *src;
  477. unsigned i;
  478. if (!fence) {
  479. return;
  480. }
  481. if (fence->ring == dst_ring) {
  482. return;
  483. }
  484. /* we are protected by the ring mutex */
  485. src = &fence->rdev->fence_drv[fence->ring];
  486. dst = &fence->rdev->fence_drv[dst_ring];
  487. for (i = 0; i < RADEON_NUM_RINGS; ++i) {
  488. if (i == dst_ring) {
  489. continue;
  490. }
  491. dst->sync_seq[i] = max(dst->sync_seq[i], src->sync_seq[i]);
  492. }
  493. }
  494. int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring)
  495. {
  496. uint64_t index;
  497. int r;
  498. radeon_scratch_free(rdev, rdev->fence_drv[ring].scratch_reg);
  499. if (rdev->wb.use_event) {
  500. rdev->fence_drv[ring].scratch_reg = 0;
  501. index = R600_WB_EVENT_OFFSET + ring * 4;
  502. } else {
  503. r = radeon_scratch_get(rdev, &rdev->fence_drv[ring].scratch_reg);
  504. if (r) {
  505. dev_err(rdev->dev, "fence failed to get scratch register\n");
  506. return r;
  507. }
  508. index = RADEON_WB_SCRATCH_OFFSET +
  509. rdev->fence_drv[ring].scratch_reg -
  510. rdev->scratch.reg_base;
  511. }
  512. rdev->fence_drv[ring].cpu_addr = &rdev->wb.wb[index/4];
  513. rdev->fence_drv[ring].gpu_addr = rdev->wb.gpu_addr + index;
  514. radeon_fence_write(rdev, atomic64_read(&rdev->fence_drv[ring].last_seq), ring);
  515. rdev->fence_drv[ring].initialized = true;
  516. dev_info(rdev->dev, "fence driver on ring %d use gpu addr 0x%016llx and cpu addr 0x%p\n",
  517. ring, rdev->fence_drv[ring].gpu_addr, rdev->fence_drv[ring].cpu_addr);
  518. return 0;
  519. }
  520. static void radeon_fence_driver_init_ring(struct radeon_device *rdev, int ring)
  521. {
  522. int i;
  523. rdev->fence_drv[ring].scratch_reg = -1;
  524. rdev->fence_drv[ring].cpu_addr = NULL;
  525. rdev->fence_drv[ring].gpu_addr = 0;
  526. for (i = 0; i < RADEON_NUM_RINGS; ++i)
  527. rdev->fence_drv[ring].sync_seq[i] = 0;
  528. atomic64_set(&rdev->fence_drv[ring].last_seq, 0);
  529. rdev->fence_drv[ring].last_activity = jiffies;
  530. rdev->fence_drv[ring].initialized = false;
  531. }
  532. int radeon_fence_driver_init(struct radeon_device *rdev)
  533. {
  534. int ring;
  535. init_waitqueue_head(&rdev->fence_queue);
  536. for (ring = 0; ring < RADEON_NUM_RINGS; ring++) {
  537. radeon_fence_driver_init_ring(rdev, ring);
  538. }
  539. if (radeon_debugfs_fence_init(rdev)) {
  540. dev_err(rdev->dev, "fence debugfs file creation failed\n");
  541. }
  542. return 0;
  543. }
  544. void radeon_fence_driver_fini(struct radeon_device *rdev)
  545. {
  546. int ring;
  547. mutex_lock(&rdev->ring_lock);
  548. for (ring = 0; ring < RADEON_NUM_RINGS; ring++) {
  549. if (!rdev->fence_drv[ring].initialized)
  550. continue;
  551. radeon_fence_wait_empty_locked(rdev, ring);
  552. wake_up_all(&rdev->fence_queue);
  553. radeon_scratch_free(rdev, rdev->fence_drv[ring].scratch_reg);
  554. rdev->fence_drv[ring].initialized = false;
  555. }
  556. mutex_unlock(&rdev->ring_lock);
  557. }
  558. /*
  559. * Fence debugfs
  560. */
  561. #if defined(CONFIG_DEBUG_FS)
  562. static int radeon_debugfs_fence_info(struct seq_file *m, void *data)
  563. {
  564. struct drm_info_node *node = (struct drm_info_node *)m->private;
  565. struct drm_device *dev = node->minor->dev;
  566. struct radeon_device *rdev = dev->dev_private;
  567. int i, j;
  568. for (i = 0; i < RADEON_NUM_RINGS; ++i) {
  569. if (!rdev->fence_drv[i].initialized)
  570. continue;
  571. seq_printf(m, "--- ring %d ---\n", i);
  572. seq_printf(m, "Last signaled fence 0x%016llx\n",
  573. (unsigned long long)atomic64_read(&rdev->fence_drv[i].last_seq));
  574. seq_printf(m, "Last emitted 0x%016llx\n",
  575. rdev->fence_drv[i].sync_seq[i]);
  576. for (j = 0; j < RADEON_NUM_RINGS; ++j) {
  577. if (i != j && rdev->fence_drv[j].initialized)
  578. seq_printf(m, "Last sync to ring %d 0x%016llx\n",
  579. j, rdev->fence_drv[i].sync_seq[j]);
  580. }
  581. }
  582. return 0;
  583. }
  584. static struct drm_info_list radeon_debugfs_fence_list[] = {
  585. {"radeon_fence_info", &radeon_debugfs_fence_info, 0, NULL},
  586. };
  587. #endif
  588. int radeon_debugfs_fence_init(struct radeon_device *rdev)
  589. {
  590. #if defined(CONFIG_DEBUG_FS)
  591. return radeon_debugfs_add_files(rdev, radeon_debugfs_fence_list, 1);
  592. #else
  593. return 0;
  594. #endif
  595. }