autoconf.c revision 1.77
1/* $NetBSD: autoconf.c,v 1.77 2000/06/10 19:34:46 frueauf Exp $ */ 2 3/* 4 * Copyright (c) 1994 Christian E. Hopps 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 by Christian E. Hopps. 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#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/reboot.h> 35#include <sys/conf.h> 36#include <sys/buf.h> 37#include <sys/device.h> 38#include <sys/disklabel.h> 39#include <sys/disk.h> 40#include <machine/cpu.h> 41#include <amiga/amiga/cfdev.h> 42#include <amiga/amiga/device.h> 43#include <amiga/amiga/custom.h> 44 45static void findroot __P((void)); 46void mbattach __P((struct device *, struct device *, void *)); 47int mbprint __P((void *, const char *)); 48int mbmatch __P((struct device *, struct cfdata *, void *)); 49 50#include <sys/kernel.h> 51 52u_long boot_partition; 53struct device *booted_device; 54int booted_partition; 55 56/* 57 * called at boot time, configure all devices on system 58 */ 59void 60cpu_configure() 61{ 62 int s; 63#ifdef DEBUG_KERNEL_START 64 int i; 65#endif 66 67 /* 68 * this is the real thing baby (i.e. not console init) 69 */ 70 amiga_realconfig = 1; 71#ifdef DRACO 72 if (is_draco()) { 73 *draco_intena &= ~DRIRQ_GLOBAL; 74 } else 75#endif 76 custom.intena = INTF_INTEN; 77 s = splhigh(); 78 79 if (config_rootfound("mainbus", "mainbus") == NULL) 80 panic("no mainbus found"); 81 82#ifdef DEBUG_KERNEL_START 83 printf("survived autoconf, going to enable interrupts\n"); 84#endif 85 86#ifdef DRACO 87 if (is_draco()) { 88 *draco_intena |= DRIRQ_GLOBAL; 89 /* softints always enabled */ 90 } else 91#endif 92 { 93 custom.intena = INTF_SETCLR | INTF_INTEN; 94 95 /* also enable hardware aided software interrupts */ 96 custom.intena = INTF_SETCLR | INTF_SOFTINT; 97 } 98#ifdef DEBUG_KERNEL_START 99 for (i=splhigh(); i>=s ;i-=0x100) { 100 splx(i); 101 printf("%d...", (i>>8) & 7); 102 } 103 printf("survived interrupt enable\n"); 104#else 105 splx(s); 106#endif 107#ifdef DEBUG_KERNEL_START 108 printf("survived configure...\n"); 109#endif 110} 111 112void 113cpu_rootconf() 114{ 115 findroot(); 116#ifdef DEBUG_KERNEL_START 117 printf("survived findroot()\n"); 118#endif 119 setroot(booted_device, booted_partition); 120#ifdef DEBUG_KERNEL_START 121 printf("survived setroot()\n"); 122#endif 123} 124 125/*ARGSUSED*/ 126int 127simple_devprint(auxp, pnp) 128 void *auxp; 129 const char *pnp; 130{ 131 return(QUIET); 132} 133 134int 135matchname(fp, sp) 136 char *fp, *sp; 137{ 138 int len; 139 140 len = strlen(fp); 141 if (strlen(sp) != len) 142 return(0); 143 if (bcmp(fp, sp, len) == 0) 144 return(1); 145 return(0); 146} 147 148/* 149 * use config_search to find appropriate device, then call that device 150 * directly with NULL device variable storage. A device can then 151 * always tell the difference betwean the real and console init 152 * by checking for NULL. 153 */ 154int 155amiga_config_found(pcfp, pdp, auxp, pfn) 156 struct cfdata *pcfp; 157 struct device *pdp; 158 void *auxp; 159 cfprint_t pfn; 160{ 161 struct device temp; 162 struct cfdata *cf; 163 164 if (amiga_realconfig) 165 return(config_found(pdp, auxp, pfn) != NULL); 166 167 if (pdp == NULL) 168 pdp = &temp; 169 170 pdp->dv_cfdata = pcfp; 171 if ((cf = config_search((cfmatch_t)NULL, pdp, auxp)) != NULL) { 172 cf->cf_attach->ca_attach(pdp, NULL, auxp); 173 pdp->dv_cfdata = NULL; 174 return(1); 175 } 176 pdp->dv_cfdata = NULL; 177 return(0); 178} 179 180/* 181 * this function needs to get enough configured to do a console 182 * basically this means start attaching the grfxx's that support 183 * the console. Kinda hacky but it works. 184 */ 185void 186config_console() 187{ 188 struct cfdata *cf; 189 190 /* 191 * we need mainbus' cfdata. 192 */ 193 cf = config_rootsearch(NULL, "mainbus", "mainbus"); 194 if (cf == NULL) { 195 panic("no mainbus"); 196 } 197 /* 198 * delay clock calibration. 199 */ 200 amiga_config_found(cf, NULL, "clock", NULL); 201 202 /* 203 * internal grf. 204 */ 205#ifdef DRACO 206 if (!(is_draco())) 207#endif 208 amiga_config_found(cf, NULL, "grfcc", NULL); 209 210 /* 211 * zbus knows when its not for real and will 212 * only configure the appropriate hardware 213 */ 214 amiga_config_found(cf, NULL, "zbus", NULL); 215} 216 217/* 218 * mainbus driver 219 */ 220struct cfattach mainbus_ca = { 221 sizeof(struct device), mbmatch, mbattach 222}; 223 224int 225mbmatch(pdp, cfp, auxp) 226 struct device *pdp; 227 struct cfdata *cfp; 228 void *auxp; 229{ 230#if 0 /* 231 * XXX is this right? but we need to be found twice 232 * (early console init hack) 233 */ 234 static int mainbus_matched = 0; 235 236 /* Allow only one instance. */ 237 if (mainbus_matched) 238 return (0); 239 240 mainbus_matched = 1; 241#endif 242 return (1); 243} 244 245/* 246 * "find" all the things that should be there. 247 */ 248void 249mbattach(pdp, dp, auxp) 250 struct device *pdp, *dp; 251 void *auxp; 252{ 253 printf("\n"); 254 config_found(dp, "clock", simple_devprint); 255 if (is_a3000() || is_a4000()) { 256 config_found(dp, "a34kbbc", simple_devprint); 257 } else 258#ifdef DRACO 259 if (!is_draco()) 260#endif 261 { 262 config_found(dp, "a2kbbc", simple_devprint); 263 } 264#ifdef DRACO 265 if (is_draco()) { 266 config_found(dp, "drbbc", simple_devprint); 267 config_found(dp, "kbd", simple_devprint); 268 config_found(dp, "drsc", simple_devprint); 269 config_found(dp, "drsupio", simple_devprint); 270 } else 271#endif 272 { 273 config_found(dp, "ser", simple_devprint); 274 config_found(dp, "par", simple_devprint); 275 config_found(dp, "kbd", simple_devprint); 276 config_found(dp, "ms", simple_devprint); 277 config_found(dp, "grfcc", simple_devprint); 278 config_found(dp, "fdc", simple_devprint); 279 } 280 if (is_a4000() || is_a1200()) { 281 config_found(dp, "wdc", simple_devprint); 282 config_found(dp, "idesc", simple_devprint); 283 } 284 if (is_a4000()) /* Try to configure A4000T SCSI */ 285 config_found(dp, "afsc", simple_devprint); 286 if (is_a3000()) 287 config_found(dp, "ahsc", simple_devprint); 288 if (/*is_a600() || */is_a1200()) 289 config_found(dp, "pccard", simple_devprint); 290#ifdef DRACO 291 if (!is_draco()) 292#endif 293 config_found(dp, "aucc", simple_devprint); 294 295 config_found(dp, "zbus", simple_devprint); 296} 297 298int 299mbprint(auxp, pnp) 300 void *auxp; 301 const char *pnp; 302{ 303 if (pnp) 304 printf("%s at %s", (char *)auxp, pnp); 305 return(UNCONF); 306} 307 308/* 309 * The system will assign the "booted device" indicator (and thus 310 * rootdev if rootspec is wildcarded) to the first partition 'a' 311 * in preference of boot. However, it does walk unit backwards 312 * to remain compatible with the old Amiga method of picking the 313 * last root found. 314 */ 315#include <sys/fcntl.h> /* XXXX and all that uses it */ 316#include <sys/proc.h> /* XXXX and all that uses it */ 317 318#include "fd.h" 319#include "sd.h" 320#include "cd.h" 321#include "wd.h" 322 323#if NFD > 0 324extern struct cfdriver fd_cd; 325#endif 326#if NSD > 0 327extern struct cfdriver sd_cd; 328#endif 329#if NCD > 0 330extern struct cfdriver cd_cd; 331#endif 332#if NWD > 0 333extern struct cfdriver wd_cd; 334#endif 335 336struct cfdriver *genericconf[] = { 337#if NFD > 0 338 &fd_cd, 339#endif 340#if NSD > 0 341 &sd_cd, 342#endif 343#if NWD > 0 344 &wd_cd, 345#endif 346#if NCD > 0 347 &cd_cd, 348#endif 349 NULL, 350}; 351 352void 353findroot(void) 354{ 355 struct disk *dkp; 356 struct partition *pp; 357 struct device **devs; 358 int i, maj, unit; 359 360#if NSD > 0 361 /* 362 * If we have the boot partition offset (boot_partition), try 363 * to locate the device corresponding to that partition. 364 */ 365#ifdef DEBUG_KERNEL_START 366 printf("Boot partition offset is %ld\n", boot_partition); 367#endif 368 if (boot_partition != 0) { 369 struct bdevsw *bdp; 370 int i; 371 372 for (unit = 0; unit < sd_cd.cd_ndevs; ++unit) { 373#ifdef DEBUG_KERNEL_START 374 printf("probing for sd%d\n", unit); 375#endif 376 if (sd_cd.cd_devs[unit] == NULL) 377 continue; 378 379 /* 380 * Find the disk corresponding to the current 381 * device. 382 */ 383 devs = (struct device **)sd_cd.cd_devs; 384 if ((dkp = disk_find(devs[unit]->dv_xname)) == NULL) 385 continue; 386 387 if (dkp->dk_driver == NULL || 388 dkp->dk_driver->d_strategy == NULL) 389 continue; 390 for (bdp = bdevsw; bdp < (bdevsw + nblkdev); bdp++) 391 if (bdp->d_strategy == 392 dkp->dk_driver->d_strategy) 393 break; 394 if (bdp->d_open(MAKEDISKDEV(4, unit, RAW_PART), 395 FREAD | FNONBLOCK, 0, curproc)) 396 continue; 397 bdp->d_close(MAKEDISKDEV(4, unit, RAW_PART), 398 FREAD | FNONBLOCK, 0, curproc); 399 pp = &dkp->dk_label->d_partitions[0]; 400 for (i = 0; i < dkp->dk_label->d_npartitions; 401 i++, pp++) { 402#ifdef DEBUG_KERNEL_START 403 printf("sd%d%c type %d offset %d size %d\n", 404 unit, i+'a', pp->p_fstype, 405 pp->p_offset, pp->p_size); 406#endif 407 if (pp->p_size == 0 || 408 (pp->p_fstype != FS_BSDFFS && 409 pp->p_fstype != FS_SWAP)) 410 continue; 411 if (pp->p_offset == boot_partition) { 412 if (booted_device == NULL) { 413 booted_device = devs[unit]; 414 booted_partition = i; 415 } else 416 printf("Ambiguous boot device\n"); 417 } 418 } 419 } 420 } 421 if (booted_device != NULL) 422 return; /* we found the boot device */ 423#endif 424 425 for (i = 0; genericconf[i] != NULL; i++) { 426 for (unit = genericconf[i]->cd_ndevs - 1; unit >= 0; unit--) { 427 if (genericconf[i]->cd_devs[unit] == NULL) 428 continue; 429 430 /* 431 * Find the disk structure corresponding to the 432 * current device. 433 */ 434 devs = (struct device **)genericconf[i]->cd_devs; 435 if ((dkp = disk_find(devs[unit]->dv_xname)) == NULL) 436 continue; 437 438 if (dkp->dk_driver == NULL || 439 dkp->dk_driver->d_strategy == NULL) 440 continue; 441 442 for (maj = 0; maj < nblkdev; maj++) 443 if (bdevsw[maj].d_strategy == 444 dkp->dk_driver->d_strategy) 445 break; 446#ifdef DIAGNOSTIC 447 if (maj >= nblkdev) 448 panic("findroot: impossible"); 449#endif 450 451 /* Open disk; forces read of disklabel. */ 452 if ((*bdevsw[maj].d_open)(MAKEDISKDEV(maj, 453 unit, 0), FREAD|FNONBLOCK, 0, &proc0)) 454 continue; 455 (void)(*bdevsw[maj].d_close)(MAKEDISKDEV(maj, 456 unit, 0), FREAD|FNONBLOCK, 0, &proc0); 457 458 pp = &dkp->dk_label->d_partitions[0]; 459 if (pp->p_size != 0 && pp->p_fstype == FS_BSDFFS) { 460 booted_device = devs[unit]; 461 booted_partition = 0; 462 return; 463 } 464 } 465 } 466} 467 468/* 469 * Try to determine, of this machine is an A3000, which has a builtin 470 * realtime clock and scsi controller, so that this hardware is only 471 * included as "configured" if this IS an A3000 472 */ 473 474int a3000_flag = 1; /* patchable */ 475#ifdef A4000 476int a4000_flag = 1; /* patchable - default to A4000 */ 477#else 478int a4000_flag = 0; /* patchable */ 479#endif 480 481int 482is_a3000() 483{ 484 /* this is a dirty kludge.. but how do you do this RIGHT ? :-) */ 485 extern long boot_fphystart; 486 short sc; 487 488 if ((machineid >> 16) == 3000) 489 return (1); /* It's an A3000 */ 490 if (machineid >> 16) 491 return (0); /* It's not an A3000 */ 492 /* Machine type is unknown, so try to guess it */ 493 /* where is fastram on the A4000 ?? */ 494 /* if fastram is below 0x07000000, assume it's not an A3000 */ 495 if (boot_fphystart < 0x07000000) 496 return(0); 497 /* 498 * OK, fastram starts at or above 0x07000000, check specific 499 * machines 500 */ 501 for (sc = 0; sc < ncfdev; sc++) { 502 switch (cfdev[sc].rom.manid) { 503 case 2026: /* Progressive Peripherals, Inc */ 504 switch (cfdev[sc].rom.prodid) { 505 case 0: /* PPI Mercury - A3000 */ 506 case 1: /* PP&S A3000 '040 */ 507 return(1); 508 case 150: /* PPI Zeus - it's an A2000 */ 509 case 105: /* PP&S A2000 '040 */ 510 case 187: /* PP&S A500 '040 */ 511 return(0); 512 } 513 break; 514 515 case 2112: /* IVS */ 516 switch (cfdev[sc].rom.prodid) { 517 case 242: 518 return(0); /* A2000 accelerator? */ 519 } 520 break; 521 } 522 } 523 return (a3000_flag); /* XXX let flag tell now */ 524} 525 526int 527is_a4000() 528{ 529 if ((machineid >> 16) == 4000) 530 return (1); /* It's an A4000 */ 531 if ((machineid >> 16) == 1200) 532 return (0); /* It's an A1200, so not A4000 */ 533#ifdef DRACO 534 if (is_draco()) 535 return (0); 536#endif 537 /* Do I need this any more? */ 538 if ((custom.deniseid & 0xff) == 0xf8) 539 return (1); 540#ifdef DEBUG 541 if (a4000_flag) 542 printf("Denise ID = %04x\n", (unsigned short)custom.deniseid); 543#endif 544 if (machineid >> 16) 545 return (0); /* It's not an A4000 */ 546 return (a4000_flag); /* Machine type not set */ 547} 548 549int 550is_a1200() 551{ 552 if ((machineid >> 16) == 1200) 553 return (1); /* It's an A1200 */ 554 return (0); /* Machine type not set */ 555} 556