[igt-dev] [Patch][i-g-t v4 1/3] lib/igt_kms: Add support for detecting connector events

Ankit Nautiyal ankit.k.nautiyal at intel.com
Wed Jun 24 05:41:28 UTC 2020


Currently, the event_detect function checks the property val for
"HOTPLUG" and "LEASE" both of which are set to '1' when these events
are sent.

This cannot be used for detecting connector events such as HDCP event
as connector events are sent along with property to signify which
property of which connector has changed. Connector ID and property id
are provided along with "CONNECTOR" and "PROPERTY" as udev
property-value pairs. Eg. for HDCP, the connector id of the connector
whose hdcp status changed, and the property id of the
‘CONTENT_PROTECTION’ property are sent with uevent.

This patch modifies the event_detect function to check multiple
properties with different expected values. It also adds support to
detect connector event for a given pair of connector and property ids.

v2: Simplified the event_detect conditional statements. (Ram)
    Changed the api name for detecting connnector events. (Anshuman)
    Added check for "HOTPLUG" property value for connector events.
v3: Used ARRAY_SIZE() instead of constants. (Ram)
v4: Rebase

Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal at intel.com>
Reviewed-by: Ramalingam C <ramalingam.c at intel.com>
Acked-by: Arkadiusz Hiler <arkadiusz.hiler at intel.com>
---
 lib/igt_kms.c | 71 ++++++++++++++++++++++++++++++++++++++-------------
 lib/igt_kms.h |  2 ++
 2 files changed, 55 insertions(+), 18 deletions(-)

diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index afef5939..1af74d08 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -4194,33 +4194,60 @@ struct udev_monitor *igt_watch_hotplug(void)
 	return mon;
 }
 
-static bool event_detected(struct udev_monitor *mon, int timeout_secs,
-			   const char *property)
+static
+bool event_detected(struct udev_monitor *mon, int timeout_secs,
+		    const char **property, int *expected_val, int num_props)
 {
 	struct udev_device *dev;
-	const char *hotplug_val;
+	const char *prop_val;
 	struct pollfd fd = {
 		.fd = udev_monitor_get_fd(mon),
 		.events = POLLIN
 	};
-	bool hotplug_received = false;
+	bool event_received = false;
+	int i;
 
-	/* Go through all of the events pending on the udev monitor. Once we
-	 * receive a hotplug, we continue going through the rest of the events
-	 * so that redundant hotplug events don't change the results of future
-	 * checks
+	/* Go through all of the events pending on the udev monitor.
+	 * Match the given set of properties and their values to
+	 * the expected values.
 	 */
-	while (!hotplug_received && poll(&fd, 1, timeout_secs * 1000)) {
+	while (!event_received && poll(&fd, 1, timeout_secs * 1000)) {
 		dev = udev_monitor_receive_device(mon);
-
-		hotplug_val = udev_device_get_property_value(dev, property);
-		if (hotplug_val && atoi(hotplug_val) == 1)
-			hotplug_received = true;
+		for (i = 0; i < num_props; i++) {
+			prop_val = udev_device_get_property_value(dev,
+								  property[i]);
+			if (!prop_val || atoi(prop_val) != expected_val[i])
+				break;
+		}
+		if (i == num_props)
+			event_received = true;
 
 		udev_device_unref(dev);
 	}
 
-	return hotplug_received;
+	return event_received;
+}
+
+/**
+ * igt_connector_event_detected:
+ * @mon: A udev monitor initialized with #igt_watch_hotplug
+ * @conn_id: Connector id of the Connector for which the property change is
+ * expected.
+ * @prop_id: Property id for which the change is expected.
+ * @timeout_secs: How long to wait for a connector event to occur.
+ *
+ * Detect if a connector event is received for a given connector and property.
+ *
+ * Returns: true if the connector event was received, false if we timed out
+ */
+bool igt_connector_event_detected(struct udev_monitor *mon, uint32_t conn_id,
+				  uint32_t prop_id, int timeout_secs)
+{
+	const char *props[3] = {"HOTPLUG", "CONNECTOR", "PROPERTY"};
+	int expected_val[3] = {1, conn_id, prop_id};
+
+	return event_detected(mon, timeout_secs, props, expected_val,
+			      ARRAY_SIZE(props));
 }
 
 /**
@@ -4228,13 +4255,17 @@ static bool event_detected(struct udev_monitor *mon, int timeout_secs,
  * @mon: A udev monitor initialized with #igt_watch_hotplug
  * @timeout_secs: How long to wait for a hotplug event to occur.
  *
- * Assert that a hotplug event was received since we last checked the monitor.
+ * Detect if a hotplug event was received since we last checked the monitor.
  *
  * Returns: true if a sysfs hotplug event was received, false if we timed out
  */
 bool igt_hotplug_detected(struct udev_monitor *mon, int timeout_secs)
 {
-	return event_detected(mon, timeout_secs, "HOTPLUG");
+	const char *props[1] = {"HOTPLUG"};
+	int expected_val = 1;
+
+	return event_detected(mon, timeout_secs, props, &expected_val,
+			      ARRAY_SIZE(props));
 }
 
 /**
@@ -4242,13 +4273,17 @@ bool igt_hotplug_detected(struct udev_monitor *mon, int timeout_secs)
  * @mon: A udev monitor initialized with #igt_watch_hotplug
  * @timeout_secs: How long to wait for a lease change event to occur.
  *
- * Assert that a lease change event was received since we last checked the monitor.
+ * Detect if a lease change event was received since we last checked the monitor.
  *
  * Returns: true if a sysfs lease change event was received, false if we timed out
  */
 bool igt_lease_change_detected(struct udev_monitor *mon, int timeout_secs)
 {
-	return event_detected(mon, timeout_secs, "LEASE");
+	const char *props[1] = {"LEASE"};
+	int expected_val = 1;
+
+	return event_detected(mon, timeout_secs, props, &expected_val,
+			      ARRAY_SIZE(props));
 }
 
 /**
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index 32a0e4cc..539f6c5a 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -779,6 +779,8 @@ bool igt_hotplug_detected(struct udev_monitor *mon,
 			  int timeout_secs);
 bool igt_lease_change_detected(struct udev_monitor *mon,
 			       int timeout_secs);
+bool igt_connector_event_detected(struct udev_monitor *mon, uint32_t conn_id,
+				  uint32_t prop_id, int timeout_msecs);
 void igt_flush_hotplugs(struct udev_monitor *mon);
 void igt_cleanup_hotplug(struct udev_monitor *mon);
 
-- 
2.17.1



More information about the igt-dev mailing list