Home | History | Annotate | Line # | Download | only in wii
machdep.c revision 1.2
      1  1.2  jmcneill /* $NetBSD: machdep.c,v 1.2 2024/01/21 01:41:54 jmcneill Exp $ */
      2  1.1  jmcneill 
      3  1.1  jmcneill /*
      4  1.1  jmcneill  * Copyright (c) 2002, 2024 The NetBSD Foundation, Inc.
      5  1.1  jmcneill  * All rights reserved.
      6  1.1  jmcneill  *
      7  1.1  jmcneill  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  jmcneill  * by Lennart Augustsson (lennart (at) augustsson.net) at Sandburst Corp.
      9  1.1  jmcneill  *
     10  1.1  jmcneill  * Redistribution and use in source and binary forms, with or without
     11  1.1  jmcneill  * modification, are permitted provided that the following conditions
     12  1.1  jmcneill  * are met:
     13  1.1  jmcneill  * 1. Redistributions of source code must retain the above copyright
     14  1.1  jmcneill  *    notice, this list of conditions and the following disclaimer.
     15  1.1  jmcneill  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  jmcneill  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  jmcneill  *    documentation and/or other materials provided with the distribution.
     18  1.1  jmcneill  *
     19  1.1  jmcneill  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1  jmcneill  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1  jmcneill  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1  jmcneill  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1  jmcneill  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1  jmcneill  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1  jmcneill  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1  jmcneill  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1  jmcneill  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1  jmcneill  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1  jmcneill  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1  jmcneill  */
     31  1.1  jmcneill 
     32  1.1  jmcneill /*
     33  1.1  jmcneill  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
     34  1.1  jmcneill  * Copyright (C) 1995, 1996 TooLs GmbH.
     35  1.1  jmcneill  * All rights reserved.
     36  1.1  jmcneill  *
     37  1.1  jmcneill  * Redistribution and use in source and binary forms, with or without
     38  1.1  jmcneill  * modification, are permitted provided that the following conditions
     39  1.1  jmcneill  * are met:
     40  1.1  jmcneill  * 1. Redistributions of source code must retain the above copyright
     41  1.1  jmcneill  *    notice, this list of conditions and the following disclaimer.
     42  1.1  jmcneill  * 2. Redistributions in binary form must reproduce the above copyright
     43  1.1  jmcneill  *    notice, this list of conditions and the following disclaimer in the
     44  1.1  jmcneill  *    documentation and/or other materials provided with the distribution.
     45  1.1  jmcneill  * 3. All advertising materials mentioning features or use of this software
     46  1.1  jmcneill  *    must display the following acknowledgement:
     47  1.1  jmcneill  *	This product includes software developed by TooLs GmbH.
     48  1.1  jmcneill  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     49  1.1  jmcneill  *    derived from this software without specific prior written permission.
     50  1.1  jmcneill  *
     51  1.1  jmcneill  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     52  1.1  jmcneill  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     53  1.1  jmcneill  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     54  1.1  jmcneill  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     55  1.1  jmcneill  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     56  1.1  jmcneill  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     57  1.1  jmcneill  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     58  1.1  jmcneill  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     59  1.1  jmcneill  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     60  1.1  jmcneill  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     61  1.1  jmcneill  */
     62  1.1  jmcneill 
     63  1.1  jmcneill #define _POWERPC_BUS_DMA_PRIVATE
     64  1.1  jmcneill 
     65  1.1  jmcneill #include <sys/cdefs.h>
     66  1.2  jmcneill __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.2 2024/01/21 01:41:54 jmcneill Exp $");
     67  1.1  jmcneill 
     68  1.1  jmcneill #include "opt_compat_netbsd.h"
     69  1.1  jmcneill #include "opt_ddb.h"
     70  1.1  jmcneill #include "opt_ddbparam.h"
     71  1.1  jmcneill #include "opt_inet.h"
     72  1.1  jmcneill #include "opt_ns.h"
     73  1.1  jmcneill #include "opt_oea.h"
     74  1.1  jmcneill 
     75  1.1  jmcneill #include <sys/param.h>
     76  1.1  jmcneill #include <sys/buf.h>
     77  1.1  jmcneill #include <sys/bus.h>
     78  1.1  jmcneill #include <sys/conf.h>
     79  1.1  jmcneill #include <sys/device.h>
     80  1.1  jmcneill #include <sys/exec.h>
     81  1.1  jmcneill #include <sys/extent.h>
     82  1.1  jmcneill #include <sys/intr.h>
     83  1.1  jmcneill #include <sys/kernel.h>
     84  1.1  jmcneill #include <sys/kgdb.h>
     85  1.1  jmcneill #include <sys/ksyms.h>
     86  1.1  jmcneill #include <sys/mbuf.h>
     87  1.1  jmcneill #include <sys/mount.h>
     88  1.1  jmcneill #include <sys/msgbuf.h>
     89  1.1  jmcneill #include <sys/proc.h>
     90  1.1  jmcneill #include <sys/reboot.h>
     91  1.1  jmcneill #include <sys/syscallargs.h>
     92  1.1  jmcneill #include <sys/sysctl.h>
     93  1.1  jmcneill #include <sys/syslog.h>
     94  1.1  jmcneill #include <sys/systm.h>
     95  1.1  jmcneill 
     96  1.1  jmcneill #include <uvm/uvm_extern.h>
     97  1.1  jmcneill 
     98  1.1  jmcneill #include <machine/powerpc.h>
     99  1.1  jmcneill #include <machine/wii.h>
    100  1.1  jmcneill 
    101  1.1  jmcneill #include <powerpc/bus_funcs.h>
    102  1.1  jmcneill #include <powerpc/db_machdep.h>
    103  1.1  jmcneill #include <powerpc/pio.h>
    104  1.1  jmcneill #include <powerpc/pmap.h>
    105  1.1  jmcneill #include <powerpc/spr.h>
    106  1.1  jmcneill #include <powerpc/trap.h>
    107  1.1  jmcneill 
    108  1.1  jmcneill #include <powerpc/oea/bat.h>
    109  1.1  jmcneill #include <powerpc/oea/spr.h>
    110  1.1  jmcneill #include <powerpc/pic/picvar.h>
    111  1.1  jmcneill 
    112  1.1  jmcneill #include <ddb/db_extern.h>
    113  1.1  jmcneill 
    114  1.1  jmcneill #include <dev/wscons/wsconsio.h>
    115  1.1  jmcneill #include <dev/wscons/wsdisplayvar.h>
    116  1.1  jmcneill #include <dev/rasops/rasops.h>
    117  1.1  jmcneill #include <dev/wsfont/wsfont.h>
    118  1.1  jmcneill #include <dev/wscons/wsdisplay_vconsvar.h>
    119  1.1  jmcneill 
    120  1.1  jmcneill #include <dev/usb/ukbdvar.h>
    121  1.1  jmcneill 
    122  1.1  jmcneill #include "ksyms.h"
    123  1.1  jmcneill #include "ukbd.h"
    124  1.1  jmcneill 
    125  1.1  jmcneill #define IBM750CL_SPR_HID4	1011
    126  1.1  jmcneill #define	 L2_CCFI		0x00100000	/* L2 complete castout prior
    127  1.1  jmcneill 						 * to L2 flash invalidate.
    128  1.1  jmcneill 						 */
    129  1.1  jmcneill 
    130  1.1  jmcneill extern u_int l2cr_config;
    131  1.1  jmcneill 
    132  1.1  jmcneill struct powerpc_bus_space wii_mem_tag = {
    133  1.1  jmcneill 	.pbs_flags = _BUS_SPACE_BIG_ENDIAN |
    134  1.1  jmcneill 		     _BUS_SPACE_MEM_TYPE,
    135  1.1  jmcneill 	.pbs_offset = 0,
    136  1.1  jmcneill 	.pbs_base = 0x0c000000,
    137  1.1  jmcneill 	.pbs_limit = 0x0dffffff,
    138  1.1  jmcneill 	.pbs_extent = NULL,
    139  1.1  jmcneill };
    140  1.1  jmcneill 
    141  1.1  jmcneill static char ex_storage[1][EXTENT_FIXED_STORAGE_SIZE(EXTMAP_RANGES)]
    142  1.1  jmcneill     __attribute__((aligned(8)));
    143  1.1  jmcneill 
    144  1.1  jmcneill static bus_addr_t
    145  1.1  jmcneill wii_dma_phys_to_bus_mem(bus_dma_tag_t t, bus_addr_t addr)
    146  1.1  jmcneill {
    147  1.1  jmcneill 	return addr;
    148  1.1  jmcneill }
    149  1.1  jmcneill 
    150  1.1  jmcneill static bus_addr_t
    151  1.1  jmcneill wii_dma_bus_mem_to_phys(bus_dma_tag_t t, bus_addr_t addr)
    152  1.1  jmcneill {
    153  1.1  jmcneill 	return addr;
    154  1.1  jmcneill }
    155  1.1  jmcneill 
    156  1.1  jmcneill static int
    157  1.1  jmcneill wii_mem2_dmamem_alloc(bus_dma_tag_t t, bus_size_t size, bus_size_t alignment,
    158  1.1  jmcneill     bus_size_t boundary, bus_dma_segment_t *segs, int nsegs, int *rsegs,
    159  1.1  jmcneill     int flags)
    160  1.1  jmcneill {
    161  1.1  jmcneill 	struct mem_region *mem, *avail;
    162  1.1  jmcneill 
    163  1.1  jmcneill 	/* Restrict memory used for DMA to ranges in MEM2 */
    164  1.1  jmcneill 	mem_regions(&mem, &avail);
    165  1.1  jmcneill 	if (mem[1].size == 0) {
    166  1.1  jmcneill 		return ENOMEM;
    167  1.1  jmcneill 	}
    168  1.1  jmcneill 
    169  1.1  jmcneill 	return _bus_dmamem_alloc_range(t, size, alignment, boundary, segs,
    170  1.1  jmcneill 	    nsegs, rsegs, flags, mem[1].start,
    171  1.1  jmcneill 	    mem[1].start + mem[1].size - PAGE_SIZE - 1);
    172  1.1  jmcneill }
    173  1.1  jmcneill 
    174  1.1  jmcneill struct powerpc_bus_dma_tag wii_bus_dma_tag = {
    175  1.1  jmcneill 	0,				/* _bounce_thresh */
    176  1.1  jmcneill 	_bus_dmamap_create,
    177  1.1  jmcneill 	_bus_dmamap_destroy,
    178  1.1  jmcneill 	_bus_dmamap_load,
    179  1.1  jmcneill 	_bus_dmamap_load_mbuf,
    180  1.1  jmcneill 	_bus_dmamap_load_uio,
    181  1.1  jmcneill 	_bus_dmamap_load_raw,
    182  1.1  jmcneill 	_bus_dmamap_unload,
    183  1.1  jmcneill 	_bus_dmamap_sync,
    184  1.1  jmcneill 	_bus_dmamem_alloc,
    185  1.1  jmcneill 	_bus_dmamem_free,
    186  1.1  jmcneill 	_bus_dmamem_map,
    187  1.1  jmcneill 	_bus_dmamem_unmap,
    188  1.1  jmcneill 	_bus_dmamem_mmap,
    189  1.1  jmcneill 	wii_dma_phys_to_bus_mem,
    190  1.1  jmcneill 	wii_dma_bus_mem_to_phys,
    191  1.1  jmcneill };
    192  1.1  jmcneill 
    193  1.1  jmcneill struct powerpc_bus_dma_tag wii_mem2_bus_dma_tag = {
    194  1.1  jmcneill 	0,				/* _bounce_thresh */
    195  1.1  jmcneill 	_bus_dmamap_create,
    196  1.1  jmcneill 	_bus_dmamap_destroy,
    197  1.1  jmcneill 	_bus_dmamap_load,
    198  1.1  jmcneill 	_bus_dmamap_load_mbuf,
    199  1.1  jmcneill 	_bus_dmamap_load_uio,
    200  1.1  jmcneill 	_bus_dmamap_load_raw,
    201  1.1  jmcneill 	_bus_dmamap_unload,
    202  1.1  jmcneill 	_bus_dmamap_sync,
    203  1.1  jmcneill 	wii_mem2_dmamem_alloc,
    204  1.1  jmcneill 	_bus_dmamem_free,
    205  1.1  jmcneill 	_bus_dmamem_map,
    206  1.1  jmcneill 	_bus_dmamem_unmap,
    207  1.1  jmcneill 	_bus_dmamem_mmap,
    208  1.1  jmcneill 	wii_dma_phys_to_bus_mem,
    209  1.1  jmcneill 	wii_dma_bus_mem_to_phys,
    210  1.1  jmcneill };
    211  1.1  jmcneill 
    212  1.1  jmcneill 
    213  1.1  jmcneill /*
    214  1.1  jmcneill  * Global variables used here and there
    215  1.1  jmcneill  */
    216  1.1  jmcneill struct mem_region physmemr[3], availmemr[3];
    217  1.1  jmcneill 
    218  1.1  jmcneill void initppc(u_int, u_int, u_int, void *); /* Called from locore */
    219  1.1  jmcneill void wii_dolphin_elf_loader_id(void);
    220  1.1  jmcneill 
    221  1.1  jmcneill static void wii_setup(void);
    222  1.1  jmcneill static void init_decrementer(void);
    223  1.1  jmcneill 
    224  1.1  jmcneill void
    225  1.1  jmcneill initppc(u_int startkernel, u_int endkernel, u_int args, void *btinfo)
    226  1.1  jmcneill {
    227  1.1  jmcneill 	extern u_long ticks_per_sec;
    228  1.1  jmcneill 	extern unsigned char edata[], end[];
    229  1.1  jmcneill 	uint32_t mem2_size;
    230  1.1  jmcneill 	register_t scratch;
    231  1.1  jmcneill 
    232  1.1  jmcneill 	memset(&edata, 0, end - edata); /* clear BSS */
    233  1.1  jmcneill 
    234  1.1  jmcneill 	mem2_size = in32(GLOBAL_MEM2_SIZE);
    235  1.1  jmcneill 
    236  1.1  jmcneill 	/* MEM1 24MB 1T-SRAM */
    237  1.1  jmcneill 	physmemr[0].start = WII_MEM1_BASE;
    238  1.1  jmcneill 	physmemr[0].size = WII_MEM1_SIZE;
    239  1.1  jmcneill 
    240  1.1  jmcneill 	/* MEM2 64MB GDDR3 */
    241  1.1  jmcneill 	physmemr[1].start = WII_MEM2_BASE;
    242  1.1  jmcneill 	physmemr[1].size = mem2_size;
    243  1.1  jmcneill 
    244  1.1  jmcneill 	physmemr[2].size = 0;
    245  1.1  jmcneill 
    246  1.1  jmcneill 	/* MEM1 available memory */
    247  1.1  jmcneill 	availmemr[0].start = ((endkernel & ~0x80000000) + PGOFSET) & ~PGOFSET;
    248  1.1  jmcneill 	availmemr[0].size = physmemr[0].size - availmemr[0].start;
    249  1.1  jmcneill 	/* External framebuffer is at the end of MEM1 */
    250  1.1  jmcneill 	availmemr[0].size -= XFB_SIZE;
    251  1.1  jmcneill 
    252  1.1  jmcneill 	/* MEM2 available memory */
    253  1.1  jmcneill 	availmemr[1].start = physmemr[1].start;
    254  1.1  jmcneill 	availmemr[1].size = physmemr[1].size;
    255  1.1  jmcneill 	if (mem2_size != 0) {
    256  1.1  jmcneill 		/* DSP uses 16KB at the start of MEM2 */
    257  1.1  jmcneill 		availmemr[1].start += DSP_SIZE;
    258  1.1  jmcneill 		availmemr[1].size -= DSP_SIZE;
    259  1.1  jmcneill 		/* IPC and Starlet use memory at the end of MEM2 */
    260  1.1  jmcneill 		availmemr[1].size -= IPC_SIZE;
    261  1.1  jmcneill 		availmemr[1].size -= ARM_SIZE;
    262  1.1  jmcneill 	}
    263  1.1  jmcneill 
    264  1.1  jmcneill 	availmemr[2].size = 0;
    265  1.1  jmcneill 
    266  1.1  jmcneill #ifdef BOOTHOWTO
    267  1.1  jmcneill 	/*
    268  1.1  jmcneill 	 * boothowto
    269  1.1  jmcneill 	 */
    270  1.1  jmcneill 	boothowto = BOOTHOWTO;
    271  1.1  jmcneill #endif
    272  1.1  jmcneill 
    273  1.1  jmcneill 	/* HID4[L2_CCFI] must be set to 1 for correct operation of L2 cache */
    274  1.1  jmcneill 	mtspr(IBM750CL_SPR_HID4, mfspr(IBM750CL_SPR_HID4) | L2_CCFI);
    275  1.1  jmcneill 
    276  1.1  jmcneill 	/* Configure L2 cache */
    277  1.1  jmcneill 	l2cr_config = L2CR_L2E | L2CR_L2PE;
    278  1.1  jmcneill 
    279  1.1  jmcneill 	if (bus_space_init(&wii_mem_tag, "iomem",
    280  1.1  jmcneill 			   ex_storage[0], sizeof(ex_storage[0]))) {
    281  1.1  jmcneill 		panic("bus_space_init failed");
    282  1.1  jmcneill 	}
    283  1.1  jmcneill 
    284  1.1  jmcneill 	/*
    285  1.1  jmcneill 	 * Initialize the BAT registers
    286  1.1  jmcneill 	 */
    287  1.1  jmcneill 	oea_batinit(
    288  1.1  jmcneill 	    WII_IOMEM_BASE, BAT_BL_32M,
    289  1.1  jmcneill 	    0);
    290  1.1  jmcneill 
    291  1.1  jmcneill 	/*
    292  1.1  jmcneill 	 * Set up trap vectors
    293  1.1  jmcneill 	 */
    294  1.1  jmcneill 	oea_init(NULL);
    295  1.1  jmcneill 
    296  1.1  jmcneill 	/*
    297  1.1  jmcneill 	 * Get CPU clock
    298  1.1  jmcneill 	 */
    299  1.1  jmcneill 	ticks_per_sec = TIMEBASE_FREQ_HZ;
    300  1.1  jmcneill 	cpu_timebase = ticks_per_sec;
    301  1.1  jmcneill 
    302  1.1  jmcneill 	wii_setup();
    303  1.1  jmcneill 
    304  1.1  jmcneill 	uvm_md_init();
    305  1.1  jmcneill 
    306  1.1  jmcneill 	/*
    307  1.1  jmcneill 	 * Initialize pmap module.
    308  1.1  jmcneill 	 */
    309  1.1  jmcneill 	pmap_bootstrap(startkernel, endkernel);
    310  1.1  jmcneill 
    311  1.1  jmcneill 	/* Now enable translation (and machine checks/recoverable interrupts) */
    312  1.1  jmcneill 	__asm __volatile ("sync; mfmsr %0; ori %0,%0,%1; mtmsr %0; isync"
    313  1.1  jmcneill 			  : "=r"(scratch)
    314  1.1  jmcneill 			  : "K"(PSL_IR|PSL_DR|PSL_ME|PSL_RI));
    315  1.1  jmcneill 
    316  1.1  jmcneill 	/*
    317  1.1  jmcneill 	 * Setup decrementer
    318  1.1  jmcneill 	 */
    319  1.1  jmcneill 	init_decrementer();
    320  1.1  jmcneill }
    321  1.1  jmcneill 
    322  1.1  jmcneill void
    323  1.1  jmcneill mem_regions(struct mem_region **mem, struct mem_region **avail)
    324  1.1  jmcneill {
    325  1.1  jmcneill 	*mem = physmemr;
    326  1.1  jmcneill 	*avail = availmemr;
    327  1.1  jmcneill }
    328  1.1  jmcneill 
    329  1.1  jmcneill /*
    330  1.1  jmcneill  * Machine dependent startup code.
    331  1.1  jmcneill  */
    332  1.1  jmcneill void
    333  1.1  jmcneill cpu_startup(void)
    334  1.1  jmcneill {
    335  1.1  jmcneill 	extern void pi_init_intr(void);
    336  1.1  jmcneill 
    337  1.1  jmcneill 	oea_startup(NULL);
    338  1.1  jmcneill 
    339  1.1  jmcneill 	/*
    340  1.1  jmcneill 	 * Now that we have VM, malloc()s are OK in bus_space.
    341  1.1  jmcneill 	 */
    342  1.1  jmcneill 	bus_space_mallocok();
    343  1.1  jmcneill 
    344  1.1  jmcneill 	/* Set up interrupt controller */
    345  1.1  jmcneill 	pic_init();
    346  1.1  jmcneill 	pi_init_intr();
    347  1.1  jmcneill 	oea_install_extint(pic_ext_intr);
    348  1.1  jmcneill }
    349  1.1  jmcneill 
    350  1.1  jmcneill /*
    351  1.1  jmcneill  * No early console support.
    352  1.1  jmcneill  */
    353  1.1  jmcneill void
    354  1.1  jmcneill consinit(void)
    355  1.1  jmcneill {
    356  1.1  jmcneill #if NUKBD > 0
    357  1.1  jmcneill 	ukbd_cnattach();
    358  1.1  jmcneill #endif
    359  1.1  jmcneill }
    360  1.1  jmcneill 
    361  1.1  jmcneill /*
    362  1.1  jmcneill  * Halt or reboot the machine after syncing/dumping according to howto.
    363  1.1  jmcneill  */
    364  1.1  jmcneill void
    365  1.1  jmcneill cpu_reboot(int howto, char *what)
    366  1.1  jmcneill {
    367  1.1  jmcneill 	static int syncing;
    368  1.1  jmcneill 	extern void disable_intr(void);
    369  1.1  jmcneill 
    370  1.1  jmcneill 	boothowto = howto;
    371  1.1  jmcneill 	if (!cold && !(howto & RB_NOSYNC) && !syncing) {
    372  1.1  jmcneill 		syncing = 1;
    373  1.1  jmcneill 		vfs_shutdown();		/* sync */
    374  1.1  jmcneill 		resettodr();		/* set wall clock */
    375  1.1  jmcneill 	}
    376  1.1  jmcneill 	splhigh();
    377  1.1  jmcneill 	if (!cold && (howto & RB_DUMP)) {
    378  1.1  jmcneill 		oea_dumpsys();
    379  1.1  jmcneill 	}
    380  1.1  jmcneill 	pmf_system_shutdown(boothowto);
    381  1.1  jmcneill 	doshutdownhooks();
    382  1.2  jmcneill 
    383  1.2  jmcneill 	disable_intr();
    384  1.2  jmcneill 
    385  1.1  jmcneill 	/* Force halt on panic to capture the cause on screen. */
    386  1.1  jmcneill 	if (panicstr != NULL) {
    387  1.1  jmcneill 		howto |= RB_HALT;
    388  1.1  jmcneill 	}
    389  1.2  jmcneill 	if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
    390  1.2  jmcneill 		printf("power off\n\n");
    391  1.2  jmcneill 		out32(HW_GPIOB_OUT, in32(HW_GPIOB_OUT) | __BIT(GPIO_SHUTDOWN));
    392  1.2  jmcneill 		delay(100000);
    393  1.2  jmcneill 		printf("power off failed!\n\n");
    394  1.2  jmcneill 	}
    395  1.1  jmcneill 	if (howto & RB_HALT) {
    396  1.1  jmcneill 		printf("halted\n\n");
    397  1.1  jmcneill 		while (1);
    398  1.1  jmcneill 	}
    399  1.1  jmcneill 
    400  1.1  jmcneill 	printf("rebooting\n\n");
    401  1.1  jmcneill 	out32(HW_RESETS, in32(HW_RESETS) & ~RSTBINB);
    402  1.1  jmcneill 	while (1);
    403  1.1  jmcneill }
    404  1.1  jmcneill 
    405  1.1  jmcneill static void
    406  1.1  jmcneill wii_setup(void)
    407  1.1  jmcneill {
    408  1.1  jmcneill 	/* Turn on the drive slot LED. */
    409  1.1  jmcneill 	out32(HW_GPIOB_OUT, in32(HW_GPIOB_OUT) | __BIT(GPIO_SLOT_LED));
    410  1.2  jmcneill 
    411  1.2  jmcneill 	/* Enable PPC access to SHUTDOWN GPIO. */
    412  1.2  jmcneill 	out32(HW_GPIO_OWNER, in32(HW_GPIO_OWNER) | __BIT(GPIO_SHUTDOWN));
    413  1.1  jmcneill }
    414  1.1  jmcneill 
    415  1.1  jmcneill static void
    416  1.1  jmcneill init_decrementer(void)
    417  1.1  jmcneill {
    418  1.1  jmcneill 	extern uint32_t ns_per_tick;
    419  1.1  jmcneill 	extern uint32_t ticks_per_intr;
    420  1.1  jmcneill 	extern u_long ticks_per_sec;
    421  1.1  jmcneill 	int scratch, msr;
    422  1.1  jmcneill 
    423  1.1  jmcneill 	KASSERT(ticks_per_sec != 0);
    424  1.1  jmcneill 
    425  1.1  jmcneill 	__asm volatile ("mfmsr %0; andi. %1,%0,%2; mtmsr %1"
    426  1.1  jmcneill 			: "=r"(msr), "=r"(scratch) : "K"((u_short)~PSL_EE));
    427  1.1  jmcneill 	ns_per_tick = 1000000000 / ticks_per_sec;
    428  1.1  jmcneill 	ticks_per_intr = ticks_per_sec / hz;
    429  1.1  jmcneill 	cpu_timebase = ticks_per_sec;
    430  1.1  jmcneill 
    431  1.1  jmcneill 	curcpu()->ci_lasttb = mftbl();
    432  1.1  jmcneill 
    433  1.1  jmcneill 	mtspr(SPR_DEC, ticks_per_intr);
    434  1.1  jmcneill 	mtmsr(msr);
    435  1.1  jmcneill }
    436