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