Skip to contentSkip to conversation

fpga: add FPGA Bus device framework

RFC PATCH In review Wu Hao 3 participants 9 messages Aug 2, 2017 – Aug 17, 2017 FPGA manager framework

lore
Share & tools
lore

Wu Hao

author
#0 lore raw

RFC PATCH 1/1 fpga: add FPGA Bus device framework

This patch is a RFC patch which replaces the patch[1] which creates 'fpga-dev' class as container device. It introduces a 'fpga' bus type, and provides interfaces to create/destroy fpga bus devices. This fpga bus device only could be used as a container device, and no drivers needed for it.

There is no interface change, so this patch could be used together with other patches of the original patch set[2].

This following APIs are provided by FPGA Bus device framework:
* fpga_dev_create
Create fpga bus device under the given parent device.
* fpga_dev_destroy
Destroy fpga bus device

The following sysfs files are created:
* /sys/bus/fpga/devices/<fpga.x>/name
Name of the fpga bus device.

[1] http://marc.info/?l=linux-fpga&m=149844237209829&w=2
[2] http://marc.info/?l=linux-fpga&m=149844232609819&w=2

---
 Documentation/ABI/testing/sysfs-bus-fpga |   5 ++
 drivers/fpga/Kconfig                     |   6 ++
 drivers/fpga/Makefile                    |   3 +
 drivers/fpga/fpga-dev.c                  | 132 +++++++++++++++++++++++++++++++
 include/linux/fpga/fpga-dev.h            |  31 ++++++++
 5 files changed, 177 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-fpga
 create mode 100644 drivers/fpga/fpga-dev.c
 create mode 100644 include/linux/fpga/fpga-dev.h
Documentation/ABI/testing/sysfs-bus-fpga new file +5 -0
new file mode 100644
index 0000000..414e946
@@ -0,0 +1,5 @@
+What:		/sys/bus/fpga/devices/<fpga.x>/name
+Date:		August 2017
+KernelVersion:	4.13
+Contact:	Wu Hao <[email protected]>
+Description:	Name of FPGA bus device
drivers/fpga/Kconfig +6 -0
index d89eb52..b97a90e 100644
@@ -12,6 +12,12 @@ config FPGA
 	  manager drivers.
 
 if FPGA
+config FPGA_DEVICE
+	tristate "FPGA Bus Device Framework"
+	help
+	  Say Y here if you want support for FPGA Bus devices from the
+	  kernel. The FPGA Bus Device Framework adds a FPGA Bus type and
+	  provide interfaces to create FPGA devices on the bus.
 
 config FPGA_REGION
 	tristate "FPGA Region"
drivers/fpga/Makefile +3 -0
index 08fc728..3eb254e 100644
@@ -5,6 +5,9 @@
 # Core FPGA Manager Framework
 obj-$(CONFIG_FPGA)			+= fpga-mgr.o
 
+# FPGA Bus Device Framework
+obj-$(CONFIG_FPGA_DEVICE)		+= fpga-dev.o
+
 # FPGA Manager Drivers
 obj-$(CONFIG_FPGA_MGR_ICE40_SPI)	+= ice40-spi.o
 obj-$(CONFIG_FPGA_MGR_SOCFPGA)		+= socfpga.o
drivers/fpga/fpga-dev.c new file +132 -0

132 lines not on this page · raw message

include/linux/fpga/fpga-dev.h new file +31 -0
new file mode 100644
index 0000000..7f6deb4
@@ -0,0 +1,31 @@
+/*
+ * FPGA Bus Device Framework driver Header
+ *
+ * Copyright (C) 2017 Intel Corporation, Inc.
+ *
+ * This work is licensed under the terms of the GNU GPL version 2. See
+ * the COPYING file in the top-level directory.
+ */
+#ifndef _LINUX_FPGA_DEV_H
+#define _LINUX_FPGA_DEV_H
+
+/**
+ * struct fpga_dev - fpga bus device structure
+ * @name: name of fpga bus device
+ * @dev: fpga bus device
+ */
+struct fpga_dev {
+	const char *name;
+	struct device dev;
+};
+
+#define to_fpga_dev(d) container_of(d, struct fpga_dev, dev)
+
+struct fpga_dev *fpga_dev_create(struct device *parent, const char *name);
+
+static inline void fpga_dev_destroy(struct fpga_dev *fdev)
+{
+	device_unregister(&fdev->dev);
+}
+
+#endif
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 9 lines · Wu Hao

This patch is a RFC patch which replaces the patch[1] which creates 'fpga-dev' class as container device. It introduces a 'fpga' bus type, and provides interfaces to create/destroy fpga bus devices. This fpga bus device only could be used as a container device, and no drivers needed for it.

There is no interface change, so this patch could be used together with other patches of the original patch set[2].

I am wondering whether this could be added to fpga-bridge.c so that fpga-bridge becomes the fpga bus and fpga bus devices are under it. The reasons for doing this are discussed in the other thread.

Quoted 5 lines

This following APIs are provided by FPGA Bus device framework:
* fpga_dev_create
Create fpga bus device under the given parent device.
* fpga_dev_destroy
Destroy fpga bus device

This is being used in such that each fpga-dev is a container for platform devices rather than fpga devices. That's not what I was expecting. :)

Alan

Quoted 73 lines

The following sysfs files are created:
* /sys/bus/fpga/devices/<fpga.x>/name
Name of the fpga bus device.

[1] http://marc.info/?l=linux-fpga&m=149844237209829&w=2
[2] http://marc.info/?l=linux-fpga&m=149844232609819&w=2

---
 Documentation/ABI/testing/sysfs-bus-fpga |   5 ++
 drivers/fpga/Kconfig                     |   6 ++
 drivers/fpga/Makefile                    |   3 +
 drivers/fpga/fpga-dev.c                  | 132 +++++++++++++++++++++++++++++++
 include/linux/fpga/fpga-dev.h            |  31 ++++++++
 5 files changed, 177 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-fpga
 create mode 100644 drivers/fpga/fpga-dev.c
 create mode 100644 include/linux/fpga/fpga-dev.h
Documentation/ABI/testing/sysfs-bus-fpga new file +5 -0
new file mode 100644
index 0000000..414e946
@@ -0,0 +1,5 @@
+What:          /sys/bus/fpga/devices/<fpga.x>/name
+Date:          August 2017
+KernelVersion: 4.13
+Contact:       Wu Hao <[email protected]>
+Description:   Name of FPGA bus device
drivers/fpga/Kconfig +6 -0
index d89eb52..b97a90e 100644
@@ -12,6 +12,12 @@ config FPGA
          manager drivers.
 
 if FPGA
+config FPGA_DEVICE
+       tristate "FPGA Bus Device Framework"
+       help
+         Say Y here if you want support for FPGA Bus devices from the
+         kernel. The FPGA Bus Device Framework adds a FPGA Bus type and
+         provide interfaces to create FPGA devices on the bus.
 
 config FPGA_REGION
        tristate "FPGA Region"
drivers/fpga/Makefile +3 -0
index 08fc728..3eb254e 100644
@@ -5,6 +5,9 @@
 # Core FPGA Manager Framework
 obj-$(CONFIG_FPGA)                     += fpga-mgr.o
 
+# FPGA Bus Device Framework
+obj-$(CONFIG_FPGA_DEVICE)              += fpga-dev.o
+
 # FPGA Manager Drivers
 obj-$(CONFIG_FPGA_MGR_ICE40_SPI)       += ice40-spi.o
 obj-$(CONFIG_FPGA_MGR_SOCFPGA)         += socfpga.o
drivers/fpga/fpga-dev.c new file +5 -0
new file mode 100644
index 0000000..ddf67bb
@@ -0,0 +1,132 @@
+/*
+ * FPGA Bus Device Framework Driver
+ *
+ * Copyright (C) 2017 Intel Corporation, Inc.
+ *

drivers/fpga/fpga-dev.c line 15

Quoted 10 lines
drivers/fpga/fpga-dev.c new file +10 -0
+ * This work is licensed under the terms of the GNU GPL version 2. See
+ * the COPYING file in the top-level directory.
+ */
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/fpga/fpga-dev.h>
+
+static DEFINE_IDA(fpga_dev_ida);
+static bool is_bus_registered;

I wouldn't think init will be called more than once. Did you run into a problem where it did?

