1/* $NetBSD: mainbus.c,v 1.1 2026/01/09 22:54:29 jmcneill Exp $ */ 2 3/* 4 * Copyright (c) 2002, 2024 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 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32#include <sys/cdefs.h> 33__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.1 2026/01/09 22:54:29 jmcneill Exp $"); 34 35#include <sys/param.h> 36#include <sys/device.h> 37#include <sys/systm.h> 38 39#include <sys/bus.h> 40#include <machine/wii.h> 41#include <machine/wiiu.h> 42#include <machine/pio.h> 43#include <arch/evbppc/nintendo/dev/mainbus.h> 44 45#include "locators.h" 46 47extern struct powerpc_bus_space wii_mem_tag; 48extern struct powerpc_bus_dma_tag wii_bus_dma_tag; 49 50int mainbus_match(device_t, cfdata_t, void *); 51void mainbus_attach(device_t, device_t, void *); 52 53CFATTACH_DECL_NEW(mainbus, 0, 54 mainbus_match, mainbus_attach, NULL, NULL); 55 56int 57mainbus_match(device_t parent, cfdata_t match, void *aux) 58{ 59 return 1; 60} 61 62static int 63mainbus_print(void *aux, const char *pnp) 64{ 65 struct mainbus_attach_args *mba = aux; 66 67 if (pnp) { 68 aprint_normal("%s at %s", mba->maa_name, pnp); 69 } 70 if (mba->maa_addr != MAINBUSCF_ADDR_DEFAULT) { 71 aprint_normal(" addr 0x%08lx", mba->maa_addr); 72 } 73 if (mba->maa_irq != MAINBUSCF_IRQ_DEFAULT) { 74 aprint_normal(" irq %d", mba->maa_irq); 75 } 76 return UNCONF; 77} 78 79void 80mainbus_attach(device_t parent, device_t self, void *aux) 81{ 82 struct mainbus_attach_args maa; 83 int maxcpu, n; 84 85 aprint_normal(": Nintendo Wii%s%s\n", 86 wiiu_plat ? " U" : "", 87 (!wiiu_plat || wiiu_native) ? "" : " (vWii)"); 88 89 maa.maa_bst = &wii_mem_tag; 90 maa.maa_dmat = &wii_bus_dma_tag; 91 92 maxcpu = wiiu_native ? 3 : 1; 93 94 for (n = 0; n < uimin(maxcpu, CPU_MAXNUM); n++) { 95 maa.maa_name = "cpu"; 96 maa.maa_addr = MAINBUSCF_ADDR_DEFAULT; 97 maa.maa_irq = MAINBUSCF_IRQ_DEFAULT; 98 config_found(self, &maa, mainbus_print, CFARGS_NONE); 99 } 100 101 maa.maa_name = "exi"; 102 maa.maa_addr = EXI_BASE; 103 maa.maa_irq = PI_IRQ_EXI; 104 config_found(self, &maa, mainbus_print, CFARGS_NONE); 105 106 maa.maa_name = "genfb"; 107 maa.maa_addr = VI_BASE; 108 maa.maa_irq = PI_IRQ_VI; 109 config_found(self, &maa, mainbus_print, CFARGS_NONE); 110 111 maa.maa_name = "ahb"; 112 maa.maa_addr = MAINBUSCF_ADDR_DEFAULT; 113 maa.maa_irq = PI_IRQ_HOLLYWOOD; 114 config_found(self, &maa, mainbus_print, CFARGS_NONE); 115 116 maa.maa_name = "bwai"; 117 maa.maa_addr = AI_BASE; 118 maa.maa_irq = PI_IRQ_AI; 119 config_found(self, &maa, mainbus_print, CFARGS_NONE); 120 121 maa.maa_name = "bwdsp"; 122 maa.maa_addr = wiiu_native ? WIIU_DSP_BASE : DSP_BASE; 123 maa.maa_irq = MAINBUSCF_IRQ_DEFAULT; 124 config_found(self, &maa, mainbus_print, CFARGS_NONE); 125 126 if (!wiiu_native) { 127 maa.maa_name = "si"; 128 maa.maa_addr = SI_BASE; 129 maa.maa_irq = PI_IRQ_SI; 130 config_found(self, &maa, mainbus_print, CFARGS_NONE); 131 } 132} 133