[svn-commits] fjoe: freebsd/trunk r9250 - in /freebsd/trunk: drivers/dahdi/ drivers/dahdi/w...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Sep 2 04:16:11 CDT 2010


Author: fjoe
Date: Thu Sep  2 04:16:05 2010
New Revision: 9250

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=9250
Log:
- Generic modevent() for DAHDI modules
- Fix try_module_get() return value
- Add dahdi_module_usecount() and use it in device detach routines
that are executed before modevent()

Modified:
    freebsd/trunk/drivers/dahdi/wcb4xxp/base.c
    freebsd/trunk/drivers/dahdi/wct4xxp/base.c
    freebsd/trunk/drivers/dahdi/wctc4xxp/base.c
    freebsd/trunk/drivers/dahdi/wctdm24xxp/base.c
    freebsd/trunk/drivers/dahdi/wcte11xp.c
    freebsd/trunk/drivers/dahdi/wcte12xp/base.c
    freebsd/trunk/freebsd/dahdi/bsd-compat.c
    freebsd/trunk/include/dahdi/compat/bsd.h

Modified: freebsd/trunk/drivers/dahdi/wcb4xxp/base.c
URL: http://svnview.digium.com/svn/dahdi/freebsd/trunk/drivers/dahdi/wcb4xxp/base.c?view=diff&rev=9250&r1=9249&r2=9250
==============================================================================
--- freebsd/trunk/drivers/dahdi/wcb4xxp/base.c (original)
+++ freebsd/trunk/drivers/dahdi/wcb4xxp/base.c Thu Sep  2 04:16:05 2010
@@ -3146,6 +3146,9 @@
 {
 	struct b4xxp *b4 = device_get_softc(dev);
 
+	if (dahdi_module_usecount(THIS_MODULE) > 0)
+		return (EBUSY);
+
 	/* unregister */
 	b4xxp_unregister(b4);
 

Modified: freebsd/trunk/drivers/dahdi/wct4xxp/base.c
URL: http://svnview.digium.com/svn/dahdi/freebsd/trunk/drivers/dahdi/wct4xxp/base.c?view=diff&rev=9250&r1=9249&r2=9250
==============================================================================
--- freebsd/trunk/drivers/dahdi/wct4xxp/base.c (original)
+++ freebsd/trunk/drivers/dahdi/wct4xxp/base.c Thu Sep  2 04:16:05 2010
@@ -5107,6 +5107,9 @@
 {
 	struct t4 *wc = device_get_softc(dev);
 
+	if (dahdi_module_usecount(THIS_MODULE) > 0)
+		return (EBUSY);
+
 	/* unregister */
 	t4_unregister(wc);
 

Modified: freebsd/trunk/drivers/dahdi/wctc4xxp/base.c
URL: http://svnview.digium.com/svn/dahdi/freebsd/trunk/drivers/dahdi/wctc4xxp/base.c?view=diff&rev=9250&r1=9249&r2=9250
==============================================================================
--- freebsd/trunk/drivers/dahdi/wctc4xxp/base.c (original)
+++ freebsd/trunk/drivers/dahdi/wctc4xxp/base.c Thu Sep  2 04:16:05 2010
@@ -4232,6 +4232,9 @@
 static int
 wctc4xxp_device_detach(device_t dev)
 {
+	if (dahdi_module_usecount(THIS_MODULE) > 0)
+		return (EBUSY);
+
 	wctc4xxp_remove_one(dev);
 	return (0);
 }

Modified: freebsd/trunk/drivers/dahdi/wctdm24xxp/base.c
URL: http://svnview.digium.com/svn/dahdi/freebsd/trunk/drivers/dahdi/wctdm24xxp/base.c?view=diff&rev=9250&r1=9249&r2=9250
==============================================================================
--- freebsd/trunk/drivers/dahdi/wctdm24xxp/base.c (original)
+++ freebsd/trunk/drivers/dahdi/wctdm24xxp/base.c Thu Sep  2 04:16:05 2010
@@ -5470,6 +5470,9 @@
 static int
 wctdm_device_detach(device_t dev)
 {
+	if (dahdi_module_usecount(THIS_MODULE) > 0)
+		return (EBUSY);
+
 	wctdm_remove_one(dev);
 	return (0);
 }

Modified: freebsd/trunk/drivers/dahdi/wcte11xp.c
URL: http://svnview.digium.com/svn/dahdi/freebsd/trunk/drivers/dahdi/wcte11xp.c?view=diff&rev=9250&r1=9249&r2=9250
==============================================================================
--- freebsd/trunk/drivers/dahdi/wcte11xp.c (original)
+++ freebsd/trunk/drivers/dahdi/wcte11xp.c Thu Sep  2 04:16:05 2010
@@ -1824,6 +1824,9 @@
 {
 	struct t1 *wc = device_get_softc(dev);
 
+	if (dahdi_module_usecount(THIS_MODULE) > 0)
+		return (EBUSY);
+
 	/* Stop any DMA */
 	__t1xxp_stop_dma(wc);
 

Modified: freebsd/trunk/drivers/dahdi/wcte12xp/base.c
URL: http://svnview.digium.com/svn/dahdi/freebsd/trunk/drivers/dahdi/wcte12xp/base.c?view=diff&rev=9250&r1=9249&r2=9250
==============================================================================
--- freebsd/trunk/drivers/dahdi/wcte12xp/base.c (original)
+++ freebsd/trunk/drivers/dahdi/wcte12xp/base.c Thu Sep  2 04:16:05 2010
@@ -2510,6 +2510,9 @@
 static int
 te12xp_device_detach(device_t dev)
 {
+	if (dahdi_module_usecount(THIS_MODULE) > 0)
+		return (EBUSY);
+
 	te12xp_remove_one(dev);
 	return (0);
 }

Modified: freebsd/trunk/freebsd/dahdi/bsd-compat.c
URL: http://svnview.digium.com/svn/dahdi/freebsd/trunk/freebsd/dahdi/bsd-compat.c?view=diff&rev=9250&r1=9249&r2=9250
==============================================================================
--- freebsd/trunk/freebsd/dahdi/bsd-compat.c (original)
+++ freebsd/trunk/freebsd/dahdi/bsd-compat.c Thu Sep  2 04:16:05 2010
@@ -379,15 +379,45 @@
 try_module_get(struct module *m)
 {
 	atomic_inc(&m->refcount);
-	return (0);
-}
-
-void module_put(struct module *m)
+	return (1);
+}
+
+void
+module_put(struct module *m)
 {
 	atomic_dec(&m->refcount);
 }
 
-void _module_ptr_sysinit(void *arg)
+int
+dahdi_module_usecount(struct module *m)
+{
+	return atomic_read(&m->refcount);
+}
+
+int
+_dahdi_module_modevent(module_t mod, int type, void *data)
+{
+	int res = 0;
+	struct module *m = (struct module *) data;
+
+	switch (type) {
+	case MOD_LOAD:
+		if (m->init)
+			res = m->init();
+		return (-res);
+	case MOD_UNLOAD:
+		if (dahdi_module_usecount(m) > 0)
+			return (EBUSY);
+		if (m->exit)
+			m->exit();
+		return (0);
+	default:
+		return (EOPNOTSUPP);
+	}
+}
+
+void
+_dahdi_module_ptr_sysinit(void *arg)
 {
 	struct module_ptr_args *args = (struct module_ptr_args *) arg;
 	*args->pfield = args->value;

Modified: freebsd/trunk/include/dahdi/compat/bsd.h
URL: http://svnview.digium.com/svn/dahdi/freebsd/trunk/include/dahdi/compat/bsd.h?view=diff&rev=9250&r1=9249&r2=9250
==============================================================================
--- freebsd/trunk/include/dahdi/compat/bsd.h (original)
+++ freebsd/trunk/include/dahdi/compat/bsd.h Thu Sep  2 04:16:05 2010
@@ -425,49 +425,30 @@
 
 int try_module_get(struct module *);
 void module_put(struct module *);
+int dahdi_module_usecount(struct module *);
 
 extern struct module _this_module;
 
 #define THIS_MODULE (&_this_module)
-
-#define _DAHDI_MODULE_EVH(name)	__CONCAT(name, _modevent)
-#define _DAHDI_MODULE(name)						\
-	static int							\
-	_DAHDI_MODULE_EVH(name)(module_t mod, int type, void *data)	\
-	{								\
-		int res = 0;						\
-									\
-		switch (type) {						\
-		case MOD_LOAD:						\
-			if (THIS_MODULE->init)				\
-				res = THIS_MODULE->init();		\
-			return (-res);					\
-		case MOD_UNLOAD:					\
-			if (atomic_read(&(THIS_MODULE->refcount)))	\
-				return (EBUSY);				\
-			if (THIS_MODULE->exit)				\
-				THIS_MODULE->exit();			\
-			return (0);					\
-		default:						\
-			return (EOPNOTSUPP);				\
-		}							\
-	}								\
-	struct module _this_module = { #name }
-
-#define DAHDI_DEV_MODULE(name)						\
-	_DAHDI_MODULE(name);						\
-	DEV_MODULE(name, _DAHDI_MODULE_EVH(name), 0)
-
-#define DAHDI_DRIVER_MODULE(name, busname, driver, devclass)		\
-	_DAHDI_MODULE(name);						\
-	DRIVER_MODULE(name, busname, driver, devclass, _DAHDI_MODULE_EVH(name), 0);
 
 struct module_ptr_args {
 	const void **pfield;
 	void *value;
 };
 
-void _module_ptr_sysinit(void *arg);
+int _dahdi_module_modevent(struct module *mod, int type, void *data);
+void _dahdi_module_ptr_sysinit(void *arg);
+
+#define _DAHDI_MODULE(name)						\
+	struct module _this_module = { #name }
+
+#define DAHDI_DEV_MODULE(name)						\
+	_DAHDI_MODULE(name);						\
+	DEV_MODULE(name, _dahdi_module_modevent, THIS_MODULE)
+
+#define DAHDI_DRIVER_MODULE(name, busname, driver, devclass)		\
+	_DAHDI_MODULE(name);						\
+	DRIVER_MODULE(name, busname, driver, devclass, _dahdi_module_modevent, THIS_MODULE);
 
 #define _module_ptr_args	__CONCAT(_module_ptr_args_, __LINE__)
 #define _module_ptr_init(field, val)					\
@@ -476,7 +457,7 @@
 	};								\
 	SYSINIT(__CONCAT(_module_ptr_args, _init),			\
 		SI_SUB_KLD, SI_ORDER_FIRST,				\
-		_module_ptr_sysinit, &_module_ptr_args)
+		_dahdi_module_ptr_sysinit, &_module_ptr_args)
 
 #define module_init(f)		_module_ptr_init(init, f)
 #define module_exit(f)		_module_ptr_init(exit, f)




More information about the svn-commits mailing list