ixdp425_machdep.c revision 1.12 1 /* $NetBSD: ixdp425_machdep.c,v 1.12 2003/12/08 14:44:03 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.12 2003/12/08 14:44:03 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 <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 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
510 /* Are we 16KB aligned for an L1 ? */
511 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
512 && kernel_l1pt.pv_pa == 0) {
513 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
514 } else {
515 valloc_pages(kernel_pt_table[loop1],
516 L2_TABLE_SIZE / PAGE_SIZE);
517 ++loop1;
518 }
519 }
520
521 /* This should never be able to happen but better confirm that. */
522 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
523 panic("initarm: Failed to align the kernel page directory");
524
525 /*
526 * Allocate a page for the system page.
527 * This page will just contain the system vectors and can be
528 * shared by all processes.
529 */
530 alloc_pages(systempage.pv_pa, 1);
531
532 /* Allocate stacks for all modes */
533 valloc_pages(irqstack, IRQ_STACK_SIZE);
534 valloc_pages(abtstack, ABT_STACK_SIZE);
535 valloc_pages(undstack, UND_STACK_SIZE);
536 valloc_pages(kernelstack, UPAGES);
537
538 /* Allocate enough pages for cleaning the Mini-Data cache. */
539 KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
540 valloc_pages(minidataclean, 1);
541
542 #ifdef VERBOSE_INIT_ARM
543 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
544 irqstack.pv_va);
545 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
546 abtstack.pv_va);
547 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
548 undstack.pv_va);
549 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
550 kernelstack.pv_va);
551 #endif
552
553 /*
554 * XXX Defer this to later so that we can reclaim the memory
555 * XXX used by the RedBoot page tables.
556 */
557 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
558
559 /*
560 * Ok we have allocated physical pages for the primary kernel
561 * page tables
562 */
563
564 #ifdef VERBOSE_INIT_ARM
565 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
566 #endif
567
568 /*
569 * Now we start construction of the L1 page table
570 * We start by mapping the L2 page tables into the L1.
571 * This means that we can replace L1 mappings later on if necessary
572 */
573 l1pagetable = kernel_l1pt.pv_pa;
574
575 /* Map the L2 pages tables in the L1 page table */
576 pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
577 &kernel_pt_table[KERNEL_PT_SYS]);
578 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
579 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
580 &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
581 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
582 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
583 &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
584
585 /* update the top of the kernel VM */
586 pmap_curmaxkvaddr =
587 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
588
589 pmap_link_l2pt(l1pagetable, IXP425_IO_VBASE,
590 &kernel_pt_table[KERNEL_PT_IO]);
591
592 #ifdef VERBOSE_INIT_ARM
593 printf("Mapping kernel\n");
594 #endif
595
596 /* Now we fill in the L2 pagetable for the kernel static code/data */
597 {
598 extern char etext[], _end[];
599 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
600 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
601 u_int logical;
602
603 textsize = (textsize + PGOFSET) & ~PGOFSET;
604 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
605
606 logical = 0x00200000; /* offset of kernel in RAM */
607
608 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
609 physical_start + logical, textsize,
610 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
611 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
612 physical_start + logical, totalsize - textsize,
613 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
614 }
615
616 #ifdef VERBOSE_INIT_ARM
617 printf("Constructing L2 page tables\n");
618 #endif
619
620 /* Map the stack pages */
621 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
622 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
623 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
624 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
625 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
626 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
627 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
628 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
629
630 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
631 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
632
633 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
634 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
635 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
636 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
637 }
638
639 /* Map the Mini-Data cache clean area. */
640 xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
641 minidataclean.pv_pa);
642
643 /* Map the vector page. */
644 pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
645 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
646
647 /*
648 * Map the IXP425 registers
649 */
650 pmap_devmap_bootstrap(l1pagetable, ixp425_devmap);
651
652 /*
653 * Give the XScale global cache clean code an appropriately
654 * sized chunk of unmapped VA space starting at 0xff000000
655 * (our device mappings end before this address).
656 */
657 xscale_cache_clean_addr = 0xff000000U;
658
659 /*
660 * Now we have the real page tables in place so we can switch to them.
661 * Once this is done we will be running with the REAL kernel page
662 * tables.
663 */
664
665 /*
666 * Update the physical_freestart/physical_freeend/free_pages
667 * variables.
668 */
669 {
670 extern char _end[];
671
672 physical_freestart = physical_start +
673 (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
674 KERNEL_BASE);
675 physical_freeend = physical_end;
676 free_pages =
677 (physical_freeend - physical_freestart) / PAGE_SIZE;
678 }
679
680 /* Switch tables */
681 #ifdef VERBOSE_INIT_ARM
682 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
683 physical_freestart, free_pages, free_pages);
684 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
685 #endif
686 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
687 setttb(kernel_l1pt.pv_pa);
688 cpu_tlb_flushID();
689 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
690
691 /*
692 * Moved from cpu_startup() as data_abort_handler() references
693 * this during uvm init
694 */
695 proc0paddr = (struct user *)kernelstack.pv_va;
696 lwp0.l_addr = proc0paddr;
697
698 #ifdef VERBOSE_INIT_ARM
699 printf("bootstrap done.\n");
700 #endif
701
702 arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
703
704 /*
705 * Pages were allocated during the secondary bootstrap for the
706 * stacks for different CPU modes.
707 * We must now set the r13 registers in the different CPU modes to
708 * point to these stacks.
709 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
710 * of the stack memory.
711 */
712 #ifdef VERBOSE_INIT_ARM
713 printf("init subsystems: stacks ");
714 #endif
715
716 set_stackptr(PSR_IRQ32_MODE,
717 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
718 set_stackptr(PSR_ABT32_MODE,
719 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
720 set_stackptr(PSR_UND32_MODE,
721 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
722
723 /*
724 * Well we should set a data abort handler.
725 * Once things get going this will change as we will need a proper
726 * handler.
727 * Until then we will use a handler that just panics but tells us
728 * why.
729 * Initialisation of the vectors will just panic on a data abort.
730 * This just fills in a slighly better one.
731 */
732 #ifdef VERBOSE_INIT_ARM
733 printf("vectors ");
734 #endif
735 data_abort_handler_address = (u_int)data_abort_handler;
736 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
737 undefined_handler_address = (u_int)undefinedinstruction_bounce;
738
739 /* Initialise the undefined instruction handlers */
740 #ifdef VERBOSE_INIT_ARM
741 printf("undefined ");
742 #endif
743 undefined_init();
744
745 /* Load memory into UVM. */
746 #ifdef VERBOSE_INIT_ARM
747 printf("page ");
748 #endif
749 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
750 uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
751 atop(physical_freestart), atop(physical_freeend),
752 VM_FREELIST_DEFAULT);
753
754 /* Boot strap pmap telling it where the kernel page table is */
755 #ifdef VERBOSE_INIT_ARM
756 printf("pmap ");
757 #endif
758 pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE,
759 KERNEL_VM_BASE + KERNEL_VM_SIZE);
760
761 /* Setup the IRQ system */
762 #ifdef VERBOSE_INIT_ARM
763 printf("irq ");
764 #endif
765 ixp425_intr_init();
766 #ifdef VERBOSE_INIT_ARM
767 printf("\nAll initialize done!\nNow Starting NetBSD, Hear we go!\n");
768 #endif
769
770 #ifdef BOOTHOWTO
771 boothowto = BOOTHOWTO;
772 #endif
773
774 #ifdef IPKDB
775 /* Initialise ipkdb */
776 ipkdb_init();
777 if (boothowto & RB_KDB)
778 ipkdb_connect(0);
779 #endif
780
781 #if NKSYMS || defined(DDB) || defined(LKM)
782 /* Firmware doesn't load symbols. */
783 ksyms_init(0, NULL, NULL);
784 #endif
785
786 #ifdef DDB
787 db_machine_init();
788 if (boothowto & RB_KDB)
789 Debugger();
790 #endif
791
792 /* We return the new stack pointer address */
793 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
794 }
795
796 /*
797 * consinit
798 */
799 void
800 consinit(void)
801 {
802 static int consinit_called;
803 static const bus_addr_t addrs[2] = {
804 IXP425_UART0_HWBASE, IXP425_UART1_HWBASE
805 };
806
807 if (consinit_called != 0)
808 return;
809
810 consinit_called = 1;
811
812 pmap_devmap_register(ixp425_devmap);
813
814 if (comcnattach(&ixp425_a4x_bs_tag, addrs[comcnunit],
815 comcnspeed, IXP425_UART_FREQ, COM_TYPE_PXA2x0, comcnmode))
816 panic("can't init serial console (UART%d)", comcnunit);
817 }
818