aboutsummaryrefslogtreecommitdiff
path: root/sys/sparc64/sparc64
diff options
context:
space:
mode:
Diffstat (limited to 'sys/sparc64/sparc64')
-rw-r--r--sys/sparc64/sparc64/mem.c100
1 files changed, 17 insertions, 83 deletions
diff --git a/sys/sparc64/sparc64/mem.c b/sys/sparc64/sparc64/mem.c
index d7a18185341f..66bbea9fc50e 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);