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