From 832a4e0700eb0aaa6224480c77007423742a2654 Mon Sep 17 00:00:00 2001 From: Paul Irofti Date: Sun, 22 Nov 2009 18:40:14 +0000 Subject: Add basic suspend/resume autoconf functionality. Okay deraadt@, kettenis@, mlarkin@. --- sys/kern/subr_autoconf.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'sys/kern') diff --git a/sys/kern/subr_autoconf.c b/sys/kern/subr_autoconf.c index df7c6a5ba9d..3ef78645ab4 100644 --- a/sys/kern/subr_autoconf.c +++ b/sys/kern/subr_autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_autoconf.c,v 1.57 2009/10/13 19:33:19 pirofti Exp $ */ +/* $OpenBSD: subr_autoconf.c,v 1.58 2009/11/22 18:40:13 pirofti Exp $ */ /* $NetBSD: subr_autoconf.c,v 1.21 1996/04/04 06:06:18 cgd Exp $ */ /* @@ -641,6 +641,42 @@ config_deactivate(struct device *dev) return (rv); } +int +config_suspend(struct device *dev) +{ + struct cfattach *ca = dev->dv_cfdata->cf_attach; + int rv = 0, oflags = dev->dv_flags; + + if (ca->ca_activate == NULL) + return (EOPNOTSUPP); + + if ((dev->dv_flags & DVF_SUSPEND) == 0) { + dev->dv_flags |= DVF_SUSPEND; + rv = (*ca->ca_activate)(dev, DVACT_SUSPEND); + if (rv) + dev->dv_flags = oflags; + } + return (rv); +} + +int +config_resume(struct device *dev) +{ + struct cfattach *ca = dev->dv_cfdata->cf_attach; + int rv = 0, oflags = dev->dv_flags; + + if (ca->ca_activate == NULL) + return (EOPNOTSUPP); + + if (dev->dv_flags & DVF_SUSPEND) { + dev->dv_flags &= ~DVF_SUSPEND; + rv = (*ca->ca_activate)(dev, DVACT_RESUME); + if (rv) + dev->dv_flags = oflags; + } + return (rv); +} + /* * Defer the configuration of the specified device until all * of its parent's devices have been attached. @@ -768,6 +804,12 @@ config_activate_children(struct device *parent, int act) case DVACT_DEACTIVATE: rv = config_deactivate(dev); break; + case DVACT_SUSPEND: + rv = config_suspend(dev); + break; + case DVACT_RESUME: + rv = config_resume(dev); + break; default: #ifdef DIAGNOSTIC printf ("config_activate_children: shouldn't get here"); -- cgit v1.2.3