aboutsummaryrefslogtreecommitdiff
path: root/sys/amd64/amd64/mem.c
diff options
context:
space:
mode:
authorMark Murray <markm@FreeBSD.org>2004-08-01 11:40:54 +0000
committerMark Murray <markm@FreeBSD.org>2004-08-01 11:40:54 +0000
commit8ab2f5ecc596131f6ca790d6ae35540c06ed7985 (patch)
tree6d7271eea5bb8ced5f0b1cdd585641f60f5622e5 /sys/amd64/amd64/mem.c
parentdcd6f4bd48d807bb13902081e85eb92149c5be73 (diff)
downloadsrc-8ab2f5ecc596131f6ca790d6ae35540c06ed7985.tar.gz
src-8ab2f5ecc596131f6ca790d6ae35540c06ed7985.zip
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.
Notes
Notes: svn path=/head/; revision=132956
Diffstat (limited to 'sys/amd64/amd64/mem.c')
-rw-r--r--sys/amd64/amd64/mem.c168
1 files changed, 27 insertions, 141 deletions
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);