Home | History | Annotate | Line # | Download | only in pci
ichlpcib.c revision 1.1.2.3
      1  1.1.2.3     matt /*	ichlpcib.c,v 1.1.2.2 2008/01/09 01:49:50 matt Exp	*/
      2      1.1  xtraeme 
      3      1.1  xtraeme /*-
      4      1.1  xtraeme  * Copyright (c) 2004 The NetBSD Foundation, Inc.
      5      1.1  xtraeme  * All rights reserved.
      6      1.1  xtraeme  *
      7      1.1  xtraeme  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1  xtraeme  * by Minoura Makoto and Matthew R. Green.
      9      1.1  xtraeme  *
     10      1.1  xtraeme  * Redistribution and use in source and binary forms, with or without
     11      1.1  xtraeme  * modification, are permitted provided that the following conditions
     12      1.1  xtraeme  * are met:
     13      1.1  xtraeme  * 1. Redistributions of source code must retain the above copyright
     14      1.1  xtraeme  *    notice, this list of conditions and the following disclaimer.
     15      1.1  xtraeme  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1  xtraeme  *    notice, this list of conditions and the following disclaimer in the
     17      1.1  xtraeme  *    documentation and/or other materials provided with the distribution.
     18      1.1  xtraeme  * 3. All advertising materials mentioning features or use of this software
     19      1.1  xtraeme  *    must display the following acknowledgement:
     20      1.1  xtraeme  *        This product includes software developed by the NetBSD
     21      1.1  xtraeme  *        Foundation, Inc. and its contributors.
     22      1.1  xtraeme  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.1  xtraeme  *    contributors may be used to endorse or promote products derived
     24      1.1  xtraeme  *    from this software without specific prior written permission.
     25      1.1  xtraeme  *
     26      1.1  xtraeme  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.1  xtraeme  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.1  xtraeme  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.1  xtraeme  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.1  xtraeme  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.1  xtraeme  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.1  xtraeme  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.1  xtraeme  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.1  xtraeme  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.1  xtraeme  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.1  xtraeme  * POSSIBILITY OF SUCH DAMAGE.
     37      1.1  xtraeme  */
     38      1.1  xtraeme 
     39      1.1  xtraeme /*
     40      1.1  xtraeme  * Intel I/O Controller Hub (ICHn) LPC Interface Bridge driver
     41      1.1  xtraeme  *
     42      1.1  xtraeme  *  LPC Interface Bridge is basically a pcib (PCI-ISA Bridge), but has
     43      1.1  xtraeme  *  some power management and monitoring functions.
     44      1.1  xtraeme  *  Currently we support the watchdog timer, SpeedStep (on some systems)
     45      1.1  xtraeme  *  and the power management timer.
     46      1.1  xtraeme  */
     47      1.1  xtraeme 
     48      1.1  xtraeme #include <sys/cdefs.h>
     49  1.1.2.3     matt __KERNEL_RCSID(0, "ichlpcib.c,v 1.1.2.2 2008/01/09 01:49:50 matt Exp");
     50      1.1  xtraeme 
     51      1.1  xtraeme #include <sys/types.h>
     52      1.1  xtraeme #include <sys/param.h>
     53      1.1  xtraeme #include <sys/systm.h>
     54      1.1  xtraeme #include <sys/device.h>
     55      1.1  xtraeme #include <sys/sysctl.h>
     56  1.1.2.2     matt #include <sys/timetc.h>
     57      1.1  xtraeme #include <machine/bus.h>
     58      1.1  xtraeme 
     59      1.1  xtraeme #include <dev/pci/pcivar.h>
     60      1.1  xtraeme #include <dev/pci/pcireg.h>
     61      1.1  xtraeme #include <dev/pci/pcidevs.h>
     62      1.1  xtraeme 
     63      1.1  xtraeme #include <dev/sysmon/sysmonvar.h>
     64      1.1  xtraeme 
     65      1.1  xtraeme #include <dev/ic/acpipmtimer.h>
     66  1.1.2.2     matt #include <dev/ic/i82801lpcreg.h>
     67  1.1.2.2     matt #include <dev/ic/hpetreg.h>
     68  1.1.2.2     matt #include <dev/ic/hpetvar.h>
     69  1.1.2.2     matt 
     70  1.1.2.2     matt #include "hpet.h"
     71      1.1  xtraeme 
     72      1.1  xtraeme struct lpcib_softc {
     73      1.1  xtraeme 	pci_chipset_tag_t	sc_pc;
     74      1.1  xtraeme 	pcitag_t		sc_pcitag;
     75      1.1  xtraeme 
     76  1.1.2.2     matt 	struct pci_attach_args	sc_pa;
     77  1.1.2.2     matt 	int			sc_has_rcba;
     78  1.1.2.2     matt 	int			sc_has_ich5_hpet;
     79  1.1.2.2     matt 
     80  1.1.2.2     matt 	/* RCBA */
     81  1.1.2.2     matt 	bus_space_tag_t		sc_rcbat;
     82  1.1.2.2     matt 	bus_space_handle_t	sc_rcbah;
     83  1.1.2.2     matt 	pcireg_t		sc_rcba_reg;
     84  1.1.2.2     matt 
     85      1.1  xtraeme 	/* Watchdog variables. */
     86      1.1  xtraeme 	struct sysmon_wdog	sc_smw;
     87      1.1  xtraeme 	bus_space_tag_t		sc_iot;
     88      1.1  xtraeme 	bus_space_handle_t	sc_ioh;
     89  1.1.2.2     matt 
     90  1.1.2.2     matt #if NHPET > 0
     91  1.1.2.2     matt 	/* HPET variables. */
     92  1.1.2.2     matt 	uint32_t		sc_hpet_reg;
     93  1.1.2.2     matt #endif
     94  1.1.2.2     matt 
     95      1.1  xtraeme 	/* Power management */
     96  1.1.2.3     matt 	pcireg_t		sc_pirq[2];
     97  1.1.2.2     matt 	pcireg_t		sc_pmcon;
     98  1.1.2.2     matt 	pcireg_t		sc_fwhsel2;
     99      1.1  xtraeme };
    100      1.1  xtraeme 
    101  1.1.2.3     matt static int lpcibmatch(device_t, cfdata_t, void *);
    102  1.1.2.3     matt static void lpcibattach(device_t, device_t, void *);
    103  1.1.2.3     matt static bool lpcib_suspend(device_t PMF_FN_PROTO);
    104  1.1.2.3     matt static bool lpcib_resume(device_t PMF_FN_PROTO);
    105      1.1  xtraeme 
    106  1.1.2.3     matt static void pmtimer_configure(device_t);
    107      1.1  xtraeme 
    108  1.1.2.3     matt static void tcotimer_configure(device_t);
    109      1.1  xtraeme static int tcotimer_setmode(struct sysmon_wdog *);
    110      1.1  xtraeme static int tcotimer_tickle(struct sysmon_wdog *);
    111      1.1  xtraeme static void tcotimer_stop(struct lpcib_softc *);
    112      1.1  xtraeme static void tcotimer_start(struct lpcib_softc *);
    113      1.1  xtraeme static void tcotimer_status_reset(struct lpcib_softc *);
    114  1.1.2.3     matt static int  tcotimer_disable_noreboot(device_t);
    115      1.1  xtraeme 
    116  1.1.2.3     matt static void speedstep_configure(device_t);
    117      1.1  xtraeme static int speedstep_sysctl_helper(SYSCTLFN_ARGS);
    118      1.1  xtraeme 
    119  1.1.2.2     matt #if NHPET > 0
    120  1.1.2.3     matt static void lpcib_hpet_configure(device_t);
    121  1.1.2.2     matt #endif
    122  1.1.2.2     matt 
    123      1.1  xtraeme struct lpcib_softc *speedstep_cookie;	/* XXX */
    124      1.1  xtraeme 
    125      1.1  xtraeme /* Defined in arch/.../pci/pcib.c. */
    126  1.1.2.3     matt extern void pcibattach(device_t, device_t, void *);
    127      1.1  xtraeme 
    128  1.1.2.3     matt CFATTACH_DECL_NEW(ichlpcib, sizeof(struct lpcib_softc),
    129      1.1  xtraeme     lpcibmatch, lpcibattach, NULL, NULL);
    130      1.1  xtraeme 
    131  1.1.2.2     matt static struct lpcib_device {
    132  1.1.2.2     matt 	pcireg_t vendor, product;
    133  1.1.2.2     matt 	int has_rcba;
    134  1.1.2.2     matt 	int has_ich5_hpet;
    135  1.1.2.2     matt } lpcib_devices[] = {
    136  1.1.2.2     matt 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801AA_LPC, 0, 0 },
    137  1.1.2.2     matt 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801BA_LPC, 0, 0 },
    138  1.1.2.2     matt 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801BAM_LPC, 0, 0 },
    139  1.1.2.2     matt 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801CA_LPC, 0, 0 },
    140  1.1.2.2     matt 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801CAM_LPC, 0, 0 },
    141  1.1.2.2     matt 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801DB_LPC, 0, 0 },
    142  1.1.2.2     matt 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801DB_ISA, 0, 0 },
    143  1.1.2.2     matt 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801EB_LPC, 0, 1 },
    144  1.1.2.2     matt 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801FB_LPC, 1, 0 },
    145  1.1.2.2     matt 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801FBM_LPC, 1, 0 },
    146  1.1.2.2     matt 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801G_LPC, 1, 0 },
    147  1.1.2.2     matt 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801GBM_LPC, 1, 0 },
    148  1.1.2.2     matt 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801GHM_LPC, 1, 0 },
    149  1.1.2.2     matt 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801H_LPC, 1, 0 },
    150  1.1.2.2     matt 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801HEM_LPC, 1, 0 },
    151  1.1.2.2     matt 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801HH_LPC, 1, 0 },
    152  1.1.2.2     matt 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801HO_LPC, 1, 0 },
    153  1.1.2.2     matt 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801HBM_LPC, 1, 0 },
    154  1.1.2.2     matt 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801IH_LPC, 1, 0 },
    155  1.1.2.2     matt 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801IO_LPC, 1, 0 },
    156  1.1.2.2     matt 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801IR_LPC, 1, 0 },
    157  1.1.2.2     matt 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801IB_LPC, 1, 0 },
    158  1.1.2.2     matt 	{ 0, 0, 0, 0 },
    159  1.1.2.2     matt };
    160  1.1.2.2     matt 
    161      1.1  xtraeme /*
    162      1.1  xtraeme  * Autoconf callbacks.
    163      1.1  xtraeme  */
    164      1.1  xtraeme static int
    165  1.1.2.3     matt lpcibmatch(device_t parent, cfdata_t match, void *aux)
    166      1.1  xtraeme {
    167      1.1  xtraeme 	struct pci_attach_args *pa = aux;
    168  1.1.2.2     matt 	struct lpcib_device *lpcib_dev;
    169      1.1  xtraeme 
    170      1.1  xtraeme 	/* We are ISA bridge, of course */
    171      1.1  xtraeme 	if (PCI_CLASS(pa->pa_class) != PCI_CLASS_BRIDGE ||
    172      1.1  xtraeme 	    PCI_SUBCLASS(pa->pa_class) != PCI_SUBCLASS_BRIDGE_ISA)
    173      1.1  xtraeme 		return 0;
    174      1.1  xtraeme 
    175  1.1.2.2     matt 	for (lpcib_dev = lpcib_devices; lpcib_dev->vendor; ++lpcib_dev) {
    176  1.1.2.2     matt 		if (PCI_VENDOR(pa->pa_id) == lpcib_dev->vendor &&
    177  1.1.2.2     matt 		    PCI_PRODUCT(pa->pa_id) == lpcib_dev->product)
    178      1.1  xtraeme 			return 10;
    179      1.1  xtraeme 	}
    180      1.1  xtraeme 
    181      1.1  xtraeme 	return 0;
    182      1.1  xtraeme }
    183      1.1  xtraeme 
    184      1.1  xtraeme static void
    185  1.1.2.3     matt lpcibattach(device_t parent, device_t self, void *aux)
    186      1.1  xtraeme {
    187      1.1  xtraeme 	struct pci_attach_args *pa = aux;
    188  1.1.2.2     matt 	struct lpcib_softc *sc = device_private(self);
    189  1.1.2.2     matt 	struct lpcib_device *lpcib_dev;
    190      1.1  xtraeme 
    191      1.1  xtraeme 	sc->sc_pc = pa->pa_pc;
    192      1.1  xtraeme 	sc->sc_pcitag = pa->pa_tag;
    193  1.1.2.2     matt 	sc->sc_pa = *pa;
    194  1.1.2.2     matt 
    195  1.1.2.2     matt 	for (lpcib_dev = lpcib_devices; lpcib_dev->vendor; ++lpcib_dev) {
    196  1.1.2.2     matt 		if (PCI_VENDOR(pa->pa_id) != lpcib_dev->vendor ||
    197  1.1.2.2     matt 		    PCI_PRODUCT(pa->pa_id) != lpcib_dev->product)
    198  1.1.2.2     matt 			continue;
    199  1.1.2.2     matt 		sc->sc_has_rcba = lpcib_dev->has_rcba;
    200  1.1.2.2     matt 		sc->sc_has_ich5_hpet = lpcib_dev->has_ich5_hpet;
    201  1.1.2.2     matt 		break;
    202  1.1.2.2     matt 	}
    203      1.1  xtraeme 
    204      1.1  xtraeme 	pcibattach(parent, self, aux);
    205      1.1  xtraeme 
    206      1.1  xtraeme 	/*
    207      1.1  xtraeme 	 * Part of our I/O registers are used as ACPI PM regs.
    208      1.1  xtraeme 	 * Since our ACPI subsystem accesses the I/O space directly so far,
    209      1.1  xtraeme 	 * we do not have to bother bus_space I/O map confliction.
    210      1.1  xtraeme 	 */
    211      1.1  xtraeme 	if (pci_mapreg_map(pa, LPCIB_PCI_PMBASE, PCI_MAPREG_TYPE_IO, 0,
    212      1.1  xtraeme 			   &sc->sc_iot, &sc->sc_ioh, NULL, NULL)) {
    213  1.1.2.3     matt 		aprint_error_dev(self, "can't map power management i/o space");
    214      1.1  xtraeme 		return;
    215      1.1  xtraeme 	}
    216      1.1  xtraeme 
    217  1.1.2.2     matt 	/* For ICH6 and later, always enable RCBA */
    218  1.1.2.2     matt 	if (sc->sc_has_rcba) {
    219  1.1.2.2     matt 		pcireg_t rcba;
    220  1.1.2.2     matt 
    221  1.1.2.2     matt 		sc->sc_rcbat = sc->sc_pa.pa_memt;
    222  1.1.2.2     matt 
    223  1.1.2.2     matt 		rcba = pci_conf_read(sc->sc_pc, sc->sc_pcitag, LPCIB_RCBA);
    224  1.1.2.2     matt 		if ((rcba & LPCIB_RCBA_EN) == 0) {
    225  1.1.2.3     matt 			aprint_error_dev(self, "RCBA is not enabled");
    226  1.1.2.2     matt 			return;
    227  1.1.2.2     matt 		}
    228  1.1.2.2     matt 		rcba &= ~LPCIB_RCBA_EN;
    229  1.1.2.2     matt 
    230  1.1.2.2     matt 		if (bus_space_map(sc->sc_rcbat, rcba, LPCIB_RCBA_SIZE, 0,
    231  1.1.2.2     matt 				  &sc->sc_rcbah)) {
    232  1.1.2.3     matt 			aprint_error_dev(self, "RCBA could not be mapped");
    233  1.1.2.2     matt 			return;
    234  1.1.2.2     matt 		}
    235  1.1.2.2     matt 	}
    236  1.1.2.2     matt 
    237      1.1  xtraeme 	/* Set up the power management timer. */
    238  1.1.2.3     matt 	pmtimer_configure(self);
    239      1.1  xtraeme 
    240      1.1  xtraeme 	/* Set up the TCO (watchdog). */
    241  1.1.2.3     matt 	tcotimer_configure(self);
    242      1.1  xtraeme 
    243      1.1  xtraeme 	/* Set up SpeedStep. */
    244  1.1.2.3     matt 	speedstep_configure(self);
    245      1.1  xtraeme 
    246  1.1.2.2     matt #if NHPET > 0
    247  1.1.2.2     matt 	/* Set up HPET. */
    248  1.1.2.3     matt 	lpcib_hpet_configure(self);
    249  1.1.2.2     matt #endif
    250  1.1.2.2     matt 
    251  1.1.2.2     matt 	/* Install power handler */
    252  1.1.2.2     matt 	if (!pmf_device_register(self, lpcib_suspend, lpcib_resume))
    253  1.1.2.2     matt 		aprint_error_dev(self, "couldn't establish power handler\n");
    254  1.1.2.2     matt }
    255  1.1.2.2     matt 
    256  1.1.2.2     matt static bool
    257  1.1.2.3     matt lpcib_suspend(device_t dv PMF_FN_ARGS)
    258  1.1.2.2     matt {
    259  1.1.2.2     matt 	struct lpcib_softc *sc = device_private(dv);
    260  1.1.2.2     matt 	pci_chipset_tag_t pc = sc->sc_pc;
    261  1.1.2.2     matt 	pcitag_t tag = sc->sc_pcitag;
    262  1.1.2.2     matt 
    263  1.1.2.2     matt 	/* capture PIRQ routing control registers */
    264  1.1.2.2     matt 	sc->sc_pirq[0] = pci_conf_read(pc, tag, LPCIB_PCI_PIRQA_ROUT);
    265  1.1.2.3     matt 	sc->sc_pirq[1] = pci_conf_read(pc, tag, LPCIB_PCI_PIRQE_ROUT);
    266  1.1.2.2     matt 
    267  1.1.2.2     matt 	sc->sc_pmcon = pci_conf_read(pc, tag, LPCIB_PCI_GEN_PMCON_1);
    268  1.1.2.2     matt 	sc->sc_fwhsel2 = pci_conf_read(pc, tag, LPCIB_PCI_GEN_STA);
    269  1.1.2.2     matt 
    270  1.1.2.2     matt 	if (sc->sc_has_rcba) {
    271  1.1.2.2     matt 		sc->sc_rcba_reg = pci_conf_read(pc, tag, LPCIB_RCBA);
    272  1.1.2.2     matt #if NHPET > 0
    273  1.1.2.2     matt 		sc->sc_hpet_reg = bus_space_read_4(sc->sc_rcbat, sc->sc_rcbah,
    274  1.1.2.2     matt 		    LPCIB_RCBA_HPTC);
    275  1.1.2.2     matt #endif
    276  1.1.2.2     matt 	} else if (sc->sc_has_ich5_hpet) {
    277  1.1.2.2     matt #if NHPET > 0
    278  1.1.2.2     matt 		sc->sc_hpet_reg = pci_conf_read(pc, tag, LPCIB_PCI_GEN_CNTL);
    279  1.1.2.2     matt #endif
    280  1.1.2.2     matt 	}
    281  1.1.2.2     matt 
    282  1.1.2.2     matt 	return true;
    283  1.1.2.2     matt }
    284  1.1.2.2     matt 
    285  1.1.2.2     matt static bool
    286  1.1.2.3     matt lpcib_resume(device_t dv PMF_FN_ARGS)
    287  1.1.2.2     matt {
    288  1.1.2.2     matt 	struct lpcib_softc *sc = device_private(dv);
    289  1.1.2.2     matt 	pci_chipset_tag_t pc = sc->sc_pc;
    290  1.1.2.2     matt 	pcitag_t tag = sc->sc_pcitag;
    291  1.1.2.2     matt 
    292  1.1.2.2     matt 	/* restore PIRQ routing control registers */
    293  1.1.2.2     matt 	pci_conf_write(pc, tag, LPCIB_PCI_PIRQA_ROUT, sc->sc_pirq[0]);
    294  1.1.2.3     matt 	pci_conf_write(pc, tag, LPCIB_PCI_PIRQE_ROUT, sc->sc_pirq[1]);
    295  1.1.2.2     matt 
    296  1.1.2.2     matt 	pci_conf_write(pc, tag, LPCIB_PCI_GEN_PMCON_1, sc->sc_pmcon);
    297  1.1.2.2     matt 	pci_conf_write(pc, tag, LPCIB_PCI_GEN_STA, sc->sc_fwhsel2);
    298  1.1.2.2     matt 
    299  1.1.2.2     matt 	if (sc->sc_has_rcba) {
    300  1.1.2.2     matt 		pci_conf_write(pc, tag, LPCIB_RCBA, sc->sc_rcba_reg);
    301  1.1.2.2     matt #if NHPET > 0
    302  1.1.2.2     matt 		bus_space_write_4(sc->sc_rcbat, sc->sc_rcbah, LPCIB_RCBA_HPTC,
    303  1.1.2.2     matt 		    sc->sc_hpet_reg);
    304  1.1.2.2     matt #endif
    305  1.1.2.2     matt 	} else if (sc->sc_has_ich5_hpet) {
    306  1.1.2.2     matt #if NHPET > 0
    307  1.1.2.2     matt 		pci_conf_write(pc, tag, LPCIB_PCI_GEN_CNTL, sc->sc_hpet_reg);
    308  1.1.2.2     matt #endif
    309      1.1  xtraeme 	}
    310  1.1.2.2     matt 
    311  1.1.2.2     matt 	return true;
    312      1.1  xtraeme }
    313      1.1  xtraeme 
    314      1.1  xtraeme /*
    315      1.1  xtraeme  * Initialize the power management timer.
    316      1.1  xtraeme  */
    317      1.1  xtraeme static void
    318  1.1.2.3     matt pmtimer_configure(device_t self)
    319      1.1  xtraeme {
    320  1.1.2.3     matt 	struct lpcib_softc *sc = device_private(self);
    321      1.1  xtraeme 	pcireg_t control;
    322      1.1  xtraeme 
    323      1.1  xtraeme 	/*
    324      1.1  xtraeme 	 * Check if power management I/O space is enabled and enable the ACPI_EN
    325      1.1  xtraeme 	 * bit if it's disabled.
    326      1.1  xtraeme 	 */
    327  1.1.2.2     matt 	control = pci_conf_read(sc->sc_pc, sc->sc_pcitag, LPCIB_PCI_ACPI_CNTL);
    328      1.1  xtraeme 	if ((control & LPCIB_PCI_ACPI_CNTL_EN) == 0) {
    329      1.1  xtraeme 		control |= LPCIB_PCI_ACPI_CNTL_EN;
    330  1.1.2.2     matt 		pci_conf_write(sc->sc_pc, sc->sc_pcitag, LPCIB_PCI_ACPI_CNTL,
    331      1.1  xtraeme 		    control);
    332      1.1  xtraeme 	}
    333      1.1  xtraeme 
    334      1.1  xtraeme 	/* Attach our PM timer with the generic acpipmtimer function */
    335  1.1.2.3     matt 	acpipmtimer_attach(self, sc->sc_iot, sc->sc_ioh,
    336      1.1  xtraeme 	    LPCIB_PM1_TMR, 0);
    337      1.1  xtraeme }
    338      1.1  xtraeme 
    339      1.1  xtraeme /*
    340      1.1  xtraeme  * Initialize the watchdog timer.
    341      1.1  xtraeme  */
    342      1.1  xtraeme static void
    343  1.1.2.3     matt tcotimer_configure(device_t self)
    344      1.1  xtraeme {
    345  1.1.2.3     matt 	struct lpcib_softc *sc = device_private(self);
    346      1.1  xtraeme 	uint32_t ioreg;
    347      1.1  xtraeme 	unsigned int period;
    348      1.1  xtraeme 
    349      1.1  xtraeme 	/*
    350  1.1.2.1     matt 	 * Clear the No Reboot (NR) bit. If this fails, enabling the TCO_EN bit
    351      1.1  xtraeme 	 * in the SMI_EN register is the last chance.
    352      1.1  xtraeme 	 */
    353  1.1.2.3     matt 	if (tcotimer_disable_noreboot(self)) {
    354      1.1  xtraeme 		ioreg = bus_space_read_4(sc->sc_iot, sc->sc_ioh, LPCIB_SMI_EN);
    355      1.1  xtraeme 		ioreg |= LPCIB_SMI_EN_TCO_EN;
    356      1.1  xtraeme 		bus_space_write_4(sc->sc_iot, sc->sc_ioh, LPCIB_SMI_EN, ioreg);
    357      1.1  xtraeme 	}
    358      1.1  xtraeme 
    359      1.1  xtraeme 	/* Reset the watchdog status registers. */
    360      1.1  xtraeme 	tcotimer_status_reset(sc);
    361      1.1  xtraeme 
    362      1.1  xtraeme 	/* Explicitly stop the TCO timer. */
    363      1.1  xtraeme 	tcotimer_stop(sc);
    364      1.1  xtraeme 
    365      1.1  xtraeme 	/*
    366      1.1  xtraeme 	 * Register the driver with the sysmon watchdog framework.
    367      1.1  xtraeme 	 */
    368  1.1.2.3     matt 	sc->sc_smw.smw_name = device_xname(self);
    369      1.1  xtraeme 	sc->sc_smw.smw_cookie = sc;
    370      1.1  xtraeme 	sc->sc_smw.smw_setmode = tcotimer_setmode;
    371      1.1  xtraeme 	sc->sc_smw.smw_tickle = tcotimer_tickle;
    372  1.1.2.2     matt 	if (sc->sc_has_rcba)
    373      1.1  xtraeme 		period = LPCIB_TCOTIMER2_MAX_TICK;
    374      1.1  xtraeme 	else
    375      1.1  xtraeme 		period = LPCIB_TCOTIMER_MAX_TICK;
    376      1.1  xtraeme 	sc->sc_smw.smw_period = lpcib_tcotimer_tick_to_second(period);
    377      1.1  xtraeme 
    378      1.1  xtraeme 	if (sysmon_wdog_register(&sc->sc_smw)) {
    379  1.1.2.3     matt 		aprint_error_dev(self, "unable to register TCO timer"
    380  1.1.2.3     matt 		       "as a sysmon watchdog device.\n");
    381      1.1  xtraeme 		return;
    382      1.1  xtraeme 	}
    383      1.1  xtraeme 
    384  1.1.2.3     matt 	aprint_verbose_dev(self, "TCO (watchdog) timer configured.\n");
    385      1.1  xtraeme }
    386      1.1  xtraeme 
    387      1.1  xtraeme /*
    388      1.1  xtraeme  * Sysmon watchdog callbacks.
    389      1.1  xtraeme  */
    390      1.1  xtraeme static int
    391      1.1  xtraeme tcotimer_setmode(struct sysmon_wdog *smw)
    392      1.1  xtraeme {
    393      1.1  xtraeme 	struct lpcib_softc *sc = smw->smw_cookie;
    394      1.1  xtraeme 	unsigned int period;
    395      1.1  xtraeme 	uint16_t ich6period = 0;
    396      1.1  xtraeme 
    397      1.1  xtraeme 	if ((smw->smw_mode & WDOG_MODE_MASK) == WDOG_MODE_DISARMED) {
    398      1.1  xtraeme 		/* Stop the TCO timer. */
    399      1.1  xtraeme 		tcotimer_stop(sc);
    400      1.1  xtraeme 	} else {
    401      1.1  xtraeme 		/*
    402      1.1  xtraeme 		 * ICH6 or newer are limited to 2s min and 613s max.
    403  1.1.2.2     matt 		 * ICH5 or older are limited to 4s min and 39s max.
    404      1.1  xtraeme 		 */
    405  1.1.2.2     matt 		if (sc->sc_has_rcba) {
    406  1.1.2.2     matt 			if (smw->smw_period < LPCIB_TCOTIMER2_MIN_TICK ||
    407  1.1.2.2     matt 			    smw->smw_period > LPCIB_TCOTIMER2_MAX_TICK)
    408      1.1  xtraeme 				return EINVAL;
    409      1.1  xtraeme 		} else {
    410  1.1.2.2     matt 			if (smw->smw_period < LPCIB_TCOTIMER_MIN_TICK ||
    411  1.1.2.2     matt 			    smw->smw_period > LPCIB_TCOTIMER_MAX_TICK)
    412      1.1  xtraeme 				return EINVAL;
    413      1.1  xtraeme 		}
    414  1.1.2.2     matt 		period = lpcib_tcotimer_second_to_tick(smw->smw_period);
    415  1.1.2.2     matt 
    416      1.1  xtraeme 		/* Stop the TCO timer, */
    417      1.1  xtraeme 		tcotimer_stop(sc);
    418      1.1  xtraeme 
    419      1.1  xtraeme 		/* set the timeout, */
    420  1.1.2.2     matt 		if (sc->sc_has_rcba) {
    421      1.1  xtraeme 			/* ICH6 or newer */
    422      1.1  xtraeme 			ich6period = bus_space_read_2(sc->sc_iot, sc->sc_ioh,
    423      1.1  xtraeme 						      LPCIB_TCO_TMR2);
    424      1.1  xtraeme 			ich6period &= 0xfc00;
    425      1.1  xtraeme 			bus_space_write_2(sc->sc_iot, sc->sc_ioh,
    426      1.1  xtraeme 					  LPCIB_TCO_TMR2, ich6period | period);
    427      1.1  xtraeme 		} else {
    428      1.1  xtraeme 			/* ICH5 or older */
    429      1.1  xtraeme 			period |= bus_space_read_1(sc->sc_iot, sc->sc_ioh,
    430      1.1  xtraeme 						   LPCIB_TCO_TMR);
    431      1.1  xtraeme 			period &= 0xc0;
    432      1.1  xtraeme 			bus_space_write_1(sc->sc_iot, sc->sc_ioh,
    433      1.1  xtraeme 					  LPCIB_TCO_TMR, period);
    434      1.1  xtraeme 		}
    435      1.1  xtraeme 
    436      1.1  xtraeme 		/* and start/reload the timer. */
    437      1.1  xtraeme 		tcotimer_start(sc);
    438      1.1  xtraeme 		tcotimer_tickle(smw);
    439      1.1  xtraeme 	}
    440      1.1  xtraeme 
    441      1.1  xtraeme 	return 0;
    442      1.1  xtraeme }
    443      1.1  xtraeme 
    444      1.1  xtraeme static int
    445      1.1  xtraeme tcotimer_tickle(struct sysmon_wdog *smw)
    446      1.1  xtraeme {
    447      1.1  xtraeme 	struct lpcib_softc *sc = smw->smw_cookie;
    448      1.1  xtraeme 
    449      1.1  xtraeme 	/* any value is allowed */
    450  1.1.2.2     matt 	if (sc->sc_has_rcba)
    451      1.1  xtraeme 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO_RLD, 1);
    452  1.1.2.2     matt 	else
    453  1.1.2.2     matt 		bus_space_write_1(sc->sc_iot, sc->sc_ioh, LPCIB_TCO_RLD, 1);
    454      1.1  xtraeme 
    455      1.1  xtraeme 	return 0;
    456      1.1  xtraeme }
    457      1.1  xtraeme 
    458      1.1  xtraeme static void
    459      1.1  xtraeme tcotimer_stop(struct lpcib_softc *sc)
    460      1.1  xtraeme {
    461      1.1  xtraeme 	uint16_t ioreg;
    462      1.1  xtraeme 
    463      1.1  xtraeme 	ioreg = bus_space_read_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_CNT);
    464      1.1  xtraeme 	ioreg |= LPCIB_TCO1_CNT_TCO_TMR_HLT;
    465      1.1  xtraeme 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_CNT, ioreg);
    466      1.1  xtraeme }
    467      1.1  xtraeme 
    468      1.1  xtraeme static void
    469      1.1  xtraeme tcotimer_start(struct lpcib_softc *sc)
    470      1.1  xtraeme {
    471      1.1  xtraeme 	uint16_t ioreg;
    472      1.1  xtraeme 
    473      1.1  xtraeme 	ioreg = bus_space_read_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_CNT);
    474      1.1  xtraeme 	ioreg &= ~LPCIB_TCO1_CNT_TCO_TMR_HLT;
    475      1.1  xtraeme 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_CNT, ioreg);
    476      1.1  xtraeme }
    477      1.1  xtraeme 
    478      1.1  xtraeme static void
    479      1.1  xtraeme tcotimer_status_reset(struct lpcib_softc *sc)
    480      1.1  xtraeme {
    481      1.1  xtraeme 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_STS,
    482      1.1  xtraeme 			  LPCIB_TCO1_STS_TIMEOUT);
    483      1.1  xtraeme 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO2_STS,
    484      1.1  xtraeme 			  LPCIB_TCO2_STS_BOOT_STS);
    485      1.1  xtraeme 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO2_STS,
    486      1.1  xtraeme 			  LPCIB_TCO2_STS_SECONDS_TO_STS);
    487      1.1  xtraeme }
    488      1.1  xtraeme 
    489      1.1  xtraeme /*
    490  1.1.2.1     matt  * Clear the No Reboot (NR) bit, this enables reboots when the timer
    491  1.1.2.1     matt  * reaches the timeout for the second time.
    492      1.1  xtraeme  */
    493      1.1  xtraeme static int
    494  1.1.2.3     matt tcotimer_disable_noreboot(device_t self)
    495      1.1  xtraeme {
    496  1.1.2.3     matt 	struct lpcib_softc *sc = device_private(self);
    497      1.1  xtraeme 
    498  1.1.2.2     matt 	if (sc->sc_has_rcba) {
    499  1.1.2.2     matt 		uint32_t status;
    500  1.1.2.2     matt 
    501  1.1.2.3     matt 		status = bus_space_read_4(sc->sc_rcbat, sc->sc_rcbah,
    502  1.1.2.3     matt 		    LPCIB_GCS_OFFSET);
    503  1.1.2.2     matt 		status &= ~LPCIB_GCS_NO_REBOOT;
    504  1.1.2.3     matt 		bus_space_write_4(sc->sc_rcbat, sc->sc_rcbah,
    505  1.1.2.3     matt 		    LPCIB_GCS_OFFSET, status);
    506  1.1.2.3     matt 		status = bus_space_read_4(sc->sc_rcbat, sc->sc_rcbah,
    507  1.1.2.3     matt 		    LPCIB_GCS_OFFSET);
    508  1.1.2.2     matt 		if (status & LPCIB_GCS_NO_REBOOT)
    509  1.1.2.2     matt 			goto error;
    510  1.1.2.2     matt 	} else {
    511  1.1.2.2     matt 		pcireg_t pcireg;
    512  1.1.2.2     matt 
    513      1.1  xtraeme 		pcireg = pci_conf_read(sc->sc_pc, sc->sc_pcitag,
    514      1.1  xtraeme 				       LPCIB_PCI_GEN_STA);
    515      1.1  xtraeme 		if (pcireg & LPCIB_PCI_GEN_STA_NO_REBOOT) {
    516      1.1  xtraeme 			/* TCO timeout reset is disabled; try to enable it */
    517      1.1  xtraeme 			pcireg &= ~LPCIB_PCI_GEN_STA_NO_REBOOT;
    518      1.1  xtraeme 			pci_conf_write(sc->sc_pc, sc->sc_pcitag,
    519      1.1  xtraeme 				       LPCIB_PCI_GEN_STA, pcireg);
    520      1.1  xtraeme 			if (pcireg & LPCIB_PCI_GEN_STA_NO_REBOOT)
    521      1.1  xtraeme 				goto error;
    522      1.1  xtraeme 		}
    523      1.1  xtraeme 	}
    524      1.1  xtraeme 
    525      1.1  xtraeme 	return 0;
    526      1.1  xtraeme error:
    527  1.1.2.3     matt 	aprint_error_dev(self, "TCO timer reboot disabled by hardware; "
    528  1.1.2.3     matt 	    "hope SMBIOS properly handles it.\n");
    529      1.1  xtraeme 	return EINVAL;
    530      1.1  xtraeme }
    531      1.1  xtraeme 
    532      1.1  xtraeme 
    533      1.1  xtraeme /*
    534      1.1  xtraeme  * Intel ICH SpeedStep support.
    535      1.1  xtraeme  */
    536      1.1  xtraeme #define SS_READ(sc, reg) \
    537      1.1  xtraeme 	bus_space_read_1((sc)->sc_iot, (sc)->sc_ioh, (reg))
    538      1.1  xtraeme #define SS_WRITE(sc, reg, val) \
    539      1.1  xtraeme 	bus_space_write_1((sc)->sc_iot, (sc)->sc_ioh, (reg), (val))
    540      1.1  xtraeme 
    541      1.1  xtraeme /*
    542      1.1  xtraeme  * Linux driver says that SpeedStep on older chipsets cause
    543      1.1  xtraeme  * lockups on Dell Inspiron 8000 and 8100.
    544      1.1  xtraeme  */
    545      1.1  xtraeme static int
    546      1.1  xtraeme speedstep_bad_hb_check(struct pci_attach_args *pa)
    547      1.1  xtraeme {
    548      1.1  xtraeme 
    549      1.1  xtraeme 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82815_FULL_HUB &&
    550      1.1  xtraeme 	    PCI_REVISION(pa->pa_class) < 5)
    551      1.1  xtraeme 		return 1;
    552      1.1  xtraeme 
    553      1.1  xtraeme 	return 0;
    554      1.1  xtraeme }
    555      1.1  xtraeme 
    556      1.1  xtraeme static void
    557  1.1.2.3     matt speedstep_configure(device_t self)
    558      1.1  xtraeme {
    559  1.1.2.3     matt 	struct lpcib_softc *sc = device_private(self);
    560      1.1  xtraeme 	const struct sysctlnode	*node, *ssnode;
    561      1.1  xtraeme 	int rv;
    562      1.1  xtraeme 
    563      1.1  xtraeme 	/* Supported on ICH2-M, ICH3-M and ICH4-M.  */
    564  1.1.2.2     matt 	if (PCI_PRODUCT(sc->sc_pa.pa_id) == PCI_PRODUCT_INTEL_82801DB_ISA ||
    565  1.1.2.2     matt 	    PCI_PRODUCT(sc->sc_pa.pa_id) == PCI_PRODUCT_INTEL_82801CAM_LPC ||
    566  1.1.2.2     matt 	    (PCI_PRODUCT(sc->sc_pa.pa_id) == PCI_PRODUCT_INTEL_82801BAM_LPC &&
    567  1.1.2.2     matt 	     pci_find_device(&sc->sc_pa, speedstep_bad_hb_check) == 0)) {
    568      1.1  xtraeme 		uint8_t pmcon;
    569      1.1  xtraeme 
    570      1.1  xtraeme 		/* Enable SpeedStep if it isn't already enabled. */
    571  1.1.2.2     matt 		pmcon = pci_conf_read(sc->sc_pc, sc->sc_pcitag,
    572      1.1  xtraeme 				      LPCIB_PCI_GEN_PMCON_1);
    573      1.1  xtraeme 		if ((pmcon & LPCIB_PCI_GEN_PMCON_1_SS_EN) == 0)
    574  1.1.2.2     matt 			pci_conf_write(sc->sc_pc, sc->sc_pcitag,
    575      1.1  xtraeme 				       LPCIB_PCI_GEN_PMCON_1,
    576      1.1  xtraeme 				       pmcon | LPCIB_PCI_GEN_PMCON_1_SS_EN);
    577      1.1  xtraeme 
    578      1.1  xtraeme 		/* Put in machdep.speedstep_state (0 for low, 1 for high). */
    579      1.1  xtraeme 		if ((rv = sysctl_createv(NULL, 0, NULL, &node,
    580      1.1  xtraeme 		    CTLFLAG_PERMANENT, CTLTYPE_NODE, "machdep", NULL,
    581      1.1  xtraeme 		    NULL, 0, NULL, 0, CTL_MACHDEP, CTL_EOL)) != 0)
    582      1.1  xtraeme 			goto err;
    583      1.1  xtraeme 
    584      1.1  xtraeme 		/* CTLFLAG_ANYWRITE? kernel option like EST? */
    585      1.1  xtraeme 		if ((rv = sysctl_createv(NULL, 0, &node, &ssnode,
    586      1.1  xtraeme 		    CTLFLAG_READWRITE, CTLTYPE_INT, "speedstep_state", NULL,
    587      1.1  xtraeme 		    speedstep_sysctl_helper, 0, NULL, 0, CTL_CREATE,
    588      1.1  xtraeme 		    CTL_EOL)) != 0)
    589      1.1  xtraeme 			goto err;
    590      1.1  xtraeme 
    591      1.1  xtraeme 		/* XXX save the sc for IO tag/handle */
    592      1.1  xtraeme 		speedstep_cookie = sc;
    593  1.1.2.3     matt 		aprint_verbose_dev(self, "SpeedStep enabled\n");
    594      1.1  xtraeme 	}
    595      1.1  xtraeme 
    596      1.1  xtraeme 	return;
    597      1.1  xtraeme 
    598      1.1  xtraeme err:
    599      1.1  xtraeme 	aprint_normal("%s: sysctl_createv failed (rv = %d)\n", __func__, rv);
    600      1.1  xtraeme }
    601      1.1  xtraeme 
    602      1.1  xtraeme /*
    603      1.1  xtraeme  * get/set the SpeedStep state: 0 == low power, 1 == high power.
    604      1.1  xtraeme  */
    605      1.1  xtraeme static int
    606      1.1  xtraeme speedstep_sysctl_helper(SYSCTLFN_ARGS)
    607      1.1  xtraeme {
    608      1.1  xtraeme 	struct sysctlnode	node;
    609      1.1  xtraeme 	struct lpcib_softc 	*sc = speedstep_cookie;
    610      1.1  xtraeme 	uint8_t			state, state2;
    611      1.1  xtraeme 	int			ostate, nstate, s, error = 0;
    612      1.1  xtraeme 
    613      1.1  xtraeme 	/*
    614      1.1  xtraeme 	 * We do the dance with spl's to avoid being at high ipl during
    615      1.1  xtraeme 	 * sysctl_lookup() which can both copyin and copyout.
    616      1.1  xtraeme 	 */
    617      1.1  xtraeme 	s = splserial();
    618      1.1  xtraeme 	state = SS_READ(sc, LPCIB_PM_SS_CNTL);
    619      1.1  xtraeme 	splx(s);
    620      1.1  xtraeme 	if ((state & LPCIB_PM_SS_STATE_LOW) == 0)
    621      1.1  xtraeme 		ostate = 1;
    622      1.1  xtraeme 	else
    623      1.1  xtraeme 		ostate = 0;
    624      1.1  xtraeme 	nstate = ostate;
    625      1.1  xtraeme 
    626      1.1  xtraeme 	node = *rnode;
    627      1.1  xtraeme 	node.sysctl_data = &nstate;
    628      1.1  xtraeme 
    629      1.1  xtraeme 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    630      1.1  xtraeme 	if (error || newp == NULL)
    631      1.1  xtraeme 		goto out;
    632      1.1  xtraeme 
    633      1.1  xtraeme 	/* Only two states are available */
    634      1.1  xtraeme 	if (nstate != 0 && nstate != 1) {
    635      1.1  xtraeme 		error = EINVAL;
    636      1.1  xtraeme 		goto out;
    637      1.1  xtraeme 	}
    638      1.1  xtraeme 
    639      1.1  xtraeme 	s = splserial();
    640      1.1  xtraeme 	state2 = SS_READ(sc, LPCIB_PM_SS_CNTL);
    641      1.1  xtraeme 	if ((state2 & LPCIB_PM_SS_STATE_LOW) == 0)
    642      1.1  xtraeme 		ostate = 1;
    643      1.1  xtraeme 	else
    644      1.1  xtraeme 		ostate = 0;
    645      1.1  xtraeme 
    646      1.1  xtraeme 	if (ostate != nstate) {
    647      1.1  xtraeme 		uint8_t cntl;
    648      1.1  xtraeme 
    649      1.1  xtraeme 		if (nstate == 0)
    650      1.1  xtraeme 			state2 |= LPCIB_PM_SS_STATE_LOW;
    651      1.1  xtraeme 		else
    652      1.1  xtraeme 			state2 &= ~LPCIB_PM_SS_STATE_LOW;
    653      1.1  xtraeme 
    654      1.1  xtraeme 		/*
    655      1.1  xtraeme 		 * Must disable bus master arbitration during the change.
    656      1.1  xtraeme 		 */
    657      1.1  xtraeme 		cntl = SS_READ(sc, LPCIB_PM_CTRL);
    658      1.1  xtraeme 		SS_WRITE(sc, LPCIB_PM_CTRL, cntl | LPCIB_PM_SS_CNTL_ARB_DIS);
    659      1.1  xtraeme 		SS_WRITE(sc, LPCIB_PM_SS_CNTL, state2);
    660      1.1  xtraeme 		SS_WRITE(sc, LPCIB_PM_CTRL, cntl);
    661      1.1  xtraeme 	}
    662      1.1  xtraeme 	splx(s);
    663      1.1  xtraeme out:
    664      1.1  xtraeme 	return error;
    665      1.1  xtraeme }
    666  1.1.2.2     matt 
    667  1.1.2.2     matt #if NHPET > 0
    668  1.1.2.2     matt struct lpcib_hpet_attach_arg {
    669  1.1.2.2     matt 	bus_space_tag_t hpet_mem_t;
    670  1.1.2.2     matt 	uint32_t hpet_reg;
    671  1.1.2.2     matt };
    672  1.1.2.2     matt 
    673  1.1.2.2     matt static int
    674  1.1.2.3     matt lpcib_hpet_match(device_t parent, cfdata_t match, void *aux)
    675  1.1.2.2     matt {
    676  1.1.2.2     matt 	struct lpcib_hpet_attach_arg *arg = aux;
    677  1.1.2.2     matt 	bus_space_tag_t tag;
    678  1.1.2.2     matt 	bus_space_handle_t handle;
    679  1.1.2.2     matt 
    680  1.1.2.2     matt 	tag = arg->hpet_mem_t;
    681  1.1.2.2     matt 
    682  1.1.2.2     matt 	if (bus_space_map(tag, arg->hpet_reg, HPET_WINDOW_SIZE, 0, &handle)) {
    683  1.1.2.2     matt 		aprint_verbose("%s: HPET window not mapped, skipping\n",
    684  1.1.2.2     matt 		    parent->dv_xname);
    685  1.1.2.2     matt 		return 0;
    686  1.1.2.2     matt 	}
    687  1.1.2.2     matt 	bus_space_unmap(tag, handle, HPET_WINDOW_SIZE);
    688  1.1.2.2     matt 
    689  1.1.2.2     matt 	return 1;
    690  1.1.2.2     matt }
    691  1.1.2.2     matt 
    692  1.1.2.2     matt static void
    693  1.1.2.2     matt lpcib_hpet_attach(device_t parent, device_t self, void *aux)
    694  1.1.2.2     matt {
    695  1.1.2.2     matt 	struct hpet_softc *sc = device_private(self);
    696  1.1.2.2     matt 	struct lpcib_hpet_attach_arg *arg = aux;
    697  1.1.2.2     matt 
    698  1.1.2.2     matt 	aprint_naive("\n");
    699  1.1.2.2     matt 	aprint_normal("\n");
    700  1.1.2.2     matt 
    701  1.1.2.2     matt 	sc->sc_memt = arg->hpet_mem_t;
    702  1.1.2.2     matt 
    703  1.1.2.2     matt 	if (bus_space_map(sc->sc_memt, arg->hpet_reg, HPET_WINDOW_SIZE, 0,
    704  1.1.2.2     matt 			  &sc->sc_memh)) {
    705  1.1.2.3     matt 		aprint_error_dev(self,
    706  1.1.2.3     matt 		    "HPET memory window could not be mapped");
    707  1.1.2.2     matt 		return;
    708  1.1.2.2     matt 	}
    709  1.1.2.2     matt 
    710  1.1.2.3     matt 	hpet_attach_subr(self);
    711  1.1.2.2     matt }
    712  1.1.2.2     matt 
    713  1.1.2.3     matt CFATTACH_DECL_NEW(ichlpcib_hpet, sizeof(struct hpet_softc), lpcib_hpet_match,
    714  1.1.2.2     matt     lpcib_hpet_attach, NULL, NULL);
    715  1.1.2.2     matt 
    716  1.1.2.2     matt static void
    717  1.1.2.3     matt lpcib_hpet_configure(device_t self)
    718  1.1.2.2     matt {
    719  1.1.2.3     matt 	struct lpcib_softc *sc = device_private(self);
    720  1.1.2.2     matt 	struct lpcib_hpet_attach_arg arg;
    721  1.1.2.2     matt 	uint32_t hpet_reg, val;
    722  1.1.2.2     matt 
    723  1.1.2.2     matt 	if (sc->sc_has_ich5_hpet) {
    724  1.1.2.3     matt 		val = pci_conf_read(sc->sc_pc, sc->sc_pcitag,
    725  1.1.2.3     matt 		    LPCIB_PCI_GEN_CNTL);
    726  1.1.2.2     matt 		switch (val & LPCIB_ICH5_HPTC_WIN_MASK) {
    727  1.1.2.2     matt 		case LPCIB_ICH5_HPTC_0000:
    728  1.1.2.2     matt 			hpet_reg = LPCIB_ICH5_HPTC_0000_BASE;
    729  1.1.2.2     matt 			break;
    730  1.1.2.2     matt 		case LPCIB_ICH5_HPTC_1000:
    731  1.1.2.2     matt 			hpet_reg = LPCIB_ICH5_HPTC_1000_BASE;
    732  1.1.2.2     matt 			break;
    733  1.1.2.2     matt 		case LPCIB_ICH5_HPTC_2000:
    734  1.1.2.2     matt 			hpet_reg = LPCIB_ICH5_HPTC_2000_BASE;
    735  1.1.2.2     matt 			break;
    736  1.1.2.2     matt 		case LPCIB_ICH5_HPTC_3000:
    737  1.1.2.2     matt 			hpet_reg = LPCIB_ICH5_HPTC_3000_BASE;
    738  1.1.2.2     matt 			break;
    739  1.1.2.2     matt 		default:
    740  1.1.2.2     matt 			return;
    741  1.1.2.2     matt 		}
    742  1.1.2.2     matt 		val |= sc->sc_hpet_reg | LPCIB_ICH5_HPTC_EN;
    743  1.1.2.3     matt 		pci_conf_write(sc->sc_pc, sc->sc_pcitag,
    744  1.1.2.3     matt 		    LPCIB_PCI_GEN_CNTL, val);
    745  1.1.2.2     matt 	} else if (sc->sc_has_rcba) {
    746  1.1.2.2     matt 		val = bus_space_read_4(sc->sc_rcbat, sc->sc_rcbah,
    747  1.1.2.2     matt 		    LPCIB_RCBA_HPTC);
    748  1.1.2.2     matt 		switch (val & LPCIB_RCBA_HPTC_WIN_MASK) {
    749  1.1.2.2     matt 		case LPCIB_RCBA_HPTC_0000:
    750  1.1.2.2     matt 			hpet_reg = LPCIB_RCBA_HPTC_0000_BASE;
    751  1.1.2.2     matt 			break;
    752  1.1.2.2     matt 		case LPCIB_RCBA_HPTC_1000:
    753  1.1.2.2     matt 			hpet_reg = LPCIB_RCBA_HPTC_1000_BASE;
    754  1.1.2.2     matt 			break;
    755  1.1.2.2     matt 		case LPCIB_RCBA_HPTC_2000:
    756  1.1.2.2     matt 			hpet_reg = LPCIB_RCBA_HPTC_2000_BASE;
    757  1.1.2.2     matt 			break;
    758  1.1.2.2     matt 		case LPCIB_RCBA_HPTC_3000:
    759  1.1.2.2     matt 			hpet_reg = LPCIB_RCBA_HPTC_3000_BASE;
    760  1.1.2.2     matt 			break;
    761  1.1.2.2     matt 		default:
    762  1.1.2.2     matt 			return;
    763  1.1.2.2     matt 		}
    764  1.1.2.2     matt 		val |= LPCIB_RCBA_HPTC_EN;
    765  1.1.2.2     matt 		bus_space_write_4(sc->sc_rcbat, sc->sc_rcbah, LPCIB_RCBA_HPTC,
    766  1.1.2.2     matt 		    val);
    767  1.1.2.2     matt 	} else {
    768  1.1.2.2     matt 		/* No HPET here */
    769  1.1.2.2     matt 		return;
    770  1.1.2.2     matt 	}
    771  1.1.2.2     matt 
    772  1.1.2.2     matt 	arg.hpet_mem_t = sc->sc_pa.pa_memt;
    773  1.1.2.2     matt 	arg.hpet_reg = hpet_reg;
    774  1.1.2.2     matt 
    775  1.1.2.3     matt 	config_found_ia(self, "hpetichbus", &arg, NULL);
    776  1.1.2.2     matt }
    777  1.1.2.2     matt #endif
    778