arm64: alternative: put secondary CPUs into polling loop during patch
[deliverable/linux.git] / arch / arm64 / include / asm / alternative.h
CommitLineData
e039ee4e
AP
1#ifndef __ASM_ALTERNATIVE_H
2#define __ASM_ALTERNATIVE_H
3
8d883b23
MZ
4#ifndef __ASSEMBLY__
5
ef5e724b 6#include <linux/init.h>
91a5cefa 7#include <linux/kconfig.h>
e039ee4e
AP
8#include <linux/types.h>
9#include <linux/stddef.h>
10#include <linux/stringify.h>
11
12struct alt_instr {
13 s32 orig_offset; /* offset to original instruction */
14 s32 alt_offset; /* offset to replacement instruction */
15 u16 cpufeature; /* cpufeature bit set for replacement */
16 u8 orig_len; /* size of original instruction(s) */
17 u8 alt_len; /* size of new instruction(s), <= orig_len */
18};
19
ef5e724b 20void __init apply_alternatives_all(void);
932ded4b 21void apply_alternatives(void *start, size_t length);
e039ee4e
AP
22void free_alternatives_memory(void);
23
24#define ALTINSTR_ENTRY(feature) \
25 " .word 661b - .\n" /* label */ \
26 " .word 663f - .\n" /* new instruction */ \
27 " .hword " __stringify(feature) "\n" /* feature bit */ \
28 " .byte 662b-661b\n" /* source len */ \
29 " .byte 664f-663f\n" /* replacement len */
30
eb7c11ee
MZ
31/*
32 * alternative assembly primitive:
33 *
34 * If any of these .org directive fail, it means that insn1 and insn2
35 * don't have the same length. This used to be written as
36 *
37 * .if ((664b-663b) != (662b-661b))
38 * .error "Alternatives instruction length mismatch"
39 * .endif
40 *
41 * but most assemblers die if insn1 or insn2 have a .inst. This should
42 * be fixed in a binutils release posterior to 2.25.51.0.2 (anything
43 * containing commit 4e4d08cf7399b606 or c1baaddf8861).
44 */
91a5cefa
JM
45#define __ALTERNATIVE_CFG(oldinstr, newinstr, feature, cfg_enabled) \
46 ".if "__stringify(cfg_enabled)" == 1\n" \
e039ee4e
AP
47 "661:\n\t" \
48 oldinstr "\n" \
49 "662:\n" \
50 ".pushsection .altinstructions,\"a\"\n" \
51 ALTINSTR_ENTRY(feature) \
52 ".popsection\n" \
53 ".pushsection .altinstr_replacement, \"a\"\n" \
54 "663:\n\t" \
55 newinstr "\n" \
56 "664:\n\t" \
57 ".popsection\n\t" \
eb7c11ee 58 ".org . - (664b-663b) + (662b-661b)\n\t" \
91a5cefa
JM
59 ".org . - (662b-661b) + (664b-663b)\n" \
60 ".endif\n"
61
62#define _ALTERNATIVE_CFG(oldinstr, newinstr, feature, cfg, ...) \
63 __ALTERNATIVE_CFG(oldinstr, newinstr, feature, IS_ENABLED(cfg))
e039ee4e 64
8d883b23
MZ
65#else
66
67.macro altinstruction_entry orig_offset alt_offset feature orig_len alt_len
68 .word \orig_offset - .
69 .word \alt_offset - .
70 .hword \feature
71 .byte \orig_len
72 .byte \alt_len
73.endm
74
91a5cefa
JM
75.macro alternative_insn insn1, insn2, cap, enable = 1
76 .if \enable
8d883b23
MZ
77661: \insn1
78662: .pushsection .altinstructions, "a"
79 altinstruction_entry 661b, 663f, \cap, 662b-661b, 664f-663f
80 .popsection
81 .pushsection .altinstr_replacement, "ax"
82663: \insn2
83664: .popsection
eb7c11ee
MZ
84 .org . - (664b-663b) + (662b-661b)
85 .org . - (662b-661b) + (664b-663b)
91a5cefa 86 .endif
8d883b23
MZ
87.endm
88
63e40815
DT
89/*
90 * Begin an alternative code sequence.
91 *
92 * The code that follows this macro will be assembled and linked as
93 * normal. There are no restrictions on this code.
94 */
77ee306c
WD
95.macro alternative_if_not cap, enable = 1
96 .if \enable
63e40815
DT
97 .pushsection .altinstructions, "a"
98 altinstruction_entry 661f, 663f, \cap, 662f-661f, 664f-663f
99 .popsection
100661:
77ee306c 101 .endif
63e40815
DT
102.endm
103
104/*
105 * Provide the alternative code sequence.
106 *
107 * The code that follows this macro is assembled into a special
108 * section to be used for dynamic patching. Code that follows this
109 * macro must:
110 *
111 * 1. Be exactly the same length (in bytes) as the default code
112 * sequence.
113 *
114 * 2. Not contain a branch target that is used outside of the
115 * alternative sequence it is defined in (branches into an
116 * alternative sequence are not fixed up).
117 */
77ee306c
WD
118.macro alternative_else, enable = 1
119 .if \enable
63e40815
DT
120662: .pushsection .altinstr_replacement, "ax"
121663:
77ee306c 122 .endif
63e40815
DT
123.endm
124
125/*
126 * Complete an alternative code sequence.
127 */
77ee306c
WD
128.macro alternative_endif, enable = 1
129 .if \enable
63e40815
DT
130664: .popsection
131 .org . - (664b-663b) + (662b-661b)
132 .org . - (662b-661b) + (664b-663b)
77ee306c 133 .endif
63e40815
DT
134.endm
135
91a5cefa
JM
136#define _ALTERNATIVE_CFG(insn1, insn2, cap, cfg, ...) \
137 alternative_insn insn1, insn2, cap, IS_ENABLED(cfg)
138
139
8d883b23
MZ
140#endif /* __ASSEMBLY__ */
141
91a5cefa
JM
142/*
143 * Usage: asm(ALTERNATIVE(oldinstr, newinstr, feature));
144 *
145 * Usage: asm(ALTERNATIVE(oldinstr, newinstr, feature, CONFIG_FOO));
146 * N.B. If CONFIG_FOO is specified, but not selected, the whole block
147 * will be omitted, including oldinstr.
148 */
149#define ALTERNATIVE(oldinstr, newinstr, ...) \
150 _ALTERNATIVE_CFG(oldinstr, newinstr, __VA_ARGS__, 1)
151
e039ee4e 152#endif /* __ASM_ALTERNATIVE_H */
This page took 0.134535 seconds and 5 git commands to generate.