Quoted 157 lines
drivers/fpga/fpga-dev.c new file +117 -0
+
+static void fpga_dev_release(struct device *dev)
+{
+       struct fpga_dev *fdev = to_fpga_dev(dev);
+
+       ida_simple_remove(&fpga_dev_ida, fdev->dev.id);
+       kfree(fdev);
+}
+
+static const struct device_type fpga_dev_type = {
+       .name           = "fpga_dev",
+       .release        = fpga_dev_release,
+};
+
+static ssize_t name_show(struct device *dev,
+                        struct device_attribute *attr, char *buf)
+{
+       struct fpga_dev *fdev = to_fpga_dev(dev);
+
+       return sprintf(buf, "%s\n", fdev->name);
+}
+static DEVICE_ATTR_RO(name);
+
+static struct attribute *fpga_dev_attrs[] = {
+       &dev_attr_name.attr,
+       NULL,
+};
+ATTRIBUTE_GROUPS(fpga_dev);
+
+static struct bus_type fpga_bus_type = {
+       .name           = "fpga",
+};
+
+/**
+ * fpga_dev_create - create a fpga device on fpga bus
+ * @parent: parent device
+ * @name: fpga bus device name
+ *
+ * Return fpga_dev struct for success, error code otherwise.
+ */
+struct fpga_dev *fpga_dev_create(struct device *parent, const char *name)
+{
+       struct fpga_dev *fdev;
+       int id, ret = 0;
+
+       if (WARN_ON(!is_bus_registered))
+               return ERR_PTR(-ENODEV);
+
+       if (!name || !strlen(name)) {
+               dev_err(parent, "Attempt to register with no name!\n");
+               return ERR_PTR(-EINVAL);
+       }
+
+       fdev = kzalloc(sizeof(*fdev), GFP_KERNEL);
+       if (!fdev)
+               return ERR_PTR(-ENOMEM);
+
+       id = ida_simple_get(&fpga_dev_ida, 0, 0, GFP_KERNEL);
+       if (id < 0) {
+               ret = id;
+               goto error_kfree;
+       }
+
+       fdev->name = name;
+
+       device_initialize(&fdev->dev);
+       fdev->dev.type = &fpga_dev_type;
+       fdev->dev.bus = &fpga_bus_type;
+       fdev->dev.groups = fpga_dev_groups;
+       fdev->dev.parent = parent;
+       fdev->dev.id = id;
+
+       ret = dev_set_name(&fdev->dev, "fpga.%d", id);
+       if (ret)
+               goto error_device;
+
+       ret = device_add(&fdev->dev);
+       if (ret)
+               goto error_device;
+
+       dev_dbg(fdev->dev.parent, "fpga bus device [%s] created\n", fdev->name);
+
+       return fdev;
+
+error_device:
+       ida_simple_remove(&fpga_dev_ida, id);
+error_kfree:
+       kfree(fdev);
+
+       return ERR_PTR(ret);
+}
+EXPORT_SYMBOL_GPL(fpga_dev_create);
+
+static int __init fpga_bus_init(void)
+{
+       int ret;
+
+       pr_info("FPGA Bus Device Framework\n");
+
+       ret = bus_register(&fpga_bus_type);
+       if (ret)
+               return ret;
+
+       is_bus_registered = true;
+       return 0;
+}
+
+static void __exit fpga_bus_exit(void)
+{
+       bus_unregister(&fpga_bus_type);
+}
+
+MODULE_DESCRIPTION("FPGA Bus Device Framework");
+MODULE_LICENSE("GPL v2");
+
+subsys_initcall(fpga_bus_init);
+module_exit(fpga_bus_exit);
include/linux/fpga/fpga-dev.h new file +31 -1
new file mode 100644
index 0000000..7f6deb4
@@ -0,0 +1,31 @@
+/*
+ * FPGA Bus Device Framework driver Header
+ *
+ * Copyright (C) 2017 Intel Corporation, Inc.
+ *
+ * This work is licensed under the terms of the GNU GPL version 2. See
+ * the COPYING file in the top-level directory.
+ */
+#ifndef _LINUX_FPGA_DEV_H
+#define _LINUX_FPGA_DEV_H
+
+/**
+ * struct fpga_dev - fpga bus device structure
+ * @name: name of fpga bus device
+ * @dev: fpga bus device
+ */
+struct fpga_dev {
+       const char *name;
+       struct device dev;
+};
+
+#define to_fpga_dev(d) container_of(d, struct fpga_dev, dev)
+
+struct fpga_dev *fpga_dev_create(struct device *parent, const char *name);
+
+static inline void fpga_dev_destroy(struct fpga_dev *fdev)
+{
+       device_unregister(&fdev->dev);
+}
+
+#endif
--

1.8.3.1

author
#2 lore raw
Quoted 21 lines · Alan Tull
Quoted 9 lines · Wu Hao

This patch is a RFC patch which replaces the patch[1] which creates 'fpga-dev' class as container device. It introduces a 'fpga' bus type, and provides interfaces to create/destroy fpga bus devices. This fpga bus device only could be used as a container device, and no drivers needed for it.

There is no interface change, so this patch could be used together with other patches of the original patch set[2].

I am wondering whether this could be added to fpga-bridge.c so that fpga-bridge becomes the fpga bus and fpga bus devices are under it. The reasons for doing this are discussed in the other thread.

Quoted 5 lines

This following APIs are provided by FPGA Bus device framework:
* fpga_dev_create
Create fpga bus device under the given parent device.
* fpga_dev_destroy
Destroy fpga bus device

Quoted 3 lines

This is being used in such that each fpga-dev is a container for platform devices rather than fpga devices. That's not what I was expecting. :)

Hi Alan

So does that mean in Intel FPGA PCIe driver, it needs to create a fpga-bridge (as base bridge?), and this fpga-bridge should register a fpga-bus and have a fpga bus device as its child, after that we can use this fpga bus device as container device, and create sub feature devices (e.g AFU and FME platform device) under it, and user application could locate it in /sys/bus/fpga/devices/. Is my understanding correct? :)

And if we have second level fpga-bridge for PR regions, then they should register fpga-bus and fpga bus type device as child too? If yes, then we need a method for user application to distinguish which one represents the FPGA device in /sys/bus/fpga/devices/, right? It seems to be a similar case that we see a lot of regions in /sys/class/fpga_region/ but not sure which one is the base region. :)

Quoted 81 lines

Alan

Quoted 78 lines

The following sysfs files are created:
* /sys/bus/fpga/devices/<fpga.x>/name
Name of the fpga bus device.

[1] http://marc.info/?l=linux-fpga&m=149844237209829&w=2
[2] http://marc.info/?l=linux-fpga&m=149844232609819&w=2

---
 Documentation/ABI/testing/sysfs-bus-fpga |   5 ++
 drivers/fpga/Kconfig                     |   6 ++
 drivers/fpga/Makefile                    |   3 +
 drivers/fpga/fpga-dev.c                  | 132 +++++++++++++++++++++++++++++++
 include/linux/fpga/fpga-dev.h            |  31 ++++++++
 5 files changed, 177 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-fpga
 create mode 100644 drivers/fpga/fpga-dev.c
 create mode 100644 include/linux/fpga/fpga-dev.h
Documentation/ABI/testing/sysfs-bus-fpga new file +5 -0
new file mode 100644
index 0000000..414e946
@@ -0,0 +1,5 @@
+What:          /sys/bus/fpga/devices/<fpga.x>/name
+Date:          August 2017
+KernelVersion: 4.13
+Contact:       Wu Hao <[email protected]>
+Description:   Name of FPGA bus device
drivers/fpga/Kconfig +6 -0
index d89eb52..b97a90e 100644
@@ -12,6 +12,12 @@ config FPGA
          manager drivers.
 
 if FPGA
+config FPGA_DEVICE
+       tristate "FPGA Bus Device Framework"
+       help
+         Say Y here if you want support for FPGA Bus devices from the
+         kernel. The FPGA Bus Device Framework adds a FPGA Bus type and
+         provide interfaces to create FPGA devices on the bus.
 
 config FPGA_REGION
        tristate "FPGA Region"
drivers/fpga/Makefile +3 -0
index 08fc728..3eb254e 100644
@@ -5,6 +5,9 @@
 # Core FPGA Manager Framework
 obj-$(CONFIG_FPGA)                     += fpga-mgr.o
 
+# FPGA Bus Device Framework
+obj-$(CONFIG_FPGA_DEVICE)              += fpga-dev.o
+
 # FPGA Manager Drivers
 obj-$(CONFIG_FPGA_MGR_ICE40_SPI)       += ice40-spi.o
 obj-$(CONFIG_FPGA_MGR_SOCFPGA)         += socfpga.o
drivers/fpga/fpga-dev.c new file +10 -0
new file mode 100644
index 0000000..ddf67bb
@@ -0,0 +1,132 @@
+/*
+ * FPGA Bus Device Framework Driver
+ *
+ * Copyright (C) 2017 Intel Corporation, Inc.
+ *
+ * This work is licensed under the terms of the GNU GPL version 2. See
+ * the COPYING file in the top-level directory.
+ */
+#include <linux/device.h>
+#include <linux/module.h>
Quoted 8 lines

drivers/fpga/fpga-dev.c line 15

Quoted 5 lines
drivers/fpga/fpga-dev.c new file +5 -0
+#include <linux/slab.h>
+#include <linux/fpga/fpga-dev.h>
+
+static DEFINE_IDA(fpga_dev_ida);
+static bool is_bus_registered;

I wouldn't think init will be called more than once. Did you run into a problem where it did?

It's used to prevent bus device creation if bus_register function returns error.

Thanks
Hao

