[PATCH i-g-t 1/4] tests/intel/kms_joiner_helper: add helper for joiner related functions
Kunal Joshi
kunal1.joshi at intel.com
Tue Dec 24 12:10:21 UTC 2024
add helper for joiner related functions
Signed-off-by: Kunal Joshi <kunal1.joshi at intel.com>
---
tests/intel/kms_joiner.c | 15 +--
tests/intel/kms_joiner_helper.c | 183 ++++++++++++++++++++++++++++++++
tests/intel/kms_joiner_helper.h | 31 ++++++
tests/meson.build | 1 +
4 files changed, 217 insertions(+), 13 deletions(-)
create mode 100644 tests/intel/kms_joiner_helper.c
create mode 100644 tests/intel/kms_joiner_helper.h
diff --git a/tests/intel/kms_joiner.c b/tests/intel/kms_joiner.c
index 418ff26a6..7e9466b6f 100644
--- a/tests/intel/kms_joiner.c
+++ b/tests/intel/kms_joiner.c
@@ -37,6 +37,7 @@
#include "igt.h"
#include "xe/xe_query.h"
#include "kms_dsc_helper.c"
+#include "intel/kms_joiner_helper.h"
/**
* SUBTEST: invalid-modeset-big-joiner
@@ -97,18 +98,6 @@ typedef struct {
static int max_dotclock;
-static void set_all_master_pipes_for_platform(data_t *data)
-{
- enum pipe pipe;
-
- for (pipe = PIPE_A; pipe < IGT_MAX_PIPES - 1; pipe++) {
- if (data->display.pipes[pipe].enabled && data->display.pipes[pipe + 1].enabled) {
- data->master_pipes |= BIT(pipe);
- igt_info("Found master pipe %s\n", kmstest_pipe_name(pipe));
- }
- }
-}
-
static void enable_force_joiner_on_all_non_big_joiner_outputs(data_t *data)
{
bool status;
@@ -430,7 +419,7 @@ igt_main
data.drm_fd = drm_open_driver_master(DRIVER_INTEL | DRIVER_XE);
kmstest_set_vt_graphics_mode();
igt_display_require(&data.display, data.drm_fd);
- set_all_master_pipes_for_platform(&data);
+ igt_set_all_master_pipes_for_platform(&data.display, &data.master_pipes);
igt_require(data.display.is_atomic);
max_dotclock = igt_get_max_dotclock(data.drm_fd);
diff --git a/tests/intel/kms_joiner_helper.c b/tests/intel/kms_joiner_helper.c
new file mode 100644
index 000000000..a733fafba
--- /dev/null
+++ b/tests/intel/kms_joiner_helper.c
@@ -0,0 +2,185 @@
+#include "kms_joiner_helper.h"
+#include "igt.h" /* for igt_debug(), igt_info() logs, etc. */
+#include "igt_kms.h" /* for igt_output_t, kmstest_pipe_name(), etc. */
+#include "intel_chipset.h" /* if you need is_intel_device() or similar */
+
+/*
+ * Detect if the output needs 1, 2, or 4 pipes (non-joiner, big joiner, ultra).
+ * This re-uses your existing logic from:
+ * bigjoiner_mode_found(), ultrajoiner_mode_found(),
+ * is_intel_device(), igt_get_max_dotclock(), etc.
+ */
+static int get_required_pipes(int drm_fd, igt_output_t *output)
+{
+ drmModeModeInfo mode;
+ int max_dotclock;
+ bool is_big = false, is_ultra = false;
+
+ if (!is_intel_device(drm_fd))
+ return 1;
+
+ max_dotclock = igt_get_max_dotclock(drm_fd);
+
+ /* This is your existing function to detect bigjoiner. */
+ is_big = bigjoiner_mode_found(drm_fd,
+ output->config.connector,
+ max_dotclock,
+ &mode);
+
+ /* This is your existing function to detect ultrajoiner. */
+ is_ultra = ultrajoiner_mode_found(drm_fd,
+ output->config.connector,
+ max_dotclock,
+ &mode);
+
+ if (is_ultra)
+ return 4;
+ if (is_big)
+ return 2;
+
+ return 1; /* default non-joiner */
+}
+
+/*
+ * Internal helper to find a block of `count` consecutive free pipes
+ * in `available_pipes_mask`. If `count > 1`, the first pipe must also
+ * be in `master_pipes_mask`. Returns the starting pipe index or -1 if not found.
+ */
+static int find_consecutive_pipes(int n_pipes,
+ uint32_t available_pipes_mask,
+ uint32_t master_pipes_mask,
+ int count)
+{
+ bool can_use;
+
+ for (int start = 0; start < n_pipes; start++) {
+ if (start + count - 1 >= n_pipes)
+ break;
+
+ /* If we need more than 1 pipe, 'start' must be a master pipe. */
+ if (count > 1) {
+ if (!(BIT(start) & master_pipes_mask))
+ continue;
+ }
+
+ can_use = true;
+ for (int i = 0; i < count; i++) {
+ int pipe_idx = start + i;
+
+ if (!(BIT(pipe_idx) & available_pipes_mask)) {
+ can_use = false;
+ break;
+ }
+ }
+ if (can_use)
+ return start;
+ }
+ return -1;
+}
+
+/*
+ * get_next_master_pipe() might already exist in your code, or you can inline
+ * your logic here. For example, returning the first set bit from the mask.
+ */
+static enum pipe get_next_master_pipe(uint32_t pipe_mask)
+{
+ int i;
+
+ if (!pipe_mask)
+ return PIPE_NONE;
+
+ i = ffs(pipe_mask) - 1; /* ffs() returns 1-based bit index. */
+ if (i < 0)
+ return PIPE_NONE;
+
+ return (enum pipe)i;
+}
+
+/*
+ * @drm_fd: DRM file descriptor
+ * @outputs: array of pointers to igt_output_t
+ * @num_outputs: how many outputs in the array
+ * @n_pipes: total number of pipes available
+ * @used_pipes_mask: pointer to a bitmask (in/out) of already-used pipes
+ * @master_pipes_mask: bitmask of valid "master" pipes
+ * @valid_pipes_mask: bitmask of valid (non-fused) pipes
+ *
+ * Assign pipes to outputs based on the number of required pipes.
+ * This function will assign 1, 2, or 4 consecutive pipes to each output.
+ * It will also mark the used pipes in the bitmask.
+ *
+ * Returns: true if all outputs can be assigned successfully; false otherwise.
+ */
+bool igt_assign_pipes_for_outputs(int drm_fd,
+ igt_output_t **outputs,
+ int num_outputs,
+ int n_pipes,
+ uint32_t *used_pipes_mask,
+ uint32_t master_pipes_mask,
+ uint32_t valid_pipes_mask)
+{
+ for (int idx = 0; idx < num_outputs; idx++) {
+ igt_output_t *out = outputs[idx];
+
+ /* 1, 2, or 4 pipes needed? */
+ int needed = get_required_pipes(drm_fd, out);
+
+ /* Which pipes are free + valid? */
+ uint32_t available_pipes_mask = (~(*used_pipes_mask)) & valid_pipes_mask;
+
+ /* Find consecutive block. */
+ int start = find_consecutive_pipes(n_pipes, available_pipes_mask,
+ master_pipes_mask,
+ needed);
+ if (start < 0) {
+ igt_debug("Cannot allocate %d consecutive pipes for output %s\n",
+ needed, out->name);
+ return false;
+ }
+
+ igt_info("Assigning %d pipes [start=%s..%s] to output %s\n",
+ needed, kmstest_pipe_name(start), kmstest_pipe_name(start + needed - 1), out->name);
+
+ /* If multi-pipe, confirm 'start' is indeed a valid master. */
+ if (needed > 1) {
+ enum pipe mp = get_next_master_pipe(BIT(start));
+
+ if (mp == PIPE_NONE) {
+ igt_debug("Failed to confirm master pipe for %s\n", out->name);
+ return false;
+ }
+ igt_output_set_pipe(out, (enum pipe)start);
+ igt_debug("Using pipe %s as master.\n", kmstest_pipe_name(start));
+ } else {
+ igt_output_set_pipe(out, (enum pipe)start);
+ }
+
+ /* Mark these pipes as used. */
+ for (int i = 0; i < needed; i++)
+ *used_pipes_mask |= BIT(start + i);
+ }
+
+ return true;
+}
+
+/**
+ * igt_set_all_master_pipes_for_platform:
+ * @master_pipes: Pointer to the variable to store the master pipes bitmask.
+ * @display: The display structure containing pipe information.
+ *
+ * This function sets the master pipes for the platform by checking if consecutive
+ * pipes are enabled. If both pipe and the next pipe are enabled, the pipe is
+ * considered a master pipe.
+ */
+void igt_set_all_master_pipes_for_platform(igt_display_t *display, uint32_t *master_pipes)
+{
+ enum pipe pipe;
+
+ *master_pipes = 0;
+ for (pipe = PIPE_A; pipe < IGT_MAX_PIPES - 1; pipe++) {
+ if (display->pipes[pipe].enabled && display->pipes[pipe + 1].enabled) {
+ *master_pipes |= BIT(pipe);
+ igt_info("Found master pipe %s\n", kmstest_pipe_name(pipe));
+ }
+ }
+}
diff --git a/tests/intel/kms_joiner_helper.h b/tests/intel/kms_joiner_helper.h
new file mode 100644
index 000000000..632fda0ae
--- /dev/null
+++ b/tests/intel/kms_joiner_helper.h
@@ -0,0 +1,31 @@
+#ifndef KMS_JOINER_HELPER_H
+#define KMS_JOINER_HELPER_H
+
+#include "igt_kms.h"
+
+/*
+ * igt_assign_pipes_for_outputs:
+ * @drm_fd: DRM file descriptor
+ * @outputs: array of pointers to igt_output_t
+ * @num_outputs: how many outputs in the array
+ * @used_pipes_mask: pointer to a bitmask (in/out) of already-used pipes
+ * @master_pipes_mask: bitmask of valid "master" pipes
+ * @valid_pipes_mask: bitmask of valid (non-fused) pipes
+ *
+ * This helper tries to assign each output to consecutive pipes, depending on
+ * whether the output needs Big Joiner (2 pipes), Ultra Joiner (4 pipes), or
+ * no joiner (1 pipe). It uses existing logic to detect big/ultra joiner modes.
+ *
+ * Returns: true if all outputs can be assigned successfully; false otherwise.
+ */
+bool igt_assign_pipes_for_outputs(int drm_fd,
+ igt_output_t **outputs,
+ int num_outputs,
+ int n_pipes,
+ uint32_t *used_pipes_mask,
+ uint32_t master_pipes_mask,
+ uint32_t valid_pipes_mask);
+void igt_set_all_master_pipes_for_platform(igt_display_t *display,
+ uint32_t *master_pipes);
+
+#endif
diff --git a/tests/meson.build b/tests/meson.build
index 89bba6454..8dd5e34a1 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -367,6 +367,7 @@ extra_sources = {
'kms_chamelium_hpd': [ join_paths ('chamelium', 'kms_chamelium_helper.c') ],
'kms_dsc': [ join_paths ('intel', 'kms_dsc_helper.c') ],
'kms_psr2_sf': [ join_paths ('intel', 'kms_dsc_helper.c') ],
+ 'kms_joiner': [join_paths ('intel', 'kms_joiner_helper.c')],
}
# Extra dependencies used on core and Intel drivers
--
2.34.1
More information about the Intel-gfx-trybot
mailing list