1/* $NetBSD: ixm1200_machdep.c,v 1.48 2011/06/30 20:09:25 wiz Exp $ */ 2 3/* 4 * Copyright (c) 2002, 2003 5 * Ichiro FUKUHARA <ichiro@ichiro.org>. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR 21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29/* 30 * Copyright (c) 1997,1998 Mark Brinicombe. 31 * Copyright (c) 1997,1998 Causality Limited. 32 * All rights reserved. 33 * 34 * Redistribution and use in source and binary forms, with or without 35 * modification, are permitted provided that the following conditions 36 * are met: 37 * 1. Redistributions of source code must retain the above copyright 38 * notice, this list of conditions and the following disclaimer. 39 * 2. Redistributions in binary form must reproduce the above copyright 40 * notice, this list of conditions and the following disclaimer in the 41 * documentation and/or other materials provided with the distribution. 42 * 3. All advertising materials mentioning features or use of this software 43 * must display the following acknowledgement: 44 * This product includes software developed by Mark Brinicombe 45 * for the NetBSD Project. 46 * 4. The name of the company nor the name of the author may be used to 47 * endorse or promote products derived from this software without specific 48 * prior written permission. 49 * 50 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 51 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 52 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 53 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 54 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 55 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 56 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 60 * SUCH DAMAGE. 61 */ 62 63#include <sys/cdefs.h> 64__KERNEL_RCSID(0, "$NetBSD: ixm1200_machdep.c,v 1.48 2011/06/30 20:09:25 wiz Exp $"); 65 66#include "opt_ddb.h" 67#include "opt_modular.h" 68#include "opt_pmap_debug.h" 69 70#include <sys/param.h> 71#include <sys/device.h> 72#include <sys/systm.h> 73#include <sys/kernel.h> 74#include <sys/exec.h> 75#include <sys/proc.h> 76#include <sys/msgbuf.h> 77#include <sys/reboot.h> 78#include <sys/termios.h> 79#include <sys/ksyms.h> 80 81#include <uvm/uvm_extern.h> 82 83#include <dev/cons.h> 84 85#include "ksyms.h" 86 87#if NKSYMS || defined(DDB) || defined(MODULAR) 88#include <machine/db_machdep.h> 89#include <ddb/db_sym.h> 90#include <ddb/db_extern.h> 91#ifndef DB_ELFSIZE 92#error Must define DB_ELFSIZE! 93#endif 94#define ELFSIZE DB_ELFSIZE 95#include <sys/exec_elf.h> 96#endif 97 98#include <machine/bootconfig.h> 99#include <sys/bus.h> 100#include <machine/cpu.h> 101#include <machine/frame.h> 102#include <arm/undefined.h> 103 104#include <arm/arm32/machdep.h> 105 106#include <arm/ixp12x0/ixp12x0reg.h> 107#include <arm/ixp12x0/ixp12x0var.h> 108#include <arm/ixp12x0/ixp12x0_comreg.h> 109#include <arm/ixp12x0/ixp12x0_comvar.h> 110#include <arm/ixp12x0/ixp12x0_pcireg.h> 111 112#include <evbarm/ixm1200/ixm1200reg.h> 113#include <evbarm/ixm1200/ixm1200var.h> 114 115/* XXX for consinit related hacks */ 116#include <sys/conf.h> 117 118void ixp12x0_reset(void) __attribute__((noreturn)); 119 120/* Kernel text starts 2MB in from the bottom of the kernel address space. */ 121#define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000) 122#define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000) 123 124/* 125 * The range 0xc1000000 - 0xccffffff is available for kernel VM space 126 * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff 127 */ 128#define KERNEL_VM_SIZE 0x0C000000 129 130/* 131 * Address to call from cpu_reset() to reset the machine. 132 * This is machine architecture dependent as it varies depending 133 * on where the ROM appears when you turn the MMU off. 134 */ 135 136u_int cpu_reset_address = (u_int) ixp12x0_reset; 137 138/* 139 * Define the default console speed for the board. 140 */ 141#ifndef CONMODE 142#define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB)) | CS8) /* 8N1 */ 143#endif 144#ifndef CONSPEED 145#define CONSPEED B38400 146#endif 147#ifndef CONADDR 148#define CONADDR IXPCOM_UART_BASE 149#endif 150 151/* Define various stack sizes in pages */ 152#define IRQ_STACK_SIZE 1 153#define ABT_STACK_SIZE 1 154#define UND_STACK_SIZE 1 155 156BootConfig bootconfig; /* Boot config storage */ 157char *boot_args = NULL; 158char *boot_file = NULL; 159 160vm_offset_t physical_start; 161vm_offset_t physical_freestart; 162vm_offset_t physical_freeend; 163vm_offset_t physical_end; 164u_int free_pages; 165 166/*int debug_flags;*/ 167#ifndef PMAP_STATIC_L1S 168int max_processes = 64; /* Default number */ 169#endif /* !PMAP_STATIC_L1S */ 170 171/* Physical and virtual addresses for some global pages */ 172pv_addr_t irqstack; 173pv_addr_t undstack; 174pv_addr_t abtstack; 175pv_addr_t kernelstack; 176 177vm_offset_t msgbufphys; 178 179extern u_int data_abort_handler_address; 180extern u_int prefetch_abort_handler_address; 181extern u_int undefined_handler_address; 182extern int end; 183 184#ifdef PMAP_DEBUG 185extern int pmap_debug_level; 186#endif /* PMAP_DEBUG */ 187 188#define KERNEL_PT_SYS 0 /* Page table for mapping proc0 zero page */ 189#define KERNEL_PT_KERNEL 1 /* Page table for mapping kernel */ 190#define KERNEL_PT_KERNEL_NUM 2 191#define KERNEL_PT_IO (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM) 192 /* Page table for mapping IO */ 193#define KERNEL_PT_VMDATA (KERNEL_PT_IO + 1) 194 /* Page tables for mapping kernel VM */ 195#define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */ 196#define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM) 197 198pv_addr_t kernel_pt_table[NUM_KERNEL_PTS]; 199 200#ifdef CPU_IXP12X0 201#define CPU_IXP12X0_CACHE_CLEAN_SIZE (0x4000 * 2) 202extern unsigned int ixp12x0_cache_clean_addr; 203extern unsigned int ixp12x0_cache_clean_size; 204static vaddr_t ixp12x0_cc_base; 205#endif /* CPU_IXP12X0 */ 206 207/* Prototypes */ 208 209void consinit(void); 210u_int cpu_get_control(void); 211 212void ixdp_ixp12x0_cc_setup(void); 213 214/* 215 * void cpu_reboot(int howto, char *bootstr) 216 * 217 * Reboots the system 218 * 219 * Deal with any syncing, unmounting, dumping and shutdown hooks, 220 * then reset the CPU. 221 */ 222 223void 224cpu_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 pmf_system_shutdown(boothowto); 233 printf("Halted while still in the ICE age.\n"); 234 printf("The operating system has halted.\n"); 235 printf("Please press any key to reboot.\n\n"); 236 cngetc(); 237 printf("rebooting...\n"); 238 ixp12x0_reset(); 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 /* Run any shutdown hooks */ 261 doshutdownhooks(); 262 263 pmf_system_shutdown(boothowto); 264 265 /* Make sure IRQ's 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 276 /* all interrupts are disabled */ 277 disable_interrupts(I32_bit); 278 279 ixp12x0_reset(); 280 281 /* ...and if that didn't work, just croak. */ 282 printf("RESET FAILED!\n"); 283 for (;;); 284} 285 286/* Static device mappings. */ 287static const struct pmap_devmap ixm1200_devmap[] = { 288 /* StrongARM System and Peripheral Registers */ 289 { 290 IXP12X0_SYS_VBASE, 291 IXP12X0_SYS_HWBASE, 292 IXP12X0_SYS_SIZE, 293 VM_PROT_READ|VM_PROT_WRITE, 294 PTE_NOCACHE, 295 }, 296 /* PCI Registers Accessible Through StrongARM Core */ 297 { 298 IXP12X0_PCI_VBASE, IXP12X0_PCI_HWBASE, 299 IXP12X0_PCI_SIZE, 300 VM_PROT_READ|VM_PROT_WRITE, 301 PTE_NOCACHE, 302 }, 303 /* PCI Registers Accessible Through I/O Cycle Access */ 304 { 305 IXP12X0_PCI_IO_VBASE, IXP12X0_PCI_IO_HWBASE, 306 IXP12X0_PCI_IO_SIZE, 307 VM_PROT_READ|VM_PROT_WRITE, 308 PTE_NOCACHE, 309 }, 310 /* PCI Type0 Configuration Space */ 311 { 312 IXP12X0_PCI_TYPE0_VBASE, IXP12X0_PCI_TYPE0_HWBASE, 313 IXP12X0_PCI_TYPE0_SIZE, 314 VM_PROT_READ|VM_PROT_WRITE, 315 PTE_NOCACHE, 316 }, 317 /* PCI Type1 Configuration Space */ 318 { 319 IXP12X0_PCI_TYPE1_VBASE, IXP12X0_PCI_TYPE1_HWBASE, 320 IXP12X0_PCI_TYPE1_SIZE, 321 VM_PROT_READ|VM_PROT_WRITE, 322 PTE_NOCACHE, 323 }, 324 { 325 0, 326 0, 327 0, 328 0, 329 0 330 }, 331}; 332 333/* 334 * Initial entry point on startup. This gets called before main() is 335 * entered. 336 * It should be responsible for setting up everything that must be 337 * in place when main is called. 338 * This includes 339 * Taking a copy of the boot configuration structure. 340 * Initialising the physical console so characters can be printed. 341 * Setting up page tables for the kernel 342 * Relocating the kernel to the bottom of physical memory 343 */ 344u_int 345initarm(void *arg) 346{ 347 int loop; 348 int loop1; 349 u_int kerneldatasize, symbolsize; 350 vaddr_t l1pagetable; 351 vaddr_t freemempos; 352#if NKSYMS || defined(DDB) || defined(MODULAR) 353 Elf_Shdr *sh; 354#endif 355 356 /* 357 * Since we map v0xf0000000 == p0x90000000, it's possible for 358 * us to initialize the console now. 359 */ 360 consinit(); 361 362#ifdef VERBOSE_INIT_ARM 363 /* Talk to the user */ 364 printf("\nNetBSD/evbarm (IXM1200) booting ...\n"); 365#endif 366 367 /* 368 * Heads up ... Setup the CPU / MMU / TLB functions 369 */ 370 if (set_cpufuncs()) 371 panic("CPU not recognized!"); 372 373 /* XXX overwrite bootconfig to hardcoded values */ 374 bootconfig.dram[0].address = 0xc0000000; 375 bootconfig.dram[0].pages = 0x10000000 / PAGE_SIZE; /* SDRAM 256MB */ 376 bootconfig.dramblocks = 1; 377 378 kerneldatasize = (u_int32_t)&end - (u_int32_t)KERNEL_TEXT_BASE; 379 380 symbolsize = 0; 381 382#ifdef PMAP_DEBUG 383 pmap_debug(-1); 384#endif 385 386#if NKSYMS || defined(DDB) || defined(MODULAR) 387 if (! memcmp(&end, "\177ELF", 4)) { 388 sh = (Elf_Shdr *)((char *)&end + ((Elf_Ehdr *)&end)->e_shoff); 389 loop = ((Elf_Ehdr *)&end)->e_shnum; 390 for(; loop; loop--, sh++) 391 if (sh->sh_offset > 0 && 392 (sh->sh_offset + sh->sh_size) > symbolsize) 393 symbolsize = sh->sh_offset + sh->sh_size; 394 } 395#endif 396#ifdef VERBOSE_INIT_ARM 397 printf("kernsize=0x%x\n", kerneldatasize); 398#endif 399 kerneldatasize += symbolsize; 400 kerneldatasize = ((kerneldatasize - 1) & ~(PAGE_SIZE * 4 - 1)) + PAGE_SIZE * 8; 401 402 /* 403 * Set up the variables that define the availablilty of physcial 404 * memory 405 */ 406 physical_start = bootconfig.dram[0].address; 407 physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE); 408 409 physical_freestart = physical_start 410 + (KERNEL_TEXT_BASE - KERNEL_BASE) + kerneldatasize; 411 physical_freeend = physical_end; 412 413 physmem = (physical_end - physical_start) / PAGE_SIZE; 414 415 freemempos = 0xc0000000; 416 417#ifdef VERBOSE_INIT_ARM 418 printf("Allocating page tables\n"); 419#endif 420 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE; 421 422#ifdef VERBOSE_INIT_ARM 423 printf("CP15 Register1 = 0x%08x\n", cpu_get_control()); 424 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n", 425 physical_freestart, free_pages, free_pages); 426 printf("physical_start = 0x%08lx, physical_end = 0x%08lx\n", 427 physical_start, physical_end); 428#endif 429 430 /* Define a macro to simplify memory allocation */ 431#define valloc_pages(var, np) \ 432 alloc_pages((var).pv_pa, (np)); \ 433 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start; 434#define alloc_pages(var, np) \ 435 (var) = freemempos; \ 436 memset((char *)(var), 0, ((np) * PAGE_SIZE)); \ 437 freemempos += (np) * PAGE_SIZE; 438 439 loop1 = 0; 440 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) { 441 /* Are we 16KB aligned for an L1 ? */ 442 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0 443 && kernel_l1pt.pv_pa == 0) { 444 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE); 445 } else { 446 valloc_pages(kernel_pt_table[loop1], 447 L2_TABLE_SIZE / PAGE_SIZE); 448 ++loop1; 449 } 450 } 451 452#ifdef DIAGNOSTIC 453 /* This should never be able to happen but better confirm that. */ 454 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0) 455 panic("initarm: Failed to align the kernel page directory"); 456#endif 457 458 /* 459 * Allocate a page for the system page mapped to V0x00000000 460 * This page will just contain the system vectors and can be 461 * shared by all processes. 462 */ 463 alloc_pages(systempage.pv_pa, 1); 464 465 /* Allocate stacks for all modes */ 466 valloc_pages(irqstack, IRQ_STACK_SIZE); 467 valloc_pages(abtstack, ABT_STACK_SIZE); 468 valloc_pages(undstack, UND_STACK_SIZE); 469 valloc_pages(kernelstack, UPAGES); 470 471#ifdef VERBOSE_INIT_ARM 472 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa, irqstack.pv_va); 473 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa, abtstack.pv_va); 474 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa, undstack.pv_va); 475 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa, kernelstack.pv_va); 476#endif 477 478 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE); 479 480#ifdef CPU_IXP12X0 481 /* 482 * XXX totally stuffed hack to work round problems introduced 483 * in recent versions of the pmap code. Due to the calls used there 484 * we cannot allocate virtual memory during bootstrap. 485 */ 486 for(;;) { 487 alloc_pages(ixp12x0_cc_base, 1); 488 if (! (ixp12x0_cc_base & (CPU_IXP12X0_CACHE_CLEAN_SIZE - 1))) 489 break; 490 } 491 { 492 vaddr_t dummy; 493 alloc_pages(dummy, CPU_IXP12X0_CACHE_CLEAN_SIZE / PAGE_SIZE - 1); 494 } 495 ixp12x0_cache_clean_addr = ixp12x0_cc_base; 496 ixp12x0_cache_clean_size = CPU_IXP12X0_CACHE_CLEAN_SIZE / 2; 497#endif /* CPU_IXP12X0 */ 498 499#ifdef VERBOSE_INIT_ARM 500 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa); 501#endif 502 503 /* 504 * Now we start construction of the L1 page table 505 * We start by mapping the L2 page tables into the L1. 506 * This means that we can replace L1 mappings later on if necessary 507 */ 508 l1pagetable = kernel_l1pt.pv_pa; 509 510 /* Map the L2 pages tables in the L1 page table */ 511 pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1), 512 &kernel_pt_table[KERNEL_PT_SYS]); 513 514 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++) 515 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000, 516 &kernel_pt_table[KERNEL_PT_KERNEL + loop]); 517 518 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++) 519 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000, 520 &kernel_pt_table[KERNEL_PT_VMDATA + loop]); 521 522 /* update the top of the kernel VM */ 523 pmap_curmaxkvaddr = 524 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000); 525 526 pmap_link_l2pt(l1pagetable, IXP12X0_IO_VBASE, 527 &kernel_pt_table[KERNEL_PT_IO]); 528 529#ifdef VERBOSE_INIT_ARM 530 printf("Mapping kernel\n"); 531#endif 532 533#if XXX 534 /* Now we fill in the L2 pagetable for the kernel code/data */ 535 { 536 extern char etext[], _end[]; 537 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE; 538 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE; 539 u_int logical; 540 541 textsize = (textsize + PGOFSET) & ~PGOFSET; 542 totalsize = (totalsize + PGOFSET) & ~PGOFSET; 543 544 logical = 0x00200000; /* offset of kernel in RAM */ 545 546 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical, 547 physical_start + logical, textsize, 548 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 549 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical, 550 physical_start + logical, totalsize - textsize, 551 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 552 } 553#else 554 { 555 pmap_map_chunk(l1pagetable, KERNEL_TEXT_BASE, 556 KERNEL_TEXT_BASE, kerneldatasize, 557 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 558 } 559#endif 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 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) { 579 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va, 580 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE, 581 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE); 582 } 583 584 /* Map the vector page. */ 585 pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa, 586 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 587 588#ifdef VERBOSE_INIT_ARM 589 printf("systempage (vector page): p0x%08lx v0x%08lx\n", 590 systempage.pv_pa, vector_page); 591#endif 592 593 /* Map the statically mapped devices. */ 594 pmap_devmap_bootstrap(l1pagetable, ixm1200_devmap); 595 596#ifdef VERBOSE_INIT_ARM 597 printf("done.\n"); 598#endif 599 600 /* 601 * Map the Dcache Flush page. 602 * Hw Ref Manual 3.2.4.5 Software Dcache Flush 603 */ 604 pmap_map_chunk(l1pagetable, ixp12x0_cache_clean_addr, 0xe0000000, 605 CPU_IXP12X0_CACHE_CLEAN_SIZE, VM_PROT_READ, PTE_CACHE); 606 607 /* 608 * Now we have the real page tables in place so we can switch to them. 609 * Once this is done we will be running with the REAL kernel page 610 * tables. 611 */ 612 613 /* Switch tables */ 614 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT); 615 cpu_setttb(kernel_l1pt.pv_pa); 616 cpu_tlb_flushID(); 617 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)); 618 619 /* 620 * Moved here from cpu_startup() as data_abort_handler() references 621 * this during init 622 */ 623 uvm_lwp_setuarea(&lwp0, kernelstack.pv_va); 624 625 /* 626 * We must now clean the cache again.... 627 * Cleaning may be done by reading new data to displace any 628 * dirty data in the cache. This will have happened in cpu_setttb() 629 * but since we are boot strapping the addresses used for the read 630 * may have just been remapped and thus the cache could be out 631 * of sync. A re-clean after the switch will cure this. 632 * After booting there are no gross reloations of the kernel thus 633 * this problem will not occur after initarm(). 634 */ 635 cpu_idcache_wbinv_all(); 636 637 arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL); 638 639 /* 640 * Pages were allocated during the secondary bootstrap for the 641 * stacks for different CPU modes. 642 * We must now set the r13 registers in the different CPU modes to 643 * point to these stacks. 644 * Since the ARM stacks use STMFD etc. we must set r13 to the top end 645 * of the stack memory. 646 */ 647#ifdef VERBOSE_INIT_ARM 648 printf("init subsystems: stacks "); 649#endif 650 651 set_stackptr(PSR_IRQ32_MODE, 652 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE); 653 set_stackptr(PSR_ABT32_MODE, 654 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE); 655 set_stackptr(PSR_UND32_MODE, 656 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE); 657#ifdef PMAP_DEBUG 658 if (pmap_debug_level >= 0) 659 printf("kstack V%08lx P%08lx\n", kernelstack.pv_va, 660 kernelstack.pv_pa); 661#endif /* PMAP_DEBUG */ 662 663 /* 664 * Well we should set a data abort handler. 665 * Once things get going this will change as we will need a proper 666 * handler. Until then we will use a handler that just panics but 667 * tells us why. 668 * Initialisation of the vetcors will just panic on a data abort. 669 * This just fills in a slightly better one. 670 */ 671#ifdef VERBOSE_INIT_ARM 672 printf("vectors "); 673#endif 674 data_abort_handler_address = (u_int)data_abort_handler; 675 prefetch_abort_handler_address = (u_int)prefetch_abort_handler; 676 undefined_handler_address = (u_int)undefinedinstruction_bounce; 677#ifdef VERBOSE_INIT_ARM 678 printf("\ndata_abort_handler_address = %08x\n", data_abort_handler_address); 679 printf("prefetch_abort_handler_address = %08x\n", prefetch_abort_handler_address); 680 printf("undefined_handler_address = %08x\n", undefined_handler_address); 681#endif 682 683 /* Initialise the undefined instruction handlers */ 684#ifdef VERBOSE_INIT_ARM 685 printf("undefined "); 686#endif 687 undefined_init(); 688 689 /* Load memory into UVM. */ 690#ifdef VERBOSE_INIT_ARM 691 printf("page "); 692#endif 693 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */ 694 uvm_page_physload(atop(physical_freestart), atop(physical_freeend), 695 atop(physical_freestart), atop(physical_freeend), 696 VM_FREELIST_DEFAULT); 697 698 /* Boot strap pmap telling it where the kernel page table is */ 699#ifdef VERBOSE_INIT_ARM 700 printf("pmap "); 701#endif 702 pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE); 703 704 /* Setup the IRQ system */ 705#ifdef VERBOSE_INIT_ARM 706 printf("irq "); 707#endif 708 ixp12x0_intr_init(); 709 710#ifdef VERBOSE_INIT_ARM 711 printf("done.\n"); 712#endif 713 714#ifdef VERBOSE_INIT_ARM 715 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n", 716 physical_freestart, free_pages, free_pages); 717 printf("freemempos=%08lx\n", freemempos); 718 printf("switching to new L1 page table @%#lx... \n", kernel_l1pt.pv_pa); 719#endif 720 721 consinit(); 722#ifdef VERBOSE_INIT_ARM 723 printf("consinit \n"); 724#endif 725 726 ixdp_ixp12x0_cc_setup(); 727 728#ifdef VERBOSE_INIT_ARM 729 printf("bootstrap done.\n"); 730#endif 731 732#if NKSYMS || defined(DDB) || defined(MODULAR) 733 ksyms_addsyms_elf(symbolsize, ((int *)&end), ((char *)&end) + symbolsize); 734#endif 735 736#ifdef DDB 737 db_machine_init(); 738 if (boothowto & RB_KDB) 739 Debugger(); 740#endif 741 742 /* We return the new stack pointer address */ 743 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP); 744} 745 746void 747consinit(void) 748{ 749 static int consinit_called = 0; 750 751 if (consinit_called != 0) 752 return; 753 754 consinit_called = 1; 755 756 pmap_devmap_register(ixm1200_devmap); 757 758 if (ixpcomcnattach(&ixp12x0_bs_tag, 759 IXPCOM_UART_HWBASE, IXPCOM_UART_VBASE, 760 CONSPEED, CONMODE)) 761 panic("can't init serial console @%lx", IXPCOM_UART_HWBASE); 762} 763 764/* 765 * For optimal cache cleaning we need two 16K banks of 766 * virtual address space that NOTHING else will access 767 * and then we alternate the cache cleaning between the 768 * two banks. 769 * The cache cleaning code requires requires 2 banks aligned 770 * on total size boundry so the banks can be alternated by 771 * eorring the size bit (assumes the bank size is a power of 2) 772 */ 773void 774ixdp_ixp12x0_cc_setup(void) 775{ 776 int loop; 777 paddr_t kaddr; 778 pt_entry_t *pte; 779 780 (void) pmap_extract(pmap_kernel(), KERNEL_TEXT_BASE, &kaddr); 781 for (loop = 0; loop < CPU_IXP12X0_CACHE_CLEAN_SIZE; loop += PAGE_SIZE) { 782 pte = vtopte(ixp12x0_cc_base + loop); 783 *pte = L2_S_PROTO | kaddr | 784 L2_S_PROT(PTE_KERNEL, VM_PROT_READ) | pte_l2_s_cache_mode; 785 PTE_SYNC(pte); 786 } 787 ixp12x0_cache_clean_addr = ixp12x0_cc_base; 788 ixp12x0_cache_clean_size = CPU_IXP12X0_CACHE_CLEAN_SIZE / 2; 789} 790