Initial support for running FreeBSD on the Nintendo Wii. We're able to

reach single user mode using a memory disk device as the file system.

This port includes the framebuffer driver, the PIC driver, a platform
driver and the GPIO driver. The IPC driver (to talk to IOS kernels) is
not yet written but there's a placeholder for it.

There are still some MMU problems and to get a working system you need to
patch locore32.S. Since we haven't found the best way yet to address that
problem, we're not committing those changes yet. The problem is related to
the different BAT layout on the Wii and to the fact that the Homebrew
loader doesn't clean up the special registers (including the 8 BATs)
before passing control to us.

You'll need a Wii with Homebrew loader and a TV that can do NTSC (for now).

Submitted by:	Margarida Gouveia
This commit is contained in:
Adrian Chadd 2012-08-21 06:31:26 +00:00
parent 27c9070e7e
commit 31ec0f7a83
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=239478
14 changed files with 2980 additions and 0 deletions

View File

@ -228,6 +228,12 @@ powerpc/psim/iobus.c optional psim
powerpc/psim/ata_iobus.c optional ata psim
powerpc/psim/openpic_iobus.c optional psim
powerpc/psim/uart_iobus.c optional uart psim
powerpc/wii/platform_wii.c optional wii
powerpc/wii/wii_bus.c optional wii
powerpc/wii/wii_pic.c optional wii
powerpc/wii/wii_fb.c optional wii
powerpc/wii/wii_gpio.c optional wii
powerpc/wii/wii_ipc.c optional wii
compat/freebsd32/freebsd32_ioctl.c optional compat_freebsd32
compat/freebsd32/freebsd32_misc.c optional compat_freebsd32

View File

@ -23,6 +23,7 @@ POWERMAC opt_platform.h
PS3 opt_platform.h
MAMBO
PSIM
WII opt_platform.h
SC_OFWFB opt_ofwfb.h

View File

@ -0,0 +1,152 @@
/*-
* Copyright (C) 2012 Margarida Gouveia
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer,
* without modification, immediately at the beginning of the file.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/pcpu.h>
#include <sys/proc.h>
#include <sys/reboot.h>
#include <sys/smp.h>
#include <sys/fbio.h>
#include <vm/vm.h>
#include <vm/pmap.h>
#include <machine/bus.h>
#include <machine/cpu.h>
#include <machine/hid.h>
#include <machine/platform.h>
#include <machine/platformvar.h>
#include <machine/pmap.h>
#include <machine/smp.h>
#include <machine/spr.h>
#include <machine/vmparam.h>
#include <powerpc/wii/wii_fbreg.h>
#include "platform_if.h"
static int wii_probe(platform_t);
static int wii_attach(platform_t);
static void wii_mem_regions(platform_t, struct mem_region **,
int *, struct mem_region **, int *);
static unsigned long wii_timebase_freq(platform_t, struct cpuref *cpuref);
static void wii_reset(platform_t);
static void wii_cpu_idle(void);
static platform_method_t wii_methods[] = {
PLATFORMMETHOD(platform_probe, wii_probe),
PLATFORMMETHOD(platform_attach, wii_attach),
PLATFORMMETHOD(platform_mem_regions, wii_mem_regions),
PLATFORMMETHOD(platform_timebase_freq, wii_timebase_freq),
PLATFORMMETHOD(platform_reset, wii_reset),
{ 0, 0 }
};
static platform_def_t wii_platform = {
"wii",
wii_methods,
0
};
PLATFORM_DEF(wii_platform);
static int
wii_probe(platform_t plat)
{
register_t vers = mfpvr();
/*
* The Wii includes a PowerPC 750CL with custom modifications
* ("Broadway").
* For now, we just assume that if we are running on a
* PowerPC 750CL, then this platform is a Nintendo Wii.
*/
if ((vers & 0xfffff0e0) == (MPC750 << 16 | MPC750CL))
return (BUS_PROBE_SPECIFIC);
return (ENXIO);
}
static int
wii_attach(platform_t plat)
{
cpu_idle_hook = wii_cpu_idle;
return (0);
}
#define MEM_REGIONS 2
static struct mem_region avail_regions[MEM_REGIONS];
static void
wii_mem_regions(platform_t plat, struct mem_region **phys, int *physsz,
struct mem_region **avail, int *availsz)
{
/* 24MB 1T-SRAM */
avail_regions[0].mr_start = 0x00000000;
avail_regions[0].mr_size = 0x01800000 - 0x0004000;
/*
* Reserve space for the framebuffer which is located
* at the end of this 24MB memory region. See wii_fbreg.h.
*/
avail_regions[0].mr_size -= WIIFB_FB_LEN;
/* 64MB GDDR3 SDRAM */
avail_regions[1].mr_start = 0x10000000 + 0x0004000;
avail_regions[1].mr_size = 0x04000000 - 0x0004000;
/* XXX for now only use the first memory region */
#undef MEM_REGIONS
#define MEM_REGIONS 1
*phys = *avail = avail_regions;
*physsz = *availsz = MEM_REGIONS;
}
static u_long
wii_timebase_freq(platform_t plat, struct cpuref *cpuref)
{
/* Bus Frequency (243MHz) / 4 */
return (60750000);
}
static void
wii_reset(platform_t plat)
{
}
static void
wii_cpu_idle(void)
{
}

293
sys/powerpc/wii/wii_bus.c Normal file
View File

@ -0,0 +1,293 @@
/*-
* Copyright (C) 2012 Margarida Gouveia
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer,
* without modification, immediately at the beginning of the file.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/module.h>
#include <sys/malloc.h>
#include <sys/bus.h>
#include <sys/clock.h>
#include <sys/cpu.h>
#include <sys/resource.h>
#include <sys/rman.h>
#include <vm/vm.h>
#include <vm/pmap.h>
#include <machine/bus.h>
#include <machine/platform.h>
#include <machine/pmap.h>
#include <machine/resource.h>
#include <powerpc/wii/wii_picreg.h>
#include <powerpc/wii/wii_fbreg.h>
#include <powerpc/wii/wii_exireg.h>
#include <powerpc/wii/wii_ipcreg.h>
#include <powerpc/wii/wii_gpioreg.h>
static void wiibus_identify(driver_t *, device_t);
static int wiibus_probe(device_t);
static int wiibus_attach(device_t);
static int wiibus_print_child(device_t, device_t);
static struct resource *
wiibus_alloc_resource(device_t, device_t, int, int *,
unsigned long, unsigned long, unsigned long,
unsigned int);
static int wiibus_activate_resource(device_t, device_t, int, int,
struct resource *);
static device_method_t wiibus_methods[] = {
/* Device interface */
DEVMETHOD(device_identify, wiibus_identify),
DEVMETHOD(device_probe, wiibus_probe),
DEVMETHOD(device_attach, wiibus_attach),
/* Bus interface */
DEVMETHOD(bus_add_child, bus_generic_add_child),
DEVMETHOD(bus_print_child, wiibus_print_child),
DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
DEVMETHOD(bus_alloc_resource, wiibus_alloc_resource),
DEVMETHOD(bus_activate_resource,wiibus_activate_resource),
DEVMETHOD_END
};
struct wiibus_softc {
device_t sc_dev;
struct rman sc_rman;
};
static MALLOC_DEFINE(M_WIIBUS, "wiibus", "Nintendo Wii system bus");
struct wiibus_devinfo {
struct resource_list di_resources;
uint8_t di_init;
};
static driver_t wiibus_driver = {
"wiibus",
wiibus_methods,
sizeof(struct wiibus_softc)
};
static devclass_t wiibus_devclass;
DRIVER_MODULE(wiibus, nexus, wiibus_driver, wiibus_devclass, 0, 0);
static void
wiibus_identify(driver_t *driver, device_t parent)
{
if (strcmp(installed_platform(), "wii") != 0)
return;
if (device_find_child(parent, "wiibus", -1) == NULL)
BUS_ADD_CHILD(parent, 0, "wiibus", 0);
}
static int
wiibus_probe(device_t dev)
{
/* Do not attach to any OF nodes that may be present */
device_set_desc(dev, "Nintendo Wii System Bus");
return (BUS_PROBE_NOWILDCARD);
}
static void
wiibus_init_device_resources(struct rman *rm, struct wiibus_devinfo *dinfo,
unsigned int rid, uintptr_t addr, size_t len, unsigned int irq)
{
if (!dinfo->di_init) {
resource_list_init(&dinfo->di_resources);
dinfo->di_init++;
}
if (addr) {
rman_manage_region(rm, addr, addr + len - 1);
resource_list_add(&dinfo->di_resources, SYS_RES_MEMORY, rid,
addr, addr + len, len);
}
if (irq)
resource_list_add(&dinfo->di_resources, SYS_RES_IRQ, rid,
irq, irq, 1);
}
static int
wiibus_attach(device_t self)
{
struct wiibus_softc *sc;
struct wiibus_devinfo *dinfo;
device_t cdev;
sc = device_get_softc(self);
sc->sc_rman.rm_type = RMAN_ARRAY;
sc->sc_rman.rm_descr = "Wii Bus Memory Mapped I/O";
rman_init(&sc->sc_rman);
/* Nintendo PIC */
dinfo = malloc(sizeof(*dinfo), M_WIIBUS, M_WAITOK | M_ZERO);
wiibus_init_device_resources(&sc->sc_rman, dinfo, 0, WIIPIC_REG_ADDR,
WIIPIC_REG_LEN, 0);
cdev = BUS_ADD_CHILD(self, 0, "wiipic", 0);
device_set_ivars(cdev, dinfo);
/* Framebuffer */
dinfo = malloc(sizeof(*dinfo), M_WIIBUS, M_WAITOK | M_ZERO);
wiibus_init_device_resources(&sc->sc_rman, dinfo, 0, WIIFB_REG_ADDR,
WIIFB_REG_LEN, 8);
wiibus_init_device_resources(&sc->sc_rman, dinfo, 1, WIIFB_FB_ADDR,
WIIFB_FB_LEN, 0);
cdev = BUS_ADD_CHILD(self, 0, "wiifb", 0);
device_set_ivars(cdev, dinfo);
/* External Interface Bus */
dinfo = malloc(sizeof(*dinfo), M_WIIBUS, M_WAITOK | M_ZERO);
wiibus_init_device_resources(&sc->sc_rman, dinfo, 0, WIIEXI_REG_ADDR,
WIIEXI_REG_LEN, 4);
cdev = BUS_ADD_CHILD(self, 0, "wiiexi", 0);
device_set_ivars(cdev, dinfo);
/* Nintendo IOS IPC */
dinfo = malloc(sizeof(*dinfo), M_WIIBUS, M_WAITOK | M_ZERO);
wiibus_init_device_resources(&sc->sc_rman, dinfo, 0, WIIIPC_REG_ADDR,
WIIIPC_REG_LEN, 14);
wiibus_init_device_resources(&sc->sc_rman, dinfo, 1, WIIIPC_IOH_ADDR,
WIIIPC_IOH_LEN, 0);
cdev = BUS_ADD_CHILD(self, 0, "wiiipc", 0);
device_set_ivars(cdev, dinfo);
/* GPIO */
dinfo = malloc(sizeof(*dinfo), M_WIIBUS, M_WAITOK | M_ZERO);
wiibus_init_device_resources(&sc->sc_rman, dinfo, 0, WIIGPIO_REG_ADDR,
WIIGPIO_REG_LEN, 0);
cdev = BUS_ADD_CHILD(self, 0, "wiigpio", 0);
device_set_ivars(cdev, dinfo);
return (bus_generic_attach(self));
}
static int
wiibus_print_child(device_t dev, device_t child)
{
struct wiibus_devinfo *dinfo = device_get_ivars(child);
int retval = 0;
retval += bus_print_child_header(dev, child);
retval += resource_list_print_type(&dinfo->di_resources, "mem",
SYS_RES_MEMORY, "%#lx");
retval += resource_list_print_type(&dinfo->di_resources, "irq",
SYS_RES_IRQ, "%ld");
retval += bus_print_child_footer(dev, child);
return (retval);
}
static struct resource *
wiibus_alloc_resource(device_t bus, device_t child, int type,
int *rid, unsigned long start, unsigned long end,
unsigned long count, unsigned int flags)
{
struct wiibus_softc *sc;
struct wiibus_devinfo *dinfo;
struct resource_list_entry *rle;
struct resource *rv;
int needactivate;
sc = device_get_softc(bus);
dinfo = device_get_ivars(child);
needactivate = flags & RF_ACTIVE;
flags &= ~RF_ACTIVE;
switch (type) {
case SYS_RES_MEMORY:
rle = resource_list_find(&dinfo->di_resources, SYS_RES_MEMORY,
*rid);
if (rle == NULL) {
device_printf(bus, "no res entry for %s memory 0x%x\n",
device_get_nameunit(child), *rid);
return (NULL);
}
rv = rman_reserve_resource(&sc->sc_rman, rle->start, rle->end,
rle->count, flags, child);
if (rv == NULL) {
device_printf(bus,
"failed to reserve resource for %s\n",
device_get_nameunit(child));
return (NULL);
}
rman_set_rid(rv, *rid);
break;
/* XXX IRQ */
default:
device_printf(bus, "unknown resource request from %s\n",
device_get_nameunit(child));
return (NULL);
}
if (needactivate) {
if (bus_activate_resource(child, type, *rid, rv) != 0) {
device_printf(bus,
"failed to activate resource for %s\n",
device_get_nameunit(child));
return (NULL);
}
}
return (rv);
}
static int
wiibus_activate_resource(device_t bus, device_t child, int type, int rid,
struct resource *res)
{
void *p;
switch (type) {
case SYS_RES_MEMORY:
p = pmap_mapdev(rman_get_start(res), rman_get_size(res));
if (p == NULL)
return (ENOMEM);
rman_set_virtual(res, p);
rman_set_bustag(res, &bs_be_tag);
rman_set_bushandle(res, (unsigned long)p);
break;
/* XXX IRQ */
default:
device_printf(bus,
"unknown activate resource request from %s\n",
device_get_nameunit(child));
return (ENXIO);
}
return (rman_activate_resource(res));
}

