Skip to contentSkip to conversation

Yet another stab at a fpga framework

RFC PATCH In review Alan Tull 2 participants 7 messages Jul 31, 2014 – Aug 12, 2014 FPGA manager framework

lore
Share & tools
lore

Alan Tull

author
#0 lore raw

cover Yet another stab at a fpga framework

The function of the framework is to provide consistent ways of programming raw images into FPGA's.

The core (fpga-mgr.c) does not include a userspace interface and just exports kernel functions.

This approach separates the core from the interfaces.

Each interface can be enabled or disabled in the defconfig.

Programming from device tree overlays is supported.

The core exports kernel functions to:
* write the fpga from a buffer or using the firmware layer
* get fpga status
* find a particular fpga manager from a device tree phandle
* register/unregister lower level fpga drivers.

The bus allows us to:
* program fpga from a device tree overlay using firmware.
* automatically reload firmware and reprogram fpga during resume.

The sysfs interface:
* read only, get the name and status of fpga manager.

I have a configfs interface patch which I haven't included, adds configfs as a separate file.

TODO:
* Enable bridges after fpga programming, disable during suspend

Examples are provided in the headers of the patches.

Alan Tull

Alan Tull (3):
fpga manager framework core
fpga bus driver
fpga sysfs interface

 drivers/Kconfig          |    2 +
 drivers/Makefile         |    1 +
 drivers/fpga/Kconfig     |   27 +++
 drivers/fpga/Makefile    |   12 ++
 drivers/fpga/bus.c       |  139 +++++++++++++++
 drivers/fpga/fpga-mgr.c  |  431 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/fpga/sysfs.c     |   68 ++++++++
 include/linux/fpga-mgr.h |  137 +++++++++++++++
 8 files changed, 817 insertions(+)
 create mode 100644 drivers/fpga/Kconfig
 create mode 100644 drivers/fpga/Makefile
 create mode 100644 drivers/fpga/bus.c
 create mode 100644 drivers/fpga/fpga-mgr.c
 create mode 100644 drivers/fpga/sysfs.c
 create mode 100644 include/linux/fpga-mgr.h
Signature · 1 line
1.7.9.5
author
#1 lore raw

RFC PATCH 1/3 fpga manager framework core

This core exports methods of doing operations on FPGAs.

EXPORT_SYMBOL_GPL(fpga_mgr_write);
Write FPGA given a buffer and count.

EXPORT_SYMBOL_GPL(fpga_mgr_firmware_write);
Request firmware and write that to a fpga

EXPORT_SYMBOL_GPL(fpga_mgr_status_get);
Get a status string, including failure information

EXPORT_SYMBOL_GPL(fpga_mgr_name);
Get name of FPGA manager

EXPORT_SYMBOL_GPL(register_fpga_manager);
EXPORT_SYMBOL_GPL(remove_fpga_manager);
Register/unregister low level fpga driver

All userspace interfaces are in separate files so that they can be compiled out on production builds where appropriate.

---
 drivers/Kconfig          |    2 +
 drivers/Makefile         |    1 +
 drivers/fpga/Kconfig     |   13 ++
 drivers/fpga/Makefile    |   10 ++
 drivers/fpga/fpga-mgr.c  |  403 ++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/fpga-mgr.h |  121 ++++++++++++++
 6 files changed, 550 insertions(+)
 create mode 100644 drivers/fpga/Kconfig
 create mode 100644 drivers/fpga/Makefile
 create mode 100644 drivers/fpga/fpga-mgr.c
 create mode 100644 include/linux/fpga-mgr.h
drivers/Kconfig +2 -0
index 0e87a34..b0cbbae 100644
@@ -34,6 +34,8 @@ source "drivers/message/fusion/Kconfig"
 
 source "drivers/firewire/Kconfig"
 
+source "drivers/fpga/Kconfig"
+
 source "drivers/message/i2o/Kconfig"
 
 source "drivers/macintosh/Kconfig"
drivers/Makefile +1 -0
index f98b50d..afdd2aa 100644
@@ -49,6 +49,7 @@ obj-$(CONFIG_RESET_CONTROLLER)	+= reset/
 # default.
 obj-y				+= tty/
 obj-y				+= char/
+obj-$(CONFIG_FPGA)		+= fpga/
 
 # gpu/ comes after char for AGP vs DRM startup
 obj-y				+= gpu/
