1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2015 Intel Corporation.
3 * Copyright 2013-2014 6WIND S.A.
23 #include <sys/queue.h>
27 #include <rte_debug.h>
28 #include <rte_interrupts.h>
30 /** Formatting string for PCI device identifier: Ex: 0000:00:01.0 */
31 #define PCI_PRI_FMT "%.4" PRIx16 ":%.2" PRIx8 ":%.2" PRIx8 ".%" PRIx8
32 #define PCI_PRI_STR_SIZE sizeof("XXXXXXXX:XX:XX.X")
34 /** Short formatting string, without domain, for PCI device: Ex: 00:01.0 */
35 #define PCI_SHORT_PRI_FMT "%.2" PRIx8 ":%.2" PRIx8 ".%" PRIx8
37 /** Nb. of values in PCI device identifier format string. */
38 #define PCI_FMT_NVAL 4
40 /** Nb. of values in PCI resource format. */
41 #define PCI_RESOURCE_FMT_NVAL 3
43 /** Maximum number of PCI resources. */
44 #define PCI_MAX_RESOURCE 6
47 * A structure describing an ID for a PCI driver. Each driver provides a
48 * table of these IDs for each device that it supports.
51 uint32_t class_id; /**< Class ID or RTE_CLASS_ANY_ID. */
52 uint16_t vendor_id; /**< Vendor ID or PCI_ANY_ID. */
53 uint16_t device_id; /**< Device ID or PCI_ANY_ID. */
54 uint16_t subsystem_vendor_id; /**< Subsystem vendor ID or PCI_ANY_ID. */
55 uint16_t subsystem_device_id; /**< Subsystem device ID or PCI_ANY_ID. */
59 * A structure describing the location of a PCI device.
62 uint32_t domain; /**< Device domain */
63 uint8_t bus; /**< Device bus */
64 uint8_t devid; /**< Device ID */
65 uint8_t function; /**< Device function. */
68 /** Any PCI device identifier (vendor, device, ...) */
69 #define PCI_ANY_ID (0xffff)
70 #define RTE_CLASS_ANY_ID (0xffffff)
73 * A structure describing a PCI mapping.
83 struct pci_msix_table {
90 * A structure describing a mapped PCI resource.
91 * For multi-process we need to reproduce all PCI mappings in secondary
92 * processes, so save them in a tailq.
94 struct mapped_pci_resource {
95 TAILQ_ENTRY(mapped_pci_resource) next;
97 struct rte_pci_addr pci_addr;
100 struct pci_map maps[PCI_MAX_RESOURCE];
101 struct pci_msix_table msix_table;
105 /** mapped pci device list */
106 TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
109 * Utility function to write a pci device name, this device name can later be
110 * used to retrieve the corresponding rte_pci_addr using eal_parse_pci_*
114 * The PCI Bus-Device-Function address
116 * The output buffer string
118 * The output buffer size
120 void rte_pci_device_name(const struct rte_pci_addr *addr,
121 char *output, size_t size);
124 * Utility function to compare two PCI device addresses.
127 * The PCI Bus-Device-Function address to compare
129 * The PCI Bus-Device-Function address to compare
131 * 0 on equal PCI address.
132 * Positive on addr is greater than addr2.
133 * Negative on addr is less than addr2, or error.
135 int rte_pci_addr_cmp(const struct rte_pci_addr *addr,
136 const struct rte_pci_addr *addr2);
140 * Utility function to parse a string into a PCI location.
143 * The string to parse
145 * The reference to the structure where the location
151 int rte_pci_addr_parse(const char *str, struct rte_pci_addr *addr);
154 * Map a particular resource from a file.
156 * @param requested_addr
157 * The starting address for the new mapping range.
159 * The file descriptor.
161 * The offset for the mapping range.
163 * The size for the mapping range.
164 * @param additional_flags
165 * The additional flags for the mapping range.
167 * - On success, the function returns a pointer to the mapped area.
168 * - On error, the value MAP_FAILED is returned.
170 void *pci_map_resource(void *requested_addr, int fd, off_t offset,
171 size_t size, int additional_flags);
174 * Unmap a particular resource.
176 * @param requested_addr
177 * The address for the unmapping range.
179 * The size for the unmapping range.
181 void pci_unmap_resource(void *requested_addr, size_t size);
187 #endif /* _RTE_PCI_H_ */