1 /* $NetBSD: autoconf.c,v 1.5 2001/11/27 01:12:55 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 */ 37 38 #include "opt_md.h" 39 40 #include <sys/param.h> 41 #include <sys/systm.h> 42 #include <sys/reboot.h> 43 #include <sys/disklabel.h> 44 #include <sys/device.h> 45 #include <sys/conf.h> 46 #include <sys/kernel.h> 47 #include <sys/malloc.h> 48 49 #include <machine/bootconfig.h> 50 #include <machine/intr.h> 51 52 #include "sacom.h" 53 54 struct device *booted_device; 55 int booted_partition; 56 57 extern dev_t dumpdev; 58 59 void dumpconf __P((void)); 60 void isa_intr_init __P((void)); 61 62 #ifndef MEMORY_DISK_IS_ROOT 63 static void get_device __P((char *name)); 64 static void set_root_device __P((void)); 65 #endif 66 67 #ifndef MEMORY_DISK_IS_ROOT 68 /* Decode a device name to a major and minor number */ 69 70 static void 71 get_device(name) 72 char *name; 73 { 74 int loop, unit, part; 75 char buf[32], *cp; 76 struct device *dv; 77 78 if (strncmp(name, "/dev/", 5) == 0) 79 name += 5; 80 81 for (loop = 0; dev_name2blk[loop].d_name != NULL; ++loop) { 82 if (strncmp(name, dev_name2blk[loop].d_name, 83 strlen(dev_name2blk[loop].d_name)) == 0) { 84 name += strlen(dev_name2blk[loop].d_name); 85 unit = part = 0; 86 87 cp = name; 88 while (*cp >= '0' && *cp <= '9') 89 unit = (unit * 10) + (*cp++ - '0'); 90 if (cp == name) 91 return; 92 93 if (*cp >= 'a' && *cp <= ('a' + MAXPARTITIONS)) 94 part = *cp - 'a'; 95 else if (*cp != '\0' && *cp != ' ') 96 return; 97 sprintf(buf, "%s%d", dev_name2blk[loop].d_name, unit); 98 for (dv = alldevs.tqh_first; dv != NULL; 99 dv = dv->dv_list.tqe_next) { 100 if (strcmp(buf, dv->dv_xname) == 0) { 101 booted_device = dv; 102 booted_partition = part; 103 return; 104 } 105 } 106 } 107 } 108 } 109 110 111 /* Set the rootdev variable from the root specifier in the boot args */ 112 113 static void 114 set_root_device() 115 { 116 char *ptr; 117 118 if (boot_file) 119 get_device(boot_file); 120 if (boot_args && 121 get_bootconf_option(boot_args, "root", BOOTOPT_TYPE_STRING, &ptr)) 122 get_device(ptr); 123 } 124 #endif /* ifndef MEMORY_DISK_IS_ROOT */ 125 126 /* 127 * Set up the root device from the boot args 128 */ 129 void 130 cpu_rootconf() 131 { 132 #ifndef MEMORY_DISK_IS_ROOT 133 set_root_device(); 134 135 printf("boot device: %s\n", 136 booted_device != NULL ? booted_device->dv_xname : "<unknown>"); 137 #endif 138 setroot(booted_device, booted_partition); 139 } 140 141 142 /* 143 * void cpu_configure() 144 * 145 * Configure all the root devices 146 * The root devices are expected to configure their own children 147 */ 148 149 void 150 cpu_configure() 151 { 152 /* 153 * Configure all the roots. 154 * We have to have a mainbus 155 */ 156 #if 0 157 startrtclock(); 158 #endif 159 160 /* 161 * Since the ICU is not standard on the ARM we don't know 162 * if we have one until we find a bridge. 163 * Since various PCI interrupts could be routed via the ICU 164 * (for PCI devices in the bridge) we need to set up the ICU 165 * now so that these interrupts can be established correctly 166 * i.e. This is a hack. 167 */ 168 169 if (config_rootfound("mainbus", NULL) == NULL) 170 panic("configure: mainbus not configured"); 171 172 /* Debugging information */ 173 174 printf("ipl_bio=%08x ipl_net=%08x ipl_tty=%08x ipl_imp=%08x\n", 175 imask[IPL_BIO], imask[IPL_NET], imask[IPL_TTY], 176 imask[IPL_IMP]); 177 printf("ipl_audio=%08x ipl_imp=%08x ipl_high=%08x ipl_serial=%08x\n", 178 imask[IPL_AUDIO], imask[IPL_CLOCK], imask[IPL_HIGH], 179 imask[IPL_SERIAL]); 180 181 /* Time to start taking interrupts so lets open the flood gates .... */ 182 (void)spl0(); 183 } 184 185 void 186 device_register(struct device *dev, void *aux) 187 { 188 } 189 190 /* 191 * This entire table could be autoconfig()ed but that would mean that 192 * the kernel's idea of the console would be out of sync with that of 193 * the standalone boot. I think it best that they both use the same 194 * known algorithm unless we see a pressing need otherwise. 195 */ 196 197 #include <dev/cons.h> 198 199 cons_decl(com); 200 cons_decl(sacom); 201 202 struct consdev constab[] = { 203 #if (NSACOM > 0) 204 cons_init(sacom), 205 #endif 206 { 0 }, 207 }; 208