drivers/fpga/Kconfig new file +13 -0
new file mode 100644
index 0000000..49293a3
@@ -0,0 +1,13 @@
+#
+# 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.
+endmenu
drivers/fpga/Makefile new file +10 -0
new file mode 100644
index 0000000..c8a676f
@@ -0,0 +1,10 @@
+#
+# Makefile for the fpga framework and fpga manager drivers.
+#
+
+fpga-mgr-core-y += fpga-mgr.o
+
+# Core FPGA Manager Framework
+obj-$(CONFIG_FPGA)			+= fpga-mgr-core.o
+
+# FPGA Manager Drivers
drivers/fpga/fpga-mgr.c new file +403 -0

403 lines not on this page · raw message

include/linux/fpga-mgr.h new file +121 -0

121 lines not on this page · raw message

Signature · 1 line
1.7.9.5
author
#5 lore raw

RFC PATCH 2/3 fpga bus driver

In reply to Alan Tull

This driver allows programming the fpga from device tree overlays.

This code is dependent on Pantelis Antoniou's current work on Device Tree overlays, a method of dynamically altering the kerel's live Device Tree. This patchset was tested with Pantelis's and Grant Likely's stuff that is in git plus some dtc fixups for compiling overlays.

Resume is handled by re-requesting the firmware and reprogramming the FPGA.

Here's a simple example. Start with:
* the altera-gpio driver built in to the kernel but not in the device tree.
* raw fpga image at /lib/firmware/soc_system.rbf
* Load appropriate device tree overlay in configfs by doing

    $ mkdir /config/device-tree/overlays/1
    $ echo socfpga_overlay.dtbo > /config/device-tree/overlays/1/path
  * This results in the FPGA getting programmed and the altera
    gpio driver getting probed.

TODO:
* Add ability to take fpga/cpu bridges out of reset.

Device tree overlay looks like this:
/dts-v1/;
/plugin/;

/ {
	fragment@0 {
		target-path="/soc";
		__overlay__ {
			#address-cells = <1>;
	                #size-cells = <1>;

			bridge@0xff200000 {
				compatible = "fpga-mgr-bus", "simple-bus";
				reg = <0xff200000 0x200000>;
				clocks = <0x2 0x2>;
				clock-names = "h2f_lw_axi_clock", "f2h_sdram0_clock";
				#address-cells = <0x2>;
				#size-cells = <0x1>;
				ranges = <0x1 0x10040 0xff210040 0x20>;

				fpgamgr = <&hps_0_fpgamgr>;
				fpga-firmware = "soc_system.rbf";

				gpio@0x100010040 {
					compatible = "altr,pio-14.0", "altr,pio-1.0";
					reg = <0x1 0x10040 0x20>;
					clocks = <0x2>;
					altr,gpio-bank-width = <0x4>;
					resetvalue = <0x0>;
					#gpio-cells = <0x2>;
					gpio-controller;
					linux,phandle = <0x2d>;
				};
			};
		};
	};
};

This patch adds one exported function to the core (fpga-mgr.c):

EXPORT_SYMBOL_GPL(of_fpga_mgr_dev_lookup);
Get pointer to fpga manager struct given a phandle.

---
 drivers/fpga/Kconfig     |    7 +++
 drivers/fpga/Makefile    |    1 +
 drivers/fpga/bus.c       |  139 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/fpga/fpga-mgr.c  |   28 +++++++++-
 include/linux/fpga-mgr.h |    4 ++
 5 files changed, 178 insertions(+), 1 deletion(-)
 create mode 100644 drivers/fpga/bus.c
drivers/fpga/Kconfig +7 -0
index 49293a3..9a2c25b 100644
@@ -10,4 +10,11 @@ config FPGA
 	  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.
+
+config FPGA_MGR_BUS
+	bool "FPGA Manager Bus"
+	depends on FPGA
+	help
+	  FPGA Manager Bus interface.  Allows loading FPGA images
+	  from Device Tree or from other drivers.
 endmenu
drivers/fpga/Makefile +1 -0
index c8a676f..e39911f 100644
@@ -6,5 +6,6 @@ fpga-mgr-core-y += fpga-mgr.o
 
 # Core FPGA Manager Framework
 obj-$(CONFIG_FPGA)			+= fpga-mgr-core.o
+obj-$(CONFIG_FPGA_MGR_BUS)		+= bus.o
 
 # FPGA Manager Drivers
drivers/fpga/bus.c new file +139 -0

139 lines not on this page · raw message

drivers/fpga/fpga-mgr.c +27 -1
index 0e2eba4..32888d6 100644
@@ -26,6 +26,7 @@
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/of_irq.h>
 #include <linux/pm.h>
 #include <linux/slab.h>
 #include <linux/uaccess.h>
