Support detachment of pchb(4) and sysbeep(4). trunk
authordyoung <dyoung@NetBSD.org>
Thu, 03 Jan 2008 04:50:19 +0000
branchtrunk
changeset 165329 ddb9362594ce
parent 165328 f58018a062f5
child 165330 951d993ab1a3
Support detachment of pchb(4) and sysbeep(4).
sys/arch/x86/isa/clock.c
sys/arch/x86/pci/pchb.c
sys/arch/x86/pci/pchb_rnd.c
sys/arch/x86/pci/pchbvar.h
--- a/sys/arch/x86/isa/clock.c	Thu Jan 03 04:42:13 2008 +0000
+++ b/sys/arch/x86/isa/clock.c	Thu Jan 03 04:50:19 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: clock.c,v 1.16 2007/12/28 14:05:22 joerg Exp $	*/
+/*	$NetBSD: clock.c,v 1.17 2008/01/03 04:50:19 dyoung Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -121,7 +121,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.16 2007/12/28 14:05:22 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.17 2008/01/03 04:50:19 dyoung Exp $");
 
 /* #define CLOCKDEBUG */
 /* #define CLOCK_PARANOIA */
@@ -166,9 +166,10 @@
 
 int sysbeepmatch(struct device *, struct cfdata *, void *);
 void sysbeepattach(struct device *, struct device *, void *);
+int sysbeepdetach(device_t, int);
 
 CFATTACH_DECL(sysbeep, sizeof(struct device),
-    sysbeepmatch, sysbeepattach, NULL, NULL);
+    sysbeepmatch, sysbeepattach, sysbeepdetach, NULL);
 
 static int ppi_attached;
 static pcppi_tag_t ppicookie;
@@ -553,6 +554,14 @@
 }
 #endif
 
+int
+sysbeepdetach(device_t self, int flags)
+{
+	pmf_device_deregister(self);
+	ppi_attached = 0;
+	return 0;
+}
+
 void
 sysbeep(int pitch, int period)
 {
--- a/sys/arch/x86/pci/pchb.c	Thu Jan 03 04:42:13 2008 +0000
+++ b/sys/arch/x86/pci/pchb.c	Thu Jan 03 04:50:19 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: pchb.c,v 1.5 2007/12/09 20:27:49 jmcneill Exp $ */
+/*	$NetBSD: pchb.c,v 1.6 2008/01/03 04:50:19 dyoung Exp $ */
 
 /*-
  * Copyright (c) 1996, 1998, 2000 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pchb.c,v 1.5 2007/12/09 20:27:49 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pchb.c,v 1.6 2008/01/03 04:50:19 dyoung Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -80,12 +80,13 @@
 
 int	pchbmatch(struct device *, struct cfdata *, void *);
 void	pchbattach(struct device *, struct device *, void *);
+int	pchbdetach(device_t, int);
 
 static bool	pchb_resume(device_t);
 static bool	pchb_suspend(device_t);
 
 CFATTACH_DECL(pchb, sizeof(struct pchb_softc),
-    pchbmatch, pchbattach, NULL, NULL);
+    pchbmatch, pchbattach, pchbdetach, NULL);
 
 int
 pchbmatch(struct device *parent, struct cfdata *match, void *aux)
@@ -384,6 +385,28 @@
 	}
 }
 
+int
+pchbdetach(device_t self, int flags)
+{
+	int rc;
+#if NRND > 0
+	struct pchb_softc *sc = device_private(self);
+#endif
+
+	if ((rc = config_detach_children(self, flags)) != 0)
+		return rc;
+
+	pmf_device_deregister(self);
+
+#if NRND > 0
+	/*
+	 * Attach a random number generator, if there is one.
+	 */
+	pchb_detach_rnd(sc);
+#endif
+	return 0;
+}
+
 static bool
 pchb_suspend(device_t dv)
 {
--- a/sys/arch/x86/pci/pchb_rnd.c	Thu Jan 03 04:42:13 2008 +0000
+++ b/sys/arch/x86/pci/pchb_rnd.c	Thu Jan 03 04:50:19 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: pchb_rnd.c,v 1.6 2007/10/17 19:58:15 garbled Exp $	*/
+/*	$NetBSD: pchb_rnd.c,v 1.7 2008/01/03 04:50:19 dyoung Exp $	*/
 
 /*
  * Copyright (c) 2000 Michael Shalayeff
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pchb_rnd.c,v 1.6 2007/10/17 19:58:15 garbled Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pchb_rnd.c,v 1.7 2008/01/03 04:50:19 dyoung Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -56,6 +56,30 @@
 #define	PCHB_RNG_MIN_SAMPLES	10
 
 void
+pchb_detach_rnd(struct pchb_softc *sc)
+{
+	uint8_t reg8;
+
+	if (!sc->sc_rnd_attached)
+		return;
+
+	/* pch is polled for entropy, so no estimate is available. */
+	rnd_detach_source(&sc->sc_rnd_source);
+
+	callout_stop(&sc->sc_rnd_ch);
+	callout_destroy(&sc->sc_rnd_ch);
+
+	/* Disable the RNG. */
+	reg8 = bus_space_read_1(sc->sc_st, sc->sc_sh, I82802_RNG_HWST);
+	bus_space_write_1(sc->sc_st, sc->sc_sh, I82802_RNG_HWST,
+	    reg8 & ~I82802_RNG_HWST_ENABLE);
+
+	bus_space_unmap(sc->sc_st, sc->sc_sh, I82802_IOSIZE);
+
+	sc->sc_rnd_attached = false;
+}
+
+void
 pchb_attach_rnd(struct pchb_softc *sc, struct pci_attach_args *pa)
 {
 	int i, j, count_ff;
@@ -173,6 +197,7 @@
 	    RND_TYPE_RNG, RND_FLAG_NO_ESTIMATE);
 	sc->sc_rnd_i = sizeof(sc->sc_rnd_ax);
 	pchb_rnd_callout(sc);
+	sc->sc_rnd_attached = true;
 }
 
 static void
--- a/sys/arch/x86/pci/pchbvar.h	Thu Jan 03 04:42:13 2008 +0000
+++ b/sys/arch/x86/pci/pchbvar.h	Thu Jan 03 04:50:19 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: pchbvar.h,v 1.2 2007/12/09 20:27:49 jmcneill Exp $	*/
+/*	$NetBSD: pchbvar.h,v 1.3 2008/01/03 04:50:19 dyoung Exp $	*/
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -56,10 +56,12 @@
 
 	int sc_rnd_i;
 	uint32_t sc_rnd_ax;
+	bool sc_rnd_attached;
 
 	pcireg_t sc_pciconfext[48];
 };
 
 void	pchb_attach_rnd(struct pchb_softc *, struct pci_attach_args *);
+void	pchb_detach_rnd(struct pchb_softc *);
 
 #endif /* _I386_PCI_PCHBVAR_H_ */