02e2fb44367f224e8785d9e2d3b4890cef5d85e0
[dpdk.git] / drivers / bus / pci / private.h
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 struct rte_pci_driver;
14 struct rte_pci_device;
15
16 /**
17  * Probe the PCI bus
18  *
19  * @return
20  *   - 0 on success.
21  *   - !0 on error.
22  */
23 int
24 rte_pci_probe(void);
25
26 /**
27  * Scan the content of the PCI bus, and the devices in the devices
28  * list
29  *
30  * @return
31  *  0 on success, negative on error
32  */
33 int rte_pci_scan(void);
34
35 /**
36  * Probe the single PCI device.
37  *
38  * Scan the content of the PCI bus, and find the pci device specified by pci
39  * address, then call the probe() function for registered driver that has a
40  * matching entry in its id_table for discovered device.
41  *
42  * @param addr
43  *      The PCI Bus-Device-Function address to probe.
44  * @return
45  *   - 0 on success.
46  *   - Negative on error.
47  */
48 int rte_pci_probe_one(const struct rte_pci_addr *addr);
49
50 /**
51  * Close the single PCI device.
52  *
53  * Scan the content of the PCI bus, and find the pci device specified by pci
54  * address, then call the remove() function for registered driver that has a
55  * matching entry in its id_table for discovered device.
56  *
57  * @param addr
58  *      The PCI Bus-Device-Function address to close.
59  * @return
60  *   - 0 on success.
61  *   - Negative on error.
62  */
63 int rte_pci_detach(const struct rte_pci_addr *addr);
64
65 /**
66  * Find the name of a PCI device.
67  */
68 void
69 pci_name_set(struct rte_pci_device *dev);
70
71 /**
72  * Add a PCI device to the PCI Bus (append to PCI Device list). This function
73  * also updates the bus references of the PCI Device (and the generic device
74  * object embedded within.
75  *
76  * @param pci_dev
77  *      PCI device to add
78  * @return void
79  */
80 void rte_pci_add_device(struct rte_pci_device *pci_dev);
81
82 /**
83  * Insert a PCI device in the PCI Bus at a particular location in the device
84  * list. It also updates the PCI Bus reference of the new devices to be
85  * inserted.
86  *
87  * @param exist_pci_dev
88  *      Existing PCI device in PCI Bus
89  * @param new_pci_dev
90  *      PCI device to be added before exist_pci_dev
91  * @return void
92  */
93 void rte_pci_insert_device(struct rte_pci_device *exist_pci_dev,
94                 struct rte_pci_device *new_pci_dev);
95
96 /**
97  * Update a pci device object by asking the kernel for the latest information.
98  *
99  * This function is private to EAL.
100  *
101  * @param addr
102  *      The PCI Bus-Device-Function address to look for
103  * @return
104  *   - 0 on success.
105  *   - negative on error.
106  */
107 int pci_update_device(const struct rte_pci_addr *addr);
108
109 /**
110  * Unbind kernel driver for this device
111  *
112  * This function is private to EAL.
113  *
114  * @return
115  *   0 on success, negative on error
116  */
117 int pci_unbind_kernel_driver(struct rte_pci_device *dev);
118
119 /**
120  * Map the PCI resource of a PCI device in virtual memory
121  *
122  * This function is private to EAL.
123  *
124  * @return
125  *   0 on success, negative on error
126  */
127 int pci_uio_map_resource(struct rte_pci_device *dev);
128
129 /**
130  * Unmap the PCI resource of a PCI device
131  *
132  * This function is private to EAL.
133  */
134 void pci_uio_unmap_resource(struct rte_pci_device *dev);
135
136 /**
137  * Allocate uio resource for PCI device
138  *
139  * This function is private to EAL.
140  *
141  * @param dev
142  *   PCI device to allocate uio resource
143  * @param uio_res
144  *   Pointer to uio resource.
145  *   If the function returns 0, the pointer will be filled.
146  * @return
147  *   0 on success, negative on error
148  */
149 int pci_uio_alloc_resource(struct rte_pci_device *dev,
150                 struct mapped_pci_resource **uio_res);
151
152 /**
153  * Free uio resource for PCI device
154  *
155  * This function is private to EAL.
156  *
157  * @param dev
158  *   PCI device to free uio resource
159  * @param uio_res
160  *   Pointer to uio resource.
161  */
162 void pci_uio_free_resource(struct rte_pci_device *dev,
163                 struct mapped_pci_resource *uio_res);
164
165 /**
166  * Map device memory to uio resource
167  *
168  * This function is private to EAL.
169  *
170  * @param dev
171  *   PCI device that has memory information.
172  * @param res_idx
173  *   Memory resource index of the PCI device.
174  * @param uio_res
175  *  uio resource that will keep mapping information.
176  * @param map_idx
177  *   Mapping information index of the uio resource.
178  * @return
179  *   0 on success, negative on error
180  */
181 int pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
182                 struct mapped_pci_resource *uio_res, int map_idx);
183
184 /*
185  * Match the PCI Driver and Device using the ID Table
186  *
187  * @param pci_drv
188  *      PCI driver from which ID table would be extracted
189  * @param pci_dev
190  *      PCI device to match against the driver
191  * @return
192  *      1 for successful match
193  *      0 for unsuccessful match
194  */
195 int
196 rte_pci_match(const struct rte_pci_driver *pci_drv,
197               const struct rte_pci_device *pci_dev);
198
199 /**
200  * Get iommu class of PCI devices on the bus.
201  * And return their preferred iova mapping mode.
202  *
203  * @return
204  *   - enum rte_iova_mode.
205  */
206 enum rte_iova_mode
207 rte_pci_get_iommu_class(void);
208
209 #endif /* _PCI_PRIVATE_H_ */