diff options
author | Christian König <christian.koenig@amd.com> | 2014-07-31 07:44:03 -0400 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2014-08-05 08:53:44 -0400 |
commit | f28be8101116c832c94b4473abf193850bf6c931 (patch) | |
tree | 5a9a4193921aee037052b75d846e41c0f70c66dc | |
parent | 3157c5897212997da27ea1a641a246f2a1808cff (diff) |
drm/radeon: separate ring and IB handling
Both on their own are complex enough.
Signed-off-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
-rw-r--r-- | drivers/gpu/drm/radeon/Makefile | 2 | ||||
-rw-r--r-- | drivers/gpu/drm/radeon/radeon_ib.c | 319 | ||||
-rw-r--r-- | drivers/gpu/drm/radeon/radeon_ring.c | 287 |
3 files changed, 320 insertions, 288 deletions
diff --git a/drivers/gpu/drm/radeon/Makefile b/drivers/gpu/drm/radeon/Makefile index 1b0400213756..0013ad0db9ef 100644 --- a/drivers/gpu/drm/radeon/Makefile +++ b/drivers/gpu/drm/radeon/Makefile | |||
@@ -80,7 +80,7 @@ radeon-y += radeon_device.o radeon_asic.o radeon_kms.o \ | |||
80 | r600_dpm.o rs780_dpm.o rv6xx_dpm.o rv770_dpm.o rv730_dpm.o rv740_dpm.o \ | 80 | r600_dpm.o rs780_dpm.o rv6xx_dpm.o rv770_dpm.o rv730_dpm.o rv740_dpm.o \ |
81 | rv770_smc.o cypress_dpm.o btc_dpm.o sumo_dpm.o sumo_smc.o trinity_dpm.o \ | 81 | rv770_smc.o cypress_dpm.o btc_dpm.o sumo_dpm.o sumo_smc.o trinity_dpm.o \ |
82 | trinity_smc.o ni_dpm.o si_smc.o si_dpm.o kv_smc.o kv_dpm.o ci_smc.o \ | 82 | trinity_smc.o ni_dpm.o si_smc.o si_dpm.o kv_smc.o kv_dpm.o ci_smc.o \ |
83 | ci_dpm.o dce6_afmt.o radeon_vm.o radeon_ucode.o | 83 | ci_dpm.o dce6_afmt.o radeon_vm.o radeon_ucode.o radeon_ib.o |
84 | 84 | ||
85 | # add async DMA block | 85 | # add async DMA block |
86 | radeon-y += \ | 86 | radeon-y += \ |
diff --git a/drivers/gpu/drm/radeon/radeon_ib.c b/drivers/gpu/drm/radeon/radeon_ib.c new file mode 100644 index 000000000000..65b0c213488d --- /dev/null +++ b/drivers/gpu/drm/radeon/radeon_ib.c | |||
@@ -0,0 +1,319 @@ | |||
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 | * Christian König | ||
28 | */ | ||
29 | #include <drm/drmP.h> | ||
30 | #include "radeon.h" | ||
31 | |||
32 | /* | ||
33 | * IB | ||
34 | * IBs (Indirect Buffers) and areas of GPU accessible memory where | ||
35 | * commands are stored. You can put a pointer to the IB in the | ||
36 | * command ring and the hw will fetch the commands from the IB | ||
37 | * and execute them. Generally userspace acceleration drivers | ||
38 | * produce command buffers which are send to the kernel and | ||
39 | * put in IBs for execution by the requested ring. | ||
40 | */ | ||
41 | static int radeon_debugfs_sa_init(struct radeon_device *rdev); | ||
42 | |||
43 | /** | ||
44 | * radeon_ib_get - request an IB (Indirect Buffer) | ||
45 | * | ||
46 | * @rdev: radeon_device pointer | ||
47 | * @ring: ring index the IB is associated with | ||
48 | * @ib: IB object returned | ||
49 | * @size: requested IB size | ||
50 | * | ||
51 | * Request an IB (all asics). IBs are allocated using the | ||
52 | * suballocator. | ||
53 | * Returns 0 on success, error on failure. | ||
54 | */ | ||
55 | int radeon_ib_get(struct radeon_device *rdev, int ring, | ||
56 | struct radeon_ib *ib, struct radeon_vm *vm, | ||
57 | unsigned size) | ||
58 | { | ||
59 | int r; | ||
60 | |||
61 | r = radeon_sa_bo_new(rdev, &rdev->ring_tmp_bo, &ib->sa_bo, size, 256); | ||
62 | if (r) { | ||
63 | dev_err(rdev->dev, "failed to get a new IB (%d)\n", r); | ||
64 | return r; | ||
65 | } | ||
66 | |||
67 | r = radeon_semaphore_create(rdev, &ib->semaphore); | ||
68 | if (r) { | ||
69 | return r; | ||
70 | } | ||
71 | |||
72 | ib->ring = ring; | ||
73 | ib->fence = NULL; | ||
74 | ib->ptr = radeon_sa_bo_cpu_addr(ib->sa_bo); | ||
75 | ib->vm = vm; | ||
76 | if (vm) { | ||
77 | /* ib pool is bound at RADEON_VA_IB_OFFSET in virtual address | ||
78 | * space and soffset is the offset inside the pool bo | ||
79 | */ | ||
80 | ib->gpu_addr = ib->sa_bo->soffset + RADEON_VA_IB_OFFSET; | ||
81 | } else { | ||
82 | ib->gpu_addr = radeon_sa_bo_gpu_addr(ib->sa_bo); | ||
83 | } | ||
84 | ib->is_const_ib = false; | ||
85 | |||
86 | return 0; | ||
87 | } | ||
88 | |||
89 | /** | ||
90 | * radeon_ib_free - free an IB (Indirect Buffer) | ||
91 | * | ||
92 | * @rdev: radeon_device pointer | ||
93 | * @ib: IB object to free | ||
94 | * | ||
95 | * Free an IB (all asics). | ||
96 | */ | ||
97 | void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib *ib) | ||
98 | { | ||
99 | radeon_semaphore_free(rdev, &ib->semaphore, ib->fence); | ||
100 | radeon_sa_bo_free(rdev, &ib->sa_bo, ib->fence); | ||
101 | radeon_fence_unref(&ib->fence); | ||
102 | } | ||
103 | |||
104 | /** | ||
105 | * radeon_ib_schedule - schedule an IB (Indirect Buffer) on the ring | ||
106 | * | ||
107 | * @rdev: radeon_device pointer | ||
108 | * @ib: IB object to schedule | ||
109 | * @const_ib: Const IB to schedule (SI only) | ||
110 | * | ||
111 | * Schedule an IB on the associated ring (all asics). | ||
112 | * Returns 0 on success, error on failure. | ||
113 | * | ||
114 | * On SI, there are two parallel engines fed from the primary ring, | ||
115 | * the CE (Constant Engine) and the DE (Drawing Engine). Since | ||
116 | * resource descriptors have moved to memory, the CE allows you to | ||
117 | * prime the caches while the DE is updating register state so that | ||
118 | * the resource descriptors will be already in cache when the draw is | ||
119 | * processed. To accomplish this, the userspace driver submits two | ||
120 | * IBs, one for the CE and one for the DE. If there is a CE IB (called | ||
121 | * a CONST_IB), it will be put on the ring prior to the DE IB. Prior | ||
122 | * to SI there was just a DE IB. | ||
123 | */ | ||
124 | int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib, | ||
125 | struct radeon_ib *const_ib) | ||
126 | { | ||
127 | struct radeon_ring *ring = &rdev->ring[ib->ring]; | ||
128 | int r = 0; | ||
129 | |||
130 | if (!ib->length_dw || !ring->ready) { | ||
131 | /* TODO: Nothings in the ib we should report. */ | ||
132 | dev_err(rdev->dev, "couldn't schedule ib\n"); | ||
133 | return -EINVAL; | ||
134 | } | ||
135 | |||
136 | /* 64 dwords should be enough for fence too */ | ||
137 | r = radeon_ring_lock(rdev, ring, 64 + RADEON_NUM_SYNCS * 8); | ||
138 | if (r) { | ||
139 | dev_err(rdev->dev, "scheduling IB failed (%d).\n", r); | ||
140 | return r; | ||
141 | } | ||
142 | |||
143 | /* grab a vm id if necessary */ | ||
144 | if (ib->vm) { | ||
145 | struct radeon_fence *vm_id_fence; | ||
146 | vm_id_fence = radeon_vm_grab_id(rdev, ib->vm, ib->ring); | ||
147 | radeon_semaphore_sync_to(ib->semaphore, vm_id_fence); | ||
148 | } | ||
149 | |||
150 | /* sync with other rings */ | ||
151 | r = radeon_semaphore_sync_rings(rdev, ib->semaphore, ib->ring); | ||
152 | if (r) { | ||
153 | dev_err(rdev->dev, "failed to sync rings (%d)\n", r); | ||
154 | radeon_ring_unlock_undo(rdev, ring); | ||
155 | return r; | ||
156 | } | ||
157 | |||
158 | if (ib->vm) | ||
159 | radeon_vm_flush(rdev, ib->vm, ib->ring); | ||
160 | |||
161 | if (const_ib) { | ||
162 | radeon_ring_ib_execute(rdev, const_ib->ring, const_ib); | ||
163 | radeon_semaphore_free(rdev, &const_ib->semaphore, NULL); | ||
164 | } | ||
165 | radeon_ring_ib_execute(rdev, ib->ring, ib); | ||
166 | r = radeon_fence_emit(rdev, &ib->fence, ib->ring); | ||
167 | if (r) { | ||
168 | dev_err(rdev->dev, "failed to emit fence for new IB (%d)\n", r); | ||
169 | radeon_ring_unlock_undo(rdev, ring); | ||
170 | return r; | ||
171 | } | ||
172 | if (const_ib) { | ||
173 | const_ib->fence = radeon_fence_ref(ib->fence); | ||
174 | } | ||
175 | |||
176 | if (ib->vm) | ||
177 | radeon_vm_fence(rdev, ib->vm, ib->fence); | ||
178 | |||
179 | radeon_ring_unlock_commit(rdev, ring); | ||
180 | return 0; | ||
181 | } | ||
182 | |||
183 | /** | ||
184 | * radeon_ib_pool_init - Init the IB (Indirect Buffer) pool | ||
185 | * | ||
186 | * @rdev: radeon_device pointer | ||
187 | * | ||
188 | * Initialize the suballocator to manage a pool of memory | ||
189 | * for use as IBs (all asics). | ||
190 | * Returns 0 on success, error on failure. | ||
191 | */ | ||
192 | int radeon_ib_pool_init(struct radeon_device *rdev) | ||
193 | { | ||
194 | int r; | ||
195 | |||
196 | if (rdev->ib_pool_ready) { | ||
197 | return 0; | ||
198 | } | ||
199 | |||
200 | if (rdev->family >= CHIP_BONAIRE) { | ||
201 | r = radeon_sa_bo_manager_init(rdev, &rdev->ring_tmp_bo, | ||
202 | RADEON_IB_POOL_SIZE*64*1024, | ||
203 | RADEON_GPU_PAGE_SIZE, | ||
204 | RADEON_GEM_DOMAIN_GTT, | ||
205 | RADEON_GEM_GTT_WC); | ||
206 | } else { | ||
207 | /* Before CIK, it's better to stick to cacheable GTT due | ||
208 | * to the command stream checking | ||
209 | */ | ||
210 | r = radeon_sa_bo_manager_init(rdev, &rdev->ring_tmp_bo, | ||
211 | RADEON_IB_POOL_SIZE*64*1024, | ||
212 | RADEON_GPU_PAGE_SIZE, | ||
213 | RADEON_GEM_DOMAIN_GTT, 0); | ||
214 | } | ||
215 | if (r) { | ||
216 | return r; | ||
217 | } | ||
218 | |||
219 | r = radeon_sa_bo_manager_start(rdev, &rdev->ring_tmp_bo); | ||
220 | if (r) { | ||
221 | return r; | ||
222 | } | ||
223 | |||
224 | rdev->ib_pool_ready = true; | ||
225 | if (radeon_debugfs_sa_init(rdev)) { | ||
226 | dev_err(rdev->dev, "failed to register debugfs file for SA\n"); | ||
227 | } | ||
228 | return 0; | ||
229 | } | ||
230 | |||
231 | /** | ||
232 | * radeon_ib_pool_fini - Free the IB (Indirect Buffer) pool | ||
233 | * | ||
234 | * @rdev: radeon_device pointer | ||
235 | * | ||
236 | * Tear down the suballocator managing the pool of memory | ||
237 | * for use as IBs (all asics). | ||
238 | */ | ||
239 | void radeon_ib_pool_fini(struct radeon_device *rdev) | ||
240 | { | ||
241 | if (rdev->ib_pool_ready) { | ||
242 | radeon_sa_bo_manager_suspend(rdev, &rdev->ring_tmp_bo); | ||
243 | radeon_sa_bo_manager_fini(rdev, &rdev->ring_tmp_bo); | ||
244 | rdev->ib_pool_ready = false; | ||
245 | } | ||
246 | } | ||
247 | |||
248 | /** | ||
249 | * radeon_ib_ring_tests - test IBs on the rings | ||
250 | * | ||
251 | * @rdev: radeon_device pointer | ||
252 | * | ||
253 | * Test an IB (Indirect Buffer) on each ring. | ||
254 | * If the test fails, disable the ring. | ||
255 | * Returns 0 on success, error if the primary GFX ring | ||
256 | * IB test fails. | ||
257 | */ | ||
258 | int radeon_ib_ring_tests(struct radeon_device *rdev) | ||
259 | { | ||
260 | unsigned i; | ||
261 | int r; | ||
262 | |||
263 | for (i = 0; i < RADEON_NUM_RINGS; ++i) { | ||
264 | struct radeon_ring *ring = &rdev->ring[i]; | ||
265 | |||
266 | if (!ring->ready) | ||
267 | continue; | ||
268 | |||
269 | r = radeon_ib_test(rdev, i, ring); | ||
270 | if (r) { | ||
271 | ring->ready = false; | ||
272 | rdev->needs_reset = false; | ||
273 | |||
274 | if (i == RADEON_RING_TYPE_GFX_INDEX) { | ||
275 | /* oh, oh, that's really bad */ | ||
276 | DRM_ERROR("radeon: failed testing IB on GFX ring (%d).\n", r); | ||
277 | rdev->accel_working = false; | ||
278 | return r; | ||
279 | |||
280 | } else { | ||
281 | /* still not good, but we can live with it */ | ||
282 | DRM_ERROR("radeon: failed testing IB on ring %d (%d).\n", i, r); | ||
283 | } | ||
284 | } | ||
285 | } | ||
286 | return 0; | ||
287 | } | ||
288 | |||
289 | /* | ||
290 | * Debugfs info | ||
291 | */ | ||
292 | #if defined(CONFIG_DEBUG_FS) | ||
293 | |||
294 | static int radeon_debugfs_sa_info(struct seq_file *m, void *data) | ||
295 | { | ||
296 | struct drm_info_node *node = (struct drm_info_node *) m->private; | ||
297 | struct drm_device *dev = node->minor->dev; | ||
298 | struct radeon_device *rdev = dev->dev_private; | ||
299 | |||
300 | radeon_sa_bo_dump_debug_info(&rdev->ring_tmp_bo, m); | ||
301 | |||
302 | return 0; | ||
303 | |||
304 | } | ||
305 | |||
306 | static struct drm_info_list radeon_debugfs_sa_list[] = { | ||
307 | {"radeon_sa_info", &radeon_debugfs_sa_info, 0, NULL}, | ||
308 | }; | ||
309 | |||
310 | #endif | ||
311 | |||
312 | static int radeon_debugfs_sa_init(struct radeon_device *rdev) | ||
313 | { | ||
314 | #if defined(CONFIG_DEBUG_FS) | ||
315 | return radeon_debugfs_add_files(rdev, radeon_debugfs_sa_list, 1); | ||
316 | #else | ||
317 | return 0; | ||
318 | #endif | ||
319 | } | ||
diff --git a/drivers/gpu/drm/radeon/radeon_ring.c b/drivers/gpu/drm/radeon/radeon_ring.c index 20b0e4faf7ae..9c86ac947275 100644 --- a/drivers/gpu/drm/radeon/radeon_ring.c +++ b/drivers/gpu/drm/radeon/radeon_ring.c | |||
@@ -26,270 +26,8 @@ | |||
26 | * Jerome Glisse | 26 | * Jerome Glisse |
27 | * Christian König | 27 | * Christian König |
28 | */ | 28 | */ |
29 | #include <linux/seq_file.h> | ||
30 | #include <linux/slab.h> | ||
31 | #include <drm/drmP.h> | 29 | #include <drm/drmP.h> |
32 | #include <drm/radeon_drm.h> | ||
33 | #include "radeon_reg.h" | ||
34 | #include "radeon.h" | 30 | #include "radeon.h" |
35 | #include "atom.h" | ||
36 | |||
37 | /* | ||
38 | * IB | ||
39 | * IBs (Indirect Buffers) and areas of GPU accessible memory where | ||
40 | * commands are stored. You can put a pointer to the IB in the | ||
41 | * command ring and the hw will fetch the commands from the IB | ||
42 | * and execute them. Generally userspace acceleration drivers | ||
43 | * produce command buffers which are send to the kernel and | ||
44 | * put in IBs for execution by the requested ring. | ||
45 | */ | ||
46 | static int radeon_debugfs_sa_init(struct radeon_device *rdev); | ||
47 | |||
48 | /** | ||
49 | * radeon_ib_get - request an IB (Indirect Buffer) | ||
50 | * | ||
51 | * @rdev: radeon_device pointer | ||
52 | * @ring: ring index the IB is associated with | ||
53 | * @ib: IB object returned | ||
54 | * @size: requested IB size | ||
55 | * | ||
56 | * Request an IB (all asics). IBs are allocated using the | ||
57 | * suballocator. | ||
58 | * Returns 0 on success, error on failure. | ||
59 | */ | ||
60 | int radeon_ib_get(struct radeon_device *rdev, int ring, | ||
61 | struct radeon_ib *ib, struct radeon_vm *vm, | ||
62 | unsigned size) | ||
63 | { | ||
64 | int r; | ||
65 | |||
66 | r = radeon_sa_bo_new(rdev, &rdev->ring_tmp_bo, &ib->sa_bo, size, 256); | ||
67 | if (r) { | ||
68 | dev_err(rdev->dev, "failed to get a new IB (%d)\n", r); | ||
69 | return r; | ||
70 | } | ||
71 | |||
72 | r = radeon_semaphore_create(rdev, &ib->semaphore); | ||
73 | if (r) { | ||
74 | return r; | ||
75 | } | ||
76 | |||
77 | ib->ring = ring; | ||
78 | ib->fence = NULL; | ||
79 | ib->ptr = radeon_sa_bo_cpu_addr(ib->sa_bo); | ||
80 | ib->vm = vm; | ||
81 | if (vm) { | ||
82 | /* ib pool is bound at RADEON_VA_IB_OFFSET in virtual address | ||
83 | * space and soffset is the offset inside the pool bo | ||
84 | */ | ||
85 | ib->gpu_addr = ib->sa_bo->soffset + RADEON_VA_IB_OFFSET; | ||
86 | } else { | ||
87 | ib->gpu_addr = radeon_sa_bo_gpu_addr(ib->sa_bo); | ||
88 | } | ||
89 | ib->is_const_ib = false; | ||
90 | |||
91 | return 0; | ||
92 | } | ||
93 | |||
94 | /** | ||
95 | * radeon_ib_free - free an IB (Indirect Buffer) | ||
96 | * | ||
97 | * @rdev: radeon_device pointer | ||
98 | * @ib: IB object to free | ||
99 | * | ||
100 | * Free an IB (all asics). | ||
101 | */ | ||
102 | void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib *ib) | ||
103 | { | ||
104 | radeon_semaphore_free(rdev, &ib->semaphore, ib->fence); | ||
105 | radeon_sa_bo_free(rdev, &ib->sa_bo, ib->fence); | ||
106 | radeon_fence_unref(&ib->fence); | ||
107 | } | ||
108 | |||
109 | /** | ||
110 | * radeon_ib_schedule - schedule an IB (Indirect Buffer) on the ring | ||
111 | * | ||
112 | * @rdev: radeon_device pointer | ||
113 | * @ib: IB object to schedule | ||
114 | * @const_ib: Const IB to schedule (SI only) | ||
115 | * | ||
116 | * Schedule an IB on the associated ring (all asics). | ||
117 | * Returns 0 on success, error on failure. | ||
118 | * | ||
119 | * On SI, there are two parallel engines fed from the primary ring, | ||
120 | * the CE (Constant Engine) and the DE (Drawing Engine). Since | ||
121 | * resource descriptors have moved to memory, the CE allows you to | ||
122 | * prime the caches while the DE is updating register state so that | ||
123 | * the resource descriptors will be already in cache when the draw is | ||
124 | * processed. To accomplish this, the userspace driver submits two | ||
125 | * IBs, one for the CE and one for the DE. If there is a CE IB (called | ||
126 | * a CONST_IB), it will be put on the ring prior to the DE IB. Prior | ||
127 | * to SI there was just a DE IB. | ||
128 | */ | ||
129 | int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib, | ||
130 | struct radeon_ib *const_ib) | ||
131 | { | ||
132 | struct radeon_ring *ring = &rdev->ring[ib->ring]; | ||
133 | int r = 0; | ||
134 | |||
135 | if (!ib->length_dw || !ring->ready) { | ||
136 | /* TODO: Nothings in the ib we should report. */ | ||
137 | dev_err(rdev->dev, "couldn't schedule ib\n"); | ||
138 | return -EINVAL; | ||
139 | } | ||
140 | |||
141 | /* 64 dwords should be enough for fence too */ | ||
142 | r = radeon_ring_lock(rdev, ring, 64 + RADEON_NUM_SYNCS * 8); | ||
143 | if (r) { | ||
144 | dev_err(rdev->dev, "scheduling IB failed (%d).\n", r); | ||
145 | return r; | ||
146 | } | ||
147 | |||
148 | /* grab a vm id if necessary */ | ||
149 | if (ib->vm) { | ||
150 | struct radeon_fence *vm_id_fence; | ||
151 | vm_id_fence = radeon_vm_grab_id(rdev, ib->vm, ib->ring); | ||
152 | radeon_semaphore_sync_to(ib->semaphore, vm_id_fence); | ||
153 | } | ||
154 | |||
155 | /* sync with other rings */ | ||
156 | r = radeon_semaphore_sync_rings(rdev, ib->semaphore, ib->ring); | ||
157 | if (r) { | ||
158 | dev_err(rdev->dev, "failed to sync rings (%d)\n", r); | ||
159 | radeon_ring_unlock_undo(rdev, ring); | ||
160 | return r; | ||
161 | } | ||
162 | |||
163 | if (ib->vm) | ||
164 | radeon_vm_flush(rdev, ib->vm, ib->ring); | ||
165 | |||
166 | if (const_ib) { | ||
167 | radeon_ring_ib_execute(rdev, const_ib->ring, const_ib); | ||
168 | radeon_semaphore_free(rdev, &const_ib->semaphore, NULL); | ||
169 | } | ||
170 | radeon_ring_ib_execute(rdev, ib->ring, ib); | ||
171 | r = radeon_fence_emit(rdev, &ib->fence, ib->ring); | ||
172 | if (r) { | ||
173 | dev_err(rdev->dev, "failed to emit fence for new IB (%d)\n", r); | ||
174 | radeon_ring_unlock_undo(rdev, ring); | ||
175 | return r; | ||
176 | } | ||
177 | if (const_ib) { | ||
178 | const_ib->fence = radeon_fence_ref(ib->fence); | ||
179 | } | ||
180 | |||
181 | if (ib->vm) | ||
182 | radeon_vm_fence(rdev, ib->vm, ib->fence); | ||
183 | |||
184 | radeon_ring_unlock_commit(rdev, ring); | ||
185 | return 0; | ||
186 | } | ||
187 | |||
188 | /** | ||
189 | * radeon_ib_pool_init - Init the IB (Indirect Buffer) pool | ||
190 | * | ||
191 | * @rdev: radeon_device pointer | ||
192 | * | ||
193 | * Initialize the suballocator to manage a pool of memory | ||
194 | * for use as IBs (all asics). | ||
195 | * Returns 0 on success, error on failure. | ||
196 | */ | ||
197 | int radeon_ib_pool_init(struct radeon_device *rdev) | ||
198 | { | ||
199 | int r; | ||
200 | |||
201 | if (rdev->ib_pool_ready) { | ||
202 | return 0; | ||
203 | } | ||
204 | |||
205 | if (rdev->family >= CHIP_BONAIRE) { | ||
206 | r = radeon_sa_bo_manager_init(rdev, &rdev->ring_tmp_bo, | ||
207 | RADEON_IB_POOL_SIZE*64*1024, | ||
208 | RADEON_GPU_PAGE_SIZE, | ||
209 | RADEON_GEM_DOMAIN_GTT, | ||
210 | RADEON_GEM_GTT_WC); | ||
211 | } else { | ||
212 | /* Before CIK, it's better to stick to cacheable GTT due | ||
213 | * to the command stream checking | ||
214 | */ | ||
215 | r = radeon_sa_bo_manager_init(rdev, &rdev->ring_tmp_bo, | ||
216 | RADEON_IB_POOL_SIZE*64*1024, | ||
217 | RADEON_GPU_PAGE_SIZE, | ||
218 | RADEON_GEM_DOMAIN_GTT, 0); | ||
219 | } | ||
220 | if (r) { | ||
221 | return r; | ||
222 | } | ||
223 | |||
224 | r = radeon_sa_bo_manager_start(rdev, &rdev->ring_tmp_bo); | ||
225 | if (r) { | ||
226 | return r; | ||
227 | } | ||
228 | |||
229 | rdev->ib_pool_ready = true; | ||
230 | if (radeon_debugfs_sa_init(rdev)) { | ||
231 | dev_err(rdev->dev, "failed to register debugfs file for SA\n"); | ||
232 | } | ||
233 | return 0; | ||
234 | } | ||
235 | |||
236 | /** | ||
237 | * radeon_ib_pool_fini - Free the IB (Indirect Buffer) pool | ||
238 | * | ||
239 | * @rdev: radeon_device pointer | ||
240 | * | ||
241 | * Tear down the suballocator managing the pool of memory | ||
242 | * for use as IBs (all asics). | ||
243 | */ | ||
244 | void radeon_ib_pool_fini(struct radeon_device *rdev) | ||
245 | { | ||
246 | if (rdev->ib_pool_ready) { | ||
247 | radeon_sa_bo_manager_suspend(rdev, &rdev->ring_tmp_bo); | ||
248 | radeon_sa_bo_manager_fini(rdev, &rdev->ring_tmp_bo); | ||
249 | rdev->ib_pool_ready = false; | ||
250 | } | ||
251 | } | ||
252 | |||
253 | /** | ||
254 | * radeon_ib_ring_tests - test IBs on the rings | ||
255 | * | ||
256 | * @rdev: radeon_device pointer | ||
257 | * | ||
258 | * Test an IB (Indirect Buffer) on each ring. | ||
259 | * If the test fails, disable the ring. | ||
260 | * Returns 0 on success, error if the primary GFX ring | ||
261 | * IB test fails. | ||
262 | */ | ||
263 | int radeon_ib_ring_tests(struct radeon_device *rdev) | ||
264 | { | ||
265 | unsigned i; | ||
266 | int r; | ||
267 | |||
268 | for (i = 0; i < RADEON_NUM_RINGS; ++i) { | ||
269 | struct radeon_ring *ring = &rdev->ring[i]; | ||
270 | |||
271 | if (!ring->ready) | ||
272 | continue; | ||
273 | |||
274 | r = radeon_ib_test(rdev, i, ring); | ||
275 | if (r) { | ||
276 | ring->ready = false; | ||
277 | rdev->needs_reset = false; | ||
278 | |||
279 | if (i == RADEON_RING_TYPE_GFX_INDEX) { | ||
280 | /* oh, oh, that's really bad */ | ||
281 | DRM_ERROR("radeon: failed testing IB on GFX ring (%d).\n", r); | ||
282 | rdev->accel_working = false; | ||
283 | return r; | ||
284 | |||
285 | } else { | ||
286 | /* still not good, but we can live with it */ | ||
287 | DRM_ERROR("radeon: failed testing IB on ring %d (%d).\n", i, r); | ||
288 | } | ||
289 | } | ||
290 | } | ||
291 | return 0; | ||
292 | } | ||
293 | 31 | ||
294 | /* | 32 | /* |
295 | * Rings | 33 | * Rings |
@@ -805,22 +543,6 @@ static struct drm_info_list radeon_debugfs_ring_info_list[] = { | |||
805 | {"radeon_ring_vce2", radeon_debugfs_ring_info, 0, &si_vce2_index}, | 543 | {"radeon_ring_vce2", radeon_debugfs_ring_info, 0, &si_vce2_index}, |
806 | }; | 544 | }; |
807 | 545 | ||
808 | static int radeon_debugfs_sa_info(struct seq_file *m, void *data) | ||
809 | { | ||
810 | struct drm_info_node *node = (struct drm_info_node *) m->private; | ||
811 | struct drm_device *dev = node->minor->dev; | ||
812 | struct radeon_device *rdev = dev->dev_private; | ||
813 | |||
814 | radeon_sa_bo_dump_debug_info(&rdev->ring_tmp_bo, m); | ||
815 | |||
816 | return 0; | ||
817 | |||
818 | } | ||
819 | |||
820 | static struct drm_info_list radeon_debugfs_sa_list[] = { | ||
821 | {"radeon_sa_info", &radeon_debugfs_sa_info, 0, NULL}, | ||
822 | }; | ||
823 | |||
824 | #endif | 546 | #endif |
825 | 547 | ||
826 | static int radeon_debugfs_ring_init(struct radeon_device *rdev, struct radeon_ring *ring) | 548 | static int radeon_debugfs_ring_init(struct radeon_device *rdev, struct radeon_ring *ring) |
@@ -842,12 +564,3 @@ static int radeon_debugfs_ring_init(struct radeon_device *rdev, struct radeon_ri | |||
842 | #endif | 564 | #endif |
843 | return 0; | 565 | return 0; |
844 | } | 566 | } |
845 | |||
846 | static int radeon_debugfs_sa_init(struct radeon_device *rdev) | ||
847 | { | ||
848 | #if defined(CONFIG_DEBUG_FS) | ||
849 | return radeon_debugfs_add_files(rdev, radeon_debugfs_sa_list, 1); | ||
850 | #else | ||
851 | return 0; | ||
852 | #endif | ||
853 | } | ||