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