blob: 01cd5615c39981ddd06d41d4c0d95d2dbd28fbea [file] [log] [blame]
Patrick Williams8dd68482022-10-04 07:57:18 -05001From 7afe2370bc24b9003be8184fbd3169ebca03165a Mon Sep 17 00:00:00 2001
2From: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
3Date: Fri, 29 Jul 2022 13:06:19 +0100
4Subject: [PATCH 06/26] arm64: smccc: add support for SMCCCv1.2 x0-x17
5 registers
6
7add support for x0-x17 registers used by the SMC calls
8
9In SMCCC v1.2 [1] arguments are passed in registers x1-x17.
10Results are returned in x0-x17.
11
12This work is inspired from the following kernel commit:
13
14arm64: smccc: Add support for SMCCCv1.2 extended input/output registers
15
16[1]: https://documentation-service.arm.com/static/5f8edaeff86e16515cdbe4c6?token=
17
18Signed-off-by: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
19Upstream-Status: Submitted [cover letter: https://lore.kernel.org/all/20220926101723.9965-1-abdellatif.elkhlifi@arm.com/]
20
21---
22
23Changelog:
24===============
25
26v4:
27
28* rename the commit title and improve description
29 new commit title: the current
30
31v3:
32
33* port x0-x17 registers support from linux kernel as defined by SMCCCv1.2
34 commit title:
35 arm64: smccc: add Xn registers support used by SMC calls
36
37 arch/arm/cpu/armv8/smccc-call.S | 53 +++++++++++++++++++++++++++++++++
38 arch/arm/lib/asm-offsets.c | 13 ++++++++
39 include/linux/arm-smccc.h | 43 ++++++++++++++++++++++++++
40 3 files changed, 109 insertions(+)
41
42diff --git a/arch/arm/cpu/armv8/smccc-call.S b/arch/arm/cpu/armv8/smccc-call.S
43index dc92b28777..ec6f299bc9 100644
44--- a/arch/arm/cpu/armv8/smccc-call.S
45+++ b/arch/arm/cpu/armv8/smccc-call.S
46@@ -1,6 +1,8 @@
47 /* SPDX-License-Identifier: GPL-2.0 */
48 /*
49 * Copyright (c) 2015, Linaro Limited
50+ * (C) Copyright 2022 ARM Limited
51+ * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
52 */
53 #include <linux/linkage.h>
54 #include <linux/arm-smccc.h>
55@@ -45,3 +47,54 @@ ENDPROC(__arm_smccc_smc)
56 ENTRY(__arm_smccc_hvc)
57 SMCCC hvc
58 ENDPROC(__arm_smccc_hvc)
59+
60+#ifdef CONFIG_ARM64
61+
62+ .macro SMCCC_1_2 instr
63+ /* Save `res` and free a GPR that won't be clobbered */
64+ stp x1, x19, [sp, #-16]!
65+
66+ /* Ensure `args` won't be clobbered while loading regs in next step */
67+ mov x19, x0
68+
69+ /* Load the registers x0 - x17 from the struct arm_smccc_1_2_regs */
70+ ldp x0, x1, [x19, #ARM_SMCCC_1_2_REGS_X0_OFFS]
71+ ldp x2, x3, [x19, #ARM_SMCCC_1_2_REGS_X2_OFFS]
72+ ldp x4, x5, [x19, #ARM_SMCCC_1_2_REGS_X4_OFFS]
73+ ldp x6, x7, [x19, #ARM_SMCCC_1_2_REGS_X6_OFFS]
74+ ldp x8, x9, [x19, #ARM_SMCCC_1_2_REGS_X8_OFFS]
75+ ldp x10, x11, [x19, #ARM_SMCCC_1_2_REGS_X10_OFFS]
76+ ldp x12, x13, [x19, #ARM_SMCCC_1_2_REGS_X12_OFFS]
77+ ldp x14, x15, [x19, #ARM_SMCCC_1_2_REGS_X14_OFFS]
78+ ldp x16, x17, [x19, #ARM_SMCCC_1_2_REGS_X16_OFFS]
79+
80+ \instr #0
81+
82+ /* Load the `res` from the stack */
83+ ldr x19, [sp]
84+
85+ /* Store the registers x0 - x17 into the result structure */
86+ stp x0, x1, [x19, #ARM_SMCCC_1_2_REGS_X0_OFFS]
87+ stp x2, x3, [x19, #ARM_SMCCC_1_2_REGS_X2_OFFS]
88+ stp x4, x5, [x19, #ARM_SMCCC_1_2_REGS_X4_OFFS]
89+ stp x6, x7, [x19, #ARM_SMCCC_1_2_REGS_X6_OFFS]
90+ stp x8, x9, [x19, #ARM_SMCCC_1_2_REGS_X8_OFFS]
91+ stp x10, x11, [x19, #ARM_SMCCC_1_2_REGS_X10_OFFS]
92+ stp x12, x13, [x19, #ARM_SMCCC_1_2_REGS_X12_OFFS]
93+ stp x14, x15, [x19, #ARM_SMCCC_1_2_REGS_X14_OFFS]
94+ stp x16, x17, [x19, #ARM_SMCCC_1_2_REGS_X16_OFFS]
95+
96+ /* Restore original x19 */
97+ ldp xzr, x19, [sp], #16
98+ ret
99+ .endm
100+
101+/*
102+ * void arm_smccc_1_2_smc(const struct arm_smccc_1_2_regs *args,
103+ * struct arm_smccc_1_2_regs *res);
104+ */
105+ENTRY(arm_smccc_1_2_smc)
106+ SMCCC_1_2 smc
107+ENDPROC(arm_smccc_1_2_smc)
108+
109+#endif
110diff --git a/arch/arm/lib/asm-offsets.c b/arch/arm/lib/asm-offsets.c
111index 22fd541f9a..b6bd1b32b0 100644
112--- a/arch/arm/lib/asm-offsets.c
113+++ b/arch/arm/lib/asm-offsets.c
114@@ -9,6 +9,8 @@
115 * generate asm statements containing #defines,
116 * compile this file to assembler, and then extract the
117 * #defines from the assembly-language output.
118+ *
119+ * (C) Copyright 2022 ARM Limited
120 */
121
122 #include <common.h>
123@@ -117,6 +119,17 @@ int main(void)
124 DEFINE(ARM_SMCCC_RES_X2_OFFS, offsetof(struct arm_smccc_res, a2));
125 DEFINE(ARM_SMCCC_QUIRK_ID_OFFS, offsetof(struct arm_smccc_quirk, id));
126 DEFINE(ARM_SMCCC_QUIRK_STATE_OFFS, offsetof(struct arm_smccc_quirk, state));
127+ #ifdef CONFIG_ARM64
128+ DEFINE(ARM_SMCCC_1_2_REGS_X0_OFFS, offsetof(struct arm_smccc_1_2_regs, a0));
129+ DEFINE(ARM_SMCCC_1_2_REGS_X2_OFFS, offsetof(struct arm_smccc_1_2_regs, a2));
130+ DEFINE(ARM_SMCCC_1_2_REGS_X4_OFFS, offsetof(struct arm_smccc_1_2_regs, a4));
131+ DEFINE(ARM_SMCCC_1_2_REGS_X6_OFFS, offsetof(struct arm_smccc_1_2_regs, a6));
132+ DEFINE(ARM_SMCCC_1_2_REGS_X8_OFFS, offsetof(struct arm_smccc_1_2_regs, a8));
133+ DEFINE(ARM_SMCCC_1_2_REGS_X10_OFFS, offsetof(struct arm_smccc_1_2_regs, a10));
134+ DEFINE(ARM_SMCCC_1_2_REGS_X12_OFFS, offsetof(struct arm_smccc_1_2_regs, a12));
135+ DEFINE(ARM_SMCCC_1_2_REGS_X14_OFFS, offsetof(struct arm_smccc_1_2_regs, a14));
136+ DEFINE(ARM_SMCCC_1_2_REGS_X16_OFFS, offsetof(struct arm_smccc_1_2_regs, a16));
137+ #endif
138 #endif
139
140 return 0;
141diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h
142index 7f2be23394..dae58d3476 100644
143--- a/include/linux/arm-smccc.h
144+++ b/include/linux/arm-smccc.h
145@@ -1,6 +1,8 @@
146 /* SPDX-License-Identifier: GPL-2.0 */
147 /*
148 * Copyright (c) 2015, Linaro Limited
149+ * (C) Copyright 2022 ARM Limited
150+ * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
151 */
152 #ifndef __LINUX_ARM_SMCCC_H
153 #define __LINUX_ARM_SMCCC_H
154@@ -66,6 +68,47 @@ struct arm_smccc_res {
155 unsigned long a3;
156 };
157
158+#ifdef CONFIG_ARM64
159+/**
160+ * struct arm_smccc_1_2_regs - Arguments for or Results from SMC call
161+ * @a0-a17 argument values from registers 0 to 17
162+ */
163+struct arm_smccc_1_2_regs {
164+ unsigned long a0;
165+ unsigned long a1;
166+ unsigned long a2;
167+ unsigned long a3;
168+ unsigned long a4;
169+ unsigned long a5;
170+ unsigned long a6;
171+ unsigned long a7;
172+ unsigned long a8;
173+ unsigned long a9;
174+ unsigned long a10;
175+ unsigned long a11;
176+ unsigned long a12;
177+ unsigned long a13;
178+ unsigned long a14;
179+ unsigned long a15;
180+ unsigned long a16;
181+ unsigned long a17;
182+};
183+
184+/**
185+ * arm_smccc_1_2_smc() - make SMC calls
186+ * @args: arguments passed via struct arm_smccc_1_2_regs
187+ * @res: result values via struct arm_smccc_1_2_regs
188+ *
189+ * This function is used to make SMC calls following SMC Calling Convention
190+ * v1.2 or above. The content of the supplied param are copied from the
191+ * structure to registers prior to the SMC instruction. The return values
192+ * are updated with the content from registers on return from the SMC
193+ * instruction.
194+ */
195+asmlinkage void arm_smccc_1_2_smc(const struct arm_smccc_1_2_regs *args,
196+ struct arm_smccc_1_2_regs *res);
197+#endif
198+
199 /**
200 * struct arm_smccc_quirk - Contains quirk information
201 * @id: quirk identification
202--
2032.17.1
204