1 /* $NetBSD: autoconf.c,v 1.24 2017/06/22 16:46:53 flxd 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. 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. 23 * 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 34 * SUCH DAMAGE. 35 * 36 * from: Utah Hdr: autoconf.c 1.31 91/01/21 37 * 38 * @(#)autoconf.c 8.1 (Berkeley) 6/10/93 39 */ 40 41 /* 42 * Setup the system to run on the current machine. 43 * 44 * Configure() is called at boot time. Available 45 * devices are determined (from possibilities mentioned in ioconf.c), 46 * and the drivers are initialized. 47 */ 48 49 /* 50 * autoconf.c for news68k - from newsmips 51 */ 52 53 #include <sys/cdefs.h> 54 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.24 2017/06/22 16:46:53 flxd Exp $"); 55 56 #include "scsibus.h" 57 58 #include <sys/param.h> 59 #include <sys/systm.h> 60 #include <sys/conf.h> 61 #include <sys/reboot.h> 62 #include <sys/device.h> 63 64 #include <dev/scsipi/scsipi_all.h> 65 #include <dev/scsipi/scsiconf.h> 66 67 #include <machine/cpu.h> 68 #include <machine/romcall.h> 69 #include <machine/autoconf.h> 70 71 #include <news68k/news68k/isr.h> 72 73 /* 74 * The following several variables are related to 75 * the configuration process, and are used in initializing 76 * the machine. 77 */ 78 79 static void findroot(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(void) 90 { 91 /* 92 * Kick off autoconfiguration 93 */ 94 (void) splhigh(); 95 96 /* Initialize the interrupt handlers. */ 97 isrinit(); 98 99 if (config_rootfound("mainbus", NULL) == NULL) 100 panic("autoconfig failed, no root"); 101 102 /* Turn on interrupts */ 103 (void) spl0(); 104 } 105 106 void 107 cpu_rootconf(void) 108 { 109 110 findroot(); 111 112 printf("boot device: %s\n", 113 booted_device ? device_xname(booted_device) : "<unknown>"); 114 115 rootconf(); 116 } 117 118 u_long bootdev = 0; /* should be dev_t, but not until 32 bits */ 119 120 /* 121 * Attempt to find the device from which we were booted. 122 */ 123 void 124 findroot(void) 125 { 126 #if NSCSIBUS > 0 127 int ctlr, part, type; 128 device_t dv; 129 130 if (BOOTDEV_MAG(bootdev) != 5) /* NEWS-OS's B_DEVMAGIC */ 131 return; 132 133 ctlr = BOOTDEV_CTLR(bootdev); /* SCSI ID */ 134 part = BOOTDEV_PART(bootdev); /* LUN */ 135 type = BOOTDEV_TYPE(bootdev); 136 137 if (type != BOOTDEV_SD) 138 return; 139 140 /* 141 * XXX assumes only one controller exists. 142 */ 143 if ((dv = device_find_by_xname("scsibus0")) != NULL) { 144 struct scsibus_softc *sdv = device_private(dv); 145 struct scsipi_periph *periph; 146 147 periph = scsipi_lookup_periph(sdv->sc_channel, ctlr, 0); 148 if (periph != NULL) { 149 booted_device = periph->periph_dev; 150 booted_partition = part; 151 } 152 } 153 #endif 154 } 155