powerpc/64: reuse PPC32 static inline flush_dcache_range()
[sfrench/cifs-2.6.git] / arch / powerpc / purgatory / trampoline.S
1 /*
2  * kexec trampoline
3  *
4  * Based on code taken from kexec-tools and kexec-lite.
5  *
6  * Copyright (C) 2004 - 2005, Milton D Miller II, IBM Corporation
7  * Copyright (C) 2006, Mohan Kumar M, IBM Corporation
8  * Copyright (C) 2013, Anton Blanchard, IBM Corporation
9  *
10  * This program is free software; you can redistribute it and/or modify it under
11  * the terms of the GNU General Public License as published by the Free
12  * Software Foundation (version 2 of the License).
13  */
14
15 #include <asm/asm-compat.h>
16
17         .machine ppc64
18         .balign 256
19         .globl purgatory_start
20 purgatory_start:
21         b       master
22
23         /* ABI: possible run_at_load flag at 0x5c */
24         .org purgatory_start + 0x5c
25         .globl run_at_load
26 run_at_load:
27         .long 0
28         .size run_at_load, . - run_at_load
29
30         /* ABI: slaves start at 60 with r3=phys */
31         .org purgatory_start + 0x60
32 slave:
33         b .
34         /* ABI: end of copied region */
35         .org purgatory_start + 0x100
36         .size purgatory_start, . - purgatory_start
37
38 /*
39  * The above 0x100 bytes at purgatory_start are replaced with the
40  * code from the kernel (or next stage) by setup_purgatory().
41  */
42
43 master:
44         or      %r1,%r1,%r1     /* low priority to let other threads catchup */
45         isync
46         mr      %r17,%r3        /* save cpu id to r17 */
47         mr      %r15,%r4        /* save physical address in reg15 */
48
49         or      %r3,%r3,%r3     /* ok now to high priority, lets boot */
50         lis     %r6,0x1
51         mtctr   %r6             /* delay a bit for slaves to catch up */
52         bdnz    .               /* before we overwrite 0-100 again */
53
54         bl      0f              /* Work out where we're running */
55 0:      mflr    %r18
56
57         /* load device-tree address */
58         ld      %r3, (dt_offset - 0b)(%r18)
59         mr      %r16,%r3        /* save dt address in reg16 */
60         li      %r4,20
61         LWZX_BE %r6,%r3,%r4     /* fetch __be32 version number at byte 20 */
62         cmpwi   %cr0,%r6,2      /* v2 or later? */
63         blt     1f
64         li      %r4,28
65         STWX_BE %r17,%r3,%r4    /* Store my cpu as __be32 at byte 28 */
66 1:
67         /* load the kernel address */
68         ld      %r4,(kernel - 0b)(%r18)
69
70         /* load the run_at_load flag */
71         /* possibly patched by kexec */
72         ld      %r6,(run_at_load - 0b)(%r18)
73         /* and patch it into the kernel */
74         stw     %r6,(0x5c)(%r4)
75
76         mr      %r3,%r16        /* restore dt address */
77
78         li      %r5,0           /* r5 will be 0 for kernel */
79
80         mfmsr   %r11
81         andi.   %r10,%r11,1     /* test MSR_LE */
82         bne     .Little_endian
83
84         mtctr   %r4             /* prepare branch to */
85         bctr                    /* start kernel */
86
87 .Little_endian:
88         mtsrr0  %r4             /* prepare branch to */
89
90         clrrdi  %r11,%r11,1     /* clear MSR_LE */
91         mtsrr1  %r11
92
93         rfid                    /* update MSR and start kernel */
94
95
96         .balign 8
97         .globl kernel
98 kernel:
99         .8byte  0x0
100         .size kernel, . - kernel
101
102         .balign 8
103         .globl dt_offset
104 dt_offset:
105         .8byte  0x0
106         .size dt_offset, . - dt_offset
107
108
109         .data
110         .balign 8
111 .globl purgatory_sha256_digest
112 purgatory_sha256_digest:
113         .skip   32
114         .size purgatory_sha256_digest, . - purgatory_sha256_digest
115
116         .balign 8
117 .globl purgatory_sha_regions
118 purgatory_sha_regions:
119         .skip   8 * 2 * 16
120         .size purgatory_sha_regions, . - purgatory_sha_regions