imc.c revision 1.10 1 /* $NetBSD: imc.c,v 1.10 2003/12/14 07:21:51 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.10 2003/12/14 07:21:51 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
61 CFATTACH_DECL(imc, sizeof(struct imc_softc),
62 imc_match, imc_attach, NULL, NULL);
63
64 struct imc_attach_args {
65 const char* iaa_name;
66
67 bus_space_tag_t iaa_st;
68 bus_space_handle_t iaa_sh;
69
70 /* ? */
71 long iaa_offset;
72 int iaa_intr;
73 #if 0
74 int iaa_stride;
75 #endif
76 };
77
78 struct imc_softc isc;
79
80 static int
81 imc_match(parent, match, aux)
82 struct device *parent;
83 struct cfdata *match;
84 void *aux;
85 {
86
87 if ( (mach_type == MACH_SGI_IP22) || (mach_type == MACH_SGI_IP20) )
88 return (1);
89
90 return (0);
91 }
92
93 static void
94 imc_attach(parent, self, aux)
95 struct device *parent;
96 struct device *self;
97 void *aux;
98 {
99 u_int32_t reg;
100 struct imc_attach_args iaa;
101 struct mainbus_attach_args *ma = aux;
102 u_int32_t sysid;
103
104 isc.iot = SGIMIPS_BUS_SPACE_HPC;
105 if (bus_space_map(isc.iot, ma->ma_addr, 0,
106 BUS_SPACE_MAP_LINEAR, &isc.ioh))
107 panic("imc_attach: could not allocate memory\n");
108
109 sysid = bus_space_read_4(isc.iot, isc.ioh, IMC_SYSID);
110
111 /* EISA present bit is on even on Indys, so don't trust it! */
112 if (mach_subtype == MACH_SGI_IP22_FULLHOUSE)
113 isc.eisa_present = (sysid & IMC_SYSID_HAVEISA);
114 else
115 isc.eisa_present = 0;
116
117 printf("\nimc0: Revision %d", (sysid & IMC_SYSID_REVMASK));
118
119 if (isc.eisa_present)
120 printf(", EISA bus present");
121
122 printf("\n");
123
124 /* Clear CPU/GIO error status registers to clear any leftover bits. */
125 bus_space_write_4(isc.iot, isc.ioh, IMC_CPU_ERRSTAT, 0);
126 bus_space_write_4(isc.iot, isc.ioh, IMC_GIO_ERRSTAT, 0);
127
128 /*
129 * Enable parity reporting on GIO/main memory transactions.
130 * Disable parity checking on CPU bus transactions (as turning
131 * it on seems to cause spurious bus errors), but enable parity
132 * checking on CPU reads from main memory (note that this bit
133 * has the opposite sense... Turning it on turns the checks off!).
134 * Finally, turn on interrupt writes to the CPU from the MC.
135 */
136 reg = bus_space_read_4(isc.iot, isc.ioh, IMC_CPUCTRL0);
137 reg &= ~IMC_CPUCTRL0_NCHKMEMPAR;
138 reg |= (IMC_CPUCTRL0_GPR | IMC_CPUCTRL0_MPR | IMC_CPUCTRL0_INTENA);
139 bus_space_write_4(isc.iot, isc.ioh, IMC_CPUCTRL0, reg);
140
141 /* Setup the MC write buffer depth */
142 reg = bus_space_read_4(isc.iot, isc.ioh, IMC_CPUCTRL1);
143 reg = (reg & ~IMC_CPUCTRL1_MCHWMSK) | 13;
144 if (mach_type == MACH_SGI_IP20)
145 reg = (reg & ~IMC_CPUCTRL1_HPCLITTLE) | IMC_CPUCTRL1_HPCFX;
146 bus_space_write_4(isc.iot, isc.ioh, IMC_CPUCTRL1, reg);
147
148
149 /*
150 * Set GIO64 arbitrator configuration register:
151 *
152 * Preserve PROM-set graphics-related bits, as they seem to depend
153 * on the graphics variant present and I'm not sure how to figure
154 * that out or 100% sure what the correct settings are for each.
155 */
156 reg = bus_space_read_4(isc.iot, isc.ioh, IMC_GIO64ARB);
157 reg &= (IMC_GIO64ARB_GRX64 | IMC_GIO64ARB_GRXRT | IMC_GIO64ARB_GRXMST);
158
159 /* GIO64 invariant for all IP22 platforms: one GIO bus, HPC1 @ 64 */
160 reg |= IMC_GIO64ARB_ONEGIO | IMC_GIO64ARB_HPC64;
161
162 /* Rest of settings are machine/board dependant */
163 if (mach_type == MACH_SGI_IP20)
164 {
165 reg |= (IMC_GIO64ARB_ONEGIO |
166 IMC_GIO64ARB_EXP1RT | IMC_GIO64ARB_EXP0RT);
167 reg &= ~(IMC_GIO64ARB_HPC64 |
168 IMC_GIO64ARB_HPCEXP64 | IMC_GIO64ARB_EISA64 |
169 IMC_GIO64ARB_EXP064 | IMC_GIO64ARB_EXP164 |
170 IMC_GIO64ARB_EXP0PIPE | IMC_GIO64ARB_EXP1PIPE |
171 IMC_GIO64ARB_EXP0MST | IMC_GIO64ARB_EXP1MST);
172 /* XXX second ethernet adapter */
173 reg |= IMC_GIO64ARB_EXP0MST;
174 }
175 else
176 {
177 switch (mach_subtype) {
178 case MACH_SGI_IP22_GUINESS:
179 /* EISA can bus-master, is 64-bit */
180 reg |= (IMC_GIO64ARB_EISAMST | IMC_GIO64ARB_EISA64);
181 break;
182
183 case MACH_SGI_IP22_FULLHOUSE:
184 /*
185 * All Fullhouse boards have a 64-bit HPC2 and pipelined
186 * EXP0 slot.
187 */
188 reg |= (IMC_GIO64ARB_HPCEXP64 | IMC_GIO64ARB_EXP0PIPE);
189
190 if (mach_boardrev < 2) {
191 /* EXP0 realtime, EXP1 can master */
192 reg |= (IMC_GIO64ARB_EXP0RT | IMC_GIO64ARB_EXP1MST);
193 } else {
194 /* EXP1 pipelined as well, EISA masters */
195 reg |= (IMC_GIO64ARB_EXP1PIPE | IMC_GIO64ARB_EISAMST);
196 }
197 break;
198 }
199 }
200
201 bus_space_write_4(isc.iot, isc.ioh, IMC_GIO64ARB, reg);
202
203 if (isc.eisa_present) {
204 #if notyet
205 memset(&iaa, 0, sizeof(iaa));
206
207 iaa.iaa_name = "eisa";
208 (void)config_found(self, (void*)&iaa, imc_print);
209 #endif
210 }
211
212 memset(&iaa, 0, sizeof(iaa));
213
214 iaa.iaa_name = "gio";
215 (void)config_found(self, (void*)&iaa, imc_print);
216 }
217
218
219 static int
220 imc_print(aux, name)
221 void *aux;
222 const char *name;
223 {
224 struct imc_attach_args* iaa = aux;
225
226 if (name)
227 aprint_normal("%s at %s", iaa->iaa_name, name);
228
229 return UNCONF;
230 }
231
232 void
233 imc_bus_reset(void)
234 {
235 bus_space_write_4(isc.iot, isc.ioh, IMC_CPU_ERRSTAT, 0);
236 bus_space_write_4(isc.iot, isc.ioh, IMC_GIO_ERRSTAT, 0);
237 }
238