dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <maxime.ripard@bootlin.com>,
	Sean Paul <seanpaul@chromium.org>,
	Daniel Vetter <daniel.vetter@intel.com>,
	Jani Nikula <jani.nikula@linux.intel.com>,
	Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: David Airlie <airlied@linux.ie>,
	intel-gfx <intel-gfx@lists.freedesktop.org>,
	linux-usb@vger.kernel.org, dri-devel@lists.freedesktop.org
Subject: [PATCH 1/3] drm: Add support for out-of-band hotplug notification
Date: Mon, 25 Feb 2019 14:20:35 +0100	[thread overview]
Message-ID: <20190225132037.31458-2-hdegoede@redhat.com> (raw)
In-Reply-To: <20190225132037.31458-1-hdegoede@redhat.com>

On some hardware a hotplug event notification may come from outside the
display driver / device.

One example of this is laptops with hybrid graphics where one or more
outputs are connected to the discrete GPU only. In this case if the
discrete GPU is fully powered down to save power, a hotplug to one of
these outputs will not be noticed through normal means. These laptops
have another mechanism to detect the hotplug which will typically raise
an event on the ACPI video bus.

Another example of this is some USB Type-C setups where the hardware
muxes the DisplayPort data and aux-lines but does not pass the altmode
HPD status bit to the GPUs DP HPD pin.

This commit adds a loose coupling to the drm subsys allowing event-sources
to notify drm-drivers of such events without needing a reference to a
drm-device or a drm-connector.

This loose coupling is implemented through a blocking notifier. drm-drivers
interested in oob hotplug events can register themselves to receive
notifations and event-sources call drm_kms_call_oob_hotplug_notifier_chain
to let any listeners know about events.

An earlier attempt has been done to implement this functionality with a
tight coupling, where the event-source would somehow figure out the right
drm-connector to deliver the event to and then send it directly to that
drm-connector. Such a tight coupling approach has several issues with
lifetime management of the coupled objects as well as introducing several
probe-ordering issues. Therefor the tight coupling approach has been
abandoned.

Note for now drm_kms_call_oob_hotplug_notifier_chain's event parameter can
only have 1 value: DRM_OOB_HOTPLUG_TYPE_C_DP.  The ACPI videobus hotplug
event case is currently already supported in the nouveau driver by
registering a generic acpi event notifier.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 Documentation/gpu/drm-kms-helpers.rst |  1 +
 drivers/gpu/drm/drm_probe_helper.c    | 67 +++++++++++++++++++++++++++
 include/drm/drm_probe_helper.h        | 12 +++++
 3 files changed, 80 insertions(+)

diff --git a/Documentation/gpu/drm-kms-helpers.rst b/Documentation/gpu/drm-kms-helpers.rst
index b422eb8edf16..f144d68f8e7a 100644
--- a/Documentation/gpu/drm-kms-helpers.rst
+++ b/Documentation/gpu/drm-kms-helpers.rst
@@ -249,6 +249,7 @@ Output Probing Helper Functions Reference
 
 .. kernel-doc:: drivers/gpu/drm/drm_probe_helper.c
    :doc: output probing helper overview
+   :doc: out-of-band hotplug event helper overview
 
 .. kernel-doc:: drivers/gpu/drm/drm_probe_helper.c
    :export:
diff --git a/drivers/gpu/drm/drm_probe_helper.c b/drivers/gpu/drm/drm_probe_helper.c
index 6fd08e04b323..4f0b421514ef 100644
--- a/drivers/gpu/drm/drm_probe_helper.c
+++ b/drivers/gpu/drm/drm_probe_helper.c
@@ -31,6 +31,7 @@
 
 #include <linux/export.h>
 #include <linux/moduleparam.h>
+#include <linux/notifier.h>
 
 #include <drm/drmP.h>
 #include <drm/drm_client.h>
@@ -792,3 +793,69 @@ bool drm_helper_hpd_irq_event(struct drm_device *dev)
 	return changed;
 }
 EXPORT_SYMBOL(drm_helper_hpd_irq_event);
