Home | History | Annotate | Line # | Download | only in rmixl
machdep.c revision 1.1.2.35
      1  1.1.2.35   matt /*	machdep.c,v 1.1.2.34 2011/04/29 08:26:18 matt Exp	*/
      2   1.1.2.1  cliff 
      3   1.1.2.1  cliff /*
      4   1.1.2.1  cliff  * Copyright 2001, 2002 Wasabi Systems, Inc.
      5   1.1.2.1  cliff  * All rights reserved.
      6   1.1.2.1  cliff  *
      7   1.1.2.1  cliff  * Written by Jason R. Thorpe and Simon Burge for Wasabi Systems, Inc.
      8   1.1.2.1  cliff  *
      9   1.1.2.1  cliff  * Redistribution and use in source and binary forms, with or without
     10   1.1.2.1  cliff  * modification, are permitted provided that the following conditions
     11   1.1.2.1  cliff  * are met:
     12   1.1.2.1  cliff  * 1. Redistributions of source code must retain the above copyright
     13   1.1.2.1  cliff  *    notice, this list of conditions and the following disclaimer.
     14   1.1.2.1  cliff  * 2. Redistributions in binary form must reproduce the above copyright
     15   1.1.2.1  cliff  *    notice, this list of conditions and the following disclaimer in the
     16   1.1.2.1  cliff  *    documentation and/or other materials provided with the distribution.
     17   1.1.2.1  cliff  * 3. All advertising materials mentioning features or use of this software
     18   1.1.2.1  cliff  *    must display the following acknowledgement:
     19   1.1.2.1  cliff  *      This product includes software developed for the NetBSD Project by
     20   1.1.2.1  cliff  *      Wasabi Systems, Inc.
     21   1.1.2.1  cliff  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22   1.1.2.1  cliff  *    or promote products derived from this software without specific prior
     23   1.1.2.1  cliff  *    written permission.
     24   1.1.2.1  cliff  *
     25   1.1.2.1  cliff  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26   1.1.2.1  cliff  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27   1.1.2.1  cliff  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28   1.1.2.1  cliff  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29   1.1.2.1  cliff  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30   1.1.2.1  cliff  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31   1.1.2.1  cliff  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32   1.1.2.1  cliff  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33   1.1.2.1  cliff  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34   1.1.2.1  cliff  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35   1.1.2.1  cliff  * POSSIBILITY OF SUCH DAMAGE.
     36   1.1.2.1  cliff  */
     37   1.1.2.1  cliff 
     38   1.1.2.1  cliff /*
     39  1.1.2.34   matt  * Copyright (c) 1988 University of Utah.
     40   1.1.2.1  cliff  * Copyright (c) 1992, 1993
     41   1.1.2.1  cliff  *	The Regents of the University of California.  All rights reserved.
     42   1.1.2.1  cliff  *
     43   1.1.2.1  cliff  * This code is derived from software contributed to Berkeley by
     44   1.1.2.1  cliff  * the Systems Programming Group of the University of Utah Computer
     45   1.1.2.1  cliff  * Science Department, The Mach Operating System project at
     46   1.1.2.1  cliff  * Carnegie-Mellon University and Ralph Campbell.
     47   1.1.2.1  cliff  *
     48   1.1.2.1  cliff  * Redistribution and use in source and binary forms, with or without
     49   1.1.2.1  cliff  * modification, are permitted provided that the following conditions
     50   1.1.2.1  cliff  * are met:
     51   1.1.2.1  cliff  * 1. Redistributions of source code must retain the above copyright
     52   1.1.2.1  cliff  *    notice, this list of conditions and the following disclaimer.
     53   1.1.2.1  cliff  * 2. Redistributions in binary form must reproduce the above copyright
     54   1.1.2.1  cliff  *    notice, this list of conditions and the following disclaimer in the
     55   1.1.2.1  cliff  *    documentation and/or other materials provided with the distribution.
     56   1.1.2.1  cliff  * 3. Neither the name of the University nor the names of its contributors
     57   1.1.2.1  cliff  *    may be used to endorse or promote products derived from this software
     58   1.1.2.1  cliff  *    without specific prior written permission.
     59   1.1.2.1  cliff  *
     60   1.1.2.1  cliff  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     61   1.1.2.1  cliff  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     62   1.1.2.1  cliff  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     63   1.1.2.1  cliff  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     64   1.1.2.1  cliff  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     65   1.1.2.1  cliff  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     66   1.1.2.1  cliff  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     67   1.1.2.1  cliff  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     68   1.1.2.1  cliff  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     69   1.1.2.1  cliff  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     70   1.1.2.1  cliff  * SUCH DAMAGE.
     71   1.1.2.1  cliff  *
     72   1.1.2.1  cliff  *	@(#)machdep.c   8.3 (Berkeley) 1/12/94
     73   1.1.2.1  cliff  *	from: Utah Hdr: machdep.c 1.63 91/04/24
     74   1.1.2.1  cliff  */
     75   1.1.2.1  cliff 
     76   1.1.2.1  cliff #include <sys/cdefs.h>
     77  1.1.2.35   matt __KERNEL_RCSID(0, "machdep.c,v 1.1.2.34 2011/04/29 08:26:18 matt Exp");
     78  1.1.2.25  cliff 
     79  1.1.2.25  cliff #define __INTR_PRIVATE
     80  1.1.2.35   matt #define __MUTEX_PRIVATE
     81   1.1.2.1  cliff 
     82  1.1.2.33  cliff #include "opt_multiprocessor.h"
     83   1.1.2.1  cliff #include "opt_ddb.h"
     84   1.1.2.1  cliff #include "opt_com.h"
     85   1.1.2.1  cliff #include "opt_execfmt.h"
     86   1.1.2.1  cliff #include "opt_memsize.h"
     87  1.1.2.28  cliff #include "rmixl_pcix.h"
     88  1.1.2.28  cliff #include "rmixl_pcie.h"
     89   1.1.2.1  cliff 
     90   1.1.2.1  cliff #include <sys/param.h>
     91   1.1.2.1  cliff #include <sys/systm.h>
     92   1.1.2.1  cliff #include <sys/kernel.h>
     93   1.1.2.1  cliff #include <sys/buf.h>
     94   1.1.2.1  cliff #include <sys/reboot.h>
     95   1.1.2.1  cliff #include <sys/mount.h>
     96   1.1.2.1  cliff #include <sys/kcore.h>
     97   1.1.2.1  cliff #include <sys/boot_flag.h>
     98   1.1.2.1  cliff #include <sys/termios.h>
     99   1.1.2.1  cliff #include <sys/ksyms.h>
    100   1.1.2.1  cliff #include <sys/bus.h>
    101   1.1.2.1  cliff #include <sys/device.h>
    102   1.1.2.6  cliff #include <sys/extent.h>
    103   1.1.2.6  cliff #include <sys/malloc.h>
    104   1.1.2.1  cliff 
    105   1.1.2.1  cliff #include <uvm/uvm_extern.h>
    106   1.1.2.1  cliff 
    107   1.1.2.1  cliff #include <dev/cons.h>
    108   1.1.2.1  cliff 
    109   1.1.2.1  cliff #include "ksyms.h"
    110   1.1.2.1  cliff 
    111   1.1.2.1  cliff #if NKSYMS || defined(DDB) || defined(LKM)
    112  1.1.2.34   matt #include <mips/db_machdep.h>
    113   1.1.2.1  cliff #include <ddb/db_extern.h>
    114   1.1.2.1  cliff #endif
    115   1.1.2.1  cliff 
    116  1.1.2.34   matt #include <mips/cpu.h>
    117  1.1.2.34   matt #include <mips/psl.h>
    118  1.1.2.34   matt #include <mips/cache.h>
    119  1.1.2.34   matt #include <mips/mips_opcode.h>
    120   1.1.2.1  cliff 
    121   1.1.2.1  cliff #include "com.h"
    122   1.1.2.1  cliff #if NCOM == 0
    123   1.1.2.1  cliff #error no serial console
    124   1.1.2.1  cliff #endif
    125   1.1.2.1  cliff 
    126   1.1.2.1  cliff #include <dev/ic/comreg.h>
    127   1.1.2.1  cliff #include <dev/ic/comvar.h>
    128   1.1.2.1  cliff 
    129  1.1.2.25  cliff #include <mips/include/intr.h>
    130  1.1.2.25  cliff 
    131  1.1.2.25  cliff #include <mips/rmi/rmixlreg.h>
    132   1.1.2.1  cliff #include <mips/rmi/rmixlvar.h>
    133  1.1.2.25  cliff #include <mips/rmi/rmixl_intr.h>
    134   1.1.2.1  cliff #include <mips/rmi/rmixl_firmware.h>
    135  1.1.2.25  cliff #include <mips/rmi/rmixl_comvar.h>
    136  1.1.2.26  cliff #include <mips/rmi/rmixl_pcievar.h>
    137  1.1.2.28  cliff #include <mips/rmi/rmixl_pcixvar.h>
    138   1.1.2.1  cliff 
    139   1.1.2.6  cliff #ifdef MACHDEP_DEBUG
    140   1.1.2.6  cliff int machdep_debug=MACHDEP_DEBUG;
    141   1.1.2.6  cliff # define DPRINTF(x)	do { if (machdep_debug) printf x ; } while(0)
    142   1.1.2.6  cliff #else
    143   1.1.2.6  cliff # define DPRINTF(x)
    144   1.1.2.6  cliff #endif
    145   1.1.2.6  cliff 
    146   1.1.2.4  cliff #ifndef CONSFREQ
    147  1.1.2.10  cliff # define CONSFREQ 66000000
    148   1.1.2.4  cliff #endif
    149   1.1.2.1  cliff #ifndef CONSPEED
    150   1.1.2.1  cliff # define CONSPEED 38400
    151   1.1.2.1  cliff #endif
    152   1.1.2.1  cliff #ifndef CONMODE
    153   1.1.2.1  cliff # define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8)
    154   1.1.2.1  cliff #endif
    155   1.1.2.1  cliff #ifndef CONSADDR
    156   1.1.2.1  cliff # define CONSADDR RMIXL_IO_DEV_UART_1
    157   1.1.2.1  cliff #endif
    158   1.1.2.1  cliff 
    159   1.1.2.4  cliff int		comcnfreq  = CONSFREQ;
    160   1.1.2.4  cliff int		comcnspeed = CONSPEED;
    161   1.1.2.4  cliff tcflag_t	comcnmode  = CONMODE;
    162   1.1.2.1  cliff bus_addr_t	comcnaddr  = (bus_addr_t)CONSADDR;
    163   1.1.2.1  cliff 
    164   1.1.2.1  cliff struct rmixl_config rmixl_configuration;
    165   1.1.2.1  cliff 
    166   1.1.2.1  cliff 
    167   1.1.2.1  cliff /*
    168   1.1.2.1  cliff  * array of tested firmware versions
    169   1.1.2.4  cliff  * if you find new ones and they work
    170   1.1.2.1  cliff  * please add them
    171   1.1.2.1  cliff  */
    172  1.1.2.18  cliff typedef struct rmiclfw_psb_id {
    173  1.1.2.18  cliff 	uint64_t		psb_version;
    174  1.1.2.18  cliff 	rmixlfw_psb_type_t	psb_type;
    175  1.1.2.18  cliff } rmiclfw_psb_id_t;
    176  1.1.2.18  cliff static rmiclfw_psb_id_t rmiclfw_psb_id[] = {
    177  1.1.2.18  cliff 	{	0x4958d4fb00000056ULL, PSB_TYPE_RMI  },
    178  1.1.2.18  cliff 	{	0x4aacdb6a00000056ULL, PSB_TYPE_RMI  },
    179  1.1.2.29  cliff 	{	0x4b67d03200000056ULL, PSB_TYPE_RMI  },
    180  1.1.2.30   matt 	{	0x4c17058b00000056ULL, PSB_TYPE_RMI  },
    181  1.1.2.26  cliff 	{	0x49a5a8fa00000056ULL, PSB_TYPE_DELL },
    182  1.1.2.26  cliff 	{	0x4b8ead3100000056ULL, PSB_TYPE_DELL },
    183   1.1.2.1  cliff };
    184   1.1.2.1  cliff #define RMICLFW_PSB_VERSIONS_LEN \
    185  1.1.2.18  cliff 	(sizeof(rmiclfw_psb_id)/sizeof(rmiclfw_psb_id[0]))
    186   1.1.2.1  cliff 
    187   1.1.2.1  cliff /*
    188   1.1.2.6  cliff  * storage for fixed extent used to allocate physical address regions
    189   1.1.2.6  cliff  * because extent(9) start and end values are u_long, they are only
    190   1.1.2.6  cliff  * 32 bits on a 32 bit kernel, which is insuffucuent since XLS physical
    191   1.1.2.6  cliff  * address is 40 bits wide.  So the "physaddr" map stores regions
    192   1.1.2.6  cliff  * in units of megabytes.
    193   1.1.2.6  cliff  */
    194   1.1.2.6  cliff static u_long rmixl_physaddr_storage[
    195   1.1.2.6  cliff 	EXTENT_FIXED_STORAGE_SIZE(32)/sizeof(u_long)
    196   1.1.2.6  cliff ];
    197   1.1.2.6  cliff 
    198   1.1.2.1  cliff /* For sysctl_hw. */
    199   1.1.2.1  cliff extern char cpu_model[];
    200   1.1.2.1  cliff 
    201   1.1.2.1  cliff /* Our exported CPU info; we can have only one. */
    202   1.1.2.1  cliff struct cpu_info cpu_info_store;
    203   1.1.2.1  cliff 
    204   1.1.2.1  cliff /* Maps for VM objects. */
    205   1.1.2.1  cliff struct vm_map *mb_map = NULL;
    206   1.1.2.1  cliff struct vm_map *phys_map = NULL;
    207   1.1.2.1  cliff 
    208   1.1.2.1  cliff int	physmem;		/* Total physical memory */
    209   1.1.2.1  cliff 
    210   1.1.2.1  cliff int	netboot;		/* Are we netbooting? */
    211   1.1.2.1  cliff 
    212   1.1.2.1  cliff 
    213   1.1.2.1  cliff phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];
    214  1.1.2.28  cliff u_quad_t mem_cluster_maxaddr;
    215   1.1.2.6  cliff u_int mem_cluster_cnt;
    216   1.1.2.6  cliff 
    217   1.1.2.1  cliff 
    218   1.1.2.1  cliff void configure(void);
    219   1.1.2.7  cliff void mach_init(int, int32_t *, void *, int64_t);
    220  1.1.2.16  cliff static uint64_t rmixlfw_init(int64_t);
    221  1.1.2.16  cliff static uint64_t mem_clusters_init(rmixlfw_mmap_t *, rmixlfw_mmap_t *);
    222  1.1.2.12  cliff static void __attribute__((__noreturn__)) rmixl_reset(void);
    223   1.1.2.6  cliff static void rmixl_physaddr_init(void);
    224   1.1.2.6  cliff static u_int ram_seg_resv(phys_ram_seg_t *, u_int, u_quad_t, u_quad_t);
    225   1.1.2.6  cliff void rmixlfw_mmap_print(rmixlfw_mmap_t *);
    226   1.1.2.1  cliff 
    227  1.1.2.16  cliff 
    228  1.1.2.14  cliff #ifdef MULTIPROCESSOR
    229  1.1.2.22   matt static bool rmixl_fixup_cop0_oscratch(int32_t, uint32_t [2]);
    230  1.1.2.14  cliff void rmixl_get_wakeup_info(struct rmixl_config *);
    231  1.1.2.14  cliff #ifdef MACHDEP_DEBUG
    232  1.1.2.14  cliff static void rmixl_wakeup_info_print(volatile rmixlfw_cpu_wakeup_info_t *);
    233  1.1.2.25  cliff #endif	/* MACHDEP_DEBUG */
    234  1.1.2.25  cliff #endif	/* MULTIPROCESSOR */
    235  1.1.2.34   matt static void rmixl_fixup_curcpu(void);
    236   1.1.2.1  cliff 
    237   1.1.2.1  cliff /*
    238   1.1.2.1  cliff  * Do all the stuff that locore normally does before calling main().
    239   1.1.2.1  cliff  */
    240   1.1.2.1  cliff void
    241   1.1.2.7  cliff mach_init(int argc, int32_t *argv, void *envp, int64_t infop)
    242   1.1.2.1  cliff {
    243   1.1.2.4  cliff 	struct rmixl_config *rcp = &rmixl_configuration;
    244  1.1.2.11   matt 	void *kernend;
    245  1.1.2.16  cliff 	uint64_t memsize;
    246   1.1.2.1  cliff 	extern char edata[], end[];
    247   1.1.2.1  cliff 
    248  1.1.2.32  cliff 	rmixl_pcr_init_core();
    249   1.1.2.8  cliff 
    250   1.1.2.1  cliff 	/*
    251   1.1.2.1  cliff 	 * Clear the BSS segment.
    252   1.1.2.1  cliff 	 */
    253   1.1.2.1  cliff 	kernend = (void *)mips_round_page(end);
    254   1.1.2.1  cliff 	memset(edata, 0, (char *)kernend - edata);
    255   1.1.2.1  cliff 
    256   1.1.2.1  cliff 	/*
    257   1.1.2.1  cliff 	 * Set up the exception vectors and CPU-specific function
    258   1.1.2.1  cliff 	 * vectors early on.  We need the wbflush() vector set up
    259   1.1.2.1  cliff 	 * before comcnattach() is called (or at least before the
    260   1.1.2.1  cliff 	 * first printf() after that is called).
    261   1.1.2.1  cliff 	 * Also clears the I+D caches.
    262  1.1.2.25  cliff 	 *
    263  1.1.2.25  cliff 	 * specify chip-specific EIRR/EIMR based spl functions
    264   1.1.2.1  cliff 	 */
    265  1.1.2.34   matt #ifdef MULTIPROCESSOR
    266  1.1.2.34   matt 	mips_vector_init(&rmixl_splsw, true);
    267  1.1.2.34   matt #else
    268  1.1.2.34   matt 	mips_vector_init(&rmixl_splsw, false);
    269  1.1.2.34   matt #endif
    270   1.1.2.1  cliff 
    271  1.1.2.15   matt 	/* mips_vector_init initialized mips_options */
    272  1.1.2.15   matt 	strcpy(cpu_model, mips_options.mips_cpu->cpu_name);
    273  1.1.2.14  cliff 
    274  1.1.2.14  cliff 	/* get system info from firmware */
    275   1.1.2.1  cliff 	memsize = rmixlfw_init(infop);
    276   1.1.2.1  cliff 
    277   1.1.2.1  cliff 	/* set the VM page size */
    278   1.1.2.1  cliff 	uvm_setpagesize();
    279   1.1.2.1  cliff 
    280   1.1.2.1  cliff 	physmem = btoc(memsize);
    281   1.1.2.1  cliff 
    282  1.1.2.10  cliff 	rmixl_obio_eb_bus_mem_init(&rcp->rc_obio_eb_memt, rcp);
    283   1.1.2.1  cliff 
    284   1.1.2.1  cliff #if NCOM > 0
    285   1.1.2.9  cliff 	rmixl_com_cnattach(comcnaddr, comcnspeed, comcnfreq,
    286   1.1.2.1  cliff 		COM_TYPE_NORMAL, comcnmode);
    287   1.1.2.1  cliff #endif
    288   1.1.2.1  cliff 
    289   1.1.2.1  cliff 	printf("\nNetBSD/rmixl\n");
    290  1.1.2.16  cliff 	printf("memsize = %#"PRIx64"\n", memsize);
    291  1.1.2.25  cliff #ifdef MEMLIMIT
    292  1.1.2.25  cliff 	printf("memlimit = %#"PRIx64"\n", (uint64_t)MEMLIMIT);
    293  1.1.2.25  cliff #endif
    294   1.1.2.1  cliff 
    295  1.1.2.14  cliff #if defined(MULTIPROCESSOR) && defined(MACHDEP_DEBUG)
    296  1.1.2.14  cliff 	rmixl_wakeup_info_print(rcp->rc_cpu_wakeup_info);
    297  1.1.2.14  cliff 	rmixl_wakeup_info_print(rcp->rc_cpu_wakeup_info + 1);
    298  1.1.2.14  cliff 	printf("cpu_wakeup_info %p, cpu_wakeup_end %p\n",
    299  1.1.2.14  cliff 		rcp->rc_cpu_wakeup_info,
    300  1.1.2.14  cliff 		rcp->rc_cpu_wakeup_end);
    301  1.1.2.18  cliff 	printf("userapp_cpu_map: %#"PRIx64"\n",
    302  1.1.2.18  cliff 		rcp->rc_psb_info.userapp_cpu_map);
    303  1.1.2.17  cliff 	printf("wakeup: %#"PRIx64"\n", rcp->rc_psb_info.wakeup);
    304  1.1.2.17  cliff {
    305  1.1.2.17  cliff 	register_t sp;
    306  1.1.2.17  cliff 	asm volatile ("move	%0, $sp\n" : "=r"(sp));
    307  1.1.2.17  cliff 	printf("sp: %#"PRIx64"\n", sp);
    308  1.1.2.17  cliff }
    309  1.1.2.14  cliff #endif
    310  1.1.2.14  cliff 
    311   1.1.2.6  cliff 	rmixl_physaddr_init();
    312   1.1.2.6  cliff 
    313   1.1.2.1  cliff 	/*
    314   1.1.2.1  cliff 	 * Obtain the cpu frequency
    315   1.1.2.1  cliff 	 * Compute the number of ticks for hz.
    316   1.1.2.1  cliff 	 * Compute the delay divisor.
    317   1.1.2.1  cliff 	 * Double the Hz if this CPU runs at twice the
    318   1.1.2.1  cliff          *  external/cp0-count frequency
    319   1.1.2.1  cliff 	 */
    320  1.1.2.17  cliff 	curcpu()->ci_cpu_freq = rcp->rc_psb_info.cpu_frequency;
    321  1.1.2.15   matt 	curcpu()->ci_cctr_freq = curcpu()->ci_cpu_freq;
    322   1.1.2.1  cliff 	curcpu()->ci_cycles_per_hz = (curcpu()->ci_cpu_freq + hz / 2) / hz;
    323   1.1.2.1  cliff 	curcpu()->ci_divisor_delay =
    324   1.1.2.1  cliff 		((curcpu()->ci_cpu_freq + 500000) / 1000000);
    325  1.1.2.15   matt         if (mips_options.mips_cpu_flags & CPU_MIPS_DOUBLE_COUNT)
    326   1.1.2.1  cliff 		curcpu()->ci_cpu_freq *= 2;
    327   1.1.2.1  cliff 
    328   1.1.2.1  cliff 	/*
    329   1.1.2.1  cliff 	 * Look at arguments passed to us and compute boothowto.
    330   1.1.2.1  cliff 	 * - rmixl firmware gives us a 32 bit argv[i], so adapt
    331   1.1.2.1  cliff 	 *   by forcing sign extension in cast to (char *)
    332   1.1.2.1  cliff 	 */
    333   1.1.2.1  cliff 	boothowto = RB_AUTOBOOT;
    334   1.1.2.1  cliff 	for (int i = 1; i < argc; i++) {
    335   1.1.2.7  cliff 		for (char *cp = (char *)(intptr_t)argv[i]; *cp; cp++) {
    336   1.1.2.1  cliff 			int howto;
    337   1.1.2.1  cliff 			/* Ignore superfluous '-', if there is one */
    338   1.1.2.1  cliff 			if (*cp == '-')
    339   1.1.2.1  cliff 				continue;
    340   1.1.2.1  cliff 
    341   1.1.2.1  cliff 			howto = 0;
    342   1.1.2.1  cliff 			BOOT_FLAG(*cp, howto);
    343   1.1.2.6  cliff 			if (howto != 0)
    344   1.1.2.1  cliff 				boothowto |= howto;
    345   1.1.2.6  cliff #ifdef DIAGNOSTIC
    346   1.1.2.6  cliff 			else
    347   1.1.2.6  cliff 				printf("bootflag '%c' not recognised\n", *cp);
    348   1.1.2.6  cliff #endif
    349   1.1.2.1  cliff 		}
    350   1.1.2.1  cliff 	}
    351   1.1.2.6  cliff #ifdef DIAGNOSTIC
    352   1.1.2.1  cliff 	printf("boothowto %#x\n", boothowto);
    353   1.1.2.6  cliff #endif
    354   1.1.2.1  cliff 
    355   1.1.2.1  cliff 	/*
    356   1.1.2.6  cliff 	 * Reserve pages from the VM system.
    357   1.1.2.6  cliff 	 */
    358   1.1.2.6  cliff 
    359   1.1.2.6  cliff 	/* reserve 0..start..kernend pages */
    360  1.1.2.28  cliff 	mem_cluster_cnt = ram_seg_resv(mem_clusters, mem_cluster_cnt,
    361   1.1.2.6  cliff 		0, round_page(MIPS_KSEG0_TO_PHYS(kernend)));
    362   1.1.2.6  cliff 
    363   1.1.2.6  cliff 	/* reserve reset exception vector page */
    364   1.1.2.9  cliff 	/* should never be in our clusters anyway... */
    365  1.1.2.28  cliff 	mem_cluster_cnt = ram_seg_resv(mem_clusters, mem_cluster_cnt,
    366  1.1.2.12  cliff 		0x1FC00000, 0x1FC00000+NBPG);
    367   1.1.2.6  cliff 
    368  1.1.2.14  cliff #ifdef MULTIPROCEESOR
    369  1.1.2.14  cliff 	/* reserve the cpu_wakeup_info area */
    370  1.1.2.28  cliff 	mem_cluster_cnt = ram_seg_resv(mem_clusters, mem_cluster_cnt,
    371  1.1.2.14  cliff 		(u_quad_t)trunc_page(rcp->rc_cpu_wakeup_info),
    372  1.1.2.14  cliff 		(u_quad_t)round_page(rcp->rc_cpu_wakeup_end));
    373  1.1.2.14  cliff #endif
    374  1.1.2.14  cliff 
    375  1.1.2.18  cliff #ifdef MEMLIMIT
    376  1.1.2.25  cliff 	/* reserve everything >= MEMLIMIT */
    377  1.1.2.28  cliff 	mem_cluster_cnt = ram_seg_resv(mem_clusters, mem_cluster_cnt,
    378  1.1.2.18  cliff 		(u_quad_t)MEMLIMIT, (u_quad_t)~0);
    379  1.1.2.14  cliff #endif
    380  1.1.2.14  cliff 
    381  1.1.2.28  cliff 	/* get maximum RAM address from the VM clusters */
    382  1.1.2.28  cliff 	mem_cluster_maxaddr = 0;
    383  1.1.2.28  cliff 	for (u_int i=0; i < mem_cluster_cnt; i++) {
    384  1.1.2.28  cliff 		u_quad_t tmp = round_page(
    385  1.1.2.28  cliff 			mem_clusters[i].start + mem_clusters[i].size);
    386  1.1.2.28  cliff 		if (tmp > mem_cluster_maxaddr)
    387  1.1.2.28  cliff 			mem_cluster_maxaddr = tmp;
    388  1.1.2.28  cliff 	}
    389  1.1.2.28  cliff 	DPRINTF(("mem_cluster_maxaddr %#"PRIx64"\n", mem_cluster_maxaddr));
    390  1.1.2.28  cliff 
    391   1.1.2.6  cliff 	/*
    392  1.1.2.28  cliff 	 * Load mem_clusters[] into the VM system.
    393   1.1.2.6  cliff 	 */
    394  1.1.2.11   matt 	mips_page_physload(MIPS_KSEG0_START, (vaddr_t) kernend,
    395  1.1.2.28  cliff 	    mem_clusters, mem_cluster_cnt, NULL, 0);
    396   1.1.2.1  cliff 
    397   1.1.2.1  cliff 	/*
    398   1.1.2.1  cliff 	 * Initialize error message buffer (at end of core).
    399   1.1.2.1  cliff 	 */
    400   1.1.2.1  cliff 	mips_init_msgbuf();
    401   1.1.2.1  cliff 
    402   1.1.2.1  cliff 	pmap_bootstrap();
    403   1.1.2.1  cliff 
    404   1.1.2.1  cliff 	/*
    405  1.1.2.34   matt 	 * Allocate uarea page for lwp0 and set it.
    406   1.1.2.1  cliff 	 */
    407  1.1.2.11   matt 	mips_init_lwp0_uarea();
    408   1.1.2.1  cliff 
    409   1.1.2.1  cliff 	/*
    410   1.1.2.1  cliff 	 * Initialize debuggers, and break into them, if appropriate.
    411   1.1.2.1  cliff 	 */
    412   1.1.2.1  cliff #if NKSYMS || defined(DDB) || defined(LKM)
    413   1.1.2.1  cliff 	ksyms_init(0, 0, 0);
    414   1.1.2.1  cliff #endif
    415   1.1.2.1  cliff 
    416   1.1.2.1  cliff #if defined(DDB)
    417   1.1.2.1  cliff 	if (boothowto & RB_KDB)
    418   1.1.2.1  cliff 		Debugger();
    419   1.1.2.1  cliff #endif
    420  1.1.2.20   matt 	/*
    421  1.1.2.25  cliff 	 * store (cpu#0) curcpu in COP0 OSSCRATCH0
    422  1.1.2.25  cliff 	 * used in exception vector
    423  1.1.2.20   matt 	 */
    424  1.1.2.24   matt 	__asm __volatile("dmtc0 %0,$%1"
    425  1.1.2.20   matt 		:: "r"(&cpu_info_store), "n"(MIPS_COP_0_OSSCRATCH));
    426  1.1.2.34   matt #ifdef MULTIPROCESSOR
    427  1.1.2.35   matt 	__asm __volatile("dmtc0 %0,$%1,2"
    428  1.1.2.35   matt 		:: "r"(&pmap_tlb0_info.ti_lock->mtx_lock),
    429  1.1.2.35   matt 		    "n"(MIPS_COP_0_OSSCRATCH));
    430  1.1.2.20   matt 	mips_fixup_exceptions(rmixl_fixup_cop0_oscratch);
    431  1.1.2.20   matt #endif
    432  1.1.2.34   matt 	rmixl_fixup_curcpu();
    433  1.1.2.20   matt }
    434  1.1.2.20   matt 
    435  1.1.2.32  cliff /*
    436  1.1.2.32  cliff  * set up Processor Control Regs for this core
    437  1.1.2.32  cliff  */
    438  1.1.2.32  cliff void
    439  1.1.2.32  cliff rmixl_pcr_init_core()
    440  1.1.2.32  cliff {
    441  1.1.2.32  cliff 	uint32_t r;
    442  1.1.2.32  cliff 
    443  1.1.2.32  cliff #ifdef MULTIPROCESSOR
    444  1.1.2.32  cliff 	rmixl_mtcr(RMIXL_PCR_MMU_SETUP, __BITS(2,0));
    445  1.1.2.32  cliff 						/* enable MMU clock gating */
    446  1.1.2.32  cliff 						/* 4 threads active -- why needed if Global? */
    447  1.1.2.32  cliff 						/* enable global TLB mode */
    448  1.1.2.32  cliff #else
    449  1.1.2.32  cliff 	rmixl_mtcr(RMIXL_PCR_THREADEN, 1);	/* disable all threads except #0 */
    450  1.1.2.32  cliff 	rmixl_mtcr(RMIXL_PCR_MMU_SETUP, 0);	/* enable MMU clock gating */
    451  1.1.2.32  cliff 						/* set single MMU Thread Mode */
    452  1.1.2.32  cliff 						/* TLB is partitioned (1 partition) */
    453  1.1.2.32  cliff #endif
    454  1.1.2.32  cliff 
    455  1.1.2.32  cliff 	r = rmixl_mfcr(RMIXL_PCR_L1D_CONFIG0);
    456  1.1.2.32  cliff 	r &= ~__BIT(14);			/* disable Unaligned Access */
    457  1.1.2.32  cliff 	rmixl_mtcr(RMIXL_PCR_L1D_CONFIG0, r);
    458  1.1.2.33  cliff 
    459  1.1.2.33  cliff #if defined(DDB) && defined(MIPS_DDB_WATCH)
    460  1.1.2.33  cliff 	/*
    461  1.1.2.33  cliff 	 * clear IEU_DEFEATURE[DBE]
    462  1.1.2.33  cliff 	 * this enables COP0 watchpoint to trigger T_WATCH exception
    463  1.1.2.33  cliff 	 * instead of signaling JTAG.
    464  1.1.2.33  cliff 	 */
    465  1.1.2.33  cliff 	r = rmixl_mfcr(RMIXL_PCR_IEU_DEFEATURE);
    466  1.1.2.33  cliff 	r &= ~__BIT(7);
    467  1.1.2.33  cliff 	rmixl_mtcr(RMIXL_PCR_IEU_DEFEATURE, r);
    468  1.1.2.33  cliff #endif
    469  1.1.2.32  cliff }
    470  1.1.2.32  cliff 
    471  1.1.2.20   matt #ifdef MULTIPROCESSOR
    472  1.1.2.20   matt static bool
    473  1.1.2.20   matt rmixl_fixup_cop0_oscratch(int32_t load_addr, uint32_t new_insns[2])
    474  1.1.2.20   matt {
    475  1.1.2.20   matt 	size_t offset = load_addr - (intptr_t)&cpu_info_store;
    476  1.1.2.20   matt 
    477  1.1.2.20   matt 	KASSERT(MIPS_KSEG0_P(load_addr));
    478  1.1.2.20   matt 	KASSERT(offset < sizeof(struct cpu_info));
    479  1.1.2.20   matt 
    480  1.1.2.20   matt 	/*
    481  1.1.2.21    snj 	 * Fixup this direct load cpu_info_store to actually get the current
    482  1.1.2.20   matt 	 * CPU's cpu_info from COP0 OSSCRATCH0 and then fix the load to be
    483  1.1.2.20   matt 	 * relative from the start of struct cpu_info.
    484  1.1.2.20   matt 	 */
    485  1.1.2.20   matt 
    486  1.1.2.23   matt 	/* [0] = [d]mfc0 rX, $22 (OSScratch) */
    487  1.1.2.20   matt 	new_insns[0] = (020 << 26)
    488  1.1.2.23   matt #ifdef _LP64
    489  1.1.2.23   matt 	    | (1 << 21)		/* double move */
    490  1.1.2.23   matt #endif
    491  1.1.2.20   matt 	    | (new_insns[0] & 0x001f0000)
    492  1.1.2.20   matt 	    | (MIPS_COP_0_OSSCRATCH << 11) | (0 << 0);
    493  1.1.2.20   matt 
    494  1.1.2.34   matt 	/* [1] = [ls][dw] rX, offset(rX) */
    495  1.1.2.20   matt 	new_insns[1] = (new_insns[1] & 0xffff0000) | offset;
    496  1.1.2.20   matt 
    497  1.1.2.20   matt 	return true;
    498   1.1.2.6  cliff }
    499  1.1.2.20   matt #endif /* MULTIPROCESSOR */
    500   1.1.2.6  cliff 
    501   1.1.2.6  cliff /*
    502  1.1.2.34   matt  * The following changes all	lX	rN, L_CPU(MIPS_CURLWP) [curlwp->l_cpu]
    503  1.1.2.34   matt  * to			     	[d]mfc0	rN, $22 [MIPS_COP_0_OSSCRATCH]
    504  1.1.2.34   matt  *
    505  1.1.2.34   matt  * the mfc0 is 3 cycles shorter than the load.
    506  1.1.2.34   matt  */
    507  1.1.2.34   matt #define	LOAD_CURCPU_0	((MIPS_CURLWP_REG << 21) | offsetof(lwp_t, l_cpu))
    508  1.1.2.34   matt #define	MFC0_CURCPU_0	((OP_COP0 << 26) | (MIPS_COP_0_OSSCRATCH << 11))
    509  1.1.2.34   matt #ifdef _LP64
    510  1.1.2.34   matt #define	LOAD_CURCPU	((uint32_t)(OP_LD << 26) | LOAD_CURCPU_0)
    511  1.1.2.34   matt #define	MFC0_CURCPU	((uint32_t)(OP_DMF << 21) | MFC0_CURCPU_0)
    512  1.1.2.34   matt #else
    513  1.1.2.34   matt #define	LOAD_CURCPU	((uint32_t)(OP_LW << 26) | LOAD_CURCPU_0)
    514  1.1.2.34   matt #define	MFC0_CURCPU	((uint32_t)(OP_MF << 21) | MFC0_CURCPU_0)
    515  1.1.2.34   matt #endif
    516  1.1.2.34   matt #define	LOAD_CURCPU_MASK	0xffe0ffff
    517  1.1.2.34   matt 
    518  1.1.2.34   matt static void
    519  1.1.2.34   matt rmixl_fixup_curcpu(void)
    520  1.1.2.34   matt {
    521  1.1.2.34   matt 	extern uint32_t _ftext[];
    522  1.1.2.34   matt 	extern uint32_t _etext[];
    523  1.1.2.34   matt 
    524  1.1.2.34   matt 	for (uint32_t *insnp = _ftext; insnp < _etext; insnp++) {
    525  1.1.2.34   matt 		const uint32_t insn = *insnp;
    526  1.1.2.34   matt 		if (__predict_false((insn & LOAD_CURCPU_MASK) == LOAD_CURCPU)) {
    527  1.1.2.34   matt 			/*
    528  1.1.2.34   matt 			 * Since the register to loaded is located in bits
    529  1.1.2.34   matt 			 * 16-20 for the mfc0 and the load instruction we can
    530  1.1.2.34   matt 			 * just change the instruction bits around it.
    531  1.1.2.34   matt 			 */
    532  1.1.2.34   matt 			*insnp = insn ^ LOAD_CURCPU ^ MFC0_CURCPU;
    533  1.1.2.34   matt 			mips_icache_sync_range((vaddr_t)insnp, 4);
    534  1.1.2.34   matt 		}
    535  1.1.2.34   matt 	}
    536  1.1.2.34   matt }
    537  1.1.2.34   matt 
    538  1.1.2.34   matt /*
    539   1.1.2.6  cliff  * ram_seg_resv - cut reserved regions out of segs, fragmenting as needed
    540   1.1.2.6  cliff  *
    541   1.1.2.6  cliff  * we simply build a new table of segs, then copy it back over the given one
    542   1.1.2.6  cliff  * this is inefficient but simple and called only a few times
    543   1.1.2.6  cliff  *
    544   1.1.2.6  cliff  * note: 'last' here means 1st addr past the end of the segment (start+size)
    545   1.1.2.6  cliff  */
    546   1.1.2.6  cliff static u_int
    547   1.1.2.6  cliff ram_seg_resv(phys_ram_seg_t *segs, u_int nsegs,
    548   1.1.2.6  cliff 	u_quad_t resv_first, u_quad_t resv_last)
    549   1.1.2.6  cliff {
    550   1.1.2.6  cliff         u_quad_t first, last;
    551   1.1.2.6  cliff 	int new_nsegs=0;
    552   1.1.2.6  cliff 	int resv_flag;
    553   1.1.2.6  cliff 	phys_ram_seg_t new_segs[VM_PHYSSEG_MAX];
    554   1.1.2.6  cliff 
    555   1.1.2.6  cliff 	for (u_int i=0; i < nsegs; i++) {
    556   1.1.2.6  cliff 		resv_flag = 0;
    557   1.1.2.6  cliff 		first = trunc_page(segs[i].start);
    558   1.1.2.6  cliff 		last = round_page(segs[i].start + segs[i].size);
    559   1.1.2.6  cliff 
    560   1.1.2.6  cliff 		KASSERT(new_nsegs < VM_PHYSSEG_MAX);
    561   1.1.2.6  cliff 		if ((resv_first <= first) && (resv_last >= last)) {
    562   1.1.2.6  cliff 			/* whole segment is resverved */
    563   1.1.2.6  cliff 			continue;
    564   1.1.2.6  cliff 		}
    565   1.1.2.6  cliff 		if ((resv_first > first) && (resv_first < last)) {
    566   1.1.2.6  cliff 			u_quad_t new_last;
    567   1.1.2.6  cliff 
    568   1.1.2.6  cliff 			/*
    569   1.1.2.6  cliff 			 * reserved start in segment
    570   1.1.2.6  cliff 			 * salvage the leading fragment
    571   1.1.2.6  cliff 			 */
    572   1.1.2.6  cliff 			resv_flag = 1;
    573   1.1.2.6  cliff 			new_last = last - (last - resv_first);
    574   1.1.2.6  cliff 			KASSERT (new_last > first);
    575   1.1.2.6  cliff 			new_segs[new_nsegs].start = first;
    576   1.1.2.6  cliff 			new_segs[new_nsegs].size = new_last - first;
    577   1.1.2.6  cliff 			new_nsegs++;
    578   1.1.2.6  cliff 		}
    579   1.1.2.6  cliff 		if ((resv_last > first) && (resv_last < last)) {
    580   1.1.2.6  cliff 			u_quad_t new_first;
    581   1.1.2.6  cliff 
    582   1.1.2.6  cliff 			/*
    583   1.1.2.6  cliff 			 * reserved end in segment
    584   1.1.2.6  cliff 			 * salvage the trailing fragment
    585   1.1.2.6  cliff 			 */
    586   1.1.2.6  cliff 			resv_flag = 1;
    587   1.1.2.6  cliff 			new_first = first + (resv_last - first);
    588   1.1.2.6  cliff 			KASSERT (last > (new_first + NBPG));
    589   1.1.2.6  cliff 			new_segs[new_nsegs].start = new_first;
    590   1.1.2.6  cliff 			new_segs[new_nsegs].size = last - new_first;
    591   1.1.2.6  cliff 			new_nsegs++;
    592   1.1.2.6  cliff 		}
    593   1.1.2.6  cliff 		if (resv_flag == 0) {
    594   1.1.2.6  cliff 			/*
    595   1.1.2.6  cliff 			 * nothing reserved here, take it all
    596   1.1.2.6  cliff 			 */
    597   1.1.2.6  cliff 			new_segs[new_nsegs].start = first;
    598   1.1.2.6  cliff 			new_segs[new_nsegs].size = last - first;
    599   1.1.2.6  cliff 			new_nsegs++;
    600   1.1.2.6  cliff 		}
    601   1.1.2.6  cliff 
    602   1.1.2.6  cliff 	}
    603   1.1.2.6  cliff 
    604   1.1.2.6  cliff 	memcpy(segs, new_segs, sizeof(new_segs));
    605   1.1.2.6  cliff 
    606   1.1.2.6  cliff 	return new_nsegs;
    607   1.1.2.6  cliff }
    608   1.1.2.6  cliff 
    609   1.1.2.6  cliff /*
    610   1.1.2.6  cliff  * create an extent for physical address space
    611   1.1.2.6  cliff  * these are in units of MB for sake of compression (for sake of 32 bit kernels)
    612   1.1.2.6  cliff  * allocate the regions where we have known functions (DRAM, IO, etc)
    613   1.1.2.6  cliff  * what remains can be allocated as needed for other stuff
    614   1.1.2.6  cliff  * e.g. to configure BARs that are not already initialized and enabled.
    615   1.1.2.6  cliff  */
    616   1.1.2.6  cliff static void
    617   1.1.2.6  cliff rmixl_physaddr_init(void)
    618   1.1.2.6  cliff {
    619   1.1.2.6  cliff 	struct extent *ext;
    620   1.1.2.6  cliff 	unsigned long start = 0UL;
    621   1.1.2.6  cliff 	unsigned long end = (__BIT(40) / (1024 * 1024)) -1;
    622   1.1.2.6  cliff 	u_long base;
    623   1.1.2.6  cliff 	u_long size;
    624   1.1.2.6  cliff 	uint32_t r;
    625   1.1.2.6  cliff 
    626   1.1.2.6  cliff 	ext = extent_create("physaddr", start, end, M_DEVBUF,
    627   1.1.2.6  cliff 		(void *)rmixl_physaddr_storage, sizeof(rmixl_physaddr_storage),
    628   1.1.2.6  cliff 		EX_NOWAIT | EX_NOCOALESCE);
    629   1.1.2.6  cliff 
    630   1.1.2.6  cliff 	if (ext == NULL)
    631   1.1.2.6  cliff 		panic("%s: extent_create failed", __func__);
    632   1.1.2.6  cliff 
    633   1.1.2.6  cliff 	/*
    634   1.1.2.6  cliff 	 * grab regions per DRAM BARs
    635   1.1.2.6  cliff 	 */
    636   1.1.2.6  cliff 	for (u_int i=0; i < RMIXL_SBC_DRAM_NBARS; i++) {
    637   1.1.2.6  cliff 		r = RMIXL_IOREG_READ(RMIXL_SBC_DRAM_BAR(i));
    638   1.1.2.6  cliff 		if ((r & RMIXL_DRAM_BAR_STATUS) == 0)
    639   1.1.2.6  cliff 			continue;	/* not enabled */
    640   1.1.2.6  cliff 		base = (u_long)(DRAM_BAR_TO_BASE((uint64_t)r) / (1024 * 1024));
    641   1.1.2.6  cliff 		size = (u_long)(DRAM_BAR_TO_SIZE((uint64_t)r) / (1024 * 1024));
    642   1.1.2.6  cliff 
    643   1.1.2.6  cliff 		DPRINTF(("%s: %d: %d: 0x%08x -- 0x%010lx:%lu MB\n",
    644   1.1.2.6  cliff 			__func__, __LINE__, i, r, base * (1024 * 1024), size));
    645   1.1.2.6  cliff 		if (extent_alloc_region(ext, base, size, EX_NOWAIT) != 0)
    646   1.1.2.6  cliff 			panic("%s: extent_alloc_region(%p, %#lx, %#lx, %#x) "
    647   1.1.2.6  cliff 				"failed", __func__, ext, base, size, EX_NOWAIT);
    648   1.1.2.6  cliff 	}
    649   1.1.2.6  cliff 
    650   1.1.2.6  cliff 	/*
    651  1.1.2.26  cliff 	 * get chip-dependent physaddr regions
    652   1.1.2.6  cliff 	 */
    653  1.1.2.26  cliff 	switch(cpu_rmixl_chip_type(mips_options.mips_cpu)) {
    654  1.1.2.26  cliff 	case CIDFL_RMI_TYPE_XLR:
    655  1.1.2.28  cliff #if NRMIXL_PCIX
    656  1.1.2.28  cliff 		rmixl_physaddr_init_pcix(ext);
    657  1.1.2.28  cliff #endif
    658  1.1.2.26  cliff 		break;
    659  1.1.2.26  cliff 	case CIDFL_RMI_TYPE_XLS:
    660  1.1.2.28  cliff #if NRMIXL_PCIE
    661  1.1.2.26  cliff 		rmixl_physaddr_init_pcie(ext);
    662  1.1.2.28  cliff #endif
    663  1.1.2.26  cliff 		break;
    664  1.1.2.26  cliff 	case CIDFL_RMI_TYPE_XLP:
    665  1.1.2.26  cliff 		/* XXX TBD */
    666  1.1.2.26  cliff 		panic("%s: RMI XLP not yet supported", __func__);
    667   1.1.2.6  cliff 	}
    668   1.1.2.6  cliff 
    669   1.1.2.6  cliff 	/*
    670   1.1.2.6  cliff 	 *  at this point all regions left in "physaddr" extent
    671   1.1.2.6  cliff 	 *  are unused holes in the physical adress space
    672   1.1.2.6  cliff 	 *  available for use as needed.
    673   1.1.2.6  cliff 	 */
    674   1.1.2.6  cliff 	rmixl_configuration.rc_phys_ex = ext;
    675   1.1.2.6  cliff #ifdef MACHDEP_DEBUG
    676   1.1.2.6  cliff 	extent_print(ext);
    677   1.1.2.6  cliff #endif
    678   1.1.2.1  cliff }
    679   1.1.2.1  cliff 
    680  1.1.2.16  cliff static uint64_t
    681   1.1.2.7  cliff rmixlfw_init(int64_t infop)
    682   1.1.2.1  cliff {
    683   1.1.2.4  cliff 	struct rmixl_config *rcp = &rmixl_configuration;
    684   1.1.2.1  cliff 
    685  1.1.2.14  cliff #ifdef MULTIPROCESSOR
    686  1.1.2.14  cliff 	rmixl_get_wakeup_info(rcp);
    687  1.1.2.14  cliff #endif
    688   1.1.2.1  cliff 
    689   1.1.2.7  cliff 	infop |= MIPS_KSEG0_START;
    690  1.1.2.17  cliff 	rcp->rc_psb_info = *(rmixlfw_info_t *)(intptr_t)infop;
    691   1.1.2.1  cliff 
    692  1.1.2.18  cliff 	rcp->rc_psb_type = PSB_TYPE_UNKNOWN;
    693   1.1.2.1  cliff 	for (int i=0; i < RMICLFW_PSB_VERSIONS_LEN; i++) {
    694  1.1.2.18  cliff 		if (rmiclfw_psb_id[i].psb_version ==
    695  1.1.2.18  cliff 		    rcp->rc_psb_info.psb_version) {
    696  1.1.2.18  cliff 			rcp->rc_psb_type = rmiclfw_psb_id[i].psb_type;
    697   1.1.2.1  cliff 			goto found;
    698  1.1.2.18  cliff 		}
    699   1.1.2.1  cliff 	}
    700   1.1.2.1  cliff 
    701   1.1.2.7  cliff 	rcp->rc_io_pbase = RMIXL_IO_DEV_PBASE;
    702   1.1.2.4  cliff 	rmixl_putchar_init(rcp->rc_io_pbase);
    703   1.1.2.4  cliff 
    704   1.1.2.6  cliff #ifdef DIAGNOSTIC
    705   1.1.2.1  cliff 	rmixl_puts("\r\nWARNING: untested psb_version: ");
    706  1.1.2.17  cliff 	rmixl_puthex64(rcp->rc_psb_info.psb_version);
    707   1.1.2.1  cliff 	rmixl_puts("\r\n");
    708   1.1.2.6  cliff #endif
    709   1.1.2.9  cliff 
    710  1.1.2.13  cliff #ifdef MEMSIZE
    711   1.1.2.9  cliff 	/* XXX trust and use MEMSIZE */
    712   1.1.2.9  cliff 	mem_clusters[0].start = 0;
    713   1.1.2.9  cliff 	mem_clusters[0].size = MEMSIZE;
    714   1.1.2.9  cliff 	mem_cluster_cnt = 1;
    715   1.1.2.7  cliff 	return MEMSIZE;
    716  1.1.2.13  cliff #else
    717  1.1.2.13  cliff 	rmixl_puts("\r\nERROR: configure MEMSIZE\r\n");
    718  1.1.2.13  cliff 	cpu_reboot(RB_HALT, NULL);
    719  1.1.2.13  cliff 	/* NOTREACHED */
    720  1.1.2.13  cliff #endif
    721   1.1.2.4  cliff 
    722   1.1.2.1  cliff  found:
    723  1.1.2.17  cliff 	rcp->rc_io_pbase = MIPS_KSEG1_TO_PHYS(rcp->rc_psb_info.io_base);
    724   1.1.2.4  cliff 	rmixl_putchar_init(rcp->rc_io_pbase);
    725   1.1.2.6  cliff #ifdef MACHDEP_DEBUG
    726   1.1.2.4  cliff 	rmixl_puts("\r\ninfop: ");
    727   1.1.2.7  cliff 	rmixl_puthex64((uint64_t)(intptr_t)infop);
    728   1.1.2.6  cliff #endif
    729   1.1.2.6  cliff #ifdef DIAGNOSTIC
    730  1.1.2.18  cliff 	rmixl_puts("\r\nrecognized psb_version=");
    731  1.1.2.17  cliff 	rmixl_puthex64(rcp->rc_psb_info.psb_version);
    732  1.1.2.18  cliff 	rmixl_puts(", psb_type=");
    733  1.1.2.18  cliff 	rmixl_puts(rmixlfw_psb_type_name(rcp->rc_psb_type));
    734   1.1.2.4  cliff 	rmixl_puts("\r\n");
    735   1.1.2.6  cliff #endif
    736   1.1.2.1  cliff 
    737   1.1.2.4  cliff 	return mem_clusters_init(
    738  1.1.2.17  cliff 		(rmixlfw_mmap_t *)(intptr_t)rcp->rc_psb_info.psb_physaddr_map,
    739  1.1.2.17  cliff 		(rmixlfw_mmap_t *)(intptr_t)rcp->rc_psb_info.avail_mem_map);
    740   1.1.2.4  cliff }
    741   1.1.2.4  cliff 
    742   1.1.2.6  cliff void
    743   1.1.2.6  cliff rmixlfw_mmap_print(rmixlfw_mmap_t *map)
    744   1.1.2.6  cliff {
    745   1.1.2.6  cliff #ifdef MACHDEP_DEBUG
    746   1.1.2.6  cliff 	for (uint32_t i=0; i < map->nmmaps; i++) {
    747   1.1.2.6  cliff 		rmixl_puthex32(i);
    748   1.1.2.6  cliff 		rmixl_puts(", ");
    749   1.1.2.6  cliff 		rmixl_puthex64(map->entry[i].start);
    750   1.1.2.6  cliff 		rmixl_puts(", ");
    751   1.1.2.6  cliff 		rmixl_puthex64(map->entry[i].size);
    752   1.1.2.6  cliff 		rmixl_puts(", ");
    753   1.1.2.6  cliff 		rmixl_puthex32(map->entry[i].type);
    754   1.1.2.6  cliff 		rmixl_puts("\r\n");
    755   1.1.2.6  cliff 	}
    756   1.1.2.6  cliff #endif
    757   1.1.2.6  cliff }
    758   1.1.2.6  cliff 
    759   1.1.2.6  cliff /*
    760   1.1.2.6  cliff  * mem_clusters_init
    761   1.1.2.6  cliff  *
    762   1.1.2.6  cliff  * initialize mem_clusters[] table based on memory address mapping
    763   1.1.2.6  cliff  * provided by boot firmware.
    764   1.1.2.6  cliff  *
    765   1.1.2.6  cliff  * prefer avail_mem_map if we can, otherwise use psb_physaddr_map.
    766   1.1.2.6  cliff  * these will be limited by MEMSIZE if it is configured.
    767   1.1.2.6  cliff  * if neither are available, just use MEMSIZE.
    768   1.1.2.6  cliff  */
    769  1.1.2.16  cliff static uint64_t
    770   1.1.2.4  cliff mem_clusters_init(
    771   1.1.2.4  cliff 	rmixlfw_mmap_t *psb_physaddr_map,
    772   1.1.2.4  cliff 	rmixlfw_mmap_t *avail_mem_map)
    773   1.1.2.4  cliff {
    774   1.1.2.6  cliff 	rmixlfw_mmap_t *map = NULL;
    775   1.1.2.6  cliff 	const char *mapname;
    776   1.1.2.4  cliff 	uint64_t sz;
    777   1.1.2.4  cliff 	uint64_t sum;
    778   1.1.2.6  cliff 	u_int cnt;
    779   1.1.2.4  cliff #ifdef MEMSIZE
    780  1.1.2.16  cliff 	uint64_t memsize = MEMSIZE;
    781   1.1.2.4  cliff #endif
    782   1.1.2.4  cliff 
    783   1.1.2.6  cliff #ifdef MACHDEP_DEBUG
    784   1.1.2.4  cliff 	rmixl_puts("psb_physaddr_map: ");
    785   1.1.2.7  cliff 	rmixl_puthex64((uint64_t)(intptr_t)psb_physaddr_map);
    786   1.1.2.4  cliff 	rmixl_puts("\r\n");
    787   1.1.2.6  cliff #endif
    788   1.1.2.6  cliff 	if (psb_physaddr_map != NULL) {
    789  1.1.2.17  cliff 		map = psb_physaddr_map;
    790   1.1.2.6  cliff 		mapname = "psb_physaddr_map";
    791   1.1.2.6  cliff 		rmixlfw_mmap_print(map);
    792   1.1.2.6  cliff 	}
    793   1.1.2.6  cliff #ifdef DIAGNOSTIC
    794   1.1.2.6  cliff 	else {
    795   1.1.2.4  cliff 		rmixl_puts("WARNING: no psb_physaddr_map\r\n");
    796   1.1.2.6  cliff 	}
    797   1.1.2.6  cliff #endif
    798   1.1.2.4  cliff 
    799   1.1.2.6  cliff #ifdef MACHDEP_DEBUG
    800   1.1.2.4  cliff 	rmixl_puts("avail_mem_map: ");
    801   1.1.2.7  cliff 	rmixl_puthex64((uint64_t)(intptr_t)avail_mem_map);
    802   1.1.2.4  cliff 	rmixl_puts("\r\n");
    803   1.1.2.6  cliff #endif
    804   1.1.2.6  cliff 	if (avail_mem_map != NULL) {
    805  1.1.2.17  cliff 		map = avail_mem_map;
    806   1.1.2.6  cliff 		mapname = "avail_mem_map";
    807   1.1.2.6  cliff 		rmixlfw_mmap_print(map);
    808   1.1.2.6  cliff 	}
    809   1.1.2.6  cliff #ifdef DIAGNOSTIC
    810   1.1.2.6  cliff 	else {
    811   1.1.2.6  cliff 		rmixl_puts("WARNING: no avail_mem_map\r\n");
    812   1.1.2.6  cliff 	}
    813   1.1.2.6  cliff #endif
    814   1.1.2.6  cliff 
    815   1.1.2.6  cliff 	if (map == NULL) {
    816   1.1.2.4  cliff #ifndef MEMSIZE
    817   1.1.2.6  cliff 		rmixl_puts("panic: no firmware memory map, "
    818   1.1.2.6  cliff 			"must configure MEMSIZE\r\n");
    819   1.1.2.6  cliff 		for(;;);	/* XXX */
    820   1.1.2.4  cliff #else
    821   1.1.2.6  cliff #ifdef DIAGNOSTIC
    822   1.1.2.4  cliff 		rmixl_puts("WARNING: no avail_mem_map, "
    823   1.1.2.4  cliff 			"using MEMSIZE\r\n");
    824   1.1.2.6  cliff #endif
    825   1.1.2.6  cliff 
    826   1.1.2.4  cliff 		mem_clusters[0].start = 0;
    827   1.1.2.4  cliff 		mem_clusters[0].size = MEMSIZE;
    828   1.1.2.4  cliff 		mem_cluster_cnt = 1;
    829   1.1.2.4  cliff 		return MEMSIZE;
    830   1.1.2.6  cliff #endif	/* MEMSIZE */
    831   1.1.2.4  cliff 	}
    832   1.1.2.1  cliff 
    833   1.1.2.6  cliff #ifdef DIAGNOSTIC
    834   1.1.2.6  cliff 	rmixl_puts("using ");
    835   1.1.2.6  cliff 	rmixl_puts(mapname);
    836   1.1.2.6  cliff 	rmixl_puts("\r\n");
    837   1.1.2.6  cliff #endif
    838   1.1.2.6  cliff #ifdef MACHDEP_DEBUG
    839   1.1.2.6  cliff 	rmixl_puts("memory clusters:\r\n");
    840   1.1.2.6  cliff #endif
    841   1.1.2.1  cliff 	sum = 0;
    842   1.1.2.6  cliff 	cnt = 0;
    843   1.1.2.6  cliff 	for (uint32_t i=0; i < map->nmmaps; i++) {
    844   1.1.2.6  cliff 		if (map->entry[i].type != RMIXLFW_MMAP_TYPE_RAM)
    845   1.1.2.1  cliff 			continue;
    846   1.1.2.6  cliff 		mem_clusters[cnt].start = map->entry[i].start;
    847   1.1.2.6  cliff 		sz = map->entry[i].size;
    848   1.1.2.1  cliff 		sum += sz;
    849   1.1.2.6  cliff 		mem_clusters[cnt].size = sz;
    850   1.1.2.6  cliff #ifdef MACHDEP_DEBUG
    851   1.1.2.1  cliff 		rmixl_puthex32(i);
    852   1.1.2.1  cliff 		rmixl_puts(": ");
    853   1.1.2.6  cliff 		rmixl_puthex64(mem_clusters[cnt].start);
    854   1.1.2.6  cliff 		rmixl_puts(", ");
    855   1.1.2.1  cliff 		rmixl_puthex64(sz);
    856   1.1.2.1  cliff 		rmixl_puts(": ");
    857   1.1.2.1  cliff 		rmixl_puthex64(sum);
    858   1.1.2.1  cliff 		rmixl_puts("\r\n");
    859   1.1.2.1  cliff #endif
    860   1.1.2.1  cliff #ifdef MEMSIZE
    861   1.1.2.1  cliff 		/*
    862   1.1.2.1  cliff 		 * configurably limit memsize
    863   1.1.2.1  cliff 		 */
    864   1.1.2.1  cliff 		if (sum == memsize)
    865   1.1.2.1  cliff 			break;
    866   1.1.2.1  cliff 		if (sum > memsize) {
    867  1.1.2.13  cliff 			uint64_t tmp;
    868  1.1.2.13  cliff 
    869   1.1.2.1  cliff 			tmp = sum - memsize;
    870   1.1.2.1  cliff 			sz -= tmp;
    871   1.1.2.1  cliff 			sum -= tmp;
    872   1.1.2.6  cliff 			mem_clusters[cnt].size = sz;
    873  1.1.2.13  cliff 			cnt++;
    874   1.1.2.1  cliff 			break;
    875   1.1.2.1  cliff 		}
    876   1.1.2.1  cliff #endif
    877   1.1.2.6  cliff 		cnt++;
    878   1.1.2.1  cliff 	}
    879   1.1.2.6  cliff 	mem_cluster_cnt = cnt;
    880   1.1.2.1  cliff 	return sum;
    881   1.1.2.1  cliff }
    882   1.1.2.1  cliff 
    883  1.1.2.14  cliff #ifdef MULTIPROCESSOR
    884  1.1.2.14  cliff /*
    885  1.1.2.25  cliff  * RMI firmware passes wakeup info structure in CP0 OS Scratch reg #7
    886  1.1.2.14  cliff  * they do not explicitly give us the size of the wakeup area.
    887  1.1.2.14  cliff  * we "know" that firmware loader sets wip->gp thusly:
    888  1.1.2.14  cliff  *   gp = stack_start[vcpu] = round_page(wakeup_end) + (vcpu * (PAGE_SIZE * 2))
    889  1.1.2.14  cliff  * so
    890  1.1.2.14  cliff  *   round_page(wakeup_end) == gp - (vcpu * (PAGE_SIZE * 2))
    891  1.1.2.14  cliff  * Only the "master" cpu runs this function, so
    892  1.1.2.14  cliff  *   vcpu = wip->master_cpu
    893  1.1.2.14  cliff  */
    894  1.1.2.14  cliff void
    895  1.1.2.14  cliff rmixl_get_wakeup_info(struct rmixl_config *rcp)
    896  1.1.2.14  cliff {
    897  1.1.2.14  cliff 	volatile rmixlfw_cpu_wakeup_info_t *wip;
    898  1.1.2.14  cliff 	int32_t scratch_7;
    899  1.1.2.14  cliff 	intptr_t end;
    900  1.1.2.14  cliff 
    901  1.1.2.14  cliff 	__asm__ volatile(
    902  1.1.2.14  cliff 		".set push"				"\n"
    903  1.1.2.14  cliff 		".set noreorder"			"\n"
    904  1.1.2.14  cliff 		".set mips64"				"\n"
    905  1.1.2.14  cliff 		"dmfc0	%0, $22, 7"			"\n"
    906  1.1.2.14  cliff 		".set pop"				"\n"
    907  1.1.2.14  cliff 			: "=r"(scratch_7));
    908  1.1.2.14  cliff 
    909  1.1.2.14  cliff 	wip = (volatile rmixlfw_cpu_wakeup_info_t *)
    910  1.1.2.14  cliff 			(intptr_t)scratch_7;
    911  1.1.2.14  cliff 	end = wip->entry.gp - (wip->master_cpu & (PAGE_SIZE * 2));;
    912  1.1.2.14  cliff 
    913  1.1.2.14  cliff 	if (wip->valid == 1) {
    914  1.1.2.14  cliff 		rcp->rc_cpu_wakeup_end = (const void *)end;
    915  1.1.2.14  cliff 		rcp->rc_cpu_wakeup_info = wip;
    916  1.1.2.14  cliff 	}
    917  1.1.2.14  cliff };
    918  1.1.2.14  cliff 
    919  1.1.2.14  cliff #ifdef MACHDEP_DEBUG
    920  1.1.2.14  cliff static void
    921  1.1.2.14  cliff rmixl_wakeup_info_print(volatile rmixlfw_cpu_wakeup_info_t *wip)
    922  1.1.2.14  cliff {
    923  1.1.2.14  cliff 	int i;
    924  1.1.2.14  cliff 
    925  1.1.2.16  cliff 	printf("%s: wip %p, size %lu\n", __func__, wip, sizeof(*wip));
    926  1.1.2.14  cliff 
    927  1.1.2.14  cliff 	printf("cpu_status %#x\n",  wip->cpu_status);
    928  1.1.2.14  cliff 	printf("valid: %d\n", wip->valid);
    929  1.1.2.14  cliff 	printf("entry: addr %#x, args %#x, sp %#"PRIx64", gp %#"PRIx64"\n",
    930  1.1.2.14  cliff 		wip->entry.addr,
    931  1.1.2.14  cliff 		wip->entry.args,
    932  1.1.2.14  cliff 		wip->entry.sp,
    933  1.1.2.14  cliff 		wip->entry.gp);
    934  1.1.2.14  cliff 	printf("master_cpu %d\n", wip->master_cpu);
    935  1.1.2.14  cliff 	printf("master_cpu_mask %#x\n", wip->master_cpu_mask);
    936  1.1.2.14  cliff 	printf("buddy_cpu_mask %#x\n", wip->buddy_cpu_mask);
    937  1.1.2.14  cliff 	printf("psb_os_cpu_map %#x\n", wip->psb_os_cpu_map);
    938  1.1.2.14  cliff 	printf("argc %d\n", wip->argc);
    939  1.1.2.14  cliff 	printf("argv:");
    940  1.1.2.14  cliff 	for (i=0; i < wip->argc; i++)
    941  1.1.2.14  cliff 		printf(" %#x", wip->argv[i]);
    942  1.1.2.14  cliff 	printf("\n");
    943  1.1.2.14  cliff 	printf("valid_tlb_entries %d\n", wip->valid_tlb_entries);
    944  1.1.2.14  cliff 	printf("tlb_map:\n");
    945  1.1.2.14  cliff 	for (i=0; i < wip->valid_tlb_entries; i++) {
    946  1.1.2.14  cliff 		volatile const struct lib_cpu_tlb_mapping *m =
    947  1.1.2.14  cliff 			&wip->tlb_map[i];
    948  1.1.2.14  cliff 		printf(" %d", m->page_size);
    949  1.1.2.14  cliff 		printf(", %d", m->asid);
    950  1.1.2.14  cliff 		printf(", %d", m->coherency);
    951  1.1.2.14  cliff 		printf(", %d", m->coherency);
    952  1.1.2.14  cliff 		printf(", %d", m->attr);
    953  1.1.2.14  cliff 		printf(", %#x", m->virt);
    954  1.1.2.14  cliff 		printf(", %#"PRIx64"\n", m->phys);
    955  1.1.2.14  cliff 	}
    956  1.1.2.14  cliff 	printf("elf segs:\n");
    957  1.1.2.14  cliff 	for (i=0; i < MAX_ELF_SEGMENTS; i++) {
    958  1.1.2.14  cliff 		volatile const struct core_segment_info *e =
    959  1.1.2.14  cliff 			&wip->seg_info[i];
    960  1.1.2.14  cliff 		printf(" %#"PRIx64"", e->vaddr);
    961  1.1.2.14  cliff 		printf(", %#"PRIx64"", e->memsz);
    962  1.1.2.14  cliff 		printf(", %#x\n", e->flags);
    963  1.1.2.14  cliff 	}
    964  1.1.2.14  cliff 	printf("envc %d\n", wip->envc);
    965  1.1.2.14  cliff 	for (i=0; i < wip->envc; i++)
    966  1.1.2.14  cliff 		printf(" %#x \"%s\"", wip->envs[i],
    967  1.1.2.14  cliff 			(char *)(intptr_t)(int32_t)(wip->envs[i]));
    968  1.1.2.14  cliff 	printf("\n");
    969  1.1.2.14  cliff 	printf("app_mode %d\n", wip->app_mode);
    970  1.1.2.14  cliff 	printf("printk_lock %#x\n", wip->printk_lock);
    971  1.1.2.14  cliff 	printf("kseg_master %d\n", wip->kseg_master);
    972  1.1.2.14  cliff 	printf("kuseg_reentry_function %#x\n", wip->kuseg_reentry_function);
    973  1.1.2.14  cliff 	printf("kuseg_reentry_args %#x\n", wip->kuseg_reentry_args);
    974  1.1.2.14  cliff 	printf("app_shared_mem_addr %#"PRIx64"\n", wip->app_shared_mem_addr);
    975  1.1.2.14  cliff 	printf("app_shared_mem_size %#"PRIx64"\n", wip->app_shared_mem_size);
    976  1.1.2.14  cliff 	printf("app_shared_mem_orig %#"PRIx64"\n", wip->app_shared_mem_orig);
    977  1.1.2.14  cliff 	printf("loader_lock %#x\n", wip->loader_lock);
    978  1.1.2.14  cliff 	printf("global_wakeup_mask %#x\n", wip->global_wakeup_mask);
    979  1.1.2.14  cliff 	printf("unused_0 %#x\n", wip->unused_0);
    980  1.1.2.14  cliff }
    981  1.1.2.14  cliff #endif	/* MACHDEP_DEBUG */
    982  1.1.2.14  cliff #endif 	/* MULTIPROCESSOR */
    983  1.1.2.14  cliff 
    984   1.1.2.1  cliff void
    985   1.1.2.1  cliff consinit(void)
    986   1.1.2.1  cliff {
    987   1.1.2.1  cliff 
    988   1.1.2.1  cliff 	/*
    989   1.1.2.1  cliff 	 * Everything related to console initialization is done
    990   1.1.2.1  cliff 	 * in mach_init().
    991   1.1.2.1  cliff 	 */
    992   1.1.2.1  cliff }
    993   1.1.2.1  cliff 
    994   1.1.2.1  cliff /*
    995   1.1.2.1  cliff  * Allocate memory for variable-sized tables,
    996   1.1.2.1  cliff  */
    997   1.1.2.1  cliff void
    998   1.1.2.1  cliff cpu_startup()
    999   1.1.2.1  cliff {
   1000   1.1.2.1  cliff 	vaddr_t minaddr, maxaddr;
   1001   1.1.2.1  cliff 	char pbuf[9];
   1002   1.1.2.1  cliff 
   1003   1.1.2.1  cliff 	/*
   1004   1.1.2.1  cliff 	 * Good {morning,afternoon,evening,night}.
   1005   1.1.2.1  cliff 	 */
   1006   1.1.2.1  cliff 	printf("%s%s", copyright, version);
   1007  1.1.2.13  cliff 	format_bytes(pbuf, sizeof(pbuf), ctob((uint64_t)physmem));
   1008   1.1.2.1  cliff 	printf("total memory = %s\n", pbuf);
   1009   1.1.2.1  cliff 
   1010   1.1.2.1  cliff 	/*
   1011   1.1.2.1  cliff 	 * Virtual memory is bootstrapped -- notify the bus spaces
   1012   1.1.2.1  cliff 	 * that memory allocation is now safe.
   1013   1.1.2.1  cliff 	 */
   1014   1.1.2.1  cliff 	rmixl_configuration.rc_mallocsafe = 1;
   1015   1.1.2.1  cliff 
   1016   1.1.2.1  cliff 	minaddr = 0;
   1017   1.1.2.1  cliff 	/*
   1018   1.1.2.1  cliff 	 * Allocate a submap for physio.
   1019   1.1.2.1  cliff 	 */
   1020   1.1.2.1  cliff 	phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
   1021   1.1.2.1  cliff 				    VM_PHYS_SIZE, 0, FALSE, NULL);
   1022   1.1.2.1  cliff 
   1023   1.1.2.1  cliff 	/*
   1024   1.1.2.1  cliff 	 * (No need to allocate an mbuf cluster submap.  Mbuf clusters
   1025   1.1.2.6  cliff 	 * are allocated via the pool allocator, and we use XKSEG to
   1026   1.1.2.1  cliff 	 * map those pages.)
   1027   1.1.2.1  cliff 	 */
   1028   1.1.2.1  cliff 
   1029   1.1.2.1  cliff 	format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
   1030   1.1.2.1  cliff 	printf("avail memory = %s\n", pbuf);
   1031   1.1.2.1  cliff }
   1032   1.1.2.1  cliff 
   1033   1.1.2.1  cliff int	waittime = -1;
   1034   1.1.2.1  cliff 
   1035   1.1.2.1  cliff void
   1036  1.1.2.34   matt cpu_reboot(int howto, char *bootstr)
   1037   1.1.2.1  cliff {
   1038   1.1.2.1  cliff 
   1039   1.1.2.1  cliff 	/* Take a snapshot before clobbering any registers. */
   1040  1.1.2.34   matt 	savectx(lwp_getpcb(curlwp));
   1041   1.1.2.1  cliff 
   1042   1.1.2.1  cliff 	if (cold) {
   1043   1.1.2.1  cliff 		howto |= RB_HALT;
   1044   1.1.2.1  cliff 		goto haltsys;
   1045   1.1.2.1  cliff 	}
   1046   1.1.2.1  cliff 
   1047   1.1.2.1  cliff 	/* If "always halt" was specified as a boot flag, obey. */
   1048   1.1.2.1  cliff 	if (boothowto & RB_HALT)
   1049   1.1.2.1  cliff 		howto |= RB_HALT;
   1050   1.1.2.1  cliff 
   1051   1.1.2.1  cliff 	boothowto = howto;
   1052   1.1.2.1  cliff 	if ((howto & RB_NOSYNC) == 0 && (waittime < 0)) {
   1053   1.1.2.1  cliff 		waittime = 0;
   1054   1.1.2.1  cliff 		vfs_shutdown();
   1055   1.1.2.1  cliff 
   1056   1.1.2.1  cliff 		/*
   1057   1.1.2.1  cliff 		 * If we've been adjusting the clock, the todr
   1058   1.1.2.1  cliff 		 * will be out of synch; adjust it now.
   1059   1.1.2.1  cliff 		 */
   1060   1.1.2.1  cliff 		resettodr();
   1061   1.1.2.1  cliff 	}
   1062   1.1.2.1  cliff 
   1063   1.1.2.1  cliff 	splhigh();
   1064   1.1.2.1  cliff 
   1065   1.1.2.1  cliff 	if (howto & RB_DUMP)
   1066   1.1.2.1  cliff 		dumpsys();
   1067   1.1.2.1  cliff 
   1068   1.1.2.1  cliff haltsys:
   1069   1.1.2.1  cliff 	doshutdownhooks();
   1070   1.1.2.1  cliff 
   1071   1.1.2.1  cliff 	if (howto & RB_HALT) {
   1072   1.1.2.1  cliff 		printf("\n");
   1073   1.1.2.1  cliff 		printf("The operating system has halted.\n");
   1074   1.1.2.1  cliff 		printf("Please press any key to reboot.\n\n");
   1075   1.1.2.1  cliff 		cnpollc(1);	/* For proper keyboard command handling */
   1076   1.1.2.1  cliff 		cngetc();
   1077   1.1.2.1  cliff 		cnpollc(0);
   1078   1.1.2.1  cliff 	}
   1079   1.1.2.1  cliff 
   1080   1.1.2.1  cliff 	printf("rebooting...\n\n");
   1081   1.1.2.1  cliff 
   1082  1.1.2.12  cliff 	rmixl_reset();
   1083   1.1.2.1  cliff }
   1084   1.1.2.1  cliff 
   1085   1.1.2.1  cliff /*
   1086   1.1.2.1  cliff  * goodbye world
   1087   1.1.2.1  cliff  */
   1088   1.1.2.1  cliff void __attribute__((__noreturn__))
   1089  1.1.2.12  cliff rmixl_reset(void)
   1090   1.1.2.1  cliff {
   1091  1.1.2.12  cliff 	uint32_t r;
   1092  1.1.2.12  cliff 
   1093  1.1.2.12  cliff 	r = RMIXL_IOREG_READ(RMIXL_IO_DEV_GPIO + RMIXL_GPIO_RESET);
   1094  1.1.2.12  cliff 	r |= RMIXL_GPIO_RESET_RESET;
   1095  1.1.2.12  cliff 	RMIXL_IOREG_WRITE(RMIXL_IO_DEV_GPIO + RMIXL_GPIO_RESET, r);
   1096  1.1.2.12  cliff 
   1097  1.1.2.12  cliff 	printf("soft reset failed, spinning...\n");
   1098   1.1.2.1  cliff 	for (;;);
   1099   1.1.2.1  cliff }
   1100