1 /* $OpenBSD: autoconf.c,v 1.9 2018/03/31 18:19:12 patrick Exp $ */ 2 /* $NetBSD: autoconf.c,v 1.2 2001/09/05 16:17:36 matt Exp $ */ 3 4 /* 5 * Copyright (c) 1994-1998 Mark Brinicombe. 6 * Copyright (c) 1994 Brini. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed by Mark Brinicombe for 20 * the NetBSD project. 21 * 4. The name of the company nor the name of the author may be used to 22 * endorse or promote products derived from this software without specific 23 * prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 28 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 29 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 30 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * SUCH DAMAGE. 36 * 37 * RiscBSD kernel project 38 * 39 * autoconf.c 40 * 41 * Autoconfiguration functions 42 */ 43 44 #include <sys/param.h> 45 #include <sys/systm.h> 46 #include <sys/reboot.h> 47 #include <sys/socket.h> 48 #include <sys/disklabel.h> 49 #include <sys/device.h> 50 #include <sys/conf.h> 51 #include <sys/kernel.h> 52 53 #include <net/if.h> 54 #include <net/if_types.h> 55 #include <netinet/in.h> 56 #include <netinet/if_ether.h> 57 58 #include <machine/bootconfig.h> 59 #include <machine/intr.h> 60 #include <machine/bus.h> 61 62 struct device *bootdv = NULL; 63 64 void dumpconf(void); 65 66 void 67 device_register(struct device *dev, void *aux) 68 { 69 } 70 71 /* 72 * void cpu_configure() 73 * 74 * Configure all the root devices 75 * The root devices are expected to configure their own children 76 */ 77 void 78 cpu_configure(void) 79 { 80 softintr_init(); 81 82 /* 83 * Since various PCI interrupts could be routed via the ICU 84 * (for PCI devices in the bridge) we need to set up the ICU 85 * now so that these interrupts can be established correctly 86 * i.e. This is a hack. 87 */ 88 89 config_rootfound("mainbus", NULL); 90 91 /* 92 * We can not know which is our root disk, defer 93 * until we can checksum blocks to figure it out. 94 */ 95 cold = 0; 96 97 /* Time to start taking interrupts so lets open the flood gates .... */ 98 (void)spl0(); 99 100 } 101 102 /* 103 * Now that we are fully operational, we can checksum the 104 * disks, and using some heuristics, hopefully are able to 105 * always determine the correct root disk. 106 */ 107 void 108 diskconf(void) 109 { 110 size_t len; 111 char *p; 112 dev_t tmpdev; 113 extern uint8_t *bootmac; 114 115 if (*boot_file != '\0') 116 printf("bootfile: %s\n", boot_file); 117 118 /* Lookup boot device from boot if not set by configuration */ 119 if (bootdv == NULL) { 120 121 /* boot_file is of the form wd0a:/bsd, we want 'wd0a' */ 122 if ((p = strchr(boot_file, ':')) != NULL) 123 len = p - boot_file; 124 else 125 len = strlen(boot_file); 126 bootdv = parsedisk(boot_file, len, 0, &tmpdev); 127 } 128 129 #if defined(NFSCLIENT) 130 if (bootmac) { 131 struct ifnet *ifp; 132 133 TAILQ_FOREACH(ifp, &ifnet, if_list) { 134 if (ifp->if_type == IFT_ETHER && 135 memcmp(bootmac, ((struct arpcom *)ifp)->ac_enaddr, 136 ETHER_ADDR_LEN) == 0) 137 break; 138 } 139 if (ifp) 140 bootdv = parsedisk(ifp->if_xname, strlen(ifp->if_xname), 141 0, &tmpdev); 142 } 143 #endif 144 145 if (bootdv != NULL) 146 printf("boot device: %s\n", bootdv->dv_xname); 147 else 148 printf("boot device: lookup %s failed.\n", boot_file); 149 setroot(bootdv, 0, RB_USERREQ); 150 dumpconf(); 151 } 152 153 struct nam2blk nam2blk[] = { 154 { "wd", 16 }, 155 { "rd", 18 }, 156 { "vnd", 19 }, 157 { "sd", 24 }, 158 { "cd", 26 }, 159 { NULL, -1 } 160 }; 161 162