Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932255AbbKCRUA (ORCPT ); Tue, 3 Nov 2015 12:20:00 -0500 Received: from mail-bn1bon0060.outbound.protection.outlook.com ([157.56.111.60]:34111 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754955AbbKCRSV (ORCPT ); Tue, 3 Nov 2015 12:18:21 -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 v13 4/6] fpga: add fpga bridge framework Date: Tue, 3 Nov 2015 11:11:02 -0600 Message-ID: <1446570664-10293-5-git-send-email-atull@opensource.altera.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1446570664-10293-1-git-send-email-atull@opensource.altera.com> References: <1446570664-10293-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: BY1PR0201CA0009.namprd02.prod.outlook.com (25.160.191.147) To BLUPR03MB1507.namprd03.prod.outlook.com (25.163.81.25) X-Microsoft-Exchange-Diagnostics-untrusted: 1;BLUPR03MB1507;2:ceLmv7meUfB/1+A6f1RkfLjmIAY5XQGSuDtdDIQ/ozwAVww46YaViNs4Cawq9xdIkiZ5xAcRZP7rTs4zDjkjfWNaccZgHa99Z+SqU4qP7ewmsQ75aDh4x/xiq4gPnHEWY1mNo5C2RkeyI5VIIyIAFoqePQDRIlocyAJuo1SllKk=;3:/iPO5N+xEOlla98pXzhkf7MCgG0vwJcAvTiA+qcquzzNRNdPv9kAympm2oZOLaOm1IA8jipiSeke6hNdm+KDY8m5ehzhptxM6HZZeay3nCW4ilbr2RRmX72UV9OmjPPyTHVLRlviwcd0x527mUmCTg==;25:FEBYOyd0bzeJSNEGm1iWGXdpF2IS9UUVcOTqdTCpf7FphZf+/RwB0NKYt9+drtZBYa3Ntws10ba1OnloUhOecFuSj+6tDNo6c6112Yu29JJhrOPiTt0tUdOD4rvgeR74PI1y3NMPtcsXHh7E4dAWHJVsgz6tw2M/CZl7YFKYs4t2oUdBWaKzrgofnApvXGXycFyk7+uq6PTiWMn0uWc5fcFNakeUn9aTruemLBCo0Ot9ZE+A4QLApvPyeCMmW7JP2q15o5kOcagFf6Q0Ohz6YA==;20:2JPAGQ4VPybbB1vX0dwZ5o56zACCdm36mQbMoH+daFTk1WzUXBm/JSO3Lm5QK9+BcvfVcsepYyax1KdKX6NM38u8iTiWwta3d+K1C+yI8Uo3hdki7DrnnFyD9ZZK8IHhOM5J//9uc0H3YEJDsZO0hbPesTvhTQ3RqVw8AVv1sbc= 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)(8121501046)(520078)(5005006)(3002001)(10201501046);SRVR:BLUPR03MB1507;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB1507;BCL:0;PCL:0;RULEID:(601004)(2401047)(5005006)(8121501046)(520078)(3002001)(10201501046);SRVR:BLUPR03MB1425;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB1425; X-Microsoft-Exchange-Diagnostics-untrusted: 1;BLUPR03MB1507;4:RGwPMAgcWW0+xJPUKdKUxXXfmtDj2cOXGLFT3lWor9J6SXjSEPvxeN9ALpSEx00LWKmCE9I1Z7rXVYZgcuZzCLY7PtpT708GgJscOSuTnh2FfbCA5kr9Xb9v6hQB96lcoqp659BtNXWcgMbrfmM0IAQx7V+Pu6of0HFsIRsLFKTAmca6AFsswNofQYOsLYHmoDGR+LPpF2UMqy9Ehw/VOveZ7zCP/49auZvlzD9GIHTufzplZlpjqtDNDiZqIbylvrZSEQSnRb0asWiTmK+7XZKasw224Rjdf1hD52k8u2er8R559Y4tjlddu67w1XznNsMRli+Uka5V2yHHnez5gq8ANF/4eiPamLuKsNaPRPfjzMrjKuzNVC2QXcXEY5K4 X-Forefront-PRVS: 0749DC2CE6 X-Forefront-Antispam-Report-Untrusted: SFV:NSPM;SFS:(10009020)(6009001)(189002)(199003)(81156007)(53416004)(77096005)(106356001)(5004730100002)(48376002)(42186005)(47776003)(66066001)(15975445007)(122386002)(189998001)(40100003)(50466002)(97736004)(105586002)(92566002)(5007970100001)(107886002)(69596002)(5008740100001)(101416001)(4001430100002)(5001960100002)(575784001)(19580405001)(33646002)(87976001)(76176999)(50226001)(86152002)(50986999)(2950100001)(5003940100001)(86362001)(19580395003)(110136002)(229853001)(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:519mJpBzFOuoKh9Lw6xJGPeO4JZKHeGk5O3lfYa/B?= =?us-ascii?Q?pHIRcGjDoHkFu5QcQDMpYP3NtejchLiuMLY4dK7461RDBrKTo0alGxUjUPlo?= =?us-ascii?Q?ZMGJs5ZZ1tPavC25wRv5qMqJAAbcs+lL4xXXfnTznIf2eTWeMGFZ6kB2A2oJ?= =?us-ascii?Q?0q0WrP3ltcB6TnxOaccOp5JavRLYLb3ZSQRuBK3fPSFERMq1UgjdTStNKj8l?= =?us-ascii?Q?kCrs5QyWd2AAQLB0AgLGOtKQnS5lJc+Vf/NjCY1QsatVMMiEoBHNdod+CWut?= =?us-ascii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3D=3D?= X-Microsoft-Exchange-Diagnostics-untrusted: 1;BLUPR03MB1507;5:FNrwev/YuyjN9qO9GozKNUzo82tFhVaq3b/M1c4HzAbDR3oT12y904NDHtSPXGDviQiNpJIP9cpYUSOFtxXAwOvJDp6O74W31uSY+tP0Bih3WwPj+xWNaFjh1vobfVQGINVijlRxOZtzJ7VDNrT+KA==;24:0LvGNxnK5Mm2gtrU/DGKe/wdbGuo15nxGBYaVB8b2fEOu5h8vG9FilT0LrIKHS0xCgW9hGtIQr25uG6gCuTncK8yBkXRn7/fNjdmzC6qblQ=;20:eR3sbPrOwBnwxx3Wo5VdNzd0cn1PIMCOZweHo4kv5Yc9+LItKGMecjWigVVN+t14+ite0SfiBFd/rl4fBGm0yBnsHRfKytd0NMSL9vvM+bGVh+Ldi4JNeOtI1XKlPOtOAt8kqzU40IbphZNHSBLgY++XMyG7flRiHOkXWyDpu2Y= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR03MB1507 X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: BL2FFO11FD033.protection.gbl X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11FD033;1:BRa4OH4HCa0HclZNEq3BcKIkvoixMhBZ51K6KfT/2gFstJ0a3fvtPqQ1Sm65JQEt/iHgADAHBryEso1+Riq1j94H6JzFYPWaeVS46nQa9QM8yapL8svR0EkE5HfTQxDCmhE+tYAv38NmZ5EgEoQ9eC1VRgOdBOZvsxgbBg2b9gTKFvmx/U2mMAP/v2O17HLoh6GsWtznKkRqk6su8VxPjksh4cq7kbcYb55s7bQXRtjkOCsKM6bV0Nnwg3HNW1ln8a8YKArn8xkYg0WqtWjwdp2DSrH1ZDkMBu1WzgaRXdS7JRENe5TugYREjgkGuHYu1ehX1bQCIBnwaTdbxmsqTl5+/AEWQdG0iw9IjQDmroLHqZW3ZwrTNJzPo9EVd/9Lp7a0sBTTXCUFH/HCfzzT9Q== X-Forefront-Antispam-Report: CIP:66.35.236.227;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(2980300002)(1109001)(1110001)(339900001)(199003)(189002)(66066001)(87936001)(6806005)(97736004)(19580395003)(6070500001)(40100003)(106466001)(85426001)(105606002)(229853001)(53416004)(19580405001)(50986999)(47776003)(122386002)(81156007)(76176999)(86362001)(189998001)(92566002)(5003940100001)(5004730100002)(5001960100002)(11100500001)(33646002)(5008740100001)(107886002)(2950100001)(21840400001)(5007970100001)(50226001)(16796002)(15975445007)(77096005)(48376002)(86152002)(575784001)(4001430100002)(50466002)(110136002)(7099028)(7059030)(2004002);DIR:OUT;SFP:1101;SCL:1;SRVR:BLUPR03MB1425;H:sj-itexedge03.altera.priv.altera.com;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;A:0;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BLUPR03MB1425;2:2xPx6McIzxg97TLYHfJium+MhhFNMQrhl88yKHvRzviWlZJMrtf2rwC2q5FOlw309KK0yUYnDl15XUcH2tslsK+Cjo2YXaT4JDzwDr7qrRR4WqEEZUsLBxdWaH1+f6/ooJTInvZwjCyd22f+sEniv/55fm35fuyL89O/n1tiV6M=;3:MJ4SGGxQ0NZJC6+TGzz38/iPN+bdsXPYVx6d3IW6S+y5JQcrHYWYaBt8P3XFDgCvfk9mrj+GpytWzBAAP4PSqkCtTKgsJqiSME/xWg1ag2z65RFKMu87wsvf1Uz8u4R9w2qQebenq0THHCTX2qmutkqk7JWkv/iqJ8BFRqQbO/3h0Vxju0WppN9qaqto162y6ajER8eMphGPkw8hWVx4u3klz+BGy86RrGNEmS35jvs=;25:CvxGSOLnEY30fV8VjzB7I4VnyTeyyoCK5xOZwNnmWOZPt48F3Sd7qL3jgY0aOlgADY4WcjgLBeGpDUC5nD1nQUjJVMuLC+L3i+A94/yNqiOvBWQM9Ie3sLSxzUaOwdm6VdnVBGmrmxgdoC/1iHTZbh59Evzvx0sWQ7qvk3ZGpc8FyiMiwfdskw7dpDdfkjF6dcL5b96bqfw49r8KpuBOEOmulZKB/X8eBxLHlsbvjSWU4ELJm9dSkd5yqNykCHA022Jz/O5HydyxF5QRadsZKA==;20:WHN7uJy4jgQlIwhS2RUIjLo+uzsiP0DU0uMqGloH6oOlj4QQv3XocC7OtL3S3aVfhcCZMsd60LoadVg5hI+CXR6CJrGJVT7ZgH4u0H8rRsxchPUkAXQLFEsqiYA0H6eWS1o8Yqzs2yN3NoAIIlNdoiui6ntEOMJFmJoLPy8VV4M= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB1425; X-Microsoft-Exchange-Diagnostics: 1;BLUPR03MB1425;4:3UdWC2flL07UYbNHrfGj59Oqwfms4vwdT8zbiwE2h4F66SxLaWcWnUILjD+gtM+HPDIwNqGgaSuHw3nfbtsW9o8Nm5GmQn+wrdg9IgE1efNF2krklhbQuhRdUgIB/9L652jQLgIgrmkTA6zIcOkg3FT06RmbNd4IUMrO1xahTw2AWdmbu2vfNl/HzjwoxVYLYNiBZ7NYxDftkyLcCBYJUq8nY0io4gTwT8N1HcEL/wXEFfUPkg0zXo/zI46v75FxlAmak54a/V70fSVA116rY6ADdBebXwMrAXTT+bjDcfX/lRAtDEjemJreB/VENMGpHLYGvZR2FHdnAz5P1rUybDvjlo9vQQ+Bj8Uy5y32qg0nuARAppSVz0/b5/EY0jQ2 X-Forefront-PRVS: 0749DC2CE6 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BLUPR03MB1425;23:ys722UraRoikc19/2027cqQ+Ciuw+QrJLzFkAPFNN?= =?us-ascii?Q?ndoFqvYiv/n8WnL9HOIqmWsI+IVQwpvCNVhKR/2y1TzhCDiPOqStnQi/lkxj?= =?us-ascii?Q?HUBeP60Z0fgRqujSHsQOB26Ehb12JsRUa+vUctRJQf5NgVAjN1xnrXeWQh++?= =?us-ascii?Q?gdraAg/lB5ddHISonJq3bqQOi+YrB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r8sZFco3HUk7YcFBarnzR+NGUXiPR08H4XsOyodMRzUqkWL7vI?= =?us-ascii?Q?SCtUhG540jfgwv21+27kc0Kpm1wrHiKDFYeC+XJVhBKfmz60uuRDn9ibi12H?= =?us-ascii?Q?VxSLyv7QpUxxPho3T6OoeaAAAPPF2uUJSdziXpmLgm/929UDYf6m/yOxC9Sw?= =?us-ascii?Q?oFuTYoVXyCfdP5hioGOmqQJuCLyTxJZ7gW5171Z0EeovsK2ZsqeXIWOeLVsZ?= =?us-ascii?Q?UN0fUNvKECFe+BwE1q+sfvXB7I1b4l5CYnyLEySwVPrIyZB/ZRstfJBQu7TJ?= =?us-ascii?Q?uH7mA=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;BLUPR03MB1425;5:NLvvTSzAd4fuvld/U9wxQ/f/9W4NzqDo1cHIniOYmDq4vz5hSnhDKTaRHTEn2wkckSBuw/AMiasveIMf2KM47QlK7fyyDUUUwAPjyRL5wOrctIlCQ9fES74EeLiPcIyRRvfeFRFqINPkDRlgKQdMdQ==;24:CxF4e/TxykaF6UUR3Ya5Z7FHQy6GYQvZ4nzg8/q6dwv+O3mpoo1GSH5CTYAbTyHPksmQmk1dwQUwYSbBOw4h/U8Qn1ZZzOV3Ayvpo7jgPxc=;20:Y6F9rheygKZn7c73AC+6TgbDivgwk45T3WeMlISik5F4A/TjfCV+k01J2qQRrbZ1Nj20IFZEit2potJvoOKzagd0A1j1fGozpCKquJtko5msKGaGszmaYc2gOk/EtskGlFiHN6aT5Sl7bv+W6H2gEAEt5bcnBgR996WK2v2lQy8= X-OriginatorOrg: opensource.altera.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2015 17:18:18.6084 (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: BLUPR03MB1425 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 10876 Lines: 404 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 FPGAs. The functions are: * of_fpga_bridge_get * fpga_bridge_put Get/put a 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. 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 --- drivers/fpga/Kconfig | 7 ++ drivers/fpga/Makefile | 3 + drivers/fpga/fpga-bridge.c | 229 +++++++++++++++++++++++++++++++++++++++ include/linux/fpga/fpga-bridge.h | 74 +++++++++++++ 4 files changed, 313 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 5fcf60a..6383b47 100644 --- a/drivers/fpga/Kconfig +++ b/drivers/fpga/Kconfig @@ -31,6 +31,13 @@ config FPGA_MGR_ZYNQ_FPGA help FPGA manager driver support for Xilinx Zynq FPGAs. +config FPGA_BRIDGE + bool "FPGA Bridge Drivers" + 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 9b55ae0..5e9e0e1 100644 --- a/drivers/fpga/Makefile +++ b/drivers/fpga/Makefile @@ -9,5 +9,8 @@ obj-$(CONFIG_FPGA) += fpga-mgr.o 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 + # High Level Interfaces obj-$(CONFIG_SIMPLE_FPGA_BUS) += simple-fpga-bus.o diff --git a/drivers/fpga/fpga-bridge.c b/drivers/fpga/fpga-bridge.c new file mode 100644 index 0000000..14cdb7f --- /dev/null +++ b/drivers/fpga/fpga-bridge.c @@ -0,0 +1,229 @@ +/* + * fpga bridge 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 + +static DEFINE_IDA(fpga_bridge_ida); +static struct class *fpga_bridge_class; + +/** + * fpga_bridge_enable + * @bridge: fpga bridge + * + * Enable transactions on the bridge + * + * Return: 0 for success, error code otherwise. + */ +int fpga_bridge_enable(struct fpga_bridge *bridge) +{ + return bridge->br_ops->enable_set(bridge, 1); +} +EXPORT_SYMBOL_GPL(fpga_bridge_enable); + +/** + * fpga_bridge_disable + * @bridge: fpga bridge + * + * Disable transactions on the bridge + * + * Return: 0 for success, error code otherwise. + */ +int fpga_bridge_disable(struct fpga_bridge *bridge) +{ + return bridge->br_ops->enable_set(bridge, 0); +} +EXPORT_SYMBOL_GPL(fpga_bridge_disable); + +static int fpga_bridge_of_node_match(struct device *dev, const void *data) +{ + return dev->of_node == data; +} + +/** + * of_fpga_bridge_get - get an exclusive reference to a fpga bridge + * @node: device node + * + * Given a device node, get an exclusive reference to a fpga bridge. + * + * Returns a fpga manager struct or IS_ERR() condition containing errno. + */ +struct fpga_bridge *of_fpga_bridge_get(struct device_node *node) +{ + struct device *dev; + struct fpga_bridge *bridge; + int ret = -ENODEV; + + dev = class_find_device(fpga_bridge_class, NULL, node, + fpga_bridge_of_node_match); + if (!dev) + return ERR_PTR(-ENODEV); + + 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; + + return bridge; + +err_ll_mod: + mutex_unlock(&bridge->mutex); +err_dev: + put_device(dev); + return ERR_PTR(ret); +} +EXPORT_SYMBOL_GPL(of_fpga_bridge_get); + +/** + * fpga_bridge_put - release a reference to a fpga bridge + * @bridge: fpga bridge + */ +void fpga_bridge_put(struct fpga_bridge *bridge) +{ + module_put(bridge->dev.parent->driver->owner); + mutex_unlock(&bridge->mutex); + put_device(&bridge->dev); +} +EXPORT_SYMBOL_GPL(fpga_bridge_put); + +/** + * 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 on success, negative error code otherwise. + */ +int fpga_bridge_register(struct device *dev, const char *name, + struct fpga_bridge_ops *br_ops, void *priv) +{ + struct fpga_bridge *bridge; + int id, ret = 0; + + if (!br_ops || !br_ops->enable_set || !br_ops->enable_show) { + dev_err(dev, "Attempt to register without fpga_bridge_ops\n"); + return -EINVAL; + } + + 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); + + 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); + +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->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) +{ + 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_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..d6da725 --- /dev/null +++ b/include/linux/fpga/fpga-bridge.h @@ -0,0 +1,74 @@ +#include +#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 + * @priv: low level driver private date + */ +struct fpga_bridge { + const char *name; + struct device dev; + struct mutex mutex; /* for exclusive reference to bridge */ + struct fpga_bridge_ops *br_ops; + void *priv; +}; + +#define to_fpga_bridge(d) container_of(d, struct fpga_bridge, dev) + +#if defined(CONFIG_FPGA_BRIDGE) + +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); + +#else + +inline struct fpga_bridge *of_fpga_bridge_get(struct device_node *node) +{ + return 0; +} + +inline void fpga_bridge_put(struct fpga_bridge *bridge) +{ +} + +inline int fpga_bridge_enable(struct fpga_bridge *bridge) +{ + return 0; +} + +inline int fpga_bridge_disable(struct fpga_bridge *bridge) +{ + return 0; +} + +#endif /* CONFIG_FPGA_BRIDGE */ + +int fpga_bridge_register(struct device *dev, const char *name, + struct fpga_bridge_ops *br_ops, void *priv); +void fpga_bridge_unregister(struct device *dev); + +#endif /* _LINUX_FPGA_BRIDGE_H */ -- 1.9.1 -- 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/