1 /* $NetBSD: autoconf.c,v 1.76 2002/10/02 16:02:34 thorpej Exp $ */ 2 3 /* 4 * Copyright (c) 1994 Ludd, University of Lule}, Sweden. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed at Ludd, University of Lule}. 18 * 4. 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 ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #include "opt_compat_netbsd.h" 34 35 #include <sys/param.h> 36 #include <sys/types.h> 37 #include <sys/systm.h> 38 #include <sys/device.h> 39 #include <sys/reboot.h> 40 #include <sys/disk.h> 41 #include <sys/buf.h> 42 #include <sys/conf.h> 43 44 #include <uvm/uvm_extern.h> 45 46 #include <machine/cpu.h> 47 #include <machine/sid.h> 48 #include <machine/param.h> 49 #include <machine/vmparam.h> 50 #include <machine/nexus.h> 51 #include <machine/ioa.h> 52 #include <machine/ka820.h> 53 #include <machine/ka750.h> 54 #include <machine/ka650.h> 55 #include <machine/clock.h> 56 #include <machine/rpb.h> 57 #include <machine/bus.h> 58 59 #include <vax/vax/gencons.h> 60 61 #include <dev/bi/bireg.h> 62 63 #include "locators.h" 64 #include "opt_cputype.h" 65 66 void gencnslask __P((void)); 67 68 struct cpu_dep *dep_call; 69 struct device *booted_device; 70 int booted_partition; /* defaults to 0 (aka 'a' partition */ 71 72 struct evcnt softnet_intrcnt = 73 EVCNT_INITIALIZER(EVCNT_TYPE_INTR, NULL, "soft", "net"); 74 struct evcnt softserial_intrcnt = 75 EVCNT_INITIALIZER(EVCNT_TYPE_INTR, NULL, "soft", "serial"); 76 struct evcnt softclock_intrcnt = 77 EVCNT_INITIALIZER(EVCNT_TYPE_INTR, NULL, "soft", "clock"); 78 79 #define MAINBUS 0 80 81 void 82 cpu_configure(void) 83 { 84 85 if (config_rootfound("mainbus", NULL) == NULL) 86 panic("mainbus not configured"); 87 88 evcnt_attach_static(&softserial_intrcnt); 89 evcnt_attach_static(&softnet_intrcnt); 90 evcnt_attach_static(&softclock_intrcnt); 91 92 /* 93 * We're ready to start up. Clear CPU cold start flag. 94 * Soft cold-start flag will be cleared in configure(). 95 */ 96 if (dep_call->cpu_clrf) 97 (*dep_call->cpu_clrf)(); 98 } 99 100 void 101 cpu_rootconf(void) 102 { 103 /* 104 * The device we booted from are looked for during autoconfig. 105 * If there has been a match, it's already been done. 106 */ 107 108 #ifdef DEBUG 109 printf("booted from type %d unit %d csr 0x%lx adapter %lx slave %d\n", 110 rpb.devtyp, rpb.unit, rpb.csrphy, rpb.adpphy, rpb.slave); 111 #endif 112 printf("boot device: %s\n", 113 booted_device ? booted_device->dv_xname : "<unknown>"); 114 115 setroot(booted_device, booted_partition); 116 } 117 118 int mainbus_print __P((void *, const char *)); 119 int mainbus_match __P((struct device *, struct cfdata *, void *)); 120 void mainbus_attach __P((struct device *, struct device *, void *)); 121 122 int 123 mainbus_print(aux, hej) 124 void *aux; 125 const char *hej; 126 { 127 if (hej) 128 printf("nothing at %s", hej); 129 return (UNCONF); 130 } 131 132 int 133 mainbus_match(parent, cf, aux) 134 struct device *parent; 135 struct cfdata *cf; 136 void *aux; 137 { 138 return 1; /* First (and only) mainbus */ 139 } 140 141 void 142 mainbus_attach(parent, self, hej) 143 struct device *parent, *self; 144 void *hej; 145 { 146 147 printf("\n"); 148 149 /* 150 * Hopefully there a master bus? 151 * Maybe should have this as master instead of mainbus. 152 */ 153 config_found(self, NULL, mainbus_print); 154 155 #if VAX53 || VAXANY 156 /* Kludge: To have two master buses */ 157 if (vax_boardtype == VAX_BTYP_53) 158 config_found(self, (void *)1, mainbus_print); 159 #endif 160 161 if (dep_call->cpu_subconf) 162 (*dep_call->cpu_subconf)(self); 163 164 #if defined(COMPAT_14) 165 if (rpb.rpb_base == (void *)-1) 166 printf("\nWARNING: you must update your boot blocks.\n\n"); 167 #endif 168 169 } 170 171 CFATTACH_DECL(mainbus, sizeof(struct device), 172 mainbus_match, mainbus_attach, NULL, NULL); 173 174 #include "sd.h" 175 #include "cd.h" 176 #include "rl.h" 177 #include "ra.h" 178 #include "hp.h" 179 #include "ry.h" 180 181 static int ubtest(void *); 182 static int jmfr(char *, struct device *, int); 183 static int booted_qe(struct device *, void *); 184 static int booted_le(struct device *, void *); 185 static int booted_ze(struct device *, void *); 186 static int booted_de(struct device *, void *); 187 static int booted_ni(struct device *, void *); 188 #if NSD > 0 || NCD > 0 189 static int booted_sd(struct device *, void *); 190 #endif 191 #if NRL > 0 192 static int booted_rl(struct device *, void *); 193 #endif 194 #if NRA 195 static int booted_ra(struct device *, void *); 196 #endif 197 #if NHP 198 static int booted_hp(struct device *, void *); 199 #endif 200 #if NRD 201 static int booted_rd(struct device *, void *); 202 #endif 203 204 int (*devreg[])(struct device *, void *) = { 205 booted_qe, 206 booted_le, 207 booted_ze, 208 booted_de, 209 booted_ni, 210 #if NSD > 0 || NCD > 0 211 booted_sd, 212 #endif 213 #if NRL > 0 214 booted_rl, 215 #endif 216 #if NRA 217 booted_ra, 218 #endif 219 #if NHP 220 booted_hp, 221 #endif 222 #if NRD 223 booted_rd, 224 #endif 225 0, 226 }; 227 228 #define ubreg(x) ((x) & 017777) 229 230 void 231 device_register(struct device *dev, void *aux) 232 { 233 int (**dp)(struct device *, void *) = devreg; 234 235 /* If there's a synthetic RPB, we can't trust it */ 236 if (rpb.rpb_base == (void *)-1) 237 return; 238 239 while (*dp) { 240 if ((*dp)(dev, aux)) { 241 booted_device = dev; 242 break; 243 } 244 dp++; 245 } 246 } 247 248 /* 249 * Simple checks. Return 1 on fail. 250 */ 251 int 252 jmfr(char *n, struct device *dev, int nr) 253 { 254 if (rpb.devtyp != nr) 255 return 1; 256 return strcmp(n, dev->dv_cfdata->cf_name); 257 } 258 259 #include <dev/qbus/ubavar.h> 260 int 261 ubtest(void *aux) 262 { 263 paddr_t p; 264 265 p = kvtophys(((struct uba_attach_args *)aux)->ua_ioh); 266 if (rpb.csrphy != p) 267 return 1; 268 return 0; 269 } 270 271 #if 1 /* NNI */ 272 #include <dev/bi/bivar.h> 273 int 274 booted_ni(struct device *dev, void *aux) 275 { 276 struct bi_attach_args *ba = aux; 277 278 if (jmfr("ni", dev, BDEV_NI) || (kvtophys(ba->ba_ioh) != rpb.csrphy)) 279 return 0; 280 281 return 1; 282 } 283 #endif /* NNI */ 284 285 #if 1 /* NDE */ 286 int 287 booted_de(struct device *dev, void *aux) 288 { 289 290 if (jmfr("de", dev, BDEV_DE) || ubtest(aux)) 291 return 0; 292 293 return 1; 294 } 295 #endif /* NDE */ 296 297 int 298 booted_le(struct device *dev, void *aux) 299 { 300 if (jmfr("le", dev, BDEV_LE)) 301 return 0; 302 return 1; 303 } 304 305 int 306 booted_ze(struct device *dev, void *aux) 307 { 308 if (jmfr("ze", dev, BDEV_ZE)) 309 return 0; 310 return 1; 311 } 312 313 #if 1 /* NQE */ 314 int 315 booted_qe(struct device *dev, void *aux) 316 { 317 if (jmfr("qe", dev, BDEV_QE) || ubtest(aux)) 318 return 0; 319 320 return 1; 321 } 322 #endif /* NQE */ 323 324 #if NSD > 0 || NCD > 0 325 #include <dev/scsipi/scsipi_all.h> 326 #include <dev/scsipi/scsipiconf.h> 327 int 328 booted_sd(struct device *dev, void *aux) 329 { 330 struct scsipibus_attach_args *sa = aux; 331 struct device *ppdev; 332 333 /* Is this a SCSI device? */ 334 if (jmfr("sd", dev, BDEV_SD) && jmfr("cd", dev, BDEV_SD)) 335 return 0; 336 337 if (sa->sa_periph->periph_channel->chan_bustype->bustype_type != 338 SCSIPI_BUSTYPE_SCSI) 339 return 0; /* ``Cannot happen'' */ 340 341 if (sa->sa_periph->periph_target != (rpb.unit/100) || 342 sa->sa_periph->periph_lun != (rpb.unit % 100)) 343 return 0; /* Wrong unit */ 344 345 ppdev = dev->dv_parent->dv_parent; 346 347 /* VS3100 NCR 53C80 (si) & VS4000 NCR 53C94 (asc) */ 348 if (((jmfr("si", ppdev, BDEV_SD) == 0) || /* new name */ 349 (jmfr("asc", ppdev, BDEV_SD) == 0)) && 350 (ppdev->dv_cfdata->cf_loc[0] == rpb.csrphy)) 351 return 1; 352 353 return 0; /* Where did we come from??? */ 354 } 355 #endif 356 #if NRL > 0 357 #include <dev/qbus/rlvar.h> 358 int 359 booted_rl(struct device *dev, void *aux) 360 { 361 struct rlc_attach_args *raa = aux; 362 static int ub; 363 364 if (jmfr("rlc", dev, BDEV_RL) == 0) 365 ub = ubtest(aux); 366 if (ub) 367 return 0; 368 if (jmfr("rl", dev, BDEV_RL)) 369 return 0; 370 if (raa->hwid != rpb.unit) 371 return 0; /* Wrong unit number */ 372 return 1; 373 } 374 #endif 375 376 #if NRA 377 #include <dev/mscp/mscp.h> 378 #include <dev/mscp/mscpreg.h> 379 #include <dev/mscp/mscpvar.h> 380 int 381 booted_ra(struct device *dev, void *aux) 382 { 383 struct drive_attach_args *da = aux; 384 struct mscp_softc *pdev = (void *)dev->dv_parent; 385 paddr_t ioaddr; 386 387 if (jmfr("ra", dev, BDEV_UDA)) 388 return 0; 389 390 if (da->da_mp->mscp_unit != rpb.unit) 391 return 0; /* Wrong unit number */ 392 393 ioaddr = kvtophys(pdev->mi_iph); /* Get phys addr of CSR */ 394 if (rpb.devtyp == BDEV_UDA && rpb.csrphy == ioaddr) 395 return 1; /* Did match CSR */ 396 397 return 0; 398 } 399 #endif 400 #if NHP 401 #include <vax/mba/mbavar.h> 402 int 403 booted_hp(struct device *dev, void *aux) 404 { 405 static int mbaaddr; 406 407 /* Save last adapter address */ 408 if (jmfr("mba", dev, BDEV_HP) == 0) { 409 struct sbi_attach_args *sa = aux; 410 411 mbaaddr = kvtophys(sa->sa_ioh); 412 return 0; 413 } 414 415 if (jmfr("hp", dev, BDEV_HP)) 416 return 0; 417 418 if (((struct mba_attach_args *)aux)->ma_unit != rpb.unit) 419 return 0; 420 421 if (mbaaddr != rpb.adpphy) 422 return 0; 423 424 return 1; 425 } 426 #endif 427 #if NRD 428 int 429 booted_rd(struct device *dev, void *aux) 430 { 431 int *nr = aux; /* XXX - use the correct attach struct */ 432 433 if (jmfr("rd", dev, BDEV_RD)) 434 return 0; 435 436 if (*nr != rpb.unit) 437 return 0; 438 439 return 1; 440 } 441 #endif 442