xref: /netbsd-src/sys/arch/evbarm/tsarm/tsarm_machdep.c (revision 274254cdae52594c1aa480a736aef78313d15c9c)
1 /*	$NetBSD: tsarm_machdep.c,v 1.10 2008/11/30 18:21:33 martin Exp $ */
2 
3 /*
4  * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
5  * All rights reserved.
6  *
7  * Based on code written by Jason R. Thorpe and Steve C. Woodford for
8  * Wasabi Systems, Inc.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed for the NetBSD Project by
21  *	Wasabi Systems, Inc.
22  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
23  *    or promote products derived from this software without specific prior
24  *    written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC
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 
39 /*
40  * Copyright (c) 1997,1998 Mark Brinicombe.
41  * Copyright (c) 1997,1998 Causality Limited.
42  * All rights reserved.
43  *
44  * Redistribution and use in source and binary forms, with or without
45  * modification, are permitted provided that the following conditions
46  * are met:
47  * 1. Redistributions of source code must retain the above copyright
48  *    notice, this list of conditions and the following disclaimer.
49  * 2. Redistributions in binary form must reproduce the above copyright
50  *    notice, this list of conditions and the following disclaimer in the
51  *    documentation and/or other materials provided with the distribution.
52  * 3. All advertising materials mentioning features or use of this software
53  *    must display the following acknowledgement:
54  *	This product includes software developed by Mark Brinicombe
55  *	for the NetBSD Project.
56  * 4. The name of the company nor the name of the author may be used to
57  *    endorse or promote products derived from this software without specific
58  *    prior written permission.
59  *
60  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
61  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
62  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
63  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
64  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
65  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
66  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
67  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
68  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
69  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
70  * SUCH DAMAGE.
71  *
72  * Machine dependant functions for kernel setup for Iyonix.
73  */
74 
75 #include <sys/cdefs.h>
76 __KERNEL_RCSID(0, "$NetBSD: tsarm_machdep.c,v 1.10 2008/11/30 18:21:33 martin Exp $");
77 
78 #include "opt_ddb.h"
79 #include "opt_kgdb.h"
80 #include "opt_pmap_debug.h"
81 
82 #include <sys/param.h>
83 #include <sys/device.h>
84 #include <sys/systm.h>
85 #include <sys/kernel.h>
86 #include <sys/exec.h>
87 #include <sys/proc.h>
88 #include <sys/msgbuf.h>
89 #include <sys/reboot.h>
90 #include <sys/termios.h>
91 #include <sys/ksyms.h>
92 
93 #include <uvm/uvm_extern.h>
94 
95 #include <dev/cons.h>
96 
97 #include <machine/db_machdep.h>
98 #include <ddb/db_sym.h>
99 #include <ddb/db_extern.h>
100 
101 #include <acorn32/include/bootconfig.h>
102 #include <machine/bus.h>
103 #include <machine/cpu.h>
104 #include <machine/frame.h>
105 #include <arm/undefined.h>
106 
107 #include <arm/arm32/machdep.h>
108 
109 #include <arm/ep93xx/ep93xxreg.h>
110 #include <arm/ep93xx/ep93xxvar.h>
111 
112 #include <dev/ic/comreg.h>
113 #include <dev/ic/comvar.h>
114 
115 #include "epcom.h"
116 #if NEPCOM > 0
117 #include <arm/ep93xx/epcomvar.h>
118 #endif
119 
120 #include "isa.h"
121 #if NISA > 0
122 #include <dev/isa/isareg.h>
123 #include <dev/isa/isavar.h>
124 #endif
125 
126 #include <machine/isa_machdep.h>
127 
128 #include <evbarm/tsarm/tsarmreg.h>
129 
130 #include "ksyms.h"
131 
132 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
133 #define	KERNEL_TEXT_BASE	(KERNEL_BASE + 0x00200000)
134 #define	KERNEL_VM_BASE		(KERNEL_BASE + 0x01000000)
135 
136 /*
137  * The range 0xc1000000 - 0xccffffff is available for kernel VM space
138  * Core-logic registers and I/O mappings occupy 0xf0000000 - 0xffffffff
139  */
140 #define KERNEL_VM_SIZE		0x0C000000
141 
142 /*
143  * Address to call from cpu_reset() to reset the machine.
144  * This is machine architecture dependant as it varies depending
145  * on where the ROM appears when you turn the MMU off.
146  */
147 
148 u_int cpu_reset_address = 0x00000000;
149 
150 /* Define various stack sizes in pages */
151 #define IRQ_STACK_SIZE	8
152 #define ABT_STACK_SIZE	8
153 #define UND_STACK_SIZE	8
154 
155 struct bootconfig bootconfig;		/* Boot config storage */
156 char *boot_args = NULL;
157 char *boot_file = NULL;
158 
159 vm_offset_t physical_start;
160 vm_offset_t physical_freestart;
161 vm_offset_t physical_freeend;
162 vm_offset_t physical_freeend_low;
163 vm_offset_t physical_end;
164 u_int free_pages;
165 int physmem = 0;
166 
167 /* Physical and virtual addresses for some global pages */
168 pv_addr_t irqstack;
169 pv_addr_t undstack;
170 pv_addr_t abtstack;
171 pv_addr_t kernelstack;
172 
173 vm_offset_t msgbufphys;
174 
175 static struct arm32_dma_range tsarm_dma_ranges[4];
176 
177 #if NISA > 0
178 extern void isa_tsarm_init(u_int, u_int);
179 #endif
180 
181 extern u_int data_abort_handler_address;
182 extern u_int prefetch_abort_handler_address;
183 extern u_int undefined_handler_address;
184 
185 #ifdef PMAP_DEBUG
186 extern int pmap_debug_level;
187 #endif
188 
189 #define KERNEL_PT_SYS		0	/* L2 table for mapping vectors page */
190 
191 #define KERNEL_PT_KERNEL	1	/* L2 table for mapping kernel */
192 #define	KERNEL_PT_KERNEL_NUM	4
193 					/* L2 tables for mapping kernel VM */
194 #define KERNEL_PT_VMDATA	(KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
195 
196 #define	KERNEL_PT_VMDATA_NUM	4	/* start with 16MB of KVM */
197 #define NUM_KERNEL_PTS		(KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
198 
199 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
200 
201 struct user *proc0paddr;
202 
203 /* Prototypes */
204 
205 void	consinit(void);
206 /*
207  * Define the default console speed for the machine.
208  */
209 #ifndef CONSPEED
210 #define CONSPEED B115200
211 #endif /* ! CONSPEED */
212 
213 #ifndef CONMODE
214 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
215 #endif
216 
217 int comcnspeed = CONSPEED;
218 int comcnmode = CONMODE;
219 
220 #if KGDB
221 #ifndef KGDB_DEVNAME
222 #error Must define KGDB_DEVNAME
223 #endif
224 const char kgdb_devname[] = KGDB_DEVNAME;
225 
226 #ifndef KGDB_DEVADDR
227 #error Must define KGDB_DEVADDR
228 #endif
229 unsigned long kgdb_devaddr = KGDB_DEVADDR;
230 
231 #ifndef KGDB_DEVRATE
232 #define KGDB_DEVRATE	CONSPEED
233 #endif
234 int kgdb_devrate = KGDB_DEVRATE;
235 
236 #ifndef KGDB_DEVMODE
237 #define KGDB_DEVMODE	CONMODE
238 #endif
239 int kgdb_devmode = KGDB_DEVMODE;
240 #endif /* KGDB */
241 
242 /*
243  * void cpu_reboot(int howto, char *bootstr)
244  *
245  * Reboots the system
246  *
247  * Deal with any syncing, unmounting, dumping and shutdown hooks,
248  * then reset the CPU.
249  */
250 void
251 cpu_reboot(int howto, char *bootstr)
252 {
253 
254 	/*
255 	 * If we are still cold then hit the air brakes
256 	 * and crash to earth fast
257 	 */
258 	if (cold) {
259 		doshutdownhooks();
260 		pmf_system_shutdown(boothowto);
261 		printf("\r\n");
262 		printf("The operating system has halted.\r\n");
263 		printf("Please press any key to reboot.\r\n");
264 		cngetc();
265 		printf("\r\nrebooting...\r\n");
266 		goto reset;
267 	}
268 
269 	/* Disable console buffering */
270 
271 	/*
272 	 * If RB_NOSYNC was not specified sync the discs.
273 	 * Note: Unless cold is set to 1 here, syslogd will die during the
274 	 * unmount.  It looks like syslogd is getting woken up only to find
275 	 * that it cannot page part of the binary in as the filesystem has
276 	 * been unmounted.
277 	 */
278 	if (!(howto & RB_NOSYNC))
279 		bootsync();
280 
281 	/* Say NO to interrupts */
282 	splhigh();
283 
284 	/* Do a dump if requested. */
285 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
286 		dumpsys();
287 
288 	/* Run any shutdown hooks */
289 	doshutdownhooks();
290 
291 	pmf_system_shutdown(boothowto);
292 
293 	/* Make sure IRQ's are disabled */
294 	IRQdisable;
295 
296 	if (howto & RB_HALT) {
297 		printf("\r\n");
298 		printf("The operating system has halted.\r\n");
299 		printf("Please press any key to reboot.\r\n");
300 		cngetc();
301 	}
302 
303 	printf("\r\nrebooting...\r\n");
304  reset:
305 	/*
306 	 * Make really really sure that all interrupts are disabled,
307 	 * and poke the Internal Bus and Peripheral Bus reset lines.
308 	 */
309 	(void) disable_interrupts(I32_bit|F32_bit);
310 
311 	{
312 		u_int32_t feed, ctrl;
313 
314 		feed = TS7XXX_IO16_VBASE + TS7XXX_WDOGFEED;
315 		ctrl = TS7XXX_IO16_VBASE + TS7XXX_WDOGCTRL;
316 
317 		__asm volatile (
318 			"mov r0, #0x5\n"
319 			"mov r1, #0x1\n"
320 			"strh r0, [%0]\n"
321 			"strh r1, [%1]\n"
322 			:
323 			: "r" (feed), "r" (ctrl)
324 			: "r0", "r1"
325 		);
326 	}
327 
328 	for (;;);
329 }
330 
331 /* Static device mappings. */
332 static const struct pmap_devmap tsarm_devmap[] = {
333     {
334 	EP93XX_AHB_VBASE,
335 	EP93XX_AHB_HWBASE,
336 	EP93XX_AHB_SIZE,
337 	VM_PROT_READ|VM_PROT_WRITE,
338 	PTE_NOCACHE,
339     },
340 
341     {
342 	EP93XX_APB_VBASE,
343 	EP93XX_APB_HWBASE,
344 	EP93XX_APB_SIZE,
345 	VM_PROT_READ|VM_PROT_WRITE,
346 	PTE_NOCACHE,
347     },
348 
349 	/*
350 	 * IO8 and IO16 space *must* be mapped contiguously with
351 	 * IO8_VA == IO16_VA - 64 Mbytes.  ISA busmap driver depends
352 	 * on that!
353 	 */
354     {
355 	TS7XXX_IO8_VBASE,
356 	TS7XXX_IO8_HWBASE,
357 	TS7XXX_IO8_SIZE,
358 	VM_PROT_READ|VM_PROT_WRITE,
359 	PTE_NOCACHE,
360     },
361 
362     {
363 	TS7XXX_IO16_VBASE,
364 	TS7XXX_IO16_HWBASE,
365 	TS7XXX_IO16_SIZE,
366 	VM_PROT_READ|VM_PROT_WRITE,
367 	PTE_NOCACHE,
368     },
369 
370    {
371 	0,
372 	0,
373 	0,
374 	0,
375 	0,
376     }
377 };
378 
379 /*
380  * u_int initarm(...)
381  *
382  * Initial entry point on startup. This gets called before main() is
383  * entered.
384  * It should be responsible for setting up everything that must be
385  * in place when main is called.
386  * This includes
387  *   Taking a copy of the boot configuration structure.
388  *   Initialising the physical console so characters can be printed.
389  *   Setting up page tables for the kernel
390  *   Initialising interrupt controllers to a sane default state
391  */
392 u_int
393 initarm(void *arg)
394 {
395 #ifdef FIXME
396 	struct bootconfig *passed_bootconfig = arg;
397 	extern char _end[];
398 #endif
399 	int loop;
400 	int loop1;
401 	u_int l1pagetable;
402 	paddr_t memstart;
403 	psize_t memsize;
404 
405 #ifdef FIXME
406 	/* Calibrate the delay loop. */
407 	i80321_calibrate_delay();
408 #endif
409 
410 	/*
411 	 * Since we map the on-board devices VA==PA, and the kernel
412 	 * is running VA==PA, it's possible for us to initialize
413 	 * the console now.
414 	 */
415 	consinit();
416 
417 #ifdef VERBOSE_INIT_ARM
418 	/* Talk to the user */
419 	printf("\nNetBSD/tsarm booting ...\n");
420 #endif
421 
422 	/*
423 	 * Heads up ... Setup the CPU / MMU / TLB functions
424 	 */
425 	if (set_cpufuncs())
426 		panic("cpu not recognized!");
427 
428 	/*
429 	 * We are currently running with the MMU enabled
430 	 */
431 
432 #ifdef FIXME
433 	/*
434 	 * Fetch the SDRAM start/size from the i80321 SDRAM configuration
435 	 * registers.
436 	 */
437 	i80321_sdram_bounds(&obio_bs_tag, VERDE_PMMR_BASE + VERDE_MCU_BASE,
438 	    &memstart, &memsize);
439 #else
440 	memstart = 0x0;
441 	memsize = 0x2000000;
442 #endif
443 
444 #ifdef VERBOSE_INIT_ARM
445 	printf("initarm: Configuring system ...\n");
446 #endif
447 
448 	/* Fake bootconfig structure for the benefit of pmap.c */
449 	/* XXX must make the memory description h/w independent */
450 	bootconfig.dramblocks = 4;
451 	bootconfig.dram[0].address = 0x0UL;
452 	bootconfig.dram[0].pages = 0x800000UL / PAGE_SIZE;
453 	bootconfig.dram[1].address = 0x1000000UL;
454 	bootconfig.dram[1].pages = 0x800000UL / PAGE_SIZE;
455 	bootconfig.dram[2].address = 0x4000000UL;
456 	bootconfig.dram[2].pages = 0x800000UL / PAGE_SIZE;
457 	bootconfig.dram[3].address = 0x5000000UL;
458 	bootconfig.dram[3].pages = 0x800000UL / PAGE_SIZE;
459 
460 	/*
461 	 * Set up the variables that define the availablilty of
462 	 * physical memory.  For now, we're going to set
463 	 * physical_freestart to 0x00200000 (where the kernel
464 	 * was loaded), and allocate the memory we need downwards.
465 	 * If we get too close to the L1 table that we set up, we
466 	 * will panic.  We will update physical_freestart and
467 	 * physical_freeend later to reflect what pmap_bootstrap()
468 	 * wants to see.
469 	 *
470 	 * XXX pmap_bootstrap() needs an enema.
471 	 */
472 	physical_start = bootconfig.dram[0].address;
473 	physical_end = bootconfig.dram[0].address +
474 		(bootconfig.dram[0].pages * PAGE_SIZE);
475 
476 	physical_freestart = 0x00009000UL;
477 	physical_freeend = 0x00200000UL;
478 
479 	physmem = (physical_end - physical_start) / PAGE_SIZE;
480 
481 #ifdef VERBOSE_INIT_ARM
482 	/* Tell the user about the memory */
483 	printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
484 	    physical_start, physical_end - 1);
485 #endif
486 
487 	/*
488 	 * Okay, the kernel starts 2MB in from the bottom of physical
489 	 * memory.  We are going to allocate our bootstrap pages downwards
490 	 * from there.
491 	 *
492 	 * We need to allocate some fixed page tables to get the kernel
493 	 * going.  We allocate one page directory and a number of page
494 	 * tables and store the physical addresses in the kernel_pt_table
495 	 * array.
496 	 *
497 	 * The kernel page directory must be on a 16K boundary.  The page
498 	 * tables must be on 4K bounaries.  What we do is allocate the
499 	 * page directory on the first 16K boundary that we encounter, and
500 	 * the page tables on 4K boundaries otherwise.  Since we allocate
501 	 * at least 3 L2 page tables, we are guaranteed to encounter at
502 	 * least one 16K aligned region.
503 	 */
504 
505 #ifdef VERBOSE_INIT_ARM
506 	printf("Allocating page tables\n");
507 #endif
508 
509 	free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
510 
511 #ifdef VERBOSE_INIT_ARM
512 	printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
513 	       physical_freestart, free_pages, free_pages);
514 #endif
515 
516 	/* Define a macro to simplify memory allocation */
517 #define	valloc_pages(var, np)				\
518 	alloc_pages((var).pv_pa, (np));			\
519 	(var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
520 
521 #define alloc_pages(var, np)				\
522 	physical_freeend -= ((np) * PAGE_SIZE);		\
523 	if (physical_freeend < physical_freestart)	\
524 		panic("initarm: out of memory");	\
525 	(var) = physical_freeend;			\
526 	free_pages -= (np);				\
527 	memset((char *)(var), 0, ((np) * PAGE_SIZE));
528 
529 	loop1 = 0;
530 	for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
531 		/* Are we 16KB aligned for an L1 ? */
532 		if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
533 		    && kernel_l1pt.pv_pa == 0) {
534 			valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
535 		} else {
536 			valloc_pages(kernel_pt_table[loop1],
537 			    L2_TABLE_SIZE / PAGE_SIZE);
538 			++loop1;
539 		}
540 	}
541 
542 	/* This should never be able to happen but better confirm that. */
543 	if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
544 		panic("initarm: Failed to align the kernel page directory");
545 
546 	/*
547 	 * Allocate a page for the system vectors page
548 	 */
549 	alloc_pages(systempage.pv_pa, 1);
550 
551 	/* Allocate stacks for all modes */
552 	valloc_pages(irqstack, IRQ_STACK_SIZE);
553 	valloc_pages(abtstack, ABT_STACK_SIZE);
554 	valloc_pages(undstack, UND_STACK_SIZE);
555 	valloc_pages(kernelstack, UPAGES);
556 
557 #ifdef VERBOSE_INIT_ARM
558 	printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
559 	    irqstack.pv_va);
560 	printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
561 	    abtstack.pv_va);
562 	printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
563 	    undstack.pv_va);
564 	printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
565 	    kernelstack.pv_va);
566 #endif
567 
568 	alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
569 
570 	/*
571 	 * Ok we have allocated physical pages for the primary kernel
572 	 * page tables.  Save physical_freeend for when we give whats left
573 	 * of memory below 2Mbyte to UVM.
574 	 */
575 
576 	physical_freeend_low = physical_freeend;
577 
578 #ifdef VERBOSE_INIT_ARM
579 	printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
580 #endif
581 
582 	/*
583 	 * Now we start construction of the L1 page table
584 	 * We start by mapping the L2 page tables into the L1.
585 	 * This means that we can replace L1 mappings later on if necessary
586 	 */
587 	l1pagetable = kernel_l1pt.pv_pa;
588 
589 	/* Map the L2 pages tables in the L1 page table */
590 	pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
591 	    &kernel_pt_table[KERNEL_PT_SYS]);
592 	for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
593 		pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
594 		    &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
595 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
596 		pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
597 		    &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
598 
599 	/* update the top of the kernel VM */
600 	pmap_curmaxkvaddr =
601 	    KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
602 
603 #ifdef VERBOSE_INIT_ARM
604 	printf("Mapping kernel\n");
605 #endif
606 
607 	/* Now we fill in the L2 pagetable for the kernel static code/data */
608 	{
609 		extern char etext[], _end[];
610 		size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
611 		size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
612 		u_int logical;
613 
614 		textsize = (textsize + PGOFSET) & ~PGOFSET;
615 		totalsize = (totalsize + PGOFSET) & ~PGOFSET;
616 
617 		logical = 0x00200000;	/* offset of kernel in RAM */
618 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
619 		    physical_start + logical, textsize,
620 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
621 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
622 		    physical_start + logical, totalsize - textsize,
623 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
624 	}
625 
626 #ifdef VERBOSE_INIT_ARM
627 	printf("Constructing L2 page tables\n");
628 #endif
629 
630 	/* Map the stack pages */
631 	pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
632 	    IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
633 	pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
634 	    ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
635 	pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
636 	    UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
637 	pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
638 	    UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
639 
640 	pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
641 	    L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
642 
643 	for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
644 		pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
645 		    kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
646 		    VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
647 	}
648 
649 	/* Map the vector page. */
650 	pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
651 	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
652 
653 	/* Map the statically mapped devices. */
654 	pmap_devmap_bootstrap(l1pagetable, tsarm_devmap);
655 
656 	/*
657 	 * Update the physical_freestart/physical_freeend/free_pages
658 	 * variables.
659 	 */
660 	{
661 		extern char _end[];
662 
663 		physical_freestart = physical_start +
664 		    (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
665 		     KERNEL_BASE);
666 		physical_freeend = physical_end;
667 		free_pages =
668 		    (physical_freeend - physical_freestart) / PAGE_SIZE;
669 	}
670 
671 	/*
672 	 * Now we have the real page tables in place so we can switch to them.
673 	 * Once this is done we will be running with the REAL kernel page
674 	 * tables.
675 	 */
676 
677 	/* Switch tables */
678 #ifdef VERBOSE_INIT_ARM
679 	printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
680 	       physical_freestart, free_pages, free_pages);
681 	printf("switching to new L1 page table  @%#lx...", kernel_l1pt.pv_pa);
682 #endif
683 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
684 	setttb(kernel_l1pt.pv_pa);
685 	cpu_tlb_flushID();
686 	cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
687 
688 	/*
689 	 * Moved from cpu_startup() as data_abort_handler() references
690 	 * this during uvm init
691 	 */
692 	proc0paddr = (struct user *)kernelstack.pv_va;
693 	lwp0.l_addr = proc0paddr;
694 
695 #ifdef VERBOSE_INIT_ARM
696 	printf("done!\n");
697 #endif
698 
699 #ifdef VERBOSE_INIT_ARM
700 	printf("bootstrap done.\n");
701 #endif
702 
703 	arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
704 
705 	/*
706 	 * Pages were allocated during the secondary bootstrap for the
707 	 * stacks for different CPU modes.
708 	 * We must now set the r13 registers in the different CPU modes to
709 	 * point to these stacks.
710 	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
711 	 * of the stack memory.
712 	 */
713 #ifdef VERBOSE_INIT_ARM
714 	printf("init subsystems: stacks ");
715 #endif
716 
717 	set_stackptr(PSR_IRQ32_MODE,
718 	    irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
719 	set_stackptr(PSR_ABT32_MODE,
720 	    abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
721 	set_stackptr(PSR_UND32_MODE,
722 	    undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
723 
724 	/*
725 	 * Well we should set a data abort handler.
726 	 * Once things get going this will change as we will need a proper
727 	 * handler.
728 	 * Until then we will use a handler that just panics but tells us
729 	 * why.
730 	 * Initialisation of the vectors will just panic on a data abort.
731 	 * This just fills in a slightly better one.
732 	 */
733 #ifdef VERBOSE_INIT_ARM
734 	printf("vectors ");
735 #endif
736 	data_abort_handler_address = (u_int)data_abort_handler;
737 	prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
738 	undefined_handler_address = (u_int)undefinedinstruction_bounce;
739 
740 	/* Initialise the undefined instruction handlers */
741 #ifdef VERBOSE_INIT_ARM
742 	printf("undefined ");
743 #endif
744 	undefined_init();
745 
746 	/* Load memory into UVM. */
747 #ifdef VERBOSE_INIT_ARM
748 	printf("page ");
749 #endif
750 	uvm_setpagesize();	/* initialize PAGE_SIZE-dependent variables */
751 	uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
752 	    atop(physical_freestart), atop(physical_freeend),
753 	    VM_FREELIST_DEFAULT);
754 	uvm_page_physload(0, atop(physical_freeend_low),
755 	    0, atop(physical_freeend_low),
756 	    VM_FREELIST_DEFAULT);
757 	/*
758 	 * There is 32 Mb of memory on the TS-7200 in 4 8Mb chunks, so far
759 	 * we've only been working with the first one mapped at 0x0.  Tell
760 	 * UVM about the others.
761 	 */
762 	uvm_page_physload(atop(0x1000000), atop(0x1800000),
763 	    atop(0x1000000), atop(0x1800000),
764 	    VM_FREELIST_DEFAULT);
765 	uvm_page_physload(atop(0x4000000), atop(0x4800000),
766 	    atop(0x4000000), atop(0x4800000),
767 	    VM_FREELIST_DEFAULT);
768 	uvm_page_physload(atop(0x5000000), atop(0x5800000),
769 	    atop(0x5000000), atop(0x5800000),
770 	    VM_FREELIST_DEFAULT);
771 
772 	physmem = 0x2000000 / PAGE_SIZE;
773 
774 
775 	/* Boot strap pmap telling it where the kernel page table is */
776 #ifdef VERBOSE_INIT_ARM
777 	printf("pmap ");
778 #endif
779 	pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
780 
781 	/* Setup the IRQ system */
782 #ifdef VERBOSE_INIT_ARM
783 	printf("irq ");
784 #endif
785 	ep93xx_intr_init();
786 #if NISA > 0
787 	isa_intr_init();
788 
789 #ifdef VERBOSE_INIT_ARM
790 	printf("isa ");
791 #endif
792 	isa_tsarm_init(TS7XXX_IO16_VBASE + TS7XXX_ISAIO,
793 		TS7XXX_IO16_VBASE + TS7XXX_ISAMEM);
794 #endif
795 
796 #ifdef VERBOSE_INIT_ARM
797 	printf("done.\n");
798 #endif
799 
800 #ifdef BOOTHOWTO
801 	boothowto = BOOTHOWTO;
802 #endif
803 
804 #ifdef DDB
805 	db_machine_init();
806 	if (boothowto & RB_KDB)
807 		Debugger();
808 #endif
809 
810 	/* We return the new stack pointer address */
811 	return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
812 }
813 
814 void
815 consinit(void)
816 {
817 	static int consinit_called;
818 	bus_space_handle_t ioh;
819 
820 	if (consinit_called != 0)
821 		return;
822 
823 	consinit_called = 1;
824 
825 	/*
826 	 * Console devices are already mapped in VA.  Our devmap reflects
827 	 * this, so register it now so drivers can map the console
828 	 * device.
829 	 */
830 	pmap_devmap_register(tsarm_devmap);
831 #if 0
832 	isa_tsarm_init(TS7XXX_IO16_VBASE + TS7XXX_ISAIO,
833 		TS7XXX_IO16_VBASE + TS7XXX_ISAMEM);
834 
835         if (comcnattach(&isa_io_bs_tag, 0x3e8, comcnspeed,
836             COM_FREQ, COM_TYPE_NORMAL, comcnmode))
837         {
838                 panic("can't init serial console");
839         }
840 #endif
841 
842 #if NEPCOM > 0
843 	bus_space_map(&ep93xx_bs_tag, EP93XX_APB_HWBASE + EP93XX_APB_UART1,
844 		EP93XX_APB_UART_SIZE, 0, &ioh);
845         if (epcomcnattach(&ep93xx_bs_tag, EP93XX_APB_HWBASE + EP93XX_APB_UART1,
846 		ioh, comcnspeed, comcnmode))
847 	{
848 		panic("can't init serial console");
849 	}
850 #else
851 	panic("serial console not configured");
852 #endif
853 #if KGDB
854 #if NEPCOM > 0
855 	if (strcmp(kgdb_devname, "epcom") == 0) {
856 		com_kgdb_attach(&ep93xx_bs_tag, kgdb_devaddr, kgdb_devrate,
857 			kgdb_devmode);
858 	}
859 #endif	/* NEPCOM > 0 */
860 #endif	/* KGDB */
861 }
862 
863 
864 bus_dma_tag_t
865 ep93xx_bus_dma_init(struct arm32_bus_dma_tag *dma_tag_template)
866 {
867 	int i;
868 	struct arm32_bus_dma_tag *dmat;
869 
870 	for (i = 0; i < bootconfig.dramblocks; i++) {
871 		tsarm_dma_ranges[i].dr_sysbase = bootconfig.dram[i].address;
872 		tsarm_dma_ranges[i].dr_busbase = bootconfig.dram[i].address;
873 		tsarm_dma_ranges[i].dr_len = bootconfig.dram[i].pages *
874 			PAGE_SIZE;
875 	}
876 
877 	dmat = dma_tag_template;
878 
879 	dmat->_ranges = tsarm_dma_ranges;
880 	dmat->_nranges = bootconfig.dramblocks;
881 
882 	return dmat;
883 }
884