drm/i915/context: create & destroy ioctls
authorBen Widawsky <ben@bwidawsk.net>
Mon, 4 Jun 2012 21:42:54 +0000 (14:42 -0700)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Thu, 14 Jun 2012 15:36:20 +0000 (17:36 +0200)
Add the interfaces to allow user space to create and destroy contexts.
Contexts are destroyed automatically if the file descriptor for the dri
device is closed.

Following convention as usual here causes checkpatch warnings.

v2: with is_initialized, no longer need to init at create
drop the context switch on create (daniel)

v3: Use interruptible lock (Chris)
return -ENODEV in !GEM case (Chris)

Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
drivers/gpu/drm/i915/i915_dma.c
drivers/gpu/drm/i915/i915_drv.h
drivers/gpu/drm/i915/i915_gem_context.c
include/drm/i915_drm.h

index 3f3aca8c37674fe0c9c2da9c9a583751ed09a0d8..ba75af12f1fdd9f3ea17ee1706f2e5dfe2ba4f81 100644 (file)
@@ -1848,6 +1848,8 @@ struct drm_ioctl_desc i915_ioctls[] = {
        DRM_IOCTL_DEF_DRV(I915_SET_SPRITE_COLORKEY, intel_sprite_set_colorkey, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
        DRM_IOCTL_DEF_DRV(I915_GET_SPRITE_COLORKEY, intel_sprite_get_colorkey, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
        DRM_IOCTL_DEF_DRV(I915_GEM_WAIT, i915_gem_wait_ioctl, DRM_AUTH|DRM_UNLOCKED),
+       DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_CREATE, i915_gem_context_create_ioctl, DRM_UNLOCKED),
+       DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_DESTROY, i915_gem_context_destroy_ioctl, DRM_UNLOCKED),
 };
 
 int i915_max_ioctl = DRM_ARRAY_SIZE(i915_ioctls);
index 6edc02b6dda405b0f0ca120594e6937dee2ead83..03e7f9e683e31076d0d0bdb0f793bbc122bc8729 100644 (file)
@@ -1386,6 +1386,10 @@ void i915_gem_context_open(struct drm_device *dev, struct drm_file *file);
 void i915_gem_context_close(struct drm_device *dev, struct drm_file *file);
 int i915_switch_context(struct intel_ring_buffer *ring,
                        struct drm_file *file, int to_id);
+int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,
+                                 struct drm_file *file);
+int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data,
+                                  struct drm_file *file);
 
 /* i915_gem_gtt.c */
 int __must_check i915_gem_init_aliasing_ppgtt(struct drm_device *dev);
index 6a7b67d9f43f1a975f0f1828c884d9686a4be54b..5642c4019b53183c4d8bc49cdd7db02e242e326c 100644 (file)
@@ -489,3 +489,58 @@ int i915_switch_context(struct intel_ring_buffer *ring,
                drm_gem_object_unreference(&from_obj->base);
        return ret;
 }
+
+int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,
+                                 struct drm_file *file)
+{
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       struct drm_i915_gem_context_create *args = data;
+       struct drm_i915_file_private *file_priv = file->driver_priv;
+       struct i915_hw_context *ctx;
+       int ret;
+
+       if (!(dev->driver->driver_features & DRIVER_GEM))
+               return -ENODEV;
+
+       ret = i915_mutex_lock_interruptible(dev);
+       if (ret)
+               return ret;
+
+       ret = create_hw_context(dev, file_priv, &ctx);
+       mutex_unlock(&dev->struct_mutex);
+
+       args->ctx_id = ctx->id;
+       DRM_DEBUG_DRIVER("HW context %d created\n", args->ctx_id);
+
+       return ret;
+}
+
+int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data,
+                                  struct drm_file *file)
+{
+       struct drm_i915_gem_context_destroy *args = data;
+       struct drm_i915_file_private *file_priv = file->driver_priv;
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       struct i915_hw_context *ctx;
+       int ret;
+
+       if (!(dev->driver->driver_features & DRIVER_GEM))
+               return -ENODEV;
+
+       ret = i915_mutex_lock_interruptible(dev);
+       if (ret)
+               return ret;
+
+       ctx = i915_gem_context_get(file_priv, args->ctx_id);
+       if (!ctx) {
+               mutex_unlock(&dev->struct_mutex);
+               return -EINVAL;
+       }
+
+       do_destroy(ctx);
+
+       mutex_unlock(&dev->struct_mutex);
+
+       DRM_DEBUG_DRIVER("HW context %d destroyed\n", args->ctx_id);
+       return 0;
+}
index 5c28ee1d19118e3398e40efa7b2f85e740bc8ba6..5da73244486a444b853a527b48dee7bf26344f92 100644 (file)
@@ -201,6 +201,8 @@ typedef struct _drm_i915_sarea {
 #define DRM_I915_GET_SPRITE_COLORKEY   0x2a
 #define DRM_I915_SET_SPRITE_COLORKEY   0x2b
 #define DRM_I915_GEM_WAIT      0x2c
+#define DRM_I915_GEM_CONTEXT_CREATE    0x2d
+#define DRM_I915_GEM_CONTEXT_DESTROY   0x2e
 
 #define DRM_IOCTL_I915_INIT            DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t)
 #define DRM_IOCTL_I915_FLUSH           DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLUSH)
@@ -245,6 +247,8 @@ typedef struct _drm_i915_sarea {
 #define DRM_IOCTL_I915_SET_SPRITE_COLORKEY DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_SET_SPRITE_COLORKEY, struct drm_intel_sprite_colorkey)
 #define DRM_IOCTL_I915_GET_SPRITE_COLORKEY DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_SET_SPRITE_COLORKEY, struct drm_intel_sprite_colorkey)
 #define DRM_IOCTL_I915_GEM_WAIT                DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_WAIT, struct drm_i915_gem_wait)
+#define DRM_IOCTL_I915_GEM_CONTEXT_CREATE      DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_GEM_CONTEXT_CREATE, struct drm_i915_gem_context_create)
+#define DRM_IOCTL_I915_GEM_CONTEXT_DESTROY     DRM_IOW (DRM_COMMAND_BASE + DRM_I915_GEM_CONTEXT_DESTROY, struct drm_i915_gem_context_destroy)
 
 /* Allow drivers to submit batchbuffers directly to hardware, relying
  * on the security mechanisms provided by hardware.
@@ -897,4 +901,15 @@ struct drm_i915_gem_wait {
        __s64 timeout_ns;
 };
 
+struct drm_i915_gem_context_create {
+       /*  output: id of new context*/
+       __u32 ctx_id;
+       __u32 pad;
+};
+
+struct drm_i915_gem_context_destroy {
+       __u32 ctx_id;
+       __u32 pad;
+};
+
 #endif                         /* _I915_DRM_H_ */