1/* $OpenBSD: autoconf.c,v 1.39 2022/09/02 20:06:55 miod Exp $ */ 2/* $NetBSD: autoconf.c,v 1.16 1996/11/13 21:13:04 cgd Exp $ */ 3 4/* 5 * Copyright (c) 1992, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * This software was developed by the Computer Systems Engineering group 9 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 10 * contributed to Berkeley. 11 * 12 * All advertising materials mentioning features or use of this software 13 * must display the following acknowledgement: 14 * This product includes software developed by the University of 15 * California, Lawrence Berkeley Laboratory. 16 * 17 * Redistribution and use in source and binary forms, with or without 18 * modification, are permitted provided that the following conditions 19 * are met: 20 * 1. Redistributions of source code must retain the above copyright 21 * notice, this list of conditions and the following disclaimer. 22 * 2. Redistributions in binary form must reproduce the above copyright 23 * notice, this list of conditions and the following disclaimer in the 24 * documentation and/or other materials provided with the distribution. 25 * 3. Neither the name of the University nor the names of its contributors 26 * may be used to endorse or promote products derived from this software 27 * without specific prior written permission. 28 * 29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 39 * SUCH DAMAGE. 40 * 41 * @(#)autoconf.c 8.4 (Berkeley) 10/1/93 42 */ 43 44#include <sys/param.h> 45#include <sys/systm.h> 46#include <sys/buf.h> 47#include <sys/disklabel.h> 48#include <sys/conf.h> 49#include <sys/reboot.h> 50#include <sys/device.h> 51 52#include <uvm/uvm_extern.h> 53 54#include <machine/autoconf.h> 55#include <machine/rpb.h> 56#include <machine/prom.h> 57#include <machine/cpuconf.h> 58#include <machine/intr.h> 59 60#include <dev/cons.h> 61 62struct device *booted_device; 63int booted_partition; 64struct bootdev_data *bootdev_data; 65char boot_dev[128]; 66 67void parse_prom_bootdev(void); 68int atoi(char *); 69 70void 71unmap_startup(void) 72{ 73 extern uint32_t kernel_text[], endboot[]; 74 uint32_t *word = kernel_text; 75 76 /* Cannot unmap KSEG0; smash with 0x00000000 (call_pall PAL_halt) */ 77 while (word < endboot) 78 *word++ = 0x00000000; 79} 80 81/* 82 * cpu_configure: 83 * called at boot time, configure all devices on system 84 */ 85void 86cpu_configure() 87{ 88 parse_prom_bootdev(); 89 softintr_init(); 90 91 unmap_startup(); 92 93 /* 94 * Disable interrupts during autoconfiguration. splhigh() won't 95 * work, because it simply _raises_ the IPL, so if machine checks 96 * are disabled, they'll stay disabled. Machine checks are needed 97 * during autoconfig. 98 */ 99 (void)alpha_pal_swpipl(ALPHA_PSL_IPL_HIGH); 100 if (config_rootfound("mainbus", "mainbus") == NULL) 101 panic("no mainbus found"); 102 (void)spl0(); 103 104 hwrpb_restart_setup(); 105 cold = 0; 106} 107 108void 109diskconf(void) 110{ 111 struct device *bootdv; 112 int bootpartition; 113 114 if (booted_device == NULL) 115 printf("WARNING: can't figure what device matches \"%s\"\n", 116 boot_dev); 117 bootdv = booted_device; 118 bootpartition = booted_partition; 119 120 setroot(bootdv, bootpartition, RB_USERREQ); 121 dumpconf(); 122} 123 124void 125parse_prom_bootdev() 126{ 127 static struct bootdev_data bd; 128 char *cp, *scp, *boot_fields[8]; 129 int i, done; 130 131 booted_device = NULL; 132 booted_partition = 0; 133 bootdev_data = NULL; 134 135 bcopy(bootinfo.booted_dev, boot_dev, sizeof bootinfo.booted_dev); 136#if 0 137 printf("parse_prom_bootdev: boot dev = \"%s\"\n", boot_dev); 138#endif 139 140 i = 0; 141 scp = cp = boot_dev; 142 for (done = 0; !done; cp++) { 143 if (*cp != ' ' && *cp != '\0') 144 continue; 145 if (*cp == '\0') 146 done = 1; 147 148 *cp = '\0'; 149 boot_fields[i++] = scp; 150 scp = cp + 1; 151 if (i == 8) 152 done = 1; 153 } 154 if (i != 8) 155 return; /* doesn't look like anything we know! */ 156 157#if 0 158 printf("i = %d, done = %d\n", i, done); 159 for (i--; i >= 0; i--) 160 printf("%d = %s\n", i, boot_fields[i]); 161#endif 162 163 bd.protocol = boot_fields[0]; 164 bd.bus = atoi(boot_fields[1]); 165 bd.slot = atoi(boot_fields[2]); 166 bd.channel = atoi(boot_fields[3]); 167 bd.remote_address = boot_fields[4]; 168 bd.unit = atoi(boot_fields[5]); 169 bd.boot_dev_type = atoi(boot_fields[6]); 170 bd.ctrl_dev_type = boot_fields[7]; 171 172#if 0 173 printf("parsed: proto = %s, bus = %d, slot = %d, channel = %d,\n", 174 bd.protocol, bd.bus, bd.slot, bd.channel); 175 printf("\tremote = %s, unit = %d, dev_type = %d, ctrl_type = %s\n", 176 bd.remote_address, bd.unit, bd.boot_dev_type, bd.ctrl_dev_type); 177#endif 178 179 bootdev_data = &bd; 180} 181 182int 183atoi(s) 184 char *s; 185{ 186 int n, neg; 187 188 n = 0; 189 neg = 0; 190 191 while (*s == '-') { 192 s++; 193 neg = !neg; 194 } 195 196 while (*s != '\0') { 197 if (*s < '0' || *s > '9') 198 break; 199 200 n = (10 * n) + (*s - '0'); 201 s++; 202 } 203 204 return (neg ? -n : n); 205} 206 207void 208device_register(dev, aux) 209 struct device *dev; 210 void *aux; 211{ 212 if (bootdev_data == NULL) { 213 /* 214 * There is no hope. 215 */ 216 return; 217 } 218 219 if (platform.device_register) 220 (*platform.device_register)(dev, aux); 221} 222 223const struct nam2blk nam2blk[] = { 224 { "wd", 0 }, 225 { "cd", 3 }, 226 { "fd", 4 }, 227 { "rd", 6 }, 228 { "sd", 8 }, 229 { "vnd", 9 }, 230 { NULL, -1 } 231}; 232