hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
....@@ -28,12 +28,16 @@
2828 */
2929 #include <linux/seq_file.h>
3030 #include <linux/slab.h>
31
-#include <drm/drmP.h>
31
+
3232 #include <drm/amdgpu_drm.h>
33
+#include <drm/drm_debugfs.h>
34
+
3335 #include "amdgpu.h"
3436 #include "atom.h"
37
+#include "amdgpu_trace.h"
3538
3639 #define AMDGPU_IB_TEST_TIMEOUT msecs_to_jiffies(1000)
40
+#define AMDGPU_IB_TEST_GFX_XGMI_TIMEOUT msecs_to_jiffies(2000)
3741
3842 /*
3943 * IB
....@@ -44,7 +48,6 @@
4448 * produce command buffers which are send to the kernel and
4549 * put in IBs for execution by the requested ring.
4650 */
47
-static int amdgpu_debugfs_sa_init(struct amdgpu_device *adev);
4851
4952 /**
5053 * amdgpu_ib_get - request an IB (Indirect Buffer)
....@@ -58,12 +61,13 @@
5861 * Returns 0 on success, error on failure.
5962 */
6063 int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
61
- unsigned size, struct amdgpu_ib *ib)
64
+ unsigned size, enum amdgpu_ib_pool_type pool_type,
65
+ struct amdgpu_ib *ib)
6266 {
6367 int r;
6468
6569 if (size) {
66
- r = amdgpu_sa_bo_new(&adev->ring_tmp_bo,
70
+ r = amdgpu_sa_bo_new(&adev->ib_pools[pool_type],
6771 &ib->sa_bo, size, 256);
6872 if (r) {
6973 dev_err(adev->dev, "failed to get a new IB (%d)\n", r);
....@@ -71,6 +75,8 @@
7175 }
7276
7377 ib->ptr = amdgpu_sa_bo_cpu_addr(ib->sa_bo);
78
+ /* flush the cache before commit the IB */
79
+ ib->flags = AMDGPU_IB_FLAG_EMIT_MEM_SYNC;
7480
7581 if (!vm)
7682 ib->gpu_addr = amdgpu_sa_bo_gpu_addr(ib->sa_bo);
....@@ -122,12 +128,13 @@
122128 struct amdgpu_device *adev = ring->adev;
123129 struct amdgpu_ib *ib = &ibs[0];
124130 struct dma_fence *tmp = NULL;
125
- bool skip_preamble, need_ctx_switch;
131
+ bool need_ctx_switch;
126132 unsigned patch_offset = ~0;
127133 struct amdgpu_vm *vm;
128134 uint64_t fence_ctx;
129135 uint32_t status = 0, alloc_size;
130136 unsigned fence_flags = 0;
137
+ bool secure;
131138
132139 unsigned i;
133140 int r = 0;
....@@ -146,13 +153,19 @@
146153 fence_ctx = 0;
147154 }
148155
149
- if (!ring->ready) {
156
+ if (!ring->sched.ready) {
150157 dev_err(adev->dev, "couldn't schedule ib on ring <%s>\n", ring->name);
151158 return -EINVAL;
152159 }
153160
154161 if (vm && !job->vmid) {
155162 dev_err(adev->dev, "VM IB without ID\n");
163
+ return -EINVAL;
164
+ }
165
+
166
+ if ((ib->flags & AMDGPU_IB_FLAGS_SECURE) &&
167
+ (ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE)) {
168
+ dev_err(adev->dev, "secure submissions not supported on compute rings\n");
156169 return -EINVAL;
157170 }
158171
....@@ -167,12 +180,19 @@
167180
168181 need_ctx_switch = ring->current_ctx != fence_ctx;
169182 if (ring->funcs->emit_pipeline_sync && job &&
170
- ((tmp = amdgpu_sync_get_fence(&job->sched_sync, NULL)) ||
183
+ ((tmp = amdgpu_sync_get_fence(&job->sched_sync)) ||
171184 (amdgpu_sriov_vf(adev) && need_ctx_switch) ||
172185 amdgpu_vm_need_pipeline_sync(ring, job))) {
173186 need_pipe_sync = true;
187
+
188
+ if (tmp)
189
+ trace_amdgpu_ib_pipe_sync(job, tmp);
190
+
174191 dma_fence_put(tmp);
175192 }
193
+
194
+ if ((ib->flags & AMDGPU_IB_FLAG_EMIT_MEM_SYNC) && ring->funcs->emit_mem_sync)
195
+ ring->funcs->emit_mem_sync(ring);
176196
177197 if (ring->funcs->insert_start)
178198 ring->funcs->insert_start(ring);
....@@ -198,32 +218,40 @@
198218 amdgpu_asic_flush_hdp(adev, ring);
199219 }
200220
201
- skip_preamble = ring->current_ctx == fence_ctx;
202
- if (job && ring->funcs->emit_cntxcntl) {
203
- if (need_ctx_switch)
204
- status |= AMDGPU_HAVE_CTX_SWITCH;
205
- status |= job->preamble_status;
221
+ if (need_ctx_switch)
222
+ status |= AMDGPU_HAVE_CTX_SWITCH;
206223
224
+ if (job && ring->funcs->emit_cntxcntl) {
225
+ status |= job->preamble_status;
226
+ status |= job->preemption_status;
207227 amdgpu_ring_emit_cntxcntl(ring, status);
228
+ }
229
+
230
+ /* Setup initial TMZiness and send it off.
231
+ */
232
+ secure = false;
233
+ if (job && ring->funcs->emit_frame_cntl) {
234
+ secure = ib->flags & AMDGPU_IB_FLAGS_SECURE;
235
+ amdgpu_ring_emit_frame_cntl(ring, true, secure);
208236 }
209237
210238 for (i = 0; i < num_ibs; ++i) {
211239 ib = &ibs[i];
212240
213
- /* drop preamble IBs if we don't have a context switch */
214
- if ((ib->flags & AMDGPU_IB_FLAG_PREAMBLE) &&
215
- skip_preamble &&
216
- !(status & AMDGPU_PREAMBLE_IB_PRESENT_FIRST) &&
217
- !amdgpu_sriov_vf(adev)) /* for SRIOV preemption, Preamble CE ib must be inserted anyway */
218
- continue;
241
+ if (job && ring->funcs->emit_frame_cntl) {
242
+ if (secure != !!(ib->flags & AMDGPU_IB_FLAGS_SECURE)) {
243
+ amdgpu_ring_emit_frame_cntl(ring, false, secure);
244
+ secure = !secure;
245
+ amdgpu_ring_emit_frame_cntl(ring, true, secure);
246
+ }
247
+ }
219248
220
- amdgpu_ring_emit_ib(ring, ib, job ? job->vmid : 0,
221
- need_ctx_switch);
222
- need_ctx_switch = false;
249
+ amdgpu_ring_emit_ib(ring, job, ib, status);
250
+ status &= ~AMDGPU_HAVE_CTX_SWITCH;
223251 }
224252
225
- if (ring->funcs->emit_tmz)
226
- amdgpu_ring_emit_tmz(ring, false);
253
+ if (job && ring->funcs->emit_frame_cntl)
254
+ amdgpu_ring_emit_frame_cntl(ring, false, secure);
227255
228256 #ifdef CONFIG_X86_64
229257 if (!(adev->flags & AMD_IS_APU))
....@@ -272,24 +300,32 @@
272300 */
273301 int amdgpu_ib_pool_init(struct amdgpu_device *adev)
274302 {
275
- int r;
303
+ unsigned size;
304
+ int r, i;
276305
277
- if (adev->ib_pool_ready) {
306
+ if (adev->ib_pool_ready)
278307 return 0;
279
- }
280
- r = amdgpu_sa_bo_manager_init(adev, &adev->ring_tmp_bo,
281
- AMDGPU_IB_POOL_SIZE*64*1024,
282
- AMDGPU_GPU_PAGE_SIZE,
283
- AMDGPU_GEM_DOMAIN_GTT);
284
- if (r) {
285
- return r;
286
- }
287308
288
- adev->ib_pool_ready = true;
289
- if (amdgpu_debugfs_sa_init(adev)) {
290
- dev_err(adev->dev, "failed to register debugfs file for SA\n");
309
+ for (i = 0; i < AMDGPU_IB_POOL_MAX; i++) {
310
+ if (i == AMDGPU_IB_POOL_DIRECT)
311
+ size = PAGE_SIZE * 2;
312
+ else
313
+ size = AMDGPU_IB_POOL_SIZE;
314
+
315
+ r = amdgpu_sa_bo_manager_init(adev, &adev->ib_pools[i],
316
+ size, AMDGPU_GPU_PAGE_SIZE,
317
+ AMDGPU_GEM_DOMAIN_GTT);
318
+ if (r)
319
+ goto error;
291320 }
321
+ adev->ib_pool_ready = true;
322
+
292323 return 0;
324
+
325
+error:
326
+ while (i--)
327
+ amdgpu_sa_bo_manager_fini(adev, &adev->ib_pools[i]);
328
+ return r;
293329 }
294330
295331 /**
....@@ -302,10 +338,14 @@
302338 */
303339 void amdgpu_ib_pool_fini(struct amdgpu_device *adev)
304340 {
305
- if (adev->ib_pool_ready) {
306
- amdgpu_sa_bo_manager_fini(adev, &adev->ring_tmp_bo);
307
- adev->ib_pool_ready = false;
308
- }
341
+ int i;
342
+
343
+ if (!adev->ib_pool_ready)
344
+ return;
345
+
346
+ for (i = 0; i < AMDGPU_IB_POOL_MAX; i++)
347
+ amdgpu_sa_bo_manager_fini(adev, &adev->ib_pools[i]);
348
+ adev->ib_pool_ready = false;
309349 }
310350
311351 /**
....@@ -320,9 +360,9 @@
320360 */
321361 int amdgpu_ib_ring_tests(struct amdgpu_device *adev)
322362 {
323
- unsigned i;
324
- int r, ret = 0;
325363 long tmo_gfx, tmo_mm;
364
+ int r, ret = 0;
365
+ unsigned i;
326366
327367 tmo_mm = tmo_gfx = AMDGPU_IB_TEST_TIMEOUT;
328368 if (amdgpu_sriov_vf(adev)) {
....@@ -341,13 +381,18 @@
341381 * cost waiting for it coming back under RUNTIME only
342382 */
343383 tmo_gfx = 8 * AMDGPU_IB_TEST_TIMEOUT;
384
+ } else if (adev->gmc.xgmi.hive_id) {
385
+ tmo_gfx = AMDGPU_IB_TEST_GFX_XGMI_TIMEOUT;
344386 }
345387
346
- for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
388
+ for (i = 0; i < adev->num_rings; ++i) {
347389 struct amdgpu_ring *ring = adev->rings[i];
348390 long tmo;
349391
350
- if (!ring || !ring->ready)
392
+ /* KIQ rings don't have an IB test because we never submit IBs
393
+ * to them and they have no interrupt support.
394
+ */
395
+ if (!ring->sched.ready || !ring->funcs->test_ib)
351396 continue;
352397
353398 /* MM engine need more time */
....@@ -362,20 +407,23 @@
362407 tmo = tmo_gfx;
363408
364409 r = amdgpu_ring_test_ib(ring, tmo);
365
- if (r) {
366
- ring->ready = false;
410
+ if (!r) {
411
+ DRM_DEV_DEBUG(adev->dev, "ib test on %s succeeded\n",
412
+ ring->name);
413
+ continue;
414
+ }
367415
368
- if (ring == &adev->gfx.gfx_ring[0]) {
369
- /* oh, oh, that's really bad */
370
- DRM_ERROR("amdgpu: failed testing IB on GFX ring (%d).\n", r);
371
- adev->accel_working = false;
372
- return r;
416
+ ring->sched.ready = false;
417
+ DRM_DEV_ERROR(adev->dev, "IB test failed on %s (%d).\n",
418
+ ring->name, r);
373419
374
- } else {
375
- /* still not good, but we can live with it */
376
- DRM_ERROR("amdgpu: failed testing IB on ring %d (%d).\n", i, r);
377
- ret = r;
378
- }
420
+ if (ring == &adev->gfx.gfx_ring[0]) {
421
+ /* oh, oh, that's really bad */
422
+ adev->accel_working = false;
423
+ return r;
424
+
425
+ } else {
426
+ ret = r;
379427 }
380428 }
381429 return ret;
....@@ -390,12 +438,18 @@
390438 {
391439 struct drm_info_node *node = (struct drm_info_node *) m->private;
392440 struct drm_device *dev = node->minor->dev;
393
- struct amdgpu_device *adev = dev->dev_private;
441
+ struct amdgpu_device *adev = drm_to_adev(dev);
394442
395
- amdgpu_sa_bo_dump_debug_info(&adev->ring_tmp_bo, m);
443
+ seq_printf(m, "--------------------- DELAYED --------------------- \n");
444
+ amdgpu_sa_bo_dump_debug_info(&adev->ib_pools[AMDGPU_IB_POOL_DELAYED],
445
+ m);
446
+ seq_printf(m, "-------------------- IMMEDIATE -------------------- \n");
447
+ amdgpu_sa_bo_dump_debug_info(&adev->ib_pools[AMDGPU_IB_POOL_IMMEDIATE],
448
+ m);
449
+ seq_printf(m, "--------------------- DIRECT ---------------------- \n");
450
+ amdgpu_sa_bo_dump_debug_info(&adev->ib_pools[AMDGPU_IB_POOL_DIRECT], m);
396451
397452 return 0;
398
-
399453 }
400454
401455 static const struct drm_info_list amdgpu_debugfs_sa_list[] = {
....@@ -404,10 +458,11 @@
404458
405459 #endif
406460
407
-static int amdgpu_debugfs_sa_init(struct amdgpu_device *adev)
461
+int amdgpu_debugfs_sa_init(struct amdgpu_device *adev)
408462 {
409463 #if defined(CONFIG_DEBUG_FS)
410
- return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_sa_list, 1);
464
+ return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_sa_list,
465
+ ARRAY_SIZE(amdgpu_debugfs_sa_list));
411466 #else
412467 return 0;
413468 #endif