Quoted 162 lines
Quoted 156 lines
drivers/fpga/fpga-dev.c new file +117 -0
+
+static void fpga_dev_release(struct device *dev)
+{
+       struct fpga_dev *fdev = to_fpga_dev(dev);
+
+       ida_simple_remove(&fpga_dev_ida, fdev->dev.id);
+       kfree(fdev);
+}
+
+static const struct device_type fpga_dev_type = {
+       .name           = "fpga_dev",
+       .release        = fpga_dev_release,
+};
+
+static ssize_t name_show(struct device *dev,
+                        struct device_attribute *attr, char *buf)
+{
+       struct fpga_dev *fdev = to_fpga_dev(dev);
+
+       return sprintf(buf, "%s\n", fdev->name);
+}
+static DEVICE_ATTR_RO(name);
+
+static struct attribute *fpga_dev_attrs[] = {
+       &dev_attr_name.attr,
+       NULL,
+};
+ATTRIBUTE_GROUPS(fpga_dev);
+
+static struct bus_type fpga_bus_type = {
+       .name           = "fpga",
+};
+
+/**
+ * fpga_dev_create - create a fpga device on fpga bus
+ * @parent: parent device
+ * @name: fpga bus device name
+ *
+ * Return fpga_dev struct for success, error code otherwise.
+ */
+struct fpga_dev *fpga_dev_create(struct device *parent, const char *name)
+{
+       struct fpga_dev *fdev;
+       int id, ret = 0;
+
+       if (WARN_ON(!is_bus_registered))
+               return ERR_PTR(-ENODEV);
+
+       if (!name || !strlen(name)) {
+               dev_err(parent, "Attempt to register with no name!\n");
+               return ERR_PTR(-EINVAL);
+       }
+
+       fdev = kzalloc(sizeof(*fdev), GFP_KERNEL);
+       if (!fdev)
+               return ERR_PTR(-ENOMEM);
+
+       id = ida_simple_get(&fpga_dev_ida, 0, 0, GFP_KERNEL);
+       if (id < 0) {
+               ret = id;
+               goto error_kfree;
+       }
+
+       fdev->name = name;
+
+       device_initialize(&fdev->dev);
+       fdev->dev.type = &fpga_dev_type;
+       fdev->dev.bus = &fpga_bus_type;
+       fdev->dev.groups = fpga_dev_groups;
+       fdev->dev.parent = parent;
+       fdev->dev.id = id;
+
+       ret = dev_set_name(&fdev->dev, "fpga.%d", id);
+       if (ret)
+               goto error_device;
+
+       ret = device_add(&fdev->dev);
+       if (ret)
+               goto error_device;
+
+       dev_dbg(fdev->dev.parent, "fpga bus device [%s] created\n", fdev->name);
+
+       return fdev;
+
+error_device:
+       ida_simple_remove(&fpga_dev_ida, id);
+error_kfree:
+       kfree(fdev);
+
+       return ERR_PTR(ret);
+}
+EXPORT_SYMBOL_GPL(fpga_dev_create);
+
+static int __init fpga_bus_init(void)
+{
+       int ret;
+
+       pr_info("FPGA Bus Device Framework\n");
+
+       ret = bus_register(&fpga_bus_type);
+       if (ret)
+               return ret;
+
+       is_bus_registered = true;
+       return 0;
+}
+
+static void __exit fpga_bus_exit(void)
+{
+       bus_unregister(&fpga_bus_type);
+}
+
+MODULE_DESCRIPTION("FPGA Bus Device Framework");
+MODULE_LICENSE("GPL v2");
+
+subsys_initcall(fpga_bus_init);
+module_exit(fpga_bus_exit);
include/linux/fpga/fpga-dev.h new file +31 -1
new file mode 100644
index 0000000..7f6deb4
@@ -0,0 +1,31 @@
+/*
+ * FPGA Bus Device Framework driver Header
+ *
+ * Copyright (C) 2017 Intel Corporation, Inc.
+ *
+ * This work is licensed under the terms of the GNU GPL version 2. See
+ * the COPYING file in the top-level directory.
+ */
+#ifndef _LINUX_FPGA_DEV_H
+#define _LINUX_FPGA_DEV_H
+
+/**
+ * struct fpga_dev - fpga bus device structure
+ * @name: name of fpga bus device
+ * @dev: fpga bus device
+ */
+struct fpga_dev {
+       const char *name;
+       struct device dev;
+};
+
+#define to_fpga_dev(d) container_of(d, struct fpga_dev, dev)
+
+struct fpga_dev *fpga_dev_create(struct device *parent, const char *name);
+
+static inline void fpga_dev_destroy(struct fpga_dev *fdev)
+{
+       device_unregister(&fdev->dev);
+}
+
+#endif
--
Quoted 2 lines

1.8.3.1

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

#3 lore raw
Quoted 22 lines · Wu Hao
Quoted 21 lines · Alan Tull
Quoted 9 lines · Wu Hao

This patch is a RFC patch which replaces the patch[1] which creates 'fpga-dev' class as container device. It introduces a 'fpga' bus type, and provides interfaces to create/destroy fpga bus devices. This fpga bus device only could be used as a container device, and no drivers needed for it.

There is no interface change, so this patch could be used together with other patches of the original patch set[2].

I am wondering whether this could be added to fpga-bridge.c so that fpga-bridge becomes the fpga bus and fpga bus devices are under it. The reasons for doing this are discussed in the other thread.

Quoted 5 lines

This following APIs are provided by FPGA Bus device framework:
* fpga_dev_create
Create fpga bus device under the given parent device.
* fpga_dev_destroy
Destroy fpga bus device

Quoted 8 lines
Quoted 3 lines

This is being used in such that each fpga-dev is a container for platform devices rather than fpga devices. That's not what I was expecting. :)

Hi Alan

So does that mean in Intel FPGA PCIe driver, it needs to create a fpga-bridge (as base bridge?),

Yes

Quoted 3 lines

and this fpga-bridge should register
a fpga-bus and have a fpga bus device as its child, after that we can use this fpga bus device as container device,

Could the bus code be added to fpga-bridge? Then the base bridge is the container device. A fpga-region would be under that and the AFU and FME fpga devices would be under it.

Quoted 2 lines

and create sub feature
devices (e.g AFU and FME platform device)

We're talking about adding a new bus to the kernel here, not platform bus.

Quoted 2 lines

under it, and user application
could locate it in /sys/bus/fpga/devices/. Is my understanding correct? :)

So sysfs may end up something like this in your case:

/sys/bus/fpga/devices/fpga.0/intel-fpga-fme.0
/sys/bus/fpga/devices/fpga.0/intel-fpga-port.0
/sys/bus/fpga/devices/fpga.0/intel-fpga-port.1
/sys/bus/fpga/devices/fpga.0/fpga-mgr0
/sys/bus/fpga/devices/fpga.0/fpga-br1
/sys/bus/fpga/devices/fpga.0/fpga-br2

/sys/bus/fpga/devices/fpga.1/fpga-region1
/sys/bus/fpga/devices/fpga.2/fpga-region2

/sys/bus/fpga/devices/fpga.3/intel-fpga-fme.1
/sys/bus/fpga/devices/fpga.3/intel-fpga-port.2
/sys/bus/fpga/devices/fpga.3/intel-fpga-port.3
/sys/bus/fpga/devices/fpga.0/fpga-mgr1
/sys/bus/fpga/devices/fpga.3/fpga-br4
/sys/bus/fpga/devices/fpga.3/fpga-br5

/sys/bus/fpga/devices/fpga.4/fpga-region4
/sys/bus/fpga/devices/fpga.5/fpga-region5

fpga-br0 and 3 are base bridges (on top of PCIe) which show up as fpga.0 and 3. Regions 0 and 3 are base regions.

fpga.0 and fpga.3 correspond to the real FPGA devices.

Quoted 5 lines

And if we have second level fpga-bridge for PR regions, then they should register fpga-bus and fpga bus type device as child too? If yes, then we need a method for user application to distinguish which one represents the FPGA device in /sys/bus/fpga/devices/, right?

To find a bus that is a fpga, userspace only needs to look for busses that have an FME (or a mgr).

Quoted 2 lines

It seems to be a similar case that we see a lot of regions in /sys/class/fpga_region/ but not sure which one is the base region. :)

I understand that the goal of fpga-dev was to describe the topology (which is the function of a bus, not a class as Rob explained). To be honest, I'm still pondering the implications of adding a fpga bus.

Alan

Quoted 263 lines
Quoted 82 lines

Alan

Quoted 78 lines

The following sysfs files are created:
* /sys/bus/fpga/devices/<fpga.x>/name
Name of the fpga bus device.

[1] http://marc.info/?l=linux-fpga&m=149844237209829&w=2
[2] http://marc.info/?l=linux-fpga&m=149844232609819&w=2

---
 Documentation/ABI/testing/sysfs-bus-fpga |   5 ++
 drivers/fpga/Kconfig                     |   6 ++
 drivers/fpga/Makefile                    |   3 +
 drivers/fpga/fpga-dev.c                  | 132 +++++++++++++++++++++++++++++++
 include/linux/fpga/fpga-dev.h            |  31 ++++++++
 5 files changed, 177 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-fpga
 create mode 100644 drivers/fpga/fpga-dev.c
 create mode 100644 include/linux/fpga/fpga-dev.h
Documentation/ABI/testing/sysfs-bus-fpga new file +5 -0
new file mode 100644
index 0000000..414e946
@@ -0,0 +1,5 @@
+What:          /sys/bus/fpga/devices/<fpga.x>/name
+Date:          August 2017
+KernelVersion: 4.13
+Contact:       Wu Hao <[email protected]>
+Description:   Name of FPGA bus device
drivers/fpga/Kconfig +6 -0
index d89eb52..b97a90e 100644
@@ -12,6 +12,12 @@ config FPGA
          manager drivers.
 
 if FPGA
