autoconf.c revision 1290
14Srgrimes/*-
24Srgrimes * Copyright (c) 1990 The Regents of the University of California.
34Srgrimes * All rights reserved.
44Srgrimes *
54Srgrimes * This code is derived from software contributed to Berkeley by
64Srgrimes * William Jolitz.
74Srgrimes *
84Srgrimes * Redistribution and use in source and binary forms, with or without
94Srgrimes * modification, are permitted provided that the following conditions
104Srgrimes * are met:
114Srgrimes * 1. Redistributions of source code must retain the above copyright
124Srgrimes *    notice, this list of conditions and the following disclaimer.
134Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
144Srgrimes *    notice, this list of conditions and the following disclaimer in the
154Srgrimes *    documentation and/or other materials provided with the distribution.
164Srgrimes * 3. All advertising materials mentioning features or use of this software
174Srgrimes *    must display the following acknowledgement:
184Srgrimes *	This product includes software developed by the University of
194Srgrimes *	California, Berkeley and its contributors.
204Srgrimes * 4. Neither the name of the University nor the names of its contributors
214Srgrimes *    may be used to endorse or promote products derived from this software
224Srgrimes *    without specific prior written permission.
234Srgrimes *
244Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
254Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
264Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
274Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
284Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
294Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
304Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
314Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
324Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
334Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
344Srgrimes * SUCH DAMAGE.
354Srgrimes *
36620Srgrimes *	from: @(#)autoconf.c	7.1 (Berkeley) 5/9/91
371290Sache *	$Id: autoconf.c,v 1.9 1994/03/21 14:37:01 ache Exp $
384Srgrimes */
394Srgrimes
404Srgrimes/*
414Srgrimes * Setup the system to run on the current machine.
424Srgrimes *
434Srgrimes * Configure() is called at boot time and initializes the vba
444Srgrimes * device tables and the memory controller monitoring.  Available
454Srgrimes * devices are determined (from possibilities mentioned in ioconf.c),
464Srgrimes * and the drivers are initialized.
474Srgrimes */
484Srgrimes#include "param.h"
494Srgrimes#include "systm.h"
504Srgrimes#include "buf.h"
514Srgrimes#include "dkstat.h"
524Srgrimes#include "conf.h"
534Srgrimes#include "dmap.h"
544Srgrimes#include "reboot.h"
55879Swollman#include "kernel.h"
564Srgrimes
574Srgrimes#include "machine/pte.h"
584Srgrimes
59798Swollmanstatic void swapconf(void);
60798Swollmanstatic void setroot(void);
61798Swollman
624Srgrimes/*
634Srgrimes * The following several variables are related to
644Srgrimes * the configuration process, and are used in initializing
654Srgrimes * the machine.
664Srgrimes */
674Srgrimesint	dkn;		/* number of iostat dk numbers assigned so far */
684Srgrimesextern int	cold;		/* cold start flag initialized in locore.s */
694Srgrimes
704Srgrimes/*
714Srgrimes * Determine i/o configuration for a machine.
724Srgrimes */
73798Swollmanvoid
744Srgrimesconfigure()
754Srgrimes{
764Srgrimes
774Srgrimes#include "isa.h"
784Srgrimes#if NISA > 0
794Srgrimes	isa_configure();
804Srgrimes#endif
814Srgrimes
82975Smartin#if GENERICxxx && !defined(DISKLESS)
834Srgrimes	if ((boothowto & RB_ASKNAME) == 0)
844Srgrimes		setroot();
854Srgrimes	setconf();
864Srgrimes#else
87975Smartin#ifndef DISKLESS
884Srgrimes	setroot();
894Srgrimes#endif
90975Smartin#endif
914Srgrimes	/*
924Srgrimes	 * Configure swap area and related system
934Srgrimes	 * parameter based on device(s) used.
944Srgrimes	 */
954Srgrimes	swapconf();
964Srgrimes	cold = 0;
974Srgrimes}
984Srgrimes
994Srgrimes/*
1004Srgrimes * Configure swap space and related parameters.
1014Srgrimes */
102798Swollmanstatic void
1034Srgrimesswapconf()
1044Srgrimes{
1054Srgrimes	register struct swdevt *swp;
1064Srgrimes	register int nblks;
1071055Sdg	extern int Maxmem;
1084Srgrimes
1094Srgrimes	for (swp = swdevt; swp->sw_dev > 0; swp++)
1104Srgrimes	{
1114Srgrimes		unsigned d = major(swp->sw_dev);
1124Srgrimes
1134Srgrimes		if (d > nblkdev) break;
1144Srgrimes		if (bdevsw[d].d_psize) {
1154Srgrimes			nblks = (*bdevsw[d].d_psize)(swp->sw_dev);
1164Srgrimes			if (nblks > 0 &&
1174Srgrimes			    (swp->sw_nblks == 0 || swp->sw_nblks > nblks))
1184Srgrimes				swp->sw_nblks = nblks;
1194Srgrimes			else
1204Srgrimes				swp->sw_nblks = 0;
1214Srgrimes		}
1224Srgrimes		swp->sw_nblks = ctod(dtoc(swp->sw_nblks));
1234Srgrimes	}
1244Srgrimes	if (dumplo == 0 && bdevsw[major(dumpdev)].d_psize)
1254Srgrimes		dumplo = (*bdevsw[major(dumpdev)].d_psize)(dumpdev) -
1264Srgrimes			Maxmem*NBPG/512;
1274Srgrimes	if (dumplo < 0)
1284Srgrimes		dumplo = 0;
1294Srgrimes}
1304Srgrimes
1314Srgrimes#define	DOSWAP			/* change swdevt and dumpdev */
1324Srgrimesu_long	bootdev = 0;		/* should be dev_t, but not until 32 bits */
1334Srgrimes
1344Srgrimesstatic	char devname[][2] = {
1354Srgrimes	'w','d',	/* 0 = wd */
1364Srgrimes	's','w',	/* 1 = sw */
1371289Sache#define FDMAJOR 2
1384Srgrimes	'f','d',	/* 2 = fd */
1394Srgrimes	'w','t',	/* 3 = wt */
1404Srgrimes	's','d',	/* 4 = sd -- new SCSI system */
1414Srgrimes};
1424Srgrimes
1434Srgrimes#define	PARTITIONMASK	0x7
1444Srgrimes#define	PARTITIONSHIFT	3
1451290Sache#define FDUNITSHIFT     6
1464Srgrimes
1474Srgrimes/*
1484Srgrimes * Attempt to find the device from which we were booted.
1494Srgrimes * If we can do so, and not instructed not to do so,
1504Srgrimes * change rootdev to correspond to the load device.
1514Srgrimes */
152798Swollmanstatic void
1534Srgrimessetroot()
1544Srgrimes{
1554Srgrimes	int  majdev, mindev, unit, part, adaptor;
156798Swollman	dev_t temp = 0, orootdev;
1574Srgrimes	struct swdevt *swp;
1584Srgrimes
1594Srgrimes/*printf("howto %x bootdev %x ", boothowto, bootdev);*/
1604Srgrimes	if (boothowto & RB_DFLTROOT ||
1614Srgrimes	    (bootdev & B_MAGICMASK) != (u_long)B_DEVMAGIC)
1624Srgrimes		return;
1634Srgrimes	majdev = (bootdev >> B_TYPESHIFT) & B_TYPEMASK;
1644Srgrimes	if (majdev > sizeof(devname) / sizeof(devname[0]))
1654Srgrimes		return;
1664Srgrimes	adaptor = (bootdev >> B_ADAPTORSHIFT) & B_ADAPTORMASK;
1674Srgrimes	unit = (bootdev >> B_UNITSHIFT) & B_UNITMASK;
1681290Sache	if (majdev == FDMAJOR) {
1691290Sache		part = 0;
1701290Sache		mindev = unit << FDUNITSHIFT;
1711290Sache	}
1721290Sache	else {
1731290Sache		part = (bootdev >> B_PARTITIONSHIFT) & B_PARTITIONMASK;
1741289Sache		mindev = (unit << PARTITIONSHIFT) + part;
1751290Sache	}
1764Srgrimes	orootdev = rootdev;
1774Srgrimes	rootdev = makedev(majdev, mindev);
1784Srgrimes	/*
1794Srgrimes	 * If the original rootdev is the same as the one
1804Srgrimes	 * just calculated, don't need to adjust the swap configuration.
1814Srgrimes	 */
1824Srgrimes	if (rootdev == orootdev)
1834Srgrimes		return;
1844Srgrimes	printf("changing root device to %c%c%d%c\n",
1854Srgrimes		devname[majdev][0], devname[majdev][1],
1861290Sache		mindev >> (majdev == FDMAJOR ? FDUNITSHIFT : PARTITIONSHIFT),
1871290Sache		part + 'a');
1884Srgrimes#ifdef DOSWAP
1894Srgrimes	mindev &= ~PARTITIONMASK;
1904Srgrimes	for (swp = swdevt; swp->sw_dev; swp++) {
1914Srgrimes		if (majdev == major(swp->sw_dev) &&
1924Srgrimes		    mindev == (minor(swp->sw_dev) & ~PARTITIONMASK)) {
1934Srgrimes
1944Srgrimes			temp = swdevt[0].sw_dev;
1954Srgrimes			swdevt[0].sw_dev = swp->sw_dev;
1964Srgrimes			swp->sw_dev = temp;
1974Srgrimes			break;
1984Srgrimes		}
1994Srgrimes	}
2004Srgrimes	if (swp->sw_dev == 0)
2014Srgrimes		return;
2024Srgrimes	/*
2034Srgrimes	 * If dumpdev was the same as the old primary swap
2044Srgrimes	 * device, move it to the new primary swap device.
2054Srgrimes	 */
2064Srgrimes	if (temp == dumpdev)
2074Srgrimes		dumpdev = swdevt[0].sw_dev;
2084Srgrimes#endif
2094Srgrimes}
210