1 /* $OpenBSD: mcbus.c,v 1.2 2012/12/05 23:20:10 deraadt Exp $ */ 2 /* $NetBSD: mcbus.c,v 1.19 2007/03/04 05:59:11 christos Exp $ */ 3 4 /* 5 * Copyright (c) 1998 by Matthew Jacob 6 * NASA AMES Research Center. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice immediately at the beginning of the file, without modification, 14 * this list of conditions, and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 25 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34 /* 35 * Autoconfiguration routines for the MCBUS system 36 * bus found on AlphaServer 4100 systems. 37 */ 38 39 #include <sys/param.h> 40 #include <sys/systm.h> 41 #include <sys/device.h> 42 #include <sys/malloc.h> 43 44 #include <machine/autoconf.h> 45 #include <machine/rpb.h> 46 #include <machine/pte.h> 47 48 #include <alpha/mcbus/mcbusreg.h> 49 #include <alpha/mcbus/mcbusvar.h> 50 51 #include <alpha/pci/mcpciareg.h> 52 53 #define KV(_addr) ((caddr_t)ALPHA_PHYS_TO_K0SEG((_addr))) 54 #define MCPCIA_EXISTS(mid, gid) \ 55 (!badaddr((void *)KV(MCPCIA_BRIDGE_ADDR(gid, mid)), sizeof (u_int32_t))) 56 57 struct mcbus_cpu_busdep mcbus_primary; 58 59 int mcbusmatch (struct device *, void *, void *); 60 void mcbusattach (struct device *, struct device *, void *); 61 int mcbusprint (void *, const char *); 62 int mcbussbm (struct device *, void *, void *); 63 64 const char *mcbus_node_type_str (u_int8_t); 65 66 typedef struct { 67 struct device mcbus_dev; 68 u_int8_t mcbus_types[MCBUS_MID_MAX]; 69 } mcbus_softc_t; 70 71 struct cfattach mcbus_ca = { 72 sizeof(mcbus_softc_t), mcbusmatch, mcbusattach 73 }; 74 75 struct cfdriver mcbus_cd = { 76 NULL, "mcbus", DV_DULL, 77 }; 78 79 /* 80 * Tru64 UNIX (formerly Digital UNIX (formerly DEC OSF/1)) probes for MCPCIAs 81 * in the following order: 82 * 83 * 5, 4, 7, 6 84 * 85 * This is so that the built-in CD-ROM on the internal 53c810 is always 86 * dka500. We probe them in the same order, for consistency. 87 */ 88 const int mcbus_mcpcia_probe_order[] = { 5, 4, 7, 6 }; 89 90 extern void mcpcia_config_cleanup (void); 91 92 int 93 mcbusprint(aux, cp) 94 void *aux; 95 const char *cp; 96 { 97 struct mcbus_dev_attach_args *tap = aux; 98 printf(" mid %d: %s", tap->ma_mid, 99 mcbus_node_type_str(tap->ma_type)); 100 return (UNCONF); 101 } 102 103 int 104 mcbussbm(parent, cf, aux) 105 struct device *parent; 106 void *cf; 107 void *aux; 108 { 109 struct mcbus_dev_attach_args *tap = aux; 110 struct cfdata *mcf = (struct cfdata *)cf; 111 112 if (mcf->cf_loc[MCBUSCF_MID] != MCBUSCF_MID_DEFAULT && 113 mcf->cf_loc[MCBUSCF_MID] != tap->ma_mid) 114 return (0); 115 116 117 return ((*mcf->cf_attach->ca_match)(parent, mcf, aux)); 118 } 119 120 int 121 mcbusmatch(parent, cf, aux) 122 struct device *parent; 123 void *cf; 124 void *aux; 125 { 126 struct mainbus_attach_args *ma = aux; 127 128 /* Make sure we're looking for a MCBUS. */ 129 if (strcmp(ma->ma_name, mcbus_cd.cd_name) != 0) 130 return (0); 131 132 /* 133 * Only available on 4100 processor type platforms. 134 */ 135 if (cputype != ST_DEC_4100) 136 return (0); 137 138 return (1); 139 } 140 141 void 142 mcbusattach(parent, self, aux) 143 struct device *parent; 144 struct device *self; 145 void *aux; 146 { 147 static const char *bcs[CPU_BCacheMask + 1] = { 148 "No", "1MB", "2MB", "4MB", 149 }; 150 struct mcbus_dev_attach_args ta; 151 mcbus_softc_t *mbp = (mcbus_softc_t *)self; 152 int i, mid; 153 154 printf(": %s BCache\n", mcbus_primary.mcbus_valid ? 155 bcs[mcbus_primary.mcbus_bcache] : "Unknown"); 156 157 mbp->mcbus_types[0] = MCBUS_TYPE_RES; 158 for (mid = 1; mid <= MCBUS_MID_MAX; ++mid) 159 mbp->mcbus_types[mid] = MCBUS_TYPE_UNK; 160 161 /* 162 * Find and "configure" memory. 163 */ 164 ta.ma_name = mcbus_cd.cd_name; 165 ta.ma_gid = MCBUS_GID_FROM_INSTANCE(0); 166 ta.ma_mid = 1; 167 ta.ma_type = MCBUS_TYPE_MEM; 168 mbp->mcbus_types[1] = MCBUS_TYPE_MEM; 169 170 (void) config_found_sm(self, &ta, mcbusprint, mcbussbm); 171 172 /* 173 * Now find PCI busses. 174 */ 175 for (i = 0; i < MCPCIA_PER_MCBUS; i++) { 176 mid = mcbus_mcpcia_probe_order[i]; 177 ta.ma_name = mcbus_cd.cd_name; 178 ta.ma_gid = MCBUS_GID_FROM_INSTANCE(0); 179 ta.ma_mid = mid; 180 ta.ma_type = MCBUS_TYPE_PCI; 181 if (MCPCIA_EXISTS(ta.ma_mid, ta.ma_gid)) 182 (void) config_found_sm(self, &ta, mcbusprint, 183 mcbussbm); 184 } 185 186 mcpcia_config_cleanup(); 187 } 188 189 const char * 190 mcbus_node_type_str(type) 191 u_int8_t type; 192 { 193 switch (type) { 194 case MCBUS_TYPE_RES: 195 panic ("RESERVED TYPE IN MCBUS_NODE_TYPE_STR"); 196 break; 197 case MCBUS_TYPE_UNK: 198 panic ("UNKNOWN TYPE IN MCBUS_NODE_TYPE_STR"); 199 break; 200 case MCBUS_TYPE_MEM: 201 return ("Memory"); 202 case MCBUS_TYPE_CPU: 203 return ("CPU"); 204 case MCBUS_TYPE_PCI: 205 return ("PCI Bridge"); 206 default: 207 panic("REALLY UNKNWON (%x) TYPE IN MCBUS_NODE_TYPE_STR", type); 208 break; 209 } 210 } 211