wii.h revision 1.10 1 1.10 jmcneill /* $NetBSD: wii.h,v 1.10 2025/02/12 11:31:04 jmcneill Exp $ */
2 1.1 jmcneill
3 1.1 jmcneill /*-
4 1.1 jmcneill * Copyright (c) 2024 Jared McNeill <jmcneill (at) invisible.ca>
5 1.1 jmcneill * All rights reserved.
6 1.1 jmcneill *
7 1.1 jmcneill * Redistribution and use in source and binary forms, with or without
8 1.1 jmcneill * modification, are permitted provided that the following conditions
9 1.1 jmcneill * are met:
10 1.1 jmcneill * 1. Redistributions of source code must retain the above copyright
11 1.1 jmcneill * notice, this list of conditions and the following disclaimer.
12 1.1 jmcneill * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 jmcneill * notice, this list of conditions and the following disclaimer in the
14 1.1 jmcneill * documentation and/or other materials provided with the distribution.
15 1.1 jmcneill *
16 1.1 jmcneill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 jmcneill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 jmcneill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 jmcneill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 jmcneill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.1 jmcneill * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.1 jmcneill * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.1 jmcneill * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.1 jmcneill * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 jmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 jmcneill * SUCH DAMAGE.
27 1.1 jmcneill */
28 1.1 jmcneill
29 1.1 jmcneill /*
30 1.1 jmcneill * Nintendo Wii platform definitions.
31 1.1 jmcneill */
32 1.1 jmcneill
33 1.1 jmcneill #ifndef _WII_H
34 1.1 jmcneill #define _WII_H
35 1.1 jmcneill
36 1.1 jmcneill #include <powerpc/pio.h>
37 1.1 jmcneill
38 1.1 jmcneill #define WII_MEM1_BASE 0x00000000
39 1.1 jmcneill #define WII_MEM1_SIZE 0x01800000 /* 24 MB */
40 1.1 jmcneill #define WII_MEM2_BASE 0x10000000
41 1.1 jmcneill #define WII_MEM2_SIZE 0x04000000 /* 64 MB */
42 1.1 jmcneill
43 1.1 jmcneill #define WII_IOMEM_BASE 0x0c000000
44 1.1 jmcneill
45 1.3 jmcneill #define GLOBAL_BASE 0x00000000
46 1.1 jmcneill #define GLOBAL_SIZE 0x00003400
47 1.1 jmcneill
48 1.10 jmcneill #define EFB_BASE 0x08000000
49 1.10 jmcneill #define EFB_SIZE 0x00300000 /* 3 MB */
50 1.10 jmcneill
51 1.1 jmcneill #define BROADWAY_BASE 0x0c000000
52 1.1 jmcneill #define BROADWAY_SIZE 0x00000004
53 1.1 jmcneill
54 1.10 jmcneill #define CP_BASE 0x0c000000
55 1.10 jmcneill #define CP_SIZE 0x0c000080
56 1.10 jmcneill
57 1.10 jmcneill #define PE_BASE 0x0c001000
58 1.10 jmcneill #define PE_SIZE 0x00000100
59 1.10 jmcneill
60 1.3 jmcneill #define VI_BASE 0x0c002000
61 1.3 jmcneill #define VI_SIZE 0x00000100
62 1.1 jmcneill
63 1.1 jmcneill #define PI_BASE 0x0c003000
64 1.1 jmcneill #define PI_SIZE 0x00000100
65 1.1 jmcneill
66 1.3 jmcneill #define DSP_BASE 0x0c005000
67 1.3 jmcneill #define DSP_SIZE 0x00000200
68 1.3 jmcneill
69 1.10 jmcneill #define WGPIPE_BASE 0x0c008000
70 1.10 jmcneill #define WGPIPE_SIZE 0x00000004
71 1.10 jmcneill
72 1.7 jmcneill #define EXI_BASE 0x0d006800
73 1.7 jmcneill #define EXI_SIZE 0x00000080
74 1.7 jmcneill
75 1.3 jmcneill #define AI_BASE 0x0d006c00
76 1.3 jmcneill #define AI_SIZE 0x00000020
77 1.3 jmcneill
78 1.1 jmcneill #define HOLLYWOOD_BASE 0x0d000000
79 1.1 jmcneill #define HOLLYWOOD_PRIV_BASE 0x0d800000
80 1.1 jmcneill #define HOLLYWOOD_SIZE 0x00008000
81 1.1 jmcneill
82 1.1 jmcneill #define XFB_START 0x01698000
83 1.1 jmcneill #define XFB_SIZE 0x00168000
84 1.1 jmcneill
85 1.3 jmcneill #define DSP_MEM_START 0x10000000
86 1.3 jmcneill #define DSP_MEM_SIZE 0x00004000
87 1.1 jmcneill
88 1.1 jmcneill #define IPC_START 0x133e0000
89 1.1 jmcneill #define IPC_SIZE 0x00020000
90 1.1 jmcneill
91 1.1 jmcneill #define ARM_START 0x13400000
92 1.1 jmcneill #define ARM_SIZE 0x00c00000
93 1.1 jmcneill
94 1.1 jmcneill #define BUS_FREQ_HZ 243000000
95 1.1 jmcneill #define CPU_FREQ_HZ (BUS_FREQ_HZ * 3)
96 1.1 jmcneill #define TIMEBASE_FREQ_HZ (BUS_FREQ_HZ / 4)
97 1.1 jmcneill
98 1.1 jmcneill /* Global memory structure */
99 1.1 jmcneill #define GLOBAL_MEM1_SIZE (GLOBAL_BASE + 0x0028)
100 1.1 jmcneill #define GLOBAL_CUR_VID_MODE (GLOBAL_BASE + 0x00cc)
101 1.1 jmcneill #define GLOBAL_BUS_SPEED (GLOBAL_BASE + 0x00f8)
102 1.1 jmcneill #define GLOBAL_CPU_SPEED (GLOBAL_BASE + 0x00fc)
103 1.1 jmcneill #define GLOBAL_SYSTEM_TIME (GLOBAL_BASE + 0x30d8)
104 1.1 jmcneill #define GLOBAL_MEM2_SIZE (GLOBAL_BASE + 0x3118)
105 1.1 jmcneill #define GLOBAL_MEM2_AVAIL_START (GLOBAL_BASE + 0x3124)
106 1.1 jmcneill #define GLOBAL_MEM2_AVAIL_END (GLOBAL_BASE + 0x3128)
107 1.1 jmcneill #define GLOBAL_IOS_VERSION (GLOBAL_BASE + 0x3140)
108 1.1 jmcneill
109 1.1 jmcneill /* Processor interface registers */
110 1.1 jmcneill #define PI_INTSR (PI_BASE + 0x00)
111 1.1 jmcneill #define PI_INTMR (PI_BASE + 0x04)
112 1.1 jmcneill
113 1.10 jmcneill /* GX registers */
114 1.10 jmcneill #define GX_WGPIPE (GX_BASE + 0x00)
115 1.10 jmcneill
116 1.1 jmcneill /* Processor IRQs */
117 1.7 jmcneill #define PI_IRQ_EXI 4
118 1.3 jmcneill #define PI_IRQ_AI 5
119 1.3 jmcneill #define PI_IRQ_DSP 6
120 1.3 jmcneill #define PI_IRQ_HOLLYWOOD 14
121 1.1 jmcneill
122 1.1 jmcneill /* Hollywood registers */
123 1.4 jmcneill #define HW_VIDIM (HOLLYWOOD_PRIV_BASE + 0x01c)
124 1.4 jmcneill #define VIDIM_E __BIT(7)
125 1.4 jmcneill #define VIDIM_Y __BITS(5,3)
126 1.4 jmcneill #define VIDIM_C __BITS(2,0)
127 1.1 jmcneill #define HW_PPCIRQFLAGS (HOLLYWOOD_BASE + 0x030)
128 1.1 jmcneill #define HW_PPCIRQMASK (HOLLYWOOD_BASE + 0x034)
129 1.3 jmcneill #define HW_ARMIRQFLAGS (HOLLYWOOD_PRIV_BASE + 0x038)
130 1.1 jmcneill #define HW_ARMIRQMASK (HOLLYWOOD_PRIV_BASE + 0x03c)
131 1.1 jmcneill #define HW_AHBPROT (HOLLYWOOD_PRIV_BASE + 0x064)
132 1.8 jmcneill #define IOPSD1EN __BIT(24)
133 1.8 jmcneill #define IOPSD0EN __BIT(23)
134 1.8 jmcneill #define IOPOH1EN __BIT(22)
135 1.8 jmcneill #define IOPOH0EN __BIT(21)
136 1.8 jmcneill #define IOPEHCEN __BIT(20)
137 1.9 jmcneill #define HW_AIPPROT (HOLLYWOOD_PRIV_BASE + 0x070)
138 1.9 jmcneill #define ENAHBIOPI __BIT(0)
139 1.1 jmcneill #define HW_GPIOB_OUT (HOLLYWOOD_BASE + 0x0c0)
140 1.5 jmcneill #define HW_GPIOB_DIR (HOLLYWOOD_BASE + 0x0c4)
141 1.5 jmcneill #define HW_GPIOB_IN (HOLLYWOOD_BASE + 0x0c8)
142 1.2 jmcneill #define HW_GPIO_OWNER (HOLLYWOOD_PRIV_BASE + 0x0fc)
143 1.10 jmcneill #define HW_COMPAT (HOLLYWOOD_PRIV_BASE + 0x180)
144 1.10 jmcneill #define DVDVIDEO __BIT(21)
145 1.1 jmcneill #define HW_RESETS (HOLLYWOOD_PRIV_BASE + 0x194)
146 1.1 jmcneill #define RSTB_IOP __BIT(23)
147 1.10 jmcneill #define RSTB_IODI __BIT(17)
148 1.1 jmcneill #define RSTBINB __BIT(0)
149 1.1 jmcneill #define HW_VERSION (HOLLYWOOD_BASE + 0x214)
150 1.1 jmcneill #define HWVER_MASK __BITS(7,4)
151 1.1 jmcneill #define HWREV_MASK __BITS(3,0)
152 1.1 jmcneill
153 1.1 jmcneill /* GPIOs */
154 1.2 jmcneill #define GPIO_SHUTDOWN 1
155 1.10 jmcneill #define GPIO_DI_SPIN 4
156 1.1 jmcneill #define GPIO_SLOT_LED 5
157 1.10 jmcneill #define GPIO_DO_EJECT 9
158 1.1 jmcneill
159 1.6 jmcneill /* Command line protocol */
160 1.6 jmcneill #define WII_ARGV_MAGIC 0x5f617267
161 1.6 jmcneill struct wii_argv {
162 1.6 jmcneill uint32_t magic;
163 1.6 jmcneill uint32_t cmdline;
164 1.6 jmcneill uint32_t length;
165 1.6 jmcneill uint32_t unused[3];
166 1.6 jmcneill };
167 1.6 jmcneill
168 1.1 jmcneill /* Blink the slot LED forever at the specified interval. */
169 1.1 jmcneill static inline void __dead
170 1.1 jmcneill wii_slot_led_blink(u_int interval_us)
171 1.1 jmcneill {
172 1.1 jmcneill uint32_t val;
173 1.1 jmcneill
174 1.1 jmcneill for (val = in32(HW_GPIOB_OUT); ; val ^= __BIT(GPIO_SLOT_LED)) {
175 1.1 jmcneill delay(interval_us);
176 1.1 jmcneill out32(HW_GPIOB_OUT, val);
177 1.1 jmcneill }
178 1.1 jmcneill }
179 1.1 jmcneill
180 1.9 jmcneill /* Enable or disable the slot LED. */
181 1.9 jmcneill static inline void
182 1.9 jmcneill wii_slot_led(bool enable)
183 1.9 jmcneill {
184 1.9 jmcneill uint32_t val;
185 1.9 jmcneill
186 1.9 jmcneill val = in32(HW_GPIOB_OUT);
187 1.9 jmcneill if (enable) {
188 1.9 jmcneill val |= __BIT(GPIO_SLOT_LED);
189 1.9 jmcneill } else {
190 1.9 jmcneill val &= ~__BIT(GPIO_SLOT_LED);
191 1.9 jmcneill }
192 1.9 jmcneill out32(HW_GPIOB_OUT, val);
193 1.9 jmcneill }
194 1.9 jmcneill
195 1.1 jmcneill #endif /* !_WII_H */
196