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/export.h>
13 #include <linux/linkage.h>
14 #include <linux/sys.h>
15 #include <asm/unistd.h>
16 #include <asm/errno.h>
17 #include <asm/processor.h>
19 #include <asm/cache.h>
20 #include <asm/ppc_asm.h>
21 #include <asm/asm-offsets.h>
22 #include <asm/cputable.h>
23 #include <asm/thread_info.h>
24 #include <asm/kexec.h>
25 #include <asm/ptrace.h>
27 #include <asm/feature-fixups.h>
32 EXPORT_SYMBOL(__bswapdi2)
34 rlwinm r7,r3,8,0xffffffff
36 rlwinm r9,r8,8,0xffffffff
45 #ifdef CONFIG_PPC_EARLY_DEBUG_BOOTX
75 #endif /* CONFIG_PPC_EARLY_DEBUG_BOOTX */
77 #ifdef CONFIG_PPC_PMAC
80 * Do an IO access in real mode
111 * Do an IO access in real mode
140 #endif // CONFIG_PPC_PMAC
142 #ifdef CONFIG_PPC_PASEMI
144 _GLOBAL(real_205_readb)
159 _GLOBAL(real_205_writeb)
174 #endif /* CONFIG_PPC_PASEMI */
177 #ifdef CONFIG_CPU_FREQ_PMAC64
179 * SCOM access functions for 970 (FX only for now)
181 * unsigned long scom970_read(unsigned int address);
182 * void scom970_write(unsigned int address, unsigned long value);
184 * The address passed in is the 24 bits register address. This code
185 * is 970 specific and will not check the status bits, so you should
186 * know what you are doing.
188 _GLOBAL(scom970_read)
195 /* rotate 24 bits SCOM address 8 bits left and mask out its low 8 bits
196 * (including parity). On current CPUs they must be 0'd,
197 * and finally or in RW bit
202 /* do the actual scom read */
211 /* XXX: fixup result on some buggy 970's (ouch ! we lost a bit, bah
212 * that's the best we can do). Not implemented yet as we don't use
213 * the scom on any of the bogus CPUs yet, but may have to be done
217 /* restore interrupts */
222 _GLOBAL(scom970_write)
229 /* rotate 24 bits SCOM address 8 bits left and mask out its low 8 bits
230 * (including parity). On current CPUs they must be 0'd.
236 mtspr SPRN_SCOMD,r4 /* write data */
238 mtspr SPRN_SCOMC,r3 /* write command */
243 /* restore interrupts */
246 #endif // CONFIG_CPU_FREQ_PMAC64
248 /* kexec_wait(phys_cpu)
250 * wait for the flag to change, indicating this kernel is going away but
251 * the slave code for the next one is at addresses 0 to 100.
253 * This is used by all slaves, even those that did not find a matching
254 * paca in the secondary startup code.
256 * Physical (hardware) cpu id should be in r3.
261 addi r5,r5,kexec_flag-1b
264 #ifdef CONFIG_KEXEC_CORE /* use no memory without kexec */
268 #ifdef CONFIG_PPC_BOOK3S_64
271 clrrdi r11,r11,1 /* Clear MSR_LE */
276 /* Create TLB entry in book3e_secondary_core_init */
282 /* this can be in text because we won't change it until we are
283 * running in real anyways
289 #ifdef CONFIG_KEXEC_CORE
290 #ifdef CONFIG_PPC_BOOK3E_64
292 * BOOK3E has no real MMU mode, so we have to setup the initial TLB
293 * for a core to identity map v:0 to p:0. This current implementation
294 * assumes that 1G is enough for kexec.
298 * Invalidate all non-IPROT TLB entries to avoid any TLB conflict.
299 * IPROT TLB entries should be >= PAGE_OFFSET and thus not conflict.
305 mfspr r10,SPRN_TLB1CFG
306 andi. r10,r10,TLBnCFG_N_ENTRY /* Extract # entries */
307 subi r10,r10,1 /* Last entry: no conflict with kernel text */
308 lis r9,MAS0_TLBSEL(1)@h
309 rlwimi r9,r10,16,4,15 /* Setup MAS0 = TLBSEL | ESEL(r9) */
311 /* Set up a temp identity mapping v:0 to p:0 and return to it. */
314 lis r9,(MAS1_VALID|MAS1_IPROT)@h
315 ori r9,r9,(MAS1_TSIZE(BOOK3E_PAGESZ_1GB))@l
318 LOAD_REG_IMMEDIATE(r9, 0x0 | MAS2_M_IF_NEEDED)
321 LOAD_REG_IMMEDIATE(r9, 0x0 | MAS3_SR | MAS3_SW | MAS3_SX)
331 /* kexec_smp_wait(void)
333 * call with interrupts off
334 * note: this is a terminal routine, it does not save lr
336 * get phys id from paca
337 * switch to real mode
338 * mark the paca as no longer used
339 * join other cpus in kexec_wait(phys_id)
341 _GLOBAL(kexec_smp_wait)
342 lhz r3,PACAHWCPUID(r13)
345 li r4,KEXEC_STATE_REAL_MODE
346 stb r4,PACAKEXECSTATE(r13)
351 * switch to real mode (turn mmu off)
352 * we use the early kernel trick that the hardware ignores bits
353 * 0 and 1 (big endian) of the effective address in real mode
355 * don't overwrite r3 here, it is live for kexec_wait above.
357 SYM_FUNC_START_LOCAL(real_mode) /* assume normal blr return */
358 #ifdef CONFIG_PPC_BOOK3E_64
359 /* Create an identity mapping. */
364 mflr r11 /* return address to SRR0 */
374 SYM_FUNC_END(real_mode)
377 * kexec_sequence(newstack, start, image, control, clear_all(),
380 * does the grungy work with stack switching and real mode switches
381 * also does simple calls to other code
384 _GLOBAL(kexec_sequence)
388 /* switch stacks to newstack -- &kexec_stack.stack */
389 stdu r1,THREAD_SIZE-STACK_FRAME_MIN_SIZE(r3)
395 /* save regs for local vars on new stack.
396 * yes, we won't go back, but ...
406 stdu r1,-STACK_FRAME_MIN_SIZE-64(r1)
408 /* save args into preserved regs */
409 mr r31,r3 /* newstack (both) */
410 mr r30,r4 /* start (real) */
411 mr r29,r5 /* image (virt) */
412 mr r28,r6 /* control, unused */
413 mr r27,r7 /* clear_all() fn desc */
414 mr r26,r8 /* copy_with_mmu_off */
415 lhz r25,PACAHWCPUID(r13) /* get our phys cpu from paca */
417 /* disable interrupts, we are overwriting kernel data next */
418 #ifdef CONFIG_PPC_BOOK3E_64
426 /* We need to turn the MMU off unless we are in hash mode
433 /* copy dest pages, flush whole dest image */
435 bl CFUNC(kexec_copy_flush) /* (image) */
437 /* turn off mmu now if not done earlier */
442 /* copy 0x100 bytes starting at start to 0 */
444 mr r4,r30 /* start, aka phys mem offset */
447 bl copy_and_flush /* (dest, src, copy limit, start offset) */
448 1: /* assume normal blr return */
450 /* release other cpus to the new kernel secondary start at 0x60 */
453 stw r6,kexec_flag-1b(5)
458 /* clear out hardware hash page table and tlb */
459 #ifdef CONFIG_PPC64_ELF_ABI_V1
460 ld r12,0(r27) /* deref function descriptor */
465 bctrl /* mmu_hash_ops.hpte_clear_all(void); */
468 * kexec image calling is:
469 * the first 0x100 bytes of the entry point are copied to 0
471 * all slaves branch to slave = 0x60 (absolute)
472 * slave(phys_cpu_id);
474 * master goes to start = entry point
475 * start(phys_cpu_id, start, 0);
478 * a wrapper is needed to call existing kernels, here is an approximate
479 * description of one method:
482 * start will be near the boot_block (maybe 0x100 bytes before it?)
483 * it will have a 0x60, which will b to boot_block, where it will wait
484 * and 0 will store phys into struct boot-block and load r3 from there,
485 * copy kernel 0-0x100 and tell slaves to back down to 0x60 again
488 * boot block will have all cpus scanning device tree to see if they
489 * are the boot cpu ?????
490 * other device tree differences (prop sizes, va vs pa, etc)...
492 1: mr r3,r25 # my phys cpu
493 mr r4,r30 # start, aka phys mem offset
496 blr /* image->start(physid, image->start, 0); */
497 #endif /* CONFIG_KEXEC_CORE */