Home | History | Annotate | Line # | Download | only in pmax
      1 /*	$NetBSD: autoconf.c,v 1.80 2012/10/13 06:51:22 tsutsui Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1988 University of Utah.
      5  * Copyright (c) 1992, 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 and Ralph Campbell.
     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. Neither the name of the University nor the names of its contributors
     21  *    may be used to endorse or promote products derived from this software
     22  *    without specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  * OR 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  * from: Utah Hdr: autoconf.c 1.31 91/01/21
     37  *
     38  *	@(#)autoconf.c	8.1 (Berkeley) 6/10/93
     39  */
     40 
     41 #include <sys/cdefs.h>
     42 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.80 2012/10/13 06:51:22 tsutsui Exp $");
     43 
     44 #include <sys/param.h>
     45 #include <sys/conf.h>
     46 #include <sys/device.h>
     47 #include <sys/intr.h>
     48 #include <sys/reboot.h>
     49 #include <sys/systm.h>
     50 
     51 #include <pmax/autoconf.h>
     52 #include <pmax/sysconf.h>
     53 
     54 #include <pmax/pmax/pmaxtype.h>
     55 
     56 #include <dev/tc/tcvar.h>
     57 
     58 #include <dev/scsipi/scsi_all.h>
     59 #include <dev/scsipi/scsipi_all.h>
     60 #include <dev/scsipi/scsiconf.h>
     61 
     62 #include "opt_dec_3100.h"
     63 #include "opt_dec_5100.h"
     64 
     65 struct intrhand		intrtab[MAX_DEV_NCOOKIES];
     66 static device_t		booted_controller;
     67 static int		booted_slot, booted_unit;
     68 static const char	*booted_protocol;
     69 
     70 /*
     71  * Configure all devices on system
     72  */
     73 void
     74 cpu_configure(void)
     75 {
     76 
     77 	/* Kick off autoconfiguration. */
     78 	(void)splhigh();
     79 
     80 	/* Interrupt initialization. */
     81 	intr_init();
     82 
     83 	if (config_rootfound("mainbus", NULL) == NULL)
     84 		panic("no mainbus found");
     85 
     86 	/* Reset any bus errors due to probing nonexistent devices. */
     87 	(*platform.bus_reset)();
     88 
     89 	/* Configuration is finished, turn on interrupts. */
     90 	spl0();	/* enable all source forcing SOFT_INTs cleared */
     91 }
     92 
     93 /*
     94  * Look at the string 'cp' and decode the boot device.  Boot names
     95  * can be something like 'rz(0,0,0)vmunix' or '5/rz0/vmunix'.
     96  *
     97  * 2100/3100/5100 allows abbrivation;
     98  *	dev(controller[,uni-number[,partition-number]]])[filename]
     99  */
    100 void
    101 makebootdev(char *cp)
    102 {
    103 	booted_device = NULL;
    104 	booted_slot = booted_unit = booted_partition = 0;
    105 	booted_protocol = NULL;
    106 
    107 #if defined(DEC_3100) || defined(DEC_5100)
    108 	if (cp[0] == 'r' && cp[1] == 'z' && cp[2] == '(') {
    109 		cp += 3;
    110 		if (*cp >= '0' && *cp <= '9')
    111 			booted_slot = *cp++ - '0';
    112 		if (*cp == ',')
    113 			cp += 1;
    114 		if (*cp >= '0' && *cp <= '9')
    115 			booted_unit = *cp++ - '0';
    116 		if (*cp == ',')
    117 			cp += 1;
    118 		if (*cp >= '0' && *cp <= '9')
    119 			booted_partition = *cp - '0';
    120 		booted_protocol = "SCSI";
    121 		return;
    122 	}
    123 	if (strncmp(cp, "tftp(", 5) == 0) {
    124 		booted_protocol = "BOOTP";
    125 		return;
    126 	}
    127 	if (strncmp(cp, "mop(", 4) == 0) {
    128 		booted_protocol = "MOP";
    129 		return;
    130 	}
    131 #endif
    132 
    133 	if (cp[0] >= '0' && cp[0] <= '9' && cp[1] == '/') {
    134 		booted_slot = cp[0] - '0';
    135 		if (cp[2] == 'r' && cp[3] == 'z'
    136 		    && cp[4] >= '0' && cp[4] <= '9') {
    137 			booted_protocol = "SCSI";
    138 			booted_unit = cp[4] - '0';
    139 		}
    140 		else if (strncmp(cp+2, "tftp", 4) == 0)
    141 			booted_protocol = "BOOTP";
    142 		else if (strncmp(cp+2, "mop", 3) == 0)
    143 			booted_protocol = "MOP";
    144 	}
    145 }
    146 
    147 void
    148 cpu_rootconf(void)
    149 {
    150 
    151 	printf("boot device: %s\n",
    152 	    booted_device ? device_xname(booted_device) : "<unknown>");
    153 
    154 	rootconf();
    155 }
    156 
    157 /*
    158  * Try to determine the boot device.
    159  */
    160 void
    161 device_register(device_t dev, void *aux)
    162 {
    163 	static int found, initted, scsiboot, netboot;
    164 	static device_t ioasicdev;
    165 	device_t parent = device_parent(dev);
    166 
    167 	if (found)
    168 		return;
    169 
    170 	if (!initted) {
    171 		scsiboot = strcmp(booted_protocol, "SCSI") == 0;
    172 		netboot = (strcmp(booted_protocol, "BOOTP") == 0) ||
    173 		    (strcmp(booted_protocol, "MOP") == 0);
    174 		initted = 1;
    175 	}
    176 
    177 	/*
    178 	 * Check if IOASIC was the boot slot.
    179 	 */
    180 	if (device_is_a(dev, "ioasic")) {
    181 		struct tc_attach_args *ta = aux;
    182 
    183 		if (ta->ta_slot == booted_slot)
    184 			ioasicdev = dev;
    185 		return;
    186 	}
    187 
    188 	/*
    189 	 * Check for ASC controller on either IOASIC or TC option card.
    190 	 */
    191 	if (scsiboot && device_is_a(dev, "asc")) {
    192 		struct tc_attach_args *ta = aux;
    193 
    194 		/*
    195 		 * If boot was from IOASIC controller, ioasicdev will
    196 		 * be the ASC parent.
    197 		 * If boot was from a TC option card, the TC slot number
    198 		 * of the ASC will match the boot slot.
    199 		 */
    200 		if (parent == ioasicdev ||
    201 		    ta->ta_slot == booted_slot) {
    202 			booted_controller = dev;
    203 			return;
    204 		}
    205 	}
    206 
    207 	/*
    208 	 * If an SII device is configured, it's currently the only
    209 	 * possible SCSI boot device.
    210 	 */
    211 	if (scsiboot && device_is_a(dev, "sii")) {
    212 		booted_controller = dev;
    213 		return;
    214 	}
    215 
    216 	/*
    217 	 * If we found the boot controller, if check disk/tape/cdrom device
    218 	 * on that controller matches.
    219 	 */
    220 	if (booted_controller &&
    221 	    (device_is_a(dev, "sd") ||
    222 	     device_is_a(dev, "st") ||
    223 	     device_is_a(dev, "cd"))) {
    224 		struct scsipibus_attach_args *sa = aux;
    225 
    226 		if (device_parent(parent) != booted_controller)
    227 			return;
    228 		if (booted_unit != sa->sa_periph->periph_target)
    229 			return;
    230 		booted_device = dev;
    231 		found = 1;
    232 		return;
    233 	}
    234 
    235 	/*
    236 	 * Check if netboot device.
    237 	 */
    238 	if (netboot) {
    239 		struct tc_attach_args *ta = aux;
    240 
    241 		if ((
    242 #if defined(DEC_3100) || defined(DEC_5100)
    243 		     /* Only one Ethernet interface on 2100/3100/5100. */
    244 		     systype == DS_PMAX || systype == DS_MIPSMATE ||
    245 #endif
    246 		     /* Only one Ethernet interface at IOASIC. */
    247 		     parent == ioasicdev)
    248 		    && device_is_a(dev, "le")) {
    249 			booted_device = dev;
    250 			found = 1;
    251 			return;
    252 		}
    253 
    254 		/* allow any TC network adapter */
    255 		if (device_class(dev) == DV_IFNET &&
    256 		    device_is_a(parent, "tc") &&
    257 		    ta->ta_slot == booted_slot) {
    258 			booted_device = dev;
    259 			found = 1;
    260 			return;
    261 		}
    262 	}
    263 }
    264