summaryrefslogtreecommitdiffstats
path: root/sys/alpha
diff options
context:
space:
mode:
authormarkm <markm@FreeBSD.org>2004-08-01 11:40:54 +0000
committermarkm <markm@FreeBSD.org>2004-08-01 11:40:54 +0000
commita6c822020d368106b01f399673116ff8716835c7 (patch)
tree6d7271eea5bb8ced5f0b1cdd585641f60f5622e5 /sys/alpha
parentd879bd3de14d88aabd818b50f6e9341d3008ae95 (diff)
downloadFreeBSD-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/alpha')
-rw-r--r--sys/alpha/alpha/mem.c167
-rw-r--r--sys/alpha/conf/GENERIC4
-rw-r--r--sys/alpha/include/memdev.h38
3 files changed, 61 insertions, 148 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);
OpenPOWER on IntegriCloud