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