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