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