radeon_ring.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. /*
  2. * Copyright 2008 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. * Copyright 2009 Jerome Glisse.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22. * OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * Authors: Dave Airlie
  25. * Alex Deucher
  26. * Jerome Glisse
  27. */
  28. #include <linux/seq_file.h>
  29. #include <linux/slab.h>
  30. #include "drmP.h"
  31. #include "radeon_drm.h"
  32. #include "radeon_reg.h"
  33. #include "radeon.h"
  34. #include "atom.h"
  35. int radeon_debugfs_ib_init(struct radeon_device *rdev);
  36. int radeon_debugfs_ring_init(struct radeon_device *rdev, struct radeon_ring *ring);
  37. u32 radeon_get_ib_value(struct radeon_cs_parser *p, int idx)
  38. {
  39. struct radeon_cs_chunk *ibc = &p->chunks[p->chunk_ib_idx];
  40. u32 pg_idx, pg_offset;
  41. u32 idx_value = 0;
  42. int new_page;
  43. pg_idx = (idx * 4) / PAGE_SIZE;
  44. pg_offset = (idx * 4) % PAGE_SIZE;
  45. if (ibc->kpage_idx[0] == pg_idx)
  46. return ibc->kpage[0][pg_offset/4];
  47. if (ibc->kpage_idx[1] == pg_idx)
  48. return ibc->kpage[1][pg_offset/4];
  49. new_page = radeon_cs_update_pages(p, pg_idx);
  50. if (new_page < 0) {
  51. p->parser_error = new_page;
  52. return 0;
  53. }
  54. idx_value = ibc->kpage[new_page][pg_offset/4];
  55. return idx_value;
  56. }
  57. void radeon_ring_write(struct radeon_ring *ring, uint32_t v)
  58. {
  59. #if DRM_DEBUG_CODE
  60. if (ring->count_dw <= 0) {
  61. DRM_ERROR("radeon: writting more dword to ring than expected !\n");
  62. }
  63. #endif
  64. ring->ring[ring->wptr++] = v;
  65. ring->wptr &= ring->ptr_mask;
  66. ring->count_dw--;
  67. ring->ring_free_dw--;
  68. }
  69. /*
  70. * IB.
  71. */
  72. bool radeon_ib_try_free(struct radeon_device *rdev, struct radeon_ib *ib)
  73. {
  74. bool done = false;
  75. /* only free ib which have been emited */
  76. if (ib->fence && ib->fence->seq < RADEON_FENCE_NOTEMITED_SEQ) {
  77. if (radeon_fence_signaled(ib->fence)) {
  78. radeon_fence_unref(&ib->fence);
  79. radeon_sa_bo_free(rdev, &ib->sa_bo, NULL);
  80. done = true;
  81. }
  82. }
  83. return done;
  84. }
  85. int radeon_ib_get(struct radeon_device *rdev, int ring,
  86. struct radeon_ib **ib, unsigned size)
  87. {
  88. struct radeon_fence *fence;
  89. unsigned cretry = 0;
  90. int r = 0, i, idx;
  91. *ib = NULL;
  92. /* align size on 256 bytes */
  93. size = ALIGN(size, 256);
  94. r = radeon_fence_create(rdev, &fence, ring);
  95. if (r) {
  96. dev_err(rdev->dev, "failed to create fence for new IB\n");
  97. return r;
  98. }
  99. radeon_mutex_lock(&rdev->ib_pool.mutex);
  100. idx = rdev->ib_pool.head_id;
  101. retry:
  102. if (cretry > 5) {
  103. dev_err(rdev->dev, "failed to get an ib after 5 retry\n");
  104. radeon_mutex_unlock(&rdev->ib_pool.mutex);
  105. radeon_fence_unref(&fence);
  106. return -ENOMEM;
  107. }
  108. cretry++;
  109. for (i = 0; i < RADEON_IB_POOL_SIZE; i++) {
  110. radeon_ib_try_free(rdev, &rdev->ib_pool.ibs[idx]);
  111. if (rdev->ib_pool.ibs[idx].fence == NULL) {
  112. r = radeon_sa_bo_new(rdev, &rdev->ib_pool.sa_manager,
  113. &rdev->ib_pool.ibs[idx].sa_bo,
  114. size, 256, false);
  115. if (!r) {
  116. *ib = &rdev->ib_pool.ibs[idx];
  117. (*ib)->ptr = radeon_sa_bo_cpu_addr((*ib)->sa_bo);
  118. (*ib)->gpu_addr = radeon_sa_bo_gpu_addr((*ib)->sa_bo);
  119. (*ib)->fence = fence;
  120. (*ib)->vm_id = 0;
  121. (*ib)->is_const_ib = false;
  122. /* ib are most likely to be allocated in a ring fashion
  123. * thus rdev->ib_pool.head_id should be the id of the
  124. * oldest ib
  125. */
  126. rdev->ib_pool.head_id = (1 + idx);
  127. rdev->ib_pool.head_id &= (RADEON_IB_POOL_SIZE - 1);
  128. radeon_mutex_unlock(&rdev->ib_pool.mutex);
  129. return 0;
  130. }
  131. }
  132. idx = (idx + 1) & (RADEON_IB_POOL_SIZE - 1);
  133. }
  134. /* this should be rare event, ie all ib scheduled none signaled yet.
  135. */
  136. for (i = 0; i < RADEON_IB_POOL_SIZE; i++) {
  137. struct radeon_fence *fence = rdev->ib_pool.ibs[idx].fence;
  138. if (fence && fence->seq < RADEON_FENCE_NOTEMITED_SEQ) {
  139. r = radeon_fence_wait(fence, false);
  140. if (!r) {
  141. goto retry;
  142. }
  143. /* an error happened */
  144. break;
  145. }
  146. idx = (idx + 1) & (RADEON_IB_POOL_SIZE - 1);
  147. }
  148. radeon_mutex_unlock(&rdev->ib_pool.mutex);
  149. radeon_fence_unref(&fence);
  150. return r;
  151. }
  152. void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib **ib)
  153. {
  154. struct radeon_ib *tmp = *ib;
  155. *ib = NULL;
  156. if (tmp == NULL) {
  157. return;
  158. }
  159. radeon_mutex_lock(&rdev->ib_pool.mutex);
  160. if (tmp->fence && tmp->fence->seq == RADEON_FENCE_NOTEMITED_SEQ) {
  161. radeon_sa_bo_free(rdev, &tmp->sa_bo, NULL);
  162. radeon_fence_unref(&tmp->fence);
  163. }
  164. radeon_mutex_unlock(&rdev->ib_pool.mutex);
  165. }
  166. int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib)
  167. {
  168. struct radeon_ring *ring = &rdev->ring[ib->fence->ring];
  169. int r = 0;
  170. if (!ib->length_dw || !ring->ready) {
  171. /* TODO: Nothings in the ib we should report. */
  172. DRM_ERROR("radeon: couldn't schedule IB(%u).\n", ib->idx);
  173. return -EINVAL;
  174. }
  175. /* 64 dwords should be enough for fence too */
  176. r = radeon_ring_lock(rdev, ring, 64);
  177. if (r) {
  178. DRM_ERROR("radeon: scheduling IB failed (%d).\n", r);
  179. return r;
  180. }
  181. radeon_ring_ib_execute(rdev, ib->fence->ring, ib);
  182. radeon_fence_emit(rdev, ib->fence);
  183. radeon_ring_unlock_commit(rdev, ring);
  184. return 0;
  185. }
  186. int radeon_ib_pool_init(struct radeon_device *rdev)
  187. {
  188. struct radeon_sa_manager tmp;
  189. int i, r;
  190. r = radeon_sa_bo_manager_init(rdev, &tmp,
  191. RADEON_IB_POOL_SIZE*64*1024,
  192. RADEON_GEM_DOMAIN_GTT);
  193. if (r) {
  194. return r;
  195. }
  196. radeon_mutex_lock(&rdev->ib_pool.mutex);
  197. if (rdev->ib_pool.ready) {
  198. radeon_mutex_unlock(&rdev->ib_pool.mutex);
  199. radeon_sa_bo_manager_fini(rdev, &tmp);
  200. return 0;
  201. }
  202. rdev->ib_pool.sa_manager = tmp;
  203. INIT_LIST_HEAD(&rdev->ib_pool.sa_manager.sa_bo);
  204. for (i = 0; i < RADEON_IB_POOL_SIZE; i++) {
  205. rdev->ib_pool.ibs[i].fence = NULL;
  206. rdev->ib_pool.ibs[i].idx = i;
  207. rdev->ib_pool.ibs[i].length_dw = 0;
  208. rdev->ib_pool.ibs[i].sa_bo = NULL;
  209. }
  210. rdev->ib_pool.head_id = 0;
  211. rdev->ib_pool.ready = true;
  212. DRM_INFO("radeon: ib pool ready.\n");
  213. if (radeon_debugfs_ib_init(rdev)) {
  214. DRM_ERROR("Failed to register debugfs file for IB !\n");
  215. }
  216. radeon_mutex_unlock(&rdev->ib_pool.mutex);
  217. return 0;
  218. }
  219. void radeon_ib_pool_fini(struct radeon_device *rdev)
  220. {
  221. unsigned i;
  222. radeon_mutex_lock(&rdev->ib_pool.mutex);
  223. if (rdev->ib_pool.ready) {
  224. for (i = 0; i < RADEON_IB_POOL_SIZE; i++) {
  225. radeon_sa_bo_free(rdev, &rdev->ib_pool.ibs[i].sa_bo, NULL);
  226. radeon_fence_unref(&rdev->ib_pool.ibs[i].fence);
  227. }
  228. radeon_sa_bo_manager_fini(rdev, &rdev->ib_pool.sa_manager);
  229. rdev->ib_pool.ready = false;
  230. }
  231. radeon_mutex_unlock(&rdev->ib_pool.mutex);
  232. }
  233. int radeon_ib_pool_start(struct radeon_device *rdev)
  234. {
  235. return radeon_sa_bo_manager_start(rdev, &rdev->ib_pool.sa_manager);
  236. }
  237. int radeon_ib_pool_suspend(struct radeon_device *rdev)
  238. {
  239. return radeon_sa_bo_manager_suspend(rdev, &rdev->ib_pool.sa_manager);
  240. }
  241. int radeon_ib_ring_tests(struct radeon_device *rdev)
  242. {
  243. unsigned i;
  244. int r;
  245. for (i = 0; i < RADEON_NUM_RINGS; ++i) {
  246. struct radeon_ring *ring = &rdev->ring[i];
  247. if (!ring->ready)
  248. continue;
  249. r = radeon_ib_test(rdev, i, ring);
  250. if (r) {
  251. ring->ready = false;
  252. if (i == RADEON_RING_TYPE_GFX_INDEX) {
  253. /* oh, oh, that's really bad */
  254. DRM_ERROR("radeon: failed testing IB on GFX ring (%d).\n", r);
  255. rdev->accel_working = false;
  256. return r;
  257. } else {
  258. /* still not good, but we can live with it */
  259. DRM_ERROR("radeon: failed testing IB on ring %d (%d).\n", i, r);
  260. }
  261. }
  262. }
  263. return 0;
  264. }
  265. /*
  266. * Ring.
  267. */
  268. int radeon_ring_index(struct radeon_device *rdev, struct radeon_ring *ring)
  269. {
  270. /* r1xx-r5xx only has CP ring */
  271. if (rdev->family < CHIP_R600)
  272. return RADEON_RING_TYPE_GFX_INDEX;
  273. if (rdev->family >= CHIP_CAYMAN) {
  274. if (ring == &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX])
  275. return CAYMAN_RING_TYPE_CP1_INDEX;
  276. else if (ring == &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX])
  277. return CAYMAN_RING_TYPE_CP2_INDEX;
  278. }
  279. return RADEON_RING_TYPE_GFX_INDEX;
  280. }
  281. void radeon_ring_free_size(struct radeon_device *rdev, struct radeon_ring *ring)
  282. {
  283. u32 rptr;
  284. if (rdev->wb.enabled)
  285. rptr = le32_to_cpu(rdev->wb.wb[ring->rptr_offs/4]);
  286. else
  287. rptr = RREG32(ring->rptr_reg);
  288. ring->rptr = (rptr & ring->ptr_reg_mask) >> ring->ptr_reg_shift;
  289. /* This works because ring_size is a power of 2 */
  290. ring->ring_free_dw = (ring->rptr + (ring->ring_size / 4));
  291. ring->ring_free_dw -= ring->wptr;
  292. ring->ring_free_dw &= ring->ptr_mask;
  293. if (!ring->ring_free_dw) {
  294. ring->ring_free_dw = ring->ring_size / 4;
  295. }
  296. }
  297. int radeon_ring_alloc(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ndw)
  298. {
  299. int r;
  300. /* Align requested size with padding so unlock_commit can
  301. * pad safely */
  302. ndw = (ndw + ring->align_mask) & ~ring->align_mask;
  303. while (ndw > (ring->ring_free_dw - 1)) {
  304. radeon_ring_free_size(rdev, ring);
  305. if (ndw < ring->ring_free_dw) {
  306. break;
  307. }
  308. r = radeon_fence_wait_next_locked(rdev, radeon_ring_index(rdev, ring));
  309. if (r)
  310. return r;
  311. }
  312. ring->count_dw = ndw;
  313. ring->wptr_old = ring->wptr;
  314. return 0;
  315. }
  316. int radeon_ring_lock(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ndw)
  317. {
  318. int r;
  319. mutex_lock(&rdev->ring_lock);
  320. r = radeon_ring_alloc(rdev, ring, ndw);
  321. if (r) {
  322. mutex_unlock(&rdev->ring_lock);
  323. return r;
  324. }
  325. return 0;
  326. }
  327. void radeon_ring_commit(struct radeon_device *rdev, struct radeon_ring *ring)
  328. {
  329. unsigned count_dw_pad;
  330. unsigned i;
  331. /* We pad to match fetch size */
  332. count_dw_pad = (ring->align_mask + 1) -
  333. (ring->wptr & ring->align_mask);
  334. for (i = 0; i < count_dw_pad; i++) {
  335. radeon_ring_write(ring, ring->nop);
  336. }
  337. DRM_MEMORYBARRIER();
  338. WREG32(ring->wptr_reg, (ring->wptr << ring->ptr_reg_shift) & ring->ptr_reg_mask);
  339. (void)RREG32(ring->wptr_reg);
  340. }
  341. void radeon_ring_unlock_commit(struct radeon_device *rdev, struct radeon_ring *ring)
  342. {
  343. radeon_ring_commit(rdev, ring);
  344. mutex_unlock(&rdev->ring_lock);
  345. }
  346. void radeon_ring_undo(struct radeon_ring *ring)
  347. {
  348. ring->wptr = ring->wptr_old;
  349. }
  350. void radeon_ring_unlock_undo(struct radeon_device *rdev, struct radeon_ring *ring)
  351. {
  352. radeon_ring_undo(ring);
  353. mutex_unlock(&rdev->ring_lock);
  354. }
  355. void radeon_ring_force_activity(struct radeon_device *rdev, struct radeon_ring *ring)
  356. {
  357. int r;
  358. radeon_ring_free_size(rdev, ring);
  359. if (ring->rptr == ring->wptr) {
  360. r = radeon_ring_alloc(rdev, ring, 1);
  361. if (!r) {
  362. radeon_ring_write(ring, ring->nop);
  363. radeon_ring_commit(rdev, ring);
  364. }
  365. }
  366. }
  367. void radeon_ring_lockup_update(struct radeon_ring *ring)
  368. {
  369. ring->last_rptr = ring->rptr;
  370. ring->last_activity = jiffies;
  371. }
  372. /**
  373. * radeon_ring_test_lockup() - check if ring is lockedup by recording information
  374. * @rdev: radeon device structure
  375. * @ring: radeon_ring structure holding ring information
  376. *
  377. * We don't need to initialize the lockup tracking information as we will either
  378. * have CP rptr to a different value of jiffies wrap around which will force
  379. * initialization of the lockup tracking informations.
  380. *
  381. * A possible false positivie is if we get call after while and last_cp_rptr ==
  382. * the current CP rptr, even if it's unlikely it might happen. To avoid this
  383. * if the elapsed time since last call is bigger than 2 second than we return
  384. * false and update the tracking information. Due to this the caller must call
  385. * radeon_ring_test_lockup several time in less than 2sec for lockup to be reported
  386. * the fencing code should be cautious about that.
  387. *
  388. * Caller should write to the ring to force CP to do something so we don't get
  389. * false positive when CP is just gived nothing to do.
  390. *
  391. **/
  392. bool radeon_ring_test_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
  393. {
  394. unsigned long cjiffies, elapsed;
  395. uint32_t rptr;
  396. cjiffies = jiffies;
  397. if (!time_after(cjiffies, ring->last_activity)) {
  398. /* likely a wrap around */
  399. radeon_ring_lockup_update(ring);
  400. return false;
  401. }
  402. rptr = RREG32(ring->rptr_reg);
  403. ring->rptr = (rptr & ring->ptr_reg_mask) >> ring->ptr_reg_shift;
  404. if (ring->rptr != ring->last_rptr) {
  405. /* CP is still working no lockup */
  406. radeon_ring_lockup_update(ring);
  407. return false;
  408. }
  409. elapsed = jiffies_to_msecs(cjiffies - ring->last_activity);
  410. if (radeon_lockup_timeout && elapsed >= radeon_lockup_timeout) {
  411. dev_err(rdev->dev, "GPU lockup CP stall for more than %lumsec\n", elapsed);
  412. return true;
  413. }
  414. /* give a chance to the GPU ... */
  415. return false;
  416. }
  417. int radeon_ring_init(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ring_size,
  418. unsigned rptr_offs, unsigned rptr_reg, unsigned wptr_reg,
  419. u32 ptr_reg_shift, u32 ptr_reg_mask, u32 nop)
  420. {
  421. int r;
  422. ring->ring_size = ring_size;
  423. ring->rptr_offs = rptr_offs;
  424. ring->rptr_reg = rptr_reg;
  425. ring->wptr_reg = wptr_reg;
  426. ring->ptr_reg_shift = ptr_reg_shift;
  427. ring->ptr_reg_mask = ptr_reg_mask;
  428. ring->nop = nop;
  429. /* Allocate ring buffer */
  430. if (ring->ring_obj == NULL) {
  431. r = radeon_bo_create(rdev, ring->ring_size, PAGE_SIZE, true,
  432. RADEON_GEM_DOMAIN_GTT,
  433. &ring->ring_obj);
  434. if (r) {
  435. dev_err(rdev->dev, "(%d) ring create failed\n", r);
  436. return r;
  437. }
  438. r = radeon_bo_reserve(ring->ring_obj, false);
  439. if (unlikely(r != 0))
  440. return r;
  441. r = radeon_bo_pin(ring->ring_obj, RADEON_GEM_DOMAIN_GTT,
  442. &ring->gpu_addr);
  443. if (r) {
  444. radeon_bo_unreserve(ring->ring_obj);
  445. dev_err(rdev->dev, "(%d) ring pin failed\n", r);
  446. return r;
  447. }
  448. r = radeon_bo_kmap(ring->ring_obj,
  449. (void **)&ring->ring);
  450. radeon_bo_unreserve(ring->ring_obj);
  451. if (r) {
  452. dev_err(rdev->dev, "(%d) ring map failed\n", r);
  453. return r;
  454. }
  455. }
  456. ring->ptr_mask = (ring->ring_size / 4) - 1;
  457. ring->ring_free_dw = ring->ring_size / 4;
  458. if (radeon_debugfs_ring_init(rdev, ring)) {
  459. DRM_ERROR("Failed to register debugfs file for rings !\n");
  460. }
  461. return 0;
  462. }
  463. void radeon_ring_fini(struct radeon_device *rdev, struct radeon_ring *ring)
  464. {
  465. int r;
  466. struct radeon_bo *ring_obj;
  467. mutex_lock(&rdev->ring_lock);
  468. ring_obj = ring->ring_obj;
  469. ring->ready = false;
  470. ring->ring = NULL;
  471. ring->ring_obj = NULL;
  472. mutex_unlock(&rdev->ring_lock);
  473. if (ring_obj) {
  474. r = radeon_bo_reserve(ring_obj, false);
  475. if (likely(r == 0)) {
  476. radeon_bo_kunmap(ring_obj);
  477. radeon_bo_unpin(ring_obj);
  478. radeon_bo_unreserve(ring_obj);
  479. }
  480. radeon_bo_unref(&ring_obj);
  481. }
  482. }
  483. /*
  484. * Debugfs info
  485. */
  486. #if defined(CONFIG_DEBUG_FS)
  487. static int radeon_debugfs_ring_info(struct seq_file *m, void *data)
  488. {
  489. struct drm_info_node *node = (struct drm_info_node *) m->private;
  490. struct drm_device *dev = node->minor->dev;
  491. struct radeon_device *rdev = dev->dev_private;
  492. int ridx = *(int*)node->info_ent->data;
  493. struct radeon_ring *ring = &rdev->ring[ridx];
  494. unsigned count, i, j;
  495. radeon_ring_free_size(rdev, ring);
  496. count = (ring->ring_size / 4) - ring->ring_free_dw;
  497. seq_printf(m, "wptr(0x%04x): 0x%08x\n", ring->wptr_reg, RREG32(ring->wptr_reg));
  498. seq_printf(m, "rptr(0x%04x): 0x%08x\n", ring->rptr_reg, RREG32(ring->rptr_reg));
  499. seq_printf(m, "driver's copy of the wptr: 0x%08x\n", ring->wptr);
  500. seq_printf(m, "driver's copy of the rptr: 0x%08x\n", ring->rptr);
  501. seq_printf(m, "%u free dwords in ring\n", ring->ring_free_dw);
  502. seq_printf(m, "%u dwords in ring\n", count);
  503. i = ring->rptr;
  504. for (j = 0; j <= count; j++) {
  505. seq_printf(m, "r[%04d]=0x%08x\n", i, ring->ring[i]);
  506. i = (i + 1) & ring->ptr_mask;
  507. }
  508. return 0;
  509. }
  510. static int radeon_ring_type_gfx_index = RADEON_RING_TYPE_GFX_INDEX;
  511. static int cayman_ring_type_cp1_index = CAYMAN_RING_TYPE_CP1_INDEX;
  512. static int cayman_ring_type_cp2_index = CAYMAN_RING_TYPE_CP2_INDEX;
  513. static struct drm_info_list radeon_debugfs_ring_info_list[] = {
  514. {"radeon_ring_gfx", radeon_debugfs_ring_info, 0, &radeon_ring_type_gfx_index},
  515. {"radeon_ring_cp1", radeon_debugfs_ring_info, 0, &cayman_ring_type_cp1_index},
  516. {"radeon_ring_cp2", radeon_debugfs_ring_info, 0, &cayman_ring_type_cp2_index},
  517. };
  518. static int radeon_debugfs_ib_info(struct seq_file *m, void *data)
  519. {
  520. struct drm_info_node *node = (struct drm_info_node *) m->private;
  521. struct drm_device *dev = node->minor->dev;
  522. struct radeon_device *rdev = dev->dev_private;
  523. struct radeon_ib *ib = &rdev->ib_pool.ibs[*((unsigned*)node->info_ent->data)];
  524. unsigned i;
  525. if (ib == NULL) {
  526. return 0;
  527. }
  528. seq_printf(m, "IB %04u\n", ib->idx);
  529. seq_printf(m, "IB fence %p\n", ib->fence);
  530. seq_printf(m, "IB size %05u dwords\n", ib->length_dw);
  531. for (i = 0; i < ib->length_dw; i++) {
  532. seq_printf(m, "[%05u]=0x%08X\n", i, ib->ptr[i]);
  533. }
  534. return 0;
  535. }
  536. static struct drm_info_list radeon_debugfs_ib_list[RADEON_IB_POOL_SIZE];
  537. static char radeon_debugfs_ib_names[RADEON_IB_POOL_SIZE][32];
  538. static unsigned radeon_debugfs_ib_idx[RADEON_IB_POOL_SIZE];
  539. static int radeon_debugfs_sa_info(struct seq_file *m, void *data)
  540. {
  541. struct drm_info_node *node = (struct drm_info_node *) m->private;
  542. struct drm_device *dev = node->minor->dev;
  543. struct radeon_device *rdev = dev->dev_private;
  544. radeon_sa_bo_dump_debug_info(&rdev->ib_pool.sa_manager, m);
  545. return 0;
  546. }
  547. static struct drm_info_list radeon_debugfs_sa_list[] = {
  548. {"radeon_sa_info", &radeon_debugfs_sa_info, 0, NULL},
  549. };
  550. #endif
  551. int radeon_debugfs_ring_init(struct radeon_device *rdev, struct radeon_ring *ring)
  552. {
  553. #if defined(CONFIG_DEBUG_FS)
  554. unsigned i;
  555. for (i = 0; i < ARRAY_SIZE(radeon_debugfs_ring_info_list); ++i) {
  556. struct drm_info_list *info = &radeon_debugfs_ring_info_list[i];
  557. int ridx = *(int*)radeon_debugfs_ring_info_list[i].data;
  558. unsigned r;
  559. if (&rdev->ring[ridx] != ring)
  560. continue;
  561. r = radeon_debugfs_add_files(rdev, info, 1);
  562. if (r)
  563. return r;
  564. }
  565. #endif
  566. return 0;
  567. }
  568. int radeon_debugfs_ib_init(struct radeon_device *rdev)
  569. {
  570. #if defined(CONFIG_DEBUG_FS)
  571. unsigned i;
  572. int r;
  573. r = radeon_debugfs_add_files(rdev, radeon_debugfs_sa_list, 1);
  574. if (r)
  575. return r;
  576. for (i = 0; i < RADEON_IB_POOL_SIZE; i++) {
  577. sprintf(radeon_debugfs_ib_names[i], "radeon_ib_%04u", i);
  578. radeon_debugfs_ib_idx[i] = i;
  579. radeon_debugfs_ib_list[i].name = radeon_debugfs_ib_names[i];
  580. radeon_debugfs_ib_list[i].show = &radeon_debugfs_ib_info;
  581. radeon_debugfs_ib_list[i].driver_features = 0;
  582. radeon_debugfs_ib_list[i].data = &radeon_debugfs_ib_idx[i];
  583. }
  584. return radeon_debugfs_add_files(rdev, radeon_debugfs_ib_list,
  585. RADEON_IB_POOL_SIZE);
  586. #else
  587. return 0;
  588. #endif
  589. }