diff options
author | markm <markm@FreeBSD.org> | 2004-08-01 11:40:54 +0000 |
---|---|---|
committer | markm <markm@FreeBSD.org> | 2004-08-01 11:40:54 +0000 |
commit | a6c822020d368106b01f399673116ff8716835c7 (patch) | |
tree | 6d7271eea5bb8ced5f0b1cdd585641f60f5622e5 /sys | |
parent | d879bd3de14d88aabd818b50f6e9341d3008ae95 (diff) | |
download | FreeBSD-src-a6c822020d368106b01f399673116ff8716835c7.zip FreeBSD-src-a6c822020d368106b01f399673116ff8716835c7.tar.gz |
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.
Diffstat (limited to 'sys')
37 files changed, 833 insertions, 692 deletions
diff --git a/sys/alpha/alpha/mem.c b/sys/alpha/alpha/mem.c index a64ea2a..fdc59ca 100644 --- a/sys/alpha/alpha/mem.c +++ b/sys/alpha/alpha/mem.c @@ -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 @@ kmemphys: 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 @@ kmemphys: 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 @@ kmemphys: 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) -{ - 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) +void +dev_mem_md_init(void) { - 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); diff --git a/sys/alpha/conf/GENERIC b/sys/alpha/conf/GENERIC index b472cf5..08edc0f 100644 --- a/sys/alpha/conf/GENERIC +++ b/sys/alpha/conf/GENERIC @@ -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 diff --git a/sys/alpha/include/memdev.h b/sys/alpha/include/memdev.h new file mode 100644 index 0000000..e2ec491 --- /dev/null +++ b/sys/alpha/include/memdev.h @@ -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); diff --git a/sys/amd64/amd64/io.c b/sys/amd64/amd64/io.c new file mode 100644 index 0000000..1aaf2ef --- /dev/null +++ b/sys/amd64/amd64/io.c @@ -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); +} diff --git a/sys/amd64/amd64/mem.c b/sys/amd64/amd64/mem.c index 739ae6d..2d0506e 100644 --- a/sys/amd64/amd64/mem.c +++ b/sys/amd64/amd64/mem.c @@ -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 @@ kmemphys: 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 @@ kmemphys: 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); diff --git a/sys/amd64/conf/GENERIC b/sys/amd64/conf/GENERIC index aa9848d..a6368d3 100644 --- a/sys/amd64/conf/GENERIC +++ b/sys/amd64/conf/GENERIC @@ -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 diff --git a/sys/amd64/conf/NOTES b/sys/amd64/conf/NOTES index d3610a6..b21160c 100644 --- a/sys/amd64/conf/NOTES +++ b/sys/amd64/conf/NOTES @@ -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 diff --git a/sys/amd64/include/iodev.h b/sys/amd64/include/iodev.h new file mode 100644 index 0000000..2273620 --- /dev/null +++ b/sys/amd64/include/iodev.h @@ -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; diff --git a/sys/amd64/include/memdev.h b/sys/amd64/include/memdev.h new file mode 100644 index 0000000..b6d3122 --- /dev/null +++ b/sys/amd64/include/memdev.h @@ -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); diff --git a/sys/conf/NOTES b/sys/conf/NOTES index 40d23b4..c919e31 100644 --- a/sys/conf/NOTES +++ b/sys/conf/NOTES @@ -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 diff --git a/sys/conf/files b/sys/conf/files index ab5ff56..b84fdaf 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -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 diff --git a/sys/conf/files.alpha b/sys/conf/files.alpha index 73f166d..6b3553b 100644 --- a/sys/conf/files.alpha +++ b/sys/conf/files.alpha @@ -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 diff --git a/sys/conf/files.amd64 b/sys/conf/files.amd64 index 2147cce..74a254a 100644 --- a/sys/conf/files.amd64 +++ b/sys/conf/files.amd64 @@ -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 diff --git a/sys/conf/files.i386 b/sys/conf/files.i386 index d569b44..b5aa266 100644 --- a/sys/conf/files.i386 +++ b/sys/conf/files.i386 @@ -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 diff --git a/sys/conf/files.ia64 b/sys/conf/files.ia64 index b4d2e94..8d1ccab 100644 --- a/sys/conf/files.ia64 +++ b/sys/conf/files.ia64 @@ -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 diff --git a/sys/conf/files.pc98 b/sys/conf/files.pc98 index 3a377b7..bfb08a7 100644 --- a/sys/conf/files.pc98 +++ b/sys/conf/files.pc98 @@ -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 diff --git a/sys/conf/files.sparc64 b/sys/conf/files.sparc64 index 878930e..148483e 100644 --- a/sys/conf/files.sparc64 +++ b/sys/conf/files.sparc64 @@ -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 diff --git a/sys/dev/io/iodev.c b/sys/dev/io/iodev.c new file mode 100644 index 0000000..d1b3170 --- /dev/null +++ b/sys/dev/io/iodev.c @@ -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); diff --git a/sys/dev/mem/memdev.c b/sys/dev/mem/memdev.c new file mode 100644 index 0000000..290259a --- /dev/null +++ b/sys/dev/mem/memdev.c @@ -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); diff --git a/sys/dev/null/null.c b/sys/dev/null/null.c index 4f7bd9c..653d732 100644 --- a/sys/dev/null/null.c +++ b/sys/dev/null/null.c @@ -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,19 +111,23 @@ 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) { switch(type) { @@ -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; diff --git a/sys/i386/conf/GENERIC b/sys/i386/conf/GENERIC index 3fce0da..f8ae817 100644 --- a/sys/i386/conf/GENERIC +++ b/sys/i386/conf/GENERIC @@ -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 diff --git a/sys/i386/conf/NOTES b/sys/i386/conf/NOTES index c1d05f5..6a6b4e6 100644 --- a/sys/i386/conf/NOTES +++ b/sys/i386/conf/NOTES @@ -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 diff --git a/sys/i386/i386/io.c b/sys/i386/i386/io.c new file mode 100644 index 0000000..1c0866d --- /dev/null +++ b/sys/i386/i386/io.c @@ -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); +} diff --git a/sys/i386/i386/mem.c b/sys/i386/i386/mem.c index 379b59c..444499c 100644 --- a/sys/i386/i386/mem.c +++ b/sys/i386/i386/mem.c @@ -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); diff --git a/sys/i386/include/iodev.h b/sys/i386/include/iodev.h new file mode 100644 index 0000000..2273620 --- /dev/null +++ b/sys/i386/include/iodev.h @@ -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; diff --git a/sys/i386/include/memdev.h b/sys/i386/include/memdev.h new file mode 100644 index 0000000..4443e36 --- /dev/null +++ b/sys/i386/include/memdev.h @@ -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); diff --git a/sys/ia64/conf/GENERIC b/sys/ia64/conf/GENERIC index 859cd9d..f19dfc3 100644 --- a/sys/ia64/conf/GENERIC +++ b/sys/ia64/conf/GENERIC @@ -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) diff --git a/sys/ia64/ia64/mem.c b/sys/ia64/ia64/mem.c index d03051f..79c97ee 100644 --- a/sys/ia64/ia64/mem.c +++ b/sys/ia64/ia64/mem.c @@ -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 @@ kmemphys: 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 @@ kmemphys: 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); diff --git a/sys/ia64/include/memdev.h b/sys/ia64/include/memdev.h new file mode 100644 index 0000000..e2ec491 --- /dev/null +++ b/sys/ia64/include/memdev.h @@ -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); diff --git a/sys/modules/Makefile b/sys/modules/Makefile index 98052a7..938c4c8 100644 --- a/sys/modules/Makefile +++ b/sys/modules/Makefile @@ -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 diff --git a/sys/modules/io/Makefile b/sys/modules/io/Makefile new file mode 100644 index 0000000..ffb3442 --- /dev/null +++ b/sys/modules/io/Makefile @@ -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> diff --git a/sys/modules/mem/Makefile b/sys/modules/mem/Makefile new file mode 100644 index 0000000..d1529a5 --- /dev/null +++ b/sys/modules/mem/Makefile @@ -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> diff --git a/sys/pc98/conf/GENERIC b/sys/pc98/conf/GENERIC index 6498139..23db02c 100644 --- a/sys/pc98/conf/GENERIC +++ b/sys/pc98/conf/GENERIC @@ -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 diff --git a/sys/powerpc/conf/GENERIC b/sys/powerpc/conf/GENERIC index 0da074d..c0cebc3 100644 --- a/sys/powerpc/conf/GENERIC +++ b/sys/powerpc/conf/GENERIC @@ -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 diff --git a/sys/sparc64/conf/GENERIC b/sys/sparc64/conf/GENERIC index d5fe010..dab8d2e 100644 --- a/sys/sparc64/conf/GENERIC +++ b/sys/sparc64/conf/GENERIC @@ -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 diff --git a/sys/sparc64/include/memdev.h b/sys/sparc64/include/memdev.h new file mode 100644 index 0000000..671a6b4 --- /dev/null +++ b/sys/sparc64/include/memdev.h @@ -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); diff --git a/sys/sparc64/sparc64/mem.c b/sys/sparc64/sparc64/mem.c index d7a1818..66bbea9 100644 --- a/sys/sparc64/sparc64/mem.c +++ b/sys/sparc64/sparc64/mem.c @@ -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; - -static d_open_t mmopen; -static d_close_t mmclose; -static d_read_t mmrw; - -#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) -{ +#include <machine/memdev.h> - return (0); -} +struct mem_range_softc 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; - 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); |