[Intel-gfx] [PATCH 05/11] drm/i915/context: Preliminary context support
Ben Widawsky
ben at bwidawsk.net
Tue Feb 14 22:09:12 CET 2012
From: Ben Widawsky <bwidawsk at gmail.com>
Create all the necessary data structures and hooks to support a context
API for userspace. Also plumb in the calls from the i915 core into the
context subsystem. There is a new file i915_context.c which will hold a
majority of the context related code. This file has nulled functions
that get called by the proper part of the i915 driver. This of course
requires a Makefile addition, as well as calls to the new nulled
functions from the other partsd of the driver (i915_dma.c).
With that, there are 2 new ioctls defined , one for creating a context,
and one for destroying a context. These are defined in the necessary
places, and again have null functionality
It's likely that a third ioctl will be required to associate the context
with an execbuf (likely execbuf3). Since that part is mostly trivial,
and will surely be contentious, it's ignored for now.
Signed-off-by: Ben Widawsky <ben at bwidawsk.net>
---
drivers/gpu/drm/i915/Makefile | 1 +
drivers/gpu/drm/i915/i915_context.c | 71 +++++++++++++++++++++++++++++++++++
drivers/gpu/drm/i915/i915_dma.c | 8 ++++
drivers/gpu/drm/i915/i915_drv.h | 30 +++++++++++++++
include/drm/i915_drm.h | 17 ++++++++
5 files changed, 127 insertions(+), 0 deletions(-)
create mode 100644 drivers/gpu/drm/i915/i915_context.c
diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile
index ce7fc77..a633990 100644
--- a/drivers/gpu/drm/i915/Makefile
+++ b/drivers/gpu/drm/i915/Makefile
@@ -6,6 +6,7 @@ ccflags-y := -Iinclude/drm
i915-y := i915_drv.o i915_dma.o i915_irq.o \
i915_debugfs.o \
i915_suspend.o \
+ i915_context.o \
i915_gem.o \
i915_gem_debug.o \
i915_gem_evict.o \
diff --git a/drivers/gpu/drm/i915/i915_context.c b/drivers/gpu/drm/i915/i915_context.c
new file mode 100644
index 0000000..9108244
--- /dev/null
+++ b/drivers/gpu/drm/i915/i915_context.c
@@ -0,0 +1,71 @@
+/*
+ * Copyright © 2011 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ * Ben Widawsky <ben at bwidawsk.net>
+ */
+
+#include "drmP.h"
+#include "i915_drm.h"
+
+int i915_context_create_ioctl(struct drm_device *dev, void *data,
+ struct drm_file *file)
+{
+ struct drm_i915_gem_context_create *args = data;
+ args->ctx_id = 0;
+ DRM_DEBUG_DRIVER("HW context %d created\n", args->ctx_id);
+ return -EIO;
+}
+
+int i915_context_destroy_ioctl(struct drm_device *dev, void *data,
+ struct drm_file *file)
+{
+ struct drm_i915_gem_context_destroy *args = data;
+ DRM_DEBUG_DRIVER("HW context %d destroyed\n", args->ctx_id);
+ return -EINVAL;
+}
+
+void i915_context_load(struct drm_device *dev)
+{
+
+}
+
+void i915_context_unload(struct drm_device *dev)
+{
+
+}
+
+void i915_context_open(struct drm_device *dev, struct drm_file *file)
+{
+
+}
+
+void i915_context_close(struct drm_device *dev, struct drm_file *file)
+{
+
+}
+
+struct drm_i915_gem_context *i915_get_context(struct drm_file *file,
+ uint32_t id)
+{
+ return NULL;
+}
diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
index 38dfcf9..43acac3 100644
--- a/drivers/gpu/drm/i915/i915_dma.c
+++ b/drivers/gpu/drm/i915/i915_dma.c
@@ -2109,6 +2109,8 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
ips_ping_for_i915_load();
+ i915_context_load(dev);
+
return 0;
out_gem_unload:
@@ -2142,6 +2144,8 @@ int i915_driver_unload(struct drm_device *dev)
struct drm_i915_private *dev_priv = dev->dev_private;
int ret;
+ i915_context_unload(dev);
+
spin_lock(&mchdev_lock);
i915_mch_dev = NULL;
spin_unlock(&mchdev_lock);
@@ -2242,6 +2246,7 @@ int i915_driver_open(struct drm_device *dev, struct drm_file *file)
spin_lock_init(&file_priv->mm.lock);
INIT_LIST_HEAD(&file_priv->mm.request_list);
+ i915_context_open(dev, file);
return 0;
}
@@ -2274,6 +2279,7 @@ void i915_driver_lastclose(struct drm_device * dev)
void i915_driver_preclose(struct drm_device * dev, struct drm_file *file_priv)
{
+ i915_context_close(dev, file_priv);
i915_gem_release(dev, file_priv);
}
@@ -2327,6 +2333,8 @@ struct drm_ioctl_desc i915_ioctls[] = {
DRM_IOCTL_DEF_DRV(I915_OVERLAY_ATTRS, intel_overlay_attrs, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
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_CONTEXT_CREATE, i915_context_create_ioctl, DRM_UNLOCKED),
+ DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_DESTROY, i915_context_destroy_ioctl, DRM_UNLOCKED),
};
int i915_max_ioctl = DRM_ARRAY_SIZE(i915_ioctls);
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 000a9ad..34e6f4f 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -949,6 +949,20 @@ struct drm_i915_file_private {
struct spinlock lock;
struct list_head request_list;
} mm;
+
+ struct spinlock context_idr_lock;
+ struct idr context_idr;
+};
+
+struct drm_i915_gem_context {
+ struct drm_device *dev;
+ struct drm_file *file;
+
+ uint32_t id;
+ uint8_t ring_enable;
+ struct drm_i915_gem_object *obj;
+ bool is_default;
+ bool is_initialized;
};
#define INTEL_INFO(dev) (((struct drm_i915_private *) (dev)->dev_private)->info)
@@ -1022,6 +1036,9 @@ struct drm_i915_file_private {
#define HAS_PCH_CPT(dev) (INTEL_PCH_TYPE(dev) == PCH_CPT)
#define HAS_PCH_IBX(dev) (INTEL_PCH_TYPE(dev) == PCH_IBX)
+/* Contexts are supported on Gen4+, but untested */
+#define HAS_HW_CONTEXTS(dev) (INTEL_INFO(dev)->gen >= 6)
+
#include "i915_trace.h"
extern struct drm_ioctl_desc i915_ioctls[];
@@ -1168,6 +1185,19 @@ int i915_gem_mmap_gtt(struct drm_file *file_priv, struct drm_device *dev,
uint32_t handle, uint64_t *offset);
int i915_gem_dumb_destroy(struct drm_file *file_priv, struct drm_device *dev,
uint32_t handle);
+
+/* i915_context.c */
+int i915_context_create_ioctl(struct drm_device *dev, void *data,
+ struct drm_file *file);
+int i915_context_destroy_ioctl(struct drm_device *dev, void *data,
+ struct drm_file *file);
+extern void i915_context_load(struct drm_device *dev);
+extern void i915_context_unload(struct drm_device *dev);
+extern void i915_context_open(struct drm_device *dev, struct drm_file *file);
+extern void i915_context_close(struct drm_device *dev, struct drm_file *file);
+extern struct drm_i915_gem_context *i915_get_context(struct drm_file *file,
+ uint32_t id);
+
/**
* Returns true if seq1 is later than seq2.
*/
diff --git a/include/drm/i915_drm.h b/include/drm/i915_drm.h
index da929bb..8fa509e 100644
--- a/include/drm/i915_drm.h
+++ b/include/drm/i915_drm.h
@@ -200,6 +200,8 @@ typedef struct _drm_i915_sarea {
#define DRM_I915_GEM_EXECBUFFER2 0x29
#define DRM_I915_GET_SPRITE_COLORKEY 0x2a
#define DRM_I915_SET_SPRITE_COLORKEY 0x2b
+#define DRM_I915_GEM_CONTEXT_CREATE 0x2c
+#define DRM_I915_GEM_CONTEXT_DESTROY 0x2d
#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)
@@ -243,6 +245,9 @@ typedef struct _drm_i915_sarea {
#define DRM_IOCTL_I915_OVERLAY_ATTRS DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_OVERLAY_ATTRS, struct drm_intel_overlay_attrs)
#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_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.
@@ -885,4 +890,16 @@ struct drm_intel_sprite_colorkey {
__u32 flags;
};
+struct drm_i915_gem_context_create {
+ /* output: id of new context*/
+ __u32 ctx_id;
+
+ __u16 pad;
+};
+
+struct drm_i915_gem_context_destroy {
+ __u32 ctx_id;
+ __u32 pad;
+};
+
#endif /* _I915_DRM_H_ */
--
1.7.9
More information about the Intel-gfx
mailing list