autoconf.c revision 1.120
11.120Sthorpej/*	$NetBSD: autoconf.c,v 1.120 2021/08/07 16:18:41 thorpej Exp $	*/
21.25Scgd
31.1Smw/*
41.17Schopps * Copyright (c) 1994 Christian E. Hopps
51.1Smw * All rights reserved.
61.1Smw *
71.1Smw * Redistribution and use in source and binary forms, with or without
81.1Smw * modification, are permitted provided that the following conditions
91.1Smw * are met:
101.1Smw * 1. Redistributions of source code must retain the above copyright
111.1Smw *    notice, this list of conditions and the following disclaimer.
121.1Smw * 2. Redistributions in binary form must reproduce the above copyright
131.1Smw *    notice, this list of conditions and the following disclaimer in the
141.1Smw *    documentation and/or other materials provided with the distribution.
151.1Smw * 3. All advertising materials mentioning features or use of this software
161.1Smw *    must display the following acknowledgement:
171.17Schopps *      This product includes software developed by Christian E. Hopps.
181.17Schopps * 4. The name of the author may not be used to endorse or promote products
191.17Schopps *    derived from this software without specific prior written permission
201.4Smw *
211.17Schopps * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
221.17Schopps * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
231.17Schopps * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
241.17Schopps * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
251.17Schopps * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
261.17Schopps * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
271.17Schopps * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
281.17Schopps * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
291.17Schopps * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
301.17Schopps * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
311.1Smw */
321.80Saymeric
331.80Saymeric#include <sys/cdefs.h>
341.120Sthorpej__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.120 2021/08/07 16:18:41 thorpej Exp $");
351.80Saymeric
361.9Schopps#include <sys/param.h>
371.9Schopps#include <sys/systm.h>
381.17Schopps#include <sys/reboot.h>
391.9Schopps#include <sys/conf.h>
401.46Sthorpej#include <sys/buf.h>
411.17Schopps#include <sys/device.h>
421.17Schopps#include <sys/disklabel.h>
431.46Sthorpej#include <sys/disk.h>
441.90Sthorpej#include <sys/proc.h>
451.19Schopps#include <machine/cpu.h>
461.17Schopps#include <amiga/amiga/cfdev.h>
471.17Schopps#include <amiga/amiga/device.h>
481.9Schopps#include <amiga/amiga/custom.h>
491.104Sphx#ifdef DRACO
501.104Sphx#include <amiga/amiga/drcustom.h>
511.104Sphx#endif
521.112Srkujawa#ifdef P5PB_CONSOLE
531.112Srkujawa#include <amiga/pci/p5pbvar.h>
541.112Srkujawa#endif /* P5PB_CONSOLE */
551.1Smw
561.116Srkujawa#include "acafh.h"
571.116Srkujawa#if NACAFH > 0
581.116Srkujawa#include <amiga/dev/acafhvar.h>
591.116Srkujawa#endif /* NACAFH > 0 */
601.115Srkujawa
611.79Saymericstatic void findroot(void);
621.107Smattvoid mbattach(device_t, device_t, void *);
631.79Saymericint mbprint(void *, const char *);
641.107Smattint mbmatch(device_t, cfdata_t, void *);
651.11Schopps
661.17Schopps#include <sys/kernel.h>
671.46Sthorpej
681.47Smhitchu_long boot_partition;
691.81Saymeric
701.81Saymericint amiga_realconfig;
711.46Sthorpej
721.1Smw/*
731.17Schopps * called at boot time, configure all devices on system
741.1Smw */
751.11Schoppsvoid
761.102Sceggercpu_configure(void)
771.1Smw{
781.44Sis	int s;
791.62Sis#ifdef DEBUG_KERNEL_START
801.62Sis	int i;
811.62Sis#endif
821.49Sgwr
831.17Schopps	/*
841.17Schopps	 * this is the real thing baby (i.e. not console init)
851.17Schopps	 */
861.17Schopps	amiga_realconfig = 1;
871.36Sis#ifdef DRACO
881.36Sis	if (is_draco()) {
891.36Sis		*draco_intena &= ~DRIRQ_GLOBAL;
901.36Sis	} else
911.36Sis#endif
921.3Smw	custom.intena = INTF_INTEN;
931.44Sis	s = splhigh();
941.1Smw
951.95Sjmc	if (config_rootfound("mainbus", NULL) == NULL)
961.17Schopps		panic("no mainbus found");
971.36Sis
981.39Sis#ifdef DEBUG_KERNEL_START
991.43Schristos	printf("survived autoconf, going to enable interrupts\n");
1001.39Sis#endif
1011.79Saymeric
1021.36Sis#ifdef DRACO
1031.36Sis	if (is_draco()) {
1041.36Sis		*draco_intena |= DRIRQ_GLOBAL;
1051.36Sis		/* softints always enabled */
1061.36Sis	} else
1071.36Sis#endif
1081.36Sis	{
1091.36Sis		custom.intena = INTF_SETCLR | INTF_INTEN;
1101.28Schopps
1111.36Sis		/* also enable hardware aided software interrupts */
1121.36Sis		custom.intena = INTF_SETCLR | INTF_SOFTINT;
1131.36Sis	}
1141.39Sis#ifdef DEBUG_KERNEL_START
1151.62Sis	for (i=splhigh(); i>=s ;i-=0x100) {
1161.62Sis		splx(i);
1171.62Sis		printf("%d...", (i>>8) & 7);
1181.62Sis	}
1191.43Schristos	printf("survived interrupt enable\n");
1201.62Sis#else
1211.62Sis	splx(s);
1221.39Sis#endif
1231.63Sthorpej#ifdef DEBUG_KERNEL_START
1241.63Sthorpej	printf("survived configure...\n");
1251.63Sthorpej#endif
1261.49Sgwr}
1271.49Sgwr
1281.49Sgwrvoid
1291.102Sceggercpu_rootconf(void)
1301.49Sgwr{
1311.77Sfrueauf	findroot();
1321.39Sis#ifdef DEBUG_KERNEL_START
1331.46Sthorpej	printf("survived findroot()\n");
1341.39Sis#endif
1351.113Smlelstv	rootconf();
1361.17Schopps}
1371.3Smw
1381.17Schopps/*ARGSUSED*/
1391.17Schoppsint
1401.114Schssimple_devprint(void *aux, const char *pnp)
1411.17Schopps{
1421.17Schopps	return(QUIET);
1431.1Smw}
1441.1Smw
1451.17Schoppsint
1461.101Sdslmatchname(const char *fp, const char *sp)
1471.17Schopps{
1481.17Schopps	int len;
1491.1Smw
1501.17Schopps	len = strlen(fp);
1511.17Schopps	if (strlen(sp) != len)
1521.17Schopps		return(0);
1531.103Scegger	if (memcmp(fp, sp, len) == 0)
1541.17Schopps		return(1);
1551.17Schopps	return(0);
1561.17Schopps}
1571.1Smw
1581.17Schopps/*
1591.96Sdrochner * use config_search_ia to find appropriate device, then call that device
1601.79Saymeric * directly with NULL device variable storage.  A device can then
1611.79Saymeric * always tell the difference betwean the real and console init
1621.17Schopps * by checking for NULL.
1631.17Schopps */
1641.11Schoppsint
1651.119Sthorpejamiga_config_found(cfdata_t pcfp, device_t parent, void *aux, cfprint_t pfn,
1661.120Sthorpej    const struct cfargs *cfargs)
1671.1Smw{
1681.17Schopps	struct device temp;
1691.107Smatt	cfdata_t cf;
1701.86Sthorpej	const struct cfattach *ca;
1711.119Sthorpej	int rv = 0;
1721.17Schopps
1731.119Sthorpej	if (amiga_realconfig) {
1741.120Sthorpej		rv = config_found(parent, aux, pfn, cfargs) != NULL;
1751.119Sthorpej		goto out;
1761.119Sthorpej	}
1771.17Schopps
1781.114Schs	if (parent == NULL) {
1791.89Saymeric		memset(&temp, 0, sizeof temp);
1801.114Schs		parent = &temp;
1811.89Saymeric	}
1821.17Schopps
1831.114Schs	parent->dv_cfdata = pcfp;
1841.114Schs	parent->dv_cfdriver = config_cfdriver_lookup(pcfp->cf_name);
1851.114Schs	parent->dv_unit = pcfp->cf_unit;
1861.89Saymeric
1871.120Sthorpej	if ((cf = config_search(parent, aux, cfargs)) != NULL) {
1881.86Sthorpej		ca = config_cfattach_lookup(cf->cf_name, cf->cf_atname);
1891.86Sthorpej		if (ca != NULL) {
1901.114Schs			(*ca->ca_attach)(parent, NULL, aux);
1911.119Sthorpej			rv = 1;
1921.86Sthorpej		}
1931.1Smw	}
1941.114Schs	parent->dv_cfdata = NULL;
1951.119Sthorpej out:
1961.119Sthorpej	return rv;
1971.17Schopps}
1981.17Schopps
1991.17Schopps/*
2001.17Schopps * this function needs to get enough configured to do a console
2011.79Saymeric * basically this means start attaching the grfxx's that support
2021.17Schopps * the console. Kinda hacky but it works.
2031.17Schopps */
2041.32Sveegovoid
2051.102Sceggerconfig_console(void)
2061.79Saymeric{
2071.107Smatt	cfdata_t cf;
2081.84Sthorpej
2091.84Sthorpej	config_init();
2101.36Sis
2111.17Schopps	/*
2121.17Schopps	 * we need mainbus' cfdata.
2131.17Schopps	 */
2141.95Sjmc	cf = config_rootsearch(NULL, "mainbus", NULL);
2151.36Sis	if (cf == NULL) {
2161.17Schopps		panic("no mainbus");
2171.36Sis	}
2181.114Schs
2191.1Smw	/*
2201.44Sis	 * delay clock calibration.
2211.44Sis	 */
2221.120Sthorpej	amiga_config_found(cf, NULL, __UNCONST("clock"), NULL, CFARGS_NONE);
2231.44Sis
2241.44Sis	/*
2251.17Schopps	 * internal grf.
2261.1Smw	 */
2271.36Sis#ifdef DRACO
2281.36Sis	if (!(is_draco()))
2291.36Sis#endif
2301.119Sthorpej		amiga_config_found(cf, NULL, __UNCONST("grfcc"), NULL,
2311.120Sthorpej		    CFARGS_NONE);
2321.67Saymeric
2331.1Smw	/*
2341.27Schopps	 * zbus knows when its not for real and will
2351.21Schopps	 * only configure the appropriate hardware
2361.1Smw	 */
2371.120Sthorpej	amiga_config_found(cf, NULL, __UNCONST("zbus"), NULL, CFARGS_NONE);
2381.1Smw}
2391.1Smw
2401.79Saymeric/*
2411.79Saymeric * mainbus driver
2421.17Schopps */
2431.107SmattCFATTACH_DECL_NEW(mainbus, 0,
2441.85Sthorpej    mbmatch, mbattach, NULL, NULL);
2451.17Schopps
2461.11Schoppsint
2471.114Schsmbmatch(device_t parent, cfdata_t cf, void *aux)
2481.1Smw{
2491.72Sis#if 0	/*
2501.72Sis	 * XXX is this right? but we need to be found twice
2511.72Sis	 * (early console init hack)
2521.72Sis	 */
2531.71Skleink	static int mainbus_matched = 0;
2541.30Sthorpej
2551.71Skleink	/* Allow only one instance. */
2561.71Skleink	if (mainbus_matched)
2571.71Skleink		return (0);
2581.71Skleink
2591.71Skleink	mainbus_matched = 1;
2601.72Sis#endif
2611.71Skleink	return (1);
2621.1Smw}
2631.1Smw
2641.1Smw/*
2651.17Schopps * "find" all the things that should be there.
2661.1Smw */
2671.11Schoppsvoid
2681.114Schsmbattach(device_t parent, device_t self, void *aux)
2691.1Smw{
2701.43Schristos	printf("\n");
2711.120Sthorpej	config_found(self, __UNCONST("clock"), simple_devprint, CFARGS_NONE);
2721.52Sis	if (is_a3000() || is_a4000()) {
2731.118Sthorpej		config_found(self, __UNCONST("a34kbbc"), simple_devprint,
2741.120Sthorpej		    CFARGS_NONE);
2751.58Sis	} else
2761.53Sis#ifdef DRACO
2771.58Sis	if (!is_draco())
2781.53Sis#endif
2791.58Sis	{
2801.118Sthorpej		config_found(self, __UNCONST("a2kbbc"), simple_devprint,
2811.120Sthorpej		    CFARGS_NONE);
2821.52Sis	}
2831.36Sis#ifdef DRACO
2841.36Sis	if (is_draco()) {
2851.118Sthorpej		config_found(self, __UNCONST("drbbc"), simple_devprint,
2861.120Sthorpej		    CFARGS_NONE);
2871.118Sthorpej		config_found(self, __UNCONST("kbd"), simple_devprint,
2881.120Sthorpej		    CFARGS_NONE);
2891.118Sthorpej		config_found(self, __UNCONST("drsc"), simple_devprint,
2901.120Sthorpej		    CFARGS_NONE);
2911.118Sthorpej		config_found(self, __UNCONST("drsupio"), simple_devprint,
2921.120Sthorpej		    CFARGS_NONE);
2931.79Saymeric	} else
2941.36Sis#endif
2951.36Sis	{
2961.118Sthorpej		config_found(self, __UNCONST("ser"), simple_devprint,
2971.120Sthorpej		    CFARGS_NONE);
2981.118Sthorpej		config_found(self, __UNCONST("par"), simple_devprint,
2991.120Sthorpej		    CFARGS_NONE);
3001.118Sthorpej		config_found(self, __UNCONST("kbd"), simple_devprint,
3011.120Sthorpej		    CFARGS_NONE);
3021.118Sthorpej		config_found(self, __UNCONST("ms"), simple_devprint,
3031.120Sthorpej		    CFARGS_NONE);
3041.118Sthorpej		config_found(self, __UNCONST("grfcc"), simple_devprint,
3051.120Sthorpej		    CFARGS_NONE);
3061.118Sthorpej		config_found(self, __UNCONST("amidisplaycc"), simple_devprint,
3071.120Sthorpej		    CFARGS_NONE);
3081.118Sthorpej		config_found(self, __UNCONST("fdc"), simple_devprint,
3091.120Sthorpej		    CFARGS_NONE);
3101.36Sis	}
3111.106Sphx	if (is_a4000() || is_a1200() || is_a600())
3121.118Sthorpej		config_found(self, __UNCONST("wdc"), simple_devprint,
3131.120Sthorpej		    CFARGS_NONE);
3141.29Schopps	if (is_a4000())			/* Try to configure A4000T SCSI */
3151.118Sthorpej		config_found(self, __UNCONST("afsc"), simple_devprint,
3161.120Sthorpej		    CFARGS_NONE);
3171.17Schopps	if (is_a3000())
3181.118Sthorpej		config_found(self, __UNCONST("ahsc"), simple_devprint,
3191.120Sthorpej		    CFARGS_NONE);
3201.106Sphx	if (is_a600() || is_a1200())
3211.118Sthorpej		config_found(self, __UNCONST("pccard"), simple_devprint,
3221.120Sthorpej		    CFARGS_NONE);
3231.111Srkujawa	if (is_a1200())
3241.118Sthorpej		config_found(self, __UNCONST("a1k2cp"), simple_devprint,
3251.120Sthorpej		    CFARGS_NONE);
3261.54Sis#ifdef DRACO
3271.54Sis	if (!is_draco())
3281.54Sis#endif
3291.118Sthorpej		config_found(self, __UNCONST("aucc"), simple_devprint,
3301.120Sthorpej		    CFARGS_NONE);
3311.54Sis
3321.116Srkujawa#if NACAFH > 0
3331.116Srkujawa	if (!is_a600() && !is_a1200() && !is_a3000() && !is_a4000())
3341.116Srkujawa		if (acafh_mbattach_probe() == true)
3351.118Sthorpej			config_found(self, __UNCONST("acafh"), simple_devprint,
3361.120Sthorpej			    CFARGS_NONE);
3371.115Srkujawa#endif
3381.115Srkujawa
3391.120Sthorpej	config_found(self, __UNCONST("zbus"), simple_devprint, CFARGS_NONE);
3401.1Smw}
3411.1Smw
3421.11Schoppsint
3431.114Schsmbprint(void *aux, const char *pnp)
3441.1Smw{
3451.17Schopps	if (pnp)
3461.114Schs		aprint_normal("%s at %s", (char *)aux, pnp);
3471.17Schopps	return(UNCONF);
3481.1Smw}
3491.1Smw
3501.46Sthorpej/*
3511.46Sthorpej * The system will assign the "booted device" indicator (and thus
3521.46Sthorpej * rootdev if rootspec is wildcarded) to the first partition 'a'
3531.46Sthorpej * in preference of boot.  However, it does walk unit backwards
3541.46Sthorpej * to remain compatible with the old Amiga method of picking the
3551.46Sthorpej * last root found.
3561.46Sthorpej */
3571.46Sthorpej#include <sys/fcntl.h>		/* XXXX and all that uses it */
3581.46Sthorpej#include <sys/proc.h>		/* XXXX and all that uses it */
3591.17Schopps
3601.46Sthorpej#include "fd.h"
3611.46Sthorpej#include "sd.h"
3621.46Sthorpej#include "cd.h"
3631.67Saymeric#include "wd.h"
3641.1Smw
3651.46Sthorpej#if NFD > 0
3661.46Sthorpejextern  struct cfdriver fd_cd;
3671.82Sgehennaextern	const struct bdevsw fd_bdevsw;
3681.46Sthorpej#endif
3691.46Sthorpej#if NSD > 0
3701.69Smhitchextern  struct cfdriver sd_cd;
3711.82Sgehennaextern	const struct bdevsw sd_bdevsw;
3721.46Sthorpej#endif
3731.46Sthorpej#if NCD > 0
3741.46Sthorpejextern  struct cfdriver cd_cd;
3751.82Sgehennaextern	const struct bdevsw cd_bdevsw;
3761.46Sthorpej#endif
3771.67Saymeric#if NWD > 0
3781.69Smhitchextern  struct cfdriver wd_cd;
3791.82Sgehennaextern	const struct bdevsw wd_bdevsw;
3801.67Saymeric#endif
3811.1Smw
3821.46Sthorpejstruct cfdriver *genericconf[] = {
3831.46Sthorpej#if NFD > 0
3841.46Sthorpej	&fd_cd,
3851.46Sthorpej#endif
3861.46Sthorpej#if NSD > 0
3871.46Sthorpej	&sd_cd,
3881.46Sthorpej#endif
3891.69Smhitch#if NWD > 0
3901.69Smhitch	&wd_cd,
3911.69Smhitch#endif
3921.46Sthorpej#if NCD > 0
3931.46Sthorpej	&cd_cd,
3941.46Sthorpej#endif
3951.46Sthorpej	NULL,
3961.1Smw};
3971.1Smw
3981.11Schoppsvoid
3991.76Smattfindroot(void)
4001.1Smw{
4011.46Sthorpej	struct disk *dkp;
4021.46Sthorpej	struct partition *pp;
4031.99Scegger	device_t *devs;
4041.46Sthorpej	int i, maj, unit;
4051.82Sgehenna	const struct bdevsw *bdp;
4061.47Smhitch
4071.47Smhitch#if NSD > 0
4081.47Smhitch	/*
4091.47Smhitch	 * If we have the boot partition offset (boot_partition), try
4101.47Smhitch	 * to locate the device corresponding to that partition.
4111.47Smhitch	 */
4121.56Sis#ifdef DEBUG_KERNEL_START
4131.56Sis	printf("Boot partition offset is %ld\n", boot_partition);
4141.56Sis#endif
4151.47Smhitch	if (boot_partition != 0) {
4161.47Smhitch
4171.47Smhitch		for (unit = 0; unit < sd_cd.cd_ndevs; ++unit) {
4181.56Sis#ifdef DEBUG_KERNEL_START
4191.56Sis			printf("probing for sd%d\n", unit);
4201.56Sis#endif
4211.99Scegger			if (device_lookup(&sd_cd,unit) == NULL)
4221.47Smhitch				continue;
4231.47Smhitch
4241.47Smhitch			/*
4251.47Smhitch			 * Find the disk corresponding to the current
4261.47Smhitch			 * device.
4271.47Smhitch			 */
4281.114Schs			devs = sd_cd.cd_devs;
4291.99Scegger			if ((dkp = disk_find(device_xname(device_lookup(&sd_cd, unit)))) == NULL)
4301.47Smhitch				continue;
4311.47Smhitch
4321.47Smhitch			if (dkp->dk_driver == NULL ||
4331.47Smhitch			    dkp->dk_driver->d_strategy == NULL)
4341.47Smhitch				continue;
4351.82Sgehenna			bdp = &sd_bdevsw;
4361.82Sgehenna			maj = bdevsw_lookup_major(bdp);
4371.82Sgehenna			if ((*bdp->d_open)(MAKEDISKDEV(maj, unit, RAW_PART),
4381.98Schristos			    FREAD | FNONBLOCK, 0, curlwp))
4391.47Smhitch				continue;
4401.82Sgehenna			(*bdp->d_close)(MAKEDISKDEV(maj, unit, RAW_PART),
4411.98Schristos			    FREAD | FNONBLOCK, 0, curlwp);
4421.47Smhitch			pp = &dkp->dk_label->d_partitions[0];
4431.54Sis			for (i = 0; i < dkp->dk_label->d_npartitions;
4441.54Sis			    i++, pp++) {
4451.56Sis#ifdef DEBUG_KERNEL_START
4461.56Sis				printf("sd%d%c type %d offset %d size %d\n",
4471.56Sis					unit, i+'a', pp->p_fstype,
4481.56Sis					pp->p_offset, pp->p_size);
4491.56Sis#endif
4501.54Sis				if (pp->p_size == 0 ||
4511.54Sis				    (pp->p_fstype != FS_BSDFFS &&
4521.54Sis				    pp->p_fstype != FS_SWAP))
4531.54Sis					continue;
4541.54Sis				if (pp->p_offset == boot_partition) {
4551.76Smatt					if (booted_device == NULL) {
4561.76Smatt						booted_device = devs[unit];
4571.76Smatt						booted_partition = i;
4581.54Sis					} else
4591.54Sis						printf("Ambiguous boot device\n");
4601.54Sis				}
4611.47Smhitch			}
4621.47Smhitch		}
4631.47Smhitch	}
4641.76Smatt	if (booted_device != NULL)
4651.47Smhitch		return;		/* we found the boot device */
4661.47Smhitch#endif
4671.46Sthorpej
4681.46Sthorpej	for (i = 0; genericconf[i] != NULL; i++) {
4691.46Sthorpej		for (unit = genericconf[i]->cd_ndevs - 1; unit >= 0; unit--) {
4701.46Sthorpej			if (genericconf[i]->cd_devs[unit] == NULL)
4711.46Sthorpej				continue;
4721.46Sthorpej
4731.46Sthorpej			/*
4741.46Sthorpej			 * Find the disk structure corresponding to the
4751.46Sthorpej			 * current device.
4761.46Sthorpej			 */
4771.99Scegger			devs = (device_t *)genericconf[i]->cd_devs;
4781.99Scegger			if ((dkp = disk_find(device_xname(devs[unit]))) == NULL)
4791.46Sthorpej				continue;
4801.46Sthorpej
4811.46Sthorpej			if (dkp->dk_driver == NULL ||
4821.46Sthorpej			    dkp->dk_driver->d_strategy == NULL)
4831.46Sthorpej				continue;
4841.46Sthorpej
4851.92Smhitch			bdp = NULL;
4861.82Sgehenna#if NFD > 0
4871.82Sgehenna			if (fd_bdevsw.d_strategy == dkp->dk_driver->d_strategy)
4881.82Sgehenna				bdp = &fd_bdevsw;
4891.82Sgehenna#endif
4901.82Sgehenna#if NSD > 0
4911.82Sgehenna			if (sd_bdevsw.d_strategy == dkp->dk_driver->d_strategy)
4921.82Sgehenna				bdp = &sd_bdevsw;
4931.82Sgehenna#endif
4941.82Sgehenna#if NWD > 0
4951.82Sgehenna			if (wd_bdevsw.d_strategy == dkp->dk_driver->d_strategy)
4961.82Sgehenna				bdp = &wd_bdevsw;
4971.82Sgehenna#endif
4981.82Sgehenna#if NCD > 0
4991.82Sgehenna			if (cd_bdevsw.d_strategy == dkp->dk_driver->d_strategy)
5001.82Sgehenna				bdp = &cd_bdevsw;
5011.82Sgehenna#endif
5021.46Sthorpej#ifdef DIAGNOSTIC
5031.82Sgehenna			if (bdp == NULL)
5041.46Sthorpej				panic("findroot: impossible");
5051.46Sthorpej#endif
5061.82Sgehenna			maj = bdevsw_lookup_major(bdp);
5071.46Sthorpej
5081.46Sthorpej			/* Open disk; forces read of disklabel. */
5091.117Smlelstv			if ((*bdp->d_open)(MAKEDISKDEV(maj, unit, RAW_PART),
5101.117Smlelstv				FREAD|FNONBLOCK, 0, &lwp0))
5111.46Sthorpej				continue;
5121.117Smlelstv			(void)(*bdp->d_close)(MAKEDISKDEV(maj, unit, RAW_PART),
5131.117Smlelstv				FREAD|FNONBLOCK, 0, &lwp0);
5141.46Sthorpej
5151.46Sthorpej			pp = &dkp->dk_label->d_partitions[0];
5161.46Sthorpej			if (pp->p_size != 0 && pp->p_fstype == FS_BSDFFS) {
5171.76Smatt				booted_device = devs[unit];
5181.76Smatt				booted_partition = 0;
5191.46Sthorpej				return;
5201.46Sthorpej			}
5211.1Smw		}
5221.1Smw	}
5231.3Smw}
5241.17Schopps
5251.11Schopps/*
5261.11Schopps * Try to determine, of this machine is an A3000, which has a builtin
5271.11Schopps * realtime clock and scsi controller, so that this hardware is only
5281.11Schopps * included as "configured" if this IS an A3000
5291.11Schopps */
5301.5Smw
5311.5Smwint a3000_flag = 1;		/* patchable */
5321.5Smw#ifdef A4000
5331.5Smwint a4000_flag = 1;		/* patchable - default to A4000 */
5341.5Smw#else
5351.5Smwint a4000_flag = 0;		/* patchable */
5361.5Smw#endif
5371.5Smw
5381.3Smwint
5391.110Smattis_a3000(void)
5401.3Smw{
5411.11Schopps	/* this is a dirty kludge.. but how do you do this RIGHT ? :-) */
5421.22Schopps	extern long boot_fphystart;
5431.11Schopps	short sc;
5441.11Schopps
5451.19Schopps	if ((machineid >> 16) == 3000)
5461.19Schopps		return (1);			/* It's an A3000 */
5471.19Schopps	if (machineid >> 16)
5481.19Schopps		return (0);			/* It's not an A3000 */
5491.19Schopps	/* Machine type is unknown, so try to guess it */
5501.11Schopps	/* where is fastram on the A4000 ?? */
5511.11Schopps	/* if fastram is below 0x07000000, assume it's not an A3000 */
5521.22Schopps	if (boot_fphystart < 0x07000000)
5531.17Schopps		return(0);
5541.11Schopps	/*
5551.11Schopps	 * OK, fastram starts at or above 0x07000000, check specific
5561.11Schopps	 * machines
5571.11Schopps	 */
5581.17Schopps	for (sc = 0; sc < ncfdev; sc++) {
5591.17Schopps		switch (cfdev[sc].rom.manid) {
5601.17Schopps		case 2026:		/* Progressive Peripherals, Inc */
5611.17Schopps			switch (cfdev[sc].rom.prodid) {
5621.17Schopps			case 0:		/* PPI Mercury - A3000 */
5631.17Schopps			case 1:		/* PP&S A3000 '040 */
5641.17Schopps				return(1);
5651.17Schopps			case 150:	/* PPI Zeus - it's an A2000 */
5661.17Schopps			case 105:	/* PP&S A2000 '040 */
5671.17Schopps			case 187:	/* PP&S A500 '040 */
5681.17Schopps				return(0);
5691.11Schopps			}
5701.11Schopps			break;
5711.3Smw
5721.17Schopps		case 2112:			/* IVS */
5731.17Schopps			switch (cfdev[sc].rom.prodid) {
5741.17Schopps			case 242:
5751.17Schopps				return(0);	/* A2000 accelerator? */
5761.11Schopps			}
5771.11Schopps			break;
5781.11Schopps		}
5791.11Schopps	}
5801.17Schopps	return (a3000_flag);		/* XXX let flag tell now */
5811.5Smw}
5821.5Smw
5831.5Smwint
5841.110Smattis_a4000(void)
5851.5Smw{
5861.19Schopps	if ((machineid >> 16) == 4000)
5871.19Schopps		return (1);		/* It's an A4000 */
5881.24Schopps	if ((machineid >> 16) == 1200)
5891.24Schopps		return (0);		/* It's an A1200, so not A4000 */
5901.36Sis#ifdef DRACO
5911.36Sis	if (is_draco())
5921.36Sis		return (0);
5931.36Sis#endif
5941.24Schopps	/* Do I need this any more? */
5951.19Schopps	if ((custom.deniseid & 0xff) == 0xf8)
5961.19Schopps		return (1);
5971.19Schopps#ifdef DEBUG
5981.19Schopps	if (a4000_flag)
5991.43Schristos		printf("Denise ID = %04x\n", (unsigned short)custom.deniseid);
6001.19Schopps#endif
6011.19Schopps	if (machineid >> 16)
6021.19Schopps		return (0);		/* It's not an A4000 */
6031.19Schopps	return (a4000_flag);		/* Machine type not set */
6041.24Schopps}
6051.24Schopps
6061.24Schoppsint
6071.110Smattis_a1200(void)
6081.24Schopps{
6091.24Schopps	if ((machineid >> 16) == 1200)
6101.24Schopps		return (1);		/* It's an A1200 */
6111.24Schopps	return (0);			/* Machine type not set */
6121.1Smw}
6131.106Sphx
6141.106Sphxint
6151.110Smattis_a600(void)
6161.106Sphx{
6171.106Sphx	if ((machineid >> 16) == 600)
6181.106Sphx		return (1);		/* It's an A600 */
6191.106Sphx	return (0);			/* Machine type not set */
6201.106Sphx}
6211.108Srkujawa
6221.108Srkujawavoid
6231.108Srkujawadevice_register(device_t dev, void *aux)
6241.108Srkujawa{
6251.112Srkujawa#ifdef P5PB_CONSOLE
6261.112Srkujawa	p5pb_device_register(dev, aux);
6271.112Srkujawa#endif /* P5PB_CONSOLE */
6281.108Srkujawa}
629