DPDK  20.08.0
rte_pci.h
Go to the documentation of this file.
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_PCI_H_
7 #define _RTE_PCI_H_
8 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 #include <stdio.h>
20 #include <limits.h>
21 #include <sys/queue.h>
22 #include <inttypes.h>
23 #include <sys/types.h>
24 
26 #define PCI_PRI_FMT "%.4" PRIx32 ":%.2" PRIx8 ":%.2" PRIx8 ".%" PRIx8
27 #define PCI_PRI_STR_SIZE sizeof("XXXXXXXX:XX:XX.X")
28 
30 #define PCI_SHORT_PRI_FMT "%.2" PRIx8 ":%.2" PRIx8 ".%" PRIx8
31 
33 #define PCI_FMT_NVAL 4
34 
36 #define PCI_RESOURCE_FMT_NVAL 3
37 
39 #define PCI_MAX_RESOURCE 6
40 
45 struct rte_pci_id {
46  uint32_t class_id;
47  uint16_t vendor_id;
48  uint16_t device_id;
51 };
52 
56 struct rte_pci_addr {
57  uint32_t domain;
58  uint8_t bus;
59  uint8_t devid;
60  uint8_t function;
61 };
62 
64 #define PCI_ANY_ID (0xffff)
65 #define RTE_CLASS_ANY_ID (0xffffff)
66 
70 struct pci_map {
71  void *addr;
72  char *path;
73  uint64_t offset;
74  uint64_t size;
75  uint64_t phaddr;
76 };
77 
78 struct pci_msix_table {
79  int bar_index;
80  uint32_t offset;
81  uint32_t size;
82 };
83 
90  TAILQ_ENTRY(mapped_pci_resource) next;
91 
92  struct rte_pci_addr pci_addr;
93  char path[PATH_MAX];
94  int nb_maps;
95  struct pci_map maps[PCI_MAX_RESOURCE];
96  struct pci_msix_table msix_table;
97 };
98 
99 
101 TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
102 
115 void rte_pci_device_name(const struct rte_pci_addr *addr,
116  char *output, size_t size);
117 
130 int rte_pci_addr_cmp(const struct rte_pci_addr *addr,
131  const struct rte_pci_addr *addr2);
132 
133 
146 int rte_pci_addr_parse(const char *str, struct rte_pci_addr *addr);
147 
165 void *pci_map_resource(void *requested_addr, int fd, off_t offset,
166  size_t size, int additional_flags);
167 
176 void pci_unmap_resource(void *requested_addr, size_t size);
177 
178 #ifdef __cplusplus
179 }
180 #endif
181 
182 #endif /* _RTE_PCI_H_ */
int rte_pci_addr_parse(const char *str, struct rte_pci_addr *addr)
uint16_t device_id
Definition: rte_pci.h:48
uint8_t bus
Definition: rte_pci.h:58
uint32_t class_id
Definition: rte_pci.h:46
uint8_t devid
Definition: rte_pci.h:59
uint16_t subsystem_device_id
Definition: rte_pci.h:50
uint32_t domain
Definition: rte_pci.h:57
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:49
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:47
void * pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size, int additional_flags)