1/*	$NetBSD$	*/
2
3/*
4 * Copyright (c) 1988 University of Utah.
5 * Copyright (c) 1992, 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 and Ralph Campbell.
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.31 91/01/21
37 *
38 *	@(#)autoconf.c	8.1 (Berkeley) 6/10/93
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#define __INTR_PRIVATE
50
51#include <sys/cdefs.h>
52__KERNEL_RCSID(0, "$NetBSD$");
53
54#include <sys/param.h>
55#include <sys/systm.h>
56#include <sys/buf.h>
57#include <sys/conf.h>
58#include <sys/reboot.h>
59#include <sys/device.h>
60#include <sys/intr.h>
61#include <sys/cpu.h>
62
63#include <dev/scsipi/scsi_all.h>
64#include <dev/scsipi/scsipi_all.h>
65#include <dev/scsipi/scsiconf.h>
66
67#include <machine/adrsmap.h>
68#include <machine/romcall.h>
69
70#include <newsmips/newsmips/machid.h>
71
72#include "scsibus.h"
73
74/*
75 * The following several variables are related to
76 * the configuration process, and are used in initializing
77 * the machine.
78 */
79int	cpuspeed = 10;	/* approx # instr per usec. */
80
81static void findroot(void);
82
83/*
84 * Determine mass storage and memory configuration for a machine.
85 * Print CPU type, and then iterate over an array of devices
86 * found on the baseboard or in turbochannel option slots.
87 * Once devices are configured, enable interrupts, and probe
88 * for attached scsi devices.
89 */
90void
91cpu_configure(void)
92{
93
94	/*
95	 * Kick off autoconfiguration
96	 */
97	(*disable_intr)();
98	(void)splhigh();
99
100	if (config_rootfound("mainbus", NULL) == NULL)
101		panic("no mainbus found");
102
103	/* Enable hardware interrupt registers. */
104	(*enable_intr)();
105
106	/* Configuration is finished, turn on interrupts. */
107	spl0();		/* enable all source forcing SOFT_INTs cleared */
108}
109
110void
111cpu_rootconf(void)
112{
113	findroot();
114
115	printf("boot device: %s\n",
116	       booted_device ? booted_device->dv_xname : "<unknown>");
117
118	rootconf();
119}
120
121u_long	bootdev = 0;		/* should be dev_t, but not until 32 bits */
122
123/*
124 * Attempt to find the device from which we were booted.
125 */
126static void
127findroot(void)
128{
129	int ctlr, unit, part, type;
130	device_t dv;
131
132	if (BOOTDEV_MAG(bootdev) != 5)	/* NEWS-OS's B_DEVMAGIC */
133		return;
134
135	ctlr = BOOTDEV_CTLR(bootdev);	/* SCSI ID */
136	unit = BOOTDEV_UNIT(bootdev);
137	part = BOOTDEV_PART(bootdev);	/* LUN */
138	type = BOOTDEV_TYPE(bootdev);
139
140	if (type != BOOTDEV_SD)
141		return;
142
143	/*
144	 * XXX assumes only one controller exists.
145	 */
146	if ((dv = device_find_by_xname("scsibus0")) != NULL) {
147#if NSCSIBUS > 0
148		struct scsibus_softc *sdv = device_private(dv);
149		struct scsipi_periph *periph;
150
151		periph = scsipi_lookup_periph(sdv->sc_channel, ctlr, 0);
152		if (periph != NULL) {
153			booted_device = periph->periph_dev;
154			booted_partition = part;
155		}
156#endif /* NSCSIBUS > 0 */
157	}
158}
159