1/* $NetBSD: iq80310_machdep.c,v 1.79 2011/06/30 20:09:25 wiz Exp $ */ 2 3/* 4 * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc. 5 * All rights reserved. 6 * 7 * Written by Jason R. Thorpe for Wasabi Systems, Inc. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed for the NetBSD Project by 20 * Wasabi Systems, Inc. 21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22 * or promote products derived from this software without specific prior 23 * written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 * POSSIBILITY OF SUCH DAMAGE. 36 */ 37 38/* 39 * Copyright (c) 1997,1998 Mark Brinicombe. 40 * Copyright (c) 1997,1998 Causality Limited. 41 * All rights reserved. 42 * 43 * Redistribution and use in source and binary forms, with or without 44 * modification, are permitted provided that the following conditions 45 * are met: 46 * 1. Redistributions of source code must retain the above copyright 47 * notice, this list of conditions and the following disclaimer. 48 * 2. Redistributions in binary form must reproduce the above copyright 49 * notice, this list of conditions and the following disclaimer in the 50 * documentation and/or other materials provided with the distribution. 51 * 3. All advertising materials mentioning features or use of this software 52 * must display the following acknowledgement: 53 * This product includes software developed by Mark Brinicombe 54 * for the NetBSD Project. 55 * 4. The name of the company nor the name of the author may be used to 56 * endorse or promote products derived from this software without specific 57 * prior written permission. 58 * 59 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 60 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 61 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 62 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 63 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 64 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 65 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 69 * SUCH DAMAGE. 70 * 71 * Machine dependent functions for kernel setup for Intel IQ80310 evaluation 72 * boards using RedBoot firmware. 73 */ 74 75#include <sys/cdefs.h> 76__KERNEL_RCSID(0, "$NetBSD: iq80310_machdep.c,v 1.79 2011/06/30 20:09:25 wiz Exp $"); 77 78#include "opt_ddb.h" 79#include "opt_pmap_debug.h" 80 81#include <sys/param.h> 82#include <sys/device.h> 83#include <sys/systm.h> 84#include <sys/kernel.h> 85#include <sys/exec.h> 86#include <sys/proc.h> 87#include <sys/msgbuf.h> 88#include <sys/reboot.h> 89#include <sys/termios.h> 90#include <sys/ksyms.h> 91 92#include <uvm/uvm_extern.h> 93 94#include <dev/cons.h> 95 96#include <machine/db_machdep.h> 97#include <ddb/db_sym.h> 98#include <ddb/db_extern.h> 99 100#include <machine/bootconfig.h> 101#include <sys/bus.h> 102#include <machine/cpu.h> 103#include <machine/frame.h> 104#include <arm/undefined.h> 105 106#include <arm/arm32/machdep.h> 107 108#include <arm/xscale/i80312reg.h> 109#include <arm/xscale/i80312var.h> 110 111#include <dev/pci/ppbreg.h> 112 113#include <evbarm/iq80310/iq80310reg.h> 114#include <evbarm/iq80310/iq80310var.h> 115#include <evbarm/iq80310/obiovar.h> 116 117#include "ksyms.h" 118 119/* Kernel text starts 2MB in from the bottom of the kernel address space. */ 120#define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000) 121#define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000) 122 123/* 124 * The range 0xc1000000 - 0xccffffff is available for kernel VM space 125 * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff 126 */ 127#define KERNEL_VM_SIZE 0x0C000000 128 129/* 130 * Address to call from cpu_reset() to reset the machine. 131 * This is machine architecture dependent as it varies depending 132 * on where the ROM appears when you turn the MMU off. 133 */ 134 135u_int cpu_reset_address = 0; 136 137/* Define various stack sizes in pages */ 138#define IRQ_STACK_SIZE 1 139#define ABT_STACK_SIZE 1 140#define UND_STACK_SIZE 1 141 142BootConfig bootconfig; /* Boot config storage */ 143char *boot_args = NULL; 144char *boot_file = NULL; 145 146vm_offset_t physical_start; 147vm_offset_t physical_freestart; 148vm_offset_t physical_freeend; 149vm_offset_t physical_end; 150u_int free_pages; 151 152/*int debug_flags;*/ 153#ifndef PMAP_STATIC_L1S 154int max_processes = 64; /* Default number */ 155#endif /* !PMAP_STATIC_L1S */ 156 157/* Physical and virtual addresses for some global pages */ 158pv_addr_t irqstack; 159pv_addr_t undstack; 160pv_addr_t abtstack; 161pv_addr_t kernelstack; 162pv_addr_t minidataclean; 163 164vm_offset_t msgbufphys; 165 166extern u_int data_abort_handler_address; 167extern u_int prefetch_abort_handler_address; 168extern u_int undefined_handler_address; 169 170#ifdef PMAP_DEBUG 171extern int pmap_debug_level; 172#endif 173 174#define KERNEL_PT_SYS 0 /* L2 table for mapping zero page */ 175 176#define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */ 177#define KERNEL_PT_KERNEL_NUM 4 178 179 /* L2 table for mapping i80312 */ 180#define KERNEL_PT_IOPXS (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM) 181 182 /* L2 tables for mapping kernel VM */ 183#define KERNEL_PT_VMDATA (KERNEL_PT_IOPXS + 1) 184#define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */ 185#define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM) 186 187pv_addr_t kernel_pt_table[NUM_KERNEL_PTS]; 188 189/* Prototypes */ 190 191void consinit(void); 192 193#include "com.h" 194#if NCOM > 0 195#include <dev/ic/comreg.h> 196#include <dev/ic/comvar.h> 197#endif 198 199/* 200 * Define the default console speed for the board. This is generally 201 * what the firmware provided with the board defaults to. 202 */ 203#ifndef CONSPEED 204#define CONSPEED B115200 205#endif /* ! CONSPEED */ 206 207#ifndef CONUNIT 208#define CONUNIT 0 209#endif 210 211#ifndef CONMODE 212#define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ 213#endif 214 215int comcnspeed = CONSPEED; 216int comcnmode = CONMODE; 217int comcnunit = CONUNIT; 218 219/* 220 * void cpu_reboot(int howto, char *bootstr) 221 * 222 * Reboots the system 223 * 224 * Deal with any syncing, unmounting, dumping and shutdown hooks, 225 * then reset the CPU. 226 */ 227void 228cpu_reboot(int howto, char *bootstr) 229{ 230 231 /* 232 * If we are still cold then hit the air brakes 233 * and crash to earth fast 234 */ 235 if (cold) { 236 doshutdownhooks(); 237 pmf_system_shutdown(boothowto); 238 printf("The operating system has halted.\n"); 239 printf("Please press any key to reboot.\n\n"); 240 cngetc(); 241 printf("rebooting...\n"); 242 cpu_reset(); 243 /*NOTREACHED*/ 244 } 245 246 /* Disable console buffering */ 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 251 * unmount. It looks like syslogd is getting woken up only to find 252 * that it cannot page part of the binary in as the filesystem has 253 * been unmounted. 254 */ 255 if (!(howto & RB_NOSYNC)) 256 bootsync(); 257 258 /* Say NO to interrupts */ 259 splhigh(); 260 261 /* Do a dump if requested. */ 262 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) 263 dumpsys(); 264 265 /* Run any shutdown hooks */ 266 doshutdownhooks(); 267 268 pmf_system_shutdown(boothowto); 269 270 /* Make sure IRQ's are disabled */ 271 IRQdisable; 272 273 if (howto & RB_HALT) { 274 iq80310_7seg('.', '.'); 275 printf("The operating system has halted.\n"); 276 printf("Please press any key to reboot.\n\n"); 277 cngetc(); 278 } 279 280 printf("rebooting...\n"); 281 cpu_reset(); 282 /*NOTREACHED*/ 283} 284 285/* Static device mappings. */ 286static const struct pmap_devmap iq80310_devmap[] = { 287 /* 288 * Map the on-board devices VA == PA so that we can access them 289 * with the MMU on or off. 290 */ 291 { 292 IQ80310_OBIO_BASE, 293 IQ80310_OBIO_BASE, 294 IQ80310_OBIO_SIZE, 295 VM_PROT_READ|VM_PROT_WRITE, 296 PTE_NOCACHE, 297 }, 298 { 299 IQ80310_PIOW_VBASE, 300 I80312_PCI_XLATE_PIOW_BASE, 301 I80312_PCI_XLATE_IOSIZE, 302 VM_PROT_READ|VM_PROT_WRITE, 303 PTE_NOCACHE, 304 }, 305 { 306 IQ80310_SIOW_VBASE, 307 I80312_PCI_XLATE_SIOW_BASE, 308 I80312_PCI_XLATE_IOSIZE, 309 VM_PROT_READ|VM_PROT_WRITE, 310 PTE_NOCACHE, 311 }, 312 { 313 IQ80310_80312_VBASE, 314 I80312_PMMR_BASE, 315 I80312_PMMR_SIZE, 316 VM_PROT_READ|VM_PROT_WRITE, 317 PTE_NOCACHE, 318 }, 319 320 { 321 0, 322 0, 323 0, 324 0, 325 0, 326 } 327}; 328 329/* 330 * u_int initarm(...) 331 * 332 * Initial entry point on startup. This gets called before main() is 333 * entered. 334 * It should be responsible for setting up everything that must be 335 * in place when main is called. 336 * This includes 337 * Taking a copy of the boot configuration structure. 338 * Initialising the physical console so characters can be printed. 339 * Setting up page tables for the kernel 340 * Relocating the kernel to the bottom of physical memory 341 */ 342u_int 343initarm(void *arg) 344{ 345 extern vaddr_t xscale_cache_clean_addr; 346#ifdef DIAGNOSTIC 347 extern vsize_t xscale_minidata_clean_size; 348#endif 349 int loop; 350 int loop1; 351 u_int l1pagetable; 352 paddr_t memstart; 353 psize_t memsize; 354 355 /* 356 * Clear out the 7-segment display. Whee, the first visual 357 * indication that we're running kernel code. 358 */ 359 iq80310_7seg(' ', ' '); 360 361 /* 362 * Heads up ... Setup the CPU / MMU / TLB functions 363 */ 364 if (set_cpufuncs()) 365 panic("CPU not recognized!"); 366 367 /* Calibrate the delay loop. */ 368 iq80310_calibrate_delay(); 369 370 /* 371 * Since we map the on-board devices VA==PA, and the kernel 372 * is running VA==PA, it's possible for us to initialize 373 * the console now. 374 */ 375 consinit(); 376 377#ifdef VERBOSE_INIT_ARM 378 /* Talk to the user */ 379 printf("\nNetBSD/evbarm (IQ80310) booting ...\n"); 380#endif 381 382 /* 383 * Reset the secondary PCI bus. RedBoot doesn't stop devices 384 * on the PCI bus before handing us control, so we have to 385 * do this. 386 * 387 * XXX This is arguably a bug in RedBoot, and doing this reset 388 * XXX could be problematic in the future if we encounter an 389 * XXX application where the PPB in the i80312 is used as a 390 * XXX PPB. 391 */ 392 { 393 uint32_t reg; 394 395#ifdef VERBOSE_INIT_ARM 396 printf("Resetting secondary PCI bus...\n"); 397#endif 398 reg = bus_space_read_4(&obio_bs_tag, 399 I80312_PMMR_BASE + I80312_PPB_BASE, PPB_REG_BRIDGECONTROL); 400 bus_space_write_4(&obio_bs_tag, 401 I80312_PMMR_BASE + I80312_PPB_BASE, PPB_REG_BRIDGECONTROL, 402 reg | PPB_BC_SECONDARY_RESET); 403 delay(10 * 1000); /* 10ms enough? */ 404 bus_space_write_4(&obio_bs_tag, 405 I80312_PMMR_BASE + I80312_PPB_BASE, PPB_REG_BRIDGECONTROL, 406 reg); 407 } 408 409 /* 410 * We are currently running with the MMU enabled and the 411 * entire address space mapped VA==PA, except for the 412 * first 64M of RAM is also double-mapped at 0xc0000000. 413 * There is an L1 page table at 0xa0004000. 414 */ 415 416 /* 417 * Fetch the SDRAM start/size from the i80312 SDRAM configuration 418 * registers. 419 */ 420 i80312_sdram_bounds(&obio_bs_tag, I80312_PMMR_BASE + I80312_MEM_BASE, 421 &memstart, &memsize); 422 423#ifdef VERBOSE_INIT_ARM 424 printf("initarm: Configuring system ...\n"); 425#endif 426 427 /* Fake bootconfig structure for the benefit of pmap.c */ 428 /* XXX must make the memory description h/w independent */ 429 bootconfig.dramblocks = 1; 430 bootconfig.dram[0].address = memstart; 431 bootconfig.dram[0].pages = memsize / PAGE_SIZE; 432 433 /* 434 * Set up the variables that define the availablilty of 435 * physical memory. For now, we're going to set 436 * physical_freestart to 0xa0200000 (where the kernel 437 * was loaded), and allocate the memory we need downwards. 438 * If we get too close to the L1 table that we set up, we 439 * will panic. We will update physical_freestart and 440 * physical_freeend later to reflect what pmap_bootstrap() 441 * wants to see. 442 * 443 * XXX pmap_bootstrap() needs an enema. 444 */ 445 physical_start = bootconfig.dram[0].address; 446 physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE); 447 448 physical_freestart = 0xa0009000UL; 449 physical_freeend = 0xa0200000UL; 450 451 physmem = (physical_end - physical_start) / PAGE_SIZE; 452 453#ifdef VERBOSE_INIT_ARM 454 /* Tell the user about the memory */ 455 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem, 456 physical_start, physical_end - 1); 457#endif 458 459 /* 460 * Okay, the kernel starts 2MB in from the bottom of physical 461 * memory. We are going to allocate our bootstrap pages downwards 462 * from there. 463 * 464 * We need to allocate some fixed page tables to get the kernel 465 * going. We allocate one page directory and a number of page 466 * tables and store the physical addresses in the kernel_pt_table 467 * array. 468 * 469 * The kernel page directory must be on a 16K boundary. The page 470 * tables must be on 4K boundaries. What we do is allocate the 471 * page directory on the first 16K boundary that we encounter, and 472 * the page tables on 4K boundaries otherwise. Since we allocate 473 * at least 3 L2 page tables, we are guaranteed to encounter at 474 * least one 16K aligned region. 475 */ 476 477#ifdef VERBOSE_INIT_ARM 478 printf("Allocating page tables\n"); 479#endif 480 481 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE; 482 483#ifdef VERBOSE_INIT_ARM 484 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n", 485 physical_freestart, free_pages, free_pages); 486#endif 487 488 /* Define a macro to simplify memory allocation */ 489#define valloc_pages(var, np) \ 490 alloc_pages((var).pv_pa, (np)); \ 491 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start; 492 493#define alloc_pages(var, np) \ 494 physical_freeend -= ((np) * PAGE_SIZE); \ 495 if (physical_freeend < physical_freestart) \ 496 panic("initarm: out of memory"); \ 497 (var) = physical_freeend; \ 498 free_pages -= (np); \ 499 memset((char *)(var), 0, ((np) * PAGE_SIZE)); 500 501 loop1 = 0; 502 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) { 503 /* Are we 16KB aligned for an L1 ? */ 504 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0 505 && kernel_l1pt.pv_pa == 0) { 506 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE); 507 } else { 508 valloc_pages(kernel_pt_table[loop1], 509 L2_TABLE_SIZE / PAGE_SIZE); 510 ++loop1; 511 } 512 } 513 514 /* This should never be able to happen but better confirm that. */ 515 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0) 516 panic("initarm: Failed to align the kernel page directory"); 517 518 /* 519 * Allocate a page for the system page mapped to V0x00000000 520 * This page will just contain the system vectors and can be 521 * shared by all processes. 522 */ 523 alloc_pages(systempage.pv_pa, 1); 524 525 /* Allocate stacks for all modes */ 526 valloc_pages(irqstack, IRQ_STACK_SIZE); 527 valloc_pages(abtstack, ABT_STACK_SIZE); 528 valloc_pages(undstack, UND_STACK_SIZE); 529 valloc_pages(kernelstack, UPAGES); 530 531 /* Allocate enough pages for cleaning the Mini-Data cache. */ 532 KASSERT(xscale_minidata_clean_size <= PAGE_SIZE); 533 valloc_pages(minidataclean, 1); 534 535#ifdef VERBOSE_INIT_ARM 536 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa, 537 irqstack.pv_va); 538 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa, 539 abtstack.pv_va); 540 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa, 541 undstack.pv_va); 542 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa, 543 kernelstack.pv_va); 544#endif 545 546 /* 547 * XXX Defer this to later so that we can reclaim the memory 548 * XXX used by the RedBoot page tables. 549 */ 550 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE); 551 552 /* 553 * Ok we have allocated physical pages for the primary kernel 554 * page tables 555 */ 556 557#ifdef VERBOSE_INIT_ARM 558 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa); 559#endif 560 561 /* 562 * Now we start construction of the L1 page table 563 * We start by mapping the L2 page tables into the L1. 564 * This means that we can replace L1 mappings later on if necessary 565 */ 566 l1pagetable = kernel_l1pt.pv_pa; 567 568 /* Map the L2 pages tables in the L1 page table */ 569 pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1), 570 &kernel_pt_table[KERNEL_PT_SYS]); 571 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++) 572 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000, 573 &kernel_pt_table[KERNEL_PT_KERNEL + loop]); 574 pmap_link_l2pt(l1pagetable, IQ80310_IOPXS_VBASE, 575 &kernel_pt_table[KERNEL_PT_IOPXS]); 576 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++) 577 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000, 578 &kernel_pt_table[KERNEL_PT_VMDATA + loop]); 579 580 /* update the top of the kernel VM */ 581 pmap_curmaxkvaddr = 582 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000); 583 584#ifdef VERBOSE_INIT_ARM 585 printf("Mapping kernel\n"); 586#endif 587 588 /* Now we fill in the L2 pagetable for the kernel static code/data */ 589 { 590 extern char etext[], _end[]; 591 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE; 592 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE; 593 u_int logical; 594 595 textsize = (textsize + PGOFSET) & ~PGOFSET; 596 totalsize = (totalsize + PGOFSET) & ~PGOFSET; 597 598 logical = 0x00200000; /* offset of kernel in RAM */ 599 600 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical, 601 physical_start + logical, textsize, 602 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 603 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical, 604 physical_start + logical, totalsize - textsize, 605 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 606 } 607 608#ifdef VERBOSE_INIT_ARM 609 printf("Constructing L2 page tables\n"); 610#endif 611 612 /* Map the stack pages */ 613 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa, 614 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 615 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa, 616 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 617 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa, 618 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 619 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa, 620 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 621 622 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa, 623 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE); 624 625 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) { 626 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va, 627 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE, 628 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE); 629 } 630 631 /* Map the Mini-Data cache clean area. */ 632 xscale_setup_minidata(l1pagetable, minidataclean.pv_va, 633 minidataclean.pv_pa); 634 635 /* Map the vector page. */ 636 pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa, 637 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 638 639 /* Map the statically mapped devices. */ 640 pmap_devmap_bootstrap(l1pagetable, iq80310_devmap); 641 642 /* 643 * Give the XScale global cache clean code an appropriately 644 * sized chunk of unmapped VA space starting at 0xff000000 645 * (our device mappings end before this address). 646 */ 647 xscale_cache_clean_addr = 0xff000000U; 648 649 /* 650 * Now we have the real page tables in place so we can switch to them. 651 * Once this is done we will be running with the REAL kernel page 652 * tables. 653 */ 654 655 /* 656 * Update the physical_freestart/physical_freeend/free_pages 657 * variables. 658 */ 659 { 660 extern char _end[]; 661 662 physical_freestart = physical_start + 663 (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) - 664 KERNEL_BASE); 665 physical_freeend = physical_end; 666 free_pages = 667 (physical_freeend - physical_freestart) / PAGE_SIZE; 668 } 669 670 /* Switch tables */ 671#ifdef VERBOSE_INIT_ARM 672 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n", 673 physical_freestart, free_pages, free_pages); 674 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa); 675#endif 676 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT); 677 cpu_setttb(kernel_l1pt.pv_pa); 678 cpu_tlb_flushID(); 679 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)); 680 681 /* 682 * Moved from cpu_startup() as data_abort_handler() references 683 * this during uvm init 684 */ 685 uvm_lwp_setuarea(&lwp0, kernelstack.pv_va); 686 687#ifdef VERBOSE_INIT_ARM 688 printf("done!\n"); 689#endif 690 691#ifdef VERBOSE_INIT_ARM 692 printf("bootstrap done.\n"); 693#endif 694 695 arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL); 696 697 /* 698 * Pages were allocated during the secondary bootstrap for the 699 * stacks for different CPU modes. 700 * We must now set the r13 registers in the different CPU modes to 701 * point to these stacks. 702 * Since the ARM stacks use STMFD etc. we must set r13 to the top end 703 * of the stack memory. 704 */ 705#ifdef VERBOSE_INIT_ARM 706 printf("init subsystems: stacks "); 707#endif 708 709 set_stackptr(PSR_IRQ32_MODE, 710 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE); 711 set_stackptr(PSR_ABT32_MODE, 712 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE); 713 set_stackptr(PSR_UND32_MODE, 714 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE); 715 716 /* 717 * Well we should set a data abort handler. 718 * Once things get going this will change as we will need a proper 719 * handler. 720 * Until then we will use a handler that just panics but tells us 721 * why. 722 * Initialisation of the vectors will just panic on a data abort. 723 * This just fills in a slightly better one. 724 */ 725#ifdef VERBOSE_INIT_ARM 726 printf("vectors "); 727#endif 728 data_abort_handler_address = (u_int)data_abort_handler; 729 prefetch_abort_handler_address = (u_int)prefetch_abort_handler; 730 undefined_handler_address = (u_int)undefinedinstruction_bounce; 731 732 /* Initialise the undefined instruction handlers */ 733#ifdef VERBOSE_INIT_ARM 734 printf("undefined "); 735#endif 736 undefined_init(); 737 738 /* Load memory into UVM. */ 739#ifdef VERBOSE_INIT_ARM 740 printf("page "); 741#endif 742 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */ 743 uvm_page_physload(atop(physical_freestart), atop(physical_freeend), 744 atop(physical_freestart), atop(physical_freeend), 745 VM_FREELIST_DEFAULT); 746 747 /* Boot strap pmap telling it where the kernel page table is */ 748#ifdef VERBOSE_INIT_ARM 749 printf("pmap "); 750#endif 751 pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE); 752 753 /* Setup the IRQ system */ 754#ifdef VERBOSE_INIT_ARM 755 printf("irq "); 756#endif 757 iq80310_intr_init(); 758 759#ifdef VERBOSE_INIT_ARM 760 printf("done.\n"); 761#endif 762 763#ifdef DDB 764 db_machine_init(); 765 if (boothowto & RB_KDB) 766 Debugger(); 767#endif 768 769 /* We return the new stack pointer address */ 770 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP); 771} 772 773void 774consinit(void) 775{ 776 static const bus_addr_t comcnaddrs[] = { 777 IQ80310_UART2, /* com0 (J9) */ 778 IQ80310_UART1, /* com1 (J10) */ 779 }; 780 static int consinit_called; 781 782 if (consinit_called != 0) 783 return; 784 785 consinit_called = 1; 786 787 /* 788 * Console devices are mapped VA==PA. Our devmap reflects 789 * this, so register it now so drivers can map the console 790 * device. 791 */ 792 pmap_devmap_register(iq80310_devmap); 793 794#if NCOM > 0 795 if (comcnattach(&obio_bs_tag, comcnaddrs[comcnunit], comcnspeed, 796 COM_FREQ, COM_TYPE_NORMAL, comcnmode)) 797 panic("can't init serial console @%lx", comcnaddrs[comcnunit]); 798#else 799 panic("serial console @%lx not configured", comcnaddrs[comcnunit]); 800#endif 801} 802