2 * Copyright © 2012 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
24 * Daniel Vetter <daniel.vetter@ffwll.ch>
36 #include <sys/ioctl.h>
38 #include "ioctl_wrappers.h"
41 #include "intel_chipset.h"
43 #define OBJECT_SIZE (1024*1024)
44 #define TEST_STRIDE (1024*4)
47 * Testcase: Check set_tiling vs gtt mmap coherency
54 uint32_t data[OBJECT_SIZE/4];
60 igt_skip_on_simulation();
64 if (IS_GEN2(intel_get_drm_devid(fd)))
69 handle = gem_create(fd, OBJECT_SIZE);
70 ptr = gem_mmap(fd, handle, OBJECT_SIZE, PROT_READ | PROT_WRITE);
73 /* gtt coherency is done with set_domain in libdrm, don't break that */
74 gem_set_domain(fd, handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
75 for (i = 0; i < OBJECT_SIZE/4; i++)
78 gem_set_tiling(fd, handle, I915_TILING_X, TEST_STRIDE);
80 igt_info("testing untiled->tiled\n");
81 tiling_changed = false;
82 gem_set_domain(fd, handle, I915_GEM_DOMAIN_GTT, 0);
83 /* Too lazy to check for the correct tiling, and impossible anyway on
84 * bit17 swizzling machines. */
85 for (i = 0; i < OBJECT_SIZE/4; i++)
86 if (ptr[i] != data[i])
87 tiling_changed = true;
88 igt_assert(tiling_changed);
90 gem_set_domain(fd, handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
91 for (i = 0; i < OBJECT_SIZE/4; i++)
94 gem_set_tiling(fd, handle, I915_TILING_X, TEST_STRIDE*2);
96 igt_info("testing tiled->tiled\n");
97 gem_set_domain(fd, handle, I915_GEM_DOMAIN_GTT, 0);
98 for (i = 0; i < OBJECT_SIZE/4; i++) {
99 int tile_row = i / (TEST_STRIDE * tile_height / 4);
100 int row = i / (TEST_STRIDE * 2 / 4);
101 int half = i & (TEST_STRIDE / 4);
102 int ofs = i % (TEST_STRIDE / 4);
103 int data_i = (tile_row/2)*(TEST_STRIDE * tile_height / 4)
105 + half*tile_height + ofs;
106 uint32_t val = data[data_i];
108 igt_assert_f(ptr[i] == val,
109 "mismatch at %i, row=%i, half=%i, ofs=%i, "
110 "read: 0x%08x, expected: 0x%08x\n",
116 gem_set_domain(fd, handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
117 for (i = 0; i < OBJECT_SIZE/4; i++)
118 ptr[i] = data[i] = i;
120 gem_set_tiling(fd, handle, I915_TILING_NONE, 0);
121 igt_info("testing tiled->untiled\n");
122 tiling_changed = false;
123 gem_set_domain(fd, handle, I915_GEM_DOMAIN_GTT, 0);
124 /* Too lazy to check for the correct tiling, and impossible anyway on
125 * bit17 swizzling machines. */
126 for (i = 0; i < OBJECT_SIZE/4; i++)
127 if (ptr[i] != data[i])
128 tiling_changed = true;
129 igt_assert(tiling_changed);
131 munmap(ptr, OBJECT_SIZE);