diff options
author | Bhanuprakash Modem <bhanuprakash.modem@intel.com> | 2021-05-12 22:35:23 +0530 |
---|---|---|
committer | Petri Latvala <petri.latvala@intel.com> | 2021-05-18 10:03:49 +0300 |
commit | eb88aa2908618475573c3fe86378e59cd364181e (patch) | |
tree | 2e2116ed1cb4dfc769af65e876ca2946ffd8161f /lib/igt_kms.c | |
parent | 15e11fc2ace7182ce0c39ad7ac5e9f608c4861cd (diff) |
lib/igt_kms: helper to override the mode on all connectors
This helper will iterate through all connectors those have a
pending_pipe != PIPE_NONE set by the test upto the point of
calling this helper. And find the combination by using
ATOMIC_TEST_ONLY then return to the test.
This helper would override the mode on all connectors that will
be modeset by the next igt_display_commit() call in the test.
V2:
* Remove MST specific logic (Daniel)
V3:
* Sort connector modes in descending order
V4:
* Fine tune the logic to reduce #of iterations (Ankit)
* Update the documentation (Ankit)
V5:
* Fix function name to make it generic (Ankit)
* Add support for legacy commit (Ankit)
Cc: Imre Deak <imre.deak@intel.com>
Cc: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
Cc: Petri Latvala <petri.latvala@intel.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Bhanuprakash Modem <bhanuprakash.modem@intel.com>
Reviewed-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
Diffstat (limited to 'lib/igt_kms.c')
-rw-r--r-- | lib/igt_kms.c | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/lib/igt_kms.c b/lib/igt_kms.c index 47b829b0..28fb9c09 100644 --- a/lib/igt_kms.c +++ b/lib/igt_kms.c @@ -4048,6 +4048,85 @@ void igt_output_set_pipe(igt_output_t *output, enum pipe pipe) } } +#define for_each_connector_mode(output) \ + for (int i__ = 0; i__ < output->config.connector->count_modes; i__++) + +static int sort_drm_modes(const void *a, const void *b) +{ + const drmModeModeInfo *mode1 = a, *mode2 = b; + + return (mode1->clock < mode2->clock) - (mode2->clock < mode1->clock); +} + +static +bool __override_all_active_output_modes_to_fit_bw(igt_display_t *display, + igt_output_t *outputs[IGT_MAX_PIPES], + const int n_outputs, + int base) +{ + igt_output_t *output = NULL; + + if (base >= n_outputs) + return false; + + output = outputs[base]; + + for_each_connector_mode(output) { + int ret; + + igt_output_override_mode(output, &output->config.connector->modes[i__]); + + if (__override_all_active_output_modes_to_fit_bw(display, outputs, n_outputs, base + 1)) + return true; + + if (display->is_atomic) + ret = igt_display_try_commit_atomic(display, + DRM_MODE_ATOMIC_TEST_ONLY | + DRM_MODE_ATOMIC_ALLOW_MODESET, + NULL); + else + ret = igt_display_try_commit2(display, COMMIT_LEGACY); + + if (!ret) + return true; + } + + return false; +} + +/** + * igt_override_all_active_output_modes_to_fit_bw: + * @display: a pointer to an #igt_display_t structure + * + * Override the mode on all active outputs (i.e. pending_pipe != PIPE_NONE) + * on basis of bandwidth. + * + * Returns: true if a valid connector mode combo found, else false + */ +bool igt_override_all_active_output_modes_to_fit_bw(igt_display_t *display) +{ + int i, n_outputs = 0; + igt_output_t *outputs[IGT_MAX_PIPES]; + + for (i = 0 ; i < display->n_outputs; i++) { + igt_output_t *output = &display->outputs[i]; + + if (output->pending_pipe == PIPE_NONE) + continue; + + /* Sort the modes in descending order by clock freq. */ + qsort(output->config.connector->modes, + output->config.connector->count_modes, + sizeof(drmModeModeInfo), + sort_drm_modes); + + outputs[n_outputs++] = output; + } + igt_require_f(n_outputs, "No active outputs found.\n"); + + return __override_all_active_output_modes_to_fit_bw(display, outputs, n_outputs, 0); +} + /* * igt_pipe_refresh: * @display: a pointer to an #igt_display_t structure |