From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ob0-f178.google.com (mail-ob0-f178.google.com [209.85.214.178]) by dpdk.org (Postfix) with ESMTP id 666AC5A29 for ; Tue, 7 Jul 2015 10:05:10 +0200 (CEST) Received: by obdbs4 with SMTP id bs4so123599182obd.3 for ; Tue, 07 Jul 2015 01:05:10 -0700 (PDT) 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:date :message-id:subject:from:to:cc:content-type; bh=oiPcuxKSWBwhMnv5ngSNp2ElA1Uj5QZjlJDdj0bOG2Y=; b=MS4MFwfTVqHXRh7pyZDSPKkuCcseVeIqdyrjE/1cTHgx8aWV8vFrnDw6BOQtcT/msh vu7tcsW+fgPs73WmgLLN5jUP6gj0Npl2sehXdI2uzgjv9nNc47DoGkGascNKxwHLasJY Iwd6MteOiLGivYNhqA8txYjSMBHiX1BtlapMsesi8rQiw5E+6wy4l5S5fAO8lLgRzYMs M7jUTRtH7UCsTD4ACAfDNZmMa+2RWtK4YMhLByuwCjJ43QDvlP0TZVdkyo/sWVMhJDkx lfGLMVyS7aTGoaRBC5a28OM12DcB4X11aHc+ZIabaowXsJyf6H9A8RQ8NIvXBngW+65Q wzXA== X-Gm-Message-State: ALoCoQmFdrXXwFPRkNQO/V12N3sSv033mSJDh8QPU1tl8cLa3jebeRP5vwOXwwZeYmW4R0ndrPca MIME-Version: 1.0 X-Received: by 10.60.33.74 with SMTP id p10mr2945485oei.62.1436256309898; Tue, 07 Jul 2015 01:05:09 -0700 (PDT) Received: by 10.76.84.233 with HTTP; Tue, 7 Jul 2015 01:05:09 -0700 (PDT) In-Reply-To: <1436163861-3025-8-git-send-email-mukawa@igel.co.jp> References: <1435652668-3380-12-git-send-email-mukawa@igel.co.jp> <1436163861-3025-1-git-send-email-mukawa@igel.co.jp> <1436163861-3025-8-git-send-email-mukawa@igel.co.jp> Date: Tue, 7 Jul 2015 10:05:09 +0200 Message-ID: From: David Marchand To: Tetsuya Mukawa Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Cc: "dev@dpdk.org" Subject: Re: [dpdk-dev] [PATCH v8 07/12] eal: Add pci_uio_map_resource_by_index() 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, 07 Jul 2015 08:05:10 -0000 On Mon, Jul 6, 2015 at 8:24 AM, Tetsuya Mukawa wrote: > From: "Tetsuya.Mukawa" > > This patch adds a new function called pci_uio_map_resource_by_index(). > The function hides how to map uio resource in linuxapp and bsdapp. > With the function, pci_uio_map_resource() will be more abstracted. > > Signed-off-by: Tetsuya Mukawa > --- > lib/librte_eal/bsdapp/eal/eal_pci.c | 107 +++++++++++++++----------- > lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 124 > +++++++++++++++++------------- > 2 files changed, 133 insertions(+), 98 deletions(-) > > diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c > b/lib/librte_eal/bsdapp/eal/eal_pci.c > index ce0ca07..c76f936 100644 > --- a/lib/librte_eal/bsdapp/eal/eal_pci.c > +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c > @@ -241,20 +241,73 @@ error: > return -1; > } > > +static int > +pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx, > + struct mapped_pci_resource *uio_res, int map_idx) > +{ > + int fd; > + char *devname; > + void *mapaddr; > + uint64_t offset; > + uint64_t pagesz; > + struct pci_map *maps; > + > + if ((dev == NULL) || (uio_res == NULL) || (uio_res->path == NULL)) > + return -1; > No need for these checks. > + > + maps = uio_res->maps; > + devname = uio_res->path; > + pagesz = sysconf(_SC_PAGESIZE); > + > + /* allocate memory to keep path */ > + maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0); > + if (maps[map_idx].path == NULL) { > + RTE_LOG(ERR, EAL, "Cannot allocate memory for path: %s\n", > + strerror(errno)); > + return -1; > + } > + > + /* > + * open resource file, to mmap it > + */ > + fd = open(devname, O_RDWR); > + if (fd < 0) { > + RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", > + devname, strerror(errno)); > + goto error; > + } > + > + /* if matching map is found, then use it */ > + offset = res_idx * pagesz; > + mapaddr = pci_map_resource(NULL, fd, (off_t)offset, > + (size_t)dev->mem_resource[res_idx].len, 0); > + close(fd); > + if (mapaddr == MAP_FAILED) > + goto error; > + > + maps[map_idx].phaddr = dev->mem_resource[res_idx].phys_addr; > + maps[map_idx].size = dev->mem_resource[res_idx].len; > + maps[map_idx].addr = mapaddr; > + maps[map_idx].offset = offset; > + strcpy(maps[map_idx].path, devname); > + dev->mem_resource[res_idx].addr = mapaddr; > + > + return 0; > + > +error: > + rte_free(maps[map_idx].path); > + return -1; > +} > + > /* map the PCI resource of a PCI device in virtual memory */ > static int > pci_uio_map_resource(struct rte_pci_device *dev) > { > int i, map_idx = 0, ret; > - char *devname; > - void *mapaddr; > uint64_t phaddr; > - uint64_t offset; > - uint64_t pagesz; > struct mapped_pci_resource *uio_res = NULL; > struct mapped_pci_res_list *uio_res_list = > RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list); > - struct pci_map *maps; > > dev->intr_handle.fd = -1; > dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN; > @@ -269,53 +322,17 @@ pci_uio_map_resource(struct rte_pci_device *dev) > return ret; > > /* Map all BARs */ > - pagesz = sysconf(_SC_PAGESIZE); > - devname = uio_res->path; > - > - maps = uio_res->maps; > for (i = 0; i != PCI_MAX_RESOURCE; i++) { > - int fd; > - > /* skip empty BAR */ > if ((phaddr = dev->mem_resource[i].phys_addr) == 0) > continue; > > - /* allocate memory to keep path */ > - maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, > 0); > - if (maps[map_idx].path == NULL) { > - RTE_LOG(ERR, EAL, "Cannot allocate memory for > path: %s\n", > - strerror(errno)); > + ret = pci_uio_map_resource_by_index(dev, i, > + uio_res, map_idx); > + if (ret != 0) > goto error; > - } > > - /* > - * open resource file, to mmap it > - */ > - fd = open(devname, O_RDWR); > - if (fd < 0) { > - RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", > - devname, strerror(errno)); > - rte_free(maps[map_idx].path); > - goto error; > - } > - > - /* if matching map is found, then use it */ > - offset = i * pagesz; > - mapaddr = pci_map_resource(NULL, fd, (off_t)offset, > - (size_t)dev->mem_resource[i].len, > 0); > - close(fd); > - if (mapaddr == MAP_FAILED) { > - rte_free(maps[map_idx].path); > - goto error; > - } > - > - maps[map_idx].phaddr = dev->mem_resource[i].phys_addr; > - maps[map_idx].size = dev->mem_resource[i].len; > - maps[map_idx].addr = mapaddr; > - maps[map_idx].offset = offset; > - strcpy(maps[map_idx].path, devname); > map_idx++; > - dev->mem_resource[i].addr = mapaddr; > } > > uio_res->nb_maps = map_idx; > @@ -325,7 +342,7 @@ pci_uio_map_resource(struct rte_pci_device *dev) > return 0; > error: > for (i = 0; i < map_idx; i++) > - rte_free(maps[i].path); > + rte_free(uio_res->maps[i].path); > > /* 'uio_res' has valid value here */ > rte_free(uio_res); > diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c > b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c > index f408bd3..cafabba 100644 > --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c > +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c > @@ -333,19 +333,82 @@ error: > return -1; > } > > +static int > +pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx, > + struct mapped_pci_resource *uio_res, int map_idx) > +{ > + int fd; > + char devname[PATH_MAX]; /* contains the /dev/uioX */ > + void *mapaddr; > + struct rte_pci_addr *loc; > + struct pci_map *maps; > + > + if ((dev == NULL) || (uio_res == NULL)) > + return -1; > Idem. Then, Acked-by: David Marchand -- David Marchand