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.109 1998/10/10 08:12:22 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_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 #include <pccard/driver.h>
104 static void configure __P((void *));
105 SYSINIT(configure, SI_SUB_CONFIGURE, SI_ORDER_FIRST, configure, NULL)
107 static void configure_finish __P((void));
108 static void configure_start __P((void));
109 static int setdumpdev __P((dev_t dev));
110 static void setroot __P((void));
112 #if defined(CD9660) || defined(CD9660_ROOT)
114 #include <sys/fcntl.h>
115 #include <sys/proc.h>
116 #include <sys/stat.h>
117 #include <machine/clock.h>
120 * XXX All this CD-ROM root stuff is fairly messy. Ick.
122 * We need to try out all our potential CDROM drives, so we need a table.
136 static int find_cdrom_root __P((void));
145 #if CD9660_ROOTDELAY > 0
146 DELAY(CD9660_ROOTDELAY * 1000000);
149 for (i = 0 ; i < 2; i++)
150 for (j = 0 ; try_cdrom[j].name ; j++) {
151 if (try_cdrom[j].major >= nblkdev)
153 rootdev = makedev(try_cdrom[j].major, i * 8);
154 bd = bdevsw[major(rootdev)];
155 if (bd == NULL || bd->d_open == NULL)
158 printf("trying %s%d as rootdev (0x%x)\n",
159 try_cdrom[j].name, i, rootdev);
160 error = (bd->d_open)(rootdev, FREAD, S_IFBLK, curproc);
162 if (bd->d_close != NULL)
163 (bd->d_close)(rootdev, FREAD, S_IFBLK,
172 #endif /* CD9660 || CD9660_ROOT */
174 extern void xpt_init __P((void));
177 extern u_char *mfs_getimage __P((void));
194 * Determine i/o configuration for a machine.
204 /* Allow all routines to decide for themselves if they want intrs */
206 * XXX Since this cannot be achieved on all architectures, we should
207 * XXX go back to disabling all interrupts until configuration is
208 * XXX completed and switch any devices that rely on the current
209 * XXX behavior to no longer rely on interrupts or to register an
210 * XXX interrupt_driven_config_hook for the task.
213 * XXX The above is wrong, because we're implicitly at splhigh(),
214 * XXX and should stay there, so enabling interrupts in the CPU
215 * XXX and the ICU at most gives pending interrupts which just get
219 bsp_apic_configure();
242 /* initialize new bus architecture */
243 root_bus_configure();
246 * Now we're ready to handle (pending) interrupts.
247 * XXX this is slightly misplaced.
252 * Allow lowering of the ipl to the lowest kernel level if we
253 * panic (or call tsleep() before clearing `cold'). No level is
254 * completely safe (since a panic may occur in a critical region
255 * at splhigh()), but we want at least bio interrupts to work.
260 /* After everyone else has a chance at grabbing resources */
275 * Print out the BIOS's idea of the disk geometries.
277 printf("BIOS Geometries:\n");
278 for (i = 0; i < N_BIOS_GEOM; i++) {
279 unsigned long bios_geom;
280 int max_cylinder, max_head, max_sector;
282 bios_geom = bootinfo.bi_bios_geom[i];
285 * XXX the bootstrap punts a 1200K floppy geometry
286 * when the get-disk-geometry interrupt fails. Skip
287 * drives that have this geometry.
289 if (bios_geom == 0x4f010f)
292 printf(" %x:%08lx ", i, bios_geom);
293 max_cylinder = bios_geom >> 16;
294 max_head = (bios_geom >> 8) & 0xff;
295 max_sector = bios_geom & 0xff;
297 "0..%d=%d cylinders, 0..%d=%d heads, 1..%d=%d sectors\n",
298 max_cylinder, max_cylinder + 1,
299 max_head, max_head + 1,
300 max_sector, max_sector);
302 printf(" %d accounted for\n", bootinfo.bi_n_bios_used);
304 printf("Device configuration finished.\n");
314 * XXX NetBSD has a much cleaner approach to finding root.
315 * XXX We should adopt their code.
317 #if defined(CD9660) || defined(CD9660_ROOT)
318 if ((boothowto & RB_CDROM)) {
320 printf("Considering CD-ROM root f/s.\n");
321 /* NB: find_cdrom_root() sets rootdev if successful. */
322 if (find_cdrom_root() == 0)
323 mountrootfsname = "cd9660";
324 else if (bootverbose)
325 printf("No CD-ROM available as root f/s.\n");
330 if (!mountrootfsname) {
332 printf("Considering MFS root f/s.\n");
333 if (mfs_getimage()) {
334 mountrootfsname = "mfs";
336 * Ignore the -a flag if this kernel isn't compiled
337 * with a generic root/swap configuration: if we skip
338 * setroot() and we aren't a generic kernel, chaos
339 * will ensue because setconf() will be a no-op.
340 * (rootdev is always initialized to NODEV in a
341 * generic configuration, so we test for that.)
343 if ((boothowto & RB_ASKNAME) == 0 || rootdev != NODEV)
345 } else if (bootverbose)
346 printf("No MFS image available as root f/s.\n");
351 if (!mountrootfsname && !nfs_diskless_valid) {
353 printf("Considering BOOTP NFS root f/s.\n");
354 mountrootfsname = "nfs";
356 #endif /* BOOTP_NFSROOT */
357 #if defined(NFS) || defined(NFS_ROOT)
358 if (!mountrootfsname && nfs_diskless_valid) {
360 printf("Considering NFS root f/s.\n");
361 mountrootfsname = "nfs";
365 #if defined(FFS) || defined(FFS_ROOT)
366 if (!mountrootfsname) {
367 mountrootfsname = "ufs";
369 printf("Considering FFS root f/s.\n");
371 * Ignore the -a flag if this kernel isn't compiled
372 * with a generic root/swap configuration: if we skip
373 * setroot() and we aren't a generic kernel, chaos
374 * will ensue because setconf() will be a no-op.
375 * (rootdev is always initialized to NODEV in a
376 * generic configuration, so we test for that.)
378 if ((boothowto & RB_ASKNAME) == 0 || rootdev != NODEV)
383 if (!mountrootfsname) {
384 panic("Nobody wants to mount my root for me");
394 if (setdumpdev(dumpdev) != 0)
410 if (maj >= nblkdev || bdevsw[maj] == NULL)
411 return (ENXIO); /* XXX is this right? */
412 if (bdevsw[maj]->d_psize == NULL)
413 return (ENXIO); /* XXX should be ENODEV ? */
414 psize = bdevsw[maj]->d_psize(dev);
416 return (ENXIO); /* XXX should be ENODEV ? */
418 * XXX should clean up checking in dumpsys() to be more like this,
419 * and nuke dodump sysctl (too many knobs), and move this to
422 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 (majdev >= nblkdev || 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);
501 sysctl_kern_dumpdev SYSCTL_HANDLER_ARGS
507 error = sysctl_handle_opaque(oidp, &ndumpdev, sizeof ndumpdev, req);
508 if (error == 0 && req->newptr != NULL)
509 error = setdumpdev(ndumpdev);
513 SYSCTL_PROC(_kern, KERN_DUMPDEV, dumpdev, CTLTYPE_OPAQUE|CTLFLAG_RW,
514 0, sizeof dumpdev, sysctl_kern_dumpdev, "T,dev_t", "");