1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2017 6WIND S.A. 3 */ 4 5 #ifndef _PCI_PRIVATE_H_ 6 #define _PCI_PRIVATE_H_ 7 8 #include <stdbool.h> 9 #include <stdio.h> 10 #include <rte_pci.h> 11 #include <rte_bus_pci.h> 12 13 extern struct rte_pci_bus rte_pci_bus; 14 15 struct rte_pci_driver; 16 struct rte_pci_device; 17 18 /** 19 * Scan the content of the PCI bus, and the devices in the devices 20 * list 21 * 22 * @return 23 * 0 on success, negative on error 24 */ 25 int rte_pci_scan(void); 26 27 /** 28 * Find the name of a PCI device. 29 */ 30 void 31 pci_name_set(struct rte_pci_device *dev); 32 33 /** 34 * Validate whether a device with given PCI address should be ignored or not. 35 * 36 * @param pci_addr 37 * PCI address of device to be validated 38 * @return 39 * true: if device is to be ignored, 40 * false: if device is to be scanned, 41 */ 42 bool rte_pci_ignore_device(const struct rte_pci_addr *pci_addr); 43 44 /** 45 * Add a PCI device to the PCI Bus (append to PCI Device list). This function 46 * also updates the bus references of the PCI Device (and the generic device 47 * object embedded within. 48 * 49 * @param pci_dev 50 * PCI device to add 51 * @return void 52 */ 53 void rte_pci_add_device(struct rte_pci_device *pci_dev); 54 55 /** 56 * Insert a PCI device in the PCI Bus at a particular location in the device 57 * list. It also updates the PCI Bus reference of the new devices to be 58 * inserted. 59 * 60 * @param exist_pci_dev 61 * Existing PCI device in PCI Bus 62 * @param new_pci_dev 63 * PCI device to be added before exist_pci_dev 64 * @return void 65 */ 66 void rte_pci_insert_device(struct rte_pci_device *exist_pci_dev, 67 struct rte_pci_device *new_pci_dev); 68 69 /** 70 * A structure describing a PCI mapping. 71 */ 72 struct pci_map { 73 void *addr; 74 char *path; 75 uint64_t offset; 76 uint64_t size; 77 uint64_t phaddr; 78 }; 79 80 struct pci_msix_table { 81 int bar_index; 82 uint32_t offset; 83 uint32_t size; 84 }; 85 86 /** 87 * A structure describing a mapped PCI resource. 88 * For multi-process we need to reproduce all PCI mappings in secondary 89 * processes, so save them in a tailq. 90 */ 91 struct mapped_pci_resource { 92 TAILQ_ENTRY(mapped_pci_resource) next; 93 94 struct rte_pci_addr pci_addr; 95 char path[PATH_MAX]; 96 int nb_maps; 97 struct pci_map maps[PCI_MAX_RESOURCE]; 98 struct pci_msix_table msix_table; 99 }; 100 101 /** mapped pci device list */ 102 TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource); 103 104 /** 105 * Map a particular resource from a file. 106 * 107 * @param requested_addr 108 * The starting address for the new mapping range. 109 * @param fd 110 * The file descriptor. 111 * @param offset 112 * The offset for the mapping range. 113 * @param size 114 * The size for the mapping range. 115 * @param additional_flags 116 * The additional rte_mem_map() flags for the mapping range. 117 * @return 118 * - On success, the function returns a pointer to the mapped area. 119 * - On error, NULL is returned. 120 */ 121 void *pci_map_resource(void *requested_addr, int fd, off_t offset, 122 size_t size, int additional_flags); 123 124 /** 125 * Unmap a particular resource. 126 * 127 * @param requested_addr 128 * The address for the unmapping range. 129 * @param size 130 * The size for the unmapping range. 131 */ 132 void pci_unmap_resource(void *requested_addr, size_t size); 133 134 /** 135 * Map the PCI resource of a PCI device in virtual memory 136 * 137 * This function is private to EAL. 138 * 139 * @return 140 * 0 on success, negative on error 141 */ 142 int pci_uio_map_resource(struct rte_pci_device *dev); 143 144 /** 145 * Unmap the PCI resource of a PCI device 146 * 147 * This function is private to EAL. 148 */ 149 void pci_uio_unmap_resource(struct rte_pci_device *dev); 150 151 /** 152 * Allocate uio resource for PCI device 153 * 154 * This function is private to EAL. 155 * 156 * @param dev 157 * PCI device to allocate uio resource 158 * @param uio_res 159 * Pointer to uio resource. 160 * If the function returns 0, the pointer will be filled. 161 * @return 162 * 0 on success, negative on error 163 */ 164 int pci_uio_alloc_resource(struct rte_pci_device *dev, 165 struct mapped_pci_resource **uio_res); 166 167 /** 168 * Free uio resource for PCI device 169 * 170 * This function is private to EAL. 171 * 172 * @param dev 173 * PCI device to free uio resource 174 * @param uio_res 175 * Pointer to uio resource. 176 */ 177 void pci_uio_free_resource(struct rte_pci_device *dev, 178 struct mapped_pci_resource *uio_res); 179 180 /** 181 * Remap the PCI resource of a PCI device in anonymous virtual memory. 182 * 183 * @param dev 184 * Point to the struct rte pci device. 185 * @return 186 * - On success, zero. 187 * - On failure, a negative value. 188 */ 189 int 190 pci_uio_remap_resource(struct rte_pci_device *dev); 191 192 /** 193 * Map device memory to uio resource 194 * 195 * This function is private to EAL. 196 * 197 * @param dev 198 * PCI device that has memory information. 199 * @param res_idx 200 * Memory resource index of the PCI device. 201 * @param uio_res 202 * uio resource that will keep mapping information. 203 * @param map_idx 204 * Mapping information index of the uio resource. 205 * @return 206 * 0 on success, negative on error 207 */ 208 int pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx, 209 struct mapped_pci_resource *uio_res, int map_idx); 210 211 /* 212 * Match the PCI Driver and Device using the ID Table 213 * 214 * @param pci_drv 215 * PCI driver from which ID table would be extracted 216 * @param pci_dev 217 * PCI device to match against the driver 218 * @return 219 * 1 for successful match 220 * 0 for unsuccessful match 221 */ 222 int 223 rte_pci_match(const struct rte_pci_driver *pci_drv, 224 const struct rte_pci_device *pci_dev); 225 226 /** 227 * OS specific callbacks for rte_pci_get_iommu_class 228 * 229 */ 230 bool 231 pci_device_iommu_support_va(const struct rte_pci_device *dev); 232 233 enum rte_iova_mode 234 pci_device_iova_mode(const struct rte_pci_driver *pci_drv, 235 const struct rte_pci_device *pci_dev); 236 237 /** 238 * Get iommu class of PCI devices on the bus. 239 * And return their preferred iova mapping mode. 240 * 241 * @return 242 * - enum rte_iova_mode. 243 */ 244 enum rte_iova_mode 245 rte_pci_get_iommu_class(void); 246 247 /* 248 * Iterate over internal devices, 249 * matching any device against the provided 250 * string. 251 * 252 * @param start 253 * Iteration starting point. 254 * 255 * @param str 256 * Device string to match against. 257 * 258 * @param it 259 * (unused) iterator structure. 260 * 261 * @return 262 * A pointer to the next matching device if any. 263 * NULL otherwise. 264 */ 265 void * 266 rte_pci_dev_iterate(const void *start, 267 const char *str, 268 const struct rte_dev_iterator *it); 269 270 #endif /* _PCI_PRIVATE_H_ */ 271