pci: merge resource mapping functions for linux and bsd
[dpdk.git] / lib / librte_eal / common / include / rte_pci.h
index 7801fa0..0f16f2c 100644 (file)
@@ -220,6 +220,34 @@ struct rte_pci_driver {
 /** Device driver supports detaching capability */
 #define RTE_PCI_DRV_DETACHABLE 0x0010
 
+/**
+ * A structure describing a PCI mapping.
+ */
+struct pci_map {
+       void *addr;
+       char *path;
+       uint64_t offset;
+       uint64_t size;
+       uint64_t phaddr;
+};
+
+/**
+ * A structure describing a mapped PCI resource.
+ * For multi-process we need to reproduce all PCI mappings in secondary
+ * processes, so save them in a tailq.
+ */
+struct mapped_pci_resource {
+       TAILQ_ENTRY(mapped_pci_resource) next;
+
+       struct rte_pci_addr pci_addr;
+       char path[PATH_MAX];
+       int nb_maps;
+       struct pci_map maps[PCI_MAX_RESOURCE];
+};
+
+/** mapped pci device list */
+TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
+
 /**< Internal use only - Macro used by pci addr parsing functions **/
 #define GET_PCIADDR_FIELD(in, fd, lim, dlm)                   \
 do {                                                               \
@@ -336,6 +364,38 @@ int rte_eal_pci_scan(void);
  */
 int rte_eal_pci_probe(void);
 
+/**
+ * @internal
+ * Map a particular resource from a file.
+ *
+ * @param requested_addr
+ *      The starting address for the new mapping range.
+ * @param fd
+ *      The file descriptor.
+ * @param offset
+ *      The offset for the mapping range.
+ * @param size
+ *      The size for the mapping range.
+ * @param additional_flags
+ *      The additional flags for the mapping range.
+ * @return
+ *   - On success, the function returns a pointer to the mapped area.
+ *   - On error, the value MAP_FAILED is returned.
+ */
+void *pci_map_resource(void *requested_addr, int fd, off_t offset,
+               size_t size, int additional_flags);
+
+/**
+ * @internal
+ * Unmap a particular resource.
+ *
+ * @param requested_addr
+ *      The address for the unmapping range.
+ * @param size
+ *      The size for the unmapping range.
+ */
+void pci_unmap_resource(void *requested_addr, size_t size);
+
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
 /**
  * Probe the single PCI device.