1 /*
2  * Copyright © 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  *   Ander Conselvan de Oliveira <ander.conselvan.de.oliveira@intel.com>
25  */
26 
27 #include "igt.h"
28 
29 IGT_TEST_DESCRIPTION(
30 "Exercise the FDI lane bifurcation code for IVB in the kernel by setting"
31 "different combinations of modes for pipes B and C.");
32 
33 typedef struct {
34 	int drm_fd;
35 	igt_display_t display;
36 } data_t;
37 
38 drmModeModeInfo mode_3_lanes = {
39 	.clock = 173000,
40 	.hdisplay = 1920,
41 	.hsync_start = 2048,
42 	.hsync_end = 2248,
43 	.htotal = 2576,
44 	.vdisplay = 1080,
45 	.vsync_start = 1083,
46 	.vsync_end = 1088,
47 	.vtotal = 1120,
48 	.vrefresh = 60,
49 	.flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC,
50 	.name = "3_lanes",
51 };
52 
53 drmModeModeInfo mode_2_lanes = {
54 	.clock = 138500,
55 	.hdisplay = 1920,
56 	.hsync_start = 1968,
57 	.hsync_end = 2000,
58 	.htotal = 2080,
59 	.vdisplay = 1080,
60 	.vsync_start = 1083,
61 	.vsync_end = 1088,
62 	.vtotal = 1111,
63 	.vrefresh = 60,
64 	.flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC,
65 	.name = "2_lanes",
66 };
67 
68 static int
disable_pipe(data_t * data,enum pipe pipe,igt_output_t * output)69 disable_pipe(data_t *data, enum pipe pipe, igt_output_t *output)
70 {
71 	igt_plane_t *primary;
72 
73 	igt_output_set_pipe(output, pipe);
74 	primary = igt_output_get_plane(output, 0);
75 	igt_plane_set_fb(primary, NULL);
76 	return igt_display_commit(&data->display);
77 }
78 
79 static int
set_mode_on_pipe(data_t * data,enum pipe pipe,igt_output_t * output)80 set_mode_on_pipe(data_t *data, enum pipe pipe, igt_output_t *output)
81 {
82 	igt_plane_t *primary;
83 	drmModeModeInfo *mode;
84 	struct igt_fb fb;
85 	int fb_id;
86 
87 	igt_output_set_pipe(output, pipe);
88 
89 	mode = igt_output_get_mode(output);
90 
91 	primary = igt_output_get_plane(output, 0);
92 
93 	fb_id = igt_create_color_fb(data->drm_fd,
94 				    mode->hdisplay, mode->vdisplay,
95 				    DRM_FORMAT_XRGB8888, I915_TILING_NONE,
96 				    1.0, 1.0, 1.0, &fb);
97 	igt_assert_lte(0, fb_id);
98 
99 	igt_plane_set_fb(primary, &fb);
100 	return igt_display_try_commit2(&data->display, COMMIT_LEGACY);
101 }
102 
103 static int
set_big_mode_on_pipe(data_t * data,enum pipe pipe,igt_output_t * output)104 set_big_mode_on_pipe(data_t *data, enum pipe pipe, igt_output_t *output)
105 {
106 	igt_output_override_mode(output, &mode_3_lanes);
107 	return set_mode_on_pipe(data, pipe, output);
108 }
109 
110 static int
set_normal_mode_on_pipe(data_t * data,enum pipe pipe,igt_output_t * output)111 set_normal_mode_on_pipe(data_t *data, enum pipe pipe, igt_output_t *output)
112 {
113 	igt_output_override_mode(output, &mode_2_lanes);
114 	return set_mode_on_pipe(data, pipe, output);
115 }
116 
117 static void
find_outputs(data_t * data,igt_output_t ** output1,igt_output_t ** output2)118 find_outputs(data_t *data, igt_output_t **output1, igt_output_t **output2)
119 {
120 	igt_output_t *output;
121 	enum pipe pipe;
122 
123 	*output1 = NULL;
124 	*output2 = NULL;
125 
126 	for_each_pipe_with_valid_output(&data->display, pipe, output) {
127 		if (pipe == PIPE_B && !*output1 && output != *output2)
128 			*output1 = output;
129 
130 		if (pipe == PIPE_C && output != *output1 && !*output2)
131 			*output2 = output;
132 
133 		igt_output_set_pipe(output, PIPE_ANY);
134 	}
135 
136 	igt_skip_on_f(!*output1 || !*output2, "Not enough connected outputs\n");
137 }
138 
139 static void
test_dpms(data_t * data)140 test_dpms(data_t *data)
141 {
142 	igt_output_t *output1, *output2;
143 	int ret;
144 
145 	find_outputs(data, &output1, &output2);
146 
147 	igt_info("Pipe %s will use connector %s\n",
148 		 kmstest_pipe_name(PIPE_B), igt_output_name(output1));
149 	igt_info("Pipe %s will use connector %s\n",
150 		 kmstest_pipe_name(PIPE_C), igt_output_name(output2));
151 
152 	ret = set_big_mode_on_pipe(data, PIPE_B, output1);
153 	igt_assert_eq(ret, 0);
154 
155 	kmstest_set_connector_dpms(data->drm_fd, output1->config.connector, DRM_MODE_DPMS_OFF);
156 
157 	ret = set_big_mode_on_pipe(data, PIPE_C, output2);
158 	igt_assert_neq(ret, 0);
159 }
160 
161 static void
test_lane_reduction(data_t * data)162 test_lane_reduction(data_t *data)
163 {
164 	igt_output_t *output1, *output2;
165 	int ret;
166 
167 	find_outputs(data, &output1, &output2);
168 
169 	igt_info("Pipe %s will use connector %s\n",
170 		 kmstest_pipe_name(PIPE_B), igt_output_name(output1));
171 	igt_info("Pipe %s will use connector %s\n",
172 		 kmstest_pipe_name(PIPE_C), igt_output_name(output2));
173 
174 	ret = set_big_mode_on_pipe(data, PIPE_B, output1);
175 	igt_assert_eq(ret, 0);
176 
177 	ret = set_normal_mode_on_pipe(data, PIPE_B, output1);
178 	igt_assert_eq(ret, 0);
179 
180 	ret = set_normal_mode_on_pipe(data, PIPE_C, output2);
181 	igt_assert_eq(ret, 0);
182 }
183 
184 static void
test_disable_pipe_B(data_t * data)185 test_disable_pipe_B(data_t *data)
186 {
187 	igt_output_t *output1, *output2;
188 	int ret;
189 
190 	find_outputs(data, &output1, &output2);
191 
192 	igt_info("Pipe %s will use connector %s\n",
193 		 kmstest_pipe_name(PIPE_B), igt_output_name(output1));
194 	igt_info("Pipe %s will use connector %s\n",
195 		 kmstest_pipe_name(PIPE_C), igt_output_name(output2));
196 
197 	ret = set_big_mode_on_pipe(data, PIPE_B, output1);
198 	igt_assert_eq(ret, 0);
199 
200 	ret = disable_pipe(data, PIPE_B, output1);
201 	igt_assert_eq(ret, 0);
202 
203 	ret = set_normal_mode_on_pipe(data, PIPE_C, output2);
204 	igt_assert_eq(ret, 0);
205 
206 	ret = set_normal_mode_on_pipe(data, PIPE_B, output1);
207 	igt_assert_eq(ret, 0);
208 }
209 
210 static void
test_from_C_to_B_with_3_lanes(data_t * data)211 test_from_C_to_B_with_3_lanes(data_t *data)
212 {
213 	igt_output_t *output1, *output2;
214 	int ret;
215 
216 	find_outputs(data, &output1, &output2);
217 
218 	igt_info("Pipe %s will use connector %s\n",
219 		 kmstest_pipe_name(PIPE_B), igt_output_name(output1));
220 	igt_info("Pipe %s will use connector %s\n",
221 		 kmstest_pipe_name(PIPE_C), igt_output_name(output2));
222 
223 	ret = set_normal_mode_on_pipe(data, PIPE_C, output2);
224 	igt_assert_eq(ret, 0);
225 
226 	ret = disable_pipe(data, PIPE_C, output2);
227 	igt_assert_eq(ret, 0);
228 
229 	ret = set_big_mode_on_pipe(data, PIPE_B, output1);
230 	igt_assert_eq(ret, 0);
231 }
232 
233 static void
test_fail_enable_pipe_C_while_B_has_3_lanes(data_t * data)234 test_fail_enable_pipe_C_while_B_has_3_lanes(data_t *data)
235 {
236 	igt_output_t *output1, *output2;
237 	int ret;
238 
239 	find_outputs(data, &output1, &output2);
240 
241 	igt_info("Pipe %s will use connector %s\n",
242 		 kmstest_pipe_name(PIPE_B), igt_output_name(output1));
243 	igt_info("Pipe %s will use connector %s\n",
244 		 kmstest_pipe_name(PIPE_C), igt_output_name(output2));
245 
246 	ret = set_big_mode_on_pipe(data, PIPE_B, output1);
247 	igt_assert_eq(ret, 0);
248 
249 	ret = set_normal_mode_on_pipe(data, PIPE_C, output2);
250 	igt_assert_neq(ret, 0);
251 }
252 
253 static data_t data;
254 igt_main
255 {
256 	int devid;
257 
258 	igt_skip_on_simulation();
259 
260 	igt_fixture {
261 		data.drm_fd = drm_open_driver_master(DRIVER_INTEL);
262 		devid = intel_get_drm_devid(data.drm_fd);
263 		igt_skip_on(!IS_IVYBRIDGE(devid));
264 
265 		kmstest_set_vt_graphics_mode();
266 		igt_display_require(&data.display, data.drm_fd);
267 	}
268 
269 	igt_subtest("pipe-B-dpms-off-modeset-pipe-C")
270 		test_dpms(&data);
271 
272 	igt_subtest("pipe-B-double-modeset-then-modeset-pipe-C")
273 		test_lane_reduction(&data);
274 
275 	igt_subtest("disable-pipe-B-enable-pipe-C")
276 		test_disable_pipe_B(&data);
277 
278 	igt_subtest("from-pipe-C-to-B-with-3-lanes")
279 		test_from_C_to_B_with_3_lanes(&data);
280 
281 	igt_subtest("enable-pipe-C-while-B-has-3-lanes")
282 		test_fail_enable_pipe_C_while_B_has_3_lanes(&data);
283 
284 	igt_fixture {
285 		igt_display_fini(&data.display);
286 	}
287 }
288