1 /* $NetBSD: mainbus.c,v 1.7 2001/10/23 22:52:14 thorpej Exp $ */ 2 3 /*- 4 * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Charles M. Hannum; by Jason R. Thorpe. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 #include <sys/param.h> 40 #include <sys/systm.h> 41 #include <sys/device.h> 42 43 #include <dev/ofw/openfirm.h> 44 45 #include <machine/platform.h> 46 47 int mainbus_match(struct device *, struct cfdata *, void *); 48 void mainbus_attach(struct device *, struct device *, void *); 49 50 struct cfattach mainbus_ca = { 51 sizeof(struct device), mainbus_match, mainbus_attach 52 }; 53 54 int mainbus_print(void *, const char *); 55 56 extern struct cfdriver mainbus_cd; 57 58 /* 59 * Probe for the mainbus; always succeeds. 60 */ 61 int 62 mainbus_match(struct device *parent, struct cfdata *cf, void *aux) 63 { 64 65 return (1); 66 } 67 68 /* 69 * Attach the mainbus. 70 */ 71 void 72 mainbus_attach(struct device *parent, struct device *self, void *aux) 73 { 74 struct ofbus_attach_args oba; 75 char buf[32]; 76 const char * const *ssp, *sp = NULL; 77 int node; 78 79 static const char * const openfirmware_special[] = { 80 /* 81 * These are _root_ devices to ignore. Others must be 82 * handled elsewhere, if at all. 83 */ 84 "virtual-memory", 85 "mmu", 86 "aliases", 87 "memory", 88 "openprom", 89 "options", 90 "packages", 91 "chosen", 92 93 /* 94 * This one is extra-special .. we make a special case 95 * and attach CPUs early. 96 */ 97 "cpus", 98 99 NULL 100 }; 101 102 printf(": %s\n", platform_name); 103 104 /* 105 * Before we do anything else, attach CPUs. We do this early, 106 * because we might need to make CPU dependent decisions during 107 * the autoconfiguration process. Also, it's a little weird to 108 * see CPUs after other devices in the boot messages. 109 */ 110 node = OF_finddevice("/cpus"); 111 if (node != -1) { 112 for (node = OF_child(node); node != 0; node = OF_peer(node)) { 113 oba.oba_busname = "cpu"; 114 oba.oba_phandle = node; 115 (void) config_found(self, &oba, mainbus_print); 116 } 117 } else { 118 /* 119 * No /cpus node; assume they're all children of the 120 * root OFW node. 121 */ 122 for (node = OF_child(OF_peer(0)); node != 0; 123 node = OF_peer(node)) { 124 if (OF_getprop(node, "device_type", 125 buf, sizeof(buf)) <= 0) 126 continue; 127 if (strcmp(buf, "cpu") != 0) 128 continue; 129 oba.oba_busname = "cpu"; 130 oba.oba_phandle = node; 131 (void) config_found(self, &oba, mainbus_print); 132 } 133 } 134 135 /* 136 * Now attach the rest of the devices on the system. 137 */ 138 for (node = OF_child(OF_peer(0)); node != 0; node = OF_peer(node)) { 139 /* 140 * Make sure it's not a CPU (we've already attached 141 * those). 142 */ 143 if (OF_getprop(node, "device_type", 144 buf, sizeof(buf)) > 0 && 145 strcmp(buf, "cpu") == 0) 146 continue; 147 148 /* 149 * Make sure this isn't one of our "special" child nodes. 150 */ 151 OF_getprop(node, "name", buf, sizeof(buf)); 152 for (ssp = openfirmware_special; (sp = *ssp) != NULL; ssp++) { 153 if (strcmp(buf, sp) == 0) 154 break; 155 } 156 if (sp != NULL) 157 continue; 158 159 oba.oba_busname = "ofw"; 160 oba.oba_phandle = node; 161 (void) config_found(self, &oba, mainbus_print); 162 } 163 } 164 165 int 166 mainbus_print(void *aux, const char *pnp) 167 { 168 struct ofbus_attach_args *oba = aux; 169 char name[64]; 170 171 if (pnp) { 172 OF_getprop(oba->oba_phandle, "name", name, sizeof(name)); 173 printf("%s at %s", name, pnp); 174 } 175 176 return (UNCONF); 177 } 178