xref: /netbsd/sys/arch/hpcsh/hpcsh/autoconf.c (revision bf9ec67e)
1 /*	$NetBSD: autoconf.c,v 1.9 2002/05/09 12:40:03 uch Exp $	*/
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. All advertising materials mentioning features or use of this software
21  *    must display the following acknowledgement:
22  *	This product includes software developed by the University of
23  *	California, Berkeley and its contributors.
24  * 4. Neither the name of the University nor the names of its contributors
25  *    may be used to endorse or promote products derived from this software
26  *    without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38  * SUCH DAMAGE.
39  *
40  * from: Utah Hdr: autoconf.c 1.31 91/01/21
41  *
42  *	@(#)autoconf.c	8.1 (Berkeley) 6/10/93
43  */
44 
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/conf.h>
48 #include <sys/disklabel.h>
49 #include <sys/device.h>
50 
51 #include <sh3/exception.h>
52 #include <machine/bus.h>
53 #include <machine/intr.h>
54 
55 #include <machine/config_hook.h>
56 #include <machine/autoconf.h>
57 
58 #include <hpcsh/dev/hd64461/hd64461var.h>
59 #include <hpcsh/dev/hd64465/hd64465var.h>
60 
61 static struct device *booted_device;
62 static int booted_partition;
63 static char booted_device_name[16];
64 static void get_device(char *name);
65 
66 void
67 cpu_configure()
68 {
69 
70 	config_hook_init();
71 	softintr_init();
72 	hd6446x_intr_init();
73 #ifdef SH3
74 	if (CPU_IS_SH3)	/* HD64461 (Jornada 690, HP620LX, HPW-50PA) */
75 		intc_intr_establish(SH7709_INTEVT2_IRQ4, IST_LEVEL, IPL_TTY,
76 		    (void *)1/* fake. see intc_intr(). */, 0);
77 #endif
78 #ifdef SH4
79 	if (CPU_IS_SH4)	/* HD64465 (HPW-650PA) */
80 		intc_intr_establish(SH_INTEVT_IRL11, IST_LEVEL, IPL_TTY,
81 		    (void *)1/* fake. see intc_intr(). */, 0);
82 #endif
83 
84 	/* Kick off autoconfiguration. */
85 	splhigh();
86 	if (config_rootfound("mainbus", "mainbus") == NULL)
87 		panic("no mainbus found");
88 
89 	/* Configuration is finished, turn on interrupts. */
90 	spl0();
91 }
92 
93 void
94 cpu_rootconf()
95 {
96 
97 	get_device(booted_device_name);
98 
99 	printf("boot device: %s\n",
100 	       booted_device ? booted_device->dv_xname : "<unknown>");
101 
102 	setroot(booted_device, booted_partition);
103 }
104 
105 void
106 makebootdev(const char *cp)
107 {
108 
109 	strncpy(booted_device_name, cp, 16);
110 }
111 
112 static void
113 get_device(char *name)
114 {
115 	int loop, unit, part;
116 	char buf[32], *cp;
117 	struct device *dv;
118 
119 	if (strncmp(name, "/dev/", 5) == 0)
120 		name += 5;
121 
122 	for (loop = 0; dev_name2blk[loop].d_name != NULL; ++loop) {
123 		if (strncmp(name, dev_name2blk[loop].d_name,
124 		    strlen(dev_name2blk[loop].d_name)) == 0) {
125 			name += strlen(dev_name2blk[loop].d_name);
126 			unit = part = 0;
127 
128 			cp = name;
129 			while (*cp >= '0' && *cp <= '9')
130 				unit = (unit * 10) + (*cp++ - '0');
131 			if (cp == name)
132 				return;
133 
134 			if (*cp >= 'a' && *cp <= ('a' + MAXPARTITIONS))
135 				part = *cp - 'a';
136 			else if (*cp != '\0' && *cp != ' ')
137 				return;
138 			sprintf(buf, "%s%d", dev_name2blk[loop].d_name, unit);
139 			for (dv = alldevs.tqh_first; dv != NULL;
140 			    dv = dv->dv_list.tqe_next) {
141 				if (strcmp(buf, dv->dv_xname) == 0) {
142 					booted_device = dv;
143 					booted_partition = part;
144 					return;
145 				}
146 			}
147 		}
148 	}
149 }
150