1 /* $NetBSD: mainbus.c,v 1.2 2007/10/17 19:54:18 garbled Exp $ */ 2 3 /* 4 * Copyright (c) 2002 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Lennart Augustsson (lennart@augustsson.net) at Sandburst Corp. 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/cdefs.h> 40 __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.2 2007/10/17 19:54:18 garbled Exp $"); 41 42 #include <sys/param.h> 43 #include <sys/device.h> 44 #include <sys/systm.h> 45 46 #include <machine/bus.h> 47 #include <machine/pmppc.h> 48 #include <arch/evbppc/pmppc/dev/mainbus.h> 49 50 #include <dev/ic/cpc700reg.h> 51 52 #include "locators.h" 53 #include "mainbus.h" 54 55 #if NCPU == 0 56 #error A cpu device is now required 57 #endif 58 59 int mainbus_match(struct device *, struct cfdata *, void *); 60 void mainbus_attach(struct device *, struct device *, void *); 61 62 CFATTACH_DECL(mainbus, sizeof(struct device), 63 mainbus_match, mainbus_attach, NULL, NULL); 64 65 static int mainbus_print(void *, const char *); 66 67 /* 68 * Probe for the mainbus; always succeeds. 69 */ 70 int 71 mainbus_match(struct device *parent, struct cfdata *match, void *aux) 72 { 73 74 return 1; 75 } 76 77 static int 78 mainbus_submatch(struct device *parent, struct cfdata *cf, 79 const int *ldesc, void *aux) 80 { 81 struct mainbus_attach_args *maa = aux; 82 83 if (cf->cf_loc[MAINBUSCF_ADDR] != maa->mb_addr) 84 return (0); 85 86 return (config_match(parent, cf, aux)); 87 } 88 89 static int 90 mainbus_print(void *aux, const char *pnp) 91 { 92 struct mainbus_attach_args *mba = aux; 93 94 if (pnp) 95 aprint_normal("%s at %s", mba->mb_name, pnp); 96 if (mba->mb_addr != MAINBUSCF_ADDR_DEFAULT) 97 aprint_normal(" addr 0x%08lx", mba->mb_addr); 98 if (mba->mb_irq != MAINBUSCF_IRQ_DEFAULT) 99 aprint_normal(" irq %d", mba->mb_irq); 100 return (UNCONF); 101 } 102 103 /* 104 * Attach the mainbus. 105 */ 106 void 107 mainbus_attach(struct device *parent, struct device *self, void *aux) 108 { 109 struct mainbus_attach_args maa; 110 111 printf(": Artesyn PM/PPC\n"); 112 printf("%s: %sPCI bus Monarch\n", self->dv_xname, 113 a_config.a_is_monarch ? "" : "not"); 114 printf("%s: boot from %s, %sECC, %s L2 cache\n", 115 self->dv_xname, 116 a_config.a_boot_device == A_BOOT_ROM ? "ROM" : "flash", 117 a_config.a_has_ecc ? "" : "no ", 118 a_config.a_l2_cache == A_CACHE_PARITY ? "parity" : 119 a_config.a_l2_cache == A_CACHE_NO_PARITY ? "no-parity" : "no"); 120 121 maa.mb_bt = &pmppc_mem_tag; 122 123 maa.mb_name = "cpu"; 124 maa.mb_addr = MAINBUSCF_ADDR_DEFAULT; 125 maa.mb_irq = MAINBUSCF_IRQ_DEFAULT; 126 config_found(self, &maa, mainbus_print); 127 128 if (a_config.a_has_rtc) { 129 maa.mb_name = "rtc"; 130 maa.mb_addr = PMPPC_RTC; 131 maa.mb_irq = PMPPC_I_RTC_INT; 132 config_found_sm_loc(self, "mainbus", NULL, &maa, mainbus_print, 133 mainbus_submatch); 134 } 135 136 if (a_config.a_has_eth) { 137 maa.mb_name = "cs"; 138 maa.mb_addr = PMPPC_CS_IO_BASE; 139 maa.mb_irq = PMPPC_I_ETH_INT; 140 config_found_sm_loc(self, "mainbus", NULL, &maa, mainbus_print, 141 mainbus_submatch); 142 maa.mb_bt = &pmppc_mem_tag; 143 } 144 if (a_config.a_flash_width != 0) { 145 maa.mb_name = "flash"; 146 maa.mb_addr = PMPPC_FLASH_BASE; 147 maa.mb_irq = MAINBUSCF_IRQ_DEFAULT; 148 maa.u.mb_flash.size = a_config.a_flash_size; 149 maa.u.mb_flash.width = a_config.a_flash_width; 150 config_found_sm_loc(self, "mainbus", NULL, &maa, mainbus_print, 151 mainbus_submatch); 152 } 153 154 maa.mb_name = "cpc"; 155 maa.mb_addr = MAINBUSCF_ADDR_DEFAULT; 156 maa.mb_irq = MAINBUSCF_IRQ_DEFAULT; 157 config_found(self, &maa, mainbus_print); 158 } 159 160 static int cpu_match(struct device *, struct cfdata *, void *); 161 static void cpu_attach(struct device *, struct device *, void *); 162 163 CFATTACH_DECL(cpu, sizeof(struct device), 164 cpu_match, cpu_attach, NULL, NULL); 165 166 extern struct cfdriver cpu_cd; 167 168 int 169 cpu_match(struct device *parent, struct cfdata *cf, void *aux) 170 { 171 struct mainbus_attach_args *maa = aux; 172 173 if (strcmp(maa->mb_name, cpu_cd.cd_name) != 0) 174 return 0; 175 176 if (cpu_info[0].ci_dev != NULL) 177 return 0; 178 179 return 1; 180 } 181 182 void 183 cpu_attach(struct device *parent, struct device *self, void *aux) 184 { 185 (void) cpu_attach_common(self, 0); 186 } 187