1/* $NetBSD$ */ 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#define __INTR_PRIVATE 50#include <sys/cdefs.h> 51__KERNEL_RCSID(0, "$NetBSD$"); 52 53#include <sys/param.h> 54#include <sys/systm.h> 55#include <sys/buf.h> 56#include <sys/conf.h> 57#include <sys/reboot.h> 58#include <sys/device.h> 59 60#include <dev/scsipi/scsi_all.h> 61#include <dev/scsipi/scsipi_all.h> 62#include <dev/scsipi/scsiconf.h> 63 64#include <machine/cpu.h> 65#include <machine/mainboard.h> 66#include <machine/autoconf.h> 67 68/* 69 * The following several variables are related to 70 * the configuration process, and are used in initializing 71 * the machine. 72 */ 73int cpuspeed = 25; /* approx # instr per usec. */ 74 75extern int initcpu(void); /*XXX*/ 76 77void findroot(device_t *, int *); 78 79struct mipsco_intrhand intrtab[MAX_INTR_COOKIES]; 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 */ 88void 89cpu_configure(void) 90{ 91 int s; 92 93 /* 94 * Kick off autoconfiguration 95 */ 96 s = splhigh(); 97 if (config_rootfound("mainbus", NULL) == NULL) 98 panic("no mainbus found"); 99 initcpu(); 100} 101 102void 103cpu_rootconf(void) 104{ 105 findroot(&booted_device, &booted_partition); 106 107 printf("boot device: %s\n", 108 booted_device ? booted_device->dv_xname : "<unknown>"); 109 rootconf(); 110} 111 112dev_t bootdev = 0; 113char boot_class; 114int boot_id, boot_lun, boot_part; 115 116/* 117 * Attempt to find the device from which we were booted. 118 */ 119void 120findroot(device_t *devpp, int *partp) 121{ 122 device_t dv; 123 deviter_t di; 124 125 for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST); 126 dv != NULL; 127 dv = deviter_next(&di)) { 128 if (device_class(dv) == boot_class && 129 /* XXX device_unit() abuse */ 130 device_unit(dv) == boot_id) 131 break; 132 } 133 deviter_release(&di); 134 if (dv != NULL) { 135 *devpp = dv; 136 *partp = boot_part; 137 return; 138 } 139 140 /* 141 * Default to "not found". 142 */ 143 *devpp = NULL; 144 *partp = 0; 145 return; 146} 147 148void 149makebootdev(char *cp) 150{ 151 boot_class = -1; 152 boot_id = boot_lun = boot_part = 0; 153 154 if (strlen(cp) < 6) 155 return; 156 if (strncmp(cp, "dk", 2) == 0 && cp[4] == '(') { /* Disk */ 157 cp += 5; 158 if (*cp >= '0' && *cp <= '9') 159 boot_lun = *cp++ - '0'; 160 if (*cp == ',') 161 cp += 1; 162 if (*cp >= '0' && *cp <= '9') 163 boot_id = *cp++ - '0'; 164 if (*cp == ',') 165 cp += 1; 166 if (*cp >= '0' && *cp <= '7') 167 boot_part = *cp - '0'; 168 boot_class = DV_DISK; 169 return; 170 } 171} 172