New upstream version 17.11-rc3
[deb_dpdk.git] / drivers / bus / pci / pci_common.c
similarity index 87%
rename from lib/librte_eal/common/eal_common_pci.c
rename to drivers/bus/pci/pci_common.c
index 52fd38c..104fdf9 100644 (file)
 #include <rte_log.h>
 #include <rte_bus.h>
 #include <rte_pci.h>
+#include <rte_bus_pci.h>
 #include <rte_per_lcore.h>
 #include <rte_memory.h>
-#include <rte_memzone.h>
 #include <rte_eal.h>
 #include <rte_string_fns.h>
 #include <rte_common.h>
 #include <rte_devargs.h>
 
-#include "eal_private.h"
+#include "private.h"
 
 extern struct rte_pci_bus rte_pci_bus;
 
 #define SYSFS_PCI_DEVICES "/sys/bus/pci/devices"
 
-const char *pci_get_sysfs_path(void)
+const char *rte_pci_get_sysfs_path(void)
 {
        const char *path = NULL;
 
@@ -81,7 +81,7 @@ static struct rte_devargs *pci_devargs_lookup(struct rte_pci_device *dev)
                if (devargs->bus != pbus)
                        continue;
                devargs->bus->parse(devargs->name, &addr);
-               if (!rte_eal_compare_pci_addr(&dev->addr, &addr))
+               if (!rte_pci_addr_cmp(&dev->addr, &addr))
                        return devargs;
        }
        return NULL;
@@ -110,56 +110,10 @@ pci_name_set(struct rte_pci_device *dev)
                dev->device.name = dev->name;
 }
 
-/* map a particular resource from a file */
-void *
-pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
-                int additional_flags)
-{
-       void *mapaddr;
-
-       /* Map the PCI memory resource of device */
-       mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
-                       MAP_SHARED | additional_flags, fd, offset);
-       if (mapaddr == MAP_FAILED) {
-               RTE_LOG(ERR, EAL, "%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n",
-                       __func__, fd, requested_addr,
-                       (unsigned long)size, (unsigned long)offset,
-                       strerror(errno), mapaddr);
-       } else
-               RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
-
-       return mapaddr;
-}
-
-/* unmap a particular resource */
-void
-pci_unmap_resource(void *requested_addr, size_t size)
-{
-       if (requested_addr == NULL)
-               return;
-
-       /* Unmap the PCI memory resource of device */
-       if (munmap(requested_addr, size)) {
-               RTE_LOG(ERR, EAL, "%s(): cannot munmap(%p, 0x%lx): %s\n",
-                       __func__, requested_addr, (unsigned long)size,
-                       strerror(errno));
-       } else
-               RTE_LOG(DEBUG, EAL, "  PCI memory unmapped at %p\n",
-                               requested_addr);
-}
-
 /*
  * Match the PCI Driver and Device using the ID Table
- *
- * @param pci_drv
- *     PCI driver from which ID table would be extracted
- * @param pci_dev
- *     PCI device to match against the driver
- * @return
- *     1 for successful match
- *     0 for unsuccessful match
  */
-static int
+int
 rte_pci_match(const struct rte_pci_driver *pci_drv,
              const struct rte_pci_device *pci_dev)
 {
@@ -271,6 +225,7 @@ rte_pci_detach_dev(struct rte_pci_device *dev)
 {
        struct rte_pci_addr *loc;
        struct rte_pci_driver *dr;
+       int ret = 0;
 
        if (dev == NULL)
                return -EINVAL;
@@ -285,8 +240,11 @@ rte_pci_detach_dev(struct rte_pci_device *dev)
        RTE_LOG(DEBUG, EAL, "  remove driver: %x:%x %s\n", dev->id.vendor_id,
                        dev->id.device_id, dr->driver.name);
 
-       if (dr->remove && (dr->remove(dev) < 0))
-               return -1;      /* negative value is an error */
+       if (dr->remove) {
+               ret = dr->remove(dev);
+               if (ret < 0)
+                       return ret;
+       }
 
        /* clear driver structure */
        dev->driver = NULL;
@@ -350,7 +308,7 @@ rte_pci_probe_one(const struct rte_pci_addr *addr)
                goto err_return;
 
        FOREACH_DEVICE_ON_PCIBUS(dev) {
-               if (rte_eal_compare_pci_addr(&dev->addr, addr))
+               if (rte_pci_addr_cmp(&dev->addr, addr))
                        continue;
 
                ret = pci_probe_all_drivers(dev);
@@ -380,7 +338,7 @@ rte_pci_detach(const struct rte_pci_addr *addr)
                return -1;
 
        FOREACH_DEVICE_ON_PCIBUS(dev) {
-               if (rte_eal_compare_pci_addr(&dev->addr, addr))
+               if (rte_pci_addr_cmp(&dev->addr, addr))
                        continue;
 
                ret = rte_pci_detach_dev(dev);
@@ -482,8 +440,7 @@ pci_parse(const char *name, void *addr)
        struct rte_pci_addr pci_addr;
        bool parse;
 
-       parse = (eal_parse_pci_BDF(name, &pci_addr) == 0 ||
-                eal_parse_pci_DomBDF(name, &pci_addr) == 0);
+       parse = (rte_pci_addr_parse(name, &pci_addr) == 0);
        if (parse && addr != NULL)
                *out = pci_addr;
        return parse == false;
@@ -559,8 +516,10 @@ pci_unplug(struct rte_device *dev)
 
        pdev = RTE_DEV_TO_PCI(dev);
        ret = rte_pci_detach_dev(pdev);
-       rte_pci_remove_device(pdev);
-       free(pdev);
+       if (ret == 0) {
+               rte_pci_remove_device(pdev);
+               free(pdev);
+       }
        return ret;
 }
 
@@ -572,6 +531,7 @@ struct rte_pci_bus rte_pci_bus = {
                .plug = pci_plug,
                .unplug = pci_unplug,
                .parse = pci_parse,
+               .get_iommu_class = rte_pci_get_iommu_class,
        },
        .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
        .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),