/* open /sys/bus/pci/devices/AAAA:BB:CC.D/driver */
snprintf(filename, sizeof(filename),
- SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/driver/unbind",
- loc->domain, loc->bus, loc->devid, loc->function);
+ "%s/" PCI_PRI_FMT "/driver/unbind", pci_get_sysfs_path(),
+ loc->domain, loc->bus, loc->devid, loc->function);
f = fopen(filename, "w");
if (f == NULL) /* device was not bound */
return RTE_PTR_ADD(last->addr, last->len);
}
-/* parse the "resource" sysfs file */
+/* parse one line of the "resource" sysfs file (note that the 'line'
+ * string is modified)
+ */
static int
-pci_parse_sysfs_resource(const char *filename, struct rte_pci_device *dev)
+pci_parse_one_sysfs_resource(char *line, size_t len, uint64_t *phys_addr,
+ uint64_t *end_addr, uint64_t *flags)
{
- FILE *f;
- char buf[BUFSIZ];
union pci_resource_info {
struct {
char *phys_addr;
};
char *ptrs[PCI_RESOURCE_FMT_NVAL];
} res_info;
+
+ if (rte_strsplit(line, len, res_info.ptrs, 3, ' ') != 3) {
+ RTE_LOG(ERR, EAL,
+ "%s(): bad resource format\n", __func__);
+ return -1;
+ }
+ errno = 0;
+ *phys_addr = strtoull(res_info.phys_addr, NULL, 16);
+ *end_addr = strtoull(res_info.end_addr, NULL, 16);
+ *flags = strtoull(res_info.flags, NULL, 16);
+ if (errno != 0) {
+ RTE_LOG(ERR, EAL,
+ "%s(): bad resource format\n", __func__);
+ return -1;
+ }
+
+ return 0;
+}
+
+/* parse the "resource" sysfs file */
+static int
+pci_parse_sysfs_resource(const char *filename, struct rte_pci_device *dev)
+{
+ FILE *f;
+ char buf[BUFSIZ];
int i;
uint64_t phys_addr, end_addr, flags;
"%s(): cannot read resource\n", __func__);
goto error;
}
-
- if (rte_strsplit(buf, sizeof(buf), res_info.ptrs, 3, ' ') != 3) {
- RTE_LOG(ERR, EAL,
- "%s(): bad resource format\n", __func__);
- goto error;
- }
- errno = 0;
- phys_addr = strtoull(res_info.phys_addr, NULL, 16);
- end_addr = strtoull(res_info.end_addr, NULL, 16);
- flags = strtoull(res_info.flags, NULL, 16);
- if (errno != 0) {
- RTE_LOG(ERR, EAL,
- "%s(): bad resource format\n", __func__);
+ if (pci_parse_one_sysfs_resource(buf, sizeof(buf), &phys_addr,
+ &end_addr, &flags) < 0)
goto error;
- }
if (flags & IORESOURCE_MEM) {
dev->mem_resource[i].phys_addr = phys_addr;
}
dev->id.subsystem_device_id = (uint16_t)tmp;
+ /* get class_id */
+ snprintf(filename, sizeof(filename), "%s/class",
+ dirname);
+ if (eal_parse_sysfs_value(filename, &tmp) < 0) {
+ free(dev);
+ return -1;
+ }
+ /* the least 24 bits are valid: class, subclass, program interface */
+ dev->id.class_id = (uint32_t)tmp & RTE_CLASS_ANY_ID;
+
/* get max_vfs */
dev->max_vfs = 0;
snprintf(filename, sizeof(filename), "%s/max_vfs", dirname);
uint16_t domain;
uint8_t bus, devid, function;
- dir = opendir(SYSFS_PCI_DEVICES);
+ dir = opendir(pci_get_sysfs_path());
if (dir == NULL) {
RTE_LOG(ERR, EAL, "%s(): opendir failed: %s\n",
__func__, strerror(errno));
&bus, &devid, &function) != 0)
continue;
- snprintf(dirname, sizeof(dirname), "%s/%s", SYSFS_PCI_DEVICES,
- e->d_name);
+ snprintf(dirname, sizeof(dirname), "%s/%s",
+ pci_get_sysfs_path(), e->d_name);
if (pci_scan_one(dirname, domain, bus, devid, function) < 0)
goto error;
}
return -1;
}
-#ifdef RTE_PCI_CONFIG
-/*
- * It is deprecated, all its configurations have been moved into
- * each PMD respectively.
- */
-void
-pci_config_space_set(__rte_unused struct rte_pci_device *dev)
-{
- RTE_LOG(DEBUG, EAL, "Nothing here, as it is deprecated\n");
-}
-#endif
-
/* Read PCI config space. */
int rte_eal_pci_read_config(const struct rte_pci_device *device,
void *buf, size_t len, off_t offset)
break;
#endif
case RTE_KDRV_IGB_UIO:
+ ret = pci_uio_ioport_map(dev, bar, p);
+ break;
case RTE_KDRV_UIO_GENERIC:
+#if defined(RTE_ARCH_X86)
+ ret = pci_ioport_map(dev, bar, p);
+#else
ret = pci_uio_ioport_map(dev, bar, p);
+#endif
break;
- default:
+ case RTE_KDRV_NONE:
#if defined(RTE_ARCH_X86)
ret = pci_ioport_map(dev, bar, p);
#endif
break;
+ default:
+ break;
}
if (!ret)
break;
#endif
case RTE_KDRV_IGB_UIO:
+ pci_uio_ioport_read(p, data, len, offset);
+ break;
case RTE_KDRV_UIO_GENERIC:
pci_uio_ioport_read(p, data, len, offset);
break;
- default:
+ case RTE_KDRV_NONE:
#if defined(RTE_ARCH_X86)
- /* special case for x86 ... */
pci_uio_ioport_read(p, data, len, offset);
#endif
break;
+ default:
+ break;
}
}
break;
#endif
case RTE_KDRV_IGB_UIO:
+ pci_uio_ioport_write(p, data, len, offset);
+ break;
case RTE_KDRV_UIO_GENERIC:
pci_uio_ioport_write(p, data, len, offset);
break;
- default:
+ case RTE_KDRV_NONE:
#if defined(RTE_ARCH_X86)
- /* special case for x86 ... */
pci_uio_ioport_write(p, data, len, offset);
#endif
break;
+ default:
+ break;
}
}
int
rte_eal_pci_ioport_unmap(struct rte_pci_ioport *p)
{
- int ret;
+ int ret = -1;
switch (p->dev->kdrv) {
#ifdef VFIO_PRESENT
case RTE_KDRV_VFIO:
- ret = -1;
if (pci_vfio_is_enabled())
ret = pci_vfio_ioport_unmap(p);
break;
#endif
case RTE_KDRV_IGB_UIO:
- case RTE_KDRV_UIO_GENERIC:
ret = pci_uio_ioport_unmap(p);
break;
- default:
+ case RTE_KDRV_UIO_GENERIC:
#if defined(RTE_ARCH_X86)
- /* special case for x86 ... nothing to do */
ret = 0;
#else
- ret = -1;
+ ret = pci_uio_ioport_unmap(p);
#endif
break;
+ case RTE_KDRV_NONE:
+#if defined(RTE_ARCH_X86)
+ ret = 0;
+#endif
+ break;
+ default:
+ break;
}
return ret;