autoconf.c revision 1.108
11.108Srkujawa/*	$NetBSD: autoconf.c,v 1.108 2011/08/04 17:48:50 rkujawa 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.108Srkujawa__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.108 2011/08/04 17:48:50 rkujawa 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.108Srkujawa#include <dev/pci/pcireg.h>
531.108Srkujawa#include <dev/pci/pcivar.h>
541.108Srkujawa#include <dev/pci/pcidevs.h>
551.1Smw
561.79Saymericstatic void findroot(void);
571.107Smattvoid mbattach(device_t, device_t, void *);
581.79Saymericint mbprint(void *, const char *);
591.107Smattint mbmatch(device_t, cfdata_t, void *);
601.11Schopps
611.17Schopps#include <sys/kernel.h>
621.46Sthorpej
631.47Smhitchu_long boot_partition;
641.81Saymeric
651.81Saymericint amiga_realconfig;
661.46Sthorpej
671.1Smw/*
681.17Schopps * called at boot time, configure all devices on system
691.1Smw */
701.11Schoppsvoid
711.102Sceggercpu_configure(void)
721.1Smw{
731.44Sis	int s;
741.62Sis#ifdef DEBUG_KERNEL_START
751.62Sis	int i;
761.62Sis#endif
771.49Sgwr
781.17Schopps	/*
791.17Schopps	 * this is the real thing baby (i.e. not console init)
801.17Schopps	 */
811.17Schopps	amiga_realconfig = 1;
821.36Sis#ifdef DRACO
831.36Sis	if (is_draco()) {
841.36Sis		*draco_intena &= ~DRIRQ_GLOBAL;
851.36Sis	} else
861.36Sis#endif
871.3Smw	custom.intena = INTF_INTEN;
881.44Sis	s = splhigh();
891.1Smw
901.95Sjmc	if (config_rootfound("mainbus", NULL) == NULL)
911.17Schopps		panic("no mainbus found");
921.36Sis
931.39Sis#ifdef DEBUG_KERNEL_START
941.43Schristos	printf("survived autoconf, going to enable interrupts\n");
951.39Sis#endif
961.79Saymeric
971.36Sis#ifdef DRACO
981.36Sis	if (is_draco()) {
991.36Sis		*draco_intena |= DRIRQ_GLOBAL;
1001.36Sis		/* softints always enabled */
1011.36Sis	} else
1021.36Sis#endif
1031.36Sis	{
1041.36Sis		custom.intena = INTF_SETCLR | INTF_INTEN;
1051.28Schopps
1061.36Sis		/* also enable hardware aided software interrupts */
1071.36Sis		custom.intena = INTF_SETCLR | INTF_SOFTINT;
1081.36Sis	}
1091.39Sis#ifdef DEBUG_KERNEL_START
1101.62Sis	for (i=splhigh(); i>=s ;i-=0x100) {
1111.62Sis		splx(i);
1121.62Sis		printf("%d...", (i>>8) & 7);
1131.62Sis	}
1141.43Schristos	printf("survived interrupt enable\n");
1151.62Sis#else
1161.62Sis	splx(s);
1171.39Sis#endif
1181.63Sthorpej#ifdef DEBUG_KERNEL_START
1191.63Sthorpej	printf("survived configure...\n");
1201.63Sthorpej#endif
1211.49Sgwr}
1221.49Sgwr
1231.49Sgwrvoid
1241.102Sceggercpu_rootconf(void)
1251.49Sgwr{
1261.77Sfrueauf	findroot();
1271.39Sis#ifdef DEBUG_KERNEL_START
1281.46Sthorpej	printf("survived findroot()\n");
1291.39Sis#endif
1301.64Sthorpej	setroot(booted_device, booted_partition);
1311.39Sis#ifdef DEBUG_KERNEL_START
1321.43Schristos	printf("survived setroot()\n");
1331.1Smw#endif
1341.17Schopps}
1351.3Smw
1361.17Schopps/*ARGSUSED*/
1371.17Schoppsint
1381.100Sdslsimple_devprint(void *auxp, const char *pnp)
1391.17Schopps{
1401.17Schopps	return(QUIET);
1411.1Smw}
1421.1Smw
1431.17Schoppsint
1441.101Sdslmatchname(const char *fp, const char *sp)
1451.17Schopps{
1461.17Schopps	int len;
1471.1Smw
1481.17Schopps	len = strlen(fp);
1491.17Schopps	if (strlen(sp) != len)
1501.17Schopps		return(0);
1511.103Scegger	if (memcmp(fp, sp, len) == 0)
1521.17Schopps		return(1);
1531.17Schopps	return(0);
1541.17Schopps}
1551.1Smw
1561.17Schopps/*
1571.96Sdrochner * use config_search_ia to find appropriate device, then call that device
1581.79Saymeric * directly with NULL device variable storage.  A device can then
1591.79Saymeric * always tell the difference betwean the real and console init
1601.17Schopps * by checking for NULL.
1611.17Schopps */
1621.11Schoppsint
1631.107Smattamiga_config_found(cfdata_t pcfp, device_t pdp, void *auxp, cfprint_t pfn)
1641.1Smw{
1651.17Schopps	struct device temp;
1661.107Smatt	cfdata_t cf;
1671.86Sthorpej	const struct cfattach *ca;
1681.17Schopps
1691.17Schopps	if (amiga_realconfig)
1701.31Scgd		return(config_found(pdp, auxp, pfn) != NULL);
1711.17Schopps
1721.89Saymeric	if (pdp == NULL) {
1731.89Saymeric		memset(&temp, 0, sizeof temp);
1741.17Schopps		pdp = &temp;
1751.89Saymeric	}
1761.17Schopps
1771.17Schopps	pdp->dv_cfdata = pcfp;
1781.88Saymeric	pdp->dv_cfdriver = config_cfdriver_lookup(pcfp->cf_name);
1791.91Saymeric	pdp->dv_unit = pcfp->cf_unit;
1801.89Saymeric
1811.97Sisaki	if ((cf = config_search_ia(NULL, pdp, NULL, auxp)) != NULL) {
1821.86Sthorpej		ca = config_cfattach_lookup(cf->cf_name, cf->cf_atname);
1831.86Sthorpej		if (ca != NULL) {
1841.86Sthorpej			(*ca->ca_attach)(pdp, NULL, auxp);
1851.86Sthorpej			pdp->dv_cfdata = NULL;
1861.86Sthorpej			return(1);
1871.86Sthorpej		}
1881.1Smw	}
1891.17Schopps	pdp->dv_cfdata = NULL;
1901.17Schopps	return(0);
1911.17Schopps}
1921.17Schopps
1931.17Schopps/*
1941.17Schopps * this function needs to get enough configured to do a console
1951.79Saymeric * basically this means start attaching the grfxx's that support
1961.17Schopps * the console. Kinda hacky but it works.
1971.17Schopps */
1981.32Sveegovoid
1991.102Sceggerconfig_console(void)
2001.79Saymeric{
2011.107Smatt	cfdata_t cf;
2021.84Sthorpej
2031.84Sthorpej	config_init();
2041.36Sis
2051.17Schopps	/*
2061.17Schopps	 * we need mainbus' cfdata.
2071.17Schopps	 */
2081.95Sjmc	cf = config_rootsearch(NULL, "mainbus", NULL);
2091.36Sis	if (cf == NULL) {
2101.17Schopps		panic("no mainbus");
2111.36Sis	}
2121.1Smw	/*
2131.44Sis	 * delay clock calibration.
2141.44Sis	 */
2151.95Sjmc	amiga_config_found(cf, NULL, __UNCONST("clock"), NULL);
2161.44Sis
2171.44Sis	/*
2181.17Schopps	 * internal grf.
2191.1Smw	 */
2201.36Sis#ifdef DRACO
2211.36Sis	if (!(is_draco()))
2221.36Sis#endif
2231.95Sjmc		amiga_config_found(cf, NULL, __UNCONST("grfcc"), NULL);
2241.67Saymeric
2251.1Smw	/*
2261.27Schopps	 * zbus knows when its not for real and will
2271.21Schopps	 * only configure the appropriate hardware
2281.1Smw	 */
2291.95Sjmc	amiga_config_found(cf, NULL, __UNCONST("zbus"), NULL);
2301.1Smw}
2311.1Smw
2321.79Saymeric/*
2331.79Saymeric * mainbus driver
2341.17Schopps */
2351.107SmattCFATTACH_DECL_NEW(mainbus, 0,
2361.85Sthorpej    mbmatch, mbattach, NULL, NULL);
2371.17Schopps
2381.11Schoppsint
2391.107Smattmbmatch(device_t pdp, cfdata_t cfp, void *auxp)
2401.1Smw{
2411.72Sis#if 0	/*
2421.72Sis	 * XXX is this right? but we need to be found twice
2431.72Sis	 * (early console init hack)
2441.72Sis	 */
2451.71Skleink	static int mainbus_matched = 0;
2461.30Sthorpej
2471.71Skleink	/* Allow only one instance. */
2481.71Skleink	if (mainbus_matched)
2491.71Skleink		return (0);
2501.71Skleink
2511.71Skleink	mainbus_matched = 1;
2521.72Sis#endif
2531.71Skleink	return (1);
2541.1Smw}
2551.1Smw
2561.1Smw/*
2571.17Schopps * "find" all the things that should be there.
2581.1Smw */
2591.11Schoppsvoid
2601.107Smattmbattach(device_t pdp, device_t dp, void *auxp)
2611.1Smw{
2621.43Schristos	printf("\n");
2631.95Sjmc	config_found(dp, __UNCONST("clock"), simple_devprint);
2641.52Sis	if (is_a3000() || is_a4000()) {
2651.95Sjmc		config_found(dp, __UNCONST("a34kbbc"), simple_devprint);
2661.58Sis	} else
2671.53Sis#ifdef DRACO
2681.58Sis	if (!is_draco())
2691.53Sis#endif
2701.58Sis	{
2711.95Sjmc		config_found(dp, __UNCONST("a2kbbc"), simple_devprint);
2721.52Sis	}
2731.36Sis#ifdef DRACO
2741.36Sis	if (is_draco()) {
2751.95Sjmc		config_found(dp, __UNCONST("drbbc"), simple_devprint);
2761.95Sjmc		config_found(dp, __UNCONST("kbd"), simple_devprint);
2771.95Sjmc		config_found(dp, __UNCONST("drsc"), simple_devprint);
2781.95Sjmc		config_found(dp, __UNCONST("drsupio"), simple_devprint);
2791.79Saymeric	} else
2801.36Sis#endif
2811.36Sis	{
2821.95Sjmc		config_found(dp, __UNCONST("ser"), simple_devprint);
2831.95Sjmc		config_found(dp, __UNCONST("par"), simple_devprint);
2841.95Sjmc		config_found(dp, __UNCONST("kbd"), simple_devprint);
2851.95Sjmc		config_found(dp, __UNCONST("ms"), simple_devprint);
2861.95Sjmc		config_found(dp, __UNCONST("grfcc"), simple_devprint);
2871.95Sjmc		config_found(dp, __UNCONST("amidisplaycc"), simple_devprint);
2881.95Sjmc		config_found(dp, __UNCONST("fdc"), simple_devprint);
2891.36Sis	}
2901.106Sphx	if (is_a4000() || is_a1200() || is_a600())
2911.95Sjmc		config_found(dp, __UNCONST("wdc"), simple_devprint);
2921.29Schopps	if (is_a4000())			/* Try to configure A4000T SCSI */
2931.95Sjmc		config_found(dp, __UNCONST("afsc"), simple_devprint);
2941.17Schopps	if (is_a3000())
2951.95Sjmc		config_found(dp, __UNCONST("ahsc"), simple_devprint);
2961.106Sphx	if (is_a600() || is_a1200())
2971.95Sjmc		config_found(dp, __UNCONST("pccard"), simple_devprint);
2981.54Sis#ifdef DRACO
2991.54Sis	if (!is_draco())
3001.54Sis#endif
3011.95Sjmc		config_found(dp, __UNCONST("aucc"), simple_devprint);
3021.54Sis
3031.95Sjmc	config_found(dp, __UNCONST("zbus"), simple_devprint);
3041.1Smw}
3051.1Smw
3061.11Schoppsint
3071.100Sdslmbprint(void *auxp, const char *pnp)
3081.1Smw{
3091.17Schopps	if (pnp)
3101.87Sthorpej		aprint_normal("%s at %s", (char *)auxp, pnp);
3111.17Schopps	return(UNCONF);
3121.1Smw}
3131.1Smw
3141.46Sthorpej/*
3151.46Sthorpej * The system will assign the "booted device" indicator (and thus
3161.46Sthorpej * rootdev if rootspec is wildcarded) to the first partition 'a'
3171.46Sthorpej * in preference of boot.  However, it does walk unit backwards
3181.46Sthorpej * to remain compatible with the old Amiga method of picking the
3191.46Sthorpej * last root found.
3201.46Sthorpej */
3211.46Sthorpej#include <sys/fcntl.h>		/* XXXX and all that uses it */
3221.46Sthorpej#include <sys/proc.h>		/* XXXX and all that uses it */
3231.17Schopps
3241.46Sthorpej#include "fd.h"
3251.46Sthorpej#include "sd.h"
3261.46Sthorpej#include "cd.h"
3271.67Saymeric#include "wd.h"
3281.1Smw
3291.46Sthorpej#if NFD > 0
3301.46Sthorpejextern  struct cfdriver fd_cd;
3311.82Sgehennaextern	const struct bdevsw fd_bdevsw;
3321.46Sthorpej#endif
3331.46Sthorpej#if NSD > 0
3341.69Smhitchextern  struct cfdriver sd_cd;
3351.82Sgehennaextern	const struct bdevsw sd_bdevsw;
3361.46Sthorpej#endif
3371.46Sthorpej#if NCD > 0
3381.46Sthorpejextern  struct cfdriver cd_cd;
3391.82Sgehennaextern	const struct bdevsw cd_bdevsw;
3401.46Sthorpej#endif
3411.67Saymeric#if NWD > 0
3421.69Smhitchextern  struct cfdriver wd_cd;
3431.82Sgehennaextern	const struct bdevsw wd_bdevsw;
3441.67Saymeric#endif
3451.1Smw
3461.46Sthorpejstruct cfdriver *genericconf[] = {
3471.46Sthorpej#if NFD > 0
3481.46Sthorpej	&fd_cd,
3491.46Sthorpej#endif
3501.46Sthorpej#if NSD > 0
3511.46Sthorpej	&sd_cd,
3521.46Sthorpej#endif
3531.69Smhitch#if NWD > 0
3541.69Smhitch	&wd_cd,
3551.69Smhitch#endif
3561.46Sthorpej#if NCD > 0
3571.46Sthorpej	&cd_cd,
3581.46Sthorpej#endif
3591.46Sthorpej	NULL,
3601.1Smw};
3611.1Smw
3621.11Schoppsvoid
3631.76Smattfindroot(void)
3641.1Smw{
3651.46Sthorpej	struct disk *dkp;
3661.46Sthorpej	struct partition *pp;
3671.99Scegger	device_t *devs;
3681.46Sthorpej	int i, maj, unit;
3691.82Sgehenna	const struct bdevsw *bdp;
3701.47Smhitch
3711.47Smhitch#if NSD > 0
3721.47Smhitch	/*
3731.47Smhitch	 * If we have the boot partition offset (boot_partition), try
3741.47Smhitch	 * to locate the device corresponding to that partition.
3751.47Smhitch	 */
3761.56Sis#ifdef DEBUG_KERNEL_START
3771.56Sis	printf("Boot partition offset is %ld\n", boot_partition);
3781.56Sis#endif
3791.47Smhitch	if (boot_partition != 0) {
3801.47Smhitch
3811.47Smhitch		for (unit = 0; unit < sd_cd.cd_ndevs; ++unit) {
3821.56Sis#ifdef DEBUG_KERNEL_START
3831.56Sis			printf("probing for sd%d\n", unit);
3841.56Sis#endif
3851.99Scegger			if (device_lookup(&sd_cd,unit) == NULL)
3861.47Smhitch				continue;
3871.47Smhitch
3881.47Smhitch			/*
3891.47Smhitch			 * Find the disk corresponding to the current
3901.47Smhitch			 * device.
3911.47Smhitch			 */
3921.99Scegger			devs = (device_t *)sd_cd.cd_devs;
3931.99Scegger			if ((dkp = disk_find(device_xname(device_lookup(&sd_cd, unit)))) == NULL)
3941.47Smhitch				continue;
3951.47Smhitch
3961.47Smhitch			if (dkp->dk_driver == NULL ||
3971.47Smhitch			    dkp->dk_driver->d_strategy == NULL)
3981.47Smhitch				continue;
3991.82Sgehenna			bdp = &sd_bdevsw;
4001.82Sgehenna			maj = bdevsw_lookup_major(bdp);
4011.82Sgehenna			if ((*bdp->d_open)(MAKEDISKDEV(maj, unit, RAW_PART),
4021.98Schristos			    FREAD | FNONBLOCK, 0, curlwp))
4031.47Smhitch				continue;
4041.82Sgehenna			(*bdp->d_close)(MAKEDISKDEV(maj, unit, RAW_PART),
4051.98Schristos			    FREAD | FNONBLOCK, 0, curlwp);
4061.47Smhitch			pp = &dkp->dk_label->d_partitions[0];
4071.54Sis			for (i = 0; i < dkp->dk_label->d_npartitions;
4081.54Sis			    i++, pp++) {
4091.56Sis#ifdef DEBUG_KERNEL_START
4101.56Sis				printf("sd%d%c type %d offset %d size %d\n",
4111.56Sis					unit, i+'a', pp->p_fstype,
4121.56Sis					pp->p_offset, pp->p_size);
4131.56Sis#endif
4141.54Sis				if (pp->p_size == 0 ||
4151.54Sis				    (pp->p_fstype != FS_BSDFFS &&
4161.54Sis				    pp->p_fstype != FS_SWAP))
4171.54Sis					continue;
4181.54Sis				if (pp->p_offset == boot_partition) {
4191.76Smatt					if (booted_device == NULL) {
4201.76Smatt						booted_device = devs[unit];
4211.76Smatt						booted_partition = i;
4221.54Sis					} else
4231.54Sis						printf("Ambiguous boot device\n");
4241.54Sis				}
4251.47Smhitch			}
4261.47Smhitch		}
4271.47Smhitch	}
4281.76Smatt	if (booted_device != NULL)
4291.47Smhitch		return;		/* we found the boot device */
4301.47Smhitch#endif
4311.46Sthorpej
4321.46Sthorpej	for (i = 0; genericconf[i] != NULL; i++) {
4331.46Sthorpej		for (unit = genericconf[i]->cd_ndevs - 1; unit >= 0; unit--) {
4341.46Sthorpej			if (genericconf[i]->cd_devs[unit] == NULL)
4351.46Sthorpej				continue;
4361.46Sthorpej
4371.46Sthorpej			/*
4381.46Sthorpej			 * Find the disk structure corresponding to the
4391.46Sthorpej			 * current device.
4401.46Sthorpej			 */
4411.99Scegger			devs = (device_t *)genericconf[i]->cd_devs;
4421.99Scegger			if ((dkp = disk_find(device_xname(devs[unit]))) == NULL)
4431.46Sthorpej				continue;
4441.46Sthorpej
4451.46Sthorpej			if (dkp->dk_driver == NULL ||
4461.46Sthorpej			    dkp->dk_driver->d_strategy == NULL)
4471.46Sthorpej				continue;
4481.46Sthorpej
4491.92Smhitch			bdp = NULL;
4501.82Sgehenna#if NFD > 0
4511.82Sgehenna			if (fd_bdevsw.d_strategy == dkp->dk_driver->d_strategy)
4521.82Sgehenna				bdp = &fd_bdevsw;
4531.82Sgehenna#endif
4541.82Sgehenna#if NSD > 0
4551.82Sgehenna			if (sd_bdevsw.d_strategy == dkp->dk_driver->d_strategy)
4561.82Sgehenna				bdp = &sd_bdevsw;
4571.82Sgehenna#endif
4581.82Sgehenna#if NWD > 0
4591.82Sgehenna			if (wd_bdevsw.d_strategy == dkp->dk_driver->d_strategy)
4601.82Sgehenna				bdp = &wd_bdevsw;
4611.82Sgehenna#endif
4621.82Sgehenna#if NCD > 0
4631.82Sgehenna			if (cd_bdevsw.d_strategy == dkp->dk_driver->d_strategy)
4641.82Sgehenna				bdp = &cd_bdevsw;
4651.82Sgehenna#endif
4661.46Sthorpej#ifdef DIAGNOSTIC
4671.82Sgehenna			if (bdp == NULL)
4681.46Sthorpej				panic("findroot: impossible");
4691.46Sthorpej#endif
4701.82Sgehenna			maj = bdevsw_lookup_major(bdp);
4711.46Sthorpej
4721.46Sthorpej			/* Open disk; forces read of disklabel. */
4731.82Sgehenna			if ((*bdp->d_open)(MAKEDISKDEV(maj,
4741.98Schristos			    unit, 0), FREAD|FNONBLOCK, 0, &lwp0))
4751.46Sthorpej				continue;
4761.82Sgehenna			(void)(*bdp->d_close)(MAKEDISKDEV(maj,
4771.98Schristos			    unit, 0), FREAD|FNONBLOCK, 0, &lwp0);
4781.46Sthorpej
4791.46Sthorpej			pp = &dkp->dk_label->d_partitions[0];
4801.46Sthorpej			if (pp->p_size != 0 && pp->p_fstype == FS_BSDFFS) {
4811.76Smatt				booted_device = devs[unit];
4821.76Smatt				booted_partition = 0;
4831.46Sthorpej				return;
4841.46Sthorpej			}
4851.1Smw		}
4861.1Smw	}
4871.3Smw}
4881.17Schopps
4891.11Schopps/*
4901.11Schopps * Try to determine, of this machine is an A3000, which has a builtin
4911.11Schopps * realtime clock and scsi controller, so that this hardware is only
4921.11Schopps * included as "configured" if this IS an A3000
4931.11Schopps */
4941.5Smw
4951.5Smwint a3000_flag = 1;		/* patchable */
4961.5Smw#ifdef A4000
4971.5Smwint a4000_flag = 1;		/* patchable - default to A4000 */
4981.5Smw#else
4991.5Smwint a4000_flag = 0;		/* patchable */
5001.5Smw#endif
5011.5Smw
5021.3Smwint
5031.11Schoppsis_a3000()
5041.3Smw{
5051.11Schopps	/* this is a dirty kludge.. but how do you do this RIGHT ? :-) */
5061.22Schopps	extern long boot_fphystart;
5071.11Schopps	short sc;
5081.11Schopps
5091.19Schopps	if ((machineid >> 16) == 3000)
5101.19Schopps		return (1);			/* It's an A3000 */
5111.19Schopps	if (machineid >> 16)
5121.19Schopps		return (0);			/* It's not an A3000 */
5131.19Schopps	/* Machine type is unknown, so try to guess it */
5141.11Schopps	/* where is fastram on the A4000 ?? */
5151.11Schopps	/* if fastram is below 0x07000000, assume it's not an A3000 */
5161.22Schopps	if (boot_fphystart < 0x07000000)
5171.17Schopps		return(0);
5181.11Schopps	/*
5191.11Schopps	 * OK, fastram starts at or above 0x07000000, check specific
5201.11Schopps	 * machines
5211.11Schopps	 */
5221.17Schopps	for (sc = 0; sc < ncfdev; sc++) {
5231.17Schopps		switch (cfdev[sc].rom.manid) {
5241.17Schopps		case 2026:		/* Progressive Peripherals, Inc */
5251.17Schopps			switch (cfdev[sc].rom.prodid) {
5261.17Schopps			case 0:		/* PPI Mercury - A3000 */
5271.17Schopps			case 1:		/* PP&S A3000 '040 */
5281.17Schopps				return(1);
5291.17Schopps			case 150:	/* PPI Zeus - it's an A2000 */
5301.17Schopps			case 105:	/* PP&S A2000 '040 */
5311.17Schopps			case 187:	/* PP&S A500 '040 */
5321.17Schopps				return(0);
5331.11Schopps			}
5341.11Schopps			break;
5351.3Smw
5361.17Schopps		case 2112:			/* IVS */
5371.17Schopps			switch (cfdev[sc].rom.prodid) {
5381.17Schopps			case 242:
5391.17Schopps				return(0);	/* A2000 accelerator? */
5401.11Schopps			}
5411.11Schopps			break;
5421.11Schopps		}
5431.11Schopps	}
5441.17Schopps	return (a3000_flag);		/* XXX let flag tell now */
5451.5Smw}
5461.5Smw
5471.5Smwint
5481.11Schoppsis_a4000()
5491.5Smw{
5501.19Schopps	if ((machineid >> 16) == 4000)
5511.19Schopps		return (1);		/* It's an A4000 */
5521.24Schopps	if ((machineid >> 16) == 1200)
5531.24Schopps		return (0);		/* It's an A1200, so not A4000 */
5541.36Sis#ifdef DRACO
5551.36Sis	if (is_draco())
5561.36Sis		return (0);
5571.36Sis#endif
5581.24Schopps	/* Do I need this any more? */
5591.19Schopps	if ((custom.deniseid & 0xff) == 0xf8)
5601.19Schopps		return (1);
5611.19Schopps#ifdef DEBUG
5621.19Schopps	if (a4000_flag)
5631.43Schristos		printf("Denise ID = %04x\n", (unsigned short)custom.deniseid);
5641.19Schopps#endif
5651.19Schopps	if (machineid >> 16)
5661.19Schopps		return (0);		/* It's not an A4000 */
5671.19Schopps	return (a4000_flag);		/* Machine type not set */
5681.24Schopps}
5691.24Schopps
5701.24Schoppsint
5711.24Schoppsis_a1200()
5721.24Schopps{
5731.24Schopps	if ((machineid >> 16) == 1200)
5741.24Schopps		return (1);		/* It's an A1200 */
5751.24Schopps	return (0);			/* Machine type not set */
5761.1Smw}
5771.106Sphx
5781.106Sphxint
5791.106Sphxis_a600()
5801.106Sphx{
5811.106Sphx	if ((machineid >> 16) == 600)
5821.106Sphx		return (1);		/* It's an A600 */
5831.106Sphx	return (0);			/* Machine type not set */
5841.106Sphx}
5851.108Srkujawa
5861.108Srkujawa
5871.108Srkujawavoid
5881.108Srkujawadevice_register(device_t dev, void *aux)
5891.108Srkujawa{
5901.108Srkujawa	prop_dictionary_t dict, parent_dict;
5911.108Srkujawa	struct pci_attach_args *pa = aux;
5921.108Srkujawa
5931.108Srkujawa	if (device_parent(dev) && device_is_a(device_parent(dev), "pci")) {
5941.108Srkujawa
5951.108Srkujawa		dict = device_properties(dev);
5961.108Srkujawa
5971.108Srkujawa		if (PCI_CLASS(pa->pa_class) == PCI_CLASS_DISPLAY) {
5981.108Srkujawa
5991.108Srkujawa			/* Handle CVPPC/BVPPC card. */
6001.108Srkujawa			if ((PCI_VENDOR(pa->pa_id) == PCI_VENDOR_TI)
6011.108Srkujawa			    && (PCI_PRODUCT(pa->pa_id) ==
6021.108Srkujawa			    PCI_PRODUCT_TI_TVP4020) ) {
6031.108Srkujawa
6041.108Srkujawa				/*
6051.108Srkujawa				 * PCI bridge knows the properties,
6061.108Srkujawa				 * PCI device doesn't - let's copy
6071.108Srkujawa				 * them.
6081.108Srkujawa				 */
6091.108Srkujawa				parent_dict = device_properties(
6101.108Srkujawa				    device_parent(device_parent(dev)));
6111.108Srkujawa
6121.108Srkujawa				prop_dictionary_set(dict, "width",
6131.108Srkujawa				    prop_dictionary_get(parent_dict, "width"));
6141.108Srkujawa
6151.108Srkujawa				prop_dictionary_set(dict, "height",
6161.108Srkujawa				    prop_dictionary_get(parent_dict, "height"));
6171.108Srkujawa
6181.108Srkujawa				prop_dictionary_set(dict, "depth",
6191.108Srkujawa				    prop_dictionary_get(parent_dict, "depth"));
6201.108Srkujawa
6211.108Srkujawa				prop_dictionary_set(dict, "linebytes",
6221.108Srkujawa				    prop_dictionary_get(parent_dict,
6231.108Srkujawa				    "linebytes"));
6241.108Srkujawa
6251.108Srkujawa				prop_dictionary_set(dict, "address",
6261.108Srkujawa				    prop_dictionary_get(parent_dict,
6271.108Srkujawa				    "address"));
6281.108Srkujawa#if (NGENFB > 0)
6291.108Srkujawa				prop_dictionary_set(dict, "virtual_address",
6301.108Srkujawa				    prop_dictionary_get(parent_dict,
6311.108Srkujawa				    "virtual_address"));
6321.108Srkujawa#endif
6331.108Srkujawa			}
6341.108Srkujawa		}
6351.108Srkujawa	}
6361.108Srkujawa}
6371.108Srkujawa
638