[PATCH i-g-t v7 10/48] lib/igt_debugfs: Move debugfs helpers to the proper location

Louis Chauvet
2026-02-23T12:09:05Z

igt_debugfs_read_connector_file and igt_debugfs_write_connector_file are
debugfs related helpers. To avoid mixing everything in igt_kms, move them
to igt_debugfs.

Reviewed-by: Kory Maincent <kory.maincent@bootlin.com>
Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
lib/igt_debugfs.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
lib/igt_debugfs.h | 13 ++++++++
lib/igt_kms.c | 93 ------------------------------------------------------
3 files changed, 107 insertions(+), 93 deletions(-)

diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index 11f5ee9984ee..6072d7d68025 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -43,6 +43,7 @@
#include "igt_aux.h"
#include "igt_kms.h"
#include "igt_debugfs.h"
+#include "igt_device.h"
#include "igt_sysfs.h"

/**
@@ -776,3 +777,96 @@ void __igt_debugfs_dump(int device, const char *filename, int level)
igt_log(IGT_LOG_DOMAIN, level, "%s:\n%s\n", filename, contents);
free(contents);
}
+
+/**
+ * igt_debugfs_read_connector_file:
+ * @drm_fd: A drm file descriptor
+ * @conn_name: Name of the output connector
+ * @filename: The file to read from in the connector's directory
+ * @buf: Buffer to store the read content
+ * @buf_size: Size of the buffer
+ *
+ * Reads from a specific file in the connector's debugfs directory.
+ *
+ * Returns: 0 on success, -1 on failure.
+ */
+int igt_debugfs_read_connector_file(int drm_fd, char *conn_name,
+ const char *filename, char *buf,
+ size_t buf_size)
+{
+ int dir, res;
+
+ dir = igt_debugfs_connector_dir(drm_fd, conn_name, O_RDONLY);
+ igt_assert_f(dir >= 0, "Failed to open debugfs dir for connector %s\n", conn_name);
+
+ res = igt_debugfs_simple_read(dir, filename, buf, buf_size);
+ close(dir);
+
+ if (res < 0)
+ return -1;
+
+ return 0;
+}
+
+/**
+ * igt_debugfs_write_connector_file:
+ * @drm_fd: A drm file descriptor
+ * @conn_name: Name of the output connector
+ * @filename: The file to write to in the connector's directory
+ * @data: Data to write to the file
+ * @data_size: Size of the data to write
+ *
+ * Writes to a specific file in the connector's debugfs directory.
+ *
+ * Returns: 0 on success, -1 on failure.
+ */
+int igt_debugfs_write_connector_file(int drm_fd, char *conn_name,
+ const char *filename, const char *data,
+ size_t data_size)
+{
+ int dir, res;
+
+ dir = igt_debugfs_connector_dir(drm_fd, conn_name, O_RDONLY);
+ igt_assert_f(dir >= 0, "Failed to open debugfs dir for connector %s\n",
+ conn_name);
+
+ res = igt_sysfs_write(dir, filename, data, data_size);
+ close(dir);
+
+ if (res < 0)
+ return -1;
+
+ return 0;
+}
+
+bool connector_attr_set_debugfs(int drm_fd,
+ drmModeConnector *connector,
+ const char *attr, const char *value,
+ const char *reset_value,
+ bool force_reset)
+{
+ char name[80];
+ int idx, dir;
+
+ idx = igt_device_get_card_index(drm_fd);
+ if (idx < 0 || idx > 63)
+ 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 (!connector_attr_set(idx, connector, dir,
+ igt_sysfs_set, attr,
+ value, reset_value,
+ force_reset))
+ return false;
+
+ igt_info("Connector %s/%s is now %s\n", name, attr, value);
+
+ return true;
+}
diff --git a/lib/igt_debugfs.h b/lib/igt_debugfs.h
index 2c546f299a43..49fbadd2a74c 100644
--- a/lib/igt_debugfs.h
+++ b/lib/igt_debugfs.h
@@ -28,6 +28,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
+#include <xf86drmMode.h>

