xref: /netbsd/sys/arch/mvmeppc/mvmeppc/autoconf.c (revision bf9ec67e)
1 /*	$NetBSD: autoconf.c,v 1.1 2002/02/27 21:02:23 scw 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 	    (u_short)imask[IPL_BIO], (u_short)imask[IPL_NET],
79 	    (u_short)imask[IPL_TTY]);
80 
81 	spl0();
82 }
83 
84 void
85 cpu_rootconf()
86 {
87 	findroot();
88 
89 	printf("boot device: %s\n",
90 	    booted_device ? booted_device->dv_xname : "<unknown>");
91 
92 	setroot(booted_device, booted_partition);
93 }
94 
95 u_long	bootdev = 0;		/* should be dev_t, but not until 32 bits */
96 
97 /*
98  * Attempt to find the device from which we were booted.
99  * If we can do so, and not instructed not to do so,
100  * change rootdev to correspond to the load device.
101  */
102 void
103 findroot(void)
104 {
105 	int i, majdev, unit, part;
106 	struct device *dv;
107 	char buf[32];
108 
109 #if 0
110 	printf("howto %x bootdev %x ", boothowto, bootdev);
111 #endif
112 
113 	if ((bootdev & B_MAGICMASK) != (u_long)B_DEVMAGIC)
114 		return;
115 
116 	majdev = (bootdev >> B_TYPESHIFT) & B_TYPEMASK;
117 	for (i = 0; dev_name2blk[i].d_name != NULL; i++)
118 		if (majdev == dev_name2blk[i].d_maj)
119 			break;
120 	if (dev_name2blk[i].d_name == NULL)
121 		return;
122 
123 	part = (bootdev >> B_PARTITIONSHIFT) & B_PARTITIONMASK;
124 	unit = (bootdev >> B_UNITSHIFT) & B_UNITMASK;
125 
126 	sprintf(buf, "%s%d", dev_name2blk[i].d_name, unit);
127 	for (dv = alldevs.tqh_first; dv != NULL;
128 	    dv = dv->dv_list.tqe_next) {
129 		if (strcmp(buf, dv->dv_xname) == 0) {
130 			booted_device = dv;
131 			booted_partition = part;
132 			return;
133 		}
134 	}
135 }
136