From 88d7363db23f8dba06ed260e10b5c7f40538565c Mon Sep 17 00:00:00 2001 From: Joan Lledó Date: Sun, 13 Sep 2020 20:16:16 +0200 Subject: pci-arbiter: Probe devices and map regions This adapts the arbiter to a bug fixed in libpciaccess. We were relying on the library to probe devices and map regions but it's the arbiter who should do it. * pci-arbiter/pcifs.c: * create_fs_tree(): probe the device to find regions and rom * pci-arbiter/func_files.c: * io_region_file(): map region on the first access attempt --- pci-arbiter/func_files.c | 24 ++++++++++++++++++++---- pci-arbiter/pcifs.c | 15 ++++++++++----- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/pci-arbiter/func_files.c b/pci-arbiter/func_files.c index c7da6978..d7d8c5d5 100644 --- a/pci-arbiter/func_files.c +++ b/pci-arbiter/func_files.c @@ -28,6 +28,8 @@ #include #include +#include + /* Read or write a block of data from/to the configuration space */ static error_t config_block_op (struct pci_device *dev, off_t offset, size_t * len, @@ -179,6 +181,7 @@ error_t io_region_file (struct pcifs_dirent * e, off_t offset, size_t * len, void *data, int read) { + error_t err = 0; size_t reg_num; struct pci_mem_region *region; @@ -197,10 +200,23 @@ io_region_file (struct pcifs_dirent * e, off_t offset, size_t * len, if (region->is_IO) region_block_ioport_op (region->base_addr, offset, len, data, read); - else if (read) - memcpy (data, region->memory + offset, *len); else - memcpy (region->memory + offset, data, *len); + { + /* First check whether the region is already mapped */ + if (region->memory == 0) + { + /* Not mapped, try to map it now */ + err = + pci_device_map_range (e->device, region->base_addr, region->size, + PCI_DEV_MAP_FLAG_WRITABLE, ®ion->memory); + if (err) + return err; + } + if (read) + memcpy (data, region->memory + offset, *len); + else + memcpy (region->memory + offset, data, *len); + } - return 0; + return err; } diff --git a/pci-arbiter/pcifs.c b/pci-arbiter/pcifs.c index 615e8753..0535779e 100644 --- a/pci-arbiter/pcifs.c +++ b/pci-arbiter/pcifs.c @@ -180,12 +180,17 @@ create_fs_tree (struct pcifs * fs) nentries += 2; /* func dir + config */ - for (j = 0; j < 6; j++) - if (device->regions[j].size > 0) - nentries++; /* + memory region */ + /* Probe the device to find regions and rom */ + err = pci_device_probe (device); + if (!err) + { + for (j = 0; j < 6; j++) + if (device->regions[j].size > 0) + nentries++; /* + memory region */ - if (device->rom_size) - nentries++; /* + rom */ + if (device->rom_size) + nentries++; /* + rom */ + } } pci_iterator_destroy(iter); -- cgit v1.2.3