@@ -203,6 +203,16 @@ config FPGA_DFL_NIOS_INTEL_PAC_N3000
the card. It also instantiates the SPI master (spi-altera) for
the card's BMC (Board Management Controller).
+config FPGA_DFL_UIO_PDEV
+ tristate "FPGA DFL Driver for Userspace I/O platform devices"
+ depends on FPGA_DFL && UIO_PDRV_GENIRQ
+ help
+ Enable this to allow DFL drivers to be written in userspace. It
+ adds the uio_pdrv_genirq platform device with the DFL feature's
+ resources, and lets the generic UIO platform device driver provide
+ support for userspace access to kernel interrupts and memory
+ locations.
+
config FPGA_DFL_PCI
tristate "FPGA DFL PCIe Device Driver"
depends on PCI && FPGA_DFL
@@ -45,6 +45,7 @@ dfl-afu-objs := dfl-afu-main.o dfl-afu-region.o dfl-afu-dma-region.o
dfl-afu-objs += dfl-afu-error.o
obj-$(CONFIG_FPGA_DFL_NIOS_INTEL_PAC_N3000) += dfl-n3000-nios.o
+obj-$(CONFIG_FPGA_DFL_UIO_PDEV) += dfl-uio-pdev.o
# Drivers for FPGAs which implement DFL
obj-$(CONFIG_FPGA_DFL_PCI) += dfl-pci.o
new file mode 100644
@@ -0,0 +1,84 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * DFL driver for Userspace I/O platform devices
+ *
+ * Copyright (C) 2020 Intel Corporation, Inc.
+ */
+#include <linux/dfl.h>
+#include <linux/errno.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/uio_driver.h>
+
+#define DRIVER_NAME "dfl-uio-pdev"
+
+static int dfl_uio_pdev_probe(struct dfl_device *ddev)
+{
+ struct resource res[2] = { { 0 } };
+ struct uio_info uio_pdata = { 0 };
+ struct platform_device *uio_pdev;
+ struct device *dev = &ddev->dev;
+ unsigned int num_res = 1;
+
+ res[0].parent = &ddev->mmio_res;
+ res[0].flags = IORESOURCE_MEM;
+ res[0].start = ddev->mmio_res.start;
+ res[0].end = ddev->mmio_res.end;
+
+ if (ddev->num_irqs) {
+ if (ddev->num_irqs > 1)
+ dev_warn(dev,
+ "%d irqs for %s, but UIO only supports the first one\n",
+ ddev->num_irqs, dev_name(dev));
+
+ res[1].flags = IORESOURCE_IRQ;
+ res[1].start = ddev->irqs[0];
+ res[1].end = ddev->irqs[0];
+ num_res++;
+ }
+
+ uio_pdata.name = DRIVER_NAME;
+ uio_pdata.version = "0";
+
+ uio_pdev = platform_device_register_resndata(dev,
+ "uio_pdrv_genirq",
+ PLATFORM_DEVID_AUTO,
+ res, num_res,
+ &uio_pdata,
+ sizeof(uio_pdata));
+ if (IS_ERR(uio_pdev))
+ return PTR_ERR(uio_pdev);
+
+ dev_set_drvdata(dev, uio_pdev);
+
+ return 0;
+}
+
+static void dfl_uio_pdev_remove(struct dfl_device *ddev)
+{
+ struct platform_device *uio_pdev = dev_get_drvdata(&ddev->dev);
+
+ platform_device_unregister(uio_pdev);
+}
+
+#define FME_FEATURE_ID_ETH_GROUP 0x10
+
+static const struct dfl_device_id dfl_uio_pdev_ids[] = {
+ { FME_ID, FME_FEATURE_ID_ETH_GROUP },
+ { }
+};
+MODULE_DEVICE_TABLE(dfl, dfl_uio_pdev_ids);
+
+static struct dfl_driver dfl_uio_pdev_driver = {
+ .drv = {
+ .name = DRIVER_NAME,
+ },
+ .id_table = dfl_uio_pdev_ids,
+ .probe = dfl_uio_pdev_probe,
+ .remove = dfl_uio_pdev_remove,
+};
+module_dfl_driver(dfl_uio_pdev_driver);
+
+MODULE_DESCRIPTION("DFL driver for Userspace I/O platform devices");
+MODULE_AUTHOR("Intel Corporation");
+MODULE_LICENSE("GPL v2");