From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1B1B8C433FE for ; Wed, 23 Nov 2022 02:10:34 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 28D6185453; Wed, 23 Nov 2022 03:10:14 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="VcijQawX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D6211854FF; Wed, 23 Nov 2022 03:09:56 +0100 (CET) Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B17B0854FB for ; Wed, 23 Nov 2022 03:09:52 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@google.com Received: by mail-io1-xd31.google.com with SMTP id y6so12274130iof.9 for ; Tue, 22 Nov 2022 18:09:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=mISK957pt8tYO6gCJN5S/BcfrbGj6ssC3ocG2jauOjY=; b=VcijQawXzx2AvwLfs+Z1aPpU98V7iVH61ELEj8QKMeSIWLvgRM7UGEWEa5D07vng22 uObU2nvG4xXpGAnfwlsVQ7itcWi2dDfVoM6b+4hVmSbrZVQVYkk6U/rgcYZZUA61U9uT 2ehzzVjKK8YoiYDpV5fEsxhHQp69fYzS0Bi1A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=mISK957pt8tYO6gCJN5S/BcfrbGj6ssC3ocG2jauOjY=; b=lC6OCw/TbjoAvvAmIbo2J9lEcBGBKcenv8EippaHEedOXUcjNt0Q41EWb7DJpe5JLq ymxbOwwfa/Kpbd+nXaboPGku/uL6tCX8Efo41f6yiIHeMl0BzLFXEWLiDyLPu2JDImPt oxxPtD+BaPUTL//8C6WysBLvDHUZbpgVtFcQFqdoGjsqAVfNQKMtIpDgzj5034G/fvtY tT5+PnrZBiip2OFg/1rnY08BBMfdsXzAuiSVQ6KuoEsA9oP58iftvz1vZpIb36jdi97w Id4809CTIKO2bsfQM/JgYUDe0IKUElJeu6C4iGeAjmwambWsgcl4UOBVh3YeoC8pa0ea fraQ== X-Gm-Message-State: ANoB5pkPQEaoJuFyuCf8uwdHEOeffYFS0OT4cRofWGRBnJJ9KGBWZVWf 38V3q7jdsVN0uIXvg74SSRrak9OW4HbZFZglNG1QZg== X-Google-Smtp-Source: AA0mqf7HE4BhT/PKD8XOLmXHGUPnEazubqDrPm17jaPnnokF/xW5GIag0TKXN65lnkyeIeodZkjTTIxRLtNQtb2DqRU= X-Received: by 2002:a5e:8412:0:b0:6c0:3a15:4b41 with SMTP id h18-20020a5e8412000000b006c03a154b41mr3317549ioj.77.1669169392010; Tue, 22 Nov 2022 18:09:52 -0800 (PST) MIME-Version: 1.0 References: <20221107192055.21669-1-abdellatif.elkhlifi@arm.com> <20221122131751.22747-1-abdellatif.elkhlifi@arm.com> <20221122131751.22747-6-abdellatif.elkhlifi@arm.com> In-Reply-To: <20221122131751.22747-6-abdellatif.elkhlifi@arm.com> From: Simon Glass Date: Tue, 22 Nov 2022 19:09:22 -0700 Message-ID: Subject: Re: [PATCH v8 05/10] arm_ffa: introduce armffa command To: Abdellatif El Khlifi Cc: Drew.Reed@arm.com, achin.gupta@arm.com, ilias.apalodimas@linaro.org, jens.wiklander@linaro.org, nd@arm.com, trini@konsulko.com, u-boot@lists.denx.de, vishnu.banavath@arm.com, xueliang.zhong@arm.com Content-Type: text/plain; charset="UTF-8" X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Hi Abdellatif, On Tue, 22 Nov 2022 at 06:18, Abdellatif El Khlifi wrote: > > Provide armffa command showcasing the use of the FF-A driver > > The armffa command allows to query secure partitions data from > the secure world and exchanging messages with the partitions > using 64-bit FF-A direct messaging. > > Signed-off-by: Abdellatif El Khlifi > Cc: Tom Rini > Cc: Simon Glass > Cc: Ilias Apalodimas > Cc: Jens Wiklander > > --- > > Changelog: > =============== > > v8: > > * update partition_info_get() second argument to be an SP count > * pass NULL device pointer to the FF-A bus discovery and operations > > v7: > > * adapt do_ffa_dev_list() following the recent update on > uclass_first_device/uclass_next_device functions (they return void now) > * set armffa command to use 64-bit direct messaging > > v4: > > * remove pattern data in do_ffa_msg_send_direct_req > > v3: > > * use the new driver interfaces (partition_info_get, sync_send_receive) > in armffa command > > v2: > > * replace use of ffa_helper_init_device function by > ffa_helper_bus_discover > > v1: > > * introduce armffa command > > MAINTAINERS | 1 + > cmd/Kconfig | 10 ++ > cmd/Makefile | 2 + > cmd/armffa.c | 237 +++++++++++++++++++++++++++++++ > drivers/firmware/arm-ffa/Kconfig | 1 + > 5 files changed, 251 insertions(+) > create mode 100644 cmd/armffa.c needs doc/usage also > > diff --git a/MAINTAINERS b/MAINTAINERS > index dcd32cf83a..aa4e87d9f8 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -266,6 +266,7 @@ F: configs/cortina_presidio-asic-pnand_defconfig > ARM FF-A > M: Abdellatif El Khlifi > S: Maintained > +F: cmd/armffa.c > F: doc/arch/arm64.ffa.rst > F: drivers/firmware/arm-ffa/ > F: include/arm_ffa.h > diff --git a/cmd/Kconfig b/cmd/Kconfig > index 1092fb9c91..060d87375f 100644 > --- a/cmd/Kconfig > +++ b/cmd/Kconfig > @@ -924,6 +924,16 @@ endmenu > > menu "Device access commands" > > +config CMD_ARMFFA > + bool "Arm FF-A test command" > + depends on ARM_FFA_TRANSPORT > + help > + Provides a test command for the Arm FF-A driver > + supported options: > + - Listing the partition(s) info > + - Sending a data pattern to the specified partition > + - Displaying the arm_ffa device info > + > config CMD_ARMFLASH > #depends on FLASH_CFI_DRIVER > bool "armflash" > diff --git a/cmd/Makefile b/cmd/Makefile > index 2444d116c0..c600d90d39 100644 > --- a/cmd/Makefile > +++ b/cmd/Makefile > @@ -12,6 +12,8 @@ obj-y += panic.o > obj-y += version.o > > # command > + > +obj-$(CONFIG_CMD_ARMFFA) += armffa.o > obj-$(CONFIG_CMD_ACPI) += acpi.o > obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o > obj-$(CONFIG_CMD_AES) += aes.o > diff --git a/cmd/armffa.c b/cmd/armffa.c > new file mode 100644 > index 0000000000..d2e8687bfb > --- /dev/null > +++ b/cmd/armffa.c > @@ -0,0 +1,237 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * (C) Copyright 2022 ARM Limited > + * Abdellatif El Khlifi > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +/** > + * do_ffa_get_singular_partition_info - implementation of the getpart subcommand do_ffa_get_singular_partition_info is too long! > + * @cmdtp: Command Table > + * @flag: flags > + * @argc: number of arguments > + * @argv: arguments > + * > + * This function queries the secure partition information which the UUID is provided > + * as an argument. The function uses the arm_ffa driver partition_info_get operation > + * to retrieve the data. > + * The input UUID string is expected to be in big endian format. > + * > + * Return: > + * > + * CMD_RET_SUCCESS: on success, otherwise failure > + */ > +static int do_ffa_get_singular_partition_info(struct cmd_tbl *cmdtp, int flag, int argc, > + char *const argv[]) > +{ > + u32 count = 0; > + int ret; > + struct ffa_partition_info *parts_info; > + u32 info_idx; > + > + if (argc != 1) > + return -EINVAL; > + > + /* Mode 1: getting the number of secure partitions */ > + ret = ffa_bus_ops_get()->partition_info_get(NULL, argv[0], &count, NULL); > + if (ret != 0) { > + ffa_err("Failure in querying partitions count (error code: %d)", ret); > + return ret; > + } > + > + if (!count) { > + ffa_info("No secure partition found"); > + return ret; > + } > + > + /* > + * pre-allocate a buffer to be filled by the driver > + * with ffa_partition_info structs > + */ > + > + ffa_info("Pre-allocating %d partition(s) info structures", count); > + > + parts_info = calloc(count, sizeof(struct ffa_partition_info)); > + if (!parts_info) > + return -EINVAL; > + > + /* > + * ask the driver to fill the buffer with the SPs info > + */ > + > + ret = ffa_bus_ops_get()->partition_info_get(NULL, argv[0], &count, parts_info); > + if (ret != 0) { > + ffa_err("Failure in querying partition(s) info (error code: %d)", ret); > + free(parts_info); > + return ret; > + } > + > + /* > + * SPs found , show the partition information > + */ > + for (info_idx = 0; info_idx < count ; info_idx++) { > + ffa_info("Partition: id = 0x%x , exec_ctxt 0x%x , properties 0x%x", > + parts_info[info_idx].id, > + parts_info[info_idx].exec_ctxt, > + parts_info[info_idx].properties); > + } > + > + free(parts_info); > + > + return 0; > +} > + > +/** > + * do_ffa_msg_send_direct_req - implementation of the ping subcommand > + * @cmdtp: Command Table > + * @flag: flags > + * @argc: number of arguments > + * @argv: arguments > + * > + * This function sends data to the secure partition which the ID is provided > + * as an argument. The function uses the arm_ffa driver sync_send_receive operation > + * to send data. > + * > + * Return: > + * > + * CMD_RET_SUCCESS: on success, otherwise failure > + */ > +int do_ffa_msg_send_direct_req(struct cmd_tbl *cmdtp, int flag, int argc, > + char *const argv[]) > +{ > + struct ffa_send_direct_data msg = { > + .data0 = 0xaaaaaaaa, > + .data1 = 0xbbbbbbbb, > + .data2 = 0xcccccccc, > + .data3 = 0xdddddddd, > + .data4 = 0xeeeeeeee, > + }; > + u16 part_id; > + int ret; > + > + if (argc != 1) > + return -EINVAL; > + > + errno = 0; > + part_id = strtoul(argv[0], NULL, 16); > + > + if (errno) { > + ffa_err("Invalid partition ID"); > + return -EINVAL; > + } > + > + ret = ffa_bus_ops_get()->sync_send_receive(NULL, part_id, &msg, 1); This needs to use driver model properly. Get a pointer to the device, then call the uclass function in the header, which is implemented in ffa-uclass.c - see how it is done in other uclasses. > + if (ret == 0) { !ret > + u8 cnt; > + > + ffa_info("SP response:\n[LSB]"); > + for (cnt = 0; > + cnt < sizeof(struct ffa_send_direct_data) / sizeof(u64); > + cnt++) > + ffa_info("0x%llx", ((u64 *)&msg)[cnt]); > + } else { > + ffa_err("Sending direct request error (%d)", ret); > + } > + > + return ret; > +} > + > +/** > + *do_ffa_dev_list - implementation of the devlist subcommand > + * @cmdtp: [in] Command Table > + * @flag: flags > + * @argc: number of arguments > + * @argv: arguments > + * > + * This function queries the devices belonging to the UCLASS_FFA > + * class. Currently, one device is expected to show up: the arm_ffa device > + * > + * Return: > + * > + * CMD_RET_SUCCESS: on success, otherwise failure > + */ > +int do_ffa_dev_list(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) > +{ > + struct udevice *dev = NULL; > + int i; > + > + ffa_info("arm_ffa uclass entries:"); > + > + for (i = 0, uclass_first_device(UCLASS_FFA, &dev); > + dev; > + uclass_next_device(&dev), i++) { > + ffa_info("entry %d - instance %08x, ops %08x, plat %08x", > + i, > + (u32)map_to_sysmem(dev), > + (u32)map_to_sysmem(dev->driver->ops), > + (u32)map_to_sysmem(dev_get_plat(dev))); > + } > + > + return 0; > +} > + > +static struct cmd_tbl armffa_commands[] = { > + U_BOOT_CMD_MKENT(getpart, 1, 1, do_ffa_get_singular_partition_info, "", ""), do_getpart() is enough > + U_BOOT_CMD_MKENT(ping, 1, 1, do_ffa_msg_send_direct_req, "", ""), > + U_BOOT_CMD_MKENT(devlist, 0, 1, do_ffa_dev_list, "", ""), > +}; > + > +/** > + * do_armffa - the armffa command main function > + * @cmdtp: Command Table > + * @flag: flags > + * @argc: number of arguments > + * @argv: arguments > + * > + * This function identifies which armffa subcommand to run. > + * Then, it makes sure the arm_ffa device is probed and > + * ready for use. > + * Then, it runs the subcommand. > + * > + * Return: > + * > + * CMD_RET_SUCCESS: on success, otherwise failure > + */ > +static int do_armffa(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) > +{ > + struct cmd_tbl *armffa_cmd; > + int ret; > + > + if (argc < 2) > + return CMD_RET_USAGE; > + > + armffa_cmd = find_cmd_tbl(argv[1], armffa_commands, ARRAY_SIZE(armffa_commands)); > + > + argc -= 2; > + argv += 2; > + > + if (!armffa_cmd || argc > armffa_cmd->maxargs) > + return CMD_RET_USAGE; > + > + ret = ffa_bus_discover(NULL); No, this should be handled by uclass_first_device(UCLASS_FFFA) etc. > + if (ret != 0) > + return cmd_process_error(cmdtp, ret); > + > + if (!ffa_bus_ops_get()) > + return -EINVAL; > + > + ret = armffa_cmd->cmd(armffa_cmd, flag, argc, argv); > + > + return cmd_process_error(armffa_cmd, ret); > +} > + > +U_BOOT_CMD(armffa, 4, 1, do_armffa, > + "Arm FF-A operations test command", > + "getpart \n" > + " - lists the partition(s) info\n" > + "ping \n" > + " - sends a data pattern to the specified partition\n" > + "devlist\n" > + " - displays the arm_ffa device info\n"); > diff --git a/drivers/firmware/arm-ffa/Kconfig b/drivers/firmware/arm-ffa/Kconfig > index e4914b9bc7..be4df89d23 100644 > --- a/drivers/firmware/arm-ffa/Kconfig > +++ b/drivers/firmware/arm-ffa/Kconfig > @@ -4,6 +4,7 @@ config ARM_FFA_TRANSPORT > bool "Enable Arm Firmware Framework for Armv8-A driver" > depends on DM && ARM64 > select ARM_SMCCC > + select CMD_ARMFFA imply would be better, unless turning it off breaks things? > select LIB_UUID > select DEVRES > help > -- > 2.17.1 > Regards, Simon