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