From patchwork Thu Jul 6 16:02:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anatolij Gustschin X-Patchwork-Id: 9828565 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9B3B760361 for ; Thu, 6 Jul 2017 16:03:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A15B286C7 for ; Thu, 6 Jul 2017 16:03:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7CF7F286CA; Thu, 6 Jul 2017 16:03:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 917A3286C7 for ; Thu, 6 Jul 2017 16:03:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751653AbdGFQDC (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 Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 3x3Mw31yqMz1qsCY; Thu, 6 Jul 2017 18:02:59 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 3x3Mw30lzzz3jgYT; Thu, 6 Jul 2017 18:02:59 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id DUMChQkEHZBr; Thu, 6 Jul 2017 18:02:57 +0200 (CEST) X-Auth-Info: npAiz2NqEpbJktiYgsmf+riXwZXgi65Kx7N7BFWIieA= Received: from crub.agik.hopto.org (p4FCB5B3B.dip0.t-ipconnect.de [79.203.91.59]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Thu, 6 Jul 2017 18:02:57 +0200 (CEST) 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-fpga-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 */