Home | History | Annotate | Line # | Download | only in wii
mainbus.c revision 1.3.2.2
      1 /* $NetBSD: mainbus.c,v 1.3.2.2 2024/02/03 11:47:07 martin 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 (at) 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.3.2.2 2024/02/03 11:47:07 martin 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/pio.h>
     42 #include <arch/evbppc/wii/dev/mainbus.h>
     43 
     44 #include "locators.h"
     45 #include "mainbus.h"
     46 
     47 extern struct powerpc_bus_space wii_mem_tag;
     48 extern struct powerpc_bus_dma_tag wii_bus_dma_tag;
     49 
     50 int	mainbus_match(device_t, cfdata_t, void *);
     51 void	mainbus_attach(device_t, device_t, void *);
     52 
     53 CFATTACH_DECL_NEW(mainbus, 0,
     54     mainbus_match, mainbus_attach, NULL, NULL);
     55 
     56 int
     57 mainbus_match(device_t parent, cfdata_t match, void *aux)
     58 {
     59 	return 1;
     60 }
     61 
     62 static int
     63 mainbus_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 
     79 void
     80 mainbus_attach(device_t parent, device_t self, void *aux)
     81 {
     82 	struct mainbus_attach_args maa;
     83 
     84 	aprint_normal(": Nintendo Wii\n");
     85 	aprint_debug_dev(self, "mem1 0x%x, mem2 0x%x\n",
     86 	    in32(GLOBAL_MEM1_SIZE), in32(GLOBAL_MEM2_SIZE));
     87 	aprint_debug_dev(self, "cpu %u, bus %u, vidmode %u\n",
     88 	    in32(GLOBAL_CPU_SPEED), in32(GLOBAL_BUS_SPEED),
     89 	    in32(GLOBAL_CUR_VID_MODE));
     90 	aprint_debug_dev(self, "ios version 0x%x\n", in32(GLOBAL_IOS_VERSION));
     91 
     92 	maa.maa_bst = &wii_mem_tag;
     93 	maa.maa_dmat = &wii_bus_dma_tag;
     94 
     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 	maa.maa_name = "genfb";
    101 	maa.maa_addr = VI_BASE;
    102 	maa.maa_irq = MAINBUSCF_IRQ_DEFAULT;
    103 	config_found(self, &maa, mainbus_print, CFARGS_NONE);
    104 
    105 	maa.maa_name = "exi";
    106 	maa.maa_addr = EXI_BASE;
    107 	maa.maa_irq = PI_IRQ_EXI;
    108 	config_found(self, &maa, mainbus_print, CFARGS_NONE);
    109 
    110 	maa.maa_name = "hollywood";
    111 	maa.maa_addr = MAINBUSCF_ADDR_DEFAULT;
    112 	maa.maa_irq = PI_IRQ_HOLLYWOOD;
    113 	config_found(self, &maa, mainbus_print, CFARGS_NONE);
    114 
    115 	maa.maa_name = "bwai";
    116 	maa.maa_addr = AI_BASE;
    117 	maa.maa_irq = PI_IRQ_AI;
    118 	config_found(self, &maa, mainbus_print, CFARGS_NONE);
    119 
    120 	maa.maa_name = "bwdsp";
    121 	maa.maa_addr = DSP_BASE;
    122 	maa.maa_irq = PI_IRQ_DSP;
    123 	config_found(self, &maa, mainbus_print, CFARGS_NONE);
    124 }
    125 
    126 static int	cpu_match(device_t, cfdata_t, void *);
    127 static void	cpu_attach(device_t, device_t, void *);
    128 
    129 CFATTACH_DECL_NEW(cpu, 0,
    130     cpu_match, cpu_attach, NULL, NULL);
    131 
    132 extern struct cfdriver cpu_cd;
    133 
    134 int
    135 cpu_match(device_t parent, cfdata_t cf, void *aux)
    136 {
    137 	struct mainbus_attach_args *maa = aux;
    138 
    139 	if (strcmp(maa->maa_name, cpu_cd.cd_name) != 0) {
    140 		return 0;
    141 	}
    142 
    143 	if (cpu_info[0].ci_dev != NULL) {
    144 		return 0;
    145 	}
    146 
    147 	return 1;
    148 }
    149 
    150 void
    151 cpu_attach(device_t parent, device_t self, void *aux)
    152 {
    153 	cpu_attach_common(self, 0);
    154 }
    155