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