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