MCPcopy Create free account
hub / github.com/F-Stack/f-stack / pci_uio_alloc_resource

Function pci_uio_alloc_resource

dpdk/drivers/bus/pci/bsd/pci.c:102–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100}
101
102int
103pci_uio_alloc_resource(struct rte_pci_device *dev,
104 struct mapped_pci_resource **uio_res)
105{
106 char devname[PATH_MAX]; /* contains the /dev/uioX */
107 struct rte_pci_addr *loc;
108 int fd;
109
110 loc = &dev->addr;
111
112 snprintf(devname, sizeof(devname), "/dev/uio@pci:%u:%u:%u",
113 dev->addr.bus, dev->addr.devid, dev->addr.function);
114
115 fd = open(devname, O_RDWR);
116 if (fd < 0) {
117 if (errno == ENOENT) {
118 RTE_LOG(WARNING, EAL, " "PCI_PRI_FMT" not managed by UIO driver, "
119 "skipping\n", loc->domain, loc->bus, loc->devid, loc->function);
120 return 1;
121 }
122 RTE_LOG(ERR, EAL, "Failed to open device file for " PCI_PRI_FMT " (%s)",
123 loc->domain, loc->bus, loc->devid, loc->function, devname);
124 return -1;
125 }
126
127 /* save fd if in primary process */
128 if (rte_intr_fd_set(dev->intr_handle, fd)) {
129 RTE_LOG(WARNING, EAL, "Failed to save fd");
130 goto error;
131 }
132
133 if (rte_intr_fd_get(dev->intr_handle) < 0) {
134 RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
135 devname, strerror(errno));
136 goto error;
137 }
138
139 if (rte_intr_type_set(dev->intr_handle, RTE_INTR_HANDLE_UIO))
140 goto error;
141
142 /* allocate the mapping details for secondary processes*/
143 *uio_res = rte_zmalloc("UIO_RES", sizeof(**uio_res), 0);
144 if (*uio_res == NULL) {
145 RTE_LOG(ERR, EAL,
146 "%s(): cannot store uio mmap details\n", __func__);
147 goto error;
148 }
149
150 strlcpy((*uio_res)->path, devname, sizeof((*uio_res)->path));
151 memcpy(&(*uio_res)->pci_addr, &dev->addr, sizeof((*uio_res)->pci_addr));
152
153 return 0;
154
155error:
156 pci_uio_free_resource(dev, *uio_res);
157 return -1;
158}
159

Callers 1

pci_uio_map_resourceFunction · 0.50

Calls 8

snprintfFunction · 0.85
rte_intr_fd_setFunction · 0.85
rte_intr_fd_getFunction · 0.85
rte_intr_type_setFunction · 0.85
rte_zmallocFunction · 0.85
pci_uio_free_resourceFunction · 0.70
strlcpyFunction · 0.50
memcpyFunction · 0.50

Tested by

no test coverage detected