1 /* $NetBSD: autoconf.c,v 1.16 2009/05/12 06:56:59 cegger 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 <sys/cdefs.h> 46 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.16 2009/05/12 06:56:59 cegger Exp $"); 47 48 #include "opt_md.h" 49 50 #include <sys/param.h> 51 #include <sys/systm.h> 52 #include <sys/reboot.h> 53 #include <sys/disklabel.h> 54 #include <sys/device.h> 55 #include <sys/conf.h> 56 #include <sys/kernel.h> 57 #include <sys/malloc.h> 58 #include <machine/bootconfig.h> 59 #include <machine/intr.h> 60 61 62 #include "podulebus.h" 63 64 extern char *booted_kernel; 65 66 extern dev_t dumpdev; 67 68 void dumpconf(void); 69 void isa_intr_init(void); 70 71 #ifndef MEMORY_DISK_IS_ROOT 72 static void get_device(char *name); 73 static void set_root_device(void); 74 #endif 75 76 #ifndef MEMORY_DISK_IS_ROOT 77 /* Decode a device name to a major and minor number */ 78 79 static void 80 get_device(char *name) 81 { 82 int unit, part; 83 char devname[16], *cp; 84 device_t dv; 85 86 if (strncmp(name, "/dev/", 5) == 0) 87 name += 5; 88 89 if (devsw_name2blk(name, devname, sizeof(devname)) == -1) 90 return; 91 92 name += strlen(devname); 93 unit = part = 0; 94 95 cp = name; 96 while (*cp >= '0' && *cp <= '9') 97 unit = (unit * 10) + (*cp++ - '0'); 98 if (cp == name) 99 return; 100 101 if (*cp >= 'a' && *cp <= ('a' + MAXPARTITIONS)) 102 part = *cp - 'a'; 103 else if (*cp != '\0' && *cp != ' ') 104 return; 105 106 if ((dv = device_find_by_driver_unit(devname, unit)) != NULL) { 107 booted_device = dv; 108 booted_partition = part; 109 } 110 } 111 112 113 /* Set the rootdev variable from the root specifier in the boot args */ 114 115 static void 116 set_root_device(void) 117 { 118 char *ptr; 119 120 if (booted_kernel) 121 get_device(booted_kernel); 122 if (boot_args && 123 get_bootconf_option(boot_args, "root", BOOTOPT_TYPE_STRING, &ptr)) 124 get_device(ptr); 125 } 126 #endif 127 128 /* 129 * Set up the root device from the boot args 130 */ 131 void 132 cpu_rootconf(void) 133 { 134 #ifndef MEMORY_DISK_IS_ROOT 135 set_root_device(); 136 137 printf("boot device: %s\n", 138 booted_device != NULL ? device_xname(booted_device) : "<unknown>"); 139 #endif 140 setroot(booted_device, booted_partition); 141 } 142 143 144 /* 145 * void cpu_configure() 146 * 147 * Configure all the root devices 148 * The root devices are expected to configure their own children 149 */ 150 151 void 152 cpu_configure(void) 153 { 154 /* 155 * Configure all the roots. 156 * We have to have a mainbus 157 */ 158 159 /* 160 * Since the ICU is not standard on the ARM we don't know 161 * if we have one until we find a bridge. 162 * Since various PCI interrupts could be routed via the ICU 163 * (for PCI devices in the bridge) we need to set up the ICU 164 * now so that these interrupts can be established correctly 165 * i.e. This is a hack. 166 */ 167 168 config_rootfound("mainbus", NULL); 169 #if NPODULEBUS > 0 170 config_rootfound("podulebus", NULL); 171 #endif /* NPODULEBUS */ 172 173 #if defined(DEBUG) 174 /* Debugging information */ 175 printf("ipl_bio=%08x ipl_net=%08x ipl_tty=%08x ipl_vm=%08x\n", 176 irqmasks[IPL_BIO], irqmasks[IPL_NET], irqmasks[IPL_TTY], 177 irqmasks[IPL_VM]); 178 printf("ipl_audio=%08x ipl_imp=%08x ipl_high=%08x ipl_serial=%08x\n", 179 irqmasks[IPL_AUDIO], irqmasks[IPL_CLOCK], irqmasks[IPL_HIGH], 180 irqmasks[IPL_SERIAL]); 181 #endif /* defined(DEBUG) */ 182 183 /* Time to start taking interrupts so lets open the flood gates .... */ 184 (void)spl0(); 185 } 186 187 void 188 device_register(struct device *dev, void *aux) 189 { 190 } 191 /* End of autoconf.c */ 192