Commit | Line | Data |
---|---|---|
15637ed4 RG |
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 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | |
15 | * documentation and/or other materials provided with the distribution. | |
16 | * 3. All advertising materials mentioning features or use of this software | |
17 | * must display the following acknowledgement: | |
18 | * This product includes software developed by the University of | |
19 | * California, Berkeley and its contributors. | |
20 | * 4. Neither the name of the University nor the names of its contributors | |
21 | * may be used to endorse or promote products derived from this software | |
22 | * without specific prior written permission. | |
23 | * | |
24 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
34 | * SUCH DAMAGE. | |
35 | * | |
78ed81a3 | 36 | * from: @(#)autoconf.c 7.1 (Berkeley) 5/9/91 |
37 | * $Id$ | |
15637ed4 | 38 | */ |
15637ed4 RG |
39 | |
40 | /* | |
41 | * Setup the system to run on the current machine. | |
42 | * | |
43 | * Configure() is called at boot time and initializes the vba | |
44 | * device tables and the memory controller monitoring. Available | |
45 | * devices are determined (from possibilities mentioned in ioconf.c), | |
46 | * and the drivers are initialized. | |
47 | */ | |
48 | #include "param.h" | |
49 | #include "systm.h" | |
50 | #include "buf.h" | |
51 | #include "dkstat.h" | |
52 | #include "conf.h" | |
53 | #include "dmap.h" | |
54 | #include "reboot.h" | |
55 | ||
56 | #include "machine/pte.h" | |
57 | ||
58 | /* | |
59 | * The following several variables are related to | |
60 | * the configuration process, and are used in initializing | |
61 | * the machine. | |
62 | */ | |
63 | int dkn; /* number of iostat dk numbers assigned so far */ | |
64 | extern int cold; /* cold start flag initialized in locore.s */ | |
65 | ||
66 | /* | |
67 | * Determine i/o configuration for a machine. | |
68 | */ | |
69 | configure() | |
70 | { | |
71 | ||
72 | #include "isa.h" | |
73 | #if NISA > 0 | |
74 | isa_configure(); | |
75 | #endif | |
76 | ||
77 | #if GENERICxxx | |
78 | if ((boothowto & RB_ASKNAME) == 0) | |
79 | setroot(); | |
80 | setconf(); | |
81 | #else | |
82 | setroot(); | |
83 | #endif | |
84 | /* | |
85 | * Configure swap area and related system | |
86 | * parameter based on device(s) used. | |
87 | */ | |
88 | swapconf(); | |
89 | cold = 0; | |
90 | } | |
91 | ||
92 | /* | |
93 | * Configure swap space and related parameters. | |
94 | */ | |
95 | swapconf() | |
96 | { | |
97 | register struct swdevt *swp; | |
98 | register int nblks; | |
99 | extern int Maxmem; | |
100 | ||
101 | for (swp = swdevt; swp->sw_dev > 0; swp++) | |
102 | { | |
103 | unsigned d = major(swp->sw_dev); | |
104 | ||
105 | if (d > nblkdev) break; | |
106 | if (bdevsw[d].d_psize) { | |
107 | nblks = (*bdevsw[d].d_psize)(swp->sw_dev); | |
108 | if (nblks > 0 && | |
109 | (swp->sw_nblks == 0 || swp->sw_nblks > nblks)) | |
110 | swp->sw_nblks = nblks; | |
111 | else | |
112 | swp->sw_nblks = 0; | |
113 | } | |
114 | swp->sw_nblks = ctod(dtoc(swp->sw_nblks)); | |
115 | } | |
116 | if (dumplo == 0 && bdevsw[major(dumpdev)].d_psize) | |
117 | /*dumplo = (*bdevsw[major(dumpdev)].d_psize)(dumpdev) - physmem;*/ | |
118 | dumplo = (*bdevsw[major(dumpdev)].d_psize)(dumpdev) - | |
119 | Maxmem*NBPG/512; | |
120 | if (dumplo < 0) | |
121 | dumplo = 0; | |
122 | } | |
123 | ||
124 | #define DOSWAP /* change swdevt and dumpdev */ | |
125 | u_long bootdev = 0; /* should be dev_t, but not until 32 bits */ | |
126 | ||
15637ed4 RG |
127 | static char devname[][2] = { |
128 | 'w','d', /* 0 = wd */ | |
129 | 's','w', /* 1 = sw */ | |
130 | 'f','d', /* 2 = fd */ | |
131 | 'w','t', /* 3 = wt */ | |
15637ed4 | 132 | 's','d', /* 4 = sd -- new SCSI system */ |
15637ed4 RG |
133 | }; |
134 | ||
135 | #define PARTITIONMASK 0x7 | |
136 | #define PARTITIONSHIFT 3 | |
137 | ||
138 | /* | |
139 | * Attempt to find the device from which we were booted. | |
140 | * If we can do so, and not instructed not to do so, | |
141 | * change rootdev to correspond to the load device. | |
142 | */ | |
143 | setroot() | |
144 | { | |
145 | int majdev, mindev, unit, part, adaptor; | |
146 | dev_t temp, orootdev; | |
147 | struct swdevt *swp; | |
148 | ||
149 | /*printf("howto %x bootdev %x ", boothowto, bootdev);*/ | |
150 | if (boothowto & RB_DFLTROOT || | |
151 | (bootdev & B_MAGICMASK) != (u_long)B_DEVMAGIC) | |
152 | return; | |
153 | majdev = (bootdev >> B_TYPESHIFT) & B_TYPEMASK; | |
154 | if (majdev > sizeof(devname) / sizeof(devname[0])) | |
155 | return; | |
156 | adaptor = (bootdev >> B_ADAPTORSHIFT) & B_ADAPTORMASK; | |
157 | part = (bootdev >> B_PARTITIONSHIFT) & B_PARTITIONMASK; | |
158 | unit = (bootdev >> B_UNITSHIFT) & B_UNITMASK; | |
159 | mindev = (unit << PARTITIONSHIFT) + part; | |
160 | orootdev = rootdev; | |
161 | rootdev = makedev(majdev, mindev); | |
162 | /* | |
163 | * If the original rootdev is the same as the one | |
164 | * just calculated, don't need to adjust the swap configuration. | |
165 | */ | |
166 | if (rootdev == orootdev) | |
167 | return; | |
15637ed4 RG |
168 | printf("changing root device to %c%c%d%c\n", |
169 | devname[majdev][0], devname[majdev][1], | |
170 | mindev >> PARTITIONSHIFT, part + 'a'); | |
171 | #ifdef DOSWAP | |
172 | mindev &= ~PARTITIONMASK; | |
173 | for (swp = swdevt; swp->sw_dev; swp++) { | |
174 | if (majdev == major(swp->sw_dev) && | |
175 | mindev == (minor(swp->sw_dev) & ~PARTITIONMASK)) { | |
176 | ||
177 | temp = swdevt[0].sw_dev; | |
178 | swdevt[0].sw_dev = swp->sw_dev; | |
179 | swp->sw_dev = temp; | |
180 | break; | |
181 | } | |
182 | } | |
183 | if (swp->sw_dev == 0) | |
184 | return; | |
185 | /* | |
186 | * If dumpdev was the same as the old primary swap | |
187 | * device, move it to the new primary swap device. | |
188 | */ | |
189 | if (temp == dumpdev) | |
190 | dumpdev = swdevt[0].sw_dev; | |
191 | #endif | |
192 | } |