1 /* $NetBSD: viper_machdep.c,v 1.33 2021/08/17 22:00:29 andvar Exp $ */ 2 3 /* 4 * Startup routines for the Arcom Viper. Below you can trace the 5 * impressive lineage ;) 6 * 7 * Modified for the Viper by Antti Kantee <pooka@netbsd.org> 8 */ 9 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 * Machine dependent functions for kernel setup for 39 * Intel DBPXA250 evaluation board (a.k.a. Lubbock). 40 * Based on iq80310_machhdep.c 41 */ 42 /* 43 * Copyright (c) 2001 Wasabi Systems, Inc. 44 * All rights reserved. 45 * 46 * Written by Jason R. Thorpe for Wasabi Systems, Inc. 47 * 48 * Redistribution and use in source and binary forms, with or without 49 * modification, are permitted provided that the following conditions 50 * are met: 51 * 1. Redistributions of source code must retain the above copyright 52 * notice, this list of conditions and the following disclaimer. 53 * 2. Redistributions in binary form must reproduce the above copyright 54 * notice, this list of conditions and the following disclaimer in the 55 * documentation and/or other materials provided with the distribution. 56 * 3. All advertising materials mentioning features or use of this software 57 * must display the following acknowledgement: 58 * This product includes software developed for the NetBSD Project by 59 * Wasabi Systems, Inc. 60 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 61 * or promote products derived from this software without specific prior 62 * written permission. 63 * 64 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 65 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 66 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 67 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 68 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 69 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 70 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 71 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 72 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 73 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 74 * POSSIBILITY OF SUCH DAMAGE. 75 */ 76 77 /* 78 * Copyright (c) 1997,1998 Mark Brinicombe. 79 * Copyright (c) 1997,1998 Causality Limited. 80 * All rights reserved. 81 * 82 * Redistribution and use in source and binary forms, with or without 83 * modification, are permitted provided that the following conditions 84 * are met: 85 * 1. Redistributions of source code must retain the above copyright 86 * notice, this list of conditions and the following disclaimer. 87 * 2. Redistributions in binary form must reproduce the above copyright 88 * notice, this list of conditions and the following disclaimer in the 89 * documentation and/or other materials provided with the distribution. 90 * 3. All advertising materials mentioning features or use of this software 91 * must display the following acknowledgement: 92 * This product includes software developed by Mark Brinicombe 93 * for the NetBSD Project. 94 * 4. The name of the company nor the name of the author may be used to 95 * endorse or promote products derived from this software without specific 96 * prior written permission. 97 * 98 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 99 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 100 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 101 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 102 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 103 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 104 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 105 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 106 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 107 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 108 * SUCH DAMAGE. 109 * 110 * Machine dependent functions for kernel setup for Intel IQ80310 evaluation 111 * boards using RedBoot firmware. 112 */ 113 114 #include <sys/cdefs.h> 115 __KERNEL_RCSID(0, "$NetBSD: viper_machdep.c,v 1.33 2021/08/17 22:00:29 andvar Exp $"); 116 117 #include "opt_arm_debug.h" 118 #include "opt_console.h" 119 #include "opt_ddb.h" 120 #include "opt_kgdb.h" 121 #include "opt_md.h" 122 #include "opt_com.h" 123 #include "lcd.h" 124 125 #include <sys/param.h> 126 #include <sys/device.h> 127 #include <sys/systm.h> 128 #include <sys/kernel.h> 129 #include <sys/exec.h> 130 #include <sys/proc.h> 131 #include <sys/msgbuf.h> 132 #include <sys/reboot.h> 133 #include <sys/termios.h> 134 #include <sys/ksyms.h> 135 #include <sys/bus.h> 136 #include <sys/cpu.h> 137 138 #include <uvm/uvm_extern.h> 139 140 #include <sys/conf.h> 141 #include <dev/cons.h> 142 #include <dev/md.h> 143 #include <dev/ic/smc91cxxreg.h> 144 145 #include <machine/db_machdep.h> 146 #include <ddb/db_sym.h> 147 #include <ddb/db_extern.h> 148 #ifdef KGDB 149 #include <sys/kgdb.h> 150 #endif 151 152 #include <machine/bootconfig.h> 153 #include <arm/locore.h> 154 #include <arm/undefined.h> 155 156 #include <arm/arm32/machdep.h> 157 158 #include <arm/xscale/pxa2x0reg.h> 159 #include <arm/xscale/pxa2x0var.h> 160 #include <arm/xscale/pxa2x0_gpio.h> 161 #include <arm/sa11x0/sa1111_reg.h> 162 #include <evbarm/viper/viper_reg.h> 163 164 /* Kernel text starts 2MB in from the bottom of the kernel address space. */ 165 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000) 166 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000) 167 168 /* 169 * The range 0xc1000000 - 0xccffffff is available for kernel VM space 170 * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff 171 */ 172 #define KERNEL_VM_SIZE 0x0C000000 173 174 BootConfig bootconfig; /* Boot config storage */ 175 char *boot_args = NULL; 176 char *boot_file = NULL; 177 178 vaddr_t physical_start; 179 vaddr_t physical_freestart; 180 vaddr_t physical_freeend; 181 vaddr_t physical_end; 182 u_int free_pages; 183 184 /*int debug_flags;*/ 185 #ifndef PMAP_STATIC_L1S 186 int max_processes = 64; /* Default number */ 187 #endif /* !PMAP_STATIC_L1S */ 188 189 /* Physical and virtual addresses for some global pages */ 190 pv_addr_t minidataclean; 191 192 paddr_t msgbufphys; 193 194 #define KERNEL_PT_SYS 0 /* Page table for mapping proc0 zero page */ 195 #define KERNEL_PT_KERNEL 1 /* Page table for mapping kernel */ 196 #define KERNEL_PT_KERNEL_NUM 4 197 #define KERNEL_PT_VMDATA (KERNEL_PT_KERNEL+KERNEL_PT_KERNEL_NUM) 198 /* Page tables for mapping kernel VM */ 199 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */ 200 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM) 201 202 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS]; 203 204 /* Prototypes */ 205 206 #if 0 207 void process_kernel_args(char *); 208 #endif 209 210 void consinit(void); 211 void kgdb_port_init(void); 212 void change_clock(uint32_t v); 213 214 bs_protos(bs_notimpl); 215 216 #include "com.h" 217 #if NCOM > 0 218 #include <dev/ic/comreg.h> 219 #include <dev/ic/comvar.h> 220 #endif 221 222 #ifndef CONSPEED 223 #define CONSPEED B115200 /* What RedBoot uses */ 224 #endif 225 #ifndef CONMODE 226 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ 227 #endif 228 229 int comcnspeed = CONSPEED; 230 int comcnmode = CONMODE; 231 232 static struct pxa2x0_gpioconf boarddep_gpioconf[] = { 233 { 44, GPIO_ALT_FN_1_IN }, /* BTCST */ 234 { 45, GPIO_ALT_FN_2_OUT }, /* BTRST */ 235 236 { -1 } 237 }; 238 static struct pxa2x0_gpioconf *viper_gpioconf[] = { 239 pxa25x_com_btuart_gpioconf, 240 pxa25x_com_ffuart_gpioconf, 241 pxa25x_com_stuart_gpioconf, 242 boarddep_gpioconf, 243 NULL 244 }; 245 246 /* 247 * void cpu_reboot(int howto, char *bootstr) 248 * 249 * Reboots the system 250 * 251 * Deal with any syncing, unmounting, dumping and shutdown hooks, 252 * then reset the CPU. 253 */ 254 void 255 cpu_reboot(int howto, char *bootstr) 256 { 257 #ifdef DIAGNOSTIC 258 /* info */ 259 printf("boot: howto=%08x curproc=%p\n", howto, curproc); 260 #endif 261 262 /* 263 * If we are still cold then hit the air brakes 264 * and crash to earth fast 265 */ 266 if (cold) { 267 doshutdownhooks(); 268 pmf_system_shutdown(boothowto); 269 printf("The operating system has halted.\n"); 270 printf("Please press any key to reboot.\n\n"); 271 cngetc(); 272 printf("rebooting...\n"); 273 cpu_reset(); 274 /*NOTREACHED*/ 275 } 276 277 /* Disable console buffering */ 278 /* cnpollc(1);*/ 279 280 /* 281 * If RB_NOSYNC was not specified sync the discs. 282 * Note: Unless cold is set to 1 here, syslogd will die during the 283 * unmount. It looks like syslogd is getting woken up only to find 284 * that it cannot page part of the binary in as the filesystem has 285 * been unmounted. 286 */ 287 if (!(howto & RB_NOSYNC)) 288 bootsync(); 289 290 /* Say NO to interrupts */ 291 splhigh(); 292 293 /* Do a dump if requested. */ 294 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) 295 dumpsys(); 296 297 /* Run any shutdown hooks */ 298 doshutdownhooks(); 299 300 pmf_system_shutdown(boothowto); 301 302 /* Make sure IRQ's are disabled */ 303 IRQdisable; 304 305 if (howto & RB_HALT) { 306 printf("The operating system has halted.\n"); 307 printf("Please press any key to reboot.\n\n"); 308 cngetc(); 309 } 310 311 printf("rebooting...\n"); 312 cpu_reset(); 313 /*NOTREACHED*/ 314 } 315 316 /* 317 * Static device mappings. These peripheral registers are mapped at 318 * fixed virtual addresses very early in viper_start() so that we 319 * can use them while booting the kernel, and stay at the same address 320 * throughout whole kernel's life time. 321 * 322 * We use this table twice; once with bootstrap page table, and once 323 * with kernel's page table which we build up in initarm(). 324 */ 325 326 static const struct pmap_devmap viper_devmap[] = { 327 { 328 VIPER_GPIO_VBASE, 329 PXA2X0_GPIO_BASE, 330 L1_S_SIZE, 331 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE, 332 }, 333 { 334 VIPER_CLKMAN_VBASE, 335 PXA2X0_CLKMAN_BASE, 336 L1_S_SIZE, 337 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE, 338 }, 339 { 340 VIPER_INTCTL_VBASE, 341 PXA2X0_INTCTL_BASE, 342 L1_S_SIZE, 343 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE, 344 }, 345 { 346 VIPER_FFUART_VBASE, 347 PXA2X0_FFUART_BASE, 348 L1_S_SIZE, 349 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE, 350 }, 351 { 352 VIPER_BTUART_VBASE, 353 PXA2X0_BTUART_BASE, 354 L1_S_SIZE, 355 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE, 356 }, 357 358 {0, 0, 0, 0,} 359 }; 360 361 #ifndef MEMSTART 362 #define MEMSTART 0xa0000000 363 #endif 364 #ifndef MEMSIZE 365 #define MEMSIZE 0x4000000 366 #endif 367 368 /* 369 * vaddr_t initarm(...) 370 * 371 * Initial entry point on startup. This gets called before main() is 372 * entered. 373 * It should be responsible for setting up everything that must be 374 * in place when main is called. 375 * This includes 376 * Taking a copy of the boot configuration structure. 377 * Initialising the physical console so characters can be printed. 378 * Setting up page tables for the kernel 379 * Relocating the kernel to the bottom of physical memory 380 */ 381 vaddr_t 382 initarm(void *arg) 383 { 384 extern vaddr_t xscale_cache_clean_addr; 385 int loop; 386 int loop1; 387 u_int l1pagetable; 388 #ifdef DIAGNOSTIC 389 extern vsize_t xscale_minidata_clean_size; /* used in KASSERT */ 390 #endif 391 392 /* Register devmap for devices we mapped in start */ 393 pmap_devmap_register(viper_devmap); 394 395 /* start 32.768 kHz OSC */ 396 ioreg_write(VIPER_CLKMAN_VBASE + 0x08, 2); 397 /* Get ready for splfoo() */ 398 pxa2x0_intr_bootstrap(VIPER_INTCTL_VBASE); 399 400 /* 401 * Heads up ... Setup the CPU / MMU / TLB functions 402 */ 403 if (set_cpufuncs()) 404 panic("cpu not recognized!"); 405 406 #if 0 407 /* Calibrate the delay loop. */ 408 #endif 409 410 /* setup GPIO for BTUART, in case bootloader doesn't take care of it */ 411 pxa2x0_gpio_bootstrap(VIPER_GPIO_VBASE); 412 pxa2x0_gpio_config(viper_gpioconf); 413 414 /* turn on clock to UART block. 415 XXX: this should not be done here. */ 416 ioreg_write(VIPER_CLKMAN_VBASE+CLKMAN_CKEN, CKEN_FFUART|CKEN_BTUART | 417 ioreg_read(VIPER_CLKMAN_VBASE+CLKMAN_CKEN)); 418 419 consinit(); 420 #ifdef KGDB 421 kgdb_port_init(); 422 #endif 423 /* Talk to the user */ 424 printf("\nNetBSD/evbarm (viper) booting ...\n"); 425 426 #if 0 427 /* 428 * Examine the boot args string for options we need to know about 429 * now. 430 */ 431 process_kernel_args((char *)nwbootinfo.bt_args); 432 #endif 433 434 printf("initarm: Configuring system ...\n"); 435 436 /* Fake bootconfig structure for the benefit of pmap.c */ 437 /* XXX must make the memory description h/w independent */ 438 bootconfig.dramblocks = 1; 439 bootconfig.dram[0].address = MEMSTART; 440 bootconfig.dram[0].pages = MEMSIZE / PAGE_SIZE; 441 442 /* 443 * Set up the variables that define the availability of 444 * physical memory. For now, we're going to set 445 * physical_freestart to 0xa0200000 (where the kernel 446 * was loaded), and allocate the memory we need downwards. 447 * If we get too close to the page tables that RedBoot 448 * set up, we will panic. We will update physical_freestart 449 * and physical_freeend later to reflect what pmap_bootstrap() 450 * wants to see. 451 * 452 * XXX pmap_bootstrap() needs an enema. 453 * (now that would be truly hardcore XXX) 454 */ 455 physical_start = bootconfig.dram[0].address; 456 physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE); 457 458 physical_freestart = 0xa0009000UL; 459 physical_freeend = 0xa0200000UL; 460 461 physmem = (physical_end - physical_start) / PAGE_SIZE; 462 463 #ifdef VERBOSE_INIT_ARM 464 /* Tell the user about the memory */ 465 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem, 466 physical_start, physical_end - 1); 467 #endif 468 469 /* 470 * Okay, the kernel starts 2MB in from the bottom of physical 471 * memory. We are going to allocate our bootstrap pages downwards 472 * from there. 473 * 474 * We need to allocate some fixed page tables to get the kernel 475 * going. We allocate one page directory and a number of page 476 * tables and store the physical addresses in the kernel_pt_table 477 * array. 478 * 479 * The kernel page directory must be on a 16K boundary. The page 480 * tables must be on 4K boundaries. What we do is allocate the 481 * page directory on the first 16K boundary that we encounter, and 482 * the page tables on 4K boundaries otherwise. Since we allocate 483 * at least 3 L2 page tables, we are guaranteed to encounter at 484 * least one 16K aligned region. 485 */ 486 487 #ifdef VERBOSE_INIT_ARM 488 printf("Allocating page tables\n"); 489 #endif 490 491 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE; 492 493 #ifdef VERBOSE_INIT_ARM 494 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n", 495 physical_freestart, free_pages, free_pages); 496 #endif 497 498 /* Define a macro to simplify memory allocation */ 499 #define valloc_pages(var, np) \ 500 alloc_pages((var).pv_pa, (np)); \ 501 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start; 502 503 #define alloc_pages(var, np) \ 504 physical_freeend -= ((np) * PAGE_SIZE); \ 505 if (physical_freeend < physical_freestart) \ 506 panic("initarm: out of memory"); \ 507 (var) = physical_freeend; \ 508 free_pages -= (np); \ 509 memset((char *)(var), 0, ((np) * PAGE_SIZE)); 510 511 loop1 = 0; 512 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) { 513 /* Are we 16KB aligned for an L1 ? */ 514 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0 515 && kernel_l1pt.pv_pa == 0) { 516 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE); 517 } else { 518 valloc_pages(kernel_pt_table[loop1], 519 L2_TABLE_SIZE / PAGE_SIZE); 520 ++loop1; 521 } 522 } 523 524 /* This should never be able to happen but better confirm that. */ 525 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0) 526 panic("initarm: Failed to align the kernel page directory"); 527 528 /* 529 * Allocate a page for the system page mapped to V0x00000000 530 * This page will just contain the system vectors and can be 531 * shared by all processes. 532 */ 533 alloc_pages(systempage.pv_pa, 1); 534 535 /* Allocate stacks for all modes */ 536 valloc_pages(irqstack, IRQ_STACK_SIZE); 537 valloc_pages(abtstack, ABT_STACK_SIZE); 538 valloc_pages(undstack, UND_STACK_SIZE); 539 valloc_pages(kernelstack, UPAGES); 540 541 /* Allocate enough pages for cleaning the Mini-Data cache. */ 542 KASSERT(xscale_minidata_clean_size <= PAGE_SIZE); 543 valloc_pages(minidataclean, 1); 544 545 #ifdef VERBOSE_INIT_ARM 546 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa, 547 irqstack.pv_va); 548 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa, 549 abtstack.pv_va); 550 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa, 551 undstack.pv_va); 552 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa, 553 kernelstack.pv_va); 554 #endif 555 556 /* 557 * XXX Defer this to later so that we can reclaim the memory 558 * XXX used by the RedBoot page tables. 559 */ 560 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE); 561 562 /* 563 * Ok we have allocated physical pages for the primary kernel 564 * page tables 565 */ 566 567 #ifdef VERBOSE_INIT_ARM 568 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa); 569 #endif 570 571 /* 572 * Now we start construction of the L1 page table 573 * We start by mapping the L2 page tables into the L1. 574 * This means that we can replace L1 mappings later on if necessary 575 */ 576 l1pagetable = kernel_l1pt.pv_pa; 577 578 /* Map the L2 pages tables in the L1 page table */ 579 pmap_link_l2pt(l1pagetable, 0x00000000, 580 &kernel_pt_table[KERNEL_PT_SYS]); 581 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++) 582 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000, 583 &kernel_pt_table[KERNEL_PT_KERNEL + loop]); 584 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++) 585 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000, 586 &kernel_pt_table[KERNEL_PT_VMDATA + loop]); 587 588 /* update the top of the kernel VM */ 589 pmap_curmaxkvaddr = 590 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000); 591 592 #ifdef VERBOSE_INIT_ARM 593 printf("Mapping kernel\n"); 594 #endif 595 596 /* Now we fill in the L2 pagetable for the kernel static code/data */ 597 { 598 extern char etext[], _end[]; 599 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE; 600 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE; 601 u_int logical; 602 603 textsize = (textsize + PGOFSET) & ~PGOFSET; 604 totalsize = (totalsize + PGOFSET) & ~PGOFSET; 605 606 logical = 0x00200000; /* offset of kernel in RAM */ 607 608 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical, 609 physical_start + logical, textsize, 610 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 611 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical, 612 physical_start + logical, totalsize - textsize, 613 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 614 } 615 616 #ifdef VERBOSE_INIT_ARM 617 printf("Constructing L2 page tables\n"); 618 #endif 619 620 /* Map the stack pages */ 621 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa, 622 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 623 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa, 624 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 625 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa, 626 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 627 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa, 628 UPAGES * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE); 629 630 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa, 631 L1_TABLE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_PAGETABLE); 632 633 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) { 634 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va, 635 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE, 636 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE); 637 } 638 639 /* Map the Mini-Data cache clean area. */ 640 xscale_setup_minidata(l1pagetable, minidataclean.pv_va, 641 minidataclean.pv_pa); 642 643 /* Map the vector page. */ 644 #if 1 645 /* MULTI-ICE requires that page 0 is NC/NB so that it can download the 646 * cache-clean code there. */ 647 pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa, 648 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE); 649 #else 650 pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa, 651 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 652 #endif 653 654 /* 655 * map integrated peripherals at same address in l1pagetable 656 * so that we can continue to use console. 657 */ 658 pmap_devmap_bootstrap(l1pagetable, viper_devmap); 659 660 /* 661 * Give the XScale global cache clean code an appropriately 662 * sized chunk of unmapped VA space starting at 0xff000000 663 * (our device mappings end before this address). 664 */ 665 xscale_cache_clean_addr = 0xff000000U; 666 667 /* 668 * Now we have the real page tables in place so we can switch to them. 669 * Once this is done we will be running with the REAL kernel page 670 * tables. 671 */ 672 673 /* 674 * Update the physical_freestart/physical_freeend/free_pages 675 * variables. 676 */ 677 { 678 extern char _end[]; 679 680 physical_freestart = physical_start + 681 (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) - 682 KERNEL_BASE); 683 physical_freeend = physical_end; 684 free_pages = 685 (physical_freeend - physical_freestart) / PAGE_SIZE; 686 } 687 688 /* Switch tables */ 689 #ifdef VERBOSE_INIT_ARM 690 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n", 691 physical_freestart, free_pages, free_pages); 692 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa); 693 #endif 694 695 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT); 696 cpu_setttb(kernel_l1pt.pv_pa, true); 697 cpu_tlb_flushID(); 698 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)); 699 700 /* 701 * Moved from cpu_startup() as data_abort_handler() references 702 * this during uvm init 703 */ 704 uvm_lwp_setuarea(&lwp0, kernelstack.pv_va); 705 706 #ifdef VERBOSE_INIT_ARM 707 printf("bootstrap done.\n"); 708 #endif 709 710 arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL); 711 712 /* 713 * Pages were allocated during the secondary bootstrap for the 714 * stacks for different CPU modes. 715 * We must now set the r13 registers in the different CPU modes to 716 * point to these stacks. 717 * Since the ARM stacks use STMFD etc. we must set r13 to the top end 718 * of the stack memory. 719 */ 720 printf("init subsystems: stacks "); 721 722 set_stackptr(PSR_IRQ32_MODE, irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE); 723 set_stackptr(PSR_ABT32_MODE, abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE); 724 set_stackptr(PSR_UND32_MODE, undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE); 725 726 /* 727 * Well we should set a data abort handler. 728 * Once things get going this will change as we will need a proper 729 * handler. 730 * Until then we will use a handler that just panics but tells us 731 * why. 732 * Initialisation of the vectors will just panic on a data abort. 733 * This just fills in a slightly better one. 734 */ 735 printf("vectors "); 736 data_abort_handler_address = (u_int)data_abort_handler; 737 prefetch_abort_handler_address = (u_int)prefetch_abort_handler; 738 undefined_handler_address = (u_int)undefinedinstruction_bounce; 739 740 /* Initialise the undefined instruction handlers */ 741 printf("undefined "); 742 undefined_init(); 743 744 /* Load memory into UVM. */ 745 printf("page "); 746 uvm_md_init(); 747 uvm_page_physload(atop(physical_freestart), atop(physical_freeend), 748 atop(physical_freestart), atop(physical_freeend), 749 VM_FREELIST_DEFAULT); 750 751 /* Boot strap pmap telling it where managed kernel virtual memory is */ 752 printf("pmap "); 753 pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE); 754 755 #ifdef __HAVE_MEMORY_DISK__ 756 md_root_setconf(memory_disk, sizeof memory_disk); 757 #endif 758 759 #ifdef KGDB 760 if (boothowto & RB_KDB) { 761 kgdb_debug_init = 1; 762 kgdb_connect(1); 763 } 764 #endif 765 766 #ifdef DDB 767 db_machine_init(); 768 769 /* Firmware doesn't load symbols. */ 770 ddb_init(0, NULL, NULL); 771 772 if (boothowto & RB_KDB) 773 Debugger(); 774 #endif 775 776 /* We return the new stack pointer address */ 777 return kernelstack.pv_va + USPACE_SVC_STACK_TOP; 778 } 779 780 #if 0 781 void 782 process_kernel_args(char *args) 783 { 784 785 boothowto = 0; 786 787 /* Make a local copy of the bootargs */ 788 strncpy(bootargs, args, MAX_BOOT_STRING); 789 790 args = bootargs; 791 boot_file = bootargs; 792 793 /* Skip the kernel image filename */ 794 while (*args != ' ' && *args != 0) 795 ++args; 796 797 if (*args != 0) 798 *args++ = 0; 799 800 while (*args == ' ') 801 ++args; 802 803 boot_args = args; 804 805 printf("bootfile: %s\n", boot_file); 806 printf("bootargs: %s\n", boot_args); 807 808 parse_mi_bootargs(boot_args); 809 } 810 #endif 811 812 #ifdef KGDB 813 #ifndef KGDB_DEVNAME 814 #define KGDB_DEVNAME "ffuart" 815 #endif 816 const char kgdb_devname[] = KGDB_DEVNAME; 817 818 #if (NCOM > 0) 819 #ifndef KGDB_DEVMODE 820 #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ 821 #endif 822 int comkgdbmode = KGDB_DEVMODE; 823 #endif /* NCOM */ 824 825 #endif /* KGDB */ 826 827 828 void 829 consinit(void) 830 { 831 static int consinit_called = 0; 832 uint32_t ckenreg = ioreg_read(VIPER_CLKMAN_VBASE+CLKMAN_CKEN); 833 #if 0 834 char *console = CONSDEVNAME; 835 #endif 836 837 if (consinit_called != 0) 838 return; 839 consinit_called = 1; 840 841 #if NCOM > 0 842 843 #ifdef FFUARTCONSOLE 844 #ifdef KGDB 845 if (0 == strcmp(kgdb_devname, "ffuart")) { 846 /* port is reserved for kgdb */ 847 } else 848 #endif 849 if (0 == comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_FFUART_BASE, 850 comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode)) { 851 852 #if 0 853 /* XXX: can't call pxa2x0_clkman_config yet */ 854 pxa2x0_clkman_config(CKEN_FFUART, 1); 855 #else 856 ioreg_write(VIPER_CLKMAN_VBASE+CLKMAN_CKEN, 857 ckenreg|CKEN_FFUART); 858 #endif 859 860 return; 861 } 862 863 #endif /* FFUARTCONSOLE */ 864 865 #ifdef BTUARTCONSOLE 866 #ifdef KGDB 867 if (0 == strcmp(kgdb_devname, "btuart")) { 868 /* port is reserved for kgdb */ 869 } else 870 #endif 871 if (0 == comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_BTUART_BASE, 872 comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode)) { 873 ioreg_write(VIPER_CLKMAN_VBASE+CLKMAN_CKEN, 874 ckenreg|CKEN_BTUART); 875 return; 876 } 877 #endif /* BTUARTCONSOLE */ 878 879 /* no console, guess we're flying blind */ 880 881 #endif /* NCOM */ 882 883 } 884 885 #ifdef KGDB 886 void 887 kgdb_port_init(void) 888 { 889 #if (NCOM > 0) && defined(COM_PXA2X0) 890 paddr_t paddr = 0; 891 uint32_t ckenreg = ioreg_read(VIPER_CLKMAN_VBASE+CLKMAN_CKEN); 892 893 if (0 == strcmp(kgdb_devname, "ffuart")) { 894 paddr = PXA2X0_FFUART_BASE; 895 ckenreg |= CKEN_FFUART; 896 } 897 else if (0 == strcmp(kgdb_devname, "btuart")) { 898 paddr = PXA2X0_BTUART_BASE; 899 ckenreg |= CKEN_BTUART; 900 } 901 902 if (paddr && 903 0 == com_kgdb_attach(&pxa2x0_a4x_bs_tag, paddr, 904 kgdb_rate, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comkgdbmode)) { 905 906 ioreg_write(VIPER_CLKMAN_VBASE+CLKMAN_CKEN, ckenreg); 907 } 908 #endif 909 } 910 #endif 911