[dpdk-dev] [PATCH v2 5/7] eal/linux: mmap ioports on ppc64
David Marchand
david.marchand at 6wind.com
Tue May 17 17:54:01 CEST 2016
Hello Olivier,
On Tue, May 17, 2016 at 11:59 AM, Olivier Matz <olivier.matz at 6wind.com> wrote:
> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> index ac449c5..077ad96 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> @@ -411,81 +412,153 @@ pci_uio_ioport_map(struct rte_pci_device *dev, int bar,
> RTE_LOG(DEBUG, EAL, "PCI Port IO found start=0x%lx\n", start);
>
> p->base = start;
> + p->len = 0;
> return 0;
> +}
> #else
> - RTE_SET_USED(dev);
> - RTE_SET_USED(bar);
> - RTE_SET_USED(p);
> +int
> +pci_uio_ioport_map(struct rte_pci_device *dev, int bar,
> + struct rte_pci_ioport *p)
> +{
> + FILE *f;
> + char buf[BUFSIZ];
> + char filename[PATH_MAX];
> + uint64_t phys_addr, end_addr, flags;
> + int fd, i;
> + void *addr;
> +
> + /* open and read addresses of the corresponding resource in sysfs */
> + snprintf(filename, sizeof(filename), "%s/" PCI_PRI_FMT "/resource",
> + SYSFS_PCI_DEVICES, dev->addr.domain, dev->addr.bus,
> + dev->addr.devid, dev->addr.function);
> + f = fopen(filename, "r");
> + if (f == NULL) {
> + RTE_LOG(ERR, EAL, "Cannot open sysfs resource: %s\n",
> + strerror(errno));
> + return -1;
> + }
> + for (i = 0; i < bar + 1; i++) {
> + if (fgets(buf, sizeof(buf), f) == NULL) {
> + RTE_LOG(ERR, EAL, "Cannot read sysfs resource\n");
> + goto error;
> + }
> + }
> + if (pci_parse_one_sysfs_resource(buf, sizeof(buf), &phys_addr,
> + &end_addr, &flags) < 0)
> + goto error;
> + if ((flags & IORESOURCE_IO) == 0) {
> + RTE_LOG(ERR, EAL, "BAR %d is not an IO resource\n", bar);
> + goto error;
> + }
> + snprintf(filename, sizeof(filename), "%s/" PCI_PRI_FMT "/resource%d",
> + SYSFS_PCI_DEVICES, dev->addr.domain, dev->addr.bus,
> + dev->addr.devid, dev->addr.function, bar);
> +
> + /* mmap the pci resource */
> + fd = open(filename, O_RDWR);
> + if (fd < 0) {
> + RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", filename,
> + strerror(errno));
> + goto error;
> + }
> + addr = mmap(NULL, end_addr + 1, PROT_READ | PROT_WRITE,
> + MAP_SHARED, fd, 0);
Sorry, did not catch it in v1, but a close(fd) is missing here.
With this, I think the patchset looks good.
Just missing some opinion from the virtio maintainers ?
> + if (addr == MAP_FAILED) {
> + RTE_LOG(ERR, EAL, "Cannot mmap IO port resource: %s\n",
> + strerror(errno));
> + goto error;
> + }
> +
> + /* strangely, the base address is mmap addr + phys_addr */
> + p->base = (uintptr_t)addr + phys_addr;
> + p->len = end_addr + 1;
> + RTE_LOG(DEBUG, EAL, "PCI Port IO found start=0x%"PRIx64"\n", p->base);
> + fclose(f);
> +
> + return 0;
> +
> +error:
> + fclose(f);
> return -1;
> -#endif
> }
> +#endif
--
David Marchand
More information about the dev
mailing list