ixdp425_machdep.c revision 1.13.10.1 1 /* $NetBSD: ixdp425_machdep.c,v 1.13.10.1 2006/06/21 14:50:47 yamt 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 <sys/cdefs.h>
73 __KERNEL_RCSID(0, "$NetBSD: ixdp425_machdep.c,v 1.13.10.1 2006/06/21 14:50:47 yamt Exp $");
74
75 #include "opt_ddb.h"
76 #include "opt_kgdb.h"
77 #include "opt_pmap_debug.h"
78
79 #include <sys/param.h>
80 #include <sys/device.h>
81 #include <sys/systm.h>
82 #include <sys/kernel.h>
83 #include <sys/exec.h>
84 #include <sys/proc.h>
85 #include <sys/msgbuf.h>
86 #include <sys/reboot.h>
87 #include <sys/termios.h>
88 #include <sys/ksyms.h>
89
90 #include <uvm/uvm_extern.h>
91
92 #include <dev/cons.h>
93
94 #include <machine/db_machdep.h>
95 #include <ddb/db_sym.h>
96 #include <ddb/db_extern.h>
97
98 #include <machine/bootconfig.h>
99 #include <machine/bus.h>
100 #include <machine/cpu.h>
101 #include <machine/frame.h>
102 #include <arm/undefined.h>
103
104 #include <arm/arm32/machdep.h>
105
106 #include <arm/xscale/ixp425reg.h>
107 #include <arm/xscale/ixp425var.h>
108 #include <arm/xscale/ixp425_sipvar.h>
109
110 #include <evbarm/ixdp425/ixdp425reg.h>
111
112 #include "com.h"
113 #if NCOM > 0
114 #include <dev/ic/comreg.h>
115 #include <dev/ic/comvar.h>
116 #endif
117
118 #include "opt_ipkdb.h"
119 #include "ksyms.h"
120
121 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
122 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000)
123 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
124
125 /*
126 * The range 0xc1000000 - 0xccffffff is available for kernel VM space
127 * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
128 */
129 #define KERNEL_VM_SIZE 0x0C000000
130
131
132 /*
133 * Address to call from cpu_reset() to reset the machine.
134 * This is machine architecture dependant as it varies depending
135 * on where the ROM appears when you turn the MMU off.
136 */
137
138 u_int cpu_reset_address = 0x00000000;
139
140 /* Define various stack sizes in pages */
141 #define IRQ_STACK_SIZE 1
142 #define ABT_STACK_SIZE 1
143 #ifdef IPKDB
144 #define UND_STACK_SIZE 2
145 #else
146 #define UND_STACK_SIZE 1
147 #endif
148
149 BootConfig bootconfig; /* Boot config storage */
150 char *boot_args = NULL;
151 char *boot_file = NULL;
152
153 vm_offset_t physical_start;
154 vm_offset_t physical_freestart;
155 vm_offset_t physical_freeend;
156 vm_offset_t physical_end;
157 u_int free_pages;
158 vm_offset_t pagetables_start;
159 int physmem = 0;
160
161 /* Physical and virtual addresses for some global pages */
162 pv_addr_t systempage;
163 pv_addr_t irqstack;
164 pv_addr_t undstack;
165 pv_addr_t abtstack;
166 pv_addr_t kernelstack;
167 pv_addr_t minidataclean;
168
169 vm_offset_t msgbufphys;
170
171 extern u_int data_abort_handler_address;
172 extern u_int prefetch_abort_handler_address;
173 extern u_int undefined_handler_address;
174 extern int end;
175
176 #ifdef PMAP_DEBUG
177 extern int pmap_debug_level;
178 #endif
179
180 #define KERNEL_PT_SYS 0 /* L2 table for mapping zero page */
181
182 #define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */
183 #define KERNEL_PT_KERNEL_NUM 4
184 #define KERNEL_PT_IO (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
185 /* L2 tables for mapping kernel VM */
186 #define KERNEL_PT_VMDATA (KERNEL_PT_IO + 1)
187 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
188 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
189
190 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
191
192 struct user *proc0paddr;
193
194 /* Prototypes */
195
196 void consinit(void);
197 u_int cpu_get_control __P((void));
198
199 /*
200 * Define the default console speed for the board. This is generally
201 * what the firmware provided with the board defaults to.
202 */
203 #ifndef CONSPEED
204 #define CONSPEED B115200
205 #endif /* ! CONSPEED */
206
207 #ifndef CONUNIT
208 #define CONUNIT 0
209 #endif
210
211 #ifndef CONMODE
212 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB)) | CS8) /* 8N1 */
213 #endif
214
215 int comcnspeed = CONSPEED;
216 int comcnmode = CONMODE;
217 int comcnunit = CONUNIT;
218
219 #if KGDB
220 #ifndef KGDB_DEVNAME
221 #error Must define KGDB_DEVNAME
222 #endif
223 const char kgdb_devname[] = KGDB_DEVNAME;
224
225 #ifndef KGDB_DEVADDR
226 #error Must define KGDB_DEVADDR
227 #endif
228 unsigned long kgdb_devaddr = KGDB_DEVADDR;
229
230 #ifndef KGDB_DEVRATE
231 #define KGDB_DEVRATE CONSPEED
232 #endif
233 int kgdb_devrate = KGDB_DEVRATE;
234
235 #ifndef KGDB_DEVMODE
236 #define KGDB_DEVMODE CONMODE
237 #endif
238 int kgdb_devmode = KGDB_DEVMODE;
239 #endif /* KGDB */
240
241 /*
242 * void cpu_reboot(int howto, char *bootstr)
243 *
244 * Reboots the system
245 *
246 * Deal with any syncing, unmounting, dumping and shutdown hooks,
247 * then reset the CPU.
248 */
249 void
250 cpu_reboot(int howto, char *bootstr)
251 {
252 u_int32_t reg;
253
254 #ifdef DIAGNOSTIC
255 /* info */
256 printf("boot: howto=%08x curproc=%p\n", howto, curproc);
257 #endif
258
259 /*
260 * If we are still cold then hit the air brakes
261 * and crash to earth fast
262 */
263 if (cold) {
264 doshutdownhooks();
265 printf("The operating system has halted.\n");
266 printf("Please press any key to reboot.\n\n");
267 cngetc();
268 printf("rebooting...\n");
269 goto reset;
270 }
271
272 /* Disable console buffering */
273
274 /*
275 * If RB_NOSYNC was not specified sync the discs.
276 * Note: Unless cold is set to 1 here, syslogd will die during the
277 * unmount. It looks like syslogd is getting woken up only to find
278 * that it cannot page part of the binary in as the filesystem has
279 * been unmounted.
280 */
281 if (!(howto & RB_NOSYNC))
282 bootsync();
283
284 /* Say NO to interrupts */
285 splhigh();
286
287 /* Do a dump if requested. */
288 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
289 dumpsys();
290
291 /* Run any shutdown hooks */
292 doshutdownhooks();
293
294 /* Make sure IRQ's are disabled */
295 IRQdisable;
296
297 if (howto & RB_HALT) {
298 printf("The operating system has halted.\n");
299 printf("Please press any key to reboot.\n\n");
300 cngetc();
301 }
302
303 printf("rebooting...\n\r");
304 reset:
305 /*
306 * Make really really sure that all interrupts are disabled,
307 */
308 (void) disable_interrupts(I32_bit|F32_bit);
309 IXPREG(IXP425_INT_ENABLE) = 0;
310
311 /*
312 * Map the boot Flash device down at physical address 0.
313 * This is safe since NetBSD runs out of an alias of
314 * SDRAM at 0x10000000.
315 */
316 reg = EXP_CSR_READ_4(ixpsip_softc, EXP_CNFG0_OFFSET);
317 reg |= EXP_CNFG0_MEM_MAP;
318 EXP_CSR_WRITE_4(ixpsip_softc, EXP_CNFG0_OFFSET, reg);
319
320 /*
321 * Jump into the bootcode's reset vector
322 *
323 * XXX:
324 * Redboot doesn't like the state in which we leave the PCI
325 * ethernet card, and so fails to detect it on reboot. This
326 * pretty much necessitates a hard reset/power cycle to be
327 * able to download a new kernel image over ethernet.
328 *
329 * I suspect this is due to a bug in Redboot's i82557 driver.
330 */
331 cpu_reset();
332
333 /* ...and if that didn't work, just croak. */
334 printf("RESET FAILED!\n");
335 for (;;);
336 }
337
338 /* Static device mappings. */
339 static const struct pmap_devmap ixp425_devmap[] = {
340 /* Physical/Virtual address for I/O space */
341 {
342 IXP425_IO_VBASE,
343 IXP425_IO_HWBASE,
344 IXP425_IO_SIZE,
345 VM_PROT_READ|VM_PROT_WRITE,
346 PTE_NOCACHE,
347 },
348
349 /* Expansion Bus */
350 {
351 IXP425_EXP_VBASE,
352 IXP425_EXP_HWBASE,
353 IXP425_EXP_SIZE,
354 VM_PROT_READ|VM_PROT_WRITE,
355 PTE_NOCACHE,
356 },
357
358 /* IXP425 PCI Configuration */
359 {
360 IXP425_PCI_VBASE,
361 IXP425_PCI_HWBASE,
362 IXP425_PCI_SIZE,
363 VM_PROT_READ|VM_PROT_WRITE,
364 PTE_NOCACHE,
365 },
366
367 /* SDRAM Controller */
368 {
369 IXP425_MCU_VBASE,
370 IXP425_MCU_HWBASE,
371 IXP425_MCU_SIZE,
372 VM_PROT_READ|VM_PROT_WRITE,
373 PTE_NOCACHE,
374 },
375
376 /* PCI Memory Space */
377 {
378 IXP425_PCI_MEM_VBASE,
379 IXP425_PCI_MEM_HWBASE,
380 IXP425_PCI_MEM_SIZE,
381 VM_PROT_READ|VM_PROT_WRITE,
382 PTE_NOCACHE,
383 },
384
385 {
386 0,
387 0,
388 0,
389 0,
390 0,
391 }
392 };
393
394 /*
395 * u_int initarm(...)
396 *
397 * Initial entry point on startup. This gets called before main() is
398 * entered.
399 * It should be responsible for setting up everything that must be
400 * in place when main is called.
401 * This includes
402 * Taking a copy of the boot configuration structure.
403 * Initialising the physical console so characters can be printed.
404 * Setting up page tables for the kernel
405 * Relocating the kernel to the bottom of physical memory
406 */
407 u_int
408 initarm(void *arg)
409 {
410 extern vaddr_t xscale_cache_clean_addr;
411 #ifdef DIAGNOSTIC
412 extern vsize_t xscale_minidata_clean_size;
413 #endif
414 int loop;
415 int loop1;
416 u_int kerneldatasize;
417 u_int l1pagetable;
418 u_int freemempos;
419 pv_addr_t kernel_l1pt;
420
421 /*
422 * Since we map v0xf0000000 == p0xc8000000, it's possible for
423 * us to initialize the console now.
424 */
425 consinit();
426
427 #ifdef VERBOSE_INIT_ARM
428 /* Talk to the user */
429 printf("\nNetBSD/evbarm (Intel IXDP425) booting ...\n");
430 #endif
431
432 /*
433 * Heads up ... Setup the CPU / MMU / TLB functions
434 */
435 if (set_cpufuncs())
436 panic("cpu not recognized!");
437
438 /* XXX overwrite bootconfig to hardcoded values */
439 bootconfig.dramblocks = 1;
440 bootconfig.dram[0].address = 0x10000000;
441 bootconfig.dram[0].pages = ixp425_sdram_size() / PAGE_SIZE;
442
443 kerneldatasize = (u_int32_t)&end - (u_int32_t)KERNEL_TEXT_BASE;
444
445 #ifdef VERBOSE_INIT_ARM
446 printf("kernsize=0x%x\n", kerneldatasize);
447 #endif
448 kerneldatasize = ((kerneldatasize - 1) & ~(PAGE_SIZE * 4 - 1)) + PAGE_SIZE * 8;
449
450 /*
451 * Set up the variables that define the availablilty of
452 * physical memory. For now, we're going to set
453 * physical_freestart to 0x10200000 (where the kernel
454 * was loaded), and allocate the memory we need downwards.
455 * If we get too close to the L1 table that we set up, we
456 * will panic. We will update physical_freestart and
457 * physical_freeend later to reflect what pmap_bootstrap()
458 * wants to see.
459 *
460 * XXX pmap_bootstrap() needs an enema.
461 */
462 physical_start = bootconfig.dram[0].address;
463 physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
464
465 physical_freestart = physical_start
466 + (KERNEL_TEXT_BASE - KERNEL_BASE) + kerneldatasize;
467 physical_freeend = physical_end;
468
469 physmem = (physical_end - physical_start) / PAGE_SIZE;
470
471 /* Tell the user about the memory */
472 #ifdef VERBOSE_INIT_ARM
473 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
474 physical_start, physical_end - 1);
475
476 printf("Allocating page tables\n");
477 #endif
478 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
479
480 freemempos = 0x10000000;
481
482 #ifdef VERBOSE_INIT_ARM
483 printf("physical_start = 0x%08lx, physical_end = 0x%08lx\n",
484 physical_start, physical_end);
485 #endif
486
487 /* Define a macro to simplify memory allocation */
488 #define valloc_pages(var, np) \
489 alloc_pages((var).pv_pa, (np)); \
490 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
491
492 #if 0
493 #define alloc_pages(var, np) \
494 physical_freeend -= ((np) * PAGE_SIZE); \
495 if (physical_freeend < physical_freestart) \
496 panic("initarm: out of memory"); \
497 (var) = physical_freeend; \
498 free_pages -= (np); \
499 memset((char *)(var), 0, ((np) * PAGE_SIZE));
500 #else
501 #define alloc_pages(var, np) \
502 (var) = freemempos; \
503 memset((char *)(var), 0, ((np) * PAGE_SIZE)); \
504 freemempos += (np) * PAGE_SIZE;
505 #endif
506
507 loop1 = 0;
508 kernel_l1pt.pv_pa = 0;
509 kernel_l1pt.pv_va = 0;
510 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
511 /* Are we 16KB aligned for an L1 ? */
512 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
513 && kernel_l1pt.pv_pa == 0) {
514 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
515 } else {
516 valloc_pages(kernel_pt_table[loop1],
517 L2_TABLE_SIZE / PAGE_SIZE);
518 ++loop1;
519 }
520 }
521
522 /* This should never be able to happen but better confirm that. */
523 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
524 panic("initarm: Failed to align the kernel page directory");
525
526 /*
527 * Allocate a page for the system page.
528 * This page will just contain the system vectors and can be
529 * shared by all processes.
530 */
531 alloc_pages(systempage.pv_pa, 1);
532
533 /* Allocate stacks for all modes */
534 valloc_pages(irqstack, IRQ_STACK_SIZE);
535 valloc_pages(abtstack, ABT_STACK_SIZE);
536 valloc_pages(undstack, UND_STACK_SIZE);
537 valloc_pages(kernelstack, UPAGES);
538
539 /* Allocate enough pages for cleaning the Mini-Data cache. */
540 KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
541 valloc_pages(minidataclean, 1);
542
543 #ifdef VERBOSE_INIT_ARM
544 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
545 irqstack.pv_va);
546 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
547 abtstack.pv_va);
548 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
549 undstack.pv_va);
550 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
551 kernelstack.pv_va);
552 #endif
553
554 /*
555 * XXX Defer this to later so that we can reclaim the memory
556 * XXX used by the RedBoot page tables.
557 */
558 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
559
560 /*
561 * Ok we have allocated physical pages for the primary kernel
562 * page tables
563 */
564
565 #ifdef VERBOSE_INIT_ARM
566 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
567 #endif
568
569 /*
570 * Now we start construction of the L1 page table
571 * We start by mapping the L2 page tables into the L1.
572 * This means that we can replace L1 mappings later on if necessary
573 */
574 l1pagetable = kernel_l1pt.pv_pa;
575
576 /* Map the L2 pages tables in the L1 page table */
577 pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
578 &kernel_pt_table[KERNEL_PT_SYS]);
579 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
580 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
581 &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
582 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
583 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
584 &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
585
586 /* update the top of the kernel VM */
587 pmap_curmaxkvaddr =
588 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
589
590 pmap_link_l2pt(l1pagetable, IXP425_IO_VBASE,
591 &kernel_pt_table[KERNEL_PT_IO]);
592
593 #ifdef VERBOSE_INIT_ARM
594 printf("Mapping kernel\n");
595 #endif
596
597 /* Now we fill in the L2 pagetable for the kernel static code/data */
598 {
599 extern char etext[], _end[];
600 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
601 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
602 u_int logical;
603
604 textsize = (textsize + PGOFSET) & ~PGOFSET;
605 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
606
607 logical = 0x00200000; /* offset of kernel in RAM */
608
609 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
610 physical_start + logical, textsize,
611 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
612 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
613 physical_start + logical, totalsize - textsize,
614 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
615 }
616
617 #ifdef VERBOSE_INIT_ARM
618 printf("Constructing L2 page tables\n");
619 #endif
620
621 /* Map the stack pages */
622 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
623 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
624 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
625 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
626 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
627 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
628 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
629 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
630
631 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
632 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
633
634 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
635 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
636 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
637 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
638 }
639
640 /* Map the Mini-Data cache clean area. */
641 xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
642 minidataclean.pv_pa);
643
644 /* Map the vector page. */
645 pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
646 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
647
648 /*
649 * Map the IXP425 registers
650 */
651 pmap_devmap_bootstrap(l1pagetable, ixp425_devmap);
652
653 /*
654 * Give the XScale global cache clean code an appropriately
655 * sized chunk of unmapped VA space starting at 0xff000000
656 * (our device mappings end before this address).
657 */
658 xscale_cache_clean_addr = 0xff000000U;
659
660 /*
661 * Now we have the real page tables in place so we can switch to them.
662 * Once this is done we will be running with the REAL kernel page
663 * tables.
664 */
665
666 /*
667 * Update the physical_freestart/physical_freeend/free_pages
668 * variables.
669 */
670 {
671 extern char _end[];
672
673 physical_freestart = physical_start +
674 (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
675 KERNEL_BASE);
676 physical_freeend = physical_end;
677 free_pages =
678 (physical_freeend - physical_freestart) / PAGE_SIZE;
679 }
680
681 /* Switch tables */
682 #ifdef VERBOSE_INIT_ARM
683 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
684 physical_freestart, free_pages, free_pages);
685 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
686 #endif
687 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
688 setttb(kernel_l1pt.pv_pa);
689 cpu_tlb_flushID();
690 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
691
692 /*
693 * Moved from cpu_startup() as data_abort_handler() references
694 * this during uvm init
695 */
696 proc0paddr = (struct user *)kernelstack.pv_va;
697 lwp0.l_addr = proc0paddr;
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
755 /* Boot strap pmap telling it where the kernel page table is */
756 #ifdef VERBOSE_INIT_ARM
757 printf("pmap ");
758 #endif
759 pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE,
760 KERNEL_VM_BASE + KERNEL_VM_SIZE);
761
762 /* Setup the IRQ system */
763 #ifdef VERBOSE_INIT_ARM
764 printf("irq ");
765 #endif
766 ixp425_intr_init();
767 #ifdef VERBOSE_INIT_ARM
768 printf("\nAll initialize done!\nNow Starting NetBSD, Hear we go!\n");
769 #endif
770
771 #ifdef BOOTHOWTO
772 boothowto = BOOTHOWTO;
773 #endif
774
775 #ifdef IPKDB
776 /* Initialise ipkdb */
777 ipkdb_init();
778 if (boothowto & RB_KDB)
779 ipkdb_connect(0);
780 #endif
781
782 #if NKSYMS || defined(DDB) || defined(LKM)
783 /* Firmware doesn't load symbols. */
784 ksyms_init(0, NULL, NULL);
785 #endif
786
787 #ifdef DDB
788 db_machine_init();
789 if (boothowto & RB_KDB)
790 Debugger();
791 #endif
792
793 /* We return the new stack pointer address */
794 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
795 }
796
797 /*
798 * consinit
799 */
800 void
801 consinit(void)
802 {
803 static int consinit_called;
804 static const bus_addr_t addrs[2] = {
805 IXP425_UART0_HWBASE, IXP425_UART1_HWBASE
806 };
807
808 if (consinit_called != 0)
809 return;
810
811 consinit_called = 1;
812
813 pmap_devmap_register(ixp425_devmap);
814
815 if (comcnattach(&ixp425_a4x_bs_tag, addrs[comcnunit],
816 comcnspeed, IXP425_UART_FREQ, COM_TYPE_PXA2x0, comcnmode))
817 panic("can't init serial console (UART%d)", comcnunit);
818 }
819