summaryrefslogtreecommitdiff
path: root/pci-arbiter/func_files.c
diff options
context:
space:
mode:
authorJoan Lledó <jlledom@member.fsf.org>2020-09-13 20:16:16 +0200
committerJoan Lledó <jlledom@member.fsf.org>2020-09-13 20:16:16 +0200
commit88d7363db23f8dba06ed260e10b5c7f40538565c (patch)
tree834dbe1d7ec9d054d484b056c0bfb8ad2353122a /pci-arbiter/func_files.c
parent7f93e803bf9cbdf9db86d3f718f527880fada358 (diff)
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
Diffstat (limited to 'pci-arbiter/func_files.c')
-rw-r--r--pci-arbiter/func_files.c24
1 files changed, 20 insertions, 4 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 <assert.h>
#include <sys/io.h>
+#include <pciaccess.h>
+
/* 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, &region->memory);
+ if (err)
+ return err;
+ }
+ if (read)
+ memcpy (data, region->memory + offset, *len);
+ else
+ memcpy (region->memory + offset, data, *len);
+ }
- return 0;
+ return err;
}