autoconf.c revision 1.11 1 1.11 thorpej /* $NetBSD: autoconf.c,v 1.11 2021/08/07 16:18:52 thorpej Exp $ */
2 1.2 matt /*-
3 1.2 matt * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
4 1.2 matt * All rights reserved.
5 1.2 matt *
6 1.2 matt * This code is derived from software contributed to The NetBSD Foundation
7 1.2 matt * by Raytheon BBN Technologies Corp and Defense Advanced Research Projects
8 1.2 matt * Agency and which was developed by Matt Thomas of 3am Software Foundry.
9 1.2 matt *
10 1.2 matt * This material is based upon work supported by the Defense Advanced Research
11 1.2 matt * Projects Agency and Space and Naval Warfare Systems Center, Pacific, under
12 1.2 matt * Contract No. N66001-09-C-2073.
13 1.2 matt * Approved for Public Release, Distribution Unlimited
14 1.2 matt *
15 1.2 matt * Redistribution and use in source and binary forms, with or without
16 1.2 matt * modification, are permitted provided that the following conditions
17 1.2 matt * are met:
18 1.2 matt * 1. Redistributions of source code must retain the above copyright
19 1.2 matt * notice, this list of conditions and the following disclaimer.
20 1.2 matt * 2. Redistributions in binary form must reproduce the above copyright
21 1.2 matt * notice, this list of conditions and the following disclaimer in the
22 1.2 matt * documentation and/or other materials provided with the distribution.
23 1.2 matt *
24 1.2 matt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
25 1.2 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 1.2 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 1.2 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
28 1.2 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 1.2 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 1.2 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 1.2 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 1.2 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 1.2 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 1.2 matt * POSSIBILITY OF SUCH DAMAGE.
35 1.2 matt */
36 1.2 matt
37 1.2 matt #include <sys/cdefs.h>
38 1.11 thorpej __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.11 2021/08/07 16:18:52 thorpej Exp $");
39 1.2 matt
40 1.2 matt #define __INTR_PRIVATE
41 1.2 matt
42 1.2 matt #include "locators.h"
43 1.2 matt
44 1.2 matt #include <sys/param.h>
45 1.2 matt #include <sys/conf.h>
46 1.7 matt #include <sys/cpu.h>
47 1.2 matt #include <sys/device.h>
48 1.2 matt #include <sys/intr.h>
49 1.7 matt #include <sys/kernel.h>
50 1.7 matt #include <sys/proc.h>
51 1.2 matt #include <sys/systm.h>
52 1.2 matt
53 1.2 matt #include <powerpc/booke/cpuvar.h>
54 1.2 matt
55 1.2 matt /*
56 1.2 matt * Determine device configuration for a machine.
57 1.2 matt */
58 1.2 matt void
59 1.2 matt cpu_configure(void)
60 1.2 matt {
61 1.2 matt
62 1.5 matt intr_init();
63 1.2 matt calc_delayconst();
64 1.2 matt
65 1.2 matt if (config_rootfound("mainbus", NULL) == NULL)
66 1.2 matt panic("%s: mainbus not configured", __func__);
67 1.2 matt
68 1.2 matt spl0();
69 1.2 matt }
70 1.2 matt
71 1.7 matt static volatile int rootconf_timo = 1;
72 1.7 matt
73 1.2 matt /*
74 1.2 matt * Setup root device.
75 1.2 matt * Configure swap area.
76 1.2 matt */
77 1.2 matt void
78 1.2 matt cpu_rootconf(void)
79 1.2 matt {
80 1.7 matt /*
81 1.7 matt * We wait up to 10 seconds for a bootable device to be found.
82 1.7 matt */
83 1.8 matt while (rootconf_timo > 0) {
84 1.7 matt if (booted_device != NULL) {
85 1.7 matt aprint_normal_dev(booted_device, "boot device\n");
86 1.7 matt break;
87 1.7 matt }
88 1.7 matt
89 1.7 matt if (root_string[0] != '\0'
90 1.7 matt && (booted_device = device_find_by_xname(root_string)) != NULL) {
91 1.7 matt aprint_normal_dev(booted_device, "boot device\n");
92 1.7 matt break;
93 1.7 matt }
94 1.7 matt
95 1.8 matt if (EWOULDBLOCK == kpause("autoconf", true, 1, NULL)) {
96 1.8 matt rootconf_timo--;
97 1.8 matt }
98 1.7 matt }
99 1.2 matt
100 1.6 mlelstv rootconf();
101 1.2 matt }
102 1.2 matt
103 1.2 matt void
104 1.2 matt device_register(device_t dev, void *aux)
105 1.2 matt {
106 1.2 matt if (cpu_md_ops.md_device_register != NULL)
107 1.2 matt (*cpu_md_ops.md_device_register)(dev, aux);
108 1.7 matt
109 1.7 matt if (booted_device == NULL) {
110 1.7 matt if (root_string[0] != '\0'
111 1.7 matt && !strcmp(device_xname(dev), root_string)) {
112 1.7 matt aprint_normal_dev(dev, "boot device\n");
113 1.7 matt booted_device = dev;
114 1.7 matt } else {
115 1.7 matt rootconf_timo = 5 * hz;
116 1.7 matt }
117 1.7 matt }
118 1.2 matt }
119 1.2 matt
120 1.2 matt static bool mainbus_found;
121 1.2 matt
122 1.2 matt static int
123 1.2 matt mainbus_print(void *aux, const char *pnp)
124 1.2 matt {
125 1.2 matt struct mainbus_attach_args *ma = aux;
126 1.2 matt
127 1.2 matt if (pnp != NULL)
128 1.2 matt return QUIET;
129 1.2 matt
130 1.2 matt if (pnp)
131 1.2 matt aprint_normal("%s at %s", ma->ma_name, pnp);
132 1.2 matt if (ma->ma_node != MAINBUSCF_NODE_DEFAULT)
133 1.2 matt aprint_normal(" node %d", ma->ma_node);
134 1.2 matt
135 1.2 matt return (UNCONF);
136 1.2 matt }
137 1.2 matt
138 1.2 matt static int
139 1.2 matt mainbus_match(device_t parent, cfdata_t cf, void *aux)
140 1.2 matt {
141 1.2 matt return mainbus_found == false;
142 1.2 matt }
143 1.2 matt
144 1.2 matt static void
145 1.2 matt mainbus_attach(device_t parent, device_t self, void *aux)
146 1.2 matt {
147 1.2 matt struct mainbus_attach_args ma;
148 1.2 matt
149 1.2 matt mainbus_found = true;
150 1.2 matt
151 1.2 matt aprint_normal("\n");
152 1.2 matt
153 1.2 matt ma.ma_name = "cpunode";
154 1.2 matt ma.ma_node = 0;
155 1.2 matt ma.ma_memt = curcpu()->ci_softc->cpu_bst;
156 1.3 matt ma.ma_le_memt = curcpu()->ci_softc->cpu_le_bst;
157 1.2 matt ma.ma_dmat = &booke_bus_dma_tag;
158 1.2 matt
159 1.11 thorpej config_found(self, &ma, mainbus_print, CFARGS_NONE);
160 1.2 matt }
161 1.2 matt
162 1.2 matt CFATTACH_DECL_NEW(mainbus, 0, mainbus_match, mainbus_attach, NULL, NULL);
163