@@ -228,6 +229,31 @@ static int fpga_mgr_ops_framework_status(struct fpga_manager *mgr, char *buf)
 	return ret;
 }
 
+/* Find the fpga manager that is pointed to by a phandle */
+struct fpga_manager *of_fpga_mgr_dev_lookup(struct device_node *node,
+					    const char *mgr_property,
+					    int *ret)
+{
+	struct fpga_manager *mgr;
+	struct device_node *mgr_node;
+
+	mgr_node = of_parse_phandle(node, mgr_property, 0);
+
+	if (!mgr_node) {
+		*ret = -ENODEV;
+		return NULL;
+	}
+
+	list_for_each_entry(mgr, &fpga_manager_list, list)
+		if (mgr_node == mgr->np)
+			return mgr;
+
+	*ret = -EPROBE_DEFER;
+
+	return NULL;
+}
+EXPORT_SYMBOL_GPL(of_fpga_mgr_dev_lookup);
+
 static int fpga_mgr_suspend(struct device *dev)
 {
 	struct fpga_manager *mgr = dev_get_drvdata(dev);
@@ -395,7 +421,7 @@ static void __exit fpga_mgr_dev_exit(void)
 	ida_destroy(&fpga_mgr_ida);
 }
 
-MODULE_AUTHOR("Alan Tull <[email protected]>");
+MODULE_AUTHOR("Alan Tull <[email protected]>");
 MODULE_DESCRIPTION("FPGA Manager framework driver");
 MODULE_LICENSE("GPL v2");
 
