Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754526AbbLJXpm (ORCPT ); Thu, 10 Dec 2015 18:45:42 -0500 Received: from mail-bn1on0062.outbound.protection.outlook.com ([157.56.110.62]:19782 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753549AbbLJXpg (ORCPT ); Thu, 10 Dec 2015 18:45:36 -0500 Authentication-Results: spf=fail (sender IP is 66.35.236.227) smtp.mailfrom=opensource.altera.com; lwn.net; dkim=none (message not signed) header.d=none;lwn.net; dmarc=none action=none header.from=opensource.altera.com; Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=atull@opensource.altera.com; From: To: Rob Herring CC: Moritz Fischer , Josh Cartwright , , , , Pawel Moll , Mark Rutland , "Ian Campbell" , Kumar Gala , Jonathan Corbet , , , , , , , Alan Tull Subject: [PATCH v14 5/7] fpga: add fpga bridge framework Date: Thu, 10 Dec 2015 17:37:07 -0600 Message-ID: <1449790629-5517-6-git-send-email-atull@opensource.altera.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1449790629-5517-1-git-send-email-atull@opensource.altera.com> References: <1449790629-5517-1-git-send-email-atull@opensource.altera.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [64.129.157.38] X-ClientProxiedBy: SN1PR0501CA0035.namprd05.prod.outlook.com (25.163.126.173) To BLUPR03MB1507.namprd03.prod.outlook.com (25.163.81.25) X-Microsoft-Exchange-Diagnostics-untrusted: 1;BLUPR03MB1507;2:qHoN/c7f8gb5tRYe7np6keOzBTJgL2MudinHzTddBnB1qXHpfZYTb51aE+wXYgwFWxSa1gdnz+Pl+z1OvTFku8wdCZeskBVqAC9be8pUX7k0caxiyt6NkdVL2aY6bYnGF4bHRtiXxqQnHoolMJEIMQ==;3:AMfqJk1vCyPQNaYYljI9r87RnWDW0qgcRO9wIoyfspEUj3qLzqV1XdbZUANBJsmMQJmJ3zsYOmfuwFU+/2e86fqjWCi3ovPSnZCPf60BDKHkl4H3w7QSkdZXQtdDEq+e;25:Okq1YWhnJb2Cc1u6DSWN/Q/5KriqycXo4KqYIkVPCi4q1l0emb+wkFrDZ7J7XzR3Lw7WzXwXEg+ir+dV5vO96ayD+PguEHL20WTh0SeYN+qrXkQmZPxe7/34OCcq53vfrf5xe4lbqgPbNydqySa5Jylbgfsx3qdBb185rml52d/1oGKPzcLUvjrJUTJncmYjJYvTZAFAO/B9QvgAaLlzDBsZ2pmXXtM6ntJKQ+WIbQcf+A5+Dx6SO5hHxBRxPg+yWvbFmwPh8VwzlxFYG879yA==;20:EdlL1b1j2cCd57PnYKvEWRRUqpFSKND9FmniJO/MWFkkkQ7IIlMZOtCc7PziH1o7iStjF90OuxOI4wPTzol5CYer1IeyvLTS48jaMVtMw/s40x6i5aXfuJxgDb2BDGa644vxKrhpzUuzWuy/PVClW4p9M/k87grxmMqMYqWVaTM= X-Microsoft-Antispam-Untrusted: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB1507; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(80048183373757)(204874498639787);UriScan:(80048183373757)(204874498639787); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(520078)(8121501046)(5005006)(10201501046)(3002001);SRVR:BLUPR03MB1507;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB1507;BCL:0;PCL:0;RULEID:(601004)(2401047)(520078)(8121501046)(5005006)(10201501046)(3002001);SRVR:CY1PR0301MB2075;BCL:0;PCL:0;RULEID:;SRVR:CY1PR0301MB2075; X-Microsoft-Exchange-Diagnostics-untrusted: 1;BLUPR03MB1507;4:ZmjRAxDb08OoDqrwE+vy71NJKaMJ0rGn3zsqzDr2Lp5RPVW0pMdSnxGpKCOSUOlkkxcQkvxa/1M8WgSUhGskukNSQvjY0El1IALBs3q0ExhIwQF10qFCWPK4cGrs8pe+j8OHrKZ0JR08DeuARqgthzkwcGg7PJzSihYclUbdTvb/6LGGoXwNSKSigSV5XPb9FoViYbkn9T5pOrFFeC+9tRMlrkDVjsCb9znpqV7zCDHU/Jh7KP7fK4I0mQQAFuoY9UPsncAwBlwniZz6n82Et0N144Ho6iGvHS9l8PficeRIq4yB//LEYAoXtoruLsgYyKZR9/9TDvh01uJFubB06e34SZdz4r/ZTOFIYyTX6NVv93/H7XdrhICGSP0aKIfrcFBoAJAZiFkeFSpAzbMpclXLFavxwu6MpCLGDg+OAzj3owICYlrIaeF6EufygAHm5JtNswTa9mR16TFpWgRacQ== X-Forefront-PRVS: 078693968A X-Forefront-Antispam-Report-Untrusted: SFV:NSPM;SFS:(10009020)(6009001)(189002)(199003)(229853001)(105586002)(19580405001)(77096005)(19580395003)(3846002)(2950100001)(47776003)(5003940100001)(50466002)(15975445007)(189998001)(86152002)(5001960100002)(48376002)(69596002)(50226001)(107886002)(40100003)(122386002)(87976001)(50986999)(86362001)(92566002)(53416004)(81156007)(42186005)(97736004)(76176999)(106356001)(66066001)(33646002)(101416001)(110136002)(586003)(6116002)(4001430100002)(5008740100001)(5004730100002)(1096002)(7059030)(2004002);DIR:OUT;SFP:1101;SCL:1;SRVR:BLUPR03MB1507;H:linuxheads99.altera.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:0;LANG:en; X-Microsoft-Exchange-Diagnostics-untrusted: =?us-ascii?Q?1;BLUPR03MB1507;23:VduRNuukIaXzPHjnAHRht8aG1gNfWVhWuFdcqh49G?= =?us-ascii?Q?ObJGGsnbHJ2LdtfHppPicNBDf1tK7mnyNJmagX3W0XbeCvAeURr1RgGyM7PZ?= =?us-ascii?Q?lgF4d2EhMi3nxXn0qZYHi4p1oiALLEnWlZCHbFK91AsDuBO/k5ov//v6VlGO?= =?us-ascii?Q?Tavff81xnhV0YWkBIqHOHj8ZDhvdixjdUbDBjKVR9/3TmkoM3CldCKn8HeyE?= =?us-ascii?Q?97nbTcaFDLjHx4lFN9AgM7zn2SS7CiMdM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TV8rb+Ov3fYt9JTltK9LLEQocor7yum62b3JDh7MecNPMIAnEALy?= =?us-ascii?Q?I9dnHnby/4DGak=3D?= X-Microsoft-Exchange-Diagnostics-untrusted: 1;BLUPR03MB1507;5:hydIzBCk3Xq/SRWNEl5bLzQx9IUxD8Ghmt5dgZmUTJtcT6At1zxGwIGu4TQBCP+BKz1ZEh/PTAImUA+nkRDhTLgJMIeeCmwe1OEmKExEJnv/7pCVsV5rQezNk0NqdwT7hzESBTv9xOXYWLvOaa0DxA==;24:f2irfgr1lb+CCDWBvWniN6iF+UyvIfHpbSRDNy1GAXsjgJJ+Zgk4QHthaK5uxn5AIBvRNT3868hBVB/HHI10mQP4s2jp5REnFbxhrnT/PNc=;20:M/YSM6WZ8odp9SC/oIKT9dNizpSURPTRQOn8RuLObFpIg9qUZkBakONhem9xqhpLcwXDhX7vOjSNz4yBEOhH83MmA55O44RhIEIhLuoqS/6Webw7Aa2g5ptC5RUcTPfRfe2gyLkbQi3rHhS+8n3Tsb5Ify8+/F/UBZFJjCzISec= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR03MB1507 X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: BN1AFFO11FD050.protection.gbl X-Microsoft-Exchange-Diagnostics: 1;BN1AFFO11FD050;1:idfJNsccfEd2Uj8G9QfeOs2XwcED6+e/E5xxcM1DjCZUljMyf1J38cq0ddqYvflYw13mVdqZEyQYwREGM9CyCPthAX4Y/jOGJgii8IaAgRbcAyZnDPGPCD22RfKReXrOx+knO+wGyd63sdIqZdAh7sjdnLxlI2As5u73/MsrmhGYktFc7h81xjNh6zYuIHdd5tEqmrM1Xmz8DWEYgP0eaFO+vK5RQOGKT1gI/Eooew9xc4/hSmtG6sERp/xIftG2OOziae54rMX6B0O3QDQ/n70bF4PQP8101kI0kDGsvj6bn3dVMibj8cdnSqFMkWxU5Pt/Tb+ew04etc14qUgSYjKguXxFACC+OMVDYRYfWrWbFmFKuiH7mapdy4hICgZBROzaZ0QYLcZj2JHYGQ0wvO3SAO0GbeOHMoCBX9Llg3lZrsY1v+4/o1kZ0dBEQWIt X-Forefront-Antispam-Report: CIP:66.35.236.227;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(586003)(33646002)(3846002)(229853001)(87936001)(5008740100001)(122386002)(6116002)(11100500001)(1220700001)(1096002)(110136002)(6806005)(189998001)(53416004)(5003940100001)(5001960100002)(5004730100002)(40100003)(105606002)(4001430100002)(107886002)(76176999)(21840400001)(106466001)(50986999)(97736004)(66066001)(50466002)(6070500001)(81156007)(15975445007)(50226001)(85426001)(86152002)(86362001)(77096005)(48376002)(92566002)(19580405001)(2950100001)(16796002)(19580395003)(47776003)(7099028)(7059030)(2004002);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR0301MB2075;H:sj-itexedge03.altera.priv.altera.com;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;MX:1;A:0;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB2075;2:YQ/vw34Vfo03/BOhOlr3KILoVMds18763Z/73g8yMlVaLNvQsWbXC4AVidAGXXgJ9DVGXtiydCtISgt7KXgQkF6hMgRckXCp5LA9GVpjYy9h3A7HflIQhTxPb84OpWFuXTHIdK0XVVJIJ46SBCRN1A==;3:96XUZ9iZl3woNat43ang4rQq4/Pyd17R7tjv4ZHLZmC4SjvgNaTd7XcE6rPuZZfsNKua3sNh4Yu3KV40WtyCk/CE5a1LOOMCSThs3FchmkDrtPbFq5yGn3QChHMpBAKV07UnREPDzXtzphcREu78bY6a82DLvgg6xHy+hbZIejBhwxgO5+Ipg7do0kCOxdGuzvRz2z71do8kEbZ/bEtCdvtEoYyL77n7bqZVjCogPao=;25:qGt69rbbxwwRlUsUQ4TmgKWcEO9MSJE8fqo4977ICG00zeDLgGDh4/m/1ficAtUa4wI4QwgkSiaiLGbA1jI7FMVtXuvinOzOyYTvNJM5tp0h4Yalh81Yi5fprzp0QdOIfTTwzJ3SC2t0nRb1AaJNN8GImcISsYe+o8x+HeNeLG04lNv1ld8esyBkMwMmGrjzHOlaZ2YdOS7kpQ4GLio3qaeoPYVbJ3ScmiMclb1IKF3wDYBFIS/ZS/DTUi8lrazYn3EiSG/gOM27CFYweFbGVQ==;20:yZoFT+ZWPZy5cOK5GG6FFw6AYYKaw317ThHgSbYCpkWho3HBexm3fmoI7PPbI44J8usg5ocG4mylH5R0uIRDdH/owhmC+Or3Ul0iKni+vFBz9s69Z4v3idZSLfvcUwUJM8xJSY1P/GmmeZOeeozgwZcEq0Ywt7KniK47GDFRv1E= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR0301MB2075; X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB2075;4:UfWaFU28Fyco9tRJI5uw3v/QKE01QvsSlY9VxS9mZMaJsWAQFf5RAqi/t6tL9TtnxAG2MAt50h6P4rg6wHm00goi8NhzLaaDisGhCwCyWjD0ge7UmY0LpiD6DEiDfAgEM78tL5DufU17EZ+5wKP0e8BpUqMFzX4tjicsRSdq4+SniZUP1OEFrbTlQwDyUCsn3JGFBfruQbfQitfsNYn6HNbc3MuhHF79Ym8wqde/pY3zSlmsQoe8Eev5kYyp22BLadR6LULBraG2YuvzeChpk8gUpGA6JtfhHJ1+V15K05P9AW9XVCHy+lFHdoeoKm0p4vrWzRMjg650BcBtpGj33hLo+Sd+WHv7G2AGmBsASiS3qtedYu0rtK4BeUtg0cNOd/T2USw1hjTeq3WJDAWIHEniZFpolehzBWQfAMZ5f0GWd6K6nCMhW9v/3j2UdnJP+eTAWz0z/EIbCmTamqnCAQ== X-Forefront-PRVS: 078693968A X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CY1PR0301MB2075;23:JnVfCOmjBRa0M3znvIbE9taLRDqY0wjk1cAEOYx?= =?us-ascii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jGq+sW9M?= =?us-ascii?Q?Z+EF6M9L0YnrMk8Bmno2gChwnYkiUPPo0ttM/0Uub8NROi3TZ6USVO9tFBnq?= =?us-ascii?Q?dcBj/yFuMQkefCO6h0gkHL/pnsRiaJDdTh0jAgEpx9Q1aXiP+e7NXtCzmoOa?= =?us-ascii?Q?cSieLp1op9a2J8nhRaPn4hkFWob65P3j89uXFJ4pto529uagzrgq4d06m2LI?= =?us-ascii?Q?PDvKIeXOeCZaD0SrxK3255JhHNofL02Ro3fR2I8QneTTqQIYOCHbLBqqFC9k?= =?us-ascii?Q?ZuDT5pZXNvzYrcrJIZhB62xYG3F1M3N1fTNC/+/jTlNTlPIPLnIl4kySnmWu?= =?us-ascii?Q?mvtm77CSDluyIgw+VSdFs48z94ykd98RneObsmOhgsuEN28a4Nvxw4UX+5b6?= =?us-ascii?Q?gzOeykZdl6WRvqzvkfTJmZAr777C8LwG4lrl8oQ0KyAb1ccwqBtILE2HXW1Q?= =?us-ascii?Q?JArc5JEGNRlgtREOVwN5cc3zyrXPmy4r0POX4etRyfp/mdYTD?= X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB2075;5:vyVPN5AmPp7W3ApODLWF3HbBZk3dBwc4sO7VBZg23Z/NxeYXwAlKAmjy+GrAYo8im0K9ZhlEQcCQvqvE/3wSB81VGLmYjCnLH0GdTjQbcdiGxsRLYEP/WZ86pB5KsV2R05dO+EZGBjTBxVdi/pGOBw==;24:NH3ujxoVVoHryn5P+cBpg0KVMQ7U6r3KNwYydaN2FvvLDWk30bnUoABsXVLyRskeI5JImeHsUBIG8tx7SoOHINmV/Pe0rbzpMp38MWY6of8=;20:iB5wtr5eyUlvwy+bQWT7jwVebFuEhF1kmkypGfdMx+rYimoBjn4iKehEVvBGqor/cC2PUyHh0orqgFK5r5Sbd8Wpum4yPVzF4akt8P1oFK9YuejI/E9zvDV5w9dTKhiPYc8qkYoYlZSp5NzGsuTUlg3wkA46rvaBnklPdWUShFA= X-OriginatorOrg: opensource.altera.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2015 23:45:32.5653 (UTC) X-MS-Exchange-CrossTenant-Id: fbd72e03-d4a5-4110-adce-614d51f2077a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=fbd72e03-d4a5-4110-adce-614d51f2077a;Ip=[66.35.236.227];Helo=[sj-itexedge03.altera.priv.altera.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0301MB2075 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 15188 Lines: 557 From: Alan Tull This framework adds API functions for enabling/ disabling FPGA bridges under kernel control. This allows the Linux kernel to disable FPGA bridges during FPGA reprogramming and to enable FPGA bridges when FPGA reprogramming is done. This framework is be manufacturer-agnostic, allowing it to be used in interfaces that use the FPGA Manager Framework to reprogram FPGA's. The functions are: * of_fpga_bridge_get * fpga_bridge_put Get/put an exclusive reference to a FPGA bridge. * fpga_bridge_enable * fpga_bridge_disable Enable/Disable traffic through a bridge. * fpga_bridge_register * fpga_bridge_unregister Register/unregister a device-specific low level FPGA Bridge driver. Get an exclusive reference to a bridge and add it to a list: * fpga_bridge_get_to_list To enable/disable/put a set of bridges that are on a list: * fpga_bridges_enable * fpga_bridges_disable * fpga_bridges_put Signed-off-by: Alan Tull --- v2: Minor cleanup v12: Bump version to line up with simple fpga bus Remove sysfs Improve get/put functions, get the low level driver too. Clean up class implementation Add kernel doc documentation Rename (un)register_fpga_bridge -> fpga_bridge_(un)register v13: Add inlined empty functions for if not CONFIG_FPGA_BRIDGE Clean up debugging Remove unneeded #include in .h Remove unnecessary prints Remove 'label' DT binding. Document the mutex v14: Allow bridges with no ops *const* struct fpga_bridge_ops Add functions to git/put/enable/disable list of bridges Add list node to struct fpga_bridge Do of_node_get/put in of_fpga_bridge_get() Add r/o attributes: name and state --- drivers/fpga/Kconfig | 7 + drivers/fpga/Makefile | 3 + drivers/fpga/fpga-bridge.c | 388 ++++++++++++++++++++++++++++++++++++++ include/linux/fpga/fpga-bridge.h | 56 ++++++ 4 files changed, 454 insertions(+) create mode 100644 drivers/fpga/fpga-bridge.c create mode 100644 include/linux/fpga/fpga-bridge.h diff --git a/drivers/fpga/Kconfig b/drivers/fpga/Kconfig index c9b9fdf..b6cfd89 100644 --- a/drivers/fpga/Kconfig +++ b/drivers/fpga/Kconfig @@ -24,6 +24,13 @@ config FPGA_MGR_ZYNQ_FPGA help FPGA manager driver support for Xilinx Zynq FPGAs. +config FPGA_BRIDGE + bool "FPGA Bridge Framework" + depends on OF + help + Say Y here if you want to support bridges connected between host + processors and FPGAs or between FPGAs. + endif # FPGA endmenu diff --git a/drivers/fpga/Makefile b/drivers/fpga/Makefile index 8d83fc6..4baef00 100644 --- a/drivers/fpga/Makefile +++ b/drivers/fpga/Makefile @@ -8,3 +8,6 @@ obj-$(CONFIG_FPGA) += fpga-mgr.o # FPGA Manager Drivers obj-$(CONFIG_FPGA_MGR_SOCFPGA) += socfpga.o obj-$(CONFIG_FPGA_MGR_ZYNQ_FPGA) += zynq-fpga.o + +# FPGA Bridge Drivers +obj-$(CONFIG_FPGA_BRIDGE) += fpga-bridge.o diff --git a/drivers/fpga/fpga-bridge.c b/drivers/fpga/fpga-bridge.c new file mode 100644 index 0000000..5119d8e --- /dev/null +++ b/drivers/fpga/fpga-bridge.c @@ -0,0 +1,388 @@ +/* + * FPGA Bridge Framework Driver + * + * Copyright (C) 2013-2015 Altera Corporation, All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ +#include +#include +#include +#include +#include +#include +#include + +static DEFINE_IDA(fpga_bridge_ida); +static struct class *fpga_bridge_class; + +/* Lock for adding/removing bridges to linked lists*/ +spinlock_t bridge_list_lock; + +static int fpga_bridge_of_node_match(struct device *dev, const void *data) +{ + return dev->of_node == data; +} + +/** + * fpga_bridge_enable - Enable transactions on the bridge + * + * @bridge: FPGA bridge + * + * Return: 0 for success, error code otherwise. + */ +int fpga_bridge_enable(struct fpga_bridge *bridge) +{ + dev_dbg(&bridge->dev, "enable\n"); + + if (bridge->br_ops && bridge->br_ops->enable_set) + return bridge->br_ops->enable_set(bridge, 1); + + return 0; +} +EXPORT_SYMBOL_GPL(fpga_bridge_enable); + +/** + * fpga_bridge_disable - Disable transactions on the bridge + * + * @bridge: FPGA bridge + * + * Return: 0 for success, error code otherwise. + */ +int fpga_bridge_disable(struct fpga_bridge *bridge) +{ + dev_dbg(&bridge->dev, "disable\n"); + + if (bridge->br_ops && bridge->br_ops->enable_set) + return bridge->br_ops->enable_set(bridge, 0); + + return 0; +} +EXPORT_SYMBOL_GPL(fpga_bridge_disable); + +/** + * of_fpga_bridge_get - get an exclusive reference to a fpga bridge + * + * @np: node pointer of a FPGA bridge + * + * Return fpga_bridge struct if successful. + * Return -EBUSY if someone already has a reference to the bridge. + * Return -ENODEV if @np is not a FPGA Bridge. + */ +struct fpga_bridge *of_fpga_bridge_get(struct device_node *np) +{ + struct device *dev; + struct fpga_bridge *bridge; + int ret = -ENODEV; + + of_node_get(np); + + dev = class_find_device(fpga_bridge_class, NULL, np, + fpga_bridge_of_node_match); + if (!dev) + goto err_dev; + + bridge = to_fpga_bridge(dev); + if (!bridge) + goto err_dev; + + if (!mutex_trylock(&bridge->mutex)) { + ret = -EBUSY; + goto err_dev; + } + + if (!try_module_get(dev->parent->driver->owner)) + goto err_ll_mod; + + dev_dbg(&bridge->dev, "get\n"); + + return bridge; + +err_ll_mod: + mutex_unlock(&bridge->mutex); +err_dev: + put_device(dev); + of_node_put(np); + return ERR_PTR(ret); +} +EXPORT_SYMBOL_GPL(of_fpga_bridge_get); + +/** + * fpga_bridge_put - release a reference to a bridge + * + * @bridge: FPGA bridge + */ +void fpga_bridge_put(struct fpga_bridge *bridge) +{ + dev_dbg(&bridge->dev, "put\n"); + + module_put(bridge->dev.parent->driver->owner); + mutex_unlock(&bridge->mutex); + put_device(&bridge->dev); +} +EXPORT_SYMBOL_GPL(fpga_bridge_put); + +/** + * fpga_bridges_enable - enable bridges in a list + * @bridge_list: list of FPGA bridges + * + * Enable each bridge in the list. If list is empty, do nothing. + * + * Return 0 for success or empty bridge list; return error code otherwise. + */ +int fpga_bridges_enable(struct list_head *bridge_list) +{ + struct fpga_bridge *bridge; + struct list_head *node; + int ret; + + list_for_each(node, bridge_list) { + bridge = list_entry(node, struct fpga_bridge, node); + ret = fpga_bridge_enable(bridge); + if (ret) + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(fpga_bridges_enable); + +/** + * fpga_bridges_disable - disable bridges in a list + * + * @bridge_list: list of FPGA bridges + * + * Disable each bridge in the list. If list is empty, do nothing. + * + * Return 0 for success or empty bridge list; return error code otherwise. + */ +int fpga_bridges_disable(struct list_head *bridge_list) +{ + struct fpga_bridge *bridge; + struct list_head *node; + int ret; + + list_for_each(node, bridge_list) { + bridge = list_entry(node, struct fpga_bridge, node); + ret = fpga_bridge_disable(bridge); + if (ret) + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(fpga_bridges_disable); + +/** + * fpga_bridges_put - put bridges + * + * @bridge_list: list of FPGA bridges + * + * For each bridge in the list, put the bridge and remove it from the list. + * If list is empty, do nothing. + */ +void fpga_bridges_put(struct list_head *bridge_list) +{ + struct fpga_bridge *bridge; + struct list_head *node, *next; + unsigned long flags; + + list_for_each_safe(node, next, bridge_list) { + bridge = list_entry(node, struct fpga_bridge, node); + + fpga_bridge_put(bridge); + + spin_lock_irqsave(&bridge_list_lock, flags); + list_del(&bridge->node); + spin_unlock_irqrestore(&bridge_list_lock, flags); + } +} +EXPORT_SYMBOL_GPL(fpga_bridges_put); + +/** + * fpga_bridges_get_to_list - get a bridge, add it to a list + * + * @np: node pointer of a FPGA bridge + * @bridge_list: list of FPGA bridges + * + * Get an exclusive reference to the bridge and and it to the list. + * + * Return 0 for success, error code from of_fpga_bridge_get() othewise. + */ +int fpga_bridge_get_to_list(struct device_node *np, + struct list_head *bridge_list) +{ + struct fpga_bridge *bridge; + unsigned long flags; + + bridge = of_fpga_bridge_get(np); + if (IS_ERR(bridge)) + return PTR_ERR(bridge); + + spin_lock_irqsave(&bridge_list_lock, flags); + list_add(&bridge->node, bridge_list); + spin_unlock_irqrestore(&bridge_list_lock, flags); + + return 0; +} +EXPORT_SYMBOL_GPL(fpga_bridge_get_to_list); + +static ssize_t name_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct fpga_bridge *bridge = to_fpga_bridge(dev); + + return sprintf(buf, "%s\n", bridge->name); +} + +static ssize_t state_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct fpga_bridge *bridge = to_fpga_bridge(dev); + int enable = 1; + + if (bridge->br_ops && bridge->br_ops->enable_show) + enable = bridge->br_ops->enable_show(bridge); + + return sprintf(buf, "%s\n", enable ? "enabled" : "disabled"); +} + +static DEVICE_ATTR_RO(name); +static DEVICE_ATTR_RO(state); + +static struct attribute *fpga_bridge_attrs[] = { + &dev_attr_name.attr, + &dev_attr_state.attr, + NULL, +}; +ATTRIBUTE_GROUPS(fpga_bridge); + +/** + * fpga_bridge_register - register a fpga bridge driver + * @dev: FPGA bridge device from pdev + * @name: FPGA bridge name + * @br_ops: pointer to structure of fpga bridge ops + * @priv: FPGA bridge private data + * + * Return: 0 for success, error code otherwise. + */ +int fpga_bridge_register(struct device *dev, const char *name, + const struct fpga_bridge_ops *br_ops, void *priv) +{ + struct fpga_bridge *bridge; + int id, ret = 0; + + if (!name || !strlen(name)) { + dev_err(dev, "Attempt to register with no name!\n"); + return -EINVAL; + } + + bridge = kzalloc(sizeof(*bridge), GFP_KERNEL); + if (!bridge) + return -ENOMEM; + + id = ida_simple_get(&fpga_bridge_ida, 0, 0, GFP_KERNEL); + if (id < 0) { + ret = id; + goto error_kfree; + } + + mutex_init(&bridge->mutex); + INIT_LIST_HEAD(&bridge->node); + + bridge->name = name; + bridge->br_ops = br_ops; + bridge->priv = priv; + + device_initialize(&bridge->dev); + bridge->dev.class = fpga_bridge_class; + bridge->dev.parent = dev; + bridge->dev.of_node = dev->of_node; + bridge->dev.id = id; + dev_set_drvdata(dev, bridge); + + ret = dev_set_name(&bridge->dev, "br%d", id); + if (ret) + goto error_device; + + ret = device_add(&bridge->dev); + if (ret) + goto error_device; + + dev_info(bridge->dev.parent, "fpga bridge [%s] registered\n", + bridge->name); + + return 0; + +error_device: + ida_simple_remove(&fpga_bridge_ida, id); +error_kfree: + kfree(bridge); + + return ret; +} +EXPORT_SYMBOL_GPL(fpga_bridge_register); + +/** + * fpga_bridge_unregister - unregister a fpga bridge driver + * @dev: FPGA bridge device from pdev + */ +void fpga_bridge_unregister(struct device *dev) +{ + struct fpga_bridge *bridge = dev_get_drvdata(dev); + + /* + * If the low level driver provides a method for putting bridge into + * a desired state upon unregister, do it. + */ + if (bridge->br_ops && bridge->br_ops->fpga_bridge_remove) + bridge->br_ops->fpga_bridge_remove(bridge); + + device_unregister(&bridge->dev); +} +EXPORT_SYMBOL_GPL(fpga_bridge_unregister); + +static void fpga_bridge_dev_release(struct device *dev) +{ + struct fpga_bridge *bridge = to_fpga_bridge(dev); + + ida_simple_remove(&fpga_bridge_ida, bridge->dev.id); + kfree(bridge); +} + +static int __init fpga_bridge_dev_init(void) +{ + spin_lock_init(&bridge_list_lock); + + fpga_bridge_class = class_create(THIS_MODULE, "fpga_bridge"); + if (IS_ERR(fpga_bridge_class)) + return PTR_ERR(fpga_bridge_class); + + fpga_bridge_class->dev_groups = fpga_bridge_groups; + fpga_bridge_class->dev_release = fpga_bridge_dev_release; + + return 0; +} + +static void __exit fpga_bridge_dev_exit(void) +{ + class_destroy(fpga_bridge_class); + ida_destroy(&fpga_bridge_ida); +} + +MODULE_DESCRIPTION("FPGA Bridge Driver"); +MODULE_AUTHOR("Alan Tull "); +MODULE_LICENSE("GPL v2"); + +subsys_initcall(fpga_bridge_dev_init); +module_exit(fpga_bridge_dev_exit); diff --git a/include/linux/fpga/fpga-bridge.h b/include/linux/fpga/fpga-bridge.h new file mode 100644 index 0000000..ad8471c --- /dev/null +++ b/include/linux/fpga/fpga-bridge.h @@ -0,0 +1,56 @@ +#include + +#ifndef _LINUX_FPGA_BRIDGE_H +#define _LINUX_FPGA_BRIDGE_H + +struct fpga_bridge; + +/** + * struct fpga_bridge_ops - ops for low level FPGA bridge drivers + * @enable_show: returns the FPGA bridge's status + * @enable_set: set a FPGA bridge as enabled or disabled + * @fpga_bridge_remove: set FPGA into a specific state during driver remove + */ +struct fpga_bridge_ops { + int (*enable_show)(struct fpga_bridge *bridge); + int (*enable_set)(struct fpga_bridge *bridge, bool enable); + void (*fpga_bridge_remove)(struct fpga_bridge *bridge); +}; + +/** + * struct fpga_bridge - FPGA bridge structure + * @name: name of low level FPGA bridge + * @dev: FPGA bridge device + * @mutex: enforces exclusive reference to bridge + * @br_ops: pointer to struct of FPGA bridge ops + * @node: FPGA bridge list node + * @priv: low level driver private date + */ +struct fpga_bridge { + const char *name; + struct device dev; + struct mutex mutex; /* for exclusive reference to bridge */ + const struct fpga_bridge_ops *br_ops; + struct list_head node; + void *priv; +}; + +#define to_fpga_bridge(d) container_of(d, struct fpga_bridge, dev) + +struct fpga_bridge *of_get_fpga_bus(struct device_node *np); +struct fpga_bridge *of_fpga_bridge_get(struct device_node *node); +void fpga_bridge_put(struct fpga_bridge *bridge); +int fpga_bridge_enable(struct fpga_bridge *bridge); +int fpga_bridge_disable(struct fpga_bridge *bridge); + +int fpga_bridges_enable(struct list_head *bridge_list); +int fpga_bridges_disable(struct list_head *bridge_list); +void fpga_bridges_put(struct list_head *bridge_list); +int fpga_bridge_get_to_list(struct device_node *np, + struct list_head *bridge_list); + +int fpga_bridge_register(struct device *dev, const char *name, + const struct fpga_bridge_ops *br_ops, void *priv); +void fpga_bridge_unregister(struct device *dev); + +#endif /* _LINUX_FPGA_BRIDGE_H */ -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/