[PATCH 36/37] set-vm
Chris Wilson
chris at chris-wilson.co.uk
Thu Nov 15 09:08:50 UTC 2018
---
drivers/gpu/drm/i915/i915_gem_context.c | 83 +++++++++++++++++++++++++
include/uapi/drm/i915_drm.h | 1 +
2 files changed, 84 insertions(+)
diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index 47bda268117b..2cde86c35c71 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -852,6 +852,77 @@ int i915_gem_vm_destroy_ioctl(struct drm_device *dev, void *data,
return 0;
}
+static int get_ppgtt(struct i915_gem_context *ctx, u64 *out)
+{
+ struct drm_i915_file_private *file_priv = ctx->file_priv;
+ struct i915_hw_ppgtt *ppgtt;
+ int ret;
+
+ /* XXX rcu acquire? */
+ ppgtt = ctx->ppgtt;
+ if (!ppgtt)
+ return -ENODEV;
+
+ ret = mutex_lock_interruptible(&file_priv->vm_lock);
+ if (ret)
+ return ret;
+
+ ret = ppgtt->user_handle;
+ if (!ret) {
+ ret = idr_alloc(&file_priv->vm_idr, ppgtt, 0, 0, GFP_KERNEL);
+ if (ret > 0) {
+ ppgtt->user_handle = ret;
+ i915_ppgtt_get(ppgtt);
+ }
+ }
+
+ mutex_unlock(&file_priv->vm_lock);
+ if (ret < 0)
+ return ret;
+
+ *out = 0xffffffffull << 32 | ret;
+ return 0;
+}
+
+static int set_ppgtt(struct i915_gem_context *ctx, u32 id, u32 ci)
+{
+ struct drm_i915_file_private *file_priv = ctx->file_priv;
+ struct i915_hw_ppgtt *ppgtt;
+ int err;
+
+ if (ci != ~0u)
+ return -EINVAL;
+
+ err = mutex_lock_interruptible(&file_priv->vm_lock);
+ if (err)
+ return err;
+
+ ppgtt = idr_find(&file_priv->vm_idr, id);
+ if (ppgtt)
+ i915_ppgtt_get(ppgtt);
+ mutex_unlock(&file_priv->vm_lock);
+ if (!ppgtt)
+ return -ENOENT;
+
+ mutex_lock(&ctx->i915->drm.struct_mutex);
+
+ /*
+ * We need to flush any requests using the current ppgtt before
+ * we release it as the requests do not hold a reference themselves,
+ * only indirectly through the context.
+ */
+
+ /* XXX idle context */
+
+ i915_ppgtt_put(ctx->ppgtt);
+ ctx->ppgtt = ppgtt;
+ ctx->desc_template = default_desc_template(ctx->i915, ppgtt);
+
+ mutex_unlock(&ctx->i915->drm.struct_mutex);
+
+ return 0;
+}
+
static bool client_is_banned(struct drm_i915_file_private *file_priv)
{
return atomic_read(&file_priv->ban_score) >= I915_CLIENT_SCORE_BANNED;
@@ -964,6 +1035,9 @@ int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data,
case I915_CONTEXT_PARAM_PRIORITY:
args->value = ctx->sched.priority >> I915_USER_PRIORITY_SHIFT;
break;
+ case I915_CONTEXT_PARAM_VM:
+ ret = get_ppgtt(ctx, &args->value);
+ break;
default:
ret = -EINVAL;
break;
@@ -1036,6 +1110,15 @@ int i915_gem_context_setparam_ioctl(struct drm_device *dev, void *data,
}
break;
+ case I915_CONTEXT_PARAM_VM:
+ if (args->size)
+ ret = -EINVAL;
+ else
+ ret = set_ppgtt(ctx,
+ lower_32_bits(args->value),
+ upper_32_bits(args->value));
+ break;
+
default:
ret = -EINVAL;
break;
diff --git a/include/uapi/drm/i915_drm.h b/include/uapi/drm/i915_drm.h
index be0cfbc2f5af..c12966d08b45 100644
--- a/include/uapi/drm/i915_drm.h
+++ b/include/uapi/drm/i915_drm.h
@@ -1516,6 +1516,7 @@ struct drm_i915_gem_context_param {
#define I915_CONTEXT_MAX_USER_PRIORITY 1023 /* inclusive */
#define I915_CONTEXT_DEFAULT_PRIORITY 0
#define I915_CONTEXT_MIN_USER_PRIORITY -1023 /* inclusive */
+#define I915_CONTEXT_PARAM_VM 0x7
__u64 value;
};
--
2.19.1
More information about the Intel-gfx-trybot
mailing list