[PATCH i-g-t 7/9] lib/igt_kms: add kmstest_force_connector_debugfs

Kunal Joshi kunal1.joshi at intel.com
Wed Apr 10 06:44:24 UTC 2024


allow to set debugfs for a connector with particular value and install
exit handler for cleanup.

This is same kmstest_force_connector just that one uses sysfs and
limited to only status sysfs.

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 | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_kms.h |  2 ++
 2 files changed, 82 insertions(+)

diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 80070d935..56c9dae9b 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -1600,6 +1600,52 @@ static bool force_connector(int drm_fd,
 	return true;
 }
 
+static bool force_connector_debugfs(int drm_fd,
+				    drmModeConnector *connector,
+				    const char *attr, const char *value)
+{
+	char name[80];
+	int i, idx, dir;
+
+	if (!connector)
+		return false;
+
+	snprintf(name, sizeof(name), "%s-%d",
+		 kmstest_connector_type_str(connector->connector_type),
+		 connector->connector_type_id);
+
+	dir = igt_debugfs_connector_dir(drm_fd, name, O_DIRECTORY);
+	if (dir < 0)
+		return false;
+
+	if (!igt_sysfs_set(dir, attr, value)) {
+		close(dir);
+		return false;
+	}
+
+	igt_debug("Debugfs %s of Connector %s is now forced %s\n", attr, name, value);
+
+	/* already tracked? */
+	if (connector_is_forced(idx, connector, FORCED_CONNECTOR_DEBUGFS)) {
+		close(dir);
+		return true;
+	}
+
+	i = forced_connector_free_index(FORCED_CONNECTOR_DEBUGFS);
+	if (i < 0) {
+		igt_warn("Connector limit reached, %s will not be reset\n", name);
+		close(dir);
+		return true;
+	}
+
+	forced_connectors_debugfs[i].idx = idx;
+	forced_connectors_debugfs[i].connector_type = connector->connector_type;
+	forced_connectors_debugfs[i].connector_type_id = connector->connector_type_id;
+	forced_connectors_debugfs[i].dir = dir;
+
+	return true;
+}
+
 static void dump_forced_connectors(enum kmstest_force_type type)
 {
 	char name[80];
@@ -1674,6 +1720,40 @@ bool kmstest_force_connector(int drm_fd, drmModeConnector *connector,
 	return true;
 }
 
+/**
+ * kmstest_force_connector_debugfs:
+ * @fd: drm file descriptor
+ * @connector: connector
+ * @attr: debugfs of the connector
+ * @value: value to set
+ *
+ * Force the specified state on the specified connector.
+ *
+ * Returns: True on success
+ */
+bool kmstest_force_connector_debugfs(int drm_fd, drmModeConnector *connector,
+				     enum kmstest_force_debugfs debugfs, const char *value)
+{
+	drmModeConnector *temp;
+	const char *attr = get_debugfs_default_attr(debugfs);
+
+	if (!force_connector_debugfs(drm_fd, connector, attr, value))
+		return false;
+
+	dump_forced_connectors(FORCED_CONNECTOR_DEBUGFS);
+
+	igt_install_exit_handler(reset_connectors_debugfs_at_exit);
+
+	/*
+	 * To allow callers to always use GetConnectorCurrent we need to force a
+	 * redetection here.
+	 */
+	temp = drmModeGetConnector(drm_fd, connector->connector_id);
+	drmModeFreeConnector(temp);
+
+	return true;
+}
+
 /**
  * kmstest_force_edid:
  * @drm_fd: drm file descriptor
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index f676de737..4980d4791 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -283,6 +283,8 @@ struct edid;
 
 bool kmstest_force_connector(int fd, drmModeConnector *connector,
 			     enum kmstest_force_connector_state state);
+bool kmstest_force_connector_debugfs(int drm_fd, drmModeConnector *connector,
+				     enum kmstest_force_debugfs debugfs, const char *value);
 void kmstest_force_edid(int drm_fd, drmModeConnector *connector,
 			const struct edid *edid);
 
-- 
2.34.1



More information about the igt-dev mailing list