Skip to contentSkip to conversation

fpga manager: add notifier for manager register and unregister events

PATCH In review Anatolij Gustschin 2 participants 3 messages Jul 6, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fpga manager: add notifier for manager register and unregister events

Add API functions for registering and removing a notifier for FPGA manager register/unregister events. Notify when a new FPGA manager has been registered or when an existing manager is being removed. This will help configuration interface drivers to get the notion of low-level FPGA managers popping up or disappearing, when using hotpluggable FPGA configuration devices (e.g. via USB-SPI adapters).

---
 Documentation/fpga/fpga-mgr.txt |  8 ++++++++
 drivers/fpga/fpga-mgr.c         | 34 ++++++++++++++++++++++++++++++++++
 include/linux/fpga/fpga-mgr.h   | 13 +++++++++++++
 3 files changed, 55 insertions(+)
Documentation/fpga/fpga-mgr.txt +8 -0
index 78f197f..e81d566 100644
@@ -73,6 +73,14 @@ Use of these two functions is described below in "How To Support a new FPGA
 device."
 
 
+To register or unregister the notifier callback for signalling
+about the low level FPGA-Managers being added or removed:
+----------------------------------------------------------
+
+	void fpga_mgr_register_mgr_notifier(struct notifier_block *nb);
+	void fpga_mgr_unregister_mgr_notifier(struct notifier_block *nb);
+
+
 How to write an image buffer to a supported FPGA
 ================================================
 /* Include to get the API */
drivers/fpga/fpga-mgr.c +34 -0
index 188ffef..7362bb4 100644
@@ -27,10 +27,39 @@
 #include <linux/slab.h>
 #include <linux/scatterlist.h>
 #include <linux/highmem.h>
+#include <linux/notifier.h>
 
 static DEFINE_IDA(fpga_mgr_ida);
 static struct class *fpga_mgr_class;
 
+static BLOCKING_NOTIFIER_HEAD(fpga_mgr_notifier_list);
+
+/**
+ * fpga_mgr_register_mgr_notifier() - register fpga manager notifier callback
+ * @nb: pointer to the notifier block for the callback events.
+ *
+ * Add a notifier callback for FPGA manager changes. These changes are
+ * either FPGA manager being added or removed.
+ */
+void fpga_mgr_register_mgr_notifier(struct notifier_block *nb)
+{
+	blocking_notifier_chain_register(&fpga_mgr_notifier_list, nb);
+}
+EXPORT_SYMBOL_GPL(fpga_mgr_register_mgr_notifier);
+
+/**
+ * fpga_mgr_unregister_mgr_notifier() - unregister a notifier callback
+ * @nb: pointer to the notifier block for the callback events.
+ *
+ * Remove a notifier callback. fpga_mgr_register_mgr_notifier() must have
+ * been previously called for this function to work properly.
+ */
+void fpga_mgr_unregister_mgr_notifier(struct notifier_block *nb)
+{
+	blocking_notifier_chain_unregister(&fpga_mgr_notifier_list, nb);
+}
+EXPORT_SYMBOL_GPL(fpga_mgr_unregister_mgr_notifier);
+
 /*
  * Call the low level driver's write_init function.  This will do the
  * device-specific things to get the FPGA into the state where it is ready to
@@ -518,6 +547,8 @@ int fpga_mgr_register(struct device *dev, const char *name,
 
 	dev_info(&mgr->dev, "%s registered\n", mgr->name);
 
+	blocking_notifier_call_chain(&fpga_mgr_notifier_list,
+				     FPGA_MGR_ADD, mgr);
 	return 0;
 
 error_device:
@@ -539,6 +570,9 @@ void fpga_mgr_unregister(struct device *dev)
 
 	dev_info(&mgr->dev, "%s %s\n", __func__, mgr->name);
 
+	blocking_notifier_call_chain(&fpga_mgr_notifier_list,
+				     FPGA_MGR_REMOVE, mgr);
+
 	/*
 	 * If the low level driver provides a method for putting fpga into
 	 * a desired state upon unregister, do it.
include/linux/fpga/fpga-mgr.h +13 -0
index b4ac24c..7ed4f68 100644
@@ -17,6 +17,7 @@
  */
 #include <linux/mutex.h>
 #include <linux/platform_device.h>
+#include <linux/notifier.h>
 
 #ifndef _LINUX_FPGA_MGR_H
 #define _LINUX_FPGA_MGR_H
