Skip to content

Commit b352749

Browse files
committed
drm/i915: Create a kernel context for GGTT updates
Create a separate kernel context if a platform requires GGTT updates using MI_UPDATE_GTT blitter command. Subsequent patch will introduce methods to update GGTT using this bind context and MI_UPDATE_GTT blitter command. v2: fix context leak on err(Oak) v3: improve err handling and improve function names(Andi) add docs for few functions. Signed-off-by: Nirmoy Das <nirmoy.das@intel.com> Reviewed-by: Oak Zeng <oak.zeng@intel.com> Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20230926083742.14740-3-nirmoy.das@intel.com
1 parent 4cd64e9 commit b352749

5 files changed

Lines changed: 94 additions & 3 deletions

File tree

drivers/gpu/drm/i915/gt/intel_engine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ intel_write_status_page(struct intel_engine_cs *engine, int reg, u32 value)
170170
#define I915_GEM_HWS_SEQNO 0x40
171171
#define I915_GEM_HWS_SEQNO_ADDR (I915_GEM_HWS_SEQNO * sizeof(u32))
172172
#define I915_GEM_HWS_MIGRATE (0x42 * sizeof(u32))
173+
#define I915_GEM_HWS_GGTT_BIND 0x46
174+
#define I915_GEM_HWS_GGTT_BIND_ADDR (I915_GEM_HWS_GGTT_BIND * sizeof(u32))
173175
#define I915_GEM_HWS_PXP 0x60
174176
#define I915_GEM_HWS_PXP_ADDR (I915_GEM_HWS_PXP * sizeof(u32))
175177
#define I915_GEM_HWS_GSC 0x62

drivers/gpu/drm/i915/gt/intel_engine_cs.c

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,20 @@ void intel_engine_destroy_pinned_context(struct intel_context *ce)
14181418
intel_context_put(ce);
14191419
}
14201420

