summaryrefslogtreecommitdiff
path: root/sys/dev/mem
diff options
context:
space:
mode:
authorJung-uk Kim <jkim@FreeBSD.org>2011-01-17 22:58:28 +0000
committerJung-uk Kim <jkim@FreeBSD.org>2011-01-17 22:58:28 +0000
commit2fea6431120dc19a04430c68b2484524074b2e43 (patch)
treef8f4914239ec2dcebc25a483fe770520ef994c63 /sys/dev/mem
parentdb3a488fb07af18a99cb7399f9d42716028098b9 (diff)
downloadsrc-test2-2fea6431120dc19a04430c68b2484524074b2e43.tar.gz
src-test2-2fea6431120dc19a04430c68b2484524074b2e43.zip
Notes
Diffstat (limited to 'sys/dev/mem')
-rw-r--r--sys/dev/mem/memdev.c4
-rw-r--r--sys/dev/mem/memutil.c45
2 files changed, 40 insertions, 9 deletions
diff --git a/sys/dev/mem/memdev.c b/sys/dev/mem/memdev.c
index 9fb33d2c4d48..28ed6ebc4e93 100644
--- a/sys/dev/mem/memdev.c
+++ b/sys/dev/mem/memdev.c
@@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$");
#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/proc.h>
@@ -80,7 +81,7 @@ mem_modevent(module_t mod __unused, int type, void *data __unused)
case MOD_LOAD:
if (bootverbose)
printf("mem: <memory>\n");
- dev_mem_md_init(); /* Machine dependant bit */
+ mem_range_init();
memdev = make_dev(&mem_cdevsw, CDEV_MINOR_MEM,
UID_ROOT, GID_KMEM, 0640, "mem");
kmemdev = make_dev(&mem_cdevsw, CDEV_MINOR_KMEM,
@@ -88,6 +89,7 @@ mem_modevent(module_t mod __unused, int type, void *data __unused)
break;
case MOD_UNLOAD:
+ mem_range_destroy();
destroy_dev(memdev);
destroy_dev(kmemdev);
break;
diff --git a/sys/dev/mem/memutil.c b/sys/dev/mem/memutil.c
index f514f50bedb6..f4ea103b39f9 100644
--- a/sys/dev/mem/memutil.c
+++ b/sys/dev/mem/memutil.c
@@ -28,35 +28,64 @@
__FBSDID("$FreeBSD$");
#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/memrange.h>
+#include <sys/rwlock.h>
#include <sys/systm.h>
+static struct rwlock mr_lock;
+
/*
* Implementation-neutral, kernel-callable functions for manipulating
* memory range attributes.
*/
+void
+mem_range_init(void)
+{
+
+ if (mem_range_softc.mr_op == NULL)
+ return;
+ rw_init(&mr_lock, "memrange");
+ mem_range_softc.mr_op->init(&mem_range_softc);
+}
+
+void
+mem_range_destroy(void)
+{
+
+ if (mem_range_softc.mr_op == NULL)
+ return;
+ rw_destroy(&mr_lock);
+}
+
int
mem_range_attr_get(struct mem_range_desc *mrd, int *arg)
{
- /* can we handle this? */
+ int nd;
+
if (mem_range_softc.mr_op == NULL)
return (EOPNOTSUPP);
-
- if (*arg == 0)
+ nd = *arg;
+ rw_rlock(&mr_lock);
+ if (nd == 0)
*arg = mem_range_softc.mr_ndesc;
else
- bcopy(mem_range_softc.mr_desc, mrd,
- (*arg) * sizeof(struct mem_range_desc));
+ bcopy(mem_range_softc.mr_desc, mrd, nd * sizeof(*mrd));
+ rw_runlock(&mr_lock);
return (0);
}
int
mem_range_attr_set(struct mem_range_desc *mrd, int *arg)
{
- /* can we handle this? */
+ int ret;
+
if (mem_range_softc.mr_op == NULL)
return (EOPNOTSUPP);
-
- return (mem_range_softc.mr_op->set(&mem_range_softc, mrd, arg));
+ rw_wlock(&mr_lock);
+ ret = mem_range_softc.mr_op->set(&mem_range_softc, mrd, arg);
+ rw_wunlock(&mr_lock);
+ return (ret);
}