autoconf.c revision 1.99
11.99Scegger/*	$NetBSD: autoconf.c,v 1.99 2008/06/13 08:17:24 cegger 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.99Scegger__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.99 2008/06/13 08:17:24 cegger 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.1Smw
501.79Saymericstatic void findroot(void);
511.79Saymericvoid mbattach(struct device *, struct device *, void *);
521.79Saymericint mbprint(void *, const char *);
531.79Saymericint mbmatch(struct device *, struct cfdata *, void *);
541.11Schopps
551.17Schopps#include <sys/kernel.h>
561.46Sthorpej
571.47Smhitchu_long boot_partition;
581.81Saymeric
591.81Saymericint amiga_realconfig;
601.46Sthorpej
611.1Smw/*
621.17Schopps * called at boot time, configure all devices on system
631.1Smw */
641.11Schoppsvoid
651.65Sthorpejcpu_configure()
661.1Smw{
671.44Sis	int s;
681.62Sis#ifdef DEBUG_KERNEL_START
691.62Sis	int i;
701.62Sis#endif
711.49Sgwr
721.17Schopps	/*
731.17Schopps	 * this is the real thing baby (i.e. not console init)
741.17Schopps	 */
751.17Schopps	amiga_realconfig = 1;
761.36Sis#ifdef DRACO
771.36Sis	if (is_draco()) {
781.36Sis		*draco_intena &= ~DRIRQ_GLOBAL;
791.36Sis	} else
801.36Sis#endif
811.3Smw	custom.intena = INTF_INTEN;
821.44Sis	s = splhigh();
831.1Smw
841.95Sjmc	if (config_rootfound("mainbus", NULL) == NULL)
851.17Schopps		panic("no mainbus found");
861.36Sis
871.39Sis#ifdef DEBUG_KERNEL_START
881.43Schristos	printf("survived autoconf, going to enable interrupts\n");
891.39Sis#endif
901.79Saymeric
911.36Sis#ifdef DRACO
921.36Sis	if (is_draco()) {
931.36Sis		*draco_intena |= DRIRQ_GLOBAL;
941.36Sis		/* softints always enabled */
951.36Sis	} else
961.36Sis#endif
971.36Sis	{
981.36Sis		custom.intena = INTF_SETCLR | INTF_INTEN;
991.28Schopps
1001.36Sis		/* also enable hardware aided software interrupts */
1011.36Sis		custom.intena = INTF_SETCLR | INTF_SOFTINT;
1021.36Sis	}
1031.39Sis#ifdef DEBUG_KERNEL_START
1041.62Sis	for (i=splhigh(); i>=s ;i-=0x100) {
1051.62Sis		splx(i);
1061.62Sis		printf("%d...", (i>>8) & 7);
1071.62Sis	}
1081.43Schristos	printf("survived interrupt enable\n");
1091.62Sis#else
1101.62Sis	splx(s);
1111.39Sis#endif
1121.63Sthorpej#ifdef DEBUG_KERNEL_START
1131.63Sthorpej	printf("survived configure...\n");
1141.63Sthorpej#endif
1151.49Sgwr}
1161.49Sgwr
1171.49Sgwrvoid
1181.49Sgwrcpu_rootconf()
1191.49Sgwr{
1201.77Sfrueauf	findroot();
1211.39Sis#ifdef DEBUG_KERNEL_START
1221.46Sthorpej	printf("survived findroot()\n");
1231.39Sis#endif
1241.64Sthorpej	setroot(booted_device, booted_partition);
1251.39Sis#ifdef DEBUG_KERNEL_START
1261.43Schristos	printf("survived setroot()\n");
1271.1Smw#endif
1281.17Schopps}
1291.3Smw
1301.17Schopps/*ARGSUSED*/
1311.17Schoppsint
1321.17Schoppssimple_devprint(auxp, pnp)
1331.17Schopps	void *auxp;
1341.42Smhitch	const char *pnp;
1351.17Schopps{
1361.17Schopps	return(QUIET);
1371.1Smw}
1381.1Smw
1391.17Schoppsint
1401.17Schoppsmatchname(fp, sp)
1411.94Sjandberg	const char *fp, *sp;
1421.17Schopps{
1431.17Schopps	int len;
1441.1Smw
1451.17Schopps	len = strlen(fp);
1461.17Schopps	if (strlen(sp) != len)
1471.17Schopps		return(0);
1481.17Schopps	if (bcmp(fp, sp, len) == 0)
1491.17Schopps		return(1);
1501.17Schopps	return(0);
1511.17Schopps}
1521.1Smw
1531.17Schopps/*
1541.96Sdrochner * use config_search_ia to find appropriate device, then call that device
1551.79Saymeric * directly with NULL device variable storage.  A device can then
1561.79Saymeric * always tell the difference betwean the real and console init
1571.17Schopps * by checking for NULL.
1581.17Schopps */
1591.11Schoppsint
1601.17Schoppsamiga_config_found(pcfp, pdp, auxp, pfn)
1611.17Schopps	struct cfdata *pcfp;
1621.17Schopps	struct device *pdp;
1631.17Schopps	void *auxp;
1641.17Schopps	cfprint_t pfn;
1651.1Smw{
1661.17Schopps	struct device temp;
1671.17Schopps	struct cfdata *cf;
1681.86Sthorpej	const struct cfattach *ca;
1691.17Schopps
1701.17Schopps	if (amiga_realconfig)
1711.31Scgd		return(config_found(pdp, auxp, pfn) != NULL);
1721.17Schopps
1731.89Saymeric	if (pdp == NULL) {
1741.89Saymeric		memset(&temp, 0, sizeof temp);
1751.17Schopps		pdp = &temp;
1761.89Saymeric	}
1771.17Schopps
1781.17Schopps	pdp->dv_cfdata = pcfp;
1791.88Saymeric	pdp->dv_cfdriver = config_cfdriver_lookup(pcfp->cf_name);
1801.91Saymeric	pdp->dv_unit = pcfp->cf_unit;
1811.89Saymeric
1821.97Sisaki	if ((cf = config_search_ia(NULL, pdp, NULL, auxp)) != NULL) {
1831.86Sthorpej		ca = config_cfattach_lookup(cf->cf_name, cf->cf_atname);
1841.86Sthorpej		if (ca != NULL) {
1851.86Sthorpej			(*ca->ca_attach)(pdp, NULL, auxp);
1861.86Sthorpej			pdp->dv_cfdata = NULL;
1871.86Sthorpej			return(1);
1881.86Sthorpej		}
1891.1Smw	}
1901.17Schopps	pdp->dv_cfdata = NULL;
1911.17Schopps	return(0);
1921.17Schopps}
1931.17Schopps
1941.17Schopps/*
1951.17Schopps * this function needs to get enough configured to do a console
1961.79Saymeric * basically this means start attaching the grfxx's that support
1971.17Schopps * the console. Kinda hacky but it works.
1981.17Schopps */
1991.32Sveegovoid
2001.17Schoppsconfig_console()
2011.79Saymeric{
2021.17Schopps	struct cfdata *cf;
2031.84Sthorpej
2041.84Sthorpej	config_init();
2051.36Sis
2061.17Schopps	/*
2071.17Schopps	 * we need mainbus' cfdata.
2081.17Schopps	 */
2091.95Sjmc	cf = config_rootsearch(NULL, "mainbus", NULL);
2101.36Sis	if (cf == NULL) {
2111.17Schopps		panic("no mainbus");
2121.36Sis	}
2131.1Smw	/*
2141.44Sis	 * delay clock calibration.
2151.44Sis	 */
2161.95Sjmc	amiga_config_found(cf, NULL, __UNCONST("clock"), NULL);
2171.44Sis
2181.44Sis	/*
2191.17Schopps	 * internal grf.
2201.1Smw	 */
2211.36Sis#ifdef DRACO
2221.36Sis	if (!(is_draco()))
2231.36Sis#endif
2241.95Sjmc		amiga_config_found(cf, NULL, __UNCONST("grfcc"), NULL);
2251.67Saymeric
2261.1Smw	/*
2271.27Schopps	 * zbus knows when its not for real and will
2281.21Schopps	 * only configure the appropriate hardware
2291.1Smw	 */
2301.95Sjmc	amiga_config_found(cf, NULL, __UNCONST("zbus"), NULL);
2311.1Smw}
2321.1Smw
2331.79Saymeric/*
2341.79Saymeric * mainbus driver
2351.17Schopps */
2361.85SthorpejCFATTACH_DECL(mainbus, sizeof(struct device),
2371.85Sthorpej    mbmatch, mbattach, NULL, NULL);
2381.17Schopps
2391.11Schoppsint
2401.45Sveegombmatch(pdp, cfp, auxp)
2411.45Sveego	struct device	*pdp;
2421.45Sveego	struct cfdata	*cfp;
2431.45Sveego	void		*auxp;
2441.1Smw{
2451.72Sis#if 0	/*
2461.72Sis	 * XXX is this right? but we need to be found twice
2471.72Sis	 * (early console init hack)
2481.72Sis	 */
2491.71Skleink	static int mainbus_matched = 0;
2501.30Sthorpej
2511.71Skleink	/* Allow only one instance. */
2521.71Skleink	if (mainbus_matched)
2531.71Skleink		return (0);
2541.71Skleink
2551.71Skleink	mainbus_matched = 1;
2561.72Sis#endif
2571.71Skleink	return (1);
2581.1Smw}
2591.1Smw
2601.1Smw/*
2611.17Schopps * "find" all the things that should be there.
2621.1Smw */
2631.11Schoppsvoid
2641.17Schoppsmbattach(pdp, dp, auxp)
2651.17Schopps	struct device *pdp, *dp;
2661.17Schopps	void *auxp;
2671.1Smw{
2681.43Schristos	printf("\n");
2691.95Sjmc	config_found(dp, __UNCONST("clock"), simple_devprint);
2701.52Sis	if (is_a3000() || is_a4000()) {
2711.95Sjmc		config_found(dp, __UNCONST("a34kbbc"), simple_devprint);
2721.58Sis	} else
2731.53Sis#ifdef DRACO
2741.58Sis	if (!is_draco())
2751.53Sis#endif
2761.58Sis	{
2771.95Sjmc		config_found(dp, __UNCONST("a2kbbc"), simple_devprint);
2781.52Sis	}
2791.36Sis#ifdef DRACO
2801.36Sis	if (is_draco()) {
2811.95Sjmc		config_found(dp, __UNCONST("drbbc"), simple_devprint);
2821.95Sjmc		config_found(dp, __UNCONST("kbd"), simple_devprint);
2831.95Sjmc		config_found(dp, __UNCONST("drsc"), simple_devprint);
2841.95Sjmc		config_found(dp, __UNCONST("drsupio"), simple_devprint);
2851.79Saymeric	} else
2861.36Sis#endif
2871.36Sis	{
2881.95Sjmc		config_found(dp, __UNCONST("ser"), simple_devprint);
2891.95Sjmc		config_found(dp, __UNCONST("par"), simple_devprint);
2901.95Sjmc		config_found(dp, __UNCONST("kbd"), simple_devprint);
2911.95Sjmc		config_found(dp, __UNCONST("ms"), simple_devprint);
2921.95Sjmc		config_found(dp, __UNCONST("grfcc"), simple_devprint);
2931.95Sjmc		config_found(dp, __UNCONST("amidisplaycc"), simple_devprint);
2941.95Sjmc		config_found(dp, __UNCONST("fdc"), simple_devprint);
2951.36Sis	}
2961.69Smhitch	if (is_a4000() || is_a1200()) {
2971.95Sjmc		config_found(dp, __UNCONST("wdc"), simple_devprint);
2981.95Sjmc		config_found(dp, __UNCONST("idesc"), simple_devprint);
2991.69Smhitch	}
3001.29Schopps	if (is_a4000())			/* Try to configure A4000T SCSI */
3011.95Sjmc		config_found(dp, __UNCONST("afsc"), simple_devprint);
3021.17Schopps	if (is_a3000())
3031.95Sjmc		config_found(dp, __UNCONST("ahsc"), simple_devprint);
3041.67Saymeric	if (/*is_a600() || */is_a1200())
3051.95Sjmc		config_found(dp, __UNCONST("pccard"), simple_devprint);
3061.54Sis#ifdef DRACO
3071.54Sis	if (!is_draco())
3081.54Sis#endif
3091.95Sjmc		config_found(dp, __UNCONST("aucc"), simple_devprint);
3101.54Sis
3111.95Sjmc	config_found(dp, __UNCONST("zbus"), simple_devprint);
3121.1Smw}
3131.1Smw
3141.11Schoppsint
3151.17Schoppsmbprint(auxp, pnp)
3161.17Schopps	void *auxp;
3171.40Scgd	const char *pnp;
3181.1Smw{
3191.17Schopps	if (pnp)
3201.87Sthorpej		aprint_normal("%s at %s", (char *)auxp, pnp);
3211.17Schopps	return(UNCONF);
3221.1Smw}
3231.1Smw
3241.46Sthorpej/*
3251.46Sthorpej * The system will assign the "booted device" indicator (and thus
3261.46Sthorpej * rootdev if rootspec is wildcarded) to the first partition 'a'
3271.46Sthorpej * in preference of boot.  However, it does walk unit backwards
3281.46Sthorpej * to remain compatible with the old Amiga method of picking the
3291.46Sthorpej * last root found.
3301.46Sthorpej */
3311.46Sthorpej#include <sys/fcntl.h>		/* XXXX and all that uses it */
3321.46Sthorpej#include <sys/proc.h>		/* XXXX and all that uses it */
3331.17Schopps
3341.46Sthorpej#include "fd.h"
3351.46Sthorpej#include "sd.h"
3361.46Sthorpej#include "cd.h"
3371.67Saymeric#include "wd.h"
3381.1Smw
3391.46Sthorpej#if NFD > 0
3401.46Sthorpejextern  struct cfdriver fd_cd;
3411.82Sgehennaextern	const struct bdevsw fd_bdevsw;
3421.46Sthorpej#endif
3431.46Sthorpej#if NSD > 0
3441.69Smhitchextern  struct cfdriver sd_cd;
3451.82Sgehennaextern	const struct bdevsw sd_bdevsw;
3461.46Sthorpej#endif
3471.46Sthorpej#if NCD > 0
3481.46Sthorpejextern  struct cfdriver cd_cd;
3491.82Sgehennaextern	const struct bdevsw cd_bdevsw;
3501.46Sthorpej#endif
3511.67Saymeric#if NWD > 0
3521.69Smhitchextern  struct cfdriver wd_cd;
3531.82Sgehennaextern	const struct bdevsw wd_bdevsw;
3541.67Saymeric#endif
3551.1Smw
3561.46Sthorpejstruct cfdriver *genericconf[] = {
3571.46Sthorpej#if NFD > 0
3581.46Sthorpej	&fd_cd,
3591.46Sthorpej#endif
3601.46Sthorpej#if NSD > 0
3611.46Sthorpej	&sd_cd,
3621.46Sthorpej#endif
3631.69Smhitch#if NWD > 0
3641.69Smhitch	&wd_cd,
3651.69Smhitch#endif
3661.46Sthorpej#if NCD > 0
3671.46Sthorpej	&cd_cd,
3681.46Sthorpej#endif
3691.46Sthorpej	NULL,
3701.1Smw};
3711.1Smw
3721.11Schoppsvoid
3731.76Smattfindroot(void)
3741.1Smw{
3751.46Sthorpej	struct disk *dkp;
3761.46Sthorpej	struct partition *pp;
3771.99Scegger	device_t *devs;
3781.46Sthorpej	int i, maj, unit;
3791.82Sgehenna	const struct bdevsw *bdp;
3801.47Smhitch
3811.47Smhitch#if NSD > 0
3821.47Smhitch	/*
3831.47Smhitch	 * If we have the boot partition offset (boot_partition), try
3841.47Smhitch	 * to locate the device corresponding to that partition.
3851.47Smhitch	 */
3861.56Sis#ifdef DEBUG_KERNEL_START
3871.56Sis	printf("Boot partition offset is %ld\n", boot_partition);
3881.56Sis#endif
3891.47Smhitch	if (boot_partition != 0) {
3901.47Smhitch
3911.47Smhitch		for (unit = 0; unit < sd_cd.cd_ndevs; ++unit) {
3921.56Sis#ifdef DEBUG_KERNEL_START
3931.56Sis			printf("probing for sd%d\n", unit);
3941.56Sis#endif
3951.99Scegger			if (device_lookup(&sd_cd,unit) == NULL)
3961.47Smhitch				continue;
3971.47Smhitch
3981.47Smhitch			/*
3991.47Smhitch			 * Find the disk corresponding to the current
4001.47Smhitch			 * device.
4011.47Smhitch			 */
4021.99Scegger			devs = (device_t *)sd_cd.cd_devs;
4031.99Scegger			if ((dkp = disk_find(device_xname(device_lookup(&sd_cd, unit)))) == NULL)
4041.47Smhitch				continue;
4051.47Smhitch
4061.47Smhitch			if (dkp->dk_driver == NULL ||
4071.47Smhitch			    dkp->dk_driver->d_strategy == NULL)
4081.47Smhitch				continue;
4091.82Sgehenna			bdp = &sd_bdevsw;
4101.82Sgehenna			maj = bdevsw_lookup_major(bdp);
4111.82Sgehenna			if ((*bdp->d_open)(MAKEDISKDEV(maj, unit, RAW_PART),
4121.98Schristos			    FREAD | FNONBLOCK, 0, curlwp))
4131.47Smhitch				continue;
4141.82Sgehenna			(*bdp->d_close)(MAKEDISKDEV(maj, unit, RAW_PART),
4151.98Schristos			    FREAD | FNONBLOCK, 0, curlwp);
4161.47Smhitch			pp = &dkp->dk_label->d_partitions[0];
4171.54Sis			for (i = 0; i < dkp->dk_label->d_npartitions;
4181.54Sis			    i++, pp++) {
4191.56Sis#ifdef DEBUG_KERNEL_START
4201.56Sis				printf("sd%d%c type %d offset %d size %d\n",
4211.56Sis					unit, i+'a', pp->p_fstype,
4221.56Sis					pp->p_offset, pp->p_size);
4231.56Sis#endif
4241.54Sis				if (pp->p_size == 0 ||
4251.54Sis				    (pp->p_fstype != FS_BSDFFS &&
4261.54Sis				    pp->p_fstype != FS_SWAP))
4271.54Sis					continue;
4281.54Sis				if (pp->p_offset == boot_partition) {
4291.76Smatt					if (booted_device == NULL) {
4301.76Smatt						booted_device = devs[unit];
4311.76Smatt						booted_partition = i;
4321.54Sis					} else
4331.54Sis						printf("Ambiguous boot device\n");
4341.54Sis				}
4351.47Smhitch			}
4361.47Smhitch		}
4371.47Smhitch	}
4381.76Smatt	if (booted_device != NULL)
4391.47Smhitch		return;		/* we found the boot device */
4401.47Smhitch#endif
4411.46Sthorpej
4421.46Sthorpej	for (i = 0; genericconf[i] != NULL; i++) {
4431.46Sthorpej		for (unit = genericconf[i]->cd_ndevs - 1; unit >= 0; unit--) {
4441.46Sthorpej			if (genericconf[i]->cd_devs[unit] == NULL)
4451.46Sthorpej				continue;
4461.46Sthorpej
4471.46Sthorpej			/*
4481.46Sthorpej			 * Find the disk structure corresponding to the
4491.46Sthorpej			 * current device.
4501.46Sthorpej			 */
4511.99Scegger			devs = (device_t *)genericconf[i]->cd_devs;
4521.99Scegger			if ((dkp = disk_find(device_xname(devs[unit]))) == NULL)
4531.46Sthorpej				continue;
4541.46Sthorpej
4551.46Sthorpej			if (dkp->dk_driver == NULL ||
4561.46Sthorpej			    dkp->dk_driver->d_strategy == NULL)
4571.46Sthorpej				continue;
4581.46Sthorpej
4591.92Smhitch			bdp = NULL;
4601.82Sgehenna#if NFD > 0
4611.82Sgehenna			if (fd_bdevsw.d_strategy == dkp->dk_driver->d_strategy)
4621.82Sgehenna				bdp = &fd_bdevsw;
4631.82Sgehenna#endif
4641.82Sgehenna#if NSD > 0
4651.82Sgehenna			if (sd_bdevsw.d_strategy == dkp->dk_driver->d_strategy)
4661.82Sgehenna				bdp = &sd_bdevsw;
4671.82Sgehenna#endif
4681.82Sgehenna#if NWD > 0
4691.82Sgehenna			if (wd_bdevsw.d_strategy == dkp->dk_driver->d_strategy)
4701.82Sgehenna				bdp = &wd_bdevsw;
4711.82Sgehenna#endif
4721.82Sgehenna#if NCD > 0
4731.82Sgehenna			if (cd_bdevsw.d_strategy == dkp->dk_driver->d_strategy)
4741.82Sgehenna				bdp = &cd_bdevsw;
4751.82Sgehenna#endif
4761.46Sthorpej#ifdef DIAGNOSTIC
4771.82Sgehenna			if (bdp == NULL)
4781.46Sthorpej				panic("findroot: impossible");
4791.46Sthorpej#endif
4801.82Sgehenna			maj = bdevsw_lookup_major(bdp);
4811.46Sthorpej
4821.46Sthorpej			/* Open disk; forces read of disklabel. */
4831.82Sgehenna			if ((*bdp->d_open)(MAKEDISKDEV(maj,
4841.98Schristos			    unit, 0), FREAD|FNONBLOCK, 0, &lwp0))
4851.46Sthorpej				continue;
4861.82Sgehenna			(void)(*bdp->d_close)(MAKEDISKDEV(maj,
4871.98Schristos			    unit, 0), FREAD|FNONBLOCK, 0, &lwp0);
4881.46Sthorpej
4891.46Sthorpej			pp = &dkp->dk_label->d_partitions[0];
4901.46Sthorpej			if (pp->p_size != 0 && pp->p_fstype == FS_BSDFFS) {
4911.76Smatt				booted_device = devs[unit];
4921.76Smatt				booted_partition = 0;
4931.46Sthorpej				return;
4941.46Sthorpej			}
4951.1Smw		}
4961.1Smw	}
4971.3Smw}
4981.17Schopps
4991.11Schopps/*
5001.11Schopps * Try to determine, of this machine is an A3000, which has a builtin
5011.11Schopps * realtime clock and scsi controller, so that this hardware is only
5021.11Schopps * included as "configured" if this IS an A3000
5031.11Schopps */
5041.5Smw
5051.5Smwint a3000_flag = 1;		/* patchable */
5061.5Smw#ifdef A4000
5071.5Smwint a4000_flag = 1;		/* patchable - default to A4000 */
5081.5Smw#else
5091.5Smwint a4000_flag = 0;		/* patchable */
5101.5Smw#endif
5111.5Smw
5121.3Smwint
5131.11Schoppsis_a3000()
5141.3Smw{
5151.11Schopps	/* this is a dirty kludge.. but how do you do this RIGHT ? :-) */
5161.22Schopps	extern long boot_fphystart;
5171.11Schopps	short sc;
5181.11Schopps
5191.19Schopps	if ((machineid >> 16) == 3000)
5201.19Schopps		return (1);			/* It's an A3000 */
5211.19Schopps	if (machineid >> 16)
5221.19Schopps		return (0);			/* It's not an A3000 */
5231.19Schopps	/* Machine type is unknown, so try to guess it */
5241.11Schopps	/* where is fastram on the A4000 ?? */
5251.11Schopps	/* if fastram is below 0x07000000, assume it's not an A3000 */
5261.22Schopps	if (boot_fphystart < 0x07000000)
5271.17Schopps		return(0);
5281.11Schopps	/*
5291.11Schopps	 * OK, fastram starts at or above 0x07000000, check specific
5301.11Schopps	 * machines
5311.11Schopps	 */
5321.17Schopps	for (sc = 0; sc < ncfdev; sc++) {
5331.17Schopps		switch (cfdev[sc].rom.manid) {
5341.17Schopps		case 2026:		/* Progressive Peripherals, Inc */
5351.17Schopps			switch (cfdev[sc].rom.prodid) {
5361.17Schopps			case 0:		/* PPI Mercury - A3000 */
5371.17Schopps			case 1:		/* PP&S A3000 '040 */
5381.17Schopps				return(1);
5391.17Schopps			case 150:	/* PPI Zeus - it's an A2000 */
5401.17Schopps			case 105:	/* PP&S A2000 '040 */
5411.17Schopps			case 187:	/* PP&S A500 '040 */
5421.17Schopps				return(0);
5431.11Schopps			}
5441.11Schopps			break;
5451.3Smw
5461.17Schopps		case 2112:			/* IVS */
5471.17Schopps			switch (cfdev[sc].rom.prodid) {
5481.17Schopps			case 242:
5491.17Schopps				return(0);	/* A2000 accelerator? */
5501.11Schopps			}
5511.11Schopps			break;
5521.11Schopps		}
5531.11Schopps	}
5541.17Schopps	return (a3000_flag);		/* XXX let flag tell now */
5551.5Smw}
5561.5Smw
5571.5Smwint
5581.11Schoppsis_a4000()
5591.5Smw{
5601.19Schopps	if ((machineid >> 16) == 4000)
5611.19Schopps		return (1);		/* It's an A4000 */
5621.24Schopps	if ((machineid >> 16) == 1200)
5631.24Schopps		return (0);		/* It's an A1200, so not A4000 */
5641.36Sis#ifdef DRACO
5651.36Sis	if (is_draco())
5661.36Sis		return (0);
5671.36Sis#endif
5681.24Schopps	/* Do I need this any more? */
5691.19Schopps	if ((custom.deniseid & 0xff) == 0xf8)
5701.19Schopps		return (1);
5711.19Schopps#ifdef DEBUG
5721.19Schopps	if (a4000_flag)
5731.43Schristos		printf("Denise ID = %04x\n", (unsigned short)custom.deniseid);
5741.19Schopps#endif
5751.19Schopps	if (machineid >> 16)
5761.19Schopps		return (0);		/* It's not an A4000 */
5771.19Schopps	return (a4000_flag);		/* Machine type not set */
5781.24Schopps}
5791.24Schopps
5801.24Schoppsint
5811.24Schoppsis_a1200()
5821.24Schopps{
5831.24Schopps	if ((machineid >> 16) == 1200)
5841.24Schopps		return (1);		/* It's an A1200 */
5851.24Schopps	return (0);			/* Machine type not set */
5861.1Smw}
587