+config FPGA_DEVICE
+       tristate "FPGA Bus Device Framework"
+       help
+         Say Y here if you want support for FPGA Bus devices from the
+         kernel. The FPGA Bus Device Framework adds a FPGA Bus type and
+         provide interfaces to create FPGA devices on the bus.
 
 config FPGA_REGION
        tristate "FPGA Region"
drivers/fpga/Makefile +3 -0
index 08fc728..3eb254e 100644
@@ -5,6 +5,9 @@
 # Core FPGA Manager Framework
 obj-$(CONFIG_FPGA)                     += fpga-mgr.o
 
+# FPGA Bus Device Framework
+obj-$(CONFIG_FPGA_DEVICE)              += fpga-dev.o
+
 # FPGA Manager Drivers
 obj-$(CONFIG_FPGA_MGR_ICE40_SPI)       += ice40-spi.o
 obj-$(CONFIG_FPGA_MGR_SOCFPGA)         += socfpga.o
drivers/fpga/fpga-dev.c new file +10 -0
new file mode 100644
index 0000000..ddf67bb
@@ -0,0 +1,132 @@
+/*
+ * FPGA Bus Device Framework Driver
+ *
+ * Copyright (C) 2017 Intel Corporation, Inc.
+ *
+ * This work is licensed under the terms of the GNU GPL version 2. See
+ * the COPYING file in the top-level directory.
+ */
+#include <linux/device.h>
+#include <linux/module.h>
Quoted 8 lines

drivers/fpga/fpga-dev.c line 15

Quoted 5 lines
drivers/fpga/fpga-dev.c new file +5 -0
+#include <linux/slab.h>
+#include <linux/fpga/fpga-dev.h>
+
+static DEFINE_IDA(fpga_dev_ida);
+static bool is_bus_registered;

I wouldn't think init will be called more than once. Did you run into a problem where it did?

It's used to prevent bus device creation if bus_register function returns error.

Thanks
Hao

Quoted 154 lines
Quoted 154 lines
drivers/fpga/fpga-dev.c new file +117 -0
+
+static void fpga_dev_release(struct device *dev)
+{
+       struct fpga_dev *fdev = to_fpga_dev(dev);
+
+       ida_simple_remove(&fpga_dev_ida, fdev->dev.id);
+       kfree(fdev);
+}
+
+static const struct device_type fpga_dev_type = {
+       .name           = "fpga_dev",
+       .release        = fpga_dev_release,
+};
+
+static ssize_t name_show(struct device *dev,
+                        struct device_attribute *attr, char *buf)
+{
+       struct fpga_dev *fdev = to_fpga_dev(dev);
+
+       return sprintf(buf, "%s\n", fdev->name);
+}
+static DEVICE_ATTR_RO(name);
+
+static struct attribute *fpga_dev_attrs[] = {
+       &dev_attr_name.attr,
+       NULL,
+};
+ATTRIBUTE_GROUPS(fpga_dev);
+
+static struct bus_type fpga_bus_type = {
+       .name           = "fpga",
+};
+
+/**
+ * fpga_dev_create - create a fpga device on fpga bus
+ * @parent: parent device
+ * @name: fpga bus device name
+ *
+ * Return fpga_dev struct for success, error code otherwise.
+ */
+struct fpga_dev *fpga_dev_create(struct device *parent, const char *name)
+{
+       struct fpga_dev *fdev;
+       int id, ret = 0;
+
+       if (WARN_ON(!is_bus_registered))
+               return ERR_PTR(-ENODEV);
+
+       if (!name || !strlen(name)) {
+               dev_err(parent, "Attempt to register with no name!\n");
+               return ERR_PTR(-EINVAL);
+       }
+
+       fdev = kzalloc(sizeof(*fdev), GFP_KERNEL);
+       if (!fdev)
+               return ERR_PTR(-ENOMEM);
+
+       id = ida_simple_get(&fpga_dev_ida, 0, 0, GFP_KERNEL);
+       if (id < 0) {
+               ret = id;
+               goto error_kfree;
+       }
+
+       fdev->name = name;
+
+       device_initialize(&fdev->dev);
+       fdev->dev.type = &fpga_dev_type;
+       fdev->dev.bus = &fpga_bus_type;
+       fdev->dev.groups = fpga_dev_groups;
+       fdev->dev.parent = parent;
+       fdev->dev.id = id;
+
+       ret = dev_set_name(&fdev->dev, "fpga.%d", id);
+       if (ret)
+               goto error_device;
+
+       ret = device_add(&fdev->dev);
+       if (ret)
+               goto error_device;
+
+       dev_dbg(fdev->dev.parent, "fpga bus device [%s] created\n", fdev->name);
+
+       return fdev;
+
+error_device:
+       ida_simple_remove(&fpga_dev_ida, id);
+error_kfree:
+       kfree(fdev);
+
+       return ERR_PTR(ret);
+}
+EXPORT_SYMBOL_GPL(fpga_dev_create);
+
+static int __init fpga_bus_init(void)
+{
+       int ret;
+
+       pr_info("FPGA Bus Device Framework\n");
+
+       ret = bus_register(&fpga_bus_type);
+       if (ret)
+               return ret;
+
+       is_bus_registered = true;
+       return 0;
+}
+
+static void __exit fpga_bus_exit(void)
+{
+       bus_unregister(&fpga_bus_type);
+}
+
+MODULE_DESCRIPTION("FPGA Bus Device Framework");
+MODULE_LICENSE("GPL v2");
+
+subsys_initcall(fpga_bus_init);
+module_exit(fpga_bus_exit);
include/linux/fpga/fpga-dev.h new file +30 -0
new file mode 100644
index 0000000..7f6deb4
@@ -0,0 +1,31 @@
+/*
+ * FPGA Bus Device Framework driver Header
+ *
+ * Copyright (C) 2017 Intel Corporation, Inc.
+ *
+ * This work is licensed under the terms of the GNU GPL version 2. See
+ * the COPYING file in the top-level directory.
+ */
+#ifndef _LINUX_FPGA_DEV_H
+#define _LINUX_FPGA_DEV_H
+
+/**
+ * struct fpga_dev - fpga bus device structure
+ * @name: name of fpga bus device
+ * @dev: fpga bus device
+ */
+struct fpga_dev {
+       const char *name;
+       struct device dev;
+};
+
+#define to_fpga_dev(d) container_of(d, struct fpga_dev, dev)
+
+struct fpga_dev *fpga_dev_create(struct device *parent, const char *name);
+
+static inline void fpga_dev_destroy(struct fpga_dev *fdev)
+{
+       device_unregister(&fdev->dev);
+}
+
Quoted 8 lines
Quoted 4 lines
include/linux/fpga/fpga-dev.h new file +1 -1
+#endif
--

1.8.3.1

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

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

author
#4 lore raw
Quoted 50 lines · Wu Hao
Quoted 22 lines · Alan Tull
Quoted 21 lines · Wu Hao
Quoted 9 lines

This patch is a RFC patch which replaces the patch[1] which creates 'fpga-dev' class as container device. It introduces a 'fpga' bus type, and provides interfaces to create/destroy fpga bus devices. This fpga bus device only could be used as a container device, and no drivers needed for it.

There is no interface change, so this patch could be used together with other patches of the original patch set[2].

I am wondering whether this could be added to fpga-bridge.c so that fpga-bridge becomes the fpga bus and fpga bus devices are under it. The reasons for doing this are discussed in the other thread.

Quoted 5 lines

This following APIs are provided by FPGA Bus device framework:
* fpga_dev_create
Create fpga bus device under the given parent device.
* fpga_dev_destroy
Destroy fpga bus device

Quoted 8 lines
Quoted 3 lines

This is being used in such that each fpga-dev is a container for platform devices rather than fpga devices. That's not what I was expecting. :)

Hi Alan

So does that mean in Intel FPGA PCIe driver, it needs to create a fpga-bridge (as base bridge?),

Yes

Quoted 3 lines

and this fpga-bridge should register
a fpga-bus and have a fpga bus device as its child, after that we can use this fpga bus device as container device,

Could the bus code be added to fpga-bridge? Then the base bridge is the container device. A fpga-region would be under that and the AFU and FME fpga devices would be under it.

Quoted 2 lines

and create sub feature
devices (e.g AFU and FME platform device)

We're talking about adding a new bus to the kernel here, not platform bus.

Quoted 2 lines

under it, and user application
could locate it in /sys/bus/fpga/devices/. Is my understanding correct? :)

Quoted 8 lines

So sysfs may end up something like this in your case:

/sys/bus/fpga/devices/fpga.0/intel-fpga-fme.0
/sys/bus/fpga/devices/fpga.0/intel-fpga-port.0
/sys/bus/fpga/devices/fpga.0/intel-fpga-port.1
/sys/bus/fpga/devices/fpga.0/fpga-mgr0
/sys/bus/fpga/devices/fpga.0/fpga-br1
/sys/bus/fpga/devices/fpga.0/fpga-br2

Hi Alan

I am a little confused on this.

