1 /*- 2 * Copyright (c) 1990 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * William Jolitz. 7 * 8 * %sccs.include.386.c% 9 * 10 * @(#)autoconf.c 5.2 (Berkeley) 06/23/90 11 */ 12 13 /* autoconf.c 1.13 87/04/02 */ 14 15 /* 16 * Setup the system to run on the current machine. 17 * 18 * Configure() is called at boot time and initializes the vba 19 * device tables and the memory controller monitoring. Available 20 * devices are determined (from possibilities mentioned in ioconf.c), 21 * and the drivers are initialized. 22 */ 23 #include "param.h" 24 #include "systm.h" 25 #include "map.h" 26 #include "buf.h" 27 #include "dkstat.h" 28 #include "vm.h" 29 #include "conf.h" 30 #include "dmap.h" 31 #include "reboot.h" 32 33 #include "pte.h" 34 #include "../machine/device.h" 35 36 /* 37 * The following several variables are related to 38 * the configuration process, and are used in initializing 39 * the machine. 40 */ 41 int dkn; /* number of iostat dk numbers assigned so far */ 42 int cold; /* cold start flag initialized in locore.s */ 43 44 /* 45 * Determine i/o configuration for a machine. 46 */ 47 configure() 48 { 49 register int *ip; 50 extern caddr_t Sysbase; 51 struct device *dvp; 52 struct driver *dp; 53 register s; 54 55 for (dvp = devtab; dp = dvp->driver; dvp++) { 56 s = splhigh(); 57 dvp->alive = (*dp->probe)(dvp); 58 if (dvp->alive) { 59 printf("%s%d", dp->name, dvp->unit); 60 (*dp->attach)(dvp); 61 printf(" at 0x%x on isa0\n", dvp->ioa); 62 } 63 splx(s); 64 } 65 66 /*pg("setroot");*/ 67 #if GENERICxxx 68 if ((boothowto & RB_ASKNAME) == 0) 69 setroot(); 70 setconf(); 71 #else 72 setroot(); 73 #endif 74 /* 75 * Configure swap area and related system 76 * parameter based on device(s) used. 77 */ 78 /*pg("swapconf");*/ 79 swapconf(); 80 cold = 0; 81 } 82 83 /* 84 * Configure swap space and related parameters. 85 */ 86 swapconf() 87 { 88 register struct swdevt *swp; 89 register int nblks; 90 91 for (swp = swdevt; swp->sw_dev > 0; swp++) 92 { 93 if ( swp->sw_dev < 0 || swp->sw_dev > nblkdev ) break; 94 if (bdevsw[major(swp->sw_dev)].d_psize) { 95 nblks = 96 (*bdevsw[major(swp->sw_dev)].d_psize)(swp->sw_dev); 97 if (nblks != -1 && 98 (swp->sw_nblks == 0 || swp->sw_nblks > nblks)) 99 swp->sw_nblks = nblks; 100 } 101 } 102 if (dumplo == 0 && bdevsw[major(dumpdev)].d_psize) 103 dumplo = (*bdevsw[major(dumpdev)].d_psize)(dumpdev) - physmem; 104 if (dumplo < 0) 105 dumplo = 0; 106 } 107 108 #define DOSWAP /* change swdevt, argdev, and dumpdev too */ 109 u_long bootdev; /* should be dev_t, but not until 32 bits */ 110 111 static char devname[][2] = { 112 0,0, /* 0 = ud */ 113 'd','k', /* 1 = vd */ 114 0,0, /* 2 = xp */ 115 }; 116 117 #define PARTITIONMASK 0x7 118 #define PARTITIONSHIFT 3 119 120 /* 121 * Attempt to find the device from which we were booted. 122 * If we can do so, and not instructed not to do so, 123 * change rootdev to correspond to the load device. 124 */ 125 setroot() 126 { 127 int majdev, mindev, unit, part, adaptor; 128 dev_t temp, orootdev; 129 struct swdevt *swp; 130 131 if (boothowto & RB_DFLTROOT || 132 (bootdev & B_MAGICMASK) != (u_long)B_DEVMAGIC) 133 return; 134 majdev = (bootdev >> B_TYPESHIFT) & B_TYPEMASK; 135 if (majdev > sizeof(devname) / sizeof(devname[0])) 136 return; 137 adaptor = (bootdev >> B_ADAPTORSHIFT) & B_ADAPTORMASK; 138 part = (bootdev >> B_PARTITIONSHIFT) & B_PARTITIONMASK; 139 unit = (bootdev >> B_UNITSHIFT) & B_UNITMASK; 140 mindev = (mindev << PARTITIONSHIFT) + part; 141 orootdev = rootdev; 142 rootdev = makedev(majdev, mindev); 143 /* 144 * If the original rootdev is the same as the one 145 * just calculated, don't need to adjust the swap configuration. 146 */ 147 if (rootdev == orootdev) 148 return; 149 printf("changing root device to %c%c%d%c\n", 150 devname[majdev][0], devname[majdev][1], 151 mindev >> PARTITIONSHIFT, part + 'a'); 152 #ifdef DOSWAP 153 mindev &= ~PARTITIONMASK; 154 for (swp = swdevt; swp->sw_dev; swp++) { 155 if (majdev == major(swp->sw_dev) && 156 mindev == (minor(swp->sw_dev) & ~PARTITIONMASK)) { 157 temp = swdevt[0].sw_dev; 158 swdevt[0].sw_dev = swp->sw_dev; 159 swp->sw_dev = temp; 160 break; 161 } 162 } 163 if (swp->sw_dev == 0) 164 return; 165 /* 166 * If argdev and dumpdev were the same as the old primary swap 167 * device, move them to the new primary swap device. 168 */ 169 if (temp == dumpdev) 170 dumpdev = swdevt[0].sw_dev; 171 if (temp == argdev) 172 argdev = swdevt[0].sw_dev; 173 #endif 174 } 175