| @@ -1325,33 +1325,23 @@ i915_gem_ringbuffer_submission(struct i915_execbuffer_params *params, · 1324 unmodified lines |
| 1325 | | 1325 | |
| 1326 | /** | 1326 | /** |
| 1327 | * Find one BSD ring to dispatch the corresponding BSD command. | 1327 | * Find one BSD ring to dispatch the corresponding BSD command. |
| 1328 | * The Ring ID is returned. | 1328 | * The ring index is returned. |
| 1329 | */ | 1329 | */ |
| 1330 | static int gen8_dispatch_bsd_ring(struct drm_device *dev, | 1330 | static unsigned int |
| 1331 | struct drm_file *file) | 1331 | gen8_dispatch_bsd_ring(struct drm_i915_private *dev_priv, struct drm_file *file) |
| 1332 | { | 1332 | { |
| 1333 | struct drm_i915_private *dev_priv = dev->dev_private; | | |
| 1334 | struct drm_i915_file_private *file_priv = file->driver_priv; | 1333 | struct drm_i915_file_private *file_priv = file->driver_priv; |
| 1335 | | 1334 | |
| 1336 | /* Check whether the file_priv is using one ring */ | 1335 | /* Check whether the file_priv has already selected one ring. */ |
| 1337 | if (file_priv->bsd_ring) | 1336 | if ((int)file_priv->bsd_ring < 0) { |
| 1338 | return file_priv->bsd_ring->id; | 1337 | /* If not, use the ping-pong mechanism to select one. */ |
| 1339 | else { | 1338 | mutex_lock(&dev_priv->dev->struct_mutex); |
| 1340 | /* If no, use the ping-pong mechanism to select one ring */ | 1339 | file_priv->bsd_ring = dev_priv->mm.bsd_ring_dispatch_index; |
| 1341 | int ring_id; | 1340 | dev_priv->mm.bsd_ring_dispatch_index ^= 1; |
| 1342 | | 1341 | mutex_unlock(&dev_priv->dev->struct_mutex); |
| 1343 | mutex_lock(&dev->struct_mutex); | | |
| 1344 | if (dev_priv->mm.bsd_ring_dispatch_index == 0) { | | |
| 1345 | ring_id = VCS; | | |
| 1346 | dev_priv->mm.bsd_ring_dispatch_index = 1; | | |
| 1347 | } else { | | |
| 1348 | ring_id = VCS2; | | |
| 1349 | dev_priv->mm.bsd_ring_dispatch_index = 0; | | |
| 1350 | } | | |
| 1351 | file_priv->bsd_ring = &dev_priv->ring[ring_id]; | | |
| 1352 | mutex_unlock(&dev->struct_mutex); | | |
| 1353 | return ring_id; | | |
| 1354 | } | 1342 | } |
| | 1343 | |
| | 1344 | return file_priv->bsd_ring; |
| 1355 | } | 1345 | } |
| 1356 | | 1346 | |
| 1357 | static struct drm_i915_gem_object * | 1347 | static struct drm_i915_gem_object * |
| @@ -1374,6 +1364,63 @@ eb_get_batch(struct eb_vmas *eb) · 16 unmodified lines |
| 1374 | return vma->obj; | 1364 | return vma->obj; |
| 1375 | } | 1365 | } |
| 1376 | | 1366 | |
| | 1367 | #define I915_USER_RINGS (4) |
| | 1368 | |
| | 1369 | static const enum intel_ring_id user_ring_map[I915_USER_RINGS + 1] = { |
| | 1370 | [I915_EXEC_DEFAULT] = RCS, |
| | 1371 | [I915_EXEC_RENDER] = RCS, |
| | 1372 | [I915_EXEC_BLT] = BCS, |
| | 1373 | [I915_EXEC_BSD] = VCS, |
| | 1374 | [I915_EXEC_VEBOX] = VECS |
| | 1375 | }; |
| | 1376 | |
| | 1377 | static int |
| | 1378 | eb_select_ring(struct drm_i915_private *dev_priv, |
| | 1379 | struct drm_file *file, |
| | 1380 | struct drm_i915_gem_execbuffer2 *args, |
| | 1381 | struct intel_engine_cs **ring) |
| | 1382 | { |
| | 1383 | unsigned int user_ring_id = args->flags & I915_EXEC_RING_MASK; |
| | 1384 | |
| | 1385 | if (user_ring_id > I915_USER_RINGS) { |
| | 1386 | DRM_DEBUG("execbuf with unknown ring: %u\n", user_ring_id); |
| | 1387 | return -EINVAL; |
| | 1388 | } |
| | 1389 | |
| | 1390 | if ((user_ring_id != I915_EXEC_BSD) && |
| | 1391 | ((args->flags & I915_EXEC_BSD_MASK) != 0)) { |
| | 1392 | DRM_DEBUG("execbuf with non bsd ring but with invalid " |
| | 1393 | "bsd dispatch flags: %d\n", (int)(args->flags)); |
| | 1394 | return -EINVAL; |
| | 1395 | } |
| | 1396 | |
| | 1397 | if (user_ring_id == I915_EXEC_BSD && HAS_BSD2(dev_priv)) { |
| | 1398 | unsigned int bsd_idx = args->flags & I915_EXEC_BSD_MASK; |
| | 1399 | |
| | 1400 | if (bsd_idx == I915_EXEC_BSD_DEFAULT) { |
| | 1401 | bsd_idx = gen8_dispatch_bsd_ring(dev_priv, file); |
| | 1402 | } else if (bsd_idx >= I915_EXEC_BSD_RING1 && |
| | 1403 | bsd_idx <= I915_EXEC_BSD_RING2) { |
| | 1404 | bsd_idx--; |
| | 1405 | } else { |
| | 1406 | DRM_DEBUG("execbuf with unknown bsd ring: %u\n", |
| | 1407 | bsd_idx); |
| | 1408 | return -EINVAL; |
| | 1409 | } |
| | 1410 | |
| | 1411 | *ring = &dev_priv->ring[_VCS(bsd_idx)]; |
| | 1412 | } else { |
| | 1413 | *ring = &dev_priv->ring[user_ring_map[user_ring_id]]; |
| | 1414 | } |
| | 1415 | |
| | 1416 | if (!intel_ring_initialized(*ring)) { |
| | 1417 | DRM_DEBUG("execbuf with invalid ring: %u\n", user_ring_id); |
| | 1418 | return -EINVAL; |
| | 1419 | } |
| | 1420 | |
| | 1421 | return 0; |
| | 1422 | } |
| | 1423 | |
| 1377 | static int | 1424 | static int |
| 1378 | i915_gem_do_execbuffer(struct drm_device *dev, void *data, | 1425 | i915_gem_do_execbuffer(struct drm_device *dev, void *data, |
| 1379 | struct drm_file *file, | 1426 | struct drm_file *file, |
| @@ -1412,51 +1459,9 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data, · 32 unmodified lines |
| 1412 | if (args->flags & I915_EXEC_IS_PINNED) | 1459 | if (args->flags & I915_EXEC_IS_PINNED) |
| 1413 | dispatch_flags |= I915_DISPATCH_PINNED; | 1460 | dispatch_flags |= I915_DISPATCH_PINNED; |
| 1414 | | 1461 | |
| 1415 | if ((args->flags & I915_EXEC_RING_MASK) > LAST_USER_RING) { | 1462 | ret = eb_select_ring(dev_priv, file, args, &ring); |
| 1416 | DRM_DEBUG("execbuf with unknown ring: %d\n", | 1463 | if (ret) |
| 1417 | (int)(args->flags & I915_EXEC_RING_MASK)); | 1464 | return ret; |
| 1418 | return -EINVAL; | | |
| 1419 | } | | |
| 1420 | | | |
| 1421 | if (((args->flags & I915_EXEC_RING_MASK) != I915_EXEC_BSD) && | | |
| 1422 | ((args->flags & I915_EXEC_BSD_MASK) != 0)) { | | |
| 1423 | DRM_DEBUG("execbuf with non bsd ring but with invalid " | | |
| 1424 | "bsd dispatch flags: %d\n", (int)(args->flags)); | | |
| 1425 | return -EINVAL; | | |
| 1426 | } | | |
| 1427 | | | |
| 1428 | if ((args->flags & I915_EXEC_RING_MASK) == I915_EXEC_DEFAULT) | | |
| 1429 | ring = &dev_priv->ring[RCS]; | | |
| 1430 | else if ((args->flags & I915_EXEC_RING_MASK) == I915_EXEC_BSD) { | | |
| 1431 | if (HAS_BSD2(dev)) { | | |
| 1432 | int ring_id; | | |
| 1433 | | | |
| 1434 | switch (args->flags & I915_EXEC_BSD_MASK) { | | |
| 1435 | case I915_EXEC_BSD_DEFAULT: | | |
| 1436 | ring_id = gen8_dispatch_bsd_ring(dev, file); | | |
| 1437 | ring = &dev_priv->ring[ring_id]; | | |
| 1438 | break; | | |
| 1439 | case I915_EXEC_BSD_RING1: | | |
| 1440 | ring = &dev_priv->ring[VCS]; | | |
| 1441 | break; | | |
| 1442 | case I915_EXEC_BSD_RING2: | | |
| 1443 | ring = &dev_priv->ring[VCS2]; | | |
| 1444 | break; | | |
| 1445 | default: | | |
| 1446 | DRM_DEBUG("execbuf with unknown bsd ring: %d\n", | | |
| 1447 | (int)(args->flags & I915_EXEC_BSD_MASK)); | | |
| 1448 | return -EINVAL; | | |
| 1449 | } | | |
| 1450 | } else | | |
| 1451 | ring = &dev_priv->ring[VCS]; | | |
| 1452 | } else | | |
| 1453 | ring = &dev_priv->ring[(args->flags & I915_EXEC_RING_MASK) - 1]; | | |
| 1454 | | | |
| 1455 | if (!intel_ring_initialized(ring)) { | | |
| 1456 | DRM_DEBUG("execbuf with invalid ring: %d\n", | | |
| 1457 | (int)(args->flags & I915_EXEC_RING_MASK)); | | |
| 1458 | return -EINVAL; | | |
| 1459 | } | | |
| 1460 | | 1465 | |
| 1461 | if (args->buffer_count < 1) { | 1466 | if (args->buffer_count < 1) { |
| 1462 | DRM_DEBUG("execbuf with %d buffers\n", args->buffer_count); | 1467 | DRM_DEBUG("execbuf with %d buffers\n", args->buffer_count); |