1 /* $NetBSD: mainbus.c,v 1.9 2001/07/22 11:29:47 wiz Exp $ */ 2 3 /* 4 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by Christopher G. Demetriou 17 * for the NetBSD Project. 18 * 4. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #include <sys/param.h> 34 #include <sys/device.h> 35 #include <sys/systm.h> 36 37 #include <dev/pci/pcivar.h> 38 #include <dev/ofw/openfirm.h> 39 40 #include <machine/autoconf.h> 41 42 int mainbus_match __P((struct device *, struct cfdata *, void *)); 43 void mainbus_attach __P((struct device *, struct device *, void *)); 44 int mainbus_print __P((void *, const char *)); 45 46 struct cfattach mainbus_ca = { 47 sizeof(struct device), mainbus_match, mainbus_attach 48 }; 49 50 /* 51 * Probe for the mainbus; always succeeds. 52 */ 53 int 54 mainbus_match(parent, cf, aux) 55 struct device *parent; 56 struct cfdata *cf; 57 void *aux; 58 { 59 return 1; 60 } 61 62 /* 63 * Attach the mainbus. 64 */ 65 void 66 mainbus_attach(parent, self, aux) 67 struct device *parent, *self; 68 void *aux; 69 { 70 struct ofbus_attach_args oba; 71 struct confargs ca; 72 int node, i; 73 u_int32_t reg[4]; 74 char name[32]; 75 76 printf("\n"); 77 78 for (i = 0; i < 2; i++) { 79 ca.ca_name = "cpu"; 80 ca.ca_reg = reg; 81 reg[0] = i; 82 config_found(self, &ca, NULL); 83 } 84 85 node = OF_peer(0); 86 if (node) { 87 oba.oba_busname = "ofw"; 88 oba.oba_phandle = node; 89 config_found(self, &oba, NULL); 90 } 91 92 for (node = OF_child(OF_finddevice("/")); node; node = OF_peer(node)) { 93 memset(name, 0, sizeof(name)); 94 if (OF_getprop(node, "name", name, sizeof(name)) == -1) 95 continue; 96 97 ca.ca_name = name; 98 ca.ca_node = node; 99 ca.ca_nreg = OF_getprop(node, "reg", reg, sizeof(reg)); 100 ca.ca_reg = reg; 101 config_found(self, &ca, NULL); 102 } 103 } 104 105 int 106 mainbus_print(aux, pnp) 107 void *aux; 108 const char *pnp; 109 { 110 struct pcibus_attach_args *pa= aux; 111 112 if (pnp) 113 printf("%s at %s", pa->pba_busname, pnp); 114 printf(" bus %d", pa->pba_bus); 115 return UNCONF; 116 } 117