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