xref: /netbsd-src/sys/arch/evbppc/wii/mainbus.c (revision 4551fde429f7337775f7db658e65c2c953726d7f)
1 /* $NetBSD: mainbus.c,v 1.4 2024/06/18 13:35:26 rin 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.4 2024/06/18 13:35:26 rin 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
mainbus_match(device_t parent,cfdata_t match,void * aux)57 mainbus_match(device_t parent, cfdata_t match, void *aux)
58 {
59 	return 1;
60 }
61 
62 static int
mainbus_print(void * aux,const char * pnp)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
mainbus_attach(device_t parent,device_t self,void * aux)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 
86 	/*
87 	 * GCC 12 blames pointer reference to 0-th page, [0, 0xfff].
88 	 * XXX map to higher address as done for, e.g., arm by devmap?
89 	 */
90 #pragma GCC diagnostic push
91 #pragma GCC diagnostic ignored "-Warray-bounds"
92 	aprint_debug_dev(self, "mem1 0x%x, mem2 0x%x\n",
93 	    in32(GLOBAL_MEM1_SIZE), in32(GLOBAL_MEM2_SIZE));
94 	aprint_debug_dev(self, "cpu %u, bus %u, vidmode %u\n",
95 	    in32(GLOBAL_CPU_SPEED), in32(GLOBAL_BUS_SPEED),
96 	    in32(GLOBAL_CUR_VID_MODE));
97 #pragma GCC diagnostic pop
98 
99 	aprint_debug_dev(self, "ios version 0x%x\n", in32(GLOBAL_IOS_VERSION));
100 
101 	maa.maa_bst = &wii_mem_tag;
102 	maa.maa_dmat = &wii_bus_dma_tag;
103 
104 	maa.maa_name = "cpu";
105 	maa.maa_addr = MAINBUSCF_ADDR_DEFAULT;
106 	maa.maa_irq = MAINBUSCF_IRQ_DEFAULT;
107 	config_found(self, &maa, mainbus_print, CFARGS_NONE);
108 
109 	maa.maa_name = "genfb";
110 	maa.maa_addr = VI_BASE;
111 	maa.maa_irq = MAINBUSCF_IRQ_DEFAULT;
112 	config_found(self, &maa, mainbus_print, CFARGS_NONE);
113 
114 	maa.maa_name = "exi";
115 	maa.maa_addr = EXI_BASE;
116 	maa.maa_irq = PI_IRQ_EXI;
117 	config_found(self, &maa, mainbus_print, CFARGS_NONE);
118 
119 	maa.maa_name = "hollywood";
120 	maa.maa_addr = MAINBUSCF_ADDR_DEFAULT;
121 	maa.maa_irq = PI_IRQ_HOLLYWOOD;
122 	config_found(self, &maa, mainbus_print, CFARGS_NONE);
123 
124 	maa.maa_name = "bwai";
125 	maa.maa_addr = AI_BASE;
126 	maa.maa_irq = PI_IRQ_AI;
127 	config_found(self, &maa, mainbus_print, CFARGS_NONE);
128 
129 	maa.maa_name = "bwdsp";
130 	maa.maa_addr = DSP_BASE;
131 	maa.maa_irq = PI_IRQ_DSP;
132 	config_found(self, &maa, mainbus_print, CFARGS_NONE);
133 }
134 
135 static int	cpu_match(device_t, cfdata_t, void *);
136 static void	cpu_attach(device_t, device_t, void *);
137 
138 CFATTACH_DECL_NEW(cpu, 0,
139     cpu_match, cpu_attach, NULL, NULL);
140 
141 extern struct cfdriver cpu_cd;
142 
143 int
cpu_match(device_t parent,cfdata_t cf,void * aux)144 cpu_match(device_t parent, cfdata_t cf, void *aux)
145 {
146 	struct mainbus_attach_args *maa = aux;
147 
148 	if (strcmp(maa->maa_name, cpu_cd.cd_name) != 0) {
149 		return 0;
150 	}
151 
152 	if (cpu_info[0].ci_dev != NULL) {
153 		return 0;
154 	}
155 
156 	return 1;
157 }
158 
159 void
cpu_attach(device_t parent,device_t self,void * aux)160 cpu_attach(device_t parent, device_t self, void *aux)
161 {
162 	cpu_attach_common(self, 0);
163 }
164