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