1 /* $NetBSD: autoconf.c,v 1.32 2002/02/12 20:38:35 scw Exp $ */ 2 3 /* 4 * Copyright (c) 1988 University of Utah. 5 * Copyright (c) 1982, 1986, 1990, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * the Systems Programming Group of the University of Utah Computer 10 * Science Department. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 3. All advertising materials mentioning features or use of this software 21 * must display the following acknowledgement: 22 * This product includes software developed by the University of 23 * California, Berkeley and its contributors. 24 * 4. Neither the name of the University nor the names of its contributors 25 * may be used to endorse or promote products derived from this software 26 * without specific prior written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 38 * SUCH DAMAGE. 39 * 40 * from: Utah $Hdr: autoconf.c 1.36 92/12/20$ 41 * 42 * @(#)autoconf.c 8.2 (Berkeley) 1/12/94 43 */ 44 45 /* 46 * Setup the system to run on the current machine. 47 * 48 * Configure() is called at boot time. 49 */ 50 51 #include <sys/param.h> 52 #include <sys/systm.h> 53 #include <sys/map.h> 54 #include <sys/buf.h> 55 #include <sys/dkstat.h> 56 #include <sys/conf.h> 57 #include <sys/reboot.h> 58 #include <sys/device.h> 59 60 #include <machine/vmparam.h> 61 #include <machine/disklabel.h> 62 #include <machine/cpu.h> 63 #include <machine/autoconf.h> 64 #include <machine/pte.h> 65 66 #include <dev/scsipi/scsi_all.h> 67 #include <dev/scsipi/scsipi_all.h> 68 #include <dev/scsipi/scsiconf.h> 69 70 #include <mvme68k/mvme68k/isr.h> 71 72 #ifdef MVME147 73 #include <mvme68k/dev/pccreg.h> 74 #endif 75 #if defined(MVME162) || defined(MVME167) || defined(MVME172) || defined(MVME177) 76 #include <dev/mvme/pcctworeg.h> 77 #endif 78 79 80 struct device *booted_device; /* boot device */ 81 82 /* 83 * Determine mass storage and memory configuration for a machine. 84 */ 85 void 86 cpu_configure() 87 { 88 89 booted_device = NULL; /* set by device drivers (if found) */ 90 91 /* Initialise interrupt handlers */ 92 isrinit(); 93 softintr_init(); 94 95 if (config_rootfound("mainbus", NULL) == NULL) 96 panic("autoconfig failed, no root"); 97 } 98 99 void 100 cpu_rootconf() 101 { 102 103 printf("boot device: %s", 104 (booted_device) ? booted_device->dv_xname : "<unknown>"); 105 106 if (bootpart) 107 printf(" (partition %d)\n", bootpart); 108 else 109 printf("\n"); 110 111 setroot(booted_device, bootpart); 112 } 113 114 void 115 device_register(dev, aux) 116 struct device *dev; 117 void *aux; 118 { 119 static struct device *controller; 120 static int foundboot; 121 struct device *parent; 122 struct cfdriver *cd; 123 124 if (foundboot) 125 return; 126 127 parent = dev->dv_parent; 128 cd = dev->dv_cfdata->cf_driver; 129 130 if (controller == NULL && parent) { 131 struct cfdriver *pcd = parent->dv_cfdata->cf_driver; 132 133 switch (machineid) { 134 #ifdef MVME147 135 case MVME_147: 136 /* 137 * We currently only support booting from the 147's 138 * onboard scsi and ethernet. So ensure this 139 * device's parent is the PCC driver. 140 */ 141 if (strcmp(pcd->cd_name, "pcc")) 142 return; 143 144 if (bootaddr == PCC_PADDR(PCC_WDSC_OFF) && 145 strcmp(cd->cd_name, "wdsc") == 0) { 146 controller = dev; 147 return; 148 } 149 150 if (bootaddr == PCC_PADDR(PCC_LE_OFF) && 151 strcmp(cd->cd_name, "le") == 0) { 152 booted_device = dev; 153 foundboot = 1; 154 return; 155 } 156 157 break; 158 #endif /* MVME_147 */ 159 160 #if defined(MVME162) || defined(MVME167) || defined(MVME172) || defined(MVME177) 161 case MVME_162: 162 case MVME_167: 163 case MVME_172: 164 case MVME_177: 165 /* 166 * We currently only support booting from the 16x and 17x 167 * onboard scsi and ethernet. So ensure this 168 * device's parent is the PCCTWO driver. 169 */ 170 if (strcmp(pcd->cd_name, "pcctwo")) 171 return; 172 173 if (bootaddr == PCCTWO_PADDR(PCCTWO_NCRSC_OFF) && 174 strcmp(cd->cd_name, "osiop") == 0) { 175 controller = dev; 176 return; 177 } 178 179 if (bootaddr == PCCTWO_PADDR(PCCTWO_IE_OFF) && 180 strcmp(cd->cd_name, "ie") == 0) { 181 booted_device = dev; 182 foundboot = 1; 183 return; 184 } 185 186 break; 187 #endif /* MVME_162 || MVME_167 || MVME_172 || MVME_177 */ 188 189 default: 190 break; 191 } 192 193 return; 194 } 195 196 /* 197 * Find out which device on the scsibus we booted from 198 */ 199 if (strcmp(cd->cd_name, "sd") == 0 || 200 strcmp(cd->cd_name, "cd") == 0 || 201 strcmp(cd->cd_name, "st") == 0) { 202 struct scsipibus_attach_args *sa = aux; 203 204 if (parent->dv_parent != controller || 205 bootdevlun != sa->sa_periph->periph_target) 206 return; 207 208 booted_device = dev; 209 foundboot = 1; 210 } 211 } 212