1 /* $OpenBSD: autoconf.c,v 1.81 2008/07/21 04:35:54 todd Exp $ */ 2 /* $NetBSD: autoconf.c,v 1.20 1996/05/03 19:41:56 christos Exp $ */ 3 4 /*- 5 * Copyright (c) 1990 The Regents of the University of California. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * William Jolitz. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * @(#)autoconf.c 7.1 (Berkeley) 5/9/91 36 */ 37 38 /* 39 * Setup the system to run on the current machine. 40 * 41 * cpu_configure() is called at boot time and initializes the vba 42 * device tables and the memory controller monitoring. Available 43 * devices are determined (from possibilities mentioned in ioconf.c), 44 * and the drivers are initialized. 45 */ 46 #include <sys/param.h> 47 #include <sys/systm.h> 48 #include <sys/user.h> 49 #include <sys/buf.h> 50 #include <sys/dkstat.h> 51 #include <sys/disklabel.h> 52 #include <sys/conf.h> 53 #include <sys/reboot.h> 54 #include <sys/device.h> 55 #include <sys/socket.h> 56 #include <sys/socketvar.h> 57 58 #include <net/if.h> 59 #include <net/if_types.h> 60 #include <netinet/in.h> 61 #include <netinet/if_ether.h> 62 63 #include <uvm/uvm_extern.h> 64 65 #include <machine/pte.h> 66 #include <machine/cpu.h> 67 #include <machine/gdt.h> 68 #include <machine/biosvar.h> 69 #include <machine/kvm86.h> 70 71 #include <dev/cons.h> 72 73 #include "ioapic.h" 74 75 #if NIOAPIC > 0 76 #include <machine/i82093var.h> 77 #endif 78 79 /* 80 * The following several variables are related to 81 * the configuration process, and are used in initializing 82 * the machine. 83 */ 84 extern dev_t bootdev; 85 86 /* Support for VIA C3 RNG */ 87 extern struct timeout viac3_rnd_tmo; 88 extern int viac3_rnd_present; 89 void viac3_rnd(void *); 90 91 #ifdef CRYPTO 92 void viac3_crypto_setup(void); 93 extern int i386_has_xcrypt; 94 #endif 95 96 /* 97 * Determine i/o configuration for a machine. 98 */ 99 void 100 cpu_configure(void) 101 { 102 /* 103 * Note, on i386, configure is not running under splhigh unlike other 104 * architectures. This fact is used by the pcmcia irq line probing. 105 */ 106 107 startrtclock(); 108 109 gdt_init(); /* XXX - pcibios uses gdt stuff */ 110 111 /* Set up proc0's TSS and LDT */ 112 i386_proc0_tss_ldt_init(); 113 114 #ifdef KVM86 115 kvm86_init(); 116 #endif 117 118 if (config_rootfound("mainbus", NULL) == NULL) 119 panic("cpu_configure: mainbus not configured"); 120 121 #if NIOAPIC > 0 122 if (nioapics > 0) 123 goto nomasks; 124 #endif 125 printf("biomask %x netmask %x ttymask %x\n", (u_short)IMASK(IPL_BIO), 126 (u_short)IMASK(IPL_NET), (u_short)IMASK(IPL_TTY)); 127 128 #if NIOAPIC > 0 129 nomasks: 130 ioapic_enable(); 131 #endif 132 133 proc0.p_addr->u_pcb.pcb_cr0 = rcr0(); 134 135 #ifdef MULTIPROCESSOR 136 /* propagate TSS and LDT configuration to the idle pcb's. */ 137 cpu_init_idle_pcbs(); 138 #endif 139 spl0(); 140 141 /* 142 * We can not know which is our root disk, defer 143 * until we can checksum blocks to figure it out. 144 */ 145 cold = 0; 146 147 /* 148 * At this point the RNG is running, and if FSXR is set we can 149 * use it. Here we setup a periodic timeout to collect the data. 150 */ 151 if (viac3_rnd_present) { 152 timeout_set(&viac3_rnd_tmo, viac3_rnd, &viac3_rnd_tmo); 153 viac3_rnd(&viac3_rnd_tmo); 154 } 155 #ifdef CRYPTO 156 /* 157 * Also, if the chip has crypto available, enable it. 158 */ 159 if (i386_has_xcrypt) 160 viac3_crypto_setup(); 161 #endif 162 } 163 164 void 165 device_register(struct device *dev, void *aux) 166 { 167 } 168 169 /* 170 * Now that we are fully operational, we can checksum the 171 * disks, and using some heuristics, hopefully are able to 172 * always determine the correct root disk. 173 */ 174 void 175 diskconf(void) 176 { 177 int majdev, unit, part = 0; 178 struct device *bootdv = NULL; 179 dev_t tmpdev; 180 char buf[128]; 181 extern bios_bootmac_t *bios_bootmac; 182 183 dkcsumattach(); 184 185 if ((bootdev & B_MAGICMASK) == (u_int)B_DEVMAGIC) { 186 majdev = B_TYPE(bootdev); 187 unit = B_UNIT(bootdev); 188 part = B_PARTITION(bootdev); 189 snprintf(buf, sizeof buf, "%s%d%c", findblkname(majdev), 190 unit, part + 'a'); 191 bootdv = parsedisk(buf, strlen(buf), part, &tmpdev); 192 } 193 194 if (bios_bootmac) { 195 struct ifnet *ifp; 196 197 for (ifp = TAILQ_FIRST(&ifnet); ifp != NULL; 198 ifp = TAILQ_NEXT(ifp, if_list)) { 199 if ((ifp->if_type == IFT_ETHER || 200 ifp->if_type == IFT_FDDI) && 201 bcmp(bios_bootmac->mac, 202 ((struct arpcom *)ifp)->ac_enaddr, 203 ETHER_ADDR_LEN) == 0) 204 break; 205 } 206 if (ifp) { 207 #if defined(NFSCLIENT) 208 printf("PXE boot MAC address %s, interface %s\n", 209 ether_sprintf(bios_bootmac->mac), ifp->if_xname); 210 bootdv = parsedisk(ifp->if_xname, strlen(ifp->if_xname), 211 0, &tmpdev); 212 part = 0; 213 #endif 214 } else 215 printf("PXE boot MAC address %s, interface %s\n", 216 ether_sprintf(bios_bootmac->mac), "unknown"); 217 } 218 219 setroot(bootdv, part, RB_USERREQ); 220 dumpconf(); 221 } 222 223 struct nam2blk nam2blk[] = { 224 { "wd", 0 }, 225 { "fd", 2 }, 226 { "sd", 4 }, 227 { "cd", 6 }, 228 { "mcd", 7 }, 229 { "rd", 17 }, 230 { "raid", 19 }, 231 { "vnd", 14 }, 232 { NULL, -1 } 233 }; 234