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