include/linux/fpga-mgr.h +4 -0
index 6af0873..35d3380 100644
@@ -105,6 +105,10 @@ struct fpga_manager {
 
 #if IS_ENABLED(CONFIG_FPGA)
 
+struct fpga_manager *of_fpga_mgr_dev_lookup(struct device_node *node,
+					    const char *mgr_property,
+					    int *ret);
+
 int fpga_mgr_firmware_write(struct fpga_manager *mgr, const char *path);
 int fpga_mgr_write(struct fpga_manager *mgr, const char *buf, size_t count);
 int fpga_mgr_status_get(struct fpga_manager *mgr, char *buf);
Signature · 1 line
1.7.9.5
author
#6 lore raw

RFC PATCH 3/3 fpga sysfs interface

In reply to Alan Tull

Add basic sysfs interface. Only exports two files:

/sys/class/fpga_manager/fpga0/name
Name of low level driver.

/sys/class/fpga_manager/fpga0/status
status of fpga framework as returned by core
fpga-mgr.c's fpga_mgr_ops_framework_status
function or by the low level driver's status
function.

---
 drivers/fpga/Kconfig     |    7 +++++
 drivers/fpga/Makefile    |    1 +
 drivers/fpga/fpga-mgr.c  |    2 ++
 drivers/fpga/sysfs.c     |   68 ++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/fpga-mgr.h |   12 ++++++++
 5 files changed, 90 insertions(+)
 create mode 100644 drivers/fpga/sysfs.c
drivers/fpga/Kconfig +7 -0
index 9a2c25b..113b8b4 100644
@@ -17,4 +17,11 @@ config FPGA_MGR_BUS
 	help
 	  FPGA Manager Bus interface.  Allows loading FPGA images
 	  from Device Tree or from other drivers.
+
+config FPGA_MGR_SYSFS
+	bool "FPGA Manager SysFS Interface"
+	depends on FPGA
+	depends on SYSFS
+	help
+	  FPGA Manager SysFS interface.
 endmenu
drivers/fpga/Makefile +1 -0
index e39911f..cad3d8c 100644
@@ -7,5 +7,6 @@ fpga-mgr-core-y += fpga-mgr.o
 # Core FPGA Manager Framework
 obj-$(CONFIG_FPGA)			+= fpga-mgr-core.o
 obj-$(CONFIG_FPGA_MGR_BUS)		+= bus.o
+obj-$(CONFIG_FPGA_MGR_SYSFS)		+= sysfs.o
 
 # FPGA Manager Drivers
drivers/fpga/fpga-mgr.c +2 -0
index 32888d6..e5d1a09 100644
@@ -402,6 +402,8 @@ static int __init fpga_mgr_dev_init(void)
 	if (IS_ERR(fpga_mgr_class))
 		return PTR_ERR(fpga_mgr_class);
 
+	fpga_mgr_sysfs_init(fpga_mgr_class);
+
 	ret = alloc_chrdev_region(&fpga_mgr_dev, 0, FPGA_MAX_MINORS,
 				  "fpga_manager");
 	if (ret) {
drivers/fpga/sysfs.c new file +68 -0

68 lines not on this page · raw message

include/linux/fpga-mgr.h +12 -0
index 35d3380..86eeff5 100644
@@ -105,6 +105,18 @@ struct fpga_manager {
 
 #if IS_ENABLED(CONFIG_FPGA)
 
+#ifdef CONFIG_FPGA_MGR_SYSFS
+
+void fpga_mgr_sysfs_init(struct class *fpga_mgr_class);
+
+#else
+
+static inline void fpga_mgr_sysfs_init(struct class *fpga_mgr_class)
+{
+}
+
+#endif /* CONFIG_FPGA_MGR_SYSFS */
+
 struct fpga_manager *of_fpga_mgr_dev_lookup(struct device_node *node,
 					    const char *mgr_property,
 					    int *ret);
Signature · 1 line
1.7.9.5
#2 lore raw

Re: [RFC PATCH 1/3] fpga manager framework core

In reply to Alan Tull
Quoted 1 line · Alan Tull

This core exports methods of doing operations on FPGAs.

I'm sticking to some high-level comments for the moment...

Quoted 9 lines

EXPORT_SYMBOL_GPL(fpga_mgr_write);
Write FPGA given a buffer and count.

EXPORT_SYMBOL_GPL(fpga_mgr_firmware_write);
Request firmware and write that to a fpga

EXPORT_SYMBOL_GPL(fpga_mgr_status_get);
Get a status string, including failure information

Quoted 6 lines

EXPORT_SYMBOL_GPL(fpga_mgr_name);
Get name of FPGA manager

EXPORT_SYMBOL_GPL(register_fpga_manager);
EXPORT_SYMBOL_GPL(remove_fpga_manager);
Register/unregister low level fpga driver

I understand these 2 being for low-level drivers, but ...

Quoted 4 lines

All userspace interfaces are in separate files so that they can be compiled out on production builds where appropriate.

How do you envision the other functions to be used besides by userspace? Automatically loading bit files embedded in your DT?

Quoted 2 lines

[...]

Quoted 8 lines
drivers/fpga/fpga-mgr.c new file +8 -0
+const char *state_str[] = {
+       "default",
+       "firmware_request",
+       "write_init",
+       "write",
+       "write_complete",
+       "write_success",
+       "read_init",

drivers/fpga/fpga-mgr.c line 212

Quoted 10 lines
drivers/fpga/fpga-mgr.c new file +10 -0
+       "read",
+       "read_complete",
+       "read_done",
+};
+
+/*
+ * Provide status as: [state] [fail] [busy] such as
+ *  'firmware_request fail' = failed to load firmware image from filesystem
+ *  'write fail'            = failed while writing to FPGA
+ *  'write_success'         = after writing, low level driver returns success

I would combine the sysfs patch with this as they are clearly related.

You seem to mix state and status here. For example, "write_success fail" makes no sense. I think you are exposing to many low level details both to userspace and perhaps specific to Altera.

How is read used?

Rob

author
#3 lore raw

Re: [RFC PATCH 1/3] fpga manager framework core

Quoted 19 lines · Rob Herring
Quoted 1 line · Alan Tull

This core exports methods of doing operations on FPGAs.

I'm sticking to some high-level comments for the moment...

Quoted 9 lines

EXPORT_SYMBOL_GPL(fpga_mgr_write);
Write FPGA given a buffer and count.

EXPORT_SYMBOL_GPL(fpga_mgr_firmware_write);
Request firmware and write that to a fpga

EXPORT_SYMBOL_GPL(fpga_mgr_status_get);
Get a status string, including failure information

Quoted 6 lines

EXPORT_SYMBOL_GPL(fpga_mgr_name);
Get name of FPGA manager

EXPORT_SYMBOL_GPL(register_fpga_manager);
EXPORT_SYMBOL_GPL(remove_fpga_manager);
Register/unregister low level fpga driver

Quoted 7 lines

I understand these 2 being for low-level drivers, but ...

Quoted 3 lines

All userspace interfaces are in separate files so that they can be compiled out on production builds where appropriate.

How do you envision the other functions to be used besides by userspace?

fpga_mgr_firmware_write() can by used in a driver's probe function. Not much more complicated than the current firmware interface. It requires one other function - of_fpga_mgr_dev_lookup() which is in the third patch, should move it to the core patch probably. Eliminating the error checking, a driver probe could add this:

struct device_node *np = pdev->dev.of_node;

/* find the fpga pointed to by this driver's 'fpgamgr' device tree property */ struct fpga_manager *mgr = of_fpga_mgr_dev_lookup(np, "fpgamgr", &ret);

/* request the bitstream file from firmware layer and write it to fpga */ fpga_mgr_firmware_write(mgr, "driver-fpga-image.rbf");

/* then enable the fpga bridges */

Also these low level functions can be used by various interfaces that could put programming in userspace control. My two main points for this set of patches are: separating the kernel core stuff from the interface, and enabling DT control. So I want to have enough here that any higher level interface will have what it needs.

Quoted 1 line

Automatically loading bit files embedded in your DT?

Yes. There's an example device tree fragment in the third patch. Usually multiple soft ip blocks are included in a single fpga image, so the example in the third patch has the device drivers one level below the fpga manager bus (the example only shows one gpio driver). The fpga image will get loaded, then the drivers get probed due to Pantelis's dynamic DT code.

The fpga bus adds two DT properties: 'fpgamgr' and 'fpga-firmware' properties. The 'fpgamgr' property is the phandle for the fpga to load (so multiple fpgas are supported, but not hard coded anywhere). The 'fpga-firmware' property is the name of the firmware file to load.

The part I want to add to the next version is enabling bridges, which has to happen between loading the fpga image and probing the drivers.

Quoted 14 lines
Quoted 1 line

[...]

Quoted 11 lines
drivers/fpga/fpga-mgr.c new file +11 -0
+const char *state_str[] = {
+       "default",
+       "firmware_request",
+       "write_init",
+       "write",
+       "write_complete",
+       "write_success",
+       "read_init",
+       "read",
+       "read_complete",
+       "read_done",
Quoted 8 lines

drivers/fpga/fpga-mgr.c line 212

Quoted 7 lines
drivers/fpga/fpga-mgr.c new file +7 -0
+};
+
+/*
+ * Provide status as: [state] [fail] [busy] such as
+ *  'firmware_request fail' = failed to load firmware image from filesystem
+ *  'write fail'            = failed while writing to FPGA
+ *  'write_success'         = after writing, low level driver returns success

I would combine the sysfs patch with this as they are clearly related.

Yeah, this limited read-only sysfs could be merged to the core. There was some thinking behind having it separate that I want to be clear about.

Some users of the fpga manager need to have the load sequence tightly controlled by userspace. I want to have that type of interface as a separate C file and enabled by defconfig. That way people with really complicated use cases can have the interface that will suit them.

The use case I am most aware of can be pretty simple: ARM with a single tightly coupled FPGA. I don't want to make any initial decisions that get in the way of something that will work for PCI FPGAs or other use cases that are a lot more complicated. On the other hand, I don't want to saddle this with an interface that is driven by the most complicated scenario, especially when there could be production cases where the firmware can be loaded by the DT and won't need a lot of userspace interaction.

So this strategy is separating core, bus, and interface(s) that put the fpga manager under userspace control.

Quoted 2 lines

You seem to mix state and status here. For example, "write_success fail" makes no sense.

I could have state and status as two separate sysfs entries. The goal is to give enough useful information to know what what stage of things went wrong.

Quoted 2 lines

I think you are exposing to many low level details both to userspace and perhaps specific to Altera.

Hmm OK, will need to revisit that and keep it usable for everybody. I still am not adamantly opposed to having status be a string reported by the lower level driver. Although that can be more manufacturor-specific, that might make sense at that point since we want to know what (in this specific FPGA's write sequence) went wrong.

Quoted 1 line

How is read used?

Errr by the fpga_mgr_read function that I need to add.

Quoted 1 line

Rob

#4 lore raw

Re: [RFC PATCH 1/3] fpga manager framework core

Quoted 97 lines · Alan Tull
Quoted 19 lines · Rob Herring
Quoted 1 line · Alan Tull

This core exports methods of doing operations on FPGAs.

I'm sticking to some high-level comments for the moment...

Quoted 9 lines

EXPORT_SYMBOL_GPL(fpga_mgr_write);
Write FPGA given a buffer and count.

EXPORT_SYMBOL_GPL(fpga_mgr_firmware_write);
Request firmware and write that to a fpga

EXPORT_SYMBOL_GPL(fpga_mgr_status_get);
Get a status string, including failure information

Quoted 6 lines

EXPORT_SYMBOL_GPL(fpga_mgr_name);
Get name of FPGA manager

EXPORT_SYMBOL_GPL(register_fpga_manager);
EXPORT_SYMBOL_GPL(remove_fpga_manager);
Register/unregister low level fpga driver

Quoted 7 lines

I understand these 2 being for low-level drivers, but ...

Quoted 3 lines

All userspace interfaces are in separate files so that they can be compiled out on production builds where appropriate.

How do you envision the other functions to be used besides by userspace?

fpga_mgr_firmware_write() can by used in a driver's probe function. Not much more complicated than the current firmware interface. It requires one other function - of_fpga_mgr_dev_lookup() which is in the third patch, should move it to the core patch probably. Eliminating the error checking, a driver probe could add this:

struct device_node *np = pdev->dev.of_node;

/* find the fpga pointed to by this driver's 'fpgamgr' device tree property */ struct fpga_manager *mgr = of_fpga_mgr_dev_lookup(np, "fpgamgr", &ret);

/* request the bitstream file from firmware layer and write it to fpga */ fpga_mgr_firmware_write(mgr, "driver-fpga-image.rbf");

/* then enable the fpga bridges */

Also these low level functions can be used by various interfaces that could put programming in userspace control. My two main points for this set of patches are: separating the kernel core stuff from the interface, and enabling DT control. So I want to have enough here that any higher level interface will have what it needs.

Quoted 1 line

Automatically loading bit files embedded in your DT?

Yes. There's an example device tree fragment in the third patch. Usually multiple soft ip blocks are included in a single fpga image, so the example in the third patch has the device drivers one level below the fpga manager bus (the example only shows one gpio driver). The fpga image will get loaded, then the drivers get probed due to Pantelis's dynamic DT code.

The fpga bus adds two DT properties: 'fpgamgr' and 'fpga-firmware' properties. The 'fpgamgr' property is the phandle for the fpga to load (so multiple fpgas are supported, but not hard coded anywhere). The 'fpga-firmware' property is the name of the firmware file to load.

The part I want to add to the next version is enabling bridges, which has to happen between loading the fpga image and probing the drivers.

Quoted 14 lines
Quoted 1 line

[...]

Quoted 11 lines
drivers/fpga/fpga-mgr.c new file +11 -0
+const char *state_str[] = {
+       "default",
+       "firmware_request",
+       "write_init",
+       "write",
+       "write_complete",
+       "write_success",
+       "read_init",
+       "read",
+       "read_complete",
+       "read_done",
Quoted 8 lines

drivers/fpga/fpga-mgr.c line 212

Quoted 7 lines
drivers/fpga/fpga-mgr.c new file +7 -0
+};
+
+/*
+ * Provide status as: [state] [fail] [busy] such as
+ *  'firmware_request fail' = failed to load firmware image from filesystem
+ *  'write fail'            = failed while writing to FPGA
+ *  'write_success'         = after writing, low level driver returns success

I would combine the sysfs patch with this as they are clearly related.

Yeah, this limited read-only sysfs could be merged to the core. There was some thinking behind having it separate that I want to be clear about.

Some users of the fpga manager need to have the load sequence tightly controlled by userspace. I want to have that type of interface as a separate C file and enabled by defconfig. That way people with really complicated use cases can have the interface that will suit them.

The use case I am most aware of can be pretty simple: ARM with a single tightly coupled FPGA. I don't want to make any initial decisions that get in the way of something that will work for PCI FPGAs or other use cases that are a lot more complicated. On the other hand, I don't want to saddle this with an interface that is driven by the most complicated scenario, especially when there could be production cases where the firmware can be loaded by the DT and won't need a lot of userspace interaction.

So this strategy is separating core, bus, and interface(s) that put the fpga manager under userspace control.

Quoted 2 lines

You seem to mix state and status here. For example, "write_success fail" makes no sense.

I could have state and status as two separate sysfs entries. The goal is to give enough useful information to know what what stage of things went wrong.

Quoted 2 lines

I think you are exposing to many low level details both to userspace and perhaps specific to Altera.

Hmm OK, will need to revisit that and keep it usable for everybody. I still am not adamantly opposed to having status be a string reported by the lower level driver. Although that can be more manufacturor-specific, that might make sense at that point since we want to know what (in this specific FPGA's write sequence) went wrong.

Quoted 1 line

How is read used?

Errr by the fpga_mgr_read function that I need to add.

Quoted 1 line

Rob