1 /* $NetBSD: smdk2800_machdep.c,v 1.40 2012/09/22 00:33:40 matt Exp $ */ 2 3 /* 4 * Copyright (c) 2002, 2003, 2005 Fujitsu Component Limited 5 * Copyright (c) 2002, 2003, 2005 Genetec Corporation 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. Neither the name of The Fujitsu Component Limited nor the name of 17 * Genetec corporation may not be used to endorse or promote products 18 * derived from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY FUJITSU COMPONENT LIMITED AND GENETEC 21 * CORPORATION ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 * DISCLAIMED. IN NO EVENT SHALL FUJITSU COMPONENT LIMITED OR GENETEC 25 * CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 28 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 */ 34 35 /* 36 * Copyright (c) 2001,2002 ARM Ltd 37 * All rights reserved. 38 * 39 * Redistribution and use in source and binary forms, with or without 40 * modification, are permitted provided that the following conditions 41 * are met: 42 * 1. Redistributions of source code must retain the above copyright 43 * notice, this list of conditions and the following disclaimer. 44 * 2. Redistributions in binary form must reproduce the above copyright 45 * notice, this list of conditions and the following disclaimer in the 46 * documentation and/or other materials provided with the distribution. 47 * 3. The name of the company may not be used to endorse or promote 48 * products derived from this software without specific prior written 49 * permission. 50 * 51 * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND 52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 53 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 54 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARM LTD 55 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 56 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 57 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 58 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 59 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 60 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 61 * POSSIBILITY OF SUCH DAMAGE. 62 * 63 */ 64 65 /* 66 * Copyright (c) 1997,1998 Mark Brinicombe. 67 * Copyright (c) 1997,1998 Causality Limited. 68 * All rights reserved. 69 * 70 * Redistribution and use in source and binary forms, with or without 71 * modification, are permitted provided that the following conditions 72 * are met: 73 * 1. Redistributions of source code must retain the above copyright 74 * notice, this list of conditions and the following disclaimer. 75 * 2. Redistributions in binary form must reproduce the above copyright 76 * notice, this list of conditions and the following disclaimer in the 77 * documentation and/or other materials provided with the distribution. 78 * 3. All advertising materials mentioning features or use of this software 79 * must display the following acknowledgement: 80 * This product includes software developed by Mark Brinicombe 81 * for the NetBSD Project. 82 * 4. The name of the company nor the name of the author may be used to 83 * endorse or promote products derived from this software without specific 84 * prior written permission. 85 * 86 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 87 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 88 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 89 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 90 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 91 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 92 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 93 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 94 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 95 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 96 * SUCH DAMAGE. 97 * 98 * Machine dependent functions for kernel setup for integrator board 99 * 100 * Created : 24/11/97 101 */ 102 103 /* 104 * Machine dependent functions for kernel setup for Samsung SMDK2800 105 * derived from integrator_machdep.c 106 */ 107 108 #include <sys/cdefs.h> 109 __KERNEL_RCSID(0, "$NetBSD: smdk2800_machdep.c,v 1.40 2012/09/22 00:33:40 matt Exp $"); 110 111 #include "opt_ddb.h" 112 #include "opt_kgdb.h" 113 #include "opt_pmap_debug.h" 114 #include "opt_md.h" 115 #include "pci.h" 116 117 #include <sys/param.h> 118 #include <sys/device.h> 119 #include <sys/systm.h> 120 #include <sys/kernel.h> 121 #include <sys/exec.h> 122 #include <sys/proc.h> 123 #include <sys/msgbuf.h> 124 #include <sys/reboot.h> 125 #include <sys/termios.h> 126 #include <sys/ksyms.h> 127 128 #include <uvm/uvm_extern.h> 129 130 #include <dev/cons.h> 131 #include <dev/md.h> 132 133 #include <machine/db_machdep.h> 134 #include <ddb/db_sym.h> 135 #include <ddb/db_extern.h> 136 #ifdef KGDB 137 #include <sys/kgdb.h> 138 #endif 139 140 #include <machine/bootconfig.h> 141 #include <sys/bus.h> 142 #include <machine/cpu.h> 143 #include <machine/frame.h> 144 #include <machine/intr.h> 145 #include <arm/undefined.h> 146 147 #include <arm/arm32/machdep.h> 148 149 #include <arm/s3c2xx0/s3c2800reg.h> 150 #include <arm/s3c2xx0/s3c2800var.h> 151 #include <evbarm/smdk2xx0/smdk2800var.h> 152 153 #include "ksyms.h" 154 155 /* Kernel text starts 2MB in from the bottom of the kernel address space. */ 156 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000) 157 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000) 158 159 /* 160 * The range 0xc1000000 - 0xccffffff is available for kernel VM space 161 * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff 162 */ 163 #define KERNEL_VM_SIZE 0x0C000000 164 165 /* Memory disk support */ 166 #if defined(MEMORY_DISK_DYNAMIC) && defined(MEMORY_DISK_ROOT_ADDR) 167 #define DO_MEMORY_DISK 168 /* We have memory disk image outside of the kernel on ROM. */ 169 #ifdef MEMORY_DISK_ROOT_ROM 170 /* map the image directory and use read-only */ 171 #else 172 /* copy the image to RAM */ 173 #endif 174 #endif 175 176 BootConfig bootconfig; /* Boot config storage */ 177 char *boot_args = NULL; 178 char *boot_file = NULL; 179 180 vm_offset_t physical_start; 181 vm_offset_t physical_freestart; 182 vm_offset_t physical_freeend; 183 vm_offset_t physical_end; 184 u_int free_pages; 185 186 /*int debug_flags;*/ 187 #ifndef PMAP_STATIC_L1S 188 int max_processes = 64; /* Default number */ 189 #endif /* !PMAP_STATIC_L1S */ 190 191 vm_offset_t msgbufphys; 192 193 #ifdef PMAP_DEBUG 194 extern int pmap_debug_level; 195 #endif 196 197 #define KERNEL_PT_SYS 0 /* L2 table for mapping zero page */ 198 #define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */ 199 #define KERNEL_PT_KERNEL_NUM 2 /* L2 tables for mapping kernel VM */ 200 201 #define KERNEL_PT_VMDATA (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM) 202 203 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */ 204 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM) 205 206 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS]; 207 208 /* Prototypes */ 209 210 void consinit(void); 211 void kgdb_port_init(void); 212 213 /* A load of console goo. */ 214 #include "vga.h" 215 #if NVGA > 0 216 #include <dev/ic/mc6845reg.h> 217 #include <dev/ic/pcdisplayvar.h> 218 #include <dev/ic/vgareg.h> 219 #include <dev/ic/vgavar.h> 220 #endif 221 222 #include "com.h" 223 #if NCOM > 0 224 #include <dev/ic/comreg.h> 225 #include <dev/ic/comvar.h> 226 #endif 227 228 #include "sscom.h" 229 #if NSSCOM > 0 230 #include "opt_sscom.h" 231 #include <arm/s3c2xx0/sscom_var.h> 232 #endif 233 234 /* 235 * Define the default console speed for the board. This is generally 236 * what the firmware provided with the board defaults to. 237 */ 238 #ifndef CONSPEED 239 #define CONSPEED B115200 /* TTYDEF_SPEED */ 240 #endif 241 #ifndef CONMODE 242 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ 243 #endif 244 245 int comcnspeed = CONSPEED; 246 int comcnmode = CONMODE; 247 248 /* 249 * void cpu_reboot(int howto, char *bootstr) 250 * 251 * Reboots the system 252 * 253 * Deal with any syncing, unmounting, dumping and shutdown hooks, 254 * then reset the CPU. 255 */ 256 void 257 cpu_reboot(int howto, char *bootstr) 258 { 259 260 cpu_reset_address_paddr = vtophys((u_int)s3c2800_softreset); 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 /* Disable console buffering */ 277 278 /* 279 * If RB_NOSYNC was not specified sync the discs. 280 * Note: Unless cold is set to 1 here, syslogd will die during the 281 * unmount. It looks like syslogd is getting woken up only to find 282 * that it cannot page part of the binary in as the filesystem has 283 * been unmounted. 284 */ 285 if (!(howto & RB_NOSYNC)) 286 bootsync(); 287 288 /* Say NO to interrupts */ 289 splhigh(); 290 291 /* Do a dump if requested. */ 292 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) 293 dumpsys(); 294 295 /* Run any shutdown hooks */ 296 doshutdownhooks(); 297 298 pmf_system_shutdown(boothowto); 299 300 /* Make sure IRQ's are disabled */ 301 IRQdisable; 302 303 if (howto & RB_HALT) { 304 printf("The operating system has halted.\n"); 305 printf("Please press any key to reboot.\n\n"); 306 cngetc(); 307 } 308 printf("rebooting...\n"); 309 cpu_reset(); 310 /* NOTREACHED */ 311 } 312 313 /* 314 * All built-in peripheral registers are statically mapped in start up 315 * routine. This table tells pmap subsystem about it, and to map them 316 * at the same position. 317 */ 318 static const struct pmap_devmap smdk2800_devmap[] = { 319 { 320 SMDK2800_IO_AREA_VBASE, 321 S3C2800_PERIPHERALS, 322 S3C2800_PERIPHERALS_SIZE, 323 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE, 324 }, 325 { 0, 0, 0, 0 } 326 }; 327 328 #define ioreg_vaddr(pa) ((pa) - S3C2800_PERIPHERALS + SMDK2800_IO_AREA_VBASE) 329 #define ioreg32(pa) (*(volatile uint32_t *)ioreg_vaddr(pa)) 330 331 /* 332 * u_int initarm(...) 333 * 334 * Initial entry point on startup. This gets called before main() is 335 * entered. 336 * It should be responsible for setting up everything that must be 337 * in place when main is called. 338 * This includes 339 * Taking a copy of the boot configuration structure. 340 * Initialising the physical console so characters can be printed. 341 * Setting up page tables for the kernel 342 * Relocating the kernel to the bottom of physical memory 343 */ 344 345 u_int 346 initarm(void *arg) 347 { 348 int loop; 349 int loop1; 350 u_int l1pagetable; 351 extern int etext __asm("_etext"); 352 extern int end __asm("_end"); 353 int progress_counter = 0; 354 355 #ifdef DO_MEMORY_DISK 356 vm_offset_t md_root_start; 357 #define MD_ROOT_SIZE (MEMORY_DISK_ROOT_SIZE * DEV_BSIZE) 358 #endif 359 360 #define gpio8(reg) (*(volatile uint8_t *)(ioreg_vaddr(S3C2800_GPIO_BASE) + (reg))) 361 362 #define LEDSTEP() __LED(progress_counter++) 363 364 #define pdatc gpio8(GPIO_PDATC) 365 #define __LED(x) (pdatc = (pdatc & ~0x07) | (~(x) & 0x07)) 366 367 LEDSTEP(); 368 /* 369 * Heads up ... Setup the CPU / MMU / TLB functions 370 */ 371 if (set_cpufuncs()) 372 panic("CPU not recognized!"); 373 374 LEDSTEP(); 375 376 377 /* Disable all peripheral interrupts */ 378 ioreg32(S3C2800_INTCTL_BASE + INTCTL_INTMSK) = 0; 379 380 consinit(); 381 #ifdef VERBOSE_INIT_ARM 382 printf("consinit done\n"); 383 #endif 384 385 #ifdef KGDB 386 LEDSTEP(); 387 kgdb_port_init(); 388 #endif 389 LEDSTEP(); 390 391 #ifdef VERBOSE_INIT_ARM 392 /* Talk to the user */ 393 printf("\nNetBSD/evbarm (SMDK2800) booting ...\n"); 394 #endif 395 396 /* 397 * Ok we have the following memory map 398 * 399 * Physical Address Range Description 400 * ----------------------- ---------------------------------- 401 * 0x00000000 - 0x00ffffff Intel flash Memory (16MB) 402 * 0x02000000 - 0x020fffff AMD flash Memory (1MB) 403 * or (depend on DIPSW setting) 404 * 0x00000000 - 0x000fffff AMD flash Memory (1MB) 405 * 0x02000000 - 0x02ffffff Intel flash Memory (16MB) 406 * 407 * 0x08000000 - 0x09ffffff SDRAM (32MB) 408 * 0x20000000 - 0x3fffffff PCI space 409 * 410 * The initarm() has the responsibility for creating the kernel 411 * page tables. 412 * It must also set up various memory pointers that are used 413 * by pmap etc. 414 */ 415 416 /* Fake bootconfig structure for the benefit of pmap.c */ 417 /* XXX must make the memory description h/w independent */ 418 bootconfig.dramblocks = 1; 419 bootconfig.dram[0].address = SDRAM_START; 420 bootconfig.dram[0].pages = SDRAM_SIZE / PAGE_SIZE; 421 422 /* 423 * Set up the variables that define the availablilty of 424 * physical memory. For now, we're going to set 425 * physical_freestart to 0x08200000 (where the kernel 426 * was loaded), and allocate the memory we need downwards. 427 * If we get too close to the bottom of SDRAM, we 428 * will panic. We will update physical_freestart and 429 * physical_freeend later to reflect what pmap_bootstrap() 430 * wants to see. 431 * 432 * XXX pmap_bootstrap() needs an enema. 433 */ 434 physical_start = bootconfig.dram[0].address; 435 physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE); 436 437 #if DO_MEMORY_DISK 438 #ifdef MEMORY_DISK_ROOT_ROM 439 md_root_start = MEMORY_DISK_ROOT_ADDR; 440 boothowto |= RB_RDONLY; 441 #else 442 /* Reserve physmem for ram disk */ 443 md_root_start = ((physical_end - MD_ROOT_SIZE) & ~(L1_S_SIZE-1)); 444 printf("Reserve %ld bytes for memory disk\n", 445 physical_end - md_root_start); 446 /* copy fs contents */ 447 memcpy((void *)md_root_start, (void *)MEMORY_DISK_ROOT_ADDR, 448 MD_ROOT_SIZE); 449 physical_end = md_root_start; 450 #endif 451 #endif 452 453 physical_freestart = 0x08000000UL; /* XXX */ 454 physical_freeend = 0x08200000UL; 455 456 physmem = (physical_end - physical_start) / PAGE_SIZE; 457 458 #ifdef VERBOSE_INIT_ARM 459 /* Tell the user about the memory */ 460 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem, 461 physical_start, physical_end - 1); 462 #endif 463 464 /* 465 * XXX 466 * Okay, the kernel starts 2MB in from the bottom of physical 467 * memory. We are going to allocate our bootstrap pages downwards 468 * from there. 469 * 470 * We need to allocate some fixed page tables to get the kernel 471 * going. We allocate one page directory and a number of page 472 * tables and store the physical addresses in the kernel_pt_table 473 * array. 474 * 475 * The kernel page directory must be on a 16K boundary. The page 476 * tables must be on 4K boundaries. What we do is allocate the 477 * page directory on the first 16K boundary that we encounter, and 478 * the page tables on 4K boundaries otherwise. Since we allocate 479 * at least 3 L2 page tables, we are guaranteed to encounter at 480 * least one 16K aligned region. 481 */ 482 483 #ifdef VERBOSE_INIT_ARM 484 printf("Allocating page tables\n"); 485 #endif 486 487 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE; 488 489 #ifdef VERBOSE_INIT_ARM 490 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n", 491 physical_freestart, free_pages, free_pages); 492 #endif 493 494 /* Define a macro to simplify memory allocation */ 495 #define valloc_pages(var, np) \ 496 alloc_pages((var).pv_pa, (np)); \ 497 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start; 498 499 #define alloc_pages(var, np) \ 500 physical_freeend -= ((np) * PAGE_SIZE); \ 501 if (physical_freeend < physical_freestart) \ 502 panic("initarm: out of memory"); \ 503 (var) = physical_freeend; \ 504 free_pages -= (np); \ 505 memset((char *)(var), 0, ((np) * PAGE_SIZE)); 506 507 loop1 = 0; 508 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) { 509 /* Are we 16KB aligned for an L1 ? */ 510 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0 511 && kernel_l1pt.pv_pa == 0) { 512 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE); 513 } else { 514 valloc_pages(kernel_pt_table[loop1], 515 L2_TABLE_SIZE / PAGE_SIZE); 516 ++loop1; 517 } 518 } 519 520 /* This should never be able to happen but better confirm that. */ 521 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0) 522 panic("initarm: Failed to align the kernel page directory\n"); 523 524 /* 525 * Allocate a page for the system page mapped to V0x00000000 526 * This page will just contain the system vectors and can be 527 * shared by all processes. 528 */ 529 alloc_pages(systempage.pv_pa, 1); 530 531 /* Allocate stacks for all modes */ 532 valloc_pages(irqstack, IRQ_STACK_SIZE); 533 valloc_pages(abtstack, ABT_STACK_SIZE); 534 valloc_pages(undstack, UND_STACK_SIZE); 535 valloc_pages(kernelstack, UPAGES); 536 537 #ifdef VERBOSE_INIT_ARM 538 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa, 539 irqstack.pv_va); 540 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa, 541 abtstack.pv_va); 542 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa, 543 undstack.pv_va); 544 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa, 545 kernelstack.pv_va); 546 #endif 547 548 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE); 549 550 LEDSTEP(); 551 552 /* 553 * Ok we have allocated physical pages for the primary kernel 554 * page tables 555 */ 556 557 #ifdef VERBOSE_INIT_ARM 558 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa); 559 #endif 560 561 /* 562 * Now we start construction of the L1 page table 563 * We start by mapping the L2 page tables into the L1. 564 * This means that we can replace L1 mappings later on if necessary 565 */ 566 l1pagetable = kernel_l1pt.pv_pa; 567 568 /* Map the L2 pages tables in the L1 page table */ 569 pmap_link_l2pt(l1pagetable, 0x00000000, 570 &kernel_pt_table[KERNEL_PT_SYS]); 571 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++) 572 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000, 573 &kernel_pt_table[KERNEL_PT_KERNEL + loop]); 574 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++) 575 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000, 576 &kernel_pt_table[KERNEL_PT_VMDATA + loop]); 577 578 /* update the top of the kernel VM */ 579 pmap_curmaxkvaddr = 580 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000); 581 582 #ifdef VERBOSE_INIT_ARM 583 printf("Mapping kernel\n"); 584 #endif 585 586 /* Now we fill in the L2 pagetable for the kernel static code/data */ 587 { 588 size_t textsize = (uintptr_t)&etext - KERNEL_TEXT_BASE; 589 size_t totalsize = (uintptr_t)&end - KERNEL_TEXT_BASE; 590 u_int logical; 591 592 textsize = (textsize + PGOFSET) & ~PGOFSET; 593 totalsize = (totalsize + PGOFSET) & ~PGOFSET; 594 595 logical = 0x00200000; /* offset of kernel in RAM */ 596 597 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical, 598 physical_start + logical, textsize, 599 VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE); 600 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical, 601 physical_start + logical, totalsize - textsize, 602 VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE); 603 } 604 605 #ifdef VERBOSE_INIT_ARM 606 printf("Constructing L2 page tables\n"); 607 #endif 608 609 /* Map the stack pages */ 610 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa, 611 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE, 612 PTE_CACHE); 613 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa, 614 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE, 615 PTE_CACHE); 616 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa, 617 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE, 618 PTE_CACHE); 619 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa, 620 UPAGES * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE); 621 622 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa, 623 L1_TABLE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_PAGETABLE); 624 625 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) { 626 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va, 627 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE, 628 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE); 629 } 630 631 /* Map the vector page. */ 632 #if 1 633 /* MULTI-ICE requires that page 0 is NC/NB so that it can download the 634 * cache-clean code there. */ 635 pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa, 636 VM_PROT_READ | VM_PROT_WRITE, PTE_NOCACHE); 637 #else 638 pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa, 639 VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE); 640 #endif 641 642 #ifdef MEMORY_DISK_DYNAMIC 643 /* map MD root image */ 644 pmap_map_chunk(l1pagetable, SMDK2800_MEMORY_DISK_VADDR, md_root_start, 645 MD_ROOT_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE); 646 647 md_root_setconf((void *)md_root_start, MD_ROOT_SIZE); 648 #endif /* MEMORY_DISK_DYNAMIC */ 649 /* 650 * map integrated peripherals at same address in l1pagetable 651 * so that we can continue to use console. 652 */ 653 pmap_devmap_bootstrap(l1pagetable, smdk2800_devmap); 654 655 /* 656 * Now we have the real page tables in place so we can switch to them. 657 * Once this is done we will be running with the REAL kernel page 658 * tables. 659 */ 660 661 /* 662 * Update the physical_freestart/physical_freeend/free_pages 663 * variables. 664 */ 665 { 666 physical_freestart = physical_start + 667 (((((uintptr_t)&end) + PGOFSET) & ~PGOFSET) - KERNEL_BASE); 668 physical_freeend = physical_end; 669 free_pages = 670 (physical_freeend - physical_freestart) / PAGE_SIZE; 671 } 672 673 /* Switch tables */ 674 #ifdef VERBOSE_INIT_ARM 675 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n", 676 physical_freestart, free_pages, free_pages); 677 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa); 678 #endif 679 LEDSTEP(); 680 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT); 681 cpu_setttb(kernel_l1pt.pv_pa, true); 682 cpu_tlb_flushID(); 683 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)); 684 685 /* 686 * Moved from cpu_startup() as data_abort_handler() references 687 * this during uvm init 688 */ 689 uvm_lwp_setuarea(&lwp0, kernelstack.pv_va); 690 691 #ifdef VERBOSE_INIT_ARM 692 printf("done!\n"); 693 #endif 694 695 #if 0 696 /* 697 * The IFPGA registers have just moved. 698 * Detach the diagnostic serial port and reattach at the new address. 699 */ 700 plcomcndetach(); 701 /* 702 * XXX this should only be done in main() but it useful to 703 * have output earlier ... 704 */ 705 consinit(); 706 #endif 707 708 LEDSTEP(); 709 #ifdef VERBOSE_INIT_ARM 710 printf("bootstrap done.\n"); 711 #endif 712 713 arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL); 714 715 /* 716 * Pages were allocated during the secondary bootstrap for the 717 * stacks for different CPU modes. 718 * We must now set the r13 registers in the different CPU modes to 719 * point to these stacks. 720 * Since the ARM stacks use STMFD etc. we must set r13 to the top end 721 * of the stack memory. 722 */ 723 #ifdef VERBOSE_INIT_ARM 724 printf("init subsystems: stacks "); 725 #endif 726 727 set_stackptr(PSR_IRQ32_MODE, 728 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE); 729 set_stackptr(PSR_ABT32_MODE, 730 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE); 731 set_stackptr(PSR_UND32_MODE, 732 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE); 733 734 LEDSTEP(); 735 736 /* 737 * Well we should set a data abort handler. 738 * Once things get going this will change as we will need a proper 739 * handler. 740 * Until then we will use a handler that just panics but tells us 741 * why. 742 * Initialisation of the vectors will just panic on a data abort. 743 * This just fills in a slightly better one. 744 */ 745 #ifdef VERBOSE_INIT_ARM 746 printf("vectors "); 747 #endif 748 data_abort_handler_address = (u_int)data_abort_handler; 749 prefetch_abort_handler_address = (u_int)prefetch_abort_handler; 750 undefined_handler_address = (u_int)undefinedinstruction_bounce; 751 752 /* Initialise the undefined instruction handlers */ 753 #ifdef VERBOSE_INIT_ARM 754 printf("undefined "); 755 #endif 756 undefined_init(); 757 758 LEDSTEP(); 759 760 /* Load memory into UVM. */ 761 #ifdef VERBOSE_INIT_ARM 762 printf("page "); 763 #endif 764 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */ 765 uvm_page_physload(atop(physical_freestart), atop(physical_freeend), 766 atop(physical_freestart), atop(physical_freeend), 767 VM_FREELIST_DEFAULT); 768 769 LEDSTEP(); 770 /* Boot strap pmap telling it where the kernel page table is */ 771 #ifdef VERBOSE_INIT_ARM 772 printf("pmap "); 773 #endif 774 pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE); 775 776 LEDSTEP(); 777 778 /* Setup the IRQ system */ 779 #ifdef VERBOSE_INIT_ARM 780 printf("irq "); 781 #endif 782 /* XXX irq_init(); */ 783 784 #ifdef VERBOSE_INIT_ARM 785 printf("done.\n"); 786 #endif 787 788 #ifdef BOOTHOWTO_INIT 789 boothowto |= BOOTHOWTO_INIT; 790 #endif 791 { 792 uint8_t gpio = ~gpio8(GPIO_PDATF); 793 794 if (gpio & (1<<5)) /* SW3 */ 795 boothowto ^= RB_SINGLE; 796 if (gpio & (1<<7)) /* SW7 */ 797 boothowto ^= RB_KDB; 798 #ifdef VERBOSE_INIT_ARM 799 printf( "sw: %x boothowto: %x\n", gpio, boothowto ); 800 #endif 801 } 802 803 #ifdef KGDB 804 if (boothowto & RB_KDB) { 805 kgdb_debug_init = 1; 806 kgdb_connect(1); 807 } 808 #endif 809 810 #ifdef DDB 811 db_machine_init(); 812 if (boothowto & RB_KDB) 813 Debugger(); 814 #endif 815 816 /* We return the new stack pointer address */ 817 return (kernelstack.pv_va + USPACE_SVC_STACK_TOP); 818 } 819 820 void 821 consinit(void) 822 { 823 static int consinit_done = 0; 824 bus_space_tag_t iot = &s3c2xx0_bs_tag; 825 int pclk; 826 827 if (consinit_done != 0) 828 return; 829 830 consinit_done = 1; 831 832 pmap_devmap_register(smdk2800_devmap); 833 834 s3c2800_clock_freq2(ioreg_vaddr(S3C2800_CLKMAN_BASE), NULL, NULL, &pclk); 835 836 #if NSSCOM > 0 837 #ifdef SSCOM0CONSOLE 838 if (0 == s3c2800_sscom_cnattach(iot, 0, comcnspeed, 839 pclk, comcnmode)) 840 return; 841 #endif 842 #ifdef SSCOM1CONSOLE 843 if (0 == s3c2800_sscom_cnattach(iot, 1, comcnspeed, 844 pclk, comcnmode)) 845 return; 846 #endif 847 #endif /* NSSCOM */ 848 #if NCOM>0 && defined(CONCOMADDR) 849 if (comcnattach(&isa_io_bs_tag, CONCOMADDR, comcnspeed, 850 COM_FREQ, COM_TYPE_NORMAL, comcnmode)) 851 panic("can't init serial console @%x", CONCOMADDR); 852 return; 853 #endif 854 855 consinit_done = 0; 856 } 857 858 859 #ifdef KGDB 860 861 #if (NSSCOM > 0) 862 863 #ifdef KGDB_DEVNAME 864 const char kgdb_devname[] = KGDB_DEVNAME; 865 #else 866 const char kgdb_devname[] = ""; 867 #endif 868 869 #ifndef KGDB_DEVMODE 870 #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE|CSTOPB|PARENB))|CS8) /* 8N1 */ 871 #endif 872 int kgdb_sscom_mode = KGDB_DEVMODE; 873 874 #endif /* NSSCOM */ 875 876 void 877 kgdb_port_init(void) 878 { 879 #if (NSSCOM > 0) 880 int unit = -1; 881 int pclk; 882 883 if (strcmp(kgdb_devname, "sscom0") == 0) 884 unit = 0; 885 else if (strcmp(kgdb_devname, "sscom1") == 0) 886 unit = 1; 887 888 if (unit >= 0) { 889 s3c2800_clock_freq2(ioreg_vaddr(S3C2800_CLKMAN_BASE), 890 NULL, NULL, &pclk); 891 892 s3c2800_sscom_kgdb_attach(&s3c2xx0_bs_tag, 893 unit, kgdb_rate, pclk, kgdb_sscom_mode); 894 } 895 #endif 896 } 897 #endif 898