View File

@ -0,0 +1,35 @@
/*-
* Copyright (C) 2012 Margarida Gouveia
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#ifndef _POWERPC_WII_WII_EXIREG_H
#define _POWERPC_WII_WII_EXIREG_H
#define WIIEXI_REG_ADDR 0x0d006800
#define WIIEXI_REG_LEN 0x40
#endif /* _POWERPC_WII_WII_IPCREG_H */

881
sys/powerpc/wii/wii_fb.c Normal file
View File

@ -0,0 +1,881 @@
/*-
* Copyright (C) 2012 Margarida Gouveia
* Copyright (c) 2003 Peter Grehan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer,
* without modification, immediately at the beginning of the file.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/module.h>
#include <sys/bus.h>
#include <sys/kernel.h>
#include <sys/sysctl.h>
#include <sys/limits.h>
#include <sys/conf.h>
#include <sys/cons.h>
#include <sys/proc.h>
#include <sys/fcntl.h>
#include <sys/malloc.h>
#include <sys/fbio.h>
#include <sys/consio.h>
#include <vm/vm.h>
#include <vm/pmap.h>
#include <machine/bus.h>
#include <machine/sc_machdep.h>
#include <machine/platform.h>
#include <machine/pmap.h>
#include <sys/rman.h>
#include <dev/fb/fbreg.h>
#include <dev/syscons/syscons.h>
#include <powerpc/wii/wii_fbreg.h>
#include <powerpc/wii/wii_fbvar.h>
/*
* Driver for the Nintendo Wii's framebuffer. Based on Linux's gcnfb.c.
*/
/*
* Syscons glue.
*/
static int wiifb_scprobe(device_t);
static int wiifb_scattach(device_t);
static device_method_t wiifb_sc_methods[] = {
DEVMETHOD(device_probe, wiifb_scprobe),
DEVMETHOD(device_attach, wiifb_scattach),
DEVMETHOD_END
};
static driver_t wiifb_sc_driver = {
"wiifb",
wiifb_sc_methods,
sizeof(sc_softc_t),
};
static devclass_t sc_devclass;
DRIVER_MODULE(sc, wiibus, wiifb_sc_driver, sc_devclass, 0, 0);
static int
wiifb_scprobe(device_t dev)
{
int error;
device_set_desc(dev, "Nintendo Wii frambuffer");
error = sc_probe_unit(device_get_unit(dev),
device_get_flags(dev) | SC_AUTODETECT_KBD);
if (error != 0)
return (error);
/* This is a fake device, so make sure we added it ourselves */
return (BUS_PROBE_NOWILDCARD);
}
static int
wiifb_scattach(device_t dev)
{
return (sc_attach_unit(device_get_unit(dev),
device_get_flags(dev) | SC_AUTODETECT_KBD));
}
/*
* Video driver routines and glue.
*/
static void wiifb_reset_video(struct wiifb_softc *);
static void wiifb_enable_interrupts(struct wiifb_softc *);
static void wiifb_configure_tv_mode(struct wiifb_softc *);
static void wiifb_setup_framebuffer(struct wiifb_softc *);
static int wiifb_configure(int);
static vi_probe_t wiifb_probe;
static vi_init_t wiifb_init;
static vi_get_info_t wiifb_get_info;
static vi_query_mode_t wiifb_query_mode;
static vi_set_mode_t wiifb_set_mode;
static vi_save_font_t wiifb_save_font;
static vi_load_font_t wiifb_load_font;
static vi_show_font_t wiifb_show_font;
static vi_save_palette_t wiifb_save_palette;
static vi_load_palette_t wiifb_load_palette;
static vi_set_border_t wiifb_set_border;
static vi_save_state_t wiifb_save_state;
static vi_load_state_t wiifb_load_state;
static vi_set_win_org_t wiifb_set_win_org;
static vi_read_hw_cursor_t wiifb_read_hw_cursor;
static vi_set_hw_cursor_t wiifb_set_hw_cursor;
static vi_set_hw_cursor_shape_t wiifb_set_hw_cursor_shape;
static vi_blank_display_t wiifb_blank_display;
static vi_mmap_t wiifb_mmap;
static vi_ioctl_t wiifb_ioctl;
static vi_clear_t wiifb_clear;
static vi_fill_rect_t wiifb_fill_rect;
static vi_bitblt_t wiifb_bitblt;
static vi_diag_t wiifb_diag;
static vi_save_cursor_palette_t wiifb_save_cursor_palette;
static vi_load_cursor_palette_t wiifb_load_cursor_palette;
static vi_copy_t wiifb_copy;
static vi_putp_t wiifb_putp;
static vi_putc_t wiifb_putc;
static vi_puts_t wiifb_puts;
static vi_putm_t wiifb_putm;
static video_switch_t wiifbvidsw = {
.probe = wiifb_probe,
.init = wiifb_init,
.get_info = wiifb_get_info,
.query_mode = wiifb_query_mode,
.set_mode = wiifb_set_mode,
.save_font = wiifb_save_font,
.load_font = wiifb_load_font,
.show_font = wiifb_show_font,
.save_palette = wiifb_save_palette,
.load_palette = wiifb_load_palette,
.set_border = wiifb_set_border,
.save_state = wiifb_save_state,
.load_state = wiifb_load_state,
.set_win_org = wiifb_set_win_org,
.read_hw_cursor = wiifb_read_hw_cursor,
.set_hw_cursor = wiifb_set_hw_cursor,
.set_hw_cursor_shape = wiifb_set_hw_cursor_shape,
.blank_display = wiifb_blank_display,
.mmap = wiifb_mmap,
.ioctl = wiifb_ioctl,
.clear = wiifb_clear,
.fill_rect = wiifb_fill_rect,
.bitblt = wiifb_bitblt,
.diag = wiifb_diag,
.save_cursor_palette = wiifb_save_cursor_palette,
.load_cursor_palette = wiifb_load_cursor_palette,
.copy = wiifb_copy,
.putp = wiifb_putp,
.putc = wiifb_putc,
.puts = wiifb_puts,
.putm = wiifb_putm,
};
VIDEO_DRIVER(wiifb, wiifbvidsw, wiifb_configure);
extern sc_rndr_sw_t txtrndrsw;
RENDERER(wiifb, 0, txtrndrsw, gfb_set);
RENDERER_MODULE(wiifb, gfb_set);
static struct wiifb_softc wiifb_softc;
static uint16_t wiifb_static_window[ROW*COL];
extern u_char dflt_font_8[];
/*
* Map the syscons colors to YUY2 (Y'UV422).
* Some colours are an approximation.
*
* The Wii has a 16 bit pixel, so each 32 bit DWORD encodes
* two pixels. The upper 16 bits is for pixel 0 (left hand pixel
* in a pair), the lower 16 bits is for pixel 1.
*
* For now, we're going to ignore that entirely and just use the
* lower 16 bits for each pixel. We'll take the upper value into
* account later.
*/
static uint32_t wiifb_cmap[16] = {
0x00800080, /* Black */
0x1dff1d6b, /* Blue */
0x4b554b4a, /* Green */
0x80808080, /* Cyan */
0x4c544cff, /* Red */
0x3aaa34b5, /* Magenta */
0x7140718a, /* Brown */
0xff80ff80, /* White */
0x80808080, /* Gray */
0xc399c36a, /* Bright Blue */
0xd076d074, /* Bright Green */
0x80808080, /* Bright Cyan */
0x4c544cff, /* Bright Red */
0x3aaa34b5, /* Bright Magenta */
0xe100e194, /* Bright Yellow */
0xff80ff80 /* Bright White */
};
static struct wiifb_mode_desc wiifb_modes[] = {
[WIIFB_MODE_NTSC_480i] = {
"NTSC 480i",
640, 480,
525,
WIIFB_MODE_FLAG_INTERLACED,
},
[WIIFB_MODE_NTSC_480p] = {
"NTSC 480p",
640, 480,
525,
WIIFB_MODE_FLAG_PROGRESSIVE,
},
[WIIFB_MODE_PAL_576i] = {
"PAL 576i (50Hz)",
640, 574,
625,
WIIFB_MODE_FLAG_INTERLACED,
},
[WIIFB_MODE_PAL_480i] = {
"PAL 480i (60Hz)",
640, 480,
525,
WIIFB_MODE_FLAG_INTERLACED,
},
[WIIFB_MODE_PAL_480p] = {
"PAL 480p",
640, 480,
525,
WIIFB_MODE_FLAG_PROGRESSIVE,
},
};
static const uint32_t wiifb_filter_coeft[] = {
0x1ae771f0, 0x0db4a574, 0x00c1188e, 0xc4c0cbe2, 0xfcecdecf,
0x13130f08, 0x00080c0f
};
static __inline int
wiifb_background(uint8_t attr)
{
return (attr >> 4);
}
static __inline int
wiifb_foreground(uint8_t attr)
{
return (attr & 0x0f);
}
static void
wiifb_reset_video(struct wiifb_softc *sc)
{
struct wiifb_dispcfg dc;
wiifb_dispcfg_read(sc, &dc);
dc.dc_reset = 1;
wiifb_dispcfg_write(sc, &dc);
dc.dc_reset = 0;
wiifb_dispcfg_write(sc, &dc);
}
static void
wiifb_enable_interrupts(struct wiifb_softc *sc)
{
struct wiifb_dispint di;
#ifdef notyet
/*
* Display Interrupt 0
*/
di.di_htiming = 1;
di.di_vtiming = 1;
di.di_enable = 1;
di.di_irq = 1;
wiifb_dispint_write(sc, 0, &di);
/*
* Display Interrupt 1
*/
di.di_htiming = sc->sc_format == WIIFB_FORMAT_PAL ? 433 : 430;
di.di_vtiming = sc->sc_mode->fd_lines;
di.di_enable = 1;
di.di_irq = 1;
if (sc->sc_mode->fd_flags & WIIFB_MODE_FLAG_INTERLACED)
di.di_vtiming /= 2;
wiifb_dispint_write(sc, 1, &di);
/*
* Display Interrupts 2 and 3 are not used.
*/
memset(&di, 0, sizeof(di));
wiifb_dispint_write(sc, 2, &di);
wiifb_dispint_write(sc, 3, &di);
#else
memset(&di, 0, sizeof(di));
wiifb_dispint_write(sc, 0, &di);
wiifb_dispint_write(sc, 1, &di);
wiifb_dispint_write(sc, 2, &di);
wiifb_dispint_write(sc, 3, &di);
#endif
}
/*
* Reference gcnfb.c for an in depth explanation.
* XXX only works with NTSC.
*/
static void
wiifb_configure_tv_mode(struct wiifb_softc *sc)
{
struct wiifb_vtiming vt;
struct wiifb_hscaling hs;
struct wiifb_htiming0 ht0;
struct wiifb_htiming1 ht1;
struct wiifb_vtimingodd vto;
struct wiifb_vtimingeven vte;
struct wiifb_burstblankodd bbo;
struct wiifb_burstblankeven bbe;
struct wiifb_picconf pc;
struct wiifb_mode_desc *mode = sc->sc_mode;
unsigned int height = mode->fd_height;
unsigned int width = mode->fd_width;
unsigned int eqpulse, interlacebias, shift;
const unsigned int maxwidth = 714;
unsigned int hblanking = maxwidth - width;
unsigned int hmargin = hblanking / 2;
unsigned int A = 20 + hmargin, C = 60 + hblanking - hmargin;
unsigned int maxheight = 484;
unsigned int P = 2 * (20 - 10 + 1);
unsigned int Q = 1;
unsigned int vblanking = maxheight - height;
unsigned int vmargin = vblanking / 2;
unsigned int prb = vmargin;
unsigned int psb = vblanking - vmargin;
int i;
/*
* Vertical timing.
*/
if (mode->fd_flags & WIIFB_MODE_FLAG_INTERLACED) {
vt.vt_actvideo = height / 2;
interlacebias = 1;
shift = 0;
} else {
vt.vt_actvideo = height;
interlacebias = 0;
shift = 1;
}
/* Lines of equalization */
if (mode->fd_lines == 625)
eqpulse = 2 * 2.5;
else
eqpulse = 2 * 3;
vt.vt_eqpulse = eqpulse << shift;
wiifb_vtiming_write(sc, &vt);
/*
* Horizontal timings.
*/
ht0.ht0_hlinew = 858 / 2;
ht1.ht1_hsyncw = 64;
ht0.ht0_hcolourstart = 71;
ht0.ht0_hcolourend = 71 + 34;
ht1.ht1_hblankstart = (858 / 2) - A;
ht1.ht1_hblankend = 64 + C;
wiifb_htiming0_write(sc, &ht0);
wiifb_htiming1_write(sc, &ht1);
/*
* Vertical timing odd/even.
*/
if (vmargin & 1) {
vto.vto_preb = (P + interlacebias + prb) << shift;
vto.vto_postb = (Q - interlacebias + psb) << shift;
vte.vte_preb = (P + prb) << shift;
vte.vte_postb = (Q - psb) << shift;
} else {
/* XXX if this isn't 0, it doesn't work? */
prb = 0;
psb = 0;
vte.vte_preb = (P + interlacebias + prb) << shift;
vte.vte_postb = (Q - interlacebias + psb) << shift;
vto.vto_preb = (P + prb) << shift;
vto.vto_postb = (Q - psb) << shift;
}
wiifb_vtimingodd_write(sc, &vto);
wiifb_vtimingeven_write(sc, &vte);
/*
* Burst blanking odd/even interval.
*/
bbo.bbo_bs1 = 2 * (18 - 7 + 1);
bbe.bbe_bs2 = bbo.bbo_bs3 = bbe.bbe_bs4 = bbo.bbo_bs1;
bbo.bbo_be1 = 2 * (525 - 7 + 1);
bbe.bbe_be2 = bbo.bbo_be3 = bbe.bbe_be4 = bbo.bbo_be1;
wiifb_burstblankodd_write(sc, &bbo);
wiifb_burstblankeven_write(sc, &bbe);
/*
* Picture configuration.
*/
pc.pc_strides = (mode->fd_width * 2) / 32;
if (mode->fd_flags & WIIFB_MODE_FLAG_INTERLACED)
pc.pc_strides *= 2;
pc.pc_reads = (mode->fd_width * 2) / 32;
wiifb_picconf_write(sc, &pc);
/*
* Horizontal scaling disabled.
*/
hs.hs_enable = 0;
hs.hs_step = 256;
wiifb_hscaling_write(sc, &hs);
/*
* Filter coeficient table.
*/
for (i = 0; i < 7; i++)
wiifb_filtcoeft_write(sc, i, wiifb_filter_coeft[i]);
/*
* Anti alias.
*/
wiifb_antialias_write(sc, 0x00ff0000);
/*
* Video clock.
*/
wiifb_videoclk_write(sc,
mode->fd_flags & WIIFB_MODE_FLAG_INTERLACED ? 0 : 1);
/*
* Disable horizontal scaling width.
*/
wiifb_hscalingw_write(sc, mode->fd_width);
/*
* DEBUG mode borders. Not used.
*/
wiifb_hborderend_write(sc, 0);
wiifb_hborderstart_write(sc, 0);
/*
* XXX unknown registers.
*/
wiifb_unknown1_write(sc, 0x00ff);
wiifb_unknown2_write(sc, 0x00ff00ff);
wiifb_unknown3_write(sc, 0x00ff00ff);
}
static void
wiifb_setup_framebuffer(struct wiifb_softc *sc)
{
intptr_t addr = sc->sc_fb_addr;
struct wiifb_topfieldbasel tfbl;
struct wiifb_bottomfieldbasel bfbl;
struct wiifb_topfieldbaser tfbr;
struct wiifb_bottomfieldbaser bfbr;
tfbl.tfbl_fbaddr = addr >> 5;
tfbl.tfbl_xoffset = (addr / 2) & 0xf;
tfbl.tfbl_pageoffbit = 1;
wiifb_topfieldbasel_write(sc, &tfbl);
if (sc->sc_mode->fd_flags & WIIFB_MODE_FLAG_INTERLACED)
addr += sc->sc_mode->fd_width * 2;
bfbl.bfbl_fbaddr = addr >> 5;
bfbl.bfbl_xoffset = (addr / 2) & 0xf;
bfbl.bfbl_pageoffbit = 1;
wiifb_bottomfieldbasel_write(sc, &bfbl);
/*
* Only used used for 3D.
*/
memset(&tfbr, 0, sizeof(tfbr));
memset(&bfbr, 0, sizeof(bfbr));
wiifb_topfieldbaser_write(sc, &tfbr);
wiifb_bottomfieldbaser_write(sc, &bfbr);
}
static int
wiifb_configure(int flags)
{
struct wiifb_softc *sc;
struct wiifb_dispcfg dc;
int progressive;
sc = &wiifb_softc;
if (sc->sc_initialized)
return 0;
sc->sc_console = 1;
sc->sc_fb_addr = WIIFB_FB_ADDR;
sc->sc_fb_size = WIIFB_FB_LEN;
sc->sc_reg_addr = WIIFB_REG_ADDR;
sc->sc_reg_size = WIIFB_REG_LEN;
wiifb_reset_video(sc);
wiifb_dispcfg_read(sc, &dc);
sc->sc_format = dc.dc_format;
sc->sc_component = wiifb_component_enabled(sc);
progressive = dc.dc_noninterlaced;
switch (sc->sc_format) {
case WIIFB_FORMAT_MPAL:
case WIIFB_FORMAT_DEBUG:
case WIIFB_FORMAT_NTSC:
sc->sc_mode = progressive ?
&wiifb_modes[WIIFB_MODE_NTSC_480p] :
&wiifb_modes[WIIFB_MODE_NTSC_480i];
break;
case WIIFB_FORMAT_PAL:
sc->sc_mode = progressive ?
&wiifb_modes[WIIFB_MODE_PAL_480p] :
&wiifb_modes[WIIFB_MODE_PAL_480i];
break;
}
sc->sc_height = sc->sc_mode->fd_height;
sc->sc_width = sc->sc_mode->fd_width;
/* Usually we multiply by 4, but I think this looks better. */
sc->sc_stride = sc->sc_width * 2;
wiifb_init(0, &sc->sc_va, 0);
sc->sc_initialized = 1;
return (0);
}
static int
wiifb_probe(int unit, video_adapter_t **adp, void *arg, int flags)
{
return (0);
}
static int
wiifb_init(int unit, video_adapter_t *adp, int flags)
{
struct wiifb_softc *sc;
video_info_t *vi;
sc = (struct wiifb_softc *)adp;
vi = &adp->va_info;
vid_init_struct(adp, "wiifb", -1, unit);
sc->sc_font = dflt_font_8;
vi->vi_cheight = WIIFB_FONT_HEIGHT;
vi->vi_width = sc->sc_width/8;
vi->vi_height = sc->sc_height/vi->vi_cheight;
vi->vi_cwidth = 8;
/*
* Clamp width/height to syscons maximums
*/
if (vi->vi_width > COL)
vi->vi_width = COL;
if (vi->vi_height > ROW)
vi->vi_height = ROW;
sc->sc_xmargin = (sc->sc_width - (vi->vi_width * vi->vi_cwidth)) / 2;
sc->sc_ymargin = (sc->sc_height - (vi->vi_height * vi->vi_cheight))/2;
adp->va_window = (vm_offset_t) wiifb_static_window;
/* XXX no colour support */
adp->va_flags |= V_ADP_FONT | /*V_ADP_COLOR |*/ V_ADP_MODECHANGE;
vid_register(&sc->sc_va);
wiifb_configure_tv_mode(sc);
wiifb_setup_framebuffer(sc);
wiifb_enable_interrupts(sc);
wiifb_clear(adp);
return (0);
}
static int
wiifb_get_info(video_adapter_t *adp, int mode, video_info_t *info)
{
bcopy(&adp->va_info, info, sizeof(*info));
return (0);
}
static int
wiifb_query_mode(video_adapter_t *adp, video_info_t *info)
{
return (0);
}
static int
wiifb_set_mode(video_adapter_t *adp, int mode)
{
return (0);
}
static int
wiifb_save_font(video_adapter_t *adp, int page, int size, int width,
u_char *data, int c, int count)
{
return (0);
}
static int
wiifb_load_font(video_adapter_t *adp, int page, int size, int width,
u_char *data, int c, int count)
{
struct wiifb_softc *sc = (struct wiifb_softc *)adp;
sc->sc_font = data;
return (0);
}
static int
wiifb_show_font(video_adapter_t *adp, int page)
{
return (0);
}
static int
wiifb_save_palette(video_adapter_t *adp, u_char *palette)
{
return (0);
}
static int
wiifb_load_palette(video_adapter_t *adp, u_char *palette)
{
return (0);
}
static int
wiifb_set_border(video_adapter_t *adp, int border)
{
return (wiifb_blank_display(adp, border));
}
static int
wiifb_save_state(video_adapter_t *adp, void *p, size_t size)
{
return (0);
}
static int
wiifb_load_state(video_adapter_t *adp, void *p)
{
return (0);
}
static int
wiifb_set_win_org(video_adapter_t *adp, off_t offset)
{
return (0);
}
static int
wiifb_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
{
*col = *row = 0;
return (0);
}
static int
wiifb_set_hw_cursor(video_adapter_t *adp, int col, int row)
{
return (0);
}
static int
wiifb_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
int celsize, int blink)
{
return (0);
}
static int
wiifb_blank_display(video_adapter_t *adp, int mode)
{
struct wiifb_softc *sc = (struct wiifb_softc *)adp;
uint32_t *p;
for (p = (uint32_t *)sc->sc_fb_addr;
p < (uint32_t *)(sc->sc_fb_addr + sc->sc_fb_size);
p++)
*p = wiifb_cmap[wiifb_background(SC_NORM_ATTR)];
return (0);
}
static int
wiifb_mmap(video_adapter_t *adp, vm_ooffset_t offset, vm_paddr_t *paddr,
int prot, vm_memattr_t *memattr)
{
struct wiifb_softc *sc;
sc = (struct wiifb_softc *)adp;
/*
* This might be a legacy VGA mem request: if so, just point it at the
* framebuffer, since it shouldn't be touched
*/
if (offset < sc->sc_stride*sc->sc_height) {
*paddr = sc->sc_fb_addr + offset;
return (0);
}
return (EINVAL);
}
static int
wiifb_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data)
{
return (0);
}
static int
wiifb_clear(video_adapter_t *adp)
{
return (wiifb_blank_display(adp, 0));
}
static int
wiifb_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
{
return (0);
}
static int
wiifb_bitblt(video_adapter_t *adp, ...)
{
return (0);
}
static int
wiifb_diag(video_adapter_t *adp, int level)
{
return (0);
}
static int
wiifb_save_cursor_palette(video_adapter_t *adp, u_char *palette)
{
return (0);
}
static int
wiifb_load_cursor_palette(video_adapter_t *adp, u_char *palette)
{
return (0);
}
static int
wiifb_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n)
{
return (0);
}
static int
wiifb_putp(video_adapter_t *adp, vm_offset_t off, uint32_t p, uint32_t a,
int size, int bpp, int bit_ltor, int byte_ltor)
{
return (0);
}
static int
wiifb_putc(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a)
{
struct wiifb_softc *sc;
int row;
int col;
int i, j, k;
uint32_t *addr;
u_char *p;
uint32_t fg, bg;
unsigned long pixel[2];
sc = (struct wiifb_softc *)adp;
row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight;
col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth / 2;
p = sc->sc_font + c*WIIFB_FONT_HEIGHT;
addr = (uint32_t *)sc->sc_fb_addr
+ (row + sc->sc_ymargin)*(sc->sc_stride/4)
+ col + sc->sc_xmargin;
bg = wiifb_cmap[wiifb_background(a)];
fg = wiifb_cmap[wiifb_foreground(a)];
for (i = 0; i < WIIFB_FONT_HEIGHT; i++) {
for (j = 0, k = 7; j < 4; j++, k--) {
if ((p[i] & (1 << k)) == 0)
pixel[0] = bg;
else
pixel[0] = fg;
k--;
if ((p[i] & (1 << k)) == 0)
pixel[1] = bg;
else
pixel[1] = fg;
addr[j] = (pixel[0] & 0xffff00ff) |
(pixel[1] & 0x0000ff00);
}
addr += (sc->sc_stride/4);
}
return (0);
}
static int
wiifb_puts(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, int len)
{
int i;
for (i = 0; i < len; i++)
wiifb_putc(adp, off + i, s[i] & 0xff, (s[i] & 0xff00) >> 8);
return (0);
}
static int
wiifb_putm(video_adapter_t *adp, int x, int y, uint8_t *pixel_image,
uint32_t pixel_mask, int size, int width)
{
return (0);
}

