Intel FPGA Device Drivers
Subsystems (2)
kbuild test robot
build botRe: [PATCH 11/16] fpga: intel: fme: add partial reconfiguration sub feature support
In reply to Wu Haourl: https://github.com/0day-ci/linux/commits/Wu-Hao/Intel-FPGA-Device-Drivers/20170401-052017 config: frv-allmodconfig (attached as .config) compiler: frv-linux-gcc (GCC) 6.2.0 reproduce: wget…
Hi Kang,
[auto build test WARNING on linus/master]
[also build test WARNING on v4.11-rc4 next-20170331]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Wu-Hao/Intel-FPGA-Device-Drivers/20170401-052017
config: frv-allmodconfig (attached as .config)
compiler: frv-linux-gcc (GCC) 6.2.0
reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=frv
All warnings (new ones prefixed by >>):
drivers/fpga/intel/fme-pr.c: In function 'interface_id_show':
drivers/fpga/intel/fme-pr.c:45:15: error: implicit declaration of function 'readq' [-Werror=implicit-function-declaration]
intfc_id_l = readq(&fme_pr->intfc_id_l);
^~~~~
drivers/fpga/intel/fme-pr.c: In function 'pr_err_handle':
drivers/fpga/intel/fme-pr.c:79:2: error: implicit declaration of function 'writeq' [-Werror=implicit-function-declaration]
writeq(fme_pr_error, &fme_pr->error);
^~~~~~
In file included from include/linux/uaccess.h:5:0,
from drivers/fpga/intel/fme-pr.c:25:
drivers/fpga/intel/fme-pr.c: In function 'fme_pr':
>> arch/frv/include/asm/uaccess.h:63:47: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
#define access_ok(type,addr,size) (__range_ok((void __user *)(addr), (size)) == 0)
^
arch/frv/include/asm/uaccess.h:61:60: note: in definition of macro '__range_ok'
#define __range_ok(addr,size) ___range_ok((unsigned long) (addr), (unsigned long) (size))
^~~~
>> drivers/fpga/intel/fme-pr.c:278:7: note: in expansion of macro 'access_ok' if (!access_ok(VERIFY_READ, port_pr.buffer_address,
^~~~~~~~~
drivers/fpga/intel/fme-pr.c:286:26: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
if (copy_from_user(buf, (void __user *)port_pr.buffer_address,
^
cc1: some warnings being treated as errors
--
drivers/fpga//intel/fme-pr.c: In function 'interface_id_show':
drivers/fpga//intel/fme-pr.c:45:15: error: implicit declaration of function 'readq' [-Werror=implicit-function-declaration]
intfc_id_l = readq(&fme_pr->intfc_id_l);
^~~~~
drivers/fpga//intel/fme-pr.c: In function 'pr_err_handle':
drivers/fpga//intel/fme-pr.c:79:2: error: implicit declaration of function 'writeq' [-Werror=implicit-function-declaration]
writeq(fme_pr_error, &fme_pr->error);
^~~~~~
In file included from include/linux/uaccess.h:5:0,
from drivers/fpga//intel/fme-pr.c:25:
drivers/fpga//intel/fme-pr.c: In function 'fme_pr':
>> arch/frv/include/asm/uaccess.h:63:47: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
#define access_ok(type,addr,size) (__range_ok((void __user *)(addr), (size)) == 0)
^
arch/frv/include/asm/uaccess.h:61:60: note: in definition of macro '__range_ok'
#define __range_ok(addr,size) ___range_ok((unsigned long) (addr), (unsigned long) (size))
^~~~ drivers/fpga//intel/fme-pr.c:278:7: note: in expansion of macro 'access_ok'
if (!access_ok(VERIFY_READ, port_pr.buffer_address,
^~~~~~~~~
drivers/fpga//intel/fme-pr.c:286:26: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
if (copy_from_user(buf, (void __user *)port_pr.buffer_address,
^
cc1: some warnings being treated as errors
vim +63 arch/frv/include/asm/uaccess.h
^1da177e4c include/asm-frv/uaccess.h Linus Torvalds 2005-04-16 47 return flag; ^1da177e4c include/asm-frv/uaccess.h Linus Torvalds 2005-04-16 48 ^1da177e4c include/asm-frv/uaccess.h Linus Torvalds 2005-04-16 49 #else ^1da177e4c include/asm-frv/uaccess.h Linus Torvalds 2005-04-16 50 ^1da177e4c include/asm-frv/uaccess.h Linus Torvalds 2005-04-16 51 if (addr < memory_start || ^1da177e4c include/asm-frv/uaccess.h Linus Torvalds 2005-04-16 52 addr > memory_end || ^1da177e4c include/asm-frv/uaccess.h Linus Torvalds 2005-04-16 53 size > memory_end - memory_start || ^1da177e4c include/asm-frv/uaccess.h Linus Torvalds 2005-04-16 54 addr + size > memory_end) ^1da177e4c include/asm-frv/uaccess.h Linus Torvalds 2005-04-16 55 return -EFAULT; ^1da177e4c include/asm-frv/uaccess.h Linus Torvalds 2005-04-16 56 ^1da177e4c include/asm-frv/uaccess.h Linus Torvalds 2005-04-16 57 return 0; ^1da177e4c include/asm-frv/uaccess.h Linus Torvalds 2005-04-16 58 #endif ^1da177e4c include/asm-frv/uaccess.h Linus Torvalds 2005-04-16 59 } ^1da177e4c include/asm-frv/uaccess.h Linus Torvalds 2005-04-16 60 ^1da177e4c include/asm-frv/uaccess.h Linus Torvalds 2005-04-16 61 #define __range_ok(addr,size) ___range_ok((unsigned long) (addr), (unsigned long) (size)) ^1da177e4c include/asm-frv/uaccess.h Linus Torvalds 2005-04-16 62 a8a77573c9 include/asm-frv/uaccess.h Al Viro 2006-06-23 @63 #define access_ok(type,addr,size) (__range_ok((void __user *)(addr), (size)) == 0) ^1da177e4c include/asm-frv/uaccess.h Linus Torvalds 2005-04-16 64 #define __access_ok(addr,size) (__range_ok((addr), (size)) == 0) ^1da177e4c include/asm-frv/uaccess.h Linus Torvalds 2005-04-16 65 ^1da177e4c include/asm-frv/uaccess.h Linus Torvalds 2005-04-16 66 /* ^1da177e4c include/asm-frv/uaccess.h Linus Torvalds 2005-04-16 67 * The exception table consists of pairs of addresses: the first is the ^1da177e4c include/asm-frv/uaccess.h Linus Torvalds 2005-04-16 68 * address of an instruction that is allowed to fault, and the second is ^1da177e4c include/asm-frv/uaccess.h Linus Torvalds 2005-04-16 69 * the address at which the program should continue. No registers are ^1da177e4c include/asm-frv/uaccess.h Linus Torvalds 2005-04-16 70 * modified, so it is entirely up to the continuation code to figure out ^1da177e4c include/asm-frv/uaccess.h Linus Torvalds 2005-04-16 71 * what to do.
:::::: The code at line 63 was first introduced by commit
:::::: a8a77573c9e5345bcf6a963858745cd83c923f44 [PATCH] frv: __user infrastructure
:::::: TO: Al Viro <[email protected]> :::::: CC: Linus Torvalds <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
kbuild test robot
build botRe: [PATCH 11/16] fpga: intel: fme: add partial reconfiguration sub feature support
In reply to Wu Haourl: https://github.com/0day-ci/linux/commits/Wu-Hao/Intel-FPGA-Device-Drivers/20170401-052017 config: sparc-allyesconfig (attached as .config) compiler: sparc64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1…
Hi Kang,
[auto build test WARNING on linus/master]
[also build test WARNING on v4.11-rc4 next-20170331]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Wu-Hao/Intel-FPGA-Device-Drivers/20170401-052017
config: sparc-allyesconfig (attached as .config)
compiler: sparc64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=sparc
All warnings (new ones prefixed by >>):
drivers/fpga/intel/fme-pr.c: In function 'fme_pr':
>> drivers/fpga/intel/fme-pr.c:278:30: warning: passing argument 2 of 'access_ok' makes pointer from integer without a cast [-Wint-conversion]
if (!access_ok(VERIFY_READ, port_pr.buffer_address,
^~~~~~~
In file included from arch/sparc/include/asm/uaccess.h:4:0,
from include/linux/uaccess.h:5,
from drivers/fpga/intel/fme-pr.c:25:
arch/sparc/include/asm/uaccess_64.h:80:19: note: expected 'const void *' but argument is of type '__u64 {aka long long unsigned int}'
static inline int access_ok(int type, const void __user * addr, unsigned long size)
^~~~~~~~~
vim +/access_ok +278 drivers/fpga/intel/fme-pr.c
262 if (!IS_ALIGNED(port_pr.buffer_size, 4))
263 return -EINVAL;
264
265 /* get fme header region */
266 fme_hdr = get_feature_ioaddr_by_index(&pdev->dev,
267 FME_FEATURE_ID_HEADER);
268 if (WARN_ON(!fme_hdr))
269 return -EINVAL;
270
271 /* check port id */
272 fme_capability.csr = readq(&fme_hdr->capability);
273 if (port_pr.port_id >= fme_capability.num_ports) {
274 dev_dbg(&pdev->dev, "port number more than maximum\n");
275 return -EINVAL;
276 }
277
> 278 if (!access_ok(VERIFY_READ, port_pr.buffer_address,
279 port_pr.buffer_size))
280 return -EFAULT;
281
282 buf = vmalloc(port_pr.buffer_size);
283 if (!buf)
284 return -ENOMEM;
285
286 if (copy_from_user(buf, (void __user *)port_pr.buffer_address,
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Re: [PATCH 11/16] fpga: intel: fme: add partial reconfiguration sub feature support
In reply to Wu HaoQuoted 8 lines · Wu Hao
From: Kang Luwei <[email protected]>
Partial Reconfiguration (PR) is the most important function for FME. It allows reconfiguration for given Port/Accelerated Function Unit (AFU).
This patch adds support for PR sub feature. In this patch, it registers a
fpga_mgrand implementsfpga_manager_ops, and invokefpga_mgr_buf_loadfor PR operation once PR request received via ioctl.
The code that invokes fpga_mgr_buf_load should be a different layer.
Quoted 300 lines
Below user space
interfaces are exposed by this sub feature.Sysfs interface:
* /sys/class/fpga/<fpga.x>/<intel-fpga-fme.x>/interface_id Read-only. Indicate the hardware interface information. Userspace applications need to check this interface to select correct green bitstream format before PR.Ioctl interface:
*FPGA_FME_PORT_PR
Do partial reconfiguration per information from userspace, including target port(AFU), buffer size and address info. It returns the PR status (PR error code if failed) to userspace.Signed-off-by Tim Whisonant <[email protected]>Signed-off-by Enno Luebbers <[email protected]>Signed-off-by Shiva Rao <[email protected]>Signed-off-by Christopher Rauer <[email protected]>Signed-off-by Alan Tull <[email protected]>Signed-off-by Kang Luwei <[email protected]>Signed-off-by Xiao Guangrong <[email protected]>Signed-off-by Wu Hao <[email protected]>--- drivers/fpga/intel/Makefile | 2 +- drivers/fpga/intel/feature-dev.h | 58 ++++++ drivers/fpga/intel/fme-main.c | 44 ++++- drivers/fpga/intel/fme-pr.c | 400 +++++++++++++++++++++++++++++++++++++++ drivers/fpga/intel/fme.h | 32 ++++ include/uapi/linux/intel-fpga.h | 44 +++++ 6 files changed, 578 insertions(+), 2 deletions(-) create mode 100644 drivers/fpga/intel/fme-pr.c create mode 100644 drivers/fpga/intel/fme.hdrivers/fpga/intel/Makefile +1
-1@@ -2,4 +2,4 @@ obj-$(CONFIG_INTEL_FPGA_PCI) += intel-fpga-pci.o obj-$(CONFIG_INTEL_FPGA_FME) += intel-fpga-fme.o intel-fpga-pci-objs := pcie.o feature-dev.o -intel-fpga-fme-objs := fme-main.o +intel-fpga-fme-objs := fme-main.o fme-pr.odrivers/fpga/intel/feature-dev.h +58
-0@@ -150,8 +150,66 @@ struct feature_fme_err { };/* FME Partial Reconfiguration Sub Feature Register Set */ +/* FME PR Control Register */ +struct feature_fme_pr_ctl { +union { +u64 csr; +struct { +u8 pr_reset:1 ;/* Reset PR Engine */ +u8 rsvdz1:3 ; +u8 pr_reset_ack:1 ;/* Reset PR Engine Ack */ +u8 rsvdz2:3 ; +u8 pr_regionid:2 ;/* PR Region ID */ +u8 rsvdz3:2 ; +u8 pr_start_req:1 ;/* PR Start Request */ +u8 pr_push_complete:1 ;/* PR Data push complete */ +u8 pr_kind:1 ;/* Load Customer or Intel GBS */ +u32 rsvdz4:17 ; +u32 config_data; + }; + }; +}; + +/* FME PR Status Register */ +struct feature_fme_pr_status { +union { +u64 csr; +struct { +u16 pr_credit:9 ;/* Number of PR Credits */ +u8 rsvdz1:7 ; +u8 pr_status:1 ;/* PR Operation status */ +u8 rsvdz2:3 ; +u8 pr_ctrlr_status:3 ;/* Controller status */ +u8 rsvdz3:1 ; +u8 pr_host_status:4 ;/* PR Host status */ +u64 rsvdz4:36 ; + }; + }; +}; + +/* FME PR Data Register */ +struct feature_fme_pr_data { +union { +u64 csr; +struct { +/* PR data from the raw-binary file */ +u32 pr_data_raw; +u32 rsvd; + }; + }; +}; +struct feature_fme_pr {struct feature_header header; +struct feature_fme_pr_ctl control; +struct feature_fme_pr_status status; +struct feature_fme_pr_data data; +u64 error; + +u64 rsvd[16 ]; + +u64 intfc_id_l;/* PR interface Id Low */ +u64 intfc_id_h;/* PR interface Id High */ };/* PORT Header Register Set */ drivers/fpga/intel/fme-main.c +43
-1@@ -23,6 +23,7 @@#include <linux/intel-fpga.h> #include "feature-dev.h" +#include "fme.h" static ssize_t ports_num_show (struct device *dev,struct device_attribute *attr,char *buf)@@ -101,6 +102,10 @@ static struct feature_driver fme_feature_drvs[] = { .ops = &fme_hdr_ops, }, { + .name = FME_FEATURE_PR_MGMT, + .ops = &pr_mgmt_ops, + }, + { .ops = NULL, }, };@@ -182,14 +187,48 @@ static const struct file_operations fme_fops = { .unlocked_ioctl = fme_ioctl, }; +static int fme_dev_init (struct platform_device *pdev) +{ +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *fme; + + fme =devm_kzalloc (&pdev->dev,sizeof (*fme),GFP_KERNEL ); +if (!fme) +return -ENOMEM ; + + fme->pdata = pdata; + +mutex_lock (&pdata->lock); +fpga_pdata_set_private (pdata, fme); +mutex_unlock (&pdata->lock); +return 0 ; +} + +static void fme_dev_destroy (struct platform_device *pdev) +{ +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *fme; + +mutex_lock (&pdata->lock); + fme =fpga_pdata_get_private (pdata); +fpga_pdata_set_private (pdata,NULL ); +mutex_unlock (&pdata->lock); + +devm_kfree (&pdev->dev, fme); +} +static int fme_probe (struct platform_device *pdev) {int ret; - ret =fpga_dev_feature_init (pdev, fme_feature_drvs); + ret =fme_dev_init (pdev);if (ret) goto exit; + ret =fpga_dev_feature_init (pdev, fme_feature_drvs); +if (ret) + goto dev_destroy; + ret =fpga_register_dev_ops (pdev, &fme_fops,THIS_MODULE );if (ret) goto feature_uinit;@@ -198,6 +237,8 @@ static int fme_probe(struct platform_device *pdev) feature_uinit:fpga_dev_feature_uinit (pdev); +dev_destroy: +fme_dev_destroy (pdev); exit:return ret; }@@ -206,6 +247,7 @@ static int fme_remove(struct platform_device *pdev) {fpga_dev_feature_uinit (pdev);fpga_unregister_dev_ops (pdev); +fme_dev_destroy (pdev);return 0 ; }drivers/fpga/intel/fme-pr.c new file +89
-0@@ -0,0 +1,400 @@ +/* +* Driver for Intel FPGA Management Engine (FME) Partial Reconfiguration +* +* Copyright (C) 2017 Intel Corporation, Inc. +* +* Authors: +* Kang Luwei <[email protected]> +* Xiao Guangrong <[email protected]> +* Joseph Grecco <[email protected]> +* Enno Luebbers <[email protected]> +* Tim Whisonant <[email protected]> +* Ananda Ravuri <[email protected]> +* Christopher Rauer <[email protected]> +* Henry Mitchel <[email protected]> +* +* This work is licensed under a dual BSD/GPLv2 license. When using or +* redistributing this file, you may do so under either license. See the +* LICENSE.BSD file under this directory for the BSD license and see +* the COPYING file in the top-level directory for the GPLv2 license. +*/ + +#include <linux/types.h> +#include <linux/device.h> +#include <linux/vmalloc.h> +#include <linux/uaccess.h> +#include <linux/fpga/fpga-mgr.h> +#include <linux/intel-fpga.h> + +#include "feature-dev.h" +#include "fme.h" + +#define PR_WAIT_TIMEOUT 8000000 + +#define PR_HOST_STATUS_IDLE 0 + +DEFINE_FPGA_PR_ERR_MSG (pr_err_msg); + +static ssize_t interface_id_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +u64 intfc_id_l, intfc_id_h; +struct feature_fme_pr *fme_pr + =get_feature_ioaddr_by_index (dev,FME_FEATURE_ID_PR_MGMT ); + + intfc_id_l =readq (&fme_pr->intfc_id_l); + intfc_id_h =readq (&fme_pr->intfc_id_h); + +return scnprintf (buf,PAGE_SIZE ,"%016llx%016llx\n" , + (unsigned long long )intfc_id_h, + (unsigned long long )intfc_id_l); +} +static DEVICE_ATTR_RO (interface_id); + +static struct attribute *pr_mgmt_attrs[] = { + &dev_attr_interface_id.attr, +NULL , +}; + +struct attribute_group pr_mgmt_attr_group = { + .attrs = pr_mgmt_attrs, + .name ="pr" , +}; + +static u64 +pr_err_handle (struct platform_device *pdev,struct feature_fme_pr *fme_pr) +{ +struct feature_fme_pr_status fme_pr_status; +unsigned long err_code; +u64 fme_pr_error; +int i =0 ; + + fme_pr_status.csr =readq (&fme_pr->status); +if (!fme_pr_status.pr_status) +return 0 ; + + err_code = fme_pr_error =readq (&fme_pr->error); +for_each_set_bit (i, &err_code,PR_MAX_ERR_NUM ) +dev_dbg (&pdev->dev,"%s\n" , pr_err_msg[i]); +writeq (fme_pr_error, &fme_pr->error); +return fme_pr_error; +} + +static int fme_pr_write_init (struct fpga_manager *mgr, +struct fpga_image_info *info,const char *buf,size_t count) +{ +struct fpga_fme *fme = mgr->priv; +struct platform_device *pdev; +struct feature_fme_pr *fme_pr; +struct feature_fme_pr_ctl fme_pr_ctl;
drivers/fpga/intel/fme-pr.c line 99
Quoted 10 lines
drivers/fpga/intel/fme-pr.c new file +10
-0+struct feature_fme_pr_status fme_pr_status; + + pdev = fme->pdata->dev; + fme_pr =get_feature_ioaddr_by_index (&pdev->dev, +FME_FEATURE_ID_PR_MGMT ); +if (!fme_pr) +return -EINVAL ; + +if (WARN_ON (info->flags !=FPGA_MGR_PARTIAL_RECONFIG )) +return -EINVAL ;
flags is bitmapped so please do:
if (WARN_ON(info->flags & FPGA_MGR_PARTIAL_RECONFIG))
Quoted 129 lines
drivers/fpga/intel/fme-pr.c new file +129
-0+ +dev_dbg (&pdev->dev,"resetting PR before initiated PR\n" ); + + fme_pr_ctl.csr =readq (&fme_pr->control); + fme_pr_ctl.pr_reset =1 ; +writeq (fme_pr_ctl.csr, &fme_pr->control); + + fme_pr_ctl.pr_reset_ack =1 ; + +if (fpga_wait_register_field (pr_reset_ack, fme_pr_ctl, + &fme_pr->control,PR_WAIT_TIMEOUT ,1 )) { +dev_err (&pdev->dev,"maximum PR timeout\n" ); +return -ETIMEDOUT ; + } + + fme_pr_ctl.csr =readq (&fme_pr->control); + fme_pr_ctl.pr_reset =0 ; +writeq (fme_pr_ctl.csr, &fme_pr->control); + +dev_dbg (&pdev->dev, +"waiting for PR resource in HW to be initialized and ready\n" ); + + fme_pr_status.pr_host_status =PR_HOST_STATUS_IDLE ; + +if (fpga_wait_register_field (pr_host_status, fme_pr_status, + &fme_pr->status,PR_WAIT_TIMEOUT ,1 )) { +dev_err (&pdev->dev,"maximum PR timeout\n" ); +return -ETIMEDOUT ; + } + +dev_dbg (&pdev->dev,"check if have any previous PR error\n" ); +pr_err_handle (pdev, fme_pr); +return 0 ; +} + +static int fme_pr_write (struct fpga_manager *mgr, +const char *buf,size_t count) +{ +struct fpga_fme *fme = mgr->priv; +struct platform_device *pdev; +struct feature_fme_pr *fme_pr; +struct feature_fme_pr_ctl fme_pr_ctl; +struct feature_fme_pr_status fme_pr_status; +struct feature_fme_pr_data fme_pr_data; +int delay, pr_credit, i =0 ; + + pdev = fme->pdata->dev; + fme_pr =get_feature_ioaddr_by_index (&pdev->dev, +FME_FEATURE_ID_PR_MGMT ); + +dev_dbg (&pdev->dev,"set PR port ID and start request\n" ); + + fme_pr_ctl.csr =readq (&fme_pr->control); + fme_pr_ctl.pr_regionid = fme->port_id; + fme_pr_ctl.pr_start_req =1 ; +writeq (fme_pr_ctl.csr, &fme_pr->control); + +dev_dbg (&pdev->dev,"pushing data from bitstream to HW\n" ); + + fme_pr_status.csr =readq (&fme_pr->status); + pr_credit = fme_pr_status.pr_credit; + +while (count >0 ) { + delay =0 ; +while (pr_credit <=1 ) { +if (delay++ >PR_WAIT_TIMEOUT ) { +dev_err (&pdev->dev,"maximum try\n" ); +return -ETIMEDOUT ; + } +udelay (1 ); + + fme_pr_status.csr =readq (&fme_pr->status); + pr_credit = fme_pr_status.pr_credit; + }; + +if (count >=4 ) { + fme_pr_data.rsvd =0 ; + fme_pr_data.pr_data_raw = *(((u32 *)buf) + i); +writeq (fme_pr_data.csr, &fme_pr->data); + count -=4 ; + pr_credit--; + i++; + }else { +WARN_ON (1 ); +return -EINVAL ; + } + } + +return 0 ; +} + +static int fme_pr_write_complete (struct fpga_manager *mgr, +struct fpga_image_info *info) +{ +struct fpga_fme *fme = mgr->priv; +struct platform_device *pdev; +struct feature_fme_pr *fme_pr; +struct feature_fme_pr_ctl fme_pr_ctl; + + pdev = fme->pdata->dev; + fme_pr =get_feature_ioaddr_by_index (&pdev->dev, +FME_FEATURE_ID_PR_MGMT ); + + fme_pr_ctl.csr =readq (&fme_pr->control); + fme_pr_ctl.pr_push_complete =1 ; +writeq (fme_pr_ctl.csr, &fme_pr->control); + +dev_dbg (&pdev->dev,"green bitstream push complete\n" ); +dev_dbg (&pdev->dev,"waiting for HW to release PR resource\n" ); + + fme_pr_ctl.pr_start_req =0 ; + +if (fpga_wait_register_field (pr_start_req, fme_pr_ctl, + &fme_pr->control,PR_WAIT_TIMEOUT ,1 )) { +dev_err (&pdev->dev,"maximum try.\n" ); +return -ETIMEDOUT ; + } + +dev_dbg (&pdev->dev,"PR operation complete, checking status\n" ); + fme->pr_err =pr_err_handle (pdev, fme_pr); +if (fme->pr_err) +return -EIO ; + +dev_dbg (&pdev->dev,"PR done successfully\n" ); +return 0 ; +} + +static enum fpga_mgr_states fme_pr_state (struct fpga_manager *mgr) +{
drivers/fpga/intel/fme-pr.c line 238
Quoted 10 lines
drivers/fpga/intel/fme-pr.c new file +10
-0+return FPGA_MGR_STATE_UNKNOWN ; +} + +static const struct fpga_manager_ops fme_pr_ops = { + .write_init = fme_pr_write_init, + .write = fme_pr_write, + .write_complete = fme_pr_write_complete, + .state = fme_pr_state, +}; +
The following fme_pr() function shouldn't be in a fpga-mgr driver. It is calling
the framework that this driver is registered with.
A fpga-mgr low level driver is supposed to be a very low level driver. This function is controlling the port and calling fpga-mgr layer to do the programming. There should be a layer above the fpga-mgr and fpga-bridge that coordinates these things. I.e. can you use my proposed fpga-region code?
Quoted 270 lines
drivers/fpga/intel/fme-pr.c new file +162
-0+static int fme_pr (struct platform_device *pdev,unsigned long arg) +{ +void __user *argp = (void __user *)arg; +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *fme; +struct fpga_manager *mgr; +struct feature_fme_header *fme_hdr; +struct feature_fme_capability fme_capability; +struct fpga_image_info info; +struct fpga_fme_port_pr port_pr; +struct platform_device *port; +unsigned long minsz; +void *buf =NULL ; +int ret =0 ; + + minsz = offsetofend(struct fpga_fme_port_pr, status); + +if (copy_from_user (&port_pr, argp, minsz)) +return -EFAULT ; + +if (port_pr.argsz < minsz || port_pr.flags) +return -EINVAL ; + +if (!IS_ALIGNED (port_pr.buffer_size,4 )) +return -EINVAL ; + +/* get fme header region */ + fme_hdr =get_feature_ioaddr_by_index (&pdev->dev, +FME_FEATURE_ID_HEADER ); +if (WARN_ON (!fme_hdr)) +return -EINVAL ; + +/* check port id */ + fme_capability.csr =readq (&fme_hdr->capability); +if (port_pr.port_id >= fme_capability.num_ports) { +dev_dbg (&pdev->dev,"port number more than maximum\n" ); +return -EINVAL ; + } + +if (!access_ok (VERIFY_READ , port_pr.buffer_address, + port_pr.buffer_size)) +return -EFAULT ; + + buf =vmalloc (port_pr.buffer_size); +if (!buf) +return -ENOMEM ; + +if (copy_from_user (buf, (void __user *)port_pr.buffer_address, + port_pr.buffer_size)) { + ret = -EFAULT ; + goto free_exit; + } + +memset (&info,0 ,sizeof (struct fpga_image_info )); + info.flags =FPGA_MGR_PARTIAL_RECONFIG ; + + mgr =fpga_mgr_get (&pdev->dev); +if (IS_ERR (mgr)) { + ret =PTR_ERR (mgr); + goto free_exit; + } + +mutex_lock (&pdata->lock); + fme =fpga_pdata_get_private (pdata); +/* fme device has been unregistered. */ +if (!fme) { + ret = -EINVAL ; + goto unlock_exit; + } + + fme->pr_err =0 ; + fme->port_id = port_pr.port_id; + +/* Find and get port device by index */ + port = pdata->fpga_for_each_port (pdev, &fme->port_id, + fpga_port_check_id); +WARN_ON (!port); + +/* Disable Port before PR */ +fpga_port_disable (port); + + ret =fpga_mgr_buf_load (mgr, &info, buf, port_pr.buffer_size); + port_pr.status = fme->pr_err; + +/* Re-enable Port after PR finished */ +fpga_port_enable (port); + +put_device (&port->dev); + +unlock_exit: +mutex_unlock (&pdata->lock); +fpga_mgr_put (mgr); +free_exit: +vfree (buf); +if (copy_to_user ((void __user *)arg, &port_pr, minsz)) +return -EFAULT ; +return ret; +} + +static int fpga_fme_pr_probe (struct platform_device *pdev) +{ +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *priv; +int ret; + +mutex_lock (&pdata->lock); + priv =fpga_pdata_get_private (pdata); + ret =fpga_mgr_register (&pdata->dev->dev, +"Intel FPGA Manager" , &fme_pr_ops, priv); +mutex_unlock (&pdata->lock); + +return ret; +} + +static int fpga_fme_pr_remove (struct platform_device *pdev) +{ +fpga_mgr_unregister (&pdev->dev); +return 0 ; +} + +static int pr_mgmt_init (struct platform_device *pdev,struct feature *feature) +{ +int ret; + + ret =fpga_fme_pr_probe (pdev); +if (ret) +return ret; + + ret =sysfs_create_group (&pdev->dev.kobj, &pr_mgmt_attr_group); +if (ret) +fpga_fme_pr_remove (pdev); + +return ret; +} + +static void pr_mgmt_uinit (struct platform_device *pdev,struct feature *feature) +{ +sysfs_remove_group (&pdev->dev.kobj, &pr_mgmt_attr_group); +fpga_fme_pr_remove (pdev); +} + +static long fme_pr_ioctl (struct platform_device *pdev,struct feature *feature, +unsigned int cmd,unsigned long arg) +{ +long ret; + +switch (cmd) { +case FPGA_FME_PORT_PR : + ret =fme_pr (pdev, arg); +break ; +default : + ret = -ENODEV ; + } + +return ret; +} + +struct feature_ops pr_mgmt_ops = { + .init = pr_mgmt_init, + .uinit = pr_mgmt_uinit, + .ioctl = fme_pr_ioctl, +};drivers/fpga/intel/fme.h new file +32
-0@@ -0,0 +1,32 @@ +/* +* Header file for Intel FPGA Management Engine (FME) Driver +* +* Copyright (C) 2017 Intel Corporation, Inc. +* +* Authors: +* Kang Luwei <[email protected]> +* Xiao Guangrong <[email protected]> +* Joseph Grecco <[email protected]> +* Enno Luebbers <[email protected]> +* Tim Whisonant <[email protected]> +* Ananda Ravuri <[email protected]> +* Henry Mitchel <[email protected]> +* +* This work is licensed under a dual BSD/GPLv2 license. When using or +* redistributing this file, you may do so under either license. See the +* LICENSE.BSD file under this directory for the BSD license and see +* the COPYING file in the top-level directory for the GPLv2 license. +*/ + +#ifndef __INTEL_FME_H +#define __INTEL_FME_H + +struct fpga_fme { +u8 port_id; +u64 pr_err; +struct feature_platform_data *pdata; +}; + +extern struct feature_ops pr_mgmt_ops; + +#endif include/uapi/linux/intel-fpga.h +44
-1@@ -18,6 +18,8 @@#ifndef _UAPI_LINUX_INTEL_FPGA_H#define _UAPI_LINUX_INTEL_FPGA_H +#include <linux/types.h> +#define FPGA_API_VERSION 0/* @@ -30,6 +32,7 @@#define FPGA_MAGIC 0xB6#define FPGA_BASE 0 +#define FME_BASE 0x80/** * FPGA_GET_API_VERSION - _IO(FPGA_MAGIC, FPGA_BASE + 0) @@ -49,4 +52,45 @@#define FPGA_CHECK_EXTENSION _IO(FPGA_MAGIC, FPGA_BASE + 1) +/* IOCTLs for FME file descriptor */ + +/** +* FPGA_FME_PORT_PR - _IOWR(FPGA_MAGIC, FME_BASE + 0, struct fpga_fme_port_pr) +* +* Driver does Partial Reconfiguration based on Port ID and Buffer (Image) +* provided by caller. +* Return: 0 on success, -errno on failure. +* If FPGA_FME_PORT_PR returns -EIO, that indicates the HW has detected +* some errors during PR, under this case, the user can fetch HW error code +* from fpga_fme_port_pr.status. Each bit on the error code is used as the +* index for the array created by DEFINE_FPGA_PR_ERR_MSG(). +* Otherwise, it is always zero. +*/ + +#define DEFINE_FPGA_PR_ERR_MSG (_name_) \ +static const char * const _name_[] = { \ + "PR operation error detected", \ + "PR CRC error detected", \ + "PR incompatiable bitstream error detected", \ + "PR IP protocol error detected", \ + "PR FIFO overflow error detected", \ + "Reserved", \ + "PR secure load error detected", \ +} + +#define PR_MAX_ERR_NUM 7 + +struct fpga_fme_port_pr { +/* Input */ +__u32 argsz;/* Structure length */ +__u32 flags;/* Zero for now */ +__u32 port_id; +__u32 buffer_size; +__u64 buffer_address;/* Userspace address to the buffer for PR */ +/* Output */ +__u64 status;/* HW error code if ioctl returns -EIO */ +}; + +#define FPGA_FME_PORT_PR _IO(FPGA_MAGIC, FME_BASE + 0) +#endif /* _UAPI_INTEL_FPGA_H */ --2.7.4
Re: [PATCH 11/16] fpga: intel: fme: add partial reconfiguration sub feature support
Quoted 450 lines · Alan Tull
Quoted 8 lines · Wu Hao
From: Kang Luwei <[email protected]>
Partial Reconfiguration (PR) is the most important function for FME. It allows reconfiguration for given Port/Accelerated Function Unit (AFU).
This patch adds support for PR sub feature. In this patch, it registers a
fpga_mgrand implementsfpga_manager_ops, and invokefpga_mgr_buf_loadfor PR operation once PR request received via ioctl.The code that invokes
fpga_mgr_buf_loadshould be a different layer.Quoted 300 lines
Below user space
interfaces are exposed by this sub feature.Sysfs interface:
* /sys/class/fpga/<fpga.x>/<intel-fpga-fme.x>/interface_id Read-only. Indicate the hardware interface information. Userspace applications need to check this interface to select correct green bitstream format before PR.Ioctl interface:
*FPGA_FME_PORT_PR
Do partial reconfiguration per information from userspace, including target port(AFU), buffer size and address info. It returns the PR status (PR error code if failed) to userspace.Signed-off-by Tim Whisonant <[email protected]>Signed-off-by Enno Luebbers <[email protected]>Signed-off-by Shiva Rao <[email protected]>Signed-off-by Christopher Rauer <[email protected]>Signed-off-by Alan Tull <[email protected]>Signed-off-by Kang Luwei <[email protected]>Signed-off-by Xiao Guangrong <[email protected]>Signed-off-by Wu Hao <[email protected]>--- drivers/fpga/intel/Makefile | 2 +- drivers/fpga/intel/feature-dev.h | 58 ++++++ drivers/fpga/intel/fme-main.c | 44 ++++- drivers/fpga/intel/fme-pr.c | 400 +++++++++++++++++++++++++++++++++++++++ drivers/fpga/intel/fme.h | 32 ++++ include/uapi/linux/intel-fpga.h | 44 +++++ 6 files changed, 578 insertions(+), 2 deletions(-) create mode 100644 drivers/fpga/intel/fme-pr.c create mode 100644 drivers/fpga/intel/fme.hdrivers/fpga/intel/Makefile +1
-1@@ -2,4 +2,4 @@ obj-$(CONFIG_INTEL_FPGA_PCI) += intel-fpga-pci.o obj-$(CONFIG_INTEL_FPGA_FME) += intel-fpga-fme.o intel-fpga-pci-objs := pcie.o feature-dev.o -intel-fpga-fme-objs := fme-main.o +intel-fpga-fme-objs := fme-main.o fme-pr.odrivers/fpga/intel/feature-dev.h +58
-0@@ -150,8 +150,66 @@ struct feature_fme_err { };/* FME Partial Reconfiguration Sub Feature Register Set */ +/* FME PR Control Register */ +struct feature_fme_pr_ctl { +union { +u64 csr; +struct { +u8 pr_reset:1 ;/* Reset PR Engine */ +u8 rsvdz1:3 ; +u8 pr_reset_ack:1 ;/* Reset PR Engine Ack */ +u8 rsvdz2:3 ; +u8 pr_regionid:2 ;/* PR Region ID */ +u8 rsvdz3:2 ; +u8 pr_start_req:1 ;/* PR Start Request */ +u8 pr_push_complete:1 ;/* PR Data push complete */ +u8 pr_kind:1 ;/* Load Customer or Intel GBS */ +u32 rsvdz4:17 ; +u32 config_data; + }; + }; +}; + +/* FME PR Status Register */ +struct feature_fme_pr_status { +union { +u64 csr; +struct { +u16 pr_credit:9 ;/* Number of PR Credits */ +u8 rsvdz1:7 ; +u8 pr_status:1 ;/* PR Operation status */ +u8 rsvdz2:3 ; +u8 pr_ctrlr_status:3 ;/* Controller status */ +u8 rsvdz3:1 ; +u8 pr_host_status:4 ;/* PR Host status */ +u64 rsvdz4:36 ; + }; + }; +}; + +/* FME PR Data Register */ +struct feature_fme_pr_data { +union { +u64 csr; +struct { +/* PR data from the raw-binary file */ +u32 pr_data_raw; +u32 rsvd; + }; + }; +}; +struct feature_fme_pr {struct feature_header header; +struct feature_fme_pr_ctl control; +struct feature_fme_pr_status status; +struct feature_fme_pr_data data; +u64 error; + +u64 rsvd[16 ]; + +u64 intfc_id_l;/* PR interface Id Low */ +u64 intfc_id_h;/* PR interface Id High */ };/* PORT Header Register Set */ drivers/fpga/intel/fme-main.c +43
-1@@ -23,6 +23,7 @@#include <linux/intel-fpga.h> #include "feature-dev.h" +#include "fme.h" static ssize_t ports_num_show (struct device *dev,struct device_attribute *attr,char *buf)@@ -101,6 +102,10 @@ static struct feature_driver fme_feature_drvs[] = { .ops = &fme_hdr_ops, }, { + .name = FME_FEATURE_PR_MGMT, + .ops = &pr_mgmt_ops, + }, + { .ops = NULL, }, };@@ -182,14 +187,48 @@ static const struct file_operations fme_fops = { .unlocked_ioctl = fme_ioctl, }; +static int fme_dev_init (struct platform_device *pdev) +{ +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *fme; + + fme =devm_kzalloc (&pdev->dev,sizeof (*fme),GFP_KERNEL ); +if (!fme) +return -ENOMEM ; + + fme->pdata = pdata; + +mutex_lock (&pdata->lock); +fpga_pdata_set_private (pdata, fme); +mutex_unlock (&pdata->lock); +return 0 ; +} + +static void fme_dev_destroy (struct platform_device *pdev) +{ +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *fme; + +mutex_lock (&pdata->lock); + fme =fpga_pdata_get_private (pdata); +fpga_pdata_set_private (pdata,NULL ); +mutex_unlock (&pdata->lock); + +devm_kfree (&pdev->dev, fme); +} +static int fme_probe (struct platform_device *pdev) {int ret; - ret =fpga_dev_feature_init (pdev, fme_feature_drvs); + ret =fme_dev_init (pdev);if (ret) goto exit; + ret =fpga_dev_feature_init (pdev, fme_feature_drvs); +if (ret) + goto dev_destroy; + ret =fpga_register_dev_ops (pdev, &fme_fops,THIS_MODULE );if (ret) goto feature_uinit;@@ -198,6 +237,8 @@ static int fme_probe(struct platform_device *pdev) feature_uinit:fpga_dev_feature_uinit (pdev); +dev_destroy: +fme_dev_destroy (pdev); exit:return ret; }@@ -206,6 +247,7 @@ static int fme_remove(struct platform_device *pdev) {fpga_dev_feature_uinit (pdev);fpga_unregister_dev_ops (pdev); +fme_dev_destroy (pdev);return 0 ; }drivers/fpga/intel/fme-pr.c new file +89
-0@@ -0,0 +1,400 @@ +/* +* Driver for Intel FPGA Management Engine (FME) Partial Reconfiguration +* +* Copyright (C) 2017 Intel Corporation, Inc. +* +* Authors: +* Kang Luwei <[email protected]> +* Xiao Guangrong <[email protected]> +* Joseph Grecco <[email protected]> +* Enno Luebbers <[email protected]> +* Tim Whisonant <[email protected]> +* Ananda Ravuri <[email protected]> +* Christopher Rauer <[email protected]> +* Henry Mitchel <[email protected]> +* +* This work is licensed under a dual BSD/GPLv2 license. When using or +* redistributing this file, you may do so under either license. See the +* LICENSE.BSD file under this directory for the BSD license and see +* the COPYING file in the top-level directory for the GPLv2 license. +*/ + +#include <linux/types.h> +#include <linux/device.h> +#include <linux/vmalloc.h> +#include <linux/uaccess.h> +#include <linux/fpga/fpga-mgr.h> +#include <linux/intel-fpga.h> + +#include "feature-dev.h" +#include "fme.h" + +#define PR_WAIT_TIMEOUT 8000000 + +#define PR_HOST_STATUS_IDLE 0 + +DEFINE_FPGA_PR_ERR_MSG (pr_err_msg); + +static ssize_t interface_id_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +u64 intfc_id_l, intfc_id_h; +struct feature_fme_pr *fme_pr + =get_feature_ioaddr_by_index (dev,FME_FEATURE_ID_PR_MGMT ); + + intfc_id_l =readq (&fme_pr->intfc_id_l); + intfc_id_h =readq (&fme_pr->intfc_id_h); + +return scnprintf (buf,PAGE_SIZE ,"%016llx%016llx\n" , + (unsigned long long )intfc_id_h, + (unsigned long long )intfc_id_l); +} +static DEVICE_ATTR_RO (interface_id); + +static struct attribute *pr_mgmt_attrs[] = { + &dev_attr_interface_id.attr, +NULL , +}; + +struct attribute_group pr_mgmt_attr_group = { + .attrs = pr_mgmt_attrs, + .name ="pr" , +}; + +static u64 +pr_err_handle (struct platform_device *pdev,struct feature_fme_pr *fme_pr) +{ +struct feature_fme_pr_status fme_pr_status; +unsigned long err_code; +u64 fme_pr_error; +int i =0 ; + + fme_pr_status.csr =readq (&fme_pr->status); +if (!fme_pr_status.pr_status) +return 0 ; + + err_code = fme_pr_error =readq (&fme_pr->error); +for_each_set_bit (i, &err_code,PR_MAX_ERR_NUM ) +dev_dbg (&pdev->dev,"%s\n" , pr_err_msg[i]); +writeq (fme_pr_error, &fme_pr->error); +return fme_pr_error; +} + +static int fme_pr_write_init (struct fpga_manager *mgr, +struct fpga_image_info *info,const char *buf,size_t count) +{ +struct fpga_fme *fme = mgr->priv; +struct platform_device *pdev; +struct feature_fme_pr *fme_pr; +struct feature_fme_pr_ctl fme_pr_ctl;drivers/fpga/intel/fme-pr.c line 99
Quoted 10 lines
drivers/fpga/intel/fme-pr.c new file +10
-0+struct feature_fme_pr_status fme_pr_status; + + pdev = fme->pdata->dev; + fme_pr =get_feature_ioaddr_by_index (&pdev->dev, +FME_FEATURE_ID_PR_MGMT ); +if (!fme_pr) +return -EINVAL ; + +if (WARN_ON (info->flags !=FPGA_MGR_PARTIAL_RECONFIG )) +return -EINVAL ;flags is bitmapped so please do:
if (
WARN_ON(info->flags & FPGA_MGR_PARTIAL_RECONFIG))Quoted 123 lines
drivers/fpga/intel/fme-pr.c new file +123
-0+ +dev_dbg (&pdev->dev,"resetting PR before initiated PR\n" ); + + fme_pr_ctl.csr =readq (&fme_pr->control); + fme_pr_ctl.pr_reset =1 ; +writeq (fme_pr_ctl.csr, &fme_pr->control); + + fme_pr_ctl.pr_reset_ack =1 ; + +if (fpga_wait_register_field (pr_reset_ack, fme_pr_ctl, + &fme_pr->control,PR_WAIT_TIMEOUT ,1 )) { +dev_err (&pdev->dev,"maximum PR timeout\n" ); +return -ETIMEDOUT ; + } + + fme_pr_ctl.csr =readq (&fme_pr->control); + fme_pr_ctl.pr_reset =0 ; +writeq (fme_pr_ctl.csr, &fme_pr->control); + +dev_dbg (&pdev->dev, +"waiting for PR resource in HW to be initialized and ready\n" ); + + fme_pr_status.pr_host_status =PR_HOST_STATUS_IDLE ; + +if (fpga_wait_register_field (pr_host_status, fme_pr_status, + &fme_pr->status,PR_WAIT_TIMEOUT ,1 )) { +dev_err (&pdev->dev,"maximum PR timeout\n" ); +return -ETIMEDOUT ; + } + +dev_dbg (&pdev->dev,"check if have any previous PR error\n" ); +pr_err_handle (pdev, fme_pr); +return 0 ; +} + +static int fme_pr_write (struct fpga_manager *mgr, +const char *buf,size_t count) +{ +struct fpga_fme *fme = mgr->priv; +struct platform_device *pdev; +struct feature_fme_pr *fme_pr; +struct feature_fme_pr_ctl fme_pr_ctl; +struct feature_fme_pr_status fme_pr_status; +struct feature_fme_pr_data fme_pr_data; +int delay, pr_credit, i =0 ; + + pdev = fme->pdata->dev; + fme_pr =get_feature_ioaddr_by_index (&pdev->dev, +FME_FEATURE_ID_PR_MGMT ); + +dev_dbg (&pdev->dev,"set PR port ID and start request\n" ); + + fme_pr_ctl.csr =readq (&fme_pr->control); + fme_pr_ctl.pr_regionid = fme->port_id; + fme_pr_ctl.pr_start_req =1 ; +writeq (fme_pr_ctl.csr, &fme_pr->control); + +dev_dbg (&pdev->dev,"pushing data from bitstream to HW\n" ); + + fme_pr_status.csr =readq (&fme_pr->status); + pr_credit = fme_pr_status.pr_credit; + +while (count >0 ) { + delay =0 ; +while (pr_credit <=1 ) { +if (delay++ >PR_WAIT_TIMEOUT ) { +dev_err (&pdev->dev,"maximum try\n" ); +return -ETIMEDOUT ; + } +udelay (1 ); + + fme_pr_status.csr =readq (&fme_pr->status); + pr_credit = fme_pr_status.pr_credit; + }; + +if (count >=4 ) { + fme_pr_data.rsvd =0 ; + fme_pr_data.pr_data_raw = *(((u32 *)buf) + i); +writeq (fme_pr_data.csr, &fme_pr->data); + count -=4 ; + pr_credit--; + i++; + }else { +WARN_ON (1 ); +return -EINVAL ; + } + } + +return 0 ; +} + +static int fme_pr_write_complete (struct fpga_manager *mgr, +struct fpga_image_info *info) +{ +struct fpga_fme *fme = mgr->priv; +struct platform_device *pdev; +struct feature_fme_pr *fme_pr; +struct feature_fme_pr_ctl fme_pr_ctl; + + pdev = fme->pdata->dev; + fme_pr =get_feature_ioaddr_by_index (&pdev->dev, +FME_FEATURE_ID_PR_MGMT ); + + fme_pr_ctl.csr =readq (&fme_pr->control); + fme_pr_ctl.pr_push_complete =1 ; +writeq (fme_pr_ctl.csr, &fme_pr->control); + +dev_dbg (&pdev->dev,"green bitstream push complete\n" ); +dev_dbg (&pdev->dev,"waiting for HW to release PR resource\n" ); + + fme_pr_ctl.pr_start_req =0 ; + +if (fpga_wait_register_field (pr_start_req, fme_pr_ctl, + &fme_pr->control,PR_WAIT_TIMEOUT ,1 )) { +dev_err (&pdev->dev,"maximum try.\n" ); +return -ETIMEDOUT ; + } + +dev_dbg (&pdev->dev,"PR operation complete, checking status\n" ); + fme->pr_err =pr_err_handle (pdev, fme_pr); +if (fme->pr_err) +return -EIO ; +
Quoted 8 lines
drivers/fpga/intel/fme-pr.c line 230
Quoted 8 lines
drivers/fpga/intel/fme-pr.c new file +8
-0+dev_dbg (&pdev->dev,"PR done successfully\n" ); +return 0 ; +} + +static enum fpga_mgr_states fme_pr_state (struct fpga_manager *mgr) +{ +return FPGA_MGR_STATE_UNKNOWN ; +}
The functions that implement the fme_pr_ops are really a low level fpga manager driver for the Altera PR IP component. A standalone version of such a driver has been reviewed and Acked. See the links below. Could this file use those functions and remove this code?
http://marc.info/?l=linux-kernel&m=149019678925564&w=2
http://marc.info/?l=linux-kernel&m=149019654225457&w=2
http://marc.info/?l=linux-kernel&m=149019598025274&w=2
http://marc.info/?l=linux-kernel&m=149013051007149&w=2
Quoted 118 lines
drivers/fpga/intel/fme-pr.c line 238
Quoted 8 lines
drivers/fpga/intel/fme-pr.c new file +8
-0+ +static const struct fpga_manager_ops fme_pr_ops = { + .write_init = fme_pr_write_init, + .write = fme_pr_write, + .write_complete = fme_pr_write_complete, + .state = fme_pr_state, +}; +The following
fme_pr()function shouldn't be in a fpga-mgr driver. It is calling
the framework that this driver is registered with.
A fpga-mgr low level driver is supposed to be a very low level driver. This function is controlling the port and calling fpga-mgr layer to do the programming. There should be a layer above the fpga-mgr and fpga-bridge that coordinates these things. I.e. can you use my proposed fpga-region code?Quoted 101 lines
drivers/fpga/intel/fme-pr.c new file +101
-0+static int fme_pr (struct platform_device *pdev,unsigned long arg) +{ +void __user *argp = (void __user *)arg; +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *fme; +struct fpga_manager *mgr; +struct feature_fme_header *fme_hdr; +struct feature_fme_capability fme_capability; +struct fpga_image_info info; +struct fpga_fme_port_pr port_pr; +struct platform_device *port; +unsigned long minsz; +void *buf =NULL ; +int ret =0 ; + + minsz = offsetofend(struct fpga_fme_port_pr, status); + +if (copy_from_user (&port_pr, argp, minsz)) +return -EFAULT ; + +if (port_pr.argsz < minsz || port_pr.flags) +return -EINVAL ; + +if (!IS_ALIGNED (port_pr.buffer_size,4 )) +return -EINVAL ; + +/* get fme header region */ + fme_hdr =get_feature_ioaddr_by_index (&pdev->dev, +FME_FEATURE_ID_HEADER ); +if (WARN_ON (!fme_hdr)) +return -EINVAL ; + +/* check port id */ + fme_capability.csr =readq (&fme_hdr->capability); +if (port_pr.port_id >= fme_capability.num_ports) { +dev_dbg (&pdev->dev,"port number more than maximum\n" ); +return -EINVAL ; + } + +if (!access_ok (VERIFY_READ , port_pr.buffer_address, + port_pr.buffer_size)) +return -EFAULT ; + + buf =vmalloc (port_pr.buffer_size); +if (!buf) +return -ENOMEM ; + +if (copy_from_user (buf, (void __user *)port_pr.buffer_address, + port_pr.buffer_size)) { + ret = -EFAULT ; + goto free_exit; + } + +memset (&info,0 ,sizeof (struct fpga_image_info )); + info.flags =FPGA_MGR_PARTIAL_RECONFIG ; + + mgr =fpga_mgr_get (&pdev->dev); +if (IS_ERR (mgr)) { + ret =PTR_ERR (mgr); + goto free_exit; + } + +mutex_lock (&pdata->lock); + fme =fpga_pdata_get_private (pdata); +/* fme device has been unregistered. */ +if (!fme) { + ret = -EINVAL ; + goto unlock_exit; + } + + fme->pr_err =0 ; + fme->port_id = port_pr.port_id; + +/* Find and get port device by index */ + port = pdata->fpga_for_each_port (pdev, &fme->port_id, + fpga_port_check_id); +WARN_ON (!port); + +/* Disable Port before PR */ +fpga_port_disable (port); + + ret =fpga_mgr_buf_load (mgr, &info, buf, port_pr.buffer_size); + port_pr.status = fme->pr_err; + +/* Re-enable Port after PR finished */ +fpga_port_enable (port); + +put_device (&port->dev); + +unlock_exit: +mutex_unlock (&pdata->lock); +fpga_mgr_put (mgr); +free_exit: +vfree (buf); +if (copy_to_user ((void __user *)arg, &port_pr, minsz)) +return -EFAULT ; +return ret; +} + +static int fpga_fme_pr_probe (struct platform_device *pdev) +{
Quoted 8 lines
drivers/fpga/intel/fme-pr.c line 347
Quoted 8 lines
drivers/fpga/intel/fme-pr.c new file +8
-0+struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *priv; +int ret; + +mutex_lock (&pdata->lock); + priv =fpga_pdata_get_private (pdata); + ret =fpga_mgr_register (&pdata->dev->dev, +"Intel FPGA Manager" , &fme_pr_ops, priv);
The call to fpga_mgr_register() above would change to a call to alt_pr_register() if the standalone version of the PR IP driver were used.
Quoted 8 lines
drivers/fpga/intel/fme-pr.c line 355
Quoted 8 lines
drivers/fpga/intel/fme-pr.c new file +8
-0+mutex_unlock (&pdata->lock); + +return ret; +} + +static int fpga_fme_pr_remove (struct platform_device *pdev) +{ +fpga_mgr_unregister (&pdev->dev);
This call to fpga_mgr_unregister() would change to a call to alt_pr_unregister() if the standalone version of the PR IP driver were used.
Quoted 158 lines
Quoted 151 lines
drivers/fpga/intel/fme-pr.c new file +45
-0+return 0 ; +} + +static int pr_mgmt_init (struct platform_device *pdev,struct feature *feature) +{ +int ret; + + ret =fpga_fme_pr_probe (pdev); +if (ret) +return ret; + + ret =sysfs_create_group (&pdev->dev.kobj, &pr_mgmt_attr_group); +if (ret) +fpga_fme_pr_remove (pdev); + +return ret; +} + +static void pr_mgmt_uinit (struct platform_device *pdev,struct feature *feature) +{ +sysfs_remove_group (&pdev->dev.kobj, &pr_mgmt_attr_group); +fpga_fme_pr_remove (pdev); +} + +static long fme_pr_ioctl (struct platform_device *pdev,struct feature *feature, +unsigned int cmd,unsigned long arg) +{ +long ret; + +switch (cmd) { +case FPGA_FME_PORT_PR : + ret =fme_pr (pdev, arg); +break ; +default : + ret = -ENODEV ; + } + +return ret; +} + +struct feature_ops pr_mgmt_ops = { + .init = pr_mgmt_init, + .uinit = pr_mgmt_uinit, + .ioctl = fme_pr_ioctl, +};drivers/fpga/intel/fme.h new file +32
-0@@ -0,0 +1,32 @@ +/* +* Header file for Intel FPGA Management Engine (FME) Driver +* +* Copyright (C) 2017 Intel Corporation, Inc. +* +* Authors: +* Kang Luwei <[email protected]> +* Xiao Guangrong <[email protected]> +* Joseph Grecco <[email protected]> +* Enno Luebbers <[email protected]> +* Tim Whisonant <[email protected]> +* Ananda Ravuri <[email protected]> +* Henry Mitchel <[email protected]> +* +* This work is licensed under a dual BSD/GPLv2 license. When using or +* redistributing this file, you may do so under either license. See the +* LICENSE.BSD file under this directory for the BSD license and see +* the COPYING file in the top-level directory for the GPLv2 license. +*/ + +#ifndef __INTEL_FME_H +#define __INTEL_FME_H + +struct fpga_fme { +u8 port_id; +u64 pr_err; +struct feature_platform_data *pdata; +}; + +extern struct feature_ops pr_mgmt_ops; + +#endif include/uapi/linux/intel-fpga.h +44
-1@@ -18,6 +18,8 @@#ifndef _UAPI_LINUX_INTEL_FPGA_H#define _UAPI_LINUX_INTEL_FPGA_H +#include <linux/types.h> +#define FPGA_API_VERSION 0/* @@ -30,6 +32,7 @@#define FPGA_MAGIC 0xB6#define FPGA_BASE 0 +#define FME_BASE 0x80/** * FPGA_GET_API_VERSION - _IO(FPGA_MAGIC, FPGA_BASE + 0) @@ -49,4 +52,45 @@#define FPGA_CHECK_EXTENSION _IO(FPGA_MAGIC, FPGA_BASE + 1) +/* IOCTLs for FME file descriptor */ + +/** +* FPGA_FME_PORT_PR - _IOWR(FPGA_MAGIC, FME_BASE + 0, struct fpga_fme_port_pr) +* +* Driver does Partial Reconfiguration based on Port ID and Buffer (Image) +* provided by caller. +* Return: 0 on success, -errno on failure. +* If FPGA_FME_PORT_PR returns -EIO, that indicates the HW has detected +* some errors during PR, under this case, the user can fetch HW error code +* from fpga_fme_port_pr.status. Each bit on the error code is used as the +* index for the array created by DEFINE_FPGA_PR_ERR_MSG(). +* Otherwise, it is always zero. +*/ + +#define DEFINE_FPGA_PR_ERR_MSG (_name_) \ +static const char * const _name_[] = { \ + "PR operation error detected", \ + "PR CRC error detected", \ + "PR incompatiable bitstream error detected", \ + "PR IP protocol error detected", \ + "PR FIFO overflow error detected", \ + "Reserved", \ + "PR secure load error detected", \ +} + +#define PR_MAX_ERR_NUM 7 + +struct fpga_fme_port_pr { +/* Input */ +__u32 argsz;/* Structure length */ +__u32 flags;/* Zero for now */ +__u32 port_id; +__u32 buffer_size; +__u64 buffer_address;/* Userspace address to the buffer for PR */ +/* Output */ +__u64 status;/* HW error code if ioctl returns -EIO */ +}; + +#define FPGA_FME_PORT_PR _IO(FPGA_MAGIC, FME_BASE + 0) +#endif /* _UAPI_INTEL_FPGA_H */ --Quoted 2 lines
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-fpga" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 11/16] fpga: intel: fme: add partial reconfiguration sub feature support
Quoted 468 lines · On Mon, Apr 03, 2017 at 03:49:41PM -0700, [email protected] wrote:
Quoted 450 lines · Alan Tull
Quoted 8 lines · Wu Hao
From: Kang Luwei <[email protected]>
Partial Reconfiguration (PR) is the most important function for FME. It allows reconfiguration for given Port/Accelerated Function Unit (AFU).
This patch adds support for PR sub feature. In this patch, it registers a
fpga_mgrand implementsfpga_manager_ops, and invokefpga_mgr_buf_loadfor PR operation once PR request received via ioctl.The code that invokes
fpga_mgr_buf_loadshould be a different layer.Quoted 300 lines
Below user space
interfaces are exposed by this sub feature.Sysfs interface:
* /sys/class/fpga/<fpga.x>/<intel-fpga-fme.x>/interface_id Read-only. Indicate the hardware interface information. Userspace applications need to check this interface to select correct green bitstream format before PR.Ioctl interface:
*FPGA_FME_PORT_PR
Do partial reconfiguration per information from userspace, including target port(AFU), buffer size and address info. It returns the PR status (PR error code if failed) to userspace.Signed-off-by Tim Whisonant <[email protected]>Signed-off-by Enno Luebbers <[email protected]>Signed-off-by Shiva Rao <[email protected]>Signed-off-by Christopher Rauer <[email protected]>Signed-off-by Alan Tull <[email protected]>Signed-off-by Kang Luwei <[email protected]>Signed-off-by Xiao Guangrong <[email protected]>Signed-off-by Wu Hao <[email protected]>---
drivers/fpga/intel/Makefile | 2 +- drivers/fpga/intel/feature-dev.h | 58 ++++++ drivers/fpga/intel/fme-main.c | 44 ++++- drivers/fpga/intel/fme-pr.c | 400 +++++++++++++++++++++++++++++++++++++++ drivers/fpga/intel/fme.h | 32 ++++ include/uapi/linux/intel-fpga.h | 44 +++++ 6 files changed, 578 insertions(+), 2 deletions(-)create mode 100644
drivers/fpga/intel/fme-pr.c
create mode 100644drivers/fpga/intel/fme.hdrivers/fpga/intel/Makefile +0
-0@@ -2,4 +2,4 @@ obj-$(CONFIG_INTEL_FPGA_PCI) += intel-fpga-pci.oobj-$(CONFIG_INTEL_FPGA_FME) += intel-fpga-fme.o
intel-fpga-pci-objs := pcie.o feature-dev.o
drivers/fpga/intel/Makefile +1
-1-intel-fpga-fme-objs := fme-main.o +intel-fpga-fme-objs := fme-main.o fme-pr.odrivers/fpga/intel/feature-dev.h +58
-0@@ -150,8 +150,66 @@ struct feature_fme_err { };/* FME Partial Reconfiguration Sub Feature Register Set */ +/* FME PR Control Register */ +struct feature_fme_pr_ctl { +union { +u64 csr; +struct { +u8 pr_reset:1 ;/* Reset PR Engine */ +u8 rsvdz1:3 ; +u8 pr_reset_ack:1 ;/* Reset PR Engine Ack */ +u8 rsvdz2:3 ; +u8 pr_regionid:2 ;/* PR Region ID */ +u8 rsvdz3:2 ; +u8 pr_start_req:1 ;/* PR Start Request */ +u8 pr_push_complete:1 ;/* PR Data push complete */ +u8 pr_kind:1 ;/* Load Customer or Intel GBS */ +u32 rsvdz4:17 ; +u32 config_data; + }; + }; +}; + +/* FME PR Status Register */ +struct feature_fme_pr_status { +union { +u64 csr; +struct { +u16 pr_credit:9 ;/* Number of PR Credits */ +u8 rsvdz1:7 ; +u8 pr_status:1 ;/* PR Operation status */ +u8 rsvdz2:3 ; +u8 pr_ctrlr_status:3 ;/* Controller status */ +u8 rsvdz3:1 ; +u8 pr_host_status:4 ;/* PR Host status */ +u64 rsvdz4:36 ; + }; + }; +}; + +/* FME PR Data Register */ +struct feature_fme_pr_data { +union { +u64 csr; +struct { +/* PR data from the raw-binary file */ +u32 pr_data_raw; +u32 rsvd; + }; + }; +}; +struct feature_fme_pr {struct feature_header header; +struct feature_fme_pr_ctl control; +struct feature_fme_pr_status status; +struct feature_fme_pr_data data; +u64 error; + +u64 rsvd[16 ]; + +u64 intfc_id_l;/* PR interface Id Low */ +u64 intfc_id_h;/* PR interface Id High */ };/* PORT Header Register Set */ drivers/fpga/intel/fme-main.c +40
-1@@ -23,6 +23,7 @@#include <linux/intel-fpga.h> #include "feature-dev.h" +#include "fme.h" static ssize_t ports_num_show (struct device *dev,struct device_attribute *attr,char *buf)@@ -101,6 +102,10 @@ static struct feature_driver fme_feature_drvs[] = { .ops = &fme_hdr_ops, }, { + .name = FME_FEATURE_PR_MGMT, + .ops = &pr_mgmt_ops, + }, + { .ops = NULL, }, };@@ -182,14 +187,48 @@ static const struct file_operations fme_fops = { .unlocked_ioctl = fme_ioctl, }; +static int fme_dev_init (struct platform_device *pdev) +{ +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *fme; + + fme =devm_kzalloc (&pdev->dev,sizeof (*fme),GFP_KERNEL ); +if (!fme) +return -ENOMEM ; + + fme->pdata = pdata; + +mutex_lock (&pdata->lock); +fpga_pdata_set_private (pdata, fme); +mutex_unlock (&pdata->lock); +return 0 ; +} + +static void fme_dev_destroy (struct platform_device *pdev) +{ +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *fme; + +mutex_lock (&pdata->lock); + fme =fpga_pdata_get_private (pdata); +fpga_pdata_set_private (pdata,NULL ); +mutex_unlock (&pdata->lock); + +devm_kfree (&pdev->dev, fme); +} +static int fme_probe (struct platform_device *pdev) {int ret; - ret =fpga_dev_feature_init (pdev, fme_feature_drvs); + ret =fme_dev_init (pdev);if (ret) goto exit; + ret =fpga_dev_feature_init (pdev, fme_feature_drvs); +if (ret) + goto dev_destroy; + ret =fpga_register_dev_ops (pdev, &fme_fops,THIS_MODULE );if (ret) goto feature_uinit;@@ -198,6 +237,8 @@ static int fme_probe(struct platform_device *pdev)
feature_uinit:fpga_dev_feature_uinit(pdev);drivers/fpga/intel/fme-main.c +2
-0+dev_destroy: +fme_dev_destroy (pdev);exit:
return ret; }drivers/fpga/intel/fme-main.c +1
-0@@ -206,6 +247,7 @@ static int fme_remove(struct platform_device *pdev) {fpga_dev_feature_uinit (pdev);fpga_unregister_dev_ops (pdev); +fme_dev_destroy (pdev);return 0 ; }drivers/fpga/intel/fme-pr.c new file +89
-0@@ -0,0 +1,400 @@ +/* +* Driver for Intel FPGA Management Engine (FME) Partial Reconfiguration +* +* Copyright (C) 2017 Intel Corporation, Inc. +* +* Authors: +* Kang Luwei <[email protected]> +* Xiao Guangrong <[email protected]> +* Joseph Grecco <[email protected]> +* Enno Luebbers <[email protected]> +* Tim Whisonant <[email protected]> +* Ananda Ravuri <[email protected]> +* Christopher Rauer <[email protected]> +* Henry Mitchel <[email protected]> +* +* This work is licensed under a dual BSD/GPLv2 license. When using or +* redistributing this file, you may do so under either license. See the +* LICENSE.BSD file under this directory for the BSD license and see +* the COPYING file in the top-level directory for the GPLv2 license. +*/ + +#include <linux/types.h> +#include <linux/device.h> +#include <linux/vmalloc.h> +#include <linux/uaccess.h> +#include <linux/fpga/fpga-mgr.h> +#include <linux/intel-fpga.h> + +#include "feature-dev.h" +#include "fme.h" + +#define PR_WAIT_TIMEOUT 8000000 + +#define PR_HOST_STATUS_IDLE 0 + +DEFINE_FPGA_PR_ERR_MSG (pr_err_msg); + +static ssize_t interface_id_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +u64 intfc_id_l, intfc_id_h; +struct feature_fme_pr *fme_pr + =get_feature_ioaddr_by_index (dev,FME_FEATURE_ID_PR_MGMT ); + + intfc_id_l =readq (&fme_pr->intfc_id_l); + intfc_id_h =readq (&fme_pr->intfc_id_h); + +return scnprintf (buf,PAGE_SIZE ,"%016llx%016llx\n" , + (unsigned long long )intfc_id_h, + (unsigned long long )intfc_id_l); +} +static DEVICE_ATTR_RO (interface_id); + +static struct attribute *pr_mgmt_attrs[] = { + &dev_attr_interface_id.attr, +NULL , +}; + +struct attribute_group pr_mgmt_attr_group = { + .attrs = pr_mgmt_attrs, + .name ="pr" , +}; + +static u64 +pr_err_handle (struct platform_device *pdev,struct feature_fme_pr *fme_pr) +{ +struct feature_fme_pr_status fme_pr_status; +unsigned long err_code; +u64 fme_pr_error; +int i =0 ; + + fme_pr_status.csr =readq (&fme_pr->status); +if (!fme_pr_status.pr_status) +return 0 ; + + err_code = fme_pr_error =readq (&fme_pr->error); +for_each_set_bit (i, &err_code,PR_MAX_ERR_NUM ) +dev_dbg (&pdev->dev,"%s\n" , pr_err_msg[i]); +writeq (fme_pr_error, &fme_pr->error); +return fme_pr_error; +} + +static int fme_pr_write_init (struct fpga_manager *mgr, +struct fpga_image_info *info,const char *buf,size_t count) +{ +struct fpga_fme *fme = mgr->priv; +struct platform_device *pdev; +struct feature_fme_pr *fme_pr; +struct feature_fme_pr_ctl fme_pr_ctl;drivers/fpga/intel/fme-pr.c line 99
Quoted 10 lines
drivers/fpga/intel/fme-pr.c new file +10
-0+struct feature_fme_pr_status fme_pr_status; + + pdev = fme->pdata->dev; + fme_pr =get_feature_ioaddr_by_index (&pdev->dev, +FME_FEATURE_ID_PR_MGMT ); +if (!fme_pr) +return -EINVAL ; + +if (WARN_ON (info->flags !=FPGA_MGR_PARTIAL_RECONFIG )) +return -EINVAL ;flags is bitmapped so please do:
if (
WARN_ON(info->flags & FPGA_MGR_PARTIAL_RECONFIG))Quoted 123 lines
drivers/fpga/intel/fme-pr.c new file +123
-0+ +dev_dbg (&pdev->dev,"resetting PR before initiated PR\n" ); + + fme_pr_ctl.csr =readq (&fme_pr->control); + fme_pr_ctl.pr_reset =1 ; +writeq (fme_pr_ctl.csr, &fme_pr->control); + + fme_pr_ctl.pr_reset_ack =1 ; + +if (fpga_wait_register_field (pr_reset_ack, fme_pr_ctl, + &fme_pr->control,PR_WAIT_TIMEOUT ,1 )) { +dev_err (&pdev->dev,"maximum PR timeout\n" ); +return -ETIMEDOUT ; + } + + fme_pr_ctl.csr =readq (&fme_pr->control); + fme_pr_ctl.pr_reset =0 ; +writeq (fme_pr_ctl.csr, &fme_pr->control); + +dev_dbg (&pdev->dev, +"waiting for PR resource in HW to be initialized and ready\n" ); + + fme_pr_status.pr_host_status =PR_HOST_STATUS_IDLE ; + +if (fpga_wait_register_field (pr_host_status, fme_pr_status, + &fme_pr->status,PR_WAIT_TIMEOUT ,1 )) { +dev_err (&pdev->dev,"maximum PR timeout\n" ); +return -ETIMEDOUT ; + } + +dev_dbg (&pdev->dev,"check if have any previous PR error\n" ); +pr_err_handle (pdev, fme_pr); +return 0 ; +} + +static int fme_pr_write (struct fpga_manager *mgr, +const char *buf,size_t count) +{ +struct fpga_fme *fme = mgr->priv; +struct platform_device *pdev; +struct feature_fme_pr *fme_pr; +struct feature_fme_pr_ctl fme_pr_ctl; +struct feature_fme_pr_status fme_pr_status; +struct feature_fme_pr_data fme_pr_data; +int delay, pr_credit, i =0 ; + + pdev = fme->pdata->dev; + fme_pr =get_feature_ioaddr_by_index (&pdev->dev, +FME_FEATURE_ID_PR_MGMT ); + +dev_dbg (&pdev->dev,"set PR port ID and start request\n" ); + + fme_pr_ctl.csr =readq (&fme_pr->control); + fme_pr_ctl.pr_regionid = fme->port_id; + fme_pr_ctl.pr_start_req =1 ; +writeq (fme_pr_ctl.csr, &fme_pr->control); + +dev_dbg (&pdev->dev,"pushing data from bitstream to HW\n" ); + + fme_pr_status.csr =readq (&fme_pr->status); + pr_credit = fme_pr_status.pr_credit; + +while (count >0 ) { + delay =0 ; +while (pr_credit <=1 ) { +if (delay++ >PR_WAIT_TIMEOUT ) { +dev_err (&pdev->dev,"maximum try\n" ); +return -ETIMEDOUT ; + } +udelay (1 ); + + fme_pr_status.csr =readq (&fme_pr->status); + pr_credit = fme_pr_status.pr_credit; + }; + +if (count >=4 ) { + fme_pr_data.rsvd =0 ; + fme_pr_data.pr_data_raw = *(((u32 *)buf) + i); +writeq (fme_pr_data.csr, &fme_pr->data); + count -=4 ; + pr_credit--; + i++; + }else { +WARN_ON (1 ); +return -EINVAL ; + } + } + +return 0 ; +} + +static int fme_pr_write_complete (struct fpga_manager *mgr, +struct fpga_image_info *info) +{ +struct fpga_fme *fme = mgr->priv; +struct platform_device *pdev; +struct feature_fme_pr *fme_pr; +struct feature_fme_pr_ctl fme_pr_ctl; + + pdev = fme->pdata->dev; + fme_pr =get_feature_ioaddr_by_index (&pdev->dev, +FME_FEATURE_ID_PR_MGMT ); + + fme_pr_ctl.csr =readq (&fme_pr->control); + fme_pr_ctl.pr_push_complete =1 ; +writeq (fme_pr_ctl.csr, &fme_pr->control); + +dev_dbg (&pdev->dev,"green bitstream push complete\n" ); +dev_dbg (&pdev->dev,"waiting for HW to release PR resource\n" ); + + fme_pr_ctl.pr_start_req =0 ; + +if (fpga_wait_register_field (pr_start_req, fme_pr_ctl, + &fme_pr->control,PR_WAIT_TIMEOUT ,1 )) { +dev_err (&pdev->dev,"maximum try.\n" ); +return -ETIMEDOUT ; + } + +dev_dbg (&pdev->dev,"PR operation complete, checking status\n" ); + fme->pr_err =pr_err_handle (pdev, fme_pr); +if (fme->pr_err) +return -EIO ; +Quoted 8 lines
drivers/fpga/intel/fme-pr.c line 230
Quoted 8 lines
drivers/fpga/intel/fme-pr.c new file +8
-0+dev_dbg (&pdev->dev,"PR done successfully\n" ); +return 0 ; +} + +static enum fpga_mgr_states fme_pr_state (struct fpga_manager *mgr) +{ +return FPGA_MGR_STATE_UNKNOWN ; +}The functions that implement the
fme_pr_opsare really a low level fpga manager driver for the Altera PR IP component. A standalone version of such a driver has been reviewed and Acked. See the links below. Could this file use those functions and remove this code?
Quoted 5 lines
http://marc.info/?l=linux-kernel&m=149019678925564&w=2
http://marc.info/?l=linux-kernel&m=149019654225457&w=2
http://marc.info/?l=linux-kernel&m=149019598025274&w=2
http://marc.info/?l=linux-kernel&m=149013051007149&w=2
Thanks for the info, I just checked these code quickly, but it seems the register definitions are totally different, so I feel that we may not be able to reuse this driver.
Thanks
Hao
Re: [PATCH 11/16] fpga: intel: fme: add partial reconfiguration sub feature support
In reply to Alan TullQuoted 11 lines · Alan Tull
Quoted 8 lines · Wu Hao
From: Kang Luwei <[email protected]>
Partial Reconfiguration (PR) is the most important function for FME. It allows reconfiguration for given Port/Accelerated Function Unit (AFU).
This patch adds support for PR sub feature. In this patch, it registers a
fpga_mgrand implementsfpga_manager_ops, and invokefpga_mgr_buf_loadfor PR operation once PR request received via ioctl.The code that invokes
fpga_mgr_buf_loadshould be a different layer.
Please see my feedback below.
Quoted 314 lines
Quoted 301 lines
Below user space
interfaces are exposed by this sub feature.Sysfs interface:
* /sys/class/fpga/<fpga.x>/<intel-fpga-fme.x>/interface_id Read-only. Indicate the hardware interface information. Userspace applications need to check this interface to select correct green bitstream format before PR.Ioctl interface:
*FPGA_FME_PORT_PR
Do partial reconfiguration per information from userspace, including target port(AFU), buffer size and address info. It returns the PR status (PR error code if failed) to userspace.Signed-off-by Tim Whisonant <[email protected]>Signed-off-by Enno Luebbers <[email protected]>Signed-off-by Shiva Rao <[email protected]>Signed-off-by Christopher Rauer <[email protected]>Signed-off-by Alan Tull <[email protected]>Signed-off-by Kang Luwei <[email protected]>Signed-off-by Xiao Guangrong <[email protected]>Signed-off-by Wu Hao <[email protected]>--- drivers/fpga/intel/Makefile | 2 +- drivers/fpga/intel/feature-dev.h | 58 ++++++ drivers/fpga/intel/fme-main.c | 44 ++++- drivers/fpga/intel/fme-pr.c | 400 +++++++++++++++++++++++++++++++++++++++ drivers/fpga/intel/fme.h | 32 ++++ include/uapi/linux/intel-fpga.h | 44 +++++ 6 files changed, 578 insertions(+), 2 deletions(-) create mode 100644 drivers/fpga/intel/fme-pr.c create mode 100644 drivers/fpga/intel/fme.hdrivers/fpga/intel/Makefile +1
-1@@ -2,4 +2,4 @@ obj-$(CONFIG_INTEL_FPGA_PCI) += intel-fpga-pci.o obj-$(CONFIG_INTEL_FPGA_FME) += intel-fpga-fme.o intel-fpga-pci-objs := pcie.o feature-dev.o -intel-fpga-fme-objs := fme-main.o +intel-fpga-fme-objs := fme-main.o fme-pr.odrivers/fpga/intel/feature-dev.h +58
-0@@ -150,8 +150,66 @@ struct feature_fme_err { };/* FME Partial Reconfiguration Sub Feature Register Set */ +/* FME PR Control Register */ +struct feature_fme_pr_ctl { +union { +u64 csr; +struct { +u8 pr_reset:1 ;/* Reset PR Engine */ +u8 rsvdz1:3 ; +u8 pr_reset_ack:1 ;/* Reset PR Engine Ack */ +u8 rsvdz2:3 ; +u8 pr_regionid:2 ;/* PR Region ID */ +u8 rsvdz3:2 ; +u8 pr_start_req:1 ;/* PR Start Request */ +u8 pr_push_complete:1 ;/* PR Data push complete */ +u8 pr_kind:1 ;/* Load Customer or Intel GBS */ +u32 rsvdz4:17 ; +u32 config_data; + }; + }; +}; + +/* FME PR Status Register */ +struct feature_fme_pr_status { +union { +u64 csr; +struct { +u16 pr_credit:9 ;/* Number of PR Credits */ +u8 rsvdz1:7 ; +u8 pr_status:1 ;/* PR Operation status */ +u8 rsvdz2:3 ; +u8 pr_ctrlr_status:3 ;/* Controller status */ +u8 rsvdz3:1 ; +u8 pr_host_status:4 ;/* PR Host status */ +u64 rsvdz4:36 ; + }; + }; +}; + +/* FME PR Data Register */ +struct feature_fme_pr_data { +union { +u64 csr; +struct { +/* PR data from the raw-binary file */ +u32 pr_data_raw; +u32 rsvd; + }; + }; +}; +struct feature_fme_pr {struct feature_header header; +struct feature_fme_pr_ctl control; +struct feature_fme_pr_status status; +struct feature_fme_pr_data data; +u64 error; + +u64 rsvd[16 ]; + +u64 intfc_id_l;/* PR interface Id Low */ +u64 intfc_id_h;/* PR interface Id High */ };/* PORT Header Register Set */ drivers/fpga/intel/fme-main.c +43
-1@@ -23,6 +23,7 @@#include <linux/intel-fpga.h> #include "feature-dev.h" +#include "fme.h" static ssize_t ports_num_show (struct device *dev,struct device_attribute *attr,char *buf)@@ -101,6 +102,10 @@ static struct feature_driver fme_feature_drvs[] = { .ops = &fme_hdr_ops, }, { + .name = FME_FEATURE_PR_MGMT, + .ops = &pr_mgmt_ops, + }, + { .ops = NULL, }, };@@ -182,14 +187,48 @@ static const struct file_operations fme_fops = { .unlocked_ioctl = fme_ioctl, }; +static int fme_dev_init (struct platform_device *pdev) +{ +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *fme; + + fme =devm_kzalloc (&pdev->dev,sizeof (*fme),GFP_KERNEL ); +if (!fme) +return -ENOMEM ; + + fme->pdata = pdata; + +mutex_lock (&pdata->lock); +fpga_pdata_set_private (pdata, fme); +mutex_unlock (&pdata->lock); +return 0 ; +} + +static void fme_dev_destroy (struct platform_device *pdev) +{ +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *fme; + +mutex_lock (&pdata->lock); + fme =fpga_pdata_get_private (pdata); +fpga_pdata_set_private (pdata,NULL ); +mutex_unlock (&pdata->lock); + +devm_kfree (&pdev->dev, fme); +} +static int fme_probe (struct platform_device *pdev) {int ret; - ret =fpga_dev_feature_init (pdev, fme_feature_drvs); + ret =fme_dev_init (pdev);if (ret) goto exit; + ret =fpga_dev_feature_init (pdev, fme_feature_drvs); +if (ret) + goto dev_destroy; + ret =fpga_register_dev_ops (pdev, &fme_fops,THIS_MODULE );if (ret) goto feature_uinit;@@ -198,6 +237,8 @@ static int fme_probe(struct platform_device *pdev) feature_uinit:fpga_dev_feature_uinit (pdev); +dev_destroy: +fme_dev_destroy (pdev); exit:return ret; }@@ -206,6 +247,7 @@ static int fme_remove(struct platform_device *pdev) {fpga_dev_feature_uinit (pdev);fpga_unregister_dev_ops (pdev); +fme_dev_destroy (pdev);return 0 ; }drivers/fpga/intel/fme-pr.c new file +89
-0@@ -0,0 +1,400 @@ +/* +* Driver for Intel FPGA Management Engine (FME) Partial Reconfiguration +* +* Copyright (C) 2017 Intel Corporation, Inc. +* +* Authors: +* Kang Luwei <[email protected]> +* Xiao Guangrong <[email protected]> +* Joseph Grecco <[email protected]> +* Enno Luebbers <[email protected]> +* Tim Whisonant <[email protected]> +* Ananda Ravuri <[email protected]> +* Christopher Rauer <[email protected]> +* Henry Mitchel <[email protected]> +* +* This work is licensed under a dual BSD/GPLv2 license. When using or +* redistributing this file, you may do so under either license. See the +* LICENSE.BSD file under this directory for the BSD license and see +* the COPYING file in the top-level directory for the GPLv2 license. +*/ + +#include <linux/types.h> +#include <linux/device.h> +#include <linux/vmalloc.h> +#include <linux/uaccess.h> +#include <linux/fpga/fpga-mgr.h> +#include <linux/intel-fpga.h> + +#include "feature-dev.h" +#include "fme.h" + +#define PR_WAIT_TIMEOUT 8000000 + +#define PR_HOST_STATUS_IDLE 0 + +DEFINE_FPGA_PR_ERR_MSG (pr_err_msg); + +static ssize_t interface_id_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +u64 intfc_id_l, intfc_id_h; +struct feature_fme_pr *fme_pr + =get_feature_ioaddr_by_index (dev,FME_FEATURE_ID_PR_MGMT ); + + intfc_id_l =readq (&fme_pr->intfc_id_l); + intfc_id_h =readq (&fme_pr->intfc_id_h); + +return scnprintf (buf,PAGE_SIZE ,"%016llx%016llx\n" , + (unsigned long long )intfc_id_h, + (unsigned long long )intfc_id_l); +} +static DEVICE_ATTR_RO (interface_id); + +static struct attribute *pr_mgmt_attrs[] = { + &dev_attr_interface_id.attr, +NULL , +}; + +struct attribute_group pr_mgmt_attr_group = { + .attrs = pr_mgmt_attrs, + .name ="pr" , +}; + +static u64 +pr_err_handle (struct platform_device *pdev,struct feature_fme_pr *fme_pr) +{ +struct feature_fme_pr_status fme_pr_status; +unsigned long err_code; +u64 fme_pr_error; +int i =0 ; + + fme_pr_status.csr =readq (&fme_pr->status); +if (!fme_pr_status.pr_status) +return 0 ; + + err_code = fme_pr_error =readq (&fme_pr->error); +for_each_set_bit (i, &err_code,PR_MAX_ERR_NUM ) +dev_dbg (&pdev->dev,"%s\n" , pr_err_msg[i]); +writeq (fme_pr_error, &fme_pr->error); +return fme_pr_error; +} + +static int fme_pr_write_init (struct fpga_manager *mgr, +struct fpga_image_info *info,const char *buf,size_t count) +{ +struct fpga_fme *fme = mgr->priv; +struct platform_device *pdev; +struct feature_fme_pr *fme_pr; +struct feature_fme_pr_ctl fme_pr_ctl;drivers/fpga/intel/fme-pr.c line 99
Quoted 10 lines
drivers/fpga/intel/fme-pr.c new file +10
-0+struct feature_fme_pr_status fme_pr_status; + + pdev = fme->pdata->dev; + fme_pr =get_feature_ioaddr_by_index (&pdev->dev, +FME_FEATURE_ID_PR_MGMT ); +if (!fme_pr) +return -EINVAL ; + +if (WARN_ON (info->flags !=FPGA_MGR_PARTIAL_RECONFIG )) +return -EINVAL ;flags is bitmapped so please do:
Quoted 1 line
if (
WARN_ON(info->flags & FPGA_MGR_PARTIAL_RECONFIG))
Thanks for the review.
Will fix this in the next version.
Quoted 141 lines
Quoted 130 lines
drivers/fpga/intel/fme-pr.c new file +129
-0+ +dev_dbg (&pdev->dev,"resetting PR before initiated PR\n" ); + + fme_pr_ctl.csr =readq (&fme_pr->control); + fme_pr_ctl.pr_reset =1 ; +writeq (fme_pr_ctl.csr, &fme_pr->control); + + fme_pr_ctl.pr_reset_ack =1 ; + +if (fpga_wait_register_field (pr_reset_ack, fme_pr_ctl, + &fme_pr->control,PR_WAIT_TIMEOUT ,1 )) { +dev_err (&pdev->dev,"maximum PR timeout\n" ); +return -ETIMEDOUT ; + } + + fme_pr_ctl.csr =readq (&fme_pr->control); + fme_pr_ctl.pr_reset =0 ; +writeq (fme_pr_ctl.csr, &fme_pr->control); + +dev_dbg (&pdev->dev, +"waiting for PR resource in HW to be initialized and ready\n" ); + + fme_pr_status.pr_host_status =PR_HOST_STATUS_IDLE ; + +if (fpga_wait_register_field (pr_host_status, fme_pr_status, + &fme_pr->status,PR_WAIT_TIMEOUT ,1 )) { +dev_err (&pdev->dev,"maximum PR timeout\n" ); +return -ETIMEDOUT ; + } + +dev_dbg (&pdev->dev,"check if have any previous PR error\n" ); +pr_err_handle (pdev, fme_pr); +return 0 ; +} + +static int fme_pr_write (struct fpga_manager *mgr, +const char *buf,size_t count) +{ +struct fpga_fme *fme = mgr->priv; +struct platform_device *pdev; +struct feature_fme_pr *fme_pr; +struct feature_fme_pr_ctl fme_pr_ctl; +struct feature_fme_pr_status fme_pr_status; +struct feature_fme_pr_data fme_pr_data; +int delay, pr_credit, i =0 ; + + pdev = fme->pdata->dev; + fme_pr =get_feature_ioaddr_by_index (&pdev->dev, +FME_FEATURE_ID_PR_MGMT ); + +dev_dbg (&pdev->dev,"set PR port ID and start request\n" ); + + fme_pr_ctl.csr =readq (&fme_pr->control); + fme_pr_ctl.pr_regionid = fme->port_id; + fme_pr_ctl.pr_start_req =1 ; +writeq (fme_pr_ctl.csr, &fme_pr->control); + +dev_dbg (&pdev->dev,"pushing data from bitstream to HW\n" ); + + fme_pr_status.csr =readq (&fme_pr->status); + pr_credit = fme_pr_status.pr_credit; + +while (count >0 ) { + delay =0 ; +while (pr_credit <=1 ) { +if (delay++ >PR_WAIT_TIMEOUT ) { +dev_err (&pdev->dev,"maximum try\n" ); +return -ETIMEDOUT ; + } +udelay (1 ); + + fme_pr_status.csr =readq (&fme_pr->status); + pr_credit = fme_pr_status.pr_credit; + }; + +if (count >=4 ) { + fme_pr_data.rsvd =0 ; + fme_pr_data.pr_data_raw = *(((u32 *)buf) + i); +writeq (fme_pr_data.csr, &fme_pr->data); + count -=4 ; + pr_credit--; + i++; + }else { +WARN_ON (1 ); +return -EINVAL ; + } + } + +return 0 ; +} + +static int fme_pr_write_complete (struct fpga_manager *mgr, +struct fpga_image_info *info) +{ +struct fpga_fme *fme = mgr->priv; +struct platform_device *pdev; +struct feature_fme_pr *fme_pr; +struct feature_fme_pr_ctl fme_pr_ctl; + + pdev = fme->pdata->dev; + fme_pr =get_feature_ioaddr_by_index (&pdev->dev, +FME_FEATURE_ID_PR_MGMT ); + + fme_pr_ctl.csr =readq (&fme_pr->control); + fme_pr_ctl.pr_push_complete =1 ; +writeq (fme_pr_ctl.csr, &fme_pr->control); + +dev_dbg (&pdev->dev,"green bitstream push complete\n" ); +dev_dbg (&pdev->dev,"waiting for HW to release PR resource\n" ); + + fme_pr_ctl.pr_start_req =0 ; + +if (fpga_wait_register_field (pr_start_req, fme_pr_ctl, + &fme_pr->control,PR_WAIT_TIMEOUT ,1 )) { +dev_err (&pdev->dev,"maximum try.\n" ); +return -ETIMEDOUT ; + } + +dev_dbg (&pdev->dev,"PR operation complete, checking status\n" ); + fme->pr_err =pr_err_handle (pdev, fme_pr); +if (fme->pr_err) +return -EIO ; + +dev_dbg (&pdev->dev,"PR done successfully\n" ); +return 0 ; +} + +static enum fpga_mgr_states fme_pr_state (struct fpga_manager *mgr) +{drivers/fpga/intel/fme-pr.c line 238
Quoted 10 lines
drivers/fpga/intel/fme-pr.c new file +10
-0+return FPGA_MGR_STATE_UNKNOWN ; +} + +static const struct fpga_manager_ops fme_pr_ops = { + .write_init = fme_pr_write_init, + .write = fme_pr_write, + .write_complete = fme_pr_write_complete, + .state = fme_pr_state, +}; +
Quoted 8 lines
The following
fme_pr()function shouldn't be in a fpga-mgr driver. It is calling
the framework that this driver is registered with.
A fpga-mgr low level driver is supposed to be a very low level driver. This function is controlling the port and calling fpga-mgr layer to do the programming. There should be a layer above the fpga-mgr and fpga-bridge that coordinates these things. I.e. can you use my proposed fpga-region code?
Hm.. as mentioned in the intel-fpga.txt documentation 'open discussion'. Current FME doesn't use fpga-region as related patches are not merged. But we will make the related changes to let FME create all fpga-regions, bridges and managers for PR function on given Intel FPGA device per suggestion.
Please notice below fme_pr is still needed to provide ioctl interface to enduser for PR, it should invoke fpga_region_program_fpga or equivalent for PR instead of fpga_mgr_buf_load then.
And if in the future, the sysfs for PR is ready, then fme_pr may not be needed, as user can do PR via fpga-region sysfs interface.
Thanks
Hao
Quoted 274 lines
Quoted 268 lines
drivers/fpga/intel/fme-pr.c new file +162
-0+static int fme_pr (struct platform_device *pdev,unsigned long arg) +{ +void __user *argp = (void __user *)arg; +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *fme; +struct fpga_manager *mgr; +struct feature_fme_header *fme_hdr; +struct feature_fme_capability fme_capability; +struct fpga_image_info info; +struct fpga_fme_port_pr port_pr; +struct platform_device *port; +unsigned long minsz; +void *buf =NULL ; +int ret =0 ; + + minsz = offsetofend(struct fpga_fme_port_pr, status); + +if (copy_from_user (&port_pr, argp, minsz)) +return -EFAULT ; + +if (port_pr.argsz < minsz || port_pr.flags) +return -EINVAL ; + +if (!IS_ALIGNED (port_pr.buffer_size,4 )) +return -EINVAL ; + +/* get fme header region */ + fme_hdr =get_feature_ioaddr_by_index (&pdev->dev, +FME_FEATURE_ID_HEADER ); +if (WARN_ON (!fme_hdr)) +return -EINVAL ; + +/* check port id */ + fme_capability.csr =readq (&fme_hdr->capability); +if (port_pr.port_id >= fme_capability.num_ports) { +dev_dbg (&pdev->dev,"port number more than maximum\n" ); +return -EINVAL ; + } + +if (!access_ok (VERIFY_READ , port_pr.buffer_address, + port_pr.buffer_size)) +return -EFAULT ; + + buf =vmalloc (port_pr.buffer_size); +if (!buf) +return -ENOMEM ; + +if (copy_from_user (buf, (void __user *)port_pr.buffer_address, + port_pr.buffer_size)) { + ret = -EFAULT ; + goto free_exit; + } + +memset (&info,0 ,sizeof (struct fpga_image_info )); + info.flags =FPGA_MGR_PARTIAL_RECONFIG ; + + mgr =fpga_mgr_get (&pdev->dev); +if (IS_ERR (mgr)) { + ret =PTR_ERR (mgr); + goto free_exit; + } + +mutex_lock (&pdata->lock); + fme =fpga_pdata_get_private (pdata); +/* fme device has been unregistered. */ +if (!fme) { + ret = -EINVAL ; + goto unlock_exit; + } + + fme->pr_err =0 ; + fme->port_id = port_pr.port_id; + +/* Find and get port device by index */ + port = pdata->fpga_for_each_port (pdev, &fme->port_id, + fpga_port_check_id); +WARN_ON (!port); + +/* Disable Port before PR */ +fpga_port_disable (port); + + ret =fpga_mgr_buf_load (mgr, &info, buf, port_pr.buffer_size); + port_pr.status = fme->pr_err; + +/* Re-enable Port after PR finished */ +fpga_port_enable (port); + +put_device (&port->dev); + +unlock_exit: +mutex_unlock (&pdata->lock); +fpga_mgr_put (mgr); +free_exit: +vfree (buf); +if (copy_to_user ((void __user *)arg, &port_pr, minsz)) +return -EFAULT ; +return ret; +} + +static int fpga_fme_pr_probe (struct platform_device *pdev) +{ +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *priv; +int ret; + +mutex_lock (&pdata->lock); + priv =fpga_pdata_get_private (pdata); + ret =fpga_mgr_register (&pdata->dev->dev, +"Intel FPGA Manager" , &fme_pr_ops, priv); +mutex_unlock (&pdata->lock); + +return ret; +} + +static int fpga_fme_pr_remove (struct platform_device *pdev) +{ +fpga_mgr_unregister (&pdev->dev); +return 0 ; +} + +static int pr_mgmt_init (struct platform_device *pdev,struct feature *feature) +{ +int ret; + + ret =fpga_fme_pr_probe (pdev); +if (ret) +return ret; + + ret =sysfs_create_group (&pdev->dev.kobj, &pr_mgmt_attr_group); +if (ret) +fpga_fme_pr_remove (pdev); + +return ret; +} + +static void pr_mgmt_uinit (struct platform_device *pdev,struct feature *feature) +{ +sysfs_remove_group (&pdev->dev.kobj, &pr_mgmt_attr_group); +fpga_fme_pr_remove (pdev); +} + +static long fme_pr_ioctl (struct platform_device *pdev,struct feature *feature, +unsigned int cmd,unsigned long arg) +{ +long ret; + +switch (cmd) { +case FPGA_FME_PORT_PR : + ret =fme_pr (pdev, arg); +break ; +default : + ret = -ENODEV ; + } + +return ret; +} + +struct feature_ops pr_mgmt_ops = { + .init = pr_mgmt_init, + .uinit = pr_mgmt_uinit, + .ioctl = fme_pr_ioctl, +};drivers/fpga/intel/fme.h new file +32
-0@@ -0,0 +1,32 @@ +/* +* Header file for Intel FPGA Management Engine (FME) Driver +* +* Copyright (C) 2017 Intel Corporation, Inc. +* +* Authors: +* Kang Luwei <[email protected]> +* Xiao Guangrong <[email protected]> +* Joseph Grecco <[email protected]> +* Enno Luebbers <[email protected]> +* Tim Whisonant <[email protected]> +* Ananda Ravuri <[email protected]> +* Henry Mitchel <[email protected]> +* +* This work is licensed under a dual BSD/GPLv2 license. When using or +* redistributing this file, you may do so under either license. See the +* LICENSE.BSD file under this directory for the BSD license and see +* the COPYING file in the top-level directory for the GPLv2 license. +*/ + +#ifndef __INTEL_FME_H +#define __INTEL_FME_H + +struct fpga_fme { +u8 port_id; +u64 pr_err; +struct feature_platform_data *pdata; +}; + +extern struct feature_ops pr_mgmt_ops; + +#endif include/uapi/linux/intel-fpga.h +44
-1@@ -18,6 +18,8 @@#ifndef _UAPI_LINUX_INTEL_FPGA_H#define _UAPI_LINUX_INTEL_FPGA_H +#include <linux/types.h> +#define FPGA_API_VERSION 0/* @@ -30,6 +32,7 @@#define FPGA_MAGIC 0xB6#define FPGA_BASE 0 +#define FME_BASE 0x80/** * FPGA_GET_API_VERSION - _IO(FPGA_MAGIC, FPGA_BASE + 0) @@ -49,4 +52,45 @@#define FPGA_CHECK_EXTENSION _IO(FPGA_MAGIC, FPGA_BASE + 1) +/* IOCTLs for FME file descriptor */ + +/** +* FPGA_FME_PORT_PR - _IOWR(FPGA_MAGIC, FME_BASE + 0, struct fpga_fme_port_pr) +* +* Driver does Partial Reconfiguration based on Port ID and Buffer (Image) +* provided by caller. +* Return: 0 on success, -errno on failure. +* If FPGA_FME_PORT_PR returns -EIO, that indicates the HW has detected +* some errors during PR, under this case, the user can fetch HW error code +* from fpga_fme_port_pr.status. Each bit on the error code is used as the +* index for the array created by DEFINE_FPGA_PR_ERR_MSG(). +* Otherwise, it is always zero. +*/ + +#define DEFINE_FPGA_PR_ERR_MSG (_name_) \ +static const char * const _name_[] = { \ + "PR operation error detected", \ + "PR CRC error detected", \ + "PR incompatiable bitstream error detected", \ + "PR IP protocol error detected", \ + "PR FIFO overflow error detected", \ + "Reserved", \ + "PR secure load error detected", \ +} + +#define PR_MAX_ERR_NUM 7 + +struct fpga_fme_port_pr { +/* Input */ +__u32 argsz;/* Structure length */ +__u32 flags;/* Zero for now */ +__u32 port_id; +__u32 buffer_size; +__u64 buffer_address;/* Userspace address to the buffer for PR */ +/* Output */ +__u64 status;/* HW error code if ioctl returns -EIO */ +}; + +#define FPGA_FME_PORT_PR _IO(FPGA_MAGIC, FME_BASE + 0) +#endif /* _UAPI_INTEL_FPGA_H */ --Quoted 2 lines
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-fpga" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 12/16 fpga: intel: add FPGA Accelerated Function Unit driver basic framework
In reply to Wu HaoOn Intel FPGA devices, the Accelerated Function Unit (AFU), can be reprogrammed for different functions. It connects to the FPGA infrastructure("blue bistream") via a Port. Port CSRs are implemented separately from the AFU CSRs to provide control and status of the Port. Once valid green bitstream is programmed into the AFU, it allows access to the AFU CSRs in the AFU MMIO space.
This patch only implements basic driver framework for AFU, including device file operation framework.
--- drivers/fpga/intel/Kconfig | 9 +++ drivers/fpga/intel/Makefile | 2 + drivers/fpga/intel/afu-main.c | 161 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 172 insertions(+) create mode 100644 drivers/fpga/intel/afu-main.c
drivers/fpga/intel/Kconfig +9 -0
@@ -32,4 +32,13 @@ config INTEL_FPGA_FME all FPGA platform level management features. There shall be 1 FME per Intel FPGA. +config INTEL_FPGA_AFU + tristate "Intel FPGA AFU Driver" + depends on INTEL_FPGA_PCI + help + This is the driver for FPGA Accelerated Function Unit (AFU) which + implements AFU and Port management features. A User AFU connects + to the FPGA infrastructure via a Port. There may be more than 1 + Port/AFU per Intel FPGA. + endif
drivers/fpga/intel/Makefile +2 -0
@@ -1,5 +1,7 @@ obj-$(CONFIG_INTEL_FPGA_PCI) += intel-fpga-pci.o obj-$(CONFIG_INTEL_FPGA_FME) += intel-fpga-fme.o +obj-$(CONFIG_INTEL_FPGA_AFU) += intel-fpga-afu.o intel-fpga-pci-objs := pcie.o feature-dev.o intel-fpga-fme-objs := fme-main.o fme-pr.o +intel-fpga-afu-objs := afu-main.o
drivers/fpga/intel/afu-main.c new file +161 -0
161 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 13/16 fpga: intel: afu: add header sub feature support
In reply to Wu HaoThe header register set is always present for the Port/AFU, it is mainly for capability, control and status of the ports that AFU connected to.
This patch implements header sub feature support. Below user interfaces are created by this patch.
Sysfs interface:
* /sys/class/fpga/<fpga.x>/<intel-fpga-port.x>/id
Read-only. Port ID.
Ioctl interface:
* FPGA_PORT_RESET
Reset the FPGA AFU Port.
--- drivers/fpga/intel/afu-main.c | 44 ++++++++++++++++++++++++++++++++++++++++- include/uapi/linux/intel-fpga.h | 14 +++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-)
drivers/fpga/intel/afu-main.c +43 -1
@@ -20,25 +20,66 @@#include <linux/kernel.h> #include <linux/module.h> +#include <linux/intel-fpga.h> #include "feature-dev.h" +static ssize_t +id_show (struct device *dev,struct device_attribute *attr,char *buf) +{ +int id =fpga_port_id (to_platform_device (dev)); + +return scnprintf (buf,PAGE_SIZE ,"%d\n" , id); +} +static DEVICE_ATTR_RO (id); + +static const struct attribute *port_hdr_attrs[] = { + &dev_attr_id.attr, +NULL , +}; +static int port_hdr_init (struct platform_device *pdev,struct feature *feature) {dev_dbg (&pdev->dev,"PORT HDR Init.\n" ); -return 0 ; +fpga_port_reset (pdev); + +return sysfs_create_files (&pdev->dev.kobj, port_hdr_attrs); }static void port_hdr_uinit (struct platform_device *pdev,struct feature *feature) {dev_dbg (&pdev->dev,"PORT HDR UInit.\n" ); + +sysfs_remove_files (&pdev->dev.kobj, port_hdr_attrs); +} + +static long +port_hdr_ioctl (struct platform_device *pdev,struct feature *feature, +unsigned int cmd,unsigned long arg) +{ +long ret; + +switch (cmd) { +case FPGA_PORT_RESET : +if (!arg) + ret =fpga_port_reset (pdev); +else + ret = -EINVAL ; +break ; +default : +dev_dbg (&pdev->dev,"%x cmd not handled" , cmd); + ret = -ENODEV ; + } + +return ret; }struct feature_ops port_hdr_ops = { .init = port_hdr_init, .uinit = port_hdr_uinit, + .ioctl = port_hdr_ioctl, };static struct feature_driver port_feature_drvs[] = {
@@ -78,6 +119,7 @@ static int afu_release(struct inode *inode, struct file *filp)dev_dbg (&pdev->dev,"Device File Release\n" ); +fpga_port_reset (pdev);feature_dev_use_end (pdata);return 0 ; }
include/uapi/linux/intel-fpga.h +14 -0
@@ -32,8 +32,11 @@#define FPGA_MAGIC 0xB6#define FPGA_BASE 0 +#define PORT_BASE 0x40#define FME_BASE 0x80 +/* Common IOCTLs for both FME and AFU file descriptor */ +/** * FPGA_GET_API_VERSION - _IO(FPGA_MAGIC, FPGA_BASE + 0) *
@@ -52,6 +55,17 @@#define FPGA_CHECK_EXTENSION _IO(FPGA_MAGIC, FPGA_BASE + 1) +/* IOCTLs for AFU file descriptor */ + +/** +* FPGA_PORT_RESET - _IO(FPGA_MAGIC, PORT_BASE + 0) +* +* Reset the FPGA AFU Port. No parameters are supported. +* Return: 0 on success, -errno of failure +*/ + +#define FPGA_PORT_RESET _IO(FPGA_MAGIC, PORT_BASE + 0) +/* IOCTLs for FME file descriptor */ /**
Signature · 1 line
2.7.4
PATCH 14/16 fpga: intel: afu add FPGA_GET_API_VERSION/CHECK_EXTENSION ioctls support
In reply to Wu HaoFPGA_GET_API_VERSION and FPGA_CHECK_EXTENSION ioctls are common ones which need to be supported by all feature devices drivers including FME and AFU. This patch implements above 2 ioctls in Intel FPGA Accelerated Function Unit (AFU) driver.
--- drivers/fpga/intel/afu-main.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/fpga/intel/afu-main.c +11 -0
@@ -124,6 +124,13 @@ static int afu_release(struct inode *inode, struct file *filp)return 0 ; } +static long afu_ioctl_check_extension (struct feature_platform_data *pdata, +unsigned long arg) +{ +/* No extension support for now */ +return 0 ; +} +static long afu_ioctl (struct file *filp,unsigned int cmd,unsigned long arg) {struct platform_device *pdev = filp->private_data;
@@ -134,6 +141,10 @@ static long afu_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)dev_dbg (&pdev->dev,"%s cmd 0x%x\n" , __func__, cmd);switch (cmd) { +case FPGA_GET_API_VERSION : +return FPGA_API_VERSION ; +case FPGA_CHECK_EXTENSION : +return afu_ioctl_check_extension (pdata, arg);default :/* * Let sub-feature's ioctl function to handle the cmd
Signature · 1 line
2.7.4
PATCH 15/16 fpga: intel: afu: add user afu sub feature support
In reply to Wu HaoFrom: Xiao Guangrong <[email protected]>
User Accelerated Function Unit sub feature exposes the MMIO region of the AFU. After valid green bitstream (GBS) is programmed and port is enabled, then this MMIO region could be accessed.
This patch adds support to enumerate the AFU MMIO region and expose it to userspace via mmap file operation. Below interfaces are exposed to user:
Sysfs interface:
* /sys/class/fpga/<fpga.x>/<intel-fpga-port.x>/afu_id Read-only. Indicate which green bitstream is programmed to this AFU.
Ioctl interfaces:
* FPGA_PORT_GET_INFO
Provide info to userspace on the number of supported region. Only UAFU region is supported now.
* FPGA_PORT_GET_REGION_INFO
Provide region information, including access permission, region size, offset from the start of device fd.
--- drivers/fpga/intel/Makefile | 2 +- drivers/fpga/intel/afu-main.c | 204 +++++++++++++++++++++++++++++++++++++++- drivers/fpga/intel/afu-region.c | 129 +++++++++++++++++++++++++ drivers/fpga/intel/afu.h | 54 +++++++++++ include/uapi/linux/intel-fpga.h | 47 +++++++++ 5 files changed, 432 insertions(+), 4 deletions(-) create mode 100644 drivers/fpga/intel/afu-region.c create mode 100644 drivers/fpga/intel/afu.h
drivers/fpga/intel/Makefile +1 -1
@@ -4,4 +4,4 @@ obj-$(CONFIG_INTEL_FPGA_AFU) += intel-fpga-afu.o intel-fpga-pci-objs := pcie.o feature-dev.o intel-fpga-fme-objs := fme-main.o fme-pr.o -intel-fpga-afu-objs := afu-main.o +intel-fpga-afu-objs := afu-main.o afu-region.o
drivers/fpga/intel/afu-main.c +201 -3
267 lines not on this page · raw message
drivers/fpga/intel/afu-region.c new file +129 -0
129 lines not on this page · raw message
drivers/fpga/intel/afu.h new file +54 -0
54 lines not on this page · raw message
include/uapi/linux/intel-fpga.h +47 -0
53 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 16/16 fpga: intel: afu: add FPGA_PORT_DMA_MAP/UNMAP ioctls support
In reply to Wu HaoDMA memory regions are required for Accelerated Function Unit (AFU) usage. These two ioctls allow user space applications to map user memory regions for dma, and unmap them after use. Iova is returned from driver to user space application via FPGA_PORT_DMA_MAP ioctl. Application needs to unmap it after use, otherwise, driver will unmap them in device file release operation.
All the mapped regions are managed via a rb tree.
Ioctl interfaces:
* FPGA_PORT_DMA_MAP
Do the dma mapping per user_addr and length which provided by user. Return iova in provided struct afu_port_dma_map.
* FPGA_PORT_DMA_UNMAP
Unmap the dma region per iova provided by user.
--- drivers/fpga/intel/Makefile | 2 +- drivers/fpga/intel/afu-dma-region.c | 373 ++++++++++++++++++++++++++++++++++++ drivers/fpga/intel/afu-main.c | 61 +++++- drivers/fpga/intel/afu.h | 18 ++ include/uapi/linux/intel-fpga.h | 37 ++++ 5 files changed, 489 insertions(+), 2 deletions(-) create mode 100644 drivers/fpga/intel/afu-dma-region.c
drivers/fpga/intel/Makefile +1 -1
@@ -4,4 +4,4 @@ obj-$(CONFIG_INTEL_FPGA_AFU) += intel-fpga-afu.o intel-fpga-pci-objs := pcie.o feature-dev.o intel-fpga-fme-objs := fme-main.o fme-pr.o -intel-fpga-afu-objs := afu-main.o afu-region.o +intel-fpga-afu-objs := afu-main.o afu-region.o afu-dma-region.o
drivers/fpga/intel/afu-dma-region.c new file +373 -0
373 lines not on this page · raw message
drivers/fpga/intel/afu-main.c +60 -1
91 lines not on this page · raw message
drivers/fpga/intel/afu.h +18 -0
@@ -32,11 +32,21 @@ struct fpga_afu_region {struct list_head node; }; +struct fpga_afu_dma_region { +u64 user_addr; +u64 length; +u64 iova; +struct page **pages; +struct rb_node node; +bool in_use; +}; +struct fpga_afu {u64 region_cur_offset;int num_regions;u8 num_umsgs;struct list_head regions; +struct rb_root dma_regions;struct feature_platform_data *pdata; };
@@ -51,4 +61,12 @@ int afu_get_region_by_offset(struct feature_platform_data *pdata, u64 offset, u64 size, struct fpga_afu_region *pregion); +void afu_dma_region_init (struct feature_platform_data *pdata); +void afu_dma_region_destroy (struct feature_platform_data *pdata); +long afu_dma_map_region (struct feature_platform_data *pdata, +u64 user_addr,u64 length,u64 *iova); +long afu_dma_unmap_region (struct feature_platform_data *pdata,u64 iova); +struct fpga_afu_dma_region *afu_dma_region_find ( +struct feature_platform_data *pdata,u64 iova,u64 size); +#endif
include/uapi/linux/intel-fpga.h +37 -0
@@ -113,6 +113,43 @@ struct fpga_port_region_info {#define FPGA_PORT_GET_REGION_INFO _IO(FPGA_MAGIC, PORT_BASE + 2) +/** +* FPGA_PORT_DMA_MAP - _IOWR(FPGA_MAGIC, PORT_BASE + 3, +* struct fpga_port_dma_map) +* +* Map the dma memory per user_addr and length which are provided by caller. +* Driver fills the iova in provided struct afu_port_dma_map. +* This interface only accepts page-size aligned user memory for dma mapping. +* Return: 0 on success, -errno on failure. +*/ +struct fpga_port_dma_map { +/* Input */ +__u32 argsz;/* Structure length */ +__u32 flags;/* Zero for now */ +__u64 user_addr;/* Process virtual address */ +__u64 length;/* Length of mapping (bytes)*/ +/* Output */ +__u64 iova;/* IO virtual address */ +}; + +#define FPGA_PORT_DMA_MAP _IO(FPGA_MAGIC, PORT_BASE + 3) + +/** +* FPGA_PORT_DMA_UNMAP - _IOW(FPGA_MAGIC, PORT_BASE + 4, +* struct fpga_port_dma_unmap) +* +* Unmap the dma memory per iova provided by caller. +* Return: 0 on success, -errno on failure. +*/ +struct fpga_port_dma_unmap { +/* Input */ +__u32 argsz;/* Structure length */ +__u32 flags;/* Zero for now */ +__u64 iova;/* IO virtual address */ +}; + +#define FPGA_PORT_DMA_UNMAP _IO(FPGA_MAGIC, PORT_BASE + 4) +/* IOCTLs for FME file descriptor */ /**
Signature · 1 line
2.7.4
kbuild test robot
build botRe: [PATCH 16/16] fpga: intel: afu: add FPGA_PORT_DMA_MAP/UNMAP ioctls support
url: https://github.com/0day-ci/linux/commits/Wu-Hao/Intel-FPGA-Device-Drivers/20170401-052017 config: frv-allmodconfig (attached as .config) compiler: frv-linux-gcc (GCC) 6.2.0 reproduce: wget…
Hi Wu,
[auto build test WARNING on linus/master]
[also build test WARNING on v4.11-rc4 next-20170331]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Wu-Hao/Intel-FPGA-Device-Drivers/20170401-052017
config: frv-allmodconfig (attached as .config)
compiler: frv-linux-gcc (GCC) 6.2.0
reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=frv
All warnings (new ones prefixed by >>):
In file included from include/linux/uaccess.h:5:0,
from drivers/fpga/intel/afu-dma-region.c:17:
drivers/fpga/intel/afu-dma-region.c: In function 'afu_dma_map_region':
arch/frv/include/asm/uaccess.h:63:47: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
#define access_ok(type,addr,size) (__range_ok((void __user *)(addr), (size)) == 0)
^
arch/frv/include/asm/uaccess.h:61:60: note: in definition of macro '__range_ok'
#define __range_ok(addr,size) ___range_ok((unsigned long) (addr), (unsigned long) (size))
^~~~
>> drivers/fpga/intel/afu-dma-region.c:291:7: note: in expansion of macro 'access_ok' if (!access_ok(VERIFY_WRITE, user_addr, length))
^~~~~~~~~
vim +/access_ok +291 drivers/fpga/intel/afu-dma-region.c
275 u64 user_addr, u64 length, u64 *iova)
276 {
277 struct fpga_afu_dma_region *region;
278 int ret;
279
280 /*
281 * Check Inputs, only accept page-aligned user memory region with
282 * valid length.
283 */
284 if (!PAGE_ALIGNED(user_addr) || !PAGE_ALIGNED(length) || !length)
285 return -EINVAL;
286
287 /* Check overflow */
288 if (user_addr + length < user_addr)
289 return -EINVAL;
290
> 291 if (!access_ok(VERIFY_WRITE, user_addr, length))
292 return -EINVAL;
293
294 region = kzalloc(sizeof(*region), GFP_KERNEL);
295 if (!region)
296 return -ENOMEM;
297
298 region->user_addr = user_addr;
299 region->length = length;
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
kbuild test robot
build botRe: [PATCH 16/16] fpga: intel: afu: add FPGA_PORT_DMA_MAP/UNMAP ioctls support
In reply to Wu Haourl: https://github.com/0day-ci/linux/commits/Wu-Hao/Intel-FPGA-Device-Drivers/20170401-052017 config: sparc-allyesconfig (attached as .config) compiler: sparc64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1…
Hi Wu,
[auto build test WARNING on linus/master]
[also build test WARNING on v4.11-rc4 next-20170331]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Wu-Hao/Intel-FPGA-Device-Drivers/20170401-052017
config: sparc-allyesconfig (attached as .config)
compiler: sparc64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=sparc
All warnings (new ones prefixed by >>):
drivers/fpga/intel/afu-dma-region.c: In function 'afu_dma_map_region':
>> drivers/fpga/intel/afu-dma-region.c:291:31: warning: passing argument 2 of 'access_ok' makes pointer from integer without a cast [-Wint-conversion]
if (!access_ok(VERIFY_WRITE, user_addr, length))
^~~~~~~~~
In file included from arch/sparc/include/asm/uaccess.h:4:0,
from include/linux/uaccess.h:5,
from drivers/fpga/intel/afu-dma-region.c:17:
arch/sparc/include/asm/uaccess_64.h:80:19: note: expected 'const void *' but argument is of type 'u64 {aka long long unsigned int}'
static inline int access_ok(int type, const void __user * addr, unsigned long size)
^~~~~~~~~
vim +/access_ok +291 drivers/fpga/intel/afu-dma-region.c
275 u64 user_addr, u64 length, u64 *iova)
276 {
277 struct fpga_afu_dma_region *region;
278 int ret;
279
280 /*
281 * Check Inputs, only accept page-aligned user memory region with
282 * valid length.
283 */
284 if (!PAGE_ALIGNED(user_addr) || !PAGE_ALIGNED(length) || !length)
285 return -EINVAL;
286
287 /* Check overflow */
288 if (user_addr + length < user_addr)
289 return -EINVAL;
290
> 291 if (!access_ok(VERIFY_WRITE, user_addr, length))
292 return -EINVAL;
293
294 region = kzalloc(sizeof(*region), GFP_KERNEL);
295 if (!region)
296 return -ENOMEM;
297
298 region->user_addr = user_addr;
299 region->length = length;
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Moritz Fischer
maintainerQuoted 33 lines · Wu Hao
Hi All,
Here is a patch-series adding drivers for Intel FPGA devices.
The Intel FPGA driver provides interfaces for userspace applications to configure, enumerate, open, and access FPGA accelerators on platforms equipped with Intel(R) FPGA solutions and enables system level management functions such as FPGA partial reconfiguration, power management and virtualization.
This patch series only adds the basic functions for FPGA accelerators and partial reconfiguration. Patches for more functions, e.g power management and virtualization, will be submitted after this series gets reviewed.
Patch 1: add a document for Intel FPGA driver overview, including the HW architecture, driver organization, device enumeration, virtualization and opens.
Patch 2: introduce a fpga-dev class. It's used in below Intel FPGA PCIe device driver, to represent a FPGA device on the system, and all actual feature devices should be registered as child nodes of this container fpga-dev device.
Patch 3-7: implement Intel FPGA PCIe device driver. It walks through the 'Device Feature List' in the PCI Bar, creates the container fpga-dev as parent and platform devices as children for the feature devices it found.
Patch 8-11: implement Intel FPGA Management Engine (FME) driver. It's a platform driver matching with the FME platform device created by above PCIe driver. Sysfs and device file ioctls are exposed as user interfaces to allow partial reconfiguration to Accelerated Function Units (AFUs) from user space applications.
Quoted 4 lines
Patch 12-16: implement Intel FPGA Accelerated Function Unit (AFU) driver. It's a platform driver matching with AFU platform device created by above PCIe driver. It provides user interfaces to expose the AFU MMIO region, map/unmap dma buffer, and control the port which AFU connects to.
This is exciting stuff. It will take some time to review, though. I marked the patchset as 'In-Review' in patchwork.
Cheers,
Moritz
Quoted 27 lines · Wu Hao
Hi All,
Here is a patch-series adding drivers for Intel FPGA devices.
The Intel FPGA driver provides interfaces for userspace applications to configure, enumerate, open, and access FPGA accelerators on platforms equipped with Intel(R) FPGA solutions and enables system level management functions such as FPGA partial reconfiguration, power management and virtualization.
This patch series only adds the basic functions for FPGA accelerators and partial reconfiguration. Patches for more functions, e.g power management and virtualization, will be submitted after this series gets reviewed.
Patch 1: add a document for Intel FPGA driver overview, including the HW architecture, driver organization, device enumeration, virtualization and opens.
Patch 2: introduce a fpga-dev class. It's used in below Intel FPGA PCIe device driver, to represent a FPGA device on the system, and all actual feature devices should be registered as child nodes of this container fpga-dev device.
Patch 3-7: implement Intel FPGA PCIe device driver. It walks through the 'Device Feature List' in the PCI Bar, creates the container fpga-dev as parent and platform devices as children for the feature devices it found.
Quoted 5 lines
Patch 8-11: implement Intel FPGA Management Engine (FME) driver. It's a platform driver matching with the FME platform device created by above PCIe driver. Sysfs and device file ioctls are exposed as user interfaces to allow partial reconfiguration to Accelerated Function Units (AFUs) from user space applications.
Do we have an open source toolchain to generate the FPGA configuration (bitstream) ? As it is required for the GPU sub-system that any driver API must comes with open source userspace.
Or are FPGA given a free pass ?
Cheers,
Jérôme
Hi Jerome,
Quoted 3 lines · Jerome Glisse
Do we have an open source toolchain to generate the FPGA configuration (bitstream) ? As it is required for the GPU sub-system that any driver API must comes with open source userspace.
As far as I know, no FPGA vendor currently provides an open-source version of their FPGA synthesis tools - there are, however, free (as in beer) versions available for download that can be used for generating FPGA bitstreams. Also, there are a number of projects to replace parts of the vendor tools with open alternatives (yosys comes to mind, which I believe recently added initial support for synthesizing logic for Intel FPGAs).
As an aside, we are also working on an open-source user-space library that would allow you to use this driver to load existing accelerator bitstreams as well as enumerate and access accelerators present in the system. This would enable workflows where users have access to e.g. a library of FPGA accelerator bitstreams and want to write applications that take advantage of these accelerators, even without having access to an FPGA synthesis tool.
Thanks
- Enno
Quoted 15 lines · Enno
Hi Jerome,
Quoted 3 lines · Jerome Glisse
Do we have an open source toolchain to generate the FPGA configuration (bitstream) ? As it is required for the GPU sub-system that any driver API must comes with open source userspace.
As far as I know, no FPGA vendor currently provides an open-source version of their FPGA synthesis tools - there are, however, free (as in beer) versions available for download that can be used for generating FPGA bitstreams. Also, there are a number of projects to replace parts of the vendor tools with open alternatives (yosys comes to mind, which I believe recently added initial support for synthesizing logic for Intel FPGAs).
Quoted 6 lines
As an aside, we are also working on an open-source user-space library that would allow you to use this driver to load existing accelerator bitstreams as well as enumerate and access accelerators present in the system. This would enable workflows where users have access to e.g. a library of FPGA accelerator bitstreams and want to write applications that take advantage of these accelerators, even without having access to an FPGA synthesis tool.
Yosys is not an open source toolchain is use quartus at least that is my understand from this commit:
https://github.com/cliffordwolf/yosys/commit/c27dcc1e47fa00cd415893c9d3f637a5d5865988
It is like if on GPU we only had close source compiler for the GPU instructions set. So FPGA is definitly following different rules than open source upstream GPU kernel driver abides to.
I see this as highly problematic if not only for security purposes there is no way for anyone to audit how secure and sane the API you want to expose to userspace. Those FPGA might have connection to memory bus or device bus and thus they might get access to any memory.
So i am baffle on how anyone can do any serious review of anything the fpga driver are doing.
Jérôme
Hi Jerome,
Quoted 8 lines · Jerome Glisse
Quoted 7 lines · Enno
Hi Jerome,
Quoted 3 lines · Jerome Glisse
Do we have an open source toolchain to generate the FPGA configuration (bitstream) ? As it is required for the GPU sub-system that any driver API must comes with open source userspace.
I think the comparison lacks. No one seems to be bothered by the fact that the GPUs
hardware is built using closed source CAD tools, even if open source drivers are available. From an OS perspective the FPGA is hardware. (Reconfigurable) but hardware.
A better comparison from my point of view would be loading a binary firmware image ...
Quoted 19 lines
Quoted 7 lines
As far as I know, no FPGA vendor currently provides an open-source version of their FPGA synthesis tools - there are, however, free (as in beer) versions available for download that can be used for generating FPGA bitstreams. Also, there are a number of projects to replace parts of the vendor tools with open alternatives (yosys comes to mind, which I believe recently added initial support for synthesizing logic for Intel FPGAs).
Quoted 6 lines
As an aside, we are also working on an open-source user-space library that would allow you to use this driver to load existing accelerator bitstreams as well as enumerate and access accelerators present in the system. This would enable workflows where users have access to e.g. a library of FPGA accelerator bitstreams and want to write applications that take advantage of these accelerators, even without having access to an FPGA synthesis tool.
Yosys is not an open source toolchain is use quartus at least that is my understand from this commit:
https://github.com/cliffordwolf/yosys/commit/c27dcc1e47fa00cd415893c9d3f637a5d5865988
Quoted 8 lines
It is like if on GPU we only had close source compiler for the GPU instructions set. So FPGA is definitly following different rules than open source upstream GPU kernel driver abides to.
I see this as highly problematic if not only for security purposes there is no way for anyone to audit how secure and sane the API you want to expose to userspace. Those FPGA might have connection to memory bus or device bus and thus they might get access to any memory.
It's up to the user to plug a specific piece of hardware into their machine. After that it is
up to the user to decide whether he wants to load a bitstream that he doesn't have the
source code for and that he needs to compile with closed source software. Do you know if NVIDIA has backdoors in their GPU, Intel in their NIC, or AMD in their
processor? What about that RTC, do you have the source code they synthesized their
ASIC design from?
Maybe my mental model on FPGAs is different from yours so feel free to disagree ;-)
Moritz
Quoted 12 lines · Moritz Fischer
Hi Jerome,
Quoted 8 lines · Jerome Glisse
Quoted 7 lines · Enno
Hi Jerome,
Quoted 3 lines · Jerome Glisse
Do we have an open source toolchain to generate the FPGA configuration (bitstream) ? As it is required for the GPU sub-system that any driver API must comes with open source userspace.
Quoted 7 lines
I think the comparison lacks. No one seems to be bothered by the fact that the GPUs hardware is built using closed source CAD tools, even if open source drivers are available. From an OS perspective the FPGA is hardware. (Reconfigurable) but hardware.
A better comparison from my point of view would be loading a binary firmware image ...
I disagree here, Altera or Xilinx provide OpenCL implementation that allows to use FPGA. Moreover FPGA are way more capable that micro-controller on which vast majority of firmware are running.
Quoted 28 lines
Quoted 19 lines
Quoted 7 lines
As far as I know, no FPGA vendor currently provides an open-source version of their FPGA synthesis tools - there are, however, free (as in beer) versions available for download that can be used for generating FPGA bitstreams. Also, there are a number of projects to replace parts of the vendor tools with open alternatives (yosys comes to mind, which I believe recently added initial support for synthesizing logic for Intel FPGAs).
Quoted 6 lines
As an aside, we are also working on an open-source user-space library that would allow you to use this driver to load existing accelerator bitstreams as well as enumerate and access accelerators present in the system. This would enable workflows where users have access to e.g. a library of FPGA accelerator bitstreams and want to write applications that take advantage of these accelerators, even without having access to an FPGA synthesis tool.
Yosys is not an open source toolchain is use quartus at least that is my understand from this commit:
https://github.com/cliffordwolf/yosys/commit/c27dcc1e47fa00cd415893c9d3f637a5d5865988Quoted 8 lines
It is like if on GPU we only had close source compiler for the GPU instructions set. So FPGA is definitly following different rules than open source upstream GPU kernel driver abides to.
I see this as highly problematic if not only for security purposes there is no way for anyone to audit how secure and sane the API you want to expose to userspace. Those FPGA might have connection to memory bus or device bus and thus they might get access to any memory.
Quoted 7 lines
It's up to the user to plug a specific piece of hardware into their machine. After that it is up to the user to decide whether he wants to load a bitstream that he doesn't have the source code for and that he needs to compile with closed source software. Do you know if NVIDIA has backdoors in their GPU, Intel in their NIC, or AMD in their processor? What about that RTC, do you have the source code they synthesized their ASIC design from?
User do not always know what program their executing. Think someone browsing some random website, through javascript program you might be able to escape the web browser and look for fpga device file, if on is present then it might be able to load a bitstream that would allow it to overwritte system memory and gain root privilege.
Even if you restrict the ioctl to upload bitstream to root user or some privilege user, you have to think about VM world. Someone from inside a vm that has access to an fpga device might be able to upload a bitstream that would allow to escape the vm and gain root privilege on the host operating system.
Security expert have proven over and over that no matter how unlikely a path looks to you, no matter how hard, they will eventualy leverage it.
So you ignoring this issue doesn't make it less real. Pretending that "secret" bitstream protect you or that only user will load a bitstream is burying your head in the sand.
So yes knowing the bitstream and links the device has is necessary to be able to evaluate the security implication of what the kernel fpga driver are doing.
Cheers,
Jérôme
Quoted 26 lines · Jerome Glisse
Quoted 11 lines · Moritz Fischer
Quoted 8 lines · Jerome Glisse
It is like if on GPU we only had close source compiler for the GPU instructions set. So FPGA is definitly following different rules than open source upstream GPU kernel driver abides to.
I see this as highly problematic if not only for security purposes there is no way for anyone to audit how secure and sane the API you want to expose to userspace. Those FPGA might have connection to memory bus or device bus and thus they might get access to any memory.
Quoted 7 lines
It's up to the user to plug a specific piece of hardware into their machine. After that it is up to the user to decide whether he wants to load a bitstream that he doesn't have the source code for and that he needs to compile with closed source software. Do you know if NVIDIA has backdoors in their GPU, Intel in their NIC, or AMD in their processor? What about that RTC, do you have the source code they synthesized their ASIC design from?
User do not always know what program their executing. Think someone browsing some random website, through javascript program you might be able to escape the web browser and look for fpga device file, if on is present then it might be able to load a bitstream that would allow it to overwritte system memory and gain root privilege.
Quoted 5 lines
Even if you restrict the ioctl to upload bitstream to root user or some privilege user, you have to think about VM world. Someone from inside a vm that has access to an fpga device might be able to upload a bitstream that would allow to escape the vm and gain root privilege on the host operating system.
If you're worried about an accelerator on an FPGA going rogue and accessing arbitrary host memory, consider that other (non-FPGA) hardware devices could potentially do that, too (e.g. a PCIe device with a programmable DMA engine). So this is not really an FPGA-specific concern.
Also, I don't think having an open-source toolchain would help defend against these kind of attacks at all. Just because you can generate bitstreams with an open-source tool doesn't prevent the attacker from loading his own bitstreams. Instead, you'll need to make sure that their bitstream (open-source or not), or, in fact, any device, is prevented from accessing memory it's not authorized to access, e.g. with an IOMMU programmed via the kernel's DMA API.
But that's not a toolchain issue.
Thanks
- Enno
Quoted 33 lines · Enno
Quoted 26 lines · Jerome Glisse
Quoted 11 lines · Moritz Fischer
Quoted 8 lines · Jerome Glisse
It is like if on GPU we only had close source compiler for the GPU instructions set. So FPGA is definitly following different rules than open source upstream GPU kernel driver abides to.
I see this as highly problematic if not only for security purposes there is no way for anyone to audit how secure and sane the API you want to expose to userspace. Those FPGA might have connection to memory bus or device bus and thus they might get access to any memory.
Quoted 7 lines
It's up to the user to plug a specific piece of hardware into their machine. After that it is up to the user to decide whether he wants to load a bitstream that he doesn't have the source code for and that he needs to compile with closed source software. Do you know if NVIDIA has backdoors in their GPU, Intel in their NIC, or AMD in their processor? What about that RTC, do you have the source code they synthesized their ASIC design from?
User do not always know what program their executing. Think someone browsing some random website, through javascript program you might be able to escape the web browser and look for fpga device file, if on is present then it might be able to load a bitstream that would allow it to overwritte system memory and gain root privilege.
Quoted 5 lines
Even if you restrict the ioctl to upload bitstream to root user or some privilege user, you have to think about VM world. Someone from inside a vm that has access to an fpga device might be able to upload a bitstream that would allow to escape the vm and gain root privilege on the host operating system.
Quoted 4 lines
If you're worried about an accelerator on an FPGA going rogue and accessing arbitrary host memory, consider that other (non-FPGA) hardware devices could potentially do that, too (e.g. a PCIe device with a programmable DMA engine). So this is not really an FPGA-specific concern.
Yes but linux kernel driver for those is auditable we can check how such DMA engine are programmed and in many case userspace do not even have any control on those (nor indirect nor direct). For the few driver that expose such DMA engine to userspace we can audit the ioctl and see if they can be abuse to do rogue DMA.
Quoted 8 lines
Also, I don't think having an open-source toolchain would help defend against these kind of attacks at all. Just because you can generate bitstreams with an open-source tool doesn't prevent the attacker from loading his own bitstreams. Instead, you'll need to make sure that their bitstream (open-source or not), or, in fact, any device, is prevented from accessing memory it's not authorized to access, e.g. with an IOMMU programmed via the kernel's DMA API.
But that's not a toolchain issue.
Open source toolchain allows to audit all the in and out of the fpga, to know how you can connect the fpga logic to the outside world and to know how this inter-connect interface with the fpga fabrics. Without such knowledge we are left to believe that the fpga logic can only go through some dedicated block that itself have to go through IOMMU. So it is security through obscurity.
Note that security is just an example of why open source toolchain matter. But this is a more fundamental issue in respect to linux kernel rules. Like i said such thing would be totaly forbidden for the GPU driver and for any other upstream driver in the linux kernel. It seems that the FPGA folks got granted an exception that was never granted to anyone else and i would like to know why.
No driver in kernel without open source userspace have been the rule for all the other drivers. Just open sourcing some helper that load the bitstream does not cut it in my view.
Jérôme
On Fri, Apr 14, 2017 at 3:49 PM, Jerome Glisse <[email protected]> wrote:
Hi Jerome,
Quoted 8 lines · Enno
Quoted 7 lines · Jerome Glisse
Quoted 6 lines · Moritz Fischer
Quoted 5 lines · Jerome Glisse
Quoted 4 lines
It is like if on GPU we only had close source compiler for the GPU instructions set. So FPGA is definitly following different rules than open source upstream GPU kernel driver abides to.
Sorry, not a GPU guy, can you point me to something that documents this policy of 'only opensource compilers for GPU'? I looked under linux/Documentation and didn't see anything.
The current patchset doesn't have anything to do with FPGA toolchains but you're using this patchset as a platform to talk about toolchain issues.
It sounds like you are opposed to any kernel support of loading images on FPGAs until all vendors have opensource toolchains.
Alan
Quoted 9 lines · Alan Tull
On Fri, Apr 14, 2017 at 3:49 PM, Jerome Glisse <[email protected]> wrote:
Hi Jerome,
Quoted 5 lines · Enno
Quoted 4 lines · Jerome Glisse
Quoted 3 lines · Moritz Fischer
Quoted 2 lines · Jerome Glisse
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
It is like if on GPU we only had close source compiler for the GPU instructions set. So FPGA is definitly following different rules than open source upstream GPU kernel driver abides to.
Sorry, not a GPU guy, can you point me to something that documents this policy of 'only opensource compilers for GPU'? I looked under linux/Documentation and didn't see anything.
https://lists.freedesktop.org/archives/dri-devel/2010-July/001828.html
There is no explicit mention about compiler but trust me it is included in everyones mind. You can ask Dave i am sure he would reject a driver with everything open except the shader compiler.
Quoted 3 lines
The current patchset doesn't have anything to do with FPGA toolchains but you're using this patchset as a platform to talk about toolchain issues.
Well Intel inclusion of FPGA triggered my curiosity and when that patchset came accross my inbox i did wonder where the open source userspace was and went looking for it to no avail. So this isn't against a specific patchset but more broadly against the whole drivers/fpga/ story. Sorry if this was not clear.
Quoted 2 lines
It sounds like you are opposed to any kernel support of loading images on FPGAs until all vendors have opensource toolchains.
Yes that is what i am saying. They are different standard in the kernel and i would rather have one clear standard about driver needing proper open source userspace to go along with any upstream driver.
Beside when it comes to FPGA i am still puzzle on why no one release info on the bitstream. They all provide details documentation on the internal (LUT, flip-flop, logic block layout and connection, memory block, ...). So there is nothing hidden in the bitstream. I am guessing the only good reason i can think of is to make it harder to map a bitstream back to VHDL/Verilog/...
Cheers,
Jérôme
Quoted 14 lines · Jerome Glisse
Quoted 13 lines · Alan Tull
On Fri, Apr 14, 2017 at 3:49 PM, Jerome Glisse <[email protected]> wrote:
Hi Jerome,
Quoted 8 lines · Enno
Quoted 7 lines · Jerome Glisse
Quoted 6 lines · Moritz Fischer
Quoted 5 lines · Jerome Glisse
Quoted 4 lines
It is like if on GPU we only had close source compiler for the GPU instructions set. So FPGA is definitly following different rules than open source upstream GPU kernel driver abides to.
Quoted 5 lines
Quoted 3 lines
Sorry, not a GPU guy, can you point me to something that documents this policy of 'only opensource compilers for GPU'? I looked under linux/Documentation and didn't see anything.
https://lists.freedesktop.org/archives/dri-devel/2010-July/001828.html
This starts out saying:
"Now this is just my opinion as maintainer of the drm, and doesn't reflect anyone or any official policy"
Quoted 1 line
There is no explicit mention about compiler
You are right about that, there is no mention about compiler.
Quoted 3 lines
but trust me it is included
in everyones mind. You can ask Dave i am sure he would reject a driver with everything open except the shader compiler.
How would that work? Before the GPU driver is accepted, an open toolchain also needs to be submitted?
It's worth it to check out the responses since they not overwhelmingly positive and tend to rather be outlining the complicating factors. Many if not most say essentially that his stance was simplistic and unproductive, slamming the door on the people from whom the solution would come. And keep in mind, this wasn't about what you've made it out to be in the first place; this is about open/closed source GPU drivers, not toolchains.
Quoted 13 lines
Quoted 5 lines
The current patchset doesn't have anything to do with FPGA toolchains but you're using this patchset as a platform to talk about toolchain issues.
Well Intel inclusion of FPGA triggered my curiosity and when that patchset came accross my inbox i did wonder where the open source userspace was and went looking for it to no avail. So this isn't against a specific patchset but more broadly against the whole
drivers/fpga/story. Sorry if this was not clear.
Quoted 6 lines
Quoted 2 lines
It sounds like you are opposed to any kernel support of loading images on FPGAs until all vendors have opensource toolchains.
Yes that is what i am saying. They are different standard in the kernel and i would rather have one clear standard about driver needing proper open source userspace to go along with any upstream driver.
Deleting drivers/fpga wouldn't be a step forward to the openness you seek.
Quoted 10 lines
Beside when it comes to FPGA i am still puzzle on why no one release info on the bitstream. They all provide details documentation on the internal (LUT, flip-flop, logic block layout and connection, memory block, ...). So there is nothing hidden in the bitstream. I am guessing the only good reason i can think of is to make it harder to map a bitstream back to VHDL/Verilog/...
Cheers,
Jérôme
Quoted 37 lines · Alan Tull
Quoted 14 lines · Jerome Glisse
Quoted 13 lines · Alan Tull
On Fri, Apr 14, 2017 at 3:49 PM, Jerome Glisse <[email protected]> wrote:
Hi Jerome,
Quoted 8 lines · Enno
Quoted 7 lines · Jerome Glisse
Quoted 6 lines · Moritz Fischer
Quoted 5 lines · Jerome Glisse
Quoted 4 lines
It is like if on GPU we only had close source compiler for the GPU instructions set. So FPGA is definitly following different rules than open source upstream GPU kernel driver abides to.
Quoted 5 lines
Quoted 3 lines
Sorry, not a GPU guy, can you point me to something that documents this policy of 'only opensource compilers for GPU'? I looked under linux/Documentation and didn't see anything.
https://lists.freedesktop.org/archives/dri-devel/2010-July/001828.html
This starts out saying:
"Now this is just my opinion as maintainer of the drm, and doesn't reflect anyone or any official policy"
Quoted 1 line
There is no explicit mention about compiler
You are right about that, there is no mention about compiler.
Quoted 3 lines
but trust me it is included
in everyones mind. You can ask Dave i am sure he would reject a driver with everything open except the shader compiler.How would that work? Before the GPU driver is accepted, an open toolchain also needs to be submitted?
Quoted 7 lines
It's worth it to check out the responses since they not overwhelmingly positive and tend to rather be outlining the complicating factors. Many if not most say essentially that his stance was simplistic and unproductive, slamming the door on the people from whom the solution would come. And keep in mind, this wasn't about what you've made it out to be in the first place; this is about open/closed source GPU drivers, not toolchains.
You are mixing thing. I say no driver without open source userspace. For GPU this means something like a mesa driver and mesa driver include a compiler but not in the form you expect (it is does not provide what i would call a toolchain). But it can be something else. It could be a standalone opencl implementation with what we call a finalizer (ie something that goes from some intermediate representation down to the hardare ISA).
So if you go look back at new driver submission like Adreno or Vivante. They provided link to the open source driver they submited to mesa along their kernel patchset posting.
For FPGA this would mean a tool that can map something like VHDL,Verilog or even something lower level like a list of lut equation with a netlist between them (and flip-flop and other blocks). So mapping this down to the bitstream. It is call a toolchain for FPGA so that's the word i did use.
Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
The current patchset doesn't have anything to do with FPGA toolchains but you're using this patchset as a platform to talk about toolchain issues.
Well Intel inclusion of FPGA triggered my curiosity and when that patchset came accross my inbox i did wonder where the open source userspace was and went looking for it to no avail. So this isn't against a specific patchset but more broadly against the whole
drivers/fpga/story. Sorry if this was not clear.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
It sounds like you are opposed to any kernel support of loading images on FPGAs until all vendors have opensource toolchains.
Yes that is what i am saying. They are different standard in the kernel and i would rather have one clear standard about driver needing proper open source userspace to go along with any upstream driver.
Deleting
drivers/fpgawouldn't be a step forward to the openness you seek.
I am not saying let delete this. Ok it is there, i dislike that fact, but it is there. I am asking: is this allowed for FPGA ? If so why ? Do everyone understand the risks of accepting this ? ...
Now if community believe that we should only accept kernel code with open source userspace bits then community can say no more changes to drivers/fpga until you have said open source bits. That would send a clear signal.
Silently accepting drivers/fpga/ with no clear rules leave everyone in the dark. People that wish to see only driver with open source userspace knows that company will be happy to stay in this status quo and won't do anything toward open source. Thinking differently would be utterly naive. A company will not do something unless there is a clear incentive to do so.
Cheers,
Jérôme
Quoted 7 lines
Well Intel inclusion of FPGA triggered my curiosity and when that patchset came accross my inbox i did wonder where the open source userspace was and went looking for it to no avail. So this isn't against a specific patchset but more broadly against the whole
drivers/fpga/story. Sorry if this was not clear.
Quoted 6 lines
Quoted 2 lines
It sounds like you are opposed to any kernel support of loading images on FPGAs until all vendors have opensource toolchains.
Yes that is what i am saying. They are different standard in the kernel and i would rather have one clear standard about driver needing proper open source userspace to go along with any upstream driver.
So Red Hat will stop shipping any hardware with loadable firmware ?
No I thought not 8)
I think you need to be much clearer what you are talking about. The GPU's load closed firmware. The sound cards load closed firmware. The pieces we demand are open (with the exception of the rather strange position Debian takes) are the actual pieces you need to use the device on the Linux side - so the 3D libraries, 2D acceleration libraries, wifi interfaces, audio playback and so on.
The FPGA bitstreams are and always have been counted as firmware (nothing here is new except that existing systems load FPGA firmware via devicetree at boot rather than dynamically). That's true of the Xilinx drivers, the many FPGA drivers for existing ARM and other processor platforms containing FPGA today that are in kernel.
The second part of the equation is the tools for selecting a bitstream, and for running whatever accelerator you loaded. Generally that's just a device that mmap's the accelerator into whatever application wishes to bash on it. The bits you need to load a bitstream do need to be open, and the device driver that does the mmio mappingand there will no doubt over time be other drivers where you do want to kernel mediate your FPGA functions.
Some bitstreams will need their own drivers, others may want to use existing drivers. Crypto for example if loaded on an FPGA you'd probably want to go via the kernel crypto hooks and FPGA hardware for some applications might want to expose gpios, serial ports, virtio etc. For debug or if I've got a CPU on my bitstream I might even want to expose a standard 16x50 UART to the serial drivers.
Generally though most bitstreams are pretty latency sensitive, often used for real time work, and just provide a set of registers to any application wanting to use that service.
(Consider for example a Z80 processor emulator on the FPGA - do you really want to define kvm hooks for Z80 virtualization, or 6502, or all the rest us retro folks are going to enable ???
Alan
Quoted 25 lines · Alan Cox
Quoted 7 lines
Well Intel inclusion of FPGA triggered my curiosity and when that patchset came accross my inbox i did wonder where the open source userspace was and went looking for it to no avail. So this isn't against a specific patchset but more broadly against the whole
drivers/fpga/story. Sorry if this was not clear.Quoted 6 lines
Quoted 2 lines
It sounds like you are opposed to any kernel support of loading images on FPGAs until all vendors have opensource toolchains.
Yes that is what i am saying. They are different standard in the kernel and i would rather have one clear standard about driver needing proper open source userspace to go along with any upstream driver.
So Red Hat will stop shipping any hardware with loadable firmware ?
No I thought not 8)
I think you need to be much clearer what you are talking about. The GPU's load closed firmware. The sound cards load closed firmware. The pieces we demand are open (with the exception of the rather strange position Debian takes) are the actual pieces you need to use the device on the Linux side - so the 3D libraries, 2D acceleration libraries, wifi interfaces, audio playback and so on.
Quoted 5 lines
The FPGA bitstreams are and always have been counted as firmware (nothing here is new except that existing systems load FPGA firmware via devicetree at boot rather than dynamically). That's true of the Xilinx drivers, the many FPGA drivers for existing ARM and other processor platforms containing FPGA today that are in kernel.
That is where we disagree. I do not see bitstream as firmware. For instance now you can run OpenCL on some FPGA, so this is exactly like GPU we should request open source stack from OpenCL down to bitstream.
Quoted 7 lines
The second part of the equation is the tools for selecting a bitstream, and for running whatever accelerator you loaded. Generally that's just a device that mmap's the accelerator into whatever application wishes to bash on it. The bits you need to load a bitstream do need to be open, and the device driver that does the mmio mappingand there will no doubt over time be other drivers where you do want to kernel mediate your FPGA functions.
For me this is not enough (tool to load bitstream).
Jérôme
Quoted 3 lines
That is where we disagree. I do not see bitstream as firmware. For instance now you can run OpenCL on some FPGA, so this is exactly like GPU we should request open source stack from OpenCL down to bitstream.
It's an accelerator with a bunch of firmwares where you load the right one. We've got lots of those in Linux already. Your GPU probably needs firmware as well in just the same way.
Quoted 1 line
For me this is not enough (tool to load bitstream).
Unfortunately that isn't likely to change for any major FPGA device in the near future. If you could load arbitrary bit patterns into an FPGA then in most cases that also means you could physically destroy the hardware.
Alan
Quoted 7 lines · One Thousand Gnomes
Quoted 3 lines
That is where we disagree. I do not see bitstream as firmware. For instance now you can run OpenCL on some FPGA, so this is exactly like GPU we should request open source stack from OpenCL down to bitstream.
It's an accelerator with a bunch of firmwares where you load the right one. We've got lots of those in Linux already. Your GPU probably needs firmware as well in just the same way.
I stress again OpenCL on FPGA ie at runtime you load a program source that is compiled at runtime and then lower to a bitstream which get loaded on the FGPA at runtime. You can go look at how OpenCL works it is not like fix firmware. OpenCL was done for GPU and everything needed to support OpenCL is open source when it comes to GPU. On contrary with FPGA the bitstream part is close source.
Sure GPU have firmware, those firmware run on realtime micro-controller to dispatch job, handle GPU power management and other janitorial stuff. For some GPU we even have open source firmware.
So FPGA with thing like OpenCL are more like GPU than like a fix hardware that is program once and use like a device for which we need a firmware. That is where we disagree on the characterization of things.
Quoted 6 lines
Quoted 1 line
For me this is not enough (tool to load bitstream).
Unfortunately that isn't likely to change for any major FPGA device in the near future. If you could load arbitrary bit patterns into an FPGA then in most cases that also means you could physically destroy the hardware.
I am just questioning the different standard in the kernel.
Jérôme