Ville Syrjälä | efa4041 | 2016-05-24 20:44:11 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2016 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 | |
| 25 | #include "igt.h" |
| 26 | #include <stdbool.h> |
| 27 | |
| 28 | IGT_TEST_DESCRIPTION("Make sure all modesets are rejected when the requested dotclock is too high"); |
| 29 | |
| 30 | typedef struct { |
| 31 | int drm_fd; |
| 32 | igt_display_t display; |
| 33 | igt_output_t *output; |
| 34 | drmModeResPtr res; |
| 35 | int max_dotclock; |
| 36 | } data_t; |
| 37 | |
| 38 | static bool has_scaling_mode_prop(data_t *data) |
| 39 | { |
| 40 | return kmstest_get_property(data->drm_fd, |
| 41 | data->output->id, |
| 42 | DRM_MODE_OBJECT_CONNECTOR, |
| 43 | "scaling mode", |
| 44 | NULL, NULL, NULL); |
| 45 | } |
| 46 | |
| 47 | static int |
| 48 | test_output(data_t *data) |
| 49 | { |
| 50 | igt_output_t *output = data->output; |
| 51 | drmModeModeInfo mode; |
| 52 | struct igt_fb fb; |
| 53 | int i; |
| 54 | |
| 55 | /* |
| 56 | * FIXME When we have a fixed mode, the kernel will ignore |
| 57 | * the user timings apart from hdisplay/vdisplay. Should |
| 58 | * fix the kernel to at least make sure the requested |
| 59 | * refresh rate as specified by the user timings will |
| 60 | * roughly match the user will get. For now skip the |
| 61 | * test on any connector with a fixed mode. |
| 62 | */ |
| 63 | if (has_scaling_mode_prop(data)) |
| 64 | return 0; |
| 65 | |
| 66 | /* |
| 67 | * FIXME test every mode we have to be more |
| 68 | * sure everything is really getting rejected? |
| 69 | */ |
| 70 | mode = *igt_output_get_mode(output); |
| 71 | mode.clock = data->max_dotclock + 1; |
| 72 | |
| 73 | igt_create_fb(data->drm_fd, |
| 74 | mode.hdisplay, mode.vdisplay, |
| 75 | DRM_FORMAT_XRGB8888, |
| 76 | LOCAL_DRM_FORMAT_MOD_NONE, |
| 77 | &fb); |
| 78 | |
| 79 | for (i = 0; i < data->res->count_crtcs; i++) { |
| 80 | int ret; |
| 81 | |
| 82 | igt_info("Checking pipe %c connector %s with mode %s\n", |
| 83 | 'A'+i, output->name, mode.name); |
| 84 | |
| 85 | ret = drmModeSetCrtc(data->drm_fd, data->res->crtcs[i], |
| 86 | fb.fb_id, 0, 0, |
| 87 | &output->id, 1, &mode); |
| 88 | igt_assert_lt(ret, 0); |
| 89 | } |
| 90 | |
| 91 | igt_remove_fb(data->drm_fd, &fb); |
| 92 | |
| 93 | return 1; |
| 94 | } |
| 95 | |
| 96 | static void test(data_t *data) |
| 97 | { |
| 98 | int valid_connectors = 0; |
| 99 | |
| 100 | for_each_connected_output(&data->display, data->output) { |
| 101 | valid_connectors += test_output(data); |
| 102 | } |
| 103 | |
| 104 | igt_require_f(valid_connectors, "No suitable connectors found\n"); |
| 105 | } |
| 106 | |
Chris Wilson | 83884e9 | 2017-03-21 17:16:03 +0000 | [diff] [blame] | 107 | static int i915_max_dotclock(data_t *data) |
Ville Syrjälä | efa4041 | 2016-05-24 20:44:11 +0300 | [diff] [blame] | 108 | { |
| 109 | char buf[4096]; |
| 110 | char *s; |
| 111 | int max_dotclock = 0; |
| 112 | |
Chris Wilson | 83884e9 | 2017-03-21 17:16:03 +0000 | [diff] [blame] | 113 | igt_debugfs_read(data->drm_fd, "i915_frequency_info", buf); |
Ville Syrjälä | efa4041 | 2016-05-24 20:44:11 +0300 | [diff] [blame] | 114 | s = strstr(buf, "Max pixel clock frequency:"); |
| 115 | igt_assert(s); |
| 116 | igt_assert_eq(sscanf(s, "Max pixel clock frequency: %d kHz", &max_dotclock), 1); |
| 117 | |
| 118 | /* 100 Mhz to 5 GHz seem like reasonable values to expect */ |
| 119 | igt_assert_lt(max_dotclock, 5000000); |
| 120 | igt_assert_lt(100000, max_dotclock); |
| 121 | |
| 122 | return max_dotclock; |
| 123 | } |
| 124 | |
| 125 | static data_t data; |
| 126 | |
| 127 | igt_simple_main |
| 128 | { |
| 129 | igt_skip_on_simulation(); |
| 130 | |
| 131 | data.drm_fd = drm_open_driver_master(DRIVER_INTEL); |
| 132 | igt_require_intel(data.drm_fd); |
| 133 | |
Ville Syrjälä | efa4041 | 2016-05-24 20:44:11 +0300 | [diff] [blame] | 134 | kmstest_set_vt_graphics_mode(); |
Chris Wilson | 519003c | 2018-10-03 20:43:49 +0100 | [diff] [blame] | 135 | |
Chris Wilson | 7f41adf | 2018-09-14 21:10:05 +0100 | [diff] [blame] | 136 | igt_display_require(&data.display, data.drm_fd); |
Ville Syrjälä | efa4041 | 2016-05-24 20:44:11 +0300 | [diff] [blame] | 137 | data.res = drmModeGetResources(data.drm_fd); |
Chris Wilson | 519003c | 2018-10-03 20:43:49 +0100 | [diff] [blame] | 138 | igt_assert(data.res); |
| 139 | |
Ville Syrjälä | efa4041 | 2016-05-24 20:44:11 +0300 | [diff] [blame] | 140 | kmstest_unset_all_crtcs(data.drm_fd, data.res); |
| 141 | |
Chris Wilson | 83884e9 | 2017-03-21 17:16:03 +0000 | [diff] [blame] | 142 | data.max_dotclock = i915_max_dotclock(&data); |
Ville Syrjälä | efa4041 | 2016-05-24 20:44:11 +0300 | [diff] [blame] | 143 | igt_info("Max dotclock: %d kHz\n", data.max_dotclock); |
| 144 | |
| 145 | test(&data); |
| 146 | |
| 147 | igt_display_fini(&data.display); |
| 148 | igt_reset_connectors(); |
| 149 | drmModeFreeResources(data.res); |
| 150 | } |