1 /* $NetBSD: autoconf.c,v 1.6 2002/05/16 02:50:54 thorpej Exp $ */ 2 3 /* 4 * Copyright (c) 1988 University of Utah. 5 * Copyright (c) 1992, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * the Systems Programming Group of the University of Utah Computer 10 * Science Department and Ralph Campbell. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 3. All advertising materials mentioning features or use of this software 21 * must display the following acknowledgement: 22 * This product includes software developed by the University of 23 * California, Berkeley and its contributors. 24 * 4. Neither the name of the University nor the names of its contributors 25 * may be used to endorse or promote products derived from this software 26 * without specific prior written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 38 * SUCH DAMAGE. 39 * 40 * from: Utah Hdr: autoconf.c 1.31 91/01/21 41 * 42 * @(#)autoconf.c 8.1 (Berkeley) 6/10/93 43 */ 44 45 /* 46 * Setup the system to run on the current machine. 47 * 48 * Configure() is called at boot time. Available 49 * devices are determined (from possibilities mentioned in ioconf.c), 50 * and the drivers are initialized. 51 */ 52 53 /* 54 * autoconf.c for news68k - from newsmips 55 */ 56 57 #include <sys/param.h> 58 #include <sys/systm.h> 59 #include <sys/conf.h> 60 #include <sys/reboot.h> 61 #include <sys/device.h> 62 63 #include <dev/scsipi/scsipi_all.h> 64 #include <dev/scsipi/scsiconf.h> 65 66 #include <machine/cpu.h> 67 #include <machine/romcall.h> 68 #include <machine/autoconf.h> 69 70 /* 71 * The following several variables are related to 72 * the configuration process, and are used in initializing 73 * the machine. 74 */ 75 76 struct device *booted_device; 77 int booted_partition; 78 79 static void findroot __P((void)); 80 81 /* 82 * Determine mass storage and memory configuration for a machine. 83 * Print cpu type, and then iterate over an array of devices 84 * found on the baseboard or in turbochannel option slots. 85 * Once devices are configured, enable interrupts, and probe 86 * for attached scsi devices. 87 */ 88 void 89 cpu_configure() 90 { 91 /* 92 * Kick off autoconfiguration 93 */ 94 (void) splhigh(); 95 96 init_sir(); 97 98 if (config_rootfound("mainbus", NULL) == NULL) 99 panic("autoconfig failed, no root"); 100 101 /* Turn on interrupts */ 102 (void) spl0(); 103 } 104 105 void 106 cpu_rootconf() 107 { 108 109 findroot(); 110 111 printf("boot device: %s\n", 112 booted_device ? booted_device->dv_xname : "<unknown>"); 113 114 setroot(booted_device, booted_partition); 115 } 116 117 u_long bootdev = 0; /* should be dev_t, but not until 32 bits */ 118 119 /* 120 * Attempt to find the device from which we were booted. 121 */ 122 void 123 findroot(void) 124 { 125 int ctlr, unit, part, type; 126 struct device *dv; 127 128 if (BOOTDEV_MAG(bootdev) != 5) /* NEWS-OS's B_DEVMAGIC */ 129 return; 130 131 ctlr = BOOTDEV_CTLR(bootdev); /* SCSI ID */ 132 unit = BOOTDEV_UNIT(bootdev); 133 part = BOOTDEV_PART(bootdev); /* LUN */ 134 type = BOOTDEV_TYPE(bootdev); 135 136 if (type != BOOTDEV_SD) 137 return; 138 139 /* 140 * XXX assumes only one controller exists. 141 */ 142 for (dv = alldevs.tqh_first; dv; dv=dv->dv_list.tqe_next) { 143 if (strcmp(dv->dv_xname, "scsibus0") == 0) { 144 struct scsibus_softc *sdv = (void *)dv; 145 struct scsipi_periph *periph; 146 147 periph = scsipi_lookup_periph(sdv->sc_channel, 148 ctlr, 0); 149 if (periph == NULL) 150 continue; 151 152 booted_device = periph->periph_dev; 153 booted_partition = part; 154 return; 155 } 156 } 157 } 158