xref: /aosp_15_r20/external/igt-gpu-tools/tests/i915/gem_tiling_max_stride.c (revision d83cc019efdc2edc6c4b16e9034a3ceb8d35d77c)
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ä <[email protected]>
25  *
26  */
27 
28 #include "igt.h"
29 #include <unistd.h>
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <string.h>
33 #include <fcntl.h>
34 #include <inttypes.h>
35 #include <errno.h>
36 #include <limits.h>
37 #include <sys/stat.h>
38 #include <sys/ioctl.h>
39 #include "drm.h"
40 
41 IGT_TEST_DESCRIPTION("Check that max fence stride works.");
42 
do_test_invalid_tiling(int fd,uint32_t handle,int tiling,int stride)43 static void do_test_invalid_tiling(int fd, uint32_t handle, int tiling, int stride)
44 {
45 	igt_assert(__gem_set_tiling(fd, handle, tiling, tiling ? stride : 0) == -EINVAL);
46 }
47 
test_invalid_tiling(int fd,uint32_t handle,int stride)48 static void test_invalid_tiling(int fd, uint32_t handle, int stride)
49 {
50 	do_test_invalid_tiling(fd, handle, I915_TILING_X, stride);
51 	do_test_invalid_tiling(fd, handle, I915_TILING_Y, stride);
52 }
53 
54 /**
55  * Testcase: Check that max fence stride works
56  */
57 
58 igt_simple_main
59 {
60 	int fd;
61 	uint32_t *ptr;
62 	uint32_t *data;
63 	uint32_t handle;
64 	uint32_t stride;
65 	uint32_t size;
66 	uint32_t devid;
67 	int i = 0, x, y;
68 	int tile_width = 512;
69 	int tile_height = 8;
70 
71 	fd = drm_open_driver(DRIVER_INTEL);
72 
73 	devid = intel_get_drm_devid(fd);
74 
75 	if (intel_gen(devid) >= 7) {
76 		stride = 256 * 1024;
77 	} else if (intel_gen(devid) >= 4) {
78 		stride = 128 * 1024;
79 	} else if (intel_gen(devid) >= 3) {
80 		stride = 8 * 1024;
81 	} else if (intel_gen(devid) >= 2) {
82 		tile_width = 128;
83 		tile_height = 16;
84 		stride = 8 * 1024;
85 	} else {
86 		igt_skip("Unknown Intel chipset, devid=%04x\n", devid);
87 	}
88 
89 	size = stride * tile_height;
90 
91 	data = malloc(size);
92 	igt_assert(data);
93 
94 	/* Fill each line with the line number */
95 	for (y = 0; y < tile_height; y++) {
96 		for (x = 0; x < stride / 4; x++)
97 			data[i++] = y;
98 	}
99 
100 	handle = gem_create(fd, size);
101 
102 	ptr = gem_mmap__gtt(fd, handle, size, PROT_READ | PROT_WRITE);
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 }
140