1 /*
2 * Copyright © 2018 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 * Displayport Display Stream Compression test
24 * Until the CRC support is added this needs to be invoked with --interactive
25 * to manually verify if the test pattern is seen without corruption for each
26 * subtest.
27 *
28 * Authors:
29 * Manasi Navare <manasi.d.navare@intel.com>
30 *
31 */
32 #include "igt.h"
33 #include "igt_sysfs.h"
34 #include <errno.h>
35 #include <getopt.h>
36 #include <math.h>
37 #include <stdint.h>
38 #include <stdbool.h>
39 #include <strings.h>
40 #include <unistd.h>
41 #include <stdlib.h>
42 #include <signal.h>
43 #include <time.h>
44 #include <fcntl.h>
45 #include <termios.h>
46
47 enum dsc_test_type
48 {
49 test_basic_dsc_enable
50 };
51
52 typedef struct {
53 int drm_fd;
54 int debugfs_fd;
55 uint32_t id;
56 igt_display_t display;
57 struct igt_fb fb_test_pattern;
58 igt_output_t *output;
59 int mode_valid;
60 drmModeModeInfo *mode;
61 drmModeConnector *connector;
62 drmModeEncoder *encoder;
63 int crtc;
64 enum pipe pipe;
65 char conn_name[128];
66 } data_t;
67
68 bool force_dsc_en_orig;
69 int force_dsc_restore_fd = -1;
70
manual(const char * expected)71 static inline void manual(const char *expected)
72 {
73 igt_debug_manual_check("all", expected);
74 }
75
is_dp_dsc_supported(data_t * data)76 static bool is_dp_dsc_supported(data_t *data)
77 {
78 char file_name[128] = {0};
79 char buf[512];
80
81 strcpy(file_name, data->conn_name);
82 strcat(file_name, "/i915_dsc_fec_support");
83 igt_require(igt_debugfs_simple_read(data->debugfs_fd, file_name, buf,
84 sizeof(buf)) > 0);
85 igt_debugfs_read(data->drm_fd, file_name, buf);
86
87 return strstr(buf, "DSC_Sink_Support: yes");
88 }
89
is_dp_fec_supported(data_t * data)90 static bool is_dp_fec_supported(data_t *data)
91 {
92 char file_name[128] = {0};
93 char buf[512];
94
95 strcpy(file_name, data->conn_name);
96 strcat(file_name, "/i915_dsc_fec_support");
97 igt_debugfs_read(data->drm_fd, file_name, buf);
98
99 return strstr(buf, "FEC_Sink_Support: yes");
100 }
101
is_dp_dsc_enabled(data_t * data)102 static bool is_dp_dsc_enabled(data_t *data)
103 {
104 char file_name[128] = {0};
105 char buf[512];
106
107 strcpy(file_name, data->conn_name);
108 strcat(file_name, "/i915_dsc_fec_support");
109 igt_debugfs_read(data->drm_fd, file_name, buf);
110
111 return strstr(buf, "DSC_Enabled: yes");
112 }
113
force_dp_dsc_enable(data_t * data)114 static void force_dp_dsc_enable(data_t *data)
115 {
116 char file_name[128] = {0};
117 int ret;
118
119 strcpy(file_name, data->conn_name);
120 strcat(file_name, "/i915_dsc_fec_support");
121 igt_debug ("Forcing DSC enable on %s\n", data->conn_name);
122 ret = igt_sysfs_write(data->debugfs_fd, file_name, "1", 1);
123 igt_assert_f(ret > 0, "debugfs_write failed");
124 }
125
is_force_dsc_enabled(data_t * data)126 static bool is_force_dsc_enabled(data_t *data)
127 {
128 char file_name[128] = {0};
129 char buf[512];
130
131 strcpy(file_name, data->conn_name);
132 strcat(file_name, "/i915_dsc_fec_support");
133 igt_debugfs_read(data->drm_fd, file_name, buf);
134
135 return strstr(buf, "Force_DSC_Enable: yes");
136 }
137
save_force_dsc_en(data_t * data)138 static void save_force_dsc_en(data_t *data)
139 {
140 char file_name[128] = {0};
141
142 force_dsc_en_orig = is_force_dsc_enabled(data);
143 strcpy(file_name, data->conn_name);
144 strcat(file_name, "/i915_dsc_fec_support");
145 force_dsc_restore_fd = openat(igt_debugfs_dir(data->drm_fd),
146 file_name, O_WRONLY);
147 igt_assert(force_dsc_restore_fd >= 0);
148 }
149
restore_force_dsc_en(void)150 static void restore_force_dsc_en(void)
151 {
152 if (force_dsc_restore_fd < 0)
153 return;
154
155 igt_debug("Restoring DSC enable\n");
156 igt_assert(write(force_dsc_restore_fd, force_dsc_en_orig ? "1" : "0", 1) == 1);
157
158 close(force_dsc_restore_fd);
159 force_dsc_restore_fd = -1;
160 }
161
test_cleanup(data_t * data)162 static void test_cleanup(data_t *data)
163 {
164 igt_plane_t *primary;
165
166 if (data->output) {
167 primary = igt_output_get_plane_type(data->output,
168 DRM_PLANE_TYPE_PRIMARY);
169 igt_plane_set_fb(primary, NULL);
170 igt_display_commit(&data->display);
171 igt_remove_fb(data->drm_fd, &data->fb_test_pattern);
172 }
173 }
174
kms_dp_dsc_exit_handler(int sig)175 static void kms_dp_dsc_exit_handler(int sig)
176 {
177 restore_force_dsc_en();
178 }
179
180
181 /*
182 * Re-probe connectors and do a modeset with DSC
183 *
184 */
update_display(data_t * data,enum dsc_test_type test_type)185 static void update_display(data_t *data, enum dsc_test_type test_type)
186 {
187 igt_plane_t *primary;
188 data->mode = igt_output_get_mode(data->output);
189 data->connector = data->output->config.connector;
190
191 if (data->connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort &&
192 data->pipe == PIPE_A) {
193 igt_debug("DSC not supported on Pipe A on external DP\n");
194 return;
195 }
196
197 /* Disable the output first */
198 igt_output_set_pipe(data->output, PIPE_NONE);
199 igt_display_commit(&data->display);
200
201 if (test_type == test_basic_dsc_enable) {
202 bool enabled;
203
204 igt_debug("DSC is supported on %s\n", data->conn_name);
205 save_force_dsc_en(data);
206 force_dp_dsc_enable(data);
207
208 igt_output_set_pipe(data->output, data->pipe);
209 igt_create_pattern_fb(data->drm_fd, data->mode->hdisplay,
210 data->mode->vdisplay,
211 DRM_FORMAT_XRGB8888,
212 LOCAL_DRM_FORMAT_MOD_NONE,
213 &data->fb_test_pattern);
214 primary = igt_output_get_plane_type(data->output,
215 DRM_PLANE_TYPE_PRIMARY);
216
217 /* Now set the output to the desired mode */
218 igt_plane_set_fb(primary, &data->fb_test_pattern);
219 igt_display_commit(&data->display);
220
221 /*
222 * Until we have CRC check support, manually check if RGB test
223 * pattern has no corruption.
224 */
225 manual("RGB test pattern without corruption");
226
227 enabled = is_dp_dsc_enabled(data);
228 restore_force_dsc_en();
229
230 igt_assert_f(enabled,
231 "Default DSC enable failed on Connector: %s Pipe: %s\n",
232 data->conn_name,
233 kmstest_pipe_name(data->pipe));
234 } else {
235 igt_assert(!"Unknown test type\n");
236 }
237 }
238
run_test(data_t * data,igt_output_t * output,enum dsc_test_type test_type)239 static void run_test(data_t *data, igt_output_t *output,
240 enum dsc_test_type test_type)
241 {
242 enum pipe pipe;
243
244 for_each_pipe(&data->display, pipe) {
245
246 if (igt_pipe_connector_valid(pipe, output)) {
247 data->pipe = pipe;
248 data->output = output;
249 update_display(data, test_type);
250 test_cleanup(data);
251 }
252 }
253 }
254
255 igt_main
256 {
257 data_t data = {};
258 igt_output_t *output;
259 drmModeRes *res;
260 drmModeConnector *connector;
261 int i, test_conn_cnt, test_cnt;
262 int tests[] = {DRM_MODE_CONNECTOR_eDP, DRM_MODE_CONNECTOR_DisplayPort};
263
264 igt_fixture {
265 data.drm_fd = drm_open_driver_master(DRIVER_ANY);
266 data.debugfs_fd = igt_debugfs_dir(data.drm_fd);
267 kmstest_set_vt_graphics_mode();
268 igt_install_exit_handler(kms_dp_dsc_exit_handler);
269 igt_display_require(&data.display, data.drm_fd);
270 igt_require(res = drmModeGetResources(data.drm_fd));
271 }
272
273 for (test_cnt = 0; test_cnt < ARRAY_SIZE(tests); test_cnt++) {
274
275 igt_subtest_f("basic-dsc-enable-%s",
kmstest_connector_type_str(tests[test_cnt])276 kmstest_connector_type_str(tests[test_cnt])) {
277 test_conn_cnt = 0;
278 for (i = 0; i < res->count_connectors; i++) {
279 connector = drmModeGetConnectorCurrent(data.drm_fd,
280 res->connectors[i]);
281 if (connector->connection != DRM_MODE_CONNECTED ||
282 connector->connector_type !=
283 tests[test_cnt])
284 continue;
285 output = igt_output_from_connector(&data.display, connector);
286 sprintf(data.conn_name, "%s-%d",
287 kmstest_connector_type_str(connector->connector_type),
288 connector->connector_type_id);
289 if(!is_dp_dsc_supported(&data)) {
290 igt_debug("DSC not supported on connector %s \n",
291 data.conn_name);
292 continue;
293 }
294 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort &&
295 !is_dp_fec_supported(&data)) {
296 igt_debug("DSC cannot be enabled without FEC on %s\n",
297 data.conn_name);
298 continue;
299 }
300 test_conn_cnt++;
301 run_test(&data, output, test_basic_dsc_enable);
302 }
303 igt_skip_on(test_conn_cnt == 0);
304 }
305 }
306
307 igt_fixture {
308 drmModeFreeConnector(connector);
309 drmModeFreeResources(res);
310 close(data.debugfs_fd);
311 close(data.drm_fd);
312 igt_display_fini(&data.display);
313 }
314 }
315