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