From 62dca01035bee8f4914d7ae7bd06cc125c614aa3 Mon Sep 17 00:00:00 2001 From: dyoung Date: Tue, 18 Aug 2009 17:06:35 +0000 Subject: [PATCH] Add a bus-independent detachment routine. In the attachment routine, save some device state to restore during detachment. --- sys/dev/ic/hpet.c | 21 +++++++++++++++++++-- sys/dev/ic/hpetvar.h | 4 +++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/sys/dev/ic/hpet.c b/sys/dev/ic/hpet.c index 8f7c875ad4c3..7e6f337a0956 100644 --- a/sys/dev/ic/hpet.c +++ b/sys/dev/ic/hpet.c @@ -1,4 +1,4 @@ -/* $NetBSD: hpet.c,v 1.6 2008/03/21 13:25:27 xtraeme Exp $ */ +/* $NetBSD: hpet.c,v 1.7 2009/08/18 17:06:35 dyoung Exp $ */ /* * Copyright (c) 2006 Nicolas Joly @@ -33,7 +33,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: hpet.c,v 1.6 2008/03/21 13:25:27 xtraeme Exp $"); +__KERNEL_RCSID(0, "$NetBSD: hpet.c,v 1.7 2009/08/18 17:06:35 dyoung Exp $"); #include #include @@ -50,6 +50,22 @@ __KERNEL_RCSID(0, "$NetBSD: hpet.c,v 1.6 2008/03/21 13:25:27 xtraeme Exp $"); static u_int hpet_get_timecount(struct timecounter *); static bool hpet_resume(device_t PMF_FN_PROTO); +int +hpet_detach(device_t dv, int flags) +{ + struct hpet_softc *sc = device_private(dv); + int rc; + + if ((rc = tc_detach(&sc->sc_tc)) != 0) + return rc; + + pmf_device_deregister(dv); + + bus_space_write_4(sc->sc_memt, sc->sc_memh, HPET_CONFIG, sc->sc_config); + + return 0; +} + void hpet_attach_subr(device_t dv) { @@ -71,6 +87,7 @@ hpet_attach_subr(device_t dv) /* Enable timer */ val = bus_space_read_4(sc->sc_memt, sc->sc_memh, HPET_CONFIG); + sc->sc_config = val; if ((val & HPET_CONFIG_ENABLE) == 0) { val |= HPET_CONFIG_ENABLE; bus_space_write_4(sc->sc_memt, sc->sc_memh, HPET_CONFIG, val); diff --git a/sys/dev/ic/hpetvar.h b/sys/dev/ic/hpetvar.h index aced06415ecc..98080d789791 100644 --- a/sys/dev/ic/hpetvar.h +++ b/sys/dev/ic/hpetvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: hpetvar.h,v 1.2 2008/03/21 13:25:27 xtraeme Exp $ */ +/* $NetBSD: hpetvar.h,v 1.3 2009/08/18 17:06:35 dyoung Exp $ */ /* * Copyright (c) 2006 Nicolas Joly @@ -35,9 +35,11 @@ struct hpet_softc { bus_space_tag_t sc_memt; bus_space_handle_t sc_memh; + uint32_t sc_config; struct timecounter sc_tc; }; void hpet_attach_subr(device_t); +int hpet_detach(device_t, int flags); #endif /* _DEV_IC_HPETVAR_H_ */