1 /* $NetBSD: ixdp425_machdep.c,v 1.37 2016/12/22 14:47:55 cherry Exp $ */ 2 /* 3 * Copyright (c) 2003 4 * Ichiro FUKUHARA <ichiro@ichiro.org>. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR 20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 /* 29 * Copyright (c) 1997,1998 Mark Brinicombe. 30 * Copyright (c) 1997,1998 Causality Limited. 31 * All rights reserved. 32 * 33 * Redistribution and use in source and binary forms, with or without 34 * modification, are permitted provided that the following conditions 35 * are met: 36 * 1. Redistributions of source code must retain the above copyright 37 * notice, this list of conditions and the following disclaimer. 38 * 2. Redistributions in binary form must reproduce the above copyright 39 * notice, this list of conditions and the following disclaimer in the 40 * documentation and/or other materials provided with the distribution. 41 * 3. All advertising materials mentioning features or use of this software 42 * must display the following acknowledgement: 43 * This product includes software developed by Mark Brinicombe 44 * for the NetBSD Project. 45 * 4. The name of the company nor the name of the author may be used to 46 * endorse or promote products derived from this software without specific 47 * prior written permission. 48 * 49 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 50 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 51 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 52 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 53 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 54 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 55 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 59 * SUCH DAMAGE. 60 */ 61 62 /* Machine dependent functions for kernel setup for Intel IXP425 evaluation 63 * boards using RedBoot firmware. 64 */ 65 66 #include <sys/cdefs.h> 67 __KERNEL_RCSID(0, "$NetBSD: ixdp425_machdep.c,v 1.37 2016/12/22 14:47:55 cherry Exp $"); 68 69 #include "opt_ddb.h" 70 #include "opt_kgdb.h" 71 #include "opt_pmap_debug.h" 72 73 #include <sys/param.h> 74 #include <sys/device.h> 75 #include <sys/systm.h> 76 #include <sys/kernel.h> 77 #include <sys/exec.h> 78 #include <sys/proc.h> 79 #include <sys/msgbuf.h> 80 #include <sys/reboot.h> 81 #include <sys/termios.h> 82 #include <sys/ksyms.h> 83 #include <sys/bus.h> 84 #include <sys/cpu.h> 85 86 #include <uvm/uvm_extern.h> 87 88 #include <dev/cons.h> 89 90 #include <machine/db_machdep.h> 91 #include <ddb/db_sym.h> 92 #include <ddb/db_extern.h> 93 94 #include <machine/bootconfig.h> 95 #include <arm/locore.h> 96 #include <arm/undefined.h> 97 98 #include <arm/arm32/machdep.h> 99 100 #include <arm/xscale/ixp425reg.h> 101 #include <arm/xscale/ixp425var.h> 102 #include <arm/xscale/ixp425_sipvar.h> 103 104 #include <evbarm/ixdp425/ixdp425reg.h> 105 106 #include "com.h" 107 #if NCOM > 0 108 #include <dev/ic/comreg.h> 109 #include <dev/ic/comvar.h> 110 #endif 111 112 #include "ksyms.h" 113 114 /* Kernel text starts 2MB in from the bottom of the kernel address space. */ 115 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000) 116 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000) 117 118 /* 119 * The range 0xc1000000 - 0xccffffff is available for kernel VM space 120 * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff 121 */ 122 #define KERNEL_VM_SIZE 0x0C000000 123 124 BootConfig bootconfig; /* Boot config storage */ 125 char *boot_args = NULL; 126 char *boot_file = NULL; 127 128 vaddr_t physical_start; 129 vaddr_t physical_freestart; 130 vaddr_t physical_freeend; 131 vaddr_t physical_end; 132 u_int free_pages; 133 134 /* Physical and virtual addresses for some global pages */ 135 pv_addr_t minidataclean; 136 137 paddr_t msgbufphys; 138 139 extern int end; 140 141 #ifdef PMAP_DEBUG 142 extern int pmap_debug_level; 143 #endif 144 145 #define KERNEL_PT_SYS 0 /* L2 table for mapping zero page */ 146 147 #define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */ 148 #define KERNEL_PT_KERNEL_NUM 4 149 #define KERNEL_PT_IO (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM) 150 /* L2 tables for mapping kernel VM */ 151 #define KERNEL_PT_VMDATA (KERNEL_PT_IO + 1) 152 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */ 153 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM) 154 155 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS]; 156 157 /* Prototypes */ 158 159 void consinit(void); 160 u_int cpu_get_control(void); 161 162 /* 163 * Define the default console speed for the board. This is generally 164 * what the firmware provided with the board defaults to. 165 */ 166 #ifndef CONSPEED 167 #define CONSPEED B115200 168 #endif /* ! CONSPEED */ 169 170 #ifndef CONUNIT 171 #define CONUNIT 0 172 #endif 173 174 #ifndef CONMODE 175 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB)) | CS8) /* 8N1 */ 176 #endif 177 178 int comcnspeed = CONSPEED; 179 int comcnmode = CONMODE; 180 int comcnunit = CONUNIT; 181 182 #if KGDB 183 #ifndef KGDB_DEVNAME 184 #error Must define KGDB_DEVNAME 185 #endif 186 const char kgdb_devname[] = KGDB_DEVNAME; 187 188 #ifndef KGDB_DEVADDR 189 #error Must define KGDB_DEVADDR 190 #endif 191 unsigned long kgdb_devaddr = KGDB_DEVADDR; 192 193 #ifndef KGDB_DEVRATE 194 #define KGDB_DEVRATE CONSPEED 195 #endif 196 int kgdb_devrate = KGDB_DEVRATE; 197 198 #ifndef KGDB_DEVMODE 199 #define KGDB_DEVMODE CONMODE 200 #endif 201 int kgdb_devmode = KGDB_DEVMODE; 202 #endif /* KGDB */ 203 204 /* 205 * void cpu_reboot(int howto, char *bootstr) 206 * 207 * Reboots the system 208 * 209 * Deal with any syncing, unmounting, dumping and shutdown hooks, 210 * then reset the CPU. 211 */ 212 void 213 cpu_reboot(int howto, char *bootstr) 214 { 215 uint32_t reg; 216 217 #ifdef DIAGNOSTIC 218 /* info */ 219 printf("boot: howto=%08x curproc=%p\n", howto, curproc); 220 #endif 221 222 /* 223 * If we are still cold then hit the air brakes 224 * and crash to earth fast 225 */ 226 if (cold) { 227 doshutdownhooks(); 228 pmf_system_shutdown(boothowto); 229 printf("The operating system has halted.\n"); 230 printf("Please press any key to reboot.\n\n"); 231 cngetc(); 232 printf("rebooting...\n"); 233 goto reset; 234 } 235 236 /* Disable console buffering */ 237 238 /* 239 * If RB_NOSYNC was not specified sync the discs. 240 * Note: Unless cold is set to 1 here, syslogd will die during the 241 * unmount. It looks like syslogd is getting woken up only to find 242 * that it cannot page part of the binary in as the filesystem has 243 * been unmounted. 244 */ 245 if (!(howto & RB_NOSYNC)) 246 bootsync(); 247 248 /* Say NO to interrupts */ 249 splhigh(); 250 251 /* Do a dump if requested. */ 252 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) 253 dumpsys(); 254 255 /* Run any shutdown hooks */ 256 doshutdownhooks(); 257 258 pmf_system_shutdown(boothowto); 259 260 /* Make sure IRQ's are disabled */ 261 IRQdisable; 262 263 if (howto & RB_HALT) { 264 printf("The operating system has halted.\n"); 265 printf("Please press any key to reboot.\n\n"); 266 cngetc(); 267 } 268 269 printf("rebooting...\n\r"); 270 reset: 271 /* 272 * Make really really sure that all interrupts are disabled, 273 */ 274 (void) disable_interrupts(I32_bit|F32_bit); 275 IXPREG(IXP425_INT_ENABLE) = 0; 276 277 /* 278 * Map the boot Flash device down at physical address 0. 279 * This is safe since NetBSD runs out of an alias of 280 * SDRAM at 0x10000000. 281 */ 282 reg = EXP_CSR_READ_4(ixpsip_softc, EXP_CNFG0_OFFSET); 283 reg |= EXP_CNFG0_MEM_MAP; 284 EXP_CSR_WRITE_4(ixpsip_softc, EXP_CNFG0_OFFSET, reg); 285 286 /* 287 * Jump into the bootcode's reset vector 288 * 289 * XXX: 290 * Redboot doesn't like the state in which we leave the PCI 291 * ethernet card, and so fails to detect it on reboot. This 292 * pretty much necessitates a hard reset/power cycle to be 293 * able to download a new kernel image over ethernet. 294 * 295 * I suspect this is due to a bug in Redboot's i82557 driver. 296 */ 297 cpu_reset(); 298 299 /* ...and if that didn't work, just croak. */ 300 printf("RESET FAILED!\n"); 301 for (;;); 302 } 303 304 /* Static device mappings. */ 305 static const struct pmap_devmap ixp425_devmap[] = { 306 /* Physical/Virtual address for I/O space */ 307 { 308 IXP425_IO_VBASE, 309 IXP425_IO_HWBASE, 310 IXP425_IO_SIZE, 311 VM_PROT_READ|VM_PROT_WRITE, 312 PTE_NOCACHE, 313 }, 314 315 /* Expansion Bus */ 316 { 317 IXP425_EXP_VBASE, 318 IXP425_EXP_HWBASE, 319 IXP425_EXP_SIZE, 320 VM_PROT_READ|VM_PROT_WRITE, 321 PTE_NOCACHE, 322 }, 323 324 /* IXP425 PCI Configuration */ 325 { 326 IXP425_PCI_VBASE, 327 IXP425_PCI_HWBASE, 328 IXP425_PCI_SIZE, 329 VM_PROT_READ|VM_PROT_WRITE, 330 PTE_NOCACHE, 331 }, 332 333 /* SDRAM Controller */ 334 { 335 IXP425_MCU_VBASE, 336 IXP425_MCU_HWBASE, 337 IXP425_MCU_SIZE, 338 VM_PROT_READ|VM_PROT_WRITE, 339 PTE_NOCACHE, 340 }, 341 342 /* PCI Memory Space */ 343 { 344 IXP425_PCI_MEM_VBASE, 345 IXP425_PCI_MEM_HWBASE, 346 IXP425_PCI_MEM_SIZE, 347 VM_PROT_READ|VM_PROT_WRITE, 348 PTE_NOCACHE, 349 }, 350 351 { 352 0, 353 0, 354 0, 355 0, 356 0, 357 } 358 }; 359 360 /* 361 * u_int initarm(...) 362 * 363 * Initial entry point on startup. This gets called before main() is 364 * entered. 365 * It should be responsible for setting up everything that must be 366 * in place when main is called. 367 * This includes 368 * Taking a copy of the boot configuration structure. 369 * Initialising the physical console so characters can be printed. 370 * Setting up page tables for the kernel 371 * Relocating the kernel to the bottom of physical memory 372 */ 373 u_int 374 initarm(void *arg) 375 { 376 extern vaddr_t xscale_cache_clean_addr; 377 #ifdef DIAGNOSTIC 378 extern vsize_t xscale_minidata_clean_size; 379 #endif 380 int loop; 381 int loop1; 382 u_int kerneldatasize; 383 u_int l1pagetable; 384 u_int freemempos; 385 386 /* 387 * Since we map v0xf0000000 == p0xc8000000, it's possible for 388 * us to initialize the console now. 389 */ 390 consinit(); 391 392 #ifdef VERBOSE_INIT_ARM 393 /* Talk to the user */ 394 printf("\nNetBSD/evbarm (Intel IXDP425) booting ...\n"); 395 #endif 396 397 /* 398 * Heads up ... Setup the CPU / MMU / TLB functions 399 */ 400 if (set_cpufuncs()) 401 panic("cpu not recognized!"); 402 403 /* XXX overwrite bootconfig to hardcoded values */ 404 bootconfig.dramblocks = 1; 405 bootconfig.dram[0].address = 0x10000000; 406 bootconfig.dram[0].pages = ixp425_sdram_size() / PAGE_SIZE; 407 408 kerneldatasize = (uint32_t)&end - (uint32_t)KERNEL_TEXT_BASE; 409 410 #ifdef VERBOSE_INIT_ARM 411 printf("kernsize=0x%x\n", kerneldatasize); 412 #endif 413 kerneldatasize = ((kerneldatasize - 1) & ~(PAGE_SIZE * 4 - 1)) + PAGE_SIZE * 8; 414 415 /* 416 * Set up the variables that define the availablilty of 417 * physical memory. For now, we're going to set 418 * physical_freestart to 0x10200000 (where the kernel 419 * was loaded), and allocate the memory we need downwards. 420 * If we get too close to the L1 table that we set up, we 421 * will panic. We will update physical_freestart and 422 * physical_freeend later to reflect what pmap_bootstrap() 423 * wants to see. 424 * 425 * XXX pmap_bootstrap() needs an enema. 426 */ 427 physical_start = bootconfig.dram[0].address; 428 physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE); 429 430 physical_freestart = physical_start 431 + (KERNEL_TEXT_BASE - KERNEL_BASE) + kerneldatasize; 432 physical_freeend = physical_end; 433 434 physmem = (physical_end - physical_start) / PAGE_SIZE; 435 436 /* Tell the user about the memory */ 437 #ifdef VERBOSE_INIT_ARM 438 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem, 439 physical_start, physical_end - 1); 440 441 printf("Allocating page tables\n"); 442 #endif 443 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE; 444 445 freemempos = 0x10000000; 446 447 #ifdef VERBOSE_INIT_ARM 448 printf("physical_start = 0x%08lx, physical_end = 0x%08lx\n", 449 physical_start, physical_end); 450 #endif 451 452 /* Define a macro to simplify memory allocation */ 453 #define valloc_pages(var, np) \ 454 alloc_pages((var).pv_pa, (np)); \ 455 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start; 456 457 #if 0 458 #define alloc_pages(var, np) \ 459 physical_freeend -= ((np) * PAGE_SIZE); \ 460 if (physical_freeend < physical_freestart) \ 461 panic("initarm: out of memory"); \ 462 (var) = physical_freeend; \ 463 free_pages -= (np); \ 464 memset((char *)(var), 0, ((np) * PAGE_SIZE)); 465 #else 466 #define alloc_pages(var, np) \ 467 (var) = freemempos; \ 468 memset((char *)(var), 0, ((np) * PAGE_SIZE)); \ 469 freemempos += (np) * PAGE_SIZE; 470 #endif 471 472 loop1 = 0; 473 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) { 474 /* Are we 16KB aligned for an L1 ? */ 475 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0 476 && kernel_l1pt.pv_pa == 0) { 477 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE); 478 } else { 479 valloc_pages(kernel_pt_table[loop1], 480 L2_TABLE_SIZE / PAGE_SIZE); 481 ++loop1; 482 } 483 } 484 485 /* This should never be able to happen but better confirm that. */ 486 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0) 487 panic("initarm: Failed to align the kernel page directory"); 488 489 /* 490 * Allocate a page for the system page. 491 * This page will just contain the system vectors and can be 492 * shared by all processes. 493 */ 494 alloc_pages(systempage.pv_pa, 1); 495 496 /* Allocate stacks for all modes */ 497 valloc_pages(irqstack, IRQ_STACK_SIZE); 498 valloc_pages(abtstack, ABT_STACK_SIZE); 499 valloc_pages(undstack, UND_STACK_SIZE); 500 valloc_pages(kernelstack, UPAGES); 501 502 /* Allocate enough pages for cleaning the Mini-Data cache. */ 503 KASSERT(xscale_minidata_clean_size <= PAGE_SIZE); 504 valloc_pages(minidataclean, 1); 505 506 #ifdef VERBOSE_INIT_ARM 507 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa, 508 irqstack.pv_va); 509 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa, 510 abtstack.pv_va); 511 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa, 512 undstack.pv_va); 513 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa, 514 kernelstack.pv_va); 515 #endif 516 517 /* 518 * XXX Defer this to later so that we can reclaim the memory 519 * XXX used by the RedBoot page tables. 520 */ 521 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE); 522 523 /* 524 * Ok we have allocated physical pages for the primary kernel 525 * page tables 526 */ 527 528 #ifdef VERBOSE_INIT_ARM 529 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa); 530 #endif 531 532 /* 533 * Now we start construction of the L1 page table 534 * We start by mapping the L2 page tables into the L1. 535 * This means that we can replace L1 mappings later on if necessary 536 */ 537 l1pagetable = kernel_l1pt.pv_pa; 538 539 /* Map the L2 pages tables in the L1 page table */ 540 pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1), 541 &kernel_pt_table[KERNEL_PT_SYS]); 542 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++) 543 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000, 544 &kernel_pt_table[KERNEL_PT_KERNEL + loop]); 545 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++) 546 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000, 547 &kernel_pt_table[KERNEL_PT_VMDATA + loop]); 548 549 /* update the top of the kernel VM */ 550 pmap_curmaxkvaddr = 551 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000); 552 553 pmap_link_l2pt(l1pagetable, IXP425_IO_VBASE, 554 &kernel_pt_table[KERNEL_PT_IO]); 555 556 #ifdef VERBOSE_INIT_ARM 557 printf("Mapping kernel\n"); 558 #endif 559 560 /* Now we fill in the L2 pagetable for the kernel static code/data */ 561 { 562 extern char etext[], _end[]; 563 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE; 564 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE; 565 u_int logical; 566 567 textsize = (textsize + PGOFSET) & ~PGOFSET; 568 totalsize = (totalsize + PGOFSET) & ~PGOFSET; 569 570 logical = 0x00200000; /* offset of kernel in RAM */ 571 572 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical, 573 physical_start + logical, textsize, 574 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 575 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical, 576 physical_start + logical, totalsize - textsize, 577 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 578 } 579 580 #ifdef VERBOSE_INIT_ARM 581 printf("Constructing L2 page tables\n"); 582 #endif 583 584 /* Map the stack pages */ 585 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa, 586 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 587 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa, 588 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 589 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa, 590 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 591 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa, 592 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 593 594 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa, 595 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE); 596 597 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) { 598 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va, 599 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE, 600 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE); 601 } 602 603 /* Map the Mini-Data cache clean area. */ 604 xscale_setup_minidata(l1pagetable, minidataclean.pv_va, 605 minidataclean.pv_pa); 606 607 /* Map the vector page. */ 608 pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa, 609 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 610 611 /* 612 * Map the IXP425 registers 613 */ 614 pmap_devmap_bootstrap(l1pagetable, ixp425_devmap); 615 616 /* 617 * Give the XScale global cache clean code an appropriately 618 * sized chunk of unmapped VA space starting at 0xff000000 619 * (our device mappings end before this address). 620 */ 621 xscale_cache_clean_addr = 0xff000000U; 622 623 /* 624 * Now we have the real page tables in place so we can switch to them. 625 * Once this is done we will be running with the REAL kernel page 626 * tables. 627 */ 628 629 /* 630 * Update the physical_freestart/physical_freeend/free_pages 631 * variables. 632 */ 633 { 634 extern char _end[]; 635 636 physical_freestart = physical_start + 637 (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) - 638 KERNEL_BASE); 639 physical_freeend = physical_end; 640 free_pages = 641 (physical_freeend - physical_freestart) / PAGE_SIZE; 642 } 643 644 /* Switch tables */ 645 #ifdef VERBOSE_INIT_ARM 646 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n", 647 physical_freestart, free_pages, free_pages); 648 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa); 649 #endif 650 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT); 651 cpu_setttb(kernel_l1pt.pv_pa, true); 652 cpu_tlb_flushID(); 653 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)); 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_IRQ32_MODE, 680 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE); 681 set_stackptr(PSR_ABT32_MODE, 682 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE); 683 set_stackptr(PSR_UND32_MODE, 684 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE); 685 686 /* 687 * Well we should set a data abort handler. 688 * Once things get going this will change as we will need a proper 689 * handler. 690 * Until then we will use a handler that just panics but tells us 691 * why. 692 * Initialisation of the vectors will just panic on a data abort. 693 * This just fills in a slightly better one. 694 */ 695 #ifdef VERBOSE_INIT_ARM 696 printf("vectors "); 697 #endif 698 data_abort_handler_address = (u_int)data_abort_handler; 699 prefetch_abort_handler_address = (u_int)prefetch_abort_handler; 700 undefined_handler_address = (u_int)undefinedinstruction_bounce; 701 702 /* Initialise the undefined instruction handlers */ 703 #ifdef VERBOSE_INIT_ARM 704 printf("undefined "); 705 #endif 706 undefined_init(); 707 708 /* Load memory into UVM. */ 709 #ifdef VERBOSE_INIT_ARM 710 printf("page "); 711 #endif 712 uvm_md_init(); 713 uvm_page_physload(atop(physical_freestart), atop(physical_freeend), 714 atop(physical_freestart), atop(physical_freeend), 715 VM_FREELIST_DEFAULT); 716 717 /* Boot strap pmap telling it where the kernel page table is */ 718 #ifdef VERBOSE_INIT_ARM 719 printf("pmap "); 720 #endif 721 pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE); 722 723 /* Setup the IRQ system */ 724 #ifdef VERBOSE_INIT_ARM 725 printf("irq "); 726 #endif 727 ixp425_intr_init(); 728 #ifdef VERBOSE_INIT_ARM 729 printf("\nAll initialization done!\nNow Starting NetBSD, Here we go!\n"); 730 #endif 731 732 #ifdef BOOTHOWTO 733 boothowto = BOOTHOWTO; 734 #endif 735 736 #ifdef DDB 737 db_machine_init(); 738 if (boothowto & RB_KDB) 739 Debugger(); 740 #endif 741 742 /* We return the new stack pointer address */ 743 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP); 744 } 745 746 /* 747 * consinit 748 */ 749 void 750 consinit(void) 751 { 752 static int consinit_called; 753 static const bus_addr_t addrs[2] = { 754 IXP425_UART0_HWBASE, IXP425_UART1_HWBASE 755 }; 756 757 if (consinit_called != 0) 758 return; 759 760 consinit_called = 1; 761 762 pmap_devmap_register(ixp425_devmap); 763 764 if (comcnattach(&ixp425_a4x_bs_tag, addrs[comcnunit], 765 comcnspeed, IXP425_UART_FREQ, COM_TYPE_PXA2x0, comcnmode)) 766 panic("can't init serial console (UART%d)", comcnunit); 767 } 768