Commit | Line | Data |
---|---|---|
4bd1c0bf WN |
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 | * | |
73041e30 | 8 | * %sccs.include.redist.c% |
4bd1c0bf | 9 | * |
73041e30 | 10 | * @(#)autoconf.c 5.7 (Berkeley) %G% |
4bd1c0bf | 11 | */ |
4fea1aeb BJ |
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" | |
4fea1aeb BJ |
26 | #include "conf.h" |
27 | #include "dmap.h" | |
28 | #include "reboot.h" | |
29 | ||
2d989769 | 30 | #include "machine/pte.h" |
4fea1aeb BJ |
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 */ | |
4e3c376b | 38 | extern int cold; /* cold start flag initialized in locore.s */ |
4fea1aeb | 39 | |
4fea1aeb BJ |
40 | /* |
41 | * Determine i/o configuration for a machine. | |
42 | */ | |
43 | configure() | |
44 | { | |
9c09b4f2 | 45 | |
2d989769 BJ |
46 | #include "isa.h" |
47 | #if NISA > 0 | |
48 | isa_configure(); | |
49 | #endif | |
4fea1aeb | 50 | |
4bd1c0bf | 51 | #if GENERICxxx |
4fea1aeb BJ |
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; | |
4fea1aeb BJ |
64 | } |
65 | ||
66 | /* | |
67 | * Configure swap space and related parameters. | |
68 | */ | |
69 | swapconf() | |
70 | { | |
71 | register struct swdevt *swp; | |
72 | register int nblks; | |
73041e30 | 73 | extern int Maxmem; |
4fea1aeb | 74 | |
4bd1c0bf WN |
75 | for (swp = swdevt; swp->sw_dev > 0; swp++) |
76 | { | |
77 | if ( swp->sw_dev < 0 || swp->sw_dev > nblkdev ) break; | |
4fea1aeb BJ |
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 | } | |
4bd1c0bf | 85 | } |
4fea1aeb | 86 | if (dumplo == 0 && bdevsw[major(dumpdev)].d_psize) |
73041e30 WN |
87 | /*dumplo = (*bdevsw[major(dumpdev)].d_psize)(dumpdev) - physmem;*/ |
88 | dumplo = (*bdevsw[major(dumpdev)].d_psize)(dumpdev) - | |
89 | Maxmem*NBPG/512; | |
4fea1aeb BJ |
90 | if (dumplo < 0) |
91 | dumplo = 0; | |
92 | } | |
93 | ||
94 | #define DOSWAP /* change swdevt, argdev, and dumpdev too */ | |
4e3c376b | 95 | u_long bootdev = 0; /* should be dev_t, but not until 32 bits */ |
4fea1aeb BJ |
96 | |
97 | static char devname[][2] = { | |
2d989769 BJ |
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 */ | |
4fea1aeb BJ |
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; | |
2d989769 | 128 | mindev = (unit << PARTITIONSHIFT) + part; |
4fea1aeb BJ |
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 argdev and dumpdev were the same as the old primary swap | |
155 | * device, move them to the new primary swap device. | |
156 | */ | |
157 | if (temp == dumpdev) | |
158 | dumpdev = swdevt[0].sw_dev; | |
159 | if (temp == argdev) | |
160 | argdev = swdevt[0].sw_dev; | |
161 | #endif | |
162 | } |