Home | History | Annotate | Line # | Download | only in pci
tco.c revision 1.2.16.2
      1  1.2.16.2  jdolecek /*	$NetBSD: tco.c,v 1.2.16.2 2017/12/03 11:36:50 jdolecek Exp $	*/
      2  1.2.16.2  jdolecek 
      3  1.2.16.2  jdolecek /*-
      4  1.2.16.2  jdolecek  * Copyright (c) 2015 The NetBSD Foundation, Inc.
      5  1.2.16.2  jdolecek  * All rights reserved.
      6  1.2.16.2  jdolecek  *
      7  1.2.16.2  jdolecek  * This code is derived from software contributed to The NetBSD Foundation
      8  1.2.16.2  jdolecek  * by Minoura Makoto and Matthew R. Green.
      9  1.2.16.2  jdolecek  *
     10  1.2.16.2  jdolecek  * Redistribution and use in source and binary forms, with or without
     11  1.2.16.2  jdolecek  * modification, are permitted provided that the following conditions
     12  1.2.16.2  jdolecek  * are met:
     13  1.2.16.2  jdolecek  * 1. Redistributions of source code must retain the above copyright
     14  1.2.16.2  jdolecek  *    notice, this list of conditions and the following disclaimer.
     15  1.2.16.2  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.2.16.2  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     17  1.2.16.2  jdolecek  *    documentation and/or other materials provided with the distribution.
     18  1.2.16.2  jdolecek  *
     19  1.2.16.2  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.2.16.2  jdolecek  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.2.16.2  jdolecek  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.2.16.2  jdolecek  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.2.16.2  jdolecek  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.2.16.2  jdolecek  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.2.16.2  jdolecek  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.2.16.2  jdolecek  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.2.16.2  jdolecek  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.2.16.2  jdolecek  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.2.16.2  jdolecek  * POSSIBILITY OF SUCH DAMAGE.
     30  1.2.16.2  jdolecek  */
     31  1.2.16.2  jdolecek 
     32  1.2.16.2  jdolecek /*
     33  1.2.16.2  jdolecek  * Intel I/O Controller Hub (ICHn) watchdog timer
     34  1.2.16.2  jdolecek  */
     35  1.2.16.2  jdolecek 
     36  1.2.16.2  jdolecek #include <sys/cdefs.h>
     37  1.2.16.2  jdolecek __KERNEL_RCSID(0, "$NetBSD: tco.c,v 1.2.16.2 2017/12/03 11:36:50 jdolecek Exp $");
     38  1.2.16.2  jdolecek 
     39  1.2.16.2  jdolecek #include <sys/types.h>
     40  1.2.16.2  jdolecek #include <sys/param.h>
     41  1.2.16.2  jdolecek #include <sys/systm.h>
     42  1.2.16.2  jdolecek #include <sys/device.h>
     43  1.2.16.2  jdolecek #include <sys/timetc.h>
     44  1.2.16.2  jdolecek #include <sys/module.h>
     45  1.2.16.2  jdolecek 
     46  1.2.16.2  jdolecek #include <dev/pci/pcivar.h>
     47  1.2.16.2  jdolecek #include <dev/pci/pcireg.h>
     48  1.2.16.2  jdolecek #include <dev/ic/i82801lpcreg.h>
     49  1.2.16.2  jdolecek 
     50  1.2.16.2  jdolecek #include <dev/sysmon/sysmonvar.h>
     51  1.2.16.2  jdolecek 
     52  1.2.16.2  jdolecek #include <arch/x86/pci/tco.h>
     53  1.2.16.2  jdolecek 
     54  1.2.16.2  jdolecek #include "pcibvar.h"
     55  1.2.16.2  jdolecek 
     56  1.2.16.2  jdolecek struct tco_softc{
     57  1.2.16.2  jdolecek 	struct sysmon_wdog	sc_smw;
     58  1.2.16.2  jdolecek 	bus_space_tag_t		sc_iot;
     59  1.2.16.2  jdolecek 	bus_space_handle_t	sc_ioh;
     60  1.2.16.2  jdolecek 	bus_space_tag_t		sc_rcbat;
     61  1.2.16.2  jdolecek 	bus_space_handle_t	sc_rcbah;
     62  1.2.16.2  jdolecek 	struct pcib_softc *	sc_pcib;
     63  1.2.16.2  jdolecek 	int			sc_armed;
     64  1.2.16.2  jdolecek 	unsigned int		sc_min_t;
     65  1.2.16.2  jdolecek 	unsigned int		sc_max_t;
     66  1.2.16.2  jdolecek 	int			sc_has_rcba;
     67  1.2.16.2  jdolecek };
     68  1.2.16.2  jdolecek 
     69  1.2.16.2  jdolecek static int tco_match(device_t, cfdata_t, void *);
     70  1.2.16.2  jdolecek static void tco_attach(device_t, device_t, void *);
     71  1.2.16.2  jdolecek static int tco_detach(device_t, int);
     72  1.2.16.2  jdolecek 
     73  1.2.16.2  jdolecek static bool tco_suspend(device_t, const pmf_qual_t *);
     74  1.2.16.2  jdolecek 
     75  1.2.16.2  jdolecek static int tcotimer_setmode(struct sysmon_wdog *);
     76  1.2.16.2  jdolecek static int tcotimer_tickle(struct sysmon_wdog *);
     77  1.2.16.2  jdolecek static void tcotimer_stop(struct tco_softc *);
     78  1.2.16.2  jdolecek static void tcotimer_start(struct tco_softc *);
     79  1.2.16.2  jdolecek static void tcotimer_status_reset(struct tco_softc *);
     80  1.2.16.2  jdolecek static int  tcotimer_disable_noreboot(device_t);
     81  1.2.16.2  jdolecek 
     82  1.2.16.2  jdolecek CFATTACH_DECL3_NEW(tco, sizeof(struct tco_softc),
     83  1.2.16.2  jdolecek     tco_match, tco_attach, tco_detach, NULL, NULL, NULL, 0);
     84  1.2.16.2  jdolecek 
     85  1.2.16.2  jdolecek /*
     86  1.2.16.2  jdolecek  * Autoconf callbacks.
     87  1.2.16.2  jdolecek  */
     88  1.2.16.2  jdolecek static int
     89  1.2.16.2  jdolecek tco_match(device_t parent, cfdata_t match, void *aux)
     90  1.2.16.2  jdolecek {
     91  1.2.16.2  jdolecek 	struct lpcib_tco_attach_args *ta = aux;
     92  1.2.16.2  jdolecek 
     93  1.2.16.2  jdolecek 	if (ta->ta_iot != 0)
     94  1.2.16.2  jdolecek 		return 1;
     95  1.2.16.2  jdolecek 
     96  1.2.16.2  jdolecek 	return 0;
     97  1.2.16.2  jdolecek }
     98  1.2.16.2  jdolecek 
     99  1.2.16.2  jdolecek static void
    100  1.2.16.2  jdolecek tco_attach(device_t parent, device_t self, void *aux)
    101  1.2.16.2  jdolecek {
    102  1.2.16.2  jdolecek 	struct tco_softc *sc = device_private(self);
    103  1.2.16.2  jdolecek 	struct lpcib_tco_attach_args *ta = aux;
    104  1.2.16.2  jdolecek 	uint32_t ioreg;
    105  1.2.16.2  jdolecek 
    106  1.2.16.2  jdolecek 	/* Retrieve bus info shared with parent/siblings */
    107  1.2.16.2  jdolecek 
    108  1.2.16.2  jdolecek 	sc->sc_iot = ta->ta_iot;
    109  1.2.16.2  jdolecek 	sc->sc_ioh = ta->ta_ioh;
    110  1.2.16.2  jdolecek 	sc->sc_rcbat = ta->ta_rcbat;
    111  1.2.16.2  jdolecek 	sc->sc_rcbah = ta->ta_rcbah;
    112  1.2.16.2  jdolecek 	sc->sc_pcib = ta->ta_pcib;
    113  1.2.16.2  jdolecek 	sc->sc_has_rcba = ta->ta_has_rcba;
    114  1.2.16.2  jdolecek 
    115  1.2.16.2  jdolecek 	aprint_normal(": TCO (watchdog) timer configured.\n");
    116  1.2.16.2  jdolecek 	aprint_naive("\n");
    117  1.2.16.2  jdolecek 
    118  1.2.16.2  jdolecek 	/* Explicitly stop the TCO timer. */
    119  1.2.16.2  jdolecek 	tcotimer_stop(sc);
    120  1.2.16.2  jdolecek 
    121  1.2.16.2  jdolecek 	/*
    122  1.2.16.2  jdolecek 	 * Enable TCO timeout SMI only if the hardware reset does not
    123  1.2.16.2  jdolecek 	 * work. We don't know what the SMBIOS does.
    124  1.2.16.2  jdolecek 	 */
    125  1.2.16.2  jdolecek 	ioreg = bus_space_read_4(sc->sc_iot, sc->sc_ioh, LPCIB_SMI_EN);
    126  1.2.16.2  jdolecek 	ioreg &= ~LPCIB_SMI_EN_TCO_EN;
    127  1.2.16.2  jdolecek 
    128  1.2.16.2  jdolecek 	/*
    129  1.2.16.2  jdolecek 	 * Clear the No Reboot (NR) bit. If this fails, enabling the TCO_EN bit
    130  1.2.16.2  jdolecek 	 * in the SMI_EN register is the last chance.
    131  1.2.16.2  jdolecek 	 */
    132  1.2.16.2  jdolecek 	if (tcotimer_disable_noreboot(self)) {
    133  1.2.16.2  jdolecek 		ioreg |= LPCIB_SMI_EN_TCO_EN;
    134  1.2.16.2  jdolecek 	}
    135  1.2.16.2  jdolecek 	if ((ioreg & LPCIB_SMI_EN_GBL_SMI_EN) != 0) {
    136  1.2.16.2  jdolecek 		bus_space_write_4(sc->sc_iot, sc->sc_ioh, LPCIB_SMI_EN, ioreg);
    137  1.2.16.2  jdolecek 	}
    138  1.2.16.2  jdolecek 
    139  1.2.16.2  jdolecek 	/* Reset the watchdog status registers. */
    140  1.2.16.2  jdolecek 	tcotimer_status_reset(sc);
    141  1.2.16.2  jdolecek 
    142  1.2.16.2  jdolecek 	/*
    143  1.2.16.2  jdolecek 	 * Register the driver with the sysmon watchdog framework.
    144  1.2.16.2  jdolecek 	 */
    145  1.2.16.2  jdolecek 	sc->sc_smw.smw_name = device_xname(self);
    146  1.2.16.2  jdolecek 	sc->sc_smw.smw_cookie = sc;
    147  1.2.16.2  jdolecek 	sc->sc_smw.smw_setmode = tcotimer_setmode;
    148  1.2.16.2  jdolecek 	sc->sc_smw.smw_tickle = tcotimer_tickle;
    149  1.2.16.2  jdolecek 
    150  1.2.16.2  jdolecek 	/*
    151  1.2.16.2  jdolecek 	 * ICH6 or newer are limited to 2ticks min and 613ticks max.
    152  1.2.16.2  jdolecek 	 *                              1sec           367secs
    153  1.2.16.2  jdolecek 	 *
    154  1.2.16.2  jdolecek 	 * ICH5 or older are limited to 4ticks min and 39ticks max.
    155  1.2.16.2  jdolecek 	 *                              2secs          23secs
    156  1.2.16.2  jdolecek 	 */
    157  1.2.16.2  jdolecek 	if (sc->sc_has_rcba) {
    158  1.2.16.2  jdolecek 		sc->sc_max_t = LPCIB_TCOTIMER2_MAX_TICK;
    159  1.2.16.2  jdolecek 		sc->sc_min_t = LPCIB_TCOTIMER2_MIN_TICK;
    160  1.2.16.2  jdolecek 	} else {
    161  1.2.16.2  jdolecek 		sc->sc_max_t = LPCIB_TCOTIMER_MAX_TICK;
    162  1.2.16.2  jdolecek 		sc->sc_min_t = LPCIB_TCOTIMER_MIN_TICK;
    163  1.2.16.2  jdolecek 	}
    164  1.2.16.2  jdolecek 	sc->sc_smw.smw_period = lpcib_tcotimer_tick_to_second(sc->sc_max_t);
    165  1.2.16.2  jdolecek 
    166  1.2.16.2  jdolecek 	aprint_verbose_dev(self, "Min/Max interval %u/%u seconds\n",
    167  1.2.16.2  jdolecek 		lpcib_tcotimer_tick_to_second(sc->sc_min_t),
    168  1.2.16.2  jdolecek 		lpcib_tcotimer_tick_to_second(sc->sc_max_t));
    169  1.2.16.2  jdolecek 
    170  1.2.16.2  jdolecek 	if (sysmon_wdog_register(&sc->sc_smw))
    171  1.2.16.2  jdolecek 		aprint_error_dev(self, "unable to register TCO timer"
    172  1.2.16.2  jdolecek 		       "as a sysmon watchdog device.\n");
    173  1.2.16.2  jdolecek 
    174  1.2.16.2  jdolecek 	if (!pmf_device_register(self, tco_suspend, NULL))
    175  1.2.16.2  jdolecek 		aprint_error_dev(self, "unable to register with pmf\n");
    176  1.2.16.2  jdolecek }
    177  1.2.16.2  jdolecek 
    178  1.2.16.2  jdolecek static int
    179  1.2.16.2  jdolecek tco_detach(device_t self, int flags)
    180  1.2.16.2  jdolecek {
    181  1.2.16.2  jdolecek 	struct tco_softc *sc = device_private(self);
    182  1.2.16.2  jdolecek 	int rc;
    183  1.2.16.2  jdolecek 
    184  1.2.16.2  jdolecek 	if ((rc = sysmon_wdog_unregister(&sc->sc_smw)) != 0) {
    185  1.2.16.2  jdolecek 		if (rc == ERESTART)
    186  1.2.16.2  jdolecek 			rc = EINTR;
    187  1.2.16.2  jdolecek 		return rc;
    188  1.2.16.2  jdolecek 	}
    189  1.2.16.2  jdolecek 
    190  1.2.16.2  jdolecek 	/* Explicitly stop the TCO timer. */
    191  1.2.16.2  jdolecek 	tcotimer_stop(sc);
    192  1.2.16.2  jdolecek 
    193  1.2.16.2  jdolecek 	/* XXX Set No Reboot? */
    194  1.2.16.2  jdolecek 
    195  1.2.16.2  jdolecek 	pmf_device_deregister(self);
    196  1.2.16.2  jdolecek 
    197  1.2.16.2  jdolecek 	return 0;
    198  1.2.16.2  jdolecek }
    199  1.2.16.2  jdolecek 
    200  1.2.16.2  jdolecek static bool
    201  1.2.16.2  jdolecek tco_suspend(device_t self, const pmf_qual_t *quals)
    202  1.2.16.2  jdolecek {
    203  1.2.16.2  jdolecek 	struct tco_softc *sc = device_private(self);
    204  1.2.16.2  jdolecek 
    205  1.2.16.2  jdolecek 	/* Allow suspend only if watchdog is not armed */
    206  1.2.16.2  jdolecek 
    207  1.2.16.2  jdolecek 	return ((sc->sc_smw.smw_mode & WDOG_MODE_MASK) == WDOG_MODE_DISARMED);
    208  1.2.16.2  jdolecek }
    209  1.2.16.2  jdolecek 
    210  1.2.16.2  jdolecek /*
    211  1.2.16.2  jdolecek  * Sysmon watchdog callbacks.
    212  1.2.16.2  jdolecek  */
    213  1.2.16.2  jdolecek static int
    214  1.2.16.2  jdolecek tcotimer_setmode(struct sysmon_wdog *smw)
    215  1.2.16.2  jdolecek {
    216  1.2.16.2  jdolecek 	struct tco_softc *sc = smw->smw_cookie;
    217  1.2.16.2  jdolecek 	unsigned int period;
    218  1.2.16.2  jdolecek 	uint16_t ich6period = 0;
    219  1.2.16.2  jdolecek 	uint8_t ich5period = 0;
    220  1.2.16.2  jdolecek 
    221  1.2.16.2  jdolecek 	if ((smw->smw_mode & WDOG_MODE_MASK) == WDOG_MODE_DISARMED) {
    222  1.2.16.2  jdolecek 		/* Stop the TCO timer. */
    223  1.2.16.2  jdolecek 		tcotimer_stop(sc);
    224  1.2.16.2  jdolecek 	} else {
    225  1.2.16.2  jdolecek 		period = lpcib_tcotimer_second_to_tick(smw->smw_period);
    226  1.2.16.2  jdolecek 		if (period < sc->sc_min_t || period > sc->sc_max_t)
    227  1.2.16.2  jdolecek 			return EINVAL;
    228  1.2.16.2  jdolecek 
    229  1.2.16.2  jdolecek 		/* Stop the TCO timer, */
    230  1.2.16.2  jdolecek 		tcotimer_stop(sc);
    231  1.2.16.2  jdolecek 
    232  1.2.16.2  jdolecek 		/* set the timeout, */
    233  1.2.16.2  jdolecek 		if (sc->sc_has_rcba) {
    234  1.2.16.2  jdolecek 			/* ICH6 or newer */
    235  1.2.16.2  jdolecek 			ich6period = bus_space_read_2(sc->sc_iot, sc->sc_ioh,
    236  1.2.16.2  jdolecek 						      LPCIB_TCO_TMR2);
    237  1.2.16.2  jdolecek 			ich6period &= 0xfc00;
    238  1.2.16.2  jdolecek 			bus_space_write_2(sc->sc_iot, sc->sc_ioh,
    239  1.2.16.2  jdolecek 					  LPCIB_TCO_TMR2, ich6period | period);
    240  1.2.16.2  jdolecek 		} else {
    241  1.2.16.2  jdolecek 			/* ICH5 or older */
    242  1.2.16.2  jdolecek 			ich5period = bus_space_read_1(sc->sc_iot, sc->sc_ioh,
    243  1.2.16.2  jdolecek 						   LPCIB_TCO_TMR);
    244  1.2.16.2  jdolecek 			ich5period &= 0xc0;
    245  1.2.16.2  jdolecek 			bus_space_write_1(sc->sc_iot, sc->sc_ioh,
    246  1.2.16.2  jdolecek 					  LPCIB_TCO_TMR, ich5period | period);
    247  1.2.16.2  jdolecek 		}
    248  1.2.16.2  jdolecek 
    249  1.2.16.2  jdolecek 		/* and start/reload the timer. */
    250  1.2.16.2  jdolecek 		tcotimer_start(sc);
    251  1.2.16.2  jdolecek 		tcotimer_tickle(smw);
    252  1.2.16.2  jdolecek 	}
    253  1.2.16.2  jdolecek 
    254  1.2.16.2  jdolecek 	return 0;
    255  1.2.16.2  jdolecek }
    256  1.2.16.2  jdolecek 
    257  1.2.16.2  jdolecek static int
    258  1.2.16.2  jdolecek tcotimer_tickle(struct sysmon_wdog *smw)
    259  1.2.16.2  jdolecek {
    260  1.2.16.2  jdolecek 	struct tco_softc *sc = smw->smw_cookie;
    261  1.2.16.2  jdolecek 
    262  1.2.16.2  jdolecek 	/* any value is allowed */
    263  1.2.16.2  jdolecek 	if (sc->sc_has_rcba)
    264  1.2.16.2  jdolecek 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO_RLD, 1);
    265  1.2.16.2  jdolecek 	else
    266  1.2.16.2  jdolecek 		bus_space_write_1(sc->sc_iot, sc->sc_ioh, LPCIB_TCO_RLD, 1);
    267  1.2.16.2  jdolecek 
    268  1.2.16.2  jdolecek 	return 0;
    269  1.2.16.2  jdolecek }
    270  1.2.16.2  jdolecek 
    271  1.2.16.2  jdolecek static void
    272  1.2.16.2  jdolecek tcotimer_stop(struct tco_softc *sc)
    273  1.2.16.2  jdolecek {
    274  1.2.16.2  jdolecek 	uint16_t ioreg;
    275  1.2.16.2  jdolecek 
    276  1.2.16.2  jdolecek 	ioreg = bus_space_read_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_CNT);
    277  1.2.16.2  jdolecek 	ioreg |= LPCIB_TCO1_CNT_TCO_TMR_HLT;
    278  1.2.16.2  jdolecek 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_CNT, ioreg);
    279  1.2.16.2  jdolecek }
    280  1.2.16.2  jdolecek 
    281  1.2.16.2  jdolecek static void
    282  1.2.16.2  jdolecek tcotimer_start(struct tco_softc *sc)
    283  1.2.16.2  jdolecek {
    284  1.2.16.2  jdolecek 	uint16_t ioreg;
    285  1.2.16.2  jdolecek 
    286  1.2.16.2  jdolecek 	ioreg = bus_space_read_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_CNT);
    287  1.2.16.2  jdolecek 	ioreg &= ~LPCIB_TCO1_CNT_TCO_TMR_HLT;
    288  1.2.16.2  jdolecek 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_CNT, ioreg);
    289  1.2.16.2  jdolecek }
    290  1.2.16.2  jdolecek 
    291  1.2.16.2  jdolecek static void
    292  1.2.16.2  jdolecek tcotimer_status_reset(struct tco_softc *sc)
    293  1.2.16.2  jdolecek {
    294  1.2.16.2  jdolecek 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_STS,
    295  1.2.16.2  jdolecek 			  LPCIB_TCO1_STS_TIMEOUT);
    296  1.2.16.2  jdolecek 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO2_STS,
    297  1.2.16.2  jdolecek 			  LPCIB_TCO2_STS_BOOT_STS);
    298  1.2.16.2  jdolecek 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO2_STS,
    299  1.2.16.2  jdolecek 			  LPCIB_TCO2_STS_SECONDS_TO_STS);
    300  1.2.16.2  jdolecek }
    301  1.2.16.2  jdolecek 
    302  1.2.16.2  jdolecek /*
    303  1.2.16.2  jdolecek  * Clear the No Reboot (NR) bit, this enables reboots when the timer
    304  1.2.16.2  jdolecek  * reaches the timeout for the second time.
    305  1.2.16.2  jdolecek  */
    306  1.2.16.2  jdolecek static int
    307  1.2.16.2  jdolecek tcotimer_disable_noreboot(device_t self)
    308  1.2.16.2  jdolecek {
    309  1.2.16.2  jdolecek 	struct tco_softc *sc = device_private(self);
    310  1.2.16.2  jdolecek 
    311  1.2.16.2  jdolecek 	if (sc->sc_has_rcba) {
    312  1.2.16.2  jdolecek 		uint32_t status;
    313  1.2.16.2  jdolecek 
    314  1.2.16.2  jdolecek 		status = bus_space_read_4(sc->sc_rcbat, sc->sc_rcbah,
    315  1.2.16.2  jdolecek 		    LPCIB_GCS_OFFSET);
    316  1.2.16.2  jdolecek 		status &= ~LPCIB_GCS_NO_REBOOT;
    317  1.2.16.2  jdolecek 		bus_space_write_4(sc->sc_rcbat, sc->sc_rcbah,
    318  1.2.16.2  jdolecek 		    LPCIB_GCS_OFFSET, status);
    319  1.2.16.2  jdolecek 		status = bus_space_read_4(sc->sc_rcbat, sc->sc_rcbah,
    320  1.2.16.2  jdolecek 		    LPCIB_GCS_OFFSET);
    321  1.2.16.2  jdolecek 		if (status & LPCIB_GCS_NO_REBOOT)
    322  1.2.16.2  jdolecek 			goto error;
    323  1.2.16.2  jdolecek 	} else {
    324  1.2.16.2  jdolecek 		pcireg_t pcireg;
    325  1.2.16.2  jdolecek 
    326  1.2.16.2  jdolecek 		pcireg = pci_conf_read(sc->sc_pcib->sc_pc, sc->sc_pcib->sc_tag,
    327  1.2.16.2  jdolecek 				       LPCIB_PCI_GEN_STA);
    328  1.2.16.2  jdolecek 		if (pcireg & LPCIB_PCI_GEN_STA_NO_REBOOT) {
    329  1.2.16.2  jdolecek 			/* TCO timeout reset is disabled; try to enable it */
    330  1.2.16.2  jdolecek 			pcireg &= ~LPCIB_PCI_GEN_STA_NO_REBOOT;
    331  1.2.16.2  jdolecek 			pci_conf_write(sc->sc_pcib->sc_pc, sc->sc_pcib->sc_tag,
    332  1.2.16.2  jdolecek 				       LPCIB_PCI_GEN_STA, pcireg);
    333  1.2.16.2  jdolecek 			if (pcireg & LPCIB_PCI_GEN_STA_NO_REBOOT)
    334  1.2.16.2  jdolecek 				goto error;
    335  1.2.16.2  jdolecek 		}
    336  1.2.16.2  jdolecek 	}
    337  1.2.16.2  jdolecek 
    338  1.2.16.2  jdolecek 	return 0;
    339  1.2.16.2  jdolecek error:
    340  1.2.16.2  jdolecek 	aprint_error_dev(self, "TCO timer reboot disabled by hardware; "
    341  1.2.16.2  jdolecek 	    "hope SMBIOS properly handles it.\n");
    342  1.2.16.2  jdolecek 	return EINVAL;
    343  1.2.16.2  jdolecek }
    344  1.2.16.2  jdolecek 
    345  1.2.16.2  jdolecek MODULE(MODULE_CLASS_DRIVER, tco, "sysmon_wdog");
    346  1.2.16.2  jdolecek 
    347  1.2.16.2  jdolecek #ifdef _MODULE
    348  1.2.16.2  jdolecek #include "ioconf.c"
    349  1.2.16.2  jdolecek #endif
    350  1.2.16.2  jdolecek 
    351  1.2.16.2  jdolecek static int
    352  1.2.16.2  jdolecek tco_modcmd(modcmd_t cmd, void *arg)
    353  1.2.16.2  jdolecek {
    354  1.2.16.2  jdolecek 	int ret = 0;
    355  1.2.16.2  jdolecek 
    356  1.2.16.2  jdolecek 	switch (cmd) {
    357  1.2.16.2  jdolecek 	case MODULE_CMD_INIT:
    358  1.2.16.2  jdolecek #ifdef _MODULE
    359  1.2.16.2  jdolecek 		ret = config_init_component(cfdriver_ioconf_tco,
    360  1.2.16.2  jdolecek 					    cfattach_ioconf_tco,
    361  1.2.16.2  jdolecek 					    cfdata_ioconf_tco);
    362  1.2.16.2  jdolecek #endif
    363  1.2.16.2  jdolecek 		break;
    364  1.2.16.2  jdolecek 	case MODULE_CMD_FINI:
    365  1.2.16.2  jdolecek #ifdef _MODULE
    366  1.2.16.2  jdolecek 		ret = config_fini_component(cfdriver_ioconf_tco,
    367  1.2.16.2  jdolecek 					    cfattach_ioconf_tco,
    368  1.2.16.2  jdolecek 					    cfdata_ioconf_tco);
    369  1.2.16.2  jdolecek #endif
    370  1.2.16.2  jdolecek 		break;
    371  1.2.16.2  jdolecek 	default:
    372  1.2.16.2  jdolecek 		ret = ENOTTY;
    373  1.2.16.2  jdolecek 	}
    374  1.2.16.2  jdolecek 
    375  1.2.16.2  jdolecek 	return ret;
    376  1.2.16.2  jdolecek }
    377