pci: probe or close device
[dpdk.git] / lib / librte_eal / common / include / rte_pci.h
index a87b4b3..1550d49 100644 (file)
@@ -191,6 +191,11 @@ struct rte_pci_driver;
  */
 typedef int (pci_devinit_t)(struct rte_pci_driver *, struct rte_pci_device *);
 
+/**
+ * Uninitialisation function for the driver called during hotplugging.
+ */
+typedef int (pci_devuninit_t)(struct rte_pci_device *);
+
 /**
  * A structure describing a PCI driver.
  */
@@ -198,6 +203,7 @@ struct rte_pci_driver {
        TAILQ_ENTRY(rte_pci_driver) next;       /**< Next in list. */
        const char *name;                       /**< Driver name. */
        pci_devinit_t *devinit;                 /**< Device init. function. */
+       pci_devuninit_t *devuninit;             /**< Device uninit function. */
        struct rte_pci_id *id_table;            /**< ID table, NULL terminated. */
        uint32_t drv_flags;                     /**< Flags contolling handling of device. */
 };
@@ -270,6 +276,40 @@ eal_parse_pci_DomBDF(const char *input, struct rte_pci_addr *dev_addr)
 }
 #undef GET_PCIADDR_FIELD
 
+/* Compare two PCI device addresses. */
+/**
+ * Utility function to compare two PCI device addresses.
+ *
+ * @param addr
+ *     The PCI Bus-Device-Function address to compare
+ * @param addr2
+ *     The PCI Bus-Device-Function address to compare
+ * @return
+ *     0 on equal PCI address.
+ *     Positive on addr is greater than addr2.
+ *     Negative on addr is less than addr2, or error.
+ */
+static inline int
+rte_eal_compare_pci_addr(struct rte_pci_addr *addr, struct rte_pci_addr *addr2)
+{
+       uint64_t dev_addr, dev_addr2;
+
+       if ((addr == NULL) || (addr2 == NULL))
+               return -1;
+
+       dev_addr = (addr->domain << 24) | (addr->bus << 16) |
+                               (addr->devid << 8) | addr->function;
+       dev_addr2 = (addr2->domain << 24) | (addr2->bus << 16) |
+                               (addr2->devid << 8) | addr2->function;
+
+       if (dev_addr > dev_addr2)
+               return 1;
+       else if (dev_addr < dev_addr2)
+               return -1;
+       else
+               return 0;
+}
+
 /**
  * Probe the PCI bus for registered drivers.
  *
@@ -283,6 +323,38 @@ eal_parse_pci_DomBDF(const char *input, struct rte_pci_addr *dev_addr)
  */
 int rte_eal_pci_probe(void);
 
+#ifdef RTE_LIBRTE_EAL_HOTPLUG
+/**
+ * Probe the single PCI device.
+ *
+ * Scan the content of the PCI bus, and find the pci device specified by pci
+ * address, then call the probe() function for registered driver that has a
+ * matching entry in its id_table for discovered device.
+ *
+ * @param addr
+ *     The PCI Bus-Device-Function address to probe.
+ * @return
+ *   - 0 on success.
+ *   - Negative on error.
+ */
+int rte_eal_pci_probe_one(struct rte_pci_addr *addr);
+
+/**
+ * Close the single PCI device.
+ *
+ * Scan the content of the PCI bus, and find the pci device specified by pci
+ * address, then call the close() function for registered driver that has a
+ * matching entry in its id_table for discovered device.
+ *
+ * @param addr
+ *     The PCI Bus-Device-Function address to close.
+ * @return
+ *   - 0 on success.
+ *   - Negative on error.
+ */
+int rte_eal_pci_close_one(struct rte_pci_addr *addr);
+#endif /* RTE_LIBRTE_EAL_HOTPLUG */
+
 /**
  * Dump the content of the PCI bus.
  *