diff options
author | David Zhang <dingchen.zhang@amd.com> | 2022-03-12 00:29:08 -0500 |
---|---|---|
committer | Aurabindo Pillai <aurabindo.pillai@amd.com> | 2022-03-16 15:49:06 -0400 |
commit | 893fc8f76bc755e1598032f11b006595bb64fc84 (patch) | |
tree | 5dd108c4685ef1b4825d3a8c6d1741e1fc079203 /lib | |
parent | 7d58593b9f502933d4e0d0ec7cf8268b5002bb54 (diff) |
lib/igt_amd: add helpers to check PSR state
[why]
For AMDGPU devices, we'd check the PSR state via reading from the
debugfs interface for a given eDP connector, where the debugfs
interface path locates at
<debugfs_root>/dri/0/eDP-X/psr_state
where 'X' is the eDP connector index.
[how]
define and add the helper to check if PSR state debugfs interface
is supported in driver, and the helper to read PSR state from the
debugfs interface.
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')
-rw-r--r-- | lib/igt_amd.c | 68 | ||||
-rw-r--r-- | lib/igt_amd.h | 3 |
2 files changed, 71 insertions, 0 deletions
diff --git a/lib/igt_amd.c b/lib/igt_amd.c index 577a8612..59e503a2 100644 --- a/lib/igt_amd.c +++ b/lib/igt_amd.c @@ -251,6 +251,38 @@ bool igt_amd_is_tiled(uint64_t modifier) } /** + * @brief generic helper to check if the debugfs entry of given connector has the + * debugfs interface defined. + * @param drm_fd: DRM file descriptor + * @param connector_name: The connector's name, on which we're reading the status + * @param interface_name: The debugfs interface name to check + * @return true if <debugfs_root>/connector_name/interface_name exists and defined + * @return false otherwise + */ +static bool igt_amd_output_has_debugfs(int drm_fd, char *connector_name, const char *interface_name) +{ + int fd; + int res; + struct stat stat; + + fd = igt_debugfs_connector_dir(drm_fd, connector_name, O_RDONLY); + if (fd < 0) { + igt_info("output %s: debugfs not found\n", connector_name); + return false; + } + + res = fstatat(fd, interface_name, &stat, 0); + if (res != 0) { + igt_info("output %s: %s debugfs not supported\n", connector_name, interface_name); + close(fd); + return false; + } + + close(fd); + return true; +} + +/** * igt_amd_output_has_dsc: check if connector has dsc debugfs entry * @drm_fd: DRM file descriptor * @connector_name: The connector's name, on which we're reading the status @@ -1097,3 +1129,39 @@ bool igt_amd_psr_support_drv(int drm_fd, char *connector_name, enum psr_mode mod else return strstr(buf, "Driver support: yes [0x01]"); } + +/** + * igt_amd_output_has_psr_state: check if eDP connector has psr_state debugfs entry + * @drm_fd: DRM file descriptor + * @connector_name: The connector's name, on which we're reading the status + */ +bool igt_amd_output_has_psr_state(int drm_fd, char *connector_name) +{ + return igt_amd_output_has_debugfs(drm_fd, connector_name, DEBUGFS_EDP_PSR_STATE); +} + +/** + * @brief Read PSR State from debugfs interface + * @param drm_fd DRM file descriptor + * @param connector_name The connector's name, on which we're reading the status + * @return PSR state as integer + */ +int igt_amd_read_psr_state(int drm_fd, char *connector_name) +{ + char buf[4]; + int fd, ret; + + fd = igt_debugfs_connector_dir(drm_fd, connector_name, O_RDONLY); + if (fd < 0) { + igt_info("Couldn't open connector %s debugfs directory\n", connector_name); + return false; + } + + ret = igt_debugfs_simple_read(fd, DEBUGFS_EDP_PSR_STATE, buf, sizeof(buf)); + close(fd); + + igt_assert_f(ret >= 0, "Reading %s for connector %s failed.\n", + DEBUGFS_EDP_PSR_STATE, connector_name); + + return strtol(buf, NULL, 10); +} diff --git a/lib/igt_amd.h b/lib/igt_amd.h index 6e465817..f87c1991 100644 --- a/lib/igt_amd.h +++ b/lib/igt_amd.h @@ -47,6 +47,7 @@ #define DEBUGFS_EDP_ILR_SETTING "ilr_setting" #define MAX_SUPPORTED_ILR 8 #define DEBUGFS_EDP_PSR_CAP "psr_capability" +#define DEBUGFS_EDP_PSR_STATE "psr_state" enum amd_dsc_clock_force { DSC_AUTOMATIC = 0, @@ -143,5 +144,7 @@ bool igt_amd_output_has_ilr_setting(int drm_fd, char *connector_name); bool igt_amd_output_has_psr_cap(int drm_fd, char *connector_name); bool igt_amd_psr_support_sink(int drm_fd, char *connector_name, enum psr_mode mode); bool igt_amd_psr_support_drv(int drm_fd, char *connector_name, enum psr_mode mode); +bool igt_amd_output_has_psr_state(int drm_fd, char *connector_name); +int igt_amd_read_psr_state(int drm_fd, char *connector_name); #endif /* IGT_AMD_H */ |