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