-/* unbind kernel driver for this device */
-static int
-pci_unbind_kernel_driver(struct rte_pci_device *dev)
-{
- int n;
- FILE *f;
- char filename[PATH_MAX];
- char buf[BUFSIZ];
- struct rte_pci_addr *loc = &dev->addr;
-
- /* open /sys/bus/pci/devices/AAAA:BB:CC.D/driver */
- rte_snprintf(filename, sizeof(filename),
- SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/driver/unbind",
- loc->domain, loc->bus, loc->devid, loc->function);
-
- RTE_LOG(DEBUG, EAL, "unbind kernel driver %s\n", filename);
-
- f = fopen(filename, "w");
- if (f == NULL) /* device was not bound */
- return 0;
-
- n = rte_snprintf(buf, sizeof(buf), PCI_PRI_FMT "\n",
- loc->domain, loc->bus, loc->devid, loc->function);
- if ((n < 0) || (n >= (int)sizeof(buf))) {
- RTE_LOG(ERR, EAL, "%s(): rte_snprintf failed\n", __func__);
- goto error;
- }
- if (fwrite(buf, n, 1, f) == 0) {
- RTE_LOG(ERR, EAL, "%s(): could not write to %s\n", __func__,
- filename);
- goto error;
- }
-
- fclose(f);
- return 0;
-
-error:
- fclose(f);
- return -1;
-}
-
-static int
-pci_exit_process(struct rte_pci_device *dev)
-{
- if (munmap(dev->mem_resource.addr, dev->mem_resource.len) == -1){
- RTE_LOG(ERR, EAL, "Error with munmap\n");
- return -1;
- }
- if (close(dev->intr_handle.fd) == -1){
- RTE_LOG(ERR, EAL, "Error closing interrupt handle\n");
- return -1;
- }
- if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
- if (pci_unbind_kernel_driver(dev) < 0){
- RTE_LOG(ERR, EAL, "Error unbinding\n");
- return -1;
- }
- if (pci_bind_device(dev, dev->previous_dr) < 0){
- RTE_LOG(ERR, EAL, "Error binding\n");
- return -1;
- }
- }
-
- return 0;
-}
-
-static void
-pci_get_previous_driver_path(struct rte_pci_device *dev)
-{
- int n;
- char dev_path[PATH_MAX];
- char dr_path[PATH_MAX];
- struct rte_pci_addr *loc = &dev->addr;
-
- n = rte_snprintf(dev_path, sizeof(dev_path), SYSFS_PCI_DEVICES "/"
- PCI_PRI_FMT "/driver", loc->domain, loc->bus, loc->devid, loc->function );
- if ((n < 0) || (n >= (int)sizeof(dev_path)))
- RTE_LOG(ERR, EAL, "Cannot rte_snprintf device filepath\n");
-
- n = readlink(dev_path, dr_path, sizeof(dr_path));
- if ((n < 0) || (n >= (int)sizeof(dr_path))){
- RTE_LOG(ERR, EAL, "Cannot readlink driver filepath\n");
- dev->previous_dr[0] = '\0';
- return;
- }
- dr_path[n] = '\0';
-
- if (dr_path[0] != '/')
- n = rte_snprintf(dev->previous_dr, sizeof(dev->previous_dr),
- SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/%s",
- loc->domain, loc->bus, loc->devid, loc->function, dr_path);
- else
- n = rte_snprintf(dev->previous_dr, sizeof(dev->previous_dr),
- "%s", dr_path);
- if ((n < 0) || (n >= (int)sizeof(dev_path)))
- RTE_LOG(ERR, EAL, "Cannot rte_snprintf driver filepath\n");
-}
-