summaryrefslogtreecommitdiff
path: root/lib/igt_amd.c
diff options
context:
space:
mode:
authorVictor Lu <victorchengchi.lu@amd.com>2021-08-06 16:44:12 +0800
committerRodrigo Siqueira <Rodrigo.Siqueira@amd.com>2021-08-29 11:05:22 -0400
commitc95edfe676bad0a7d296dd271a237d8225728a9d (patch)
treed7e2b46a03d28ebb5eee796635d5cf2029e69f77 /lib/igt_amd.c
parent1afd52c1471dafdf521eae431f3e228826de6de2 (diff)
tests/amdgpu: Introduce amd_hotplug tests
[Why] There is a debugfs entry to trigger software hotplugs. We can use this for IGT tests. [How] Add hotplug test for all connectors, hotplug after suspend. Signed-off-by: Victor Lu <victorchengchi.lu@amd.com> Reviewed-by: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com>
Diffstat (limited to 'lib/igt_amd.c')
-rw-r--r--lib/igt_amd.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/lib/igt_amd.c b/lib/igt_amd.c
index a4e1cb59..4ffe7cf2 100644
--- a/lib/igt_amd.c
+++ b/lib/igt_amd.c
@@ -20,6 +20,9 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
+#include <fcntl.h>
+#include <sys/stat.h>
+
#include "igt_amd.h"
#include "igt.h"
#include <amdgpu_drm.h>
@@ -246,3 +249,77 @@ bool igt_amd_is_tiled(uint64_t modifier)
else
return false;
}
+
+/**
+ * igt_amd_output_has_hpd: check if connector has HPD debugfs entry
+ * @drm_fd: DRM file descriptor
+ * @connector_name: The connector's name, on which we're reading the status
+ */
+static bool igt_amd_output_has_hpd(int drm_fd, char *connector_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, DEBUGFS_HPD_TRIGGER, &stat, 0);
+ if (res != 0) {
+ igt_info("%s debugfs not supported\n", DEBUGFS_HPD_TRIGGER);
+ close(fd);
+ return false;
+ }
+
+ close(fd);
+ return true;
+}
+
+/**
+ * igt_amd_require_hpd: Checks if connectors have HPD debugfs
+ * @display: A pointer to an #igt_display_t structure
+ * @drm_fd: DRM file descriptor
+ *
+ * Checks if the AMDGPU driver has support the 'trigger_hotplug'
+ * entry for HPD. Skip test if HPD is not supported.
+ */
+void igt_amd_require_hpd(igt_display_t *display, int drm_fd)
+{
+ igt_output_t *output;
+
+ for_each_connected_output(display, output) {
+ if (igt_amd_output_has_hpd(drm_fd, output->name))
+ return;
+ }
+
+ igt_skip("No HPD debugfs support.\n");
+}
+
+/**
+ * igt_amd_trigger_hotplut: Triggers a debugfs HPD
+ * @drm_fd: DRM file descriptor
+ * @connector_name: The connector's name, which we trigger the hotplug on
+ *
+ * igt_amd_require_hpd should be called before calling this.
+ */
+int igt_amd_trigger_hotplug(int drm_fd, char *connector_name)
+{
+ int fd, hpd_fd;
+ int wr_len;
+ const char *enable_hpd = "1";
+
+ fd = igt_debugfs_connector_dir(drm_fd, connector_name, O_RDONLY);
+ igt_assert(fd >= 0);
+ hpd_fd = openat(fd, DEBUGFS_HPD_TRIGGER, O_WRONLY);
+ close(fd);
+ igt_assert(hpd_fd >= 0);
+
+ wr_len = write(hpd_fd, enable_hpd, strlen(enable_hpd));
+ close(hpd_fd);
+ igt_assert_eq(wr_len, strlen(enable_hpd));
+
+ return 0;
+}