blob: f52f88ddcd50b8157e4f7d4f6197e276c4bf6102 [file] [log] [blame]
Patrick Williams8dd68482022-10-04 07:57:18 -05001From a09ed2542f4d991fef61bd51f87d373f44ad1ff3 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
4Subject: [PATCH 10/26] 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
9the secure world and exchanging messages with the partitions.
10
11Signed-off-by: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
Patrick Williams8dd68482022-10-04 07:57:18 -050012Upstream-Status: Submitted [cover letter: https://lore.kernel.org/all/20220926101723.9965-1-abdellatif.elkhlifi@arm.com/]
Brad Bishopbec4ebc2022-08-03 09:55:16 -040013---
Patrick Williams8dd68482022-10-04 07:57:18 -050014
15Changelog:
16===============
17
18v4:
19
20* remove pattern data in do_ffa_msg_send_direct_req
21
22v3:
23
24* use the new driver interfaces (partition_info_get, sync_send_receive)
25 in armffa command
26
27v2:
28
29* replace use of ffa_helper_init_device function by
30 ffa_helper_bus_discover
31
32v1:
33
34* introduce armffa command
35
36 MAINTAINERS | 1 +
37 cmd/Kconfig | 10 ++
38 cmd/Makefile | 2 +
39 cmd/armffa.c | 242 +++++++++++++++++++++++++++++++
40 drivers/firmware/arm-ffa/Kconfig | 1 +
41 5 files changed, 256 insertions(+)
Brad Bishopbec4ebc2022-08-03 09:55:16 -040042 create mode 100644 cmd/armffa.c
43
44diff --git a/MAINTAINERS b/MAINTAINERS
Patrick Williams8dd68482022-10-04 07:57:18 -050045index e760b4ca3a..9f0a1b7387 100644
Brad Bishopbec4ebc2022-08-03 09:55:16 -040046--- a/MAINTAINERS
47+++ b/MAINTAINERS
Patrick Williams92b42cb2022-09-03 06:53:57 -050048@@ -247,6 +247,7 @@ F: include/configs/turris_*.h
Brad Bishopbec4ebc2022-08-03 09:55:16 -040049 ARM FF-A
50 M: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
51 S: Maintained
52+F: cmd/armffa.c
Patrick Williams8dd68482022-10-04 07:57:18 -050053 F: doc/README.ffa.drv
54 F: drivers/firmware/arm-ffa/
Brad Bishopbec4ebc2022-08-03 09:55:16 -040055 F: include/arm_ffa.h
Brad Bishopbec4ebc2022-08-03 09:55:16 -040056diff --git a/cmd/Kconfig b/cmd/Kconfig
Patrick Williams8dd68482022-10-04 07:57:18 -050057index ba2f321ae9..090e668125 100644
Brad Bishopbec4ebc2022-08-03 09:55:16 -040058--- a/cmd/Kconfig
59+++ b/cmd/Kconfig
Patrick Williams92b42cb2022-09-03 06:53:57 -050060@@ -873,6 +873,16 @@ endmenu
Brad Bishopbec4ebc2022-08-03 09:55:16 -040061
62 menu "Device access commands"
63
64+config CMD_ARMFFA
65+ bool "Arm FF-A test command"
66+ depends on ARM_FFA_TRANSPORT
67+ help
68+ Provides a test command for the Arm FF-A driver
69+ supported options:
70+ - Listing the partition(s) info
71+ - Sending a data pattern to the specified partition
72+ - Displaying the arm_ffa device info
73+
74 config CMD_ARMFLASH
75 #depends on FLASH_CFI_DRIVER
76 bool "armflash"
77diff --git a/cmd/Makefile b/cmd/Makefile
Patrick Williams8dd68482022-10-04 07:57:18 -050078index 5e43a1e022..e40f52f1e4 100644
Brad Bishopbec4ebc2022-08-03 09:55:16 -040079--- a/cmd/Makefile
80+++ b/cmd/Makefile
81@@ -12,6 +12,8 @@ obj-y += panic.o
82 obj-y += version.o
83
84 # command
85+
86+obj-$(CONFIG_CMD_ARMFFA) += armffa.o
87 obj-$(CONFIG_CMD_ACPI) += acpi.o
88 obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o
89 obj-$(CONFIG_CMD_AES) += aes.o
90diff --git a/cmd/armffa.c b/cmd/armffa.c
91new file mode 100644
Patrick Williams8dd68482022-10-04 07:57:18 -050092index 0000000000..9b56e8a830
Brad Bishopbec4ebc2022-08-03 09:55:16 -040093--- /dev/null
94+++ b/cmd/armffa.c
Patrick Williams8dd68482022-10-04 07:57:18 -050095@@ -0,0 +1,242 @@
Brad Bishopbec4ebc2022-08-03 09:55:16 -040096+// SPDX-License-Identifier: GPL-2.0+
97+/*
Patrick Williams8dd68482022-10-04 07:57:18 -050098+ * (C) Copyright 2022 ARM Limited
Brad Bishopbec4ebc2022-08-03 09:55:16 -040099+ * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
100+ */
101+
Patrick Williams8dd68482022-10-04 07:57:18 -0500102+#include <arm_ffa.h>
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400103+#include <asm/io.h>
104+#include <common.h>
105+#include <command.h>
106+#include <dm.h>
107+#include <mapmem.h>
108+#include <stdlib.h>
109+
110+/**
111+ * do_ffa_get_singular_partition_info - implementation of the getpart subcommand
112+ * @cmdtp: Command Table
113+ * @flag: flags
114+ * @argc: number of arguments
115+ * @argv: arguments
116+ *
117+ * This function queries the secure partition information which the UUID is provided
Patrick Williams8dd68482022-10-04 07:57:18 -0500118+ * as an argument. The function uses the arm_ffa driver partition_info_get operation
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400119+ * to retrieve the data.
120+ * The input UUID string is expected to be in big endian format.
121+ *
122+ * Return:
123+ *
124+ * CMD_RET_SUCCESS: on success, otherwise failure
125+ */
126+static int do_ffa_get_singular_partition_info(struct cmd_tbl *cmdtp, int flag, int argc,
127+ char *const argv[])
128+{
Patrick Williams8dd68482022-10-04 07:57:18 -0500129+ u32 count = 0, size = 0;
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400130+ int ret;
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400131+ struct ffa_partition_info *parts_info;
132+ u32 info_idx;
133+
134+ if (argc != 1)
135+ return -EINVAL;
136+
Patrick Williams8dd68482022-10-04 07:57:18 -0500137+ /* Mode 1: getting the number of secure partitions */
138+ ret = ffa_bus_ops_get()->partition_info_get(argv[0], &count, NULL);
139+ if (ret != 0) {
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400140+ ffa_err("Failure in querying partitions count (error code: %d)", ret);
141+ return ret;
142+ }
143+
144+ if (!count) {
145+ ffa_info("No secure partition found");
146+ return ret;
147+ }
148+
149+ /*
150+ * pre-allocate a buffer to be filled by the driver
Patrick Williams8dd68482022-10-04 07:57:18 -0500151+ * with ffa_partition_info structs
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400152+ */
153+
Patrick Williams8dd68482022-10-04 07:57:18 -0500154+ ffa_info("Pre-allocating %d partition(s) info structures", count);
155+
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400156+ parts_info = calloc(count, sizeof(struct ffa_partition_info));
157+ if (!parts_info)
158+ return -EINVAL;
159+
Patrick Williams8dd68482022-10-04 07:57:18 -0500160+ size = count * sizeof(struct ffa_partition_info);
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400161+
162+ /*
163+ * ask the driver to fill the buffer with the SPs info
164+ */
Patrick Williams8dd68482022-10-04 07:57:18 -0500165+
166+ ret = ffa_bus_ops_get()->partition_info_get(argv[0], &size, parts_info);
167+ if (ret != 0) {
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400168+ ffa_err("Failure in querying partition(s) info (error code: %d)", ret);
169+ free(parts_info);
170+ return ret;
171+ }
172+
173+ /*
174+ * SPs found , show the partition information
175+ */
176+ for (info_idx = 0; info_idx < count ; info_idx++) {
177+ ffa_info("Partition: id = 0x%x , exec_ctxt 0x%x , properties 0x%x",
178+ parts_info[info_idx].id,
179+ parts_info[info_idx].exec_ctxt,
180+ parts_info[info_idx].properties);
181+ }
182+
183+ free(parts_info);
184+
185+ return 0;
186+}
187+
188+/**
189+ * do_ffa_msg_send_direct_req - implementation of the ping subcommand
190+ * @cmdtp: Command Table
191+ * @flag: flags
192+ * @argc: number of arguments
193+ * @argv: arguments
194+ *
195+ * This function sends data to the secure partition which the ID is provided
Patrick Williams8dd68482022-10-04 07:57:18 -0500196+ * as an argument. The function uses the arm_ffa driver sync_send_receive operation
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400197+ * to send data.
198+ *
199+ * Return:
200+ *
201+ * CMD_RET_SUCCESS: on success, otherwise failure
202+ */
203+int do_ffa_msg_send_direct_req(struct cmd_tbl *cmdtp, int flag, int argc,
204+ char *const argv[])
205+{
Patrick Williams8dd68482022-10-04 07:57:18 -0500206+ struct ffa_send_direct_data msg = {
207+ .data0 = 0xaaaaaaaa,
208+ .data1 = 0xbbbbbbbb,
209+ .data2 = 0xcccccccc,
210+ .data3 = 0xdddddddd,
211+ .data4 = 0xeeeeeeee,
212+ };
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400213+ u16 part_id;
214+ int ret;
215+
216+ if (argc != 1)
217+ return -EINVAL;
218+
219+ errno = 0;
220+ part_id = strtoul(argv[0], NULL, 16);
221+
222+ if (errno) {
223+ ffa_err("Invalid partition ID");
224+ return -EINVAL;
225+ }
226+
Patrick Williams8dd68482022-10-04 07:57:18 -0500227+ ret = ffa_bus_ops_get()->sync_send_receive(part_id, &msg);
228+ if (ret == 0) {
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400229+ u8 cnt;
230+
231+ ffa_info("SP response:\n[LSB]");
232+ for (cnt = 0;
Patrick Williams8dd68482022-10-04 07:57:18 -0500233+ cnt < sizeof(struct ffa_send_direct_data) / sizeof(u64);
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400234+ cnt++)
Patrick Williams8dd68482022-10-04 07:57:18 -0500235+ ffa_info("0x%llx", ((u64 *)&msg)[cnt]);
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400236+ } else {
237+ ffa_err("Sending direct request error (%d)", ret);
238+ }
239+
240+ return ret;
241+}
242+
243+/**
244+ *do_ffa_dev_list - implementation of the devlist subcommand
245+ * @cmdtp: [in] Command Table
246+ * @flag: flags
247+ * @argc: number of arguments
248+ * @argv: arguments
249+ *
250+ * This function queries the devices belonging to the UCLASS_FFA
251+ * class. Currently, one device is expected to show up: the arm_ffa device
252+ *
253+ * Return:
254+ *
255+ * CMD_RET_SUCCESS: on success, otherwise failure
256+ */
257+int do_ffa_dev_list(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
258+{
259+ struct udevice *dev = NULL;
260+ int i, ret;
261+
262+ ffa_info("arm_ffa uclass entries:");
263+
264+ for (i = 0, ret = uclass_first_device(UCLASS_FFA, &dev);
265+ dev;
266+ ret = uclass_next_device(&dev), i++) {
267+ if (ret)
268+ break;
269+
270+ ffa_info("entry %d - instance %08x, ops %08x, plat %08x",
271+ i,
272+ (u32)map_to_sysmem(dev),
273+ (u32)map_to_sysmem(dev->driver->ops),
274+ (u32)map_to_sysmem(dev_get_plat(dev)));
275+ }
276+
277+ return cmd_process_error(cmdtp, ret);
278+}
279+
280+static struct cmd_tbl armffa_commands[] = {
281+ U_BOOT_CMD_MKENT(getpart, 1, 1, do_ffa_get_singular_partition_info, "", ""),
282+ U_BOOT_CMD_MKENT(ping, 1, 1, do_ffa_msg_send_direct_req, "", ""),
283+ U_BOOT_CMD_MKENT(devlist, 0, 1, do_ffa_dev_list, "", ""),
284+};
285+
286+/**
287+ * do_armffa - the armffa command main function
288+ * @cmdtp: Command Table
289+ * @flag: flags
290+ * @argc: number of arguments
291+ * @argv: arguments
292+ *
293+ * This function identifies which armffa subcommand to run.
294+ * Then, it makes sure the arm_ffa device is probed and
295+ * ready for use.
296+ * Then, it runs the subcommand.
297+ *
298+ * Return:
299+ *
300+ * CMD_RET_SUCCESS: on success, otherwise failure
301+ */
302+static int do_armffa(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
303+{
304+ struct cmd_tbl *armffa_cmd;
305+ int ret;
306+
307+ if (argc < 2)
308+ return CMD_RET_USAGE;
309+
310+ armffa_cmd = find_cmd_tbl(argv[1], armffa_commands, ARRAY_SIZE(armffa_commands));
311+
312+ argc -= 2;
313+ argv += 2;
314+
315+ if (!armffa_cmd || argc > armffa_cmd->maxargs)
316+ return CMD_RET_USAGE;
317+
Patrick Williams8dd68482022-10-04 07:57:18 -0500318+ ret = ffa_bus_discover();
319+ if (ret != 0)
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400320+ return cmd_process_error(cmdtp, ret);
321+
Patrick Williams8dd68482022-10-04 07:57:18 -0500322+ if (!ffa_bus_ops_get())
323+ return -EINVAL;
324+
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400325+ ret = armffa_cmd->cmd(armffa_cmd, flag, argc, argv);
326+
327+ return cmd_process_error(armffa_cmd, ret);
328+}
329+
330+U_BOOT_CMD(armffa, 4, 1, do_armffa,
331+ "Arm FF-A operations test command",
332+ "getpart <partition UUID>\n"
333+ " - lists the partition(s) info\n"
334+ "ping <partition ID>\n"
335+ " - sends a data pattern to the specified partition\n"
336+ "devlist\n"
337+ " - displays the arm_ffa device info\n");
Patrick Williams8dd68482022-10-04 07:57:18 -0500338diff --git a/drivers/firmware/arm-ffa/Kconfig b/drivers/firmware/arm-ffa/Kconfig
339index aceb61cf49..40b467b0a5 100644
340--- a/drivers/firmware/arm-ffa/Kconfig
341+++ b/drivers/firmware/arm-ffa/Kconfig
342@@ -4,6 +4,7 @@ config ARM_FFA_TRANSPORT
343 bool "Enable Arm Firmware Framework for Armv8-A driver"
344 depends on DM && ARM64
345 select ARM_SMCCC
346+ select CMD_ARMFFA
347 select LIB_UUID
348 select DEVRES
349 help
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400350--
Patrick Williams8dd68482022-10-04 07:57:18 -05003512.17.1
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400352