View File

@ -0,0 +1,40 @@
/*-
* Copyright (C) 2012 Margarida Gouveia
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer,
* without modification, immediately at the beginning of the file.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $FreeBSD$
*/
#ifndef _POWERPC_WII_WII_FBREG_H
#define _POWERPC_WII_WII_FBREG_H
/*
* Memory addresses for the I/O and the framebuffer.
*/
#define WIIFB_REG_ADDR 0x0c002000
#define WIIFB_REG_LEN 0x100
#define WIIFB_FB_ADDR 0x01698000 /* at the end of 1T SRAM */
#define WIIFB_FB_LEN 0x168000
#endif /* _POWERPC_WII_WII_FBREG_H */

857
sys/powerpc/wii/wii_fbvar.h Normal file
View File

@ -0,0 +1,857 @@
/*-
* Copyright (C) 2012 Margarida Gouveia
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer,
* without modification, immediately at the beginning of the file.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $FreeBSD$
*/
#ifndef _POWERPC_WII_WIIFB_H
#define _POWERPC_WII_WIIFB_H
#define WIIFB_FONT_HEIGHT 8
enum wiifb_format {
WIIFB_FORMAT_NTSC = 0,
WIIFB_FORMAT_PAL = 1,
WIIFB_FORMAT_MPAL = 2,
WIIFB_FORMAT_DEBUG = 3
};
enum wiifb_mode {
WIIFB_MODE_NTSC_480i = 0,
WIIFB_MODE_NTSC_480p = 1,
WIIFB_MODE_PAL_576i = 2,
WIIFB_MODE_PAL_480i = 3,
WIIFB_MODE_PAL_480p = 4
};
struct wiifb_mode_desc {
const char *fd_name;
unsigned int fd_width;
unsigned int fd_height;
unsigned int fd_lines;
uint8_t fd_flags;
#define WIIFB_MODE_FLAG_PROGRESSIVE 0x00
#define WIIFB_MODE_FLAG_INTERLACED 0x01
};
struct wiifb_softc {
video_adapter_t sc_va;
struct cdev *sc_si;
int sc_console;
intptr_t sc_reg_addr;
unsigned int sc_reg_size;
intptr_t sc_fb_addr;
unsigned int sc_fb_size;
unsigned int sc_height;
unsigned int sc_width;
unsigned int sc_stride;
unsigned int sc_xmargin;
unsigned int sc_ymargin;
boolean_t sc_component;
enum wiifb_format sc_format;
struct wiifb_mode_desc *sc_mode;
unsigned int sc_vtiming;
unsigned int sc_htiming;
unsigned char *sc_font;
int sc_initialized;
int sc_rrid;
};
/*
* Vertical timing
* 16 bit
*/
#define WIIFB_REG_VTIMING 0x00
struct wiifb_vtiming {
uint8_t vt_eqpulse;
uint16_t vt_actvideo;
};
static __inline void
wiifb_vtiming_read(struct wiifb_softc *sc, struct wiifb_vtiming *vt)
{
volatile uint16_t *reg =
(uint16_t *)(sc->sc_reg_addr + WIIFB_REG_VTIMING);
vt->vt_eqpulse = *reg & 0xf;
vt->vt_actvideo = (*reg >> 4) & 0x3ff;
}
static __inline void
wiifb_vtiming_write(struct wiifb_softc *sc, struct wiifb_vtiming *vt)
{
volatile uint16_t *reg =
(uint16_t *)(sc->sc_reg_addr + WIIFB_REG_VTIMING);
*reg = ((vt->vt_actvideo & 0x3ff) << 4) |
(vt->vt_eqpulse & 0xf);
powerpc_sync();
}
/*
* Display configuration
* 16 bit
*/
#define WIIFB_REG_DISPCFG 0x02
struct wiifb_dispcfg {
uint8_t dc_enable;
uint8_t dc_reset;
uint8_t dc_noninterlaced;
uint8_t dc_3dmode;
uint8_t dc_latchenb0;
uint8_t dc_latchenb1;
enum wiifb_format dc_format;
};
static __inline void
wiifb_dispcfg_read(struct wiifb_softc *sc, struct wiifb_dispcfg *dc)
{
volatile uint16_t *reg =
(uint16_t *)(sc->sc_reg_addr + WIIFB_REG_DISPCFG);
dc->dc_enable = *reg & 0x1;
dc->dc_reset = (*reg >> 1) & 0x1;
dc->dc_noninterlaced = (*reg >> 2) & 0x1;
dc->dc_3dmode = (*reg >> 3) & 0x1;
dc->dc_latchenb0 = (*reg >> 4) & 0x3;
dc->dc_latchenb1 = (*reg >> 6) & 0x3;
dc->dc_format = (*reg >> 8) & 0x3;
}
static __inline void
wiifb_dispcfg_write(struct wiifb_softc *sc, struct wiifb_dispcfg *dc)
{
volatile uint16_t *reg =
(uint16_t *)(sc->sc_reg_addr + WIIFB_REG_DISPCFG);
*reg = ((dc->dc_format & 0x3) << 8) |
((dc->dc_latchenb1 & 0x3) << 6) |
((dc->dc_latchenb0 & 0x3) << 4) |
((dc->dc_3dmode & 0x1) << 3) |
((dc->dc_noninterlaced & 0x1) << 2) |
((dc->dc_reset & 0x1) << 1) |
(dc->dc_enable & 0x1);
powerpc_sync();
}
/*
* Horizontal Timing 0
* 32 bit
*/
#define WIIFB_REG_HTIMING0 0x04
struct wiifb_htiming0 {
uint16_t ht0_hlinew; /* half line width */
uint8_t ht0_hcolourend;
uint8_t ht0_hcolourstart;
};
static __inline void
wiifb_htiming0_read(struct wiifb_softc *sc, struct wiifb_htiming0 *ht0)
{
volatile uint32_t *reg =
(uint32_t *)(sc->sc_reg_addr + WIIFB_REG_HTIMING0);
ht0->ht0_hlinew = *reg & 0x1ff;
ht0->ht0_hcolourend = (*reg >> 16) & 0x7f;
ht0->ht0_hcolourstart = (*reg >> 24) & 0x7f;
}
static __inline void
wiifb_htiming0_write(struct wiifb_softc *sc, struct wiifb_htiming0 *ht0)
{
volatile uint32_t *reg =
(uint32_t *)(sc->sc_reg_addr + WIIFB_REG_HTIMING0);
*reg = ((ht0->ht0_hcolourstart & 0x7f) << 24) |
((ht0->ht0_hcolourend & 0x7f) << 16) |
(ht0->ht0_hlinew & 0x1ff);
powerpc_sync();
}
/*
* Horizontal Timing 1
* 32 bit
*/
#define WIIFB_REG_HTIMING1 0x08
struct wiifb_htiming1 {
uint8_t ht1_hsyncw;
uint16_t ht1_hblankend;
uint16_t ht1_hblankstart;
};
static __inline void
wiifb_htiming1_read(struct wiifb_softc *sc, struct wiifb_htiming1 *ht1)
{
volatile uint32_t *reg =
(uint32_t *)(sc->sc_reg_addr + WIIFB_REG_HTIMING1);
ht1->ht1_hsyncw = *reg & 0x7f;
ht1->ht1_hblankend = (*reg >> 7) & 0x3ff;
ht1->ht1_hblankstart = (*reg >> 17) & 0x3ff;
}
static __inline void
wiifb_htiming1_write(struct wiifb_softc *sc, struct wiifb_htiming1 *ht1)
{
volatile uint32_t *reg =
(uint32_t *)(sc->sc_reg_addr + WIIFB_REG_HTIMING1);
*reg = ((ht1->ht1_hblankstart & 0x3ff) << 17) |
((ht1->ht1_hblankend & 0x3ff) << 7) |
(ht1->ht1_hsyncw & 0x7f);
powerpc_sync();
}
/*
* Vertical Timing Odd
* 32 bit
*/
#define WIIFB_REG_VTIMINGODD 0x0c
struct wiifb_vtimingodd {
uint16_t vto_preb; /* pre blanking */
uint16_t vto_postb; /* post blanking */
};
static __inline void
wiifb_vtimingodd_read(struct wiifb_softc *sc, struct wiifb_vtimingodd *vto)
{
volatile uint32_t *reg =
(uint32_t *)(sc->sc_reg_addr + WIIFB_REG_VTIMINGODD);
vto->vto_preb = *reg & 0x3ff;
vto->vto_postb = (*reg >> 16) & 0x3ff;
}
static __inline void
wiifb_vtimingodd_write(struct wiifb_softc *sc, struct wiifb_vtimingodd *vto)
{
volatile uint32_t *reg =
(uint32_t *)(sc->sc_reg_addr + WIIFB_REG_VTIMINGODD);
*reg = ((vto->vto_postb & 0x3ff) << 16) |
(vto->vto_preb & 0x3ff);
powerpc_sync();
}
/*
* Vertical Timing Even
* 32 bit
*/
#define WIIFB_REG_VTIMINGEVEN 0x10
struct wiifb_vtimingeven {
uint16_t vte_preb; /* pre blanking */
uint16_t vte_postb; /* post blanking */
};
static __inline void
wiifb_vtimingeven_read(struct wiifb_softc *sc, struct wiifb_vtimingeven *vte)
{
volatile uint32_t *reg =
(uint32_t *)(sc->sc_reg_addr + WIIFB_REG_VTIMINGEVEN);
vte->vte_preb = *reg & 0x3ff;
vte->vte_postb = (*reg >> 16) & 0x3ff;
}
static __inline void
wiifb_vtimingeven_write(struct wiifb_softc *sc, struct wiifb_vtimingeven *vte)
{
volatile uint32_t *reg =
(uint32_t *)(sc->sc_reg_addr + WIIFB_REG_VTIMINGEVEN);
*reg = ((vte->vte_postb & 0x3ff) << 16) |
(vte->vte_preb & 0x3ff);
powerpc_sync();
}
/*
* Burst Blanking Odd Interval
* 32 bit
*/
#define WIIFB_REG_BURSTBLANKODD 0x14
struct wiifb_burstblankodd {
uint8_t bbo_bs1;
uint16_t bbo_be1;
uint8_t bbo_bs3;
uint16_t bbo_be3;
};
static __inline void
wiifb_burstblankodd_read(struct wiifb_softc *sc,
struct wiifb_burstblankodd *bbo)
{
volatile uint32_t *reg =
(uint32_t *)(sc->sc_reg_addr + WIIFB_REG_BURSTBLANKODD);
bbo->bbo_bs1 = *reg & 0x1f;
bbo->bbo_be1 = (*reg >> 5) & 0x7ff;
bbo->bbo_bs3 = (*reg >> 16) & 0x1f;
bbo->bbo_be3 = (*reg >> 21) & 0x7ff;
}
static __inline void
wiifb_burstblankodd_write(struct wiifb_softc *sc,
struct wiifb_burstblankodd *bbo)
{
volatile uint32_t *reg =
(uint32_t *)(sc->sc_reg_addr + WIIFB_REG_BURSTBLANKODD);
*reg = ((bbo->bbo_be3 & 0x7ff) << 21) |
((bbo->bbo_bs3 & 0x1f) << 16) |
((bbo->bbo_be1 & 0x7ff) << 5) |
(bbo->bbo_bs1 & 0x1f);
powerpc_sync();
}
/*
* Burst Blanking Even Interval
* 32 bit
*/
#define WIIFB_REG_BURSTBLANKEVEN 0x18
struct wiifb_burstblankeven {
uint8_t bbe_bs2;
uint16_t bbe_be2;
uint8_t bbe_bs4;
uint16_t bbe_be4;
};
static __inline void
wiifb_burstblankeven_read(struct wiifb_softc *sc,
struct wiifb_burstblankeven *bbe)
{
volatile uint32_t *reg =
(uint32_t *)(sc->sc_reg_addr + WIIFB_REG_BURSTBLANKEVEN);
bbe->bbe_bs2 = *reg & 0x1f;
bbe->bbe_be2 = (*reg >> 5) & 0x7ff;
bbe->bbe_bs4 = (*reg >> 16) & 0x1f;
bbe->bbe_be4 = (*reg >> 21) & 0x7ff;
}
static __inline void
wiifb_burstblankeven_write(struct wiifb_softc *sc,
struct wiifb_burstblankeven *bbe)
{
volatile uint32_t *reg =
(uint32_t *)(sc->sc_reg_addr + WIIFB_REG_BURSTBLANKEVEN);
*reg = ((bbe->bbe_be4 & 0x7ff) << 21) |
((bbe->bbe_bs4 & 0x1f) << 16) |
((bbe->bbe_be2 & 0x7ff) << 5) |
(bbe->bbe_bs2 & 0x1f);
powerpc_sync();
}
/*
* Top Field Base Left
* 32 bit
*/
#define WIIFB_REG_TOPFIELDBASEL 0x1c
struct wiifb_topfieldbasel {
uint32_t tfbl_fbaddr;
uint8_t tfbl_xoffset;
uint8_t tfbl_pageoffbit;
};
static __inline void
wiifb_topfieldbasel_read(struct wiifb_softc *sc,
struct wiifb_topfieldbasel *tfbl)
{
volatile uint32_t *reg =
(uint32_t *)(sc->sc_reg_addr + WIIFB_REG_TOPFIELDBASEL);
tfbl->tfbl_fbaddr = *reg & 0xffffff;
tfbl->tfbl_xoffset = (*reg >> 24) & 0xf;
tfbl->tfbl_pageoffbit = (*reg >> 28) & 0x1;
}
static __inline void
wiifb_topfieldbasel_write(struct wiifb_softc *sc,
struct wiifb_topfieldbasel *tfbl)
{
volatile uint32_t *reg =
(uint32_t *)(sc->sc_reg_addr + WIIFB_REG_TOPFIELDBASEL);
*reg = ((tfbl->tfbl_pageoffbit & 0x1) << 28) |
((tfbl->tfbl_xoffset & 0xf) << 24) |
(tfbl->tfbl_fbaddr & 0xffffff);
powerpc_sync();
}
/*
* Top Field Base Right
* 32 bit
*/
#define WIIFB_REG_TOPFIELDBASER 0x20
struct wiifb_topfieldbaser {
uint32_t tfbr_fbaddr;
uint8_t tfbr_pageoffbit;
};
static __inline void
wiifb_topfieldbaser_read(struct wiifb_softc *sc,
struct wiifb_topfieldbaser *tfbr)
{
volatile uint32_t *reg =
(uint32_t *)(sc->sc_reg_addr + WIIFB_REG_TOPFIELDBASER);
tfbr->tfbr_fbaddr = *reg & 0xffffff;
tfbr->tfbr_pageoffbit = (*reg >> 28) & 0x1;
}
static __inline void
wiifb_topfieldbaser_write(struct wiifb_softc *sc,
struct wiifb_topfieldbaser *tfbr)
{
volatile uint32_t *reg =
(uint32_t *)(sc->sc_reg_addr + WIIFB_REG_TOPFIELDBASER);
*reg = ((tfbr->tfbr_pageoffbit & 0x1) << 28) |
(tfbr->tfbr_fbaddr & 0xffffff);
powerpc_sync();
}
/*
* Bottom Field Base Left
* 32 bit
*/
#define WIIFB_REG_BOTTOMFIELDBASEL 0x24
struct wiifb_bottomfieldbasel {
uint32_t bfbl_fbaddr;
uint8_t bfbl_xoffset;
uint8_t bfbl_pageoffbit;
};
static __inline void
wiifb_bottomfieldbasel_read(struct wiifb_softc *sc,
struct wiifb_bottomfieldbasel *bfbl)
{
volatile uint32_t *reg =
(uint32_t *)(sc->sc_reg_addr + WIIFB_REG_BOTTOMFIELDBASEL);
bfbl->bfbl_fbaddr = *reg & 0xffffff;
bfbl->bfbl_xoffset = (*reg >> 24) & 0xf;
bfbl->bfbl_pageoffbit = (*reg >> 28) & 0x1;
}
static __inline void
wiifb_bottomfieldbasel_write(struct wiifb_softc *sc,
struct wiifb_bottomfieldbasel *bfbl)
{
volatile uint32_t *reg =
(uint32_t *)(sc->sc_reg_addr + WIIFB_REG_BOTTOMFIELDBASEL);
*reg = ((bfbl->bfbl_pageoffbit & 0x1) << 28) |
((bfbl->bfbl_xoffset & 0xf) << 24) |
(bfbl->bfbl_fbaddr & 0xffffff);
powerpc_sync();
}
/*
* Bottom Field Base Right
* 32 bit
*/
#define WIIFB_REG_BOTTOMFIELDBASER 0x28
struct wiifb_bottomfieldbaser {
uint32_t bfbr_fbaddr;
uint8_t bfbr_pageoffbit;
};
static __inline void
wiifb_bottomfieldbaser_read(struct wiifb_softc *sc,
struct wiifb_bottomfieldbaser *bfbr)
{
volatile uint32_t *reg =
(uint32_t *)(sc->sc_reg_addr + WIIFB_REG_BOTTOMFIELDBASER);
bfbr->bfbr_fbaddr = *reg & 0xffffff;
bfbr->bfbr_pageoffbit = (*reg >> 28) & 0x1;
}
static __inline void
wiifb_bottomfieldbaser_write(struct wiifb_softc *sc,
struct wiifb_bottomfieldbaser *bfbr)
{
volatile uint32_t *reg =
(uint32_t *)(sc->sc_reg_addr + WIIFB_REG_BOTTOMFIELDBASER);
*reg = ((bfbr->bfbr_pageoffbit & 0x1) << 28) |
(bfbr->bfbr_fbaddr & 0xffffff);
powerpc_sync();
}
/*
* Display Position Vertical
* 16 bit
*/
#define WIIFB_REG_DISPPOSV 0x2c
static __inline uint16_t
wiifb_dispposv_read(struct wiifb_softc *sc)
{
volatile uint32_t *reg =
(uint32_t *)(sc->sc_reg_addr + WIIFB_REG_DISPPOSV);
return (*reg & 0x7ff);
}
static __inline void
wiifb_dispposv_write(struct wiifb_softc *sc, uint16_t val)
{
volatile uint32_t *reg =
(uint32_t *)(sc->sc_reg_addr + WIIFB_REG_DISPPOSV);
*reg = val & 0x7ff;
powerpc_sync();
}
/*
* Display Position Horizontal
* 16 bit
*/
#define WIIFB_REG_DISPPOSH 0x2e
static __inline uint16_t
wiifb_dispposh_read(struct wiifb_softc *sc)
{
volatile uint32_t *reg =
(uint32_t *)(sc->sc_reg_addr + WIIFB_REG_DISPPOSH);
return (*reg & 0x7ff);
}
static __inline void
wiifb_dispposh_write(struct wiifb_softc *sc, uint16_t val)
{
volatile uint32_t *reg =
(uint32_t *)(sc->sc_reg_addr + WIIFB_REG_DISPPOSH);
*reg = val & 0x7ff;
powerpc_sync();
}
/*
* Display Interrupts.
* There are 4 display interrupt registers, all 32 bit.
*/
#define WIIFB_REG_DISPINT0 0x30
#define WIIFB_REG_DISPINT1 0x34
#define WIIFB_REG_DISPINT2 0x38
#define WIIFB_REG_DISPINT3 0x3c
struct wiifb_dispint {
uint16_t di_htiming;
uint16_t di_vtiming;
uint8_t di_enable;
uint8_t di_irq;
};
static __inline void
wiifb_dispint_read(struct wiifb_softc *sc, int regno, struct wiifb_dispint *di)
{
volatile uint32_t *reg = (uint32_t *)(sc->sc_reg_addr +
WIIFB_REG_DISPINT0 + regno * 4);
di->di_htiming = *reg & 0x3ff;
di->di_vtiming = (*reg >> 16) & 0x3ff;
di->di_enable = (*reg >> 28) & 0x1;
di->di_irq = (*reg >> 31) & 0x1;
}
static __inline void
wiifb_dispint_write(struct wiifb_softc *sc, int regno, struct wiifb_dispint *di)
{
volatile uint32_t *reg = (uint32_t *)(sc->sc_reg_addr +
WIIFB_REG_DISPINT0 + regno * 4);
*reg = ((di->di_irq & 0x1) << 31) |
((di->di_enable & 0x1) << 28) |
((di->di_vtiming & 0x3ff) << 16) |
(di->di_htiming & 0x3ff);
powerpc_sync();
}
/*
* Display Latch 0
* 32 bit
*/
#define WIIFB_REG_DISPLAYTCH0 0x40
/*
* Display Latch 1
* 32 bit
*/
#define WIIFB_REG_DISPLAYTCH1 0x44
/*
* Picture Configuration
* 16 bit
*/
#define WIIFB_REG_PICCONF 0x48
struct wiifb_picconf {
uint8_t pc_strides; /* strides per line (words) */
uint8_t pc_reads; /* reads per line (words */
};
static __inline void
wiifb_picconf_read(struct wiifb_softc *sc, struct wiifb_picconf *pc)
{
volatile uint16_t *reg =
(uint16_t *)(sc->sc_reg_addr + WIIFB_REG_PICCONF);
pc->pc_strides = *reg & 0xff;
pc->pc_reads = (*reg >> 8) & 0xff;
}
static __inline void
wiifb_picconf_write(struct wiifb_softc *sc, struct wiifb_picconf *pc)
{
volatile uint16_t *reg =
(uint16_t *)(sc->sc_reg_addr + WIIFB_REG_PICCONF);
*reg = ((pc->pc_reads & 0xff) << 8) |
(pc->pc_strides & 0xff);
powerpc_sync();
}
/*
* Horizontal Scaling
* 16 bit
*/
#define WIIFB_REG_HSCALING 0x4a
struct wiifb_hscaling {
uint16_t hs_step;
uint8_t hs_enable;
};
static __inline void
wiifb_hscaling_read(struct wiifb_softc *sc, struct wiifb_hscaling *hs)
{
volatile uint16_t *reg =
(uint16_t *)(sc->sc_reg_addr + WIIFB_REG_HSCALING);
hs->hs_step = *reg & 0x1ff;
hs->hs_enable = (*reg >> 12) & 0x1;
}
static __inline void
wiifb_hscaling_write(struct wiifb_softc *sc, struct wiifb_hscaling *hs)
{
volatile uint16_t *reg =
(uint16_t *)(sc->sc_reg_addr + WIIFB_REG_HSCALING);
*reg = ((hs->hs_step & 0x1ff) << 12) |
(hs->hs_enable & 0x1);
powerpc_sync();
}
/*
* Filter Coeficient Table 0-6
* 32 bit
*/
#define WIIFB_REG_FILTCOEFT0 0x4c
#define WIIFB_REG_FILTCOEFT1 0x50
#define WIIFB_REG_FILTCOEFT2 0x54
#define WIIFB_REG_FILTCOEFT3 0x58
#define WIIFB_REG_FILTCOEFT4 0x5c
#define WIIFB_REG_FILTCOEFT5 0x60
#define WIIFB_REG_FILTCOEFT6 0x64
static __inline void
wiifb_filtcoeft_write(struct wiifb_softc *sc, unsigned int regno,
uint32_t coeft)
{
volatile uint32_t *reg =
(uint32_t *)(sc->sc_reg_addr + WIIFB_REG_FILTCOEFT0 + 4 * regno);
*reg = coeft;
powerpc_sync();
}
/*
* Anti-aliasing
* 32 bit
*/
#define WIIFB_REG_ANTIALIAS 0x68
static __inline void
wiifb_antialias_write(struct wiifb_softc *sc, uint32_t antialias)
{
volatile uint32_t *reg =
(uint32_t *)(sc->sc_reg_addr + WIIFB_REG_ANTIALIAS);
*reg = antialias;
powerpc_sync();
}
/*
* Video Clock
* 16 bit
*/
#define WIIFB_REG_VIDEOCLK 0x6c
static __inline uint8_t
wiifb_videoclk_read(struct wiifb_softc *sc)
{
volatile uint16_t *reg =
(uint16_t *)(sc->sc_reg_addr + WIIFB_REG_VIDEOCLK);
return (*reg & 0x1);
}
static __inline void
wiifb_videoclk_write(struct wiifb_softc *sc, uint16_t clk54mhz)
{
volatile uint16_t *reg =
(uint16_t *)(sc->sc_reg_addr + WIIFB_REG_VIDEOCLK);
*reg = clk54mhz & 0x1;
powerpc_sync();
}
/*
* DTV Status
* 16 bit
*
* DTV is another name for the Component Cable output.
*/
#define WIIFB_REG_DTVSTATUS 0x6e
static __inline uint16_t
wiifb_dtvstatus_read(struct wiifb_softc *sc)
{
volatile uint16_t *reg =
(uint16_t *)(sc->sc_reg_addr + WIIFB_REG_DTVSTATUS);
return (*reg & 0x1);
}
static __inline uint16_t
wiifb_component_enabled(struct wiifb_softc *sc)
{
return wiifb_dtvstatus_read(sc);
}
/*
* Horizontal Scaling Width
* 16 bit
*/
#define WIIFB_REG_HSCALINGW 0x70
static __inline uint16_t
wiifb_hscalingw_read(struct wiifb_softc *sc)
{
volatile uint16_t *reg =
(uint16_t *)(sc->sc_reg_addr + WIIFB_REG_HSCALINGW);
return (*reg & 0x3ff);
}
static __inline void
wiifb_hscalingw_write(struct wiifb_softc *sc, uint16_t width)
{
volatile uint16_t *reg =
(uint16_t *)(sc->sc_reg_addr + WIIFB_REG_HSCALINGW);
*reg = width & 0x3ff;
powerpc_sync();
}
/*
* Horizontal Border End
* For debug mode only. Not used by this driver.
* 16 bit
*/
#define WIIFB_REG_HBORDEREND 0x72
static __inline void
wiifb_hborderend_write(struct wiifb_softc *sc, uint16_t border)
{
volatile uint16_t *reg =
(uint16_t *)(sc->sc_reg_addr + WIIFB_REG_HBORDEREND);
*reg = border;
powerpc_sync();
}
/*
* Horizontal Border Start
* 16 bit
*/
#define WIIFB_REG_HBORDERSTART 0x74
static __inline void
wiifb_hborderstart_write(struct wiifb_softc *sc, uint16_t border)
{
volatile uint16_t *reg =
(uint16_t *)(sc->sc_reg_addr + WIIFB_REG_HBORDERSTART);
*reg = border;
powerpc_sync();
}
/*
* Unknown register
* 16 bit
*/
#define WIIFB_REG_UNKNOWN1 0x76
static __inline void
wiifb_unknown1_write(struct wiifb_softc *sc, uint16_t unknown)
{
volatile uint16_t *reg =
(uint16_t *)(sc->sc_reg_addr + WIIFB_REG_UNKNOWN1);
*reg = unknown;
powerpc_sync();
}
/*
* Unknown register
* 32 bit
*/
#define WIIFB_REG_UNKNOWN2 0x78
static __inline void
wiifb_unknown2_write(struct wiifb_softc *sc, uint32_t unknown)
{
volatile uint32_t *reg =
(uint32_t *)(sc->sc_reg_addr + WIIFB_REG_UNKNOWN2);
*reg = unknown;
powerpc_sync();
}
/*
* Unknown register
* 32 bit
*/
#define WIIFB_REG_UNKNOWN3 0x7c
static __inline void
wiifb_unknown3_write(struct wiifb_softc *sc, uint32_t unknown)
{
volatile uint32_t *reg =
(uint32_t *)(sc->sc_reg_addr + WIIFB_REG_UNKNOWN3);
*reg = unknown;
powerpc_sync();
}
#endif /* _POWERPC_WII_WIIFB_H */

