1 /* $NetBSD: iq80321_machdep.c,v 1.54 2013/08/18 15:58:20 matt Exp $ */ 2 3 /* 4 * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc. 5 * All rights reserved. 6 * 7 * Written by Jason R. Thorpe and Steve C. Woodford 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 IQ80321 evaluation 72 * boards using RedBoot firmware. 73 */ 74 75 #include <sys/cdefs.h> 76 __KERNEL_RCSID(0, "$NetBSD: iq80321_machdep.c,v 1.54 2013/08/18 15:58:20 matt Exp $"); 77 78 #include "opt_ddb.h" 79 #include "opt_kgdb.h" 80 #include "opt_pmap_debug.h" 81 82 #include <sys/param.h> 83 #include <sys/device.h> 84 #include <sys/systm.h> 85 #include <sys/kernel.h> 86 #include <sys/exec.h> 87 #include <sys/proc.h> 88 #include <sys/msgbuf.h> 89 #include <sys/reboot.h> 90 #include <sys/termios.h> 91 #include <sys/ksyms.h> 92 #include <sys/cpu.h> 93 #include <sys/bus.h> 94 95 #include <uvm/uvm_extern.h> 96 97 #include <dev/cons.h> 98 99 #include <dev/pci/ppbreg.h> 100 101 #include <machine/db_machdep.h> 102 #include <ddb/db_sym.h> 103 #include <ddb/db_extern.h> 104 105 #include <machine/bootconfig.h> 106 107 #include <arm/locore.h> 108 #include <arm/undefined.h> 109 110 #include <arm/arm32/machdep.h> 111 112 #include <arm/xscale/i80321reg.h> 113 #include <arm/xscale/i80321var.h> 114 115 #include <evbarm/iq80321/iq80321reg.h> 116 #include <evbarm/iq80321/iq80321var.h> 117 #include <evbarm/iq80321/obiovar.h> 118 119 #include "ksyms.h" 120 121 /* Kernel text starts 2MB in from the bottom of the kernel address space. */ 122 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000) 123 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000) 124 125 /* 126 * The range 0xc1000000 - 0xccffffff is available for kernel VM space 127 * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff 128 */ 129 #define KERNEL_VM_SIZE 0x0C000000 130 131 BootConfig bootconfig; /* Boot config storage */ 132 char *boot_args = NULL; 133 char *boot_file = NULL; 134 135 vm_offset_t physical_start; 136 vm_offset_t physical_freestart; 137 vm_offset_t physical_freeend; 138 vm_offset_t physical_end; 139 u_int free_pages; 140 141 /*int debug_flags;*/ 142 #ifndef PMAP_STATIC_L1S 143 int max_processes = 64; /* Default number */ 144 #endif /* !PMAP_STATIC_L1S */ 145 146 /* Physical and virtual addresses for some global pages */ 147 pv_addr_t minidataclean; 148 149 vm_offset_t msgbufphys; 150 151 #ifdef PMAP_DEBUG 152 extern int pmap_debug_level; 153 #endif 154 155 #define KERNEL_PT_SYS 0 /* L2 table for mapping zero page */ 156 157 #define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */ 158 #define KERNEL_PT_KERNEL_NUM 4 159 160 /* L2 table for mapping i80321 */ 161 #define KERNEL_PT_IOPXS (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM) 162 163 /* L2 tables for mapping kernel VM */ 164 #define KERNEL_PT_VMDATA (KERNEL_PT_IOPXS + 1) 165 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */ 166 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM) 167 168 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS]; 169 170 /* Prototypes */ 171 172 void consinit(void); 173 174 #include "com.h" 175 #if NCOM > 0 176 #include <dev/ic/comreg.h> 177 #include <dev/ic/comvar.h> 178 #endif 179 180 /* 181 * Define the default console speed for the board. This is generally 182 * what the firmware provided with the board defaults to. 183 */ 184 #ifndef CONSPEED 185 #define CONSPEED B115200 186 #endif /* ! CONSPEED */ 187 188 #ifndef CONUNIT 189 #define CONUNIT 0 190 #endif 191 192 #ifndef CONMODE 193 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ 194 #endif 195 196 int comcnspeed = CONSPEED; 197 int comcnmode = CONMODE; 198 int comcnunit = CONUNIT; 199 200 #if KGDB 201 #ifndef KGDB_DEVNAME 202 #error Must define KGDB_DEVNAME 203 #endif 204 const char kgdb_devname[] = KGDB_DEVNAME; 205 206 #ifndef KGDB_DEVADDR 207 #error Must define KGDB_DEVADDR 208 #endif 209 unsigned long kgdb_devaddr = KGDB_DEVADDR; 210 211 #ifndef KGDB_DEVRATE 212 #define KGDB_DEVRATE CONSPEED 213 #endif 214 int kgdb_devrate = KGDB_DEVRATE; 215 216 #ifndef KGDB_DEVMODE 217 #define KGDB_DEVMODE CONMODE 218 #endif 219 int kgdb_devmode = KGDB_DEVMODE; 220 #endif /* KGDB */ 221 222 #if defined(I80321_REBOOT) 223 extern void I80321_REBOOT(int); 224 #endif 225 226 /* 227 * void cpu_reboot(int howto, char *bootstr) 228 * 229 * Reboots the system 230 * 231 * Deal with any syncing, unmounting, dumping and shutdown hooks, 232 * then reset the CPU. 233 */ 234 void 235 cpu_reboot(int howto, char *bootstr) 236 { 237 238 /* 239 * If we are still cold then hit the air brakes 240 * and crash to earth fast 241 */ 242 if (cold) { 243 doshutdownhooks(); 244 pmf_system_shutdown(boothowto); 245 printf("The operating system has halted.\n"); 246 printf("Please press any key to reboot.\n\n"); 247 cngetc(); 248 printf("rebooting...\n"); 249 goto reset; 250 } 251 252 /* Disable console buffering */ 253 254 /* 255 * If RB_NOSYNC was not specified sync the discs. 256 * Note: Unless cold is set to 1 here, syslogd will die during the 257 * unmount. It looks like syslogd is getting woken up only to find 258 * that it cannot page part of the binary in as the filesystem has 259 * been unmounted. 260 */ 261 if (!(howto & RB_NOSYNC)) 262 bootsync(); 263 264 /* Say NO to interrupts */ 265 splhigh(); 266 267 /* Do a dump if requested. */ 268 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) 269 dumpsys(); 270 271 /* Run any shutdown hooks */ 272 doshutdownhooks(); 273 274 pmf_system_shutdown(boothowto); 275 276 /* Make sure IRQ's are disabled */ 277 IRQdisable; 278 279 if (howto & RB_HALT) { 280 #if defined(I80321_REBOOT) 281 I80321_REBOOT(howto); 282 #endif 283 iq80321_7seg('.', '.'); 284 printf("The operating system has halted.\n"); 285 printf("Please press any key to reboot.\n\n"); 286 cngetc(); 287 } 288 289 printf("rebooting...\n\r"); 290 reset: 291 #if defined(I80321_REBOOT) 292 I80321_REBOOT(howto); 293 #endif 294 295 /* 296 * Make really really sure that all interrupts are disabled, 297 * and poke the Internal Bus and Peripheral Bus reset lines. 298 */ 299 (void) disable_interrupts(I32_bit|F32_bit); 300 *(volatile uint32_t *)(IQ80321_80321_VBASE + VERDE_ATU_BASE + 301 ATU_PCSR) = PCSR_RIB | PCSR_RPB; 302 303 /* ...and if that didn't work, just croak. */ 304 printf("RESET FAILED!\n"); 305 for (;;); 306 } 307 308 /* Static device mappings. */ 309 static const struct pmap_devmap iq80321_devmap[] = { 310 /* 311 * Map the on-board devices VA == PA so that we can access them 312 * with the MMU on or off. 313 */ 314 { 315 IQ80321_OBIO_BASE, 316 IQ80321_OBIO_BASE, 317 IQ80321_OBIO_SIZE, 318 VM_PROT_READ|VM_PROT_WRITE, 319 PTE_NOCACHE, 320 }, 321 322 { 323 IQ80321_IOW_VBASE, 324 VERDE_OUT_XLATE_IO_WIN0_BASE, 325 VERDE_OUT_XLATE_IO_WIN_SIZE, 326 VM_PROT_READ|VM_PROT_WRITE, 327 PTE_NOCACHE, 328 }, 329 330 { 331 IQ80321_80321_VBASE, 332 VERDE_PMMR_BASE, 333 VERDE_PMMR_SIZE, 334 VM_PROT_READ|VM_PROT_WRITE, 335 PTE_NOCACHE, 336 }, 337 338 { 339 0, 340 0, 341 0, 342 0, 343 0, 344 } 345 }; 346 347 static void 348 iq80321_hardclock_hook(void) 349 { 350 static int snakefreq; 351 352 if ((snakefreq++ & 15) == 0) 353 iq80321_7seg_snake(); 354 } 355 356 /* 357 * u_int initarm(...) 358 * 359 * Initial entry point on startup. This gets called before main() is 360 * entered. 361 * It should be responsible for setting up everything that must be 362 * in place when main is called. 363 * This includes 364 * Taking a copy of the boot configuration structure. 365 * Initialising the physical console so characters can be printed. 366 * Setting up page tables for the kernel 367 * Relocating the kernel to the bottom of physical memory 368 */ 369 u_int 370 initarm(void *arg) 371 { 372 extern vaddr_t xscale_cache_clean_addr; 373 #ifdef DIAGNOSTIC 374 extern vsize_t xscale_minidata_clean_size; 375 #endif 376 int loop; 377 int loop1; 378 u_int l1pagetable; 379 paddr_t memstart; 380 psize_t memsize; 381 382 /* 383 * Clear out the 7-segment display. Whee, the first visual 384 * indication that we're running kernel code. 385 */ 386 iq80321_7seg(' ', ' '); 387 388 /* Calibrate the delay loop. */ 389 i80321_calibrate_delay(); 390 i80321_hardclock_hook = iq80321_hardclock_hook; 391 392 /* 393 * Since we map the on-board devices VA==PA, and the kernel 394 * is running VA==PA, it's possible for us to initialize 395 * the console now. 396 */ 397 consinit(); 398 399 #ifdef VERBOSE_INIT_ARM 400 /* Talk to the user */ 401 printf("\nNetBSD/evbarm (IQ80321) booting ...\n"); 402 #endif 403 404 /* 405 * Heads up ... Setup the CPU / MMU / TLB functions 406 */ 407 if (set_cpufuncs()) 408 panic("CPU not recognized!"); 409 410 /* 411 * We are currently running with the MMU enabled and the 412 * entire address space mapped VA==PA, except for the 413 * first 64M of RAM is also double-mapped at 0xc0000000. 414 * There is an L1 page table at 0xa0004000. 415 */ 416 417 /* 418 * Fetch the SDRAM start/size from the i80321 SDRAM configuration 419 * registers. 420 */ 421 i80321_sdram_bounds(&obio_bs_tag, VERDE_PMMR_BASE + VERDE_MCU_BASE, 422 &memstart, &memsize); 423 424 #ifdef VERBOSE_INIT_ARM 425 printf("initarm: Configuring system ...\n"); 426 #endif 427 428 /* Fake bootconfig structure for the benefit of pmap.c */ 429 /* XXX must make the memory description h/w independent */ 430 bootconfig.dramblocks = 1; 431 bootconfig.dram[0].address = memstart; 432 bootconfig.dram[0].pages = memsize / PAGE_SIZE; 433 434 /* 435 * Set up the variables that define the availablilty of 436 * physical memory. For now, we're going to set 437 * physical_freestart to 0xa0200000 (where the kernel 438 * was loaded), and allocate the memory we need downwards. 439 * If we get too close to the L1 table that we set up, we 440 * will panic. We will update physical_freestart and 441 * physical_freeend later to reflect what pmap_bootstrap() 442 * wants to see. 443 * 444 * XXX pmap_bootstrap() needs an enema. 445 */ 446 physical_start = bootconfig.dram[0].address; 447 physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE); 448 449 physical_freestart = 0xa0009000UL; 450 physical_freeend = 0xa0200000UL; 451 452 physmem = (physical_end - physical_start) / PAGE_SIZE; 453 454 #ifdef VERBOSE_INIT_ARM 455 /* Tell the user about the memory */ 456 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem, 457 physical_start, physical_end - 1); 458 #endif 459 460 /* 461 * Okay, the kernel starts 2MB in from the bottom of physical 462 * memory. We are going to allocate our bootstrap pages downwards 463 * from there. 464 * 465 * We need to allocate some fixed page tables to get the kernel 466 * going. We allocate one page directory and a number of page 467 * tables and store the physical addresses in the kernel_pt_table 468 * array. 469 * 470 * The kernel page directory must be on a 16K boundary. The page 471 * tables must be on 4K boundaries. What we do is allocate the 472 * page directory on the first 16K boundary that we encounter, and 473 * the page tables on 4K boundaries otherwise. Since we allocate 474 * at least 3 L2 page tables, we are guaranteed to encounter at 475 * least one 16K aligned region. 476 */ 477 478 #ifdef VERBOSE_INIT_ARM 479 printf("Allocating page tables\n"); 480 #endif 481 482 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE; 483 484 #ifdef VERBOSE_INIT_ARM 485 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n", 486 physical_freestart, free_pages, free_pages); 487 #endif 488 489 /* Define a macro to simplify memory allocation */ 490 #define valloc_pages(var, np) \ 491 alloc_pages((var).pv_pa, (np)); \ 492 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start; 493 494 #define alloc_pages(var, np) \ 495 physical_freeend -= ((np) * PAGE_SIZE); \ 496 if (physical_freeend < physical_freestart) \ 497 panic("initarm: out of memory"); \ 498 (var) = physical_freeend; \ 499 free_pages -= (np); \ 500 memset((char *)(var), 0, ((np) * PAGE_SIZE)); 501 502 loop1 = 0; 503 kernel_l1pt.pv_pa = 0; 504 kernel_l1pt.pv_va = 0; 505 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) { 506 /* Are we 16KB aligned for an L1 ? */ 507 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0 508 && kernel_l1pt.pv_pa == 0) { 509 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE); 510 } else { 511 valloc_pages(kernel_pt_table[loop1], 512 L2_TABLE_SIZE / PAGE_SIZE); 513 ++loop1; 514 } 515 } 516 517 /* This should never be able to happen but better confirm that. */ 518 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0) 519 panic("initarm: Failed to align the kernel page directory"); 520 521 /* 522 * Allocate a page for the system page mapped to V0x00000000 523 * This page will just contain the system vectors and can be 524 * shared by all processes. 525 */ 526 alloc_pages(systempage.pv_pa, 1); 527 528 /* Allocate stacks for all modes */ 529 valloc_pages(irqstack, IRQ_STACK_SIZE); 530 valloc_pages(abtstack, ABT_STACK_SIZE); 531 valloc_pages(undstack, UND_STACK_SIZE); 532 valloc_pages(kernelstack, UPAGES); 533 534 /* Allocate enough pages for cleaning the Mini-Data cache. */ 535 KASSERT(xscale_minidata_clean_size <= PAGE_SIZE); 536 valloc_pages(minidataclean, 1); 537 538 #ifdef VERBOSE_INIT_ARM 539 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa, 540 irqstack.pv_va); 541 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa, 542 abtstack.pv_va); 543 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa, 544 undstack.pv_va); 545 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa, 546 kernelstack.pv_va); 547 #endif 548 549 /* 550 * XXX Defer this to later so that we can reclaim the memory 551 * XXX used by the RedBoot page tables. 552 */ 553 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE); 554 555 /* 556 * Ok we have allocated physical pages for the primary kernel 557 * page tables 558 */ 559 560 #ifdef VERBOSE_INIT_ARM 561 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa); 562 #endif 563 564 /* 565 * Now we start construction of the L1 page table 566 * We start by mapping the L2 page tables into the L1. 567 * This means that we can replace L1 mappings later on if necessary 568 */ 569 l1pagetable = kernel_l1pt.pv_pa; 570 571 /* Map the L2 pages tables in the L1 page table */ 572 pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1), 573 &kernel_pt_table[KERNEL_PT_SYS]); 574 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++) 575 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000, 576 &kernel_pt_table[KERNEL_PT_KERNEL + loop]); 577 pmap_link_l2pt(l1pagetable, IQ80321_IOPXS_VBASE, 578 &kernel_pt_table[KERNEL_PT_IOPXS]); 579 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++) 580 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000, 581 &kernel_pt_table[KERNEL_PT_VMDATA + loop]); 582 583 /* update the top of the kernel VM */ 584 pmap_curmaxkvaddr = 585 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000); 586 587 #ifdef VERBOSE_INIT_ARM 588 printf("Mapping kernel\n"); 589 #endif 590 591 /* Now we fill in the L2 pagetable for the kernel static code/data */ 592 { 593 extern char etext[], _end[]; 594 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE; 595 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE; 596 u_int logical; 597 598 textsize = (textsize + PGOFSET) & ~PGOFSET; 599 totalsize = (totalsize + PGOFSET) & ~PGOFSET; 600 601 logical = 0x00200000; /* offset of kernel in RAM */ 602 603 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical, 604 physical_start + logical, textsize, 605 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 606 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical, 607 physical_start + logical, totalsize - textsize, 608 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 609 } 610 611 #ifdef VERBOSE_INIT_ARM 612 printf("Constructing L2 page tables\n"); 613 #endif 614 615 /* Map the stack pages */ 616 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa, 617 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 618 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa, 619 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 620 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa, 621 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 622 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa, 623 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 624 625 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa, 626 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE); 627 628 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) { 629 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va, 630 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE, 631 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE); 632 } 633 634 /* Map the Mini-Data cache clean area. */ 635 xscale_setup_minidata(l1pagetable, minidataclean.pv_va, 636 minidataclean.pv_pa); 637 638 /* Map the vector page. */ 639 pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa, 640 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 641 642 /* Map the statically mapped devices. */ 643 pmap_devmap_bootstrap(l1pagetable, iq80321_devmap); 644 645 /* 646 * Give the XScale global cache clean code an appropriately 647 * sized chunk of unmapped VA space starting at 0xff000000 648 * (our device mappings end before this address). 649 */ 650 xscale_cache_clean_addr = 0xff000000U; 651 652 /* 653 * Now we have the real page tables in place so we can switch to them. 654 * Once this is done we will be running with the REAL kernel page 655 * tables. 656 */ 657 658 /* 659 * Update the physical_freestart/physical_freeend/free_pages 660 * variables. 661 */ 662 { 663 extern char _end[]; 664 665 physical_freestart = physical_start + 666 (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) - 667 KERNEL_BASE); 668 physical_freeend = physical_end; 669 free_pages = 670 (physical_freeend - physical_freestart) / PAGE_SIZE; 671 } 672 673 /* Switch tables */ 674 #ifdef VERBOSE_INIT_ARM 675 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n", 676 physical_freestart, free_pages, free_pages); 677 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa); 678 #endif 679 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT); 680 cpu_setttb(kernel_l1pt.pv_pa, true); 681 cpu_tlb_flushID(); 682 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)); 683 684 /* 685 * Moved from cpu_startup() as data_abort_handler() references 686 * this during uvm init 687 */ 688 uvm_lwp_setuarea(&lwp0, kernelstack.pv_va); 689 690 #ifdef VERBOSE_INIT_ARM 691 printf("done!\n"); 692 #endif 693 694 #ifdef VERBOSE_INIT_ARM 695 printf("bootstrap done.\n"); 696 #endif 697 698 arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL); 699 700 /* 701 * Pages were allocated during the secondary bootstrap for the 702 * stacks for different CPU modes. 703 * We must now set the r13 registers in the different CPU modes to 704 * point to these stacks. 705 * Since the ARM stacks use STMFD etc. we must set r13 to the top end 706 * of the stack memory. 707 */ 708 #ifdef VERBOSE_INIT_ARM 709 printf("init subsystems: stacks "); 710 #endif 711 712 set_stackptr(PSR_IRQ32_MODE, 713 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE); 714 set_stackptr(PSR_ABT32_MODE, 715 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE); 716 set_stackptr(PSR_UND32_MODE, 717 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE); 718 719 /* 720 * Well we should set a data abort handler. 721 * Once things get going this will change as we will need a proper 722 * handler. 723 * Until then we will use a handler that just panics but tells us 724 * why. 725 * Initialisation of the vectors will just panic on a data abort. 726 * This just fills in a slightly better one. 727 */ 728 #ifdef VERBOSE_INIT_ARM 729 printf("vectors "); 730 #endif 731 data_abort_handler_address = (u_int)data_abort_handler; 732 prefetch_abort_handler_address = (u_int)prefetch_abort_handler; 733 undefined_handler_address = (u_int)undefinedinstruction_bounce; 734 735 /* Initialise the undefined instruction handlers */ 736 #ifdef VERBOSE_INIT_ARM 737 printf("undefined "); 738 #endif 739 undefined_init(); 740 741 /* Load memory into UVM. */ 742 #ifdef VERBOSE_INIT_ARM 743 printf("page "); 744 #endif 745 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */ 746 uvm_page_physload(atop(physical_freestart), atop(physical_freeend), 747 atop(physical_freestart), atop(physical_freeend), 748 VM_FREELIST_DEFAULT); 749 750 /* Boot strap pmap telling it where the kernel page table is */ 751 #ifdef VERBOSE_INIT_ARM 752 printf("pmap "); 753 #endif 754 pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE); 755 756 /* Setup the IRQ system */ 757 #ifdef VERBOSE_INIT_ARM 758 printf("irq "); 759 #endif 760 i80321_intr_init(); 761 762 #ifdef VERBOSE_INIT_ARM 763 printf("done.\n"); 764 #endif 765 766 #ifdef BOOTHOWTO 767 boothowto = BOOTHOWTO; 768 #endif 769 770 #ifdef DDB 771 db_machine_init(); 772 if (boothowto & RB_KDB) 773 Debugger(); 774 #endif 775 776 /* We return the new stack pointer address */ 777 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP); 778 } 779 780 void 781 consinit(void) 782 { 783 static const bus_addr_t comcnaddrs[] = { 784 IQ80321_UART1, /* com0 */ 785 }; 786 static int consinit_called; 787 788 if (consinit_called != 0) 789 return; 790 791 consinit_called = 1; 792 793 /* 794 * Console devices are mapped VA==PA. Our devmap reflects 795 * this, so register it now so drivers can map the console 796 * device. 797 */ 798 pmap_devmap_register(iq80321_devmap); 799 800 #if NCOM > 0 801 if (comcnattach(&obio_bs_tag, comcnaddrs[comcnunit], comcnspeed, 802 COM_FREQ, COM_TYPE_NORMAL, comcnmode)) 803 panic("can't init serial console @%lx", comcnaddrs[comcnunit]); 804 #else 805 panic("serial console @%lx not configured", comcnaddrs[comcnunit]); 806 #endif 807 #if KGDB 808 #if NCOM > 0 809 if (strcmp(kgdb_devname, "com") == 0) { 810 com_kgdb_attach(&obio_bs_tag, kgdb_devaddr, kgdb_devrate, 811 COM_FREQ, COM_TYPE_NORMAL, kgdb_devmode); 812 } 813 #endif /* NCOM > 0 */ 814 #endif /* KGDB */ 815 } 816