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