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