[PATCH 37/37] ctx-create-ext-setparam
Chris Wilson
chris at chris-wilson.co.uk
Wed Nov 14 16:55:22 UTC 2018
---
drivers/gpu/drm/i915/i915_gem_context.c | 249 ++++++++++++++----------
include/uapi/drm/i915_drm.h | 47 +++--
2 files changed, 173 insertions(+), 123 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index 759efef6df8f..2921dd3ac31a 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -86,10 +86,13 @@
*/
#include <linux/log2.h>
+
#include <drm/drmP.h>
#include <drm/i915_drm.h>
+
#include "i915_drv.h"
#include "i915_trace.h"
+#include "i915_user_extensions.h"
#include "intel_workarounds.h"
#define ALL_L3_SLICES(dev) (1 << NUM_L3_SLICES(dev)) - 1
@@ -852,6 +855,133 @@ int i915_gem_vm_destroy_ioctl(struct drm_device *dev, void *data,
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 int ctx_setparam(struct i915_gem_context *ctx,
+ const struct drm_i915_gem_context_param *args)
+{
+ int ret = 0;
+
+ switch (args->param) {
+ case I915_CONTEXT_PARAM_NO_ZEROMAP:
+ if (args->size)
+ ret = -EINVAL;
+ else if (args->value)
+ set_bit(UCONTEXT_NO_ZEROMAP, &ctx->user_flags);
+ else
+ clear_bit(UCONTEXT_NO_ZEROMAP, &ctx->user_flags);
+ break;
+
+ case I915_CONTEXT_PARAM_NO_ERROR_CAPTURE:
+ if (args->size)
+ ret = -EINVAL;
+ else if (args->value)
+ i915_gem_context_set_no_error_capture(ctx);
+ else
+ i915_gem_context_clear_no_error_capture(ctx);
+ break;
+
+ case I915_CONTEXT_PARAM_BANNABLE:
+ if (args->size)
+ ret = -EINVAL;
+ else if (!capable(CAP_SYS_ADMIN) && !args->value)
+ ret = -EPERM;
+ else if (args->value)
+ i915_gem_context_set_bannable(ctx);
+ else
+ i915_gem_context_clear_bannable(ctx);
+ break;
+
+ case I915_CONTEXT_PARAM_PRIORITY:
+ {
+ s64 priority = args->value;
+
+ if (args->size)
+ ret = -EINVAL;
+ else if (!(ctx->i915->caps.scheduler & I915_SCHEDULER_CAP_PRIORITY))
+ ret = -ENODEV;
+ else if (priority > I915_CONTEXT_MAX_USER_PRIORITY ||
+ priority < I915_CONTEXT_MIN_USER_PRIORITY)
+ ret = -EINVAL;
+ else if (priority > I915_CONTEXT_DEFAULT_PRIORITY &&
+ !capable(CAP_SYS_NICE))
+ ret = -EPERM;
+ else
+ ctx->sched.priority =
+ I915_USER_PRIORITY(priority);
+ }
+ 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;
+
+ case I915_CONTEXT_PARAM_BAN_PERIOD:
+ default:
+ ret = -EINVAL;
+ break;
+ }
+
+ return ret;
+}
+
+static int create_setparam(struct i915_user_extension *ext, void *data)
+{
+ const struct drm_i915_gem_context_create_ext_setparam *args =
+ container_of(ext, typeof(*args), base);
+
+ if (args->setparam.ctx_id)
+ return -EINVAL;
+
+ return ctx_setparam(data, &args->setparam);
+}
+
+static const i915_user_extension_fn create_extensions[] = {
+ [I915_CONTEXT_CREATE_EXT_SETPARAM] = create_setparam,
+};
+
static bool client_is_banned(struct drm_i915_file_private *file_priv)
{
return atomic_read(&file_priv->ban_score) >= I915_CLIENT_SCORE_BANNED;
@@ -861,7 +991,7 @@ int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,
struct drm_file *file)
{
struct drm_i915_private *dev_priv = to_i915(dev);
- struct drm_i915_gem_context_create *args = data;
+ struct drm_i915_gem_context_create_v2 *args = data;
struct drm_i915_file_private *file_priv = file->driver_priv;
struct i915_gem_context *ctx;
int ret;
@@ -869,7 +999,7 @@ int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,
if (!DRIVER_CAPS(dev_priv)->has_logical_contexts)
return -ENODEV;
- if (args->pad != 0)
+ if (args->flags)
return -EINVAL;
if (client_is_banned(file_priv)) {
@@ -891,6 +1021,15 @@ int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,
GEM_BUG_ON(i915_gem_context_is_kernel(ctx));
+ ret = i915_user_extensions(u64_to_user_ptr(args->extensions),
+ create_extensions,
+ ARRAY_SIZE(create_extensions),
+ ctx);
+ if (ret) {
+ context_close(ctx);
+ return ret;
+ }
+
args->ctx_id = ctx->user_handle;
DRM_DEBUG("HW context %d created\n", args->ctx_id);
@@ -1008,121 +1147,19 @@ int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data,
return ret;
}
-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;
-}
-
int i915_gem_context_setparam_ioctl(struct drm_device *dev, void *data,
struct drm_file *file)
{
struct drm_i915_file_private *file_priv = file->driver_priv;
struct drm_i915_gem_context_param *args = data;
struct i915_gem_context *ctx;
- int ret = 0;
+ int ret;
ctx = i915_gem_context_lookup(file_priv, args->ctx_id);
if (!ctx)
return -ENOENT;
- switch (args->param) {
- case I915_CONTEXT_PARAM_BAN_PERIOD:
- ret = -EINVAL;
- break;
- case I915_CONTEXT_PARAM_NO_ZEROMAP:
- if (args->size)
- ret = -EINVAL;
- else if (args->value)
- set_bit(UCONTEXT_NO_ZEROMAP, &ctx->user_flags);
- else
- clear_bit(UCONTEXT_NO_ZEROMAP, &ctx->user_flags);
- break;
- case I915_CONTEXT_PARAM_NO_ERROR_CAPTURE:
- if (args->size)
- ret = -EINVAL;
- else if (args->value)
- i915_gem_context_set_no_error_capture(ctx);
- else
- i915_gem_context_clear_no_error_capture(ctx);
- break;
- case I915_CONTEXT_PARAM_BANNABLE:
- if (args->size)
- ret = -EINVAL;
- else if (!capable(CAP_SYS_ADMIN) && !args->value)
- ret = -EPERM;
- else if (args->value)
- i915_gem_context_set_bannable(ctx);
- else
- i915_gem_context_clear_bannable(ctx);
- break;
-
- case I915_CONTEXT_PARAM_PRIORITY:
- {
- s64 priority = args->value;
-
- if (args->size)
- ret = -EINVAL;
- else if (!(to_i915(dev)->caps.scheduler & I915_SCHEDULER_CAP_PRIORITY))
- ret = -ENODEV;
- else if (priority > I915_CONTEXT_MAX_USER_PRIORITY ||
- priority < I915_CONTEXT_MIN_USER_PRIORITY)
- ret = -EINVAL;
- else if (priority > I915_CONTEXT_DEFAULT_PRIORITY &&
- !capable(CAP_SYS_NICE))
- ret = -EPERM;
- else
- ctx->sched.priority =
- I915_USER_PRIORITY(priority);
- }
- 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;
- }
+ ret = ctx_setparam(ctx, args);
i915_gem_context_put(ctx);
return ret;
diff --git a/include/uapi/drm/i915_drm.h b/include/uapi/drm/i915_drm.h
index c12966d08b45..0f4fdd9d7d85 100644
--- a/include/uapi/drm/i915_drm.h
+++ b/include/uapi/drm/i915_drm.h
@@ -1441,6 +1441,36 @@ struct drm_i915_gem_context_create {
__u32 pad;
};
+struct drm_i915_gem_context_create_v2 {
+ /* output: id of new context*/
+ __u32 ctx_id;
+ __u32 flags;
+ __u64 extensions;
+};
+
+struct drm_i915_gem_context_param {
+ __u32 ctx_id;
+ __u32 size;
+ __u64 param;
+#define I915_CONTEXT_PARAM_BAN_PERIOD 0x1
+#define I915_CONTEXT_PARAM_NO_ZEROMAP 0x2
+#define I915_CONTEXT_PARAM_GTT_SIZE 0x3
+#define I915_CONTEXT_PARAM_NO_ERROR_CAPTURE 0x4
+#define I915_CONTEXT_PARAM_BANNABLE 0x5
+#define I915_CONTEXT_PARAM_PRIORITY 0x6
+#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;
+};
+
+struct drm_i915_gem_context_create_ext_setparam {
+#define I915_CONTEXT_CREATE_EXT_SETPARAM 0
+ struct i915_user_extension base;
+ struct drm_i915_gem_context_param setparam;
+};
+
struct drm_i915_gem_context_destroy {
__u32 ctx_id;
__u32 pad;
@@ -1503,23 +1533,6 @@ struct drm_i915_gem_userptr {
__u32 handle;
};
-struct drm_i915_gem_context_param {
- __u32 ctx_id;
- __u32 size;
- __u64 param;
-#define I915_CONTEXT_PARAM_BAN_PERIOD 0x1
-#define I915_CONTEXT_PARAM_NO_ZEROMAP 0x2
-#define I915_CONTEXT_PARAM_GTT_SIZE 0x3
-#define I915_CONTEXT_PARAM_NO_ERROR_CAPTURE 0x4
-#define I915_CONTEXT_PARAM_BANNABLE 0x5
-#define I915_CONTEXT_PARAM_PRIORITY 0x6
-#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;
-};
-
enum drm_i915_oa_format {
I915_OA_FORMAT_A13 = 1, /* HSW only */
I915_OA_FORMAT_A29, /* HSW only */
--
2.19.1
More information about the Intel-gfx-trybot
mailing list