4 * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
7 * Based on code written by Jason R. Thorpe and Steve C. Woodford for
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed for the NetBSD Project by
21 * Wasabi Systems, Inc.
22 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
23 * or promote products derived from this software without specific prior
26 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
40 * Copyright (c) 1997,1998 Mark Brinicombe.
41 * Copyright (c) 1997,1998 Causality Limited.
42 * All rights reserved.
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
47 * 1. Redistributions of source code must retain the above copyright
48 * notice, this list of conditions and the following disclaimer.
49 * 2. Redistributions in binary form must reproduce the above copyright
50 * notice, this list of conditions and the following disclaimer in the
51 * documentation and/or other materials provided with the distribution.
52 * 3. All advertising materials mentioning features or use of this software
53 * must display the following acknowledgement:
54 * This product includes software developed by Mark Brinicombe
55 * for the NetBSD Project.
56 * 4. The name of the company nor the name of the author may be used to
57 * endorse or promote products derived from this software without specific
58 * prior written permission.
60 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
61 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
62 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
63 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
64 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
65 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
66 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
67 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
68 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
69 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72 * Machine dependant functions for kernel setup for Armadillo.
75 /* Armadillo-9 physical memory map
76 0000 0000 - 0fff ffff reserved
77 1000 0000 - 1000 000f I/O Control Register
78 1000 0010 - 11dd ffff reserved
79 1200 0000 - 1200 ffff PC/104 I/O space (8bit)
80 1201 0000 - 12ff ffff reserved
81 1300 0000 - 13ff ffff PC/104 Memory space (8bit)
82 1400 0000 - 1fff ffff reserved
83 2000 0000 - 21ff ffff reserved
84 2200 0000 - 2200 ffff PC/104 I/O space (16bit)
85 2201 0000 - 22ff ffff reserved
86 2300 0000 - 23ff ffff PC/104 Memory space (16bit)
87 2400 0000 - 2fff ffff reserved
88 3000 0000 - 3fff ffff reserved
89 4000 0000 - 43ff ffff Compact Flash I/O space
90 4400 0000 - 47ff ffff reserved
91 4800 0000 - 4bff ffff Compact Flash Attribute space
92 4c00 0000 - 4fff ffff Compact Flash memory space
93 5000 0000 - 5fff ffff reserved
94 6000 0000 - 607f ffff Flash Memory (8MByte)
95 6080 0000 - 6fff ffff reserved
96 7000 0000 - 7fff ffff reserved
97 8000 0000 - 8008 ffff EP9315 Internal Register (AHB)
98 8009 0000 - 8009 3fff Internal Boot ROM (16kByte)
99 8009 4000 - 8009 ffff reserved
100 800a 0000 - 800f ffff EP9315 Internal Register (AHB)
101 8010 0000 - 807f ffff reserved
102 8080 0000 - 8094 ffff EP9315 Internal Register (APB)
103 8095 0000 - 8fff ffff reserved
104 9000 0000 - bfff ffff reserved
105 c000 0000 - c1ff ffff SDRAM (32MByte)
106 c200 0000 - c3ff ffff reserved
107 c400 0000 - c5ff ffff SDRAM (32MByte)
108 c600 0000 - cfff ffff reserved
109 d000 0000 - ffff ffff reserved
112 #include <sys/cdefs.h>
113 __KERNEL_RCSID(0, "$NetBSD$");
116 #include "opt_kgdb.h"
117 #include "opt_pmap_debug.h"
119 #include <sys/param.h>
120 #include <sys/device.h>
121 #include <sys/systm.h>
122 #include <sys/kernel.h>
123 #include <sys/exec.h>
124 #include <sys/proc.h>
125 #include <sys/msgbuf.h>
126 #include <sys/reboot.h>
127 #include <sys/termios.h>
128 #include <sys/ksyms.h>
131 #include <net/if_ether.h>
133 #include <uvm/uvm_extern.h>
135 #include <dev/cons.h>
137 #include <machine/db_machdep.h>
138 #include <ddb/db_sym.h>
139 #include <ddb/db_extern.h>
141 #define DRAM_BLOCKS 4
142 #include <machine/bootconfig.h>
143 #include <machine/autoconf.h>
144 #include <machine/bus.h>
145 #include <machine/cpu.h>
146 #include <machine/frame.h>
147 #include <arm/undefined.h>
149 #include <arm/arm32/machdep.h>
151 #include <arm/ep93xx/ep93xxreg.h>
152 #include <arm/ep93xx/ep93xxvar.h>
156 #include <arm/ep93xx/epwdogvar.h>
158 #include <arm/ep93xx/epwdogreg.h>
160 #include <dev/ic/comreg.h>
161 #include <dev/ic/comvar.h>
165 #include <arm/ep93xx/epcomvar.h>
170 #include <dev/isa/isareg.h>
171 #include <dev/isa/isavar.h>
174 #include <machine/isa_machdep.h>
176 #include <evbarm/armadillo/armadillo9reg.h>
177 #include <evbarm/armadillo/armadillo9var.h>
179 struct armadillo_model_t
*armadillo_model
= 0;
180 static struct armadillo_model_t armadillo_model_table
[] = {
181 { DEVCFG_ARMADILLO9
, "Armadillo-9" },
182 { DEVCFG_ARMADILLO210
, "Armadillo-210" },
183 { 0, "Armadillo(unknown model)" } };
187 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
188 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000)
189 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
192 * The range 0xc1000000 - 0xccffffff is available for kernel VM space
193 * Core-logic registers and I/O mappings occupy 0xf0000000 - 0xffffffff
195 #define KERNEL_VM_SIZE 0x0c000000
198 * Address to call from cpu_reset() to reset the machine.
199 * This is machine architecture dependant as it varies depending
200 * on where the ROM appears when you turn the MMU off.
203 u_int cpu_reset_address
= 0x80090000;
205 /* Define various stack sizes in pages */
206 #define IRQ_STACK_SIZE 8
207 #define ABT_STACK_SIZE 8
208 #define UND_STACK_SIZE 8
210 BootConfig bootconfig
; /* Boot config storage */
211 char *boot_args
= NULL
;
212 char *boot_file
= NULL
;
214 vm_offset_t physical_start
;
215 vm_offset_t physical_freestart
;
216 vm_offset_t physical_freeend
;
217 vm_offset_t physical_freeend_low
;
218 vm_offset_t physical_end
;
221 /* Physical and virtual addresses for some global pages */
222 pv_addr_t systempage
;
226 pv_addr_t kernelstack
;
228 vm_offset_t msgbufphys
;
230 static struct arm32_dma_range armadillo9_dma_ranges
[4];
233 extern void isa_armadillo9_init(u_int
, u_int
);
236 extern u_int data_abort_handler_address
;
237 extern u_int prefetch_abort_handler_address
;
238 extern u_int undefined_handler_address
;
241 extern int pmap_debug_level
;
244 #define KERNEL_PT_SYS 0 /* L2 table for mapping vectors page */
246 #define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */
247 #define KERNEL_PT_KERNEL_NUM 4
248 /* L2 tables for mapping kernel VM */
249 #define KERNEL_PT_VMDATA (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
251 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
252 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
254 pv_addr_t kernel_pt_table
[NUM_KERNEL_PTS
];
260 * Define the default console speed for the machine.
264 #define CONSPEED B115200
265 #endif /* ! CONSPEED */
268 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
275 int comcnspeed
= CONSPEED
;
276 int comcnmode
= CONMODE
;
277 const unsigned long comaddr
[] = {
278 EP93XX_APB_UART1
, EP93XX_APB_UART2
};
283 #error Must define KGDB_DEVNAME
285 const char kgdb_devname
[] = KGDB_DEVNAME
;
288 #error Must define KGDB_DEVADDR
290 unsigned long kgdb_devaddr
= KGDB_DEVADDR
;
293 #define KGDB_DEVRATE CONSPEED
295 int kgdb_devrate
= KGDB_DEVRATE
;
298 #define KGDB_DEVMODE CONMODE
300 int kgdb_devmode
= KGDB_DEVMODE
;
304 * MAC address for the built-in Ethernet.
306 uint8_t armadillo9_ethaddr
[ETHER_ADDR_LEN
];
309 armadillo9_device_register(device_t dev
, void *aux
)
312 /* MAC address for the built-in Ethernet. */
313 if (device_is_a(dev
, "epe")) {
314 prop_data_t pd
= prop_data_create_data_nocopy(
315 armadillo9_ethaddr
, ETHER_ADDR_LEN
);
317 if (prop_dictionary_set(device_properties(dev
),
318 "mac-addr", pd
) == false) {
319 printf("WARNING: unable to set mac-addr property "
320 "for %s\n", dev
->dv_xname
);
322 prop_object_release(pd
);
327 * void cpu_reboot(int howto, char *bootstr)
331 * Deal with any syncing, unmounting, dumping and shutdown hooks,
332 * then reset the CPU.
335 cpu_reboot(int howto
, char *bootstr
)
338 * If we are still cold then hit the air brakes
339 * and crash to earth fast
343 pmf_system_shutdown(boothowto
);
345 printf("The operating system has halted.\r\n");
346 printf("Please press any key to reboot.\r\n");
348 printf("\r\nrebooting...\r\n");
352 /* Disable console buffering */
355 * If RB_NOSYNC was not specified sync the discs.
356 * Note: Unless cold is set to 1 here, syslogd will die during the
357 * unmount. It looks like syslogd is getting woken up only to find
358 * that it cannot page part of the binary in as the filesystem has
361 if (!(howto
& RB_NOSYNC
))
364 /* Say NO to interrupts */
367 /* Do a dump if requested. */
368 if ((howto
& (RB_DUMP
| RB_HALT
)) == RB_DUMP
)
371 /* Run any shutdown hooks */
374 pmf_system_shutdown(boothowto
);
376 /* Make sure IRQ's are disabled */
379 if (howto
& RB_HALT
) {
381 printf("The operating system has halted.\r\n");
382 printf("Please press any key to reboot.\r\n");
386 printf("\r\nrebooting...\r\n");
389 * Make really really sure that all interrupts are disabled,
390 * and poke the Internal Bus and Peripheral Bus reset lines.
392 (void) disable_interrupts(I32_bit
|F32_bit
);
397 u_int32_t ctrl
= EP93XX_APB_VBASE
+ EP93XX_APB_WDOG
+ EP93XX_WDOG_Ctrl
;
398 u_int32_t val
= EP93XX_WDOG_ENABLE
;
402 : "r" (ctrl
), "r" (val
)
409 /* Static device mappings. */
410 static const struct pmap_devmap armadillo9_devmap
[] = {
415 VM_PROT_READ
|VM_PROT_WRITE
,
423 VM_PROT_READ
|VM_PROT_WRITE
,
428 EP93XX_PCMCIA0_VBASE
,
429 EP93XX_PCMCIA0_HWBASE
,
431 VM_PROT_READ
|VM_PROT_WRITE
,
436 * IO8 and IO16 space *must* be mapped contiguously with
437 * IO8_VA == IO16_VA - 64 Mbytes. ISA busmap driver depends
441 ARMADILLO9_IO8_VBASE
,
442 ARMADILLO9_IO8_HWBASE
,
444 VM_PROT_READ
|VM_PROT_WRITE
,
449 ARMADILLO9_IO16_VBASE
,
450 ARMADILLO9_IO16_HWBASE
,
451 ARMADILLO9_IO16_SIZE
,
452 VM_PROT_READ
|VM_PROT_WRITE
,
468 * Initial entry point on startup. This gets called before main() is
470 * It should be responsible for setting up everything that must be
471 * in place when main is called.
473 * Taking a copy of the boot configuration structure.
474 * Initialising the physical console so characters can be printed.
475 * Setting up page tables for the kernel
476 * Initialising interrupt controllers to a sane default state
484 struct bootparam_tag
*bootparam_p
;
485 unsigned long devcfg
;
488 * Since we map the on-board devices VA==PA, and the kernel
489 * is running VA==PA, it's possible for us to initialize
495 devcfg
= *((volatile unsigned long*)(EP93XX_APB_HWBASE
497 + EP93XX_SYSCON_DeviceCfg
));
498 for (armadillo_model
= &armadillo_model_table
[0];
499 armadillo_model
->devcfg
; armadillo_model
++)
500 if (devcfg
== armadillo_model
->devcfg
)
503 /* Talk to the user */
504 printf("\nNetBSD/%s booting ...\n", armadillo_model
->name
);
506 /* set some informations from bootloader */
507 bootparam_p
= (struct bootparam_tag
*)bootparam
;
508 bootconfig
.dramblocks
= 0;
509 while (bootparam_p
->hdr
.tag
!= BOOTPARAM_TAG_NONE
) {
510 switch (bootparam_p
->hdr
.tag
) {
511 case BOOTPARAM_TAG_MEM
:
512 if (bootconfig
.dramblocks
< DRAM_BLOCKS
) {
513 #ifdef VERBOSE_INIT_ARM
514 printf("dram[%d]: address=0x%08lx, size=0x%08lx\n",
515 bootconfig
.dramblocks
,
516 bootparam_p
->u
.mem
.start
,
517 bootparam_p
->u
.mem
.size
);
519 bootconfig
.dram
[bootconfig
.dramblocks
].address
=
520 bootparam_p
->u
.mem
.start
;
521 bootconfig
.dram
[bootconfig
.dramblocks
].pages
=
522 bootparam_p
->u
.mem
.size
/ PAGE_SIZE
;
523 bootconfig
.dramblocks
++;
526 case BOOTPARAM_TAG_CMDLINE
:
527 #ifdef VERBOSE_INIT_ARM
528 printf("cmdline: %s\n", bootparam_p
->u
.cmdline
.cmdline
);
530 parse_mi_bootargs(bootparam_p
->u
.cmdline
.cmdline
);
533 bootparam_p
= bootparam_tag_next(bootparam_p
);
537 * Heads up ... Setup the CPU / MMU / TLB functions
540 panic("cpu not recognized!");
542 #ifdef VERBOSE_INIT_ARM
543 printf("initarm: Configuring system ...\n");
546 * Set up the variables that define the availablilty of
547 * physical memory. For now, we're going to set
548 * physical_freestart to 0xc0200000 (where the kernel
549 * was loaded), and allocate the memory we need downwards.
550 * If we get too close to the L1 table that we set up, we
551 * will panic. We will update physical_freestart and
552 * physical_freeend later to reflect what pmap_bootstrap()
555 * XXX pmap_bootstrap() needs an enema.
557 physical_start
= bootconfig
.dram
[0].address
;
558 physical_end
= bootconfig
.dram
[0].address
559 + (bootconfig
.dram
[0].pages
* PAGE_SIZE
);
561 physical_freestart
= 0xc0018000UL
;
562 physical_freeend
= 0xc0200000UL
;
564 physmem
= (physical_end
- physical_start
) / PAGE_SIZE
;
566 #ifdef VERBOSE_INIT_ARM
567 /* Tell the user about the memory */
568 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem
,
569 physical_start
, physical_end
- 1);
573 * Okay, the kernel starts 2MB in from the bottom of physical
574 * memory. We are going to allocate our bootstrap pages downwards
577 * We need to allocate some fixed page tables to get the kernel
578 * going. We allocate one page directory and a number of page
579 * tables and store the physical addresses in the kernel_pt_table
582 * The kernel page directory must be on a 16K boundary. The page
583 * tables must be on 4K bounaries. What we do is allocate the
584 * page directory on the first 16K boundary that we encounter, and
585 * the page tables on 4K boundaries otherwise. Since we allocate
586 * at least 3 L2 page tables, we are guaranteed to encounter at
587 * least one 16K aligned region.
590 #ifdef VERBOSE_INIT_ARM
591 printf("Allocating page tables\n");
594 free_pages
= (physical_freeend
- physical_freestart
) / PAGE_SIZE
;
596 #ifdef VERBOSE_INIT_ARM
597 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
598 physical_freestart
, free_pages
, free_pages
);
601 /* Define a macro to simplify memory allocation */
602 #define valloc_pages(var, np) \
603 alloc_pages((var).pv_pa, (np)); \
604 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
606 #define alloc_pages(var, np) \
607 physical_freeend -= ((np) * PAGE_SIZE); \
608 if (physical_freeend < physical_freestart) \
609 panic("initarm: out of memory"); \
610 (var) = physical_freeend; \
611 free_pages -= (np); \
612 memset((char *)(var), 0, ((np) * PAGE_SIZE));
615 for (loop
= 0; loop
<= NUM_KERNEL_PTS
; ++loop
) {
616 /* Are we 16KB aligned for an L1 ? */
617 if (((physical_freeend
- L1_TABLE_SIZE
) & (L1_TABLE_SIZE
- 1)) == 0
618 && kernel_l1pt
.pv_pa
== 0) {
619 valloc_pages(kernel_l1pt
, L1_TABLE_SIZE
/ PAGE_SIZE
);
621 valloc_pages(kernel_pt_table
[loop1
],
622 L2_TABLE_SIZE
/ PAGE_SIZE
);
627 /* This should never be able to happen but better confirm that. */
628 if (!kernel_l1pt
.pv_pa
|| (kernel_l1pt
.pv_pa
& (L1_TABLE_SIZE
-1)) != 0)
629 panic("initarm: Failed to align the kernel page directory");
632 * Allocate a page for the system vectors page
634 alloc_pages(systempage
.pv_pa
, 1);
636 /* Allocate stacks for all modes */
637 valloc_pages(irqstack
, IRQ_STACK_SIZE
);
638 valloc_pages(abtstack
, ABT_STACK_SIZE
);
639 valloc_pages(undstack
, UND_STACK_SIZE
);
640 valloc_pages(kernelstack
, UPAGES
);
642 #ifdef VERBOSE_INIT_ARM
643 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack
.pv_pa
,
645 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack
.pv_pa
,
647 printf("UND stack: p0x%08lx v0x%08lx\n", undstack
.pv_pa
,
649 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack
.pv_pa
,
653 alloc_pages(msgbufphys
, round_page(MSGBUFSIZE
) / PAGE_SIZE
);
656 * Ok we have allocated physical pages for the primary kernel
657 * page tables. Save physical_freeend for when we give whats left
658 * of memory below 2Mbyte to UVM.
661 physical_freeend_low
= physical_freeend
;
663 #ifdef VERBOSE_INIT_ARM
664 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt
.pv_pa
);
668 * Now we start construction of the L1 page table
669 * We start by mapping the L2 page tables into the L1.
670 * This means that we can replace L1 mappings later on if necessary
672 l1pagetable
= kernel_l1pt
.pv_pa
;
674 /* Map the L2 pages tables in the L1 page table */
675 pmap_link_l2pt(l1pagetable
, ARM_VECTORS_HIGH
& ~(0x00400000 - 1),
676 &kernel_pt_table
[KERNEL_PT_SYS
]);
677 for (loop
= 0; loop
< KERNEL_PT_KERNEL_NUM
; loop
++)
678 pmap_link_l2pt(l1pagetable
, KERNEL_BASE
+ loop
* 0x00400000,
679 &kernel_pt_table
[KERNEL_PT_KERNEL
+ loop
]);
680 for (loop
= 0; loop
< KERNEL_PT_VMDATA_NUM
; loop
++)
681 pmap_link_l2pt(l1pagetable
, KERNEL_VM_BASE
+ loop
* 0x00400000,
682 &kernel_pt_table
[KERNEL_PT_VMDATA
+ loop
]);
684 /* update the top of the kernel VM */
686 KERNEL_VM_BASE
+ (KERNEL_PT_VMDATA_NUM
* 0x00400000);
688 #ifdef VERBOSE_INIT_ARM
689 printf("Mapping kernel\n");
692 /* Now we fill in the L2 pagetable for the kernel static code/data */
694 extern char etext
[], _end
[];
695 size_t textsize
= (uintptr_t) etext
- KERNEL_TEXT_BASE
;
696 size_t totalsize
= (uintptr_t) _end
- KERNEL_TEXT_BASE
;
699 textsize
= (textsize
+ PGOFSET
) & ~PGOFSET
;
700 totalsize
= (totalsize
+ PGOFSET
) & ~PGOFSET
;
702 logical
= 0x00200000; /* offset of kernel in RAM */
703 logical
+= pmap_map_chunk(l1pagetable
, KERNEL_BASE
+ logical
,
704 physical_start
+ logical
, textsize
,
705 VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
706 logical
+= pmap_map_chunk(l1pagetable
, KERNEL_BASE
+ logical
,
707 physical_start
+ logical
, totalsize
- textsize
,
708 VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
711 #ifdef VERBOSE_INIT_ARM
712 printf("Constructing L2 page tables\n");
715 /* Map the stack pages */
716 pmap_map_chunk(l1pagetable
, irqstack
.pv_va
, irqstack
.pv_pa
,
717 IRQ_STACK_SIZE
* PAGE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
718 pmap_map_chunk(l1pagetable
, abtstack
.pv_va
, abtstack
.pv_pa
,
719 ABT_STACK_SIZE
* PAGE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
720 pmap_map_chunk(l1pagetable
, undstack
.pv_va
, undstack
.pv_pa
,
721 UND_STACK_SIZE
* PAGE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
722 pmap_map_chunk(l1pagetable
, kernelstack
.pv_va
, kernelstack
.pv_pa
,
723 UPAGES
* PAGE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
725 pmap_map_chunk(l1pagetable
, kernel_l1pt
.pv_va
, kernel_l1pt
.pv_pa
,
726 L1_TABLE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_PAGETABLE
);
728 for (loop
= 0; loop
< NUM_KERNEL_PTS
; ++loop
) {
729 pmap_map_chunk(l1pagetable
, kernel_pt_table
[loop
].pv_va
,
730 kernel_pt_table
[loop
].pv_pa
, L2_TABLE_SIZE
,
731 VM_PROT_READ
|VM_PROT_WRITE
, PTE_PAGETABLE
);
734 /* Map the vector page. */
735 pmap_map_entry(l1pagetable
, ARM_VECTORS_HIGH
, systempage
.pv_pa
,
736 VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
738 /* Map the statically mapped devices. */
739 pmap_devmap_bootstrap(l1pagetable
, armadillo9_devmap
);
742 * Update the physical_freestart/physical_freeend/free_pages
748 physical_freestart
= physical_start
+
749 (((((uintptr_t) _end
) + PGOFSET
) & ~PGOFSET
) -
751 physical_freeend
= physical_end
;
753 (physical_freeend
- physical_freestart
) / PAGE_SIZE
;
757 * Now we have the real page tables in place so we can switch to them.
758 * Once this is done we will be running with the REAL kernel page
763 #ifdef VERBOSE_INIT_ARM
764 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
765 physical_freestart
, free_pages
, free_pages
);
766 printf("switching to new L1 page table @%#lx...", kernel_l1pt
.pv_pa
);
768 cpu_domains((DOMAIN_CLIENT
<< (PMAP_DOMAIN_KERNEL
*2)) | DOMAIN_CLIENT
);
769 cpu_setttb(kernel_l1pt
.pv_pa
);
771 cpu_domains(DOMAIN_CLIENT
<< (PMAP_DOMAIN_KERNEL
*2));
774 * Moved from cpu_startup() as data_abort_handler() references
775 * this during uvm init
777 uvm_lwp_setuarea(&lwp0
, kernelstack
.pv_va
);
779 #ifdef VERBOSE_INIT_ARM
783 #ifdef VERBOSE_INIT_ARM
784 printf("bootstrap done.\n");
787 arm32_vector_init(ARM_VECTORS_HIGH
, ARM_VEC_ALL
);
790 * Pages were allocated during the secondary bootstrap for the
791 * stacks for different CPU modes.
792 * We must now set the r13 registers in the different CPU modes to
793 * point to these stacks.
794 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
795 * of the stack memory.
797 #ifdef VERBOSE_INIT_ARM
798 printf("init subsystems: stacks ");
801 set_stackptr(PSR_IRQ32_MODE
,
802 irqstack
.pv_va
+ IRQ_STACK_SIZE
* PAGE_SIZE
);
803 set_stackptr(PSR_ABT32_MODE
,
804 abtstack
.pv_va
+ ABT_STACK_SIZE
* PAGE_SIZE
);
805 set_stackptr(PSR_UND32_MODE
,
806 undstack
.pv_va
+ UND_STACK_SIZE
* PAGE_SIZE
);
809 * Well we should set a data abort handler.
810 * Once things get going this will change as we will need a proper
812 * Until then we will use a handler that just panics but tells us
814 * Initialisation of the vectors will just panic on a data abort.
815 * This just fills in a slightly better one.
817 #ifdef VERBOSE_INIT_ARM
820 data_abort_handler_address
= (u_int
)data_abort_handler
;
821 prefetch_abort_handler_address
= (u_int
)prefetch_abort_handler
;
822 undefined_handler_address
= (u_int
)undefinedinstruction_bounce
;
824 /* Initialise the undefined instruction handlers */
825 #ifdef VERBOSE_INIT_ARM
826 printf("undefined ");
830 /* Load memory into UVM. */
831 #ifdef VERBOSE_INIT_ARM
834 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
835 uvm_page_physload(atop(physical_freestart
), atop(physical_freeend
),
836 atop(physical_freestart
), atop(physical_freeend
),
837 VM_FREELIST_DEFAULT
);
838 uvm_page_physload(atop(0xc0000000), atop(physical_freeend_low
),
839 atop(0xc0000000), atop(physical_freeend_low
),
840 VM_FREELIST_DEFAULT
);
841 physmem
= bootconfig
.dram
[0].pages
;
842 for (loop
= 1; loop
< bootconfig
.dramblocks
; ++loop
) {
843 size_t start
= bootconfig
.dram
[loop
].address
;
844 size_t size
= bootconfig
.dram
[loop
].pages
* PAGE_SIZE
;
845 uvm_page_physload(atop(start
), atop(start
+ size
),
846 atop(start
), atop(start
+ size
),
847 VM_FREELIST_DEFAULT
);
848 physmem
+= bootconfig
.dram
[loop
].pages
;
851 /* Boot strap pmap telling it where the kernel page table is */
852 #ifdef VERBOSE_INIT_ARM
855 pmap_bootstrap(KERNEL_VM_BASE
, KERNEL_VM_BASE
+ KERNEL_VM_SIZE
);
857 /* Setup the IRQ system */
858 #ifdef VERBOSE_INIT_ARM
865 #ifdef VERBOSE_INIT_ARM
868 isa_armadillo9_init(ARMADILLO9_IO16_VBASE
+ ARMADILLO9_ISAIO
,
869 ARMADILLO9_IO16_VBASE
+ ARMADILLO9_ISAMEM
);
872 #ifdef VERBOSE_INIT_ARM
877 boothowto
= BOOTHOWTO
;
882 if (boothowto
& RB_KDB
)
886 /* We have our own device_register() */
887 evbarm_device_register
= armadillo9_device_register
;
889 /* We return the new stack pointer address */
890 return(kernelstack
.pv_va
+ USPACE_SVC_STACK_TOP
);
896 static int consinit_called
;
898 bus_space_handle_t ioh
;
901 if (consinit_called
!= 0)
907 * Console devices are already mapped in VA. Our devmap reflects
908 * this, so register it now so drivers can map the console
911 pmap_devmap_register(armadillo9_devmap
);
914 bus_space_map(&ep93xx_bs_tag
, EP93XX_APB_HWBASE
+ comaddr
[CONUNIT
],
915 EP93XX_APB_UART_SIZE
, 0, &ioh
);
916 if (epcomcnattach(&ep93xx_bs_tag
, EP93XX_APB_HWBASE
+ comaddr
[CONUNIT
],
917 ioh
, comcnspeed
, comcnmode
))
919 panic("can't init serial console");
922 panic("serial console not configured");
926 if (strcmp(kgdb_devname
, "epcom") == 0) {
927 com_kgdb_attach(&ep93xx_bs_tag
, kgdb_devaddr
, kgdb_devrate
,
930 #endif /* NEPCOM > 0 */
936 ep93xx_bus_dma_init(struct arm32_bus_dma_tag
*dma_tag_template
)
939 struct arm32_bus_dma_tag
*dmat
;
941 for (i
= 0; i
< bootconfig
.dramblocks
; i
++) {
942 armadillo9_dma_ranges
[i
].dr_sysbase
= bootconfig
.dram
[i
].address
;
943 armadillo9_dma_ranges
[i
].dr_busbase
= bootconfig
.dram
[i
].address
;
944 armadillo9_dma_ranges
[i
].dr_len
= bootconfig
.dram
[i
].pages
*
948 dmat
= dma_tag_template
;
950 dmat
->_ranges
= armadillo9_dma_ranges
;
951 dmat
->_nranges
= bootconfig
.dramblocks
;