aboutsummaryrefslogtreecommitdiff
path: root/sys/amd64
diff options
context:
space:
mode:
Diffstat (limited to 'sys/amd64')
-rw-r--r--sys/amd64/amd64/io.c77
-rw-r--r--sys/amd64/amd64/mem.c168
-rw-r--r--sys/amd64/conf/GENERIC4
-rw-r--r--sys/amd64/conf/NOTES4
-rw-r--r--sys/amd64/include/iodev.h33
-rw-r--r--sys/amd64/include/memdev.h38
6 files changed, 182 insertions, 142 deletions
diff --git a/sys/amd64/amd64/io.c b/sys/amd64/amd64/io.c
new file mode 100644
index 000000000000..1aaf2ef63282
--- /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 739ae6deb655..2d0506e80900 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 aa9848d826da..a6368d340813 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 d3610a60fc0c..b21160c79c5b 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 000000000000..2273620ccba4
--- /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 000000000000..b6d31220cb93
--- /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);