1 /* $NetBSD: gemini_machdep.c,v 1.33 2020/11/28 14:02:30 skrll Exp $ */ 2 3 /* adapted from: 4 * NetBSD: sdp24xx_machdep.c,v 1.4 2008/08/27 11:03:10 matt Exp 5 */ 6 7 /* 8 * Machine dependent functions for kernel setup for TI OSK5912 board. 9 * Based on lubbock_machdep.c which in turn was based on iq80310_machhdep.c 10 * 11 * Copyright (c) 2002, 2003, 2005 Genetec Corporation. All rights reserved. 12 * Written by Hiroyuki Bessho for Genetec Corporation. 13 * 14 * Redistribution and use in source and binary forms, with or without 15 * modification, are permitted provided that the following conditions 16 * are met: 17 * 1. Redistributions of source code must retain the above copyright 18 * notice, this list of conditions and the following disclaimer. 19 * 2. Redistributions in binary form must reproduce the above copyright 20 * notice, this list of conditions and the following disclaimer in the 21 * documentation and/or other materials provided with the distribution. 22 * 3. The name of Genetec Corporation may not be used to endorse or 23 * promote products derived from this software without specific prior 24 * written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 * 38 * Copyright (c) 2001 Wasabi Systems, Inc. 39 * All rights reserved. 40 * 41 * Written by Jason R. Thorpe for Wasabi Systems, Inc. 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 for the NetBSD Project by 54 * Wasabi Systems, Inc. 55 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 56 * or promote products derived from this software without specific prior 57 * written permission. 58 * 59 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 61 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 62 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 63 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 64 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 65 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 66 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 67 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 68 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 69 * POSSIBILITY OF SUCH DAMAGE. 70 * 71 * Copyright (c) 1997,1998 Mark Brinicombe. 72 * Copyright (c) 1997,1998 Causality Limited. 73 * All rights reserved. 74 * 75 * Redistribution and use in source and binary forms, with or without 76 * modification, are permitted provided that the following conditions 77 * are met: 78 * 1. Redistributions of source code must retain the above copyright 79 * notice, this list of conditions and the following disclaimer. 80 * 2. Redistributions in binary form must reproduce the above copyright 81 * notice, this list of conditions and the following disclaimer in the 82 * documentation and/or other materials provided with the distribution. 83 * 3. All advertising materials mentioning features or use of this software 84 * must display the following acknowledgement: 85 * This product includes software developed by Mark Brinicombe 86 * for the NetBSD Project. 87 * 4. The name of the company nor the name of the author may be used to 88 * endorse or promote products derived from this software without specific 89 * prior written permission. 90 * 91 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 92 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 93 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 94 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 95 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 96 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 97 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 98 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 99 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 100 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 101 * SUCH DAMAGE. 102 * 103 * Copyright (c) 2007 Microsoft 104 * All rights reserved. 105 * 106 * Redistribution and use in source and binary forms, with or without 107 * modification, are permitted provided that the following conditions 108 * are met: 109 * 1. Redistributions of source code must retain the above copyright 110 * notice, this list of conditions and the following disclaimer. 111 * 2. Redistributions in binary form must reproduce the above copyright 112 * notice, this list of conditions and the following disclaimer in the 113 * documentation and/or other materials provided with the distribution. 114 * 3. All advertising materials mentioning features or use of this software 115 * must display the following acknowledgement: 116 * This product includes software developed by Microsoft 117 * 118 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 119 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 120 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 121 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTERS BE LIABLE FOR ANY DIRECT, 122 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 123 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 124 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 125 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 126 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 127 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 128 * SUCH DAMAGE. 129 */ 130 131 #include <sys/cdefs.h> 132 __KERNEL_RCSID(0, "$NetBSD: gemini_machdep.c,v 1.33 2020/11/28 14:02:30 skrll Exp $"); 133 134 #include "opt_arm_debug.h" 135 #include "opt_console.h" 136 #include "opt_machdep.h" 137 #include "opt_ddb.h" 138 #include "opt_kgdb.h" 139 #include "opt_md.h" 140 #include "opt_com.h" 141 #include "opt_gemini.h" 142 #include "geminiwdt.h" 143 #include "geminiipm.h" 144 145 #include <sys/param.h> 146 #include <sys/device.h> 147 #include <sys/systm.h> 148 #include <sys/kernel.h> 149 #include <sys/exec.h> 150 #include <sys/proc.h> 151 #include <sys/msgbuf.h> 152 #include <sys/reboot.h> 153 #include <sys/termios.h> 154 #include <sys/ksyms.h> 155 #include <sys/bus.h> 156 #include <sys/cpu.h> 157 #include <sys/conf.h> 158 159 #include <uvm/uvm_extern.h> 160 161 #include <dev/cons.h> 162 #include <dev/md.h> 163 164 #include <machine/db_machdep.h> 165 #include <ddb/db_sym.h> 166 #include <ddb/db_extern.h> 167 #ifdef KGDB 168 #include <sys/kgdb.h> 169 #endif 170 171 #include <arm/locore.h> 172 #include <arm/undefined.h> 173 174 #include <arm/arm32/machdep.h> 175 176 #include <machine/bootconfig.h> 177 178 #include <arm/gemini/gemini_reg.h> 179 #include <arm/gemini/gemini_var.h> 180 #include <arm/gemini/gemini_wdtvar.h> 181 #include <arm/gemini/gemini_com.h> 182 #include <arm/gemini/lpc_com.h> 183 184 #include <evbarm/gemini/gemini.h> 185 186 #if defined(VERBOSE_INIT_ARM) 187 # define GEMINI_PUTCHAR(c) gemini_putchar(c) 188 # define GEMINI_PUTHEX(n) gemini_puthex(n) 189 #else /* VERBOSE_INIT_ARM */ 190 # define GEMINI_PUTCHAR(c) 191 # define GEMINI_PUTHEX(n) 192 #endif /* VERBOSE_INIT_ARM */ 193 194 BootConfig bootconfig; /* Boot config storage */ 195 char *boot_args = NULL; 196 char *boot_file = NULL; 197 198 /* Physical address of the beginning of SDRAM. */ 199 paddr_t physical_start; 200 /* Physical address of the first byte after the end of SDRAM. */ 201 paddr_t physical_end; 202 203 /* Same things, but for the free (unused by the kernel) memory. */ 204 static paddr_t physical_freestart, physical_freeend; 205 static u_int free_pages; 206 207 /* Physical address of the message buffer. */ 208 paddr_t msgbufphys; 209 210 extern char KERNEL_BASE_phys[]; 211 extern char KERNEL_BASE_virt[]; 212 extern char etext[], __data_start[], _edata[], __bss_start[], __bss_end__[]; 213 extern char _end[]; 214 215 #define KERNEL_PT_SYS 0 /* Page table for mapping proc0 zero page */ 216 #define KERNEL_PT_KERNEL 1 /* Page table for mapping kernel */ 217 #define KERNEL_PT_KERNEL_NUM 4 218 #define KERNEL_PT_VMDATA (KERNEL_PT_KERNEL+KERNEL_PT_KERNEL_NUM) 219 /* Page tables for mapping kernel VM */ 220 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */ 221 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM) 222 223 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS]; 224 225 226 #if (NGEMINIIPM > 0) 227 pv_addr_t ipmq_pt; /* L2 Page table for mapping IPM queues */ 228 #if defined(DEBUG) || 1 229 unsigned long gemini_ipmq_pbase = GEMINI_IPMQ_PBASE; 230 unsigned long gemini_ipmq_vbase = GEMINI_IPMQ_VBASE; 231 #endif /* DEBUG */ 232 #endif /* NGEMINIIPM > 0 */ 233 234 235 /* 236 * Macros to translate between physical and virtual for a subset of the 237 * kernel address space. *Not* for general use. 238 */ 239 #define KERNEL_BASE_PHYS ((paddr_t)&KERNEL_BASE_phys) 240 241 u_long kern_vtopdiff; 242 243 /* Prototypes */ 244 245 void gemini_intr_init(bus_space_tag_t); 246 void consinit(void); 247 #ifdef KGDB 248 static void kgdb_port_init(void); 249 #endif 250 251 static void setup_real_page_tables(void); 252 static void init_clocks(void); 253 254 bs_protos(bs_notimpl); 255 256 #include "com.h" 257 #if NCOM > 0 258 #include <dev/ic/comreg.h> 259 #include <dev/ic/comvar.h> 260 #endif 261 262 263 static void gemini_global_reset(void) __attribute__ ((noreturn)); 264 static void gemini_cpu1_start(void); 265 static void gemini_memchk(void); 266 267 static void 268 gemini_global_reset(void) 269 { 270 #if defined(GEMINI_MASTER) || defined(GEMINI_SINGLE) 271 volatile uint32_t *rp; 272 uint32_t r; 273 274 rp = (volatile uint32_t *) 275 (GEMINI_GLOBAL_VBASE + GEMINI_GLOBAL_RESET_CTL); 276 r = *rp; 277 r |= GLOBAL_RESET_GLOBAL; 278 *rp = r; 279 #endif 280 for(;;); 281 /* NOTREACHED */ 282 } 283 284 static void 285 gemini_cpu1_start(void) 286 { 287 #ifdef GEMINI_MASTER 288 volatile uint32_t *rp; 289 uint32_t r; 290 291 rp = (volatile uint32_t *) 292 (GEMINI_GLOBAL_VBASE + GEMINI_GLOBAL_RESET_CTL); 293 r = *rp; 294 r &= ~GLOBAL_RESET_CPU1; 295 *rp = r; 296 #endif 297 } 298 299 static void 300 gemini_memchk(void) 301 { 302 volatile uint32_t *rp; 303 uint32_t r; 304 uint32_t base; 305 uint32_t size; 306 307 rp = (volatile uint32_t *) 308 (GEMINI_DRAMC_VBASE + GEMINI_DRAMC_RMCR); 309 r = *rp; 310 base = (r & DRAMC_RMCR_RMBAR) >> DRAMC_RMCR_RMBAR_SHFT; 311 size = (r & DRAMC_RMCR_RMSZR) >> DRAMC_RMCR_RMSZR_SHFT; 312 #if defined(GEMINI_SINGLE) 313 if (r != 0) 314 panic("%s: RMCR %#x, MEMSIZE %d mismatch\n", 315 __FUNCTION__, r, MEMSIZE); 316 #elif defined(GEMINI_MASTER) 317 if (base != MEMSIZE) 318 panic("%s: RMCR %#x, MEMSIZE %d mismatch\n", 319 __FUNCTION__, r, MEMSIZE); 320 #elif defined(GEMINI_SLAVE) 321 if (size != MEMSIZE) 322 panic("%s: RMCR %#x, MEMSIZE %d mismatch\n", 323 __FUNCTION__, r, MEMSIZE); 324 #endif 325 #if defined(VERBOSE_INIT_ARM) || 1 326 printf("DRAM Remap: base=%dMB, size=%dMB\n", base, size); 327 #endif 328 } 329 330 /* 331 * void cpu_reboot(int howto, char *bootstr) 332 * 333 * Reboots the system 334 * 335 * Deal with any syncing, unmounting, dumping and shutdown hooks, 336 * then reset the CPU. 337 */ 338 void 339 cpu_reboot(int howto, char *bootstr) 340 { 341 extern struct geminitmr_softc *ref_sc; 342 343 #ifdef DIAGNOSTIC 344 /* info */ 345 printf("boot: howto=%08x curproc=%p\n", howto, curproc); 346 #endif 347 348 /* 349 * If we are still cold then hit the air brakes 350 * and crash to earth fast 351 */ 352 if (cold) { 353 doshutdownhooks(); 354 pmf_system_shutdown(boothowto); 355 printf("The operating system has halted.\n"); 356 printf("Please press any key to reboot.\n\n"); 357 cngetc(); 358 printf("rebooting...\n"); 359 if (ref_sc != NULL) 360 delay(2000); /* cnflush(); */ 361 gemini_global_reset(); 362 /*NOTREACHED*/ 363 } 364 365 /* Disable console buffering */ 366 cnpollc(1); 367 368 /* 369 * If RB_NOSYNC was not specified sync the discs. 370 * Note: Unless cold is set to 1 here, syslogd will die during the 371 * unmount. It looks like syslogd is getting woken up only to find 372 * that it cannot page part of the binary in as the filesystem has 373 * been unmounted. 374 */ 375 if (!(howto & RB_NOSYNC)) 376 bootsync(); 377 378 /* Say NO to interrupts */ 379 splhigh(); 380 381 /* Do a dump if requested. */ 382 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) 383 dumpsys(); 384 385 /* Run any shutdown hooks */ 386 doshutdownhooks(); 387 388 pmf_system_shutdown(boothowto); 389 390 /* Make sure IRQ's are disabled */ 391 IRQdisable; 392 393 if (howto & RB_HALT) { 394 printf("The operating system has halted.\n"); 395 printf("Please press any key to reboot.\n\n"); 396 cngetc(); 397 } 398 399 printf("rebooting...\n"); 400 if (ref_sc != NULL) 401 delay(2000); /* cnflush(); */ 402 gemini_global_reset(); 403 /*NOTREACHED*/ 404 } 405 406 /* 407 * Static device mappings. These peripheral registers are mapped at 408 * fixed virtual addresses very early in initarm() so that we can use 409 * them while booting the kernel, and stay at the same address 410 * throughout whole kernel's life time. 411 * 412 * We use this table twice; once with bootstrap page table, and once 413 * with kernel's page table which we build up in initarm(). 414 * 415 * Since we map these registers into the bootstrap page table using 416 * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map 417 * registers segment-aligned and segment-rounded in order to avoid 418 * using the 2nd page tables. 419 */ 420 421 #define _A(a) ((a) & ~L1_S_OFFSET) 422 #define _S(s) (((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1)) 423 424 static const struct pmap_devmap devmap[] = { 425 /* Global regs */ 426 { 427 .pd_va = _A(GEMINI_GLOBAL_VBASE), 428 .pd_pa = _A(GEMINI_GLOBAL_BASE), 429 .pd_size = _S(L1_S_SIZE), 430 .pd_prot = VM_PROT_READ|VM_PROT_WRITE, 431 .pd_cache = PTE_NOCACHE 432 }, 433 434 /* Watchdog */ 435 { 436 .pd_va = _A(GEMINI_WATCHDOG_VBASE), 437 .pd_pa = _A(GEMINI_WATCHDOG_BASE), 438 .pd_size = _S(L1_S_SIZE), 439 .pd_prot = VM_PROT_READ|VM_PROT_WRITE, 440 .pd_cache = PTE_NOCACHE 441 }, 442 443 /* UART */ 444 { 445 .pd_va = _A(GEMINI_UART_VBASE), 446 .pd_pa = _A(GEMINI_UART_BASE), 447 .pd_size = _S(L1_S_SIZE), 448 .pd_prot = VM_PROT_READ|VM_PROT_WRITE, 449 .pd_cache = PTE_NOCACHE 450 }, 451 452 /* LPCHC */ 453 { 454 .pd_va = _A(GEMINI_LPCHC_VBASE), 455 .pd_pa = _A(GEMINI_LPCHC_BASE), 456 .pd_size = _S(L1_S_SIZE), 457 .pd_prot = VM_PROT_READ|VM_PROT_WRITE, 458 .pd_cache = PTE_NOCACHE 459 }, 460 461 /* LPCIO */ 462 { 463 .pd_va = _A(GEMINI_LPCIO_VBASE), 464 .pd_pa = _A(GEMINI_LPCIO_BASE), 465 .pd_size = _S(L1_S_SIZE), 466 .pd_prot = VM_PROT_READ|VM_PROT_WRITE, 467 .pd_cache = PTE_NOCACHE 468 }, 469 470 /* Timers */ 471 { 472 .pd_va = _A(GEMINI_TIMER_VBASE), 473 .pd_pa = _A(GEMINI_TIMER_BASE), 474 .pd_size = _S(L1_S_SIZE), 475 .pd_prot = VM_PROT_READ|VM_PROT_WRITE, 476 .pd_cache = PTE_NOCACHE 477 }, 478 479 /* DRAM Controller */ 480 { 481 .pd_va = _A(GEMINI_DRAMC_VBASE), 482 .pd_pa = _A(GEMINI_DRAMC_BASE), 483 .pd_size = _S(L1_S_SIZE), 484 .pd_prot = VM_PROT_READ|VM_PROT_WRITE, 485 .pd_cache = PTE_NOCACHE 486 }, 487 488 #if defined(MEMORY_DISK_DYNAMIC) 489 /* Ramdisk */ 490 { 491 .pd_va = _A(GEMINI_RAMDISK_VBASE), 492 .pd_pa = _A(GEMINI_RAMDISK_PBASE), 493 .pd_size = _S(GEMINI_RAMDISK_SIZE), 494 .pd_prot = VM_PROT_READ|VM_PROT_WRITE, 495 .pd_cache = PTE_NOCACHE 496 }, 497 #endif 498 499 {0} /* list terminator */ 500 }; 501 502 #undef _A 503 #undef _S 504 505 #ifdef DDB 506 static void gemini_db_trap(int where) 507 { 508 #if NGEMINIWDT > 0 509 static int oldwatchdogstate; 510 511 if (where) { 512 oldwatchdogstate = geminiwdt_enable(0); 513 } else { 514 geminiwdt_enable(oldwatchdogstate); 515 } 516 #endif 517 } 518 #endif 519 520 #if defined(VERBOSE_INIT_ARM) || 1 521 void gemini_putchar(char c); 522 void 523 gemini_putchar(char c) 524 { 525 unsigned char *com0addr = (unsigned char *)GEMINI_UART_VBASE; 526 int timo = 150000; 527 528 while ((com0addr[COM_REG_LSR * 4] & LSR_TXRDY) == 0) 529 if (--timo == 0) 530 break; 531 532 com0addr[COM_REG_TXDATA] = c; 533 534 while ((com0addr[COM_REG_LSR * 4] & LSR_TSRE) == 0) 535 if (--timo == 0) 536 break; 537 } 538 539 void gemini_puthex(unsigned int); 540 void 541 gemini_puthex(unsigned int val) 542 { 543 char hexc[] = "0123456789abcdef"; 544 545 gemini_putchar('0'); 546 gemini_putchar('x'); 547 gemini_putchar(hexc[(val >> 28) & 0xf]); 548 gemini_putchar(hexc[(val >> 24) & 0xf]); 549 gemini_putchar(hexc[(val >> 20) & 0xf]); 550 gemini_putchar(hexc[(val >> 16) & 0xf]); 551 gemini_putchar(hexc[(val >> 12) & 0xf]); 552 gemini_putchar(hexc[(val >> 8) & 0xf]); 553 gemini_putchar(hexc[(val >> 4) & 0xf]); 554 gemini_putchar(hexc[(val >> 0) & 0xf]); 555 } 556 #endif /* VERBOSE_INIT_ARM */ 557 558 /* 559 * vaddr_t initarm(...) 560 * 561 * Initial entry point on startup. This gets called before main() is 562 * entered. 563 * It should be responsible for setting up everything that must be 564 * in place when main is called. 565 * This includes 566 * Taking a copy of the boot configuration structure. 567 * Initialising the physical console so characters can be printed. 568 * Setting up page tables for the kernel 569 * Relocating the kernel to the bottom of physical memory 570 */ 571 vaddr_t 572 initarm(void *arg) 573 { 574 GEMINI_PUTCHAR('0'); 575 576 /* 577 * start cpu#1 now 578 */ 579 gemini_cpu1_start(); 580 581 /* 582 * When we enter here, we are using a temporary first level 583 * translation table with section entries in it to cover the OBIO 584 * peripherals and SDRAM. The temporary first level translation table 585 * is at the end of SDRAM. 586 */ 587 588 /* Heads up ... Setup the CPU / MMU / TLB functions. */ 589 GEMINI_PUTCHAR('1'); 590 if (set_cpufuncs()) 591 panic("cpu not recognized!"); 592 593 GEMINI_PUTCHAR('2'); 594 init_clocks(); 595 GEMINI_PUTCHAR('3'); 596 597 /* The console is going to try to map things. Give pmap a devmap. */ 598 pmap_devmap_register(devmap); 599 GEMINI_PUTCHAR('4'); 600 consinit(); 601 GEMINI_PUTCHAR('5'); 602 #ifdef KGDB 603 kgdb_port_init(); 604 #endif 605 606 /* Talk to the user */ 607 printf("\nNetBSD/evbarm (gemini) booting ...\n"); 608 609 #ifdef BOOT_ARGS 610 char mi_bootargs[] = BOOT_ARGS; 611 parse_mi_bootargs(mi_bootargs); 612 #endif 613 614 #ifdef VERBOSE_INIT_ARM 615 printf("initarm: Configuring system ...\n"); 616 #endif 617 618 /* 619 * Set up the variables that define the availability of physical 620 * memory. 621 */ 622 gemini_memchk(); 623 physical_start = GEMINI_DRAM_BASE; 624 #define MEMSIZE_BYTES (MEMSIZE * 1024 * 1024) 625 physical_end = (physical_start & ~(0x400000-1)) + MEMSIZE_BYTES; 626 physmem = (physical_end - physical_start) / PAGE_SIZE; 627 628 /* Fake bootconfig structure for the benefit of pmap.c. */ 629 bootconfig.dramblocks = 1; 630 bootconfig.dram[0].address = physical_start; 631 bootconfig.dram[0].pages = physmem; 632 633 kern_vtopdiff = KERNEL_BASE - GEMINI_DRAM_BASE; 634 635 /* 636 * Our kernel is at the beginning of memory, so set our free space to 637 * all the memory after the kernel. 638 */ 639 physical_freestart = KERN_VTOPHYS(round_page((vaddr_t) _end)); 640 physical_freeend = physical_end; 641 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE; 642 643 /* 644 * This is going to do all the hard work of setting up the first and 645 * and second level page tables. Pages of memory will be allocated 646 * and mapped for other structures that are required for system 647 * operation. When it returns, physical_freestart and free_pages will 648 * have been updated to reflect the allocations that were made. In 649 * addition, kernel_l1pt, kernel_pt_table[], systempage, irqstack, 650 * abtstack, undstack, kernelstack, msgbufphys will be set to point to 651 * the memory that was allocated for them. 652 */ 653 setup_real_page_tables(); 654 655 /* 656 * Moved from cpu_startup() as data_abort_handler() references 657 * this during uvm init. 658 */ 659 uvm_lwp_setuarea(&lwp0, kernelstack.pv_va); 660 661 #ifdef VERBOSE_INIT_ARM 662 printf("bootstrap done.\n"); 663 #endif 664 665 arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL); 666 667 /* 668 * Pages were allocated during the secondary bootstrap for the 669 * stacks for different CPU modes. 670 * We must now set the r13 registers in the different CPU modes to 671 * point to these stacks. 672 * Since the ARM stacks use STMFD etc. we must set r13 to the top end 673 * of the stack memory. 674 */ 675 #ifdef VERBOSE_INIT_ARM 676 printf("init subsystems: stacks "); 677 #endif 678 679 set_stackptr(PSR_FIQ32_MODE, fiqstack.pv_va + FIQ_STACK_SIZE * PAGE_SIZE); 680 set_stackptr(PSR_IRQ32_MODE, irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE); 681 set_stackptr(PSR_ABT32_MODE, abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE); 682 set_stackptr(PSR_UND32_MODE, undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE); 683 684 /* 685 * Well we should set a data abort handler. 686 * Once things get going this will change as we will need a proper 687 * handler. 688 * Until then we will use a handler that just panics but tells us 689 * why. 690 * Initialisation of the vectors will just panic on a data abort. 691 * This just fills in a slightly better one. 692 */ 693 #ifdef VERBOSE_INIT_ARM 694 printf("vectors "); 695 #endif 696 data_abort_handler_address = (u_int)data_abort_handler; 697 prefetch_abort_handler_address = (u_int)prefetch_abort_handler; 698 undefined_handler_address = (u_int)undefinedinstruction_bounce; 699 700 /* Initialise the undefined instruction handlers */ 701 #ifdef VERBOSE_INIT_ARM 702 printf("undefined "); 703 #endif 704 undefined_init(); 705 706 /* Load memory into UVM. */ 707 #ifdef VERBOSE_INIT_ARM 708 printf("page "); 709 #endif 710 uvm_md_init(); 711 712 #if (GEMINI_RAM_RESV_PBASE != 0) 713 uvm_page_physload(atop(physical_freestart), atop(GEMINI_RAM_RESV_PBASE), 714 atop(physical_freestart), atop(GEMINI_RAM_RESV_PBASE), 715 VM_FREELIST_DEFAULT); 716 uvm_page_physload(atop(GEMINI_RAM_RESV_PEND), atop(physical_freeend), 717 atop(GEMINI_RAM_RESV_PEND), atop(physical_freeend), 718 VM_FREELIST_DEFAULT); 719 #else 720 uvm_page_physload(atop(physical_freestart), atop(physical_freeend), 721 atop(physical_freestart), atop(physical_freeend), 722 VM_FREELIST_DEFAULT); 723 #endif 724 uvm_page_physload(atop(GEMINI_DRAM_BASE), atop(KERNEL_BASE_phys), 725 atop(GEMINI_DRAM_BASE), atop(KERNEL_BASE_phys), 726 VM_FREELIST_DEFAULT); 727 728 /* Boot strap pmap telling it where managed kernel virtual memory is */ 729 #ifdef VERBOSE_INIT_ARM 730 printf("pmap "); 731 #endif 732 pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE); 733 734 #ifdef VERBOSE_INIT_ARM 735 printf("done.\n"); 736 #endif 737 738 #if defined(MEMORY_DISK_DYNAMIC) 739 md_root_setconf((char *)GEMINI_RAMDISK_VBASE, GEMINI_RAMDISK_SIZE); 740 #endif 741 742 #ifdef KGDB 743 if (boothowto & RB_KDB) { 744 kgdb_debug_init = 1; 745 kgdb_connect(1); 746 } 747 #endif 748 749 #ifdef DDB 750 db_trap_callback = gemini_db_trap; 751 db_machine_init(); 752 753 /* Firmware doesn't load symbols. */ 754 ddb_init(0, NULL, NULL); 755 756 if (boothowto & RB_KDB) 757 Debugger(); 758 #endif 759 printf("initarm done.\n"); 760 761 /* We return the new stack pointer address */ 762 return kernelstack.pv_va + USPACE_SVC_STACK_TOP; 763 } 764 765 static void 766 init_clocks(void) 767 { 768 } 769 770 #ifndef CONSADDR 771 #error Specify the address of the console UART with the CONSADDR option. 772 #endif 773 #ifndef CONSPEED 774 #define CONSPEED 19200 775 #endif 776 #ifndef CONMODE 777 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ 778 #endif 779 780 static const bus_addr_t consaddr = CONSADDR; 781 static const int conspeed = CONSPEED; 782 static const int conmode = CONMODE; 783 784 #if CONSADDR==0x42000000 785 /* 786 * console initialization for obio com console 787 */ 788 void 789 consinit(void) 790 { 791 static int consinit_called = 0; 792 793 if (consinit_called != 0) 794 return; 795 consinit_called = 1; 796 797 if (comcnattach(&gemini_a4x_bs_tag, consaddr, conspeed, 798 GEMINI_COM_FREQ, COM_TYPE_16550_NOERS, conmode)) 799 panic("Serial console can not be initialized."); 800 } 801 802 #elif CONSADDR==0x478003f8 803 # include <arm/gemini/gemini_lpcvar.h> 804 /* 805 * console initialization for lpc com console 806 */ 807 void 808 consinit(void) 809 { 810 static int consinit_called = 0; 811 bus_space_tag_t iot = &gemini_bs_tag; 812 bus_space_handle_t lpchc_ioh; 813 bus_space_handle_t lpcio_ioh; 814 bus_size_t sz = L1_S_SIZE; 815 gemini_lpc_softc_t lpcsoftc; 816 gemini_lpc_bus_ops_t *ops; 817 void *lpctag = &lpcsoftc; 818 uint32_t r; 819 extern gemini_lpc_bus_ops_t gemini_lpc_bus_ops; 820 821 ops = &gemini_lpc_bus_ops; 822 823 if (consinit_called != 0) 824 return; 825 consinit_called = 1; 826 827 if (bus_space_map(iot, GEMINI_LPCHC_BASE, sz, 0, &lpchc_ioh)) 828 panic("consinit: LPCHC can not be mapped."); 829 830 if (bus_space_map(iot, GEMINI_LPCIO_BASE, sz, 0, &lpcio_ioh)) 831 panic("consinit: LPCIO can not be mapped."); 832 833 /* enable the LPC bus */ 834 r = bus_space_read_4(iot, lpchc_ioh, GEMINI_LPCHC_CSR); 835 r |= LPCHC_CSR_BEN; 836 bus_space_write_4(iot, lpchc_ioh, GEMINI_LPCHC_CSR, r); 837 838 memset(&lpcsoftc, 0, sizeof(lpcsoftc)); 839 lpcsoftc.sc_iot = iot; 840 lpcsoftc.sc_ioh = lpcio_ioh; 841 842 /* activate Serial Port 1 */ 843 (*ops->lpc_pnp_enter)(lpctag); 844 (*ops->lpc_pnp_write)(lpctag, 1, 0x30, 0x01); 845 (*ops->lpc_pnp_exit)(lpctag); 846 847 if (comcnattach(iot, consaddr, conspeed, 848 IT8712F_COM_FREQ, COM_TYPE_NORMAL, conmode)) { 849 panic("Serial console can not be initialized."); 850 } 851 852 bus_space_unmap(iot, lpcio_ioh, sz); 853 bus_space_unmap(iot, lpchc_ioh, sz); 854 } 855 #else 856 # error unknown console 857 #endif 858 859 #ifdef KGDB 860 #ifndef KGDB_DEVADDR 861 #error Specify the address of the kgdb UART with the KGDB_DEVADDR option. 862 #endif 863 #ifndef KGDB_DEVRATE 864 #define KGDB_DEVRATE 19200 865 #endif 866 867 #ifndef KGDB_DEVMODE 868 #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ 869 #endif 870 static const vaddr_t comkgdbaddr = KGDB_DEVADDR; 871 static const int comkgdbspeed = KGDB_DEVRATE; 872 static const int comkgdbmode = KGDB_DEVMODE; 873 874 void 875 static kgdb_port_init(void) 876 { 877 static int kgdbsinit_called = 0; 878 879 if (kgdbsinit_called != 0) 880 return; 881 882 kgdbsinit_called = 1; 883 884 bus_space_handle_t bh; 885 if (bus_space_map(&gemini_a4x_bs_tag, comkgdbaddr, 886 GEMINI_UART_SIZE, 0, &bh)) 887 panic("kgdb port can not be mapped."); 888 889 if (com_kgdb_attach(&gemini_a4x_bs_tag, comkgdbaddr, comkgdbspeed, 890 GEMINI_UART_SIZE, COM_TYPE_16550_NOERS, comkgdbmode)) 891 panic("KGDB uart can not be initialized."); 892 893 bus_space_unmap(&gemini_a4x_bs_tag, bh, GEMINI_UART_SIZE); 894 } 895 #endif 896 897 static void 898 setup_real_page_tables(void) 899 { 900 /* 901 * We need to allocate some fixed page tables to get the kernel going. 902 * 903 * We are going to allocate our bootstrap pages from the beginning of 904 * the free space that we just calculated. We allocate one page 905 * directory and a number of page tables and store the physical 906 * addresses in the kernel_pt_table array. 907 * 908 * The kernel page directory must be on a 16K boundary. The page 909 * tables must be on 4K boundaries. What we do is allocate the 910 * page directory on the first 16K boundary that we encounter, and 911 * the page tables on 4K boundaries otherwise. Since we allocate 912 * at least 3 L2 page tables, we are guaranteed to encounter at 913 * least one 16K aligned region. 914 */ 915 916 #ifdef VERBOSE_INIT_ARM 917 printf("Allocating page tables\n"); 918 #endif 919 920 /* 921 * Define a macro to simplify memory allocation. As we allocate the 922 * memory, make sure that we don't walk over our temporary first level 923 * translation table. 924 */ 925 #define valloc_pages(var, np) \ 926 (var).pv_pa = physical_freestart; \ 927 physical_freestart += ((np) * PAGE_SIZE); \ 928 if (physical_freestart > (physical_freeend - L1_TABLE_SIZE)) \ 929 panic("initarm: out of memory"); \ 930 free_pages -= (np); \ 931 (var).pv_va = KERN_PHYSTOV((var).pv_pa); \ 932 memset((char *)(var).pv_va, 0, ((np) * PAGE_SIZE)); 933 934 int loop, pt_index; 935 936 pt_index = 0; 937 kernel_l1pt.pv_pa = 0; 938 kernel_l1pt.pv_va = 0; 939 #ifdef VERBOSE_INIT_ARM 940 printf("%s: physical_freestart %#lx\n", __func__, physical_freestart); 941 #endif 942 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) { 943 /* Are we 16KB aligned for an L1 ? */ 944 if ((physical_freestart & (L1_TABLE_SIZE - 1)) == 0 945 && kernel_l1pt.pv_pa == 0) { 946 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE); 947 } else { 948 valloc_pages(kernel_pt_table[pt_index], 949 L2_TABLE_SIZE / PAGE_SIZE); 950 ++pt_index; 951 } 952 } 953 954 #if (NGEMINIIPM > 0) 955 valloc_pages(ipmq_pt, L2_TABLE_SIZE / PAGE_SIZE); 956 #endif 957 958 #ifdef VERBOSE_INIT_ARM 959 pt_index=0; 960 printf("%s: kernel_l1pt: %#lx:%#lx\n", 961 __func__, kernel_l1pt.pv_va, kernel_l1pt.pv_pa); 962 printf("%s: kernel_pt_table:\n", __func__); 963 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) { 964 printf("\t%#lx:%#lx\n", kernel_pt_table[pt_index].pv_va, 965 kernel_pt_table[pt_index].pv_pa); 966 ++pt_index; 967 } 968 #if (NGEMINIIPM > 0) 969 printf("%s: ipmq_pt:\n", __func__); 970 printf("\t%#lx:%#lx\n", ipmq_pt.pv_va, ipmq_pt.pv_pa); 971 #endif 972 #endif 973 974 /* This should never be able to happen but better confirm that. */ 975 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0) 976 panic("initarm: Failed to align the kernel page directory"); 977 978 /* 979 * Allocate a page for the system page mapped to V0x00000000 980 * This page will just contain the system vectors and can be 981 * shared by all processes. 982 */ 983 valloc_pages(systempage, 1); 984 systempage.pv_va = ARM_VECTORS_HIGH; 985 986 /* Allocate stacks for all modes */ 987 valloc_pages(fiqstack, FIQ_STACK_SIZE); 988 valloc_pages(irqstack, IRQ_STACK_SIZE); 989 valloc_pages(abtstack, ABT_STACK_SIZE); 990 valloc_pages(undstack, UND_STACK_SIZE); 991 valloc_pages(kernelstack, UPAGES); 992 993 /* Allocate the message buffer. */ 994 pv_addr_t msgbuf; 995 int msgbuf_pgs = round_page(MSGBUFSIZE) / PAGE_SIZE; 996 valloc_pages(msgbuf, msgbuf_pgs); 997 msgbufphys = msgbuf.pv_pa; 998 999 /* 1000 * Ok we have allocated physical pages for the primary kernel 1001 * page tables 1002 */ 1003 1004 #ifdef VERBOSE_INIT_ARM 1005 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa); 1006 #endif 1007 1008 /* 1009 * Now we start construction of the L1 page table 1010 * We start by mapping the L2 page tables into the L1. 1011 * This means that we can replace L1 mappings later on if necessary 1012 */ 1013 vaddr_t l1_va = kernel_l1pt.pv_va; 1014 paddr_t l1_pa = kernel_l1pt.pv_pa; 1015 1016 /* Map the L2 pages tables in the L1 page table */ 1017 pmap_link_l2pt(l1_va, ARM_VECTORS_HIGH & ~(0x00400000 - 1), 1018 &kernel_pt_table[KERNEL_PT_SYS]); 1019 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++) 1020 pmap_link_l2pt(l1_va, KERNEL_BASE + loop * 0x00400000, 1021 &kernel_pt_table[KERNEL_PT_KERNEL + loop]); 1022 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++) 1023 pmap_link_l2pt(l1_va, KERNEL_VM_BASE + loop * 0x00400000, 1024 &kernel_pt_table[KERNEL_PT_VMDATA + loop]); 1025 1026 /* update the top of the kernel VM */ 1027 pmap_curmaxkvaddr = 1028 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000); 1029 1030 #if (NGEMINIIPM > 0) 1031 printf("%s:%d: pmap_link_l2pt ipmq_pt\n", __FUNCTION__, __LINE__); 1032 pmap_link_l2pt(l1_va, GEMINI_IPMQ_VBASE, &ipmq_pt); 1033 #endif 1034 1035 #ifdef VERBOSE_INIT_ARM 1036 printf("Mapping kernel\n"); 1037 #endif 1038 1039 /* Now we fill in the L2 pagetable for the kernel static code/data */ 1040 #define round_L_page(x) (((x) + L2_L_OFFSET) & L2_L_FRAME) 1041 size_t textsize = round_L_page(etext - KERNEL_BASE_virt); 1042 size_t totalsize = round_L_page(_end - KERNEL_BASE_virt); 1043 /* offset of kernel in RAM */ 1044 u_int offset = (u_int)KERNEL_BASE_virt - KERNEL_BASE; 1045 1046 #ifdef DDB 1047 /* Map text section read-write. */ 1048 offset += pmap_map_chunk(l1_va, 1049 (vaddr_t)KERNEL_BASE + offset, 1050 physical_start + offset, textsize, 1051 VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE, 1052 PTE_CACHE); 1053 #else 1054 /* Map text section read-only. */ 1055 offset += pmap_map_chunk(l1_va, 1056 (vaddr_t)KERNEL_BASE + offset, 1057 physical_start + offset, textsize, 1058 VM_PROT_READ|VM_PROT_EXECUTE, PTE_CACHE); 1059 #endif 1060 /* Map data and bss sections read-write. */ 1061 offset += pmap_map_chunk(l1_va, 1062 (vaddr_t)KERNEL_BASE + offset, 1063 physical_start + offset, totalsize - textsize, 1064 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 1065 1066 #ifdef VERBOSE_INIT_ARM 1067 printf("Constructing L2 page tables\n"); 1068 #endif 1069 1070 /* Map the stack pages */ 1071 pmap_map_chunk(l1_va, fiqstack.pv_va, fiqstack.pv_pa, 1072 FIQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 1073 pmap_map_chunk(l1_va, irqstack.pv_va, irqstack.pv_pa, 1074 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 1075 pmap_map_chunk(l1_va, abtstack.pv_va, abtstack.pv_pa, 1076 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 1077 pmap_map_chunk(l1_va, undstack.pv_va, undstack.pv_pa, 1078 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 1079 pmap_map_chunk(l1_va, kernelstack.pv_va, kernelstack.pv_pa, 1080 UPAGES * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE); 1081 1082 pmap_map_chunk(l1_va, kernel_l1pt.pv_va, kernel_l1pt.pv_pa, 1083 L1_TABLE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_PAGETABLE); 1084 1085 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) { 1086 pmap_map_chunk(l1_va, kernel_pt_table[loop].pv_va, 1087 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE, 1088 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE); 1089 } 1090 1091 /* Map the vector page. */ 1092 pmap_map_entry(l1_va, ARM_VECTORS_HIGH, systempage.pv_pa, 1093 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 1094 1095 #if (NGEMINIIPM > 0) 1096 /* Map the IPM queue l2pt */ 1097 pmap_map_chunk(l1_va, ipmq_pt.pv_va, ipmq_pt.pv_pa, 1098 L2_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE); 1099 1100 /* Map the IPM queue pages */ 1101 pmap_map_chunk(l1_va, GEMINI_IPMQ_VBASE, GEMINI_IPMQ_PBASE, 1102 GEMINI_IPMQ_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE); 1103 1104 #ifdef GEMINI_SLAVE 1105 /* 1106 * Map all memory, incluuding that owned by other core 1107 * take into account the RAM remap, so view in this region 1108 * is consistent with MASTER 1109 */ 1110 pmap_map_chunk(l1_va, 1111 GEMINI_ALLMEM_VBASE, 1112 GEMINI_ALLMEM_PBASE + ((GEMINI_ALLMEM_SIZE - MEMSIZE) * 1024 * 1024), 1113 (GEMINI_ALLMEM_SIZE - MEMSIZE) * 1024 * 1024, 1114 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 1115 pmap_map_chunk(l1_va, 1116 GEMINI_ALLMEM_VBASE + GEMINI_BUSBASE * 1024 * 1024, 1117 GEMINI_ALLMEM_PBASE, 1118 (MEMSIZE * 1024 * 1024), 1119 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 1120 #else 1121 /* Map all memory, incluuding that owned by other core */ 1122 pmap_map_chunk(l1_va, GEMINI_ALLMEM_VBASE, GEMINI_ALLMEM_PBASE, 1123 GEMINI_ALLMEM_SIZE * 1024 * 1024, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 1124 #endif /* GEMINI_SLAVE */ 1125 #endif /* NGEMINIIPM */ 1126 1127 /* 1128 * Map integrated peripherals at same address in first level page 1129 * table so that we can continue to use console. 1130 */ 1131 pmap_devmap_bootstrap(l1_va, devmap); 1132 1133 1134 #ifdef VERBOSE_INIT_ARM 1135 /* Tell the user about where all the bits and pieces live. */ 1136 printf("%22s Physical Virtual Num\n", " "); 1137 printf("%22s Starting Ending Starting Ending Pages\n", " "); 1138 1139 static const char mem_fmt[] = 1140 "%20s: 0x%08lx 0x%08lx 0x%08lx 0x%08lx %d\n"; 1141 static const char mem_fmt_nov[] = 1142 "%20s: 0x%08lx 0x%08lx %d\n"; 1143 1144 printf(mem_fmt, "SDRAM", physical_start, physical_end-1, 1145 KERN_PHYSTOV(physical_start), KERN_PHYSTOV(physical_end-1), 1146 (int)physmem); 1147 printf(mem_fmt, "text section", 1148 KERN_VTOPHYS((vaddr_t)KERNEL_BASE_virt), KERN_VTOPHYS((vaddr_t)etext-1), 1149 (vaddr_t)KERNEL_BASE_virt, (vaddr_t)etext-1, 1150 (int)(textsize / PAGE_SIZE)); 1151 printf(mem_fmt, "data section", 1152 KERN_VTOPHYS((vaddr_t)__data_start), KERN_VTOPHYS((vaddr_t)_edata), 1153 (vaddr_t)__data_start, (vaddr_t)_edata, 1154 (int)((round_page((vaddr_t)_edata) 1155 - trunc_page((vaddr_t)__data_start)) / PAGE_SIZE)); 1156 printf(mem_fmt, "bss section", 1157 KERN_VTOPHYS((vaddr_t)__bss_start), KERN_VTOPHYS((vaddr_t)__bss_end__), 1158 (vaddr_t)__bss_start, (vaddr_t)__bss_end__, 1159 (int)((round_page((vaddr_t)__bss_end__) 1160 - trunc_page((vaddr_t)__bss_start)) / PAGE_SIZE)); 1161 printf(mem_fmt, "L1 page directory", 1162 kernel_l1pt.pv_pa, kernel_l1pt.pv_pa + L1_TABLE_SIZE - 1, 1163 kernel_l1pt.pv_va, kernel_l1pt.pv_va + L1_TABLE_SIZE - 1, 1164 L1_TABLE_SIZE / PAGE_SIZE); 1165 printf(mem_fmt, "Exception Vectors", 1166 systempage.pv_pa, systempage.pv_pa + PAGE_SIZE - 1, 1167 (vaddr_t)ARM_VECTORS_HIGH, (vaddr_t)ARM_VECTORS_HIGH + PAGE_SIZE - 1, 1168 1); 1169 printf(mem_fmt, "FIQ stack", 1170 fiqstack.pv_pa, fiqstack.pv_pa + (FIQ_STACK_SIZE * PAGE_SIZE) - 1, 1171 fiqstack.pv_va, fiqstack.pv_va + (FIQ_STACK_SIZE * PAGE_SIZE) - 1, 1172 FIQ_STACK_SIZE); 1173 printf(mem_fmt, "IRQ stack", 1174 irqstack.pv_pa, irqstack.pv_pa + (IRQ_STACK_SIZE * PAGE_SIZE) - 1, 1175 irqstack.pv_va, irqstack.pv_va + (IRQ_STACK_SIZE * PAGE_SIZE) - 1, 1176 IRQ_STACK_SIZE); 1177 printf(mem_fmt, "ABT stack", 1178 abtstack.pv_pa, abtstack.pv_pa + (ABT_STACK_SIZE * PAGE_SIZE) - 1, 1179 abtstack.pv_va, abtstack.pv_va + (ABT_STACK_SIZE * PAGE_SIZE) - 1, 1180 ABT_STACK_SIZE); 1181 printf(mem_fmt, "UND stack", 1182 undstack.pv_pa, undstack.pv_pa + (UND_STACK_SIZE * PAGE_SIZE) - 1, 1183 undstack.pv_va, undstack.pv_va + (UND_STACK_SIZE * PAGE_SIZE) - 1, 1184 UND_STACK_SIZE); 1185 printf(mem_fmt, "SVC stack", 1186 kernelstack.pv_pa, kernelstack.pv_pa + (UPAGES * PAGE_SIZE) - 1, 1187 kernelstack.pv_va, kernelstack.pv_va + (UPAGES * PAGE_SIZE) - 1, 1188 UPAGES); 1189 printf(mem_fmt_nov, "Message Buffer", 1190 msgbufphys, msgbufphys + msgbuf_pgs * PAGE_SIZE - 1, msgbuf_pgs); 1191 printf(mem_fmt, "Free Memory", physical_freestart, physical_freeend-1, 1192 KERN_PHYSTOV(physical_freestart), KERN_PHYSTOV(physical_freeend-1), 1193 free_pages); 1194 #endif 1195 1196 /* 1197 * Now we have the real page tables in place so we can switch to them. 1198 * Once this is done we will be running with the REAL kernel page 1199 * tables. 1200 */ 1201 1202 /* Switch tables */ 1203 #ifdef VERBOSE_INIT_ARM 1204 printf("switching to new L1 page table @%#lx...", l1_pa); 1205 #endif 1206 1207 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT); 1208 cpu_setttb(l1_pa, true); 1209 cpu_tlb_flushID(); 1210 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)); 1211 1212 #ifdef VERBOSE_INIT_ARM 1213 printf("OK.\n"); 1214 #endif 1215 } 1216