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