Home | History | Annotate | Line # | Download | only in rmixl
machdep.c revision 1.1.2.4
      1  1.1.2.4  cliff /*	$NetBSD: machdep.c,v 1.1.2.4 2009/09/22 07:15:37 cliff 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.1  cliff  * Copyright (c) 1992, 1993
     40  1.1.2.1  cliff  *	The Regents of the University of California.  All rights reserved.
     41  1.1.2.1  cliff  *
     42  1.1.2.1  cliff  * This code is derived from software contributed to Berkeley by
     43  1.1.2.1  cliff  * the Systems Programming Group of the University of Utah Computer
     44  1.1.2.1  cliff  * Science Department, The Mach Operating System project at
     45  1.1.2.1  cliff  * Carnegie-Mellon University and Ralph Campbell.
     46  1.1.2.1  cliff  *
     47  1.1.2.1  cliff  * Redistribution and use in source and binary forms, with or without
     48  1.1.2.1  cliff  * modification, are permitted provided that the following conditions
     49  1.1.2.1  cliff  * are met:
     50  1.1.2.1  cliff  * 1. Redistributions of source code must retain the above copyright
     51  1.1.2.1  cliff  *    notice, this list of conditions and the following disclaimer.
     52  1.1.2.1  cliff  * 2. Redistributions in binary form must reproduce the above copyright
     53  1.1.2.1  cliff  *    notice, this list of conditions and the following disclaimer in the
     54  1.1.2.1  cliff  *    documentation and/or other materials provided with the distribution.
     55  1.1.2.1  cliff  * 3. Neither the name of the University nor the names of its contributors
     56  1.1.2.1  cliff  *    may be used to endorse or promote products derived from this software
     57  1.1.2.1  cliff  *    without specific prior written permission.
     58  1.1.2.1  cliff  *
     59  1.1.2.1  cliff  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60  1.1.2.1  cliff  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61  1.1.2.1  cliff  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62  1.1.2.1  cliff  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63  1.1.2.1  cliff  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64  1.1.2.1  cliff  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65  1.1.2.1  cliff  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66  1.1.2.1  cliff  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67  1.1.2.1  cliff  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68  1.1.2.1  cliff  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69  1.1.2.1  cliff  * SUCH DAMAGE.
     70  1.1.2.1  cliff  *
     71  1.1.2.1  cliff  *	@(#)machdep.c   8.3 (Berkeley) 1/12/94
     72  1.1.2.1  cliff  *	from: Utah Hdr: machdep.c 1.63 91/04/24
     73  1.1.2.1  cliff  */
     74  1.1.2.1  cliff /*
     75  1.1.2.1  cliff  * Copyright (c) 1988 University of Utah.
     76  1.1.2.1  cliff  *
     77  1.1.2.1  cliff  * This code is derived from software contributed to Berkeley by
     78  1.1.2.1  cliff  * the Systems Programming Group of the University of Utah Computer
     79  1.1.2.1  cliff  * Science Department, The Mach Operating System project at
     80  1.1.2.1  cliff  * Carnegie-Mellon University and Ralph Campbell.
     81  1.1.2.1  cliff  *
     82  1.1.2.1  cliff  * Redistribution and use in source and binary forms, with or without
     83  1.1.2.1  cliff  * modification, are permitted provided that the following conditions
     84  1.1.2.1  cliff  * are met:
     85  1.1.2.1  cliff  * 1. Redistributions of source code must retain the above copyright
     86  1.1.2.1  cliff  *    notice, this list of conditions and the following disclaimer.
     87  1.1.2.1  cliff  * 2. Redistributions in binary form must reproduce the above copyright
     88  1.1.2.1  cliff  *    notice, this list of conditions and the following disclaimer in the
     89  1.1.2.1  cliff  *    documentation and/or other materials provided with the distribution.
     90  1.1.2.1  cliff  * 3. All advertising materials mentioning features or use of this software
     91  1.1.2.1  cliff  *    must display the following acknowledgement:
     92  1.1.2.1  cliff  *	This product includes software developed by the University of
     93  1.1.2.1  cliff  *	California, Berkeley and its contributors.
     94  1.1.2.1  cliff  * 4. Neither the name of the University nor the names of its contributors
     95  1.1.2.1  cliff  *    may be used to endorse or promote products derived from this software
     96  1.1.2.1  cliff  *    without specific prior written permission.
     97  1.1.2.1  cliff  *
     98  1.1.2.1  cliff  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     99  1.1.2.1  cliff  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    100  1.1.2.1  cliff  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    101  1.1.2.1  cliff  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    102  1.1.2.1  cliff  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    103  1.1.2.1  cliff  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    104  1.1.2.1  cliff  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    105  1.1.2.1  cliff  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    106  1.1.2.1  cliff  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    107  1.1.2.1  cliff  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    108  1.1.2.1  cliff  * SUCH DAMAGE.
    109  1.1.2.1  cliff  *
    110  1.1.2.1  cliff  *	@(#)machdep.c   8.3 (Berkeley) 1/12/94
    111  1.1.2.1  cliff  *	from: Utah Hdr: machdep.c 1.63 91/04/24
    112  1.1.2.1  cliff  */
    113  1.1.2.1  cliff 
    114  1.1.2.1  cliff #include <sys/cdefs.h>
    115  1.1.2.4  cliff __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.1.2.4 2009/09/22 07:15:37 cliff Exp $");
    116  1.1.2.1  cliff 
    117  1.1.2.1  cliff #include "opt_ddb.h"
    118  1.1.2.1  cliff #include "opt_com.h"
    119  1.1.2.1  cliff #include "opt_execfmt.h"
    120  1.1.2.1  cliff #include "opt_memsize.h"
    121  1.1.2.1  cliff 
    122  1.1.2.1  cliff #include <sys/param.h>
    123  1.1.2.1  cliff #include <sys/systm.h>
    124  1.1.2.1  cliff #include <sys/kernel.h>
    125  1.1.2.1  cliff #include <sys/buf.h>
    126  1.1.2.1  cliff #include <sys/reboot.h>
    127  1.1.2.1  cliff #include <sys/user.h>
    128  1.1.2.1  cliff #include <sys/mount.h>
    129  1.1.2.1  cliff #include <sys/kcore.h>
    130  1.1.2.1  cliff #include <sys/boot_flag.h>
    131  1.1.2.1  cliff #include <sys/termios.h>
    132  1.1.2.1  cliff #include <sys/ksyms.h>
    133  1.1.2.1  cliff #include <sys/bus.h>
    134  1.1.2.1  cliff #include <sys/device.h>
    135  1.1.2.1  cliff 
    136  1.1.2.1  cliff #include <uvm/uvm_extern.h>
    137  1.1.2.1  cliff 
    138  1.1.2.1  cliff #include <dev/cons.h>
    139  1.1.2.1  cliff 
    140  1.1.2.1  cliff #include "ksyms.h"
    141  1.1.2.1  cliff 
    142  1.1.2.1  cliff #if NKSYMS || defined(DDB) || defined(LKM)
    143  1.1.2.1  cliff #include <machine/db_machdep.h>
    144  1.1.2.1  cliff #include <ddb/db_extern.h>
    145  1.1.2.1  cliff #endif
    146  1.1.2.1  cliff 
    147  1.1.2.1  cliff #include <machine/cpu.h>
    148  1.1.2.1  cliff #include <machine/psl.h>
    149  1.1.2.1  cliff 
    150  1.1.2.1  cliff #include "com.h"
    151  1.1.2.1  cliff #if NCOM == 0
    152  1.1.2.1  cliff #error no serial console
    153  1.1.2.1  cliff #endif
    154  1.1.2.1  cliff 
    155  1.1.2.1  cliff #include <dev/ic/comreg.h>
    156  1.1.2.1  cliff #include <dev/ic/comvar.h>
    157  1.1.2.1  cliff 
    158  1.1.2.1  cliff #include <mips/rmi/rmixl_comvar.h>
    159  1.1.2.1  cliff #include <mips/rmi/rmixlvar.h>
    160  1.1.2.1  cliff #include <mips/rmi/rmixl_firmware.h>
    161  1.1.2.1  cliff #include <mips/rmi/rmixlreg.h>
    162  1.1.2.1  cliff 
    163  1.1.2.4  cliff #ifndef CONSFREQ
    164  1.1.2.4  cliff # define CONSFREQ -1		/* inherit from firmware */
    165  1.1.2.4  cliff #endif
    166  1.1.2.1  cliff #ifndef CONSPEED
    167  1.1.2.1  cliff # define CONSPEED 38400
    168  1.1.2.1  cliff #endif
    169  1.1.2.1  cliff #ifndef CONMODE
    170  1.1.2.1  cliff # define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8)
    171  1.1.2.1  cliff #endif
    172  1.1.2.1  cliff #ifndef CONSADDR
    173  1.1.2.1  cliff # define CONSADDR RMIXL_IO_DEV_UART_1
    174  1.1.2.1  cliff #endif
    175  1.1.2.1  cliff 
    176  1.1.2.4  cliff int		comcnfreq  = CONSFREQ;
    177  1.1.2.4  cliff int		comcnspeed = CONSPEED;
    178  1.1.2.4  cliff tcflag_t	comcnmode  = CONMODE;
    179  1.1.2.1  cliff bus_addr_t	comcnaddr  = (bus_addr_t)CONSADDR;
    180  1.1.2.1  cliff 
    181  1.1.2.1  cliff struct rmixl_config rmixl_configuration;
    182  1.1.2.1  cliff 
    183  1.1.2.1  cliff 
    184  1.1.2.1  cliff /*
    185  1.1.2.1  cliff  * array of tested firmware versions
    186  1.1.2.4  cliff  * if you find new ones and they work
    187  1.1.2.1  cliff  * please add them
    188  1.1.2.1  cliff  */
    189  1.1.2.1  cliff static uint64_t rmiclfw_psb_versions[] = {
    190  1.1.2.1  cliff 	0x4958d4fb00000056,
    191  1.1.2.4  cliff 	0x49a5a8fa00000056,
    192  1.1.2.1  cliff };
    193  1.1.2.1  cliff #define RMICLFW_PSB_VERSIONS_LEN \
    194  1.1.2.1  cliff 	(sizeof(rmiclfw_psb_versions)/sizeof(rmiclfw_psb_versions[0]))
    195  1.1.2.1  cliff 
    196  1.1.2.1  cliff /*
    197  1.1.2.1  cliff  * kernel copies of firmware info
    198  1.1.2.1  cliff  */
    199  1.1.2.1  cliff static rmixlfw_info_t rmixlfw_info;
    200  1.1.2.1  cliff static rmixlfw_mmap_t rmixlfw_phys_mmap;
    201  1.1.2.1  cliff static rmixlfw_mmap_t rmixlfw_avail_mmap;
    202  1.1.2.4  cliff #define RMIXLFW_INFOP_LEGAL	0x8c000000
    203  1.1.2.1  cliff 
    204  1.1.2.1  cliff 
    205  1.1.2.1  cliff /* For sysctl_hw. */
    206  1.1.2.1  cliff extern char cpu_model[];
    207  1.1.2.1  cliff 
    208  1.1.2.1  cliff /* Our exported CPU info; we can have only one. */
    209  1.1.2.1  cliff struct cpu_info cpu_info_store;
    210  1.1.2.1  cliff 
    211  1.1.2.1  cliff /* Maps for VM objects. */
    212  1.1.2.1  cliff struct vm_map *mb_map = NULL;
    213  1.1.2.1  cliff struct vm_map *phys_map = NULL;
    214  1.1.2.1  cliff 
    215  1.1.2.1  cliff int	physmem;		/* Total physical memory */
    216  1.1.2.1  cliff 
    217  1.1.2.1  cliff int	netboot;		/* Are we netbooting? */
    218  1.1.2.1  cliff 
    219  1.1.2.1  cliff 
    220  1.1.2.1  cliff phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];
    221  1.1.2.1  cliff int mem_cluster_cnt;
    222  1.1.2.1  cliff 
    223  1.1.2.1  cliff void configure(void);
    224  1.1.2.1  cliff void mach_init(int, int32_t *, void *, void *);
    225  1.1.2.1  cliff static u_long rmixlfw_init(void *);
    226  1.1.2.4  cliff static u_long mem_clusters_init(rmixlfw_mmap_t *, rmixlfw_mmap_t *);
    227  1.1.2.1  cliff static void __attribute__((__noreturn__)) rmixl_exit(int);
    228  1.1.2.1  cliff 
    229  1.1.2.1  cliff 
    230  1.1.2.1  cliff /*
    231  1.1.2.1  cliff  * safepri is a safe priority for sleep to set for a spin-wait during
    232  1.1.2.1  cliff  * autoconfiguration or after a panic.  Used as an argument to splx().
    233  1.1.2.1  cliff  */
    234  1.1.2.1  cliff int	safepri = MIPS1_PSL_LOWIPL;
    235  1.1.2.1  cliff 
    236  1.1.2.1  cliff extern struct user *proc0paddr;
    237  1.1.2.1  cliff 
    238  1.1.2.1  cliff /*
    239  1.1.2.1  cliff  * Do all the stuff that locore normally does before calling main().
    240  1.1.2.1  cliff  */
    241  1.1.2.1  cliff void
    242  1.1.2.1  cliff mach_init(int argc, int32_t *argv, void *envp, void *infop)
    243  1.1.2.1  cliff {
    244  1.1.2.4  cliff 	struct rmixl_config *rcp = &rmixl_configuration;
    245  1.1.2.1  cliff 	void *kernend, *v;
    246  1.1.2.1  cliff         size_t first, last;
    247  1.1.2.1  cliff 	u_long memsize;
    248  1.1.2.1  cliff 	extern char edata[], end[];
    249  1.1.2.1  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.1  cliff 	 */
    263  1.1.2.1  cliff 	mips_vector_init();
    264  1.1.2.1  cliff 
    265  1.1.2.1  cliff 	memsize = rmixlfw_init(infop);
    266  1.1.2.1  cliff 
    267  1.1.2.1  cliff 	/* set the VM page size */
    268  1.1.2.1  cliff 	uvm_setpagesize();
    269  1.1.2.1  cliff 
    270  1.1.2.1  cliff 	physmem = btoc(memsize);
    271  1.1.2.1  cliff 
    272  1.1.2.3  cliff 	rmixl_eb_bus_mem_init(&rcp->rc_eb_memt, rcp); /* need for console */
    273  1.1.2.3  cliff 	rmixl_el_bus_mem_init(&rcp->rc_el_memt, rcp); /* XXX defer ? */
    274  1.1.2.1  cliff 
    275  1.1.2.1  cliff #if NCOM > 0
    276  1.1.2.4  cliff 	rmixl_com_cnattach(comcnaddr, comcnspeed, -1,
    277  1.1.2.1  cliff 		COM_TYPE_NORMAL, comcnmode);
    278  1.1.2.1  cliff #endif
    279  1.1.2.1  cliff 
    280  1.1.2.1  cliff 	printf("\nNetBSD/rmixl\n");
    281  1.1.2.1  cliff 	printf("memsize = %#lx\n", memsize);
    282  1.1.2.1  cliff 
    283  1.1.2.1  cliff 	/*
    284  1.1.2.1  cliff 	 * Obtain the cpu frequency
    285  1.1.2.1  cliff 	 * Compute the number of ticks for hz.
    286  1.1.2.1  cliff 	 * Compute the delay divisor.
    287  1.1.2.1  cliff 	 * Double the Hz if this CPU runs at twice the
    288  1.1.2.1  cliff          *  external/cp0-count frequency
    289  1.1.2.1  cliff 	 */
    290  1.1.2.1  cliff 	curcpu()->ci_cpu_freq = rmixlfw_info.cpu_frequency;
    291  1.1.2.1  cliff 	curcpu()->ci_cycles_per_hz = (curcpu()->ci_cpu_freq + hz / 2) / hz;
    292  1.1.2.1  cliff 	curcpu()->ci_divisor_delay =
    293  1.1.2.1  cliff 		((curcpu()->ci_cpu_freq + 500000) / 1000000);
    294  1.1.2.1  cliff         if (mips_cpu_flags & CPU_MIPS_DOUBLE_COUNT)
    295  1.1.2.1  cliff 		curcpu()->ci_cpu_freq *= 2;
    296  1.1.2.1  cliff 
    297  1.1.2.1  cliff 	/*
    298  1.1.2.1  cliff 	 * Look at arguments passed to us and compute boothowto.
    299  1.1.2.1  cliff 	 * - rmixl firmware gives us a 32 bit argv[i], so adapt
    300  1.1.2.1  cliff 	 *   by forcing sign extension in cast to (char *)
    301  1.1.2.1  cliff 	 */
    302  1.1.2.1  cliff 	boothowto = RB_AUTOBOOT;
    303  1.1.2.1  cliff 	for (int i = 1; i < argc; i++) {
    304  1.1.2.1  cliff 		for (char *cp = (char *)(uint64_t)argv[i]; *cp; cp++) {
    305  1.1.2.1  cliff 			int howto;
    306  1.1.2.1  cliff 			/* Ignore superfluous '-', if there is one */
    307  1.1.2.1  cliff 			if (*cp == '-')
    308  1.1.2.1  cliff 				continue;
    309  1.1.2.1  cliff 
    310  1.1.2.1  cliff 			howto = 0;
    311  1.1.2.1  cliff 			BOOT_FLAG(*cp, howto);
    312  1.1.2.1  cliff 			if (! howto)
    313  1.1.2.1  cliff 				printf("bootflag '%c' not recognised\n", *cp);
    314  1.1.2.1  cliff 			else
    315  1.1.2.1  cliff 				boothowto |= howto;
    316  1.1.2.1  cliff 		}
    317  1.1.2.1  cliff 	}
    318  1.1.2.1  cliff 	printf("boothowto %#x\n", boothowto);
    319  1.1.2.1  cliff 
    320  1.1.2.1  cliff 	/*
    321  1.1.2.1  cliff 	 * Load the rest of the available pages into the VM system.
    322  1.1.2.1  cliff 	 */
    323  1.1.2.1  cliff 	first = round_page(MIPS_KSEG0_TO_PHYS(kernend));
    324  1.1.2.1  cliff 	last = mem_clusters[0].start + mem_clusters[0].size;
    325  1.1.2.1  cliff 	uvm_page_physload(atop(first), atop(last), atop(first), atop(last),
    326  1.1.2.1  cliff 		VM_FREELIST_DEFAULT);
    327  1.1.2.1  cliff 	for (int i = 1; i < mem_cluster_cnt; i++) {
    328  1.1.2.1  cliff 		first = round_page(mem_clusters[i].start);
    329  1.1.2.1  cliff 		last = mem_clusters[i].start + mem_clusters[i].size;
    330  1.1.2.1  cliff 		uvm_page_physload(atop(first), atop(last), atop(first), atop(last),
    331  1.1.2.1  cliff 			VM_FREELIST_DEFAULT);
    332  1.1.2.1  cliff 	}
    333  1.1.2.1  cliff 
    334  1.1.2.1  cliff 	/*
    335  1.1.2.1  cliff 	 * Initialize error message buffer (at end of core).
    336  1.1.2.1  cliff 	 */
    337  1.1.2.1  cliff 	mips_init_msgbuf();
    338  1.1.2.1  cliff 
    339  1.1.2.1  cliff 	pmap_bootstrap();
    340  1.1.2.1  cliff 
    341  1.1.2.1  cliff 	/*
    342  1.1.2.1  cliff 	 * Allocate space for proc0's USPACE.
    343  1.1.2.1  cliff 	 */
    344  1.1.2.1  cliff 	v = (void *)uvm_pageboot_alloc(USPACE);
    345  1.1.2.1  cliff 	lwp0.l_addr = proc0paddr = (struct user *)v;
    346  1.1.2.1  cliff 	lwp0.l_md.md_regs = (struct frame *)((char *)v + USPACE) - 1;
    347  1.1.2.1  cliff #ifdef _LP64
    348  1.1.2.1  cliff         lwp0.l_md.md_regs->f_regs[_R_SR] = MIPS_SR_KX;
    349  1.1.2.1  cliff #endif
    350  1.1.2.1  cliff         proc0paddr->u_pcb.pcb_context.val[_L_SR] =
    351  1.1.2.1  cliff #ifdef _LP64
    352  1.1.2.1  cliff             MIPS_SR_KX |
    353  1.1.2.1  cliff #endif
    354  1.1.2.1  cliff             MIPS_INT_MASK | MIPS_SR_INT_IE; /* SR */
    355  1.1.2.1  cliff 
    356  1.1.2.1  cliff 
    357  1.1.2.1  cliff 	/*
    358  1.1.2.1  cliff 	 * Initialize debuggers, and break into them, if appropriate.
    359  1.1.2.1  cliff 	 */
    360  1.1.2.1  cliff #if NKSYMS || defined(DDB) || defined(LKM)
    361  1.1.2.1  cliff 	ksyms_init(0, 0, 0);
    362  1.1.2.1  cliff #endif
    363  1.1.2.1  cliff 
    364  1.1.2.1  cliff #if defined(DDB)
    365  1.1.2.1  cliff 	if (boothowto & RB_KDB)
    366  1.1.2.1  cliff 		Debugger();
    367  1.1.2.1  cliff #endif
    368  1.1.2.1  cliff 
    369  1.1.2.1  cliff }
    370  1.1.2.1  cliff 
    371  1.1.2.1  cliff static u_long
    372  1.1.2.1  cliff rmixlfw_init(void *infop)
    373  1.1.2.1  cliff {
    374  1.1.2.4  cliff 	struct rmixl_config *rcp = &rmixl_configuration;
    375  1.1.2.1  cliff 	uint64_t tmp;
    376  1.1.2.1  cliff 
    377  1.1.2.1  cliff 	strcpy(cpu_model, "RMI XLS616ATX VIIA");	/* XXX */
    378  1.1.2.1  cliff 
    379  1.1.2.1  cliff 	tmp = (int64_t)infop;
    380  1.1.2.1  cliff 	tmp |= 0xffffffffULL << 32;
    381  1.1.2.1  cliff 	infop = (void *)tmp;
    382  1.1.2.1  cliff 	rmixlfw_info = *(rmixlfw_info_t *)infop;
    383  1.1.2.1  cliff 
    384  1.1.2.1  cliff 	for (int i=0; i < RMICLFW_PSB_VERSIONS_LEN; i++) {
    385  1.1.2.1  cliff 		if (rmiclfw_psb_versions[i] == rmixlfw_info.psb_version)
    386  1.1.2.1  cliff 			goto found;
    387  1.1.2.1  cliff 	}
    388  1.1.2.1  cliff 
    389  1.1.2.4  cliff 	rcp->rc_io_pbase = MIPS_KSEG1_TO_PHYS(RMIXL_IO_DEV_PBASE);
    390  1.1.2.4  cliff 	rmixl_putchar_init(rcp->rc_io_pbase);
    391  1.1.2.4  cliff 
    392  1.1.2.1  cliff 	rmixl_puts("\r\nWARNING: untested psb_version: ");
    393  1.1.2.1  cliff 	rmixl_puthex64(rmixlfw_info.psb_version);
    394  1.1.2.1  cliff 	rmixl_puts("\r\n");
    395  1.1.2.4  cliff 
    396  1.1.2.1  cliff  found:
    397  1.1.2.4  cliff 	rcp->rc_io_pbase = MIPS_KSEG1_TO_PHYS(rmixlfw_info.io_base);
    398  1.1.2.4  cliff 	rmixl_putchar_init(rcp->rc_io_pbase);
    399  1.1.2.4  cliff 	rmixl_puts("\r\ninfop: ");
    400  1.1.2.4  cliff 	rmixl_puthex64((uint64_t)infop);
    401  1.1.2.4  cliff 	rmixl_puts("\r\nrecognized psb_version: ");
    402  1.1.2.4  cliff 	rmixl_puthex64(rmixlfw_info.psb_version);
    403  1.1.2.4  cliff 	rmixl_puts("\r\n");
    404  1.1.2.1  cliff 
    405  1.1.2.4  cliff 	return mem_clusters_init(
    406  1.1.2.4  cliff 		(rmixlfw_mmap_t *)rmixlfw_info.psb_physaddr_map,
    407  1.1.2.4  cliff 		(rmixlfw_mmap_t *)rmixlfw_info.avail_mem_map);
    408  1.1.2.4  cliff }
    409  1.1.2.4  cliff 
    410  1.1.2.4  cliff static u_long
    411  1.1.2.4  cliff mem_clusters_init(
    412  1.1.2.4  cliff 	rmixlfw_mmap_t *psb_physaddr_map,
    413  1.1.2.4  cliff 	rmixlfw_mmap_t *avail_mem_map)
    414  1.1.2.4  cliff {
    415  1.1.2.4  cliff 	uint64_t tmp;
    416  1.1.2.4  cliff 	uint64_t sz;
    417  1.1.2.4  cliff 	uint64_t sum;
    418  1.1.2.4  cliff #ifdef MEMSIZE
    419  1.1.2.4  cliff 	u_long memsize = MEMSIZE;
    420  1.1.2.4  cliff #endif
    421  1.1.2.4  cliff 
    422  1.1.2.4  cliff 	rmixl_puts("psb_physaddr_map: ");
    423  1.1.2.4  cliff 	rmixl_puthex64((uint64_t)psb_physaddr_map);
    424  1.1.2.4  cliff 	rmixl_puts("\r\n");
    425  1.1.2.4  cliff 
    426  1.1.2.4  cliff 	if (psb_physaddr_map != NULL)
    427  1.1.2.4  cliff 		rmixl_puts("WARNING: no psb_physaddr_map\r\n");
    428  1.1.2.4  cliff 	else
    429  1.1.2.4  cliff 		rmixlfw_phys_mmap  = *psb_physaddr_map;
    430  1.1.2.4  cliff 
    431  1.1.2.4  cliff 	rmixl_puts("avail_mem_map: ");
    432  1.1.2.4  cliff 	rmixl_puthex64((uint64_t)avail_mem_map);
    433  1.1.2.4  cliff 	rmixl_puts("\r\n");
    434  1.1.2.4  cliff 	if (avail_mem_map == NULL) {
    435  1.1.2.4  cliff #ifndef MEMSIZE
    436  1.1.2.4  cliff 		rmixl_puts("ERROR: no avail_mem_map, "
    437  1.1.2.4  cliff 			"must define MEMSIZE\r\n");
    438  1.1.2.4  cliff #else
    439  1.1.2.4  cliff 		rmixl_puts("WARNING: no avail_mem_map, "
    440  1.1.2.4  cliff 			"using MEMSIZE\r\n");
    441  1.1.2.4  cliff 		mem_clusters[0].start = 0;
    442  1.1.2.4  cliff 		mem_clusters[0].size = MEMSIZE;
    443  1.1.2.4  cliff 		mem_cluster_cnt = 1;
    444  1.1.2.4  cliff 		return MEMSIZE;
    445  1.1.2.4  cliff #endif
    446  1.1.2.4  cliff 	}
    447  1.1.2.1  cliff 
    448  1.1.2.4  cliff 	rmixl_puts("using avail_mem_map\r\n");
    449  1.1.2.4  cliff 	rmixlfw_avail_mmap = *(rmixlfw_mmap_t *)rmixlfw_info.avail_mem_map;
    450  1.1.2.4  cliff 	rmixl_puts("memory clusters map:\r\n");
    451  1.1.2.1  cliff 	sum = 0;
    452  1.1.2.1  cliff 	mem_cluster_cnt = 0;
    453  1.1.2.1  cliff 	for (uint32_t i=0; i < rmixlfw_avail_mmap.nmmaps; i++) {
    454  1.1.2.1  cliff 		if (rmixlfw_avail_mmap.entry[i].type != RMIXLFW_MMAP_TYPE_RAM)
    455  1.1.2.1  cliff 			continue;
    456  1.1.2.1  cliff 		mem_clusters[i].start = rmixlfw_avail_mmap.entry[i].start;
    457  1.1.2.1  cliff 		sz = rmixlfw_avail_mmap.entry[i].size;
    458  1.1.2.1  cliff 		sum += sz;
    459  1.1.2.1  cliff 		mem_clusters[i].size = sz;
    460  1.1.2.1  cliff 		mem_cluster_cnt++;
    461  1.1.2.1  cliff #ifdef DEBUG
    462  1.1.2.1  cliff 		rmixl_puthex32(i);
    463  1.1.2.1  cliff 		rmixl_puts(": ");
    464  1.1.2.1  cliff 		rmixl_puthex64(mem_clusters[i].start);
    465  1.1.2.1  cliff 		rmixl_puts(": ");
    466  1.1.2.1  cliff 		rmixl_puthex64(sz);
    467  1.1.2.1  cliff 		rmixl_puts(": ");
    468  1.1.2.1  cliff 		rmixl_puthex64(sum);
    469  1.1.2.1  cliff 		rmixl_puts("\r\n");
    470  1.1.2.1  cliff #endif
    471  1.1.2.1  cliff #ifdef MEMSIZE
    472  1.1.2.1  cliff 		/*
    473  1.1.2.1  cliff 		 * configurably limit memsize
    474  1.1.2.1  cliff 		 */
    475  1.1.2.1  cliff 		if (sum == memsize)
    476  1.1.2.1  cliff 			break;
    477  1.1.2.1  cliff 		if (sum > memsize) {
    478  1.1.2.1  cliff 			tmp = sum - memsize;
    479  1.1.2.1  cliff 			sz -= tmp;
    480  1.1.2.1  cliff 			sum -= tmp;
    481  1.1.2.1  cliff 			mem_clusters[i].size = sz;
    482  1.1.2.1  cliff 			break;
    483  1.1.2.1  cliff 		}
    484  1.1.2.1  cliff #endif
    485  1.1.2.1  cliff 	}
    486  1.1.2.1  cliff 	return sum;
    487  1.1.2.1  cliff }
    488  1.1.2.1  cliff 
    489  1.1.2.1  cliff void
    490  1.1.2.1  cliff consinit(void)
    491  1.1.2.1  cliff {
    492  1.1.2.1  cliff 
    493  1.1.2.1  cliff 	/*
    494  1.1.2.1  cliff 	 * Everything related to console initialization is done
    495  1.1.2.1  cliff 	 * in mach_init().
    496  1.1.2.1  cliff 	 */
    497  1.1.2.1  cliff }
    498  1.1.2.1  cliff 
    499  1.1.2.1  cliff /*
    500  1.1.2.1  cliff  * Allocate memory for variable-sized tables,
    501  1.1.2.1  cliff  */
    502  1.1.2.1  cliff void
    503  1.1.2.1  cliff cpu_startup()
    504  1.1.2.1  cliff {
    505  1.1.2.1  cliff 	vaddr_t minaddr, maxaddr;
    506  1.1.2.1  cliff 	char pbuf[9];
    507  1.1.2.1  cliff 
    508  1.1.2.1  cliff 	/*
    509  1.1.2.1  cliff 	 * Good {morning,afternoon,evening,night}.
    510  1.1.2.1  cliff 	 */
    511  1.1.2.1  cliff 	printf("%s%s", copyright, version);
    512  1.1.2.1  cliff 	format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
    513  1.1.2.1  cliff 	printf("total memory = %s\n", pbuf);
    514  1.1.2.1  cliff 
    515  1.1.2.1  cliff 	/*
    516  1.1.2.1  cliff 	 * Virtual memory is bootstrapped -- notify the bus spaces
    517  1.1.2.1  cliff 	 * that memory allocation is now safe.
    518  1.1.2.1  cliff 	 */
    519  1.1.2.1  cliff 	rmixl_configuration.rc_mallocsafe = 1;
    520  1.1.2.1  cliff 
    521  1.1.2.1  cliff 	minaddr = 0;
    522  1.1.2.1  cliff 	/*
    523  1.1.2.1  cliff 	 * Allocate a submap for physio.
    524  1.1.2.1  cliff 	 */
    525  1.1.2.1  cliff 	phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    526  1.1.2.1  cliff 				    VM_PHYS_SIZE, 0, FALSE, NULL);
    527  1.1.2.1  cliff 
    528  1.1.2.1  cliff 	/*
    529  1.1.2.1  cliff 	 * (No need to allocate an mbuf cluster submap.  Mbuf clusters
    530  1.1.2.1  cliff 	 * are allocated via the pool allocator, and we use KSEG to
    531  1.1.2.1  cliff 	 * map those pages.)
    532  1.1.2.1  cliff 	 */
    533  1.1.2.1  cliff 
    534  1.1.2.1  cliff 	format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
    535  1.1.2.1  cliff 	printf("avail memory = %s\n", pbuf);
    536  1.1.2.1  cliff }
    537  1.1.2.1  cliff 
    538  1.1.2.1  cliff int	waittime = -1;
    539  1.1.2.1  cliff 
    540  1.1.2.1  cliff void
    541  1.1.2.1  cliff cpu_reboot(howto, bootstr)
    542  1.1.2.1  cliff 	int howto;
    543  1.1.2.1  cliff 	char *bootstr;
    544  1.1.2.1  cliff {
    545  1.1.2.1  cliff 
    546  1.1.2.1  cliff 	/* Take a snapshot before clobbering any registers. */
    547  1.1.2.1  cliff 	if (curproc)
    548  1.1.2.1  cliff 		savectx((struct user *)curpcb);
    549  1.1.2.1  cliff 
    550  1.1.2.1  cliff 	if (cold) {
    551  1.1.2.1  cliff 		howto |= RB_HALT;
    552  1.1.2.1  cliff 		goto haltsys;
    553  1.1.2.1  cliff 	}
    554  1.1.2.1  cliff 
    555  1.1.2.1  cliff 	/* If "always halt" was specified as a boot flag, obey. */
    556  1.1.2.1  cliff 	if (boothowto & RB_HALT)
    557  1.1.2.1  cliff 		howto |= RB_HALT;
    558  1.1.2.1  cliff 
    559  1.1.2.1  cliff 	boothowto = howto;
    560  1.1.2.1  cliff 	if ((howto & RB_NOSYNC) == 0 && (waittime < 0)) {
    561  1.1.2.1  cliff 		waittime = 0;
    562  1.1.2.1  cliff 		vfs_shutdown();
    563  1.1.2.1  cliff 
    564  1.1.2.1  cliff 		/*
    565  1.1.2.1  cliff 		 * If we've been adjusting the clock, the todr
    566  1.1.2.1  cliff 		 * will be out of synch; adjust it now.
    567  1.1.2.1  cliff 		 */
    568  1.1.2.1  cliff 		resettodr();
    569  1.1.2.1  cliff 	}
    570  1.1.2.1  cliff 
    571  1.1.2.1  cliff 	splhigh();
    572  1.1.2.1  cliff 
    573  1.1.2.1  cliff 	if (howto & RB_DUMP)
    574  1.1.2.1  cliff 		dumpsys();
    575  1.1.2.1  cliff 
    576  1.1.2.1  cliff haltsys:
    577  1.1.2.1  cliff 	doshutdownhooks();
    578  1.1.2.1  cliff 
    579  1.1.2.1  cliff 	if (howto & RB_HALT) {
    580  1.1.2.1  cliff 		printf("\n");
    581  1.1.2.1  cliff 		printf("The operating system has halted.\n");
    582  1.1.2.1  cliff 		printf("Please press any key to reboot.\n\n");
    583  1.1.2.1  cliff 		cnpollc(1);	/* For proper keyboard command handling */
    584  1.1.2.1  cliff 		cngetc();
    585  1.1.2.1  cliff 		cnpollc(0);
    586  1.1.2.1  cliff 	}
    587  1.1.2.1  cliff 
    588  1.1.2.1  cliff 	printf("rebooting...\n\n");
    589  1.1.2.1  cliff 
    590  1.1.2.1  cliff 	rmixl_exit(0);
    591  1.1.2.1  cliff }
    592  1.1.2.1  cliff 
    593  1.1.2.1  cliff /*
    594  1.1.2.1  cliff  * goodbye world
    595  1.1.2.1  cliff  */
    596  1.1.2.1  cliff #define GPIO_CPU_RST 0xa0			/* XXX TMP */
    597  1.1.2.1  cliff void __attribute__((__noreturn__))
    598  1.1.2.1  cliff rmixl_exit(int howto)
    599  1.1.2.1  cliff {
    600  1.1.2.1  cliff 	/* use firmware callbak to reboot */
    601  1.1.2.1  cliff 	void (*reset)(void) = (void *)rmixlfw_info.warm_reset;
    602  1.1.2.4  cliff 	if (reset != 0) {
    603  1.1.2.4  cliff 		(*reset)();
    604  1.1.2.4  cliff 		printf("warm reset callback failed, spinning...\n");
    605  1.1.2.4  cliff 	} else {
    606  1.1.2.4  cliff 		printf("warm reset callback absent, spinning...\n");
    607  1.1.2.4  cliff 	}
    608  1.1.2.1  cliff 	for (;;);
    609  1.1.2.1  cliff }
    610