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