Skip to content

Commit 7174537

Browse files
Brad Volkindanvet
authored andcommitted
drm/i915: Tidy up execbuffer command parsing code
Move it to a separate function since the main do_execbuffer function already has so much going on. v2: - Move pin/unpin calls inside i915_parse_cmds() (Chris W, v4 7/7 feedback) Issue: VIZ-4719 Signed-off-by: Brad Volkin <bradley.d.volkin@intel.com> Reviewed-By: Jon Bloomfield <jon.bloomfield@intel.com> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
1 parent 0079a7d commit 7174537

File tree

2 files changed

+77
-55
lines changed

2 files changed

+77
-55
lines changed

drivers/gpu/drm/i915/i915_cmd_parser.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,10 +1050,17 @@ int i915_parse_cmds(struct intel_engine_cs *ring,
10501050
struct drm_i915_cmd_descriptor default_desc = { 0 };
10511051
bool oacontrol_set = false; /* OACONTROL tracking. See check_cmd() */
10521052

1053+
ret = i915_gem_obj_ggtt_pin(shadow_batch_obj, 4096, 0);
1054+
if (ret) {
1055+
DRM_DEBUG_DRIVER("CMD: Failed to pin shadow batch\n");
1056+
return -1;
1057+
}
1058+
10531059
batch_base = copy_batch(shadow_batch_obj, batch_obj,
10541060
batch_start_offset, batch_len);
10551061
if (IS_ERR(batch_base)) {
10561062
DRM_DEBUG_DRIVER("CMD: Failed to copy batch\n");
1063+
i915_gem_object_ggtt_unpin(shadow_batch_obj);
10571064
return PTR_ERR(batch_base);
10581065
}
10591066

@@ -1124,6 +1131,7 @@ int i915_parse_cmds(struct intel_engine_cs *ring,
11241131
}
11251132

11261133
vunmap(batch_base);
1134+
i915_gem_object_ggtt_unpin(shadow_batch_obj);
11271135

11281136
return ret;
11291137
}

drivers/gpu/drm/i915/i915_gem_execbuffer.c

Lines changed: 69 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,65 @@ i915_emit_box(struct intel_engine_cs *ring,
10721072
return 0;
10731073
}
10741074

1075+
static struct drm_i915_gem_object*
1076+
i915_gem_execbuffer_parse(struct intel_engine_cs *ring,
1077+
struct drm_i915_gem_exec_object2 *shadow_exec_entry,
1078+
struct eb_vmas *eb,
1079+
struct drm_i915_gem_object *batch_obj,
1080+
u32 batch_start_offset,
1081+
u32 batch_len,
1082+
bool is_master,
1083+
u32 *flags)
1084+
{
1085+
struct drm_i915_private *dev_priv = to_i915(batch_obj->base.dev);
1086+
struct drm_i915_gem_object *shadow_batch_obj;
1087+
int ret;
1088+
1089+
shadow_batch_obj = i915_gem_batch_pool_get(&dev_priv->mm.batch_pool,
1090+
batch_obj->base.size);
1091+
if (IS_ERR(shadow_batch_obj))
1092+
return shadow_batch_obj;
1093+
1094+
ret = i915_parse_cmds(ring,
1095+
batch_obj,
1096+
shadow_batch_obj,
1097+
batch_start_offset,
1098+
batch_len,
1099+
is_master);
1100+
if (ret) {
1101+
if (ret == -EACCES)
1102+
return batch_obj;
1103+
} else {
1104+
struct i915_vma *vma;
1105+
1106+
memset(shadow_exec_entry, 0, sizeof(*shadow_exec_entry));
1107+
1108+
vma = i915_gem_obj_to_ggtt(shadow_batch_obj);
1109+
vma->exec_entry = shadow_exec_entry;
1110+
vma->exec_entry->flags = __EXEC_OBJECT_PURGEABLE;
1111+
drm_gem_object_reference(&shadow_batch_obj->base);
1112+
list_add_tail(&vma->exec_list, &eb->vmas);
1113+
1114+
shadow_batch_obj->base.pending_read_domains =
1115+
batch_obj->base.pending_read_domains;
1116+
1117+
/*
1118+
* Set the DISPATCH_SECURE bit to remove the NON_SECURE
1119+
* bit from MI_BATCH_BUFFER_START commands issued in the
1120+
* dispatch_execbuffer implementations. We specifically
1121+
* don't want that set when the command parser is
1122+
* enabled.
1123+
*
1124+
* FIXME: with aliasing ppgtt, buffers that should only
1125+
* be in ggtt still end up in the aliasing ppgtt. remove
1126+
* this check when that is fixed.
1127+
*/
1128+
if (USES_FULL_PPGTT(dev))
1129+
*flags |= I915_DISPATCH_SECURE;
1130+
}
1131+
1132+
return ret ? ERR_PTR(ret) : shadow_batch_obj;
1133+
}
10751134

