Home | History | Annotate | Line # | Download | only in cavium
      1  1.25   thorpej /*	$NetBSD: machdep.c,v 1.25 2024/03/05 14:15:30 thorpej 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.5      matt 
    116   1.1    hikaru #include <sys/cdefs.h>
    117  1.25   thorpej __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.25 2024/03/05 14:15:30 thorpej Exp $");
    118   1.1    hikaru 
    119   1.1    hikaru #include <sys/param.h>
    120   1.1    hikaru #include <sys/systm.h>
    121   1.1    hikaru #include <sys/kernel.h>
    122   1.1    hikaru #include <sys/buf.h>
    123   1.2      matt #include <sys/cpu.h>
    124   1.1    hikaru #include <sys/reboot.h>
    125   1.1    hikaru #include <sys/mount.h>
    126   1.1    hikaru #include <sys/kcore.h>
    127   1.1    hikaru #include <sys/boot_flag.h>
    128   1.1    hikaru #include <sys/termios.h>
    129   1.1    hikaru #include <sys/ksyms.h>
    130   1.1    hikaru 
    131   1.1    hikaru #include <uvm/uvm_extern.h>
    132   1.1    hikaru 
    133   1.1    hikaru #include <dev/cons.h>
    134   1.1    hikaru 
    135   1.1    hikaru #include "ksyms.h"
    136   1.1    hikaru 
    137   1.1    hikaru #if NKSYMS || defined(DDB) || defined(LKM)
    138   1.1    hikaru #include <machine/db_machdep.h>
    139   1.1    hikaru #include <ddb/db_extern.h>
    140   1.1    hikaru #endif
    141   1.1    hikaru 
    142   1.1    hikaru #include <machine/psl.h>
    143   1.1    hikaru #include <machine/locore.h>
    144   1.1    hikaru 
    145   1.1    hikaru #include <mips/cavium/autoconf.h>
    146   1.1    hikaru #include <mips/cavium/octeonvar.h>
    147   1.1    hikaru #include <mips/cavium/include/iobusvar.h>
    148   1.1    hikaru #include <mips/cavium/include/bootbusvar.h>
    149   1.1    hikaru 
    150  1.21    simonb #include <mips/cavium/dev/octeon_uartvar.h>
    151   1.1    hikaru #include <mips/cavium/dev/octeon_ciureg.h>
    152   1.1    hikaru #include <mips/cavium/dev/octeon_gpioreg.h>
    153   1.1    hikaru 
    154   1.1    hikaru #include <evbmips/cavium/octeon_uboot.h>
    155   1.1    hikaru 
    156  1.18  jmcneill #include <dev/fdt/fdtvar.h>
    157  1.19    simonb #include <dev/fdt/fdt_private.h>
    158  1.18  jmcneill 
    159   1.1    hikaru static void	mach_init_vector(void);
    160   1.1    hikaru static void	mach_init_bus_space(void);
    161   1.1    hikaru static void	mach_init_console(void);
    162  1.13    simonb static void	mach_init_memory(void);
    163  1.16    simonb static void	parse_boot_args(void);
    164   1.1    hikaru 
    165   1.1    hikaru #include "com.h"
    166   1.1    hikaru #if NCOM > 0
    167   1.1    hikaru #include <dev/ic/comreg.h>
    168   1.1    hikaru #include <dev/ic/comvar.h>
    169   1.1    hikaru int	comcnrate = 115200;	/* XXX should be config option */
    170   1.1    hikaru #endif /* NCOM > 0 */
    171   1.1    hikaru 
    172   1.1    hikaru /* Maps for VM objects. */
    173   1.1    hikaru struct vm_map *phys_map = NULL;
    174   1.1    hikaru 
    175   1.1    hikaru int	netboot;
    176   1.1    hikaru 
    177   1.1    hikaru phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];
    178   1.1    hikaru int mem_cluster_cnt;
    179  1.13    simonb extern char kernel_text[];
    180  1.13    simonb extern char edata[];
    181  1.13    simonb extern char end[];
    182   1.1    hikaru 
    183   1.1    hikaru void	mach_init(uint64_t, uint64_t, uint64_t, uint64_t);
    184   1.1    hikaru 
    185   1.1    hikaru struct octeon_config octeon_configuration;
    186  1.16    simonb struct octeon_btdesc octeon_btdesc;
    187   1.1    hikaru struct octeon_btinfo octeon_btinfo;
    188   1.1    hikaru 
    189  1.24    simonb #ifdef notyet
    190  1.24    simonb static char octeon_nmi_stack[PAGE_SIZE] __section(".data1") __aligned(PAGE_SIZE);
    191  1.24    simonb #endif
    192   1.6      matt 
    193  1.23    simonb /* Currently the OCTEON kernels only support big endian boards */
    194  1.23    simonb CTASSERT(_BYTE_ORDER == _BIG_ENDIAN);
    195  1.23    simonb 
    196   1.1    hikaru /*
    197   1.1    hikaru  * Do all the stuff that locore normally does before calling main().
    198   1.1    hikaru  */
    199   1.1    hikaru void
    200   1.1    hikaru mach_init(uint64_t arg0, uint64_t arg1, uint64_t arg2, uint64_t arg3)
    201   1.1    hikaru {
    202   1.1    hikaru 	uint64_t btinfo_paddr;
    203  1.18  jmcneill 	void *fdt_data;
    204  1.12    simonb 
    205  1.12    simonb 	/* clear the BSS segment */
    206  1.12    simonb 	memset(edata, 0, end - edata);
    207   1.1    hikaru 
    208  1.17    simonb 	cpu_reset_address = octeon_soft_reset;
    209  1.17    simonb 
    210  1.21    simonb #if 1 || defined(OCTEON_EARLY_CONSOLE)	/* XXX - remove "1 ||" when MP works */
    211  1.21    simonb 	/*
    212  1.21    simonb 	 * Set up very conservative timer params so we can use delay(9)
    213  1.21    simonb 	 * early.  It doesn't matter if we delay too long at this stage.
    214  1.21    simonb 	 */
    215  1.21    simonb 	octeon_cal_timer(2000 * 1000 * 1000);
    216  1.21    simonb 	octuart_early_cnattach(comcnrate);
    217  1.21    simonb #endif /* OCTEON_EARLY_CONSOLE */
    218  1.21    simonb 
    219   1.1    hikaru 	KASSERT(MIPS_XKPHYS_P(arg3));
    220   1.6      matt 	btinfo_paddr = mips3_ld(arg3 + OCTEON_BTINFO_PADDR_OFFSET);
    221   1.1    hikaru 
    222  1.16    simonb 	/* XXX KASSERT these addresses? */
    223  1.16    simonb 	memcpy(&octeon_btdesc, (void *)arg3, sizeof(octeon_btdesc));
    224  1.16    simonb 	if ((octeon_btdesc.obt_desc_ver == OCTEON_SUPPORTED_DESCRIPTOR_VERSION) &&
    225  1.16    simonb 	    (octeon_btdesc.obt_desc_size == sizeof(octeon_btdesc))) {
    226  1.16    simonb 		btinfo_paddr = MIPS_PHYS_TO_XKPHYS(CCA_CACHEABLE,
    227  1.16    simonb 		    octeon_btdesc.obt_boot_info_addr);
    228  1.16    simonb 	} else {
    229  1.16    simonb 		panic("unknown boot descriptor size %u",
    230  1.16    simonb 		    octeon_btdesc.obt_desc_size);
    231  1.16    simonb 	}
    232  1.16    simonb 	memcpy(&octeon_btinfo, (void *)btinfo_paddr, sizeof(octeon_btinfo));
    233  1.16    simonb 	parse_boot_args();
    234   1.1    hikaru 
    235  1.14    simonb 	octeon_cal_timer(octeon_btinfo.obt_eclock_hz);
    236   1.1    hikaru 
    237  1.14    simonb 	cpu_setmodel("Cavium Octeon %s",
    238  1.14    simonb 	    octeon_cpu_model(mips_options.mips_cpu_id));
    239   1.7     skrll 
    240  1.18  jmcneill 	if (octeon_btinfo.obt_minor_version >= 3 &&
    241  1.18  jmcneill 	    octeon_btinfo.obt_fdt_addr != 0) {
    242  1.18  jmcneill 		fdt_data = (void *)MIPS_PHYS_TO_XKPHYS(CCA_CACHEABLE,
    243  1.18  jmcneill 		    octeon_btinfo.obt_fdt_addr);
    244  1.18  jmcneill 		fdtbus_init(fdt_data);
    245  1.18  jmcneill 	}
    246  1.18  jmcneill 
    247   1.1    hikaru 	mach_init_vector();
    248   1.1    hikaru 
    249   1.9    cherry 	uvm_md_init();
    250   1.1    hikaru 
    251   1.1    hikaru 	mach_init_bus_space();
    252   1.1    hikaru 
    253   1.1    hikaru 	mach_init_console();
    254   1.1    hikaru 
    255  1.16    simonb #ifdef DEBUG
    256  1.16    simonb 	/* Show a couple of boot desc/info params for positive feedback */
    257  1.21    simonb 	printf(">> boot desc eclock    = %d\n", octeon_btdesc.obt_eclock);
    258  1.21    simonb 	printf(">> boot desc core mask = %#x\n", octeon_btinfo.obt_core_mask);
    259  1.21    simonb 	printf(">> boot info board     = %d\n", octeon_btinfo.obt_board_type);
    260  1.16    simonb #endif /* DEBUG */
    261  1.16    simonb 
    262  1.13    simonb 	mach_init_memory();
    263   1.1    hikaru 
    264   1.1    hikaru 	/*
    265   1.1    hikaru 	 * Allocate uarea page for lwp0 and set it.
    266   1.1    hikaru 	 */
    267   1.1    hikaru 	mips_init_lwp0_uarea();
    268   1.1    hikaru 
    269  1.24    simonb #ifdef notyet
    270   1.6      matt 	curcpu()->ci_nmi_stack = octeon_nmi_stack + sizeof(octeon_nmi_stack) - sizeof(struct kernframe);
    271   1.6      matt 	*(uint64_t *)MIPS_PHYS_TO_KSEG0(0x800) = (intptr_t)octeon_reset_vector;
    272   1.6      matt 	const uint64_t wdog_reg = MIPS_PHYS_TO_XKPHYS_UNCACHED(CIU_WDOG0);
    273   1.6      matt 	uint64_t wdog = mips3_ld(wdog_reg);
    274   1.6      matt 	wdog &= ~(CIU_WDOGX_MODE|CIU_WDOGX_LEN);
    275   1.6      matt 	wdog |= __SHIFTIN(3, CIU_WDOGX_MODE);
    276   1.6      matt 	wdog |= CIU_WDOGX_LEN;		// max period
    277   1.6      matt 	mips64_sd_a64(wdog_reg, wdog);
    278   1.6      matt 	printf("Watchdog enabled!\n");
    279  1.24    simonb #endif /* notyet */
    280   1.6      matt 
    281   1.1    hikaru #if defined(DDB)
    282   1.1    hikaru 	if (boothowto & RB_KDB)
    283   1.1    hikaru 		Debugger();
    284   1.1    hikaru #endif
    285   1.1    hikaru }
    286   1.1    hikaru 
    287   1.1    hikaru void
    288   1.1    hikaru consinit(void)
    289   1.1    hikaru {
    290   1.1    hikaru 
    291   1.1    hikaru 	/*
    292   1.1    hikaru 	 * Everything related to console initialization is done
    293   1.1    hikaru 	 * in mach_init().
    294   1.1    hikaru 	 */
    295   1.1    hikaru }
    296   1.1    hikaru 
    297   1.1    hikaru void
    298   1.1    hikaru mach_init_vector(void)
    299   1.1    hikaru {
    300   1.1    hikaru 
    301   1.1    hikaru 	/* Make sure exception base at 0 (MIPS_COP_0_EBASE) */
    302   1.5      matt 	__asm __volatile("mtc0 %0, $15, 1" : : "r"(0x80000000) );
    303   1.1    hikaru 
    304   1.1    hikaru 	/*
    305   1.1    hikaru 	 * Set up the exception vectors and CPU-specific function
    306   1.1    hikaru 	 * vectors early on.  We need the wbflush() vector set up
    307   1.1    hikaru 	 * before comcnattach() is called (or at least before the
    308   1.1    hikaru 	 * first printf() after that is called).
    309   1.1    hikaru 	 * Also clears the I+D caches.
    310   1.1    hikaru 	 */
    311   1.4      matt 	mips_vector_init(NULL, true);
    312   1.1    hikaru }
    313   1.1    hikaru 
    314   1.1    hikaru void
    315   1.1    hikaru mach_init_bus_space(void)
    316   1.1    hikaru {
    317   1.1    hikaru 	struct octeon_config *mcp = &octeon_configuration;
    318   1.1    hikaru 
    319   1.1    hikaru 	octeon_dma_init(mcp);
    320   1.1    hikaru 
    321   1.1    hikaru 	iobus_bootstrap(mcp);
    322   1.1    hikaru 	bootbus_bootstrap(mcp);
    323   1.1    hikaru }
    324   1.1    hikaru 
    325   1.1    hikaru void
    326   1.1    hikaru mach_init_console(void)
    327   1.1    hikaru {
    328   1.1    hikaru #if NCOM > 0
    329   1.1    hikaru 	struct octeon_config *mcp = &octeon_configuration;
    330   1.1    hikaru 	int status;
    331  1.11    simonb 	extern int octuart_com_cnattach(bus_space_tag_t, int, int);
    332   1.1    hikaru 
    333   1.1    hikaru 	/*
    334   1.1    hikaru 	 * Delay to allow firmware putchars to complete.
    335   1.1    hikaru 	 * FIFO depth * character time.
    336   1.1    hikaru 	 * character time = (1000000 / (defaultrate / 10))
    337   1.1    hikaru 	 */
    338   1.1    hikaru 	delay(640000000 / comcnrate);
    339   1.1    hikaru 
    340  1.11    simonb 	status = octuart_com_cnattach(
    341   1.1    hikaru 		&mcp->mc_iobus_bust,
    342   1.1    hikaru 		0,	/* XXX port 0 */
    343   1.1    hikaru 		comcnrate);
    344   1.1    hikaru 	if (status != 0)
    345   1.1    hikaru 		panic("can't initialize console!");	/* XXX print to nowhere! */
    346   1.1    hikaru #else
    347   1.1    hikaru 	panic("octeon: not configured to use serial console");
    348   1.1    hikaru #endif /* NCOM > 0 */
    349   1.1    hikaru }
    350   1.1    hikaru 
    351  1.13    simonb static void
    352  1.13    simonb mach_init_memory(void)
    353   1.1    hikaru {
    354  1.13    simonb 	struct octeon_bootmem_desc *memdesc;
    355  1.13    simonb 	struct octeon_bootmem_block_header *block;
    356  1.13    simonb 	paddr_t blockaddr;
    357  1.13    simonb 	int i;
    358  1.13    simonb 
    359  1.13    simonb 	mem_cluster_cnt = 0;
    360  1.13    simonb 
    361  1.13    simonb 	if (octeon_btinfo.obt_phy_mem_desc_addr == 0)
    362  1.13    simonb 		panic("bootmem desc is missing");
    363  1.13    simonb 
    364  1.13    simonb 	memdesc = (void *)MIPS_PHYS_TO_XKPHYS(CCA_CACHEABLE,
    365  1.13    simonb                     octeon_btinfo.obt_phy_mem_desc_addr);
    366  1.13    simonb 	printf("u-boot bootmem desc @ 0x%x version %d.%d\n",
    367  1.13    simonb 	    octeon_btinfo.obt_phy_mem_desc_addr,
    368  1.13    simonb 	    memdesc->bmd_major_version, memdesc->bmd_minor_version);
    369  1.13    simonb 	if (memdesc->bmd_major_version > 3)
    370  1.13    simonb 		panic("unhandled bootmem desc version %d.%d",
    371  1.13    simonb 		    memdesc->bmd_major_version, memdesc->bmd_minor_version);
    372  1.13    simonb 
    373  1.13    simonb 	blockaddr = memdesc->bmd_head_addr;
    374  1.13    simonb 	if (blockaddr == 0)
    375  1.13    simonb 		panic("bootmem list is empty");
    376  1.13    simonb 
    377  1.13    simonb 	for (i = 0; i < VM_PHYSSEG_MAX && blockaddr != 0;
    378  1.13    simonb 	    i++, blockaddr = block->bbh_next_block_addr) {
    379  1.13    simonb 		block = (void *)MIPS_PHYS_TO_XKPHYS(CCA_CACHEABLE, blockaddr);
    380  1.13    simonb 
    381  1.13    simonb 		mem_clusters[mem_cluster_cnt].start = blockaddr;
    382  1.13    simonb 		mem_clusters[mem_cluster_cnt].size = block->bbh_size;
    383  1.13    simonb 		mem_cluster_cnt++;
    384   1.1    hikaru 	}
    385   1.1    hikaru 
    386  1.13    simonb 	physmem = btoc(octeon_btinfo.obt_dram_size * 1024 * 1024);
    387   1.7     skrll 
    388   1.3      matt #ifdef MULTIPROCESSOR
    389  1.20    simonb 	const uint64_t fuse = octeon_xkphys_read_8(CIU_FUSE);
    390  1.20    simonb 	const int cores = popcount64(fuse);
    391  1.20    simonb 	mem_clusters[0].start += cores * PAGE_SIZE;
    392  1.20    simonb 	mem_clusters[0].size  -= cores * PAGE_SIZE;
    393   1.3      matt #endif
    394   1.3      matt 
    395   1.1    hikaru 	/*
    396   1.1    hikaru 	 * Load the rest of the available pages into the VM system.
    397   1.1    hikaru 	 */
    398   1.3      matt 	mips_page_physload(mips_trunc_page(kernel_text), mips_round_page(end),
    399   1.1    hikaru 	    mem_clusters, mem_cluster_cnt, NULL, 0);
    400   1.1    hikaru 
    401   1.1    hikaru 	/*
    402   1.1    hikaru 	 * Initialize error message buffer (at end of core).
    403   1.1    hikaru 	 */
    404   1.1    hikaru 	mips_init_msgbuf();
    405   1.1    hikaru 
    406   1.1    hikaru 	pmap_bootstrap();
    407   1.1    hikaru }
    408   1.1    hikaru 
    409  1.16    simonb void
    410  1.16    simonb parse_boot_args(void)
    411  1.16    simonb {
    412  1.16    simonb 	int i;
    413  1.16    simonb 	char *arg, *p;
    414  1.16    simonb 
    415  1.16    simonb 	for (i = 0; i < octeon_btdesc.obt_argc; i++) {
    416  1.16    simonb 		arg = (char *)MIPS_PHYS_TO_KSEG0(octeon_btdesc.obt_argv[i]);
    417  1.16    simonb 		if (*arg == '-') {
    418  1.16    simonb 			for (p = arg + 1; *p; p++) {
    419  1.16    simonb 				switch (*p) {
    420  1.16    simonb 				case '1':
    421  1.16    simonb 					boothowto |= RB_MD1;
    422  1.16    simonb 					break;
    423  1.16    simonb 				case 's':
    424  1.16    simonb 					boothowto |= RB_SINGLE;
    425  1.16    simonb 					break;
    426  1.16    simonb 				case 'd':
    427  1.16    simonb 					boothowto |= RB_KDB;
    428  1.16    simonb 					break;
    429  1.16    simonb 				case 'a':
    430  1.16    simonb 					boothowto |= RB_ASKNAME;
    431  1.16    simonb 					break;
    432  1.16    simonb 				case 'q':
    433  1.16    simonb 					boothowto |= AB_QUIET;
    434  1.16    simonb 					break;
    435  1.16    simonb 				case 'v':
    436  1.16    simonb 					boothowto |= AB_VERBOSE;
    437  1.16    simonb 					break;
    438  1.16    simonb 				case 'x':
    439  1.16    simonb 					boothowto |= AB_DEBUG;
    440  1.16    simonb 					break;
    441  1.16    simonb 				case 'z':
    442  1.16    simonb 					boothowto |= AB_SILENT;
    443  1.16    simonb 					break;
    444  1.16    simonb 				}
    445  1.16    simonb 			}
    446  1.16    simonb 		}
    447  1.16    simonb 		if (strncmp(arg, "root=", 5) == 0)
    448  1.16    simonb 			rootspec = strchr(arg, '=') + 1;
    449  1.16    simonb 	}
    450  1.16    simonb }
    451  1.16    simonb 
    452   1.1    hikaru /*
    453   1.1    hikaru  * cpu_startup
    454   1.1    hikaru  * cpu_reboot
    455   1.1    hikaru  */
    456   1.1    hikaru 
    457   1.1    hikaru int	waittime = -1;
    458   1.1    hikaru 
    459   1.1    hikaru /*
    460   1.1    hikaru  * Allocate memory for variable-sized tables,
    461   1.1    hikaru  */
    462   1.1    hikaru void
    463   1.1    hikaru cpu_startup(void)
    464   1.1    hikaru {
    465   1.5      matt 
    466   1.1    hikaru 	/*
    467   1.1    hikaru 	 * Do the common startup items.
    468   1.1    hikaru 	 */
    469   1.1    hikaru 	cpu_startup_common();
    470   1.1    hikaru 
    471   1.1    hikaru 	/*
    472   1.1    hikaru 	 * Virtual memory is bootstrapped -- notify the bus spaces
    473   1.1    hikaru 	 * that memory allocation is now safe.
    474   1.1    hikaru 	 */
    475   1.1    hikaru 	octeon_configuration.mc_mallocsafe = 1;
    476  1.19    simonb 
    477  1.19    simonb 	fdtbus_intr_init();
    478   1.1    hikaru }
    479   1.1    hikaru 
    480   1.1    hikaru void
    481   1.1    hikaru cpu_reboot(int howto, char *bootstr)
    482   1.1    hikaru {
    483   1.1    hikaru 
    484   1.1    hikaru 	/* Take a snapshot before clobbering any registers. */
    485   1.1    hikaru 	savectx(curpcb);
    486   1.1    hikaru 
    487   1.1    hikaru 	if (cold) {
    488   1.1    hikaru 		howto |= RB_HALT;
    489   1.1    hikaru 		goto haltsys;
    490   1.1    hikaru 	}
    491   1.1    hikaru 
    492   1.1    hikaru 	/* If "always halt" was specified as a boot flag, obey. */
    493   1.1    hikaru 	if (boothowto & RB_HALT)
    494   1.1    hikaru 		howto |= RB_HALT;
    495   1.1    hikaru 
    496   1.1    hikaru 	boothowto = howto;
    497   1.1    hikaru 	if ((howto & RB_NOSYNC) == 0 && (waittime < 0)) {
    498   1.1    hikaru 		waittime = 0;
    499   1.1    hikaru 		vfs_shutdown();
    500   1.1    hikaru 	}
    501   1.1    hikaru 
    502   1.1    hikaru 	splhigh();
    503   1.1    hikaru 
    504   1.1    hikaru 	if (howto & RB_DUMP)
    505   1.1    hikaru 		dumpsys();
    506   1.1    hikaru 
    507   1.1    hikaru haltsys:
    508   1.1    hikaru 	doshutdownhooks();
    509   1.1    hikaru 
    510   1.1    hikaru 	if (howto & RB_HALT) {
    511   1.1    hikaru 		printf("\n");
    512   1.1    hikaru 		printf("The operating system has halted.\n");
    513   1.1    hikaru 		printf("Please press any key to reboot.\n\n");
    514   1.8    martin 		cnpollc(1);	/* For proper keyboard command handling */
    515   1.8    martin 		cngetc();
    516   1.8    martin 		cnpollc(0);
    517   1.1    hikaru 	}
    518   1.1    hikaru 
    519   1.1    hikaru 	printf("%s\n\n", ((howto & RB_HALT) != 0) ? "halted." : "rebooting...");
    520   1.1    hikaru 
    521   1.1    hikaru 	/*
    522   1.1    hikaru 	 * Need a small delay here, otherwise we see the first few characters of
    523   1.1    hikaru 	 * the warning below.
    524   1.1    hikaru 	 */
    525   1.1    hikaru 	delay(80000);
    526   1.1    hikaru 
    527  1.14    simonb 	octeon_soft_reset();
    528   1.1    hikaru 
    529   1.1    hikaru 	delay(1000000);
    530   1.1    hikaru 
    531   1.1    hikaru 	printf("WARNING: reset failed!\nSpinning...");
    532   1.1    hikaru 
    533   1.1    hikaru 	for (;;)
    534   1.1    hikaru 		/* spin forever */ ;	/* XXX */
    535   1.1    hikaru }
    536