Return-Path: Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by gabe.freedesktop.org (Postfix) with ESMTPS id 77C836E5CF for ; Mon, 26 Apr 2021 10:31:19 +0000 (UTC) From: Bhanuprakash Modem Date: Mon, 26 Apr 2021 23:51:23 +0530 Message-Id: <20210426182136.2815-2-bhanuprakash.modem@intel.com> In-Reply-To: <20210426182136.2815-1-bhanuprakash.modem@intel.com> References: <20210426182136.2815-1-bhanuprakash.modem@intel.com> MIME-Version: 1.0 Subject: [igt-dev] [v3 i-g-t 01/14] lib/igt_kms: helper to override the mode on all connectors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" To: igt-dev@lists.freedesktop.org Cc: Petri Latvala List-ID: 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 Cc: Imre Deak Cc: Ankit Nautiyal Cc: Petri Latvala Cc: Daniel Vetter Signed-off-by: Bhanuprakash Modem --- lib/igt_kms.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ lib/igt_kms.h | 1 + 2 files changed, 56 insertions(+) diff --git a/lib/igt_kms.c b/lib/igt_kms.c index 08d429a81..7aea8098c 100644 --- a/lib/igt_kms.c +++ b/lib/igt_kms.c @@ -3841,6 +3841,61 @@ 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_link_bw(igt_display_t *display, int base) +{ + for ( ; base < display->n_outputs; base++) { + igt_output_t *output = &display->outputs[base]; + + 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); + + for_each_connector_mode(output) { + igt_output_override_mode(output, &output->config.connector->modes[i__]); + + if (__override_all_active_output_modes_to_fit_link_bw(display, base + 1)) + return true; + + if (igt_display_try_commit_atomic(display, + DRM_MODE_ATOMIC_TEST_ONLY | + DRM_MODE_ATOMIC_ALLOW_MODESET, + NULL) == 0) + return true; + } + } + + return false; +} + +/** + * override_all_active_output_modes_to_fit_link_bw: + * @display: a pointer to an #igt_display_t structure + * + * Override the mode on all connectors those are sharing the link bw + * + * Returns: true if a valid connector mode combo found, else false + */ +bool override_all_active_output_modes_to_fit_link_bw(igt_display_t *display) +{ + return __override_all_active_output_modes_to_fit_link_bw(display, 0); +} + /* * igt_pipe_refresh: * @display: a pointer to an #igt_display_t structure diff --git a/lib/igt_kms.h b/lib/igt_kms.h index 09b10b3e0..518dfffba 100644 --- a/lib/igt_kms.h +++ b/lib/igt_kms.h @@ -892,5 +892,6 @@ void igt_require_pipe(igt_display_t *display, void igt_dump_connectors_fd(int drmfd); void igt_dump_crtcs_fd(int drmfd); +bool override_all_active_output_modes_to_fit_link_bw(igt_display_t *display); #endif /* __IGT_KMS_H__ */ -- 2.20.1 _______________________________________________ igt-dev mailing list igt-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/igt-dev