1 1.4 rin /* $NetBSD: mainbus.c,v 1.4 2024/06/18 13:35:26 rin Exp $ */ 2 1.1 jmcneill 3 1.1 jmcneill /* 4 1.1 jmcneill * Copyright (c) 2002, 2024 The NetBSD Foundation, Inc. 5 1.1 jmcneill * All rights reserved. 6 1.1 jmcneill * 7 1.1 jmcneill * This code is derived from software contributed to The NetBSD Foundation 8 1.1 jmcneill * by Lennart Augustsson (lennart (at) augustsson.net) at Sandburst Corp. 9 1.1 jmcneill * 10 1.1 jmcneill * Redistribution and use in source and binary forms, with or without 11 1.1 jmcneill * modification, are permitted provided that the following conditions 12 1.1 jmcneill * are met: 13 1.1 jmcneill * 1. Redistributions of source code must retain the above copyright 14 1.1 jmcneill * notice, this list of conditions and the following disclaimer. 15 1.1 jmcneill * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 jmcneill * notice, this list of conditions and the following disclaimer in the 17 1.1 jmcneill * documentation and/or other materials provided with the distribution. 18 1.1 jmcneill * 19 1.1 jmcneill * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.1 jmcneill * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.1 jmcneill * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.1 jmcneill * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.1 jmcneill * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.1 jmcneill * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.1 jmcneill * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.1 jmcneill * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.1 jmcneill * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.1 jmcneill * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.1 jmcneill * POSSIBILITY OF SUCH DAMAGE. 30 1.1 jmcneill */ 31 1.1 jmcneill 32 1.1 jmcneill #include <sys/cdefs.h> 33 1.4 rin __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.4 2024/06/18 13:35:26 rin Exp $"); 34 1.1 jmcneill 35 1.1 jmcneill #include <sys/param.h> 36 1.1 jmcneill #include <sys/device.h> 37 1.1 jmcneill #include <sys/systm.h> 38 1.1 jmcneill 39 1.1 jmcneill #include <sys/bus.h> 40 1.1 jmcneill #include <machine/wii.h> 41 1.1 jmcneill #include <machine/pio.h> 42 1.1 jmcneill #include <arch/evbppc/wii/dev/mainbus.h> 43 1.1 jmcneill 44 1.1 jmcneill #include "locators.h" 45 1.1 jmcneill #include "mainbus.h" 46 1.1 jmcneill 47 1.1 jmcneill extern struct powerpc_bus_space wii_mem_tag; 48 1.1 jmcneill extern struct powerpc_bus_dma_tag wii_bus_dma_tag; 49 1.1 jmcneill 50 1.1 jmcneill int mainbus_match(device_t, cfdata_t, void *); 51 1.1 jmcneill void mainbus_attach(device_t, device_t, void *); 52 1.1 jmcneill 53 1.1 jmcneill CFATTACH_DECL_NEW(mainbus, 0, 54 1.1 jmcneill mainbus_match, mainbus_attach, NULL, NULL); 55 1.1 jmcneill 56 1.1 jmcneill int 57 1.1 jmcneill mainbus_match(device_t parent, cfdata_t match, void *aux) 58 1.1 jmcneill { 59 1.1 jmcneill return 1; 60 1.1 jmcneill } 61 1.1 jmcneill 62 1.1 jmcneill static int 63 1.1 jmcneill mainbus_print(void *aux, const char *pnp) 64 1.1 jmcneill { 65 1.1 jmcneill struct mainbus_attach_args *mba = aux; 66 1.1 jmcneill 67 1.1 jmcneill if (pnp) { 68 1.1 jmcneill aprint_normal("%s at %s", mba->maa_name, pnp); 69 1.1 jmcneill } 70 1.1 jmcneill if (mba->maa_addr != MAINBUSCF_ADDR_DEFAULT) { 71 1.1 jmcneill aprint_normal(" addr 0x%08lx", mba->maa_addr); 72 1.1 jmcneill } 73 1.1 jmcneill if (mba->maa_irq != MAINBUSCF_IRQ_DEFAULT) { 74 1.1 jmcneill aprint_normal(" irq %d", mba->maa_irq); 75 1.1 jmcneill } 76 1.1 jmcneill return UNCONF; 77 1.1 jmcneill } 78 1.1 jmcneill 79 1.1 jmcneill void 80 1.1 jmcneill mainbus_attach(device_t parent, device_t self, void *aux) 81 1.1 jmcneill { 82 1.1 jmcneill struct mainbus_attach_args maa; 83 1.1 jmcneill 84 1.1 jmcneill aprint_normal(": Nintendo Wii\n"); 85 1.4 rin 86 1.4 rin /* 87 1.4 rin * GCC 12 blames pointer reference to 0-th page, [0, 0xfff]. 88 1.4 rin * XXX map to higher address as done for, e.g., arm by devmap? 89 1.4 rin */ 90 1.4 rin #pragma GCC diagnostic push 91 1.4 rin #pragma GCC diagnostic ignored "-Warray-bounds" 92 1.1 jmcneill aprint_debug_dev(self, "mem1 0x%x, mem2 0x%x\n", 93 1.1 jmcneill in32(GLOBAL_MEM1_SIZE), in32(GLOBAL_MEM2_SIZE)); 94 1.1 jmcneill aprint_debug_dev(self, "cpu %u, bus %u, vidmode %u\n", 95 1.1 jmcneill in32(GLOBAL_CPU_SPEED), in32(GLOBAL_BUS_SPEED), 96 1.1 jmcneill in32(GLOBAL_CUR_VID_MODE)); 97 1.4 rin #pragma GCC diagnostic pop 98 1.4 rin 99 1.1 jmcneill aprint_debug_dev(self, "ios version 0x%x\n", in32(GLOBAL_IOS_VERSION)); 100 1.1 jmcneill 101 1.1 jmcneill maa.maa_bst = &wii_mem_tag; 102 1.1 jmcneill maa.maa_dmat = &wii_bus_dma_tag; 103 1.1 jmcneill 104 1.1 jmcneill maa.maa_name = "cpu"; 105 1.1 jmcneill maa.maa_addr = MAINBUSCF_ADDR_DEFAULT; 106 1.1 jmcneill maa.maa_irq = MAINBUSCF_IRQ_DEFAULT; 107 1.1 jmcneill config_found(self, &maa, mainbus_print, CFARGS_NONE); 108 1.1 jmcneill 109 1.1 jmcneill maa.maa_name = "genfb"; 110 1.1 jmcneill maa.maa_addr = VI_BASE; 111 1.1 jmcneill maa.maa_irq = MAINBUSCF_IRQ_DEFAULT; 112 1.1 jmcneill config_found(self, &maa, mainbus_print, CFARGS_NONE); 113 1.1 jmcneill 114 1.3 jmcneill maa.maa_name = "exi"; 115 1.3 jmcneill maa.maa_addr = EXI_BASE; 116 1.3 jmcneill maa.maa_irq = PI_IRQ_EXI; 117 1.3 jmcneill config_found(self, &maa, mainbus_print, CFARGS_NONE); 118 1.3 jmcneill 119 1.1 jmcneill maa.maa_name = "hollywood"; 120 1.1 jmcneill maa.maa_addr = MAINBUSCF_ADDR_DEFAULT; 121 1.1 jmcneill maa.maa_irq = PI_IRQ_HOLLYWOOD; 122 1.1 jmcneill config_found(self, &maa, mainbus_print, CFARGS_NONE); 123 1.2 jmcneill 124 1.2 jmcneill maa.maa_name = "bwai"; 125 1.2 jmcneill maa.maa_addr = AI_BASE; 126 1.2 jmcneill maa.maa_irq = PI_IRQ_AI; 127 1.2 jmcneill config_found(self, &maa, mainbus_print, CFARGS_NONE); 128 1.2 jmcneill 129 1.2 jmcneill maa.maa_name = "bwdsp"; 130 1.2 jmcneill maa.maa_addr = DSP_BASE; 131 1.2 jmcneill maa.maa_irq = PI_IRQ_DSP; 132 1.2 jmcneill config_found(self, &maa, mainbus_print, CFARGS_NONE); 133 1.1 jmcneill } 134 1.1 jmcneill 135 1.1 jmcneill static int cpu_match(device_t, cfdata_t, void *); 136 1.1 jmcneill static void cpu_attach(device_t, device_t, void *); 137 1.1 jmcneill 138 1.1 jmcneill CFATTACH_DECL_NEW(cpu, 0, 139 1.1 jmcneill cpu_match, cpu_attach, NULL, NULL); 140 1.1 jmcneill 141 1.1 jmcneill extern struct cfdriver cpu_cd; 142 1.1 jmcneill 143 1.1 jmcneill int 144 1.1 jmcneill cpu_match(device_t parent, cfdata_t cf, void *aux) 145 1.1 jmcneill { 146 1.1 jmcneill struct mainbus_attach_args *maa = aux; 147 1.1 jmcneill 148 1.1 jmcneill if (strcmp(maa->maa_name, cpu_cd.cd_name) != 0) { 149 1.1 jmcneill return 0; 150 1.1 jmcneill } 151 1.1 jmcneill 152 1.1 jmcneill if (cpu_info[0].ci_dev != NULL) { 153 1.1 jmcneill return 0; 154 1.1 jmcneill } 155 1.1 jmcneill 156 1.1 jmcneill return 1; 157 1.1 jmcneill } 158 1.1 jmcneill 159 1.1 jmcneill void 160 1.1 jmcneill cpu_attach(device_t parent, device_t self, void *aux) 161 1.1 jmcneill { 162 1.1 jmcneill cpu_attach_common(self, 0); 163 1.1 jmcneill } 164