kms_rotation_crc: Allow the sprite test to run even without universal planes
[platform/upstream/intel-gpu-tools.git] / tests / gem_tiling_max_stride.c
1 /*
2  * Copyright © 2013 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  *    Ville Syrjälä <ville.syrjala@linux.intel.com>
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 <limits.h>
36 #include <sys/stat.h>
37 #include <sys/ioctl.h>
38 #include "drm.h"
39 #include "ioctl_wrappers.h"
40 #include "drmtest.h"
41 #include "intel_io.h"
42 #include "intel_chipset.h"
43
44 static void do_test_invalid_tiling(int fd, uint32_t handle, int tiling, int stride)
45 {
46         igt_assert(__gem_set_tiling(fd, handle, tiling, tiling ? stride : 0) == -EINVAL);
47 }
48
49 static void test_invalid_tiling(int fd, uint32_t handle, int stride)
50 {
51         do_test_invalid_tiling(fd, handle, I915_TILING_X, stride);
52         do_test_invalid_tiling(fd, handle, I915_TILING_Y, stride);
53 }
54
55 /**
56  * Testcase: Check that max fence stride works
57  */
58
59 igt_simple_main
60 {
61         int fd;
62         uint32_t *ptr;
63         uint32_t *data;
64         uint32_t handle;
65         uint32_t stride;
66         uint32_t size;
67         uint32_t devid;
68         int i = 0, x, y;
69         int tile_width = 512;
70         int tile_height = 8;
71
72         fd = drm_open_any();
73
74         devid = intel_get_drm_devid(fd);
75
76         if (intel_gen(devid) >= 7)
77                 stride = 256 * 1024;
78         else if (intel_gen(devid) >= 4)
79                 stride = 128 * 1024;
80         else {
81                 if (IS_GEN2(devid)) {
82                         tile_width = 128;
83                         tile_height = 16;
84                 }
85                 stride = 8 * 1024;
86         }
87
88         size = stride * tile_height;
89
90         data = malloc(size);
91         igt_assert(data);
92
93         /* Fill each line with the line number */
94         for (y = 0; y < tile_height; y++) {
95                 for (x = 0; x < stride / 4; x++)
96                         data[i++] = y;
97         }
98
99         handle = gem_create(fd, size);
100
101         ptr = gem_mmap(fd, handle, size, PROT_READ | PROT_WRITE);
102         igt_assert(ptr);
103
104         test_invalid_tiling(fd, handle, 0);
105         test_invalid_tiling(fd, handle, 64);
106         test_invalid_tiling(fd, handle, stride - 1);
107         test_invalid_tiling(fd, handle, stride + 1);
108         test_invalid_tiling(fd, handle, stride + 127);
109         test_invalid_tiling(fd, handle, stride + 128);
110         test_invalid_tiling(fd, handle, stride + tile_width - 1);
111         test_invalid_tiling(fd, handle, stride + tile_width);
112         test_invalid_tiling(fd, handle, stride * 2);
113         test_invalid_tiling(fd, handle, INT_MAX);
114         test_invalid_tiling(fd, handle, UINT_MAX);
115
116         gem_set_tiling(fd, handle, I915_TILING_X, stride);
117
118         gem_set_domain(fd, handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
119
120         memcpy(ptr, data, size);
121
122         gem_set_tiling(fd, handle, I915_TILING_NONE, 0);
123
124         memcpy(data, ptr, size);
125
126         /* Check that each tile contains the expected pattern */
127         for (i = 0; i < size / 4; ) {
128                 for (y = 0; y < tile_height; y++) {
129                         for (x = 0; x < tile_width / 4; x++) {
130                                 igt_assert(y == data[i]);
131                                 i++;
132                         }
133                 }
134         }
135
136         munmap(ptr, size);
137
138         close(fd);
139 }