1/*	$NetBSD$	*/
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$");
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
70volatile u_long *intrstat;
71volatile u_long *intrmask;
72
73static struct device *getdevunit(const char *, int);
74static int devidentparse(const char *, int *, int *, int *);
75static int atoi(const char *);
76
77struct device_equiv {
78	const char *alias;
79	const char *real;
80};
81static struct device_equiv device_equiv[] = {
82	{ "en", "xe" },
83	{ "tp", "xe" },
84};
85static int ndevice_equivs = (sizeof(device_equiv)/sizeof(device_equiv[0]));
86
87/*
88 * Determine mass storage and memory configuration for a machine.
89 */
90void
91cpu_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	/* Initialize the interrupt handlers. */
100	isrinit();
101
102#if 0
103	dma_rev = ((volatile u_char *)IIOV(NEXT_P_SCR1))[1];
104	switch (dma_rev) {
105	case 0:
106		intrmask = (volatile u_long *)IIOV(NEXT_P_INTRMASK_0);
107		intrstat = (volatile u_long *)IIOV(NEXT_P_INTRSTAT_0);
108		/* dspreg = (volatile u_long *)IIOV(0x2007000); */
109		break;
110	case 1:
111		intrmask = (volatile u_long *)IIOV(NEXT_P_INTRMASK);
112		intrstat = (volatile u_long *)IIOV(NEXT_P_INTRSTAT);
113		/* dspreg = (volatile u_long *)IIOV(0x2108000); */
114		break;
115	default:
116		panic("unknown DMA chip revision");
117	}
118#else
119	intrmask = (volatile u_long *)IIOV(rom_intrmask);
120	intrstat = (volatile u_long *)IIOV(rom_intrstat);
121	printf ("intrmask: %p\n", intrmask);
122	printf ("intrstat: %p\n", intrstat);
123#endif
124
125	INTR_SETMASK(0);
126
127	if (config_rootfound("mainbus", NULL) == NULL)
128		panic("autoconfig failed, no root");
129
130	/* Turn on interrupts */
131	spl0();
132}
133
134void
135cpu_rootconf(void)
136{
137	int count, lun, part;
138
139	count = lun = part = 0;
140
141	devidentparse (rom_boot_info, &count, &lun, &part);
142	booted_device = getdevunit (rom_boot_dev, count);
143
144	printf("boot device: %s\n",
145		(booted_device) ? booted_device->dv_xname : "<unknown>");
146
147	rootconf();
148}
149
150/*
151 * find a device matching "name" and unit number
152 */
153static struct device *
154getdevunit(const char *name, int unit)
155{
156	int i;
157
158	for (i = 0; i < ndevice_equivs; i++)
159		if (device_equiv->alias && strcmp (name, device_equiv->alias) == 0)
160			name = device_equiv->real;
161
162	return device_find_by_driver_unit(name, unit);
163}
164
165/*
166 * Parse a device ident.
167 *
168 * Format:
169 *   (count, lun, part)
170 */
171static int
172devidentparse(const char *spec, int *count, int *lun, int *part)
173{
174	int i;
175	const char *args[3];
176
177	if (*spec == '(') {
178		/* tokenize device ident */
179		args[0] = ++spec;
180		for (i = 1; *spec && *spec != ')' && i<3; spec++) {
181			if (*spec == ',')
182				args[i++] = ++spec;
183		}
184		if (*spec != ')')
185			goto baddev;
186
187		switch(i) {
188		case 3:
189			*count  = atoi(args[0]);
190			*lun  = atoi(args[1]);
191			*part  = atoi(args[2]);
192			break;
193		case 2:
194			*lun  = atoi(args[0]);
195			*part  = atoi(args[1]);
196			break;
197		case 1:
198			*part  = atoi(args[0]);
199			break;
200		case 0:
201			break;
202		}
203	}
204	else
205		goto baddev;
206
207	return 0;
208
209 baddev:
210	return ENXIO;
211}
212
213static int
214atoi(const char *s)
215{
216	int val = 0;
217
218	while(isdigit(*s))
219		val = val * 10 + (*s++ - '0');
220	return val;
221}
222