Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751965AbdGFQDC (ORCPT ); Thu, 6 Jul 2017 12:03:02 -0400 Received: from mail-out.m-online.net ([212.18.0.10]:39065 "EHLO mail-out.m-online.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750970AbdGFQDB (ORCPT ); Thu, 6 Jul 2017 12:03:01 -0400 X-Auth-Info: npAiz2NqEpbJktiYgsmf+riXwZXgi65Kx7N7BFWIieA= From: Anatolij Gustschin To: Alan Tull Cc: Moritz Fischer , linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] fpga manager: add notifier for manager register and unregister events Date: Thu, 6 Jul 2017 18:02:57 +0200 Message-Id: <1499356977-4412-1-git-send-email-agust@denx.de> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4401 Lines: 127 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). Signed-off-by: Anatolij Gustschin --- Documentation/fpga/fpga-mgr.txt | 8 ++++++++ drivers/fpga/fpga-mgr.c | 34 ++++++++++++++++++++++++++++++++++ include/linux/fpga/fpga-mgr.h | 13 +++++++++++++ 3 files changed, 55 insertions(+) diff --git a/Documentation/fpga/fpga-mgr.txt b/Documentation/fpga/fpga-mgr.txt index 78f197f..e81d566 100644 --- a/Documentation/fpga/fpga-mgr.txt +++ b/Documentation/fpga/fpga-mgr.txt @@ -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 */ diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c index 188ffef..7362bb4 100644 --- a/drivers/fpga/fpga-mgr.c +++ b/drivers/fpga/fpga-mgr.c @@ -27,10 +27,39 @@ #include #include #include +#include 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. diff --git a/include/linux/fpga/fpga-mgr.h b/include/linux/fpga/fpga-mgr.h index b4ac24c..7ed4f68 100644 --- a/include/linux/fpga/fpga-mgr.h +++ b/include/linux/fpga/fpga-mgr.h @@ -17,6 +17,7 @@ */ #include #include +#include #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