autoconf.c revision 2430
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 372430Sse * $Id: autoconf.c,v 1.13 1994/08/29 21:47:11 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 */ 482056Swollman#include <sys/param.h> 492056Swollman#include <sys/systm.h> 502056Swollman#include <sys/buf.h> 512056Swollman#include <sys/dkstat.h> 522056Swollman#include <sys/conf.h> 532056Swollman#include <sys/dmap.h> 542056Swollman#include <sys/reboot.h> 552056Swollman#include <sys/kernel.h> 564Srgrimes 572056Swollman#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 822430Sse#include "pci.h" 832430Sse#if NPCI > 0 842430Sse pci_configure(); 852430Sse#endif 862430Sse 87975Smartin#if GENERICxxx && !defined(DISKLESS) 884Srgrimes if ((boothowto & RB_ASKNAME) == 0) 894Srgrimes setroot(); 904Srgrimes setconf(); 914Srgrimes#else 92975Smartin#ifndef DISKLESS 934Srgrimes setroot(); 944Srgrimes#endif 95975Smartin#endif 964Srgrimes /* 974Srgrimes * Configure swap area and related system 984Srgrimes * parameter based on device(s) used. 994Srgrimes */ 1004Srgrimes swapconf(); 1014Srgrimes cold = 0; 1024Srgrimes} 1034Srgrimes 1044Srgrimes/* 1054Srgrimes * Configure swap space and related parameters. 1064Srgrimes */ 107798Swollmanstatic void 1084Srgrimesswapconf() 1094Srgrimes{ 1104Srgrimes register struct swdevt *swp; 1114Srgrimes register int nblks; 1121055Sdg extern int Maxmem; 1134Srgrimes 1144Srgrimes for (swp = swdevt; swp->sw_dev > 0; swp++) 1154Srgrimes { 1164Srgrimes unsigned d = major(swp->sw_dev); 1174Srgrimes 1184Srgrimes if (d > nblkdev) break; 1194Srgrimes if (bdevsw[d].d_psize) { 1204Srgrimes nblks = (*bdevsw[d].d_psize)(swp->sw_dev); 1214Srgrimes if (nblks > 0 && 1224Srgrimes (swp->sw_nblks == 0 || swp->sw_nblks > nblks)) 1234Srgrimes swp->sw_nblks = nblks; 1244Srgrimes else 1254Srgrimes swp->sw_nblks = 0; 1264Srgrimes } 1274Srgrimes swp->sw_nblks = ctod(dtoc(swp->sw_nblks)); 1284Srgrimes } 1294Srgrimes if (dumplo == 0 && bdevsw[major(dumpdev)].d_psize) 1304Srgrimes dumplo = (*bdevsw[major(dumpdev)].d_psize)(dumpdev) - 1314Srgrimes Maxmem*NBPG/512; 1324Srgrimes if (dumplo < 0) 1334Srgrimes dumplo = 0; 1344Srgrimes} 1354Srgrimes 1364Srgrimes#define DOSWAP /* change swdevt and dumpdev */ 1374Srgrimesu_long bootdev = 0; /* should be dev_t, but not until 32 bits */ 1384Srgrimes 1394Srgrimesstatic char devname[][2] = { 1404Srgrimes 'w','d', /* 0 = wd */ 1414Srgrimes 's','w', /* 1 = sw */ 1421289Sache#define FDMAJOR 2 1434Srgrimes 'f','d', /* 2 = fd */ 1444Srgrimes 'w','t', /* 3 = wt */ 1454Srgrimes 's','d', /* 4 = sd -- new SCSI system */ 1464Srgrimes}; 1474Srgrimes 1484Srgrimes#define PARTITIONMASK 0x7 1494Srgrimes#define PARTITIONSHIFT 3 1501290Sache#define FDUNITSHIFT 6 1512400Sache#define RAW_PART 2 1524Srgrimes 1534Srgrimes/* 1544Srgrimes * Attempt to find the device from which we were booted. 1554Srgrimes * If we can do so, and not instructed not to do so, 1564Srgrimes * change rootdev to correspond to the load device. 1574Srgrimes */ 158798Swollmanstatic void 1594Srgrimessetroot() 1604Srgrimes{ 1614Srgrimes int majdev, mindev, unit, part, adaptor; 162798Swollman dev_t temp = 0, orootdev; 1634Srgrimes struct swdevt *swp; 1644Srgrimes 1654Srgrimes/*printf("howto %x bootdev %x ", boothowto, bootdev);*/ 1664Srgrimes if (boothowto & RB_DFLTROOT || 1674Srgrimes (bootdev & B_MAGICMASK) != (u_long)B_DEVMAGIC) 1684Srgrimes return; 1694Srgrimes majdev = (bootdev >> B_TYPESHIFT) & B_TYPEMASK; 1704Srgrimes if (majdev > sizeof(devname) / sizeof(devname[0])) 1714Srgrimes return; 1724Srgrimes adaptor = (bootdev >> B_ADAPTORSHIFT) & B_ADAPTORMASK; 1734Srgrimes unit = (bootdev >> B_UNITSHIFT) & B_UNITMASK; 1741290Sache if (majdev == FDMAJOR) { 1752400Sache part = RAW_PART; 1761290Sache mindev = unit << FDUNITSHIFT; 1771290Sache } 1781290Sache else { 1791290Sache part = (bootdev >> B_PARTITIONSHIFT) & B_PARTITIONMASK; 1801289Sache mindev = (unit << PARTITIONSHIFT) + part; 1811290Sache } 1824Srgrimes orootdev = rootdev; 1834Srgrimes rootdev = makedev(majdev, mindev); 1844Srgrimes /* 1854Srgrimes * If the original rootdev is the same as the one 1864Srgrimes * just calculated, don't need to adjust the swap configuration. 1874Srgrimes */ 1884Srgrimes if (rootdev == orootdev) 1894Srgrimes return; 1904Srgrimes printf("changing root device to %c%c%d%c\n", 1914Srgrimes devname[majdev][0], devname[majdev][1], 1921290Sache mindev >> (majdev == FDMAJOR ? FDUNITSHIFT : PARTITIONSHIFT), 1931290Sache part + 'a'); 1944Srgrimes#ifdef DOSWAP 1954Srgrimes mindev &= ~PARTITIONMASK; 1964Srgrimes for (swp = swdevt; swp->sw_dev; swp++) { 1974Srgrimes if (majdev == major(swp->sw_dev) && 1984Srgrimes mindev == (minor(swp->sw_dev) & ~PARTITIONMASK)) { 1994Srgrimes 2004Srgrimes temp = swdevt[0].sw_dev; 2014Srgrimes swdevt[0].sw_dev = swp->sw_dev; 2024Srgrimes swp->sw_dev = temp; 2034Srgrimes break; 2044Srgrimes } 2054Srgrimes } 2064Srgrimes if (swp->sw_dev == 0) 2074Srgrimes return; 2084Srgrimes /* 2094Srgrimes * If dumpdev was the same as the old primary swap 2104Srgrimes * device, move it to the new primary swap device. 2114Srgrimes */ 2124Srgrimes if (temp == dumpdev) 2134Srgrimes dumpdev = swdevt[0].sw_dev; 2144Srgrimes#endif 2154Srgrimes} 216