It seems that we could not have multiple fpga-br/region/mgr under one device. As in patch set2, intel-fpga-fme.0 creates platform devices as children, and register fpga-bridges/regions/mgr under these children platform devices. This is why 3 new platform device driver introduced in this patch set 2 to match with those new created children platform devices.

So it is something like this /sys/bus/fpga/devices/fpga.0/intel-fpga-fme.0/intel-fpga-fme-region.0/fpga_region/region0 /sys/bus/fpga/devices/fpga.0/intel-fpga-fme.0/intel-fpga-fme-region.1/fpga_region/region1 /sys/bus/fpga/devices/fpga.0/intel-fpga-fme.0/intel-fpga-fme-br.0/fpga_bridge/br1 /sys/bus/fpga/devices/fpga.0/intel-fpga-fme.0/intel-fpga-fme-br.1/fpga_region/br2 /sys/bus/fpga/devices/fpga.1
/sys/bus/fpga/devices/fpga.2

br0 should be the base bridge. fpga.1 and 2 are the child fpga bus device of fpga bridge.

Quoted 20 lines

/sys/bus/fpga/devices/fpga.1/fpga-region1
/sys/bus/fpga/devices/fpga.2/fpga-region2

/sys/bus/fpga/devices/fpga.3/intel-fpga-fme.1
/sys/bus/fpga/devices/fpga.3/intel-fpga-port.2
/sys/bus/fpga/devices/fpga.3/intel-fpga-port.3
/sys/bus/fpga/devices/fpga.0/fpga-mgr1
/sys/bus/fpga/devices/fpga.3/fpga-br4
/sys/bus/fpga/devices/fpga.3/fpga-br5

/sys/bus/fpga/devices/fpga.4/fpga-region4
/sys/bus/fpga/devices/fpga.5/fpga-region5

fpga-br0 and 3 are base bridges (on top of PCIe) which show up as fpga.0 and 3. Regions 0 and 3 are base regions.

fpga.0 and fpga.3 correspond to the real FPGA devices.

Quoted 1 line
Quoted 7 lines
Quoted 4 lines

And if we have second level fpga-bridge for PR regions, then they should register fpga-bus and fpga bus type device as child too? If yes, then we need a method for user application to distinguish which one represents the FPGA device in /sys/bus/fpga/devices/, right?

To find a bus that is a fpga, userspace only needs to look for busses that have an FME (or a mgr).

Do you mean that check all fpga-dev.x folder to see if anyone has FME?

Then it is still not friendly to user space, as we may have a lot of bridges (and regions) on one system.

And looks like no big difference that we reuse base fpga-region as container. Search all regionx in /sys/class/fpga_region/ to see if anyone has a FME.

How do you think? : )

Hao

Quoted 278 lines
Quoted 3 lines

It seems to be a similar case that we see a lot of regions in /sys/class/fpga_region/ but not sure which one is the base region. :)

I understand that the goal of fpga-dev was to describe the topology (which is the function of a bus, not a class as Rob explained). To be honest, I'm still pondering the implications of adding a fpga bus.

Alan

Quoted 12 lines
Quoted 12 lines

Alan

Quoted 8 lines

The following sysfs files are created:
* /sys/bus/fpga/devices/<fpga.x>/name
Name of the fpga bus device.

[1] http://marc.info/?l=linux-fpga&m=149844237209829&w=2
[2] http://marc.info/?l=linux-fpga&m=149844232609819&w=2

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
---
 Documentation/ABI/testing/sysfs-bus-fpga |   5 ++
 drivers/fpga/Kconfig                     |   6 ++
 drivers/fpga/Makefile                    |   3 +
 drivers/fpga/fpga-dev.c                  | 132

+++++++++++++++++++++++++++++++

Quoted 7 lines
Quoted 7 lines

Review

Quoted 7 lines
 include/linux/fpga/fpga-dev.h            |  31 ++++++++
 5 files changed, 177 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-fpga
 create mode 100644 drivers/fpga/fpga-dev.c
 create mode 100644 include/linux/fpga/fpga-dev.h
(quoted diff) +0 -0

b/Documentation/ABI/testing/sysfs-bus-fpga

Quoted 106 lines
Quoted 57 lines
Quoted 57 lines

new file mode 100644
index 0000000..414e946

Documentation/ABI/testing/sysfs-bus-fpga new file +5 -0
@@ -0,0 +1,5 @@
+What:          /sys/bus/fpga/devices/<fpga.x>/name
+Date:          August 2017
+KernelVersion: 4.13
+Contact:       Wu Hao <[email protected]>
+Description:   Name of FPGA bus device
drivers/fpga/Kconfig +6 -0
index d89eb52..b97a90e 100644
@@ -12,6 +12,12 @@ config FPGA
          manager drivers.
 
 if FPGA
+config FPGA_DEVICE
+       tristate "FPGA Bus Device Framework"
+       help
+         Say Y here if you want support for FPGA Bus devices from the
+         kernel. The FPGA Bus Device Framework adds a FPGA Bus type and
+         provide interfaces to create FPGA devices on the bus.
 
 config FPGA_REGION
        tristate "FPGA Region"
drivers/fpga/Makefile +3 -0
index 08fc728..3eb254e 100644
@@ -5,6 +5,9 @@
 # Core FPGA Manager Framework
 obj-$(CONFIG_FPGA)                     += fpga-mgr.o
 
+# FPGA Bus Device Framework
+obj-$(CONFIG_FPGA_DEVICE)              += fpga-dev.o
+
 # FPGA Manager Drivers
 obj-$(CONFIG_FPGA_MGR_ICE40_SPI)       += ice40-spi.o
 obj-$(CONFIG_FPGA_MGR_SOCFPGA)         += socfpga.o
drivers/fpga/fpga-dev.c new file +10 -0
new file mode 100644
index 0000000..ddf67bb
@@ -0,0 +1,132 @@
+/*
+ * FPGA Bus Device Framework Driver
+ *
+ * Copyright (C) 2017 Intel Corporation, Inc.
+ *
+ * This work is licensed under the terms of the GNU GPL version 2. See
+ * the COPYING file in the top-level directory.
+ */
+#include <linux/device.h>
+#include <linux/module.h>
Quoted 8 lines

drivers/fpga/fpga-dev.c line 15

Quoted 5 lines
drivers/fpga/fpga-dev.c new file +5 -0
+#include <linux/slab.h>
+#include <linux/fpga/fpga-dev.h>
+
+static DEFINE_IDA(fpga_dev_ida);
+static bool is_bus_registered;

I wouldn't think init will be called more than once. Did you run into a problem where it did?

It's used to prevent bus device creation if bus_register function returns error.

Thanks
Hao

Quoted 34 lines
Quoted 34 lines
drivers/fpga/fpga-dev.c new file +33 -0
+
+static void fpga_dev_release(struct device *dev)
+{
+       struct fpga_dev *fdev = to_fpga_dev(dev);
+
+       ida_simple_remove(&fpga_dev_ida, fdev->dev.id);
+       kfree(fdev);
+}
+
+static const struct device_type fpga_dev_type = {
+       .name           = "fpga_dev",
+       .release        = fpga_dev_release,
+};
+
+static ssize_t name_show(struct device *dev,
+                        struct device_attribute *attr, char *buf)
+{
+       struct fpga_dev *fdev = to_fpga_dev(dev);
+
+       return sprintf(buf, "%s\n", fdev->name);
+}
+static DEVICE_ATTR_RO(name);
+
+static struct attribute *fpga_dev_attrs[] = {
+       &dev_attr_name.attr,
+       NULL,
+};
+ATTRIBUTE_GROUPS(fpga_dev);
+
+static struct bus_type fpga_bus_type = {
+       .name           = "fpga",
+};
+
Quoted 8 lines
Quoted 8 lines

drivers/fpga/fpga-dev.c

Quoted 8 lines
drivers/fpga/fpga-dev.c new file +8 -0
+/**
+ * fpga_dev_create - create a fpga device on fpga bus
+ * @parent: parent device
+ * @name: fpga bus device name
+ *
+ * Return fpga_dev struct for success, error code otherwise.
+ */
+struct fpga_dev *fpga_dev_create(struct device *parent, const char

*name)

