Home | History | Annotate | Line # | Download | only in rmixl
machdep.c revision 1.1.2.25
      1 /*	$NetBSD: machdep.c,v 1.1.2.25 2010/03/21 21:22:28 cliff Exp $	*/
      2 
      3 /*
      4  * Copyright 2001, 2002 Wasabi Systems, Inc.
      5  * All rights reserved.
      6  *
      7  * Written by Jason R. Thorpe and Simon Burge for Wasabi Systems, Inc.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *      This product includes software developed for the NetBSD Project by
     20  *      Wasabi Systems, Inc.
     21  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  *    or promote products derived from this software without specific prior
     23  *    written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  * POSSIBILITY OF SUCH DAMAGE.
     36  */
     37 
     38 /*
     39  * Copyright (c) 1992, 1993
     40  *	The Regents of the University of California.  All rights reserved.
     41  *
     42  * This code is derived from software contributed to Berkeley by
     43  * the Systems Programming Group of the University of Utah Computer
     44  * Science Department, The Mach Operating System project at
     45  * Carnegie-Mellon University and Ralph Campbell.
     46  *
     47  * Redistribution and use in source and binary forms, with or without
     48  * modification, are permitted provided that the following conditions
     49  * are met:
     50  * 1. Redistributions of source code must retain the above copyright
     51  *    notice, this list of conditions and the following disclaimer.
     52  * 2. Redistributions in binary form must reproduce the above copyright
     53  *    notice, this list of conditions and the following disclaimer in the
     54  *    documentation and/or other materials provided with the distribution.
     55  * 3. Neither the name of the University nor the names of its contributors
     56  *    may be used to endorse or promote products derived from this software
     57  *    without specific prior written permission.
     58  *
     59  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69  * SUCH DAMAGE.
     70  *
     71  *	@(#)machdep.c   8.3 (Berkeley) 1/12/94
     72  *	from: Utah Hdr: machdep.c 1.63 91/04/24
     73  */
     74 /*
     75  * Copyright (c) 1988 University of Utah.
     76  *
     77  * This code is derived from software contributed to Berkeley by
     78  * the Systems Programming Group of the University of Utah Computer
     79  * Science Department, The Mach Operating System project at
     80  * Carnegie-Mellon University and Ralph Campbell.
     81  *
     82  * Redistribution and use in source and binary forms, with or without
     83  * modification, are permitted provided that the following conditions
     84  * are met:
     85  * 1. Redistributions of source code must retain the above copyright
     86  *    notice, this list of conditions and the following disclaimer.
     87  * 2. Redistributions in binary form must reproduce the above copyright
     88  *    notice, this list of conditions and the following disclaimer in the
     89  *    documentation and/or other materials provided with the distribution.
     90  * 3. All advertising materials mentioning features or use of this software
     91  *    must display the following acknowledgement:
     92  *	This product includes software developed by the University of
     93  *	California, Berkeley and its contributors.
     94  * 4. Neither the name of the University nor the names of its contributors
     95  *    may be used to endorse or promote products derived from this software
     96  *    without specific prior written permission.
     97  *
     98  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     99  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    100  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    101  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    102  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    103  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    104  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    105  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    106  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    107  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    108  * SUCH DAMAGE.
    109  *
    110  *	@(#)machdep.c   8.3 (Berkeley) 1/12/94
    111  *	from: Utah Hdr: machdep.c 1.63 91/04/24
    112  */
    113 
    114 #include <sys/cdefs.h>
    115 __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.1.2.25 2010/03/21 21:22:28 cliff Exp $");
    116 
    117 #define __INTR_PRIVATE
    118 
    119 #include "opt_ddb.h"
    120 #include "opt_com.h"
    121 #include "opt_execfmt.h"
    122 #include "opt_memsize.h"
    123 
    124 #include <sys/param.h>
    125 #include <sys/systm.h>
    126 #include <sys/kernel.h>
    127 #include <sys/buf.h>
    128 #include <sys/reboot.h>
    129 #include <sys/user.h>
    130 #include <sys/mount.h>
    131 #include <sys/kcore.h>
    132 #include <sys/boot_flag.h>
    133 #include <sys/termios.h>
    134 #include <sys/ksyms.h>
    135 #include <sys/bus.h>
    136 #include <sys/device.h>
    137 #include <sys/extent.h>
    138 #include <sys/malloc.h>
    139 
    140 #include <uvm/uvm_extern.h>
    141 
    142 #include <dev/cons.h>
    143 
    144 #include "ksyms.h"
    145 
    146 #if NKSYMS || defined(DDB) || defined(LKM)
    147 #include <machine/db_machdep.h>
    148 #include <ddb/db_extern.h>
    149 #endif
    150 
    151 #include <machine/cpu.h>
    152 #include <machine/psl.h>
    153 
    154 #include "com.h"
    155 #if NCOM == 0
    156 #error no serial console
    157 #endif
    158 
    159 #include <dev/ic/comreg.h>
    160 #include <dev/ic/comvar.h>
    161 
    162 #include <mips/include/intr.h>
    163 
    164 #include <mips/rmi/rmixlreg.h>
    165 #include <mips/rmi/rmixlvar.h>
    166 #include <mips/rmi/rmixl_intr.h>
    167 #include <mips/rmi/rmixl_firmware.h>
    168 #include <mips/rmi/rmixl_comvar.h>
    169 
    170 #ifdef MACHDEP_DEBUG
    171 int machdep_debug=MACHDEP_DEBUG;
    172 # define DPRINTF(x)	do { if (machdep_debug) printf x ; } while(0)
    173 #else
    174 # define DPRINTF(x)
    175 #endif
    176 
    177 #ifndef CONSFREQ
    178 # define CONSFREQ 66000000
    179 #endif
    180 #ifndef CONSPEED
    181 # define CONSPEED 38400
    182 #endif
    183 #ifndef CONMODE
    184 # define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8)
    185 #endif
    186 #ifndef CONSADDR
    187 # define CONSADDR RMIXL_IO_DEV_UART_1
    188 #endif
    189 
    190 int		comcnfreq  = CONSFREQ;
    191 int		comcnspeed = CONSPEED;
    192 tcflag_t	comcnmode  = CONMODE;
    193 bus_addr_t	comcnaddr  = (bus_addr_t)CONSADDR;
    194 
    195 struct rmixl_config rmixl_configuration;
    196 
    197 
    198 /*
    199  * array of tested firmware versions
    200  * if you find new ones and they work
    201  * please add them
    202  */
    203 typedef struct rmiclfw_psb_id {
    204 	uint64_t		psb_version;
    205 	rmixlfw_psb_type_t	psb_type;
    206 } rmiclfw_psb_id_t;
    207 static rmiclfw_psb_id_t rmiclfw_psb_id[] = {
    208 	{	0x4958d4fb00000056ULL, PSB_TYPE_RMI  },
    209 	{	0x49a5a8fa00000056ULL, PSB_TYPE_DELL },
    210 	{	0x4aacdb6a00000056ULL, PSB_TYPE_RMI  },
    211 };
    212 #define RMICLFW_PSB_VERSIONS_LEN \
    213 	(sizeof(rmiclfw_psb_id)/sizeof(rmiclfw_psb_id[0]))
    214 
    215 /*
    216  * storage for fixed extent used to allocate physical address regions
    217  * because extent(9) start and end values are u_long, they are only
    218  * 32 bits on a 32 bit kernel, which is insuffucuent since XLS physical
    219  * address is 40 bits wide.  So the "physaddr" map stores regions
    220  * in units of megabytes.
    221  */
    222 static u_long rmixl_physaddr_storage[
    223 	EXTENT_FIXED_STORAGE_SIZE(32)/sizeof(u_long)
    224 ];
    225 
    226 /* For sysctl_hw. */
    227 extern char cpu_model[];
    228 
    229 /* Our exported CPU info; we can have only one. */
    230 struct cpu_info cpu_info_store;
    231 
    232 /* Maps for VM objects. */
    233 struct vm_map *mb_map = NULL;
    234 struct vm_map *phys_map = NULL;
    235 
    236 int	physmem;		/* Total physical memory */
    237 
    238 int	netboot;		/* Are we netbooting? */
    239 
    240 
    241 phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];
    242 u_int mem_cluster_cnt;
    243 
    244 
    245 void configure(void);
    246 void mach_init(int, int32_t *, void *, int64_t);
    247 static uint64_t rmixlfw_init(int64_t);
    248 static uint64_t mem_clusters_init(rmixlfw_mmap_t *, rmixlfw_mmap_t *);
    249 static void __attribute__((__noreturn__)) rmixl_reset(void);
    250 static void rmixl_physaddr_init(void);
    251 static u_int ram_seg_resv(phys_ram_seg_t *, u_int, u_quad_t, u_quad_t);
    252 void rmixlfw_mmap_print(rmixlfw_mmap_t *);
    253 
    254 
    255 #ifdef MULTIPROCESSOR
    256 static bool rmixl_fixup_cop0_oscratch(int32_t, uint32_t [2]);
    257 void rmixl_get_wakeup_info(struct rmixl_config *);
    258 #ifdef MACHDEP_DEBUG
    259 static void rmixl_wakeup_info_print(volatile rmixlfw_cpu_wakeup_info_t *);
    260 #endif	/* MACHDEP_DEBUG */
    261 #endif	/* MULTIPROCESSOR */
    262 
    263 
    264 /*
    265  * safepri is a safe priority for sleep to set for a spin-wait during
    266  * autoconfiguration or after a panic.  Used as an argument to splx().
    267  */
    268 int	safepri = MIPS1_PSL_LOWIPL;
    269 
    270 /*
    271  * Do all the stuff that locore normally does before calling main().
    272  */
    273 void
    274 mach_init(int argc, int32_t *argv, void *envp, int64_t infop)
    275 {
    276 	struct rmixl_config *rcp = &rmixl_configuration;
    277 	void *kernend;
    278 	uint64_t memsize;
    279 	u_int vm_cluster_cnt;
    280 	uint32_t r;
    281 	phys_ram_seg_t vm_clusters[VM_PHYSSEG_MAX];
    282 	extern char edata[], end[];
    283 
    284 #ifndef MULTIPROCESSOR
    285 	rmixl_mtcr(0, 1);		/* disable all threads except #0 */
    286 	rmixl_mtcr(0x400, 0);		/* enable MMU clock gating */
    287 					/* set single MMU Thread Mode */
    288 					/* TLB is partitioned (1 partition) */
    289 #endif
    290 
    291 	r = rmixl_mfcr(0x300);
    292 	r &= ~__BIT(14);		/* disabled Unaligned Access */
    293 	rmixl_mtcr(0x300, r);
    294 
    295 	/*
    296 	 * Clear the BSS segment.
    297 	 */
    298 	kernend = (void *)mips_round_page(end);
    299 	memset(edata, 0, (char *)kernend - edata);
    300 
    301 	/*
    302 	 * Set up the exception vectors and CPU-specific function
    303 	 * vectors early on.  We need the wbflush() vector set up
    304 	 * before comcnattach() is called (or at least before the
    305 	 * first printf() after that is called).
    306 	 * Also clears the I+D caches.
    307 	 *
    308 	 * specify chip-specific EIRR/EIMR based spl functions
    309 	 */
    310 	mips_vector_init(&rmixl_splsw);
    311 
    312 	/* mips_vector_init initialized mips_options */
    313 	strcpy(cpu_model, mips_options.mips_cpu->cpu_name);
    314 
    315 	/* get system info from firmware */
    316 	memsize = rmixlfw_init(infop);
    317 
    318 	/* set the VM page size */
    319 	uvm_setpagesize();
    320 
    321 	physmem = btoc(memsize);
    322 
    323 	rmixl_obio_eb_bus_mem_init(&rcp->rc_obio_eb_memt, rcp);
    324 
    325 #if NCOM > 0
    326 	rmixl_com_cnattach(comcnaddr, comcnspeed, comcnfreq,
    327 		COM_TYPE_NORMAL, comcnmode);
    328 #endif
    329 
    330 	printf("\nNetBSD/rmixl\n");
    331 	printf("memsize = %#"PRIx64"\n", memsize);
    332 #ifdef MEMLIMIT
    333 	printf("memlimit = %#"PRIx64"\n", (uint64_t)MEMLIMIT);
    334 #endif
    335 
    336 #if defined(MULTIPROCESSOR) && defined(MACHDEP_DEBUG)
    337 	rmixl_wakeup_info_print(rcp->rc_cpu_wakeup_info);
    338 	rmixl_wakeup_info_print(rcp->rc_cpu_wakeup_info + 1);
    339 	printf("cpu_wakeup_info %p, cpu_wakeup_end %p\n",
    340 		rcp->rc_cpu_wakeup_info,
    341 		rcp->rc_cpu_wakeup_end);
    342 	printf("userapp_cpu_map: %#"PRIx64"\n",
    343 		rcp->rc_psb_info.userapp_cpu_map);
    344 	printf("wakeup: %#"PRIx64"\n", rcp->rc_psb_info.wakeup);
    345 {
    346 	register_t sp;
    347 	asm volatile ("move	%0, $sp\n" : "=r"(sp));
    348 	printf("sp: %#"PRIx64"\n", sp);
    349 }
    350 #endif
    351 
    352 	rmixl_physaddr_init();
    353 
    354 	/*
    355 	 * Obtain the cpu frequency
    356 	 * Compute the number of ticks for hz.
    357 	 * Compute the delay divisor.
    358 	 * Double the Hz if this CPU runs at twice the
    359          *  external/cp0-count frequency
    360 	 */
    361 	curcpu()->ci_cpu_freq = rcp->rc_psb_info.cpu_frequency;
    362 	curcpu()->ci_cctr_freq = curcpu()->ci_cpu_freq;
    363 	curcpu()->ci_cycles_per_hz = (curcpu()->ci_cpu_freq + hz / 2) / hz;
    364 	curcpu()->ci_divisor_delay =
    365 		((curcpu()->ci_cpu_freq + 500000) / 1000000);
    366         if (mips_options.mips_cpu_flags & CPU_MIPS_DOUBLE_COUNT)
    367 		curcpu()->ci_cpu_freq *= 2;
    368 
    369 	/*
    370 	 * Look at arguments passed to us and compute boothowto.
    371 	 * - rmixl firmware gives us a 32 bit argv[i], so adapt
    372 	 *   by forcing sign extension in cast to (char *)
    373 	 */
    374 	boothowto = RB_AUTOBOOT;
    375 	for (int i = 1; i < argc; i++) {
    376 		for (char *cp = (char *)(intptr_t)argv[i]; *cp; cp++) {
    377 			int howto;
    378 			/* Ignore superfluous '-', if there is one */
    379 			if (*cp == '-')
    380 				continue;
    381 
    382 			howto = 0;
    383 			BOOT_FLAG(*cp, howto);
    384 			if (howto != 0)
    385 				boothowto |= howto;
    386 #ifdef DIAGNOSTIC
    387 			else
    388 				printf("bootflag '%c' not recognised\n", *cp);
    389 #endif
    390 		}
    391 	}
    392 #ifdef DIAGNOSTIC
    393 	printf("boothowto %#x\n", boothowto);
    394 #endif
    395 
    396 	/*
    397 	 * Reserve pages from the VM system.
    398 	 * to maintain mem_clusters[] as a map of raw ram,
    399 	 * copy into temporary table vm_clusters[]
    400 	 * work on that and use it to feed vm_physload()
    401 	 */
    402 	KASSERT(sizeof(mem_clusters) == sizeof(vm_clusters));
    403 	memcpy(&vm_clusters, &mem_clusters, sizeof(vm_clusters));
    404 	vm_cluster_cnt = mem_cluster_cnt;
    405 
    406 	/* reserve 0..start..kernend pages */
    407 	vm_cluster_cnt = ram_seg_resv(vm_clusters, vm_cluster_cnt,
    408 		0, round_page(MIPS_KSEG0_TO_PHYS(kernend)));
    409 
    410 	/* reserve reset exception vector page */
    411 	/* should never be in our clusters anyway... */
    412 	vm_cluster_cnt = ram_seg_resv(vm_clusters, vm_cluster_cnt,
    413 		0x1FC00000, 0x1FC00000+NBPG);
    414 
    415 #ifdef MULTIPROCEESOR
    416 	/* reserve the cpu_wakeup_info area */
    417 	vm_cluster_cnt = ram_seg_resv(vm_clusters, vm_cluster_cnt,
    418 		(u_quad_t)trunc_page(rcp->rc_cpu_wakeup_info),
    419 		(u_quad_t)round_page(rcp->rc_cpu_wakeup_end));
    420 #endif
    421 
    422 #ifdef MEMLIMIT
    423 	/* reserve everything >= MEMLIMIT */
    424 	vm_cluster_cnt = ram_seg_resv(vm_clusters, vm_cluster_cnt,
    425 		(u_quad_t)MEMLIMIT, (u_quad_t)~0);
    426 #endif
    427 
    428 	/*
    429 	 * Load vm_clusters[] into the VM system.
    430 	 */
    431 	mips_page_physload(MIPS_KSEG0_START, (vaddr_t) kernend,
    432 	    vm_clusters, vm_cluster_cnt, NULL, 0);
    433 
    434 	/*
    435 	 * Initialize error message buffer (at end of core).
    436 	 */
    437 	mips_init_msgbuf();
    438 
    439 	pmap_bootstrap();
    440 
    441 	/*
    442 	 * Allocate space for proc0's USPACE.
    443 	 */
    444 	mips_init_lwp0_uarea();
    445 
    446 	/*
    447 	 * Initialize debuggers, and break into them, if appropriate.
    448 	 */
    449 #if NKSYMS || defined(DDB) || defined(LKM)
    450 	ksyms_init(0, 0, 0);
    451 #endif
    452 
    453 #if defined(DDB)
    454 	if (boothowto & RB_KDB)
    455 		Debugger();
    456 #endif
    457 #ifdef MULTIPROCESSOR
    458 	/*
    459 	 * store (cpu#0) curcpu in COP0 OSSCRATCH0
    460 	 * used in exception vector
    461 	 */
    462 	__asm __volatile("dmtc0 %0,$%1"
    463 		:: "r"(&cpu_info_store), "n"(MIPS_COP_0_OSSCRATCH));
    464 	mips_fixup_exceptions(rmixl_fixup_cop0_oscratch);
    465 #endif
    466 }
    467 
    468 #ifdef MULTIPROCESSOR
    469 static bool
    470 rmixl_fixup_cop0_oscratch(int32_t load_addr, uint32_t new_insns[2])
    471 {
    472 	size_t offset = load_addr - (intptr_t)&cpu_info_store;
    473 
    474 	KASSERT(MIPS_KSEG0_P(load_addr));
    475 	KASSERT(offset < sizeof(struct cpu_info));
    476 
    477 	/*
    478 	 * Fixup this direct load cpu_info_store to actually get the current
    479 	 * CPU's cpu_info from COP0 OSSCRATCH0 and then fix the load to be
    480 	 * relative from the start of struct cpu_info.
    481 	 */
    482 
    483 	/* [0] = [d]mfc0 rX, $22 (OSScratch) */
    484 	new_insns[0] = (020 << 26)
    485 #ifdef _LP64
    486 	    | (1 << 21)		/* double move */
    487 #endif
    488 	    | (new_insns[0] & 0x001f0000)
    489 	    | (MIPS_COP_0_OSSCRATCH << 11) | (0 << 0);
    490 
    491 	/* [1] = l[dw] rX, offset(rX) */
    492 	new_insns[1] = (new_insns[1] & 0xffff0000) | offset;
    493 
    494 	return true;
    495 }
    496 #endif /* MULTIPROCESSOR */
    497 
    498 /*
    499  * ram_seg_resv - cut reserved regions out of segs, fragmenting as needed
    500  *
    501  * we simply build a new table of segs, then copy it back over the given one
    502  * this is inefficient but simple and called only a few times
    503  *
    504  * note: 'last' here means 1st addr past the end of the segment (start+size)
    505  */
    506 static u_int
    507 ram_seg_resv(phys_ram_seg_t *segs, u_int nsegs,
    508 	u_quad_t resv_first, u_quad_t resv_last)
    509 {
    510         u_quad_t first, last;
    511 	int new_nsegs=0;
    512 	int resv_flag;
    513 	phys_ram_seg_t new_segs[VM_PHYSSEG_MAX];
    514 
    515 	for (u_int i=0; i < nsegs; i++) {
    516 		resv_flag = 0;
    517 		first = trunc_page(segs[i].start);
    518 		last = round_page(segs[i].start + segs[i].size);
    519 
    520 		KASSERT(new_nsegs < VM_PHYSSEG_MAX);
    521 		if ((resv_first <= first) && (resv_last >= last)) {
    522 			/* whole segment is resverved */
    523 			continue;
    524 		}
    525 		if ((resv_first > first) && (resv_first < last)) {
    526 			u_quad_t new_last;
    527 
    528 			/*
    529 			 * reserved start in segment
    530 			 * salvage the leading fragment
    531 			 */
    532 			resv_flag = 1;
    533 			new_last = last - (last - resv_first);
    534 			KASSERT (new_last > first);
    535 			new_segs[new_nsegs].start = first;
    536 			new_segs[new_nsegs].size = new_last - first;
    537 			new_nsegs++;
    538 		}
    539 		if ((resv_last > first) && (resv_last < last)) {
    540 			u_quad_t new_first;
    541 
    542 			/*
    543 			 * reserved end in segment
    544 			 * salvage the trailing fragment
    545 			 */
    546 			resv_flag = 1;
    547 			new_first = first + (resv_last - first);
    548 			KASSERT (last > (new_first + NBPG));
    549 			new_segs[new_nsegs].start = new_first;
    550 			new_segs[new_nsegs].size = last - new_first;
    551 			new_nsegs++;
    552 		}
    553 		if (resv_flag == 0) {
    554 			/*
    555 			 * nothing reserved here, take it all
    556 			 */
    557 			new_segs[new_nsegs].start = first;
    558 			new_segs[new_nsegs].size = last - first;
    559 			new_nsegs++;
    560 		}
    561 
    562 	}
    563 
    564 	memcpy(segs, new_segs, sizeof(new_segs));
    565 
    566 	return new_nsegs;
    567 }
    568 
    569 /*
    570  * create an extent for physical address space
    571  * these are in units of MB for sake of compression (for sake of 32 bit kernels)
    572  * allocate the regions where we have known functions (DRAM, IO, etc)
    573  * what remains can be allocated as needed for other stuff
    574  * e.g. to configure BARs that are not already initialized and enabled.
    575  */
    576 static void
    577 rmixl_physaddr_init(void)
    578 {
    579 	struct extent *ext;
    580 	unsigned long start = 0UL;
    581 	unsigned long end = (__BIT(40) / (1024 * 1024)) -1;
    582 	u_long base;
    583 	u_long size;
    584 	uint32_t r;
    585 
    586 	ext = extent_create("physaddr", start, end, M_DEVBUF,
    587 		(void *)rmixl_physaddr_storage, sizeof(rmixl_physaddr_storage),
    588 		EX_NOWAIT | EX_NOCOALESCE);
    589 
    590 	if (ext == NULL)
    591 		panic("%s: extent_create failed", __func__);
    592 
    593 	/*
    594 	 * grab regions per DRAM BARs
    595 	 */
    596 	for (u_int i=0; i < RMIXL_SBC_DRAM_NBARS; i++) {
    597 		r = RMIXL_IOREG_READ(RMIXL_SBC_DRAM_BAR(i));
    598 		if ((r & RMIXL_DRAM_BAR_STATUS) == 0)
    599 			continue;	/* not enabled */
    600 		base = (u_long)(DRAM_BAR_TO_BASE((uint64_t)r) / (1024 * 1024));
    601 		size = (u_long)(DRAM_BAR_TO_SIZE((uint64_t)r) / (1024 * 1024));
    602 
    603 		DPRINTF(("%s: %d: %d: 0x%08x -- 0x%010lx:%lu MB\n",
    604 			__func__, __LINE__, i, r, base * (1024 * 1024), size));
    605 		if (extent_alloc_region(ext, base, size, EX_NOWAIT) != 0)
    606 			panic("%s: extent_alloc_region(%p, %#lx, %#lx, %#x) "
    607 				"failed", __func__, ext, base, size, EX_NOWAIT);
    608 	}
    609 
    610 	/*
    611 	 * grab regions per PCIe CFG, ECFG, IO, MEM BARs
    612 	 */
    613 	r = RMIXL_IOREG_READ(RMIXL_SBC_PCIE_CFG_BAR);
    614 	if ((r & RMIXL_PCIE_CFG_BAR_ENB) != 0) {
    615 		base = (u_long)(RMIXL_PCIE_CFG_BAR_TO_BA((uint64_t)r)
    616 			/ (1024 * 1024));
    617 		size = (u_long)RMIXL_PCIE_CFG_SIZE / (1024 * 1024);
    618 		DPRINTF(("%s: %d: %s: 0x%08x -- 0x%010lx:%ld MB\n", __func__,
    619 			__LINE__, "CFG", r, base * 1024 * 1024, size));
    620 		if (extent_alloc_region(ext, base, size, EX_NOWAIT) != 0)
    621 			panic("%s: extent_alloc_region(%p, %#lx, %#lx, %#x) "
    622 				"failed", __func__, ext, base, size, EX_NOWAIT);
    623 	}
    624 	r = RMIXL_IOREG_READ(RMIXL_SBC_PCIE_ECFG_BAR);
    625 	if ((r & RMIXL_PCIE_ECFG_BAR_ENB) != 0) {
    626 		base = (u_long)(RMIXL_PCIE_ECFG_BAR_TO_BA((uint64_t)r)
    627 			/ (1024 * 1024));
    628 		size = (u_long)RMIXL_PCIE_ECFG_SIZE / (1024 * 1024);
    629 		DPRINTF(("%s: %d: %s: 0x%08x -- 0x%010lx:%ld MB\n", __func__,
    630 			__LINE__, "ECFG", r, base * 1024 * 1024, size));
    631 		if (extent_alloc_region(ext, base, size, EX_NOWAIT) != 0)
    632 			panic("%s: extent_alloc_region(%p, %#lx, %#lx, %#x) "
    633 				"failed", __func__, ext, base, size, EX_NOWAIT);
    634 	}
    635 	r = RMIXL_IOREG_READ(RMIXL_SBC_PCIE_MEM_BAR);
    636 	if ((r & RMIXL_PCIE_MEM_BAR_ENB) != 0) {
    637 		base = (u_long)(RMIXL_PCIE_MEM_BAR_TO_BA((uint64_t)r)
    638 			/ (1024 * 1024));
    639 		size = (u_long)(RMIXL_PCIE_MEM_BAR_TO_SIZE((uint64_t)r)
    640 			/ (1024 * 1024));
    641 		DPRINTF(("%s: %d: %s: 0x%08x -- 0x%010lx:%ld MB\n", __func__,
    642 			__LINE__, "MEM", r, base * 1024 * 1024, size));
    643 		if (extent_alloc_region(ext, base, size, EX_NOWAIT) != 0)
    644 			panic("%s: extent_alloc_region(%p, %#lx, %#lx, %#x) "
    645 				"failed", __func__, ext, base, size, EX_NOWAIT);
    646 	}
    647 	r = RMIXL_IOREG_READ(RMIXL_SBC_PCIE_IO_BAR);
    648 	if ((r & RMIXL_PCIE_IO_BAR_ENB) != 0) {
    649 		base = (u_long)(RMIXL_PCIE_IO_BAR_TO_BA((uint64_t)r)
    650 			/ (1024 * 1024));
    651 		size = (u_long)(RMIXL_PCIE_IO_BAR_TO_SIZE((uint64_t)r)
    652 			/ (1024 * 1024));
    653 		DPRINTF(("%s: %d: %s: 0x%08x -- 0x%010lx:%ld MB\n", __func__,
    654 			__LINE__, "IO", r, base * 1024 * 1024, size));
    655 		if (extent_alloc_region(ext, base, size, EX_NOWAIT) != 0)
    656 			panic("%s: extent_alloc_region(%p, %#lx, %#lx, %#x) "
    657 				"failed", __func__, ext, base, size, EX_NOWAIT);
    658 	}
    659 
    660 	/*
    661 	 *  at this point all regions left in "physaddr" extent
    662 	 *  are unused holes in the physical adress space
    663 	 *  available for use as needed.
    664 	 */
    665 	rmixl_configuration.rc_phys_ex = ext;
    666 #ifdef MACHDEP_DEBUG
    667 	extent_print(ext);
    668 #endif
    669 }
    670 
    671 static uint64_t
    672 rmixlfw_init(int64_t infop)
    673 {
    674 	struct rmixl_config *rcp = &rmixl_configuration;
    675 
    676 #ifdef MULTIPROCESSOR
    677 	rmixl_get_wakeup_info(rcp);
    678 #endif
    679 
    680 	infop |= MIPS_KSEG0_START;
    681 	rcp->rc_psb_info = *(rmixlfw_info_t *)(intptr_t)infop;
    682 
    683 	rcp->rc_psb_type = PSB_TYPE_UNKNOWN;
    684 	for (int i=0; i < RMICLFW_PSB_VERSIONS_LEN; i++) {
    685 		if (rmiclfw_psb_id[i].psb_version ==
    686 		    rcp->rc_psb_info.psb_version) {
    687 			rcp->rc_psb_type = rmiclfw_psb_id[i].psb_type;
    688 			goto found;
    689 		}
    690 	}
    691 
    692 	rcp->rc_io_pbase = RMIXL_IO_DEV_PBASE;
    693 	rmixl_putchar_init(rcp->rc_io_pbase);
    694 
    695 #ifdef DIAGNOSTIC
    696 	rmixl_puts("\r\nWARNING: untested psb_version: ");
    697 	rmixl_puthex64(rcp->rc_psb_info.psb_version);
    698 	rmixl_puts("\r\n");
    699 #endif
    700 
    701 #ifdef MEMSIZE
    702 	/* XXX trust and use MEMSIZE */
    703 	mem_clusters[0].start = 0;
    704 	mem_clusters[0].size = MEMSIZE;
    705 	mem_cluster_cnt = 1;
    706 	return MEMSIZE;
    707 #else
    708 	rmixl_puts("\r\nERROR: configure MEMSIZE\r\n");
    709 	cpu_reboot(RB_HALT, NULL);
    710 	/* NOTREACHED */
    711 #endif
    712 
    713  found:
    714 	rcp->rc_io_pbase = MIPS_KSEG1_TO_PHYS(rcp->rc_psb_info.io_base);
    715 	rmixl_putchar_init(rcp->rc_io_pbase);
    716 #ifdef MACHDEP_DEBUG
    717 	rmixl_puts("\r\ninfop: ");
    718 	rmixl_puthex64((uint64_t)(intptr_t)infop);
    719 #endif
    720 #ifdef DIAGNOSTIC
    721 	rmixl_puts("\r\nrecognized psb_version=");
    722 	rmixl_puthex64(rcp->rc_psb_info.psb_version);
    723 	rmixl_puts(", psb_type=");
    724 	rmixl_puts(rmixlfw_psb_type_name(rcp->rc_psb_type));
    725 	rmixl_puts("\r\n");
    726 #endif
    727 
    728 	return mem_clusters_init(
    729 		(rmixlfw_mmap_t *)(intptr_t)rcp->rc_psb_info.psb_physaddr_map,
    730 		(rmixlfw_mmap_t *)(intptr_t)rcp->rc_psb_info.avail_mem_map);
    731 }
    732 
    733 void
    734 rmixlfw_mmap_print(rmixlfw_mmap_t *map)
    735 {
    736 #ifdef MACHDEP_DEBUG
    737 	for (uint32_t i=0; i < map->nmmaps; i++) {
    738 		rmixl_puthex32(i);
    739 		rmixl_puts(", ");
    740 		rmixl_puthex64(map->entry[i].start);
    741 		rmixl_puts(", ");
    742 		rmixl_puthex64(map->entry[i].size);
    743 		rmixl_puts(", ");
    744 		rmixl_puthex32(map->entry[i].type);
    745 		rmixl_puts("\r\n");
    746 	}
    747 #endif
    748 }
    749 
    750 /*
    751  * mem_clusters_init
    752  *
    753  * initialize mem_clusters[] table based on memory address mapping
    754  * provided by boot firmware.
    755  *
    756  * prefer avail_mem_map if we can, otherwise use psb_physaddr_map.
    757  * these will be limited by MEMSIZE if it is configured.
    758  * if neither are available, just use MEMSIZE.
    759  */
    760 static uint64_t
    761 mem_clusters_init(
    762 	rmixlfw_mmap_t *psb_physaddr_map,
    763 	rmixlfw_mmap_t *avail_mem_map)
    764 {
    765 	rmixlfw_mmap_t *map = NULL;
    766 	const char *mapname;
    767 	uint64_t sz;
    768 	uint64_t sum;
    769 	u_int cnt;
    770 #ifdef MEMSIZE
    771 	uint64_t memsize = MEMSIZE;
    772 #endif
    773 
    774 #ifdef MACHDEP_DEBUG
    775 	rmixl_puts("psb_physaddr_map: ");
    776 	rmixl_puthex64((uint64_t)(intptr_t)psb_physaddr_map);
    777 	rmixl_puts("\r\n");
    778 #endif
    779 	if (psb_physaddr_map != NULL) {
    780 		map = psb_physaddr_map;
    781 		mapname = "psb_physaddr_map";
    782 		rmixlfw_mmap_print(map);
    783 	}
    784 #ifdef DIAGNOSTIC
    785 	else {
    786 		rmixl_puts("WARNING: no psb_physaddr_map\r\n");
    787 	}
    788 #endif
    789 
    790 #ifdef MACHDEP_DEBUG
    791 	rmixl_puts("avail_mem_map: ");
    792 	rmixl_puthex64((uint64_t)(intptr_t)avail_mem_map);
    793 	rmixl_puts("\r\n");
    794 #endif
    795 	if (avail_mem_map != NULL) {
    796 		map = avail_mem_map;
    797 		mapname = "avail_mem_map";
    798 		rmixlfw_mmap_print(map);
    799 	}
    800 #ifdef DIAGNOSTIC
    801 	else {
    802 		rmixl_puts("WARNING: no avail_mem_map\r\n");
    803 	}
    804 #endif
    805 
    806 	if (map == NULL) {
    807 #ifndef MEMSIZE
    808 		rmixl_puts("panic: no firmware memory map, "
    809 			"must configure MEMSIZE\r\n");
    810 		for(;;);	/* XXX */
    811 #else
    812 #ifdef DIAGNOSTIC
    813 		rmixl_puts("WARNING: no avail_mem_map, "
    814 			"using MEMSIZE\r\n");
    815 #endif
    816 
    817 		mem_clusters[0].start = 0;
    818 		mem_clusters[0].size = MEMSIZE;
    819 		mem_cluster_cnt = 1;
    820 		return MEMSIZE;
    821 #endif	/* MEMSIZE */
    822 	}
    823 
    824 #ifdef DIAGNOSTIC
    825 	rmixl_puts("using ");
    826 	rmixl_puts(mapname);
    827 	rmixl_puts("\r\n");
    828 #endif
    829 #ifdef MACHDEP_DEBUG
    830 	rmixl_puts("memory clusters:\r\n");
    831 #endif
    832 	sum = 0;
    833 	cnt = 0;
    834 	for (uint32_t i=0; i < map->nmmaps; i++) {
    835 		if (map->entry[i].type != RMIXLFW_MMAP_TYPE_RAM)
    836 			continue;
    837 		mem_clusters[cnt].start = map->entry[i].start;
    838 		sz = map->entry[i].size;
    839 		sum += sz;
    840 		mem_clusters[cnt].size = sz;
    841 #ifdef MACHDEP_DEBUG
    842 		rmixl_puthex32(i);
    843 		rmixl_puts(": ");
    844 		rmixl_puthex64(mem_clusters[cnt].start);
    845 		rmixl_puts(", ");
    846 		rmixl_puthex64(sz);
    847 		rmixl_puts(": ");
    848 		rmixl_puthex64(sum);
    849 		rmixl_puts("\r\n");
    850 #endif
    851 #ifdef MEMSIZE
    852 		/*
    853 		 * configurably limit memsize
    854 		 */
    855 		if (sum == memsize)
    856 			break;
    857 		if (sum > memsize) {
    858 			uint64_t tmp;
    859 
    860 			tmp = sum - memsize;
    861 			sz -= tmp;
    862 			sum -= tmp;
    863 			mem_clusters[cnt].size = sz;
    864 			cnt++;
    865 			break;
    866 		}
    867 #endif
    868 		cnt++;
    869 	}
    870 	mem_cluster_cnt = cnt;
    871 	return sum;
    872 }
    873 
    874 #ifdef MULTIPROCESSOR
    875 /*
    876  * RMI firmware passes wakeup info structure in CP0 OS Scratch reg #7
    877  * they do not explicitly give us the size of the wakeup area.
    878  * we "know" that firmware loader sets wip->gp thusly:
    879  *   gp = stack_start[vcpu] = round_page(wakeup_end) + (vcpu * (PAGE_SIZE * 2))
    880  * so
    881  *   round_page(wakeup_end) == gp - (vcpu * (PAGE_SIZE * 2))
    882  * Only the "master" cpu runs this function, so
    883  *   vcpu = wip->master_cpu
    884  */
    885 void
    886 rmixl_get_wakeup_info(struct rmixl_config *rcp)
    887 {
    888 	volatile rmixlfw_cpu_wakeup_info_t *wip;
    889 	int32_t scratch_7;
    890 	intptr_t end;
    891 
    892 	__asm__ volatile(
    893 		".set push"				"\n"
    894 		".set noreorder"			"\n"
    895 		".set mips64"				"\n"
    896 		"dmfc0	%0, $22, 7"			"\n"
    897 		".set pop"				"\n"
    898 			: "=r"(scratch_7));
    899 
    900 	wip = (volatile rmixlfw_cpu_wakeup_info_t *)
    901 			(intptr_t)scratch_7;
    902 	end = wip->entry.gp - (wip->master_cpu & (PAGE_SIZE * 2));;
    903 
    904 	if (wip->valid == 1) {
    905 		rcp->rc_cpu_wakeup_end = (const void *)end;
    906 		rcp->rc_cpu_wakeup_info = wip;
    907 	}
    908 };
    909 
    910 #ifdef MACHDEP_DEBUG
    911 static void
    912 rmixl_wakeup_info_print(volatile rmixlfw_cpu_wakeup_info_t *wip)
    913 {
    914 	int i;
    915 
    916 	printf("%s: wip %p, size %lu\n", __func__, wip, sizeof(*wip));
    917 
    918 	printf("cpu_status %#x\n",  wip->cpu_status);
    919 	printf("valid: %d\n", wip->valid);
    920 	printf("entry: addr %#x, args %#x, sp %#"PRIx64", gp %#"PRIx64"\n",
    921 		wip->entry.addr,
    922 		wip->entry.args,
    923 		wip->entry.sp,
    924 		wip->entry.gp);
    925 	printf("master_cpu %d\n", wip->master_cpu);
    926 	printf("master_cpu_mask %#x\n", wip->master_cpu_mask);
    927 	printf("buddy_cpu_mask %#x\n", wip->buddy_cpu_mask);
    928 	printf("psb_os_cpu_map %#x\n", wip->psb_os_cpu_map);
    929 	printf("argc %d\n", wip->argc);
    930 	printf("argv:");
    931 	for (i=0; i < wip->argc; i++)
    932 		printf(" %#x", wip->argv[i]);
    933 	printf("\n");
    934 	printf("valid_tlb_entries %d\n", wip->valid_tlb_entries);
    935 	printf("tlb_map:\n");
    936 	for (i=0; i < wip->valid_tlb_entries; i++) {
    937 		volatile const struct lib_cpu_tlb_mapping *m =
    938 			&wip->tlb_map[i];
    939 		printf(" %d", m->page_size);
    940 		printf(", %d", m->asid);
    941 		printf(", %d", m->coherency);
    942 		printf(", %d", m->coherency);
    943 		printf(", %d", m->attr);
    944 		printf(", %#x", m->virt);
    945 		printf(", %#"PRIx64"\n", m->phys);
    946 	}
    947 	printf("elf segs:\n");
    948 	for (i=0; i < MAX_ELF_SEGMENTS; i++) {
    949 		volatile const struct core_segment_info *e =
    950 			&wip->seg_info[i];
    951 		printf(" %#"PRIx64"", e->vaddr);
    952 		printf(", %#"PRIx64"", e->memsz);
    953 		printf(", %#x\n", e->flags);
    954 	}
    955 	printf("envc %d\n", wip->envc);
    956 	for (i=0; i < wip->envc; i++)
    957 		printf(" %#x \"%s\"", wip->envs[i],
    958 			(char *)(intptr_t)(int32_t)(wip->envs[i]));
    959 	printf("\n");
    960 	printf("app_mode %d\n", wip->app_mode);
    961 	printf("printk_lock %#x\n", wip->printk_lock);
    962 	printf("kseg_master %d\n", wip->kseg_master);
    963 	printf("kuseg_reentry_function %#x\n", wip->kuseg_reentry_function);
    964 	printf("kuseg_reentry_args %#x\n", wip->kuseg_reentry_args);
    965 	printf("app_shared_mem_addr %#"PRIx64"\n", wip->app_shared_mem_addr);
    966 	printf("app_shared_mem_size %#"PRIx64"\n", wip->app_shared_mem_size);
    967 	printf("app_shared_mem_orig %#"PRIx64"\n", wip->app_shared_mem_orig);
    968 	printf("loader_lock %#x\n", wip->loader_lock);
    969 	printf("global_wakeup_mask %#x\n", wip->global_wakeup_mask);
    970 	printf("unused_0 %#x\n", wip->unused_0);
    971 }
    972 #endif	/* MACHDEP_DEBUG */
    973 #endif 	/* MULTIPROCESSOR */
    974 
    975 void
    976 consinit(void)
    977 {
    978 
    979 	/*
    980 	 * Everything related to console initialization is done
    981 	 * in mach_init().
    982 	 */
    983 }
    984 
    985 /*
    986  * Allocate memory for variable-sized tables,
    987  */
    988 void
    989 cpu_startup()
    990 {
    991 	vaddr_t minaddr, maxaddr;
    992 	char pbuf[9];
    993 
    994 	/*
    995 	 * Good {morning,afternoon,evening,night}.
    996 	 */
    997 	printf("%s%s", copyright, version);
    998 	format_bytes(pbuf, sizeof(pbuf), ctob((uint64_t)physmem));
    999 	printf("total memory = %s\n", pbuf);
   1000 
   1001 	/*
   1002 	 * Virtual memory is bootstrapped -- notify the bus spaces
   1003 	 * that memory allocation is now safe.
   1004 	 */
   1005 	rmixl_configuration.rc_mallocsafe = 1;
   1006 
   1007 	minaddr = 0;
   1008 	/*
   1009 	 * Allocate a submap for physio.
   1010 	 */
   1011 	phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
   1012 				    VM_PHYS_SIZE, 0, FALSE, NULL);
   1013 
   1014 	/*
   1015 	 * (No need to allocate an mbuf cluster submap.  Mbuf clusters
   1016 	 * are allocated via the pool allocator, and we use XKSEG to
   1017 	 * map those pages.)
   1018 	 */
   1019 
   1020 	format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
   1021 	printf("avail memory = %s\n", pbuf);
   1022 }
   1023 
   1024 int	waittime = -1;
   1025 
   1026 void
   1027 cpu_reboot(howto, bootstr)
   1028 	int howto;
   1029 	char *bootstr;
   1030 {
   1031 
   1032 	/* Take a snapshot before clobbering any registers. */
   1033 	savectx(curlwp->l_addr);
   1034 
   1035 	if (cold) {
   1036 		howto |= RB_HALT;
   1037 		goto haltsys;
   1038 	}
   1039 
   1040 	/* If "always halt" was specified as a boot flag, obey. */
   1041 	if (boothowto & RB_HALT)
   1042 		howto |= RB_HALT;
   1043 
   1044 	boothowto = howto;
   1045 	if ((howto & RB_NOSYNC) == 0 && (waittime < 0)) {
   1046 		waittime = 0;
   1047 		vfs_shutdown();
   1048 
   1049 		/*
   1050 		 * If we've been adjusting the clock, the todr
   1051 		 * will be out of synch; adjust it now.
   1052 		 */
   1053 		resettodr();
   1054 	}
   1055 
   1056 	splhigh();
   1057 
   1058 	if (howto & RB_DUMP)
   1059 		dumpsys();
   1060 
   1061 haltsys:
   1062 	doshutdownhooks();
   1063 
   1064 	if (howto & RB_HALT) {
   1065 		printf("\n");
   1066 		printf("The operating system has halted.\n");
   1067 		printf("Please press any key to reboot.\n\n");
   1068 		cnpollc(1);	/* For proper keyboard command handling */
   1069 		cngetc();
   1070 		cnpollc(0);
   1071 	}
   1072 
   1073 	printf("rebooting...\n\n");
   1074 
   1075 	rmixl_reset();
   1076 }
   1077 
   1078 /*
   1079  * goodbye world
   1080  */
   1081 void __attribute__((__noreturn__))
   1082 rmixl_reset(void)
   1083 {
   1084 	uint32_t r;
   1085 
   1086 	r = RMIXL_IOREG_READ(RMIXL_IO_DEV_GPIO + RMIXL_GPIO_RESET);
   1087 	r |= RMIXL_GPIO_RESET_RESET;
   1088 	RMIXL_IOREG_WRITE(RMIXL_IO_DEV_GPIO + RMIXL_GPIO_RESET, r);
   1089 
   1090 	printf("soft reset failed, spinning...\n");
   1091 	for (;;);
   1092 }
   1093