2 * Copyright © 2013 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>
40 #include "ioctl_wrappers.h"
42 #include "igt_debugfs.h"
45 #define OBJECT_SIZE (16*1024*1024)
48 test_fence_restore(int fd, bool tiled2untiled)
50 uint32_t handle1, handle2, handle_tiled;
51 uint32_t *ptr1, *ptr2, *ptr_tiled;
54 /* We wall the tiled object with untiled canary objects to make sure
55 * that we detect tile leaking in both directions. */
56 handle1 = gem_create(fd, OBJECT_SIZE);
57 handle2 = gem_create(fd, OBJECT_SIZE);
58 handle_tiled = gem_create(fd, OBJECT_SIZE);
60 /* Access the buffer objects in the order we want to have the laid out. */
61 ptr1 = gem_mmap(fd, handle1, OBJECT_SIZE, PROT_READ | PROT_WRITE);
62 igt_assert(ptr1 != MAP_FAILED);
63 for (i = 0; i < OBJECT_SIZE/sizeof(uint32_t); i++)
66 ptr_tiled = gem_mmap(fd, handle_tiled, OBJECT_SIZE, PROT_READ | PROT_WRITE);
67 igt_assert(ptr_tiled != MAP_FAILED);
69 gem_set_tiling(fd, handle_tiled, I915_TILING_X, 2048);
70 for (i = 0; i < OBJECT_SIZE/sizeof(uint32_t); i++)
73 ptr2 = gem_mmap(fd, handle2, OBJECT_SIZE, PROT_READ | PROT_WRITE);
74 igt_assert(ptr2 != MAP_FAILED);
75 for (i = 0; i < OBJECT_SIZE/sizeof(uint32_t); i++)
79 gem_set_tiling(fd, handle_tiled, I915_TILING_NONE, 2048);
81 gem_set_tiling(fd, handle_tiled, I915_TILING_X, 2048);
83 igt_system_suspend_autoresume();
85 igt_info("checking the first canary object\n");
86 for (i = 0; i < OBJECT_SIZE/sizeof(uint32_t); i++)
87 igt_assert(ptr1[i] == i);
89 igt_info("checking the second canary object\n");
90 for (i = 0; i < OBJECT_SIZE/sizeof(uint32_t); i++)
91 igt_assert(ptr2[i] == i);
93 gem_close(fd, handle1);
94 gem_close(fd, handle2);
95 gem_close(fd, handle_tiled);
97 munmap(ptr1, OBJECT_SIZE);
98 munmap(ptr2, OBJECT_SIZE);
99 munmap(ptr_tiled, OBJECT_SIZE);
103 test_debugfs_reader(void)
105 struct igt_helper_process reader = {};
106 reader.use_SIGKILL = true;
108 igt_fork_helper(&reader) {
109 static const char dfs_base[] = "/sys/kernel/debug/dri";
110 static char tmp[1024];
112 snprintf(tmp, sizeof(tmp) - 1,
113 "while true; do find %s/%i/ -type f | xargs cat > /dev/null 2>&1; done",
114 dfs_base, drm_get_card());
115 igt_assert(execl("/bin/sh", "sh", "-c", tmp, (char *) NULL) != -1);
120 igt_system_suspend_autoresume();
124 igt_stop_helper(&reader);
128 test_sysfs_reader(void)
130 struct igt_helper_process reader = {};
131 reader.use_SIGKILL = true;
133 igt_fork_helper(&reader) {
134 static const char dfs_base[] = "/sys/class/drm/card";
135 static char tmp[1024];
137 snprintf(tmp, sizeof(tmp) - 1,
138 "while true; do find %s%i*/ -type f | xargs cat > /dev/null 2>&1; done",
139 dfs_base, drm_get_card());
140 igt_assert(execl("/bin/sh", "sh", "-c", tmp, (char *) NULL) != -1);
145 igt_system_suspend_autoresume();
149 igt_stop_helper(&reader);
157 fw_fd = igt_open_forcewake_handle();
158 igt_assert(fw_fd >= 0);
159 igt_system_suspend_autoresume();
167 igt_skip_on_simulation();
172 igt_subtest("fence-restore-tiled2untiled")
173 test_fence_restore(fd, true);
175 igt_subtest("fence-restore-untiled")
176 test_fence_restore(fd, false);
178 igt_subtest("debugfs-reader")
179 test_debugfs_reader();
181 igt_subtest("sysfs-reader")
184 igt_subtest("forcewake")