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