summaryrefslogtreecommitdiffstats
path: root/sys/sparc64
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/sparc64
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/sparc64')
-rw-r--r--sys/sparc64/conf/GENERIC4
-rw-r--r--sys/sparc64/include/memdev.h38
-rw-r--r--sys/sparc64/sparc64/mem.c100
3 files changed, 58 insertions, 84 deletions
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);
OpenPOWER on IntegriCloud