pchb.c revision 1.3 1 1.3 garbled /* $NetBSD: pchb.c,v 1.3 2008/01/28 18:24:21 garbled Exp $ */
2 1.2 garbled
3 1.2 garbled /*-
4 1.2 garbled * Copyright (c) 2007 The NetBSD Foundation, Inc.
5 1.2 garbled * All rights reserved.
6 1.2 garbled *
7 1.2 garbled * This code is derived from software contributed to The NetBSD Foundation
8 1.2 garbled * by Tim Rightnour
9 1.2 garbled *
10 1.2 garbled * Redistribution and use in source and binary forms, with or without
11 1.2 garbled * modification, are permitted provided that the following conditions
12 1.2 garbled * are met:
13 1.2 garbled * 1. Redistributions of source code must retain the above copyright
14 1.2 garbled * notice, this list of conditions and the following disclaimer.
15 1.2 garbled * 2. Redistributions in binary form must reproduce the above copyright
16 1.2 garbled * notice, this list of conditions and the following disclaimer in the
17 1.2 garbled * documentation and/or other materials provided with the distribution.
18 1.2 garbled * 3. All advertising materials mentioning features or use of this software
19 1.2 garbled * must display the following acknowledgement:
20 1.2 garbled * This product includes software developed by the NetBSD
21 1.2 garbled * Foundation, Inc. and its contributors.
22 1.2 garbled * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2 garbled * contributors may be used to endorse or promote products derived
24 1.2 garbled * from this software without specific prior written permission.
25 1.2 garbled *
26 1.2 garbled * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2 garbled * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2 garbled * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2 garbled * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2 garbled * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2 garbled * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2 garbled * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2 garbled * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2 garbled * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2 garbled * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2 garbled * POSSIBILITY OF SUCH DAMAGE.
37 1.2 garbled */
38 1.2 garbled
39 1.2 garbled #include <sys/cdefs.h>
40 1.3 garbled __KERNEL_RCSID(0, "$NetBSD: pchb.c,v 1.3 2008/01/28 18:24:21 garbled Exp $");
41 1.2 garbled
42 1.2 garbled #include <sys/types.h>
43 1.2 garbled #include <sys/param.h>
44 1.2 garbled #include <sys/systm.h>
45 1.2 garbled #include <sys/device.h>
46 1.2 garbled
47 1.2 garbled #include <machine/bus.h>
48 1.2 garbled #include <machine/pio.h>
49 1.2 garbled
50 1.2 garbled #include <dev/pci/pcivar.h>
51 1.2 garbled #include <dev/pci/pcireg.h>
52 1.2 garbled #include <dev/pci/pcidevs.h>
53 1.2 garbled #include <dev/pci/agpreg.h>
54 1.2 garbled #include <dev/pci/agpvar.h>
55 1.2 garbled
56 1.2 garbled #include <dev/ic/mpc105reg.h>
57 1.2 garbled #include <dev/ic/mpc106reg.h>
58 1.2 garbled #include <dev/ic/ibm82660reg.h>
59 1.2 garbled
60 1.2 garbled #include "agp.h"
61 1.2 garbled
62 1.2 garbled int pchbmatch(struct device *, struct cfdata *, void *);
63 1.2 garbled void pchbattach(struct device *, struct device *, void *);
64 1.2 garbled
65 1.2 garbled CFATTACH_DECL(pchb, sizeof(struct device),
66 1.2 garbled pchbmatch, pchbattach, NULL, NULL);
67 1.2 garbled
68 1.2 garbled int
69 1.2 garbled pchbmatch(struct device *parent, struct cfdata *cf, void *aux)
70 1.2 garbled {
71 1.2 garbled struct pci_attach_args *pa = aux;
72 1.2 garbled
73 1.2 garbled /*
74 1.2 garbled * Match all known PCI host chipsets.
75 1.2 garbled */
76 1.2 garbled if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
77 1.2 garbled PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_HOST) {
78 1.2 garbled return (1);
79 1.2 garbled }
80 1.2 garbled
81 1.2 garbled return (0);
82 1.2 garbled }
83 1.2 garbled
84 1.2 garbled static void
85 1.2 garbled mpc105_print(struct pci_attach_args *pa, struct device *self)
86 1.2 garbled {
87 1.2 garbled pcireg_t reg1, reg2;
88 1.2 garbled const char *s1;
89 1.2 garbled
90 1.2 garbled reg1 = pci_conf_read(pa->pa_pc, pa->pa_tag, MPC105_PICR1);
91 1.2 garbled reg2 = pci_conf_read(pa->pa_pc, pa->pa_tag, MPC105_PICR2);
92 1.2 garbled aprint_normal("%s: L2 cache: ", self->dv_xname);
93 1.2 garbled
94 1.2 garbled switch (reg2 & MPC105_PICR2_L2_SIZE) {
95 1.2 garbled case MPC105_PICR2_L2_SIZE_256K:
96 1.2 garbled s1 = "256K";
97 1.2 garbled break;
98 1.2 garbled case MPC105_PICR2_L2_SIZE_512K:
99 1.2 garbled s1 = "512K";
100 1.2 garbled break;
101 1.2 garbled case MPC105_PICR2_L2_SIZE_1M:
102 1.2 garbled s1 = "1M";
103 1.2 garbled break;
104 1.2 garbled default:
105 1.2 garbled s1 = "reserved size";
106 1.2 garbled break;
107 1.2 garbled }
108 1.2 garbled
109 1.2 garbled aprint_normal("%s, ", s1);
110 1.2 garbled switch (reg1 & MPC105_PICR1_L2_MP) {
111 1.2 garbled case MPC105_PICR1_L2_MP_NONE:
112 1.2 garbled s1 = "uniprocessor/none";
113 1.2 garbled break;
114 1.2 garbled case MPC105_PICR1_L2_MP_WT:
115 1.2 garbled s1 = "write-through";
116 1.2 garbled break;
117 1.2 garbled case MPC105_PICR1_L2_MP_WB:
118 1.2 garbled s1 = "write-back";
119 1.2 garbled break;
120 1.2 garbled case MPC105_PICR1_L2_MP_MP:
121 1.2 garbled s1 = "multiprocessor";
122 1.2 garbled break;
123 1.2 garbled }
124 1.2 garbled aprint_normal("%s mode\n", s1);
125 1.2 garbled }
126 1.2 garbled
127 1.2 garbled static void
128 1.2 garbled mpc106_print(struct pci_attach_args *pa, struct device *self)
129 1.2 garbled {
130 1.2 garbled pcireg_t reg1, reg2;
131 1.2 garbled const char *s1;
132 1.2 garbled
133 1.2 garbled reg1 = pci_conf_read(pa->pa_pc, pa->pa_tag, MPC106_PICR1);
134 1.2 garbled reg2 = pci_conf_read(pa->pa_pc, pa->pa_tag, MPC106_PICR2);
135 1.2 garbled aprint_normal("%s: L2 cache: ", self->dv_xname);
136 1.2 garbled
137 1.2 garbled switch (reg2 & MPC106_PICR2_L2_SIZE) {
138 1.2 garbled case MPC106_PICR2_L2_SIZE_256K:
139 1.2 garbled s1 = "256K";
140 1.2 garbled break;
141 1.2 garbled case MPC106_PICR2_L2_SIZE_512K:
142 1.2 garbled s1 = "512K";
143 1.2 garbled break;
144 1.2 garbled case MPC106_PICR2_L2_SIZE_1M:
145 1.2 garbled s1 = "1M";
146 1.2 garbled break;
147 1.2 garbled default:
148 1.2 garbled s1 = "reserved size";
149 1.2 garbled break;
150 1.2 garbled }
151 1.2 garbled
152 1.2 garbled aprint_normal("%s, ", s1);
153 1.2 garbled switch (reg1 & MPC106_PICR1_EXT_L2_EN) {
154 1.2 garbled case 0:
155 1.2 garbled switch (reg1 & MPC106_PICR1_L2_MP) {
156 1.2 garbled case MPC106_PICR1_L2_MP_NONE:
157 1.2 garbled s1 = "uniprocessor/none";
158 1.2 garbled break;
159 1.2 garbled case MPC106_PICR1_L2_MP_WT:
160 1.2 garbled s1 = "internally controlled write-through";
161 1.2 garbled break;
162 1.2 garbled case MPC106_PICR1_L2_MP_WB:
163 1.2 garbled s1 = "internally controlled write-back";
164 1.2 garbled break;
165 1.2 garbled case MPC106_PICR1_L2_MP_MP:
166 1.2 garbled s1 = "multiprocessor/none";
167 1.2 garbled break;
168 1.2 garbled }
169 1.2 garbled break;
170 1.2 garbled case 1:
171 1.2 garbled switch (reg1 & MPC106_PICR1_L2_MP) {
172 1.2 garbled case MPC106_PICR1_L2_MP_NONE:
173 1.2 garbled s1 = "uniprocessor/external";
174 1.2 garbled break;
175 1.2 garbled case MPC106_PICR1_L2_MP_MP:
176 1.2 garbled s1 = "multiprocessors/external";
177 1.2 garbled break;
178 1.2 garbled default:
179 1.2 garbled s1 = "reserved";
180 1.2 garbled break;
181 1.2 garbled }
182 1.2 garbled }
183 1.2 garbled aprint_normal("%s mode\n", s1);
184 1.2 garbled }
185 1.2 garbled
186 1.2 garbled static void
187 1.2 garbled ibm82660_print(struct pci_attach_args *pa, struct device *self)
188 1.2 garbled {
189 1.2 garbled pcireg_t reg1;
190 1.2 garbled #ifdef PREP_BUS_SPACE_IO
191 1.2 garbled pcireg_t reg2;
192 1.2 garbled #endif
193 1.2 garbled const char *s1, *s2;
194 1.2 garbled
195 1.2 garbled reg1 = pci_conf_read(pa->pa_pc, pa->pa_tag,
196 1.2 garbled IBM_82660_CACHE_STATUS);
197 1.2 garbled #ifdef PREP_BUS_SPACE_IO
198 1.2 garbled reg2 = in32rb(PREP_BUS_SPACE_IO+IBM_82660_SYSTEM_CTRL);
199 1.2 garbled if (reg2 & IBM_82660_SYSTEM_CTRL_L2_EN) {
200 1.2 garbled if (reg1 & IBM_82660_CACHE_STATUS_L2_EN)
201 1.2 garbled s1 = "internal enabled";
202 1.2 garbled else
203 1.2 garbled s1 = "enabled";
204 1.2 garbled if (reg2 & IBM_82660_SYSTEM_CTRL_L2_MI)
205 1.2 garbled s2 = "(normal operation)";
206 1.2 garbled else
207 1.2 garbled s2 = "(miss updates inhibited)";
208 1.2 garbled } else {
209 1.2 garbled s1 = "disabled";
210 1.2 garbled s2 = "";
211 1.2 garbled }
212 1.2 garbled #else
213 1.2 garbled if (reg1 & IBM_82660_CACHE_STATUS_L2_EN)
214 1.2 garbled s1 = "enabled";
215 1.2 garbled else
216 1.2 garbled s1 = "disabled";
217 1.2 garbled s2 = "";
218 1.2 garbled #endif
219 1.2 garbled aprint_normal("%s: L1: %s L2: %s %s\n", self->dv_xname,
220 1.2 garbled (reg1 & IBM_82660_CACHE_STATUS_L1_EN) ? "enabled" : "disabled",
221 1.2 garbled s1, s2);
222 1.2 garbled
223 1.2 garbled reg1 = pci_conf_read(pa->pa_pc, pa->pa_tag, IBM_82660_OPTIONS_1);
224 1.2 garbled aprint_verbose("%s: MCP# assertion %s "
225 1.2 garbled "TEA# assertion %s\n", self->dv_xname,
226 1.2 garbled (reg1 & IBM_82660_OPTIONS_1_MCP) ? "enabled" : "disabled",
227 1.2 garbled (reg1 & IBM_82660_OPTIONS_1_TEA) ? "enabled" : "disabled");
228 1.2 garbled aprint_verbose("%s: PCI/ISA I/O mapping %s\n", self->dv_xname,
229 1.2 garbled (reg1 & IBM_82660_OPTIONS_1_ISA) ? "contiguous" : "non-contiguous");
230 1.2 garbled
231 1.2 garbled reg1 = pci_conf_read(pa->pa_pc, pa->pa_tag, IBM_82660_OPTIONS_3);
232 1.2 garbled aprint_normal("%s: DRAM %s (%s) SRAM %s\n", self->dv_xname,
233 1.2 garbled (reg1 & IBM_82660_OPTIONS_3_DRAM) ? "EDO" : "standard",
234 1.2 garbled (reg1 & IBM_82660_OPTIONS_3_ECC) ? "ECC" : "parity",
235 1.2 garbled (reg1 & IBM_82660_OPTIONS_3_SRAM) ? "sync" : "async");
236 1.2 garbled aprint_verbose("%s: Snoop mode %s\n", self->dv_xname,
237 1.2 garbled (reg1 & IBM_82660_OPTIONS_3_SNOOP) ? "603" : "601/604");
238 1.2 garbled }
239 1.2 garbled
240 1.2 garbled void
241 1.2 garbled pchbattach(struct device *parent, struct device *self, void *aux)
242 1.2 garbled {
243 1.2 garbled struct pci_attach_args *pa = aux;
244 1.2 garbled char devinfo[256];
245 1.2 garbled #if NAGP > 0
246 1.2 garbled struct agpbus_attach_args apa;
247 1.2 garbled #endif
248 1.3 garbled volatile unsigned char *python;
249 1.3 garbled uint32_t v;
250 1.3 garbled
251 1.3 garbled aprint_normal("\n");
252 1.2 garbled
253 1.2 garbled /*
254 1.2 garbled * All we do is print out a description. Eventually, we
255 1.2 garbled * might want to add code that does something that's
256 1.2 garbled * possibly chipset-specific.
257 1.2 garbled */
258 1.2 garbled
259 1.2 garbled pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
260 1.3 garbled aprint_normal("%s: %s (rev. 0x%02x)\n", self->dv_xname, devinfo,
261 1.2 garbled PCI_REVISION(pa->pa_class));
262 1.2 garbled
263 1.2 garbled switch (PCI_VENDOR(pa->pa_id)) {
264 1.2 garbled case PCI_VENDOR_IBM:
265 1.2 garbled switch (PCI_PRODUCT(pa->pa_id)) {
266 1.2 garbled case PCI_PRODUCT_IBM_82660:
267 1.2 garbled ibm82660_print(pa, self);
268 1.2 garbled break;
269 1.3 garbled case PCI_PRODUCT_IBM_PYTHON:
270 1.3 garbled python = mapiodev(0xfeff6000, 0x60);
271 1.3 garbled v = 0x88b78e01; /* taken from linux */
272 1.3 garbled out32rb(python+0x30, v);
273 1.3 garbled v = in32rb(python+0x30);
274 1.3 garbled aprint_debug("Reset python reg 30 to 0x%x\n", v);
275 1.3 garbled break;
276 1.2 garbled }
277 1.2 garbled break;
278 1.2 garbled case PCI_VENDOR_MOT:
279 1.2 garbled switch (PCI_PRODUCT(pa->pa_id)) {
280 1.2 garbled case PCI_PRODUCT_MOT_MPC105:
281 1.2 garbled mpc105_print(pa, self);
282 1.2 garbled break;
283 1.2 garbled case PCI_PRODUCT_MOT_MPC106:
284 1.2 garbled mpc106_print(pa, self);
285 1.2 garbled break;
286 1.2 garbled }
287 1.2 garbled break;
288 1.2 garbled }
289 1.2 garbled
290 1.2 garbled #if NAGP > 0
291 1.2 garbled if (pci_get_capability(pa->pa_pc, pa->pa_tag, PCI_CAP_AGP,
292 1.2 garbled NULL, NULL) != 0) {
293 1.2 garbled apa.apa_pci_args = *pa;
294 1.2 garbled config_found_ia(self, "agpbus", &apa, agpbusprint);
295 1.2 garbled }
296 1.2 garbled #endif /* NAGP */
297 1.2 garbled }
298