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