bnx2x: fix part of 32-bit build
[dpdk.git] / lib / librte_eal / linuxapp / eal / eal_pci.c
index 1d5a13b..0e62f65 100644 (file)
@@ -41,7 +41,6 @@
 #include <rte_devargs.h>
 #include <rte_memcpy.h>
 
-#include "rte_pci_dev_ids.h"
 #include "eal_filesystem.h"
 #include "eal_private.h"
 #include "eal_pci_init.h"
@@ -123,6 +122,56 @@ pci_get_kernel_driver_by_path(const char *filename, char *dri_name)
        return -1;
 }
 
+/* Map pci device */
+int
+pci_map_device(struct rte_pci_device *dev)
+{
+       int ret = -1;
+
+       /* try mapping the NIC resources using VFIO if it exists */
+       switch (dev->kdrv) {
+       case RTE_KDRV_VFIO:
+#ifdef VFIO_PRESENT
+               if (pci_vfio_is_enabled())
+                       ret = pci_vfio_map_resource(dev);
+#endif
+               break;
+       case RTE_KDRV_IGB_UIO:
+       case RTE_KDRV_UIO_GENERIC:
+               /* map resources for devices that use uio */
+               ret = pci_uio_map_resource(dev);
+               break;
+       default:
+               RTE_LOG(DEBUG, EAL,
+                       "  Not managed by a supported kernel driver, skipped\n");
+               ret = 1;
+               break;
+       }
+
+       return ret;
+}
+
+/* Unmap pci device */
+void
+pci_unmap_device(struct rte_pci_device *dev)
+{
+       /* try unmapping the NIC resources using VFIO if it exists */
+       switch (dev->kdrv) {
+       case RTE_KDRV_VFIO:
+               RTE_LOG(ERR, EAL, "Hotplug doesn't support vfio yet\n");
+               break;
+       case RTE_KDRV_IGB_UIO:
+       case RTE_KDRV_UIO_GENERIC:
+               /* unmap resources for devices that use uio */
+               pci_uio_unmap_resource(dev);
+               break;
+       default:
+               RTE_LOG(DEBUG, EAL,
+                       "  Not managed by a supported kernel driver, skipped\n");
+               break;
+       }
+}
+
 void *
 pci_find_max_end_va(void)
 {
@@ -508,7 +557,7 @@ pci_config_max_read_request_size(struct rte_pci_device *dev)
        return 0;
 }
 
-static void
+void
 pci_config_space_set(struct rte_pci_device *dev)
 {
        if (rte_eal_process_type() != RTE_PROC_PRIMARY)
@@ -522,6 +571,56 @@ pci_config_space_set(struct rte_pci_device *dev)
 }
 #endif
 
+/* Read PCI config space. */
+int rte_eal_pci_read_config(const struct rte_pci_device *device,
+                           void *buf, size_t len, off_t offset)
+{
+       const struct rte_intr_handle *intr_handle = &device->intr_handle;
+
+       switch (intr_handle->type) {
+       case RTE_INTR_HANDLE_UIO:
+       case RTE_INTR_HANDLE_UIO_INTX:
+               return pci_uio_read_config(intr_handle, buf, len, offset);
+
+#ifdef VFIO_PRESENT
+       case RTE_INTR_HANDLE_VFIO_MSIX:
+       case RTE_INTR_HANDLE_VFIO_MSI:
+       case RTE_INTR_HANDLE_VFIO_LEGACY:
+               return pci_vfio_read_config(intr_handle, buf, len, offset);
+#endif
+       default:
+               RTE_LOG(ERR, EAL,
+                       "Unknown handle type of fd %d\n",
+                                       intr_handle->fd);
+               return -1;
+       }
+}
+
+/* Write PCI config space. */
+int rte_eal_pci_write_config(const struct rte_pci_device *device,
+                            const void *buf, size_t len, off_t offset)
+{
+       const struct rte_intr_handle *intr_handle = &device->intr_handle;
+
+       switch (intr_handle->type) {
+       case RTE_INTR_HANDLE_UIO:
+       case RTE_INTR_HANDLE_UIO_INTX:
+               return pci_uio_write_config(intr_handle, buf, len, offset);
+
+#ifdef VFIO_PRESENT
+       case RTE_INTR_HANDLE_VFIO_MSIX:
+       case RTE_INTR_HANDLE_VFIO_MSI:
+       case RTE_INTR_HANDLE_VFIO_LEGACY:
+               return pci_vfio_write_config(intr_handle, buf, len, offset);
+#endif
+       default:
+               RTE_LOG(ERR, EAL,
+                       "Unknown handle type of fd %d\n",
+                                       intr_handle->fd);
+               return -1;
+       }
+}
+
 /* Init the PCI EAL subsystem */
 int
 rte_eal_pci_init(void)