xref: /netbsd/sys/arch/prep/prep/autoconf.c (revision c4a72b64)
1 /*	$NetBSD: autoconf.c,v 1.6 2002/09/06 13:18:43 gehenna Exp $	*/
2 
3 /*-
4  * Copyright (c) 1990 The Regents of the University of California.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * William Jolitz.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the University of
21  *	California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *	@(#)autoconf.c	7.1 (Berkeley) 5/9/91
39  */
40 
41 /*
42  * Setup the system to run on the current machine.
43  *
44  * Configure() is called at boot time and initializes the vba
45  * device tables and the memory controller monitoring.  Available
46  * devices are determined (from possibilities mentioned in ioconf.c),
47  * and the drivers are initialized.
48  */
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/buf.h>
52 #include <sys/dkstat.h>
53 #include <sys/disklabel.h>
54 #include <sys/conf.h>
55 #include <sys/reboot.h>
56 #include <sys/device.h>
57 
58 #include <machine/pte.h>
59 #include <machine/intr.h>
60 
61 struct device *booted_device;
62 int booted_partition;
63 
64 static void findroot __P((void));
65 
66 /*
67  * Determine i/o configuration for a machine.
68  */
69 void
70 cpu_configure()
71 {
72 	/* startrtclock(); */
73 
74 	if (config_rootfound("mainbus", NULL) == NULL)
75 		panic("configure: mainbus not configured");
76 
77 	printf("biomask %x netmask %x ttymask %x\n",
78 	    imask[IPL_BIO] & 0x1fffffff,
79 	    imask[IPL_NET] & 0x1fffffff,
80 	    imask[IPL_TTY] & 0x1fffffff);
81 
82 	spl0();
83 }
84 
85 void
86 cpu_rootconf()
87 {
88 	findroot();
89 
90 	printf("boot device: %s\n",
91 	    booted_device ? booted_device->dv_xname : "<unknown>");
92 
93 	setroot(booted_device, booted_partition);
94 }
95 
96 u_long	bootdev = 0;		/* should be dev_t, but not until 32 bits */
97 
98 /*
99  * Attempt to find the device from which we were booted.
100  * If we can do so, and not instructed not to do so,
101  * change rootdev to correspond to the load device.
102  */
103 void
104 findroot(void)
105 {
106 	int unit, part;
107 	struct device *dv;
108 	char buf[32];
109 	const char *name;
110 
111 #if 0
112 	printf("howto %x bootdev %x ", boothowto, bootdev);
113 #endif
114 
115 	if ((bootdev & B_MAGICMASK) != (u_long)B_DEVMAGIC)
116 		return;
117 
118 	name = devsw_blk2name((bootdev >> B_TYPESHIFT) & B_TYPEMASK);
119 	if (name == NULL)
120 		return;
121 
122 	part = (bootdev >> B_PARTITIONSHIFT) & B_PARTITIONMASK;
123 	unit = (bootdev >> B_UNITSHIFT) & B_UNITMASK;
124 
125 	sprintf(buf, "%s%d", name, unit);
126 	for (dv = alldevs.tqh_first; dv != NULL; dv = dv->dv_list.tqe_next) {
127 		if (strcmp(buf, dv->dv_xname) == 0) {
128 			booted_device = dv;
129 			booted_partition = part;
130 			return;
131 		}
132 	}
133 }
134