Quoted 99 lines
Quoted 32 lines
Quoted 32 lines
drivers/fpga/fpga-dev.c new file +32 -0
+{
+       struct fpga_dev *fdev;
+       int id, ret = 0;
+
+       if (WARN_ON(!is_bus_registered))
+               return ERR_PTR(-ENODEV);
+
+       if (!name || !strlen(name)) {
+               dev_err(parent, "Attempt to register with no name!\n");
+               return ERR_PTR(-EINVAL);
+       }
+
+       fdev = kzalloc(sizeof(*fdev), GFP_KERNEL);
+       if (!fdev)
+               return ERR_PTR(-ENOMEM);
+
+       id = ida_simple_get(&fpga_dev_ida, 0, 0, GFP_KERNEL);
+       if (id < 0) {
+               ret = id;
+               goto error_kfree;
+       }
+
+       fdev->name = name;
+
+       device_initialize(&fdev->dev);
+       fdev->dev.type = &fpga_dev_type;
+       fdev->dev.bus = &fpga_bus_type;
+       fdev->dev.groups = fpga_dev_groups;
+       fdev->dev.parent = parent;
+       fdev->dev.id = id;
+
+       ret = dev_set_name(&fdev->dev, "fpga.%d", id);
Quoted 8 lines

drivers/fpga/fpga-dev.c

Quoted 8 lines
drivers/fpga/fpga-dev.c new file +8 -0
+       if (ret)
+               goto error_device;
+
+       ret = device_add(&fdev->dev);
+       if (ret)
+               goto error_device;
+
+       dev_dbg(fdev->dev.parent, "fpga bus device [%s] created\n", fdev-

name);

Quoted 58 lines
Quoted 58 lines
drivers/fpga/fpga-dev.c new file +36 -0
+
+       return fdev;
+
+error_device:
+       ida_simple_remove(&fpga_dev_ida, id);
+error_kfree:
+       kfree(fdev);
+
+       return ERR_PTR(ret);
+}
+EXPORT_SYMBOL_GPL(fpga_dev_create);
+
+static int __init fpga_bus_init(void)
+{
+       int ret;
+
+       pr_info("FPGA Bus Device Framework\n");
+
+       ret = bus_register(&fpga_bus_type);
+       if (ret)
+               return ret;
+
+       is_bus_registered = true;
+       return 0;
+}
+
+static void __exit fpga_bus_exit(void)
+{
+       bus_unregister(&fpga_bus_type);
+}
+
+MODULE_DESCRIPTION("FPGA Bus Device Framework");
+MODULE_LICENSE("GPL v2");
+
+subsys_initcall(fpga_bus_init);
+module_exit(fpga_bus_exit);
include/linux/fpga/fpga-dev.h new file +16 -0
new file mode 100644
index 0000000..7f6deb4
@@ -0,0 +1,31 @@
+/*
+ * FPGA Bus Device Framework driver Header
+ *
+ * Copyright (C) 2017 Intel Corporation, Inc.
+ *
+ * This work is licensed under the terms of the GNU GPL version 2. See
+ * the COPYING file in the top-level directory.
+ */
+#ifndef _LINUX_FPGA_DEV_H
+#define _LINUX_FPGA_DEV_H
+
+/**
+ * struct fpga_dev - fpga bus device structure
+ * @name: name of fpga bus device
+ * @dev: fpga bus device
+ */
Quoted 8 lines
Quoted 8 lines

include/linux/fpga/fpga-dev.h

Quoted 8 lines
include/linux/fpga/fpga-dev.h new file +8 -0
+struct fpga_dev {
+       const char *name;
+       struct device dev;
+};
+
+#define to_fpga_dev(d) container_of(d, struct fpga_dev, dev)
+
+struct fpga_dev *fpga_dev_create(struct device *parent, const char

*name);

Quoted 18 lines
Quoted 6 lines
Quoted 6 lines
include/linux/fpga/fpga-dev.h new file +6 -0
+
+static inline void fpga_dev_destroy(struct fpga_dev *fdev)
+{
+       device_unregister(&fdev->dev);
+}
+
Quoted 8 lines
Quoted 4 lines
include/linux/fpga/fpga-dev.h new file +1 -1
+#endif
--

1.8.3.1

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

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

#5 lore raw
Quoted 69 lines · Hao
Quoted 50 lines · Wu Hao
Quoted 22 lines · Alan Tull
Quoted 21 lines · Wu Hao
Quoted 9 lines

This patch is a RFC patch which replaces the patch[1] which creates 'fpga-dev' class as container device. It introduces a 'fpga' bus type, and provides interfaces to create/destroy fpga bus devices. This fpga bus device only could be used as a container device, and no drivers needed for it.

There is no interface change, so this patch could be used together with other patches of the original patch set[2].

I am wondering whether this could be added to fpga-bridge.c so that fpga-bridge becomes the fpga bus and fpga bus devices are under it. The reasons for doing this are discussed in the other thread.

Quoted 5 lines

This following APIs are provided by FPGA Bus device framework:
* fpga_dev_create
Create fpga bus device under the given parent device.
* fpga_dev_destroy
Destroy fpga bus device

Quoted 8 lines
Quoted 3 lines

This is being used in such that each fpga-dev is a container for platform devices rather than fpga devices. That's not what I was expecting. :)

Hi Alan

So does that mean in Intel FPGA PCIe driver, it needs to create a fpga-bridge (as base bridge?),

Yes

Quoted 3 lines

and this fpga-bridge should register
a fpga-bus and have a fpga bus device as its child, after that we can use this fpga bus device as container device,

Could the bus code be added to fpga-bridge? Then the base bridge is the container device. A fpga-region would be under that and the AFU and FME fpga devices would be under it.

Quoted 2 lines

and create sub feature
devices (e.g AFU and FME platform device)

We're talking about adding a new bus to the kernel here, not platform bus.

Quoted 2 lines

under it, and user application
could locate it in /sys/bus/fpga/devices/. Is my understanding correct? :)

Quoted 8 lines

So sysfs may end up something like this in your case:

/sys/bus/fpga/devices/fpga.0/intel-fpga-fme.0
/sys/bus/fpga/devices/fpga.0/intel-fpga-port.0
/sys/bus/fpga/devices/fpga.0/intel-fpga-port.1
/sys/bus/fpga/devices/fpga.0/fpga-mgr0
/sys/bus/fpga/devices/fpga.0/fpga-br1
/sys/bus/fpga/devices/fpga.0/fpga-br2

Hi Alan

I am a little confused on this.

It seems that we could not have multiple fpga-br/region/mgr under one device. As in patch set2, intel-fpga-fme.0 creates platform devices as children, and register fpga-bridges/regions/mgr under these children platform devices. This is why 3 new platform device driver introduced in this patch set 2 to match with those new created children platform devices.

Quoted 7 lines

So it is something like this /sys/bus/fpga/devices/fpga.0/intel-fpga-fme.0/intel-fpga-fme-region.0/fpga_region/region0 /sys/bus/fpga/devices/fpga.0/intel-fpga-fme.0/intel-fpga-fme-region.1/fpga_region/region1 /sys/bus/fpga/devices/fpga.0/intel-fpga-fme.0/intel-fpga-fme-br.0/fpga_bridge/br1 /sys/bus/fpga/devices/fpga.0/intel-fpga-fme.0/intel-fpga-fme-br.1/fpga_region/br2 /sys/bus/fpga/devices/fpga.1
/sys/bus/fpga/devices/fpga.2

Hi Hao,

OK I see that now. Because the regions, mgr, and bridges are all children of the fme's.

Quoted 28 lines

br0 should be the base bridge. fpga.1 and 2 are the child fpga bus device of fpga bridge.

Quoted 25 lines

/sys/bus/fpga/devices/fpga.1/fpga-region1
/sys/bus/fpga/devices/fpga.2/fpga-region2

/sys/bus/fpga/devices/fpga.3/intel-fpga-fme.1
/sys/bus/fpga/devices/fpga.3/intel-fpga-port.2
/sys/bus/fpga/devices/fpga.3/intel-fpga-port.3
/sys/bus/fpga/devices/fpga.0/fpga-mgr1
/sys/bus/fpga/devices/fpga.3/fpga-br4
/sys/bus/fpga/devices/fpga.3/fpga-br5

/sys/bus/fpga/devices/fpga.4/fpga-region4
/sys/bus/fpga/devices/fpga.5/fpga-region5

fpga-br0 and 3 are base bridges (on top of PCIe) which show up as fpga.0 and 3. Regions 0 and 3 are base regions.

fpga.0 and fpga.3 correspond to the real FPGA devices.

Quoted 5 lines

And if we have second level fpga-bridge for PR regions, then they should register fpga-bus and fpga bus type device as child too? If yes, then we need a method for user application to distinguish which one represents the FPGA device in /sys/bus/fpga/devices/, right?

Quoted 7 lines
Quoted 2 lines

To find a bus that is a fpga, userspace only needs to look for busses that have an FME (or a mgr).

Do you mean that check all fpga-dev.x folder to see if anyone has FME?

Then it is still not friendly to user space, as we may have a lot of bridges (and regions) on one system.

It doesn't sound too hard for userspace code to go through sysfs once and find the FME's.

Quoted 6 lines

And looks like no big difference that we reuse base fpga-region as container. Search all regionx in /sys/class/fpga_region/ to see if anyone has a FME.

How do you think? : )

Yes, looking for /sys/class/fpga_region/region*/device/intel-fpga-fme.* That's not so bad, right? :)

Then the fpga-dev stuff can go away and we can stop worrying about all the issues involved in implementing a fpga bus or class.

Alan

Quoted 12 lines

Hao

Quoted 9 lines
Quoted 3 lines

It seems to be a similar case that we see a lot of regions in /sys/class/fpga_region/ but not sure which one is the base region. :)

I understand that the goal of fpga-dev was to describe the topology (which is the function of a bus, not a class as Rob explained). To be honest, I'm still pondering the implications of adding a fpga bus.

Alan

author
#6 lore raw
Quoted 135 lines · Hao
Quoted 59 lines
Quoted 50 lines · Wu Hao
Quoted 22 lines · Alan Tull
Quoted 21 lines · Wu Hao
Quoted 9 lines

This patch is a RFC patch which replaces the patch[1] which creates 'fpga-dev' class as container device. It introduces a 'fpga' bus type, and provides interfaces to create/destroy fpga bus devices. This fpga bus device only could be used as a container device, and no drivers needed for it.

