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