[PATCH i-g-t 4/9] lib/igt_kms: refactor helpers forced_connectors helpers
Kunal Joshi
kunal1.joshi at intel.com
Wed Apr 10 06:44:21 UTC 2024
refactor connector_is_forced, forced_connector_free_index and
dump_forced_connectors to behave according to kmstest_force_type
Cc: Ville Syrjälä <ville.syrjala at linux.intel.com>
Cc: Ankit Nautiyal <ankit.k.nautiyal at intel.com>
Cc: Bhanuprakash Modem <bhanuprakash.modem at intel.com>
Cc: Karthik B S <karthik.b.s at intel.com>
Signed-off-by: Kunal Joshi <kunal1.joshi at intel.com>
---
lib/igt_kms.c | 46 +++++++++++++++++++++++++++++-----------------
1 file changed, 29 insertions(+), 17 deletions(-)
diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index cc934a514..dac822c7a 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -1495,28 +1495,37 @@ int igt_connector_sysfs_open(int drm_fd,
return conn_dir;
}
-static bool connector_is_forced(int idx, drmModeConnector *connector)
+static bool connector_is_forced(int idx, drmModeConnector *connector, enum kmstest_force_type type)
{
+ struct forced_connector *connectors;
+
+ igt_assert(type >= FORCED_CONNECTOR && type < FORCED_CONNECTOR_MAX);
igt_assert(connector->connector_type != 0);
- for (int i = 0; forced_connectors[i].connector_type; i++) {
- if (forced_connectors[i].idx == idx &&
- forced_connectors[i].connector_type == connector->connector_type &&
- forced_connectors[i].connector_type_id == connector->connector_type_id)
+ connectors = type == FORCED_CONNECTOR ? forced_connectors : forced_connectors_debugfs;
+ for (int i = 0; connectors[i].connector_type; i++) {
+ if (connectors[i].idx == idx &&
+ connectors[i].connector_type == connector->connector_type &&
+ connectors[i].connector_type_id == connector->connector_type_id)
return true;
}
return false;
}
-static int forced_connector_free_index(void)
+static int forced_connector_free_index(enum kmstest_force_type type)
{
int i;
+ struct forced_connector *connectors;
+
+ igt_assert(type >= FORCED_CONNECTOR && type < FORCED_CONNECTOR_MAX);
+ connectors = type == FORCED_CONNECTOR ? forced_connectors : forced_connectors_debugfs;
- for (i = 0; forced_connectors[i].connector_type; i++)
+ for (i = 0; connectors[i].connector_type; i++)
;
- return i < ARRAY_SIZE(forced_connectors) ? i : -1;
+ return i < (type == FORCED_CONNECTOR ? ARRAY_SIZE(forced_connectors) :
+ ARRAY_SIZE(forced_connectors_debugfs)) ? i : -1;
}
static bool force_connector(int drm_fd,
@@ -1546,12 +1555,12 @@ static bool force_connector(int drm_fd,
igt_debug("Connector %s is now forced %s\n", name, value);
/* already tracked? */
- if (connector_is_forced(idx, connector)) {
+ if (connector_is_forced(idx, connector, FORCED_CONNECTOR)) {
close(dir);
return true;
}
- i = forced_connector_free_index();
+ i = forced_connector_free_index(FORCED_CONNECTOR);
if (i < 0) {
igt_warn("Connector limit reached, %s will not be reset\n", name);
close(dir);
@@ -1566,16 +1575,19 @@ static bool force_connector(int drm_fd,
return true;
}
-static void dump_forced_connectors(void)
+static void dump_forced_connectors(enum kmstest_force_type type)
{
char name[80];
+ struct forced_connector *connectors;
+ igt_assert(type >= FORCED_CONNECTOR && type < FORCED_CONNECTOR_MAX);
+ connectors = type == FORCED_CONNECTOR ? forced_connectors : forced_connectors_debugfs;
igt_debug("Current forced connectors:\n");
- for (int i = 0; forced_connectors[i].connector_type; i++) {
- kmstest_connector_dirname(forced_connectors[i].idx,
- forced_connectors[i].connector_type,
- forced_connectors[i].connector_type_id,
+ for (int i = 0; connectors[i].connector_type; i++) {
+ kmstest_connector_dirname(connectors[i].idx,
+ connectors[i].connector_type,
+ connectors[i].connector_type_id,
name, sizeof(name));
igt_debug("\t%s\n", name);
}
@@ -1625,7 +1637,7 @@ bool kmstest_force_connector(int drm_fd, drmModeConnector *connector,
if (!force_connector(drm_fd, connector, value))
return false;
- dump_forced_connectors();
+ dump_forced_connectors(FORCED_CONNECTOR);
igt_install_exit_handler(reset_connectors_at_exit);
@@ -2618,7 +2630,7 @@ static void igt_handle_spurious_hpd(igt_display_t *display)
conn->connector_type_id);
}
- dump_forced_connectors();
+ dump_forced_connectors(FORCED_CONNECTOR);
}
/**
--
2.34.1
More information about the igt-dev
mailing list