Skip to contentSkip to conversation

Yet another stab at a fpga framework

PATCH In review [email protected] 5 participants 17 messages Aug 1, 2014 – Sep 8, 2014 FPGA manager framework

lore
Share & tools
lore
#0 lore raw

cover Yet another stab at a fpga framework

From: Alan Tull <[email protected]>

[resend with fixed email settings]

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

Programming from device tree overlays is supported.

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. In some production contexts, interfaces that might be used during development can be disabled.

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

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       |  145 ++++++++++++++++
 drivers/fpga/fpga-mgr.c  |  431 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/fpga/sysfs.c     |   69 ++++++++
 include/linux/fpga-mgr.h |  137 +++++++++++++++
 8 files changed, 824 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 · 6 lines
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw

PATCH 1/3 fpga manager framework core

From: Alan Tull <[email protected]>

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

TODO: Add interface to set FPGA in specific state such
as reset.

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
#8 lore raw

PATCH 2/3 fpga bus driver

In reply to [email protected]

From: Alan Tull <[email protected]>

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.
* To remove/clear FPGA image, remove device tree overlay by doing:

    $ rmdir /config/device-tree/overlays/1

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       |  145 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/fpga/fpga-mgr.c  |   26 +++++++++
 include/linux/fpga-mgr.h |    4 ++
 5 files changed, 183 insertions(+)
 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 +145 -0

145 lines not on this page · raw message

drivers/fpga/fpga-mgr.c +26 -0
index 0e2eba4..93327ea 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);
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 · 6 lines
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#12 lore raw

PATCH 3/3 fpga sysfs interface

In reply to [email protected]

From: Alan Tull <[email protected]>

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     |   69 ++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/fpga-mgr.h |   12 ++++++++
 5 files changed, 91 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 93327ea..a604de7 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 +69 -0

69 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: [PATCH 1/3] fpga manager framework core

In reply to [email protected]

Hi!

drivers/fpga/fpga-mgr.c line 161

Quoted 9 lines
drivers/fpga/fpga-mgr.c new file +9 -0
+static int fpga_mgr_get_new_minor(struct fpga_manager *mgr, int request_nr)
+{
+	int nr, start;
+
+	/* check specified minor number */
+	if (request_nr >= FPGA_MAX_MINORS) {
+		dev_err(mgr->parent, "Out of device minors (%d)\n", request_nr);
+		return -ENODEV;
+	}

if (request_nr < -1)
return -EINVAL;
?

include/linux/fpga-mgr.h line 67

Quoted 3 lines
include/linux/fpga-mgr.h new file +3 -0
+	/* FPGA mangager isr */
+	irqreturn_t (*isr)(int irq, void *dev_id);
+};

"manager"?

Best regards,
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#4 lore raw

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

In reply to [email protected]

Hi!

drivers/fpga/fpga-mgr.c line 173

Quoted 2 lines
drivers/fpga/fpga-mgr.c new file +2 -0
+	nr = ida_simple_get(&fpga_mgr_ida, start, FPGA_MAX_MINORS, GFP_KERNEL);
+

Actually, are you sure ida framework is a good idea here? AFAICT, you only use it to keep track of used minors.
pavel

Signature · 6 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#9 lore raw

Re: [PATCH 2/3] fpga bus driver

In reply to [email protected]

Hi!

Quoted 9 lines

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.

Nice!

drivers/fpga/fpga-mgr.c static int fpga_mgr_ops_framework_status(struct fpga_manager *mgr, char *buf) · line 244

Quoted 13 lines
drivers/fpga/fpga-mgr.c +13 -0
+/* 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;

Could IS_ERR_OR_NULL() and friends be used to get reasonable calling convention?

Thanks,
Pavel

Signature · 6 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#13 lore raw

Re: [PATCH 3/3] fpga sysfs interface

In reply to [email protected]
Quoted 4 lines · On Fri 2014-08-01 17:28:38, [email protected]…

From: Alan Tull <[email protected]>

Add basic sysfs interface. Only exports two files:

Quoted 8 lines

/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.

I believe sysfs additions need to be documented in Documentation/ABI/. Otherwise it looks good.

Thanks,
Pavel

Signature · 6 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#10 lore raw

Re: [PATCH 2/3] fpga bus driver

In reply to Pavel Machek
Quoted 13 lines · Pavel Machek

Hi!

Quoted 9 lines

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.
Quoted 1 line

Nice!

Thanks!

Quoted 16 lines
Quoted 4 lines
drivers/fpga/fpga-mgr.c +3 -0
+/* 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,

drivers/fpga/fpga-mgr.c static int fpga_mgr_ops_framework_status(struct fpga_manager *mgr, char *buf) · line 244

Quoted 10 lines
drivers/fpga/fpga-mgr.c +10 -0
+                                         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;

Could IS_ERR_OR_NULL() and friends be used to get reasonable calling

Yes, that would be much simpler here. I could get rid of the 'ret'.

Quoted 8 lines

convention?

Thanks,
Pavel

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

#3 lore raw

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

In reply to Pavel Machek
Quoted 16 lines · Pavel Machek

Hi!

drivers/fpga/fpga-mgr.c line 161

Quoted 9 lines
drivers/fpga/fpga-mgr.c new file +9 -0
+static int fpga_mgr_get_new_minor(struct fpga_manager *mgr, int request_nr)
+{
+     int nr, start;
+
+     /* check specified minor number */
+     if (request_nr >= FPGA_MAX_MINORS) {
+             dev_err(mgr->parent, "Out of device minors (%d)\n", request_nr);
+             return -ENODEV;
+     }

if (request_nr < -1)
return -EINVAL;
?

