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.102 1998/07/19 11:12:14 jkh 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_devfs.h" /* for SLICE */
49 #include "opt_bootp.h"
51 #include "opt_cd9660.h"
53 #include "opt_nfsroot.h"
55 #include <sys/param.h>
56 #include <sys/systm.h>
58 #include <sys/disklabel.h>
59 #include <sys/diskslice.h>
60 #include <sys/reboot.h>
61 #include <sys/kernel.h>
62 #include <sys/malloc.h>
63 #include <sys/mount.h>
64 #include <sys/sysctl.h>
66 #include <machine/bootinfo.h>
67 #include <machine/cons.h>
68 #include <machine/ipl.h>
69 #include <machine/md_var.h>
71 #include <machine/smp.h>
74 #include <i386/isa/icu.h>
78 #include <i386/isa/isa_device.h>
83 #include <i386/isa/pnp.h>
88 #include <i386/eisa/eisaconf.h>
93 #include <pci/pcivar.h>
98 #include <pccard/driver.h>
103 #include <scsi/scsiconf.h>
106 static void configure __P((void *));
107 SYSINIT(configure, SI_SUB_CONFIGURE, SI_ORDER_FIRST, configure, NULL)
109 static void configure_finish __P((void));
110 static void configure_start __P((void));
111 static int setdumpdev __P((dev_t dev));
113 static void setroot __P((void));
117 #include <sys/fcntl.h>
118 #include <sys/proc.h>
119 #include <sys/stat.h>
120 #include <machine/clock.h>
123 * XXX All this CD-ROM root stuff is fairly messy. Ick.
125 * We need to try out all our potential CDROM drives, so we need a table.
139 static int find_cdrom_root __P((void));
148 #if CD9660_ROOTDELAY > 0
149 DELAY(CD9660_ROOTDELAY * 1000000);
152 for (i = 0 ; i < 2; i++)
153 for (j = 0 ; try_cdrom[j].name ; j++) {
154 if (try_cdrom[j].major >= nblkdev)
156 rootdev = makedev(try_cdrom[j].major, i * 8);
157 bd = bdevsw[major(rootdev)];
158 if (bd == NULL || bd->d_open == NULL)
161 printf("trying %s%d as rootdev (0x%x)\n",
162 try_cdrom[j].name, i, rootdev);
163 error = (bd->d_open)(rootdev, FREAD, S_IFBLK, curproc);
165 if (bd->d_close != NULL)
166 (bd->d_close)(rootdev, FREAD, S_IFBLK,
182 scsi_configure_start();
190 scsi_configure_finish();
195 * Determine i/o configuration for a machine.
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();
244 * Now we're ready to handle (pending) interrupts.
245 * XXX this is slightly misplaced.
250 * Allow lowering of the ipl to the lowest kernel level if we
251 * panic (or call tsleep() before clearing `cold'). No level is
252 * completely safe (since a panic may occur in a critical region
253 * at splhigh()), but we want at least bio interrupts to work.
258 /* After everyone else has a chance at grabbing resources */
273 * Print out the BIOS's idea of the disk geometries.
275 printf("BIOS Geometries:\n");
276 for (i = 0; i < N_BIOS_GEOM; i++) {
277 unsigned long bios_geom;
278 int max_cylinder, max_head, max_sector;
280 bios_geom = bootinfo.bi_bios_geom[i];
283 * XXX the bootstrap punts a 1200K floppy geometry
284 * when the get-disk-geometry interrupt fails. Skip
285 * drives that have this geometry.
287 if (bios_geom == 0x4f010f)
290 printf(" %x:%08lx ", i, bios_geom);
291 max_cylinder = bios_geom >> 16;
292 max_head = (bios_geom >> 8) & 0xff;
293 max_sector = bios_geom & 0xff;
295 "0..%d=%d cylinders, 0..%d=%d heads, 1..%d=%d sectors\n",
296 max_cylinder, max_cylinder + 1,
297 max_head, max_head + 1,
298 max_sector, max_sector);
300 printf(" %d accounted for\n", bootinfo.bi_n_bios_used);
302 printf("Device configuration finished.\n");
313 * XXX NetBSD has a much cleaner approach to finding root.
314 * XXX We should adopt their code.
316 #if defined(CD9660) || defined(CD9660_ROOT)
317 if ((boothowto & RB_CDROM)) {
319 printf("Considering CD-ROM root f/s.\n");
320 /* NB: find_cdrom_root() sets rootdev if successful. */
321 if (find_cdrom_root() == 0)
322 mountrootfsname = "cd9660";
323 else if (bootverbose)
324 printf("No CD-ROM available as root f/s.\n");
329 if (!mountrootfsname) {
331 printf("Considering MFS root f/s.\n");
332 mountrootfsname = "mfs";
334 * Ignore the -a flag if this kernel isn't compiled
335 * with a generic root/swap configuration: if we skip
336 * setroot() and we aren't a generic kernel, chaos
337 * will ensue because setconf() will be a no-op.
338 * (rootdev is always initialized to NODEV in a
339 * generic configuration, so we test for that.)
341 if ((boothowto & RB_ASKNAME) == 0 || rootdev != NODEV)
347 if (!mountrootfsname && !nfs_diskless_valid) {
349 printf("Considering BOOTP NFS root f/s.\n");
350 mountrootfsname = "nfs";
352 #endif /* BOOTP_NFSROOT */
353 #if defined(NFS) || defined(NFS_ROOT)
354 if (!mountrootfsname && nfs_diskless_valid) {
356 printf("Considering NFS root f/s.\n");
357 mountrootfsname = "nfs";
361 #if defined(FFS) || defined(FFS_ROOT)
362 if (!mountrootfsname) {
363 mountrootfsname = "ufs";
365 printf("Considering FFS root f/s.\n");
367 * Ignore the -a flag if this kernel isn't compiled
368 * with a generic root/swap configuration: if we skip
369 * setroot() and we aren't a generic kernel, chaos
370 * will ensue because setconf() will be a no-op.
371 * (rootdev is always initialized to NODEV in a
372 * generic configuration, so we test for that.)
374 if ((boothowto & RB_ASKNAME) == 0 || rootdev != NODEV)
379 if (!mountrootfsname) {
380 panic("Nobody wants to mount my root for me");
391 if (setdumpdev(dumpdev) != 0)
409 if (bdevsw[maj] == NULL)
410 return (ENXIO); /* XXX is this right? */
411 if (bdevsw[maj]->d_psize == NULL)
412 return (ENXIO); /* XXX should be ENODEV ? */
413 psize = bdevsw[maj]->d_psize(dev);
415 return (ENXIO); /* XXX should be ENODEV ? */
417 * XXX should clean up checking in dumpsys() to be more like this,
418 * and nuke dodump sysctl (too many knobs), and move this to
421 newdumplo = psize - Maxmem * PAGE_SIZE / DEV_BSIZE;
431 u_long bootdev = 0; /* not a dev_t - encoding is different */
434 #define FDUNITSHIFT 6
437 * Attempt to find the device from which we were booted.
438 * If we can do so, and not instructed not to do so,
439 * set rootdevs[] and rootdevnames[] to correspond to the
445 int majdev, mindev, unit, slice, part;
450 if (boothowto & RB_DFLTROOT || (bootdev & B_MAGICMASK) != B_DEVMAGIC)
452 majdev = B_TYPE(bootdev);
453 if (bdevsw[majdev] == NULL)
455 unit = B_UNIT(bootdev);
456 slice = B_SLICE(bootdev);
457 if (slice == WHOLE_DISK_SLICE)
458 slice = COMPATIBILITY_SLICE;
459 if (slice < 0 || slice >= MAX_SLICES)
463 * XXX kludge for inconsistent unit numbering and lack of slice
464 * support for floppies.
466 if (majdev == FDMAJOR) {
467 slice = COMPATIBILITY_SLICE;
469 mindev = unit << FDUNITSHIFT;
471 part = B_PARTITION(bootdev);
472 mindev = dkmakeminor(unit, slice, part);
475 newrootdev = makedev(majdev, mindev);
476 rootdevs[0] = newrootdev;
477 sname = dsname(bdevsw[majdev]->d_name, unit, slice, part, partname);
478 rootdevnames[0] = malloc(strlen(sname) + 2, M_DEVBUF, M_NOWAIT);
479 sprintf(rootdevnames[0], "%s%s", sname, partname);
482 * For properly dangerously dedicated disks (ones with a historical
483 * bogus partition table), the boot blocks will give slice = 4, but
484 * the kernel will only provide the compatibility slice since it
485 * knows that slice 4 is not a real slice. Arrange to try mounting
486 * the compatibility slice as root if mounting the slice passed by
487 * the boot blocks fails. This handles the dangerously dedicated
488 * case and perhaps others.
490 if (slice == COMPATIBILITY_SLICE)
492 slice = COMPATIBILITY_SLICE;
493 rootdevs[1] = dkmodslice(newrootdev, slice);
494 sname = dsname(bdevsw[majdev]->d_name, unit, slice, part, partname);
495 rootdevnames[1] = malloc(strlen(sname) + 2, M_DEVBUF, M_NOWAIT);
496 sprintf(rootdevnames[1], "%s%s", sname, partname);
502 sysctl_kern_dumpdev SYSCTL_HANDLER_ARGS
508 error = sysctl_handle_opaque(oidp, &ndumpdev, sizeof ndumpdev, req);
509 if (error == 0 && req->newptr != NULL)
510 error = setdumpdev(ndumpdev);
514 SYSCTL_PROC(_kern, KERN_DUMPDEV, dumpdev, CTLTYPE_OPAQUE|CTLFLAG_RW,
515 0, sizeof dumpdev, sysctl_kern_dumpdev, "T,dev_t", "");