11.122Sandvar/*	$NetBSD: autoconf.c,v 1.122 2023/10/14 08:05:25 andvar 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.122Sandvar__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.122 2023/10/14 08:05:25 andvar 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.121Sriastrad#include <sys/device_impl.h>	/* XXX autoconf abuse */
431.17Schopps#include <sys/disklabel.h>
441.46Sthorpej#include <sys/disk.h>
451.90Sthorpej#include <sys/proc.h>
461.19Schopps#include <machine/cpu.h>
471.17Schopps#include <amiga/amiga/cfdev.h>
481.17Schopps#include <amiga/amiga/device.h>
491.9Schopps#include <amiga/amiga/custom.h>
501.104Sphx#ifdef DRACO
511.104Sphx#include <amiga/amiga/drcustom.h>
521.104Sphx#endif
531.112Srkujawa#ifdef P5PB_CONSOLE
541.112Srkujawa#include <amiga/pci/p5pbvar.h>
551.112Srkujawa#endif /* P5PB_CONSOLE */
561.1Smw
571.116Srkujawa#include "acafh.h"
581.116Srkujawa#if NACAFH > 0
591.116Srkujawa#include <amiga/dev/acafhvar.h>
601.116Srkujawa#endif /* NACAFH > 0 */
611.115Srkujawa
621.79Saymericstatic void findroot(void);
631.107Smattvoid mbattach(device_t, device_t, void *);
641.79Saymericint mbprint(void *, const char *);
651.107Smattint mbmatch(device_t, cfdata_t, void *);
661.11Schopps
671.17Schopps#include <sys/kernel.h>
681.46Sthorpej
691.47Smhitchu_long boot_partition;
701.81Saymeric
711.81Saymericint amiga_realconfig;
721.46Sthorpej
731.1Smw/*
741.17Schopps * called at boot time, configure all devices on system
751.1Smw */
761.11Schoppsvoid
771.102Sceggercpu_configure(void)
781.1Smw{
791.44Sis	int s;
801.62Sis#ifdef DEBUG_KERNEL_START
811.62Sis	int i;
821.62Sis#endif
831.49Sgwr
841.17Schopps	/*
851.17Schopps	 * this is the real thing baby (i.e. not console init)
861.17Schopps	 */
871.17Schopps	amiga_realconfig = 1;
881.36Sis#ifdef DRACO
891.36Sis	if (is_draco()) {
901.36Sis		*draco_intena &= ~DRIRQ_GLOBAL;
911.36Sis	} else
921.36Sis#endif
931.3Smw	custom.intena = INTF_INTEN;
941.44Sis	s = splhigh();
951.1Smw
961.95Sjmc	if (config_rootfound("mainbus", NULL) == NULL)
971.17Schopps		panic("no mainbus found");
981.36Sis
991.39Sis#ifdef DEBUG_KERNEL_START
1001.43Schristos	printf("survived autoconf, going to enable interrupts\n");
1011.39Sis#endif
1021.79Saymeric
1031.36Sis#ifdef DRACO
1041.36Sis	if (is_draco()) {
1051.36Sis		*draco_intena |= DRIRQ_GLOBAL;
1061.36Sis		/* softints always enabled */
1071.36Sis	} else
1081.36Sis#endif
1091.36Sis	{
1101.36Sis		custom.intena = INTF_SETCLR | INTF_INTEN;
1111.28Schopps
1121.36Sis		/* also enable hardware aided software interrupts */
1131.36Sis		custom.intena = INTF_SETCLR | INTF_SOFTINT;
1141.36Sis	}
1151.39Sis#ifdef DEBUG_KERNEL_START
1161.62Sis	for (i=splhigh(); i>=s ;i-=0x100) {
1171.62Sis		splx(i);
1181.62Sis		printf("%d...", (i>>8) & 7);
1191.62Sis	}
1201.43Schristos	printf("survived interrupt enable\n");
1211.62Sis#else
1221.62Sis	splx(s);
1231.39Sis#endif
1241.63Sthorpej#ifdef DEBUG_KERNEL_START
1251.63Sthorpej	printf("survived configure...\n");
1261.63Sthorpej#endif
1271.49Sgwr}
1281.49Sgwr
1291.49Sgwrvoid
1301.102Sceggercpu_rootconf(void)
1311.49Sgwr{
1321.77Sfrueauf	findroot();
1331.39Sis#ifdef DEBUG_KERNEL_START
1341.46Sthorpej	printf("survived findroot()\n");
1351.39Sis#endif
1361.113Smlelstv	rootconf();
1371.17Schopps}
1381.3Smw
1391.17Schopps/*ARGSUSED*/
1401.17Schoppsint
1411.114Schssimple_devprint(void *aux, const char *pnp)
1421.17Schopps{
1431.17Schopps	return(QUIET);
1441.1Smw}
1451.1Smw
1461.17Schoppsint
1471.101Sdslmatchname(const char *fp, const char *sp)
1481.17Schopps{
1491.17Schopps	int len;
1501.1Smw
1511.17Schopps	len = strlen(fp);
1521.17Schopps	if (strlen(sp) != len)
1531.17Schopps		return(0);
1541.103Scegger	if (memcmp(fp, sp, len) == 0)
1551.17Schopps		return(1);
1561.17Schopps	return(0);
1571.17Schopps}
1581.1Smw
1591.17Schopps/*
1601.96Sdrochner * use config_search_ia to find appropriate device, then call that device
1611.79Saymeric * directly with NULL device variable storage.  A device can then
1621.122Sandvar * always tell the difference between the real and console init
1631.17Schopps * by checking for NULL.
1641.17Schopps */
1651.11Schoppsint
1661.119Sthorpejamiga_config_found(cfdata_t pcfp, device_t parent, void *aux, cfprint_t pfn,
1671.120Sthorpej    const struct cfargs *cfargs)
1681.1Smw{
1691.17Schopps	struct device temp;
1701.107Smatt	cfdata_t cf;
1711.86Sthorpej	const struct cfattach *ca;
1721.119Sthorpej	int rv = 0;
1731.17Schopps
1741.119Sthorpej	if (amiga_realconfig) {
1751.120Sthorpej		rv = config_found(parent, aux, pfn, cfargs) != NULL;
1761.119Sthorpej		goto out;
1771.119Sthorpej	}
1781.17Schopps
1791.114Schs	if (parent == NULL) {
1801.89Saymeric		memset(&temp, 0, sizeof temp);
1811.114Schs		parent = &temp;
1821.89Saymeric	}
1831.17Schopps
1841.114Schs	parent->dv_cfdata = pcfp;
1851.114Schs	parent->dv_cfdriver = config_cfdriver_lookup(pcfp->cf_name);
1861.114Schs	parent->dv_unit = pcfp->cf_unit;
1871.89Saymeric
1881.120Sthorpej	if ((cf = config_search(parent, aux, cfargs)) != NULL) {
1891.86Sthorpej		ca = config_cfattach_lookup(cf->cf_name, cf->cf_atname);
1901.86Sthorpej		if (ca != NULL) {
1911.114Schs			(*ca->ca_attach)(parent, NULL, aux);
1921.119Sthorpej			rv = 1;
1931.86Sthorpej		}
1941.1Smw	}
1951.114Schs	parent->dv_cfdata = NULL;
1961.119Sthorpej out:
1971.119Sthorpej	return rv;
1981.17Schopps}
1991.17Schopps
2001.17Schopps/*
2011.17Schopps * this function needs to get enough configured to do a console
2021.79Saymeric * basically this means start attaching the grfxx's that support
2031.17Schopps * the console. Kinda hacky but it works.
2041.17Schopps */
2051.32Sveegovoid
2061.102Sceggerconfig_console(void)
2071.79Saymeric{
2081.107Smatt	cfdata_t cf;
2091.84Sthorpej
2101.84Sthorpej	config_init();
2111.36Sis
2121.17Schopps	/*
2131.17Schopps	 * we need mainbus' cfdata.
2141.17Schopps	 */
2151.95Sjmc	cf = config_rootsearch(NULL, "mainbus", NULL);
2161.36Sis	if (cf == NULL) {
2171.17Schopps		panic("no mainbus");
2181.36Sis	}
2191.114Schs
2201.1Smw	/*
2211.44Sis	 * delay clock calibration.
2221.44Sis	 */
2231.120Sthorpej	amiga_config_found(cf, NULL, __UNCONST("clock"), NULL, CFARGS_NONE);
2241.44Sis
2251.44Sis	/*
2261.17Schopps	 * internal grf.
2271.1Smw	 */
2281.36Sis#ifdef DRACO
2291.36Sis	if (!(is_draco()))
2301.36Sis#endif
2311.119Sthorpej		amiga_config_found(cf, NULL, __UNCONST("grfcc"), NULL,
2321.120Sthorpej		    CFARGS_NONE);
2331.67Saymeric
2341.1Smw	/*
2351.27Schopps	 * zbus knows when its not for real and will
2361.21Schopps	 * only configure the appropriate hardware
2371.1Smw	 */
2381.120Sthorpej	amiga_config_found(cf, NULL, __UNCONST("zbus"), NULL, CFARGS_NONE);
2391.1Smw}
2401.1Smw
2411.79Saymeric/*
2421.79Saymeric * mainbus driver
2431.17Schopps */
2441.107SmattCFATTACH_DECL_NEW(mainbus, 0,
2451.85Sthorpej    mbmatch, mbattach, NULL, NULL);
2461.17Schopps
2471.11Schoppsint
2481.114Schsmbmatch(device_t parent, cfdata_t cf, void *aux)
2491.1Smw{
2501.72Sis#if 0	/*
2511.72Sis	 * XXX is this right? but we need to be found twice
2521.72Sis	 * (early console init hack)
2531.72Sis	 */
2541.71Skleink	static int mainbus_matched = 0;
2551.30Sthorpej
2561.71Skleink	/* Allow only one instance. */
2571.71Skleink	if (mainbus_matched)
2581.71Skleink		return (0);
2591.71Skleink
2601.71Skleink	mainbus_matched = 1;
2611.72Sis#endif
2621.71Skleink	return (1);
2631.1Smw}
2641.1Smw
2651.1Smw/*
2661.17Schopps * "find" all the things that should be there.
2671.1Smw */
2681.11Schoppsvoid
2691.114Schsmbattach(device_t parent, device_t self, void *aux)
2701.1Smw{
2711.43Schristos	printf("\n");
2721.120Sthorpej	config_found(self, __UNCONST("clock"), simple_devprint, CFARGS_NONE);
2731.52Sis	if (is_a3000() || is_a4000()) {
2741.118Sthorpej		config_found(self, __UNCONST("a34kbbc"), simple_devprint,
2751.120Sthorpej		    CFARGS_NONE);
2761.58Sis	} else
2771.53Sis#ifdef DRACO
2781.58Sis	if (!is_draco())
2791.53Sis#endif
2801.58Sis	{
2811.118Sthorpej		config_found(self, __UNCONST("a2kbbc"), simple_devprint,
2821.120Sthorpej		    CFARGS_NONE);
2831.52Sis	}
2841.36Sis#ifdef DRACO
2851.36Sis	if (is_draco()) {
2861.118Sthorpej		config_found(self, __UNCONST("drbbc"), simple_devprint,
2871.120Sthorpej		    CFARGS_NONE);
2881.118Sthorpej		config_found(self, __UNCONST("kbd"), simple_devprint,
2891.120Sthorpej		    CFARGS_NONE);
2901.118Sthorpej		config_found(self, __UNCONST("drsc"), simple_devprint,
2911.120Sthorpej		    CFARGS_NONE);
2921.118Sthorpej		config_found(self, __UNCONST("drsupio"), simple_devprint,
2931.120Sthorpej		    CFARGS_NONE);
2941.79Saymeric	} else
2951.36Sis#endif
2961.36Sis	{
2971.118Sthorpej		config_found(self, __UNCONST("ser"), simple_devprint,
2981.120Sthorpej		    CFARGS_NONE);
2991.118Sthorpej		config_found(self, __UNCONST("par"), simple_devprint,
3001.120Sthorpej		    CFARGS_NONE);
3011.118Sthorpej		config_found(self, __UNCONST("kbd"), simple_devprint,
3021.120Sthorpej		    CFARGS_NONE);
3031.118Sthorpej		config_found(self, __UNCONST("ms"), simple_devprint,
3041.120Sthorpej		    CFARGS_NONE);
3051.118Sthorpej		config_found(self, __UNCONST("grfcc"), simple_devprint,
3061.120Sthorpej		    CFARGS_NONE);
3071.118Sthorpej		config_found(self, __UNCONST("amidisplaycc"), simple_devprint,
3081.120Sthorpej		    CFARGS_NONE);
3091.118Sthorpej		config_found(self, __UNCONST("fdc"), simple_devprint,
3101.120Sthorpej		    CFARGS_NONE);
3111.36Sis	}
3121.106Sphx	if (is_a4000() || is_a1200() || is_a600())
3131.118Sthorpej		config_found(self, __UNCONST("wdc"), simple_devprint,
3141.120Sthorpej		    CFARGS_NONE);
3151.29Schopps	if (is_a4000())			/* Try to configure A4000T SCSI */
3161.118Sthorpej		config_found(self, __UNCONST("afsc"), simple_devprint,
3171.120Sthorpej		    CFARGS_NONE);
3181.17Schopps	if (is_a3000())
3191.118Sthorpej		config_found(self, __UNCONST("ahsc"), simple_devprint,
3201.120Sthorpej		    CFARGS_NONE);
3211.106Sphx	if (is_a600() || is_a1200())
3221.118Sthorpej		config_found(self, __UNCONST("pccard"), simple_devprint,
3231.120Sthorpej		    CFARGS_NONE);
3241.111Srkujawa	if (is_a1200())
3251.118Sthorpej		config_found(self, __UNCONST("a1k2cp"), simple_devprint,
3261.120Sthorpej		    CFARGS_NONE);
3271.54Sis#ifdef DRACO
3281.54Sis	if (!is_draco())
3291.54Sis#endif
3301.118Sthorpej		config_found(self, __UNCONST("aucc"), simple_devprint,
3311.120Sthorpej		    CFARGS_NONE);
3321.54Sis
3331.116Srkujawa#if NACAFH > 0
3341.116Srkujawa	if (!is_a600() && !is_a1200() && !is_a3000() && !is_a4000())
3351.116Srkujawa		if (acafh_mbattach_probe() == true)
3361.118Sthorpej			config_found(self, __UNCONST("acafh"), simple_devprint,
3371.120Sthorpej			    CFARGS_NONE);
3381.115Srkujawa#endif
3391.115Srkujawa
3401.120Sthorpej	config_found(self, __UNCONST("zbus"), simple_devprint, CFARGS_NONE);
3411.1Smw}
3421.1Smw
3431.11Schoppsint
3441.114Schsmbprint(void *aux, const char *pnp)
3451.1Smw{
3461.17Schopps	if (pnp)
3471.114Schs		aprint_normal("%s at %s", (char *)aux, pnp);
3481.17Schopps	return(UNCONF);
3491.1Smw}
3501.1Smw
3511.46Sthorpej/*
3521.46Sthorpej * The system will assign the "booted device" indicator (and thus
3531.46Sthorpej * rootdev if rootspec is wildcarded) to the first partition 'a'
3541.46Sthorpej * in preference of boot.  However, it does walk unit backwards
3551.46Sthorpej * to remain compatible with the old Amiga method of picking the
3561.46Sthorpej * last root found.
3571.46Sthorpej */
3581.46Sthorpej#include <sys/fcntl.h>		/* XXXX and all that uses it */
3591.46Sthorpej#include <sys/proc.h>		/* XXXX and all that uses it */
3601.17Schopps
3611.46Sthorpej#include "fd.h"
3621.46Sthorpej#include "sd.h"
3631.46Sthorpej#include "cd.h"
3641.67Saymeric#include "wd.h"
3651.1Smw
3661.46Sthorpej#if NFD > 0
3671.46Sthorpejextern  struct cfdriver fd_cd;
3681.82Sgehennaextern	const struct bdevsw fd_bdevsw;
3691.46Sthorpej#endif
3701.46Sthorpej#if NSD > 0
3711.69Smhitchextern  struct cfdriver sd_cd;
3721.82Sgehennaextern	const struct bdevsw sd_bdevsw;
3731.46Sthorpej#endif
3741.46Sthorpej#if NCD > 0
3751.46Sthorpejextern  struct cfdriver cd_cd;
3761.82Sgehennaextern	const struct bdevsw cd_bdevsw;
3771.46Sthorpej#endif
3781.67Saymeric#if NWD > 0
3791.69Smhitchextern  struct cfdriver wd_cd;
3801.82Sgehennaextern	const struct bdevsw wd_bdevsw;
3811.67Saymeric#endif
3821.1Smw
3831.46Sthorpejstruct cfdriver *genericconf[] = {
3841.46Sthorpej#if NFD > 0
3851.46Sthorpej	&fd_cd,
3861.46Sthorpej#endif
3871.46Sthorpej#if NSD > 0
3881.46Sthorpej	&sd_cd,
3891.46Sthorpej#endif
3901.69Smhitch#if NWD > 0
3911.69Smhitch	&wd_cd,
3921.69Smhitch#endif
3931.46Sthorpej#if NCD > 0
3941.46Sthorpej	&cd_cd,
3951.46Sthorpej#endif
3961.46Sthorpej	NULL,
3971.1Smw};
3981.1Smw
3991.11Schoppsvoid
4001.76Smattfindroot(void)
4011.1Smw{
4021.46Sthorpej	struct disk *dkp;
4031.46Sthorpej	struct partition *pp;
4041.99Scegger	device_t *devs;
4051.46Sthorpej	int i, maj, unit;
4061.82Sgehenna	const struct bdevsw *bdp;
4071.47Smhitch
4081.47Smhitch#if NSD > 0
4091.47Smhitch	/*
4101.47Smhitch	 * If we have the boot partition offset (boot_partition), try
4111.47Smhitch	 * to locate the device corresponding to that partition.
4121.47Smhitch	 */
4131.56Sis#ifdef DEBUG_KERNEL_START
4141.56Sis	printf("Boot partition offset is %ld\n", boot_partition);
4151.56Sis#endif
4161.47Smhitch	if (boot_partition != 0) {
4171.47Smhitch
4181.47Smhitch		for (unit = 0; unit < sd_cd.cd_ndevs; ++unit) {
4191.56Sis#ifdef DEBUG_KERNEL_START
4201.56Sis			printf("probing for sd%d\n", unit);
4211.56Sis#endif
4221.99Scegger			if (device_lookup(&sd_cd,unit) == NULL)
4231.47Smhitch				continue;
4241.47Smhitch
4251.47Smhitch			/*
4261.47Smhitch			 * Find the disk corresponding to the current
4271.47Smhitch			 * device.
4281.47Smhitch			 */
4291.114Schs			devs = sd_cd.cd_devs;
4301.99Scegger			if ((dkp = disk_find(device_xname(device_lookup(&sd_cd, unit)))) == NULL)
4311.47Smhitch				continue;
4321.47Smhitch
4331.47Smhitch			if (dkp->dk_driver == NULL ||
4341.47Smhitch			    dkp->dk_driver->d_strategy == NULL)
4351.47Smhitch				continue;
4361.82Sgehenna			bdp = &sd_bdevsw;
4371.82Sgehenna			maj = bdevsw_lookup_major(bdp);
4381.82Sgehenna			if ((*bdp->d_open)(MAKEDISKDEV(maj, unit, RAW_PART),
4391.98Schristos			    FREAD | FNONBLOCK, 0, curlwp))
4401.47Smhitch				continue;
4411.82Sgehenna			(*bdp->d_close)(MAKEDISKDEV(maj, unit, RAW_PART),
4421.98Schristos			    FREAD | FNONBLOCK, 0, curlwp);
4431.47Smhitch			pp = &dkp->dk_label->d_partitions[0];
4441.54Sis			for (i = 0; i < dkp->dk_label->d_npartitions;
4451.54Sis			    i++, pp++) {
4461.56Sis#ifdef DEBUG_KERNEL_START
4471.56Sis				printf("sd%d%c type %d offset %d size %d\n",
4481.56Sis					unit, i+'a', pp->p_fstype,
4491.56Sis					pp->p_offset, pp->p_size);
4501.56Sis#endif
4511.54Sis				if (pp->p_size == 0 ||
4521.54Sis				    (pp->p_fstype != FS_BSDFFS &&
4531.54Sis				    pp->p_fstype != FS_SWAP))
4541.54Sis					continue;
4551.54Sis				if (pp->p_offset == boot_partition) {
4561.76Smatt					if (booted_device == NULL) {
4571.76Smatt						booted_device = devs[unit];
4581.76Smatt						booted_partition = i;
4591.54Sis					} else
4601.54Sis						printf("Ambiguous boot device\n");
4611.54Sis				}
4621.47Smhitch			}
4631.47Smhitch		}
4641.47Smhitch	}
4651.76Smatt	if (booted_device != NULL)
4661.47Smhitch		return;		/* we found the boot device */
4671.47Smhitch#endif
4681.46Sthorpej
4691.46Sthorpej	for (i = 0; genericconf[i] != NULL; i++) {
4701.46Sthorpej		for (unit = genericconf[i]->cd_ndevs - 1; unit >= 0; unit--) {
4711.46Sthorpej			if (genericconf[i]->cd_devs[unit] == NULL)
4721.46Sthorpej				continue;
4731.46Sthorpej
4741.46Sthorpej			/*
4751.46Sthorpej			 * Find the disk structure corresponding to the
4761.46Sthorpej			 * current device.
4771.46Sthorpej			 */
4781.99Scegger			devs = (device_t *)genericconf[i]->cd_devs;
4791.99Scegger			if ((dkp = disk_find(device_xname(devs[unit]))) == NULL)
4801.46Sthorpej				continue;
4811.46Sthorpej
4821.46Sthorpej			if (dkp->dk_driver == NULL ||
4831.46Sthorpej			    dkp->dk_driver->d_strategy == NULL)
4841.46Sthorpej				continue;
4851.46Sthorpej
4861.92Smhitch			bdp = NULL;
4871.82Sgehenna#if NFD > 0
4881.82Sgehenna			if (fd_bdevsw.d_strategy == dkp->dk_driver->d_strategy)
4891.82Sgehenna				bdp = &fd_bdevsw;
4901.82Sgehenna#endif
4911.82Sgehenna#if NSD > 0
4921.82Sgehenna			if (sd_bdevsw.d_strategy == dkp->dk_driver->d_strategy)
4931.82Sgehenna				bdp = &sd_bdevsw;
4941.82Sgehenna#endif
4951.82Sgehenna#if NWD > 0
4961.82Sgehenna			if (wd_bdevsw.d_strategy == dkp->dk_driver->d_strategy)
4971.82Sgehenna				bdp = &wd_bdevsw;
4981.82Sgehenna#endif
4991.82Sgehenna#if NCD > 0
5001.82Sgehenna			if (cd_bdevsw.d_strategy == dkp->dk_driver->d_strategy)
5011.82Sgehenna				bdp = &cd_bdevsw;
5021.82Sgehenna#endif
5031.46Sthorpej#ifdef DIAGNOSTIC
5041.82Sgehenna			if (bdp == NULL)
5051.46Sthorpej				panic("findroot: impossible");
5061.46Sthorpej#endif
5071.82Sgehenna			maj = bdevsw_lookup_major(bdp);
5081.46Sthorpej
5091.46Sthorpej			/* Open disk; forces read of disklabel. */
5101.117Smlelstv			if ((*bdp->d_open)(MAKEDISKDEV(maj, unit, RAW_PART),
5111.117Smlelstv				FREAD|FNONBLOCK, 0, &lwp0))
5121.46Sthorpej				continue;
5131.117Smlelstv			(void)(*bdp->d_close)(MAKEDISKDEV(maj, unit, RAW_PART),
5141.117Smlelstv				FREAD|FNONBLOCK, 0, &lwp0);
5151.46Sthorpej
5161.46Sthorpej			pp = &dkp->dk_label->d_partitions[0];
5171.46Sthorpej			if (pp->p_size != 0 && pp->p_fstype == FS_BSDFFS) {
5181.76Smatt				booted_device = devs[unit];
5191.76Smatt				booted_partition = 0;
5201.46Sthorpej				return;
5211.46Sthorpej			}
5221.1Smw		}
5231.1Smw	}
5241.3Smw}
5251.17Schopps
5261.11Schopps/*
5271.11Schopps * Try to determine, of this machine is an A3000, which has a builtin
5281.11Schopps * realtime clock and scsi controller, so that this hardware is only
5291.11Schopps * included as "configured" if this IS an A3000
5301.11Schopps */
5311.5Smw
5321.5Smwint a3000_flag = 1;		/* patchable */
5331.5Smw#ifdef A4000
5341.5Smwint a4000_flag = 1;		/* patchable - default to A4000 */
5351.5Smw#else
5361.5Smwint a4000_flag = 0;		/* patchable */
5371.5Smw#endif
5381.5Smw
5391.3Smwint
5401.110Smattis_a3000(void)
5411.3Smw{
5421.11Schopps	/* this is a dirty kludge.. but how do you do this RIGHT ? :-) */
5431.22Schopps	extern long boot_fphystart;
5441.11Schopps	short sc;
5451.11Schopps
5461.19Schopps	if ((machineid >> 16) == 3000)
5471.19Schopps		return (1);			/* It's an A3000 */
5481.19Schopps	if (machineid >> 16)
5491.19Schopps		return (0);			/* It's not an A3000 */
5501.19Schopps	/* Machine type is unknown, so try to guess it */
5511.11Schopps	/* where is fastram on the A4000 ?? */
5521.11Schopps	/* if fastram is below 0x07000000, assume it's not an A3000 */
5531.22Schopps	if (boot_fphystart < 0x07000000)
5541.17Schopps		return(0);
5551.11Schopps	/*
5561.11Schopps	 * OK, fastram starts at or above 0x07000000, check specific
5571.11Schopps	 * machines
5581.11Schopps	 */
5591.17Schopps	for (sc = 0; sc < ncfdev; sc++) {
5601.17Schopps		switch (cfdev[sc].rom.manid) {
5611.17Schopps		case 2026:		/* Progressive Peripherals, Inc */
5621.17Schopps			switch (cfdev[sc].rom.prodid) {
5631.17Schopps			case 0:		/* PPI Mercury - A3000 */
5641.17Schopps			case 1:		/* PP&S A3000 '040 */
5651.17Schopps				return(1);
5661.17Schopps			case 150:	/* PPI Zeus - it's an A2000 */
5671.17Schopps			case 105:	/* PP&S A2000 '040 */
5681.17Schopps			case 187:	/* PP&S A500 '040 */
5691.17Schopps				return(0);
5701.11Schopps			}
5711.11Schopps			break;
5721.3Smw
5731.17Schopps		case 2112:			/* IVS */
5741.17Schopps			switch (cfdev[sc].rom.prodid) {
5751.17Schopps			case 242:
5761.17Schopps				return(0);	/* A2000 accelerator? */
5771.11Schopps			}
5781.11Schopps			break;
5791.11Schopps		}
5801.11Schopps	}
5811.17Schopps	return (a3000_flag);		/* XXX let flag tell now */
5821.5Smw}
5831.5Smw
5841.5Smwint
5851.110Smattis_a4000(void)
5861.5Smw{
5871.19Schopps	if ((machineid >> 16) == 4000)
5881.19Schopps		return (1);		/* It's an A4000 */
5891.24Schopps	if ((machineid >> 16) == 1200)
5901.24Schopps		return (0);		/* It's an A1200, so not A4000 */
5911.36Sis#ifdef DRACO
5921.36Sis	if (is_draco())
5931.36Sis		return (0);
5941.36Sis#endif
5951.24Schopps	/* Do I need this any more? */
5961.19Schopps	if ((custom.deniseid & 0xff) == 0xf8)
5971.19Schopps		return (1);
5981.19Schopps#ifdef DEBUG
5991.19Schopps	if (a4000_flag)
6001.43Schristos		printf("Denise ID = %04x\n", (unsigned short)custom.deniseid);
6011.19Schopps#endif
6021.19Schopps	if (machineid >> 16)
6031.19Schopps		return (0);		/* It's not an A4000 */
6041.19Schopps	return (a4000_flag);		/* Machine type not set */
6051.24Schopps}
6061.24Schopps
6071.24Schoppsint
6081.110Smattis_a1200(void)
6091.24Schopps{
6101.24Schopps	if ((machineid >> 16) == 1200)
6111.24Schopps		return (1);		/* It's an A1200 */
6121.24Schopps	return (0);			/* Machine type not set */
6131.1Smw}
6141.106Sphx
6151.106Sphxint
6161.110Smattis_a600(void)
6171.106Sphx{
6181.106Sphx	if ((machineid >> 16) == 600)
6191.106Sphx		return (1);		/* It's an A600 */
6201.106Sphx	return (0);			/* Machine type not set */
6211.106Sphx}
6221.108Srkujawa
6231.108Srkujawavoid
6241.108Srkujawadevice_register(device_t dev, void *aux)
6251.108Srkujawa{
6261.112Srkujawa#ifdef P5PB_CONSOLE
6271.112Srkujawa	p5pb_device_register(dev, aux);
6281.112Srkujawa#endif /* P5PB_CONSOLE */
6291.108Srkujawa}
630