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>
31
_GLOBAL(call_do_softirq)
34
stdu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r3)
42
_GLOBAL(call_handle_irq)
47
stdu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r5)
57
.tc ppc64_caches[TC],ppc64_caches
61
* Write any modified data cache blocks out to memory
62
* and invalidate the corresponding instruction cache blocks.
64
* flush_icache_range(unsigned long start, unsigned long stop)
66
* flush all bytes from start through stop-1 inclusive
69
_KPROBE(__flush_icache_range)
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,DCACHEL1LINESIZE(r10)/* Get cache line 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,DCACHEL1LOGLINESIZE(r10) /* Get log-2 of cache line size */
85
srw. r8,r8,r9 /* compute line count */
86
beqlr /* nothing to do? */
93
/* Now invalidate the instruction cache */
95
lwz r7,ICACHEL1LINESIZE(r10) /* Get Icache line size */
97
andc r6,r3,r5 /* round low to line bdy */
98
subf r8,r6,r4 /* compute length */
100
lwz r9,ICACHEL1LOGLINESIZE(r10) /* Get log-2 of Icache line size */
101
srw. r8,r8,r9 /* compute line count */
102
beqlr /* nothing to do? */
111
* Like above, but only do the D-cache.
113
* flush_dcache_range(unsigned long start, unsigned long stop)
115
* flush all bytes from start to stop-1 inclusive
117
_GLOBAL(flush_dcache_range)
120
* Flush the data cache to memory
122
* Different systems have different cache line sizes
124
ld r10,PPC64_CACHES@toc(r2)
125
lwz r7,DCACHEL1LINESIZE(r10) /* Get dcache line size */
127
andc r6,r3,r5 /* round low to line bdy */
128
subf r8,r6,r4 /* compute length */
129
add r8,r8,r5 /* ensure we get enough */
130
lwz r9,DCACHEL1LOGLINESIZE(r10) /* Get log-2 of dcache line size */
131
srw. r8,r8,r9 /* compute line count */
132
beqlr /* nothing to do? */
141
* Like above, but works on non-mapped physical addresses.
142
* Use only for non-LPAR setups ! It also assumes real mode
143
* is cacheable. Used for flushing out the DART before using
144
* it as uncacheable memory
146
* flush_dcache_phys_range(unsigned long start, unsigned long stop)
148
* flush all bytes from start to stop-1 inclusive
150
_GLOBAL(flush_dcache_phys_range)
151
ld r10,PPC64_CACHES@toc(r2)
152
lwz r7,DCACHEL1LINESIZE(r10) /* Get dcache line size */
154
andc r6,r3,r5 /* round low to line bdy */
155
subf r8,r6,r4 /* compute length */
156
add r8,r8,r5 /* ensure we get enough */
157
lwz r9,DCACHEL1LOGLINESIZE(r10) /* Get log-2 of dcache line size */
158
srw. r8,r8,r9 /* compute line count */
159
beqlr /* nothing to do? */
160
mfmsr r5 /* Disable MMU Data Relocation */
173
mtmsr r5 /* Re-enable MMU Data Relocation */
178
_GLOBAL(flush_inval_dcache_range)
179
ld r10,PPC64_CACHES@toc(r2)
180
lwz r7,DCACHEL1LINESIZE(r10) /* Get dcache line size */
182
andc r6,r3,r5 /* round low to line bdy */
183
subf r8,r6,r4 /* compute length */
184
add r8,r8,r5 /* ensure we get enough */
185
lwz r9,DCACHEL1LOGLINESIZE(r10)/* Get log-2 of dcache line size */
186
srw. r8,r8,r9 /* compute line count */
187
beqlr /* nothing to do? */
200
* Flush a particular page from the data cache to RAM.
201
* Note: this is necessary because the instruction cache does *not*
202
* snoop from the data cache.
204
* void __flush_dcache_icache(void *page)
206
_GLOBAL(__flush_dcache_icache)
208
* Flush the data cache to memory
210
* Different systems have different cache line sizes
213
/* Flush the dcache */
214
ld r7,PPC64_CACHES@toc(r2)
215
clrrdi r3,r3,PAGE_SHIFT /* Page align */
216
lwz r4,DCACHEL1LINESPERPAGE(r7) /* Get # dcache lines per page */
217
lwz r5,DCACHEL1LINESIZE(r7) /* Get dcache line size */
225
/* Now invalidate the icache */
227
lwz r4,ICACHEL1LINESPERPAGE(r7) /* Get # icache lines per page */
228
lwz r5,ICACHEL1LINESIZE(r7) /* Get icache line size */
237
#if defined(CONFIG_PPC_PMAC) || defined(CONFIG_PPC_MAPLE)
239
* Do an IO access in real mode
270
* Do an IO access in real mode
299
#endif /* defined(CONFIG_PPC_PMAC) || defined(CONFIG_PPC_MAPLE) */
301
#ifdef CONFIG_PPC_PASEMI
303
/* No support in all binutils for these yet, so use defines */
304
#define LBZCIX(RT,RA,RB) .long (0x7c0006aa|(RT<<21)|(RA<<16)|(RB << 11))
305
#define STBCIX(RS,RA,RB) .long (0x7c0007aa|(RS<<21)|(RA<<16)|(RB << 11))
308
_GLOBAL(real_205_readb)
323
_GLOBAL(real_205_writeb)
338
#endif /* CONFIG_PPC_PASEMI */
341
#ifdef CONFIG_CPU_FREQ_PMAC64
343
* SCOM access functions for 970 (FX only for now)
345
* unsigned long scom970_read(unsigned int address);
346
* void scom970_write(unsigned int address, unsigned long value);
348
* The address passed in is the 24 bits register address. This code
349
* is 970 specific and will not check the status bits, so you should
350
* know what you are doing.
352
_GLOBAL(scom970_read)
359
/* rotate 24 bits SCOM address 8 bits left and mask out it's low 8 bits
360
* (including parity). On current CPUs they must be 0'd,
361
* and finally or in RW bit
366
/* do the actual scom read */
375
/* XXX: fixup result on some buggy 970's (ouch ! we lost a bit, bah
376
* that's the best we can do). Not implemented yet as we don't use
377
* the scom on any of the bogus CPUs yet, but may have to be done
381
/* restore interrupts */
386
_GLOBAL(scom970_write)
393
/* rotate 24 bits SCOM address 8 bits left and mask out it's low 8 bits
394
* (including parity). On current CPUs they must be 0'd.
400
mtspr SPRN_SCOMD,r4 /* write data */
402
mtspr SPRN_SCOMC,r3 /* write command */
407
/* restore interrupts */
410
#endif /* CONFIG_CPU_FREQ_PMAC64 */
414
* Create a kernel thread
415
* kernel_thread(fn, arg, flags)
417
_GLOBAL(kernel_thread)
420
stdu r1,-STACK_FRAME_OVERHEAD(r1)
423
ori r3,r5,CLONE_VM /* flags */
424
oris r3,r3,(CLONE_UNTRACED>>16)
425
li r4,0 /* new sp (unused) */
428
bns+ 1f /* did system call indicate error? */
429
neg r3,r3 /* if so, make return code negative */
430
1: cmpdi 0,r3,0 /* parent or child? */
431
bne 2f /* return if parent */
433
stdu r0,-STACK_FRAME_OVERHEAD(r1)
436
mtlr r29 /* fn addr in lr */
437
mr r3,r30 /* load arg and call fn */
439
li r0,__NR_exit /* exit after child exits */
442
2: addi r1,r1,STACK_FRAME_OVERHEAD
448
* disable_kernel_fp()
451
_GLOBAL(disable_kernel_fp)
453
rldicl r0,r3,(63-MSR_FP_LG),1
454
rldicl r3,r0,(MSR_FP_LG+1),0
455
mtmsrd r3 /* disable use of fpu now */
459
/* kexec_wait(phys_cpu)
461
* wait for the flag to change, indicating this kernel is going away but
462
* the slave code for the next one is at addresses 0 to 100.
464
* This is used by all slaves.
466
* Physical (hardware) cpu id should be in r3.
471
addi r5,r5,kexec_flag-1b
473
li r4,KEXEC_STATE_REAL_MODE
474
stb r4,PACAKEXECSTATE(r13)
478
#ifdef CONFIG_KEXEC /* use no memory without kexec */
485
/* this can be in text because we won't change it until we are
486
* running in real anyways
494
/* kexec_smp_wait(void)
496
* call with interrupts off
497
* note: this is a terminal routine, it does not save lr
499
* get phys id from paca
500
* switch to real mode
501
* join other cpus in kexec_wait(phys_id)
503
_GLOBAL(kexec_smp_wait)
504
lhz r3,PACAHWCPUID(r13)
509
* switch to real mode (turn mmu off)
510
* we use the early kernel trick that the hardware ignores bits
511
* 0 and 1 (big endian) of the effective address in real mode
513
* don't overwrite r3 here, it is live for kexec_wait above.
515
real_mode: /* assume normal blr return */
518
mflr r11 /* return address to SRR0 */
530
* kexec_sequence(newstack, start, image, control, clear_all())
532
* does the grungy work with stack switching and real mode switches
533
* also does simple calls to other code
536
_GLOBAL(kexec_sequence)
540
/* switch stacks to newstack -- &kexec_stack.stack */
541
stdu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r3)
547
/* save regs for local vars on new stack.
548
* yes, we won't go back, but ...
558
stdu r1,-STACK_FRAME_OVERHEAD-64(r1)
560
/* save args into preserved regs */
561
mr r31,r3 /* newstack (both) */
562
mr r30,r4 /* start (real) */
563
mr r29,r5 /* image (virt) */
564
mr r28,r6 /* control, unused */
565
mr r27,r7 /* clear_all() fn desc */
566
mr r26,r8 /* spare */
567
lhz r25,PACAHWCPUID(r13) /* get our phys cpu from paca */
569
/* disable interrupts, we are overwriting kernel data next */
574
/* copy dest pages, flush whole dest image */
576
bl .kexec_copy_flush /* (image) */
581
/* copy 0x100 bytes starting at start to 0 */
583
mr r4,r30 /* start, aka phys mem offset */
586
bl .copy_and_flush /* (dest, src, copy limit, start offset) */
587
1: /* assume normal blr return */
589
/* release other cpus to the new kernel secondary start at 0x60 */
592
stw r6,kexec_flag-1b(5)
594
/* clear out hardware hash page table and tlb */
595
ld r5,0(r27) /* deref function descriptor */
597
bctrl /* ppc_md.hpte_clear_all(void); */
600
* kexec image calling is:
601
* the first 0x100 bytes of the entry point are copied to 0
603
* all slaves branch to slave = 0x60 (absolute)
604
* slave(phys_cpu_id);
606
* master goes to start = entry point
607
* start(phys_cpu_id, start, 0);
610
* a wrapper is needed to call existing kernels, here is an approximate
611
* description of one method:
614
* start will be near the boot_block (maybe 0x100 bytes before it?)
615
* it will have a 0x60, which will b to boot_block, where it will wait
616
* and 0 will store phys into struct boot-block and load r3 from there,
617
* copy kernel 0-0x100 and tell slaves to back down to 0x60 again
620
* boot block will have all cpus scanning device tree to see if they
621
* are the boot cpu ?????
622
* other device tree differences (prop sizes, va vs pa, etc)...
624
mr r3,r25 # my phys cpu
625
mr r4,r30 # start, aka phys mem offset
628
blr /* image->start(physid, image->start, 0); */
629
#endif /* CONFIG_KEXEC */