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);
201 /* Final pass to lookup all created contexts */
202 err = create_vmas(i915, &objects, &contexts);
204 list_for_each_entry_safe(ctx, cn, &contexts, link) {
205 list_del_init(&ctx->link);
206 mock_context_close(ctx);
209 list_for_each_entry_safe(obj, on, &objects, st_link)
210 i915_gem_object_put(obj);
217 bool (*assert)(const struct i915_vma *,
218 const struct pin_mode *mode,
223 static bool assert_pin_valid(const struct i915_vma *vma,
224 const struct pin_mode *mode,
230 if (i915_vma_misplaced(vma, mode->size, 0, mode->flags))
237 static bool assert_pin_enospc(const struct i915_vma *vma,
238 const struct pin_mode *mode,
241 return result == -ENOSPC;
245 static bool assert_pin_einval(const struct i915_vma *vma,
246 const struct pin_mode *mode,
249 return result == -EINVAL;
252 static int igt_vma_pin1(void *arg)
254 struct i915_ggtt *ggtt = arg;
255 const struct pin_mode modes[] = {
256 #define VALID(sz, fl) { .size = (sz), .flags = (fl), .assert = assert_pin_valid, .string = #sz ", " #fl ", (valid) " }
257 #define __INVALID(sz, fl, check, eval) { .size = (sz), .flags = (fl), .assert = (check), .string = #sz ", " #fl ", (invalid " #eval ")" }
258 #define INVALID(sz, fl) __INVALID(sz, fl, assert_pin_einval, EINVAL)
259 #define NOSPACE(sz, fl) __INVALID(sz, fl, assert_pin_enospc, ENOSPC)
260 VALID(0, PIN_GLOBAL),
261 VALID(0, PIN_GLOBAL | PIN_MAPPABLE),
263 VALID(0, PIN_GLOBAL | PIN_OFFSET_BIAS | 4096),
264 VALID(0, PIN_GLOBAL | PIN_OFFSET_BIAS | 8192),
265 VALID(0, PIN_GLOBAL | PIN_OFFSET_BIAS | (ggtt->mappable_end - 4096)),
266 VALID(0, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_BIAS | (ggtt->mappable_end - 4096)),
267 VALID(0, PIN_GLOBAL | PIN_OFFSET_BIAS | (ggtt->vm.total - 4096)),
269 VALID(0, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_FIXED | (ggtt->mappable_end - 4096)),
270 INVALID(0, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_FIXED | ggtt->mappable_end),
271 VALID(0, PIN_GLOBAL | PIN_OFFSET_FIXED | (ggtt->vm.total - 4096)),
272 INVALID(0, PIN_GLOBAL | PIN_OFFSET_FIXED | ggtt->vm.total),
273 INVALID(0, PIN_GLOBAL | PIN_OFFSET_FIXED | round_down(U64_MAX, PAGE_SIZE)),
275 VALID(4096, PIN_GLOBAL),
276 VALID(8192, PIN_GLOBAL),
277 VALID(ggtt->mappable_end - 4096, PIN_GLOBAL | PIN_MAPPABLE),
278 VALID(ggtt->mappable_end, PIN_GLOBAL | PIN_MAPPABLE),
279 NOSPACE(ggtt->mappable_end + 4096, PIN_GLOBAL | PIN_MAPPABLE),
280 VALID(ggtt->vm.total - 4096, PIN_GLOBAL),
281 VALID(ggtt->vm.total, PIN_GLOBAL),
282 NOSPACE(ggtt->vm.total + 4096, PIN_GLOBAL),
283 NOSPACE(round_down(U64_MAX, PAGE_SIZE), PIN_GLOBAL),
284 INVALID(8192, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_FIXED | (ggtt->mappable_end - 4096)),
285 INVALID(8192, PIN_GLOBAL | PIN_OFFSET_FIXED | (ggtt->vm.total - 4096)),
286 INVALID(8192, PIN_GLOBAL | PIN_OFFSET_FIXED | (round_down(U64_MAX, PAGE_SIZE) - 4096)),
288 VALID(8192, PIN_GLOBAL | PIN_OFFSET_BIAS | (ggtt->mappable_end - 4096)),
290 #if !IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM)
291 /* Misusing BIAS is a programming error (it is not controllable
292 * from userspace) so when debugging is enabled, it explodes.
293 * However, the tests are still quite interesting for checking
294 * variable start, end and size.
296 NOSPACE(0, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_BIAS | ggtt->mappable_end),
297 NOSPACE(0, PIN_GLOBAL | PIN_OFFSET_BIAS | ggtt->vm.total),
298 NOSPACE(8192, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_BIAS | (ggtt->mappable_end - 4096)),
299 NOSPACE(8192, PIN_GLOBAL | PIN_OFFSET_BIAS | (ggtt->vm.total - 4096)),
307 struct drm_i915_gem_object *obj;
308 struct i915_vma *vma;
311 /* Exercise all the weird and wonderful i915_vma_pin requests,
312 * focusing on error handling of boundary conditions.
315 GEM_BUG_ON(!drm_mm_clean(&ggtt->vm.mm));
317 obj = i915_gem_object_create_internal(ggtt->vm.i915, PAGE_SIZE);
321 vma = checked_vma_instance(obj, &ggtt->vm, NULL);
325 for (m = modes; m->assert; m++) {
326 err = i915_vma_pin(vma, m->size, 0, m->flags);
327 if (!m->assert(vma, m, err)) {
328 pr_err("%s to pin single page into GGTT with mode[%d:%s]: size=%llx flags=%llx, err=%d\n",
329 m->assert == assert_pin_valid ? "Failed" : "Unexpectedly succeeded",
330 (int)(m - modes), m->string, m->size, m->flags,
340 err = i915_vma_unbind(vma);
342 pr_err("Failed to unbind single page from GGTT, err=%d\n", err);
352 i915_gem_object_put(obj);
356 static unsigned long rotated_index(const struct intel_rotation_info *r,
361 return (r->plane[n].stride * (r->plane[n].height - y - 1) +
362 r->plane[n].offset + x);
365 static struct scatterlist *
366 assert_rotated(struct drm_i915_gem_object *obj,
367 const struct intel_rotation_info *r, unsigned int n,
368 struct scatterlist *sg)
372 for (x = 0; x < r->plane[n].width; x++) {
373 for (y = 0; y < r->plane[n].height; y++) {
374 unsigned long src_idx;
378 pr_err("Invalid sg table: too short at plane %d, (%d, %d)!\n",
380 return ERR_PTR(-EINVAL);
383 src_idx = rotated_index(r, n, x, y);
384 src = i915_gem_object_get_dma_address(obj, src_idx);
386 if (sg_dma_len(sg) != PAGE_SIZE) {
387 pr_err("Invalid sg.length, found %d, expected %lu for rotated page (%d, %d) [src index %lu]\n",
388 sg_dma_len(sg), PAGE_SIZE,
390 return ERR_PTR(-EINVAL);
393 if (sg_dma_address(sg) != src) {
394 pr_err("Invalid address for rotated page (%d, %d) [src index %lu]\n",
396 return ERR_PTR(-EINVAL);
406 static unsigned long remapped_index(const struct intel_remapped_info *r,
411 return (r->plane[n].stride * y +
412 r->plane[n].offset + x);
415 static struct scatterlist *
416 assert_remapped(struct drm_i915_gem_object *obj,
417 const struct intel_remapped_info *r, unsigned int n,
418 struct scatterlist *sg)
421 unsigned int left = 0;
424 for (y = 0; y < r->plane[n].height; y++) {
425 for (x = 0; x < r->plane[n].width; x++) {
426 unsigned long src_idx;
430 pr_err("Invalid sg table: too short at plane %d, (%d, %d)!\n",
432 return ERR_PTR(-EINVAL);
436 left = sg_dma_len(sg);
439 src_idx = remapped_index(r, n, x, y);
440 src = i915_gem_object_get_dma_address(obj, src_idx);
442 if (left < PAGE_SIZE || left & (PAGE_SIZE-1)) {
443 pr_err("Invalid sg.length, found %d, expected %lu for remapped page (%d, %d) [src index %lu]\n",
444 sg_dma_len(sg), PAGE_SIZE,
446 return ERR_PTR(-EINVAL);
449 if (sg_dma_address(sg) + offset != src) {
450 pr_err("Invalid address for remapped page (%d, %d) [src index %lu]\n",
452 return ERR_PTR(-EINVAL);
467 static unsigned int rotated_size(const struct intel_remapped_plane_info *a,
468 const struct intel_remapped_plane_info *b)
470 return a->width * a->height + b->width * b->height;
473 static int igt_vma_rotate_remap(void *arg)
475 struct i915_ggtt *ggtt = arg;
476 struct i915_address_space *vm = &ggtt->vm;
477 struct drm_i915_gem_object *obj;
478 const struct intel_remapped_plane_info planes[] = {
479 { .width = 1, .height = 1, .stride = 1 },
480 { .width = 2, .height = 2, .stride = 2 },
481 { .width = 4, .height = 4, .stride = 4 },
482 { .width = 8, .height = 8, .stride = 8 },
484 { .width = 3, .height = 5, .stride = 3 },
485 { .width = 3, .height = 5, .stride = 4 },
486 { .width = 3, .height = 5, .stride = 5 },
488 { .width = 5, .height = 3, .stride = 5 },
489 { .width = 5, .height = 3, .stride = 7 },
490 { .width = 5, .height = 3, .stride = 9 },
492 { .width = 4, .height = 6, .stride = 6 },
493 { .width = 6, .height = 4, .stride = 6 },
496 enum i915_ggtt_view_type types[] = {
497 I915_GGTT_VIEW_ROTATED,
498 I915_GGTT_VIEW_REMAPPED,
501 const unsigned int max_pages = 64;
504 /* Create VMA for many different combinations of planes and check
505 * that the page layout within the rotated VMA match our expectations.
508 obj = i915_gem_object_create_internal(vm->i915, max_pages * PAGE_SIZE);
512 for (t = types; *t; t++) {
513 for (a = planes; a->width; a++) {
514 for (b = planes + ARRAY_SIZE(planes); b-- != planes; ) {
515 struct i915_ggtt_view view;
516 unsigned int n, max_offset;
518 max_offset = max(a->stride * a->height,
519 b->stride * b->height);
520 GEM_BUG_ON(max_offset > max_pages);
521 max_offset = max_pages - max_offset;
524 view.rotated.plane[0] = *a;
525 view.rotated.plane[1] = *b;
527 for_each_prime_number_from(view.rotated.plane[0].offset, 0, max_offset) {
528 for_each_prime_number_from(view.rotated.plane[1].offset, 0, max_offset) {
529 struct scatterlist *sg;
530 struct i915_vma *vma;
532 vma = checked_vma_instance(obj, vm, &view);
538 err = i915_vma_pin(vma, 0, 0, PIN_GLOBAL);
540 pr_err("Failed to pin VMA, err=%d\n", err);
544 if (view.type == I915_GGTT_VIEW_ROTATED &&
545 vma->size != rotated_size(a, b) * PAGE_SIZE) {
546 pr_err("VMA is wrong size, expected %lu, found %llu\n",
547 PAGE_SIZE * rotated_size(a, b), vma->size);
552 if (view.type == I915_GGTT_VIEW_REMAPPED &&
553 vma->size > rotated_size(a, b) * PAGE_SIZE) {
554 pr_err("VMA is wrong size, expected %lu, found %llu\n",
555 PAGE_SIZE * rotated_size(a, b), vma->size);
560 if (vma->pages->nents > rotated_size(a, b)) {
561 pr_err("sg table is wrong sizeo, expected %u, found %u nents\n",
562 rotated_size(a, b), vma->pages->nents);
567 if (vma->node.size < vma->size) {
568 pr_err("VMA binding too small, expected %llu, found %llu\n",
569 vma->size, vma->node.size);
574 if (vma->pages == obj->mm.pages) {
575 pr_err("VMA using unrotated object pages!\n");
580 sg = vma->pages->sgl;
581 for (n = 0; n < ARRAY_SIZE(view.rotated.plane); n++) {
582 if (view.type == I915_GGTT_VIEW_ROTATED)
583 sg = assert_rotated(obj, &view.rotated, n, sg);
585 sg = assert_remapped(obj, &view.remapped, n, sg);
587 pr_err("Inconsistent %s VMA pages for plane %d: [(%d, %d, %d, %d), (%d, %d, %d, %d)]\n",
588 view.type == I915_GGTT_VIEW_ROTATED ?
589 "rotated" : "remapped", n,
590 view.rotated.plane[0].width,
591 view.rotated.plane[0].height,
592 view.rotated.plane[0].stride,
593 view.rotated.plane[0].offset,
594 view.rotated.plane[1].width,
595 view.rotated.plane[1].height,
596 view.rotated.plane[1].stride,
597 view.rotated.plane[1].offset);
613 i915_gem_object_put(obj);
618 static bool assert_partial(struct drm_i915_gem_object *obj,
619 struct i915_vma *vma,
620 unsigned long offset,
626 for_each_sgt_daddr(dma, sgt, vma->pages) {
630 pr_err("Partial scattergather list too long\n");
634 src = i915_gem_object_get_dma_address(obj, offset);
636 pr_err("DMA mismatch for partial page offset %lu\n",
648 static bool assert_pin(struct i915_vma *vma,
649 struct i915_ggtt_view *view,
655 if (vma->size != size) {
656 pr_err("(%s) VMA is wrong size, expected %llu, found %llu\n",
657 name, size, vma->size);
661 if (vma->node.size < vma->size) {
662 pr_err("(%s) VMA binding too small, expected %llu, found %llu\n",
663 name, vma->size, vma->node.size);
667 if (view && view->type != I915_GGTT_VIEW_NORMAL) {
668 if (memcmp(&vma->ggtt_view, view, sizeof(*view))) {
669 pr_err("(%s) VMA mismatch upon creation!\n",
674 if (vma->pages == vma->obj->mm.pages) {
675 pr_err("(%s) VMA using original object pages!\n",
680 if (vma->ggtt_view.type != I915_GGTT_VIEW_NORMAL) {
681 pr_err("Not the normal ggtt view! Found %d\n",
682 vma->ggtt_view.type);
686 if (vma->pages != vma->obj->mm.pages) {
687 pr_err("VMA not using object pages!\n");
695 static int igt_vma_partial(void *arg)
697 struct i915_ggtt *ggtt = arg;
698 struct i915_address_space *vm = &ggtt->vm;
699 const unsigned int npages = 1021; /* prime! */
700 struct drm_i915_gem_object *obj;
708 unsigned int sz, offset;
709 struct i915_vma *vma;
712 /* Create lots of different VMA for the object and check that
713 * we are returned the same VMA when we later request the same range.
716 obj = i915_gem_object_create_internal(vm->i915, npages * PAGE_SIZE);
720 for (p = phases; p->name; p++) { /* exercise both create/lookup */
721 unsigned int count, nvma;
724 for_each_prime_number_from(sz, 1, npages) {
725 for_each_prime_number_from(offset, 0, npages - sz) {
726 struct i915_ggtt_view view;
728 view.type = I915_GGTT_VIEW_PARTIAL;
729 view.partial.offset = offset;
730 view.partial.size = sz;
733 view.type = I915_GGTT_VIEW_NORMAL;
735 vma = checked_vma_instance(obj, vm, &view);
741 err = i915_vma_pin(vma, 0, 0, PIN_GLOBAL);
745 if (!assert_pin(vma, &view, sz*PAGE_SIZE, p->name)) {
746 pr_err("(%s) Inconsistent partial pinning for (offset=%d, size=%d)\n",
747 p->name, offset, sz);
752 if (!assert_partial(obj, vma, offset, sz)) {
753 pr_err("(%s) Inconsistent partial pages for (offset=%d, size=%d)\n",
754 p->name, offset, sz);
767 list_for_each_entry(vma, &obj->vma.list, obj_link)
770 pr_err("(%s) All partial vma were not recorded on the obj->vma_list: found %u, expected %u\n",
771 p->name, count, nvma);
776 /* Check that we did create the whole object mapping */
777 vma = checked_vma_instance(obj, vm, NULL);
783 err = i915_vma_pin(vma, 0, 0, PIN_GLOBAL);
787 if (!assert_pin(vma, NULL, obj->base.size, p->name)) {
788 pr_err("(%s) inconsistent full pin\n", p->name);
796 list_for_each_entry(vma, &obj->vma.list, obj_link)
799 pr_err("(%s) allocated an extra full vma!\n", p->name);
806 i915_gem_object_put(obj);
811 int i915_vma_mock_selftests(void)
813 static const struct i915_subtest tests[] = {
814 SUBTEST(igt_vma_create),
815 SUBTEST(igt_vma_pin1),
816 SUBTEST(igt_vma_rotate_remap),
817 SUBTEST(igt_vma_partial),
819 struct drm_i915_private *i915;
820 struct i915_ggtt *ggtt;
823 i915 = mock_gem_device();
827 ggtt = kmalloc(sizeof(*ggtt), GFP_KERNEL);
832 mock_init_ggtt(i915, ggtt);
834 err = i915_subtests(tests, ggtt);
836 mock_device_flush(i915);
837 i915_gem_drain_freed_objects(i915);
838 mock_fini_ggtt(ggtt);
841 drm_dev_put(&i915->drm);
845 static int igt_vma_remapped_gtt(void *arg)
847 struct drm_i915_private *i915 = arg;
848 const struct intel_remapped_plane_info planes[] = {
849 { .width = 1, .height = 1, .stride = 1 },
850 { .width = 2, .height = 2, .stride = 2 },
851 { .width = 4, .height = 4, .stride = 4 },
852 { .width = 8, .height = 8, .stride = 8 },
854 { .width = 3, .height = 5, .stride = 3 },
855 { .width = 3, .height = 5, .stride = 4 },
856 { .width = 3, .height = 5, .stride = 5 },
858 { .width = 5, .height = 3, .stride = 5 },
859 { .width = 5, .height = 3, .stride = 7 },
860 { .width = 5, .height = 3, .stride = 9 },
862 { .width = 4, .height = 6, .stride = 6 },
863 { .width = 6, .height = 4, .stride = 6 },
866 enum i915_ggtt_view_type types[] = {
867 I915_GGTT_VIEW_ROTATED,
868 I915_GGTT_VIEW_REMAPPED,
871 struct drm_i915_gem_object *obj;
872 intel_wakeref_t wakeref;
875 obj = i915_gem_object_create_internal(i915, 10 * 10 * PAGE_SIZE);
879 wakeref = intel_runtime_pm_get(&i915->runtime_pm);
881 for (t = types; *t; t++) {
882 for (p = planes; p->width; p++) {
883 struct i915_ggtt_view view = {
885 .rotated.plane[0] = *p,
887 struct i915_vma *vma;
892 i915_gem_object_lock(obj);
893 err = i915_gem_object_set_to_gtt_domain(obj, true);
894 i915_gem_object_unlock(obj);
898 vma = i915_gem_object_ggtt_pin(obj, &view, 0, 0, PIN_MAPPABLE);
904 GEM_BUG_ON(vma->ggtt_view.type != *t);
906 map = i915_vma_pin_iomap(vma);
913 for (y = 0 ; y < p->height; y++) {
914 for (x = 0 ; x < p->width; x++) {
916 u32 val = y << 16 | x;
918 if (*t == I915_GGTT_VIEW_ROTATED)
919 offset = (x * p->height + y) * PAGE_SIZE;
921 offset = (y * p->width + x) * PAGE_SIZE;
923 iowrite32(val, &map[offset / sizeof(*map)]);
927 i915_vma_unpin_iomap(vma);
929 vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, PIN_MAPPABLE);
935 GEM_BUG_ON(vma->ggtt_view.type != I915_GGTT_VIEW_NORMAL);
937 map = i915_vma_pin_iomap(vma);
944 for (y = 0 ; y < p->height; y++) {
945 for (x = 0 ; x < p->width; x++) {
946 unsigned int offset, src_idx;
947 u32 exp = y << 16 | x;
950 if (*t == I915_GGTT_VIEW_ROTATED)
951 src_idx = rotated_index(&view.rotated, 0, x, y);
953 src_idx = remapped_index(&view.remapped, 0, x, y);
954 offset = src_idx * PAGE_SIZE;
956 val = ioread32(&map[offset / sizeof(*map)]);
958 pr_err("%s VMA write test failed, expected 0x%x, found 0x%x\n",
959 *t == I915_GGTT_VIEW_ROTATED ? "Rotated" : "Remapped",
961 i915_vma_unpin_iomap(vma);
966 i915_vma_unpin_iomap(vma);
973 intel_runtime_pm_put(&i915->runtime_pm, wakeref);
974 i915_gem_object_put(obj);
979 int i915_vma_live_selftests(struct drm_i915_private *i915)
981 static const struct i915_subtest tests[] = {
982 SUBTEST(igt_vma_remapped_gtt),
985 return i915_subtests(tests, i915);