blob: 44afdd56f0afbd081307a9b44b2d61389315a5a9 [file] [log] [blame]
Andrew Geisslerea144b032023-01-27 16:03:57 -06001From e9ec690a3f0d34631729a17c1734d66111e768e1 Mon Sep 17 00:00:00 2001
Brad Bishopbec4ebc2022-08-03 09:55:16 -04002From: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
Patrick Williams8dd68482022-10-04 07:57:18 -05003Date: Mon, 6 Jun 2022 12:46:38 +0100
Andrew Geisslerea144b032023-01-27 16:03:57 -06004Subject: [PATCH 05/25] arm_ffa: introduce armffa command
Brad Bishopbec4ebc2022-08-03 09:55:16 -04005
Patrick Williams8dd68482022-10-04 07:57:18 -05006Provide armffa command showcasing the use of the FF-A driver
Brad Bishopbec4ebc2022-08-03 09:55:16 -04007
8The armffa command allows to query secure partitions data from
Andrew Geisslerea144b032023-01-27 16:03:57 -06009the secure world and exchanging messages with the partitions
10using 64-bit FF-A direct messaging.
Brad Bishopbec4ebc2022-08-03 09:55:16 -040011
12Signed-off-by: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
Andrew Geisslerea144b032023-01-27 16:03:57 -060013Cc: Tom Rini <trini@konsulko.com>
14Cc: Simon Glass <sjg@chromium.org>
15Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
16Cc: Jens Wiklander <jens.wiklander@linaro.org>
17Upstream-Status: Submitted [cover letter: https://lore.kernel.org/all/20221122131751.22747-1-abdellatif.elkhlifi@arm.com/]
Patrick Williams8dd68482022-10-04 07:57:18 -050018
19Changelog:
20===============
21
Andrew Geisslerea144b032023-01-27 16:03:57 -060022v8:
23
24* update partition_info_get() second argument to be an SP count
25* pass NULL device pointer to the FF-A bus discovery and operations
26
27v7:
28
29* adapt do_ffa_dev_list() following the recent update on
30 uclass_first_device/uclass_next_device functions (they return void now)
31* set armffa command to use 64-bit direct messaging
32
Patrick Williams8dd68482022-10-04 07:57:18 -050033v4:
34
35* remove pattern data in do_ffa_msg_send_direct_req
36
37v3:
38
39* use the new driver interfaces (partition_info_get, sync_send_receive)
40 in armffa command
41
42v2:
43
44* replace use of ffa_helper_init_device function by
45 ffa_helper_bus_discover
46
47v1:
48
49* introduce armffa command
Andrew Geisslerea144b032023-01-27 16:03:57 -060050---
Patrick Williams8dd68482022-10-04 07:57:18 -050051 MAINTAINERS | 1 +
52 cmd/Kconfig | 10 ++
53 cmd/Makefile | 2 +
Andrew Geisslerea144b032023-01-27 16:03:57 -060054 cmd/armffa.c | 237 +++++++++++++++++++++++++++++++
Patrick Williams8dd68482022-10-04 07:57:18 -050055 drivers/firmware/arm-ffa/Kconfig | 1 +
Andrew Geisslerea144b032023-01-27 16:03:57 -060056 5 files changed, 251 insertions(+)
Brad Bishopbec4ebc2022-08-03 09:55:16 -040057 create mode 100644 cmd/armffa.c
58
59diff --git a/MAINTAINERS b/MAINTAINERS
Andrew Geisslerea144b032023-01-27 16:03:57 -060060index 734fcb10c4..d50bdddea8 100644
Brad Bishopbec4ebc2022-08-03 09:55:16 -040061--- a/MAINTAINERS
62+++ b/MAINTAINERS
Andrew Geisslerea144b032023-01-27 16:03:57 -060063@@ -251,6 +251,7 @@ F: configs/cortina_presidio-asic-pnand_defconfig
Brad Bishopbec4ebc2022-08-03 09:55:16 -040064 ARM FF-A
65 M: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
66 S: Maintained
67+F: cmd/armffa.c
Andrew Geisslerea144b032023-01-27 16:03:57 -060068 F: doc/arch/arm64.ffa.rst
Patrick Williams8dd68482022-10-04 07:57:18 -050069 F: drivers/firmware/arm-ffa/
Brad Bishopbec4ebc2022-08-03 09:55:16 -040070 F: include/arm_ffa.h
Brad Bishopbec4ebc2022-08-03 09:55:16 -040071diff --git a/cmd/Kconfig b/cmd/Kconfig
Andrew Geisslerea144b032023-01-27 16:03:57 -060072index 0e0be94f41..013d4c3da7 100644
Brad Bishopbec4ebc2022-08-03 09:55:16 -040073--- a/cmd/Kconfig
74+++ b/cmd/Kconfig
Andrew Geisslerea144b032023-01-27 16:03:57 -060075@@ -912,6 +912,16 @@ endmenu
Brad Bishopbec4ebc2022-08-03 09:55:16 -040076
77 menu "Device access commands"
78
79+config CMD_ARMFFA
80+ bool "Arm FF-A test command"
81+ depends on ARM_FFA_TRANSPORT
82+ help
83+ Provides a test command for the Arm FF-A driver
84+ supported options:
85+ - Listing the partition(s) info
86+ - Sending a data pattern to the specified partition
87+ - Displaying the arm_ffa device info
88+
89 config CMD_ARMFLASH
90 #depends on FLASH_CFI_DRIVER
91 bool "armflash"
92diff --git a/cmd/Makefile b/cmd/Makefile
Andrew Geisslerea144b032023-01-27 16:03:57 -060093index 6e87522b62..979c6d59df 100644
Brad Bishopbec4ebc2022-08-03 09:55:16 -040094--- a/cmd/Makefile
95+++ b/cmd/Makefile
96@@ -12,6 +12,8 @@ obj-y += panic.o
97 obj-y += version.o
98
99 # command
100+
101+obj-$(CONFIG_CMD_ARMFFA) += armffa.o
102 obj-$(CONFIG_CMD_ACPI) += acpi.o
103 obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o
104 obj-$(CONFIG_CMD_AES) += aes.o
105diff --git a/cmd/armffa.c b/cmd/armffa.c
106new file mode 100644
Andrew Geisslerea144b032023-01-27 16:03:57 -0600107index 0000000000..d2e8687bfb
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400108--- /dev/null
109+++ b/cmd/armffa.c
Andrew Geisslerea144b032023-01-27 16:03:57 -0600110@@ -0,0 +1,237 @@
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400111+// SPDX-License-Identifier: GPL-2.0+
112+/*
Patrick Williams8dd68482022-10-04 07:57:18 -0500113+ * (C) Copyright 2022 ARM Limited
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400114+ * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
115+ */
116+
Patrick Williams8dd68482022-10-04 07:57:18 -0500117+#include <arm_ffa.h>
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400118+#include <asm/io.h>
119+#include <common.h>
120+#include <command.h>
121+#include <dm.h>
122+#include <mapmem.h>
123+#include <stdlib.h>
124+
125+/**
126+ * do_ffa_get_singular_partition_info - implementation of the getpart subcommand
127+ * @cmdtp: Command Table
128+ * @flag: flags
129+ * @argc: number of arguments
130+ * @argv: arguments
131+ *
132+ * This function queries the secure partition information which the UUID is provided
Patrick Williams8dd68482022-10-04 07:57:18 -0500133+ * as an argument. The function uses the arm_ffa driver partition_info_get operation
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400134+ * to retrieve the data.
135+ * The input UUID string is expected to be in big endian format.
136+ *
137+ * Return:
138+ *
139+ * CMD_RET_SUCCESS: on success, otherwise failure
140+ */
141+static int do_ffa_get_singular_partition_info(struct cmd_tbl *cmdtp, int flag, int argc,
142+ char *const argv[])
143+{
Andrew Geisslerea144b032023-01-27 16:03:57 -0600144+ u32 count = 0;
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400145+ int ret;
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400146+ struct ffa_partition_info *parts_info;
147+ u32 info_idx;
148+
149+ if (argc != 1)
150+ return -EINVAL;
151+
Patrick Williams8dd68482022-10-04 07:57:18 -0500152+ /* Mode 1: getting the number of secure partitions */
Andrew Geisslerea144b032023-01-27 16:03:57 -0600153+ ret = ffa_bus_ops_get()->partition_info_get(NULL, argv[0], &count, NULL);
Patrick Williams8dd68482022-10-04 07:57:18 -0500154+ if (ret != 0) {
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400155+ ffa_err("Failure in querying partitions count (error code: %d)", ret);
156+ return ret;
157+ }
158+
159+ if (!count) {
160+ ffa_info("No secure partition found");
161+ return ret;
162+ }
163+
164+ /*
165+ * pre-allocate a buffer to be filled by the driver
Patrick Williams8dd68482022-10-04 07:57:18 -0500166+ * with ffa_partition_info structs
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400167+ */
168+
Patrick Williams8dd68482022-10-04 07:57:18 -0500169+ ffa_info("Pre-allocating %d partition(s) info structures", count);
170+
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400171+ parts_info = calloc(count, sizeof(struct ffa_partition_info));
172+ if (!parts_info)
173+ return -EINVAL;
174+
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400175+ /*
176+ * ask the driver to fill the buffer with the SPs info
177+ */
Patrick Williams8dd68482022-10-04 07:57:18 -0500178+
Andrew Geisslerea144b032023-01-27 16:03:57 -0600179+ ret = ffa_bus_ops_get()->partition_info_get(NULL, argv[0], &count, parts_info);
Patrick Williams8dd68482022-10-04 07:57:18 -0500180+ if (ret != 0) {
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400181+ ffa_err("Failure in querying partition(s) info (error code: %d)", ret);
182+ free(parts_info);
183+ return ret;
184+ }
185+
186+ /*
187+ * SPs found , show the partition information
188+ */
189+ for (info_idx = 0; info_idx < count ; info_idx++) {
190+ ffa_info("Partition: id = 0x%x , exec_ctxt 0x%x , properties 0x%x",
191+ parts_info[info_idx].id,
192+ parts_info[info_idx].exec_ctxt,
193+ parts_info[info_idx].properties);
194+ }
195+
196+ free(parts_info);
197+
198+ return 0;
199+}
200+
201+/**
202+ * do_ffa_msg_send_direct_req - implementation of the ping subcommand
203+ * @cmdtp: Command Table
204+ * @flag: flags
205+ * @argc: number of arguments
206+ * @argv: arguments
207+ *
208+ * This function sends data to the secure partition which the ID is provided
Patrick Williams8dd68482022-10-04 07:57:18 -0500209+ * as an argument. The function uses the arm_ffa driver sync_send_receive operation
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400210+ * to send data.
211+ *
212+ * Return:
213+ *
214+ * CMD_RET_SUCCESS: on success, otherwise failure
215+ */
216+int do_ffa_msg_send_direct_req(struct cmd_tbl *cmdtp, int flag, int argc,
217+ char *const argv[])
218+{
Patrick Williams8dd68482022-10-04 07:57:18 -0500219+ struct ffa_send_direct_data msg = {
220+ .data0 = 0xaaaaaaaa,
221+ .data1 = 0xbbbbbbbb,
222+ .data2 = 0xcccccccc,
223+ .data3 = 0xdddddddd,
224+ .data4 = 0xeeeeeeee,
225+ };
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400226+ u16 part_id;
227+ int ret;
228+
229+ if (argc != 1)
230+ return -EINVAL;
231+
232+ errno = 0;
233+ part_id = strtoul(argv[0], NULL, 16);
234+
235+ if (errno) {
236+ ffa_err("Invalid partition ID");
237+ return -EINVAL;
238+ }
239+
Andrew Geisslerea144b032023-01-27 16:03:57 -0600240+ ret = ffa_bus_ops_get()->sync_send_receive(NULL, part_id, &msg, 1);
Patrick Williams8dd68482022-10-04 07:57:18 -0500241+ if (ret == 0) {
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400242+ u8 cnt;
243+
244+ ffa_info("SP response:\n[LSB]");
245+ for (cnt = 0;
Patrick Williams8dd68482022-10-04 07:57:18 -0500246+ cnt < sizeof(struct ffa_send_direct_data) / sizeof(u64);
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400247+ cnt++)
Patrick Williams8dd68482022-10-04 07:57:18 -0500248+ ffa_info("0x%llx", ((u64 *)&msg)[cnt]);
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400249+ } else {
250+ ffa_err("Sending direct request error (%d)", ret);
251+ }
252+
253+ return ret;
254+}
255+
256+/**
257+ *do_ffa_dev_list - implementation of the devlist subcommand
258+ * @cmdtp: [in] Command Table
259+ * @flag: flags
260+ * @argc: number of arguments
261+ * @argv: arguments
262+ *
263+ * This function queries the devices belonging to the UCLASS_FFA
264+ * class. Currently, one device is expected to show up: the arm_ffa device
265+ *
266+ * Return:
267+ *
268+ * CMD_RET_SUCCESS: on success, otherwise failure
269+ */
270+int do_ffa_dev_list(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
271+{
272+ struct udevice *dev = NULL;
Andrew Geisslerea144b032023-01-27 16:03:57 -0600273+ int i;
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400274+
275+ ffa_info("arm_ffa uclass entries:");
276+
Andrew Geisslerea144b032023-01-27 16:03:57 -0600277+ for (i = 0, uclass_first_device(UCLASS_FFA, &dev);
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400278+ dev;
Andrew Geisslerea144b032023-01-27 16:03:57 -0600279+ uclass_next_device(&dev), i++) {
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400280+ ffa_info("entry %d - instance %08x, ops %08x, plat %08x",
281+ i,
282+ (u32)map_to_sysmem(dev),
283+ (u32)map_to_sysmem(dev->driver->ops),
284+ (u32)map_to_sysmem(dev_get_plat(dev)));
285+ }
286+
Andrew Geisslerea144b032023-01-27 16:03:57 -0600287+ return 0;
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400288+}
289+
290+static struct cmd_tbl armffa_commands[] = {
291+ U_BOOT_CMD_MKENT(getpart, 1, 1, do_ffa_get_singular_partition_info, "", ""),
292+ U_BOOT_CMD_MKENT(ping, 1, 1, do_ffa_msg_send_direct_req, "", ""),
293+ U_BOOT_CMD_MKENT(devlist, 0, 1, do_ffa_dev_list, "", ""),
294+};
295+
296+/**
297+ * do_armffa - the armffa command main function
298+ * @cmdtp: Command Table
299+ * @flag: flags
300+ * @argc: number of arguments
301+ * @argv: arguments
302+ *
303+ * This function identifies which armffa subcommand to run.
304+ * Then, it makes sure the arm_ffa device is probed and
305+ * ready for use.
306+ * Then, it runs the subcommand.
307+ *
308+ * Return:
309+ *
310+ * CMD_RET_SUCCESS: on success, otherwise failure
311+ */
312+static int do_armffa(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
313+{
314+ struct cmd_tbl *armffa_cmd;
315+ int ret;
316+
317+ if (argc < 2)
318+ return CMD_RET_USAGE;
319+
320+ armffa_cmd = find_cmd_tbl(argv[1], armffa_commands, ARRAY_SIZE(armffa_commands));
321+
322+ argc -= 2;
323+ argv += 2;
324+
325+ if (!armffa_cmd || argc > armffa_cmd->maxargs)
326+ return CMD_RET_USAGE;
327+
Andrew Geisslerea144b032023-01-27 16:03:57 -0600328+ ret = ffa_bus_discover(NULL);
Patrick Williams8dd68482022-10-04 07:57:18 -0500329+ if (ret != 0)
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400330+ return cmd_process_error(cmdtp, ret);
331+
Patrick Williams8dd68482022-10-04 07:57:18 -0500332+ if (!ffa_bus_ops_get())
333+ return -EINVAL;
334+
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400335+ ret = armffa_cmd->cmd(armffa_cmd, flag, argc, argv);
336+
337+ return cmd_process_error(armffa_cmd, ret);
338+}
339+
340+U_BOOT_CMD(armffa, 4, 1, do_armffa,
341+ "Arm FF-A operations test command",
342+ "getpart <partition UUID>\n"
343+ " - lists the partition(s) info\n"
344+ "ping <partition ID>\n"
345+ " - sends a data pattern to the specified partition\n"
346+ "devlist\n"
347+ " - displays the arm_ffa device info\n");
Patrick Williams8dd68482022-10-04 07:57:18 -0500348diff --git a/drivers/firmware/arm-ffa/Kconfig b/drivers/firmware/arm-ffa/Kconfig
Andrew Geisslerea144b032023-01-27 16:03:57 -0600349index e4914b9bc7..be4df89d23 100644
Patrick Williams8dd68482022-10-04 07:57:18 -0500350--- a/drivers/firmware/arm-ffa/Kconfig
351+++ b/drivers/firmware/arm-ffa/Kconfig
352@@ -4,6 +4,7 @@ config ARM_FFA_TRANSPORT
353 bool "Enable Arm Firmware Framework for Armv8-A driver"
354 depends on DM && ARM64
355 select ARM_SMCCC
356+ select CMD_ARMFFA
357 select LIB_UUID
358 select DEVRES
359 help
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400360--
Patrick Williams8dd68482022-10-04 07:57:18 -05003612.17.1
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400362