Home | History | Annotate | Line # | Download | only in rmixl
machdep.c revision 1.1.2.42
      1  1.1.2.35   matt /*	machdep.c,v 1.1.2.34 2011/04/29 08:26:18 matt 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.34   matt  * Copyright (c) 1988 University of Utah.
     40   1.1.2.1  cliff  * Copyright (c) 1992, 1993
     41   1.1.2.1  cliff  *	The Regents of the University of California.  All rights reserved.
     42   1.1.2.1  cliff  *
     43   1.1.2.1  cliff  * This code is derived from software contributed to Berkeley by
     44   1.1.2.1  cliff  * the Systems Programming Group of the University of Utah Computer
     45   1.1.2.1  cliff  * Science Department, The Mach Operating System project at
     46   1.1.2.1  cliff  * Carnegie-Mellon University and Ralph Campbell.
     47   1.1.2.1  cliff  *
     48   1.1.2.1  cliff  * Redistribution and use in source and binary forms, with or without
     49   1.1.2.1  cliff  * modification, are permitted provided that the following conditions
     50   1.1.2.1  cliff  * are met:
     51   1.1.2.1  cliff  * 1. Redistributions of source code must retain the above copyright
     52   1.1.2.1  cliff  *    notice, this list of conditions and the following disclaimer.
     53   1.1.2.1  cliff  * 2. Redistributions in binary form must reproduce the above copyright
     54   1.1.2.1  cliff  *    notice, this list of conditions and the following disclaimer in the
     55   1.1.2.1  cliff  *    documentation and/or other materials provided with the distribution.
     56   1.1.2.1  cliff  * 3. Neither the name of the University nor the names of its contributors
     57   1.1.2.1  cliff  *    may be used to endorse or promote products derived from this software
     58   1.1.2.1  cliff  *    without specific prior written permission.
     59   1.1.2.1  cliff  *
     60   1.1.2.1  cliff  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     61   1.1.2.1  cliff  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     62   1.1.2.1  cliff  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     63   1.1.2.1  cliff  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     64   1.1.2.1  cliff  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     65   1.1.2.1  cliff  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     66   1.1.2.1  cliff  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     67   1.1.2.1  cliff  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     68   1.1.2.1  cliff  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     69   1.1.2.1  cliff  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     70   1.1.2.1  cliff  * SUCH DAMAGE.
     71   1.1.2.1  cliff  *
     72   1.1.2.1  cliff  *	@(#)machdep.c   8.3 (Berkeley) 1/12/94
     73   1.1.2.1  cliff  *	from: Utah Hdr: machdep.c 1.63 91/04/24
     74   1.1.2.1  cliff  */
     75   1.1.2.1  cliff 
     76   1.1.2.1  cliff #include <sys/cdefs.h>
     77  1.1.2.35   matt __KERNEL_RCSID(0, "machdep.c,v 1.1.2.34 2011/04/29 08:26:18 matt Exp");
     78  1.1.2.25  cliff 
     79  1.1.2.25  cliff #define __INTR_PRIVATE
     80  1.1.2.35   matt #define __MUTEX_PRIVATE
     81  1.1.2.39   matt #define _MIPS_BUS_DMA_PRIVATE
     82   1.1.2.1  cliff 
     83  1.1.2.33  cliff #include "opt_multiprocessor.h"
     84   1.1.2.1  cliff #include "opt_ddb.h"
     85   1.1.2.1  cliff #include "opt_com.h"
     86   1.1.2.1  cliff #include "opt_execfmt.h"
     87   1.1.2.1  cliff #include "opt_memsize.h"
     88  1.1.2.28  cliff #include "rmixl_pcix.h"
     89  1.1.2.28  cliff #include "rmixl_pcie.h"
     90   1.1.2.1  cliff 
     91   1.1.2.1  cliff #include <sys/param.h>
     92   1.1.2.1  cliff #include <sys/systm.h>
     93   1.1.2.1  cliff #include <sys/kernel.h>
     94   1.1.2.1  cliff #include <sys/buf.h>
     95   1.1.2.1  cliff #include <sys/reboot.h>
     96   1.1.2.1  cliff #include <sys/mount.h>
     97   1.1.2.1  cliff #include <sys/kcore.h>
     98   1.1.2.1  cliff #include <sys/boot_flag.h>
     99   1.1.2.1  cliff #include <sys/termios.h>
    100   1.1.2.1  cliff #include <sys/ksyms.h>
    101  1.1.2.36   matt #include <sys/intr.h>
    102   1.1.2.1  cliff #include <sys/bus.h>
    103   1.1.2.1  cliff #include <sys/device.h>
    104   1.1.2.6  cliff #include <sys/extent.h>
    105   1.1.2.6  cliff #include <sys/malloc.h>
    106   1.1.2.1  cliff 
    107   1.1.2.1  cliff #include <uvm/uvm_extern.h>
    108   1.1.2.1  cliff 
    109   1.1.2.1  cliff #include <dev/cons.h>
    110   1.1.2.1  cliff 
    111   1.1.2.1  cliff #include "ksyms.h"
    112   1.1.2.1  cliff 
    113   1.1.2.1  cliff #if NKSYMS || defined(DDB) || defined(LKM)
    114  1.1.2.34   matt #include <mips/db_machdep.h>
    115   1.1.2.1  cliff #include <ddb/db_extern.h>
    116   1.1.2.1  cliff #endif
    117   1.1.2.1  cliff 
    118  1.1.2.34   matt #include <mips/cpu.h>
    119  1.1.2.34   matt #include <mips/psl.h>
    120  1.1.2.34   matt #include <mips/cache.h>
    121  1.1.2.39   matt #include <mips/mipsNN.h>
    122  1.1.2.34   matt #include <mips/mips_opcode.h>
    123  1.1.2.36   matt #include <mips/pte.h>
    124   1.1.2.1  cliff 
    125   1.1.2.1  cliff #include "com.h"
    126   1.1.2.1  cliff #if NCOM == 0
    127   1.1.2.1  cliff #error no serial console
    128   1.1.2.1  cliff #endif
    129   1.1.2.1  cliff 
    130   1.1.2.1  cliff #include <dev/ic/comreg.h>
    131   1.1.2.1  cliff #include <dev/ic/comvar.h>
    132   1.1.2.1  cliff 
    133  1.1.2.39   matt #include <dev/pci/pcireg.h>
    134  1.1.2.39   matt #include <dev/pci/pcivar.h>
    135  1.1.2.39   matt #include <dev/pci/pciconf.h>
    136  1.1.2.39   matt 
    137  1.1.2.25  cliff #include <mips/rmi/rmixlreg.h>
    138   1.1.2.1  cliff #include <mips/rmi/rmixlvar.h>
    139  1.1.2.25  cliff #include <mips/rmi/rmixl_intr.h>
    140   1.1.2.1  cliff #include <mips/rmi/rmixl_firmware.h>
    141  1.1.2.25  cliff #include <mips/rmi/rmixl_comvar.h>
    142  1.1.2.26  cliff #include <mips/rmi/rmixl_pcievar.h>
    143  1.1.2.28  cliff #include <mips/rmi/rmixl_pcixvar.h>
    144   1.1.2.1  cliff 
    145  1.1.2.39   matt //#define MACHDEP_DEBUG 1
    146   1.1.2.6  cliff #ifdef MACHDEP_DEBUG
    147   1.1.2.6  cliff int machdep_debug=MACHDEP_DEBUG;
    148  1.1.2.39   matt # define DPRINTF(x,...)	do { if (machdep_debug) printf(x, ## __VA_ARGS__); } while(0)
    149   1.1.2.6  cliff #else
    150  1.1.2.39   matt # define DPRINTF(x,...)
    151  1.1.2.39   matt #endif
    152  1.1.2.39   matt 
    153  1.1.2.39   matt #ifdef __HAVE_PCI_CONF_HOOK
    154  1.1.2.39   matt static int rmixl_pci_conf_hook(void *, int, int, int, pcireg_t);
    155   1.1.2.6  cliff #endif
    156   1.1.2.6  cliff 
    157   1.1.2.4  cliff #ifndef CONSFREQ
    158  1.1.2.10  cliff # define CONSFREQ 66000000
    159   1.1.2.4  cliff #endif
    160   1.1.2.1  cliff #ifndef CONSPEED
    161   1.1.2.1  cliff # define CONSPEED 38400
    162   1.1.2.1  cliff #endif
    163   1.1.2.1  cliff #ifndef CONMODE
    164   1.1.2.1  cliff # define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8)
    165   1.1.2.1  cliff #endif
    166   1.1.2.1  cliff #ifndef CONSADDR
    167  1.1.2.39   matt # define CONSADDR 0
    168   1.1.2.1  cliff #endif
    169   1.1.2.1  cliff 
    170   1.1.2.4  cliff int		comcnfreq  = CONSFREQ;
    171   1.1.2.4  cliff int		comcnspeed = CONSPEED;
    172   1.1.2.4  cliff tcflag_t	comcnmode  = CONMODE;
    173   1.1.2.1  cliff bus_addr_t	comcnaddr  = (bus_addr_t)CONSADDR;
    174   1.1.2.1  cliff 
    175  1.1.2.39   matt struct rmixl_config rmixl_configuration = {
    176  1.1.2.39   matt 	.rc_io = {
    177  1.1.2.39   matt 		.r_pbase = (bus_addr_t)-1,
    178  1.1.2.39   matt 	},
    179  1.1.2.39   matt 	.rc_flash[0] = {
    180  1.1.2.39   matt 		.r_pbase = (bus_addr_t)-1,
    181  1.1.2.39   matt 	},
    182  1.1.2.39   matt 	.rc_flash[1] = {
    183  1.1.2.39   matt 		.r_pbase = (bus_addr_t)-1,
    184  1.1.2.39   matt 	},
    185  1.1.2.39   matt 	.rc_flash[2] = {
    186  1.1.2.39   matt 		.r_pbase = (bus_addr_t)-1,
    187  1.1.2.39   matt 	},
    188  1.1.2.39   matt 	.rc_flash[3] = {
    189  1.1.2.39   matt 		.r_pbase = (bus_addr_t)-1,
    190  1.1.2.39   matt 	},
    191  1.1.2.39   matt 	.rc_pci_cfg = {
    192  1.1.2.39   matt 		.r_pbase = (bus_addr_t)-1,
    193  1.1.2.39   matt 	},
    194  1.1.2.39   matt 	.rc_pci_ecfg = {
    195  1.1.2.39   matt 		.r_pbase = (bus_addr_t)-1,
    196  1.1.2.39   matt 	},
    197  1.1.2.39   matt 	.rc_pci_mem = {
    198  1.1.2.39   matt 		.r_pbase = (bus_addr_t)-1,
    199  1.1.2.39   matt 	},
    200  1.1.2.39   matt 	.rc_pci_io = {
    201  1.1.2.39   matt 		.r_pbase = (bus_addr_t)-1,
    202  1.1.2.39   matt 	},
    203  1.1.2.39   matt 	.rc_pci_link_mem[0] = {
    204  1.1.2.39   matt 		.r_pbase = (bus_addr_t)-1,
    205  1.1.2.39   matt 	},
    206  1.1.2.39   matt 	.rc_pci_link_mem[1] = {
    207  1.1.2.39   matt 		.r_pbase = (bus_addr_t)-1,
    208  1.1.2.39   matt 	},
    209  1.1.2.39   matt 	.rc_pci_link_mem[2] = {
    210  1.1.2.39   matt 		.r_pbase = (bus_addr_t)-1,
    211  1.1.2.39   matt 	},
    212  1.1.2.39   matt 	.rc_pci_link_mem[3] = {
    213  1.1.2.39   matt 		.r_pbase = (bus_addr_t)-1,
    214  1.1.2.39   matt 	},
    215  1.1.2.39   matt 	.rc_pci_link_io[0] = {
    216  1.1.2.39   matt 		.r_pbase = (bus_addr_t)-1,
    217  1.1.2.39   matt 	},
    218  1.1.2.39   matt 	.rc_pci_link_io[1] = {
    219  1.1.2.39   matt 		.r_pbase = (bus_addr_t)-1,
    220  1.1.2.39   matt 	},
    221  1.1.2.39   matt 	.rc_pci_link_io[2] = {
    222  1.1.2.39   matt 		.r_pbase = (bus_addr_t)-1,
    223  1.1.2.39   matt 	},
    224  1.1.2.39   matt 	.rc_pci_link_io[3] = {
    225  1.1.2.39   matt 		.r_pbase = (bus_addr_t)-1,
    226  1.1.2.39   matt 	},
    227  1.1.2.39   matt 	.rc_srio_mem = {
    228  1.1.2.39   matt 		.r_pbase = (bus_addr_t)-1,
    229  1.1.2.39   matt 	},
    230  1.1.2.39   matt 	/*
    231  1.1.2.39   matt 	 * Staticly initialize the 64-bit dmatag.
    232  1.1.2.39   matt 	 */
    233  1.1.2.39   matt 	.rc_dmat64 = &rmixl_configuration.rc_dma_tag,
    234  1.1.2.39   matt 	.rc_dma_tag = {
    235  1.1.2.39   matt 		._cookie = &rmixl_configuration.rc_dma_tag,
    236  1.1.2.39   matt 		._dmamap_ops = _BUS_DMAMAP_OPS_INITIALIZER,
    237  1.1.2.39   matt 		._dmamem_ops = _BUS_DMAMEM_OPS_INITIALIZER,
    238  1.1.2.39   matt 		._dmatag_ops = _BUS_DMATAG_OPS_INITIALIZER,
    239  1.1.2.39   matt 	},
    240  1.1.2.39   matt #ifdef __HAVE_PCI_CONF_HOOK
    241  1.1.2.39   matt 	.rc_pci_chipset = {
    242  1.1.2.39   matt 		.pc_conf_hook = rmixl_pci_conf_hook,
    243  1.1.2.39   matt 	}
    244  1.1.2.39   matt #endif
    245  1.1.2.39   matt };
    246   1.1.2.1  cliff 
    247  1.1.2.36   matt #ifdef ENABLE_MIPS_KSEGX
    248  1.1.2.36   matt pt_entry_t mips_ksegx_pte;
    249  1.1.2.36   matt paddr_t mips_ksegx_start;
    250  1.1.2.36   matt #endif
    251   1.1.2.1  cliff 
    252   1.1.2.1  cliff /*
    253   1.1.2.1  cliff  * array of tested firmware versions
    254   1.1.2.4  cliff  * if you find new ones and they work
    255   1.1.2.1  cliff  * please add them
    256   1.1.2.1  cliff  */
    257  1.1.2.18  cliff typedef struct rmiclfw_psb_id {
    258  1.1.2.18  cliff 	uint64_t		psb_version;
    259  1.1.2.18  cliff 	rmixlfw_psb_type_t	psb_type;
    260  1.1.2.18  cliff } rmiclfw_psb_id_t;
    261  1.1.2.18  cliff static rmiclfw_psb_id_t rmiclfw_psb_id[] = {
    262  1.1.2.18  cliff 	{	0x4958d4fb00000056ULL, PSB_TYPE_RMI  },
    263  1.1.2.18  cliff 	{	0x4aacdb6a00000056ULL, PSB_TYPE_RMI  },
    264  1.1.2.29  cliff 	{	0x4b67d03200000056ULL, PSB_TYPE_RMI  },
    265  1.1.2.30   matt 	{	0x4c17058b00000056ULL, PSB_TYPE_RMI  },
    266  1.1.2.26  cliff 	{	0x49a5a8fa00000056ULL, PSB_TYPE_DELL },
    267  1.1.2.26  cliff 	{	0x4b8ead3100000056ULL, PSB_TYPE_DELL },
    268   1.1.2.1  cliff };
    269   1.1.2.1  cliff #define RMICLFW_PSB_VERSIONS_LEN \
    270  1.1.2.18  cliff 	(sizeof(rmiclfw_psb_id)/sizeof(rmiclfw_psb_id[0]))
    271   1.1.2.1  cliff 
    272   1.1.2.1  cliff /*
    273   1.1.2.6  cliff  * storage for fixed extent used to allocate physical address regions
    274   1.1.2.6  cliff  * because extent(9) start and end values are u_long, they are only
    275   1.1.2.6  cliff  * 32 bits on a 32 bit kernel, which is insuffucuent since XLS physical
    276   1.1.2.6  cliff  * address is 40 bits wide.  So the "physaddr" map stores regions
    277   1.1.2.6  cliff  * in units of megabytes.
    278   1.1.2.6  cliff  */
    279   1.1.2.6  cliff static u_long rmixl_physaddr_storage[
    280   1.1.2.6  cliff 	EXTENT_FIXED_STORAGE_SIZE(32)/sizeof(u_long)
    281   1.1.2.6  cliff ];
    282   1.1.2.6  cliff 
    283   1.1.2.1  cliff /* For sysctl_hw. */
    284   1.1.2.1  cliff extern char cpu_model[];
    285   1.1.2.1  cliff 
    286  1.1.2.39   matt /* Our exported CPU info; we can have only one. */
    287   1.1.2.1  cliff struct cpu_info cpu_info_store;
    288   1.1.2.1  cliff 
    289   1.1.2.1  cliff /* Maps for VM objects. */
    290   1.1.2.1  cliff struct vm_map *mb_map = NULL;
    291   1.1.2.1  cliff struct vm_map *phys_map = NULL;
    292   1.1.2.1  cliff 
    293   1.1.2.1  cliff int	physmem;		/* Total physical memory */
    294   1.1.2.1  cliff 
    295   1.1.2.1  cliff int	netboot;		/* Are we netbooting? */
    296   1.1.2.1  cliff 
    297   1.1.2.1  cliff 
    298   1.1.2.1  cliff phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];
    299  1.1.2.28  cliff u_quad_t mem_cluster_maxaddr;
    300   1.1.2.6  cliff u_int mem_cluster_cnt;
    301   1.1.2.6  cliff 
    302   1.1.2.1  cliff 
    303   1.1.2.1  cliff void configure(void);
    304   1.1.2.7  cliff void mach_init(int, int32_t *, void *, int64_t);
    305  1.1.2.16  cliff static uint64_t rmixlfw_init(int64_t);
    306  1.1.2.16  cliff static uint64_t mem_clusters_init(rmixlfw_mmap_t *, rmixlfw_mmap_t *);
    307  1.1.2.12  cliff static void __attribute__((__noreturn__)) rmixl_reset(void);
    308  1.1.2.39   matt static uint64_t rmixl_physaddr_init(void);
    309   1.1.2.6  cliff static u_int ram_seg_resv(phys_ram_seg_t *, u_int, u_quad_t, u_quad_t);
    310  1.1.2.39   matt void rmixlfw_mmap_print(const char *, rmixlfw_mmap_t *);
    311   1.1.2.1  cliff 
    312  1.1.2.16  cliff 
    313  1.1.2.14  cliff #ifdef MULTIPROCESSOR
    314  1.1.2.22   matt static bool rmixl_fixup_cop0_oscratch(int32_t, uint32_t [2]);
    315  1.1.2.14  cliff void rmixl_get_wakeup_info(struct rmixl_config *);
    316  1.1.2.14  cliff #ifdef MACHDEP_DEBUG
    317  1.1.2.14  cliff static void rmixl_wakeup_info_print(volatile rmixlfw_cpu_wakeup_info_t *);
    318  1.1.2.25  cliff #endif	/* MACHDEP_DEBUG */
    319  1.1.2.25  cliff #endif	/* MULTIPROCESSOR */
    320  1.1.2.34   matt static void rmixl_fixup_curcpu(void);
    321   1.1.2.1  cliff 
    322  1.1.2.38   matt #if NCOM > 0
    323  1.1.2.38   matt static volatile uint32_t *rmixl_com0addr;
    324  1.1.2.39   matt 
    325  1.1.2.38   matt static int
    326  1.1.2.38   matt rmixl_cngetc(dev_t dv)
    327  1.1.2.38   matt {
    328  1.1.2.38   matt 	volatile uint32_t * const com0addr = rmixl_com0addr;
    329  1.1.2.38   matt 
    330  1.1.2.38   matt         if ((be32toh(com0addr[com_lsr]) & LSR_RXRDY) == 0)
    331  1.1.2.38   matt 		return -1;
    332  1.1.2.38   matt 
    333  1.1.2.38   matt 	return be32toh(com0addr[com_data]) & 0xff;
    334  1.1.2.38   matt }
    335  1.1.2.38   matt 
    336  1.1.2.38   matt static void
    337  1.1.2.38   matt rmixl_cnputc(dev_t dv, int c)
    338  1.1.2.39   matt {
    339  1.1.2.38   matt 	volatile uint32_t * const com0addr = rmixl_com0addr;
    340  1.1.2.38   matt 	int timo = 150000;
    341  1.1.2.38   matt 
    342  1.1.2.38   matt 	while ((be32toh(com0addr[com_lsr]) & LSR_TXRDY) == 0 && --timo > 0)
    343  1.1.2.38   matt 		;
    344  1.1.2.38   matt 
    345  1.1.2.38   matt 	com0addr[com_data] = htobe32(c);
    346  1.1.2.38   matt 	__asm __volatile("sync");
    347  1.1.2.39   matt 
    348  1.1.2.38   matt 	while ((be32toh(com0addr[com_lsr]) & LSR_TSRE) == 0 && --timo > 0)
    349  1.1.2.38   matt 		;
    350  1.1.2.38   matt }
    351  1.1.2.38   matt 
    352  1.1.2.38   matt struct consdev rmixl_earlycons = {
    353  1.1.2.38   matt 	.cn_putc = rmixl_cnputc,
    354  1.1.2.38   matt 	.cn_getc = rmixl_cngetc,
    355  1.1.2.38   matt 	.cn_pollc = nullcnpollc,
    356  1.1.2.38   matt };
    357  1.1.2.38   matt #endif
    358  1.1.2.38   matt 
    359   1.1.2.1  cliff /*
    360   1.1.2.1  cliff  * Do all the stuff that locore normally does before calling main().
    361   1.1.2.1  cliff  */
    362   1.1.2.1  cliff void
    363   1.1.2.7  cliff mach_init(int argc, int32_t *argv, void *envp, int64_t infop)
    364   1.1.2.1  cliff {
    365   1.1.2.4  cliff 	struct rmixl_config *rcp = &rmixl_configuration;
    366  1.1.2.11   matt 	void *kernend;
    367  1.1.2.16  cliff 	uint64_t memsize;
    368   1.1.2.1  cliff 	extern char edata[], end[];
    369  1.1.2.36   matt 	size_t fl_count = 0;
    370  1.1.2.36   matt 	struct mips_vmfreelist fl[1];
    371  1.1.2.39   matt 	bool uboot_p = false;
    372  1.1.2.39   matt 
    373  1.1.2.39   matt 	const uint32_t cfg0 = mips3_cp0_config_read();
    374  1.1.2.39   matt #if (MIPS64_XLR + MIPS64_XLS) > 0 && (MIPS64_XLP) == 0
    375  1.1.2.39   matt 	const bool is_xlp_p = false	/* make sure cfg0 is used */
    376  1.1.2.39   matt 	    && MIPSNN_GET(CFG_AR, cfg0) == MIPSNN_CFG_AR_REV2;
    377  1.1.2.39   matt 	KASSERT(MIPSNN_GET(CFG_AR, cfg0) == MIPSNN_CFG_AR_REV1);
    378  1.1.2.39   matt #elif (MIPS64_XLR + MIPS64_XLS) == 0 && (MIPS64_XLP) > 0
    379  1.1.2.39   matt 	const bool is_xlp_p = true	/* make sure cfg0 is used */
    380  1.1.2.39   matt 	    || MIPSNN_GET(CFG_AR, cfg0) == MIPSNN_CFG_AR_REV2;
    381  1.1.2.39   matt 	KASSERT(MIPSNN_GET(CFG_AR, cfg0) == MIPSNN_CFG_AR_REV2);
    382  1.1.2.39   matt #else
    383  1.1.2.39   matt 	const bool is_xlp_p = (MIPSNN_GET(CFG_AR, cfg0) == MIPSNN_CFG_AR_REV2);
    384  1.1.2.39   matt #endif
    385   1.1.2.1  cliff 
    386  1.1.2.39   matt 	rmixl_pcr_init_core(is_xlp_p);
    387   1.1.2.8  cliff 
    388  1.1.2.37   matt #ifdef MULTIPROCESSOR
    389  1.1.2.37   matt 	__asm __volatile("dmtc0 %0,$%1,2"
    390  1.1.2.37   matt 	    ::	"r"(&pmap_tlb0_info.ti_hwlock->mtx_lock),
    391  1.1.2.37   matt 		"n"(MIPS_COP_0_OSSCRATCH));
    392  1.1.2.37   matt #endif
    393  1.1.2.37   matt 
    394   1.1.2.1  cliff 	/*
    395   1.1.2.1  cliff 	 * Clear the BSS segment.
    396   1.1.2.1  cliff 	 */
    397   1.1.2.1  cliff 	kernend = (void *)mips_round_page(end);
    398   1.1.2.1  cliff 	memset(edata, 0, (char *)kernend - edata);
    399   1.1.2.1  cliff 
    400  1.1.2.38   matt #if NCOM > 0
    401  1.1.2.39   matt 	/*
    402  1.1.2.39   matt 	 * If no comcnaddr has been set, pick an appropriate one.
    403  1.1.2.39   matt 	 */
    404  1.1.2.39   matt 	if (comcnaddr == 0) {
    405  1.1.2.39   matt 		comcnaddr = is_xlp_p
    406  1.1.2.39   matt 		    ? RMIXLP_UART1_PCITAG
    407  1.1.2.39   matt 		    : RMIXL_IO_DEV_UART_1;
    408  1.1.2.39   matt 	}
    409  1.1.2.39   matt 	if (is_xlp_p) {
    410  1.1.2.39   matt #if (MIPS64_XLP) > 0
    411  1.1.2.39   matt 		rmixl_com0addr =
    412  1.1.2.39   matt 		    (void *)(vaddr_t)(RMIXLP_SBC_PCIE_ECFG_VBASE | comcnaddr | 0x100);
    413  1.1.2.39   matt #endif /* MIPS64_XLP */
    414  1.1.2.39   matt 	} else {
    415  1.1.2.39   matt #if (MIPS64_XLR + MIPS64_XLS) > 0
    416  1.1.2.39   matt 		rcp->rc_io.r_pbase = RMIXL_IO_DEV_PBASE;
    417  1.1.2.39   matt 		rmixl_com0addr =
    418  1.1.2.39   matt 		    (void *)(vaddr_t)(RMIXL_IO_DEV_VBASE | comcnaddr);
    419  1.1.2.39   matt #endif /* (MIPS64_XLR + MIPS64_XLS) > 0 */
    420  1.1.2.39   matt 	}
    421  1.1.2.39   matt 	cn_tab = &rmixl_earlycons;
    422  1.1.2.38   matt #endif
    423  1.1.2.38   matt 
    424   1.1.2.1  cliff 	/*
    425   1.1.2.1  cliff 	 * Set up the exception vectors and CPU-specific function
    426   1.1.2.1  cliff 	 * vectors early on.  We need the wbflush() vector set up
    427   1.1.2.1  cliff 	 * before comcnattach() is called (or at least before the
    428   1.1.2.1  cliff 	 * first printf() after that is called).
    429   1.1.2.1  cliff 	 * Also clears the I+D caches.
    430  1.1.2.25  cliff 	 *
    431  1.1.2.25  cliff 	 * specify chip-specific EIRR/EIMR based spl functions
    432   1.1.2.1  cliff 	 */
    433  1.1.2.34   matt #ifdef MULTIPROCESSOR
    434  1.1.2.34   matt 	mips_vector_init(&rmixl_splsw, true);
    435  1.1.2.34   matt #else
    436  1.1.2.34   matt 	mips_vector_init(&rmixl_splsw, false);
    437  1.1.2.34   matt #endif
    438   1.1.2.1  cliff 
    439  1.1.2.39   matt 	if (argc < 0) {
    440  1.1.2.39   matt 		void *bd = (void *)(intptr_t)argc;
    441  1.1.2.39   matt 		void *imgaddr = argv;
    442  1.1.2.39   matt 		void *consdev = envp;
    443  1.1.2.39   matt 		char *bootargs = (void *)(intptr_t)infop;
    444  1.1.2.39   matt 		printf("%s: u-boot: boardinfo=%p, image-addr=%p, consdev=%p, bootargs=%p <%s>\n",
    445  1.1.2.39   matt 		    __func__, bd, imgaddr, consdev, bootargs, bootargs);
    446  1.1.2.39   matt 		uboot_p = true;
    447  1.1.2.39   matt 		printf("%s: u-boot: console baudrate=%d\n", __func__,
    448  1.1.2.39   matt 		    *(int *)bd);
    449  1.1.2.39   matt 		if (*(int *)bd % 1200 == 0)
    450  1.1.2.39   matt 			comcnspeed = *(int *)bd;
    451  1.1.2.39   matt 	} else {
    452  1.1.2.39   matt 		DPRINTF("%s: argc=%d, argv=%p, envp=%p, info=%#"PRIx64"\n",
    453  1.1.2.39   matt 		    __func__, argc, argv, envp, infop);
    454  1.1.2.39   matt 	}
    455  1.1.2.39   matt 
    456  1.1.2.15   matt 	/* mips_vector_init initialized mips_options */
    457  1.1.2.15   matt 	strcpy(cpu_model, mips_options.mips_cpu->cpu_name);
    458  1.1.2.14  cliff 
    459  1.1.2.39   matt 	if (is_xlp_p) {
    460  1.1.2.39   matt #if (MIPS64_XLP) > 0
    461  1.1.2.39   matt 		uint32_t cfg6 = mipsNN_cp0_config6_read();
    462  1.1.2.39   matt 		printf("%s: cfg6=%#x "
    463  1.1.2.39   matt 		    "<ctlb=%u,vtlb=%u,elvt=%u,epw=%u,eft=%u,pwi=%u,fti=%u>\n",
    464  1.1.2.39   matt 		    __func__, cfg6,
    465  1.1.2.39   matt 		    MIPSNN_GET(RMIXLP_CFG6_CTLB_SIZE, cfg6),
    466  1.1.2.39   matt 		    MIPSNN_GET(RMIXLP_CFG6_VTLB_SIZE, cfg6),
    467  1.1.2.39   matt 		    __SHIFTOUT(cfg6, MIPSNN_RMIXLP_CFG6_ELVT),
    468  1.1.2.39   matt 		    __SHIFTOUT(cfg6, MIPSNN_RMIXLP_CFG6_EPW),
    469  1.1.2.39   matt 		    __SHIFTOUT(cfg6, MIPSNN_RMIXLP_CFG6_EFT),
    470  1.1.2.39   matt 		    __SHIFTOUT(cfg6, MIPSNN_RMIXLP_CFG6_PWI),
    471  1.1.2.39   matt 		    __SHIFTOUT(cfg6, MIPSNN_RMIXLP_CFG6_FTI));
    472  1.1.2.39   matt 		rcp->rc_pci_ecfg.r_pbase = RMIXLP_SBC_PCIE_ECFG_PBASE;
    473  1.1.2.39   matt 		rcp->rc_pci_ecfg.r_size = RMIXLP_SBC_PCIE_ECFG_SIZE(
    474  1.1.2.39   matt 		    RMIXLP_SBC_PCIE_ECFG_PBASE,
    475  1.1.2.39   matt 		    RMIXLP_SBC_PCIE_ECFG_TO_PA(
    476  1.1.2.39   matt 			rmixlp_read_4(RMIXLP_SBC_PCITAG,
    477  1.1.2.39   matt 			    RMIXLP_SBC_PCIE_ECFG_LIMIT)));
    478  1.1.2.39   matt 
    479  1.1.2.39   matt 		DPRINTF("%s: ecfg pbase=%#"PRIxBUSADDR" size=%#"PRIxBUSSIZE"\n",
    480  1.1.2.39   matt 		    __func__, rcp->rc_pci_ecfg.r_pbase,
    481  1.1.2.39   matt 		    rcp->rc_pci_ecfg.r_size);
    482  1.1.2.39   matt 
    483  1.1.2.39   matt 		rmixl_pci_ecfg_eb_bus_mem_init(&rcp->rc_pci_ecfg_eb_memt, rcp);
    484  1.1.2.39   matt 		rmixl_pci_ecfg_el_bus_mem_init(&rcp->rc_pci_ecfg_el_memt, rcp);
    485  1.1.2.39   matt 		rcp->rc_pci_ecfg_eb_memh = MIPS_PHYS_TO_KSEG1(rcp->rc_pci_ecfg.r_pbase);
    486  1.1.2.39   matt 		rcp->rc_pci_ecfg_el_memh = rcp->rc_pci_ecfg_eb_memh;
    487  1.1.2.39   matt 		DPRINTF("%s: pci ecfg bus space done!\n", __func__);
    488  1.1.2.39   matt 		rmixlp_pcie_pc_init();
    489  1.1.2.39   matt 		DPRINTF("%s: pci chipset init done!\n", __func__);
    490  1.1.2.39   matt #if NCOM > 0
    491  1.1.2.39   matt 		comcnfreq = 133333333;
    492  1.1.2.39   matt 		com_pci_cnattach(comcnaddr, comcnspeed,
    493  1.1.2.39   matt 		    comcnfreq, COM_TYPE_NORMAL, comcnmode);
    494  1.1.2.39   matt 		DPRINTF("%s: com@pci console attached!\n", __func__);
    495  1.1.2.39   matt #endif
    496  1.1.2.39   matt #endif /* MIPS64_XLP */
    497  1.1.2.39   matt 	}
    498  1.1.2.39   matt 
    499  1.1.2.39   matt 	/* determine DRAM first */
    500  1.1.2.39   matt 	memsize = rmixl_physaddr_init();
    501  1.1.2.39   matt 	DPRINTF("%s: physaddr init done (memsize=%"PRIu64"MB)!\n",
    502  1.1.2.39   matt 	    __func__, memsize >> 20);
    503  1.1.2.39   matt 
    504  1.1.2.39   matt 	if (!uboot_p) {
    505  1.1.2.39   matt 		/* get system info from firmware */
    506  1.1.2.39   matt 		memsize = rmixlfw_init(infop);
    507  1.1.2.39   matt 		DPRINTF("%s: firmware init done (memsize=%"PRIu64"MB)!\n",
    508  1.1.2.39   matt 		    __func__, memsize >> 20);
    509  1.1.2.39   matt 	} else {
    510  1.1.2.39   matt 		rcp->rc_psb_info.userapp_cpu_map = 1;
    511  1.1.2.39   matt 	}
    512   1.1.2.1  cliff 
    513   1.1.2.1  cliff 	/* set the VM page size */
    514   1.1.2.1  cliff 	uvm_setpagesize();
    515   1.1.2.1  cliff 
    516   1.1.2.1  cliff 	physmem = btoc(memsize);
    517   1.1.2.1  cliff 
    518  1.1.2.39   matt 	if (!is_xlp_p) {
    519  1.1.2.39   matt #if (MIPS64_XLR + MIPS64_XLS) > 0
    520  1.1.2.39   matt 		rmixl_obio_eb_bus_mem_init(&rcp->rc_obio_eb_memt, rcp);
    521   1.1.2.1  cliff #if NCOM > 0
    522  1.1.2.39   matt 		rmixl_com_cnattach(comcnaddr, comcnspeed, comcnfreq,
    523  1.1.2.39   matt 		    COM_TYPE_NORMAL, comcnmode);
    524   1.1.2.1  cliff #endif
    525  1.1.2.39   matt #endif /* (MIPS64_XLR + MIPS64_XLS) > 0 */
    526  1.1.2.39   matt 	}
    527   1.1.2.1  cliff 
    528   1.1.2.1  cliff 	printf("\nNetBSD/rmixl\n");
    529  1.1.2.16  cliff 	printf("memsize = %#"PRIx64"\n", memsize);
    530  1.1.2.25  cliff #ifdef MEMLIMIT
    531  1.1.2.25  cliff 	printf("memlimit = %#"PRIx64"\n", (uint64_t)MEMLIMIT);
    532  1.1.2.25  cliff #endif
    533   1.1.2.1  cliff 
    534  1.1.2.14  cliff #if defined(MULTIPROCESSOR) && defined(MACHDEP_DEBUG)
    535  1.1.2.39   matt 	if (!uboot_p) {
    536  1.1.2.39   matt 		rmixl_wakeup_info_print(rcp->rc_cpu_wakeup_info);
    537  1.1.2.39   matt 		rmixl_wakeup_info_print(rcp->rc_cpu_wakeup_info + 1);
    538  1.1.2.39   matt 		printf("cpu_wakeup_info %p, cpu_wakeup_end %p\n",
    539  1.1.2.39   matt 			rcp->rc_cpu_wakeup_info,
    540  1.1.2.39   matt 			rcp->rc_cpu_wakeup_end);
    541  1.1.2.39   matt 		printf("userapp_cpu_map: %#"PRIx64"\n",
    542  1.1.2.39   matt 			rcp->rc_psb_info.userapp_cpu_map);
    543  1.1.2.39   matt 		printf("wakeup: %#"PRIx64"\n", rcp->rc_psb_info.wakeup);
    544  1.1.2.39   matt 	}
    545  1.1.2.17  cliff {
    546  1.1.2.17  cliff 	register_t sp;
    547  1.1.2.17  cliff 	asm volatile ("move	%0, $sp\n" : "=r"(sp));
    548  1.1.2.17  cliff 	printf("sp: %#"PRIx64"\n", sp);
    549  1.1.2.17  cliff }
    550  1.1.2.14  cliff #endif
    551  1.1.2.14  cliff 
    552   1.1.2.1  cliff 	/*
    553   1.1.2.1  cliff 	 * Obtain the cpu frequency
    554   1.1.2.1  cliff 	 * Compute the number of ticks for hz.
    555   1.1.2.1  cliff 	 * Compute the delay divisor.
    556   1.1.2.1  cliff 	 * Double the Hz if this CPU runs at twice the
    557   1.1.2.1  cliff          *  external/cp0-count frequency
    558   1.1.2.1  cliff 	 */
    559  1.1.2.39   matt 	if (uboot_p) {
    560  1.1.2.39   matt 		/*
    561  1.1.2.39   matt 		 * Since u-boot doesn't tell us, we have to figure it out
    562  1.1.2.39   matt 		 */
    563  1.1.2.39   matt 		if (is_xlp_p) {
    564  1.1.2.39   matt #if (MIPS64_XLP) > 0
    565  1.1.2.39   matt 			uint32_t por_cfg = rmixlp_read_4(RMIXLP_SM_PCITAG,
    566  1.1.2.39   matt 			    RMIXLP_SM_POWER_ON_RESET_CFG);
    567  1.1.2.39   matt 			u_int cdv = __SHIFTOUT(por_cfg, RMIXLP_SM_POWER_ON_RESET_CFG_CDV) + 1;
    568  1.1.2.39   matt 			u_int cdf = __SHIFTOUT(por_cfg, RMIXLP_SM_POWER_ON_RESET_CFG_CDF) + 1;
    569  1.1.2.39   matt 			u_int cdr = __SHIFTOUT(por_cfg, RMIXLP_SM_POWER_ON_RESET_CFG_CDR) + 1;
    570  1.1.2.39   matt 			u_int cpll_dfs = __SHIFTOUT(por_cfg, RMIXLP_SM_POWER_ON_RESET_CFG_CPLL_DFS) + 1;
    571  1.1.2.39   matt 
    572  1.1.2.39   matt 			uint64_t freq_in = 133333333;
    573  1.1.2.39   matt 			uint64_t freq_out = (freq_in / cdr) * cdf / (cdv * cpll_dfs);
    574  1.1.2.39   matt 			if (freq_out % 1000 > 900) {
    575  1.1.2.39   matt 				freq_out = (freq_out + 99) / 100;
    576  1.1.2.39   matt 				freq_out *= 100;
    577  1.1.2.39   matt 			}
    578  1.1.2.39   matt 			rcp->rc_psb_info.cpu_frequency = freq_out;
    579  1.1.2.39   matt #endif /* MIPS64_XLP > 0 */
    580  1.1.2.39   matt 		} else {
    581  1.1.2.39   matt #if (MIPS64_XLR + MIPS64_XLS) > 0
    582  1.1.2.39   matt 			const uint32_t por_cfg = RMIXL_IOREG_READ(
    583  1.1.2.39   matt 			    RMIXL_IO_DEV_GPIO + RMIXL_GPIO_RESET_CFG);
    584  1.1.2.39   matt 
    585  1.1.2.39   matt 			const u_int divq = __SHIFTOUT(por_cfg,
    586  1.1.2.39   matt 			    RMIXL_GPIO_RESET_CFG_PLL1_OUT_DIV);
    587  1.1.2.39   matt 			const u_int divf = __SHIFTOUT(por_cfg,
    588  1.1.2.39   matt 			    RMIXL_GPIO_RESET_CFG_PLL1_FB_DIV) + 1;
    589  1.1.2.39   matt 
    590  1.1.2.39   matt 			uint64_t freq_in = 66666666;
    591  1.1.2.39   matt 			uint64_t freq_out = (freq_in / 4) * divf / divq;
    592  1.1.2.39   matt 
    593  1.1.2.39   matt 			if (freq_out % 1000 > 900) {
    594  1.1.2.39   matt 				freq_out = (freq_out + 99) / 100;
    595  1.1.2.39   matt 				freq_out *= 100;
    596  1.1.2.39   matt 			}
    597  1.1.2.39   matt 			rcp->rc_psb_info.cpu_frequency = freq_out;
    598  1.1.2.39   matt #endif /* (MIPS64_XLR + MIPS64_XLS) > 0 */
    599  1.1.2.39   matt 		}
    600  1.1.2.39   matt 	}
    601  1.1.2.39   matt 	DPRINTF("%s: cpu_freq=%"PRIu64"\n", __func__,
    602  1.1.2.39   matt 	    rcp->rc_psb_info.cpu_frequency);
    603  1.1.2.17  cliff 	curcpu()->ci_cpu_freq = rcp->rc_psb_info.cpu_frequency;
    604  1.1.2.15   matt 	curcpu()->ci_cctr_freq = curcpu()->ci_cpu_freq;
    605   1.1.2.1  cliff 	curcpu()->ci_cycles_per_hz = (curcpu()->ci_cpu_freq + hz / 2) / hz;
    606   1.1.2.1  cliff 	curcpu()->ci_divisor_delay =
    607   1.1.2.1  cliff 		((curcpu()->ci_cpu_freq + 500000) / 1000000);
    608  1.1.2.15   matt         if (mips_options.mips_cpu_flags & CPU_MIPS_DOUBLE_COUNT)
    609   1.1.2.1  cliff 		curcpu()->ci_cpu_freq *= 2;
    610   1.1.2.1  cliff 
    611   1.1.2.1  cliff 	/*
    612   1.1.2.1  cliff 	 * Look at arguments passed to us and compute boothowto.
    613   1.1.2.1  cliff 	 * - rmixl firmware gives us a 32 bit argv[i], so adapt
    614   1.1.2.1  cliff 	 *   by forcing sign extension in cast to (char *)
    615   1.1.2.1  cliff 	 */
    616   1.1.2.1  cliff 	boothowto = RB_AUTOBOOT;
    617  1.1.2.39   matt 	// boothowto |= AB_VERBOSE;
    618  1.1.2.42   matt 	// boothowto |= AB_DEBUG;
    619  1.1.2.39   matt 	if (!uboot_p) {
    620  1.1.2.39   matt 		for (int i = 1; i < argc; i++) {
    621  1.1.2.39   matt 			for (char *cp = (char *)(intptr_t)argv[i]; *cp; cp++) {
    622  1.1.2.39   matt 				int howto;
    623  1.1.2.39   matt 				/* Ignore superfluous '-', if there is one */
    624  1.1.2.39   matt 				if (*cp == '-')
    625  1.1.2.39   matt 					continue;
    626  1.1.2.39   matt 
    627  1.1.2.39   matt 				howto = 0;
    628  1.1.2.39   matt 				BOOT_FLAG(*cp, howto);
    629  1.1.2.39   matt 				if (howto != 0)
    630  1.1.2.39   matt 					boothowto |= howto;
    631   1.1.2.6  cliff #ifdef DIAGNOSTIC
    632  1.1.2.39   matt 				else
    633  1.1.2.39   matt 					printf("bootflag '%c' not recognised\n",
    634  1.1.2.39   matt 					     *cp);
    635   1.1.2.6  cliff #endif
    636  1.1.2.39   matt 			}
    637   1.1.2.1  cliff 		}
    638   1.1.2.1  cliff 	}
    639   1.1.2.6  cliff #ifdef DIAGNOSTIC
    640   1.1.2.1  cliff 	printf("boothowto %#x\n", boothowto);
    641   1.1.2.6  cliff #endif
    642   1.1.2.1  cliff 
    643   1.1.2.1  cliff 	/*
    644   1.1.2.6  cliff 	 * Reserve pages from the VM system.
    645   1.1.2.6  cliff 	 */
    646   1.1.2.6  cliff 
    647   1.1.2.6  cliff 	/* reserve 0..start..kernend pages */
    648  1.1.2.28  cliff 	mem_cluster_cnt = ram_seg_resv(mem_clusters, mem_cluster_cnt,
    649   1.1.2.6  cliff 		0, round_page(MIPS_KSEG0_TO_PHYS(kernend)));
    650   1.1.2.6  cliff 
    651   1.1.2.6  cliff 	/* reserve reset exception vector page */
    652   1.1.2.9  cliff 	/* should never be in our clusters anyway... */
    653  1.1.2.28  cliff 	mem_cluster_cnt = ram_seg_resv(mem_clusters, mem_cluster_cnt,
    654  1.1.2.12  cliff 		0x1FC00000, 0x1FC00000+NBPG);
    655   1.1.2.6  cliff 
    656  1.1.2.39   matt 	/* Stop this abomination */
    657  1.1.2.39   matt 	mem_cluster_cnt = ram_seg_resv(mem_clusters, mem_cluster_cnt,
    658  1.1.2.39   matt 		0x18000000, 0x20000000);
    659  1.1.2.39   matt 
    660  1.1.2.36   matt #ifdef MULTIPROCESSOR
    661  1.1.2.14  cliff 	/* reserve the cpu_wakeup_info area */
    662  1.1.2.28  cliff 	mem_cluster_cnt = ram_seg_resv(mem_clusters, mem_cluster_cnt,
    663  1.1.2.37   matt 		(u_quad_t)trunc_page((vaddr_t)rcp->rc_cpu_wakeup_info),
    664  1.1.2.37   matt 		(u_quad_t)round_page((vaddr_t)rcp->rc_cpu_wakeup_end));
    665  1.1.2.14  cliff #endif
    666  1.1.2.14  cliff 
    667  1.1.2.18  cliff #ifdef MEMLIMIT
    668  1.1.2.25  cliff 	/* reserve everything >= MEMLIMIT */
    669  1.1.2.28  cliff 	mem_cluster_cnt = ram_seg_resv(mem_clusters, mem_cluster_cnt,
    670  1.1.2.18  cliff 		(u_quad_t)MEMLIMIT, (u_quad_t)~0);
    671  1.1.2.14  cliff #endif
    672  1.1.2.14  cliff 
    673  1.1.2.36   matt #ifdef ENABLE_MIPS_KSEGX
    674  1.1.2.36   matt 	/*
    675  1.1.2.36   matt 	 * Now we need to reserve an aligned block of memory for pre-init
    676  1.1.2.36   matt 	 * allocations so we don't deplete KSEG0.
    677  1.1.2.36   matt 	 */
    678  1.1.2.36   matt 	for (u_int i=0; i < mem_cluster_cnt; i++) {
    679  1.1.2.36   matt 		u_quad_t finish = round_page(
    680  1.1.2.36   matt 			mem_clusters[i].start + mem_clusters[i].size);
    681  1.1.2.36   matt 		u_quad_t start = roundup2(mem_clusters[i].start, VM_KSEGX_SIZE);
    682  1.1.2.36   matt 		if (start > MIPS_PHYS_MASK && start + VM_KSEGX_SIZE <= finish) {
    683  1.1.2.36   matt 			mips_ksegx_start = start;
    684  1.1.2.36   matt 			mips_ksegx_pte.pt_entry = mips_paddr_to_tlbpfn(start)
    685  1.1.2.36   matt 			    | MIPS3_PG_D | MIPS3_PG_CACHED
    686  1.1.2.36   matt 			    | MIPS3_PG_V | MIPS3_PG_G;
    687  1.1.2.36   matt 			fl[0].fl_start = start;
    688  1.1.2.36   matt 			fl[0].fl_end = start + VM_KSEGX_SIZE;
    689  1.1.2.36   matt 			fl[0].fl_freelist = VM_FREELIST_FIRST512M;
    690  1.1.2.36   matt 			fl_count++;
    691  1.1.2.39   matt 			DPRINTF("mips_ksegx_start %#"PRIxPADDR"\n",
    692  1.1.2.39   matt 			    fl[0].fl_start);
    693  1.1.2.36   matt 			break;
    694  1.1.2.36   matt 		}
    695  1.1.2.36   matt 	}
    696  1.1.2.36   matt #endif
    697  1.1.2.36   matt 
    698  1.1.2.28  cliff 	/* get maximum RAM address from the VM clusters */
    699  1.1.2.28  cliff 	mem_cluster_maxaddr = 0;
    700  1.1.2.28  cliff 	for (u_int i=0; i < mem_cluster_cnt; i++) {
    701  1.1.2.28  cliff 		u_quad_t tmp = round_page(
    702  1.1.2.28  cliff 			mem_clusters[i].start + mem_clusters[i].size);
    703  1.1.2.28  cliff 		if (tmp > mem_cluster_maxaddr)
    704  1.1.2.28  cliff 			mem_cluster_maxaddr = tmp;
    705  1.1.2.28  cliff 	}
    706  1.1.2.39   matt 	DPRINTF("mem_cluster_maxaddr %#"PRIx64"\n", mem_cluster_maxaddr);
    707  1.1.2.28  cliff 
    708   1.1.2.6  cliff 	/*
    709  1.1.2.28  cliff 	 * Load mem_clusters[] into the VM system.
    710   1.1.2.6  cliff 	 */
    711  1.1.2.11   matt 	mips_page_physload(MIPS_KSEG0_START, (vaddr_t) kernend,
    712  1.1.2.36   matt 	    mem_clusters, mem_cluster_cnt, fl, fl_count);
    713   1.1.2.1  cliff 
    714   1.1.2.1  cliff 	/*
    715   1.1.2.1  cliff 	 * Initialize error message buffer (at end of core).
    716   1.1.2.1  cliff 	 */
    717   1.1.2.1  cliff 	mips_init_msgbuf();
    718   1.1.2.1  cliff 
    719   1.1.2.1  cliff 	pmap_bootstrap();
    720   1.1.2.1  cliff 
    721   1.1.2.1  cliff 	/*
    722  1.1.2.34   matt 	 * Allocate uarea page for lwp0 and set it.
    723   1.1.2.1  cliff 	 */
    724  1.1.2.11   matt 	mips_init_lwp0_uarea();
    725   1.1.2.1  cliff 
    726   1.1.2.1  cliff 	/*
    727   1.1.2.1  cliff 	 * Initialize debuggers, and break into them, if appropriate.
    728   1.1.2.1  cliff 	 */
    729   1.1.2.1  cliff #if NKSYMS || defined(DDB) || defined(LKM)
    730   1.1.2.1  cliff 	ksyms_init(0, 0, 0);
    731   1.1.2.1  cliff #endif
    732   1.1.2.1  cliff 
    733   1.1.2.1  cliff #if defined(DDB)
    734   1.1.2.1  cliff 	if (boothowto & RB_KDB)
    735   1.1.2.1  cliff 		Debugger();
    736   1.1.2.1  cliff #endif
    737  1.1.2.20   matt 	/*
    738  1.1.2.25  cliff 	 * store (cpu#0) curcpu in COP0 OSSCRATCH0
    739  1.1.2.25  cliff 	 * used in exception vector
    740  1.1.2.20   matt 	 */
    741  1.1.2.24   matt 	__asm __volatile("dmtc0 %0,$%1"
    742  1.1.2.20   matt 		:: "r"(&cpu_info_store), "n"(MIPS_COP_0_OSSCRATCH));
    743  1.1.2.34   matt #ifdef MULTIPROCESSOR
    744  1.1.2.20   matt 	mips_fixup_exceptions(rmixl_fixup_cop0_oscratch);
    745  1.1.2.20   matt #endif
    746  1.1.2.34   matt 	rmixl_fixup_curcpu();
    747  1.1.2.20   matt }
    748  1.1.2.20   matt 
    749  1.1.2.32  cliff /*
    750  1.1.2.32  cliff  * set up Processor Control Regs for this core
    751  1.1.2.32  cliff  */
    752  1.1.2.32  cliff void
    753  1.1.2.39   matt rmixl_pcr_init_core(bool is_xlp_p)
    754  1.1.2.32  cliff {
    755  1.1.2.32  cliff 	uint32_t r;
    756  1.1.2.32  cliff 
    757  1.1.2.39   matt 
    758  1.1.2.39   matt 	if (is_xlp_p) {
    759  1.1.2.39   matt #if (MIPS64_XLP) > 0
    760  1.1.2.39   matt #ifndef MULTIPROCESSOR
    761  1.1.2.39   matt 		rmixl_mtcr(RMIXLP_PCR_IFU_THREAD_EN, 1);
    762  1.1.2.39   matt 			/* disable all threads except #0 */
    763  1.1.2.39   matt #endif
    764  1.1.2.39   matt 		rmixl_mtcr(RMIXLP_PCR_MMU_SETUP, 1);
    765  1.1.2.39   matt 			/* enable MMU clock gating */
    766  1.1.2.39   matt 			/* TLB is global */
    767  1.1.2.39   matt #ifdef MIPS_DISABLE_L1_CACHE
    768  1.1.2.39   matt 		r = rmixl_mfcr(RMIXLP_PCR_L1D_CONFIG0);
    769  1.1.2.39   matt 		r &= ~__BIT(0);				/* disable L1D cache */
    770  1.1.2.39   matt 		rmixl_mtcr(RMIXLP_PCR_L1D_CONFIG0, r);
    771  1.1.2.39   matt #endif
    772  1.1.2.39   matt 		r = rmixl_mfcr(RMIXLP_PCR_LSU_DEFEATURE);
    773  1.1.2.39   matt 		r &= ~RMIXLP_PCR_LSE_DEFEATURE_EUL;
    774  1.1.2.39   matt 		rmixl_mtcr(RMIXLP_PCR_LSU_DEFEATURE, r);
    775  1.1.2.39   matt 
    776  1.1.2.39   matt 		/*
    777  1.1.2.39   matt 		 * Enable Large Variable TLB.
    778  1.1.2.39   matt 	 	 */
    779  1.1.2.39   matt 		uint32_t cfg6 = mipsNN_cp0_config6_read();
    780  1.1.2.39   matt 		cfg6 |= MIPSNN_RMIXLP_CFG6_ELVT;
    781  1.1.2.39   matt 		mipsNN_cp0_config6_write(cfg6);
    782  1.1.2.39   matt 		/*
    783  1.1.2.39   matt 		 * Force TLB Random to be rewritten.
    784  1.1.2.39   matt 		 */
    785  1.1.2.39   matt 		mips3_cp0_wired_write(0);
    786  1.1.2.39   matt #endif /* MIPS64_XLP */
    787  1.1.2.39   matt 	} else {
    788  1.1.2.39   matt #if (MIPS64_XLR + MIPS64_XLS) > 0
    789  1.1.2.32  cliff #ifdef MULTIPROCESSOR
    790  1.1.2.39   matt 		rmixl_mtcr(RMIXL_PCR_MMU_SETUP, __BITS(2,0));
    791  1.1.2.39   matt 			/* enable MMU clock gating */
    792  1.1.2.39   matt 			/* 4 threads active -- why needed if Global? */
    793  1.1.2.39   matt 			/* enable global TLB mode */
    794  1.1.2.32  cliff #else
    795  1.1.2.39   matt 		rmixl_mtcr(RMIXL_PCR_THREADEN, 1);
    796  1.1.2.39   matt 			/* disable all threads except #0 */
    797  1.1.2.39   matt 		rmixl_mtcr(RMIXL_PCR_MMU_SETUP, 0);
    798  1.1.2.39   matt 			/* enable MMU clock gating */
    799  1.1.2.39   matt 			/* set single MMU Thread Mode */
    800  1.1.2.39   matt 			/* TLB is partitioned (1 partition) */
    801  1.1.2.39   matt #endif
    802  1.1.2.39   matt 		r = rmixl_mfcr(RMIXL_PCR_L1D_CONFIG0);
    803  1.1.2.39   matt 		r &= ~__BIT(14);		/* disable Unaligned Access */
    804  1.1.2.39   matt 		rmixl_mtcr(RMIXL_PCR_L1D_CONFIG0, r);
    805  1.1.2.39   matt #endif /* (MIPS64_XLR + MIPS64_XLS) > 0 */
    806  1.1.2.39   matt 	}
    807  1.1.2.33  cliff 
    808  1.1.2.33  cliff #if defined(DDB) && defined(MIPS_DDB_WATCH)
    809  1.1.2.33  cliff 	/*
    810  1.1.2.33  cliff 	 * clear IEU_DEFEATURE[DBE]
    811  1.1.2.33  cliff 	 * this enables COP0 watchpoint to trigger T_WATCH exception
    812  1.1.2.33  cliff 	 * instead of signaling JTAG.
    813  1.1.2.33  cliff 	 */
    814  1.1.2.33  cliff 	r = rmixl_mfcr(RMIXL_PCR_IEU_DEFEATURE);
    815  1.1.2.33  cliff 	r &= ~__BIT(7);
    816  1.1.2.33  cliff 	rmixl_mtcr(RMIXL_PCR_IEU_DEFEATURE, r);
    817  1.1.2.33  cliff #endif
    818  1.1.2.32  cliff }
    819  1.1.2.32  cliff 
    820  1.1.2.20   matt #ifdef MULTIPROCESSOR
    821  1.1.2.20   matt static bool
    822  1.1.2.20   matt rmixl_fixup_cop0_oscratch(int32_t load_addr, uint32_t new_insns[2])
    823  1.1.2.20   matt {
    824  1.1.2.20   matt 	size_t offset = load_addr - (intptr_t)&cpu_info_store;
    825  1.1.2.20   matt 
    826  1.1.2.20   matt 	KASSERT(MIPS_KSEG0_P(load_addr));
    827  1.1.2.20   matt 	KASSERT(offset < sizeof(struct cpu_info));
    828  1.1.2.20   matt 
    829  1.1.2.20   matt 	/*
    830  1.1.2.21    snj 	 * Fixup this direct load cpu_info_store to actually get the current
    831  1.1.2.20   matt 	 * CPU's cpu_info from COP0 OSSCRATCH0 and then fix the load to be
    832  1.1.2.20   matt 	 * relative from the start of struct cpu_info.
    833  1.1.2.20   matt 	 */
    834  1.1.2.20   matt 
    835  1.1.2.23   matt 	/* [0] = [d]mfc0 rX, $22 (OSScratch) */
    836  1.1.2.20   matt 	new_insns[0] = (020 << 26)
    837  1.1.2.23   matt #ifdef _LP64
    838  1.1.2.23   matt 	    | (1 << 21)		/* double move */
    839  1.1.2.23   matt #endif
    840  1.1.2.20   matt 	    | (new_insns[0] & 0x001f0000)
    841  1.1.2.20   matt 	    | (MIPS_COP_0_OSSCRATCH << 11) | (0 << 0);
    842  1.1.2.20   matt 
    843  1.1.2.34   matt 	/* [1] = [ls][dw] rX, offset(rX) */
    844  1.1.2.20   matt 	new_insns[1] = (new_insns[1] & 0xffff0000) | offset;
    845  1.1.2.20   matt 
    846  1.1.2.20   matt 	return true;
    847   1.1.2.6  cliff }
    848  1.1.2.20   matt #endif /* MULTIPROCESSOR */
    849   1.1.2.6  cliff 
    850   1.1.2.6  cliff /*
    851  1.1.2.34   matt  * The following changes all	lX	rN, L_CPU(MIPS_CURLWP) [curlwp->l_cpu]
    852  1.1.2.34   matt  * to			     	[d]mfc0	rN, $22 [MIPS_COP_0_OSSCRATCH]
    853  1.1.2.34   matt  *
    854  1.1.2.34   matt  * the mfc0 is 3 cycles shorter than the load.
    855  1.1.2.34   matt  */
    856  1.1.2.34   matt #define	LOAD_CURCPU_0	((MIPS_CURLWP_REG << 21) | offsetof(lwp_t, l_cpu))
    857  1.1.2.34   matt #define	MFC0_CURCPU_0	((OP_COP0 << 26) | (MIPS_COP_0_OSSCRATCH << 11))
    858  1.1.2.34   matt #ifdef _LP64
    859  1.1.2.34   matt #define	LOAD_CURCPU	((uint32_t)(OP_LD << 26) | LOAD_CURCPU_0)
    860  1.1.2.34   matt #define	MFC0_CURCPU	((uint32_t)(OP_DMF << 21) | MFC0_CURCPU_0)
    861  1.1.2.34   matt #else
    862  1.1.2.34   matt #define	LOAD_CURCPU	((uint32_t)(OP_LW << 26) | LOAD_CURCPU_0)
    863  1.1.2.34   matt #define	MFC0_CURCPU	((uint32_t)(OP_MF << 21) | MFC0_CURCPU_0)
    864  1.1.2.34   matt #endif
    865  1.1.2.34   matt #define	LOAD_CURCPU_MASK	0xffe0ffff
    866  1.1.2.34   matt 
    867  1.1.2.34   matt static void
    868  1.1.2.34   matt rmixl_fixup_curcpu(void)
    869  1.1.2.34   matt {
    870  1.1.2.34   matt 	extern uint32_t _ftext[];
    871  1.1.2.34   matt 	extern uint32_t _etext[];
    872  1.1.2.34   matt 
    873  1.1.2.34   matt 	for (uint32_t *insnp = _ftext; insnp < _etext; insnp++) {
    874  1.1.2.34   matt 		const uint32_t insn = *insnp;
    875  1.1.2.34   matt 		if (__predict_false((insn & LOAD_CURCPU_MASK) == LOAD_CURCPU)) {
    876  1.1.2.34   matt 			/*
    877  1.1.2.34   matt 			 * Since the register to loaded is located in bits
    878  1.1.2.34   matt 			 * 16-20 for the mfc0 and the load instruction we can
    879  1.1.2.34   matt 			 * just change the instruction bits around it.
    880  1.1.2.34   matt 			 */
    881  1.1.2.34   matt 			*insnp = insn ^ LOAD_CURCPU ^ MFC0_CURCPU;
    882  1.1.2.34   matt 			mips_icache_sync_range((vaddr_t)insnp, 4);
    883  1.1.2.34   matt 		}
    884  1.1.2.34   matt 	}
    885  1.1.2.34   matt }
    886  1.1.2.34   matt 
    887  1.1.2.34   matt /*
    888   1.1.2.6  cliff  * ram_seg_resv - cut reserved regions out of segs, fragmenting as needed
    889   1.1.2.6  cliff  *
    890   1.1.2.6  cliff  * we simply build a new table of segs, then copy it back over the given one
    891   1.1.2.6  cliff  * this is inefficient but simple and called only a few times
    892   1.1.2.6  cliff  *
    893   1.1.2.6  cliff  * note: 'last' here means 1st addr past the end of the segment (start+size)
    894   1.1.2.6  cliff  */
    895   1.1.2.6  cliff static u_int
    896   1.1.2.6  cliff ram_seg_resv(phys_ram_seg_t *segs, u_int nsegs,
    897   1.1.2.6  cliff 	u_quad_t resv_first, u_quad_t resv_last)
    898   1.1.2.6  cliff {
    899   1.1.2.6  cliff         u_quad_t first, last;
    900   1.1.2.6  cliff 	int new_nsegs=0;
    901   1.1.2.6  cliff 	int resv_flag;
    902   1.1.2.6  cliff 	phys_ram_seg_t new_segs[VM_PHYSSEG_MAX];
    903   1.1.2.6  cliff 
    904   1.1.2.6  cliff 	for (u_int i=0; i < nsegs; i++) {
    905   1.1.2.6  cliff 		resv_flag = 0;
    906   1.1.2.6  cliff 		first = trunc_page(segs[i].start);
    907   1.1.2.6  cliff 		last = round_page(segs[i].start + segs[i].size);
    908   1.1.2.6  cliff 
    909   1.1.2.6  cliff 		KASSERT(new_nsegs < VM_PHYSSEG_MAX);
    910   1.1.2.6  cliff 		if ((resv_first <= first) && (resv_last >= last)) {
    911   1.1.2.6  cliff 			/* whole segment is resverved */
    912   1.1.2.6  cliff 			continue;
    913   1.1.2.6  cliff 		}
    914   1.1.2.6  cliff 		if ((resv_first > first) && (resv_first < last)) {
    915   1.1.2.6  cliff 			u_quad_t new_last;
    916   1.1.2.6  cliff 
    917   1.1.2.6  cliff 			/*
    918   1.1.2.6  cliff 			 * reserved start in segment
    919   1.1.2.6  cliff 			 * salvage the leading fragment
    920   1.1.2.6  cliff 			 */
    921   1.1.2.6  cliff 			resv_flag = 1;
    922   1.1.2.6  cliff 			new_last = last - (last - resv_first);
    923   1.1.2.6  cliff 			KASSERT (new_last > first);
    924   1.1.2.6  cliff 			new_segs[new_nsegs].start = first;
    925   1.1.2.6  cliff 			new_segs[new_nsegs].size = new_last - first;
    926   1.1.2.6  cliff 			new_nsegs++;
    927   1.1.2.6  cliff 		}
    928   1.1.2.6  cliff 		if ((resv_last > first) && (resv_last < last)) {
    929   1.1.2.6  cliff 			u_quad_t new_first;
    930   1.1.2.6  cliff 
    931   1.1.2.6  cliff 			/*
    932   1.1.2.6  cliff 			 * reserved end in segment
    933   1.1.2.6  cliff 			 * salvage the trailing fragment
    934   1.1.2.6  cliff 			 */
    935   1.1.2.6  cliff 			resv_flag = 1;
    936   1.1.2.6  cliff 			new_first = first + (resv_last - first);
    937   1.1.2.6  cliff 			KASSERT (last > (new_first + NBPG));
    938   1.1.2.6  cliff 			new_segs[new_nsegs].start = new_first;
    939   1.1.2.6  cliff 			new_segs[new_nsegs].size = last - new_first;
    940   1.1.2.6  cliff 			new_nsegs++;
    941   1.1.2.6  cliff 		}
    942   1.1.2.6  cliff 		if (resv_flag == 0) {
    943   1.1.2.6  cliff 			/*
    944   1.1.2.6  cliff 			 * nothing reserved here, take it all
    945   1.1.2.6  cliff 			 */
    946   1.1.2.6  cliff 			new_segs[new_nsegs].start = first;
    947   1.1.2.6  cliff 			new_segs[new_nsegs].size = last - first;
    948   1.1.2.6  cliff 			new_nsegs++;
    949   1.1.2.6  cliff 		}
    950   1.1.2.6  cliff 
    951   1.1.2.6  cliff 	}
    952   1.1.2.6  cliff 
    953   1.1.2.6  cliff 	memcpy(segs, new_segs, sizeof(new_segs));
    954   1.1.2.6  cliff 
    955   1.1.2.6  cliff 	return new_nsegs;
    956   1.1.2.6  cliff }
    957   1.1.2.6  cliff 
    958  1.1.2.39   matt #if (MIPS64_XLP) > 0
    959  1.1.2.39   matt static void
    960  1.1.2.39   matt rmixlp_physaddr_pcie_cfg_init(struct extent *ext)
    961  1.1.2.39   matt {
    962  1.1.2.39   matt 	struct rmixl_config * const rcp = &rmixl_configuration;
    963  1.1.2.39   matt 
    964  1.1.2.39   matt 	uint64_t xbase = RMIXLP_SBC_PCIE_CFG_TO_PA(
    965  1.1.2.39   matt 	    rmixlp_read_4(RMIXLP_SBC_PCITAG, RMIXLP_SBC_PCIE_CFG_BASE));
    966  1.1.2.39   matt 	uint64_t xlimit = RMIXLP_SBC_PCIE_CFG_TO_PA(
    967  1.1.2.39   matt 	    rmixlp_read_4(RMIXLP_SBC_PCITAG, RMIXLP_SBC_PCIE_CFG_LIMIT));
    968  1.1.2.39   matt 
    969  1.1.2.39   matt 	if (xlimit < xbase || xbase == 0)
    970  1.1.2.39   matt 		return;	/* not enabled */
    971  1.1.2.39   matt 
    972  1.1.2.39   matt 	uint64_t xsize = RMIXLP_SBC_PCIE_CFG_SIZE(xbase, xlimit);
    973  1.1.2.39   matt 
    974  1.1.2.39   matt 	DPRINTF("%s: %s: %#"PRIx64":%"PRIu64" MB\n", __func__,
    975  1.1.2.39   matt 	    "pci-cfg", xbase, xsize >> 20);
    976  1.1.2.39   matt 
    977  1.1.2.39   matt 	rmixl_physaddr_add(ext, "pcicfg", &rcp->rc_pci_cfg, xbase, xsize);
    978  1.1.2.39   matt }
    979  1.1.2.39   matt 
    980  1.1.2.39   matt static void
    981  1.1.2.39   matt rmixlp_physaddr_pcie_ecfg_init(struct extent *ext)
    982  1.1.2.39   matt {
    983  1.1.2.39   matt 	struct rmixl_config * const rcp = &rmixl_configuration;
    984  1.1.2.39   matt 
    985  1.1.2.39   matt 	uint64_t xbase = RMIXLP_SBC_PCIE_ECFG_TO_PA(
    986  1.1.2.39   matt 	    rmixlp_read_4(RMIXLP_SBC_PCITAG, RMIXLP_SBC_PCIE_ECFG_BASE));
    987  1.1.2.39   matt 	uint64_t xlimit = RMIXLP_SBC_PCIE_ECFG_TO_PA(
    988  1.1.2.39   matt 	    rmixlp_read_4(RMIXLP_SBC_PCITAG, RMIXLP_SBC_PCIE_ECFG_LIMIT));
    989  1.1.2.39   matt 
    990  1.1.2.39   matt 	if (xlimit < xbase || xbase == 0)
    991  1.1.2.39   matt 		return;	/* not enabled */
    992  1.1.2.39   matt 
    993  1.1.2.39   matt 	uint64_t xsize = RMIXLP_SBC_PCIE_ECFG_SIZE(xbase, xlimit);
    994  1.1.2.39   matt 
    995  1.1.2.39   matt 	KASSERT(rcp->rc_pci_ecfg.r_pbase == xbase);
    996  1.1.2.39   matt 
    997  1.1.2.39   matt 	DPRINTF("%s: %s: %#"PRIx64":%"PRIu64" MB\n", __func__,
    998  1.1.2.39   matt 	    "pci-ecfg", xbase, xsize >> 20);
    999  1.1.2.39   matt 
   1000  1.1.2.39   matt 	rmixl_physaddr_add(ext, "pciecfg", &rcp->rc_pci_ecfg, xbase, xsize);
   1001  1.1.2.39   matt }
   1002  1.1.2.39   matt 
   1003  1.1.2.39   matt static void
   1004  1.1.2.39   matt rmixlp_physaddr_pcie_mem_init(struct extent *ext)
   1005  1.1.2.39   matt {
   1006  1.1.2.39   matt 	struct rmixl_config * const rcp = &rmixl_configuration;
   1007  1.1.2.39   matt 	for (size_t i = 0; i < RMIXLP_SBC_NPCIE_MEM; i++) {
   1008  1.1.2.39   matt 		uint64_t xbase = RMIXLP_SBC_PCIE_MEM_TO_PA(
   1009  1.1.2.39   matt 		    rmixlp_read_4(RMIXLP_SBC_PCITAG,
   1010  1.1.2.39   matt 			RMIXLP_SBC_PCIE_MEM_BASEn(i)));
   1011  1.1.2.39   matt 		uint64_t xlimit = RMIXLP_SBC_PCIE_MEM_TO_PA(
   1012  1.1.2.39   matt 		    rmixlp_read_4(RMIXLP_SBC_PCITAG,
   1013  1.1.2.39   matt 			RMIXLP_SBC_PCIE_MEM_LIMITn(i)));
   1014  1.1.2.39   matt 
   1015  1.1.2.39   matt 		if (xlimit < xbase || xbase == 0)
   1016  1.1.2.39   matt 			continue;	/* not enabled */
   1017  1.1.2.39   matt 
   1018  1.1.2.39   matt 		uint64_t xsize = RMIXLP_SBC_PCIE_MEM_SIZE(xbase, xlimit);
   1019  1.1.2.39   matt 
   1020  1.1.2.39   matt 		DPRINTF("%s: %s %zu: %#"PRIx64":%"PRIu64" MB\n", __func__,
   1021  1.1.2.39   matt 		    "pci-mem", i, xbase, xsize >> 20);
   1022  1.1.2.39   matt 
   1023  1.1.2.39   matt 		rmixl_physaddr_add(ext, "pcimem", &rcp->rc_pci_link_mem[i],
   1024  1.1.2.39   matt 		    xbase, xsize);
   1025  1.1.2.39   matt 	}
   1026  1.1.2.39   matt }
   1027  1.1.2.39   matt 
   1028  1.1.2.39   matt static void
   1029  1.1.2.39   matt rmixlp_physaddr_pcie_io_init(struct extent *ext)
   1030  1.1.2.39   matt {
   1031  1.1.2.39   matt 	struct rmixl_config * const rcp = &rmixl_configuration;
   1032  1.1.2.39   matt 	for (size_t i = 0; i < RMIXLP_SBC_NPCIE_IO; i++) {
   1033  1.1.2.39   matt 		uint64_t xbase = RMIXLP_SBC_PCIE_IO_TO_PA(
   1034  1.1.2.39   matt 		    rmixlp_read_4(RMIXLP_SBC_PCITAG,
   1035  1.1.2.39   matt 			RMIXLP_SBC_PCIE_IO_BASEn(i)));
   1036  1.1.2.39   matt 		uint64_t xlimit = RMIXLP_SBC_PCIE_IO_TO_PA(
   1037  1.1.2.39   matt 		    rmixlp_read_4(RMIXLP_SBC_PCITAG,
   1038  1.1.2.39   matt 			RMIXLP_SBC_PCIE_IO_LIMITn(i)));
   1039  1.1.2.39   matt 
   1040  1.1.2.39   matt 		if (xlimit < xbase || xbase == 0)
   1041  1.1.2.39   matt 			continue;	/* not enabled */
   1042  1.1.2.39   matt 
   1043  1.1.2.39   matt 		uint64_t xsize = RMIXLP_SBC_PCIE_IO_SIZE(xbase, xlimit);
   1044  1.1.2.39   matt 
   1045  1.1.2.39   matt 		DPRINTF("%s: %s %zu: %#"PRIx64":%"PRIu64" MB\n", __func__,
   1046  1.1.2.39   matt 		    "pci-io", i, xbase, xsize >> 20);
   1047  1.1.2.39   matt 
   1048  1.1.2.39   matt 		rmixl_physaddr_add(ext, "pci-io", &rcp->rc_pci_link_io[i],
   1049  1.1.2.39   matt 		    xbase, xsize);
   1050  1.1.2.39   matt 	}
   1051  1.1.2.39   matt }
   1052  1.1.2.39   matt 
   1053  1.1.2.39   matt static void
   1054  1.1.2.39   matt rmixlp_physaddr_srio_mem_init(struct extent *ext)
   1055  1.1.2.39   matt {
   1056  1.1.2.39   matt 	struct rmixl_config * const rcp = &rmixl_configuration;
   1057  1.1.2.39   matt 	uint64_t xbase = RMIXLP_SBC_SRIO_MEM_TO_PA(
   1058  1.1.2.39   matt 	    rmixlp_read_4(RMIXLP_SBC_PCITAG, RMIXLP_SBC_SRIO_MEM_BASE));
   1059  1.1.2.39   matt 	uint64_t xlimit = RMIXLP_SBC_SRIO_MEM_TO_PA(
   1060  1.1.2.39   matt 	    rmixlp_read_4(RMIXLP_SBC_PCITAG, RMIXLP_SBC_SRIO_MEM_LIMIT));
   1061  1.1.2.39   matt 
   1062  1.1.2.39   matt 	if (xlimit < xbase || xbase == 0)
   1063  1.1.2.39   matt 	    return;	/* not enabled */
   1064  1.1.2.39   matt 
   1065  1.1.2.39   matt 	uint64_t xsize = RMIXLP_SBC_SRIO_MEM_SIZE(xbase, xlimit);
   1066  1.1.2.39   matt 
   1067  1.1.2.39   matt 	DPRINTF("%s: %s: %#"PRIx64":%"PRIu64" MB\n", __func__,
   1068  1.1.2.39   matt 	    "srio-mem", xbase, xsize >> 20);
   1069  1.1.2.39   matt 
   1070  1.1.2.39   matt 	rmixl_physaddr_add(ext, "sriomem", &rcp->rc_srio_mem, xbase, xsize);
   1071  1.1.2.39   matt }
   1072  1.1.2.39   matt 
   1073  1.1.2.40   matt static void
   1074  1.1.2.40   matt rmixlp_physaddr_nor_init(struct extent *ext)
   1075  1.1.2.40   matt {
   1076  1.1.2.40   matt 	struct rmixl_config * const rcp = &rmixl_configuration;
   1077  1.1.2.40   matt 	for (size_t i = 0; i < RMIXLP_NOR_NCS; i++) {
   1078  1.1.2.40   matt 		uint64_t xbase = RMIXLP_NOR_CS_ADDRESS_TO_PA(
   1079  1.1.2.40   matt 		    rmixlp_read_4(RMIXLP_NOR_PCITAG,
   1080  1.1.2.40   matt 			RMIXLP_NOR_CS_BASEADDRESSn(i)));
   1081  1.1.2.40   matt 		uint64_t xlimit = RMIXLP_NOR_CS_ADDRESS_TO_PA(
   1082  1.1.2.40   matt 		    rmixlp_read_4(RMIXLP_NOR_PCITAG,
   1083  1.1.2.40   matt 			RMIXLP_NOR_CS_BASELIMITn(i)));
   1084  1.1.2.40   matt 
   1085  1.1.2.40   matt 		if (xlimit < xbase || xbase == 0)
   1086  1.1.2.40   matt 			continue;	/* not enabled */
   1087  1.1.2.40   matt 
   1088  1.1.2.40   matt 		uint64_t xsize = RMIXLP_NOR_CS_SIZE(xbase, xlimit);
   1089  1.1.2.40   matt 
   1090  1.1.2.40   matt 		DPRINTF("%s: %s %zu: %#"PRIx64":%"PRIu64" MB\n", __func__,
   1091  1.1.2.40   matt 		    "nor", i, xbase, xsize >> 20);
   1092  1.1.2.40   matt 
   1093  1.1.2.41   matt 		rmixl_physaddr_add(ext, "nor", &rcp->rc_norflash[i],
   1094  1.1.2.40   matt 		    xbase, xsize);
   1095  1.1.2.40   matt 	}
   1096  1.1.2.40   matt }
   1097  1.1.2.40   matt 
   1098  1.1.2.39   matt static uint64_t
   1099  1.1.2.39   matt rmixlp_physaddr_dram_init(struct extent *ext)
   1100  1.1.2.39   matt {
   1101  1.1.2.39   matt 	uint64_t memsize = 0;
   1102  1.1.2.39   matt 	/*
   1103  1.1.2.39   matt 	 * grab regions per DRAM BARs
   1104  1.1.2.39   matt 	 */
   1105  1.1.2.39   matt 	phys_ram_seg_t *mp = mem_clusters;
   1106  1.1.2.39   matt 	for (u_int i = 0; i < RMIXLP_SBC_NDRAM; i++) {
   1107  1.1.2.39   matt 		uint64_t xbase =
   1108  1.1.2.39   matt 		    RMIXLP_SBC_DRAM_TO_PA(
   1109  1.1.2.39   matt 			rmixlp_read_4(RMIXLP_SBC_PCITAG,
   1110  1.1.2.39   matt 			    RMIXLP_SBC_DRAM_BASEn(i)));
   1111  1.1.2.39   matt 		uint64_t xlimit =
   1112  1.1.2.39   matt 		    RMIXLP_SBC_DRAM_TO_PA(
   1113  1.1.2.39   matt 			rmixlp_read_4(RMIXLP_SBC_PCITAG,
   1114  1.1.2.39   matt 			    RMIXLP_SBC_DRAM_LIMITn(i)));
   1115  1.1.2.39   matt 
   1116  1.1.2.39   matt 		if (xlimit < xbase)
   1117  1.1.2.39   matt 			continue;	/* not enabled */
   1118  1.1.2.39   matt 
   1119  1.1.2.39   matt 		mp->start = xbase;
   1120  1.1.2.39   matt 		mp->size = RMIXLP_SBC_DRAM_SIZE(xbase, xlimit);
   1121  1.1.2.39   matt 
   1122  1.1.2.39   matt 		memsize += mp->size;
   1123  1.1.2.39   matt 
   1124  1.1.2.39   matt 		u_long base = mp->start >> 20;
   1125  1.1.2.39   matt 		u_long size = mp->size >> 20;
   1126  1.1.2.39   matt 
   1127  1.1.2.39   matt 		mp++;
   1128  1.1.2.39   matt 
   1129  1.1.2.39   matt 		DPRINTF("%s: dram %u: 0x%05lx00000:%lu MB\n",
   1130  1.1.2.39   matt 			__func__, i, base, size);
   1131  1.1.2.39   matt 		if (extent_alloc_region(ext, base, size, EX_NOWAIT) != 0)
   1132  1.1.2.39   matt 			panic("%s: extent_alloc_region(%p, %#lx, %#lx, %#x) "
   1133  1.1.2.39   matt 				"failed", __func__, ext, base, size, EX_NOWAIT);
   1134  1.1.2.39   matt 	}
   1135  1.1.2.39   matt 
   1136  1.1.2.39   matt 	mem_cluster_cnt = mp - mem_clusters;
   1137  1.1.2.39   matt 	return memsize;
   1138  1.1.2.39   matt }
   1139  1.1.2.39   matt #endif /* MIPS64_XLP */
   1140  1.1.2.39   matt 
   1141  1.1.2.39   matt #if (MIPS64_XLR + MIPS64_XLS) > 0
   1142  1.1.2.39   matt static uint64_t
   1143  1.1.2.39   matt rmixl_physaddr_dram_init(struct extent *ext)
   1144  1.1.2.39   matt {
   1145  1.1.2.39   matt 	uint64_t memsize = 0;
   1146  1.1.2.39   matt 	/*
   1147  1.1.2.39   matt 	 * grab regions per DRAM BARs
   1148  1.1.2.39   matt 	 */
   1149  1.1.2.39   matt 	phys_ram_seg_t *mp = mem_clusters;
   1150  1.1.2.39   matt 	for (u_int i=0; i < RMIXL_SBC_DRAM_NBARS; i++) {
   1151  1.1.2.39   matt 		uint32_t r = RMIXL_IOREG_READ(RMIXL_SBC_DRAM_BAR(i));
   1152  1.1.2.39   matt 		if ((r & RMIXL_DRAM_BAR_STATUS) == 0)
   1153  1.1.2.39   matt 			continue;	/* not enabled */
   1154  1.1.2.39   matt 
   1155  1.1.2.39   matt 		mp->start = DRAM_BAR_TO_BASE((uint64_t)r);
   1156  1.1.2.39   matt 		mp->size  = DRAM_BAR_TO_SIZE((uint64_t)r);
   1157  1.1.2.39   matt 
   1158  1.1.2.39   matt 		u_long base = mp->start >> 20;
   1159  1.1.2.39   matt 		u_long size = mp->size >> 20;
   1160  1.1.2.39   matt 
   1161  1.1.2.39   matt 		memsize += mp->size;
   1162  1.1.2.39   matt 
   1163  1.1.2.39   matt 		mp++;
   1164  1.1.2.39   matt 
   1165  1.1.2.39   matt 		DPRINTF("%s: dram %u: 0x%08x -- 0x%010lx:%lu MB\n",
   1166  1.1.2.39   matt 			__func__, i, r, base * (1024 * 1024), size);
   1167  1.1.2.39   matt 		if (extent_alloc_region(ext, base, size, EX_NOWAIT) != 0)
   1168  1.1.2.39   matt 			panic("%s: extent_alloc_region(%p, %#lx, %#lx, %#x) "
   1169  1.1.2.39   matt 				"failed", __func__, ext, base, size, EX_NOWAIT);
   1170  1.1.2.39   matt 	}
   1171  1.1.2.39   matt 
   1172  1.1.2.39   matt 	mem_cluster_cnt = mp - mem_clusters;
   1173  1.1.2.39   matt 
   1174  1.1.2.39   matt 	return memsize;
   1175  1.1.2.39   matt }
   1176  1.1.2.39   matt #endif /* (MIPS64_XLR + MIPS64_XLS) > 0 */
   1177  1.1.2.39   matt 
   1178   1.1.2.6  cliff /*
   1179   1.1.2.6  cliff  * create an extent for physical address space
   1180   1.1.2.6  cliff  * these are in units of MB for sake of compression (for sake of 32 bit kernels)
   1181   1.1.2.6  cliff  * allocate the regions where we have known functions (DRAM, IO, etc)
   1182   1.1.2.6  cliff  * what remains can be allocated as needed for other stuff
   1183   1.1.2.6  cliff  * e.g. to configure BARs that are not already initialized and enabled.
   1184   1.1.2.6  cliff  */
   1185  1.1.2.39   matt static uint64_t
   1186   1.1.2.6  cliff rmixl_physaddr_init(void)
   1187   1.1.2.6  cliff {
   1188   1.1.2.6  cliff 	struct extent *ext;
   1189   1.1.2.6  cliff 	unsigned long start = 0UL;
   1190  1.1.2.39   matt 	unsigned long end = (__BIT(40) / (1024 * 1024)) - 1;
   1191  1.1.2.39   matt 	const bool is_xlp_p = cpu_rmixlp(mips_options.mips_cpu);
   1192  1.1.2.39   matt 	uint64_t memsize;
   1193   1.1.2.6  cliff 
   1194   1.1.2.6  cliff 	ext = extent_create("physaddr", start, end, M_DEVBUF,
   1195   1.1.2.6  cliff 		(void *)rmixl_physaddr_storage, sizeof(rmixl_physaddr_storage),
   1196   1.1.2.6  cliff 		EX_NOWAIT | EX_NOCOALESCE);
   1197   1.1.2.6  cliff 
   1198   1.1.2.6  cliff 	if (ext == NULL)
   1199   1.1.2.6  cliff 		panic("%s: extent_create failed", __func__);
   1200   1.1.2.6  cliff 
   1201  1.1.2.39   matt 	if (is_xlp_p) {
   1202  1.1.2.39   matt #if (MIPS64_XLP) > 0
   1203  1.1.2.39   matt 		memsize = rmixlp_physaddr_dram_init(ext);
   1204  1.1.2.39   matt 		rmixlp_physaddr_pcie_cfg_init(ext);
   1205  1.1.2.39   matt 		rmixlp_physaddr_pcie_ecfg_init(ext);
   1206  1.1.2.39   matt 		rmixlp_physaddr_pcie_mem_init(ext);
   1207  1.1.2.39   matt 		rmixlp_physaddr_pcie_io_init(ext);
   1208  1.1.2.39   matt 		rmixlp_physaddr_srio_mem_init(ext);
   1209  1.1.2.40   matt 		rmixlp_physaddr_nor_init(ext);
   1210  1.1.2.39   matt #else
   1211  1.1.2.39   matt 		memsize = 0;
   1212  1.1.2.39   matt #endif /* MIPS64_XLP */
   1213  1.1.2.39   matt 	} else {
   1214  1.1.2.39   matt #if (MIPS64_XLR + MIPS64_XLS) > 0
   1215  1.1.2.39   matt 		memsize = rmixl_physaddr_dram_init(ext);
   1216   1.1.2.6  cliff 
   1217  1.1.2.39   matt 		/*
   1218  1.1.2.39   matt 		 * get chip-dependent physaddr regions
   1219  1.1.2.39   matt 		 */
   1220  1.1.2.39   matt 		switch(cpu_rmixl_chip_type(mips_options.mips_cpu)) {
   1221  1.1.2.39   matt 		case CIDFL_RMI_TYPE_XLR:
   1222  1.1.2.28  cliff #if NRMIXL_PCIX
   1223  1.1.2.39   matt 			rmixl_physaddr_init_pcix(ext);
   1224  1.1.2.28  cliff #endif
   1225  1.1.2.39   matt 			break;
   1226  1.1.2.39   matt 		case CIDFL_RMI_TYPE_XLS:
   1227  1.1.2.28  cliff #if NRMIXL_PCIE
   1228  1.1.2.39   matt 			rmixl_physaddr_init_pcie(ext);
   1229  1.1.2.28  cliff #endif
   1230  1.1.2.39   matt 			break;
   1231  1.1.2.39   matt 		default:
   1232  1.1.2.39   matt 			panic("%s: unknown chip type %d", __func__,
   1233  1.1.2.39   matt 			    cpu_rmixl_chip_type(mips_options.mips_cpu));
   1234  1.1.2.39   matt 		}
   1235  1.1.2.39   matt #else
   1236  1.1.2.39   matt 		memsize = 0;
   1237  1.1.2.39   matt #endif /* (MIPS64_XLR + MIPS64_XLS) > 0 */
   1238   1.1.2.6  cliff 	}
   1239   1.1.2.6  cliff 
   1240   1.1.2.6  cliff 	/*
   1241   1.1.2.6  cliff 	 *  at this point all regions left in "physaddr" extent
   1242   1.1.2.6  cliff 	 *  are unused holes in the physical adress space
   1243   1.1.2.6  cliff 	 *  available for use as needed.
   1244   1.1.2.6  cliff 	 */
   1245   1.1.2.6  cliff 	rmixl_configuration.rc_phys_ex = ext;
   1246   1.1.2.6  cliff #ifdef MACHDEP_DEBUG
   1247   1.1.2.6  cliff 	extent_print(ext);
   1248   1.1.2.6  cliff #endif
   1249  1.1.2.39   matt 	return memsize;
   1250   1.1.2.1  cliff }
   1251   1.1.2.1  cliff 
   1252  1.1.2.16  cliff static uint64_t
   1253   1.1.2.7  cliff rmixlfw_init(int64_t infop)
   1254   1.1.2.1  cliff {
   1255  1.1.2.39   matt 	struct rmixl_config * const rcp = &rmixl_configuration;
   1256  1.1.2.39   matt 	const bool is_xlp_p = cpu_rmixlp(mips_options.mips_cpu);
   1257   1.1.2.1  cliff 
   1258  1.1.2.14  cliff #ifdef MULTIPROCESSOR
   1259  1.1.2.14  cliff 	rmixl_get_wakeup_info(rcp);
   1260  1.1.2.14  cliff #endif
   1261   1.1.2.1  cliff 
   1262   1.1.2.7  cliff 	infop |= MIPS_KSEG0_START;
   1263  1.1.2.17  cliff 	rcp->rc_psb_info = *(rmixlfw_info_t *)(intptr_t)infop;
   1264   1.1.2.1  cliff 
   1265  1.1.2.18  cliff 	rcp->rc_psb_type = PSB_TYPE_UNKNOWN;
   1266   1.1.2.1  cliff 	for (int i=0; i < RMICLFW_PSB_VERSIONS_LEN; i++) {
   1267  1.1.2.18  cliff 		if (rmiclfw_psb_id[i].psb_version ==
   1268  1.1.2.18  cliff 		    rcp->rc_psb_info.psb_version) {
   1269  1.1.2.18  cliff 			rcp->rc_psb_type = rmiclfw_psb_id[i].psb_type;
   1270   1.1.2.1  cliff 			goto found;
   1271  1.1.2.18  cliff 		}
   1272   1.1.2.1  cliff 	}
   1273   1.1.2.1  cliff 
   1274  1.1.2.39   matt 	if (is_xlp_p) {
   1275  1.1.2.39   matt #if (MIPS64_XLP) > 0
   1276  1.1.2.39   matt 		rcp->rc_pci_ecfg.r_pbase = RMIXLP_SBC_PCIE_ECFG_PBASE;
   1277  1.1.2.39   matt #endif /* MIPS64_XLP */
   1278  1.1.2.39   matt 	} else {
   1279  1.1.2.39   matt #if (MIPS64_XLR + MIPS64_XLS) > 0
   1280  1.1.2.39   matt 		rcp->rc_io.r_pbase = RMIXL_IO_DEV_PBASE;
   1281  1.1.2.39   matt #endif /* (MIPS64_XLR + MIPS64_XLS) > 0 */
   1282  1.1.2.39   matt 	}
   1283   1.1.2.4  cliff 
   1284   1.1.2.6  cliff #ifdef DIAGNOSTIC
   1285  1.1.2.39   matt 	printf("\nWARNING: untested psb_version: %#"PRIx64"\n",
   1286  1.1.2.39   matt 	    rcp->rc_psb_info.psb_version);
   1287   1.1.2.6  cliff #endif
   1288   1.1.2.9  cliff 
   1289  1.1.2.13  cliff #ifdef MEMSIZE
   1290   1.1.2.9  cliff 	/* XXX trust and use MEMSIZE */
   1291   1.1.2.9  cliff 	mem_clusters[0].start = 0;
   1292   1.1.2.9  cliff 	mem_clusters[0].size = MEMSIZE;
   1293   1.1.2.9  cliff 	mem_cluster_cnt = 1;
   1294   1.1.2.7  cliff 	return MEMSIZE;
   1295  1.1.2.13  cliff #else
   1296  1.1.2.39   matt 	uint64_t memsize = 0;
   1297  1.1.2.39   matt 	for (size_t i = 0; i < mem_cluster_cnt; i++) {
   1298  1.1.2.39   matt 		memsize += mem_clusters[i].size;
   1299  1.1.2.39   matt 	}
   1300  1.1.2.39   matt 	if (memsize)
   1301  1.1.2.39   matt 		return memsize;
   1302  1.1.2.39   matt 
   1303  1.1.2.39   matt 	printf("\nERROR: configure MEMSIZE\n");
   1304  1.1.2.13  cliff 	cpu_reboot(RB_HALT, NULL);
   1305  1.1.2.13  cliff 	/* NOTREACHED */
   1306  1.1.2.13  cliff #endif
   1307   1.1.2.4  cliff 
   1308   1.1.2.1  cliff  found:
   1309  1.1.2.39   matt 	rcp->rc_io.r_pbase = MIPS_KSEG1_TO_PHYS(rcp->rc_psb_info.io_base);
   1310  1.1.2.39   matt 	DPRINTF("\ninfop: %#"PRIx64"\n", infop);
   1311   1.1.2.6  cliff #ifdef DIAGNOSTIC
   1312  1.1.2.39   matt 	printf("\nrecognized psb_version=%#"PRIx64", psb_type=%s\n",
   1313  1.1.2.39   matt 	    rcp->rc_psb_info.psb_version,
   1314  1.1.2.39   matt 	    rmixlfw_psb_type_name(rcp->rc_psb_type));
   1315   1.1.2.6  cliff #endif
   1316   1.1.2.1  cliff 
   1317   1.1.2.4  cliff 	return mem_clusters_init(
   1318  1.1.2.17  cliff 		(rmixlfw_mmap_t *)(intptr_t)rcp->rc_psb_info.psb_physaddr_map,
   1319  1.1.2.17  cliff 		(rmixlfw_mmap_t *)(intptr_t)rcp->rc_psb_info.avail_mem_map);
   1320   1.1.2.4  cliff }
   1321   1.1.2.4  cliff 
   1322   1.1.2.6  cliff void
   1323  1.1.2.39   matt rmixlfw_mmap_print(const char *mapname, rmixlfw_mmap_t *map)
   1324   1.1.2.6  cliff {
   1325   1.1.2.6  cliff #ifdef MACHDEP_DEBUG
   1326  1.1.2.39   matt 	for (size_t i=0; i < map->nmmaps; i++) {
   1327  1.1.2.39   matt 		printf("%s[%zu]: %#"PRIx64", %#"PRIx64", %#x\n",
   1328  1.1.2.39   matt 		    mapname, i, map->entry[i].start, map->entry[i].size,
   1329  1.1.2.39   matt 		    map->entry[i].type);
   1330   1.1.2.6  cliff 	}
   1331   1.1.2.6  cliff #endif
   1332   1.1.2.6  cliff }
   1333   1.1.2.6  cliff 
   1334   1.1.2.6  cliff /*
   1335   1.1.2.6  cliff  * mem_clusters_init
   1336   1.1.2.6  cliff  *
   1337   1.1.2.6  cliff  * initialize mem_clusters[] table based on memory address mapping
   1338   1.1.2.6  cliff  * provided by boot firmware.
   1339   1.1.2.6  cliff  *
   1340   1.1.2.6  cliff  * prefer avail_mem_map if we can, otherwise use psb_physaddr_map.
   1341   1.1.2.6  cliff  * these will be limited by MEMSIZE if it is configured.
   1342   1.1.2.6  cliff  * if neither are available, just use MEMSIZE.
   1343   1.1.2.6  cliff  */
   1344  1.1.2.16  cliff static uint64_t
   1345   1.1.2.4  cliff mem_clusters_init(
   1346   1.1.2.4  cliff 	rmixlfw_mmap_t *psb_physaddr_map,
   1347   1.1.2.4  cliff 	rmixlfw_mmap_t *avail_mem_map)
   1348   1.1.2.4  cliff {
   1349   1.1.2.6  cliff 	rmixlfw_mmap_t *map = NULL;
   1350   1.1.2.6  cliff 	const char *mapname;
   1351   1.1.2.4  cliff 	uint64_t sz;
   1352   1.1.2.4  cliff 	uint64_t sum;
   1353   1.1.2.6  cliff 	u_int cnt;
   1354   1.1.2.4  cliff #ifdef MEMSIZE
   1355  1.1.2.16  cliff 	uint64_t memsize = MEMSIZE;
   1356   1.1.2.4  cliff #endif
   1357   1.1.2.4  cliff 
   1358   1.1.2.6  cliff #ifdef MACHDEP_DEBUG
   1359  1.1.2.39   matt 	printf("psb_physaddr_map: %p\n", psb_physaddr_map);
   1360   1.1.2.6  cliff #endif
   1361   1.1.2.6  cliff 	if (psb_physaddr_map != NULL) {
   1362  1.1.2.17  cliff 		map = psb_physaddr_map;
   1363   1.1.2.6  cliff 		mapname = "psb_physaddr_map";
   1364  1.1.2.39   matt 		rmixlfw_mmap_print(mapname, map);
   1365   1.1.2.6  cliff 	}
   1366   1.1.2.6  cliff #ifdef DIAGNOSTIC
   1367   1.1.2.6  cliff 	else {
   1368  1.1.2.39   matt 		printf("WARNING: no psb_physaddr_map\n");
   1369   1.1.2.6  cliff 	}
   1370   1.1.2.6  cliff #endif
   1371   1.1.2.4  cliff 
   1372   1.1.2.6  cliff #ifdef MACHDEP_DEBUG
   1373  1.1.2.39   matt 	printf("avail_mem_map: %p\n", avail_mem_map);
   1374   1.1.2.6  cliff #endif
   1375   1.1.2.6  cliff 	if (avail_mem_map != NULL) {
   1376  1.1.2.17  cliff 		map = avail_mem_map;
   1377   1.1.2.6  cliff 		mapname = "avail_mem_map";
   1378  1.1.2.39   matt 		rmixlfw_mmap_print(mapname, map);
   1379   1.1.2.6  cliff 	}
   1380   1.1.2.6  cliff #ifdef DIAGNOSTIC
   1381   1.1.2.6  cliff 	else {
   1382  1.1.2.39   matt 		printf("WARNING: no avail_mem_map\n");
   1383   1.1.2.6  cliff 	}
   1384   1.1.2.6  cliff #endif
   1385   1.1.2.6  cliff 
   1386   1.1.2.6  cliff 	if (map == NULL) {
   1387   1.1.2.4  cliff #ifndef MEMSIZE
   1388  1.1.2.39   matt 		printf("panic: no firmware memory map, "
   1389   1.1.2.6  cliff 			"must configure MEMSIZE\r\n");
   1390   1.1.2.6  cliff 		for(;;);	/* XXX */
   1391   1.1.2.4  cliff #else
   1392   1.1.2.6  cliff #ifdef DIAGNOSTIC
   1393  1.1.2.39   matt 		printf("WARNING: no avail_mem_map, using MEMSIZE\n");
   1394   1.1.2.6  cliff #endif
   1395   1.1.2.6  cliff 
   1396   1.1.2.4  cliff 		mem_clusters[0].start = 0;
   1397   1.1.2.4  cliff 		mem_clusters[0].size = MEMSIZE;
   1398   1.1.2.4  cliff 		mem_cluster_cnt = 1;
   1399   1.1.2.4  cliff 		return MEMSIZE;
   1400   1.1.2.6  cliff #endif	/* MEMSIZE */
   1401   1.1.2.4  cliff 	}
   1402   1.1.2.1  cliff 
   1403   1.1.2.6  cliff #ifdef DIAGNOSTIC
   1404  1.1.2.39   matt 	printf("using %s\n", mapname);
   1405   1.1.2.6  cliff #endif
   1406   1.1.2.6  cliff #ifdef MACHDEP_DEBUG
   1407  1.1.2.39   matt 	printf("memory clusters:\n");
   1408   1.1.2.6  cliff #endif
   1409   1.1.2.1  cliff 	sum = 0;
   1410   1.1.2.6  cliff 	cnt = 0;
   1411   1.1.2.6  cliff 	for (uint32_t i=0; i < map->nmmaps; i++) {
   1412   1.1.2.6  cliff 		if (map->entry[i].type != RMIXLFW_MMAP_TYPE_RAM)
   1413   1.1.2.1  cliff 			continue;
   1414   1.1.2.6  cliff 		mem_clusters[cnt].start = map->entry[i].start;
   1415   1.1.2.6  cliff 		sz = map->entry[i].size;
   1416   1.1.2.1  cliff 		sum += sz;
   1417   1.1.2.6  cliff 		mem_clusters[cnt].size = sz;
   1418   1.1.2.6  cliff #ifdef MACHDEP_DEBUG
   1419  1.1.2.39   matt 		printf("[%u]: %#"PRIx64", %#"PRIx64", %#"PRIx64"\n",
   1420  1.1.2.39   matt 		    i, mem_clusters[cnt].start, sz, sum);
   1421   1.1.2.1  cliff #endif
   1422   1.1.2.1  cliff #ifdef MEMSIZE
   1423   1.1.2.1  cliff 		/*
   1424   1.1.2.1  cliff 		 * configurably limit memsize
   1425   1.1.2.1  cliff 		 */
   1426   1.1.2.1  cliff 		if (sum == memsize)
   1427   1.1.2.1  cliff 			break;
   1428   1.1.2.1  cliff 		if (sum > memsize) {
   1429  1.1.2.13  cliff 			uint64_t tmp;
   1430  1.1.2.13  cliff 
   1431   1.1.2.1  cliff 			tmp = sum - memsize;
   1432   1.1.2.1  cliff 			sz -= tmp;
   1433   1.1.2.1  cliff 			sum -= tmp;
   1434   1.1.2.6  cliff 			mem_clusters[cnt].size = sz;
   1435  1.1.2.13  cliff 			cnt++;
   1436   1.1.2.1  cliff 			break;
   1437   1.1.2.1  cliff 		}
   1438   1.1.2.1  cliff #endif
   1439   1.1.2.6  cliff 		cnt++;
   1440   1.1.2.1  cliff 	}
   1441   1.1.2.6  cliff 	mem_cluster_cnt = cnt;
   1442   1.1.2.1  cliff 	return sum;
   1443   1.1.2.1  cliff }
   1444   1.1.2.1  cliff 
   1445  1.1.2.14  cliff #ifdef MULTIPROCESSOR
   1446  1.1.2.14  cliff /*
   1447  1.1.2.25  cliff  * RMI firmware passes wakeup info structure in CP0 OS Scratch reg #7
   1448  1.1.2.14  cliff  * they do not explicitly give us the size of the wakeup area.
   1449  1.1.2.14  cliff  * we "know" that firmware loader sets wip->gp thusly:
   1450  1.1.2.14  cliff  *   gp = stack_start[vcpu] = round_page(wakeup_end) + (vcpu * (PAGE_SIZE * 2))
   1451  1.1.2.14  cliff  * so
   1452  1.1.2.14  cliff  *   round_page(wakeup_end) == gp - (vcpu * (PAGE_SIZE * 2))
   1453  1.1.2.14  cliff  * Only the "master" cpu runs this function, so
   1454  1.1.2.14  cliff  *   vcpu = wip->master_cpu
   1455  1.1.2.14  cliff  */
   1456  1.1.2.14  cliff void
   1457  1.1.2.14  cliff rmixl_get_wakeup_info(struct rmixl_config *rcp)
   1458  1.1.2.14  cliff {
   1459  1.1.2.14  cliff 	volatile rmixlfw_cpu_wakeup_info_t *wip;
   1460  1.1.2.14  cliff 	int32_t scratch_7;
   1461  1.1.2.14  cliff 	intptr_t end;
   1462  1.1.2.14  cliff 
   1463  1.1.2.14  cliff 	__asm__ volatile(
   1464  1.1.2.14  cliff 		".set push"				"\n"
   1465  1.1.2.14  cliff 		".set noreorder"			"\n"
   1466  1.1.2.39   matt 		".set mips64"				"\n"
   1467  1.1.2.14  cliff 		"dmfc0	%0, $22, 7"			"\n"
   1468  1.1.2.14  cliff 		".set pop"				"\n"
   1469  1.1.2.14  cliff 			: "=r"(scratch_7));
   1470  1.1.2.14  cliff 
   1471  1.1.2.14  cliff 	wip = (volatile rmixlfw_cpu_wakeup_info_t *)
   1472  1.1.2.14  cliff 			(intptr_t)scratch_7;
   1473  1.1.2.14  cliff 	end = wip->entry.gp - (wip->master_cpu & (PAGE_SIZE * 2));;
   1474  1.1.2.14  cliff 
   1475  1.1.2.14  cliff 	if (wip->valid == 1) {
   1476  1.1.2.14  cliff 		rcp->rc_cpu_wakeup_end = (const void *)end;
   1477  1.1.2.14  cliff 		rcp->rc_cpu_wakeup_info = wip;
   1478  1.1.2.14  cliff 	}
   1479  1.1.2.14  cliff };
   1480  1.1.2.14  cliff 
   1481  1.1.2.14  cliff #ifdef MACHDEP_DEBUG
   1482  1.1.2.14  cliff static void
   1483  1.1.2.14  cliff rmixl_wakeup_info_print(volatile rmixlfw_cpu_wakeup_info_t *wip)
   1484  1.1.2.14  cliff {
   1485  1.1.2.14  cliff 	int i;
   1486  1.1.2.14  cliff 
   1487  1.1.2.16  cliff 	printf("%s: wip %p, size %lu\n", __func__, wip, sizeof(*wip));
   1488  1.1.2.14  cliff 
   1489  1.1.2.14  cliff 	printf("cpu_status %#x\n",  wip->cpu_status);
   1490  1.1.2.14  cliff 	printf("valid: %d\n", wip->valid);
   1491  1.1.2.14  cliff 	printf("entry: addr %#x, args %#x, sp %#"PRIx64", gp %#"PRIx64"\n",
   1492  1.1.2.14  cliff 		wip->entry.addr,
   1493  1.1.2.14  cliff 		wip->entry.args,
   1494  1.1.2.14  cliff 		wip->entry.sp,
   1495  1.1.2.14  cliff 		wip->entry.gp);
   1496  1.1.2.14  cliff 	printf("master_cpu %d\n", wip->master_cpu);
   1497  1.1.2.14  cliff 	printf("master_cpu_mask %#x\n", wip->master_cpu_mask);
   1498  1.1.2.14  cliff 	printf("buddy_cpu_mask %#x\n", wip->buddy_cpu_mask);
   1499  1.1.2.14  cliff 	printf("psb_os_cpu_map %#x\n", wip->psb_os_cpu_map);
   1500  1.1.2.14  cliff 	printf("argc %d\n", wip->argc);
   1501  1.1.2.14  cliff 	printf("argv:");
   1502  1.1.2.14  cliff 	for (i=0; i < wip->argc; i++)
   1503  1.1.2.14  cliff 		printf(" %#x", wip->argv[i]);
   1504  1.1.2.14  cliff 	printf("\n");
   1505  1.1.2.14  cliff 	printf("valid_tlb_entries %d\n", wip->valid_tlb_entries);
   1506  1.1.2.14  cliff 	printf("tlb_map:\n");
   1507  1.1.2.14  cliff 	for (i=0; i < wip->valid_tlb_entries; i++) {
   1508  1.1.2.14  cliff 		volatile const struct lib_cpu_tlb_mapping *m =
   1509  1.1.2.14  cliff 			&wip->tlb_map[i];
   1510  1.1.2.14  cliff 		printf(" %d", m->page_size);
   1511  1.1.2.14  cliff 		printf(", %d", m->asid);
   1512  1.1.2.14  cliff 		printf(", %d", m->coherency);
   1513  1.1.2.14  cliff 		printf(", %d", m->coherency);
   1514  1.1.2.14  cliff 		printf(", %d", m->attr);
   1515  1.1.2.14  cliff 		printf(", %#x", m->virt);
   1516  1.1.2.14  cliff 		printf(", %#"PRIx64"\n", m->phys);
   1517  1.1.2.14  cliff 	}
   1518  1.1.2.14  cliff 	printf("elf segs:\n");
   1519  1.1.2.14  cliff 	for (i=0; i < MAX_ELF_SEGMENTS; i++) {
   1520  1.1.2.14  cliff 		volatile const struct core_segment_info *e =
   1521  1.1.2.14  cliff 			&wip->seg_info[i];
   1522  1.1.2.14  cliff 		printf(" %#"PRIx64"", e->vaddr);
   1523  1.1.2.14  cliff 		printf(", %#"PRIx64"", e->memsz);
   1524  1.1.2.14  cliff 		printf(", %#x\n", e->flags);
   1525  1.1.2.14  cliff 	}
   1526  1.1.2.14  cliff 	printf("envc %d\n", wip->envc);
   1527  1.1.2.14  cliff 	for (i=0; i < wip->envc; i++)
   1528  1.1.2.14  cliff 		printf(" %#x \"%s\"", wip->envs[i],
   1529  1.1.2.14  cliff 			(char *)(intptr_t)(int32_t)(wip->envs[i]));
   1530  1.1.2.14  cliff 	printf("\n");
   1531  1.1.2.14  cliff 	printf("app_mode %d\n", wip->app_mode);
   1532  1.1.2.14  cliff 	printf("printk_lock %#x\n", wip->printk_lock);
   1533  1.1.2.14  cliff 	printf("kseg_master %d\n", wip->kseg_master);
   1534  1.1.2.14  cliff 	printf("kuseg_reentry_function %#x\n", wip->kuseg_reentry_function);
   1535  1.1.2.14  cliff 	printf("kuseg_reentry_args %#x\n", wip->kuseg_reentry_args);
   1536  1.1.2.14  cliff 	printf("app_shared_mem_addr %#"PRIx64"\n", wip->app_shared_mem_addr);
   1537  1.1.2.14  cliff 	printf("app_shared_mem_size %#"PRIx64"\n", wip->app_shared_mem_size);
   1538  1.1.2.14  cliff 	printf("app_shared_mem_orig %#"PRIx64"\n", wip->app_shared_mem_orig);
   1539  1.1.2.14  cliff 	printf("loader_lock %#x\n", wip->loader_lock);
   1540  1.1.2.14  cliff 	printf("global_wakeup_mask %#x\n", wip->global_wakeup_mask);
   1541  1.1.2.14  cliff 	printf("unused_0 %#x\n", wip->unused_0);
   1542  1.1.2.14  cliff }
   1543  1.1.2.14  cliff #endif	/* MACHDEP_DEBUG */
   1544  1.1.2.14  cliff #endif 	/* MULTIPROCESSOR */
   1545  1.1.2.14  cliff 
   1546   1.1.2.1  cliff void
   1547   1.1.2.1  cliff consinit(void)
   1548   1.1.2.1  cliff {
   1549   1.1.2.1  cliff 
   1550   1.1.2.1  cliff 	/*
   1551   1.1.2.1  cliff 	 * Everything related to console initialization is done
   1552   1.1.2.1  cliff 	 * in mach_init().
   1553   1.1.2.1  cliff 	 */
   1554   1.1.2.1  cliff }
   1555   1.1.2.1  cliff 
   1556   1.1.2.1  cliff /*
   1557   1.1.2.1  cliff  * Allocate memory for variable-sized tables,
   1558   1.1.2.1  cliff  */
   1559   1.1.2.1  cliff void
   1560   1.1.2.1  cliff cpu_startup()
   1561   1.1.2.1  cliff {
   1562   1.1.2.1  cliff 	vaddr_t minaddr, maxaddr;
   1563   1.1.2.1  cliff 	char pbuf[9];
   1564   1.1.2.1  cliff 
   1565   1.1.2.1  cliff 	/*
   1566   1.1.2.1  cliff 	 * Good {morning,afternoon,evening,night}.
   1567   1.1.2.1  cliff 	 */
   1568   1.1.2.1  cliff 	printf("%s%s", copyright, version);
   1569  1.1.2.13  cliff 	format_bytes(pbuf, sizeof(pbuf), ctob((uint64_t)physmem));
   1570   1.1.2.1  cliff 	printf("total memory = %s\n", pbuf);
   1571   1.1.2.1  cliff 
   1572   1.1.2.1  cliff 	/*
   1573   1.1.2.1  cliff 	 * Virtual memory is bootstrapped -- notify the bus spaces
   1574   1.1.2.1  cliff 	 * that memory allocation is now safe.
   1575   1.1.2.1  cliff 	 */
   1576   1.1.2.1  cliff 	rmixl_configuration.rc_mallocsafe = 1;
   1577   1.1.2.1  cliff 
   1578   1.1.2.1  cliff 	minaddr = 0;
   1579   1.1.2.1  cliff 	/*
   1580   1.1.2.1  cliff 	 * Allocate a submap for physio.
   1581   1.1.2.1  cliff 	 */
   1582   1.1.2.1  cliff 	phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
   1583   1.1.2.1  cliff 				    VM_PHYS_SIZE, 0, FALSE, NULL);
   1584   1.1.2.1  cliff 
   1585   1.1.2.1  cliff 	/*
   1586   1.1.2.1  cliff 	 * (No need to allocate an mbuf cluster submap.  Mbuf clusters
   1587   1.1.2.6  cliff 	 * are allocated via the pool allocator, and we use XKSEG to
   1588   1.1.2.1  cliff 	 * map those pages.)
   1589   1.1.2.1  cliff 	 */
   1590   1.1.2.1  cliff 
   1591   1.1.2.1  cliff 	format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
   1592   1.1.2.1  cliff 	printf("avail memory = %s\n", pbuf);
   1593   1.1.2.1  cliff }
   1594   1.1.2.1  cliff 
   1595   1.1.2.1  cliff int	waittime = -1;
   1596   1.1.2.1  cliff 
   1597   1.1.2.1  cliff void
   1598  1.1.2.34   matt cpu_reboot(int howto, char *bootstr)
   1599   1.1.2.1  cliff {
   1600   1.1.2.1  cliff 
   1601   1.1.2.1  cliff 	/* Take a snapshot before clobbering any registers. */
   1602  1.1.2.34   matt 	savectx(lwp_getpcb(curlwp));
   1603   1.1.2.1  cliff 
   1604   1.1.2.1  cliff 	if (cold) {
   1605   1.1.2.1  cliff 		howto |= RB_HALT;
   1606   1.1.2.1  cliff 		goto haltsys;
   1607   1.1.2.1  cliff 	}
   1608   1.1.2.1  cliff 
   1609   1.1.2.1  cliff 	/* If "always halt" was specified as a boot flag, obey. */
   1610   1.1.2.1  cliff 	if (boothowto & RB_HALT)
   1611   1.1.2.1  cliff 		howto |= RB_HALT;
   1612   1.1.2.1  cliff 
   1613   1.1.2.1  cliff 	boothowto = howto;
   1614   1.1.2.1  cliff 	if ((howto & RB_NOSYNC) == 0 && (waittime < 0)) {
   1615   1.1.2.1  cliff 		waittime = 0;
   1616   1.1.2.1  cliff 		vfs_shutdown();
   1617   1.1.2.1  cliff 
   1618   1.1.2.1  cliff 		/*
   1619   1.1.2.1  cliff 		 * If we've been adjusting the clock, the todr
   1620   1.1.2.1  cliff 		 * will be out of synch; adjust it now.
   1621   1.1.2.1  cliff 		 */
   1622   1.1.2.1  cliff 		resettodr();
   1623   1.1.2.1  cliff 	}
   1624   1.1.2.1  cliff 
   1625   1.1.2.1  cliff 	splhigh();
   1626   1.1.2.1  cliff 
   1627   1.1.2.1  cliff 	if (howto & RB_DUMP)
   1628   1.1.2.1  cliff 		dumpsys();
   1629   1.1.2.1  cliff 
   1630   1.1.2.1  cliff haltsys:
   1631   1.1.2.1  cliff 	doshutdownhooks();
   1632   1.1.2.1  cliff 
   1633   1.1.2.1  cliff 	if (howto & RB_HALT) {
   1634   1.1.2.1  cliff 		printf("\n");
   1635   1.1.2.1  cliff 		printf("The operating system has halted.\n");
   1636   1.1.2.1  cliff 		printf("Please press any key to reboot.\n\n");
   1637   1.1.2.1  cliff 		cnpollc(1);	/* For proper keyboard command handling */
   1638   1.1.2.1  cliff 		cngetc();
   1639   1.1.2.1  cliff 		cnpollc(0);
   1640   1.1.2.1  cliff 	}
   1641   1.1.2.1  cliff 
   1642   1.1.2.1  cliff 	printf("rebooting...\n\n");
   1643   1.1.2.1  cliff 
   1644  1.1.2.12  cliff 	rmixl_reset();
   1645   1.1.2.1  cliff }
   1646   1.1.2.1  cliff 
   1647   1.1.2.1  cliff /*
   1648   1.1.2.1  cliff  * goodbye world
   1649   1.1.2.1  cliff  */
   1650   1.1.2.1  cliff void __attribute__((__noreturn__))
   1651  1.1.2.12  cliff rmixl_reset(void)
   1652   1.1.2.1  cliff {
   1653  1.1.2.12  cliff 	uint32_t r;
   1654  1.1.2.12  cliff 
   1655  1.1.2.39   matt 	if (MIPSNN_GET(CFG_AR, mips3_cp0_config_read()) == MIPSNN_CFG_AR_REV2) {
   1656  1.1.2.39   matt 		rmixlp_write_4(RMIXLP_SM_PCITAG, RMIXLP_SM_CHIP_RESET, 1);
   1657  1.1.2.39   matt 		DELAY(1000000);
   1658  1.1.2.39   matt 		printf("%s: resorting to plan b!", __func__);
   1659  1.1.2.39   matt 		*(volatile uint32_t *)MIPS_PHYS_TO_KSEG1(0x18035100) = 1;
   1660  1.1.2.39   matt 		__asm __volatile("sync");
   1661  1.1.2.39   matt 	} else {
   1662  1.1.2.39   matt 		r = RMIXL_IOREG_READ(RMIXL_IO_DEV_GPIO + RMIXL_GPIO_RESET);
   1663  1.1.2.39   matt 		r |= RMIXL_GPIO_RESET_RESET;
   1664  1.1.2.39   matt 		RMIXL_IOREG_WRITE(RMIXL_IO_DEV_GPIO + RMIXL_GPIO_RESET, r);
   1665  1.1.2.39   matt 	}
   1666  1.1.2.12  cliff 
   1667  1.1.2.12  cliff 	printf("soft reset failed, spinning...\n");
   1668   1.1.2.1  cliff 	for (;;);
   1669   1.1.2.1  cliff }
   1670  1.1.2.39   matt 
   1671  1.1.2.39   matt #ifdef __HAVE_PCI_CONF_HOOK
   1672  1.1.2.39   matt int
   1673  1.1.2.39   matt rmixl_pci_conf_hook(void *v, int bus, int device, int function, pcireg_t id)
   1674  1.1.2.39   matt {
   1675  1.1.2.39   matt 	return PCI_CONF_MAP_MEM | PCI_CONF_ENABLE_MEM | PCI_CONF_ENABLE_BM;
   1676  1.1.2.39   matt }
   1677  1.1.2.39   matt #endif
   1678