1 /* $NetBSD: machdep.c,v 1.35 2004/03/24 15:34:51 atatat Exp $ */ 2 3 /* 4 * Copyright (c) 1982, 1986, 1990, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * the Systems Programming Group of the University of Utah Computer 9 * Science Department. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * from: Utah Hdr: machdep.c 1.74 92/12/20 36 * from: @(#)machdep.c 8.10 (Berkeley) 4/20/94 37 */ 38 39 /* 40 * Copyright (c) 2001 Matthew Fredette. 41 * Copyright (c) 1994, 1995 Gordon W. Ross 42 * Copyright (c) 1993 Adam Glass 43 * Copyright (c) 1988 University of Utah. 44 * 45 * This code is derived from software contributed to Berkeley by 46 * the Systems Programming Group of the University of Utah Computer 47 * Science Department. 48 * 49 * Redistribution and use in source and binary forms, with or without 50 * modification, are permitted provided that the following conditions 51 * are met: 52 * 1. Redistributions of source code must retain the above copyright 53 * notice, this list of conditions and the following disclaimer. 54 * 2. Redistributions in binary form must reproduce the above copyright 55 * notice, this list of conditions and the following disclaimer in the 56 * documentation and/or other materials provided with the distribution. 57 * 3. All advertising materials mentioning features or use of this software 58 * must display the following acknowledgement: 59 * This product includes software developed by the University of 60 * California, Berkeley and its contributors. 61 * 4. Neither the name of the University nor the names of its contributors 62 * may be used to endorse or promote products derived from this software 63 * without specific prior written permission. 64 * 65 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 66 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 67 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 68 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 69 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 70 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 71 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 72 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 73 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 74 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 75 * SUCH DAMAGE. 76 * 77 * from: Utah Hdr: machdep.c 1.74 92/12/20 78 * from: @(#)machdep.c 8.10 (Berkeley) 4/20/94 79 */ 80 81 /*- 82 * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc. 83 * All rights reserved. 84 * 85 * This code is derived from software contributed to The NetBSD Foundation 86 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 87 * NASA Ames Research Center. 88 * 89 * Redistribution and use in source and binary forms, with or without 90 * modification, are permitted provided that the following conditions 91 * are met: 92 * 1. Redistributions of source code must retain the above copyright 93 * notice, this list of conditions and the following disclaimer. 94 * 2. Redistributions in binary form must reproduce the above copyright 95 * notice, this list of conditions and the following disclaimer in the 96 * documentation and/or other materials provided with the distribution. 97 * 3. All advertising materials mentioning features or use of this software 98 * must display the following acknowledgement: 99 * This product includes software developed by the NetBSD 100 * Foundation, Inc. and its contributors. 101 * 4. Neither the name of The NetBSD Foundation nor the names of its 102 * contributors may be used to endorse or promote products derived 103 * from this software without specific prior written permission. 104 * 105 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 106 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 107 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 108 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 109 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 110 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 111 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 112 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 113 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 114 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 115 * POSSIBILITY OF SUCH DAMAGE. 116 */ 117 118 /* 119 * Copyright (c) 1992, 1993 120 * The Regents of the University of California. All rights reserved. 121 * 122 * This software was developed by the Computer Systems Engineering group 123 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 124 * contributed to Berkeley. 125 * 126 * All advertising materials mentioning features or use of this software 127 * must display the following acknowledgement: 128 * This product includes software developed by the University of 129 * California, Lawrence Berkeley Laboratory. 130 * 131 * Redistribution and use in source and binary forms, with or without 132 * modification, are permitted provided that the following conditions 133 * are met: 134 * 1. Redistributions of source code must retain the above copyright 135 * notice, this list of conditions and the following disclaimer. 136 * 2. Redistributions in binary form must reproduce the above copyright 137 * notice, this list of conditions and the following disclaimer in the 138 * documentation and/or other materials provided with the distribution. 139 * 3. All advertising materials mentioning features or use of this software 140 * must display the following acknowledgement: 141 * This product includes software developed by the University of 142 * California, Berkeley and its contributors. 143 * 4. Neither the name of the University nor the names of its contributors 144 * may be used to endorse or promote products derived from this software 145 * without specific prior written permission. 146 * 147 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 148 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 149 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 150 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 151 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 152 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 153 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 154 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 155 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 156 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 157 * SUCH DAMAGE. 158 * 159 * @(#)machdep.c 8.6 (Berkeley) 1/14/94 160 */ 161 162 #include <sys/cdefs.h> 163 __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.35 2004/03/24 15:34:51 atatat Exp $"); 164 165 #include "opt_ddb.h" 166 #include "opt_kgdb.h" 167 #include "opt_fpu_emulate.h" 168 169 #include <sys/param.h> 170 #include <sys/systm.h> 171 #include <sys/kernel.h> 172 #include <sys/proc.h> 173 #include <sys/buf.h> 174 #include <sys/reboot.h> 175 #include <sys/conf.h> 176 #include <sys/file.h> 177 #include <sys/device.h> 178 #include <sys/malloc.h> 179 #include <sys/extent.h> 180 #include <sys/mbuf.h> 181 #include <sys/msgbuf.h> 182 #include <sys/ioctl.h> 183 #include <sys/tty.h> 184 #include <sys/mount.h> 185 #include <sys/user.h> 186 #include <sys/exec.h> 187 #include <sys/core.h> 188 #include <sys/kcore.h> 189 #include <sys/vnode.h> 190 #include <sys/sa.h> 191 #include <sys/syscallargs.h> 192 #include <sys/ksyms.h> 193 #ifdef KGDB 194 #include <sys/kgdb.h> 195 #endif 196 197 #include <uvm/uvm.h> /* XXX: not _extern ... need vm_map_create */ 198 199 #include <sys/sysctl.h> 200 201 #include <dev/cons.h> 202 203 #include <machine/promlib.h> 204 #include <machine/cpu.h> 205 #include <machine/dvma.h> 206 #include <machine/idprom.h> 207 #include <machine/kcore.h> 208 #include <machine/reg.h> 209 #include <machine/psl.h> 210 #include <machine/pte.h> 211 #define _SUN68K_BUS_DMA_PRIVATE 212 #include <machine/autoconf.h> 213 #include <machine/bus.h> 214 #include <machine/intr.h> 215 #include <machine/pmap.h> 216 217 #if defined(DDB) 218 #include <machine/db_machdep.h> 219 #include <ddb/db_sym.h> 220 #include <ddb/db_extern.h> 221 #endif 222 223 #include <dev/vme/vmereg.h> 224 #include <dev/vme/vmevar.h> 225 226 #include <sun2/sun2/control.h> 227 #include <sun2/sun2/enable.h> 228 #include <sun2/sun2/machdep.h> 229 230 #include <sun68k/sun68k/vme_sun68k.h> 231 232 #include "ksyms.h" 233 234 /* Defined in locore.s */ 235 extern char kernel_text[]; 236 /* Defined by the linker */ 237 extern char etext[]; 238 239 /* Our exported CPU info; we can have only one. */ 240 struct cpu_info cpu_info_store; 241 242 struct vm_map *exec_map = NULL; 243 struct vm_map *mb_map = NULL; 244 struct vm_map *phys_map = NULL; 245 246 int physmem; 247 int fputype; 248 caddr_t msgbufaddr; 249 250 /* Virtual page frame for /dev/mem (see mem.c) */ 251 vaddr_t vmmap; 252 253 /* 254 * safepri is a safe priority for sleep to set for a spin-wait 255 * during autoconfiguration or after a panic. 256 */ 257 int safepri = PSL_LOWIPL; 258 259 /* Soft copy of the enable register. */ 260 __volatile u_short enable_reg_soft = ENABLE_REG_SOFT_UNDEF; 261 262 /* 263 * Our no-fault fault handler. 264 */ 265 label_t *nofault; 266 267 /* 268 * dvmamap is used to manage DVMA memory. 269 */ 270 static struct extent *dvmamap; 271 272 /* Our private scratch page for dumping the MMU. */ 273 static vaddr_t dumppage; 274 275 static void identifycpu __P((void)); 276 static void initcpu __P((void)); 277 278 /* 279 * cpu_startup: allocate memory for variable-sized tables, 280 * initialize CPU, and do autoconfiguration. 281 * 282 * This is called early in init_main.c:main(), after the 283 * kernel memory allocator is ready for use, but before 284 * the creation of processes 1,2, and mountroot, etc. 285 */ 286 void 287 cpu_startup() 288 { 289 caddr_t v; 290 vaddr_t minaddr, maxaddr; 291 char pbuf[9]; 292 293 /* 294 * Initialize message buffer (for kernel printf). 295 * This is put in physical pages four through seven 296 * so it will always be in the same place after a 297 * reboot. (physical pages 0-3 are reserved by the PROM 298 * for its vector table and other stuff.) 299 * Its mapping was prepared in pmap_bootstrap(). 300 * Also, offset some to avoid PROM scribbles. 301 */ 302 v = (caddr_t) (PAGE_SIZE * 4); 303 msgbufaddr = (caddr_t)(v + MSGBUFOFF); 304 initmsgbuf(msgbufaddr, MSGBUFSIZE); 305 306 #if NKSYMS || defined(DDB) || defined(LKM) 307 { 308 extern int end[]; 309 extern char *esym; 310 311 ksyms_init(end[0], end + 1, (int*)esym); 312 } 313 #endif /* DDB */ 314 315 /* 316 * Good {morning,afternoon,evening,night}. 317 */ 318 printf(version); 319 identifycpu(); 320 fputype = FPU_NONE; 321 #ifdef FPU_EMULATE 322 printf("fpu: emulator\n"); 323 #else 324 printf("fpu: no math support\n"); 325 #endif 326 327 format_bytes(pbuf, sizeof(pbuf), ctob(physmem)); 328 printf("total memory = %s\n", pbuf); 329 330 /* 331 * XXX fredette - we force a small number of buffers 332 * to help me debug this on my low-memory machine. 333 * this should go away at some point, allowing the 334 * normal automatic buffer-sizing to happen. 335 */ 336 bufpages = 37; 337 338 /* 339 * Get scratch page for dumpsys(). 340 */ 341 if ((dumppage = uvm_km_alloc(kernel_map, PAGE_SIZE)) == 0) 342 panic("startup: alloc dumppage"); 343 344 345 minaddr = 0; 346 /* 347 * Allocate a submap for exec arguments. This map effectively 348 * limits the number of processes exec'ing at any time. 349 */ 350 exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr, 351 NCARGS, VM_MAP_PAGEABLE, FALSE, NULL); 352 353 /* 354 * Allocate a submap for physio 355 */ 356 phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr, 357 VM_PHYS_SIZE, 0, FALSE, NULL); 358 359 /* 360 * Finally, allocate mbuf cluster submap. 361 */ 362 mb_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr, 363 nmbclusters * mclbytes, VM_MAP_INTRSAFE, 364 FALSE, NULL); 365 366 format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free)); 367 printf("avail memory = %s\n", pbuf); 368 369 /* 370 * Allocate a virtual page (for use by /dev/mem) 371 * This page is handed to pmap_enter() therefore 372 * it has to be in the normal kernel VA range. 373 */ 374 vmmap = uvm_km_valloc_wait(kernel_map, PAGE_SIZE); 375 376 /* 377 * Allocate DMA map for devices on the bus. 378 */ 379 dvmamap = extent_create("dvmamap", 380 DVMA_MAP_BASE, DVMA_MAP_BASE + DVMA_MAP_AVAIL, 381 M_DEVBUF, 0, 0, EX_NOWAIT); 382 if (dvmamap == NULL) 383 panic("unable to allocate DVMA map"); 384 385 /* 386 * Set up CPU-specific registers, cache, etc. 387 */ 388 initcpu(); 389 } 390 391 /* 392 * Set registers on exec. 393 */ 394 void 395 setregs(l, pack, stack) 396 struct lwp *l; 397 struct exec_package *pack; 398 u_long stack; 399 { 400 struct trapframe *tf = (struct trapframe *)l->l_md.md_regs; 401 402 tf->tf_sr = PSL_USERSET; 403 tf->tf_pc = pack->ep_entry & ~1; 404 tf->tf_regs[D0] = 0; 405 tf->tf_regs[D1] = 0; 406 tf->tf_regs[D2] = 0; 407 tf->tf_regs[D3] = 0; 408 tf->tf_regs[D4] = 0; 409 tf->tf_regs[D5] = 0; 410 tf->tf_regs[D6] = 0; 411 tf->tf_regs[D7] = 0; 412 tf->tf_regs[A0] = 0; 413 tf->tf_regs[A1] = 0; 414 tf->tf_regs[A2] = (int)l->l_proc->p_psstr; 415 tf->tf_regs[A3] = 0; 416 tf->tf_regs[A4] = 0; 417 tf->tf_regs[A5] = 0; 418 tf->tf_regs[A6] = 0; 419 tf->tf_regs[SP] = stack; 420 421 /* restore a null state frame */ 422 l->l_addr->u_pcb.pcb_fpregs.fpf_null = 0; 423 424 l->l_md.md_flags = 0; 425 } 426 427 /* 428 * Info for CTL_HW 429 */ 430 char machine[16] = MACHINE; /* from <machine/param.h> */ 431 char kernel_arch[16] = "sun2"; /* XXX needs a sysctl node */ 432 char cpu_model[120]; 433 434 /* 435 * Determine which Sun2 model we are running on. 436 */ 437 void 438 identifycpu() 439 { 440 extern char *cpu_string; /* XXX */ 441 442 /* Other stuff? (VAC, mc6888x version, etc.) */ 443 /* Note: miniroot cares about the kernel_arch part. */ 444 sprintf(cpu_model, "%s %s", kernel_arch, cpu_string); 445 446 printf("Model: %s\n", cpu_model); 447 } 448 449 /* 450 * machine dependent system variables. 451 */ 452 #if 0 /* XXX - Not yet... */ 453 static int 454 sysctl_machdep_root_device(SYSCTLFN_ARGS) 455 { 456 struct sysctlnode node = *rnode; 457 458 node.sysctl_data = some permutation on root_device; 459 node.sysctl_size = strlen(root_device) + 1; 460 return (sysctl_lookup(SYSCTLFN_CALL(&node))); 461 } 462 #endif 463 464 static int 465 sysctl_machdep_booted_kernel(SYSCTLFN_ARGS) 466 { 467 struct sysctlnode node = *rnode; 468 char *cp; 469 470 cp = prom_getbootfile(); 471 if (cp == NULL || cp[0] == '\0') 472 return (ENOENT); 473 474 node.sysctl_data = cp; 475 node.sysctl_size = strlen(cp) + 1; 476 return (sysctl_lookup(SYSCTLFN_CALL(&node))); 477 } 478 479 SYSCTL_SETUP(sysctl_machdep_setup, "sysctl machdep subtree setup") 480 { 481 482 sysctl_createv(clog, 0, NULL, NULL, 483 CTLFLAG_PERMANENT, 484 CTLTYPE_NODE, "machdep", NULL, 485 NULL, 0, NULL, 0, 486 CTL_MACHDEP, CTL_EOL); 487 488 sysctl_createv(clog, 0, NULL, NULL, 489 CTLFLAG_PERMANENT, 490 CTLTYPE_STRUCT, "console_device", NULL, 491 sysctl_consdev, 0, NULL, sizeof(dev_t), 492 CTL_MACHDEP, CPU_CONSDEV, CTL_EOL); 493 #if 0 /* XXX - Not yet... */ 494 sysctl_createv(clog, 0, NULL, NULL, 495 CTLFLAG_PERMANENT, 496 CTLTYPE_STRING, "root_device", NULL, 497 sysctl_machdep_root_device, 0, NULL, 0, 498 CTL_MACHDEP, CPU_ROOT_DEVICE, CTL_EOL); 499 #endif 500 sysctl_createv(clog, 0, NULL, NULL, 501 CTLFLAG_PERMANENT, 502 CTLTYPE_STRING, "booted_kernel", NULL, 503 sysctl_machdep_booted_kernel, 0, NULL, 0, 504 CTL_MACHDEP, CPU_BOOTED_KERNEL, CTL_EOL); 505 } 506 507 /* See: sig_machdep.c */ 508 509 /* 510 * Do a sync in preparation for a reboot. 511 * XXX - This could probably be common code. 512 * XXX - And now, most of it is in vfs_shutdown() 513 * XXX - Put waittime checks in there too? 514 */ 515 int waittime = -1; /* XXX - Who else looks at this? -gwr */ 516 static void 517 reboot_sync __P((void)) 518 { 519 520 /* Check waittime here to localize its use to this function. */ 521 if (waittime >= 0) 522 return; 523 waittime = 0; 524 vfs_shutdown(); 525 } 526 527 /* 528 * Common part of the BSD and SunOS reboot system calls. 529 */ 530 __dead void 531 cpu_reboot(howto, user_boot_string) 532 int howto; 533 char *user_boot_string; 534 { 535 char *bs, *p; 536 char default_boot_string[8]; 537 538 /* If system is cold, just halt. (early panic?) */ 539 if (cold) 540 goto haltsys; 541 542 /* Un-blank the screen if appropriate. */ 543 cnpollc(1); 544 545 if ((howto & RB_NOSYNC) == 0) { 546 reboot_sync(); 547 /* 548 * If we've been adjusting the clock, the todr 549 * will be out of synch; adjust it now. 550 * 551 * XXX - However, if the kernel has been sitting in ddb, 552 * the time will be way off, so don't set the HW clock! 553 * XXX - Should do sanity check against HW clock. -gwr 554 */ 555 /* resettodr(); */ 556 } 557 558 /* Disable interrupts. */ 559 splhigh(); 560 561 /* Write out a crash dump if asked. */ 562 if (howto & RB_DUMP) 563 dumpsys(); 564 565 /* run any shutdown hooks */ 566 doshutdownhooks(); 567 568 if (howto & RB_HALT) { 569 haltsys: 570 printf("halted.\n"); 571 prom_halt(); 572 } 573 574 /* 575 * Automatic reboot. 576 */ 577 bs = user_boot_string; 578 if (bs == NULL) { 579 /* 580 * Build our own boot string with an empty 581 * boot device/file and (maybe) some flags. 582 * The PROM will supply the device/file name. 583 */ 584 bs = default_boot_string; 585 *bs = '\0'; 586 if (howto & (RB_KDB|RB_ASKNAME|RB_SINGLE)) { 587 /* Append the boot flags. */ 588 p = bs; 589 *p++ = ' '; 590 *p++ = '-'; 591 if (howto & RB_KDB) 592 *p++ = 'd'; 593 if (howto & RB_ASKNAME) 594 *p++ = 'a'; 595 if (howto & RB_SINGLE) 596 *p++ = 's'; 597 *p = '\0'; 598 } 599 } 600 printf("rebooting...\n"); 601 prom_boot(bs); 602 for (;;) ; 603 /*NOTREACHED*/ 604 } 605 606 /* 607 * These variables are needed by /sbin/savecore 608 */ 609 u_int32_t dumpmag = 0x8fca0101; /* magic number */ 610 int dumpsize = 0; /* pages */ 611 long dumplo = 0; /* blocks */ 612 613 #define DUMP_EXTRA 3 /* CPU-dependent extra pages */ 614 615 /* 616 * This is called by main to set dumplo, dumpsize. 617 * Dumps always skip the first PAGE_SIZE of disk space 618 * in case there might be a disk label stored there. 619 * If there is extra space, put dump at the end to 620 * reduce the chance that swapping trashes it. 621 */ 622 void 623 cpu_dumpconf() 624 { 625 const struct bdevsw *bdev; 626 int devblks; /* size of dump device in blocks */ 627 int dumpblks; /* size of dump image in blocks */ 628 int (*getsize)__P((dev_t)); 629 630 if (dumpdev == NODEV) 631 return; 632 633 bdev = bdevsw_lookup(dumpdev); 634 if (bdev == NULL) 635 panic("dumpconf: bad dumpdev=0x%x", dumpdev); 636 getsize = bdev->d_psize; 637 if (getsize == NULL) 638 return; 639 devblks = (*getsize)(dumpdev); 640 if (devblks <= ctod(1)) 641 return; 642 devblks &= ~(ctod(1)-1); 643 644 /* 645 * Note: savecore expects dumpsize to be the 646 * number of pages AFTER the dump header. 647 */ 648 dumpsize = physmem; 649 650 /* Position dump image near end of space, page aligned. */ 651 dumpblks = ctod(physmem + DUMP_EXTRA); 652 dumplo = devblks - dumpblks; 653 654 /* If it does not fit, truncate it by moving dumplo. */ 655 /* Note: Must force signed comparison. */ 656 if (dumplo < ((long)ctod(1))) { 657 dumplo = ctod(1); 658 dumpsize = dtoc(devblks - dumplo) - DUMP_EXTRA; 659 } 660 } 661 662 /* Note: gdb looks for "dumppcb" in a kernel crash dump. */ 663 struct pcb dumppcb; 664 extern paddr_t avail_start; 665 666 /* 667 * Write a crash dump. The format while in swap is: 668 * kcore_seg_t cpu_hdr; 669 * cpu_kcore_hdr_t cpu_data; 670 * padding (PAGE_SIZE-sizeof(kcore_seg_t)) 671 * pagemap (2*PAGE_SIZE) 672 * physical memory... 673 */ 674 void 675 dumpsys() 676 { 677 const struct bdevsw *dsw; 678 kcore_seg_t *kseg_p; 679 cpu_kcore_hdr_t *chdr_p; 680 struct sun2_kcore_hdr *sh; 681 char *vaddr; 682 paddr_t paddr; 683 int psize, todo, chunk; 684 daddr_t blkno; 685 int error = 0; 686 687 if (dumpdev == NODEV) 688 return; 689 dsw = bdevsw_lookup(dumpdev); 690 if (dsw == NULL || dsw->d_psize == NULL) 691 return; 692 if (dumppage == 0) 693 return; 694 695 /* 696 * For dumps during autoconfiguration, 697 * if dump device has already configured... 698 */ 699 if (dumpsize == 0) 700 cpu_dumpconf(); 701 if (dumplo <= 0) { 702 printf("\ndump to dev %u,%u not possible\n", major(dumpdev), 703 minor(dumpdev)); 704 return; 705 } 706 savectx(&dumppcb); 707 708 psize = (*(dsw->d_psize))(dumpdev); 709 if (psize == -1) { 710 printf("dump area unavailable\n"); 711 return; 712 } 713 714 printf("\ndumping to dev %u,%u offset %ld\n", major(dumpdev), 715 minor(dumpdev), dumplo); 716 717 /* 718 * Prepare the dump header, including MMU state. 719 */ 720 blkno = dumplo; 721 todo = dumpsize; /* pages */ 722 vaddr = (char*)dumppage; 723 memset(vaddr, 0, PAGE_SIZE); 724 725 /* Set pointers to all three parts. */ 726 kseg_p = (kcore_seg_t *)vaddr; 727 chdr_p = (cpu_kcore_hdr_t *) (kseg_p + 1); 728 sh = &chdr_p->un._sun2; 729 730 /* Fill in kcore_seg_t part. */ 731 CORE_SETMAGIC(*kseg_p, KCORE_MAGIC, MID_MACHINE, CORE_CPU); 732 kseg_p->c_size = (ctob(DUMP_EXTRA) - sizeof(*kseg_p)); 733 734 /* Fill in cpu_kcore_hdr_t part. */ 735 strncpy(chdr_p->name, kernel_arch, sizeof(chdr_p->name)); 736 chdr_p->page_size = PAGE_SIZE; 737 chdr_p->kernbase = KERNBASE; 738 739 /* Fill in the sun2_kcore_hdr part (MMU state). */ 740 pmap_kcore_hdr(sh); 741 742 /* Write out the dump header. */ 743 error = (*dsw->d_dump)(dumpdev, blkno, vaddr, PAGE_SIZE); 744 if (error) 745 goto fail; 746 blkno += btodb(PAGE_SIZE); 747 748 /* translation RAM (pages zero through seven) */ 749 for(chunk = 0; chunk < (PAGE_SIZE * 8); chunk += PAGE_SIZE) { 750 pmap_get_pagemap((int*)vaddr, chunk); 751 error = (*dsw->d_dump)(dumpdev, blkno, vaddr, PAGE_SIZE); 752 if (error) 753 goto fail; 754 blkno += btodb(PAGE_SIZE); 755 } 756 757 /* 758 * Now dump physical memory. Have to do it in two chunks. 759 * The first chunk is "unmanaged" (by the VM code) and its 760 * range of physical addresses is not allow in pmap_enter. 761 * However, that segment is mapped linearly, so we can just 762 * use the virtual mappings already in place. The second 763 * chunk is done the normal way, using pmap_enter. 764 * 765 * Note that vaddr==(paddr+KERNBASE) for paddr=0 through etext. 766 */ 767 768 /* Do the first chunk (0 <= PA < avail_start) */ 769 paddr = 0; 770 chunk = btoc(avail_start); 771 if (chunk > todo) 772 chunk = todo; 773 do { 774 if ((todo & 0xf) == 0) 775 printf("\r%4d", todo); 776 vaddr = (char*)(paddr + KERNBASE); 777 error = (*dsw->d_dump)(dumpdev, blkno, vaddr, PAGE_SIZE); 778 if (error) 779 goto fail; 780 paddr += PAGE_SIZE; 781 blkno += btodb(PAGE_SIZE); 782 --todo; 783 } while (--chunk > 0); 784 785 /* Do the second chunk (avail_start <= PA < dumpsize) */ 786 vaddr = (char*)vmmap; /* Borrow /dev/mem VA */ 787 do { 788 if ((todo & 0xf) == 0) 789 printf("\r%4d", todo); 790 pmap_kenter_pa(vmmap, paddr | PMAP_NC, VM_PROT_READ); 791 pmap_update(pmap_kernel()); 792 error = (*dsw->d_dump)(dumpdev, blkno, vaddr, PAGE_SIZE); 793 pmap_kremove(vmmap, PAGE_SIZE); 794 pmap_update(pmap_kernel()); 795 if (error) 796 goto fail; 797 paddr += PAGE_SIZE; 798 blkno += btodb(PAGE_SIZE); 799 } while (--todo > 0); 800 801 printf("\rdump succeeded\n"); 802 return; 803 fail: 804 printf(" dump error=%d\n", error); 805 } 806 807 static void 808 initcpu() 809 { 810 /* XXX: Enable RAM parity/ECC checking? */ 811 /* XXX: parityenable(); */ 812 813 } 814 815 /* straptrap() in trap.c */ 816 817 /* from hp300: badaddr() */ 818 819 /* XXX: parityenable() ? */ 820 /* regdump() moved to regdump.c */ 821 822 /* 823 * cpu_exec_aout_makecmds(): 824 * CPU-dependent a.out format hook for execve(). 825 * 826 * Determine if the given exec package refers to something which we 827 * understand and, if so, set up the vmcmds for it. 828 */ 829 int 830 cpu_exec_aout_makecmds(p, epp) 831 struct proc *p; 832 struct exec_package *epp; 833 { 834 return ENOEXEC; 835 } 836 837 /* 838 * Soft interrupt support. 839 */ 840 void isr_soft_request(level) 841 int level; 842 { 843 u_char bit; 844 845 if ((level < _IPL_SOFT_LEVEL_MIN) || (level > _IPL_SOFT_LEVEL_MAX)) 846 return; 847 848 bit = 1 << level; 849 enable_reg_or(bit); 850 } 851 852 void isr_soft_clear(level) 853 int level; 854 { 855 u_char bit; 856 857 if ((level < _IPL_SOFT_LEVEL_MIN) || (level > _IPL_SOFT_LEVEL_MAX)) 858 return; 859 860 bit = 1 << level; 861 enable_reg_and(~bit); 862 } 863 864 /* 865 * Like _bus_dmamap_load(), but for raw memory allocated with 866 * bus_dmamem_alloc(). 867 */ 868 int 869 _bus_dmamap_load_raw(t, map, segs, nsegs, size, flags) 870 bus_dma_tag_t t; 871 bus_dmamap_t map; 872 bus_dma_segment_t *segs; 873 int nsegs; 874 bus_size_t size; 875 int flags; 876 { 877 struct vm_page *m; 878 paddr_t pa; 879 bus_addr_t dva; 880 bus_size_t sgsize; 881 struct pglist *mlist; 882 int pagesz = PAGE_SIZE; 883 int error; 884 885 /* 886 * Make sure that on error condition we return "no valid mappings". 887 */ 888 map->dm_nsegs = 0; 889 map->dm_mapsize = 0; 890 891 /* Allocate DVMA addresses */ 892 sgsize = (size + pagesz - 1) & -pagesz; 893 894 /* 895 * If the device can see our entire 24-bit address space, 896 * we can use any properly aligned virtual addresses. 897 */ 898 if ((map->_dm_flags & BUS_DMA_24BIT) != 0) { 899 dva = _bus_dma_valloc_skewed(sgsize, map->_dm_boundary, 900 pagesz, 0); 901 if (dva == 0) 902 return (ENOMEM); 903 } 904 905 /* 906 * Otherwise, we need virtual addresses in DVMA space. 907 */ 908 else { 909 error = extent_alloc(dvmamap, sgsize, pagesz, 910 map->_dm_boundary, 911 (flags & BUS_DMA_NOWAIT) == 0 912 ? EX_WAITOK : EX_NOWAIT, 913 (u_long *)&dva); 914 if (error) 915 return (error); 916 } 917 918 /* Fill in the segment. */ 919 map->dm_segs[0].ds_addr = dva; 920 map->dm_segs[0].ds_len = size; 921 map->dm_segs[0]._ds_va = dva; 922 map->dm_segs[0]._ds_sgsize = sgsize; 923 924 /* Map physical pages into MMU */ 925 mlist = segs[0]._ds_mlist; 926 for (m = TAILQ_FIRST(mlist); m != NULL; m = TAILQ_NEXT(m,pageq)) { 927 if (sgsize == 0) 928 panic("_bus_dmamap_load_raw: size botch"); 929 pa = VM_PAGE_TO_PHYS(m); 930 pmap_enter(pmap_kernel(), dva, 931 (pa & -pagesz) | PMAP_NC, 932 VM_PROT_READ|VM_PROT_WRITE, PMAP_WIRED); 933 934 dva += pagesz; 935 sgsize -= pagesz; 936 } 937 pmap_update(pmap_kernel()); 938 939 /* Make the map truly valid. */ 940 map->dm_nsegs = 1; 941 map->dm_mapsize = size; 942 943 return (0); 944 } 945 946 /* 947 * load DMA map with a linear buffer. 948 */ 949 int 950 _bus_dmamap_load(t, map, buf, buflen, p, flags) 951 bus_dma_tag_t t; 952 bus_dmamap_t map; 953 void *buf; 954 bus_size_t buflen; 955 struct proc *p; 956 int flags; 957 { 958 bus_size_t sgsize; 959 vaddr_t va = (vaddr_t)buf; 960 int pagesz = PAGE_SIZE; 961 bus_addr_t dva; 962 pmap_t pmap; 963 int rv; 964 965 /* 966 * Make sure that on error condition we return "no valid mappings". 967 */ 968 map->dm_nsegs = 0; 969 map->dm_mapsize = 0; 970 971 if (buflen > map->_dm_size) 972 return (EINVAL); 973 974 /* 975 * A 24-bit device can see all of our kernel address space, so 976 * if we have KVAs, we can just load them as-is, no mapping 977 * necessary. 978 */ 979 if ((map->_dm_flags & BUS_DMA_24BIT) != 0 && p == NULL) { 980 /* 981 * XXX Need to implement "don't DMA across this boundry". 982 */ 983 if (map->_dm_boundary != 0) 984 panic("bus_dmamap_load: boundaries not implemented"); 985 map->dm_mapsize = buflen; 986 map->dm_nsegs = 1; 987 map->dm_segs[0].ds_addr = (bus_addr_t)va; 988 map->dm_segs[0].ds_len = buflen; 989 map->_dm_flags |= _BUS_DMA_DIRECTMAP; 990 return (0); 991 } 992 993 /* 994 * Allocate a region in DVMA space. 995 */ 996 sgsize = m68k_round_page(buflen + (va & (pagesz - 1))); 997 998 if (extent_alloc(dvmamap, sgsize, pagesz, map->_dm_boundary, 999 (flags & BUS_DMA_NOWAIT) == 0 ? EX_WAITOK : EX_NOWAIT, 1000 (u_long *)&dva) != 0) { 1001 return (ENOMEM); 1002 } 1003 1004 /* Fill in the segment. */ 1005 map->dm_segs[0].ds_addr = dva + (va & (pagesz - 1)); 1006 map->dm_segs[0].ds_len = buflen; 1007 map->dm_segs[0]._ds_va = dva; 1008 map->dm_segs[0]._ds_sgsize = sgsize; 1009 1010 /* 1011 * Now map the DVMA addresses we allocated to point to the 1012 * pages of the caller's buffer. 1013 */ 1014 if (p != NULL) 1015 pmap = p->p_vmspace->vm_map.pmap; 1016 else 1017 pmap = pmap_kernel(); 1018 1019 for (; buflen > 0; ) { 1020 paddr_t pa; 1021 /* 1022 * Get the physical address for this page. 1023 */ 1024 rv = pmap_extract(pmap, va, &pa); 1025 #ifdef DIAGNOSTIC 1026 if (!rv) 1027 panic("_bus_dmamap_load: no page"); 1028 #endif /* DIAGNOSTIC */ 1029 1030 /* 1031 * Compute the segment size, and adjust counts. 1032 */ 1033 sgsize = pagesz - (va & (pagesz - 1)); 1034 if (buflen < sgsize) 1035 sgsize = buflen; 1036 1037 pmap_enter(pmap_kernel(), dva, 1038 (pa & -pagesz) | PMAP_NC, 1039 VM_PROT_READ|VM_PROT_WRITE, PMAP_WIRED); 1040 1041 dva += pagesz; 1042 va += sgsize; 1043 buflen -= sgsize; 1044 } 1045 pmap_update(pmap_kernel()); 1046 1047 /* Make the map truly valid. */ 1048 map->dm_nsegs = 1; 1049 map->dm_mapsize = map->dm_segs[0].ds_len; 1050 1051 return (0); 1052 } 1053 1054 /* 1055 * unload a DMA map. 1056 */ 1057 void 1058 _bus_dmamap_unload(t, map) 1059 bus_dma_tag_t t; 1060 bus_dmamap_t map; 1061 { 1062 bus_dma_segment_t *segs = map->dm_segs; 1063 int nsegs = map->dm_nsegs; 1064 int flags = map->_dm_flags; 1065 bus_addr_t dva; 1066 bus_size_t len; 1067 int s, error; 1068 1069 if (nsegs != 1) 1070 panic("_bus_dmamem_unload: nsegs = %d", nsegs); 1071 1072 /* 1073 * _BUS_DMA_DIRECTMAP is set iff this map was loaded using 1074 * _bus_dmamap_load for a 24-bit device. 1075 */ 1076 if ((flags & _BUS_DMA_DIRECTMAP) != 0) { 1077 /* Nothing to release */ 1078 map->_dm_flags &= ~_BUS_DMA_DIRECTMAP; 1079 } 1080 1081 /* 1082 * Otherwise, this map was loaded using _bus_dmamap_load for a 1083 * non-24-bit device, or using _bus_dmamap_load_raw. 1084 */ 1085 else { 1086 dva = segs[0]._ds_va & -PAGE_SIZE; 1087 len = segs[0]._ds_sgsize; 1088 1089 /* 1090 * Unmap the DVMA addresses. 1091 */ 1092 pmap_remove(pmap_kernel(), dva, dva + len); 1093 pmap_update(pmap_kernel()); 1094 1095 /* 1096 * Free the DVMA addresses. 1097 */ 1098 if ((flags & BUS_DMA_24BIT) != 0) { 1099 /* 1100 * This map was loaded using _bus_dmamap_load_raw 1101 * for a 24-bit device. 1102 */ 1103 uvm_unmap(kernel_map, dva, dva + len); 1104 } else { 1105 /* 1106 * This map was loaded using _bus_dmamap_load or 1107 * _bus_dmamap_load_raw for a non-24-bit device. 1108 */ 1109 s = splhigh(); 1110 error = extent_free(dvmamap, dva, len, EX_NOWAIT); 1111 splx(s); 1112 if (error != 0) 1113 printf("warning: %ld of DVMA space lost\n", len); 1114 } 1115 } 1116 1117 /* Mark the mappings as invalid. */ 1118 map->dm_mapsize = 0; 1119 map->dm_nsegs = 0; 1120 } 1121 1122 /* 1123 * Translate a VME address and address modifier 1124 * into a CPU physical address and page type. 1125 */ 1126 int 1127 vmebus_translate(mod, addr, btp, bap) 1128 vme_am_t mod; 1129 vme_addr_t addr; 1130 bus_type_t *btp; 1131 bus_addr_t *bap; 1132 { 1133 bus_addr_t base; 1134 1135 switch(mod) { 1136 #define _DS (VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA) 1137 1138 case (VME_AM_A16|_DS): 1139 base = 0x00ff0000; 1140 break; 1141 1142 case (VME_AM_A24|_DS): 1143 base = 0; 1144 break; 1145 1146 default: 1147 return (ENOENT); 1148 #undef _DS 1149 } 1150 1151 *bap = base | addr; 1152 *btp = (*bap & 0x800000 ? PMAP_VME8 : PMAP_VME0); 1153 return (0); 1154 } 1155