Skip to content

Commit 8249f8b

Browse files
yilunxu1984matthew-gerlach
authored andcommitted
uio: uio_dfl: add userspace i/o driver for DFL bus
This patch supports the DFL drivers be written in userspace. This is realized by exposing the userspace I/O device interfaces. The driver now only binds the ether group feature, which has no irq. So the irq support is not implemented yet. Signed-off-by: Xu Yilun <yilun.xu@intel.com> Reviewed-by: Tom Rix <trix@redhat.com>
1 parent 537becc commit 8249f8b

4 files changed

Lines changed: 85 additions & 0 deletions

File tree

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6895,6 +6895,7 @@ S: Maintained
68956895
F: Documentation/ABI/testing/sysfs-bus-dfl*
68966896
F: Documentation/fpga/dfl.rst
68976897
F: drivers/fpga/dfl*
6898+
F: drivers/uio/uio_dfl.c
68986899
F: include/linux/dfl.h
68996900
F: include/uapi/linux/fpga-dfl.h
69006901

drivers/uio/Kconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,21 @@ config UIO_HV_GENERIC
165165
to network and storage devices from userspace.
166166

167167
If you compile this as a module, it will be called uio_hv_generic.
168+
169+
config UIO_DFL
170+
tristate "Generic driver for DFL (Device Feature List) bus"
171+
depends on FPGA_DFL
172+
help
173+
Generic DFL (Device Feature List) driver for Userspace I/O devices.
174+
It is useful to provide direct access to DFL devices from userspace.
175+
A sample userspace application using this driver is available for
176+
download in a git repository:
177+
178+
git clone https://github.com/OPAE/opae-sdk.git
179+
180+
It could be found at:
181+
182+
opae-sdk/tools/libopaeuio/
183+
184+
If you compile this as a module, it will be called uio_dfl.
168185
endif

drivers/uio/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ obj-$(CONFIG_UIO_PRUSS) += uio_pruss.o
1111
obj-$(CONFIG_UIO_MF624) += uio_mf624.o
1212
obj-$(CONFIG_UIO_FSL_ELBC_GPCM) += uio_fsl_elbc_gpcm.o
1313
obj-$(CONFIG_UIO_HV_GENERIC) += uio_hv_generic.o
14+
obj-$(CONFIG_UIO_DFL) += uio_dfl.o

drivers/uio/uio_dfl.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Generic DFL driver for Userspace I/O devicess
4+
*
5+
* Copyright (C) 2021 Intel Corporation, Inc.
6+
*/
7+
#include <linux/dfl.h>
8+
#include <linux/errno.h>
9+
#include <linux/module.h>
10+
#include <linux/uio_driver.h>
11+
12+
#define DRIVER_NAME "uio_dfl"
13+
14+
static int uio_dfl_probe(struct dfl_device *ddev)
15+
{
16+
struct resource *r = &ddev->mmio_res;
17+
struct device *dev = &ddev->dev;
18+
struct uio_info *uioinfo;
19+
struct uio_mem *uiomem;
20+
int ret;
21+
22+
uioinfo = devm_kzalloc(dev, sizeof(struct uio_info), GFP_KERNEL);
23+
if (!uioinfo)
24+
return -ENOMEM;
25+
26+
uioinfo->name = DRIVER_NAME;
27+
uioinfo->version = "0";
28+
29+
uiomem = &uioinfo->mem[0];
30+
uiomem->memtype = UIO_MEM_PHYS;
31+
uiomem->addr = r->start & PAGE_MASK;
32+
uiomem->offs = r->start & ~PAGE_MASK;
33+
uiomem->size = (uiomem->offs + resource_size(r)
34+
+ PAGE_SIZE - 1) & PAGE_MASK;
35+
uiomem->name = r->name;
36+
37+
/* Irq is yet to be supported */
38+
uioinfo->irq = UIO_IRQ_NONE;
39+
40+
ret = devm_uio_register_device(dev, uioinfo);
41+
if (ret)
42+
dev_err(dev, "unable to register uio device\n");
43+
44+
return ret;
45+
}
46+
47+
#define FME_FEATURE_ID_ETH_GROUP 0x10
48+
49+
static const struct dfl_device_id uio_dfl_ids[] = {
50+
{ FME_ID, FME_FEATURE_ID_ETH_GROUP },
51+
{ }
52+
};
53+
MODULE_DEVICE_TABLE(dfl, uio_dfl_ids);
54+
55+
static struct dfl_driver uio_dfl_driver = {
56+
.drv = {
57+
.name = DRIVER_NAME,
58+
},
59+
.id_table = uio_dfl_ids,
60+
.probe = uio_dfl_probe,
61+
};
62+
module_dfl_driver(uio_dfl_driver);
63+
64+
MODULE_DESCRIPTION("Generic DFL driver for Userspace I/O devices");
65+
MODULE_AUTHOR("Intel Corporation");
66+
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)