aboutsummaryrefslogtreecommitdiff
path: root/pci-arbiter/netfs_impl.c
diff options
context:
space:
mode:
authorJoan Lledó <jlledom@member.fsf.org>2022-08-15 18:15:20 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2022-08-15 20:33:03 +0200
commit8171d2aa48184a4d1ed1299e1c87f1b898371688 (patch)
tree3fae659c5065eccf4a45864fca2e0038d76c4465 /pci-arbiter/netfs_impl.c
parentb6509385bb1dd2a6d47401465bfb98b6339c5c2b (diff)
downloadhurd-8171d2aa48184a4d1ed1299e1c87f1b898371688.tar.gz
hurd-8171d2aa48184a4d1ed1299e1c87f1b898371688.tar.bz2
hurd-8171d2aa48184a4d1ed1299e1c87f1b898371688.zip
Implement mapping for ROM files
* pci-arbiter/device_map.h: * pci-arbiter/device_map.c: * New function: device_map_rom * Copies the whole rom in the arbiter space. * pci-arbiter/pcifs.h: * struct pcifs_dirent: * New field to store the mapping address for each device rom. o pci-arbiter/func_files.h: * pci-arbiter/func_files.c: * read_rom_file: * Retrieves the rom contents from the local space instead of libpciaccess. * pci-arbiter/netfs_impl.c: * netfs_attempt_read:get_filemap_region * Update call to read_rom_file. * get_filemap_region: * Uses the old code at netfs_get_filemap to get a proxy to the device memory region. * get_filemap_rom: * Returns a proxy to the locally mapped device rom. * netfs_get_filemap: * Checks the requested file to map and calls get_filemap_rom, get_filemap_region or returns en error. Message-Id: <20220815161520.6059-2-jlledom@mailfence.com>
Diffstat (limited to 'pci-arbiter/netfs_impl.c')
-rw-r--r--pci-arbiter/netfs_impl.c68
1 files changed, 54 insertions, 14 deletions
diff --git a/pci-arbiter/netfs_impl.c b/pci-arbiter/netfs_impl.c
index b2630f01..b66f0019 100644
--- a/pci-arbiter/netfs_impl.c
+++ b/pci-arbiter/netfs_impl.c
@@ -509,7 +509,7 @@ netfs_attempt_read (struct iouser * cred, struct node * node,
}
else if (!strncmp (node->nn->ln->name, FILE_ROM_NAME, NAME_SIZE))
{
- err = read_rom_file (node->nn->ln->device, offset, len, data);
+ err = read_rom_file (node->nn->ln, offset, len, data);
if (!err)
/* Update atime */
UPDATE_TIMES (node->nn->ln, TOUCH_ATIME);
@@ -569,8 +569,8 @@ netfs_node_norefs (struct node *node)
destroy_node (node);
}
-mach_port_t
-netfs_get_filemap (struct node *node, vm_prot_t prot)
+static mach_port_t
+get_filemap_region (struct node *node, vm_prot_t prot)
{
error_t err;
memory_object_t proxy;
@@ -578,13 +578,6 @@ netfs_get_filemap (struct node *node, vm_prot_t prot)
size_t reg_num;
struct pci_mem_region *region;
- /* Only regions files can be mapped */
- if (strncmp
- (node->nn->ln->name, FILE_REGION_NAME, strlen (FILE_REGION_NAME)))
- {
- goto error;
- }
-
/* Get region info */
reg_num =
strtol (&node->nn->ln->name[strlen (node->nn->ln->name) - 1], 0, 16);
@@ -594,14 +587,42 @@ netfs_get_filemap (struct node *node, vm_prot_t prot)
err = device_map_region (node->nn->ln->device, region,
&node->nn->ln->region_maps[reg_num]);
if (err)
- return err;
+ goto error;
/* Create a new memory object proxy with the required protection */
max_prot = (VM_PROT_READ | VM_PROT_WRITE) & prot;
err =
- vm_region_create_proxy(mach_task_self (),
- (vm_address_t)node->nn->ln->region_maps[reg_num],
- max_prot, region->size, &proxy);
+ vm_region_create_proxy (mach_task_self (),
+ (vm_address_t) node->nn->ln->region_maps[reg_num],
+ max_prot, region->size, &proxy);
+ if (err)
+ goto error;
+
+ return proxy;
+
+error:
+ errno = EOPNOTSUPP;
+ return MACH_PORT_NULL;
+}
+
+static mach_port_t
+get_filemap_rom (struct node *node, vm_prot_t prot)
+{
+ error_t err;
+ memory_object_t proxy;
+ vm_prot_t max_prot;
+
+ /* Ensure the rom is mapped */
+ err = device_map_rom (node->nn->ln->device, &node->nn->ln->rom_map);
+ if (err)
+ goto error;
+
+ /* Create a new memory object proxy with the required protection */
+ max_prot = (VM_PROT_READ) & prot;
+ err =
+ vm_region_create_proxy (mach_task_self (),
+ (vm_address_t) node->nn->ln->rom_map,
+ max_prot, node->nn->ln->device->rom_size, &proxy);
if (err)
goto error;
@@ -611,3 +632,22 @@ error:
errno = EOPNOTSUPP;
return MACH_PORT_NULL;
}
+
+mach_port_t
+netfs_get_filemap (struct node *node, vm_prot_t prot)
+{
+ /* Only region and rom files can be mapped */
+ if (!strncmp
+ (node->nn->ln->name, FILE_REGION_NAME, strlen (FILE_REGION_NAME)))
+ {
+ return get_filemap_region (node, prot);
+ }
+
+ if (!strncmp (node->nn->ln->name, FILE_ROM_NAME, strlen (FILE_ROM_NAME)))
+ {
+ return get_filemap_rom (node, prot);
+ }
+
+ errno = EOPNOTSUPP;
+ return MACH_PORT_NULL;
+}