1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * This file contains miscellaneous low-level functions.
4 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
6 * Largely rewritten by Cort Dougan (cort@cs.nmt.edu)
8 * Adapted for iSeries by Mike Corrigan (mikejc@us.ibm.com)
9 * PPC64 updates by Dave Engebretsen (engebret@us.ibm.com)
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)
53 EXPORT_SYMBOL(__bswapdi2)
55 rlwinm r7,r3,8,0xffffffff
57 rlwinm r9,r8,8,0xffffffff
66 #ifdef CONFIG_PPC_EARLY_DEBUG_BOOTX
96 #endif /* CONFIG_PPC_EARLY_DEBUG_BOOTX */
98 #if defined(CONFIG_PPC_PMAC) || defined(CONFIG_PPC_MAPLE)
101 * Do an IO access in real mode
132 * Do an IO access in real mode
161 #endif /* defined(CONFIG_PPC_PMAC) || defined(CONFIG_PPC_MAPLE) */
163 #ifdef CONFIG_PPC_PASEMI
165 _GLOBAL(real_205_readb)
180 _GLOBAL(real_205_writeb)
195 #endif /* CONFIG_PPC_PASEMI */
198 #if defined(CONFIG_CPU_FREQ_PMAC64) || defined(CONFIG_CPU_FREQ_MAPLE)
200 * SCOM access functions for 970 (FX only for now)
202 * unsigned long scom970_read(unsigned int address);
203 * void scom970_write(unsigned int address, unsigned long value);
205 * The address passed in is the 24 bits register address. This code
206 * is 970 specific and will not check the status bits, so you should
207 * know what you are doing.
209 _GLOBAL(scom970_read)
216 /* rotate 24 bits SCOM address 8 bits left and mask out it's low 8 bits
217 * (including parity). On current CPUs they must be 0'd,
218 * and finally or in RW bit
223 /* do the actual scom read */
232 /* XXX: fixup result on some buggy 970's (ouch ! we lost a bit, bah
233 * that's the best we can do). Not implemented yet as we don't use
234 * the scom on any of the bogus CPUs yet, but may have to be done
238 /* restore interrupts */
243 _GLOBAL(scom970_write)
250 /* rotate 24 bits SCOM address 8 bits left and mask out it's low 8 bits
251 * (including parity). On current CPUs they must be 0'd.
257 mtspr SPRN_SCOMD,r4 /* write data */
259 mtspr SPRN_SCOMC,r3 /* write command */
264 /* restore interrupts */
267 #endif /* CONFIG_CPU_FREQ_PMAC64 || CONFIG_CPU_FREQ_MAPLE */
269 /* kexec_wait(phys_cpu)
271 * wait for the flag to change, indicating this kernel is going away but
272 * the slave code for the next one is at addresses 0 to 100.
274 * This is used by all slaves, even those that did not find a matching
275 * paca in the secondary startup code.
277 * Physical (hardware) cpu id should be in r3.
282 addi r5,r5,kexec_flag-1b
285 #ifdef CONFIG_KEXEC_CORE /* use no memory without kexec */
289 #ifdef CONFIG_PPC_BOOK3S_64
292 clrrdi r11,r11,1 /* Clear MSR_LE */
297 /* Create TLB entry in book3e_secondary_core_init */
303 /* this can be in text because we won't change it until we are
304 * running in real anyways
310 #ifdef CONFIG_KEXEC_CORE
311 #ifdef CONFIG_PPC_BOOK3E
313 * BOOK3E has no real MMU mode, so we have to setup the initial TLB
314 * for a core to identity map v:0 to p:0. This current implementation
315 * assumes that 1G is enough for kexec.
319 * Invalidate all non-IPROT TLB entries to avoid any TLB conflict.
320 * IPROT TLB entries should be >= PAGE_OFFSET and thus not conflict.
326 mfspr r10,SPRN_TLB1CFG
327 andi. r10,r10,TLBnCFG_N_ENTRY /* Extract # entries */
328 subi r10,r10,1 /* Last entry: no conflict with kernel text */
329 lis r9,MAS0_TLBSEL(1)@h
330 rlwimi r9,r10,16,4,15 /* Setup MAS0 = TLBSEL | ESEL(r9) */
332 /* Set up a temp identity mapping v:0 to p:0 and return to it. */
335 lis r9,(MAS1_VALID|MAS1_IPROT)@h
336 ori r9,r9,(MAS1_TSIZE(BOOK3E_PAGESZ_1GB))@l
339 LOAD_REG_IMMEDIATE(r9, 0x0 | MAS2_M_IF_NEEDED)
342 LOAD_REG_IMMEDIATE(r9, 0x0 | MAS3_SR | MAS3_SW | MAS3_SX)
352 /* kexec_smp_wait(void)
354 * call with interrupts off
355 * note: this is a terminal routine, it does not save lr
357 * get phys id from paca
358 * switch to real mode
359 * mark the paca as no longer used
360 * join other cpus in kexec_wait(phys_id)
362 _GLOBAL(kexec_smp_wait)
363 lhz r3,PACAHWCPUID(r13)
366 li r4,KEXEC_STATE_REAL_MODE
367 stb r4,PACAKEXECSTATE(r13)
373 * switch to real mode (turn mmu off)
374 * we use the early kernel trick that the hardware ignores bits
375 * 0 and 1 (big endian) of the effective address in real mode
377 * don't overwrite r3 here, it is live for kexec_wait above.
379 real_mode: /* assume normal blr return */
380 #ifdef CONFIG_PPC_BOOK3E
381 /* Create an identity mapping. */
386 mflr r11 /* return address to SRR0 */
398 * kexec_sequence(newstack, start, image, control, clear_all(),
401 * does the grungy work with stack switching and real mode switches
402 * also does simple calls to other code
405 _GLOBAL(kexec_sequence)
409 /* switch stacks to newstack -- &kexec_stack.stack */
410 stdu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r3)
418 * This is the best time to turn AMR/IAMR off.
419 * key 0 is used in radix for supervisor<->user
420 * protection, but on hash key 0 is reserved
421 * ideally we want to enter with a clean state.
422 * NOTE, we rely on r0 being 0 from above.
425 BEGIN_FTR_SECTION_NESTED(42)
427 END_FTR_SECTION_NESTED_IFSET(CPU_FTR_HVMODE, 42)
428 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
430 /* save regs for local vars on new stack.
431 * yes, we won't go back, but ...
441 stdu r1,-STACK_FRAME_OVERHEAD-64(r1)
443 /* save args into preserved regs */
444 mr r31,r3 /* newstack (both) */
445 mr r30,r4 /* start (real) */
446 mr r29,r5 /* image (virt) */
447 mr r28,r6 /* control, unused */
448 mr r27,r7 /* clear_all() fn desc */
449 mr r26,r8 /* copy_with_mmu_off */
450 lhz r25,PACAHWCPUID(r13) /* get our phys cpu from paca */
452 /* disable interrupts, we are overwriting kernel data next */
453 #ifdef CONFIG_PPC_BOOK3E
461 /* We need to turn the MMU off unless we are in hash mode
468 /* copy dest pages, flush whole dest image */
470 bl kexec_copy_flush /* (image) */
472 /* turn off mmu now if not done earlier */
477 /* copy 0x100 bytes starting at start to 0 */
479 mr r4,r30 /* start, aka phys mem offset */
482 bl copy_and_flush /* (dest, src, copy limit, start offset) */
483 1: /* assume normal blr return */
485 /* release other cpus to the new kernel secondary start at 0x60 */
488 stw r6,kexec_flag-1b(5)
493 /* clear out hardware hash page table and tlb */
494 #ifdef PPC64_ELF_ABI_v1
495 ld r12,0(r27) /* deref function descriptor */
500 bctrl /* mmu_hash_ops.hpte_clear_all(void); */
503 * kexec image calling is:
504 * the first 0x100 bytes of the entry point are copied to 0
506 * all slaves branch to slave = 0x60 (absolute)
507 * slave(phys_cpu_id);
509 * master goes to start = entry point
510 * start(phys_cpu_id, start, 0);
513 * a wrapper is needed to call existing kernels, here is an approximate
514 * description of one method:
517 * start will be near the boot_block (maybe 0x100 bytes before it?)
518 * it will have a 0x60, which will b to boot_block, where it will wait
519 * and 0 will store phys into struct boot-block and load r3 from there,
520 * copy kernel 0-0x100 and tell slaves to back down to 0x60 again
523 * boot block will have all cpus scanning device tree to see if they
524 * are the boot cpu ?????
525 * other device tree differences (prop sizes, va vs pa, etc)...
527 1: mr r3,r25 # my phys cpu
528 mr r4,r30 # start, aka phys mem offset
531 blr /* image->start(physid, image->start, 0); */
532 #endif /* CONFIG_KEXEC_CORE */