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