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