1 /* $NetBSD: mainbus.c,v 1.10 2002/10/02 04:19:45 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 CFATTACH_DECL(mainbus, sizeof(struct device), 51 mainbus_match, mainbus_attach, NULL, NULL); 52 53 int mainbus_print(void *, const char *); 54 55 extern struct cfdriver mainbus_cd; 56 57 /* 58 * Probe for the mainbus; always succeeds. 59 */ 60 int 61 mainbus_match(struct device *parent, struct cfdata *cf, void *aux) 62 { 63 64 return (1); 65 } 66 67 /* 68 * Attach the mainbus. 69 */ 70 void 71 mainbus_attach(struct device *parent, struct device *self, void *aux) 72 { 73 struct ofbus_attach_args oba; 74 char buf[32]; 75 const char * const *ssp, *sp = NULL; 76 int node; 77 78 static const char * const openfirmware_special[] = { 79 /* 80 * These are _root_ devices to ignore. Others must be 81 * handled elsewhere, if at all. 82 */ 83 "virtual-memory", 84 "mmu", 85 "aliases", 86 "memory", 87 "openprom", 88 "options", 89 "packages", 90 "chosen", 91 92 /* 93 * This one is extra-special .. we make a special case 94 * and attach CPUs early. 95 */ 96 "cpus", 97 98 NULL 99 }; 100 101 printf(": %s\n", platform_name); 102 103 /* 104 * Before we do anything else, attach CPUs. We do this early, 105 * because we might need to make CPU dependent decisions during 106 * the autoconfiguration process. Also, it's a little weird to 107 * see CPUs after other devices in the boot messages. 108 */ 109 node = OF_finddevice("/cpus"); 110 if (node == -1) { 111 112 /* 113 * No /cpus node; assume they're all children of the 114 * root OFW node. 115 */ 116 node = OF_peer(0); 117 } 118 for (node = OF_child(node); node != 0; node = OF_peer(node)) { 119 if (OF_getprop(node, "device_type", buf, sizeof(buf)) <= 0) 120 continue; 121 if (strcmp(buf, "cpu") != 0) 122 continue; 123 124 oba.oba_busname = "cpu"; 125 of_packagename(node, oba.oba_ofname, sizeof oba.oba_ofname); 126 oba.oba_phandle = node; 127 (void) config_found(self, &oba, mainbus_print); 128 } 129 130 /* 131 * Now attach the rest of the devices on the system. 132 */ 133 for (node = OF_child(OF_peer(0)); node != 0; node = OF_peer(node)) { 134 135 /* 136 * Make sure it's not a CPU (we've already attached those). 137 */ 138 if (OF_getprop(node, "device_type", buf, sizeof(buf)) > 0 && 139 strcmp(buf, "cpu") == 0) 140 continue; 141 142 /* 143 * Make sure this isn't one of our "special" child nodes. 144 */ 145 OF_getprop(node, "name", buf, sizeof(buf)); 146 for (ssp = openfirmware_special; (sp = *ssp) != NULL; ssp++) { 147 if (strcmp(buf, sp) == 0) 148 break; 149 } 150 if (sp != NULL) 151 continue; 152 153 oba.oba_busname = "ofw"; 154 of_packagename(node, oba.oba_ofname, sizeof oba.oba_ofname); 155 oba.oba_phandle = node; 156 (void) config_found(self, &oba, mainbus_print); 157 } 158 } 159 160 int 161 mainbus_print(void *aux, const char *pnp) 162 { 163 struct ofbus_attach_args *oba = aux; 164 165 if (pnp) 166 printf("%s at %s", oba->oba_ofname, pnp); 167 else 168 printf(" (%s)", oba->oba_ofname); 169 return (UNCONF); 170 } 171