<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 17 Jul 2019 at 09:03, Vijay Kumar Banerjee <<a href="mailto:vijaykumar9597@gmail.com">vijaykumar9597@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">---<br>
 freebsd/sys/kern/kern_conf.c       |  8 +++----<br>
 freebsd/sys/sys/conf.h             |  2 +-<br>
 rtemsbsd/include/machine/vm.h      |  2 ++<br>
 rtemsbsd/sys/fs/devfs/devfs_devs.c | 34 ++++++++++++++++++++++++++++++<br>
 testsuite/cdev01/test_cdev.c       | 17 ++++++++++++++-<br>
 testsuite/cdev01/test_cdev01.h     |  3 ++-<br>
 testsuite/cdev01/test_main.c       |  4 ++++<br>
 7 files changed, 63 insertions(+), 7 deletions(-)<br>
<br>
diff --git a/freebsd/sys/kern/kern_conf.c b/freebsd/sys/kern/kern_conf.c<br>
index 92237d9d..560a450a 100644<br>
--- a/freebsd/sys/kern/kern_conf.c<br>
+++ b/freebsd/sys/kern/kern_conf.c<br>
@@ -328,8 +328,8 @@ static struct cdevsw dead_cdevsw = {<br>
        .d_write =      dead_write,<br>
        .d_ioctl =      dead_ioctl,<br>
        .d_poll =       dead_poll,<br>
-#ifndef __rtems__<br>
        .d_mmap =       dead_mmap,<br>
+#ifndef __rtems__<br>
        .d_strategy =   dead_strategy,<br>
 #endif /* __rtems__ */<br>
        .d_name =       "dead",<br>
@@ -522,7 +522,6 @@ giant_kqfilter(struct cdev *dev, struct knote *kn)<br>
        return (retval);<br>
 }<br>
<br>
-#ifndef __rtems__<br>
 static int<br>
 giant_mmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr, int nprot,<br>
     vm_memattr_t *memattr)<br>
@@ -541,6 +540,7 @@ giant_mmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr, int nprot,<br>
        return (retval);<br>
 }<br>
<br>
+#ifndef __rtems__<br>
 static int<br>
 giant_mmap_single(struct cdev *dev, vm_ooffset_t *offset, vm_size_t size,<br>
     vm_object_t *object, int nprot)<br>
@@ -667,8 +667,8 @@ prep_cdevsw(struct cdevsw *devsw, int flags)<br>
                devsw->d_write = dead_write;<br>
                devsw->d_ioctl = dead_ioctl;<br>
                devsw->d_poll = dead_poll;<br>
-#ifndef __rtems__<br>
                devsw->d_mmap = dead_mmap;<br>
+#ifndef __rtems__<br>
                devsw->d_mmap_single = dead_mmap_single;<br>
                devsw->d_strategy = dead_strategy;<br>
                devsw->d_dump = dead_dump;<br>
@@ -702,8 +702,8 @@ prep_cdevsw(struct cdevsw *devsw, int flags)<br>
        FIXUP(d_write,          no_write,       giant_write);<br>
        FIXUP(d_ioctl,          no_ioctl,       giant_ioctl);<br>
        FIXUP(d_poll,           no_poll,        giant_poll);<br>
-#ifndef __rtems__<br>
        FIXUP(d_mmap,           no_mmap,        giant_mmap);<br>
+#ifndef __rtems__<br>
        FIXUP(d_strategy,       no_strategy,    giant_strategy);<br>
 #endif /* __rtems__ */<br>
        FIXUP(d_kqfilter,       no_kqfilter,    giant_kqfilter);<br>
