2 * Copyright (c) 1990 The Regents of the University of California.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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
36 * from: @(#)autoconf.c 7.1 (Berkeley) 5/9/91
37 * $Id: autoconf.c,v 1.110 1998/10/26 07:05:34 bde Exp $
41 * Setup the system to run on the current machine.
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.
48 #include "opt_bootp.h"
50 #include "opt_cd9660.h"
52 #include "opt_nfsroot.h"
54 #include <sys/param.h>
55 #include <sys/systm.h>
57 #include <sys/disklabel.h>
58 #include <sys/diskslice.h>
59 #include <sys/reboot.h>
60 #include <sys/kernel.h>
61 #include <sys/malloc.h>
62 #include <sys/mount.h>
63 #include <sys/sysctl.h>
65 #include <machine/bootinfo.h>
66 #include <machine/cons.h>
67 #include <machine/ipl.h>
68 #include <machine/md_var.h>
70 #include <machine/smp.h>
73 #include <i386/isa/icu.h>
77 #include <i386/isa/isa_device.h>
82 #include <i386/isa/pnp.h>
87 #include <i386/eisa/eisaconf.h>
92 #include <pci/pcivar.h>
97 static void configure_first __P((void *));
98 static void configure __P((void *));
99 static void configure_final __P((void *));
101 static void configure_finish __P((void));
102 static void configure_start __P((void));
103 static int setdumpdev __P((dev_t dev));
104 static void setroot __P((void));
106 SYSINIT(configure1, SI_SUB_CONFIGURE, SI_ORDER_FIRST, configure_first, NULL);
107 /* SI_ORDER_SECOND is hookable */
108 SYSINIT(configure2, SI_SUB_CONFIGURE, SI_ORDER_THIRD, configure, NULL);
109 /* SI_ORDER_MIDDLE is hookable */
110 SYSINIT(configure3, SI_SUB_CONFIGURE, SI_ORDER_ANY, configure_final, NULL);
113 #if defined(CD9660) || defined(CD9660_ROOT)
115 #include <sys/fcntl.h>
116 #include <sys/proc.h>
117 #include <sys/stat.h>
118 #include <machine/clock.h>
121 * XXX All this CD-ROM root stuff is fairly messy. Ick.
123 * We need to try out all our potential CDROM drives, so we need a table.
137 static int find_cdrom_root __P((void));
146 #if CD9660_ROOTDELAY > 0
147 DELAY(CD9660_ROOTDELAY * 1000000);
150 for (i = 0 ; i < 2; i++)
151 for (j = 0 ; try_cdrom[j].name ; j++) {
152 if (try_cdrom[j].major >= nblkdev)
154 rootdev = makedev(try_cdrom[j].major, i * 8);
155 bd = bdevsw[major(rootdev)];
156 if (bd == NULL || bd->d_open == NULL)
159 printf("trying %s%d as rootdev (0x%x)\n",
160 try_cdrom[j].name, i, rootdev);
161 error = (bd->d_open)(rootdev, FREAD, S_IFBLK, curproc);
163 if (bd->d_close != NULL)
164 (bd->d_close)(rootdev, FREAD, S_IFBLK,
173 #endif /* CD9660 || CD9660_ROOT */
176 extern u_char *mfs_getimage __P((void));
190 * Determine i/o configuration for a machine.
193 configure_first(dummy)
197 configure_start(); /* DDB hook? */
205 /* Allow all routines to decide for themselves if they want intrs */
207 * XXX Since this cannot be achieved on all architectures, we should
208 * XXX go back to disabling all interrupts until configuration is
209 * XXX completed and switch any devices that rely on the current
210 * XXX behavior to no longer rely on interrupts or to register an
211 * XXX interrupt_driven_config_hook for the task.
214 * XXX The above is wrong, because we're implicitly at splhigh(),
215 * XXX and should stay there, so enabling interrupts in the CPU
216 * XXX and the ICU at most gives pending interrupts which just get
220 bsp_apic_configure();
243 /* initialize new bus architecture */
244 root_bus_configure();
247 * Now we're ready to handle (pending) interrupts.
248 * XXX this is slightly misplaced.
253 * Allow lowering of the ipl to the lowest kernel level if we
254 * panic (or call tsleep() before clearing `cold'). No level is
255 * completely safe (since a panic may occur in a critical region
256 * at splhigh()), but we want at least bio interrupts to work.
262 configure_final(dummy)
267 configure_finish(); /* DDB hook? */
278 * Print out the BIOS's idea of the disk geometries.
280 printf("BIOS Geometries:\n");
281 for (i = 0; i < N_BIOS_GEOM; i++) {
282 unsigned long bios_geom;
283 int max_cylinder, max_head, max_sector;
285 bios_geom = bootinfo.bi_bios_geom[i];
288 * XXX the bootstrap punts a 1200K floppy geometry
289 * when the get-disk-geometry interrupt fails. Skip
290 * drives that have this geometry.
292 if (bios_geom == 0x4f010f)
295 printf(" %x:%08lx ", i, bios_geom);
296 max_cylinder = bios_geom >> 16;
297 max_head = (bios_geom >> 8) & 0xff;
298 max_sector = bios_geom & 0xff;
300 "0..%d=%d cylinders, 0..%d=%d heads, 1..%d=%d sectors\n",
301 max_cylinder, max_cylinder + 1,
302 max_head, max_head + 1,
303 max_sector, max_sector);
305 printf(" %d accounted for\n", bootinfo.bi_n_bios_used);
307 printf("Device configuration finished.\n");
317 * XXX NetBSD has a much cleaner approach to finding root.
318 * XXX We should adopt their code.
320 #if defined(CD9660) || defined(CD9660_ROOT)
321 if ((boothowto & RB_CDROM)) {
323 printf("Considering CD-ROM root f/s.\n");
324 /* NB: find_cdrom_root() sets rootdev if successful. */
325 if (find_cdrom_root() == 0)
326 mountrootfsname = "cd9660";
327 else if (bootverbose)
328 printf("No CD-ROM available as root f/s.\n");
333 if (!mountrootfsname) {
335 printf("Considering MFS root f/s.\n");
336 if (mfs_getimage()) {
337 mountrootfsname = "mfs";
339 * Ignore the -a flag if this kernel isn't compiled
340 * with a generic root/swap configuration: if we skip
341 * setroot() and we aren't a generic kernel, chaos
342 * will ensue because setconf() will be a no-op.
343 * (rootdev is always initialized to NODEV in a
344 * generic configuration, so we test for that.)
346 if ((boothowto & RB_ASKNAME) == 0 || rootdev != NODEV)
348 } else if (bootverbose)
349 printf("No MFS image available as root f/s.\n");
354 if (!mountrootfsname && !nfs_diskless_valid) {
356 printf("Considering BOOTP NFS root f/s.\n");
357 mountrootfsname = "nfs";
359 #endif /* BOOTP_NFSROOT */
360 #if defined(NFS) || defined(NFS_ROOT)
361 if (!mountrootfsname && nfs_diskless_valid) {
363 printf("Considering NFS root f/s.\n");
364 mountrootfsname = "nfs";
368 #if defined(FFS) || defined(FFS_ROOT)
369 if (!mountrootfsname) {
370 mountrootfsname = "ufs";
372 printf("Considering FFS root f/s.\n");
374 * Ignore the -a flag if this kernel isn't compiled
375 * with a generic root/swap configuration: if we skip
376 * setroot() and we aren't a generic kernel, chaos
377 * will ensue because setconf() will be a no-op.
378 * (rootdev is always initialized to NODEV in a
379 * generic configuration, so we test for that.)
381 if ((boothowto & RB_ASKNAME) == 0 || rootdev != NODEV)
386 if (!mountrootfsname) {
387 panic("Nobody wants to mount my root for me");
397 if (setdumpdev(dumpdev) != 0)
413 if (maj >= nblkdev || bdevsw[maj] == NULL)
414 return (ENXIO); /* XXX is this right? */
415 if (bdevsw[maj]->d_psize == NULL)
416 return (ENXIO); /* XXX should be ENODEV ? */
417 psize = bdevsw[maj]->d_psize(dev);
419 return (ENXIO); /* XXX should be ENODEV ? */
421 * XXX should clean up checking in dumpsys() to be more like this,
422 * and nuke dodump sysctl (too many knobs), and move this to
425 newdumplo = psize - Maxmem * PAGE_SIZE / DEV_BSIZE;
434 u_long bootdev = 0; /* not a dev_t - encoding is different */
437 #define FDUNITSHIFT 6
440 * Attempt to find the device from which we were booted.
441 * If we can do so, and not instructed not to do so,
442 * set rootdevs[] and rootdevnames[] to correspond to the
448 int majdev, mindev, unit, slice, part;
453 if (boothowto & RB_DFLTROOT || (bootdev & B_MAGICMASK) != B_DEVMAGIC)
455 majdev = B_TYPE(bootdev);
456 if (majdev >= nblkdev || bdevsw[majdev] == NULL)
458 unit = B_UNIT(bootdev);
459 slice = B_SLICE(bootdev);
460 if (slice == WHOLE_DISK_SLICE)
461 slice = COMPATIBILITY_SLICE;
462 if (slice < 0 || slice >= MAX_SLICES)
466 * XXX kludge for inconsistent unit numbering and lack of slice
467 * support for floppies.
469 if (majdev == FDMAJOR) {
470 slice = COMPATIBILITY_SLICE;
472 mindev = unit << FDUNITSHIFT;
474 part = B_PARTITION(bootdev);
475 mindev = dkmakeminor(unit, slice, part);
478 newrootdev = makedev(majdev, mindev);
479 rootdevs[0] = newrootdev;
480 sname = dsname(bdevsw[majdev]->d_name, unit, slice, part, partname);
481 rootdevnames[0] = malloc(strlen(sname) + 2, M_DEVBUF, M_NOWAIT);
482 sprintf(rootdevnames[0], "%s%s", sname, partname);
485 * For properly dangerously dedicated disks (ones with a historical
486 * bogus partition table), the boot blocks will give slice = 4, but
487 * the kernel will only provide the compatibility slice since it
488 * knows that slice 4 is not a real slice. Arrange to try mounting
489 * the compatibility slice as root if mounting the slice passed by
490 * the boot blocks fails. This handles the dangerously dedicated
491 * case and perhaps others.
493 if (slice == COMPATIBILITY_SLICE)
495 slice = COMPATIBILITY_SLICE;
496 rootdevs[1] = dkmodslice(newrootdev, slice);
497 sname = dsname(bdevsw[majdev]->d_name, unit, slice, part, partname);
498 rootdevnames[1] = malloc(strlen(sname) + 2, M_DEVBUF, M_NOWAIT);
499 sprintf(rootdevnames[1], "%s%s", sname, partname);
504 sysctl_kern_dumpdev SYSCTL_HANDLER_ARGS
510 error = sysctl_handle_opaque(oidp, &ndumpdev, sizeof ndumpdev, req);
511 if (error == 0 && req->newptr != NULL)
512 error = setdumpdev(ndumpdev);
516 SYSCTL_PROC(_kern, KERN_DUMPDEV, dumpdev, CTLTYPE_OPAQUE|CTLFLAG_RW,
517 0, sizeof dumpdev, sysctl_kern_dumpdev, "T,dev_t", "");