Home | History | Annotate | Line # | Download | only in next68k
autoconf.c revision 1.24
      1 /*	$NetBSD: autoconf.c,v 1.24 2011/02/08 20:20:21 rmind 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. Neither the name of the University nor the names of its contributors
     21  *    may be used to endorse or promote products derived from this software
     22  *    without specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  * SUCH DAMAGE.
     35  *
     36  * from: Utah $Hdr: autoconf.c 1.36 92/12/20$
     37  *
     38  *	@(#)autoconf.c  8.2 (Berkeley) 1/12/94
     39  */
     40 
     41 /*
     42  * Setup the system to run on the current machine.
     43  *
     44  * Configure() is called at boot time.  Available
     45  * devices are determined (from possibilities mentioned in ioconf.c),
     46  * and the drivers are initialized.
     47  */
     48 
     49 #include <sys/cdefs.h>
     50 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.24 2011/02/08 20:20:21 rmind Exp $");
     51 
     52 #include <sys/param.h>
     53 #include <sys/systm.h>
     54 #include <sys/buf.h>
     55 #include <sys/conf.h>
     56 #include <sys/reboot.h>
     57 #include <sys/device.h>
     58 
     59 #include <machine/vmparam.h>
     60 #include <machine/autoconf.h>
     61 #include <machine/disklabel.h>
     62 #include <machine/cpu.h>
     63 #include <machine/pte.h>
     64 
     65 #include <next68k/next68k/isr.h>
     66 #include <next68k/next68k/nextrom.h>
     67 
     68 #include <next68k/dev/intiovar.h>
     69 
     70 volatile u_long *intrstat;
     71 volatile u_long *intrmask;
     72 
     73 static struct device *getdevunit(const char *, int);
     74 static int devidentparse(const char *, int *, int *, int *);
     75 static int atoi(const char *);
     76 
     77 struct device_equiv {
     78 	const char *alias;
     79 	const char *real;
     80 };
     81 static struct device_equiv device_equiv[] = {
     82 	{ "en", "xe" },
     83 	{ "tp", "xe" },
     84 };
     85 static int ndevice_equivs = (sizeof(device_equiv)/sizeof(device_equiv[0]));
     86 
     87 /*
     88  * Determine mass storage and memory configuration for a machine.
     89  */
     90 void
     91 cpu_configure(void)
     92 {
     93 /* 	int dma_rev; */
     94 	extern u_int rom_intrmask;
     95 	extern u_int rom_intrstat;
     96 
     97 	booted_device = NULL;	/* set by device drivers (if found) */
     98 
     99 #if 0
    100 	dma_rev = ((volatile u_char *)IIOV(NEXT_P_SCR1))[1];
    101 	switch (dma_rev) {
    102 	case 0:
    103 		intrmask = (volatile u_long *)IIOV(NEXT_P_INTRMASK_0);
    104 		intrstat = (volatile u_long *)IIOV(NEXT_P_INTRSTAT_0);
    105 		/* dspreg = (volatile u_long *)IIOV(0x2007000); */
    106 		break;
    107 	case 1:
    108 		intrmask = (volatile u_long *)IIOV(NEXT_P_INTRMASK);
    109 		intrstat = (volatile u_long *)IIOV(NEXT_P_INTRSTAT);
    110 		/* dspreg = (volatile u_long *)IIOV(0x2108000); */
    111 		break;
    112 	default:
    113 		panic("unknown DMA chip revision");
    114 	}
    115 #else
    116 	intrmask = (volatile u_long *)IIOV(rom_intrmask);
    117 	intrstat = (volatile u_long *)IIOV(rom_intrstat);
    118 	printf ("intrmask: %p\n", intrmask);
    119 	printf ("intrstat: %p\n", intrstat);
    120 #endif
    121 
    122 	INTR_SETMASK(0);
    123 
    124 	if (config_rootfound("mainbus", NULL) == NULL)
    125 		panic("autoconfig failed, no root");
    126 
    127 	/* Turn on interrupts */
    128 	spl0();
    129 }
    130 
    131 void
    132 cpu_rootconf(void)
    133 {
    134 	int count, lun, part;
    135 
    136 	count = lun = part = 0;
    137 
    138 	devidentparse (rom_boot_info, &count, &lun, &part);
    139 	booted_device = getdevunit (rom_boot_dev, count);
    140 
    141 	printf("boot device: %s\n",
    142 		(booted_device) ? booted_device->dv_xname : "<unknown>");
    143 
    144 	setroot(booted_device, part);
    145 }
    146 
    147 /*
    148  * find a device matching "name" and unit number
    149  */
    150 static struct device *
    151 getdevunit(const char *name, int unit)
    152 {
    153 	int i;
    154 
    155 	for (i = 0; i < ndevice_equivs; i++)
    156 		if (device_equiv->alias && strcmp (name, device_equiv->alias) == 0)
    157 			name = device_equiv->real;
    158 
    159 	return device_find_by_driver_unit(name, unit);
    160 }
    161 
    162 /*
    163  * Parse a device ident.
    164  *
    165  * Format:
    166  *   (count, lun, part)
    167  */
    168 static int
    169 devidentparse(const char *spec, int *count, int *lun, int *part)
    170 {
    171 	int i;
    172 	const char *args[3];
    173 
    174 	if (*spec == '(') {
    175 		/* tokenize device ident */
    176 		args[0] = ++spec;
    177 		for (i = 1; *spec && *spec != ')' && i<3; spec++) {
    178 			if (*spec == ',')
    179 				args[i++] = ++spec;
    180 		}
    181 		if (*spec != ')')
    182 			goto baddev;
    183 
    184 		switch(i) {
    185 		case 3:
    186 			*count  = atoi(args[0]);
    187 			*lun  = atoi(args[1]);
    188 			*part  = atoi(args[2]);
    189 			break;
    190 		case 2:
    191 			*lun  = atoi(args[0]);
    192 			*part  = atoi(args[1]);
    193 			break;
    194 		case 1:
    195 			*part  = atoi(args[0]);
    196 			break;
    197 		case 0:
    198 			break;
    199 		}
    200 	}
    201 	else
    202 		goto baddev;
    203 
    204 	return 0;
    205 
    206  baddev:
    207 	return ENXIO;
    208 }
    209 
    210 static int
    211 atoi(const char *s)
    212 {
    213 	int val = 0;
    214 
    215 	while(isdigit(*s))
    216 		val = val * 10 + (*s++ - '0');
    217 	return val;
    218 }
    219