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