xref: /openbsd/sys/arch/armv7/armv7/autoconf.c (revision 771fbea0)
1 /*	$OpenBSD: autoconf.c,v 1.10 2021/03/25 04:12:01 jsg Exp $	*/
2 /*	$NetBSD: autoconf.c,v 1.2 2001/09/05 16:17:36 matt Exp $	*/
3 
4 /*
5  * Copyright (c) 1994-1998 Mark Brinicombe.
6  * Copyright (c) 1994 Brini.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *	This product includes software developed by Mark Brinicombe for
20  *      the NetBSD project.
21  * 4. The name of the company nor the name of the author may be used to
22  *    endorse or promote products derived from this software without specific
23  *    prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
26  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  * RiscBSD kernel project
38  *
39  * autoconf.c
40  *
41  * Autoconfiguration functions
42  */
43 
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/reboot.h>
47 #include <sys/device.h>
48 
49 #include <net/if.h>
50 #include <net/if_types.h>
51 #include <netinet/in.h>
52 #include <netinet/if_ether.h>
53 
54 #include <machine/bootconfig.h>
55 #include <machine/intr.h>
56 
57 struct device *bootdv = NULL;
58 
59 void dumpconf(void);
60 
61 void
62 device_register(struct device *dev, void *aux)
63 {
64 }
65 
66 /*
67  * void cpu_configure()
68  *
69  * Configure all the root devices
70  * The root devices are expected to configure their own children
71  */
72 void
73 cpu_configure(void)
74 {
75 	softintr_init();
76 
77 	/*
78 	 * Since various PCI interrupts could be routed via the ICU
79 	 * (for PCI devices in the bridge) we need to set up the ICU
80 	 * now so that these interrupts can be established correctly
81 	 * i.e. This is a hack.
82 	 */
83 
84 	config_rootfound("mainbus", NULL);
85 
86 	/*
87 	 * We can not know which is our root disk, defer
88 	 * until we can checksum blocks to figure it out.
89 	 */
90 	cold = 0;
91 
92 	/* Time to start taking interrupts so lets open the flood gates .... */
93 	(void)spl0();
94 
95 }
96 
97 /*
98  * Now that we are fully operational, we can checksum the
99  * disks, and using some heuristics, hopefully are able to
100  * always determine the correct root disk.
101  */
102 void
103 diskconf(void)
104 {
105 	size_t	len;
106 	char	*p;
107 	dev_t	tmpdev;
108 	extern uint8_t *bootmac;
109 
110 	if (*boot_file != '\0')
111 		printf("bootfile: %s\n", boot_file);
112 
113 	/* Lookup boot device from boot if not set by configuration */
114 	if (bootdv == NULL) {
115 
116 		/* boot_file is of the form wd0a:/bsd, we want 'wd0a' */
117 		if ((p = strchr(boot_file, ':')) != NULL)
118 			len = p - boot_file;
119 		else
120 			len = strlen(boot_file);
121 		bootdv = parsedisk(boot_file, len, 0, &tmpdev);
122 	}
123 
124 #if defined(NFSCLIENT)
125 	if (bootmac) {
126 		struct ifnet *ifp;
127 
128 		TAILQ_FOREACH(ifp, &ifnet, if_list) {
129 			if (ifp->if_type == IFT_ETHER &&
130 			    memcmp(bootmac, ((struct arpcom *)ifp)->ac_enaddr,
131 			    ETHER_ADDR_LEN) == 0)
132 				break;
133 		}
134 		if (ifp)
135 			bootdv = parsedisk(ifp->if_xname, strlen(ifp->if_xname),
136 			    0, &tmpdev);
137 	}
138 #endif
139 
140 	if (bootdv != NULL)
141 		printf("boot device: %s\n", bootdv->dv_xname);
142 	else
143 		printf("boot device: lookup %s failed.\n", boot_file);
144 	setroot(bootdv, 0, RB_USERREQ);
145 	dumpconf();
146 }
147 
148 struct nam2blk nam2blk[] = {
149 	{ "wd",		16 },
150 	{ "rd",		18 },
151 	{ "vnd",	19 },
152 	{ "sd",		24 },
153 	{ "cd",		26 },
154 	{ NULL,		-1 }
155 };
156 
157