machdep.c revision 1.3
1/* $NetBSD: machdep.c,v 1.3 2026/01/10 23:10:01 jmcneill 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@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.3 2026/01/10 23:10:01 jmcneill 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 145extern u_int l2cr_config; 146 147struct powerpc_bus_space wii_mem_tag = { 148 .pbs_flags = _BUS_SPACE_BIG_ENDIAN | 149 _BUS_SPACE_MEM_TYPE, 150}; 151 152static char ex_storage[1][EXTENT_FIXED_STORAGE_SIZE(EXTMAP_RANGES)] 153 __attribute__((aligned(8))); 154 155static bus_addr_t 156wii_dma_phys_to_bus_mem(bus_dma_tag_t t, bus_addr_t addr) 157{ 158 return addr; 159} 160 161static bus_addr_t 162wii_dma_bus_mem_to_phys(bus_dma_tag_t t, bus_addr_t addr) 163{ 164 return addr; 165} 166 167static int 168wii_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 186struct 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 205struct 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 */ 229struct mem_region physmemr[4], availmemr[4]; 230char wii_cmdline[1024]; 231bool wiiu_plat; /* Running on a Wii U */ 232bool wiiu_native; /* Native Wii U mode (not vWii) */ 233 234void initppc(u_int, u_int, u_int, void *); /* Called from locore */ 235void wii_dolphin_elf_loader_id(void); 236 237static void wii_setup(void); 238static void wii_poweroff(void); 239static void wii_reset(void); 240static void wii_halt(void); 241static void init_decrementer(void); 242 243static void 244system_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 255static void 256wii_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 270static void 271wii_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 312static void 313wiiu_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 341static void 342wiiu_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 377void 378initppc(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 484void 485mem_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 */ 494void 495cpu_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 */ 520void 521consinit(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 */ 542void 543cpu_reboot(int howto, char *what) 544{ 545 static int syncing; 546 extern void disable_intr(void); 547 548 boothowto = howto; 549 if (!cold && !(howto & RB_NOSYNC) && !syncing) { 550 syncing = 1; 551 vfs_shutdown(); /* sync */ 552 } 553 splhigh(); 554 if (!cold && (howto & RB_DUMP)) { 555 oea_dumpsys(); 556 } 557 pmf_system_shutdown(boothowto); 558 doshutdownhooks(); 559 560 disable_intr(); 561 562#ifdef MULTIPROCESSOR 563 cpu_halt_others(); 564 delay(100000); 565#endif 566 567 /* Force halt on panic to capture the cause on screen. */ 568 if (panicstr != NULL) { 569 howto |= RB_HALT; 570 } 571 if ((howto & RB_POWERDOWN) == RB_POWERDOWN) { 572 printf("power off\n\n"); 573 wii_poweroff(); 574 delay(100000); 575 printf("power off failed!\n\n"); 576 } 577 if (howto & RB_HALT) { 578 printf("The operating system has halted.\n"); 579 wii_halt(); 580 } 581 582 printf("rebooting...\n\n"); 583 wii_reset(); 584 while (1); 585} 586 587static void 588wii_setup(void) 589{ 590 if (!wiiu_plat) { 591 /* Turn on the drive slot LED. */ 592 wii_slot_led(true); 593 594 /* Enable PPC access to SHUTDOWN GPIO. */ 595 out32(HW_GPIO_OWNER, in32(HW_GPIO_OWNER) | __BIT(GPIO_SHUTDOWN)); 596 597 /* Enable PPC access to DI_SPIN GPIO. */ 598 out32(HW_GPIO_OWNER, in32(HW_GPIO_OWNER) | __BIT(GPIO_DI_SPIN)); 599 600 /* Enable PPC access to EXI bus. */ 601 out32(HW_AIPPROT, in32(HW_AIPPROT) | ENAHBIOPI); 602 603 /* Enable DVD video support. */ 604 out32(HW_COMPAT, in32(HW_COMPAT) & ~DVDVIDEO); 605 } 606} 607 608static void 609wiiu_wood_ipc(uint32_t msg) 610{ 611 KASSERT(wiiu_native); 612 613 out32(HW_IPCPPCMSG, msg); 614 out32(HW_IPCPPCCTRL, HW_IPCPPCCTRL_X1); 615 for (;;) { 616 if ((in32(HW_IPCPPCCTRL) & HW_IPCPPCCTRL_X1) == 0) { 617 break; 618 } 619 } 620} 621 622static void 623wii_poweroff(void) 624{ 625 if (wiiu_native) { 626#if notyet 627 wiiu_wood_ipc(0xcafe0001); /* CMD_POWEROFF */ 628#endif 629 } else { 630 out32(HW_GPIOB_OUT, in32(HW_GPIOB_OUT) | __BIT(GPIO_SHUTDOWN)); 631 } 632} 633 634static void 635wii_reset(void) 636{ 637 if (wiiu_native) { 638#if notyet 639 wiiu_wood_ipc(0xcafe0002); /* CMD_REBOOT */ 640#else 641 wiiu_wood_ipc(0xcafe0001); /* CMD_POWEROFF */ 642#endif 643 } else { 644 out32(HW_RESETS, in32(HW_RESETS) & ~RSTBINB); 645 } 646} 647 648static void 649wii_halt(void) 650{ 651 printf("Please press the %s button to reboot.\n", 652 wiiu_native ? "POWER" : "RESET"); 653 if (wiiu_native) { 654 bool pressed = false; 655 while (1) { 656 if ((in32(HW_GPIOB_IN) & __BIT(WIIU_GPIO_POWER)) != 0) { 657 /* Button was pressed */ 658 pressed = true; 659 } else if (pressed) { 660 /* Button was released */ 661 break; 662 } 663 } 664 } else { 665 while (1) { 666 if ((in32(PI_INTERRUPT_CAUSE) & RESET_SWITCH_STATE) == 0) { 667 break; 668 } 669 } 670 } 671} 672 673static void 674init_decrementer(void) 675{ 676 extern uint32_t ns_per_tick; 677 extern uint32_t ticks_per_intr; 678 extern uint32_t ticks_per_sec; 679 int scratch, msr; 680 681 KASSERT(ticks_per_sec != 0); 682 683 __asm volatile ("mfmsr %0; andi. %1,%0,%2; mtmsr %1" 684 : "=r"(msr), "=r"(scratch) : "K"((u_short)~PSL_EE)); 685 ns_per_tick = 1000000000 / ticks_per_sec; 686 ticks_per_intr = ticks_per_sec / hz; 687 cpu_timebase = ticks_per_sec; 688 689 curcpu()->ci_lasttb = mftbl(); 690 691 mtspr(SPR_DEC, ticks_per_intr); 692 mtmsr(msr); 693} 694