summaryrefslogtreecommitdiff
path: root/lib/igt_amd.c
diff options
context:
space:
mode:
authorDavid Zhang <dingchen.zhang@amd.com>2022-04-06 10:48:38 -0400
committerAurabindo Pillai <aurabindo.pillai@amd.com>2022-04-06 15:31:50 -0400
commitb4d8d30a4ec8dae5c1c403f41348c073a9591d9f (patch)
tree22a0f6ee4186fe4573ef6fba23ceac664ecf0e76 /lib/igt_amd.c
parent7506029428b3740395ce086daf86b9498fbbeb77 (diff)
lib/igt_amd: add helper to R/W DM visual confirm debug option
[why & how] AMDGPU DM exposure a debugfs interface entry of visual confirm debug option which is configured for debugging like surface programming. It also supports the PSR feature visual confirm debugging. We'd add helpers to read/write visual confirm debug option from/to such interface entry. The interface entry "amdgpu_dm_visual_confirm" is located in the debugfs directory. We'd add the enumeration of visual confirm option which is aligned to the amdgpu kernel driver. Changes in v2: -------------------- - close the file descriptor before return in helper of setting visual confirm - drop the '_dm_' from helpers to check visual confirm debugfs existence, get/set option from/to the debugfs entry. Cc: Rodrigo Siqueira <rodrigo.siqueira@amd.com> Cc: Harry Wentland <harry.wentland@amd.com> Cc: Leo Li <sunpeng.li@amd.com> Cc: Aurabindo Pillai <aurabindo.pillai@amd.com> Cc: Wayne Lin <wayne.lin@amd.com> Signed-off-by: David Zhang <dingchen.zhang@amd.com> Reviewed-by: Aurabindo Pillai <aurabindo.pillai@amd.com>
Diffstat (limited to 'lib/igt_amd.c')
-rw-r--r--lib/igt_amd.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/lib/igt_amd.c b/lib/igt_amd.c
index 888da44a..f6ca2237 100644
--- a/lib/igt_amd.c
+++ b/lib/igt_amd.c
@@ -25,6 +25,7 @@
#include "igt_amd.h"
#include "igt.h"
+#include "igt_sysfs.h"
#include <amdgpu_drm.h>
#define X0 1
@@ -251,6 +252,38 @@ bool igt_amd_is_tiled(uint64_t modifier)
}
/**
+ * @brief generic helper to check if the amdgpu dm debugfs entry defined
+ *
+ * @param drm_fd DRM file descriptor
+ * @param interface_name The debugfs interface entry name with prefix "amdgpu_"
+ * @return true if <debugfs_root>/interface_name exists and defined
+ * @return false otherwise
+ */
+static bool amd_has_debugfs(int drm_fd, const char *interface_name)
+{
+ int fd;
+ int res;
+ struct stat stat;
+
+ fd = igt_debugfs_dir(drm_fd);
+ if (fd < 0) {
+ igt_info("Couldn't open debugfs dir!\n");
+ return false;
+ }
+
+ res = fstatat(fd, interface_name, &stat, 0);
+ if (res != 0) {
+ igt_info("debugfs %s not supported\n", interface_name);
+ close(fd);
+ return false;
+ }
+
+ close(fd);
+ return true;
+}
+
+
+/**
* @brief generic helper to check if the debugfs entry of given connector has the
* debugfs interface defined.
* @param drm_fd: DRM file descriptor
@@ -1075,3 +1108,70 @@ int igt_amd_read_psr_state(int drm_fd, char *connector_name)
return strtol(buf, NULL, 10);
}
+
+/**
+ * @brief check if AMDGPU DM visual confirm debugfs interface entry exist and defined
+ *
+ * @param drm_fd DRM file descriptor
+ * @return true if visual confirm debugfs interface exists and defined
+ * @return false otherwise
+ */
+bool igt_amd_has_visual_confirm(int drm_fd)
+{
+ return amd_has_debugfs(drm_fd, DEBUGFS_DM_VISUAL_CONFIRM);
+}
+
+/**
+ * @brief Read amdgpu DM visual confirm debugfs interface
+ *
+ * @param drm_fd DRM file descriptor
+ * @return int visual confirm debug option as integer
+ */
+int igt_amd_get_visual_confirm(int drm_fd)
+{
+ char buf[4]; /* current 4 bytes are enough */
+ int fd, ret;
+
+ fd = igt_debugfs_dir(drm_fd);
+ if (fd < 0) {
+ igt_info("Couldn't open debugfs dir!\n");
+ return -1;
+ }
+
+ ret = igt_debugfs_simple_read(fd, DEBUGFS_DM_VISUAL_CONFIRM, buf, sizeof(buf));
+ close(fd);
+
+ igt_assert_f(ret >= 0, "Reading %s failed.\n",
+ DEBUGFS_DM_VISUAL_CONFIRM);
+
+ return strtol(buf, NULL, 10);
+}
+
+/**
+ * @brief Write amdgpu DM visual confirm debug option to debugfs interface
+ *
+ * @param drm_fd DRM file descriptor
+ * @param option amdgpu DC visual confirm debug option
+ * @return true if set visual confirm option success
+ * @return false otherwise
+ */
+bool igt_amd_set_visual_confirm(int drm_fd, enum amdgpu_debug_visual_confirm option)
+{
+ char buf[4];
+ int fd;
+ bool res;
+
+ fd = igt_debugfs_dir(drm_fd);
+ if (fd < 0) {
+ igt_info("Couldn't open debugfs dir!\n");
+ return false;
+ }
+
+ memset(buf, '\0', sizeof(buf));
+ snprintf(buf, sizeof(buf), "%d\n", option);
+
+ res = igt_sysfs_set(fd, DEBUGFS_DM_VISUAL_CONFIRM, buf);
+ close(fd);
+
+ return res;
+}