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