aboutsummaryrefslogtreecommitdiff
path: root/pci-arbiter/netfs_impl.c
diff options
context:
space:
mode:
authorJoan Lledó <jlledom@member.fsf.org>2021-12-19 12:26:47 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2021-12-25 21:32:04 +0100
commit0fb7bdd65cb934e7d854aa333fec8f0e0cdf8b20 (patch)
treeabedd788f25680e2688563713c6709e3ec002a99 /pci-arbiter/netfs_impl.c
parent6f68c39ee5f08410936ba7e8cc3a15f120cec05c (diff)
downloadhurd-0fb7bdd65cb934e7d854aa333fec8f0e0cdf8b20.tar.gz
hurd-0fb7bdd65cb934e7d854aa333fec8f0e0cdf8b20.tar.bz2
hurd-0fb7bdd65cb934e7d854aa333fec8f0e0cdf8b20.zip
pci-arbiter: Implement memory mapping over region files
* pci-arbiter/Makefile: * Add device_map.c to sources * pci-arbiter/device_map.c: * pci-arbiter/device_map.h: * New module for device mapping * Relies on libpciaccess mapping methods * pci-arbiter/func_files.c: * io_region_file(): Use the new device mapping module * pci-arbiter/netfs_impl.c: * Implements netfs_get_filemap(): * Uses the device mapping module to map the region to the arbiter space * Calls the kernel RPC vm_region_create_proxy() to obtain the memory object proxy * Only region files are mapped for now Message-Id: <20211219112647.11512-4-jlledom@mailfence.com>
Diffstat (limited to 'pci-arbiter/netfs_impl.c')
-rw-r--r--pci-arbiter/netfs_impl.c48
1 files changed, 47 insertions, 1 deletions
diff --git a/pci-arbiter/netfs_impl.c b/pci-arbiter/netfs_impl.c
index 2087cfb4..8b4bd22b 100644
--- a/pci-arbiter/netfs_impl.c
+++ b/pci-arbiter/netfs_impl.c
@@ -29,11 +29,16 @@
#include <unistd.h>
#include <sys/mman.h>
#include <hurd/netfs.h>
+#include <hurd/paths.h>
+#include <mach/mach4.h>
+#include <device/device.h>
+
+#include <pciaccess.h>
#include "pcifs.h"
#include "ncache.h"
-#include <pciaccess.h>
#include "func_files.h"
+#include "device_map.h"
#define DIRENTS_CHUNK_SIZE (8*1024)
/* Returned directory entries are aligned to blocks this many bytes long.
@@ -563,3 +568,44 @@ netfs_node_norefs (struct node *node)
{
destroy_node (node);
}
+
+mach_port_t
+netfs_get_filemap (struct node *node, vm_prot_t prot)
+{
+ error_t err;
+ memory_object_t proxy;
+ vm_prot_t max_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);
+ region = &node->nn->ln->device->regions[reg_num];
+
+ /* Ensure the region is mapped */
+ err = device_map_region (node->nn->ln->device, region);
+ if (err)
+ return err;
+
+ /* 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)region->memory,
+ max_prot, region->size, &proxy);
+ if (err)
+ goto error;
+
+ return proxy;
+
+error:
+ errno = EOPNOTSUPP;
+ return MACH_PORT_NULL;
+}