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)
372 * switch to real mode (turn mmu off)
373 * we use the early kernel trick that the hardware ignores bits
374 * 0 and 1 (big endian) of the effective address in real mode
376 * don't overwrite r3 here, it is live for kexec_wait above.
378 real_mode: /* assume normal blr return */
379 #ifdef CONFIG_PPC_BOOK3E
380 /* Create an identity mapping. */
385 mflr r11 /* return address to SRR0 */
397 * kexec_sequence(newstack, start, image, control, clear_all(),
400 * does the grungy work with stack switching and real mode switches
401 * also does simple calls to other code
404 _GLOBAL(kexec_sequence)
408 /* switch stacks to newstack -- &kexec_stack.stack */
409 stdu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r3)
415 /* save regs for local vars on new stack.
416 * yes, we won't go back, but ...
426 stdu r1,-STACK_FRAME_OVERHEAD-64(r1)
428 /* save args into preserved regs */
429 mr r31,r3 /* newstack (both) */
430 mr r30,r4 /* start (real) */
431 mr r29,r5 /* image (virt) */
432 mr r28,r6 /* control, unused */
433 mr r27,r7 /* clear_all() fn desc */
434 mr r26,r8 /* copy_with_mmu_off */
435 lhz r25,PACAHWCPUID(r13) /* get our phys cpu from paca */
437 /* disable interrupts, we are overwriting kernel data next */
438 #ifdef CONFIG_PPC_BOOK3E
446 /* We need to turn the MMU off unless we are in hash mode
453 /* copy dest pages, flush whole dest image */
455 bl kexec_copy_flush /* (image) */
457 /* turn off mmu now if not done earlier */
462 /* copy 0x100 bytes starting at start to 0 */
464 mr r4,r30 /* start, aka phys mem offset */
467 bl copy_and_flush /* (dest, src, copy limit, start offset) */
468 1: /* assume normal blr return */
470 /* release other cpus to the new kernel secondary start at 0x60 */
473 stw r6,kexec_flag-1b(5)
478 /* clear out hardware hash page table and tlb */
479 #ifdef PPC64_ELF_ABI_v1
480 ld r12,0(r27) /* deref function descriptor */
485 bctrl /* mmu_hash_ops.hpte_clear_all(void); */
488 * kexec image calling is:
489 * the first 0x100 bytes of the entry point are copied to 0
491 * all slaves branch to slave = 0x60 (absolute)
492 * slave(phys_cpu_id);
494 * master goes to start = entry point
495 * start(phys_cpu_id, start, 0);
498 * a wrapper is needed to call existing kernels, here is an approximate
499 * description of one method:
502 * start will be near the boot_block (maybe 0x100 bytes before it?)
503 * it will have a 0x60, which will b to boot_block, where it will wait
504 * and 0 will store phys into struct boot-block and load r3 from there,
505 * copy kernel 0-0x100 and tell slaves to back down to 0x60 again
508 * boot block will have all cpus scanning device tree to see if they
509 * are the boot cpu ?????
510 * other device tree differences (prop sizes, va vs pa, etc)...
512 1: mr r3,r25 # my phys cpu
513 mr r4,r30 # start, aka phys mem offset
516 blr /* image->start(physid, image->start, 0); */
517 #endif /* CONFIG_KEXEC_CORE */