autoconf.c revision 1.17
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.17Schopps *	$Id: autoconf.c,v 1.17 1994/05/08 05:52:13 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.17Schopps#include <amiga/amiga/cfdev.h>
391.17Schopps#include <amiga/amiga/device.h>
401.9Schopps#include <amiga/amiga/custom.h>
411.17Schopps#include <amiga/dev/ztwobusvar.h>
421.1Smw
431.17Schoppsvoid configure __P((void));
441.11Schoppsvoid setroot __P((void));
451.11Schoppsvoid swapconf __P((void));
461.17Schoppsvoid mbattach __P((struct device *, struct device *, void *));
471.17Schoppsint mbprint __P((void *, char *));
481.17Schoppsint mbmatch __P((struct device *, struct cfdata *, void *));
491.11Schopps
501.17Schoppsint cold;	/* 1 if still booting */
511.17Schopps#include <sys/kernel.h>
521.1Smw/*
531.17Schopps * called at boot time, configure all devices on system
541.1Smw */
551.11Schoppsvoid
561.1Smwconfigure()
571.1Smw{
581.17Schopps	/*
591.17Schopps	 * this is the real thing baby (i.e. not console init)
601.17Schopps	 */
611.17Schopps	amiga_realconfig = 1;
621.3Smw	custom.intena = INTF_INTEN;
631.1Smw
641.17Schopps	if (config_rootfound("mainbus", "mainbus") == 0)
651.17Schopps		panic("no mainbus found");
661.11Schopps
671.17Schopps	custom.intena = INTF_SETCLR | INTF_INTEN;
681.17Schopps#ifdef GENERIC
691.1Smw	if ((boothowto & RB_ASKNAME) == 0)
701.1Smw		setroot();
711.1Smw	setconf();
721.1Smw#else
731.1Smw	setroot();
741.1Smw#endif
751.1Smw	swapconf();
761.1Smw	cold = 0;
771.17Schopps}
781.3Smw
791.17Schopps/*ARGSUSED*/
801.17Schoppsint
811.17Schoppssimple_devprint(auxp, pnp)
821.17Schopps	void *auxp;
831.17Schopps	char *pnp;
841.17Schopps{
851.17Schopps	return(QUIET);
861.1Smw}
871.1Smw
881.17Schoppsint
891.17Schoppsmatchname(fp, sp)
901.17Schopps	char *fp, *sp;
911.17Schopps{
921.17Schopps	int len;
931.1Smw
941.17Schopps	len = strlen(fp);
951.17Schopps	if (strlen(sp) != len)
961.17Schopps		return(0);
971.17Schopps	if (bcmp(fp, sp, len) == 0)
981.17Schopps		return(1);
991.17Schopps	return(0);
1001.17Schopps}
1011.1Smw
1021.17Schopps/*
1031.17Schopps * use config_search to find appropriate device, then call that device
1041.17Schopps * directly with NULL device variable storage.  A device can then
1051.17Schopps * always tell the difference betwean the real and console init
1061.17Schopps * by checking for NULL.
1071.17Schopps */
1081.11Schoppsint
1091.17Schoppsamiga_config_found(pcfp, pdp, auxp, pfn)
1101.17Schopps	struct cfdata *pcfp;
1111.17Schopps	struct device *pdp;
1121.17Schopps	void *auxp;
1131.17Schopps	cfprint_t pfn;
1141.1Smw{
1151.17Schopps	struct device temp;
1161.17Schopps	struct cfdata *cf;
1171.17Schopps
1181.17Schopps	if (amiga_realconfig)
1191.17Schopps		return(config_found(pdp, auxp, pfn));
1201.17Schopps
1211.17Schopps	if (pdp == NULL)
1221.17Schopps		pdp = &temp;
1231.17Schopps
1241.17Schopps	pdp->dv_cfdata = pcfp;
1251.17Schopps	if ((cf = config_search((cfmatch_t)NULL, pdp, auxp)) != NULL) {
1261.17Schopps		cf->cf_driver->cd_attach(pdp, NULL, auxp);
1271.17Schopps		pdp->dv_cfdata = NULL;
1281.17Schopps		return(1);
1291.1Smw	}
1301.17Schopps	pdp->dv_cfdata = NULL;
1311.17Schopps	return(0);
1321.17Schopps}
1331.17Schopps
1341.17Schopps/*
1351.17Schopps * this function needs to get enough configured to do a console
1361.17Schopps * basically this means start attaching the grfxx's that support
1371.17Schopps * the console. Kinda hacky but it works.
1381.17Schopps */
1391.17Schoppsint
1401.17Schoppsconfig_console()
1411.17Schopps{
1421.17Schopps	extern struct cfdriver mainbuscd, ztwobuscd;
1431.17Schopps	struct cfdata *cf;
1441.17Schopps
1451.17Schopps	/*
1461.17Schopps	 * we need mainbus' cfdata.
1471.17Schopps	 */
1481.17Schopps	cf = config_rootsearch(NULL, "mainbus", "mainbus");
1491.17Schopps	if (cf == NULL)
1501.17Schopps		panic("no mainbus");
1511.1Smw	/*
1521.17Schopps	 * internal grf.
1531.1Smw	 */
1541.17Schopps	amiga_config_found(cf, NULL, "grfcc", NULL);
1551.17Schopps#if not_yet
1561.1Smw	/*
1571.17Schopps	 * ztwobus knows when its not for real (amiga_realconfig == 0)
1581.1Smw	 */
1591.17Schopps	amiga_config_found(cf, NULL, "ztwobus", NULL);
1601.17Schopps#endif
1611.1Smw}
1621.1Smw
1631.17Schopps/*
1641.17Schopps * mainbus driver
1651.17Schopps */
1661.17Schoppsstruct cfdriver mainbuscd = {
1671.17Schopps	NULL, "mainbus", mbmatch, mbattach,
1681.17Schopps	DV_DULL, sizeof(struct device), NULL, 0
1691.17Schopps};
1701.17Schopps
1711.11Schoppsint
1721.17Schoppsmbmatch(pdp, cfp, auxp)
1731.17Schopps	struct device *pdp;
1741.17Schopps	struct cfdata *cfp;
1751.17Schopps	void *auxp;
1761.1Smw{
1771.17Schopps	if (cfp->cf_unit > 0)
1781.1Smw		return(0);
1791.1Smw	/*
1801.17Schopps	 * We are always here
1811.1Smw	 */
1821.1Smw	return(1);
1831.1Smw}
1841.1Smw
1851.1Smw/*
1861.17Schopps * "find" all the things that should be there.
1871.1Smw */
1881.11Schoppsvoid
1891.17Schoppsmbattach(pdp, dp, auxp)
1901.17Schopps	struct device *pdp, *dp;
1911.17Schopps	void *auxp;
1921.1Smw{
1931.17Schopps	config_found(dp, "clock", simple_devprint);
1941.17Schopps	config_found(dp, "ser", simple_devprint);
1951.17Schopps	config_found(dp, "par", simple_devprint);
1961.17Schopps	config_found(dp, "kbd", simple_devprint);
1971.17Schopps	config_found(dp, "grfcc", simple_devprint);
1981.17Schopps	config_found(dp, "ztwobus", simple_devprint);
1991.17Schopps	if (is_a3000())
2001.17Schopps		config_found(dp, "ahsc", simple_devprint);
2011.1Smw}
2021.1Smw
2031.11Schoppsint
2041.17Schoppsmbprint(auxp, pnp)
2051.17Schopps	void *auxp;
2061.17Schopps	char *pnp;
2071.1Smw{
2081.17Schopps	if (pnp)
2091.17Schopps		printf("%s at %s", (char *)auxp, pnp);
2101.17Schopps	return(UNCONF);
2111.1Smw}
2121.1Smw
2131.11Schoppsvoid
2141.17Schoppsswapconf()
2151.1Smw{
2161.17Schopps	struct swdevt *swp;
2171.17Schopps	u_int maj;
2181.17Schopps	int nb;
2191.3Smw
2201.17Schopps	for (swp = swdevt; swp->sw_dev > 0; swp++) {
2211.17Schopps		maj = major(swp->sw_dev);
2221.5Smw
2231.17Schopps		if (maj > nblkdev)
2241.17Schopps			break;
2251.1Smw
2261.17Schopps		if (bdevsw[maj].d_psize) {
2271.17Schopps			nb = bdevsw[maj].d_psize(swp->sw_dev);
2281.17Schopps			if (nb > 0 &&
2291.17Schopps			    (swp->sw_nblks == 0 || swp->sw_nblks > nb))
2301.17Schopps				swp->sw_nblks = nb;
2311.17Schopps			else
2321.17Schopps				swp->sw_nblks = 0;
2331.1Smw		}
2341.17Schopps		swp->sw_nblks = ctod(dtoc(swp->sw_nblks));
2351.11Schopps	}
2361.17Schopps	if (dumplo == 0 && bdevsw[major(dumpdev)].d_psize)
2371.17Schopps	/*dumplo = (*bdevsw[major(dumpdev)].d_psize)(dumpdev) - physmem;*/
2381.17Schopps		dumplo = (*bdevsw[major(dumpdev)].d_psize)(dumpdev) -
2391.17Schopps			ctob(physmem)/DEV_BSIZE;
2401.17Schopps	if (dumplo < 0)
2411.17Schopps		dumplo = 0;
2421.17Schopps
2431.1Smw}
2441.1Smw
2451.17Schopps#define	DOSWAP			/* change swdevt and dumpdev */
2461.17Schoppsu_long	bootdev = 0;		/* should be dev_t, but not until 32 bits */
2471.1Smw
2481.1Smwstatic	char devname[][2] = {
2491.17Schopps	0,0,
2501.17Schopps	0,0,
2511.17Schopps	'f','d',	/* 2 = fd */
2521.17Schopps	0,0,
2531.17Schopps	's','d',	/* 4 = sd -- new SCSI system */
2541.1Smw};
2551.1Smw
2561.11Schoppsvoid
2571.1Smwsetroot()
2581.1Smw{
2591.17Schopps	int majdev, mindev, unit, part, adaptor;
2601.1Smw	dev_t temp, orootdev;
2611.1Smw	struct swdevt *swp;
2621.1Smw
2631.1Smw	if (boothowto & RB_DFLTROOT ||
2641.17Schopps	    (bootdev & B_MAGICMASK) != (u_long)B_DEVMAGIC)
2651.11Schopps		return;
2661.1Smw	majdev = (bootdev >> B_TYPESHIFT) & B_TYPEMASK;
2671.17Schopps	if (majdev > sizeof(devname) / sizeof(devname[0]))
2681.11Schopps		return;
2691.1Smw	adaptor = (bootdev >> B_ADAPTORSHIFT) & B_ADAPTORMASK;
2701.1Smw	part = (bootdev >> B_PARTITIONSHIFT) & B_PARTITIONMASK;
2711.1Smw	unit = (bootdev >> B_UNITSHIFT) & B_UNITMASK;
2721.1Smw	orootdev = rootdev;
2731.17Schopps	rootdev = MAKEDISKDEV(majdev, unit, part);
2741.1Smw	/*
2751.1Smw	 * If the original rootdev is the same as the one
2761.1Smw	 * just calculated, don't need to adjust the swap configuration.
2771.1Smw	 */
2781.17Schopps	if (rootdev == orootdev)
2791.11Schopps		return;
2801.17Schopps	printf("changing root device to %c%c%d%c\n",
2811.1Smw		devname[majdev][0], devname[majdev][1],
2821.17Schopps		unit, part + 'a');
2831.1Smw#ifdef DOSWAP
2841.17Schopps	mindev = DISKUNIT(rootdev);
2851.1Smw	for (swp = swdevt; swp->sw_dev; swp++) {
2861.1Smw		if (majdev == major(swp->sw_dev) &&
2871.17Schopps		    mindev == DISKUNIT(swp->sw_dev)) {
2881.1Smw			temp = swdevt[0].sw_dev;
2891.1Smw			swdevt[0].sw_dev = swp->sw_dev;
2901.1Smw			swp->sw_dev = temp;
2911.1Smw			break;
2921.1Smw		}
2931.1Smw	}
2941.1Smw	if (swp->sw_dev == 0)
2951.1Smw		return;
2961.1Smw	/*
2971.1Smw	 * If dumpdev was the same as the old primary swap
2981.1Smw	 * device, move it to the new primary swap device.
2991.1Smw	 */
3001.1Smw	if (temp == dumpdev)
3011.1Smw		dumpdev = swdevt[0].sw_dev;
3021.1Smw#endif
3031.3Smw}
3041.3Smw
3051.17Schopps
3061.11Schopps/*
3071.11Schopps * Try to determine, of this machine is an A3000, which has a builtin
3081.11Schopps * realtime clock and scsi controller, so that this hardware is only
3091.11Schopps * included as "configured" if this IS an A3000
3101.11Schopps */
3111.5Smw
3121.5Smwint a3000_flag = 1;		/* patchable */
3131.5Smw#ifdef A4000
3141.5Smwint a4000_flag = 1;		/* patchable - default to A4000 */
3151.5Smw#else
3161.5Smwint a4000_flag = 0;		/* patchable */
3171.5Smw#endif
3181.5Smw
3191.3Smwint
3201.11Schoppsis_a3000()
3211.3Smw{
3221.11Schopps	/* this is a dirty kludge.. but how do you do this RIGHT ? :-) */
3231.11Schopps	extern long orig_fastram_start;
3241.11Schopps	short sc;
3251.11Schopps
3261.11Schopps	/* where is fastram on the A4000 ?? */
3271.11Schopps	/* if fastram is below 0x07000000, assume it's not an A3000 */
3281.11Schopps	if (orig_fastram_start < 0x07000000)
3291.17Schopps		return(0);
3301.11Schopps	/*
3311.11Schopps	 * OK, fastram starts at or above 0x07000000, check specific
3321.11Schopps	 * machines
3331.11Schopps	 */
3341.17Schopps	for (sc = 0; sc < ncfdev; sc++) {
3351.17Schopps		switch (cfdev[sc].rom.manid) {
3361.17Schopps		case 2026:		/* Progressive Peripherals, Inc */
3371.17Schopps			switch (cfdev[sc].rom.prodid) {
3381.17Schopps			case 0:		/* PPI Mercury - A3000 */
3391.17Schopps			case 1:		/* PP&S A3000 '040 */
3401.17Schopps				return(1);
3411.17Schopps			case 150:	/* PPI Zeus - it's an A2000 */
3421.17Schopps			case 105:	/* PP&S A2000 '040 */
3431.17Schopps			case 187:	/* PP&S A500 '040 */
3441.17Schopps				return(0);
3451.11Schopps			}
3461.11Schopps			break;
3471.3Smw
3481.17Schopps		case 2112:			/* IVS */
3491.17Schopps			switch (cfdev[sc].rom.prodid) {
3501.17Schopps			case 242:
3511.17Schopps				return(0);	/* A2000 accelerator? */
3521.11Schopps			}
3531.11Schopps			break;
3541.11Schopps		}
3551.11Schopps	}
3561.17Schopps	return (a3000_flag);		/* XXX let flag tell now */
3571.5Smw}
3581.5Smw
3591.5Smwint
3601.11Schoppsis_a4000()
3611.5Smw{
3621.11Schopps	return (a4000_flag);		/* XXX */
3631.1Smw}
364