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 _GLOBAL(call_do_softirq)
37 stdu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r3)
48 stdu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r4)
58 .tc ppc64_caches[TC],ppc64_caches
62 * Write any modified data cache blocks out to memory
63 * and invalidate the corresponding instruction cache blocks.
65 * flush_icache_range(unsigned long start, unsigned long stop)
67 * flush all bytes from start through stop-1 inclusive
70 _GLOBAL_TOC(flush_icache_range)
74 END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
76 * Flush the data cache to memory
78 * Different systems have different cache line sizes
79 * and in some cases i-cache and d-cache line sizes differ from
82 ld r10,PPC64_CACHES@toc(r2)
83 lwz r7,DCACHEL1BLOCKSIZE(r10)/* Get cache block size */
85 andc r6,r3,r5 /* round low to line bdy */
86 subf r8,r6,r4 /* compute length */
87 add r8,r8,r5 /* ensure we get enough */
88 lwz r9,DCACHEL1LOGBLOCKSIZE(r10) /* Get log-2 of cache block size */
89 srw. r8,r8,r9 /* compute line count */
90 beqlr /* nothing to do? */
97 /* Now invalidate the instruction cache */
99 lwz r7,ICACHEL1BLOCKSIZE(r10) /* Get Icache block size */
101 andc r6,r3,r5 /* round low to line bdy */
102 subf r8,r6,r4 /* compute length */
104 lwz r9,ICACHEL1LOGBLOCKSIZE(r10) /* Get log-2 of Icache block size */
105 srw. r8,r8,r9 /* compute line count */
106 beqlr /* nothing to do? */
113 _ASM_NOKPROBE_SYMBOL(flush_icache_range)
114 EXPORT_SYMBOL(flush_icache_range)
117 * Like above, but only do the D-cache.
119 * flush_dcache_range(unsigned long start, unsigned long stop)
121 * flush all bytes from start to stop-1 inclusive
123 _GLOBAL_TOC(flush_dcache_range)
126 * Flush the data cache to memory
128 * Different systems have different cache line sizes
130 ld r10,PPC64_CACHES@toc(r2)
131 lwz r7,DCACHEL1BLOCKSIZE(r10) /* Get dcache block size */
133 andc r6,r3,r5 /* round low to line bdy */
134 subf r8,r6,r4 /* compute length */
135 add r8,r8,r5 /* ensure we get enough */
136 lwz r9,DCACHEL1LOGBLOCKSIZE(r10) /* Get log-2 of dcache block size */
137 srw. r8,r8,r9 /* compute line count */
138 beqlr /* nothing to do? */
145 EXPORT_SYMBOL(flush_dcache_range)
148 * Like above, but works on non-mapped physical addresses.
149 * Use only for non-LPAR setups ! It also assumes real mode
150 * is cacheable. Used for flushing out the DART before using
151 * it as uncacheable memory
153 * flush_dcache_phys_range(unsigned long start, unsigned long stop)
155 * flush all bytes from start to stop-1 inclusive
157 _GLOBAL(flush_dcache_phys_range)
158 ld r10,PPC64_CACHES@toc(r2)
159 lwz r7,DCACHEL1BLOCKSIZE(r10) /* Get dcache block size */
161 andc r6,r3,r5 /* round low to line bdy */
162 subf r8,r6,r4 /* compute length */
163 add r8,r8,r5 /* ensure we get enough */
164 lwz r9,DCACHEL1LOGBLOCKSIZE(r10) /* Get log-2 of dcache block size */
165 srw. r8,r8,r9 /* compute line count */
166 beqlr /* nothing to do? */
167 mfmsr r5 /* Disable MMU Data Relocation */
180 mtmsr r5 /* Re-enable MMU Data Relocation */
185 _GLOBAL(flush_inval_dcache_range)
186 ld r10,PPC64_CACHES@toc(r2)
187 lwz r7,DCACHEL1BLOCKSIZE(r10) /* Get dcache block size */
189 andc r6,r3,r5 /* round low to line bdy */
190 subf r8,r6,r4 /* compute length */
191 add r8,r8,r5 /* ensure we get enough */
192 lwz r9,DCACHEL1LOGBLOCKSIZE(r10)/* Get log-2 of dcache block size */
193 srw. r8,r8,r9 /* compute line count */
194 beqlr /* nothing to do? */
207 * Flush a particular page from the data cache to RAM.
208 * Note: this is necessary because the instruction cache does *not*
209 * snoop from the data cache.
211 * void __flush_dcache_icache(void *page)
213 _GLOBAL(__flush_dcache_icache)
215 * Flush the data cache to memory
217 * Different systems have different cache line sizes
223 END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
225 /* Flush the dcache */
226 ld r7,PPC64_CACHES@toc(r2)
227 clrrdi r3,r3,PAGE_SHIFT /* Page align */
228 lwz r4,DCACHEL1BLOCKSPERPAGE(r7) /* Get # dcache blocks per page */
229 lwz r5,DCACHEL1BLOCKSIZE(r7) /* Get dcache block size */
237 /* Now invalidate the icache */
239 lwz r4,ICACHEL1BLOCKSPERPAGE(r7) /* Get # icache blocks per page */
240 lwz r5,ICACHEL1BLOCKSIZE(r7) /* Get icache block size */
249 EXPORT_SYMBOL(__bswapdi2)
251 rlwinm r7,r3,8,0xffffffff
253 rlwinm r9,r8,8,0xffffffff
254 rlwimi r7,r3,24,16,23
256 rlwimi r9,r8,24,16,23
262 #ifdef CONFIG_PPC_EARLY_DEBUG_BOOTX
292 #endif /* CONFIG_PPC_EARLY_DEBUG_BOOTX */
294 #if defined(CONFIG_PPC_PMAC) || defined(CONFIG_PPC_MAPLE)
297 * Do an IO access in real mode
328 * Do an IO access in real mode
357 #endif /* defined(CONFIG_PPC_PMAC) || defined(CONFIG_PPC_MAPLE) */
359 #ifdef CONFIG_PPC_PASEMI
361 _GLOBAL(real_205_readb)
376 _GLOBAL(real_205_writeb)
391 #endif /* CONFIG_PPC_PASEMI */
394 #if defined(CONFIG_CPU_FREQ_PMAC64) || defined(CONFIG_CPU_FREQ_MAPLE)
396 * SCOM access functions for 970 (FX only for now)
398 * unsigned long scom970_read(unsigned int address);
399 * void scom970_write(unsigned int address, unsigned long value);
401 * The address passed in is the 24 bits register address. This code
402 * is 970 specific and will not check the status bits, so you should
403 * know what you are doing.
405 _GLOBAL(scom970_read)
412 /* rotate 24 bits SCOM address 8 bits left and mask out it's low 8 bits
413 * (including parity). On current CPUs they must be 0'd,
414 * and finally or in RW bit
419 /* do the actual scom read */
428 /* XXX: fixup result on some buggy 970's (ouch ! we lost a bit, bah
429 * that's the best we can do). Not implemented yet as we don't use
430 * the scom on any of the bogus CPUs yet, but may have to be done
434 /* restore interrupts */
439 _GLOBAL(scom970_write)
446 /* rotate 24 bits SCOM address 8 bits left and mask out it's low 8 bits
447 * (including parity). On current CPUs they must be 0'd.
453 mtspr SPRN_SCOMD,r4 /* write data */
455 mtspr SPRN_SCOMC,r3 /* write command */
460 /* restore interrupts */
463 #endif /* CONFIG_CPU_FREQ_PMAC64 || CONFIG_CPU_FREQ_MAPLE */
465 /* kexec_wait(phys_cpu)
467 * wait for the flag to change, indicating this kernel is going away but
468 * the slave code for the next one is at addresses 0 to 100.
470 * This is used by all slaves, even those that did not find a matching
471 * paca in the secondary startup code.
473 * Physical (hardware) cpu id should be in r3.
478 addi r5,r5,kexec_flag-1b
481 #ifdef CONFIG_KEXEC_CORE /* use no memory without kexec */
485 #ifdef CONFIG_PPC_BOOK3S_64
488 clrrdi r11,r11,1 /* Clear MSR_LE */
493 /* Create TLB entry in book3e_secondary_core_init */
499 /* this can be in text because we won't change it until we are
500 * running in real anyways
506 #ifdef CONFIG_KEXEC_CORE
507 #ifdef CONFIG_PPC_BOOK3E
509 * BOOK3E has no real MMU mode, so we have to setup the initial TLB
510 * for a core to identity map v:0 to p:0. This current implementation
511 * assumes that 1G is enough for kexec.
515 * Invalidate all non-IPROT TLB entries to avoid any TLB conflict.
516 * IPROT TLB entries should be >= PAGE_OFFSET and thus not conflict.
522 mfspr r10,SPRN_TLB1CFG
523 andi. r10,r10,TLBnCFG_N_ENTRY /* Extract # entries */
524 subi r10,r10,1 /* Last entry: no conflict with kernel text */
525 lis r9,MAS0_TLBSEL(1)@h
526 rlwimi r9,r10,16,4,15 /* Setup MAS0 = TLBSEL | ESEL(r9) */
528 /* Set up a temp identity mapping v:0 to p:0 and return to it. */
529 #if defined(CONFIG_SMP) || defined(CONFIG_PPC_E500MC)
530 #define M_IF_NEEDED MAS2_M
532 #define M_IF_NEEDED 0
536 lis r9,(MAS1_VALID|MAS1_IPROT)@h
537 ori r9,r9,(MAS1_TSIZE(BOOK3E_PAGESZ_1GB))@l
540 LOAD_REG_IMMEDIATE(r9, 0x0 | M_IF_NEEDED)
543 LOAD_REG_IMMEDIATE(r9, 0x0 | MAS3_SR | MAS3_SW | MAS3_SX)
553 /* kexec_smp_wait(void)
555 * call with interrupts off
556 * note: this is a terminal routine, it does not save lr
558 * get phys id from paca
559 * switch to real mode
560 * mark the paca as no longer used
561 * join other cpus in kexec_wait(phys_id)
563 _GLOBAL(kexec_smp_wait)
564 lhz r3,PACAHWCPUID(r13)
567 li r4,KEXEC_STATE_REAL_MODE
568 stb r4,PACAKEXECSTATE(r13)
574 * switch to real mode (turn mmu off)
575 * we use the early kernel trick that the hardware ignores bits
576 * 0 and 1 (big endian) of the effective address in real mode
578 * don't overwrite r3 here, it is live for kexec_wait above.
580 real_mode: /* assume normal blr return */
581 #ifdef CONFIG_PPC_BOOK3E
582 /* Create an identity mapping. */
587 mflr r11 /* return address to SRR0 */
599 * kexec_sequence(newstack, start, image, control, clear_all(),
602 * does the grungy work with stack switching and real mode switches
603 * also does simple calls to other code
606 _GLOBAL(kexec_sequence)
610 /* switch stacks to newstack -- &kexec_stack.stack */
611 stdu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r3)
619 * This is the best time to turn AMR/IAMR off.
620 * key 0 is used in radix for supervisor<->user
621 * protection, but on hash key 0 is reserved
622 * ideally we want to enter with a clean state.
623 * NOTE, we rely on r0 being 0 from above.
627 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
629 /* save regs for local vars on new stack.
630 * yes, we won't go back, but ...
640 stdu r1,-STACK_FRAME_OVERHEAD-64(r1)
642 /* save args into preserved regs */
643 mr r31,r3 /* newstack (both) */
644 mr r30,r4 /* start (real) */
645 mr r29,r5 /* image (virt) */
646 mr r28,r6 /* control, unused */
647 mr r27,r7 /* clear_all() fn desc */
648 mr r26,r8 /* copy_with_mmu_off */
649 lhz r25,PACAHWCPUID(r13) /* get our phys cpu from paca */
651 /* disable interrupts, we are overwriting kernel data next */
652 #ifdef CONFIG_PPC_BOOK3E
660 /* We need to turn the MMU off unless we are in hash mode
667 /* copy dest pages, flush whole dest image */
669 bl kexec_copy_flush /* (image) */
671 /* turn off mmu now if not done earlier */
676 /* copy 0x100 bytes starting at start to 0 */
678 mr r4,r30 /* start, aka phys mem offset */
681 bl copy_and_flush /* (dest, src, copy limit, start offset) */
682 1: /* assume normal blr return */
684 /* release other cpus to the new kernel secondary start at 0x60 */
687 stw r6,kexec_flag-1b(5)
692 /* clear out hardware hash page table and tlb */
693 #ifdef PPC64_ELF_ABI_v1
694 ld r12,0(r27) /* deref function descriptor */
699 bctrl /* mmu_hash_ops.hpte_clear_all(void); */
702 * kexec image calling is:
703 * the first 0x100 bytes of the entry point are copied to 0
705 * all slaves branch to slave = 0x60 (absolute)
706 * slave(phys_cpu_id);
708 * master goes to start = entry point
709 * start(phys_cpu_id, start, 0);
712 * a wrapper is needed to call existing kernels, here is an approximate
713 * description of one method:
716 * start will be near the boot_block (maybe 0x100 bytes before it?)
717 * it will have a 0x60, which will b to boot_block, where it will wait
718 * and 0 will store phys into struct boot-block and load r3 from there,
719 * copy kernel 0-0x100 and tell slaves to back down to 0x60 again
722 * boot block will have all cpus scanning device tree to see if they
723 * are the boot cpu ?????
724 * other device tree differences (prop sizes, va vs pa, etc)...
726 1: mr r3,r25 # my phys cpu
727 mr r4,r30 # start, aka phys mem offset
730 blr /* image->start(physid, image->start, 0); */
731 #endif /* CONFIG_KEXEC_CORE */