DPDK  17.11.10
rte_pci.h
Go to the documentation of this file.
1 /*-
2  * BSD LICENSE
3  *
4  * Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
5  * Copyright 2013-2014 6WIND S.A.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in
16  * the documentation and/or other materials provided with the
17  * distribution.
18  * * Neither the name of Intel Corporation nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #ifndef _RTE_PCI_H_
36 #define _RTE_PCI_H_
37 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 #include <stdio.h>
49 #include <stdlib.h>
50 #include <limits.h>
51 #include <errno.h>
52 #include <sys/queue.h>
53 #include <stdint.h>
54 #include <inttypes.h>
55 
56 #include <rte_debug.h>
57 #include <rte_interrupts.h>
58 
60 #define PCI_PRI_FMT "%.4" PRIx16 ":%.2" PRIx8 ":%.2" PRIx8 ".%" PRIx8
61 #define PCI_PRI_STR_SIZE sizeof("XXXXXXXX:XX:XX.X")
62 
64 #define PCI_SHORT_PRI_FMT "%.2" PRIx8 ":%.2" PRIx8 ".%" PRIx8
65 
67 #define PCI_FMT_NVAL 4
68 
70 #define PCI_RESOURCE_FMT_NVAL 3
71 
73 #define PCI_MAX_RESOURCE 6
74 
79 struct rte_pci_id {
80  uint32_t class_id;
81  uint16_t vendor_id;
82  uint16_t device_id;
85 };
86 
90 struct rte_pci_addr {
91  uint32_t domain;
92  uint8_t bus;
93  uint8_t devid;
94  uint8_t function;
95 };
96 
98 #define PCI_ANY_ID (0xffff)
99 #define RTE_CLASS_ANY_ID (0xffffff)
100 
104 struct pci_map {
105  void *addr;
106  char *path;
107  uint64_t offset;
108  uint64_t size;
109  uint64_t phaddr;
110 };
111 
112 struct pci_msix_table {
113  int bar_index;
114  uint32_t offset;
115  uint32_t size;
116 };
117 
124  TAILQ_ENTRY(mapped_pci_resource) next;
125 
126  struct rte_pci_addr pci_addr;
127  char path[PATH_MAX];
128  int nb_maps;
129  struct pci_map maps[PCI_MAX_RESOURCE];
130  struct pci_msix_table msix_table;
131 };
132 
133 
135 TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
136 
151 int eal_parse_pci_BDF(const char *input, struct rte_pci_addr *dev_addr);
152 
166 int eal_parse_pci_DomBDF(const char *input, struct rte_pci_addr *dev_addr);
167 
180 void rte_pci_device_name(const struct rte_pci_addr *addr,
181  char *output, size_t size);
182 
196 int rte_eal_compare_pci_addr(const struct rte_pci_addr *addr,
197  const struct rte_pci_addr *addr2);
198 
211 int rte_pci_addr_cmp(const struct rte_pci_addr *addr,
212  const struct rte_pci_addr *addr2);
213 
214 
227 int rte_pci_addr_parse(const char *str, struct rte_pci_addr *addr);
228 
246 void *pci_map_resource(void *requested_addr, int fd, off_t offset,
247  size_t size, int additional_flags);
248 
257 void pci_unmap_resource(void *requested_addr, size_t size);
258 
259 #ifdef __cplusplus
260 }
261 #endif
262 
263 #endif /* _RTE_PCI_H_ */
int eal_parse_pci_BDF(const char *input, struct rte_pci_addr *dev_addr)
int rte_pci_addr_parse(const char *str, struct rte_pci_addr *addr)
int rte_eal_compare_pci_addr(const struct rte_pci_addr *addr, const struct rte_pci_addr *addr2)
uint16_t device_id
Definition: rte_pci.h:82
uint8_t bus
Definition: rte_pci.h:92
int eal_parse_pci_DomBDF(const char *input, struct rte_pci_addr *dev_addr)
uint32_t class_id
Definition: rte_pci.h:80
uint8_t devid
Definition: rte_pci.h:93
uint16_t subsystem_device_id
Definition: rte_pci.h:84
uint32_t domain
Definition: rte_pci.h:91
void rte_pci_device_name(const struct rte_pci_addr *addr, char *output, size_t size)
uint16_t subsystem_vendor_id
Definition: rte_pci.h:83
TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource)
void pci_unmap_resource(void *requested_addr, size_t size)
int rte_pci_addr_cmp(const struct rte_pci_addr *addr, const struct rte_pci_addr *addr2)
uint16_t vendor_id
Definition: rte_pci.h:81
void * pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size, int additional_flags)