mainbus.c revision 1.1 1 /* $NetBSD: mainbus.c,v 1.1 2024/01/20 21:36:00 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 (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.1 2024/01/20 21:36:00 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/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 = "hollywood";
106 maa.maa_addr = MAINBUSCF_ADDR_DEFAULT;
107 maa.maa_irq = PI_IRQ_HOLLYWOOD;
108 config_found(self, &maa, mainbus_print, CFARGS_NONE);
109 }
110
111 static int cpu_match(device_t, cfdata_t, void *);
112 static void cpu_attach(device_t, device_t, void *);
113
114 CFATTACH_DECL_NEW(cpu, 0,
115 cpu_match, cpu_attach, NULL, NULL);
116
117 extern struct cfdriver cpu_cd;
118
119 int
120 cpu_match(device_t parent, cfdata_t cf, void *aux)
121 {
122 struct mainbus_attach_args *maa = aux;
123
124 if (strcmp(maa->maa_name, cpu_cd.cd_name) != 0) {
125 return 0;
126 }
127
128 if (cpu_info[0].ci_dev != NULL) {
129 return 0;
130 }
131
132 return 1;
133 }
134
135 void
136 cpu_attach(device_t parent, device_t self, void *aux)
137 {
138 cpu_attach_common(self, 0);
139 }
140