aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOscar Mateo <oscar.mateo@intel.com>2014-07-03 11:28:00 -0400
committerDaniel Vetter <daniel.vetter@ffwll.ch>2014-07-08 06:30:41 -0400
commit821d66dd7ca3f59f68478d0d0ee1f28a1de74267 (patch)
tree43600136e563204ea81f50b425d11e2accec74fc
parentea0c76f8c306716a301abbf28699c4ca0a102bed (diff)
drm/i915: Emphasize that ctx->id is merely a user handle
This is an Execlists preparatory patch, since they make context ID become an overloaded term: - In the software, it was used to distinguish which context userspace was trying to use. - In the BSpec, the term is used to describe the 20-bits long field the hardware uses to it to discriminate the contexts that are submitted to the ELSP and inform the driver about their current status (via Context Switch Interrupts and Context Status Buffers). Initially, I tried to make the different meanings converge, but it proved impossible: - The software ctx->id is per-filp, while the hardware one needs to be globally unique. - Also, we multiplex several backing states objects per intel_context, and all of them need unique HW IDs. - I tried adding a per-filp ID and then composing the HW context ID as: ctx->id + file_priv->id + ring->id, but the fact that the hardware only uses 20-bits means we have to artificially limit the number of filps or contexts the userspace can create. The ctx->user_handle renaming bits are done with this Cocci patch (plus manual frobbing of the struct declaration): @@ struct intel_context c; @@ - (c).id + c.user_handle @@ struct intel_context *c; @@ - (c)->id + c->user_handle Also, while we are at it, s/DEFAULT_CONTEXT_ID/DEFAULT_CONTEXT_HANDLE and change the type to unsigned 32 bits. v2: s/handle/user_handle and change the type to uint32_t as suggested by Chris Wilson. Reviewed-by: Jesse Barnes <jbarnes@virtuousgeek.org> (v1) Signed-off-by: Oscar Mateo <oscar.mateo@intel.com> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
-rw-r--r--drivers/gpu/drm/i915/i915_debugfs.c2
-rw-r--r--drivers/gpu/drm/i915/i915_drv.h6
-rw-r--r--drivers/gpu/drm/i915/i915_gem_context.c12
-rw-r--r--drivers/gpu/drm/i915/i915_gem_execbuffer.c2
-rw-r--r--drivers/gpu/drm/i915/intel_uncore.c2
5 files changed, 12 insertions, 12 deletions
diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index 31d5cdf30154..b3b56c46ef7e 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -1876,7 +1876,7 @@ static int per_file_ctx(int id, void *ptr, void *data)
1876 if (i915_gem_context_is_default(ctx)) 1876 if (i915_gem_context_is_default(ctx))
1877 seq_puts(m, " default context:\n"); 1877 seq_puts(m, " default context:\n");
1878 else 1878 else
1879 seq_printf(m, " context %d:\n", ctx->id); 1879 seq_printf(m, " context %d:\n", ctx->user_handle);
1880 ppgtt->debug_dump(ppgtt, m); 1880 ppgtt->debug_dump(ppgtt, m);
1881 1881
1882 return 0; 1882 return 0;
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index eeb3e4c27508..dcef38b1ea61 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -585,10 +585,10 @@ struct i915_ctx_hang_stats {
585}; 585};
586 586
587/* This must match up with the value previously used for execbuf2.rsvd1. */ 587/* This must match up with the value previously used for execbuf2.rsvd1. */
588#define DEFAULT_CONTEXT_ID 0 588#define DEFAULT_CONTEXT_HANDLE 0
589struct intel_context { 589struct intel_context {
590 struct kref ref; 590 struct kref ref;
591 int id; 591 int user_handle;
592 uint8_t remap_slice; 592 uint8_t remap_slice;
593 struct drm_i915_file_private *file_priv; 593 struct drm_i915_file_private *file_priv;
594 struct i915_ctx_hang_stats hang_stats; 594 struct i915_ctx_hang_stats hang_stats;
@@ -2469,7 +2469,7 @@ static inline void i915_gem_context_unreference(struct intel_context *ctx)
2469 2469
2470static inline bool i915_gem_context_is_default(const struct intel_context *c) 2470static inline bool i915_gem_context_is_default(const struct intel_context *c)
2471{ 2471{
2472 return c->id == DEFAULT_CONTEXT_ID; 2472 return c->user_handle == DEFAULT_CONTEXT_HANDLE;
2473} 2473}
2474 2474
2475int i915_gem_context_create_ioctl(struct drm_device *dev, void *data, 2475int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,
diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index 6b7648228757..de72a2859f32 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -276,14 +276,14 @@ __create_hw_context(struct drm_device *dev,
276 /* Default context will never have a file_priv */ 276 /* Default context will never have a file_priv */
277 if (file_priv != NULL) { 277 if (file_priv != NULL) {
278 ret = idr_alloc(&file_priv->context_idr, ctx, 278 ret = idr_alloc(&file_priv->context_idr, ctx,
279 DEFAULT_CONTEXT_ID, 0, GFP_KERNEL); 279 DEFAULT_CONTEXT_HANDLE, 0, GFP_KERNEL);
280 if (ret < 0) 280 if (ret < 0)
281 goto err_out; 281 goto err_out;
282 } else 282 } else
283 ret = DEFAULT_CONTEXT_ID; 283 ret = DEFAULT_CONTEXT_HANDLE;
284 284
285 ctx->file_priv = file_priv; 285 ctx->file_priv = file_priv;
286 ctx->id = ret; 286 ctx->user_handle = ret;
287 /* NB: Mark all slices as needing a remap so that when the context first 287 /* NB: Mark all slices as needing a remap so that when the context first
288 * loads it will restore whatever remap state already exists. If there 288 * loads it will restore whatever remap state already exists. If there
289 * is no remap info, it will be a NOP. */ 289 * is no remap info, it will be a NOP. */
@@ -793,7 +793,7 @@ int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,
793 if (IS_ERR(ctx)) 793 if (IS_ERR(ctx))
794 return PTR_ERR(ctx); 794 return PTR_ERR(ctx);
795 795
796 args->ctx_id = ctx->id; 796 args->ctx_id = ctx->user_handle;
797 DRM_DEBUG_DRIVER("HW context %d created\n", args->ctx_id); 797 DRM_DEBUG_DRIVER("HW context %d created\n", args->ctx_id);
798 798
799 return 0; 799 return 0;
@@ -807,7 +807,7 @@ int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data,
807 struct intel_context *ctx; 807 struct intel_context *ctx;
808 int ret; 808 int ret;
809 809
810 if (args->ctx_id == DEFAULT_CONTEXT_ID) 810 if (args->ctx_id == DEFAULT_CONTEXT_HANDLE)
811 return -ENOENT; 811 return -ENOENT;
812 812
813 ret = i915_mutex_lock_interruptible(dev); 813 ret = i915_mutex_lock_interruptible(dev);
@@ -820,7 +820,7 @@ int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data,
820 return PTR_ERR(ctx); 820 return PTR_ERR(ctx);
821 } 821 }
822 822
823 idr_remove(&ctx->file_priv->context_idr, ctx->id); 823 idr_remove(&ctx->file_priv->context_idr, ctx->user_handle);
824 i915_gem_context_unreference(ctx); 824 i915_gem_context_unreference(ctx);
825 mutex_unlock(&dev->struct_mutex); 825 mutex_unlock(&dev->struct_mutex);
826 826
diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
index d815ef51a5ea..c97178ebf2b5 100644
--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
@@ -938,7 +938,7 @@ i915_gem_validate_context(struct drm_device *dev, struct drm_file *file,
938 struct intel_context *ctx = NULL; 938 struct intel_context *ctx = NULL;
939 struct i915_ctx_hang_stats *hs; 939 struct i915_ctx_hang_stats *hs;
940 940
941 if (ring->id != RCS && ctx_id != DEFAULT_CONTEXT_ID) 941 if (ring->id != RCS && ctx_id != DEFAULT_CONTEXT_HANDLE)
942 return ERR_PTR(-EINVAL); 942 return ERR_PTR(-EINVAL);
943 943
944 ctx = i915_gem_context_get(file->driver_priv, ctx_id); 944 ctx = i915_gem_context_get(file->driver_priv, ctx_id);
diff --git a/drivers/gpu/drm/i915/intel_uncore.c b/drivers/gpu/drm/i915/intel_uncore.c
index 29145df8ef64..e0f0843569a6 100644
--- a/drivers/gpu/drm/i915/intel_uncore.c
+++ b/drivers/gpu/drm/i915/intel_uncore.c
@@ -1010,7 +1010,7 @@ int i915_get_reset_stats_ioctl(struct drm_device *dev,
1010 if (args->flags || args->pad) 1010 if (args->flags || args->pad)
1011 return -EINVAL; 1011 return -EINVAL;
1012 1012
1013 if (args->ctx_id == DEFAULT_CONTEXT_ID && !capable(CAP_SYS_ADMIN)) 1013 if (args->ctx_id == DEFAULT_CONTEXT_HANDLE && !capable(CAP_SYS_ADMIN))
1014 return -EPERM; 1014 return -EPERM;
1015 1015
1016 ret = mutex_lock_interruptible(&dev->struct_mutex); 1016 ret = mutex_lock_interruptible(&dev->struct_mutex);