1421+
static struct intel_context *
1422+
create_ggtt_bind_context(struct intel_engine_cs *engine)
1423+
{
1424+
static struct lock_class_key kernel;
1425+
1426+
/*
1427+
* MI_UPDATE_GTT can insert up to 511 PTE entries and there could be multiple
1428+
* bind requets at a time so get a bigger ring.
1429+
*/
1430+
return intel_engine_create_pinned_context(engine, engine->gt->vm, SZ_512K,
1431+
I915_GEM_HWS_GGTT_BIND_ADDR,
1432+
&kernel, "ggtt_bind_context");
1433+
}
1434+
14211435
static struct intel_context *
14221436
create_kernel_context(struct intel_engine_cs *engine)
14231437
{
@@ -1441,7 +1455,7 @@ create_kernel_context(struct intel_engine_cs *engine)
14411455
*/
14421456
static int engine_init_common(struct intel_engine_cs *engine)
14431457
{
1444-
struct intel_context *ce;
1458+
struct intel_context *ce, *bce = NULL;
14451459
int ret;
14461460

14471461
engine->set_default_submission(engine);
@@ -1457,17 +1471,33 @@ static int engine_init_common(struct intel_engine_cs *engine)
14571471
ce = create_kernel_context(engine);
14581472
if (IS_ERR(ce))
14591473
return PTR_ERR(ce);
1474+
/*
1475+
* Create a separate pinned context for GGTT update with blitter engine
1476+
* if a platform require such service. MI_UPDATE_GTT works on other
1477+
* engines as well but BCS should be less busy engine so pick that for
1478+
* GGTT updates.
1479+
*/
1480+
if (engine->id == BCS0) {
1481+
bce = create_ggtt_bind_context(engine);
1482+
if (IS_ERR(bce)) {
1483+
ret = PTR_ERR(bce);
1484+
goto err_ce_context;
1485+
}
1486+
}
14601487

14611488
ret = measure_breadcrumb_dw(ce);
14621489
if (ret < 0)
1463-
goto err_context;
1490+
goto err_bce_context;
14641491

14651492
engine->emit_fini_breadcrumb_dw = ret;
14661493
engine->kernel_context = ce;
1494+
engine->bind_context = bce;
14671495

14681496
return 0;
14691497

1470-
err_context:
1498+
err_bce_context:
1499+
intel_engine_destroy_pinned_context(bce);
1500+
err_ce_context:
14711501
intel_engine_destroy_pinned_context(ce);
14721502
return ret;
14731503
}
@@ -1537,6 +1567,10 @@ void intel_engine_cleanup_common(struct intel_engine_cs *engine)
15371567
if (engine->kernel_context)
15381568
intel_engine_destroy_pinned_context(engine->kernel_context);
15391569

1570+
if (engine->bind_context)
1571+
intel_engine_destroy_pinned_context(engine->bind_context);
1572+
1573+
15401574
GEM_BUG_ON(!llist_empty(&engine->barrier_tasks));
15411575
cleanup_status_page(engine);
15421576

drivers/gpu/drm/i915/gt/intel_engine_types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,9 @@ struct intel_engine_cs {
416416
struct llist_head barrier_tasks;
417417

418418
struct intel_context *kernel_context; /* pinned */
419+
struct intel_context *bind_context; /* pinned, only for BCS0 */
420+
/* mark the bind context's availability status */
421+
bool bind_context_ready;
419422

420423
/**
421424
* pinned_contexts_list: List of pinned contexts. This list is only

drivers/gpu/drm/i915/gt/intel_gt.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,3 +1035,52 @@ bool intel_gt_needs_wa_22016122933(struct intel_gt *gt)
10351035
{
10361036
return MEDIA_VER_FULL(gt->i915) == IP_VER(13, 0) && gt->type == GT_MEDIA;
10371037
}
1038+
1039+
static void __intel_gt_bind_context_set_ready(struct intel_gt *gt, bool ready)
1040+
{
1041+
struct intel_engine_cs *engine = gt->engine[BCS0];
1042+
1043+
if (engine && engine->bind_context)
1044+
engine->bind_context_ready = ready;
1045+
}
1046+
1047+
/**
1048+
* intel_gt_bind_context_set_ready - Set the context binding as ready
1049+
*
1050+
* @gt: GT structure
1051+
*
1052+
* This function marks the binder context as ready.
1053+
*/
1054+
void intel_gt_bind_context_set_ready(struct intel_gt *gt)
1055+
{
1056+
__intel_gt_bind_context_set_ready(gt, true);
1057+
}
1058+
1059+
/**
1060+
* intel_gt_bind_context_set_unready - Set the context binding as ready
1061+
* @gt: GT structure
1062+
*
1063+
* This function marks the binder context as not ready.
1064+
*/
1065+
1066+
void intel_gt_bind_context_set_unready(struct intel_gt *gt)
1067+
{
1068+
__intel_gt_bind_context_set_ready(gt, false);
1069+
}
1070+
1071+
/**
1072+
* intel_gt_is_bind_context_ready - Check if context binding is ready
1073+
*
1074+
* @gt: GT structure
1075+
*
1076+
* This function returns binder context's ready status.
1077+
*/
1078+
bool intel_gt_is_bind_context_ready(struct intel_gt *gt)
1079+
{
1080+
struct intel_engine_cs *engine = gt->engine[BCS0];
1081+
1082+
if (engine)
1083+
return engine->bind_context_ready;
1084+
1085+
return false;
1086+
}

drivers/gpu/drm/i915/gt/intel_gt.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,7 @@ enum i915_map_type intel_gt_coherent_map_type(struct intel_gt *gt,
176176
struct drm_i915_gem_object *obj,
177177
bool always_coherent);
178178

179+
void intel_gt_bind_context_set_ready(struct intel_gt *gt);
180+
void intel_gt_bind_context_set_unready(struct intel_gt *gt);
181+
bool intel_gt_is_bind_context_ready(struct intel_gt *gt);
179182
#endif /* __INTEL_GT_H__ */

0 commit comments

Comments
 (0)