blob: cbf8c101a7650c4925c46417c2c8474c24439dff [file] [log] [blame]
Patrick Williams864cc432023-02-09 14:54:44 -06001From c6b116c4793449775064a8fc949a3b607b7ade27 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
Patrick Williams864cc432023-02-09 14:54:44 -06004Subject: [PATCH 05/27] 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
Patrick Williams864cc432023-02-09 14:54:44 -060050
51Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Andrew Geisslerea144b032023-01-27 16:03:57 -060052---
Patrick Williams8dd68482022-10-04 07:57:18 -050053 MAINTAINERS | 1 +
54 cmd/Kconfig | 10 ++
55 cmd/Makefile | 2 +
Andrew Geisslerea144b032023-01-27 16:03:57 -060056 cmd/armffa.c | 237 +++++++++++++++++++++++++++++++
Patrick Williams8dd68482022-10-04 07:57:18 -050057 drivers/firmware/arm-ffa/Kconfig | 1 +
Andrew Geisslerea144b032023-01-27 16:03:57 -060058 5 files changed, 251 insertions(+)
Brad Bishopbec4ebc2022-08-03 09:55:16 -040059 create mode 100644 cmd/armffa.c
60
61diff --git a/MAINTAINERS b/MAINTAINERS
Patrick Williams864cc432023-02-09 14:54:44 -060062index 509619d31ce6..61ce6c436fe1 100644
Brad Bishopbec4ebc2022-08-03 09:55:16 -040063--- a/MAINTAINERS
64+++ b/MAINTAINERS
Patrick Williams864cc432023-02-09 14:54:44 -060065@@ -267,6 +267,7 @@ F: configs/cortina_presidio-asic-pnand_defconfig
Brad Bishopbec4ebc2022-08-03 09:55:16 -040066 ARM FF-A
67 M: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
68 S: Maintained
69+F: cmd/armffa.c
Andrew Geisslerea144b032023-01-27 16:03:57 -060070 F: doc/arch/arm64.ffa.rst
Patrick Williams8dd68482022-10-04 07:57:18 -050071 F: drivers/firmware/arm-ffa/
Brad Bishopbec4ebc2022-08-03 09:55:16 -040072 F: include/arm_ffa.h
Brad Bishopbec4ebc2022-08-03 09:55:16 -040073diff --git a/cmd/Kconfig b/cmd/Kconfig
Patrick Williams864cc432023-02-09 14:54:44 -060074index b2d75987170e..7d0a40e8acb4 100644
Brad Bishopbec4ebc2022-08-03 09:55:16 -040075--- a/cmd/Kconfig
76+++ b/cmd/Kconfig
Patrick Williams864cc432023-02-09 14:54:44 -060077@@ -924,6 +924,16 @@ endmenu
Brad Bishopbec4ebc2022-08-03 09:55:16 -040078
79 menu "Device access commands"
80
81+config CMD_ARMFFA
82+ bool "Arm FF-A test command"
83+ depends on ARM_FFA_TRANSPORT
84+ help
85+ Provides a test command for the Arm FF-A driver
86+ supported options:
87+ - Listing the partition(s) info
88+ - Sending a data pattern to the specified partition
89+ - Displaying the arm_ffa device info
90+
91 config CMD_ARMFLASH
92 #depends on FLASH_CFI_DRIVER
93 bool "armflash"
94diff --git a/cmd/Makefile b/cmd/Makefile
Patrick Williams864cc432023-02-09 14:54:44 -060095index 0b6a96c1d914..c757f1647da6 100644
Brad Bishopbec4ebc2022-08-03 09:55:16 -040096--- a/cmd/Makefile
97+++ b/cmd/Makefile
98@@ -12,6 +12,8 @@ obj-y += panic.o
99 obj-y += version.o
100
101 # command
102+
103+obj-$(CONFIG_CMD_ARMFFA) += armffa.o
104 obj-$(CONFIG_CMD_ACPI) += acpi.o
105 obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o
106 obj-$(CONFIG_CMD_AES) += aes.o
107diff --git a/cmd/armffa.c b/cmd/armffa.c
108new file mode 100644
Patrick Williams864cc432023-02-09 14:54:44 -0600109index 000000000000..d2e8687bfb1f
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400110--- /dev/null
111+++ b/cmd/armffa.c
Andrew Geisslerea144b032023-01-27 16:03:57 -0600112@@ -0,0 +1,237 @@
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400113+// SPDX-License-Identifier: GPL-2.0+
114+/*
Patrick Williams8dd68482022-10-04 07:57:18 -0500115+ * (C) Copyright 2022 ARM Limited
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400116+ * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
117+ */
118+
Patrick Williams8dd68482022-10-04 07:57:18 -0500119+#include <arm_ffa.h>
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400120+#include <asm/io.h>
121+#include <common.h>
122+#include <command.h>
123+#include <dm.h>
124+#include <mapmem.h>
125+#include <stdlib.h>
126+
127+/**
128+ * do_ffa_get_singular_partition_info - implementation of the getpart subcommand
129+ * @cmdtp: Command Table
130+ * @flag: flags
131+ * @argc: number of arguments
132+ * @argv: arguments
133+ *
134+ * This function queries the secure partition information which the UUID is provided
Patrick Williams8dd68482022-10-04 07:57:18 -0500135+ * as an argument. The function uses the arm_ffa driver partition_info_get operation
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400136+ * to retrieve the data.
137+ * The input UUID string is expected to be in big endian format.
138+ *
139+ * Return:
140+ *
141+ * CMD_RET_SUCCESS: on success, otherwise failure
142+ */
143+static int do_ffa_get_singular_partition_info(struct cmd_tbl *cmdtp, int flag, int argc,
144+ char *const argv[])
145+{
Andrew Geisslerea144b032023-01-27 16:03:57 -0600146+ u32 count = 0;
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400147+ int ret;
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400148+ struct ffa_partition_info *parts_info;
149+ u32 info_idx;
150+
151+ if (argc != 1)
152+ return -EINVAL;
153+
Patrick Williams8dd68482022-10-04 07:57:18 -0500154+ /* Mode 1: getting the number of secure partitions */
Andrew Geisslerea144b032023-01-27 16:03:57 -0600155+ ret = ffa_bus_ops_get()->partition_info_get(NULL, argv[0], &count, NULL);
Patrick Williams8dd68482022-10-04 07:57:18 -0500156+ if (ret != 0) {
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400157+ ffa_err("Failure in querying partitions count (error code: %d)", ret);
158+ return ret;
159+ }
160+
161+ if (!count) {
162+ ffa_info("No secure partition found");
163+ return ret;
164+ }
165+
166+ /*
167+ * pre-allocate a buffer to be filled by the driver
Patrick Williams8dd68482022-10-04 07:57:18 -0500168+ * with ffa_partition_info structs
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400169+ */
170+
Patrick Williams8dd68482022-10-04 07:57:18 -0500171+ ffa_info("Pre-allocating %d partition(s) info structures", count);
172+
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400173+ parts_info = calloc(count, sizeof(struct ffa_partition_info));
174+ if (!parts_info)
175+ return -EINVAL;
176+
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400177+ /*
178+ * ask the driver to fill the buffer with the SPs info
179+ */
Patrick Williams8dd68482022-10-04 07:57:18 -0500180+
Andrew Geisslerea144b032023-01-27 16:03:57 -0600181+ ret = ffa_bus_ops_get()->partition_info_get(NULL, argv[0], &count, parts_info);
Patrick Williams8dd68482022-10-04 07:57:18 -0500182+ if (ret != 0) {
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400183+ ffa_err("Failure in querying partition(s) info (error code: %d)", ret);
184+ free(parts_info);
185+ return ret;
186+ }
187+
188+ /*
189+ * SPs found , show the partition information
190+ */
191+ for (info_idx = 0; info_idx < count ; info_idx++) {
192+ ffa_info("Partition: id = 0x%x , exec_ctxt 0x%x , properties 0x%x",
193+ parts_info[info_idx].id,
194+ parts_info[info_idx].exec_ctxt,
195+ parts_info[info_idx].properties);
196+ }
197+
198+ free(parts_info);
199+
200+ return 0;
201+}
202+
203+/**
204+ * do_ffa_msg_send_direct_req - implementation of the ping subcommand
205+ * @cmdtp: Command Table
206+ * @flag: flags
207+ * @argc: number of arguments
208+ * @argv: arguments
209+ *
210+ * This function sends data to the secure partition which the ID is provided
Patrick Williams8dd68482022-10-04 07:57:18 -0500211+ * as an argument. The function uses the arm_ffa driver sync_send_receive operation
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400212+ * to send data.
213+ *
214+ * Return:
215+ *
216+ * CMD_RET_SUCCESS: on success, otherwise failure
217+ */
218+int do_ffa_msg_send_direct_req(struct cmd_tbl *cmdtp, int flag, int argc,
219+ char *const argv[])
220+{
Patrick Williams8dd68482022-10-04 07:57:18 -0500221+ struct ffa_send_direct_data msg = {
222+ .data0 = 0xaaaaaaaa,
223+ .data1 = 0xbbbbbbbb,
224+ .data2 = 0xcccccccc,
225+ .data3 = 0xdddddddd,
226+ .data4 = 0xeeeeeeee,
227+ };
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400228+ u16 part_id;
229+ int ret;
230+
231+ if (argc != 1)
232+ return -EINVAL;
233+
234+ errno = 0;
235+ part_id = strtoul(argv[0], NULL, 16);
236+
237+ if (errno) {
238+ ffa_err("Invalid partition ID");
239+ return -EINVAL;
240+ }
241+
Andrew Geisslerea144b032023-01-27 16:03:57 -0600242+ ret = ffa_bus_ops_get()->sync_send_receive(NULL, part_id, &msg, 1);
Patrick Williams8dd68482022-10-04 07:57:18 -0500243+ if (ret == 0) {
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400244+ u8 cnt;
245+
246+ ffa_info("SP response:\n[LSB]");
247+ for (cnt = 0;
Patrick Williams8dd68482022-10-04 07:57:18 -0500248+ cnt < sizeof(struct ffa_send_direct_data) / sizeof(u64);
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400249+ cnt++)
Patrick Williams8dd68482022-10-04 07:57:18 -0500250+ ffa_info("0x%llx", ((u64 *)&msg)[cnt]);
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400251+ } else {
252+ ffa_err("Sending direct request error (%d)", ret);
253+ }
254+
255+ return ret;
256+}
257+
258+/**
259+ *do_ffa_dev_list - implementation of the devlist subcommand
260+ * @cmdtp: [in] Command Table
261+ * @flag: flags
262+ * @argc: number of arguments
263+ * @argv: arguments
264+ *
265+ * This function queries the devices belonging to the UCLASS_FFA
266+ * class. Currently, one device is expected to show up: the arm_ffa device
267+ *
268+ * Return:
269+ *
270+ * CMD_RET_SUCCESS: on success, otherwise failure
271+ */
272+int do_ffa_dev_list(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
273+{
274+ struct udevice *dev = NULL;
Andrew Geisslerea144b032023-01-27 16:03:57 -0600275+ int i;
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400276+
277+ ffa_info("arm_ffa uclass entries:");
278+
Andrew Geisslerea144b032023-01-27 16:03:57 -0600279+ for (i = 0, uclass_first_device(UCLASS_FFA, &dev);
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400280+ dev;
Andrew Geisslerea144b032023-01-27 16:03:57 -0600281+ uclass_next_device(&dev), i++) {
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400282+ ffa_info("entry %d - instance %08x, ops %08x, plat %08x",
283+ i,
284+ (u32)map_to_sysmem(dev),
285+ (u32)map_to_sysmem(dev->driver->ops),
286+ (u32)map_to_sysmem(dev_get_plat(dev)));
287+ }
288+
Andrew Geisslerea144b032023-01-27 16:03:57 -0600289+ return 0;
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400290+}
291+
292+static struct cmd_tbl armffa_commands[] = {
293+ U_BOOT_CMD_MKENT(getpart, 1, 1, do_ffa_get_singular_partition_info, "", ""),
294+ U_BOOT_CMD_MKENT(ping, 1, 1, do_ffa_msg_send_direct_req, "", ""),
295+ U_BOOT_CMD_MKENT(devlist, 0, 1, do_ffa_dev_list, "", ""),
296+};
297+
298+/**
299+ * do_armffa - the armffa command main function
300+ * @cmdtp: Command Table
301+ * @flag: flags
302+ * @argc: number of arguments
303+ * @argv: arguments
304+ *
305+ * This function identifies which armffa subcommand to run.
306+ * Then, it makes sure the arm_ffa device is probed and
307+ * ready for use.
308+ * Then, it runs the subcommand.
309+ *
310+ * Return:
311+ *
312+ * CMD_RET_SUCCESS: on success, otherwise failure
313+ */
314+static int do_armffa(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
315+{
316+ struct cmd_tbl *armffa_cmd;
317+ int ret;
318+
319+ if (argc < 2)
320+ return CMD_RET_USAGE;
321+
322+ armffa_cmd = find_cmd_tbl(argv[1], armffa_commands, ARRAY_SIZE(armffa_commands));
323+
324+ argc -= 2;
325+ argv += 2;
326+
327+ if (!armffa_cmd || argc > armffa_cmd->maxargs)
328+ return CMD_RET_USAGE;
329+
Andrew Geisslerea144b032023-01-27 16:03:57 -0600330+ ret = ffa_bus_discover(NULL);
Patrick Williams8dd68482022-10-04 07:57:18 -0500331+ if (ret != 0)
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400332+ return cmd_process_error(cmdtp, ret);
333+
Patrick Williams8dd68482022-10-04 07:57:18 -0500334+ if (!ffa_bus_ops_get())
335+ return -EINVAL;
336+
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400337+ ret = armffa_cmd->cmd(armffa_cmd, flag, argc, argv);
338+
339+ return cmd_process_error(armffa_cmd, ret);
340+}
341+
342+U_BOOT_CMD(armffa, 4, 1, do_armffa,
343+ "Arm FF-A operations test command",
344+ "getpart <partition UUID>\n"
345+ " - lists the partition(s) info\n"
346+ "ping <partition ID>\n"
347+ " - sends a data pattern to the specified partition\n"
348+ "devlist\n"
349+ " - displays the arm_ffa device info\n");
Patrick Williams8dd68482022-10-04 07:57:18 -0500350diff --git a/drivers/firmware/arm-ffa/Kconfig b/drivers/firmware/arm-ffa/Kconfig
Patrick Williams864cc432023-02-09 14:54:44 -0600351index e4914b9bc779..be4df89d23fa 100644
Patrick Williams8dd68482022-10-04 07:57:18 -0500352--- a/drivers/firmware/arm-ffa/Kconfig
353+++ b/drivers/firmware/arm-ffa/Kconfig
354@@ -4,6 +4,7 @@ config ARM_FFA_TRANSPORT
355 bool "Enable Arm Firmware Framework for Armv8-A driver"
356 depends on DM && ARM64
357 select ARM_SMCCC
358+ select CMD_ARMFFA
359 select LIB_UUID
360 select DEVRES
361 help
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400362--
Patrick Williams864cc432023-02-09 14:54:44 -06003632.39.1
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400364