10761135
int
10771136
i915_gem_ringbuffer_submission(struct drm_device *dev, struct drm_file *file,
@@ -1289,7 +1348,6 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
12891348
struct drm_i915_private *dev_priv = dev->dev_private;
12901349
struct eb_vmas *eb;
12911350
struct drm_i915_gem_object *batch_obj;
1292-
struct drm_i915_gem_object *shadow_batch_obj = NULL;
12931351
struct drm_i915_gem_exec_object2 shadow_exec_entry;
12941352
struct intel_engine_cs *ring;
12951353
struct intel_context *ctx;
@@ -1409,62 +1467,18 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
14091467
}
14101468

14111469
if (i915_needs_cmd_parser(ring)) {
1412-
shadow_batch_obj =
1413-
i915_gem_batch_pool_get(&dev_priv->mm.batch_pool,
1414-
batch_obj->base.size);
1415-
if (IS_ERR(shadow_batch_obj)) {
1416-
ret = PTR_ERR(shadow_batch_obj);
1417-
/* Don't try to clean up the obj in the error path */
1418-
shadow_batch_obj = NULL;
1470+
batch_obj = i915_gem_execbuffer_parse(ring,
1471+
&shadow_exec_entry,
1472+
eb,
1473+
batch_obj,
1474+
args->batch_start_offset,
1475+
args->batch_len,
1476+
file->is_master,
1477+
&flags);
1478+
if (IS_ERR(batch_obj)) {
1479+
ret = PTR_ERR(batch_obj);
14191480
goto err;
14201481
}
1421-
1422-
ret = i915_gem_obj_ggtt_pin(shadow_batch_obj, 4096, 0);
1423-
if (ret)
1424-
goto err;
1425-
1426-
ret = i915_parse_cmds(ring,
1427-
batch_obj,
1428-
shadow_batch_obj,
1429-
args->batch_start_offset,
1430-
args->batch_len,
1431-
file->is_master);
1432-
i915_gem_object_ggtt_unpin(shadow_batch_obj);
1433-
1434-
if (ret) {
1435-
if (ret != -EACCES)
1436-
goto err;
1437-
} else {
1438-
struct i915_vma *vma;
1439-
1440-
memset(&shadow_exec_entry, 0,
1441-
sizeof(shadow_exec_entry));
1442-
1443-
vma = i915_gem_obj_to_ggtt(shadow_batch_obj);
1444-
vma->exec_entry = &shadow_exec_entry;
1445-
vma->exec_entry->flags = __EXEC_OBJECT_PURGEABLE;
1446-
drm_gem_object_reference(&shadow_batch_obj->base);
1447-
list_add_tail(&vma->exec_list, &eb->vmas);
1448-
1449-
shadow_batch_obj->base.pending_read_domains =
1450-
batch_obj->base.pending_read_domains;
1451-
1452-
batch_obj = shadow_batch_obj;
1453-
1454-
/*
1455-
* Set the DISPATCH_SECURE bit to remove the NON_SECURE
1456-
* bit from MI_BATCH_BUFFER_START commands issued in the
1457-
* dispatch_execbuffer implementations. We specifically
1458-
* don't want that set when the command parser is
1459-
* enabled.
1460-
*
1461-
* FIXME: with aliasing ppgtt, buffers that should only
1462-
* be in ggtt still end up in the aliasing ppgtt. remove
1463-
* this check when that is fixed.
1464-
*/
1465-
if (USES_FULL_PPGTT(dev))
1466-
flags |= I915_DISPATCH_SECURE;
1467-
}
14681482
}
14691483

14701484
batch_obj->base.pending_read_domains |= I915_GEM_DOMAIN_COMMAND;

0 commit comments

Comments
 (0)