<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:10pt;color:#0000FF;margin:5pt;" align="Left">
[AMD Official Use Only]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
Reviewed-by: Aurabindo Pillai <aurabindo.pillai@amd.com><br>
</div>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div id="Signature">
<div>
<div></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
--</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Regards,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Jay<br>
</div>
</div>
</div>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Zhang, Dingchen (David) <Dingchen.Zhang@amd.com><br>
<b>Sent:</b> Tuesday, April 5, 2022 4:13 PM<br>
<b>To:</b> igt-dev@lists.freedesktop.org <igt-dev@lists.freedesktop.org><br>
<b>Cc:</b> Siqueira, Rodrigo <Rodrigo.Siqueira@amd.com>; Wentland, Harry <Harry.Wentland@amd.com>; Li, Sun peng (Leo) <Sunpeng.Li@amd.com>; Pillai, Aurabindo <Aurabindo.Pillai@amd.com>; Lin, Wayne <Wayne.Lin@amd.com><br>
<b>Subject:</b> [PATCH] lib/igt_amd: add helper to R/W DM visual confirm debug option</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">[why & how]<br>
AMDGPU DM exposure a debugfs interface entry of visual confirm<br>
debug option which is configured for debugging like surface<br>
programming. It also supports the PSR feature visual confirm<br>
debugging. We'd add helpers to read/write visual confirm debug<br>
option from/to such interface entry.<br>
<br>
The interface entry "amdgpu_dm_visual_confirm" is located in the<br>
debugfs directory. We'd add the enumeration of visual confirm<br>
option which is aligned to the amdgpu kernel driver.<br>
<br>
Changes in v2:<br>
--------------------<br>
- close the file descriptor before return in helper of setting<br>
visual confirm<br>
- drop the '_dm_' from helpers to check visual confirm debugfs<br>
existence, get/set option from/to the debugfs entry.<br>
<br>
Cc: Rodrigo Siqueira <rodrigo.siqueira@amd.com><br>
Cc: Harry Wentland <harry.wentland@amd.com><br>
Cc: Leo Li <sunpeng.li@amd.com><br>
Cc: Aurabindo Pillai <aurabindo.pillai@amd.com><br>
Cc: Wayne Lin <wayne.lin@amd.com><br>
<br>
Signed-off-by: David Zhang <dingchen.zhang@amd.com><br>
---<br>
lib/igt_amd.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++<br>
lib/igt_amd.h | 20 ++++++++++<br>
2 files changed, 120 insertions(+)<br>
<br>
diff --git a/lib/igt_amd.c b/lib/igt_amd.c<br>
index 664602da..f499ab46 100644<br>
--- a/lib/igt_amd.c<br>
+++ b/lib/igt_amd.c<br>
@@ -25,6 +25,7 @@<br>
<br>
#include "igt_amd.h"<br>
#include "igt.h"<br>
+#include "igt_sysfs.h"<br>
#include <amdgpu_drm.h><br>
<br>
#define X0 1<br>
@@ -250,6 +251,38 @@ bool igt_amd_is_tiled(uint64_t modifier)<br>
return false;<br>
}<br>
<br>
+/**<br>
+ * @brief generic helper to check if the amdgpu dm debugfs entry defined<br>
+ *<br>
+ * @param drm_fd DRM file descriptor<br>
+ * @param interface_name The debugfs interface entry name with prefix "amdgpu_"<br>
+ * @return true if <debugfs_root>/interface_name exists and defined<br>
+ * @return false otherwise<br>
+ */<br>
+static bool amd_has_debugfs(int drm_fd, const char *interface_name)<br>
+{<br>
+ int fd;<br>
+ int res;<br>
+ struct stat stat;<br>
+<br>
+ fd = igt_debugfs_dir(drm_fd);<br>
+ if (fd < 0) {<br>
+ igt_info("Couldn't open debugfs dir!\n");<br>
+ return false;<br>
+ }<br>
+<br>
+ res = fstatat(fd, interface_name, &stat, 0);<br>
+ if (res != 0) {<br>
+ igt_info("debugfs %s not supported\n", interface_name);<br>
+ close(fd);<br>
+ return false;<br>
+ }<br>
+<br>
+ close(fd);<br>
+ return true;<br>
+}<br>
+<br>
+<br>
/**<br>
* @brief generic helper to check if the debugfs entry of given connector has the<br>
* debugfs interface defined.<br>
@@ -1075,3 +1108,70 @@ int igt_amd_read_psr_state(int drm_fd, char *connector_name)<br>
<br>
return strtol(buf, NULL, 10);<br>
}<br>
+<br>
+/**<br>
+ * @brief check if AMDGPU DM visual confirm debugfs interface entry exist and defined<br>
+ * <br>
+ * @param drm_fd DRM file descriptor<br>
+ * @return true if visual confirm debugfs interface exists and defined<br>
+ * @return false otherwise<br>
+ */<br>
+bool igt_amd_has_visual_confirm(int drm_fd)<br>
+{<br>
+ return amd_has_debugfs(drm_fd, DEBUGFS_DM_VISUAL_CONFIRM);<br>
+}<br>
+<br>
+/**<br>
+ * @brief Read amdgpu DM visual confirm debugfs interface<br>
+ *<br>
+ * @param drm_fd DRM file descriptor<br>
+ * @return int visual confirm debug option as integer<br>
+ */<br>
+int igt_amd_get_visual_confirm(int drm_fd)<br>
+{<br>
+ char buf[4]; /* current 4 bytes are enough */<br>
+ int fd, ret;<br>
+<br>
+ fd = igt_debugfs_dir(drm_fd);<br>
+ if (fd < 0) {<br>
+ igt_info("Couldn't open debugfs dir!\n");<br>
+ return -1;<br>
+ }<br>
+<br>
+ ret = igt_debugfs_simple_read(fd, DEBUGFS_DM_VISUAL_CONFIRM, buf, sizeof(buf));<br>
+ close(fd);<br>
+<br>
+ igt_assert_f(ret >= 0, "Reading %s failed.\n",<br>
+ DEBUGFS_DM_VISUAL_CONFIRM);<br>
+<br>
+ return strtol(buf, NULL, 10);<br>
+}<br>
+<br>
+/**<br>
+ * @brief Write amdgpu DM visual confirm debug option to debugfs interface<br>
+ *<br>
+ * @param drm_fd DRM file descriptor<br>
+ * @param option amdgpu DC visual confirm debug option<br>
+ * @return true if set visual confirm option success<br>
+ * @return false otherwise<br>
+ */<br>
+bool igt_amd_set_visual_confirm(int drm_fd, enum amdgpu_debug_visual_confirm option)<br>
+{<br>
+ char buf[4];<br>
+ int fd;<br>
+ bool res;<br>
+<br>
+ fd = igt_debugfs_dir(drm_fd);<br>
+ if (fd < 0) {<br>
+ igt_info("Couldn't open debugfs dir!\n");<br>
+ return false;<br>
+ }<br>
+<br>
+ memset(buf, '\0', sizeof(buf));<br>
+ snprintf(buf, sizeof(buf), "%d\n", option);<br>
+<br>
+ res = igt_sysfs_set(fd, DEBUGFS_DM_VISUAL_CONFIRM, buf);<br>
+ close(fd);<br>
+<br>
+ return res;<br>
+}<br>
diff --git a/lib/igt_amd.h b/lib/igt_amd.h<br>
index e4e12ce5..428bfe6f 100644<br>
--- a/lib/igt_amd.h<br>
+++ b/lib/igt_amd.h<br>
@@ -49,6 +49,9 @@<br>
#define DEBUGFS_EDP_PSR_CAP "psr_capability"<br>
#define DEBUGFS_EDP_PSR_STATE "psr_state"<br>
<br>
+/* amdgpu DM interface entries */<br>
+#define DEBUGFS_DM_VISUAL_CONFIRM "amdgpu_dm_visual_confirm"<br>
+<br>
enum amd_dsc_clock_force {<br>
DSC_AUTOMATIC = 0,<br>
DSC_FORCE_ON,<br>
@@ -115,6 +118,19 @@ enum amdgpu_psr_state {<br>
PSR_STATE_INVALID = 0xFF<br>
};<br>
<br>
+/*<br>
+ * enumeration of amdgpu DC visual confirm debug option<br>
+ * aligned to the upstreamed amdgpu kernel driver 'enum visual_confirm' in dc.h<br>
+ */<br>
+enum amdgpu_debug_visual_confirm {<br>
+ VISUAL_CONFIRM_DISABLE = 0,<br>
+ VISUAL_CONFIRM_SURFACE = 1,<br>
+ VISUAL_CONFIRM_HDR = 2,<br>
+ VISUAL_CONFIRM_MPCTREE = 4,<br>
+ VISUAL_CONFIRM_PSR = 5,<br>
+ VISUAL_CONFIRM_SWIZZLE = 9<br>
+};<br>
+<br>
uint32_t igt_amd_create_bo(int fd, uint64_t size);<br>
void *igt_amd_mmap_bo(int fd, uint32_t handle, uint64_t size, int prot);<br>
unsigned int igt_amd_compute_offset(unsigned int* swizzle_pattern,<br>
@@ -172,4 +188,8 @@ bool igt_amd_psr_support_drv(int drm_fd, char *connector_name, enum psr_mode mod<br>
bool igt_amd_output_has_psr_state(int drm_fd, char *connector_name);<br>
int igt_amd_read_psr_state(int drm_fd, char *connector_name);<br>
<br>
+/* DM interface helpers */<br>
+bool igt_amd_has_visual_confirm(int drm_fd);<br>
+int igt_amd_get_visual_confirm(int drm_fd);<br>
+bool igt_amd_set_visual_confirm(int drm_fd, enum amdgpu_debug_visual_confirm option);<br>
#endif /* IGT_AMD_H */<br>
-- <br>
2.25.1<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>