blob: 93f66d336681eac7a26fb9913a15376c87cf1cce [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0 */
Masahiro Yamadaa93297e2017-04-14 11:10:22 +09002/*
3 * Copyright (c) 2015, Linaro Limited
Abdellatif El Khlifi0b77c1d2023-08-04 14:33:37 +01004 * Copyright 2022-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
5 *
6 * Authors:
7 * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
8*/
Masahiro Yamadaa93297e2017-04-14 11:10:22 +09009#include <linux/linkage.h>
10#include <linux/arm-smccc.h>
Masahiro Yamadae8ead732017-04-14 11:10:23 +090011#include <generated/asm-offsets.h>
Masahiro Yamadaa93297e2017-04-14 11:10:22 +090012
Alexander Graf449c8b22019-02-11 15:07:17 +010013#ifdef CONFIG_EFI_LOADER
Heinrich Schuchardt26f09d02018-10-18 12:29:40 +020014 .section .text.efi_runtime
Alexander Graf449c8b22019-02-11 15:07:17 +010015#endif
Heinrich Schuchardt26f09d02018-10-18 12:29:40 +020016
Masahiro Yamadaa93297e2017-04-14 11:10:22 +090017 .macro SMCCC instr
18 .cfi_startproc
19 \instr #0
20 ldr x4, [sp]
21 stp x0, x1, [x4, #ARM_SMCCC_RES_X0_OFFS]
22 stp x2, x3, [x4, #ARM_SMCCC_RES_X2_OFFS]
23 ldr x4, [sp, #8]
24 cbz x4, 1f /* no quirk structure */
25 ldr x9, [x4, #ARM_SMCCC_QUIRK_ID_OFFS]
26 cmp x9, #ARM_SMCCC_QUIRK_QCOM_A6
27 b.ne 1f
28 str x6, [x4, ARM_SMCCC_QUIRK_STATE_OFFS]
291: ret
30 .cfi_endproc
31 .endm
32
33/*
34 * void arm_smccc_smc(unsigned long a0, unsigned long a1, unsigned long a2,
35 * unsigned long a3, unsigned long a4, unsigned long a5,
36 * unsigned long a6, unsigned long a7, struct arm_smccc_res *res,
37 * struct arm_smccc_quirk *quirk)
38 */
39ENTRY(__arm_smccc_smc)
40 SMCCC smc
41ENDPROC(__arm_smccc_smc)
42
43/*
44 * void arm_smccc_hvc(unsigned long a0, unsigned long a1, unsigned long a2,
45 * unsigned long a3, unsigned long a4, unsigned long a5,
46 * unsigned long a6, unsigned long a7, struct arm_smccc_res *res,
47 * struct arm_smccc_quirk *quirk)
48 */
49ENTRY(__arm_smccc_hvc)
50 SMCCC hvc
51ENDPROC(__arm_smccc_hvc)
Abdellatif El Khlifi0b77c1d2023-08-04 14:33:37 +010052
53#ifdef CONFIG_ARM64
54
55 .macro SMCCC_1_2 instr
56 /* Save `res` and free a GPR that won't be clobbered */
57 stp x1, x19, [sp, #-16]!
58
59 /* Ensure `args` won't be clobbered while loading regs in next step */
60 mov x19, x0
61
62 /* Load the registers x0 - x17 from the struct arm_smccc_1_2_regs */
63 ldp x0, x1, [x19, #ARM_SMCCC_1_2_REGS_X0_OFFS]
64 ldp x2, x3, [x19, #ARM_SMCCC_1_2_REGS_X2_OFFS]
65 ldp x4, x5, [x19, #ARM_SMCCC_1_2_REGS_X4_OFFS]
66 ldp x6, x7, [x19, #ARM_SMCCC_1_2_REGS_X6_OFFS]
67 ldp x8, x9, [x19, #ARM_SMCCC_1_2_REGS_X8_OFFS]
68 ldp x10, x11, [x19, #ARM_SMCCC_1_2_REGS_X10_OFFS]
69 ldp x12, x13, [x19, #ARM_SMCCC_1_2_REGS_X12_OFFS]
70 ldp x14, x15, [x19, #ARM_SMCCC_1_2_REGS_X14_OFFS]
71 ldp x16, x17, [x19, #ARM_SMCCC_1_2_REGS_X16_OFFS]
72
73 \instr #0
74
75 /* Load the `res` from the stack */
76 ldr x19, [sp]
77
78 /* Store the registers x0 - x17 into the result structure */
79 stp x0, x1, [x19, #ARM_SMCCC_1_2_REGS_X0_OFFS]
80 stp x2, x3, [x19, #ARM_SMCCC_1_2_REGS_X2_OFFS]
81 stp x4, x5, [x19, #ARM_SMCCC_1_2_REGS_X4_OFFS]
82 stp x6, x7, [x19, #ARM_SMCCC_1_2_REGS_X6_OFFS]
83 stp x8, x9, [x19, #ARM_SMCCC_1_2_REGS_X8_OFFS]
84 stp x10, x11, [x19, #ARM_SMCCC_1_2_REGS_X10_OFFS]
85 stp x12, x13, [x19, #ARM_SMCCC_1_2_REGS_X12_OFFS]
86 stp x14, x15, [x19, #ARM_SMCCC_1_2_REGS_X14_OFFS]
87 stp x16, x17, [x19, #ARM_SMCCC_1_2_REGS_X16_OFFS]
88
89 /* Restore original x19 */
90 ldp xzr, x19, [sp], #16
91 ret
92 .endm
93
94/*
95 * void arm_smccc_1_2_smc(const struct arm_smccc_1_2_regs *args,
96 * struct arm_smccc_1_2_regs *res);
97 */
98ENTRY(arm_smccc_1_2_smc)
99 SMCCC_1_2 smc
100ENDPROC(arm_smccc_1_2_smc)
101
102#endif