Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 1 | From a09ed2542f4d991fef61bd51f87d373f44ad1ff3 Mon Sep 17 00:00:00 2001 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 2 | From: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com> |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 3 | Date: Mon, 6 Jun 2022 12:46:38 +0100 |
| 4 | Subject: [PATCH 10/26] arm_ffa: introduce armffa command |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 5 | |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 6 | Provide armffa command showcasing the use of the FF-A driver |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 7 | |
| 8 | The armffa command allows to query secure partitions data from |
| 9 | the secure world and exchanging messages with the partitions. |
| 10 | |
| 11 | Signed-off-by: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com> |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 12 | Upstream-Status: Submitted [cover letter: https://lore.kernel.org/all/20220926101723.9965-1-abdellatif.elkhlifi@arm.com/] |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 13 | --- |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 14 | |
| 15 | Changelog: |
| 16 | =============== |
| 17 | |
| 18 | v4: |
| 19 | |
| 20 | * remove pattern data in do_ffa_msg_send_direct_req |
| 21 | |
| 22 | v3: |
| 23 | |
| 24 | * use the new driver interfaces (partition_info_get, sync_send_receive) |
| 25 | in armffa command |
| 26 | |
| 27 | v2: |
| 28 | |
| 29 | * replace use of ffa_helper_init_device function by |
| 30 | ffa_helper_bus_discover |
| 31 | |
| 32 | v1: |
| 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 Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 42 | create mode 100644 cmd/armffa.c |
| 43 | |
| 44 | diff --git a/MAINTAINERS b/MAINTAINERS |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 45 | index e760b4ca3a..9f0a1b7387 100644 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 46 | --- a/MAINTAINERS |
| 47 | +++ b/MAINTAINERS |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 48 | @@ -247,6 +247,7 @@ F: include/configs/turris_*.h |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 49 | ARM FF-A |
| 50 | M: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com> |
| 51 | S: Maintained |
| 52 | +F: cmd/armffa.c |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 53 | F: doc/README.ffa.drv |
| 54 | F: drivers/firmware/arm-ffa/ |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 55 | F: include/arm_ffa.h |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 56 | diff --git a/cmd/Kconfig b/cmd/Kconfig |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 57 | index ba2f321ae9..090e668125 100644 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 58 | --- a/cmd/Kconfig |
| 59 | +++ b/cmd/Kconfig |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 60 | @@ -873,6 +873,16 @@ endmenu |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 61 | |
| 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" |
| 77 | diff --git a/cmd/Makefile b/cmd/Makefile |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 78 | index 5e43a1e022..e40f52f1e4 100644 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 79 | --- 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 |
| 90 | diff --git a/cmd/armffa.c b/cmd/armffa.c |
| 91 | new file mode 100644 |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 92 | index 0000000000..9b56e8a830 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 93 | --- /dev/null |
| 94 | +++ b/cmd/armffa.c |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 95 | @@ -0,0 +1,242 @@ |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 96 | +// SPDX-License-Identifier: GPL-2.0+ |
| 97 | +/* |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 98 | + * (C) Copyright 2022 ARM Limited |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 99 | + * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com> |
| 100 | + */ |
| 101 | + |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 102 | +#include <arm_ffa.h> |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 103 | +#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 Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 118 | + * as an argument. The function uses the arm_ffa driver partition_info_get operation |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 119 | + * 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 Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 129 | + u32 count = 0, size = 0; |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 130 | + int ret; |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 131 | + struct ffa_partition_info *parts_info; |
| 132 | + u32 info_idx; |
| 133 | + |
| 134 | + if (argc != 1) |
| 135 | + return -EINVAL; |
| 136 | + |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 137 | + /* 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 Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 140 | + 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 Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 151 | + * with ffa_partition_info structs |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 152 | + */ |
| 153 | + |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 154 | + ffa_info("Pre-allocating %d partition(s) info structures", count); |
| 155 | + |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 156 | + parts_info = calloc(count, sizeof(struct ffa_partition_info)); |
| 157 | + if (!parts_info) |
| 158 | + return -EINVAL; |
| 159 | + |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 160 | + size = count * sizeof(struct ffa_partition_info); |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 161 | + |
| 162 | + /* |
| 163 | + * ask the driver to fill the buffer with the SPs info |
| 164 | + */ |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 165 | + |
| 166 | + ret = ffa_bus_ops_get()->partition_info_get(argv[0], &size, parts_info); |
| 167 | + if (ret != 0) { |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 168 | + 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 Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 196 | + * as an argument. The function uses the arm_ffa driver sync_send_receive operation |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 197 | + * 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 Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 206 | + struct ffa_send_direct_data msg = { |
| 207 | + .data0 = 0xaaaaaaaa, |
| 208 | + .data1 = 0xbbbbbbbb, |
| 209 | + .data2 = 0xcccccccc, |
| 210 | + .data3 = 0xdddddddd, |
| 211 | + .data4 = 0xeeeeeeee, |
| 212 | + }; |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 213 | + 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 Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 227 | + ret = ffa_bus_ops_get()->sync_send_receive(part_id, &msg); |
| 228 | + if (ret == 0) { |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 229 | + u8 cnt; |
| 230 | + |
| 231 | + ffa_info("SP response:\n[LSB]"); |
| 232 | + for (cnt = 0; |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 233 | + cnt < sizeof(struct ffa_send_direct_data) / sizeof(u64); |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 234 | + cnt++) |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 235 | + ffa_info("0x%llx", ((u64 *)&msg)[cnt]); |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 236 | + } 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 Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 318 | + ret = ffa_bus_discover(); |
| 319 | + if (ret != 0) |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 320 | + return cmd_process_error(cmdtp, ret); |
| 321 | + |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 322 | + if (!ffa_bus_ops_get()) |
| 323 | + return -EINVAL; |
| 324 | + |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 325 | + 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 Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 338 | diff --git a/drivers/firmware/arm-ffa/Kconfig b/drivers/firmware/arm-ffa/Kconfig |
| 339 | index 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 Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 350 | -- |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame^] | 351 | 2.17.1 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 352 | |