2283f0938c12cebcc433c3834c6e5470c5ab969f
[dpdk.git] / drivers / bus / pci / private.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2017 6WIND. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of 6WIND nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef _PCI_PRIVATE_H_
35 #define _PCI_PRIVATE_H_
36
37 #include <stdbool.h>
38 #include <stdio.h>
39 #include <rte_pci.h>
40 #include <rte_bus_pci.h>
41
42 struct rte_pci_driver;
43 struct rte_pci_device;
44
45 /**
46  * Probe the PCI bus
47  *
48  * @return
49  *   - 0 on success.
50  *   - !0 on error.
51  */
52 int
53 rte_pci_probe(void);
54
55 /**
56  * Scan the content of the PCI bus, and the devices in the devices
57  * list
58  *
59  * @return
60  *  0 on success, negative on error
61  */
62 int rte_pci_scan(void);
63
64 /**
65  * Probe the single PCI device.
66  *
67  * Scan the content of the PCI bus, and find the pci device specified by pci
68  * address, then call the probe() function for registered driver that has a
69  * matching entry in its id_table for discovered device.
70  *
71  * @param addr
72  *      The PCI Bus-Device-Function address to probe.
73  * @return
74  *   - 0 on success.
75  *   - Negative on error.
76  */
77 int rte_pci_probe_one(const struct rte_pci_addr *addr);
78
79 /**
80  * Close the single PCI device.
81  *
82  * Scan the content of the PCI bus, and find the pci device specified by pci
83  * address, then call the remove() function for registered driver that has a
84  * matching entry in its id_table for discovered device.
85  *
86  * @param addr
87  *      The PCI Bus-Device-Function address to close.
88  * @return
89  *   - 0 on success.
90  *   - Negative on error.
91  */
92 int rte_pci_detach(const struct rte_pci_addr *addr);
93
94 /**
95  * Find the name of a PCI device.
96  */
97 void
98 pci_name_set(struct rte_pci_device *dev);
99
100 /**
101  * Add a PCI device to the PCI Bus (append to PCI Device list). This function
102  * also updates the bus references of the PCI Device (and the generic device
103  * object embedded within.
104  *
105  * @param pci_dev
106  *      PCI device to add
107  * @return void
108  */
109 void rte_pci_add_device(struct rte_pci_device *pci_dev);
110
111 /**
112  * Insert a PCI device in the PCI Bus at a particular location in the device
113  * list. It also updates the PCI Bus reference of the new devices to be
114  * inserted.
115  *
116  * @param exist_pci_dev
117  *      Existing PCI device in PCI Bus
118  * @param new_pci_dev
119  *      PCI device to be added before exist_pci_dev
120  * @return void
121  */
122 void rte_pci_insert_device(struct rte_pci_device *exist_pci_dev,
123                 struct rte_pci_device *new_pci_dev);
124
125 /**
126  * Remove a PCI device from the PCI Bus. This sets to NULL the bus references
127  * in the PCI device object as well as the generic device object.
128  *
129  * @param pci_device
130  *      PCI device to be removed from PCI Bus
131  * @return void
132  */
133 void rte_pci_remove_device(struct rte_pci_device *pci_device);
134
135 /**
136  * Update a pci device object by asking the kernel for the latest information.
137  *
138  * This function is private to EAL.
139  *
140  * @param addr
141  *      The PCI Bus-Device-Function address to look for
142  * @return
143  *   - 0 on success.
144  *   - negative on error.
145  */
146 int pci_update_device(const struct rte_pci_addr *addr);
147
148 /**
149  * Unbind kernel driver for this device
150  *
151  * This function is private to EAL.
152  *
153  * @return
154  *   0 on success, negative on error
155  */
156 int pci_unbind_kernel_driver(struct rte_pci_device *dev);
157
158 /**
159  * Map the PCI resource of a PCI device in virtual memory
160  *
161  * This function is private to EAL.
162  *
163  * @return
164  *   0 on success, negative on error
165  */
166 int pci_uio_map_resource(struct rte_pci_device *dev);
167
168 /**
169  * Unmap the PCI resource of a PCI device
170  *
171  * This function is private to EAL.
172  */
173 void pci_uio_unmap_resource(struct rte_pci_device *dev);
174
175 /**
176  * Allocate uio resource for PCI device
177  *
178  * This function is private to EAL.
179  *
180  * @param dev
181  *   PCI device to allocate uio resource
182  * @param uio_res
183  *   Pointer to uio resource.
184  *   If the function returns 0, the pointer will be filled.
185  * @return
186  *   0 on success, negative on error
187  */
188 int pci_uio_alloc_resource(struct rte_pci_device *dev,
189                 struct mapped_pci_resource **uio_res);
190
191 /**
192  * Free uio resource for PCI device
193  *
194  * This function is private to EAL.
195  *
196  * @param dev
197  *   PCI device to free uio resource
198  * @param uio_res
199  *   Pointer to uio resource.
200  */
201 void pci_uio_free_resource(struct rte_pci_device *dev,
202                 struct mapped_pci_resource *uio_res);
203
204 /**
205  * Map device memory to uio resource
206  *
207  * This function is private to EAL.
208  *
209  * @param dev
210  *   PCI device that has memory information.
211  * @param res_idx
212  *   Memory resource index of the PCI device.
213  * @param uio_res
214  *  uio resource that will keep mapping information.
215  * @param map_idx
216  *   Mapping information index of the uio resource.
217  * @return
218  *   0 on success, negative on error
219  */
220 int pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
221                 struct mapped_pci_resource *uio_res, int map_idx);
222
223 /*
224  * Match the PCI Driver and Device using the ID Table
225  *
226  * @param pci_drv
227  *      PCI driver from which ID table would be extracted
228  * @param pci_dev
229  *      PCI device to match against the driver
230  * @return
231  *      1 for successful match
232  *      0 for unsuccessful match
233  */
234 int
235 rte_pci_match(const struct rte_pci_driver *pci_drv,
236               const struct rte_pci_device *pci_dev);
237
238 /**
239  * Get iommu class of PCI devices on the bus.
240  * And return their preferred iova mapping mode.
241  *
242  * @return
243  *   - enum rte_iova_mode.
244  */
245 enum rte_iova_mode
246 rte_pci_get_iommu_class(void);
247
248 #endif /* _PCI_PRIVATE_H_ */