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