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 9A84EC001DC for ; Thu, 27 Jul 2023 05:51:23 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1CB2986384; Thu, 27 Jul 2023 07:51:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; secure) header.d=gmx.de header.i=xypron.glpk@gmx.de header.b="BDGDD0lc"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B3D3A86387; Thu, 27 Jul 2023 07:51:19 +0200 (CEST) Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C40518620C for ; Thu, 27 Jul 2023 07:51:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1690437074; x=1691041874; i=xypron.glpk@gmx.de; bh=9xJpBji5HZmHTUHS9xcR7qdo8eivirR7j2KS6gM71zc=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=BDGDD0lc0g8aaJzcm8FN970P+DJNu0LjdXrGLkY+bVOEW7nEIPxbjx2fWwLrlTzSvz3EMju lO6xOUIoTDWLSgde1EZWnTdMB/bsLUzZh2kB0XWvpuU4IDS/hbyRRXoyn4KbJQQGuudCy3J0Q QyYIQIkljuEXg5KU4OS5TCqQxbuwLd8p4BWvi5TtocIGQm3Wx4hrfveK+SaBF2Q9NU4WeXI+o UVFo6zbUJNrESaUUszSCtmSdkY3UDoqciDcIE3XE633XUF4xHgZxMjCr+llcXQnv3l8cSpA/W 4i2M1BQ8qPIruXW1Cgugnudv2MPczfhQLO+fSv8HPSIQvCi1OuVQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [192.168.123.94] ([62.143.244.162]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N1Obb-1pj4tl1TQp-012oAY; Thu, 27 Jul 2023 07:51:14 +0200 Message-ID: <14abbf36-f536-fb8c-2ac7-833c62f7fb4b@gmx.de> Date: Thu, 27 Jul 2023 07:51:42 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH 2/6] arm_ffa: introduce armffa command To: abdellatif.elkhlifi@arm.com Cc: nd@arm.com, trini@konsulko.com, Ilias Apalodimas , u-boot@lists.denx.de References: <20220329151659.16894-1-abdellatif.elkhlifi@arm.com> <20220329151659.16894-3-abdellatif.elkhlifi@arm.com> Content-Language: en-US From: Heinrich Schuchardt In-Reply-To: <20220329151659.16894-3-abdellatif.elkhlifi@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:85yI5LD7HiuyFV10ckBfMuKrcHLi5IfTABvPojLpIfYxTXe0LUw WxWEEt1ZbTpOLiq6o3Cg9ygIFWodcwlZbTJdRO1Jk2dDdQAU1Q+B1ymXp9Qud3XdrJgk4r6 JfaJZ/RQuL6DHmyOWjodQZFnEMHZJtUKOhjhsFavtC/khHTRObB7UWshc3jcahsn4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6trtcBtxQ= 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.8 at phobos.denx.de X-Virus-Status: Clean On 3/29/22 17:16, abdellatif.elkhlifi@arm.com wrote: > From: Abdellatif El Khlifi > > 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. > > Signed-off-by: Abdellatif El Khlifi > Cc: Tom Rini > --- > MAINTAINERS | 1 + > cmd/Kconfig | 10 ++ > cmd/Makefile | 2 + > cmd/armffa.c | 266 ++++++++++++++++++++++++++++++++++++++++ > drivers/arm-ffa/Kconfig | 1 + We want to have all commands to be documented in /doc/usage/cmd/. Could you, please, provide the missing /doc/usage/cmd/armffa.rst file. Best regards Heinrich > 5 files changed, 280 insertions(+) > create mode 100644 cmd/armffa.c > > diff --git a/MAINTAINERS b/MAINTAINERS > index c5b608eb60..50ccd6a7ba 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -235,6 +235,7 @@ F: include/configs/turris_*.h > ARM FF-A > M: Abdellatif El Khlifi > S: Maintained > +F: cmd/armffa.c > F: drivers/arm-ffa/ > F: include/arm_ffa.h > F: include/arm_ffa_helper.h > diff --git a/cmd/Kconfig b/cmd/Kconfig > index 79219bcb74..de5bea1404 100644 > --- a/cmd/Kconfig > +++ b/cmd/Kconfig > @@ -813,6 +813,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 ede634d731..2905ce63cf 100644 > --- a/cmd/Makefile > +++ b/cmd/Makefile > @@ -12,6 +12,8 @@ obj-y +=3D panic.o > obj-y +=3D version.o > > # command > + > +obj-$(CONFIG_CMD_ARMFFA) +=3D armffa.o > obj-$(CONFIG_CMD_ACPI) +=3D acpi.o > obj-$(CONFIG_CMD_ADDRMAP) +=3D addrmap.o > obj-$(CONFIG_CMD_AES) +=3D aes.o > diff --git a/cmd/armffa.c b/cmd/armffa.c > new file mode 100644 > index 0000000000..fcfc3a06bd > --- /dev/null > +++ b/cmd/armffa.c > @@ -0,0 +1,266 @@ > +// 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 s= ubcommand > + * @cmdtp: Command Table > + * @flag: flags > + * @argc: number of arguments > + * @argv: arguments > + * > + * This function queries the secure partition information which the UUI= D is provided > + * as an argument. The function uses the arm_ffa driver helper function > + * 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, in= t flag, int argc, > + char *const argv[]) > +{ > + struct ffa_interface_data func_data =3D {0}; > + u32 count =3D 0; > + int ret; > + union ffa_partition_uuid service_uuid =3D {0}; > + struct ffa_partition_info *parts_info; > + u32 info_idx; > + > + if (argc !=3D 1) > + return -EINVAL; > + > + if (ffa_uuid_str_to_bin(argv[0], (unsigned char *)&service_uuid)) { > + ffa_err("Invalid UUID"); > + return -EINVAL; > + } > + > + /* > + * get from the driver the count of the SPs matching the UUID > + */ > + func_data.data0_size =3D sizeof(service_uuid); > + func_data.data0 =3D &service_uuid; > + func_data.data1_size =3D sizeof(count); > + func_data.data1 =3D &count; > + > + ret =3D ffa_helper_get_partitions_info(&func_data); > + if (ret !=3D FFA_ERR_STAT_SUCCESS) { > + 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 > + */ > + > + parts_info =3D calloc(count, sizeof(struct ffa_partition_info)); > + if (!parts_info) > + return -EINVAL; > + > + ffa_info("Pre-allocating %d partition(s) info structures", count); > + > + func_data.data1_size =3D count * sizeof(struct ffa_partition_info); > + func_data.data1 =3D parts_info; > + > + /* > + * ask the driver to fill the buffer with the SPs info > + */ > + ret =3D ffa_helper_get_partitions_info(&func_data); > + if (ret !=3D FFA_ERR_STAT_SUCCESS) { > + 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 =3D 0; info_idx < count ; info_idx++) { > + ffa_info("Partition: id =3D 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 pro= vided > + * as an argument. The function uses the arm_ffa driver helper function > + * 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 ar= gc, > + char *const argv[]) > +{ > + struct ffa_interface_data func_data =3D {0}; > + struct ffa_send_direct_data msg =3D {0}; > + u32 pattern =3D 0xaabbccd0; > + u16 part_id; > + int ret; > + > + if (argc !=3D 1) > + return -EINVAL; > + > + errno =3D 0; > + part_id =3D strtoul(argv[0], NULL, 16); > + > + if (errno) { > + ffa_err("Invalid partition ID"); > + return -EINVAL; > + } > + > + /* > + * telling the driver which partition to use > + */ > + func_data.data0_size =3D sizeof(part_id); > + func_data.data0 =3D &part_id; > + > + /* > + * filling the message data > + */ > + msg.a3 =3D ++pattern; > + msg.a4 =3D ++pattern; > + msg.a5 =3D ++pattern; > + msg.a6 =3D ++pattern; > + msg.a7 =3D ++pattern; > + func_data.data1_size =3D sizeof(msg); > + func_data.data1 =3D &msg; > + > + ret =3D ffa_helper_msg_send_direct_req(&func_data); > + if (ret =3D=3D FFA_ERR_STAT_SUCCESS) { > + u8 cnt; > + > + ffa_info("SP response:\n[LSB]"); > + for (cnt =3D 0; > + cnt < sizeof(struct ffa_send_direct_data) / sizeof(u32); > + cnt++) > + ffa_info("0x%x", ((u32 *)&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 dev= ice > + * > + * Return: > + * > + * CMD_RET_SUCCESS: on success, otherwise failure > + */ > +int do_ffa_dev_list(struct cmd_tbl *cmdtp, int flag, int argc, char *co= nst argv[]) > +{ > + struct udevice *dev =3D NULL; > + int i, ret; > + > + ffa_info("arm_ffa uclass entries:"); > + > + for (i =3D 0, ret =3D uclass_first_device(UCLASS_FFA, &dev); > + dev; > + ret =3D uclass_next_device(&dev), i++) { > + if (ret) > + break; > + > + 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 cmd_process_error(cmdtp, ret); > +} > + > +static struct cmd_tbl armffa_commands[] =3D { > + U_BOOT_CMD_MKENT(getpart, 1, 1, do_ffa_get_singular_partition_info, ""= , ""), > + 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 *c= onst argv[]) > +{ > + struct cmd_tbl *armffa_cmd; > + int ret; > + > + if (argc < 2) > + return CMD_RET_USAGE; > + > + armffa_cmd =3D find_cmd_tbl(argv[1], armffa_commands, ARRAY_SIZE(armff= a_commands)); > + > + argc -=3D 2; > + argv +=3D 2; > + > + if (!armffa_cmd || argc > armffa_cmd->maxargs) > + return CMD_RET_USAGE; > + > + ret =3D ffa_helper_init_device(); > + if (ret !=3D FFA_ERR_STAT_SUCCESS) > + return cmd_process_error(cmdtp, ret); > + > + ret =3D 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/arm-ffa/Kconfig b/drivers/arm-ffa/Kconfig > index e503dfaebf..7b7cfe26b1 100644 > --- a/drivers/arm-ffa/Kconfig > +++ b/drivers/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 if ARM64 > + select CMD_ARMFFA > select LIB_UUID > select ARM_FFA_TRANSPORT_HELPERS > help