All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fpga: add simple userspace interface to trigger FPGA programming
@ 2017-12-04 15:43 Thomas Petazzoni
  2017-12-04 15:50 ` Alan Tull
  2018-08-11 15:01 ` Philippe De Muyter
  0 siblings, 2 replies; 19+ messages in thread
From: Thomas Petazzoni @ 2017-12-04 15:43 UTC (permalink / raw)
  To: Alan Tull, Moritz Fischer, linux-fpga
  Cc: Florian Fainelli, Marek Vasut, Thomas Petazzoni

The current FPGA subsystem only allows programming the FPGA bitstream
through Device Tree overlays. This assumes that the devices inside the
FPGA are described through a Device Tree.

However, some platforms have their FPGA connected to the main CPU over
PCIe and the devices in the FPGA are therefore dynamically
discoverable using the normal PCIe enumeration mechanisms. There is
therefore no Device Tree overlay describing the devices in the
FPGA. Furthermore, on my platform (an old SH7786), there is no Device
Tree at all, as there is no support for Device Tree for this SoC.

Adding a userspace interface to trigger the programming of the FPGA
has already been requested in the past (see [1]) showing that there is
a need for such a feature.

This commit therefore introduces a very simple interface, in the form
of a "load" sysfs file. Writing the name of the firmware file to
program into the FPGA to this "load" file triggers the programming
process.

[1] http://lists.infradead.org/pipermail/linux-arm-kernel/2016-July/443034.html

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
 Documentation/ABI/testing/sysfs-class-fpga-manager | 11 +++++++++
 drivers/fpga/fpga-mgr.c                            | 28 ++++++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-class-fpga-manager b/Documentation/ABI/testing/sysfs-class-fpga-manager
index 23056c532fdd..46785ad8b878 100644
--- a/Documentation/ABI/testing/sysfs-class-fpga-manager
+++ b/Documentation/ABI/testing/sysfs-class-fpga-manager
@@ -35,3 +35,14 @@ Description:	Read fpga manager state as a string.
 		* write complete	= Doing post programming steps
 		* write complete error	= Error while doing post programming
 		* operating		= FPGA is programmed and operating
+
+What:		/sys/class/fpga_manager/<fpga>/load
+Date:		December 2017
+KernelVersion:	4.16
+Contact:	Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
+
+Description:	Program a bitstream firmware into the FPGA.
+
+		Writing the name of a firmware file into this "load"
+		file will trigger the programming of the FPGA using
+		that firmware.
diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c
index 188ffefa3cc3..1c7ca77c96c2 100644
--- a/drivers/fpga/fpga-mgr.c
+++ b/drivers/fpga/fpga-mgr.c
@@ -351,12 +351,40 @@ static ssize_t state_show(struct device *dev,
 	return sprintf(buf, "%s\n", state_str[mgr->state]);
 }
 
+static ssize_t load_store(struct device *dev,
+			  struct device_attribute *attr, const char *buf,
+			  size_t count)
+{
+	struct fpga_manager *mgr = to_fpga_manager(dev);
+	char *name;
+	int ret;
+
+	if (count > 0 && buf[count - 1] == '\n')
+		count--;
+
+	name = kstrndup(buf, count, GFP_KERNEL);
+	if (!name)
+		return -ENOSPC;
+
+	ret = fpga_mgr_firmware_load(mgr, NULL, name);
+	if (ret < 0) {
+		kfree(name);
+		return ret;
+	}
+
+	kfree(name);
+
+	return count;
+}
+
 static DEVICE_ATTR_RO(name);
 static DEVICE_ATTR_RO(state);
+static DEVICE_ATTR_WO(load);
 
 static struct attribute *fpga_mgr_attrs[] = {
 	&dev_attr_name.attr,
 	&dev_attr_state.attr,
+	&dev_attr_load.attr,
 	NULL,
 };
 ATTRIBUTE_GROUPS(fpga_mgr);
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2018-08-11 17:42 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-04 15:43 [PATCH] fpga: add simple userspace interface to trigger FPGA programming Thomas Petazzoni
2017-12-04 15:50 ` Alan Tull
2017-12-04 15:58   ` Thomas Petazzoni
2017-12-04 16:25     ` Alan Tull
2017-12-04 16:49       ` Moritz Fischer
2017-12-04 17:30         ` Alan Tull
2017-12-09 18:05   ` Florian Fainelli
2017-12-10  4:03     ` Alan Tull
2017-12-10 22:44       ` Thomas Petazzoni
2017-12-10 22:59         ` Florian Fainelli
2017-12-11 22:05           ` Moritz Fischer
2017-12-11 23:32             ` Alan Tull
2017-12-13  6:30         ` yves.vandervennet
2017-12-13  5:23           ` Thomas Petazzoni
2017-12-13 15:59             ` Alan Tull
2017-12-14  5:27               ` Thomas Petazzoni
2017-12-14 20:10                 ` Alan Tull
2017-12-10 22:42     ` Thomas Petazzoni
2018-08-11 15:01 ` Philippe De Muyter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.