1 // SPDX-License-Identifier: GPL-2.0+
16 /* Select the right physical address formatting according to the platform */
17 #ifdef CONFIG_PHYS_64BIT
18 #define PhysAddrLength "ll"
20 #define PhysAddrLength ""
22 #define PHYS_ADDR_LN "%" PhysAddrLength "x"
25 * ffa_get_dev() - Return the FF-A device
26 * @devp: pointer to the FF-A device
28 * Search for the FF-A device.
31 * 0 on success. Otherwise, failure
33 static int ffa_get_dev(struct udevice **devp)
37 ret = uclass_first_device_err(UCLASS_FFA, devp);
39 log_err("Cannot find FF-A bus device\n");
47 * do_ffa_getpart() - implementation of the getpart subcommand
48 * @cmdtp: Command Table
50 * @argc: number of arguments
53 * Query a secure partition information. The secure partition UUID is provided
54 * as an argument. The function uses the arm_ffa driver
55 * partition_info_get operation which implements FFA_PARTITION_INFO_GET
56 * ABI to retrieve the data. The input UUID string is expected to be in big
61 * CMD_RET_SUCCESS: on success, otherwise failure
63 static int do_ffa_getpart(struct cmd_tbl *cmdtp, int flag, int argc,
68 struct ffa_partition_desc *descs;
73 log_err("Missing argument\n");
77 ret = ffa_get_dev(&dev);
79 return CMD_RET_FAILURE;
81 /* Ask the driver to fill the buffer with the SPs info */
83 ret = ffa_partition_info_get(dev, argv[1], &count, &descs);
85 log_err("Failure in querying partition(s) info (error code: %d)\n", ret);
86 return CMD_RET_FAILURE;
89 /* SPs found , show the partition information */
90 for (i = 0; i < count ; i++) {
91 log_info("Partition: id = %x , exec_ctxt %x , properties %x\n",
93 descs[i].info.exec_ctxt,
94 descs[i].info.properties);
97 return CMD_RET_SUCCESS;
101 * do_ffa_ping() - implementation of the ping subcommand
102 * @cmdtp: Command Table
104 * @argc: number of arguments
107 * Send data to a secure partition. The secure partition UUID is provided
108 * as an argument. Use the arm_ffa driver sync_send_receive operation
109 * which implements FFA_MSG_SEND_DIRECT_{REQ,RESP} ABIs to send/receive data.
113 * CMD_RET_SUCCESS: on success, otherwise failure
115 static int do_ffa_ping(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
117 struct ffa_send_direct_data msg = {
129 log_err("Missing argument\n");
130 return CMD_RET_USAGE;
133 part_id = strtoul(argv[1], NULL, 16);
135 log_err("Partition ID can not be 0\n");
136 return CMD_RET_USAGE;
139 ret = ffa_get_dev(&dev);
141 return CMD_RET_FAILURE;
143 ret = ffa_sync_send_receive(dev, part_id, &msg, 1);
147 log_info("SP response:\n[LSB]\n");
149 cnt < sizeof(struct ffa_send_direct_data) / sizeof(u64);
151 log_info("%llx\n", ((u64 *)&msg)[cnt]);
152 return CMD_RET_SUCCESS;
155 log_err("Sending direct request error (%d)\n", ret);
156 return CMD_RET_FAILURE;
160 *do_ffa_devlist() - implementation of the devlist subcommand
161 * @cmdtp: [in] Command Table
163 * @argc: number of arguments
166 * Query the device belonging to the UCLASS_FFA
171 * CMD_RET_SUCCESS: on success, otherwise failure
173 static int do_ffa_devlist(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
178 ret = ffa_get_dev(&dev);
180 return CMD_RET_FAILURE;
182 log_info("device %s, addr " PHYS_ADDR_LN ", driver %s, ops " PHYS_ADDR_LN "\n",
186 map_to_sysmem(dev->driver->ops));
188 return CMD_RET_SUCCESS;
191 static char armffa_help_text[] =
192 "getpart <partition UUID>\n"
193 " - lists the partition(s) info\n"
194 "ping <partition ID>\n"
195 " - sends a data pattern to the specified partition\n"
197 " - displays information about the FF-A device/driver\n";
199 U_BOOT_CMD_WITH_SUBCMDS(armffa, "Arm FF-A test command", armffa_help_text,
200 U_BOOT_SUBCMD_MKENT(getpart, 2, 1, do_ffa_getpart),
201 U_BOOT_SUBCMD_MKENT(ping, 2, 1, do_ffa_ping),
202 U_BOOT_SUBCMD_MKENT(devlist, 1, 1, do_ffa_devlist));