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