From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f51.google.com (mail-wm0-f51.google.com [74.125.82.51]) by dpdk.org (Postfix) with ESMTP id 96F175939 for ; Tue, 17 May 2016 17:54:21 +0200 (CEST) Received: by mail-wm0-f51.google.com with SMTP id e201so145864289wme.0 for ; Tue, 17 May 2016 08:54:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=FhNf+tROzAduRc61vv5IWpkSpP7gW013ZoNtzJmztzQ=; b=vj2TiCBNflFTK/SYVp3N3um8HGDO8j4fxwLH9zSDl2E0YElEABnGU9W7f1n+gPUiQz WzaSGP3HlHkgA+g87KMOmT6acgTfds9ASqo/JTWEpwkWsLZPomegNSdBGGEQ83HC6ird bhvIT6Ql/rB4AoMFoeYO/rvhEpZlJ62WsJ/OWdSFuS6NwdV/IyLWcdeoYAp8HUBJzZGc 24D07S1NPf/YAXYqCZEVXbWKWpyMXEhCkFL8IqRbBlHrVblTZ6/9XdZ0/2rhcIGzjytK WN2HETl9hF3vm0rVTl6Hzb2pg1c+tHfgiwPIqPFwlvMbOFZsStH3klw3Bcshoa0v3Sc6 w0BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=FhNf+tROzAduRc61vv5IWpkSpP7gW013ZoNtzJmztzQ=; b=OqyB3eQVe3IQl8aXKOF2RclLzVcJ9776pcrm9b9AnX7PdfCA7BJyS/O06N0HuFXq2W LSJBKs/njr90GuifMfN1XxjiJFDqnb8xGwqXtIQLAH4HHikRdTjhrDFEUJ2ih8jnafDZ 4E9FnMmF6LDJfwO8ywaRUH0yc3y3SutG0h5tuG6gqSr+hdf6qcOoCje4+hnT4v0HX78r UDarF7pfgGM9n7Ksrkr99Q1qlnFV17j0/uC7JtTMxZ0elYOtGOvho7Gqe6FH1O0KDFMb 32f4HNJgVRUV2Syv0mJsXJdtkP9bRTra06Tp/xiBJPKFlL5GzwwKTSR7yoT4jOw3lkFu mq/A== X-Gm-Message-State: AOPr4FUpstH2wfHo0yhl3hpmNYuLJAKD8enjH+hqzSqISl9BFCwE6VyxpjsjwFOZ9PCrybC3zSbfdMjfNMN7Twff X-Received: by 10.28.15.79 with SMTP id 76mr2370805wmp.53.1463500461328; Tue, 17 May 2016 08:54:21 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.16.2 with HTTP; Tue, 17 May 2016 08:54:01 -0700 (PDT) In-Reply-To: <1463479192-2488-6-git-send-email-olivier.matz@6wind.com> References: <1463143859-3105-1-git-send-email-olivier.matz@6wind.com> <1463479192-2488-1-git-send-email-olivier.matz@6wind.com> <1463479192-2488-6-git-send-email-olivier.matz@6wind.com> From: David Marchand Date: Tue, 17 May 2016 17:54:01 +0200 Message-ID: To: Olivier Matz Cc: "dev@dpdk.org" , Chao Zhu , Yuanhan Liu , "Xie, Huawei" Content-Type: text/plain; charset=UTF-8 Subject: Re: [dpdk-dev] [PATCH v2 5/7] eal/linux: mmap ioports on ppc64 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 May 2016 15:54:21 -0000 Hello Olivier, On Tue, May 17, 2016 at 11:59 AM, Olivier Matz 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