2 * Copyright © 2016 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 #include <linux/prime_numbers.h>
27 #include "gem/selftests/mock_context.h"
29 #include "i915_scatterlist.h"
30 #include "i915_selftest.h"
32 #include "mock_gem_device.h"
35 static bool assert_vma(struct i915_vma *vma,
36 struct drm_i915_gem_object *obj,
37 struct i915_gem_context *ctx)
41 if (vma->vm != ctx->vm) {
42 pr_err("VMA created with wrong VM\n");
46 if (vma->size != obj->base.size) {
47 pr_err("VMA created with wrong size, found %llu, expected %zu\n",
48 vma->size, obj->base.size);
52 if (vma->ggtt_view.type != I915_GGTT_VIEW_NORMAL) {
53 pr_err("VMA created with wrong type [%d]\n",
61 static struct i915_vma *
62 checked_vma_instance(struct drm_i915_gem_object *obj,
63 struct i915_address_space *vm,
64 const struct i915_ggtt_view *view)
69 vma = i915_vma_instance(obj, vm, view);
73 /* Manual checks, will be reinforced by i915_vma_compare! */
75 pr_err("VMA's vm [%p] does not match request [%p]\n",
80 if (i915_is_ggtt(vm) != i915_vma_is_ggtt(vma)) {
81 pr_err("VMA ggtt status [%d] does not match parent [%d]\n",
82 i915_vma_is_ggtt(vma), i915_is_ggtt(vm));
86 if (i915_vma_compare(vma, vm, view)) {
87 pr_err("i915_vma_compare failed with create parameters!\n");
88 return ERR_PTR(-EINVAL);
91 if (i915_vma_compare(vma, vma->vm,
92 i915_vma_is_ggtt(vma) ? &vma->ggtt_view : NULL)) {
93 pr_err("i915_vma_compare failed with itself\n");
94 return ERR_PTR(-EINVAL);
98 pr_err("i915_vma_compare failed to detect the difference!\n");
99 return ERR_PTR(-EINVAL);
105 static int create_vmas(struct drm_i915_private *i915,
106 struct list_head *objects,
107 struct list_head *contexts)
109 struct drm_i915_gem_object *obj;
110 struct i915_gem_context *ctx;
113 list_for_each_entry(obj, objects, st_link) {
114 for (pinned = 0; pinned <= 1; pinned++) {
115 list_for_each_entry(ctx, contexts, link) {
116 struct i915_address_space *vm = ctx->vm;
117 struct i915_vma *vma;
120 vma = checked_vma_instance(obj, vm, NULL);
124 if (!assert_vma(vma, obj, ctx)) {
125 pr_err("VMA lookup/create failed\n");
130 err = i915_vma_pin(vma, 0, 0, PIN_USER);
132 pr_err("Failed to pin VMA\n");
145 static int igt_vma_create(void *arg)
147 struct i915_ggtt *ggtt = arg;
148 struct drm_i915_private *i915 = ggtt->vm.i915;
149 struct drm_i915_gem_object *obj, *on;
150 struct i915_gem_context *ctx, *cn;
151 unsigned long num_obj, num_ctx;
152 unsigned long no, nc;
153 IGT_TIMEOUT(end_time);
158 /* Exercise creating many vma amonst many objections, checking the
159 * vma creation and lookup routines.
163 for_each_prime_number(num_obj, ULONG_MAX - 1) {
164 for (; no < num_obj; no++) {
165 obj = i915_gem_object_create_internal(i915, PAGE_SIZE);
169 list_add(&obj->st_link, &objects);
173 for_each_prime_number(num_ctx, MAX_CONTEXT_HW_ID) {
174 for (; nc < num_ctx; nc++) {
175 ctx = mock_context(i915, "mock");
179 list_move(&ctx->link, &contexts);
182 err = create_vmas(i915, &objects, &contexts);
186 if (igt_timeout(end_time,
187 "%s timed out: after %lu objects in %lu contexts\n",
192 list_for_each_entry_safe(ctx, cn, &contexts, link) {
193 list_del_init(&ctx->link);
194 mock_context_close(ctx);
199 /* Final pass to lookup all created contexts */
200 err = create_vmas(i915, &objects, &contexts);
202 list_for_each_entry_safe(ctx, cn, &contexts, link) {
203 list_del_init(&ctx->link);
204 mock_context_close(ctx);
207 list_for_each_entry_safe(obj, on, &objects, st_link)
208 i915_gem_object_put(obj);
215 bool (*assert)(const struct i915_vma *,
216 const struct pin_mode *mode,
221 static bool assert_pin_valid(const struct i915_vma *vma,
222 const struct pin_mode *mode,
228 if (i915_vma_misplaced(vma, mode->size, 0, mode->flags))
235 static bool assert_pin_enospc(const struct i915_vma *vma,
236 const struct pin_mode *mode,
239 return result == -ENOSPC;
243 static bool assert_pin_einval(const struct i915_vma *vma,
244 const struct pin_mode *mode,
247 return result == -EINVAL;
250 static int igt_vma_pin1(void *arg)
252 struct i915_ggtt *ggtt = arg;
253 const struct pin_mode modes[] = {
254 #define VALID(sz, fl) { .size = (sz), .flags = (fl), .assert = assert_pin_valid, .string = #sz ", " #fl ", (valid) " }
255 #define __INVALID(sz, fl, check, eval) { .size = (sz), .flags = (fl), .assert = (check), .string = #sz ", " #fl ", (invalid " #eval ")" }
256 #define INVALID(sz, fl) __INVALID(sz, fl, assert_pin_einval, EINVAL)
257 #define NOSPACE(sz, fl) __INVALID(sz, fl, assert_pin_enospc, ENOSPC)
258 VALID(0, PIN_GLOBAL),
259 VALID(0, PIN_GLOBAL | PIN_MAPPABLE),
261 VALID(0, PIN_GLOBAL | PIN_OFFSET_BIAS | 4096),
262 VALID(0, PIN_GLOBAL | PIN_OFFSET_BIAS | 8192),
263 VALID(0, PIN_GLOBAL | PIN_OFFSET_BIAS | (ggtt->mappable_end - 4096)),
264 VALID(0, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_BIAS | (ggtt->mappable_end - 4096)),
265 VALID(0, PIN_GLOBAL | PIN_OFFSET_BIAS | (ggtt->vm.total - 4096)),
267 VALID(0, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_FIXED | (ggtt->mappable_end - 4096)),
268 INVALID(0, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_FIXED | ggtt->mappable_end),
269 VALID(0, PIN_GLOBAL | PIN_OFFSET_FIXED | (ggtt->vm.total - 4096)),
270 INVALID(0, PIN_GLOBAL | PIN_OFFSET_FIXED | ggtt->vm.total),
271 INVALID(0, PIN_GLOBAL | PIN_OFFSET_FIXED | round_down(U64_MAX, PAGE_SIZE)),
273 VALID(4096, PIN_GLOBAL),
274 VALID(8192, PIN_GLOBAL),
275 VALID(ggtt->mappable_end - 4096, PIN_GLOBAL | PIN_MAPPABLE),
276 VALID(ggtt->mappable_end, PIN_GLOBAL | PIN_MAPPABLE),
277 NOSPACE(ggtt->mappable_end + 4096, PIN_GLOBAL | PIN_MAPPABLE),
278 VALID(ggtt->vm.total - 4096, PIN_GLOBAL),
279 VALID(ggtt->vm.total, PIN_GLOBAL),
280 NOSPACE(ggtt->vm.total + 4096, PIN_GLOBAL),
281 NOSPACE(round_down(U64_MAX, PAGE_SIZE), PIN_GLOBAL),
282 INVALID(8192, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_FIXED | (ggtt->mappable_end - 4096)),
283 INVALID(8192, PIN_GLOBAL | PIN_OFFSET_FIXED | (ggtt->vm.total - 4096)),
284 INVALID(8192, PIN_GLOBAL | PIN_OFFSET_FIXED | (round_down(U64_MAX, PAGE_SIZE) - 4096)),
286 VALID(8192, PIN_GLOBAL | PIN_OFFSET_BIAS | (ggtt->mappable_end - 4096)),
288 #if !IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM)
289 /* Misusing BIAS is a programming error (it is not controllable
290 * from userspace) so when debugging is enabled, it explodes.
291 * However, the tests are still quite interesting for checking
292 * variable start, end and size.
294 NOSPACE(0, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_BIAS | ggtt->mappable_end),
295 NOSPACE(0, PIN_GLOBAL | PIN_OFFSET_BIAS | ggtt->vm.total),
296 NOSPACE(8192, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_BIAS | (ggtt->mappable_end - 4096)),
297 NOSPACE(8192, PIN_GLOBAL | PIN_OFFSET_BIAS | (ggtt->vm.total - 4096)),
305 struct drm_i915_gem_object *obj;
306 struct i915_vma *vma;
309 /* Exercise all the weird and wonderful i915_vma_pin requests,
310 * focusing on error handling of boundary conditions.
313 GEM_BUG_ON(!drm_mm_clean(&ggtt->vm.mm));
315 obj = i915_gem_object_create_internal(ggtt->vm.i915, PAGE_SIZE);
319 vma = checked_vma_instance(obj, &ggtt->vm, NULL);
323 for (m = modes; m->assert; m++) {
324 err = i915_vma_pin(vma, m->size, 0, m->flags);
325 if (!m->assert(vma, m, err)) {
326 pr_err("%s to pin single page into GGTT with mode[%d:%s]: size=%llx flags=%llx, err=%d\n",
327 m->assert == assert_pin_valid ? "Failed" : "Unexpectedly succeeded",
328 (int)(m - modes), m->string, m->size, m->flags,
338 err = i915_vma_unbind(vma);
340 pr_err("Failed to unbind single page from GGTT, err=%d\n", err);
348 i915_gem_object_put(obj);
352 static unsigned long rotated_index(const struct intel_rotation_info *r,
357 return (r->plane[n].stride * (r->plane[n].height - y - 1) +
358 r->plane[n].offset + x);
361 static struct scatterlist *
362 assert_rotated(struct drm_i915_gem_object *obj,
363 const struct intel_rotation_info *r, unsigned int n,
364 struct scatterlist *sg)
368 for (x = 0; x < r->plane[n].width; x++) {
369 for (y = 0; y < r->plane[n].height; y++) {
370 unsigned long src_idx;
374 pr_err("Invalid sg table: too short at plane %d, (%d, %d)!\n",
376 return ERR_PTR(-EINVAL);
379 src_idx = rotated_index(r, n, x, y);
380 src = i915_gem_object_get_dma_address(obj, src_idx);
382 if (sg_dma_len(sg) != PAGE_SIZE) {
383 pr_err("Invalid sg.length, found %d, expected %lu for rotated page (%d, %d) [src index %lu]\n",
384 sg_dma_len(sg), PAGE_SIZE,
386 return ERR_PTR(-EINVAL);
389 if (sg_dma_address(sg) != src) {
390 pr_err("Invalid address for rotated page (%d, %d) [src index %lu]\n",
392 return ERR_PTR(-EINVAL);
402 static unsigned long remapped_index(const struct intel_remapped_info *r,
407 return (r->plane[n].stride * y +
408 r->plane[n].offset + x);
411 static struct scatterlist *
412 assert_remapped(struct drm_i915_gem_object *obj,
413 const struct intel_remapped_info *r, unsigned int n,
414 struct scatterlist *sg)
417 unsigned int left = 0;
420 for (y = 0; y < r->plane[n].height; y++) {
421 for (x = 0; x < r->plane[n].width; x++) {
422 unsigned long src_idx;
426 pr_err("Invalid sg table: too short at plane %d, (%d, %d)!\n",
428 return ERR_PTR(-EINVAL);
432 left = sg_dma_len(sg);
435 src_idx = remapped_index(r, n, x, y);
436 src = i915_gem_object_get_dma_address(obj, src_idx);
438 if (left < PAGE_SIZE || left & (PAGE_SIZE-1)) {
439 pr_err("Invalid sg.length, found %d, expected %lu for remapped page (%d, %d) [src index %lu]\n",
440 sg_dma_len(sg), PAGE_SIZE,
442 return ERR_PTR(-EINVAL);
445 if (sg_dma_address(sg) + offset != src) {
446 pr_err("Invalid address for remapped page (%d, %d) [src index %lu]\n",
448 return ERR_PTR(-EINVAL);
463 static unsigned int rotated_size(const struct intel_remapped_plane_info *a,
464 const struct intel_remapped_plane_info *b)
466 return a->width * a->height + b->width * b->height;
469 static int igt_vma_rotate_remap(void *arg)
471 struct i915_ggtt *ggtt = arg;
472 struct i915_address_space *vm = &ggtt->vm;
473 struct drm_i915_gem_object *obj;
474 const struct intel_remapped_plane_info planes[] = {
475 { .width = 1, .height = 1, .stride = 1 },
476 { .width = 2, .height = 2, .stride = 2 },
477 { .width = 4, .height = 4, .stride = 4 },
478 { .width = 8, .height = 8, .stride = 8 },
480 { .width = 3, .height = 5, .stride = 3 },
481 { .width = 3, .height = 5, .stride = 4 },
482 { .width = 3, .height = 5, .stride = 5 },
484 { .width = 5, .height = 3, .stride = 5 },
485 { .width = 5, .height = 3, .stride = 7 },
486 { .width = 5, .height = 3, .stride = 9 },
488 { .width = 4, .height = 6, .stride = 6 },
489 { .width = 6, .height = 4, .stride = 6 },
492 enum i915_ggtt_view_type types[] = {
493 I915_GGTT_VIEW_ROTATED,
494 I915_GGTT_VIEW_REMAPPED,
497 const unsigned int max_pages = 64;
500 /* Create VMA for many different combinations of planes and check
501 * that the page layout within the rotated VMA match our expectations.
504 obj = i915_gem_object_create_internal(vm->i915, max_pages * PAGE_SIZE);
508 for (t = types; *t; t++) {
509 for (a = planes; a->width; a++) {
510 for (b = planes + ARRAY_SIZE(planes); b-- != planes; ) {
511 struct i915_ggtt_view view;
512 unsigned int n, max_offset;
514 max_offset = max(a->stride * a->height,
515 b->stride * b->height);
516 GEM_BUG_ON(max_offset > max_pages);
517 max_offset = max_pages - max_offset;
520 view.rotated.plane[0] = *a;
521 view.rotated.plane[1] = *b;
523 for_each_prime_number_from(view.rotated.plane[0].offset, 0, max_offset) {
524 for_each_prime_number_from(view.rotated.plane[1].offset, 0, max_offset) {
525 struct scatterlist *sg;
526 struct i915_vma *vma;
528 vma = checked_vma_instance(obj, vm, &view);
534 err = i915_vma_pin(vma, 0, 0, PIN_GLOBAL);
536 pr_err("Failed to pin VMA, err=%d\n", err);
540 if (view.type == I915_GGTT_VIEW_ROTATED &&
541 vma->size != rotated_size(a, b) * PAGE_SIZE) {
542 pr_err("VMA is wrong size, expected %lu, found %llu\n",
543 PAGE_SIZE * rotated_size(a, b), vma->size);
548 if (view.type == I915_GGTT_VIEW_REMAPPED &&
549 vma->size > rotated_size(a, b) * PAGE_SIZE) {
550 pr_err("VMA is wrong size, expected %lu, found %llu\n",
551 PAGE_SIZE * rotated_size(a, b), vma->size);
556 if (vma->pages->nents > rotated_size(a, b)) {
557 pr_err("sg table is wrong sizeo, expected %u, found %u nents\n",
558 rotated_size(a, b), vma->pages->nents);
563 if (vma->node.size < vma->size) {
564 pr_err("VMA binding too small, expected %llu, found %llu\n",
565 vma->size, vma->node.size);
570 if (vma->pages == obj->mm.pages) {
571 pr_err("VMA using unrotated object pages!\n");
576 sg = vma->pages->sgl;
577 for (n = 0; n < ARRAY_SIZE(view.rotated.plane); n++) {
578 if (view.type == I915_GGTT_VIEW_ROTATED)
579 sg = assert_rotated(obj, &view.rotated, n, sg);
581 sg = assert_remapped(obj, &view.remapped, n, sg);
583 pr_err("Inconsistent %s VMA pages for plane %d: [(%d, %d, %d, %d), (%d, %d, %d, %d)]\n",
584 view.type == I915_GGTT_VIEW_ROTATED ?
585 "rotated" : "remapped", n,
586 view.rotated.plane[0].width,
587 view.rotated.plane[0].height,
588 view.rotated.plane[0].stride,
589 view.rotated.plane[0].offset,
590 view.rotated.plane[1].width,
591 view.rotated.plane[1].height,
592 view.rotated.plane[1].stride,
593 view.rotated.plane[1].offset);
607 i915_gem_object_put(obj);
612 static bool assert_partial(struct drm_i915_gem_object *obj,
613 struct i915_vma *vma,
614 unsigned long offset,
620 for_each_sgt_dma(dma, sgt, vma->pages) {
624 pr_err("Partial scattergather list too long\n");
628 src = i915_gem_object_get_dma_address(obj, offset);
630 pr_err("DMA mismatch for partial page offset %lu\n",
642 static bool assert_pin(struct i915_vma *vma,
643 struct i915_ggtt_view *view,
649 if (vma->size != size) {
650 pr_err("(%s) VMA is wrong size, expected %llu, found %llu\n",
651 name, size, vma->size);
655 if (vma->node.size < vma->size) {
656 pr_err("(%s) VMA binding too small, expected %llu, found %llu\n",
657 name, vma->size, vma->node.size);
661 if (view && view->type != I915_GGTT_VIEW_NORMAL) {
662 if (memcmp(&vma->ggtt_view, view, sizeof(*view))) {
663 pr_err("(%s) VMA mismatch upon creation!\n",
668 if (vma->pages == vma->obj->mm.pages) {
669 pr_err("(%s) VMA using original object pages!\n",
674 if (vma->ggtt_view.type != I915_GGTT_VIEW_NORMAL) {
675 pr_err("Not the normal ggtt view! Found %d\n",
676 vma->ggtt_view.type);
680 if (vma->pages != vma->obj->mm.pages) {
681 pr_err("VMA not using object pages!\n");
689 static int igt_vma_partial(void *arg)
691 struct i915_ggtt *ggtt = arg;
692 struct i915_address_space *vm = &ggtt->vm;
693 const unsigned int npages = 1021; /* prime! */
694 struct drm_i915_gem_object *obj;
702 unsigned int sz, offset;
703 struct i915_vma *vma;
706 /* Create lots of different VMA for the object and check that
707 * we are returned the same VMA when we later request the same range.
710 obj = i915_gem_object_create_internal(vm->i915, npages * PAGE_SIZE);
714 for (p = phases; p->name; p++) { /* exercise both create/lookup */
715 unsigned int count, nvma;
718 for_each_prime_number_from(sz, 1, npages) {
719 for_each_prime_number_from(offset, 0, npages - sz) {
720 struct i915_ggtt_view view;
722 view.type = I915_GGTT_VIEW_PARTIAL;
723 view.partial.offset = offset;
724 view.partial.size = sz;
727 view.type = I915_GGTT_VIEW_NORMAL;
729 vma = checked_vma_instance(obj, vm, &view);
735 err = i915_vma_pin(vma, 0, 0, PIN_GLOBAL);
739 if (!assert_pin(vma, &view, sz*PAGE_SIZE, p->name)) {
740 pr_err("(%s) Inconsistent partial pinning for (offset=%d, size=%d)\n",
741 p->name, offset, sz);
746 if (!assert_partial(obj, vma, offset, sz)) {
747 pr_err("(%s) Inconsistent partial pages for (offset=%d, size=%d)\n",
748 p->name, offset, sz);
759 list_for_each_entry(vma, &obj->vma.list, obj_link)
762 pr_err("(%s) All partial vma were not recorded on the obj->vma_list: found %u, expected %u\n",
763 p->name, count, nvma);
768 /* Check that we did create the whole object mapping */
769 vma = checked_vma_instance(obj, vm, NULL);
775 err = i915_vma_pin(vma, 0, 0, PIN_GLOBAL);
779 if (!assert_pin(vma, NULL, obj->base.size, p->name)) {
780 pr_err("(%s) inconsistent full pin\n", p->name);
788 list_for_each_entry(vma, &obj->vma.list, obj_link)
791 pr_err("(%s) allocated an extra full vma!\n", p->name);
798 i915_gem_object_put(obj);
803 int i915_vma_mock_selftests(void)
805 static const struct i915_subtest tests[] = {
806 SUBTEST(igt_vma_create),
807 SUBTEST(igt_vma_pin1),
808 SUBTEST(igt_vma_rotate_remap),
809 SUBTEST(igt_vma_partial),
811 struct drm_i915_private *i915;
812 struct i915_ggtt *ggtt;
815 i915 = mock_gem_device();
819 ggtt = kmalloc(sizeof(*ggtt), GFP_KERNEL);
824 mock_init_ggtt(i915, ggtt);
826 mutex_lock(&i915->drm.struct_mutex);
827 err = i915_subtests(tests, ggtt);
828 mock_device_flush(i915);
829 mutex_unlock(&i915->drm.struct_mutex);
831 i915_gem_drain_freed_objects(i915);
833 mock_fini_ggtt(ggtt);
836 drm_dev_put(&i915->drm);
840 static int igt_vma_remapped_gtt(void *arg)
842 struct drm_i915_private *i915 = arg;
843 const struct intel_remapped_plane_info planes[] = {
844 { .width = 1, .height = 1, .stride = 1 },
845 { .width = 2, .height = 2, .stride = 2 },
846 { .width = 4, .height = 4, .stride = 4 },
847 { .width = 8, .height = 8, .stride = 8 },
849 { .width = 3, .height = 5, .stride = 3 },
850 { .width = 3, .height = 5, .stride = 4 },
851 { .width = 3, .height = 5, .stride = 5 },
853 { .width = 5, .height = 3, .stride = 5 },
854 { .width = 5, .height = 3, .stride = 7 },
855 { .width = 5, .height = 3, .stride = 9 },
857 { .width = 4, .height = 6, .stride = 6 },
858 { .width = 6, .height = 4, .stride = 6 },
861 enum i915_ggtt_view_type types[] = {
862 I915_GGTT_VIEW_ROTATED,
863 I915_GGTT_VIEW_REMAPPED,
866 struct drm_i915_gem_object *obj;
867 intel_wakeref_t wakeref;
870 obj = i915_gem_object_create_internal(i915, 10 * 10 * PAGE_SIZE);
874 mutex_lock(&i915->drm.struct_mutex);
876 wakeref = intel_runtime_pm_get(&i915->runtime_pm);
878 for (t = types; *t; t++) {
879 for (p = planes; p->width; p++) {
880 struct i915_ggtt_view view = {
882 .rotated.plane[0] = *p,
884 struct i915_vma *vma;
889 i915_gem_object_lock(obj);
890 err = i915_gem_object_set_to_gtt_domain(obj, true);
891 i915_gem_object_unlock(obj);
895 vma = i915_gem_object_ggtt_pin(obj, &view, 0, 0, PIN_MAPPABLE);
901 GEM_BUG_ON(vma->ggtt_view.type != *t);
903 map = i915_vma_pin_iomap(vma);
910 for (y = 0 ; y < p->height; y++) {
911 for (x = 0 ; x < p->width; x++) {
913 u32 val = y << 16 | x;
915 if (*t == I915_GGTT_VIEW_ROTATED)
916 offset = (x * p->height + y) * PAGE_SIZE;
918 offset = (y * p->width + x) * PAGE_SIZE;
920 iowrite32(val, &map[offset / sizeof(*map)]);
924 i915_vma_unpin_iomap(vma);
926 vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, PIN_MAPPABLE);
932 GEM_BUG_ON(vma->ggtt_view.type != I915_GGTT_VIEW_NORMAL);
934 map = i915_vma_pin_iomap(vma);
941 for (y = 0 ; y < p->height; y++) {
942 for (x = 0 ; x < p->width; x++) {
943 unsigned int offset, src_idx;
944 u32 exp = y << 16 | x;
947 if (*t == I915_GGTT_VIEW_ROTATED)
948 src_idx = rotated_index(&view.rotated, 0, x, y);
950 src_idx = remapped_index(&view.remapped, 0, x, y);
951 offset = src_idx * PAGE_SIZE;
953 val = ioread32(&map[offset / sizeof(*map)]);
955 pr_err("%s VMA write test failed, expected 0x%x, found 0x%x\n",
956 *t == I915_GGTT_VIEW_ROTATED ? "Rotated" : "Remapped",
958 i915_vma_unpin_iomap(vma);
963 i915_vma_unpin_iomap(vma);
968 intel_runtime_pm_put(&i915->runtime_pm, wakeref);
969 mutex_unlock(&i915->drm.struct_mutex);
970 i915_gem_object_put(obj);
975 int i915_vma_live_selftests(struct drm_i915_private *i915)
977 static const struct i915_subtest tests[] = {
978 SUBTEST(igt_vma_remapped_gtt),
981 return i915_subtests(tests, i915);