Home | History | Annotate | Line # | Download | only in wii
machdep.c revision 1.6.2.1
      1  1.6.2.1  perseant /* $NetBSD: machdep.c,v 1.6.2.1 2025/08/02 05:55:36 perseant 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.6.2.1  perseant __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.6.2.1 2025/08/02 05:55:36 perseant 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.6.2.1  perseant #ifndef WII_DEFAULT_CMDLINE
    126  1.6.2.1  perseant #define WII_DEFAULT_CMDLINE "root=ld0a"
    127  1.6.2.1  perseant #endif
    128  1.6.2.1  perseant 
    129      1.1  jmcneill #define IBM750CL_SPR_HID4	1011
    130      1.1  jmcneill #define	 L2_CCFI		0x00100000	/* L2 complete castout prior
    131      1.1  jmcneill 						 * to L2 flash invalidate.
    132      1.1  jmcneill 						 */
    133      1.1  jmcneill 
    134  1.6.2.1  perseant #define MINI_MEM2_START		0x13f00000	/* Start of reserved MEM2 for MINI */
    135  1.6.2.1  perseant 
    136      1.1  jmcneill extern u_int l2cr_config;
    137      1.1  jmcneill 
    138      1.1  jmcneill struct powerpc_bus_space wii_mem_tag = {
    139      1.1  jmcneill 	.pbs_flags = _BUS_SPACE_BIG_ENDIAN |
    140      1.1  jmcneill 		     _BUS_SPACE_MEM_TYPE,
    141      1.1  jmcneill 	.pbs_offset = 0,
    142      1.1  jmcneill 	.pbs_base = 0x0c000000,
    143      1.1  jmcneill 	.pbs_limit = 0x0dffffff,
    144      1.1  jmcneill 	.pbs_extent = NULL,
    145      1.1  jmcneill };
    146      1.1  jmcneill 
    147      1.1  jmcneill static char ex_storage[1][EXTENT_FIXED_STORAGE_SIZE(EXTMAP_RANGES)]
    148      1.1  jmcneill     __attribute__((aligned(8)));
    149      1.1  jmcneill 
    150      1.1  jmcneill static bus_addr_t
    151      1.1  jmcneill wii_dma_phys_to_bus_mem(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 bus_addr_t
    157      1.1  jmcneill wii_dma_bus_mem_to_phys(bus_dma_tag_t t, bus_addr_t addr)
    158      1.1  jmcneill {
    159      1.1  jmcneill 	return addr;
    160      1.1  jmcneill }
    161      1.1  jmcneill 
    162      1.1  jmcneill static int
    163      1.1  jmcneill wii_mem2_dmamem_alloc(bus_dma_tag_t t, bus_size_t size, bus_size_t alignment,
    164      1.1  jmcneill     bus_size_t boundary, bus_dma_segment_t *segs, int nsegs, int *rsegs,
    165      1.1  jmcneill     int flags)
    166      1.1  jmcneill {
    167      1.1  jmcneill 	struct mem_region *mem, *avail;
    168      1.1  jmcneill 
    169      1.1  jmcneill 	/* Restrict memory used for DMA to ranges in MEM2 */
    170      1.1  jmcneill 	mem_regions(&mem, &avail);
    171      1.1  jmcneill 	if (mem[1].size == 0) {
    172      1.1  jmcneill 		return ENOMEM;
    173      1.1  jmcneill 	}
    174      1.1  jmcneill 
    175      1.1  jmcneill 	return _bus_dmamem_alloc_range(t, size, alignment, boundary, segs,
    176      1.1  jmcneill 	    nsegs, rsegs, flags, mem[1].start,
    177      1.1  jmcneill 	    mem[1].start + mem[1].size - PAGE_SIZE - 1);
    178      1.1  jmcneill }
    179      1.1  jmcneill 
    180      1.1  jmcneill struct powerpc_bus_dma_tag wii_bus_dma_tag = {
    181      1.1  jmcneill 	0,				/* _bounce_thresh */
    182      1.1  jmcneill 	_bus_dmamap_create,
    183      1.1  jmcneill 	_bus_dmamap_destroy,
    184      1.1  jmcneill 	_bus_dmamap_load,
    185      1.1  jmcneill 	_bus_dmamap_load_mbuf,
    186      1.1  jmcneill 	_bus_dmamap_load_uio,
    187      1.1  jmcneill 	_bus_dmamap_load_raw,
    188      1.1  jmcneill 	_bus_dmamap_unload,
    189      1.1  jmcneill 	_bus_dmamap_sync,
    190      1.1  jmcneill 	_bus_dmamem_alloc,
    191      1.1  jmcneill 	_bus_dmamem_free,
    192      1.1  jmcneill 	_bus_dmamem_map,
    193      1.1  jmcneill 	_bus_dmamem_unmap,
    194      1.1  jmcneill 	_bus_dmamem_mmap,
    195      1.1  jmcneill 	wii_dma_phys_to_bus_mem,
    196      1.1  jmcneill 	wii_dma_bus_mem_to_phys,
    197      1.1  jmcneill };
    198      1.1  jmcneill 
    199      1.1  jmcneill struct powerpc_bus_dma_tag wii_mem2_bus_dma_tag = {
    200      1.1  jmcneill 	0,				/* _bounce_thresh */
    201      1.1  jmcneill 	_bus_dmamap_create,
    202      1.1  jmcneill 	_bus_dmamap_destroy,
    203      1.1  jmcneill 	_bus_dmamap_load,
    204      1.1  jmcneill 	_bus_dmamap_load_mbuf,
    205      1.1  jmcneill 	_bus_dmamap_load_uio,
    206      1.1  jmcneill 	_bus_dmamap_load_raw,
    207      1.1  jmcneill 	_bus_dmamap_unload,
    208      1.1  jmcneill 	_bus_dmamap_sync,
    209      1.1  jmcneill 	wii_mem2_dmamem_alloc,
    210      1.1  jmcneill 	_bus_dmamem_free,
    211      1.1  jmcneill 	_bus_dmamem_map,
    212      1.1  jmcneill 	_bus_dmamem_unmap,
    213      1.1  jmcneill 	_bus_dmamem_mmap,
    214      1.1  jmcneill 	wii_dma_phys_to_bus_mem,
    215      1.1  jmcneill 	wii_dma_bus_mem_to_phys,
    216      1.1  jmcneill };
    217      1.1  jmcneill 
    218      1.1  jmcneill 
    219      1.1  jmcneill /*
    220      1.1  jmcneill  * Global variables used here and there
    221      1.1  jmcneill  */
    222      1.1  jmcneill struct mem_region physmemr[3], availmemr[3];
    223      1.4  jmcneill char wii_cmdline[1024];
    224      1.1  jmcneill 
    225      1.1  jmcneill void initppc(u_int, u_int, u_int, void *); /* Called from locore */
    226      1.1  jmcneill void wii_dolphin_elf_loader_id(void);
    227      1.1  jmcneill 
    228      1.1  jmcneill static void wii_setup(void);
    229      1.1  jmcneill static void init_decrementer(void);
    230      1.1  jmcneill 
    231      1.1  jmcneill void
    232      1.1  jmcneill initppc(u_int startkernel, u_int endkernel, u_int args, void *btinfo)
    233      1.1  jmcneill {
    234  1.6.2.1  perseant 	extern uint32_t ticks_per_sec;
    235  1.6.2.1  perseant 	extern uint32_t ticks_per_msec;
    236      1.1  jmcneill 	extern unsigned char edata[], end[];
    237      1.4  jmcneill 	extern struct wii_argv wii_argv;
    238      1.5  jmcneill 	uint32_t mem2_start, mem2_end;
    239      1.1  jmcneill 	register_t scratch;
    240      1.1  jmcneill 
    241      1.1  jmcneill 	memset(&edata, 0, end - edata); /* clear BSS */
    242      1.1  jmcneill 
    243  1.6.2.1  perseant 	wii_cmdline[0] = '\0';
    244      1.4  jmcneill 	if (wii_argv.magic == WII_ARGV_MAGIC) {
    245      1.4  jmcneill 		void *ptr = (void *)(uintptr_t)(wii_argv.cmdline & ~0x80000000);
    246      1.4  jmcneill 		if (ptr != NULL) {
    247      1.4  jmcneill 			memcpy(wii_cmdline, ptr, wii_argv.length);
    248      1.4  jmcneill 		}
    249  1.6.2.1  perseant 	} else {
    250  1.6.2.1  perseant 		snprintf(wii_cmdline, sizeof(wii_cmdline), WII_DEFAULT_CMDLINE);
    251      1.4  jmcneill 	}
    252      1.4  jmcneill 
    253      1.5  jmcneill 	mem2_start = in32(GLOBAL_MEM2_AVAIL_START) & ~0x80000000;
    254      1.5  jmcneill 	mem2_end = in32(GLOBAL_MEM2_AVAIL_END) & ~0x80000000;
    255  1.6.2.1  perseant 	if (mem2_start < WII_MEM2_BASE) {
    256  1.6.2.1  perseant 		/* Must have been booted from MINI. */
    257  1.6.2.1  perseant 		mem2_start = WII_MEM2_BASE + DSP_MEM_SIZE;
    258  1.6.2.1  perseant 		mem2_end = MINI_MEM2_START;
    259  1.6.2.1  perseant 	}
    260  1.6.2.1  perseant 	/*
    261  1.6.2.1  perseant 	 * Clear GLOBAL_MEM2_AVAIL_{START,END} so we can detect the correct
    262  1.6.2.1  perseant 	 * memory size when soft resetting from IOS to MINI.
    263  1.6.2.1  perseant 	 */
    264  1.6.2.1  perseant 	out32(GLOBAL_MEM2_AVAIL_START, 0);
    265  1.6.2.1  perseant 	out32(GLOBAL_MEM2_AVAIL_END, 0);
    266      1.1  jmcneill 
    267      1.1  jmcneill 	/* MEM1 24MB 1T-SRAM */
    268      1.1  jmcneill 	physmemr[0].start = WII_MEM1_BASE;
    269      1.1  jmcneill 	physmemr[0].size = WII_MEM1_SIZE;
    270      1.1  jmcneill 
    271      1.1  jmcneill 	/* MEM2 64MB GDDR3 */
    272      1.1  jmcneill 	physmemr[1].start = WII_MEM2_BASE;
    273      1.5  jmcneill 	physmemr[1].size = WII_MEM2_SIZE;
    274      1.1  jmcneill 
    275      1.1  jmcneill 	physmemr[2].size = 0;
    276      1.1  jmcneill 
    277      1.1  jmcneill 	/* MEM1 available memory */
    278      1.1  jmcneill 	availmemr[0].start = ((endkernel & ~0x80000000) + PGOFSET) & ~PGOFSET;
    279      1.1  jmcneill 	availmemr[0].size = physmemr[0].size - availmemr[0].start;
    280      1.1  jmcneill 	/* External framebuffer is at the end of MEM1 */
    281      1.1  jmcneill 	availmemr[0].size -= XFB_SIZE;
    282      1.1  jmcneill 
    283      1.1  jmcneill 	/* MEM2 available memory */
    284      1.5  jmcneill 	availmemr[1].start = mem2_start;
    285      1.5  jmcneill 	availmemr[1].size = mem2_end - mem2_start;
    286      1.1  jmcneill 
    287      1.1  jmcneill 	availmemr[2].size = 0;
    288      1.1  jmcneill 
    289      1.1  jmcneill #ifdef BOOTHOWTO
    290      1.1  jmcneill 	/*
    291      1.1  jmcneill 	 * boothowto
    292      1.1  jmcneill 	 */
    293      1.1  jmcneill 	boothowto = BOOTHOWTO;
    294      1.1  jmcneill #endif
    295      1.1  jmcneill 
    296      1.1  jmcneill 	/* HID4[L2_CCFI] must be set to 1 for correct operation of L2 cache */
    297      1.1  jmcneill 	mtspr(IBM750CL_SPR_HID4, mfspr(IBM750CL_SPR_HID4) | L2_CCFI);
    298      1.1  jmcneill 
    299      1.1  jmcneill 	/* Configure L2 cache */
    300      1.1  jmcneill 	l2cr_config = L2CR_L2E | L2CR_L2PE;
    301      1.1  jmcneill 
    302      1.1  jmcneill 	if (bus_space_init(&wii_mem_tag, "iomem",
    303      1.1  jmcneill 			   ex_storage[0], sizeof(ex_storage[0]))) {
    304      1.1  jmcneill 		panic("bus_space_init failed");
    305      1.1  jmcneill 	}
    306      1.1  jmcneill 
    307      1.1  jmcneill 	/*
    308      1.1  jmcneill 	 * Initialize the BAT registers
    309      1.1  jmcneill 	 */
    310      1.1  jmcneill 	oea_batinit(
    311      1.1  jmcneill 	    WII_IOMEM_BASE, BAT_BL_32M,
    312      1.1  jmcneill 	    0);
    313      1.1  jmcneill 
    314      1.1  jmcneill 	/*
    315      1.1  jmcneill 	 * Set up trap vectors
    316      1.1  jmcneill 	 */
    317      1.1  jmcneill 	oea_init(NULL);
    318      1.1  jmcneill 
    319      1.1  jmcneill 	/*
    320      1.1  jmcneill 	 * Get CPU clock
    321      1.1  jmcneill 	 */
    322      1.1  jmcneill 	ticks_per_sec = TIMEBASE_FREQ_HZ;
    323  1.6.2.1  perseant 	ticks_per_msec = ticks_per_sec / 1000;
    324      1.1  jmcneill 	cpu_timebase = ticks_per_sec;
    325      1.1  jmcneill 
    326      1.1  jmcneill 	wii_setup();
    327      1.1  jmcneill 
    328      1.1  jmcneill 	uvm_md_init();
    329      1.1  jmcneill 
    330      1.1  jmcneill 	/*
    331      1.1  jmcneill 	 * Initialize pmap module.
    332      1.1  jmcneill 	 */
    333      1.1  jmcneill 	pmap_bootstrap(startkernel, endkernel);
    334      1.1  jmcneill 
    335      1.1  jmcneill 	/* Now enable translation (and machine checks/recoverable interrupts) */
    336      1.1  jmcneill 	__asm __volatile ("sync; mfmsr %0; ori %0,%0,%1; mtmsr %0; isync"
    337      1.1  jmcneill 			  : "=r"(scratch)
    338      1.1  jmcneill 			  : "K"(PSL_IR|PSL_DR|PSL_ME|PSL_RI));
    339      1.1  jmcneill 
    340      1.1  jmcneill 	/*
    341      1.1  jmcneill 	 * Setup decrementer
    342      1.1  jmcneill 	 */
    343      1.1  jmcneill 	init_decrementer();
    344      1.1  jmcneill }
    345      1.1  jmcneill 
    346      1.1  jmcneill void
    347      1.1  jmcneill mem_regions(struct mem_region **mem, struct mem_region **avail)
    348      1.1  jmcneill {
    349      1.1  jmcneill 	*mem = physmemr;
    350      1.1  jmcneill 	*avail = availmemr;
    351      1.1  jmcneill }
    352      1.1  jmcneill 
    353      1.1  jmcneill /*
    354      1.1  jmcneill  * Machine dependent startup code.
    355      1.1  jmcneill  */
    356      1.1  jmcneill void
    357      1.1  jmcneill cpu_startup(void)
    358      1.1  jmcneill {
    359      1.1  jmcneill 	extern void pi_init_intr(void);
    360      1.1  jmcneill 
    361      1.1  jmcneill 	oea_startup(NULL);
    362      1.1  jmcneill 
    363      1.1  jmcneill 	/*
    364      1.1  jmcneill 	 * Now that we have VM, malloc()s are OK in bus_space.
    365      1.1  jmcneill 	 */
    366      1.1  jmcneill 	bus_space_mallocok();
    367      1.1  jmcneill 
    368      1.1  jmcneill 	/* Set up interrupt controller */
    369      1.1  jmcneill 	pic_init();
    370      1.1  jmcneill 	pi_init_intr();
    371      1.1  jmcneill 	oea_install_extint(pic_ext_intr);
    372      1.1  jmcneill }
    373      1.1  jmcneill 
    374      1.1  jmcneill /*
    375      1.1  jmcneill  * No early console support.
    376      1.1  jmcneill  */
    377      1.1  jmcneill void
    378      1.1  jmcneill consinit(void)
    379      1.1  jmcneill {
    380      1.1  jmcneill #if NUKBD > 0
    381      1.1  jmcneill 	ukbd_cnattach();
    382      1.1  jmcneill #endif
    383      1.1  jmcneill }
    384      1.1  jmcneill 
    385      1.1  jmcneill /*
    386      1.1  jmcneill  * Halt or reboot the machine after syncing/dumping according to howto.
    387      1.1  jmcneill  */
    388      1.1  jmcneill void
    389      1.1  jmcneill cpu_reboot(int howto, char *what)
    390      1.1  jmcneill {
    391      1.1  jmcneill 	static int syncing;
    392      1.1  jmcneill 	extern void disable_intr(void);
    393      1.1  jmcneill 
    394      1.1  jmcneill 	boothowto = howto;
    395      1.1  jmcneill 	if (!cold && !(howto & RB_NOSYNC) && !syncing) {
    396      1.1  jmcneill 		syncing = 1;
    397      1.1  jmcneill 		vfs_shutdown();		/* sync */
    398      1.1  jmcneill 	}
    399      1.1  jmcneill 	splhigh();
    400      1.1  jmcneill 	if (!cold && (howto & RB_DUMP)) {
    401      1.1  jmcneill 		oea_dumpsys();
    402      1.1  jmcneill 	}
    403      1.1  jmcneill 	pmf_system_shutdown(boothowto);
    404      1.1  jmcneill 	doshutdownhooks();
    405      1.2  jmcneill 
    406      1.2  jmcneill 	disable_intr();
    407      1.2  jmcneill 
    408      1.1  jmcneill 	/* Force halt on panic to capture the cause on screen. */
    409      1.1  jmcneill 	if (panicstr != NULL) {
    410      1.1  jmcneill 		howto |= RB_HALT;
    411      1.1  jmcneill 	}
    412      1.2  jmcneill 	if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
    413      1.2  jmcneill 		printf("power off\n\n");
    414      1.2  jmcneill 		out32(HW_GPIOB_OUT, in32(HW_GPIOB_OUT) | __BIT(GPIO_SHUTDOWN));
    415      1.2  jmcneill 		delay(100000);
    416      1.2  jmcneill 		printf("power off failed!\n\n");
    417      1.2  jmcneill 	}
    418      1.1  jmcneill 	if (howto & RB_HALT) {
    419      1.1  jmcneill 		printf("halted\n\n");
    420      1.1  jmcneill 		while (1);
    421      1.1  jmcneill 	}
    422      1.1  jmcneill 
    423      1.1  jmcneill 	printf("rebooting\n\n");
    424      1.1  jmcneill 	out32(HW_RESETS, in32(HW_RESETS) & ~RSTBINB);
    425      1.1  jmcneill 	while (1);
    426      1.1  jmcneill }
    427      1.1  jmcneill 
    428      1.1  jmcneill static void
    429      1.1  jmcneill wii_setup(void)
    430      1.1  jmcneill {
    431      1.1  jmcneill 	/* Turn on the drive slot LED. */
    432  1.6.2.1  perseant 	wii_slot_led(true);
    433      1.2  jmcneill 
    434      1.2  jmcneill 	/* Enable PPC access to SHUTDOWN GPIO. */
    435      1.2  jmcneill 	out32(HW_GPIO_OWNER, in32(HW_GPIO_OWNER) | __BIT(GPIO_SHUTDOWN));
    436  1.6.2.1  perseant 
    437  1.6.2.1  perseant 	/* Enable PPC access to DI_SPIN GPIO. */
    438  1.6.2.1  perseant 	out32(HW_GPIO_OWNER, in32(HW_GPIO_OWNER) | __BIT(GPIO_DI_SPIN));
    439  1.6.2.1  perseant 
    440  1.6.2.1  perseant 	/* Enable PPC access to EXI bus. */
    441  1.6.2.1  perseant 	out32(HW_AIPPROT, in32(HW_AIPPROT) | ENAHBIOPI);
    442  1.6.2.1  perseant 
    443  1.6.2.1  perseant 	/* Enable DVD video support. */
    444  1.6.2.1  perseant 	out32(HW_COMPAT, in32(HW_COMPAT) & ~DVDVIDEO);
    445      1.1  jmcneill }
    446      1.1  jmcneill 
    447      1.1  jmcneill static void
    448      1.1  jmcneill init_decrementer(void)
    449      1.1  jmcneill {
    450      1.1  jmcneill 	extern uint32_t ns_per_tick;
    451      1.1  jmcneill 	extern uint32_t ticks_per_intr;
    452  1.6.2.1  perseant 	extern uint32_t ticks_per_sec;
    453      1.1  jmcneill 	int scratch, msr;
    454      1.1  jmcneill 
    455      1.1  jmcneill 	KASSERT(ticks_per_sec != 0);
    456      1.1  jmcneill 
    457      1.1  jmcneill 	__asm volatile ("mfmsr %0; andi. %1,%0,%2; mtmsr %1"
    458      1.1  jmcneill 			: "=r"(msr), "=r"(scratch) : "K"((u_short)~PSL_EE));
    459      1.1  jmcneill 	ns_per_tick = 1000000000 / ticks_per_sec;
    460      1.1  jmcneill 	ticks_per_intr = ticks_per_sec / hz;
    461      1.1  jmcneill 	cpu_timebase = ticks_per_sec;
    462      1.1  jmcneill 
    463      1.1  jmcneill 	curcpu()->ci_lasttb = mftbl();
    464      1.1  jmcneill 
    465      1.1  jmcneill 	mtspr(SPR_DEC, ticks_per_intr);
    466      1.1  jmcneill 	mtmsr(msr);
    467      1.1  jmcneill }
    468