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