@@ -606,11 +606,17 @@ static int igt_vma_partial(void *arg)
struct drm_i915_private *i915 = arg;
struct i915_address_space *vm = &i915->ggtt.base;
const unsigned int npages = 1021; /* prime! */
- struct drm_i915_gem_object *obj;
+ struct drm_i915_gem_object *obj = NULL;
const struct phase {
const char *name;
+ unsigned int flags;
+#define CREATE BIT(0)
+#define WHOLE BIT(1)
} phases[] = {
- { "create" },
+ { "create", CREATE },
+ { "lookup" },
+ { "whole", WHOLE },
+ { "recreate", CREATE | WHOLE },
{ "lookup" },
{ },
}, *p;
@@ -618,17 +624,44 @@ static int igt_vma_partial(void *arg)
struct i915_vma *vma;
int err = -ENOMEM;
- /* Create lots of different VMA for the object and check that
+ /*
+ * Create lots of different VMA for the object and check that
* we are returned the same VMA when we later request the same range.
*/
- obj = i915_gem_object_create_internal(i915, npages*PAGE_SIZE);
- if (IS_ERR(obj))
- goto out;
-
for (p = phases; p->name; p++) { /* exercise both create/lookup */
unsigned int count, nvma;
+ if (p->flags & CREATE) {
+ if (obj)
+ i915_gem_object_put(obj);
+
+ obj = i915_gem_object_create_internal(i915,
+ npages*PAGE_SIZE);
+ if (IS_ERR(obj))
+ goto out;
+ }
+
+ if (p->flags & WHOLE) {
+ /*
+ * Make sure we can create mappable partial vma
+ * while the whole object is in use elsewhere.
+ */
+ vma = i915_vma_instance(obj, vm, NULL);
+ if (IS_ERR(vma)) {
+ err = PTR_ERR(vma);
+ goto out_object;
+ }
+
+ err = i915_vma_unbind(vma);
+ if (err)
+ goto out_object;
+
+ err = i915_vma_pin(vma, 0, 0, PIN_GLOBAL | PIN_HIGH);
+ if (err)
+ goto out_object;
+ }
+
nvma = 0;
for_each_prime_number_from(sz, 1, npages) {
for_each_prime_number_from(offset, 0, npages - sz) {
@@ -707,12 +740,24 @@ static int igt_vma_partial(void *arg)
err = -EINVAL;
goto out_object;
}
+
+ if (p->flags & WHOLE) {
+ vma = i915_vma_instance(obj, vm, NULL);
+ if (IS_ERR(vma)) {
+ err = PTR_ERR(vma);
+ goto out_object;
+ }
+
+ i915_vma_unpin(vma);
+ }
}
out_object:
i915_gem_object_put(obj);
out:
return err;
+#undef CREATE
+#undef WHOLE
}
int i915_vma_mock_selftests(void)