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