Quoted 8 lines

include/linux/fpga-mgr.h line 67

Quoted 3 lines
include/linux/fpga-mgr.h new file +3 -0
+     /* FPGA mangager isr */
+     irqreturn_t (*isr)(int irq, void *dev_id);
+};

"manager"?

Best regards,
Pavel

Thanks! Will fix these.

Alan

Quoted 4 lines

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

#14 lore raw
In reply to [email protected]

Hi Alan,

Quoted 51 lines · On Aug 2, 2014, at 1:28 AM, <[email protected]> wrote:

From: Alan Tull <[email protected]>

[resend with fixed email settings]

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

Programming from device tree overlays is supported.

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. In some production contexts, interfaces that might be used during development can be disabled.

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

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       |  145 ++++++++++++++++
drivers/fpga/fpga-mgr.c  |  431 ++++++++++++++++++++++++++++++++++++++++++++++
drivers/fpga/sysfs.c     |   69 ++++++++
include/linux/fpga-mgr.h |  137 +++++++++++++++
8 files changed, 824 insertions(+)
Quoted 7 lines

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

Looks very sane and useful. Please let me know if you come across any problems with the overlays code, especially the removal path.

Regards

-- Pantelis

#11 lore raw

Re: [PATCH 2/3] fpga bus driver

In reply to [email protected]

Hi Alan,

Quoted 15 lines · On Aug 2, 2014, at 1:28 AM, <[email protected]> wrote:

From: Alan Tull <[email protected]>

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.

Quoted 7 lines

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

FWIW, there's now an updated configfs interface. You can just

# cp socfpga_overlay.dtbo /config/device-tree/overlays/1/dtbo

That's namespace safe, if you care about those things.

Regards

-- Pantelis

#5 lore raw

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

In reply to Pavel Machek
Quoted 9 lines · Pavel Machek

Hi!

drivers/fpga/fpga-mgr.c line 173

Quoted 2 lines
drivers/fpga/fpga-mgr.c new file +2 -0
+     nr = ida_simple_get(&fpga_mgr_ida, start, FPGA_MAX_MINORS, GFP_KERNEL);
+

Actually, are you sure ida framework is a good idea here? AFAICT, you only use it to keep track of used minors.
pavel

Yes, the ida is to keep track of minors. I think that was the intent of introducing ida into the kernel (looking at git logs of idr.c). SImilar to idr, but uses less memory. I see some other frameworks using it for this purpose, such as the rtc class. I can change this if this is something the kernel wants to move away from. What issues are you seeing here and what would you suggest?

Alan Tull
aka
delcious.quinoa
aka
[email protected]

#6 lore raw

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

Quoted 11 lines · Alan Tull
Quoted 9 lines · Pavel Machek

Hi!

drivers/fpga/fpga-mgr.c line 173

Quoted 2 lines
drivers/fpga/fpga-mgr.c new file +2 -0
+     nr = ida_simple_get(&fpga_mgr_ida, start, FPGA_MAX_MINORS, GFP_KERNEL);
+

Actually, are you sure ida framework is a good idea here? AFAICT, you only use it to keep track of used minors.
pavel

Quoted 6 lines

Yes, the ida is to keep track of minors. I think that was the intent of introducing ida into the kernel (looking at git logs of idr.c). SImilar to idr, but uses less memory. I see some other frameworks using it for this purpose, such as the rtc class. I can change this if this is something the kernel wants to move away from. What issues are you seeing here and what would you suggest?

Well, it looked to me like a job for bitfield, since we don't plan that many minors...

Pavel

#7 lore raw

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

Quoted 19 lines · Pavel Machek
Quoted 11 lines · Alan Tull
Quoted 9 lines · Pavel Machek

Hi!

drivers/fpga/fpga-mgr.c line 173

Quoted 2 lines
drivers/fpga/fpga-mgr.c new file +2 -0
+     nr = ida_simple_get(&fpga_mgr_ida, start, FPGA_MAX_MINORS, GFP_KERNEL);
+

Actually, are you sure ida framework is a good idea here? AFAICT, you only use it to keep track of used minors.
pavel

Quoted 6 lines

Yes, the ida is to keep track of minors. I think that was the intent of introducing ida into the kernel (looking at git logs of idr.c). SImilar to idr, but uses less memory. I see some other frameworks using it for this purpose, such as the rtc class. I can change this if this is something the kernel wants to move away from. What issues are you seeing here and what would you suggest?

Quoted 2 lines

Well, it looked to me like a job for bitfield, since we don't plan that many minors...

Use ida, it's simple, works correctly, and I don't have to audit crazy special-case bitfield manipulation that odds are, is wrong in some odd corner condition.

greg k-h

#15 lore raw
In reply to [email protected]

Hi!

Quoted 26 lines

[resend with fixed email settings]

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

Programming from device tree overlays is supported.

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. In some production contexts, interfaces that might be used during development can be disabled.

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.

Quoted 5 lines

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.

Thanks for the patches... is there new version? Is that corresponding socfpga code?

I'd like to configure fpga with .rbf file on board similar to SocKit.

Thanks,
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
author
#16 lore raw
Quoted 34 lines · Pavel Machek

Hi!

Quoted 26 lines

[resend with fixed email settings]

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

Programming from device tree overlays is supported.

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. In some production contexts, interfaces that might be used during development can be disabled.

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.

Quoted 5 lines

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.

Quoted 7 lines

Thanks for the patches... is there new version? Is that corresponding socfpga code?

I'd like to configure fpga with .rbf file on board similar to SocKit.

Thanks,
Pavel

Yes, hopefully next week.

Regards,
Alan

Quoted 5 lines
Signature · 3 lines
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html