2 * This file contains miscellaneous low-level functions.
3 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
5 * Largely rewritten by Cort Dougan (cort@cs.nmt.edu)
7 * Adapted for iSeries by Mike Corrigan (mikejc@us.ibm.com)
8 * PPC64 updates by Dave Engebretsen (engebret@us.ibm.com)
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
17 #include <linux/sys.h>
18 #include <asm/unistd.h>
19 #include <asm/errno.h>
20 #include <asm/processor.h>
22 #include <asm/cache.h>
23 #include <asm/ppc_asm.h>
24 #include <asm/asm-offsets.h>
25 #include <asm/cputable.h>
26 #include <asm/thread_info.h>
27 #include <asm/kexec.h>
28 #include <asm/ptrace.h>
30 #include <asm/export.h>
34 #ifndef CONFIG_PREEMPT_RT_FULL
35 _GLOBAL(call_do_softirq)
38 stdu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r3)
50 stdu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r4)
60 .tc ppc64_caches[TC],ppc64_caches
64 * Write any modified data cache blocks out to memory
65 * and invalidate the corresponding instruction cache blocks.
67 * flush_icache_range(unsigned long start, unsigned long stop)
69 * flush all bytes from start through stop-1 inclusive
72 _GLOBAL(flush_icache_range)
76 END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
78 * Flush the data cache to memory
80 * Different systems have different cache line sizes
81 * and in some cases i-cache and d-cache line sizes differ from
84 ld r10,PPC64_CACHES@toc(r2)
85 lwz r7,DCACHEL1LINESIZE(r10)/* Get cache line size */
87 andc r6,r3,r5 /* round low to line bdy */
88 subf r8,r6,r4 /* compute length */
89 add r8,r8,r5 /* ensure we get enough */
90 lwz r9,DCACHEL1LOGLINESIZE(r10) /* Get log-2 of cache line size */
91 srw. r8,r8,r9 /* compute line count */
92 beqlr /* nothing to do? */
99 /* Now invalidate the instruction cache */
101 lwz r7,ICACHEL1LINESIZE(r10) /* Get Icache line size */
103 andc r6,r3,r5 /* round low to line bdy */
104 subf r8,r6,r4 /* compute length */
106 lwz r9,ICACHEL1LOGLINESIZE(r10) /* Get log-2 of Icache line size */
107 srw. r8,r8,r9 /* compute line count */
108 beqlr /* nothing to do? */
115 _ASM_NOKPROBE_SYMBOL(flush_icache_range)
116 EXPORT_SYMBOL(flush_icache_range)
119 * Like above, but only do the D-cache.
121 * flush_dcache_range(unsigned long start, unsigned long stop)
123 * flush all bytes from start to stop-1 inclusive
125 _GLOBAL(flush_dcache_range)
128 * Flush the data cache to memory
130 * Different systems have different cache line sizes
132 ld r10,PPC64_CACHES@toc(r2)
133 lwz r7,DCACHEL1LINESIZE(r10) /* Get dcache line size */
135 andc r6,r3,r5 /* round low to line bdy */
136 subf r8,r6,r4 /* compute length */
137 add r8,r8,r5 /* ensure we get enough */
138 lwz r9,DCACHEL1LOGLINESIZE(r10) /* Get log-2 of dcache line size */
139 srw. r8,r8,r9 /* compute line count */
140 beqlr /* nothing to do? */
147 EXPORT_SYMBOL(flush_dcache_range)
150 * Like above, but works on non-mapped physical addresses.
151 * Use only for non-LPAR setups ! It also assumes real mode
152 * is cacheable. Used for flushing out the DART before using
153 * it as uncacheable memory
155 * flush_dcache_phys_range(unsigned long start, unsigned long stop)
157 * flush all bytes from start to stop-1 inclusive
159 _GLOBAL(flush_dcache_phys_range)
160 ld r10,PPC64_CACHES@toc(r2)
161 lwz r7,DCACHEL1LINESIZE(r10) /* Get dcache line size */
163 andc r6,r3,r5 /* round low to line bdy */
164 subf r8,r6,r4 /* compute length */
165 add r8,r8,r5 /* ensure we get enough */
166 lwz r9,DCACHEL1LOGLINESIZE(r10) /* Get log-2 of dcache line size */
167 srw. r8,r8,r9 /* compute line count */
168 beqlr /* nothing to do? */
169 mfmsr r5 /* Disable MMU Data Relocation */
182 mtmsr r5 /* Re-enable MMU Data Relocation */
187 _GLOBAL(flush_inval_dcache_range)
188 ld r10,PPC64_CACHES@toc(r2)
189 lwz r7,DCACHEL1LINESIZE(r10) /* Get dcache line size */
191 andc r6,r3,r5 /* round low to line bdy */
192 subf r8,r6,r4 /* compute length */
193 add r8,r8,r5 /* ensure we get enough */
194 lwz r9,DCACHEL1LOGLINESIZE(r10)/* Get log-2 of dcache line size */
195 srw. r8,r8,r9 /* compute line count */
196 beqlr /* nothing to do? */
209 * Flush a particular page from the data cache to RAM.
210 * Note: this is necessary because the instruction cache does *not*
211 * snoop from the data cache.
213 * void __flush_dcache_icache(void *page)
215 _GLOBAL(__flush_dcache_icache)
217 * Flush the data cache to memory
219 * Different systems have different cache line sizes
225 END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
227 /* Flush the dcache */
228 ld r7,PPC64_CACHES@toc(r2)
229 clrrdi r3,r3,PAGE_SHIFT /* Page align */
230 lwz r4,DCACHEL1LINESPERPAGE(r7) /* Get # dcache lines per page */
231 lwz r5,DCACHEL1LINESIZE(r7) /* Get dcache line size */
239 /* Now invalidate the icache */
241 lwz r4,ICACHEL1LINESPERPAGE(r7) /* Get # icache lines per page */
242 lwz r5,ICACHEL1LINESIZE(r7) /* Get icache line size */
251 EXPORT_SYMBOL(__bswapdi2)
253 rlwinm r7,r3,8,0xffffffff
255 rlwinm r9,r8,8,0xffffffff
256 rlwimi r7,r3,24,16,23
258 rlwimi r9,r8,24,16,23
264 #ifdef CONFIG_PPC_EARLY_DEBUG_BOOTX
294 #endif /* CONFIG_PPC_EARLY_DEBUG_BOOTX */
296 #if defined(CONFIG_PPC_PMAC) || defined(CONFIG_PPC_MAPLE)
299 * Do an IO access in real mode
330 * Do an IO access in real mode
359 #endif /* defined(CONFIG_PPC_PMAC) || defined(CONFIG_PPC_MAPLE) */
361 #ifdef CONFIG_PPC_PASEMI
363 _GLOBAL(real_205_readb)
378 _GLOBAL(real_205_writeb)
393 #endif /* CONFIG_PPC_PASEMI */
396 #if defined(CONFIG_CPU_FREQ_PMAC64) || defined(CONFIG_CPU_FREQ_MAPLE)
398 * SCOM access functions for 970 (FX only for now)
400 * unsigned long scom970_read(unsigned int address);
401 * void scom970_write(unsigned int address, unsigned long value);
403 * The address passed in is the 24 bits register address. This code
404 * is 970 specific and will not check the status bits, so you should
405 * know what you are doing.
407 _GLOBAL(scom970_read)
414 /* rotate 24 bits SCOM address 8 bits left and mask out it's low 8 bits
415 * (including parity). On current CPUs they must be 0'd,
416 * and finally or in RW bit
421 /* do the actual scom read */
430 /* XXX: fixup result on some buggy 970's (ouch ! we lost a bit, bah
431 * that's the best we can do). Not implemented yet as we don't use
432 * the scom on any of the bogus CPUs yet, but may have to be done
436 /* restore interrupts */
441 _GLOBAL(scom970_write)
448 /* rotate 24 bits SCOM address 8 bits left and mask out it's low 8 bits
449 * (including parity). On current CPUs they must be 0'd.
455 mtspr SPRN_SCOMD,r4 /* write data */
457 mtspr SPRN_SCOMC,r3 /* write command */
462 /* restore interrupts */
465 #endif /* CONFIG_CPU_FREQ_PMAC64 || CONFIG_CPU_FREQ_MAPLE */
467 /* kexec_wait(phys_cpu)
469 * wait for the flag to change, indicating this kernel is going away but
470 * the slave code for the next one is at addresses 0 to 100.
472 * This is used by all slaves, even those that did not find a matching
473 * paca in the secondary startup code.
475 * Physical (hardware) cpu id should be in r3.
480 addi r5,r5,kexec_flag-1b
483 #ifdef CONFIG_KEXEC /* use no memory without kexec */
487 #ifdef CONFIG_PPC_BOOK3S_64
490 clrrdi r11,r11,1 /* Clear MSR_LE */
495 /* Create TLB entry in book3e_secondary_core_init */
501 /* this can be in text because we won't change it until we are
502 * running in real anyways
509 #ifdef CONFIG_PPC_BOOK3E
511 * BOOK3E has no real MMU mode, so we have to setup the initial TLB
512 * for a core to identity map v:0 to p:0. This current implementation
513 * assumes that 1G is enough for kexec.
517 * Invalidate all non-IPROT TLB entries to avoid any TLB conflict.
518 * IPROT TLB entries should be >= PAGE_OFFSET and thus not conflict.
524 mfspr r10,SPRN_TLB1CFG
525 andi. r10,r10,TLBnCFG_N_ENTRY /* Extract # entries */
526 subi r10,r10,1 /* Last entry: no conflict with kernel text */
527 lis r9,MAS0_TLBSEL(1)@h
528 rlwimi r9,r10,16,4,15 /* Setup MAS0 = TLBSEL | ESEL(r9) */
530 /* Set up a temp identity mapping v:0 to p:0 and return to it. */
531 #if defined(CONFIG_SMP) || defined(CONFIG_PPC_E500MC)
532 #define M_IF_NEEDED MAS2_M
534 #define M_IF_NEEDED 0
538 lis r9,(MAS1_VALID|MAS1_IPROT)@h
539 ori r9,r9,(MAS1_TSIZE(BOOK3E_PAGESZ_1GB))@l
542 LOAD_REG_IMMEDIATE(r9, 0x0 | M_IF_NEEDED)
545 LOAD_REG_IMMEDIATE(r9, 0x0 | MAS3_SR | MAS3_SW | MAS3_SX)
555 /* kexec_smp_wait(void)
557 * call with interrupts off
558 * note: this is a terminal routine, it does not save lr
560 * get phys id from paca
561 * switch to real mode
562 * mark the paca as no longer used
563 * join other cpus in kexec_wait(phys_id)
565 _GLOBAL(kexec_smp_wait)
566 lhz r3,PACAHWCPUID(r13)
569 li r4,KEXEC_STATE_REAL_MODE
570 stb r4,PACAKEXECSTATE(r13)
576 * switch to real mode (turn mmu off)
577 * we use the early kernel trick that the hardware ignores bits
578 * 0 and 1 (big endian) of the effective address in real mode
580 * don't overwrite r3 here, it is live for kexec_wait above.
582 real_mode: /* assume normal blr return */
583 #ifdef CONFIG_PPC_BOOK3E
584 /* Create an identity mapping. */
589 mflr r11 /* return address to SRR0 */
601 * kexec_sequence(newstack, start, image, control, clear_all(),
604 * does the grungy work with stack switching and real mode switches
605 * also does simple calls to other code
608 _GLOBAL(kexec_sequence)
612 /* switch stacks to newstack -- &kexec_stack.stack */
613 stdu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r3)
619 /* save regs for local vars on new stack.
620 * yes, we won't go back, but ...
630 stdu r1,-STACK_FRAME_OVERHEAD-64(r1)
632 /* save args into preserved regs */
633 mr r31,r3 /* newstack (both) */
634 mr r30,r4 /* start (real) */
635 mr r29,r5 /* image (virt) */
636 mr r28,r6 /* control, unused */
637 mr r27,r7 /* clear_all() fn desc */
638 mr r26,r8 /* copy_with_mmu_off */
639 lhz r25,PACAHWCPUID(r13) /* get our phys cpu from paca */
641 /* disable interrupts, we are overwriting kernel data next */
642 #ifdef CONFIG_PPC_BOOK3E
650 /* We need to turn the MMU off unless we are in hash mode
657 /* copy dest pages, flush whole dest image */
659 bl kexec_copy_flush /* (image) */
661 /* turn off mmu now if not done earlier */
666 /* copy 0x100 bytes starting at start to 0 */
668 mr r4,r30 /* start, aka phys mem offset */
671 bl copy_and_flush /* (dest, src, copy limit, start offset) */
672 1: /* assume normal blr return */
674 /* release other cpus to the new kernel secondary start at 0x60 */
677 stw r6,kexec_flag-1b(5)
682 /* clear out hardware hash page table and tlb */
683 #ifdef PPC64_ELF_ABI_v1
684 ld r12,0(r27) /* deref function descriptor */
689 bctrl /* mmu_hash_ops.hpte_clear_all(void); */
692 * kexec image calling is:
693 * the first 0x100 bytes of the entry point are copied to 0
695 * all slaves branch to slave = 0x60 (absolute)
696 * slave(phys_cpu_id);
698 * master goes to start = entry point
699 * start(phys_cpu_id, start, 0);
702 * a wrapper is needed to call existing kernels, here is an approximate
703 * description of one method:
706 * start will be near the boot_block (maybe 0x100 bytes before it?)
707 * it will have a 0x60, which will b to boot_block, where it will wait
708 * and 0 will store phys into struct boot-block and load r3 from there,
709 * copy kernel 0-0x100 and tell slaves to back down to 0x60 again
712 * boot block will have all cpus scanning device tree to see if they
713 * are the boot cpu ?????
714 * other device tree differences (prop sizes, va vs pa, etc)...
716 1: mr r3,r25 # my phys cpu
717 mr r4,r30 # start, aka phys mem offset
720 blr /* image->start(physid, image->start, 0); */
721 #endif /* CONFIG_KEXEC */