[igt-dev] [PATCH i-g-t 1/4] lib/igt_kms: Add igt_connector_sysfs_open()
Ville Syrjala
ville.syrjala at linux.intel.com
Tue Dec 3 15:35:52 UTC 2019
From: Ville Syrjälä <ville.syrjala at linux.intel.com>
Add a helper to open the sysfs directory for a connector.
Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
---
lib/igt_kms.c | 34 ++++++++++++++++++++++++++++++++++
lib/igt_kms.h | 3 +++
2 files changed, 37 insertions(+)
diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 44647a2263bd..74ae98d774f1 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -965,6 +965,40 @@ static void reset_connectors_at_exit(int sig)
igt_reset_connectors();
}
+static char *kmstest_connector_dirname(int idx,
+ uint32_t connector_type,
+ uint32_t connector_type_id,
+ char *name, int namelen)
+{
+ snprintf(name, namelen, "card%d-%s-%d", idx,
+ kmstest_connector_type_str(connector_type),
+ connector_type_id);
+
+ return name;
+}
+
+int igt_connector_sysfs_open(int drm_fd,
+ drmModeConnector *connector)
+{
+ char name[80];
+ int dir, conn_dir;
+
+ dir = igt_sysfs_open(drm_fd);
+ if (dir < 0)
+ return dir;
+
+ if (!kmstest_connector_dirname(igt_device_get_card_index(drm_fd),
+ connector->connector_type,
+ connector->connector_type_id,
+ name, sizeof(name)))
+ return -1;
+
+ conn_dir = openat(dir, name, O_RDONLY);
+ close(dir);
+
+ return conn_dir;
+}
+
/**
* kmstest_force_connector:
* @fd: drm file descriptor
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index 3f798392f8a0..6c919e92f488 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -844,4 +844,7 @@ static inline bool igt_vblank_before(uint32_t a, uint32_t b)
void igt_parse_connector_tile_blob(drmModePropertyBlobPtr blob,
igt_tile_info_t *tile);
+int igt_connector_sysfs_open(int drm_fd,
+ drmModeConnector *connector);
+
#endif /* __IGT_KMS_H__ */
--
2.23.0
More information about the igt-dev
mailing list