autoconf.c revision 1.43
11.43Schristos/*	$NetBSD: autoconf.c,v 1.43 1996/10/13 03:06:31 christos 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.30Sthorpejint mbmatch __P((struct device *, void *, 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.17Schopps	/*
581.17Schopps	 * this is the real thing baby (i.e. not console init)
591.17Schopps	 */
601.17Schopps	amiga_realconfig = 1;
611.36Sis#ifdef DRACO
621.36Sis	if (is_draco()) {
631.36Sis		*draco_intena &= ~DRIRQ_GLOBAL;
641.36Sis	} else
651.36Sis#endif
661.3Smw	custom.intena = INTF_INTEN;
671.1Smw
681.31Scgd	if (config_rootfound("mainbus", "mainbus") == NULL)
691.17Schopps		panic("no mainbus found");
701.36Sis
711.39Sis#ifdef DEBUG_KERNEL_START
721.43Schristos	printf("survived autoconf, going to enable interrupts\n");
731.39Sis#endif
741.11Schopps
751.36Sis#ifdef DRACO
761.36Sis	if (is_draco()) {
771.36Sis		*draco_intena |= DRIRQ_GLOBAL;
781.36Sis		/* softints always enabled */
791.36Sis	} else
801.36Sis#endif
811.36Sis	{
821.36Sis		custom.intena = INTF_SETCLR | INTF_INTEN;
831.28Schopps
841.36Sis		/* also enable hardware aided software interrupts */
851.36Sis		custom.intena = INTF_SETCLR | INTF_SOFTINT;
861.36Sis	}
871.39Sis#ifdef DEBUG_KERNEL_START
881.43Schristos	printf("survived interrupt enable\n");
891.39Sis#endif
901.28Schopps
911.17Schopps#ifdef GENERIC
921.36Sis	if ((boothowto & RB_ASKNAME) == 0) {
931.1Smw		setroot();
941.39Sis#ifdef DEBUG_KERNEL_START
951.43Schristos		printf("survived setroot()\n");
961.39Sis#endif
971.36Sis	}
981.1Smw	setconf();
991.39Sis#ifdef DEBUG_KERNEL_START
1001.43Schristos	printf("survived setconf()\n");
1011.39Sis#endif
1021.1Smw#else
1031.1Smw	setroot();
1041.39Sis#ifdef DEBUG_KERNEL_START
1051.43Schristos	printf("survived setroot()\n");
1061.1Smw#endif
1071.39Sis#endif
1081.39Sis#ifdef DEBUG_KERNEL_START
1091.43Schristos	printf("survived root device search\n");
1101.39Sis#endif
1111.1Smw	swapconf();
1121.39Sis#ifdef DEBUG_KERNEL_START
1131.43Schristos	printf("survived swap device search\n");
1141.39Sis#endif
1151.1Smw	cold = 0;
1161.17Schopps}
1171.3Smw
1181.17Schopps/*ARGSUSED*/
1191.17Schoppsint
1201.17Schoppssimple_devprint(auxp, pnp)
1211.17Schopps	void *auxp;
1221.42Smhitch	const char *pnp;
1231.17Schopps{
1241.17Schopps	return(QUIET);
1251.1Smw}
1261.1Smw
1271.17Schoppsint
1281.17Schoppsmatchname(fp, sp)
1291.17Schopps	char *fp, *sp;
1301.17Schopps{
1311.17Schopps	int len;
1321.1Smw
1331.17Schopps	len = strlen(fp);
1341.17Schopps	if (strlen(sp) != len)
1351.17Schopps		return(0);
1361.17Schopps	if (bcmp(fp, sp, len) == 0)
1371.17Schopps		return(1);
1381.17Schopps	return(0);
1391.17Schopps}
1401.1Smw
1411.17Schopps/*
1421.17Schopps * use config_search to find appropriate device, then call that device
1431.17Schopps * directly with NULL device variable storage.  A device can then
1441.17Schopps * always tell the difference betwean the real and console init
1451.17Schopps * by checking for NULL.
1461.17Schopps */
1471.11Schoppsint
1481.17Schoppsamiga_config_found(pcfp, pdp, auxp, pfn)
1491.17Schopps	struct cfdata *pcfp;
1501.17Schopps	struct device *pdp;
1511.17Schopps	void *auxp;
1521.17Schopps	cfprint_t pfn;
1531.1Smw{
1541.17Schopps	struct device temp;
1551.17Schopps	struct cfdata *cf;
1561.17Schopps
1571.17Schopps	if (amiga_realconfig)
1581.31Scgd		return(config_found(pdp, auxp, pfn) != NULL);
1591.17Schopps
1601.17Schopps	if (pdp == NULL)
1611.17Schopps		pdp = &temp;
1621.17Schopps
1631.17Schopps	pdp->dv_cfdata = pcfp;
1641.17Schopps	if ((cf = config_search((cfmatch_t)NULL, pdp, auxp)) != NULL) {
1651.30Sthorpej		cf->cf_attach->ca_attach(pdp, NULL, auxp);
1661.17Schopps		pdp->dv_cfdata = NULL;
1671.17Schopps		return(1);
1681.1Smw	}
1691.17Schopps	pdp->dv_cfdata = NULL;
1701.17Schopps	return(0);
1711.17Schopps}
1721.17Schopps
1731.17Schopps/*
1741.17Schopps * this function needs to get enough configured to do a console
1751.17Schopps * basically this means start attaching the grfxx's that support
1761.17Schopps * the console. Kinda hacky but it works.
1771.17Schopps */
1781.32Sveegovoid
1791.17Schoppsconfig_console()
1801.17Schopps{
1811.17Schopps	struct cfdata *cf;
1821.36Sis
1831.17Schopps	/*
1841.17Schopps	 * we need mainbus' cfdata.
1851.17Schopps	 */
1861.17Schopps	cf = config_rootsearch(NULL, "mainbus", "mainbus");
1871.36Sis	if (cf == NULL) {
1881.17Schopps		panic("no mainbus");
1891.36Sis	}
1901.1Smw	/*
1911.17Schopps	 * internal grf.
1921.1Smw	 */
1931.36Sis#ifdef DRACO
1941.36Sis	if (!(is_draco()))
1951.36Sis#endif
1961.36Sis		amiga_config_found(cf, NULL, "grfcc", NULL);
1971.1Smw	/*
1981.27Schopps	 * zbus knows when its not for real and will
1991.21Schopps	 * only configure the appropriate hardware
2001.1Smw	 */
2011.27Schopps	amiga_config_found(cf, NULL, "zbus", NULL);
2021.1Smw}
2031.1Smw
2041.17Schopps/*
2051.17Schopps * mainbus driver
2061.17Schopps */
2071.30Sthorpejstruct cfattach mainbus_ca = {
2081.30Sthorpej	sizeof(struct device), mbmatch, mbattach
2091.30Sthorpej};
2101.30Sthorpej
2111.30Sthorpejstruct cfdriver mainbus_cd = {
2121.30Sthorpej	NULL, "mainbus", DV_DULL, NULL, 0
2131.17Schopps};
2141.17Schopps
2151.11Schoppsint
2161.30Sthorpejmbmatch(pdp, match, auxp)
2171.17Schopps	struct device *pdp;
2181.30Sthorpej	void *match, *auxp;
2191.1Smw{
2201.30Sthorpej	struct cfdata *cfp = match;
2211.30Sthorpej
2221.17Schopps	if (cfp->cf_unit > 0)
2231.1Smw		return(0);
2241.1Smw	/*
2251.17Schopps	 * We are always here
2261.1Smw	 */
2271.1Smw	return(1);
2281.1Smw}
2291.1Smw
2301.1Smw/*
2311.17Schopps * "find" all the things that should be there.
2321.1Smw */
2331.11Schoppsvoid
2341.17Schoppsmbattach(pdp, dp, auxp)
2351.17Schopps	struct device *pdp, *dp;
2361.17Schopps	void *auxp;
2371.1Smw{
2381.43Schristos	printf("\n");
2391.17Schopps	config_found(dp, "clock", simple_devprint);
2401.36Sis#ifdef DRACO
2411.36Sis	if (is_draco()) {
2421.36Sis		config_found(dp, "kbd", simple_devprint);
2431.36Sis		config_found(dp, "drsc", simple_devprint);
2441.36Sis		/*
2451.36Sis		 * XXX -- missing here:
2461.36Sis		 * SuperIO chip serial, parallel, floppy
2471.36Sis		 * or maybe just make that into a pseudo
2481.36Sis		 * ISA bus.
2491.36Sis		 */
2501.36Sis	} else
2511.36Sis#endif
2521.36Sis	{
2531.36Sis		config_found(dp, "ser", simple_devprint);
2541.36Sis		config_found(dp, "par", simple_devprint);
2551.36Sis		config_found(dp, "kbd", simple_devprint);
2561.36Sis		config_found(dp, "ms", simple_devprint);
2571.36Sis		config_found(dp, "ms", simple_devprint);
2581.36Sis		config_found(dp, "grfcc", simple_devprint);
2591.36Sis		config_found(dp, "fdc", simple_devprint);
2601.36Sis	}
2611.24Schopps	if (is_a4000() || is_a1200())
2621.23Schopps		config_found(dp, "idesc", simple_devprint);
2631.29Schopps	if (is_a4000())			/* Try to configure A4000T SCSI */
2641.29Schopps		config_found(dp, "afsc", simple_devprint);
2651.27Schopps	config_found(dp, "zbus", simple_devprint);
2661.17Schopps	if (is_a3000())
2671.17Schopps		config_found(dp, "ahsc", simple_devprint);
2681.1Smw}
2691.1Smw
2701.11Schoppsint
2711.17Schoppsmbprint(auxp, pnp)
2721.17Schopps	void *auxp;
2731.40Scgd	const char *pnp;
2741.1Smw{
2751.17Schopps	if (pnp)
2761.43Schristos		printf("%s at %s", (char *)auxp, pnp);
2771.17Schopps	return(UNCONF);
2781.1Smw}
2791.1Smw
2801.11Schoppsvoid
2811.17Schoppsswapconf()
2821.1Smw{
2831.17Schopps	struct swdevt *swp;
2841.17Schopps	u_int maj;
2851.17Schopps	int nb;
2861.3Smw
2871.17Schopps	for (swp = swdevt; swp->sw_dev > 0; swp++) {
2881.17Schopps		maj = major(swp->sw_dev);
2891.5Smw
2901.17Schopps		if (maj > nblkdev)
2911.17Schopps			break;
2921.1Smw
2931.17Schopps		if (bdevsw[maj].d_psize) {
2941.17Schopps			nb = bdevsw[maj].d_psize(swp->sw_dev);
2951.17Schopps			if (nb > 0 &&
2961.17Schopps			    (swp->sw_nblks == 0 || swp->sw_nblks > nb))
2971.17Schopps				swp->sw_nblks = nb;
2981.17Schopps			else
2991.17Schopps				swp->sw_nblks = 0;
3001.1Smw		}
3011.17Schopps		swp->sw_nblks = ctod(dtoc(swp->sw_nblks));
3021.11Schopps	}
3031.38Smhitch	dumpconf();
3041.17Schopps	if (dumplo < 0)
3051.17Schopps		dumplo = 0;
3061.17Schopps
3071.1Smw}
3081.1Smw
3091.17Schopps#define	DOSWAP			/* change swdevt and dumpdev */
3101.17Schoppsu_long	bootdev = 0;		/* should be dev_t, but not until 32 bits */
3111.1Smw
3121.1Smwstatic	char devname[][2] = {
3131.32Sveego	{ 0	,0	},
3141.32Sveego	{ 0	,0	},
3151.32Sveego	{ 'f'	,'d'	},	/* 2 = fd */
3161.32Sveego	{ 0	,0	},
3171.32Sveego	{ 's'	,'d'	}	/* 4 = sd -- new SCSI system */
3181.1Smw};
3191.1Smw
3201.11Schoppsvoid
3211.1Smwsetroot()
3221.1Smw{
3231.17Schopps	int majdev, mindev, unit, part, adaptor;
3241.32Sveego	dev_t temp = 0;
3251.32Sveego	dev_t orootdev;
3261.1Smw	struct swdevt *swp;
3271.1Smw
3281.1Smw	if (boothowto & RB_DFLTROOT ||
3291.17Schopps	    (bootdev & B_MAGICMASK) != (u_long)B_DEVMAGIC)
3301.11Schopps		return;
3311.1Smw	majdev = (bootdev >> B_TYPESHIFT) & B_TYPEMASK;
3321.17Schopps	if (majdev > sizeof(devname) / sizeof(devname[0]))
3331.11Schopps		return;
3341.1Smw	adaptor = (bootdev >> B_ADAPTORSHIFT) & B_ADAPTORMASK;
3351.1Smw	part = (bootdev >> B_PARTITIONSHIFT) & B_PARTITIONMASK;
3361.1Smw	unit = (bootdev >> B_UNITSHIFT) & B_UNITMASK;
3371.1Smw	orootdev = rootdev;
3381.17Schopps	rootdev = MAKEDISKDEV(majdev, unit, part);
3391.1Smw	/*
3401.1Smw	 * If the original rootdev is the same as the one
3411.1Smw	 * just calculated, don't need to adjust the swap configuration.
3421.1Smw	 */
3431.17Schopps	if (rootdev == orootdev)
3441.11Schopps		return;
3451.43Schristos	printf("changing root device to %c%c%d%c\n",
3461.41Schristos	    devname[majdev][0], devname[majdev][1],
3471.41Schristos	    unit, part + 'a');
3481.1Smw#ifdef DOSWAP
3491.17Schopps	mindev = DISKUNIT(rootdev);
3501.1Smw	for (swp = swdevt; swp->sw_dev; swp++) {
3511.1Smw		if (majdev == major(swp->sw_dev) &&
3521.17Schopps		    mindev == DISKUNIT(swp->sw_dev)) {
3531.1Smw			temp = swdevt[0].sw_dev;
3541.1Smw			swdevt[0].sw_dev = swp->sw_dev;
3551.1Smw			swp->sw_dev = temp;
3561.1Smw			break;
3571.1Smw		}
3581.1Smw	}
3591.1Smw	if (swp->sw_dev == 0)
3601.1Smw		return;
3611.1Smw	/*
3621.1Smw	 * If dumpdev was the same as the old primary swap
3631.1Smw	 * device, move it to the new primary swap device.
3641.1Smw	 */
3651.1Smw	if (temp == dumpdev)
3661.1Smw		dumpdev = swdevt[0].sw_dev;
3671.1Smw#endif
3681.3Smw}
3691.3Smw
3701.17Schopps
3711.11Schopps/*
3721.11Schopps * Try to determine, of this machine is an A3000, which has a builtin
3731.11Schopps * realtime clock and scsi controller, so that this hardware is only
3741.11Schopps * included as "configured" if this IS an A3000
3751.11Schopps */
3761.5Smw
3771.5Smwint a3000_flag = 1;		/* patchable */
3781.5Smw#ifdef A4000
3791.5Smwint a4000_flag = 1;		/* patchable - default to A4000 */
3801.5Smw#else
3811.5Smwint a4000_flag = 0;		/* patchable */
3821.5Smw#endif
3831.5Smw
3841.3Smwint
3851.11Schoppsis_a3000()
3861.3Smw{
3871.11Schopps	/* this is a dirty kludge.. but how do you do this RIGHT ? :-) */
3881.22Schopps	extern long boot_fphystart;
3891.11Schopps	short sc;
3901.11Schopps
3911.19Schopps	if ((machineid >> 16) == 3000)
3921.19Schopps		return (1);			/* It's an A3000 */
3931.19Schopps	if (machineid >> 16)
3941.19Schopps		return (0);			/* It's not an A3000 */
3951.19Schopps	/* Machine type is unknown, so try to guess it */
3961.11Schopps	/* where is fastram on the A4000 ?? */
3971.11Schopps	/* if fastram is below 0x07000000, assume it's not an A3000 */
3981.22Schopps	if (boot_fphystart < 0x07000000)
3991.17Schopps		return(0);
4001.11Schopps	/*
4011.11Schopps	 * OK, fastram starts at or above 0x07000000, check specific
4021.11Schopps	 * machines
4031.11Schopps	 */
4041.17Schopps	for (sc = 0; sc < ncfdev; sc++) {
4051.17Schopps		switch (cfdev[sc].rom.manid) {
4061.17Schopps		case 2026:		/* Progressive Peripherals, Inc */
4071.17Schopps			switch (cfdev[sc].rom.prodid) {
4081.17Schopps			case 0:		/* PPI Mercury - A3000 */
4091.17Schopps			case 1:		/* PP&S A3000 '040 */
4101.17Schopps				return(1);
4111.17Schopps			case 150:	/* PPI Zeus - it's an A2000 */
4121.17Schopps			case 105:	/* PP&S A2000 '040 */
4131.17Schopps			case 187:	/* PP&S A500 '040 */
4141.17Schopps				return(0);
4151.11Schopps			}
4161.11Schopps			break;
4171.3Smw
4181.17Schopps		case 2112:			/* IVS */
4191.17Schopps			switch (cfdev[sc].rom.prodid) {
4201.17Schopps			case 242:
4211.17Schopps				return(0);	/* A2000 accelerator? */
4221.11Schopps			}
4231.11Schopps			break;
4241.11Schopps		}
4251.11Schopps	}
4261.17Schopps	return (a3000_flag);		/* XXX let flag tell now */
4271.5Smw}
4281.5Smw
4291.5Smwint
4301.11Schoppsis_a4000()
4311.5Smw{
4321.19Schopps	if ((machineid >> 16) == 4000)
4331.19Schopps		return (1);		/* It's an A4000 */
4341.24Schopps	if ((machineid >> 16) == 1200)
4351.24Schopps		return (0);		/* It's an A1200, so not A4000 */
4361.36Sis#ifdef DRACO
4371.36Sis	if (is_draco())
4381.36Sis		return (0);
4391.36Sis#endif
4401.24Schopps	/* Do I need this any more? */
4411.19Schopps	if ((custom.deniseid & 0xff) == 0xf8)
4421.19Schopps		return (1);
4431.19Schopps#ifdef DEBUG
4441.19Schopps	if (a4000_flag)
4451.43Schristos		printf("Denise ID = %04x\n", (unsigned short)custom.deniseid);
4461.19Schopps#endif
4471.19Schopps	if (machineid >> 16)
4481.19Schopps		return (0);		/* It's not an A4000 */
4491.19Schopps	return (a4000_flag);		/* Machine type not set */
4501.24Schopps}
4511.24Schopps
4521.24Schoppsint
4531.24Schoppsis_a1200()
4541.24Schopps{
4551.24Schopps	if ((machineid >> 16) == 1200)
4561.24Schopps		return (1);		/* It's an A1200 */
4571.24Schopps	return (0);			/* Machine type not set */
4581.1Smw}
4591.36Sis
4601.36Sis#ifdef DRACO
4611.36Sisint
4621.36Sisis_draco()
4631.36Sis{
4641.36Sis	if ((machineid >> 24) == 0x7D)
4651.36Sis		return ((machineid >> 16) & 0xFF);
4661.36Sis	return (0);
4671.36Sis}
4681.36Sis#endif
469