1 /* $NetBSD: machdep.c,v 1.55 2024/05/13 00:08:06 msaitoh Exp $ */ 2 /* $OpenBSD: zaurus_machdep.c,v 1.25 2006/06/20 18:24:04 todd Exp $ */ 3 4 /* 5 * Copyright (c) 2002, 2003 Genetec Corporation. All rights reserved. 6 * Written by Hiroyuki Bessho for Genetec Corporation. 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. The name of Genetec Corporation may not be used to endorse or 17 * promote products derived from this software without specific prior 18 * written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 * 32 * Machine dependent functions for kernel setup for 33 * Intel DBPXA250 evaluation board (a.k.a. Lubbock). 34 * Based on iq80310_machhdep.c 35 */ 36 37 /* 38 * Copyright (c) 2001 Wasabi Systems, Inc. 39 * All rights reserved. 40 * 41 * Written by Jason R. Thorpe for Wasabi Systems, Inc. 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 for the NetBSD Project by 54 * Wasabi Systems, Inc. 55 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 56 * or promote products derived from this software without specific prior 57 * written permission. 58 * 59 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 61 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 62 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 63 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 64 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 65 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 66 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 67 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 68 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 69 * POSSIBILITY OF SUCH DAMAGE. 70 */ 71 72 /* 73 * Copyright (c) 1997,1998 Mark Brinicombe. 74 * Copyright (c) 1997,1998 Causality Limited. 75 * All rights reserved. 76 * 77 * Redistribution and use in source and binary forms, with or without 78 * modification, are permitted provided that the following conditions 79 * are met: 80 * 1. Redistributions of source code must retain the above copyright 81 * notice, this list of conditions and the following disclaimer. 82 * 2. Redistributions in binary form must reproduce the above copyright 83 * notice, this list of conditions and the following disclaimer in the 84 * documentation and/or other materials provided with the distribution. 85 * 3. All advertising materials mentioning features or use of this software 86 * must display the following acknowledgement: 87 * This product includes software developed by Mark Brinicombe 88 * for the NetBSD Project. 89 * 4. The name of the company nor the name of the author may be used to 90 * endorse or promote products derived from this software without specific 91 * prior written permission. 92 * 93 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 94 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 95 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 96 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 97 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 98 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 99 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 101 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 102 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 103 * SUCH DAMAGE. 104 * 105 * Machine dependent functions for kernel setup for Intel IQ80310 evaluation 106 * boards using RedBoot firmware. 107 */ 108 109 #include <sys/cdefs.h> 110 __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.55 2024/05/13 00:08:06 msaitoh Exp $"); 111 112 #include "opt_ddb.h" 113 #include "opt_kgdb.h" 114 #include "opt_modular.h" 115 #include "opt_md.h" 116 #include "opt_com.h" 117 #include "ksyms.h" 118 119 #include "opt_kloader.h" 120 #ifndef KLOADER_KERNEL_PATH 121 #define KLOADER_KERNEL_PATH "/netbsd" 122 #endif 123 124 #include <sys/param.h> 125 #include <sys/device.h> 126 #include <sys/systm.h> 127 #include <sys/kernel.h> 128 #include <sys/exec.h> 129 #include <sys/proc.h> 130 #include <sys/msgbuf.h> 131 #include <sys/reboot.h> 132 #include <sys/termios.h> 133 #include <sys/boot_flag.h> 134 #include <sys/cpu.h> 135 #include <sys/conf.h> 136 #include <sys/queue.h> 137 #include <sys/bus.h> 138 139 #include <uvm/uvm_extern.h> 140 141 #include <dev/cons.h> 142 143 #include <dev/ic/comreg.h> 144 145 #include <machine/db_machdep.h> 146 #include <ddb/db_sym.h> 147 #include <ddb/db_extern.h> 148 #ifdef KGDB 149 #include <sys/kgdb.h> 150 #endif 151 152 #include <machine/bootconfig.h> 153 #include <machine/bootinfo.h> 154 #ifdef KLOADER 155 #include <machine/kloader.h> 156 #endif 157 158 #include <arm/locore.h> 159 #include <arm/undefined.h> 160 #include <arm/arm32/machdep.h> 161 162 #include <arm/xscale/pxa2x0cpu.h> 163 #include <arm/xscale/pxa2x0reg.h> 164 #include <arm/xscale/pxa2x0var.h> 165 #include <arm/xscale/pxa2x0_gpio.h> 166 167 #include <arm/sa11x0/sa11x0_ostvar.h> 168 169 #include <arch/zaurus/zaurus/zaurus_reg.h> 170 #include <arch/zaurus/zaurus/zaurus_var.h> 171 172 #include <zaurus/dev/scoopreg.h> 173 #include <zaurus/dev/zlcdvar.h> 174 #include <zaurus/dev/w100lcdvar.h> 175 176 #if 0 /* XXX */ 177 #include "apm.h" 178 #endif /* XXX */ 179 #if NAPM > 0 180 #include <zaurus/dev/zapmvar.h> 181 #endif 182 183 /* Kernel text starts 2MB in from the bottom of the kernel address space. */ 184 #define KERNEL_TEXT_BASE ((vaddr_t)&KERNEL_BASE_virt) 185 #ifndef KERNEL_VM_BASE 186 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000) 187 #endif 188 189 /* 190 * The range 0xc4000000 - 0xcfffffff is available for kernel VM space 191 * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff 192 */ 193 #define KERNEL_VM_SIZE 0x0c000000 194 195 int zaurusmod; /* Zaurus model */ 196 197 BootConfig bootconfig; /* Boot config storage */ 198 char *boot_file = NULL; 199 char *boot_args = NULL; 200 201 paddr_t physical_start; 202 paddr_t physical_freestart; 203 paddr_t physical_freeend; 204 paddr_t physical_end; 205 u_int free_pages; 206 207 #ifndef PMAP_STATIC_L1S 208 int max_processes = 64; /* Default number */ 209 #endif /* !PMAP_STATIC_L1S */ 210 211 /* Physical and virtual addresses for some global pages */ 212 pv_addr_t minidataclean; 213 214 paddr_t msgbufphys; 215 216 #define KERNEL_PT_SYS 0 /* Page table for mapping proc0 zero page */ 217 #define KERNEL_PT_KERNEL 1 /* Page table for mapping kernel */ 218 #define KERNEL_PT_KERNEL_NUM ((KERNEL_VM_BASE - KERNEL_BASE) >> 22) 219 #define KERNEL_PT_VMDATA (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM) 220 /* Page tables for mapping kernel VM */ 221 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */ 222 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM) 223 224 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS]; 225 226 const char *console = 227 #ifdef FFUARTCONSOLE 228 "ffuart"; 229 #else 230 "glass"; 231 #endif 232 int glass_console = 0; 233 234 #ifdef KLOADER 235 pv_addr_t bootinfo_pt; 236 pv_addr_t bootinfo_pg; 237 struct kloader_bootinfo kbootinfo; 238 int kloader_howto = 0; 239 #else 240 struct bootinfo _bootinfo; 241 #endif 242 struct bootinfo *bootinfo; 243 struct btinfo_howto *bi_howto; 244 245 extern char etext[], end[]; 246 extern void *esym; 247 #if NKSYMS || defined(DDB) || defined(MODULAR) 248 #include <sys/exec_elf.h> 249 #endif 250 251 #define KERNEL_BASE_PHYS ((paddr_t)&KERNEL_BASE_phys) 252 #define BOOTINFO_PAGE (KERNEL_BASE_PHYS - PAGE_SIZE) 253 254 /* Prototypes */ 255 void consinit(void); 256 void dumpsys(void); 257 #ifdef KGDB 258 void kgdb_port_init(void); 259 #endif 260 #ifdef KLOADER 261 static int parseboot(char *arg, char **filename, int *howto); 262 static char *gettrailer(char *arg); 263 static int parseopts(const char *opts, int *howto); 264 #endif 265 266 #if defined(CPU_XSCALE_PXA250) 267 static struct pxa2x0_gpioconf pxa25x_boarddep_gpioconf[] = { 268 { 34, GPIO_ALT_FN_1_IN }, /* FFRXD */ 269 { 35, GPIO_ALT_FN_1_IN }, /* FFCTS */ 270 { 39, GPIO_ALT_FN_2_OUT }, /* FFTXD */ 271 { 40, GPIO_ALT_FN_2_OUT }, /* FFDTR */ 272 { 41, GPIO_ALT_FN_2_OUT }, /* FFRTS */ 273 274 { 44, GPIO_ALT_FN_1_IN }, /* BTCST */ 275 { 45, GPIO_ALT_FN_2_OUT }, /* BTRST */ 276 277 { -1 } 278 }; 279 static struct pxa2x0_gpioconf *pxa25x_zaurus_gpioconf[] = { 280 pxa25x_com_btuart_gpioconf, 281 pxa25x_com_ffuart_gpioconf, 282 pxa25x_com_stuart_gpioconf, 283 pxa25x_boarddep_gpioconf, 284 NULL 285 }; 286 #else 287 static struct pxa2x0_gpioconf *pxa25x_zaurus_gpioconf[] = { 288 NULL 289 }; 290 #endif 291 #if defined(CPU_XSCALE_PXA270) 292 static struct pxa2x0_gpioconf pxa27x_boarddep_gpioconf[] = { 293 { 34, GPIO_ALT_FN_1_IN }, /* FFRXD */ 294 { 35, GPIO_ALT_FN_1_IN }, /* FFCTS */ 295 { 39, GPIO_ALT_FN_2_OUT }, /* FFTXD */ 296 { 40, GPIO_ALT_FN_2_OUT }, /* FFDTR */ 297 { 41, GPIO_ALT_FN_2_OUT }, /* FFRTS */ 298 299 { 44, GPIO_ALT_FN_1_IN }, /* BTCST */ 300 { 45, GPIO_ALT_FN_2_OUT }, /* BTRST */ 301 302 { 104, GPIO_ALT_FN_1_OUT }, /* pSKTSEL */ 303 304 { -1 } 305 }; 306 static struct pxa2x0_gpioconf *pxa27x_zaurus_gpioconf[] = { 307 pxa27x_com_btuart_gpioconf, 308 pxa27x_com_ffuart_gpioconf, 309 pxa27x_com_stuart_gpioconf, 310 pxa27x_i2c_gpioconf, 311 pxa27x_i2s_gpioconf, 312 pxa27x_pxamci_gpioconf, 313 pxa27x_boarddep_gpioconf, 314 NULL 315 }; 316 #else 317 static struct pxa2x0_gpioconf *pxa27x_zaurus_gpioconf[] = { 318 NULL 319 }; 320 #endif 321 322 /* 323 * void cpu_reboot(int howto, char *bootstr) 324 * 325 * Reboots the system 326 * 327 * Deal with any syncing, unmounting, dumping and shutdown hooks, 328 * then reset the CPU. 329 */ 330 void 331 cpu_reboot(int howto, char *bootstr) 332 { 333 /* 334 * If we are still cold then hit the air brakes 335 * and crash to earth fast 336 */ 337 if (cold) { 338 howto |= RB_HALT; 339 goto haltsys; 340 } 341 342 boothowto = howto; 343 344 #ifdef KLOADER 345 if ((howto & RB_HALT) == 0 && panicstr == NULL) { 346 char *filename = NULL; 347 348 if ((howto & RB_STRING) && (bootstr != NULL)) { 349 if (parseboot(bootstr, &filename, &kloader_howto) == 0){ 350 filename = NULL; 351 kloader_howto = 0; 352 } 353 } 354 if (kloader_howto != 0) { 355 printf("howto: 0x%x\n", kloader_howto); 356 } 357 if (filename != NULL) { 358 kloader_reboot_setup(filename); 359 } else { 360 kloader_reboot_setup(KLOADER_KERNEL_PATH); 361 } 362 } 363 #endif 364 365 /* 366 * If RB_NOSYNC was not specified sync the discs. 367 * Note: Unless cold is set to 1 here, syslogd will die during the 368 * unmount. It looks like syslogd is getting woken up only to find 369 * that it cannot page part of the binary in as the filesystem has 370 * been unmounted. 371 */ 372 if (!(howto & RB_NOSYNC)) { 373 bootsync(); 374 } 375 376 /* Wait 3s */ 377 delay(3 * 1000 * 1000); 378 379 /* Say NO to interrupts */ 380 splhigh(); 381 382 /* Do a dump if requested. */ 383 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) 384 dumpsys(); 385 386 haltsys: 387 /* Run any shutdown hooks */ 388 doshutdownhooks(); 389 390 pmf_system_shutdown(boothowto); 391 392 /* Make sure IRQ's are disabled */ 393 IRQdisable; 394 395 if (howto & RB_HALT) { 396 #if NAPM > 0 397 if (howto & RB_POWERDOWN) { 398 printf("\nAttempting to power down...\n"); 399 zapm_poweroff(); 400 } 401 #endif 402 printf("The operating system has halted.\n"); 403 printf("Please press any key to reboot.\n\n"); 404 cngetc(); 405 } 406 #ifdef KLOADER 407 else if (panicstr == NULL) { 408 delay(1 * 1000 * 1000); 409 kloader_reboot(); 410 printf("\n"); 411 printf("Failed to load a new kernel.\n"); 412 printf("Please press any key to reboot.\n\n"); 413 cngetc(); 414 } 415 #endif 416 417 printf("rebooting...\n"); 418 delay(1 * 1000 * 1000); 419 zaurus_restart(); 420 421 printf("REBOOT FAILED!!!\n"); 422 for (;;) 423 continue; 424 /*NOTREACHED*/ 425 } 426 427 /* 428 * Do a GPIO reset, immediately causing the processor to begin the normal 429 * boot sequence. See 2.7 Reset in the PXA27x Developer's Manual for the 430 * summary of effects of this kind of reset. 431 */ 432 void 433 zaurus_restart(void) 434 { 435 uint32_t rv; 436 437 if (ZAURUS_ISC1000 || ZAURUS_ISC3000) { 438 rv = pxa2x0_memctl_read(MEMCTL_MSC0); 439 if ((rv & 0xffff0000) == 0x7ff00000) { 440 pxa2x0_memctl_write(MEMCTL_MSC0, 441 (rv & 0xffff) | 0x7ee00000); 442 } 443 444 /* External reset circuit presumably asserts nRESET_GPIO. */ 445 pxa2x0_gpio_set_function(89, GPIO_OUT | GPIO_SET); 446 } else { 447 /* SL-C7x0/SL-C860 */ 448 /* Clear all reset status */ 449 ioreg_write(ZAURUS_POWMAN_VBASE + POWMAN_RCSR, 450 POWMAN_HWR|POWMAN_WDR|POWMAN_SMR|POWMAN_GPR); 451 452 /* watchdog reset */ 453 saost_reset(); 454 } 455 delay(1 * 1000 * 1000); /* wait 1s */ 456 } 457 458 static inline pd_entry_t * 459 read_ttb(void) 460 { 461 u_long ttb; 462 463 __asm volatile("mrc p15, 0, %0, c2, c0, 0" : "=r" (ttb)); 464 465 return (pd_entry_t *)(ttb & ~((1 << 14) - 1)); 466 } 467 468 /* 469 * Static device mappings. These peripheral registers are mapped at 470 * fixed virtual addresses very early in initarm() so that we can use 471 * them while booting the kernel, and stay at the same address 472 * throughout whole kernel's life time. 473 * 474 * We use this table twice; once with bootstrap page table, and once 475 * with kernel's page table which we build up in initarm(). 476 * 477 * Since we map these registers into the bootstrap page table using 478 * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map 479 * registers segment-aligned and segment-rounded in order to avoid 480 * using the 2nd page tables. 481 */ 482 static const struct pmap_devmap zaurus_devmap[] = { 483 DEVMAP_ENTRY( 484 ZAURUS_GPIO_VBASE, 485 PXA2X0_GPIO_BASE, 486 PXA2X0_GPIO_SIZE 487 ), 488 DEVMAP_ENTRY( 489 ZAURUS_CLKMAN_VBASE, 490 PXA2X0_CLKMAN_BASE, 491 PXA2X0_CLKMAN_SIZE 492 ), 493 DEVMAP_ENTRY( 494 ZAURUS_INTCTL_VBASE, 495 PXA2X0_INTCTL_BASE, 496 PXA2X0_INTCTL_SIZE 497 ), 498 DEVMAP_ENTRY( 499 ZAURUS_MEMCTL_VBASE, 500 PXA2X0_MEMCTL_BASE, 501 PXA2X0_MEMCTL_SIZE 502 ), 503 DEVMAP_ENTRY( 504 ZAURUS_SCOOP0_VBASE, 505 C3000_SCOOP0_BASE, 506 SCOOP_SIZE 507 ), 508 DEVMAP_ENTRY( 509 ZAURUS_SCOOP1_VBASE, 510 C3000_SCOOP1_BASE, 511 SCOOP_SIZE 512 ), 513 DEVMAP_ENTRY( 514 ZAURUS_FFUART_VBASE, 515 PXA2X0_FFUART_BASE, 516 4 * COM_NPORTS 517 ), 518 DEVMAP_ENTRY( 519 ZAURUS_BTUART_VBASE, 520 PXA2X0_BTUART_BASE, 521 4 * COM_NPORTS 522 ), 523 DEVMAP_ENTRY( 524 ZAURUS_STUART_VBASE, 525 PXA2X0_STUART_BASE, 526 4 * COM_NPORTS 527 ), 528 DEVMAP_ENTRY( 529 ZAURUS_POWMAN_VBASE, 530 PXA2X0_POWMAN_BASE, 531 PXA2X0_POWMAN_SIZE 532 ), 533 534 DEVMAP_ENTRY_END 535 }; 536 537 void green_on(int virt); 538 void 539 green_on(int virt) 540 { 541 /* clobber green led p */ 542 volatile uint16_t *p; 543 544 if (virt) { 545 p = (volatile uint16_t *)(ZAURUS_SCOOP0_VBASE + SCOOP_GPWR); 546 } else { 547 p = (volatile uint16_t *)(C3000_SCOOP0_BASE + SCOOP_GPWR); 548 } 549 550 *p |= (1 << SCOOP0_LED_GREEN); 551 } 552 553 void irda_on(int virt); 554 void 555 irda_on(int virt) 556 { 557 /* clobber IrDA led p */ 558 volatile uint16_t *p; 559 560 if (virt) { 561 /* XXX scoop1 registers are not page-aligned! */ 562 int o = C3000_SCOOP1_BASE - trunc_page(C3000_SCOOP1_BASE); 563 p = (volatile uint16_t *)(ZAURUS_SCOOP1_VBASE + o + SCOOP_GPWR); 564 } else { 565 p = (volatile uint16_t *)(C3000_SCOOP1_BASE + SCOOP_GPWR); 566 } 567 568 *p &= ~(1 << SCOOP1_IR_ON); 569 } 570 571 static int 572 hw_isc1000(void) 573 { 574 /* XXX scoop1 registers are not page-aligned! */ 575 const u_long baseaddr = ZAURUS_SCOOP1_VBASE + 576 (C3000_SCOOP1_BASE - trunc_page(C3000_SCOOP1_BASE)); 577 uint16_t mcr, cdr, csr, cpr, ccr, irr, irm, imr, isr; 578 uint16_t gpcr, gpwr, gprr; 579 580 mcr = ioreg16_read(baseaddr + SCOOP_MCR); 581 cdr = ioreg16_read(baseaddr + SCOOP_CDR); 582 csr = ioreg16_read(baseaddr + SCOOP_CSR); 583 cpr = ioreg16_read(baseaddr + SCOOP_CPR); 584 ccr = ioreg16_read(baseaddr + SCOOP_CCR); 585 irr = ioreg16_read(baseaddr + SCOOP_IRR); 586 irm = ioreg16_read(baseaddr + SCOOP_IRM); 587 imr = ioreg16_read(baseaddr + SCOOP_IMR); 588 isr = ioreg16_read(baseaddr + SCOOP_ISR); 589 gpcr = ioreg16_read(baseaddr + SCOOP_GPCR); 590 gpwr = ioreg16_read(baseaddr + SCOOP_GPWR); 591 gprr = ioreg16_read(baseaddr + SCOOP_GPRR); 592 593 if (mcr == 0 && cdr == 0 && csr == 0 && cpr == 0 && ccr == 0 && 594 irr == 0 && irm == 0 && imr == 0 && isr == 0 && 595 gpcr == 0 && gpwr == 0 && gprr == 0) { 596 /* scoop1 isn't found: hardware is SL-C1000 */ 597 return 1; 598 } 599 return 0; 600 } 601 602 /* 603 * vaddr_t initarm(...) 604 * 605 * Initial entry point on startup. This gets called before main() is 606 * entered. 607 * It should be responsible for setting up everything that must be 608 * in place when main is called. 609 * This includes 610 * Taking a copy of the boot configuration structure. 611 * Initialising the physical console so characters can be printed. 612 * Setting up page tables for the kernel 613 * Relocating the kernel to the bottom of physical memory 614 */ 615 vaddr_t 616 initarm(void *arg) 617 { 618 extern char KERNEL_BASE_phys[], KERNEL_BASE_virt[]; 619 int loop; 620 int loop1; 621 u_int l1pagetable; 622 paddr_t memstart; 623 psize_t memsize; 624 struct pxa2x0_gpioconf **zaurus_gpioconf; 625 u_int *magicaddr; 626 #if NKSYMS || defined(DDB) || defined(MODULAR) 627 u_int symbolsize; 628 #endif 629 630 /* Get ready for zaurus_restart() */ 631 pxa2x0_memctl_bootstrap(PXA2X0_MEMCTL_BASE); 632 633 /* 634 * Heads up ... Setup the CPU / MMU / TLB functions 635 */ 636 if (set_cpufuncs()) 637 panic("cpu not recognized!"); 638 639 /* Get ready for splfoo() */ 640 pxa2x0_intr_bootstrap(PXA2X0_INTCTL_BASE); 641 642 /* map some peripheral registers at static I/O area */ 643 pmap_devmap_bootstrap((vaddr_t)read_ttb(), zaurus_devmap); 644 645 /* set new memctl register address so that zaurus_restart() doesn't 646 touch illegal address. */ 647 pxa2x0_memctl_bootstrap(ZAURUS_MEMCTL_VBASE); 648 649 /* set new intc register address so that splfoo() doesn't 650 touch illegal address. */ 651 pxa2x0_intr_bootstrap(ZAURUS_INTCTL_VBASE); 652 653 /* 654 * Examine the boot args string for options we need to know about 655 * now. 656 */ 657 magicaddr = (u_int *)(KERNEL_BASE_PHYS - BOOTARGS_BUFSIZ); 658 if (*magicaddr == BOOTARGS_MAGIC) { 659 #ifdef KLOADER 660 bootinfo = &kbootinfo.bootinfo; 661 #else 662 bootinfo = &_bootinfo; 663 #endif 664 memcpy(bootinfo, (void *)(KERNEL_BASE_PHYS - BOOTINFO_MAXSIZE), 665 BOOTINFO_MAXSIZE); 666 bi_howto = lookup_bootinfo(BTINFO_HOWTO); 667 boothowto = (bi_howto != NULL) ? bi_howto->howto : RB_AUTOBOOT; 668 } else { 669 boothowto = RB_AUTOBOOT; 670 } 671 *magicaddr = 0xdeadbeef; 672 if (boothowto & RB_MD1) { 673 /* serial console */ 674 console = "ffuart"; 675 } 676 677 memstart = PXA2X0_SDRAM0_START; 678 memsize = 0x04000000; /* 64MB */ 679 680 /* 681 * This test will work for now but has to be revised when support 682 * for other models is added. 683 */ 684 if ((cputype & ~CPU_ID_XSCALE_COREREV_MASK) == CPU_ID_PXA27X) { 685 if (hw_isc1000()) 686 zaurusmod = ZAURUS_C1000; /* SL-C1000 */ 687 else 688 zaurusmod = ZAURUS_C3000; /* SL-C3x00 */ 689 zaurus_gpioconf = pxa27x_zaurus_gpioconf; 690 } else { 691 zaurusmod = ZAURUS_C860; /* SL-C7x0/860 */ 692 if (cputype == CPU_ID_PXA250B) { 693 /* SL-C700 */ 694 memsize = 0x02000000; /* 32MB */ 695 } 696 zaurus_gpioconf = pxa25x_zaurus_gpioconf; 697 } 698 699 /* setup a serial console for very early boot */ 700 pxa2x0_gpio_bootstrap(ZAURUS_GPIO_VBASE); 701 pxa2x0_gpio_config(zaurus_gpioconf); 702 pxa2x0_clkman_bootstrap(ZAURUS_CLKMAN_VBASE); 703 if (strcmp(console, "glass") != 0) 704 consinit(); 705 #ifdef KGDB 706 kgdb_port_init(); 707 #endif 708 709 #ifdef VERBOSE_INIT_ARM 710 /* Talk to the user */ 711 printf("\nNetBSD/zaurus booting ...\n"); 712 #endif 713 714 #ifdef KLOADER 715 /* copy boot parameter for kloader */ 716 kloader_bootinfo_set(&kbootinfo, 0, NULL, NULL, true); 717 #endif 718 719 #ifdef VERBOSE_INIT_ARM 720 printf("initarm: Configuring system ...\n"); 721 #endif 722 723 /* Fake bootconfig structure for the benefit of pmap.c */ 724 /* XXX must make the memory description h/w independent */ 725 bootconfig.dramblocks = 1; 726 bootconfig.dram[0].address = memstart; 727 bootconfig.dram[0].pages = memsize / PAGE_SIZE; 728 729 /* 730 * Set up the variables that define the availability of 731 * physical memory. For now, we're going to set 732 * physical_freestart to 0xa0200000 (where the kernel 733 * was loaded), and allocate the memory we need downwards. 734 * If we get too close to the page tables that RedBoot 735 * set up, we will panic. We will update physical_freestart 736 * and physical_freeend later to reflect what pmap_bootstrap() 737 * wants to see. 738 * 739 * XXX pmap_bootstrap() needs an enema. 740 */ 741 physical_start = bootconfig.dram[0].address; 742 physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE); 743 744 physical_freestart = PXA2X0_SDRAM0_START + 0x9000; 745 physical_freeend = BOOTINFO_PAGE; 746 747 physmem = (physical_end - physical_start) / PAGE_SIZE; 748 749 #ifdef VERBOSE_INIT_ARM 750 /* Tell the user about the memory */ 751 printf("physmemory: %lu pages at 0x%08lx -> 0x%08lx\n", physmem, 752 physical_start, physical_end - 1); 753 #endif 754 755 /* 756 * Okay, the kernel starts 2MB in from the bottom of physical 757 * memory. We are going to allocate our bootstrap pages downwards 758 * from there. 759 * 760 * We need to allocate some fixed page tables to get the kernel 761 * going. We allocate one page directory and a number of page 762 * tables and store the physical addresses in the kernel_pt_table 763 * array. 764 * 765 * The kernel page directory must be on a 16K boundary. The page 766 * tables must be on 4K boundaries. What we do is allocate the 767 * page directory on the first 16K boundary that we encounter, and 768 * the page tables on 4K boundaries otherwise. Since we allocate 769 * at least 3 L2 page tables, we are guaranteed to encounter at 770 * least one 16K aligned region. 771 */ 772 773 #ifdef VERBOSE_INIT_ARM 774 printf("Allocating page tables\n"); 775 #endif 776 777 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE; 778 779 #ifdef VERBOSE_INIT_ARM 780 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n", 781 physical_freestart, free_pages, free_pages); 782 #endif 783 784 /* Define a macro to simplify memory allocation */ 785 #define valloc_pages(var, np) \ 786 alloc_pages((var).pv_pa, (np)); \ 787 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start; 788 789 #define alloc_pages(var, np) \ 790 physical_freeend -= ((np) * PAGE_SIZE); \ 791 if (physical_freeend < physical_freestart) \ 792 panic("initarm: out of memory"); \ 793 (var) = physical_freeend; \ 794 free_pages -= (np); \ 795 memset((char *)(var), 0, ((np) * PAGE_SIZE)); 796 797 loop1 = 0; 798 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) { 799 /* Are we 16KB aligned for an L1 ? */ 800 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0 801 && kernel_l1pt.pv_pa == 0) { 802 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE); 803 } else { 804 valloc_pages(kernel_pt_table[loop1], 805 L2_TABLE_SIZE / PAGE_SIZE); 806 ++loop1; 807 } 808 } 809 #ifdef KLOADER 810 valloc_pages(bootinfo_pt, L2_TABLE_SIZE / PAGE_SIZE); 811 #endif 812 813 /* This should never be able to happen but better confirm that. */ 814 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0) 815 panic("initarm: Failed to align the kernel page directory"); 816 817 /* 818 * Allocate a page for the system page mapped to V0x00000000 819 * This page will just contain the system vectors and can be 820 * shared by all processes. 821 */ 822 alloc_pages(systempage.pv_pa, 1); 823 824 /* Allocate stacks for all modes */ 825 valloc_pages(irqstack, IRQ_STACK_SIZE); 826 valloc_pages(abtstack, ABT_STACK_SIZE); 827 valloc_pages(undstack, UND_STACK_SIZE); 828 valloc_pages(kernelstack, UPAGES); 829 830 /* Allocate enough pages for cleaning the Mini-Data cache. */ 831 #ifdef DIAGNOSTIC 832 KASSERT(xscale_minidata_clean_size <= PAGE_SIZE); 833 #endif 834 valloc_pages(minidataclean, 1); 835 836 #ifdef KLOADER 837 bootinfo_pg.pv_pa = BOOTINFO_PAGE; 838 bootinfo_pg.pv_va = KERNEL_BASE + bootinfo_pg.pv_pa - physical_start; 839 #endif 840 841 #ifdef VERBOSE_INIT_ARM 842 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa, 843 irqstack.pv_va); 844 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa, 845 abtstack.pv_va); 846 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa, 847 undstack.pv_va); 848 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa, 849 kernelstack.pv_va); 850 printf("minidataclean: p0x%08lx v0x%08lx, size = %ld\n", 851 minidataclean.pv_pa, minidataclean.pv_va, 852 xscale_minidata_clean_size); 853 #ifdef KLOADER 854 printf("bootinfo_pg: p0x%08lx v0x%08lx\n", bootinfo_pg.pv_pa, 855 bootinfo_pg.pv_va); 856 #endif 857 #endif 858 859 /* 860 * XXX Defer this to later so that we can reclaim the memory 861 * XXX used by the RedBoot page tables. 862 */ 863 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE); 864 865 /* 866 * Ok we have allocated physical pages for the primary kernel 867 * page tables 868 */ 869 870 #ifdef VERBOSE_INIT_ARM 871 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa); 872 #endif 873 874 /* 875 * Now we start construction of the L1 page table 876 * We start by mapping the L2 page tables into the L1. 877 * This means that we can replace L1 mappings later on if necessary 878 */ 879 l1pagetable = kernel_l1pt.pv_pa; 880 881 /* Map the L2 pages tables in the L1 page table */ 882 pmap_link_l2pt(l1pagetable, 0x00000000, 883 &kernel_pt_table[KERNEL_PT_SYS]); 884 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++) 885 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000, 886 &kernel_pt_table[KERNEL_PT_KERNEL + loop]); 887 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++) 888 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000, 889 &kernel_pt_table[KERNEL_PT_VMDATA + loop]); 890 #ifdef KLOADER 891 pmap_link_l2pt(l1pagetable, PXA2X0_SDRAM0_START, &bootinfo_pt); 892 #endif 893 894 /* update the top of the kernel VM */ 895 pmap_curmaxkvaddr = 896 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000); 897 898 /* check symbol table loaded by bootloader (zbsdmod.o) */ 899 esym = end; 900 #if NKSYMS || defined(DDB) || defined(MODULAR) 901 symbolsize = 0; 902 Elf_Ehdr *eh = (Elf_Ehdr *)end; 903 #ifdef VERBOSE_INIT_ARM 904 printf("Checking ELF MAGIC at end: %02x %02x %02x %02x\n", 905 end[0], end[1], end[2], end[3]); 906 #endif 907 if (memcmp(eh->e_ident, ELFMAG, SELFMAG) == 0) { 908 Elf_Shdr *sh; 909 #ifdef VERBOSE_INIT_ARM 910 printf("ELF header found at end\n"); 911 #endif 912 sh = (Elf_Shdr *)((char *)end + eh->e_shoff); 913 for (loop = 0; loop < eh->e_shnum; loop++, sh++) { 914 #ifdef VERBOSE_INIT_ARM 915 printf("Checking ELF header %d\n", loop); 916 #endif 917 if (sh->sh_type != SHT_SYMTAB && 918 sh->sh_type != SHT_STRTAB) { 919 continue; 920 } 921 #ifdef VERBOSE_INIT_ARM 922 printf("Section[%2d]: offset = %d, size = %d\n", 923 loop, sh->sh_offset, sh->sh_size); 924 #endif 925 if (sh->sh_offset > 0 && 926 (sh->sh_offset + sh->sh_size) > symbolsize) { 927 symbolsize = sh->sh_offset + sh->sh_size; 928 } 929 #ifdef VERBOSE_INIT_ARM 930 printf("Updating symbolsize = %d\n", symbolsize); 931 #endif 932 } 933 esym = (char *)esym + symbolsize; 934 } 935 #ifdef VERBOSE_INIT_ARM 936 printf("symbolsize = %d\n", symbolsize); 937 #endif 938 #endif /* NKSYMS || defined(DDB) || defined(MODULAR) */ 939 940 #ifdef VERBOSE_INIT_ARM 941 printf("Mapping kernel\n"); 942 #endif 943 944 /* Now we fill in the L2 pagetable for the kernel static code/data 945 * and the symbol table. */ 946 { 947 948 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE; 949 size_t totalsize = (uintptr_t) esym - KERNEL_TEXT_BASE; 950 u_int logical; 951 952 textsize = (textsize + PGOFSET) & ~PGOFSET; 953 totalsize = (totalsize + PGOFSET) & ~PGOFSET; 954 955 /* offset of kernel in RAM */ 956 logical = KERNEL_TEXT_BASE - KERNEL_BASE; 957 958 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical, 959 physical_start + logical, textsize, 960 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 961 pmap_map_chunk(l1pagetable, KERNEL_BASE + logical, 962 physical_start + logical, totalsize - textsize, 963 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 964 } 965 966 #ifdef VERBOSE_INIT_ARM 967 printf("Constructing L2 page tables\n"); 968 #endif 969 970 /* Map the stack pages */ 971 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa, 972 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 973 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa, 974 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 975 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa, 976 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 977 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa, 978 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 979 980 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa, 981 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE); 982 983 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) { 984 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va, 985 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE, 986 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE); 987 } 988 989 #ifdef KLOADER 990 pmap_map_chunk(l1pagetable, bootinfo_pt.pv_va, bootinfo_pt.pv_pa, 991 L2_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE); 992 pmap_map_chunk(l1pagetable, bootinfo_pg.pv_va, bootinfo_pg.pv_pa, 993 PAGE_SIZE, VM_PROT_ALL, PTE_CACHE); 994 #endif 995 996 /* Map the Mini-Data cache clean area. */ 997 xscale_setup_minidata(l1pagetable, minidataclean.pv_va, 998 minidataclean.pv_pa); 999 1000 /* Map the vector page. */ 1001 #if 0 1002 /* MULTI-ICE requires that page 0 is NC/NB so that it can download the 1003 * cache-clean code there. */ 1004 pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa, 1005 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE); 1006 #else 1007 pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa, 1008 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 1009 #endif 1010 1011 /* 1012 * map integrated peripherals at same address in l1pagetable 1013 * so that we can continue to use console. 1014 */ 1015 pmap_devmap_bootstrap(l1pagetable, zaurus_devmap); 1016 1017 /* 1018 * Give the XScale global cache clean code an appropriately 1019 * sized chunk of unmapped VA space starting at 0xff000000 1020 * (our device mappings end before this address). 1021 */ 1022 xscale_cache_clean_addr = 0xff000000U; 1023 1024 /* 1025 * Now we have the real page tables in place so we can switch to them. 1026 * Once this is done we will be running with the REAL kernel page 1027 * tables. 1028 */ 1029 1030 /* 1031 * Update the physical_freestart/physical_freeend/free_pages 1032 * variables. 1033 */ 1034 { 1035 1036 physical_freestart = physical_start + 1037 ((((uintptr_t) esym + PGOFSET) & ~PGOFSET) - KERNEL_BASE); 1038 physical_freeend = physical_end; 1039 free_pages = 1040 (physical_freeend - physical_freestart) / PAGE_SIZE; 1041 } 1042 1043 /* Switch tables */ 1044 #ifdef VERBOSE_INIT_ARM 1045 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n", 1046 physical_freestart, free_pages, free_pages); 1047 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa); 1048 #endif 1049 1050 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT); 1051 cpu_setttb(kernel_l1pt.pv_pa, true); 1052 cpu_tlb_flushID(); 1053 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)); 1054 1055 /* 1056 * Moved from cpu_startup() as data_abort_handler() references 1057 * this during uvm init 1058 */ 1059 uvm_lwp_setuarea(&lwp0, kernelstack.pv_va); 1060 1061 #ifdef VERBOSE_INIT_ARM 1062 printf("bootstrap done.\n"); 1063 #endif 1064 1065 arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL); 1066 1067 /* 1068 * Pages were allocated during the secondary bootstrap for the 1069 * stacks for different CPU modes. 1070 * We must now set the r13 registers in the different CPU modes to 1071 * point to these stacks. 1072 * Since the ARM stacks use STMFD etc. we must set r13 to the top end 1073 * of the stack memory. 1074 */ 1075 #ifdef VERBOSE_INIT_ARM 1076 printf("init subsystems: stacks "); 1077 #endif 1078 1079 set_stackptr(PSR_IRQ32_MODE, 1080 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE); 1081 set_stackptr(PSR_ABT32_MODE, 1082 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE); 1083 set_stackptr(PSR_UND32_MODE, 1084 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE); 1085 1086 /* 1087 * Well we should set a data abort handler. 1088 * Once things get going this will change as we will need a proper 1089 * handler. 1090 * Until then we will use a handler that just panics but tells us 1091 * why. 1092 * Initialisation of the vectors will just panic on a data abort. 1093 * This just fills in a slightly better one. 1094 */ 1095 #ifdef VERBOSE_INIT_ARM 1096 printf("vectors "); 1097 #endif 1098 data_abort_handler_address = (u_int)data_abort_handler; 1099 prefetch_abort_handler_address = (u_int)prefetch_abort_handler; 1100 undefined_handler_address = (u_int)undefinedinstruction_bounce; 1101 1102 /* Initialise the undefined instruction handlers */ 1103 #ifdef VERBOSE_INIT_ARM 1104 printf("undefined "); 1105 #endif 1106 undefined_init(); 1107 1108 /* Load memory into UVM. */ 1109 #ifdef VERBOSE_INIT_ARM 1110 printf("page "); 1111 #endif 1112 uvm_md_init(); 1113 uvm_page_physload(atop(physical_freestart), atop(physical_freeend), 1114 atop(physical_freestart), atop(physical_freeend), 1115 VM_FREELIST_DEFAULT); 1116 1117 /* Boot strap pmap telling it where managed kernel virtual memory is */ 1118 #ifdef VERBOSE_INIT_ARM 1119 printf("pmap "); 1120 #endif 1121 pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE); 1122 1123 #ifdef VERBOSE_INIT_ARM 1124 printf("\n"); 1125 #endif 1126 1127 #ifdef __HAVE_MEMORY_DISK__ 1128 md_root_setconf(memory_disk, sizeof memory_disk); 1129 #endif 1130 1131 #if NKSYMS || defined(DDB) || defined(MODULAR) 1132 if (symbolsize > 0) 1133 ksyms_addsyms_elf(symbolsize, &end, esym); 1134 #endif 1135 1136 #ifdef KGDB 1137 if (boothowto & RB_KDB) { 1138 kgdb_debug_init = 1; 1139 kgdb_connect(1); 1140 } 1141 #endif 1142 1143 #ifdef DDB 1144 db_machine_init(); 1145 if (boothowto & RB_KDB) 1146 Debugger(); 1147 #endif 1148 1149 /* We return the new stack pointer address */ 1150 return kernelstack.pv_va + USPACE_SVC_STACK_TOP; 1151 } 1152 1153 void * 1154 lookup_bootinfo(int type) 1155 { 1156 struct btinfo_common *help; 1157 int n; 1158 1159 if (bootinfo == NULL) 1160 return (NULL); 1161 1162 n = bootinfo->nentries; 1163 help = (struct btinfo_common *)(bootinfo->info); 1164 while (n--) { 1165 if (help->type == type) 1166 return (help); 1167 help = (struct btinfo_common *)((char *)help + help->len); 1168 } 1169 return (NULL); 1170 } 1171 1172 #ifdef KLOADER 1173 static int 1174 parseboot(char *arg, char **filename, int *howto) 1175 { 1176 char *opts = NULL; 1177 1178 *filename = NULL; 1179 *howto = 0; 1180 1181 /* if there were no arguments */ 1182 if (arg == NULL || *arg == '\0') 1183 return 1; 1184 1185 /* format is... */ 1186 /* [[xxNx:]filename] [-adqsv] */ 1187 1188 /* check for just args */ 1189 if (arg[0] == '-') { 1190 opts = arg; 1191 } else { 1192 /* there's a file name */ 1193 *filename = arg; 1194 1195 opts = gettrailer(arg); 1196 if (opts == NULL || *opts == '\0') { 1197 opts = NULL; 1198 } else if (*opts != '-') { 1199 printf("invalid arguments\n"); 1200 return 0; 1201 } 1202 } 1203 1204 /* at this point, we have dealt with filenames. */ 1205 1206 /* now, deal with options */ 1207 if (opts) { 1208 if (parseopts(opts, howto) == 0) { 1209 return 0; 1210 } 1211 } 1212 return 1; 1213 } 1214 1215 static char * 1216 gettrailer(char *arg) 1217 { 1218 static char nullstr[] = ""; 1219 char *options; 1220 1221 if ((options = strchr(arg, ' ')) == NULL) 1222 return nullstr; 1223 else 1224 *options++ = '\0'; 1225 1226 /* trim leading blanks */ 1227 while (*options == ' ') 1228 options++; 1229 1230 return options; 1231 } 1232 1233 static int 1234 parseopts(const char *opts, int *howto) 1235 { 1236 int r, tmpopt = *howto; 1237 1238 opts++; /* skip - */ 1239 while (*opts && *opts != ' ') { 1240 r = 0; 1241 BOOT_FLAG(*opts, r); 1242 if (r == 0) { 1243 printf("-%c: unknown flag\n", *opts); 1244 return 0; 1245 } 1246 tmpopt |= r; 1247 opts++; 1248 } 1249 1250 *howto = tmpopt; 1251 return 1; 1252 } 1253 #endif 1254 1255 /* 1256 * Console 1257 */ 1258 #include "com.h" 1259 #if (NCOM > 0) 1260 #include <dev/ic/comvar.h> 1261 #endif 1262 1263 #include "lcd.h" 1264 #include "w100lcd.h" 1265 #include "wsdisplay.h" 1266 1267 #ifndef CONSPEED 1268 #define CONSPEED B9600 1269 #endif 1270 #ifndef CONMODE 1271 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ 1272 #endif 1273 1274 int comcnspeed = CONSPEED; 1275 int comcnmode = CONMODE; 1276 1277 #ifdef KGDB 1278 #ifndef KGDB_DEVNAME 1279 #define KGDB_DEVNAME "ffuart" 1280 #endif 1281 const char kgdb_devname[] = KGDB_DEVNAME; 1282 1283 #if (NCOM > 0) 1284 #ifndef KGDB_DEVMODE 1285 #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ 1286 #endif 1287 int comkgdbmode = KGDB_DEVMODE; 1288 #endif /* NCOM */ 1289 #endif /* KGDB */ 1290 1291 void 1292 consinit(void) 1293 { 1294 static int consinit_called = 0; 1295 #if (NCOM > 0) && defined(COM_PXA2X0) 1296 paddr_t paddr; 1297 u_int cken = 0; 1298 #endif 1299 1300 if (consinit_called) 1301 return; 1302 consinit_called = 1; 1303 1304 #if (NCOM > 0) && defined(COM_PXA2X0) 1305 #ifdef KGDB 1306 if (strcmp(kgdb_devname, console) == 0) { 1307 /* port is reserved for kgdb */ 1308 } else 1309 #endif 1310 if (strcmp(console, "ffuart") == 0) { 1311 paddr = PXA2X0_FFUART_BASE; 1312 cken = CKEN_FFUART; 1313 } else if (strcmp(console, "btuart") == 0) { 1314 paddr = PXA2X0_BTUART_BASE; 1315 cken = CKEN_BTUART; 1316 } else if (strcmp(console, "stuart") == 0) { 1317 paddr = PXA2X0_STUART_BASE; 1318 cken = CKEN_STUART; 1319 irda_on(0); 1320 } else 1321 #endif 1322 if (strcmp(console, "glass") == 0) { 1323 #if ((NLCD > 0) || (NW100LCD > 0)) && (NWSDISPLAY > 0) 1324 glass_console = 1; 1325 #if NLCD > 0 1326 if (ZAURUS_ISC1000 || ZAURUS_ISC3000) 1327 lcd_cnattach(); 1328 #endif 1329 #if NW100LCD > 0 1330 if (ZAURUS_ISC860) 1331 w100lcd_cnattach(); 1332 #endif 1333 #endif 1334 } 1335 1336 #if (NCOM > 0) && defined(COM_PXA2X0) 1337 if (cken != 0 && comcnattach(&pxa2x0_a4x_bs_tag, paddr, comcnspeed, 1338 PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode) == 0) { 1339 pxa2x0_clkman_config(cken, 1); 1340 } 1341 #endif 1342 } 1343 1344 #ifdef KGDB 1345 void 1346 kgdb_port_init(void) 1347 { 1348 #if (NCOM > 0) && defined(COM_PXA2X0) 1349 paddr_t paddr; 1350 u_int cken; 1351 1352 if (strcmp(kgdb_devname, "ffuart") == 0) { 1353 paddr = PXA2X0_FFUART_BASE; 1354 cken = CKEN_FFUART; 1355 } else if (strcmp(kgdb_devname, "btuart") == 0) { 1356 paddr = PXA2X0_BTUART_BASE; 1357 cken = CKEN_BTUART; 1358 } else if (strcmp(kgdb_devname, "stuart") == 0) { 1359 paddr = PXA2X0_STUART_BASE; 1360 cken = CKEN_STUART; 1361 irda_on(0); 1362 } else 1363 return; 1364 1365 if (com_kgdb_attach(&pxa2x0_a4x_bs_tag, paddr, 1366 kgdb_rate, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comkgdbmode) == 0) { 1367 pxa2x0_clkman_config(cken, 1); 1368 } 1369 #endif 1370 } 1371 #endif 1372