1*f5dff4bdSjmcneill /* $NetBSD: wii.h,v 1.9 2024/10/13 16:21:36 jmcneill Exp $ */ 28d626ee2Sjmcneill 38d626ee2Sjmcneill /*- 48d626ee2Sjmcneill * Copyright (c) 2024 Jared McNeill <jmcneill@invisible.ca> 58d626ee2Sjmcneill * All rights reserved. 68d626ee2Sjmcneill * 78d626ee2Sjmcneill * Redistribution and use in source and binary forms, with or without 88d626ee2Sjmcneill * modification, are permitted provided that the following conditions 98d626ee2Sjmcneill * are met: 108d626ee2Sjmcneill * 1. Redistributions of source code must retain the above copyright 118d626ee2Sjmcneill * notice, this list of conditions and the following disclaimer. 128d626ee2Sjmcneill * 2. Redistributions in binary form must reproduce the above copyright 138d626ee2Sjmcneill * notice, this list of conditions and the following disclaimer in the 148d626ee2Sjmcneill * documentation and/or other materials provided with the distribution. 158d626ee2Sjmcneill * 168d626ee2Sjmcneill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 178d626ee2Sjmcneill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 188d626ee2Sjmcneill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 198d626ee2Sjmcneill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 208d626ee2Sjmcneill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 218d626ee2Sjmcneill * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 228d626ee2Sjmcneill * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 238d626ee2Sjmcneill * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 248d626ee2Sjmcneill * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 258d626ee2Sjmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 268d626ee2Sjmcneill * SUCH DAMAGE. 278d626ee2Sjmcneill */ 288d626ee2Sjmcneill 298d626ee2Sjmcneill /* 308d626ee2Sjmcneill * Nintendo Wii platform definitions. 318d626ee2Sjmcneill */ 328d626ee2Sjmcneill 338d626ee2Sjmcneill #ifndef _WII_H 348d626ee2Sjmcneill #define _WII_H 358d626ee2Sjmcneill 368d626ee2Sjmcneill #include <powerpc/pio.h> 378d626ee2Sjmcneill 388d626ee2Sjmcneill #define WII_MEM1_BASE 0x00000000 398d626ee2Sjmcneill #define WII_MEM1_SIZE 0x01800000 /* 24 MB */ 408d626ee2Sjmcneill #define WII_MEM2_BASE 0x10000000 418d626ee2Sjmcneill #define WII_MEM2_SIZE 0x04000000 /* 64 MB */ 428d626ee2Sjmcneill 438d626ee2Sjmcneill #define WII_IOMEM_BASE 0x0c000000 448d626ee2Sjmcneill 458d626ee2Sjmcneill #define GLOBAL_BASE 0x00000000 468d626ee2Sjmcneill #define GLOBAL_SIZE 0x00003400 478d626ee2Sjmcneill 488d626ee2Sjmcneill #define BROADWAY_BASE 0x0c000000 498d626ee2Sjmcneill #define BROADWAY_SIZE 0x00000004 508d626ee2Sjmcneill 518d626ee2Sjmcneill #define VI_BASE 0x0c002000 528d626ee2Sjmcneill #define VI_SIZE 0x00000100 538d626ee2Sjmcneill 548d626ee2Sjmcneill #define PI_BASE 0x0c003000 558d626ee2Sjmcneill #define PI_SIZE 0x00000100 568d626ee2Sjmcneill 57ed377828Sjmcneill #define DSP_BASE 0x0c005000 58ed377828Sjmcneill #define DSP_SIZE 0x00000200 59ed377828Sjmcneill 60c0f93ec1Sjmcneill #define EXI_BASE 0x0d006800 61c0f93ec1Sjmcneill #define EXI_SIZE 0x00000080 62c0f93ec1Sjmcneill 63ed377828Sjmcneill #define AI_BASE 0x0d006c00 64ed377828Sjmcneill #define AI_SIZE 0x00000020 65ed377828Sjmcneill 668d626ee2Sjmcneill #define HOLLYWOOD_BASE 0x0d000000 678d626ee2Sjmcneill #define HOLLYWOOD_PRIV_BASE 0x0d800000 688d626ee2Sjmcneill #define HOLLYWOOD_SIZE 0x00008000 698d626ee2Sjmcneill 708d626ee2Sjmcneill #define XFB_START 0x01698000 718d626ee2Sjmcneill #define XFB_SIZE 0x00168000 728d626ee2Sjmcneill 73ed377828Sjmcneill #define DSP_MEM_START 0x10000000 74ed377828Sjmcneill #define DSP_MEM_SIZE 0x00004000 758d626ee2Sjmcneill 768d626ee2Sjmcneill #define IPC_START 0x133e0000 778d626ee2Sjmcneill #define IPC_SIZE 0x00020000 788d626ee2Sjmcneill 798d626ee2Sjmcneill #define ARM_START 0x13400000 808d626ee2Sjmcneill #define ARM_SIZE 0x00c00000 818d626ee2Sjmcneill 828d626ee2Sjmcneill #define BUS_FREQ_HZ 243000000 838d626ee2Sjmcneill #define CPU_FREQ_HZ (BUS_FREQ_HZ * 3) 848d626ee2Sjmcneill #define TIMEBASE_FREQ_HZ (BUS_FREQ_HZ / 4) 858d626ee2Sjmcneill 868d626ee2Sjmcneill /* Global memory structure */ 878d626ee2Sjmcneill #define GLOBAL_MEM1_SIZE (GLOBAL_BASE + 0x0028) 888d626ee2Sjmcneill #define GLOBAL_CUR_VID_MODE (GLOBAL_BASE + 0x00cc) 898d626ee2Sjmcneill #define GLOBAL_BUS_SPEED (GLOBAL_BASE + 0x00f8) 908d626ee2Sjmcneill #define GLOBAL_CPU_SPEED (GLOBAL_BASE + 0x00fc) 918d626ee2Sjmcneill #define GLOBAL_SYSTEM_TIME (GLOBAL_BASE + 0x30d8) 928d626ee2Sjmcneill #define GLOBAL_MEM2_SIZE (GLOBAL_BASE + 0x3118) 938d626ee2Sjmcneill #define GLOBAL_MEM2_AVAIL_START (GLOBAL_BASE + 0x3124) 948d626ee2Sjmcneill #define GLOBAL_MEM2_AVAIL_END (GLOBAL_BASE + 0x3128) 958d626ee2Sjmcneill #define GLOBAL_IOS_VERSION (GLOBAL_BASE + 0x3140) 968d626ee2Sjmcneill 978d626ee2Sjmcneill /* Processor interface registers */ 988d626ee2Sjmcneill #define PI_INTSR (PI_BASE + 0x00) 998d626ee2Sjmcneill #define PI_INTMR (PI_BASE + 0x04) 1008d626ee2Sjmcneill 1018d626ee2Sjmcneill /* Processor IRQs */ 102c0f93ec1Sjmcneill #define PI_IRQ_EXI 4 103ed377828Sjmcneill #define PI_IRQ_AI 5 104ed377828Sjmcneill #define PI_IRQ_DSP 6 1058d626ee2Sjmcneill #define PI_IRQ_HOLLYWOOD 14 1068d626ee2Sjmcneill 1078d626ee2Sjmcneill /* Hollywood registers */ 1089e64f9afSjmcneill #define HW_VIDIM (HOLLYWOOD_PRIV_BASE + 0x01c) 1099e64f9afSjmcneill #define VIDIM_E __BIT(7) 1109e64f9afSjmcneill #define VIDIM_Y __BITS(5,3) 1119e64f9afSjmcneill #define VIDIM_C __BITS(2,0) 1128d626ee2Sjmcneill #define HW_PPCIRQFLAGS (HOLLYWOOD_BASE + 0x030) 1138d626ee2Sjmcneill #define HW_PPCIRQMASK (HOLLYWOOD_BASE + 0x034) 1148d626ee2Sjmcneill #define HW_ARMIRQFLAGS (HOLLYWOOD_PRIV_BASE + 0x038) 1158d626ee2Sjmcneill #define HW_ARMIRQMASK (HOLLYWOOD_PRIV_BASE + 0x03c) 1168d626ee2Sjmcneill #define HW_AHBPROT (HOLLYWOOD_PRIV_BASE + 0x064) 117818facd3Sjmcneill #define IOPSD1EN __BIT(24) 118818facd3Sjmcneill #define IOPSD0EN __BIT(23) 119818facd3Sjmcneill #define IOPOH1EN __BIT(22) 120818facd3Sjmcneill #define IOPOH0EN __BIT(21) 121818facd3Sjmcneill #define IOPEHCEN __BIT(20) 122*f5dff4bdSjmcneill #define HW_AIPPROT (HOLLYWOOD_PRIV_BASE + 0x070) 123*f5dff4bdSjmcneill #define ENAHBIOPI __BIT(0) 1248d626ee2Sjmcneill #define HW_GPIOB_OUT (HOLLYWOOD_BASE + 0x0c0) 125297a048cSjmcneill #define HW_GPIOB_DIR (HOLLYWOOD_BASE + 0x0c4) 126297a048cSjmcneill #define HW_GPIOB_IN (HOLLYWOOD_BASE + 0x0c8) 1278f331784Sjmcneill #define HW_GPIO_OWNER (HOLLYWOOD_PRIV_BASE + 0x0fc) 1288d626ee2Sjmcneill #define HW_RESETS (HOLLYWOOD_PRIV_BASE + 0x194) 1298d626ee2Sjmcneill #define RSTB_IOP __BIT(23) 1308d626ee2Sjmcneill #define RSTBINB __BIT(0) 1318d626ee2Sjmcneill #define HW_VERSION (HOLLYWOOD_BASE + 0x214) 1328d626ee2Sjmcneill #define HWVER_MASK __BITS(7,4) 1338d626ee2Sjmcneill #define HWREV_MASK __BITS(3,0) 1348d626ee2Sjmcneill 1358d626ee2Sjmcneill /* GPIOs */ 1368f331784Sjmcneill #define GPIO_SHUTDOWN 1 1378d626ee2Sjmcneill #define GPIO_SLOT_LED 5 1388d626ee2Sjmcneill 139276b55c3Sjmcneill /* Command line protocol */ 140276b55c3Sjmcneill #define WII_ARGV_MAGIC 0x5f617267 141276b55c3Sjmcneill struct wii_argv { 142276b55c3Sjmcneill uint32_t magic; 143276b55c3Sjmcneill uint32_t cmdline; 144276b55c3Sjmcneill uint32_t length; 145276b55c3Sjmcneill uint32_t unused[3]; 146276b55c3Sjmcneill }; 147276b55c3Sjmcneill 1488d626ee2Sjmcneill /* Blink the slot LED forever at the specified interval. */ 1498d626ee2Sjmcneill static inline void __dead 1508d626ee2Sjmcneill wii_slot_led_blink(u_int interval_us) 1518d626ee2Sjmcneill { 1528d626ee2Sjmcneill uint32_t val; 1538d626ee2Sjmcneill 1548d626ee2Sjmcneill for (val = in32(HW_GPIOB_OUT); ; val ^= __BIT(GPIO_SLOT_LED)) { 1558d626ee2Sjmcneill delay(interval_us); 1568d626ee2Sjmcneill out32(HW_GPIOB_OUT, val); 1578d626ee2Sjmcneill } 1588d626ee2Sjmcneill } 1598d626ee2Sjmcneill 160*f5dff4bdSjmcneill /* Enable or disable the slot LED. */ 161*f5dff4bdSjmcneill static inline void 162*f5dff4bdSjmcneill wii_slot_led(bool enable) 163*f5dff4bdSjmcneill { 164*f5dff4bdSjmcneill uint32_t val; 165*f5dff4bdSjmcneill 166*f5dff4bdSjmcneill val = in32(HW_GPIOB_OUT); 167*f5dff4bdSjmcneill if (enable) { 168*f5dff4bdSjmcneill val |= __BIT(GPIO_SLOT_LED); 169*f5dff4bdSjmcneill } else { 170*f5dff4bdSjmcneill val &= ~__BIT(GPIO_SLOT_LED); 171*f5dff4bdSjmcneill } 172*f5dff4bdSjmcneill out32(HW_GPIOB_OUT, val); 173*f5dff4bdSjmcneill } 174*f5dff4bdSjmcneill 1758d626ee2Sjmcneill #endif /* !_WII_H */ 176