const char *igt_debugfs_mount(void);
char *igt_debugfs_path(int device, char *path, int pathlen);
@@ -176,4 +177,16 @@ int igt_get_stable_obj_count(int driver);
void __igt_debugfs_dump(int device, const char *filename, int level);
#define igt_debugfs_dump(d, f) __igt_debugfs_dump(d, f, IGT_LOG_DEBUG)

+int igt_debugfs_read_connector_file(int drm_fd, char *conn_name,
+ const char *filename, char *buf,
+ size_t buf_size);
+int igt_debugfs_write_connector_file(int drm_fd, char *conn_name,
+ const char *filename, const char *data,
+ size_t data_size);
+bool connector_attr_set_debugfs(int drm_fd,
+ drmModeConnector *connector,
+ const char *attr, const char *value,
+ const char *reset_value,
+ bool force_reset);
+
#endif /* __IGT_DEBUGFS_H__ */
diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 043d7dd547c2..ae85d06a9b51 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -1755,38 +1755,6 @@ static bool connector_attr_set_sysfs(int drm_fd,
return true;
}

-static bool connector_attr_set_debugfs(int drm_fd,
- drmModeConnector *connector,
- const char *attr, const char *value,
- const char *reset_value,
- bool force_reset)
-{
- char name[80];
- int idx, dir;
-
- idx = igt_device_get_card_index(drm_fd);
- if (idx < 0 || idx > 63)
- 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 (!connector_attr_set(idx, connector, dir,
- igt_sysfs_set, attr,
- value, reset_value,
- force_reset))
- return false;
-
- igt_info("Connector %s/%s is now %s\n", name, attr, value);
-
- return true;
-}
-
/**
* dump_connector_attrs: Display on debug log all the connector attributes
*/
@@ -7466,67 +7434,6 @@ static int igt_parse_marked_value(const char *buf, char marked_char, int *result
return -1;
}

-/**
- * igt_debugfs_read_connector_file:
- * @drm_fd: A drm file descriptor
- * @conn_name: Name of the output connector
- * @filename: The file to read from in the connector's directory
- * @buf: Buffer to store the read content
- * @buf_size: Size of the buffer
- *
- * Reads from a specific file in the connector's debugfs directory.
- *
- * Returns: 0 on success, -1 on failure.
- */
-static int igt_debugfs_read_connector_file(int drm_fd, char *conn_name,
- const char *filename, char *buf,
- size_t buf_size)
-{
- int dir, res;
-
- dir = igt_debugfs_connector_dir(drm_fd, conn_name, O_RDONLY);
- igt_assert_f(dir >= 0, "Failed to open debugfs dir for connector %s\n", conn_name);
-
- res = igt_debugfs_simple_read(dir, filename, buf, buf_size);
- close(dir);
-
- if (res < 0)
- return -1;
-
- return 0;
-}
-
-/**
- * igt_debugfs_write_connector_file:
- * @drm_fd: A drm file descriptor
- * @conn_name: Name of the output connector
- * @filename: The file to write to in the connector's directory
- * @data: Data to write to the file
- * @data_size: Size of the data to write
- *
- * Writes to a specific file in the connector's debugfs directory.
- *
- * Returns: 0 on success, -1 on failure.
- */
-static int igt_debugfs_write_connector_file(int drm_fd, char *conn_name,
- const char *filename, const char *data,
- size_t data_size)
-{
- int dir, res;
-
- dir = igt_debugfs_connector_dir(drm_fd, conn_name, O_RDONLY);
- igt_assert_f(dir >= 0, "Failed to open debugfs dir for connector %s\n",
- conn_name);
-
- res = igt_sysfs_write(dir, filename, data, data_size);
- close(dir);
-
- if (res < 0)
- return -1;
-
- return 0;
-}
-
/**
* igt_get_current_link_rate:
* @drm_fd: A drm file descriptor

--
2.52.0