diff --git a/freebsd/sys/sys/conf.h b/freebsd/sys/sys/conf.h<br>
index 4ace162f..c0a66442 100644<br>
--- a/freebsd/sys/sys/conf.h<br>
+++ b/freebsd/sys/sys/conf.h<br>
@@ -209,8 +209,8 @@ struct cdevsw {<br>
        d_write_t               *d_write;<br>
        d_ioctl_t               *d_ioctl;<br>
        d_poll_t                *d_poll;<br>
-#ifndef __rtems__<br>
        d_mmap_t                *d_mmap;<br>
+#ifndef __rtems__<br>
        d_strategy_t            *d_strategy;<br>
        dumper_t                *d_dump;<br>
 #endif /* __rtems__ */<br>
diff --git a/rtemsbsd/include/machine/vm.h b/rtemsbsd/include/machine/vm.h<br>
index e69de29b..351b7472 100644<br>
--- a/rtemsbsd/include/machine/vm.h<br>
+++ b/rtemsbsd/include/machine/vm.h<br>
@@ -0,0 +1,2 @@<br></blockquote><div> Hi,</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+#define VM_MEMATTR_DEFAULT 0<br>
+#define VM_MEMATTR_UNCACHEABLE 1<br></blockquote><div><br></div><div>Are you sure that these values are correct in general?</div><div>BSD defines this only for ARM versions smaller 6.</div><div><a href="https://github.com/freebsd/freebsd/blob/1d6e4247415d264485ee94b59fdbc12e0c566fd0/sys/arm/include/vm.h">https://github.com/freebsd/freebsd/blob/1d6e4247415d264485ee94b59fdbc12e0c566fd0/sys/arm/include/vm.h</a> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
diff --git a/rtemsbsd/sys/fs/devfs/devfs_devs.c b/rtemsbsd/sys/fs/devfs/devfs_devs.c<br>
index 7c697b0a..9878936f 100644<br>
--- a/rtemsbsd/sys/fs/devfs/devfs_devs.c<br>
+++ b/rtemsbsd/sys/fs/devfs/devfs_devs.c<br>
@@ -387,6 +387,39 @@ devfs_imfs_kqfilter(rtems_libio_t *iop, struct knote *kn)<br>
        return error;<br>
 }<br>
