[Zrouter-src-freebsd] ZRouter.org: push to FreeBSD HEAD tree

zrouter-src-freebsd at zrouter.org zrouter-src-freebsd at zrouter.org
Tue Feb 28 11:41:34 UTC 2012


details:   http://zrouter.org/hg/FreeBSD/head//rev/71a12368a33d
changeset: 343:71a12368a33d
user:      ray at terran.dlink.ua
date:      Tue Feb 28 13:40:57 2012 +0200
description:
Add more device control methods.
Simplify implementation.

diffstat:

 head/sys/kern/subr_bus.c |  132 +++++++++++++++++++++-------------------------
 1 files changed, 60 insertions(+), 72 deletions(-)

diffs (161 lines):

diff -r ca0e917f29fb -r 71a12368a33d head/sys/kern/subr_bus.c
--- a/head/sys/kern/subr_bus.c	Tue Feb 28 13:39:44 2012 +0200
+++ b/head/sys/kern/subr_bus.c	Tue Feb 28 13:40:57 2012 +0200
@@ -414,15 +414,11 @@
 
 #ifdef DEVCTL_ATTACH_ENABLED
 
-static d_open_t		devctl2_open;
-static d_close_t	devctl2_close;
 static d_ioctl_t	devctl2_ioctl;
 
 static struct cdevsw devctl2_cdevsw = {
 	.d_version =	D_VERSION,
 	.d_flags =	D_NEEDGIANT,
-	.d_open =	devctl2_open,
-	.d_close =	devctl2_close,
 	.d_ioctl =	devctl2_ioctl,
 	.d_name =	"devctl2",
 };
@@ -440,81 +436,73 @@
 	devclass_get_device(devclass_find(_n), (_u))
 
 static	int
-devctl2_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
-{
-	return (0);
-}
-
-static	int
-devctl2_close(struct cdev *dev, int fflag, int devtype, struct thread *td)
-{
-	return (0);
-}
-
-static	int
-devctl2_attach_device(struct devctl_attach_args *arg)
-{
-	device_t bus, child;
-
-	/* TODO: check args */
-	bus = FIND_DEV(arg->bus_name, arg->bus_unit);
-	if (!bus)
-		return (ENXIO);
-
-	child = device_add_child(bus, arg->dev_name, arg->dev_unit);
-	if (!child)
-		return (ENXIO);
-
-	return (device_probe_and_attach(child));
-}
-
-static	int
-devctl2_attach_hinted_device(struct devctl_attach_args *arg)
-{
-	device_t bus;
-
-	/* TODO: check args */
-	bus = FIND_DEV(arg->bus_name, arg->bus_unit);
-	if (!bus)
-		return (ENXIO);
-
-	BUS_HINTED_CHILD(bus, arg->dev_name, arg->dev_unit);
-
-	return (bus_generic_attach(bus));
-}
-
-static	int
-devctl2_detach_device(struct devctl_attach_args *arg)
-{
-	device_t bus, child;
-
-	/* TODO: check args */
-	bus = FIND_DEV(arg->bus_name, arg->bus_unit);
-	if (!bus)
-		return (ENXIO);
-
-	child = FIND_DEV(arg->dev_name, arg->dev_unit);
-	if (!child)
-		return (ENXIO);
-
-	return (device_delete_child(bus, child));
-}
-
-static	int
 devctl2_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
     struct thread *td)
 {
-
+	struct devctl_attach_args *arg;
+	device_t bus, child;
+
+	arg = (struct devctl_attach_args *)data;
+	/* Get/check devices */
 	switch (cmd) {
+	/* Create device */
 	case DEVCTLADEV:
-		return (devctl2_attach_device(
-		    (struct devctl_attach_args *)data));
 	case DEVCTLAHDEV:
-		return (devctl2_attach_hinted_device(
-		    (struct devctl_attach_args *)data));
+		child = FIND_DEV(arg->dev_name, arg->dev_unit);
+		if (child)
+			return (EEXIST);
+
+		bus = FIND_DEV(arg->bus_name, arg->bus_unit);
+		if (!bus)
+			return (ENXIO);
+		break;
+	/* Operate on existing device */
 	case DEVCTLDDEV:
-		return (devctl2_detach_device(
-		    (struct devctl_attach_args *)data));
+	case DEVCTLSUSDEV:
+	case DEVCTLRSMDEV:
+	case DEVCTLSHTDEV:
+		child = FIND_DEV(arg->dev_name, arg->dev_unit);
+		if (!child)
+			return (ENXIO);
+
+		bus = device_get_parent(child);
+		break;
+	default:
+		return (ENOTTY);
+	}
+
+	/* Do requested call */
+	switch (cmd) {
+	/* Identify? */
+	/* Probe? */
+	/* Attach? */
+	case DEVCTLADEV:
+		child = BUS_ADD_CHILD(bus, 0, arg->dev_name, arg->dev_unit);
+		if (!child)
+			return (EIO);
+		if (device_probe_and_attach(child) != 0) {
+			/* remove device if it won't do probe/attach */
+			device_delete_child(bus, child);
+			return (ENXIO);
+		}
+		return (0);
+
+	case DEVCTLAHDEV:
+		BUS_HINTED_CHILD(bus, arg->dev_name, arg->dev_unit);
+		return (bus_generic_attach(bus));
+
+	case DEVCTLDDEV:
+		return (device_delete_child(bus, child));
+
+	case DEVCTLSUSDEV:
+		return (DEVICE_SUSPEND(child));
+
+	case DEVCTLRSMDEV:
+		return (DEVICE_RESUME(child));
+
+	case DEVCTLSHTDEV:
+		return (DEVICE_SHUTDOWN(child));
+
 	default:
 		break;
 	}


More information about the Zrouter-src-freebsd mailing list