353a1aba0e704dcf04327357301fc3a080b5d745
[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  * Close 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 remove() 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 close.
44  * @return
45  *   - 0 on success.
46  *   - Negative on error.
47  */
48 int rte_pci_detach(const struct rte_pci_addr *addr);
49
50 /**
51  * Find the name of a PCI device.
52  */
53 void
54 pci_name_set(struct rte_pci_device *dev);
55
56 /**
57  * Add a PCI device to the PCI Bus (append to PCI Device list). This function
58  * also updates the bus references of the PCI Device (and the generic device
59  * object embedded within.
60  *
61  * @param pci_dev
62  *      PCI device to add
63  * @return void
64  */
65 void rte_pci_add_device(struct rte_pci_device *pci_dev);
66
67 /**
68  * Insert a PCI device in the PCI Bus at a particular location in the device
69  * list. It also updates the PCI Bus reference of the new devices to be
70  * inserted.
71  *
72  * @param exist_pci_dev
73  *      Existing PCI device in PCI Bus
74  * @param new_pci_dev
75  *      PCI device to be added before exist_pci_dev
76  * @return void
77  */
78 void rte_pci_insert_device(struct rte_pci_device *exist_pci_dev,
79                 struct rte_pci_device *new_pci_dev);
80
81 /**
82  * Update a pci device object by asking the kernel for the latest information.
83  *
84  * This function is private to EAL.
85  *
86  * @param addr
87  *      The PCI Bus-Device-Function address to look for
88  * @return
89  *   - 0 on success.
90  *   - negative on error.
91  */
92 int pci_update_device(const struct rte_pci_addr *addr);
93
94 /**
95  * Map the PCI resource of a PCI device in virtual memory
96  *
97  * This function is private to EAL.
98  *
99  * @return
100  *   0 on success, negative on error
101  */
102 int pci_uio_map_resource(struct rte_pci_device *dev);
103
104 /**
105  * Unmap the PCI resource of a PCI device
106  *
107  * This function is private to EAL.
108  */
109 void pci_uio_unmap_resource(struct rte_pci_device *dev);
110
111 /**
112  * Allocate uio resource for PCI device
113  *
114  * This function is private to EAL.
115  *
116  * @param dev
117  *   PCI device to allocate uio resource
118  * @param uio_res
119  *   Pointer to uio resource.
120  *   If the function returns 0, the pointer will be filled.
121  * @return
122  *   0 on success, negative on error
123  */
124 int pci_uio_alloc_resource(struct rte_pci_device *dev,
125                 struct mapped_pci_resource **uio_res);
126
127 /**
128  * Free uio resource for PCI device
129  *
130  * This function is private to EAL.
131  *
132  * @param dev
133  *   PCI device to free uio resource
134  * @param uio_res
135  *   Pointer to uio resource.
136  */
137 void pci_uio_free_resource(struct rte_pci_device *dev,
138                 struct mapped_pci_resource *uio_res);
139
140 /**
141  * Map device memory to uio resource
142  *
143  * This function is private to EAL.
144  *
145  * @param dev
146  *   PCI device that has memory information.
147  * @param res_idx
148  *   Memory resource index of the PCI device.
149  * @param uio_res
150  *  uio resource that will keep mapping information.
151  * @param map_idx
152  *   Mapping information index of the uio resource.
153  * @return
154  *   0 on success, negative on error
155  */
156 int pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
157                 struct mapped_pci_resource *uio_res, int map_idx);
158
159 /*
160  * Match the PCI Driver and Device using the ID Table
161  *
162  * @param pci_drv
163  *      PCI driver from which ID table would be extracted
164  * @param pci_dev
165  *      PCI device to match against the driver
166  * @return
167  *      1 for successful match
168  *      0 for unsuccessful match
169  */
170 int
171 rte_pci_match(const struct rte_pci_driver *pci_drv,
172               const struct rte_pci_device *pci_dev);
173
174 /**
175  * Get iommu class of PCI devices on the bus.
176  * And return their preferred iova mapping mode.
177  *
178  * @return
179  *   - enum rte_iova_mode.
180  */
181 enum rte_iova_mode
182 rte_pci_get_iommu_class(void);
183
184 #endif /* _PCI_PRIVATE_H_ */