Home | History | Annotate | Line # | Download | only in cavium
machdep.c revision 1.10.14.2
      1  1.10.14.2  jdolecek /*	$NetBSD: machdep.c,v 1.10.14.2 2017/12/03 11:36:08 jdolecek Exp $	*/
      2  1.10.14.2  jdolecek 
      3  1.10.14.2  jdolecek /*
      4  1.10.14.2  jdolecek  * Copyright 2001, 2002 Wasabi Systems, Inc.
      5  1.10.14.2  jdolecek  * All rights reserved.
      6  1.10.14.2  jdolecek  *
      7  1.10.14.2  jdolecek  * Written by Jason R. Thorpe and Simon Burge for Wasabi Systems, Inc.
      8  1.10.14.2  jdolecek  *
      9  1.10.14.2  jdolecek  * Redistribution and use in source and binary forms, with or without
     10  1.10.14.2  jdolecek  * modification, are permitted provided that the following conditions
     11  1.10.14.2  jdolecek  * are met:
     12  1.10.14.2  jdolecek  * 1. Redistributions of source code must retain the above copyright
     13  1.10.14.2  jdolecek  *    notice, this list of conditions and the following disclaimer.
     14  1.10.14.2  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.10.14.2  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     16  1.10.14.2  jdolecek  *    documentation and/or other materials provided with the distribution.
     17  1.10.14.2  jdolecek  * 3. All advertising materials mentioning features or use of this software
     18  1.10.14.2  jdolecek  *    must display the following acknowledgement:
     19  1.10.14.2  jdolecek  *      This product includes software developed for the NetBSD Project by
     20  1.10.14.2  jdolecek  *      Wasabi Systems, Inc.
     21  1.10.14.2  jdolecek  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  1.10.14.2  jdolecek  *    or promote products derived from this software without specific prior
     23  1.10.14.2  jdolecek  *    written permission.
     24  1.10.14.2  jdolecek  *
     25  1.10.14.2  jdolecek  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  1.10.14.2  jdolecek  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.10.14.2  jdolecek  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.10.14.2  jdolecek  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  1.10.14.2  jdolecek  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.10.14.2  jdolecek  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.10.14.2  jdolecek  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.10.14.2  jdolecek  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.10.14.2  jdolecek  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.10.14.2  jdolecek  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.10.14.2  jdolecek  * POSSIBILITY OF SUCH DAMAGE.
     36  1.10.14.2  jdolecek  */
     37  1.10.14.2  jdolecek 
     38  1.10.14.2  jdolecek /*
     39  1.10.14.2  jdolecek  * Copyright (c) 1992, 1993
     40  1.10.14.2  jdolecek  *	The Regents of the University of California.  All rights reserved.
     41  1.10.14.2  jdolecek  *
     42  1.10.14.2  jdolecek  * This code is derived from software contributed to Berkeley by
     43  1.10.14.2  jdolecek  * the Systems Programming Group of the University of Utah Computer
     44  1.10.14.2  jdolecek  * Science Department, The Mach Operating System project at
     45  1.10.14.2  jdolecek  * Carnegie-Mellon University and Ralph Campbell.
     46  1.10.14.2  jdolecek  *
     47  1.10.14.2  jdolecek  * Redistribution and use in source and binary forms, with or without
     48  1.10.14.2  jdolecek  * modification, are permitted provided that the following conditions
     49  1.10.14.2  jdolecek  * are met:
     50  1.10.14.2  jdolecek  * 1. Redistributions of source code must retain the above copyright
     51  1.10.14.2  jdolecek  *    notice, this list of conditions and the following disclaimer.
     52  1.10.14.2  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     53  1.10.14.2  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     54  1.10.14.2  jdolecek  *    documentation and/or other materials provided with the distribution.
     55  1.10.14.2  jdolecek  * 3. Neither the name of the University nor the names of its contributors
     56  1.10.14.2  jdolecek  *    may be used to endorse or promote products derived from this software
     57  1.10.14.2  jdolecek  *    without specific prior written permission.
     58  1.10.14.2  jdolecek  *
     59  1.10.14.2  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60  1.10.14.2  jdolecek  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61  1.10.14.2  jdolecek  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62  1.10.14.2  jdolecek  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63  1.10.14.2  jdolecek  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64  1.10.14.2  jdolecek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65  1.10.14.2  jdolecek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66  1.10.14.2  jdolecek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67  1.10.14.2  jdolecek  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68  1.10.14.2  jdolecek  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69  1.10.14.2  jdolecek  * SUCH DAMAGE.
     70  1.10.14.2  jdolecek  *
     71  1.10.14.2  jdolecek  *	@(#)machdep.c   8.3 (Berkeley) 1/12/94
     72  1.10.14.2  jdolecek  *	from: Utah Hdr: machdep.c 1.63 91/04/24
     73  1.10.14.2  jdolecek  */
     74  1.10.14.2  jdolecek /*
     75  1.10.14.2  jdolecek  * Copyright (c) 1988 University of Utah.
     76  1.10.14.2  jdolecek  *
     77  1.10.14.2  jdolecek  * This code is derived from software contributed to Berkeley by
     78  1.10.14.2  jdolecek  * the Systems Programming Group of the University of Utah Computer
     79  1.10.14.2  jdolecek  * Science Department, The Mach Operating System project at
     80  1.10.14.2  jdolecek  * Carnegie-Mellon University and Ralph Campbell.
     81  1.10.14.2  jdolecek  *
     82  1.10.14.2  jdolecek  * Redistribution and use in source and binary forms, with or without
     83  1.10.14.2  jdolecek  * modification, are permitted provided that the following conditions
     84  1.10.14.2  jdolecek  * are met:
     85  1.10.14.2  jdolecek  * 1. Redistributions of source code must retain the above copyright
     86  1.10.14.2  jdolecek  *    notice, this list of conditions and the following disclaimer.
     87  1.10.14.2  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     88  1.10.14.2  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     89  1.10.14.2  jdolecek  *    documentation and/or other materials provided with the distribution.
     90  1.10.14.2  jdolecek  * 3. All advertising materials mentioning features or use of this software
     91  1.10.14.2  jdolecek  *    must display the following acknowledgement:
     92  1.10.14.2  jdolecek  *	This product includes software developed by the University of
     93  1.10.14.2  jdolecek  *	California, Berkeley and its contributors.
     94  1.10.14.2  jdolecek  * 4. Neither the name of the University nor the names of its contributors
     95  1.10.14.2  jdolecek  *    may be used to endorse or promote products derived from this software
     96  1.10.14.2  jdolecek  *    without specific prior written permission.
     97  1.10.14.2  jdolecek  *
     98  1.10.14.2  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     99  1.10.14.2  jdolecek  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    100  1.10.14.2  jdolecek  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    101  1.10.14.2  jdolecek  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    102  1.10.14.2  jdolecek  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    103  1.10.14.2  jdolecek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    104  1.10.14.2  jdolecek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    105  1.10.14.2  jdolecek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    106  1.10.14.2  jdolecek  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    107  1.10.14.2  jdolecek  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    108  1.10.14.2  jdolecek  * SUCH DAMAGE.
    109  1.10.14.2  jdolecek  *
    110  1.10.14.2  jdolecek  *	@(#)machdep.c   8.3 (Berkeley) 1/12/94
    111  1.10.14.2  jdolecek  *	from: Utah Hdr: machdep.c 1.63 91/04/24
    112  1.10.14.2  jdolecek  */
    113  1.10.14.2  jdolecek 
    114  1.10.14.2  jdolecek #include "opt_multiprocessor.h"
    115  1.10.14.2  jdolecek #include "opt_cavium.h"
    116  1.10.14.2  jdolecek 
    117  1.10.14.2  jdolecek #include <sys/cdefs.h>
    118  1.10.14.2  jdolecek __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.10.14.2 2017/12/03 11:36:08 jdolecek Exp $");
    119  1.10.14.2  jdolecek 
    120  1.10.14.2  jdolecek #include <sys/param.h>
    121  1.10.14.2  jdolecek #include <sys/systm.h>
    122  1.10.14.2  jdolecek #include <sys/kernel.h>
    123  1.10.14.2  jdolecek #include <sys/buf.h>
    124  1.10.14.2  jdolecek #include <sys/cpu.h>
    125  1.10.14.2  jdolecek #include <sys/reboot.h>
    126  1.10.14.2  jdolecek #include <sys/mount.h>
    127  1.10.14.2  jdolecek #include <sys/kcore.h>
    128  1.10.14.2  jdolecek #include <sys/boot_flag.h>
    129  1.10.14.2  jdolecek #include <sys/termios.h>
    130  1.10.14.2  jdolecek #include <sys/ksyms.h>
    131  1.10.14.2  jdolecek 
    132  1.10.14.2  jdolecek #include <uvm/uvm_extern.h>
    133  1.10.14.2  jdolecek 
    134  1.10.14.2  jdolecek #include <dev/cons.h>
    135  1.10.14.2  jdolecek 
    136  1.10.14.2  jdolecek #include "ksyms.h"
    137  1.10.14.2  jdolecek 
    138  1.10.14.2  jdolecek #if NKSYMS || defined(DDB) || defined(LKM)
    139  1.10.14.2  jdolecek #include <machine/db_machdep.h>
    140  1.10.14.2  jdolecek #include <ddb/db_extern.h>
    141  1.10.14.2  jdolecek #endif
    142  1.10.14.2  jdolecek 
    143  1.10.14.2  jdolecek #include <machine/psl.h>
    144  1.10.14.2  jdolecek #include <machine/locore.h>
    145  1.10.14.2  jdolecek 
    146  1.10.14.2  jdolecek #include <mips/cavium/autoconf.h>
    147  1.10.14.2  jdolecek #include <mips/cavium/octeonvar.h>
    148  1.10.14.2  jdolecek #include <mips/cavium/include/iobusvar.h>
    149  1.10.14.2  jdolecek #include <mips/cavium/include/bootbusvar.h>
    150  1.10.14.2  jdolecek 
    151  1.10.14.2  jdolecek #include <mips/cavium/dev/octeon_uartreg.h>
    152  1.10.14.2  jdolecek #include <mips/cavium/dev/octeon_ciureg.h>
    153  1.10.14.2  jdolecek #include <mips/cavium/dev/octeon_gpioreg.h>
    154  1.10.14.2  jdolecek 
    155  1.10.14.2  jdolecek #include <evbmips/cavium/octeon_uboot.h>
    156  1.10.14.2  jdolecek 
    157  1.10.14.2  jdolecek static void	mach_init_bss(void);
    158  1.10.14.2  jdolecek static void	mach_init_vector(void);
    159  1.10.14.2  jdolecek static void	mach_init_bus_space(void);
    160  1.10.14.2  jdolecek static void	mach_init_console(void);
    161  1.10.14.2  jdolecek static void	mach_init_memory(u_quad_t);
    162  1.10.14.2  jdolecek 
    163  1.10.14.2  jdolecek #include "com.h"
    164  1.10.14.2  jdolecek #if NCOM > 0
    165  1.10.14.2  jdolecek #include <dev/ic/comreg.h>
    166  1.10.14.2  jdolecek #include <dev/ic/comvar.h>
    167  1.10.14.2  jdolecek int	comcnrate = 115200;	/* XXX should be config option */
    168  1.10.14.2  jdolecek #endif /* NCOM > 0 */
    169  1.10.14.2  jdolecek 
    170  1.10.14.2  jdolecek /* Maps for VM objects. */
    171  1.10.14.2  jdolecek struct vm_map *phys_map = NULL;
    172  1.10.14.2  jdolecek 
    173  1.10.14.2  jdolecek int	netboot;
    174  1.10.14.2  jdolecek 
    175  1.10.14.2  jdolecek phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];
    176  1.10.14.2  jdolecek int mem_cluster_cnt;
    177  1.10.14.2  jdolecek 
    178  1.10.14.2  jdolecek void	mach_init(uint64_t, uint64_t, uint64_t, uint64_t);
    179  1.10.14.2  jdolecek 
    180  1.10.14.2  jdolecek struct octeon_config octeon_configuration;
    181  1.10.14.2  jdolecek struct octeon_btinfo octeon_btinfo;
    182  1.10.14.2  jdolecek 
    183  1.10.14.2  jdolecek char octeon_nmi_stack[PAGE_SIZE] __section(".data1") __aligned(PAGE_SIZE);
    184  1.10.14.2  jdolecek 
    185  1.10.14.2  jdolecek /*
    186  1.10.14.2  jdolecek  * Do all the stuff that locore normally does before calling main().
    187  1.10.14.2  jdolecek  */
    188  1.10.14.2  jdolecek void
    189  1.10.14.2  jdolecek mach_init(uint64_t arg0, uint64_t arg1, uint64_t arg2, uint64_t arg3)
    190  1.10.14.2  jdolecek {
    191  1.10.14.2  jdolecek 	uint64_t btinfo_paddr;
    192  1.10.14.2  jdolecek 	u_quad_t memsize;
    193  1.10.14.2  jdolecek 	int corefreq;
    194  1.10.14.2  jdolecek 
    195  1.10.14.2  jdolecek 	mach_init_bss();
    196  1.10.14.2  jdolecek 
    197  1.10.14.2  jdolecek 	KASSERT(MIPS_XKPHYS_P(arg3));
    198  1.10.14.2  jdolecek 	btinfo_paddr = mips3_ld(arg3 + OCTEON_BTINFO_PADDR_OFFSET);
    199  1.10.14.2  jdolecek 
    200  1.10.14.2  jdolecek 	/* Should be in first 256MB segment */
    201  1.10.14.2  jdolecek 	KASSERT(btinfo_paddr < 256 * 1024 * 1024);
    202  1.10.14.2  jdolecek 	memcpy(&octeon_btinfo,
    203  1.10.14.2  jdolecek 	    (struct octeon_btinfo *)MIPS_PHYS_TO_KSEG0(btinfo_paddr),
    204  1.10.14.2  jdolecek 	    sizeof(octeon_btinfo));
    205  1.10.14.2  jdolecek 
    206  1.10.14.2  jdolecek 	corefreq = octeon_btinfo.obt_eclock_hz;
    207  1.10.14.2  jdolecek #ifdef OCTEON_MEMSIZE // avoid uvm issue
    208  1.10.14.2  jdolecek 	memsize = OCTEON_MEMSIZE;
    209  1.10.14.2  jdolecek #else
    210  1.10.14.2  jdolecek 	memsize = octeon_btinfo.obt_dram_size * 1024 * 1024;
    211  1.10.14.2  jdolecek #endif
    212  1.10.14.2  jdolecek 
    213  1.10.14.2  jdolecek 	octeon_cal_timer(corefreq);
    214  1.10.14.2  jdolecek 
    215  1.10.14.2  jdolecek 	switch (MIPS_PRID_IMPL(mips_options.mips_cpu_id)) {
    216  1.10.14.2  jdolecek 	case 0: cpu_setmodel("Cavium Octeon CN38XX/CN36XX"); break;
    217  1.10.14.2  jdolecek 	case 1: cpu_setmodel("Cavium Octeon CN31XX/CN3020"); break;
    218  1.10.14.2  jdolecek 	case 2: cpu_setmodel("Cavium Octeon CN3005/CN3010"); break;
    219  1.10.14.2  jdolecek 	case 3: cpu_setmodel("Cavium Octeon CN58XX"); break;
    220  1.10.14.2  jdolecek 	case 4: cpu_setmodel("Cavium Octeon CN5[4-7]XX"); break;
    221  1.10.14.2  jdolecek 	case 6: cpu_setmodel("Cavium Octeon CN50XX"); break;
    222  1.10.14.2  jdolecek 	case 7: cpu_setmodel("Cavium Octeon CN52XX"); break;
    223  1.10.14.2  jdolecek 	default: cpu_setmodel("Cavium Octeon"); break;
    224  1.10.14.2  jdolecek 	}
    225  1.10.14.2  jdolecek 
    226  1.10.14.2  jdolecek 	mach_init_vector();
    227  1.10.14.2  jdolecek 
    228  1.10.14.2  jdolecek 	uvm_md_init();
    229  1.10.14.2  jdolecek 
    230  1.10.14.2  jdolecek 	mach_init_bus_space();
    231  1.10.14.2  jdolecek 
    232  1.10.14.2  jdolecek 	mach_init_console();
    233  1.10.14.2  jdolecek 
    234  1.10.14.2  jdolecek 	mach_init_memory(memsize);
    235  1.10.14.2  jdolecek 
    236  1.10.14.2  jdolecek 	/*
    237  1.10.14.2  jdolecek 	 * Allocate uarea page for lwp0 and set it.
    238  1.10.14.2  jdolecek 	 */
    239  1.10.14.2  jdolecek 	mips_init_lwp0_uarea();
    240  1.10.14.2  jdolecek 
    241  1.10.14.2  jdolecek 	boothowto = RB_AUTOBOOT;
    242  1.10.14.2  jdolecek 	boothowto |= AB_VERBOSE;
    243  1.10.14.2  jdolecek 
    244  1.10.14.2  jdolecek #if 0
    245  1.10.14.2  jdolecek 	curcpu()->ci_nmi_stack = octeon_nmi_stack + sizeof(octeon_nmi_stack) - sizeof(struct kernframe);
    246  1.10.14.2  jdolecek 	*(uint64_t *)MIPS_PHYS_TO_KSEG0(0x800) = (intptr_t)octeon_reset_vector;
    247  1.10.14.2  jdolecek 	const uint64_t wdog_reg = MIPS_PHYS_TO_XKPHYS_UNCACHED(CIU_WDOG0);
    248  1.10.14.2  jdolecek 	uint64_t wdog = mips3_ld(wdog_reg);
    249  1.10.14.2  jdolecek 	wdog &= ~(CIU_WDOGX_MODE|CIU_WDOGX_LEN);
    250  1.10.14.2  jdolecek 	wdog |= __SHIFTIN(3, CIU_WDOGX_MODE);
    251  1.10.14.2  jdolecek 	wdog |= CIU_WDOGX_LEN;		// max period
    252  1.10.14.2  jdolecek 	mips64_sd_a64(wdog_reg, wdog);
    253  1.10.14.2  jdolecek 	printf("Watchdog enabled!\n");
    254  1.10.14.2  jdolecek #endif
    255  1.10.14.2  jdolecek 
    256  1.10.14.2  jdolecek #if defined(DDB)
    257  1.10.14.2  jdolecek 	if (boothowto & RB_KDB)
    258  1.10.14.2  jdolecek 		Debugger();
    259  1.10.14.2  jdolecek #endif
    260  1.10.14.2  jdolecek }
    261  1.10.14.2  jdolecek 
    262  1.10.14.2  jdolecek void
    263  1.10.14.2  jdolecek consinit(void)
    264  1.10.14.2  jdolecek {
    265  1.10.14.2  jdolecek 
    266  1.10.14.2  jdolecek 	/*
    267  1.10.14.2  jdolecek 	 * Everything related to console initialization is done
    268  1.10.14.2  jdolecek 	 * in mach_init().
    269  1.10.14.2  jdolecek 	 */
    270  1.10.14.2  jdolecek }
    271  1.10.14.2  jdolecek 
    272  1.10.14.2  jdolecek void
    273  1.10.14.2  jdolecek mach_init_bss(void)
    274  1.10.14.2  jdolecek {
    275  1.10.14.2  jdolecek 	extern char edata[], end[];
    276  1.10.14.2  jdolecek 
    277  1.10.14.2  jdolecek 	/*
    278  1.10.14.2  jdolecek 	 * Clear the BSS segment.
    279  1.10.14.2  jdolecek 	 */
    280  1.10.14.2  jdolecek 	memset(edata, 0, mips_round_page(end) - (uintptr_t)edata);
    281  1.10.14.2  jdolecek }
    282  1.10.14.2  jdolecek 
    283  1.10.14.2  jdolecek void
    284  1.10.14.2  jdolecek mach_init_vector(void)
    285  1.10.14.2  jdolecek {
    286  1.10.14.2  jdolecek 
    287  1.10.14.2  jdolecek 	/* Make sure exception base at 0 (MIPS_COP_0_EBASE) */
    288  1.10.14.2  jdolecek 	__asm __volatile("mtc0 %0, $15, 1" : : "r"(0x80000000) );
    289  1.10.14.2  jdolecek 
    290  1.10.14.2  jdolecek 	/*
    291  1.10.14.2  jdolecek 	 * Set up the exception vectors and CPU-specific function
    292  1.10.14.2  jdolecek 	 * vectors early on.  We need the wbflush() vector set up
    293  1.10.14.2  jdolecek 	 * before comcnattach() is called (or at least before the
    294  1.10.14.2  jdolecek 	 * first printf() after that is called).
    295  1.10.14.2  jdolecek 	 * Also clears the I+D caches.
    296  1.10.14.2  jdolecek 	 */
    297  1.10.14.2  jdolecek 	mips_vector_init(NULL, true);
    298  1.10.14.2  jdolecek }
    299  1.10.14.2  jdolecek 
    300  1.10.14.2  jdolecek void
    301  1.10.14.2  jdolecek mach_init_bus_space(void)
    302  1.10.14.2  jdolecek {
    303  1.10.14.2  jdolecek 	struct octeon_config *mcp = &octeon_configuration;
    304  1.10.14.2  jdolecek 
    305  1.10.14.2  jdolecek 	octeon_dma_init(mcp);
    306  1.10.14.2  jdolecek 
    307  1.10.14.2  jdolecek 	iobus_bootstrap(mcp);
    308  1.10.14.2  jdolecek 	bootbus_bootstrap(mcp);
    309  1.10.14.2  jdolecek }
    310  1.10.14.2  jdolecek 
    311  1.10.14.2  jdolecek void
    312  1.10.14.2  jdolecek mach_init_console(void)
    313  1.10.14.2  jdolecek {
    314  1.10.14.2  jdolecek #if NCOM > 0
    315  1.10.14.2  jdolecek 	struct octeon_config *mcp = &octeon_configuration;
    316  1.10.14.2  jdolecek 	int status;
    317  1.10.14.2  jdolecek 	extern int octeon_uart_com_cnattach(bus_space_tag_t, int, int);
    318  1.10.14.2  jdolecek 
    319  1.10.14.2  jdolecek 	/*
    320  1.10.14.2  jdolecek 	 * Delay to allow firmware putchars to complete.
    321  1.10.14.2  jdolecek 	 * FIFO depth * character time.
    322  1.10.14.2  jdolecek 	 * character time = (1000000 / (defaultrate / 10))
    323  1.10.14.2  jdolecek 	 */
    324  1.10.14.2  jdolecek 	delay(640000000 / comcnrate);
    325  1.10.14.2  jdolecek 
    326  1.10.14.2  jdolecek 	status = octeon_uart_com_cnattach(
    327  1.10.14.2  jdolecek 		&mcp->mc_iobus_bust,
    328  1.10.14.2  jdolecek 		0,	/* XXX port 0 */
    329  1.10.14.2  jdolecek 		comcnrate);
    330  1.10.14.2  jdolecek 	if (status != 0)
    331  1.10.14.2  jdolecek 		panic("can't initialize console!");	/* XXX print to nowhere! */
    332  1.10.14.2  jdolecek #else
    333  1.10.14.2  jdolecek 	panic("octeon: not configured to use serial console");
    334  1.10.14.2  jdolecek #endif /* NCOM > 0 */
    335  1.10.14.2  jdolecek }
    336  1.10.14.2  jdolecek 
    337  1.10.14.2  jdolecek void
    338  1.10.14.2  jdolecek mach_init_memory(u_quad_t memsize)
    339  1.10.14.2  jdolecek {
    340  1.10.14.2  jdolecek 	extern char kernel_text[];
    341  1.10.14.2  jdolecek 	extern char end[];
    342  1.10.14.2  jdolecek 
    343  1.10.14.2  jdolecek 	physmem = btoc(memsize);
    344  1.10.14.2  jdolecek 
    345  1.10.14.2  jdolecek 	if (memsize <= 256 * 1024 * 1024) {
    346  1.10.14.2  jdolecek 		mem_clusters[0].start = 0;
    347  1.10.14.2  jdolecek 		mem_clusters[0].size = memsize;
    348  1.10.14.2  jdolecek 		mem_cluster_cnt = 1;
    349  1.10.14.2  jdolecek 	} else if (memsize <= 512 * 1024 * 1024) {
    350  1.10.14.2  jdolecek 		mem_clusters[0].start = 0;
    351  1.10.14.2  jdolecek 		mem_clusters[0].size = 256 * 1024 * 1024;
    352  1.10.14.2  jdolecek 		mem_clusters[1].start = 0x410000000ULL;
    353  1.10.14.2  jdolecek 		mem_clusters[1].size = memsize - 256 * 1024 * 1024;
    354  1.10.14.2  jdolecek 		mem_cluster_cnt = 2;
    355  1.10.14.2  jdolecek 	} else {
    356  1.10.14.2  jdolecek 		mem_clusters[0].start = 0;
    357  1.10.14.2  jdolecek 		mem_clusters[0].size = 256 * 1024 * 1024;
    358  1.10.14.2  jdolecek 		mem_clusters[1].start = 0x20000000;
    359  1.10.14.2  jdolecek 		mem_clusters[1].size = memsize - 512 * 1024 * 1024;
    360  1.10.14.2  jdolecek 		mem_clusters[2].start = 0x410000000ULL;
    361  1.10.14.2  jdolecek 		mem_clusters[2].size = 256 * 1024 * 1024;
    362  1.10.14.2  jdolecek 		mem_cluster_cnt = 3;
    363  1.10.14.2  jdolecek 	}
    364  1.10.14.2  jdolecek 
    365  1.10.14.2  jdolecek 
    366  1.10.14.2  jdolecek #ifdef MULTIPROCESSOR
    367  1.10.14.2  jdolecek 	const u_int cores = mipsNN_cp0_ebase_read() & MIPS_EBASE_CPUNUM;
    368  1.10.14.2  jdolecek 	mem_clusters[0].start = cores * 4096;
    369  1.10.14.2  jdolecek #endif
    370  1.10.14.2  jdolecek 
    371  1.10.14.2  jdolecek 	/*
    372  1.10.14.2  jdolecek 	 * Load the rest of the available pages into the VM system.
    373  1.10.14.2  jdolecek 	 */
    374  1.10.14.2  jdolecek 	mips_page_physload(mips_trunc_page(kernel_text), mips_round_page(end),
    375  1.10.14.2  jdolecek 	    mem_clusters, mem_cluster_cnt, NULL, 0);
    376  1.10.14.2  jdolecek 
    377  1.10.14.2  jdolecek 	/*
    378  1.10.14.2  jdolecek 	 * Initialize error message buffer (at end of core).
    379  1.10.14.2  jdolecek 	 */
    380  1.10.14.2  jdolecek 	mips_init_msgbuf();
    381  1.10.14.2  jdolecek 
    382  1.10.14.2  jdolecek 	pmap_bootstrap();
    383  1.10.14.2  jdolecek }
    384  1.10.14.2  jdolecek 
    385  1.10.14.2  jdolecek /*
    386  1.10.14.2  jdolecek  * cpu_startup
    387  1.10.14.2  jdolecek  * cpu_reboot
    388  1.10.14.2  jdolecek  */
    389  1.10.14.2  jdolecek 
    390  1.10.14.2  jdolecek int	waittime = -1;
    391  1.10.14.2  jdolecek 
    392  1.10.14.2  jdolecek /*
    393  1.10.14.2  jdolecek  * Allocate memory for variable-sized tables,
    394  1.10.14.2  jdolecek  */
    395  1.10.14.2  jdolecek void
    396  1.10.14.2  jdolecek cpu_startup(void)
    397  1.10.14.2  jdolecek {
    398  1.10.14.2  jdolecek #ifdef MULTIPROCESSOR
    399  1.10.14.2  jdolecek 	// Create a kcpuset so we can see on which CPUs the kernel was started.
    400  1.10.14.2  jdolecek 	kcpuset_create(&cpus_booted, true);
    401  1.10.14.2  jdolecek #endif
    402  1.10.14.2  jdolecek 
    403  1.10.14.2  jdolecek 	/*
    404  1.10.14.2  jdolecek 	 * Do the common startup items.
    405  1.10.14.2  jdolecek 	 */
    406  1.10.14.2  jdolecek 	cpu_startup_common();
    407  1.10.14.2  jdolecek 
    408  1.10.14.2  jdolecek 	/*
    409  1.10.14.2  jdolecek 	 * Virtual memory is bootstrapped -- notify the bus spaces
    410  1.10.14.2  jdolecek 	 * that memory allocation is now safe.
    411  1.10.14.2  jdolecek 	 */
    412  1.10.14.2  jdolecek 	octeon_configuration.mc_mallocsafe = 1;
    413  1.10.14.2  jdolecek }
    414  1.10.14.2  jdolecek 
    415  1.10.14.2  jdolecek void
    416  1.10.14.2  jdolecek cpu_reboot(int howto, char *bootstr)
    417  1.10.14.2  jdolecek {
    418  1.10.14.2  jdolecek 
    419  1.10.14.2  jdolecek 	/* Take a snapshot before clobbering any registers. */
    420  1.10.14.2  jdolecek 	savectx(curpcb);
    421  1.10.14.2  jdolecek 
    422  1.10.14.2  jdolecek 	if (cold) {
    423  1.10.14.2  jdolecek 		howto |= RB_HALT;
    424  1.10.14.2  jdolecek 		goto haltsys;
    425  1.10.14.2  jdolecek 	}
    426  1.10.14.2  jdolecek 
    427  1.10.14.2  jdolecek 	/* If "always halt" was specified as a boot flag, obey. */
    428  1.10.14.2  jdolecek 	if (boothowto & RB_HALT)
    429  1.10.14.2  jdolecek 		howto |= RB_HALT;
    430  1.10.14.2  jdolecek 
    431  1.10.14.2  jdolecek 	boothowto = howto;
    432  1.10.14.2  jdolecek 	if ((howto & RB_NOSYNC) == 0 && (waittime < 0)) {
    433  1.10.14.2  jdolecek 		waittime = 0;
    434  1.10.14.2  jdolecek 		vfs_shutdown();
    435  1.10.14.2  jdolecek 
    436  1.10.14.2  jdolecek 		/*
    437  1.10.14.2  jdolecek 		 * If we've been adjusting the clock, the todr
    438  1.10.14.2  jdolecek 		 * will be out of synch; adjust it now.
    439  1.10.14.2  jdolecek 		 */
    440  1.10.14.2  jdolecek 		resettodr();
    441  1.10.14.2  jdolecek 	}
    442  1.10.14.2  jdolecek 
    443  1.10.14.2  jdolecek 	splhigh();
    444  1.10.14.2  jdolecek 
    445  1.10.14.2  jdolecek 	if (howto & RB_DUMP)
    446  1.10.14.2  jdolecek 		dumpsys();
    447  1.10.14.2  jdolecek 
    448  1.10.14.2  jdolecek haltsys:
    449  1.10.14.2  jdolecek 	doshutdownhooks();
    450  1.10.14.2  jdolecek 
    451  1.10.14.2  jdolecek 	if (howto & RB_HALT) {
    452  1.10.14.2  jdolecek 		printf("\n");
    453  1.10.14.2  jdolecek 		printf("The operating system has halted.\n");
    454  1.10.14.2  jdolecek 		printf("Please press any key to reboot.\n\n");
    455  1.10.14.2  jdolecek 		cnpollc(1);	/* For proper keyboard command handling */
    456  1.10.14.2  jdolecek 		cngetc();
    457  1.10.14.2  jdolecek 		cnpollc(0);
    458  1.10.14.2  jdolecek 	}
    459  1.10.14.2  jdolecek 
    460  1.10.14.2  jdolecek 	printf("%s\n\n", ((howto & RB_HALT) != 0) ? "halted." : "rebooting...");
    461  1.10.14.2  jdolecek 
    462  1.10.14.2  jdolecek 	/*
    463  1.10.14.2  jdolecek 	 * Need a small delay here, otherwise we see the first few characters of
    464  1.10.14.2  jdolecek 	 * the warning below.
    465  1.10.14.2  jdolecek 	 */
    466  1.10.14.2  jdolecek 	delay(80000);
    467  1.10.14.2  jdolecek 
    468  1.10.14.2  jdolecek 	/* initiate chip soft-reset */
    469  1.10.14.2  jdolecek 	uint64_t fuse = octeon_read_csr(CIU_FUSE);
    470  1.10.14.2  jdolecek 	octeon_write_csr(CIU_SOFT_BIST, fuse);
    471  1.10.14.2  jdolecek 	octeon_read_csr(CIU_SOFT_RST);
    472  1.10.14.2  jdolecek 	octeon_write_csr(CIU_SOFT_RST, fuse);
    473  1.10.14.2  jdolecek 
    474  1.10.14.2  jdolecek 	delay(1000000);
    475  1.10.14.2  jdolecek 
    476  1.10.14.2  jdolecek 	printf("WARNING: reset failed!\nSpinning...");
    477  1.10.14.2  jdolecek 
    478  1.10.14.2  jdolecek 	for (;;)
    479  1.10.14.2  jdolecek 		/* spin forever */ ;	/* XXX */
    480  1.10.14.2  jdolecek }
    481