svn commit: r219212 - in stable/8/sys: amd64/amd64 amd64/include
arm/arm arm/include conf dev/mem i386/i386 i386/include
ia64/ia64 ia64/include mips/include mips/mips modules/mem
pc98/pc98 powerpc/...
Jung-uk Kim
jkim at FreeBSD.org
Thu Mar 3 00:24:56 UTC 2011
Author: jkim
Date: Thu Mar 3 00:24:55 2011
New Revision: 219212
URL: http://svn.freebsd.org/changeset/base/219212
Log:
MFC: r217515, r217519, r217539
Add reader/writer lock around mem_range_attr_get() and mem_range_attr_set().
Compile sys/dev/mem/memutil.c for all supported platforms and remove now
unnecessary dev_mem_md_init(). Consistently define mem_range_softc from
mem.c for all platforms. Add missing #include guards for machine/memdev.h
and sys/memrange.h. Clean up some nearby style(9) nits.
Modified:
stable/8/sys/amd64/amd64/machdep.c
stable/8/sys/amd64/amd64/mem.c
stable/8/sys/amd64/include/memdev.h
stable/8/sys/arm/arm/mem.c
stable/8/sys/arm/include/memdev.h
stable/8/sys/conf/files
stable/8/sys/conf/files.amd64
stable/8/sys/conf/files.i386
stable/8/sys/conf/files.pc98
stable/8/sys/dev/mem/memdev.c
stable/8/sys/dev/mem/memutil.c
stable/8/sys/i386/i386/machdep.c
stable/8/sys/i386/i386/mem.c
stable/8/sys/i386/include/memdev.h
stable/8/sys/ia64/ia64/mem.c
stable/8/sys/ia64/include/memdev.h
stable/8/sys/mips/include/memdev.h
stable/8/sys/mips/mips/mem.c
stable/8/sys/modules/mem/Makefile
stable/8/sys/pc98/pc98/machdep.c
stable/8/sys/powerpc/include/memdev.h
stable/8/sys/powerpc/powerpc/mem.c
stable/8/sys/sparc64/include/memdev.h
stable/8/sys/sparc64/sparc64/mem.c
stable/8/sys/sun4v/include/memdev.h
stable/8/sys/sys/memrange.h
Directory Properties:
stable/8/sys/ (props changed)
stable/8/sys/amd64/include/xen/ (props changed)
stable/8/sys/cddl/contrib/opensolaris/ (props changed)
stable/8/sys/contrib/dev/acpica/ (props changed)
stable/8/sys/contrib/pf/ (props changed)
Modified: stable/8/sys/amd64/amd64/machdep.c
==============================================================================
--- stable/8/sys/amd64/amd64/machdep.c Wed Mar 2 22:44:04 2011 (r219211)
+++ stable/8/sys/amd64/amd64/machdep.c Thu Mar 3 00:24:55 2011 (r219212)
@@ -74,7 +74,6 @@ __FBSDID("$FreeBSD$");
#include <sys/linker.h>
#include <sys/lock.h>
#include <sys/malloc.h>
-#include <sys/memrange.h>
#include <sys/msgbuf.h>
#include <sys/mutex.h>
#include <sys/pcpu.h>
@@ -193,8 +192,6 @@ struct pcpu __pcpu[MAXCPU];
struct mtx icu_lock;
-struct mem_range_softc mem_range_softc;
-
struct mtx dt_lock; /* lock for GDT and LDT */
static void
Modified: stable/8/sys/amd64/amd64/mem.c
==============================================================================
--- stable/8/sys/amd64/amd64/mem.c Wed Mar 2 22:44:04 2011 (r219211)
+++ stable/8/sys/amd64/amd64/mem.c Thu Mar 3 00:24:55 2011 (r219212)
@@ -72,6 +72,8 @@ __FBSDID("$FreeBSD$");
*/
MALLOC_DEFINE(M_MEMDESC, "memdesc", "memory range descriptors");
+struct mem_range_softc mem_range_softc;
+
/* ARGSUSED */
int
memrw(struct cdev *dev, struct uio *uio, int flags)
@@ -214,10 +216,3 @@ memioctl(struct cdev *dev __unused, u_lo
}
return (error);
}
-
-void
-dev_mem_md_init(void)
-{
- if (mem_range_softc.mr_op != NULL)
- mem_range_softc.mr_op->init(&mem_range_softc);
-}
Modified: stable/8/sys/amd64/include/memdev.h
==============================================================================
--- stable/8/sys/amd64/include/memdev.h Wed Mar 2 22:44:04 2011 (r219211)
+++ stable/8/sys/amd64/include/memdev.h Thu Mar 3 00:24:55 2011 (r219212)
@@ -26,6 +26,9 @@
* $FreeBSD$
*/
+#ifndef _MACHINE_MEMDEV_H_
+#define _MACHINE_MEMDEV_H_
+
#define CDEV_MINOR_MEM 0
#define CDEV_MINOR_KMEM 1
@@ -34,4 +37,4 @@ d_read_t memrw;
d_ioctl_t memioctl;
d_mmap_t memmmap;
-void dev_mem_md_init(void);
+#endif /* _MACHINE_MEMDEV_H_ */
Modified: stable/8/sys/arm/arm/mem.c
==============================================================================
--- stable/8/sys/arm/arm/mem.c Wed Mar 2 22:44:04 2011 (r219211)
+++ stable/8/sys/arm/arm/mem.c Thu Mar 3 00:24:55 2011 (r219212)
@@ -70,6 +70,8 @@ __FBSDID("$FreeBSD$");
*/
MALLOC_DEFINE(M_MEMDESC, "memdesc", "memory range descriptors");
+struct mem_range_softc mem_range_softc;
+
/* ARGSUSED */
int
memrw(struct cdev *dev, struct uio *uio, int flags)
@@ -163,8 +165,3 @@ memmmap(struct cdev *dev, vm_offset_t of
/* else panic! */
return (0);
}
-
-void
-dev_mem_md_init(void)
-{
-}
Modified: stable/8/sys/arm/include/memdev.h
==============================================================================
--- stable/8/sys/arm/include/memdev.h Wed Mar 2 22:44:04 2011 (r219211)
+++ stable/8/sys/arm/include/memdev.h Thu Mar 3 00:24:55 2011 (r219212)
@@ -26,6 +26,9 @@
* $FreeBSD$
*/
+#ifndef _MACHINE_MEMDEV_H_
+#define _MACHINE_MEMDEV_H_
+
#define CDEV_MINOR_MEM 0
#define CDEV_MINOR_KMEM 1
@@ -34,4 +37,4 @@ d_read_t memrw;
d_mmap_t memmmap;
#define memioctl (d_ioctl_t *)NULL
-void dev_mem_md_init(void);
+#endif /* _MACHINE_MEMDEV_H_ */
Modified: stable/8/sys/conf/files
==============================================================================
--- stable/8/sys/conf/files Wed Mar 2 22:44:04 2011 (r219211)
+++ stable/8/sys/conf/files Thu Mar 3 00:24:55 2011 (r219212)
@@ -1248,6 +1248,7 @@ dev/mcd/mcd.c optional mcd isa nowerro
dev/mcd/mcd_isa.c optional mcd isa nowerror
dev/md/md.c optional md
dev/mem/memdev.c optional mem
+dev/mem/memutil.c optional mem
dev/mfi/mfi.c optional mfi
dev/mfi/mfi_debug.c optional mfi
dev/mfi/mfi_pci.c optional mfi pci
Modified: stable/8/sys/conf/files.amd64
==============================================================================
--- stable/8/sys/conf/files.amd64 Wed Mar 2 22:44:04 2011 (r219211)
+++ stable/8/sys/conf/files.amd64 Thu Mar 3 00:24:55 2011 (r219212)
@@ -212,7 +212,6 @@ dev/hwpmc/hwpmc_x86.c optional hwpmc
dev/kbd/kbd.c optional atkbd | sc | ukbd
dev/lindev/full.c optional lindev
dev/lindev/lindev.c optional lindev
-dev/mem/memutil.c optional mem
dev/nfe/if_nfe.c optional nfe pci
dev/nve/if_nve.c optional nve pci
dev/nvram/nvram.c optional nvram isa
Modified: stable/8/sys/conf/files.i386
==============================================================================
--- stable/8/sys/conf/files.i386 Wed Mar 2 22:44:04 2011 (r219211)
+++ stable/8/sys/conf/files.i386 Thu Mar 3 00:24:55 2011 (r219212)
@@ -210,7 +210,6 @@ dev/kbd/kbd.c optional atkbd | sc | uk
dev/le/if_le_isa.c optional le isa
dev/lindev/full.c optional lindev
dev/lindev/lindev.c optional lindev
-dev/mem/memutil.c optional mem
dev/mse/mse.c optional mse
dev/mse/mse_isa.c optional mse isa
dev/nfe/if_nfe.c optional nfe pci
Modified: stable/8/sys/conf/files.pc98
==============================================================================
--- stable/8/sys/conf/files.pc98 Wed Mar 2 22:44:04 2011 (r219211)
+++ stable/8/sys/conf/files.pc98 Thu Mar 3 00:24:55 2011 (r219212)
@@ -111,7 +111,6 @@ dev/kbd/kbd.c optional pckbd | sc | uk
dev/le/if_le_cbus.c optional le isa
dev/lindev/full.c optional lindev
dev/lindev/lindev.c optional lindev
-dev/mem/memutil.c optional mem
dev/mse/mse.c optional mse
dev/mse/mse_cbus.c optional mse isa
dev/sbni/if_sbni.c optional sbni
Modified: stable/8/sys/dev/mem/memdev.c
==============================================================================
--- stable/8/sys/dev/mem/memdev.c Wed Mar 2 22:44:04 2011 (r219211)
+++ stable/8/sys/dev/mem/memdev.c Thu Mar 3 00:24:55 2011 (r219212)
@@ -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
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
break;
case MOD_UNLOAD:
+ mem_range_destroy();
destroy_dev(memdev);
destroy_dev(kmemdev);
break;
Modified: stable/8/sys/dev/mem/memutil.c
==============================================================================
--- stable/8/sys/dev/mem/memutil.c Wed Mar 2 22:44:04 2011 (r219211)
+++ stable/8/sys/dev/mem/memutil.c Thu Mar 3 00:24:55 2011 (r219212)
@@ -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);
}
Modified: stable/8/sys/i386/i386/machdep.c
==============================================================================
--- stable/8/sys/i386/i386/machdep.c Wed Mar 2 22:44:04 2011 (r219211)
+++ stable/8/sys/i386/i386/machdep.c Thu Mar 3 00:24:55 2011 (r219212)
@@ -74,7 +74,6 @@ __FBSDID("$FreeBSD$");
#include <sys/linker.h>
#include <sys/lock.h>
#include <sys/malloc.h>
-#include <sys/memrange.h>
#include <sys/msgbuf.h>
#include <sys/mutex.h>
#include <sys/pcpu.h>
@@ -239,8 +238,6 @@ struct pcpu __pcpu[MAXCPU];
struct mtx icu_lock;
-struct mem_range_softc mem_range_softc;
-
static void
cpu_startup(dummy)
void *dummy;
Modified: stable/8/sys/i386/i386/mem.c
==============================================================================
--- stable/8/sys/i386/i386/mem.c Wed Mar 2 22:44:04 2011 (r219211)
+++ stable/8/sys/i386/i386/mem.c Thu Mar 3 00:24:55 2011 (r219212)
@@ -72,10 +72,11 @@ __FBSDID("$FreeBSD$");
*/
MALLOC_DEFINE(M_MEMDESC, "memdesc", "memory range descriptors");
+struct mem_range_softc mem_range_softc;
+
static struct sx memsxlock;
SX_SYSINIT(memsxlockinit, &memsxlock, "/dev/mem lock");
-
/* ARGSUSED */
int
memrw(struct cdev *dev, struct uio *uio, int flags)
@@ -233,10 +234,3 @@ memioctl(struct cdev *dev __unused, u_lo
}
return (error);
}
-
-void
-dev_mem_md_init(void)
-{
- if (mem_range_softc.mr_op != NULL)
- mem_range_softc.mr_op->init(&mem_range_softc);
-}
Modified: stable/8/sys/i386/include/memdev.h
==============================================================================
--- stable/8/sys/i386/include/memdev.h Wed Mar 2 22:44:04 2011 (r219211)
+++ stable/8/sys/i386/include/memdev.h Thu Mar 3 00:24:55 2011 (r219212)
@@ -26,6 +26,9 @@
* $FreeBSD$
*/
+#ifndef _MACHINE_MEMDEV_H_
+#define _MACHINE_MEMDEV_H_
+
#define CDEV_MINOR_MEM 0
#define CDEV_MINOR_KMEM 1
@@ -34,4 +37,4 @@ d_read_t memrw;
d_ioctl_t memioctl;
d_mmap_t memmmap;
-void dev_mem_md_init(void);
+#endif /* _MACHINE_MEMDEV_H_ */
Modified: stable/8/sys/ia64/ia64/mem.c
==============================================================================
--- stable/8/sys/ia64/ia64/mem.c Wed Mar 2 22:44:04 2011 (r219211)
+++ stable/8/sys/ia64/ia64/mem.c Thu Mar 3 00:24:55 2011 (r219212)
@@ -167,8 +167,3 @@ memmmap(struct cdev *dev, vm_offset_t of
*paddr = IA64_PHYS_TO_RR7(offset);
return (0);
}
-
-void
-dev_mem_md_init(void)
-{
-}
Modified: stable/8/sys/ia64/include/memdev.h
==============================================================================
--- stable/8/sys/ia64/include/memdev.h Wed Mar 2 22:44:04 2011 (r219211)
+++ stable/8/sys/ia64/include/memdev.h Thu Mar 3 00:24:55 2011 (r219212)
@@ -26,6 +26,9 @@
* $FreeBSD$
*/
+#ifndef _MACHINE_MEMDEV_H_
+#define _MACHINE_MEMDEV_H_
+
#define CDEV_MINOR_MEM 0
#define CDEV_MINOR_KMEM 1
@@ -34,4 +37,4 @@ d_read_t memrw;
#define memioctl (d_ioctl_t *)NULL
d_mmap_t memmmap;
-void dev_mem_md_init(void);
+#endif /* _MACHINE_MEMDEV_H_ */
Modified: stable/8/sys/mips/include/memdev.h
==============================================================================
--- stable/8/sys/mips/include/memdev.h Wed Mar 2 22:44:04 2011 (r219211)
+++ stable/8/sys/mips/include/memdev.h Thu Mar 3 00:24:55 2011 (r219212)
@@ -27,6 +27,9 @@
* $FreeBSD$
*/
+#ifndef _MACHINE_MEMDEV_H_
+#define _MACHINE_MEMDEV_H_
+
#define CDEV_MINOR_MEM 0
#define CDEV_MINOR_KMEM 1
@@ -35,4 +38,4 @@ d_read_t memrw;
#define memioctl (d_ioctl_t *)NULL
d_mmap_t memmmap;
-void dev_mem_md_init(void);
+#endif /* _MACHINE_MEMDEV_H_ */
Modified: stable/8/sys/mips/mips/mem.c
==============================================================================
--- stable/8/sys/mips/mips/mem.c Wed Mar 2 22:44:04 2011 (r219211)
+++ stable/8/sys/mips/mips/mem.c Thu Mar 3 00:24:55 2011 (r219212)
@@ -164,8 +164,3 @@ memmmap(struct cdev *dev, vm_offset_t of
return (0);
}
-
-void
-dev_mem_md_init(void)
-{
-}
Modified: stable/8/sys/modules/mem/Makefile
==============================================================================
--- stable/8/sys/modules/mem/Makefile Wed Mar 2 22:44:04 2011 (r219211)
+++ stable/8/sys/modules/mem/Makefile Thu Mar 3 00:24:55 2011 (r219212)
@@ -5,10 +5,7 @@
.PATH: ${.CURDIR}/../../${MACHINE_ARCH}/${MACHINE_ARCH}
KMOD= mem
-SRCS= memdev.c mem.c
-.if ${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386"
-SRCS+= memutil.c
-.endif
+SRCS= memdev.c mem.c memutil.c
.if ${MACHINE_ARCH} == "i386"
SRCS+= i686_mem.c k6_mem.c
.endif
Modified: stable/8/sys/pc98/pc98/machdep.c
==============================================================================
--- stable/8/sys/pc98/pc98/machdep.c Wed Mar 2 22:44:04 2011 (r219211)
+++ stable/8/sys/pc98/pc98/machdep.c Thu Mar 3 00:24:55 2011 (r219212)
@@ -71,7 +71,6 @@ __FBSDID("$FreeBSD$");
#include <sys/linker.h>
#include <sys/lock.h>
#include <sys/malloc.h>
-#include <sys/memrange.h>
#include <sys/msgbuf.h>
#include <sys/mutex.h>
#include <sys/pcpu.h>
@@ -207,8 +206,6 @@ struct pcpu __pcpu[MAXCPU];
struct mtx icu_lock;
-struct mem_range_softc mem_range_softc;
-
static void
cpu_startup(dummy)
void *dummy;
Modified: stable/8/sys/powerpc/include/memdev.h
==============================================================================
--- stable/8/sys/powerpc/include/memdev.h Wed Mar 2 22:44:04 2011 (r219211)
+++ stable/8/sys/powerpc/include/memdev.h Thu Mar 3 00:24:55 2011 (r219212)
@@ -26,6 +26,9 @@
* $FreeBSD$
*/
+#ifndef _MACHINE_MEMDEV_H_
+#define _MACHINE_MEMDEV_H_
+
#define CDEV_MINOR_MEM 0
#define CDEV_MINOR_KMEM 1
@@ -34,4 +37,4 @@ d_read_t memrw;
#define memioctl (d_ioctl_t *)NULL
d_mmap_t memmmap;
-void dev_mem_md_init(void);
+#endif /* _MACHINE_MEMDEV_H_ */
Modified: stable/8/sys/powerpc/powerpc/mem.c
==============================================================================
--- stable/8/sys/powerpc/powerpc/mem.c Wed Mar 2 22:44:04 2011 (r219211)
+++ stable/8/sys/powerpc/powerpc/mem.c Thu Mar 3 00:24:55 2011 (r219212)
@@ -181,8 +181,3 @@ memmmap(struct cdev *dev, vm_offset_t of
return (0);
}
-
-void
-dev_mem_md_init(void)
-{
-}
Modified: stable/8/sys/sparc64/include/memdev.h
==============================================================================
--- stable/8/sys/sparc64/include/memdev.h Wed Mar 2 22:44:04 2011 (r219211)
+++ stable/8/sys/sparc64/include/memdev.h Thu Mar 3 00:24:55 2011 (r219212)
@@ -26,6 +26,9 @@
* $FreeBSD$
*/
+#ifndef _MACHINE_MEMDEV_H_
+#define _MACHINE_MEMDEV_H_
+
#define CDEV_MINOR_MEM 0
#define CDEV_MINOR_KMEM 1
@@ -34,4 +37,4 @@ d_read_t memrw;
#define memioctl (d_ioctl_t *)NULL
#define memmmap (d_mmap_t *)NULL
-void dev_mem_md_init(void);
+#endif /* _MACHINE_MEMDEV_H_ */
Modified: stable/8/sys/sparc64/sparc64/mem.c
==============================================================================
--- stable/8/sys/sparc64/sparc64/mem.c Wed Mar 2 22:44:04 2011 (r219211)
+++ stable/8/sys/sparc64/sparc64/mem.c Thu Mar 3 00:24:55 2011 (r219212)
@@ -188,9 +188,3 @@ memrw(struct cdev *dev, struct uio *uio,
kmem_free_wakeup(kernel_map, ova, PAGE_SIZE * colors);
return (error);
}
-
-void
-dev_mem_md_init(void)
-{
-
-}
Modified: stable/8/sys/sun4v/include/memdev.h
==============================================================================
--- stable/8/sys/sun4v/include/memdev.h Wed Mar 2 22:44:04 2011 (r219211)
+++ stable/8/sys/sun4v/include/memdev.h Thu Mar 3 00:24:55 2011 (r219212)
@@ -26,6 +26,9 @@
* $FreeBSD$
*/
+#ifndef _MACHINE_MEMDEV_H_
+#define _MACHINE_MEMDEV_H_
+
#define CDEV_MINOR_MEM 0
#define CDEV_MINOR_KMEM 1
@@ -34,4 +37,4 @@ d_read_t memrw;
#define memioctl (d_ioctl_t *)NULL
#define memmmap (d_mmap_t *)NULL
-void dev_mem_md_init(void);
+#endif /* _MACHINE_MEMDEV_H_ */
Modified: stable/8/sys/sys/memrange.h
==============================================================================
--- stable/8/sys/sys/memrange.h Wed Mar 2 22:44:04 2011 (r219211)
+++ stable/8/sys/sys/memrange.h Thu Mar 3 00:24:55 2011 (r219212)
@@ -4,6 +4,9 @@
* $FreeBSD$
*/
+#ifndef _SYS_MEMRANGE_H_
+#define _SYS_MEMRANGE_H_
+
/* Memory range attributes */
#define MDF_UNCACHEABLE (1<<0) /* region not cached */
#define MDF_WRITECOMBINE (1<<1) /* region supports "write combine" action */
@@ -65,7 +68,12 @@ struct mem_range_softc
extern struct mem_range_softc mem_range_softc;
-extern int mem_range_attr_get(struct mem_range_desc *mrd, int *arg);
-extern int mem_range_attr_set(struct mem_range_desc *mrd, int *arg);
+extern void mem_range_init(void);
+extern void mem_range_destroy(void);
+
+extern int mem_range_attr_get(struct mem_range_desc *mrd, int *arg);
+extern int mem_range_attr_set(struct mem_range_desc *mrd, int *arg);
+
+#endif /* _KERNEL */
-#endif
+#endif /* _SYS_MEMRANGE_H_ */
More information about the svn-src-stable-8
mailing list