summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Widawsky <benjamin.widawsky@intel.com>2014-05-09 19:34:33 -0700
committerBen Widawsky <benjamin.widawsky@intel.com>2014-06-20 18:36:15 -0700
commit7010548d94215db483feee750e599efb98cd8647 (patch)
tree4a8040e85e72d9fe7e12f8e0f7fccdf8d3917a16
parent7772a5f084348cedd6557f3dc2d79f12e39c5823 (diff)
drm/i915: Track userptr VMAs
This HACK allows users to reuse the userptr ioctl in order to pre-reserve the VMA at a specific location. The vma will follow all the same paths as other userptr objects - only the drm_mm node is actually allocated. Again, this patch is a big HACK to get some other people currently using userptr enabled. Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
-rw-r--r--drivers/gpu/drm/i915/i915_drv.h3
-rw-r--r--drivers/gpu/drm/i915/i915_gem.c22
-rw-r--r--drivers/gpu/drm/i915/i915_gem_execbuffer.c3
-rw-r--r--drivers/gpu/drm/i915/i915_gem_gtt.h4
4 files changed, 28 insertions, 4 deletions
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 2187dd03759f..64cb0eb7ccc0 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -2225,7 +2225,8 @@ void i915_gem_vma_destroy(struct i915_vma *vma);
#define PIN_GLOBAL (1<<2)
#define PIN_ALIASING (1<<3)
#define PIN_GLOBAL_ALIASED (PIN_ALIASING | PIN_GLOBAL)
-#define PIN_OFFSET_BIAS (1<<4)
+#define PIN_BOUND (1<<4)
+#define PIN_OFFSET_BIAS (1<<5)
#define PIN_OFFSET_MASK (PAGE_MASK)
int __must_check i915_gem_object_pin(struct drm_i915_gem_object *obj,
struct i915_address_space *vm,
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 7d47b761b8b1..d9c050657b01 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -3436,7 +3436,13 @@ i915_gem_object_bind_to_vm(struct drm_i915_gem_object *obj,
if (IS_ERR(vma))
goto err_unpin;
+ if (flags & PIN_BOUND) {
+ WARN_ON(!vma->node.allocated && !vma->obj->userptr.ptr);
+ goto skip_search;
+ }
+
search_free:
+ WARN_ON(vma->node.allocated);
ret = drm_mm_insert_node_in_range_generic(&vm->mm, &vma->node,
size, alignment,
obj->cache_level,
@@ -3453,6 +3459,7 @@ search_free:
goto err_free_vma;
}
+skip_search:
if (WARN_ON(!i915_gem_valid_gtt_space(dev, &vma->node,
obj->cache_level))) {
ret = -EINVAL;
@@ -3489,10 +3496,13 @@ search_free:
i915_gem_vma_bind(vma, obj->cache_level, vma_bind_flags);
i915_gem_verify_gtt(dev);
+ if (flags & PIN_BOUND)
+ vma->uptr_bind=1;
return vma;
err_remove_node:
- drm_mm_remove_node(&vma->node);
+ if ((flags & PIN_BOUND) == 0)
+ drm_mm_remove_node(&vma->node);
err_free_vma:
i915_gem_vma_destroy(vma);
vma = ERR_PTR(ret);
@@ -4076,6 +4086,11 @@ i915_gem_object_pin(struct drm_i915_gem_object *obj,
if (WARN_ON(flags & (PIN_GLOBAL | PIN_MAPPABLE) && !i915_is_ggtt(vm)))
return -EINVAL;
+ if (flags & PIN_BOUND) {
+ if (WARN_ON(flags & ~PIN_BOUND))
+ return -EINVAL;
+ }
+
vma = i915_gem_obj_to_vma(obj, vm);
if (vma) {
if (WARN_ON(vma->pin_count == DRM_I915_GEM_OBJECT_MAX_PIN_COUNT))
@@ -4097,7 +4112,8 @@ i915_gem_object_pin(struct drm_i915_gem_object *obj,
}
}
- if (vma == NULL || !drm_mm_node_allocated(&vma->node)) {
+ if (vma == NULL || !drm_mm_node_allocated(&vma->node) ||
+ ((flags & PIN_BOUND) && !vma->uptr_bind)) {
vma = i915_gem_object_bind_to_vm(obj, vm, alignment, flags);
if (IS_ERR(vma))
return PTR_ERR(vma);
@@ -4516,7 +4532,7 @@ struct i915_vma *i915_gem_obj_to_vma(struct drm_i915_gem_object *obj,
void i915_gem_vma_destroy(struct i915_vma *vma)
{
- WARN_ON(vma->node.allocated);
+ WARN_ON(vma->node.allocated && !vma->uptr);
/* Keep the vma as a placeholder in the execbuffer reservation lists */
if (!list_empty(&vma->exec_list))
diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
index 338b1c05be39..869b56cedd7c 100644
--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
@@ -571,6 +571,9 @@ i915_gem_execbuffer_reserve_vma(struct i915_vma *vma,
if (entry->flags & __EXEC_OBJECT_NEEDS_BIAS)
flags |= BATCH_OFFSET_BIAS | PIN_OFFSET_BIAS;
+ if (vma->uptr)
+ flags |= PIN_BOUND;
+
ret = i915_gem_object_pin(obj, vma->vm, entry->alignment, flags);
if (ret)
return ret;
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h b/drivers/gpu/drm/i915/i915_gem_gtt.h
index 7e3ac3597104..2e9d598dcba1 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.h
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.h
@@ -171,6 +171,10 @@ struct i915_vma {
unsigned int pin_count:4;
#define DRM_I915_GEM_OBJECT_MAX_PIN_COUNT 0xf
+ /* FIXME: */
+ unsigned int uptr:1; /* Whether this VMA has been userptr'd */
+ unsigned int uptr_bind:1; /* Whether we've actually bound it */
+
/** Unmap an object from an address space. This usually consists of
* setting the valid PTE entries to a reserved scratch page. */
void (*unbind_vma)(struct i915_vma *vma);