There is no interface change, so this patch could be used together with other patches of the original patch set[2].

I am wondering whether this could be added to fpga-bridge.c so that fpga-bridge becomes the fpga bus and fpga bus devices are under it. The reasons for doing this are discussed in the other thread.

Quoted 5 lines

This following APIs are provided by FPGA Bus device framework:
* fpga_dev_create
Create fpga bus device under the given parent device.
* fpga_dev_destroy
Destroy fpga bus device

Quoted 8 lines
Quoted 3 lines

This is being used in such that each fpga-dev is a container for platform devices rather than fpga devices. That's not what I was expecting. :)

Hi Alan

So does that mean in Intel FPGA PCIe driver, it needs to create a fpga-bridge (as base bridge?),

Yes

Quoted 3 lines

and this fpga-bridge should register
a fpga-bus and have a fpga bus device as its child, after that we can use this fpga bus device as container device,

Could the bus code be added to fpga-bridge? Then the base bridge is the container device. A fpga-region would be under that and the AFU and FME fpga devices would be under it.

Quoted 2 lines

and create sub feature
devices (e.g AFU and FME platform device)

We're talking about adding a new bus to the kernel here, not platform bus.

Quoted 2 lines

under it, and user application
could locate it in /sys/bus/fpga/devices/. Is my understanding correct? :)

Quoted 8 lines

So sysfs may end up something like this in your case:

/sys/bus/fpga/devices/fpga.0/intel-fpga-fme.0
/sys/bus/fpga/devices/fpga.0/intel-fpga-port.0
/sys/bus/fpga/devices/fpga.0/intel-fpga-port.1
/sys/bus/fpga/devices/fpga.0/fpga-mgr0
/sys/bus/fpga/devices/fpga.0/fpga-br1
/sys/bus/fpga/devices/fpga.0/fpga-br2

Quoted 6 lines

Hi Alan

I am a little confused on this.

It seems that we could not have multiple fpga-br/region/mgr under one device. As in patch set2, intel-fpga-fme.0 creates platform devices as children, and

register

Quoted 1 line

fpga-bridges/regions/mgr under these children platform devices. This is why 3

new

Quoted 1 line

platform device driver introduced in this patch set 2 to match with those new

created

Quoted 4 lines

children platform devices.

So it is something like this /sys/bus/fpga/devices/fpga.0/intel-fpga-fme.0/intel-fpga-fme-

region.0/fpga_region/region0

Quoted 1 line

/sys/bus/fpga/devices/fpga.0/intel-fpga-fme.0/intel-fpga-fme-

region.1/fpga_region/region1

Quoted 1 line

/sys/bus/fpga/devices/fpga.0/intel-fpga-fme.0/intel-fpga-fme-

br.0/fpga_bridge/br1

Quoted 1 line

/sys/bus/fpga/devices/fpga.0/intel-fpga-fme.0/intel-fpga-fme-

br.1/fpga_region/br2

Quoted 2 lines

/sys/bus/fpga/devices/fpga.1
/sys/bus/fpga/devices/fpga.2

Hi Hao,

OK I see that now. Because the regions, mgr, and bridges are all children of the fme's.

Quoted 2 lines

br0 should be the base bridge. fpga.1 and 2 are the child fpga bus device of

fpga bridge.

Quoted 26 lines
Quoted 26 lines

/sys/bus/fpga/devices/fpga.1/fpga-region1
/sys/bus/fpga/devices/fpga.2/fpga-region2

/sys/bus/fpga/devices/fpga.3/intel-fpga-fme.1
/sys/bus/fpga/devices/fpga.3/intel-fpga-port.2
/sys/bus/fpga/devices/fpga.3/intel-fpga-port.3
/sys/bus/fpga/devices/fpga.0/fpga-mgr1
/sys/bus/fpga/devices/fpga.3/fpga-br4
/sys/bus/fpga/devices/fpga.3/fpga-br5

/sys/bus/fpga/devices/fpga.4/fpga-region4
/sys/bus/fpga/devices/fpga.5/fpga-region5

fpga-br0 and 3 are base bridges (on top of PCIe) which show up as fpga.0 and 3. Regions 0 and 3 are base regions.

fpga.0 and fpga.3 correspond to the real FPGA devices.

Quoted 5 lines

And if we have second level fpga-bridge for PR regions, then they should register fpga-bus and fpga bus type device as child too? If yes, then we need a method for user application to distinguish which one represents the FPGA device in /sys/bus/fpga/devices/, right?

Quoted 7 lines
Quoted 2 lines

To find a bus that is a fpga, userspace only needs to look for busses that have an FME (or a mgr).

Do you mean that check all fpga-dev.x folder to see if anyone has FME?

Then it is still not friendly to user space, as we may have a lot of bridges (and regions) on one system.

It doesn't sound too hard for userspace code to go through sysfs once and find the FME's.

Quoted 5 lines

And looks like no big difference that we reuse base fpga-region as container. Search all regionx in /sys/class/fpga_region/ to see if anyone has a FME.

Quoted 8 lines
Quoted 1 line

How do you think? : )

Yes, looking for /sys/class/fpga_region/region*/device/intel-fpga-fme.* That's not so bad, right? :)

Then the fpga-dev stuff can go away and we can stop worrying about all the issues involved in implementing a fpga bus or class.

Hi Alan

Thanks for your feedback.

I think the only concern here is I'm not sure if we will have some fpga devices with a large number fpga regions (e.g 100+) in the future. If there are many regions in the system, then the enduser / application needs to search all the regions one by one, which seems not perfect.

Hao

Quoted 15 lines

Alan

Quoted 12 lines

Hao

Quoted 9 lines
Quoted 3 lines

It seems to be a similar case that we see a lot of regions in /sys/class/fpga_region/ but not sure which one is the base region. :)

I understand that the goal of fpga-dev was to describe the topology (which is the function of a bus, not a class as Rob explained). To be honest, I'm still pondering the implications of adding a fpga bus.

Alan

#7 lore raw
Quoted 144 lines · Hao
Quoted 135 lines · Hao
Quoted 59 lines
Quoted 50 lines · Wu Hao
Quoted 22 lines · Alan Tull
Quoted 21 lines · Wu Hao
Quoted 9 lines

This patch is a RFC patch which replaces the patch[1] which creates 'fpga-dev' class as container device. It introduces a 'fpga' bus type, and provides interfaces to create/destroy fpga bus devices. This fpga bus device only could be used as a container device, and no drivers needed for it.

There is no interface change, so this patch could be used together with other patches of the original patch set[2].

I am wondering whether this could be added to fpga-bridge.c so that fpga-bridge becomes the fpga bus and fpga bus devices are under it. The reasons for doing this are discussed in the other thread.

Quoted 5 lines

This following APIs are provided by FPGA Bus device framework:
* fpga_dev_create
Create fpga bus device under the given parent device.
* fpga_dev_destroy
Destroy fpga bus device

Quoted 8 lines
Quoted 3 lines

This is being used in such that each fpga-dev is a container for platform devices rather than fpga devices. That's not what I was expecting. :)

Hi Alan

So does that mean in Intel FPGA PCIe driver, it needs to create a fpga-bridge (as base bridge?),

Yes

Quoted 3 lines

and this fpga-bridge should register
a fpga-bus and have a fpga bus device as its child, after that we can use this fpga bus device as container device,

Could the bus code be added to fpga-bridge? Then the base bridge is the container device. A fpga-region would be under that and the AFU and FME fpga devices would be under it.

Quoted 2 lines

and create sub feature
devices (e.g AFU and FME platform device)

We're talking about adding a new bus to the kernel here, not platform bus.

Quoted 2 lines

under it, and user application
could locate it in /sys/bus/fpga/devices/. Is my understanding correct? :)

Quoted 8 lines

So sysfs may end up something like this in your case:

/sys/bus/fpga/devices/fpga.0/intel-fpga-fme.0
/sys/bus/fpga/devices/fpga.0/intel-fpga-port.0
/sys/bus/fpga/devices/fpga.0/intel-fpga-port.1
/sys/bus/fpga/devices/fpga.0/fpga-mgr0
/sys/bus/fpga/devices/fpga.0/fpga-br1
/sys/bus/fpga/devices/fpga.0/fpga-br2

Quoted 6 lines

Hi Alan

I am a little confused on this.

It seems that we could not have multiple fpga-br/region/mgr under one device. As in patch set2, intel-fpga-fme.0 creates platform devices as children, and

register

Quoted 1 line

fpga-bridges/regions/mgr under these children platform devices. This is why 3

new

Quoted 1 line

platform device driver introduced in this patch set 2 to match with those new

created

Quoted 4 lines

children platform devices.

So it is something like this /sys/bus/fpga/devices/fpga.0/intel-fpga-fme.0/intel-fpga-fme-

region.0/fpga_region/region0

Quoted 1 line

/sys/bus/fpga/devices/fpga.0/intel-fpga-fme.0/intel-fpga-fme-

region.1/fpga_region/region1

Quoted 1 line

/sys/bus/fpga/devices/fpga.0/intel-fpga-fme.0/intel-fpga-fme-

br.0/fpga_bridge/br1

Quoted 1 line

