]>
Commit | Line | Data |
---|---|---|
771fe6b9 JG |
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> | |
5a0e3ad6 | 29 | #include <linux/slab.h> |
771fe6b9 JG |
30 | #include "drmP.h" |
31 | #include "radeon_drm.h" | |
32 | #include "radeon_reg.h" | |
33 | #include "radeon.h" | |
34 | #include "atom.h" | |
35 | ||
36 | int radeon_debugfs_ib_init(struct radeon_device *rdev); | |
af9720f4 | 37 | int radeon_debugfs_ring_init(struct radeon_device *rdev); |
771fe6b9 | 38 | |
ce580fab AK |
39 | u32 radeon_get_ib_value(struct radeon_cs_parser *p, int idx) |
40 | { | |
41 | struct radeon_cs_chunk *ibc = &p->chunks[p->chunk_ib_idx]; | |
42 | u32 pg_idx, pg_offset; | |
43 | u32 idx_value = 0; | |
44 | int new_page; | |
45 | ||
46 | pg_idx = (idx * 4) / PAGE_SIZE; | |
47 | pg_offset = (idx * 4) % PAGE_SIZE; | |
48 | ||
49 | if (ibc->kpage_idx[0] == pg_idx) | |
50 | return ibc->kpage[0][pg_offset/4]; | |
51 | if (ibc->kpage_idx[1] == pg_idx) | |
52 | return ibc->kpage[1][pg_offset/4]; | |
53 | ||
54 | new_page = radeon_cs_update_pages(p, pg_idx); | |
55 | if (new_page < 0) { | |
56 | p->parser_error = new_page; | |
57 | return 0; | |
58 | } | |
59 | ||
60 | idx_value = ibc->kpage[new_page][pg_offset/4]; | |
61 | return idx_value; | |
62 | } | |
63 | ||
e32eb50d | 64 | void radeon_ring_write(struct radeon_ring *ring, uint32_t v) |
ce580fab AK |
65 | { |
66 | #if DRM_DEBUG_CODE | |
e32eb50d | 67 | if (ring->count_dw <= 0) { |
ce580fab AK |
68 | DRM_ERROR("radeon: writting more dword to ring than expected !\n"); |
69 | } | |
70 | #endif | |
e32eb50d CK |
71 | ring->ring[ring->wptr++] = v; |
72 | ring->wptr &= ring->ptr_mask; | |
73 | ring->count_dw--; | |
74 | ring->ring_free_dw--; | |
ce580fab AK |
75 | } |
76 | ||
b15ba512 JG |
77 | /* |
78 | * IB. | |
79 | */ | |
80 | static bool radeon_ib_try_free(struct radeon_device *rdev, | |
81 | struct radeon_ib *ib) | |
9f93ed39 | 82 | { |
b15ba512 JG |
83 | bool done = false; |
84 | ||
85 | /* only free ib which have been emited */ | |
86 | if (ib->fence && ib->fence->emitted) { | |
87 | if (radeon_fence_signaled(ib->fence)) { | |
88 | radeon_fence_unref(&ib->fence); | |
89 | radeon_sa_bo_free(rdev, &ib->sa_bo); | |
90 | done = true; | |
91 | } | |
9f93ed39 | 92 | } |
b15ba512 | 93 | return done; |
9f93ed39 JG |
94 | } |
95 | ||
7b1f2485 | 96 | int radeon_ib_get(struct radeon_device *rdev, int ring, struct radeon_ib **ib) |
771fe6b9 JG |
97 | { |
98 | struct radeon_fence *fence; | |
b15ba512 JG |
99 | unsigned cretry = 0; |
100 | int r = 0, i, idx; | |
771fe6b9 JG |
101 | |
102 | *ib = NULL; | |
b15ba512 | 103 | |
7b1f2485 | 104 | r = radeon_fence_create(rdev, &fence, ring); |
771fe6b9 | 105 | if (r) { |
91cb91be | 106 | dev_err(rdev->dev, "failed to create fence for new IB\n"); |
771fe6b9 JG |
107 | return r; |
108 | } | |
b15ba512 | 109 | |
771fe6b9 | 110 | mutex_lock(&rdev->ib_pool.mutex); |
b15ba512 JG |
111 | idx = rdev->ib_pool.head_id; |
112 | retry: | |
113 | if (cretry > 5) { | |
114 | dev_err(rdev->dev, "failed to get an ib after 5 retry\n"); | |
ecb114a1 | 115 | mutex_unlock(&rdev->ib_pool.mutex); |
91cb91be | 116 | radeon_fence_unref(&fence); |
b15ba512 | 117 | return -ENOMEM; |
771fe6b9 | 118 | } |
b15ba512 JG |
119 | cretry++; |
120 | for (i = 0; i < RADEON_IB_POOL_SIZE; i++) { | |
121 | radeon_ib_try_free(rdev, &rdev->ib_pool.ibs[idx]); | |
122 | if (rdev->ib_pool.ibs[idx].fence == NULL) { | |
123 | r = radeon_sa_bo_new(rdev, &rdev->ib_pool.sa_manager, | |
124 | &rdev->ib_pool.ibs[idx].sa_bo, | |
125 | 64*1024, 64); | |
126 | if (!r) { | |
127 | *ib = &rdev->ib_pool.ibs[idx]; | |
128 | (*ib)->ptr = rdev->ib_pool.sa_manager.cpu_ptr; | |
129 | (*ib)->ptr += ((*ib)->sa_bo.offset >> 2); | |
130 | (*ib)->gpu_addr = rdev->ib_pool.sa_manager.gpu_addr; | |
131 | (*ib)->gpu_addr += (*ib)->sa_bo.offset; | |
132 | (*ib)->fence = fence; | |
133 | /* ib are most likely to be allocated in a ring fashion | |
134 | * thus rdev->ib_pool.head_id should be the id of the | |
135 | * oldest ib | |
136 | */ | |
137 | rdev->ib_pool.head_id = (1 + idx); | |
138 | rdev->ib_pool.head_id &= (RADEON_IB_POOL_SIZE - 1); | |
139 | mutex_unlock(&rdev->ib_pool.mutex); | |
140 | return 0; | |
141 | } | |
91cb91be | 142 | } |
b15ba512 JG |
143 | idx = (idx + 1) & (RADEON_IB_POOL_SIZE - 1); |
144 | } | |
145 | /* this should be rare event, ie all ib scheduled none signaled yet. | |
146 | */ | |
147 | for (i = 0; i < RADEON_IB_POOL_SIZE; i++) { | |
148 | if (rdev->ib_pool.ibs[idx].fence) { | |
149 | r = radeon_fence_wait(rdev->ib_pool.ibs[idx].fence, false); | |
150 | if (!r) { | |
151 | goto retry; | |
152 | } | |
153 | /* an error happened */ | |
154 | break; | |
155 | } | |
156 | idx = (idx + 1) & (RADEON_IB_POOL_SIZE - 1); | |
771fe6b9 | 157 | } |
ecb114a1 | 158 | mutex_unlock(&rdev->ib_pool.mutex); |
b15ba512 JG |
159 | radeon_fence_unref(&fence); |
160 | return r; | |
771fe6b9 JG |
161 | } |
162 | ||
163 | void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib **ib) | |
164 | { | |
165 | struct radeon_ib *tmp = *ib; | |
166 | ||
167 | *ib = NULL; | |
168 | if (tmp == NULL) { | |
169 | return; | |
170 | } | |
171 | mutex_lock(&rdev->ib_pool.mutex); | |
b15ba512 JG |
172 | if (tmp->fence && !tmp->fence->emitted) { |
173 | radeon_sa_bo_free(rdev, &tmp->sa_bo); | |
174 | radeon_fence_unref(&tmp->fence); | |
175 | } | |
771fe6b9 JG |
176 | mutex_unlock(&rdev->ib_pool.mutex); |
177 | } | |
178 | ||
771fe6b9 JG |
179 | int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib) |
180 | { | |
e32eb50d | 181 | struct radeon_ring *ring = &rdev->ring[ib->fence->ring]; |
771fe6b9 JG |
182 | int r = 0; |
183 | ||
e32eb50d | 184 | if (!ib->length_dw || !ring->ready) { |
771fe6b9 | 185 | /* TODO: Nothings in the ib we should report. */ |
91cb91be | 186 | DRM_ERROR("radeon: couldn't schedule IB(%u).\n", ib->idx); |
771fe6b9 JG |
187 | return -EINVAL; |
188 | } | |
ecb114a1 | 189 | |
6cdf6585 | 190 | /* 64 dwords should be enough for fence too */ |
e32eb50d | 191 | r = radeon_ring_lock(rdev, ring, 64); |
771fe6b9 | 192 | if (r) { |
ec4f2ac4 | 193 | DRM_ERROR("radeon: scheduling IB failed (%d).\n", r); |
771fe6b9 JG |
194 | return r; |
195 | } | |
4c87bc26 | 196 | radeon_ring_ib_execute(rdev, ib->fence->ring, ib); |
771fe6b9 | 197 | radeon_fence_emit(rdev, ib->fence); |
e32eb50d | 198 | radeon_ring_unlock_commit(rdev, ring); |
771fe6b9 JG |
199 | return 0; |
200 | } | |
201 | ||
202 | int radeon_ib_pool_init(struct radeon_device *rdev) | |
203 | { | |
b15ba512 | 204 | int i, r; |
771fe6b9 | 205 | |
b15ba512 JG |
206 | mutex_lock(&rdev->ib_pool.mutex); |
207 | if (rdev->ib_pool.ready) { | |
208 | mutex_unlock(&rdev->ib_pool.mutex); | |
9f022ddf | 209 | return 0; |
771fe6b9 | 210 | } |
b15ba512 JG |
211 | |
212 | r = radeon_sa_bo_manager_init(rdev, &rdev->ib_pool.sa_manager, | |
213 | RADEON_IB_POOL_SIZE*64*1024, | |
214 | RADEON_GEM_DOMAIN_GTT); | |
771fe6b9 | 215 | if (r) { |
b15ba512 | 216 | mutex_unlock(&rdev->ib_pool.mutex); |
771fe6b9 JG |
217 | return r; |
218 | } | |
771fe6b9 | 219 | |
b15ba512 JG |
220 | for (i = 0; i < RADEON_IB_POOL_SIZE; i++) { |
221 | rdev->ib_pool.ibs[i].fence = NULL; | |
771fe6b9 JG |
222 | rdev->ib_pool.ibs[i].idx = i; |
223 | rdev->ib_pool.ibs[i].length_dw = 0; | |
b15ba512 | 224 | INIT_LIST_HEAD(&rdev->ib_pool.ibs[i].sa_bo.list); |
771fe6b9 | 225 | } |
91cb91be | 226 | rdev->ib_pool.head_id = 0; |
771fe6b9 JG |
227 | rdev->ib_pool.ready = true; |
228 | DRM_INFO("radeon: ib pool ready.\n"); | |
b15ba512 | 229 | |
771fe6b9 JG |
230 | if (radeon_debugfs_ib_init(rdev)) { |
231 | DRM_ERROR("Failed to register debugfs file for IB !\n"); | |
232 | } | |
af9720f4 CK |
233 | if (radeon_debugfs_ring_init(rdev)) { |
234 | DRM_ERROR("Failed to register debugfs file for rings !\n"); | |
235 | } | |
b15ba512 JG |
236 | mutex_unlock(&rdev->ib_pool.mutex); |
237 | return 0; | |
771fe6b9 JG |
238 | } |
239 | ||
240 | void radeon_ib_pool_fini(struct radeon_device *rdev) | |
241 | { | |
b15ba512 | 242 | unsigned i; |
4c788679 | 243 | |
771fe6b9 | 244 | mutex_lock(&rdev->ib_pool.mutex); |
b15ba512 JG |
245 | if (rdev->ib_pool.ready) { |
246 | for (i = 0; i < RADEON_IB_POOL_SIZE; i++) { | |
247 | radeon_sa_bo_free(rdev, &rdev->ib_pool.ibs[i].sa_bo); | |
248 | radeon_fence_unref(&rdev->ib_pool.ibs[i].fence); | |
4c788679 | 249 | } |
b15ba512 JG |
250 | radeon_sa_bo_manager_fini(rdev, &rdev->ib_pool.sa_manager); |
251 | rdev->ib_pool.ready = false; | |
771fe6b9 | 252 | } |
b15ba512 | 253 | mutex_unlock(&rdev->ib_pool.mutex); |
771fe6b9 JG |
254 | } |
255 | ||
b15ba512 JG |
256 | int radeon_ib_pool_start(struct radeon_device *rdev) |
257 | { | |
258 | return radeon_sa_bo_manager_start(rdev, &rdev->ib_pool.sa_manager); | |
259 | } | |
260 | ||
261 | int radeon_ib_pool_suspend(struct radeon_device *rdev) | |
262 | { | |
263 | return radeon_sa_bo_manager_suspend(rdev, &rdev->ib_pool.sa_manager); | |
264 | } | |
771fe6b9 JG |
265 | |
266 | /* | |
267 | * Ring. | |
268 | */ | |
e32eb50d | 269 | int radeon_ring_index(struct radeon_device *rdev, struct radeon_ring *ring) |
bf852799 CK |
270 | { |
271 | /* r1xx-r5xx only has CP ring */ | |
272 | if (rdev->family < CHIP_R600) | |
273 | return RADEON_RING_TYPE_GFX_INDEX; | |
274 | ||
275 | if (rdev->family >= CHIP_CAYMAN) { | |
e32eb50d | 276 | if (ring == &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX]) |
bf852799 | 277 | return CAYMAN_RING_TYPE_CP1_INDEX; |
e32eb50d | 278 | else if (ring == &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX]) |
bf852799 CK |
279 | return CAYMAN_RING_TYPE_CP2_INDEX; |
280 | } | |
281 | return RADEON_RING_TYPE_GFX_INDEX; | |
282 | } | |
283 | ||
e32eb50d | 284 | void radeon_ring_free_size(struct radeon_device *rdev, struct radeon_ring *ring) |
771fe6b9 | 285 | { |
78c5560a AD |
286 | u32 rptr; |
287 | ||
724c80e1 | 288 | if (rdev->wb.enabled) |
78c5560a | 289 | rptr = le32_to_cpu(rdev->wb.wb[ring->rptr_offs/4]); |
5596a9db | 290 | else |
78c5560a AD |
291 | rptr = RREG32(ring->rptr_reg); |
292 | ring->rptr = (rptr & ring->ptr_reg_mask) >> ring->ptr_reg_shift; | |
771fe6b9 | 293 | /* This works because ring_size is a power of 2 */ |
e32eb50d CK |
294 | ring->ring_free_dw = (ring->rptr + (ring->ring_size / 4)); |
295 | ring->ring_free_dw -= ring->wptr; | |
296 | ring->ring_free_dw &= ring->ptr_mask; | |
297 | if (!ring->ring_free_dw) { | |
298 | ring->ring_free_dw = ring->ring_size / 4; | |
771fe6b9 JG |
299 | } |
300 | } | |
301 | ||
7b1f2485 | 302 | |
e32eb50d | 303 | int radeon_ring_alloc(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ndw) |
771fe6b9 JG |
304 | { |
305 | int r; | |
306 | ||
307 | /* Align requested size with padding so unlock_commit can | |
308 | * pad safely */ | |
e32eb50d CK |
309 | ndw = (ndw + ring->align_mask) & ~ring->align_mask; |
310 | while (ndw > (ring->ring_free_dw - 1)) { | |
311 | radeon_ring_free_size(rdev, ring); | |
312 | if (ndw < ring->ring_free_dw) { | |
771fe6b9 JG |
313 | break; |
314 | } | |
e32eb50d | 315 | r = radeon_fence_wait_next(rdev, radeon_ring_index(rdev, ring)); |
91700f3c | 316 | if (r) |
771fe6b9 | 317 | return r; |
771fe6b9 | 318 | } |
e32eb50d CK |
319 | ring->count_dw = ndw; |
320 | ring->wptr_old = ring->wptr; | |
771fe6b9 JG |
321 | return 0; |
322 | } | |
323 | ||
e32eb50d | 324 | int radeon_ring_lock(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ndw) |
91700f3c MG |
325 | { |
326 | int r; | |
327 | ||
e32eb50d CK |
328 | mutex_lock(&ring->mutex); |
329 | r = radeon_ring_alloc(rdev, ring, ndw); | |
91700f3c | 330 | if (r) { |
e32eb50d | 331 | mutex_unlock(&ring->mutex); |
91700f3c MG |
332 | return r; |
333 | } | |
334 | return 0; | |
335 | } | |
336 | ||
e32eb50d | 337 | void radeon_ring_commit(struct radeon_device *rdev, struct radeon_ring *ring) |
771fe6b9 JG |
338 | { |
339 | unsigned count_dw_pad; | |
340 | unsigned i; | |
341 | ||
342 | /* We pad to match fetch size */ | |
e32eb50d CK |
343 | count_dw_pad = (ring->align_mask + 1) - |
344 | (ring->wptr & ring->align_mask); | |
771fe6b9 | 345 | for (i = 0; i < count_dw_pad; i++) { |
78c5560a | 346 | radeon_ring_write(ring, ring->nop); |
771fe6b9 JG |
347 | } |
348 | DRM_MEMORYBARRIER(); | |
78c5560a | 349 | WREG32(ring->wptr_reg, (ring->wptr << ring->ptr_reg_shift) & ring->ptr_reg_mask); |
e32eb50d | 350 | (void)RREG32(ring->wptr_reg); |
91700f3c MG |
351 | } |
352 | ||
e32eb50d | 353 | void radeon_ring_unlock_commit(struct radeon_device *rdev, struct radeon_ring *ring) |
91700f3c | 354 | { |
e32eb50d CK |
355 | radeon_ring_commit(rdev, ring); |
356 | mutex_unlock(&ring->mutex); | |
771fe6b9 JG |
357 | } |
358 | ||
e32eb50d | 359 | void radeon_ring_unlock_undo(struct radeon_device *rdev, struct radeon_ring *ring) |
771fe6b9 | 360 | { |
e32eb50d CK |
361 | ring->wptr = ring->wptr_old; |
362 | mutex_unlock(&ring->mutex); | |
771fe6b9 JG |
363 | } |
364 | ||
e32eb50d | 365 | int radeon_ring_init(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ring_size, |
78c5560a AD |
366 | unsigned rptr_offs, unsigned rptr_reg, unsigned wptr_reg, |
367 | u32 ptr_reg_shift, u32 ptr_reg_mask, u32 nop) | |
771fe6b9 JG |
368 | { |
369 | int r; | |
370 | ||
e32eb50d CK |
371 | ring->ring_size = ring_size; |
372 | ring->rptr_offs = rptr_offs; | |
373 | ring->rptr_reg = rptr_reg; | |
374 | ring->wptr_reg = wptr_reg; | |
78c5560a AD |
375 | ring->ptr_reg_shift = ptr_reg_shift; |
376 | ring->ptr_reg_mask = ptr_reg_mask; | |
377 | ring->nop = nop; | |
771fe6b9 | 378 | /* Allocate ring buffer */ |
e32eb50d CK |
379 | if (ring->ring_obj == NULL) { |
380 | r = radeon_bo_create(rdev, ring->ring_size, PAGE_SIZE, true, | |
4c788679 | 381 | RADEON_GEM_DOMAIN_GTT, |
e32eb50d | 382 | &ring->ring_obj); |
771fe6b9 | 383 | if (r) { |
4c788679 | 384 | dev_err(rdev->dev, "(%d) ring create failed\n", r); |
771fe6b9 JG |
385 | return r; |
386 | } | |
e32eb50d | 387 | r = radeon_bo_reserve(ring->ring_obj, false); |
4c788679 JG |
388 | if (unlikely(r != 0)) |
389 | return r; | |
e32eb50d CK |
390 | r = radeon_bo_pin(ring->ring_obj, RADEON_GEM_DOMAIN_GTT, |
391 | &ring->gpu_addr); | |
771fe6b9 | 392 | if (r) { |
e32eb50d | 393 | radeon_bo_unreserve(ring->ring_obj); |
4c788679 | 394 | dev_err(rdev->dev, "(%d) ring pin failed\n", r); |
771fe6b9 JG |
395 | return r; |
396 | } | |
e32eb50d CK |
397 | r = radeon_bo_kmap(ring->ring_obj, |
398 | (void **)&ring->ring); | |
399 | radeon_bo_unreserve(ring->ring_obj); | |
771fe6b9 | 400 | if (r) { |
4c788679 | 401 | dev_err(rdev->dev, "(%d) ring map failed\n", r); |
771fe6b9 JG |
402 | return r; |
403 | } | |
404 | } | |
e32eb50d CK |
405 | ring->ptr_mask = (ring->ring_size / 4) - 1; |
406 | ring->ring_free_dw = ring->ring_size / 4; | |
771fe6b9 JG |
407 | return 0; |
408 | } | |
409 | ||
e32eb50d | 410 | void radeon_ring_fini(struct radeon_device *rdev, struct radeon_ring *ring) |
771fe6b9 | 411 | { |
4c788679 | 412 | int r; |
ca2af923 | 413 | struct radeon_bo *ring_obj; |
4c788679 | 414 | |
e32eb50d CK |
415 | mutex_lock(&ring->mutex); |
416 | ring_obj = ring->ring_obj; | |
417 | ring->ring = NULL; | |
418 | ring->ring_obj = NULL; | |
419 | mutex_unlock(&ring->mutex); | |
ca2af923 AD |
420 | |
421 | if (ring_obj) { | |
422 | r = radeon_bo_reserve(ring_obj, false); | |
4c788679 | 423 | if (likely(r == 0)) { |
ca2af923 AD |
424 | radeon_bo_kunmap(ring_obj); |
425 | radeon_bo_unpin(ring_obj); | |
426 | radeon_bo_unreserve(ring_obj); | |
4c788679 | 427 | } |
ca2af923 | 428 | radeon_bo_unref(&ring_obj); |
771fe6b9 | 429 | } |
771fe6b9 JG |
430 | } |
431 | ||
771fe6b9 JG |
432 | /* |
433 | * Debugfs info | |
434 | */ | |
435 | #if defined(CONFIG_DEBUG_FS) | |
af9720f4 CK |
436 | |
437 | static int radeon_debugfs_ring_info(struct seq_file *m, void *data) | |
438 | { | |
439 | struct drm_info_node *node = (struct drm_info_node *) m->private; | |
440 | struct drm_device *dev = node->minor->dev; | |
441 | struct radeon_device *rdev = dev->dev_private; | |
442 | int ridx = *(int*)node->info_ent->data; | |
443 | struct radeon_ring *ring = &rdev->ring[ridx]; | |
444 | unsigned count, i, j; | |
445 | ||
446 | radeon_ring_free_size(rdev, ring); | |
447 | count = (ring->ring_size / 4) - ring->ring_free_dw; | |
448 | seq_printf(m, "wptr(0x%04x): 0x%08x\n", ring->wptr_reg, RREG32(ring->wptr_reg)); | |
449 | seq_printf(m, "rptr(0x%04x): 0x%08x\n", ring->rptr_reg, RREG32(ring->rptr_reg)); | |
450 | seq_printf(m, "driver's copy of the wptr: 0x%08x\n", ring->wptr); | |
451 | seq_printf(m, "driver's copy of the rptr: 0x%08x\n", ring->rptr); | |
452 | seq_printf(m, "%u free dwords in ring\n", ring->ring_free_dw); | |
453 | seq_printf(m, "%u dwords in ring\n", count); | |
454 | i = ring->rptr; | |
455 | for (j = 0; j <= count; j++) { | |
456 | seq_printf(m, "r[%04d]=0x%08x\n", i, ring->ring[i]); | |
457 | i = (i + 1) & ring->ptr_mask; | |
458 | } | |
459 | return 0; | |
460 | } | |
461 | ||
462 | static int radeon_ring_type_gfx_index = RADEON_RING_TYPE_GFX_INDEX; | |
463 | static int cayman_ring_type_cp1_index = CAYMAN_RING_TYPE_CP1_INDEX; | |
464 | static int cayman_ring_type_cp2_index = CAYMAN_RING_TYPE_CP2_INDEX; | |
465 | ||
466 | static struct drm_info_list radeon_debugfs_ring_info_list[] = { | |
467 | {"radeon_ring_gfx", radeon_debugfs_ring_info, 0, &radeon_ring_type_gfx_index}, | |
468 | {"radeon_ring_cp1", radeon_debugfs_ring_info, 0, &cayman_ring_type_cp1_index}, | |
469 | {"radeon_ring_cp2", radeon_debugfs_ring_info, 0, &cayman_ring_type_cp2_index}, | |
470 | }; | |
471 | ||
771fe6b9 JG |
472 | static int radeon_debugfs_ib_info(struct seq_file *m, void *data) |
473 | { | |
474 | struct drm_info_node *node = (struct drm_info_node *) m->private; | |
475 | struct radeon_ib *ib = node->info_ent->data; | |
476 | unsigned i; | |
477 | ||
478 | if (ib == NULL) { | |
479 | return 0; | |
480 | } | |
91cb91be | 481 | seq_printf(m, "IB %04u\n", ib->idx); |
771fe6b9 JG |
482 | seq_printf(m, "IB fence %p\n", ib->fence); |
483 | seq_printf(m, "IB size %05u dwords\n", ib->length_dw); | |
484 | for (i = 0; i < ib->length_dw; i++) { | |
485 | seq_printf(m, "[%05u]=0x%08X\n", i, ib->ptr[i]); | |
486 | } | |
487 | return 0; | |
488 | } | |
489 | ||
490 | static struct drm_info_list radeon_debugfs_ib_list[RADEON_IB_POOL_SIZE]; | |
491 | static char radeon_debugfs_ib_names[RADEON_IB_POOL_SIZE][32]; | |
492 | #endif | |
493 | ||
af9720f4 CK |
494 | int radeon_debugfs_ring_init(struct radeon_device *rdev) |
495 | { | |
496 | #if defined(CONFIG_DEBUG_FS) | |
497 | return radeon_debugfs_add_files(rdev, radeon_debugfs_ring_info_list, | |
498 | ARRAY_SIZE(radeon_debugfs_ring_info_list)); | |
499 | #else | |
500 | return 0; | |
501 | #endif | |
502 | } | |
503 | ||
771fe6b9 JG |
504 | int radeon_debugfs_ib_init(struct radeon_device *rdev) |
505 | { | |
506 | #if defined(CONFIG_DEBUG_FS) | |
507 | unsigned i; | |
508 | ||
509 | for (i = 0; i < RADEON_IB_POOL_SIZE; i++) { | |
510 | sprintf(radeon_debugfs_ib_names[i], "radeon_ib_%04u", i); | |
511 | radeon_debugfs_ib_list[i].name = radeon_debugfs_ib_names[i]; | |
512 | radeon_debugfs_ib_list[i].show = &radeon_debugfs_ib_info; | |
513 | radeon_debugfs_ib_list[i].driver_features = 0; | |
514 | radeon_debugfs_ib_list[i].data = &rdev->ib_pool.ibs[i]; | |
515 | } | |
516 | return radeon_debugfs_add_files(rdev, radeon_debugfs_ib_list, | |
517 | RADEON_IB_POOL_SIZE); | |
518 | #else | |
519 | return 0; | |
520 | #endif | |
521 | } |