]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
drm/i915: Emphasize that ctx->id is merely a user handle
authorOscar Mateo <oscar.mateo@intel.com>
Thu, 3 Jul 2014 15:28:00 +0000 (16:28 +0100)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Tue, 8 Jul 2014 10:30:41 +0000 (12:30 +0200)
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>
drivers/gpu/drm/i915/i915_debugfs.c
drivers/gpu/drm/i915/i915_drv.h
drivers/gpu/drm/i915/i915_gem_context.c
drivers/gpu/drm/i915/i915_gem_execbuffer.c
drivers/gpu/drm/i915/intel_uncore.c

index 31d5cdf3015493120beb0d697fab61b3c6c3bd8d..b3b56c46ef7e9f1f5a35f20ba76427eec4e8200a 100644 (file)
@@ -1876,7 +1876,7 @@ static int per_file_ctx(int id, void *ptr, void *data)
        if (i915_gem_context_is_default(ctx))
                seq_puts(m, "  default context:\n");
        else
-               seq_printf(m, "  context %d:\n", ctx->id);
+               seq_printf(m, "  context %d:\n", ctx->user_handle);
        ppgtt->debug_dump(ppgtt, m);
 
        return 0;
index eeb3e4c275082fda69d13c42cae538a7680c33ed..dcef38b1ea619c53c3a3ce22e04f1dac076d4edd 100644 (file)
@@ -585,10 +585,10 @@ struct i915_ctx_hang_stats {
 };
 
 /* This must match up with the value previously used for execbuf2.rsvd1. */
-#define DEFAULT_CONTEXT_ID 0
+#define DEFAULT_CONTEXT_HANDLE 0
 struct intel_context {
        struct kref ref;
-       int id;
+       int user_handle;
        uint8_t remap_slice;
        struct drm_i915_file_private *file_priv;
        struct i915_ctx_hang_stats hang_stats;
@@ -2469,7 +2469,7 @@ static inline void i915_gem_context_unreference(struct intel_context *ctx)
 
 static inline bool i915_gem_context_is_default(const struct intel_context *c)
 {
-       return c->id == DEFAULT_CONTEXT_ID;
+       return c->user_handle == DEFAULT_CONTEXT_HANDLE;
 }
 
 int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,
index 6b76482287577680dfddf190cac3f020f81666ae..de72a2859f3281648b802c168ac49a2a57a63ee6 100644 (file)
@@ -276,14 +276,14 @@ __create_hw_context(struct drm_device *dev,
        /* Default context will never have a file_priv */
        if (file_priv != NULL) {
                ret = idr_alloc(&file_priv->context_idr, ctx,
-                               DEFAULT_CONTEXT_ID, 0, GFP_KERNEL);
+                               DEFAULT_CONTEXT_HANDLE, 0, GFP_KERNEL);
                if (ret < 0)
                        goto err_out;
        } else
-               ret = DEFAULT_CONTEXT_ID;
+               ret = DEFAULT_CONTEXT_HANDLE;
 
        ctx->file_priv = file_priv;
-       ctx->id = ret;
+       ctx->user_handle = ret;
        /* NB: Mark all slices as needing a remap so that when the context first
         * loads it will restore whatever remap state already exists. If there
         * 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,
        if (IS_ERR(ctx))
                return PTR_ERR(ctx);
 
-       args->ctx_id = ctx->id;
+       args->ctx_id = ctx->user_handle;
        DRM_DEBUG_DRIVER("HW context %d created\n", args->ctx_id);
 
        return 0;
@@ -807,7 +807,7 @@ int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data,
        struct intel_context *ctx;
        int ret;
 
-       if (args->ctx_id == DEFAULT_CONTEXT_ID)
+       if (args->ctx_id == DEFAULT_CONTEXT_HANDLE)
                return -ENOENT;
 
        ret = i915_mutex_lock_interruptible(dev);
@@ -820,7 +820,7 @@ int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data,
                return PTR_ERR(ctx);
        }
 
-       idr_remove(&ctx->file_priv->context_idr, ctx->id);
+       idr_remove(&ctx->file_priv->context_idr, ctx->user_handle);
        i915_gem_context_unreference(ctx);
        mutex_unlock(&dev->struct_mutex);
 
index d815ef51a5eac9fb91587b73d0bb63b32f026c9b..c97178ebf2b50f574cb8fea7ed76fd07409f0815 100644 (file)
@@ -938,7 +938,7 @@ i915_gem_validate_context(struct drm_device *dev, struct drm_file *file,
        struct intel_context *ctx = NULL;
        struct i915_ctx_hang_stats *hs;
 
-       if (ring->id != RCS && ctx_id != DEFAULT_CONTEXT_ID)
+       if (ring->id != RCS && ctx_id != DEFAULT_CONTEXT_HANDLE)
                return ERR_PTR(-EINVAL);
 
        ctx = i915_gem_context_get(file->driver_priv, ctx_id);
index 29145df8ef6477fba5aaf2e57c163339b8ee8829..e0f0843569a63ec2a96fe054b96d2e3de91af3ce 100644 (file)
@@ -1010,7 +1010,7 @@ int i915_get_reset_stats_ioctl(struct drm_device *dev,
        if (args->flags || args->pad)
                return -EINVAL;
 
-       if (args->ctx_id == DEFAULT_CONTEXT_ID && !capable(CAP_SYS_ADMIN))
+       if (args->ctx_id == DEFAULT_CONTEXT_HANDLE && !capable(CAP_SYS_ADMIN))
                return -EPERM;
 
        ret = mutex_lock_interruptible(&dev->struct_mutex);