@@ -154,4 +155,16 @@ int fpga_mgr_register(struct device *dev, const char *name,
 
 void fpga_mgr_unregister(struct device *dev);
 
+/*
+ * FPGA Manager register notifier events
+ * FPGA_MGR_ADD: a new fpga manager has been registered
+ * FPGA_MGR_REMOVE: a registered fpga manager is being removed
+ */
+#define FPGA_MGR_ADD	1
+#define FPGA_MGR_REMOVE	2
+
+void fpga_mgr_register_mgr_notifier(struct notifier_block *nb);
+
+void fpga_mgr_unregister_mgr_notifier(struct notifier_block *nb);
+
 #endif /*_LINUX_FPGA_MGR_H */
Signature · 1 line
2.7.4
#1 lore raw
Quoted 7 lines · Anatolij Gustschin

Add API functions for registering and removing a notifier for FPGA manager register/unregister events. Notify when a new FPGA manager has been registered or when an existing manager is being removed. This will help configuration interface drivers to get the notion of low-level FPGA managers popping up or disappearing, when using hotpluggable FPGA configuration devices (e.g. via USB-SPI adapters).

Hi Anatolij,

This is interesting and looks pretty straightforward. Do you have any code that uses it?

Alan

Quoted 125 lines
---
 Documentation/fpga/fpga-mgr.txt |  8 ++++++++
 drivers/fpga/fpga-mgr.c         | 34 ++++++++++++++++++++++++++++++++++
 include/linux/fpga/fpga-mgr.h   | 13 +++++++++++++
 3 files changed, 55 insertions(+)
Documentation/fpga/fpga-mgr.txt +8 -0
index 78f197f..e81d566 100644
@@ -73,6 +73,14 @@ Use of these two functions is described below in "How To Support a new FPGA
 device."
 
 
+To register or unregister the notifier callback for signalling
+about the low level FPGA-Managers being added or removed:
+----------------------------------------------------------
+
+       void fpga_mgr_register_mgr_notifier(struct notifier_block *nb);
+       void fpga_mgr_unregister_mgr_notifier(struct notifier_block *nb);
+
+
 How to write an image buffer to a supported FPGA
 ================================================
 /* Include to get the API */
drivers/fpga/fpga-mgr.c +34 -0
index 188ffef..7362bb4 100644
@@ -27,10 +27,39 @@
 #include <linux/slab.h>
 #include <linux/scatterlist.h>
 #include <linux/highmem.h>
+#include <linux/notifier.h>
 
 static DEFINE_IDA(fpga_mgr_ida);
 static struct class *fpga_mgr_class;
 
+static BLOCKING_NOTIFIER_HEAD(fpga_mgr_notifier_list);
+
+/**
+ * fpga_mgr_register_mgr_notifier() - register fpga manager notifier callback
+ * @nb: pointer to the notifier block for the callback events.
+ *
+ * Add a notifier callback for FPGA manager changes. These changes are
+ * either FPGA manager being added or removed.
+ */
+void fpga_mgr_register_mgr_notifier(struct notifier_block *nb)
+{
+       blocking_notifier_chain_register(&fpga_mgr_notifier_list, nb);
+}
+EXPORT_SYMBOL_GPL(fpga_mgr_register_mgr_notifier);
+
+/**
+ * fpga_mgr_unregister_mgr_notifier() - unregister a notifier callback
+ * @nb: pointer to the notifier block for the callback events.
+ *
+ * Remove a notifier callback. fpga_mgr_register_mgr_notifier() must have
+ * been previously called for this function to work properly.
+ */
+void fpga_mgr_unregister_mgr_notifier(struct notifier_block *nb)
+{
+       blocking_notifier_chain_unregister(&fpga_mgr_notifier_list, nb);
+}
+EXPORT_SYMBOL_GPL(fpga_mgr_unregister_mgr_notifier);
+
 /*
  * Call the low level driver's write_init function.  This will do the
  * device-specific things to get the FPGA into the state where it is ready to
@@ -518,6 +547,8 @@ int fpga_mgr_register(struct device *dev, const char *name,
 
        dev_info(&mgr->dev, "%s registered\n", mgr->name);
 
+       blocking_notifier_call_chain(&fpga_mgr_notifier_list,
+                                    FPGA_MGR_ADD, mgr);
        return 0;
 
 error_device:
@@ -539,6 +570,9 @@ void fpga_mgr_unregister(struct device *dev)
 
        dev_info(&mgr->dev, "%s %s\n", __func__, mgr->name);
 
+       blocking_notifier_call_chain(&fpga_mgr_notifier_list,
+                                    FPGA_MGR_REMOVE, mgr);
+
        /*
         * If the low level driver provides a method for putting fpga into
         * a desired state upon unregister, do it.
include/linux/fpga/fpga-mgr.h +13 -1
index b4ac24c..7ed4f68 100644
@@ -17,6 +17,7 @@
  */
 #include <linux/mutex.h>
 #include <linux/platform_device.h>
+#include <linux/notifier.h>
 
 #ifndef _LINUX_FPGA_MGR_H
 #define _LINUX_FPGA_MGR_H
@@ -154,4 +155,16 @@ int fpga_mgr_register(struct device *dev, const char *name,
 
 void fpga_mgr_unregister(struct device *dev);
 
+/*
+ * FPGA Manager register notifier events
+ * FPGA_MGR_ADD: a new fpga manager has been registered
+ * FPGA_MGR_REMOVE: a registered fpga manager is being removed
+ */
+#define FPGA_MGR_ADD   1
+#define FPGA_MGR_REMOVE        2
+
+void fpga_mgr_register_mgr_notifier(struct notifier_block *nb);
+
+void fpga_mgr_unregister_mgr_notifier(struct notifier_block *nb);
+
 #endif /*_LINUX_FPGA_MGR_H */
--

2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-fpga" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw

Hi Alan,

On Thu, 6 Jul 2017 13:53:23 -0500
Alan Tull [email protected] wrote:
...

Quoted 2 lines

This is interesting and looks pretty straightforward. Do you have any code that uses it?

I've send a patch series for FPP manager, it will add the FPGA manager when an FTDI based configuration device is connected via USB and the manager will disappear when this device is unplugged. I have code with configuration interface for this manager, but it is something special and not suitable for mainline, I think. It creates the configuration interface when a new manager is detected and removes this interface when the device is detached.

Thanks,
Anatolij