1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
|
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)autoconf.c 7.1 (Berkeley) 5/9/91
* $Id: autoconf.c,v 1.134 1999/08/22 21:44:32 peter Exp $
*/
/*
* Setup the system to run on the current machine.
*
* Configure() is called at boot time and initializes the vba
* device tables and the memory controller monitoring. Available
* devices are determined (from possibilities mentioned in ioconf.c),
* and the drivers are initialized.
*/
#include "opt_bootp.h"
#include "opt_ffs.h"
#include "opt_cd9660.h"
#include "opt_nfsroot.h"
#include "opt_bus.h"
#include "opt_rootdevname.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/conf.h>
#include <sys/disklabel.h>
#include <sys/diskslice.h>
#include <sys/reboot.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/mount.h>
#include <sys/sysctl.h>
#include <sys/cons.h>
#include <machine/bootinfo.h>
#include <machine/ipl.h>
#include <machine/md_var.h>
#ifdef APIC_IO
#include <machine/smp.h>
#endif /* APIC_IO */
#include "pnp.h"
#if NPNP > 0
#include <i386/isa/icu.h>
#include <i386/isa/isa_device.h>
#include <i386/isa/pnp.h>
#endif
device_t isa_bus_device = 0;
static void configure_first __P((void *));
static void configure __P((void *));
static void configure_final __P((void *));
static void configure_finish __P((void));
static void configure_start __P((void));
#if defined(FFS) || defined(FFS_ROOT)
static void setroot __P((void));
#endif
static int setrootbyname __P((char *name));
static void gets __P((char *));
SYSINIT(configure1, SI_SUB_CONFIGURE, SI_ORDER_FIRST, configure_first, NULL);
/* SI_ORDER_SECOND is hookable */
SYSINIT(configure2, SI_SUB_CONFIGURE, SI_ORDER_THIRD, configure, NULL);
/* SI_ORDER_MIDDLE is hookable */
SYSINIT(configure3, SI_SUB_CONFIGURE, SI_ORDER_ANY, configure_final, NULL);
dev_t rootdev = NODEV;
dev_t dumpdev = NODEV;
#if defined(CD9660) || defined(CD9660_ROOT)
#include <sys/fcntl.h>
#include <sys/proc.h>
#include <sys/stat.h>
#include <machine/clock.h>
/*
* XXX All this CD-ROM root stuff is fairly messy. Ick.
*
* We need to try out all our potential CDROM drives, so we need a table.
*/
static struct {
char *name;
int major;
} try_cdrom[] = {
{ "cd", 6 },
{ "mcd", 7 },
{ "scd", 16 },
{ "matcd", 17 },
{ "wcd", 19 },
{ 0, 0}
};
static int find_cdrom_root __P((void));
static int
find_cdrom_root()
{
int i, j, error;
struct cdevsw *bd;
dev_t orootdev;
#if CD9660_ROOTDELAY > 0
DELAY(CD9660_ROOTDELAY * 1000000);
#endif
orootdev = rootdev;
for (i = 0 ; i < 2; i++)
for (j = 0 ; try_cdrom[j].name ; j++) {
if (try_cdrom[j].major >= NUMCDEVSW)
continue;
rootdev = makebdev(try_cdrom[j].major, i * 8);
bd = devsw(rootdev);
if (bd == NULL || bd->d_open == NULL)
continue;
if (bootverbose)
printf("trying %s%d as rootdev (%p)\n",
try_cdrom[j].name, i, (void *)rootdev);
error = (bd->d_open)(rootdev, FREAD, S_IFBLK, curproc);
if (error == 0) {
if (bd->d_close != NULL)
(bd->d_close)(rootdev, FREAD, S_IFBLK,
curproc);
return 0;
}
}
rootdev = orootdev;
return EINVAL;
}
#endif /* CD9660 || CD9660_ROOT */
static void
configure_start()
{
}
static void
configure_finish()
{
}
device_t nexus_dev;
/*
* Determine i/o configuration for a machine.
*/
static void
configure_first(dummy)
void *dummy;
{
configure_start(); /* DDB hook? */
}
static void
configure(dummy)
void *dummy;
{
/*
* Activate the ICU's. Note that we are explicitly at splhigh()
* at present as we have no way to disable stray PCI level triggered
* interrupts until the devices have had a driver attached. This
* is particularly a problem when the interrupts are shared. For
* example, if IRQ 10 is shared between a disk and network device
* and the disk device generates an interrupt, if we "activate"
* IRQ 10 when the network driver is set up, then we will get
* recursive interrupt 10's as nothing will know how to turn off
* the disk device's interrupt.
*
* Having the ICU's active means we can probe interrupt routing to
* see if a device causes the corresponding pending bit to be set.
*
* This is all rather inconvenient.
*/
#ifdef APIC_IO
bsp_apic_configure();
enable_intr();
#else
enable_intr();
INTREN(IRQ_SLAVE);
#endif /* APIC_IO */
/* nexus0 is the top of the i386 device tree */
device_add_child(root_bus, "nexus", 0, 0);
/* initialize new bus architecture */
root_bus_configure();
#if NPNP > 0
/* Activate PNP. If no drivers are found, let ISA probe them.. */
pnp_configure();
#endif
/*
* Explicitly probe and attach ISA last. The isa bus saves
* it's device node at attach time for us here.
*/
if (isa_bus_device)
bus_generic_attach(isa_bus_device);
/*
* Now we're ready to handle (pending) interrupts.
* XXX this is slightly misplaced.
*/
spl0();
/*
* Allow lowering of the ipl to the lowest kernel level if we
* panic (or call tsleep() before clearing `cold'). No level is
* completely safe (since a panic may occur in a critical region
* at splhigh()), but we want at least bio interrupts to work.
*/
safepri = cpl;
}
static void
configure_final(dummy)
void *dummy;
{
int i;
configure_finish(); /* DDB hook? */
cninit_finish();
if (bootverbose) {
#ifdef APIC_IO
imen_dump();
#endif /* APIC_IO */
/*
* Print out the BIOS's idea of the disk geometries.
*/
printf("BIOS Geometries:\n");
for (i = 0; i < N_BIOS_GEOM; i++) {
unsigned long bios_geom;
int max_cylinder, max_head, max_sector;
bios_geom = bootinfo.bi_bios_geom[i];
/*
* XXX the bootstrap punts a 1200K floppy geometry
* when the get-disk-geometry interrupt fails. Skip
* drives that have this geometry.
*/
if (bios_geom == 0x4f010f)
continue;
printf(" %x:%08lx ", i, bios_geom);
max_cylinder = bios_geom >> 16;
max_head = (bios_geom >> 8) & 0xff;
max_sector = bios_geom & 0xff;
printf(
"0..%d=%d cylinders, 0..%d=%d heads, 1..%d=%d sectors\n",
max_cylinder, max_cylinder + 1,
max_head, max_head + 1,
max_sector, max_sector);
}
printf(" %d accounted for\n", bootinfo.bi_n_bios_used);
printf("Device configuration finished.\n");
}
cold = 0;
}
void
cpu_rootconf()
{
/*
* XXX NetBSD has a much cleaner approach to finding root.
* XXX We should adopt their code.
*/
#if defined(CD9660) || defined(CD9660_ROOT)
if ((boothowto & RB_CDROM)) {
if (bootverbose)
printf("Considering CD-ROM root f/s.\n");
/* NB: find_cdrom_root() sets rootdev if successful. */
if (find_cdrom_root() == 0)
mountrootfsname = "cd9660";
else if (bootverbose)
printf("No CD-ROM available as root f/s.\n");
}
#endif
#ifdef BOOTP_NFSROOT
if (!mountrootfsname && !nfs_diskless_valid) {
if (bootverbose)
printf("Considering BOOTP NFS root f/s.\n");
mountrootfsname = "nfs";
}
#endif /* BOOTP_NFSROOT */
#if defined(NFS) || defined(NFS_ROOT)
if (!mountrootfsname && nfs_diskless_valid) {
if (bootverbose)
printf("Considering NFS root f/s.\n");
mountrootfsname = "nfs";
}
#endif /* NFS */
#if defined(FFS) || defined(FFS_ROOT)
if (!mountrootfsname) {
mountrootfsname = "ufs";
if (bootverbose)
printf("Considering FFS root f/s.\n");
if (boothowto & RB_ASKNAME)
setconf();
else
setroot();
}
#endif
if (!mountrootfsname) {
panic("Nobody wants to mount my root for me");
}
}
u_long bootdev = 0; /* not a dev_t - encoding is different */
#define FDMAJOR 2
#define FDUNITSHIFT 6
#if defined(FFS) || defined(FFS_ROOT)
/*
* Attempt to find the device from which we were booted.
* If we can do so, and not instructed not to do so,
* set rootdevs[] and rootdevnames[] to correspond to the
* boot device(s).
*/
static void
setroot()
{
int majdev, mindev, unit, slice, part;
dev_t newrootdev, dev;
char partname[2];
char *sname;
if (boothowto & RB_DFLTROOT) {
#ifdef ROOTDEVNAME
setrootbyname(ROOTDEVNAME);
#else
setconf();
#endif
return;
}
if ((bootdev & B_MAGICMASK) != B_DEVMAGIC) {
printf("No B_DEVMAGIC\n");
setconf();
return;
}
majdev = B_TYPE(bootdev);
dev = makebdev(majdev, 0);
if (devsw(dev) == NULL) {
printf("No bdevsw (majdev=%d bootdev=%p)\n", majdev,
(void *)bootdev);
setconf();
return;
}
unit = B_UNIT(bootdev);
slice = B_SLICE(bootdev);
if (slice == WHOLE_DISK_SLICE)
slice = COMPATIBILITY_SLICE;
if (slice < 0 || slice >= MAX_SLICES) {
printf("bad slice\n");
setconf();
return;
}
/*
* XXX kludge for inconsistent unit numbering and lack of slice
* support for floppies.
*/
if (majdev == FDMAJOR) {
slice = COMPATIBILITY_SLICE;
part = RAW_PART;
mindev = unit << FDUNITSHIFT;
} else {
part = B_PARTITION(bootdev);
mindev = dkmakeminor(unit, slice, part);
}
newrootdev = makebdev(majdev, mindev);
rootdevs[0] = newrootdev;
sname = dsname(devsw(newrootdev)->d_name, unit, slice, part, partname);
rootdevnames[0] = malloc(strlen(sname) + 2, M_DEVBUF, M_NOWAIT);
sprintf(rootdevnames[0], "%s%s", sname, partname);
/*
* For properly dangerously dedicated disks (ones with a historical
* bogus partition table), the boot blocks will give slice = 4, but
* the kernel will only provide the compatibility slice since it
* knows that slice 4 is not a real slice. Arrange to try mounting
* the compatibility slice as root if mounting the slice passed by
* the boot blocks fails. This handles the dangerously dedicated
* case and perhaps others.
*/
if (slice == COMPATIBILITY_SLICE)
return;
slice = COMPATIBILITY_SLICE;
rootdevs[1] = dkmodslice(newrootdev, slice);
sname = dsname(devsw(newrootdev)->d_name, unit, slice, part, partname);
rootdevnames[1] = malloc(strlen(sname) + 2, M_DEVBUF, M_NOWAIT);
sprintf(rootdevnames[1], "%s%s", sname, partname);
}
#endif
static int
setrootbyname(char *name)
{
char *cp;
int bd, unit, slice, part;
dev_t dev;
printf("setrootbyname(\"%s\")\n", name);
slice = 0;
part = 0;
cp = name;
while (cp != '\0' && (*cp < '0' || *cp > '9'))
cp++;
if (cp == name) {
printf("missing device name\n");
return(1);
}
if (*cp == '\0') {
printf("missing unit number\n");
return(1);
}
unit = *cp - '0';
*cp++ = '\0';
for (bd = 0; bd < NUMCDEVSW; bd++) {
dev = makebdev(bd, 0);
if (devsw(dev) != NULL &&
strcmp(devsw(dev)->d_name, name) == 0)
goto gotit;
}
return (2);
gotit:
while (*cp >= '0' && *cp <= '9')
unit += 10 * unit + *cp++ - '0';
if (*cp == 's' && cp[1] >= '0' && cp[1] <= '9') {
slice = cp[1] - '0' + 1;
cp += 2;
}
if (*cp >= 'a' && *cp <= 'h') {
part = *cp - 'a';
cp++;
}
if (*cp != '\0') {
printf("junk after name\n");
return (1);
}
rootdev = makebdev(bd, dkmakeminor(unit, slice, part));
printf("driver=%s, unit=%d, slice=%d, part=%d -> rootdev=%p\n",
name, unit, slice, part, (void *)rootdev);
return 0;
}
void
setconf()
{
char name[128];
int i;
dev_t dev;
for(;;) {
printf("root device? ");
gets(name);
i = setrootbyname(name);
if (!i)
return;
printf("use one of:\n");
for (i = 0; i < NUMCDEVSW; i++) {
dev = makebdev(i, 0);
if (devsw(dev) != NULL)
printf(" \"%s\"", devsw(dev)->d_name);
}
printf("\nfollowed by a unit number...\n");
}
}
static void
gets(cp)
char *cp;
{
register char *lp;
register int c;
lp = cp;
for (;;) {
printf("%c", c = cngetc() & 0177);
switch (c) {
case -1:
case '\n':
case '\r':
*lp++ = '\0';
return;
case '\b':
case '\177':
if (lp > cp) {
printf(" \b");
lp--;
}
continue;
case '#':
lp--;
if (lp < cp)
lp = cp;
continue;
case '@':
case 'u' & 037:
lp = cp;
printf("%c", '\n');
continue;
default:
*lp++ = c;
}
}
}
|