1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * This file contains the generic code to perform a call to the
4 * pSeries LPAR hypervisor.
6 #include <linux/jump_label.h>
7 #include <asm/hvcall.h>
8 #include <asm/processor.h>
9 #include <asm/ppc_asm.h>
10 #include <asm/asm-offsets.h>
11 #include <asm/ptrace.h>
12 #include <asm/feature-fixups.h>
16 #ifdef CONFIG_TRACEPOINTS
18 #ifndef CONFIG_JUMP_LABEL
21 .globl hcall_tracepoint_refcount
22 hcall_tracepoint_refcount:
29 * precall must preserve all registers. use unused STK_PARAM()
30 * areas to save snapshots and opcode.
32 #define HCALL_INST_PRECALL(FIRST_REG) \
34 std r3,STK_PARAM(R3)(r1); \
35 std r4,STK_PARAM(R4)(r1); \
36 std r5,STK_PARAM(R5)(r1); \
37 std r6,STK_PARAM(R6)(r1); \
38 std r7,STK_PARAM(R7)(r1); \
39 std r8,STK_PARAM(R8)(r1); \
40 std r9,STK_PARAM(R9)(r1); \
41 std r10,STK_PARAM(R10)(r1); \
43 addi r4,r1,STK_PARAM(FIRST_REG); \
44 stdu r1,-STACK_FRAME_OVERHEAD(r1); \
45 bl __trace_hcall_entry; \
46 ld r3,STACK_FRAME_OVERHEAD+STK_PARAM(R3)(r1); \
47 ld r4,STACK_FRAME_OVERHEAD+STK_PARAM(R4)(r1); \
48 ld r5,STACK_FRAME_OVERHEAD+STK_PARAM(R5)(r1); \
49 ld r6,STACK_FRAME_OVERHEAD+STK_PARAM(R6)(r1); \
50 ld r7,STACK_FRAME_OVERHEAD+STK_PARAM(R7)(r1); \
51 ld r8,STACK_FRAME_OVERHEAD+STK_PARAM(R8)(r1); \
52 ld r9,STACK_FRAME_OVERHEAD+STK_PARAM(R9)(r1); \
53 ld r10,STACK_FRAME_OVERHEAD+STK_PARAM(R10)(r1)
56 * postcall is performed immediately before function return which
57 * allows liberal use of volatile registers.
59 #define __HCALL_INST_POSTCALL \
60 ld r0,STACK_FRAME_OVERHEAD+STK_PARAM(R3)(r1); \
61 std r3,STACK_FRAME_OVERHEAD+STK_PARAM(R3)(r1); \
64 bl __trace_hcall_exit; \
65 ld r0,STACK_FRAME_OVERHEAD+16(r1); \
66 addi r1,r1,STACK_FRAME_OVERHEAD; \
67 ld r3,STK_PARAM(R3)(r1); \
70 #define HCALL_INST_POSTCALL_NORETS \
74 #define HCALL_INST_POSTCALL(BUFREG) \
78 #ifdef CONFIG_JUMP_LABEL
79 #define HCALL_BRANCH(LABEL) \
80 ARCH_STATIC_BRANCH(LABEL, hcall_tracepoint_key)
84 * We branch around this in early init (eg when populating the MMU
85 * hashtable) by using an unconditional cpu feature.
87 #define HCALL_BRANCH(LABEL) \
90 END_FTR_SECTION(0, 1); \
91 ld r12,hcall_tracepoint_refcount@toc(r2); \
99 #define HCALL_INST_PRECALL(FIRST_ARG)
100 #define HCALL_INST_POSTCALL_NORETS
101 #define HCALL_INST_POSTCALL(BUFREG)
102 #define HCALL_BRANCH(LABEL)
105 _GLOBAL_TOC(plpar_hcall_norets)
110 HCALL_BRANCH(plpar_hcall_norets_trace)
111 HVSC /* invoke the hypervisor */
115 blr /* return r3 = status */
117 #ifdef CONFIG_TRACEPOINTS
118 plpar_hcall_norets_trace:
119 HCALL_INST_PRECALL(R4)
121 HCALL_INST_POSTCALL_NORETS
127 _GLOBAL_TOC(plpar_hcall)
133 HCALL_BRANCH(plpar_hcall_trace)
135 std r4,STK_PARAM(R4)(r1) /* Save ret buffer */
144 HVSC /* invoke the hypervisor */
146 ld r12,STK_PARAM(R4)(r1)
155 blr /* return r3 = status */
157 #ifdef CONFIG_TRACEPOINTS
159 HCALL_INST_PRECALL(R5)
161 std r4,STK_PARAM(R4)(r1)
173 ld r12,STK_PARAM(R4)(r1)
179 HCALL_INST_POSTCALL(r12)
188 * plpar_hcall_raw can be called in real mode. kexec/kdump need some
189 * hypervisor calls to be executed in real mode. So plpar_hcall_raw
190 * does not access the per cpu hypervisor call statistics variables,
191 * since these variables may not be present in the RMO region.
193 _GLOBAL(plpar_hcall_raw)
199 std r4,STK_PARAM(R4)(r1) /* Save ret buffer */
208 HVSC /* invoke the hypervisor */
210 ld r12,STK_PARAM(R4)(r1)
219 blr /* return r3 = status */
221 _GLOBAL_TOC(plpar_hcall9)
227 HCALL_BRANCH(plpar_hcall9_trace)
229 std r4,STK_PARAM(R4)(r1) /* Save ret buffer */
237 ld r10,STK_PARAM(R11)(r1) /* put arg7 in R10 */
238 ld r11,STK_PARAM(R12)(r1) /* put arg8 in R11 */
239 ld r12,STK_PARAM(R13)(r1) /* put arg9 in R12 */
241 HVSC /* invoke the hypervisor */
244 ld r12,STK_PARAM(R4)(r1)
258 blr /* return r3 = status */
260 #ifdef CONFIG_TRACEPOINTS
262 HCALL_INST_PRECALL(R5)
264 std r4,STK_PARAM(R4)(r1)
273 ld r10,STACK_FRAME_OVERHEAD+STK_PARAM(R11)(r1)
274 ld r11,STACK_FRAME_OVERHEAD+STK_PARAM(R12)(r1)
275 ld r12,STACK_FRAME_OVERHEAD+STK_PARAM(R13)(r1)
280 ld r12,STACK_FRAME_OVERHEAD+STK_PARAM(R4)(r1)
291 HCALL_INST_POSTCALL(r12)
299 /* See plpar_hcall_raw to see why this is needed */
300 _GLOBAL(plpar_hcall9_raw)
306 std r4,STK_PARAM(R4)(r1) /* Save ret buffer */
314 ld r10,STK_PARAM(R11)(r1) /* put arg7 in R10 */
315 ld r11,STK_PARAM(R12)(r1) /* put arg8 in R11 */
316 ld r12,STK_PARAM(R13)(r1) /* put arg9 in R12 */
318 HVSC /* invoke the hypervisor */
321 ld r12,STK_PARAM(R4)(r1)
335 blr /* return r3 = status */