Home | History | Annotate | Line # | Download | only in alpha
autoconf.c revision 1.19
      1 /*	$NetBSD: autoconf.c,v 1.19 1997/02/03 19:46:55 cgd 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/param.h>
     48 #include <sys/systm.h>
     49 #include <sys/buf.h>
     50 #include <sys/disklabel.h>
     51 #include <sys/conf.h>
     52 #include <sys/reboot.h>
     53 #include <sys/device.h>
     54 #include <dev/cons.h>
     55 
     56 #include <machine/autoconf.h>
     57 #include <machine/prom.h>
     58 #include <machine/cpuconf.h>
     59 
     60 struct device		*booted_device;
     61 int			booted_partition;
     62 struct bootdev_data	*bootdev_data;
     63 char			boot_dev[128];
     64 
     65 void	parse_prom_bootdev __P((void));
     66 int	atoi __P((char *));
     67 
     68 struct devnametobdevmaj alpha_nam2blk[] = {
     69 	{ "st",		2 },
     70 	{ "cd",		3 },
     71 	{ "md",		6 },
     72 	{ "sd",		8 },
     73 	{ "fd",		0 },
     74 	{ "wd",		4 },
     75 	{ NULL,		0 },
     76 };
     77 
     78 /*
     79  * configure:
     80  * called at boot time, configure all devices on system
     81  */
     82 void
     83 configure()
     84 {
     85 
     86 	parse_prom_bootdev();
     87 
     88 	(void)splhigh();
     89 	if (config_rootfound("mainbus", "mainbus") == NULL)
     90 		panic("no mainbus found");
     91 	(void)spl0();
     92 
     93 	if (booted_device == NULL)
     94 		printf("WARNING: can't figure what device matches \"%s\"\n",
     95 		    boot_dev);
     96 	setroot(booted_device, booted_partition, alpha_nam2blk);
     97 	swapconf();
     98 	dumpconf();
     99 	cold = 0;
    100 }
    101 
    102 void
    103 parse_prom_bootdev()
    104 {
    105 	static char hacked_boot_dev[128];
    106 	static struct bootdev_data bd;
    107 	char *cp, *scp, *boot_fields[8];
    108 	int i, done;
    109 
    110 	booted_device = NULL;
    111 	booted_partition = 0;
    112 	bootdev_data = NULL;
    113 
    114         prom_getenv(PROM_E_BOOTED_DEV, boot_dev, sizeof(boot_dev));
    115 	bcopy(boot_dev, hacked_boot_dev, sizeof hacked_boot_dev);
    116 #if 0
    117 	printf("parse_prom_bootdev: boot dev = \"%s\"\n", boot_dev);
    118 #endif
    119 
    120 	i = 0;
    121 	scp = cp = hacked_boot_dev;
    122 	for (done = 0; !done; cp++) {
    123 		if (*cp != ' ' && *cp != '\0')
    124 			continue;
    125 		if (*cp == '\0')
    126 			done = 1;
    127 
    128 		*cp = '\0';
    129 		boot_fields[i++] = scp;
    130 		scp = cp + 1;
    131 		if (i == 8)
    132 			done = 1;
    133 	}
    134 	if (i != 8)
    135 		return;		/* doesn't look like anything we know! */
    136 
    137 #if 0
    138 	printf("i = %d, done = %d\n", i, done);
    139 	for (i--; i >= 0; i--)
    140 		printf("%d = %s\n", i, boot_fields[i]);
    141 #endif
    142 
    143 	bd.protocol = boot_fields[0];
    144 	bd.bus = atoi(boot_fields[1]);
    145 	bd.slot = atoi(boot_fields[2]);
    146 	bd.channel = atoi(boot_fields[3]);
    147 	bd.remote_address = boot_fields[4];
    148 	bd.unit = atoi(boot_fields[5]);
    149 	bd.boot_dev_type = atoi(boot_fields[6]);
    150 	bd.ctrl_dev_type = boot_fields[7];
    151 
    152 #if 0
    153 	printf("parsed: proto = %s, bus = %d, slot = %d, channel = %d,\n",
    154 	    bd.protocol, bd.bus, bd.slot, bd.channel);
    155 	printf("\tremote = %s, unit = %d, dev_type = %d, ctrl_type = %s\n",
    156 	    bd.remote_address, bd.unit, bd.boot_dev_type, bd.ctrl_dev_type);
    157 #endif
    158 
    159 	bootdev_data = &bd;
    160 }
    161 
    162 int
    163 atoi(s)
    164 	char *s;
    165 {
    166 	int n, neg;
    167 
    168 	n = 0;
    169 	neg = 0;
    170 
    171 	while (*s == '-') {
    172 		s++;
    173 		neg = !neg;
    174 	}
    175 
    176 	while (*s != '\0') {
    177 		if (*s < '0' && *s > '9')
    178 			break;
    179 
    180 		n = (10 * n) + (*s - '0');
    181 		s++;
    182 	}
    183 
    184 	return (neg ? -n : n);
    185 }
    186 
    187 void
    188 device_register(dev, aux)
    189 	struct device *dev;
    190 	void *aux;
    191 {
    192 	extern const struct cpusw *cpu_fn_switch;
    193 
    194 	if (bootdev_data == NULL) {
    195 		/*
    196 		 * There is no hope.
    197 		 */
    198 
    199 		return;
    200 	}
    201 
    202 	(*cpu_fn_switch->device_register)(dev, aux);
    203 }
    204