1 /* $NetBSD: autoconf.c,v 1.12 2002/01/31 17:56:33 uch 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 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 46 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.12 2002/01/31 17:56:33 uch Exp $"); 47 48 #include <sys/param.h> 49 #include <sys/systm.h> 50 #include <sys/conf.h> /* setroot() */ 51 52 #include <machine/disklabel.h> 53 54 #include <machine/sysconf.h> 55 #include <machine/config_hook.h> 56 57 void makebootdev(const char *); 58 59 struct device *booted_device; 60 int booted_partition; 61 static char __booted_device_name[16]; 62 static void get_device(const char *); 63 64 /* 65 * Setup the system to run on the current machine. 66 * 67 * cpu_configure() is called at boot time. Available 68 * devices are determined (from possibilities mentioned in ioconf.c), 69 * and the drivers are initialized. 70 */ 71 void 72 cpu_configure() 73 { 74 75 softintr_init(); 76 77 /* Kick off autoconfiguration. */ 78 (void)splhigh(); 79 80 config_hook_init(); 81 82 if (config_rootfound("mainbus", "mainbus") == NULL) 83 panic("no mainbus found"); 84 85 /* Configuration is finished, turn on interrupts. */ 86 _splnone(); /* enable all source forcing SOFT_INTs cleared */ 87 } 88 89 void 90 cpu_rootconf() 91 { 92 93 get_device(__booted_device_name); 94 95 printf("boot device: %s\n", 96 booted_device ? booted_device->dv_xname : "<unknown>"); 97 98 setroot(booted_device, booted_partition); 99 } 100 101 void 102 makebootdev(const char *cp) 103 { 104 105 strncpy(__booted_device_name, cp, 16); 106 } 107 108 static void 109 get_device(const char *name) 110 { 111 int loop, unit, part; 112 char buf[32]; 113 const char *cp; 114 struct device *dv; 115 116 if (strncmp(name, "/dev/", 5) == 0) 117 name += 5; 118 119 for (loop = 0; dev_name2blk[loop].d_name != NULL; ++loop) { 120 if (strncmp(name, dev_name2blk[loop].d_name, 121 strlen(dev_name2blk[loop].d_name)) == 0) { 122 name += strlen(dev_name2blk[loop].d_name); 123 unit = part = 0; 124 125 cp = name; 126 while (*cp >= '0' && *cp <= '9') 127 unit = (unit * 10) + (*cp++ - '0'); 128 if (cp == name) 129 return; 130 131 if (*cp >= 'a' && *cp <= ('a' + MAXPARTITIONS)) 132 part = *cp - 'a'; 133 else if (*cp != '\0' && *cp != ' ') 134 return; 135 sprintf(buf, "%s%d", dev_name2blk[loop].d_name, unit); 136 for (dv = alldevs.tqh_first; dv != NULL; 137 dv = dv->dv_list.tqe_next) { 138 if (strcmp(buf, dv->dv_xname) == 0) { 139 booted_device = dv; 140 booted_partition = part; 141 return; 142 } 143 } 144 } 145 } 146 } 147