1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * This file contains miscellaneous low-level functions.
12 #include <linux/sys.h>
13 #include <asm/unistd.h>
14 #include <asm/errno.h>
15 #include <asm/processor.h>
17 #include <asm/cache.h>
18 #include <asm/ppc_asm.h>
19 #include <asm/asm-offsets.h>
20 #include <asm/cputable.h>
21 #include <asm/thread_info.h>
22 #include <asm/kexec.h>
23 #include <asm/ptrace.h>
25 #include <asm/export.h>
26 #include <asm/feature-fixups.h>
30 _GLOBAL(call_do_softirq)
33 stdu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r3)
44 stdu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r4)
54 .tc ppc64_caches[TC],ppc64_caches
58 * Write any modified data cache blocks out to memory
59 * and invalidate the corresponding instruction cache blocks.
61 * flush_icache_range(unsigned long start, unsigned long stop)
63 * flush all bytes from start through stop-1 inclusive
66 _GLOBAL_TOC(flush_icache_range)
70 END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
72 * Flush the data cache to memory
74 * Different systems have different cache line sizes
75 * and in some cases i-cache and d-cache line sizes differ from
78 ld r10,PPC64_CACHES@toc(r2)
79 lwz r7,DCACHEL1BLOCKSIZE(r10)/* Get cache block size */
81 andc r6,r3,r5 /* round low to line bdy */
82 subf r8,r6,r4 /* compute length */
83 add r8,r8,r5 /* ensure we get enough */
84 lwz r9,DCACHEL1LOGBLOCKSIZE(r10) /* Get log-2 of cache block size */
85 srw. r8,r8,r9 /* compute line count */
86 beqlr /* nothing to do? */
93 /* Now invalidate the instruction cache */
95 lwz r7,ICACHEL1BLOCKSIZE(r10) /* Get Icache block size */
97 andc r6,r3,r5 /* round low to line bdy */
98 subf r8,r6,r4 /* compute length */
100 lwz r9,ICACHEL1LOGBLOCKSIZE(r10) /* Get log-2 of Icache block size */
101 srw. r8,r8,r9 /* compute line count */
102 beqlr /* nothing to do? */
109 _ASM_NOKPROBE_SYMBOL(flush_icache_range)
110 EXPORT_SYMBOL(flush_icache_range)
113 * Flush a particular page from the data cache to RAM.
114 * Note: this is necessary because the instruction cache does *not*
115 * snoop from the data cache.
117 * void __flush_dcache_icache(void *page)
119 _GLOBAL(__flush_dcache_icache)
121 * Flush the data cache to memory
123 * Different systems have different cache line sizes
129 END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
131 /* Flush the dcache */
132 ld r7,PPC64_CACHES@toc(r2)
133 clrrdi r3,r3,PAGE_SHIFT /* Page align */
134 lwz r4,DCACHEL1BLOCKSPERPAGE(r7) /* Get # dcache blocks per page */
135 lwz r5,DCACHEL1BLOCKSIZE(r7) /* Get dcache block size */
143 /* Now invalidate the icache */
145 lwz r4,ICACHEL1BLOCKSPERPAGE(r7) /* Get # icache blocks per page */
146 lwz r5,ICACHEL1BLOCKSIZE(r7) /* Get icache block size */
155 EXPORT_SYMBOL(__bswapdi2)
157 rlwinm r7,r3,8,0xffffffff
159 rlwinm r9,r8,8,0xffffffff
160 rlwimi r7,r3,24,16,23
162 rlwimi r9,r8,24,16,23
168 #ifdef CONFIG_PPC_EARLY_DEBUG_BOOTX
198 #endif /* CONFIG_PPC_EARLY_DEBUG_BOOTX */
200 #if defined(CONFIG_PPC_PMAC) || defined(CONFIG_PPC_MAPLE)
203 * Do an IO access in real mode
234 * Do an IO access in real mode
263 #endif /* defined(CONFIG_PPC_PMAC) || defined(CONFIG_PPC_MAPLE) */
265 #ifdef CONFIG_PPC_PASEMI
267 _GLOBAL(real_205_readb)
282 _GLOBAL(real_205_writeb)
297 #endif /* CONFIG_PPC_PASEMI */
300 #if defined(CONFIG_CPU_FREQ_PMAC64) || defined(CONFIG_CPU_FREQ_MAPLE)
302 * SCOM access functions for 970 (FX only for now)
304 * unsigned long scom970_read(unsigned int address);
305 * void scom970_write(unsigned int address, unsigned long value);
307 * The address passed in is the 24 bits register address. This code
308 * is 970 specific and will not check the status bits, so you should
309 * know what you are doing.
311 _GLOBAL(scom970_read)
318 /* rotate 24 bits SCOM address 8 bits left and mask out it's low 8 bits
319 * (including parity). On current CPUs they must be 0'd,
320 * and finally or in RW bit
325 /* do the actual scom read */
334 /* XXX: fixup result on some buggy 970's (ouch ! we lost a bit, bah
335 * that's the best we can do). Not implemented yet as we don't use
336 * the scom on any of the bogus CPUs yet, but may have to be done
340 /* restore interrupts */
345 _GLOBAL(scom970_write)
352 /* rotate 24 bits SCOM address 8 bits left and mask out it's low 8 bits
353 * (including parity). On current CPUs they must be 0'd.
359 mtspr SPRN_SCOMD,r4 /* write data */
361 mtspr SPRN_SCOMC,r3 /* write command */
366 /* restore interrupts */
369 #endif /* CONFIG_CPU_FREQ_PMAC64 || CONFIG_CPU_FREQ_MAPLE */
371 /* kexec_wait(phys_cpu)
373 * wait for the flag to change, indicating this kernel is going away but
374 * the slave code for the next one is at addresses 0 to 100.
376 * This is used by all slaves, even those that did not find a matching
377 * paca in the secondary startup code.
379 * Physical (hardware) cpu id should be in r3.
384 addi r5,r5,kexec_flag-1b
387 #ifdef CONFIG_KEXEC_CORE /* use no memory without kexec */
391 #ifdef CONFIG_PPC_BOOK3S_64
394 clrrdi r11,r11,1 /* Clear MSR_LE */
399 /* Create TLB entry in book3e_secondary_core_init */
405 /* this can be in text because we won't change it until we are
406 * running in real anyways
412 #ifdef CONFIG_KEXEC_CORE
413 #ifdef CONFIG_PPC_BOOK3E
415 * BOOK3E has no real MMU mode, so we have to setup the initial TLB
416 * for a core to identity map v:0 to p:0. This current implementation
417 * assumes that 1G is enough for kexec.
421 * Invalidate all non-IPROT TLB entries to avoid any TLB conflict.
422 * IPROT TLB entries should be >= PAGE_OFFSET and thus not conflict.
428 mfspr r10,SPRN_TLB1CFG
429 andi. r10,r10,TLBnCFG_N_ENTRY /* Extract # entries */
430 subi r10,r10,1 /* Last entry: no conflict with kernel text */
431 lis r9,MAS0_TLBSEL(1)@h
432 rlwimi r9,r10,16,4,15 /* Setup MAS0 = TLBSEL | ESEL(r9) */
434 /* Set up a temp identity mapping v:0 to p:0 and return to it. */
435 #if defined(CONFIG_SMP) || defined(CONFIG_PPC_E500MC)
436 #define M_IF_NEEDED MAS2_M
438 #define M_IF_NEEDED 0
442 lis r9,(MAS1_VALID|MAS1_IPROT)@h
443 ori r9,r9,(MAS1_TSIZE(BOOK3E_PAGESZ_1GB))@l
446 LOAD_REG_IMMEDIATE(r9, 0x0 | M_IF_NEEDED)
449 LOAD_REG_IMMEDIATE(r9, 0x0 | MAS3_SR | MAS3_SW | MAS3_SX)
459 /* kexec_smp_wait(void)
461 * call with interrupts off
462 * note: this is a terminal routine, it does not save lr
464 * get phys id from paca
465 * switch to real mode
466 * mark the paca as no longer used
467 * join other cpus in kexec_wait(phys_id)
469 _GLOBAL(kexec_smp_wait)
470 lhz r3,PACAHWCPUID(r13)
473 li r4,KEXEC_STATE_REAL_MODE
474 stb r4,PACAKEXECSTATE(r13)
480 * switch to real mode (turn mmu off)
481 * we use the early kernel trick that the hardware ignores bits
482 * 0 and 1 (big endian) of the effective address in real mode
484 * don't overwrite r3 here, it is live for kexec_wait above.
486 real_mode: /* assume normal blr return */
487 #ifdef CONFIG_PPC_BOOK3E
488 /* Create an identity mapping. */
493 mflr r11 /* return address to SRR0 */
505 * kexec_sequence(newstack, start, image, control, clear_all(),
508 * does the grungy work with stack switching and real mode switches
509 * also does simple calls to other code
512 _GLOBAL(kexec_sequence)
516 /* switch stacks to newstack -- &kexec_stack.stack */
517 stdu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r3)
525 * This is the best time to turn AMR/IAMR off.
526 * key 0 is used in radix for supervisor<->user
527 * protection, but on hash key 0 is reserved
528 * ideally we want to enter with a clean state.
529 * NOTE, we rely on r0 being 0 from above.
532 BEGIN_FTR_SECTION_NESTED(42)
534 END_FTR_SECTION_NESTED_IFSET(CPU_FTR_HVMODE, 42)
535 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
537 /* save regs for local vars on new stack.
538 * yes, we won't go back, but ...
548 stdu r1,-STACK_FRAME_OVERHEAD-64(r1)
550 /* save args into preserved regs */
551 mr r31,r3 /* newstack (both) */
552 mr r30,r4 /* start (real) */
553 mr r29,r5 /* image (virt) */
554 mr r28,r6 /* control, unused */
555 mr r27,r7 /* clear_all() fn desc */
556 mr r26,r8 /* copy_with_mmu_off */
557 lhz r25,PACAHWCPUID(r13) /* get our phys cpu from paca */
559 /* disable interrupts, we are overwriting kernel data next */
560 #ifdef CONFIG_PPC_BOOK3E
568 /* We need to turn the MMU off unless we are in hash mode
575 /* copy dest pages, flush whole dest image */
577 bl kexec_copy_flush /* (image) */
579 /* turn off mmu now if not done earlier */
584 /* copy 0x100 bytes starting at start to 0 */
586 mr r4,r30 /* start, aka phys mem offset */
589 bl copy_and_flush /* (dest, src, copy limit, start offset) */
590 1: /* assume normal blr return */
592 /* release other cpus to the new kernel secondary start at 0x60 */
595 stw r6,kexec_flag-1b(5)
600 /* clear out hardware hash page table and tlb */
601 #ifdef PPC64_ELF_ABI_v1
602 ld r12,0(r27) /* deref function descriptor */
607 bctrl /* mmu_hash_ops.hpte_clear_all(void); */
610 * kexec image calling is:
611 * the first 0x100 bytes of the entry point are copied to 0
613 * all slaves branch to slave = 0x60 (absolute)
614 * slave(phys_cpu_id);
616 * master goes to start = entry point
617 * start(phys_cpu_id, start, 0);
620 * a wrapper is needed to call existing kernels, here is an approximate
621 * description of one method:
624 * start will be near the boot_block (maybe 0x100 bytes before it?)
625 * it will have a 0x60, which will b to boot_block, where it will wait
626 * and 0 will store phys into struct boot-block and load r3 from there,
627 * copy kernel 0-0x100 and tell slaves to back down to 0x60 again
630 * boot block will have all cpus scanning device tree to see if they
631 * are the boot cpu ?????
632 * other device tree differences (prop sizes, va vs pa, etc)...
634 1: mr r3,r25 # my phys cpu
635 mr r4,r30 # start, aka phys mem offset
638 blr /* image->start(physid, image->start, 0); */
639 #endif /* CONFIG_KEXEC_CORE */