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/i915_gem_context.h"
28 #include "gem/i915_gem_internal.h"
29 #include "gem/selftests/mock_context.h"
31 #include "i915_scatterlist.h"
32 #include "i915_selftest.h"
34 #include "mock_gem_device.h"
37 static bool assert_vma(struct i915_vma *vma,
38 struct drm_i915_gem_object *obj,
39 struct i915_gem_context *ctx)
43 if (vma->vm != ctx->vm) {
44 pr_err("VMA created with wrong VM\n");
48 if (vma->size != obj->base.size) {
49 pr_err("VMA created with wrong size, found %llu, expected %zu\n",
50 vma->size, obj->base.size);
54 if (vma->gtt_view.type != I915_GTT_VIEW_NORMAL) {
55 pr_err("VMA created with wrong type [%d]\n",
63 static struct i915_vma *
64 checked_vma_instance(struct drm_i915_gem_object *obj,
65 struct i915_address_space *vm,
66 const struct i915_gtt_view *view)
71 vma = i915_vma_instance(obj, vm, view);
75 /* Manual checks, will be reinforced by i915_vma_compare! */
77 pr_err("VMA's vm [%p] does not match request [%p]\n",
82 if (i915_is_ggtt(vm) != i915_vma_is_ggtt(vma)) {
83 pr_err("VMA ggtt status [%d] does not match parent [%d]\n",
84 i915_vma_is_ggtt(vma), i915_is_ggtt(vm));
88 if (i915_vma_compare(vma, vm, view)) {
89 pr_err("i915_vma_compare failed with create parameters!\n");
90 return ERR_PTR(-EINVAL);
93 if (i915_vma_compare(vma, vma->vm,
94 i915_vma_is_ggtt(vma) ? &vma->gtt_view : NULL)) {
95 pr_err("i915_vma_compare failed with itself\n");
96 return ERR_PTR(-EINVAL);
100 pr_err("i915_vma_compare failed to detect the difference!\n");
101 return ERR_PTR(-EINVAL);
107 static int create_vmas(struct drm_i915_private *i915,
108 struct list_head *objects,
109 struct list_head *contexts)
111 struct drm_i915_gem_object *obj;
112 struct i915_gem_context *ctx;
115 list_for_each_entry(obj, objects, st_link) {
116 for (pinned = 0; pinned <= 1; pinned++) {
117 list_for_each_entry(ctx, contexts, link) {
118 struct i915_address_space *vm;
119 struct i915_vma *vma;
122 vm = i915_gem_context_get_eb_vm(ctx);
123 vma = checked_vma_instance(obj, vm, NULL);
128 if (!assert_vma(vma, obj, ctx)) {
129 pr_err("VMA lookup/create failed\n");
134 err = i915_vma_pin(vma, 0, 0, PIN_USER);
136 pr_err("Failed to pin VMA\n");
149 static int igt_vma_create(void *arg)
151 struct i915_ggtt *ggtt = arg;
152 struct drm_i915_private *i915 = ggtt->vm.i915;
153 struct drm_i915_gem_object *obj, *on;
154 struct i915_gem_context *ctx, *cn;
155 unsigned long num_obj, num_ctx;
156 unsigned long no, nc;
157 IGT_TIMEOUT(end_time);
162 /* Exercise creating many vma amonst many objections, checking the
163 * vma creation and lookup routines.
167 for_each_prime_number(num_obj, ULONG_MAX - 1) {
168 for (; no < num_obj; no++) {
169 obj = i915_gem_object_create_internal(i915, PAGE_SIZE);
173 list_add(&obj->st_link, &objects);
177 for_each_prime_number(num_ctx, 2 * BITS_PER_LONG) {
178 for (; nc < num_ctx; nc++) {
179 ctx = mock_context(i915, "mock");
183 list_move(&ctx->link, &contexts);
186 err = create_vmas(i915, &objects, &contexts);
190 if (igt_timeout(end_time,
191 "%s timed out: after %lu objects in %lu contexts\n",
196 list_for_each_entry_safe(ctx, cn, &contexts, link) {
197 list_del_init(&ctx->link);
198 mock_context_close(ctx);
205 /* Final pass to lookup all created contexts */
206 err = create_vmas(i915, &objects, &contexts);
208 list_for_each_entry_safe(ctx, cn, &contexts, link) {
209 list_del_init(&ctx->link);
210 mock_context_close(ctx);
213 list_for_each_entry_safe(obj, on, &objects, st_link)
214 i915_gem_object_put(obj);
221 bool (*assert)(const struct i915_vma *,
222 const struct pin_mode *mode,
227 static bool assert_pin_valid(const struct i915_vma *vma,
228 const struct pin_mode *mode,
234 if (i915_vma_misplaced(vma, mode->size, 0, mode->flags))
241 static bool assert_pin_enospc(const struct i915_vma *vma,
242 const struct pin_mode *mode,
245 return result == -ENOSPC;
249 static bool assert_pin_einval(const struct i915_vma *vma,
250 const struct pin_mode *mode,
253 return result == -EINVAL;
256 static int igt_vma_pin1(void *arg)
258 struct i915_ggtt *ggtt = arg;
259 const struct pin_mode modes[] = {
260 #define VALID(sz, fl) { .size = (sz), .flags = (fl), .assert = assert_pin_valid, .string = #sz ", " #fl ", (valid) " }
261 #define __INVALID(sz, fl, check, eval) { .size = (sz), .flags = (fl), .assert = (check), .string = #sz ", " #fl ", (invalid " #eval ")" }
262 #define INVALID(sz, fl) __INVALID(sz, fl, assert_pin_einval, EINVAL)
263 #define NOSPACE(sz, fl) __INVALID(sz, fl, assert_pin_enospc, ENOSPC)
264 VALID(0, PIN_GLOBAL),
265 VALID(0, PIN_GLOBAL | PIN_MAPPABLE),
267 VALID(0, PIN_GLOBAL | PIN_OFFSET_BIAS | 4096),
268 VALID(0, PIN_GLOBAL | PIN_OFFSET_BIAS | 8192),
269 VALID(0, PIN_GLOBAL | PIN_OFFSET_BIAS | (ggtt->mappable_end - 4096)),
270 VALID(0, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_BIAS | (ggtt->mappable_end - 4096)),
271 VALID(0, PIN_GLOBAL | PIN_OFFSET_BIAS | (ggtt->vm.total - 4096)),
273 VALID(0, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_FIXED | (ggtt->mappable_end - 4096)),
274 INVALID(0, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_FIXED | ggtt->mappable_end),
275 VALID(0, PIN_GLOBAL | PIN_OFFSET_FIXED | (ggtt->vm.total - 4096)),
276 INVALID(0, PIN_GLOBAL | PIN_OFFSET_FIXED | ggtt->vm.total),
277 INVALID(0, PIN_GLOBAL | PIN_OFFSET_FIXED | round_down(U64_MAX, PAGE_SIZE)),
279 VALID(4096, PIN_GLOBAL),
280 VALID(8192, PIN_GLOBAL),
281 VALID(ggtt->mappable_end - 4096, PIN_GLOBAL | PIN_MAPPABLE),
282 VALID(ggtt->mappable_end, PIN_GLOBAL | PIN_MAPPABLE),
283 NOSPACE(ggtt->mappable_end + 4096, PIN_GLOBAL | PIN_MAPPABLE),
284 VALID(ggtt->vm.total - 4096, PIN_GLOBAL),
285 VALID(ggtt->vm.total, PIN_GLOBAL),
286 NOSPACE(ggtt->vm.total + 4096, PIN_GLOBAL),
287 NOSPACE(round_down(U64_MAX, PAGE_SIZE), PIN_GLOBAL),
288 INVALID(8192, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_FIXED | (ggtt->mappable_end - 4096)),
289 INVALID(8192, PIN_GLOBAL | PIN_OFFSET_FIXED | (ggtt->vm.total - 4096)),
290 INVALID(8192, PIN_GLOBAL | PIN_OFFSET_FIXED | (round_down(U64_MAX, PAGE_SIZE) - 4096)),
292 VALID(8192, PIN_GLOBAL | PIN_OFFSET_BIAS | (ggtt->mappable_end - 4096)),
294 #if !IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM)
295 /* Misusing BIAS is a programming error (it is not controllable
296 * from userspace) so when debugging is enabled, it explodes.
297 * However, the tests are still quite interesting for checking
298 * variable start, end and size.
300 NOSPACE(0, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_BIAS | ggtt->mappable_end),
301 NOSPACE(0, PIN_GLOBAL | PIN_OFFSET_BIAS | ggtt->vm.total),
302 NOSPACE(8192, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_BIAS | (ggtt->mappable_end - 4096)),
303 NOSPACE(8192, PIN_GLOBAL | PIN_OFFSET_BIAS | (ggtt->vm.total - 4096)),
311 struct drm_i915_gem_object *obj;
312 struct i915_vma *vma;
315 /* Exercise all the weird and wonderful i915_vma_pin requests,
316 * focusing on error handling of boundary conditions.
319 GEM_BUG_ON(!drm_mm_clean(&ggtt->vm.mm));
321 obj = i915_gem_object_create_internal(ggtt->vm.i915, PAGE_SIZE);
325 vma = checked_vma_instance(obj, &ggtt->vm, NULL);
329 for (m = modes; m->assert; m++) {
330 err = i915_vma_pin(vma, m->size, 0, m->flags);
331 if (!m->assert(vma, m, err)) {
332 pr_err("%s to pin single page into GGTT with mode[%d:%s]: size=%llx flags=%llx, err=%d\n",
333 m->assert == assert_pin_valid ? "Failed" : "Unexpectedly succeeded",
334 (int)(m - modes), m->string, m->size, m->flags,
344 err = i915_vma_unbind_unlocked(vma);
346 pr_err("Failed to unbind single page from GGTT, err=%d\n", err);
356 i915_gem_object_put(obj);
360 static unsigned long rotated_index(const struct intel_rotation_info *r,
365 return (r->plane[n].src_stride * (r->plane[n].height - y - 1) +
366 r->plane[n].offset + x);
369 static struct scatterlist *
370 assert_rotated(struct drm_i915_gem_object *obj,
371 const struct intel_rotation_info *r, unsigned int n,
372 struct scatterlist *sg)
376 for (x = 0; x < r->plane[n].width; x++) {
379 for (y = 0; y < r->plane[n].height; y++) {
380 unsigned long src_idx;
384 pr_err("Invalid sg table: too short at plane %d, (%d, %d)!\n",
386 return ERR_PTR(-EINVAL);
389 src_idx = rotated_index(r, n, x, y);
390 src = i915_gem_object_get_dma_address(obj, src_idx);
392 if (sg_dma_len(sg) != PAGE_SIZE) {
393 pr_err("Invalid sg.length, found %d, expected %lu for rotated page (%d, %d) [src index %lu]\n",
394 sg_dma_len(sg), PAGE_SIZE,
396 return ERR_PTR(-EINVAL);
399 if (sg_dma_address(sg) != src) {
400 pr_err("Invalid address for rotated page (%d, %d) [src index %lu]\n",
402 return ERR_PTR(-EINVAL);
408 left = (r->plane[n].dst_stride - y) * PAGE_SIZE;
414 pr_err("Invalid sg table: too short at plane %d, (%d, %d)!\n",
416 return ERR_PTR(-EINVAL);
419 if (sg_dma_len(sg) != left) {
420 pr_err("Invalid sg.length, found %d, expected %u for rotated page (%d, %d)\n",
421 sg_dma_len(sg), left, x, y);
422 return ERR_PTR(-EINVAL);
425 if (sg_dma_address(sg) != 0) {
426 pr_err("Invalid address, found %pad, expected 0 for remapped page (%d, %d)\n",
427 &sg_dma_address(sg), x, y);
428 return ERR_PTR(-EINVAL);
437 static unsigned long remapped_index(const struct intel_remapped_info *r,
442 return (r->plane[n].src_stride * y +
443 r->plane[n].offset + x);
446 static struct scatterlist *
447 assert_remapped(struct drm_i915_gem_object *obj,
448 const struct intel_remapped_info *r, unsigned int n,
449 struct scatterlist *sg)
452 unsigned int left = 0;
455 for (y = 0; y < r->plane[n].height; y++) {
456 for (x = 0; x < r->plane[n].width; x++) {
457 unsigned long src_idx;
461 pr_err("Invalid sg table: too short at plane %d, (%d, %d)!\n",
463 return ERR_PTR(-EINVAL);
467 left = sg_dma_len(sg);
470 src_idx = remapped_index(r, n, x, y);
471 src = i915_gem_object_get_dma_address(obj, src_idx);
473 if (left < PAGE_SIZE || left & (PAGE_SIZE-1)) {
474 pr_err("Invalid sg.length, found %d, expected %lu for remapped page (%d, %d) [src index %lu]\n",
475 sg_dma_len(sg), PAGE_SIZE,
477 return ERR_PTR(-EINVAL);
480 if (sg_dma_address(sg) + offset != src) {
481 pr_err("Invalid address for remapped page (%d, %d) [src index %lu]\n",
483 return ERR_PTR(-EINVAL);
495 pr_err("Unexpected sg tail with %d size for remapped page (%d, %d)\n",
498 return ERR_PTR(-EINVAL);
501 left = (r->plane[n].dst_stride - r->plane[n].width) * PAGE_SIZE;
507 pr_err("Invalid sg table: too short at plane %d, (%d, %d)!\n",
509 return ERR_PTR(-EINVAL);
512 if (sg_dma_len(sg) != left) {
513 pr_err("Invalid sg.length, found %u, expected %u for remapped page (%d, %d)\n",
514 sg_dma_len(sg), left,
516 return ERR_PTR(-EINVAL);
519 if (sg_dma_address(sg) != 0) {
520 pr_err("Invalid address, found %pad, expected 0 for remapped page (%d, %d)\n",
523 return ERR_PTR(-EINVAL);
533 static unsigned int remapped_size(enum i915_gtt_view_type view_type,
534 const struct intel_remapped_plane_info *a,
535 const struct intel_remapped_plane_info *b)
538 if (view_type == I915_GTT_VIEW_ROTATED)
539 return a->dst_stride * a->width + b->dst_stride * b->width;
541 return a->dst_stride * a->height + b->dst_stride * b->height;
544 static int igt_vma_rotate_remap(void *arg)
546 struct i915_ggtt *ggtt = arg;
547 struct i915_address_space *vm = &ggtt->vm;
548 struct drm_i915_gem_object *obj;
549 const struct intel_remapped_plane_info planes[] = {
550 { .width = 1, .height = 1, .src_stride = 1 },
551 { .width = 2, .height = 2, .src_stride = 2 },
552 { .width = 4, .height = 4, .src_stride = 4 },
553 { .width = 8, .height = 8, .src_stride = 8 },
555 { .width = 3, .height = 5, .src_stride = 3 },
556 { .width = 3, .height = 5, .src_stride = 4 },
557 { .width = 3, .height = 5, .src_stride = 5 },
559 { .width = 5, .height = 3, .src_stride = 5 },
560 { .width = 5, .height = 3, .src_stride = 7 },
561 { .width = 5, .height = 3, .src_stride = 9 },
563 { .width = 4, .height = 6, .src_stride = 6 },
564 { .width = 6, .height = 4, .src_stride = 6 },
566 { .width = 2, .height = 2, .src_stride = 2, .dst_stride = 2 },
567 { .width = 3, .height = 3, .src_stride = 3, .dst_stride = 4 },
568 { .width = 5, .height = 6, .src_stride = 7, .dst_stride = 8 },
572 enum i915_gtt_view_type types[] = {
573 I915_GTT_VIEW_ROTATED,
574 I915_GTT_VIEW_REMAPPED,
577 const unsigned int max_pages = 64;
580 /* Create VMA for many different combinations of planes and check
581 * that the page layout within the rotated VMA match our expectations.
584 obj = i915_gem_object_create_internal(vm->i915, max_pages * PAGE_SIZE);
588 for (t = types; *t; t++) {
589 for (a = planes; a->width; a++) {
590 for (b = planes + ARRAY_SIZE(planes); b-- != planes; ) {
591 struct i915_gtt_view view = {
593 .remapped.plane[0] = *a,
594 .remapped.plane[1] = *b,
596 struct intel_remapped_plane_info *plane_info = view.remapped.plane;
597 unsigned int n, max_offset;
599 max_offset = max(plane_info[0].src_stride * plane_info[0].height,
600 plane_info[1].src_stride * plane_info[1].height);
601 GEM_BUG_ON(max_offset > max_pages);
602 max_offset = max_pages - max_offset;
604 if (!plane_info[0].dst_stride)
605 plane_info[0].dst_stride = view.type == I915_GTT_VIEW_ROTATED ?
606 plane_info[0].height :
608 if (!plane_info[1].dst_stride)
609 plane_info[1].dst_stride = view.type == I915_GTT_VIEW_ROTATED ?
610 plane_info[1].height :
613 for_each_prime_number_from(plane_info[0].offset, 0, max_offset) {
614 for_each_prime_number_from(plane_info[1].offset, 0, max_offset) {
615 struct scatterlist *sg;
616 struct i915_vma *vma;
617 unsigned int expected_pages;
619 vma = checked_vma_instance(obj, vm, &view);
625 err = i915_vma_pin(vma, 0, 0, PIN_GLOBAL);
627 pr_err("Failed to pin VMA, err=%d\n", err);
631 expected_pages = remapped_size(view.type, &plane_info[0], &plane_info[1]);
633 if (view.type == I915_GTT_VIEW_ROTATED &&
634 vma->size != expected_pages * PAGE_SIZE) {
635 pr_err("VMA is wrong size, expected %lu, found %llu\n",
636 PAGE_SIZE * expected_pages, vma->size);
641 if (view.type == I915_GTT_VIEW_REMAPPED &&
642 vma->size > expected_pages * PAGE_SIZE) {
643 pr_err("VMA is wrong size, expected %lu, found %llu\n",
644 PAGE_SIZE * expected_pages, vma->size);
649 if (vma->pages->nents > expected_pages) {
650 pr_err("sg table is wrong sizeo, expected %u, found %u nents\n",
651 expected_pages, vma->pages->nents);
656 if (vma->node.size < vma->size) {
657 pr_err("VMA binding too small, expected %llu, found %llu\n",
658 vma->size, vma->node.size);
663 if (vma->pages == obj->mm.pages) {
664 pr_err("VMA using unrotated object pages!\n");
669 sg = vma->pages->sgl;
670 for (n = 0; n < ARRAY_SIZE(view.rotated.plane); n++) {
671 if (view.type == I915_GTT_VIEW_ROTATED)
672 sg = assert_rotated(obj, &view.rotated, n, sg);
674 sg = assert_remapped(obj, &view.remapped, n, sg);
676 pr_err("Inconsistent %s VMA pages for plane %d: [(%d, %d, %d, %d, %d), (%d, %d, %d, %d, %d)]\n",
677 view.type == I915_GTT_VIEW_ROTATED ?
678 "rotated" : "remapped", n,
680 plane_info[0].height,
681 plane_info[0].src_stride,
682 plane_info[0].dst_stride,
683 plane_info[0].offset,
685 plane_info[1].height,
686 plane_info[1].src_stride,
687 plane_info[1].dst_stride,
688 plane_info[1].offset);
695 err = i915_vma_unbind_unlocked(vma);
697 pr_err("Unbinding returned %i\n", err);
708 i915_gem_object_put(obj);
713 static bool assert_partial(struct drm_i915_gem_object *obj,
714 struct i915_vma *vma,
715 unsigned long offset,
721 for_each_sgt_daddr(dma, sgt, vma->pages) {
725 pr_err("Partial scattergather list too long\n");
729 src = i915_gem_object_get_dma_address(obj, offset);
731 pr_err("DMA mismatch for partial page offset %lu\n",
743 static bool assert_pin(struct i915_vma *vma,
744 struct i915_gtt_view *view,
750 if (vma->size != size) {
751 pr_err("(%s) VMA is wrong size, expected %llu, found %llu\n",
752 name, size, vma->size);
756 if (vma->node.size < vma->size) {
757 pr_err("(%s) VMA binding too small, expected %llu, found %llu\n",
758 name, vma->size, vma->node.size);
762 if (view && view->type != I915_GTT_VIEW_NORMAL) {
763 if (memcmp(&vma->gtt_view, view, sizeof(*view))) {
764 pr_err("(%s) VMA mismatch upon creation!\n",
769 if (vma->pages == vma->obj->mm.pages) {
770 pr_err("(%s) VMA using original object pages!\n",
775 if (vma->gtt_view.type != I915_GTT_VIEW_NORMAL) {
776 pr_err("Not the normal ggtt view! Found %d\n",
781 if (vma->pages != vma->obj->mm.pages) {
782 pr_err("VMA not using object pages!\n");
790 static int igt_vma_partial(void *arg)
792 struct i915_ggtt *ggtt = arg;
793 struct i915_address_space *vm = &ggtt->vm;
794 const unsigned int npages = 1021; /* prime! */
795 struct drm_i915_gem_object *obj;
803 unsigned int sz, offset;
804 struct i915_vma *vma;
807 /* Create lots of different VMA for the object and check that
808 * we are returned the same VMA when we later request the same range.
811 obj = i915_gem_object_create_internal(vm->i915, npages * PAGE_SIZE);
815 for (p = phases; p->name; p++) { /* exercise both create/lookup */
816 unsigned int count, nvma;
819 for_each_prime_number_from(sz, 1, npages) {
820 for_each_prime_number_from(offset, 0, npages - sz) {
821 struct i915_gtt_view view;
823 view.type = I915_GTT_VIEW_PARTIAL;
824 view.partial.offset = offset;
825 view.partial.size = sz;
828 view.type = I915_GTT_VIEW_NORMAL;
830 vma = checked_vma_instance(obj, vm, &view);
836 err = i915_vma_pin(vma, 0, 0, PIN_GLOBAL);
840 if (!assert_pin(vma, &view, sz*PAGE_SIZE, p->name)) {
841 pr_err("(%s) Inconsistent partial pinning for (offset=%d, size=%d)\n",
842 p->name, offset, sz);
847 if (!assert_partial(obj, vma, offset, sz)) {
848 pr_err("(%s) Inconsistent partial pages for (offset=%d, size=%d)\n",
849 p->name, offset, sz);
856 err = i915_vma_unbind_unlocked(vma);
858 pr_err("Unbinding returned %i\n", err);
867 list_for_each_entry(vma, &obj->vma.list, obj_link)
870 pr_err("(%s) All partial vma were not recorded on the obj->vma_list: found %u, expected %u\n",
871 p->name, count, nvma);
876 /* Check that we did create the whole object mapping */
877 vma = checked_vma_instance(obj, vm, NULL);
883 err = i915_vma_pin(vma, 0, 0, PIN_GLOBAL);
887 if (!assert_pin(vma, NULL, obj->base.size, p->name)) {
888 pr_err("(%s) inconsistent full pin\n", p->name);
895 err = i915_vma_unbind_unlocked(vma);
897 pr_err("Unbinding returned %i\n", err);
902 list_for_each_entry(vma, &obj->vma.list, obj_link)
905 pr_err("(%s) allocated an extra full vma!\n", p->name);
912 i915_gem_object_put(obj);
917 int i915_vma_mock_selftests(void)
919 static const struct i915_subtest tests[] = {
920 SUBTEST(igt_vma_create),
921 SUBTEST(igt_vma_pin1),
922 SUBTEST(igt_vma_rotate_remap),
923 SUBTEST(igt_vma_partial),
925 struct drm_i915_private *i915;
929 i915 = mock_gem_device();
933 /* allocate the ggtt */
934 err = intel_gt_assign_ggtt(to_gt(i915));
942 err = i915_subtests(tests, gt->ggtt);
944 mock_device_flush(i915);
945 i915_gem_drain_freed_objects(i915);
946 mock_fini_ggtt(gt->ggtt);
949 mock_destroy_device(i915);
953 static int igt_vma_remapped_gtt(void *arg)
955 struct drm_i915_private *i915 = arg;
956 const struct intel_remapped_plane_info planes[] = {
957 { .width = 1, .height = 1, .src_stride = 1 },
958 { .width = 2, .height = 2, .src_stride = 2 },
959 { .width = 4, .height = 4, .src_stride = 4 },
960 { .width = 8, .height = 8, .src_stride = 8 },
962 { .width = 3, .height = 5, .src_stride = 3 },
963 { .width = 3, .height = 5, .src_stride = 4 },
964 { .width = 3, .height = 5, .src_stride = 5 },
966 { .width = 5, .height = 3, .src_stride = 5 },
967 { .width = 5, .height = 3, .src_stride = 7 },
968 { .width = 5, .height = 3, .src_stride = 9 },
970 { .width = 4, .height = 6, .src_stride = 6 },
971 { .width = 6, .height = 4, .src_stride = 6 },
973 { .width = 2, .height = 2, .src_stride = 2, .dst_stride = 2 },
974 { .width = 3, .height = 3, .src_stride = 3, .dst_stride = 4 },
975 { .width = 5, .height = 6, .src_stride = 7, .dst_stride = 8 },
979 enum i915_gtt_view_type types[] = {
980 I915_GTT_VIEW_ROTATED,
981 I915_GTT_VIEW_REMAPPED,
984 struct drm_i915_gem_object *obj;
985 intel_wakeref_t wakeref;
988 if (!i915_ggtt_has_aperture(to_gt(i915)->ggtt))
991 obj = i915_gem_object_create_internal(i915, 10 * 10 * PAGE_SIZE);
995 wakeref = intel_runtime_pm_get(&i915->runtime_pm);
997 for (t = types; *t; t++) {
998 for (p = planes; p->width; p++) {
999 struct i915_gtt_view view = {
1001 .rotated.plane[0] = *p,
1003 struct intel_remapped_plane_info *plane_info = view.rotated.plane;
1004 struct i915_vma *vma;
1008 i915_gem_object_lock(obj, NULL);
1009 err = i915_gem_object_set_to_gtt_domain(obj, true);
1010 i915_gem_object_unlock(obj);
1014 if (!plane_info[0].dst_stride)
1015 plane_info[0].dst_stride = *t == I915_GTT_VIEW_ROTATED ?
1016 p->height : p->width;
1018 vma = i915_gem_object_ggtt_pin(obj, &view, 0, 0, PIN_MAPPABLE);
1024 GEM_BUG_ON(vma->gtt_view.type != *t);
1026 map = i915_vma_pin_iomap(vma);
1027 i915_vma_unpin(vma);
1033 for (y = 0 ; y < plane_info[0].height; y++) {
1034 for (x = 0 ; x < plane_info[0].width; x++) {
1035 unsigned int offset;
1036 u32 val = y << 16 | x;
1038 if (*t == I915_GTT_VIEW_ROTATED)
1039 offset = (x * plane_info[0].dst_stride + y) * PAGE_SIZE;
1041 offset = (y * plane_info[0].dst_stride + x) * PAGE_SIZE;
1043 iowrite32(val, &map[offset / sizeof(*map)]);
1047 i915_vma_unpin_iomap(vma);
1049 vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, PIN_MAPPABLE);
1055 GEM_BUG_ON(vma->gtt_view.type != I915_GTT_VIEW_NORMAL);
1057 map = i915_vma_pin_iomap(vma);
1058 i915_vma_unpin(vma);
1064 for (y = 0 ; y < plane_info[0].height; y++) {
1065 for (x = 0 ; x < plane_info[0].width; x++) {
1066 unsigned int offset, src_idx;
1067 u32 exp = y << 16 | x;
1070 if (*t == I915_GTT_VIEW_ROTATED)
1071 src_idx = rotated_index(&view.rotated, 0, x, y);
1073 src_idx = remapped_index(&view.remapped, 0, x, y);
1074 offset = src_idx * PAGE_SIZE;
1076 val = ioread32(&map[offset / sizeof(*map)]);
1078 pr_err("%s VMA write test failed, expected 0x%x, found 0x%x\n",
1079 *t == I915_GTT_VIEW_ROTATED ? "Rotated" : "Remapped",
1081 i915_vma_unpin_iomap(vma);
1087 i915_vma_unpin_iomap(vma);
1094 intel_runtime_pm_put(&i915->runtime_pm, wakeref);
1095 i915_gem_object_put(obj);
1100 int i915_vma_live_selftests(struct drm_i915_private *i915)
1102 static const struct i915_subtest tests[] = {
1103 SUBTEST(igt_vma_remapped_gtt),
1106 return i915_live_subtests(tests, i915);