+
+/**
+ * DOC: out-of-band hotplug event helper overview
+ *
+ * On some hardware a hotplug event notification may come from outside
+ * the display driver / device.
+ *
+ * One example of this is laptops with hybrid graphics where one or more
+ * outputs are connected to the discrete GPU only. In this case if the discrete
+ * GPU is fully powered down to save power, a hotplug to one of these outputs
+ * will not be noticed through normal means. These laptops have another
+ * mechanism to detect the hotplug which will typically raise an event on the
+ * ACPI video bus.
+ *
+ * Another example of this is some USB Type-C setups where the hardware
+ * muxes the DisplayPort data and aux-lines but does not pass the altmode
+ * HPD status bit to the GPUs DP HPD pin.
+ *
+ * The oob hotplug helper functions allow a drm display driver to listen
+ * for such oob events and allow other subsystems to notify listeners of
+ * these events.
+ */
+
+static BLOCKING_NOTIFIER_HEAD(drm_kms_oob_hotplug_notifier_head);
+
+/**
+ * drm_kms_register_oob_hotplug_notifier - register an oob hotplug notifier
+ * @nb: notifier_block to register
+ *
+ * Drivers can use this helper function to register a notifier for
+ * out-of-band hotplug events.
+ */
+int drm_kms_register_oob_hotplug_notifier(struct notifier_block *nb)
+{
+	return blocking_notifier_chain_register(
+				&drm_kms_oob_hotplug_notifier_head, nb);
+}
+EXPORT_SYMBOL(drm_kms_register_oob_hotplug_notifier);
+
+/**
+ * drm_kms_unregister_oob_hotplug_notifier - unregister an oob hotplug notifier
+ * @nb: notifier_block to register
+ *
+ * Drivers can use this helper function to unregister a notifier for
+ * out-of-band hotplug events.
+ */
+int drm_kms_unregister_oob_hotplug_notifier(struct notifier_block *nb)
+{
+	return blocking_notifier_chain_unregister(
+				&drm_kms_oob_hotplug_notifier_head, nb);
+}
+EXPORT_SYMBOL(drm_kms_unregister_oob_hotplug_notifier);
+
+/**
+ * drm_kms_call_oob_hotplug_notifier_chain - notify about an oob hotplug event
+ * @event: enum drm_kms_oob_hotplug_event value describing the event
+ *
+ * Out-of-band hotplug event sources can call this helper function to notify
+ * kms-drivers about an oob hotplug event.
+ */
+int drm_kms_call_oob_hotplug_notifier_chain(unsigned long event)
+{
+	return blocking_notifier_call_chain(
+			&drm_kms_oob_hotplug_notifier_head, event, NULL);
+}
+EXPORT_SYMBOL(drm_kms_call_oob_hotplug_notifier_chain);
diff --git a/include/drm/drm_probe_helper.h b/include/drm/drm_probe_helper.h
index 8d3ed2834d34..68cfce47d35f 100644
--- a/include/drm/drm_probe_helper.h
+++ b/include/drm/drm_probe_helper.h
@@ -24,4 +24,16 @@ void drm_kms_helper_poll_disable(struct drm_device *dev);
 void drm_kms_helper_poll_enable(struct drm_device *dev);
 bool drm_kms_helper_is_poll_worker(void);
 
+/**
+ * enum drm_kms_oob_hotplug_event - out-of-band hotplug events
+ * @DRM_OOB_HOTPLUG_TYPE_C_DP: DisplayPort over Type-C hotplug event
+ */
+enum drm_kms_oob_hotplug_event {
+	DRM_OOB_HOTPLUG_TYPE_C_DP = 0,
+};
+
+int drm_kms_register_oob_hotplug_notifier(struct notifier_block *nb);
+int drm_kms_unregister_oob_hotplug_notifier(struct notifier_block *nb);
+int drm_kms_call_oob_hotplug_notifier_chain(unsigned long event);
+
 #endif
-- 
2.20.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2019-02-25 13:20 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-25 13:20 [PATCH 0/3] Propagate DP-over-Type-C hotplug events from Type-C subsys to drm-drivers Hans de Goede
2019-02-25 13:20 ` Hans de Goede [this message]
2019-02-25 13:20 ` [PATCH 2/3] i915: Add support for out-of-bound hotplug events Hans de Goede
2019-02-25 13:20 ` [PATCH 3/3] usb: typec: altmodes/displayport: Notify drm subsys of " Hans de Goede
2019-02-25 14:06   ` Greg Kroah-Hartman
2019-02-25 16:19     ` Hans de Goede
2019-02-26  7:40   ` kbuild test robot
2019-02-26 16:04   ` kbuild test robot
2019-02-27  9:44   ` Heikki Krogerus
2019-02-27 15:51     ` Hans de Goede
2019-02-27 10:55 ` [PATCH 0/3] Propagate DP-over-Type-C hotplug events from Type-C subsys to drm-drivers Heikki Krogerus
2019-02-27 11:16   ` Jani Nikula
2019-02-27 11:49     ` Heikki Krogerus
2019-02-27 15:45     ` Hans de Goede
2019-02-28  9:15       ` Heikki Krogerus
2019-02-28 11:24         ` Hans de Goede
2019-02-28 14:47           ` Heikki Krogerus
2019-02-28 16:54             ` Hans de Goede
2019-03-04 15:17               ` Heikki Krogerus
2019-03-05  7:45                 ` Hans de Goede

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190225132037.31458-2-hdegoede@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=airlied@linux.ie \
    --cc=daniel.vetter@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=maxime.ripard@bootlin.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=seanpaul@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).