1 /* $NetBSD: hpc_machdep.c,v 1.8 2001/03/23 08:58:14 toshii Exp $ */ 2 3 /* 4 * Copyright (c) 1994-1998 Mark Brinicombe. 5 * Copyright (c) 1994 Brini. 6 * All rights reserved. 7 * 8 * This code is derived from software written for Brini by Mark Brinicombe 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 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 by Brini. 21 * 4. The name of the company nor the name of the author may be used to 22 * endorse or promote products derived from this software without specific 23 * prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED 26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 28 * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 29 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 30 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * SUCH DAMAGE. 36 * 37 * RiscBSD kernel project 38 * 39 * machdep.c 40 * 41 * Machine dependant functions for kernel setup 42 * 43 * This file needs a lot of work. 44 * 45 * Created : 17/09/94 46 */ 47 /* 48 * hpc_machdep.c 49 */ 50 51 #include "opt_cputypes.h" 52 #include "opt_ddb.h" 53 #include "opt_pmap_debug.h" 54 55 #include <sys/param.h> 56 #include <sys/systm.h> 57 #include <sys/kernel.h> 58 #include <sys/reboot.h> 59 #include <sys/proc.h> 60 #include <sys/msgbuf.h> 61 #include <sys/exec.h> 62 63 #include <dev/cons.h> 64 65 #ifdef DDB 66 #include <machine/db_machdep.h> 67 #include <ddb/db_sym.h> 68 #include <ddb/db_extern.h> 69 #ifndef DB_ELFSIZE 70 #error Must define DB_ELFSIZE! 71 #endif 72 #define ELFSIZE DB_ELFSIZE 73 #include <sys/exec_elf.h> 74 #endif 75 76 #include <uvm/uvm.h> 77 78 #include <machine/signal.h> 79 #include <machine/frame.h> 80 #include <machine/bootconfig.h> 81 #include <machine/cpu.h> 82 #include <machine/io.h> 83 #include <machine/irqhandler.h> 84 #include <machine/katelib.h> 85 #include <machine/pte.h> 86 #include <machine/bootinfo.h> 87 #include <machine/undefined.h> 88 #include <machine/rtc.h> 89 #include <hpcarm/sa11x0/sa11x0_reg.h> 90 91 #include <dev/hpc/bicons.h> 92 93 #include "opt_ipkdb.h" 94 95 /* XXX for consinit related hacks */ 96 #include <sys/conf.h> 97 98 /* 99 * Address to call from cpu_reset() to reset the machine. 100 * This is machine architecture dependant as it varies depending 101 * on where the ROM appears when you turn the MMU off. 102 */ 103 104 u_int cpu_reset_address = 0; 105 106 /* Define various stack sizes in pages */ 107 #define IRQ_STACK_SIZE 1 108 #define ABT_STACK_SIZE 1 109 #ifdef IPKDB 110 #define UND_STACK_SIZE 2 111 #else 112 #define UND_STACK_SIZE 1 113 #endif 114 115 BootConfig bootconfig; /* Boot config storage */ 116 struct bootinfo *bootinfo, bootinfo_storage; 117 char booted_kernel[80]; 118 119 vm_offset_t physical_start; 120 vm_offset_t physical_freestart; 121 vm_offset_t physical_freeend; 122 vm_offset_t physical_end; 123 u_int free_pages; 124 int physmem = 0; 125 126 #define biconscnpollc nullcnpollc 127 cons_decl(bicons); 128 static struct consdev bicons = cons_init(bicons); 129 130 #ifndef PMAP_STATIC_L1S 131 int max_processes = 64; /* Default number */ 132 #endif /* !PMAP_STATIC_L1S */ 133 134 135 /* Physical and virtual addresses for some global pages */ 136 pv_addr_t systempage; 137 pv_addr_t irqstack; 138 pv_addr_t undstack; 139 pv_addr_t abtstack; 140 pv_addr_t kernelstack; 141 142 char *boot_args = NULL; 143 char *boot_file = NULL; 144 145 vm_offset_t msgbufphys; 146 147 extern u_int data_abort_handler_address; 148 extern u_int prefetch_abort_handler_address; 149 extern u_int undefined_handler_address; 150 extern int end; 151 152 #ifdef PMAP_DEBUG 153 extern int pmap_debug_level; 154 #endif /* PMAP_DEBUG */ 155 156 #define KERNEL_PT_VMEM 0 /* Page table for mapping video memory */ 157 #define KERNEL_PT_SYS 1 /* Page table for mapping proc0 zero page */ 158 #define KERNEL_PT_KERNEL 2 /* Page table for mapping kernel */ 159 #define KERNEL_PT_IO 3 /* Page table for mapping IO */ 160 #define KERNEL_PT_VMDATA 4 /* Page tables for mapping kernel VM */ 161 #define KERNEL_PT_VMDATA_NUM (KERNEL_VM_SIZE >> (PDSHIFT + 2)) 162 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM + 1) 163 164 pt_entry_t kernel_pt_table[NUM_KERNEL_PTS]; 165 166 struct user *proc0paddr; 167 168 #ifdef CPU_SA110 169 #define CPU_SA110_CACHE_CLEAN_SIZE (0x4000 * 2) 170 extern unsigned int sa110_cache_clean_addr; 171 extern unsigned int sa110_cache_clean_size; 172 static vaddr_t sa110_cc_base; 173 #endif /* CPU_SA110 */ 174 175 /* virtual address for framebuffer */ 176 /* XXX temporary hack until we have bus_space_map */ 177 #define FRAMEBUF_BASE 0xd0100000 178 179 /* Prototypes */ 180 181 void physcon_display_base __P((u_int addr)); 182 extern void consinit __P((void)); 183 184 void map_section __P((vm_offset_t pt, vm_offset_t va, vm_offset_t pa, 185 int cacheable)); 186 void map_pagetable __P((vm_offset_t pt, vm_offset_t va, vm_offset_t pa)); 187 void map_entry __P((vm_offset_t pt, vm_offset_t va, vm_offset_t pa)); 188 void map_entry_nc __P((vm_offset_t pt, vm_offset_t va, vm_offset_t pa)); 189 void map_entry_ro __P((vm_offset_t pt, vm_offset_t va, vm_offset_t pa)); 190 vm_size_t map_chunk __P((vm_offset_t pd, vm_offset_t pt, vm_offset_t va, 191 vm_offset_t pa, vm_size_t size, u_int acc, 192 u_int flg)); 193 194 void data_abort_handler __P((trapframe_t *frame)); 195 void prefetch_abort_handler __P((trapframe_t *frame)); 196 void undefinedinstruction_bounce __P((trapframe_t *frame)); 197 void zero_page_readonly __P((void)); 198 void zero_page_readwrite __P((void)); 199 200 u_int cpu_get_control __P((void)); 201 202 void rpc_sa110_cc_setup(void); 203 204 #ifdef DEBUG_BEFOREMMU 205 static void fakecninit(); 206 #endif 207 208 #ifdef BOOT_DUMP 209 void dumppages(char *, int); 210 #endif 211 212 extern int db_trapper(); 213 214 extern void dump_spl_masks __P((void)); 215 extern pt_entry_t *pmap_pte __P((pmap_t pmap, vm_offset_t va)); 216 extern void db_machine_init __P((void)); 217 extern void parse_mi_bootargs __P((char *args)); 218 219 extern void dumpsys __P((void)); 220 221 /* 222 * void cpu_reboot(int howto, char *bootstr) 223 * 224 * Reboots the system 225 * 226 * Deal with any syncing, unmounting, dumping and shutdown hooks, 227 * then reset the CPU. 228 */ 229 230 void 231 cpu_reboot(howto, bootstr) 232 int howto; 233 char *bootstr; 234 { 235 /* 236 * If we are still cold then hit the air brakes 237 * and crash to earth fast 238 */ 239 if (cold) { 240 doshutdownhooks(); 241 printf("Halted while still in the ICE age.\n"); 242 printf("The operating system has halted.\n"); 243 printf("Please press any key to reboot.\n\n"); 244 cngetc(); 245 printf("rebooting...\n"); 246 cpu_reset(); 247 /*NOTREACHED*/ 248 } 249 250 /* Disable console buffering */ 251 cnpollc(1); 252 253 /* 254 * If RB_NOSYNC was not specified sync the discs. 255 * Note: Unless cold is set to 1 here, syslogd will die during the unmount. 256 * It looks like syslogd is getting woken up only to find that it cannot 257 * page part of the binary in as the filesystem has been unmounted. 258 */ 259 if (!(howto & RB_NOSYNC)) 260 bootsync(); 261 262 /* Say NO to interrupts */ 263 splhigh(); 264 265 /* Do a dump if requested. */ 266 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) 267 dumpsys(); 268 269 270 /* Run any shutdown hooks */ 271 doshutdownhooks(); 272 273 /* Make sure IRQ's are disabled */ 274 IRQdisable; 275 276 if (howto & RB_HALT) { 277 printf("The operating system has halted.\n"); 278 printf("Please press any key to reboot.\n\n"); 279 cngetc(); 280 } 281 282 printf("rebooting...\n"); 283 cpu_reset(); 284 /*NOTREACHED*/ 285 } 286 287 /* 288 * 289 * Initial entry point on startup. This gets called before main() is 290 * entered. 291 * It should be responcible for setting up everything that must be 292 * in place when main is called. 293 * This includes 294 * Taking a copy of the boot configuration structure. 295 * Initialising the physical console so characters can be printed. 296 * Setting up page tables for the kernel 297 */ 298 299 u_int 300 initarm(argc, argv, bi) 301 int argc; 302 char **argv; 303 struct bootinfo *bi; 304 { 305 int loop; 306 u_int kerneldatasize, symbolsize; 307 u_int l1pagetable; 308 u_int l2pagetable; 309 vm_offset_t freemempos; 310 extern char page0[], page0_end[]; 311 pv_addr_t kernel_l1pt; 312 pv_addr_t kernel_ptpt; 313 #ifdef DDB 314 Elf_Shdr *sh; 315 #endif 316 317 /* 318 * Heads up ... Setup the CPU / MMU / TLB functions 319 */ 320 set_cpufuncs(); 321 322 /* Put the processer in SVC mode */ 323 __asm("mov r0, sp; mov r1, ip; mrs r2, cpsr_all;"); 324 /* PSR_MODE, PSR_SVC32_MODE" */ 325 __asm("bic r2, r2, #31; orr r2, r2, #19;"); 326 __asm("msr cpsr_all, r2; mov sp, r0; mov ip, r1;"); 327 328 #ifdef DEBUG_BEFOREMMU 329 /* 330 * At this point, we cannot call real consinit(). 331 * Just call a faked up version of consinit(), which does the thing 332 * with MMU disabled. 333 */ 334 fakecninit(); 335 #endif 336 337 /* 338 * XXX for now, overwrite bootconfig to hardcoded values. 339 * XXX kill bootconfig and directly call uvm_physload 340 */ 341 bootconfig.dram[0].address = 0xc0000000; 342 bootconfig.dram[0].pages = 8192; 343 bootconfig.dramblocks = 1; 344 kerneldatasize = (u_int32_t)&end - (u_int32_t)KERNEL_TEXT_BASE; 345 346 symbolsize = 0; 347 #ifdef DDB 348 if (! memcmp(&end, "\177ELF", 4)) { 349 sh = (Elf_Shdr *)((char *)&end + ((Elf_Ehdr *)&end)->e_shoff); 350 loop = ((Elf_Ehdr *)&end)->e_shnum; 351 for(; loop; loop--, sh++) 352 if (sh->sh_offset > 0 && 353 (sh->sh_offset + sh->sh_size) > symbolsize) 354 symbolsize = sh->sh_offset + sh->sh_size; 355 } 356 #endif 357 358 printf("kernsize=0x%x\n", kerneldatasize); 359 kerneldatasize += symbolsize; 360 kerneldatasize = ((kerneldatasize - 1) & ~(NBPG * 4 - 1)) + NBPG * 8; 361 362 /* parse kernel args */ 363 strncpy(booted_kernel, *argv, sizeof(booted_kernel)); 364 for(argc--, argv++; argc; argc--, argv++) 365 switch(**argv) { 366 case 'a': 367 boothowto |= RB_ASKNAME; 368 break; 369 case 's': 370 boothowto |= RB_SINGLE; 371 break; 372 default: 373 break; 374 } 375 376 /* copy bootinfo into known kernel space */ 377 bootinfo_storage = *bi; 378 bootinfo = &bootinfo_storage; 379 380 bootinfo->fb_addr = (void *)FRAMEBUF_BASE; 381 382 #ifdef BOOTINFO_FB_WIDTH 383 bootinfo->fb_line_bytes = BOOTINFO_FB_LINE_BYTES; 384 bootinfo->fb_width = BOOTINFO_FB_WIDTH; 385 bootinfo->fb_height = BOOTINFO_FB_HEIGHT; 386 bootinfo->fb_type = BOOTINFO_FB_TYPE; 387 #endif 388 389 /* 390 * hpcboot has loaded me with MMU disabled. 391 * So create kernel page tables and enable MMU 392 */ 393 394 /* 395 * Set up the variables that define the availablilty of physcial 396 * memory 397 */ 398 physical_start = bootconfig.dram[0].address; 399 physical_freestart = physical_start 400 + (KERNEL_TEXT_BASE - KERNEL_SPACE_START) + kerneldatasize; 401 physical_end = bootconfig.dram[bootconfig.dramblocks - 1].address 402 + bootconfig.dram[bootconfig.dramblocks - 1].pages * NBPG; 403 physical_freeend = physical_end; 404 /* free_pages = bootconfig.drampages;*/ 405 406 for (loop = 0; loop < bootconfig.dramblocks; ++loop) 407 physmem += bootconfig.dram[loop].pages; 408 409 /* XXX handle UMA framebuffer memory */ 410 411 /* Use the first 1MB to allocate things */ 412 freemempos = 0xc0000000; 413 memset((void *)0xc0000000, 0, 0x80000); 414 415 /* 416 * Right We have the bottom meg of memory mapped to 0x00000000 417 * so was can get at it. The kernel will ocupy the start of it. 418 * After the kernel/args we allocate some of the fixed page tables 419 * we need to get the system going. 420 * We allocate one page directory and 8 page tables and store the 421 * physical addresses in the kernel_pt_table array. 422 * Must remember that neither the page L1 or L2 page tables are the 423 * same size as a page ! 424 * 425 * Ok the next bit of physical allocate may look complex but it is 426 * simple really. I have done it like this so that no memory gets 427 * wasted during the allocate of various pages and tables that are 428 * all different sizes. 429 * The start address will be page aligned. 430 * We allocate the kernel page directory on the first free 16KB 431 * boundry we find. 432 * We allocate the kernel page tables on the first 1KB boundry we find. 433 * We allocate 9 PT's. This means that in the process we 434 * KNOW that we will encounter at least 1 16KB boundry. 435 * 436 * Eventually if the top end of the memory gets used for process L1 437 * page tables the kernel L1 page table may be moved up there. 438 */ 439 440 #ifdef VERBOSE_INIT_ARM 441 printf("Allocating page tables\n"); 442 #endif 443 444 /* Define a macro to simplify memory allocation */ 445 #define valloc_pages(var, np) \ 446 (var).pv_pa = (var).pv_va = freemempos; \ 447 freemempos += np * NBPG; 448 #define alloc_pages(var, np) \ 449 (var) = freemempos; \ 450 freemempos += np * NBPG; 451 452 453 valloc_pages(kernel_l1pt, PD_SIZE / NBPG); 454 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) { 455 alloc_pages(kernel_pt_table[loop], PT_SIZE / NBPG); 456 } 457 458 /* 459 * Allocate a page for the system page mapped to V0x00000000 460 * This page will just contain the system vectors and can be 461 * shared by all processes. 462 */ 463 valloc_pages(systempage, 1); 464 465 /* Allocate a page for the page table to map kernel page tables*/ 466 valloc_pages(kernel_ptpt, PT_SIZE / NBPG); 467 468 /* Allocate stacks for all modes */ 469 valloc_pages(irqstack, IRQ_STACK_SIZE); 470 valloc_pages(abtstack, ABT_STACK_SIZE); 471 valloc_pages(undstack, UND_STACK_SIZE); 472 valloc_pages(kernelstack, UPAGES); 473 474 #ifdef VERBOSE_INIT_ARM 475 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa, irqstack.pv_va); 476 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa, abtstack.pv_va); 477 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa, undstack.pv_va); 478 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa, kernelstack.pv_va); 479 #endif 480 481 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / NBPG); 482 483 #ifdef CPU_SA110 484 /* 485 * XXX totally stuffed hack to work round problems introduced 486 * in recent versions of the pmap code. Due to the calls used there 487 * we cannot allocate virtual memory during bootstrap. 488 */ 489 for(;;) { 490 alloc_pages(sa110_cc_base, 1); 491 if (! (sa110_cc_base & (CPU_SA110_CACHE_CLEAN_SIZE - 1))) 492 break; 493 } 494 { 495 vaddr_t dummy; 496 alloc_pages(dummy, CPU_SA110_CACHE_CLEAN_SIZE / NBPG - 1); 497 } 498 sa110_cache_clean_addr = sa110_cc_base; 499 sa110_cache_clean_size = CPU_SA110_CACHE_CLEAN_SIZE / 2; 500 #endif /* CPU_SA110 */ 501 502 /* 503 * Ok we have allocated physical pages for the primary kernel 504 * page tables 505 */ 506 507 #ifdef VERBOSE_INIT_ARM 508 printf("Creating L1 page table\n"); 509 #endif 510 511 /* 512 * Now we start consturction of the L1 page table 513 * We start by mapping the L2 page tables into the L1. 514 * This means that we can replace L1 mappings later on if necessary 515 */ 516 l1pagetable = kernel_l1pt.pv_pa; 517 518 /* Map the L2 pages tables in the L1 page table */ 519 map_pagetable(l1pagetable, 0x00000000, 520 kernel_pt_table[KERNEL_PT_SYS]); 521 map_pagetable(l1pagetable, KERNEL_SPACE_START, 522 kernel_pt_table[KERNEL_PT_KERNEL]); 523 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; ++loop) 524 map_pagetable(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000, 525 kernel_pt_table[KERNEL_PT_VMDATA + loop]); 526 map_pagetable(l1pagetable, PROCESS_PAGE_TBLS_BASE, 527 kernel_ptpt.pv_pa); 528 #define SAIPIO_BASE 0xd0000000 /* XXX XXX */ 529 map_pagetable(l1pagetable, SAIPIO_BASE, 530 kernel_pt_table[KERNEL_PT_IO]); 531 532 533 #ifdef VERBOSE_INIT_ARM 534 printf("Mapping kernel\n"); 535 #endif 536 537 /* Now we fill in the L2 pagetable for the kernel code/data */ 538 l2pagetable = kernel_pt_table[KERNEL_PT_KERNEL]; 539 540 /* 541 * XXX there is no ELF header to find RO region. 542 * XXX What should we do? 543 */ 544 #if 0 545 if (N_GETMAGIC(kernexec[0]) == ZMAGIC) { 546 logical = map_chunk(l1pagetable, l2pagetable, KERNEL_TEXT_BASE, 547 physical_start, kernexec->a_text, 548 AP_KR, PT_CACHEABLE); 549 logical += map_chunk(l1pagetable, l2pagetable, 550 KERNEL_TEXT_BASE + logical, physical_start + logical, 551 kerneldatasize - kernexec->a_text, AP_KRW, PT_CACHEABLE); 552 } else 553 #endif 554 map_chunk(l1pagetable, l2pagetable, KERNEL_TEXT_BASE, 555 KERNEL_TEXT_BASE, kerneldatasize, 556 AP_KRW, PT_CACHEABLE); 557 558 #ifdef VERBOSE_INIT_ARM 559 printf("Constructing L2 page tables\n"); 560 #endif 561 562 /* Map the stack pages */ 563 l2pagetable = kernel_pt_table[KERNEL_PT_KERNEL]; 564 map_chunk(0, l2pagetable, irqstack.pv_va, irqstack.pv_pa, 565 IRQ_STACK_SIZE * NBPG, AP_KRW, PT_CACHEABLE); 566 map_chunk(0, l2pagetable, abtstack.pv_va, abtstack.pv_pa, 567 ABT_STACK_SIZE * NBPG, AP_KRW, PT_CACHEABLE); 568 map_chunk(0, l2pagetable, undstack.pv_va, undstack.pv_pa, 569 UND_STACK_SIZE * NBPG, AP_KRW, PT_CACHEABLE); 570 map_chunk(0, l2pagetable, kernelstack.pv_va, kernelstack.pv_pa, 571 UPAGES * NBPG, AP_KRW, PT_CACHEABLE); 572 map_chunk(0, l2pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa, 573 PD_SIZE, AP_KRW, 0); 574 575 /* Map the page table that maps the kernel pages */ 576 map_entry_nc(l2pagetable, kernel_ptpt.pv_pa, kernel_ptpt.pv_pa); 577 578 /* 579 * Map entries in the page table used to map PTE's 580 * Basically every kernel page table gets mapped here 581 */ 582 /* The -2 is slightly bogus, it should be -log2(sizeof(pt_entry_t)) */ 583 l2pagetable = kernel_ptpt.pv_pa; 584 map_entry_nc(l2pagetable, (0x00000000 >> (PGSHIFT-2)), 585 kernel_pt_table[KERNEL_PT_SYS]); 586 map_entry_nc(l2pagetable, (KERNEL_SPACE_START >> (PGSHIFT-2)), 587 kernel_pt_table[KERNEL_PT_KERNEL]); 588 map_entry_nc(l2pagetable, (KERNEL_BASE >> (PGSHIFT-2)), 589 kernel_pt_table[KERNEL_PT_KERNEL]); 590 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; ++loop) { 591 map_entry_nc(l2pagetable, ((KERNEL_VM_BASE + 592 (loop * 0x00400000)) >> (PGSHIFT-2)), 593 kernel_pt_table[KERNEL_PT_VMDATA + loop]); 594 } 595 map_entry_nc(l2pagetable, (PROCESS_PAGE_TBLS_BASE >> (PGSHIFT-2)), 596 kernel_ptpt.pv_pa); 597 map_entry_nc(l2pagetable, (SAIPIO_BASE >> (PGSHIFT-2)), 598 kernel_pt_table[KERNEL_PT_IO]); 599 600 /* 601 * Map the system page in the kernel page table for the bottom 1Meg 602 * of the virtual memory map. 603 */ 604 l2pagetable = kernel_pt_table[KERNEL_PT_SYS]; 605 map_entry(l2pagetable, 0x0000000, systempage.pv_pa); 606 607 /* Map any I/O modules here, as we don't have real bus_space_map() */ 608 printf("mapping IO..."); 609 l2pagetable = kernel_pt_table[KERNEL_PT_IO]; 610 map_entry_nc(l2pagetable, SACOM3_BASE, SACOM3_HW_BASE); 611 612 #ifdef FRAMEBUF_HW_BASE 613 /* map framebuffer if its address is known */ 614 map_section(l1pagetable, FRAMEBUF_BASE, FRAMEBUF_HW_BASE, 1); 615 #endif 616 617 #ifdef CPU_SA110 618 l2pagetable = kernel_pt_table[KERNEL_PT_KERNEL]; 619 map_chunk(0, l2pagetable, sa110_cache_clean_addr, 620 sa110_cache_clean_addr, CPU_SA110_CACHE_CLEAN_SIZE, 621 AP_KRW, PT_CACHEABLE); 622 #endif 623 /* 624 * Now we have the real page tables in place so we can switch to them. 625 * Once this is done we will be running with the REAL kernel page 626 * tables. 627 */ 628 629 printf("done.\n"); 630 631 /* Right set up the vectors at the bottom of page 0 */ 632 memcpy((char *)systempage.pv_va, page0, page0_end - page0); 633 634 /* 635 * Pages were allocated during the secondary bootstrap for the 636 * stacks for different CPU modes. 637 * We must now set the r13 registers in the different CPU modes to 638 * point to these stacks. 639 * Since the ARM stacks use STMFD etc. we must set r13 to the top end 640 * of the stack memory. 641 */ 642 printf("init subsystems: stacks "); 643 644 set_stackptr(PSR_IRQ32_MODE, irqstack.pv_va + IRQ_STACK_SIZE * NBPG); 645 set_stackptr(PSR_ABT32_MODE, abtstack.pv_va + ABT_STACK_SIZE * NBPG); 646 set_stackptr(PSR_UND32_MODE, undstack.pv_va + UND_STACK_SIZE * NBPG); 647 #ifdef PMAP_DEBUG 648 if (pmap_debug_level >= 0) 649 printf("kstack V%08lx P%08lx\n", kernelstack.pv_va, 650 kernelstack.pv_pa); 651 #endif /* PMAP_DEBUG */ 652 653 /* 654 * Well we should set a data abort handler. 655 * Once things get going this will change as we will need a proper 656 * handler. Until then we will use a handler that just panics but 657 * tells us why. 658 * Initialisation of the vectors will just panic on a data abort. 659 * This just fills in a slighly better one. 660 */ 661 printf("vectors "); 662 data_abort_handler_address = (u_int)data_abort_handler; 663 prefetch_abort_handler_address = (u_int)prefetch_abort_handler; 664 undefined_handler_address = (u_int)undefinedinstruction_bounce; 665 printf("%08x %08x %08x\n", data_abort_handler_address, 666 prefetch_abort_handler_address, undefined_handler_address); 667 668 /* Initialise the undefined instruction handlers */ 669 printf("undefined "); 670 undefined_init(); 671 672 /* Set the page table address. */ 673 setttb(kernel_l1pt.pv_pa); 674 675 /* Disable PID virtual address mapping */ 676 asm("mcr 15, 0, %0, c13, c0, 0" : : "r" (0)); 677 #ifdef BOOT_DUMP 678 dumppages((char *)0xb0100000, 64); /* XXX */ 679 #endif 680 /* Enable MMU, I-cache, D-cache, write buffer. */ 681 cpufunc_control(0x337f, 0x107d); 682 683 if (bootinfo->bi_cnuse == BI_CNUSE_SERIAL) 684 consinit(); 685 else { 686 /* XXX this isn't useful for normal use, but helps debuging */ 687 biconscninit(&bicons); 688 cn_tab = &bicons; 689 cn_tab->cn_pri = CN_REMOTE; 690 } 691 692 #ifdef VERBOSE_INIT_ARM 693 printf("MMU enabled. control=%08x\n", cpu_get_control()); 694 #endif 695 696 /* Boot strap pmap telling it where the kernel page table is */ 697 pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, kernel_ptpt); 698 699 700 #ifdef CPU_SA110 701 if (cputype == CPU_ID_SA110) 702 rpc_sa110_cc_setup(); 703 #endif /* CPU_SA110 */ 704 705 #ifdef IPKDB 706 /* Initialise ipkdb */ 707 ipkdb_init(); 708 if (boothowto & RB_KDB) 709 ipkdb_connect(0); 710 #endif /* NIPKDB */ 711 712 #ifdef BOOT_DUMP 713 dumppages((char *)kernel_l1pt.pv_va, 16); 714 dumppages((char *)PROCESS_PAGE_TBLS_BASE, 16); 715 #endif 716 717 #ifdef DDB 718 { 719 static struct undefined_handler uh; 720 721 uh.uh_handler = db_trapper; 722 install_coproc_handler_static(0, &uh); 723 } 724 ddb_init(symbolsize, ((int *)&end), ((char *)&end) + symbolsize); 725 #endif 726 727 printf("kernsize=0x%x", kerneldatasize); 728 printf(" (including 0x%x symbols)\n", symbolsize); 729 730 #ifdef DDB 731 if (boothowto & RB_KDB) 732 Debugger(); 733 #endif /* DDB */ 734 735 /* We return the new stack pointer address */ 736 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP); 737 } 738 739 #ifdef DEBUG_BEFOREMMU 740 cons_decl(sacom); 741 void 742 fakecninit() 743 { 744 static struct consdev fakecntab = cons_init(sacom); 745 cn_tab = &fakecntab; 746 747 (*cn_tab->cn_init)(0); 748 cn_tab->cn_pri = CN_REMOTE; 749 } 750 #endif 751 752 #ifdef CPU_SA110 753 754 /* 755 * For optimal cache cleaning we need two 16K banks of 756 * virtual address space that NOTHING else will access 757 * and then we alternate the cache cleaning between the 758 * two banks. 759 * The cache cleaning code requires requires 2 banks aligned 760 * on total size boundry so the banks can be alternated by 761 * eorring the size bit (assumes the bank size is a power of 2) 762 */ 763 void 764 rpc_sa110_cc_setup(void) 765 { 766 int loop; 767 paddr_t kaddr; 768 pt_entry_t *pte; 769 770 (void) pmap_extract(kernel_pmap, KERNEL_TEXT_BASE, &kaddr); 771 for (loop = 0; loop < CPU_SA110_CACHE_CLEAN_SIZE; loop += NBPG) { 772 pte = pmap_pte(kernel_pmap, (sa110_cc_base + loop)); 773 *pte = L2_PTE(kaddr, AP_KR); 774 } 775 sa110_cache_clean_addr = sa110_cc_base; 776 sa110_cache_clean_size = CPU_SA110_CACHE_CLEAN_SIZE / 2; 777 } 778 #endif /* CPU_SA110 */ 779 780 #ifdef BOOT_DUMP 781 void dumppages(char *start, int nbytes) 782 { 783 char *p = start; 784 char *p1; 785 int i; 786 787 for(i = nbytes; i > 0; i -= 16, p += 16) { 788 for(p1 = p + 15; p != p1; p1--) { 789 if (*p1) 790 break; 791 } 792 if (! *p1) 793 continue; 794 printf("%08x %02x %02x %02x %02x %02x %02x %02x %02x" 795 " %02x %02x %02x %02x %02x %02x %02x %02x\n", 796 (unsigned int)p, 797 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], 798 p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]); 799 } 800 } 801 #endif 802 803 /* End of machdep.c */ 804