[PATCH] Add mmap

Vijay Kumar Banerjee vijaykumar9597 at gmail.com
Tue Jul 16 14:29:42 UTC 2019


---
 freebsd/sys/kern/kern_conf.c       |  8 ++++----
 freebsd/sys/sys/conf.h             |  2 +-
 rtemsbsd/include/machine/vm.h      |  2 ++
 rtemsbsd/sys/fs/devfs/devfs_devs.c | 10 ++++++++++
 4 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/freebsd/sys/kern/kern_conf.c b/freebsd/sys/kern/kern_conf.c
index 92237d9d..560a450a 100644
--- a/freebsd/sys/kern/kern_conf.c
+++ b/freebsd/sys/kern/kern_conf.c
@@ -328,8 +328,8 @@ static struct cdevsw dead_cdevsw = {
 	.d_write =	dead_write,
 	.d_ioctl =	dead_ioctl,
 	.d_poll =	dead_poll,
-#ifndef __rtems__
 	.d_mmap =	dead_mmap,
+#ifndef __rtems__
 	.d_strategy =	dead_strategy,
 #endif /* __rtems__ */
 	.d_name =	"dead",
@@ -522,7 +522,6 @@ giant_kqfilter(struct cdev *dev, struct knote *kn)
 	return (retval);
 }
 
-#ifndef __rtems__
 static int
 giant_mmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr, int nprot,
     vm_memattr_t *memattr)
@@ -541,6 +540,7 @@ giant_mmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr, int nprot,
 	return (retval);
 }
 
+#ifndef __rtems__
 static int
 giant_mmap_single(struct cdev *dev, vm_ooffset_t *offset, vm_size_t size,
     vm_object_t *object, int nprot)
@@ -667,8 +667,8 @@ prep_cdevsw(struct cdevsw *devsw, int flags)
 		devsw->d_write = dead_write;
 		devsw->d_ioctl = dead_ioctl;
 		devsw->d_poll = dead_poll;
-#ifndef __rtems__
 		devsw->d_mmap = dead_mmap;
+#ifndef __rtems__
 		devsw->d_mmap_single = dead_mmap_single;
 		devsw->d_strategy = dead_strategy;
 		devsw->d_dump = dead_dump;
@@ -702,8 +702,8 @@ prep_cdevsw(struct cdevsw *devsw, int flags)
 	FIXUP(d_write,		no_write,	giant_write);
 	FIXUP(d_ioctl,		no_ioctl,	giant_ioctl);
 	FIXUP(d_poll,		no_poll,	giant_poll);
-#ifndef __rtems__
 	FIXUP(d_mmap,		no_mmap,	giant_mmap);
+#ifndef __rtems__
 	FIXUP(d_strategy,	no_strategy,	giant_strategy);
 #endif /* __rtems__ */
 	FIXUP(d_kqfilter,	no_kqfilter,	giant_kqfilter);
diff --git a/freebsd/sys/sys/conf.h b/freebsd/sys/sys/conf.h
index 4ace162f..c0a66442 100644
--- a/freebsd/sys/sys/conf.h
+++ b/freebsd/sys/sys/conf.h
@@ -209,8 +209,8 @@ struct cdevsw {
 	d_write_t		*d_write;
 	d_ioctl_t		*d_ioctl;
 	d_poll_t		*d_poll;
-#ifndef __rtems__
 	d_mmap_t		*d_mmap;
+#ifndef __rtems__
 	d_strategy_t		*d_strategy;
 	dumper_t		*d_dump;
 #endif /* __rtems__ */
diff --git a/rtemsbsd/include/machine/vm.h b/rtemsbsd/include/machine/vm.h
index e69de29b..351b7472 100644
--- a/rtemsbsd/include/machine/vm.h
+++ b/rtemsbsd/include/machine/vm.h
@@ -0,0 +1,2 @@
+#define VM_MEMATTR_DEFAULT 0
+#define VM_MEMATTR_UNCACHEABLE 1
diff --git a/rtemsbsd/sys/fs/devfs/devfs_devs.c b/rtemsbsd/sys/fs/devfs/devfs_devs.c
index 7c697b0a..34105cf2 100644
--- a/rtemsbsd/sys/fs/devfs/devfs_devs.c
+++ b/rtemsbsd/sys/fs/devfs/devfs_devs.c
@@ -387,6 +387,15 @@ devfs_imfs_kqfilter(rtems_libio_t *iop, struct knote *kn)
 	return error;
 }
 
+static int
+devfs_imfs_mmap(rtems_libio_t *iop, void **addr, size_t len, int prot,
+    off_t off)
+{
+	struct cdev *cdev = devfs_imfs_get_context_by_iop(iop);
+
+	return (cdev->si_devsw->d_mmap( cdev, off, (vm_paddr_t *) addr, prot, VM_MEMATTR_DEFAULT));
+}
+
 static const rtems_filesystem_file_handlers_r devfs_imfs_handlers = {
 	.open_h = devfs_imfs_open,
 	.close_h = devfs_imfs_close,
@@ -403,6 +412,7 @@ static const rtems_filesystem_file_handlers_r devfs_imfs_handlers = {
 	.kqfilter_h = devfs_imfs_kqfilter,
 	.readv_h = devfs_imfs_readv,
 	.writev_h = devfs_imfs_writev,
+	.mmap_h = devfs_imfs_mmap,
 };
 
 static const IMFS_node_control devfs_imfs_control = IMFS_GENERIC_INITIALIZER(
-- 
2.20.1




More information about the devel mailing list