1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
|
/*
* Copyright © 2016 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
*/
/**
* TEST: kms invalid mode
* Category: Display
* Description: Make sure all modesets are rejected when the requested mode is
* invalid
* Driver requirement: i915, xe
* Mega feature: General Display Features
*/
#include "igt.h"
#include "xe/xe_query.h"
#include <limits.h>
#include <stdbool.h>
/**
* SUBTEST: %s
* Description: Make sure all modesets are rejected when the requested mode
* (%arg[1]) is invalid
*
* arg[1]:
*
* @bad-hsync-end: Bad hsync_end
* @bad-hsync-start: Bad hsync_start
* @bad-htotal: Bad htotal
* @bad-vsync-end: Bad vsync_end
* @bad-vsync-start: Bad vsync_start
* @bad-vtotal: Bad vtotal
* @clock-too-high: High clock
* @int-max-clock: Clock as INT_MAX
* @uint-max-clock: Clock as UINT_MAX
* @zero-clock: Clock as zero
* @zero-hdisplay: hdisplay as zero
* @zero-vdisplay: vdisplay as zero
* @overflow-vrefresh: vrefresh calculation overflow
*/
IGT_TEST_DESCRIPTION("Make sure all modesets are rejected when the requested mode is invalid");
typedef struct _data data_t;
struct _data {
int drm_fd;
enum pipe pipe;
igt_display_t display;
igt_output_t *output;
drmModeResPtr res;
int max_dotclock;
bool (*adjust_mode)(data_t *data, drmModeModeInfoPtr mode);
};
static bool has_scaling_mode_prop(data_t *data)
{
return kmstest_get_property(data->drm_fd,
data->output->id,
DRM_MODE_OBJECT_CONNECTOR,
"scaling mode",
NULL, NULL, NULL);
}
static bool
can_bigjoiner(data_t *data)
{
uint32_t devid = intel_get_drm_devid(data->drm_fd);
/*
* GEN11 and GEN12 require DSC to support bigjoiner.
* XELPD and later GEN support uncompressed bigjoiner.
*/
if (intel_display_ver(devid) > 12) {
igt_debug("Platform supports uncompressed bigjoiner\n");
return true;
} else if (igt_is_dsc_supported_by_source(data->drm_fd)) {
return igt_is_dsc_supported_by_sink(data->drm_fd, data->output->name);
}
return false;
}
static bool
can_ultrajoiner(data_t *data)
{
bool ultra_joiner_supported = false;
bool is_dgfx;
int display_ver;
is_dgfx = is_xe_device(data->drm_fd) ? xe_has_vram(data->drm_fd) :
gem_has_lmem(data->drm_fd);
display_ver = intel_display_ver(intel_get_drm_devid(data->drm_fd));
if ((is_dgfx && display_ver == 14) || display_ver > 14)
ultra_joiner_supported = true;
if (ultra_joiner_supported) {
igt_debug("Platform supports ultrajoiner\n");
return true;
}
return false;
}
static bool
adjust_mode_clock_too_high(data_t *data, drmModeModeInfoPtr mode)
{
int max_dotclock = data->max_dotclock;
igt_require(max_dotclock != 0);
/*
* FIXME When we have a fixed mode, the kernel will ignore
* the user timings apart from hdisplay/vdisplay. Should
* fix the kernel to at least make sure the requested
* refresh rate as specified by the user timings will
* roughly match the user will get. For now skip the
* test on any connector with a fixed mode.
*/
if (has_scaling_mode_prop(data))
return false;
/*
* Newer platforms can support modes higher than the maximum dot clock
* by using pipe joiner, so set the mode clock twice that of maximum
* dot clock;
*/
if (can_bigjoiner(data)) {
igt_info("Platform supports bigjoiner with %s\n",
data->output->name);
max_dotclock *= 2;
}
if (can_ultrajoiner(data)) {
igt_info("Platform supports ultrajoiner with %s\n",
data->output->name);
max_dotclock *= 4;
}
mode->clock = max_dotclock + 1;
return true;
}
static bool
adjust_mode_zero_clock(data_t *data, drmModeModeInfoPtr mode)
{
mode->clock = 0;
return true;
}
static bool
adjust_mode_int_max_clock(data_t *data, drmModeModeInfoPtr mode)
{
mode->clock = INT_MAX;
return true;
}
static bool
adjust_mode_uint_max_clock(data_t *data, drmModeModeInfoPtr mode)
{
mode->clock = UINT_MAX;
return true;
}
static bool
adjust_mode_zero_hdisplay(data_t *data, drmModeModeInfoPtr mode)
{
mode->hdisplay = 0;
return true;
}
static bool
adjust_mode_zero_vdisplay(data_t *data, drmModeModeInfoPtr mode)
{
mode->vdisplay = 0;
return true;
}
static bool
adjust_mode_bad_hsync_start(data_t *data, drmModeModeInfoPtr mode)
{
mode->hsync_start = mode->hdisplay - 1;
return true;
}
static bool
adjust_mode_bad_vsync_start(data_t *data, drmModeModeInfoPtr mode)
{
mode->vsync_start = mode->vdisplay - 1;
return true;
}
static bool
adjust_mode_bad_hsync_end(data_t *data, drmModeModeInfoPtr mode)
{
mode->hsync_end = mode->hsync_start - 1;
return true;
}
static bool
adjust_mode_bad_vsync_end(data_t *data, drmModeModeInfoPtr mode)
{
mode->vsync_end = mode->vsync_start - 1;
return true;
}
static bool
adjust_mode_bad_htotal(data_t *data, drmModeModeInfoPtr mode)
{
mode->htotal = mode->hsync_end - 1;
return true;
}
static bool
adjust_mode_bad_vtotal(data_t *data, drmModeModeInfoPtr mode)
{
mode->vtotal = mode->vsync_end - 1;
return true;
}
static bool
adjust_mode_overflow_vrefresh(data_t *data, drmModeModeInfoPtr mode)
{
/*
* htotal * vtotal * vscan == 2^32
* overflow during vrefresh calculation
*/
mode->htotal = 32768;
mode->vtotal = 32768;
mode->vscan = 4;
return true;
}
static void
test_output(data_t *data)
{
igt_output_t *output = data->output;
drmModeModeInfo mode;
struct igt_fb fb;
int ret;
uint32_t crtc_id;
/*
* FIXME test every mode we have to be more
* sure everything is really getting rejected?
*/
mode = *igt_output_get_mode(output);
igt_require(data->adjust_mode(data, &mode));
igt_create_fb(data->drm_fd,
max_t(uint16_t, mode.hdisplay, 64),
max_t(uint16_t, mode.vdisplay, 64),
DRM_FORMAT_XRGB8888,
DRM_FORMAT_MOD_LINEAR,
&fb);
kmstest_unset_all_crtcs(data->drm_fd, data->res);
crtc_id = data->display.pipes[data->pipe].crtc_id;
ret = drmModeSetCrtc(data->drm_fd, crtc_id,
fb.fb_id, 0, 0,
&output->id, 1, &mode);
igt_assert_lt(ret, 0);
igt_remove_fb(data->drm_fd, &fb);
}
static const struct {
const char *name;
bool (*adjust_mode)(data_t *data, drmModeModeInfoPtr mode);
} subtests[] = {
{ .name = "clock-too-high",
.adjust_mode = adjust_mode_clock_too_high,
},
{ .name = "zero-clock",
.adjust_mode = adjust_mode_zero_clock,
},
{ .name = "int-max-clock",
.adjust_mode = adjust_mode_int_max_clock,
},
{ .name = "uint-max-clock",
.adjust_mode = adjust_mode_uint_max_clock,
},
{ .name = "zero-hdisplay",
.adjust_mode = adjust_mode_zero_hdisplay,
},
{ .name = "zero-vdisplay",
.adjust_mode = adjust_mode_zero_vdisplay,
},
{ .name = "bad-hsync-start",
.adjust_mode = adjust_mode_bad_hsync_start,
},
{ .name = "bad-vsync-start",
.adjust_mode = adjust_mode_bad_vsync_start,
},
{ .name = "bad-hsync-end",
.adjust_mode = adjust_mode_bad_hsync_end,
},
{ .name = "bad-vsync-end",
.adjust_mode = adjust_mode_bad_vsync_end,
},
{ .name = "bad-htotal",
.adjust_mode = adjust_mode_bad_htotal,
},
{ .name = "bad-vtotal",
.adjust_mode = adjust_mode_bad_vtotal,
},
{ .name = "overflow-vrefresh",
.adjust_mode = adjust_mode_overflow_vrefresh,
},
};
static data_t data;
igt_main
{
enum pipe pipe;
igt_output_t *output;
igt_fixture {
data.drm_fd = drm_open_driver_master(DRIVER_ANY);
kmstest_set_vt_graphics_mode();
igt_display_require(&data.display, data.drm_fd);
data.res = drmModeGetResources(data.drm_fd);
igt_assert(data.res);
data.max_dotclock = igt_get_max_dotclock(data.drm_fd);
igt_info("Max dotclock: %d kHz\n", data.max_dotclock);
}
igt_describe("Make sure all modesets are rejected when the requested mode is invalid");
for (int i = 0; i < ARRAY_SIZE(subtests); i++) {
igt_subtest_with_dynamic(subtests[i].name) {
for_each_pipe_with_valid_output(&data.display, pipe, output) {
igt_display_reset(&data.display);
igt_output_set_pipe(output, pipe);
if (!intel_pipe_output_combo_valid(&data.display))
continue;
igt_dynamic_f("pipe-%s-%s", kmstest_pipe_name(pipe), igt_output_name(output)) {
data.output = output;
data.pipe = pipe;
data.adjust_mode = subtests[i].adjust_mode;
test_output(&data);
}
}
}
}
igt_fixture {
igt_display_fini(&data.display);
igt_reset_connectors();
drmModeFreeResources(data.res);
drm_close_driver(data.drm_fd);
}
}
|