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