mcbus.c revision 1.1 1 /* $NetBSD: mcbus.c,v 1.1 1998/04/15 00:48:12 mjacob Exp $ */
2
3 /*
4 * Copyright (c) 1998 by Matthew Jacob
5 * NASA AMES Research Center.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice immediately at the beginning of the file, without modification,
13 * this list of conditions, and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33 /*
34 * Autoconfiguration and support routines for the TurboLaser System Bus
35 * found on AlphaServer 8200 and 8400 systems.
36 */
37
38 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
39
40 __KERNEL_RCSID(0, "$NetBSD: mcbus.c,v 1.1 1998/04/15 00:48:12 mjacob Exp $");
41
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/device.h>
45 #include <sys/malloc.h>
46
47 #include <machine/autoconf.h>
48 #include <machine/rpb.h>
49 #include <machine/pte.h>
50
51 #include <alpha/mcbus/mcbusreg.h>
52 #include <alpha/mcbus/mcbusvar.h>
53
54 #include "locators.h"
55
56 #define KV(_addr) ((caddr_t)ALPHA_PHYS_TO_K0SEG((_addr)))
57
58 extern struct cfdriver mcbus_cd;
59 extern int cputype;
60
61 struct mcbus_cpu_busdep mcbus_primary;
62
63 static int mcbusmatch __P((struct device *, struct cfdata *, void *));
64 static void mcbusattach __P((struct device *, struct device *, void *));
65 static int mcbusprint __P((void *, const char *));
66 static int mcbussubmatch __P((struct device *, struct cfdata *, void *));
67 static char *mcbus_node_type_str __P((u_int8_t));
68
69 typedef struct {
70 struct device mcbus_dev;
71 u_int8_t mcbus_types[MCBUS_MID_MAX];
72 } mcbus_softc_t;
73
74 struct cfattach mcbus_ca = {
75 sizeof (mcbus_softc_t), mcbusmatch, mcbusattach
76 };
77
78 extern void mcpcia_config_cleanup __P((void));
79
80
81 static int
82 mcbusprint(aux, cp)
83 void *aux;
84 const char *cp;
85 {
86 struct mcbus_dev_attach_args *tap = aux;
87 printf(" mid %d: %s", tap->ma_mid, mcbus_node_type_str(tap->ma_type));
88 return (UNCONF);
89 }
90
91 static int
92 mcbussubmatch(parent, cf, aux)
93 struct device *parent;
94 struct cfdata *cf;
95 void *aux;
96 {
97 struct mcbus_dev_attach_args *tap = aux;
98 if (tap->ma_name != mcbus_cd.cd_name)
99 return (0);
100 if (cf->cf_loc[MCBUSCF_MID] != MCBUSCF_MID_DEFAULT &&
101 cf->cf_loc[MCBUSCF_MID] != tap->ma_mid)
102 return (0);
103 return ((*cf->cf_attach->ca_match)(parent, cf, aux));
104 }
105
106 static int
107 mcbusmatch(parent, cf, aux)
108 struct device *parent;
109 struct cfdata *cf;
110 void *aux;
111 {
112 struct confargs *ca = aux;
113
114 /* Make sure we're looking for a MCBUS. */
115 if (strcmp(ca->ca_name, mcbus_cd.cd_name) != 0)
116 return (0);
117
118 /*
119 * Only available on 4100 processor type platforms.
120 */
121 if (cputype != ST_DEC_4100)
122 return (0);
123 return (1);
124 }
125
126 static void
127 mcbusattach(parent, self, aux)
128 struct device *parent;
129 struct device *self;
130 void *aux;
131 {
132 static const char *bcs[4] = {
133 "(no bcache)", "1MB BCache", "4MB BCache", "??????"
134 };
135 static const u_int8_t pci_mid_order[4] = { 5, 4, 7, 6 };
136 struct mcbus_dev_attach_args ta;
137 mcbus_softc_t *mbp = (mcbus_softc_t *)self;
138 u_int8_t mid;
139 int i;
140
141 printf("\n");
142
143 mbp->mcbus_types[0] = MCBUS_TYPE_RES;
144 for (mid = 1; mid <= MCBUS_MID_MAX; ++mid) {
145 mbp->mcbus_types[mid] = MCBUS_TYPE_UNK;
146 }
147
148 /*
149 * Find and "configure" memory.
150 */
151 ta.ma_name = mcbus_cd.cd_name;
152 ta.ma_gid = MCBUS_GID_FROM_INSTANCE(self->dv_unit);
153 ta.ma_mid = 1;
154 ta.ma_type = MCBUS_TYPE_MEM;
155 mbp->mcbus_types[1] = MCBUS_TYPE_MEM;
156 config_found_sm(self, &ta, mcbusprint, mcbussubmatch);
157
158 /*
159 * Now find PCI busses. In keeping with Digital's ordering
160 * of things, we'll search in a specific MID order.
161 */
162 for (i = 0; i < MCPCIA_PER_MCBUS; i++) {
163 mid = pci_mid_order[i];
164 ta.ma_name = mcbus_cd.cd_name;
165 ta.ma_gid = MCBUS_GID_FROM_INSTANCE(self->dv_unit);
166 ta.ma_mid = mid;
167 ta.ma_type = MCBUS_TYPE_PCI;
168 /*
169 * Attach any children nodes (PCI busses).
170 */
171 config_found_sm(self, &ta, mcbusprint, mcbussubmatch);
172 }
173
174 /*
175 * Deal with hooking CPU instances to MCBUS module ids.
176 *
177 * Note that we do this here because it's the read of
178 * stupid MCPCIA WHOAMI register that can get us the
179 * module ID and type of the configuring CPU.
180 */
181
182 if (mcbus_primary.mcbus_valid) {
183 mid = mcbus_primary.mcbus_cpu_mid;
184 printf("%s mid %d: %s %s\n", self->dv_xname,
185 mid, mcbus_node_type_str(MCBUS_TYPE_CPU),
186 bcs[mcbus_primary.mcbus_bcache & 0x3]);
187 #if 0
188 ta.ma_name = mcbus_cd.cd_name;
189 ta.ma_gid = MCBUS_GID_FROM_INSTANCE(self->dv_unit);
190 ta.ma_mid = mid;
191 ta.ma_type = MCBUS_TYPE_CPU;
192 mbp->mcbus_types[mid] = MCBUS_TYPE_CPU;
193 config_found_sm(self, &ta, mcbusprint, mcbussubmatch);
194 #endif
195 }
196
197 /*
198 * Now clean up after configuring everything.
199 *
200 * This is an unfortunate layering violation- but
201 * we can't enable interrupts until *all* probing
202 * is done, but the code and knowledge to clean
203 * up after probing and to enable interrupts is
204 * down in the MCPCIA layer.
205 */
206 mcpcia_config_cleanup();
207 }
208
209 static char *
210 mcbus_node_type_str(type)
211 u_int8_t type;
212 {
213 switch (type) {
214 case MCBUS_TYPE_RES:
215 panic ("RESERVED TYPE IN MCBUS_NODE_TYPE_STR");
216 break;
217 case MCBUS_TYPE_UNK:
218 panic ("UNKNOWN TYPE IN MCBUS_NODE_TYPE_STR");
219 break;
220 case MCBUS_TYPE_MEM:
221 return ("Memory");
222 case MCBUS_TYPE_CPU:
223 return ("CPU");
224 case MCBUS_TYPE_PCI:
225 return ("PCI Bridge");
226 default:
227 panic("REALLY UNKNWON (%x) TYPE IN MCBUS_NODE_TYPE_STR", type);
228 break;
229 }
230 }
231