Home | History | Annotate | Line # | Download | only in alpha
autoconf.c revision 1.31
      1 /* $NetBSD: autoconf.c,v 1.31 1998/10/06 21:19:05 thorpej Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1992, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * This software was developed by the Computer Systems Engineering group
      8  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      9  * contributed to Berkeley.
     10  *
     11  * All advertising materials mentioning features or use of this software
     12  * must display the following acknowledgement:
     13  *	This product includes software developed by the University of
     14  *	California, Lawrence Berkeley Laboratory.
     15  *
     16  * Redistribution and use in source and binary forms, with or without
     17  * modification, are permitted provided that the following conditions
     18  * are met:
     19  * 1. Redistributions of source code must retain the above copyright
     20  *    notice, this list of conditions and the following disclaimer.
     21  * 2. Redistributions in binary form must reproduce the above copyright
     22  *    notice, this list of conditions and the following disclaimer in the
     23  *    documentation and/or other materials provided with the distribution.
     24  * 3. All advertising materials mentioning features or use of this software
     25  *    must display the following acknowledgement:
     26  *	This product includes software developed by the University of
     27  *	California, Berkeley and its contributors.
     28  * 4. Neither the name of the University nor the names of its contributors
     29  *    may be used to endorse or promote products derived from this software
     30  *    without specific prior written permission.
     31  *
     32  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     33  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     34  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     35  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     36  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     40  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     41  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     42  * SUCH DAMAGE.
     43  *
     44  *	@(#)autoconf.c	8.4 (Berkeley) 10/1/93
     45  */
     46 
     47 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     48 
     49 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.31 1998/10/06 21:19:05 thorpej Exp $");
     50 
     51 #include "opt_multiprocessor.h"
     52 
     53 #include <sys/param.h>
     54 #include <sys/systm.h>
     55 #include <sys/buf.h>
     56 #include <sys/disklabel.h>
     57 #include <sys/reboot.h>
     58 #include <sys/device.h>
     59 #include <dev/cons.h>
     60 
     61 #include <machine/autoconf.h>
     62 #include <machine/cpu.h>
     63 #include <machine/prom.h>
     64 #include <machine/conf.h>
     65 
     66 struct device		*booted_device;
     67 int			booted_partition;
     68 struct bootdev_data	*bootdev_data;
     69 
     70 void	parse_prom_bootdev __P((void));
     71 int	atoi __P((char *));
     72 
     73 struct devnametobdevmaj alpha_nam2blk[] = {
     74 	{ "st",		2 },
     75 	{ "cd",		3 },
     76 	{ "md",		6 },
     77 	{ "sd",		8 },
     78 	{ "fd",		0 },
     79 	{ "wd",		4 },
     80 	{ NULL,		0 },
     81 };
     82 
     83 /*
     84  * configure:
     85  * called at boot time, configure all devices on system
     86  */
     87 void
     88 configure()
     89 {
     90 
     91 	parse_prom_bootdev();
     92 
     93 	/*
     94 	 * Disable interrupts during autoconfiguration.  splhigh() won't
     95 	 * work, because it simply _raises_ the IPL, so if machine checks
     96 	 * are disabled, they'll stay disabled.  Machine checks are needed
     97 	 * during autoconfig.
     98 	 */
     99 	(void)alpha_pal_swpipl(ALPHA_PSL_IPL_HIGH);
    100 	if (config_rootfound("mainbus", "mainbus") == NULL)
    101 		panic("no mainbus found");
    102 	(void)spl0();
    103 	cold = 0;
    104 
    105 	/*
    106 	 * Note that bootstrapping is finished, and set the HWRPB up
    107 	 * to do restarts.
    108 	 */
    109 	hwrpb_restart_setup();
    110 
    111 #if defined(MULTIPROCESSOR)
    112 	/*
    113 	 * Spin up any secondary CPUs.
    114 	 */
    115 	cpu_run_spinup_queue();
    116 #endif
    117 }
    118 
    119 void
    120 cpu_rootconf()
    121 {
    122 
    123 	if (booted_device == NULL)
    124 		printf("WARNING: can't figure what device matches \"%s\"\n",
    125 		    bootinfo.booted_dev);
    126 	setroot(booted_device, booted_partition, alpha_nam2blk);
    127 }
    128 
    129 void
    130 parse_prom_bootdev()
    131 {
    132 	static char hacked_boot_dev[128];
    133 	static struct bootdev_data bd;
    134 	char *cp, *scp, *boot_fields[8];
    135 	int i, done;
    136 
    137 	booted_device = NULL;
    138 	booted_partition = 0;
    139 	bootdev_data = NULL;
    140 
    141 	bcopy(bootinfo.booted_dev, hacked_boot_dev,
    142 	    min(sizeof bootinfo.booted_dev, sizeof hacked_boot_dev));
    143 #if 0
    144 	printf("parse_prom_bootdev: boot dev = \"%s\"\n", hacked_boot_dev);
    145 #endif
    146 
    147 	i = 0;
    148 	scp = cp = hacked_boot_dev;
    149 	for (done = 0; !done; cp++) {
    150 		if (*cp != ' ' && *cp != '\0')
    151 			continue;
    152 		if (*cp == '\0')
    153 			done = 1;
    154 
    155 		*cp = '\0';
    156 		boot_fields[i++] = scp;
    157 		scp = cp + 1;
    158 		if (i == 8)
    159 			done = 1;
    160 	}
    161 	if (i != 8)
    162 		return;		/* doesn't look like anything we know! */
    163 
    164 #if 0
    165 	printf("i = %d, done = %d\n", i, done);
    166 	for (i--; i >= 0; i--)
    167 		printf("%d = %s\n", i, boot_fields[i]);
    168 #endif
    169 
    170 	bd.protocol = boot_fields[0];
    171 	bd.bus = atoi(boot_fields[1]);
    172 	bd.slot = atoi(boot_fields[2]);
    173 	bd.channel = atoi(boot_fields[3]);
    174 	bd.remote_address = boot_fields[4];
    175 	bd.unit = atoi(boot_fields[5]);
    176 	bd.boot_dev_type = atoi(boot_fields[6]);
    177 	bd.ctrl_dev_type = boot_fields[7];
    178 
    179 #if 0
    180 	printf("parsed: proto = %s, bus = %d, slot = %d, channel = %d,\n",
    181 	    bd.protocol, bd.bus, bd.slot, bd.channel);
    182 	printf("\tremote = %s, unit = %d, dev_type = %d, ctrl_type = %s\n",
    183 	    bd.remote_address, bd.unit, bd.boot_dev_type, bd.ctrl_dev_type);
    184 #endif
    185 
    186 	bootdev_data = &bd;
    187 }
    188 
    189 int
    190 atoi(s)
    191 	char *s;
    192 {
    193 	int n, neg;
    194 
    195 	n = 0;
    196 	neg = 0;
    197 
    198 	while (*s == '-') {
    199 		s++;
    200 		neg = !neg;
    201 	}
    202 
    203 	while (*s != '\0') {
    204 		if (*s < '0' && *s > '9')
    205 			break;
    206 
    207 		n = (10 * n) + (*s - '0');
    208 		s++;
    209 	}
    210 
    211 	return (neg ? -n : n);
    212 }
    213 
    214 void
    215 device_register(dev, aux)
    216 	struct device *dev;
    217 	void *aux;
    218 {
    219 	if (bootdev_data == NULL) {
    220 		/*
    221 		 * There is no hope.
    222 		 */
    223 		return;
    224 	}
    225 	if (platform.device_register)
    226 		(*platform.device_register)(dev, aux);
    227 }
    228