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_notrace)
110 HVSC /* invoke the hypervisor */
113 stb r4,PACASRR_VALID(r13)
117 blr /* return r3 = status */
119 _GLOBAL_TOC(plpar_hcall_norets)
124 HCALL_BRANCH(plpar_hcall_norets_trace)
125 HVSC /* invoke the hypervisor */
128 stb r4,PACASRR_VALID(r13)
132 blr /* return r3 = status */
134 #ifdef CONFIG_TRACEPOINTS
135 plpar_hcall_norets_trace:
136 HCALL_INST_PRECALL(R4)
138 HCALL_INST_POSTCALL_NORETS
141 stb r4,PACASRR_VALID(r13)
148 _GLOBAL_TOC(plpar_hcall)
154 HCALL_BRANCH(plpar_hcall_trace)
156 std r4,STK_PARAM(R4)(r1) /* Save ret buffer */
165 HVSC /* invoke the hypervisor */
167 ld r12,STK_PARAM(R4)(r1)
174 stb r4,PACASRR_VALID(r13)
179 blr /* return r3 = status */
181 #ifdef CONFIG_TRACEPOINTS
183 HCALL_INST_PRECALL(R5)
185 std r4,STK_PARAM(R4)(r1)
197 ld r12,STK_PARAM(R4)(r1)
203 HCALL_INST_POSTCALL(r12)
206 stb r4,PACASRR_VALID(r13)
215 * plpar_hcall_raw can be called in real mode. kexec/kdump need some
216 * hypervisor calls to be executed in real mode. So plpar_hcall_raw
217 * does not access the per cpu hypervisor call statistics variables,
218 * since these variables may not be present in the RMO region.
220 _GLOBAL(plpar_hcall_raw)
226 std r4,STK_PARAM(R4)(r1) /* Save ret buffer */
235 HVSC /* invoke the hypervisor */
237 ld r12,STK_PARAM(R4)(r1)
244 stb r4,PACASRR_VALID(r13)
249 blr /* return r3 = status */
251 _GLOBAL_TOC(plpar_hcall9)
257 HCALL_BRANCH(plpar_hcall9_trace)
259 std r4,STK_PARAM(R4)(r1) /* Save ret buffer */
267 ld r10,STK_PARAM(R11)(r1) /* put arg7 in R10 */
268 ld r11,STK_PARAM(R12)(r1) /* put arg8 in R11 */
269 ld r12,STK_PARAM(R13)(r1) /* put arg9 in R12 */
271 HVSC /* invoke the hypervisor */
274 ld r12,STK_PARAM(R4)(r1)
286 stb r4,PACASRR_VALID(r13)
291 blr /* return r3 = status */
293 #ifdef CONFIG_TRACEPOINTS
295 HCALL_INST_PRECALL(R5)
297 std r4,STK_PARAM(R4)(r1)
306 ld r10,STACK_FRAME_OVERHEAD+STK_PARAM(R11)(r1)
307 ld r11,STACK_FRAME_OVERHEAD+STK_PARAM(R12)(r1)
308 ld r12,STACK_FRAME_OVERHEAD+STK_PARAM(R13)(r1)
313 ld r12,STACK_FRAME_OVERHEAD+STK_PARAM(R4)(r1)
324 HCALL_INST_POSTCALL(r12)
327 stb r4,PACASRR_VALID(r13)
335 /* See plpar_hcall_raw to see why this is needed */
336 _GLOBAL(plpar_hcall9_raw)
342 std r4,STK_PARAM(R4)(r1) /* Save ret buffer */
350 ld r10,STK_PARAM(R11)(r1) /* put arg7 in R10 */
351 ld r11,STK_PARAM(R12)(r1) /* put arg8 in R11 */
352 ld r12,STK_PARAM(R13)(r1) /* put arg9 in R12 */
354 HVSC /* invoke the hypervisor */
357 ld r12,STK_PARAM(R4)(r1)
369 stb r4,PACASRR_VALID(r13)
374 blr /* return r3 = status */