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