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 185BDEB64D9 for ; Mon, 3 Jul 2023 00:55:19 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BC79186442; Mon, 3 Jul 2023 02:55:17 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org 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; unprotected) header.d=linaro.org header.i=@linaro.org header.b="r7h1mwEv"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BBFBB865AC; Mon, 3 Jul 2023 02:55:15 +0200 (CEST) Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) (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 89AF686377 for ; Mon, 3 Jul 2023 02:55:12 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-682702826ceso516074b3a.1 for ; Sun, 02 Jul 2023 17:55:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688345711; x=1690937711; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date:from:to:cc :subject:date:message-id:reply-to; bh=BLfjCbLl+PZPvvrIoAULasA570dMLKiaEV8yz591SN4=; b=r7h1mwEvV0JUJHECxRCinkdciLCx6AnNEHNyPB1Cy8FcBP4aAG4ch2a7Z7PyTSmTbT 1ARZKgUCKcbbIkwjWhAV470Vl/wJjw/nNtWUwis3CODIeMgNHE/bQjPHQoHMBNjhijzM 4pSymsV0ZmmccFe9hEAEAP3NDPJxxkWHwzPOFpPplUKmhTKFeTXVDSsU9Ah1ikRwodCp pmLPfbHSh4vvGD7J3wpczgoVjeGRxsu1E263DoYsgXi81XV18sJuVvSNRYwMWDT0H+eE HTz1wayS1bBlzB0KjBaFdvBqSMp+wVxRXMHCHuRdZ9Kanf99zTkWOMI2RFNeMtMeKkMg N3YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688345711; x=1690937711; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BLfjCbLl+PZPvvrIoAULasA570dMLKiaEV8yz591SN4=; b=jTzs2IDdBeM+16uthFA9z7qlo5wq6846qRymez5uX182g0u6cR5WiyHamys7m9IlYi 9ahMPiz2CEu5gcgpX0eLc+uqEz5r3FuK5GCDPfN1s97xMqC18fmjwUFItf9//9VMrpBZ C+sKx3FAJ42QnXx/dYPjJ5lDezMiZMUkIT6Y3idIWf8Ldcn7jo9ypQkBbrsVRDM37/JR 7ythHlb5XvPrEgCUch1bQ3TUDDDO1X9W0un18dfKEQOaLyrvzZec21u45rXathQojrz6 aOeCXCMp8JZlKQAuocLxYnv8Y3nH+NSi8qQiZjs8gDxzpcHXKouu0mB2sfOoppfWD07L Ej1w== X-Gm-Message-State: ABy/qLaW5X6OLph/3yyHIM1K6HbQIqFhNJRkOthQFB2v2EyZzZm9GXzw SP7niiejh4KrCOHRvXa/XAbSjg== X-Google-Smtp-Source: APBJJlGvzi0sYYrA74WIGTskfkZ0E1ghjDpcRDPGgDPvDOJHw3uZ3h434MzYkq5Qw03DQT02qEBbeg== X-Received: by 2002:a05:6a00:3103:b0:67f:ff0a:1bbb with SMTP id bi3-20020a056a00310300b0067fff0a1bbbmr10340662pfb.1.1688345710820; Sun, 02 Jul 2023 17:55:10 -0700 (PDT) Received: from laputa ([2400:4050:c3e1:100:b349:4abf:f4cb:7486]) by smtp.gmail.com with ESMTPSA id a20-20020aa78654000000b0066a613c4a58sm11003054pfo.102.2023.07.02.17.55.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jul 2023 17:55:09 -0700 (PDT) Date: Mon, 3 Jul 2023 09:55:07 +0900 From: AKASHI Takahiro To: Simon Glass Cc: trini@konsulko.com, etienne.carriere@st.com, u-boot@lists.denx.de Subject: Re: [PATCH 08/10] cmd: add scmi command for SCMI firmware Message-ID: Mail-Followup-To: AKASHI Takahiro , Simon Glass , trini@konsulko.com, etienne.carriere@st.com, u-boot@lists.denx.de References: <20230628004841.21774-1-takahiro.akashi@linaro.org> <20230628004841.21774-9-takahiro.akashi@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Thu, Jun 29, 2023 at 08:10:00PM +0100, Simon Glass wrote: > Hi AKASHI, > > On Wed, 28 Jun 2023 at 01:49, AKASHI Takahiro > wrote: > > > > This command, "scmi", provides a command line interface to various SCMI > > protocols. It supports at least initially SCMI base protocol with the sub > > command, "base", and is intended mainly for debug purpose. > > > > Signed-off-by: AKASHI Takahiro > > --- > > cmd/Kconfig | 8 ++ > > cmd/Makefile | 1 + > > cmd/scmi.c | 373 +++++++++++++++++++++++++++++++++++++++++++++++++++ > > 3 files changed, 382 insertions(+) > > create mode 100644 cmd/scmi.c > > > > diff --git a/cmd/Kconfig b/cmd/Kconfig > > index 02e54f1e50fe..065470a76295 100644 > > --- a/cmd/Kconfig > > +++ b/cmd/Kconfig > > @@ -2504,6 +2504,14 @@ config CMD_CROS_EC > > a number of sub-commands for performing EC tasks such as > > updating its flash, accessing a small saved context area > > and talking to the I2C bus behind the EC (if there is one). > > + > > +config CMD_SCMI > > + bool "Enable scmi command" > > + depends on SCMI_FIRMWARE > > + default n > > + help > > + This command provides user interfaces to several SCMI protocols, > > + including Base protocol. > > Please mention what is SCMI I will give a full spelling. > > endmenu > > > > menu "Filesystem commands" > > diff --git a/cmd/Makefile b/cmd/Makefile > > index 6c37521b4e2b..826e0b74b587 100644 > > --- a/cmd/Makefile > > +++ b/cmd/Makefile > > @@ -156,6 +156,7 @@ obj-$(CONFIG_CMD_SATA) += sata.o > > obj-$(CONFIG_CMD_NVME) += nvme.o > > obj-$(CONFIG_SANDBOX) += sb.o > > obj-$(CONFIG_CMD_SF) += sf.o > > +obj-$(CONFIG_CMD_SCMI) += scmi.o > > obj-$(CONFIG_CMD_SCSI) += scsi.o disk.o > > obj-$(CONFIG_CMD_SHA1SUM) += sha1sum.o > > obj-$(CONFIG_CMD_SEAMA) += seama.o > > diff --git a/cmd/scmi.c b/cmd/scmi.c > > new file mode 100644 > > index 000000000000..c97f77e97d95 > > --- /dev/null > > +++ b/cmd/scmi.c > > @@ -0,0 +1,373 @@ > > +// SPDX-License-Identifier: GPL-2.0+ > > +/* > > + * SCMI utility command > > + * > > + * Copyright (c) 2023 Linaro Limited > > + * Author: AKASHI Takahiro > > + */ > > + > > +#include > > +#include > > +#include > > +#include /* uclass_get_device */ > > Goes before linux/bitfield.h Can you tell me why? > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +static struct udevice *agent; > > +static struct udevice *base_proto; > > +static const struct scmi_base_ops *ops; > > + > > +struct { > > + enum scmi_std_protocol id; > > + const char *name; > > +} protocol_name[] = { > > + {SCMI_PROTOCOL_ID_BASE, "Base"}, > > + {SCMI_PROTOCOL_ID_POWER_DOMAIN, "Power domain management"}, > > + {SCMI_PROTOCOL_ID_SYSTEM, "System power management"}, > > + {SCMI_PROTOCOL_ID_PERF, "Performance domain management"}, > > + {SCMI_PROTOCOL_ID_CLOCK, "Clock management"}, > > + {SCMI_PROTOCOL_ID_SENSOR, "Sensor management"}, > > + {SCMI_PROTOCOL_ID_RESET_DOMAIN, "Reset domain management"}, > > + {SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN, "Voltage domain management"}, > > +}; > > + > > +/** > > + * scmi_convert_id_to_string() - get the name of SCMI protocol > > + * > > + * @id: Protocol ID > > + * > > + * Get the printable name of the protocol, @id > > + * > > + * Return: Name string on success, NULL on failure > > + */ > > +static const char *scmi_convert_id_to_string(enum scmi_std_protocol id) > > scmi_lookup_id? Not sure your intention. The name above gives us exactly what this function does for pretty printing instead of a number. I think that 'lookup' implies we try to determine if the id exists or not. > > +{ > > + int i; > > + > > + for (i = 0; i < ARRAY_SIZE(protocol_name); i++) > > + if (id == protocol_name[i].id) > > + return protocol_name[i].name; > > + > > + return NULL; > > +} > > + > > +/** > > + * do_scmi_base_info() - get the information of SCMI services > > + * > > + * @cmdtp: Command table > > + * @flag: Command flag > > + * @argc: Number of arguments > > + * @argv: Argument array > > + * > > + * Get the information of SCMI services using various interfaces > > + * provided by the Base protocol. > > + * > > + * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure > > + */ > > +static int do_scmi_base_info(struct cmd_tbl *cmdtp, int flag, int argc, > > + char * const argv[]) > > +{ > > + u32 agent_id, num_protocols; > > + u8 agent_name[SCMI_BASE_NAME_LENGTH_MAX], *protocols; > > + int i, ret; > > + > > + if (argc != 1) > > + return CMD_RET_USAGE; > > + > > + printf("SCMI device: %s\n", agent->name); > > + printf(" protocol version: 0x%x\n", scmi_version(agent)); > > + printf(" # of agents: %d\n", scmi_num_agents(agent)); > > + for (i = 0; i < scmi_num_agents(agent); i++) { > > + ret = (*ops->base_discover_agent)(base_proto, i, &agent_id, > > + agent_name); > > + if (ret) { > > + if (ret != -EOPNOTSUPP) > > + printf("base_discover_agent() failed for id: %d (%d)\n", > > + i, ret); > > + break; > > + } > > + printf(" %c%2d: %s\n", i == scmi_agent_id(agent) ? '>' : ' ', > > + i, agent_name); > > + } > > + printf(" # of protocols: %d\n", scmi_num_protocols(agent)); > > + num_protocols = scmi_num_protocols(agent); > > + protocols = scmi_protocols(agent); > > + if (protocols) > > + for (i = 0; i < num_protocols; i++) > > + printf(" %s\n", > > + scmi_convert_id_to_string(protocols[i])); > > + printf(" vendor: %s\n", scmi_vendor(agent)); > > + printf(" sub vendor: %s\n", scmi_sub_vendor(agent)); > > + printf(" impl version: 0x%x\n", scmi_impl_version(agent)); > > + > > + return CMD_RET_SUCCESS; > > +} > > + > > +/** > > + * do_scmi_base_set_dev() - set access permission to device > > + * > > + * @cmdtp: Command table > > + * @flag: Command flag > > + * @argc: Number of arguments > > + * @argv: Argument array > > + * > > + * Set access permission to device with SCMI_BASE_SET_DEVICE_PERMISSIONS > > + * > > + * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure > > + */ > > +static int do_scmi_base_set_dev(struct cmd_tbl *cmdtp, int flag, int argc, > > + char * const argv[]) > > +{ > > + u32 agent_id, device_id, flags, attributes; > > + char *end; > > + int ret; > > + > > + if (argc != 4) > > + return CMD_RET_USAGE; > > + > > + agent_id = simple_strtoul(argv[1], &end, 16); > > + if (*end != '\0') > > + return CMD_RET_USAGE; > > + > > + device_id = simple_strtoul(argv[2], &end, 16); > > + if (*end != '\0') > > + return CMD_RET_USAGE; > > + > > + flags = simple_strtoul(argv[3], &end, 16); > > + if (*end != '\0') > > + return CMD_RET_USAGE; > > + > > + ret = (*ops->protocol_message_attrs)(base_proto, > > + SCMI_BASE_SET_DEVICE_PERMISSIONS, > > + &attributes); > > + if (ret) { > > + printf("This operation is not supported\n"); > > + return CMD_RET_FAILURE; > > + } > > + > > + ret = (*ops->base_set_device_permissions)(base_proto, agent_id, > > + device_id, flags); > > Please use helpers rather than using ops directly. Okay. -Takahiro Akashi > Regards, > Simon