autoconf.c revision 1.83
1/* $NetBSD: autoconf.c,v 1.83 2002/09/27 20:29:42 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.83 2002/09/27 20:29:42 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 /* 197 * we need mainbus' cfdata. 198 */ 199 cf = config_rootsearch(NULL, "mainbus", "mainbus"); 200 if (cf == NULL) { 201 panic("no mainbus"); 202 } 203 /* 204 * delay clock calibration. 205 */ 206 amiga_config_found(cf, NULL, "clock", NULL); 207 208 /* 209 * internal grf. 210 */ 211#ifdef DRACO 212 if (!(is_draco())) 213#endif 214 amiga_config_found(cf, NULL, "grfcc", NULL); 215 216 /* 217 * zbus knows when its not for real and will 218 * only configure the appropriate hardware 219 */ 220 amiga_config_found(cf, NULL, "zbus", NULL); 221} 222 223/* 224 * mainbus driver 225 */ 226const struct cfattach mainbus_ca = { 227 sizeof(struct device), mbmatch, mbattach 228}; 229 230int 231mbmatch(pdp, cfp, auxp) 232 struct device *pdp; 233 struct cfdata *cfp; 234 void *auxp; 235{ 236#if 0 /* 237 * XXX is this right? but we need to be found twice 238 * (early console init hack) 239 */ 240 static int mainbus_matched = 0; 241 242 /* Allow only one instance. */ 243 if (mainbus_matched) 244 return (0); 245 246 mainbus_matched = 1; 247#endif 248 return (1); 249} 250 251/* 252 * "find" all the things that should be there. 253 */ 254void 255mbattach(pdp, dp, auxp) 256 struct device *pdp, *dp; 257 void *auxp; 258{ 259 printf("\n"); 260 config_found(dp, "clock", simple_devprint); 261 if (is_a3000() || is_a4000()) { 262 config_found(dp, "a34kbbc", simple_devprint); 263 } else 264#ifdef DRACO 265 if (!is_draco()) 266#endif 267 { 268 config_found(dp, "a2kbbc", simple_devprint); 269 } 270#ifdef DRACO 271 if (is_draco()) { 272 config_found(dp, "drbbc", simple_devprint); 273 config_found(dp, "kbd", simple_devprint); 274 config_found(dp, "drsc", simple_devprint); 275 config_found(dp, "drsupio", simple_devprint); 276 } else 277#endif 278 { 279 config_found(dp, "ser", simple_devprint); 280 config_found(dp, "par", simple_devprint); 281 config_found(dp, "kbd", simple_devprint); 282 config_found(dp, "ms", simple_devprint); 283 config_found(dp, "grfcc", simple_devprint); 284 config_found(dp, "amidisplaycc", simple_devprint); 285 config_found(dp, "fdc", simple_devprint); 286 } 287 if (is_a4000() || is_a1200()) { 288 config_found(dp, "wdc", simple_devprint); 289 config_found(dp, "idesc", simple_devprint); 290 } 291 if (is_a4000()) /* Try to configure A4000T SCSI */ 292 config_found(dp, "afsc", simple_devprint); 293 if (is_a3000()) 294 config_found(dp, "ahsc", simple_devprint); 295 if (/*is_a600() || */is_a1200()) 296 config_found(dp, "pccard", simple_devprint); 297#ifdef DRACO 298 if (!is_draco()) 299#endif 300 config_found(dp, "aucc", simple_devprint); 301 302 config_found(dp, "zbus", simple_devprint); 303} 304 305int 306mbprint(auxp, pnp) 307 void *auxp; 308 const char *pnp; 309{ 310 if (pnp) 311 printf("%s at %s", (char *)auxp, pnp); 312 return(UNCONF); 313} 314 315/* 316 * The system will assign the "booted device" indicator (and thus 317 * rootdev if rootspec is wildcarded) to the first partition 'a' 318 * in preference of boot. However, it does walk unit backwards 319 * to remain compatible with the old Amiga method of picking the 320 * last root found. 321 */ 322#include <sys/fcntl.h> /* XXXX and all that uses it */ 323#include <sys/proc.h> /* XXXX and all that uses it */ 324 325#include "fd.h" 326#include "sd.h" 327#include "cd.h" 328#include "wd.h" 329 330#if NFD > 0 331extern struct cfdriver fd_cd; 332extern const struct bdevsw fd_bdevsw; 333#endif 334#if NSD > 0 335extern struct cfdriver sd_cd; 336extern const struct bdevsw sd_bdevsw; 337#endif 338#if NCD > 0 339extern struct cfdriver cd_cd; 340extern const struct bdevsw cd_bdevsw; 341#endif 342#if NWD > 0 343extern struct cfdriver wd_cd; 344extern const struct bdevsw wd_bdevsw; 345#endif 346 347struct cfdriver *genericconf[] = { 348#if NFD > 0 349 &fd_cd, 350#endif 351#if NSD > 0 352 &sd_cd, 353#endif 354#if NWD > 0 355 &wd_cd, 356#endif 357#if NCD > 0 358 &cd_cd, 359#endif 360 NULL, 361}; 362 363void 364findroot(void) 365{ 366 struct disk *dkp; 367 struct partition *pp; 368 struct device **devs; 369 int i, maj, unit; 370 const struct bdevsw *bdp; 371 372#if NSD > 0 373 /* 374 * If we have the boot partition offset (boot_partition), try 375 * to locate the device corresponding to that partition. 376 */ 377#ifdef DEBUG_KERNEL_START 378 printf("Boot partition offset is %ld\n", boot_partition); 379#endif 380 if (boot_partition != 0) { 381 int i; 382 383 for (unit = 0; unit < sd_cd.cd_ndevs; ++unit) { 384#ifdef DEBUG_KERNEL_START 385 printf("probing for sd%d\n", unit); 386#endif 387 if (sd_cd.cd_devs[unit] == NULL) 388 continue; 389 390 /* 391 * Find the disk corresponding to the current 392 * device. 393 */ 394 devs = (struct device **)sd_cd.cd_devs; 395 if ((dkp = disk_find(devs[unit]->dv_xname)) == NULL) 396 continue; 397 398 if (dkp->dk_driver == NULL || 399 dkp->dk_driver->d_strategy == NULL) 400 continue; 401 bdp = &sd_bdevsw; 402 maj = bdevsw_lookup_major(bdp); 403 if ((*bdp->d_open)(MAKEDISKDEV(maj, unit, RAW_PART), 404 FREAD | FNONBLOCK, 0, curproc)) 405 continue; 406 (*bdp->d_close)(MAKEDISKDEV(maj, unit, RAW_PART), 407 FREAD | FNONBLOCK, 0, curproc); 408 pp = &dkp->dk_label->d_partitions[0]; 409 for (i = 0; i < dkp->dk_label->d_npartitions; 410 i++, pp++) { 411#ifdef DEBUG_KERNEL_START 412 printf("sd%d%c type %d offset %d size %d\n", 413 unit, i+'a', pp->p_fstype, 414 pp->p_offset, pp->p_size); 415#endif 416 if (pp->p_size == 0 || 417 (pp->p_fstype != FS_BSDFFS && 418 pp->p_fstype != FS_SWAP)) 419 continue; 420 if (pp->p_offset == boot_partition) { 421 if (booted_device == NULL) { 422 booted_device = devs[unit]; 423 booted_partition = i; 424 } else 425 printf("Ambiguous boot device\n"); 426 } 427 } 428 } 429 } 430 if (booted_device != NULL) 431 return; /* we found the boot device */ 432#endif 433 434 for (i = 0; genericconf[i] != NULL; i++) { 435 for (unit = genericconf[i]->cd_ndevs - 1; unit >= 0; unit--) { 436 if (genericconf[i]->cd_devs[unit] == NULL) 437 continue; 438 439 /* 440 * Find the disk structure corresponding to the 441 * current device. 442 */ 443 devs = (struct device **)genericconf[i]->cd_devs; 444 if ((dkp = disk_find(devs[unit]->dv_xname)) == NULL) 445 continue; 446 447 if (dkp->dk_driver == NULL || 448 dkp->dk_driver->d_strategy == NULL) 449 continue; 450 451#if NFD > 0 452 if (fd_bdevsw.d_strategy == dkp->dk_driver->d_strategy) 453 bdp = &fd_bdevsw; 454#endif 455#if NSD > 0 456 if (sd_bdevsw.d_strategy == dkp->dk_driver->d_strategy) 457 bdp = &sd_bdevsw; 458#endif 459#if NWD > 0 460 if (wd_bdevsw.d_strategy == dkp->dk_driver->d_strategy) 461 bdp = &wd_bdevsw; 462#endif 463#if NCD > 0 464 if (cd_bdevsw.d_strategy == dkp->dk_driver->d_strategy) 465 bdp = &cd_bdevsw; 466#endif 467#ifdef DIAGNOSTIC 468 if (bdp == NULL) 469 panic("findroot: impossible"); 470#endif 471 maj = bdevsw_lookup_major(bdp); 472 473 /* Open disk; forces read of disklabel. */ 474 if ((*bdp->d_open)(MAKEDISKDEV(maj, 475 unit, 0), FREAD|FNONBLOCK, 0, &proc0)) 476 continue; 477 (void)(*bdp->d_close)(MAKEDISKDEV(maj, 478 unit, 0), FREAD|FNONBLOCK, 0, &proc0); 479 480 pp = &dkp->dk_label->d_partitions[0]; 481 if (pp->p_size != 0 && pp->p_fstype == FS_BSDFFS) { 482 booted_device = devs[unit]; 483 booted_partition = 0; 484 return; 485 } 486 } 487 } 488} 489 490/* 491 * Try to determine, of this machine is an A3000, which has a builtin 492 * realtime clock and scsi controller, so that this hardware is only 493 * included as "configured" if this IS an A3000 494 */ 495 496int a3000_flag = 1; /* patchable */ 497#ifdef A4000 498int a4000_flag = 1; /* patchable - default to A4000 */ 499#else 500int a4000_flag = 0; /* patchable */ 501#endif 502 503int 504is_a3000() 505{ 506 /* this is a dirty kludge.. but how do you do this RIGHT ? :-) */ 507 extern long boot_fphystart; 508 short sc; 509 510 if ((machineid >> 16) == 3000) 511 return (1); /* It's an A3000 */ 512 if (machineid >> 16) 513 return (0); /* It's not an A3000 */ 514 /* Machine type is unknown, so try to guess it */ 515 /* where is fastram on the A4000 ?? */ 516 /* if fastram is below 0x07000000, assume it's not an A3000 */ 517 if (boot_fphystart < 0x07000000) 518 return(0); 519 /* 520 * OK, fastram starts at or above 0x07000000, check specific 521 * machines 522 */ 523 for (sc = 0; sc < ncfdev; sc++) { 524 switch (cfdev[sc].rom.manid) { 525 case 2026: /* Progressive Peripherals, Inc */ 526 switch (cfdev[sc].rom.prodid) { 527 case 0: /* PPI Mercury - A3000 */ 528 case 1: /* PP&S A3000 '040 */ 529 return(1); 530 case 150: /* PPI Zeus - it's an A2000 */ 531 case 105: /* PP&S A2000 '040 */ 532 case 187: /* PP&S A500 '040 */ 533 return(0); 534 } 535 break; 536 537 case 2112: /* IVS */ 538 switch (cfdev[sc].rom.prodid) { 539 case 242: 540 return(0); /* A2000 accelerator? */ 541 } 542 break; 543 } 544 } 545 return (a3000_flag); /* XXX let flag tell now */ 546} 547 548int 549is_a4000() 550{ 551 if ((machineid >> 16) == 4000) 552 return (1); /* It's an A4000 */ 553 if ((machineid >> 16) == 1200) 554 return (0); /* It's an A1200, so not A4000 */ 555#ifdef DRACO 556 if (is_draco()) 557 return (0); 558#endif 559 /* Do I need this any more? */ 560 if ((custom.deniseid & 0xff) == 0xf8) 561 return (1); 562#ifdef DEBUG 563 if (a4000_flag) 564 printf("Denise ID = %04x\n", (unsigned short)custom.deniseid); 565#endif 566 if (machineid >> 16) 567 return (0); /* It's not an A4000 */ 568 return (a4000_flag); /* Machine type not set */ 569} 570 571int 572is_a1200() 573{ 574 if ((machineid >> 16) == 1200) 575 return (1); /* It's an A1200 */ 576 return (0); /* Machine type not set */ 577} 578