autoconf.c revision 798
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 37798Swollman * $Id: autoconf.c,v 1.4 1993/10/16 14:14:48 rgrimes 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" 554Srgrimes 564Srgrimes#include "machine/pte.h" 574Srgrimes 58798Swollmanstatic void swapconf(void); 59798Swollmanstatic void setroot(void); 60798Swollman 614Srgrimes/* 624Srgrimes * The following several variables are related to 634Srgrimes * the configuration process, and are used in initializing 644Srgrimes * the machine. 654Srgrimes */ 664Srgrimesint dkn; /* number of iostat dk numbers assigned so far */ 674Srgrimesextern int cold; /* cold start flag initialized in locore.s */ 684Srgrimes 694Srgrimes/* 704Srgrimes * Determine i/o configuration for a machine. 714Srgrimes */ 72798Swollmanvoid 734Srgrimesconfigure() 744Srgrimes{ 754Srgrimes 764Srgrimes#include "isa.h" 774Srgrimes#if NISA > 0 784Srgrimes isa_configure(); 794Srgrimes#endif 804Srgrimes 814Srgrimes#if GENERICxxx 824Srgrimes if ((boothowto & RB_ASKNAME) == 0) 834Srgrimes setroot(); 844Srgrimes setconf(); 854Srgrimes#else 864Srgrimes setroot(); 874Srgrimes#endif 884Srgrimes /* 894Srgrimes * Configure swap area and related system 904Srgrimes * parameter based on device(s) used. 914Srgrimes */ 924Srgrimes swapconf(); 934Srgrimes cold = 0; 944Srgrimes} 954Srgrimes 964Srgrimes/* 974Srgrimes * Configure swap space and related parameters. 984Srgrimes */ 99798Swollmanstatic void 1004Srgrimesswapconf() 1014Srgrimes{ 1024Srgrimes register struct swdevt *swp; 1034Srgrimes register int nblks; 1044Srgrimesextern int Maxmem; 1054Srgrimes 1064Srgrimes for (swp = swdevt; swp->sw_dev > 0; swp++) 1074Srgrimes { 1084Srgrimes unsigned d = major(swp->sw_dev); 1094Srgrimes 1104Srgrimes if (d > nblkdev) break; 1114Srgrimes if (bdevsw[d].d_psize) { 1124Srgrimes nblks = (*bdevsw[d].d_psize)(swp->sw_dev); 1134Srgrimes if (nblks > 0 && 1144Srgrimes (swp->sw_nblks == 0 || swp->sw_nblks > nblks)) 1154Srgrimes swp->sw_nblks = nblks; 1164Srgrimes else 1174Srgrimes swp->sw_nblks = 0; 1184Srgrimes } 1194Srgrimes swp->sw_nblks = ctod(dtoc(swp->sw_nblks)); 1204Srgrimes } 1214Srgrimes if (dumplo == 0 && bdevsw[major(dumpdev)].d_psize) 1224Srgrimes /*dumplo = (*bdevsw[major(dumpdev)].d_psize)(dumpdev) - physmem;*/ 1234Srgrimes dumplo = (*bdevsw[major(dumpdev)].d_psize)(dumpdev) - 1244Srgrimes Maxmem*NBPG/512; 1254Srgrimes if (dumplo < 0) 1264Srgrimes dumplo = 0; 1274Srgrimes} 1284Srgrimes 1294Srgrimes#define DOSWAP /* change swdevt and dumpdev */ 1304Srgrimesu_long bootdev = 0; /* should be dev_t, but not until 32 bits */ 1314Srgrimes 1324Srgrimesstatic char devname[][2] = { 1334Srgrimes 'w','d', /* 0 = wd */ 1344Srgrimes 's','w', /* 1 = sw */ 1354Srgrimes 'f','d', /* 2 = fd */ 1364Srgrimes 'w','t', /* 3 = wt */ 1374Srgrimes 's','d', /* 4 = sd -- new SCSI system */ 1384Srgrimes}; 1394Srgrimes 1404Srgrimes#define PARTITIONMASK 0x7 1414Srgrimes#define PARTITIONSHIFT 3 1424Srgrimes 1434Srgrimes/* 1444Srgrimes * Attempt to find the device from which we were booted. 1454Srgrimes * If we can do so, and not instructed not to do so, 1464Srgrimes * change rootdev to correspond to the load device. 1474Srgrimes */ 148798Swollmanstatic void 1494Srgrimessetroot() 1504Srgrimes{ 1514Srgrimes int majdev, mindev, unit, part, adaptor; 152798Swollman dev_t temp = 0, orootdev; 1534Srgrimes struct swdevt *swp; 1544Srgrimes 1554Srgrimes/*printf("howto %x bootdev %x ", boothowto, bootdev);*/ 1564Srgrimes if (boothowto & RB_DFLTROOT || 1574Srgrimes (bootdev & B_MAGICMASK) != (u_long)B_DEVMAGIC) 1584Srgrimes return; 1594Srgrimes majdev = (bootdev >> B_TYPESHIFT) & B_TYPEMASK; 1604Srgrimes if (majdev > sizeof(devname) / sizeof(devname[0])) 1614Srgrimes return; 1624Srgrimes adaptor = (bootdev >> B_ADAPTORSHIFT) & B_ADAPTORMASK; 1634Srgrimes part = (bootdev >> B_PARTITIONSHIFT) & B_PARTITIONMASK; 1644Srgrimes unit = (bootdev >> B_UNITSHIFT) & B_UNITMASK; 1654Srgrimes mindev = (unit << PARTITIONSHIFT) + part; 1664Srgrimes orootdev = rootdev; 1674Srgrimes rootdev = makedev(majdev, mindev); 1684Srgrimes /* 1694Srgrimes * If the original rootdev is the same as the one 1704Srgrimes * just calculated, don't need to adjust the swap configuration. 1714Srgrimes */ 1724Srgrimes if (rootdev == orootdev) 1734Srgrimes return; 1744Srgrimes printf("changing root device to %c%c%d%c\n", 1754Srgrimes devname[majdev][0], devname[majdev][1], 1764Srgrimes mindev >> PARTITIONSHIFT, part + 'a'); 1774Srgrimes#ifdef DOSWAP 1784Srgrimes mindev &= ~PARTITIONMASK; 1794Srgrimes for (swp = swdevt; swp->sw_dev; swp++) { 1804Srgrimes if (majdev == major(swp->sw_dev) && 1814Srgrimes mindev == (minor(swp->sw_dev) & ~PARTITIONMASK)) { 1824Srgrimes 1834Srgrimes temp = swdevt[0].sw_dev; 1844Srgrimes swdevt[0].sw_dev = swp->sw_dev; 1854Srgrimes swp->sw_dev = temp; 1864Srgrimes break; 1874Srgrimes } 1884Srgrimes } 1894Srgrimes if (swp->sw_dev == 0) 1904Srgrimes return; 1914Srgrimes /* 1924Srgrimes * If dumpdev was the same as the old primary swap 1934Srgrimes * device, move it to the new primary swap device. 1944Srgrimes */ 1954Srgrimes if (temp == dumpdev) 1964Srgrimes dumpdev = swdevt[0].sw_dev; 1974Srgrimes#endif 1984Srgrimes} 199