1 /* $NetBSD: hpc_machdep.c,v 1.84 2008/04/20 16:19:46 rafal 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 38 /* 39 * Machine dependent functions for kernel setup. 40 */ 41 42 #include <sys/cdefs.h> 43 __KERNEL_RCSID(0, "$NetBSD: hpc_machdep.c,v 1.84 2008/04/20 16:19:46 rafal Exp $"); 44 45 #include "opt_ddb.h" 46 #include "opt_pmap_debug.h" 47 #include "fs_nfs.h" 48 #include "ksyms.h" 49 50 #include <sys/param.h> 51 #include <sys/systm.h> 52 #include <sys/kernel.h> 53 #include <sys/reboot.h> 54 #include <sys/proc.h> 55 #include <sys/msgbuf.h> 56 #include <sys/exec.h> 57 #include <sys/ksyms.h> 58 #include <sys/boot_flag.h> 59 #include <sys/conf.h> /* XXX for consinit related hacks */ 60 61 #if NKSYMS || defined(DDB) || defined(LKM) 62 #include <machine/db_machdep.h> 63 #include <ddb/db_sym.h> 64 #include <ddb/db_extern.h> 65 #ifndef DB_ELFSIZE 66 #error Must define DB_ELFSIZE! 67 #endif 68 #define ELFSIZE DB_ELFSIZE 69 #include <sys/exec_elf.h> 70 #endif 71 72 #include <uvm/uvm.h> 73 74 #include <arm/sa11x0/sa11x0_reg.h> 75 #include <arm/cpuconf.h> 76 #include <arm/undefined.h> 77 78 #include <machine/bootconfig.h> 79 #include <machine/bootinfo.h> 80 #include <machine/cpu.h> 81 #include <machine/frame.h> 82 #include <machine/intr.h> 83 #include <machine/io.h> 84 #include <machine/platid.h> 85 #include <machine/rtc.h> 86 #include <machine/signal.h> 87 88 #include <dev/cons.h> 89 #include <dev/hpc/apm/apmvar.h> 90 #include <dev/hpc/bicons.h> 91 92 #ifdef NFS 93 #include <sys/mount.h> 94 #include <nfs/rpcv2.h> 95 #include <nfs/nfsproto.h> 96 #include <nfs/nfs.h> 97 #include <nfs/nfsmount.h> 98 #endif /* NFS */ 99 100 /* Kernel text starts 256K in from the bottom of the kernel address space. */ 101 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00040000) 102 #define KERNEL_VM_BASE (KERNEL_BASE + 0x00C00000) 103 #define KERNEL_VM_SIZE 0x05000000 104 105 /* 106 * Address to call from cpu_reset() to reset the machine. 107 * This is machine architecture dependent as it varies depending 108 * on where the ROM appears when you turn the MMU off. 109 */ 110 u_int cpu_reset_address = 0; 111 112 /* Define various stack sizes in pages */ 113 #define IRQ_STACK_SIZE 1 114 #define ABT_STACK_SIZE 1 115 #define UND_STACK_SIZE 1 116 117 BootConfig bootconfig; /* Boot config storage */ 118 struct bootinfo *bootinfo, bootinfo_storage; 119 static char booted_kernel_storage[80]; 120 char *booted_kernel = booted_kernel_storage; 121 122 paddr_t physical_start; 123 paddr_t physical_freestart; 124 paddr_t physical_freeend; 125 paddr_t physical_end; 126 int physmem = 0; 127 128 #ifndef PMAP_STATIC_L1S 129 int max_processes = 64; /* Default number */ 130 #endif /* !PMAP_STATIC_L1S */ 131 132 133 /* Physical and virtual addresses for some global pages */ 134 pv_addr_t systempage; 135 pv_addr_t irqstack; 136 pv_addr_t undstack; 137 pv_addr_t abtstack; 138 pv_addr_t kernelstack; 139 140 char *boot_args = NULL; 141 char boot_file[16]; 142 143 vaddr_t msgbufphys; 144 145 extern u_int data_abort_handler_address; 146 extern u_int prefetch_abort_handler_address; 147 extern u_int undefined_handler_address; 148 extern int end; 149 150 #ifdef PMAP_DEBUG 151 extern int pmap_debug_level; 152 #endif /* PMAP_DEBUG */ 153 154 #define KERNEL_PT_VMEM 0 /* Page table for mapping video memory */ 155 #define KERNEL_PT_SYS 1 /* Page table for mapping proc0 zero page */ 156 #define KERNEL_PT_IO 2 /* Page table for mapping IO */ 157 #define KERNEL_PT_KERNEL 3 /* Page table for mapping kernel */ 158 #define KERNEL_PT_KERNEL_NUM 4 159 #define KERNEL_PT_VMDATA (KERNEL_PT_KERNEL+KERNEL_PT_KERNEL_NUM) 160 /* Page tables for mapping kernel VM */ 161 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */ 162 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM) 163 164 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS]; 165 166 struct user *proc0paddr; 167 168 #define CPU_SA110_CACHE_CLEAN_SIZE (0x4000 * 2) 169 extern unsigned int sa1_cache_clean_addr; 170 extern unsigned int sa1_cache_clean_size; 171 static vaddr_t sa1_cc_base; 172 173 /* Mode dependent sleep function holder */ 174 void (*__sleep_func)(void *); 175 void *__sleep_ctx; 176 177 /* Non-buffered non-cacheable memory needed to enter idle mode */ 178 extern vaddr_t sa11x0_idle_mem; 179 180 /* Prototypes */ 181 void data_abort_handler(trapframe_t *); 182 void prefetch_abort_handler(trapframe_t *); 183 void undefinedinstruction_bounce(trapframe_t *); 184 void dumpsys(void); 185 u_int cpu_get_control(void); 186 187 u_int initarm(int, char **, struct bootinfo *); 188 189 #ifdef DEBUG_BEFOREMMU 190 static void fakecninit(void); 191 #endif 192 193 #ifdef BOOT_DUMP 194 static void dumppages(char *, int); 195 #endif 196 197 /* 198 * Reboots the system. 199 * 200 * Deal with any syncing, unmounting, dumping and shutdown hooks, 201 * then reset the CPU. 202 */ 203 void 204 cpu_reboot(int howto, char *bootstr) 205 { 206 /* 207 * If we are still cold then hit the air brakes 208 * and crash to earth fast. 209 */ 210 if (cold) { 211 doshutdownhooks(); 212 printf("Halted while still in the ICE age.\n"); 213 printf("The operating system has halted.\n"); 214 printf("Please press any key to reboot.\n\n"); 215 cngetc(); 216 printf("rebooting...\n"); 217 cpu_reset(); 218 /* NOTREACHED */ 219 } 220 221 /* Reset the sleep function. */ 222 __sleep_func = NULL; 223 __sleep_ctx = NULL; 224 225 /* Disable console buffering. */ 226 cnpollc(1); 227 228 /* 229 * If RB_NOSYNC was not specified sync the discs. 230 * Note: Unless cold is set to 1 here, syslogd will die during 231 * the unmount. It looks like syslogd is getting woken up only 232 * to find that it cannot page part of the binary in as the 233 * file system has been unmounted. 234 */ 235 if (!(howto & RB_NOSYNC)) 236 bootsync(); 237 238 /* Say NO to interrupts. */ 239 (void)splhigh(); 240 241 /* Do a dump if requested. */ 242 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) 243 dumpsys(); 244 245 /* Run any shutdown hooks. */ 246 doshutdownhooks(); 247 248 /* Make sure IRQs are disabled. */ 249 IRQdisable; 250 251 if (howto & RB_HALT) { 252 printf("The operating system has halted.\n"); 253 printf("Please press any key to reboot.\n\n"); 254 cngetc(); 255 } 256 257 printf("rebooting...\n"); 258 cpu_reset(); 259 /* NOTREACHED */ 260 } 261 262 /* Number of DRAM pages which are installed */ 263 /* Units are 4K pages, so 8192 is 32 MB of memory */ 264 #ifndef DRAM_PAGES 265 #define DRAM_PAGES 8192 266 #endif 267 268 /* 269 * Static device mappings. These peripheral registers are mapped at 270 * fixed virtual addresses very early in initarm() so that we can use 271 * them while booting the kernel and stay at the same address 272 * throughout whole kernel's life time. 273 */ 274 static const struct pmap_devmap sa11x0_devmap[] = { 275 /* Physical/virtual address for UART #3. */ 276 { 277 SACOM3_VBASE, 278 SACOM3_BASE, 279 0x24, 280 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE 281 }, 282 { 0, 0, 0, 0, 0 } 283 }; 284 285 /* 286 * Initial entry point on startup. This gets called before main() is 287 * entered. 288 * It should be responsible for setting up everything that must be 289 * in place when main is called. 290 * This includes: 291 * Taking a copy of the boot configuration structure. 292 * Initializing the physical console so characters can be printed. 293 * Setting up page tables for the kernel. 294 */ 295 u_int 296 initarm(int argc, char **argv, struct bootinfo *bi) 297 { 298 u_int kerneldatasize, symbolsize; 299 u_int l1pagetable; 300 vaddr_t freemempos; 301 pv_addr_t kernel_l1pt; 302 vsize_t pt_size; 303 int loop, i; 304 #if NKSYMS || defined(DDB) || defined(LKM) 305 Elf_Shdr *sh; 306 #endif 307 308 __sleep_func = NULL; 309 __sleep_ctx = NULL; 310 311 /* 312 * Heads up ... Setup the CPU / MMU / TLB functions. 313 */ 314 set_cpufuncs(); 315 316 #ifdef DEBUG_BEFOREMMU 317 /* 318 * At this point, we cannot call real consinit(). 319 * Just call a faked up version of consinit(), which does the thing 320 * with MMU disabled. 321 */ 322 fakecninit(); 323 #endif 324 325 /* 326 * XXX for now, overwrite bootconfig to hardcoded values. 327 * XXX kill bootconfig and directly call uvm_physload 328 */ 329 bootconfig.dram[0].address = 0xc0000000; 330 bootconfig.dram[0].pages = DRAM_PAGES; 331 bootconfig.dramblocks = 1; 332 kerneldatasize = (uint32_t)&end - (uint32_t)KERNEL_TEXT_BASE; 333 334 symbolsize = 0; 335 #if NKSYMS || defined(DDB) || defined(LKM) 336 if (!memcmp(&end, "\177ELF", 4)) { 337 sh = (Elf_Shdr *)((char *)&end + ((Elf_Ehdr *)&end)->e_shoff); 338 loop = ((Elf_Ehdr *)&end)->e_shnum; 339 for (; loop; loop--, sh++) 340 if (sh->sh_offset > 0 && 341 (sh->sh_offset + sh->sh_size) > symbolsize) 342 symbolsize = sh->sh_offset + sh->sh_size; 343 } 344 #endif 345 346 printf("kernsize=0x%x\n", kerneldatasize); 347 kerneldatasize += symbolsize; 348 kerneldatasize = ((kerneldatasize - 1) & ~(PAGE_SIZE * 4 - 1)) + 349 PAGE_SIZE * 8; 350 351 /* parse kernel args */ 352 boothowto = 0; 353 boot_file[0] = '\0'; 354 strncpy(booted_kernel_storage, argv[0], sizeof(booted_kernel_storage)); 355 for (i = 1; i < argc; i++) { 356 char *cp = argv[i]; 357 358 switch (*cp) { 359 case 'b': 360 /* boot device: -b=sd0 etc. */ 361 cp = cp + 2; 362 #ifdef NFS 363 if (strcmp(cp, "nfs") == 0) 364 mountroot = nfs_mountroot; 365 else 366 strncpy(boot_file, cp, sizeof(boot_file)); 367 #else /* !NFS */ 368 strncpy(boot_file, cp, sizeof(boot_file)); 369 #endif /* !NFS */ 370 break; 371 default: 372 BOOT_FLAG(*cp, boothowto); 373 break; 374 } 375 } 376 377 /* copy bootinfo into known kernel space */ 378 bootinfo_storage = *bi; 379 bootinfo = &bootinfo_storage; 380 381 #ifdef BOOTINFO_FB_WIDTH 382 bootinfo->fb_line_bytes = BOOTINFO_FB_LINE_BYTES; 383 bootinfo->fb_width = BOOTINFO_FB_WIDTH; 384 bootinfo->fb_height = BOOTINFO_FB_HEIGHT; 385 bootinfo->fb_type = BOOTINFO_FB_TYPE; 386 #endif 387 388 /* 389 * hpcboot has loaded me with MMU disabled. 390 * So create kernel page tables and enable MMU. 391 */ 392 393 /* 394 * Set up the variables that define the availability of physcial 395 * memory. 396 */ 397 physical_start = bootconfig.dram[0].address; 398 physical_freestart = physical_start 399 + (KERNEL_TEXT_BASE - KERNEL_BASE) + kerneldatasize; 400 physical_end = bootconfig.dram[bootconfig.dramblocks - 1].address 401 + bootconfig.dram[bootconfig.dramblocks - 1].pages * PAGE_SIZE; 402 physical_freeend = physical_end; 403 404 for (loop = 0; loop < bootconfig.dramblocks; ++loop) 405 physmem += bootconfig.dram[loop].pages; 406 407 /* XXX handle UMA framebuffer memory */ 408 409 /* Use the first 256kB to allocate things */ 410 freemempos = KERNEL_BASE; 411 memset((void *)KERNEL_BASE, 0, KERNEL_TEXT_BASE - KERNEL_BASE); 412 413 /* 414 * Right. We have the bottom meg of memory mapped to 0x00000000 415 * so was can get at it. The kernel will occupy the start of it. 416 * After the kernel/args we allocate some of the fixed page tables 417 * we need to get the system going. 418 * We allocate one page directory and NUM_KERNEL_PTS page tables 419 * and store the physical addresses in the kernel_pt_table array. 420 * Must remember that neither the page L1 or L2 page tables are the 421 * same size as a page ! 422 * 423 * Ok, the next bit of physical allocate may look complex but it is 424 * simple really. I have done it like this so that no memory gets 425 * wasted during the allocate of various pages and tables that are 426 * all different sizes. 427 * The start address will be page aligned. 428 * We allocate the kernel page directory on the first free 16KB 429 * boundary we find. 430 * We allocate the kernel page tables on the first 1KB boundary we 431 * find. We allocate at least 9 PT's (12 currently). This means 432 * that in the process we KNOW that we will encounter at least one 433 * 16KB boundary. 434 * 435 * Eventually if the top end of the memory gets used for process L1 436 * page tables the kernel L1 page table may be moved up there. 437 */ 438 439 #ifdef VERBOSE_INIT_ARM 440 printf("Allocating page tables\n"); 441 #endif 442 443 /* Define a macro to simplify memory allocation */ 444 #define valloc_pages(var, np) \ 445 (var).pv_pa = (var).pv_va = freemempos; \ 446 freemempos += (np) * PAGE_SIZE; 447 #define alloc_pages(var, np) \ 448 (var) = freemempos; \ 449 freemempos += (np) * PAGE_SIZE; 450 451 452 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE); 453 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) { 454 alloc_pages(kernel_pt_table[loop].pv_pa, 455 L2_TABLE_SIZE / PAGE_SIZE); 456 kernel_pt_table[loop].pv_va = kernel_pt_table[loop].pv_pa; 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 pt_size = round_page(freemempos) - KERNEL_BASE; 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, 476 irqstack.pv_va); 477 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa, 478 abtstack.pv_va); 479 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa, 480 undstack.pv_va); 481 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa, 482 kernelstack.pv_va); 483 #endif 484 485 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE); 486 487 /* 488 * XXX Actually, we only need virtual space and don't need 489 * XXX physical memory for sa110_cc_base and sa11x0_idle_mem. 490 */ 491 /* 492 * XXX totally stuffed hack to work round problems introduced 493 * in recent versions of the pmap code. Due to the calls used there 494 * we cannot allocate virtual memory during bootstrap. 495 */ 496 for (;;) { 497 alloc_pages(sa1_cc_base, 1); 498 if (!(sa1_cc_base & (CPU_SA110_CACHE_CLEAN_SIZE - 1))) 499 break; 500 } 501 { 502 vaddr_t dummy; 503 alloc_pages(dummy, CPU_SA110_CACHE_CLEAN_SIZE / PAGE_SIZE - 1); 504 } 505 sa1_cache_clean_addr = sa1_cc_base; 506 sa1_cache_clean_size = CPU_SA110_CACHE_CLEAN_SIZE / 2; 507 508 alloc_pages(sa11x0_idle_mem, 1); 509 510 /* 511 * Ok, we have allocated physical pages for the primary kernel 512 * page tables. 513 */ 514 515 #ifdef VERBOSE_INIT_ARM 516 printf("Creating L1 page table\n"); 517 #endif 518 519 /* 520 * Now we start construction of the L1 page table. 521 * We start by mapping the L2 page tables into the L1. 522 * This means that we can replace L1 mappings later on if necessary. 523 */ 524 l1pagetable = kernel_l1pt.pv_pa; 525 526 /* Map the L2 pages tables in the L1 page table */ 527 pmap_link_l2pt(l1pagetable, 0x00000000, 528 &kernel_pt_table[KERNEL_PT_SYS]); 529 #define SAIPIO_BASE 0xd0000000 /* XXX XXX */ 530 pmap_link_l2pt(l1pagetable, SAIPIO_BASE, 531 &kernel_pt_table[KERNEL_PT_IO]); 532 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++) 533 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000, 534 &kernel_pt_table[KERNEL_PT_KERNEL + loop]); 535 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++) 536 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000, 537 &kernel_pt_table[KERNEL_PT_VMDATA + loop]); 538 539 /* update the top of the kernel VM */ 540 pmap_curmaxkvaddr = 541 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000); 542 543 #ifdef VERBOSE_INIT_ARM 544 printf("Mapping kernel\n"); 545 #endif 546 547 /* Now we fill in the L2 pagetable for the kernel code/data */ 548 549 /* 550 * XXX there is no ELF header to find RO region. 551 * XXX What should we do? 552 */ 553 #if 0 554 if (N_GETMAGIC(kernexec[0]) == ZMAGIC) { 555 logical = pmap_map_chunk(l1pagetable, KERNEL_TEXT_BASE, 556 physical_start, kernexec->a_text, 557 VM_PROT_READ, PTE_CACHE); 558 logical += pmap_map_chunk(l1pagetable, 559 KERNEL_TEXT_BASE + logical, physical_start + logical, 560 kerneldatasize - kernexec->a_text, 561 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 562 } else 563 #endif 564 pmap_map_chunk(l1pagetable, KERNEL_TEXT_BASE, 565 KERNEL_TEXT_BASE, kerneldatasize, 566 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 567 568 #ifdef VERBOSE_INIT_ARM 569 printf("Constructing L2 page tables\n"); 570 #endif 571 572 /* Map the stack pages */ 573 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa, 574 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 575 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa, 576 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 577 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa, 578 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 579 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa, 580 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 581 582 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa, 583 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE); 584 585 /* Map page tables */ 586 pmap_map_chunk(l1pagetable, KERNEL_BASE, KERNEL_BASE, pt_size, 587 VM_PROT_READ | VM_PROT_WRITE, PTE_PAGETABLE); 588 589 /* Map a page for entering idle mode */ 590 pmap_map_entry(l1pagetable, sa11x0_idle_mem, sa11x0_idle_mem, 591 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE); 592 593 /* Map the vector page. */ 594 pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa, 595 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 596 597 /* Map the statically mapped devices. */ 598 pmap_devmap_bootstrap(l1pagetable, sa11x0_devmap); 599 600 pmap_map_chunk(l1pagetable, sa1_cache_clean_addr, 0xe0000000, 601 CPU_SA110_CACHE_CLEAN_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 602 /* 603 * Now we have the real page tables in place so we can switch to them. 604 * Once this is done we will be running with the REAL kernel page 605 * tables. 606 */ 607 608 printf("done.\n"); 609 610 /* 611 * Pages were allocated during the secondary bootstrap for the 612 * stacks for different CPU modes. 613 * We must now set the r13 registers in the different CPU modes to 614 * point to these stacks. 615 * Since the ARM stacks use STMFD etc. we must set r13 to the top end 616 * of the stack memory. 617 */ 618 printf("init subsystems: stacks "); 619 620 set_stackptr(PSR_IRQ32_MODE, 621 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE); 622 set_stackptr(PSR_ABT32_MODE, 623 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE); 624 set_stackptr(PSR_UND32_MODE, 625 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE); 626 #ifdef PMAP_DEBUG 627 if (pmap_debug_level >= 0) 628 printf("kstack V%08lx P%08lx\n", kernelstack.pv_va, 629 kernelstack.pv_pa); 630 #endif /* PMAP_DEBUG */ 631 632 /* 633 * Well we should set a data abort handler. 634 * Once things get going this will change as we will need a proper 635 * handler. Until then we will use a handler that just panics but 636 * tells us why. 637 * Initialization of the vectors will just panic on a data abort. 638 * This just fills in a slightly better one. 639 */ 640 printf("vectors "); 641 data_abort_handler_address = (u_int)data_abort_handler; 642 prefetch_abort_handler_address = (u_int)prefetch_abort_handler; 643 undefined_handler_address = (u_int)undefinedinstruction_bounce; 644 printf("%08x %08x %08x\n", data_abort_handler_address, 645 prefetch_abort_handler_address, undefined_handler_address); 646 647 /* Initialize the undefined instruction handlers */ 648 printf("undefined "); 649 undefined_init(); 650 651 /* Set the page table address. */ 652 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT); 653 setttb(kernel_l1pt.pv_pa); 654 cpu_tlb_flushID(); 655 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)); 656 657 /* 658 * Moved from cpu_startup() as data_abort_handler() references 659 * this during uvm init. 660 */ 661 proc0paddr = (struct user *)kernelstack.pv_va; 662 lwp0.l_addr = proc0paddr; 663 664 #ifdef BOOT_DUMP 665 dumppages((char *)0xc0000000, 16 * PAGE_SIZE); 666 dumppages((char *)0xb0100000, 64); /* XXX */ 667 #endif 668 /* Enable MMU, I-cache, D-cache, write buffer. */ 669 cpufunc_control(0x337f, 0x107d); 670 671 arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL); 672 673 consinit(); 674 675 #ifdef VERBOSE_INIT_ARM 676 printf("freemempos=%08lx\n", freemempos); 677 printf("MMU enabled. control=%08x\n", cpu_get_control()); 678 #endif 679 680 /* Load memory into UVM. */ 681 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */ 682 for (loop = 0; loop < bootconfig.dramblocks; loop++) { 683 paddr_t dblk_start = (paddr_t)bootconfig.dram[loop].address; 684 paddr_t dblk_end = dblk_start 685 + (bootconfig.dram[loop].pages * PAGE_SIZE); 686 687 if (dblk_start < physical_freestart) 688 dblk_start = physical_freestart; 689 if (dblk_end > physical_freeend) 690 dblk_end = physical_freeend; 691 692 uvm_page_physload(atop(dblk_start), atop(dblk_end), 693 atop(dblk_start), atop(dblk_end), VM_FREELIST_DEFAULT); 694 } 695 696 /* Boot strap pmap telling it where the kernel page table is */ 697 pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE, 698 KERNEL_VM_BASE + KERNEL_VM_SIZE); 699 700 #ifdef BOOT_DUMP 701 dumppages((char *)kernel_l1pt.pv_va, 16); 702 #endif 703 704 #ifdef DDB 705 db_machine_init(); 706 #endif 707 #if NKSYMS || defined(DDB) || defined(LKM) 708 ksyms_init(symbolsize, ((int *)&end), ((char *)&end) + symbolsize); 709 #endif 710 711 printf("kernsize=0x%x", kerneldatasize); 712 printf(" (including 0x%x symbols)\n", symbolsize); 713 714 #ifdef DDB 715 if (boothowto & RB_KDB) 716 Debugger(); 717 #endif /* DDB */ 718 719 if (bootinfo->magic == BOOTINFO_MAGIC) { 720 platid.dw.dw0 = bootinfo->platid_cpu; 721 platid.dw.dw1 = bootinfo->platid_machine; 722 } 723 724 /* We return the new stack pointer address */ 725 return (kernelstack.pv_va + USPACE_SVC_STACK_TOP); 726 } 727 728 void 729 machine_sleep(void) 730 { 731 732 if (__sleep_func != NULL) 733 __sleep_func(__sleep_ctx); 734 } 735 736 void 737 machine_standby(void) 738 { 739 740 } 741 742 void 743 consinit(void) 744 { 745 static int consinit_called = 0; 746 747 if (consinit_called != 0) 748 return; 749 750 consinit_called = 1; 751 if (bootinfo->bi_cnuse == BI_CNUSE_SERIAL) 752 cninit(); 753 else { 754 /* 755 * Nothing to do here. Console initialization is done at 756 * autoconf device attach time. 757 */ 758 } 759 } 760 761 #ifdef DEBUG_BEFOREMMU 762 cons_decl(sacom); 763 764 static void 765 fakecninit(void) 766 { 767 static struct consdev fakecntab = cons_init(sacom); 768 cn_tab = &fakecntab; 769 770 (*cn_tab->cn_init)(0); 771 cn_tab->cn_pri = CN_REMOTE; 772 } 773 #endif 774 775 #ifdef BOOT_DUMP 776 static void 777 dumppages(char *start, int nbytes) 778 { 779 char *p = start; 780 char *p1; 781 int i; 782 783 for (i = nbytes; i > 0; i -= 16, p += 16) { 784 for (p1 = p + 15; p != p1; p1--) { 785 if (*p1) 786 break; 787 } 788 if (!*p1) 789 continue; 790 printf("%08x %02x %02x %02x %02x %02x %02x %02x %02x" 791 " %02x %02x %02x %02x %02x %02x %02x %02x\n", 792 (unsigned int)p, 793 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], 794 p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]); 795 } 796 } 797 #endif 798