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