- for (j = 0; j != nb_maps && (phaddr != maps[j].phaddr ||
- dev->mem_resource[i].len != maps[j].size);
- j++)
- ;
-
- /* if matching map is found, then use it */
- if (j != nb_maps) {
- int fail = 0;
-
- /* update devname for mmap */
- snprintf(devname, sizeof(devname),
- SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/resource%d",
- loc->domain, loc->bus, loc->devid, loc->function,
- i);
-
- /*
- * open resource file, to mmap it
- */
- fd = open(devname, O_RDWR);
- if (fd < 0) {
- RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
- devname, strerror(errno));
- return -1;
- }
-
- if (maps[j].addr != NULL)
- fail = 1;
- else {
- /* try mapping somewhere close to the end of hugepages */
- if (pci_map_addr == NULL)
- pci_map_addr = pci_find_max_end_va();
-
- mapaddr = pci_map_resource(pci_map_addr, fd, 0,
- (size_t)maps[j].size, 0);
- if (mapaddr == MAP_FAILED)
- fail = 1;
-
- pci_map_addr = RTE_PTR_ADD(mapaddr, (size_t) maps[j].size);
- }
-
- maps[j].path = rte_malloc(NULL, strlen(devname) + 1, 0);
- if (maps[j].path == NULL)
- fail = 1;
-
- if (fail) {
- rte_free(uio_res);
- close(fd);
- return -1;
- }
- close(fd);
-
- maps[j].addr = mapaddr;
- maps[j].offset = 0;
- strcpy(maps[j].path, devname);
- dev->mem_resource[i].addr = mapaddr;
+ /* open and read addresses of the corresponding resource in sysfs */
+ snprintf(filename, sizeof(filename), "%s/" PCI_PRI_FMT "/resource",
+ pci_get_sysfs_path(), dev->addr.domain, dev->addr.bus,
+ dev->addr.devid, dev->addr.function);
+ f = fopen(filename, "r");
+ if (f == NULL) {
+ RTE_LOG(ERR, EAL, "Cannot open sysfs resource: %s\n",
+ strerror(errno));
+ return -1;
+ }
+ for (i = 0; i < bar + 1; i++) {
+ if (fgets(buf, sizeof(buf), f) == NULL) {
+ RTE_LOG(ERR, EAL, "Cannot read sysfs resource\n");
+ goto error;