This commit is contained in:
Vijay Kumar Banerjee 2019-07-18 14:26:26 +05:30 committed by Christian Mauderer
parent bc2ba9a9cd
commit b68ca55c96
7 changed files with 71 additions and 7 deletions

View File

@ -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);

View File

@ -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__ */

View File

@ -0,0 +1,2 @@
#define VM_MEMATTR_DEFAULT 0
#define VM_MEMATTR_UNCACHEABLE 1

View File

@ -387,6 +387,43 @@ 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);
struct file *fp = rtems_bsd_iop_to_fp(iop);
struct thread *td = rtems_bsd_get_curthread_or_null();
struct file *fpop;
struct cdevsw *dsw;
int error, ref;
if (td != 0) {
if (cdev == NULL) {
error = ENXIO;
goto err;
}
if (cdev->si_flags & SI_ALIAS) {
cdev = cdev->si_parent;
}
dsw = dev_refthread(cdev, &ref);
if (dsw == NULL) {
error = ENXIO;
goto err;
}
fpop = td->td_fpop;
curthread->td_fpop = fp;
error = dsw->d_mmap( cdev, off, (vm_paddr_t *) addr, prot, VM_MEMATTR_DEFAULT);
td->td_fpop = fpop;
dev_relthread(cdev, ref);
} else {
error = ENOMEM;
}
err:
return rtems_bsd_error_to_status_and_errno(error);
}
static const rtems_filesystem_file_handlers_r devfs_imfs_handlers = {
.open_h = devfs_imfs_open,
.close_h = devfs_imfs_close,
@ -403,6 +440,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(

View File

@ -30,8 +30,10 @@
*/
#include <machine/rtems-bsd-kernel-space.h>
#include <machine/vm.h>
#include <sys/types.h>
#include <sys/conf.h>
#include <sys/mman.h>
#include <rtems/seterr.h>
@ -46,6 +48,7 @@ static d_write_t testwrite;
static d_ioctl_t testioctl;
static d_poll_t testpoll;
static d_kqfilter_t testkqfilter;
static d_mmap_t testmmap;
static struct cdevsw test_cdevsw = {
.d_version = D_VERSION,
@ -59,6 +62,7 @@ static struct cdevsw test_cdevsw = {
.d_ioctl = testioctl,
.d_poll = testpoll,
.d_kqfilter = testkqfilter,
.d_mmap = testmmap,
};
static int
@ -77,7 +81,7 @@ testclose(struct cdev *dev, int fflag, int devtype, struct thread *td)
{
test_state *state = dev->si_drv1;
assert(*state == TEST_KQFILTER);
assert(*state == TEST_MMAP);
*state = TEST_CLOSED;
return 0;
@ -148,6 +152,21 @@ testkqfilter(struct cdev *dev, struct knote *kn)
return TEST_KQ_ERRNO;
}
static int
testmmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr,
int nprot, vm_memattr_t *memattr)
{
test_state *state = dev->si_drv1;
assert(paddr != NULL);
assert(memattr == VM_MEMATTR_DEFAULT);
assert(nprot == (PROT_READ | PROT_WRITE));
assert(*state == TEST_KQFILTER);
*state = TEST_MMAP;
return 0;
}
void
test_make_dev(test_state *state, const char *name)
{

View File

@ -42,7 +42,8 @@ typedef enum {
TEST_WRITEV,
TEST_POLL,
TEST_KQFILTER,
TEST_CLOSED
TEST_MMAP,
TEST_CLOSED,
} test_state;
void test_make_dev(test_state *state, const char *name);

View File

@ -35,6 +35,7 @@
#include <sys/time.h>
#include <sys/uio.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <assert.h>
#include <errno.h>
@ -125,6 +126,9 @@ static void test_cdev(const char *path)
assert(rv == -1);
assert(errno == TEST_KQ_ERRNO);
rv = mmap(NULL, 1, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
assert(rv == 0);
rv = close(fd);
assert(rv == 0);