289
sys/powerpc/wii/wii_gpio.c Normal file
View File

@ -0,0 +1,289 @@
/*-
* Copyright (C) 2012 Margarida Gouveia
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/module.h>
#include <sys/bus.h>
#include <sys/conf.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/rman.h>
#include <sys/gpio.h>
#include <machine/bus.h>
#include <machine/platform.h>
#include <machine/intr_machdep.h>
#include <machine/resource.h>
#include <powerpc/wii/wii_gpioreg.h>
#include "gpio_if.h"
struct wiigpio_softc {
device_t sc_dev;
struct resource *sc_rres;
bus_space_tag_t sc_bt;
bus_space_handle_t sc_bh;
int sc_rrid;
struct mtx sc_mtx;
struct gpio_pin sc_pins[WIIGPIO_NPINS];
};
#define WIIGPIO_LOCK(sc) mtx_lock(&(sc)->sc_mtx)
#define WIIGPIO_UNLOCK(sc) mtx_unlock(&(sc)->sc_mtx)
static int wiigpio_probe(device_t);
static int wiigpio_attach(device_t);
static int wiigpio_detach(device_t);
static int wiigpio_pin_max(device_t, int *);
static int wiigpio_pin_getname(device_t, uint32_t, char *);
static int wiigpio_pin_getflags(device_t, uint32_t, uint32_t *);
static int wiigpio_pin_setflags(device_t, uint32_t, uint32_t);
static int wiigpio_pin_getcaps(device_t, uint32_t, uint32_t *);
static int wiigpio_pin_get(device_t, uint32_t, unsigned int *);
static int wiigpio_pin_set(device_t, uint32_t, unsigned int);
static int wiigpio_pin_toggle(device_t, uint32_t);
static device_method_t wiigpio_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, wiigpio_probe),
DEVMETHOD(device_attach, wiigpio_attach),
DEVMETHOD(device_detach, wiigpio_detach),
/* GPIO protocol */
DEVMETHOD(gpio_pin_max, wiigpio_pin_max),
DEVMETHOD(gpio_pin_getname, wiigpio_pin_getname),
DEVMETHOD(gpio_pin_getflags, wiigpio_pin_getflags),
DEVMETHOD(gpio_pin_setflags, wiigpio_pin_setflags),
DEVMETHOD(gpio_pin_getcaps, wiigpio_pin_getcaps),
DEVMETHOD(gpio_pin_get, wiigpio_pin_get),
DEVMETHOD(gpio_pin_set, wiigpio_pin_set),
DEVMETHOD(gpio_pin_toggle, wiigpio_pin_toggle),
{ 0, 0 },
};
static driver_t wiigpio_driver = {
"wiigpio",
wiigpio_methods,
sizeof(struct wiigpio_softc)
};
static devclass_t wiigpio_devclass;
DRIVER_MODULE(wiigpio, wiibus, wiigpio_driver, wiigpio_devclass, 0, 0);
static __inline uint32_t
wiigpio_read(struct wiigpio_softc *sc)
{
return (bus_space_read_4(sc->sc_bt, sc->sc_bh, 0));
}
static __inline void
wiigpio_write(struct wiigpio_softc *sc, uint32_t reg)
{
bus_space_write_4(sc->sc_bt, sc->sc_bh, 0, reg);
}
static int
wiigpio_probe(device_t dev)
{
device_set_desc(dev, "Nintendo Wii GPIO");
return (BUS_PROBE_NOWILDCARD);
}
static int
wiigpio_attach(device_t dev)
{
struct wiigpio_softc *sc;
int i;
sc = device_get_softc(dev);
sc->sc_dev = dev;
sc->sc_rrid = 0;
sc->sc_rres = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
&sc->sc_rrid, RF_ACTIVE);
if (sc->sc_rres == NULL) {
device_printf(dev, "could not alloc mem resource\n");
return (ENXIO);
}
sc->sc_bt = rman_get_bustag(sc->sc_rres);
sc->sc_bh = rman_get_bushandle(sc->sc_rres);
mtx_init(&sc->sc_mtx, device_get_nameunit(dev), NULL, MTX_DEF);
for (i = 0; i < WIIGPIO_NPINS; i++) {
sc->sc_pins[i].gp_caps = GPIO_PIN_INPUT | GPIO_PIN_OUTPUT;
sc->sc_pins[i].gp_pin = i;
sc->sc_pins[i].gp_flags = 0;
snprintf(sc->sc_pins[i].gp_name, GPIOMAXNAME, "PIN %d", i);
}
device_add_child(dev, "gpioc", device_get_unit(dev));
device_add_child(dev, "gpiobus", device_get_unit(dev));
return (bus_generic_attach(dev));
}
static int
wiigpio_detach(device_t dev)
{
struct wiigpio_softc *sc;
sc = device_get_softc(dev);
bus_release_resource(dev, SYS_RES_MEMORY, sc->sc_rrid, sc->sc_rres);
mtx_destroy(&sc->sc_mtx);
return (0);
}
static int
wiigpio_pin_max(device_t dev, int *maxpin)
{
*maxpin = WIIGPIO_NPINS - 1;
return (0);
}
static int
wiigpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps)
{
struct wiigpio_softc *sc;
if (pin >= WIIGPIO_NPINS)
return (EINVAL);
sc = device_get_softc(dev);
*caps = sc->sc_pins[pin].gp_caps;
return (0);
}
static int
wiigpio_pin_get(device_t dev, uint32_t pin, unsigned int *val)
{
struct wiigpio_softc *sc;
uint32_t reg;
if (pin >= WIIGPIO_NPINS)
return (EINVAL);
sc = device_get_softc(dev);
WIIGPIO_LOCK(sc);
reg = wiigpio_read(sc);
*val = !!(reg & (1 << pin));
WIIGPIO_UNLOCK(sc);
return (0);
}
static int
wiigpio_pin_set(device_t dev, uint32_t pin, unsigned int value)
{
struct wiigpio_softc *sc;
uint32_t reg, pinmask = 1 << pin;
if (pin >= WIIGPIO_NPINS)
return (EINVAL);
sc = device_get_softc(dev);
WIIGPIO_LOCK(sc);
reg = wiigpio_read(sc) & ~pinmask;
if (value)
reg |= pinmask;
wiigpio_write(sc, reg);
WIIGPIO_UNLOCK(sc);
return (0);
}
static int
wiigpio_pin_toggle(device_t dev, uint32_t pin)
{
struct wiigpio_softc *sc;
uint32_t val, pinmask = 1 << pin;
sc = device_get_softc(dev);
WIIGPIO_LOCK(sc);
val = wiigpio_read(sc) & pinmask;
if (val)
wiigpio_write(sc, wiigpio_read(sc) & ~pinmask);
else
wiigpio_write(sc, wiigpio_read(sc) | pinmask);
WIIGPIO_UNLOCK(sc);
return (0);
}
static int
wiigpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags)
{
struct wiigpio_softc *sc;
if (pin >= WIIGPIO_NPINS)
return (EINVAL);
sc = device_get_softc(dev);
WIIGPIO_LOCK(sc);
sc->sc_pins[pin].gp_flags = flags;
WIIGPIO_UNLOCK(sc);
return (0);
}
static int
wiigpio_pin_getflags(device_t dev, uint32_t pin, uint32_t *flags)
{
struct wiigpio_softc *sc;
if (pin >= WIIGPIO_NPINS)
return (EINVAL);
sc = device_get_softc(dev);
WIIGPIO_LOCK(sc);
*flags = sc->sc_pins[pin].gp_flags;
WIIGPIO_UNLOCK(sc);
return (0);
}
static int
wiigpio_pin_getname(device_t dev, uint32_t pin, char *name)
{
struct wiigpio_softc *sc;
if (pin >= WIIGPIO_NPINS)
return (EINVAL);
sc = device_get_softc(dev);
WIIGPIO_LOCK(sc);
memcpy(name, sc->sc_pins[pin].gp_name, GPIOMAXNAME);
WIIGPIO_UNLOCK(sc);
return (0);
}

