autoconf.c revision 1.20
11.1Smw/*
21.17Schopps * Copyright (c) 1994 Christian E. Hopps
31.1Smw * All rights reserved.
41.1Smw *
51.1Smw * Redistribution and use in source and binary forms, with or without
61.1Smw * modification, are permitted provided that the following conditions
71.1Smw * are met:
81.1Smw * 1. Redistributions of source code must retain the above copyright
91.1Smw *    notice, this list of conditions and the following disclaimer.
101.1Smw * 2. Redistributions in binary form must reproduce the above copyright
111.1Smw *    notice, this list of conditions and the following disclaimer in the
121.1Smw *    documentation and/or other materials provided with the distribution.
131.1Smw * 3. All advertising materials mentioning features or use of this software
141.1Smw *    must display the following acknowledgement:
151.17Schopps *      This product includes software developed by Christian E. Hopps.
161.17Schopps * 4. The name of the author may not be used to endorse or promote products
171.17Schopps *    derived from this software without specific prior written permission
181.4Smw *
191.17Schopps * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
201.17Schopps * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
211.17Schopps * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
221.17Schopps * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
231.17Schopps * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
241.17Schopps * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
251.17Schopps * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
261.17Schopps * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
271.17Schopps * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
281.17Schopps * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
291.1Smw *
301.20Schopps *	$Id: autoconf.c,v 1.20 1994/05/29 01:44:26 chopps Exp $
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.17Schopps#include <amiga/dev/ztwobusvar.h>
431.1Smw
441.17Schoppsvoid configure __P((void));
451.11Schoppsvoid setroot __P((void));
461.11Schoppsvoid swapconf __P((void));
471.17Schoppsvoid mbattach __P((struct device *, struct device *, void *));
481.17Schoppsint mbprint __P((void *, char *));
491.17Schoppsint mbmatch __P((struct device *, struct cfdata *, void *));
501.11Schopps
511.17Schoppsint cold;	/* 1 if still booting */
521.17Schopps#include <sys/kernel.h>
531.1Smw/*
541.17Schopps * called at boot time, configure all devices on system
551.1Smw */
561.11Schoppsvoid
571.1Smwconfigure()
581.1Smw{
591.17Schopps	/*
601.17Schopps	 * this is the real thing baby (i.e. not console init)
611.17Schopps	 */
621.17Schopps	amiga_realconfig = 1;
631.3Smw	custom.intena = INTF_INTEN;
641.1Smw
651.17Schopps	if (config_rootfound("mainbus", "mainbus") == 0)
661.17Schopps		panic("no mainbus found");
671.11Schopps
681.17Schopps	custom.intena = INTF_SETCLR | INTF_INTEN;
691.17Schopps#ifdef GENERIC
701.1Smw	if ((boothowto & RB_ASKNAME) == 0)
711.1Smw		setroot();
721.1Smw	setconf();
731.1Smw#else
741.1Smw	setroot();
751.1Smw#endif
761.1Smw	swapconf();
771.1Smw	cold = 0;
781.17Schopps}
791.3Smw
801.17Schopps/*ARGSUSED*/
811.17Schoppsint
821.17Schoppssimple_devprint(auxp, pnp)
831.17Schopps	void *auxp;
841.17Schopps	char *pnp;
851.17Schopps{
861.17Schopps	return(QUIET);
871.1Smw}
881.1Smw
891.17Schoppsint
901.17Schoppsmatchname(fp, sp)
911.17Schopps	char *fp, *sp;
921.17Schopps{
931.17Schopps	int len;
941.1Smw
951.17Schopps	len = strlen(fp);
961.17Schopps	if (strlen(sp) != len)
971.17Schopps		return(0);
981.17Schopps	if (bcmp(fp, sp, len) == 0)
991.17Schopps		return(1);
1001.17Schopps	return(0);
1011.17Schopps}
1021.1Smw
1031.17Schopps/*
1041.17Schopps * use config_search to find appropriate device, then call that device
1051.17Schopps * directly with NULL device variable storage.  A device can then
1061.17Schopps * always tell the difference betwean the real and console init
1071.17Schopps * by checking for NULL.
1081.17Schopps */
1091.11Schoppsint
1101.17Schoppsamiga_config_found(pcfp, pdp, auxp, pfn)
1111.17Schopps	struct cfdata *pcfp;
1121.17Schopps	struct device *pdp;
1131.17Schopps	void *auxp;
1141.17Schopps	cfprint_t pfn;
1151.1Smw{
1161.17Schopps	struct device temp;
1171.17Schopps	struct cfdata *cf;
1181.17Schopps
1191.17Schopps	if (amiga_realconfig)
1201.17Schopps		return(config_found(pdp, auxp, pfn));
1211.17Schopps
1221.17Schopps	if (pdp == NULL)
1231.17Schopps		pdp = &temp;
1241.17Schopps
1251.17Schopps	pdp->dv_cfdata = pcfp;
1261.17Schopps	if ((cf = config_search((cfmatch_t)NULL, pdp, auxp)) != NULL) {
1271.17Schopps		cf->cf_driver->cd_attach(pdp, NULL, auxp);
1281.17Schopps		pdp->dv_cfdata = NULL;
1291.17Schopps		return(1);
1301.1Smw	}
1311.17Schopps	pdp->dv_cfdata = NULL;
1321.17Schopps	return(0);
1331.17Schopps}
1341.17Schopps
1351.17Schopps/*
1361.17Schopps * this function needs to get enough configured to do a console
1371.17Schopps * basically this means start attaching the grfxx's that support
1381.17Schopps * the console. Kinda hacky but it works.
1391.17Schopps */
1401.17Schoppsint
1411.17Schoppsconfig_console()
1421.17Schopps{
1431.17Schopps	extern struct cfdriver mainbuscd, ztwobuscd;
1441.17Schopps	struct cfdata *cf;
1451.17Schopps
1461.17Schopps	/*
1471.17Schopps	 * we need mainbus' cfdata.
1481.17Schopps	 */
1491.17Schopps	cf = config_rootsearch(NULL, "mainbus", "mainbus");
1501.17Schopps	if (cf == NULL)
1511.17Schopps		panic("no mainbus");
1521.1Smw	/*
1531.17Schopps	 * internal grf.
1541.1Smw	 */
1551.17Schopps	amiga_config_found(cf, NULL, "grfcc", NULL);
1561.17Schopps#if not_yet
1571.1Smw	/*
1581.17Schopps	 * ztwobus knows when its not for real (amiga_realconfig == 0)
1591.1Smw	 */
1601.17Schopps	amiga_config_found(cf, NULL, "ztwobus", NULL);
1611.17Schopps#endif
1621.1Smw}
1631.1Smw
1641.17Schopps/*
1651.17Schopps * mainbus driver
1661.17Schopps */
1671.17Schoppsstruct cfdriver mainbuscd = {
1681.17Schopps	NULL, "mainbus", mbmatch, mbattach,
1691.17Schopps	DV_DULL, sizeof(struct device), NULL, 0
1701.17Schopps};
1711.17Schopps
1721.11Schoppsint
1731.17Schoppsmbmatch(pdp, cfp, auxp)
1741.17Schopps	struct device *pdp;
1751.17Schopps	struct cfdata *cfp;
1761.17Schopps	void *auxp;
1771.1Smw{
1781.17Schopps	if (cfp->cf_unit > 0)
1791.1Smw		return(0);
1801.1Smw	/*
1811.17Schopps	 * We are always here
1821.1Smw	 */
1831.1Smw	return(1);
1841.1Smw}
1851.1Smw
1861.1Smw/*
1871.17Schopps * "find" all the things that should be there.
1881.1Smw */
1891.11Schoppsvoid
1901.17Schoppsmbattach(pdp, dp, auxp)
1911.17Schopps	struct device *pdp, *dp;
1921.17Schopps	void *auxp;
1931.1Smw{
1941.19Schopps	printf ("\n");
1951.17Schopps	config_found(dp, "clock", simple_devprint);
1961.17Schopps	config_found(dp, "ser", simple_devprint);
1971.17Schopps	config_found(dp, "par", simple_devprint);
1981.17Schopps	config_found(dp, "kbd", simple_devprint);
1991.17Schopps	config_found(dp, "grfcc", simple_devprint);
2001.20Schopps	config_found(dp, "fdc", simple_devprint);
2011.17Schopps	config_found(dp, "ztwobus", simple_devprint);
2021.17Schopps	if (is_a3000())
2031.17Schopps		config_found(dp, "ahsc", simple_devprint);
2041.19Schopps	if (is_a3000() || is_a4000()) {
2051.19Schopps		config_found(dp, "zthreebus", simple_devprint);
2061.19Schopps	}
2071.19Schopps	if (is_a4000())
2081.19Schopps		config_found(dp, "idesc", simple_devprint);
2091.1Smw}
2101.1Smw
2111.11Schoppsint
2121.17Schoppsmbprint(auxp, pnp)
2131.17Schopps	void *auxp;
2141.17Schopps	char *pnp;
2151.1Smw{
2161.17Schopps	if (pnp)
2171.17Schopps		printf("%s at %s", (char *)auxp, pnp);
2181.17Schopps	return(UNCONF);
2191.1Smw}
2201.1Smw
2211.11Schoppsvoid
2221.17Schoppsswapconf()
2231.1Smw{
2241.17Schopps	struct swdevt *swp;
2251.17Schopps	u_int maj;
2261.17Schopps	int nb;
2271.3Smw
2281.17Schopps	for (swp = swdevt; swp->sw_dev > 0; swp++) {
2291.17Schopps		maj = major(swp->sw_dev);
2301.5Smw
2311.17Schopps		if (maj > nblkdev)
2321.17Schopps			break;
2331.1Smw
2341.17Schopps		if (bdevsw[maj].d_psize) {
2351.17Schopps			nb = bdevsw[maj].d_psize(swp->sw_dev);
2361.17Schopps			if (nb > 0 &&
2371.17Schopps			    (swp->sw_nblks == 0 || swp->sw_nblks > nb))
2381.17Schopps				swp->sw_nblks = nb;
2391.17Schopps			else
2401.17Schopps				swp->sw_nblks = 0;
2411.1Smw		}
2421.17Schopps		swp->sw_nblks = ctod(dtoc(swp->sw_nblks));
2431.11Schopps	}
2441.17Schopps	if (dumplo == 0 && bdevsw[major(dumpdev)].d_psize)
2451.17Schopps	/*dumplo = (*bdevsw[major(dumpdev)].d_psize)(dumpdev) - physmem;*/
2461.17Schopps		dumplo = (*bdevsw[major(dumpdev)].d_psize)(dumpdev) -
2471.17Schopps			ctob(physmem)/DEV_BSIZE;
2481.17Schopps	if (dumplo < 0)
2491.17Schopps		dumplo = 0;
2501.17Schopps
2511.1Smw}
2521.1Smw
2531.17Schopps#define	DOSWAP			/* change swdevt and dumpdev */
2541.17Schoppsu_long	bootdev = 0;		/* should be dev_t, but not until 32 bits */
2551.1Smw
2561.1Smwstatic	char devname[][2] = {
2571.17Schopps	0,0,
2581.17Schopps	0,0,
2591.17Schopps	'f','d',	/* 2 = fd */
2601.17Schopps	0,0,
2611.17Schopps	's','d',	/* 4 = sd -- new SCSI system */
2621.1Smw};
2631.1Smw
2641.11Schoppsvoid
2651.1Smwsetroot()
2661.1Smw{
2671.17Schopps	int majdev, mindev, unit, part, adaptor;
2681.1Smw	dev_t temp, orootdev;
2691.1Smw	struct swdevt *swp;
2701.1Smw
2711.1Smw	if (boothowto & RB_DFLTROOT ||
2721.17Schopps	    (bootdev & B_MAGICMASK) != (u_long)B_DEVMAGIC)
2731.11Schopps		return;
2741.1Smw	majdev = (bootdev >> B_TYPESHIFT) & B_TYPEMASK;
2751.17Schopps	if (majdev > sizeof(devname) / sizeof(devname[0]))
2761.11Schopps		return;
2771.1Smw	adaptor = (bootdev >> B_ADAPTORSHIFT) & B_ADAPTORMASK;
2781.1Smw	part = (bootdev >> B_PARTITIONSHIFT) & B_PARTITIONMASK;
2791.1Smw	unit = (bootdev >> B_UNITSHIFT) & B_UNITMASK;
2801.1Smw	orootdev = rootdev;
2811.17Schopps	rootdev = MAKEDISKDEV(majdev, unit, part);
2821.1Smw	/*
2831.1Smw	 * If the original rootdev is the same as the one
2841.1Smw	 * just calculated, don't need to adjust the swap configuration.
2851.1Smw	 */
2861.17Schopps	if (rootdev == orootdev)
2871.11Schopps		return;
2881.17Schopps	printf("changing root device to %c%c%d%c\n",
2891.1Smw		devname[majdev][0], devname[majdev][1],
2901.17Schopps		unit, part + 'a');
2911.1Smw#ifdef DOSWAP
2921.17Schopps	mindev = DISKUNIT(rootdev);
2931.1Smw	for (swp = swdevt; swp->sw_dev; swp++) {
2941.1Smw		if (majdev == major(swp->sw_dev) &&
2951.17Schopps		    mindev == DISKUNIT(swp->sw_dev)) {
2961.1Smw			temp = swdevt[0].sw_dev;
2971.1Smw			swdevt[0].sw_dev = swp->sw_dev;
2981.1Smw			swp->sw_dev = temp;
2991.1Smw			break;
3001.1Smw		}
3011.1Smw	}
3021.1Smw	if (swp->sw_dev == 0)
3031.1Smw		return;
3041.1Smw	/*
3051.1Smw	 * If dumpdev was the same as the old primary swap
3061.1Smw	 * device, move it to the new primary swap device.
3071.1Smw	 */
3081.1Smw	if (temp == dumpdev)
3091.1Smw		dumpdev = swdevt[0].sw_dev;
3101.1Smw#endif
3111.3Smw}
3121.3Smw
3131.17Schopps
3141.11Schopps/*
3151.11Schopps * Try to determine, of this machine is an A3000, which has a builtin
3161.11Schopps * realtime clock and scsi controller, so that this hardware is only
3171.11Schopps * included as "configured" if this IS an A3000
3181.11Schopps */
3191.5Smw
3201.5Smwint a3000_flag = 1;		/* patchable */
3211.5Smw#ifdef A4000
3221.5Smwint a4000_flag = 1;		/* patchable - default to A4000 */
3231.5Smw#else
3241.5Smwint a4000_flag = 0;		/* patchable */
3251.5Smw#endif
3261.5Smw
3271.3Smwint
3281.11Schoppsis_a3000()
3291.3Smw{
3301.11Schopps	/* this is a dirty kludge.. but how do you do this RIGHT ? :-) */
3311.11Schopps	extern long orig_fastram_start;
3321.11Schopps	short sc;
3331.11Schopps
3341.19Schopps	if ((machineid >> 16) == 3000)
3351.19Schopps		return (1);			/* It's an A3000 */
3361.19Schopps	if (machineid >> 16)
3371.19Schopps		return (0);			/* It's not an A3000 */
3381.19Schopps	/* Machine type is unknown, so try to guess it */
3391.11Schopps	/* where is fastram on the A4000 ?? */
3401.11Schopps	/* if fastram is below 0x07000000, assume it's not an A3000 */
3411.11Schopps	if (orig_fastram_start < 0x07000000)
3421.17Schopps		return(0);
3431.11Schopps	/*
3441.11Schopps	 * OK, fastram starts at or above 0x07000000, check specific
3451.11Schopps	 * machines
3461.11Schopps	 */
3471.17Schopps	for (sc = 0; sc < ncfdev; sc++) {
3481.17Schopps		switch (cfdev[sc].rom.manid) {
3491.17Schopps		case 2026:		/* Progressive Peripherals, Inc */
3501.17Schopps			switch (cfdev[sc].rom.prodid) {
3511.17Schopps			case 0:		/* PPI Mercury - A3000 */
3521.17Schopps			case 1:		/* PP&S A3000 '040 */
3531.17Schopps				return(1);
3541.17Schopps			case 150:	/* PPI Zeus - it's an A2000 */
3551.17Schopps			case 105:	/* PP&S A2000 '040 */
3561.17Schopps			case 187:	/* PP&S A500 '040 */
3571.17Schopps				return(0);
3581.11Schopps			}
3591.11Schopps			break;
3601.3Smw
3611.17Schopps		case 2112:			/* IVS */
3621.17Schopps			switch (cfdev[sc].rom.prodid) {
3631.17Schopps			case 242:
3641.17Schopps				return(0);	/* A2000 accelerator? */
3651.11Schopps			}
3661.11Schopps			break;
3671.11Schopps		}
3681.11Schopps	}
3691.17Schopps	return (a3000_flag);		/* XXX let flag tell now */
3701.5Smw}
3711.5Smw
3721.5Smwint
3731.11Schoppsis_a4000()
3741.5Smw{
3751.19Schopps	if ((machineid >> 16) == 4000)
3761.19Schopps		return (1);		/* It's an A4000 */
3771.19Schopps	if ((custom.deniseid & 0xff) == 0xf8)
3781.19Schopps		return (1);
3791.19Schopps#ifdef DEBUG
3801.19Schopps	if (a4000_flag)
3811.19Schopps		printf ("Denise ID = %04x\n", (unsigned short)custom.deniseid);
3821.19Schopps#endif
3831.19Schopps	if (machineid >> 16)
3841.19Schopps		return (0);		/* It's not an A4000 */
3851.19Schopps	return (a4000_flag);		/* Machine type not set */
3861.1Smw}
387