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