No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / evbarm / iq80321 / iq80321_machdep.c
blob92488fc68d634cd5355e8ffbb618d30ca804d59e
1 /* $NetBSD$ */
3 /*
4 * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
5 * All rights reserved.
7 * Written by Jason R. Thorpe and Steve C. Woodford for Wasabi Systems, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed for the NetBSD Project by
20 * Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
23 * written permission.
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
39 * Copyright (c) 1997,1998 Mark Brinicombe.
40 * Copyright (c) 1997,1998 Causality Limited.
41 * All rights reserved.
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. All advertising materials mentioning features or use of this software
52 * must display the following acknowledgement:
53 * This product includes software developed by Mark Brinicombe
54 * for the NetBSD Project.
55 * 4. The name of the company nor the name of the author may be used to
56 * endorse or promote products derived from this software without specific
57 * prior written permission.
59 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
60 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
61 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
62 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
63 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
64 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
65 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * SUCH DAMAGE.
71 * Machine dependant functions for kernel setup for Intel IQ80321 evaluation
72 * boards using RedBoot firmware.
75 #include <sys/cdefs.h>
76 __KERNEL_RCSID(0, "$NetBSD$");
78 #include "opt_ddb.h"
79 #include "opt_kgdb.h"
80 #include "opt_pmap_debug.h"
82 #include <sys/param.h>
83 #include <sys/device.h>
84 #include <sys/systm.h>
85 #include <sys/kernel.h>
86 #include <sys/exec.h>
87 #include <sys/proc.h>
88 #include <sys/msgbuf.h>
89 #include <sys/reboot.h>
90 #include <sys/termios.h>
91 #include <sys/ksyms.h>
93 #include <uvm/uvm_extern.h>
95 #include <dev/cons.h>
97 #include <machine/db_machdep.h>
98 #include <ddb/db_sym.h>
99 #include <ddb/db_extern.h>
101 #include <machine/bootconfig.h>
102 #include <machine/bus.h>
103 #include <machine/cpu.h>
104 #include <machine/frame.h>
105 #include <arm/undefined.h>
107 #include <arm/arm32/machdep.h>
109 #include <arm/xscale/i80321reg.h>
110 #include <arm/xscale/i80321var.h>
112 #include <dev/pci/ppbreg.h>
114 #include <evbarm/iq80321/iq80321reg.h>
115 #include <evbarm/iq80321/iq80321var.h>
116 #include <evbarm/iq80321/obiovar.h>
118 #include "ksyms.h"
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)
125 * The range 0xc1000000 - 0xccffffff is available for kernel VM space
126 * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
128 #define KERNEL_VM_SIZE 0x0C000000
131 * Address to call from cpu_reset() to reset the machine.
132 * This is machine architecture dependant as it varies depending
133 * on where the ROM appears when you turn the MMU off.
135 * XXX Not actally used on IQ80321 -- clean up the generic
136 * ARM code.
139 u_int cpu_reset_address = 0x00000000;
141 /* Define various stack sizes in pages */
142 #define IRQ_STACK_SIZE 1
143 #define ABT_STACK_SIZE 1
144 #define UND_STACK_SIZE 1
146 BootConfig bootconfig; /* Boot config storage */
147 char *boot_args = NULL;
148 char *boot_file = NULL;
150 vm_offset_t physical_start;
151 vm_offset_t physical_freestart;
152 vm_offset_t physical_freeend;
153 vm_offset_t physical_end;
154 u_int free_pages;
156 /*int debug_flags;*/
157 #ifndef PMAP_STATIC_L1S
158 int max_processes = 64; /* Default number */
159 #endif /* !PMAP_STATIC_L1S */
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;
168 vm_offset_t msgbufphys;
170 extern u_int data_abort_handler_address;
171 extern u_int prefetch_abort_handler_address;
172 extern u_int undefined_handler_address;
174 #ifdef PMAP_DEBUG
175 extern int pmap_debug_level;
176 #endif
178 #define KERNEL_PT_SYS 0 /* L2 table for mapping zero page */
180 #define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */
181 #define KERNEL_PT_KERNEL_NUM 4
183 /* L2 table for mapping i80321 */
184 #define KERNEL_PT_IOPXS (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
186 /* L2 tables for mapping kernel VM */
187 #define KERNEL_PT_VMDATA (KERNEL_PT_IOPXS + 1)
188 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
189 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
191 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
193 /* Prototypes */
195 void consinit(void);
197 #include "com.h"
198 #if NCOM > 0
199 #include <dev/ic/comreg.h>
200 #include <dev/ic/comvar.h>
201 #endif
204 * Define the default console speed for the board. This is generally
205 * what the firmware provided with the board defaults to.
207 #ifndef CONSPEED
208 #define CONSPEED B115200
209 #endif /* ! CONSPEED */
211 #ifndef CONUNIT
212 #define CONUNIT 0
213 #endif
215 #ifndef CONMODE
216 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
217 #endif
219 int comcnspeed = CONSPEED;
220 int comcnmode = CONMODE;
221 int comcnunit = CONUNIT;
223 #if KGDB
224 #ifndef KGDB_DEVNAME
225 #error Must define KGDB_DEVNAME
226 #endif
227 const char kgdb_devname[] = KGDB_DEVNAME;
229 #ifndef KGDB_DEVADDR
230 #error Must define KGDB_DEVADDR
231 #endif
232 unsigned long kgdb_devaddr = KGDB_DEVADDR;
234 #ifndef KGDB_DEVRATE
235 #define KGDB_DEVRATE CONSPEED
236 #endif
237 int kgdb_devrate = KGDB_DEVRATE;
239 #ifndef KGDB_DEVMODE
240 #define KGDB_DEVMODE CONMODE
241 #endif
242 int kgdb_devmode = KGDB_DEVMODE;
243 #endif /* KGDB */
245 #if defined(I80321_REBOOT)
246 extern void I80321_REBOOT(int);
247 #endif
250 * void cpu_reboot(int howto, char *bootstr)
252 * Reboots the system
254 * Deal with any syncing, unmounting, dumping and shutdown hooks,
255 * then reset the CPU.
257 void
258 cpu_reboot(int howto, char *bootstr)
262 * If we are still cold then hit the air brakes
263 * and crash to earth fast
265 if (cold) {
266 doshutdownhooks();
267 pmf_system_shutdown(boothowto);
268 printf("The operating system has halted.\n");
269 printf("Please press any key to reboot.\n\n");
270 cngetc();
271 printf("rebooting...\n");
272 goto reset;
275 /* Disable console buffering */
278 * If RB_NOSYNC was not specified sync the discs.
279 * Note: Unless cold is set to 1 here, syslogd will die during the
280 * unmount. It looks like syslogd is getting woken up only to find
281 * that it cannot page part of the binary in as the filesystem has
282 * been unmounted.
284 if (!(howto & RB_NOSYNC))
285 bootsync();
287 /* Say NO to interrupts */
288 splhigh();
290 /* Do a dump if requested. */
291 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
292 dumpsys();
294 /* Run any shutdown hooks */
295 doshutdownhooks();
297 pmf_system_shutdown(boothowto);
299 /* Make sure IRQ's are disabled */
300 IRQdisable;
302 if (howto & RB_HALT) {
303 #if defined(I80321_REBOOT)
304 I80321_REBOOT(howto);
305 #endif
306 iq80321_7seg('.', '.');
307 printf("The operating system has halted.\n");
308 printf("Please press any key to reboot.\n\n");
309 cngetc();
312 printf("rebooting...\n\r");
313 reset:
314 #if defined(I80321_REBOOT)
315 I80321_REBOOT(howto);
316 #endif
319 * Make really really sure that all interrupts are disabled,
320 * and poke the Internal Bus and Peripheral Bus reset lines.
322 (void) disable_interrupts(I32_bit|F32_bit);
323 *(volatile uint32_t *)(IQ80321_80321_VBASE + VERDE_ATU_BASE +
324 ATU_PCSR) = PCSR_RIB | PCSR_RPB;
326 /* ...and if that didn't work, just croak. */
327 printf("RESET FAILED!\n");
328 for (;;);
331 /* Static device mappings. */
332 static const struct pmap_devmap iq80321_devmap[] = {
334 * Map the on-board devices VA == PA so that we can access them
335 * with the MMU on or off.
338 IQ80321_OBIO_BASE,
339 IQ80321_OBIO_BASE,
340 IQ80321_OBIO_SIZE,
341 VM_PROT_READ|VM_PROT_WRITE,
342 PTE_NOCACHE,
346 IQ80321_IOW_VBASE,
347 VERDE_OUT_XLATE_IO_WIN0_BASE,
348 VERDE_OUT_XLATE_IO_WIN_SIZE,
349 VM_PROT_READ|VM_PROT_WRITE,
350 PTE_NOCACHE,
354 IQ80321_80321_VBASE,
355 VERDE_PMMR_BASE,
356 VERDE_PMMR_SIZE,
357 VM_PROT_READ|VM_PROT_WRITE,
358 PTE_NOCACHE,
370 static void
371 iq80321_hardclock_hook(void)
373 static int snakefreq;
375 if ((snakefreq++ & 15) == 0)
376 iq80321_7seg_snake();
380 * u_int initarm(...)
382 * Initial entry point on startup. This gets called before main() is
383 * entered.
384 * It should be responsible for setting up everything that must be
385 * in place when main is called.
386 * This includes
387 * Taking a copy of the boot configuration structure.
388 * Initialising the physical console so characters can be printed.
389 * Setting up page tables for the kernel
390 * Relocating the kernel to the bottom of physical memory
392 u_int
393 initarm(void *arg)
395 extern vaddr_t xscale_cache_clean_addr;
396 #ifdef DIAGNOSTIC
397 extern vsize_t xscale_minidata_clean_size;
398 #endif
399 int loop;
400 int loop1;
401 u_int l1pagetable;
402 paddr_t memstart;
403 psize_t memsize;
406 * Clear out the 7-segment display. Whee, the first visual
407 * indication that we're running kernel code.
409 iq80321_7seg(' ', ' ');
411 /* Calibrate the delay loop. */
412 i80321_calibrate_delay();
413 i80321_hardclock_hook = iq80321_hardclock_hook;
416 * Since we map the on-board devices VA==PA, and the kernel
417 * is running VA==PA, it's possible for us to initialize
418 * the console now.
420 consinit();
422 #ifdef VERBOSE_INIT_ARM
423 /* Talk to the user */
424 printf("\nNetBSD/evbarm (IQ80321) booting ...\n");
425 #endif
428 * Heads up ... Setup the CPU / MMU / TLB functions
430 if (set_cpufuncs())
431 panic("CPU not recognized!");
434 * We are currently running with the MMU enabled and the
435 * entire address space mapped VA==PA, except for the
436 * first 64M of RAM is also double-mapped at 0xc0000000.
437 * There is an L1 page table at 0xa0004000.
441 * Fetch the SDRAM start/size from the i80321 SDRAM configuration
442 * registers.
444 i80321_sdram_bounds(&obio_bs_tag, VERDE_PMMR_BASE + VERDE_MCU_BASE,
445 &memstart, &memsize);
447 #ifdef VERBOSE_INIT_ARM
448 printf("initarm: Configuring system ...\n");
449 #endif
451 /* Fake bootconfig structure for the benefit of pmap.c */
452 /* XXX must make the memory description h/w independent */
453 bootconfig.dramblocks = 1;
454 bootconfig.dram[0].address = memstart;
455 bootconfig.dram[0].pages = memsize / PAGE_SIZE;
458 * Set up the variables that define the availablilty of
459 * physical memory. For now, we're going to set
460 * physical_freestart to 0xa0200000 (where the kernel
461 * was loaded), and allocate the memory we need downwards.
462 * If we get too close to the L1 table that we set up, we
463 * will panic. We will update physical_freestart and
464 * physical_freeend later to reflect what pmap_bootstrap()
465 * wants to see.
467 * XXX pmap_bootstrap() needs an enema.
469 physical_start = bootconfig.dram[0].address;
470 physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
472 physical_freestart = 0xa0009000UL;
473 physical_freeend = 0xa0200000UL;
475 physmem = (physical_end - physical_start) / PAGE_SIZE;
477 #ifdef VERBOSE_INIT_ARM
478 /* Tell the user about the memory */
479 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
480 physical_start, physical_end - 1);
481 #endif
484 * Okay, the kernel starts 2MB in from the bottom of physical
485 * memory. We are going to allocate our bootstrap pages downwards
486 * from there.
488 * We need to allocate some fixed page tables to get the kernel
489 * going. We allocate one page directory and a number of page
490 * tables and store the physical addresses in the kernel_pt_table
491 * array.
493 * The kernel page directory must be on a 16K boundary. The page
494 * tables must be on 4K boundaries. What we do is allocate the
495 * page directory on the first 16K boundary that we encounter, and
496 * the page tables on 4K boundaries otherwise. Since we allocate
497 * at least 3 L2 page tables, we are guaranteed to encounter at
498 * least one 16K aligned region.
501 #ifdef VERBOSE_INIT_ARM
502 printf("Allocating page tables\n");
503 #endif
505 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
507 #ifdef VERBOSE_INIT_ARM
508 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
509 physical_freestart, free_pages, free_pages);
510 #endif
512 /* Define a macro to simplify memory allocation */
513 #define valloc_pages(var, np) \
514 alloc_pages((var).pv_pa, (np)); \
515 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
517 #define alloc_pages(var, np) \
518 physical_freeend -= ((np) * PAGE_SIZE); \
519 if (physical_freeend < physical_freestart) \
520 panic("initarm: out of memory"); \
521 (var) = physical_freeend; \
522 free_pages -= (np); \
523 memset((char *)(var), 0, ((np) * PAGE_SIZE));
525 loop1 = 0;
526 kernel_l1pt.pv_pa = 0;
527 kernel_l1pt.pv_va = 0;
528 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
529 /* Are we 16KB aligned for an L1 ? */
530 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
531 && kernel_l1pt.pv_pa == 0) {
532 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
533 } else {
534 valloc_pages(kernel_pt_table[loop1],
535 L2_TABLE_SIZE / PAGE_SIZE);
536 ++loop1;
540 /* This should never be able to happen but better confirm that. */
541 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
542 panic("initarm: Failed to align the kernel page directory");
545 * Allocate a page for the system page mapped to V0x00000000
546 * This page will just contain the system vectors and can be
547 * shared by all processes.
549 alloc_pages(systempage.pv_pa, 1);
551 /* Allocate stacks for all modes */
552 valloc_pages(irqstack, IRQ_STACK_SIZE);
553 valloc_pages(abtstack, ABT_STACK_SIZE);
554 valloc_pages(undstack, UND_STACK_SIZE);
555 valloc_pages(kernelstack, UPAGES);
557 /* Allocate enough pages for cleaning the Mini-Data cache. */
558 KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
559 valloc_pages(minidataclean, 1);
561 #ifdef VERBOSE_INIT_ARM
562 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
563 irqstack.pv_va);
564 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
565 abtstack.pv_va);
566 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
567 undstack.pv_va);
568 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
569 kernelstack.pv_va);
570 #endif
573 * XXX Defer this to later so that we can reclaim the memory
574 * XXX used by the RedBoot page tables.
576 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
579 * Ok we have allocated physical pages for the primary kernel
580 * page tables
583 #ifdef VERBOSE_INIT_ARM
584 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
585 #endif
588 * Now we start construction of the L1 page table
589 * We start by mapping the L2 page tables into the L1.
590 * This means that we can replace L1 mappings later on if necessary
592 l1pagetable = kernel_l1pt.pv_pa;
594 /* Map the L2 pages tables in the L1 page table */
595 pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
596 &kernel_pt_table[KERNEL_PT_SYS]);
597 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
598 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
599 &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
600 pmap_link_l2pt(l1pagetable, IQ80321_IOPXS_VBASE,
601 &kernel_pt_table[KERNEL_PT_IOPXS]);
602 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
603 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
604 &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
606 /* update the top of the kernel VM */
607 pmap_curmaxkvaddr =
608 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
610 #ifdef VERBOSE_INIT_ARM
611 printf("Mapping kernel\n");
612 #endif
614 /* Now we fill in the L2 pagetable for the kernel static code/data */
616 extern char etext[], _end[];
617 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
618 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
619 u_int logical;
621 textsize = (textsize + PGOFSET) & ~PGOFSET;
622 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
624 logical = 0x00200000; /* offset of kernel in RAM */
626 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
627 physical_start + logical, textsize,
628 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
629 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
630 physical_start + logical, totalsize - textsize,
631 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
634 #ifdef VERBOSE_INIT_ARM
635 printf("Constructing L2 page tables\n");
636 #endif
638 /* Map the stack pages */
639 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
640 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
641 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
642 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
643 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
644 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
645 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
646 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
648 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
649 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
651 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
652 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
653 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
654 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
657 /* Map the Mini-Data cache clean area. */
658 xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
659 minidataclean.pv_pa);
661 /* Map the vector page. */
662 pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
663 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
665 /* Map the statically mapped devices. */
666 pmap_devmap_bootstrap(l1pagetable, iq80321_devmap);
669 * Give the XScale global cache clean code an appropriately
670 * sized chunk of unmapped VA space starting at 0xff000000
671 * (our device mappings end before this address).
673 xscale_cache_clean_addr = 0xff000000U;
676 * Now we have the real page tables in place so we can switch to them.
677 * Once this is done we will be running with the REAL kernel page
678 * tables.
682 * Update the physical_freestart/physical_freeend/free_pages
683 * variables.
686 extern char _end[];
688 physical_freestart = physical_start +
689 (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
690 KERNEL_BASE);
691 physical_freeend = physical_end;
692 free_pages =
693 (physical_freeend - physical_freestart) / PAGE_SIZE;
696 /* Switch tables */
697 #ifdef VERBOSE_INIT_ARM
698 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
699 physical_freestart, free_pages, free_pages);
700 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
701 #endif
702 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
703 cpu_setttb(kernel_l1pt.pv_pa);
704 cpu_tlb_flushID();
705 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
708 * Moved from cpu_startup() as data_abort_handler() references
709 * this during uvm init
711 uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
713 #ifdef VERBOSE_INIT_ARM
714 printf("done!\n");
715 #endif
717 #ifdef VERBOSE_INIT_ARM
718 printf("bootstrap done.\n");
719 #endif
721 arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
724 * Pages were allocated during the secondary bootstrap for the
725 * stacks for different CPU modes.
726 * We must now set the r13 registers in the different CPU modes to
727 * point to these stacks.
728 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
729 * of the stack memory.
731 #ifdef VERBOSE_INIT_ARM
732 printf("init subsystems: stacks ");
733 #endif
735 set_stackptr(PSR_IRQ32_MODE,
736 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
737 set_stackptr(PSR_ABT32_MODE,
738 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
739 set_stackptr(PSR_UND32_MODE,
740 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
743 * Well we should set a data abort handler.
744 * Once things get going this will change as we will need a proper
745 * handler.
746 * Until then we will use a handler that just panics but tells us
747 * why.
748 * Initialisation of the vectors will just panic on a data abort.
749 * This just fills in a slightly better one.
751 #ifdef VERBOSE_INIT_ARM
752 printf("vectors ");
753 #endif
754 data_abort_handler_address = (u_int)data_abort_handler;
755 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
756 undefined_handler_address = (u_int)undefinedinstruction_bounce;
758 /* Initialise the undefined instruction handlers */
759 #ifdef VERBOSE_INIT_ARM
760 printf("undefined ");
761 #endif
762 undefined_init();
764 /* Load memory into UVM. */
765 #ifdef VERBOSE_INIT_ARM
766 printf("page ");
767 #endif
768 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
769 uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
770 atop(physical_freestart), atop(physical_freeend),
771 VM_FREELIST_DEFAULT);
773 /* Boot strap pmap telling it where the kernel page table is */
774 #ifdef VERBOSE_INIT_ARM
775 printf("pmap ");
776 #endif
777 pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
779 /* Setup the IRQ system */
780 #ifdef VERBOSE_INIT_ARM
781 printf("irq ");
782 #endif
783 i80321_intr_init();
785 #ifdef VERBOSE_INIT_ARM
786 printf("done.\n");
787 #endif
789 #ifdef BOOTHOWTO
790 boothowto = BOOTHOWTO;
791 #endif
793 #ifdef DDB
794 db_machine_init();
795 if (boothowto & RB_KDB)
796 Debugger();
797 #endif
799 /* We return the new stack pointer address */
800 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
803 void
804 consinit(void)
806 static const bus_addr_t comcnaddrs[] = {
807 IQ80321_UART1, /* com0 */
809 static int consinit_called;
811 if (consinit_called != 0)
812 return;
814 consinit_called = 1;
817 * Console devices are mapped VA==PA. Our devmap reflects
818 * this, so register it now so drivers can map the console
819 * device.
821 pmap_devmap_register(iq80321_devmap);
823 #if NCOM > 0
824 if (comcnattach(&obio_bs_tag, comcnaddrs[comcnunit], comcnspeed,
825 COM_FREQ, COM_TYPE_NORMAL, comcnmode))
826 panic("can't init serial console @%lx", comcnaddrs[comcnunit]);
827 #else
828 panic("serial console @%lx not configured", comcnaddrs[comcnunit]);
829 #endif
830 #if KGDB
831 #if NCOM > 0
832 if (strcmp(kgdb_devname, "com") == 0) {
833 com_kgdb_attach(&obio_bs_tag, kgdb_devaddr, kgdb_devrate,
834 COM_FREQ, COM_TYPE_NORMAL, kgdb_devmode);
836 #endif /* NCOM > 0 */
837 #endif /* KGDB */