1 /* $NetBSD: machdep.c,v 1.7 2026/11/07 22:20:12 thorpej Exp $ */ 2 3 /* 4 * Copyright (c) 2002, 2024 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Lennart Augustsson (lennart (at) augustsson.net) at Sandburst Corp. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 /* 33 * Copyright (C) 1995, 1996 Wolfgang Solfrank. 34 * Copyright (C) 1995, 1996 TooLs GmbH. 35 * All rights reserved. 36 * 37 * Redistribution and use in source and binary forms, with or without 38 * modification, are permitted provided that the following conditions 39 * are met: 40 * 1. Redistributions of source code must retain the above copyright 41 * notice, this list of conditions and the following disclaimer. 42 * 2. Redistributions in binary form must reproduce the above copyright 43 * notice, this list of conditions and the following disclaimer in the 44 * documentation and/or other materials provided with the distribution. 45 * 3. All advertising materials mentioning features or use of this software 46 * must display the following acknowledgement: 47 * This product includes software developed by TooLs GmbH. 48 * 4. The name of TooLs GmbH may not be used to endorse or promote products 49 * derived from this software without specific prior written permission. 50 * 51 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 52 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 53 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 54 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 56 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 57 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 58 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 59 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 60 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 61 */ 62 63 #define _POWERPC_BUS_DMA_PRIVATE 64 65 #include <sys/cdefs.h> 66 __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.7 2026/11/07 22:20:12 thorpej Exp $"); 67 68 #include "opt_compat_netbsd.h" 69 #include "opt_ddb.h" 70 #include "opt_ddbparam.h" 71 #include "opt_inet.h" 72 #include "opt_ns.h" 73 #include "opt_oea.h" 74 #include "opt_multiprocessor.h" 75 76 #include <sys/param.h> 77 #include <sys/buf.h> 78 #include <sys/bus.h> 79 #include <sys/conf.h> 80 #include <sys/device.h> 81 #include <sys/exec.h> 82 #include <sys/extent.h> 83 #include <sys/intr.h> 84 #include <sys/kernel.h> 85 #include <sys/kgdb.h> 86 #include <sys/ksyms.h> 87 #include <sys/mbuf.h> 88 #include <sys/mount.h> 89 #include <sys/msgbuf.h> 90 #include <sys/proc.h> 91 #include <sys/reboot.h> 92 #include <sys/syscallargs.h> 93 #include <sys/sysctl.h> 94 #include <sys/syslog.h> 95 #include <sys/systm.h> 96 #include <sys/cpu.h> 97 98 #include <uvm/uvm_extern.h> 99 100 #include <machine/powerpc.h> 101 #include <machine/wii.h> 102 #include <machine/wiiu.h> 103 #include <arch/evbppc/nintendo/dev/gecko.h> 104 #include <arch/evbppc/nintendo/pic_pi.h> 105 #include <arch/evbppc/nintendo/ipi_latte.h> 106 107 #include <powerpc/bus_funcs.h> 108 #include <powerpc/db_machdep.h> 109 #include <powerpc/pio.h> 110 #include <powerpc/pmap.h> 111 #include <powerpc/spr.h> 112 #include <powerpc/trap.h> 113 114 #include <powerpc/oea/bat.h> 115 #include <powerpc/oea/spr.h> 116 #include <powerpc/oea/hid.h> 117 #include <powerpc/pic/picvar.h> 118 119 #include <ddb/db_extern.h> 120 121 #include <dev/wscons/wsconsio.h> 122 #include <dev/wscons/wsdisplayvar.h> 123 #include <dev/rasops/rasops.h> 124 #include <dev/wsfont/wsfont.h> 125 #include <dev/wscons/wsdisplay_vconsvar.h> 126 127 #include <dev/usb/ukbdvar.h> 128 129 #include "ksyms.h" 130 #include "ukbd.h" 131 #include "genfb.h" 132 #include "gecko.h" 133 134 #ifndef WII_DEFAULT_CMDLINE 135 #define WII_DEFAULT_CMDLINE "root=ld0a" 136 #endif 137 138 #define IBM750CL_SPR_HID4 1011 139 140 #define MINI_MEM2_START 0x13f00000 /* Start of reserved MEM2 for MINI */ 141 142 #define PI_INTERRUPT_CAUSE 0x0c003000 143 #define RESET_SWITCH_STATE __BIT(16) 144 145 extern u_int l2cr_config; 146 147 struct powerpc_bus_space wii_mem_tag = { 148 .pbs_flags = _BUS_SPACE_BIG_ENDIAN | 149 _BUS_SPACE_MEM_TYPE, 150 }; 151 152 static char ex_storage[1][EXTENT_FIXED_STORAGE_SIZE(EXTMAP_RANGES)] 153 __attribute__((aligned(8))); 154 155 static bus_addr_t 156 wii_dma_phys_to_bus_mem(bus_dma_tag_t t, bus_addr_t addr) 157 { 158 return addr; 159 } 160 161 static bus_addr_t 162 wii_dma_bus_mem_to_phys(bus_dma_tag_t t, bus_addr_t addr) 163 { 164 return addr; 165 } 166 167 static int 168 wii_mem2_dmamem_alloc(bus_dma_tag_t t, bus_size_t size, bus_size_t alignment, 169 bus_size_t boundary, bus_dma_segment_t *segs, int nsegs, int *rsegs, 170 int flags) 171 { 172 struct mem_region *mem, *avail; 173 const int mem2_index = wiiu_native ? 2 : 1; 174 175 /* Restrict memory used for DMA to ranges in MEM2 */ 176 mem_regions(&mem, &avail); 177 if (mem[mem2_index].size == 0) { 178 return ENOMEM; 179 } 180 181 return _bus_dmamem_alloc_range(t, size, alignment, boundary, segs, 182 nsegs, rsegs, flags, mem[mem2_index].start, 183 mem[mem2_index].start + mem[mem2_index].size - PAGE_SIZE - 1); 184 } 185 186 struct powerpc_bus_dma_tag wii_bus_dma_tag = { 187 0, 0, /* _bounce_thresh_min/max */ 188 _bus_dmamap_create, 189 _bus_dmamap_destroy, 190 _bus_dmamap_load, 191 _bus_dmamap_load_mbuf, 192 _bus_dmamap_load_uio, 193 _bus_dmamap_load_raw, 194 _bus_dmamap_unload, 195 _bus_dmamap_sync, 196 _bus_dmamem_alloc, 197 _bus_dmamem_free, 198 _bus_dmamem_map, 199 _bus_dmamem_unmap, 200 _bus_dmamem_mmap, 201 wii_dma_phys_to_bus_mem, 202 wii_dma_bus_mem_to_phys, 203 }; 204 205 struct powerpc_bus_dma_tag wii_mem2_bus_dma_tag = { 206 WII_MEM2_BASE, /* _bounce_thresh_min */ 207 WII_MEM2_BASE + WII_MEM2_SIZE - 1, /* _bounce_thresh_max */ 208 _bus_dmamap_create, 209 _bus_dmamap_destroy, 210 _bus_dmamap_load, 211 _bus_dmamap_load_mbuf, 212 _bus_dmamap_load_uio, 213 _bus_dmamap_load_raw, 214 _bus_dmamap_unload, 215 _bus_dmamap_sync, 216 wii_mem2_dmamem_alloc, 217 _bus_dmamem_free, 218 _bus_dmamem_map, 219 _bus_dmamem_unmap, 220 _bus_dmamem_mmap, 221 wii_dma_phys_to_bus_mem, 222 wii_dma_bus_mem_to_phys, 223 }; 224 225 226 /* 227 * Global variables used here and there 228 */ 229 struct mem_region physmemr[4], availmemr[4]; 230 char wii_cmdline[1024]; 231 bool wiiu_plat; /* Running on a Wii U */ 232 bool wiiu_native; /* Native Wii U mode (not vWii) */ 233 234 void initppc(u_int, u_int, u_int, void *); /* Called from locore */ 235 void wii_dolphin_elf_loader_id(void); 236 237 static void wii_setup(void); 238 static void wii_poweroff(void); 239 static void wii_reset(void); 240 static void wii_halt(void); 241 static void init_decrementer(void); 242 243 static void 244 system_detect(void) 245 { 246 uint32_t val; 247 248 val = in32(LT_CHIPREVID); 249 if (__SHIFTOUT(val, LT_CHIPREVID_MAGIC) == LT_CHIPREVID_MAGIC_CAFE) { 250 wiiu_plat = true; 251 wiiu_native = (in32(LT_PIMCOMPAT) & PPC_COMPAT) == 0; 252 } 253 } 254 255 static void 256 wii_init_cmdline(void) 257 { 258 extern struct wii_argv wii_argv; 259 260 if (wii_argv.magic == WII_ARGV_MAGIC) { 261 void *ptr = (void *)(uintptr_t)(wii_argv.cmdline & ~0x80000000); 262 if (ptr != NULL) { 263 memcpy(wii_cmdline, ptr, wii_argv.length); 264 } 265 } else { 266 snprintf(wii_cmdline, sizeof(wii_cmdline), WII_DEFAULT_CMDLINE); 267 } 268 } 269 270 static void 271 wii_init_memmap(u_int endkernel) 272 { 273 uint32_t mem2_start, mem2_end; 274 275 mem2_start = in32(GLOBAL_MEM2_AVAIL_START) & ~0x80000000; 276 mem2_end = in32(GLOBAL_MEM2_AVAIL_END) & ~0x80000000; 277 if (mem2_start < WII_MEM2_BASE) { 278 /* Must have been booted from MINI. */ 279 mem2_start = WII_MEM2_BASE + DSP_MEM_SIZE; 280 mem2_end = MINI_MEM2_START; 281 } 282 /* 283 * Clear GLOBAL_MEM2_AVAIL_{START,END} so we can detect the correct 284 * memory size when soft resetting from IOS to MINI. 285 */ 286 out32(GLOBAL_MEM2_AVAIL_START, 0); 287 out32(GLOBAL_MEM2_AVAIL_END, 0); 288 289 /* MEM1 24MB 1T-SRAM */ 290 physmemr[0].start = WII_MEM1_BASE; 291 physmemr[0].size = WII_MEM1_SIZE; 292 293 /* MEM2 64MB GDDR3 */ 294 physmemr[1].start = WII_MEM2_BASE; 295 physmemr[1].size = WII_MEM2_SIZE; 296 297 physmemr[2].size = 0; 298 299 /* MEM1 available memory */ 300 availmemr[0].start = ((endkernel & ~0x80000000) + PGOFSET) & ~PGOFSET; 301 availmemr[0].size = physmemr[0].size - availmemr[0].start; 302 /* External framebuffer is at the end of MEM1 */ 303 availmemr[0].size -= XFB_SIZE; 304 305 /* MEM2 available memory */ 306 availmemr[1].start = mem2_start; 307 availmemr[1].size = mem2_end - mem2_start; 308 309 availmemr[2].size = 0; 310 } 311 312 static void 313 wiiu_init_cmdline(void) 314 { 315 struct wiiu_argv *argv = (struct wiiu_argv *)WIIU_LOADER_DATA_ADDR; 316 317 if (argv->magic == WIIU_LOADER_MAGIC) { 318 char *p; 319 320 /* 321 * Split the command line string into tokens to match 322 * the format used by HBC. 323 */ 324 memcpy(wii_cmdline, argv->cmdline, sizeof(argv->cmdline)); 325 wii_cmdline[sizeof(argv->cmdline) - 1] = '\0'; 326 p = wii_cmdline; 327 for (;;) { 328 p = strchr(p, ' '); 329 if (*p == '\0') { 330 break; 331 } 332 *p++ = '\0'; 333 } 334 p++; 335 *p = '\0'; 336 } else { 337 snprintf(wii_cmdline, sizeof(wii_cmdline), WII_DEFAULT_CMDLINE); 338 } 339 } 340 341 static void 342 wiiu_init_memmap(u_int endkernel) 343 { 344 /* MEM1 32MB */ 345 physmemr[0].start = 0x00000000; 346 physmemr[0].size = 0x2000000; 347 348 /* MEM0 3MB */ 349 physmemr[1].start = 0x08000000; 350 physmemr[1].size = 0x300000; 351 352 /* MEM2 2GB */ 353 physmemr[2].start = 0x10000000; 354 physmemr[2].size = 0x80000000; 355 356 physmemr[3].size = 0; 357 358 /* MEM1 available memory */ 359 availmemr[0].start = (endkernel + PGOFSET) & ~PGOFSET; 360 availmemr[0].size = physmemr[0].size - availmemr[0].start; 361 362 /* 363 * MEM2 available memory. Reserved regions: 364 * USB DMA 0x10000000 - 0x103fffff 365 * Sound DMA 0x10400000 - 0x1041ffff 366 * Framebuffer 0x17500000 - 0x17a7ffff 367 */ 368 availmemr[1].start = 0x10420000; 369 availmemr[1].size = 0x17500000 - availmemr[1].start; 370 availmemr[2].start = 0x17a80000; 371 availmemr[2].size = physmemr[2].start + physmemr[2].size - 372 availmemr[2].start; 373 374 availmemr[3].size = 0; 375 } 376 377 void 378 initppc(u_int startkernel, u_int endkernel, u_int args, void *btinfo) 379 { 380 extern uint32_t ticks_per_sec; 381 extern uint32_t ticks_per_msec; 382 extern unsigned char edata[], end[]; 383 register_t scratch, spr; 384 385 memset(&edata, 0, end - edata); /* clear BSS */ 386 wii_cmdline[0] = '\0'; 387 388 system_detect(); 389 390 if (wiiu_native) { 391 wiiu_init_cmdline(); 392 wiiu_init_memmap(endkernel); 393 } else { 394 wii_init_cmdline(); 395 wii_init_memmap(endkernel); 396 } 397 398 #ifdef BOOTHOWTO 399 /* 400 * boothowto 401 */ 402 boothowto = BOOTHOWTO; 403 #endif 404 405 cpu_model_init(); 406 407 if (!wiiu_native) { 408 spr = mfspr(IBM750CL_SPR_HID4); 409 spr |= HID4_L2_CCFI; 410 spr |= HID4_DBP; 411 mtspr(IBM750CL_SPR_HID4, spr); 412 asm volatile ("isync"); 413 } 414 415 if (wiiu_native) { 416 spr = mfspr(SPR_IBMESPRESSO_HID5); 417 mtspr(SPR_IBMESPRESSO_HID5, spr | HID5_H5A | HID5_PIRE); 418 419 spr = mfspr(SPR_SCR); 420 mtspr(SPR_SCR, (spr & ~0x40000000) | 0x80000000); 421 422 spr = mfspr(SPR_CAR); 423 mtspr(SPR_CAR, spr | 0xfc100000); 424 425 mtspr(SPR_BCR, 0x08000000); 426 427 asm volatile ("isync"); 428 } 429 430 /* Configure L2 cache */ 431 l2cr_config = L2CR_L2E; 432 433 if (bus_space_init(&wii_mem_tag, NULL, 434 ex_storage[0], sizeof(ex_storage[0]))) { 435 panic("bus_space_init failed"); 436 } 437 438 /* 439 * Initialize the BAT registers 440 */ 441 if (wiiu_native) { 442 oea_batinit( 443 WII_IOMEM_BASE, BAT_BL_32M, 444 0); 445 } else { 446 oea_batinit( 447 EFB_BASE, BAT_BL_128M, 448 0); 449 } 450 451 /* 452 * Set up trap vectors 453 */ 454 oea_init(NULL); 455 456 /* 457 * Get CPU clock 458 */ 459 ticks_per_sec = wiiu_native ? WIIU_TIMEBASE_FREQ_HZ : 460 WII_TIMEBASE_FREQ_HZ; 461 ticks_per_msec = ticks_per_sec / 1000; 462 cpu_timebase = ticks_per_sec; 463 464 wii_setup(); 465 466 uvm_md_init(); 467 468 /* 469 * Initialize pmap module. 470 */ 471 pmap_bootstrap(startkernel, endkernel); 472 473 /* Now enable translation (and machine checks/recoverable interrupts) */ 474 asm volatile ("sync; mfmsr %0; ori %0,%0,%1; mtmsr %0; isync" 475 : "=r"(scratch) 476 : "K"(PSL_IR|PSL_DR|PSL_ME|PSL_RI)); 477 478 /* 479 * Setup decrementer 480 */ 481 init_decrementer(); 482 } 483 484 void 485 mem_regions(struct mem_region **mem, struct mem_region **avail) 486 { 487 *mem = physmemr; 488 *avail = availmemr; 489 } 490 491 /* 492 * Machine dependent startup code. 493 */ 494 void 495 cpu_startup(void) 496 { 497 oea_startup(NULL); 498 499 /* 500 * Now that we have VM, malloc()s are OK in bus_space. 501 */ 502 bus_space_mallocok(); 503 504 /* Set up interrupt controller */ 505 pic_init(); 506 pi_init_intr(); 507 oea_install_extint(pic_ext_intr); 508 509 #ifdef MULTIPROCESSOR 510 if (wiiu_native) { 511 ipi_latte_init(); 512 oea_install_extint_vec(pic_ext_intr, EXC_IPI); 513 } 514 #endif 515 } 516 517 /* 518 * No early console support. 519 */ 520 void 521 consinit(void) 522 { 523 #if NGENFB > 0 524 if (wiiu_native) { 525 extern void wiiufb_consinit(void); 526 wiiufb_consinit(); 527 } 528 #endif 529 #if NGECKO > 0 530 if (!wiiu_native) { 531 usbgecko_consinit(); 532 } 533 #endif 534 #if NUKBD > 0 535 ukbd_cnattach(); 536 #endif 537 } 538 539 /* 540 * Halt or reboot the machine after syncing/dumping according to howto. 541 */ 542 void 543 cpu_reboot(int howto, char *what) 544 { 545 static int syncdone = false; 546 547 if (cold) { 548 howto |= RB_HALT; 549 goto haltsys; 550 } 551 552 boothowto = howto; 553 554 if ((howto & RB_NOSYNC) == 0 && panicstr == NULL) { 555 if (!syncdone) { 556 syncdone = true; 557 /* XXX used to force unmount as well, here */ 558 vfs_sync_all(curlwp); 559 } 560 561 while (vfs_unmountall1(curlwp, false, false) || 562 config_detach_all(boothowto) || 563 vfs_unmount_forceone(curlwp)) { 564 /* do nothing */ 565 } 566 } else { 567 if (!db_active) { 568 suspendsched(); 569 } 570 } 571 572 pmf_system_shutdown(boothowto); 573 574 /* Disable interrupts */ 575 splhigh(); 576 577 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) { 578 oea_dumpsys(); 579 } 580 581 haltsys: 582 doshutdownhooks(); 583 584 #ifdef MULTIPROCESSOR 585 cpu_halt_others(); 586 delay(100000); 587 #endif 588 589 if ((howto & RB_POWERDOWN) == RB_POWERDOWN) { 590 printf("power off\n\n"); 591 wii_poweroff(); 592 delay(100000); 593 printf("power off failed!\n\n"); 594 } 595 596 if (howto & RB_HALT) { 597 printf("The operating system has halted.\n"); 598 wii_halt(); 599 } 600 601 printf("rebooting...\n\n"); 602 wii_reset(); 603 while (1); 604 } 605 606 static void 607 wii_setup(void) 608 { 609 /* Enable PPC access to EXI bus. */ 610 out32(HW_AIPPROT, in32(HW_AIPPROT) | ENAHBIOPI); 611 612 if (!wiiu_plat) { 613 /* Turn on the drive slot LED. */ 614 wii_slot_led(true); 615 616 /* Enable PPC access to SHUTDOWN GPIO. */ 617 out32(HW_GPIO_OWNER, in32(HW_GPIO_OWNER) | __BIT(GPIO_SHUTDOWN)); 618 619 /* Enable PPC access to DI_SPIN GPIO. */ 620 out32(HW_GPIO_OWNER, in32(HW_GPIO_OWNER) | __BIT(GPIO_DI_SPIN)); 621 622 /* Enable DVD video support. */ 623 out32(HW_COMPAT, in32(HW_COMPAT) & ~DVDVIDEO); 624 } 625 } 626 627 static void 628 wiiu_wood_ipc(uint32_t msg) 629 { 630 KASSERT(wiiu_native); 631 632 out32(HW_IPCPPCMSG, msg); 633 out32(HW_IPCPPCCTRL, HW_IPCPPCCTRL_X1); 634 for (;;) { 635 if ((in32(HW_IPCPPCCTRL) & HW_IPCPPCCTRL_X1) == 0) { 636 break; 637 } 638 } 639 } 640 641 static void 642 wii_poweroff(void) 643 { 644 if (wiiu_native) { 645 wiiu_wood_ipc(CMD_POWEROFF); 646 } else { 647 out32(HW_GPIOB_OUT, in32(HW_GPIOB_OUT) | __BIT(GPIO_SHUTDOWN)); 648 } 649 } 650 651 static void 652 wii_reset(void) 653 { 654 if (wiiu_native) { 655 wiiu_wood_ipc(CMD_REBOOT); 656 } else { 657 out32(HW_RESETS, in32(HW_RESETS) & ~RSTBINB); 658 } 659 } 660 661 static void 662 wii_halt(void) 663 { 664 printf("Please press the %s button to reboot.\n", 665 wiiu_native ? "POWER" : "RESET"); 666 if (wiiu_native) { 667 bool pressed = false; 668 while (1) { 669 if ((in32(HW_GPIOB_IN) & __BIT(WIIU_GPIO_POWER)) != 0) { 670 /* Button was pressed */ 671 pressed = true; 672 } else if (pressed) { 673 /* Button was released */ 674 break; 675 } 676 } 677 } else { 678 while (1) { 679 if ((in32(PI_INTERRUPT_CAUSE) & RESET_SWITCH_STATE) == 0) { 680 break; 681 } 682 } 683 } 684 } 685 686 static void 687 init_decrementer(void) 688 { 689 extern uint32_t ns_per_tick; 690 extern uint32_t ticks_per_intr; 691 extern uint32_t ticks_per_sec; 692 int scratch, msr; 693 694 KASSERT(ticks_per_sec != 0); 695 696 __asm volatile ("mfmsr %0; andi. %1,%0,%2; mtmsr %1" 697 : "=r"(msr), "=r"(scratch) : "K"((u_short)~PSL_EE)); 698 ns_per_tick = 1000000000 / ticks_per_sec; 699 ticks_per_intr = ticks_per_sec / hz; 700 cpu_timebase = ticks_per_sec; 701 702 curcpu()->ci_lasttb = mftbl(); 703 704 mtspr(SPR_DEC, ticks_per_intr); 705 mtmsr(msr); 706 } 707