View File

@ -0,0 +1,37 @@
/*-
* Copyright (C) 2012 Margarida Gouveia
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#ifndef _POWERPC_WII_WII_GPIOREG_H
#define _POWERPC_WII_WII_GPIOREG_H
#define WIIGPIO_NPINS 32
#define WIIGPIO_REG_ADDR 0x0d8000c0
#define WIIGPIO_REG_LEN 0x4
#endif /* _POWERPC_WII_WII_GPIOREG_H */

102
sys/powerpc/wii/wii_ipc.c Normal file
View File

@ -0,0 +1,102 @@
/*-
* Copyright (C) 2012 Margarida Gouveia
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/module.h>
#include <sys/bus.h>
#include <sys/conf.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/rman.h>
#include <machine/bus.h>
#include <machine/platform.h>
#include <machine/intr_machdep.h>
#include <machine/resource.h>
#include <powerpc/wii/wii_ipcreg.h>
/*
* Driver to interface with the Wii's IOS. IOS are small "microkernels" that run
* on the Broadway GPU and provide access to system services like USB.
*/
static int wiiipc_probe(device_t);
static int wiiipc_attach(device_t);
struct wiiipc_softc {
};
static device_method_t wiiipc_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, wiiipc_probe),
DEVMETHOD(device_attach, wiiipc_attach),
{ 0, 0 },
};
static driver_t wiiipc_driver = {
"wiiipc",
wiiipc_methods,
sizeof(struct wiiipc_softc)
};
static devclass_t wiiipc_devclass;
DRIVER_MODULE(wiiipc, wiibus, wiiipc_driver, wiiipc_devclass, 0, 0);
static int
wiiipc_probe(device_t dev)
{
device_set_desc(dev, "Nintendo Wii IOS IPC");
return (BUS_PROBE_NOWILDCARD);
}
static int
wiiipc_attach(device_t dev)
{
struct wiiipc_softc *sc;
sc = device_get_softc(dev);
#ifdef notyet
sc->sc_dev = dev;
sc->sc_rrid = 0;
sc->sc_rres = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
&sc->sc_rrid, RF_ACTIVE);
if (sc->sc_rres == NULL) {
device_printf(dev, "could not alloc mem resource\n");
return (ENXIO);
}
sc->sc_bt = rman_get_bustag(sc->sc_rres);
sc->sc_bh = rman_get_bushandle(sc->sc_rres);
#endif
return (0);
}

