autoconf.c revision 1.2 1 1.2 jmcneill /* $NetBSD: autoconf.c,v 1.2 2024/01/24 21:53:34 jmcneill Exp $ */
2 1.1 jmcneill
3 1.1 jmcneill /*-
4 1.1 jmcneill * Copyright (c) 1990 The Regents of the University of California.
5 1.1 jmcneill * All rights reserved.
6 1.1 jmcneill *
7 1.1 jmcneill * This code is derived from software contributed to Berkeley by
8 1.1 jmcneill * William Jolitz.
9 1.1 jmcneill *
10 1.1 jmcneill * Redistribution and use in source and binary forms, with or without
11 1.1 jmcneill * modification, are permitted provided that the following conditions
12 1.1 jmcneill * are met:
13 1.1 jmcneill * 1. Redistributions of source code must retain the above copyright
14 1.1 jmcneill * notice, this list of conditions and the following disclaimer.
15 1.1 jmcneill * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 jmcneill * notice, this list of conditions and the following disclaimer in the
17 1.1 jmcneill * documentation and/or other materials provided with the distribution.
18 1.1 jmcneill * 3. Neither the name of the University nor the names of its contributors
19 1.1 jmcneill * may be used to endorse or promote products derived from this software
20 1.1 jmcneill * without specific prior written permission.
21 1.1 jmcneill *
22 1.1 jmcneill * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 1.1 jmcneill * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.1 jmcneill * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.1 jmcneill * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 1.1 jmcneill * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.1 jmcneill * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.1 jmcneill * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.1 jmcneill * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.1 jmcneill * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.1 jmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.1 jmcneill * SUCH DAMAGE.
33 1.1 jmcneill *
34 1.1 jmcneill * @(#)autoconf.c 7.1 (Berkeley) 5/9/91
35 1.1 jmcneill */
36 1.1 jmcneill
37 1.1 jmcneill /*
38 1.1 jmcneill * Setup the system to run on the current machine.
39 1.1 jmcneill *
40 1.1 jmcneill * Configure() is called at boot time and initializes the vba
41 1.1 jmcneill * device tables and the memory controller monitoring. Available
42 1.1 jmcneill * devices are determined (from possibilities mentioned in ioconf.c),
43 1.1 jmcneill * and the drivers are initialized.
44 1.1 jmcneill */
45 1.1 jmcneill
46 1.1 jmcneill #include <sys/cdefs.h>
47 1.2 jmcneill __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.2 2024/01/24 21:53:34 jmcneill Exp $");
48 1.1 jmcneill
49 1.1 jmcneill #include <sys/param.h>
50 1.1 jmcneill #include <sys/systm.h>
51 1.1 jmcneill #include <sys/buf.h>
52 1.1 jmcneill #include <sys/disklabel.h>
53 1.1 jmcneill #include <sys/conf.h>
54 1.1 jmcneill #include <sys/reboot.h>
55 1.1 jmcneill #include <sys/device.h>
56 1.2 jmcneill #include <sys/boot_flag.h>
57 1.1 jmcneill
58 1.1 jmcneill #include <powerpc/pte.h>
59 1.1 jmcneill
60 1.2 jmcneill #include <machine/wii.h>
61 1.2 jmcneill
62 1.1 jmcneill void findroot(void);
63 1.1 jmcneill void disable_intr(void);
64 1.1 jmcneill void enable_intr(void);
65 1.1 jmcneill
66 1.2 jmcneill static void parse_cmdline(void);
67 1.2 jmcneill
68 1.1 jmcneill /*
69 1.1 jmcneill * Determine i/o configuration for a machine.
70 1.1 jmcneill */
71 1.1 jmcneill void
72 1.1 jmcneill cpu_configure(void)
73 1.1 jmcneill {
74 1.2 jmcneill parse_cmdline();
75 1.1 jmcneill
76 1.1 jmcneill if (config_rootfound("mainbus", NULL) == NULL)
77 1.1 jmcneill panic("configure: mainbus not configured");
78 1.1 jmcneill
79 1.1 jmcneill genppc_cpu_configure();
80 1.1 jmcneill }
81 1.1 jmcneill
82 1.1 jmcneill void
83 1.1 jmcneill cpu_rootconf(void)
84 1.1 jmcneill {
85 1.1 jmcneill findroot();
86 1.1 jmcneill
87 1.1 jmcneill printf("boot device: %s\n",
88 1.1 jmcneill booted_device ? device_xname(booted_device) : "<unknown>");
89 1.1 jmcneill
90 1.1 jmcneill rootconf();
91 1.1 jmcneill }
92 1.1 jmcneill
93 1.1 jmcneill void
94 1.1 jmcneill findroot(void)
95 1.1 jmcneill {
96 1.2 jmcneill }
97 1.1 jmcneill
98 1.2 jmcneill void
99 1.2 jmcneill device_register(device_t dev, void *aux)
100 1.2 jmcneill {
101 1.2 jmcneill if (bootspec != NULL && strcmp(device_xname(dev), bootspec) == 0) {
102 1.1 jmcneill booted_device = dev;
103 1.1 jmcneill booted_partition = 0;
104 1.1 jmcneill }
105 1.1 jmcneill }
106 1.1 jmcneill
107 1.2 jmcneill static void
108 1.2 jmcneill parse_cmdline(void)
109 1.1 jmcneill {
110 1.2 jmcneill static char bootspec_buf[64];
111 1.2 jmcneill extern char wii_cmdline[];
112 1.2 jmcneill const char *cmdline = wii_cmdline;
113 1.2 jmcneill
114 1.2 jmcneill while (*cmdline != '\0') {
115 1.2 jmcneill const char *cp = cmdline;
116 1.2 jmcneill
117 1.2 jmcneill if (*cp == '-') {
118 1.2 jmcneill for (cp++; *cp != '\0'; cp++) {
119 1.2 jmcneill BOOT_FLAG(*cp, boothowto);
120 1.2 jmcneill }
121 1.2 jmcneill } else if (strncmp(cp, "root=", 5) == 0) {
122 1.2 jmcneill snprintf(bootspec_buf, sizeof(bootspec_buf), "%s",
123 1.2 jmcneill cp + 5);
124 1.2 jmcneill if (bootspec_buf[0] != '\0') {
125 1.2 jmcneill bootspec = bootspec_buf;
126 1.2 jmcneill booted_method = "bootinfo/rootdevice";
127 1.2 jmcneill }
128 1.2 jmcneill }
129 1.2 jmcneill
130 1.2 jmcneill cmdline += strlen(cmdline) + 1;
131 1.2 jmcneill }
132 1.1 jmcneill }
133