summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Clark <robdclark@chromium.org>2021-11-07 12:36:53 -0800
committerRob Clark <robdclark@chromium.org>2021-11-29 16:32:09 -0800
commit77fd5c719be64cef31dfea81c6405ced2aa7992c (patch)
tree271e254415a054fcbfba257de2ab7cd5c891e748
parent5598666e8612fa98c6b4a92a824998f52135b0cc (diff)
lib/igt_debugfs: Add helper for writing debugfs files
Signed-off-by: Rob Clark <robdclark@chromium.org> Reviewed-by: Petri Latvala <petri.latvala@intel.com>
-rw-r--r--lib/igt_debugfs.c17
-rw-r--r--lib/igt_debugfs.h13
2 files changed, 30 insertions, 0 deletions
diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index a5bb95ca..dd6f2995 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -352,6 +352,23 @@ void __igt_debugfs_read(int fd, const char *filename, char *buf, int size)
}
/**
+ * __igt_debugfs_write:
+ * @fd: the drm device file fd
+ * @filename: file name
+ * @buf: buffer to be written to the debugfs file
+ * @size: size of the buffer
+ *
+ * This function opens the debugfs file, writes it, then closes the file.
+ */
+void __igt_debugfs_write(int fd, const char *filename, const char *buf, int size)
+{
+ int dir = igt_debugfs_dir(fd);
+
+ igt_sysfs_write(dir, filename, buf, size);
+ close(dir);
+}
+
+/**
* igt_debugfs_search:
* @filename: file name
* @substring: string to search for in @filename
diff --git a/lib/igt_debugfs.h b/lib/igt_debugfs.h
index d43ba6c6..b4867681 100644
--- a/lib/igt_debugfs.h
+++ b/lib/igt_debugfs.h
@@ -40,6 +40,7 @@ int igt_debugfs_pipe_dir(int device, int pipe, int mode);
int igt_debugfs_open(int fd, const char *filename, int mode);
void __igt_debugfs_read(int fd, const char *filename, char *buf, int size);
+void __igt_debugfs_write(int fd, const char *filename, const char *buf, int size);
int igt_debugfs_simple_read(int dir, const char *filename, char *buf, int size);
bool igt_debugfs_search(int fd, const char *filename, const char *substring);
@@ -54,6 +55,18 @@ bool igt_debugfs_search(int fd, const char *filename, const char *substring);
#define igt_debugfs_read(fd, filename, buf) \
__igt_debugfs_read(fd, (filename), (buf), sizeof(buf))
+/**
+ * igt_debugfs_write:
+ * @fd: the drm device file fd
+ * @filename: name of the debugfs file
+ * @buf: buffer to be written to the debugfs file
+ *
+ * This is just a convenience wrapper for __igt_debugfs_write. See its
+ * documentation.
+ */
+#define igt_debugfs_write(fd, filename, buf) \
+ __igt_debugfs_write(fd, (filename), (buf), sizeof(buf))
+
/*
* Pipe CRC
*/