Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753994AbbHMRpK (ORCPT ); Thu, 13 Aug 2015 13:45:10 -0400 Received: from mail-bn1bon0077.outbound.protection.outlook.com ([157.56.111.77]:24282 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753458AbbHMRnO (ORCPT ); Thu, 13 Aug 2015 13:43:14 -0400 Authentication-Results: spf=fail (sender IP is 66.35.236.227) smtp.mailfrom=opensource.altera.com; ettus.com; dkim=none (message not signed) header.d=none; Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=atull@opensource.altera.com; From: To: , , , , , CC: Moritz Fischer , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Petr Cvek , , , Alan Tull Subject: [PATCH v10 3/8] add fpga manager core Date: Thu, 13 Aug 2015 12:37:27 -0500 Message-ID: <1439487452-23977-5-git-send-email-atull@opensource.altera.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1439487452-23977-1-git-send-email-atull@opensource.altera.com> References: <1439487452-23977-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: CY1PR13CA0115.namprd13.prod.outlook.com (25.164.65.41) To BN3PR03MB1510.namprd03.prod.outlook.com (25.163.35.149) X-Microsoft-Exchange-Diagnostics-untrusted: 1;BN3PR03MB1510;2:jKRXqNZdPo/KF8b60OMKqoNu96D40Mp/43/keetXFvv2v+j1S5EsGUAOxPAQTiZdI3Ptz2ALEaHqtXDN1aqut+P0mddDKKvwoP+W3SUpUl/V0xMHKwk4XGBBome//cCY2wBCf2BJsCe6srbHLPIJ57Eacim+Vsy/s3PcU7QGSp4=;3:0+iSZtGlMbQjkQc/t+JvVPJ8Zn6ZTWe0z0EsBwTnXoy/F5/lt+ta9C6vITG9BJsdr2IK6PfecOCTuqmWOCK7ileN7MoCVKanGs6Cf6uekcB2a1/3foBbsa6foCbbxQEd0evYMhAuAL9AAN5YHURW6w==;25:X/dLkjzAm6toZHVP5FxDuFjGfkmrHui08pWb2gOFnP3Ud2StUR0xH4JvpglXfX7oVyglHVZ2jNsHM4s1UCO7Z1SCUrgDq/yi+8MnhCusGjt544BhhSqxmD6SYEVyZfvtjmIwbTG8FFUiTASzUtnMafodbSNYVPSD+JOGjsKaX2g/fZprjPi+rdVa4ZAoon5Ym4kNYWuUpZln1zwpYCfMbnfn8QPVA4DCDSAd7cvz6+9JvNWRtSHIJCfWLWeJthPlDIpkkYuLCuvo5wrnBrm6Ew==;20:tZXitG1J1et3fS4wac8JeXJMcV5FfV3UsoHuwYtk9EiQWBzAApX5uM+ZsQAghbPXxb0P0/xdAwLyTWMeamicNeW37Tmx8MA5yExrxJNVi1iP7wVP2lWBGkKvwzn2XCbet2ZirCXkiW7YjY5ozTwXG4eNE+1xogGdWMG4HI6pHSk= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN3PR03MB1510;UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN2PR03MB046; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:;UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005006)(3002001);SRVR:BN3PR03MB1510;BCL:0;PCL:0;RULEID:;SRVR:BN3PR03MB1510;BCL:0;PCL:0;RULEID:(601004)(5005006)(3002001);SRVR:SN2PR03MB046;BCL:0;PCL:0;RULEID:;SRVR:SN2PR03MB046; X-Microsoft-Exchange-Diagnostics-untrusted: 1;BN3PR03MB1510;4:4Q8B8ul0jOInynwROFygmMAvbI/SDRZJgaj8XV1HjSk/hcoyaX8mtWY9mzGHmwyvrQVGohW1Mrj2Jda3QVnLth3QGgEFE2UxKzrSTj+xPMK2DPaR1vfyhulTT/J2T4lERMtqg4TdfArpkS1m4G/ntnenQqNv/FgurxOe7QeKbu468eL0LZuFJgJCqiwTx76gJGu3B0mvDqBfIeAQ3fYsn04Hu3lgejT1ZM+yr1dsc+qjpu9xmH95lgT48I+LdzmsGaMD0be0YvhBk/j1miPpeo59uWDC7Q371eQssTvK+NY= X-Forefront-PRVS: 0667289FF8 X-Forefront-Antispam-Report-Untrusted: SFV:NSPM;SFS:(10009020)(6009001)(199003)(189002)(50986999)(86362001)(87976001)(48376002)(50466002)(77156002)(101416001)(2950100001)(76176999)(5003940100001)(122386002)(15975445007)(69596002)(53416004)(42186005)(62966003)(97736004)(40100003)(229853001)(189998001)(5001960100002)(81156007)(107886002)(50226001)(5001860100001)(86152002)(4001540100001)(64706001)(66066001)(2201001)(47776003)(5001920100001)(5001770100001)(46102003)(19580395003)(68736005)(33646002)(92566002)(77096005)(19580405001)(106356001)(105586002)(5001830100001)(7059030)(2004002)(2101003)(4001430100001);DIR:OUT;SFP:1101;SCL:1;SRVR:BN3PR03MB1510;H:linuxheads99.altera.com;FPR:;SPF:None;PTR:InfoNoRecords;A:0;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics-untrusted: =?us-ascii?Q?1;BN3PR03MB1510;23:cVsDY/ZO61MQXcBVUTS6M0ZVI8MOOSHHF3PZBj55j?= =?us-ascii?Q?7wdk8iCqJCTcVHhqjTOAGBVS8WIYhbjSTTSL9VLtnVa2anz2UbVv02Bx/weP?= =?us-ascii?Q?30DRq1EdMcdr8B4xLx0BQ2iTVRlWsY/ZcegUdpg3o6P58swMh8//JJPl9pTK?= =?us-ascii?Q?rq24zuRyzK1HZG/FNwTgJZ851ymbKX/atYR34mxk4G6PoWBVL88x+kmthpUM?= =?us-ascii?Q?W/c0IhSDEWHcUXNXYRFH0YYRh0lFk7+gEYJkI6UzTnd3gpQt6I8VD6DsJhsd?= =?us-ascii?Q?7O3P5gQW2s/CILWkQ1h9WTn7nGJoPldwYdCqCNJv0qpjWj8/+D7xf/YfHAN6?= =?us-ascii?Q?K5IIyyMlUBB7+6T2MWEonLCF00dnZueCcescQelGQg2FHZRB8DukN3j7Ru4W?= =?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3M0yeb8KZ9uTkB9DnygO?= =?us-ascii?Q?UTmUjhNqBcOtbUwiSsTkKw=3D?= X-Microsoft-Exchange-Diagnostics-untrusted: 1;BN3PR03MB1510;5:ZtybKaDhSSc/seUuhuGhKO82OG/q+u75ZXc4iFvUA2M87na4qY45xswAtdpaoCP7ns8SIIkCoHYb9h9dKLyDXg6qsE5GiZc8pQlRSZDvi1h4wax5CX1Me1DO3lz3dXJvOC8eSTJHg/I/kihHB0QQTg==;24:2ZtnMXkXG1WAYTCtx+KY5Cox0w6c+jJFjoAK/53IwyTGLtCuxAI2YOwdnTc5xKF2V9kCHCqMX6ttamy5WdOCPh/Lfd4kgtcQhSliYdcNLEQ=;20:PcdMBWMR7W39gz23f+rzILcUVVqqV/q+8SWE4xqcu59zmRcidR2DhhO5e7Yc3P5ZqPDRA7zQhRV/o3HDp6yycge+0XEmkUoDR8hXg3z8k1QuC08lTYiNXytk+FDOH3wUBnL3wDQIluTUCnEL83LX/P2j1evVXyoHizHxRT9owNE= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN3PR03MB1510 X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: BN1AFFO11FD036.protection.gbl X-Microsoft-Exchange-Diagnostics: 1;BN1AFFO11FD036;1:viGWmFHWiu7jMtE3inOJNhxnLqvICmRQNutqg0DTp4VyB5bjS59ouJ9Z8vhr9WA8fBUVi292kOivr4Cw7mDV24nzJzyUSMGzkh9vTbR3v5pYXQdTbB97ny121+VVmpxvDdqVQBRlcQi7dGcpUU2CgiJP9fkCWZp2jzhpwvFY04Vg7gSvio3NIrRYug/ZxGEc1Rm9IDcV0rIq8ZQu48gmYvDY9UmBSoy4TJdKIlkw1YQjhuQoJRQzofUQjOf3W41JXfGT3r9GBPF8B2fLblpSi9bhFDjLB3GYMTD2UI+Y83A/nXDS2QxmInq/0iTrgM4ZlvNxPwtiIcaWpObHeILwBnbDBTMW99IuqGPN9OoZ7XByb8kDQXbNvMpbyzt2UD8vYHP5CcEsSM3zNd35cxPqew== X-Forefront-Antispam-Report: CIP:66.35.236.227;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(2980300002)(3050300001)(339900001)(199003)(189002)(5001860100001)(4001540100001)(87936001)(6806004)(50226001)(86152002)(6070500001)(92566002)(50986999)(122386002)(5003940100001)(15975445007)(77156002)(5001770100001)(81156007)(5001960100002)(48376002)(5001830100001)(107886002)(50466002)(19580395003)(68736005)(2950100001)(46102003)(62966003)(76176999)(33646002)(106466001)(85426001)(2201001)(64706001)(66066001)(40100003)(97736004)(189998001)(16796002)(21840400001)(229853001)(77096005)(86362001)(53416004)(19580405001)(105606002)(47776003)(7099028)(7059030)(2004002)(2101003)(4001430100001);DIR:OUT;SFP:1101;SCL:1;SRVR:SN2PR03MB046;H:sj-itexedge03.altera.priv.altera.com;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;A:0;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;SN2PR03MB046;2:ZBwEPnJ2BwVxkarLmWLTlTQTYi6jPO2efmfE74gNYL0lwOObt+qiksGBxqqtwkMa1BA0cNqRGDwEy8Rf0VmjZXJ5cwZ8BkDUK2hq9sehE9P8g6kKQIX4LLqH/lUriZ8jU4S37h/OCzdMfcdOlf3gN/VVC1VPfIGoDrwvdJmJLdw=;3:haSTzgxFYvVdLZbrlHjMQD7oFmiAq9Kwv7Hs6e+Ly0M2F/oofNgfp8Ml3QTxnftzkIObrSmj7M8xPbf6nj1u6mU3m38n1Dw9O1aDOztuJlmS9+ikVWjKFMbsKZOqDAil+2l+v9/pUPDJjLV6X1LSwl3igzRduPkf6qbUU9PAGJp/jDDVm9VFz6JevdyuGLtUmIMB2ifQalF3cwK78XQcHM3wPbof7Z6TixOFmDUVg9k=;25:QIgmu/NmMRfO3Ivjk3E2wXmJvmNA98YisD5MBNj5+KuDHinPMN3lPGwfaOEojf6y9iCxnUCBls3vMgsEROsGoOykehIY8uFr4IzFdrROWtesIRM8RWHITYTkBrgBotR6QjU9dNiWf4vktgemzb8Szyl4rgyUzPYqDQia1HfojTIg5xmw8PZUeEGHQirkikunGz9FqcysW78+0MyJUFKdli5InAkI40nZHFe1bXOiWgfJdXNc0y4Mm/m2NI793xCXbgp2zJocNdWGKu2SS1q5RA==;20:0HhfPlV3l/1M/C0CTnGxGA9bvqV1pfnohsUAN2hMeHoQVE5CKHyoPkqyTUbpyCVRjz8MibPw4Sowj/AtE/58o18+W8BFnF8JnlqzfxftS8HNUDBxbgKts84akm0Ejuysc1wARL6Aak8kQ0f9HsBxM9vnYNYbVLzWh/X8PTdqMrM= SN2PR03MB046: X-MS-Exchange-Organization-RulesExecuted X-Microsoft-Exchange-Diagnostics: 1;SN2PR03MB046;4:i7Ex96YdV8VC8iM+wQWkdnOfRGwVv4B6sRGW8tsiA5n+U/SFSTY5/u7iylQUs5CVnjhTYOxg2XYUMSNtw/pnA07kNCR24LukSGBjCfuPUjVOgiWvK3wA0kvtfHJg9qTu43TOVdhbha9YTfcB6jirZWX/JpRTeZp5Ayevh8qOISK6e1z6QETyhLB4k2a/H95+gajvmpEYTYipk4gVlH75XLzHE6L4+bmNGLLT8k++qflfFpnQrxa/beG1M1HBrvIUVaDE0zLTP+XrcsFsPxbYcyF+5fmBRLyOa2lAqpEpYK0= X-Forefront-PRVS: 0667289FF8 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;SN2PR03MB046;23:3zYGDlZFtaafXYS+0qIj81/1dyjOIA3B8bctKsaP3A?= =?us-ascii?Q?xydYq1ygLfeRmtz9Wao7rITWRpCZ1B+suksO6LZQB+oZJTYg5+Gv9+Y4MYee?= =?us-ascii?Q?7o5CftR1i0foILwhCH0dUFvjKo/oe+7u02XsYyQN/QpdSM2Ods5/3FgqI4bj?= =?us-ascii?Q?tS9VVr0419t7Mf0PWEtqDFB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?us-ascii?Q?h0uHNJ8uQqbnZR5n5RIVOW1Lsv1l9J+Agc2M3Olw9J+ZZcUjjP3jvZIJC1gr?= =?us-ascii?Q?DGGNVecrUnRV043QweHPNeOWJiXkzJpOp0nOq+BRfdwxpomauivhqbJyn5N8?= =?us-ascii?Q?nbirCukKIO/WOuU5nn4RKpOuj0taxfPmGlOiJdJBdF0oF4o6zE450W6aXLgF?= =?us-ascii?Q?6EzHTz50QanCffuUEO/xY1JgDjLVqxmJCASpQ8hFzliTo9iAf+SUwUxXv7e0?= =?us-ascii?Q?e2Izx0VfmR15IXvA8QaBcZ3ZTjwYOGtx0WxK13TeqEmbTKR+60F4xzsI7rAA?= =?us-ascii?Q?wAURCNAgd52mHDFl2y9m48384e2KjGLb7QrpgVxteGFtyG+B+ayvbyJSawM+?= =?us-ascii?Q?AtVK2CSw=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;SN2PR03MB046;5:PLUPmIbxRdNIlbYnYRANIRbbFd6L4shEQyJ4+eODCs9MrR/x3iY5oOPMH5PhAP03JWLIKIYgWw0oH9YGbZSs5jdwVKB3BGJE1BD2BK0qqFESyrDsEbvMveyZTx6w+U06hUSXoYg7qD9ZcIObaFUQRA==;24:Cn8SFQEz7JyZBWK16VTQwEco47HxlzttvR0L/p8p63NJ2dBXv9Zm1Bc3wZaeeZbftgT8tCfdsmGqEPCj4a6r0f+bcWdsZx48YGFn6UFXwV4=;20:vfgVCUpIBgf/EdKS1lK6Azv+vkHerdQTBJzuftZ+pwbIj1J/AlWr6RElpqauHRP0l53h4YiyKPmMY5XzJ+4U6GxPyjKYmzU5Ryo8wa6zeOazezmd/IsSPpnq7gq6CvWhddlPhy+PzOzmNMYpeu2cr1sxPUmbMkXs3P6XZXMDKVY= X-OriginatorOrg: opensource.altera.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Aug 2015 17:43:09.1812 (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: SN2PR03MB046 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 20213 Lines: 695 From: Alan Tull API to support programming FPGA. The following functions are exported as GPL: * fpga_mgr_buf_load Load fpga from image in buffer * fpga_mgr_firmware_load Request firmware and load it to the FPGA. * fpga_mgr_register * fpga_mgr_unregister FPGA device drivers can be added by calling fpga_mgr_register() to register a set of fpga_manager_ops to do device specific stuff. * of_fpga_mgr_get * fpga_mgr_put Get/put a reference to a fpga manager. The following sysfs files are created: * /sys/class/fpga_manager//name Name of low level driver. * /sys/class/fpga_manager//state State of fpga manager Signed-off-by: Alan Tull Acked-by: Michal Simek --- v2: s/mangager/manager/ check for invalid request_nr add fpga reset interface rework the state code remove FPGA_MGR_FAIL flag add _ERR states to fpga manager states enum low level state op now returns a state enum value initialize framework state from driver state op remove unused fpga read stuff merge sysfs.c into fpga-mgr.c move suspend/resume from bus.c to fpga-mgr.c v3: Add struct device to fpga_manager (not as a pointer) Add to_fpga_manager Don't get irq in fpga-mgr.c (let low level driver do it) remove from struct fpga_manager: nr, np, parent get rid of fpga_mgr_get_new_minor() simplify fpga_manager_register: reorder parameters use dev instead of pdev get rid of code that used to make more sense when this was a char driver, don't alloc_chrdev_region use a mutex instead of flags v4: Move to drivers/staging v5: Make some things be static Kconfig: add 'if FPGA' Makefile: s/fpga-mgr-core.o/fpga-mgr.o/ clean up includes use enum fpga_mgr_states instead of int static const char *state_str use DEVICE_ATTR_RO/RW/WO and ATTRIBUTE_GROUPS return -EINVAL instead of BUG_ON move ida_simple_get after kzalloc clean up fpga_mgr_remove fpga-mgr.h: remove '#if IS_ENABLED(CONFIG_FPGA)' add kernel-doc documentation Move header to new include/linux/fpga folder static const struct fpga_mgr_ops dev_info msg simplified v6: no statically allocated string for image_name kernel doc fixes changes regarding enabling SYSFS for fpga mgr Makefile cleanup v7: no change in this patch for v7 of the patchset v8: no change in this patch for v8 of the patchset v9: remove writable attributes 'firmware' and 'reset' remove suspend/resume support for now remove list of fpga managers; use class device iterators instead simplify locking by giving out only one ref exclusively add device tree support add flags par down API into fewer functions update copyright year rename some functions for clarity clean up unnecessary #includes add some error messages write_init may need to look at buffer header, so add to params v10: Make this a tristate in Kconfig pass flags parameter to write_complete use BIT(0) in macro move to drivers/fpga fpga_manager_get/put call module_try_get/module_put --- drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/fpga/Kconfig | 14 ++ drivers/fpga/Makefile | 8 + drivers/fpga/fpga-mgr.c | 381 +++++++++++++++++++++++++++++++++++++++++ include/linux/fpga/fpga-mgr.h | 127 ++++++++++++++ 6 files changed, 533 insertions(+) create mode 100644 drivers/fpga/Kconfig create mode 100644 drivers/fpga/Makefile create mode 100644 drivers/fpga/fpga-mgr.c create mode 100644 include/linux/fpga/fpga-mgr.h diff --git a/drivers/Kconfig b/drivers/Kconfig index 6e973b8..2683346 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -184,4 +184,6 @@ source "drivers/android/Kconfig" source "drivers/nvdimm/Kconfig" +source "drivers/fpga/Kconfig" + endmenu diff --git a/drivers/Makefile b/drivers/Makefile index b64b49f..832a6e0 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -165,3 +165,4 @@ obj-$(CONFIG_RAS) += ras/ obj-$(CONFIG_THUNDERBOLT) += thunderbolt/ obj-$(CONFIG_CORESIGHT) += hwtracing/coresight/ obj-$(CONFIG_ANDROID) += android/ +obj-$(CONFIG_FPGA) += fpga/ diff --git a/drivers/fpga/Kconfig b/drivers/fpga/Kconfig new file mode 100644 index 0000000..f1f1f6d --- /dev/null +++ b/drivers/fpga/Kconfig @@ -0,0 +1,14 @@ +# +# FPGA framework configuration +# + +menu "FPGA Configuration Support" + +config FPGA + tristate "FPGA Configuration Framework" + help + Say Y here if you want support for configuring FPGAs from the + kernel. The FPGA framework adds a FPGA manager class and FPGA + manager drivers. + +endmenu diff --git a/drivers/fpga/Makefile b/drivers/fpga/Makefile new file mode 100644 index 0000000..3313c52 --- /dev/null +++ b/drivers/fpga/Makefile @@ -0,0 +1,8 @@ +# +# Makefile for the fpga framework and fpga manager drivers. +# + +# Core FPGA Manager Framework +obj-$(CONFIG_FPGA) += fpga-mgr.o + +# FPGA Manager Drivers diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c new file mode 100644 index 0000000..5d900bf --- /dev/null +++ b/drivers/fpga/fpga-mgr.c @@ -0,0 +1,381 @@ +/* + * FPGA Manager Core + * + * Copyright (C) 2013-2015 Altera Corporation + * + * With code from the mailing list: + * Copyright (C) 2013 Xilinx, Inc. + * + * 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_mgr_ida); +static struct class *fpga_mgr_class; + +/** + * fpga_mgr_buf_load - load fpga from image in buffer + * @mgr: fpga manager + * @flags: flags setting fpga confuration modes + * @buf: buffer contain fpga image + * @count: byte count of buf + * + * Step the low level fpga manager through the device-specific steps of getting + * an FPGA ready to be configured, writing the image to it, then doing whatever + * post-configuration steps necessary. + * + * Return: 0 on success, negative error code otherwise. + */ +int fpga_mgr_buf_load(struct fpga_manager *mgr, u32 flags, const char *buf, + size_t count) +{ + struct device *dev = &mgr->dev; + int ret; + + if (!mgr) + return -ENODEV; + + /* + * 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 receive an FPGA image. + */ + mgr->state = FPGA_MGR_STATE_WRITE_INIT; + ret = mgr->mops->write_init(mgr, flags, buf, count); + if (ret) { + dev_err(dev, "Error preparing FPGA for writing\n"); + mgr->state = FPGA_MGR_STATE_WRITE_INIT_ERR; + return ret; + } + + /* + * Write the FPGA image to the FPGA. + */ + mgr->state = FPGA_MGR_STATE_WRITE; + ret = mgr->mops->write(mgr, buf, count); + if (ret) { + dev_err(dev, "Error while writing image data to FPGA\n"); + mgr->state = FPGA_MGR_STATE_WRITE_ERR; + return ret; + } + + /* + * After all the FPGA image has been written, do the device specific + * steps to finish and set the FPGA into operating mode. + */ + mgr->state = FPGA_MGR_STATE_WRITE_COMPLETE; + ret = mgr->mops->write_complete(mgr, flags); + if (ret) { + dev_err(dev, "Error after writing image data to FPGA\n"); + mgr->state = FPGA_MGR_STATE_WRITE_COMPLETE_ERR; + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(fpga_mgr_buf_load); + +/** + * fpga_mgr_firmware_load - request firmware and load to fpga + * @mgr: fpga manager + * @flags: flags setting fpga confuration modes + * @image_name: name of image file on the firmware search path + * + * Request an FPGA image using the firmware class, then write out to the FPGA. + * Update the state before each step to provide info on what step failed if + * there is a failure. + * + * Return: 0 on success, negative error code otherwise. + */ +int fpga_mgr_firmware_load(struct fpga_manager *mgr, u32 flags, + const char *image_name) +{ + struct device *dev = &mgr->dev; + const struct firmware *fw; + int ret; + + if (!mgr) + return -ENODEV; + + dev_info(dev, "writing %s to %s\n", image_name, mgr->name); + + mgr->state = FPGA_MGR_STATE_FIRMWARE_REQ; + + ret = request_firmware(&fw, image_name, dev); + if (ret) { + mgr->state = FPGA_MGR_STATE_FIRMWARE_REQ_ERR; + dev_err(dev, "Error requesting firmware %s\n", image_name); + return ret; + } + + ret = fpga_mgr_buf_load(mgr, flags, fw->data, fw->size); + if (ret) + return ret; + + release_firmware(fw); + + return 0; +} +EXPORT_SYMBOL_GPL(fpga_mgr_firmware_load); + +static const char * const state_str[] = { + [FPGA_MGR_STATE_UNKNOWN] = "unknown", + [FPGA_MGR_STATE_POWER_OFF] = "power off", + [FPGA_MGR_STATE_POWER_UP] = "power up", + [FPGA_MGR_STATE_RESET] = "reset", + + /* requesting FPGA image from firmware */ + [FPGA_MGR_STATE_FIRMWARE_REQ] = "firmware request", + [FPGA_MGR_STATE_FIRMWARE_REQ_ERR] = "firmware request error", + + /* Preparing FPGA to receive image */ + [FPGA_MGR_STATE_WRITE_INIT] = "write init", + [FPGA_MGR_STATE_WRITE_INIT_ERR] = "write init error", + + /* Writing image to FPGA */ + [FPGA_MGR_STATE_WRITE] = "write", + [FPGA_MGR_STATE_WRITE_ERR] = "write error", + + /* Finishing configuration after image has been written */ + [FPGA_MGR_STATE_WRITE_COMPLETE] = "write complete", + [FPGA_MGR_STATE_WRITE_COMPLETE_ERR] = "write complete error", + + /* FPGA reports to be in normal operating mode */ + [FPGA_MGR_STATE_OPERATING] = "operating", +}; + +static ssize_t name_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct fpga_manager *mgr = to_fpga_manager(dev); + + return sprintf(buf, "%s\n", mgr->name); +} + +static ssize_t state_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct fpga_manager *mgr = to_fpga_manager(dev); + + return sprintf(buf, "%s\n", state_str[mgr->state]); +} + +static DEVICE_ATTR_RO(name); +static DEVICE_ATTR_RO(state); + +static struct attribute *fpga_mgr_attrs[] = { + &dev_attr_name.attr, + &dev_attr_state.attr, + NULL, +}; +ATTRIBUTE_GROUPS(fpga_mgr); + +static int fpga_mgr_of_node_match(struct device *dev, const void *data) +{ + return dev->of_node == data; +} + +/** + * of_fpga_mgr_get - get an exclusive reference to a fpga mgr + * @node: device node + * + * Given a device node, get an exclusive reference to a fpga mgr. + * + * Return: fpga manager struct or IS_ERR() condition containing error code. + */ +struct fpga_manager *of_fpga_mgr_get(struct device_node *node) +{ + struct fpga_manager *mgr; + struct device *dev; + + if (!node) + return ERR_PTR(-EINVAL); + + dev = class_find_device(fpga_mgr_class, NULL, node, + fpga_mgr_of_node_match); + if (!dev) + return ERR_PTR(-ENODEV); + + mgr = to_fpga_manager(dev); + put_device(dev); + if (!mgr) + return ERR_PTR(-ENODEV); + + /* Get exclusive use of fpga manager */ + if (!mutex_trylock(&mgr->ref_mutex)) + return ERR_PTR(-EBUSY); + + if (!try_module_get(THIS_MODULE)) { + mutex_unlock(&mgr->ref_mutex); + return ERR_PTR(-ENODEV); + } + + return mgr; +} +EXPORT_SYMBOL_GPL(of_fpga_mgr_get); + +/** + * fpga_mgr_put - release a reference to a fpga manager + * @mgr: fpga manager structure + */ +void fpga_mgr_put(struct fpga_manager *mgr) +{ + if (mgr) { + module_put(THIS_MODULE); + mutex_unlock(&mgr->ref_mutex); + } +} +EXPORT_SYMBOL_GPL(fpga_mgr_put); + +/** + * fpga_mgr_register - register a low level fpga manager driver + * @dev: fpga manager device from pdev + * @name: fpga manager name + * @mops: pointer to structure of fpga manager ops + * @priv: fpga manager private data + * + * Return: 0 on success, negative error code otherwise. + */ +int fpga_mgr_register(struct device *dev, const char *name, + const struct fpga_manager_ops *mops, + void *priv) +{ + struct fpga_manager *mgr; + const char *dt_label; + int id, ret; + + if (!mops || !mops->write_init || !mops->write || + !mops->write_complete || !mops->state) { + dev_err(dev, "Attempt to register without fpga_manager_ops\n"); + return -EINVAL; + } + + if (!name || !strlen(name)) { + dev_err(dev, "Attempt to register with no name!\n"); + return -EINVAL; + } + + mgr = kzalloc(sizeof(*mgr), GFP_KERNEL); + if (!mgr) + return -ENOMEM; + + id = ida_simple_get(&fpga_mgr_ida, 0, 0, GFP_KERNEL); + if (id < 0) { + ret = id; + goto error_kfree; + } + + mutex_init(&mgr->ref_mutex); + + mgr->name = name; + mgr->mops = mops; + mgr->priv = priv; + + /* + * Initialize framework state by requesting low level driver read state + * from device. FPGA may be in reset mode or may have been programmed + * by bootloader or EEPROM. + */ + mgr->state = mgr->mops->state(mgr); + + device_initialize(&mgr->dev); + mgr->dev.class = fpga_mgr_class; + mgr->dev.parent = dev; + mgr->dev.of_node = dev->of_node; + mgr->dev.id = id; + dev_set_drvdata(dev, mgr); + + dt_label = of_get_property(mgr->dev.of_node, "label", NULL); + if (dt_label) + ret = dev_set_name(&mgr->dev, "%s", dt_label); + else + ret = dev_set_name(&mgr->dev, "fpga%d", id); + + ret = device_add(&mgr->dev); + if (ret) + goto error_device; + + dev_info(&mgr->dev, "%s registered\n", mgr->name); + + return 0; + +error_device: + ida_simple_remove(&fpga_mgr_ida, id); +error_kfree: + kfree(mgr); + + return ret; +} +EXPORT_SYMBOL_GPL(fpga_mgr_register); + +/** + * fpga_mgr_unregister - unregister a low level fpga manager driver + * @dev: fpga manager device from pdev + */ +void fpga_mgr_unregister(struct device *dev) +{ + struct fpga_manager *mgr = dev_get_drvdata(dev); + + dev_info(&mgr->dev, "%s %s\n", __func__, mgr->name); + + /* + * If the low level driver provides a method for putting fpga into + * a desired state upon unregister, do it. + */ + if (mgr->mops->fpga_remove) + mgr->mops->fpga_remove(mgr); + + device_unregister(&mgr->dev); +} +EXPORT_SYMBOL_GPL(fpga_mgr_unregister); + +static void fpga_mgr_dev_release(struct device *dev) +{ + struct fpga_manager *mgr = to_fpga_manager(dev); + + ida_simple_remove(&fpga_mgr_ida, mgr->dev.id); + kfree(mgr); +} + +static int __init fpga_mgr_class_init(void) +{ + pr_info("FPGA manager framework\n"); + + fpga_mgr_class = class_create(THIS_MODULE, "fpga_manager"); + if (IS_ERR(fpga_mgr_class)) + return PTR_ERR(fpga_mgr_class); + + fpga_mgr_class->dev_groups = fpga_mgr_groups; + fpga_mgr_class->dev_release = fpga_mgr_dev_release; + + return 0; +} + +static void __exit fpga_mgr_class_exit(void) +{ + class_destroy(fpga_mgr_class); + ida_destroy(&fpga_mgr_ida); +} + +MODULE_AUTHOR("Alan Tull "); +MODULE_DESCRIPTION("FPGA manager framework"); +MODULE_LICENSE("GPL v2"); + +subsys_initcall(fpga_mgr_class_init); +module_exit(fpga_mgr_class_exit); diff --git a/include/linux/fpga/fpga-mgr.h b/include/linux/fpga/fpga-mgr.h new file mode 100644 index 0000000..0940bf4 --- /dev/null +++ b/include/linux/fpga/fpga-mgr.h @@ -0,0 +1,127 @@ +/* + * FPGA Framework + * + * Copyright (C) 2013-2015 Altera Corporation + * + * 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 + +#ifndef _LINUX_FPGA_MGR_H +#define _LINUX_FPGA_MGR_H + +struct fpga_manager; + +/** + * enum fpga_mgr_states - fpga framework states + * @FPGA_MGR_STATE_UNKNOWN: can't determine state + * @FPGA_MGR_STATE_POWER_OFF: FPGA power is off + * @FPGA_MGR_STATE_POWER_UP: FPGA reports power is up + * @FPGA_MGR_STATE_RESET: FPGA in reset state + * @FPGA_MGR_STATE_FIRMWARE_REQ: firmware request in progress + * @FPGA_MGR_STATE_FIRMWARE_REQ_ERR: firmware request failed + * @FPGA_MGR_STATE_WRITE_INIT: preparing FPGA for programming + * @FPGA_MGR_STATE_WRITE_INIT_ERR: Error during WRITE_INIT stage + * @FPGA_MGR_STATE_WRITE: writing image to FPGA + * @FPGA_MGR_STATE_WRITE_ERR: Error while writing FPGA + * @FPGA_MGR_STATE_WRITE_COMPLETE: Doing post programming steps + * @FPGA_MGR_STATE_WRITE_COMPLETE_ERR: Error during WRITE_COMPLETE + * @FPGA_MGR_STATE_OPERATING: FPGA is programmed and operating + */ +enum fpga_mgr_states { + /* default FPGA states */ + FPGA_MGR_STATE_UNKNOWN, + FPGA_MGR_STATE_POWER_OFF, + FPGA_MGR_STATE_POWER_UP, + FPGA_MGR_STATE_RESET, + + /* getting an image for loading */ + FPGA_MGR_STATE_FIRMWARE_REQ, + FPGA_MGR_STATE_FIRMWARE_REQ_ERR, + + /* write sequence: init, write, complete */ + FPGA_MGR_STATE_WRITE_INIT, + FPGA_MGR_STATE_WRITE_INIT_ERR, + FPGA_MGR_STATE_WRITE, + FPGA_MGR_STATE_WRITE_ERR, + FPGA_MGR_STATE_WRITE_COMPLETE, + FPGA_MGR_STATE_WRITE_COMPLETE_ERR, + + /* fpga is programmed and operating */ + FPGA_MGR_STATE_OPERATING, +}; + +/* + * FPGA Manager flags + * FPGA_MGR_PARTIAL_RECONFIG: do partial reconfiguration if supported + */ +#define FPGA_MGR_PARTIAL_RECONFIG BIT(0) + +/** + * struct fpga_manager_ops - ops for low level fpga manager drivers + * @state: returns an enum value of the FPGA's state + * @write_init: prepare the FPGA to receive confuration data + * @write: write count bytes of configuration data to the FPGA + * @write_complete: set FPGA to operating state after writing is done + * @fpga_remove: optional: Set FPGA into a specific state during driver remove + * + * fpga_manager_ops are the low level functions implemented by a specific + * fpga manager driver. The optional ones are tested for NULL before being + * called, so leaving them out is fine. + */ +struct fpga_manager_ops { + enum fpga_mgr_states (*state)(struct fpga_manager *mgr); + int (*write_init)(struct fpga_manager *mgr, u32 flags, + const char *buf, size_t count); + int (*write)(struct fpga_manager *mgr, const char *buf, size_t count); + int (*write_complete)(struct fpga_manager *mgr, u32 flags); + void (*fpga_remove)(struct fpga_manager *mgr); +}; + +/** + * struct fpga_manager - fpga manager structure + * @name: name of low level fpga manager + * @dev: fpga manager device + * @ref_mutex: only allows one reference to fpga manager + * @state: state of fpga manager + * @mops: pointer to struct of fpga manager ops + * @priv: low level driver private date + */ +struct fpga_manager { + const char *name; + struct device dev; + struct mutex ref_mutex; + enum fpga_mgr_states state; + const struct fpga_manager_ops *mops; + void *priv; +}; + +#define to_fpga_manager(d) container_of(d, struct fpga_manager, dev) + +int fpga_mgr_buf_load(struct fpga_manager *mgr, u32 flags, + const char *buf, size_t count); + +int fpga_mgr_firmware_load(struct fpga_manager *mgr, u32 flags, + const char *image_name); + +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); + +void fpga_mgr_unregister(struct device *dev); + +#endif /*_LINUX_FPGA_MGR_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/