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