xref: /netbsd-src/sys/arch/evbppc/mpc85xx/autoconf.c (revision c7fb772b85b2b5d4cfb282f868f454b4701534fd)
1*c7fb772bSthorpej /*	$NetBSD: autoconf.c,v 1.11 2021/08/07 16:18:52 thorpej Exp $	*/
2262e1f2bSmatt /*-
3262e1f2bSmatt  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
4262e1f2bSmatt  * All rights reserved.
5262e1f2bSmatt  *
6262e1f2bSmatt  * This code is derived from software contributed to The NetBSD Foundation
7262e1f2bSmatt  * by Raytheon BBN Technologies Corp and Defense Advanced Research Projects
8262e1f2bSmatt  * Agency and which was developed by Matt Thomas of 3am Software Foundry.
9262e1f2bSmatt  *
10262e1f2bSmatt  * This material is based upon work supported by the Defense Advanced Research
11262e1f2bSmatt  * Projects Agency and Space and Naval Warfare Systems Center, Pacific, under
12262e1f2bSmatt  * Contract No. N66001-09-C-2073.
13262e1f2bSmatt  * Approved for Public Release, Distribution Unlimited
14262e1f2bSmatt  *
15262e1f2bSmatt  * Redistribution and use in source and binary forms, with or without
16262e1f2bSmatt  * modification, are permitted provided that the following conditions
17262e1f2bSmatt  * are met:
18262e1f2bSmatt  * 1. Redistributions of source code must retain the above copyright
19262e1f2bSmatt  *    notice, this list of conditions and the following disclaimer.
20262e1f2bSmatt  * 2. Redistributions in binary form must reproduce the above copyright
21262e1f2bSmatt  *    notice, this list of conditions and the following disclaimer in the
22262e1f2bSmatt  *    documentation and/or other materials provided with the distribution.
23262e1f2bSmatt  *
24262e1f2bSmatt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
25262e1f2bSmatt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26262e1f2bSmatt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27262e1f2bSmatt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
28262e1f2bSmatt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29262e1f2bSmatt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30262e1f2bSmatt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31262e1f2bSmatt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32262e1f2bSmatt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33262e1f2bSmatt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34262e1f2bSmatt  * POSSIBILITY OF SUCH DAMAGE.
35262e1f2bSmatt  */
36262e1f2bSmatt 
37262e1f2bSmatt #include <sys/cdefs.h>
38*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.11 2021/08/07 16:18:52 thorpej Exp $");
39262e1f2bSmatt 
40262e1f2bSmatt #define __INTR_PRIVATE
41262e1f2bSmatt 
42262e1f2bSmatt #include "locators.h"
43262e1f2bSmatt 
44262e1f2bSmatt #include <sys/param.h>
45262e1f2bSmatt #include <sys/conf.h>
46bc80e114Smatt #include <sys/cpu.h>
47262e1f2bSmatt #include <sys/device.h>
48262e1f2bSmatt #include <sys/intr.h>
49bc80e114Smatt #include <sys/kernel.h>
50bc80e114Smatt #include <sys/proc.h>
51262e1f2bSmatt #include <sys/systm.h>
5296d8734bSmatt 
53262e1f2bSmatt #include <powerpc/booke/cpuvar.h>
54262e1f2bSmatt 
55262e1f2bSmatt /*
56262e1f2bSmatt  * Determine device configuration for a machine.
57262e1f2bSmatt  */
58262e1f2bSmatt void
cpu_configure(void)59262e1f2bSmatt cpu_configure(void)
60262e1f2bSmatt {
61262e1f2bSmatt 
62b1e55671Smatt 	intr_init();
63262e1f2bSmatt 	calc_delayconst();
64262e1f2bSmatt 
65262e1f2bSmatt 	if (config_rootfound("mainbus", NULL) == NULL)
66262e1f2bSmatt 		panic("%s: mainbus not configured", __func__);
67262e1f2bSmatt 
68262e1f2bSmatt 	spl0();
69262e1f2bSmatt }
70262e1f2bSmatt 
71bc80e114Smatt static volatile int rootconf_timo = 1;
72bc80e114Smatt 
73262e1f2bSmatt /*
74262e1f2bSmatt  * Setup root device.
75262e1f2bSmatt  * Configure swap area.
76262e1f2bSmatt  */
77262e1f2bSmatt void
cpu_rootconf(void)78262e1f2bSmatt cpu_rootconf(void)
79262e1f2bSmatt {
80bc80e114Smatt 	/*
81bc80e114Smatt 	 * We wait up to 10 seconds for a bootable device to be found.
82bc80e114Smatt 	 */
83d4eadb8eSmatt 	while (rootconf_timo > 0) {
84bc80e114Smatt 		if (booted_device != NULL) {
85bc80e114Smatt 			aprint_normal_dev(booted_device, "boot device\n");
86bc80e114Smatt 			break;
87bc80e114Smatt 		}
88bc80e114Smatt 
89bc80e114Smatt 		if (root_string[0] != '\0'
90bc80e114Smatt 		    && (booted_device = device_find_by_xname(root_string)) != NULL) {
91bc80e114Smatt 			aprint_normal_dev(booted_device, "boot device\n");
92bc80e114Smatt 			break;
93bc80e114Smatt 		}
94bc80e114Smatt 
95d4eadb8eSmatt 		if (EWOULDBLOCK == kpause("autoconf", true, 1, NULL)) {
96d4eadb8eSmatt 			rootconf_timo--;
97d4eadb8eSmatt 		}
98bc80e114Smatt 	}
99262e1f2bSmatt 
1008ce44338Smlelstv 	rootconf();
101262e1f2bSmatt }
102262e1f2bSmatt 
103262e1f2bSmatt void
device_register(device_t dev,void * aux)104262e1f2bSmatt device_register(device_t dev, void *aux)
105262e1f2bSmatt {
106262e1f2bSmatt 	if (cpu_md_ops.md_device_register != NULL)
107262e1f2bSmatt 		(*cpu_md_ops.md_device_register)(dev, aux);
108bc80e114Smatt 
109bc80e114Smatt 	if (booted_device == NULL) {
110bc80e114Smatt 		if (root_string[0] != '\0'
111bc80e114Smatt 		    && !strcmp(device_xname(dev), root_string)) {
112bc80e114Smatt 			aprint_normal_dev(dev, "boot device\n");
113bc80e114Smatt 			booted_device = dev;
114bc80e114Smatt 		} else {
115bc80e114Smatt 			rootconf_timo = 5 * hz;
116bc80e114Smatt 		}
117bc80e114Smatt 	}
118262e1f2bSmatt }
119262e1f2bSmatt 
120262e1f2bSmatt static bool mainbus_found;
121262e1f2bSmatt 
122262e1f2bSmatt static int
mainbus_print(void * aux,const char * pnp)123262e1f2bSmatt mainbus_print(void *aux, const char *pnp)
124262e1f2bSmatt {
125262e1f2bSmatt 	struct mainbus_attach_args *ma = aux;
126262e1f2bSmatt 
127262e1f2bSmatt 	if (pnp != NULL)
128262e1f2bSmatt 		return QUIET;
129262e1f2bSmatt 
130262e1f2bSmatt 	if (pnp)
131262e1f2bSmatt 		aprint_normal("%s at %s", ma->ma_name, pnp);
132262e1f2bSmatt 	if (ma->ma_node != MAINBUSCF_NODE_DEFAULT)
133262e1f2bSmatt 		aprint_normal(" node %d", ma->ma_node);
134262e1f2bSmatt 
135262e1f2bSmatt 	return (UNCONF);
136262e1f2bSmatt }
137262e1f2bSmatt 
138262e1f2bSmatt static int
mainbus_match(device_t parent,cfdata_t cf,void * aux)139262e1f2bSmatt mainbus_match(device_t parent, cfdata_t cf, void *aux)
140262e1f2bSmatt {
141262e1f2bSmatt 	return mainbus_found == false;
142262e1f2bSmatt }
143262e1f2bSmatt 
144262e1f2bSmatt static void
mainbus_attach(device_t parent,device_t self,void * aux)145262e1f2bSmatt mainbus_attach(device_t parent, device_t self, void *aux)
146262e1f2bSmatt {
147262e1f2bSmatt 	struct mainbus_attach_args ma;
148262e1f2bSmatt 
149262e1f2bSmatt 	mainbus_found = true;
150262e1f2bSmatt 
151262e1f2bSmatt 	aprint_normal("\n");
152262e1f2bSmatt 
153262e1f2bSmatt 	ma.ma_name = "cpunode";
154262e1f2bSmatt 	ma.ma_node = 0;
155262e1f2bSmatt 	ma.ma_memt = curcpu()->ci_softc->cpu_bst;
156a853fe29Smatt 	ma.ma_le_memt = curcpu()->ci_softc->cpu_le_bst;
157262e1f2bSmatt 	ma.ma_dmat = &booke_bus_dma_tag;
158262e1f2bSmatt 
159*c7fb772bSthorpej 	config_found(self, &ma, mainbus_print, CFARGS_NONE);
160262e1f2bSmatt }
161262e1f2bSmatt 
162262e1f2bSmatt CFATTACH_DECL_NEW(mainbus, 0, mainbus_match, mainbus_attach, NULL, NULL);
163