xref: /netbsd-src/sys/arch/shark/shark/autoconf.c (revision e5fbc36ada28f9b9a5836ecffaf4a06aa1ebb687)
1 /*	$NetBSD: autoconf.c,v 1.22 2023/12/20 15:34:45 thorpej Exp $	*/
2 
3 /*
4  * Copyright (c) 1994-1998 Mark Brinicombe.
5  * Copyright (c) 1994 Brini.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *	This product includes software developed by Mark Brinicombe for
19  *      the NetBSD project.
20  * 4. The name of the company nor the name of the author may be used to
21  *    endorse or promote products derived from this software without specific
22  *    prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
25  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30  * 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  * RiscBSD kernel project
37  *
38  * autoconf.c
39  *
40  * Autoconfiguration functions
41  *
42  * Created      : 08/10/94
43  */
44 
45 #include <sys/cdefs.h>
46 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.22 2023/12/20 15:34:45 thorpej Exp $");
47 
48 #include "opt_md.h"
49 
50 #include <sys/param.h>
51 #include <sys/systm.h>
52 #include <sys/reboot.h>
53 #include <sys/disklabel.h>
54 #include <sys/device.h>
55 #include <sys/conf.h>
56 #include <sys/intr.h>
57 #include <sys/kernel.h>
58 
59 #include <uvm/uvm_extern.h>
60 
61 #include <arm/arm32/machdep.h>
62 
63 #include <machine/bootconfig.h>
64 #include <machine/irqhandler.h>
65 
66 #include "isa.h"
67 
68 #ifdef SHARK
69 #include <shark/shark/sequoia.h>
70 extern void	ofrootfound(void);
71 extern void	ofw_device_register(device_t, void *);
72 extern void	startrtclock(void);
73 #endif
74 
75 #if defined(OFWGENCFG) || defined(SHARK)
76 /* Temporary for SHARK! */
77 extern void ofw_device_register(device_t, void *);
78 #include <machine/ofw.h>
79 #endif
80 
81 extern dev_t dumpdev;
82 
83 void isa_intr_init(void);
84 
85 #ifndef MEMORY_DISK_IS_ROOT
86 static void get_device(char *name);
87 static void set_root_device(void);
88 #endif
89 
90 #ifndef MEMORY_DISK_IS_ROOT
91 /* Decode a device name to a major and minor number */
92 
93 static void
get_device(char * name)94 get_device(char *name)
95 {
96 	int unit, part;
97 	char devname[16], *cp;
98 	device_t dv;
99 
100 	if (strncmp(name, "/dev/", 5) == 0)
101 		name += 5;
102 
103 	if (devsw_name2blk(name, devname, sizeof(devname)) == -1)
104 		return;
105 
106 	name += strlen(devname);
107 	unit = part = 0;
108 
109 	cp = name;
110 	while (*cp >= '0' && *cp <= '9')
111 		unit = (unit * 10) + (*cp++ - '0');
112 	if (cp == name)
113 		return;
114 
115 	if (*cp >= 'a' && *cp <= ('a' + MAXPARTITIONS))
116 		part = *cp - 'a';
117 	else if (*cp != '\0' && *cp != ' ')
118 		return;
119 	if ((dv = device_find_by_driver_unit(devname, unit)) != NULL) {
120 		booted_device = dv;
121 		booted_partition = part;
122 	}
123 }
124 
125 
126 /* Set the rootdev variable from the root specifier in the boot args */
127 
128 static void
set_root_device(void)129 set_root_device(void)
130 {
131 	char *ptr;
132 
133 	if (boot_file)
134 		get_device(boot_file);
135 	if (boot_args &&
136 	    get_bootconf_option(boot_args, "root", BOOTOPT_TYPE_STRING, &ptr))
137 		get_device(ptr);
138 }
139 #endif
140 
141 /*
142  * Set up the root device from the boot args
143  */
144 void
cpu_rootconf(void)145 cpu_rootconf(void)
146 {
147 #ifndef MEMORY_DISK_IS_ROOT
148 	set_root_device();
149 
150 	printf("boot device: %s\n",
151 	    booted_device != NULL ? device_xname(booted_device) : "<unknown>");
152 #endif
153 	rootconf();
154 }
155 
156 
157 /*
158  * void cpu_configure()
159  *
160  * Configure all the root devices
161  * The root devices are expected to configure their own children
162  */
163 
164 void
cpu_configure(void)165 cpu_configure(void)
166 {
167 	/*
168 	 * Configure all the roots.
169 	 * We have to have a mainbus
170 	 */
171 
172 #ifdef SHARK
173 	sequoiaInit();
174 	startrtclock();
175 #endif
176 
177 	/*
178 	 * Since the ICU is not standard on the ARM we don't know
179 	 * if we have one until we find a bridge.
180 	 * Since various PCI interrupts could be routed via the ICU
181 	 * (for PCI devices in the bridge) we need to set up the ICU
182 	 * now so that these interrupts can be established correctly
183 	 * i.e. This is a hack.
184 	 */
185 #if NISA > 0 && !defined(SHARK)
186 	isa_intr_init();
187 #endif
188 
189 	config_rootfound("mainbus", NULL);
190 #if defined(OFWGENCFG) || defined(SHARK)
191 	/* Temporary for SHARK! */
192 	ofrootfound();
193 #endif
194 
195 #if defined(DIAGNOSTIC)
196 	dump_spl_masks();
197 #endif /* defined(DIAGNOSTIC) */
198 
199 	/* Time to start taking interrupts so lets open the flood gates .... */
200 	(void)spl0();
201 }
202 
203 void
device_register(device_t dev,void * aux)204 device_register(device_t dev, void *aux)
205 {
206 #if defined(OFWGENCFG) || defined(SHARK)
207 	/* Temporary for SHARK! */
208 	ofw_device_register(dev, aux);
209 #endif
210 }
211 /* End of autoconf.c */
212