ixdp425_machdep.c revision 1.4 1 /* $NetBSD: ixdp425_machdep.c,v 1.4 2003/06/01 01:49:57 ichiro Exp $ */
2 /*
3 * Copyright (c) 2003
4 * Ichiro FUKUHARA <ichiro (at) ichiro.org>.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Ichiro FUKUHARA.
18 * 4. The name of the company nor the name of the author may be used to
19 * endorse or promote products derived from this software without specific
20 * prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR
26 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34 /*
35 * Copyright (c) 1997,1998 Mark Brinicombe.
36 * Copyright (c) 1997,1998 Causality Limited.
37 * All rights reserved.
38 *
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
41 * are met:
42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in the
46 * documentation and/or other materials provided with the distribution.
47 * 3. All advertising materials mentioning features or use of this software
48 * must display the following acknowledgement:
49 * This product includes software developed by Mark Brinicombe
50 * for the NetBSD Project.
51 * 4. The name of the company nor the name of the author may be used to
52 * endorse or promote products derived from this software without specific
53 * prior written permission.
54 *
55 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
56 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
57 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
58 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
59 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
60 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
61 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 * SUCH DAMAGE.
66 */
67
68 /* Machine dependant functions for kernel setup for Intel IXP425 evaluation
69 * boards using RedBoot firmware.
70 */
71
72 #include "opt_ddb.h"
73 #include "opt_kgdb.h"
74 #include "opt_pmap_debug.h"
75
76 #include <sys/param.h>
77 #include <sys/device.h>
78 #include <sys/systm.h>
79 #include <sys/kernel.h>
80 #include <sys/exec.h>
81 #include <sys/proc.h>
82 #include <sys/msgbuf.h>
83 #include <sys/reboot.h>
84 #include <sys/termios.h>
85 #include <sys/ksyms.h>
86
87 #include <uvm/uvm_extern.h>
88
89 #include <dev/cons.h>
90
91 #include <machine/db_machdep.h>
92 #include <ddb/db_sym.h>
93 #include <ddb/db_extern.h>
94
95 #include <machine/bootconfig.h>
96 #include <machine/bus.h>
97 #include <machine/cpu.h>
98 #include <machine/frame.h>
99 #include <arm/undefined.h>
100
101 #include <arm/arm32/machdep.h>
102
103 #include <arm/xscale/ixp425reg.h>
104 #include <arm/xscale/ixp425var.h>
105
106 #include <arm/xscale/ixp425_sipvar.h>
107 #include <arm/xscale/ixp425_comvar.h>
108
109 #include "opt_ipkdb.h"
110 #include "ksyms.h"
111
112 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
113 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000)
114 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
115
116 /*
117 * The range 0xc1000000 - 0xccffffff is available for kernel VM space
118 * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
119 */
120 #define KERNEL_VM_SIZE 0x0C000000
121
122
123 /*
124 * Address to call from cpu_reset() to reset the machine.
125 * This is machine architecture dependant as it varies depending
126 * on where the ROM appears when you turn the MMU off.
127 */
128
129 u_int cpu_reset_address = 0x00000000;
130
131 /* Define various stack sizes in pages */
132 #define IRQ_STACK_SIZE 1
133 #define ABT_STACK_SIZE 1
134 #ifdef IPKDB
135 #define UND_STACK_SIZE 2
136 #else
137 #define UND_STACK_SIZE 1
138 #endif
139
140 BootConfig bootconfig; /* Boot config storage */
141 char *boot_args = NULL;
142 char *boot_file = NULL;
143
144 vm_offset_t physical_start;
145 vm_offset_t physical_freestart;
146 vm_offset_t physical_freeend;
147 vm_offset_t physical_end;
148 u_int free_pages;
149 vm_offset_t pagetables_start;
150 int physmem = 0;
151
152 /*int debug_flags;*/
153 #ifndef PMAP_STATIC_L1S
154 int max_processes = 64; /* Default number */
155 #endif /* !PMAP_STATIC_L1S */
156
157 /* Physical and virtual addresses for some global pages */
158 pv_addr_t systempage;
159 pv_addr_t irqstack;
160 pv_addr_t undstack;
161 pv_addr_t abtstack;
162 pv_addr_t kernelstack;
163 pv_addr_t minidataclean;
164
165 vm_offset_t msgbufphys;
166
167 extern u_int data_abort_handler_address;
168 extern u_int prefetch_abort_handler_address;
169 extern u_int undefined_handler_address;
170 extern int end;
171
172 #ifdef PMAP_DEBUG
173 extern int pmap_debug_level;
174 #endif
175
176 #define KERNEL_PT_SYS 0 /* L2 table for mapping zero page */
177
178 #define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */
179 #define KERNEL_PT_KERNEL_NUM 4
180 #define KERNEL_PT_IO (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
181 /* L2 tables for mapping kernel VM */
182 #define KERNEL_PT_VMDATA (KERNEL_PT_IO + 1)
183 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
184 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
185
186 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
187
188 struct user *proc0paddr;
189
190 /* Prototypes */
191
192 void consinit(void);
193 u_int cpu_get_control __P((void));
194
195 /*
196 * Define the default console speed for the board. This is generally
197 * what the firmware provided with the board defaults to.
198 */
199 #ifndef CONSPEED
200 #define CONSPEED B115200
201 #endif /* ! CONSPEED */
202
203 #ifndef CONUNIT
204 #define CONUNIT 0
205 #endif
206
207 #ifndef CONMODE
208 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB)) | CS8) /* 8N1 */
209 #endif
210
211 int comcnspeed = CONSPEED;
212 int comcnmode = CONMODE;
213 int comcnunit = CONUNIT;
214
215 #if KGDB
216 #ifndef KGDB_DEVNAME
217 #error Must define KGDB_DEVNAME
218 #endif
219 const char kgdb_devname[] = KGDB_DEVNAME;
220
221 #ifndef KGDB_DEVADDR
222 #error Must define KGDB_DEVADDR
223 #endif
224 unsigned long kgdb_devaddr = KGDB_DEVADDR;
225
226 #ifndef KGDB_DEVRATE
227 #define KGDB_DEVRATE CONSPEED
228 #endif
229 int kgdb_devrate = KGDB_DEVRATE;
230
231 #ifndef KGDB_DEVMODE
232 #define KGDB_DEVMODE CONMODE
233 #endif
234 int kgdb_devmode = KGDB_DEVMODE;
235 #endif /* KGDB */
236
237 /*
238 * void cpu_reboot(int howto, char *bootstr)
239 *
240 * Reboots the system
241 *
242 * Deal with any syncing, unmounting, dumping and shutdown hooks,
243 * then reset the CPU.
244 */
245 void
246 cpu_reboot(int howto, char *bootstr)
247 {
248 #ifdef DIAGNOSTIC
249 /* info */
250 printf("boot: howto=%08x curproc=%p\n", howto, curproc);
251 #endif
252
253 /*
254 * If we are still cold then hit the air brakes
255 * and crash to earth fast
256 */
257 if (cold) {
258 doshutdownhooks();
259 printf("The operating system has halted.\n");
260 printf("Please press any key to reboot.\n\n");
261 cngetc();
262 printf("rebooting...\n");
263 goto reset;
264 }
265
266 /* Disable console buffering */
267
268 /*
269 * If RB_NOSYNC was not specified sync the discs.
270 * Note: Unless cold is set to 1 here, syslogd will die during the
271 * unmount. It looks like syslogd is getting woken up only to find
272 * that it cannot page part of the binary in as the filesystem has
273 * been unmounted.
274 */
275 if (!(howto & RB_NOSYNC))
276 bootsync();
277
278 /* Say NO to interrupts */
279 splhigh();
280
281 /* Do a dump if requested. */
282 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
283 dumpsys();
284
285 /* Run any shutdown hooks */
286 doshutdownhooks();
287
288 /* Make sure IRQ's are disabled */
289 IRQdisable;
290
291 if (howto & RB_HALT) {
292 printf("The operating system has halted.\n");
293 printf("Please press any key to reboot.\n\n");
294 cngetc();
295 }
296
297 printf("rebooting...\n\r");
298 reset:
299 /*
300 * Make really really sure that all interrupts are disabled,
301 */
302 (void) disable_interrupts(I32_bit|F32_bit);
303 /*
304 * XXX system reset routine
305 */
306 (void) disable_interrupts(I32_bit|F32_bit);
307 /* ...and if that didn't work, just croak. */
308 printf("RESET FAILED!\n");
309 for (;;);
310 }
311
312 /*
313 * Mapping table for core kernel memory. This memory is mapped at init
314 * time with section mappings.
315 */
316 struct l1_sec_map {
317 vaddr_t va;
318 vaddr_t pa;
319 vsize_t size;
320 vm_prot_t prot;
321 int cache;
322 } l1_sec_table[] = {
323 /*
324 * Map the on-board devices VA == PA so that we can access them
325 * with the MMU on or off.
326 */
327 {
328 IXP425_UART0_HWBASE,
329 IXP425_UART0_HWBASE,
330 IXP425_REG_SIZE * 2,
331 VM_PROT_READ|VM_PROT_WRITE,
332 PTE_NOCACHE,
333 },
334 {
335 0,
336 0,
337 0,
338 0,
339 0,
340 }
341 };
342
343 /*
344 * u_int initarm(...)
345 *
346 * Initial entry point on startup. This gets called before main() is
347 * entered.
348 * It should be responsible for setting up everything that must be
349 * in place when main is called.
350 * This includes
351 * Taking a copy of the boot configuration structure.
352 * Initialising the physical console so characters can be printed.
353 * Setting up page tables for the kernel
354 * Relocating the kernel to the bottom of physical memory
355 */
356 u_int
357 initarm(void *arg)
358 {
359 extern vaddr_t xscale_cache_clean_addr;
360 #ifdef DIAGNOSTIC
361 extern vsize_t xscale_minidata_clean_size;
362 #endif
363 int loop;
364 int loop1;
365 u_int kerneldatasize, symbolsize;
366 u_int l1pagetable;
367 u_int freemempos;
368 pv_addr_t kernel_l1pt;
369 #if 0
370 paddr_t memstart;
371 psize_t memsize;
372 #endif
373
374 /*
375 * Since we map v0xf0000000 == p0xc8000000, it's possible for
376 * us to initialize the console now.
377 */
378 consinit();
379
380 #ifdef VERBOSE_INIT_ARM
381 /* Talk to the user */
382 printf("\nNetBSD/evbarm (IXP425) booting ...\n");
383 #endif
384
385 /*
386 * Heads up ... Setup the CPU / MMU / TLB functions
387 */
388 if (set_cpufuncs())
389 panic("cpu not recognized!");
390
391 /* XXX overwrite bootconfig to hardcoded values */
392 bootconfig.dramblocks = 1;
393 bootconfig.dram[0].address = 0x10000000;
394 bootconfig.dram[0].pages = 0x04000000 / PAGE_SIZE; /* SDRAM 64MB */
395
396 kerneldatasize = (u_int32_t)&end - (u_int32_t)KERNEL_TEXT_BASE;
397
398 #ifdef VERBOSE_INIT_ARM
399 printf("kernsize=0x%x\n", kerneldatasize);
400 #endif
401 kerneldatasize += symbolsize;
402 kerneldatasize = ((kerneldatasize - 1) & ~(PAGE_SIZE * 4 - 1)) + PAGE_SIZE * 8;
403
404 /*
405 * Set up the variables that define the availablilty of
406 * physical memory. For now, we're going to set
407 * physical_freestart to 0x10200000 (where the kernel
408 * was loaded), and allocate the memory we need downwards.
409 * If we get too close to the L1 table that we set up, we
410 * will panic. We will update physical_freestart and
411 * physical_freeend later to reflect what pmap_bootstrap()
412 * wants to see.
413 *
414 * XXX pmap_bootstrap() needs an enema.
415 */
416 physical_start = bootconfig.dram[0].address;
417 physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
418
419 physical_freestart = physical_start
420 + (KERNEL_TEXT_BASE - KERNEL_BASE) + kerneldatasize;
421 physical_freeend = physical_end;
422
423 physmem = (physical_end - physical_start) / PAGE_SIZE;
424
425 /* Tell the user about the memory */
426 #ifdef VERBOSE_INIT_ARM
427 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
428 physical_start, physical_end - 1);
429
430 printf("Allocating page tables\n");
431 #endif
432 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
433
434 freemempos = 0x10000000;
435
436 #ifdef VERBOSE_INIT_ARM
437 printf("CP15 Register1 = 0x%08x\n", cpu_get_control());
438 printf("physical_start = 0x%08lx, physical_end = 0x%08lx\n",
439 physical_start, physical_end);
440 #endif
441
442 /* Define a macro to simplify memory allocation */
443 #define valloc_pages(var, np) \
444 alloc_pages((var).pv_pa, (np)); \
445 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
446
447 #if 0
448 #define alloc_pages(var, np) \
449 physical_freeend -= ((np) * PAGE_SIZE); \
450 if (physical_freeend < physical_freestart) \
451 panic("initarm: out of memory"); \
452 (var) = physical_freeend; \
453 free_pages -= (np); \
454 memset((char *)(var), 0, ((np) * PAGE_SIZE));
455 #else
456 #define alloc_pages(var, np) \
457 (var) = freemempos; \
458 memset((char *)(var), 0, ((np) * PAGE_SIZE)); \
459 freemempos += (np) * PAGE_SIZE;
460 #endif
461
462 loop1 = 0;
463 kernel_l1pt.pv_pa = 0;
464 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
465 /* Are we 16KB aligned for an L1 ? */
466 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
467 && kernel_l1pt.pv_pa == 0) {
468 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
469 } else {
470 valloc_pages(kernel_pt_table[loop1],
471 L2_TABLE_SIZE / PAGE_SIZE);
472 ++loop1;
473 }
474 }
475
476 /* This should never be able to happen but better confirm that. */
477 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
478 panic("initarm: Failed to align the kernel page directory");
479
480 /*
481 * Allocate a page for the system page mapped to V0x00000000
482 * This page will just contain the system vectors and can be
483 * shared by all processes.
484 */
485 alloc_pages(systempage.pv_pa, 1);
486
487 /* Allocate stacks for all modes */
488 valloc_pages(irqstack, IRQ_STACK_SIZE);
489 valloc_pages(abtstack, ABT_STACK_SIZE);
490 valloc_pages(undstack, UND_STACK_SIZE);
491 valloc_pages(kernelstack, UPAGES);
492
493 /* Allocate enough pages for cleaning the Mini-Data cache. */
494 KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
495 valloc_pages(minidataclean, 1);
496
497 #ifdef VERBOSE_INIT_ARM
498 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
499 irqstack.pv_va);
500 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
501 abtstack.pv_va);
502 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
503 undstack.pv_va);
504 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
505 kernelstack.pv_va);
506 #endif
507
508 /*
509 * XXX Defer this to later so that we can reclaim the memory
510 * XXX used by the RedBoot page tables.
511 */
512 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
513
514 /*
515 * Ok we have allocated physical pages for the primary kernel
516 * page tables
517 */
518
519 #ifdef VERBOSE_INIT_ARM
520 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
521 #endif
522
523 /*
524 * Now we start construction of the L1 page table
525 * We start by mapping the L2 page tables into the L1.
526 * This means that we can replace L1 mappings later on if necessary
527 */
528 l1pagetable = kernel_l1pt.pv_pa;
529
530 /* Map the L2 pages tables in the L1 page table */
531 pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
532 &kernel_pt_table[KERNEL_PT_SYS]);
533 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
534 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
535 &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
536 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
537 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
538 &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
539
540 /* update the top of the kernel VM */
541 pmap_curmaxkvaddr =
542 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
543
544 pmap_link_l2pt(l1pagetable, IXP425_IO_VBASE,
545 &kernel_pt_table[KERNEL_PT_IO]);
546
547 #ifdef VERBOSE_INIT_ARM
548 printf("Mapping kernel\n");
549 #endif
550
551 /* Now we fill in the L2 pagetable for the kernel static code/data */
552 {
553 extern char etext[], _end[];
554 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
555 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
556 u_int logical;
557
558 textsize = (textsize + PGOFSET) & ~PGOFSET;
559 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
560
561 logical = 0x00200000; /* offset of kernel in RAM */
562
563 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
564 physical_start + logical, textsize,
565 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
566 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
567 physical_start + logical, totalsize - textsize,
568 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
569 }
570
571 #ifdef VERBOSE_INIT_ARM
572 printf("Constructing L2 page tables\n");
573 #endif
574
575 /* Map the stack pages */
576 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
577 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
578 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
579 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
580 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
581 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
582 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
583 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
584
585 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
586 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
587
588 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
589 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
590 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
591 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
592 }
593
594 /* Map the Mini-Data cache clean area. */
595 xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
596 minidataclean.pv_pa);
597
598 /* Map the vector page. */
599 pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
600 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
601
602 /*
603 * Map the IXP425 registers
604 */
605
606 ixp425_pmap_io_reg(l1pagetable);
607
608 /*
609 * Map devices we can map w/ section mappings.
610 */
611 loop = 0;
612 while (l1_sec_table[loop].size) {
613 vm_size_t sz;
614
615 #ifdef VERBOSE_INIT_ARM
616 printf("%08lx -> %08lx @ %08lx\n", l1_sec_table[loop].pa,
617 l1_sec_table[loop].pa + l1_sec_table[loop].size - 1,
618 l1_sec_table[loop].va);
619 #endif
620 for (sz = 0; sz < l1_sec_table[loop].size; sz += L1_S_SIZE)
621 pmap_map_section(l1pagetable,
622 l1_sec_table[loop].va + sz,
623 l1_sec_table[loop].pa + sz,
624 l1_sec_table[loop].prot,
625 l1_sec_table[loop].cache);
626 ++loop;
627 }
628
629
630 /*
631 * Give the XScale global cache clean code an appropriately
632 * sized chunk of unmapped VA space starting at 0xff000000
633 * (our device mappings end before this address).
634 */
635 xscale_cache_clean_addr = 0xff000000U;
636
637 /*
638 * Now we have the real page tables in place so we can switch to them.
639 * Once this is done we will be running with the REAL kernel page
640 * tables.
641 */
642
643 /*
644 * Update the physical_freestart/physical_freeend/free_pages
645 * variables.
646 */
647 {
648 extern char _end[];
649
650 physical_freestart = physical_start +
651 (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
652 KERNEL_BASE);
653 physical_freeend = physical_end;
654 free_pages =
655 (physical_freeend - physical_freestart) / PAGE_SIZE;
656 }
657
658 /* Switch tables */
659 #ifdef VERBOSE_INIT_ARM
660 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
661 physical_freestart, free_pages, free_pages);
662 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
663 #endif
664 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
665 setttb(kernel_l1pt.pv_pa);
666 cpu_tlb_flushID();
667 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
668
669 /*
670 * Moved from cpu_startup() as data_abort_handler() references
671 * this during uvm init
672 */
673 proc0paddr = (struct user *)kernelstack.pv_va;
674 lwp0.l_addr = proc0paddr;
675
676 #ifdef VERBOSE_INIT_ARM
677 printf("bootstrap done.\n");
678 #endif
679
680 arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
681
682 /*
683 * Pages were allocated during the secondary bootstrap for the
684 * stacks for different CPU modes.
685 * We must now set the r13 registers in the different CPU modes to
686 * point to these stacks.
687 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
688 * of the stack memory.
689 */
690 #ifdef VERBOSE_INIT_ARM
691 printf("init subsystems: stacks ");
692 #endif
693
694 set_stackptr(PSR_IRQ32_MODE,
695 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
696 set_stackptr(PSR_ABT32_MODE,
697 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
698 set_stackptr(PSR_UND32_MODE,
699 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
700
701 /*
702 * Well we should set a data abort handler.
703 * Once things get going this will change as we will need a proper
704 * handler.
705 * Until then we will use a handler that just panics but tells us
706 * why.
707 * Initialisation of the vectors will just panic on a data abort.
708 * This just fills in a slighly better one.
709 */
710 #ifdef VERBOSE_INIT_ARM
711 printf("vectors ");
712 #endif
713 data_abort_handler_address = (u_int)data_abort_handler;
714 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
715 undefined_handler_address = (u_int)undefinedinstruction_bounce;
716
717 /* Initialise the undefined instruction handlers */
718 #ifdef VERBOSE_INIT_ARM
719 printf("undefined ");
720 #endif
721 undefined_init();
722
723 /* Load memory into UVM. */
724 #ifdef VERBOSE_INIT_ARM
725 printf("page ");
726 #endif
727 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
728 uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
729 atop(physical_freestart), atop(physical_freeend),
730 VM_FREELIST_DEFAULT);
731
732 /* Boot strap pmap telling it where the kernel page table is */
733 #ifdef VERBOSE_INIT_ARM
734 printf("pmap ");
735 #endif
736 pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE,
737 KERNEL_VM_BASE + KERNEL_VM_SIZE);
738
739 /* Setup the IRQ system */
740 #ifdef VERBOSE_INIT_ARM
741 printf("irq ");
742 #endif
743 ixp425_intr_init();
744 #ifdef VERBOSE_INIT_ARM
745 printf("\nAll initialize done!\nNow Starting NetBSD, Hear we go!\n");
746 #endif
747
748 #ifdef BOOTHOWTO
749 boothowto = BOOTHOWTO;
750 #endif
751
752 #ifdef IPKDB
753 /* Initialise ipkdb */
754 ipkdb_init();
755 if (boothowto & RB_KDB)
756 ipkdb_connect(0);
757 #endif
758
759 #if NKSYMS || defined(DDB) || defined(LKM)
760 /* Firmware doesn't load symbols. */
761 ksyms_init(0, NULL, NULL);
762 #endif
763
764 #ifdef DDB
765 db_machine_init();
766 if (boothowto & RB_KDB)
767 Debugger();
768 #endif
769
770 /* We return the new stack pointer address */
771 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
772 }
773
774 /*
775 * consinit
776 */
777 void
778 consinit(void)
779 {
780 extern struct bus_space ixpsip_bs_tag;
781 static int consinit_called;
782
783 if (consinit_called != 0)
784 return;
785
786 consinit_called = 1;
787 if (ixdp_ixp4xx_comcnattach(&ixpsip_bs_tag, comcnunit,
788 comcnspeed, FREQ, comcnmode))
789 panic("can't init serial console (UART%d)", comcnunit);
790 }
791