Home | History | Annotate | Line # | Download | only in gdium
machdep.c revision 1.8.2.3
      1  1.8.2.3  yamt /*	$NetBSD: machdep.c,v 1.8.2.3 2010/03/11 15:02:19 yamt Exp $	*/
      2  1.8.2.2  yamt 
      3  1.8.2.2  yamt /*
      4  1.8.2.2  yamt  * Copyright 2001, 2002 Wasabi Systems, Inc.
      5  1.8.2.2  yamt  * All rights reserved.
      6  1.8.2.2  yamt  *
      7  1.8.2.2  yamt  * Written by Jason R. Thorpe and Simon Burge for Wasabi Systems, Inc.
      8  1.8.2.2  yamt  *
      9  1.8.2.2  yamt  * Redistribution and use in source and binary forms, with or without
     10  1.8.2.2  yamt  * modification, are permitted provided that the following conditions
     11  1.8.2.2  yamt  * are met:
     12  1.8.2.2  yamt  * 1. Redistributions of source code must retain the above copyright
     13  1.8.2.2  yamt  *    notice, this list of conditions and the following disclaimer.
     14  1.8.2.2  yamt  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.8.2.2  yamt  *    notice, this list of conditions and the following disclaimer in the
     16  1.8.2.2  yamt  *    documentation and/or other materials provided with the distribution.
     17  1.8.2.2  yamt  * 3. All advertising materials mentioning features or use of this software
     18  1.8.2.2  yamt  *    must display the following acknowledgement:
     19  1.8.2.2  yamt  *      This product includes software developed for the NetBSD Project by
     20  1.8.2.2  yamt  *      Wasabi Systems, Inc.
     21  1.8.2.2  yamt  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  1.8.2.2  yamt  *    or promote products derived from this software without specific prior
     23  1.8.2.2  yamt  *    written permission.
     24  1.8.2.2  yamt  *
     25  1.8.2.2  yamt  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  1.8.2.2  yamt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.8.2.2  yamt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.8.2.2  yamt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  1.8.2.2  yamt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.8.2.2  yamt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.8.2.2  yamt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.8.2.2  yamt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.8.2.2  yamt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.8.2.2  yamt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.8.2.2  yamt  * POSSIBILITY OF SUCH DAMAGE.
     36  1.8.2.2  yamt  */
     37  1.8.2.2  yamt 
     38  1.8.2.2  yamt /*
     39  1.8.2.2  yamt  * Copyright (c) 1992, 1993
     40  1.8.2.2  yamt  *	The Regents of the University of California.  All rights reserved.
     41  1.8.2.2  yamt  *
     42  1.8.2.2  yamt  * This code is derived from software contributed to Berkeley by
     43  1.8.2.2  yamt  * the Systems Programming Group of the University of Utah Computer
     44  1.8.2.2  yamt  * Science Department, The Mach Operating System project at
     45  1.8.2.2  yamt  * Carnegie-Mellon University and Ralph Campbell.
     46  1.8.2.2  yamt  *
     47  1.8.2.2  yamt  * Redistribution and use in source and binary forms, with or without
     48  1.8.2.2  yamt  * modification, are permitted provided that the following conditions
     49  1.8.2.2  yamt  * are met:
     50  1.8.2.2  yamt  * 1. Redistributions of source code must retain the above copyright
     51  1.8.2.2  yamt  *    notice, this list of conditions and the following disclaimer.
     52  1.8.2.2  yamt  * 2. Redistributions in binary form must reproduce the above copyright
     53  1.8.2.2  yamt  *    notice, this list of conditions and the following disclaimer in the
     54  1.8.2.2  yamt  *    documentation and/or other materials provided with the distribution.
     55  1.8.2.2  yamt  * 3. Neither the name of the University nor the names of its contributors
     56  1.8.2.2  yamt  *    may be used to endorse or promote products derived from this software
     57  1.8.2.2  yamt  *    without specific prior written permission.
     58  1.8.2.2  yamt  *
     59  1.8.2.2  yamt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60  1.8.2.2  yamt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61  1.8.2.2  yamt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62  1.8.2.2  yamt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63  1.8.2.2  yamt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64  1.8.2.2  yamt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65  1.8.2.2  yamt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66  1.8.2.2  yamt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67  1.8.2.2  yamt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68  1.8.2.2  yamt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69  1.8.2.2  yamt  * SUCH DAMAGE.
     70  1.8.2.2  yamt  *
     71  1.8.2.2  yamt  *	@(#)machdep.c   8.3 (Berkeley) 1/12/94
     72  1.8.2.2  yamt  *	from: Utah Hdr: machdep.c 1.63 91/04/24
     73  1.8.2.2  yamt  */
     74  1.8.2.2  yamt /*
     75  1.8.2.2  yamt  * Copyright (c) 1988 University of Utah.
     76  1.8.2.2  yamt  *
     77  1.8.2.2  yamt  * This code is derived from software contributed to Berkeley by
     78  1.8.2.2  yamt  * the Systems Programming Group of the University of Utah Computer
     79  1.8.2.2  yamt  * Science Department, The Mach Operating System project at
     80  1.8.2.2  yamt  * Carnegie-Mellon University and Ralph Campbell.
     81  1.8.2.2  yamt  *
     82  1.8.2.2  yamt  * Redistribution and use in source and binary forms, with or without
     83  1.8.2.2  yamt  * modification, are permitted provided that the following conditions
     84  1.8.2.2  yamt  * are met:
     85  1.8.2.2  yamt  * 1. Redistributions of source code must retain the above copyright
     86  1.8.2.2  yamt  *    notice, this list of conditions and the following disclaimer.
     87  1.8.2.2  yamt  * 2. Redistributions in binary form must reproduce the above copyright
     88  1.8.2.2  yamt  *    notice, this list of conditions and the following disclaimer in the
     89  1.8.2.2  yamt  *    documentation and/or other materials provided with the distribution.
     90  1.8.2.2  yamt  * 3. All advertising materials mentioning features or use of this software
     91  1.8.2.2  yamt  *    must display the following acknowledgement:
     92  1.8.2.2  yamt  *	This product includes software developed by the University of
     93  1.8.2.2  yamt  *	California, Berkeley and its contributors.
     94  1.8.2.2  yamt  * 4. Neither the name of the University nor the names of its contributors
     95  1.8.2.2  yamt  *    may be used to endorse or promote products derived from this software
     96  1.8.2.2  yamt  *    without specific prior written permission.
     97  1.8.2.2  yamt  *
     98  1.8.2.2  yamt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     99  1.8.2.2  yamt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    100  1.8.2.2  yamt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    101  1.8.2.2  yamt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    102  1.8.2.2  yamt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    103  1.8.2.2  yamt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    104  1.8.2.2  yamt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    105  1.8.2.2  yamt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    106  1.8.2.2  yamt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    107  1.8.2.2  yamt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    108  1.8.2.2  yamt  * SUCH DAMAGE.
    109  1.8.2.2  yamt  *
    110  1.8.2.2  yamt  *	@(#)machdep.c   8.3 (Berkeley) 1/12/94
    111  1.8.2.2  yamt  *	from: Utah Hdr: machdep.c 1.63 91/04/24
    112  1.8.2.2  yamt  */
    113  1.8.2.2  yamt 
    114  1.8.2.2  yamt #include <sys/cdefs.h>
    115  1.8.2.3  yamt __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.8.2.3 2010/03/11 15:02:19 yamt Exp $");
    116  1.8.2.2  yamt 
    117  1.8.2.2  yamt #include "opt_ddb.h"
    118  1.8.2.2  yamt #include "opt_execfmt.h"
    119  1.8.2.2  yamt #include "opt_modular.h"
    120  1.8.2.2  yamt 
    121  1.8.2.2  yamt #include <sys/param.h>
    122  1.8.2.2  yamt #include <sys/systm.h>
    123  1.8.2.2  yamt #include <sys/kernel.h>
    124  1.8.2.2  yamt #include <sys/buf.h>
    125  1.8.2.2  yamt #include <sys/reboot.h>
    126  1.8.2.2  yamt #include <sys/mount.h>
    127  1.8.2.2  yamt #include <sys/kcore.h>
    128  1.8.2.2  yamt #include <sys/boot_flag.h>
    129  1.8.2.2  yamt #include <sys/termios.h>
    130  1.8.2.2  yamt #include <sys/ksyms.h>
    131  1.8.2.2  yamt #include <sys/device.h>
    132  1.8.2.2  yamt 
    133  1.8.2.2  yamt #include <uvm/uvm_extern.h>
    134  1.8.2.2  yamt 
    135  1.8.2.2  yamt #include <dev/cons.h>
    136  1.8.2.2  yamt 
    137  1.8.2.2  yamt #include "ksyms.h"
    138  1.8.2.2  yamt 
    139  1.8.2.2  yamt #if NKSYMS || defined(DDB) || defined(MODULAR)
    140  1.8.2.2  yamt #include <machine/db_machdep.h>
    141  1.8.2.2  yamt #include <ddb/db_extern.h>
    142  1.8.2.2  yamt #endif
    143  1.8.2.2  yamt 
    144  1.8.2.2  yamt #include <machine/cpu.h>
    145  1.8.2.2  yamt #include <machine/psl.h>
    146  1.8.2.2  yamt 
    147  1.8.2.2  yamt #include <mips/bonito/bonitoreg.h>
    148  1.8.2.2  yamt #include <evbmips/gdium/gdiumvar.h>
    149  1.8.2.2  yamt 
    150  1.8.2.2  yamt #include "com.h"
    151  1.8.2.2  yamt #if NCOM > 0
    152  1.8.2.2  yamt #include <dev/ic/comreg.h>
    153  1.8.2.2  yamt #include <dev/ic/comvar.h>
    154  1.8.2.2  yamt 
    155  1.8.2.2  yamt int	comcnrate = 38400;	/* XXX should be config option */
    156  1.8.2.2  yamt #endif /* NCOM > 0 */
    157  1.8.2.2  yamt 
    158  1.8.2.2  yamt struct gdium_config gdium_configuration = {
    159  1.8.2.2  yamt 	.gc_bonito = {
    160  1.8.2.2  yamt 		.bc_adbase = 11,	/* magic */
    161  1.8.2.2  yamt 	},
    162  1.8.2.2  yamt };
    163  1.8.2.2  yamt 
    164  1.8.2.2  yamt /* For sysctl_hw. */
    165  1.8.2.2  yamt extern char cpu_model[];
    166  1.8.2.2  yamt 
    167  1.8.2.2  yamt /* Our exported CPU info; we can have only one. */
    168  1.8.2.2  yamt struct cpu_info cpu_info_store;
    169  1.8.2.2  yamt 
    170  1.8.2.2  yamt /* Maps for VM objects. */
    171  1.8.2.2  yamt struct vm_map *phys_map = NULL;
    172  1.8.2.2  yamt 
    173  1.8.2.2  yamt int	netboot;		/* Are we netbooting? */
    174  1.8.2.2  yamt 
    175  1.8.2.2  yamt phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];
    176  1.8.2.2  yamt int mem_cluster_cnt;
    177  1.8.2.2  yamt 
    178  1.8.2.2  yamt void	configure(void);
    179  1.8.2.2  yamt void	mach_init(int, char **, char **, void *);
    180  1.8.2.2  yamt 
    181  1.8.2.2  yamt /*
    182  1.8.2.2  yamt  * safepri is a safe priority for sleep to set for a spin-wait during
    183  1.8.2.2  yamt  * autoconfiguration or after a panic.  Used as an argument to splx().
    184  1.8.2.2  yamt  */
    185  1.8.2.2  yamt int	safepri = MIPS1_PSL_LOWIPL;
    186  1.8.2.2  yamt 
    187  1.8.2.2  yamt /*
    188  1.8.2.2  yamt  * For some reason, PMON doesn't assign a real address to the Ralink's BAR.
    189  1.8.2.2  yamt  * So we have to do it.
    190  1.8.2.2  yamt  */
    191  1.8.2.2  yamt static void
    192  1.8.2.2  yamt gdium_pci_attach_hook(device_t parent, device_t self,
    193  1.8.2.2  yamt     struct pcibus_attach_args *pba)
    194  1.8.2.2  yamt {
    195  1.8.2.2  yamt 	const pcitag_t high_dev = pci_make_tag(pba->pba_pc, 0, 17, 1);
    196  1.8.2.2  yamt 	const pcitag_t ralink_dev = pci_make_tag(pba->pba_pc, 0, 13, 0);
    197  1.8.2.2  yamt 	bus_size_t high_size, ralink_size;
    198  1.8.2.2  yamt 	pcireg_t v;
    199  1.8.2.2  yamt 
    200  1.8.2.2  yamt 	/*
    201  1.8.2.2  yamt 	 * Get the highest PCI addr used from the last PCI dev.
    202  1.8.2.2  yamt 	 */
    203  1.8.2.2  yamt 	v = pci_conf_read(pba->pba_pc, high_dev, PCI_MAPREG_START);
    204  1.8.2.2  yamt 	v &= PCI_MAPREG_MEM_ADDR_MASK;
    205  1.8.2.2  yamt 
    206  1.8.2.2  yamt 	/*
    207  1.8.2.2  yamt 	 * Get the sizes of the map registers.
    208  1.8.2.2  yamt 	 */
    209  1.8.2.2  yamt 	pci_mapreg_info(pba->pba_pc, high_dev, PCI_MAPREG_START,
    210  1.8.2.2  yamt 	    PCI_MAPREG_MEM_TYPE_32BIT, NULL, &high_size, NULL);
    211  1.8.2.2  yamt 	pci_mapreg_info(pba->pba_pc, ralink_dev, PCI_MAPREG_START,
    212  1.8.2.2  yamt 	    PCI_MAPREG_MEM_TYPE_32BIT, NULL, &ralink_size, NULL);
    213  1.8.2.2  yamt 
    214  1.8.2.2  yamt 	/*
    215  1.8.2.2  yamt 	 * Position the ralink register space after the last device.
    216  1.8.2.2  yamt 	 */
    217  1.8.2.2  yamt 	v = (v + high_size + ralink_size - 1) & ~(ralink_size - 1);
    218  1.8.2.2  yamt 
    219  1.8.2.2  yamt 	/*
    220  1.8.2.2  yamt 	 * Set the mapreg.
    221  1.8.2.2  yamt 	 */
    222  1.8.2.2  yamt 	pci_conf_write(pba->pba_pc, ralink_dev, PCI_MAPREG_START, v);
    223  1.8.2.2  yamt 
    224  1.8.2.2  yamt #if 0
    225  1.8.2.2  yamt 	/*
    226  1.8.2.2  yamt 	 * Why does linux do this?
    227  1.8.2.2  yamt 	 */
    228  1.8.2.2  yamt 	for (int dev = 15; dev <= 17; dev +=2) {
    229  1.8.2.2  yamt 		for (int func = 0; func <= 1; func++) {
    230  1.8.2.2  yamt 			pcitag_t usb_dev = pci_make_tag(pba->pba_pc, 0, dev, func);
    231  1.8.2.2  yamt 			v = pci_conf_read(pba->pba_pc, usb_dev, 0xe0);
    232  1.8.2.2  yamt 			v |= 3;
    233  1.8.2.2  yamt 			pci_conf_write(pba->pba_pc, usb_dev, 0xe0, v);
    234  1.8.2.2  yamt 		}
    235  1.8.2.2  yamt 	}
    236  1.8.2.2  yamt #endif
    237  1.8.2.2  yamt }
    238  1.8.2.2  yamt 
    239  1.8.2.2  yamt /*
    240  1.8.2.2  yamt  * Do all the stuff that locore normally does before calling main().
    241  1.8.2.2  yamt  */
    242  1.8.2.2  yamt void
    243  1.8.2.2  yamt mach_init(int argc, char **argv, char **envp, void *callvec)
    244  1.8.2.2  yamt {
    245  1.8.2.2  yamt 	struct gdium_config *gc = &gdium_configuration;
    246  1.8.2.3  yamt 	void *kernend;
    247  1.8.2.3  yamt 	u_long first, last;
    248  1.8.2.3  yamt 	struct pcb *pcb0;
    249  1.8.2.3  yamt 	vaddr_t v;
    250  1.8.2.2  yamt #ifdef NOTYET
    251  1.8.2.2  yamt 	char *cp;
    252  1.8.2.2  yamt 	int howto;
    253  1.8.2.2  yamt #endif
    254  1.8.2.2  yamt 	int i;
    255  1.8.2.2  yamt 	psize_t memsize;
    256  1.8.2.2  yamt 
    257  1.8.2.2  yamt 	extern char edata[], end[];
    258  1.8.2.2  yamt 
    259  1.8.2.2  yamt 	/*
    260  1.8.2.2  yamt 	 * Clear the BSS segment.
    261  1.8.2.2  yamt 	 */
    262  1.8.2.2  yamt 	kernend = (void *)mips_round_page(end);
    263  1.8.2.2  yamt 	memset(edata, 0, (char *)kernend - edata);
    264  1.8.2.2  yamt 
    265  1.8.2.2  yamt 	/*
    266  1.8.2.2  yamt 	 * Set up the exception vectors and CPU-specific function
    267  1.8.2.2  yamt 	 * vectors early on.  We need the wbflush() vector set up
    268  1.8.2.2  yamt 	 * before comcnattach() is called (or at least before the
    269  1.8.2.2  yamt 	 * first printf() after that is called).
    270  1.8.2.2  yamt 	 * Also clears the I+D caches.
    271  1.8.2.2  yamt 	 */
    272  1.8.2.2  yamt 	mips_vector_init();
    273  1.8.2.2  yamt 
    274  1.8.2.2  yamt 	/* set the VM page size */
    275  1.8.2.2  yamt 	uvm_setpagesize();
    276  1.8.2.2  yamt 
    277  1.8.2.2  yamt 	memsize = 256*1024*1024;
    278  1.8.2.2  yamt 	physmem = btoc(memsize);
    279  1.8.2.2  yamt 
    280  1.8.2.2  yamt 	bonito_pci_init(&gc->gc_pc, &gc->gc_bonito);
    281  1.8.2.2  yamt 	/*
    282  1.8.2.2  yamt 	 * Override the null bonito_pci_attach_hook with our own to we can
    283  1.8.2.2  yamt 	 * fix the ralink (device 13).
    284  1.8.2.2  yamt 	 */
    285  1.8.2.2  yamt 	gc->gc_pc.pc_attach_hook = gdium_pci_attach_hook;
    286  1.8.2.2  yamt 	gdium_bus_io_init(&gc->gc_iot, gc);
    287  1.8.2.2  yamt 	gdium_bus_mem_init(&gc->gc_memt, gc);
    288  1.8.2.2  yamt 	gdium_dma_init(gc);
    289  1.8.2.2  yamt 	gdium_cnattach(gc);
    290  1.8.2.2  yamt 
    291  1.8.2.2  yamt 	/*
    292  1.8.2.2  yamt 	 * Disable the 2nd PCI window since we don't need it.
    293  1.8.2.2  yamt 	 */
    294  1.8.2.2  yamt 	mips3_sd((uint64_t *)MIPS_PHYS_TO_KSEG1(BONITO_REGBASE + 0x158), 0xe);
    295  1.8.2.2  yamt 	pci_conf_write(&gc->gc_pc, pci_make_tag(&gc->gc_pc, 0, 0, 0), 18, 0);
    296  1.8.2.2  yamt 
    297  1.8.2.2  yamt 	/*
    298  1.8.2.2  yamt 	 * Get the timer from PMON.
    299  1.8.2.2  yamt 	 */
    300  1.8.2.2  yamt 	for (i = 0; envp[i] != NULL; i++) {
    301  1.8.2.2  yamt 		if (!strncmp(envp[i], "cpuclock=", 9)) {
    302  1.8.2.2  yamt 			curcpu()->ci_cpu_freq =
    303  1.8.2.2  yamt 			    strtoul(&envp[i][9], NULL, 10);
    304  1.8.2.2  yamt 			break;
    305  1.8.2.2  yamt 		}
    306  1.8.2.2  yamt 	}
    307  1.8.2.2  yamt 
    308  1.8.2.2  yamt 	if (mips_cpu_flags & CPU_MIPS_DOUBLE_COUNT)
    309  1.8.2.2  yamt 		curcpu()->ci_cpu_freq /= 2;
    310  1.8.2.2  yamt 
    311  1.8.2.2  yamt 	/* Compute the number of ticks for hz. */
    312  1.8.2.2  yamt 	curcpu()->ci_cycles_per_hz = (curcpu()->ci_cpu_freq + hz / 2) / hz;
    313  1.8.2.2  yamt 
    314  1.8.2.2  yamt 	/* Compute the delay divisor. */
    315  1.8.2.2  yamt 	curcpu()->ci_divisor_delay =
    316  1.8.2.2  yamt 	    ((curcpu()->ci_cpu_freq + 500000) / 1000000);
    317  1.8.2.2  yamt 
    318  1.8.2.2  yamt 	/*
    319  1.8.2.2  yamt 	 * Get correct cpu frequency if the CPU runs at twice the
    320  1.8.2.2  yamt 	 * external/cp0-count frequency.
    321  1.8.2.2  yamt 	 */
    322  1.8.2.2  yamt 	if (mips_cpu_flags & CPU_MIPS_DOUBLE_COUNT)
    323  1.8.2.2  yamt 		curcpu()->ci_cpu_freq *= 2;
    324  1.8.2.2  yamt 
    325  1.8.2.2  yamt #ifdef DEBUG
    326  1.8.2.2  yamt 	printf("Timer calibration: %lu cycles/sec\n",
    327  1.8.2.2  yamt 	    curcpu()->ci_cpu_freq);
    328  1.8.2.2  yamt #endif
    329  1.8.2.2  yamt 
    330  1.8.2.2  yamt #if NCOM > 0
    331  1.8.2.2  yamt 	/*
    332  1.8.2.2  yamt 	 * Delay to allow firmware putchars to complete.
    333  1.8.2.2  yamt 	 * FIFO depth * character time.
    334  1.8.2.2  yamt 	 * character time = (1000000 / (defaultrate / 10))
    335  1.8.2.2  yamt 	 */
    336  1.8.2.2  yamt 	delay(160000000 / comcnrate);
    337  1.8.2.2  yamt 	if (comcnattach(&gc->gc_iot, MALTA_UART0ADR, comcnrate,
    338  1.8.2.2  yamt 	    COM_FREQ, COM_TYPE_NORMAL,
    339  1.8.2.2  yamt 	    (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8) != 0)
    340  1.8.2.2  yamt 		panic("malta: unable to initialize serial console");
    341  1.8.2.2  yamt #endif /* NCOM > 0 */
    342  1.8.2.2  yamt 
    343  1.8.2.2  yamt 	mem_clusters[0].start = 0;
    344  1.8.2.2  yamt 	mem_clusters[0].size = ctob(physmem);
    345  1.8.2.2  yamt 	mem_cluster_cnt = 1;
    346  1.8.2.2  yamt 
    347  1.8.2.2  yamt 	strcpy(cpu_model, "Gdium Liberty 1000");
    348  1.8.2.2  yamt 
    349  1.8.2.2  yamt 	/*
    350  1.8.2.2  yamt 	 * XXX: check argv[0] - do something if "gdb"???
    351  1.8.2.2  yamt 	 */
    352  1.8.2.2  yamt 
    353  1.8.2.2  yamt 	/*
    354  1.8.2.2  yamt 	 * Look at arguments passed to us and compute boothowto.
    355  1.8.2.2  yamt 	 */
    356  1.8.2.2  yamt 	boothowto = RB_AUTOBOOT;
    357  1.8.2.2  yamt #ifdef NOTYET
    358  1.8.2.2  yamt 	for (i = 1; i < argc; i++) {
    359  1.8.2.2  yamt 		for (cp = argv[i]; *cp; cp++) {
    360  1.8.2.2  yamt 			/* Ignore superfluous '-', if there is one */
    361  1.8.2.2  yamt 			if (*cp == '-')
    362  1.8.2.2  yamt 				continue;
    363  1.8.2.2  yamt 
    364  1.8.2.2  yamt 			howto = 0;
    365  1.8.2.2  yamt 			BOOT_FLAG(*cp, howto);
    366  1.8.2.2  yamt 			if (! howto)
    367  1.8.2.2  yamt 				printf("bootflag '%c' not recognised\n", *cp);
    368  1.8.2.2  yamt 			else
    369  1.8.2.2  yamt 				boothowto |= howto;
    370  1.8.2.2  yamt 		}
    371  1.8.2.2  yamt 	}
    372  1.8.2.2  yamt #endif
    373  1.8.2.2  yamt 
    374  1.8.2.2  yamt 	/*
    375  1.8.2.2  yamt 	 * Load the rest of the available pages into the VM system.
    376  1.8.2.2  yamt 	 */
    377  1.8.2.2  yamt 	first = round_page(MIPS_KSEG0_TO_PHYS(kernend));
    378  1.8.2.2  yamt 	last = mem_clusters[0].start + mem_clusters[0].size;
    379  1.8.2.2  yamt 	uvm_page_physload(atop(first), atop(last), atop(first), atop(last),
    380  1.8.2.2  yamt 		VM_FREELIST_DEFAULT);
    381  1.8.2.2  yamt 
    382  1.8.2.2  yamt 	/*
    383  1.8.2.2  yamt 	 * Initialize error message buffer (at end of core).
    384  1.8.2.2  yamt 	 */
    385  1.8.2.2  yamt 	mips_init_msgbuf();
    386  1.8.2.2  yamt 
    387  1.8.2.2  yamt 	pmap_bootstrap();
    388  1.8.2.2  yamt 
    389  1.8.2.2  yamt 	/*
    390  1.8.2.3  yamt 	 * Allocate uarea page for lwp0 and set it.
    391  1.8.2.2  yamt 	 */
    392  1.8.2.3  yamt 	v = uvm_pageboot_alloc(USPACE);
    393  1.8.2.3  yamt 	uvm_lwp_setuarea(&lwp0, v);
    394  1.8.2.3  yamt 
    395  1.8.2.3  yamt 	pcb0 = lwp_getpcb(&lwp0);
    396  1.8.2.3  yamt 	pcb0->pcb_context[11] = MIPS_INT_MASK | MIPS_SR_INT_IE; /* SR */
    397  1.8.2.3  yamt 
    398  1.8.2.3  yamt 	lwp0.l_md.md_regs = (struct frame *)(v + USPACE) - 1;
    399  1.8.2.2  yamt 
    400  1.8.2.2  yamt 	/*
    401  1.8.2.2  yamt 	 * Initialize debuggers, and break into them, if appropriate.
    402  1.8.2.2  yamt 	 */
    403  1.8.2.2  yamt #if defined(DDB)
    404  1.8.2.2  yamt 	if (boothowto & RB_KDB)
    405  1.8.2.2  yamt 		Debugger();
    406  1.8.2.2  yamt #endif
    407  1.8.2.2  yamt }
    408  1.8.2.2  yamt 
    409  1.8.2.2  yamt void
    410  1.8.2.2  yamt consinit(void)
    411  1.8.2.2  yamt {
    412  1.8.2.2  yamt 
    413  1.8.2.2  yamt 	/*
    414  1.8.2.2  yamt 	 * Everything related to console initialization is done
    415  1.8.2.2  yamt 	 * in mach_init().
    416  1.8.2.2  yamt 	 */
    417  1.8.2.2  yamt }
    418  1.8.2.2  yamt 
    419  1.8.2.2  yamt /*
    420  1.8.2.2  yamt  * Allocate memory for variable-sized tables,
    421  1.8.2.2  yamt  */
    422  1.8.2.2  yamt void
    423  1.8.2.2  yamt cpu_startup(void)
    424  1.8.2.2  yamt {
    425  1.8.2.2  yamt 	vaddr_t minaddr, maxaddr;
    426  1.8.2.2  yamt 	char pbuf[9];
    427  1.8.2.2  yamt 
    428  1.8.2.2  yamt 	/*
    429  1.8.2.2  yamt 	 * Good {morning,afternoon,evening,night}.
    430  1.8.2.2  yamt 	 */
    431  1.8.2.2  yamt 	printf("%s%s", copyright, version);
    432  1.8.2.2  yamt 	format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
    433  1.8.2.2  yamt 	printf("total memory = %s\n", pbuf);
    434  1.8.2.2  yamt 
    435  1.8.2.2  yamt 	/*
    436  1.8.2.2  yamt 	 * Virtual memory is bootstrapped -- notify the bus spaces
    437  1.8.2.2  yamt 	 * that memory allocation is now safe.
    438  1.8.2.2  yamt 	 */
    439  1.8.2.2  yamt 	gdium_configuration.gc_mallocsafe = 1;
    440  1.8.2.2  yamt 
    441  1.8.2.2  yamt 	minaddr = 0;
    442  1.8.2.2  yamt 	/*
    443  1.8.2.2  yamt 	 * Allocate a submap for physio.
    444  1.8.2.2  yamt 	 */
    445  1.8.2.2  yamt 	phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    446  1.8.2.2  yamt 				    VM_PHYS_SIZE, 0, FALSE, NULL);
    447  1.8.2.2  yamt 
    448  1.8.2.2  yamt 	/*
    449  1.8.2.2  yamt 	 * (No need to allocate an mbuf cluster submap.  Mbuf clusters
    450  1.8.2.2  yamt 	 * are allocated via the pool allocator, and we use KSEG to
    451  1.8.2.2  yamt 	 * map those pages.)
    452  1.8.2.2  yamt 	 */
    453  1.8.2.2  yamt 
    454  1.8.2.2  yamt 	format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
    455  1.8.2.2  yamt 	printf("avail memory = %s\n", pbuf);
    456  1.8.2.2  yamt }
    457  1.8.2.2  yamt 
    458  1.8.2.2  yamt int	waittime = -1;
    459  1.8.2.2  yamt 
    460  1.8.2.2  yamt void
    461  1.8.2.2  yamt cpu_reboot(int howto, char *bootstr)
    462  1.8.2.2  yamt {
    463  1.8.2.2  yamt 
    464  1.8.2.2  yamt 	/* Take a snapshot before clobbering any registers. */
    465  1.8.2.2  yamt 	if (curproc)
    466  1.8.2.3  yamt 		savectx(curpcb);
    467  1.8.2.2  yamt 
    468  1.8.2.2  yamt 	if (cold) {
    469  1.8.2.2  yamt 		howto |= RB_HALT;
    470  1.8.2.2  yamt 		goto haltsys;
    471  1.8.2.2  yamt 	}
    472  1.8.2.2  yamt 
    473  1.8.2.2  yamt 	/* If "always halt" was specified as a boot flag, obey. */
    474  1.8.2.2  yamt 	if (boothowto & RB_HALT)
    475  1.8.2.2  yamt 		howto |= RB_HALT;
    476  1.8.2.2  yamt 
    477  1.8.2.2  yamt 	boothowto = howto;
    478  1.8.2.2  yamt 	if ((howto & RB_NOSYNC) == 0 && (waittime < 0)) {
    479  1.8.2.2  yamt 		waittime = 0;
    480  1.8.2.2  yamt 		vfs_shutdown();
    481  1.8.2.2  yamt 
    482  1.8.2.2  yamt 		/*
    483  1.8.2.2  yamt 		 * If we've been adjusting the clock, the todr
    484  1.8.2.2  yamt 		 * will be out of synch; adjust it now.
    485  1.8.2.2  yamt 		 */
    486  1.8.2.2  yamt 		resettodr();
    487  1.8.2.2  yamt 	}
    488  1.8.2.2  yamt 
    489  1.8.2.2  yamt 	splhigh();
    490  1.8.2.2  yamt 
    491  1.8.2.2  yamt 	if (howto & RB_DUMP)
    492  1.8.2.2  yamt 		dumpsys();
    493  1.8.2.2  yamt 
    494  1.8.2.2  yamt haltsys:
    495  1.8.2.2  yamt 	doshutdownhooks();
    496  1.8.2.2  yamt 
    497  1.8.2.2  yamt 	pmf_system_shutdown(boothowto);
    498  1.8.2.2  yamt 
    499  1.8.2.2  yamt 	if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
    500  1.8.2.2  yamt 		/*
    501  1.8.2.2  yamt 		 * Turning on GPIO1 as output will cause a powerdown.
    502  1.8.2.2  yamt 		 */
    503  1.8.2.2  yamt 		REGVAL(BONITO_GPIODATA) |= 2;
    504  1.8.2.2  yamt 		REGVAL(BONITO_GPIOIE) &= ~2;
    505  1.8.2.2  yamt 	}
    506  1.8.2.2  yamt 
    507  1.8.2.2  yamt 	if (howto & RB_HALT) {
    508  1.8.2.2  yamt 		printf("\n");
    509  1.8.2.2  yamt 		printf("The operating system has halted.\n");
    510  1.8.2.2  yamt 		printf("Please press any key to reboot.\n\n");
    511  1.8.2.2  yamt 		cnpollc(1);	/* For proper keyboard command handling */
    512  1.8.2.2  yamt 		cngetc();
    513  1.8.2.2  yamt 		cnpollc(0);
    514  1.8.2.2  yamt 	}
    515  1.8.2.2  yamt 
    516  1.8.2.2  yamt 	printf("%s\n\n", ((howto & RB_HALT) != 0) ? "halted." : "rebooting...");
    517  1.8.2.2  yamt 
    518  1.8.2.2  yamt 	/*
    519  1.8.2.2  yamt 	 * Turning off GPIO2 as output will cause a reset.
    520  1.8.2.2  yamt 	 */
    521  1.8.2.2  yamt 	REGVAL(BONITO_GPIODATA) &= ~4;
    522  1.8.2.2  yamt 	REGVAL(BONITO_GPIOIE) &= ~4;
    523  1.8.2.2  yamt 
    524  1.8.2.2  yamt 	__asm__ __volatile__ (
    525  1.8.2.2  yamt 		"\t.long 0x3c02bfc0\n"
    526  1.8.2.2  yamt 		"\t.long 0x00400008\n"
    527  1.8.2.2  yamt 	    ::: "v0");
    528  1.8.2.2  yamt }
    529