autoconf.c revision 1.45
11.45Sveego/*	$NetBSD: autoconf.c,v 1.45 1996/12/23 09:15:39 veego 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.9Schopps#include <sys/param.h>
331.9Schopps#include <sys/systm.h>
341.17Schopps#include <sys/reboot.h>
351.9Schopps#include <sys/conf.h>
361.17Schopps#include <sys/device.h>
371.17Schopps#include <sys/disklabel.h>
381.19Schopps#include <machine/cpu.h>
391.17Schopps#include <amiga/amiga/cfdev.h>
401.17Schopps#include <amiga/amiga/device.h>
411.9Schopps#include <amiga/amiga/custom.h>
421.1Smw
431.11Schoppsvoid setroot __P((void));
441.11Schoppsvoid swapconf __P((void));
451.17Schoppsvoid mbattach __P((struct device *, struct device *, void *));
461.40Scgdint mbprint __P((void *, const char *));
471.45Sveegoint mbmatch __P((struct device *, struct cfdata *, void *));
481.11Schopps
491.17Schoppsint cold;	/* 1 if still booting */
501.17Schopps#include <sys/kernel.h>
511.1Smw/*
521.17Schopps * called at boot time, configure all devices on system
531.1Smw */
541.11Schoppsvoid
551.1Smwconfigure()
561.1Smw{
571.44Sis	int s;
581.17Schopps	/*
591.17Schopps	 * this is the real thing baby (i.e. not console init)
601.17Schopps	 */
611.17Schopps	amiga_realconfig = 1;
621.36Sis#ifdef DRACO
631.36Sis	if (is_draco()) {
641.36Sis		*draco_intena &= ~DRIRQ_GLOBAL;
651.36Sis	} else
661.36Sis#endif
671.3Smw	custom.intena = INTF_INTEN;
681.44Sis	s = splhigh();
691.1Smw
701.31Scgd	if (config_rootfound("mainbus", "mainbus") == NULL)
711.17Schopps		panic("no mainbus found");
721.36Sis
731.39Sis#ifdef DEBUG_KERNEL_START
741.43Schristos	printf("survived autoconf, going to enable interrupts\n");
751.39Sis#endif
761.11Schopps
771.36Sis#ifdef DRACO
781.36Sis	if (is_draco()) {
791.36Sis		*draco_intena |= DRIRQ_GLOBAL;
801.36Sis		/* softints always enabled */
811.36Sis	} else
821.36Sis#endif
831.36Sis	{
841.36Sis		custom.intena = INTF_SETCLR | INTF_INTEN;
851.28Schopps
861.36Sis		/* also enable hardware aided software interrupts */
871.36Sis		custom.intena = INTF_SETCLR | INTF_SOFTINT;
881.36Sis	}
891.44Sis	splx(s);
901.39Sis#ifdef DEBUG_KERNEL_START
911.43Schristos	printf("survived interrupt enable\n");
921.39Sis#endif
931.28Schopps
941.17Schopps#ifdef GENERIC
951.36Sis	if ((boothowto & RB_ASKNAME) == 0) {
961.1Smw		setroot();
971.39Sis#ifdef DEBUG_KERNEL_START
981.43Schristos		printf("survived setroot()\n");
991.39Sis#endif
1001.36Sis	}
1011.1Smw	setconf();
1021.39Sis#ifdef DEBUG_KERNEL_START
1031.43Schristos	printf("survived setconf()\n");
1041.39Sis#endif
1051.1Smw#else
1061.1Smw	setroot();
1071.39Sis#ifdef DEBUG_KERNEL_START
1081.43Schristos	printf("survived setroot()\n");
1091.1Smw#endif
1101.39Sis#endif
1111.39Sis#ifdef DEBUG_KERNEL_START
1121.43Schristos	printf("survived root device search\n");
1131.39Sis#endif
1141.1Smw	swapconf();
1151.39Sis#ifdef DEBUG_KERNEL_START
1161.43Schristos	printf("survived swap device search\n");
1171.39Sis#endif
1181.1Smw	cold = 0;
1191.17Schopps}
1201.3Smw
1211.17Schopps/*ARGSUSED*/
1221.17Schoppsint
1231.17Schoppssimple_devprint(auxp, pnp)
1241.17Schopps	void *auxp;
1251.42Smhitch	const char *pnp;
1261.17Schopps{
1271.17Schopps	return(QUIET);
1281.1Smw}
1291.1Smw
1301.17Schoppsint
1311.17Schoppsmatchname(fp, sp)
1321.17Schopps	char *fp, *sp;
1331.17Schopps{
1341.17Schopps	int len;
1351.1Smw
1361.17Schopps	len = strlen(fp);
1371.17Schopps	if (strlen(sp) != len)
1381.17Schopps		return(0);
1391.17Schopps	if (bcmp(fp, sp, len) == 0)
1401.17Schopps		return(1);
1411.17Schopps	return(0);
1421.17Schopps}
1431.1Smw
1441.17Schopps/*
1451.17Schopps * use config_search to find appropriate device, then call that device
1461.17Schopps * directly with NULL device variable storage.  A device can then
1471.17Schopps * always tell the difference betwean the real and console init
1481.17Schopps * by checking for NULL.
1491.17Schopps */
1501.11Schoppsint
1511.17Schoppsamiga_config_found(pcfp, pdp, auxp, pfn)
1521.17Schopps	struct cfdata *pcfp;
1531.17Schopps	struct device *pdp;
1541.17Schopps	void *auxp;
1551.17Schopps	cfprint_t pfn;
1561.1Smw{
1571.17Schopps	struct device temp;
1581.17Schopps	struct cfdata *cf;
1591.17Schopps
1601.17Schopps	if (amiga_realconfig)
1611.31Scgd		return(config_found(pdp, auxp, pfn) != NULL);
1621.17Schopps
1631.17Schopps	if (pdp == NULL)
1641.17Schopps		pdp = &temp;
1651.17Schopps
1661.17Schopps	pdp->dv_cfdata = pcfp;
1671.17Schopps	if ((cf = config_search((cfmatch_t)NULL, pdp, auxp)) != NULL) {
1681.30Sthorpej		cf->cf_attach->ca_attach(pdp, NULL, auxp);
1691.17Schopps		pdp->dv_cfdata = NULL;
1701.17Schopps		return(1);
1711.1Smw	}
1721.17Schopps	pdp->dv_cfdata = NULL;
1731.17Schopps	return(0);
1741.17Schopps}
1751.17Schopps
1761.17Schopps/*
1771.17Schopps * this function needs to get enough configured to do a console
1781.17Schopps * basically this means start attaching the grfxx's that support
1791.17Schopps * the console. Kinda hacky but it works.
1801.17Schopps */
1811.32Sveegovoid
1821.17Schoppsconfig_console()
1831.17Schopps{
1841.17Schopps	struct cfdata *cf;
1851.36Sis
1861.17Schopps	/*
1871.17Schopps	 * we need mainbus' cfdata.
1881.17Schopps	 */
1891.17Schopps	cf = config_rootsearch(NULL, "mainbus", "mainbus");
1901.36Sis	if (cf == NULL) {
1911.17Schopps		panic("no mainbus");
1921.36Sis	}
1931.1Smw	/*
1941.44Sis	 * delay clock calibration.
1951.44Sis	 */
1961.44Sis	amiga_config_found(cf, NULL, "clock", NULL);
1971.44Sis
1981.44Sis	/*
1991.17Schopps	 * internal grf.
2001.1Smw	 */
2011.36Sis#ifdef DRACO
2021.36Sis	if (!(is_draco()))
2031.36Sis#endif
2041.36Sis		amiga_config_found(cf, NULL, "grfcc", NULL);
2051.1Smw	/*
2061.27Schopps	 * zbus knows when its not for real and will
2071.21Schopps	 * only configure the appropriate hardware
2081.1Smw	 */
2091.27Schopps	amiga_config_found(cf, NULL, "zbus", NULL);
2101.1Smw}
2111.1Smw
2121.17Schopps/*
2131.17Schopps * mainbus driver
2141.17Schopps */
2151.30Sthorpejstruct cfattach mainbus_ca = {
2161.30Sthorpej	sizeof(struct device), mbmatch, mbattach
2171.30Sthorpej};
2181.30Sthorpej
2191.30Sthorpejstruct cfdriver mainbus_cd = {
2201.30Sthorpej	NULL, "mainbus", DV_DULL, NULL, 0
2211.17Schopps};
2221.17Schopps
2231.11Schoppsint
2241.45Sveegombmatch(pdp, cfp, auxp)
2251.45Sveego	struct device	*pdp;
2261.45Sveego	struct cfdata	*cfp;
2271.45Sveego	void		*auxp;
2281.1Smw{
2291.30Sthorpej
2301.17Schopps	if (cfp->cf_unit > 0)
2311.1Smw		return(0);
2321.1Smw	/*
2331.17Schopps	 * We are always here
2341.1Smw	 */
2351.1Smw	return(1);
2361.1Smw}
2371.1Smw
2381.1Smw/*
2391.17Schopps * "find" all the things that should be there.
2401.1Smw */
2411.11Schoppsvoid
2421.17Schoppsmbattach(pdp, dp, auxp)
2431.17Schopps	struct device *pdp, *dp;
2441.17Schopps	void *auxp;
2451.1Smw{
2461.43Schristos	printf("\n");
2471.17Schopps	config_found(dp, "clock", simple_devprint);
2481.36Sis#ifdef DRACO
2491.36Sis	if (is_draco()) {
2501.36Sis		config_found(dp, "kbd", simple_devprint);
2511.36Sis		config_found(dp, "drsc", simple_devprint);
2521.44Sis		config_found(dp, "drcom", simple_devprint);
2531.44Sis		config_found(dp, "drcom", simple_devprint);
2541.36Sis		/*
2551.36Sis		 * XXX -- missing here:
2561.36Sis		 * SuperIO chip serial, parallel, floppy
2571.36Sis		 * or maybe just make that into a pseudo
2581.36Sis		 * ISA bus.
2591.36Sis		 */
2601.36Sis	} else
2611.36Sis#endif
2621.36Sis	{
2631.36Sis		config_found(dp, "ser", simple_devprint);
2641.36Sis		config_found(dp, "par", simple_devprint);
2651.36Sis		config_found(dp, "kbd", simple_devprint);
2661.36Sis		config_found(dp, "ms", simple_devprint);
2671.36Sis		config_found(dp, "ms", simple_devprint);
2681.36Sis		config_found(dp, "grfcc", simple_devprint);
2691.36Sis		config_found(dp, "fdc", simple_devprint);
2701.36Sis	}
2711.24Schopps	if (is_a4000() || is_a1200())
2721.23Schopps		config_found(dp, "idesc", simple_devprint);
2731.29Schopps	if (is_a4000())			/* Try to configure A4000T SCSI */
2741.29Schopps		config_found(dp, "afsc", simple_devprint);
2751.27Schopps	config_found(dp, "zbus", simple_devprint);
2761.17Schopps	if (is_a3000())
2771.17Schopps		config_found(dp, "ahsc", simple_devprint);
2781.1Smw}
2791.1Smw
2801.11Schoppsint
2811.17Schoppsmbprint(auxp, pnp)
2821.17Schopps	void *auxp;
2831.40Scgd	const char *pnp;
2841.1Smw{
2851.17Schopps	if (pnp)
2861.43Schristos		printf("%s at %s", (char *)auxp, pnp);
2871.17Schopps	return(UNCONF);
2881.1Smw}
2891.1Smw
2901.11Schoppsvoid
2911.17Schoppsswapconf()
2921.1Smw{
2931.17Schopps	struct swdevt *swp;
2941.17Schopps	u_int maj;
2951.17Schopps	int nb;
2961.3Smw
2971.17Schopps	for (swp = swdevt; swp->sw_dev > 0; swp++) {
2981.17Schopps		maj = major(swp->sw_dev);
2991.5Smw
3001.17Schopps		if (maj > nblkdev)
3011.17Schopps			break;
3021.1Smw
3031.17Schopps		if (bdevsw[maj].d_psize) {
3041.17Schopps			nb = bdevsw[maj].d_psize(swp->sw_dev);
3051.17Schopps			if (nb > 0 &&
3061.17Schopps			    (swp->sw_nblks == 0 || swp->sw_nblks > nb))
3071.17Schopps				swp->sw_nblks = nb;
3081.17Schopps			else
3091.17Schopps				swp->sw_nblks = 0;
3101.1Smw		}
3111.17Schopps		swp->sw_nblks = ctod(dtoc(swp->sw_nblks));
3121.11Schopps	}
3131.38Smhitch	dumpconf();
3141.17Schopps	if (dumplo < 0)
3151.17Schopps		dumplo = 0;
3161.17Schopps
3171.1Smw}
3181.1Smw
3191.17Schopps#define	DOSWAP			/* change swdevt and dumpdev */
3201.17Schoppsu_long	bootdev = 0;		/* should be dev_t, but not until 32 bits */
3211.1Smw
3221.1Smwstatic	char devname[][2] = {
3231.32Sveego	{ 0	,0	},
3241.32Sveego	{ 0	,0	},
3251.32Sveego	{ 'f'	,'d'	},	/* 2 = fd */
3261.32Sveego	{ 0	,0	},
3271.32Sveego	{ 's'	,'d'	}	/* 4 = sd -- new SCSI system */
3281.1Smw};
3291.1Smw
3301.11Schoppsvoid
3311.1Smwsetroot()
3321.1Smw{
3331.17Schopps	int majdev, mindev, unit, part, adaptor;
3341.32Sveego	dev_t temp = 0;
3351.32Sveego	dev_t orootdev;
3361.1Smw	struct swdevt *swp;
3371.1Smw
3381.1Smw	if (boothowto & RB_DFLTROOT ||
3391.17Schopps	    (bootdev & B_MAGICMASK) != (u_long)B_DEVMAGIC)
3401.11Schopps		return;
3411.1Smw	majdev = (bootdev >> B_TYPESHIFT) & B_TYPEMASK;
3421.17Schopps	if (majdev > sizeof(devname) / sizeof(devname[0]))
3431.11Schopps		return;
3441.1Smw	adaptor = (bootdev >> B_ADAPTORSHIFT) & B_ADAPTORMASK;
3451.1Smw	part = (bootdev >> B_PARTITIONSHIFT) & B_PARTITIONMASK;
3461.1Smw	unit = (bootdev >> B_UNITSHIFT) & B_UNITMASK;
3471.1Smw	orootdev = rootdev;
3481.17Schopps	rootdev = MAKEDISKDEV(majdev, unit, part);
3491.1Smw	/*
3501.1Smw	 * If the original rootdev is the same as the one
3511.1Smw	 * just calculated, don't need to adjust the swap configuration.
3521.1Smw	 */
3531.17Schopps	if (rootdev == orootdev)
3541.11Schopps		return;
3551.43Schristos	printf("changing root device to %c%c%d%c\n",
3561.41Schristos	    devname[majdev][0], devname[majdev][1],
3571.41Schristos	    unit, part + 'a');
3581.1Smw#ifdef DOSWAP
3591.17Schopps	mindev = DISKUNIT(rootdev);
3601.1Smw	for (swp = swdevt; swp->sw_dev; swp++) {
3611.1Smw		if (majdev == major(swp->sw_dev) &&
3621.17Schopps		    mindev == DISKUNIT(swp->sw_dev)) {
3631.1Smw			temp = swdevt[0].sw_dev;
3641.1Smw			swdevt[0].sw_dev = swp->sw_dev;
3651.1Smw			swp->sw_dev = temp;
3661.1Smw			break;
3671.1Smw		}
3681.1Smw	}
3691.1Smw	if (swp->sw_dev == 0)
3701.1Smw		return;
3711.1Smw	/*
3721.1Smw	 * If dumpdev was the same as the old primary swap
3731.1Smw	 * device, move it to the new primary swap device.
3741.1Smw	 */
3751.1Smw	if (temp == dumpdev)
3761.1Smw		dumpdev = swdevt[0].sw_dev;
3771.1Smw#endif
3781.3Smw}
3791.3Smw
3801.17Schopps
3811.11Schopps/*
3821.11Schopps * Try to determine, of this machine is an A3000, which has a builtin
3831.11Schopps * realtime clock and scsi controller, so that this hardware is only
3841.11Schopps * included as "configured" if this IS an A3000
3851.11Schopps */
3861.5Smw
3871.5Smwint a3000_flag = 1;		/* patchable */
3881.5Smw#ifdef A4000
3891.5Smwint a4000_flag = 1;		/* patchable - default to A4000 */
3901.5Smw#else
3911.5Smwint a4000_flag = 0;		/* patchable */
3921.5Smw#endif
3931.5Smw
3941.3Smwint
3951.11Schoppsis_a3000()
3961.3Smw{
3971.11Schopps	/* this is a dirty kludge.. but how do you do this RIGHT ? :-) */
3981.22Schopps	extern long boot_fphystart;
3991.11Schopps	short sc;
4001.11Schopps
4011.19Schopps	if ((machineid >> 16) == 3000)
4021.19Schopps		return (1);			/* It's an A3000 */
4031.19Schopps	if (machineid >> 16)
4041.19Schopps		return (0);			/* It's not an A3000 */
4051.19Schopps	/* Machine type is unknown, so try to guess it */
4061.11Schopps	/* where is fastram on the A4000 ?? */
4071.11Schopps	/* if fastram is below 0x07000000, assume it's not an A3000 */
4081.22Schopps	if (boot_fphystart < 0x07000000)
4091.17Schopps		return(0);
4101.11Schopps	/*
4111.11Schopps	 * OK, fastram starts at or above 0x07000000, check specific
4121.11Schopps	 * machines
4131.11Schopps	 */
4141.17Schopps	for (sc = 0; sc < ncfdev; sc++) {
4151.17Schopps		switch (cfdev[sc].rom.manid) {
4161.17Schopps		case 2026:		/* Progressive Peripherals, Inc */
4171.17Schopps			switch (cfdev[sc].rom.prodid) {
4181.17Schopps			case 0:		/* PPI Mercury - A3000 */
4191.17Schopps			case 1:		/* PP&S A3000 '040 */
4201.17Schopps				return(1);
4211.17Schopps			case 150:	/* PPI Zeus - it's an A2000 */
4221.17Schopps			case 105:	/* PP&S A2000 '040 */
4231.17Schopps			case 187:	/* PP&S A500 '040 */
4241.17Schopps				return(0);
4251.11Schopps			}
4261.11Schopps			break;
4271.3Smw
4281.17Schopps		case 2112:			/* IVS */
4291.17Schopps			switch (cfdev[sc].rom.prodid) {
4301.17Schopps			case 242:
4311.17Schopps				return(0);	/* A2000 accelerator? */
4321.11Schopps			}
4331.11Schopps			break;
4341.11Schopps		}
4351.11Schopps	}
4361.17Schopps	return (a3000_flag);		/* XXX let flag tell now */
4371.5Smw}
4381.5Smw
4391.5Smwint
4401.11Schoppsis_a4000()
4411.5Smw{
4421.19Schopps	if ((machineid >> 16) == 4000)
4431.19Schopps		return (1);		/* It's an A4000 */
4441.24Schopps	if ((machineid >> 16) == 1200)
4451.24Schopps		return (0);		/* It's an A1200, so not A4000 */
4461.36Sis#ifdef DRACO
4471.36Sis	if (is_draco())
4481.36Sis		return (0);
4491.36Sis#endif
4501.24Schopps	/* Do I need this any more? */
4511.19Schopps	if ((custom.deniseid & 0xff) == 0xf8)
4521.19Schopps		return (1);
4531.19Schopps#ifdef DEBUG
4541.19Schopps	if (a4000_flag)
4551.43Schristos		printf("Denise ID = %04x\n", (unsigned short)custom.deniseid);
4561.19Schopps#endif
4571.19Schopps	if (machineid >> 16)
4581.19Schopps		return (0);		/* It's not an A4000 */
4591.19Schopps	return (a4000_flag);		/* Machine type not set */
4601.24Schopps}
4611.24Schopps
4621.24Schoppsint
4631.24Schoppsis_a1200()
4641.24Schopps{
4651.24Schopps	if ((machineid >> 16) == 1200)
4661.24Schopps		return (1);		/* It's an A1200 */
4671.24Schopps	return (0);			/* Machine type not set */
4681.1Smw}
4691.36Sis
4701.36Sis#ifdef DRACO
4711.36Sisint
4721.36Sisis_draco()
4731.36Sis{
4741.36Sis	if ((machineid >> 24) == 0x7D)
4751.36Sis		return ((machineid >> 16) & 0xFF);
4761.36Sis	return (0);
4771.36Sis}
4781.36Sis#endif
479