FPGA subsystem core
v2 cover FPGA subsystem core
Hi All,
this is the second attempt to introduce new Linux FPGA subsystem which can help us to unify all fpga drivers which in general do the same things.
Xilinx has hwicap in the kernel as char driver (drivers/char/xilinx_hwicap/) and I would like to base Zynq devcfg driver based on this interface because make no sense to push the Linux kernel another char driver (I am testing this interface on this driver).
Based on my discussion at ELC with Greg KH the new driver should support firmware interface for loading bitstream.
FPGA manager/driver just define set of functions and call fpga_mgr_register().
struct fpga_manager_ops zynq_fpga_mgr_ops = {
.read_init = zynq_init,
.write_init = zynq_init,
.read = zynq_read,
.write = zynq_write,
.read_complete = zynq_complete,
.write_complete = zynq_complete,
};
fpga_mgr_register(pdev, &zynq_fpga_mgr_ops, "Zynq FPGA Manager", priv);
For unregistration it is enough to call:fpga_mgr_unregister(pdev);
Here is the set of commands for writing bitstream to FPGA.
Through firmware interface:
cat /sys/class/fpga_manager/fpga0/name
echo -n fpga.bin > /sys/class/fpga_manager/fpga0/firmware
Through sysfs bin file:
cat /sys/class/fpga_manager/fpga0/fpga_config_state
echo -n write_init > /sys/class/fpga_manager/fpga0/fpga_config_state cat /lib/firmware/fpga.bin > /sys/class/fpga_manager/fpga0/fpga_config_data echo -n write_complete > /sys/class/fpga_manager/fpga0/fpga_config_state
Subsystem supports working with phandles for cases where you want to load bitstreams for particular device through defined device.
For example:
mngr@0 {
compatible = "whatever";
fpga-mgr = <&ps7_dev_cfg_0>;
...
} ;With these lines you can get easily load bitstream to the device.
struct fpga_manager *mgr;
mgr = of_find_fpga_mgr_by_phandle(pdev->dev.of_node, "fpga-mgr"); if (mgr)
mgr->fpga_firmware_write(mgr, "filename");
NOTE: I have added there of_find_fpga_mgr_by_node() and of_find_fpga_mgr_by_phandle() but maybe they should be added separately to drivers/of/of_fpga.c.
Alessandro: I haven't looked at your FMC cases but maybe this could be also worth for your cases.
TODO:
- Probably make sense to create doc in Documentation folder too.
- When interface is fine also send zynq devcfg driver
- Properly test reading (we have problem with zynq devcfg driver now)
- Not sure if firmware interface also provide option to create files from kernel space.
Thanks for your comments,
Michal
Changes in v2:
- Remove ! from all error message not to be shouty
- Fix error codes
- Add sysfs-class-fpga description
- Use read/write helper functions with bit protection
- s/fpga_mgr_status_show/fpga_mgr_status_read/g
- Do not all end driver status just show core status
- Extract firmware support to specific sysfs firmware file
- Add support for sysfs bin attributes (fpga_config_state, fpga_config_data)
- Allocate space for name dynamically
- Introduce new flags bits (INIT_DONE, READ, WRITE)
Michal Simek (1):
fpga: Introduce new fpga subsystem
Documentation/ABI/testing/sysfs-class-fpga | 33 ++ MAINTAINERS | 7 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/fpga/Kconfig | 18 + drivers/fpga/Makefile | 5 + drivers/fpga/fpga-mgr.c | 753 +++++++++++++++++++++++++++++ include/linux/fpga.h | 110 +++++ 8 files changed, 929 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-fpga create mode 100644 drivers/fpga/Kconfig create mode 100644 drivers/fpga/Makefile create mode 100644 drivers/fpga/fpga-mgr.c create mode 100644 include/linux/fpga.h
--
1.8.2.3
RFC PATCH v2 1/1 fpga: Introduce new fpga subsystem
This new fpga subsystem core should unify all fpga drivers/managers which do the same things. Load configuration data to fpga or another programmable logic through common interface. It doesn't matter if it is MMIO device, gpio bitbanging, etc. connection. The point is to have the same interface for these drivers.
---
Changes in v2:
- Remove ! from all error message not to be shouty
- Fix error codes
- Add sysfs-class-fpga description
- Use read/write helper functions with bit protection
- s/fpga_mgr_status_show/fpga_mgr_status_read/g
- Do not all end driver status just show core status
- Extract firmware support to specific sysfs firmware file
- Add support for sysfs bin attributes (fpga_config_state, fpga_config_data)
- Allocate space for name dynamically
- Introduce new flags bits (INIT_DONE, READ, WRITE)
Documentation/ABI/testing/sysfs-class-fpga | 33 ++ MAINTAINERS | 7 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/fpga/Kconfig | 18 + drivers/fpga/Makefile | 5 + drivers/fpga/fpga-mgr.c | 753 +++++++++++++++++++++++++++++ include/linux/fpga.h | 110 +++++ 8 files changed, 929 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-fpga create mode 100644 drivers/fpga/Kconfig create mode 100644 drivers/fpga/Makefile create mode 100644 drivers/fpga/fpga-mgr.c create mode 100644 include/linux/fpga.h
Documentation/ABI/testing/sysfs-class-fpga new file +33 -0
@@ -0,0 +1,33 @@ +What: /sys/class/fpga_manager/fpga<dev-id>/firmware +Date: October 2013 +KernelVersion: 3.12 +Contact: Michal Simek <[email protected]> +Description: + Writing firmware name will invoke firmware interface + to request for a firmware which includes fpga bitstream. + +What: /sys/class/fpga_manager/fpga<dev-id>/fpga_config_state +Date: October 2013 +KernelVersion: 3.12 +Contact: Michal Simek <[email protected]> +Description: + By reading this file you will get current fpga manager state. + Flag bits are present in include/linux/fpga.h (FPGA_MGR_XX). + By writing to this file you can change fpga manager state. + Valid options are: write_init, write_complete, read_init, + read_complete. + +What: /sys/class/fpga_manager/fpga<dev-id>/fpga_config_data +Date: October 2013 +KernelVersion: 3.12 +Contact: Michal Simek <[email protected]> +Description: + For writing fpga bitstream to the device when device is + in proper state setup through fpga_config_state. + +What: /sys/class/fpga_manager/fpga<dev-id>/name +Date: October 2013 +KernelVersion: 3.12 +Contact: Michal Simek <[email protected]> +Description: + Show fpga manager name.
MAINTAINERS +7 -0
@@ -3427,6 +3427,13 @@ F: include/linux/fmc*.h F: include/linux/ipmi-fru.h K: fmc_d.*register +FPGA SUBSYSTEM +M: Michal Simek <[email protected]> +T: git git://git.xilinx.com/linux-xlnx.git +S: Supported +F: drivers/fpga/ +F: include/linux/fpga.h + FPU EMULATOR M: Bill Metzenthen <[email protected]> W: http://floatingpoint.sourceforge.net/emulator/index.html
drivers/Kconfig +2 -0
@@ -166,4 +166,6 @@ source "drivers/reset/Kconfig" source "drivers/fmc/Kconfig" +source "drivers/fpga/Kconfig" + endmenu
drivers/Makefile +1 -0
@@ -152,3 +152,4 @@ obj-$(CONFIG_VME_BUS) += vme/ obj-$(CONFIG_IPACK_BUS) += ipack/ obj-$(CONFIG_NTB) += ntb/ obj-$(CONFIG_FMC) += fmc/ +obj-$(CONFIG_FPGA) += fpga/
drivers/fpga/Kconfig new file +18 -0
@@ -0,0 +1,18 @@ +# +# FPGA framework configuration +# + +menu "FPGA devices" + +config FPGA + tristate "FPGA Framework" + help + Say Y here if you want support for configuring FPGAs from the + kernel. The FPGA framework adds a FPGA manager class and FPGA + manager drivers. + +if FPGA + +endif + +endmenu
drivers/fpga/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# +# Makefile for the fpga framework and fpga manager drivers. +# + +obj-$(CONFIG_FPGA) += fpga-mgr.o
drivers/fpga/fpga-mgr.c new file +753 -0
753 lines not on this page · raw message
include/linux/fpga.h new file +110 -0
110 lines not on this page · raw message
--
1.8.2.3
Re: [RFC PATCH v2] fpga: Introduce new fpga subsystem
Quoted 5 lines · Michal Simek
This new fpga subsystem core should unify all fpga
drivers/managerswhich do the same things. Load configuration data to fpga or another programmable logic through common interface. It doesn't matter if it is MMIO device, gpio bitbanging, etc. connection. The point is to have the same interface for these drivers.
Does this interface support partial reprogramming/configuration for FPGAs that can do that?
trivial notes:
There are a _lot_ of dev_dbg statements.
I hope some of these would be removed one day, especially the function tracing style ones, because there's already a generic kernel mechanism for that.
Maybe perf/trace support could be added eventually.
drivers/fpga/fpga-mgr.c
Quoted 1 line
drivers/fpga/fpga-mgr.c +0
-0
[]
Quoted 39 lines
drivers/fpga/fpga-mgr.c +39
-0+/** +* fpga_mgr_status_write - Write fpga manager status +* @dev: Pointer to the device structure +* @attr: Pointer to the device attribute structure +* @buf: Pointer to the buffer location +* @count: Number of characters in @buf +* +* Returns the number of bytes copied to @buf, a negative error number otherwise +*/ +static ssize_t fpga_mgr_status_write (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct fpga_manager *mgr =dev_get_drvdata (dev); +int ret; + +if (test_and_set_bit_lock (FPGA_MGR_DEV_BUSY , &mgr->flags)) +return -EBUSY ; + + ret =strcmp (buf,"write_init" ); +if (!ret) { + ret =fpga_mgr_write_init (mgr); + goto out; + } + + ret =strcmp (buf,"write_complete" ); +if (!ret) { + ret =fpga_mgr_write_complete (mgr); + goto out; + } + + ret =strcmp (buf,"read_init" ); +if (!ret) { + ret =fpga_mgr_read_init (mgr); + goto out; + } + + ret =strcmp (buf,"read_complete" ); +if (!ret) {
drivers/fpga/fpga-mgr.c line 338
Quoted 10 lines
drivers/fpga/fpga-mgr.c +10
-0+ ret =fpga_mgr_read_complete (mgr); + goto out; + } + + ret = -EINVAL ; +out: +clear_bit_unlock (FPGA_MGR_DEV_BUSY , &mgr->flags); + +return ret ? : count; +}
I think this style is awkward and this would be
better written as:
if (!strcmp(buf, "write_init")) ret = fpga_mgr_write_init(mgr); else if (!strcmp(buf, "write_complete")) ret = fpga_mgr_write_complete(mgr); else if (!strcmp(buf, "read_init")) ret = fpga_mgr_read_init(mgr); else if (!strcmp(buf, "read_complete")) ret = fpga_mgr_read_complete(mgr); else ret = -EINVAL; clear_bit_unlock(FPGA_MGR_DEV_BUSY, &mgr->flags); if (ret) return ret; return count; }
Maybe use (strcmp(...) == 0) if you prefer that.
Both styles are commonly used in linux.
Probably all of the "return ret ?: count;" uses
would be more easily understood on 3 lines.
Re: [RFC PATCH v2] fpga: Introduce new fpga subsystem
Hi Joe,
Quoted 9 lines · Joe Perches
Quoted 5 lines · Michal Simek
This new fpga subsystem core should unify all fpga
drivers/managerswhich do the same things. Load configuration data to fpga or another programmable logic through common interface. It doesn't matter if it is MMIO device, gpio bitbanging, etc. connection. The point is to have the same interface for these drivers.Does this interface support partial reprogramming/configuration for FPGAs that can do that?
Currently we have two interfaces and third one is around (char driver) that's why I didn't look at this support.
But for Xilinx devices init and complete phase is different.
We can use one more flag parameter for init and complete functions.
It means we can simple extend config states with write_init_partial, etc Or the second option is to create new sysfs file to indicate that we will work with partial bitstreams.
Quoted 9 lines
trivial notes:
There are a _lot_ of
dev_dbgstatements.I hope some of these would be removed one day, especially the function tracing style ones, because there's already a generic kernel mechanism for that.
Maybe perf/trace support could be added eventually.
Are you talking about trace_printk?
Quoted 74 lines
drivers/fpga/fpga-mgr.c
Quoted 1 line
drivers/fpga/fpga-mgr.c +0
-0[]
Quoted 39 lines
drivers/fpga/fpga-mgr.c +39
-0+/** +* fpga_mgr_status_write - Write fpga manager status +* @dev: Pointer to the device structure +* @attr: Pointer to the device attribute structure +* @buf: Pointer to the buffer location +* @count: Number of characters in @buf +* +* Returns the number of bytes copied to @buf, a negative error number otherwise +*/ +static ssize_t fpga_mgr_status_write (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct fpga_manager *mgr =dev_get_drvdata (dev); +int ret; + +if (test_and_set_bit_lock (FPGA_MGR_DEV_BUSY , &mgr->flags)) +return -EBUSY ; + + ret =strcmp (buf,"write_init" ); +if (!ret) { + ret =fpga_mgr_write_init (mgr); + goto out; + } + + ret =strcmp (buf,"write_complete" ); +if (!ret) { + ret =fpga_mgr_write_complete (mgr); + goto out; + } + + ret =strcmp (buf,"read_init" ); +if (!ret) { + ret =fpga_mgr_read_init (mgr); + goto out; + } + + ret =strcmp (buf,"read_complete" ); +if (!ret) {drivers/fpga/fpga-mgr.c line 338
Quoted 10 lines
drivers/fpga/fpga-mgr.c +10
-0+ ret =fpga_mgr_read_complete (mgr); + goto out; + } + + ret = -EINVAL ; +out: +clear_bit_unlock (FPGA_MGR_DEV_BUSY , &mgr->flags); + +return ret ? : count; +}I think this style is awkward and this would be
better written as:if (!strcmp(buf, "write_init")) ret = fpga_mgr_write_init(mgr); else if (!strcmp(buf, "write_complete")) ret = fpga_mgr_write_complete(mgr); else if (!strcmp(buf, "read_init")) ret = fpga_mgr_read_init(mgr); else if (!strcmp(buf, "read_complete")) ret = fpga_mgr_read_complete(mgr); else ret = -EINVAL; clear_bit_unlock(FPGA_MGR_DEV_BUSY, &mgr->flags); if (ret) return ret; return count; }
Quoted 2 lines
Maybe use (strcmp(...) == 0) if you prefer that.
Both styles are commonly used in linux.
sure.
Quoted 2 lines
Probably all of the "return ret ?: count;" uses
would be more easily understood on 3 lines.
This structure is also quite common in the kernel
git grep "? :" | wc -l
415
git grep "?:" | wc -l
541
Thanks,
Michal
Signature · 5 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91 w: www.monstr.eu p: +42-0-721842854 Maintainer of Linux kernel - Microblaze cpu - http://www.monstr.eu/fdt/ Maintainer of Linux kernel - Xilinx Zynq ARM architecture Microblaze U-BOOT custodian and responsible for u-boot arm zynq platform
Re: [RFC PATCH v2] fpga: Introduce new fpga subsystem
Quoted 9 lines · Michal Simek
Quoted 2 lines
Probably all of the "return ret ?: count;" uses
would be more easily understood on 3 lines.This structure is also quite common in the kernel
git grep "? :" | wc -l
415git grep "?:" | wc -l
541
And it should all be removed and fixed up properly to make it easier to read and understand. Please don't add new instances of it, I sure will not take it.
greg k-h
Re: [RFC PATCH v2] fpga: Introduce new fpga subsystem
In reply to Michal SimekDocumentation/ABI/testing/sysfs-class-fpga line 18
Quoted 10 lines · Michal Simek
Documentation/ABI/testing/sysfs-class-fpga new file +10
-0+What: /sys/class/fpga_manager/fpga<dev-id>/fpga_config_state +Date: October 2013 +KernelVersion: 3.12 +Contact: Michal Simek <[email protected]> +Description: + By reading this file you will get current fpga manager state. + Flag bits are present in include/linux/fpga.h (FPGA_MGR_XX). + By writing to this file you can change fpga manager state. + Valid options are: write_init, write_complete, read_init, + read_complete.
This shouldn't be asymmetric - read/write should be in the same format.
I strongly encourage you to use text strings to indicate the state of the configuration FSM, and I *really* think you should rework things to have an explicit configuration FSM rather than trying to bodge one together with a bunch of bit flags.
Plus error handling is missing, failures need to be reported back.
Noticed several typos:
drivers/fpga/fpga-mgr.c line 62
Quoted 5 lines
drivers/fpga/fpga-mgr.c new file +5
-0+ +if (mgr->mops->read_init) { + ret = mgr->mops->read_init (mgr); +if (ret) { +dev_dbg (mgr->dev,"Failed to write_init\n" );
^^^^^^^^
read_init
Review
Quoted 1 line
(quoted diff) +1
-0+ if (mgr->mops->write) {
^^^^^^^^^^
read
drivers/fpga/fpga-mgr.c line 100
Quoted 3 lines
drivers/fpga/fpga-mgr.c new file +3
-0+ ret = mgr->mops->read (mgr, buf, count); +if (ret) { +dev_dbg (mgr->dev,"Failed to write\n" );
^^^^^^^^^^^^^^^^^
read
Review
Quoted 2 lines
(quoted diff) +2
-0+ + if (mgr->mops->write_complete) {
^^^^^^^^^^
read
drivers/fpga/fpga-mgr.c line 132
Quoted 3 lines
drivers/fpga/fpga-mgr.c new file +3
-0+ ret = mgr->mops->read_complete (mgr); +if (ret) { +dev_dbg (mgr->dev,"Failed to write_complete\n" );
^^^^^^^^^^^^
read
drivers/fpga/fpga-mgr.c line 200
Quoted 8 lines
drivers/fpga/fpga-mgr.c new file +8
-0+static inline int fpga_mgr_write (struct fpga_manager *mgr,const u8 *buf, +ssize_t count) +{ +int bit, ret; + +dev_dbg (mgr->dev,"%s %lx\n" , __func__, mgr->flags); + +/* FPGE init has to be done to be able to continue */
^^^^^^
FPGA
drivers/fpga/fpga-mgr.c line 491
Quoted 7 lines
drivers/fpga/fpga-mgr.c new file +7
-0+static struct device_attribute fpga_mgr_attrs[] = { +__ATTR (name,S_IRUGO , fpga_mgr_name_show,NULL ), +__ATTR (firmware,S_IWUSR ,NULL , fpga_mgr_attr_write), +__ATTR (fpga_config_state,S_IRUSR |S_IWUSR , + fpga_mgr_status_read, fpga_mgr_status_write), + __ATTR_NULL +};
AFAIK it is preferred to use DEVICE_ATTR_RO(), ATTRIBUTE_GROUPS() and struct class.dev_groups
eg see this note in linux/device.h
struct class {
struct device_attribute *dev_attrs; /* use dev_groups instead */
const struct attribute_group **dev_groups;
}
Quoted 6 lines
drivers/fpga/fpga-mgr.c new file +6
-0+struct fpga_manager *mgr; +int ret; + +if (!mops) { +dev_dbg (&pdev->dev,"Register failed: NO fpga_manager_ops\n" ); +return -EINVAL ;
drivers/fpga/fpga-mgr.c line 597
Quoted 10 lines
drivers/fpga/fpga-mgr.c new file +10
-0+ } + +if (!name || !strlen (name)) { +dev_dbg (&pdev->dev,"Register failed: NO name specific\n" ); +return -EINVAL ; + } + + mgr =devm_kzalloc (&pdev->dev,sizeof (*mgr),GFP_KERNEL ); +if (!mgr) +return -ENOMEM ;
I wonder if this is right, it seems like a strange way to make a class subsystem, usually the struct fpga_manager would contain the 'struct device' (not a pointer, so you can use container_of) and drvdata would be reserved for something else.
This seems to create lifetime issues since the devm above will be free'd when the platform driver is released, but the class device will live on with the stray pointer. Better to allocate everything against the class device below.
Plus you need to ensure the device is fully functionally before device_register is called, otherwise you race with notifications to userspace.
Quoted 10 lines
drivers/fpga/fpga-mgr.c new file +10
-0+/** +* fpga_mgr_unregister: Remove fpga manager +* @pdev: Pointer to the platform device of fpga manager +* +* Function unregister fpga manager and release all temporary structures +* +* Returns 0 for all cases +*/ +int fpga_mgr_unregister (struct platform_device *pdev) +{
drivers/fpga/fpga-mgr.c line 664
Quoted 10 lines
drivers/fpga/fpga-mgr.c new file +10
-0+struct fpga_manager *mgr =platform_get_drvdata (pdev); + +if (mgr && mgr->mops && mgr->mops->fpga_remove) + mgr->mops->fpga_remove (mgr); + +device_unregister (mgr->dev); + +spin_lock (&fpga_mgr_idr_lock); +idr_remove (&fpga_mgr_idr, mgr->nr); +spin_unlock (&fpga_mgr_idr_lock);
What happens when userspace is holding one of the sysfs files open and you unload the module? Looks like bad things?
Regards,
Jason
Re: [RFC PATCH v2] fpga: Introduce new fpga subsystem
Quoted 16 lines · Jason Gunthorpe
Documentation/ABI/testing/sysfs-class-fpga line 18
Quoted 10 lines · Michal Simek
Documentation/ABI/testing/sysfs-class-fpga new file +10
-0+What: /sys/class/fpga_manager/fpga<dev-id>/fpga_config_state +Date: October 2013 +KernelVersion: 3.12 +Contact: Michal Simek <[email protected]> +Description: + By reading this file you will get current fpga manager state. + Flag bits are present in include/linux/fpga.h (FPGA_MGR_XX). + By writing to this file you can change fpga manager state. + Valid options are: write_init, write_complete, read_init, + read_complete.This shouldn't be asymmetric - read/write should be in the same format.
Quoted 4 lines
I strongly encourage you to use text strings to indicate the state of the configuration FSM, and I *really* think you should rework things to have an explicit configuration FSM rather than trying to bodge one together with a bunch of bit flags.
Any favourite names for states?
Or ready, write_init, write_complete is enough for now?
Alan: This should be unified way for user to get proper states from the driver. It means from my point of view will be better to have set of states which this function can return instead of calling origin status function where we can't control states for all these drivers.
Quoted 1 line
Plus error handling is missing, failures need to be reported back.
Will fix this.
Quoted 1 line
Noticed several typos:
Ah yeah c&p. :-(
Quoted 51 lines
drivers/fpga/fpga-mgr.c line 62
Quoted 6 lines
drivers/fpga/fpga-mgr.c new file +5
-0+ +if (mgr->mops->read_init) { + ret = mgr->mops->read_init (mgr); +if (ret) { +dev_dbg (mgr->dev,"Failed to write_init\n" );^^^^^^^^
read_initReview
Quoted 1 line
(quoted diff) +1
-0+ if (mgr->mops->write) {^^^^^^^^^^read
drivers/fpga/fpga-mgr.c line 100
Quoted 3 lines
drivers/fpga/fpga-mgr.c new file +3
-0+ ret = mgr->mops->read (mgr, buf, count); +if (ret) { +dev_dbg (mgr->dev,"Failed to write\n" );^^^^^^^^^^^^^^^^^read
Review
Quoted 2 lines
(quoted diff) +2
-0+ + if (mgr->mops->write_complete) {^^^^^^^^^^read
drivers/fpga/fpga-mgr.c line 132
Quoted 3 lines
drivers/fpga/fpga-mgr.c new file +3
-0+ ret = mgr->mops->read_complete (mgr); +if (ret) { +dev_dbg (mgr->dev,"Failed to write_complete\n" );^^^^^^^^^^^^
readdrivers/fpga/fpga-mgr.c line 200
Quoted 8 lines
drivers/fpga/fpga-mgr.c new file +8
-0+static inline int fpga_mgr_write (struct fpga_manager *mgr,const u8 *buf, +ssize_t count) +{ +int bit, ret; + +dev_dbg (mgr->dev,"%s %lx\n" , __func__, mgr->flags); + +/* FPGE init has to be done to be able to continue */ ^^^^^^FPGA
drivers/fpga/fpga-mgr.c line 491
Quoted 7 lines
drivers/fpga/fpga-mgr.c new file +7
-0+static struct device_attribute fpga_mgr_attrs[] = { +__ATTR (name,S_IRUGO , fpga_mgr_name_show,NULL ), +__ATTR (firmware,S_IWUSR ,NULL , fpga_mgr_attr_write), +__ATTR (fpga_config_state,S_IRUSR |S_IWUSR , + fpga_mgr_status_read, fpga_mgr_status_write), + __ATTR_NULL +};AFAIK it is preferred to use
DEVICE_ATTR_RO(),ATTRIBUTE_GROUPS()and struct class.dev_groups
Quoted 7 lines
eg see this note in
linux/device.hstruct class {
structdevice_attribute*dev_attrs; /* usedev_groupsinstead */
const structattribute_group**dev_groups;
}
This will be fixed in v3. I have already changed this.
Quoted 13 lines
Quoted 13 lines
drivers/fpga/fpga-mgr.c new file +13
-0+struct fpga_manager *mgr; +int ret; + +if (!mops) { +dev_dbg (&pdev->dev,"Register failed: NO fpga_manager_ops\n" ); +return -EINVAL ; + } + +if (!name || !strlen (name)) { +dev_dbg (&pdev->dev,"Register failed: NO name specific\n" ); +return -EINVAL ; + } +
Quoted 8 lines
drivers/fpga/fpga-mgr.c line 597
Quoted 3 lines
drivers/fpga/fpga-mgr.c new file +3
-0+ mgr =devm_kzalloc (&pdev->dev,sizeof (*mgr),GFP_KERNEL ); +if (!mgr) +return -ENOMEM ;I wonder if this is right, it seems like a strange way to make a class subsystem, usually the struct
fpga_managerwould contain the 'struct device' (not a pointer, so you can usecontainer_of) and drvdata would be reserved for something else.
I am not following you here. mrg structure is connected with the driver it means when driver is removed then this structure is freed.
Quoted 5 lines
This seems to create lifetime issues since the devm above will be free'd when the platform driver is released, but the class device will live on with the stray pointer. Better to allocate everything against the class device below.
device in unregistered before this structure is freed. fpga_mgr_unregister() is called in the platform driver in remove function.
Quoted 4 lines
Plus you need to ensure the device is fully functionally before
device_registeris called, otherwise you race with notifications to userspace.
fpga_mgr_register() should be called as the latest function in the probe in platform_driver. At least it is what I have for zynq.
Quoted 15 lines
Quoted 15 lines
drivers/fpga/fpga-mgr.c new file +15
-0+/** +* fpga_mgr_unregister: Remove fpga manager +* @pdev: Pointer to the platform device of fpga manager +* +* Function unregister fpga manager and release all temporary structures +* +* Returns 0 for all cases +*/ +int fpga_mgr_unregister (struct platform_device *pdev) +{ +struct fpga_manager *mgr =platform_get_drvdata (pdev); + +if (mgr && mgr->mops && mgr->mops->fpga_remove) + mgr->mops->fpga_remove (mgr); +
Quoted 8 lines
drivers/fpga/fpga-mgr.c line 664
Quoted 5 lines
drivers/fpga/fpga-mgr.c new file +5
-0+device_unregister (mgr->dev); + +spin_lock (&fpga_mgr_idr_lock); +idr_remove (&fpga_mgr_idr, mgr->nr); +spin_unlock (&fpga_mgr_idr_lock);What happens when userspace is holding one of the sysfs files open and you unload the module? Looks like bad things?
I didn't test this but feel free to check it.
Thanks,
Michal
Signature · 5 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91 w: www.monstr.eu p: +42-0-721842854 Maintainer of Linux kernel - Microblaze cpu - http://www.monstr.eu/fdt/ Maintainer of Linux kernel - Xilinx Zynq ARM architecture Microblaze U-BOOT custodian and responsible for u-boot arm zynq platform
Re: [RFC PATCH v2] fpga: Introduce new fpga subsystem
Quoted 7 lines · Michal Simek
Quoted 4 lines
I strongly encourage you to use text strings to indicate the state of the configuration FSM, and I *really* think you should rework things to have an explicit configuration FSM rather than trying to bodge one together with a bunch of bit flags.
Any favourite names for states?
Or ready,write_init,write_completeis enough for now?
Doesnt really matter to me, don't forget error states. Transisionts to ready, write_init and write_complete can all fail.
Quoted 7 lines
Quoted 4 lines
I wonder if this is right, it seems like a strange way to make a class subsystem, usually the struct
fpga_managerwould contain the 'struct device' (not a pointer, so you can usecontainer_of) and drvdata would be reserved for something else.I am not following you here. mrg structure is connected with the driver it means when driver is removed then this structure is freed.
You've got your mgr structure and then later you allocate a struct device as well, the mgr can be free'd before the struct device is released, due to the way ref counting works. You are not doing anything to compensate for that.
Quoted 7 lines
Quoted 4 lines
This seems to create lifetime issues since the devm above will be free'd when the platform driver is released, but the class device will live on with the stray pointer. Better to allocate everything against the class device below.
device in unregistered before this structure is freed.
fpga_mgr_unregister()is called in the platform driver in remove function.
Which is the problem, device_unregister dosen't delete 'mgr->dev', and it doesn't mean the sysfs call backs are uncallable, so you have a free'd dangling pointer in mgr->dev, and an object lifetime issue.
Quoted 4 lines
Quoted 2 lines
What happens when userspace is holding one of the sysfs files open and you unload the module? Looks like bad things?
I didn't test this but feel free to check it.
You should fix these problems before your driver reaches Linus.
Jason
Re: [RFC PATCH v2] fpga: Introduce new fpga subsystem
In reply to Michal SimekQuoted 17 lines · Michal Simek
Quoted 16 lines · Jason Gunthorpe
Documentation/ABI/testing/sysfs-class-fpga line 18
Quoted 10 lines · Michal Simek
Documentation/ABI/testing/sysfs-class-fpga new file +10
-0+What: /sys/class/fpga_manager/fpga<dev-id>/fpga_config_state +Date: October 2013 +KernelVersion: 3.12 +Contact: Michal Simek <[email protected]> +Description: + By reading this file you will get current fpga manager state. + Flag bits are present in include/linux/fpga.h (FPGA_MGR_XX). + By writing to this file you can change fpga manager state. + Valid options are: write_init, write_complete, read_init, + read_complete.This shouldn't be asymmetric - read/write should be in the same format.
Quoted 7 lines
Quoted 4 lines
I strongly encourage you to use text strings to indicate the state of the configuration FSM, and I *really* think you should rework things to have an explicit configuration FSM rather than trying to bodge one together with a bunch of bit flags.
Any favourite names for states?
Or ready,write_init,write_completeis enough for now?
Currently the only state I want to attempt to *set* from sysfs would be reset.
For Altera fpga, the states I want to *report* are:
static const char *const altera_fpga_state_str[] = {
[ALT_FPGAMGR_STAT_POWER_UP] = "power up phase", [ALT_FPGAMGR_STAT_RESET] = "reset phase", [ALT_FPGAMGR_STAT_CFG] = "configuration phase", [ALT_FPGAMGR_STAT_INIT] = "initialization phase", [ALT_FPGAMGR_STAT_USER_MODE] = "user mode", [ALT_FPGAMGR_STAT_UNKNOWN] = "undetermined", [ALT_FPGAMGR_STAT_POWER_OFF] = "powered off",
};
Setting write_init and write_complete explicitly is fine, but not needed for me. I'm fine with the driver knowing that if I request to write data, it knows that it needs to write_init and write_complete. Either way works for me here.
Quoted 5 lines
Alan: This should be unified way for user to get proper states from the driver. It means from my point of view will be better to have set of states which this function can return instead of calling origin status function where we can't control states for all these drivers.
I agree with both you and Jason on this :) I agree that it should be strings, and also that it probably should come from the framework instead of directly from the low level driver. The framework should query the low level driver for state. Not all vendors' fpgas support exactly the same set of states, so we can hash out a superset that we can agree on that fits all our needs (mine are above).
I think this is separate from your 'flags' implementation. I like that implementation for locking, but I want something that actually goes to the low level driver to find out what state the fpga manager has to report.
Quoted 142 lines
Quoted 2 lines
Plus error handling is missing, failures need to be reported back.
Will fix this.
Quoted 1 line
Noticed several typos:
Ah yeah c&p. :-(
Quoted 51 lines
drivers/fpga/fpga-mgr.c line 62
Quoted 6 lines
drivers/fpga/fpga-mgr.c new file +5
-0+ +if (mgr->mops->read_init) { + ret = mgr->mops->read_init (mgr); +if (ret) { +dev_dbg (mgr->dev,"Failed to write_init\n" );^^^^^^^^
read_initReview
Quoted 1 line
(quoted diff) +1
-0+ if (mgr->mops->write) {^^^^^^^^^^read
drivers/fpga/fpga-mgr.c line 100
Quoted 3 lines
drivers/fpga/fpga-mgr.c new file +3
-0+ ret = mgr->mops->read (mgr, buf, count); +if (ret) { +dev_dbg (mgr->dev,"Failed to write\n" );^^^^^^^^^^^^^^^^^read
Review
Quoted 2 lines
(quoted diff) +2
-0+ + if (mgr->mops->write_complete) {^^^^^^^^^^read
drivers/fpga/fpga-mgr.c line 132
Quoted 3 lines
drivers/fpga/fpga-mgr.c new file +3
-0+ ret = mgr->mops->read_complete (mgr); +if (ret) { +dev_dbg (mgr->dev,"Failed to write_complete\n" );^^^^^^^^^^^^
readdrivers/fpga/fpga-mgr.c line 200
Quoted 8 lines
drivers/fpga/fpga-mgr.c new file +8
-0+static inline int fpga_mgr_write (struct fpga_manager *mgr,const u8 *buf, +ssize_t count) +{ +int bit, ret; + +dev_dbg (mgr->dev,"%s %lx\n" , __func__, mgr->flags); + +/* FPGE init has to be done to be able to continue */ ^^^^^^FPGA
drivers/fpga/fpga-mgr.c line 491
Quoted 7 lines
drivers/fpga/fpga-mgr.c new file +7
-0+static struct device_attribute fpga_mgr_attrs[] = { +__ATTR (name,S_IRUGO , fpga_mgr_name_show,NULL ), +__ATTR (firmware,S_IWUSR ,NULL , fpga_mgr_attr_write), +__ATTR (fpga_config_state,S_IRUSR |S_IWUSR , + fpga_mgr_status_read, fpga_mgr_status_write), + __ATTR_NULL +};AFAIK it is preferred to use
DEVICE_ATTR_RO(),ATTRIBUTE_GROUPS()and struct class.dev_groupsQuoted 7 lines
eg see this note in
linux/device.hstruct class {
structdevice_attribute*dev_attrs; /* usedev_groupsinstead */
const structattribute_group**dev_groups;
}This will be fixed in v3. I have already changed this.
Quoted 13 lines
Quoted 13 lines
drivers/fpga/fpga-mgr.c new file +13
-0+struct fpga_manager *mgr; +int ret; + +if (!mops) { +dev_dbg (&pdev->dev,"Register failed: NO fpga_manager_ops\n" ); +return -EINVAL ; + } + +if (!name || !strlen (name)) { +dev_dbg (&pdev->dev,"Register failed: NO name specific\n" ); +return -EINVAL ; + } +Quoted 8 lines
drivers/fpga/fpga-mgr.c line 597
Quoted 3 lines
drivers/fpga/fpga-mgr.c new file +3
-0+ mgr =devm_kzalloc (&pdev->dev,sizeof (*mgr),GFP_KERNEL ); +if (!mgr) +return -ENOMEM ;I wonder if this is right, it seems like a strange way to make a class subsystem, usually the struct
fpga_managerwould contain the 'struct device' (not a pointer, so you can usecontainer_of) and drvdata would be reserved for something else.I am not following you here. mrg structure is connected with the driver it means when driver is removed then this structure is freed.
Quoted 5 lines
This seems to create lifetime issues since the devm above will be free'd when the platform driver is released, but the class device will live on with the stray pointer. Better to allocate everything against the class device below.
device in unregistered before this structure is freed.
fpga_mgr_unregister()is called in the platform driver in remove function.Quoted 4 lines
Plus you need to ensure the device is fully functionally before
device_registeris called, otherwise you race with notifications to userspace.
fpga_mgr_register()should be called as the latest function in the probe inplatform_driver. At least it is what I have for zynq.Quoted 15 lines
Quoted 15 lines
drivers/fpga/fpga-mgr.c new file +15
-0+/** +* fpga_mgr_unregister: Remove fpga manager +* @pdev: Pointer to the platform device of fpga manager +* +* Function unregister fpga manager and release all temporary structures +* +* Returns 0 for all cases +*/ +int fpga_mgr_unregister (struct platform_device *pdev) +{ +struct fpga_manager *mgr =platform_get_drvdata (pdev); + +if (mgr && mgr->mops && mgr->mops->fpga_remove) + mgr->mops->fpga_remove (mgr); +Quoted 8 lines
drivers/fpga/fpga-mgr.c line 664
Quoted 5 lines
drivers/fpga/fpga-mgr.c new file +5
-0+device_unregister (mgr->dev); + +spin_lock (&fpga_mgr_idr_lock); +idr_remove (&fpga_mgr_idr, mgr->nr); +spin_unlock (&fpga_mgr_idr_lock);What happens when userspace is holding one of the sysfs files open and you unload the module? Looks like bad things?
I didn't test this but feel free to check it.
Thanks,
Michal
Quoted 4 lines · Michal Simek
Based on my discussion at ELC with Greg KH the new driver should support firmware interface for loading bitstream.
As I have previously stated, I think this is a mistake simply because the firmware interface is a bad mapping on requirements for an FPGA, especially once you account for the vast number of ways an FPGA can get loaded and you take partial reconfiguration into account. I happen to be at a face to face meeting with Greg today, so I'll pick his brain a bit.
-hpa
Quoted 6 lines · H. Peter Anvin
Quoted 4 lines · Michal Simek
Based on my discussion at ELC with Greg KH the new driver should support firmware interface for loading bitstream.
Quoted 6 lines
As I have previously stated, I think this is a mistake simply because the firmware interface is a bad mapping on requirements for an FPGA, especially once you account for the vast number of ways an FPGA can get loaded and you take partial reconfiguration into account. I happen to be at a face to face meeting with Greg today, so I'll pick his brain a bit.
Umm. Could the discussion be kept on line?
Yes, more than one bitstream makes sense for fpga, but more than one firmware makes sense for most other devices, too...
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 7 lines · Pavel Machek
Quoted 6 lines · H. Peter Anvin
Quoted 4 lines · Michal Simek
Based on my discussion at ELC with Greg KH the new driver should support firmware interface for loading bitstream.
Quoted 8 lines
Quoted 6 lines
As I have previously stated, I think this is a mistake simply because the firmware interface is a bad mapping on requirements for an FPGA, especially once you account for the vast number of ways an FPGA can get loaded and you take partial reconfiguration into account. I happen to be at a face to face meeting with Greg today, so I'll pick his brain a bit.
Umm. Could the discussion be kept on line?
I agree with you.
But anyway what was resolution from that meeting?
Thanks,
Michal
Signature · 5 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91 w: www.monstr.eu p: +42-0-721842854 Maintainer of Linux kernel - Microblaze cpu - http://www.monstr.eu/fdt/ Maintainer of Linux kernel - Xilinx Zynq ARM architecture Microblaze U-BOOT custodian and responsible for u-boot arm zynq platform
Quoted 1 line · Michal Simek
But anyway what was resolution from that meeting?
It never happened, we got distracted by lunch :)
Yes; I never got too corner Greg ;)
Quoted 4 lines · Greg Kroah-Hartman
Quoted 1 line · Michal Simek
But anyway what was resolution from that meeting?
It never happened, we got distracted by lunch :)
Signature · 1 line
Sent from my mobile phone. Please pardon brevity and lack of formatting.
Quoted 7 lines · H. Peter Anvin
Yes; I never got too corner Greg ;)
Quoted 4 lines · Greg Kroah-Hartman
Quoted 1 line · Michal Simek
But anyway what was resolution from that meeting?
It never happened, we got distracted by lunch :)
Then why not to have it here?
M
Signature · 5 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91 w: www.monstr.eu p: +42-0-721842854 Maintainer of Linux kernel - Microblaze cpu - http://www.monstr.eu/fdt/ Maintainer of Linux kernel - Xilinx Zynq ARM architecture Microblaze U-BOOT custodian and responsible for u-boot arm zynq platform
Quoted 11 lines · Michal Simek
Quoted 7 lines · H. Peter Anvin
Yes; I never got too corner Greg ;)
Quoted 4 lines · Greg Kroah-Hartman
Quoted 1 line · Michal Simek
But anyway what was resolution from that meeting?
It never happened, we got distracted by lunch :)
Then why not to have it here?
The essential question is if the firmware interface really is appropriate for FPGAs. It definitely has a feel of a "square peg in a round hole", especially when you consider the myriad ways FPGAs can be configured (some persistent, some not, some which takes effect now, some which come later, some which involve bytecode interpreters...) and considering reconfiguration and partial reconfiguration.
-hpa
Quoted 13 lines · H. Peter Anvin
Quoted 11 lines · Michal Simek
Quoted 7 lines · H. Peter Anvin
Yes; I never got too corner Greg ;)
Quoted 4 lines · Greg Kroah-Hartman
Quoted 1 line · Michal Simek
But anyway what was resolution from that meeting?
It never happened, we got distracted by lunch :)
Then why not to have it here?
Quoted 6 lines
The essential question is if the firmware interface really is appropriate for FPGAs. It definitely has a feel of a "square peg in a round hole", especially when you consider the myriad ways FPGAs can be configured (some persistent, some not, some which takes effect now, some which come later, some which involve bytecode interpreters...) and considering reconfiguration and partial reconfiguration.
If you look at it in general I believe that there is wide range
of applications which just contain one bitstream per fpga and the bitstream is replaced by newer version in upgrade. For them firmware interface should be pretty useful. Just setup firmware name with bitstream and it will be automatically loaded in startup phase.
Then there is another set of applications especially in connection to partial reconfiguration where this can be done statically by pregenerated partial bitstreams
or automatically generated on target cpu. For doing everything on the target firmware interface is not the best because everything can be handled by user application and it is easier just to push this bitstream to do device and not to save it to the fs.
I think the question here is if this subsystem could have several interfaces. For example Alan is asking for adding char support.
Does it even make sense to have more interfaces with the same backend driver? When this is answered then we can talk which one make sense to have. In v2 is sysfs and firmware one. Adding char is also easy to do.
Thanks,
Michal
Signature · 5 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91 w: www.monstr.eu p: +42-0-721842854 Maintainer of Linux kernel - Microblaze cpu - http://www.monstr.eu/fdt/ Maintainer of Linux kernel - Xilinx Zynq ARM architecture Microblaze U-BOOT custodian and responsible for u-boot arm zynq platform
Quoted 16 lines · Michal Simek
If you look at it in general I believe that there is wide range of applications which just contain one bitstream per fpga and the bitstream is replaced by newer version in upgrade. For them firmware interface should be pretty useful. Just setup firmware name with bitstream and it will be automatically loaded in startup phase.
Then there is another set of applications especially in connection to partial reconfiguration where this can be done statically by pregenerated partial bitstreams or automatically generated on target cpu. For doing everything on the target firmware interface is not the best because everything can be handled by user application and it is easier just to push this bitstream to do device and not to save it to the fs.
Quoted 7 lines
I think the question here is if this subsystem could have several interfaces. For example Alan is asking for adding char support. Does it even make sense to have more interfaces with the same backend driver? When this is answered then we can talk which one make sense to have. In v2 is sysfs and firmware one. Adding char is also easy to do.
Greg, what do you think?
I agree that the firmware interface makes sense when the use of the FPGA is an implementation detail in a fixed hardware configuration, but that is a fairly restricted use case all things considered.
-hpa
Quoted 25 lines · H. Peter Anvin
Quoted 16 lines · Michal Simek
If you look at it in general I believe that there is wide range of applications which just contain one bitstream per fpga and the bitstream is replaced by newer version in upgrade. For them firmware interface should be pretty useful. Just setup firmware name with bitstream and it will be automatically loaded in startup phase.
Then there is another set of applications especially in connection to partial reconfiguration where this can be done statically by pregenerated partial bitstreams or automatically generated on target cpu. For doing everything on the target firmware interface is not the best because everything can be handled by user application and it is easier just to push this bitstream to do device and not to save it to the fs.
Quoted 7 lines
I think the question here is if this subsystem could have several interfaces. For example Alan is asking for adding char support. Does it even make sense to have more interfaces with the same backend driver? When this is answered then we can talk which one make sense to have. In v2 is sysfs and firmware one. Adding char is also easy to do.
Quoted 5 lines
Greg, what do you think?
I agree that the firmware interface makes sense when the use of the FPGA is an implementation detail in a fixed hardware configuration, but that is a fairly restricted use case all things considered.
Ideally I thought this would be just like "firmware", you dump the file to the FPGA, it validates it and away you go with a new image running in the chip.
But, it sounds like this is much more complicated, so much so that configfs might be the correct interface for it, as you can do lots of things there, and it is very flexible (some say too flexible...)
A char device, with a zillion different custom ioctls is also a way to do it, but one that I really want to avoid as that gets messy really quickly.
thanks,
greg k-h
Quoted 7 lines · Greg Kroah-Hartman
Quoted 3 lines
I agree that the firmware interface makes sense when the use of the FPGA is an implementation detail in a fixed hardware configuration, but that is a fairly restricted use case all things considered.
Ideally I thought this would be just like "firmware", you dump the file to the FPGA, it validates it and away you go with a new image running in the chip.
That is 99% of the use cases. The other stuff people are talking about is fringe.
I've been doing FPGAs for > 10 years and I've never once used read back via the config bus. In fact all my FPGAs turn that feature off once they are loaded.
Partial reconfiguration is very specialized, and hard to use from a FPGA design standpoint.
I also think it is sensible to focus this interface on simple SRAM FPGAs, not FLASH based stuff, or whatever complex device required a byte code interpreter (never heard of that before).
Jason
Every FPGA toolchain I know of has a way to emit JAM/STAPL bytecode files... and a fair number of programming scenarios need them.
Quoted 27 lines · Jason Gunthorpe
Quoted 5 lines · Greg Kroah-Hartman
Quoted 3 lines
I agree that the firmware interface makes sense when the use of the FPGA is an implementation detail in a fixed hardware configuration, but that is a fairly restricted use case all things considered.
Ideally I thought this would be just like "firmware", you dump the
file
Quoted 1 line
to the FPGA, it validates it and away you go with a new image running
in
Quoted 1 line
the chip.
That is 99% of the use cases. The other stuff people are talking about is fringe.
I've been doing FPGAs for > 10 years and I've never once used read back via the config bus. In fact all my FPGAs turn that feature off once they are loaded.
Partial reconfiguration is very specialized, and hard to use from a FPGA design standpoint.
I also think it is sensible to focus this interface on simple SRAM FPGAs, not FLASH based stuff, or whatever complex device required a byte code interpreter (never heard of that before).
Jason
Signature · 1 line
Sent from my mobile phone. Please pardon brevity and lack of formatting.
Quoted 2 lines · H. Peter Anvin
Every FPGA toolchain I know of has a way to emit JAM/STAPL bytecode files... and a fair number of programming scenarios need them.
Yes, but now you are talking about JTAG.
JTAG is a very different problem than configuring over the configuration bus, I don't think it makes much sense to try and combine those two things into a single subsystem.
The majority use of JAM/STAPL output is for manufacturing automation. In system, In field programming of SRAM FPGAs via JTAG is uncommon.
Jason
I do it all the time.
JAM/STAPL seems to me to be more used for exotic connections to serial flash for persistent programming.
Quoted 16 lines · Jason Gunthorpe
Quoted 2 lines · H. Peter Anvin
Every FPGA toolchain I know of has a way to emit JAM/STAPL bytecode files... and a fair number of programming scenarios need them.
Yes, but now you are talking about JTAG.
JTAG is a very different problem than configuring over the configuration bus, I don't think it makes much sense to try and combine those two things into a single subsystem.
The majority use of JAM/STAPL output is for manufacturing automation. In system, In field programming of SRAM FPGAs via JTAG is uncommon.
Jason
Signature · 1 line
Sent from my mobile phone. Please pardon brevity and lack of formatting.
Quoted 3 lines · H. Peter Anvin
I do it all the time.
JAM/STAPL seems to me to be more used for exotic connections to serial flash for persistent programming.
ok. I expect you have any code which you are using. Why not to share it with us to see how you are using it?
I will try to find out some people at Xilinx to have generic overview about all these methods.
Thanks,
Michal
Signature · 5 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91 w: www.monstr.eu p: +42-0-721842854 Maintainer of Linux kernel - Microblaze cpu - http://www.monstr.eu/fdt/ Maintainer of Linux kernel - Xilinx Zynq ARM architecture Microblaze U-BOOT custodian and responsible for u-boot arm zynq platform
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 1 line · H. Peter Anvin
I would, but in my case it was employer-owned and closed.
ok. But I believe general concept for this can be shared. If you used char device, sysfs, etc.
Thanks,
Michal
Signature · 5 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91 w: www.monstr.eu p: +42-0-721842854 Maintainer of Linux kernel - Microblaze cpu - http://www.monstr.eu/fdt/ Maintainer of Linux kernel - Xilinx Zynq ARM architecture Microblaze U-BOOT custodian and responsible for u-boot arm zynq platform
If I recall correctly we simply poked at the FPGA directly from userspace. Not ideal by any means and also meant we had to have a backup recovery mechanism as it meant that the FPGA had to be programmed already as the bus interface was in soft IP.
Quoted 8 lines · Michal Simek
Quoted 1 line · H. Peter Anvin
I would, but in my case it was employer-owned and closed.
ok. But I believe general concept for this can be shared. If you used char device, sysfs, etc.
Thanks,
Michal
Signature · 1 line
Sent from my mobile phone. Please pardon brevity and lack of formatting.
Quoted 1 line · H. Peter Anvin
If I recall correctly we simply poked at the FPGA directly from userspace.
Not ideal by any means and also meant we had to have a backup recovery mechanism as it meant
that the FPGA had to be programmed already as the bus interface was in soft IP.
ok. How was that physical hardware connection to device you wanted to talk? Was it any special IP with MMIO? Or gpio jtag emulation or similar?
Thanks,
Michal
Signature · 5 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91 w: www.monstr.eu p: +42-0-721842854 Maintainer of Linux kernel - Microblaze cpu - http://www.monstr.eu/fdt/ Maintainer of Linux kernel - Xilinx Zynq ARM architecture Microblaze U-BOOT custodian and responsible for u-boot arm zynq platform
Special soft IP presenting a PCI device to the host.
Quoted 14 lines · Michal Simek
Quoted 1 line · H. Peter Anvin
If I recall correctly we simply poked at the FPGA directly from
userspace.
Not ideal by any means and also meant we had to have a backup recovery mechanism as it meant
that the FPGA had to be programmed already as the bus interface was in soft IP.ok. How was that physical hardware connection to device you wanted to talk?
Was it any special IP with MMIO? Or gpio jtag emulation or similar?Thanks,
Michal
Signature · 1 line
Sent from my mobile phone. Please pardon brevity and lack of formatting.
Quoted 1 line · H. Peter Anvin
Special soft IP presenting a PCI device to the host.
ok. It means that you should need just different backend for this device which is able to communicate over PCI.
I still can't see why this case should be problematic for this fpga manager.
As Jason pointed if this is just about JTAG emulation and your data is in different format then you have to create your backend which will support this configuration.
I will want to look at gpio jtag emulation to be able to program different board. We have this support for u-boot and doing in Linux should be also possible.
I think the question is if we can live with 2/3 user interfaces. I tend to keep firmware one because it is covering a lot of common use cases and it can be easily to use.
And then I don't have any preference if sysfs or char device is better.
Thanks,
Michal
Signature · 5 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91 w: www.monstr.eu p: +42-0-721842854 Maintainer of Linux kernel - Microblaze cpu - http://www.monstr.eu/fdt/ Maintainer of Linux kernel - Xilinx Zynq ARM architecture Microblaze U-BOOT custodian and responsible for u-boot arm zynq platform
Quoted 15 lines · Michal Simek
Quoted 1 line · H. Peter Anvin
Special soft IP presenting a PCI device to the host.
ok. It means that you should need just different backend for this device which is able to communicate over PCI.
I still can't see why this case should be problematic for this fpga manager.
As Jason pointed if this is just about JTAG emulation and your data is in different format then you have to create your backend which will support this configuration.
I will want to look at gpio jtag emulation to be able to program different board. We have this support for u-boot and doing in Linux should be also possible.
Quoted 4 lines
I think the question is if we can live with 2/3 user interfaces. I tend to keep firmware one because it is covering a lot of common use cases and it can be easily to use.
And then I don't have any preference if sysfs or char device
The sysfs and char device interface are equal, except I don't think it is right to write binary data to a sysfs attribute.
The difference between these 3 options is that firmware will work for some fixed use cases, but either the sysfs or char interface will work for all the use cases.
Alan
Quoted 5 lines
is better.
Thanks,
Michal
Quoted 16 lines · Alan Tull
Quoted 15 lines · Michal Simek
Quoted 1 line · H. Peter Anvin
Special soft IP presenting a PCI device to the host.
ok. It means that you should need just different backend for this device which is able to communicate over PCI.
I still can't see why this case should be problematic for this fpga manager.
As Jason pointed if this is just about JTAG emulation and your data is in different format then you have to create your backend which will support this configuration.
I will want to look at gpio jtag emulation to be able to program different board. We have this support for u-boot and doing in Linux should be also possible.
Quoted 7 lines
Quoted 4 lines
I think the question is if we can live with 2/3 user interfaces. I tend to keep firmware one because it is covering a lot of common use cases and it can be easily to use.
And then I don't have any preference if sysfs or char deviceThe sysfs and char device interface are equal, except I don't think it is right to write binary data to a sysfs attribute.
That's exactly what binary sysfs files are for :)
Quoted 3 lines
The difference between these 3 options is that firmware will work for some fixed use cases, but either the sysfs or char interface will work for all the use cases.
I don't understand how one will work but the other will not, please explain.
thanks,
greg k-h
A message that is not in the archive (sent off-list or not yet received): CANk1AXS9fpypVVWgvvUCZjKXDvLPpB7=kCNucwFcktgBHmV37w@mail.gmail.com
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 7 lines · H. Peter Anvin
A very common use case would be where a device contains an FPGA but is presented to the user as a product, often having its own device driver to drive the programmed device and/or additional logic. From *that* point of view it would be nice if the FPGA subsystem had the capability for the *device driver* to trigger a firmware load request which is then fed to the FPGA subsystem for programming. This would be an in-kernel interface, in other words.
That is sort of backwards though, how does the driver know it should load and start fpga progamming?
The way we are working driver attach today is to program the FPGA, under control of user space, and then do a PCI rescan, which discovers the FPGA device and triggers driver binding of the PCI FPGA driver.
Please keep in mind that loading the wrong FPGA could permanently destroy the system. This is why we have meta-data encoded with the bitstream. The user space loader does some sanity checks :)
Jason
Quoted 2 lines · Jason Gunthorpe
That is sort of backwards though, how does the driver know it should load and start fpga progamming?
A common way is for there to be a bitstream stored in flash which presents an interface to download the data. I think some FPGAs with hard bus IP even has that built in.
Another variant -- common on USB -- is to use a simple USB interface chip like an FTDI which can be used (sometimes in conjunction with a CPLD) to (in effect) bitbang in a bitstream into the FPGA. After configuration, the programming pins are used for the USB interface.
-hpa
Quoted 4 lines · H. Peter Anvin
I do it all the time.
JAM/STAPL seems to me to be more used for exotic connections to serial flash for persistent programming.
The FPGA tools write two kinds of SVF/JAM/STAPL files, one is ment to be replayed the to FPGA itself (what I was talking about), and one is ment to be replayed to the vendor's family of configuration PROMS (aka funky serial FLASH)
Programming the PROM in-ciruit/in-field via JTAG is normal, while programming the FPGA via JTAG is uncommon. This proposed FPGA susbsytem is about programming SRAM FPGAs, not FLASH ...
Fortunately these PROMs are on their way out, modern FPGAs can be directly connected to normal NOR FLASH and you can program the NOR via drivers/mtd :)
Regards,
Jason
Quoted 6 lines · Jason Gunthorpe
Quoted 4 lines · Greg Kroah-Hartman
Quoted 3 lines
I agree that the firmware interface makes sense when the use of the FPGA is an implementation detail in a fixed hardware configuration, but that is a fairly restricted use case all things considered.
Quoted 6 lines
Quoted 3 lines
Ideally I thought this would be just like "firmware", you dump the file to the FPGA, it validates it and away you go with a new image running in the chip.
That is 99% of the use cases. The other stuff people are talking about is fringe.
yep.
Quoted 6 lines
I've been doing FPGAs for > 10 years and I've never once used read back via the config bus. In fact all my FPGAs turn that feature off once they are loaded.
Partial reconfiguration is very specialized, and hard to use from a FPGA design standpoint.
And also from software point of view in connection to drivers handling. It means tools supports partial reconfiguration and even Xilinx produce TRD design where partial reconfiguration is used but it is long way to go to get this work nicely.
Quoted 3 lines
I also think it is sensible to focus this interface on simple SRAM FPGAs, not FLASH based stuff, or whatever complex device required a byte code interpreter (never heard of that before).
Agree.
Michal
Signature · 5 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91 w: www.monstr.eu p: +42-0-721842854 Maintainer of Linux kernel - Microblaze cpu - http://www.monstr.eu/fdt/ Maintainer of Linux kernel - Xilinx Zynq ARM architecture Microblaze U-BOOT custodian and responsible for u-boot arm zynq platform
Quoted 5 lines · Greg Kroah-Hartman
Ideally I thought this would be just like "firmware", you dump the file to the FPGA, it validates it and away you go with a new image running in the chip.
Quoted 8 lines
But, it sounds like this is much more complicated, so much so that configfs might be the correct interface for it, as you can do lots of things there, and it is very flexible (some say too flexible...)
A char device, with a zillion different custom ioctls is also a way to do it, but one that I really want to avoid as that gets messy really quickly.
I'm not sure that a zillion custom ioctls are necessary, but I think we really need to get a better understanding of the various usage cases (and there are going to be ones where an "FPGA driver" simply makes no sense at all.)
-hpa
Quoted 15 lines · H. Peter Anvin
Quoted 5 lines · Greg Kroah-Hartman
Ideally I thought this would be just like "firmware", you dump the file to the FPGA, it validates it and away you go with a new image running in the chip.
Quoted 8 lines
But, it sounds like this is much more complicated, so much so that configfs might be the correct interface for it, as you can do lots of things there, and it is very flexible (some say too flexible...)
A char device, with a zillion different custom ioctls is also a way to do it, but one that I really want to avoid as that gets messy really quickly.
Quoted 4 lines
I'm not sure that a zillion custom ioctls are necessary, but I think we really need to get a better understanding of the various usage cases (and there are going to be ones where an "FPGA driver" simply makes no sense at all.)
Isn't this a reason to add this to staging area a see where this can go?
Thanks,
Michal
Signature · 5 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91 w: www.monstr.eu p: +42-0-721842854 Maintainer of Linux kernel - Microblaze cpu - http://www.monstr.eu/fdt/ Maintainer of Linux kernel - Xilinx Zynq ARM architecture Microblaze U-BOOT custodian and responsible for u-boot arm zynq platform
Quoted 36 lines · Greg Kroah-Hartman
Quoted 25 lines · H. Peter Anvin
Quoted 16 lines · Michal Simek
If you look at it in general I believe that there is wide range of applications which just contain one bitstream per fpga and the bitstream is replaced by newer version in upgrade. For them firmware interface should be pretty useful. Just setup firmware name with bitstream and it will be automatically loaded in startup phase.
Then there is another set of applications especially in connection to partial reconfiguration where this can be done statically by pregenerated partial bitstreams or automatically generated on target cpu. For doing everything on the target firmware interface is not the best because everything can be handled by user application and it is easier just to push this bitstream to do device and not to save it to the fs.
Quoted 7 lines
I think the question here is if this subsystem could have several interfaces. For example Alan is asking for adding char support. Does it even make sense to have more interfaces with the same backend driver? When this is answered then we can talk which one make sense to have. In v2 is sysfs and firmware one. Adding char is also easy to do.
Quoted 5 lines
Greg, what do you think?
I agree that the firmware interface makes sense when the use of the FPGA is an implementation detail in a fixed hardware configuration, but that is a fairly restricted use case all things considered.
Ideally I thought this would be just like "firmware", you dump the file to the FPGA, it validates it and away you go with a new image running in the chip.
Quoted 7 lines
But, it sounds like this is much more complicated, so much so that configfs might be the correct interface for it, as you can do lots of things there, and it is very flexible (some say too flexible...)
A char device, with a zillion different custom ioctls is also a way to do it, but one that I really want to avoid as that gets messy really quickly.
Hi Greg,
We are discussing a char device that has very few interfaces:
- a way of writing the image to fpga
- a way of getting fpga manager status
- a way of setting fpga manager state
This all looks like standard char driver interface to me. Writing the image could be writing to the devnode (cat image.bin > /dev/fpga0). The status stuff would be sysfs attributes. All normal stuff any char driver in the kernel would do. Why not just go with that?
Quoted 5 lines
thanks,
greg k-h
Quoted 52 lines · Alan Tull
Quoted 36 lines · Greg Kroah-Hartman
Quoted 25 lines · H. Peter Anvin
Quoted 16 lines · Michal Simek
If you look at it in general I believe that there is wide range of applications which just contain one bitstream per fpga and the bitstream is replaced by newer version in upgrade. For them firmware interface should be pretty useful. Just setup firmware name with bitstream and it will be automatically loaded in startup phase.
Then there is another set of applications especially in connection to partial reconfiguration where this can be done statically by pregenerated partial bitstreams or automatically generated on target cpu. For doing everything on the target firmware interface is not the best because everything can be handled by user application and it is easier just to push this bitstream to do device and not to save it to the fs.
Quoted 7 lines
I think the question here is if this subsystem could have several interfaces. For example Alan is asking for adding char support. Does it even make sense to have more interfaces with the same backend driver? When this is answered then we can talk which one make sense to have. In v2 is sysfs and firmware one. Adding char is also easy to do.
Quoted 5 lines
Greg, what do you think?
I agree that the firmware interface makes sense when the use of the FPGA is an implementation detail in a fixed hardware configuration, but that is a fairly restricted use case all things considered.
Ideally I thought this would be just like "firmware", you dump the file to the FPGA, it validates it and away you go with a new image running in the chip.
Quoted 7 lines
But, it sounds like this is much more complicated, so much so that configfs might be the correct interface for it, as you can do lots of things there, and it is very flexible (some say too flexible...)
A char device, with a zillion different custom ioctls is also a way to do it, but one that I really want to avoid as that gets messy really quickly.
Hi Greg,
We are discussing a char device that has very few interfaces:
- a way of writing the image to fpga
- a way of getting fpga manager status
- a way of setting fpga manager state
Quoted 4 lines
This all looks like standard char driver interface to me. Writing the image could be writing to the devnode (cat image.bin >
/dev/fpga0). The status stuff would be sysfs attributes. All normal stuff any char driver in the kernel would do. Why not just go with that?
Because we really hate to add new ioctls to the kernel if at all possible. Using sysfs (and it's one-value-per-file rule), makes userspace tools easier, and managing the different devices in the system easier (you know _exactly_ which device you are talking to, you don't have to guess based on minor number).
thanks,
greg k-h
Quoted 53 lines · Greg Kroah-Hartman
Quoted 52 lines · Alan Tull
Quoted 36 lines · Greg Kroah-Hartman
Quoted 25 lines · H. Peter Anvin
Quoted 16 lines · Michal Simek
If you look at it in general I believe that there is wide range of applications which just contain one bitstream per fpga and the bitstream is replaced by newer version in upgrade. For them firmware interface should be pretty useful. Just setup firmware name with bitstream and it will be automatically loaded in startup phase.
Then there is another set of applications especially in connection to partial reconfiguration where this can be done statically by pregenerated partial bitstreams or automatically generated on target cpu. For doing everything on the target firmware interface is not the best because everything can be handled by user application and it is easier just to push this bitstream to do device and not to save it to the fs.
Quoted 7 lines
I think the question here is if this subsystem could have several interfaces. For example Alan is asking for adding char support. Does it even make sense to have more interfaces with the same backend driver? When this is answered then we can talk which one make sense to have. In v2 is sysfs and firmware one. Adding char is also easy to do.
Quoted 5 lines
Greg, what do you think?
I agree that the firmware interface makes sense when the use of the FPGA is an implementation detail in a fixed hardware configuration, but that is a fairly restricted use case all things considered.
Ideally I thought this would be just like "firmware", you dump the file to the FPGA, it validates it and away you go with a new image running in the chip.
Quoted 7 lines
But, it sounds like this is much more complicated, so much so that configfs might be the correct interface for it, as you can do lots of things there, and it is very flexible (some say too flexible...)
A char device, with a zillion different custom ioctls is also a way to do it, but one that I really want to avoid as that gets messy really quickly.
Hi Greg,
We are discussing a char device that has very few interfaces:
- a way of writing the image to fpga
- a way of getting fpga manager status
- a way of setting fpga manager state
Quoted 7 lines
Quoted 4 lines
This all looks like standard char driver interface to me. Writing the image could be writing to the devnode (cat image.bin >
/dev/fpga0). The status stuff would be sysfs attributes. All normal stuff any char driver in the kernel would do. Why not just go with that?Because we really hate to add new ioctls to the kernel if at all possible.
I don't see any need for adding any ioctls.
Quoted 4 lines
Using sysfs (and it's one-value-per-file rule), makes userspace tools easier, and managing the different devices in the system easier (you know _exactly_ which device you are talking to, you don't have to guess based on minor number).
That's cool. The interface we could use is writing the raw fpga data to /sys/class/fpga_manager/fpga0/fpga_config_data
Reading or setting the fpga state could be from/sys/class/fpga_manager/fpga0/fpga_config_state
Or do I misunderstand? Do you include sysfs attributes when you are talking about ioctls?
Alan
Quoted 9 lines
thanks,
greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 70 lines · delicious quinoa
Quoted 53 lines · Greg Kroah-Hartman
Quoted 52 lines · Alan Tull
Quoted 36 lines · Greg Kroah-Hartman
Quoted 25 lines · H. Peter Anvin
Quoted 16 lines · Michal Simek
If you look at it in general I believe that there is wide range of applications which just contain one bitstream per fpga and the bitstream is replaced by newer version in upgrade. For them firmware interface should be pretty useful. Just setup firmware name with bitstream and it will be automatically loaded in startup phase.
Then there is another set of applications especially in connection to partial reconfiguration where this can be done statically by pregenerated partial bitstreams or automatically generated on target cpu. For doing everything on the target firmware interface is not the best because everything can be handled by user application and it is easier just to push this bitstream to do device and not to save it to the fs.
Quoted 7 lines
I think the question here is if this subsystem could have several interfaces. For example Alan is asking for adding char support. Does it even make sense to have more interfaces with the same backend driver? When this is answered then we can talk which one make sense to have. In v2 is sysfs and firmware one. Adding char is also easy to do.
Quoted 5 lines
Greg, what do you think?
I agree that the firmware interface makes sense when the use of the FPGA is an implementation detail in a fixed hardware configuration, but that is a fairly restricted use case all things considered.
Ideally I thought this would be just like "firmware", you dump the file to the FPGA, it validates it and away you go with a new image running in the chip.
Quoted 7 lines
But, it sounds like this is much more complicated, so much so that configfs might be the correct interface for it, as you can do lots of things there, and it is very flexible (some say too flexible...)
A char device, with a zillion different custom ioctls is also a way to do it, but one that I really want to avoid as that gets messy really quickly.
Hi Greg,
We are discussing a char device that has very few interfaces:
- a way of writing the image to fpga
- a way of getting fpga manager status
- a way of setting fpga manager stateQuoted 7 lines
Quoted 4 lines
This all looks like standard char driver interface to me. Writing the image could be writing to the devnode (cat image.bin >
/dev/fpga0). The status stuff would be sysfs attributes. All normal stuff any char driver in the kernel would do. Why not just go with that?Because we really hate to add new ioctls to the kernel if at all possible.
I don't see any need for adding any ioctls.
Quoted 4 lines
Using sysfs (and it's one-value-per-file rule), makes userspace tools easier, and managing the different devices in the system easier (you know _exactly_ which device you are talking to, you don't have to guess based on minor number).
Quoted 5 lines
That's cool. The interface we could use is writing the raw fpga data to
/sys/class/fpga_manager/fpga0/fpga_config_dataReading or setting the fpga state could be from
/sys/class/fpga_manager/fpga0/fpga_config_state
Ok, that's fine, I don't object to that, but you are giving up the notification and loading ability of the kernel for the image files by doing this, which will require you to use/write/maintain userspace tools. If you use the firmware interface, no userspace tool is needed at all, which I can see some people really wanting, right?
Quoted 2 lines
Or do I misunderstand? Do you include sysfs attributes when you are talking about ioctls?
You can't do ioctls on sysfs files, so no.
greg k-h
Quoted 34 lines · Michal Simek
Quoted 13 lines · H. Peter Anvin
Quoted 11 lines · Michal Simek
Quoted 7 lines · H. Peter Anvin
Yes; I never got too corner Greg ;)
Quoted 4 lines · Greg Kroah-Hartman
Quoted 1 line · Michal Simek
But anyway what was resolution from that meeting?
It never happened, we got distracted by lunch :)
Then why not to have it here?
Quoted 6 lines
The essential question is if the firmware interface really is appropriate for FPGAs. It definitely has a feel of a "square peg in a round hole", especially when you consider the myriad ways FPGAs can be configured (some persistent, some not, some which takes effect now, some which come later, some which involve bytecode interpreters...) and considering reconfiguration and partial reconfiguration.
If you look at it in general I believe that there is wide range
of applications which just contain one bitstream per fpga and the bitstream is replaced by newer version in upgrade. For them firmware interface should be pretty useful. Just setup firmware name with bitstream and it will be automatically loaded in startup phase.Then there is another set of applications especially in connection to partial reconfiguration where this can be done statically by pregenerated partial bitstreams
or automatically generated on target cpu. For doing everything on the target firmware interface is not the best because everything can be handled by user application and it is easier just to push this bitstream to do device and not to save it to the fs.
Quoted 3 lines
I think the question here is if this subsystem could have several interfaces. For example Alan is asking for adding char support.
Does it even make sense to have more interfaces with the same backend driver?
Just for clarification, I'm asking for just one way to write the fpga image data, not two or three.
I like being able to directly write the fpga image buffer from userspace; that will support the superset of use cases. v2 accepts the binary image data from a sysfs attribute (cat image.bin
Quoted 1 line
/sys/class/fpga_manager/fpga0/fpga_config_data). My original fpga
manager framework allowed writing the image data to the device node (cat image.bin > /dev/fpga0) rather than sysfs. My point is that it that if you are writing data, that goes to the file ops, not to sysfs attributes. sysfs is for text communication (Documentation/sysfs.txt:
"Attributes should be ASCII text files...")
Quoted 2 lines
When this is answered then we can talk which one make sense to have. In v2 is sysfs and firmware one. Adding char is also easy to do.
Please, not three ways to do the same thing. If you change from having the fpga_config_data attribute to having a file_operations' write, that would be what I think is more standard for char drivers in the kernel, if I'm not mistaken.
Quoted 4 lines
Thanks,
Michal
Quoted 11 lines · Michal Simek
Through firmware interface:
cat/sys/class/fpga_manager/fpga0/name
echo -n fpga.bin >/sys/class/fpga_manager/fpga0/firmwareThrough sysfs bin file:
cat/sys/class/fpga_manager/fpga0/fpga_config_state
echo -nwrite_init>/sys/class/fpga_manager/fpga0/fpga_config_statecat/lib/firmware/fpga.bin>/sys/class/fpga_manager/fpga0/fpga_config_dataecho -nwrite_complete>/sys/class/fpga_manager/fpga0/fpga_config_state
Hi Michal,
I have v2 working for me with Altera socfpga and had some feedback.
Add me and Dinh as maintainers.
This driver now has two interfaces for programming the image. I don't think things in the kernel usually have multiple interfaces.
Does the fpga community in general find that the firmware class is suitable for all our use cases? I think it only supports the most simple use cases.
My original fpga framework that you started with supported writing the fpga device through the devnode, i.e.
cat fpga.bin > /dev/fpga0
I think we should get back to that basic char driver interface like that. It seems like if you have a char driver, you would open and write to the devnode instead of adding an attribute under /sys.
The 'flags' implementation is a nice way to do some locking. But it doesn't replace the status op to get fpga manager status which vanished in v2. So please add that back. Its interface was that catting the 'status' attribute got a status description from the low level driver such as 'power up phase' or 'reset phase'. Too useful to just get rid of.
Alan
Quoted 66 lines
Subsystem supports working with phandles for cases where you want to load bitstreams for particular device through defined device.
For example:mngr@0 { compatible = "whatever"; fpga-mgr = <&ps7_dev_cfg_0>; ... } ;With these lines you can get easily load bitstream to the device.
struct
fpga_manager*mgr;
mgr =of_find_fpga_mgr_by_phandle(pdev->dev.of_node, "fpga-mgr"); if (mgr)mgr->fpga_firmware_write(mgr, "filename");NOTE: I have added there
of_find_fpga_mgr_by_node()andof_find_fpga_mgr_by_phandle()but maybe they should be added separately todrivers/of/of_fpga.c.Alessandro: I haven't looked at your FMC cases but maybe this could be also worth for your cases.
TODO:
- Probably make sense to create doc in Documentation folder too.
- When interface is fine also send zynq devcfg driver
- Properly test reading (we have problem with zynq devcfg driver now)
- Not sure if firmware interface also provide option to create files from kernel space.Thanks for your comments,
MichalChanges in v2:
- Remove ! from all error message not to be shouty
- Fix error codes
- Add sysfs-class-fpga description
- Use read/write helper functions with bit protection
- s/fpga_mgr_status_show/fpga_mgr_status_read/g
- Do not all end driver status just show core status
- Extract firmware support to specific sysfs firmware file
- Add support for sysfs bin attributes (fpga_config_state,fpga_config_data)
- Allocate space for name dynamically
- Introduce new flags bits (INIT_DONE, READ, WRITE)Michal Simek (1):
fpga: Introduce new fpga subsystemDocumentation/ABI/testing/sysfs-class-fpga | 33 ++ MAINTAINERS | 7 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/fpga/Kconfig | 18 + drivers/fpga/Makefile | 5 + drivers/fpga/fpga-mgr.c | 753 +++++++++++++++++++++++++++++ include/linux/fpga.h | 110 +++++ 8 files changed, 929 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-fpga create mode 100644 drivers/fpga/Kconfig create mode 100644 drivers/fpga/Makefile create mode 100644 drivers/fpga/fpga-mgr.c create mode 100644 include/linux/fpga.h--
1.8.2.3
Hi,
Quoted 14 lines · Alan Tull
Quoted 11 lines · Michal Simek
Through firmware interface:
cat/sys/class/fpga_manager/fpga0/name
echo -n fpga.bin >/sys/class/fpga_manager/fpga0/firmwareThrough sysfs bin file:
cat/sys/class/fpga_manager/fpga0/fpga_config_state
echo -nwrite_init>/sys/class/fpga_manager/fpga0/fpga_config_statecat/lib/firmware/fpga.bin>/sys/class/fpga_manager/fpga0/fpga_config_dataecho -nwrite_complete>/sys/class/fpga_manager/fpga0/fpga_config_state
Quoted 5 lines
Hi Michal,
I have v2 working for me with Altera socfpga and had some feedback.
Add me and Dinh as maintainers.
why not just one? What about you?
Quoted 3 lines
This driver now has two interfaces for programming the image. I don't think things in the kernel usually have multiple interfaces.
The question here is if this is a problem. i2c create char devices and also provide sysfs access too. It is done through notification.
Quoted 3 lines
Does the fpga community in general find that the firmware class is suitable for all our use cases? I think it only supports the most simple use cases.
Let's continue with this on that second thread and we will see what happen.
Quoted 6 lines
My original fpga framework that you started with supported writing the fpga device through the devnode, i.e.
cat fpga.bin >/dev/fpga0
I think we should get back to that basic char driver interface like that. It seems like if you have a char driver, you would open and write to the devnode instead of adding an attribute under /sys.
It is the same as above. As you know we can simple add support for char device with the current set of functions without changing logic in the driver.
Quoted 6 lines
The 'flags' implementation is a nice way to do some locking. But it doesn't replace the status op to get fpga manager status which vanished in v2. So please add that back. Its interface was that catting the 'status' attribute got a status description from the low level driver such as 'power up phase' or 'reset phase'. Too useful to just get rid of.
No problem to add it back but it means that core will loose control about values which can be returned back to the user. It is probably better to create set of return values.
Thanks,
Michal
Signature · 5 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91 w: www.monstr.eu p: +42-0-721842854 Maintainer of Linux kernel - Microblaze cpu - http://www.monstr.eu/fdt/ Maintainer of Linux kernel - Xilinx Zynq ARM architecture Microblaze U-BOOT custodian and responsible for u-boot arm zynq platform
Quoted 17 lines · Michal Simek
Hi,
Quoted 14 lines · Alan Tull
Quoted 11 lines · Michal Simek
Through firmware interface:
cat/sys/class/fpga_manager/fpga0/name
echo -n fpga.bin >/sys/class/fpga_manager/fpga0/firmwareThrough sysfs bin file:
cat/sys/class/fpga_manager/fpga0/fpga_config_state
echo -nwrite_init>/sys/class/fpga_manager/fpga0/fpga_config_statecat/lib/firmware/fpga.bin>/sys/class/fpga_manager/fpga0/fpga_config_dataecho -nwrite_complete>/sys/class/fpga_manager/fpga0/fpga_config_state
Quoted 7 lines
Quoted 5 lines
Hi Michal,
I have v2 working for me with Altera socfpga and had some feedback.
Add me and Dinh as maintainers.
why not just one? What about you?
That's fine. Just add "Alan Tull <[email protected]>" So we can expect that in v3, right?
Quoted 6 lines
Quoted 3 lines
This driver now has two interfaces for programming the image. I don't think things in the kernel usually have multiple interfaces.
The question here is if this is a problem. i2c create char devices and also provide sysfs access too. It is done through notification.
i2c_master_send() is called as the fops write or from an i2c client, but not by writing data to some attribute under sysfs. So there aren't two direct paths from userspace to the i2c core. I am advocating against multiple ways for userspace to request/send fpga images for programming.
Quoted 6 lines
Quoted 4 lines
Does the fpga community in general find that the firmware class is suitable for all our use cases? I think it only supports the most simple use cases.
Let's continue with this on that second thread and we will see what happen.
Yes, let's continue this particular discussion on the other thread.
Quoted 26 lines
Quoted 8 lines
My original fpga framework that you started with supported writing the fpga device through the devnode, i.e.
cat fpga.bin >/dev/fpga0
I think we should get back to that basic char driver interface like that. It seems like if you have a char driver, you would open and write to the devnode instead of adding an attribute under /sys.It is the same as above. As you know we can simple add support for char device with the current set of functions without changing logic in the driver.
Quoted 6 lines
The 'flags' implementation is a nice way to do some locking. But it doesn't replace the status op to get fpga manager status which vanished in v2. So please add that back. Its interface was that catting the 'status' attribute got a status description from the low level driver such as 'power up phase' or 'reset phase'. Too useful to just get rid of.
No problem to add it back but it means that core will loose control about values which can be returned back to the user. It is probably better to create set of return values.
Thanks,
Michal