• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2013, 2015 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  *    David Weinehall <david.weinehall@intel.com>
26  *
27  */
28 
29 #include "igt.h"
30 #include <unistd.h>
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <string.h>
34 #include <fcntl.h>
35 #include <inttypes.h>
36 #include <errno.h>
37 #include <sys/stat.h>
38 #include <sys/ioctl.h>
39 
40 #include <drm.h>
41 
42 #include "igt_device.h"
43 
44 #define OBJECT_SIZE (16*1024*1024)
45 
46 static void
test_fence_restore(int fd,bool tiled2untiled,bool hibernate)47 test_fence_restore(int fd, bool tiled2untiled, bool hibernate)
48 {
49 	uint32_t handle1, handle2, handle_tiled;
50 	uint32_t *ptr1, *ptr2, *ptr_tiled;
51 	int i;
52 
53 	/* We wall the tiled object with untiled canary objects to make sure
54 	 * that we detect tile leaking in both directions. */
55 	handle1 = gem_create(fd, OBJECT_SIZE);
56 	handle2 = gem_create(fd, OBJECT_SIZE);
57 	handle_tiled = gem_create(fd, OBJECT_SIZE);
58 
59 	/* Access the buffer objects in the order we want to have the laid out. */
60 	ptr1 = gem_mmap__gtt(fd, handle1, OBJECT_SIZE, PROT_READ | PROT_WRITE);
61 	gem_set_domain(fd, handle1, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
62 	for (i = 0; i < OBJECT_SIZE/sizeof(uint32_t); i++)
63 		ptr1[i] = i;
64 
65 	ptr_tiled = gem_mmap__gtt(fd, handle_tiled, OBJECT_SIZE,
66 				  PROT_READ | PROT_WRITE);
67 	gem_set_domain(fd, handle_tiled,
68 		       I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
69 	if (tiled2untiled)
70 		gem_set_tiling(fd, handle_tiled, I915_TILING_X, 2048);
71 	for (i = 0; i < OBJECT_SIZE/sizeof(uint32_t); i++)
72 		ptr_tiled[i] = i;
73 
74 	ptr2 = gem_mmap__gtt(fd, handle2, OBJECT_SIZE, PROT_READ | PROT_WRITE);
75 	gem_set_domain(fd, handle2, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
76 	for (i = 0; i < OBJECT_SIZE/sizeof(uint32_t); i++)
77 		ptr2[i] = i;
78 
79 	if (tiled2untiled)
80 		gem_set_tiling(fd, handle_tiled, I915_TILING_NONE, 2048);
81 	else
82 		gem_set_tiling(fd, handle_tiled, I915_TILING_X, 2048);
83 
84 	if (hibernate)
85 		igt_system_suspend_autoresume(SUSPEND_STATE_DISK,
86 					      SUSPEND_TEST_NONE);
87 	else
88 		igt_system_suspend_autoresume(SUSPEND_STATE_MEM,
89 					      SUSPEND_TEST_NONE);
90 
91 	igt_info("checking the first canary object\n");
92 	for (i = 0; i < OBJECT_SIZE/sizeof(uint32_t); i++)
93 		igt_assert(ptr1[i] == i);
94 
95 	igt_info("checking the second canary object\n");
96 	for (i = 0; i < OBJECT_SIZE/sizeof(uint32_t); i++)
97 		igt_assert(ptr2[i] == i);
98 
99 	gem_close(fd, handle1);
100 	gem_close(fd, handle2);
101 	gem_close(fd, handle_tiled);
102 
103 	munmap(ptr1, OBJECT_SIZE);
104 	munmap(ptr2, OBJECT_SIZE);
105 	munmap(ptr_tiled, OBJECT_SIZE);
106 }
107 
108 static void
test_debugfs_reader(int fd,bool hibernate)109 test_debugfs_reader(int fd, bool hibernate)
110 {
111 	struct igt_helper_process reader = {};
112 	reader.use_SIGKILL = true;
113 
114 	igt_fork_helper(&reader) {
115 		static const char dfs_base[] = "/sys/kernel/debug/dri";
116 		static char tmp[1024];
117 
118 		snprintf(tmp, sizeof(tmp) - 1,
119 			 "while true; do find %s/%i/ -type f ! -path \"*/crc/*\" | xargs cat > /dev/null 2>&1; done",
120 			 dfs_base, igt_device_get_card_index(fd));
121 		igt_assert(execl("/bin/sh", "sh", "-c", tmp, (char *) NULL) != -1);
122 	}
123 
124 	sleep(1);
125 
126 	if (hibernate)
127 		igt_system_suspend_autoresume(SUSPEND_STATE_DISK,
128 					      SUSPEND_TEST_NONE);
129 	else
130 		igt_system_suspend_autoresume(SUSPEND_STATE_MEM,
131 					      SUSPEND_TEST_NONE);
132 
133 	sleep(1);
134 
135 	igt_stop_helper(&reader);
136 }
137 
138 static void
test_sysfs_reader(int fd,bool hibernate)139 test_sysfs_reader(int fd, bool hibernate)
140 {
141 	struct igt_helper_process reader = {};
142 	reader.use_SIGKILL = true;
143 
144 	igt_fork_helper(&reader) {
145 		static const char dfs_base[] = "/sys/class/drm/card";
146 		static char tmp[1024];
147 
148 		snprintf(tmp, sizeof(tmp) - 1,
149 			 "while true; do find %s%i*/ -type f | xargs cat > /dev/null 2>&1; done",
150 			 dfs_base, igt_device_get_card_index(fd));
151 		igt_assert(execl("/bin/sh", "sh", "-c", tmp, (char *) NULL) != -1);
152 	}
153 
154 	sleep(1);
155 
156 	if (hibernate)
157 		igt_system_suspend_autoresume(SUSPEND_STATE_DISK,
158 					      SUSPEND_TEST_NONE);
159 	else
160 		igt_system_suspend_autoresume(SUSPEND_STATE_MEM,
161 					      SUSPEND_TEST_NONE);
162 
163 	sleep(1);
164 
165 	igt_stop_helper(&reader);
166 }
167 
168 static void
test_shrink(int fd,unsigned int mode)169 test_shrink(int fd, unsigned int mode)
170 {
171 	size_t size;
172 	void *mem;
173 
174 	gem_quiescent_gpu(fd);
175 	intel_purge_vm_caches(fd);
176 
177 	mem = intel_get_total_pinnable_mem(&size);
178 	igt_assert(mem != MAP_FAILED);
179 
180 	intel_purge_vm_caches(fd);
181 	igt_system_suspend_autoresume(mode, SUSPEND_TEST_NONE);
182 
183 	munmap(mem, size);
184 }
185 
186 static void
test_forcewake(int fd,bool hibernate)187 test_forcewake(int fd, bool hibernate)
188 {
189 	int fw_fd;
190 
191 	fw_fd = igt_open_forcewake_handle(fd);
192 	igt_assert_lte(0, fw_fd);
193 
194 	if (hibernate)
195 		igt_system_suspend_autoresume(SUSPEND_STATE_DISK,
196 					      SUSPEND_TEST_NONE);
197 	else
198 		igt_system_suspend_autoresume(SUSPEND_STATE_MEM,
199 					      SUSPEND_TEST_NONE);
200 
201 	close (fw_fd);
202 }
203 
204 int fd;
205 
206 igt_main
207 {
208 	igt_skip_on_simulation();
209 
210 	igt_fixture
211 		fd = drm_open_driver(DRIVER_INTEL);
212 
213 	igt_subtest("fence-restore-tiled2untiled")
214 		test_fence_restore(fd, true, false);
215 
216 	igt_subtest("fence-restore-untiled")
217 		test_fence_restore(fd, false, false);
218 
219 	igt_subtest("debugfs-reader")
220 		test_debugfs_reader(fd, false);
221 
222 	igt_subtest("sysfs-reader")
223 		test_sysfs_reader(fd, false);
224 
225 	igt_subtest("shrink")
226 		test_shrink(fd, SUSPEND_STATE_MEM);
227 
228 	igt_subtest("forcewake")
229 		test_forcewake(fd, false);
230 
231 	igt_subtest("fence-restore-tiled2untiled-hibernate")
232 		test_fence_restore(fd, true, true);
233 
234 	igt_subtest("fence-restore-untiled-hibernate")
235 		test_fence_restore(fd, false, true);
236 
237 	igt_subtest("debugfs-reader-hibernate")
238 		test_debugfs_reader(fd, true);
239 
240 	igt_subtest("sysfs-reader-hibernate")
241 		test_sysfs_reader(fd, true);
242 
243 	igt_subtest("forcewake-hibernate")
244 		test_forcewake(fd, true);
245 
246 	igt_fixture
247 		close(fd);
248 }
249