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