autoconf.c revision 1.32
11.32Sveego/*	$NetBSD: autoconf.c,v 1.32 1996/04/21 21:06:49 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.17Schoppsint mbprint __P((void *, 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.3Smw	custom.intena = INTF_INTEN;
621.1Smw
631.31Scgd	if (config_rootfound("mainbus", "mainbus") == NULL)
641.17Schopps		panic("no mainbus found");
651.11Schopps
661.17Schopps	custom.intena = INTF_SETCLR | INTF_INTEN;
671.28Schopps
681.28Schopps	/* also enable hardware aided software interrupts */
691.28Schopps	custom.intena = INTF_SETCLR | INTF_SOFTINT;
701.28Schopps
711.17Schopps#ifdef GENERIC
721.1Smw	if ((boothowto & RB_ASKNAME) == 0)
731.1Smw		setroot();
741.1Smw	setconf();
751.1Smw#else
761.1Smw	setroot();
771.1Smw#endif
781.1Smw	swapconf();
791.1Smw	cold = 0;
801.17Schopps}
811.3Smw
821.17Schopps/*ARGSUSED*/
831.17Schoppsint
841.17Schoppssimple_devprint(auxp, pnp)
851.17Schopps	void *auxp;
861.17Schopps	char *pnp;
871.17Schopps{
881.17Schopps	return(QUIET);
891.1Smw}
901.1Smw
911.17Schoppsint
921.17Schoppsmatchname(fp, sp)
931.17Schopps	char *fp, *sp;
941.17Schopps{
951.17Schopps	int len;
961.1Smw
971.17Schopps	len = strlen(fp);
981.17Schopps	if (strlen(sp) != len)
991.17Schopps		return(0);
1001.17Schopps	if (bcmp(fp, sp, len) == 0)
1011.17Schopps		return(1);
1021.17Schopps	return(0);
1031.17Schopps}
1041.1Smw
1051.17Schopps/*
1061.17Schopps * use config_search to find appropriate device, then call that device
1071.17Schopps * directly with NULL device variable storage.  A device can then
1081.17Schopps * always tell the difference betwean the real and console init
1091.17Schopps * by checking for NULL.
1101.17Schopps */
1111.11Schoppsint
1121.17Schoppsamiga_config_found(pcfp, pdp, auxp, pfn)
1131.17Schopps	struct cfdata *pcfp;
1141.17Schopps	struct device *pdp;
1151.17Schopps	void *auxp;
1161.17Schopps	cfprint_t pfn;
1171.1Smw{
1181.17Schopps	struct device temp;
1191.17Schopps	struct cfdata *cf;
1201.17Schopps
1211.17Schopps	if (amiga_realconfig)
1221.31Scgd		return(config_found(pdp, auxp, pfn) != NULL);
1231.17Schopps
1241.17Schopps	if (pdp == NULL)
1251.17Schopps		pdp = &temp;
1261.17Schopps
1271.17Schopps	pdp->dv_cfdata = pcfp;
1281.17Schopps	if ((cf = config_search((cfmatch_t)NULL, pdp, auxp)) != NULL) {
1291.30Sthorpej		cf->cf_attach->ca_attach(pdp, NULL, auxp);
1301.17Schopps		pdp->dv_cfdata = NULL;
1311.17Schopps		return(1);
1321.1Smw	}
1331.17Schopps	pdp->dv_cfdata = NULL;
1341.17Schopps	return(0);
1351.17Schopps}
1361.17Schopps
1371.17Schopps/*
1381.17Schopps * this function needs to get enough configured to do a console
1391.17Schopps * basically this means start attaching the grfxx's that support
1401.17Schopps * the console. Kinda hacky but it works.
1411.17Schopps */
1421.32Sveegovoid
1431.17Schoppsconfig_console()
1441.17Schopps{
1451.17Schopps	struct cfdata *cf;
1461.17Schopps
1471.17Schopps	/*
1481.17Schopps	 * we need mainbus' cfdata.
1491.17Schopps	 */
1501.17Schopps	cf = config_rootsearch(NULL, "mainbus", "mainbus");
1511.17Schopps	if (cf == NULL)
1521.17Schopps		panic("no mainbus");
1531.1Smw	/*
1541.17Schopps	 * internal grf.
1551.1Smw	 */
1561.17Schopps	amiga_config_found(cf, NULL, "grfcc", NULL);
1571.1Smw	/*
1581.27Schopps	 * zbus knows when its not for real and will
1591.21Schopps	 * only configure the appropriate hardware
1601.1Smw	 */
1611.27Schopps	amiga_config_found(cf, NULL, "zbus", NULL);
1621.1Smw}
1631.1Smw
1641.17Schopps/*
1651.17Schopps * mainbus driver
1661.17Schopps */
1671.30Sthorpejstruct cfattach mainbus_ca = {
1681.30Sthorpej	sizeof(struct device), mbmatch, mbattach
1691.30Sthorpej};
1701.30Sthorpej
1711.30Sthorpejstruct cfdriver mainbus_cd = {
1721.30Sthorpej	NULL, "mainbus", DV_DULL, NULL, 0
1731.17Schopps};
1741.17Schopps
1751.11Schoppsint
1761.30Sthorpejmbmatch(pdp, match, auxp)
1771.17Schopps	struct device *pdp;
1781.30Sthorpej	void *match, *auxp;
1791.1Smw{
1801.30Sthorpej	struct cfdata *cfp = match;
1811.30Sthorpej
1821.17Schopps	if (cfp->cf_unit > 0)
1831.1Smw		return(0);
1841.1Smw	/*
1851.17Schopps	 * We are always here
1861.1Smw	 */
1871.1Smw	return(1);
1881.1Smw}
1891.1Smw
1901.1Smw/*
1911.17Schopps * "find" all the things that should be there.
1921.1Smw */
1931.11Schoppsvoid
1941.17Schoppsmbattach(pdp, dp, auxp)
1951.17Schopps	struct device *pdp, *dp;
1961.17Schopps	void *auxp;
1971.1Smw{
1981.19Schopps	printf ("\n");
1991.17Schopps	config_found(dp, "clock", simple_devprint);
2001.17Schopps	config_found(dp, "ser", simple_devprint);
2011.17Schopps	config_found(dp, "par", simple_devprint);
2021.17Schopps	config_found(dp, "kbd", simple_devprint);
2031.17Schopps	config_found(dp, "grfcc", simple_devprint);
2041.20Schopps	config_found(dp, "fdc", simple_devprint);
2051.24Schopps	if (is_a4000() || is_a1200())
2061.23Schopps		config_found(dp, "idesc", simple_devprint);
2071.29Schopps	if (is_a4000())			/* Try to configure A4000T SCSI */
2081.29Schopps		config_found(dp, "afsc", simple_devprint);
2091.27Schopps	config_found(dp, "zbus", simple_devprint);
2101.17Schopps	if (is_a3000())
2111.17Schopps		config_found(dp, "ahsc", simple_devprint);
2121.1Smw}
2131.1Smw
2141.11Schoppsint
2151.17Schoppsmbprint(auxp, pnp)
2161.17Schopps	void *auxp;
2171.17Schopps	char *pnp;
2181.1Smw{
2191.17Schopps	if (pnp)
2201.17Schopps		printf("%s at %s", (char *)auxp, pnp);
2211.17Schopps	return(UNCONF);
2221.1Smw}
2231.1Smw
2241.11Schoppsvoid
2251.17Schoppsswapconf()
2261.1Smw{
2271.17Schopps	struct swdevt *swp;
2281.17Schopps	u_int maj;
2291.17Schopps	int nb;
2301.3Smw
2311.17Schopps	for (swp = swdevt; swp->sw_dev > 0; swp++) {
2321.17Schopps		maj = major(swp->sw_dev);
2331.5Smw
2341.17Schopps		if (maj > nblkdev)
2351.17Schopps			break;
2361.1Smw
2371.17Schopps		if (bdevsw[maj].d_psize) {
2381.17Schopps			nb = bdevsw[maj].d_psize(swp->sw_dev);
2391.17Schopps			if (nb > 0 &&
2401.17Schopps			    (swp->sw_nblks == 0 || swp->sw_nblks > nb))
2411.17Schopps				swp->sw_nblks = nb;
2421.17Schopps			else
2431.17Schopps				swp->sw_nblks = 0;
2441.1Smw		}
2451.17Schopps		swp->sw_nblks = ctod(dtoc(swp->sw_nblks));
2461.11Schopps	}
2471.17Schopps	if (dumplo == 0 && bdevsw[major(dumpdev)].d_psize)
2481.17Schopps	/*dumplo = (*bdevsw[major(dumpdev)].d_psize)(dumpdev) - physmem;*/
2491.17Schopps		dumplo = (*bdevsw[major(dumpdev)].d_psize)(dumpdev) -
2501.17Schopps			ctob(physmem)/DEV_BSIZE;
2511.17Schopps	if (dumplo < 0)
2521.17Schopps		dumplo = 0;
2531.17Schopps
2541.1Smw}
2551.1Smw
2561.17Schopps#define	DOSWAP			/* change swdevt and dumpdev */
2571.17Schoppsu_long	bootdev = 0;		/* should be dev_t, but not until 32 bits */
2581.1Smw
2591.1Smwstatic	char devname[][2] = {
2601.32Sveego	{ 0	,0	},
2611.32Sveego	{ 0	,0	},
2621.32Sveego	{ 'f'	,'d'	},	/* 2 = fd */
2631.32Sveego	{ 0	,0	},
2641.32Sveego	{ 's'	,'d'	}	/* 4 = sd -- new SCSI system */
2651.1Smw};
2661.1Smw
2671.11Schoppsvoid
2681.1Smwsetroot()
2691.1Smw{
2701.17Schopps	int majdev, mindev, unit, part, adaptor;
2711.32Sveego	dev_t temp = 0;
2721.32Sveego	dev_t orootdev;
2731.1Smw	struct swdevt *swp;
2741.1Smw
2751.1Smw	if (boothowto & RB_DFLTROOT ||
2761.17Schopps	    (bootdev & B_MAGICMASK) != (u_long)B_DEVMAGIC)
2771.11Schopps		return;
2781.1Smw	majdev = (bootdev >> B_TYPESHIFT) & B_TYPEMASK;
2791.17Schopps	if (majdev > sizeof(devname) / sizeof(devname[0]))
2801.11Schopps		return;
2811.1Smw	adaptor = (bootdev >> B_ADAPTORSHIFT) & B_ADAPTORMASK;
2821.1Smw	part = (bootdev >> B_PARTITIONSHIFT) & B_PARTITIONMASK;
2831.1Smw	unit = (bootdev >> B_UNITSHIFT) & B_UNITMASK;
2841.1Smw	orootdev = rootdev;
2851.17Schopps	rootdev = MAKEDISKDEV(majdev, unit, part);
2861.1Smw	/*
2871.1Smw	 * If the original rootdev is the same as the one
2881.1Smw	 * just calculated, don't need to adjust the swap configuration.
2891.1Smw	 */
2901.17Schopps	if (rootdev == orootdev)
2911.11Schopps		return;
2921.17Schopps	printf("changing root device to %c%c%d%c\n",
2931.1Smw		devname[majdev][0], devname[majdev][1],
2941.17Schopps		unit, part + 'a');
2951.1Smw#ifdef DOSWAP
2961.17Schopps	mindev = DISKUNIT(rootdev);
2971.1Smw	for (swp = swdevt; swp->sw_dev; swp++) {
2981.1Smw		if (majdev == major(swp->sw_dev) &&
2991.17Schopps		    mindev == DISKUNIT(swp->sw_dev)) {
3001.1Smw			temp = swdevt[0].sw_dev;
3011.1Smw			swdevt[0].sw_dev = swp->sw_dev;
3021.1Smw			swp->sw_dev = temp;
3031.1Smw			break;
3041.1Smw		}
3051.1Smw	}
3061.1Smw	if (swp->sw_dev == 0)
3071.1Smw		return;
3081.1Smw	/*
3091.1Smw	 * If dumpdev was the same as the old primary swap
3101.1Smw	 * device, move it to the new primary swap device.
3111.1Smw	 */
3121.1Smw	if (temp == dumpdev)
3131.1Smw		dumpdev = swdevt[0].sw_dev;
3141.1Smw#endif
3151.3Smw}
3161.3Smw
3171.17Schopps
3181.11Schopps/*
3191.11Schopps * Try to determine, of this machine is an A3000, which has a builtin
3201.11Schopps * realtime clock and scsi controller, so that this hardware is only
3211.11Schopps * included as "configured" if this IS an A3000
3221.11Schopps */
3231.5Smw
3241.5Smwint a3000_flag = 1;		/* patchable */
3251.5Smw#ifdef A4000
3261.5Smwint a4000_flag = 1;		/* patchable - default to A4000 */
3271.5Smw#else
3281.5Smwint a4000_flag = 0;		/* patchable */
3291.5Smw#endif
3301.5Smw
3311.3Smwint
3321.11Schoppsis_a3000()
3331.3Smw{
3341.11Schopps	/* this is a dirty kludge.. but how do you do this RIGHT ? :-) */
3351.22Schopps	extern long boot_fphystart;
3361.11Schopps	short sc;
3371.11Schopps
3381.19Schopps	if ((machineid >> 16) == 3000)
3391.19Schopps		return (1);			/* It's an A3000 */
3401.19Schopps	if (machineid >> 16)
3411.19Schopps		return (0);			/* It's not an A3000 */
3421.19Schopps	/* Machine type is unknown, so try to guess it */
3431.11Schopps	/* where is fastram on the A4000 ?? */
3441.11Schopps	/* if fastram is below 0x07000000, assume it's not an A3000 */
3451.22Schopps	if (boot_fphystart < 0x07000000)
3461.17Schopps		return(0);
3471.11Schopps	/*
3481.11Schopps	 * OK, fastram starts at or above 0x07000000, check specific
3491.11Schopps	 * machines
3501.11Schopps	 */
3511.17Schopps	for (sc = 0; sc < ncfdev; sc++) {
3521.17Schopps		switch (cfdev[sc].rom.manid) {
3531.17Schopps		case 2026:		/* Progressive Peripherals, Inc */
3541.17Schopps			switch (cfdev[sc].rom.prodid) {
3551.17Schopps			case 0:		/* PPI Mercury - A3000 */
3561.17Schopps			case 1:		/* PP&S A3000 '040 */
3571.17Schopps				return(1);
3581.17Schopps			case 150:	/* PPI Zeus - it's an A2000 */
3591.17Schopps			case 105:	/* PP&S A2000 '040 */
3601.17Schopps			case 187:	/* PP&S A500 '040 */
3611.17Schopps				return(0);
3621.11Schopps			}
3631.11Schopps			break;
3641.3Smw
3651.17Schopps		case 2112:			/* IVS */
3661.17Schopps			switch (cfdev[sc].rom.prodid) {
3671.17Schopps			case 242:
3681.17Schopps				return(0);	/* A2000 accelerator? */
3691.11Schopps			}
3701.11Schopps			break;
3711.11Schopps		}
3721.11Schopps	}
3731.17Schopps	return (a3000_flag);		/* XXX let flag tell now */
3741.5Smw}
3751.5Smw
3761.5Smwint
3771.11Schoppsis_a4000()
3781.5Smw{
3791.19Schopps	if ((machineid >> 16) == 4000)
3801.19Schopps		return (1);		/* It's an A4000 */
3811.24Schopps	if ((machineid >> 16) == 1200)
3821.24Schopps		return (0);		/* It's an A1200, so not A4000 */
3831.24Schopps	/* Do I need this any more? */
3841.19Schopps	if ((custom.deniseid & 0xff) == 0xf8)
3851.19Schopps		return (1);
3861.19Schopps#ifdef DEBUG
3871.19Schopps	if (a4000_flag)
3881.19Schopps		printf ("Denise ID = %04x\n", (unsigned short)custom.deniseid);
3891.19Schopps#endif
3901.19Schopps	if (machineid >> 16)
3911.19Schopps		return (0);		/* It's not an A4000 */
3921.19Schopps	return (a4000_flag);		/* Machine type not set */
3931.24Schopps}
3941.24Schopps
3951.24Schoppsint
3961.24Schoppsis_a1200()
3971.24Schopps{
3981.24Schopps	if ((machineid >> 16) == 1200)
3991.24Schopps		return (1);		/* It's an A1200 */
4001.24Schopps	return (0);			/* Machine type not set */
4011.1Smw}
402