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