[RFC v4 23/25] drm: Add DRM device registered notifier
Noralf Trønnes
noralf at tronnes.org
Thu Apr 12 16:12:35 UTC 2018
Add a notifier that fires when a new DRM device is registered.
This can be used by the bootsplash client to connect to all devices.
Signed-off-by: Noralf Trønnes <noralf at tronnes.org>
---
drivers/gpu/drm/drm_drv.c | 32 ++++++++++++++++++++++++++++++++
include/drm/drm_drv.h | 4 ++++
2 files changed, 36 insertions(+)
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index 6f21bafb29be..e42ce320ad07 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -31,6 +31,7 @@
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/mount.h>
+#include <linux/notifier.h>
#include <linux/slab.h>
#include <linux/srcu.h>
@@ -79,6 +80,8 @@ static struct dentry *drm_debugfs_root;
DEFINE_STATIC_SRCU(drm_unplug_srcu);
+static BLOCKING_NOTIFIER_HEAD(drm_dev_notifier);
+
/*
* DRM Minors
* A DRM device can provide several char-dev interfaces on the DRM-Major. Each
@@ -837,6 +840,8 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags)
dev->dev ? dev_name(dev->dev) : "virtual device",
dev->primary->index);
+ blocking_notifier_call_chain(&drm_dev_notifier, 0, dev);
+
goto out_unlock;
err_minors:
@@ -894,6 +899,33 @@ void drm_dev_unregister(struct drm_device *dev)
}
EXPORT_SYMBOL(drm_dev_unregister);
+/**
+ * drm_dev_register_notifier - Register a notifier for new DRM devices
+ * @nb: Notifier block
+ *
+ * Register a notifier that fires when a new &drm_device is registered.
+ *
+ * Note:
+ * Users of this function has to be linked into drm.ko. This is done to make
+ * life simple avoiding tricky race situations.
+ */
+void drm_dev_register_notifier(struct notifier_block *nb)
+{
+ /* Currently this can't fail, but catch it in case this changes */
+ WARN_ON(blocking_notifier_chain_register(&drm_dev_notifier, nb));
+}
+
+/**
+ * drm_dev_unregister_notifier - Unregister DRM device notifier
+ * @nb: Notifier block
+ *
+ * This is a no-op if the notifier isn't registered.
+ */
+void drm_dev_unregister_notifier(struct notifier_block *nb)
+{
+ blocking_notifier_chain_unregister(&drm_dev_notifier, nb);
+}
+
/**
* drm_dev_set_unique - Set the unique name of a DRM device
* @dev: device of which to set the unique name
diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
index 13356e6fd40c..5e6c6ed0d59d 100644
--- a/include/drm/drm_drv.h
+++ b/include/drm/drm_drv.h
@@ -40,6 +40,7 @@ struct drm_minor;
struct dma_buf_attachment;
struct drm_display_mode;
struct drm_mode_create_dumb;
+struct notifier_block;
struct drm_printer;
/* driver capabilities and requirements mask */
@@ -641,6 +642,9 @@ struct drm_device *drm_dev_alloc(struct drm_driver *driver,
int drm_dev_register(struct drm_device *dev, unsigned long flags);
void drm_dev_unregister(struct drm_device *dev);
+void drm_dev_register_notifier(struct notifier_block *nb);
+void drm_dev_unregister_notifier(struct notifier_block *nb);
+
void drm_dev_get(struct drm_device *dev);
void drm_dev_put(struct drm_device *dev);
void drm_dev_unref(struct drm_device *dev);
--
2.15.1
More information about the dri-devel
mailing list