autoconf.c revision 7090
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 377090Sbde * $Id: autoconf.c,v 1.20 1995/02/18 18:04:30 wpaul 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 577090Sbde#include <machine/md_var.h> 582056Swollman#include <machine/pte.h> 594Srgrimes 60798Swollmanstatic void swapconf(void); 61798Swollmanstatic void setroot(void); 62798Swollman 634Srgrimes/* 644Srgrimes * The following several variables are related to 654Srgrimes * the configuration process, and are used in initializing 664Srgrimes * the machine. 674Srgrimes */ 684Srgrimesint dkn; /* number of iostat dk numbers assigned so far */ 694Srgrimes 704370Sphkextern int (*mountroot) __P((void)); 714370Sphk#ifdef FFS 724370Sphkint ffs_mountroot __P((void)); 734370Sphk#endif 744370Sphk#ifdef NFS 754370Sphkint nfs_mountroot __P((void)); 764370Sphk#endif 774370Sphk 786105Sse#include "isa.h" 796105Sse#if NISA > 0 806105Sse #include <i386/isa/isa_device.h> 816105Sse#endif 826105Sse 836105Sse#include "pci.h" 846105Sse#if NPCI > 0 856105Sse #include <pci/pcivar.h> 866105Sse#endif 876105Sse 884Srgrimes/* 894Srgrimes * Determine i/o configuration for a machine. 904Srgrimes */ 91798Swollmanvoid 924Srgrimesconfigure() 934Srgrimes{ 944Srgrimes 954Srgrimes#if NISA > 0 964Srgrimes isa_configure(); 974Srgrimes#endif 984Srgrimes 992430Sse#if NPCI > 0 1002430Sse pci_configure(); 1012430Sse#endif 1022430Sse 1034370Sphk#ifdef NFS 1043795Sphk if (nfs_diskless_valid) 1053795Sphk mountroot = nfs_mountroot; 1064370Sphk#endif /* NFS */ 1074370Sphk#ifdef FFS 1084370Sphk if (!mountroot) { 1094370Sphk mountroot = ffs_mountroot; 1106547Swpaul /* 1116547Swpaul * Ignore the -a flag if this kernel isn't compiled 1126547Swpaul * with a generic root/swap configuration: if we skip 1136547Swpaul * setroot() and we aren't a generic kernel, chaos 1146547Swpaul * will ensue because setconf() will be a no-op. 1156547Swpaul * (rootdev is always initialized to NODEV in a 1166547Swpaul * generic configuration, so we test for that.) 1176547Swpaul */ 1186547Swpaul if ((boothowto & RB_ASKNAME) == 0 || rootdev != NODEV) 1195321Sjkh setroot(); 1205321Sjkh setconf(); 1213795Sphk } 1224Srgrimes#endif 1234370Sphk if (!mountroot) { 1244370Sphk panic("Nobody wants to mount my root for me"); 1254370Sphk } 1264Srgrimes /* 1274Srgrimes * Configure swap area and related system 1284Srgrimes * parameter based on device(s) used. 1294Srgrimes */ 1304Srgrimes swapconf(); 1314Srgrimes cold = 0; 1324Srgrimes} 1334Srgrimes 1344Srgrimes/* 1354Srgrimes * Configure swap space and related parameters. 1364Srgrimes */ 137798Swollmanstatic void 1384Srgrimesswapconf() 1394Srgrimes{ 1404Srgrimes register struct swdevt *swp; 1414Srgrimes register int nblks; 1424Srgrimes 1434Srgrimes for (swp = swdevt; swp->sw_dev > 0; swp++) 1444Srgrimes { 1454Srgrimes unsigned d = major(swp->sw_dev); 1464Srgrimes 1474Srgrimes if (d > nblkdev) break; 1484Srgrimes if (bdevsw[d].d_psize) { 1494Srgrimes nblks = (*bdevsw[d].d_psize)(swp->sw_dev); 1504Srgrimes if (nblks > 0 && 1514Srgrimes (swp->sw_nblks == 0 || swp->sw_nblks > nblks)) 1524Srgrimes swp->sw_nblks = nblks; 1534Srgrimes else 1544Srgrimes swp->sw_nblks = 0; 1554Srgrimes } 1564Srgrimes swp->sw_nblks = ctod(dtoc(swp->sw_nblks)); 1574Srgrimes } 1584Srgrimes if (dumplo == 0 && bdevsw[major(dumpdev)].d_psize) 1594Srgrimes dumplo = (*bdevsw[major(dumpdev)].d_psize)(dumpdev) - 1604Srgrimes Maxmem*NBPG/512; 1614Srgrimes if (dumplo < 0) 1624Srgrimes dumplo = 0; 1634Srgrimes} 1644Srgrimes 1654Srgrimes#define DOSWAP /* change swdevt and dumpdev */ 1664Srgrimesu_long bootdev = 0; /* should be dev_t, but not until 32 bits */ 1674Srgrimes 1684Srgrimesstatic char devname[][2] = { 1696105Sse {'w','d'}, /* 0 = wd */ 1706105Sse {'s','w'}, /* 1 = sw */ 1711289Sache#define FDMAJOR 2 1726105Sse {'f','d'}, /* 2 = fd */ 1736105Sse {'w','t'}, /* 3 = wt */ 1746105Sse {'s','d'}, /* 4 = sd -- new SCSI system */ 1754Srgrimes}; 1764Srgrimes 1774Srgrimes#define PARTITIONMASK 0x7 1784Srgrimes#define PARTITIONSHIFT 3 1791290Sache#define FDUNITSHIFT 6 1802400Sache#define RAW_PART 2 1814Srgrimes 1824Srgrimes/* 1834Srgrimes * Attempt to find the device from which we were booted. 1844Srgrimes * If we can do so, and not instructed not to do so, 1854Srgrimes * change rootdev to correspond to the load device. 1864Srgrimes */ 187798Swollmanstatic void 1884Srgrimessetroot() 1894Srgrimes{ 1904Srgrimes int majdev, mindev, unit, part, adaptor; 191798Swollman dev_t temp = 0, orootdev; 1924Srgrimes struct swdevt *swp; 1934Srgrimes 1944Srgrimes/*printf("howto %x bootdev %x ", boothowto, bootdev);*/ 1954Srgrimes if (boothowto & RB_DFLTROOT || 1964Srgrimes (bootdev & B_MAGICMASK) != (u_long)B_DEVMAGIC) 1974Srgrimes return; 1984Srgrimes majdev = (bootdev >> B_TYPESHIFT) & B_TYPEMASK; 1994Srgrimes if (majdev > sizeof(devname) / sizeof(devname[0])) 2004Srgrimes return; 2014Srgrimes adaptor = (bootdev >> B_ADAPTORSHIFT) & B_ADAPTORMASK; 2024Srgrimes unit = (bootdev >> B_UNITSHIFT) & B_UNITMASK; 2031290Sache if (majdev == FDMAJOR) { 2042400Sache part = RAW_PART; 2051290Sache mindev = unit << FDUNITSHIFT; 2061290Sache } 2071290Sache else { 2081290Sache part = (bootdev >> B_PARTITIONSHIFT) & B_PARTITIONMASK; 2091289Sache mindev = (unit << PARTITIONSHIFT) + part; 2101290Sache } 2114Srgrimes orootdev = rootdev; 2124Srgrimes rootdev = makedev(majdev, mindev); 2134Srgrimes /* 2144Srgrimes * If the original rootdev is the same as the one 2154Srgrimes * just calculated, don't need to adjust the swap configuration. 2164Srgrimes */ 2174Srgrimes if (rootdev == orootdev) 2184Srgrimes return; 2194Srgrimes printf("changing root device to %c%c%d%c\n", 2204Srgrimes devname[majdev][0], devname[majdev][1], 2211290Sache mindev >> (majdev == FDMAJOR ? FDUNITSHIFT : PARTITIONSHIFT), 2221290Sache part + 'a'); 2234Srgrimes#ifdef DOSWAP 2244Srgrimes mindev &= ~PARTITIONMASK; 2254Srgrimes for (swp = swdevt; swp->sw_dev; swp++) { 2264Srgrimes if (majdev == major(swp->sw_dev) && 2274Srgrimes mindev == (minor(swp->sw_dev) & ~PARTITIONMASK)) { 2284Srgrimes 2294Srgrimes temp = swdevt[0].sw_dev; 2304Srgrimes swdevt[0].sw_dev = swp->sw_dev; 2314Srgrimes swp->sw_dev = temp; 2324Srgrimes break; 2334Srgrimes } 2344Srgrimes } 2354Srgrimes if (swp->sw_dev == 0) 2364Srgrimes return; 2374Srgrimes /* 2384Srgrimes * If dumpdev was the same as the old primary swap 2394Srgrimes * device, move it to the new primary swap device. 2404Srgrimes */ 2414Srgrimes if (temp == dumpdev) 2424Srgrimes dumpdev = swdevt[0].sw_dev; 2434Srgrimes#endif 2444Srgrimes} 245