summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorOlivier Matz <olivier.matz@6wind.com>2014-01-24 16:31:26 +0100
committerThomas Monjalon <thomas.monjalon@6wind.com>2014-01-28 16:32:58 +0100
commit43f1788266c13e83c1412a03dcec1b5245f3bedb (patch)
treeb39a84bcad306b8abaf8e0956491685d9b4bcb94 /lib
parenta064e7b2d60a32a98525f85a69a4a9d52375bab6 (diff)
downloaddpdk-43f1788266c13e83c1412a03dcec1b5245f3bedb.zip
dpdk-43f1788266c13e83c1412a03dcec1b5245f3bedb.tar.gz
dpdk-43f1788266c13e83c1412a03dcec1b5245f3bedb.tar.xz
pci: split the function providing uio device and mappings
Add a new function pci_get_uio_dev() that parses /sys/bus/pci/devices to get the uio device associated with a PCI device. This patch just moves some code that was in pci_uio_map_resource() in the new function without any functional change. Thanks to this change, the next commit will be easier to understand. Moreover it improves readability: having smaller functions help to understand what pci_uio_map_resource() does. Signed-off-by: Olivier Matz <olivier.matz@6wind.com> Acked-by: Thomas Monjalon <thomas.monjalon@6wind.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/librte_eal/linuxapp/eal/eal_pci.c82
1 files changed, 50 insertions, 32 deletions
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index 37ee6f1..1039777 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -460,34 +460,20 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
return -1;
}
-/* map the PCI resource of a PCI device in virtual memory */
-static int
-pci_uio_map_resource(struct rte_pci_device *dev)
+/*
+ * Return the uioX char device used for a pci device. On success, return
+ * the UIO number and fill dstbuf string with the path of the device in
+ * sysfs. On error, return a negative value. In this case dstbuf is
+ * invalid.
+ */
+static int pci_get_uio_dev(struct rte_pci_device *dev, char *dstbuf,
+ unsigned int buflen)
{
- int i, j;
+ struct rte_pci_addr *loc = &dev->addr;
+ unsigned int uio_num;
struct dirent *e;
DIR *dir;
char dirname[PATH_MAX];
- char filename[PATH_MAX];
- char dirname2[PATH_MAX];
- char devname[PATH_MAX]; /* contains the /dev/uioX */
- void *mapaddr;
- unsigned uio_num;
- unsigned long start,size;
- uint64_t phaddr;
- uint64_t offset;
- uint64_t pagesz;
- ssize_t nb_maps;
- struct rte_pci_addr *loc = &dev->addr;
- struct uio_resource *uio_res;
- struct uio_map *maps;
-
- dev->intr_handle.fd = -1;
-
- /* secondary processes - use already recorded details */
- if ((rte_eal_process_type() != RTE_PROC_PRIMARY) &&
- (dev->id.vendor_id != PCI_VENDOR_ID_QUMRANET))
- return (pci_uio_map_secondary(dev));
/* depending on kernel version, uio can be located in uio/uioX
* or uio:uioX */
@@ -525,8 +511,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
errno = 0;
uio_num = strtoull(e->d_name + shortprefix_len, &endptr, 10);
if (errno == 0 && endptr != (e->d_name + shortprefix_len)) {
- rte_snprintf(dirname2, sizeof(dirname2),
- "%s/uio%u", dirname, uio_num);
+ rte_snprintf(dstbuf, buflen, "%s/uio%u", dirname, uio_num);
break;
}
@@ -534,15 +519,48 @@ pci_uio_map_resource(struct rte_pci_device *dev)
errno = 0;
uio_num = strtoull(e->d_name + longprefix_len, &endptr, 10);
if (errno == 0 && endptr != (e->d_name + longprefix_len)) {
- rte_snprintf(dirname2, sizeof(dirname2),
- "%s/uio:uio%u", dirname, uio_num);
+ rte_snprintf(dstbuf, buflen, "%s/uio:uio%u", dirname, uio_num);
break;
}
}
closedir(dir);
/* No uio resource found */
- if (e == NULL) {
+ if (e == NULL)
+ return -1;
+
+ return 0;
+}
+
+/* map the PCI resource of a PCI device in virtual memory */
+static int
+pci_uio_map_resource(struct rte_pci_device *dev)
+{
+ int i, j;
+ char dirname[PATH_MAX];
+ char filename[PATH_MAX];
+ char devname[PATH_MAX]; /* contains the /dev/uioX */
+ void *mapaddr;
+ int uio_num;
+ unsigned long start,size;
+ uint64_t phaddr;
+ uint64_t offset;
+ uint64_t pagesz;
+ ssize_t nb_maps;
+ struct rte_pci_addr *loc = &dev->addr;
+ struct uio_resource *uio_res;
+ struct uio_map *maps;
+
+ dev->intr_handle.fd = -1;
+
+ /* secondary processes - use already recorded details */
+ if ((rte_eal_process_type() != RTE_PROC_PRIMARY) &&
+ (dev->id.vendor_id != PCI_VENDOR_ID_QUMRANET))
+ return (pci_uio_map_secondary(dev));
+
+ /* find uio resource */
+ uio_num = pci_get_uio_dev(dev, dirname, sizeof(dirname));
+ if (uio_num < 0) {
RTE_LOG(WARNING, EAL, " "PCI_PRI_FMT" not managed by UIO driver, "
"skipping\n", loc->domain, loc->bus, loc->devid, loc->function);
return -1;
@@ -551,7 +569,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
if(dev->id.vendor_id == PCI_VENDOR_ID_QUMRANET) {
/* get portio size */
rte_snprintf(filename, sizeof(filename),
- "%s/portio/port0/size", dirname2);
+ "%s/portio/port0/size", dirname);
if (eal_parse_sysfs_value(filename, &size) < 0) {
RTE_LOG(ERR, EAL, "%s(): cannot parse size\n",
__func__);
@@ -560,7 +578,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
/* get portio start */
rte_snprintf(filename, sizeof(filename),
- "%s/portio/port0/start", dirname2);
+ "%s/portio/port0/start", dirname);
if (eal_parse_sysfs_value(filename, &start) < 0) {
RTE_LOG(ERR, EAL, "%s(): cannot parse portio start\n",
__func__);
@@ -585,7 +603,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
memcpy(&uio_res->pci_addr, &dev->addr, sizeof(uio_res->pci_addr));
/* collect info about device mappings */
- if ((nb_maps = pci_uio_get_mappings(dirname2, uio_res->maps,
+ if ((nb_maps = pci_uio_get_mappings(dirname, uio_res->maps,
sizeof (uio_res->maps) / sizeof (uio_res->maps[0])))
< 0)
return (nb_maps);