Home | History | Annotate | Line # | Download | only in adm5120
machdep.c revision 1.14
      1  1.14    matt /* $NetBSD: machdep.c,v 1.14 2009/12/14 00:46:00 matt Exp $ */
      2   1.1  dyoung 
      3   1.1  dyoung /*-
      4   1.1  dyoung  * Copyright (c) 2007 Ruslan Ermilov and Vsevolod Lobko.
      5   1.1  dyoung  * All rights reserved.
      6   1.1  dyoung  *
      7   1.1  dyoung  * Redistribution and use in source and binary forms, with or
      8   1.1  dyoung  * without modification, are permitted provided that the following
      9   1.1  dyoung  * conditions are met:
     10   1.1  dyoung  * 1. Redistributions of source code must retain the above copyright
     11   1.1  dyoung  *    notice, this list of conditions and the following disclaimer.
     12   1.1  dyoung  * 2. Redistributions in binary form must reproduce the above
     13   1.1  dyoung  *    copyright notice, this list of conditions and the following
     14   1.1  dyoung  *    disclaimer in the documentation and/or other materials provided
     15   1.1  dyoung  *    with the distribution.
     16   1.1  dyoung  * 3. The names of the authors may not be used to endorse or promote
     17   1.1  dyoung  *    products derived from this software without specific prior
     18   1.1  dyoung  *    written permission.
     19   1.1  dyoung  *
     20   1.1  dyoung  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY
     21   1.1  dyoung  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     22   1.1  dyoung  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
     23   1.1  dyoung  * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS
     24   1.1  dyoung  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
     25   1.1  dyoung  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     26   1.1  dyoung  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
     27   1.1  dyoung  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28   1.1  dyoung  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
     29   1.1  dyoung  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     30   1.1  dyoung  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
     31   1.1  dyoung  * OF SUCH DAMAGE.
     32   1.1  dyoung  */
     33   1.1  dyoung /*
     34   1.1  dyoung  * Copyright (c) 1992, 1993
     35   1.1  dyoung  *	The Regents of the University of California.  All rights reserved.
     36   1.1  dyoung  *
     37   1.1  dyoung  * This code is derived from software contributed to Berkeley by
     38   1.1  dyoung  * the Systems Programming Group of the University of Utah Computer
     39   1.1  dyoung  * Science Department, The Mach Operating System project at
     40   1.1  dyoung  * Carnegie-Mellon University and Ralph Campbell.
     41   1.1  dyoung  *
     42   1.1  dyoung  * Redistribution and use in source and binary forms, with or without
     43   1.1  dyoung  * modification, are permitted provided that the following conditions
     44   1.1  dyoung  * are met:
     45   1.1  dyoung  * 1. Redistributions of source code must retain the above copyright
     46   1.1  dyoung  *    notice, this list of conditions and the following disclaimer.
     47   1.1  dyoung  * 2. Redistributions in binary form must reproduce the above copyright
     48   1.1  dyoung  *    notice, this list of conditions and the following disclaimer in the
     49   1.1  dyoung  *    documentation and/or other materials provided with the distribution.
     50   1.1  dyoung  * 3. Neither the name of the University nor the names of its contributors
     51   1.1  dyoung  *    may be used to endorse or promote products derived from this software
     52   1.1  dyoung  *    without specific prior written permission.
     53   1.1  dyoung  *
     54   1.1  dyoung  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     55   1.1  dyoung  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     56   1.1  dyoung  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     57   1.1  dyoung  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     58   1.1  dyoung  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     59   1.1  dyoung  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     60   1.1  dyoung  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     61   1.1  dyoung  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     62   1.1  dyoung  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     63   1.1  dyoung  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     64   1.1  dyoung  * SUCH DAMAGE.
     65   1.1  dyoung  *
     66   1.1  dyoung  *	@(#)machdep.c	8.3 (Berkeley) 1/12/94
     67   1.1  dyoung  * 	from: Utah Hdr: machdep.c 1.63 91/04/24
     68   1.1  dyoung  */
     69   1.1  dyoung /*
     70   1.1  dyoung  * Copyright (c) 1988 University of Utah.
     71   1.1  dyoung  *
     72   1.1  dyoung  * This code is derived from software contributed to Berkeley by
     73   1.1  dyoung  * the Systems Programming Group of the University of Utah Computer
     74   1.1  dyoung  * Science Department, The Mach Operating System project at
     75   1.1  dyoung  * Carnegie-Mellon University and Ralph Campbell.
     76   1.1  dyoung  *
     77   1.1  dyoung  * Redistribution and use in source and binary forms, with or without
     78   1.1  dyoung  * modification, are permitted provided that the following conditions
     79   1.1  dyoung  * are met:
     80   1.1  dyoung  * 1. Redistributions of source code must retain the above copyright
     81   1.1  dyoung  *    notice, this list of conditions and the following disclaimer.
     82   1.1  dyoung  * 2. Redistributions in binary form must reproduce the above copyright
     83   1.1  dyoung  *    notice, this list of conditions and the following disclaimer in the
     84   1.1  dyoung  *    documentation and/or other materials provided with the distribution.
     85   1.1  dyoung  * 3. All advertising materials mentioning features or use of this software
     86   1.1  dyoung  *    must display the following acknowledgement:
     87   1.1  dyoung  *	This product includes software developed by the University of
     88   1.1  dyoung  *	California, Berkeley and its contributors.
     89   1.1  dyoung  * 4. Neither the name of the University nor the names of its contributors
     90   1.1  dyoung  *    may be used to endorse or promote products derived from this software
     91   1.1  dyoung  *    without specific prior written permission.
     92   1.1  dyoung  *
     93   1.1  dyoung  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     94   1.1  dyoung  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     95   1.1  dyoung  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     96   1.1  dyoung  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     97   1.1  dyoung  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     98   1.1  dyoung  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     99   1.1  dyoung  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    100   1.1  dyoung  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    101   1.1  dyoung  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    102   1.1  dyoung  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    103   1.1  dyoung  * SUCH DAMAGE.
    104   1.1  dyoung  *
    105   1.1  dyoung  *	@(#)machdep.c	8.3 (Berkeley) 1/12/94
    106   1.1  dyoung  * 	from: Utah Hdr: machdep.c 1.63 91/04/24
    107   1.1  dyoung  */
    108   1.1  dyoung 
    109   1.1  dyoung #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
    110  1.14    matt __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.14 2009/12/14 00:46:00 matt Exp $");
    111   1.1  dyoung 
    112   1.1  dyoung #include "opt_ddb.h"
    113   1.1  dyoung #include "opt_kgdb.h"
    114   1.1  dyoung 
    115   1.1  dyoung #include "opt_memsize.h"
    116  1.10     apb #include "opt_modular.h"
    117   1.1  dyoung #include "opt_ethaddr.h"
    118   1.1  dyoung 
    119   1.1  dyoung #include "opt_pci.h"
    120   1.1  dyoung #include "pci.h"
    121   1.1  dyoung 
    122   1.1  dyoung #include <sys/param.h>
    123   1.1  dyoung #include <sys/systm.h>
    124   1.1  dyoung #include <sys/kernel.h>
    125   1.1  dyoung #include <sys/buf.h>
    126   1.1  dyoung #include <sys/reboot.h>
    127   1.1  dyoung #include <sys/mount.h>
    128   1.1  dyoung #include <sys/kcore.h>
    129   1.1  dyoung #include <sys/boot_flag.h>
    130   1.1  dyoung #include <sys/termios.h>
    131   1.1  dyoung #include <sys/ksyms.h>
    132   1.7  dyoung #include <sys/device.h>
    133   1.1  dyoung 
    134   1.1  dyoung #include <net/if.h>
    135   1.1  dyoung #include <net/if_ether.h>
    136   1.1  dyoung 
    137   1.1  dyoung #include <uvm/uvm_extern.h>
    138   1.1  dyoung 
    139   1.1  dyoung #include <dev/cons.h>
    140   1.1  dyoung 
    141   1.1  dyoung #include "ksyms.h"
    142   1.1  dyoung 
    143   1.8      ad #if NKSYMS || defined(DDB) || defined(MODULAR)
    144   1.1  dyoung #include <machine/db_machdep.h>
    145   1.1  dyoung #include <ddb/db_extern.h>
    146   1.1  dyoung #endif
    147   1.1  dyoung 
    148   1.1  dyoung #include <mips/cache.h>
    149   1.1  dyoung #include <mips/locore.h>
    150   1.1  dyoung 
    151   1.1  dyoung #include <mips/adm5120/include/adm5120reg.h>
    152   1.1  dyoung #include <mips/adm5120/include/adm5120var.h>
    153   1.1  dyoung #include <mips/adm5120/include/adm5120_extiovar.h>
    154   1.1  dyoung #include <mips/adm5120/include/adm5120_obiovar.h>
    155   1.1  dyoung #include <mips/adm5120/include/adm5120_mainbusvar.h>
    156   1.1  dyoung #include <mips/adm5120/include/adm5120_pcivar.h>
    157   1.1  dyoung #include <mips/adm5120/dev/uart.h>
    158   1.1  dyoung 
    159   1.1  dyoung #ifndef	MEMSIZE
    160   1.1  dyoung #define	MEMSIZE 4 * 1024 * 1024
    161   1.1  dyoung #endif /* !MEMSIZE */
    162   1.1  dyoung 
    163   1.1  dyoung /* Our exported CPU info; we can have only one. */
    164   1.1  dyoung struct cpu_info cpu_info_store;
    165   1.1  dyoung 
    166   1.1  dyoung /* Maps for VM objects. */
    167   1.1  dyoung struct vm_map *mb_map = NULL;
    168   1.1  dyoung struct vm_map *phys_map = NULL;
    169   1.1  dyoung 
    170   1.1  dyoung int maxmem;			/* max memory per process */
    171   1.1  dyoung 
    172   1.1  dyoung int mem_cluster_cnt;
    173   1.1  dyoung phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];
    174   1.1  dyoung 
    175   1.1  dyoung struct adm5120_config adm5120_configuration;
    176   1.1  dyoung 
    177   1.1  dyoung void adm5120_setcpufreq(void);
    178   1.1  dyoung 
    179   1.1  dyoung void
    180   1.1  dyoung adm5120_setcpufreq(void)
    181   1.1  dyoung {
    182   1.1  dyoung 	uint32_t v, freq;
    183   1.1  dyoung 
    184   1.1  dyoung 	v = SW_READ(SW_CODE_REG);
    185   1.1  dyoung 	switch (v & CLKS_MASK) {
    186   1.1  dyoung 	case CLKS_175MHZ:
    187   1.1  dyoung 		freq = 175 * 1000 * 1000;
    188   1.1  dyoung 		break;
    189   1.1  dyoung 	case CLKS_200MHZ:
    190   1.1  dyoung 		freq = 200 * 1000 * 1000;
    191   1.1  dyoung 		break;
    192   1.1  dyoung 	default:
    193   1.1  dyoung 		panic("adm5120: cannot determine CPU clock speed");
    194   1.1  dyoung 	}
    195   1.1  dyoung 
    196   1.1  dyoung 	curcpu()->ci_cpu_freq = freq;
    197   1.1  dyoung 	curcpu()->ci_cycles_per_hz = (freq + hz / 2) / hz / 2;
    198   1.1  dyoung 	curcpu()->ci_divisor_delay = ((freq + 500000) / 1000000) / 2;
    199   1.1  dyoung }
    200   1.1  dyoung 
    201   1.1  dyoung void	mach_init(int, char **, void *, void *); /* XXX */
    202   1.1  dyoung 
    203   1.1  dyoung static void
    204   1.1  dyoung copy_args(int argc, char **argv)
    205   1.1  dyoung {
    206   1.1  dyoung 	struct adm5120_config *admc = &adm5120_configuration;
    207   1.1  dyoung 	int i;
    208   1.1  dyoung 	char *buf;
    209   1.1  dyoung 	size_t buflen, rc;
    210   1.1  dyoung 
    211   1.1  dyoung 	buf = admc->args;
    212   1.1  dyoung 	buflen = sizeof(admc->args);
    213   1.1  dyoung 
    214   1.1  dyoung 	if (argc >= __arraycount(admc->argv))
    215   1.1  dyoung 		panic("%s: too many boot args\n", __func__);
    216   1.1  dyoung 
    217   1.1  dyoung 	for (i = 0; buflen > 0 && i < argc && argv[i] != NULL; i++) {
    218   1.1  dyoung 		admc->argv[i] = buf;
    219   1.1  dyoung 		if ((rc = strlcpy(buf, argv[i], buflen)) >= buflen)
    220   1.1  dyoung 			panic("%s: boot args too long\n", __func__);
    221   1.1  dyoung 
    222   1.1  dyoung 		buf += rc;
    223   1.1  dyoung 		buflen -= rc;
    224   1.1  dyoung 		*buf++ = '\0';
    225   1.1  dyoung 		buflen--;
    226   1.1  dyoung 	}
    227   1.1  dyoung 	if (i < argc)
    228   1.1  dyoung 		panic("%s: boot args too long\n", __func__);
    229   1.1  dyoung 
    230   1.1  dyoung 	admc->argc = argc;
    231   1.1  dyoung }
    232   1.1  dyoung 
    233   1.1  dyoung static void
    234   1.1  dyoung parse_args(prop_dictionary_t properties, int argc, char **argv,
    235   1.1  dyoung     uint32_t *memsizep)
    236   1.1  dyoung {
    237   1.1  dyoung 	char buf[32];
    238   1.1  dyoung 	char *key, *val, *valend;
    239   1.1  dyoung 	unsigned long tmp;
    240   1.1  dyoung 	int i;
    241   1.1  dyoung 	uint8_t enaddr[ETHER_ADDR_LEN];
    242   1.1  dyoung 
    243   1.1  dyoung 	if (memsizep != NULL)
    244   1.1  dyoung 		*memsizep = MEMSIZE;
    245   1.1  dyoung 
    246   1.1  dyoung 	for (i = 0; i < argc && argv[i] != NULL; i++) {
    247   1.1  dyoung 		if (strlcpy(buf, argv[i], sizeof(buf)) >= sizeof(buf))
    248   1.1  dyoung 			goto err;
    249   1.1  dyoung 		val = buf;
    250   1.1  dyoung 		key = strsep(&val, "=");
    251   1.1  dyoung 		if (val == NULL)
    252   1.1  dyoung 			goto err;
    253   1.1  dyoung 		if (strcmp(key, "mem") == 0) {
    254   1.1  dyoung 			tmp = strtoul(val, &valend, 10);
    255   1.1  dyoung 			if (val == valend || *valend != 'M')
    256   1.1  dyoung 				goto err;
    257   1.1  dyoung 			if (memsizep != NULL)
    258   1.1  dyoung 				*memsizep = tmp * 1024 * 1024;
    259   1.1  dyoung 		} else if (strcmp(key, "HZ") == 0)
    260   1.1  dyoung 			;
    261   1.1  dyoung 		else if (strcmp(key, "gpio") == 0) {
    262   1.1  dyoung 			prop_number_t pn;
    263   1.1  dyoung 
    264   1.1  dyoung 			tmp = strtoul(val, &valend, 10);
    265   1.1  dyoung 			if (val == valend || *valend != '\0')
    266   1.1  dyoung 				goto err;
    267   1.1  dyoung 			if (properties == NULL)
    268   1.1  dyoung 				continue;
    269   1.1  dyoung 			pn = prop_number_create_unsigned_integer(tmp);
    270   1.1  dyoung 			if (pn == NULL) {
    271   1.1  dyoung 				printf(
    272   1.1  dyoung 				   "%s: prop_number_create_unsigned_integer\n",
    273   1.1  dyoung 				   __func__);
    274   1.1  dyoung 				continue;
    275   1.1  dyoung 			}
    276   1.1  dyoung 			if (!prop_dictionary_set(properties, "initial-gpio",
    277   1.1  dyoung 			    pn)) {
    278   1.1  dyoung 				printf("%s: prop_dictionary_set(gpio)\n",
    279   1.1  dyoung 				    __func__);
    280   1.1  dyoung 			}
    281   1.1  dyoung 			prop_object_release(pn);
    282   1.1  dyoung 		} else if (strcmp(key, "kmac") == 0) {
    283   1.1  dyoung 			prop_data_t pd;
    284   1.1  dyoung 
    285   1.1  dyoung 			ether_nonstatic_aton(enaddr, val);
    286   1.1  dyoung 			if (properties == NULL)
    287   1.1  dyoung 				continue;
    288   1.1  dyoung 			pd = prop_data_create_data(enaddr, sizeof(enaddr));
    289   1.1  dyoung 			if (pd == NULL) {
    290   1.1  dyoung 				printf("%s: prop_data_create_data\n", __func__);
    291   1.1  dyoung 				continue;
    292   1.1  dyoung 			}
    293   1.1  dyoung 			if (!prop_dictionary_set(properties, "mac-addr", pd)) {
    294   1.1  dyoung 				printf("%s: prop_dictionary_set(mac)\n",
    295   1.1  dyoung 				    __func__);
    296   1.1  dyoung 			}
    297   1.1  dyoung 			prop_object_release(pd);
    298   1.1  dyoung 		} else if (strcmp(key, "board") == 0)
    299   1.1  dyoung 			printf("Routerboard %s\n", val);
    300   1.1  dyoung 		else if (strcmp(key, "boot") == 0)
    301   1.1  dyoung 			;
    302   1.1  dyoung 		continue;
    303   1.1  dyoung 	err:
    304   1.1  dyoung 		printf("bad argv[%d] (%s)\n", i, argv[i]);
    305   1.1  dyoung 	}
    306   1.1  dyoung }
    307   1.1  dyoung 
    308   1.1  dyoung void
    309   1.1  dyoung mach_init(int argc, char **argv, void *a2, void *a3)
    310   1.1  dyoung {
    311   1.1  dyoung 	struct adm5120_config *admc = &adm5120_configuration;
    312  1.13   rmind 	struct pcb *pcb0;
    313   1.1  dyoung 	uint32_t memsize;
    314   1.1  dyoung 	vaddr_t kernend;
    315   1.1  dyoung 	u_long first, last;
    316   1.1  dyoung 	vaddr_t v;
    317   1.1  dyoung 
    318   1.1  dyoung 	extern char edata[], end[];	/* XXX */
    319   1.1  dyoung 
    320   1.1  dyoung 	/* clear the BSS segment */
    321   1.1  dyoung 	kernend = mips_round_page(end);
    322   1.1  dyoung 	memset(edata, 0, kernend - (vaddr_t)edata);
    323   1.1  dyoung 
    324   1.1  dyoung 	/* set CPU model info for sysctl_hw */
    325   1.1  dyoung 	strcpy(cpu_model, "Infineon ADM5120");
    326   1.1  dyoung 
    327   1.1  dyoung 	/*
    328   1.1  dyoung 	 * Set up the exception vectors and CPU-specific function
    329   1.1  dyoung 	 * vectors early on.  We need the wbflush() vector set up
    330   1.1  dyoung 	 * before comcnattach() is called (or at least before the
    331   1.1  dyoung 	 * first printf() after that is called).
    332   1.1  dyoung 	 * Sets up mips_cpu_flags that may be queried by other
    333   1.1  dyoung 	 * functions called during startup.
    334   1.1  dyoung 	 * Also clears the I+D caches.
    335   1.1  dyoung 	 */
    336   1.1  dyoung 	mips_vector_init();
    337   1.1  dyoung 
    338   1.1  dyoung 	/*
    339   1.1  dyoung 	 * Set the VM page size.
    340   1.1  dyoung 	 */
    341   1.1  dyoung 	uvm_setpagesize();
    342   1.1  dyoung 
    343   1.1  dyoung 	adm5120_setcpufreq();
    344   1.1  dyoung 
    345   1.1  dyoung 	/*
    346   1.1  dyoung 	 * Initialize bus space tags.
    347   1.1  dyoung 	 */
    348   1.1  dyoung 	obio_bus_mem_init(&admc->obio_space, admc);
    349   1.1  dyoung 	extio_bus_mem_init(&admc->extio_space, admc);
    350   1.1  dyoung #if NPCI > 0
    351   1.1  dyoung 	pciio_bus_mem_init(&admc->pciio_space, admc);
    352   1.1  dyoung 	pcimem_bus_mem_init(&admc->pcimem_space, admc);
    353   1.1  dyoung #endif
    354   1.1  dyoung 
    355   1.1  dyoung 	/*
    356   1.1  dyoung 	 * Initialize bus DMA tag.
    357   1.1  dyoung 	 */
    358   1.1  dyoung 	obio_dma_init(&admc->obio_dmat);
    359   1.1  dyoung 
    360   1.1  dyoung 	/*
    361   1.1  dyoung 	 * Attach serial console.
    362   1.1  dyoung 	 */
    363   1.1  dyoung 	uart_cnattach();
    364   1.1  dyoung 
    365   1.1  dyoung 	/*
    366   1.1  dyoung 	 * Look at arguments passed to us and compute boothowto.
    367   1.1  dyoung 	 */
    368   1.1  dyoung 	boothowto = RB_AUTOBOOT;
    369   1.1  dyoung #ifdef KADB
    370   1.1  dyoung 	boothowto |= RB_KDB;
    371   1.1  dyoung #endif
    372   1.1  dyoung 
    373   1.1  dyoung 	parse_args(NULL, argc, argv, &memsize);
    374   1.1  dyoung 
    375   1.1  dyoung 	/*
    376   1.1  dyoung 	 * Determine the memory size.
    377   1.1  dyoung 	 *
    378   1.1  dyoung 	 * Note: Reserve the first page!  That's where the trap
    379   1.1  dyoung 	 * vectors are located.
    380   1.1  dyoung 	 */
    381   1.1  dyoung 
    382   1.1  dyoung #if 0
    383   1.1  dyoung 	if (GET_MEMSIZE(memsize) == 0) {
    384   1.1  dyoung 		uint32_t val;
    385   1.1  dyoung 
    386   1.1  dyoung 		/* This does not seem to work... --dyoung */
    387   1.1  dyoung 		val = SW_READ(SW_MEMCONT_REG);
    388   1.1  dyoung 		printf("SW_MEMCONT_REG: 0x%08" PRIx32 "\n", val);
    389   1.1  dyoung 		switch (val & SDRAM_SIZE_MASK) {
    390   1.1  dyoung 		case SDRAM_SIZE_4MBYTES:
    391   1.1  dyoung 			memsize = 4 * 1024 * 1024;
    392   1.1  dyoung 			break;
    393   1.1  dyoung 		case SDRAM_SIZE_8MBYTES:
    394   1.1  dyoung 			memsize = 8 * 1024 * 1024;
    395   1.1  dyoung 			break;
    396   1.1  dyoung 		case SDRAM_SIZE_16MBYTES:
    397   1.1  dyoung 			memsize = 16 * 1024 * 1024;
    398   1.1  dyoung 			break;
    399   1.1  dyoung 		case SDRAM_SIZE_64MBYTES:
    400   1.1  dyoung 			memsize = 64 * 1024 * 1024;
    401   1.1  dyoung 			break;
    402   1.1  dyoung 		case SDRAM_SIZE_128MBYTES:
    403   1.1  dyoung 			memsize = 128 * 1024 * 1024;
    404   1.1  dyoung 			break;
    405   1.1  dyoung 		default:
    406   1.1  dyoung 			panic("adm5120: cannot determine memory size");
    407   1.1  dyoung 		}
    408   1.1  dyoung 	}
    409   1.1  dyoung #endif
    410   1.1  dyoung 
    411   1.1  dyoung 	physmem = btoc(memsize);
    412   1.1  dyoung 
    413   1.1  dyoung 	mem_clusters[mem_cluster_cnt].start = PAGE_SIZE;
    414   1.1  dyoung 	mem_clusters[mem_cluster_cnt].size =
    415   1.1  dyoung 	    memsize - mem_clusters[mem_cluster_cnt].start;
    416   1.1  dyoung 	mem_cluster_cnt++;
    417   1.1  dyoung 
    418   1.1  dyoung 	/*
    419   1.1  dyoung 	 * Load the rest of the available pages into the VM system.
    420   1.1  dyoung 	 */
    421   1.1  dyoung 	first = round_page(MIPS_KSEG0_TO_PHYS(kernend));
    422   1.1  dyoung 	last = mem_clusters[0].start + mem_clusters[0].size;
    423   1.1  dyoung 	uvm_page_physload(atop(first), atop(last), atop(first), atop(last),
    424   1.1  dyoung 	    VM_FREELIST_DEFAULT);
    425   1.1  dyoung 
    426   1.1  dyoung 	/*
    427   1.1  dyoung 	 * Initialize message buffer (at end of core).
    428   1.1  dyoung 	 */
    429   1.1  dyoung 	mips_init_msgbuf();
    430   1.1  dyoung 
    431   1.1  dyoung 	/*
    432   1.1  dyoung 	 * Initialize the virtual memory system.
    433   1.1  dyoung 	 */
    434   1.1  dyoung 	pmap_bootstrap();
    435   1.1  dyoung 
    436   1.1  dyoung 	/*
    437  1.13   rmind 	 * Allocate uarea page for lwp0 and set it.
    438   1.1  dyoung 	 */
    439  1.14    matt 	mips_init_lwp0_uarea();
    440   1.1  dyoung 
    441   1.1  dyoung 	/*
    442   1.1  dyoung 	 * Initialize debuggers, and break into them, if appropriate.
    443   1.1  dyoung 	 */
    444   1.1  dyoung #ifdef DDB
    445   1.1  dyoung 	if (boothowto & RB_KDB)
    446   1.1  dyoung 		Debugger();
    447   1.1  dyoung #endif
    448   1.1  dyoung 
    449   1.1  dyoung 	copy_args(argc, argv);
    450   1.1  dyoung }
    451   1.1  dyoung 
    452   1.1  dyoung void
    453   1.1  dyoung consinit(void)
    454   1.1  dyoung {
    455   1.1  dyoung 
    456   1.1  dyoung 	/*
    457   1.1  dyoung 	 * Everything related to console initialization is done
    458   1.1  dyoung 	 * in mach_init().
    459   1.1  dyoung 	 */
    460   1.1  dyoung }
    461   1.1  dyoung 
    462   1.1  dyoung void
    463   1.1  dyoung cpu_startup(void)
    464   1.1  dyoung {
    465   1.1  dyoung 	struct adm5120_config *admc = &adm5120_configuration;
    466   1.1  dyoung 	char pbuf[9];
    467   1.1  dyoung 	vaddr_t minaddr, maxaddr;
    468   1.1  dyoung #ifdef DEBUG
    469   1.1  dyoung 	extern int pmapdebug;		/* XXX */
    470   1.1  dyoung 	int opmapdebug = pmapdebug;
    471   1.1  dyoung 
    472   1.1  dyoung 	pmapdebug = 0;		/* Shut up pmap debug during bootstrap */
    473   1.1  dyoung #endif
    474   1.1  dyoung 
    475   1.1  dyoung 	if ((admc->properties = prop_dictionary_create()) == NULL)
    476   1.1  dyoung 		printf("%s: prop_dictionary_create\n", __func__);
    477   1.1  dyoung 	parse_args(admc->properties, admc->argc, admc->argv, NULL);
    478   1.1  dyoung 
    479   1.1  dyoung 	/*
    480   1.1  dyoung 	 * Good {morning,afternoon,evening,night}.
    481   1.1  dyoung 	 */
    482   1.1  dyoung 	printf("%s%s", copyright, version);
    483   1.1  dyoung 	printf("%s\n", cpu_model);
    484   1.1  dyoung 	format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
    485   1.1  dyoung 	printf("total memory = %s\n", pbuf);
    486   1.1  dyoung 
    487   1.1  dyoung 	minaddr = 0;
    488   1.1  dyoung 
    489   1.1  dyoung 	/*
    490   1.1  dyoung 	 * Allocate a submap for physio
    491   1.1  dyoung 	 */
    492   1.1  dyoung 	phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    493   1.1  dyoung 	    VM_PHYS_SIZE, 0, FALSE, NULL);
    494   1.1  dyoung 
    495   1.1  dyoung 	/*
    496   1.1  dyoung 	 * No need to allocate an mbuf cluster submap.  Mbuf clusters
    497   1.1  dyoung 	 * are allocated via the pool allocator, and we use KSEG to
    498   1.1  dyoung 	 * map those pages.
    499   1.1  dyoung 	 */
    500   1.1  dyoung 
    501   1.1  dyoung #ifdef DEBUG
    502   1.1  dyoung 	pmapdebug = opmapdebug;
    503   1.1  dyoung #endif
    504   1.1  dyoung 	format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
    505   1.1  dyoung 	printf("avail memory = %s\n", pbuf);
    506   1.1  dyoung }
    507   1.1  dyoung 
    508   1.1  dyoung void
    509   1.1  dyoung cpu_reboot(int howto, char *bootstr)
    510   1.1  dyoung {
    511   1.1  dyoung 	static int waittime = -1;
    512   1.1  dyoung 
    513   1.1  dyoung 	/* Take a snapshot before clobbering any registers. */
    514   1.1  dyoung 	if (curproc)
    515  1.13   rmind 		savectx(curpcb);
    516   1.1  dyoung 
    517   1.1  dyoung 	/* If "always halt" was specified as a boot flag, obey. */
    518   1.1  dyoung 	if (boothowto & RB_HALT)
    519   1.1  dyoung 		howto |= RB_HALT;
    520   1.1  dyoung 
    521   1.1  dyoung 	boothowto = howto;
    522   1.1  dyoung 
    523   1.1  dyoung 	/* If system is cold, just halt. */
    524   1.1  dyoung 	if (cold) {
    525   1.1  dyoung 		boothowto |= RB_HALT;
    526   1.1  dyoung 		goto haltsys;
    527   1.1  dyoung 	}
    528   1.1  dyoung 
    529   1.1  dyoung 	if ((boothowto & RB_NOSYNC) == 0 && waittime < 0) {
    530   1.1  dyoung 		waittime = 0;
    531   1.1  dyoung 
    532   1.1  dyoung 		/*
    533   1.1  dyoung 		 * Synchronize the disks....
    534   1.1  dyoung 		 */
    535   1.1  dyoung 		vfs_shutdown();
    536   1.1  dyoung 
    537   1.1  dyoung 		/*
    538   1.1  dyoung 		 * If we've been adjusting the clock, the todr
    539   1.1  dyoung 		 * will be out of synch; adjust it now.
    540   1.1  dyoung 		 */
    541   1.1  dyoung 		resettodr();
    542   1.1  dyoung 	}
    543   1.1  dyoung 
    544   1.1  dyoung 	/* Disable interrupts. */
    545   1.1  dyoung 	splhigh();
    546   1.1  dyoung 
    547   1.1  dyoung 	if (boothowto & RB_DUMP)
    548   1.1  dyoung 		dumpsys();
    549   1.1  dyoung 
    550   1.1  dyoung  haltsys:
    551   1.1  dyoung 	/* Run any shutdown hooks. */
    552   1.1  dyoung 	doshutdownhooks();
    553   1.1  dyoung 
    554   1.7  dyoung 	pmf_system_shutdown(boothowto);
    555   1.7  dyoung 
    556   1.1  dyoung 	/*
    557   1.1  dyoung 	 * Routerboard BIOS may autoboot, so "pseudo-halt".
    558   1.1  dyoung 	 */
    559   1.1  dyoung 	if (boothowto & RB_HALT) {
    560   1.1  dyoung 		printf("\n");
    561   1.1  dyoung 		printf("The operating system has halted.\n");
    562   1.1  dyoung 		printf("Please press any key to reboot.\n\n");
    563   1.1  dyoung 		cnpollc(1);	/* For proper keyboard command handling */
    564   1.1  dyoung 		cngetc();
    565   1.1  dyoung 		cnpollc(0);
    566   1.1  dyoung 	}
    567   1.1  dyoung 
    568   1.1  dyoung 	printf("reseting board...\n\n");
    569   1.1  dyoung 	mips_icache_sync_all();
    570   1.1  dyoung 	mips_dcache_wbinv_all();
    571   1.1  dyoung 	SW_WRITE(SW_SFTRES_REG, 0);			/* reset */
    572   1.1  dyoung 	for (;;)
    573   1.1  dyoung 		/* spin forever */ ;	/* XXX */
    574   1.1  dyoung 	/*NOTREACHED*/
    575   1.1  dyoung }
    576