1 /* $NetBSD: npwr_fc_machdep.c,v 1.5 2008/01/19 13:11:16 chris 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 dependant 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.5 2008/01/19 13:11:16 chris 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 <machine/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 /* 131 * Address to call from cpu_reset() to reset the machine. 132 * This is machine architecture dependant as it varies depending 133 * on where the ROM appears when you turn the MMU off. 134 * 135 * XXX Not actally used on IQ80321 -- clean up the generic 136 * ARM code. 137 */ 138 139 u_int cpu_reset_address = 0x00000000; 140 141 /* Define various stack sizes in pages */ 142 #define IRQ_STACK_SIZE 1 143 #define ABT_STACK_SIZE 1 144 #define UND_STACK_SIZE 1 145 146 BootConfig bootconfig; /* Boot config storage */ 147 char *boot_args = NULL; 148 char *boot_file = NULL; 149 150 vm_offset_t physical_start; 151 vm_offset_t physical_freestart; 152 vm_offset_t physical_freeend; 153 vm_offset_t physical_end; 154 u_int free_pages; 155 vm_offset_t pagetables_start; 156 int physmem = 0; 157 158 /*int debug_flags;*/ 159 #ifndef PMAP_STATIC_L1S 160 int max_processes = 64; /* Default number */ 161 #endif /* !PMAP_STATIC_L1S */ 162 163 /* Physical and virtual addresses for some global pages */ 164 pv_addr_t systempage; 165 pv_addr_t irqstack; 166 pv_addr_t undstack; 167 pv_addr_t abtstack; 168 pv_addr_t kernelstack; 169 pv_addr_t minidataclean; 170 171 vm_offset_t msgbufphys; 172 173 extern u_int data_abort_handler_address; 174 extern u_int prefetch_abort_handler_address; 175 extern u_int undefined_handler_address; 176 177 #ifdef PMAP_DEBUG 178 extern int pmap_debug_level; 179 #endif 180 181 #define KERNEL_PT_SYS 0 /* L2 table for mapping zero page */ 182 183 #define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */ 184 #define KERNEL_PT_KERNEL_NUM 4 185 186 /* L2 table for mapping i80321 */ 187 #define KERNEL_PT_IOPXS (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM) 188 189 /* L2 tables for mapping kernel VM */ 190 #define KERNEL_PT_VMDATA (KERNEL_PT_IOPXS + 1) 191 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */ 192 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM) 193 194 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS]; 195 196 struct user *proc0paddr; 197 198 /* Prototypes */ 199 200 void consinit(void); 201 202 #include "com.h" 203 #if NCOM > 0 204 #include <dev/ic/comreg.h> 205 #include <dev/ic/comvar.h> 206 #endif 207 208 /* 209 * Define the default console speed for the board. This is generally 210 * what the firmware provided with the board defaults to. 211 */ 212 #ifndef CONSPEED 213 #define CONSPEED B115200 214 #endif /* ! CONSPEED */ 215 216 #ifndef CONUNIT 217 #define CONUNIT 0 218 #endif 219 220 #ifndef CONMODE 221 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ 222 #endif 223 224 int comcnspeed = CONSPEED; 225 int comcnmode = CONMODE; 226 int comcnunit = CONUNIT; 227 228 #if KGDB 229 #ifndef KGDB_DEVNAME 230 #error Must define KGDB_DEVNAME 231 #endif 232 const char kgdb_devname[] = KGDB_DEVNAME; 233 234 #ifndef KGDB_DEVADDR 235 #error Must define KGDB_DEVADDR 236 #endif 237 unsigned long kgdb_devaddr = KGDB_DEVADDR; 238 239 #ifndef KGDB_DEVRATE 240 #define KGDB_DEVRATE CONSPEED 241 #endif 242 int kgdb_devrate = KGDB_DEVRATE; 243 244 #ifndef KGDB_DEVMODE 245 #define KGDB_DEVMODE CONMODE 246 #endif 247 int kgdb_devmode = KGDB_DEVMODE; 248 #endif /* KGDB */ 249 250 /* 251 * void cpu_reboot(int howto, char *bootstr) 252 * 253 * Reboots the system 254 * 255 * Deal with any syncing, unmounting, dumping and shutdown hooks, 256 * then reset the CPU. 257 */ 258 void 259 cpu_reboot(int howto, char *bootstr) 260 { 261 262 /* 263 * If we are still cold then hit the air brakes 264 * and crash to earth fast 265 */ 266 if (cold) { 267 doshutdownhooks(); 268 printf("The operating system has halted.\n"); 269 printf("Please press any key to reboot.\n\n"); 270 cngetc(); 271 printf("rebooting...\n"); 272 goto reset; 273 } 274 275 /* Disable console buffering */ 276 277 /* 278 * If RB_NOSYNC was not specified sync the discs. 279 * Note: Unless cold is set to 1 here, syslogd will die during the 280 * unmount. It looks like syslogd is getting woken up only to find 281 * that it cannot page part of the binary in as the filesystem has 282 * been unmounted. 283 */ 284 if (!(howto & RB_NOSYNC)) 285 bootsync(); 286 287 /* Say NO to interrupts */ 288 splhigh(); 289 290 /* Do a dump if requested. */ 291 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) 292 dumpsys(); 293 294 /* Run any shutdown hooks */ 295 doshutdownhooks(); 296 297 /* Make sure IRQ's are disabled */ 298 IRQdisable; 299 300 if (howto & RB_HALT) { 301 printf("The operating system has halted.\n"); 302 printf("Please press any key to reboot.\n\n"); 303 cngetc(); 304 } 305 306 printf("rebooting...\n\r"); 307 reset: 308 /* 309 * Make really really sure that all interrupts are disabled, 310 * and poke the Internal Bus and Peripheral Bus reset lines. 311 */ 312 (void) disable_interrupts(I32_bit|F32_bit); 313 *(volatile uint32_t *)(IQ80321_80321_VBASE + VERDE_ATU_BASE + 314 ATU_PCSR) = PCSR_RIB | PCSR_RPB; 315 316 /* ...and if that didn't work, just croak. */ 317 printf("RESET FAILED!\n"); 318 for (;;); 319 } 320 321 /* Static device mappings. */ 322 static const struct pmap_devmap iq80321_devmap[] = { 323 /* 324 * Map the on-board devices VA == PA so that we can access them 325 * with the MMU on or off. 326 */ 327 { 328 IQ80321_OBIO_BASE, 329 IQ80321_OBIO_BASE, 330 IQ80321_OBIO_SIZE, 331 VM_PROT_READ|VM_PROT_WRITE, 332 PTE_NOCACHE, 333 }, 334 335 { 336 IQ80321_IOW_VBASE, 337 VERDE_OUT_XLATE_IO_WIN0_BASE, 338 VERDE_OUT_XLATE_IO_WIN_SIZE, 339 VM_PROT_READ|VM_PROT_WRITE, 340 PTE_NOCACHE, 341 }, 342 343 { 344 IQ80321_80321_VBASE, 345 VERDE_PMMR_BASE, 346 VERDE_PMMR_SIZE, 347 VM_PROT_READ|VM_PROT_WRITE, 348 PTE_NOCACHE, 349 }, 350 351 { 352 0, 353 0, 354 0, 355 0, 356 0, 357 } 358 }; 359 360 /* 361 * u_int initarm(...) 362 * 363 * Initial entry point on startup. This gets called before main() is 364 * entered. 365 * It should be responsible for setting up everything that must be 366 * in place when main is called. 367 * This includes 368 * Taking a copy of the boot configuration structure. 369 * Initialising the physical console so characters can be printed. 370 * Setting up page tables for the kernel 371 * Relocating the kernel to the bottom of physical memory 372 */ 373 u_int 374 initarm(void *arg) 375 { 376 extern vaddr_t xscale_cache_clean_addr; 377 #ifdef DIAGNOSTIC 378 extern vsize_t xscale_minidata_clean_size; 379 #endif 380 int loop; 381 int loop1; 382 u_int l1pagetable; 383 pv_addr_t kernel_l1pt; 384 paddr_t memstart; 385 psize_t memsize; 386 387 /* Calibrate the delay loop. */ 388 i80321_calibrate_delay(); 389 i80321_hardclock_hook = NULL; 390 391 /* 392 * Since we map the on-board devices VA==PA, and the kernel 393 * is running VA==PA, it's possible for us to initialize 394 * the console now. 395 */ 396 consinit(); 397 398 #ifdef VERBOSE_INIT_ARM 399 /* Talk to the user */ 400 printf("\nNetBSD/evbarm (NPWR_FC) booting ...\n"); 401 #endif 402 403 /* 404 * Heads up ... Setup the CPU / MMU / TLB functions 405 */ 406 if (set_cpufuncs()) 407 panic("cpu not recognized!"); 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 i80321 SDRAM configration 418 * registers. 419 */ 420 i80321_sdram_bounds(&obio_bs_tag, VERDE_PMMR_BASE + VERDE_MCU_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 bounaries. 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 kernel_l1pt.pv_pa = 0; 503 kernel_l1pt.pv_va = 0; 504 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) { 505 /* Are we 16KB aligned for an L1 ? */ 506 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0 507 && kernel_l1pt.pv_pa == 0) { 508 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE); 509 } else { 510 valloc_pages(kernel_pt_table[loop1], 511 L2_TABLE_SIZE / PAGE_SIZE); 512 ++loop1; 513 } 514 } 515 516 /* This should never be able to happen but better confirm that. */ 517 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0) 518 panic("initarm: Failed to align the kernel page directory"); 519 520 /* 521 * Allocate a page for the system page mapped to V0x00000000 522 * This page will just contain the system vectors and can be 523 * shared by all processes. 524 */ 525 alloc_pages(systempage.pv_pa, 1); 526 527 /* Allocate stacks for all modes */ 528 valloc_pages(irqstack, IRQ_STACK_SIZE); 529 valloc_pages(abtstack, ABT_STACK_SIZE); 530 valloc_pages(undstack, UND_STACK_SIZE); 531 valloc_pages(kernelstack, UPAGES); 532 533 /* Allocate enough pages for cleaning the Mini-Data cache. */ 534 KASSERT(xscale_minidata_clean_size <= PAGE_SIZE); 535 valloc_pages(minidataclean, 1); 536 537 #ifdef VERBOSE_INIT_ARM 538 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa, 539 irqstack.pv_va); 540 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa, 541 abtstack.pv_va); 542 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa, 543 undstack.pv_va); 544 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa, 545 kernelstack.pv_va); 546 #endif 547 548 /* 549 * XXX Defer this to later so that we can reclaim the memory 550 * XXX used by the RedBoot page tables. 551 */ 552 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE); 553 554 /* 555 * Ok we have allocated physical pages for the primary kernel 556 * page tables 557 */ 558 559 #ifdef VERBOSE_INIT_ARM 560 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa); 561 #endif 562 563 /* 564 * Now we start construction of the L1 page table 565 * We start by mapping the L2 page tables into the L1. 566 * This means that we can replace L1 mappings later on if necessary 567 */ 568 l1pagetable = kernel_l1pt.pv_pa; 569 570 /* Map the L2 pages tables in the L1 page table */ 571 pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1), 572 &kernel_pt_table[KERNEL_PT_SYS]); 573 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++) 574 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000, 575 &kernel_pt_table[KERNEL_PT_KERNEL + loop]); 576 pmap_link_l2pt(l1pagetable, IQ80321_IOPXS_VBASE, 577 &kernel_pt_table[KERNEL_PT_IOPXS]); 578 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++) 579 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000, 580 &kernel_pt_table[KERNEL_PT_VMDATA + loop]); 581 582 /* update the top of the kernel VM */ 583 pmap_curmaxkvaddr = 584 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000); 585 586 #ifdef VERBOSE_INIT_ARM 587 printf("Mapping kernel\n"); 588 #endif 589 590 /* Now we fill in the L2 pagetable for the kernel static code/data */ 591 { 592 extern char etext[], _end[]; 593 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE; 594 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE; 595 u_int logical; 596 597 textsize = (textsize + PGOFSET) & ~PGOFSET; 598 totalsize = (totalsize + PGOFSET) & ~PGOFSET; 599 600 logical = 0x00200000; /* offset of kernel in RAM */ 601 602 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical, 603 physical_start + logical, textsize, 604 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 605 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical, 606 physical_start + logical, totalsize - textsize, 607 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 608 } 609 610 #ifdef VERBOSE_INIT_ARM 611 printf("Constructing L2 page tables\n"); 612 #endif 613 614 /* Map the stack pages */ 615 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa, 616 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 617 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa, 618 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 619 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa, 620 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 621 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa, 622 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 623 624 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa, 625 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE); 626 627 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) { 628 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va, 629 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE, 630 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE); 631 } 632 633 /* Map the Mini-Data cache clean area. */ 634 xscale_setup_minidata(l1pagetable, minidataclean.pv_va, 635 minidataclean.pv_pa); 636 637 /* Map the vector page. */ 638 pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa, 639 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 640 641 /* Map the statically mapped devices. */ 642 pmap_devmap_bootstrap(l1pagetable, iq80321_devmap); 643 644 /* 645 * Give the XScale global cache clean code an appropriately 646 * sized chunk of unmapped VA space starting at 0xff000000 647 * (our device mappings end before this address). 648 */ 649 xscale_cache_clean_addr = 0xff000000U; 650 651 /* 652 * Now we have the real page tables in place so we can switch to them. 653 * Once this is done we will be running with the REAL kernel page 654 * tables. 655 */ 656 657 /* 658 * Update the physical_freestart/physical_freeend/free_pages 659 * variables. 660 */ 661 { 662 extern char _end[]; 663 664 physical_freestart = physical_start + 665 (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) - 666 KERNEL_BASE); 667 physical_freeend = physical_end; 668 free_pages = 669 (physical_freeend - physical_freestart) / PAGE_SIZE; 670 } 671 672 /* Switch tables */ 673 #ifdef VERBOSE_INIT_ARM 674 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n", 675 physical_freestart, free_pages, free_pages); 676 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa); 677 #endif 678 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT); 679 setttb(kernel_l1pt.pv_pa); 680 cpu_tlb_flushID(); 681 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)); 682 683 /* 684 * Moved from cpu_startup() as data_abort_handler() references 685 * this during uvm init 686 */ 687 proc0paddr = (struct user *)kernelstack.pv_va; 688 lwp0.l_addr = proc0paddr; 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 slighly 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((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE, 755 KERNEL_VM_BASE + KERNEL_VM_SIZE); 756 757 /* Setup the IRQ system */ 758 #ifdef VERBOSE_INIT_ARM 759 printf("irq "); 760 #endif 761 i80321_intr_init(); 762 763 #ifdef VERBOSE_INIT_ARM 764 printf("done.\n"); 765 #endif 766 767 #ifdef BOOTHOWTO 768 boothowto = BOOTHOWTO; 769 #endif 770 771 #if NKSYMS || defined(DDB) || defined(LKM) 772 /* Firmware doesn't load symbols. */ 773 ksyms_init(0, NULL, NULL); 774 #endif 775 776 #ifdef DDB 777 db_machine_init(); 778 if (boothowto & RB_KDB) 779 Debugger(); 780 #endif 781 782 /* We return the new stack pointer address */ 783 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP); 784 } 785 786 void 787 consinit(void) 788 { 789 static const bus_addr_t comcnaddrs[] = { 790 IQ80321_UART1, /* com0 */ 791 }; 792 static int consinit_called; 793 794 if (consinit_called != 0) 795 return; 796 797 consinit_called = 1; 798 799 /* 800 * Console devices are mapped VA==PA. Our devmap reflects 801 * this, so register it now so drivers can map the console 802 * device. 803 */ 804 pmap_devmap_register(iq80321_devmap); 805 806 #if NCOM > 0 807 if (comcnattach(&obio_bs_tag, comcnaddrs[comcnunit], comcnspeed, 808 COM_FREQ, COM_TYPE_NORMAL, comcnmode)) 809 panic("can't init serial console @%lx", comcnaddrs[comcnunit]); 810 #else 811 panic("serial console @%lx not configured", comcnaddrs[comcnunit]); 812 #endif 813 #if KGDB 814 #if NCOM > 0 815 if (strcmp(kgdb_devname, "com") == 0) { 816 com_kgdb_attach(&obio_bs_tag, kgdb_devaddr, kgdb_devrate, 817 COM_FREQ, COM_TYPE_NORMAL, kgdb_devmode); 818 } 819 #endif /* NCOM > 0 */ 820 #endif /* KGDB */ 821 } 822