No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / evbarm / iq80310 / iq80310_machdep.c
blobc4bd40be287e3bb4dc65000d5912722457e0043c
1 /* $NetBSD$ */
3 /*
4 * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
5 * All rights reserved.
7 * Written by Jason R. Thorpe 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 IQ80310 evaluation
72 * boards using RedBoot firmware.
75 #include <sys/cdefs.h>
76 __KERNEL_RCSID(0, "$NetBSD$");
78 #include "opt_ddb.h"
79 #include "opt_pmap_debug.h"
81 #include <sys/param.h>
82 #include <sys/device.h>
83 #include <sys/systm.h>
84 #include <sys/kernel.h>
85 #include <sys/exec.h>
86 #include <sys/proc.h>
87 #include <sys/msgbuf.h>
88 #include <sys/reboot.h>
89 #include <sys/termios.h>
90 #include <sys/ksyms.h>
92 #include <uvm/uvm_extern.h>
94 #include <dev/cons.h>
96 #include <machine/db_machdep.h>
97 #include <ddb/db_sym.h>
98 #include <ddb/db_extern.h>
100 #include <machine/bootconfig.h>
101 #include <machine/bus.h>
102 #include <machine/cpu.h>
103 #include <machine/frame.h>
104 #include <arm/undefined.h>
106 #include <arm/arm32/machdep.h>
108 #include <arm/xscale/i80312reg.h>
109 #include <arm/xscale/i80312var.h>
111 #include <dev/pci/ppbreg.h>
113 #include <evbarm/iq80310/iq80310reg.h>
114 #include <evbarm/iq80310/iq80310var.h>
115 #include <evbarm/iq80310/obiovar.h>
117 #include "ksyms.h"
119 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
120 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000)
121 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
124 * The range 0xc1000000 - 0xccffffff is available for kernel VM space
125 * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
127 #define KERNEL_VM_SIZE 0x0C000000
130 * Address to call from cpu_reset() to reset the machine.
131 * This is machine architecture dependant as it varies depending
132 * on where the ROM appears when you turn the MMU off.
135 u_int cpu_reset_address = 0;
137 /* Define various stack sizes in pages */
138 #define IRQ_STACK_SIZE 1
139 #define ABT_STACK_SIZE 1
140 #define UND_STACK_SIZE 1
142 BootConfig bootconfig; /* Boot config storage */
143 char *boot_args = NULL;
144 char *boot_file = NULL;
146 vm_offset_t physical_start;
147 vm_offset_t physical_freestart;
148 vm_offset_t physical_freeend;
149 vm_offset_t physical_end;
150 u_int free_pages;
152 /*int debug_flags;*/
153 #ifndef PMAP_STATIC_L1S
154 int max_processes = 64; /* Default number */
155 #endif /* !PMAP_STATIC_L1S */
157 /* Physical and virtual addresses for some global pages */
158 pv_addr_t irqstack;
159 pv_addr_t undstack;
160 pv_addr_t abtstack;
161 pv_addr_t kernelstack;
162 pv_addr_t minidataclean;
164 vm_offset_t msgbufphys;
166 extern u_int data_abort_handler_address;
167 extern u_int prefetch_abort_handler_address;
168 extern u_int undefined_handler_address;
170 #ifdef PMAP_DEBUG
171 extern int pmap_debug_level;
172 #endif
174 #define KERNEL_PT_SYS 0 /* L2 table for mapping zero page */
176 #define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */
177 #define KERNEL_PT_KERNEL_NUM 4
179 /* L2 table for mapping i80312 */
180 #define KERNEL_PT_IOPXS (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
182 /* L2 tables for mapping kernel VM */
183 #define KERNEL_PT_VMDATA (KERNEL_PT_IOPXS + 1)
184 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
185 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
187 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
189 /* Prototypes */
191 void consinit(void);
193 #include "com.h"
194 #if NCOM > 0
195 #include <dev/ic/comreg.h>
196 #include <dev/ic/comvar.h>
197 #endif
200 * Define the default console speed for the board. This is generally
201 * what the firmware provided with the board defaults to.
203 #ifndef CONSPEED
204 #define CONSPEED B115200
205 #endif /* ! CONSPEED */
207 #ifndef CONUNIT
208 #define CONUNIT 0
209 #endif
211 #ifndef CONMODE
212 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
213 #endif
215 int comcnspeed = CONSPEED;
216 int comcnmode = CONMODE;
217 int comcnunit = CONUNIT;
220 * void cpu_reboot(int howto, char *bootstr)
222 * Reboots the system
224 * Deal with any syncing, unmounting, dumping and shutdown hooks,
225 * then reset the CPU.
227 void
228 cpu_reboot(int howto, char *bootstr)
232 * If we are still cold then hit the air brakes
233 * and crash to earth fast
235 if (cold) {
236 doshutdownhooks();
237 pmf_system_shutdown(boothowto);
238 printf("The operating system has halted.\n");
239 printf("Please press any key to reboot.\n\n");
240 cngetc();
241 printf("rebooting...\n");
242 cpu_reset();
243 /*NOTREACHED*/
246 /* Disable console buffering */
249 * If RB_NOSYNC was not specified sync the discs.
250 * Note: Unless cold is set to 1 here, syslogd will die during the
251 * unmount. It looks like syslogd is getting woken up only to find
252 * that it cannot page part of the binary in as the filesystem has
253 * been unmounted.
255 if (!(howto & RB_NOSYNC))
256 bootsync();
258 /* Say NO to interrupts */
259 splhigh();
261 /* Do a dump if requested. */
262 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
263 dumpsys();
265 /* Run any shutdown hooks */
266 doshutdownhooks();
268 pmf_system_shutdown(boothowto);
270 /* Make sure IRQ's are disabled */
271 IRQdisable;
273 if (howto & RB_HALT) {
274 iq80310_7seg('.', '.');
275 printf("The operating system has halted.\n");
276 printf("Please press any key to reboot.\n\n");
277 cngetc();
280 printf("rebooting...\n");
281 cpu_reset();
282 /*NOTREACHED*/
285 /* Static device mappings. */
286 static const struct pmap_devmap iq80310_devmap[] = {
288 * Map the on-board devices VA == PA so that we can access them
289 * with the MMU on or off.
292 IQ80310_OBIO_BASE,
293 IQ80310_OBIO_BASE,
294 IQ80310_OBIO_SIZE,
295 VM_PROT_READ|VM_PROT_WRITE,
296 PTE_NOCACHE,
299 IQ80310_PIOW_VBASE,
300 I80312_PCI_XLATE_PIOW_BASE,
301 I80312_PCI_XLATE_IOSIZE,
302 VM_PROT_READ|VM_PROT_WRITE,
303 PTE_NOCACHE,
306 IQ80310_SIOW_VBASE,
307 I80312_PCI_XLATE_SIOW_BASE,
308 I80312_PCI_XLATE_IOSIZE,
309 VM_PROT_READ|VM_PROT_WRITE,
310 PTE_NOCACHE,
313 IQ80310_80312_VBASE,
314 I80312_PMMR_BASE,
315 I80312_PMMR_SIZE,
316 VM_PROT_READ|VM_PROT_WRITE,
317 PTE_NOCACHE,
330 * u_int initarm(...)
332 * Initial entry point on startup. This gets called before main() is
333 * entered.
334 * It should be responsible for setting up everything that must be
335 * in place when main is called.
336 * This includes
337 * Taking a copy of the boot configuration structure.
338 * Initialising the physical console so characters can be printed.
339 * Setting up page tables for the kernel
340 * Relocating the kernel to the bottom of physical memory
342 u_int
343 initarm(void *arg)
345 extern vaddr_t xscale_cache_clean_addr;
346 #ifdef DIAGNOSTIC
347 extern vsize_t xscale_minidata_clean_size;
348 #endif
349 int loop;
350 int loop1;
351 u_int l1pagetable;
352 paddr_t memstart;
353 psize_t memsize;
356 * Clear out the 7-segment display. Whee, the first visual
357 * indication that we're running kernel code.
359 iq80310_7seg(' ', ' ');
362 * Heads up ... Setup the CPU / MMU / TLB functions
364 if (set_cpufuncs())
365 panic("CPU not recognized!");
367 /* Calibrate the delay loop. */
368 iq80310_calibrate_delay();
371 * Since we map the on-board devices VA==PA, and the kernel
372 * is running VA==PA, it's possible for us to initialize
373 * the console now.
375 consinit();
377 #ifdef VERBOSE_INIT_ARM
378 /* Talk to the user */
379 printf("\nNetBSD/evbarm (IQ80310) booting ...\n");
380 #endif
383 * Reset the secondary PCI bus. RedBoot doesn't stop devices
384 * on the PCI bus before handing us control, so we have to
385 * do this.
387 * XXX This is arguably a bug in RedBoot, and doing this reset
388 * XXX could be problematic in the future if we encounter an
389 * XXX application where the PPB in the i80312 is used as a
390 * XXX PPB.
393 uint32_t reg;
395 #ifdef VERBOSE_INIT_ARM
396 printf("Resetting secondary PCI bus...\n");
397 #endif
398 reg = bus_space_read_4(&obio_bs_tag,
399 I80312_PMMR_BASE + I80312_PPB_BASE, PPB_REG_BRIDGECONTROL);
400 bus_space_write_4(&obio_bs_tag,
401 I80312_PMMR_BASE + I80312_PPB_BASE, PPB_REG_BRIDGECONTROL,
402 reg | PPB_BC_SECONDARY_RESET);
403 delay(10 * 1000); /* 10ms enough? */
404 bus_space_write_4(&obio_bs_tag,
405 I80312_PMMR_BASE + I80312_PPB_BASE, PPB_REG_BRIDGECONTROL,
406 reg);
410 * We are currently running with the MMU enabled and the
411 * entire address space mapped VA==PA, except for the
412 * first 64M of RAM is also double-mapped at 0xc0000000.
413 * There is an L1 page table at 0xa0004000.
417 * Fetch the SDRAM start/size from the i80312 SDRAM configuration
418 * registers.
420 i80312_sdram_bounds(&obio_bs_tag, I80312_PMMR_BASE + I80312_MEM_BASE,
421 &memstart, &memsize);
423 #ifdef VERBOSE_INIT_ARM
424 printf("initarm: Configuring system ...\n");
425 #endif
427 /* Fake bootconfig structure for the benefit of pmap.c */
428 /* XXX must make the memory description h/w independent */
429 bootconfig.dramblocks = 1;
430 bootconfig.dram[0].address = memstart;
431 bootconfig.dram[0].pages = memsize / PAGE_SIZE;
434 * Set up the variables that define the availablilty of
435 * physical memory. For now, we're going to set
436 * physical_freestart to 0xa0200000 (where the kernel
437 * was loaded), and allocate the memory we need downwards.
438 * If we get too close to the L1 table that we set up, we
439 * will panic. We will update physical_freestart and
440 * physical_freeend later to reflect what pmap_bootstrap()
441 * wants to see.
443 * XXX pmap_bootstrap() needs an enema.
445 physical_start = bootconfig.dram[0].address;
446 physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
448 physical_freestart = 0xa0009000UL;
449 physical_freeend = 0xa0200000UL;
451 physmem = (physical_end - physical_start) / PAGE_SIZE;
453 #ifdef VERBOSE_INIT_ARM
454 /* Tell the user about the memory */
455 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
456 physical_start, physical_end - 1);
457 #endif
460 * Okay, the kernel starts 2MB in from the bottom of physical
461 * memory. We are going to allocate our bootstrap pages downwards
462 * from there.
464 * We need to allocate some fixed page tables to get the kernel
465 * going. We allocate one page directory and a number of page
466 * tables and store the physical addresses in the kernel_pt_table
467 * array.
469 * The kernel page directory must be on a 16K boundary. The page
470 * tables must be on 4K boundaries. What we do is allocate the
471 * page directory on the first 16K boundary that we encounter, and
472 * the page tables on 4K boundaries otherwise. Since we allocate
473 * at least 3 L2 page tables, we are guaranteed to encounter at
474 * least one 16K aligned region.
477 #ifdef VERBOSE_INIT_ARM
478 printf("Allocating page tables\n");
479 #endif
481 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
483 #ifdef VERBOSE_INIT_ARM
484 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
485 physical_freestart, free_pages, free_pages);
486 #endif
488 /* Define a macro to simplify memory allocation */
489 #define valloc_pages(var, np) \
490 alloc_pages((var).pv_pa, (np)); \
491 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
493 #define alloc_pages(var, np) \
494 physical_freeend -= ((np) * PAGE_SIZE); \
495 if (physical_freeend < physical_freestart) \
496 panic("initarm: out of memory"); \
497 (var) = physical_freeend; \
498 free_pages -= (np); \
499 memset((char *)(var), 0, ((np) * PAGE_SIZE));
501 loop1 = 0;
502 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
503 /* Are we 16KB aligned for an L1 ? */
504 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
505 && kernel_l1pt.pv_pa == 0) {
506 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
507 } else {
508 valloc_pages(kernel_pt_table[loop1],
509 L2_TABLE_SIZE / PAGE_SIZE);
510 ++loop1;
514 /* This should never be able to happen but better confirm that. */
515 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
516 panic("initarm: Failed to align the kernel page directory");
519 * Allocate a page for the system page mapped to V0x00000000
520 * This page will just contain the system vectors and can be
521 * shared by all processes.
523 alloc_pages(systempage.pv_pa, 1);
525 /* Allocate stacks for all modes */
526 valloc_pages(irqstack, IRQ_STACK_SIZE);
527 valloc_pages(abtstack, ABT_STACK_SIZE);
528 valloc_pages(undstack, UND_STACK_SIZE);
529 valloc_pages(kernelstack, UPAGES);
531 /* Allocate enough pages for cleaning the Mini-Data cache. */
532 KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
533 valloc_pages(minidataclean, 1);
535 #ifdef VERBOSE_INIT_ARM
536 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
537 irqstack.pv_va);
538 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
539 abtstack.pv_va);
540 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
541 undstack.pv_va);
542 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
543 kernelstack.pv_va);
544 #endif
547 * XXX Defer this to later so that we can reclaim the memory
548 * XXX used by the RedBoot page tables.
550 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
553 * Ok we have allocated physical pages for the primary kernel
554 * page tables
557 #ifdef VERBOSE_INIT_ARM
558 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
559 #endif
562 * Now we start construction of the L1 page table
563 * We start by mapping the L2 page tables into the L1.
564 * This means that we can replace L1 mappings later on if necessary
566 l1pagetable = kernel_l1pt.pv_pa;
568 /* Map the L2 pages tables in the L1 page table */
569 pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
570 &kernel_pt_table[KERNEL_PT_SYS]);
571 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
572 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
573 &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
574 pmap_link_l2pt(l1pagetable, IQ80310_IOPXS_VBASE,
575 &kernel_pt_table[KERNEL_PT_IOPXS]);
576 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
577 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
578 &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
580 /* update the top of the kernel VM */
581 pmap_curmaxkvaddr =
582 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
584 #ifdef VERBOSE_INIT_ARM
585 printf("Mapping kernel\n");
586 #endif
588 /* Now we fill in the L2 pagetable for the kernel static code/data */
590 extern char etext[], _end[];
591 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
592 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
593 u_int logical;
595 textsize = (textsize + PGOFSET) & ~PGOFSET;
596 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
598 logical = 0x00200000; /* offset of kernel in RAM */
600 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
601 physical_start + logical, textsize,
602 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
603 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
604 physical_start + logical, totalsize - textsize,
605 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
608 #ifdef VERBOSE_INIT_ARM
609 printf("Constructing L2 page tables\n");
610 #endif
612 /* Map the stack pages */
613 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
614 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
615 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
616 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
617 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
618 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
619 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
620 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
622 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
623 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
625 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
626 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
627 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
628 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
631 /* Map the Mini-Data cache clean area. */
632 xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
633 minidataclean.pv_pa);
635 /* Map the vector page. */
636 pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
637 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
639 /* Map the statically mapped devices. */
640 pmap_devmap_bootstrap(l1pagetable, iq80310_devmap);
643 * Give the XScale global cache clean code an appropriately
644 * sized chunk of unmapped VA space starting at 0xff000000
645 * (our device mappings end before this address).
647 xscale_cache_clean_addr = 0xff000000U;
650 * Now we have the real page tables in place so we can switch to them.
651 * Once this is done we will be running with the REAL kernel page
652 * tables.
656 * Update the physical_freestart/physical_freeend/free_pages
657 * variables.
660 extern char _end[];
662 physical_freestart = physical_start +
663 (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
664 KERNEL_BASE);
665 physical_freeend = physical_end;
666 free_pages =
667 (physical_freeend - physical_freestart) / PAGE_SIZE;
670 /* Switch tables */
671 #ifdef VERBOSE_INIT_ARM
672 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
673 physical_freestart, free_pages, free_pages);
674 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
675 #endif
676 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
677 cpu_setttb(kernel_l1pt.pv_pa);
678 cpu_tlb_flushID();
679 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
682 * Moved from cpu_startup() as data_abort_handler() references
683 * this during uvm init
685 uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
687 #ifdef VERBOSE_INIT_ARM
688 printf("done!\n");
689 #endif
691 #ifdef VERBOSE_INIT_ARM
692 printf("bootstrap done.\n");
693 #endif
695 arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
698 * Pages were allocated during the secondary bootstrap for the
699 * stacks for different CPU modes.
700 * We must now set the r13 registers in the different CPU modes to
701 * point to these stacks.
702 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
703 * of the stack memory.
705 #ifdef VERBOSE_INIT_ARM
706 printf("init subsystems: stacks ");
707 #endif
709 set_stackptr(PSR_IRQ32_MODE,
710 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
711 set_stackptr(PSR_ABT32_MODE,
712 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
713 set_stackptr(PSR_UND32_MODE,
714 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
717 * Well we should set a data abort handler.
718 * Once things get going this will change as we will need a proper
719 * handler.
720 * Until then we will use a handler that just panics but tells us
721 * why.
722 * Initialisation of the vectors will just panic on a data abort.
723 * This just fills in a slightly better one.
725 #ifdef VERBOSE_INIT_ARM
726 printf("vectors ");
727 #endif
728 data_abort_handler_address = (u_int)data_abort_handler;
729 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
730 undefined_handler_address = (u_int)undefinedinstruction_bounce;
732 /* Initialise the undefined instruction handlers */
733 #ifdef VERBOSE_INIT_ARM
734 printf("undefined ");
735 #endif
736 undefined_init();
738 /* Load memory into UVM. */
739 #ifdef VERBOSE_INIT_ARM
740 printf("page ");
741 #endif
742 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
743 uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
744 atop(physical_freestart), atop(physical_freeend),
745 VM_FREELIST_DEFAULT);
747 /* Boot strap pmap telling it where the kernel page table is */
748 #ifdef VERBOSE_INIT_ARM
749 printf("pmap ");
750 #endif
751 pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
753 /* Setup the IRQ system */
754 #ifdef VERBOSE_INIT_ARM
755 printf("irq ");
756 #endif
757 iq80310_intr_init();
759 #ifdef VERBOSE_INIT_ARM
760 printf("done.\n");
761 #endif
763 #ifdef DDB
764 db_machine_init();
765 if (boothowto & RB_KDB)
766 Debugger();
767 #endif
769 /* We return the new stack pointer address */
770 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
773 void
774 consinit(void)
776 static const bus_addr_t comcnaddrs[] = {
777 IQ80310_UART2, /* com0 (J9) */
778 IQ80310_UART1, /* com1 (J10) */
780 static int consinit_called;
782 if (consinit_called != 0)
783 return;
785 consinit_called = 1;
788 * Console devices are mapped VA==PA. Our devmap reflects
789 * this, so register it now so drivers can map the console
790 * device.
792 pmap_devmap_register(iq80310_devmap);
794 #if NCOM > 0
795 if (comcnattach(&obio_bs_tag, comcnaddrs[comcnunit], comcnspeed,
796 COM_FREQ, COM_TYPE_NORMAL, comcnmode))
797 panic("can't init serial console @%lx", comcnaddrs[comcnunit]);
798 #else
799 panic("serial console @%lx not configured", comcnaddrs[comcnunit]);
800 #endif