autoconf.c revision 1.119
11.119Sthorpej/*	$NetBSD: autoconf.c,v 1.119 2021/04/27 14:48:28 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.119Sthorpej#define	__SUBR_AUTOCONF_PRIVATE		/* XXX amiga_config_found() */
341.119Sthorpej
351.80Saymeric#include <sys/cdefs.h>
361.119Sthorpej__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.119 2021/04/27 14:48:28 thorpej Exp $");
371.80Saymeric
381.9Schopps#include <sys/param.h>
391.9Schopps#include <sys/systm.h>
401.17Schopps#include <sys/reboot.h>
411.9Schopps#include <sys/conf.h>
421.46Sthorpej#include <sys/buf.h>
431.17Schopps#include <sys/device.h>
441.17Schopps#include <sys/disklabel.h>
451.46Sthorpej#include <sys/disk.h>
461.90Sthorpej#include <sys/proc.h>
471.19Schopps#include <machine/cpu.h>
481.17Schopps#include <amiga/amiga/cfdev.h>
491.17Schopps#include <amiga/amiga/device.h>
501.9Schopps#include <amiga/amiga/custom.h>
511.104Sphx#ifdef DRACO
521.104Sphx#include <amiga/amiga/drcustom.h>
531.104Sphx#endif
541.112Srkujawa#ifdef P5PB_CONSOLE
551.112Srkujawa#include <amiga/pci/p5pbvar.h>
561.112Srkujawa#endif /* P5PB_CONSOLE */
571.1Smw
581.116Srkujawa#include "acafh.h"
591.116Srkujawa#if NACAFH > 0
601.116Srkujawa#include <amiga/dev/acafhvar.h>
611.116Srkujawa#endif /* NACAFH > 0 */
621.115Srkujawa
631.79Saymericstatic void findroot(void);
641.107Smattvoid mbattach(device_t, device_t, void *);
651.79Saymericint mbprint(void *, const char *);
661.107Smattint mbmatch(device_t, cfdata_t, void *);
671.11Schopps
681.17Schopps#include <sys/kernel.h>
691.46Sthorpej
701.47Smhitchu_long boot_partition;
711.81Saymeric
721.81Saymericint amiga_realconfig;
731.46Sthorpej
741.1Smw/*
751.17Schopps * called at boot time, configure all devices on system
761.1Smw */
771.11Schoppsvoid
781.102Sceggercpu_configure(void)
791.1Smw{
801.44Sis	int s;
811.62Sis#ifdef DEBUG_KERNEL_START
821.62Sis	int i;
831.62Sis#endif
841.49Sgwr
851.17Schopps	/*
861.17Schopps	 * this is the real thing baby (i.e. not console init)
871.17Schopps	 */
881.17Schopps	amiga_realconfig = 1;
891.36Sis#ifdef DRACO
901.36Sis	if (is_draco()) {
911.36Sis		*draco_intena &= ~DRIRQ_GLOBAL;
921.36Sis	} else
931.36Sis#endif
941.3Smw	custom.intena = INTF_INTEN;
951.44Sis	s = splhigh();
961.1Smw
971.95Sjmc	if (config_rootfound("mainbus", NULL) == NULL)
981.17Schopps		panic("no mainbus found");
991.36Sis
1001.39Sis#ifdef DEBUG_KERNEL_START
1011.43Schristos	printf("survived autoconf, going to enable interrupts\n");
1021.39Sis#endif
1031.79Saymeric
1041.36Sis#ifdef DRACO
1051.36Sis	if (is_draco()) {
1061.36Sis		*draco_intena |= DRIRQ_GLOBAL;
1071.36Sis		/* softints always enabled */
1081.36Sis	} else
1091.36Sis#endif
1101.36Sis	{
1111.36Sis		custom.intena = INTF_SETCLR | INTF_INTEN;
1121.28Schopps
1131.36Sis		/* also enable hardware aided software interrupts */
1141.36Sis		custom.intena = INTF_SETCLR | INTF_SOFTINT;
1151.36Sis	}
1161.39Sis#ifdef DEBUG_KERNEL_START
1171.62Sis	for (i=splhigh(); i>=s ;i-=0x100) {
1181.62Sis		splx(i);
1191.62Sis		printf("%d...", (i>>8) & 7);
1201.62Sis	}
1211.43Schristos	printf("survived interrupt enable\n");
1221.62Sis#else
1231.62Sis	splx(s);
1241.39Sis#endif
1251.63Sthorpej#ifdef DEBUG_KERNEL_START
1261.63Sthorpej	printf("survived configure...\n");
1271.63Sthorpej#endif
1281.49Sgwr}
1291.49Sgwr
1301.49Sgwrvoid
1311.102Sceggercpu_rootconf(void)
1321.49Sgwr{
1331.77Sfrueauf	findroot();
1341.39Sis#ifdef DEBUG_KERNEL_START
1351.46Sthorpej	printf("survived findroot()\n");
1361.39Sis#endif
1371.113Smlelstv	rootconf();
1381.17Schopps}
1391.3Smw
1401.17Schopps/*ARGSUSED*/
1411.17Schoppsint
1421.114Schssimple_devprint(void *aux, const char *pnp)
1431.17Schopps{
1441.17Schopps	return(QUIET);
1451.1Smw}
1461.1Smw
1471.17Schoppsint
1481.101Sdslmatchname(const char *fp, const char *sp)
1491.17Schopps{
1501.17Schopps	int len;
1511.1Smw
1521.17Schopps	len = strlen(fp);
1531.17Schopps	if (strlen(sp) != len)
1541.17Schopps		return(0);
1551.103Scegger	if (memcmp(fp, sp, len) == 0)
1561.17Schopps		return(1);
1571.17Schopps	return(0);
1581.17Schopps}
1591.1Smw
1601.17Schopps/*
1611.96Sdrochner * use config_search_ia to find appropriate device, then call that device
1621.79Saymeric * directly with NULL device variable storage.  A device can then
1631.79Saymeric * always tell the difference betwean the real and console init
1641.17Schopps * by checking for NULL.
1651.17Schopps */
1661.11Schoppsint
1671.119Sthorpejamiga_config_found(cfdata_t pcfp, device_t parent, void *aux, cfprint_t pfn,
1681.119Sthorpej    cfarg_t tag, ...)
1691.1Smw{
1701.17Schopps	struct device temp;
1711.107Smatt	cfdata_t cf;
1721.86Sthorpej	const struct cfattach *ca;
1731.119Sthorpej	int rv = 0;
1741.119Sthorpej	va_list ap;
1751.119Sthorpej
1761.119Sthorpej	va_start(ap, tag);
1771.17Schopps
1781.119Sthorpej	if (amiga_realconfig) {
1791.119Sthorpej		rv = config_vfound(parent, aux, pfn, tag, ap) != NULL;
1801.119Sthorpej		goto out;
1811.119Sthorpej	}
1821.17Schopps
1831.114Schs	if (parent == NULL) {
1841.89Saymeric		memset(&temp, 0, sizeof temp);
1851.114Schs		parent = &temp;
1861.89Saymeric	}
1871.17Schopps
1881.114Schs	parent->dv_cfdata = pcfp;
1891.114Schs	parent->dv_cfdriver = config_cfdriver_lookup(pcfp->cf_name);
1901.114Schs	parent->dv_unit = pcfp->cf_unit;
1911.89Saymeric
1921.119Sthorpej	if ((cf = config_vsearch(parent, aux, tag, ap)) != NULL) {
1931.86Sthorpej		ca = config_cfattach_lookup(cf->cf_name, cf->cf_atname);
1941.86Sthorpej		if (ca != NULL) {
1951.114Schs			(*ca->ca_attach)(parent, NULL, aux);
1961.119Sthorpej			rv = 1;
1971.86Sthorpej		}
1981.1Smw	}
1991.114Schs	parent->dv_cfdata = NULL;
2001.119Sthorpej out:
2011.119Sthorpej	va_end(ap);
2021.119Sthorpej	return rv;
2031.17Schopps}
2041.17Schopps
2051.17Schopps/*
2061.17Schopps * this function needs to get enough configured to do a console
2071.79Saymeric * basically this means start attaching the grfxx's that support
2081.17Schopps * the console. Kinda hacky but it works.
2091.17Schopps */
2101.32Sveegovoid
2111.102Sceggerconfig_console(void)
2121.79Saymeric{
2131.107Smatt	cfdata_t cf;
2141.84Sthorpej
2151.84Sthorpej	config_init();
2161.36Sis
2171.17Schopps	/*
2181.17Schopps	 * we need mainbus' cfdata.
2191.17Schopps	 */
2201.95Sjmc	cf = config_rootsearch(NULL, "mainbus", NULL);
2211.36Sis	if (cf == NULL) {
2221.17Schopps		panic("no mainbus");
2231.36Sis	}
2241.114Schs
2251.1Smw	/*
2261.44Sis	 * delay clock calibration.
2271.44Sis	 */
2281.119Sthorpej	amiga_config_found(cf, NULL, __UNCONST("clock"), NULL, CFARG_EOL);
2291.44Sis
2301.44Sis	/*
2311.17Schopps	 * internal grf.
2321.1Smw	 */
2331.36Sis#ifdef DRACO
2341.36Sis	if (!(is_draco()))
2351.36Sis#endif
2361.119Sthorpej		amiga_config_found(cf, NULL, __UNCONST("grfcc"), NULL,
2371.119Sthorpej		    CFARG_EOL);
2381.67Saymeric
2391.1Smw	/*
2401.27Schopps	 * zbus knows when its not for real and will
2411.21Schopps	 * only configure the appropriate hardware
2421.1Smw	 */
2431.119Sthorpej	amiga_config_found(cf, NULL, __UNCONST("zbus"), NULL, CFARG_EOL);
2441.1Smw}
2451.1Smw
2461.79Saymeric/*
2471.79Saymeric * mainbus driver
2481.17Schopps */
2491.107SmattCFATTACH_DECL_NEW(mainbus, 0,
2501.85Sthorpej    mbmatch, mbattach, NULL, NULL);
2511.17Schopps
2521.11Schoppsint
2531.114Schsmbmatch(device_t parent, cfdata_t cf, void *aux)
2541.1Smw{
2551.72Sis#if 0	/*
2561.72Sis	 * XXX is this right? but we need to be found twice
2571.72Sis	 * (early console init hack)
2581.72Sis	 */
2591.71Skleink	static int mainbus_matched = 0;
2601.30Sthorpej
2611.71Skleink	/* Allow only one instance. */
2621.71Skleink	if (mainbus_matched)
2631.71Skleink		return (0);
2641.71Skleink
2651.71Skleink	mainbus_matched = 1;
2661.72Sis#endif
2671.71Skleink	return (1);
2681.1Smw}
2691.1Smw
2701.1Smw/*
2711.17Schopps * "find" all the things that should be there.
2721.1Smw */
2731.11Schoppsvoid
2741.114Schsmbattach(device_t parent, device_t self, void *aux)
2751.1Smw{
2761.43Schristos	printf("\n");
2771.118Sthorpej	config_found(self, __UNCONST("clock"), simple_devprint, CFARG_EOL);
2781.52Sis	if (is_a3000() || is_a4000()) {
2791.118Sthorpej		config_found(self, __UNCONST("a34kbbc"), simple_devprint,
2801.118Sthorpej		    CFARG_EOL);
2811.58Sis	} else
2821.53Sis#ifdef DRACO
2831.58Sis	if (!is_draco())
2841.53Sis#endif
2851.58Sis	{
2861.118Sthorpej		config_found(self, __UNCONST("a2kbbc"), simple_devprint,
2871.118Sthorpej		    CFARG_EOL);
2881.52Sis	}
2891.36Sis#ifdef DRACO
2901.36Sis	if (is_draco()) {
2911.118Sthorpej		config_found(self, __UNCONST("drbbc"), simple_devprint,
2921.118Sthorpej		    CFARG_EOL);
2931.118Sthorpej		config_found(self, __UNCONST("kbd"), simple_devprint,
2941.118Sthorpej		    CFARG_EOL);
2951.118Sthorpej		config_found(self, __UNCONST("drsc"), simple_devprint,
2961.118Sthorpej		    CFARG_EOL);
2971.118Sthorpej		config_found(self, __UNCONST("drsupio"), simple_devprint,
2981.118Sthorpej		    CFARG_EOL);
2991.79Saymeric	} else
3001.36Sis#endif
3011.36Sis	{
3021.118Sthorpej		config_found(self, __UNCONST("ser"), simple_devprint,
3031.118Sthorpej		    CFARG_EOL);
3041.118Sthorpej		config_found(self, __UNCONST("par"), simple_devprint,
3051.118Sthorpej		    CFARG_EOL);
3061.118Sthorpej		config_found(self, __UNCONST("kbd"), simple_devprint,
3071.118Sthorpej		    CFARG_EOL);
3081.118Sthorpej		config_found(self, __UNCONST("ms"), simple_devprint,
3091.118Sthorpej		    CFARG_EOL);
3101.118Sthorpej		config_found(self, __UNCONST("grfcc"), simple_devprint,
3111.118Sthorpej		    CFARG_EOL);
3121.118Sthorpej		config_found(self, __UNCONST("amidisplaycc"), simple_devprint,
3131.118Sthorpej		    CFARG_EOL);
3141.118Sthorpej		config_found(self, __UNCONST("fdc"), simple_devprint,
3151.118Sthorpej		    CFARG_EOL);
3161.36Sis	}
3171.106Sphx	if (is_a4000() || is_a1200() || is_a600())
3181.118Sthorpej		config_found(self, __UNCONST("wdc"), simple_devprint,
3191.118Sthorpej		    CFARG_EOL);
3201.29Schopps	if (is_a4000())			/* Try to configure A4000T SCSI */
3211.118Sthorpej		config_found(self, __UNCONST("afsc"), simple_devprint,
3221.118Sthorpej		    CFARG_EOL);
3231.17Schopps	if (is_a3000())
3241.118Sthorpej		config_found(self, __UNCONST("ahsc"), simple_devprint,
3251.118Sthorpej		    CFARG_EOL);
3261.106Sphx	if (is_a600() || is_a1200())
3271.118Sthorpej		config_found(self, __UNCONST("pccard"), simple_devprint,
3281.118Sthorpej		    CFARG_EOL);
3291.111Srkujawa	if (is_a1200())
3301.118Sthorpej		config_found(self, __UNCONST("a1k2cp"), simple_devprint,
3311.118Sthorpej		    CFARG_EOL);
3321.54Sis#ifdef DRACO
3331.54Sis	if (!is_draco())
3341.54Sis#endif
3351.118Sthorpej		config_found(self, __UNCONST("aucc"), simple_devprint,
3361.118Sthorpej		    CFARG_EOL);
3371.54Sis
3381.116Srkujawa#if NACAFH > 0
3391.116Srkujawa	if (!is_a600() && !is_a1200() && !is_a3000() && !is_a4000())
3401.116Srkujawa		if (acafh_mbattach_probe() == true)
3411.118Sthorpej			config_found(self, __UNCONST("acafh"), simple_devprint,
3421.118Sthorpej			    CFARG_EOL);
3431.115Srkujawa#endif
3441.115Srkujawa
3451.118Sthorpej	config_found(self, __UNCONST("zbus"), simple_devprint, CFARG_EOL);
3461.1Smw}
3471.1Smw
3481.11Schoppsint
3491.114Schsmbprint(void *aux, const char *pnp)
3501.1Smw{
3511.17Schopps	if (pnp)
3521.114Schs		aprint_normal("%s at %s", (char *)aux, pnp);
3531.17Schopps	return(UNCONF);
3541.1Smw}
3551.1Smw
3561.46Sthorpej/*
3571.46Sthorpej * The system will assign the "booted device" indicator (and thus
3581.46Sthorpej * rootdev if rootspec is wildcarded) to the first partition 'a'
3591.46Sthorpej * in preference of boot.  However, it does walk unit backwards
3601.46Sthorpej * to remain compatible with the old Amiga method of picking the
3611.46Sthorpej * last root found.
3621.46Sthorpej */
3631.46Sthorpej#include <sys/fcntl.h>		/* XXXX and all that uses it */
3641.46Sthorpej#include <sys/proc.h>		/* XXXX and all that uses it */
3651.17Schopps
3661.46Sthorpej#include "fd.h"
3671.46Sthorpej#include "sd.h"
3681.46Sthorpej#include "cd.h"
3691.67Saymeric#include "wd.h"
3701.1Smw
3711.46Sthorpej#if NFD > 0
3721.46Sthorpejextern  struct cfdriver fd_cd;
3731.82Sgehennaextern	const struct bdevsw fd_bdevsw;
3741.46Sthorpej#endif
3751.46Sthorpej#if NSD > 0
3761.69Smhitchextern  struct cfdriver sd_cd;
3771.82Sgehennaextern	const struct bdevsw sd_bdevsw;
3781.46Sthorpej#endif
3791.46Sthorpej#if NCD > 0
3801.46Sthorpejextern  struct cfdriver cd_cd;
3811.82Sgehennaextern	const struct bdevsw cd_bdevsw;
3821.46Sthorpej#endif
3831.67Saymeric#if NWD > 0
3841.69Smhitchextern  struct cfdriver wd_cd;
3851.82Sgehennaextern	const struct bdevsw wd_bdevsw;
3861.67Saymeric#endif
3871.1Smw
3881.46Sthorpejstruct cfdriver *genericconf[] = {
3891.46Sthorpej#if NFD > 0
3901.46Sthorpej	&fd_cd,
3911.46Sthorpej#endif
3921.46Sthorpej#if NSD > 0
3931.46Sthorpej	&sd_cd,
3941.46Sthorpej#endif
3951.69Smhitch#if NWD > 0
3961.69Smhitch	&wd_cd,
3971.69Smhitch#endif
3981.46Sthorpej#if NCD > 0
3991.46Sthorpej	&cd_cd,
4001.46Sthorpej#endif
4011.46Sthorpej	NULL,
4021.1Smw};
4031.1Smw
4041.11Schoppsvoid
4051.76Smattfindroot(void)
4061.1Smw{
4071.46Sthorpej	struct disk *dkp;
4081.46Sthorpej	struct partition *pp;
4091.99Scegger	device_t *devs;
4101.46Sthorpej	int i, maj, unit;
4111.82Sgehenna	const struct bdevsw *bdp;
4121.47Smhitch
4131.47Smhitch#if NSD > 0
4141.47Smhitch	/*
4151.47Smhitch	 * If we have the boot partition offset (boot_partition), try
4161.47Smhitch	 * to locate the device corresponding to that partition.
4171.47Smhitch	 */
4181.56Sis#ifdef DEBUG_KERNEL_START
4191.56Sis	printf("Boot partition offset is %ld\n", boot_partition);
4201.56Sis#endif
4211.47Smhitch	if (boot_partition != 0) {
4221.47Smhitch
4231.47Smhitch		for (unit = 0; unit < sd_cd.cd_ndevs; ++unit) {
4241.56Sis#ifdef DEBUG_KERNEL_START
4251.56Sis			printf("probing for sd%d\n", unit);
4261.56Sis#endif
4271.99Scegger			if (device_lookup(&sd_cd,unit) == NULL)
4281.47Smhitch				continue;
4291.47Smhitch
4301.47Smhitch			/*
4311.47Smhitch			 * Find the disk corresponding to the current
4321.47Smhitch			 * device.
4331.47Smhitch			 */
4341.114Schs			devs = sd_cd.cd_devs;
4351.99Scegger			if ((dkp = disk_find(device_xname(device_lookup(&sd_cd, unit)))) == NULL)
4361.47Smhitch				continue;
4371.47Smhitch
4381.47Smhitch			if (dkp->dk_driver == NULL ||
4391.47Smhitch			    dkp->dk_driver->d_strategy == NULL)
4401.47Smhitch				continue;
4411.82Sgehenna			bdp = &sd_bdevsw;
4421.82Sgehenna			maj = bdevsw_lookup_major(bdp);
4431.82Sgehenna			if ((*bdp->d_open)(MAKEDISKDEV(maj, unit, RAW_PART),
4441.98Schristos			    FREAD | FNONBLOCK, 0, curlwp))
4451.47Smhitch				continue;
4461.82Sgehenna			(*bdp->d_close)(MAKEDISKDEV(maj, unit, RAW_PART),
4471.98Schristos			    FREAD | FNONBLOCK, 0, curlwp);
4481.47Smhitch			pp = &dkp->dk_label->d_partitions[0];
4491.54Sis			for (i = 0; i < dkp->dk_label->d_npartitions;
4501.54Sis			    i++, pp++) {
4511.56Sis#ifdef DEBUG_KERNEL_START
4521.56Sis				printf("sd%d%c type %d offset %d size %d\n",
4531.56Sis					unit, i+'a', pp->p_fstype,
4541.56Sis					pp->p_offset, pp->p_size);
4551.56Sis#endif
4561.54Sis				if (pp->p_size == 0 ||
4571.54Sis				    (pp->p_fstype != FS_BSDFFS &&
4581.54Sis				    pp->p_fstype != FS_SWAP))
4591.54Sis					continue;
4601.54Sis				if (pp->p_offset == boot_partition) {
4611.76Smatt					if (booted_device == NULL) {
4621.76Smatt						booted_device = devs[unit];
4631.76Smatt						booted_partition = i;
4641.54Sis					} else
4651.54Sis						printf("Ambiguous boot device\n");
4661.54Sis				}
4671.47Smhitch			}
4681.47Smhitch		}
4691.47Smhitch	}
4701.76Smatt	if (booted_device != NULL)
4711.47Smhitch		return;		/* we found the boot device */
4721.47Smhitch#endif
4731.46Sthorpej
4741.46Sthorpej	for (i = 0; genericconf[i] != NULL; i++) {
4751.46Sthorpej		for (unit = genericconf[i]->cd_ndevs - 1; unit >= 0; unit--) {
4761.46Sthorpej			if (genericconf[i]->cd_devs[unit] == NULL)
4771.46Sthorpej				continue;
4781.46Sthorpej
4791.46Sthorpej			/*
4801.46Sthorpej			 * Find the disk structure corresponding to the
4811.46Sthorpej			 * current device.
4821.46Sthorpej			 */
4831.99Scegger			devs = (device_t *)genericconf[i]->cd_devs;
4841.99Scegger			if ((dkp = disk_find(device_xname(devs[unit]))) == NULL)
4851.46Sthorpej				continue;
4861.46Sthorpej
4871.46Sthorpej			if (dkp->dk_driver == NULL ||
4881.46Sthorpej			    dkp->dk_driver->d_strategy == NULL)
4891.46Sthorpej				continue;
4901.46Sthorpej
4911.92Smhitch			bdp = NULL;
4921.82Sgehenna#if NFD > 0
4931.82Sgehenna			if (fd_bdevsw.d_strategy == dkp->dk_driver->d_strategy)
4941.82Sgehenna				bdp = &fd_bdevsw;
4951.82Sgehenna#endif
4961.82Sgehenna#if NSD > 0
4971.82Sgehenna			if (sd_bdevsw.d_strategy == dkp->dk_driver->d_strategy)
4981.82Sgehenna				bdp = &sd_bdevsw;
4991.82Sgehenna#endif
5001.82Sgehenna#if NWD > 0
5011.82Sgehenna			if (wd_bdevsw.d_strategy == dkp->dk_driver->d_strategy)
5021.82Sgehenna				bdp = &wd_bdevsw;
5031.82Sgehenna#endif
5041.82Sgehenna#if NCD > 0
5051.82Sgehenna			if (cd_bdevsw.d_strategy == dkp->dk_driver->d_strategy)
5061.82Sgehenna				bdp = &cd_bdevsw;
5071.82Sgehenna#endif
5081.46Sthorpej#ifdef DIAGNOSTIC
5091.82Sgehenna			if (bdp == NULL)
5101.46Sthorpej				panic("findroot: impossible");
5111.46Sthorpej#endif
5121.82Sgehenna			maj = bdevsw_lookup_major(bdp);
5131.46Sthorpej
5141.46Sthorpej			/* Open disk; forces read of disklabel. */
5151.117Smlelstv			if ((*bdp->d_open)(MAKEDISKDEV(maj, unit, RAW_PART),
5161.117Smlelstv				FREAD|FNONBLOCK, 0, &lwp0))
5171.46Sthorpej				continue;
5181.117Smlelstv			(void)(*bdp->d_close)(MAKEDISKDEV(maj, unit, RAW_PART),
5191.117Smlelstv				FREAD|FNONBLOCK, 0, &lwp0);
5201.46Sthorpej
5211.46Sthorpej			pp = &dkp->dk_label->d_partitions[0];
5221.46Sthorpej			if (pp->p_size != 0 && pp->p_fstype == FS_BSDFFS) {
5231.76Smatt				booted_device = devs[unit];
5241.76Smatt				booted_partition = 0;
5251.46Sthorpej				return;
5261.46Sthorpej			}
5271.1Smw		}
5281.1Smw	}
5291.3Smw}
5301.17Schopps
5311.11Schopps/*
5321.11Schopps * Try to determine, of this machine is an A3000, which has a builtin
5331.11Schopps * realtime clock and scsi controller, so that this hardware is only
5341.11Schopps * included as "configured" if this IS an A3000
5351.11Schopps */
5361.5Smw
5371.5Smwint a3000_flag = 1;		/* patchable */
5381.5Smw#ifdef A4000
5391.5Smwint a4000_flag = 1;		/* patchable - default to A4000 */
5401.5Smw#else
5411.5Smwint a4000_flag = 0;		/* patchable */
5421.5Smw#endif
5431.5Smw
5441.3Smwint
5451.110Smattis_a3000(void)
5461.3Smw{
5471.11Schopps	/* this is a dirty kludge.. but how do you do this RIGHT ? :-) */
5481.22Schopps	extern long boot_fphystart;
5491.11Schopps	short sc;
5501.11Schopps
5511.19Schopps	if ((machineid >> 16) == 3000)
5521.19Schopps		return (1);			/* It's an A3000 */
5531.19Schopps	if (machineid >> 16)
5541.19Schopps		return (0);			/* It's not an A3000 */
5551.19Schopps	/* Machine type is unknown, so try to guess it */
5561.11Schopps	/* where is fastram on the A4000 ?? */
5571.11Schopps	/* if fastram is below 0x07000000, assume it's not an A3000 */
5581.22Schopps	if (boot_fphystart < 0x07000000)
5591.17Schopps		return(0);
5601.11Schopps	/*
5611.11Schopps	 * OK, fastram starts at or above 0x07000000, check specific
5621.11Schopps	 * machines
5631.11Schopps	 */
5641.17Schopps	for (sc = 0; sc < ncfdev; sc++) {
5651.17Schopps		switch (cfdev[sc].rom.manid) {
5661.17Schopps		case 2026:		/* Progressive Peripherals, Inc */
5671.17Schopps			switch (cfdev[sc].rom.prodid) {
5681.17Schopps			case 0:		/* PPI Mercury - A3000 */
5691.17Schopps			case 1:		/* PP&S A3000 '040 */
5701.17Schopps				return(1);
5711.17Schopps			case 150:	/* PPI Zeus - it's an A2000 */
5721.17Schopps			case 105:	/* PP&S A2000 '040 */
5731.17Schopps			case 187:	/* PP&S A500 '040 */
5741.17Schopps				return(0);
5751.11Schopps			}
5761.11Schopps			break;
5771.3Smw
5781.17Schopps		case 2112:			/* IVS */
5791.17Schopps			switch (cfdev[sc].rom.prodid) {
5801.17Schopps			case 242:
5811.17Schopps				return(0);	/* A2000 accelerator? */
5821.11Schopps			}
5831.11Schopps			break;
5841.11Schopps		}
5851.11Schopps	}
5861.17Schopps	return (a3000_flag);		/* XXX let flag tell now */
5871.5Smw}
5881.5Smw
5891.5Smwint
5901.110Smattis_a4000(void)
5911.5Smw{
5921.19Schopps	if ((machineid >> 16) == 4000)
5931.19Schopps		return (1);		/* It's an A4000 */
5941.24Schopps	if ((machineid >> 16) == 1200)
5951.24Schopps		return (0);		/* It's an A1200, so not A4000 */
5961.36Sis#ifdef DRACO
5971.36Sis	if (is_draco())
5981.36Sis		return (0);
5991.36Sis#endif
6001.24Schopps	/* Do I need this any more? */
6011.19Schopps	if ((custom.deniseid & 0xff) == 0xf8)
6021.19Schopps		return (1);
6031.19Schopps#ifdef DEBUG
6041.19Schopps	if (a4000_flag)
6051.43Schristos		printf("Denise ID = %04x\n", (unsigned short)custom.deniseid);
6061.19Schopps#endif
6071.19Schopps	if (machineid >> 16)
6081.19Schopps		return (0);		/* It's not an A4000 */
6091.19Schopps	return (a4000_flag);		/* Machine type not set */
6101.24Schopps}
6111.24Schopps
6121.24Schoppsint
6131.110Smattis_a1200(void)
6141.24Schopps{
6151.24Schopps	if ((machineid >> 16) == 1200)
6161.24Schopps		return (1);		/* It's an A1200 */
6171.24Schopps	return (0);			/* Machine type not set */
6181.1Smw}
6191.106Sphx
6201.106Sphxint
6211.110Smattis_a600(void)
6221.106Sphx{
6231.106Sphx	if ((machineid >> 16) == 600)
6241.106Sphx		return (1);		/* It's an A600 */
6251.106Sphx	return (0);			/* Machine type not set */
6261.106Sphx}
6271.108Srkujawa
6281.108Srkujawavoid
6291.108Srkujawadevice_register(device_t dev, void *aux)
6301.108Srkujawa{
6311.112Srkujawa#ifdef P5PB_CONSOLE
6321.112Srkujawa	p5pb_device_register(dev, aux);
6331.112Srkujawa#endif /* P5PB_CONSOLE */
6341.108Srkujawa}
635