2 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
3 * Copyright (C) 1995, 1996 TooLs GmbH.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by TooLs GmbH.
17 * 4. The name of TooLs GmbH may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * Copyright (C) 2001 Benno Rice
33 * All rights reserved.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
44 * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR
45 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
46 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
47 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
49 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
50 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
51 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
52 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
53 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 * $NetBSD: machdep.c,v 1.74.2.1 2000/11/01 16:13:48 tv Exp $
57 #include <sys/cdefs.h>
58 __FBSDID("$FreeBSD$");
60 #include "opt_compat.h"
62 #include "opt_kstack_pages.h"
63 #include "opt_platform.h"
65 #include <sys/param.h>
67 #include <sys/systm.h>
73 #include <sys/eventhandler.h>
75 #include <sys/imgact.h>
77 #include <sys/kernel.h>
79 #include <sys/linker.h>
81 #include <sys/malloc.h>
83 #include <sys/msgbuf.h>
84 #include <sys/mutex.h>
85 #include <sys/ptrace.h>
86 #include <sys/reboot.h>
87 #include <sys/rwlock.h>
88 #include <sys/signalvar.h>
89 #include <sys/syscallsubr.h>
90 #include <sys/sysctl.h>
91 #include <sys/sysent.h>
92 #include <sys/sysproto.h>
93 #include <sys/ucontext.h>
95 #include <sys/vmmeter.h>
96 #include <sys/vnode.h>
98 #include <net/netisr.h>
101 #include <vm/vm_extern.h>
102 #include <vm/vm_kern.h>
103 #include <vm/vm_page.h>
104 #include <vm/vm_map.h>
105 #include <vm/vm_object.h>
106 #include <vm/vm_pager.h>
108 #include <machine/altivec.h>
109 #ifndef __powerpc64__
110 #include <machine/bat.h>
112 #include <machine/cpu.h>
113 #include <machine/elf.h>
114 #include <machine/fpu.h>
115 #include <machine/hid.h>
116 #include <machine/kdb.h>
117 #include <machine/md_var.h>
118 #include <machine/metadata.h>
119 #include <machine/mmuvar.h>
120 #include <machine/pcb.h>
121 #include <machine/reg.h>
122 #include <machine/sigframe.h>
123 #include <machine/spr.h>
124 #include <machine/trap.h>
125 #include <machine/vmparam.h>
126 #include <machine/ofw_machdep.h>
130 #include <dev/ofw/openfirm.h>
135 int cacheline_size = 128;
137 int cacheline_size = 32;
139 int hw_direct_map = 1;
141 extern void *ap_pcpu;
143 struct pcpu __pcpu[MAXCPU];
145 static struct trapframe frame0;
147 char machine[] = "powerpc";
148 SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD, machine, 0, "");
150 static void cpu_startup(void *);
151 SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL);
153 SYSCTL_INT(_machdep, CPU_CACHELINE, cacheline_size,
154 CTLFLAG_RD, &cacheline_size, 0, "");
156 uintptr_t powerpc_init(vm_offset_t, vm_offset_t, vm_offset_t, void *);
161 #ifndef __powerpc64__
162 struct bat battable[16];
165 struct kva_md_info kmi;
168 cpu_startup(void *dummy)
172 * Initialise the decrementer-based clock.
177 * Good {morning,afternoon,evening,night}.
179 cpu_setup(PCPU_GET(cpuid));
184 printf("real memory = %ld (%ld MB)\n", ptoa(physmem),
185 ptoa(physmem) / 1048576);
189 printf("available KVA = %zd (%zd MB)\n",
190 virtual_end - virtual_avail,
191 (virtual_end - virtual_avail) / 1048576);
194 * Display any holes after the first chunk of extended memory.
199 printf("Physical memory chunk(s):\n");
200 for (indx = 0; phys_avail[indx + 1] != 0; indx += 2) {
202 phys_avail[indx + 1] - phys_avail[indx];
205 printf("0x%016lx - 0x%016lx, %ld bytes (%ld pages)\n",
207 printf("0x%08x - 0x%08x, %d bytes (%ld pages)\n",
209 phys_avail[indx], phys_avail[indx + 1] - 1, size1,
214 vm_ksubmap_init(&kmi);
216 printf("avail memory = %ld (%ld MB)\n", ptoa(vm_cnt.v_free_count),
217 ptoa(vm_cnt.v_free_count) / 1048576);
220 * Set up buffers, so they can be used to read disk labels.
223 vm_pager_bufferinit();
226 extern vm_offset_t __startkernel, __endkernel;
228 #ifndef __powerpc64__
229 /* Bits for running on 64-bit systems in 32-bit mode. */
230 extern void *testppc64, *testppc64size;
231 extern void *restorebridge, *restorebridgesize;
232 extern void *rfid_patch, *rfi_patch1, *rfi_patch2;
233 extern void *trapcode64;
236 extern void *rstcode, *rstsize;
237 extern void *trapcode, *trapsize;
238 extern void *slbtrap, *slbtrapsize;
239 extern void *alitrap, *alisize;
240 extern void *dsitrap, *dsisize;
241 extern void *decrint, *decrsize;
242 extern void *extint, *extsize;
243 extern void *dblow, *dbsize;
244 extern void *imisstrap, *imisssize;
245 extern void *dlmisstrap, *dlmisssize;
246 extern void *dsmisstrap, *dsmisssize;
249 powerpc_init(vm_offset_t fdt, vm_offset_t toc, vm_offset_t ofentry, void *mdp)
252 vm_offset_t startkernel, endkernel;
257 register_t msr, scratch;
261 uint8_t *cache_check;
263 #ifndef __powerpc64__
267 vm_offset_t ksym_start;
268 vm_offset_t ksym_end;
275 /* Store boot environment state */
276 OF_initial_setup((void *)fdt, NULL, (int (*)(void *))ofentry);
278 /* First guess at start/end kernel positions */
279 startkernel = __startkernel;
280 endkernel = __endkernel;
284 * The Wii loader doesn't pass us any environment so, mdp
285 * points to garbage at this point. The Wii CPU is a 750CL.
288 if ((vers & 0xfffff0e0) == (MPC750 << 16 | MPC750CL))
293 * Parse metadata if present and fetch parameters. Must be done
294 * before console is inited so cninit gets the right value of
298 preload_metadata = mdp;
299 kmdp = preload_search_by_type("elf kernel");
301 boothowto = MD_FETCH(kmdp, MODINFOMD_HOWTO, int);
302 kern_envp = MD_FETCH(kmdp, MODINFOMD_ENVP, char *);
303 endkernel = ulmax(endkernel, MD_FETCH(kmdp,
304 MODINFOMD_KERNEND, vm_offset_t));
306 ksym_start = MD_FETCH(kmdp, MODINFOMD_SSYM, uintptr_t);
307 ksym_end = MD_FETCH(kmdp, MODINFOMD_ESYM, uintptr_t);
308 db_fetch_ksymtab(ksym_start, ksym_end);
314 * Init params/tunables that can be overridden by the loader
319 * Start initializing proc0 and thread0.
321 proc_linkup0(&proc0, &thread0);
322 thread0.td_frame = &frame0;
325 * Set up per-cpu data.
328 pcpu_init(pc, 0, sizeof(struct pcpu));
329 pc->pc_curthread = &thread0;
331 __asm __volatile("mr 13,%0" :: "r"(pc->pc_curthread));
333 __asm __volatile("mr 2,%0" :: "r"(pc->pc_curthread));
337 __asm __volatile("mtsprg 0, %0" :: "r"(pc));
340 * Init mutexes, which we use heavily in PMAP
346 * Install the OF client interface
352 * Initialize the console before printing anything.
357 * Complain if there is no metadata.
359 if (mdp == NULL || kmdp == NULL) {
360 printf("powerpc_init: no loader metadata.\n");
369 /* Various very early CPU fix ups */
370 switch (mfpvr() >> 16) {
372 * PowerPC 970 CPUs have a misfeature requested by Apple that
373 * makes them pretend they have a 32-byte cacheline. Turn this
374 * off before we measure the cacheline size.
380 scratch = mfspr(SPR_HID5);
381 scratch &= ~HID5_970_DCBZ_SIZE_HI;
382 mtspr(SPR_HID5, scratch);
386 /* XXX: get from ibm,slb-size in device tree */
393 * Initialize the interrupt tables and figure out our cache line
394 * size and whether or not we need the 64-bit bridge code.
398 * Disable translation in case the vector area hasn't been
399 * mapped (G5). Note that no OFW calls can be made until
400 * translation is re-enabled.
404 mtmsr((msr & ~(PSL_IR | PSL_DR)) | PSL_RI);
407 * Measure the cacheline size using dcbz
409 * Use EXC_PGM as a playground. We are about to overwrite it
410 * anyway, we know it exists, and we know it is cache-aligned.
413 cache_check = (void *)EXC_PGM;
415 for (cacheline_size = 0; cacheline_size < 0x100; cacheline_size++)
416 cache_check[cacheline_size] = 0xff;
418 __asm __volatile("dcbz 0,%0":: "r" (cache_check) : "memory");
420 /* Find the first byte dcbz did not zero to get the cache line size */
421 for (cacheline_size = 0; cacheline_size < 0x100 &&
422 cache_check[cacheline_size] == 0; cacheline_size++);
424 /* Work around psim bug */
425 if (cacheline_size == 0) {
430 /* Make sure the kernel icache is valid before we go too much further */
431 __syncicache((caddr_t)startkernel, endkernel - startkernel);
433 #ifndef __powerpc64__
435 * Figure out whether we need to use the 64 bit PMAP. This works by
436 * executing an instruction that is only legal on 64-bit PPC (mtmsrd),
437 * and setting ppc64 = 0 if that causes a trap.
442 bcopy(&testppc64, (void *)EXC_PGM, (size_t)&testppc64size);
443 __syncicache((void *)EXC_PGM, (size_t)&testppc64size);
451 : "=r"(scratch), "=r"(ppc64));
454 cpu_features |= PPC_FEATURE_64;
457 * Now copy restorebridge into all the handlers, if necessary,
458 * and set up the trap tables.
461 if (cpu_features & PPC_FEATURE_64) {
462 /* Patch the two instances of rfi -> rfid */
463 bcopy(&rfid_patch,&rfi_patch1,4);
465 /* rfi_patch2 is at the end of dbleave */
466 bcopy(&rfid_patch,&rfi_patch2,4);
470 * Copy a code snippet to restore 32-bit bridge mode
471 * to the top of every non-generic trap handler
474 trap_offset += (size_t)&restorebridgesize;
475 bcopy(&restorebridge, (void *)EXC_RST, trap_offset);
476 bcopy(&restorebridge, (void *)EXC_DSI, trap_offset);
477 bcopy(&restorebridge, (void *)EXC_ALI, trap_offset);
478 bcopy(&restorebridge, (void *)EXC_PGM, trap_offset);
479 bcopy(&restorebridge, (void *)EXC_MCHK, trap_offset);
480 bcopy(&restorebridge, (void *)EXC_TRC, trap_offset);
481 bcopy(&restorebridge, (void *)EXC_BPT, trap_offset);
484 * Set the common trap entry point to the one that
485 * knows to restore 32-bit operation on execution.
488 generictrap = &trapcode64;
490 generictrap = &trapcode;
493 #else /* powerpc64 */
494 cpu_features |= PPC_FEATURE_64;
495 generictrap = &trapcode;
497 /* Set TOC base so that the interrupt code can get at it */
498 *((register_t *)TRAP_TOCBASE) = toc;
501 bcopy(&rstcode, (void *)(EXC_RST + trap_offset), (size_t)&rstsize);
504 bcopy(&dblow, (void *)(EXC_MCHK + trap_offset), (size_t)&dbsize);
505 bcopy(&dblow, (void *)(EXC_PGM + trap_offset), (size_t)&dbsize);
506 bcopy(&dblow, (void *)(EXC_TRC + trap_offset), (size_t)&dbsize);
507 bcopy(&dblow, (void *)(EXC_BPT + trap_offset), (size_t)&dbsize);
509 bcopy(generictrap, (void *)EXC_MCHK, (size_t)&trapsize);
510 bcopy(generictrap, (void *)EXC_PGM, (size_t)&trapsize);
511 bcopy(generictrap, (void *)EXC_TRC, (size_t)&trapsize);
512 bcopy(generictrap, (void *)EXC_BPT, (size_t)&trapsize);
514 bcopy(&alitrap, (void *)(EXC_ALI + trap_offset), (size_t)&alisize);
515 bcopy(&dsitrap, (void *)(EXC_DSI + trap_offset), (size_t)&dsisize);
516 bcopy(generictrap, (void *)EXC_ISI, (size_t)&trapsize);
518 bcopy(&slbtrap, (void *)EXC_DSE, (size_t)&slbtrapsize);
519 bcopy(&slbtrap, (void *)EXC_ISE, (size_t)&slbtrapsize);
521 bcopy(generictrap, (void *)EXC_EXI, (size_t)&trapsize);
522 bcopy(generictrap, (void *)EXC_FPU, (size_t)&trapsize);
523 bcopy(generictrap, (void *)EXC_DECR, (size_t)&trapsize);
524 bcopy(generictrap, (void *)EXC_SC, (size_t)&trapsize);
525 bcopy(generictrap, (void *)EXC_FPA, (size_t)&trapsize);
526 bcopy(generictrap, (void *)EXC_VEC, (size_t)&trapsize);
527 bcopy(generictrap, (void *)EXC_PERF, (size_t)&trapsize);
528 bcopy(generictrap, (void *)EXC_VECAST_G4, (size_t)&trapsize);
529 bcopy(generictrap, (void *)EXC_VECAST_G5, (size_t)&trapsize);
530 #ifndef __powerpc64__
531 /* G2-specific TLB miss helper handlers */
532 bcopy(&imisstrap, (void *)EXC_IMISS, (size_t)&imisssize);
533 bcopy(&dlmisstrap, (void *)EXC_DLMISS, (size_t)&dlmisssize);
534 bcopy(&dsmisstrap, (void *)EXC_DSMISS, (size_t)&dsmisssize);
536 __syncicache(EXC_RSVD, EXC_LAST - EXC_RSVD);
543 /* Warn if cachline size was not determined */
544 if (cacheline_warn == 1) {
545 printf("WARNING: cacheline size undetermined, setting to 32\n");
549 * Choose a platform module so we can get the physical memory map.
552 platform_probe_and_attach();
555 * Initialise virtual memory. Use BUS_PROBE_GENERIC priority
556 * in case the platform module had a better idea of what we
559 if (cpu_features & PPC_FEATURE_64)
560 pmap_mmu_install(MMU_TYPE_G5, BUS_PROBE_GENERIC);
562 pmap_mmu_install(MMU_TYPE_OEA, BUS_PROBE_GENERIC);
564 pmap_bootstrap(startkernel, endkernel);
565 mtmsr(PSL_KERNSET & ~PSL_EE);
568 * Initialize params/tunables that are derived from memsize
570 init_param2(physmem);
573 * Grab booted kernel's name
575 env = kern_getenv("kernelname");
577 strlcpy(kernelname, env, sizeof(kernelname));
582 * Finish setting up thread0.
584 thread0.td_pcb = (struct pcb *)
585 ((thread0.td_kstack + thread0.td_kstack_pages * PAGE_SIZE -
586 sizeof(struct pcb)) & ~15UL);
587 bzero((void *)thread0.td_pcb, sizeof(struct pcb));
588 pc->pc_curpcb = thread0.td_pcb;
590 /* Initialise the message buffer. */
591 msgbufinit(msgbufp, msgbufsize);
594 if (boothowto & RB_KDB)
595 kdb_enter(KDB_WHY_BOOTFLAGS,
596 "Boot flags requested debugger");
599 return (((uintptr_t)thread0.td_pcb -
600 (sizeof(struct callframe) - 3*sizeof(register_t))) & ~15UL);
604 bzero(void *buf, size_t len)
610 while (((vm_offset_t) p & (sizeof(u_long) - 1)) && len) {
615 while (len >= sizeof(u_long) * 8) {
617 *((u_long*) p + 1) = 0;
618 *((u_long*) p + 2) = 0;
619 *((u_long*) p + 3) = 0;
620 len -= sizeof(u_long) * 8;
621 *((u_long*) p + 4) = 0;
622 *((u_long*) p + 5) = 0;
623 *((u_long*) p + 6) = 0;
624 *((u_long*) p + 7) = 0;
625 p += sizeof(u_long) * 8;
628 while (len >= sizeof(u_long)) {
630 len -= sizeof(u_long);
646 * Flush the D-cache for non-DMA I/O so that the I-cache can
647 * be made coherent later.
650 cpu_flush_dcache(void *ptr, size_t len)
656 * Shutdown the CPU as much as possible.
666 ptrace_set_pc(struct thread *td, unsigned long addr)
668 struct trapframe *tf;
671 tf->srr0 = (register_t)addr;
677 ptrace_single_step(struct thread *td)
679 struct trapframe *tf;
688 ptrace_clear_single_step(struct thread *td)
690 struct trapframe *tf;
699 kdb_cpu_clear_singlestep(void)
702 kdb_frame->srr1 &= ~PSL_SE;
706 kdb_cpu_set_singlestep(void)
709 kdb_frame->srr1 |= PSL_SE;
713 * Initialise a struct pcpu.
716 cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t sz)
719 /* Copy the SLB contents from the current CPU */
720 memcpy(pcpu->pc_slb, PCPU_GET(slb), sizeof(pcpu->pc_slb));
731 if (td->td_md.md_spinlock_count == 0) {
732 msr = intr_disable();
733 td->td_md.md_spinlock_count = 1;
734 td->td_md.md_saved_msr = msr;
736 td->td_md.md_spinlock_count++;
748 msr = td->td_md.md_saved_msr;
749 td->td_md.md_spinlock_count--;
750 if (td->td_md.md_spinlock_count == 0)
754 int db_trap_glue(struct trapframe *); /* Called from trap_subr.S */
757 db_trap_glue(struct trapframe *frame)
759 if (!(frame->srr1 & PSL_PR)
760 && (frame->exc == EXC_TRC || frame->exc == EXC_RUNMODETRC
761 || (frame->exc == EXC_PGM
762 && (frame->srr1 & 0x20000))
763 || frame->exc == EXC_BPT
764 || frame->exc == EXC_DSI)) {
765 int type = frame->exc;
767 /* Ignore DTrace traps. */
768 if (*(uint32_t *)frame->srr0 == EXC_DTRACE)
770 if (type == EXC_PGM && (frame->srr1 & 0x20000)) {
773 return (kdb_trap(type, 0, frame));
779 #ifndef __powerpc64__
782 va_to_vsid(pmap_t pm, vm_offset_t va)
784 return ((pm->pm_sr[(uintptr_t)va >> ADDR_SR_SHFT]) & SR_VSID_MASK);
790 pmap_early_io_map(vm_paddr_t pa, vm_size_t size)
796 /* From p3-53 of the MPC7450 RISC Microprocessor Family Reference Manual */
798 flush_disable_caches(void)
802 register_t cache_reg;
803 volatile uint32_t *memp;
810 mtmsr(msr & ~(PSL_EE | PSL_DR));
811 msscr0 = mfspr(SPR_MSSCR0);
812 msscr0 &= ~MSSCR0_L2PFE;
813 mtspr(SPR_MSSCR0, msscr0);
816 __asm__ __volatile__("dssall; sync");
819 __asm__ __volatile__("dcbf 0,%0" :: "r"(0));
820 __asm__ __volatile__("dcbf 0,%0" :: "r"(0));
821 __asm__ __volatile__("dcbf 0,%0" :: "r"(0));
823 /* Lock the L1 Data cache. */
824 mtspr(SPR_LDSTCR, mfspr(SPR_LDSTCR) | 0xFF);
828 mtspr(SPR_LDSTCR, 0);
831 * Perform this in two stages: Flush the cache starting in RAM, then do it
834 memp = (volatile uint32_t *)0x00000000;
835 for (i = 0; i < 128 * 1024; i++) {
837 __asm__ __volatile__("dcbf 0,%0" :: "r"(memp));
838 memp += 32/sizeof(*memp);
841 memp = (volatile uint32_t *)0xfff00000;
845 mtspr(SPR_LDSTCR, x);
846 for (i = 0; i < 128; i++) {
848 __asm__ __volatile__("dcbf 0,%0" :: "r"(memp));
849 memp += 32/sizeof(*memp);
851 x = ((x << 1) | 1) & 0xff;
853 mtspr(SPR_LDSTCR, 0);
855 cache_reg = mfspr(SPR_L2CR);
856 if (cache_reg & L2CR_L2E) {
857 cache_reg &= ~(L2CR_L2IO_7450 | L2CR_L2DO_7450);
858 mtspr(SPR_L2CR, cache_reg);
860 mtspr(SPR_L2CR, cache_reg | L2CR_L2HWF);
861 while (mfspr(SPR_L2CR) & L2CR_L2HWF)
862 ; /* Busy wait for cache to flush */
864 cache_reg &= ~L2CR_L2E;
865 mtspr(SPR_L2CR, cache_reg);
867 mtspr(SPR_L2CR, cache_reg | L2CR_L2I);
869 while (mfspr(SPR_L2CR) & L2CR_L2I)
870 ; /* Busy wait for L2 cache invalidate */
874 cache_reg = mfspr(SPR_L3CR);
875 if (cache_reg & L3CR_L3E) {
876 cache_reg &= ~(L3CR_L3IO | L3CR_L3DO);
877 mtspr(SPR_L3CR, cache_reg);
879 mtspr(SPR_L3CR, cache_reg | L3CR_L3HWF);
880 while (mfspr(SPR_L3CR) & L3CR_L3HWF)
881 ; /* Busy wait for cache to flush */
883 cache_reg &= ~L3CR_L3E;
884 mtspr(SPR_L3CR, cache_reg);
886 mtspr(SPR_L3CR, cache_reg | L3CR_L3I);
888 while (mfspr(SPR_L3CR) & L3CR_L3I)
889 ; /* Busy wait for L3 cache invalidate */
893 mtspr(SPR_HID0, mfspr(SPR_HID0) & ~HID0_DCE);
903 static u_quad_t timebase = 0;
904 static register_t sprgs[4];
905 static register_t srrs[2];
908 struct thread *fputd;
909 struct thread *vectd;
912 register_t saved_msr;
916 PCPU_SET(restore, &resetjb);
919 fputd = PCPU_GET(fputhread);
920 vectd = PCPU_GET(vecthread);
925 if (setjmp(resetjb) == 0) {
926 sprgs[0] = mfspr(SPR_SPRG0);
927 sprgs[1] = mfspr(SPR_SPRG1);
928 sprgs[2] = mfspr(SPR_SPRG2);
929 sprgs[3] = mfspr(SPR_SPRG3);
930 srrs[0] = mfspr(SPR_SRR0);
931 srrs[1] = mfspr(SPR_SRR1);
934 flush_disable_caches();
935 hid0 = mfspr(SPR_HID0);
936 hid0 = (hid0 & ~(HID0_DOZE | HID0_NAP)) | HID0_SLEEP;
939 msr = mfmsr() | PSL_POW;
940 mtspr(SPR_HID0, hid0);
947 PCPU_SET(curthread, curthread);
948 PCPU_SET(curpcb, curthread->td_pcb);
949 pmap_activate(curthread);
951 mtspr(SPR_SPRG0, sprgs[0]);
952 mtspr(SPR_SPRG1, sprgs[1]);
953 mtspr(SPR_SPRG2, sprgs[2]);
954 mtspr(SPR_SPRG3, sprgs[3]);
955 mtspr(SPR_SRR0, srrs[0]);
956 mtspr(SPR_SRR1, srrs[1]);
958 if (fputd == curthread)
959 enable_fpu(curthread);
960 if (vectd == curthread)
961 enable_vec(curthread);