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