1 /* $NetBSD: hpc_machdep.c,v 1.78 2006/02/27 11:34:35 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.78 2006/02/27 11:34:35 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 * Initial entry point on startup. This gets called before main() is 287 * entered. 288 * It should be responsible for setting up everything that must be 289 * in place when main is called. 290 * This includes: 291 * Taking a copy of the boot configuration structure. 292 * Initialising the physical console so characters can be printed. 293 * Setting up page tables for the kernel. 294 */ 295 u_int 296 initarm(int argc, char **argv, struct bootinfo *bi) 297 { 298 int loop; 299 u_int kerneldatasize, symbolsize; 300 u_int l1pagetable; 301 vaddr_t freemempos; 302 pv_addr_t kernel_l1pt; 303 vsize_t pt_size; 304 #if NKSYMS || defined(DDB) || defined(LKM) 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 = DRAM_PAGES; 328 bootconfig.dramblocks = 1; 329 kerneldatasize = (u_int32_t)&end - (u_int32_t)KERNEL_TEXT_BASE; 330 331 symbolsize = 0; 332 #if NKSYMS || defined(DDB) || defined(LKM) 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) & ~(PAGE_SIZE * 4 - 1)) + 346 PAGE_SIZE * 8; 347 348 /* parse kernel args */ 349 boothowto = 0; 350 boot_file[0] = '\0'; 351 strncpy(booted_kernel_storage, *argv, sizeof(booted_kernel_storage)); 352 for (argc--, argv++; argc; argc--, argv++) 353 switch (**argv) { 354 case 'b': 355 /* boot device: -b=sd0 etc. */ 356 #ifdef NFS 357 if (strcmp(*argv + 2, "nfs") == 0) 358 mountroot = nfs_mountroot; 359 else 360 strncpy(boot_file, *argv + 2, 361 sizeof(boot_file)); 362 #else /* NFS */ 363 strncpy(boot_file, *argv + 2, sizeof(boot_file)); 364 #endif /* NFS */ 365 break; 366 default: 367 BOOT_FLAG(**argv, boothowto); 368 break; 369 } 370 371 /* copy bootinfo into known kernel space */ 372 bootinfo_storage = *bi; 373 bootinfo = &bootinfo_storage; 374 375 #ifdef BOOTINFO_FB_WIDTH 376 bootinfo->fb_line_bytes = BOOTINFO_FB_LINE_BYTES; 377 bootinfo->fb_width = BOOTINFO_FB_WIDTH; 378 bootinfo->fb_height = BOOTINFO_FB_HEIGHT; 379 bootinfo->fb_type = BOOTINFO_FB_TYPE; 380 #endif 381 382 /* 383 * hpcboot has loaded me with MMU disabled. 384 * So create kernel page tables and enable MMU. 385 */ 386 387 /* 388 * Set up the variables that define the availablilty of physcial 389 * memory. 390 */ 391 physical_start = bootconfig.dram[0].address; 392 physical_freestart = physical_start 393 + (KERNEL_TEXT_BASE - KERNEL_BASE) + kerneldatasize; 394 physical_end = bootconfig.dram[bootconfig.dramblocks - 1].address 395 + bootconfig.dram[bootconfig.dramblocks - 1].pages * PAGE_SIZE; 396 physical_freeend = physical_end; 397 398 for (loop = 0; loop < bootconfig.dramblocks; ++loop) 399 physmem += bootconfig.dram[loop].pages; 400 401 /* XXX handle UMA framebuffer memory */ 402 403 /* Use the first 256kB to allocate things */ 404 freemempos = KERNEL_BASE; 405 memset((void *)KERNEL_BASE, 0, KERNEL_TEXT_BASE - KERNEL_BASE); 406 407 /* 408 * Right. We have the bottom meg of memory mapped to 0x00000000 409 * so was can get at it. The kernel will occupy the start of it. 410 * After the kernel/args we allocate some of the fixed page tables 411 * we need to get the system going. 412 * We allocate one page directory and 8 page tables and store the 413 * physical addresses in the kernel_pt_table array. 414 * Must remember that neither the page L1 or L2 page tables are the 415 * same size as a page ! 416 * 417 * Ok, the next bit of physical allocate may look complex but it is 418 * simple really. I have done it like this so that no memory gets 419 * wasted during the allocate of various pages and tables that are 420 * all different sizes. 421 * The start address will be page aligned. 422 * We allocate the kernel page directory on the first free 16KB 423 * boundary we find. 424 * We allocate the kernel page tables on the first 1KB boundary we find. 425 * We allocate 9 PT's. This means that in the process we 426 * KNOW that we will encounter at least 1 16KB boundary. 427 * 428 * Eventually if the top end of the memory gets used for process L1 429 * page tables the kernel L1 page table may be moved up there. 430 */ 431 432 #ifdef VERBOSE_INIT_ARM 433 printf("Allocating page tables\n"); 434 #endif 435 436 /* Define a macro to simplify memory allocation */ 437 #define valloc_pages(var, np) \ 438 (var).pv_pa = (var).pv_va = freemempos; \ 439 freemempos += (np) * PAGE_SIZE; 440 #define alloc_pages(var, np) \ 441 (var) = freemempos; \ 442 freemempos += (np) * PAGE_SIZE; 443 444 445 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE); 446 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) { 447 alloc_pages(kernel_pt_table[loop].pv_pa, 448 L2_TABLE_SIZE / PAGE_SIZE); 449 kernel_pt_table[loop].pv_va = kernel_pt_table[loop].pv_pa; 450 } 451 452 /* 453 * Allocate a page for the system page mapped to V0x00000000 454 * This page will just contain the system vectors and can be 455 * shared by all processes. 456 */ 457 valloc_pages(systempage, 1); 458 459 pt_size = round_page(freemempos) - KERNEL_BASE; 460 461 /* Allocate stacks for all modes */ 462 valloc_pages(irqstack, IRQ_STACK_SIZE); 463 valloc_pages(abtstack, ABT_STACK_SIZE); 464 valloc_pages(undstack, UND_STACK_SIZE); 465 valloc_pages(kernelstack, UPAGES); 466 467 #ifdef VERBOSE_INIT_ARM 468 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa, 469 irqstack.pv_va); 470 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa, 471 abtstack.pv_va); 472 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa, 473 undstack.pv_va); 474 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa, 475 kernelstack.pv_va); 476 #endif 477 478 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE); 479 480 /* 481 * XXX Actually, we only need virtual space and don't need 482 * XXX physical memory for sa110_cc_base and sa11x0_idle_mem. 483 */ 484 /* 485 * XXX totally stuffed hack to work round problems introduced 486 * in recent versions of the pmap code. Due to the calls used there 487 * we cannot allocate virtual memory during bootstrap. 488 */ 489 for (;;) { 490 alloc_pages(sa1_cc_base, 1); 491 if (! (sa1_cc_base & (CPU_SA110_CACHE_CLEAN_SIZE - 1))) 492 break; 493 } 494 { 495 vaddr_t dummy; 496 alloc_pages(dummy, CPU_SA110_CACHE_CLEAN_SIZE / PAGE_SIZE - 1); 497 } 498 sa1_cache_clean_addr = sa1_cc_base; 499 sa1_cache_clean_size = CPU_SA110_CACHE_CLEAN_SIZE / 2; 500 501 alloc_pages(sa11x0_idle_mem, 1); 502 503 /* 504 * Ok, we have allocated physical pages for the primary kernel 505 * page tables. 506 */ 507 508 #ifdef VERBOSE_INIT_ARM 509 printf("Creating L1 page table\n"); 510 #endif 511 512 /* 513 * Now we start construction of the L1 page table. 514 * We start by mapping the L2 page tables into the L1. 515 * This means that we can replace L1 mappings later on if necessary. 516 */ 517 l1pagetable = kernel_l1pt.pv_pa; 518 519 /* Map the L2 pages tables in the L1 page table */ 520 pmap_link_l2pt(l1pagetable, 0x00000000, 521 &kernel_pt_table[KERNEL_PT_SYS]); 522 pmap_link_l2pt(l1pagetable, KERNEL_BASE, 523 &kernel_pt_table[KERNEL_PT_KERNEL]); 524 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; ++loop) 525 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000, 526 &kernel_pt_table[KERNEL_PT_VMDATA + loop]); 527 528 /* update the top of the kernel VM */ 529 pmap_curmaxkvaddr = 530 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000); 531 #define SAIPIO_BASE 0xd0000000 /* XXX XXX */ 532 pmap_link_l2pt(l1pagetable, SAIPIO_BASE, 533 &kernel_pt_table[KERNEL_PT_IO]); 534 535 536 #ifdef VERBOSE_INIT_ARM 537 printf("Mapping kernel\n"); 538 #endif 539 540 /* Now we fill in the L2 pagetable for the kernel code/data */ 541 542 /* 543 * XXX there is no ELF header to find RO region. 544 * XXX What should we do? 545 */ 546 #if 0 547 if (N_GETMAGIC(kernexec[0]) == ZMAGIC) { 548 logical = pmap_map_chunk(l1pagetable, KERNEL_TEXT_BASE, 549 physical_start, kernexec->a_text, 550 VM_PROT_READ, PTE_CACHE); 551 logical += pmap_map_chunk(l1pagetable, 552 KERNEL_TEXT_BASE + logical, physical_start + logical, 553 kerneldatasize - kernexec->a_text, 554 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 555 } else 556 #endif 557 pmap_map_chunk(l1pagetable, KERNEL_TEXT_BASE, 558 KERNEL_TEXT_BASE, kerneldatasize, 559 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 560 561 #ifdef VERBOSE_INIT_ARM 562 printf("Constructing L2 page tables\n"); 563 #endif 564 565 /* Map the stack pages */ 566 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa, 567 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 568 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa, 569 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 570 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa, 571 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 572 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa, 573 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 574 575 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa, 576 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE); 577 578 /* Map page tables */ 579 pmap_map_chunk(l1pagetable, KERNEL_BASE, KERNEL_BASE, pt_size, 580 VM_PROT_READ | VM_PROT_WRITE, PTE_PAGETABLE); 581 582 /* Map a page for entering idle mode */ 583 pmap_map_entry(l1pagetable, sa11x0_idle_mem, sa11x0_idle_mem, 584 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE); 585 586 /* Map the vector page. */ 587 pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa, 588 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 589 590 /* Map any I/O modules here, as we don't have real bus_space_map() */ 591 printf("mapping IO..."); 592 pmap_map_entry(l1pagetable, SACOM3_BASE, SACOM3_HW_BASE, 593 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE); 594 595 pmap_map_chunk(l1pagetable, sa1_cache_clean_addr, 0xe0000000, 596 CPU_SA110_CACHE_CLEAN_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 597 /* 598 * Now we have the real page tables in place so we can switch to them. 599 * Once this is done we will be running with the REAL kernel page 600 * tables. 601 */ 602 603 printf("done.\n"); 604 605 /* 606 * Pages were allocated during the secondary bootstrap for the 607 * stacks for different CPU modes. 608 * We must now set the r13 registers in the different CPU modes to 609 * point to these stacks. 610 * Since the ARM stacks use STMFD etc. we must set r13 to the top end 611 * of the stack memory. 612 */ 613 printf("init subsystems: stacks "); 614 615 set_stackptr(PSR_IRQ32_MODE, 616 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE); 617 set_stackptr(PSR_ABT32_MODE, 618 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE); 619 set_stackptr(PSR_UND32_MODE, 620 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE); 621 #ifdef PMAP_DEBUG 622 if (pmap_debug_level >= 0) 623 printf("kstack V%08lx P%08lx\n", kernelstack.pv_va, 624 kernelstack.pv_pa); 625 #endif /* PMAP_DEBUG */ 626 627 /* 628 * Well we should set a data abort handler. 629 * Once things get going this will change as we will need a proper 630 * handler. Until then we will use a handler that just panics but 631 * tells us why. 632 * Initialisation of the vectors will just panic on a data abort. 633 * This just fills in a slightly better one. 634 */ 635 printf("vectors "); 636 data_abort_handler_address = (u_int)data_abort_handler; 637 prefetch_abort_handler_address = (u_int)prefetch_abort_handler; 638 undefined_handler_address = (u_int)undefinedinstruction_bounce; 639 printf("%08x %08x %08x\n", data_abort_handler_address, 640 prefetch_abort_handler_address, undefined_handler_address); 641 642 /* Initialise the undefined instruction handlers */ 643 printf("undefined "); 644 undefined_init(); 645 646 /* Set the page table address. */ 647 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT); 648 setttb(kernel_l1pt.pv_pa); 649 cpu_tlb_flushID(); 650 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)); 651 652 /* 653 * Moved from cpu_startup() as data_abort_handler() references 654 * this during uvm init. 655 */ 656 proc0paddr = (struct user *)kernelstack.pv_va; 657 lwp0.l_addr = proc0paddr; 658 659 #ifdef BOOT_DUMP 660 dumppages((char *)0xc0000000, 16 * PAGE_SIZE); 661 dumppages((char *)0xb0100000, 64); /* XXX */ 662 #endif 663 /* Enable MMU, I-cache, D-cache, write buffer. */ 664 cpufunc_control(0x337f, 0x107d); 665 666 arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL); 667 668 consinit(); 669 670 #ifdef VERBOSE_INIT_ARM 671 printf("freemempos=%08lx\n", freemempos); 672 printf("MMU enabled. control=%08x\n", cpu_get_control()); 673 #endif 674 675 /* Load memory into UVM. */ 676 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */ 677 for (loop = 0; loop < bootconfig.dramblocks; loop++) { 678 paddr_t dblk_start = (paddr_t)bootconfig.dram[loop].address; 679 paddr_t dblk_end = dblk_start 680 + (bootconfig.dram[loop].pages * PAGE_SIZE); 681 682 if (dblk_start < physical_freestart) 683 dblk_start = physical_freestart; 684 if (dblk_end > physical_freeend) 685 dblk_end = physical_freeend; 686 687 uvm_page_physload(atop(dblk_start), atop(dblk_end), 688 atop(dblk_start), atop(dblk_end), VM_FREELIST_DEFAULT); 689 } 690 691 /* Boot strap pmap telling it where the kernel page table is */ 692 pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE, 693 KERNEL_VM_BASE + KERNEL_VM_SIZE); 694 695 if (cputype == CPU_ID_SA110) 696 rpc_sa110_cc_setup(); 697 698 #ifdef IPKDB 699 /* Initialise ipkdb */ 700 ipkdb_init(); 701 if (boothowto & RB_KDB) 702 ipkdb_connect(0); 703 #endif /* NIPKDB */ 704 705 #ifdef BOOT_DUMP 706 dumppages((char *)kernel_l1pt.pv_va, 16); 707 dumppages((char *)PTE_BASE, 16); 708 #endif 709 710 #ifdef DDB 711 db_machine_init(); 712 #endif 713 #if NKSYMS || defined(DDB) || defined(LKM) 714 ksyms_init(symbolsize, ((int *)&end), ((char *)&end) + symbolsize); 715 #endif 716 717 printf("kernsize=0x%x", kerneldatasize); 718 printf(" (including 0x%x symbols)\n", symbolsize); 719 720 #ifdef DDB 721 if (boothowto & RB_KDB) 722 Debugger(); 723 #endif /* DDB */ 724 725 if (bootinfo->magic == BOOTINFO_MAGIC) { 726 platid.dw.dw0 = bootinfo->platid_cpu; 727 platid.dw.dw1 = bootinfo->platid_machine; 728 } 729 730 /* We return the new stack pointer address */ 731 return (kernelstack.pv_va + USPACE_SVC_STACK_TOP); 732 } 733 734 void 735 consinit(void) 736 { 737 static int consinit_called = 0; 738 739 if (consinit_called != 0) 740 return; 741 742 consinit_called = 1; 743 if (bootinfo->bi_cnuse == BI_CNUSE_SERIAL) 744 cninit(); 745 else { 746 /* 747 * Nothing to do here. Console initialization is done at 748 * autoconf device attach time. 749 */ 750 } 751 } 752 753 #ifdef DEBUG_BEFOREMMU 754 cons_decl(sacom); 755 void 756 fakecninit(void) 757 { 758 static struct consdev fakecntab = cons_init(sacom); 759 cn_tab = &fakecntab; 760 761 (*cn_tab->cn_init)(0); 762 cn_tab->cn_pri = CN_REMOTE; 763 } 764 #endif 765 766 void 767 machine_sleep(void) 768 { 769 770 } 771 772 void 773 machine_standby(void) 774 { 775 776 } 777 778 /* 779 * For optimal cache cleaning we need two 16K banks of 780 * virtual address space that NOTHING else will access 781 * and then we alternate the cache cleaning between the 782 * two banks. 783 * The cache cleaning code requires requires 2 banks aligned 784 * on total size boundary so the banks can be alternated by 785 * eorring the size bit (assumes the bank size is a power of 2) 786 */ 787 void 788 rpc_sa110_cc_setup(void) 789 { 790 int loop; 791 paddr_t kaddr; 792 pt_entry_t *pte; 793 794 (void) pmap_extract(pmap_kernel(), KERNEL_TEXT_BASE, &kaddr); 795 for (loop = 0; loop < CPU_SA110_CACHE_CLEAN_SIZE; loop += PAGE_SIZE) { 796 pte = vtopte(sa1_cc_base + loop); 797 *pte = L2_S_PROTO | kaddr | 798 L2_S_PROT(PTE_KERNEL, VM_PROT_READ) | pte_l2_s_cache_mode; 799 PTE_SYNC(pte); 800 } 801 sa1_cache_clean_addr = sa1_cc_base; 802 sa1_cache_clean_size = CPU_SA110_CACHE_CLEAN_SIZE / 2; 803 } 804 805 #ifdef BOOT_DUMP 806 void dumppages(char *start, int nbytes) 807 { 808 char *p = start; 809 char *p1; 810 int i; 811 812 for (i = nbytes; i > 0; i -= 16, p += 16) { 813 for (p1 = p + 15; p != p1; p1--) { 814 if (*p1) 815 break; 816 } 817 if (!*p1) 818 continue; 819 printf("%08x %02x %02x %02x %02x %02x %02x %02x %02x" 820 " %02x %02x %02x %02x %02x %02x %02x %02x\n", 821 (unsigned int)p, 822 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], 823 p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]); 824 } 825 } 826 #endif 827 828 /* End of machdep.c */ 829