Module Name: src
Committed By: jruoho
Date: Tue Jun 14 16:33:51 UTC 2011
Modified Files:
src/sys/dev/acpi: hpet_acpi.c
src/sys/dev/ic: hpetvar.h
Log Message:
Add detach function.
To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/acpi/hpet_acpi.c
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/ic/hpetvar.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/acpi/hpet_acpi.c
diff -u src/sys/dev/acpi/hpet_acpi.c:1.6 src/sys/dev/acpi/hpet_acpi.c:1.7
--- src/sys/dev/acpi/hpet_acpi.c:1.6 Tue Jun 14 13:59:23 2011
+++ src/sys/dev/acpi/hpet_acpi.c Tue Jun 14 16:33:51 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: hpet_acpi.c,v 1.6 2011/06/14 13:59:23 jruoho Exp $ */
+/* $NetBSD: hpet_acpi.c,v 1.7 2011/06/14 16:33:51 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.6 2011/06/14 13:59:23 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hpet_acpi.c,v 1.7 2011/06/14 16:33:51 jruoho Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -47,6 +47,7 @@
static void hpet_acpi_dev_attach(device_t, device_t, void *);
static int hpet_acpi_tab_match(device_t, cfdata_t, void *);
static void hpet_acpi_tab_attach(device_t, device_t, void *);
+static int hpet_acpi_detach(device_t, int);
static const char * const hpet_acpi_ids[] = {
"PNP0103",
@@ -54,10 +55,10 @@
};
CFATTACH_DECL_NEW(hpet_acpi_tab, sizeof(struct hpet_softc),
- hpet_acpi_tab_match, hpet_acpi_tab_attach, NULL, NULL);
+ hpet_acpi_tab_match, hpet_acpi_tab_attach, hpet_acpi_detach, NULL);
CFATTACH_DECL_NEW(hpet_acpi_dev, sizeof(struct hpet_softc),
- hpet_acpi_dev_match, hpet_acpi_dev_attach, NULL, NULL);
+ hpet_acpi_dev_match, hpet_acpi_dev_attach, hpet_acpi_detach, NULL);
static int
hpet_acpi_tab_match(device_t parent, cfdata_t match, void *aux)
@@ -87,22 +88,27 @@
ACPI_TABLE_HPET *hpet;
ACPI_STATUS rv;
+ sc->sc_mapped = false;
+
rv = AcpiGetTable(ACPI_SIG_HPET, 1, (ACPI_TABLE_HEADER **)&hpet);
if (ACPI_FAILURE(rv))
return;
sc->sc_memt = aa->aa_memt;
+ sc->sc_mems = HPET_MEM_WIDTH;
if (hpet->Address.Address == 0xfed0000000000000UL) /* A quirk. */
hpet->Address.Address >>= 32;
if (bus_space_map(sc->sc_memt, hpet->Address.Address,
- HPET_MEM_WIDTH, 0, &sc->sc_memh) != 0) {
+ sc->sc_mems, 0, &sc->sc_memh) != 0) {
aprint_error(": failed to map mem space\n");
return;
}
+ sc->sc_mapped = true;
+
aprint_naive("\n");
aprint_normal(": mem 0x%"PRIx64"-0x%"PRIx64"\n",
hpet->Address.Address, hpet->Address.Address + HPET_MEM_WIDTH);
@@ -130,6 +136,8 @@
struct acpi_mem *mem;
ACPI_STATUS rv;
+ sc->sc_mapped = false;
+
rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS",
&res, &acpi_resource_parse_ops_default);
@@ -149,15 +157,33 @@
}
sc->sc_memt = aa->aa_memt;
+ sc->sc_mems = mem->ar_length;
if (bus_space_map(sc->sc_memt, mem->ar_base,
- mem->ar_length, 0, &sc->sc_memh) != 0) {
+ sc->sc_mems, 0, &sc->sc_memh) != 0) {
aprint_error(": failed to map mem space\n");
goto out;
}
+ sc->sc_mapped = true;
+
hpet_attach_subr(self);
out:
acpi_resource_cleanup(&res);
}
+
+static int
+hpet_acpi_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);
+ bus_space_unmap(sc->sc_memt, sc->sc_memh, sc->sc_mems);
+
+ return rv;
+}
Index: src/sys/dev/ic/hpetvar.h
diff -u src/sys/dev/ic/hpetvar.h:1.3 src/sys/dev/ic/hpetvar.h:1.4
--- src/sys/dev/ic/hpetvar.h:1.3 Tue Aug 18 17:06:35 2009
+++ src/sys/dev/ic/hpetvar.h Tue Jun 14 16:33:51 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: hpetvar.h,v 1.3 2009/08/18 17:06:35 dyoung Exp $ */
+/* $NetBSD: hpetvar.h,v 1.4 2011/06/14 16:33:51 jruoho Exp $ */
/*
* Copyright (c) 2006 Nicolas Joly
@@ -32,11 +32,13 @@
#define _DEV_IC_HPETVAR_H_
struct hpet_softc {
- bus_space_tag_t sc_memt;
- bus_space_handle_t sc_memh;
-
- uint32_t sc_config;
- struct timecounter sc_tc;
+ bus_size_t sc_mems;
+ bus_space_tag_t sc_memt;
+ bus_space_handle_t sc_memh;
+
+ bool sc_mapped;
+ uint32_t sc_config;
+ struct timecounter sc_tc;
};
void hpet_attach_subr(device_t);