<br>
+static int<br>
+devfs_imfs_mmap(rtems_libio_t *iop, void **addr, size_t len, int prot,<br>
+    off_t off)<br>
+{<br>
+       struct cdev *cdev = devfs_imfs_get_context_by_iop(iop);<br>
+       struct file *fp = rtems_bsd_iop_to_fp(iop);<br>
+       struct thread *td = rtems_bsd_get_curthread_or_null();<br>
+       struct file *fpop;<br>
+       struct cdevsw *dsw;<br>
+       int error, ref;<br>
+<br>
+       if (td != 0) {<br>
+               if (cdev == NULL) {<br>
+                       error = ENXIO;<br>
+               }<br>
+               if (cdev->si_flags & SI_ALIAS) {<br>
+                       cdev = cdev->si_parent;<br>
+               }<br>
+               dsw = dev_refthread(cdev, &ref);<br>
+               if (dsw == NULL) {<br>
+                       error = ENXIO;<br>
+               }<br>
+               fpop = td->td_fpop;<br>
+               curthread->td_fpop = fp;<br>
+               error = dsw->d_mmap( cdev, off, (vm_paddr_t *) addr, prot, VM_MEMATTR_DEFAULT);<br>
+               td->td_fpop = fpop;<br>
+               dev_relthread(cdev, ref);<br>
+       } else {<br>
+               error = ENOMEM;<br>
+       }<br>
+       return error;<br>
+}<br>
+<br>
 static const rtems_filesystem_file_handlers_r devfs_imfs_handlers = {<br>
        .open_h = devfs_imfs_open,<br>
        .close_h = devfs_imfs_close,<br>
@@ -403,6 +436,7 @@ static const rtems_filesystem_file_handlers_r devfs_imfs_handlers = {<br>
        .kqfilter_h = devfs_imfs_kqfilter,<br>
        .readv_h = devfs_imfs_readv,<br>
        .writev_h = devfs_imfs_writev,<br>
+       .mmap_h = devfs_imfs_mmap,<br>
 };<br>
<br>
 static const IMFS_node_control devfs_imfs_control = IMFS_GENERIC_INITIALIZER(<br>
diff --git a/testsuite/cdev01/test_cdev.c b/testsuite/cdev01/test_cdev.c<br>
index 19fb1a5e..bff455cf 100644<br>
--- a/testsuite/cdev01/test_cdev.c<br>
+++ b/testsuite/cdev01/test_cdev.c<br>
@@ -32,6 +32,7 @@<br>
 #include <machine/rtems-bsd-kernel-space.h><br>
 #include <sys/types.h><br>
 #include <sys/conf.h><br>
+#include <sys/mman.h><br>
<br>
 #include <rtems/seterr.h><br>
<br>
@@ -46,6 +47,7 @@ static        d_write_t       testwrite;<br>
 static d_ioctl_t       testioctl;<br>
 static d_poll_t        testpoll;<br>
 static d_kqfilter_t    testkqfilter;<br>
+static d_mmap_t        testmmap;<br>
<br>
 static struct cdevsw test_cdevsw = {<br>
        .d_version =    D_VERSION,<br>
@@ -59,6 +61,7 @@ static struct cdevsw test_cdevsw = {<br>
        .d_ioctl =      testioctl,<br>
        .d_poll =       testpoll,<br>
        .d_kqfilter =   testkqfilter,<br>
+       .d_mmap =       testmmap,<br>
 };<br>
<br>
 static int<br>
@@ -77,7 +80,7 @@ testclose(struct cdev *dev, int fflag, int devtype, struct thread *td)<br>
 {<br>
        test_state *state = dev->si_drv1;<br>
<br>
-       assert(*state == TEST_KQFILTER);<br>
+       assert(*state == TEST_MMAP);<br>
        *state = TEST_CLOSED;<br>
<br>
        return 0;<br>
@@ -148,6 +151,18 @@ testkqfilter(struct cdev *dev, struct knote *kn)<br>
        return TEST_KQ_ERRNO;<br>
 }<br>
<br>
+static int<br>
+testmmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr,<br>
+         int nprot, vm_memattr_t *memattr)<br>
+{<br>
+       test_state *state = dev->si_drv1;<br>
+<br>
+       assert(*state == TEST_KQFILTER);<br>
+       *state = TEST_MMAP;<br>
+<br>
+       return 0;<br>
+}<br>
+<br>
 void<br>
 test_make_dev(test_state *state, const char *name)<br>
 {<br>
diff --git a/testsuite/cdev01/test_cdev01.h b/testsuite/cdev01/test_cdev01.h<br>
index a83001b5..58866a0c 100644<br>
--- a/testsuite/cdev01/test_cdev01.h<br>
+++ b/testsuite/cdev01/test_cdev01.h<br>
@@ -42,7 +42,8 @@ typedef enum {<br>
        TEST_WRITEV,<br>
        TEST_POLL,<br>
        TEST_KQFILTER,<br>
-       TEST_CLOSED<br>
+       TEST_MMAP,<br>
+       TEST_CLOSED,<br>
 } test_state;<br>
<br>
 void test_make_dev(test_state *state, const char *name);<br>
diff --git a/testsuite/cdev01/test_main.c b/testsuite/cdev01/test_main.c<br>
index cbff9133..23aefa86 100644<br>
--- a/testsuite/cdev01/test_main.c<br>
+++ b/testsuite/cdev01/test_main.c<br>
@@ -35,6 +35,7 @@<br>
 #include <sys/time.h><br>
 #include <sys/uio.h><br>
 #include <sys/ioctl.h><br>
+#include <sys/mman.h><br>
<br>
 #include <assert.h><br>
 #include <errno.h><br>
@@ -125,6 +126,9 @@ static void test_cdev(const char *path)<br>
        assert(rv == -1);<br>
        assert(errno == TEST_KQ_ERRNO);<br>
<br>
+       rv = mmap(NULL, 1, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);<br>
+       assert(rv == 0);<br>
+<br>
        rv = close(fd);<br>
        assert(rv == 0);<br>
<br>
-- <br>
2.20.1<br>
<br>
_______________________________________________<br>
devel mailing list<br>
<a href="mailto:devel@rtems.org" target="_blank">devel@rtems.org</a><br>
<a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
</blockquote></div></div>