Break out the MI part of the /dev/[k]mem and /dev/io drivers into
their own directory and module, leaving the MD parts in the MD area (the MD parts _are_ part of the modules). /dev/mem and /dev/io are now loadable modules, thus taking us one step further towards a kernel created entirely out of modules. Of course, there is nothing preventing the kernel from having these statically compiled.
This commit is contained in:
parent
dcd6f4bd48
commit
8ab2f5ecc5
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=132956
@ -59,84 +59,18 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/uio.h>
|
||||
|
||||
#include <machine/md_var.h>
|
||||
#ifdef PERFMON
|
||||
#include <machine/perfmon.h>
|
||||
#endif
|
||||
|
||||
#include <vm/vm.h>
|
||||
#include <vm/pmap.h>
|
||||
#include <vm/vm_extern.h>
|
||||
|
||||
static struct cdev *memdev, *kmemdev;
|
||||
#ifdef PERFMON
|
||||
static struct cdev *perfdev;
|
||||
#endif /* PERFMON */
|
||||
|
||||
static d_open_t mmopen;
|
||||
static d_close_t mmclose;
|
||||
static d_read_t mmrw;
|
||||
static d_ioctl_t mmioctl;
|
||||
static d_mmap_t memmmap;
|
||||
|
||||
#define CDEV_MAJOR 2
|
||||
static struct cdevsw mem_cdevsw = {
|
||||
.d_version = D_VERSION,
|
||||
.d_open = mmopen,
|
||||
.d_close = mmclose,
|
||||
.d_read = mmrw,
|
||||
.d_write = mmrw,
|
||||
.d_ioctl = mmioctl,
|
||||
.d_mmap = memmmap,
|
||||
.d_name = "mem",
|
||||
.d_maj = CDEV_MAJOR,
|
||||
.d_flags = D_MEM | D_NEEDGIANT,
|
||||
};
|
||||
#include <machine/memdev.h>
|
||||
|
||||
struct mem_range_softc mem_range_softc;
|
||||
|
||||
static int
|
||||
mmclose(struct cdev *dev, int flags, int fmt, struct thread *td)
|
||||
{
|
||||
switch (minor(dev)) {
|
||||
#ifdef PERFMON
|
||||
case 32:
|
||||
return perfmon_close(dev, flags, fmt, td);
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
mmopen(struct cdev *dev, int flags, int fmt, struct thread *td)
|
||||
{
|
||||
int error;
|
||||
|
||||
switch (minor(dev)) {
|
||||
case 0:
|
||||
case 1:
|
||||
if (flags & FWRITE) {
|
||||
error = securelevel_gt(td->td_ucred, 0);
|
||||
if (error)
|
||||
return (error);
|
||||
}
|
||||
break;
|
||||
case 32:
|
||||
#ifdef PERFMON
|
||||
return perfmon_open(dev, flags, fmt, td);
|
||||
#else
|
||||
return ENODEV;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static int
|
||||
mmrw(struct cdev *dev, struct uio *uio, int flags)
|
||||
/* ARGSUSED */
|
||||
int
|
||||
memrw(struct cdev *dev, struct uio *uio, int flags)
|
||||
{
|
||||
vm_offset_t o, v;
|
||||
int c = 0;
|
||||
@ -152,13 +86,10 @@ mmrw(struct cdev *dev, struct uio *uio, int flags)
|
||||
uio->uio_iov++;
|
||||
uio->uio_iovcnt--;
|
||||
if (uio->uio_iovcnt < 0)
|
||||
panic("mmrw");
|
||||
panic("memrw");
|
||||
continue;
|
||||
}
|
||||
switch (minor(dev)) {
|
||||
|
||||
/* minor device 0 is physical memory */
|
||||
case 0:
|
||||
if (minor(dev) == CDEV_MINOR_MEM) {
|
||||
v = uio->uio_offset;
|
||||
kmemphys:
|
||||
/* Allow reads only in RAM. */
|
||||
@ -174,9 +105,8 @@ mmrw(struct cdev *dev, struct uio *uio, int flags)
|
||||
error =
|
||||
uiomove((caddr_t)ALPHA_PHYS_TO_K0SEG(v), c, uio);
|
||||
continue;
|
||||
|
||||
/* minor device 1 is kernel memory */
|
||||
case 1:
|
||||
}
|
||||
else if (minor(dev) == CDEV_MINOR_KMEM) {
|
||||
v = uio->uio_offset;
|
||||
|
||||
if (v >= ALPHA_K0SEG_BASE && v <= ALPHA_K0SEG_END) {
|
||||
@ -186,8 +116,9 @@ mmrw(struct cdev *dev, struct uio *uio, int flags)
|
||||
|
||||
c = min(iov->iov_len, MAXPHYS);
|
||||
/*
|
||||
* Make sure that all of the pages are currently resident so
|
||||
* that we don't create any zero-fill pages.
|
||||
* Make sure that all of the pages are currently
|
||||
* resident so that we don't create any zero-fill
|
||||
* pages.
|
||||
*/
|
||||
addr = trunc_page(v);
|
||||
eaddr = round_page(v + c);
|
||||
@ -203,22 +134,16 @@ mmrw(struct cdev *dev, struct uio *uio, int flags)
|
||||
error = uiomove((caddr_t)v, c, uio);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (error)
|
||||
break;
|
||||
iov->iov_base = (char *)iov->iov_base + c;
|
||||
iov->iov_len -= c;
|
||||
uio->uio_offset += c;
|
||||
uio->uio_resid -= c;
|
||||
/* else panic! */
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*******************************************************\
|
||||
* allow user processes to MMAP some memory sections *
|
||||
* instead of going through read/write *
|
||||
\*******************************************************/
|
||||
static int
|
||||
/*
|
||||
* allow user processes to MMAP some memory sections
|
||||
* instead of going through read/write
|
||||
*/
|
||||
int
|
||||
memmmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int prot)
|
||||
{
|
||||
/*
|
||||
@ -227,7 +152,7 @@ memmmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int prot)
|
||||
* could be transient and hence incorrect or invalid at
|
||||
* a later time.
|
||||
*/
|
||||
if (minor(dev) != 0)
|
||||
if (minor(dev) != CDEV_MINOR_MEM)
|
||||
return (-1);
|
||||
|
||||
/*
|
||||
@ -239,59 +164,7 @@ memmmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int prot)
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
mmioctl(struct cdev *dev, u_long cmd, caddr_t cmdarg, int flags, struct thread *td)
|
||||
void
|
||||
dev_mem_md_init(void)
|
||||
{
|
||||
switch(minor(dev)) {
|
||||
#ifdef PERFMON
|
||||
case 32:
|
||||
return perfmon_ioctl(dev, cmd, cmdarg, flags, td);
|
||||
#endif
|
||||
default:
|
||||
return ENODEV;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
mem_modevent(module_t mod, int type, void *data)
|
||||
{
|
||||
switch(type) {
|
||||
case MOD_LOAD:
|
||||
if (bootverbose)
|
||||
printf("mem: <memory & I/O>\n");
|
||||
/* XXX - ??? */
|
||||
#if 0
|
||||
/* Initialise memory range handling */
|
||||
if (mem_range_softc.mr_op != NULL)
|
||||
mem_range_softc.mr_op->init(&mem_range_softc);
|
||||
#endif
|
||||
|
||||
memdev = make_dev(&mem_cdevsw, 0, UID_ROOT, GID_KMEM,
|
||||
0640, "mem");
|
||||
kmemdev = make_dev(&mem_cdevsw, 1, UID_ROOT, GID_KMEM,
|
||||
0640, "kmem");
|
||||
#ifdef PERFMON
|
||||
perfdev = make_dev(&mem_cdevsw, 32, UID_ROOT, GID_KMEM,
|
||||
0640, "perfmon");
|
||||
#endif /* PERFMON */
|
||||
return 0;
|
||||
|
||||
case MOD_UNLOAD:
|
||||
destroy_dev(memdev);
|
||||
destroy_dev(kmemdev);
|
||||
#ifdef PERFMON
|
||||
destroy_dev(perfdev);
|
||||
#endif /* PERFMON */
|
||||
return 0;
|
||||
|
||||
case MOD_SHUTDOWN:
|
||||
return 0;
|
||||
|
||||
default:
|
||||
return EOPNOTSUPP;
|
||||
}
|
||||
}
|
||||
|
||||
DEV_MODULE(mem, mem_modevent, NULL);
|
||||
|
@ -171,8 +171,10 @@ device wb # Winbond W89C840F
|
||||
device xl # 3Com 3c90x (``Boomerang'', ``Cyclone'')
|
||||
|
||||
# Pseudo devices.
|
||||
device random # Entropy device
|
||||
device loop # Network loopback
|
||||
device mem # Memory and kernel memory devices
|
||||
device null # Null and zero devices
|
||||
device random # Entropy device
|
||||
device ether # Ethernet support
|
||||
device sl # Kernel SLIP
|
||||
device ppp # Kernel PPP
|
||||
|
38
sys/alpha/include/memdev.h
Normal file
38
sys/alpha/include/memdev.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*-
|
||||
* Copyright (c) 2004 Mark R V Murray
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer
|
||||
* in this position and unchanged.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#define CDEV_MAJOR 2
|
||||
#define CDEV_MINOR_MEM 0
|
||||
#define CDEV_MINOR_KMEM 1
|
||||
|
||||
d_open_t memopen;
|
||||
d_read_t memrw;
|
||||
#define memioctl (d_ioctl_t *)NULL;
|
||||
d_mmap_t memmmap;
|
||||
|
||||
void dev_mem_md_init(void);
|
77
sys/amd64/amd64/io.c
Normal file
77
sys/amd64/amd64/io.c
Normal file
@ -0,0 +1,77 @@
|
||||
/*-
|
||||
* Copyright (c) 2004 Mark R V Murray
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer
|
||||
* in this position and unchanged.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/signalvar.h>
|
||||
#include <sys/systm.h>
|
||||
|
||||
#include <machine/db_machdep.h>
|
||||
#include <machine/frame.h>
|
||||
#include <machine/psl.h>
|
||||
#include <machine/specialreg.h>
|
||||
|
||||
#include <vm/vm.h>
|
||||
#include <vm/pmap.h>
|
||||
|
||||
#include <machine/iodev.h>
|
||||
|
||||
/* ARGSUSED */
|
||||
int
|
||||
ioopen(struct cdev *dev __unused, int flags __unused, int fmt __unused,
|
||||
struct thread *td)
|
||||
{
|
||||
int error;
|
||||
|
||||
error = suser(td);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
error = securelevel_gt(td->td_ucred, 0);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
|
||||
td->td_frame->tf_rflags |= PSL_IOPL;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
int
|
||||
ioclose(struct cdev *dev __unused, int flags __unused, int fmt __unused,
|
||||
struct thread *td)
|
||||
{
|
||||
td->td_frame->tf_rflags &= ~PSL_IOPL;
|
||||
|
||||
return (0);
|
||||
}
|
@ -47,7 +47,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/conf.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/ioccom.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/memrange.h>
|
||||
@ -58,82 +57,19 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/systm.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
#include <machine/db_machdep.h>
|
||||
#include <machine/frame.h>
|
||||
#include <machine/psl.h>
|
||||
#include <machine/specialreg.h>
|
||||
#include <machine/vmparam.h>
|
||||
|
||||
#include <vm/vm.h>
|
||||
#include <vm/pmap.h>
|
||||
#include <vm/vm_extern.h>
|
||||
|
||||
static struct cdev *memdev, *kmemdev, *iodev;
|
||||
|
||||
static d_open_t mmopen;
|
||||
static d_close_t mmclose;
|
||||
static d_read_t mmrw;
|
||||
static d_ioctl_t mmioctl;
|
||||
static d_mmap_t memmmap;
|
||||
|
||||
#define CDEV_MAJOR 2
|
||||
static struct cdevsw mem_cdevsw = {
|
||||
.d_version = D_VERSION,
|
||||
.d_open = mmopen,
|
||||
.d_close = mmclose,
|
||||
.d_read = mmrw,
|
||||
.d_write = mmrw,
|
||||
.d_ioctl = mmioctl,
|
||||
.d_mmap = memmmap,
|
||||
.d_name = "mem",
|
||||
.d_maj = CDEV_MAJOR,
|
||||
.d_flags = D_MEM | D_NEEDGIANT,
|
||||
};
|
||||
|
||||
MALLOC_DEFINE(M_MEMDESC, "memdesc", "memory range descriptors");
|
||||
#include <machine/memdev.h>
|
||||
|
||||
struct mem_range_softc mem_range_softc;
|
||||
|
||||
static int
|
||||
mmclose(struct cdev *dev, int flags, int fmt, struct thread *td)
|
||||
{
|
||||
switch (minor(dev)) {
|
||||
case 14:
|
||||
td->td_frame->tf_rflags &= ~PSL_IOPL;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
mmopen(struct cdev *dev, int flags, int fmt, struct thread *td)
|
||||
{
|
||||
int error;
|
||||
|
||||
switch (minor(dev)) {
|
||||
case 0:
|
||||
case 1:
|
||||
if (flags & FWRITE) {
|
||||
error = securelevel_gt(td->td_ucred, 0);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
}
|
||||
break;
|
||||
case 14:
|
||||
error = suser(td);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
error = securelevel_gt(td->td_ucred, 0);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
td->td_frame->tf_rflags |= PSL_IOPL;
|
||||
break;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static int
|
||||
mmrw(struct cdev *dev, struct uio *uio, int flags)
|
||||
/* ARGSUSED */
|
||||
int
|
||||
memrw(struct cdev *dev, struct uio *uio, int flags)
|
||||
{
|
||||
int o;
|
||||
u_long c = 0, v;
|
||||
@ -149,22 +85,18 @@ mmrw(struct cdev *dev, struct uio *uio, int flags)
|
||||
uio->uio_iov++;
|
||||
uio->uio_iovcnt--;
|
||||
if (uio->uio_iovcnt < 0)
|
||||
panic("mmrw");
|
||||
panic("memrw");
|
||||
continue;
|
||||
}
|
||||
switch (minor(dev)) {
|
||||
|
||||
/* minor device 0 is physical memory */
|
||||
case 0:
|
||||
if (minor(dev) == CDEV_MINOR_MEM) {
|
||||
v = uio->uio_offset;
|
||||
kmemphys:
|
||||
o = v & PAGE_MASK;
|
||||
c = min(uio->uio_resid, (u_int)(PAGE_SIZE - o));
|
||||
error = uiomove((void *)PHYS_TO_DMAP(v), (int)c, uio);
|
||||
continue;
|
||||
|
||||
/* minor device 1 is kernel memory */
|
||||
case 1:
|
||||
}
|
||||
else if (minor(dev) == CDEV_MINOR_KMEM) {
|
||||
v = uio->uio_offset;
|
||||
|
||||
if (v >= DMAP_MIN_ADDRESS && v < DMAP_MAX_ADDRESS) {
|
||||
@ -175,8 +107,9 @@ mmrw(struct cdev *dev, struct uio *uio, int flags)
|
||||
c = iov->iov_len;
|
||||
|
||||
/*
|
||||
* Make sure that all of the pages are currently resident so
|
||||
* that we don't create any zero-fill pages.
|
||||
* Make sure that all of the pages are currently
|
||||
* resident so that we don't create any zero-fill
|
||||
* pages.
|
||||
*/
|
||||
addr = trunc_page(v);
|
||||
eaddr = round_page(v + c);
|
||||
@ -194,44 +127,24 @@ mmrw(struct cdev *dev, struct uio *uio, int flags)
|
||||
|
||||
error = uiomove((caddr_t)(long)v, (int)c, uio);
|
||||
continue;
|
||||
|
||||
default:
|
||||
return (ENODEV);
|
||||
}
|
||||
|
||||
if (error)
|
||||
break;
|
||||
iov->iov_base = (char *)iov->iov_base + c;
|
||||
iov->iov_len -= c;
|
||||
uio->uio_offset += c;
|
||||
uio->uio_resid -= c;
|
||||
/* else panic! */
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*******************************************************\
|
||||
* allow user processes to MMAP some memory sections *
|
||||
* instead of going through read/write *
|
||||
\*******************************************************/
|
||||
static int
|
||||
/*
|
||||
* allow user processes to MMAP some memory sections
|
||||
* instead of going through read/write
|
||||
*/
|
||||
int
|
||||
memmmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int prot)
|
||||
{
|
||||
switch (minor(dev))
|
||||
{
|
||||
|
||||
/* minor device 0 is physical memory */
|
||||
case 0:
|
||||
if (minor(dev) == CDEV_MINOR_MEM)
|
||||
*paddr = offset;
|
||||
break;
|
||||
|
||||
/* minor device 1 is kernel memory */
|
||||
case 1:
|
||||
else if (minor(dev) == CDEV_MINOR_KMEM)
|
||||
*paddr = vtophys(offset);
|
||||
break;
|
||||
|
||||
default:
|
||||
return (-1);
|
||||
}
|
||||
/* else panic! */
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -241,8 +154,9 @@ memmmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int prot)
|
||||
* This is basically just an ioctl shim for mem_range_attr_get
|
||||
* and mem_range_attr_set.
|
||||
*/
|
||||
static int
|
||||
mmioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags, struct thread *td)
|
||||
int
|
||||
memioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags,
|
||||
struct thread *td)
|
||||
{
|
||||
int nd, error = 0;
|
||||
struct mem_range_op *mo = (struct mem_range_op *)data;
|
||||
@ -331,37 +245,9 @@ mem_range_AP_init(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
mem_modevent(module_t mod, int type, void *data)
|
||||
void
|
||||
dev_mem_md_init(void)
|
||||
{
|
||||
switch(type) {
|
||||
case MOD_LOAD:
|
||||
if (bootverbose)
|
||||
printf("mem: <memory & I/O>\n");
|
||||
/* Initialise memory range handling */
|
||||
if (mem_range_softc.mr_op != NULL)
|
||||
mem_range_softc.mr_op->init(&mem_range_softc);
|
||||
|
||||
memdev = make_dev(&mem_cdevsw, 0, UID_ROOT, GID_KMEM,
|
||||
0640, "mem");
|
||||
kmemdev = make_dev(&mem_cdevsw, 1, UID_ROOT, GID_KMEM,
|
||||
0640, "kmem");
|
||||
iodev = make_dev(&mem_cdevsw, 14, UID_ROOT, GID_WHEEL,
|
||||
0600, "io");
|
||||
return (0);
|
||||
|
||||
case MOD_UNLOAD:
|
||||
destroy_dev(memdev);
|
||||
destroy_dev(kmemdev);
|
||||
destroy_dev(iodev);
|
||||
return (0);
|
||||
|
||||
case MOD_SHUTDOWN:
|
||||
return (0);
|
||||
|
||||
default:
|
||||
return (EOPNOTSUPP);
|
||||
}
|
||||
if (mem_range_softc.mr_op != NULL)
|
||||
mem_range_softc.mr_op->init(&mem_range_softc);
|
||||
}
|
||||
|
||||
DEV_MODULE(mem, mem_modevent, NULL);
|
||||
|
@ -217,8 +217,10 @@ device awi # BayStack 660 and others
|
||||
device wi # WaveLAN/Intersil/Symbol 802.11 wireless NICs.
|
||||
|
||||
# Pseudo devices.
|
||||
device random # Entropy device
|
||||
device loop # Network loopback
|
||||
device mem # Memory and kernel memory devices
|
||||
device null # Null and zero devices
|
||||
device random # Entropy device
|
||||
device ether # Ethernet support
|
||||
device sl # Kernel SLIP
|
||||
device ppp # Kernel PPP
|
||||
|
@ -517,3 +517,7 @@ options TIMER_FREQ=((14318182+6)/12)
|
||||
options VM_KMEM_SIZE
|
||||
options VM_KMEM_SIZE_MAX
|
||||
options VM_KMEM_SIZE_SCALE
|
||||
|
||||
|
||||
# The I/O device
|
||||
device io
|
||||
|
33
sys/amd64/include/iodev.h
Normal file
33
sys/amd64/include/iodev.h
Normal file
@ -0,0 +1,33 @@
|
||||
/*-
|
||||
* Copyright (c) 2004 Mark R V Murray
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer
|
||||
* in this position and unchanged.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#define CDEV_MAJOR 2
|
||||
#define CDEV_MINOR_IO 14
|
||||
|
||||
d_open_t ioopen;
|
||||
d_close_t ioclose;
|
38
sys/amd64/include/memdev.h
Normal file
38
sys/amd64/include/memdev.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*-
|
||||
* Copyright (c) 2004 Mark R V Murray
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer
|
||||
* in this position and unchanged.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#define CDEV_MAJOR 2
|
||||
#define CDEV_MINOR_MEM 0
|
||||
#define CDEV_MINOR_KMEM 1
|
||||
|
||||
d_open_t memopen;
|
||||
d_read_t memrw;
|
||||
d_ioctl_t memioctl;
|
||||
d_mmap_t memmmap;
|
||||
|
||||
void dev_mem_md_init(void);
|
@ -836,9 +836,15 @@ options EXT2FS
|
||||
# unsuitable for inclusion on machines with untrusted local users.
|
||||
options VFS_AIO
|
||||
|
||||
# Cryptographically secure random number generator; /dev/[u]random
|
||||
# Cryptographically secure random number generator; /dev/random
|
||||
device random
|
||||
|
||||
# The bit-bucket; /dev/null
|
||||
device null
|
||||
|
||||
# The system memory devices; /dev/mem, /dev/kmem
|
||||
device mem
|
||||
|
||||
# Optional character code conversion support with LIBICONV.
|
||||
# Each option requires their base file system and LIBICONV.
|
||||
options CD9660_ICONV
|
||||
|
@ -545,6 +545,7 @@ dev/mca/mca_bus.c optional mca
|
||||
dev/mcd/mcd.c optional mcd isa nowerror
|
||||
dev/mcd/mcd_isa.c optional mcd isa nowerror
|
||||
dev/md/md.c optional md
|
||||
dev/mem/memdev.c optional mem
|
||||
dev/mii/amphy.c optional miibus
|
||||
dev/mii/bmtphy.c optional miibus
|
||||
dev/mii/brgphy.c optional miibus
|
||||
@ -583,8 +584,8 @@ dev/mpt/mpt_pci.c optional mpt pci
|
||||
dev/my/if_my.c optional my
|
||||
dev/musycc/musycc.c optional musycc
|
||||
dev/nge/if_nge.c optional nge
|
||||
dev/null/null.c standard
|
||||
dev/nmdm/nmdm.c optional nmdm
|
||||
dev/null/null.c optional null
|
||||
dev/patm/if_patm.c optional patm pci
|
||||
dev/patm/if_patm_intr.c optional patm pci
|
||||
dev/patm/if_patm_ioctl.c optional patm pci
|
||||
|
@ -71,7 +71,7 @@ alpha/alpha/in_cksum.c optional inet
|
||||
alpha/alpha/interrupt.c standard
|
||||
alpha/alpha/locore.s standard no-obj
|
||||
alpha/alpha/machdep.c standard
|
||||
alpha/alpha/mem.c standard
|
||||
alpha/alpha/mem.c optional mem
|
||||
alpha/alpha/pmap.c standard
|
||||
alpha/alpha/mp_machdep.c optional smp
|
||||
alpha/alpha/prom.c standard
|
||||
|
@ -59,12 +59,13 @@ amd64/amd64/identcpu.c standard
|
||||
amd64/amd64/in_cksum.c optional inet
|
||||
amd64/amd64/initcpu.c standard
|
||||
amd64/amd64/intr_machdep.c standard
|
||||
amd64/amd64/io.c optional io
|
||||
amd64/amd64/io_apic.c standard
|
||||
amd64/amd64/legacy.c standard
|
||||
amd64/amd64/local_apic.c standard
|
||||
amd64/amd64/locore.S standard no-obj
|
||||
amd64/amd64/machdep.c standard
|
||||
amd64/amd64/mem.c standard
|
||||
amd64/amd64/mem.c optional mem
|
||||
amd64/amd64/mp_machdep.c optional smp
|
||||
amd64/amd64/mpboot.S optional smp
|
||||
amd64/amd64/mptable.c optional mptable
|
||||
@ -100,6 +101,7 @@ dev/fb/fb.c optional fb
|
||||
dev/fb/fb.c optional vga
|
||||
dev/fb/splash.c optional splash
|
||||
dev/fb/vga.c optional vga
|
||||
dev/io/iodev.c optional io
|
||||
dev/fdc/fdc.c optional fdc
|
||||
dev/fdc/fdc_acpi.c optional fdc
|
||||
dev/fdc/fdc_isa.c optional fdc isa
|
||||
|
@ -152,6 +152,7 @@ dev/kbd/kbd.c optional sc
|
||||
dev/kbd/kbd.c optional ukbd
|
||||
dev/kbd/kbd.c optional vt
|
||||
dev/lnc/if_lnc_isa.c optional lnc isa
|
||||
dev/io/iodev.c optional io
|
||||
dev/ppc/ppc.c optional ppc
|
||||
dev/ppc/ppc_puc.c optional ppc puc pci
|
||||
dev/random/nehemiah.c optional random
|
||||
@ -216,19 +217,20 @@ i386/i386/elf_machdep.c standard
|
||||
i386/i386/exception.s standard
|
||||
i386/i386/gdb_machdep.c optional gdb
|
||||
i386/i386/geode.c optional cpu_geode
|
||||
i386/i386/i686_mem.c standard
|
||||
i386/i386/i686_mem.c optional mem
|
||||
i386/i386/identcpu.c standard
|
||||
i386/i386/in_cksum.c optional inet
|
||||
i386/i386/initcpu.c standard
|
||||
i386/i386/intr_machdep.c standard
|
||||
i386/i386/io_apic.c optional apic
|
||||
i386/i386/k6_mem.c standard
|
||||
i386/i386/io.c optional io
|
||||
i386/i386/k6_mem.c optional mem
|
||||
i386/i386/legacy.c standard
|
||||
i386/i386/local_apic.c optional apic
|
||||
i386/i386/locore.s standard no-obj
|
||||
i386/i386/longrun.c optional cpu_enable_longrun
|
||||
i386/i386/machdep.c standard
|
||||
i386/i386/mem.c standard
|
||||
i386/i386/mem.c optional mem
|
||||
i386/i386/mp_clock.c optional smp
|
||||
i386/i386/mp_machdep.c optional smp
|
||||
i386/i386/mpboot.s optional smp
|
||||
|
@ -104,7 +104,7 @@ ia64/ia64/interrupt.c standard
|
||||
ia64/ia64/locore.S standard no-obj
|
||||
ia64/ia64/machdep.c standard
|
||||
ia64/ia64/mca.c standard
|
||||
ia64/ia64/mem.c standard
|
||||
ia64/ia64/mem.c optional mem
|
||||
ia64/ia64/mp_machdep.c optional smp
|
||||
ia64/ia64/nexus.c standard
|
||||
ia64/ia64/pal.S standard
|
||||
|
@ -157,7 +157,7 @@ i386/i386/k6_mem.c standard
|
||||
i386/i386/legacy.c standard
|
||||
i386/i386/local_apic.c optional apic
|
||||
i386/i386/locore.s standard no-obj
|
||||
i386/i386/mem.c standard
|
||||
i386/i386/mem.c optional mem
|
||||
i386/i386/mp_clock.c optional smp
|
||||
i386/i386/mp_machdep.c optional smp
|
||||
i386/i386/mpboot.s optional smp
|
||||
|
@ -88,7 +88,7 @@ sparc64/sparc64/intr_machdep.c standard
|
||||
sparc64/sparc64/iommu.c standard
|
||||
sparc64/sparc64/locore.S standard no-obj
|
||||
sparc64/sparc64/machdep.c standard
|
||||
sparc64/sparc64/mem.c standard
|
||||
sparc64/sparc64/mem.c optional mem
|
||||
sparc64/sparc64/mp_exception.S optional smp
|
||||
sparc64/sparc64/mp_locore.S optional smp
|
||||
sparc64/sparc64/mp_machdep.c optional smp
|
||||
|
89
sys/dev/io/iodev.c
Normal file
89
sys/dev/io/iodev.c
Normal file
@ -0,0 +1,89 @@
|
||||
/*-
|
||||
* Copyright (c) 2004 Mark R V Murray
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer
|
||||
* in this position and unchanged.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/module.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/signalvar.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
#include <machine/specialreg.h>
|
||||
|
||||
#include <vm/vm.h>
|
||||
#include <vm/pmap.h>
|
||||
|
||||
#include <machine/iodev.h>
|
||||
|
||||
static struct cdev *iodev;
|
||||
|
||||
static struct cdevsw io_cdevsw = {
|
||||
.d_version = D_VERSION,
|
||||
.d_flags = D_NEEDGIANT,
|
||||
.d_open = ioopen,
|
||||
.d_close = ioclose,
|
||||
.d_name = "io",
|
||||
};
|
||||
|
||||
/* ARGSUSED */
|
||||
static int
|
||||
io_modevent(module_t mod __unused, int type, void *data __unused)
|
||||
{
|
||||
switch(type) {
|
||||
case MOD_LOAD:
|
||||
if (bootverbose)
|
||||
printf("io: <I/O>\n");
|
||||
iodev = make_dev(&io_cdevsw, CDEV_MINOR_IO,
|
||||
UID_ROOT, GID_WHEEL, 0600, "io");
|
||||
break;
|
||||
|
||||
case MOD_UNLOAD:
|
||||
destroy_dev(iodev);
|
||||
break;
|
||||
|
||||
case MOD_SHUTDOWN:
|
||||
break;
|
||||
|
||||
default:
|
||||
return(EOPNOTSUPP);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
DEV_MODULE(io, io_modevent, NULL);
|
108
sys/dev/mem/memdev.c
Normal file
108
sys/dev/mem/memdev.c
Normal file
@ -0,0 +1,108 @@
|
||||
/*-
|
||||
* Copyright (c) 2004 Mark R V Murray
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer
|
||||
* in this position and unchanged.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/memrange.h>
|
||||
#include <sys/module.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/signalvar.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
#include <vm/vm.h>
|
||||
#include <vm/pmap.h>
|
||||
|
||||
#include <machine/memdev.h>
|
||||
|
||||
static struct cdev *memdev, *kmemdev;
|
||||
|
||||
static struct cdevsw mem_cdevsw = {
|
||||
.d_version = D_VERSION,
|
||||
.d_flags = D_MEM|D_NEEDGIANT,
|
||||
.d_open = memopen,
|
||||
.d_read = memrw,
|
||||
.d_write = memrw,
|
||||
.d_ioctl = memioctl,
|
||||
.d_mmap = memmmap,
|
||||
.d_name = "mem",
|
||||
};
|
||||
|
||||
/* ARGSUSED */
|
||||
int
|
||||
memopen(struct cdev *dev __unused, int flags, int fmt __unused,
|
||||
struct thread *td)
|
||||
{
|
||||
int error = 0;
|
||||
|
||||
if (flags & FWRITE)
|
||||
error = securelevel_gt(td->td_ucred, 0);
|
||||
|
||||
return (error);
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
static int
|
||||
mem_modevent(module_t mod __unused, int type, void *data __unused)
|
||||
{
|
||||
switch(type) {
|
||||
case MOD_LOAD:
|
||||
if (bootverbose)
|
||||
printf("mem: <memory>\n");
|
||||
dev_mem_md_init(); /* Machine dependant bit */
|
||||
memdev = make_dev(&mem_cdevsw, CDEV_MINOR_MEM,
|
||||
UID_ROOT, GID_KMEM, 0640, "mem");
|
||||
kmemdev = make_dev(&mem_cdevsw, CDEV_MINOR_KMEM,
|
||||
UID_ROOT, GID_KMEM, 0640, "kmem");
|
||||
break;
|
||||
|
||||
case MOD_UNLOAD:
|
||||
destroy_dev(memdev);
|
||||
destroy_dev(kmemdev);
|
||||
break;
|
||||
|
||||
case MOD_SHUTDOWN:
|
||||
break;
|
||||
|
||||
default:
|
||||
return(EOPNOTSUPP);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
DEV_MODULE(mem, mem_modevent, NULL);
|
@ -43,14 +43,17 @@ __FBSDID("$FreeBSD$");
|
||||
/* For use with destroy_dev(9). */
|
||||
static struct cdev *null_dev;
|
||||
static struct cdev *zero_dev;
|
||||
static struct cdev *full_dev;
|
||||
|
||||
static d_write_t null_write;
|
||||
static d_ioctl_t null_ioctl;
|
||||
static d_read_t zero_read;
|
||||
static d_write_t full_write;
|
||||
|
||||
#define CDEV_MAJOR 2
|
||||
#define NULL_MINOR 2
|
||||
#define ZERO_MINOR 12
|
||||
#define NULL_MINOR 0
|
||||
#define ZERO_MINOR 1
|
||||
#define FULL_MINOR 2
|
||||
|
||||
static struct cdevsw null_cdevsw = {
|
||||
.d_version = D_VERSION,
|
||||
@ -70,6 +73,14 @@ static struct cdevsw zero_cdevsw = {
|
||||
.d_flags = D_MMAP_ANON,
|
||||
};
|
||||
|
||||
static struct cdevsw full_cdevsw = {
|
||||
.d_version = D_VERSION,
|
||||
.d_read = (d_read_t *)nullop,
|
||||
.d_write = full_write,
|
||||
.d_name = "full",
|
||||
.d_maj = CDEV_MAJOR,
|
||||
};
|
||||
|
||||
static void *zbuf;
|
||||
|
||||
/* ARGSUSED */
|
||||
@ -100,17 +111,21 @@ null_ioctl(struct cdev *dev __unused, u_long cmd, caddr_t data __unused,
|
||||
static int
|
||||
zero_read(struct cdev *dev __unused, struct uio *uio, int flags __unused)
|
||||
{
|
||||
int c;
|
||||
int error = 0;
|
||||
|
||||
while (uio->uio_resid > 0 && error == 0) {
|
||||
c = uio->uio_resid < PAGE_SIZE ? uio->uio_resid : PAGE_SIZE;
|
||||
error = uiomove(zbuf, c, uio);
|
||||
}
|
||||
while (uio->uio_resid > 0 && error == 0)
|
||||
error = uiomove(zbuf, MIN(uio->uio_resid, PAGE_SIZE), uio);
|
||||
|
||||
return (error);
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
static int
|
||||
full_write(struct cdev *dev __unused, struct uio *uio, int flags __unused)
|
||||
{
|
||||
return (ENOSPC);
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
static int
|
||||
null_modevent(module_t mod __unused, int type, void *data __unused)
|
||||
@ -120,15 +135,18 @@ null_modevent(module_t mod __unused, int type, void *data __unused)
|
||||
if (bootverbose)
|
||||
printf("null: <null device, zero device>\n");
|
||||
zbuf = (void *)malloc(PAGE_SIZE, M_TEMP, M_WAITOK | M_ZERO);
|
||||
zero_dev = make_dev(&zero_cdevsw, ZERO_MINOR, UID_ROOT,
|
||||
GID_WHEEL, 0666, "zero");
|
||||
null_dev = make_dev(&null_cdevsw, NULL_MINOR, UID_ROOT,
|
||||
GID_WHEEL, 0666, "null");
|
||||
zero_dev = make_dev(&zero_cdevsw, ZERO_MINOR, UID_ROOT,
|
||||
GID_WHEEL, 0666, "zero");
|
||||
full_dev = make_dev(&full_cdevsw, FULL_MINOR, UID_ROOT,
|
||||
GID_WHEEL, 0666, "full");
|
||||
break;
|
||||
|
||||
case MOD_UNLOAD:
|
||||
destroy_dev(null_dev);
|
||||
destroy_dev(zero_dev);
|
||||
destroy_dev(full_dev);
|
||||
free(zbuf, M_TEMP);
|
||||
break;
|
||||
|
||||
|
@ -29,7 +29,7 @@ ident GENERIC
|
||||
|
||||
makeoptions DEBUG=-g # Build kernel with gdb(1) debug symbols
|
||||
|
||||
options SCHED_ULE # ULE scheduler
|
||||
options SCHED_4BSD
|
||||
options INET # InterNETworking
|
||||
options INET6 # IPv6 communications protocols
|
||||
options FFS # Berkeley Fast Filesystem
|
||||
@ -239,8 +239,10 @@ device wi # WaveLAN/Intersil/Symbol 802.11 wireless NICs.
|
||||
#device wl # Older non 802.11 Wavelan wireless NIC.
|
||||
|
||||
# Pseudo devices.
|
||||
device random # Entropy device
|
||||
device loop # Network loopback
|
||||
device mem # Memory and kernel memory devices
|
||||
device null # Null and zero devices
|
||||
device random # Entropy device
|
||||
device ether # Ethernet support
|
||||
device sl # Kernel SLIP
|
||||
device ppp # Kernel PPP
|
||||
|
@ -1053,3 +1053,7 @@ options TIMER_FREQ=((14318182+6)/12)
|
||||
options VM_KMEM_SIZE
|
||||
options VM_KMEM_SIZE_MAX
|
||||
options VM_KMEM_SIZE_SCALE
|
||||
|
||||
|
||||
# The I/O device
|
||||
device io
|
||||
|
77
sys/i386/i386/io.c
Normal file
77
sys/i386/i386/io.c
Normal file
@ -0,0 +1,77 @@
|
||||
/*-
|
||||
* Copyright (c) 2004 Mark R V Murray
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer
|
||||
* in this position and unchanged.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/signalvar.h>
|
||||
#include <sys/systm.h>
|
||||
|
||||
#include <machine/db_machdep.h>
|
||||
#include <machine/frame.h>
|
||||
#include <machine/psl.h>
|
||||
#include <machine/specialreg.h>
|
||||
|
||||
#include <vm/vm.h>
|
||||
#include <vm/pmap.h>
|
||||
|
||||
#include <machine/iodev.h>
|
||||
|
||||
/* ARGSUSED */
|
||||
int
|
||||
ioopen(struct cdev *dev __unused, int flags __unused, int fmt __unused,
|
||||
struct thread *td)
|
||||
{
|
||||
int error;
|
||||
|
||||
error = suser(td);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
error = securelevel_gt(td->td_ucred, 0);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
|
||||
td->td_frame->tf_eflags |= PSL_IOPL;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
int
|
||||
ioclose(struct cdev *dev __unused, int flags __unused, int fmt __unused,
|
||||
struct thread *td)
|
||||
{
|
||||
td->td_frame->tf_eflags &= ~PSL_IOPL;
|
||||
|
||||
return (0);
|
||||
}
|
@ -58,81 +58,31 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/systm.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
#include <machine/db_machdep.h>
|
||||
#include <machine/frame.h>
|
||||
#include <machine/psl.h>
|
||||
#include <machine/specialreg.h>
|
||||
|
||||
#include <vm/vm.h>
|
||||
#include <vm/pmap.h>
|
||||
#include <vm/vm_extern.h>
|
||||
|
||||
static struct cdev *memdev, *kmemdev, *iodev;
|
||||
|
||||
static d_open_t mmopen;
|
||||
static d_close_t mmclose;
|
||||
static d_read_t mmrw;
|
||||
static d_ioctl_t mmioctl;
|
||||
static d_mmap_t memmmap;
|
||||
|
||||
#define CDEV_MAJOR 2
|
||||
static struct cdevsw mem_cdevsw = {
|
||||
.d_version = D_VERSION,
|
||||
.d_open = mmopen,
|
||||
.d_close = mmclose,
|
||||
.d_read = mmrw,
|
||||
.d_write = mmrw,
|
||||
.d_ioctl = mmioctl,
|
||||
.d_mmap = memmmap,
|
||||
.d_name = "mem",
|
||||
.d_maj = CDEV_MAJOR,
|
||||
.d_flags = D_MEM | D_NEEDGIANT,
|
||||
};
|
||||
#include <machine/memdev.h>
|
||||
|
||||
/*
|
||||
* Used in /dev/mem drivers and elsewhere
|
||||
*/
|
||||
MALLOC_DEFINE(M_MEMDESC, "memdesc", "memory range descriptors");
|
||||
|
||||
struct mem_range_softc mem_range_softc;
|
||||
|
||||
static int
|
||||
mmclose(struct cdev *dev, int flags, int fmt, struct thread *td)
|
||||
void
|
||||
mem_range_AP_init(void)
|
||||
{
|
||||
switch (minor(dev)) {
|
||||
case 14:
|
||||
td->td_frame->tf_eflags &= ~PSL_IOPL;
|
||||
}
|
||||
return (0);
|
||||
if (mem_range_softc.mr_op && mem_range_softc.mr_op->initAP)
|
||||
mem_range_softc.mr_op->initAP(&mem_range_softc);
|
||||
}
|
||||
|
||||
static int
|
||||
mmopen(struct cdev *dev, int flags, int fmt, struct thread *td)
|
||||
{
|
||||
int error;
|
||||
|
||||
switch (minor(dev)) {
|
||||
case 0:
|
||||
case 1:
|
||||
if (flags & FWRITE) {
|
||||
error = securelevel_gt(td->td_ucred, 0);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
}
|
||||
break;
|
||||
case 14:
|
||||
error = suser(td);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
error = securelevel_gt(td->td_ucred, 0);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
td->td_frame->tf_eflags |= PSL_IOPL;
|
||||
break;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static int
|
||||
mmrw(struct cdev *dev, struct uio *uio, int flags)
|
||||
/* ARGSUSED */
|
||||
int
|
||||
memrw(struct cdev *dev, struct uio *uio, int flags)
|
||||
{
|
||||
int o;
|
||||
u_int c = 0, v;
|
||||
@ -148,13 +98,10 @@ mmrw(struct cdev *dev, struct uio *uio, int flags)
|
||||
uio->uio_iov++;
|
||||
uio->uio_iovcnt--;
|
||||
if (uio->uio_iovcnt < 0)
|
||||
panic("mmrw");
|
||||
panic("memrw");
|
||||
continue;
|
||||
}
|
||||
switch (minor(dev)) {
|
||||
|
||||
/* minor device 0 is physical memory */
|
||||
case 0:
|
||||
if (minor(dev) == CDEV_MINOR_MEM) {
|
||||
v = uio->uio_offset;
|
||||
v &= ~PAGE_MASK;
|
||||
pmap_kenter((vm_offset_t)ptvmmap, v);
|
||||
@ -165,14 +112,14 @@ mmrw(struct cdev *dev, struct uio *uio, int flags)
|
||||
error = uiomove((caddr_t)&ptvmmap[o], (int)c, uio);
|
||||
pmap_qremove((vm_offset_t)ptvmmap, 1);
|
||||
continue;
|
||||
|
||||
/* minor device 1 is kernel memory */
|
||||
case 1:
|
||||
}
|
||||
else if (minor(dev) == CDEV_MINOR_KMEM) {
|
||||
c = iov->iov_len;
|
||||
|
||||
/*
|
||||
* Make sure that all of the pages are currently resident so
|
||||
* that we don't create any zero-fill pages.
|
||||
* Make sure that all of the pages are currently
|
||||
* resident so that we don't create any zero-fill
|
||||
* pages.
|
||||
*/
|
||||
addr = trunc_page(uio->uio_offset);
|
||||
eaddr = round_page(uio->uio_offset + c);
|
||||
@ -189,44 +136,26 @@ mmrw(struct cdev *dev, struct uio *uio, int flags)
|
||||
return (EFAULT);
|
||||
error = uiomove((caddr_t)(int)uio->uio_offset, (int)c, uio);
|
||||
continue;
|
||||
|
||||
default:
|
||||
return (ENODEV);
|
||||
}
|
||||
|
||||
if (error)
|
||||
break;
|
||||
iov->iov_base = (char *)iov->iov_base + c;
|
||||
iov->iov_len -= c;
|
||||
uio->uio_offset += c;
|
||||
uio->uio_resid -= c;
|
||||
/* else panic! */
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*******************************************************\
|
||||
* allow user processes to MMAP some memory sections *
|
||||
* instead of going through read/write *
|
||||
\*******************************************************/
|
||||
static int
|
||||
memmmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int prot)
|
||||
/*
|
||||
* allow user processes to MMAP some memory sections
|
||||
* instead of going through read/write
|
||||
*/
|
||||
/* ARGSUSED */
|
||||
int
|
||||
memmmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr,
|
||||
int prot __unused)
|
||||
{
|
||||
switch (minor(dev))
|
||||
{
|
||||
|
||||
/* minor device 0 is physical memory */
|
||||
case 0:
|
||||
if (minor(dev) == CDEV_MINOR_MEM)
|
||||
*paddr = offset;
|
||||
break;
|
||||
|
||||
/* minor device 1 is kernel memory */
|
||||
case 1:
|
||||
else if (minor(dev) == CDEV_MINOR_KMEM)
|
||||
*paddr = vtophys(offset);
|
||||
break;
|
||||
|
||||
default:
|
||||
return (-1);
|
||||
}
|
||||
/* else panic! */
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -236,8 +165,10 @@ memmmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int prot)
|
||||
* This is basically just an ioctl shim for mem_range_attr_get
|
||||
* and mem_range_attr_set.
|
||||
*/
|
||||
static int
|
||||
mmioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags, struct thread *td)
|
||||
/* ARGSUSED */
|
||||
int
|
||||
memioctl(struct cdev *dev __unused, u_long cmd, caddr_t data, int flags,
|
||||
struct thread *td)
|
||||
{
|
||||
int nd, error = 0;
|
||||
struct mem_range_op *mo = (struct mem_range_op *)data;
|
||||
@ -317,46 +248,9 @@ mem_range_attr_set(struct mem_range_desc *mrd, int *arg)
|
||||
return (mem_range_softc.mr_op->set(&mem_range_softc, mrd, arg));
|
||||
}
|
||||
|
||||
#ifdef SMP
|
||||
void
|
||||
mem_range_AP_init(void)
|
||||
dev_mem_md_init(void)
|
||||
{
|
||||
if (mem_range_softc.mr_op && mem_range_softc.mr_op->initAP)
|
||||
(mem_range_softc.mr_op->initAP(&mem_range_softc));
|
||||
if (mem_range_softc.mr_op != NULL)
|
||||
mem_range_softc.mr_op->init(&mem_range_softc);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
mem_modevent(module_t mod, int type, void *data)
|
||||
{
|
||||
switch(type) {
|
||||
case MOD_LOAD:
|
||||
if (bootverbose)
|
||||
printf("mem: <memory & I/O>\n");
|
||||
/* Initialise memory range handling */
|
||||
if (mem_range_softc.mr_op != NULL)
|
||||
mem_range_softc.mr_op->init(&mem_range_softc);
|
||||
|
||||
memdev = make_dev(&mem_cdevsw, 0, UID_ROOT, GID_KMEM,
|
||||
0640, "mem");
|
||||
kmemdev = make_dev(&mem_cdevsw, 1, UID_ROOT, GID_KMEM,
|
||||
0640, "kmem");
|
||||
iodev = make_dev(&mem_cdevsw, 14, UID_ROOT, GID_WHEEL,
|
||||
0600, "io");
|
||||
return (0);
|
||||
|
||||
case MOD_UNLOAD:
|
||||
destroy_dev(memdev);
|
||||
destroy_dev(kmemdev);
|
||||
destroy_dev(iodev);
|
||||
return (0);
|
||||
|
||||
case MOD_SHUTDOWN:
|
||||
return (0);
|
||||
|
||||
default:
|
||||
return (EOPNOTSUPP);
|
||||
}
|
||||
}
|
||||
|
||||
DEV_MODULE(mem, mem_modevent, NULL);
|
||||
|
33
sys/i386/include/iodev.h
Normal file
33
sys/i386/include/iodev.h
Normal file
@ -0,0 +1,33 @@
|
||||
/*-
|
||||
* Copyright (c) 2004 Mark R V Murray
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer
|
||||
* in this position and unchanged.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#define CDEV_MAJOR 2
|
||||
#define CDEV_MINOR_IO 14
|
||||
|
||||
d_open_t ioopen;
|
||||
d_close_t ioclose;
|
40
sys/i386/include/memdev.h
Normal file
40
sys/i386/include/memdev.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*-
|
||||
* Copyright (c) 2004 Mark R V Murray
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer
|
||||
* in this position and unchanged.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#define CDEV_MAJOR 2
|
||||
#define CDEV_MINOR_MEM 0
|
||||
#define CDEV_MINOR_KMEM 1
|
||||
|
||||
d_open_t memopen;
|
||||
d_read_t memrw;
|
||||
d_ioctl_t memioctl;
|
||||
d_mmap_t memmmap;
|
||||
|
||||
void dev_mem_md_init(void);
|
||||
|
||||
MALLOC_DECLARE(M_MEMDEV);
|
@ -140,6 +140,8 @@ device loop # Network loopback
|
||||
device md # Memory "disks"
|
||||
device pty # Pseudo-ttys (telnet etc)
|
||||
device puc # Multi I/O cards and multi-channel UARTs
|
||||
device null # Null and zero devices
|
||||
device mem # Memory and kernel memory devices
|
||||
device random # Entropy device
|
||||
device tun # Packet tunnel.
|
||||
device uart # Serial port (UART)
|
||||
|
@ -34,9 +34,11 @@
|
||||
*
|
||||
* from: Utah $Hdr: mem.c 1.13 89/10/08$
|
||||
* from: @(#)mem.c 7.2 (Berkeley) 5/9/91
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* Memory special file
|
||||
*/
|
||||
@ -58,38 +60,12 @@
|
||||
|
||||
#include <machine/cpu.h>
|
||||
#include <machine/frame.h>
|
||||
#ifdef PERFMON
|
||||
#include <machine/perfmon.h>
|
||||
#endif
|
||||
|
||||
#include <vm/vm.h>
|
||||
#include <vm/pmap.h>
|
||||
#include <vm/vm_extern.h>
|
||||
|
||||
static struct cdev *memdev, *kmemdev;
|
||||
#ifdef PERFMON
|
||||
static struct cdev *perfdev;
|
||||
#endif /* PERFMON */
|
||||
|
||||
static d_open_t mmopen;
|
||||
static d_close_t mmclose;
|
||||
static d_read_t mmrw;
|
||||
static d_ioctl_t mmioctl;
|
||||
static d_mmap_t memmmap;
|
||||
|
||||
#define CDEV_MAJOR 2
|
||||
static struct cdevsw mem_cdevsw = {
|
||||
.d_version = D_VERSION,
|
||||
.d_open = mmopen,
|
||||
.d_close = mmclose,
|
||||
.d_read = mmrw,
|
||||
.d_write = mmrw,
|
||||
.d_ioctl = mmioctl,
|
||||
.d_mmap = memmmap,
|
||||
.d_name = "mem",
|
||||
.d_maj = CDEV_MAJOR,
|
||||
.d_flags = D_MEM | D_NEEDGIANT,
|
||||
};
|
||||
#include <machine/memdev.h>
|
||||
|
||||
struct mem_range_softc mem_range_softc;
|
||||
|
||||
@ -99,49 +75,9 @@ ia64_pa_access(vm_offset_t pa)
|
||||
return (VM_PROT_READ|VM_PROT_WRITE);
|
||||
}
|
||||
|
||||
static int
|
||||
mmclose(struct cdev *dev, int flags, int fmt, struct thread *td)
|
||||
{
|
||||
switch (minor(dev)) {
|
||||
#ifdef PERFMON
|
||||
case 32:
|
||||
return perfmon_close(dev, flags, fmt, td);
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
mmopen(struct cdev *dev, int flags, int fmt, struct thread *td)
|
||||
{
|
||||
int error;
|
||||
|
||||
switch (minor(dev)) {
|
||||
case 0:
|
||||
case 1:
|
||||
if (flags & FWRITE) {
|
||||
error = securelevel_gt(td->td_ucred, 0);
|
||||
if (error)
|
||||
return error;
|
||||
}
|
||||
break;
|
||||
case 32:
|
||||
#ifdef PERFMON
|
||||
return perfmon_open(dev, flags, fmt, td);
|
||||
#else
|
||||
return ENODEV;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static int
|
||||
mmrw(struct cdev *dev, struct uio *uio, int flags)
|
||||
/* ARGSUSED */
|
||||
int
|
||||
memrw(strct cdev *dev, struct uio *uio, int flags)
|
||||
{
|
||||
struct iovec *iov;
|
||||
vm_offset_t addr, eaddr, o, v;
|
||||
@ -154,14 +90,11 @@ mmrw(struct cdev *dev, struct uio *uio, int flags)
|
||||
uio->uio_iov++;
|
||||
uio->uio_iovcnt--;
|
||||
if (uio->uio_iovcnt < 0)
|
||||
panic("mmrw");
|
||||
panic("memrw");
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (minor(dev)) {
|
||||
|
||||
/* minor device 0 is physical memory */
|
||||
case 0:
|
||||
if (minor(dev) == CDEV_MINOR_MEM) {
|
||||
v = uio->uio_offset;
|
||||
kmemphys:
|
||||
/* Allow reads only in RAM. */
|
||||
@ -177,9 +110,8 @@ mmrw(struct cdev *dev, struct uio *uio, int flags)
|
||||
c = min(uio->uio_resid, (int)(PAGE_SIZE - o));
|
||||
error = uiomove((caddr_t)IA64_PHYS_TO_RR7(v), c, uio);
|
||||
continue;
|
||||
|
||||
/* minor device 1 is kernel memory */
|
||||
case 1:
|
||||
}
|
||||
else if (minor(dev) == CDEV_MINOR_KMEM) {
|
||||
v = uio->uio_offset;
|
||||
|
||||
if (v >= IA64_RR_BASE(6)) {
|
||||
@ -205,27 +137,18 @@ mmrw(struct cdev *dev, struct uio *uio, int flags)
|
||||
return (EFAULT);
|
||||
error = uiomove((caddr_t)v, c, uio);
|
||||
continue;
|
||||
|
||||
default:
|
||||
return (ENODEV);
|
||||
}
|
||||
|
||||
if (error)
|
||||
break;
|
||||
iov->iov_base = (char *)iov->iov_base + c;
|
||||
iov->iov_len -= c;
|
||||
uio->uio_offset += c;
|
||||
uio->uio_resid -= c;
|
||||
/* else panic! */
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*******************************************************\
|
||||
* allow user processes to MMAP some memory sections *
|
||||
* instead of going through read/write *
|
||||
\*******************************************************/
|
||||
static int
|
||||
memmmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int prot)
|
||||
/*
|
||||
* allow user processes to MMAP some memory sections
|
||||
* instead of going through read/write
|
||||
*/
|
||||
int
|
||||
memmmap(strct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int prot)
|
||||
{
|
||||
/*
|
||||
* /dev/mem is the only one that makes sense through this
|
||||
@ -233,7 +156,7 @@ memmmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int prot)
|
||||
* could be transient and hence incorrect or invalid at
|
||||
* a later time.
|
||||
*/
|
||||
if (minor(dev) != 0)
|
||||
if (minor(dev) != CDEV_MINOR_MEM)
|
||||
return (-1);
|
||||
|
||||
/*
|
||||
@ -245,59 +168,7 @@ memmmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int prot)
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
mmioctl(struct cdev *dev, u_long cmd, caddr_t cmdarg, int flags, struct thread *td)
|
||||
void
|
||||
dev_mem_md_init(void)
|
||||
{
|
||||
switch(minor(dev)) {
|
||||
#ifdef PERFMON
|
||||
case 32:
|
||||
return perfmon_ioctl(dev, cmd, cmdarg, flags, td);
|
||||
#endif
|
||||
default:
|
||||
return ENODEV;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
mem_modevent(module_t mod, int type, void *data)
|
||||
{
|
||||
switch(type) {
|
||||
case MOD_LOAD:
|
||||
if (bootverbose)
|
||||
printf("mem: <memory & I/O>\n");
|
||||
/* XXX - ??? */
|
||||
#if 0
|
||||
/* Initialise memory range handling */
|
||||
if (mem_range_softc.mr_op != NULL)
|
||||
mem_range_softc.mr_op->init(&mem_range_softc);
|
||||
#endif
|
||||
|
||||
memdev = make_dev(&mem_cdevsw, 0, UID_ROOT, GID_KMEM,
|
||||
0640, "mem");
|
||||
kmemdev = make_dev(&mem_cdevsw, 1, UID_ROOT, GID_KMEM,
|
||||
0640, "kmem");
|
||||
#ifdef PERFMON
|
||||
perfdev = make_dev(&mem_cdevsw, 32, UID_ROOT, GID_KMEM,
|
||||
0640, "perfmon");
|
||||
#endif /* PERFMON */
|
||||
return 0;
|
||||
|
||||
case MOD_UNLOAD:
|
||||
destroy_dev(memdev);
|
||||
destroy_dev(kmemdev);
|
||||
#ifdef PERFMON
|
||||
destroy_dev(perfdev);
|
||||
#endif /* PERFMON */
|
||||
return 0;
|
||||
|
||||
case MOD_SHUTDOWN:
|
||||
return 0;
|
||||
|
||||
default:
|
||||
return EOPNOTSUPP;
|
||||
}
|
||||
}
|
||||
|
||||
DEV_MODULE(mem, mem_modevent, NULL);
|
||||
|
38
sys/ia64/include/memdev.h
Normal file
38
sys/ia64/include/memdev.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*-
|
||||
* Copyright (c) 2004 Mark R V Murray
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer
|
||||
* in this position and unchanged.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#define CDEV_MAJOR 2
|
||||
#define CDEV_MINOR_MEM 0
|
||||
#define CDEV_MINOR_KMEM 1
|
||||
|
||||
d_open_t memopen;
|
||||
d_read_t memrw;
|
||||
#define memioctl (d_ioctl_t *)NULL;
|
||||
d_mmap_t memmmap;
|
||||
|
||||
void dev_mem_md_init(void);
|
@ -101,6 +101,7 @@ SUBDIR= ${_3dfx} \
|
||||
if_tun \
|
||||
if_vlan \
|
||||
${_iir} \
|
||||
${_io} \
|
||||
ip6fw \
|
||||
${_ipfilter} \
|
||||
ipfw \
|
||||
@ -131,6 +132,7 @@ SUBDIR= ${_3dfx} \
|
||||
mac_test \
|
||||
mcd \
|
||||
md \
|
||||
mem \
|
||||
mii \
|
||||
mlx \
|
||||
${_mly} \
|
||||
@ -149,7 +151,7 @@ SUBDIR= ${_3dfx} \
|
||||
${_nsp} \
|
||||
ntfs \
|
||||
ntfs_iconv \
|
||||
${_null} \
|
||||
null \
|
||||
nullfs \
|
||||
${_nwfs} \
|
||||
${_oltr} \
|
||||
@ -252,7 +254,6 @@ _syscons= syscons
|
||||
.endif
|
||||
|
||||
.if defined(ALL_MODULES)
|
||||
_null= null
|
||||
_ufs= ufs
|
||||
.endif
|
||||
|
||||
@ -301,6 +302,7 @@ _hfa= hfa
|
||||
_i2c= i2c
|
||||
_ibcs2= ibcs2
|
||||
_ie= ie
|
||||
_io= io
|
||||
_linprocfs= linprocfs
|
||||
_linux= linux
|
||||
_lnc= lnc
|
||||
@ -374,6 +376,7 @@ _sppp= sppp
|
||||
.endif
|
||||
|
||||
.if ${MACHINE_ARCH} == "amd64"
|
||||
_io= io
|
||||
#_ndis= ndis
|
||||
.endif
|
||||
|
||||
|
10
sys/modules/io/Makefile
Normal file
10
sys/modules/io/Makefile
Normal file
@ -0,0 +1,10 @@
|
||||
# $FreeBSD$
|
||||
|
||||
.PATH: ${.CURDIR}/../../dev/io
|
||||
.PATH: ${.CURDIR}/../../${MACHINE_ARCH}/${MACHINE_ARCH}
|
||||
|
||||
KMOD= io
|
||||
SRCS= iodev.c io.c
|
||||
SRCS+= bus_if.h device_if.h vnode_if.h
|
||||
|
||||
.include <bsd.kmod.mk>
|
10
sys/modules/mem/Makefile
Normal file
10
sys/modules/mem/Makefile
Normal file
@ -0,0 +1,10 @@
|
||||
# $FreeBSD$
|
||||
|
||||
.PATH: ${.CURDIR}/../../dev/mem
|
||||
.PATH: ${.CURDIR}/../../${MACHINE_ARCH}/${MACHINE_ARCH}
|
||||
|
||||
KMOD= mem
|
||||
SRCS= memdev.c mem.c
|
||||
SRCS+= bus_if.h device_if.h vnode_if.h
|
||||
|
||||
.include <bsd.kmod.mk>
|
@ -216,8 +216,10 @@ device wi # WaveLAN/Intersil/Symbol 802.11 wireless NICs.
|
||||
#device wl # Older non 802.11 Wavelan wireless NIC.
|
||||
|
||||
# Pseudo devices.
|
||||
device random # Entropy device
|
||||
device loop # Network loopback
|
||||
device mem # Memory and kernel memory devices
|
||||
device null # Null and zero devices
|
||||
device random # Entropy device
|
||||
device ether # Ethernet support
|
||||
device sl # Kernel SLIP
|
||||
device ppp # Kernel PPP
|
||||
|
@ -102,8 +102,10 @@ device dc # DEC/Intel 21143 and various workalikes
|
||||
device fxp # Intel EtherExpress PRO/100B (82557, 82558)
|
||||
|
||||
# Pseudo devices.
|
||||
device random # Entropy device
|
||||
device loop # Network loopback
|
||||
device mem # Memory and kernel memory devices
|
||||
device null # Null and zero devices
|
||||
device random # Entropy device
|
||||
device ether # Ethernet support
|
||||
device sl # Kernel SLIP
|
||||
device ppp # Kernel PPP
|
||||
|
@ -165,8 +165,10 @@ device rl # RealTek 8129/8139
|
||||
device xl # 3Com 3c90x (``Boomerang'', ``Cyclone'')
|
||||
|
||||
# Pseudo devices.
|
||||
device random # Entropy device
|
||||
device loop # Network loopback
|
||||
device mem # Memory and kernel memory devices
|
||||
device null # Null and zero devices
|
||||
device random # Entropy device
|
||||
device ether # Ethernet support
|
||||
device sl # Kernel SLIP
|
||||
device ppp # Kernel PPP
|
||||
|
38
sys/sparc64/include/memdev.h
Normal file
38
sys/sparc64/include/memdev.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*-
|
||||
* Copyright (c) 2004 Mark R V Murray
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer
|
||||
* in this position and unchanged.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#define CDEV_MAJOR 2
|
||||
#define CDEV_MINOR_MEM 0
|
||||
#define CDEV_MINOR_KMEM 1
|
||||
|
||||
d_open_t memopen;
|
||||
d_read_t memrw;
|
||||
#define memioctl (d_ioctl_t *)NULL
|
||||
#define memmmap (d_mmap_t *)NULL
|
||||
|
||||
void dev_mem_md_init(void);
|
@ -35,10 +35,11 @@
|
||||
* from: Utah $Hdr: mem.c 1.13 89/10/08$
|
||||
* from: @(#)mem.c 7.2 (Berkeley) 5/9/91
|
||||
* from: FreeBSD: src/sys/i386/i386/mem.c,v 1.94 2001/09/26
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* Memory special file
|
||||
*
|
||||
@ -52,9 +53,10 @@
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/memrange.h>
|
||||
#include <sys/module.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/module.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/signalvar.h>
|
||||
#include <sys/systm.h>
|
||||
@ -73,54 +75,13 @@
|
||||
#include <machine/tlb.h>
|
||||
#include <machine/upa.h>
|
||||
|
||||
static struct cdev *memdev, *kmemdev;
|
||||
#include <machine/memdev.h>
|
||||
|
||||
static d_open_t mmopen;
|
||||
static d_close_t mmclose;
|
||||
static d_read_t mmrw;
|
||||
struct mem_range_softc mem_range_softc;
|
||||
|
||||
#define CDEV_MAJOR 2
|
||||
static struct cdevsw mem_cdevsw = {
|
||||
.d_version = D_VERSION,
|
||||
.d_open = mmopen,
|
||||
.d_close = mmclose,
|
||||
.d_read = mmrw,
|
||||
.d_write = mmrw,
|
||||
.d_name = "mem",
|
||||
.d_maj = CDEV_MAJOR,
|
||||
.d_flags = D_MEM | D_NEEDGIANT,
|
||||
};
|
||||
|
||||
static int
|
||||
mmclose(struct cdev *dev, int flags, int fmt, struct thread *td)
|
||||
{
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
mmopen(struct cdev *dev, int flags, int fmt, struct thread *td)
|
||||
{
|
||||
int error;
|
||||
|
||||
switch (minor(dev)) {
|
||||
case 0:
|
||||
case 1:
|
||||
if (flags & FWRITE) {
|
||||
error = securelevel_gt(td->td_ucred, 0);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return (ENXIO);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static int
|
||||
mmrw(struct cdev *dev, struct uio *uio, int flags)
|
||||
/* ARGSUSED */
|
||||
int
|
||||
memrw(struct cdev *dev, struct uio *uio, int flags)
|
||||
{
|
||||
struct iovec *iov;
|
||||
vm_offset_t eva;
|
||||
@ -147,12 +108,10 @@ mmrw(struct cdev *dev, struct uio *uio, int flags)
|
||||
uio->uio_iov++;
|
||||
uio->uio_iovcnt--;
|
||||
if (uio->uio_iovcnt < 0)
|
||||
panic("mmrw");
|
||||
panic("memrw");
|
||||
continue;
|
||||
}
|
||||
switch (minor(dev)) {
|
||||
case 0:
|
||||
/* mem (physical memory) */
|
||||
if (minor(dev) == CDEV_MINOR_MEM) {
|
||||
pa = uio->uio_offset & ~PAGE_MASK;
|
||||
if (!is_physical_memory(pa)) {
|
||||
error = EFAULT;
|
||||
@ -193,8 +152,8 @@ mmrw(struct cdev *dev, struct uio *uio, int flags)
|
||||
uio);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
/* kmem (kernel memory) */
|
||||
}
|
||||
else if (minor(dev) == CDEV_MINOR_KMEM) {
|
||||
va = trunc_page(uio->uio_offset);
|
||||
eva = round_page(uio->uio_offset + iov->iov_len);
|
||||
|
||||
@ -215,40 +174,15 @@ mmrw(struct cdev *dev, struct uio *uio, int flags)
|
||||
|
||||
error = uiomove((void *)va, iov->iov_len, uio);
|
||||
break;
|
||||
default:
|
||||
return (ENODEV);
|
||||
}
|
||||
/* else panic! */
|
||||
}
|
||||
if (ova != 0)
|
||||
kmem_free_wakeup(kernel_map, ova, PAGE_SIZE * DCACHE_COLORS);
|
||||
return (error);
|
||||
}
|
||||
|
||||
static int
|
||||
mem_modevent(module_t mod, int type, void *data)
|
||||
void
|
||||
dev_mem_md_init(void)
|
||||
{
|
||||
switch(type) {
|
||||
case MOD_LOAD:
|
||||
if (bootverbose)
|
||||
printf("mem: <memory & I/O>\n");
|
||||
|
||||
memdev = make_dev(&mem_cdevsw, 0, UID_ROOT, GID_KMEM,
|
||||
0640, "mem");
|
||||
kmemdev = make_dev(&mem_cdevsw, 1, UID_ROOT, GID_KMEM,
|
||||
0640, "kmem");
|
||||
return 0;
|
||||
|
||||
case MOD_UNLOAD:
|
||||
destroy_dev(memdev);
|
||||
destroy_dev(kmemdev);
|
||||
return 0;
|
||||
|
||||
case MOD_SHUTDOWN:
|
||||
return 0;
|
||||
|
||||
default:
|
||||
return EOPNOTSUPP;
|
||||
}
|
||||
}
|
||||
|
||||
DEV_MODULE(mem, mem_modevent, NULL);
|
||||
|
Loading…
Reference in New Issue
Block a user