@@ -302,7 +302,13 @@ to_intel_context(struct i915_gem_context *ctx,
static inline struct intel_context *
intel_context_pin(struct i915_gem_context *ctx, struct intel_engine_cs *engine)
{
- return engine->context_pin(engine, ctx);
+ struct intel_context *ce = to_intel_context(ctx, engine);
+
+ if (likely(ce->pin_count++))
+ return ce;
+ GEM_BUG_ON(!ce->pin_count); /* no overflow please! */
+
+ return engine->context_pin(engine, ctx, ce);
}
static inline void __intel_context_pin(struct intel_context *ce)
@@ -1422,19 +1422,13 @@ static const struct intel_context_ops execlists_context_ops = {
static struct intel_context *
execlists_context_pin(struct intel_engine_cs *engine,
- struct i915_gem_context *ctx)
+ struct i915_gem_context *ctx,
+ struct intel_context *ce)
{
- struct intel_context *ce = to_intel_context(ctx, engine);
-
lockdep_assert_held(&ctx->i915->drm.struct_mutex);
GEM_BUG_ON(!ctx->ppgtt);
- if (likely(ce->pin_count++))
- return ce;
- GEM_BUG_ON(!ce->pin_count); /* no overflow please! */
-
ce->ops = &execlists_context_ops;
-
return __execlists_context_pin(engine, ctx, ce);
}
@@ -1386,18 +1386,12 @@ static const struct intel_context_ops ring_context_ops = {
static struct intel_context *
intel_ring_context_pin(struct intel_engine_cs *engine,
- struct i915_gem_context *ctx)
+ struct i915_gem_context *ctx,
+ struct intel_context *ce)
{
- struct intel_context *ce = to_intel_context(ctx, engine);
-
lockdep_assert_held(&ctx->i915->drm.struct_mutex);
- if (likely(ce->pin_count++))
- return ce;
- GEM_BUG_ON(!ce->pin_count); /* no overflow please! */
-
ce->ops = &ring_context_ops;
-
return __ring_context_pin(engine, ctx, ce);
}
@@ -473,7 +473,8 @@ struct intel_engine_cs {
void (*set_default_submission)(struct intel_engine_cs *engine);
struct intel_context *(*context_pin)(struct intel_engine_cs *engine,
- struct i915_gem_context *ctx);
+ struct i915_gem_context *ctx,
+ struct intel_context *ce);
int (*request_alloc)(struct i915_request *rq);
int (*init_context)(struct i915_request *rq);
@@ -89,15 +89,12 @@ static const struct intel_context_ops mock_context_ops = {
static struct intel_context *
mock_context_pin(struct intel_engine_cs *engine,
- struct i915_gem_context *ctx)
+ struct i915_gem_context *ctx,
+ struct intel_context *ce)
{
- struct intel_context *ce = to_intel_context(ctx, engine);
-
- if (!ce->pin_count++) {
- i915_gem_context_get(ctx);
- ce->ring = engine->buffer;
- ce->ops = &mock_context_ops;
- }
+ i915_gem_context_get(ctx);
+ ce->ring = engine->buffer;
+ ce->ops = &mock_context_ops;
return ce;
}
We already have it coded 3 times and a 4th one is coming for the GuC path in an upcoming patch, so let's move it to a common place. Cc: Chris Wilson <chris@chris-wilson.co.uk> Cc: Michal Wajdeczko <michal.wajdeczko@intel.com> Signed-off-by: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com> --- drivers/gpu/drm/i915/i915_gem_context.h | 8 +++++++- drivers/gpu/drm/i915/intel_lrc.c | 10 ++-------- drivers/gpu/drm/i915/intel_ringbuffer.c | 10 ++-------- drivers/gpu/drm/i915/intel_ringbuffer.h | 3 ++- drivers/gpu/drm/i915/selftests/mock_engine.c | 13 +++++-------- 5 files changed, 18 insertions(+), 26 deletions(-)