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