imc.c revision 1.11 1 /* $NetBSD: imc.c,v 1.11 2004/01/10 05:00:50 sekiya Exp $ */
2
3 /*
4 * Copyright (c) 2001 Rafal K. Boni
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #include <sys/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: imc.c,v 1.11 2004/01/10 05:00:50 sekiya Exp $");
32
33 #include <sys/param.h>
34 #include <sys/device.h>
35 #include <sys/systm.h>
36
37 #include <machine/cpu.h>
38 #include <machine/locore.h>
39 #include <machine/autoconf.h>
40 #include <machine/bus.h>
41 #include <machine/machtype.h>
42
43 #include <sgimips/dev/imcreg.h>
44
45 #include "locators.h"
46
47 struct imc_softc {
48 struct device sc_dev;
49
50 bus_space_tag_t iot;
51 bus_space_handle_t ioh;
52
53 int eisa_present : 1;
54 };
55
56 static int imc_match(struct device *, struct cfdata *, void *);
57 static void imc_attach(struct device *, struct device *, void *);
58 static int imc_print(void *, const char *);
59 void imc_bus_reset(void);
60 void imc_bus_error(void);
61 void imc_watchdog_tickle(void);
62
63 CFATTACH_DECL(imc, sizeof(struct imc_softc),
64 imc_match, imc_attach, NULL, NULL);
65
66 struct imc_attach_args {
67 const char* iaa_name;
68
69 bus_space_tag_t iaa_st;
70 bus_space_handle_t iaa_sh;
71
72 /* ? */
73 long iaa_offset;
74 int iaa_intr;
75 #if 0
76 int iaa_stride;
77 #endif
78 };
79
80 struct imc_softc isc;
81
82 static int
83 imc_match(parent, match, aux)
84 struct device *parent;
85 struct cfdata *match;
86 void *aux;
87 {
88
89 if ( (mach_type == MACH_SGI_IP22) || (mach_type == MACH_SGI_IP20) )
90 return (1);
91
92 return (0);
93 }
94
95 static void
96 imc_attach(parent, self, aux)
97 struct device *parent;
98 struct device *self;
99 void *aux;
100 {
101 u_int32_t reg;
102 struct imc_attach_args iaa;
103 struct mainbus_attach_args *ma = aux;
104 u_int32_t sysid;
105
106 isc.iot = SGIMIPS_BUS_SPACE_HPC;
107 if (bus_space_map(isc.iot, ma->ma_addr, 0,
108 BUS_SPACE_MAP_LINEAR, &isc.ioh))
109 panic("imc_attach: could not allocate memory\n");
110
111 sysid = bus_space_read_4(isc.iot, isc.ioh, IMC_SYSID);
112
113 /* EISA present bit is on even on Indys, so don't trust it! */
114 if (mach_subtype == MACH_SGI_IP22_FULLHOUSE)
115 isc.eisa_present = (sysid & IMC_SYSID_HAVEISA);
116 else
117 isc.eisa_present = 0;
118
119 printf("\nimc0: Revision %d", (sysid & IMC_SYSID_REVMASK));
120
121 if (isc.eisa_present)
122 printf(", EISA bus present");
123
124 printf("\n");
125
126 /* Clear CPU/GIO error status registers to clear any leftover bits. */
127 bus_space_write_4(isc.iot, isc.ioh, IMC_CPU_ERRSTAT, 0);
128 bus_space_write_4(isc.iot, isc.ioh, IMC_GIO_ERRSTAT, 0);
129
130 /*
131 * Enable parity reporting on GIO/main memory transactions.
132 * Disable parity checking on CPU bus transactions (as turning
133 * it on seems to cause spurious bus errors), but enable parity
134 * checking on CPU reads from main memory (note that this bit
135 * has the opposite sense... Turning it on turns the checks off!).
136 * Finally, turn on interrupt writes to the CPU from the MC.
137 */
138 reg = bus_space_read_4(isc.iot, isc.ioh, IMC_CPUCTRL0);
139 reg &= ~IMC_CPUCTRL0_NCHKMEMPAR;
140 reg |= (IMC_CPUCTRL0_GPR | IMC_CPUCTRL0_MPR | IMC_CPUCTRL0_INTENA);
141 bus_space_write_4(isc.iot, isc.ioh, IMC_CPUCTRL0, reg);
142
143 /* Setup the MC write buffer depth */
144 reg = bus_space_read_4(isc.iot, isc.ioh, IMC_CPUCTRL1);
145 reg = (reg & ~IMC_CPUCTRL1_MCHWMSK) | 13;
146 if (mach_type == MACH_SGI_IP20)
147 reg = (reg & ~IMC_CPUCTRL1_HPCLITTLE) | IMC_CPUCTRL1_HPCFX;
148 bus_space_write_4(isc.iot, isc.ioh, IMC_CPUCTRL1, reg);
149
150
151 /*
152 * Set GIO64 arbitrator configuration register:
153 *
154 * Preserve PROM-set graphics-related bits, as they seem to depend
155 * on the graphics variant present and I'm not sure how to figure
156 * that out or 100% sure what the correct settings are for each.
157 */
158 reg = bus_space_read_4(isc.iot, isc.ioh, IMC_GIO64ARB);
159 reg &= (IMC_GIO64ARB_GRX64 | IMC_GIO64ARB_GRXRT | IMC_GIO64ARB_GRXMST);
160
161 /* GIO64 invariant for all IP22 platforms: one GIO bus, HPC1 @ 64 */
162 reg |= IMC_GIO64ARB_ONEGIO | IMC_GIO64ARB_HPC64;
163
164 /* Rest of settings are machine/board dependant */
165 if (mach_type == MACH_SGI_IP20)
166 {
167 reg |= (IMC_GIO64ARB_ONEGIO |
168 IMC_GIO64ARB_EXP1RT | IMC_GIO64ARB_EXP0RT);
169 reg &= ~(IMC_GIO64ARB_HPC64 |
170 IMC_GIO64ARB_HPCEXP64 | IMC_GIO64ARB_EISA64 |
171 IMC_GIO64ARB_EXP064 | IMC_GIO64ARB_EXP164 |
172 IMC_GIO64ARB_EXP0PIPE | IMC_GIO64ARB_EXP1PIPE |
173 IMC_GIO64ARB_EXP0MST | IMC_GIO64ARB_EXP1MST);
174 /* XXX second ethernet adapter */
175 reg |= IMC_GIO64ARB_EXP0MST;
176 }
177 else
178 {
179 switch (mach_subtype) {
180 case MACH_SGI_IP22_GUINESS:
181 /* EISA can bus-master, is 64-bit */
182 reg |= (IMC_GIO64ARB_EISAMST | IMC_GIO64ARB_EISA64);
183 break;
184
185 case MACH_SGI_IP22_FULLHOUSE:
186 /*
187 * All Fullhouse boards have a 64-bit HPC2 and pipelined
188 * EXP0 slot.
189 */
190 reg |= (IMC_GIO64ARB_HPCEXP64 | IMC_GIO64ARB_EXP0PIPE);
191
192 if (mach_boardrev < 2) {
193 /* EXP0 realtime, EXP1 can master */
194 reg |= (IMC_GIO64ARB_EXP0RT | IMC_GIO64ARB_EXP1MST);
195 } else {
196 /* EXP1 pipelined as well, EISA masters */
197 reg |= (IMC_GIO64ARB_EXP1PIPE | IMC_GIO64ARB_EISAMST);
198 }
199 break;
200 }
201 }
202
203 bus_space_write_4(isc.iot, isc.ioh, IMC_GIO64ARB, reg);
204
205 if (isc.eisa_present) {
206 #if notyet
207 memset(&iaa, 0, sizeof(iaa));
208
209 iaa.iaa_name = "eisa";
210 (void)config_found(self, (void*)&iaa, imc_print);
211 #endif
212 }
213
214 memset(&iaa, 0, sizeof(iaa));
215
216 iaa.iaa_name = "gio";
217 (void)config_found(self, (void*)&iaa, imc_print);
218
219 /* enable watchdog and clear it */
220 reg = bus_space_read_4(isc.iot, isc.ioh, IMC_CPUCTRL0);
221 reg |= IMC_CPUCTRL0_WDOG;
222 bus_space_write_4(isc.iot, isc.ioh, IMC_CPUCTRL0, reg);
223 imc_watchdog_tickle();
224 }
225
226
227 static int
228 imc_print(aux, name)
229 void *aux;
230 const char *name;
231 {
232 struct imc_attach_args* iaa = aux;
233
234 if (name)
235 aprint_normal("%s at %s", iaa->iaa_name, name);
236
237 return UNCONF;
238 }
239
240 void
241 imc_bus_reset(void)
242 {
243 bus_space_write_4(isc.iot, isc.ioh, IMC_CPU_ERRSTAT, 0);
244 bus_space_write_4(isc.iot, isc.ioh, IMC_GIO_ERRSTAT, 0);
245 }
246
247 void
248 imc_bus_error(void)
249 {
250 printf("bus error: cpu_stat %08x addr %08x, gio_stat %08x addr %08x\n",
251 bus_space_read_4(isc.iot, isc.ioh, IMC_CPU_ERRSTAT),
252 bus_space_read_4(isc.iot, isc.ioh, IMC_CPU_ERRADDR),
253 bus_space_read_4(isc.iot, isc.ioh, IMC_GIO_ERRSTAT),
254 bus_space_read_4(isc.iot, isc.ioh, IMC_GIO_ERRADDR) );
255 imc_bus_reset();
256 }
257
258 void
259 imc_watchdog_tickle(void)
260 {
261 bus_space_write_4(isc.iot, isc.ioh, IMC_WDOG, 0);
262 }
263