Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 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 |
Jerome Glisse | c507f7e | 2012-05-09 15:34:58 +0200 | [diff] [blame] | 27 | * Christian König |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 28 | */ |
| 29 | #include <linux/seq_file.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 30 | #include <linux/slab.h> |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 31 | #include "drmP.h" |
| 32 | #include "radeon_drm.h" |
| 33 | #include "radeon_reg.h" |
| 34 | #include "radeon.h" |
| 35 | #include "atom.h" |
| 36 | |
Jerome Glisse | c507f7e | 2012-05-09 15:34:58 +0200 | [diff] [blame] | 37 | /* |
| 38 | * IB. |
| 39 | */ |
| 40 | int radeon_debugfs_sa_init(struct radeon_device *rdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 41 | |
Andi Kleen | ce580fa | 2011-10-13 16:08:47 -0700 | [diff] [blame] | 42 | u32 radeon_get_ib_value(struct radeon_cs_parser *p, int idx) |
| 43 | { |
| 44 | struct radeon_cs_chunk *ibc = &p->chunks[p->chunk_ib_idx]; |
| 45 | u32 pg_idx, pg_offset; |
| 46 | u32 idx_value = 0; |
| 47 | int new_page; |
| 48 | |
| 49 | pg_idx = (idx * 4) / PAGE_SIZE; |
| 50 | pg_offset = (idx * 4) % PAGE_SIZE; |
| 51 | |
| 52 | if (ibc->kpage_idx[0] == pg_idx) |
| 53 | return ibc->kpage[0][pg_offset/4]; |
| 54 | if (ibc->kpage_idx[1] == pg_idx) |
| 55 | return ibc->kpage[1][pg_offset/4]; |
| 56 | |
| 57 | new_page = radeon_cs_update_pages(p, pg_idx); |
| 58 | if (new_page < 0) { |
| 59 | p->parser_error = new_page; |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | idx_value = ibc->kpage[new_page][pg_offset/4]; |
| 64 | return idx_value; |
| 65 | } |
| 66 | |
Jerome Glisse | 69e130a | 2011-12-21 12:13:46 -0500 | [diff] [blame] | 67 | int radeon_ib_get(struct radeon_device *rdev, int ring, |
| 68 | struct radeon_ib **ib, unsigned size) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 69 | { |
Jerome Glisse | c507f7e | 2012-05-09 15:34:58 +0200 | [diff] [blame] | 70 | int r; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 71 | |
Jerome Glisse | c507f7e | 2012-05-09 15:34:58 +0200 | [diff] [blame] | 72 | *ib = kmalloc(sizeof(struct radeon_ib), GFP_KERNEL); |
| 73 | if (*ib == NULL) { |
| 74 | return -ENOMEM; |
| 75 | } |
| 76 | r = radeon_sa_bo_new(rdev, &rdev->ring_tmp_bo, &(*ib)->sa_bo, size, 256, true); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 77 | if (r) { |
Jerome Glisse | c507f7e | 2012-05-09 15:34:58 +0200 | [diff] [blame] | 78 | dev_err(rdev->dev, "failed to get a new IB (%d)\n", r); |
| 79 | kfree(*ib); |
| 80 | *ib = NULL; |
| 81 | return r; |
| 82 | } |
| 83 | r = radeon_fence_create(rdev, &(*ib)->fence, ring); |
| 84 | if (r) { |
| 85 | dev_err(rdev->dev, "failed to create fence for new IB (%d)\n", r); |
| 86 | radeon_sa_bo_free(rdev, &(*ib)->sa_bo, NULL); |
| 87 | kfree(*ib); |
| 88 | *ib = NULL; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 89 | return r; |
| 90 | } |
Jerome Glisse | b15ba51 | 2011-11-15 11:48:34 -0500 | [diff] [blame] | 91 | |
Jerome Glisse | c507f7e | 2012-05-09 15:34:58 +0200 | [diff] [blame] | 92 | (*ib)->ptr = radeon_sa_bo_cpu_addr((*ib)->sa_bo); |
| 93 | (*ib)->gpu_addr = radeon_sa_bo_gpu_addr((*ib)->sa_bo); |
| 94 | (*ib)->vm_id = 0; |
| 95 | (*ib)->is_const_ib = false; |
Jerome Glisse | 68470ae | 2012-05-09 15:35:00 +0200 | [diff] [blame] | 96 | (*ib)->semaphore = NULL; |
Jerome Glisse | c507f7e | 2012-05-09 15:34:58 +0200 | [diff] [blame] | 97 | |
| 98 | return 0; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib **ib) |
| 102 | { |
| 103 | struct radeon_ib *tmp = *ib; |
| 104 | |
| 105 | *ib = NULL; |
| 106 | if (tmp == NULL) { |
| 107 | return; |
| 108 | } |
Jerome Glisse | 68470ae | 2012-05-09 15:35:00 +0200 | [diff] [blame] | 109 | radeon_semaphore_free(rdev, tmp->semaphore, tmp->fence); |
Jerome Glisse | c507f7e | 2012-05-09 15:34:58 +0200 | [diff] [blame] | 110 | radeon_sa_bo_free(rdev, &tmp->sa_bo, tmp->fence); |
| 111 | radeon_fence_unref(&tmp->fence); |
| 112 | kfree(tmp); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 113 | } |
| 114 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 115 | int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib) |
| 116 | { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 117 | struct radeon_ring *ring = &rdev->ring[ib->fence->ring]; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 118 | int r = 0; |
| 119 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 120 | if (!ib->length_dw || !ring->ready) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 121 | /* TODO: Nothings in the ib we should report. */ |
Jerome Glisse | c507f7e | 2012-05-09 15:34:58 +0200 | [diff] [blame] | 122 | dev_err(rdev->dev, "couldn't schedule ib\n"); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 123 | return -EINVAL; |
| 124 | } |
Dave Airlie | ecb114a | 2009-09-15 11:12:56 +1000 | [diff] [blame] | 125 | |
Dave Airlie | 6cdf658 | 2009-06-29 18:29:13 +1000 | [diff] [blame] | 126 | /* 64 dwords should be enough for fence too */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 127 | r = radeon_ring_lock(rdev, ring, 64); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 128 | if (r) { |
Jerome Glisse | c507f7e | 2012-05-09 15:34:58 +0200 | [diff] [blame] | 129 | dev_err(rdev->dev, "scheduling IB failed (%d).\n", r); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 130 | return r; |
| 131 | } |
Christian König | 4c87bc2 | 2011-10-19 19:02:21 +0200 | [diff] [blame] | 132 | radeon_ring_ib_execute(rdev, ib->fence->ring, ib); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 133 | radeon_fence_emit(rdev, ib->fence); |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 134 | radeon_ring_unlock_commit(rdev, ring); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | int radeon_ib_pool_init(struct radeon_device *rdev) |
| 139 | { |
Jerome Glisse | c507f7e | 2012-05-09 15:34:58 +0200 | [diff] [blame] | 140 | int r; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 141 | |
Jerome Glisse | c507f7e | 2012-05-09 15:34:58 +0200 | [diff] [blame] | 142 | if (rdev->ib_pool_ready) { |
Jerome Glisse | 9f022dd | 2009-09-11 15:35:22 +0200 | [diff] [blame] | 143 | return 0; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 144 | } |
Jerome Glisse | c507f7e | 2012-05-09 15:34:58 +0200 | [diff] [blame] | 145 | r = radeon_sa_bo_manager_init(rdev, &rdev->ring_tmp_bo, |
Christian König | c3b7fe8 | 2012-05-09 15:34:56 +0200 | [diff] [blame] | 146 | RADEON_IB_POOL_SIZE*64*1024, |
| 147 | RADEON_GEM_DOMAIN_GTT); |
| 148 | if (r) { |
Christian König | c3b7fe8 | 2012-05-09 15:34:56 +0200 | [diff] [blame] | 149 | return r; |
| 150 | } |
Jerome Glisse | c507f7e | 2012-05-09 15:34:58 +0200 | [diff] [blame] | 151 | rdev->ib_pool_ready = true; |
| 152 | if (radeon_debugfs_sa_init(rdev)) { |
| 153 | dev_err(rdev->dev, "failed to register debugfs file for SA\n"); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 154 | } |
Jerome Glisse | b15ba51 | 2011-11-15 11:48:34 -0500 | [diff] [blame] | 155 | return 0; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | void radeon_ib_pool_fini(struct radeon_device *rdev) |
| 159 | { |
Jerome Glisse | c507f7e | 2012-05-09 15:34:58 +0200 | [diff] [blame] | 160 | if (rdev->ib_pool_ready) { |
| 161 | radeon_sa_bo_manager_fini(rdev, &rdev->ring_tmp_bo); |
| 162 | rdev->ib_pool_ready = false; |
Alex Deucher | ca2af92 | 2010-05-06 11:02:24 -0400 | [diff] [blame] | 163 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 164 | } |
| 165 | |
Jerome Glisse | b15ba51 | 2011-11-15 11:48:34 -0500 | [diff] [blame] | 166 | int radeon_ib_pool_start(struct radeon_device *rdev) |
| 167 | { |
Jerome Glisse | c507f7e | 2012-05-09 15:34:58 +0200 | [diff] [blame] | 168 | return radeon_sa_bo_manager_start(rdev, &rdev->ring_tmp_bo); |
Jerome Glisse | b15ba51 | 2011-11-15 11:48:34 -0500 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | int radeon_ib_pool_suspend(struct radeon_device *rdev) |
| 172 | { |
Jerome Glisse | c507f7e | 2012-05-09 15:34:58 +0200 | [diff] [blame] | 173 | return radeon_sa_bo_manager_suspend(rdev, &rdev->ring_tmp_bo); |
Jerome Glisse | b15ba51 | 2011-11-15 11:48:34 -0500 | [diff] [blame] | 174 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 175 | |
Christian König | 7bd560e | 2012-05-02 15:11:12 +0200 | [diff] [blame] | 176 | int radeon_ib_ring_tests(struct radeon_device *rdev) |
| 177 | { |
| 178 | unsigned i; |
| 179 | int r; |
| 180 | |
| 181 | for (i = 0; i < RADEON_NUM_RINGS; ++i) { |
| 182 | struct radeon_ring *ring = &rdev->ring[i]; |
| 183 | |
| 184 | if (!ring->ready) |
| 185 | continue; |
| 186 | |
| 187 | r = radeon_ib_test(rdev, i, ring); |
| 188 | if (r) { |
| 189 | ring->ready = false; |
| 190 | |
| 191 | if (i == RADEON_RING_TYPE_GFX_INDEX) { |
| 192 | /* oh, oh, that's really bad */ |
| 193 | DRM_ERROR("radeon: failed testing IB on GFX ring (%d).\n", r); |
| 194 | rdev->accel_working = false; |
| 195 | return r; |
| 196 | |
| 197 | } else { |
| 198 | /* still not good, but we can live with it */ |
| 199 | DRM_ERROR("radeon: failed testing IB on ring %d (%d).\n", i, r); |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | return 0; |
| 204 | } |
| 205 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 206 | /* |
| 207 | * Ring. |
| 208 | */ |
Jerome Glisse | c507f7e | 2012-05-09 15:34:58 +0200 | [diff] [blame] | 209 | int radeon_debugfs_ring_init(struct radeon_device *rdev, struct radeon_ring *ring); |
| 210 | |
| 211 | void radeon_ring_write(struct radeon_ring *ring, uint32_t v) |
| 212 | { |
| 213 | #if DRM_DEBUG_CODE |
| 214 | if (ring->count_dw <= 0) { |
| 215 | DRM_ERROR("radeon: writting more dword to ring than expected !\n"); |
| 216 | } |
| 217 | #endif |
| 218 | ring->ring[ring->wptr++] = v; |
| 219 | ring->wptr &= ring->ptr_mask; |
| 220 | ring->count_dw--; |
| 221 | ring->ring_free_dw--; |
| 222 | } |
| 223 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 224 | int radeon_ring_index(struct radeon_device *rdev, struct radeon_ring *ring) |
Christian König | bf85279 | 2011-10-13 13:19:22 +0200 | [diff] [blame] | 225 | { |
| 226 | /* r1xx-r5xx only has CP ring */ |
| 227 | if (rdev->family < CHIP_R600) |
| 228 | return RADEON_RING_TYPE_GFX_INDEX; |
| 229 | |
| 230 | if (rdev->family >= CHIP_CAYMAN) { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 231 | if (ring == &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX]) |
Christian König | bf85279 | 2011-10-13 13:19:22 +0200 | [diff] [blame] | 232 | return CAYMAN_RING_TYPE_CP1_INDEX; |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 233 | else if (ring == &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX]) |
Christian König | bf85279 | 2011-10-13 13:19:22 +0200 | [diff] [blame] | 234 | return CAYMAN_RING_TYPE_CP2_INDEX; |
| 235 | } |
| 236 | return RADEON_RING_TYPE_GFX_INDEX; |
| 237 | } |
| 238 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 239 | void radeon_ring_free_size(struct radeon_device *rdev, struct radeon_ring *ring) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 240 | { |
Alex Deucher | 78c5560 | 2011-11-17 14:25:56 -0500 | [diff] [blame] | 241 | u32 rptr; |
| 242 | |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 243 | if (rdev->wb.enabled) |
Alex Deucher | 78c5560 | 2011-11-17 14:25:56 -0500 | [diff] [blame] | 244 | rptr = le32_to_cpu(rdev->wb.wb[ring->rptr_offs/4]); |
Christian König | 5596a9d | 2011-10-13 12:48:45 +0200 | [diff] [blame] | 245 | else |
Alex Deucher | 78c5560 | 2011-11-17 14:25:56 -0500 | [diff] [blame] | 246 | rptr = RREG32(ring->rptr_reg); |
| 247 | ring->rptr = (rptr & ring->ptr_reg_mask) >> ring->ptr_reg_shift; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 248 | /* This works because ring_size is a power of 2 */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 249 | ring->ring_free_dw = (ring->rptr + (ring->ring_size / 4)); |
| 250 | ring->ring_free_dw -= ring->wptr; |
| 251 | ring->ring_free_dw &= ring->ptr_mask; |
| 252 | if (!ring->ring_free_dw) { |
| 253 | ring->ring_free_dw = ring->ring_size / 4; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | |
Christian König | 7b1f248 | 2011-09-23 15:11:23 +0200 | [diff] [blame] | 257 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 258 | int radeon_ring_alloc(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ndw) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 259 | { |
| 260 | int r; |
| 261 | |
| 262 | /* Align requested size with padding so unlock_commit can |
| 263 | * pad safely */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 264 | ndw = (ndw + ring->align_mask) & ~ring->align_mask; |
| 265 | while (ndw > (ring->ring_free_dw - 1)) { |
| 266 | radeon_ring_free_size(rdev, ring); |
| 267 | if (ndw < ring->ring_free_dw) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 268 | break; |
| 269 | } |
Christian König | 8a47cc9 | 2012-05-09 15:34:48 +0200 | [diff] [blame] | 270 | r = radeon_fence_wait_next_locked(rdev, radeon_ring_index(rdev, ring)); |
Matthew Garrett | 91700f3 | 2010-04-30 15:24:17 -0400 | [diff] [blame] | 271 | if (r) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 272 | return r; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 273 | } |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 274 | ring->count_dw = ndw; |
| 275 | ring->wptr_old = ring->wptr; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 276 | return 0; |
| 277 | } |
| 278 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 279 | int radeon_ring_lock(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ndw) |
Matthew Garrett | 91700f3 | 2010-04-30 15:24:17 -0400 | [diff] [blame] | 280 | { |
| 281 | int r; |
| 282 | |
Christian König | d6999bc | 2012-05-09 15:34:45 +0200 | [diff] [blame] | 283 | mutex_lock(&rdev->ring_lock); |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 284 | r = radeon_ring_alloc(rdev, ring, ndw); |
Matthew Garrett | 91700f3 | 2010-04-30 15:24:17 -0400 | [diff] [blame] | 285 | if (r) { |
Christian König | d6999bc | 2012-05-09 15:34:45 +0200 | [diff] [blame] | 286 | mutex_unlock(&rdev->ring_lock); |
Matthew Garrett | 91700f3 | 2010-04-30 15:24:17 -0400 | [diff] [blame] | 287 | return r; |
| 288 | } |
| 289 | return 0; |
| 290 | } |
| 291 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 292 | void radeon_ring_commit(struct radeon_device *rdev, struct radeon_ring *ring) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 293 | { |
| 294 | unsigned count_dw_pad; |
| 295 | unsigned i; |
| 296 | |
| 297 | /* We pad to match fetch size */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 298 | count_dw_pad = (ring->align_mask + 1) - |
| 299 | (ring->wptr & ring->align_mask); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 300 | for (i = 0; i < count_dw_pad; i++) { |
Alex Deucher | 78c5560 | 2011-11-17 14:25:56 -0500 | [diff] [blame] | 301 | radeon_ring_write(ring, ring->nop); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 302 | } |
| 303 | DRM_MEMORYBARRIER(); |
Alex Deucher | 78c5560 | 2011-11-17 14:25:56 -0500 | [diff] [blame] | 304 | WREG32(ring->wptr_reg, (ring->wptr << ring->ptr_reg_shift) & ring->ptr_reg_mask); |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 305 | (void)RREG32(ring->wptr_reg); |
Matthew Garrett | 91700f3 | 2010-04-30 15:24:17 -0400 | [diff] [blame] | 306 | } |
| 307 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 308 | void radeon_ring_unlock_commit(struct radeon_device *rdev, struct radeon_ring *ring) |
Matthew Garrett | 91700f3 | 2010-04-30 15:24:17 -0400 | [diff] [blame] | 309 | { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 310 | radeon_ring_commit(rdev, ring); |
Christian König | d6999bc | 2012-05-09 15:34:45 +0200 | [diff] [blame] | 311 | mutex_unlock(&rdev->ring_lock); |
| 312 | } |
| 313 | |
| 314 | void radeon_ring_undo(struct radeon_ring *ring) |
| 315 | { |
| 316 | ring->wptr = ring->wptr_old; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 317 | } |
| 318 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 319 | void radeon_ring_unlock_undo(struct radeon_device *rdev, struct radeon_ring *ring) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 320 | { |
Christian König | d6999bc | 2012-05-09 15:34:45 +0200 | [diff] [blame] | 321 | radeon_ring_undo(ring); |
| 322 | mutex_unlock(&rdev->ring_lock); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 323 | } |
| 324 | |
Christian König | 7b9ef16 | 2012-05-02 15:11:23 +0200 | [diff] [blame] | 325 | void radeon_ring_force_activity(struct radeon_device *rdev, struct radeon_ring *ring) |
| 326 | { |
| 327 | int r; |
| 328 | |
Christian König | 7b9ef16 | 2012-05-02 15:11:23 +0200 | [diff] [blame] | 329 | radeon_ring_free_size(rdev, ring); |
| 330 | if (ring->rptr == ring->wptr) { |
| 331 | r = radeon_ring_alloc(rdev, ring, 1); |
| 332 | if (!r) { |
| 333 | radeon_ring_write(ring, ring->nop); |
| 334 | radeon_ring_commit(rdev, ring); |
| 335 | } |
| 336 | } |
Christian König | 7b9ef16 | 2012-05-02 15:11:23 +0200 | [diff] [blame] | 337 | } |
| 338 | |
Christian König | 069211e | 2012-05-02 15:11:20 +0200 | [diff] [blame] | 339 | void radeon_ring_lockup_update(struct radeon_ring *ring) |
| 340 | { |
| 341 | ring->last_rptr = ring->rptr; |
| 342 | ring->last_activity = jiffies; |
| 343 | } |
| 344 | |
| 345 | /** |
| 346 | * radeon_ring_test_lockup() - check if ring is lockedup by recording information |
| 347 | * @rdev: radeon device structure |
| 348 | * @ring: radeon_ring structure holding ring information |
| 349 | * |
| 350 | * We don't need to initialize the lockup tracking information as we will either |
| 351 | * have CP rptr to a different value of jiffies wrap around which will force |
| 352 | * initialization of the lockup tracking informations. |
| 353 | * |
| 354 | * A possible false positivie is if we get call after while and last_cp_rptr == |
| 355 | * the current CP rptr, even if it's unlikely it might happen. To avoid this |
| 356 | * if the elapsed time since last call is bigger than 2 second than we return |
| 357 | * false and update the tracking information. Due to this the caller must call |
| 358 | * radeon_ring_test_lockup several time in less than 2sec for lockup to be reported |
| 359 | * the fencing code should be cautious about that. |
| 360 | * |
| 361 | * Caller should write to the ring to force CP to do something so we don't get |
| 362 | * false positive when CP is just gived nothing to do. |
| 363 | * |
| 364 | **/ |
| 365 | bool radeon_ring_test_lockup(struct radeon_device *rdev, struct radeon_ring *ring) |
| 366 | { |
| 367 | unsigned long cjiffies, elapsed; |
| 368 | uint32_t rptr; |
| 369 | |
| 370 | cjiffies = jiffies; |
| 371 | if (!time_after(cjiffies, ring->last_activity)) { |
| 372 | /* likely a wrap around */ |
| 373 | radeon_ring_lockup_update(ring); |
| 374 | return false; |
| 375 | } |
| 376 | rptr = RREG32(ring->rptr_reg); |
| 377 | ring->rptr = (rptr & ring->ptr_reg_mask) >> ring->ptr_reg_shift; |
| 378 | if (ring->rptr != ring->last_rptr) { |
| 379 | /* CP is still working no lockup */ |
| 380 | radeon_ring_lockup_update(ring); |
| 381 | return false; |
| 382 | } |
| 383 | elapsed = jiffies_to_msecs(cjiffies - ring->last_activity); |
Christian König | 3368ff0 | 2012-05-02 15:11:21 +0200 | [diff] [blame] | 384 | if (radeon_lockup_timeout && elapsed >= radeon_lockup_timeout) { |
Christian König | 069211e | 2012-05-02 15:11:20 +0200 | [diff] [blame] | 385 | dev_err(rdev->dev, "GPU lockup CP stall for more than %lumsec\n", elapsed); |
| 386 | return true; |
| 387 | } |
| 388 | /* give a chance to the GPU ... */ |
| 389 | return false; |
| 390 | } |
| 391 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 392 | int radeon_ring_init(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ring_size, |
Alex Deucher | 78c5560 | 2011-11-17 14:25:56 -0500 | [diff] [blame] | 393 | unsigned rptr_offs, unsigned rptr_reg, unsigned wptr_reg, |
| 394 | u32 ptr_reg_shift, u32 ptr_reg_mask, u32 nop) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 395 | { |
| 396 | int r; |
| 397 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 398 | ring->ring_size = ring_size; |
| 399 | ring->rptr_offs = rptr_offs; |
| 400 | ring->rptr_reg = rptr_reg; |
| 401 | ring->wptr_reg = wptr_reg; |
Alex Deucher | 78c5560 | 2011-11-17 14:25:56 -0500 | [diff] [blame] | 402 | ring->ptr_reg_shift = ptr_reg_shift; |
| 403 | ring->ptr_reg_mask = ptr_reg_mask; |
| 404 | ring->nop = nop; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 405 | /* Allocate ring buffer */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 406 | if (ring->ring_obj == NULL) { |
| 407 | r = radeon_bo_create(rdev, ring->ring_size, PAGE_SIZE, true, |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 408 | RADEON_GEM_DOMAIN_GTT, |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 409 | &ring->ring_obj); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 410 | if (r) { |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 411 | dev_err(rdev->dev, "(%d) ring create failed\n", r); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 412 | return r; |
| 413 | } |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 414 | r = radeon_bo_reserve(ring->ring_obj, false); |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 415 | if (unlikely(r != 0)) |
| 416 | return r; |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 417 | r = radeon_bo_pin(ring->ring_obj, RADEON_GEM_DOMAIN_GTT, |
| 418 | &ring->gpu_addr); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 419 | if (r) { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 420 | radeon_bo_unreserve(ring->ring_obj); |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 421 | dev_err(rdev->dev, "(%d) ring pin failed\n", r); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 422 | return r; |
| 423 | } |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 424 | r = radeon_bo_kmap(ring->ring_obj, |
| 425 | (void **)&ring->ring); |
| 426 | radeon_bo_unreserve(ring->ring_obj); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 427 | if (r) { |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 428 | dev_err(rdev->dev, "(%d) ring map failed\n", r); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 429 | return r; |
| 430 | } |
| 431 | } |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 432 | ring->ptr_mask = (ring->ring_size / 4) - 1; |
| 433 | ring->ring_free_dw = ring->ring_size / 4; |
Christian König | ec1a6cc | 2012-05-02 15:11:11 +0200 | [diff] [blame] | 434 | if (radeon_debugfs_ring_init(rdev, ring)) { |
| 435 | DRM_ERROR("Failed to register debugfs file for rings !\n"); |
| 436 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 437 | return 0; |
| 438 | } |
| 439 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 440 | void radeon_ring_fini(struct radeon_device *rdev, struct radeon_ring *ring) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 441 | { |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 442 | int r; |
Alex Deucher | ca2af92 | 2010-05-06 11:02:24 -0400 | [diff] [blame] | 443 | struct radeon_bo *ring_obj; |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 444 | |
Christian König | d6999bc | 2012-05-09 15:34:45 +0200 | [diff] [blame] | 445 | mutex_lock(&rdev->ring_lock); |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 446 | ring_obj = ring->ring_obj; |
Christian König | d6999bc | 2012-05-09 15:34:45 +0200 | [diff] [blame] | 447 | ring->ready = false; |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 448 | ring->ring = NULL; |
| 449 | ring->ring_obj = NULL; |
Christian König | d6999bc | 2012-05-09 15:34:45 +0200 | [diff] [blame] | 450 | mutex_unlock(&rdev->ring_lock); |
Alex Deucher | ca2af92 | 2010-05-06 11:02:24 -0400 | [diff] [blame] | 451 | |
| 452 | if (ring_obj) { |
| 453 | r = radeon_bo_reserve(ring_obj, false); |
| 454 | if (likely(r == 0)) { |
| 455 | radeon_bo_kunmap(ring_obj); |
| 456 | radeon_bo_unpin(ring_obj); |
| 457 | radeon_bo_unreserve(ring_obj); |
| 458 | } |
| 459 | radeon_bo_unref(&ring_obj); |
| 460 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 461 | } |
| 462 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 463 | /* |
| 464 | * Debugfs info |
| 465 | */ |
| 466 | #if defined(CONFIG_DEBUG_FS) |
Christian König | af9720f | 2011-10-24 17:08:44 +0200 | [diff] [blame] | 467 | |
| 468 | static int radeon_debugfs_ring_info(struct seq_file *m, void *data) |
| 469 | { |
| 470 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 471 | struct drm_device *dev = node->minor->dev; |
| 472 | struct radeon_device *rdev = dev->dev_private; |
| 473 | int ridx = *(int*)node->info_ent->data; |
| 474 | struct radeon_ring *ring = &rdev->ring[ridx]; |
| 475 | unsigned count, i, j; |
| 476 | |
| 477 | radeon_ring_free_size(rdev, ring); |
| 478 | count = (ring->ring_size / 4) - ring->ring_free_dw; |
| 479 | seq_printf(m, "wptr(0x%04x): 0x%08x\n", ring->wptr_reg, RREG32(ring->wptr_reg)); |
| 480 | seq_printf(m, "rptr(0x%04x): 0x%08x\n", ring->rptr_reg, RREG32(ring->rptr_reg)); |
| 481 | seq_printf(m, "driver's copy of the wptr: 0x%08x\n", ring->wptr); |
| 482 | seq_printf(m, "driver's copy of the rptr: 0x%08x\n", ring->rptr); |
| 483 | seq_printf(m, "%u free dwords in ring\n", ring->ring_free_dw); |
| 484 | seq_printf(m, "%u dwords in ring\n", count); |
| 485 | i = ring->rptr; |
| 486 | for (j = 0; j <= count; j++) { |
| 487 | seq_printf(m, "r[%04d]=0x%08x\n", i, ring->ring[i]); |
| 488 | i = (i + 1) & ring->ptr_mask; |
| 489 | } |
| 490 | return 0; |
| 491 | } |
| 492 | |
| 493 | static int radeon_ring_type_gfx_index = RADEON_RING_TYPE_GFX_INDEX; |
| 494 | static int cayman_ring_type_cp1_index = CAYMAN_RING_TYPE_CP1_INDEX; |
| 495 | static int cayman_ring_type_cp2_index = CAYMAN_RING_TYPE_CP2_INDEX; |
| 496 | |
| 497 | static struct drm_info_list radeon_debugfs_ring_info_list[] = { |
| 498 | {"radeon_ring_gfx", radeon_debugfs_ring_info, 0, &radeon_ring_type_gfx_index}, |
| 499 | {"radeon_ring_cp1", radeon_debugfs_ring_info, 0, &cayman_ring_type_cp1_index}, |
| 500 | {"radeon_ring_cp2", radeon_debugfs_ring_info, 0, &cayman_ring_type_cp2_index}, |
| 501 | }; |
| 502 | |
Christian König | 711a972 | 2012-05-09 15:34:51 +0200 | [diff] [blame] | 503 | static int radeon_debugfs_sa_info(struct seq_file *m, void *data) |
| 504 | { |
| 505 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 506 | struct drm_device *dev = node->minor->dev; |
| 507 | struct radeon_device *rdev = dev->dev_private; |
| 508 | |
Jerome Glisse | c507f7e | 2012-05-09 15:34:58 +0200 | [diff] [blame] | 509 | radeon_sa_bo_dump_debug_info(&rdev->ring_tmp_bo, m); |
Christian König | 711a972 | 2012-05-09 15:34:51 +0200 | [diff] [blame] | 510 | |
| 511 | return 0; |
| 512 | |
| 513 | } |
| 514 | |
| 515 | static struct drm_info_list radeon_debugfs_sa_list[] = { |
| 516 | {"radeon_sa_info", &radeon_debugfs_sa_info, 0, NULL}, |
| 517 | }; |
| 518 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 519 | #endif |
| 520 | |
Christian König | ec1a6cc | 2012-05-02 15:11:11 +0200 | [diff] [blame] | 521 | int radeon_debugfs_ring_init(struct radeon_device *rdev, struct radeon_ring *ring) |
Christian König | af9720f | 2011-10-24 17:08:44 +0200 | [diff] [blame] | 522 | { |
| 523 | #if defined(CONFIG_DEBUG_FS) |
Christian König | ec1a6cc | 2012-05-02 15:11:11 +0200 | [diff] [blame] | 524 | unsigned i; |
| 525 | for (i = 0; i < ARRAY_SIZE(radeon_debugfs_ring_info_list); ++i) { |
| 526 | struct drm_info_list *info = &radeon_debugfs_ring_info_list[i]; |
| 527 | int ridx = *(int*)radeon_debugfs_ring_info_list[i].data; |
| 528 | unsigned r; |
| 529 | |
| 530 | if (&rdev->ring[ridx] != ring) |
| 531 | continue; |
| 532 | |
| 533 | r = radeon_debugfs_add_files(rdev, info, 1); |
| 534 | if (r) |
| 535 | return r; |
| 536 | } |
Christian König | af9720f | 2011-10-24 17:08:44 +0200 | [diff] [blame] | 537 | #endif |
Christian König | ec1a6cc | 2012-05-02 15:11:11 +0200 | [diff] [blame] | 538 | return 0; |
Christian König | af9720f | 2011-10-24 17:08:44 +0200 | [diff] [blame] | 539 | } |
| 540 | |
Jerome Glisse | c507f7e | 2012-05-09 15:34:58 +0200 | [diff] [blame] | 541 | int radeon_debugfs_sa_init(struct radeon_device *rdev) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 542 | { |
| 543 | #if defined(CONFIG_DEBUG_FS) |
Jerome Glisse | c507f7e | 2012-05-09 15:34:58 +0200 | [diff] [blame] | 544 | return radeon_debugfs_add_files(rdev, radeon_debugfs_sa_list, 1); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 545 | #else |
| 546 | return 0; |
| 547 | #endif |
| 548 | } |