[i-g-t 1/4] lib/igt_kms: Add helper functions to read few debugfs

Bhanuprakash Modem bhanuprakash.modem at intel.com
Wed Apr 6 16:16:06 UTC 2022


Add helper functions:
    - Read maximum bpc from connector debugfs
    - Read Current bpc from crtc debugfs
    - Assert if Current & Requested bpc are not equal

Signed-off-by: Bhanuprakash Modem <bhanuprakash.modem at intel.com>
---
 lib/igt_kms.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_kms.h |  5 +++
 2 files changed, 89 insertions(+)

diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 7838ff28..8161d2e1 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -5379,3 +5379,87 @@ int igt_get_dsc_debugfs_fd(int drmfd, drmModeConnector *connector)
 
 	return openat(igt_debugfs_dir(drmfd), file_name, O_WRONLY);
 }
+
+/*
+ * igt_get_output_max_bpc:
+ * @drmfd: A drm file descriptor
+ * @output_name: Name of the libdrm connector we're going to use
+ *
+ * Returns: The maximum bpc from the connector debugfs.
+ */
+unsigned int igt_get_output_max_bpc(int drmfd, char *connector_name)
+{
+	char buf[24];
+	char *start_loc;
+	int fd, res;
+	unsigned int maximum;
+
+	fd = igt_debugfs_connector_dir(drmfd, connector_name, O_RDONLY);
+	igt_assert(fd >= 0);
+
+	res = igt_debugfs_simple_read(fd, "output_bpc", buf, sizeof(buf));
+	igt_require(res > 0);
+
+	close(fd);
+
+	igt_assert(start_loc = strstr(buf, "Maximum: "));
+	igt_assert_eq(sscanf(start_loc, "Maximum: %u", &maximum), 1);
+
+	return maximum;
+}
+
+/*
+ * igt_get_pipe_current_bpc:
+ * @drmfd: A drm file descriptor
+ * @pipe: Display pipe
+ *
+ * Returns: The current bpc from the crtc debugfs.
+ */
+unsigned int igt_get_pipe_current_bpc(int drmfd, enum pipe pipe)
+{
+	char buf[24];
+	char debugfs_name[24];
+	char *start_loc;
+	int fd, res;
+	unsigned int current;
+
+	fd = igt_debugfs_pipe_dir(drmfd, pipe, O_RDONLY);
+	igt_assert(fd >= 0);
+
+	if (is_i915_device(drmfd))
+		strcpy(debugfs_name, "i915_current_bpc");
+	else if (is_amdgpu_device(drmfd))
+		strcpy(debugfs_name, "amdgpu_current_bpc");
+
+	res = igt_debugfs_simple_read(fd, debugfs_name, buf, sizeof(buf));
+	igt_require(res > 0);
+
+	close(fd);
+
+	igt_assert(start_loc = strstr(buf, "Current: "));
+	igt_assert_eq(sscanf(start_loc, "Current: %u", &current), 1);
+
+	return current;
+}
+
+/*
+ * igt_assert_output_bpc_equal:
+ * @drmfd: A drm file descriptor
+ * @pipe: Display pipe
+ * @output_name: Name of the libdrm connector we're going to use
+ * @bpc: BPC to compare with max & current bpc
+ *
+ * Returns: True if crtc has the correct requested bpc, else False.
+ */
+void igt_assert_output_bpc_equal(int drmfd, enum pipe pipe,
+				 char *output_name, unsigned int bpc)
+{
+	unsigned int maximum = igt_get_output_max_bpc(drmfd, output_name);
+	unsigned int current = igt_get_pipe_current_bpc(drmfd, pipe);
+
+	igt_require_f(maximum >= bpc,
+		      "Monitor doesn't support %u bpc, max is %u\n", bpc,
+		      maximum);
+
+	igt_assert_eq(current, bpc);
+}
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index e9ecd21e..aca541d8 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -948,4 +948,9 @@ int igt_force_dsc_enable_bpp(int drmfd, drmModeConnector *connector,
 				int bpp);
 int igt_get_dsc_debugfs_fd(int drmfd, drmModeConnector *connector);
 
+unsigned int igt_get_output_max_bpc(int drmfd, char *connector_name);
+unsigned int igt_get_pipe_current_bpc(int drmfd, enum pipe pipe);
+void igt_assert_output_bpc_equal(int drmfd, enum pipe pipe,
+				char *output_name, unsigned int bpc);
+
 #endif /* __IGT_KMS_H__ */
-- 
2.35.1



More information about the Intel-gfx-trybot mailing list