Home | History | Annotate | Line # | Download | only in rmixl
machdep.c revision 1.1.2.12
      1  1.1.2.12  cliff /*	$NetBSD: machdep.c,v 1.1.2.12 2010/01/03 08:37:14 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.12  cliff __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.1.2.12 2010/01/03 08:37:14 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.6  cliff #include <sys/extent.h>
    136   1.1.2.6  cliff #include <sys/malloc.h>
    137   1.1.2.1  cliff 
    138   1.1.2.1  cliff #include <uvm/uvm_extern.h>
    139   1.1.2.1  cliff 
    140   1.1.2.1  cliff #include <dev/cons.h>
    141   1.1.2.1  cliff 
    142   1.1.2.1  cliff #include "ksyms.h"
    143   1.1.2.1  cliff 
    144   1.1.2.1  cliff #if NKSYMS || defined(DDB) || defined(LKM)
    145   1.1.2.1  cliff #include <machine/db_machdep.h>
    146   1.1.2.1  cliff #include <ddb/db_extern.h>
    147   1.1.2.1  cliff #endif
    148   1.1.2.1  cliff 
    149   1.1.2.1  cliff #include <machine/cpu.h>
    150   1.1.2.1  cliff #include <machine/psl.h>
    151   1.1.2.1  cliff 
    152   1.1.2.1  cliff #include "com.h"
    153   1.1.2.1  cliff #if NCOM == 0
    154   1.1.2.1  cliff #error no serial console
    155   1.1.2.1  cliff #endif
    156   1.1.2.1  cliff 
    157   1.1.2.1  cliff #include <dev/ic/comreg.h>
    158   1.1.2.1  cliff #include <dev/ic/comvar.h>
    159   1.1.2.1  cliff 
    160   1.1.2.1  cliff #include <mips/rmi/rmixl_comvar.h>
    161   1.1.2.1  cliff #include <mips/rmi/rmixlvar.h>
    162   1.1.2.1  cliff #include <mips/rmi/rmixl_firmware.h>
    163   1.1.2.1  cliff #include <mips/rmi/rmixlreg.h>
    164   1.1.2.1  cliff 
    165   1.1.2.6  cliff #ifdef MACHDEP_DEBUG
    166   1.1.2.6  cliff int machdep_debug=MACHDEP_DEBUG;
    167   1.1.2.6  cliff # define DPRINTF(x)	do { if (machdep_debug) printf x ; } while(0)
    168   1.1.2.6  cliff #else
    169   1.1.2.6  cliff # define DPRINTF(x)
    170   1.1.2.6  cliff #endif
    171   1.1.2.6  cliff 
    172   1.1.2.4  cliff #ifndef CONSFREQ
    173  1.1.2.10  cliff # define CONSFREQ 66000000
    174   1.1.2.4  cliff #endif
    175   1.1.2.1  cliff #ifndef CONSPEED
    176   1.1.2.1  cliff # define CONSPEED 38400
    177   1.1.2.1  cliff #endif
    178   1.1.2.1  cliff #ifndef CONMODE
    179   1.1.2.1  cliff # define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8)
    180   1.1.2.1  cliff #endif
    181   1.1.2.1  cliff #ifndef CONSADDR
    182   1.1.2.1  cliff # define CONSADDR RMIXL_IO_DEV_UART_1
    183   1.1.2.1  cliff #endif
    184   1.1.2.1  cliff 
    185   1.1.2.4  cliff int		comcnfreq  = CONSFREQ;
    186   1.1.2.4  cliff int		comcnspeed = CONSPEED;
    187   1.1.2.4  cliff tcflag_t	comcnmode  = CONMODE;
    188   1.1.2.1  cliff bus_addr_t	comcnaddr  = (bus_addr_t)CONSADDR;
    189   1.1.2.1  cliff 
    190   1.1.2.1  cliff struct rmixl_config rmixl_configuration;
    191   1.1.2.1  cliff 
    192   1.1.2.1  cliff 
    193   1.1.2.1  cliff /*
    194   1.1.2.1  cliff  * array of tested firmware versions
    195   1.1.2.4  cliff  * if you find new ones and they work
    196   1.1.2.1  cliff  * please add them
    197   1.1.2.1  cliff  */
    198   1.1.2.1  cliff static uint64_t rmiclfw_psb_versions[] = {
    199   1.1.2.7  cliff 	0x4958d4fb00000056ULL,
    200   1.1.2.7  cliff 	0x49a5a8fa00000056ULL,
    201   1.1.2.9  cliff 	0x4aacdb6a00000056ULL,
    202   1.1.2.1  cliff };
    203   1.1.2.1  cliff #define RMICLFW_PSB_VERSIONS_LEN \
    204   1.1.2.1  cliff 	(sizeof(rmiclfw_psb_versions)/sizeof(rmiclfw_psb_versions[0]))
    205   1.1.2.1  cliff 
    206   1.1.2.1  cliff /*
    207   1.1.2.1  cliff  * kernel copies of firmware info
    208   1.1.2.1  cliff  */
    209   1.1.2.1  cliff static rmixlfw_info_t rmixlfw_info;
    210   1.1.2.1  cliff static rmixlfw_mmap_t rmixlfw_phys_mmap;
    211   1.1.2.1  cliff static rmixlfw_mmap_t rmixlfw_avail_mmap;
    212   1.1.2.4  cliff #define RMIXLFW_INFOP_LEGAL	0x8c000000
    213   1.1.2.1  cliff 
    214   1.1.2.1  cliff 
    215   1.1.2.6  cliff /*
    216   1.1.2.6  cliff  * storage for fixed extent used to allocate physical address regions
    217   1.1.2.6  cliff  * because extent(9) start and end values are u_long, they are only
    218   1.1.2.6  cliff  * 32 bits on a 32 bit kernel, which is insuffucuent since XLS physical
    219   1.1.2.6  cliff  * address is 40 bits wide.  So the "physaddr" map stores regions
    220   1.1.2.6  cliff  * in units of megabytes.
    221   1.1.2.6  cliff  */
    222   1.1.2.6  cliff static u_long rmixl_physaddr_storage[
    223   1.1.2.6  cliff 	EXTENT_FIXED_STORAGE_SIZE(32)/sizeof(u_long)
    224   1.1.2.6  cliff ];
    225   1.1.2.6  cliff 
    226   1.1.2.1  cliff /* For sysctl_hw. */
    227   1.1.2.1  cliff extern char cpu_model[];
    228   1.1.2.1  cliff 
    229   1.1.2.1  cliff /* Our exported CPU info; we can have only one. */
    230   1.1.2.1  cliff struct cpu_info cpu_info_store;
    231   1.1.2.1  cliff 
    232   1.1.2.1  cliff /* Maps for VM objects. */
    233   1.1.2.1  cliff struct vm_map *mb_map = NULL;
    234   1.1.2.1  cliff struct vm_map *phys_map = NULL;
    235   1.1.2.1  cliff 
    236   1.1.2.1  cliff int	physmem;		/* Total physical memory */
    237   1.1.2.1  cliff 
    238   1.1.2.1  cliff int	netboot;		/* Are we netbooting? */
    239   1.1.2.1  cliff 
    240   1.1.2.1  cliff 
    241   1.1.2.1  cliff phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];
    242   1.1.2.6  cliff u_int mem_cluster_cnt;
    243   1.1.2.6  cliff 
    244   1.1.2.1  cliff 
    245   1.1.2.1  cliff void configure(void);
    246   1.1.2.7  cliff void mach_init(int, int32_t *, void *, int64_t);
    247   1.1.2.7  cliff static u_long rmixlfw_init(int64_t);
    248   1.1.2.4  cliff static u_long mem_clusters_init(rmixlfw_mmap_t *, rmixlfw_mmap_t *);
    249  1.1.2.12  cliff static void __attribute__((__noreturn__)) rmixl_reset(void);
    250   1.1.2.6  cliff static void rmixl_physaddr_init(void);
    251   1.1.2.6  cliff static u_int ram_seg_resv(phys_ram_seg_t *, u_int, u_quad_t, u_quad_t);
    252   1.1.2.6  cliff void rmixlfw_mmap_print(rmixlfw_mmap_t *);
    253   1.1.2.1  cliff 
    254   1.1.2.1  cliff 
    255   1.1.2.1  cliff /*
    256   1.1.2.1  cliff  * safepri is a safe priority for sleep to set for a spin-wait during
    257   1.1.2.1  cliff  * autoconfiguration or after a panic.  Used as an argument to splx().
    258   1.1.2.1  cliff  */
    259   1.1.2.1  cliff int	safepri = MIPS1_PSL_LOWIPL;
    260   1.1.2.1  cliff 
    261   1.1.2.1  cliff /*
    262   1.1.2.1  cliff  * Do all the stuff that locore normally does before calling main().
    263   1.1.2.1  cliff  */
    264   1.1.2.1  cliff void
    265   1.1.2.7  cliff mach_init(int argc, int32_t *argv, void *envp, int64_t infop)
    266   1.1.2.1  cliff {
    267   1.1.2.4  cliff 	struct rmixl_config *rcp = &rmixl_configuration;
    268  1.1.2.11   matt 	void *kernend;
    269   1.1.2.1  cliff 	u_long memsize;
    270   1.1.2.6  cliff 	u_int vm_cluster_cnt;
    271   1.1.2.8  cliff 	uint32_t r;
    272   1.1.2.6  cliff 	phys_ram_seg_t vm_clusters[VM_PHYSSEG_MAX];
    273   1.1.2.1  cliff 	extern char edata[], end[];
    274   1.1.2.1  cliff 
    275   1.1.2.8  cliff 	rmixl_mtcr(0, 1);		/* disable all threads except #0 */
    276   1.1.2.8  cliff 
    277   1.1.2.8  cliff 	r = rmixl_mfcr(0x300);
    278   1.1.2.8  cliff 	r &= ~__BIT(14);		/* disabled Unaligned Access */
    279   1.1.2.8  cliff 	rmixl_mtcr(0x300, r);
    280   1.1.2.8  cliff 
    281   1.1.2.8  cliff 	rmixl_mtcr(0x400, 0);		/* enable MMU clock gating */
    282   1.1.2.8  cliff 					/* set single MMU Thread Mode */
    283   1.1.2.9  cliff 					/* TLB is partitioned (1 partition) */
    284   1.1.2.8  cliff 
    285   1.1.2.1  cliff 	/*
    286   1.1.2.1  cliff 	 * Clear the BSS segment.
    287   1.1.2.1  cliff 	 */
    288   1.1.2.1  cliff 	kernend = (void *)mips_round_page(end);
    289   1.1.2.1  cliff 	memset(edata, 0, (char *)kernend - edata);
    290   1.1.2.1  cliff 
    291   1.1.2.1  cliff 	/*
    292   1.1.2.1  cliff 	 * Set up the exception vectors and CPU-specific function
    293   1.1.2.1  cliff 	 * vectors early on.  We need the wbflush() vector set up
    294   1.1.2.1  cliff 	 * before comcnattach() is called (or at least before the
    295   1.1.2.1  cliff 	 * first printf() after that is called).
    296   1.1.2.1  cliff 	 * Also clears the I+D caches.
    297   1.1.2.1  cliff 	 */
    298   1.1.2.1  cliff 	mips_vector_init();
    299   1.1.2.1  cliff 
    300   1.1.2.1  cliff 	memsize = rmixlfw_init(infop);
    301   1.1.2.1  cliff 
    302   1.1.2.1  cliff 	/* set the VM page size */
    303   1.1.2.1  cliff 	uvm_setpagesize();
    304   1.1.2.1  cliff 
    305   1.1.2.1  cliff 	physmem = btoc(memsize);
    306   1.1.2.1  cliff 
    307  1.1.2.10  cliff 	rmixl_obio_eb_bus_mem_init(&rcp->rc_obio_eb_memt, rcp);
    308   1.1.2.1  cliff 
    309   1.1.2.1  cliff #if NCOM > 0
    310   1.1.2.9  cliff 	rmixl_com_cnattach(comcnaddr, comcnspeed, comcnfreq,
    311   1.1.2.1  cliff 		COM_TYPE_NORMAL, comcnmode);
    312   1.1.2.1  cliff #endif
    313   1.1.2.1  cliff 
    314   1.1.2.1  cliff 	printf("\nNetBSD/rmixl\n");
    315   1.1.2.1  cliff 	printf("memsize = %#lx\n", memsize);
    316   1.1.2.1  cliff 
    317   1.1.2.6  cliff 	rmixl_physaddr_init();
    318   1.1.2.6  cliff 
    319   1.1.2.1  cliff 	/*
    320   1.1.2.1  cliff 	 * Obtain the cpu frequency
    321   1.1.2.1  cliff 	 * Compute the number of ticks for hz.
    322   1.1.2.1  cliff 	 * Compute the delay divisor.
    323   1.1.2.1  cliff 	 * Double the Hz if this CPU runs at twice the
    324   1.1.2.1  cliff          *  external/cp0-count frequency
    325   1.1.2.1  cliff 	 */
    326   1.1.2.1  cliff 	curcpu()->ci_cpu_freq = rmixlfw_info.cpu_frequency;
    327   1.1.2.1  cliff 	curcpu()->ci_cycles_per_hz = (curcpu()->ci_cpu_freq + hz / 2) / hz;
    328   1.1.2.1  cliff 	curcpu()->ci_divisor_delay =
    329   1.1.2.1  cliff 		((curcpu()->ci_cpu_freq + 500000) / 1000000);
    330   1.1.2.1  cliff         if (mips_cpu_flags & CPU_MIPS_DOUBLE_COUNT)
    331   1.1.2.1  cliff 		curcpu()->ci_cpu_freq *= 2;
    332   1.1.2.1  cliff 
    333   1.1.2.1  cliff 	/*
    334   1.1.2.1  cliff 	 * Look at arguments passed to us and compute boothowto.
    335   1.1.2.1  cliff 	 * - rmixl firmware gives us a 32 bit argv[i], so adapt
    336   1.1.2.1  cliff 	 *   by forcing sign extension in cast to (char *)
    337   1.1.2.1  cliff 	 */
    338   1.1.2.1  cliff 	boothowto = RB_AUTOBOOT;
    339   1.1.2.1  cliff 	for (int i = 1; i < argc; i++) {
    340   1.1.2.7  cliff 		for (char *cp = (char *)(intptr_t)argv[i]; *cp; cp++) {
    341   1.1.2.1  cliff 			int howto;
    342   1.1.2.1  cliff 			/* Ignore superfluous '-', if there is one */
    343   1.1.2.1  cliff 			if (*cp == '-')
    344   1.1.2.1  cliff 				continue;
    345   1.1.2.1  cliff 
    346   1.1.2.1  cliff 			howto = 0;
    347   1.1.2.1  cliff 			BOOT_FLAG(*cp, howto);
    348   1.1.2.6  cliff 			if (howto != 0)
    349   1.1.2.1  cliff 				boothowto |= howto;
    350   1.1.2.6  cliff #ifdef DIAGNOSTIC
    351   1.1.2.6  cliff 			else
    352   1.1.2.6  cliff 				printf("bootflag '%c' not recognised\n", *cp);
    353   1.1.2.6  cliff #endif
    354   1.1.2.1  cliff 		}
    355   1.1.2.1  cliff 	}
    356   1.1.2.6  cliff #ifdef DIAGNOSTIC
    357   1.1.2.1  cliff 	printf("boothowto %#x\n", boothowto);
    358   1.1.2.6  cliff #endif
    359   1.1.2.1  cliff 
    360   1.1.2.1  cliff 	/*
    361   1.1.2.6  cliff 	 * Reserve pages from the VM system.
    362   1.1.2.6  cliff 	 * to maintain mem_clusters[] as a map of raw ram,
    363   1.1.2.6  cliff 	 * copy into temporary table vm_clusters[]
    364   1.1.2.6  cliff 	 * work on that and use it to feed vm_physload()
    365   1.1.2.6  cliff 	 */
    366   1.1.2.6  cliff 	KASSERT(sizeof(mem_clusters) == sizeof(vm_clusters));
    367   1.1.2.6  cliff 	memcpy(&vm_clusters, &mem_clusters, sizeof(vm_clusters));
    368   1.1.2.6  cliff 	vm_cluster_cnt = mem_cluster_cnt;
    369   1.1.2.6  cliff 
    370   1.1.2.6  cliff 	/* reserve 0..start..kernend pages */
    371   1.1.2.6  cliff 	vm_cluster_cnt = ram_seg_resv(vm_clusters, vm_cluster_cnt,
    372   1.1.2.6  cliff 		0, round_page(MIPS_KSEG0_TO_PHYS(kernend)));
    373   1.1.2.6  cliff 
    374   1.1.2.6  cliff 	/* reserve reset exception vector page */
    375   1.1.2.9  cliff 	/* should never be in our clusters anyway... */
    376   1.1.2.6  cliff 	vm_cluster_cnt = ram_seg_resv(vm_clusters, vm_cluster_cnt,
    377  1.1.2.12  cliff 		0x1FC00000, 0x1FC00000+NBPG);
    378   1.1.2.6  cliff 
    379   1.1.2.6  cliff 	/*
    380   1.1.2.6  cliff 	 * Load vm_clusters[] into the VM system.
    381   1.1.2.6  cliff 	 */
    382  1.1.2.11   matt 	mips_page_physload(MIPS_KSEG0_START, (vaddr_t) kernend,
    383  1.1.2.11   matt 	    vm_clusters, vm_cluster_cnt, NULL, 0);
    384   1.1.2.1  cliff 
    385   1.1.2.1  cliff 	/*
    386   1.1.2.1  cliff 	 * Initialize error message buffer (at end of core).
    387   1.1.2.1  cliff 	 */
    388   1.1.2.1  cliff 	mips_init_msgbuf();
    389   1.1.2.1  cliff 
    390   1.1.2.1  cliff 	pmap_bootstrap();
    391   1.1.2.1  cliff 
    392   1.1.2.1  cliff 	/*
    393   1.1.2.1  cliff 	 * Allocate space for proc0's USPACE.
    394   1.1.2.1  cliff 	 */
    395  1.1.2.11   matt 	mips_init_lwp0_uarea();
    396   1.1.2.1  cliff 
    397   1.1.2.1  cliff 	/*
    398   1.1.2.1  cliff 	 * Initialize debuggers, and break into them, if appropriate.
    399   1.1.2.1  cliff 	 */
    400   1.1.2.1  cliff #if NKSYMS || defined(DDB) || defined(LKM)
    401   1.1.2.1  cliff 	ksyms_init(0, 0, 0);
    402   1.1.2.1  cliff #endif
    403   1.1.2.1  cliff 
    404   1.1.2.1  cliff #if defined(DDB)
    405   1.1.2.1  cliff 	if (boothowto & RB_KDB)
    406   1.1.2.1  cliff 		Debugger();
    407   1.1.2.1  cliff #endif
    408   1.1.2.6  cliff }
    409   1.1.2.6  cliff 
    410   1.1.2.6  cliff /*
    411   1.1.2.6  cliff  * ram_seg_resv - cut reserved regions out of segs, fragmenting as needed
    412   1.1.2.6  cliff  *
    413   1.1.2.6  cliff  * we simply build a new table of segs, then copy it back over the given one
    414   1.1.2.6  cliff  * this is inefficient but simple and called only a few times
    415   1.1.2.6  cliff  *
    416   1.1.2.6  cliff  * note: 'last' here means 1st addr past the end of the segment (start+size)
    417   1.1.2.6  cliff  */
    418   1.1.2.6  cliff static u_int
    419   1.1.2.6  cliff ram_seg_resv(phys_ram_seg_t *segs, u_int nsegs,
    420   1.1.2.6  cliff 	u_quad_t resv_first, u_quad_t resv_last)
    421   1.1.2.6  cliff {
    422   1.1.2.6  cliff         u_quad_t first, last;
    423   1.1.2.6  cliff 	int new_nsegs=0;
    424   1.1.2.6  cliff 	int resv_flag;
    425   1.1.2.6  cliff 	phys_ram_seg_t new_segs[VM_PHYSSEG_MAX];
    426   1.1.2.6  cliff 
    427   1.1.2.6  cliff 	for (u_int i=0; i < nsegs; i++) {
    428   1.1.2.6  cliff 		resv_flag = 0;
    429   1.1.2.6  cliff 		first = trunc_page(segs[i].start);
    430   1.1.2.6  cliff 		last = round_page(segs[i].start + segs[i].size);
    431   1.1.2.6  cliff 
    432   1.1.2.6  cliff 		KASSERT(new_nsegs < VM_PHYSSEG_MAX);
    433   1.1.2.6  cliff 		if ((resv_first <= first) && (resv_last >= last)) {
    434   1.1.2.6  cliff 			/* whole segment is resverved */
    435   1.1.2.6  cliff 			continue;
    436   1.1.2.6  cliff 		}
    437   1.1.2.6  cliff 		if ((resv_first > first) && (resv_first < last)) {
    438   1.1.2.6  cliff 			u_quad_t new_last;
    439   1.1.2.6  cliff 
    440   1.1.2.6  cliff 			/*
    441   1.1.2.6  cliff 			 * reserved start in segment
    442   1.1.2.6  cliff 			 * salvage the leading fragment
    443   1.1.2.6  cliff 			 */
    444   1.1.2.6  cliff 			resv_flag = 1;
    445   1.1.2.6  cliff 			new_last = last - (last - resv_first);
    446   1.1.2.6  cliff 			KASSERT (new_last > first);
    447   1.1.2.6  cliff 			new_segs[new_nsegs].start = first;
    448   1.1.2.6  cliff 			new_segs[new_nsegs].size = new_last - first;
    449   1.1.2.6  cliff 			new_nsegs++;
    450   1.1.2.6  cliff 		}
    451   1.1.2.6  cliff 		if ((resv_last > first) && (resv_last < last)) {
    452   1.1.2.6  cliff 			u_quad_t new_first;
    453   1.1.2.6  cliff 
    454   1.1.2.6  cliff 			/*
    455   1.1.2.6  cliff 			 * reserved end in segment
    456   1.1.2.6  cliff 			 * salvage the trailing fragment
    457   1.1.2.6  cliff 			 */
    458   1.1.2.6  cliff 			resv_flag = 1;
    459   1.1.2.6  cliff 			new_first = first + (resv_last - first);
    460   1.1.2.6  cliff 			KASSERT (last > (new_first + NBPG));
    461   1.1.2.6  cliff 			new_segs[new_nsegs].start = new_first;
    462   1.1.2.6  cliff 			new_segs[new_nsegs].size = last - new_first;
    463   1.1.2.6  cliff 			new_nsegs++;
    464   1.1.2.6  cliff 		}
    465   1.1.2.6  cliff 		if (resv_flag == 0) {
    466   1.1.2.6  cliff 			/*
    467   1.1.2.6  cliff 			 * nothing reserved here, take it all
    468   1.1.2.6  cliff 			 */
    469   1.1.2.6  cliff 			new_segs[new_nsegs].start = first;
    470   1.1.2.6  cliff 			new_segs[new_nsegs].size = last - first;
    471   1.1.2.6  cliff 			new_nsegs++;
    472   1.1.2.6  cliff 		}
    473   1.1.2.6  cliff 
    474   1.1.2.6  cliff 	}
    475   1.1.2.6  cliff 
    476   1.1.2.6  cliff 	memcpy(segs, new_segs, sizeof(new_segs));
    477   1.1.2.6  cliff 
    478   1.1.2.6  cliff 	return new_nsegs;
    479   1.1.2.6  cliff }
    480   1.1.2.6  cliff 
    481   1.1.2.6  cliff /*
    482   1.1.2.6  cliff  * create an extent for physical address space
    483   1.1.2.6  cliff  * these are in units of MB for sake of compression (for sake of 32 bit kernels)
    484   1.1.2.6  cliff  * allocate the regions where we have known functions (DRAM, IO, etc)
    485   1.1.2.6  cliff  * what remains can be allocated as needed for other stuff
    486   1.1.2.6  cliff  * e.g. to configure BARs that are not already initialized and enabled.
    487   1.1.2.6  cliff  */
    488   1.1.2.6  cliff static void
    489   1.1.2.6  cliff rmixl_physaddr_init(void)
    490   1.1.2.6  cliff {
    491   1.1.2.6  cliff 	struct extent *ext;
    492   1.1.2.6  cliff 	unsigned long start = 0UL;
    493   1.1.2.6  cliff 	unsigned long end = (__BIT(40) / (1024 * 1024)) -1;
    494   1.1.2.6  cliff 	u_long base;
    495   1.1.2.6  cliff 	u_long size;
    496   1.1.2.6  cliff 	uint32_t r;
    497   1.1.2.6  cliff 
    498   1.1.2.6  cliff 	ext = extent_create("physaddr", start, end, M_DEVBUF,
    499   1.1.2.6  cliff 		(void *)rmixl_physaddr_storage, sizeof(rmixl_physaddr_storage),
    500   1.1.2.6  cliff 		EX_NOWAIT | EX_NOCOALESCE);
    501   1.1.2.6  cliff 
    502   1.1.2.6  cliff 	if (ext == NULL)
    503   1.1.2.6  cliff 		panic("%s: extent_create failed", __func__);
    504   1.1.2.6  cliff 
    505   1.1.2.6  cliff 	/*
    506   1.1.2.6  cliff 	 * grab regions per DRAM BARs
    507   1.1.2.6  cliff 	 */
    508   1.1.2.6  cliff 	for (u_int i=0; i < RMIXL_SBC_DRAM_NBARS; i++) {
    509   1.1.2.6  cliff 		r = RMIXL_IOREG_READ(RMIXL_SBC_DRAM_BAR(i));
    510   1.1.2.6  cliff 		if ((r & RMIXL_DRAM_BAR_STATUS) == 0)
    511   1.1.2.6  cliff 			continue;	/* not enabled */
    512   1.1.2.6  cliff 		base = (u_long)(DRAM_BAR_TO_BASE((uint64_t)r) / (1024 * 1024));
    513   1.1.2.6  cliff 		size = (u_long)(DRAM_BAR_TO_SIZE((uint64_t)r) / (1024 * 1024));
    514   1.1.2.6  cliff 
    515   1.1.2.6  cliff 		DPRINTF(("%s: %d: %d: 0x%08x -- 0x%010lx:%lu MB\n",
    516   1.1.2.6  cliff 			__func__, __LINE__, i, r, base * (1024 * 1024), size));
    517   1.1.2.6  cliff 		if (extent_alloc_region(ext, base, size, EX_NOWAIT) != 0)
    518   1.1.2.6  cliff 			panic("%s: extent_alloc_region(%p, %#lx, %#lx, %#x) "
    519   1.1.2.6  cliff 				"failed", __func__, ext, base, size, EX_NOWAIT);
    520   1.1.2.6  cliff 	}
    521   1.1.2.6  cliff 
    522   1.1.2.6  cliff 	/*
    523   1.1.2.6  cliff 	 * grab regions per PCIe CFG, ECFG, IO, MEM BARs
    524   1.1.2.6  cliff 	 */
    525   1.1.2.6  cliff 	r = RMIXL_IOREG_READ(RMIXL_SBC_PCIE_CFG_BAR);
    526   1.1.2.6  cliff 	if ((r & RMIXL_PCIE_CFG_BAR_ENB) != 0) {
    527   1.1.2.6  cliff 		base = (u_long)(RMIXL_PCIE_CFG_BAR_TO_BA((uint64_t)r)
    528   1.1.2.6  cliff 			/ (1024 * 1024));
    529   1.1.2.6  cliff 		size = (u_long)RMIXL_PCIE_CFG_SIZE / (1024 * 1024);
    530   1.1.2.6  cliff 		DPRINTF(("%s: %d: %s: 0x%08x -- 0x%010lx:%ld MB\n", __func__,
    531   1.1.2.6  cliff 			__LINE__, "CFG", r, base * 1024 * 1024, size));
    532   1.1.2.6  cliff 		if (extent_alloc_region(ext, base, size, EX_NOWAIT) != 0)
    533   1.1.2.6  cliff 			panic("%s: extent_alloc_region(%p, %#lx, %#lx, %#x) "
    534   1.1.2.6  cliff 				"failed", __func__, ext, base, size, EX_NOWAIT);
    535   1.1.2.6  cliff 	}
    536   1.1.2.6  cliff 	r = RMIXL_IOREG_READ(RMIXL_SBC_PCIE_ECFG_BAR);
    537   1.1.2.6  cliff 	if ((r & RMIXL_PCIE_ECFG_BAR_ENB) != 0) {
    538   1.1.2.6  cliff 		base = (u_long)(RMIXL_PCIE_ECFG_BAR_TO_BA((uint64_t)r)
    539   1.1.2.6  cliff 			/ (1024 * 1024));
    540   1.1.2.6  cliff 		size = (u_long)RMIXL_PCIE_ECFG_SIZE / (1024 * 1024);
    541   1.1.2.6  cliff 		DPRINTF(("%s: %d: %s: 0x%08x -- 0x%010lx:%ld MB\n", __func__,
    542   1.1.2.6  cliff 			__LINE__, "ECFG", r, base * 1024 * 1024, size));
    543   1.1.2.6  cliff 		if (extent_alloc_region(ext, base, size, EX_NOWAIT) != 0)
    544   1.1.2.6  cliff 			panic("%s: extent_alloc_region(%p, %#lx, %#lx, %#x) "
    545   1.1.2.6  cliff 				"failed", __func__, ext, base, size, EX_NOWAIT);
    546   1.1.2.6  cliff 	}
    547   1.1.2.6  cliff 	r = RMIXL_IOREG_READ(RMIXL_SBC_PCIE_MEM_BAR);
    548   1.1.2.6  cliff 	if ((r & RMIXL_PCIE_MEM_BAR_ENB) != 0) {
    549   1.1.2.6  cliff 		base = (u_long)(RMIXL_PCIE_MEM_BAR_TO_BA((uint64_t)r)
    550   1.1.2.6  cliff 			/ (1024 * 1024));
    551   1.1.2.6  cliff 		size = (u_long)(RMIXL_PCIE_MEM_BAR_TO_SIZE((uint64_t)r)
    552   1.1.2.6  cliff 			/ (1024 * 1024));
    553   1.1.2.6  cliff 		DPRINTF(("%s: %d: %s: 0x%08x -- 0x%010lx:%ld MB\n", __func__,
    554   1.1.2.6  cliff 			__LINE__, "MEM", r, base * 1024 * 1024, size));
    555   1.1.2.6  cliff 		if (extent_alloc_region(ext, base, size, EX_NOWAIT) != 0)
    556   1.1.2.6  cliff 			panic("%s: extent_alloc_region(%p, %#lx, %#lx, %#x) "
    557   1.1.2.6  cliff 				"failed", __func__, ext, base, size, EX_NOWAIT);
    558   1.1.2.6  cliff 	}
    559   1.1.2.6  cliff 	r = RMIXL_IOREG_READ(RMIXL_SBC_PCIE_IO_BAR);
    560   1.1.2.6  cliff 	if ((r & RMIXL_PCIE_IO_BAR_ENB) != 0) {
    561   1.1.2.6  cliff 		base = (u_long)(RMIXL_PCIE_IO_BAR_TO_BA((uint64_t)r)
    562   1.1.2.6  cliff 			/ (1024 * 1024));
    563   1.1.2.6  cliff 		size = (u_long)(RMIXL_PCIE_IO_BAR_TO_SIZE((uint64_t)r)
    564   1.1.2.6  cliff 			/ (1024 * 1024));
    565   1.1.2.6  cliff 		DPRINTF(("%s: %d: %s: 0x%08x -- 0x%010lx:%ld MB\n", __func__,
    566   1.1.2.6  cliff 			__LINE__, "IO", r, base * 1024 * 1024, size));
    567   1.1.2.6  cliff 		if (extent_alloc_region(ext, base, size, EX_NOWAIT) != 0)
    568   1.1.2.6  cliff 			panic("%s: extent_alloc_region(%p, %#lx, %#lx, %#x) "
    569   1.1.2.6  cliff 				"failed", __func__, ext, base, size, EX_NOWAIT);
    570   1.1.2.6  cliff 	}
    571   1.1.2.6  cliff 
    572   1.1.2.6  cliff 	/*
    573   1.1.2.6  cliff 	 *  at this point all regions left in "physaddr" extent
    574   1.1.2.6  cliff 	 *  are unused holes in the physical adress space
    575   1.1.2.6  cliff 	 *  available for use as needed.
    576   1.1.2.6  cliff 	 */
    577   1.1.2.6  cliff 	rmixl_configuration.rc_phys_ex = ext;
    578   1.1.2.6  cliff #ifdef MACHDEP_DEBUG
    579   1.1.2.6  cliff 	extent_print(ext);
    580   1.1.2.6  cliff #endif
    581   1.1.2.1  cliff }
    582   1.1.2.1  cliff 
    583   1.1.2.1  cliff static u_long
    584   1.1.2.7  cliff rmixlfw_init(int64_t infop)
    585   1.1.2.1  cliff {
    586   1.1.2.4  cliff 	struct rmixl_config *rcp = &rmixl_configuration;
    587   1.1.2.1  cliff 
    588   1.1.2.1  cliff 	strcpy(cpu_model, "RMI XLS616ATX VIIA");	/* XXX */
    589   1.1.2.1  cliff 
    590   1.1.2.7  cliff 	infop |= MIPS_KSEG0_START;
    591   1.1.2.7  cliff 	rmixlfw_info = *(rmixlfw_info_t *)(intptr_t)infop;
    592   1.1.2.1  cliff 
    593   1.1.2.1  cliff 	for (int i=0; i < RMICLFW_PSB_VERSIONS_LEN; i++) {
    594   1.1.2.1  cliff 		if (rmiclfw_psb_versions[i] == rmixlfw_info.psb_version)
    595   1.1.2.1  cliff 			goto found;
    596   1.1.2.1  cliff 	}
    597   1.1.2.1  cliff 
    598   1.1.2.7  cliff 	rcp->rc_io_pbase = RMIXL_IO_DEV_PBASE;
    599   1.1.2.4  cliff 	rmixl_putchar_init(rcp->rc_io_pbase);
    600   1.1.2.4  cliff 
    601   1.1.2.6  cliff #ifdef DIAGNOSTIC
    602   1.1.2.1  cliff 	rmixl_puts("\r\nWARNING: untested psb_version: ");
    603   1.1.2.1  cliff 	rmixl_puthex64(rmixlfw_info.psb_version);
    604   1.1.2.1  cliff 	rmixl_puts("\r\n");
    605   1.1.2.6  cliff #endif
    606   1.1.2.9  cliff 
    607   1.1.2.9  cliff 	/* XXX trust and use MEMSIZE */
    608   1.1.2.9  cliff 	mem_clusters[0].start = 0;
    609   1.1.2.9  cliff 	mem_clusters[0].size = MEMSIZE;
    610   1.1.2.9  cliff 	mem_cluster_cnt = 1;
    611   1.1.2.7  cliff 	return MEMSIZE;
    612   1.1.2.4  cliff 
    613   1.1.2.1  cliff  found:
    614   1.1.2.4  cliff 	rcp->rc_io_pbase = MIPS_KSEG1_TO_PHYS(rmixlfw_info.io_base);
    615   1.1.2.4  cliff 	rmixl_putchar_init(rcp->rc_io_pbase);
    616   1.1.2.6  cliff #ifdef MACHDEP_DEBUG
    617   1.1.2.4  cliff 	rmixl_puts("\r\ninfop: ");
    618   1.1.2.7  cliff 	rmixl_puthex64((uint64_t)(intptr_t)infop);
    619   1.1.2.6  cliff #endif
    620   1.1.2.6  cliff #ifdef DIAGNOSTIC
    621   1.1.2.4  cliff 	rmixl_puts("\r\nrecognized psb_version: ");
    622   1.1.2.4  cliff 	rmixl_puthex64(rmixlfw_info.psb_version);
    623   1.1.2.4  cliff 	rmixl_puts("\r\n");
    624   1.1.2.6  cliff #endif
    625   1.1.2.1  cliff 
    626   1.1.2.4  cliff 	return mem_clusters_init(
    627   1.1.2.7  cliff 		(rmixlfw_mmap_t *)(intptr_t)rmixlfw_info.psb_physaddr_map,
    628   1.1.2.7  cliff 		(rmixlfw_mmap_t *)(intptr_t)rmixlfw_info.avail_mem_map);
    629   1.1.2.4  cliff }
    630   1.1.2.4  cliff 
    631   1.1.2.6  cliff void
    632   1.1.2.6  cliff rmixlfw_mmap_print(rmixlfw_mmap_t *map)
    633   1.1.2.6  cliff {
    634   1.1.2.6  cliff #ifdef MACHDEP_DEBUG
    635   1.1.2.6  cliff 	for (uint32_t i=0; i < map->nmmaps; i++) {
    636   1.1.2.6  cliff 		rmixl_puthex32(i);
    637   1.1.2.6  cliff 		rmixl_puts(", ");
    638   1.1.2.6  cliff 		rmixl_puthex64(map->entry[i].start);
    639   1.1.2.6  cliff 		rmixl_puts(", ");
    640   1.1.2.6  cliff 		rmixl_puthex64(map->entry[i].size);
    641   1.1.2.6  cliff 		rmixl_puts(", ");
    642   1.1.2.6  cliff 		rmixl_puthex32(map->entry[i].type);
    643   1.1.2.6  cliff 		rmixl_puts("\r\n");
    644   1.1.2.6  cliff 	}
    645   1.1.2.6  cliff #endif
    646   1.1.2.6  cliff }
    647   1.1.2.6  cliff 
    648   1.1.2.6  cliff /*
    649   1.1.2.6  cliff  * mem_clusters_init
    650   1.1.2.6  cliff  *
    651   1.1.2.6  cliff  * initialize mem_clusters[] table based on memory address mapping
    652   1.1.2.6  cliff  * provided by boot firmware.
    653   1.1.2.6  cliff  *
    654   1.1.2.6  cliff  * prefer avail_mem_map if we can, otherwise use psb_physaddr_map.
    655   1.1.2.6  cliff  * these will be limited by MEMSIZE if it is configured.
    656   1.1.2.6  cliff  * if neither are available, just use MEMSIZE.
    657   1.1.2.6  cliff  */
    658   1.1.2.4  cliff static u_long
    659   1.1.2.4  cliff mem_clusters_init(
    660   1.1.2.4  cliff 	rmixlfw_mmap_t *psb_physaddr_map,
    661   1.1.2.4  cliff 	rmixlfw_mmap_t *avail_mem_map)
    662   1.1.2.4  cliff {
    663   1.1.2.6  cliff 	rmixlfw_mmap_t *map = NULL;
    664   1.1.2.6  cliff 	const char *mapname;
    665   1.1.2.4  cliff 	uint64_t tmp;
    666   1.1.2.4  cliff 	uint64_t sz;
    667   1.1.2.4  cliff 	uint64_t sum;
    668   1.1.2.6  cliff 	u_int cnt;
    669   1.1.2.4  cliff #ifdef MEMSIZE
    670   1.1.2.4  cliff 	u_long memsize = MEMSIZE;
    671   1.1.2.4  cliff #endif
    672   1.1.2.4  cliff 
    673   1.1.2.6  cliff #ifdef MACHDEP_DEBUG
    674   1.1.2.4  cliff 	rmixl_puts("psb_physaddr_map: ");
    675   1.1.2.7  cliff 	rmixl_puthex64((uint64_t)(intptr_t)psb_physaddr_map);
    676   1.1.2.4  cliff 	rmixl_puts("\r\n");
    677   1.1.2.6  cliff #endif
    678   1.1.2.6  cliff 	if (psb_physaddr_map != NULL) {
    679   1.1.2.6  cliff 		rmixlfw_phys_mmap = *psb_physaddr_map;
    680   1.1.2.6  cliff 		map = &rmixlfw_phys_mmap;
    681   1.1.2.6  cliff 		mapname = "psb_physaddr_map";
    682   1.1.2.6  cliff 		rmixlfw_mmap_print(map);
    683   1.1.2.6  cliff 	}
    684   1.1.2.6  cliff #ifdef DIAGNOSTIC
    685   1.1.2.6  cliff 	else {
    686   1.1.2.4  cliff 		rmixl_puts("WARNING: no psb_physaddr_map\r\n");
    687   1.1.2.6  cliff 	}
    688   1.1.2.6  cliff #endif
    689   1.1.2.4  cliff 
    690   1.1.2.6  cliff #ifdef MACHDEP_DEBUG
    691   1.1.2.4  cliff 	rmixl_puts("avail_mem_map: ");
    692   1.1.2.7  cliff 	rmixl_puthex64((uint64_t)(intptr_t)avail_mem_map);
    693   1.1.2.4  cliff 	rmixl_puts("\r\n");
    694   1.1.2.6  cliff #endif
    695   1.1.2.6  cliff 	if (avail_mem_map != NULL) {
    696   1.1.2.6  cliff 		rmixlfw_avail_mmap = *avail_mem_map;
    697   1.1.2.6  cliff 		map = &rmixlfw_avail_mmap;
    698   1.1.2.6  cliff 		mapname = "avail_mem_map";
    699   1.1.2.6  cliff 		rmixlfw_mmap_print(map);
    700   1.1.2.6  cliff 	}
    701   1.1.2.6  cliff #ifdef DIAGNOSTIC
    702   1.1.2.6  cliff 	else {
    703   1.1.2.6  cliff 		rmixl_puts("WARNING: no avail_mem_map\r\n");
    704   1.1.2.6  cliff 	}
    705   1.1.2.6  cliff #endif
    706   1.1.2.6  cliff 
    707   1.1.2.6  cliff 	if (map == NULL) {
    708   1.1.2.4  cliff #ifndef MEMSIZE
    709   1.1.2.6  cliff 		rmixl_puts("panic: no firmware memory map, "
    710   1.1.2.6  cliff 			"must configure MEMSIZE\r\n");
    711   1.1.2.6  cliff 		for(;;);	/* XXX */
    712   1.1.2.4  cliff #else
    713   1.1.2.6  cliff #ifdef DIAGNOSTIC
    714   1.1.2.4  cliff 		rmixl_puts("WARNING: no avail_mem_map, "
    715   1.1.2.4  cliff 			"using MEMSIZE\r\n");
    716   1.1.2.6  cliff #endif
    717   1.1.2.6  cliff 
    718   1.1.2.4  cliff 		mem_clusters[0].start = 0;
    719   1.1.2.4  cliff 		mem_clusters[0].size = MEMSIZE;
    720   1.1.2.4  cliff 		mem_cluster_cnt = 1;
    721   1.1.2.4  cliff 		return MEMSIZE;
    722   1.1.2.6  cliff #endif	/* MEMSIZE */
    723   1.1.2.4  cliff 	}
    724   1.1.2.1  cliff 
    725   1.1.2.6  cliff #ifdef DIAGNOSTIC
    726   1.1.2.6  cliff 	rmixl_puts("using ");
    727   1.1.2.6  cliff 	rmixl_puts(mapname);
    728   1.1.2.6  cliff 	rmixl_puts("\r\n");
    729   1.1.2.6  cliff #endif
    730   1.1.2.6  cliff #ifdef MACHDEP_DEBUG
    731   1.1.2.6  cliff 	rmixl_puts("memory clusters:\r\n");
    732   1.1.2.6  cliff #endif
    733   1.1.2.1  cliff 	sum = 0;
    734   1.1.2.6  cliff 	cnt = 0;
    735   1.1.2.6  cliff 	for (uint32_t i=0; i < map->nmmaps; i++) {
    736   1.1.2.6  cliff 		if (map->entry[i].type != RMIXLFW_MMAP_TYPE_RAM)
    737   1.1.2.1  cliff 			continue;
    738   1.1.2.6  cliff 		mem_clusters[cnt].start = map->entry[i].start;
    739   1.1.2.6  cliff 		sz = map->entry[i].size;
    740   1.1.2.1  cliff 		sum += sz;
    741   1.1.2.6  cliff 		mem_clusters[cnt].size = sz;
    742   1.1.2.6  cliff #ifdef MACHDEP_DEBUG
    743   1.1.2.1  cliff 		rmixl_puthex32(i);
    744   1.1.2.1  cliff 		rmixl_puts(": ");
    745   1.1.2.6  cliff 		rmixl_puthex64(mem_clusters[cnt].start);
    746   1.1.2.6  cliff 		rmixl_puts(", ");
    747   1.1.2.1  cliff 		rmixl_puthex64(sz);
    748   1.1.2.1  cliff 		rmixl_puts(": ");
    749   1.1.2.1  cliff 		rmixl_puthex64(sum);
    750   1.1.2.1  cliff 		rmixl_puts("\r\n");
    751   1.1.2.1  cliff #endif
    752   1.1.2.1  cliff #ifdef MEMSIZE
    753   1.1.2.1  cliff 		/*
    754   1.1.2.1  cliff 		 * configurably limit memsize
    755   1.1.2.1  cliff 		 */
    756   1.1.2.1  cliff 		if (sum == memsize)
    757   1.1.2.1  cliff 			break;
    758   1.1.2.1  cliff 		if (sum > memsize) {
    759   1.1.2.1  cliff 			tmp = sum - memsize;
    760   1.1.2.1  cliff 			sz -= tmp;
    761   1.1.2.1  cliff 			sum -= tmp;
    762   1.1.2.6  cliff 			mem_clusters[cnt].size = sz;
    763   1.1.2.1  cliff 			break;
    764   1.1.2.1  cliff 		}
    765   1.1.2.1  cliff #endif
    766   1.1.2.6  cliff 		cnt++;
    767   1.1.2.1  cliff 	}
    768   1.1.2.6  cliff 	mem_cluster_cnt = cnt;
    769   1.1.2.1  cliff 	return sum;
    770   1.1.2.1  cliff }
    771   1.1.2.1  cliff 
    772   1.1.2.1  cliff void
    773   1.1.2.1  cliff consinit(void)
    774   1.1.2.1  cliff {
    775   1.1.2.1  cliff 
    776   1.1.2.1  cliff 	/*
    777   1.1.2.1  cliff 	 * Everything related to console initialization is done
    778   1.1.2.1  cliff 	 * in mach_init().
    779   1.1.2.1  cliff 	 */
    780   1.1.2.1  cliff }
    781   1.1.2.1  cliff 
    782   1.1.2.1  cliff /*
    783   1.1.2.1  cliff  * Allocate memory for variable-sized tables,
    784   1.1.2.1  cliff  */
    785   1.1.2.1  cliff void
    786   1.1.2.1  cliff cpu_startup()
    787   1.1.2.1  cliff {
    788   1.1.2.1  cliff 	vaddr_t minaddr, maxaddr;
    789   1.1.2.1  cliff 	char pbuf[9];
    790   1.1.2.1  cliff 
    791   1.1.2.1  cliff 	/*
    792   1.1.2.1  cliff 	 * Good {morning,afternoon,evening,night}.
    793   1.1.2.1  cliff 	 */
    794   1.1.2.1  cliff 	printf("%s%s", copyright, version);
    795   1.1.2.1  cliff 	format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
    796   1.1.2.1  cliff 	printf("total memory = %s\n", pbuf);
    797   1.1.2.1  cliff 
    798   1.1.2.1  cliff 	/*
    799   1.1.2.1  cliff 	 * Virtual memory is bootstrapped -- notify the bus spaces
    800   1.1.2.1  cliff 	 * that memory allocation is now safe.
    801   1.1.2.1  cliff 	 */
    802   1.1.2.1  cliff 	rmixl_configuration.rc_mallocsafe = 1;
    803   1.1.2.1  cliff 
    804   1.1.2.1  cliff 	minaddr = 0;
    805   1.1.2.1  cliff 	/*
    806   1.1.2.1  cliff 	 * Allocate a submap for physio.
    807   1.1.2.1  cliff 	 */
    808   1.1.2.1  cliff 	phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    809   1.1.2.1  cliff 				    VM_PHYS_SIZE, 0, FALSE, NULL);
    810   1.1.2.1  cliff 
    811   1.1.2.1  cliff 	/*
    812   1.1.2.1  cliff 	 * (No need to allocate an mbuf cluster submap.  Mbuf clusters
    813   1.1.2.6  cliff 	 * are allocated via the pool allocator, and we use XKSEG to
    814   1.1.2.1  cliff 	 * map those pages.)
    815   1.1.2.1  cliff 	 */
    816   1.1.2.1  cliff 
    817   1.1.2.1  cliff 	format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
    818   1.1.2.1  cliff 	printf("avail memory = %s\n", pbuf);
    819   1.1.2.1  cliff }
    820   1.1.2.1  cliff 
    821   1.1.2.1  cliff int	waittime = -1;
    822   1.1.2.1  cliff 
    823   1.1.2.1  cliff void
    824   1.1.2.1  cliff cpu_reboot(howto, bootstr)
    825   1.1.2.1  cliff 	int howto;
    826   1.1.2.1  cliff 	char *bootstr;
    827   1.1.2.1  cliff {
    828   1.1.2.1  cliff 
    829   1.1.2.1  cliff 	/* Take a snapshot before clobbering any registers. */
    830   1.1.2.1  cliff 	if (curproc)
    831   1.1.2.1  cliff 		savectx((struct user *)curpcb);
    832   1.1.2.1  cliff 
    833   1.1.2.1  cliff 	if (cold) {
    834   1.1.2.1  cliff 		howto |= RB_HALT;
    835   1.1.2.1  cliff 		goto haltsys;
    836   1.1.2.1  cliff 	}
    837   1.1.2.1  cliff 
    838   1.1.2.1  cliff 	/* If "always halt" was specified as a boot flag, obey. */
    839   1.1.2.1  cliff 	if (boothowto & RB_HALT)
    840   1.1.2.1  cliff 		howto |= RB_HALT;
    841   1.1.2.1  cliff 
    842   1.1.2.1  cliff 	boothowto = howto;
    843   1.1.2.1  cliff 	if ((howto & RB_NOSYNC) == 0 && (waittime < 0)) {
    844   1.1.2.1  cliff 		waittime = 0;
    845   1.1.2.1  cliff 		vfs_shutdown();
    846   1.1.2.1  cliff 
    847   1.1.2.1  cliff 		/*
    848   1.1.2.1  cliff 		 * If we've been adjusting the clock, the todr
    849   1.1.2.1  cliff 		 * will be out of synch; adjust it now.
    850   1.1.2.1  cliff 		 */
    851   1.1.2.1  cliff 		resettodr();
    852   1.1.2.1  cliff 	}
    853   1.1.2.1  cliff 
    854   1.1.2.1  cliff 	splhigh();
    855   1.1.2.1  cliff 
    856   1.1.2.1  cliff 	if (howto & RB_DUMP)
    857   1.1.2.1  cliff 		dumpsys();
    858   1.1.2.1  cliff 
    859   1.1.2.1  cliff haltsys:
    860   1.1.2.1  cliff 	doshutdownhooks();
    861   1.1.2.1  cliff 
    862   1.1.2.1  cliff 	if (howto & RB_HALT) {
    863   1.1.2.1  cliff 		printf("\n");
    864   1.1.2.1  cliff 		printf("The operating system has halted.\n");
    865   1.1.2.1  cliff 		printf("Please press any key to reboot.\n\n");
    866   1.1.2.1  cliff 		cnpollc(1);	/* For proper keyboard command handling */
    867   1.1.2.1  cliff 		cngetc();
    868   1.1.2.1  cliff 		cnpollc(0);
    869   1.1.2.1  cliff 	}
    870   1.1.2.1  cliff 
    871   1.1.2.1  cliff 	printf("rebooting...\n\n");
    872   1.1.2.1  cliff 
    873  1.1.2.12  cliff 	rmixl_reset();
    874   1.1.2.1  cliff }
    875   1.1.2.1  cliff 
    876   1.1.2.1  cliff /*
    877   1.1.2.1  cliff  * goodbye world
    878   1.1.2.1  cliff  */
    879   1.1.2.1  cliff void __attribute__((__noreturn__))
    880  1.1.2.12  cliff rmixl_reset(void)
    881   1.1.2.1  cliff {
    882  1.1.2.12  cliff 	uint32_t r;
    883  1.1.2.12  cliff 
    884  1.1.2.12  cliff 	r = RMIXL_IOREG_READ(RMIXL_IO_DEV_GPIO + RMIXL_GPIO_RESET);
    885  1.1.2.12  cliff 	r |= RMIXL_GPIO_RESET_RESET;
    886  1.1.2.12  cliff 	RMIXL_IOREG_WRITE(RMIXL_IO_DEV_GPIO + RMIXL_GPIO_RESET, r);
    887  1.1.2.12  cliff 
    888  1.1.2.12  cliff 	printf("soft reset failed, spinning...\n");
    889   1.1.2.1  cliff 	for (;;);
    890   1.1.2.1  cliff }
    891