blob: 0e467a85c3404c0e7e4dcd0862cb38b45bed12af [file] [log] [blame]
Patrick Williams44b3caf2024-04-12 16:51:14 -05001From cc651db9a1370e697fd2525ce58b81ff7e112474 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 Williams44b3caf2024-04-12 16:51:14 -05004Subject: [PATCH] FF-A v15: arm64: smccc: add support for SMCCCv1.2 x0-x17
5 registers
Patrick Williams8dd68482022-10-04 07:57:18 -05006
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>
Patrick Williams2a254922023-08-11 09:48:11 -050019Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Andrew Geisslerea144b032023-01-27 16:03:57 -060020Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
Patrick Williams2a254922023-08-11 09:48:11 -050021Reviewed-by: Simon Glass <sjg@chromium.org>
Andrew Geisslerea144b032023-01-27 16:03:57 -060022Cc: Tom Rini <trini@konsulko.com>
Patrick Williams2a254922023-08-11 09:48:11 -050023Upstream-Status: Submitted [cover letter: https://lore.kernel.org/all/20230713132847.176000-1-abdellatif.elkhlifi@arm.com/]
Andrew Geisslerea144b032023-01-27 16:03:57 -060024---
Patrick Williams2a254922023-08-11 09:48:11 -050025 arch/arm/cpu/armv8/smccc-call.S | 57 ++++++++++++++++++++++++++++++++-
26 arch/arm/lib/asm-offsets.c | 16 +++++++++
27 include/linux/arm-smccc.h | 45 ++++++++++++++++++++++++++
28 3 files changed, 117 insertions(+), 1 deletion(-)
Patrick Williams8dd68482022-10-04 07:57:18 -050029
30diff --git a/arch/arm/cpu/armv8/smccc-call.S b/arch/arm/cpu/armv8/smccc-call.S
Patrick Williams2a254922023-08-11 09:48:11 -050031index dc92b28777..93f66d3366 100644
Patrick Williams8dd68482022-10-04 07:57:18 -050032--- a/arch/arm/cpu/armv8/smccc-call.S
33+++ b/arch/arm/cpu/armv8/smccc-call.S
Patrick Williams2a254922023-08-11 09:48:11 -050034@@ -1,7 +1,11 @@
Patrick Williams8dd68482022-10-04 07:57:18 -050035 /* SPDX-License-Identifier: GPL-2.0 */
36 /*
37 * Copyright (c) 2015, Linaro Limited
Patrick Williams2a254922023-08-11 09:48:11 -050038- */
39+ * Copyright 2022-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
40+ *
41+ * Authors:
42+ * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
43+*/
Patrick Williams8dd68482022-10-04 07:57:18 -050044 #include <linux/linkage.h>
45 #include <linux/arm-smccc.h>
Patrick Williams2a254922023-08-11 09:48:11 -050046 #include <generated/asm-offsets.h>
47@@ -45,3 +49,54 @@ ENDPROC(__arm_smccc_smc)
Patrick Williams8dd68482022-10-04 07:57:18 -050048 ENTRY(__arm_smccc_hvc)
49 SMCCC hvc
50 ENDPROC(__arm_smccc_hvc)
51+
52+#ifdef CONFIG_ARM64
53+
54+ .macro SMCCC_1_2 instr
55+ /* Save `res` and free a GPR that won't be clobbered */
56+ stp x1, x19, [sp, #-16]!
57+
58+ /* Ensure `args` won't be clobbered while loading regs in next step */
59+ mov x19, x0
60+
61+ /* Load the registers x0 - x17 from the struct arm_smccc_1_2_regs */
62+ ldp x0, x1, [x19, #ARM_SMCCC_1_2_REGS_X0_OFFS]
63+ ldp x2, x3, [x19, #ARM_SMCCC_1_2_REGS_X2_OFFS]
64+ ldp x4, x5, [x19, #ARM_SMCCC_1_2_REGS_X4_OFFS]
65+ ldp x6, x7, [x19, #ARM_SMCCC_1_2_REGS_X6_OFFS]
66+ ldp x8, x9, [x19, #ARM_SMCCC_1_2_REGS_X8_OFFS]
67+ ldp x10, x11, [x19, #ARM_SMCCC_1_2_REGS_X10_OFFS]
68+ ldp x12, x13, [x19, #ARM_SMCCC_1_2_REGS_X12_OFFS]
69+ ldp x14, x15, [x19, #ARM_SMCCC_1_2_REGS_X14_OFFS]
70+ ldp x16, x17, [x19, #ARM_SMCCC_1_2_REGS_X16_OFFS]
71+
72+ \instr #0
73+
74+ /* Load the `res` from the stack */
75+ ldr x19, [sp]
76+
77+ /* Store the registers x0 - x17 into the result structure */
78+ stp x0, x1, [x19, #ARM_SMCCC_1_2_REGS_X0_OFFS]
79+ stp x2, x3, [x19, #ARM_SMCCC_1_2_REGS_X2_OFFS]
80+ stp x4, x5, [x19, #ARM_SMCCC_1_2_REGS_X4_OFFS]
81+ stp x6, x7, [x19, #ARM_SMCCC_1_2_REGS_X6_OFFS]
82+ stp x8, x9, [x19, #ARM_SMCCC_1_2_REGS_X8_OFFS]
83+ stp x10, x11, [x19, #ARM_SMCCC_1_2_REGS_X10_OFFS]
84+ stp x12, x13, [x19, #ARM_SMCCC_1_2_REGS_X12_OFFS]
85+ stp x14, x15, [x19, #ARM_SMCCC_1_2_REGS_X14_OFFS]
86+ stp x16, x17, [x19, #ARM_SMCCC_1_2_REGS_X16_OFFS]
87+
88+ /* Restore original x19 */
89+ ldp xzr, x19, [sp], #16
90+ ret
91+ .endm
92+
93+/*
94+ * void arm_smccc_1_2_smc(const struct arm_smccc_1_2_regs *args,
95+ * struct arm_smccc_1_2_regs *res);
96+ */
97+ENTRY(arm_smccc_1_2_smc)
98+ SMCCC_1_2 smc
99+ENDPROC(arm_smccc_1_2_smc)
100+
101+#endif
102diff --git a/arch/arm/lib/asm-offsets.c b/arch/arm/lib/asm-offsets.c
Patrick Williams2a254922023-08-11 09:48:11 -0500103index 6de0ce9152..181a8ac4c2 100644
Patrick Williams8dd68482022-10-04 07:57:18 -0500104--- a/arch/arm/lib/asm-offsets.c
105+++ b/arch/arm/lib/asm-offsets.c
Patrick Williams2a254922023-08-11 09:48:11 -0500106@@ -9,6 +9,11 @@
Patrick Williams8dd68482022-10-04 07:57:18 -0500107 * generate asm statements containing #defines,
108 * compile this file to assembler, and then extract the
109 * #defines from the assembly-language output.
110+ *
Patrick Williams2a254922023-08-11 09:48:11 -0500111+ * Copyright 2022-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
112+ *
113+ * Authors:
114+ * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
Patrick Williams8dd68482022-10-04 07:57:18 -0500115 */
116
117 #include <common.h>
Patrick Williams2a254922023-08-11 09:48:11 -0500118@@ -90,6 +95,17 @@ int main(void)
Patrick Williams8dd68482022-10-04 07:57:18 -0500119 DEFINE(ARM_SMCCC_RES_X2_OFFS, offsetof(struct arm_smccc_res, a2));
120 DEFINE(ARM_SMCCC_QUIRK_ID_OFFS, offsetof(struct arm_smccc_quirk, id));
121 DEFINE(ARM_SMCCC_QUIRK_STATE_OFFS, offsetof(struct arm_smccc_quirk, state));
Andrew Geisslerea144b032023-01-27 16:03:57 -0600122+#ifdef CONFIG_ARM64
123+ DEFINE(ARM_SMCCC_1_2_REGS_X0_OFFS, offsetof(struct arm_smccc_1_2_regs, a0));
124+ DEFINE(ARM_SMCCC_1_2_REGS_X2_OFFS, offsetof(struct arm_smccc_1_2_regs, a2));
125+ DEFINE(ARM_SMCCC_1_2_REGS_X4_OFFS, offsetof(struct arm_smccc_1_2_regs, a4));
126+ DEFINE(ARM_SMCCC_1_2_REGS_X6_OFFS, offsetof(struct arm_smccc_1_2_regs, a6));
127+ DEFINE(ARM_SMCCC_1_2_REGS_X8_OFFS, offsetof(struct arm_smccc_1_2_regs, a8));
128+ DEFINE(ARM_SMCCC_1_2_REGS_X10_OFFS, offsetof(struct arm_smccc_1_2_regs, a10));
129+ DEFINE(ARM_SMCCC_1_2_REGS_X12_OFFS, offsetof(struct arm_smccc_1_2_regs, a12));
130+ DEFINE(ARM_SMCCC_1_2_REGS_X14_OFFS, offsetof(struct arm_smccc_1_2_regs, a14));
131+ DEFINE(ARM_SMCCC_1_2_REGS_X16_OFFS, offsetof(struct arm_smccc_1_2_regs, a16));
132+#endif
Patrick Williams8dd68482022-10-04 07:57:18 -0500133 #endif
134
135 return 0;
136diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h
Patrick Williams2a254922023-08-11 09:48:11 -0500137index e1d09884a1..f44e9e8f93 100644
Patrick Williams8dd68482022-10-04 07:57:18 -0500138--- a/include/linux/arm-smccc.h
139+++ b/include/linux/arm-smccc.h
Patrick Williams2a254922023-08-11 09:48:11 -0500140@@ -1,6 +1,10 @@
Patrick Williams8dd68482022-10-04 07:57:18 -0500141 /* SPDX-License-Identifier: GPL-2.0 */
142 /*
143 * Copyright (c) 2015, Linaro Limited
Patrick Williams2a254922023-08-11 09:48:11 -0500144+ * Copyright 2022-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
145+ *
146+ * Authors:
147+ * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
Patrick Williams8dd68482022-10-04 07:57:18 -0500148 */
149 #ifndef __LINUX_ARM_SMCCC_H
150 #define __LINUX_ARM_SMCCC_H
Patrick Williams2a254922023-08-11 09:48:11 -0500151@@ -70,6 +74,47 @@ struct arm_smccc_res {
Patrick Williams8dd68482022-10-04 07:57:18 -0500152 unsigned long a3;
153 };
154
155+#ifdef CONFIG_ARM64
156+/**
157+ * struct arm_smccc_1_2_regs - Arguments for or Results from SMC call
158+ * @a0-a17 argument values from registers 0 to 17
159+ */
160+struct arm_smccc_1_2_regs {
161+ unsigned long a0;
162+ unsigned long a1;
163+ unsigned long a2;
164+ unsigned long a3;
165+ unsigned long a4;
166+ unsigned long a5;
167+ unsigned long a6;
168+ unsigned long a7;
169+ unsigned long a8;
170+ unsigned long a9;
171+ unsigned long a10;
172+ unsigned long a11;
173+ unsigned long a12;
174+ unsigned long a13;
175+ unsigned long a14;
176+ unsigned long a15;
177+ unsigned long a16;
178+ unsigned long a17;
179+};
180+
181+/**
182+ * arm_smccc_1_2_smc() - make SMC calls
183+ * @args: arguments passed via struct arm_smccc_1_2_regs
184+ * @res: result values via struct arm_smccc_1_2_regs
185+ *
186+ * This function is used to make SMC calls following SMC Calling Convention
187+ * v1.2 or above. The content of the supplied param are copied from the
188+ * structure to registers prior to the SMC instruction. The return values
189+ * are updated with the content from registers on return from the SMC
190+ * instruction.
191+ */
192+asmlinkage void arm_smccc_1_2_smc(const struct arm_smccc_1_2_regs *args,
193+ struct arm_smccc_1_2_regs *res);
194+#endif
195+
196 /**
197 * struct arm_smccc_quirk - Contains quirk information
198 * @id: quirk identification