[dpdk-dev] [PATCH 5/7] eal/linux: mmap ioports on ppc64

2016-05-13 Thread Olivier Matz


On 05/13/2016 04:33 PM, David Marchand wrote:
>> --- a/lib/librte_eal/common/include/rte_pci.h
>> +++ b/lib/librte_eal/common/include/rte_pci.h
>> @@ -105,7 +105,8 @@ extern struct pci_device_list pci_device_list; /**< 
>> Global list of PCI devices.
>>  /** Nb. of values in PCI resource format. */
>>  #define PCI_RESOURCE_FMT_NVAL 3
>>
>> -/** IO resource type: memory address space */
>> +/** IO resource type: */
>> +#define IORESOURCE_IO 0x0100
>>  #define IORESOURCE_MEM0x0200
>>
>>  /**
> 
> This could go in a linux-specific header.

Yep, I'll do a separate patch for that in v2.

> 
>> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c 
>> b/lib/librte_eal/linuxapp/eal/eal_pci.c
>> index 1a93725..f1ea52b 100644
>> --- a/lib/librte_eal/linuxapp/eal/eal_pci.c
>> +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
>> @@ -191,9 +191,9 @@ pci_find_max_end_va(void)
>>  }
>>
>>  /* parse one line of the "resource" sysfs file (note that the 'line'
>> - * string is modified)
>> + * string is modified
>>   */
> 
> Garbage ?

Indeed :)


Thanks for reviewing!



[dpdk-dev] [PATCH 5/7] eal/linux: mmap ioports on ppc64

2016-05-13 Thread David Marchand
On Fri, May 13, 2016 at 2:50 PM, Olivier Matz  wrote:
> On PPC64, the ioports are mapped in memory. Implement the missing part
> of ioport API for PPC64 when using uio. This may also work on other
> architectures but it has not been tested.
>
> Signed-off-by: David Marchand 
> Signed-off-by: Olivier Matz 
> ---
>  lib/librte_eal/common/include/rte_pci.h|   4 +-
>  lib/librte_eal/linuxapp/eal/eal_pci.c  |   4 +-
>  lib/librte_eal/linuxapp/eal/eal_pci_init.h |   6 ++
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c  | 119 
> +++--
>  4 files changed, 107 insertions(+), 26 deletions(-)
>
> diff --git a/lib/librte_eal/common/include/rte_pci.h 
> b/lib/librte_eal/common/include/rte_pci.h
> index fd049d1..4657396 100644
> --- a/lib/librte_eal/common/include/rte_pci.h
> +++ b/lib/librte_eal/common/include/rte_pci.h
> @@ -105,7 +105,8 @@ extern struct pci_device_list pci_device_list; /**< 
> Global list of PCI devices.
>  /** Nb. of values in PCI resource format. */
>  #define PCI_RESOURCE_FMT_NVAL 3
>
> -/** IO resource type: memory address space */
> +/** IO resource type: */
> +#define IORESOURCE_IO 0x0100
>  #define IORESOURCE_MEM0x0200
>
>  /**

This could go in a linux-specific header.

> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c 
> b/lib/librte_eal/linuxapp/eal/eal_pci.c
> index 1a93725..f1ea52b 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
> @@ -191,9 +191,9 @@ pci_find_max_end_va(void)
>  }
>
>  /* parse one line of the "resource" sysfs file (note that the 'line'
> - * string is modified)
> + * string is modified
>   */

Garbage ?

-- 
David Marchand


[dpdk-dev] [PATCH 5/7] eal/linux: mmap ioports on ppc64

2016-05-13 Thread Olivier Matz
On PPC64, the ioports are mapped in memory. Implement the missing part
of ioport API for PPC64 when using uio. This may also work on other
architectures but it has not been tested.

Signed-off-by: David Marchand 
Signed-off-by: Olivier Matz 
---
 lib/librte_eal/common/include/rte_pci.h|   4 +-
 lib/librte_eal/linuxapp/eal/eal_pci.c  |   4 +-
 lib/librte_eal/linuxapp/eal/eal_pci_init.h |   6 ++
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c  | 119 +++--
 4 files changed, 107 insertions(+), 26 deletions(-)

diff --git a/lib/librte_eal/common/include/rte_pci.h 
b/lib/librte_eal/common/include/rte_pci.h
index fd049d1..4657396 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -105,7 +105,8 @@ extern struct pci_device_list pci_device_list; /**< Global 
list of PCI devices.
 /** Nb. of values in PCI resource format. */
 #define PCI_RESOURCE_FMT_NVAL 3

-/** IO resource type: memory address space */
+/** IO resource type: */
+#define IORESOURCE_IO 0x0100
 #define IORESOURCE_MEM0x0200

 /**
@@ -518,6 +519,7 @@ int rte_eal_pci_write_config(const struct rte_pci_device 
*device,
 struct rte_pci_ioport {
struct rte_pci_device *dev;
uint64_t base;
+   uint64_t len; /* only filled for memory mapped ports */
 };

 /**
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c 
b/lib/librte_eal/linuxapp/eal/eal_pci.c
index 1a93725..f1ea52b 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -191,9 +191,9 @@ pci_find_max_end_va(void)
 }

 /* parse one line of the "resource" sysfs file (note that the 'line'
- * string is modified)
+ * string is modified
  */
-static int
+int
 pci_parse_one_sysfs_resource(char *line, size_t len, uint64_t *phys_addr,
uint64_t *end_addr, uint64_t *flags)
 {
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h 
b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
index 7011753..fbe34c6 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -42,6 +42,12 @@
 extern void *pci_map_addr;
 void *pci_find_max_end_va(void);

+/* parse one line of the "resource" sysfs file (note that the 'line'
+ * string is modified)
+ */
+int pci_parse_one_sysfs_resource(char *line, size_t len, uint64_t *phys_addr,
+   uint64_t *end_addr, uint64_t *flags);
+
 int pci_uio_alloc_resource(struct rte_pci_device *dev,
struct mapped_pci_resource **uio_res);
 void pci_uio_free_resource(struct rte_pci_device *dev,
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
@@ -35,6 +35,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -368,11 +369,11 @@ error:
return -1;
 }

+#if defined(RTE_ARCH_X86)
 int
 pci_uio_ioport_map(struct rte_pci_device *dev, int bar,
   struct rte_pci_ioport *p)
 {
-#if defined(RTE_ARCH_X86)
char dirname[PATH_MAX];
char filename[PATH_MAX];
int uio_num;
@@ -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), _addr,
+   _addr, ) < 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);
+
+   /*