1/*	$NetBSD: gemini_machdep.c,v 1.35 2023/08/10 20:02:55 andvar Exp $	*/
2
3/* adapted from:
4 *	NetBSD: sdp24xx_machdep.c,v 1.4 2008/08/27 11:03:10 matt Exp
5 */
6
7/*
8 * Machine dependent functions for kernel setup for TI OSK5912 board.
9 * Based on lubbock_machdep.c which in turn was based on iq80310_machhdep.c
10 *
11 * Copyright (c) 2002, 2003, 2005  Genetec Corporation.  All rights reserved.
12 * Written by Hiroyuki Bessho for Genetec Corporation.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 *    notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 *    notice, this list of conditions and the following disclaimer in the
21 *    documentation and/or other materials provided with the distribution.
22 * 3. The name of Genetec Corporation may not be used to endorse or
23 *    promote products derived from this software without specific prior
24 *    written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 *
38 * Copyright (c) 2001 Wasabi Systems, Inc.
39 * All rights reserved.
40 *
41 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 *    notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 *    notice, this list of conditions and the following disclaimer in the
50 *    documentation and/or other materials provided with the distribution.
51 * 3. All advertising materials mentioning features or use of this software
52 *    must display the following acknowledgement:
53 *	This product includes software developed for the NetBSD Project by
54 *	Wasabi Systems, Inc.
55 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
56 *    or promote products derived from this software without specific prior
57 *    written permission.
58 *
59 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
61 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
62 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
63 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
64 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
65 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
66 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
67 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
68 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
69 * POSSIBILITY OF SUCH DAMAGE.
70 *
71 * Copyright (c) 1997,1998 Mark Brinicombe.
72 * Copyright (c) 1997,1998 Causality Limited.
73 * All rights reserved.
74 *
75 * Redistribution and use in source and binary forms, with or without
76 * modification, are permitted provided that the following conditions
77 * are met:
78 * 1. Redistributions of source code must retain the above copyright
79 *    notice, this list of conditions and the following disclaimer.
80 * 2. Redistributions in binary form must reproduce the above copyright
81 *    notice, this list of conditions and the following disclaimer in the
82 *    documentation and/or other materials provided with the distribution.
83 * 3. All advertising materials mentioning features or use of this software
84 *    must display the following acknowledgement:
85 *	This product includes software developed by Mark Brinicombe
86 *	for the NetBSD Project.
87 * 4. The name of the company nor the name of the author may be used to
88 *    endorse or promote products derived from this software without specific
89 *    prior written permission.
90 *
91 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
92 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
93 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
94 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
95 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
96 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
97 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
98 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
99 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
100 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
101 * SUCH DAMAGE.
102 *
103 * Copyright (c) 2007 Microsoft
104 * All rights reserved.
105 *
106 * Redistribution and use in source and binary forms, with or without
107 * modification, are permitted provided that the following conditions
108 * are met:
109 * 1. Redistributions of source code must retain the above copyright
110 *    notice, this list of conditions and the following disclaimer.
111 * 2. Redistributions in binary form must reproduce the above copyright
112 *    notice, this list of conditions and the following disclaimer in the
113 *    documentation and/or other materials provided with the distribution.
114 * 3. All advertising materials mentioning features or use of this software
115 *    must display the following acknowledgement:
116 *	This product includes software developed by Microsoft
117 *
118 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
119 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
120 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
121 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTERS BE LIABLE FOR ANY DIRECT,
122 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
123 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
124 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
125 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
126 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
127 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
128 * SUCH DAMAGE.
129 */
130
131#include <sys/cdefs.h>
132__KERNEL_RCSID(0, "$NetBSD: gemini_machdep.c,v 1.35 2023/08/10 20:02:55 andvar Exp $");
133
134#include "opt_arm_debug.h"
135#include "opt_console.h"
136#include "opt_machdep.h"
137#include "opt_ddb.h"
138#include "opt_kgdb.h"
139#include "opt_md.h"
140#include "opt_com.h"
141#include "opt_gemini.h"
142#include "geminiwdt.h"
143#include "geminiipm.h"
144
145#include <sys/param.h>
146#include <sys/device.h>
147#include <sys/systm.h>
148#include <sys/kernel.h>
149#include <sys/exec.h>
150#include <sys/proc.h>
151#include <sys/msgbuf.h>
152#include <sys/reboot.h>
153#include <sys/termios.h>
154#include <sys/ksyms.h>
155#include <sys/bus.h>
156#include <sys/cpu.h>
157#include <sys/conf.h>
158
159#include <uvm/uvm_extern.h>
160
161#include <dev/cons.h>
162#include <dev/md.h>
163
164#include <machine/db_machdep.h>
165#include <ddb/db_sym.h>
166#include <ddb/db_extern.h>
167#ifdef KGDB
168#include <sys/kgdb.h>
169#endif
170
171#include <arm/locore.h>
172#include <arm/undefined.h>
173
174#include <arm/arm32/machdep.h>
175
176#include <machine/bootconfig.h>
177
178#include <arm/gemini/gemini_reg.h>
179#include <arm/gemini/gemini_var.h>
180#include <arm/gemini/gemini_wdtvar.h>
181#include <arm/gemini/gemini_com.h>
182#include <arm/gemini/lpc_com.h>
183
184#include <evbarm/gemini/gemini.h>
185
186#if defined(VERBOSE_INIT_ARM)
187# define GEMINI_PUTCHAR(c)	gemini_putchar(c)
188# define GEMINI_PUTHEX(n)	gemini_puthex(n)
189#else	/* VERBOSE_INIT_ARM */
190# define GEMINI_PUTCHAR(c)
191# define GEMINI_PUTHEX(n)
192#endif	/* VERBOSE_INIT_ARM */
193
194BootConfig bootconfig;		/* Boot config storage */
195char *boot_args = NULL;
196char *boot_file = NULL;
197
198/* Physical address of the beginning of SDRAM. */
199paddr_t physical_start;
200/* Physical address of the first byte after the end of SDRAM. */
201paddr_t physical_end;
202
203/* Same things, but for the free (unused by the kernel) memory. */
204static paddr_t physical_freestart, physical_freeend;
205static u_int free_pages;
206
207/* Physical address of the message buffer. */
208paddr_t msgbufphys;
209
210extern char KERNEL_BASE_phys[];
211extern char KERNEL_BASE_virt[];
212extern char etext[], __data_start[], _edata[], __bss_start[], __bss_end__[];
213extern char _end[];
214
215#define KERNEL_PT_SYS		0	/* Page table for mapping proc0 zero page */
216#define KERNEL_PT_KERNEL	1	/* Page table for mapping kernel */
217#define	KERNEL_PT_KERNEL_NUM	4
218#define KERNEL_PT_VMDATA	(KERNEL_PT_KERNEL+KERNEL_PT_KERNEL_NUM)
219				        /* Page tables for mapping kernel VM */
220#define	KERNEL_PT_VMDATA_NUM	4	/* start with 16MB of KVM */
221#define NUM_KERNEL_PTS		(KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
222
223pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
224
225
226#if (NGEMINIIPM > 0)
227pv_addr_t ipmq_pt;		/* L2 Page table for mapping IPM queues */
228#if defined(DEBUG) || 1
229unsigned long gemini_ipmq_pbase = GEMINI_IPMQ_PBASE;
230unsigned long gemini_ipmq_vbase = GEMINI_IPMQ_VBASE;
231#endif	/* DEBUG */
232#endif	/* NGEMINIIPM > 0 */
233
234
235/*
236 * Macros to translate between physical and virtual for a subset of the
237 * kernel address space.  *Not* for general use.
238 */
239#define KERNEL_BASE_PHYS ((paddr_t)&KERNEL_BASE_phys)
240
241u_long kern_vtopdiff;
242
243/* Prototypes */
244
245void gemini_intr_init(bus_space_tag_t);
246void consinit(void);
247#ifdef KGDB
248static void kgdb_port_init(void);
249#endif
250
251static void setup_real_page_tables(void);
252static void init_clocks(void);
253
254bs_protos(bs_notimpl);
255
256#include "com.h"
257#if NCOM > 0
258#include <dev/ic/comreg.h>
259#include <dev/ic/comvar.h>
260#endif
261
262
263static void gemini_global_reset(void) __attribute__ ((noreturn));
264static void gemini_cpu1_start(void);
265static void gemini_memchk(void);
266
267static void
268gemini_global_reset(void)
269{
270#if defined(GEMINI_MASTER) || defined(GEMINI_SINGLE)
271	volatile uint32_t *rp;
272	uint32_t r;
273
274	rp = (volatile uint32_t *)
275		(GEMINI_GLOBAL_VBASE + GEMINI_GLOBAL_RESET_CTL);
276	r = *rp;
277	r |= GLOBAL_RESET_GLOBAL;
278	*rp = r;
279#endif
280	for(;;);
281	/* NOTREACHED */
282}
283
284static void
285gemini_cpu1_start(void)
286{
287#ifdef GEMINI_MASTER
288	volatile uint32_t *rp;
289	uint32_t r;
290
291	rp = (volatile uint32_t *)
292		(GEMINI_GLOBAL_VBASE + GEMINI_GLOBAL_RESET_CTL);
293	r = *rp;
294	r &= ~GLOBAL_RESET_CPU1;
295	*rp = r;
296#endif
297}
298
299static void
300gemini_memchk(void)
301{
302	volatile uint32_t *rp;
303	uint32_t r;
304	uint32_t base;
305	uint32_t size;
306
307	rp = (volatile uint32_t *)
308		(GEMINI_DRAMC_VBASE + GEMINI_DRAMC_RMCR);
309	r = *rp;
310	base = (r & DRAMC_RMCR_RMBAR) >> DRAMC_RMCR_RMBAR_SHFT;
311	size = (r & DRAMC_RMCR_RMSZR) >> DRAMC_RMCR_RMSZR_SHFT;
312#if defined(GEMINI_SINGLE)
313	if (r != 0)
314		panic("%s: RMCR %#x, MEMSIZE %d mismatch\n",
315			__FUNCTION__, r, MEMSIZE);
316#elif defined(GEMINI_MASTER)
317	if (base != MEMSIZE)
318		panic("%s: RMCR %#x, MEMSIZE %d mismatch\n",
319			__FUNCTION__, r, MEMSIZE);
320#elif defined(GEMINI_SLAVE)
321	if (size != MEMSIZE)
322		panic("%s: RMCR %#x, MEMSIZE %d mismatch\n",
323			__FUNCTION__, r, MEMSIZE);
324#endif
325#if defined(VERBOSE_INIT_ARM) || 1
326	printf("DRAM Remap: base=%dMB, size=%dMB\n", base, size);
327#endif
328}
329
330/*
331 * void cpu_reboot(int howto, char *bootstr)
332 *
333 * Reboots the system
334 *
335 * Deal with any syncing, unmounting, dumping and shutdown hooks,
336 * then reset the CPU.
337 */
338void
339cpu_reboot(int howto, char *bootstr)
340{
341	extern struct geminitmr_softc *ref_sc;
342
343#ifdef DIAGNOSTIC
344	/* info */
345	printf("boot: howto=%08x curproc=%p\n", howto, curproc);
346#endif
347
348	/*
349	 * If we are still cold then hit the air brakes
350	 * and crash to earth fast
351	 */
352	if (cold) {
353		doshutdownhooks();
354		pmf_system_shutdown(boothowto);
355		printf("The operating system has halted.\n");
356		printf("Please press any key to reboot.\n\n");
357		cngetc();
358		printf("rebooting...\n");
359		if (ref_sc != NULL)
360			delay(2000);			/* cnflush(); */
361		gemini_global_reset();
362		/*NOTREACHED*/
363	}
364
365	/* Disable console buffering */
366	cnpollc(1);
367
368	/*
369	 * If RB_NOSYNC was not specified sync the discs.
370	 * Note: Unless cold is set to 1 here, syslogd will die during the
371	 * unmount.  It looks like syslogd is getting woken up only to find
372	 * that it cannot page part of the binary in as the filesystem has
373	 * been unmounted.
374	 */
375	if (!(howto & RB_NOSYNC))
376		bootsync();
377
378	/* Say NO to interrupts */
379	splhigh();
380
381	/* Do a dump if requested. */
382	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
383		dumpsys();
384
385	/* Run any shutdown hooks */
386	doshutdownhooks();
387
388	pmf_system_shutdown(boothowto);
389
390	/* Make sure IRQ's are disabled */
391	IRQdisable;
392
393	if (howto & RB_HALT) {
394		printf("The operating system has halted.\n");
395		printf("Please press any key to reboot.\n\n");
396		cngetc();
397	}
398
399	printf("rebooting...\n");
400	if (ref_sc != NULL)
401		delay(2000);			/* cnflush(); */
402	gemini_global_reset();
403	/*NOTREACHED*/
404}
405
406/*
407 * Static device mappings. These peripheral registers are mapped at
408 * fixed virtual addresses very early in initarm() so that we can use
409 * them while booting the kernel, and stay at the same address
410 * throughout whole kernel's life time.
411 *
412 * We use this table twice; once with bootstrap page table, and once
413 * with kernel's page table which we build up in initarm().
414 *
415 * Since we map these registers into the bootstrap page table using
416 * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map
417 * registers segment-aligned and segment-rounded in order to avoid
418 * using the 2nd page tables.
419 */
420
421static const struct pmap_devmap devmap[] = {
422	/* Global regs */
423	DEVMAP_ENTRY_FLAGS(GEMINI_GLOBAL_VBASE,
424			   GEMINI_GLOBAL_BASE,
425			   L1_S_SIZE,
426			   PMAP_NOCACHE),
427
428	/* Watchdog */
429	DEVMAP_ENTRY_FLAGS(GEMINI_WATCHDOG_VBASE,
430			   GEMINI_WATCHDOG_BASE,
431			   L1_S_SIZE,
432			   PMAP_NOCACHE),
433
434	DEVMAP_ENTRY_FLAGS(GEMINI_WATCHDOG_VBASE,
435			   GEMINI_WATCHDOG_BASE,
436			   L1_S_SIZE,
437			   PMAP_NOCACHE),
438
439	/* UART */
440	DEVMAP_ENTRY_FLAGS(GEMINI_UART_VBASE,
441			   GEMINI_UART_BASE,
442			   L1_S_SIZE,
443			   PMAP_NOCACHE),
444
445	/* LPCHC */
446	DEVMAP_ENTRY_FLAGS(GEMINI_LPCHC_VBASE,
447			   GEMINI_LPCHC_BASE,
448			   L1_S_SIZE,
449			   PMAP_NOCACHE),
450
451	/* LPCIO */
452	DEVMAP_ENTRY_FLAGS(GEMINI_LPCIO_VBASE,
453			   GEMINI_LPCIO_BASE,
454			   L1_S_SIZE,
455			   PMAP_NOCACHE),
456
457	/* Timers */
458	DEVMAP_ENTRY_FLAGS(GEMINI_TIMER_VBASE,
459			   GEMINI_TIMER_BASE,
460			   L1_S_SIZE,
461			   PMAP_NOCACHE),
462
463	/* DRAM Controller */
464	DEVMAP_ENTRY_FLAGS(GEMINI_DRAMC_VBASE,
465			   GEMINI_DRAMC_BASE,
466			   L1_S_SIZE,
467			   PMAP_NOCACHE),
468
469#if defined(MEMORY_DISK_DYNAMIC)
470	/* Ramdisk */
471	DEVMAP_ENTRY_FLAGS(GEMINI_RAMDISK_VBASE,
472			   GEMINI_RAMDISK_PBASE,
473			   L1_S_SIZE,
474			   PMAP_NOCACHE),
475#endif
476
477	/* list terminator */
478	DEVMAP_ENTRY_END
479};
480
481#ifdef DDB
482static void gemini_db_trap(int where)
483{
484#if  NGEMINIWDT > 0
485	static int oldwatchdogstate;
486
487	if (where) {
488		oldwatchdogstate = geminiwdt_enable(0);
489	} else {
490		geminiwdt_enable(oldwatchdogstate);
491	}
492#endif
493}
494#endif
495
496#if defined(VERBOSE_INIT_ARM) || 1
497void gemini_putchar(char c);
498void
499gemini_putchar(char c)
500{
501	unsigned char *com0addr = (unsigned char *)GEMINI_UART_VBASE;
502	int timo = 150000;
503
504	while ((com0addr[COM_REG_LSR * 4] & LSR_TXRDY) == 0)
505		if (--timo == 0)
506			break;
507
508	com0addr[COM_REG_TXDATA] = c;
509
510	while ((com0addr[COM_REG_LSR * 4] & LSR_TSRE) == 0)
511		if (--timo == 0)
512			break;
513}
514
515void gemini_puthex(unsigned int);
516void
517gemini_puthex(unsigned int val)
518{
519	char hexc[] = "0123456789abcdef";
520
521	gemini_putchar('0');
522	gemini_putchar('x');
523	gemini_putchar(hexc[(val >> 28) & 0xf]);
524	gemini_putchar(hexc[(val >> 24) & 0xf]);
525	gemini_putchar(hexc[(val >> 20) & 0xf]);
526	gemini_putchar(hexc[(val >> 16) & 0xf]);
527	gemini_putchar(hexc[(val >> 12) & 0xf]);
528	gemini_putchar(hexc[(val >> 8) & 0xf]);
529	gemini_putchar(hexc[(val >> 4) & 0xf]);
530	gemini_putchar(hexc[(val >> 0) & 0xf]);
531}
532#endif	/* VERBOSE_INIT_ARM */
533
534/*
535 * vaddr_t initarm(...)
536 *
537 * Initial entry point on startup. This gets called before main() is
538 * entered.
539 * It should be responsible for setting up everything that must be
540 * in place when main is called.
541 * This includes
542 *   Taking a copy of the boot configuration structure.
543 *   Initialising the physical console so characters can be printed.
544 *   Setting up page tables for the kernel
545 *   Relocating the kernel to the bottom of physical memory
546 */
547vaddr_t
548initarm(void *arg)
549{
550	GEMINI_PUTCHAR('0');
551
552	/*
553	 * start cpu#1 now
554	 */
555	gemini_cpu1_start();
556
557	/*
558	 * When we enter here, we are using a temporary first level
559	 * translation table with section entries in it to cover the OBIO
560	 * peripherals and SDRAM.  The temporary first level translation table
561	 * is at the end of SDRAM.
562	 */
563
564	/* Heads up ... Setup the CPU / MMU / TLB functions. */
565	GEMINI_PUTCHAR('1');
566	if (set_cpufuncs())
567		panic("cpu not recognized!");
568
569	GEMINI_PUTCHAR('2');
570	init_clocks();
571	GEMINI_PUTCHAR('3');
572
573	/* The console is going to try to map things.  Give pmap a devmap. */
574	pmap_devmap_register(devmap);
575	GEMINI_PUTCHAR('4');
576	consinit();
577	GEMINI_PUTCHAR('5');
578#ifdef KGDB
579	kgdb_port_init();
580#endif
581
582	/* Talk to the user */
583	printf("\nNetBSD/evbarm (gemini) booting ...\n");
584
585#ifdef BOOT_ARGS
586	char mi_bootargs[] = BOOT_ARGS;
587	parse_mi_bootargs(mi_bootargs);
588#endif
589
590#ifdef VERBOSE_INIT_ARM
591	printf("initarm: Configuring system ...\n");
592#endif
593
594	/*
595	 * Set up the variables that define the availability of physical
596	 * memory.
597	 */
598	gemini_memchk();
599	physical_start = GEMINI_DRAM_BASE;
600#define	MEMSIZE_BYTES 	(MEMSIZE * 1024 * 1024)
601	physical_end = (physical_start & ~(0x400000-1)) + MEMSIZE_BYTES;
602	physmem = (physical_end - physical_start) / PAGE_SIZE;
603
604	/* Fake bootconfig structure for the benefit of pmap.c. */
605	bootconfig.dramblocks = 1;
606	bootconfig.dram[0].address = physical_start;
607	bootconfig.dram[0].pages = physmem;
608
609	kern_vtopdiff = KERNEL_BASE - GEMINI_DRAM_BASE;
610
611	/*
612	 * Our kernel is at the beginning of memory, so set our free space to
613	 * all the memory after the kernel.
614	 */
615	physical_freestart = KERN_VTOPHYS(round_page((vaddr_t) _end));
616	physical_freeend = physical_end;
617	free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
618
619	/*
620	 * This is going to do all the hard work of setting up the first and
621	 * and second level page tables.  Pages of memory will be allocated
622	 * and mapped for other structures that are required for system
623	 * operation.  When it returns, physical_freestart and free_pages will
624	 * have been updated to reflect the allocations that were made.  In
625	 * addition, kernel_l1pt, kernel_pt_table[], systempage, irqstack,
626	 * abtstack, undstack, kernelstack, msgbufphys will be set to point to
627	 * the memory that was allocated for them.
628	 */
629	setup_real_page_tables();
630
631	/*
632	 * Moved from cpu_startup() as data_abort_handler() references
633	 * this during uvm init.
634	 */
635	uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
636
637#ifdef VERBOSE_INIT_ARM
638	printf("bootstrap done.\n");
639#endif
640
641	arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
642
643	/*
644	 * Pages were allocated during the secondary bootstrap for the
645	 * stacks for different CPU modes.
646	 * We must now set the r13 registers in the different CPU modes to
647	 * point to these stacks.
648	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
649	 * of the stack memory.
650	 */
651#ifdef VERBOSE_INIT_ARM
652	printf("init subsystems: stacks ");
653#endif
654
655	set_stackptr(PSR_FIQ32_MODE, fiqstack.pv_va + FIQ_STACK_SIZE * PAGE_SIZE);
656	set_stackptr(PSR_IRQ32_MODE, irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
657	set_stackptr(PSR_ABT32_MODE, abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
658	set_stackptr(PSR_UND32_MODE, undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
659
660	/*
661	 * Well we should set a data abort handler.
662	 * Once things get going this will change as we will need a proper
663	 * handler.
664	 * Until then we will use a handler that just panics but tells us
665	 * why.
666	 * Initialisation of the vectors will just panic on a data abort.
667	 * This just fills in a slightly better one.
668	 */
669#ifdef VERBOSE_INIT_ARM
670	printf("vectors ");
671#endif
672	data_abort_handler_address = (u_int)data_abort_handler;
673	prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
674	undefined_handler_address = (u_int)undefinedinstruction_bounce;
675
676	/* Initialise the undefined instruction handlers */
677#ifdef VERBOSE_INIT_ARM
678	printf("undefined ");
679#endif
680	undefined_init();
681
682	/* Load memory into UVM. */
683#ifdef VERBOSE_INIT_ARM
684	printf("page ");
685#endif
686	uvm_md_init();
687
688#if (GEMINI_RAM_RESV_PBASE != 0)
689	uvm_page_physload(atop(physical_freestart), atop(GEMINI_RAM_RESV_PBASE),
690	    atop(physical_freestart), atop(GEMINI_RAM_RESV_PBASE),
691	    VM_FREELIST_DEFAULT);
692	uvm_page_physload(atop(GEMINI_RAM_RESV_PEND), atop(physical_freeend),
693	    atop(GEMINI_RAM_RESV_PEND), atop(physical_freeend),
694	    VM_FREELIST_DEFAULT);
695#else
696	uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
697	    atop(physical_freestart), atop(physical_freeend),
698	    VM_FREELIST_DEFAULT);
699#endif
700	uvm_page_physload(atop(GEMINI_DRAM_BASE), atop(KERNEL_BASE_phys),
701	    atop(GEMINI_DRAM_BASE), atop(KERNEL_BASE_phys),
702	    VM_FREELIST_DEFAULT);
703
704	/* Boot strap pmap telling it where managed kernel virtual memory is */
705#ifdef VERBOSE_INIT_ARM
706	printf("pmap ");
707#endif
708	pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
709
710#ifdef VERBOSE_INIT_ARM
711	printf("done.\n");
712#endif
713
714#if defined(MEMORY_DISK_DYNAMIC)
715	md_root_setconf((char *)GEMINI_RAMDISK_VBASE, GEMINI_RAMDISK_SIZE);
716#endif
717
718#ifdef KGDB
719	if (boothowto & RB_KDB) {
720		kgdb_debug_init = 1;
721		kgdb_connect(1);
722	}
723#endif
724
725#ifdef DDB
726	db_trap_callback = gemini_db_trap;
727	db_machine_init();
728
729	/* Firmware doesn't load symbols. */
730	ddb_init(0, NULL, NULL);
731
732	if (boothowto & RB_KDB)
733		Debugger();
734#endif
735	printf("initarm done.\n");
736
737	/* We return the new stack pointer address */
738	return kernelstack.pv_va + USPACE_SVC_STACK_TOP;
739}
740
741static void
742init_clocks(void)
743{
744}
745
746#ifndef CONSADDR
747#error Specify the address of the console UART with the CONSADDR option.
748#endif
749#ifndef CONSPEED
750#define CONSPEED 19200
751#endif
752#ifndef CONMODE
753#define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
754#endif
755
756static const bus_addr_t consaddr = CONSADDR;
757static const int conspeed = CONSPEED;
758static const int conmode = CONMODE;
759
760#if CONSADDR==0x42000000
761/*
762 * console initialization for obio com console
763 */
764void
765consinit(void)
766{
767	static int consinit_called = 0;
768
769	if (consinit_called != 0)
770		return;
771	consinit_called = 1;
772
773	if (comcnattach(&gemini_a4x_bs_tag, consaddr, conspeed,
774		GEMINI_COM_FREQ, COM_TYPE_16550_NOERS, conmode))
775			panic("Serial console can not be initialized.");
776}
777
778#elif CONSADDR==0x478003f8
779# include <arm/gemini/gemini_lpcvar.h>
780/*
781 * console initialization for lpc com console
782 */
783void
784consinit(void)
785{
786	static int consinit_called = 0;
787	bus_space_tag_t iot = &gemini_bs_tag;
788	bus_space_handle_t lpchc_ioh;
789	bus_space_handle_t lpcio_ioh;
790	bus_size_t sz = L1_S_SIZE;
791	gemini_lpc_softc_t lpcsoftc;
792	gemini_lpc_bus_ops_t *ops;
793	void *lpctag = &lpcsoftc;
794	uint32_t r;
795	extern gemini_lpc_bus_ops_t gemini_lpc_bus_ops;
796
797	ops = &gemini_lpc_bus_ops;
798
799	if (consinit_called != 0)
800		return;
801	consinit_called = 1;
802
803	if (bus_space_map(iot, GEMINI_LPCHC_BASE, sz, 0, &lpchc_ioh))
804		panic("consinit: LPCHC can not be mapped.");
805
806	if (bus_space_map(iot, GEMINI_LPCIO_BASE, sz, 0, &lpcio_ioh))
807		panic("consinit: LPCIO can not be mapped.");
808
809	/* enable the LPC bus */
810	r = bus_space_read_4(iot, lpchc_ioh, GEMINI_LPCHC_CSR);
811	r |= LPCHC_CSR_BEN;
812	bus_space_write_4(iot, lpchc_ioh, GEMINI_LPCHC_CSR, r);
813
814	memset(&lpcsoftc, 0, sizeof(lpcsoftc));
815	lpcsoftc.sc_iot = iot;
816	lpcsoftc.sc_ioh = lpcio_ioh;
817
818	/* activate Serial Port 1 */
819	(*ops->lpc_pnp_enter)(lpctag);
820	(*ops->lpc_pnp_write)(lpctag, 1, 0x30, 0x01);
821	(*ops->lpc_pnp_exit)(lpctag);
822
823	if (comcnattach(iot, consaddr, conspeed,
824		IT8712F_COM_FREQ, COM_TYPE_NORMAL, conmode)) {
825			panic("Serial console can not be initialized.");
826	}
827
828	bus_space_unmap(iot, lpcio_ioh, sz);
829	bus_space_unmap(iot, lpchc_ioh, sz);
830}
831#else
832# error unknown console
833#endif
834
835#ifdef KGDB
836#ifndef KGDB_DEVADDR
837#error Specify the address of the kgdb UART with the KGDB_DEVADDR option.
838#endif
839#ifndef KGDB_DEVRATE
840#define KGDB_DEVRATE 19200
841#endif
842
843#ifndef KGDB_DEVMODE
844#define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
845#endif
846static const vaddr_t comkgdbaddr = KGDB_DEVADDR;
847static const int comkgdbspeed = KGDB_DEVRATE;
848static const int comkgdbmode = KGDB_DEVMODE;
849
850void
851static kgdb_port_init(void)
852{
853	static int kgdbsinit_called = 0;
854
855	if (kgdbsinit_called != 0)
856		return;
857
858	kgdbsinit_called = 1;
859
860	bus_space_handle_t bh;
861	if (bus_space_map(&gemini_a4x_bs_tag, comkgdbaddr,
862		GEMINI_UART_SIZE, 0, &bh))
863			panic("kgdb port can not be mapped.");
864
865	if (com_kgdb_attach(&gemini_a4x_bs_tag, comkgdbaddr, comkgdbspeed,
866		GEMINI_UART_SIZE, COM_TYPE_16550_NOERS, comkgdbmode))
867			panic("KGDB uart can not be initialized.");
868
869	bus_space_unmap(&gemini_a4x_bs_tag, bh, GEMINI_UART_SIZE);
870}
871#endif
872
873static void
874setup_real_page_tables(void)
875{
876	/*
877	 * We need to allocate some fixed page tables to get the kernel going.
878	 *
879	 * We are going to allocate our bootstrap pages from the beginning of
880	 * the free space that we just calculated.  We allocate one page
881	 * directory and a number of page tables and store the physical
882	 * addresses in the kernel_pt_table array.
883	 *
884	 * The kernel page directory must be on a 16K boundary.  The page
885	 * tables must be on 4K boundaries.  What we do is allocate the
886	 * page directory on the first 16K boundary that we encounter, and
887	 * the page tables on 4K boundaries otherwise.  Since we allocate
888	 * at least 3 L2 page tables, we are guaranteed to encounter at
889	 * least one 16K aligned region.
890	 */
891
892#ifdef VERBOSE_INIT_ARM
893	printf("Allocating page tables\n");
894#endif
895
896	/*
897	 * Define a macro to simplify memory allocation.  As we allocate the
898	 * memory, make sure that we don't walk over our temporary first level
899	 * translation table.
900	 */
901#define valloc_pages(var, np)						\
902	(var).pv_pa = physical_freestart;				\
903	physical_freestart += ((np) * PAGE_SIZE);			\
904	if (physical_freestart > (physical_freeend - L1_TABLE_SIZE))	\
905		panic("initarm: out of memory");			\
906	free_pages -= (np);						\
907	(var).pv_va = KERN_PHYSTOV((var).pv_pa);			\
908	memset((char *)(var).pv_va, 0, ((np) * PAGE_SIZE));
909
910	int loop, pt_index;
911
912	pt_index = 0;
913	kernel_l1pt.pv_pa = 0;
914	kernel_l1pt.pv_va = 0;
915#ifdef VERBOSE_INIT_ARM
916	printf("%s: physical_freestart %#lx\n", __func__, physical_freestart);
917#endif
918	for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
919		/* Are we 16KB aligned for an L1 ? */
920		if ((physical_freestart & (L1_TABLE_SIZE - 1)) == 0
921		    && kernel_l1pt.pv_pa == 0) {
922			valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
923		} else {
924			valloc_pages(kernel_pt_table[pt_index],
925			    L2_TABLE_SIZE / PAGE_SIZE);
926			++pt_index;
927		}
928	}
929
930#if (NGEMINIIPM > 0)
931	valloc_pages(ipmq_pt, L2_TABLE_SIZE / PAGE_SIZE);
932#endif
933
934#ifdef VERBOSE_INIT_ARM
935	pt_index=0;
936	printf("%s: kernel_l1pt: %#lx:%#lx\n",
937		__func__, kernel_l1pt.pv_va, kernel_l1pt.pv_pa);
938	printf("%s: kernel_pt_table:\n", __func__);
939	for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
940		printf("\t%#lx:%#lx\n", kernel_pt_table[pt_index].pv_va,
941			kernel_pt_table[pt_index].pv_pa);
942		++pt_index;
943	}
944#if (NGEMINIIPM > 0)
945	printf("%s: ipmq_pt:\n", __func__);
946	printf("\t%#lx:%#lx\n", ipmq_pt.pv_va, ipmq_pt.pv_pa);
947#endif
948#endif
949
950	/* This should never be able to happen but better confirm that. */
951	if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
952		panic("initarm: Failed to align the kernel page directory");
953
954	/*
955	 * Allocate a page for the system page mapped to V0x00000000
956	 * This page will just contain the system vectors and can be
957	 * shared by all processes.
958	 */
959	valloc_pages(systempage, 1);
960	systempage.pv_va = ARM_VECTORS_HIGH;
961
962	/* Allocate stacks for all modes */
963	valloc_pages(fiqstack, FIQ_STACK_SIZE);
964	valloc_pages(irqstack, IRQ_STACK_SIZE);
965	valloc_pages(abtstack, ABT_STACK_SIZE);
966	valloc_pages(undstack, UND_STACK_SIZE);
967	valloc_pages(kernelstack, UPAGES);
968
969	/* Allocate the message buffer. */
970	pv_addr_t msgbuf;
971	int msgbuf_pgs = round_page(MSGBUFSIZE) / PAGE_SIZE;
972	valloc_pages(msgbuf, msgbuf_pgs);
973	msgbufphys = msgbuf.pv_pa;
974
975	/*
976	 * Ok we have allocated physical pages for the primary kernel
977	 * page tables
978	 */
979
980#ifdef VERBOSE_INIT_ARM
981	printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
982#endif
983
984	/*
985	 * Now we start construction of the L1 page table
986	 * We start by mapping the L2 page tables into the L1.
987	 * This means that we can replace L1 mappings later on if necessary
988	 */
989	vaddr_t l1_va = kernel_l1pt.pv_va;
990	paddr_t l1_pa = kernel_l1pt.pv_pa;
991
992	/* Map the L2 pages tables in the L1 page table */
993	pmap_link_l2pt(l1_va, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
994		       &kernel_pt_table[KERNEL_PT_SYS]);
995	for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
996		pmap_link_l2pt(l1_va, KERNEL_BASE + loop * 0x00400000,
997			       &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
998	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
999		pmap_link_l2pt(l1_va, KERNEL_VM_BASE + loop * 0x00400000,
1000			       &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
1001
1002	/* update the top of the kernel VM */
1003	pmap_curmaxkvaddr =
1004	    KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
1005
1006#if (NGEMINIIPM > 0)
1007printf("%s:%d: pmap_link_l2pt ipmq_pt\n", __FUNCTION__, __LINE__);
1008	pmap_link_l2pt(l1_va, GEMINI_IPMQ_VBASE, &ipmq_pt);
1009#endif
1010
1011#ifdef VERBOSE_INIT_ARM
1012	printf("Mapping kernel\n");
1013#endif
1014
1015	/* Now we fill in the L2 pagetable for the kernel static code/data */
1016#define round_L_page(x) (((x) + L2_L_OFFSET) & L2_L_FRAME)
1017	size_t textsize = round_L_page(etext - KERNEL_BASE_virt);
1018	size_t totalsize = round_L_page(_end - KERNEL_BASE_virt);
1019	/* offset of kernel in RAM */
1020	u_int offset = (u_int)KERNEL_BASE_virt - KERNEL_BASE;
1021
1022#ifdef DDB
1023	/* Map text section read-write. */
1024	offset += pmap_map_chunk(l1_va,
1025				(vaddr_t)KERNEL_BASE + offset,
1026				 physical_start + offset, textsize,
1027				 VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE,
1028				 PTE_CACHE);
1029#else
1030	/* Map text section read-only. */
1031	offset += pmap_map_chunk(l1_va,
1032				(vaddr_t)KERNEL_BASE + offset,
1033				 physical_start + offset, textsize,
1034				 VM_PROT_READ|VM_PROT_EXECUTE, PTE_CACHE);
1035#endif
1036	/* Map data and bss sections read-write. */
1037	offset += pmap_map_chunk(l1_va,
1038				(vaddr_t)KERNEL_BASE + offset,
1039				 physical_start + offset, totalsize - textsize,
1040				 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
1041
1042#ifdef VERBOSE_INIT_ARM
1043	printf("Constructing L2 page tables\n");
1044#endif
1045
1046	/* Map the stack pages */
1047	pmap_map_chunk(l1_va, fiqstack.pv_va, fiqstack.pv_pa,
1048	    FIQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
1049	pmap_map_chunk(l1_va, irqstack.pv_va, irqstack.pv_pa,
1050	    IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
1051	pmap_map_chunk(l1_va, abtstack.pv_va, abtstack.pv_pa,
1052	    ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
1053	pmap_map_chunk(l1_va, undstack.pv_va, undstack.pv_pa,
1054	    UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
1055	pmap_map_chunk(l1_va, kernelstack.pv_va, kernelstack.pv_pa,
1056	    UPAGES * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
1057
1058	pmap_map_chunk(l1_va, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
1059	    L1_TABLE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_PAGETABLE);
1060
1061	for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
1062		pmap_map_chunk(l1_va, kernel_pt_table[loop].pv_va,
1063			       kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
1064			       VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
1065	}
1066
1067	/* Map the vector page. */
1068	pmap_map_entry(l1_va, ARM_VECTORS_HIGH, systempage.pv_pa,
1069		       VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
1070
1071#if (NGEMINIIPM > 0)
1072	/* Map the IPM queue l2pt */
1073	pmap_map_chunk(l1_va, ipmq_pt.pv_va, ipmq_pt.pv_pa,
1074		L2_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
1075
1076	/* Map the IPM queue pages */
1077	pmap_map_chunk(l1_va, GEMINI_IPMQ_VBASE, GEMINI_IPMQ_PBASE,
1078	    GEMINI_IPMQ_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
1079
1080#ifdef GEMINI_SLAVE
1081	/*
1082	 * Map all memory, including that owned by other core
1083	 * take into account the RAM remap, so view in this region
1084	 * is consistent with MASTER
1085	 */
1086	pmap_map_chunk(l1_va,
1087	    GEMINI_ALLMEM_VBASE,
1088	    GEMINI_ALLMEM_PBASE + ((GEMINI_ALLMEM_SIZE - MEMSIZE) * 1024 * 1024),
1089	    (GEMINI_ALLMEM_SIZE - MEMSIZE) * 1024 * 1024,
1090	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
1091	pmap_map_chunk(l1_va,
1092	    GEMINI_ALLMEM_VBASE + GEMINI_BUSBASE * 1024 * 1024,
1093	    GEMINI_ALLMEM_PBASE,
1094	    (MEMSIZE * 1024 * 1024),
1095	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
1096#else
1097	/* Map all memory, including that owned by other core */
1098	pmap_map_chunk(l1_va, GEMINI_ALLMEM_VBASE, GEMINI_ALLMEM_PBASE,
1099	    GEMINI_ALLMEM_SIZE * 1024 * 1024, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
1100#endif	/* GEMINI_SLAVE */
1101#endif	/* NGEMINIIPM */
1102
1103	/*
1104	 * Map integrated peripherals at same address in first level page
1105	 * table so that we can continue to use console.
1106	 */
1107	pmap_devmap_bootstrap(l1_va, devmap);
1108
1109
1110#ifdef VERBOSE_INIT_ARM
1111	/* Tell the user about where all the bits and pieces live. */
1112	printf("%22s       Physical              Virtual        Num\n", " ");
1113	printf("%22s Starting    Ending    Starting    Ending   Pages\n", " ");
1114
1115	static const char mem_fmt[] =
1116	    "%20s: 0x%08lx 0x%08lx 0x%08lx 0x%08lx %d\n";
1117	static const char mem_fmt_nov[] =
1118	    "%20s: 0x%08lx 0x%08lx                       %d\n";
1119
1120	printf(mem_fmt, "SDRAM", physical_start, physical_end-1,
1121	    KERN_PHYSTOV(physical_start), KERN_PHYSTOV(physical_end-1),
1122	    (int)physmem);
1123	printf(mem_fmt, "text section",
1124	       KERN_VTOPHYS((vaddr_t)KERNEL_BASE_virt), KERN_VTOPHYS((vaddr_t)etext-1),
1125	       (vaddr_t)KERNEL_BASE_virt, (vaddr_t)etext-1,
1126	       (int)(textsize / PAGE_SIZE));
1127	printf(mem_fmt, "data section",
1128	       KERN_VTOPHYS((vaddr_t)__data_start), KERN_VTOPHYS((vaddr_t)_edata),
1129	       (vaddr_t)__data_start, (vaddr_t)_edata,
1130	       (int)((round_page((vaddr_t)_edata)
1131		      - trunc_page((vaddr_t)__data_start)) / PAGE_SIZE));
1132	printf(mem_fmt, "bss section",
1133	       KERN_VTOPHYS((vaddr_t)__bss_start), KERN_VTOPHYS((vaddr_t)__bss_end__),
1134	       (vaddr_t)__bss_start, (vaddr_t)__bss_end__,
1135	       (int)((round_page((vaddr_t)__bss_end__)
1136		      - trunc_page((vaddr_t)__bss_start)) / PAGE_SIZE));
1137	printf(mem_fmt, "L1 page directory",
1138	    kernel_l1pt.pv_pa, kernel_l1pt.pv_pa + L1_TABLE_SIZE - 1,
1139	    kernel_l1pt.pv_va, kernel_l1pt.pv_va + L1_TABLE_SIZE - 1,
1140	    L1_TABLE_SIZE / PAGE_SIZE);
1141	printf(mem_fmt, "Exception Vectors",
1142	    systempage.pv_pa, systempage.pv_pa + PAGE_SIZE - 1,
1143	    (vaddr_t)ARM_VECTORS_HIGH, (vaddr_t)ARM_VECTORS_HIGH + PAGE_SIZE - 1,
1144	    1);
1145	printf(mem_fmt, "FIQ stack",
1146	    fiqstack.pv_pa, fiqstack.pv_pa + (FIQ_STACK_SIZE * PAGE_SIZE) - 1,
1147	    fiqstack.pv_va, fiqstack.pv_va + (FIQ_STACK_SIZE * PAGE_SIZE) - 1,
1148	    FIQ_STACK_SIZE);
1149	printf(mem_fmt, "IRQ stack",
1150	    irqstack.pv_pa, irqstack.pv_pa + (IRQ_STACK_SIZE * PAGE_SIZE) - 1,
1151	    irqstack.pv_va, irqstack.pv_va + (IRQ_STACK_SIZE * PAGE_SIZE) - 1,
1152	    IRQ_STACK_SIZE);
1153	printf(mem_fmt, "ABT stack",
1154	    abtstack.pv_pa, abtstack.pv_pa + (ABT_STACK_SIZE * PAGE_SIZE) - 1,
1155	    abtstack.pv_va, abtstack.pv_va + (ABT_STACK_SIZE * PAGE_SIZE) - 1,
1156	    ABT_STACK_SIZE);
1157	printf(mem_fmt, "UND stack",
1158	    undstack.pv_pa, undstack.pv_pa + (UND_STACK_SIZE * PAGE_SIZE) - 1,
1159	    undstack.pv_va, undstack.pv_va + (UND_STACK_SIZE * PAGE_SIZE) - 1,
1160	    UND_STACK_SIZE);
1161	printf(mem_fmt, "SVC stack",
1162	    kernelstack.pv_pa, kernelstack.pv_pa + (UPAGES * PAGE_SIZE) - 1,
1163	    kernelstack.pv_va, kernelstack.pv_va + (UPAGES * PAGE_SIZE) - 1,
1164	    UPAGES);
1165	printf(mem_fmt_nov, "Message Buffer",
1166	    msgbufphys, msgbufphys + msgbuf_pgs * PAGE_SIZE - 1, msgbuf_pgs);
1167	printf(mem_fmt, "Free Memory", physical_freestart, physical_freeend-1,
1168	    KERN_PHYSTOV(physical_freestart), KERN_PHYSTOV(physical_freeend-1),
1169	    free_pages);
1170#endif
1171
1172	/*
1173	 * Now we have the real page tables in place so we can switch to them.
1174	 * Once this is done we will be running with the REAL kernel page
1175	 * tables.
1176	 */
1177
1178	/* Switch tables */
1179#ifdef VERBOSE_INIT_ARM
1180	printf("switching to new L1 page table  @%#lx...", l1_pa);
1181#endif
1182
1183	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
1184	cpu_setttb(l1_pa, true);
1185	cpu_tlb_flushID();
1186	cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
1187
1188#ifdef VERBOSE_INIT_ARM
1189	printf("OK.\n");
1190#endif
1191}
1192