Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752627AbbGQQMh (ORCPT ); Fri, 17 Jul 2015 12:12:37 -0400 Received: from mail-bl2on0077.outbound.protection.outlook.com ([65.55.169.77]:23495 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752337AbbGQQLj (ORCPT ); Fri, 17 Jul 2015 12:11:39 -0400 Authentication-Results: spf=fail (sender IP is 66.35.236.227) smtp.mailfrom=opensource.altera.com; vger.kernel.org; dkim=none (message not signed) header.d=none; Authentication-Results: linuxfoundation.org; dkim=none (message not signed) header.d=none; From: To: , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Petr Cvek , , , , Alan Tull Subject: [PATCH v9 5/7] staging: fpga manager core Date: Fri, 17 Jul 2015 10:51:15 -0500 Message-ID: <1437148277-5405-6-git-send-email-atull@opensource.altera.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1437148277-5405-1-git-send-email-atull@opensource.altera.com> References: <1437148277-5405-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: DM2PR21CA0039.namprd21.prod.outlook.com (25.161.137.177) To CY1PR03MB1519.namprd03.prod.outlook.com (25.163.17.25) X-Microsoft-Exchange-Diagnostics-untrusted: 1;CY1PR03MB1519;2:wrQ7aO8igxK1yrrpBg2MflI+j9QX1CZ1F8eMJ1G517LOQuVgR+TlQNALsmYLaIfR;3:td8D8vlDXuU1gzQCN5OPJh5U9GeqFp5OJT1eS/FmF149Vz31p68wlwBrH7Eu+OzAFd95liJxRwlnF8Fk0L5tDSZI6DprTnip/tLC6PHrQrjtc8lnS18jH0j4SzJY8C18mYob5xmoF2ns0iAqBRvVrg==;25:f/qt/KMRFDRFI82CCg3JD/C1+AICfSQ3jpUCOtT6yKAhE4/t9hnv43C0tWGrvnzZ6GVdU6F544sIqLrigEkezw/xrcedYa7I4qk6KyoTEGDS/Ca7EUAvdDw8c8gJGEcxyhaiBnEJPqxKYgHLS9JI9JNxhvSIpxDbpQrv4K4Gc8oYyf0Ra0eoS5LTPayfjjsX19FGDsdED+URpU2Wb34JaUC3XCZZHoGt9PdOC4EsPljQ0I3XhwQ+qIAGN68xHXsDIWtOjClopMPTZHtrUkp4BA==;20:nYp5InJVpdObMLxBqHtdULx3x6GlDQRMzAFmgKIL0f0PMulDd5ImcAHYszu0b0168iV01p6A+DYdMmXpPH0ecai3WfEAd+5gDMdI6PPOGGnn5f1LGb0SAdmZh3L4bdCIYBMYDA0xX+FQL1s+yDuQpHptQ6oHKxOqkkqVZ3YTqEA= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR03MB1519;UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN1PR03MB233; CY1PR03MB1519: X-MS-Exchange-Organization-RulesExecuted 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:CY1PR03MB1519;BCL:0;PCL:0;RULEID:;SRVR:CY1PR03MB1519;BCL:0;PCL:0;RULEID:(601004)(5005006)(3002001);SRVR:BN1PR03MB233;BCL:0;PCL:0;RULEID:;SRVR:BN1PR03MB233; X-Microsoft-Exchange-Diagnostics-untrusted: 1;CY1PR03MB1519;4:X4LNdI+sDwTljmcEyhUu+2EavwC+klBYTLPei3c9qQHuBNQ5zrr7L/vJs3MV8WujdkwZRfwm1KCcWeIKZvxnNKUtqvReQizKMOi4MX1CA8bKQf57mXrtx3WQW81rZ8SNIUKndGE2FKE77X4hlLViSuGAn2u+e8d7Kl9a3EhDBU+wDOEDmXpZLoe8OxrVzgXO5k+BYMtBu3dKodim0SuEuyN6zSwH+68bj7BqPbZqVhoA4aTSet1FP3rfRI/36BSGLJPP2nqKNVQ6xef67bBx+cj1Apwmki7jZ7EnyAeI0r8= X-Forefront-PRVS: 06400060E1 X-Forefront-Antispam-Report-Untrusted: SFV:NSPM;SFS:(10009020)(6009001)(42186005)(19580405001)(19580395003)(229853001)(53416004)(46102003)(87976001)(122386002)(2201001)(86362001)(86152002)(33646002)(62966003)(50466002)(77156002)(92566002)(15975445007)(5001960100002)(2950100001)(48376002)(50226001)(107886002)(77096005)(5001770100001)(76176999)(47776003)(50986999)(5001920100001)(5003940100001)(189998001)(7059030)(4001430100001)(2101003);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR03MB1519;H:linuxheads99.altera.com;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics-untrusted: 1;CY1PR03MB1519;23:5wCWIKrz6IQsIj3ZUnsA6FWf5DITE5p+d7HolqGXj6CsCmNFlmuzQpbLElxrE+feDGK5+BBz7n3//MtRgzOcyJex+CrN0Pv1B0D5jpnJjvTnxukBfdK2EgfSW0fluwbzI4grEwHl4cSaY4QuwwARJovGk4oQ8RIqjI3h4S8cgYW7eRnt4mZa7j5Jh53n6mXKzdJfpfE2YEOme2YuH4OtinIJ1sBlXpWUIqbzqlDHqKIMk7YkYUy9NvCJxMVXrS5XNdz8fdUofjZm5a7ul0eJBqJBfzMB+xp83Hf/MzUNkRR55g6l52jdnN0nzT2nMWfNEfbau4qDu9wuwv4YRPGXDt1YQaBffXx6IyfIyYwricuEUnd8OItJjecmTDq3+UN1vrpDEE/LE3j2soB7SVuNmmxL7A95kkDITGnxtQvvA734Zf63nBCGmf3XkPpfP0ZLqB9HWR9S5IT0rjW+0vJT0yO2/22bq8vtYm4W5GLtetnBbApBuzDIcmp8iXs05PvrNRxFJIC9Un6AuestgLg/TVVr8KXWsamHz/Owk97zF7BaduK+cWyFTCeuFjDqbZD+N9ZWiUMwX2oJiTaPrxFZINnzoPaat2ZjjwxiYo/ekLVcUgl1TK6z8kSLYkS5QOnZstAi+0D5ohR41tcA/3GX+tVFE4Sw2/grQze0JSboBtrfxMzxePNPz51sSAGWmtbsWanDCoiIN6m9fLu4UYKd0QC0hzZTLVYcxPX+Ey706zIwziza3Dj9iDnH85qjfB9Yip861yFlC0nbsm5yaVaJPtdz6nTU09SP1O/wVbpXB+LfmaHHrFGUguwfHVT6LeHNwlhnnwypLAQYLVLU9iXhb++fahmWNQdhYOaa1YzLWD0ERQ/gTaaPb7mOLkZ8pDDFu2MHK4mDdaChPdqhou6ENdPtmp94NPRx7//sHekHg4DMeqJkmChbKxdYjFYXo2J0 X-Microsoft-Exchange-Diagnostics-untrusted: 1;CY1PR03MB1519;5:n8FQPMeA5LicpCwJMYRVuPF9MJCMYmrDMSlIKIBvWYnmccIONCzUmGVy49oQJMdl9wlz3cy1WtCAuBgsJ12GQzocywfFEm1ezC1Pyp/hbaDUEqeWBUzECBMUYuC88EUpc7r4d75jUq5imTWL+PG7eA==;24:A/7aceastYzXyKAbbE7uws+kHSJ4Z5pJn1mK/mQN6tHtwIJ7D2No2h+zc4c+JgKyL/gg48b3w5jaM1zZFyzCFOPDtX/aH5YBK4RzcyfIhjk=;20:wviBaNn1xUNqivw+Jz9Xe2IDVWeGTuFedi0xvmlYB9rpia5qCG33s8BTBJbHRFvvlHDujmLKL3nuQykDXVRMEI8+dMz9BWmPwDCdCyxhzGb7Y9RUzPKXPBzb0wUWhVmEKCOMBGJPmtqUzztRCywTBzrlMlqCzqhJdSHtfe8jb8Q= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR03MB1519 X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: BN1AFFO11FD021.protection.gbl X-Microsoft-Exchange-Diagnostics: 1;BN1AFFO11FD021;1:qYTXkn3QYmFO1T6XVxc89am2VggT895P2IqwbrWqmOWIYurWtuQqKgOtknP8v+1msTrEImO5kkptSZx/qK0c9BXl73HdCdBrQqpdfKlhvYQBVCcd2mz+yNeFipyOB/I1X5Jz/mrDYh2pW7Dh0Aznd7bduWUCYML3MvWg+pWNvcVyJau+pz0NfCOCBmByln7gvjeH/MEZ6MSMyzJDtkxghiFHrUCmHn9DEgpgq4kUS/+yhHUFVc8S7sLX1V32S0oUBHgwYG9LJtLbQBXOXE4jKxTIc8qUR7SsNvyYGHngOKROrfKlYtn2i+ufHJcUk7SuwBBq61ZHXjahQZZa4OvEVr7ljS4itMOSgFLxYXZ8hSAXQCKMqnVL6e1JQDXyXYeSqMc7cedc7LjwmFOOhPl6y61xsTtG8l1O0VLdTMZukuDH7yUJoyTslHV6+TEL9GnT X-Forefront-Antispam-Report: CIP:66.35.236.227;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(2980300002)(339900001)(199003)(189002)(77096005)(2201001)(2950100001)(50986999)(19580405001)(15975445007)(86362001)(46102003)(6806004)(47776003)(86152002)(107886002)(189998001)(76176999)(87936001)(85426001)(48376002)(77156002)(5001960100002)(122386002)(50466002)(62966003)(106466001)(53416004)(105606002)(16796002)(92566002)(229853001)(19580395003)(5001920100001)(50226001)(5001770100001)(5003940100001)(33646002)(7099028)(7059030)(4001430100001)(2101003);DIR:OUT;SFP:1101;SCL:1;SRVR:BN1PR03MB233;H:sj-itexedge03.altera.priv.altera.com;FPR:;SPF:Fail;MLV:sfv;A:0;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BN1PR03MB233;2:83i2Uq/dM4U0ke0auRQyu7IQCG++pqU2IsQgiQaTgOcJdRiQJCCQBmj39bkqkqn5;3:xZDUVDdPgQ098a8F96+2aELKpDryzHTfOQE2Wzeu26HRx1nDHxq3xn9d0tAqRAzFKkq1frLsuSFKoaD9CsgGZoMDfaK9OrAFPhnL9V0D1kFzE6WcGAHh3zllbXN7r4IIEl4EOdJKTnz/ZKwhaZOXxNTgAsmfhZ/Dl1KMVrC8xnSmIMH+TgZeN6Et/D2iQEz1fH/U0u7WSXm4NfbTPEUMvunYUbK5Cpdq4zzkD5IVhAc=;25:h0VDk8Tzwu8gqyimsNA2y9SzUhmmEA+yZzeRWOVpE7DGSOuxGBWeAs3s7F4+OeJUgqVgWD6nOsdL7FL8B2/RldGE4HM0eGRWWlNXcU0qDTEvYvY9zpUIgFIliVkxijVoLA336/DpzWvllpw7z8KhS4PCCuprxiS/tqqvVilpmaSUgB7BB7nZOcSKA+Buev6V2ND+pNFv+HFbclwEuiZYIOP+S232QgBpwc/lUYR7yZQi15gGIx+sHf6HNWorge+XB42erCyzGNrV3SLYR1kNKA==;20:lWI82ORVrVXAKi0ZjoIFmmnNecLtWRwpenon0H1gf2Ju0kUzs+OPkmAgJKsvU77MuifOlGMw2BefhqAy6IEdhx4IONt14N0smy2nYEAZM62CBjR0knf6ZWrOPe2HsFHtkAPWB0ExXGVWaDHUR8EXvgY1nYzRvB5FlNSYmUjsxmw= BN1PR03MB233: X-MS-Exchange-Organization-RulesExecuted X-Microsoft-Exchange-Diagnostics: 1;BN1PR03MB233;4:556YURh+Yc4YU5vvAwC010AU4YjpsalOq9HdC7wLvTcCa38ZfvBX/HY094viaL1EUzx7NahONKNqOXpjfnhEn5fLZK9tN+iGX2fj1nkFb9xeFJz42xKT+yQvlpjPddS1JAp1+dYSGt7zJBegtNKYVnid5bhfvei4/74SKl+mbykYByRD6rAGz6l0JdMoPwy2wy5runvaMXq6rBC3UvpZ3a3jpkpwiSpx1EYRa14P3R7CFec9rMzpuCproCrRM6C1jqAbfrJP64w9huNshWVeuIWuqMaCNvQmxanXDm0CBXU= X-Forefront-PRVS: 06400060E1 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BN1PR03MB233;23:oVJRcRDQdHa8O/0jY6SQkr3VXQ7I+m+Ek6PWSKDrlK?= =?us-ascii?Q?G6gQO/gE9UTaOwWvqTeWHmbeBLJ3WFcmDOgwIOHcEXjmoFqN6FM+Sgb9itgY?= =?us-ascii?Q?cdwqarVwbWxCsHpbzFAPjWPTBoY7+CFvBzPv9XlKw9jX4oQH+6mouI0Rf6OI?= =?us-ascii?Q?E0onmHp5aN3dmHsSAUQ6cUvu8nV9KGRzGyi3s1cqfSv97hSE7kuMr541jspf?= =?us-ascii?Q?N26GtUwdIDaZeVjRbnyZr3/XtfipiuotR2QmarpqhyZjGiY8FCtDpIImSZAy?= =?us-ascii?Q?c+xBnOfMy6hwSCzTwYcFVV8gU4QFEQxc0S/khry21eUMQQyYfSIw5Uiqwq+P?= =?us-ascii?Q?hMxugv0ns8uMJYWR2yhM2IXaYmiBAOkiPZv6CYAAvVb58ZtmhW6N6siKtYfB?= =?us-ascii?Q?2JHLtqurwyTPPjuWxa+x0cyFa0CRhn4G3zu6BJxCAKU+aAjmg/cs8vJEhZNj?= =?us-ascii?Q?s8FQFgxxyYq7N1O3uQJDEoz5P6kCO9tLAtzMm5CTiCGdQeZMoHKXKXzR2QvJ?= =?us-ascii?Q?noHyhigo5mAUDQp8V0j5aksE2QOiFASt58C7JGs7s31cq7VtM0Ni6qLyJ4iH?= =?us-ascii?Q?h/8liCv/IIAzxuesz4Y3wwtOOlwFMY/iYWVBgGBs4G/LIFU6CqrlZ0GOmFrf?= =?us-ascii?Q?0Oi+YHzFLPpnWM+eJfjfQp3GZ8dIaQkiHwCo868vTiF2DM0a379lftVHHs4A?= =?us-ascii?Q?4qDxAE6Uy1ipzug1D3oKXFhiFdn9R30G2gNanWrMqmA+xO98hsKqj8D3uyUP?= =?us-ascii?Q?lXSvy3xLkn6a1Xe84QyFUvqJZ/O433F0kBkN9xE6h3l+aJIkuF+BOik5RkrE?= =?us-ascii?Q?mVWlcG6aSydZIDRfn8dP4+q63jIPJbIuPP5a+FptyaAFoV9q0R2+aMNsd7eL?= =?us-ascii?Q?Zv+AyylbhQaJTEAEfAqc9RGfTrO/5m9DO12mJTC++/8mQQu2WD8pmI/9kvc7?= =?us-ascii?Q?U+KrshQD2S+A5/sOmEVoatFw27ipNxRfwxJGdKBlV11bF2lf9eNjyvL7w/zH?= =?us-ascii?Q?xNHrAr5IPtWmaammPfcnjmi/4MiBrF9yCE1zAudvLERmi0vHzvHXy4hUg1/E?= =?us-ascii?Q?nmZrWqzz6ACkwcplv0rkzryHvW8fHfQWdybTTFMow1d9LDJAnVJq/bA2liwH?= =?us-ascii?Q?jqwVDDLinlBKwIiFpGNhCfFmOHjAIT?= X-Microsoft-Exchange-Diagnostics: 1;BN1PR03MB233;5:h1az1XkI8CDkoHlGVWxtMBHscFBjjDMzQGb4h2rwVdENp2GLl4ZSEesv258I/SwqK/4M0YzxFzrbe3OtcK6tvol5W/+c7INGFrGg8Ko2ACEuOTIZx5x6scPCUlYQ1D9GLr2Y1gu0Duo3ZxWtplTZvA==;24:9QGXZkn7bDjky2JDUTpoIv1h3nqnEMEzpcZ2uyPxpRrA9CfcHfVRQN+9cJGZTY3MCwLRU/D0eBJt+7YPpCtuK5soub+LYswEFon449PhiWA=;20:ZCXEwTqzMcpMCt9xqoWdfKkbxW9sF01pZCcT+5UPo6CRWW/cQklzmgiJGtsR1YQmBwAvZKHhQDwn7zczf6VDLANj1yPrNJwC6qI60TVah5P5DyT1Lj4P4twSoKuxqvdfGiKOTbqSrvzUpUeRZFjrYdSbffXpYUZmR6VroupI4N4= X-OriginatorOrg: opensource.altera.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2015 15:56:29.8239 (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: BN1PR03MB233 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 20026 Lines: 681 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 --- drivers/staging/Kconfig | 2 + drivers/staging/Makefile | 1 + drivers/staging/fpga/Kconfig | 14 ++ drivers/staging/fpga/Makefile | 8 + drivers/staging/fpga/fpga-mgr.c | 373 +++++++++++++++++++++++++++++++++++++++ include/linux/fpga/fpga-mgr.h | 127 +++++++++++++ 6 files changed, 525 insertions(+) create mode 100644 drivers/staging/fpga/Kconfig create mode 100644 drivers/staging/fpga/Makefile create mode 100644 drivers/staging/fpga/fpga-mgr.c create mode 100644 include/linux/fpga/fpga-mgr.h diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig index 7f6cae5..89c089c 100644 --- a/drivers/staging/Kconfig +++ b/drivers/staging/Kconfig @@ -112,4 +112,6 @@ source "drivers/staging/fsl-mc/Kconfig" source "drivers/staging/wilc1000/Kconfig" +source "drivers/staging/fpga/Kconfig" + endif # STAGING diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile index 347f647..e129940 100644 --- a/drivers/staging/Makefile +++ b/drivers/staging/Makefile @@ -48,3 +48,4 @@ obj-$(CONFIG_COMMON_CLK_XLNX_CLKWZRD) += clocking-wizard/ obj-$(CONFIG_FB_TFT) += fbtft/ obj-$(CONFIG_FSL_MC_BUS) += fsl-mc/ obj-$(CONFIG_WILC1000) += wilc1000/ +obj-$(CONFIG_FPGA) += fpga/ diff --git a/drivers/staging/fpga/Kconfig b/drivers/staging/fpga/Kconfig new file mode 100644 index 0000000..8254ca0 --- /dev/null +++ b/drivers/staging/fpga/Kconfig @@ -0,0 +1,14 @@ +# +# FPGA framework configuration +# + +menu "FPGA Configuration Support" + +config FPGA + bool "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/staging/fpga/Makefile b/drivers/staging/fpga/Makefile new file mode 100644 index 0000000..3313c52 --- /dev/null +++ b/drivers/staging/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/staging/fpga/fpga-mgr.c b/drivers/staging/fpga/fpga-mgr.c new file mode 100644 index 0000000..1363f8f --- /dev/null +++ b/drivers/staging/fpga/fpga-mgr.c @@ -0,0 +1,373 @@ +/* + * 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); + 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); + + if (!mutex_trylock(&mgr->ref_mutex)) + return ERR_PTR(-EBUSY); + + 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) + 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..14a2ca6 --- /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 (1) + +/** + * 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); + 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/