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 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'pci-arbiter/func_files.c') 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; } -- cgit v1.2.3