ppb.c revision 1.34.22.4 1 /* $NetBSD: ppb.c,v 1.34.22.4 2007/09/04 15:11:21 joerg Exp $ */
2
3 /*
4 * Copyright (c) 1996, 1998 Christopher G. Demetriou. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Christopher G. Demetriou
17 * for the NetBSD Project.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: ppb.c,v 1.34.22.4 2007/09/04 15:11:21 joerg Exp $");
35
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/device.h>
40
41 #include <dev/pci/pcireg.h>
42 #include <dev/pci/pcivar.h>
43 #include <dev/pci/ppbreg.h>
44 #include <dev/pci/pcidevs.h>
45
46 struct ppb_softc {
47 struct device sc_dev; /* generic device glue */
48 pci_chipset_tag_t sc_pc; /* our PCI chipset... */
49 pcitag_t sc_tag; /* ...and tag. */
50
51 struct pci_conf_state sc_pciconf;
52 pcireg_t sc_pciconfext[48];
53 };
54
55 static pnp_status_t ppb_power(device_t, pnp_request_t, void *);
56
57 static int
58 ppbmatch(struct device *parent, struct cfdata *match,
59 void *aux)
60 {
61 struct pci_attach_args *pa = aux;
62
63 /*
64 * Check the ID register to see that it's a PCI bridge.
65 * If it is, we assume that we can deal with it; it _should_
66 * work in a standardized way...
67 */
68 if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
69 PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_PCI)
70 return (1);
71
72 return (0);
73 }
74
75 static void
76 ich_disable_sci(struct device *self, pci_chipset_tag_t pc, pcitag_t tag)
77 {
78 pcireg_t val;
79
80 /*
81 * Intel I/O Controller Hub 6 Family Datasheet
82 * Section 19.1.44
83 *
84 * Intel I/O Controller Hub 7 Family Datasheet
85 * Section 18.1.44
86 *
87 * Intel I/O Controller Hub 8 Family Datasheet
88 * Section 20.1.45
89 *
90 * Intel I/O Controller Hub 9 Family Datasheet
91 * Section 20.1.46
92 *
93 * Address Offset: D8
94 *
95 * Bit 31: Power Management SCI Enable
96 * Bit 30: Hot Plug SCI Enable
97 *
98 * Disable both as NetBSD currently can't deal with the interrupts.
99 */
100
101 val = pci_conf_read(pc, tag, 0xd8);
102 if ((val & 0xc000000) != 0) {
103 aprint_normal("%s: disabling unsupported PM and Hot Plug SCI\n",
104 self->dv_xname);
105
106 val &= ~(0xc000000);
107 pci_conf_write(pc, tag, 0xd8, val);
108 }
109 }
110
111 static void
112 ppbattach(struct device *parent, struct device *self, void *aux)
113 {
114 struct ppb_softc *sc = (void *) self;
115 struct pci_attach_args *pa = aux;
116 pci_chipset_tag_t pc = pa->pa_pc;
117 struct pcibus_attach_args pba;
118 pcireg_t busdata;
119 char devinfo[256];
120
121 pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
122 aprint_normal(": %s (rev. 0x%02x)\n", devinfo,
123 PCI_REVISION(pa->pa_class));
124 aprint_naive("\n");
125
126 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL &&
127 (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82801FB_EXP_0 ||
128 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82801FB_EXP_1 ||
129 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82801FB_EXP_2 ||
130 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82801G_EXP_1 ||
131 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82801G_EXP_2 ||
132 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82801G_EXP_3 ||
133 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82801G_EXP_4 ||
134 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82801G_EXP_5 ||
135 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82801G_EXP_6 ||
136 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82801H_EXP_1 ||
137 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82801H_EXP_2 ||
138 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82801H_EXP_3 ||
139 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82801H_EXP_4 ||
140 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82801H_EXP_5 ||
141 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82801H_EXP_6 ||
142 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82801I_EXP_1 ||
143 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82801I_EXP_2 ||
144 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82801I_EXP_3 ||
145 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82801I_EXP_4 ||
146 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82801I_EXP_5 ||
147 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82801I_EXP_6))
148 ich_disable_sci(self, pc, pa->pa_tag);
149
150 sc->sc_pc = pc;
151 sc->sc_tag = pa->pa_tag;
152
153 busdata = pci_conf_read(pc, pa->pa_tag, PPB_REG_BUSINFO);
154
155 if (PPB_BUSINFO_SECONDARY(busdata) == 0) {
156 aprint_normal("%s: not configured by system firmware\n",
157 self->dv_xname);
158 return;
159 }
160
161 #if 0
162 /*
163 * XXX can't do this, because we're not given our bus number
164 * (we shouldn't need it), and because we've no way to
165 * decompose our tag.
166 */
167 /* sanity check. */
168 if (pa->pa_bus != PPB_BUSINFO_PRIMARY(busdata))
169 panic("ppbattach: bus in tag (%d) != bus in reg (%d)",
170 pa->pa_bus, PPB_BUSINFO_PRIMARY(busdata));
171 #endif
172
173 if (pnp_register(self, ppb_power) != PNP_STATUS_SUCCESS)
174 aprint_error("%s: couldn't establish power handler\n",
175 device_xname(self));
176
177 /*
178 * Attach the PCI bus than hangs off of it.
179 *
180 * XXX Don't pass-through Memory Read Multiple. Should we?
181 * XXX Consult the spec...
182 */
183 pba.pba_iot = pa->pa_iot;
184 pba.pba_memt = pa->pa_memt;
185 pba.pba_dmat = pa->pa_dmat;
186 pba.pba_dmat64 = pa->pa_dmat64;
187 pba.pba_pc = pc;
188 pba.pba_flags = pa->pa_flags & ~PCI_FLAGS_MRM_OKAY;
189 pba.pba_bus = PPB_BUSINFO_SECONDARY(busdata);
190 pba.pba_bridgetag = &sc->sc_tag;
191 pba.pba_intrswiz = pa->pa_intrswiz;
192 pba.pba_intrtag = pa->pa_intrtag;
193
194 config_found_ia(self, "pcibus", &pba, pcibusprint);
195 }
196
197 static pnp_status_t
198 ppb_power(device_t dv, pnp_request_t req, void *opaque)
199 {
200 struct ppb_softc *sc;
201 pnp_capabilities_t *pcaps;
202 pnp_state_t *pstate;
203 pcireg_t val;
204 int off;
205
206 sc = (struct ppb_softc *)dv;
207 switch (req) {
208 case PNP_REQUEST_GET_CAPABILITIES:
209 pcaps = opaque;
210 pcaps->state = PNP_STATE_D0 | PNP_STATE_D3;
211 break;
212 case PNP_REQUEST_GET_STATE:
213 pstate = opaque;
214 *pstate = PNP_STATE_D0; /* XXX */
215 break;
216 case PNP_REQUEST_SET_STATE:
217 pstate = opaque;
218 switch (*pstate) {
219 case PNP_STATE_D0:
220 pci_conf_restore(sc->sc_pc, sc->sc_tag,
221 &sc->sc_pciconf);
222 for (off = 0x40; off <= 0xff; off += 4) {
223 val = pci_conf_read(sc->sc_pc, sc->sc_tag, off);
224 if (val != sc->sc_pciconfext[(off - 0x40) / 4])
225 pci_conf_write(sc->sc_pc, sc->sc_tag,
226 off,
227 sc->sc_pciconfext[(off - 0x40)/4]);
228 }
229 break;
230 case PNP_STATE_D3:
231 pci_conf_capture(sc->sc_pc, sc->sc_tag,
232 &sc->sc_pciconf);
233 for (off = 0x40; off <= 0xff; off += 4)
234 sc->sc_pciconfext[(off - 0x40) / 4] =
235 pci_conf_read(sc->sc_pc, sc->sc_tag, off);
236 break;
237 default:
238 return PNP_STATUS_UNSUPPORTED;
239 }
240 break;
241 default:
242 return PNP_STATUS_UNSUPPORTED;
243 }
244
245 return PNP_STATUS_SUCCESS;
246 }
247
248 CFATTACH_DECL(ppb, sizeof(struct ppb_softc),
249 ppbmatch, ppbattach, NULL, NULL);
250