View File

@ -0,0 +1,37 @@
/*-
* Copyright (C) 2012 Margarida Gouveia
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#ifndef _POWERPC_WII_WII_IPCREG_H
#define _POWERPC_WII_WII_IPCREG_H
#define WIIIPC_REG_ADDR 0x0d000000
#define WIIIPC_REG_LEN 0x40
#define WIIIPC_IOH_ADDR 0x133e0000
#define WIIIPC_IOH_LEN 0x20000
#endif /* _POWERPC_WII_WII_IPCREG_H */

209
sys/powerpc/wii/wii_pic.c Normal file
View File

@ -0,0 +1,209 @@
/*-
* Copyright (C) 2012 Margarida Gouveia
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/module.h>
#include <sys/bus.h>
#include <sys/conf.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/rman.h>
#include <machine/bus.h>
#include <machine/platform.h>
#include <machine/intr_machdep.h>
#include <machine/resource.h>
#include <powerpc/wii/wii_picreg.h>
#include "pic_if.h"
static int wiipic_probe(device_t);
static int wiipic_attach(device_t);
static void wiipic_dispatch(device_t, struct trapframe *);
static void wiipic_enable(device_t, unsigned int, unsigned int);
static void wiipic_eoi(device_t, unsigned int);
static void wiipic_mask(device_t, unsigned int);
static void wiipic_unmask(device_t, unsigned int);
struct wiipic_softc {
device_t sc_dev;
struct resource *sc_rres;
bus_space_tag_t sc_bt;
bus_space_handle_t sc_bh;
int sc_rrid;
int sc_vector[WIIPIC_NIRQ];
};
static device_method_t wiipic_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, wiipic_probe),
DEVMETHOD(device_attach, wiipic_attach),
/* PIC interface */
DEVMETHOD(pic_dispatch, wiipic_dispatch),
DEVMETHOD(pic_enable, wiipic_enable),
DEVMETHOD(pic_eoi, wiipic_eoi),
DEVMETHOD(pic_mask, wiipic_mask),
DEVMETHOD(pic_unmask, wiipic_unmask),
{ 0, 0 },
};
static driver_t wiipic_driver = {
"wiipic",
wiipic_methods,
sizeof(struct wiipic_softc)
};
static devclass_t wiipic_devclass;
DRIVER_MODULE(wiipic, wiibus, wiipic_driver, wiipic_devclass, 0, 0);
static __inline uint32_t
wiipic_imr_read(struct wiipic_softc *sc)
{
return (bus_space_read_4(sc->sc_bt, sc->sc_bh, WIIPIC_IMR));
}
static __inline void
wiipic_imr_write(struct wiipic_softc *sc, uint32_t imr)
{
bus_space_write_4(sc->sc_bt, sc->sc_bh, WIIPIC_IMR, imr);
}
static __inline uint32_t
wiipic_icr_read(struct wiipic_softc *sc)
{
return (bus_space_read_4(sc->sc_bt, sc->sc_bh, WIIPIC_ICR));
}
static __inline void
wiipic_icr_write(struct wiipic_softc *sc, uint32_t icr)
{
bus_space_write_4(sc->sc_bt, sc->sc_bh, WIIPIC_ICR, icr);
}
static int
wiipic_probe(device_t dev)
{
device_set_desc(dev, "Nintendo Wii PIC");
return (BUS_PROBE_NOWILDCARD);
}
static int
wiipic_attach(device_t dev)
{
struct wiipic_softc *sc;
sc = device_get_softc(dev);
sc->sc_dev = dev;
sc->sc_rrid = 0;
sc->sc_rres = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
&sc->sc_rrid, RF_ACTIVE);
if (sc->sc_rres == NULL) {
device_printf(dev, "could not alloc mem resource\n");
return (ENXIO);
}
sc->sc_bt = rman_get_bustag(sc->sc_rres);
sc->sc_bh = rman_get_bushandle(sc->sc_rres);
/* Turn off all interrupts */
wiipic_imr_write(sc, 0x00000000);
wiipic_icr_write(sc, 0xffffffff);
powerpc_register_pic(dev, 0, WIIPIC_NIRQ, 0, FALSE);
return (0);
}
static void
wiipic_dispatch(device_t dev, struct trapframe *tf)
{
struct wiipic_softc *sc;
uint32_t irq;
sc = device_get_softc(dev);
irq = ffs(wiipic_icr_read(sc) & wiipic_imr_read(sc));
KASSERT(irq < WIIPIC_NIRQ, ("bogus irq %d", irq));
powerpc_dispatch_intr(sc->sc_vector[irq], tf);
}
static void
wiipic_enable(device_t dev, unsigned int irq, unsigned int vector)
{
struct wiipic_softc *sc;
KASSERT(irq < WIIPIC_NIRQ, ("bogus irq %d", irq));
sc = device_get_softc(dev);
sc->sc_vector[irq] = vector;
wiipic_unmask(dev, irq);
}
static void
wiipic_eoi(device_t dev, unsigned int irq)
{
struct wiipic_softc *sc;
uint32_t icr;
sc = device_get_softc(dev);
icr = wiipic_icr_read(sc);
icr |= (1 << irq);
wiipic_icr_write(sc, icr);
}
static void
wiipic_mask(device_t dev, unsigned int irq)
{
struct wiipic_softc *sc;
uint32_t imr;
sc = device_get_softc(dev);
imr = wiipic_imr_read(sc);
imr &= ~(1 << irq);
wiipic_imr_write(sc, imr);
}
static void
wiipic_unmask(device_t dev, unsigned int irq)
{
struct wiipic_softc *sc;
uint32_t imr;
sc = device_get_softc(dev);
imr = wiipic_imr_read(sc);
imr |= (1 << irq);
wiipic_imr_write(sc, imr);
}

View File

@ -0,0 +1,41 @@
/*-
* Copyright (C) 2012 Margarida Gouveia
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#ifndef _POWERPC_WII_WII_PICREG_H
#define _POWERPC_WII_WII_PICREG_H
#define WIIPIC_REG_ADDR 0x0c003000
#define WIIPIC_REG_LEN 0x08
#define WIIPIC_ICR 0x00
#define WIIPIC_IMR 0x04
#define WIIPIC_RESET 0x24
#define WIIPIC_NIRQ 32
#endif /* _POWERPC_WII_WII_PICREG_H */