1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2015 Intel Corporation. 3 * Copyright 2013-2014 6WIND S.A. 4 */ 5 6 #ifndef _RTE_BUS_PCI_H_ 7 #define _RTE_BUS_PCI_H_ 8 9 /** 10 * @file 11 * PCI device & driver interface 12 */ 13 14 #ifdef __cplusplus 15 extern "C" { 16 #endif 17 18 #include <stdio.h> 19 #include <stdlib.h> 20 #include <limits.h> 21 #include <errno.h> 22 #include <stdint.h> 23 #include <inttypes.h> 24 25 #include <rte_compat.h> 26 #include <rte_debug.h> 27 #include <rte_interrupts.h> 28 #include <rte_pci.h> 29 30 /* Forward declarations */ 31 struct rte_pci_device; 32 struct rte_pci_driver; 33 struct rte_pci_ioport; 34 35 struct rte_devargs; 36 37 /** 38 * Map the PCI device resources in user space virtual memory address 39 * 40 * Note that driver should not call this function when flag 41 * RTE_PCI_DRV_NEED_MAPPING is set, as EAL will do that for 42 * you when it's on. 43 * 44 * @param dev 45 * A pointer to a rte_pci_device structure describing the device 46 * to use 47 * 48 * @return 49 * 0 on success, negative on error and positive if no driver 50 * is found for the device. 51 */ 52 int rte_pci_map_device(struct rte_pci_device *dev); 53 54 /** 55 * Unmap this device 56 * 57 * @param dev 58 * A pointer to a rte_pci_device structure describing the device 59 * to use 60 */ 61 void rte_pci_unmap_device(struct rte_pci_device *dev); 62 63 /** 64 * Dump the content of the PCI bus. 65 * 66 * @param f 67 * A pointer to a file for output 68 */ 69 void rte_pci_dump(FILE *f); 70 71 /** 72 * Find device's extended PCI capability. 73 * 74 * @param dev 75 * A pointer to rte_pci_device structure. 76 * 77 * @param cap 78 * Extended capability to be found, which can be any from 79 * RTE_PCI_EXT_CAP_ID_*, defined in librte_pci. 80 * 81 * @return 82 * > 0: The offset of the next matching extended capability structure 83 * within the device's PCI configuration space. 84 * < 0: An error in PCI config space read. 85 * = 0: Device does not support it. 86 */ 87 __rte_experimental 88 off_t rte_pci_find_ext_capability(struct rte_pci_device *dev, uint32_t cap); 89 90 /** 91 * Enables/Disables Bus Master for device's PCI command register. 92 * 93 * @param dev 94 * A pointer to rte_pci_device structure. 95 * @param enable 96 * Enable or disable Bus Master. 97 * 98 * @return 99 * 0 on success, -1 on error in PCI config space read/write. 100 */ 101 __rte_experimental 102 int rte_pci_set_bus_master(struct rte_pci_device *dev, bool enable); 103 104 /** 105 * Read PCI config space. 106 * 107 * @param device 108 * A pointer to a rte_pci_device structure describing the device 109 * to use 110 * @param buf 111 * A data buffer where the bytes should be read into 112 * @param len 113 * The length of the data buffer. 114 * @param offset 115 * The offset into PCI config space 116 * @return 117 * Number of bytes read on success, negative on error. 118 */ 119 int rte_pci_read_config(const struct rte_pci_device *device, 120 void *buf, size_t len, off_t offset); 121 122 /** 123 * Write PCI config space. 124 * 125 * @param device 126 * A pointer to a rte_pci_device structure describing the device 127 * to use 128 * @param buf 129 * A data buffer containing the bytes should be written 130 * @param len 131 * The length of the data buffer. 132 * @param offset 133 * The offset into PCI config space 134 */ 135 int rte_pci_write_config(const struct rte_pci_device *device, 136 const void *buf, size_t len, off_t offset); 137 138 /** 139 * Initialize a rte_pci_ioport object for a pci device io resource. 140 * 141 * This object is then used to gain access to those io resources (see below). 142 * 143 * @param dev 144 * A pointer to a rte_pci_device structure describing the device 145 * to use. 146 * @param bar 147 * Index of the io pci resource we want to access. 148 * @param p 149 * The rte_pci_ioport object to be initialized. 150 * @return 151 * 0 on success, negative on error. 152 */ 153 int rte_pci_ioport_map(struct rte_pci_device *dev, int bar, 154 struct rte_pci_ioport *p); 155 156 /** 157 * Release any resources used in a rte_pci_ioport object. 158 * 159 * @param p 160 * The rte_pci_ioport object to be uninitialized. 161 * @return 162 * 0 on success, negative on error. 163 */ 164 int rte_pci_ioport_unmap(struct rte_pci_ioport *p); 165 166 /** 167 * Read from a io pci resource. 168 * 169 * @param p 170 * The rte_pci_ioport object from which we want to read. 171 * @param data 172 * A data buffer where the bytes should be read into 173 * @param len 174 * The length of the data buffer. 175 * @param offset 176 * The offset into the pci io resource. 177 */ 178 void rte_pci_ioport_read(struct rte_pci_ioport *p, 179 void *data, size_t len, off_t offset); 180 181 /** 182 * Write to a io pci resource. 183 * 184 * @param p 185 * The rte_pci_ioport object to which we want to write. 186 * @param data 187 * A data buffer where the bytes should be read into 188 * @param len 189 * The length of the data buffer. 190 * @param offset 191 * The offset into the pci io resource. 192 */ 193 void rte_pci_ioport_write(struct rte_pci_ioport *p, 194 const void *data, size_t len, off_t offset); 195 196 #ifdef __cplusplus 197 } 198 #endif 199 200 #endif /* _RTE_BUS_PCI_H_ */ 201