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