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