From patchwork Sun Oct 30 18:12:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Moritz Fischer X-Patchwork-Id: 9404619 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 BA3766022E for ; Sun, 30 Oct 2016 18:15:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC79F28DBF for ; Sun, 30 Oct 2016 18:15:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F3F228E01; Sun, 30 Oct 2016 18:15:02 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0B04B28DBF for ; Sun, 30 Oct 2016 18:15:01 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1c0ubF-00060y-BP; Sun, 30 Oct 2016 18:12:53 +0000 Received: from mail-pf0-x22f.google.com ([2607:f8b0:400e:c00::22f]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1c0ub9-0005yl-7w for linux-arm-kernel@lists.infradead.org; Sun, 30 Oct 2016 18:12:49 +0000 Received: by mail-pf0-x22f.google.com with SMTP id 189so10826760pfz.3 for ; Sun, 30 Oct 2016 11:12:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ettus-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=EOf1kBXTAdEupGnpDiUM9/pdTN6+SdLWH/TKPt8kL9o=; b=cRySZTUz5weOoJnwmBbW84qJV3nYRG0BYRq5YLurAc5hLWQ0Q5USBuBKgocuVTCVaH vFCmRwtSzZ9qrctA6V2VvdEOzhHXq4hPx5S7fZoo+t13e7niHFkAguuCgfCxSevAViF2 lGtiyFtfKXu4vDtjnPNQ8FikT4wAPP+y47lQb+Sa2Gw4s4nyKk4SzQMc7rxGU9WWRZ+m n6yFlA2QJCFyIwZHgYrB3h3FUtRwWa/dT2akGA0NicddfaoBYb8vsYPL5U9F7SEtYZca Q1cJYzkAi9+CQUAVn8QewI+Bk2jTTcZwrcB8lPkqTnhAY1Adt+//SMvJQFOeVO9wWv7L 4S8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=EOf1kBXTAdEupGnpDiUM9/pdTN6+SdLWH/TKPt8kL9o=; b=Ew9DKr89EXiw6E6KfiGkLw/6l/EpaZaCdpLMUIl1cIoT+UeTbkVoxYNfOqNh33Yf13 owHOF45kxEaF2PCPO+Mpg6AHu/tLeEkKWh9gwTdhjSCJRF00ONRMlwX5W7FqvM+kzj3a XITTTmtjjkZIdRlR24FpKbwgo+VQoyVLLY65xljAk/ou5l7hUOZUGUt8NY95hvDfY/gC EoRzNpb9he+8wllX0XykF3CLQg840tTrs06dKMGtfc0ipuigm4oNLDb0k5AwhG35Cq6j 0S/07ZoIKFVdBkUk83hRF7jFiQ3QDeA9z44Zg3gUUlZgGXyM8YyKJtRv2mFhwr0i6KSe 1oMQ== X-Gm-Message-State: ABUngvfgZpIt0K/RHE81NngDdvK6uUIXmzSx4rC5XPnAxkut6NMpQBBTyBmye+Cf2N+rkf6M X-Received: by 10.98.83.70 with SMTP id h67mr42394098pfb.107.1477851142704; Sun, 30 Oct 2016 11:12:22 -0700 (PDT) Received: from beastybook.lan (c-50-185-0-126.hsd1.ca.comcast.net. [50.185.0.126]) by smtp.gmail.com with ESMTPSA id v4sm31235193pfb.52.2016.10.30.11.12.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 Oct 2016 11:12:21 -0700 (PDT) From: Moritz Fischer To: atull@opensource.altera.com Subject: [RFC] fpga: Pull checks for supported operations into framework Date: Sun, 30 Oct 2016 11:12:03 -0700 Message-Id: <1477851123-17686-1-git-send-email-moritz.fischer@ettus.com> X-Mailer: git-send-email 2.4.11 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161030_111248_420792_2E6A571C X-CRM114-Status: GOOD ( 19.86 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Moritz Fischer , Michal Simek , =?UTF-8?q?S=C3=B6ren=20Brinkmann?= , linux-kernel@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Most of the drivers only support a subset of {PARTIAL, FULL} reconfiguration. Pull duplicate checks in each driver into the framework. Signed-off-by: Moritz Fischer Cc: Alan Tull Cc: Michal Simek Cc: Sören Brinkmann Cc: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org --- Hi all, with the new drivers (ice40, altera-ps-spi) being submitted I've noticed we're duplicating this check over and over again, so I figured we might as well pull it into the framework. I'm not sure if there are gonna be other 'flags' we need to support in the short term (we talked about byte-swapping ...) Note: This patch goes on top of greg's char-misc-testing that already contains Alan's latest changes to support the A10 and won't apply to master. Cheers, Moritz --- drivers/fpga/fpga-mgr.c | 12 ++++++++++++ drivers/fpga/socfpga-a10.c | 4 +++- drivers/fpga/socfpga.c | 3 ++- drivers/fpga/zynq-fpga.c | 3 ++- include/linux/fpga/fpga-mgr.h | 9 +++++++-- 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c index c58b4c4..85f17d8 100644 --- a/drivers/fpga/fpga-mgr.c +++ b/drivers/fpga/fpga-mgr.c @@ -49,6 +49,11 @@ int fpga_mgr_buf_load(struct fpga_manager *mgr, struct fpga_image_info *info, struct device *dev = &mgr->dev; int ret; + if (!(mgr->supported_flags & info->flags)) { + dev_err(dev, "Unsupported flags passed\n"); + return -ENOTSUPP; + } + /* * 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 @@ -252,6 +257,7 @@ EXPORT_SYMBOL_GPL(fpga_mgr_put); */ int fpga_mgr_register(struct device *dev, const char *name, const struct fpga_manager_ops *mops, + u32 supported_flags, void *priv) { struct fpga_manager *mgr; @@ -268,6 +274,11 @@ int fpga_mgr_register(struct device *dev, const char *name, return -EINVAL; } + if (!supported_flags) { + dev_err(dev, "Attempt to register with no supported flags\n"); + return -EINVAL; + } + mgr = kzalloc(sizeof(*mgr), GFP_KERNEL); if (!mgr) return -ENOMEM; @@ -282,6 +293,7 @@ int fpga_mgr_register(struct device *dev, const char *name, mgr->name = name; mgr->mops = mops; + mgr->supported_flags = supported_flags; mgr->priv = priv; /* diff --git a/drivers/fpga/socfpga-a10.c b/drivers/fpga/socfpga-a10.c index ccd9fb2..e7c82ff 100644 --- a/drivers/fpga/socfpga-a10.c +++ b/drivers/fpga/socfpga-a10.c @@ -519,7 +519,9 @@ static int socfpga_a10_fpga_probe(struct platform_device *pdev) } return fpga_mgr_register(dev, "SoCFPGA Arria10 FPGA Manager", - &socfpga_a10_fpga_mgr_ops, priv); + &socfpga_a10_fpga_mgr_ops, + FPGA_MGR_PARTIAL_RECONFIG, + priv); } static int socfpga_a10_fpga_remove(struct platform_device *pdev) diff --git a/drivers/fpga/socfpga.c b/drivers/fpga/socfpga.c index b6672e6..3285b7d 100644 --- a/drivers/fpga/socfpga.c +++ b/drivers/fpga/socfpga.c @@ -582,7 +582,8 @@ static int socfpga_fpga_probe(struct platform_device *pdev) return ret; return fpga_mgr_register(dev, "Altera SOCFPGA FPGA Manager", - &socfpga_fpga_ops, priv); + &socfpga_fpga_ops, FPGA_MGR_FULL_RECONFIG, + priv); } static int socfpga_fpga_remove(struct platform_device *pdev) diff --git a/drivers/fpga/zynq-fpga.c b/drivers/fpga/zynq-fpga.c index 249682e..1dabd25 100644 --- a/drivers/fpga/zynq-fpga.c +++ b/drivers/fpga/zynq-fpga.c @@ -413,6 +413,7 @@ static int zynq_fpga_probe(struct platform_device *pdev) struct zynq_fpga_priv *priv; struct resource *res; int err; + u32 flags = FPGA_MGR_FULL_RECONFIG | FPGA_MGR_PARTIAL_RECONFIG; priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) @@ -465,7 +466,7 @@ static int zynq_fpga_probe(struct platform_device *pdev) clk_disable(priv->clk); err = fpga_mgr_register(dev, "Xilinx Zynq FPGA Manager", - &zynq_fpga_ops, priv); + &zynq_fpga_ops, flags, priv); if (err) { dev_err(dev, "unable to register FPGA manager"); clk_unprepare(priv->clk); diff --git a/include/linux/fpga/fpga-mgr.h b/include/linux/fpga/fpga-mgr.h index 040b86d..4f4bcf2 100644 --- a/include/linux/fpga/fpga-mgr.h +++ b/include/linux/fpga/fpga-mgr.h @@ -64,9 +64,12 @@ enum fpga_mgr_states { /* * FPGA Manager flags + * FPGA_MGR_FULL_RECONFIG: do full reconfiguration if supported * FPGA_MGR_PARTIAL_RECONFIG: do partial reconfiguration if supported */ -#define FPGA_MGR_PARTIAL_RECONFIG BIT(0) +#define FPGA_MGR_FULL_RECONFIG BIT(0) +#define FPGA_MGR_PARTIAL_RECONFIG BIT(1) +#define FPGA_MGR_EXTERNAL_CONFIG BIT(2) /** * struct fpga_image_info - information specific to a FPGA image @@ -119,6 +122,7 @@ struct fpga_manager { enum fpga_mgr_states state; const struct fpga_manager_ops *mops; void *priv; + u32 supported_flags; }; #define to_fpga_manager(d) container_of(d, struct fpga_manager, dev) @@ -135,7 +139,8 @@ struct fpga_manager *of_fpga_mgr_get(struct device_node *node); void fpga_mgr_put(struct fpga_manager *mgr); int fpga_mgr_register(struct device *dev, const char *name, - const struct fpga_manager_ops *mops, void *priv); + const struct fpga_manager_ops *mops, u32 supported_flags, + void *priv); void fpga_mgr_unregister(struct device *dev);