Home | History | Annotate | Line # | Download | only in next68k
autoconf.c revision 1.2
      1 /*	$NetBSD: autoconf.c,v 1.2 1998/11/10 22:45:44 dbj Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1988 University of Utah.
      5  * Copyright (c) 1982, 1986, 1990, 1993
      6  * 	The Regents of the University of California. All rights reserved.
      7  *
      8  * This code is derived from software contributed to Berkeley by
      9  * the Systems Programming Group of the University of Utah Computer
     10  * Science Department.
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice, this list of conditions and the following disclaimer.
     17  * 2. Redistributions in binary form must reproduce the above copyright
     18  *    notice, this list of conditions and the following disclaimer in the
     19  *    documentation and/or other materials provided with the distribution.
     20  * 3. All advertising materials mentioning features or use of this software
     21  *    must display the following acknowledgement:
     22  *	This product includes software developed by the University of
     23  *	California, Berkeley and its contributors.
     24  * 4. Neither the name of the University nor the names of its contributors
     25  *    may be used to endorse or promote products derived from this software
     26  *    without specific prior written permission.
     27  *
     28  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     29  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     31  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     32  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     37  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     38  * SUCH DAMAGE.
     39  *
     40  * from: Utah $Hdr: autoconf.c 1.36 92/12/20$
     41  *
     42  *	@(#)autoconf.c  8.2 (Berkeley) 1/12/94
     43  */
     44 
     45 /*
     46  * Setup the system to run on the current machine.
     47  *
     48  * Configure() is called at boot time.  Available
     49  * devices are determined (from possibilities mentioned in ioconf.c),
     50  * and the drivers are initialized.
     51  */
     52 
     53 #include <sys/param.h>
     54 #include <sys/systm.h>
     55 #include <sys/map.h>
     56 #include <sys/buf.h>
     57 #include <sys/dkstat.h>
     58 #include <sys/conf.h>
     59 #include <sys/dmap.h>
     60 #include <sys/reboot.h>
     61 #include <sys/device.h>
     62 
     63 #include <machine/vmparam.h>
     64 #include <machine/autoconf.h>
     65 #include <machine/disklabel.h>
     66 #include <machine/cpu.h>
     67 #include <machine/pte.h>
     68 
     69 #include <next68k/next68k/isr.h>
     70 
     71 struct device *booted_device;	/* boot device */
     72 
     73 /*
     74  * The following several variables are related to
     75  * the configuration process, and are used in initializing
     76  * the machine.
     77  */
     78 int	cold;			/* if 1, still working on cold-start */
     79 
     80 void mainbus_attach __P((struct device *, struct device *, void *));
     81 int  mainbus_match __P((struct device *, struct cfdata *, void *));
     82 int  mainbus_print __P((void *, const char *));
     83 
     84 struct mainbus_softc {
     85 	struct device sc_dev;
     86 };
     87 
     88 struct cfattach mainbus_ca = {
     89 	sizeof(struct mainbus_softc), mainbus_match, mainbus_attach
     90 };
     91 
     92 #if 0
     93 struct cfdriver mainbus_cd = {
     94 	NULL, "mainbus", DV_DULL, 0
     95 };
     96 #endif
     97 
     98 static	char *mainbusdevs[] = {
     99         "intio",
    100 	NULL
    101 };
    102 
    103 int
    104 mainbus_match(parent, cf, args)
    105 	struct device *parent;
    106 	struct cfdata *cf;
    107 	void *args;
    108 {
    109 	static int mainbus_matched;
    110 
    111 	if (mainbus_matched)
    112 		return (0);
    113 
    114 	return ((mainbus_matched = 1));
    115 }
    116 
    117 void
    118 mainbus_attach(parent, self, args)
    119 	struct device *parent, *self;
    120 	void *args;
    121 {
    122 	char **devices;
    123 	int i;
    124 
    125 	printf("\n");
    126 
    127 	/*
    128 	 * Attach children.
    129 	 */
    130         devices = mainbusdevs;
    131 
    132 	for (i = 0; devices[i] != NULL; ++i)
    133 		(void)config_found(self, devices[i], mainbus_print);
    134 }
    135 
    136 int
    137 mainbus_print(aux, cp)
    138 	void *aux;
    139 	const char *cp;
    140 {
    141 	char *devname = aux;
    142 
    143 	if (cp)
    144 		printf("%s at %s\n", devname, cp);
    145 
    146 	return (UNCONF);
    147 }
    148 
    149 struct devnametobdevmaj next68k_nam2blk[] = {
    150 	{ "sd",		4 },
    151 	{ "st",		5 },
    152 	{ "cd",		6 },
    153 	{ "md",		13 },
    154 	{ NULL,		0 },
    155 };
    156 
    157 /*
    158  * Determine mass storage and memory configuration for a machine.
    159  */
    160 void
    161 configure()
    162 {
    163 
    164 	booted_device = NULL;	/* set by device drivers (if found) */
    165 
    166 	INTR_SETMASK(0);
    167 
    168 	init_sir();
    169 
    170 	if (config_rootfound("mainbus", NULL) == NULL)
    171 		panic("autoconfig failed, no root");
    172 
    173 	cold = 0;
    174 
    175 	/* Turn on interrupts */
    176 	spl0();
    177 }
    178 
    179 void
    180 cpu_rootconf()
    181 {
    182 
    183 	printf("boot device: %s\n",
    184 		(booted_device) ? booted_device->dv_xname : "<unknown>");
    185 
    186 	setroot(booted_device, 0, next68k_nam2blk);
    187 }
    188 
    189 #if 0 /* @@@ Does anything use this? Is it a required interface? */
    190 /*
    191  * find a device matching "name" and unit number
    192  */
    193 struct device *
    194 getdevunit(name, unit)
    195 	char *name;
    196 	int unit;
    197 {
    198 	struct device *dev = alldevs.tqh_first;
    199 	char num[10], fullname[16];
    200 	int lunit;
    201 
    202 	/* compute length of name and decimal expansion of unit number */
    203 	sprintf(num, "%d", unit);
    204 	lunit = strlen(num);
    205 	if (strlen(name) + lunit >= sizeof(fullname) - 1)
    206 		panic("config_attach: device name too long");
    207 
    208 	strcpy(fullname, name);
    209 	strcat(fullname, num);
    210 
    211 	while (strcmp(dev->dv_xname, fullname) != 0) {
    212 		if ((dev = dev->dv_list.tqe_next) == NULL)
    213 			return NULL;
    214 	}
    215 	return dev;
    216 }
    217 
    218 #endif
    219