svn commit: r366315 - in head/sys/riscv: include riscv

Kristof Provost kp at FreeBSD.org
Thu Oct 1 15:04:56 UTC 2020


Author: kp
Date: Thu Oct  1 15:04:55 2020
New Revision: 366315
URL: https://svnweb.freebsd.org/changeset/base/366315

Log:
  riscv: Add memmmap so we can mmap /dev/mem
  
  Reviewed by:	mhorne
  Sponsored by:	Axiado
  Differential Revision:	https://reviews.freebsd.org/D26622

Modified:
  head/sys/riscv/include/memdev.h
  head/sys/riscv/riscv/mem.c

Modified: head/sys/riscv/include/memdev.h
==============================================================================
--- head/sys/riscv/include/memdev.h	Thu Oct  1 14:20:36 2020	(r366314)
+++ head/sys/riscv/include/memdev.h	Thu Oct  1 15:04:55 2020	(r366315)
@@ -35,6 +35,6 @@
 d_open_t	memopen;
 d_read_t	memrw;
 d_ioctl_t	memioctl_md;
-#define		memmmap		(d_mmap_t *)NULL
+d_mmap_t	memmmap;
 
 #endif /* _MACHINE_MEMDEV_H_ */

Modified: head/sys/riscv/riscv/mem.c
==============================================================================
--- head/sys/riscv/riscv/mem.c	Thu Oct  1 14:20:36 2020	(r366314)
+++ head/sys/riscv/riscv/mem.c	Thu Oct  1 15:04:55 2020	(r366315)
@@ -122,6 +122,21 @@ memrw(struct cdev *dev, struct uio *uio, int flags)
 	return (error);
 }
 
+/*
+ * Allow user processes to MMAP some memory sections
+ * instead of going through read/write.
+ */
+int
+memmmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr,
+    int prot __unused, vm_memattr_t *memattr __unused)
+{
+	if (dev2unit(dev) == CDEV_MINOR_MEM) {
+		*paddr = offset;
+		return (0);
+	}
+	return (-1);
+}
+
 int
 memioctl_md(struct cdev *dev __unused, u_long cmd __unused,
     caddr_t data __unused, int flags __unused, struct thread *td __unused)


More information about the svn-src-head mailing list