1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2014 Intel Corporation 3 */ 4 5 #ifndef EAL_PCI_INIT_H_ 6 #define EAL_PCI_INIT_H_ 7 8 #include <rte_vfio.h> 9 10 /** IO resource type: */ 11 #define IORESOURCE_IO 0x00000100 12 #define IORESOURCE_MEM 0x00000200 13 14 /* 15 * Helper function to map PCI resources right after hugepages in virtual memory 16 */ 17 extern void *pci_map_addr; 18 void *pci_find_max_end_va(void); 19 20 /* parse one line of the "resource" sysfs file (note that the 'line' 21 * string is modified) 22 */ 23 int pci_parse_one_sysfs_resource(char *line, size_t len, uint64_t *phys_addr, 24 uint64_t *end_addr, uint64_t *flags); 25 26 int pci_uio_alloc_resource(struct rte_pci_device *dev, 27 struct mapped_pci_resource **uio_res); 28 void pci_uio_free_resource(struct rte_pci_device *dev, 29 struct mapped_pci_resource *uio_res); 30 int pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx, 31 struct mapped_pci_resource *uio_res, int map_idx); 32 33 int pci_uio_read_config(const struct rte_intr_handle *intr_handle, 34 void *buf, size_t len, off_t offs); 35 int pci_uio_write_config(const struct rte_intr_handle *intr_handle, 36 const void *buf, size_t len, off_t offs); 37 38 int pci_uio_ioport_map(struct rte_pci_device *dev, int bar, 39 struct rte_pci_ioport *p); 40 void pci_uio_ioport_read(struct rte_pci_ioport *p, 41 void *data, size_t len, off_t offset); 42 void pci_uio_ioport_write(struct rte_pci_ioport *p, 43 const void *data, size_t len, off_t offset); 44 int pci_uio_ioport_unmap(struct rte_pci_ioport *p); 45 46 #ifdef VFIO_PRESENT 47 48 #ifdef PCI_MSIX_TABLE_BIR 49 #define RTE_PCI_MSIX_TABLE_BIR PCI_MSIX_TABLE_BIR 50 #else 51 #define RTE_PCI_MSIX_TABLE_BIR 0x7 52 #endif 53 54 #ifdef PCI_MSIX_TABLE_OFFSET 55 #define RTE_PCI_MSIX_TABLE_OFFSET PCI_MSIX_TABLE_OFFSET 56 #else 57 #define RTE_PCI_MSIX_TABLE_OFFSET 0xfffffff8 58 #endif 59 60 #ifdef PCI_MSIX_FLAGS_QSIZE 61 #define RTE_PCI_MSIX_FLAGS_QSIZE PCI_MSIX_FLAGS_QSIZE 62 #else 63 #define RTE_PCI_MSIX_FLAGS_QSIZE 0x07ff 64 #endif 65 66 /* access config space */ 67 int pci_vfio_read_config(const struct rte_intr_handle *intr_handle, 68 void *buf, size_t len, off_t offs); 69 int pci_vfio_write_config(const struct rte_intr_handle *intr_handle, 70 const void *buf, size_t len, off_t offs); 71 72 int pci_vfio_ioport_map(struct rte_pci_device *dev, int bar, 73 struct rte_pci_ioport *p); 74 void pci_vfio_ioport_read(struct rte_pci_ioport *p, 75 void *data, size_t len, off_t offset); 76 void pci_vfio_ioport_write(struct rte_pci_ioport *p, 77 const void *data, size_t len, off_t offset); 78 int pci_vfio_ioport_unmap(struct rte_pci_ioport *p); 79 80 /* map/unmap VFIO resource prototype */ 81 int pci_vfio_map_resource(struct rte_pci_device *dev); 82 int pci_vfio_unmap_resource(struct rte_pci_device *dev); 83 84 int pci_vfio_is_enabled(void); 85 86 #endif 87 88 #endif /* EAL_PCI_INIT_H_ */ 89