Module Name:    src
Committed By:   jruoho
Date:           Wed Jun 15 04:20:47 UTC 2011

Modified Files:
        src/sys/arch/x86/pci: amdpcib_hpet.c
        src/sys/dev/acpi: hpet_acpi.c

Log Message:
Add detach function for hpet(4) at amdpcib(4).


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/x86/pci/amdpcib_hpet.c
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/acpi/hpet_acpi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/pci/amdpcib_hpet.c
diff -u src/sys/arch/x86/pci/amdpcib_hpet.c:1.4 src/sys/arch/x86/pci/amdpcib_hpet.c:1.5
--- src/sys/arch/x86/pci/amdpcib_hpet.c:1.4	Fri Mar 21 13:25:27 2008
+++ src/sys/arch/x86/pci/amdpcib_hpet.c	Wed Jun 15 04:20:47 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: amdpcib_hpet.c,v 1.4 2008/03/21 13:25:27 xtraeme Exp $ */
+/* $NetBSD: amdpcib_hpet.c,v 1.5 2011/06/15 04:20:47 jruoho Exp $ */
 
 /*
  * Copyright (c) 2006 Nicolas Joly
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: amdpcib_hpet.c,v 1.4 2008/03/21 13:25:27 xtraeme Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amdpcib_hpet.c,v 1.5 2011/06/15 04:20:47 jruoho Exp $");
 
 #include <sys/systm.h>
 #include <sys/device.h>
@@ -45,12 +45,12 @@
 
 #include <dev/ic/hpetvar.h>
 
-
 static int	amdpcib_hpet_match(device_t , cfdata_t , void *);
 static void	amdpcib_hpet_attach(device_t, device_t, void *);
+static int	amdpcib_hpet_detach(device_t, int);
 
-CFATTACH_DECL_NEW(amdpcib_hpet, sizeof(struct hpet_softc), amdpcib_hpet_match,
-    amdpcib_hpet_attach, NULL, NULL);
+CFATTACH_DECL_NEW(amdpcib_hpet, sizeof(struct hpet_softc),
+    amdpcib_hpet_match, amdpcib_hpet_attach, amdpcib_hpet_detach, NULL);
 
 static int
 amdpcib_hpet_match(device_t parent, cfdata_t match, void *aux)
@@ -68,20 +68,43 @@
 	aprint_naive("\n");
 	aprint_normal(": HPET timer\n");
 
+	sc->sc_mapped = false;
 	conf = pci_conf_read(pa->pa_pc, pa->pa_tag, 0xa0);
+
 	if ((conf & 1) == 0) {
 		aprint_normal_dev(self, "HPET timer is disabled\n");
 		return;
 	}
 
+	sc->sc_mems = 1024;
 	sc->sc_memt = pa->pa_memt;
 
 	addr = conf & 0xfffffc00;
-	if (bus_space_map(sc->sc_memt, addr, 1024, 0,
-	    &sc->sc_memh)) {
-		aprint_error_dev(self, "failed to map mem\n");
+
+	if (bus_space_map(sc->sc_memt, addr, sc->sc_mems, 0, &sc->sc_memh)) {
+		aprint_error_dev(self, "failed to map mem space\n");
 		return;
 	}
 
+	sc->sc_mapped = true;
 	hpet_attach_subr(self);
 }
+
+static int
+amdpcib_hpet_detach(device_t self, int flags)
+{
+	struct hpet_softc *sc = device_private(self);
+	int rv;
+
+	if (sc->sc_mapped != true)
+		return 0;
+
+	rv = hpet_detach(self, flags);
+
+	if (rv != 0)
+		return rv;
+
+	bus_space_unmap(sc->sc_memt, sc->sc_memh, sc->sc_mems);
+
+	return 0;
+}

Index: src/sys/dev/acpi/hpet_acpi.c
diff -u src/sys/dev/acpi/hpet_acpi.c:1.7 src/sys/dev/acpi/hpet_acpi.c:1.8
--- src/sys/dev/acpi/hpet_acpi.c:1.7	Tue Jun 14 16:33:51 2011
+++ src/sys/dev/acpi/hpet_acpi.c	Wed Jun 15 04:20:47 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: hpet_acpi.c,v 1.7 2011/06/14 16:33:51 jruoho Exp $ */
+/* $NetBSD: hpet_acpi.c,v 1.8 2011/06/15 04:20:47 jruoho Exp $ */
 
 /*
  * Copyright (c) 2006, 2011 Nicolas Joly
@@ -28,7 +28,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hpet_acpi.c,v 1.7 2011/06/14 16:33:51 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hpet_acpi.c,v 1.8 2011/06/15 04:20:47 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -183,7 +183,11 @@
 		return 0;
 
 	rv = hpet_detach(self, flags);
+
+	if (rv != 0)
+		return rv;
+
 	bus_space_unmap(sc->sc_memt, sc->sc_memh, sc->sc_mems);
 
-	return rv;
+	return 0;
 }

Reply via email to