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