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