1 /* $NetBSD: autoconf.c,v 1.25 2025/11/29 23:12:26 tsutsui 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.25 2025/11/29 23:12:26 tsutsui 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 if (config_rootfound("mainbus", NULL) == NULL) 97 panic("autoconfig failed, no root"); 98 99 /* Turn on interrupts */ 100 (void) spl0(); 101 } 102 103 void 104 cpu_rootconf(void) 105 { 106 107 findroot(); 108 109 printf("boot device: %s\n", 110 booted_device ? device_xname(booted_device) : "<unknown>"); 111 112 rootconf(); 113 } 114 115 u_long bootdev = 0; /* should be dev_t, but not until 32 bits */ 116 117 /* 118 * Attempt to find the device from which we were booted. 119 */ 120 void 121 findroot(void) 122 { 123 #if NSCSIBUS > 0 124 int ctlr, part, type; 125 device_t dv; 126 127 if (BOOTDEV_MAG(bootdev) != 5) /* NEWS-OS's B_DEVMAGIC */ 128 return; 129 130 ctlr = BOOTDEV_CTLR(bootdev); /* SCSI ID */ 131 part = BOOTDEV_PART(bootdev); /* LUN */ 132 type = BOOTDEV_TYPE(bootdev); 133 134 if (type != BOOTDEV_SD) 135 return; 136 137 /* 138 * XXX assumes only one controller exists. 139 */ 140 if ((dv = device_find_by_xname("scsibus0")) != NULL) { 141 struct scsibus_softc *sdv = device_private(dv); 142 struct scsipi_periph *periph; 143 144 periph = scsipi_lookup_periph(sdv->sc_channel, ctlr, 0); 145 if (periph != NULL) { 146 booted_device = periph->periph_dev; 147 booted_partition = part; 148 } 149 } 150 #endif 151 } 152