1 /* $NetBSD: autoconf.c,v 1.1 2002/02/10 01:58:01 thorpej Exp $ */ 2 3 /* 4 * Copyright (c) 1994-1998 Mark Brinicombe. 5 * Copyright (c) 1994 Brini. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by Mark Brinicombe for 19 * the NetBSD project. 20 * 4. The name of the company nor the name of the author may be used to 21 * endorse or promote products derived from this software without specific 22 * prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 25 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 27 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 28 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 * 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 * RiscBSD kernel project 37 * 38 * autoconf.c 39 * 40 * Autoconfiguration functions 41 * 42 * Created : 08/10/94 43 */ 44 45 #include "opt_md.h" 46 47 #include <sys/param.h> 48 #include <sys/systm.h> 49 #include <sys/reboot.h> 50 #include <sys/disklabel.h> 51 #include <sys/device.h> 52 #include <sys/conf.h> 53 #include <sys/kernel.h> 54 #include <sys/malloc.h> 55 #include <machine/bootconfig.h> 56 #include <machine/intr.h> 57 58 #include "isa.h" 59 60 #ifdef SHARK 61 #include <shark/shark/sequoia.h> 62 extern void ofrootfound __P((void)); 63 extern void ofw_device_register __P((struct device *, void *aux)); 64 extern void startrtclock __P((void)); 65 #endif 66 67 #if defined(OFWGENCFG) || defined(SHARK) 68 /* Temporary for SHARK! */ 69 extern void ofw_device_register(struct device *dev, void *aux); 70 #include <machine/ofw.h> 71 #endif 72 73 struct device *booted_device; 74 int booted_partition; 75 76 extern dev_t dumpdev; 77 78 void dumpconf __P((void)); 79 void isa_intr_init __P((void)); 80 81 #ifndef MEMORY_DISK_IS_ROOT 82 static void get_device __P((char *name)); 83 static void set_root_device __P((void)); 84 #endif 85 86 #ifndef MEMORY_DISK_IS_ROOT 87 /* Decode a device name to a major and minor number */ 88 89 static void 90 get_device(name) 91 char *name; 92 { 93 int loop, unit, part; 94 char buf[32], *cp; 95 struct device *dv; 96 97 if (strncmp(name, "/dev/", 5) == 0) 98 name += 5; 99 100 for (loop = 0; dev_name2blk[loop].d_name != NULL; ++loop) { 101 if (strncmp(name, dev_name2blk[loop].d_name, 102 strlen(dev_name2blk[loop].d_name)) == 0) { 103 name += strlen(dev_name2blk[loop].d_name); 104 unit = part = 0; 105 106 cp = name; 107 while (*cp >= '0' && *cp <= '9') 108 unit = (unit * 10) + (*cp++ - '0'); 109 if (cp == name) 110 return; 111 112 if (*cp >= 'a' && *cp <= ('a' + MAXPARTITIONS)) 113 part = *cp - 'a'; 114 else if (*cp != '\0' && *cp != ' ') 115 return; 116 sprintf(buf, "%s%d", dev_name2blk[loop].d_name, unit); 117 for (dv = alldevs.tqh_first; dv != NULL; 118 dv = dv->dv_list.tqe_next) { 119 if (strcmp(buf, dv->dv_xname) == 0) { 120 booted_device = dv; 121 booted_partition = part; 122 return; 123 } 124 } 125 } 126 } 127 } 128 129 130 /* Set the rootdev variable from the root specifier in the boot args */ 131 132 static void 133 set_root_device() 134 { 135 char *ptr; 136 137 if (boot_file) 138 get_device(boot_file); 139 if (boot_args && 140 get_bootconf_option(boot_args, "root", BOOTOPT_TYPE_STRING, &ptr)) 141 get_device(ptr); 142 } 143 #endif 144 145 /* 146 * Set up the root device from the boot args 147 */ 148 void 149 cpu_rootconf() 150 { 151 #ifndef MEMORY_DISK_IS_ROOT 152 set_root_device(); 153 154 printf("boot device: %s\n", 155 booted_device != NULL ? booted_device->dv_xname : "<unknown>"); 156 #endif 157 setroot(booted_device, booted_partition); 158 } 159 160 161 /* 162 * void cpu_configure() 163 * 164 * Configure all the root devices 165 * The root devices are expected to configure their own children 166 */ 167 168 void 169 cpu_configure() 170 { 171 /* 172 * Configure all the roots. 173 * We have to have a mainbus 174 */ 175 176 #ifdef SHARK 177 sequoiaInit(); 178 startrtclock(); 179 #endif 180 181 /* 182 * Since the ICU is not standard on the ARM we don't know 183 * if we have one until we find a bridge. 184 * Since various PCI interrupts could be routed via the ICU 185 * (for PCI devices in the bridge) we need to set up the ICU 186 * now so that these interrupts can be established correctly 187 * i.e. This is a hack. 188 */ 189 #if NISA > 0 && !defined(SHARK) 190 isa_intr_init(); 191 #endif 192 193 config_rootfound("mainbus", NULL); 194 #if defined(OFWGENCFG) || defined(SHARK) 195 /* Temporary for SHARK! */ 196 ofrootfound(); 197 #endif 198 199 /* Debugging information */ 200 #ifndef TERSE 201 printf("ipl_bio=%08x ipl_net=%08x ipl_tty=%08x ipl_imp=%08x\n", 202 irqmasks[IPL_BIO], irqmasks[IPL_NET], irqmasks[IPL_TTY], 203 irqmasks[IPL_IMP]); 204 printf("ipl_audio=%08x ipl_imp=%08x ipl_high=%08x ipl_serial=%08x\n", 205 irqmasks[IPL_AUDIO], irqmasks[IPL_CLOCK], irqmasks[IPL_HIGH], 206 irqmasks[IPL_SERIAL]); 207 #endif 208 209 /* Time to start taking interrupts so lets open the flood gates .... */ 210 (void)spl0(); 211 } 212 213 void 214 device_register(struct device *dev, void *aux) 215 { 216 #if defined(OFWGENCFG) || defined(SHARK) 217 /* Temporary for SHARK! */ 218 ofw_device_register(dev, aux); 219 #endif 220 } 221 /* End of autoconf.c */ 222