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