kms_rotation_crc: Allow the sprite test to run even without universal planes
[platform/upstream/intel-gpu-tools.git] / tests / gem_set_tiling_vs_gtt.c
1 /*
2  * Copyright © 2012 Intel Corporation
3  *
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:
10  *
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
13  * Software.
14  *
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
21  * IN THE SOFTWARE.
22  *
23  * Authors:
24  *    Daniel Vetter <daniel.vetter@ffwll.ch>
25  *
26  */
27
28 #include <unistd.h>
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <string.h>
32 #include <fcntl.h>
33 #include <inttypes.h>
34 #include <errno.h>
35 #include <sys/stat.h>
36 #include <sys/ioctl.h>
37 #include "drm.h"
38 #include "ioctl_wrappers.h"
39 #include "drmtest.h"
40 #include "intel_io.h"
41 #include "intel_chipset.h"
42
43 #define OBJECT_SIZE (1024*1024)
44 #define TEST_STRIDE (1024*4)
45
46 /**
47  * Testcase: Check set_tiling vs gtt mmap coherency
48  */
49
50 igt_simple_main
51 {
52         int fd;
53         uint32_t *ptr;
54         uint32_t data[OBJECT_SIZE/4];
55         int i;
56         uint32_t handle;
57         bool tiling_changed;
58         int tile_height;
59
60         igt_skip_on_simulation();
61
62         fd = drm_open_any();
63
64         if (IS_GEN2(intel_get_drm_devid(fd)))
65                 tile_height = 16;
66         else
67                 tile_height = 8;
68
69         handle = gem_create(fd, OBJECT_SIZE);
70         ptr = gem_mmap(fd, handle, OBJECT_SIZE, PROT_READ | PROT_WRITE);
71         igt_assert(ptr);
72
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++)
76                 ptr[i] = data[i] = i;
77
78         gem_set_tiling(fd, handle, I915_TILING_X, TEST_STRIDE);
79
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);
89
90         gem_set_domain(fd, handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
91         for (i = 0; i < OBJECT_SIZE/4; i++)
92                 ptr[i] = data[i] = i;
93
94         gem_set_tiling(fd, handle, I915_TILING_X, TEST_STRIDE*2);
95
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)
104                         + row*TEST_STRIDE/4
105                         + half*tile_height + ofs;
106                 uint32_t val = data[data_i];
107
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",
111                              i, row, half, ofs,
112                              ptr[i], val);
113
114         }
115
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;
119
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);
130
131         munmap(ptr, OBJECT_SIZE);
132
133         close(fd);
134 }