Home | History | Annotate | Line # | Download | only in malta
machdep.c revision 1.3
      1  1.3  simonb /*	$NetBSD: machdep.c,v 1.3 2002/04/09 03:38:28 simonb Exp $	*/
      2  1.1  simonb 
      3  1.1  simonb /*
      4  1.1  simonb  * Copyright 2001, 2002 Wasabi Systems, Inc.
      5  1.1  simonb  * All rights reserved.
      6  1.1  simonb  *
      7  1.1  simonb  * Written by Jason R. Thorpe and Simon Burge for Wasabi Systems, Inc.
      8  1.1  simonb  *
      9  1.1  simonb  * Redistribution and use in source and binary forms, with or without
     10  1.1  simonb  * modification, are permitted provided that the following conditions
     11  1.1  simonb  * are met:
     12  1.1  simonb  * 1. Redistributions of source code must retain the above copyright
     13  1.1  simonb  *    notice, this list of conditions and the following disclaimer.
     14  1.1  simonb  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1  simonb  *    notice, this list of conditions and the following disclaimer in the
     16  1.1  simonb  *    documentation and/or other materials provided with the distribution.
     17  1.1  simonb  * 3. All advertising materials mentioning features or use of this software
     18  1.1  simonb  *    must display the following acknowledgement:
     19  1.1  simonb  *      This product includes software developed for the NetBSD Project by
     20  1.1  simonb  *      Wasabi Systems, Inc.
     21  1.1  simonb  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  1.1  simonb  *    or promote products derived from this software without specific prior
     23  1.1  simonb  *    written permission.
     24  1.1  simonb  *
     25  1.1  simonb  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  1.1  simonb  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.1  simonb  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.1  simonb  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  1.1  simonb  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.1  simonb  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.1  simonb  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.1  simonb  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.1  simonb  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.1  simonb  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.1  simonb  * POSSIBILITY OF SUCH DAMAGE.
     36  1.1  simonb  */
     37  1.1  simonb 
     38  1.1  simonb /*
     39  1.1  simonb  * Copyright (c) 1988 University of Utah.
     40  1.1  simonb  * Copyright (c) 1992, 1993
     41  1.1  simonb  *	The Regents of the University of California.  All rights reserved.
     42  1.1  simonb  *
     43  1.1  simonb  * This code is derived from software contributed to Berkeley by
     44  1.1  simonb  * the Systems Programming Group of the University of Utah Computer
     45  1.1  simonb  * Science Department, The Mach Operating System project at
     46  1.1  simonb  * Carnegie-Mellon University and Ralph Campbell.
     47  1.1  simonb  *
     48  1.1  simonb  * Redistribution and use in source and binary forms, with or without
     49  1.1  simonb  * modification, are permitted provided that the following conditions
     50  1.1  simonb  * are met:
     51  1.1  simonb  * 1. Redistributions of source code must retain the above copyright
     52  1.1  simonb  *    notice, this list of conditions and the following disclaimer.
     53  1.1  simonb  * 2. Redistributions in binary form must reproduce the above copyright
     54  1.1  simonb  *    notice, this list of conditions and the following disclaimer in the
     55  1.1  simonb  *    documentation and/or other materials provided with the distribution.
     56  1.1  simonb  * 3. All advertising materials mentioning features or use of this software
     57  1.1  simonb  *    must display the following acknowledgement:
     58  1.1  simonb  *	This product includes software developed by the University of
     59  1.1  simonb  *	California, Berkeley and its contributors.
     60  1.1  simonb  * 4. Neither the name of the University nor the names of its contributors
     61  1.1  simonb  *    may be used to endorse or promote products derived from this software
     62  1.1  simonb  *    without specific prior written permission.
     63  1.1  simonb  *
     64  1.1  simonb  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     65  1.1  simonb  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     66  1.1  simonb  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     67  1.1  simonb  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     68  1.1  simonb  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     69  1.1  simonb  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     70  1.1  simonb  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     71  1.1  simonb  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     72  1.1  simonb  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     73  1.1  simonb  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     74  1.1  simonb  * SUCH DAMAGE.
     75  1.1  simonb  *
     76  1.1  simonb  *	@(#)machdep.c   8.3 (Berkeley) 1/12/94
     77  1.1  simonb  *	from: Utah Hdr: machdep.c 1.63 91/04/24
     78  1.1  simonb  */
     79  1.1  simonb 
     80  1.1  simonb #include "opt_ddb.h"
     81  1.1  simonb #include "opt_execfmt.h"
     82  1.1  simonb 
     83  1.1  simonb #include <sys/param.h>
     84  1.1  simonb #include <sys/systm.h>
     85  1.1  simonb #include <sys/kernel.h>
     86  1.1  simonb #include <sys/buf.h>
     87  1.1  simonb #include <sys/reboot.h>
     88  1.1  simonb #include <sys/user.h>
     89  1.1  simonb #include <sys/mount.h>
     90  1.1  simonb #include <sys/kcore.h>
     91  1.1  simonb #include <sys/boot_flag.h>
     92  1.1  simonb #include <sys/sysctl.h>
     93  1.1  simonb #include <sys/termios.h>
     94  1.1  simonb 
     95  1.1  simonb #include <uvm/uvm_extern.h>
     96  1.1  simonb 
     97  1.1  simonb #include <dev/cons.h>
     98  1.1  simonb 
     99  1.1  simonb #ifdef DDB
    100  1.1  simonb #include <machine/db_machdep.h>
    101  1.1  simonb #include <ddb/db_extern.h>
    102  1.1  simonb #endif
    103  1.1  simonb 
    104  1.1  simonb #include <machine/cpu.h>
    105  1.1  simonb #include <machine/psl.h>
    106  1.1  simonb #include <machine/yamon.h>
    107  1.1  simonb 
    108  1.1  simonb #include <evbmips/malta/autoconf.h>
    109  1.1  simonb #include <evbmips/malta/maltareg.h>
    110  1.1  simonb #include <evbmips/malta/maltavar.h>
    111  1.1  simonb 
    112  1.1  simonb #include "com.h"
    113  1.1  simonb #if NCOM > 0
    114  1.1  simonb #include <dev/ic/comreg.h>
    115  1.1  simonb #include <dev/ic/comvar.h>
    116  1.1  simonb 
    117  1.1  simonb int	comcnrate = 38400;	/* XXX should be config option */
    118  1.1  simonb #endif /* NCOM > 0 */
    119  1.1  simonb 
    120  1.1  simonb 
    121  1.1  simonb #define REGVAL(x)       *((__volatile u_int32_t *)(MIPS_PHYS_TO_KSEG1((x))))
    122  1.1  simonb 
    123  1.1  simonb struct malta_config malta_configuration;
    124  1.1  simonb 
    125  1.1  simonb /* For sysctl. */
    126  1.1  simonb char machine[] = MACHINE;
    127  1.1  simonb char machine_arch[] = MACHINE_ARCH;
    128  1.1  simonb char cpu_model[] = "MIPS Malta Evaluation Board";
    129  1.1  simonb 
    130  1.1  simonb /* Our exported CPU info; we can have only one. */
    131  1.1  simonb struct cpu_info cpu_info_store;
    132  1.1  simonb 
    133  1.1  simonb /* Maps for VM objects. */
    134  1.1  simonb struct vm_map *exec_map = NULL;
    135  1.1  simonb struct vm_map *mb_map = NULL;
    136  1.1  simonb struct vm_map *phys_map = NULL;
    137  1.1  simonb 
    138  1.1  simonb int	physmem;		/* Total physical memory */
    139  1.1  simonb 
    140  1.1  simonb int	netboot;		/* Are we netbooting? */
    141  1.1  simonb 
    142  1.1  simonb yamon_env_var *yamon_envp;
    143  1.1  simonb 
    144  1.1  simonb phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];
    145  1.1  simonb int mem_cluster_cnt;
    146  1.1  simonb 
    147  1.1  simonb void	configure(void);
    148  1.1  simonb void	mach_init(int, char **, yamon_env_var *, u_long);
    149  1.1  simonb 
    150  1.1  simonb /*
    151  1.1  simonb  * safepri is a safe priority for sleep to set for a spin-wait during
    152  1.1  simonb  * autoconfiguration or after a panic.  Used as an argument to splx().
    153  1.1  simonb  */
    154  1.1  simonb int	safepri = MIPS1_PSL_LOWIPL;
    155  1.1  simonb 
    156  1.1  simonb extern struct user *proc0paddr;
    157  1.1  simonb 
    158  1.1  simonb /*
    159  1.1  simonb  * Do all the stuff that locore normally does before calling main().
    160  1.1  simonb  */
    161  1.1  simonb void
    162  1.1  simonb mach_init(int argc, char **argv, yamon_env_var *envp, u_long memsize)
    163  1.1  simonb {
    164  1.1  simonb 	struct malta_config *mcp = &malta_configuration;
    165  1.1  simonb 	bus_space_handle_t sh;
    166  1.1  simonb 	caddr_t kernend, v;
    167  1.1  simonb         u_long first, last;
    168  1.1  simonb 	vsize_t size;
    169  1.1  simonb 	char *cp;
    170  1.1  simonb 	int i, howto;
    171  1.1  simonb 	uint8_t *brkres = (uint8_t *)MIPS_PHYS_TO_KSEG1(MALTA_BRKRES);
    172  1.1  simonb 
    173  1.1  simonb 	extern char edata[], end[];
    174  1.1  simonb 
    175  1.1  simonb 	*brkres = 0;	/* Disable BREAK==reset on console */
    176  1.1  simonb 
    177  1.1  simonb 	/* Get the propaganda in early! */
    178  1.1  simonb 	led_display_str("NetBSD");
    179  1.1  simonb 
    180  1.1  simonb 	/*
    181  1.1  simonb 	 * Clear the BSS segment.
    182  1.1  simonb 	 */
    183  1.1  simonb 	kernend = (caddr_t)mips_round_page(end);
    184  1.1  simonb 	memset(edata, 0, kernend - edata);
    185  1.1  simonb 
    186  1.1  simonb 	/* save the yamon environment pointer */
    187  1.1  simonb 	yamon_envp = envp;
    188  1.1  simonb 
    189  1.1  simonb 	/* Use YAMON callbacks for early console I/O */
    190  1.1  simonb 	cn_tab = &yamon_promcd;
    191  1.1  simonb 
    192  1.2  simonb 	/*
    193  1.2  simonb 	 * Set up the exception vectors and cpu-specific function
    194  1.2  simonb 	 * vectors early on.  We need the wbflush() vector set up
    195  1.2  simonb 	 * before comcnattach() is called (or at least before the
    196  1.2  simonb 	 * first printf() after that is called).
    197  1.2  simonb 	 * Also clears the I+D caches.
    198  1.2  simonb 	 */
    199  1.2  simonb 	mips_vector_init();
    200  1.2  simonb 
    201  1.1  simonb 	uvm_setpagesize();
    202  1.1  simonb 
    203  1.1  simonb 	physmem = btoc(memsize);
    204  1.1  simonb 
    205  1.1  simonb 	gt_pci_init(&mcp->mc_pc, &mcp->mc_gt);
    206  1.1  simonb 	malta_bus_io_init(&mcp->mc_iot, mcp);
    207  1.1  simonb 	malta_bus_mem_init(&mcp->mc_memt, mcp);
    208  1.1  simonb 	malta_dma_init(mcp);
    209  1.1  simonb 
    210  1.3  simonb 	/*
    211  1.3  simonb 	 * Calibrate the timer, delay() relies on this.
    212  1.3  simonb 	 */
    213  1.3  simonb 	bus_space_map(&mcp->mc_iot, MALTA_RTCADR, 2, 0, &sh);
    214  1.3  simonb 	malta_cal_timer(&mcp->mc_iot, sh);
    215  1.3  simonb 	bus_space_unmap(&mcp->mc_iot, sh, 2);
    216  1.3  simonb 
    217  1.3  simonb 
    218  1.1  simonb #if NCOM > 0
    219  1.1  simonb 	/*
    220  1.1  simonb 	 * Delay to allow firmware putchars to complete.
    221  1.1  simonb 	 * FIFO depth * character time.
    222  1.1  simonb 	 * character time = (1000000 / (defaultrate / 10))
    223  1.1  simonb 	 */
    224  1.3  simonb 	delay(160000000 / comcnrate);
    225  1.3  simonb 	if (comcnattach(&mcp->mc_iot, MALTA_UART0ADR, comcnrate, COM_FREQ,
    226  1.1  simonb 	    (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8) != 0)
    227  1.1  simonb 		panic("malta: unable to initialize serial console");
    228  1.1  simonb #else
    229  1.1  simonb 	panic("malta: not configured to use serial console");
    230  1.1  simonb #endif /* NCOM > 0 */
    231  1.1  simonb 
    232  1.1  simonb 	consinit();
    233  1.1  simonb 
    234  1.1  simonb 	mem_clusters[0].start = 0;
    235  1.1  simonb 	mem_clusters[0].size = ctob(physmem);
    236  1.1  simonb 	mem_cluster_cnt = 1;
    237  1.1  simonb 
    238  1.1  simonb 	/*
    239  1.1  simonb 	 * XXX: check argv[0] - do something if "gdb"???
    240  1.1  simonb 	 */
    241  1.1  simonb 
    242  1.1  simonb 	/*
    243  1.1  simonb 	 * Look at arguments passed to us and compute boothowto.
    244  1.1  simonb 	 */
    245  1.1  simonb 	boothowto = RB_AUTOBOOT;
    246  1.1  simonb 	for (i = 1; i < argc; i++) {
    247  1.1  simonb 		for (cp = argv[i]; *cp; cp++) {
    248  1.1  simonb 			/* Ignore superfluous '-', if there is one */
    249  1.1  simonb 			if (*cp == '-')
    250  1.1  simonb 				continue;
    251  1.1  simonb 
    252  1.1  simonb 			howto = 0;
    253  1.1  simonb 			BOOT_FLAG(*cp, howto);
    254  1.1  simonb 			if (! howto)
    255  1.1  simonb 				printf("bootflag '%c' not recognised\n", *cp);
    256  1.1  simonb 			else
    257  1.1  simonb 				boothowto |= howto;
    258  1.1  simonb 		}
    259  1.1  simonb 	}
    260  1.1  simonb 
    261  1.1  simonb 	/*
    262  1.1  simonb 	 * Load the rest of the available pages into the VM system.
    263  1.1  simonb 	 */
    264  1.1  simonb 	first = round_page(MIPS_KSEG0_TO_PHYS(kernend));
    265  1.1  simonb 	last = mem_clusters[0].start + mem_clusters[0].size;
    266  1.1  simonb 	uvm_page_physload(atop(first), atop(last), atop(first), atop(last),
    267  1.1  simonb 		VM_FREELIST_DEFAULT);
    268  1.1  simonb 
    269  1.1  simonb 	/*
    270  1.1  simonb 	 * Initialize error message buffer (at end of core).
    271  1.1  simonb 	 */
    272  1.1  simonb 	mips_init_msgbuf();
    273  1.1  simonb 
    274  1.1  simonb 	/*
    275  1.1  simonb 	 * Compute the size of system data structures.  pmap_bootstrap()
    276  1.1  simonb 	 * needs some of this information.
    277  1.1  simonb 	 */
    278  1.1  simonb 	size = (vsize_t)allocsys(NULL, NULL);
    279  1.1  simonb 
    280  1.1  simonb 	pmap_bootstrap();
    281  1.1  simonb 
    282  1.1  simonb 	/*
    283  1.1  simonb 	 * Allocate space for proc0's USPACE.
    284  1.1  simonb 	 */
    285  1.1  simonb 	v = (caddr_t)uvm_pageboot_alloc(USPACE);
    286  1.1  simonb 	proc0.p_addr = proc0paddr = (struct user *)v;
    287  1.1  simonb 	proc0.p_md.md_regs = (struct frame *)(v + USPACE) - 1;
    288  1.1  simonb 	curpcb = &proc0.p_addr->u_pcb;
    289  1.1  simonb 	curpcb->pcb_context[11] = MIPS_INT_MASK | MIPS_SR_INT_IE; /* SR */
    290  1.1  simonb 
    291  1.1  simonb 	/*
    292  1.1  simonb 	 * Allocate space for system data structures.  These data structures
    293  1.1  simonb 	 * are allocated here instead of cpu_startup() because physical
    294  1.1  simonb 	 * memory is directly addressable.  We don't have to map these into
    295  1.1  simonb 	 * virtual address space.
    296  1.1  simonb 	 */
    297  1.1  simonb 	v = (caddr_t)uvm_pageboot_alloc(size);
    298  1.1  simonb 	if ((allocsys(v, NULL) - v) != size)
    299  1.1  simonb 		panic("mach_init: table size inconsistency");
    300  1.1  simonb 
    301  1.1  simonb 	/*
    302  1.1  simonb 	 * Initialize debuggers, and break into them, if appropriate.
    303  1.1  simonb 	 */
    304  1.1  simonb #ifdef DDB
    305  1.1  simonb 	ddb_init(0, 0, 0);
    306  1.1  simonb #endif
    307  1.1  simonb 
    308  1.1  simonb 	if (boothowto & RB_KDB)
    309  1.1  simonb #if defined(DDB)
    310  1.1  simonb 		Debugger();
    311  1.1  simonb #endif
    312  1.1  simonb }
    313  1.1  simonb 
    314  1.1  simonb void
    315  1.1  simonb consinit(void)
    316  1.1  simonb {
    317  1.1  simonb 
    318  1.1  simonb 	/*
    319  1.1  simonb 	 * Everything related to console initialization is done
    320  1.1  simonb 	 * in mach_init().
    321  1.1  simonb 	 */
    322  1.1  simonb }
    323  1.1  simonb 
    324  1.1  simonb /*
    325  1.1  simonb  * Allocate memory for variable-sized tables,
    326  1.1  simonb  */
    327  1.1  simonb void
    328  1.1  simonb cpu_startup()
    329  1.1  simonb {
    330  1.1  simonb 	unsigned i;
    331  1.1  simonb 	int base, residual;
    332  1.1  simonb 	vaddr_t minaddr, maxaddr;
    333  1.1  simonb 	vsize_t size;
    334  1.1  simonb 	char pbuf[9];
    335  1.1  simonb 
    336  1.1  simonb 	/*
    337  1.1  simonb 	 * Good {morning,afternoon,evening,night}.
    338  1.1  simonb 	 */
    339  1.1  simonb 	printf(version);
    340  1.1  simonb 	format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
    341  1.1  simonb 	printf("%s memory", pbuf);
    342  1.1  simonb 
    343  1.1  simonb 	/*
    344  1.1  simonb 	 * Virtual memory is bootstrapped -- notify the bus spaces
    345  1.1  simonb 	 * that memory allocation is now safe.
    346  1.1  simonb 	 */
    347  1.1  simonb 	malta_configuration.mc_mallocsafe = 1;
    348  1.1  simonb 
    349  1.1  simonb 	/*
    350  1.1  simonb 	 * Allocate virtual address space for file I/O buffers.
    351  1.1  simonb 	 * Note they are different than the array of headers, 'buf',
    352  1.1  simonb 	 * and usually occupy more virtual memory than physical.
    353  1.1  simonb 	 */
    354  1.1  simonb 	size = MAXBSIZE * nbuf;
    355  1.1  simonb 	if (uvm_map(kernel_map, (vaddr_t *)&buffers, round_page(size),
    356  1.1  simonb 		    NULL, UVM_UNKNOWN_OFFSET, 0,
    357  1.1  simonb 		    UVM_MAPFLAG(UVM_PROT_NONE, UVM_PROT_NONE, UVM_INH_NONE,
    358  1.1  simonb 		    UVM_ADV_NORMAL, 0)) != 0)
    359  1.1  simonb 		panic("startup: cannot allocate VM for buffers");
    360  1.1  simonb 	minaddr = (vaddr_t)buffers;
    361  1.1  simonb 	base = bufpages / nbuf;
    362  1.1  simonb 	residual = bufpages % nbuf;
    363  1.1  simonb 	for (i = 0; i < nbuf; i++) {
    364  1.1  simonb 		vsize_t curbufsize;
    365  1.1  simonb 		vaddr_t curbuf;
    366  1.1  simonb 		struct vm_page *pg;
    367  1.1  simonb 
    368  1.1  simonb 		/*
    369  1.1  simonb 		 * Each buffer has MAXBSIZE bytes of VM space allocated.  Of
    370  1.1  simonb 		 * that MAXBSIZE space, we allocate and map (base+1) pages
    371  1.1  simonb 		 * for the first "residual" buffers, and then we allocate
    372  1.1  simonb 		 * "base" pages for the rest.
    373  1.1  simonb 		 */
    374  1.1  simonb 		curbuf = (vaddr_t) buffers + (i * MAXBSIZE);
    375  1.1  simonb 		curbufsize = NBPG * ((i < residual) ? (base + 1) : base);
    376  1.1  simonb 
    377  1.1  simonb 		while (curbufsize) {
    378  1.1  simonb 			pg = uvm_pagealloc(NULL, 0, NULL, 0);
    379  1.1  simonb 			if (pg == NULL)
    380  1.1  simonb 				panic("cpu_startup: not enough memory for "
    381  1.1  simonb 					"buffer cache");
    382  1.1  simonb 			pmap_kenter_pa(curbuf, VM_PAGE_TO_PHYS(pg),
    383  1.1  simonb 				       VM_PROT_READ|VM_PROT_WRITE);
    384  1.1  simonb 			curbuf += PAGE_SIZE;
    385  1.1  simonb 			curbufsize -= PAGE_SIZE;
    386  1.1  simonb 		}
    387  1.1  simonb 	}
    388  1.1  simonb 	pmap_update(pmap_kernel());
    389  1.1  simonb 
    390  1.1  simonb 	/*
    391  1.1  simonb 	 * Allocate a submap for exec arguments.  This map effectively
    392  1.1  simonb 	 * limits the number of processes exec'ing at any time.
    393  1.1  simonb 	 */
    394  1.1  simonb 	exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    395  1.1  simonb 				    16 * NCARGS, VM_MAP_PAGEABLE, FALSE, NULL);
    396  1.1  simonb 	/*
    397  1.1  simonb 	 * Allocate a submap for physio.
    398  1.1  simonb 	 */
    399  1.1  simonb 	phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    400  1.1  simonb 				    VM_PHYS_SIZE, 0, FALSE, NULL);
    401  1.1  simonb 
    402  1.1  simonb 	/*
    403  1.1  simonb 	 * (No need to allocate an mbuf cluster submap.  Mbuf clusters
    404  1.1  simonb 	 * are allocated via the pool allocator, and we use KSEG to
    405  1.1  simonb 	 * map those pages.)
    406  1.1  simonb 	 */
    407  1.1  simonb 
    408  1.1  simonb 	format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
    409  1.1  simonb 	printf(", %s free", pbuf);
    410  1.1  simonb 	format_bytes(pbuf, sizeof(pbuf), bufpages * NBPG);
    411  1.1  simonb 	printf(", %s in %d buffers\n", pbuf, nbuf);
    412  1.1  simonb 
    413  1.1  simonb 	/*
    414  1.1  simonb 	 * Set up buffers, so they can be used to read disk labels.
    415  1.1  simonb 	 */
    416  1.1  simonb 	bufinit();
    417  1.1  simonb }
    418  1.1  simonb 
    419  1.1  simonb int
    420  1.1  simonb cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
    421  1.1  simonb 	int *name;
    422  1.1  simonb 	u_int namelen;
    423  1.1  simonb 	void *oldp;
    424  1.1  simonb 	size_t *oldlenp;
    425  1.1  simonb 	void *newp;
    426  1.1  simonb 	size_t newlen;
    427  1.1  simonb 	struct proc *p;
    428  1.1  simonb {
    429  1.1  simonb 	/* All sysctl names at this level are terminal. */
    430  1.1  simonb 	if (namelen != 1)
    431  1.1  simonb 		return ENOTDIR;
    432  1.1  simonb 
    433  1.1  simonb 	switch (name[0]) {
    434  1.1  simonb 	default:
    435  1.1  simonb 		return EOPNOTSUPP;
    436  1.1  simonb 	}
    437  1.1  simonb }
    438  1.1  simonb 
    439  1.1  simonb int	waittime = -1;
    440  1.1  simonb 
    441  1.1  simonb void
    442  1.1  simonb cpu_reboot(howto, bootstr)
    443  1.1  simonb 	int howto;
    444  1.1  simonb 	char *bootstr;
    445  1.1  simonb {
    446  1.1  simonb 
    447  1.1  simonb 	/* Take a snapshot before clobbering any registers. */
    448  1.1  simonb 	if (curproc)
    449  1.1  simonb 		savectx((struct user *)curpcb);
    450  1.1  simonb 
    451  1.1  simonb 	if (cold) {
    452  1.1  simonb 		howto |= RB_HALT;
    453  1.1  simonb 		goto haltsys;
    454  1.1  simonb 	}
    455  1.1  simonb 
    456  1.1  simonb 	/* If "always halt" was specified as a boot flag, obey. */
    457  1.1  simonb 	if (boothowto & RB_HALT)
    458  1.1  simonb 		howto |= RB_HALT;
    459  1.1  simonb 
    460  1.1  simonb 	boothowto = howto;
    461  1.1  simonb 	if ((howto & RB_NOSYNC) == 0 && (waittime < 0)) {
    462  1.1  simonb 		waittime = 0;
    463  1.1  simonb 		vfs_shutdown();
    464  1.1  simonb 
    465  1.1  simonb 		/*
    466  1.1  simonb 		 * If we've been adjusting the clock, the todr
    467  1.1  simonb 		 * will be out of synch; adjust it now.
    468  1.1  simonb 		 */
    469  1.1  simonb 		resettodr();
    470  1.1  simonb 	}
    471  1.1  simonb 
    472  1.1  simonb 	splhigh();
    473  1.1  simonb 
    474  1.1  simonb 	if (howto & RB_DUMP)
    475  1.1  simonb 		dumpsys();
    476  1.1  simonb 
    477  1.1  simonb haltsys:
    478  1.1  simonb 	doshutdownhooks();
    479  1.1  simonb 
    480  1.1  simonb 	if (howto & RB_HALT) {
    481  1.1  simonb 		printf("\n");
    482  1.1  simonb 		printf("The operating system has halted.\n");
    483  1.1  simonb 		printf("Please press any key to reboot.\n\n");
    484  1.1  simonb 		cnpollc(1);	/* For proper keyboard command handling */
    485  1.1  simonb 		cngetc();
    486  1.1  simonb 		cnpollc(0);
    487  1.1  simonb 	}
    488  1.1  simonb 
    489  1.1  simonb 	printf("%s\n\n", ((howto & RB_HALT) != 0) ? "halted." : "rebooting...");
    490  1.1  simonb 	yamon_exit(boothowto);
    491  1.1  simonb 	printf("Oops, back from yamon_exit()\n\nResetting...");
    492  1.1  simonb 
    493  1.1  simonb 	REGVAL(MALTA_SOFTRES) = MALTA_GORESET;
    494  1.1  simonb 
    495  1.1  simonb 	/*
    496  1.1  simonb 	 * Need a small delay here, otherwise we see the first few characters of
    497  1.1  simonb 	 * the warning below.
    498  1.1  simonb 	 */
    499  1.1  simonb 	delay(80000);
    500  1.1  simonb 
    501  1.1  simonb 	printf("WARNING: reset failed!\nSpinning...");
    502  1.1  simonb 
    503  1.1  simonb 	for (;;)
    504  1.1  simonb 		/* spin forever */ ;	/* XXX */
    505  1.1  simonb }
    506