blob: 64c1b95bbc5b61bbad263f115c5b167f58aca0c1 [file] [log] [blame]
Patrick Williams864cc432023-02-09 14:54:44 -06001From f1f1780630302e1d7cab95d1c6dc32e2fc0bdd70 Mon Sep 17 00:00:00 2001
Patrick Williams8dd68482022-10-04 07:57:18 -05002From: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
3Date: Fri, 29 Jul 2022 13:06:19 +0100
Patrick Williams864cc432023-02-09 14:54:44 -06004Subject: [PATCH 01/27] arm64: smccc: add support for SMCCCv1.2 x0-x17
Patrick Williams8dd68482022-10-04 07:57:18 -05005 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>
Andrew Geisslerea144b032023-01-27 16:03:57 -060019Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
20Cc: Tom Rini <trini@konsulko.com>
21Cc: Simon Glass <sjg@chromium.org>
22Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
23Upstream-Status: Submitted [cover letter: https://lore.kernel.org/all/20221122131751.22747-1-abdellatif.elkhlifi@arm.com/]
Patrick Williams8dd68482022-10-04 07:57:18 -050024
25Changelog:
26===============
27
Andrew Geisslerea144b032023-01-27 16:03:57 -060028v7:
29
30* improve indentation of ARM_SMCCC_1_2_REGS_Xn_OFFS
31
Patrick Williams8dd68482022-10-04 07:57:18 -050032v4:
33
34* rename the commit title and improve description
35 new commit title: the current
36
37v3:
38
39* port x0-x17 registers support from linux kernel as defined by SMCCCv1.2
40 commit title:
41 arm64: smccc: add Xn registers support used by SMC calls
Patrick Williams864cc432023-02-09 14:54:44 -060042
43Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Andrew Geisslerea144b032023-01-27 16:03:57 -060044---
Patrick Williams8dd68482022-10-04 07:57:18 -050045 arch/arm/cpu/armv8/smccc-call.S | 53 +++++++++++++++++++++++++++++++++
Andrew Geisslerea144b032023-01-27 16:03:57 -060046 arch/arm/lib/asm-offsets.c | 14 +++++++++
Patrick Williams8dd68482022-10-04 07:57:18 -050047 include/linux/arm-smccc.h | 43 ++++++++++++++++++++++++++
Andrew Geisslerea144b032023-01-27 16:03:57 -060048 3 files changed, 110 insertions(+)
Patrick Williams8dd68482022-10-04 07:57:18 -050049
50diff --git a/arch/arm/cpu/armv8/smccc-call.S b/arch/arm/cpu/armv8/smccc-call.S
Patrick Williams864cc432023-02-09 14:54:44 -060051index dc92b28777c3..ec6f299bc929 100644
Patrick Williams8dd68482022-10-04 07:57:18 -050052--- a/arch/arm/cpu/armv8/smccc-call.S
53+++ b/arch/arm/cpu/armv8/smccc-call.S
54@@ -1,6 +1,8 @@
55 /* SPDX-License-Identifier: GPL-2.0 */
56 /*
57 * Copyright (c) 2015, Linaro Limited
58+ * (C) Copyright 2022 ARM Limited
59+ * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
60 */
61 #include <linux/linkage.h>
62 #include <linux/arm-smccc.h>
63@@ -45,3 +47,54 @@ ENDPROC(__arm_smccc_smc)
64 ENTRY(__arm_smccc_hvc)
65 SMCCC hvc
66 ENDPROC(__arm_smccc_hvc)
67+
68+#ifdef CONFIG_ARM64
69+
70+ .macro SMCCC_1_2 instr
71+ /* Save `res` and free a GPR that won't be clobbered */
72+ stp x1, x19, [sp, #-16]!
73+
74+ /* Ensure `args` won't be clobbered while loading regs in next step */
75+ mov x19, x0
76+
77+ /* Load the registers x0 - x17 from the struct arm_smccc_1_2_regs */
78+ ldp x0, x1, [x19, #ARM_SMCCC_1_2_REGS_X0_OFFS]
79+ ldp x2, x3, [x19, #ARM_SMCCC_1_2_REGS_X2_OFFS]
80+ ldp x4, x5, [x19, #ARM_SMCCC_1_2_REGS_X4_OFFS]
81+ ldp x6, x7, [x19, #ARM_SMCCC_1_2_REGS_X6_OFFS]
82+ ldp x8, x9, [x19, #ARM_SMCCC_1_2_REGS_X8_OFFS]
83+ ldp x10, x11, [x19, #ARM_SMCCC_1_2_REGS_X10_OFFS]
84+ ldp x12, x13, [x19, #ARM_SMCCC_1_2_REGS_X12_OFFS]
85+ ldp x14, x15, [x19, #ARM_SMCCC_1_2_REGS_X14_OFFS]
86+ ldp x16, x17, [x19, #ARM_SMCCC_1_2_REGS_X16_OFFS]
87+
88+ \instr #0
89+
90+ /* Load the `res` from the stack */
91+ ldr x19, [sp]
92+
93+ /* Store the registers x0 - x17 into the result structure */
94+ stp x0, x1, [x19, #ARM_SMCCC_1_2_REGS_X0_OFFS]
95+ stp x2, x3, [x19, #ARM_SMCCC_1_2_REGS_X2_OFFS]
96+ stp x4, x5, [x19, #ARM_SMCCC_1_2_REGS_X4_OFFS]
97+ stp x6, x7, [x19, #ARM_SMCCC_1_2_REGS_X6_OFFS]
98+ stp x8, x9, [x19, #ARM_SMCCC_1_2_REGS_X8_OFFS]
99+ stp x10, x11, [x19, #ARM_SMCCC_1_2_REGS_X10_OFFS]
100+ stp x12, x13, [x19, #ARM_SMCCC_1_2_REGS_X12_OFFS]
101+ stp x14, x15, [x19, #ARM_SMCCC_1_2_REGS_X14_OFFS]
102+ stp x16, x17, [x19, #ARM_SMCCC_1_2_REGS_X16_OFFS]
103+
104+ /* Restore original x19 */
105+ ldp xzr, x19, [sp], #16
106+ ret
107+ .endm
108+
109+/*
110+ * void arm_smccc_1_2_smc(const struct arm_smccc_1_2_regs *args,
111+ * struct arm_smccc_1_2_regs *res);
112+ */
113+ENTRY(arm_smccc_1_2_smc)
114+ SMCCC_1_2 smc
115+ENDPROC(arm_smccc_1_2_smc)
116+
117+#endif
118diff --git a/arch/arm/lib/asm-offsets.c b/arch/arm/lib/asm-offsets.c
Patrick Williams864cc432023-02-09 14:54:44 -0600119index 22fd541f9a28..db6d7ed23428 100644
Patrick Williams8dd68482022-10-04 07:57:18 -0500120--- a/arch/arm/lib/asm-offsets.c
121+++ b/arch/arm/lib/asm-offsets.c
Andrew Geisslerea144b032023-01-27 16:03:57 -0600122@@ -9,6 +9,9 @@
Patrick Williams8dd68482022-10-04 07:57:18 -0500123 * generate asm statements containing #defines,
124 * compile this file to assembler, and then extract the
125 * #defines from the assembly-language output.
126+ *
127+ * (C) Copyright 2022 ARM Limited
Andrew Geisslerea144b032023-01-27 16:03:57 -0600128+ * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
Patrick Williams8dd68482022-10-04 07:57:18 -0500129 */
130
131 #include <common.h>
Andrew Geisslerea144b032023-01-27 16:03:57 -0600132@@ -117,6 +120,17 @@ int main(void)
Patrick Williams8dd68482022-10-04 07:57:18 -0500133 DEFINE(ARM_SMCCC_RES_X2_OFFS, offsetof(struct arm_smccc_res, a2));
134 DEFINE(ARM_SMCCC_QUIRK_ID_OFFS, offsetof(struct arm_smccc_quirk, id));
135 DEFINE(ARM_SMCCC_QUIRK_STATE_OFFS, offsetof(struct arm_smccc_quirk, state));
Andrew Geisslerea144b032023-01-27 16:03:57 -0600136+#ifdef CONFIG_ARM64
137+ DEFINE(ARM_SMCCC_1_2_REGS_X0_OFFS, offsetof(struct arm_smccc_1_2_regs, a0));
138+ DEFINE(ARM_SMCCC_1_2_REGS_X2_OFFS, offsetof(struct arm_smccc_1_2_regs, a2));
139+ DEFINE(ARM_SMCCC_1_2_REGS_X4_OFFS, offsetof(struct arm_smccc_1_2_regs, a4));
140+ DEFINE(ARM_SMCCC_1_2_REGS_X6_OFFS, offsetof(struct arm_smccc_1_2_regs, a6));
141+ DEFINE(ARM_SMCCC_1_2_REGS_X8_OFFS, offsetof(struct arm_smccc_1_2_regs, a8));
142+ DEFINE(ARM_SMCCC_1_2_REGS_X10_OFFS, offsetof(struct arm_smccc_1_2_regs, a10));
143+ DEFINE(ARM_SMCCC_1_2_REGS_X12_OFFS, offsetof(struct arm_smccc_1_2_regs, a12));
144+ DEFINE(ARM_SMCCC_1_2_REGS_X14_OFFS, offsetof(struct arm_smccc_1_2_regs, a14));
145+ DEFINE(ARM_SMCCC_1_2_REGS_X16_OFFS, offsetof(struct arm_smccc_1_2_regs, a16));
146+#endif
Patrick Williams8dd68482022-10-04 07:57:18 -0500147 #endif
148
149 return 0;
150diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h
Patrick Williams864cc432023-02-09 14:54:44 -0600151index e1d09884a1c5..9105031d55d3 100644
Patrick Williams8dd68482022-10-04 07:57:18 -0500152--- a/include/linux/arm-smccc.h
153+++ b/include/linux/arm-smccc.h
154@@ -1,6 +1,8 @@
155 /* SPDX-License-Identifier: GPL-2.0 */
156 /*
157 * Copyright (c) 2015, Linaro Limited
158+ * (C) Copyright 2022 ARM Limited
159+ * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
160 */
161 #ifndef __LINUX_ARM_SMCCC_H
162 #define __LINUX_ARM_SMCCC_H
Andrew Geisslerea144b032023-01-27 16:03:57 -0600163@@ -70,6 +72,47 @@ struct arm_smccc_res {
Patrick Williams8dd68482022-10-04 07:57:18 -0500164 unsigned long a3;
165 };
166
167+#ifdef CONFIG_ARM64
168+/**
169+ * struct arm_smccc_1_2_regs - Arguments for or Results from SMC call
170+ * @a0-a17 argument values from registers 0 to 17
171+ */
172+struct arm_smccc_1_2_regs {
173+ unsigned long a0;
174+ unsigned long a1;
175+ unsigned long a2;
176+ unsigned long a3;
177+ unsigned long a4;
178+ unsigned long a5;
179+ unsigned long a6;
180+ unsigned long a7;
181+ unsigned long a8;
182+ unsigned long a9;
183+ unsigned long a10;
184+ unsigned long a11;
185+ unsigned long a12;
186+ unsigned long a13;
187+ unsigned long a14;
188+ unsigned long a15;
189+ unsigned long a16;
190+ unsigned long a17;
191+};
192+
193+/**
194+ * arm_smccc_1_2_smc() - make SMC calls
195+ * @args: arguments passed via struct arm_smccc_1_2_regs
196+ * @res: result values via struct arm_smccc_1_2_regs
197+ *
198+ * This function is used to make SMC calls following SMC Calling Convention
199+ * v1.2 or above. The content of the supplied param are copied from the
200+ * structure to registers prior to the SMC instruction. The return values
201+ * are updated with the content from registers on return from the SMC
202+ * instruction.
203+ */
204+asmlinkage void arm_smccc_1_2_smc(const struct arm_smccc_1_2_regs *args,
205+ struct arm_smccc_1_2_regs *res);
206+#endif
207+
208 /**
209 * struct arm_smccc_quirk - Contains quirk information
210 * @id: quirk identification
211--
Patrick Williams864cc432023-02-09 14:54:44 -06002122.39.1
Patrick Williams8dd68482022-10-04 07:57:18 -0500213