/sys/bus/fpga/devices/fpga.0/intel-fpga-fme.0/intel-fpga-fme-

br.1/fpga_region/br2

Quoted 2 lines

/sys/bus/fpga/devices/fpga.1
/sys/bus/fpga/devices/fpga.2

Hi Hao,

OK I see that now. Because the regions, mgr, and bridges are all children of the fme's.

Quoted 2 lines

br0 should be the base bridge. fpga.1 and 2 are the child fpga bus device of

fpga bridge.

Quoted 26 lines
Quoted 26 lines

/sys/bus/fpga/devices/fpga.1/fpga-region1
/sys/bus/fpga/devices/fpga.2/fpga-region2

/sys/bus/fpga/devices/fpga.3/intel-fpga-fme.1
/sys/bus/fpga/devices/fpga.3/intel-fpga-port.2
/sys/bus/fpga/devices/fpga.3/intel-fpga-port.3
/sys/bus/fpga/devices/fpga.0/fpga-mgr1
/sys/bus/fpga/devices/fpga.3/fpga-br4
/sys/bus/fpga/devices/fpga.3/fpga-br5

/sys/bus/fpga/devices/fpga.4/fpga-region4
/sys/bus/fpga/devices/fpga.5/fpga-region5

fpga-br0 and 3 are base bridges (on top of PCIe) which show up as fpga.0 and 3. Regions 0 and 3 are base regions.

fpga.0 and fpga.3 correspond to the real FPGA devices.

Quoted 5 lines

And if we have second level fpga-bridge for PR regions, then they should register fpga-bus and fpga bus type device as child too? If yes, then we need a method for user application to distinguish which one represents the FPGA device in /sys/bus/fpga/devices/, right?

Quoted 7 lines
Quoted 2 lines

To find a bus that is a fpga, userspace only needs to look for busses that have an FME (or a mgr).

Do you mean that check all fpga-dev.x folder to see if anyone has FME?

Then it is still not friendly to user space, as we may have a lot of bridges (and regions) on one system.

It doesn't sound too hard for userspace code to go through sysfs once and find the FME's.

Quoted 5 lines

And looks like no big difference that we reuse base fpga-region as container. Search all regionx in /sys/class/fpga_region/ to see if anyone has a FME.

Quoted 8 lines
Quoted 1 line

How do you think? : )

Yes, looking for /sys/class/fpga_region/region*/device/intel-fpga-fme.* That's not so bad, right? :)

Then the fpga-dev stuff can go away and we can stop worrying about all the issues involved in implementing a fpga bus or class.

Quoted 8 lines

Hi Alan

Thanks for your feedback.

I think the only concern here is I'm not sure if we will have some fpga devices with a large number fpga regions (e.g 100+) in the future. If there are many regions in the system, then the enduser / application needs to search all the regions one by one, which seems not perfect.

Well your library could do so, I suppose a clever libudev enumerate could work, too, I suppose.

Cheers,

Moritz

author
#8 lore raw
Quoted 152 lines · Hao
Quoted 60 lines
Quoted 60 lines · Hao
Quoted 59 lines
Quoted 58 lines · Wu Hao
Quoted 22 lines · Alan Tull
Quoted 21 lines · Wu Hao
Quoted 9 lines

This patch is a RFC patch which replaces the patch[1] which creates 'fpga-dev' class as container device. It introduces a 'fpga' bus type, and provides interfaces to create/destroy fpga bus devices. This fpga bus device only could be used as a container device, and no drivers needed for it.

There is no interface change, so this patch could be used together with other patches of the original patch set[2].

I am wondering whether this could be added to fpga-bridge.c so that fpga-bridge becomes the fpga bus and fpga bus devices are under it. The reasons for doing this are discussed in the other thread.

Quoted 5 lines

This following APIs are provided by FPGA Bus device framework:
* fpga_dev_create
Create fpga bus device under the given parent device.
* fpga_dev_destroy
Destroy fpga bus device

Quoted 8 lines
Quoted 3 lines

This is being used in such that each fpga-dev is a container for platform devices rather than fpga devices. That's not what I was expecting. :)

Hi Alan

So does that mean in Intel FPGA PCIe driver, it needs to create a fpga-bridge (as base bridge?),

Yes

Quoted 3 lines

and this fpga-bridge should register
a fpga-bus and have a fpga bus device as its child, after that we can use this fpga bus device as container device,

Could the bus code be added to fpga-bridge? Then the base bridge is the container device. A fpga-region would be under that and the AFU and FME fpga devices would be under it.

Quoted 2 lines

and create sub feature
devices (e.g AFU and FME platform device)

We're talking about adding a new bus to the kernel here, not platform bus.

Quoted 2 lines

under it, and user application
could locate it in /sys/bus/fpga/devices/. Is my understanding correct? :)

So sysfs may end up something like this in your case:

/sys/bus/fpga/devices/fpga.0/intel-fpga-fme.0
/sys/bus/fpga/devices/fpga.0/intel-fpga-port.0
/sys/bus/fpga/devices/fpga.0/intel-fpga-port.1
/sys/bus/fpga/devices/fpga.0/fpga-mgr0
/sys/bus/fpga/devices/fpga.0/fpga-br1
/sys/bus/fpga/devices/fpga.0/fpga-br2

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Hi Alan

I am a little confused on this.

It seems that we could not have multiple fpga-br/region/mgr under one

device.

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

As in patch set2, intel-fpga-fme.0 creates platform devices as children, and

register

Quoted 1 line

fpga-bridges/regions/mgr under these children platform devices. This is

why 3

Quoted 2 lines
Quoted 2 lines

new

Quoted 1 line

platform device driver introduced in this patch set 2 to match with those

new

Quoted 78 lines
Quoted 65 lines

created

Quoted 4 lines

children platform devices.

So it is something like this /sys/bus/fpga/devices/fpga.0/intel-fpga-fme.0/intel-fpga-fme-

region.0/fpga_region/region0

Quoted 1 line

/sys/bus/fpga/devices/fpga.0/intel-fpga-fme.0/intel-fpga-fme-

region.1/fpga_region/region1

Quoted 1 line

/sys/bus/fpga/devices/fpga.0/intel-fpga-fme.0/intel-fpga-fme-

br.0/fpga_bridge/br1

Quoted 1 line

/sys/bus/fpga/devices/fpga.0/intel-fpga-fme.0/intel-fpga-fme-

br.1/fpga_region/br2

Quoted 2 lines

/sys/bus/fpga/devices/fpga.1
/sys/bus/fpga/devices/fpga.2

Hi Hao,

OK I see that now. Because the regions, mgr, and bridges are all children of the fme's.

Quoted 2 lines

br0 should be the base bridge. fpga.1 and 2 are the child fpga bus device of

fpga bridge.

Quoted 26 lines
Quoted 26 lines

/sys/bus/fpga/devices/fpga.1/fpga-region1
/sys/bus/fpga/devices/fpga.2/fpga-region2

/sys/bus/fpga/devices/fpga.3/intel-fpga-fme.1
/sys/bus/fpga/devices/fpga.3/intel-fpga-port.2
/sys/bus/fpga/devices/fpga.3/intel-fpga-port.3
/sys/bus/fpga/devices/fpga.0/fpga-mgr1
/sys/bus/fpga/devices/fpga.3/fpga-br4
/sys/bus/fpga/devices/fpga.3/fpga-br5

/sys/bus/fpga/devices/fpga.4/fpga-region4
/sys/bus/fpga/devices/fpga.5/fpga-region5

fpga-br0 and 3 are base bridges (on top of PCIe) which show up as fpga.0 and 3. Regions 0 and 3 are base regions.

fpga.0 and fpga.3 correspond to the real FPGA devices.

Quoted 5 lines

And if we have second level fpga-bridge for PR regions, then they should register fpga-bus and fpga bus type device as child too? If yes, then we need a method for user application to distinguish which one represents the FPGA device in /sys/bus/fpga/devices/, right?

Quoted 7 lines
Quoted 2 lines

To find a bus that is a fpga, userspace only needs to look for busses that have an FME (or a mgr).

Do you mean that check all fpga-dev.x folder to see if anyone has FME?

Then it is still not friendly to user space, as we may have a lot of bridges (and regions) on one system.

It doesn't sound too hard for userspace code to go through sysfs once and find the FME's.

Quoted 5 lines

And looks like no big difference that we reuse base fpga-region as container. Search all regionx in /sys/class/fpga_region/ to see if anyone has a FME.

Quoted 8 lines
Quoted 1 line

How do you think? : )

Yes, looking for /sys/class/fpga_region/region*/device/intel-fpga-fme.* That's not so bad, right? :)

Then the fpga-dev stuff can go away and we can stop worrying about all the issues involved in implementing a fpga bus or class.

Hi Alan

Thanks for your feedback.

Quoted 7 lines
Quoted 4 lines

I think the only concern here is I'm not sure if we will have some fpga devices with a large number fpga regions (e.g 100+) in the future. If there are many regions in the system, then the enduser / application needs to search all the regions one by one, which seems not perfect.

Well your library could do so, I suppose a clever libudev enumerate could work, too, I suppose.

Yes, agree, adding some code in user space library should be able to cover this. : ) Thanks for your suggestion.

Hao

Quoted 4 lines

Cheers,

Moritz