1 /*
2 * Copyright © 2017 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
24 #include <signal.h>
25
26 #include "igt.h"
27 #include "drmtest.h"
28 #include "sw_sync.h"
29
30 IGT_TEST_DESCRIPTION("Tests that interrupt various atomic ioctls.");
31
32 enum plane_test_type
33 {
34 test_legacy_modeset,
35 test_atomic_modeset,
36 test_legacy_dpms,
37 test_setplane,
38 test_setcursor,
39 test_pageflip
40 };
41
block_plane(igt_display_t * display,igt_output_t * output,enum plane_test_type test_type,igt_plane_t * plane)42 static int block_plane(igt_display_t *display, igt_output_t *output, enum plane_test_type test_type, igt_plane_t *plane)
43 {
44 int timeline = sw_sync_timeline_create();
45
46 igt_fork(child, 1) {
47 /* Ignore the signal helper, we need to block indefinitely on the fence. */
48 signal(SIGCONT, SIG_IGN);
49
50 if (test_type == test_legacy_modeset || test_type == test_atomic_modeset) {
51 igt_output_set_pipe(output, PIPE_NONE);
52 igt_plane_set_fb(plane, NULL);
53 }
54 igt_plane_set_fence_fd(plane, sw_sync_timeline_create_fence(timeline, 1));
55
56 igt_display_commit2(display, COMMIT_ATOMIC);
57 }
58
59 return timeline;
60 }
61
unblock(int block)62 static void unblock(int block)
63 {
64 sw_sync_timeline_inc(block, 1);
65 close(block);
66 }
67
ev_page_flip(int fd,unsigned seq,unsigned tv_sec,unsigned tv_usec,void * user_data)68 static void ev_page_flip(int fd, unsigned seq, unsigned tv_sec, unsigned tv_usec, void *user_data)
69 {
70 igt_debug("Retrieved vblank seq: %u on unk\n", seq);
71 }
72
73 static drmEventContext drm_events = {
74 .version = 2,
75 .page_flip_handler = ev_page_flip
76 };
77
run_plane_test(igt_display_t * display,enum pipe pipe,igt_output_t * output,enum plane_test_type test_type,unsigned plane_type)78 static void run_plane_test(igt_display_t *display, enum pipe pipe, igt_output_t *output,
79 enum plane_test_type test_type, unsigned plane_type)
80 {
81 drmModeModeInfo *mode;
82 igt_fb_t fb, fb2;
83 igt_plane_t *primary, *plane;
84 int block;
85
86 /*
87 * Make sure we start with everything disabled to force a real modeset.
88 * igt_display_require only sets sw state, and assumes the first test
89 * doesn't care about hw state.
90 */
91 igt_display_commit2(display, COMMIT_ATOMIC);
92
93 igt_output_set_pipe(output, pipe);
94
95 primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY);
96 plane = igt_output_get_plane_type(output, plane_type);
97 mode = igt_output_get_mode(output);
98
99 igt_create_fb(display->drm_fd, mode->hdisplay, mode->vdisplay,
100 DRM_FORMAT_XRGB8888, LOCAL_DRM_FORMAT_MOD_NONE, &fb);
101
102 switch (plane_type) {
103 case DRM_PLANE_TYPE_PRIMARY:
104 igt_create_fb(display->drm_fd, mode->hdisplay, mode->vdisplay,
105 DRM_FORMAT_XRGB8888, LOCAL_DRM_FORMAT_MOD_NONE, &fb2);
106 break;
107 case DRM_PLANE_TYPE_CURSOR:
108 igt_create_fb(display->drm_fd, 64, 64,
109 DRM_FORMAT_ARGB8888, LOCAL_DRM_FORMAT_MOD_NONE, &fb2);
110 break;
111 }
112
113 if (test_type != test_legacy_modeset && test_type != test_atomic_modeset) {
114 igt_plane_set_fb(primary, &fb);
115 igt_display_commit2(display, COMMIT_ATOMIC);
116 }
117
118 igt_plane_set_fb(plane, &fb2);
119
120 block = block_plane(display, output, test_type, plane);
121
122 /* wait for the block to complete in block_plane */
123 sleep(1);
124
125 igt_fork(child, 1) {
126 signal(SIGCONT, SIG_IGN);
127
128 /* unblock after 5 seconds to allow the ioctl to complete,
129 * instead of failing with -EINTR.
130 */
131 igt_assert(sleep(5) == 0);
132
133 unblock(block);
134 }
135
136 /* run the test */
137 igt_while_interruptible(true) {
138 switch (test_type) {
139 case test_legacy_modeset: {
140 struct drm_mode_crtc crtc = {
141 .set_connectors_ptr = (uint64_t)(uintptr_t)&output->id,
142 .count_connectors = 1,
143 .crtc_id = primary->pipe->crtc_id,
144 .fb_id = fb2.fb_id,
145 .mode_valid = 1,
146 .mode = *(struct drm_mode_modeinfo*)mode,
147 };
148
149 do_ioctl(display->drm_fd, DRM_IOCTL_MODE_SETCRTC, &crtc);
150 break;
151 }
152 case test_atomic_modeset: {
153 uint32_t objs[3] = {
154 plane->pipe->crtc_id,
155 output->id,
156 plane->drm_plane->plane_id
157 };
158 uint32_t count_props[3] = { 2, 1, 6 };
159 uint32_t props[] = {
160 /* crtc: 2 props */
161 plane->pipe->props[IGT_CRTC_MODE_ID],
162 plane->pipe->props[IGT_CRTC_ACTIVE],
163 /* connector: 1 prop */
164 output->props[IGT_CONNECTOR_CRTC_ID],
165 /* plane: remainder props */
166 plane->props[IGT_PLANE_CRTC_ID],
167 plane->props[IGT_PLANE_FB_ID],
168 plane->props[IGT_PLANE_SRC_W],
169 plane->props[IGT_PLANE_SRC_H],
170 plane->props[IGT_PLANE_CRTC_W],
171 plane->props[IGT_PLANE_CRTC_H]
172 };
173 uint64_t prop_vals[] = {
174 /* crtc */
175 0, /* mode_id, filled in below */
176 true,
177 /* connector */
178 plane->pipe->crtc_id,
179 /* plane */
180 plane->pipe->crtc_id,
181 fb2.fb_id,
182 IGT_FIXED(fb2.width, 0),
183 IGT_FIXED(fb2.height, 0),
184 fb2.width,
185 fb2.height
186 };
187 uint32_t mode_blob;
188
189 struct drm_mode_atomic atm = {
190 .flags = DRM_MODE_ATOMIC_ALLOW_MODESET,
191 .count_objs = 3, /* crtc, connector, plane */
192 .objs_ptr = (uint64_t)(uintptr_t)&objs,
193 .count_props_ptr = (uint64_t)(uintptr_t)&count_props,
194 .props_ptr = (uint64_t)(uintptr_t)&props,
195 .prop_values_ptr = (uint64_t)(uintptr_t)&prop_vals,
196 };
197
198 do_or_die(drmModeCreatePropertyBlob(display->drm_fd, mode, sizeof(*mode), &mode_blob));
199 prop_vals[0] = mode_blob;
200
201 do_ioctl(display->drm_fd, DRM_IOCTL_MODE_ATOMIC, &atm);
202
203 do_or_die(drmModeDestroyPropertyBlob(display->drm_fd, mode_blob));
204 break;
205 }
206 case test_legacy_dpms: {
207 struct drm_mode_connector_set_property prop = {
208 .value = DRM_MODE_DPMS_OFF,
209 .prop_id = output->props[IGT_CONNECTOR_DPMS],
210 .connector_id = output->id,
211 };
212
213 do_ioctl(display->drm_fd, DRM_IOCTL_MODE_SETPROPERTY, &prop);
214 break;
215 }
216 case test_setcursor: {
217 struct drm_mode_cursor cur = {
218 .flags = DRM_MODE_CURSOR_BO,
219 .crtc_id = plane->pipe->crtc_id,
220 .width = fb2.width,
221 .height = fb2.height,
222 .handle = fb2.gem_handle,
223 };
224 do_ioctl(display->drm_fd, DRM_IOCTL_MODE_CURSOR, &cur);
225 break;
226 }
227 case test_setplane: {
228 struct drm_mode_set_plane setplane = {
229 .plane_id = plane->drm_plane->plane_id,
230 .crtc_id = plane->pipe->crtc_id,
231 .fb_id = fb2.fb_id,
232 .crtc_w = fb2.width,
233 .crtc_h = fb2.height,
234 .src_w = IGT_FIXED(fb2.width, 0),
235 .src_h = IGT_FIXED(fb2.height, 0),
236 };
237
238 do_ioctl(display->drm_fd, DRM_IOCTL_MODE_SETPLANE, &setplane);
239 break;
240 }
241 case test_pageflip: {
242 struct drm_mode_crtc_page_flip pageflip = {
243 .crtc_id = plane->pipe->crtc_id,
244 .fb_id = fb2.fb_id,
245 .flags = DRM_MODE_PAGE_FLIP_EVENT,
246 };
247
248 do_ioctl(display->drm_fd, DRM_IOCTL_MODE_PAGE_FLIP, &pageflip);
249
250 drmHandleEvent(display->drm_fd, &drm_events);
251 break;
252 }
253 }
254 }
255
256 igt_waitchildren();
257
258 /* The mode is unset by the forked helper, force a refresh here */
259 if (test_type == test_legacy_modeset || test_type == test_atomic_modeset)
260 igt_pipe_refresh(display, pipe, true);
261
262 igt_plane_set_fb(plane, NULL);
263 igt_plane_set_fb(primary, NULL);
264 igt_output_set_pipe(output, PIPE_NONE);
265 igt_display_commit2(display, COMMIT_ATOMIC);
266 igt_remove_fb(display->drm_fd, &fb);
267 }
268
269 igt_main
270 {
271 igt_display_t display;
272 igt_output_t *output;
273 enum pipe pipe;
274
275 igt_skip_on_simulation();
276
277 igt_fixture {
278 display.drm_fd = drm_open_driver_master(DRIVER_ANY);
279
280 kmstest_set_vt_graphics_mode();
281
282 igt_display_require(&display, display.drm_fd);
283 igt_require(display.is_atomic);
284 igt_display_require_output(&display);
285
286 igt_require_sw_sync();
287 }
288
289 igt_subtest("legacy-setmode")
290 for_each_pipe_with_valid_output(&display, pipe, output) {
291 run_plane_test(&display, pipe, output, test_legacy_modeset, DRM_PLANE_TYPE_PRIMARY);
292 break;
293 }
294
295 igt_subtest("atomic-setmode")
296 for_each_pipe_with_valid_output(&display, pipe, output) {
297 run_plane_test(&display, pipe, output, test_atomic_modeset, DRM_PLANE_TYPE_PRIMARY);
298 break;
299 }
300
301 igt_subtest("legacy-dpms")
302 for_each_pipe_with_valid_output(&display, pipe, output) {
303 run_plane_test(&display, pipe, output, test_legacy_dpms, DRM_PLANE_TYPE_PRIMARY);
304 break;
305 }
306
307 igt_subtest("legacy-pageflip")
308 for_each_pipe_with_valid_output(&display, pipe, output) {
309 run_plane_test(&display, pipe, output, test_pageflip, DRM_PLANE_TYPE_PRIMARY);
310 break;
311 }
312
313 igt_subtest("legacy-cursor")
314 for_each_pipe_with_valid_output(&display, pipe, output) {
315 run_plane_test(&display, pipe, output, test_setcursor, DRM_PLANE_TYPE_CURSOR);
316 break;
317 }
318
319 igt_subtest("universal-setplane-primary")
320 for_each_pipe_with_valid_output(&display, pipe, output) {
321 run_plane_test(&display, pipe, output, test_setplane, DRM_PLANE_TYPE_PRIMARY);
322 break;
323 }
324
325 igt_subtest("universal-setplane-cursor")
326 for_each_pipe_with_valid_output(&display, pipe, output) {
327 run_plane_test(&display, pipe, output, test_setplane, DRM_PLANE_TYPE_CURSOR);
328 break;
329 }
330
331 /* TODO: legacy gamma_set/get, object set/getprop, getcrtc, getconnector */
332 igt_fixture {
333 igt_display_fini(&display);
334 }
335 }
336