Commit c95e7ce3 authored by Chris Wilson's avatar Chris Wilson

drm/i915/selftests: Create a clean GGTT for vma/gtt selftesting

Some tests (e.g. igt_vma_pin1) presume that we have a completely clean
GGTT so that it can probe boundaries without fear that something is
already allocated there. However, the mock device is starting to get
complicated and following similar rules to the live device, i.e. we
can't guarantee that i915->ggtt remains clean, so create a temporary
address_space equivalent to the mock ggtt for the purpose.
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: default avatarMatthew Auld <matthew.auld@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190121222117.23305-7-chris@chris-wilson.co.uk
parent 480cd6dd
...@@ -1267,27 +1267,35 @@ static int exercise_mock(struct drm_i915_private *i915, ...@@ -1267,27 +1267,35 @@ static int exercise_mock(struct drm_i915_private *i915,
static int igt_mock_fill(void *arg) static int igt_mock_fill(void *arg)
{ {
return exercise_mock(arg, fill_hole); struct i915_ggtt *ggtt = arg;
return exercise_mock(ggtt->vm.i915, fill_hole);
} }
static int igt_mock_walk(void *arg) static int igt_mock_walk(void *arg)
{ {
return exercise_mock(arg, walk_hole); struct i915_ggtt *ggtt = arg;
return exercise_mock(ggtt->vm.i915, walk_hole);
} }
static int igt_mock_pot(void *arg) static int igt_mock_pot(void *arg)
{ {
return exercise_mock(arg, pot_hole); struct i915_ggtt *ggtt = arg;
return exercise_mock(ggtt->vm.i915, pot_hole);
} }
static int igt_mock_drunk(void *arg) static int igt_mock_drunk(void *arg)
{ {
return exercise_mock(arg, drunk_hole); struct i915_ggtt *ggtt = arg;
return exercise_mock(ggtt->vm.i915, drunk_hole);
} }
static int igt_gtt_reserve(void *arg) static int igt_gtt_reserve(void *arg)
{ {
struct drm_i915_private *i915 = arg; struct i915_ggtt *ggtt = arg;
struct drm_i915_gem_object *obj, *on; struct drm_i915_gem_object *obj, *on;
LIST_HEAD(objects); LIST_HEAD(objects);
u64 total; u64 total;
...@@ -1300,11 +1308,12 @@ static int igt_gtt_reserve(void *arg) ...@@ -1300,11 +1308,12 @@ static int igt_gtt_reserve(void *arg)
/* Start by filling the GGTT */ /* Start by filling the GGTT */
for (total = 0; for (total = 0;
total + 2*I915_GTT_PAGE_SIZE <= i915->ggtt.vm.total; total + 2 * I915_GTT_PAGE_SIZE <= ggtt->vm.total;
total += 2*I915_GTT_PAGE_SIZE) { total += 2 * I915_GTT_PAGE_SIZE) {
struct i915_vma *vma; struct i915_vma *vma;
obj = i915_gem_object_create_internal(i915, 2*PAGE_SIZE); obj = i915_gem_object_create_internal(ggtt->vm.i915,
2 * PAGE_SIZE);
if (IS_ERR(obj)) { if (IS_ERR(obj)) {
err = PTR_ERR(obj); err = PTR_ERR(obj);
goto out; goto out;
...@@ -1318,20 +1327,20 @@ static int igt_gtt_reserve(void *arg) ...@@ -1318,20 +1327,20 @@ static int igt_gtt_reserve(void *arg)
list_add(&obj->st_link, &objects); list_add(&obj->st_link, &objects);
vma = i915_vma_instance(obj, &i915->ggtt.vm, NULL); vma = i915_vma_instance(obj, &ggtt->vm, NULL);
if (IS_ERR(vma)) { if (IS_ERR(vma)) {
err = PTR_ERR(vma); err = PTR_ERR(vma);
goto out; goto out;
} }
err = i915_gem_gtt_reserve(&i915->ggtt.vm, &vma->node, err = i915_gem_gtt_reserve(&ggtt->vm, &vma->node,
obj->base.size, obj->base.size,
total, total,
obj->cache_level, obj->cache_level,
0); 0);
if (err) { if (err) {
pr_err("i915_gem_gtt_reserve (pass 1) failed at %llu/%llu with err=%d\n", pr_err("i915_gem_gtt_reserve (pass 1) failed at %llu/%llu with err=%d\n",
total, i915->ggtt.vm.total, err); total, ggtt->vm.total, err);
goto out; goto out;
} }
track_vma_bind(vma); track_vma_bind(vma);
...@@ -1349,11 +1358,12 @@ static int igt_gtt_reserve(void *arg) ...@@ -1349,11 +1358,12 @@ static int igt_gtt_reserve(void *arg)
/* Now we start forcing evictions */ /* Now we start forcing evictions */
for (total = I915_GTT_PAGE_SIZE; for (total = I915_GTT_PAGE_SIZE;
total + 2*I915_GTT_PAGE_SIZE <= i915->ggtt.vm.total; total + 2 * I915_GTT_PAGE_SIZE <= ggtt->vm.total;
total += 2*I915_GTT_PAGE_SIZE) { total += 2 * I915_GTT_PAGE_SIZE) {
struct i915_vma *vma; struct i915_vma *vma;
obj = i915_gem_object_create_internal(i915, 2*PAGE_SIZE); obj = i915_gem_object_create_internal(ggtt->vm.i915,
2 * PAGE_SIZE);
if (IS_ERR(obj)) { if (IS_ERR(obj)) {
err = PTR_ERR(obj); err = PTR_ERR(obj);
goto out; goto out;
...@@ -1367,20 +1377,20 @@ static int igt_gtt_reserve(void *arg) ...@@ -1367,20 +1377,20 @@ static int igt_gtt_reserve(void *arg)
list_add(&obj->st_link, &objects); list_add(&obj->st_link, &objects);
vma = i915_vma_instance(obj, &i915->ggtt.vm, NULL); vma = i915_vma_instance(obj, &ggtt->vm, NULL);
if (IS_ERR(vma)) { if (IS_ERR(vma)) {
err = PTR_ERR(vma); err = PTR_ERR(vma);
goto out; goto out;
} }
err = i915_gem_gtt_reserve(&i915->ggtt.vm, &vma->node, err = i915_gem_gtt_reserve(&ggtt->vm, &vma->node,
obj->base.size, obj->base.size,
total, total,
obj->cache_level, obj->cache_level,
0); 0);
if (err) { if (err) {
pr_err("i915_gem_gtt_reserve (pass 2) failed at %llu/%llu with err=%d\n", pr_err("i915_gem_gtt_reserve (pass 2) failed at %llu/%llu with err=%d\n",
total, i915->ggtt.vm.total, err); total, ggtt->vm.total, err);
goto out; goto out;
} }
track_vma_bind(vma); track_vma_bind(vma);
...@@ -1401,7 +1411,7 @@ static int igt_gtt_reserve(void *arg) ...@@ -1401,7 +1411,7 @@ static int igt_gtt_reserve(void *arg)
struct i915_vma *vma; struct i915_vma *vma;
u64 offset; u64 offset;
vma = i915_vma_instance(obj, &i915->ggtt.vm, NULL); vma = i915_vma_instance(obj, &ggtt->vm, NULL);
if (IS_ERR(vma)) { if (IS_ERR(vma)) {
err = PTR_ERR(vma); err = PTR_ERR(vma);
goto out; goto out;
...@@ -1413,18 +1423,18 @@ static int igt_gtt_reserve(void *arg) ...@@ -1413,18 +1423,18 @@ static int igt_gtt_reserve(void *arg)
goto out; goto out;
} }
offset = random_offset(0, i915->ggtt.vm.total, offset = random_offset(0, ggtt->vm.total,
2*I915_GTT_PAGE_SIZE, 2*I915_GTT_PAGE_SIZE,
I915_GTT_MIN_ALIGNMENT); I915_GTT_MIN_ALIGNMENT);
err = i915_gem_gtt_reserve(&i915->ggtt.vm, &vma->node, err = i915_gem_gtt_reserve(&ggtt->vm, &vma->node,
obj->base.size, obj->base.size,
offset, offset,
obj->cache_level, obj->cache_level,
0); 0);
if (err) { if (err) {
pr_err("i915_gem_gtt_reserve (pass 3) failed at %llu/%llu with err=%d\n", pr_err("i915_gem_gtt_reserve (pass 3) failed at %llu/%llu with err=%d\n",
total, i915->ggtt.vm.total, err); total, ggtt->vm.total, err);
goto out; goto out;
} }
track_vma_bind(vma); track_vma_bind(vma);
...@@ -1450,7 +1460,7 @@ static int igt_gtt_reserve(void *arg) ...@@ -1450,7 +1460,7 @@ static int igt_gtt_reserve(void *arg)
static int igt_gtt_insert(void *arg) static int igt_gtt_insert(void *arg)
{ {
struct drm_i915_private *i915 = arg; struct i915_ggtt *ggtt = arg;
struct drm_i915_gem_object *obj, *on; struct drm_i915_gem_object *obj, *on;
struct drm_mm_node tmp = {}; struct drm_mm_node tmp = {};
const struct invalid_insert { const struct invalid_insert {
...@@ -1459,8 +1469,8 @@ static int igt_gtt_insert(void *arg) ...@@ -1459,8 +1469,8 @@ static int igt_gtt_insert(void *arg)
u64 start, end; u64 start, end;
} invalid_insert[] = { } invalid_insert[] = {
{ {
i915->ggtt.vm.total + I915_GTT_PAGE_SIZE, 0, ggtt->vm.total + I915_GTT_PAGE_SIZE, 0,
0, i915->ggtt.vm.total, 0, ggtt->vm.total,
}, },
{ {
2*I915_GTT_PAGE_SIZE, 0, 2*I915_GTT_PAGE_SIZE, 0,
...@@ -1490,7 +1500,7 @@ static int igt_gtt_insert(void *arg) ...@@ -1490,7 +1500,7 @@ static int igt_gtt_insert(void *arg)
/* Check a couple of obviously invalid requests */ /* Check a couple of obviously invalid requests */
for (ii = invalid_insert; ii->size; ii++) { for (ii = invalid_insert; ii->size; ii++) {
err = i915_gem_gtt_insert(&i915->ggtt.vm, &tmp, err = i915_gem_gtt_insert(&ggtt->vm, &tmp,
ii->size, ii->alignment, ii->size, ii->alignment,
I915_COLOR_UNEVICTABLE, I915_COLOR_UNEVICTABLE,
ii->start, ii->end, ii->start, ii->end,
...@@ -1505,11 +1515,12 @@ static int igt_gtt_insert(void *arg) ...@@ -1505,11 +1515,12 @@ static int igt_gtt_insert(void *arg)
/* Start by filling the GGTT */ /* Start by filling the GGTT */
for (total = 0; for (total = 0;
total + I915_GTT_PAGE_SIZE <= i915->ggtt.vm.total; total + I915_GTT_PAGE_SIZE <= ggtt->vm.total;
total += I915_GTT_PAGE_SIZE) { total += I915_GTT_PAGE_SIZE) {
struct i915_vma *vma; struct i915_vma *vma;
obj = i915_gem_object_create_internal(i915, I915_GTT_PAGE_SIZE); obj = i915_gem_object_create_internal(ggtt->vm.i915,
I915_GTT_PAGE_SIZE);
if (IS_ERR(obj)) { if (IS_ERR(obj)) {
err = PTR_ERR(obj); err = PTR_ERR(obj);
goto out; goto out;
...@@ -1523,15 +1534,15 @@ static int igt_gtt_insert(void *arg) ...@@ -1523,15 +1534,15 @@ static int igt_gtt_insert(void *arg)
list_add(&obj->st_link, &objects); list_add(&obj->st_link, &objects);
vma = i915_vma_instance(obj, &i915->ggtt.vm, NULL); vma = i915_vma_instance(obj, &ggtt->vm, NULL);
if (IS_ERR(vma)) { if (IS_ERR(vma)) {
err = PTR_ERR(vma); err = PTR_ERR(vma);
goto out; goto out;
} }
err = i915_gem_gtt_insert(&i915->ggtt.vm, &vma->node, err = i915_gem_gtt_insert(&ggtt->vm, &vma->node,
obj->base.size, 0, obj->cache_level, obj->base.size, 0, obj->cache_level,
0, i915->ggtt.vm.total, 0, ggtt->vm.total,
0); 0);
if (err == -ENOSPC) { if (err == -ENOSPC) {
/* maxed out the GGTT space */ /* maxed out the GGTT space */
...@@ -1540,7 +1551,7 @@ static int igt_gtt_insert(void *arg) ...@@ -1540,7 +1551,7 @@ static int igt_gtt_insert(void *arg)
} }
if (err) { if (err) {
pr_err("i915_gem_gtt_insert (pass 1) failed at %llu/%llu with err=%d\n", pr_err("i915_gem_gtt_insert (pass 1) failed at %llu/%llu with err=%d\n",
total, i915->ggtt.vm.total, err); total, ggtt->vm.total, err);
goto out; goto out;
} }
track_vma_bind(vma); track_vma_bind(vma);
...@@ -1552,7 +1563,7 @@ static int igt_gtt_insert(void *arg) ...@@ -1552,7 +1563,7 @@ static int igt_gtt_insert(void *arg)
list_for_each_entry(obj, &objects, st_link) { list_for_each_entry(obj, &objects, st_link) {
struct i915_vma *vma; struct i915_vma *vma;
vma = i915_vma_instance(obj, &i915->ggtt.vm, NULL); vma = i915_vma_instance(obj, &ggtt->vm, NULL);
if (IS_ERR(vma)) { if (IS_ERR(vma)) {
err = PTR_ERR(vma); err = PTR_ERR(vma);
goto out; goto out;
...@@ -1572,7 +1583,7 @@ static int igt_gtt_insert(void *arg) ...@@ -1572,7 +1583,7 @@ static int igt_gtt_insert(void *arg)
struct i915_vma *vma; struct i915_vma *vma;
u64 offset; u64 offset;
vma = i915_vma_instance(obj, &i915->ggtt.vm, NULL); vma = i915_vma_instance(obj, &ggtt->vm, NULL);
if (IS_ERR(vma)) { if (IS_ERR(vma)) {
err = PTR_ERR(vma); err = PTR_ERR(vma);
goto out; goto out;
...@@ -1587,13 +1598,13 @@ static int igt_gtt_insert(void *arg) ...@@ -1587,13 +1598,13 @@ static int igt_gtt_insert(void *arg)
goto out; goto out;
} }
err = i915_gem_gtt_insert(&i915->ggtt.vm, &vma->node, err = i915_gem_gtt_insert(&ggtt->vm, &vma->node,
obj->base.size, 0, obj->cache_level, obj->base.size, 0, obj->cache_level,
0, i915->ggtt.vm.total, 0, ggtt->vm.total,
0); 0);
if (err) { if (err) {
pr_err("i915_gem_gtt_insert (pass 2) failed at %llu/%llu with err=%d\n", pr_err("i915_gem_gtt_insert (pass 2) failed at %llu/%llu with err=%d\n",
total, i915->ggtt.vm.total, err); total, ggtt->vm.total, err);
goto out; goto out;
} }
track_vma_bind(vma); track_vma_bind(vma);
...@@ -1609,11 +1620,12 @@ static int igt_gtt_insert(void *arg) ...@@ -1609,11 +1620,12 @@ static int igt_gtt_insert(void *arg)
/* And then force evictions */ /* And then force evictions */
for (total = 0; for (total = 0;
total + 2*I915_GTT_PAGE_SIZE <= i915->ggtt.vm.total; total + 2 * I915_GTT_PAGE_SIZE <= ggtt->vm.total;
total += 2*I915_GTT_PAGE_SIZE) { total += 2 * I915_GTT_PAGE_SIZE) {
struct i915_vma *vma; struct i915_vma *vma;
obj = i915_gem_object_create_internal(i915, 2*I915_GTT_PAGE_SIZE); obj = i915_gem_object_create_internal(ggtt->vm.i915,
2 * I915_GTT_PAGE_SIZE);
if (IS_ERR(obj)) { if (IS_ERR(obj)) {
err = PTR_ERR(obj); err = PTR_ERR(obj);
goto out; goto out;
...@@ -1627,19 +1639,19 @@ static int igt_gtt_insert(void *arg) ...@@ -1627,19 +1639,19 @@ static int igt_gtt_insert(void *arg)
list_add(&obj->st_link, &objects); list_add(&obj->st_link, &objects);
vma = i915_vma_instance(obj, &i915->ggtt.vm, NULL); vma = i915_vma_instance(obj, &ggtt->vm, NULL);
if (IS_ERR(vma)) { if (IS_ERR(vma)) {
err = PTR_ERR(vma); err = PTR_ERR(vma);
goto out; goto out;
} }
err = i915_gem_gtt_insert(&i915->ggtt.vm, &vma->node, err = i915_gem_gtt_insert(&ggtt->vm, &vma->node,
obj->base.size, 0, obj->cache_level, obj->base.size, 0, obj->cache_level,
0, i915->ggtt.vm.total, 0, ggtt->vm.total,
0); 0);
if (err) { if (err) {
pr_err("i915_gem_gtt_insert (pass 3) failed at %llu/%llu with err=%d\n", pr_err("i915_gem_gtt_insert (pass 3) failed at %llu/%llu with err=%d\n",
total, i915->ggtt.vm.total, err); total, ggtt->vm.total, err);
goto out; goto out;
} }
track_vma_bind(vma); track_vma_bind(vma);
...@@ -1666,17 +1678,25 @@ int i915_gem_gtt_mock_selftests(void) ...@@ -1666,17 +1678,25 @@ int i915_gem_gtt_mock_selftests(void)
SUBTEST(igt_gtt_insert), SUBTEST(igt_gtt_insert),
}; };
struct drm_i915_private *i915; struct drm_i915_private *i915;
struct i915_ggtt ggtt;
int err; int err;
i915 = mock_gem_device(); i915 = mock_gem_device();
if (!i915) if (!i915)
return -ENOMEM; return -ENOMEM;
mock_init_ggtt(i915, &ggtt);
mutex_lock(&i915->drm.struct_mutex); mutex_lock(&i915->drm.struct_mutex);
err = i915_subtests(tests, i915); err = i915_subtests(tests, &ggtt);
mock_device_flush(i915);
mutex_unlock(&i915->drm.struct_mutex); mutex_unlock(&i915->drm.struct_mutex);
i915_gem_drain_freed_objects(i915);
mock_fini_ggtt(&ggtt);
drm_dev_put(&i915->drm); drm_dev_put(&i915->drm);
return err; return err;
} }
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "mock_gem_device.h" #include "mock_gem_device.h"
#include "mock_context.h" #include "mock_context.h"
#include "mock_gtt.h"
static bool assert_vma(struct i915_vma *vma, static bool assert_vma(struct i915_vma *vma,
struct drm_i915_gem_object *obj, struct drm_i915_gem_object *obj,
...@@ -141,7 +142,8 @@ static int create_vmas(struct drm_i915_private *i915, ...@@ -141,7 +142,8 @@ static int create_vmas(struct drm_i915_private *i915,
static int igt_vma_create(void *arg) static int igt_vma_create(void *arg)
{ {
struct drm_i915_private *i915 = arg; struct i915_ggtt *ggtt = arg;
struct drm_i915_private *i915 = ggtt->vm.i915;
struct drm_i915_gem_object *obj, *on; struct drm_i915_gem_object *obj, *on;
struct i915_gem_context *ctx, *cn; struct i915_gem_context *ctx, *cn;
unsigned long num_obj, num_ctx; unsigned long num_obj, num_ctx;
...@@ -245,7 +247,7 @@ static bool assert_pin_einval(const struct i915_vma *vma, ...@@ -245,7 +247,7 @@ static bool assert_pin_einval(const struct i915_vma *vma,
static int igt_vma_pin1(void *arg) static int igt_vma_pin1(void *arg)
{ {
struct drm_i915_private *i915 = arg; struct i915_ggtt *ggtt = arg;
const struct pin_mode modes[] = { const struct pin_mode modes[] = {
#define VALID(sz, fl) { .size = (sz), .flags = (fl), .assert = assert_pin_valid, .string = #sz ", " #fl ", (valid) " } #define VALID(sz, fl) { .size = (sz), .flags = (fl), .assert = assert_pin_valid, .string = #sz ", " #fl ", (valid) " }
#define __INVALID(sz, fl, check, eval) { .size = (sz), .flags = (fl), .assert = (check), .string = #sz ", " #fl ", (invalid " #eval ")" } #define __INVALID(sz, fl, check, eval) { .size = (sz), .flags = (fl), .assert = (check), .string = #sz ", " #fl ", (invalid " #eval ")" }
...@@ -256,30 +258,30 @@ static int igt_vma_pin1(void *arg) ...@@ -256,30 +258,30 @@ static int igt_vma_pin1(void *arg)
VALID(0, PIN_GLOBAL | PIN_OFFSET_BIAS | 4096), VALID(0, PIN_GLOBAL | PIN_OFFSET_BIAS | 4096),
VALID(0, PIN_GLOBAL | PIN_OFFSET_BIAS | 8192), VALID(0, PIN_GLOBAL | PIN_OFFSET_BIAS | 8192),
VALID(0, PIN_GLOBAL | PIN_OFFSET_BIAS | (i915->ggtt.mappable_end - 4096)), VALID(0, PIN_GLOBAL | PIN_OFFSET_BIAS | (ggtt->mappable_end - 4096)),
VALID(0, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_BIAS | (i915->ggtt.mappable_end - 4096)), VALID(0, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_BIAS | (ggtt->mappable_end - 4096)),
VALID(0, PIN_GLOBAL | PIN_OFFSET_BIAS | (i915->ggtt.vm.total - 4096)), VALID(0, PIN_GLOBAL | PIN_OFFSET_BIAS | (ggtt->vm.total - 4096)),
VALID(0, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_FIXED | (i915->ggtt.mappable_end - 4096)), VALID(0, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_FIXED | (ggtt->mappable_end - 4096)),
INVALID(0, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_FIXED | i915->ggtt.mappable_end), INVALID(0, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_FIXED | ggtt->mappable_end),
VALID(0, PIN_GLOBAL | PIN_OFFSET_FIXED | (i915->ggtt.vm.total - 4096)), VALID(0, PIN_GLOBAL | PIN_OFFSET_FIXED | (ggtt->vm.total - 4096)),
INVALID(0, PIN_GLOBAL | PIN_OFFSET_FIXED | i915->ggtt.vm.total), INVALID(0, PIN_GLOBAL | PIN_OFFSET_FIXED | ggtt->vm.total),
INVALID(0, PIN_GLOBAL | PIN_OFFSET_FIXED | round_down(U64_MAX, PAGE_SIZE)), INVALID(0, PIN_GLOBAL | PIN_OFFSET_FIXED | round_down(U64_MAX, PAGE_SIZE)),
VALID(4096, PIN_GLOBAL), VALID(4096, PIN_GLOBAL),
VALID(8192, PIN_GLOBAL), VALID(8192, PIN_GLOBAL),
VALID(i915->ggtt.mappable_end - 4096, PIN_GLOBAL | PIN_MAPPABLE), VALID(ggtt->mappable_end - 4096, PIN_GLOBAL | PIN_MAPPABLE),
VALID(i915->ggtt.mappable_end, PIN_GLOBAL | PIN_MAPPABLE), VALID(ggtt->mappable_end, PIN_GLOBAL | PIN_MAPPABLE),
NOSPACE(i915->ggtt.mappable_end + 4096, PIN_GLOBAL | PIN_MAPPABLE), NOSPACE(ggtt->mappable_end + 4096, PIN_GLOBAL | PIN_MAPPABLE),
VALID(i915->ggtt.vm.total - 4096, PIN_GLOBAL), VALID(ggtt->vm.total - 4096, PIN_GLOBAL),
VALID(i915->ggtt.vm.total, PIN_GLOBAL), VALID(ggtt->vm.total, PIN_GLOBAL),
NOSPACE(i915->ggtt.vm.total + 4096, PIN_GLOBAL), NOSPACE(ggtt->vm.total + 4096, PIN_GLOBAL),
NOSPACE(round_down(U64_MAX, PAGE_SIZE), PIN_GLOBAL), NOSPACE(round_down(U64_MAX, PAGE_SIZE), PIN_GLOBAL),
INVALID(8192, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_FIXED | (i915->ggtt.mappable_end - 4096)), INVALID(8192, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_FIXED | (ggtt->mappable_end - 4096)),
INVALID(8192, PIN_GLOBAL | PIN_OFFSET_FIXED | (i915->ggtt.vm.total - 4096)), INVALID(8192, PIN_GLOBAL | PIN_OFFSET_FIXED | (ggtt->vm.total - 4096)),
INVALID(8192, PIN_GLOBAL | PIN_OFFSET_FIXED | (round_down(U64_MAX, PAGE_SIZE) - 4096)), INVALID(8192, PIN_GLOBAL | PIN_OFFSET_FIXED | (round_down(U64_MAX, PAGE_SIZE) - 4096)),
VALID(8192, PIN_GLOBAL | PIN_OFFSET_BIAS | (i915->ggtt.mappable_end - 4096)), VALID(8192, PIN_GLOBAL | PIN_OFFSET_BIAS | (ggtt->mappable_end - 4096)),
#if !IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM) #if !IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM)
/* Misusing BIAS is a programming error (it is not controllable /* Misusing BIAS is a programming error (it is not controllable
...@@ -287,10 +289,10 @@ static int igt_vma_pin1(void *arg) ...@@ -287,10 +289,10 @@ static int igt_vma_pin1(void *arg)
* However, the tests are still quite interesting for checking * However, the tests are still quite interesting for checking
* variable start, end and size. * variable start, end and size.
*/ */
NOSPACE(0, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_BIAS | i915->ggtt.mappable_end), NOSPACE(0, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_BIAS | ggtt->mappable_end),
NOSPACE(0, PIN_GLOBAL | PIN_OFFSET_BIAS | i915->ggtt.vm.total), NOSPACE(0, PIN_GLOBAL | PIN_OFFSET_BIAS | ggtt->vm.total),
NOSPACE(8192, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_BIAS | (i915->ggtt.mappable_end - 4096)), NOSPACE(8192, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_BIAS | (ggtt->mappable_end - 4096)),
NOSPACE(8192, PIN_GLOBAL | PIN_OFFSET_BIAS | (i915->ggtt.vm.total - 4096)), NOSPACE(8192, PIN_GLOBAL | PIN_OFFSET_BIAS | (ggtt->vm.total - 4096)),
#endif #endif
{ }, { },
#undef NOSPACE #undef NOSPACE
...@@ -306,13 +308,13 @@ static int igt_vma_pin1(void *arg) ...@@ -306,13 +308,13 @@ static int igt_vma_pin1(void *arg)
* focusing on error handling of boundary conditions. * focusing on error handling of boundary conditions.
*/ */
GEM_BUG_ON(!drm_mm_clean(&i915->ggtt.vm.mm)); GEM_BUG_ON(!drm_mm_clean(&ggtt->vm.mm));
obj = i915_gem_object_create_internal(i915, PAGE_SIZE); obj = i915_gem_object_create_internal(ggtt->vm.i915, PAGE_SIZE);
if (IS_ERR(obj)) if (IS_ERR(obj))
return PTR_ERR(obj); return PTR_ERR(obj);
vma = checked_vma_instance(obj, &i915->ggtt.vm, NULL); vma = checked_vma_instance(obj, &ggtt->vm, NULL);
if (IS_ERR(vma)) if (IS_ERR(vma))
goto out; goto out;
...@@ -403,8 +405,8 @@ static unsigned int rotated_size(const struct intel_rotation_plane_info *a, ...@@ -403,8 +405,8 @@ static unsigned int rotated_size(const struct intel_rotation_plane_info *a,
static int igt_vma_rotate(void *arg) static int igt_vma_rotate(void *arg)
{ {
struct drm_i915_private *i915 = arg; struct i915_ggtt *ggtt = arg;
struct i915_address_space *vm = &i915->ggtt.vm; struct i915_address_space *vm = &ggtt->vm;
struct drm_i915_gem_object *obj; struct drm_i915_gem_object *obj;
const struct intel_rotation_plane_info planes[] = { const struct intel_rotation_plane_info planes[] = {
{ .width = 1, .height = 1, .stride = 1 }, { .width = 1, .height = 1, .stride = 1 },
...@@ -431,7 +433,7 @@ static int igt_vma_rotate(void *arg) ...@@ -431,7 +433,7 @@ static int igt_vma_rotate(void *arg)
* that the page layout within the rotated VMA match our expectations. * that the page layout within the rotated VMA match our expectations.
*/ */
obj = i915_gem_object_create_internal(i915, max_pages * PAGE_SIZE); obj = i915_gem_object_create_internal(vm->i915, max_pages * PAGE_SIZE);
if (IS_ERR(obj)) if (IS_ERR(obj))
goto out; goto out;
...@@ -602,8 +604,8 @@ static bool assert_pin(struct i915_vma *vma, ...@@ -602,8 +604,8 @@ static bool assert_pin(struct i915_vma *vma,
static int igt_vma_partial(void *arg) static int igt_vma_partial(void *arg)
{ {
struct drm_i915_private *i915 = arg; struct i915_ggtt *ggtt = arg;
struct i915_address_space *vm = &i915->ggtt.vm; struct i915_address_space *vm = &ggtt->vm;
const unsigned int npages = 1021; /* prime! */ const unsigned int npages = 1021; /* prime! */
struct drm_i915_gem_object *obj; struct drm_i915_gem_object *obj;
const struct phase { const struct phase {
...@@ -621,7 +623,7 @@ static int igt_vma_partial(void *arg) ...@@ -621,7 +623,7 @@ static int igt_vma_partial(void *arg)
* we are returned the same VMA when we later request the same range. * we are returned the same VMA when we later request the same range.
*/ */
obj = i915_gem_object_create_internal(i915, npages*PAGE_SIZE); obj = i915_gem_object_create_internal(vm->i915, npages * PAGE_SIZE);
if (IS_ERR(obj)) if (IS_ERR(obj))
goto out; goto out;
...@@ -723,17 +725,24 @@ int i915_vma_mock_selftests(void) ...@@ -723,17 +725,24 @@ int i915_vma_mock_selftests(void)
SUBTEST(igt_vma_partial), SUBTEST(igt_vma_partial),
}; };
struct drm_i915_private *i915; struct drm_i915_private *i915;
struct i915_ggtt ggtt;
int err; int err;
i915 = mock_gem_device(); i915 = mock_gem_device();
if (!i915) if (!i915)
return -ENOMEM; return -ENOMEM;
mock_init_ggtt(i915, &ggtt);
mutex_lock(&i915->drm.struct_mutex); mutex_lock(&i915->drm.struct_mutex);
err = i915_subtests(tests, i915); err = i915_subtests(tests, &ggtt);
mock_device_flush(i915);
mutex_unlock(&i915->drm.struct_mutex); mutex_unlock(&i915->drm.struct_mutex);
i915_gem_drain_freed_objects(i915);
mock_fini_ggtt(&ggtt);
drm_dev_put(&i915->drm); drm_dev_put(&i915->drm);
return err; return err;
} }
...@@ -72,7 +72,7 @@ static void mock_device_release(struct drm_device *dev) ...@@ -72,7 +72,7 @@ static void mock_device_release(struct drm_device *dev)
i915_gem_drain_freed_objects(i915); i915_gem_drain_freed_objects(i915);
mutex_lock(&i915->drm.struct_mutex); mutex_lock(&i915->drm.struct_mutex);
mock_fini_ggtt(i915); mock_fini_ggtt(&i915->ggtt);
mutex_unlock(&i915->drm.struct_mutex); mutex_unlock(&i915->drm.struct_mutex);
WARN_ON(!list_empty(&i915->gt.timelines)); WARN_ON(!list_empty(&i915->gt.timelines));
...@@ -232,7 +232,7 @@ struct drm_i915_private *mock_gem_device(void) ...@@ -232,7 +232,7 @@ struct drm_i915_private *mock_gem_device(void)
mutex_lock(&i915->drm.struct_mutex); mutex_lock(&i915->drm.struct_mutex);
mock_init_ggtt(i915); mock_init_ggtt(i915, &i915->ggtt);
mkwrite_device_info(i915)->ring_mask = BIT(0); mkwrite_device_info(i915)->ring_mask = BIT(0);
i915->kernel_context = mock_context(i915, NULL); i915->kernel_context = mock_context(i915, NULL);
......
...@@ -97,9 +97,9 @@ static void mock_unbind_ggtt(struct i915_vma *vma) ...@@ -97,9 +97,9 @@ static void mock_unbind_ggtt(struct i915_vma *vma)
{ {
} }
void mock_init_ggtt(struct drm_i915_private *i915) void mock_init_ggtt(struct drm_i915_private *i915, struct i915_ggtt *ggtt)
{ {
struct i915_ggtt *ggtt = &i915->ggtt; memset(ggtt, 0, sizeof(*ggtt));
ggtt->vm.i915 = i915; ggtt->vm.i915 = i915;
ggtt->vm.is_ggtt = true; ggtt->vm.is_ggtt = true;
...@@ -118,13 +118,10 @@ void mock_init_ggtt(struct drm_i915_private *i915) ...@@ -118,13 +118,10 @@ void mock_init_ggtt(struct drm_i915_private *i915)
ggtt->vm.vma_ops.set_pages = ggtt_set_pages; ggtt->vm.vma_ops.set_pages = ggtt_set_pages;
ggtt->vm.vma_ops.clear_pages = clear_pages; ggtt->vm.vma_ops.clear_pages = clear_pages;
i915_address_space_init(&ggtt->vm, VM_CLASS_GGTT); i915_address_space_init(&ggtt->vm, VM_CLASS_GGTT);
} }
void mock_fini_ggtt(struct drm_i915_private *i915) void mock_fini_ggtt(struct i915_ggtt *ggtt)
{ {
struct i915_ggtt *ggtt = &i915->ggtt;
i915_address_space_fini(&ggtt->vm); i915_address_space_fini(&ggtt->vm);
} }
...@@ -25,8 +25,8 @@ ...@@ -25,8 +25,8 @@
#ifndef __MOCK_GTT_H #ifndef __MOCK_GTT_H
#define __MOCK_GTT_H #define __MOCK_GTT_H
void mock_init_ggtt(struct drm_i915_private *i915); void mock_init_ggtt(struct drm_i915_private *i915, struct i915_ggtt *ggtt);
void mock_fini_ggtt(struct drm_i915_private *i915); void mock_fini_ggtt(struct i915_ggtt *ggtt);
struct i915_hw_ppgtt * struct i915_hw_ppgtt *
mock_ppgtt(struct drm_i915_private *i915, mock_ppgtt(struct drm_i915_private *i915,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment