From b513c26294324c9c81aa94c85d2e8dc2d3ffd009 Mon Sep 17 00:00:00 2001 From: David Greenman Date: Mon, 22 Nov 1993 09:46:45 +0000 Subject: [PATCH] patches from Julian Elischer - Added support for mmapping /dev/mem --- sys/amd64/amd64/mem.c | 28 +++++++++++++++++++++++++++- sys/i386/i386/conf.c | 6 +++--- sys/i386/i386/mem.c | 28 +++++++++++++++++++++++++++- 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/sys/amd64/amd64/mem.c b/sys/amd64/amd64/mem.c index 51c62cacf1e2..0caf00c07f5c 100644 --- a/sys/amd64/amd64/mem.c +++ b/sys/amd64/amd64/mem.c @@ -38,7 +38,7 @@ * * from: Utah $Hdr: mem.c 1.13 89/10/08$ * from: @(#)mem.c 7.2 (Berkeley) 5/9/91 - * $Id$ + * $Id: mem.c,v 1.3 1993/10/16 14:15:06 rgrimes Exp $ */ /* @@ -228,3 +228,29 @@ mmrw(dev, uio, flags) free(zbuf, M_TEMP); return (error); } + + + + +/*******************************************************\ +* allow user processes to MMAP some memory sections * +* instead of going through read/write * +\*******************************************************/ +int memmmap(dev_t dev, int offset, int nprot) +{ + switch (minor(dev)) + { + +/* minor device 0 is physical memory */ + case 0: + return i386_btop(offset); + +/* minor device 1 is kernel memory */ + case 1: + return i386_btop(vtophys(offset)); + + default: + return -1; + } +} + diff --git a/sys/i386/i386/conf.c b/sys/i386/i386/conf.c index ae333fd5869f..41e9aeb66bdd 100644 --- a/sys/i386/i386/conf.c +++ b/sys/i386/i386/conf.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)conf.c 5.8 (Berkeley) 5/12/91 - * $Id: conf.c,v 1.14 1993/11/03 18:07:32 nate Exp $ + * $Id: conf.c,v 1.15 1993/11/18 05:01:51 rgrimes Exp $ */ #include "param.h" @@ -188,7 +188,7 @@ extern struct tty pccons; int cttyopen(), cttyread(), cttywrite(), cttyioctl(), cttyselect(); -int mmopen(), mmclose(), mmrw(); +int mmopen(), mmclose(), mmrw(), memmmap(); #define mmselect seltrue #include "pty.h" @@ -393,7 +393,7 @@ struct cdevsw cdevsw[] = cttyselect, enodev, NULL }, { mmopen, mmclose, mmrw, mmrw, /*2*/ enodev, nullop, nullop, NULL, /* memory */ - mmselect, enodev, NULL }, + mmselect, memmmap, NULL }, { wdopen, wdclose, rawread, rawwrite, /*3*/ wdioctl, enodev, nullop, NULL, /* wd */ seltrue, enodev, wdstrategy }, diff --git a/sys/i386/i386/mem.c b/sys/i386/i386/mem.c index 51c62cacf1e2..0caf00c07f5c 100644 --- a/sys/i386/i386/mem.c +++ b/sys/i386/i386/mem.c @@ -38,7 +38,7 @@ * * from: Utah $Hdr: mem.c 1.13 89/10/08$ * from: @(#)mem.c 7.2 (Berkeley) 5/9/91 - * $Id$ + * $Id: mem.c,v 1.3 1993/10/16 14:15:06 rgrimes Exp $ */ /* @@ -228,3 +228,29 @@ mmrw(dev, uio, flags) free(zbuf, M_TEMP); return (error); } + + + + +/*******************************************************\ +* allow user processes to MMAP some memory sections * +* instead of going through read/write * +\*******************************************************/ +int memmmap(dev_t dev, int offset, int nprot) +{ + switch (minor(dev)) + { + +/* minor device 0 is physical memory */ + case 0: + return i386_btop(offset); + +/* minor device 1 is kernel memory */ + case 1: + return i386_btop(vtophys(offset)); + + default: + return -1; + } +} +