ichlpcib.c revision 1.4.4.3 1 1.4.4.3 yamt /* $NetBSD: ichlpcib.c,v 1.4.4.3 2007/12/07 17:26:57 yamt Exp $ */
2 1.4.4.2 yamt
3 1.4.4.2 yamt /*-
4 1.4.4.2 yamt * Copyright (c) 2004 The NetBSD Foundation, Inc.
5 1.4.4.2 yamt * All rights reserved.
6 1.4.4.2 yamt *
7 1.4.4.2 yamt * This code is derived from software contributed to The NetBSD Foundation
8 1.4.4.2 yamt * by Minoura Makoto and Matthew R. Green.
9 1.4.4.2 yamt *
10 1.4.4.2 yamt * Redistribution and use in source and binary forms, with or without
11 1.4.4.2 yamt * modification, are permitted provided that the following conditions
12 1.4.4.2 yamt * are met:
13 1.4.4.2 yamt * 1. Redistributions of source code must retain the above copyright
14 1.4.4.2 yamt * notice, this list of conditions and the following disclaimer.
15 1.4.4.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
16 1.4.4.2 yamt * notice, this list of conditions and the following disclaimer in the
17 1.4.4.2 yamt * documentation and/or other materials provided with the distribution.
18 1.4.4.2 yamt * 3. All advertising materials mentioning features or use of this software
19 1.4.4.2 yamt * must display the following acknowledgement:
20 1.4.4.2 yamt * This product includes software developed by the NetBSD
21 1.4.4.2 yamt * Foundation, Inc. and its contributors.
22 1.4.4.2 yamt * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.4.4.2 yamt * contributors may be used to endorse or promote products derived
24 1.4.4.2 yamt * from this software without specific prior written permission.
25 1.4.4.2 yamt *
26 1.4.4.2 yamt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.4.4.2 yamt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.4.4.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.4.4.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.4.4.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.4.4.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.4.4.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.4.4.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.4.4.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.4.4.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.4.4.2 yamt * POSSIBILITY OF SUCH DAMAGE.
37 1.4.4.2 yamt */
38 1.4.4.2 yamt
39 1.4.4.2 yamt /*
40 1.4.4.2 yamt * Intel I/O Controller Hub (ICHn) LPC Interface Bridge driver
41 1.4.4.2 yamt *
42 1.4.4.2 yamt * LPC Interface Bridge is basically a pcib (PCI-ISA Bridge), but has
43 1.4.4.2 yamt * some power management and monitoring functions.
44 1.4.4.2 yamt * Currently we support the watchdog timer, SpeedStep (on some systems)
45 1.4.4.2 yamt * and the power management timer.
46 1.4.4.2 yamt */
47 1.4.4.2 yamt
48 1.4.4.2 yamt #include <sys/cdefs.h>
49 1.4.4.3 yamt __KERNEL_RCSID(0, "$NetBSD: ichlpcib.c,v 1.4.4.3 2007/12/07 17:26:57 yamt Exp $");
50 1.4.4.2 yamt
51 1.4.4.2 yamt #include <sys/types.h>
52 1.4.4.2 yamt #include <sys/param.h>
53 1.4.4.2 yamt #include <sys/systm.h>
54 1.4.4.2 yamt #include <sys/device.h>
55 1.4.4.2 yamt #include <sys/sysctl.h>
56 1.4.4.2 yamt #include <machine/bus.h>
57 1.4.4.2 yamt
58 1.4.4.2 yamt #include <dev/pci/pcivar.h>
59 1.4.4.2 yamt #include <dev/pci/pcireg.h>
60 1.4.4.2 yamt #include <dev/pci/pcidevs.h>
61 1.4.4.2 yamt
62 1.4.4.2 yamt #include <dev/sysmon/sysmonvar.h>
63 1.4.4.2 yamt
64 1.4.4.2 yamt #include <dev/ic/i82801lpcreg.h>
65 1.4.4.2 yamt #include <dev/ic/acpipmtimer.h>
66 1.4.4.2 yamt
67 1.4.4.2 yamt struct lpcib_softc {
68 1.4.4.2 yamt /* Device object. */
69 1.4.4.2 yamt struct device sc_dev;
70 1.4.4.2 yamt
71 1.4.4.2 yamt pci_chipset_tag_t sc_pc;
72 1.4.4.2 yamt pcitag_t sc_pcitag;
73 1.4.4.2 yamt
74 1.4.4.2 yamt /* Watchdog variables. */
75 1.4.4.2 yamt struct sysmon_wdog sc_smw;
76 1.4.4.2 yamt bus_space_tag_t sc_iot;
77 1.4.4.2 yamt bus_space_handle_t sc_ioh;
78 1.4.4.2 yamt
79 1.4.4.2 yamt /* Power management */
80 1.4.4.2 yamt void *sc_powerhook;
81 1.4.4.2 yamt struct pci_conf_state sc_pciconf;
82 1.4.4.2 yamt pcireg_t sc_pirq[8];
83 1.4.4.2 yamt };
84 1.4.4.2 yamt
85 1.4.4.2 yamt static int lpcibmatch(struct device *, struct cfdata *, void *);
86 1.4.4.2 yamt static void lpcibattach(struct device *, struct device *, void *);
87 1.4.4.2 yamt static void lpcib_powerhook(int, void *);
88 1.4.4.2 yamt
89 1.4.4.2 yamt static void pmtimer_configure(struct lpcib_softc *, struct pci_attach_args *);
90 1.4.4.2 yamt
91 1.4.4.2 yamt static void tcotimer_configure(struct lpcib_softc *, struct pci_attach_args *);
92 1.4.4.2 yamt static int tcotimer_setmode(struct sysmon_wdog *);
93 1.4.4.2 yamt static int tcotimer_tickle(struct sysmon_wdog *);
94 1.4.4.2 yamt static void tcotimer_stop(struct lpcib_softc *);
95 1.4.4.2 yamt static void tcotimer_start(struct lpcib_softc *);
96 1.4.4.2 yamt static void tcotimer_status_reset(struct lpcib_softc *);
97 1.4.4.2 yamt static int tcotimer_disable_noreboot(struct lpcib_softc *, bus_space_tag_t,
98 1.4.4.2 yamt bus_space_handle_t);
99 1.4.4.2 yamt
100 1.4.4.2 yamt static void speedstep_configure(struct lpcib_softc *, struct pci_attach_args *);
101 1.4.4.2 yamt static int speedstep_sysctl_helper(SYSCTLFN_ARGS);
102 1.4.4.2 yamt
103 1.4.4.2 yamt struct lpcib_softc *speedstep_cookie; /* XXX */
104 1.4.4.2 yamt static int lpcib_ich6 = 0;
105 1.4.4.2 yamt
106 1.4.4.2 yamt /* Defined in arch/.../pci/pcib.c. */
107 1.4.4.2 yamt extern void pcibattach(struct device *, struct device *, void *);
108 1.4.4.2 yamt
109 1.4.4.2 yamt CFATTACH_DECL(ichlpcib, sizeof(struct lpcib_softc),
110 1.4.4.2 yamt lpcibmatch, lpcibattach, NULL, NULL);
111 1.4.4.2 yamt
112 1.4.4.2 yamt /*
113 1.4.4.2 yamt * Autoconf callbacks.
114 1.4.4.2 yamt */
115 1.4.4.2 yamt static int
116 1.4.4.2 yamt lpcibmatch(struct device *parent, struct cfdata *match, void *aux)
117 1.4.4.2 yamt {
118 1.4.4.2 yamt struct pci_attach_args *pa = aux;
119 1.4.4.2 yamt
120 1.4.4.2 yamt /* We are ISA bridge, of course */
121 1.4.4.2 yamt if (PCI_CLASS(pa->pa_class) != PCI_CLASS_BRIDGE ||
122 1.4.4.2 yamt PCI_SUBCLASS(pa->pa_class) != PCI_SUBCLASS_BRIDGE_ISA)
123 1.4.4.2 yamt return 0;
124 1.4.4.2 yamt
125 1.4.4.2 yamt /* Matches only Intel ICH */
126 1.4.4.2 yamt if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL) {
127 1.4.4.2 yamt switch (PCI_PRODUCT(pa->pa_id)) {
128 1.4.4.2 yamt case PCI_PRODUCT_INTEL_82801AA_LPC: /* ICH */
129 1.4.4.2 yamt case PCI_PRODUCT_INTEL_82801AB_LPC: /* ICH0 */
130 1.4.4.2 yamt case PCI_PRODUCT_INTEL_82801BA_LPC: /* ICH2 */
131 1.4.4.2 yamt case PCI_PRODUCT_INTEL_82801BAM_LPC: /* ICH2-M */
132 1.4.4.2 yamt case PCI_PRODUCT_INTEL_82801CA_LPC: /* ICH3-S */
133 1.4.4.2 yamt case PCI_PRODUCT_INTEL_82801CAM_LPC: /* ICH3-M */
134 1.4.4.2 yamt case PCI_PRODUCT_INTEL_82801DB_LPC: /* ICH4 */
135 1.4.4.2 yamt case PCI_PRODUCT_INTEL_82801DB_ISA: /* ICH4-M */
136 1.4.4.2 yamt case PCI_PRODUCT_INTEL_82801EB_LPC: /* ICH5 */
137 1.4.4.2 yamt return 10;
138 1.4.4.2 yamt case PCI_PRODUCT_INTEL_82801FB_LPC: /* ICH6 */
139 1.4.4.2 yamt case PCI_PRODUCT_INTEL_82801FBM_LPC: /* ICH6-M */
140 1.4.4.2 yamt case PCI_PRODUCT_INTEL_82801G_LPC: /* ICH7 */
141 1.4.4.2 yamt case PCI_PRODUCT_INTEL_82801GBM_LPC: /* ICH7-M */
142 1.4.4.2 yamt case PCI_PRODUCT_INTEL_82801GHM_LPC: /* ICH7-M DH */
143 1.4.4.2 yamt case PCI_PRODUCT_INTEL_82801H_LPC: /* ICH8 */
144 1.4.4.2 yamt case PCI_PRODUCT_INTEL_82801HH_LPC: /* ICH8 DH */
145 1.4.4.2 yamt case PCI_PRODUCT_INTEL_82801HO_LPC: /* ICH8 DO */
146 1.4.4.2 yamt case PCI_PRODUCT_INTEL_82801HBM_LPC: /* iCH8-M */
147 1.4.4.2 yamt case PCI_PRODUCT_INTEL_82801IH_LPC: /* ICH9 */
148 1.4.4.2 yamt case PCI_PRODUCT_INTEL_82801IR_LPC: /* ICH9-R */
149 1.4.4.2 yamt case PCI_PRODUCT_INTEL_82801IB_LPC: /* ICH9 ? */
150 1.4.4.2 yamt lpcib_ich6 = 1;
151 1.4.4.2 yamt return 10; /* prior to pcib */
152 1.4.4.2 yamt }
153 1.4.4.2 yamt }
154 1.4.4.2 yamt
155 1.4.4.2 yamt return 0;
156 1.4.4.2 yamt }
157 1.4.4.2 yamt
158 1.4.4.2 yamt static void
159 1.4.4.2 yamt lpcibattach(struct device *parent, struct device *self, void *aux)
160 1.4.4.2 yamt {
161 1.4.4.2 yamt struct pci_attach_args *pa = aux;
162 1.4.4.2 yamt struct lpcib_softc *sc = (void*) self;
163 1.4.4.2 yamt
164 1.4.4.2 yamt sc->sc_pc = pa->pa_pc;
165 1.4.4.2 yamt sc->sc_pcitag = pa->pa_tag;
166 1.4.4.2 yamt
167 1.4.4.2 yamt pcibattach(parent, self, aux);
168 1.4.4.2 yamt
169 1.4.4.2 yamt /*
170 1.4.4.2 yamt * Part of our I/O registers are used as ACPI PM regs.
171 1.4.4.2 yamt * Since our ACPI subsystem accesses the I/O space directly so far,
172 1.4.4.2 yamt * we do not have to bother bus_space I/O map confliction.
173 1.4.4.2 yamt */
174 1.4.4.2 yamt if (pci_mapreg_map(pa, LPCIB_PCI_PMBASE, PCI_MAPREG_TYPE_IO, 0,
175 1.4.4.2 yamt &sc->sc_iot, &sc->sc_ioh, NULL, NULL)) {
176 1.4.4.2 yamt aprint_error("%s: can't map power management i/o space",
177 1.4.4.2 yamt sc->sc_dev.dv_xname);
178 1.4.4.2 yamt return;
179 1.4.4.2 yamt }
180 1.4.4.2 yamt
181 1.4.4.2 yamt /* Set up the power management timer. */
182 1.4.4.2 yamt pmtimer_configure(sc, pa);
183 1.4.4.2 yamt
184 1.4.4.2 yamt /* Set up the TCO (watchdog). */
185 1.4.4.2 yamt tcotimer_configure(sc, pa);
186 1.4.4.2 yamt
187 1.4.4.2 yamt /* Set up SpeedStep. */
188 1.4.4.2 yamt speedstep_configure(sc, pa);
189 1.4.4.2 yamt
190 1.4.4.2 yamt /* Install powerhook */
191 1.4.4.2 yamt sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
192 1.4.4.2 yamt lpcib_powerhook, sc);
193 1.4.4.2 yamt if (sc->sc_powerhook == NULL)
194 1.4.4.2 yamt aprint_error("%s: can't establish powerhook\n",
195 1.4.4.2 yamt sc->sc_dev.dv_xname);
196 1.4.4.2 yamt }
197 1.4.4.2 yamt
198 1.4.4.2 yamt static void
199 1.4.4.2 yamt lpcib_powerhook(int why, void *opaque)
200 1.4.4.2 yamt {
201 1.4.4.2 yamt struct lpcib_softc *sc;
202 1.4.4.2 yamt pci_chipset_tag_t pc;
203 1.4.4.2 yamt pcitag_t tag;
204 1.4.4.2 yamt
205 1.4.4.2 yamt sc = (struct lpcib_softc *)opaque;
206 1.4.4.2 yamt pc = sc->sc_pc;
207 1.4.4.2 yamt tag = sc->sc_pcitag;
208 1.4.4.2 yamt
209 1.4.4.2 yamt switch (why) {
210 1.4.4.2 yamt case PWR_SUSPEND:
211 1.4.4.2 yamt pci_conf_capture(pc, tag, &sc->sc_pciconf);
212 1.4.4.2 yamt
213 1.4.4.2 yamt /* capture PIRQ routing control registers */
214 1.4.4.2 yamt sc->sc_pirq[0] = pci_conf_read(pc, tag, LPCIB_PCI_PIRQA_ROUT);
215 1.4.4.2 yamt sc->sc_pirq[1] = pci_conf_read(pc, tag, LPCIB_PCI_PIRQB_ROUT);
216 1.4.4.2 yamt sc->sc_pirq[2] = pci_conf_read(pc, tag, LPCIB_PCI_PIRQC_ROUT);
217 1.4.4.2 yamt sc->sc_pirq[3] = pci_conf_read(pc, tag, LPCIB_PCI_PIRQD_ROUT);
218 1.4.4.2 yamt sc->sc_pirq[4] = pci_conf_read(pc, tag, LPCIB_PCI_PIRQE_ROUT);
219 1.4.4.2 yamt sc->sc_pirq[5] = pci_conf_read(pc, tag, LPCIB_PCI_PIRQF_ROUT);
220 1.4.4.2 yamt sc->sc_pirq[6] = pci_conf_read(pc, tag, LPCIB_PCI_PIRQG_ROUT);
221 1.4.4.2 yamt sc->sc_pirq[7] = pci_conf_read(pc, tag, LPCIB_PCI_PIRQH_ROUT);
222 1.4.4.2 yamt
223 1.4.4.2 yamt break;
224 1.4.4.2 yamt
225 1.4.4.2 yamt case PWR_RESUME:
226 1.4.4.2 yamt pci_conf_restore(pc, tag, &sc->sc_pciconf);
227 1.4.4.2 yamt
228 1.4.4.2 yamt /* restore PIRQ routing control registers */
229 1.4.4.2 yamt pci_conf_write(pc, tag, LPCIB_PCI_PIRQA_ROUT, sc->sc_pirq[0]);
230 1.4.4.2 yamt pci_conf_write(pc, tag, LPCIB_PCI_PIRQB_ROUT, sc->sc_pirq[1]);
231 1.4.4.2 yamt pci_conf_write(pc, tag, LPCIB_PCI_PIRQC_ROUT, sc->sc_pirq[2]);
232 1.4.4.2 yamt pci_conf_write(pc, tag, LPCIB_PCI_PIRQD_ROUT, sc->sc_pirq[3]);
233 1.4.4.2 yamt pci_conf_write(pc, tag, LPCIB_PCI_PIRQE_ROUT, sc->sc_pirq[4]);
234 1.4.4.2 yamt pci_conf_write(pc, tag, LPCIB_PCI_PIRQF_ROUT, sc->sc_pirq[5]);
235 1.4.4.2 yamt pci_conf_write(pc, tag, LPCIB_PCI_PIRQG_ROUT, sc->sc_pirq[6]);
236 1.4.4.2 yamt pci_conf_write(pc, tag, LPCIB_PCI_PIRQH_ROUT, sc->sc_pirq[7]);
237 1.4.4.2 yamt
238 1.4.4.2 yamt break;
239 1.4.4.2 yamt }
240 1.4.4.2 yamt }
241 1.4.4.2 yamt
242 1.4.4.2 yamt /*
243 1.4.4.2 yamt * Initialize the power management timer.
244 1.4.4.2 yamt */
245 1.4.4.2 yamt static void
246 1.4.4.2 yamt pmtimer_configure(struct lpcib_softc *sc, struct pci_attach_args *pa)
247 1.4.4.2 yamt {
248 1.4.4.2 yamt pcireg_t control;
249 1.4.4.2 yamt
250 1.4.4.2 yamt /*
251 1.4.4.2 yamt * Check if power management I/O space is enabled and enable the ACPI_EN
252 1.4.4.2 yamt * bit if it's disabled.
253 1.4.4.2 yamt */
254 1.4.4.2 yamt control = pci_conf_read(pa->pa_pc, pa->pa_tag, LPCIB_PCI_ACPI_CNTL);
255 1.4.4.2 yamt if ((control & LPCIB_PCI_ACPI_CNTL_EN) == 0) {
256 1.4.4.2 yamt control |= LPCIB_PCI_ACPI_CNTL_EN;
257 1.4.4.2 yamt pci_conf_write(pa->pa_pc, pa->pa_tag, LPCIB_PCI_ACPI_CNTL,
258 1.4.4.2 yamt control);
259 1.4.4.2 yamt }
260 1.4.4.2 yamt
261 1.4.4.2 yamt /* Attach our PM timer with the generic acpipmtimer function */
262 1.4.4.2 yamt acpipmtimer_attach(&sc->sc_dev, sc->sc_iot, sc->sc_ioh,
263 1.4.4.2 yamt LPCIB_PM1_TMR, 0);
264 1.4.4.2 yamt }
265 1.4.4.2 yamt
266 1.4.4.2 yamt /*
267 1.4.4.2 yamt * Initialize the watchdog timer.
268 1.4.4.2 yamt */
269 1.4.4.2 yamt static void
270 1.4.4.2 yamt tcotimer_configure(struct lpcib_softc *sc, struct pci_attach_args *pa)
271 1.4.4.2 yamt {
272 1.4.4.2 yamt bus_space_handle_t gcs_memh;
273 1.4.4.2 yamt pcireg_t pcireg;
274 1.4.4.2 yamt uint32_t ioreg;
275 1.4.4.2 yamt unsigned int period;
276 1.4.4.2 yamt
277 1.4.4.2 yamt /*
278 1.4.4.2 yamt * Map the memory space necessary for GCS (General Control
279 1.4.4.2 yamt * and Status Register). This is where the No Reboot (NR) bit
280 1.4.4.2 yamt * lives on ICH6 and newer.
281 1.4.4.2 yamt */
282 1.4.4.2 yamt if (lpcib_ich6) {
283 1.4.4.2 yamt pcireg = pci_conf_read(pa->pa_pc, pa->pa_tag, LPCIB_RCBA);
284 1.4.4.2 yamt pcireg &= 0xffffc000;
285 1.4.4.2 yamt if (bus_space_map(pa->pa_memt, pcireg + LPCIB_GCS_OFFSET,
286 1.4.4.2 yamt LPCIB_GCS_SIZE, 0, &gcs_memh)) {
287 1.4.4.2 yamt aprint_error("%s: can't map GCS memory space; "
288 1.4.4.2 yamt "TCO timer disabled\n", sc->sc_dev.dv_xname);
289 1.4.4.2 yamt return;
290 1.4.4.2 yamt }
291 1.4.4.2 yamt }
292 1.4.4.2 yamt
293 1.4.4.2 yamt /*
294 1.4.4.2 yamt * Clear the No Reboot (NR) bit. If this fails, enabling the TCO_EN bit
295 1.4.4.2 yamt * in the SMI_EN register is the last chance.
296 1.4.4.2 yamt */
297 1.4.4.2 yamt if (tcotimer_disable_noreboot(sc, pa->pa_memt, gcs_memh)) {
298 1.4.4.2 yamt ioreg = bus_space_read_4(sc->sc_iot, sc->sc_ioh, LPCIB_SMI_EN);
299 1.4.4.2 yamt ioreg |= LPCIB_SMI_EN_TCO_EN;
300 1.4.4.2 yamt bus_space_write_4(sc->sc_iot, sc->sc_ioh, LPCIB_SMI_EN, ioreg);
301 1.4.4.2 yamt }
302 1.4.4.2 yamt
303 1.4.4.2 yamt /* Reset the watchdog status registers. */
304 1.4.4.2 yamt tcotimer_status_reset(sc);
305 1.4.4.2 yamt
306 1.4.4.2 yamt /* Explicitly stop the TCO timer. */
307 1.4.4.2 yamt tcotimer_stop(sc);
308 1.4.4.2 yamt
309 1.4.4.2 yamt /*
310 1.4.4.2 yamt * Register the driver with the sysmon watchdog framework.
311 1.4.4.2 yamt */
312 1.4.4.2 yamt sc->sc_smw.smw_name = sc->sc_dev.dv_xname;
313 1.4.4.2 yamt sc->sc_smw.smw_cookie = sc;
314 1.4.4.2 yamt sc->sc_smw.smw_setmode = tcotimer_setmode;
315 1.4.4.2 yamt sc->sc_smw.smw_tickle = tcotimer_tickle;
316 1.4.4.2 yamt if (lpcib_ich6)
317 1.4.4.2 yamt period = LPCIB_TCOTIMER2_MAX_TICK;
318 1.4.4.2 yamt else
319 1.4.4.2 yamt period = LPCIB_TCOTIMER_MAX_TICK;
320 1.4.4.2 yamt sc->sc_smw.smw_period = lpcib_tcotimer_tick_to_second(period);
321 1.4.4.2 yamt
322 1.4.4.2 yamt if (sysmon_wdog_register(&sc->sc_smw)) {
323 1.4.4.2 yamt aprint_error("%s: unable to register TCO timer"
324 1.4.4.2 yamt "as a sysmon watchdog device.\n",
325 1.4.4.2 yamt sc->sc_dev.dv_xname);
326 1.4.4.2 yamt return;
327 1.4.4.2 yamt }
328 1.4.4.2 yamt
329 1.4.4.2 yamt aprint_verbose("%s: TCO (watchdog) timer configured.\n",
330 1.4.4.2 yamt sc->sc_dev.dv_xname);
331 1.4.4.2 yamt }
332 1.4.4.2 yamt
333 1.4.4.2 yamt /*
334 1.4.4.2 yamt * Sysmon watchdog callbacks.
335 1.4.4.2 yamt */
336 1.4.4.2 yamt static int
337 1.4.4.2 yamt tcotimer_setmode(struct sysmon_wdog *smw)
338 1.4.4.2 yamt {
339 1.4.4.2 yamt struct lpcib_softc *sc = smw->smw_cookie;
340 1.4.4.2 yamt unsigned int period;
341 1.4.4.2 yamt uint16_t ich6period = 0;
342 1.4.4.2 yamt
343 1.4.4.2 yamt if ((smw->smw_mode & WDOG_MODE_MASK) == WDOG_MODE_DISARMED) {
344 1.4.4.2 yamt /* Stop the TCO timer. */
345 1.4.4.2 yamt tcotimer_stop(sc);
346 1.4.4.2 yamt } else {
347 1.4.4.2 yamt /*
348 1.4.4.2 yamt * ICH5 or older are limited to 4s min and 39s max.
349 1.4.4.2 yamt * ICH6 or newer are limited to 2s min and 613s max.
350 1.4.4.2 yamt */
351 1.4.4.2 yamt if (!lpcib_ich6) {
352 1.4.4.3 yamt if (smw->smw_period < LPCIB_TCOTIMER_MIN_TICK ||
353 1.4.4.3 yamt smw->smw_period > LPCIB_TCOTIMER_MAX_TICK)
354 1.4.4.2 yamt return EINVAL;
355 1.4.4.2 yamt } else {
356 1.4.4.3 yamt if (smw->smw_period < LPCIB_TCOTIMER2_MIN_TICK ||
357 1.4.4.3 yamt smw->smw_period > LPCIB_TCOTIMER2_MAX_TICK)
358 1.4.4.2 yamt return EINVAL;
359 1.4.4.2 yamt }
360 1.4.4.3 yamt period = lpcib_tcotimer_second_to_tick(smw->smw_period);
361 1.4.4.3 yamt
362 1.4.4.2 yamt /* Stop the TCO timer, */
363 1.4.4.2 yamt tcotimer_stop(sc);
364 1.4.4.2 yamt
365 1.4.4.2 yamt /* set the timeout, */
366 1.4.4.2 yamt if (lpcib_ich6) {
367 1.4.4.2 yamt /* ICH6 or newer */
368 1.4.4.2 yamt ich6period = bus_space_read_2(sc->sc_iot, sc->sc_ioh,
369 1.4.4.2 yamt LPCIB_TCO_TMR2);
370 1.4.4.2 yamt ich6period &= 0xfc00;
371 1.4.4.2 yamt bus_space_write_2(sc->sc_iot, sc->sc_ioh,
372 1.4.4.2 yamt LPCIB_TCO_TMR2, ich6period | period);
373 1.4.4.2 yamt } else {
374 1.4.4.2 yamt /* ICH5 or older */
375 1.4.4.2 yamt period |= bus_space_read_1(sc->sc_iot, sc->sc_ioh,
376 1.4.4.2 yamt LPCIB_TCO_TMR);
377 1.4.4.2 yamt period &= 0xc0;
378 1.4.4.2 yamt bus_space_write_1(sc->sc_iot, sc->sc_ioh,
379 1.4.4.2 yamt LPCIB_TCO_TMR, period);
380 1.4.4.2 yamt }
381 1.4.4.2 yamt
382 1.4.4.2 yamt /* and start/reload the timer. */
383 1.4.4.2 yamt tcotimer_start(sc);
384 1.4.4.2 yamt tcotimer_tickle(smw);
385 1.4.4.2 yamt }
386 1.4.4.2 yamt
387 1.4.4.2 yamt return 0;
388 1.4.4.2 yamt }
389 1.4.4.2 yamt
390 1.4.4.2 yamt static int
391 1.4.4.2 yamt tcotimer_tickle(struct sysmon_wdog *smw)
392 1.4.4.2 yamt {
393 1.4.4.2 yamt struct lpcib_softc *sc = smw->smw_cookie;
394 1.4.4.2 yamt
395 1.4.4.2 yamt /* any value is allowed */
396 1.4.4.2 yamt if (!lpcib_ich6)
397 1.4.4.2 yamt bus_space_write_1(sc->sc_iot, sc->sc_ioh, LPCIB_TCO_RLD, 1);
398 1.4.4.2 yamt else
399 1.4.4.2 yamt bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO_RLD, 1);
400 1.4.4.2 yamt
401 1.4.4.2 yamt return 0;
402 1.4.4.2 yamt }
403 1.4.4.2 yamt
404 1.4.4.2 yamt static void
405 1.4.4.2 yamt tcotimer_stop(struct lpcib_softc *sc)
406 1.4.4.2 yamt {
407 1.4.4.2 yamt uint16_t ioreg;
408 1.4.4.2 yamt
409 1.4.4.2 yamt ioreg = bus_space_read_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_CNT);
410 1.4.4.2 yamt ioreg |= LPCIB_TCO1_CNT_TCO_TMR_HLT;
411 1.4.4.2 yamt bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_CNT, ioreg);
412 1.4.4.2 yamt }
413 1.4.4.2 yamt
414 1.4.4.2 yamt static void
415 1.4.4.2 yamt tcotimer_start(struct lpcib_softc *sc)
416 1.4.4.2 yamt {
417 1.4.4.2 yamt uint16_t ioreg;
418 1.4.4.2 yamt
419 1.4.4.2 yamt ioreg = bus_space_read_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_CNT);
420 1.4.4.2 yamt ioreg &= ~LPCIB_TCO1_CNT_TCO_TMR_HLT;
421 1.4.4.2 yamt bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_CNT, ioreg);
422 1.4.4.2 yamt }
423 1.4.4.2 yamt
424 1.4.4.2 yamt static void
425 1.4.4.2 yamt tcotimer_status_reset(struct lpcib_softc *sc)
426 1.4.4.2 yamt {
427 1.4.4.2 yamt bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_STS,
428 1.4.4.2 yamt LPCIB_TCO1_STS_TIMEOUT);
429 1.4.4.2 yamt bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO2_STS,
430 1.4.4.2 yamt LPCIB_TCO2_STS_BOOT_STS);
431 1.4.4.2 yamt bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO2_STS,
432 1.4.4.2 yamt LPCIB_TCO2_STS_SECONDS_TO_STS);
433 1.4.4.2 yamt }
434 1.4.4.2 yamt
435 1.4.4.2 yamt /*
436 1.4.4.2 yamt * Clear the No Reboot (NR) bit, this enables reboots when the timer
437 1.4.4.2 yamt * reaches the timeout for the second time.
438 1.4.4.2 yamt */
439 1.4.4.2 yamt static int
440 1.4.4.2 yamt tcotimer_disable_noreboot(struct lpcib_softc *sc, bus_space_tag_t gcs_memt,
441 1.4.4.2 yamt bus_space_handle_t gcs_memh)
442 1.4.4.2 yamt {
443 1.4.4.2 yamt pcireg_t pcireg;
444 1.4.4.2 yamt uint16_t status = 0;
445 1.4.4.2 yamt
446 1.4.4.2 yamt if (!lpcib_ich6) {
447 1.4.4.2 yamt pcireg = pci_conf_read(sc->sc_pc, sc->sc_pcitag,
448 1.4.4.2 yamt LPCIB_PCI_GEN_STA);
449 1.4.4.2 yamt if (pcireg & LPCIB_PCI_GEN_STA_NO_REBOOT) {
450 1.4.4.2 yamt /* TCO timeout reset is disabled; try to enable it */
451 1.4.4.2 yamt pcireg &= ~LPCIB_PCI_GEN_STA_NO_REBOOT;
452 1.4.4.2 yamt pci_conf_write(sc->sc_pc, sc->sc_pcitag,
453 1.4.4.2 yamt LPCIB_PCI_GEN_STA, pcireg);
454 1.4.4.2 yamt if (pcireg & LPCIB_PCI_GEN_STA_NO_REBOOT)
455 1.4.4.2 yamt goto error;
456 1.4.4.2 yamt }
457 1.4.4.2 yamt } else {
458 1.4.4.2 yamt status = bus_space_read_4(gcs_memt, gcs_memh, 0);
459 1.4.4.2 yamt status &= ~LPCIB_GCS_NO_REBOOT;
460 1.4.4.2 yamt bus_space_write_4(gcs_memt, gcs_memh, 0, status);
461 1.4.4.2 yamt status = bus_space_read_4(gcs_memt, gcs_memh, 0);
462 1.4.4.2 yamt bus_space_unmap(gcs_memt, gcs_memh, LPCIB_GCS_SIZE);
463 1.4.4.2 yamt if (status & LPCIB_GCS_NO_REBOOT)
464 1.4.4.2 yamt goto error;
465 1.4.4.2 yamt }
466 1.4.4.2 yamt
467 1.4.4.2 yamt return 0;
468 1.4.4.2 yamt error:
469 1.4.4.2 yamt aprint_error("%s: TCO timer reboot disabled by hardware; "
470 1.4.4.2 yamt "hope SMBIOS properly handles it.\n", sc->sc_dev.dv_xname);
471 1.4.4.2 yamt return EINVAL;
472 1.4.4.2 yamt }
473 1.4.4.2 yamt
474 1.4.4.2 yamt
475 1.4.4.2 yamt /*
476 1.4.4.2 yamt * Intel ICH SpeedStep support.
477 1.4.4.2 yamt */
478 1.4.4.2 yamt #define SS_READ(sc, reg) \
479 1.4.4.2 yamt bus_space_read_1((sc)->sc_iot, (sc)->sc_ioh, (reg))
480 1.4.4.2 yamt #define SS_WRITE(sc, reg, val) \
481 1.4.4.2 yamt bus_space_write_1((sc)->sc_iot, (sc)->sc_ioh, (reg), (val))
482 1.4.4.2 yamt
483 1.4.4.2 yamt /*
484 1.4.4.2 yamt * Linux driver says that SpeedStep on older chipsets cause
485 1.4.4.2 yamt * lockups on Dell Inspiron 8000 and 8100.
486 1.4.4.2 yamt */
487 1.4.4.2 yamt static int
488 1.4.4.2 yamt speedstep_bad_hb_check(struct pci_attach_args *pa)
489 1.4.4.2 yamt {
490 1.4.4.2 yamt
491 1.4.4.2 yamt if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82815_FULL_HUB &&
492 1.4.4.2 yamt PCI_REVISION(pa->pa_class) < 5)
493 1.4.4.2 yamt return 1;
494 1.4.4.2 yamt
495 1.4.4.2 yamt return 0;
496 1.4.4.2 yamt }
497 1.4.4.2 yamt
498 1.4.4.2 yamt static void
499 1.4.4.2 yamt speedstep_configure(struct lpcib_softc *sc, struct pci_attach_args *pa)
500 1.4.4.2 yamt {
501 1.4.4.2 yamt const struct sysctlnode *node, *ssnode;
502 1.4.4.2 yamt int rv;
503 1.4.4.2 yamt
504 1.4.4.2 yamt /* Supported on ICH2-M, ICH3-M and ICH4-M. */
505 1.4.4.2 yamt if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82801DB_ISA ||
506 1.4.4.2 yamt PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82801CAM_LPC ||
507 1.4.4.2 yamt (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82801BAM_LPC &&
508 1.4.4.2 yamt pci_find_device(pa, speedstep_bad_hb_check) == 0)) {
509 1.4.4.2 yamt uint8_t pmcon;
510 1.4.4.2 yamt
511 1.4.4.2 yamt /* Enable SpeedStep if it isn't already enabled. */
512 1.4.4.2 yamt pmcon = pci_conf_read(pa->pa_pc, pa->pa_tag,
513 1.4.4.2 yamt LPCIB_PCI_GEN_PMCON_1);
514 1.4.4.2 yamt if ((pmcon & LPCIB_PCI_GEN_PMCON_1_SS_EN) == 0)
515 1.4.4.2 yamt pci_conf_write(pa->pa_pc, pa->pa_tag,
516 1.4.4.2 yamt LPCIB_PCI_GEN_PMCON_1,
517 1.4.4.2 yamt pmcon | LPCIB_PCI_GEN_PMCON_1_SS_EN);
518 1.4.4.2 yamt
519 1.4.4.2 yamt /* Put in machdep.speedstep_state (0 for low, 1 for high). */
520 1.4.4.2 yamt if ((rv = sysctl_createv(NULL, 0, NULL, &node,
521 1.4.4.2 yamt CTLFLAG_PERMANENT, CTLTYPE_NODE, "machdep", NULL,
522 1.4.4.2 yamt NULL, 0, NULL, 0, CTL_MACHDEP, CTL_EOL)) != 0)
523 1.4.4.2 yamt goto err;
524 1.4.4.2 yamt
525 1.4.4.2 yamt /* CTLFLAG_ANYWRITE? kernel option like EST? */
526 1.4.4.2 yamt if ((rv = sysctl_createv(NULL, 0, &node, &ssnode,
527 1.4.4.2 yamt CTLFLAG_READWRITE, CTLTYPE_INT, "speedstep_state", NULL,
528 1.4.4.2 yamt speedstep_sysctl_helper, 0, NULL, 0, CTL_CREATE,
529 1.4.4.2 yamt CTL_EOL)) != 0)
530 1.4.4.2 yamt goto err;
531 1.4.4.2 yamt
532 1.4.4.2 yamt /* XXX save the sc for IO tag/handle */
533 1.4.4.2 yamt speedstep_cookie = sc;
534 1.4.4.2 yamt aprint_verbose("%s: SpeedStep enabled\n", sc->sc_dev.dv_xname);
535 1.4.4.2 yamt }
536 1.4.4.2 yamt
537 1.4.4.2 yamt return;
538 1.4.4.2 yamt
539 1.4.4.2 yamt err:
540 1.4.4.2 yamt aprint_normal("%s: sysctl_createv failed (rv = %d)\n", __func__, rv);
541 1.4.4.2 yamt }
542 1.4.4.2 yamt
543 1.4.4.2 yamt /*
544 1.4.4.2 yamt * get/set the SpeedStep state: 0 == low power, 1 == high power.
545 1.4.4.2 yamt */
546 1.4.4.2 yamt static int
547 1.4.4.2 yamt speedstep_sysctl_helper(SYSCTLFN_ARGS)
548 1.4.4.2 yamt {
549 1.4.4.2 yamt struct sysctlnode node;
550 1.4.4.2 yamt struct lpcib_softc *sc = speedstep_cookie;
551 1.4.4.2 yamt uint8_t state, state2;
552 1.4.4.2 yamt int ostate, nstate, s, error = 0;
553 1.4.4.2 yamt
554 1.4.4.2 yamt /*
555 1.4.4.2 yamt * We do the dance with spl's to avoid being at high ipl during
556 1.4.4.2 yamt * sysctl_lookup() which can both copyin and copyout.
557 1.4.4.2 yamt */
558 1.4.4.2 yamt s = splserial();
559 1.4.4.2 yamt state = SS_READ(sc, LPCIB_PM_SS_CNTL);
560 1.4.4.2 yamt splx(s);
561 1.4.4.2 yamt if ((state & LPCIB_PM_SS_STATE_LOW) == 0)
562 1.4.4.2 yamt ostate = 1;
563 1.4.4.2 yamt else
564 1.4.4.2 yamt ostate = 0;
565 1.4.4.2 yamt nstate = ostate;
566 1.4.4.2 yamt
567 1.4.4.2 yamt node = *rnode;
568 1.4.4.2 yamt node.sysctl_data = &nstate;
569 1.4.4.2 yamt
570 1.4.4.2 yamt error = sysctl_lookup(SYSCTLFN_CALL(&node));
571 1.4.4.2 yamt if (error || newp == NULL)
572 1.4.4.2 yamt goto out;
573 1.4.4.2 yamt
574 1.4.4.2 yamt /* Only two states are available */
575 1.4.4.2 yamt if (nstate != 0 && nstate != 1) {
576 1.4.4.2 yamt error = EINVAL;
577 1.4.4.2 yamt goto out;
578 1.4.4.2 yamt }
579 1.4.4.2 yamt
580 1.4.4.2 yamt s = splserial();
581 1.4.4.2 yamt state2 = SS_READ(sc, LPCIB_PM_SS_CNTL);
582 1.4.4.2 yamt if ((state2 & LPCIB_PM_SS_STATE_LOW) == 0)
583 1.4.4.2 yamt ostate = 1;
584 1.4.4.2 yamt else
585 1.4.4.2 yamt ostate = 0;
586 1.4.4.2 yamt
587 1.4.4.2 yamt if (ostate != nstate) {
588 1.4.4.2 yamt uint8_t cntl;
589 1.4.4.2 yamt
590 1.4.4.2 yamt if (nstate == 0)
591 1.4.4.2 yamt state2 |= LPCIB_PM_SS_STATE_LOW;
592 1.4.4.2 yamt else
593 1.4.4.2 yamt state2 &= ~LPCIB_PM_SS_STATE_LOW;
594 1.4.4.2 yamt
595 1.4.4.2 yamt /*
596 1.4.4.2 yamt * Must disable bus master arbitration during the change.
597 1.4.4.2 yamt */
598 1.4.4.2 yamt cntl = SS_READ(sc, LPCIB_PM_CTRL);
599 1.4.4.2 yamt SS_WRITE(sc, LPCIB_PM_CTRL, cntl | LPCIB_PM_SS_CNTL_ARB_DIS);
600 1.4.4.2 yamt SS_WRITE(sc, LPCIB_PM_SS_CNTL, state2);
601 1.4.4.2 yamt SS_WRITE(sc, LPCIB_PM_CTRL, cntl);
602 1.4.4.2 yamt }
603 1.4.4.2 yamt splx(s);
604 1.4.4.2 yamt out:
605 1.4.4.2 yamt return error;
606 1.4.4.2 yamt }
607