From patchwork Fri Sep 8 02:51:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 720784 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp548306wrp; Thu, 7 Sep 2023 19:52:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG19gYXNVLoDLGx6KwXyOYUsJ0/P7FaaJ/Q3DgK096km9+9tYasi8kX2VjYB2SNuDTup2En X-Received: by 2002:a1c:7c0b:0:b0:401:bcb4:f119 with SMTP id x11-20020a1c7c0b000000b00401bcb4f119mr1008296wmc.3.1694141553229; Thu, 07 Sep 2023 19:52:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694141553; cv=none; d=google.com; s=arc-20160816; b=xwvtopMRBj2JeBV+NJ3e8IG6qEi8B5v0nV5RYzrGStBKTccJe0urtA8qGvDhna2ytu 3d4PGRK+HaPKKC686kSAgbFHSMuXwYLPLCpsIEfKxdwJDrPzSU+fgeiPaSJid17nqUQS upVW+Rjcfug4PTOZd+cvIB4CBKv5MvkaxNJab2Gu+HNzAtuCxbFpcEM8/pt87p41eIaw X1Bz3WPRU+B/1+EFzpGxiAQLZWiipth8EHBkqGX5S/p4WZlt31yE1kRNzgk26vgA3BEJ zpwI2+RgILpmOQQOzNwJLojPO5+aASKWp1SztZDq1DkyiQtUiVudpsLhwP6CQMAImnhi D9QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=yzkgTxanHuGRyCSlSZ9PXe+d68+baw/Nk/8TmPTifpc=; fh=+s9SE2w9oguEKAMcR35TXtqntCOeVFhiK9u/Kju91lo=; b=HTd2B1tpxCaWriJnHzXdH69r6+iP2Ssv9fE+NVJfBrqiYdEq7REOaaanGFQgwpB1ta m19bz/7urOlwymjg1Wiu5LEL8pHKZ29m/Ejd0CSRlWOQIWT5wffOsE5l+mg5OUNvmxgA 8cBrIr3g7y8a9vbwNa7v6PUfFGIZYMYMEvim9Oe4nOZycXRIoDr7odxyPbbGX+HR3Nvj LZv/n1m9q9Ab3RB+DgNDTrVHTiYAEoBsalVOu2Ld5//iOONcUouKELJ+VSJHptOSNNaq KPmPLv0ybjz19RzQeWHNMmDqQuw8fJ645LZ03g5DD4FnrmfuwvQFdnn0SXZwRoIkeLaS sOyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IH31gBKu; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id q4-20020adff504000000b00317779f81efsi358187wro.392.2023.09.07.19.52.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 19:52:33 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IH31gBKu; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BB62486998; Fri, 8 Sep 2023 04:52:25 +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="IH31gBKu"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E5CAF866CF; Fri, 8 Sep 2023 04:52:23 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) (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 88606866CF for ; Fri, 8 Sep 2023 04:52:20 +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-pl1-x62f.google.com with SMTP id d9443c01a7336-1bf1876ef69so3578375ad.1 for ; Thu, 07 Sep 2023 19:52:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694141539; x=1694746339; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yzkgTxanHuGRyCSlSZ9PXe+d68+baw/Nk/8TmPTifpc=; b=IH31gBKufjmpHUNwG+aHqqIM8f9gBzxYTWkUuH8KE8ekp8cNQeAXd4ZzabBonxrMNL Ht4NVxpP1CBNt8XCmFYCXncVZBXit9B3wQg8O42OikSEeBBB+gGiPGSuCuiTgcFq4d1P mz12PvF6okrBnmaokJ5T9wuTzpg3UEbeMNuzetpB72xjj+GoPL7NBEu8HFcjd+8ybfYM cewr8GfZW9Efecl0GvZC17iK2NkhzRszJXjGOm1yqc32vwMCQpubPurPM+y9zJeiDUHX so7XyJNBZKcX4QZz3sUjQIbFJbCqTaFFQglVbje44aiTBxaatdWF9UEPl5o/7GGUmaLy 58rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694141539; x=1694746339; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yzkgTxanHuGRyCSlSZ9PXe+d68+baw/Nk/8TmPTifpc=; b=U9S6WPYDadoIjU48TH8Zs2yUWVTKsjK4o3GP+6S3OTKa6Vy6QgzjSwVmqSSgJtYJZO DZb8OH5LFgpW0cui82GOwql+U6ZBVzAAkdwNMOxakCm2pwyA5WRRK2bcrAho4NN+cdtm N2IMsQNHFRx7vT1iVh7YWX0J2p7he74UNmP9DhgujU0TwjTUdY1MoGhKy7ITzYdLDbq0 dgAuzFi1VVZJAe/dt9Vh3uoGIYIPb/gFJ234pxw7ch+xO9wQCe6IriIazket+xwkb5Xk +45mvC/DiFV09T3s/5BErraIMySnH8WN2oAm8tK/8/upVCT5IJv8FadQu15d82vLXw+5 Mjwg== X-Gm-Message-State: AOJu0Ywm5G3o3b1Z++t7TwlFPJTn53+EQ9Xj5S98ad3ksak/YS7ABS5s JCLOxsXN9xCPh3ahJw7dgkhnWQ== X-Received: by 2002:a17:902:e84f:b0:1b8:b55d:4cff with SMTP id t15-20020a170902e84f00b001b8b55d4cffmr1517661plg.2.1694141538692; Thu, 07 Sep 2023 19:52:18 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:2d89:7669:ac2d:f09e]) by smtp.gmail.com with ESMTPSA id n9-20020a170902e54900b001c0ce518e98sm417286plf.224.2023.09.07.19.52.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 19:52:18 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org Cc: etienne.carriere@st.com, u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH v3 01/13] scmi: refactor the code to hide a channel from devices Date: Fri, 8 Sep 2023 11:51:26 +0900 Message-Id: <20230908025138.44405-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230908025138.44405-1-takahiro.akashi@linaro.org> References: <20230908025138.44405-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 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 The commit 85dc58289238 ("firmware: scmi: prepare uclass to pass channel reference") added an explicit parameter, channel, but it seems to make the code complex. Hiding this parameter will allow for adding a generic (protocol-agnostic) helper function, i.e. for PROTOCOL_VERSION, in a later patch. Signed-off-by: AKASHI Takahiro Reviewed-by: Simon Glass --- v3 * fix an issue on ST board (reported by Etienne) by taking care of cases where probed devices are children of SCMI protocol device (i.e. clock devices under CCF) See find_scmi_protocol_device(). * move "per_device_plato_auto" to a succeeding right patch v2 * new patch --- drivers/clk/clk_scmi.c | 27 +--- drivers/firmware/scmi/scmi_agent-uclass.c | 160 +++++++++++----------- drivers/power/regulator/scmi_regulator.c | 27 +--- drivers/reset/reset-scmi.c | 19 +-- include/scmi_agent.h | 15 +- 5 files changed, 103 insertions(+), 145 deletions(-) diff --git a/drivers/clk/clk_scmi.c b/drivers/clk/clk_scmi.c index d172fed24c9d..34a49363a51a 100644 --- a/drivers/clk/clk_scmi.c +++ b/drivers/clk/clk_scmi.c @@ -13,17 +13,8 @@ #include #include -/** - * struct scmi_clk_priv - Private data for SCMI clocks - * @channel: Reference to the SCMI channel to use - */ -struct scmi_clk_priv { - struct scmi_channel *channel; -}; - static int scmi_clk_get_num_clock(struct udevice *dev, size_t *num_clocks) { - struct scmi_clk_priv *priv = dev_get_priv(dev); struct scmi_clk_protocol_attr_out out; struct scmi_msg msg = { .protocol_id = SCMI_PROTOCOL_ID_CLOCK, @@ -33,7 +24,7 @@ static int scmi_clk_get_num_clock(struct udevice *dev, size_t *num_clocks) }; int ret; - ret = devm_scmi_process_msg(dev, priv->channel, &msg); + ret = devm_scmi_process_msg(dev, &msg); if (ret) return ret; @@ -44,7 +35,6 @@ static int scmi_clk_get_num_clock(struct udevice *dev, size_t *num_clocks) static int scmi_clk_get_attibute(struct udevice *dev, int clkid, char **name) { - struct scmi_clk_priv *priv = dev_get_priv(dev); struct scmi_clk_attribute_in in = { .clock_id = clkid, }; @@ -59,7 +49,7 @@ static int scmi_clk_get_attibute(struct udevice *dev, int clkid, char **name) }; int ret; - ret = devm_scmi_process_msg(dev, priv->channel, &msg); + ret = devm_scmi_process_msg(dev, &msg); if (ret) return ret; @@ -70,7 +60,6 @@ static int scmi_clk_get_attibute(struct udevice *dev, int clkid, char **name) static int scmi_clk_gate(struct clk *clk, int enable) { - struct scmi_clk_priv *priv = dev_get_priv(clk->dev); struct scmi_clk_state_in in = { .clock_id = clk->id, .attributes = enable, @@ -81,7 +70,7 @@ static int scmi_clk_gate(struct clk *clk, int enable) in, out); int ret; - ret = devm_scmi_process_msg(clk->dev, priv->channel, &msg); + ret = devm_scmi_process_msg(clk->dev, &msg); if (ret) return ret; @@ -100,7 +89,6 @@ static int scmi_clk_disable(struct clk *clk) static ulong scmi_clk_get_rate(struct clk *clk) { - struct scmi_clk_priv *priv = dev_get_priv(clk->dev); struct scmi_clk_rate_get_in in = { .clock_id = clk->id, }; @@ -110,7 +98,7 @@ static ulong scmi_clk_get_rate(struct clk *clk) in, out); int ret; - ret = devm_scmi_process_msg(clk->dev, priv->channel, &msg); + ret = devm_scmi_process_msg(clk->dev, &msg); if (ret < 0) return ret; @@ -123,7 +111,6 @@ static ulong scmi_clk_get_rate(struct clk *clk) static ulong scmi_clk_set_rate(struct clk *clk, ulong rate) { - struct scmi_clk_priv *priv = dev_get_priv(clk->dev); struct scmi_clk_rate_set_in in = { .clock_id = clk->id, .flags = SCMI_CLK_RATE_ROUND_CLOSEST, @@ -136,7 +123,7 @@ static ulong scmi_clk_set_rate(struct clk *clk, ulong rate) in, out); int ret; - ret = devm_scmi_process_msg(clk->dev, priv->channel, &msg); + ret = devm_scmi_process_msg(clk->dev, &msg); if (ret < 0) return ret; @@ -149,12 +136,11 @@ static ulong scmi_clk_set_rate(struct clk *clk, ulong rate) static int scmi_clk_probe(struct udevice *dev) { - struct scmi_clk_priv *priv = dev_get_priv(dev); struct clk *clk; size_t num_clocks, i; int ret; - ret = devm_scmi_of_get_channel(dev, &priv->channel); + ret = devm_scmi_of_get_channel(dev); if (ret) return ret; @@ -205,5 +191,4 @@ U_BOOT_DRIVER(scmi_clock) = { .id = UCLASS_CLK, .ops = &scmi_clk_ops, .probe = scmi_clk_probe, - .priv_auto = sizeof(struct scmi_clk_priv *), }; diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c b/drivers/firmware/scmi/scmi_agent-uclass.c index 02de692d66f3..feb31809e715 100644 --- a/drivers/firmware/scmi/scmi_agent-uclass.c +++ b/drivers/firmware/scmi/scmi_agent-uclass.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -51,77 +52,23 @@ int scmi_to_linux_errno(s32 scmi_code) return -EPROTO; } -/* - * SCMI agent devices binds devices of various uclasses depeding on - * the FDT description. scmi_bind_protocol() is a generic bind sequence - * called by the uclass at bind stage, that is uclass post_bind. - */ -static int scmi_bind_protocols(struct udevice *dev) +static struct udevice *find_scmi_protocol_device(struct udevice *dev) { - int ret = 0; - ofnode node; - const char *name; - - dev_for_each_subnode(node, dev) { - struct driver *drv = NULL; - u32 protocol_id; - - if (!ofnode_is_enabled(node)) - continue; - - if (ofnode_read_u32(node, "reg", &protocol_id)) - continue; + struct udevice *parent = NULL, *protocol; - name = ofnode_get_name(node); - switch (protocol_id) { - case SCMI_PROTOCOL_ID_CLOCK: - if (CONFIG_IS_ENABLED(CLK_SCMI)) - drv = DM_DRIVER_GET(scmi_clock); - break; - case SCMI_PROTOCOL_ID_RESET_DOMAIN: - if (IS_ENABLED(CONFIG_RESET_SCMI)) - drv = DM_DRIVER_GET(scmi_reset_domain); - break; - case SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN: - if (IS_ENABLED(CONFIG_DM_REGULATOR_SCMI)) { - node = ofnode_find_subnode(node, "regulators"); - if (!ofnode_valid(node)) { - dev_err(dev, "no regulators node\n"); - return -ENXIO; - } - drv = DM_DRIVER_GET(scmi_voltage_domain); - } - break; - default: - break; - } - - if (!drv) { - dev_dbg(dev, "Ignore unsupported SCMI protocol %#x\n", - protocol_id); - continue; - } - - ret = device_bind(dev, drv, name, NULL, node, NULL); - if (ret) + for (protocol = dev; protocol; protocol = parent) { + parent = dev_get_parent(protocol); + if (!parent || + device_get_uclass_id(parent) == UCLASS_SCMI_AGENT) break; } - return ret; -} - -static struct udevice *find_scmi_transport_device(struct udevice *dev) -{ - struct udevice *parent = dev; - - do { - parent = dev_get_parent(parent); - } while (parent && device_get_uclass_id(parent) != UCLASS_SCMI_AGENT); - - if (!parent) + if (!parent) { dev_err(dev, "Invalid SCMI device, agent not found\n"); + return NULL; + } - return parent; + return protocol; } static const struct scmi_agent_ops *transport_dev_ops(struct udevice *dev) @@ -129,43 +76,90 @@ static const struct scmi_agent_ops *transport_dev_ops(struct udevice *dev) return (const struct scmi_agent_ops *)dev->driver->ops; } -int devm_scmi_of_get_channel(struct udevice *dev, struct scmi_channel **channel) +/** + * scmi_of_get_channel() - Get SCMI channel handle + * + * @dev: SCMI agent device + * @channel: Output reference to the SCMI channel upon success + * + * On return, @channel will be set. + * Return 0 on success and a negative errno on failure + */ +static int scmi_of_get_channel(struct udevice *dev, struct scmi_channel **channel) { - struct udevice *parent; + const struct scmi_agent_ops *ops; - parent = find_scmi_transport_device(dev); - if (!parent) + ops = transport_dev_ops(dev); + if (ops->of_get_channel) + return ops->of_get_channel(dev, channel); + else + return -EPROTONOSUPPORT; +} + +int devm_scmi_of_get_channel(struct udevice *dev) +{ + struct udevice *protocol; + struct scmi_agent_proto_priv *priv; + int ret; + + protocol = find_scmi_protocol_device(dev); + if (!protocol) return -ENODEV; - if (transport_dev_ops(parent)->of_get_channel) - return transport_dev_ops(parent)->of_get_channel(parent, channel); + priv = dev_get_parent_priv(protocol); + ret = scmi_of_get_channel(protocol->parent, &priv->channel); + if (ret == -EPROTONOSUPPORT) { + /* Drivers without a get_channel operator don't need a channel ref */ + priv->channel = NULL; - /* Drivers without a get_channel operator don't need a channel ref */ - *channel = NULL; + return 0; + } - return 0; + return ret; } -int devm_scmi_process_msg(struct udevice *dev, struct scmi_channel *channel, - struct scmi_msg *msg) +/** + * scmi_process_msg() - Send and process an SCMI message + * + * Send a message to an SCMI server. + * Caller sets scmi_msg::out_msg_sz to the output message buffer size. + * + * @dev: SCMI agent device + * @channel: Communication channel for the device + * @msg: Message structure reference + * + * On return, scmi_msg::out_msg_sz stores the response payload size. + * Return: 0 on success and a negative errno on failure + */ +static int scmi_process_msg(struct udevice *dev, struct scmi_channel *channel, + struct scmi_msg *msg) { const struct scmi_agent_ops *ops; - struct udevice *parent; - parent = find_scmi_transport_device(dev); - if (!parent) - return -ENODEV; + ops = transport_dev_ops(dev); + if (ops->process_msg) + return ops->process_msg(dev, channel, msg); + else + return -EPROTONOSUPPORT; +} - ops = transport_dev_ops(parent); +int devm_scmi_process_msg(struct udevice *dev, struct scmi_msg *msg) +{ + struct udevice *protocol; + struct scmi_agent_proto_priv *priv; - if (ops->process_msg) - return ops->process_msg(parent, channel, msg); + protocol = find_scmi_protocol_device(dev); + if (!protocol) + return -ENODEV; + + priv = dev_get_parent_priv(protocol); - return -EPROTONOSUPPORT; + return scmi_process_msg(protocol->parent, priv->channel, msg); } UCLASS_DRIVER(scmi_agent) = { .id = UCLASS_SCMI_AGENT, .name = "scmi_agent", .post_bind = scmi_bind_protocols, + .per_child_auto = sizeof(struct scmi_agent_proto_priv *), }; diff --git a/drivers/power/regulator/scmi_regulator.c b/drivers/power/regulator/scmi_regulator.c index 801148036ff6..08918b20872c 100644 --- a/drivers/power/regulator/scmi_regulator.c +++ b/drivers/power/regulator/scmi_regulator.c @@ -25,18 +25,9 @@ struct scmi_regulator_platdata { u32 domain_id; }; -/** - * struct scmi_regulator_priv - Private data for SCMI voltage regulator - * @channel: Reference to the SCMI channel to use - */ -struct scmi_regulator_priv { - struct scmi_channel *channel; -}; - static int scmi_voltd_set_enable(struct udevice *dev, bool enable) { struct scmi_regulator_platdata *pdata = dev_get_plat(dev); - struct scmi_regulator_priv *priv = dev_get_priv(dev); struct scmi_voltd_config_set_in in = { .domain_id = pdata->domain_id, .config = enable ? SCMI_VOLTD_CONFIG_ON : SCMI_VOLTD_CONFIG_OFF, @@ -47,7 +38,7 @@ static int scmi_voltd_set_enable(struct udevice *dev, bool enable) in, out); int ret; - ret = devm_scmi_process_msg(dev, priv->channel, &msg); + ret = devm_scmi_process_msg(dev, &msg); if (ret) return ret; @@ -57,7 +48,6 @@ static int scmi_voltd_set_enable(struct udevice *dev, bool enable) static int scmi_voltd_get_enable(struct udevice *dev) { struct scmi_regulator_platdata *pdata = dev_get_plat(dev); - struct scmi_regulator_priv *priv = dev_get_priv(dev); struct scmi_voltd_config_get_in in = { .domain_id = pdata->domain_id, }; @@ -67,7 +57,7 @@ static int scmi_voltd_get_enable(struct udevice *dev) in, out); int ret; - ret = devm_scmi_process_msg(dev, priv->channel, &msg); + ret = devm_scmi_process_msg(dev, &msg); if (ret < 0) return ret; @@ -80,7 +70,6 @@ static int scmi_voltd_get_enable(struct udevice *dev) static int scmi_voltd_set_voltage_level(struct udevice *dev, int uV) { - struct scmi_regulator_priv *priv = dev_get_priv(dev); struct scmi_regulator_platdata *pdata = dev_get_plat(dev); struct scmi_voltd_level_set_in in = { .domain_id = pdata->domain_id, @@ -92,7 +81,7 @@ static int scmi_voltd_set_voltage_level(struct udevice *dev, int uV) in, out); int ret; - ret = devm_scmi_process_msg(dev, priv->channel, &msg); + ret = devm_scmi_process_msg(dev, &msg); if (ret < 0) return ret; @@ -101,7 +90,6 @@ static int scmi_voltd_set_voltage_level(struct udevice *dev, int uV) static int scmi_voltd_get_voltage_level(struct udevice *dev) { - struct scmi_regulator_priv *priv = dev_get_priv(dev); struct scmi_regulator_platdata *pdata = dev_get_plat(dev); struct scmi_voltd_level_get_in in = { .domain_id = pdata->domain_id, @@ -112,7 +100,7 @@ static int scmi_voltd_get_voltage_level(struct udevice *dev) in, out); int ret; - ret = devm_scmi_process_msg(dev, priv->channel, &msg); + ret = devm_scmi_process_msg(dev, &msg); if (ret < 0) return ret; @@ -140,7 +128,6 @@ static int scmi_regulator_of_to_plat(struct udevice *dev) static int scmi_regulator_probe(struct udevice *dev) { struct scmi_regulator_platdata *pdata = dev_get_plat(dev); - struct scmi_regulator_priv *priv = dev_get_priv(dev); struct scmi_voltd_attr_in in = { 0 }; struct scmi_voltd_attr_out out = { 0 }; struct scmi_msg scmi_msg = { @@ -153,14 +140,14 @@ static int scmi_regulator_probe(struct udevice *dev) }; int ret; - ret = devm_scmi_of_get_channel(dev->parent, &priv->channel); + ret = devm_scmi_of_get_channel(dev); if (ret) return ret; /* Check voltage domain is known from SCMI server */ in.domain_id = pdata->domain_id; - ret = devm_scmi_process_msg(dev, priv->channel, &scmi_msg); + ret = devm_scmi_process_msg(dev, &scmi_msg); if (ret) { dev_err(dev, "Failed to query voltage domain %u: %d\n", pdata->domain_id, ret); @@ -184,7 +171,6 @@ U_BOOT_DRIVER(scmi_regulator) = { .probe = scmi_regulator_probe, .of_to_plat = scmi_regulator_of_to_plat, .plat_auto = sizeof(struct scmi_regulator_platdata), - .priv_auto = sizeof(struct scmi_regulator_priv *), }; static int scmi_regulator_bind(struct udevice *dev) @@ -209,4 +195,5 @@ U_BOOT_DRIVER(scmi_voltage_domain) = { .name = "scmi_voltage_domain", .id = UCLASS_NOP, .bind = scmi_regulator_bind, + .per_child_auto = sizeof(struct scmi_agent_proto_priv *), }; diff --git a/drivers/reset/reset-scmi.c b/drivers/reset/reset-scmi.c index 122556162ec3..b76711f0a8fb 100644 --- a/drivers/reset/reset-scmi.c +++ b/drivers/reset/reset-scmi.c @@ -13,17 +13,8 @@ #include #include -/** - * struct scmi_reset_priv - Private data for SCMI reset controller - * @channel: Reference to the SCMI channel to use - */ -struct scmi_reset_priv { - struct scmi_channel *channel; -}; - static int scmi_reset_set_level(struct reset_ctl *rst, bool assert_not_deassert) { - struct scmi_reset_priv *priv = dev_get_priv(rst->dev); struct scmi_rd_reset_in in = { .domain_id = rst->id, .flags = assert_not_deassert ? SCMI_RD_RESET_FLAG_ASSERT : 0, @@ -35,7 +26,7 @@ static int scmi_reset_set_level(struct reset_ctl *rst, bool assert_not_deassert) in, out); int ret; - ret = devm_scmi_process_msg(rst->dev, priv->channel, &msg); + ret = devm_scmi_process_msg(rst->dev, &msg); if (ret) return ret; @@ -54,7 +45,6 @@ static int scmi_reset_deassert(struct reset_ctl *rst) static int scmi_reset_request(struct reset_ctl *rst) { - struct scmi_reset_priv *priv = dev_get_priv(rst->dev); struct scmi_rd_attr_in in = { .domain_id = rst->id, }; @@ -68,7 +58,7 @@ static int scmi_reset_request(struct reset_ctl *rst) * We don't really care about the attribute, just check * the reset domain exists. */ - ret = devm_scmi_process_msg(rst->dev, priv->channel, &msg); + ret = devm_scmi_process_msg(rst->dev, &msg); if (ret) return ret; @@ -83,9 +73,7 @@ static const struct reset_ops scmi_reset_domain_ops = { static int scmi_reset_probe(struct udevice *dev) { - struct scmi_reset_priv *priv = dev_get_priv(dev); - - return devm_scmi_of_get_channel(dev, &priv->channel); + return devm_scmi_of_get_channel(dev); } U_BOOT_DRIVER(scmi_reset_domain) = { @@ -93,5 +81,4 @@ U_BOOT_DRIVER(scmi_reset_domain) = { .id = UCLASS_RESET, .ops = &scmi_reset_domain_ops, .probe = scmi_reset_probe, - .priv_auto = sizeof(struct scmi_reset_priv *), }; diff --git a/include/scmi_agent.h b/include/scmi_agent.h index ee6286366df7..577892029ff8 100644 --- a/include/scmi_agent.h +++ b/include/scmi_agent.h @@ -15,6 +15,14 @@ struct udevice; struct scmi_channel; +/** + * struct scmi_agent_proto_priv - Private data in device for SCMI agent + * @channel: Reference to the SCMI channel to use + */ +struct scmi_agent_proto_priv { + struct scmi_channel *channel; +}; + /* * struct scmi_msg - Context of a SCMI message sent and the response received * @@ -49,10 +57,9 @@ struct scmi_msg { * devm_scmi_of_get_channel() - Get SCMI channel handle from SCMI agent DT node * * @dev: Device requesting a channel - * @channel: Output reference to the SCMI channel upon success * @return 0 on success and a negative errno on failure */ -int devm_scmi_of_get_channel(struct udevice *dev, struct scmi_channel **channel); +int devm_scmi_of_get_channel(struct udevice *dev); /** * devm_scmi_process_msg() - Send and process an SCMI message @@ -62,12 +69,10 @@ int devm_scmi_of_get_channel(struct udevice *dev, struct scmi_channel **channel) * On return, scmi_msg::out_msg_sz stores the response payload size. * * @dev: SCMI device - * @channel: Communication channel for the device * @msg: Message structure reference * Return: 0 on success and a negative errno on failure */ -int devm_scmi_process_msg(struct udevice *dev, struct scmi_channel *channel, - struct scmi_msg *msg); +int devm_scmi_process_msg(struct udevice *dev, struct scmi_msg *msg); /** * scmi_to_linux_errno() - Convert an SCMI error code into a Linux errno code From patchwork Fri Sep 8 02:51:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 720785 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp548363wrp; Thu, 7 Sep 2023 19:52:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFVsxHANZo2s667T4gpYp7IegrCjMBr3P3CZbGSlewoqFG3rJCUdfBlDpMFlIbtcQuiyUGs X-Received: by 2002:adf:ffd0:0:b0:313:f463:9d40 with SMTP id x16-20020adfffd0000000b00313f4639d40mr722241wrs.65.1694141572936; Thu, 07 Sep 2023 19:52:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694141572; cv=none; d=google.com; s=arc-20160816; b=I2gUuSLnAl6N5SdOdp3B/LUvOJNfovZ1y2bF1vIC+dKMm+F0pcDBKJhKddnZWbU2Zv M+ObQ7rnt6Smbs7f4NIEhfEWCrk6vopNVjqQw5PU5Q8Ko9dmHNEgZxrnOF6QwDEbqS0h PJkwwYrK42xB39sfB3bZlEHAh5v1j/pPWfocuG8xlNl6bm0laCxANpL8Pj7o12lF2KUx ryd9FNE4hvaR8GHFK8c/sifMHSYlkZw9IsMvHJ6vKzXZYLF2hrOAaY0ul4OCWIA718Zz 3LwO5LZqANjBgvx8r96rPpWYkeK8dmdU6iTEG8dWZ2WrNMETM7KRLQCNeNrx+nW70Sbw +ywA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YP5GypidPwfsg4gfiM/WuMY1RsNXxacFHC8ieH3JDUo=; fh=+s9SE2w9oguEKAMcR35TXtqntCOeVFhiK9u/Kju91lo=; b=VDGiMHEzmiyHL/leoKhQtD7QtSAYM9vPvJPynmxd9Dfbujd5T05gCnF+fm2pN/myBi F+0Vw/HteIg1YoWMg1lKDl4OGPJ/D0aitZBGMmEo3vSQaTOPlLiiAlaqm+rvhRsSRWmB ixJsZTImbUOhONx4zIiLRc26CK4yamgs8CYeWhvpX74tRVx59ZyA1pBxFWVMwy+EZZNq JKSsQDsbtrkD5XgFKEUKlI6pSWb/NWabMgzjnOODWJkI7BYNxfWpTAwXSD2a3FI/j4Jp gc7ROxfVJLctgoI5LJswE7FUUiANgCWshL6ym35yw/biimMo1D+P97s1Sidz4F4UeKmd VOPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lKb+Dsq1; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id c14-20020a5d63ce000000b00318082f5285si350820wrw.416.2023.09.07.19.52.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 19:52:52 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lKb+Dsq1; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B6F2C868D1; Fri, 8 Sep 2023 04:52:28 +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="lKb+Dsq1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1C8648676C; Fri, 8 Sep 2023 04:52:27 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) (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 E3B9386907 for ; Fri, 8 Sep 2023 04:52:22 +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-pl1-x62d.google.com with SMTP id d9443c01a7336-1b89b0c73d7so3003155ad.1 for ; Thu, 07 Sep 2023 19:52:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694141541; x=1694746341; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YP5GypidPwfsg4gfiM/WuMY1RsNXxacFHC8ieH3JDUo=; b=lKb+Dsq1HljNonoEI5Z46zTbXfcWkKiHXHHb2yl9C1uu1ah3ucnqolrNhz17nN0GbN ZWGoKK2/+jGoEHrbTL3DumCYsCQC/4oSWFdoBPp4cVpEokSleUqO0HvszmPgKeN64HQV qcB3TaVFWECMt6SEA7brevR+TkrafWX9xr4DGYzdkeDNrqy3y6zRgHiVFFj1su9ij+6B jwmf453ubaovMG/4kCtQJakH4Zs4S5h6+qq5VlwuxoMYDhycIEsQZmorXsBHbNqXL+Tj Lnc4+681gz3nB23LiaDgeUt9TJ1ifvE6ul/8ltug/oKRS46IpZTtHuFBGLj60ucamSyO pI0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694141541; x=1694746341; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YP5GypidPwfsg4gfiM/WuMY1RsNXxacFHC8ieH3JDUo=; b=mxOqt9kJAg9ccwfTR5kQkPMEZIVF6j4w1Kc27g8UOmJuGDh01eUumOliczdJ2QW4iP krDoVdImyy3cZZIKXVOco1jSQ1n3qxEBrH0gHUV1444fxZT+XZLL78KPKGFY7ah7lJPF iF1sr+c65FAOjKMtIP424nvO6X/xwM/z+QGjs3Y7evIXEZKyquWBAvy0JIs0BjjD/+PN SIFStpdJ9qoCv2lC5xO9ZuQT+5BLwWlFYOXLmZ0hLzcMOo2+cBmKeCxGHPK9HM802mkJ 51e58ZB2lzNfSnClgB4T0PoQtgZHgsdCC7cP/2xtXYkmJBKImAwiylkV4kAKamSBHNUR vHBA== X-Gm-Message-State: AOJu0Yxqfu66JIuPP0xnJR5gT5VYjvvOVsABkgc9jS4+Est05GPtYuoG yOHCF3SxvGix3826mRkvPVWV+A== X-Received: by 2002:a17:903:41c2:b0:1c0:ecbb:182e with SMTP id u2-20020a17090341c200b001c0ecbb182emr1494471ple.2.1694141541028; Thu, 07 Sep 2023 19:52:21 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:2d89:7669:ac2d:f09e]) by smtp.gmail.com with ESMTPSA id n9-20020a170902e54900b001c0ce518e98sm417286plf.224.2023.09.07.19.52.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 19:52:20 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org Cc: etienne.carriere@st.com, u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH v3 02/13] firmware: scmi: implement SCMI base protocol Date: Fri, 8 Sep 2023 11:51:27 +0900 Message-Id: <20230908025138.44405-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230908025138.44405-1-takahiro.akashi@linaro.org> References: <20230908025138.44405-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 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 SCMI base protocol is mandatory according to the SCMI specification. With this patch, SCMI base protocol can be accessed via SCMI transport layers. All the commands, except SCMI_BASE_NOTIFY_ERRORS, are supported. This is because U-Boot doesn't support interrupts and the current transport layers are not able to handle asynchronous messages properly. Signed-off-by: AKASHI Takahiro Reviewed-by: Simon Glass --- v3 * strncpy (TODO) * remove a duplicated function prototype * use newly-allocated memory when return vendor name or agent name * revise function descriptions in a header v2 * add helper functions, removing direct uses of ops * add function descriptions for each of functions in ops --- drivers/firmware/scmi/Makefile | 1 + drivers/firmware/scmi/base.c | 656 +++++++++++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/scmi_protocols.h | 351 ++++++++++++++++++ 4 files changed, 1009 insertions(+) create mode 100644 drivers/firmware/scmi/base.c diff --git a/drivers/firmware/scmi/Makefile b/drivers/firmware/scmi/Makefile index b2ff483c75a1..1a23d4981709 100644 --- a/drivers/firmware/scmi/Makefile +++ b/drivers/firmware/scmi/Makefile @@ -1,4 +1,5 @@ obj-y += scmi_agent-uclass.o +obj-y += base.o obj-y += smt.o obj-$(CONFIG_SCMI_AGENT_SMCCC) += smccc_agent.o obj-$(CONFIG_SCMI_AGENT_MAILBOX) += mailbox_agent.o diff --git a/drivers/firmware/scmi/base.c b/drivers/firmware/scmi/base.c new file mode 100644 index 000000000000..6b99f36d0697 --- /dev/null +++ b/drivers/firmware/scmi/base.c @@ -0,0 +1,656 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * SCMI Base protocol as U-Boot device + * + * Copyright (C) 2023 Linaro Limited + * author: AKASHI Takahiro + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * scmi_generic_protocol_version - get protocol version + * @dev: SCMI device + * @id: SCMI protocol ID + * @version: Pointer to SCMI protocol version + * + * Obtain the protocol version number in @version. + * + * Return: 0 on success, error code otherwise + */ +int scmi_generic_protocol_version(struct udevice *dev, + enum scmi_std_protocol id, u32 *version) +{ + struct scmi_protocol_version_out out; + struct scmi_msg msg = { + .protocol_id = id, + .message_id = SCMI_PROTOCOL_VERSION, + .out_msg = (u8 *)&out, + .out_msg_sz = sizeof(out), + }; + int ret; + + ret = devm_scmi_process_msg(dev, &msg); + if (ret) + return ret; + if (out.status) + return scmi_to_linux_errno(out.status); + + *version = out.version; + + return 0; +} + +/** + * scmi_base_protocol_version_int - get Base protocol version + * @dev: SCMI device + * @version: Pointer to SCMI protocol version + * + * Obtain the protocol version number in @version for Base protocol. + * + * Return: 0 on success, error code otherwise + */ +static int scmi_base_protocol_version_int(struct udevice *dev, u32 *version) +{ + return scmi_generic_protocol_version(dev, SCMI_PROTOCOL_ID_BASE, + version); +} + +/** + * scmi_protocol_attrs_int - get protocol attributes + * @dev: SCMI device + * @num_agents: Number of SCMI agents + * @num_protocols: Number of SCMI protocols + * + * Obtain the protocol attributes, the number of agents and the number + * of protocols, in @num_agents and @num_protocols respectively, that + * the device provides. + * + * Return: 0 on success, error code otherwise + */ +static int scmi_protocol_attrs_int(struct udevice *dev, u32 *num_agents, + u32 *num_protocols) +{ + struct scmi_protocol_attrs_out out; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_BASE, + .message_id = SCMI_PROTOCOL_ATTRIBUTES, + .out_msg = (u8 *)&out, + .out_msg_sz = sizeof(out), + }; + int ret; + + ret = devm_scmi_process_msg(dev, &msg); + if (ret) + return ret; + if (out.status) + return scmi_to_linux_errno(out.status); + + *num_agents = SCMI_PROTOCOL_ATTRS_NUM_AGENTS(out.attributes); + *num_protocols = SCMI_PROTOCOL_ATTRS_NUM_PROTOCOLS(out.attributes); + + return 0; +} + +/** + * scmi_protocol_message_attrs_int - get message-specific attributes + * @dev: SCMI device + * @message_id: SCMI message ID + * @attributes: Message-specific attributes + * + * Obtain the message-specific attributes in @attributes. + * This command succeeds if the message is implemented and available. + * + * Return: 0 on success, error code otherwise + */ +static int scmi_protocol_message_attrs_int(struct udevice *dev, u32 message_id, + u32 *attributes) +{ + struct scmi_protocol_msg_attrs_out out; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_BASE, + .message_id = SCMI_PROTOCOL_MESSAGE_ATTRIBUTES, + .in_msg = (u8 *)&message_id, + .in_msg_sz = sizeof(message_id), + .out_msg = (u8 *)&out, + .out_msg_sz = sizeof(out), + }; + int ret; + + ret = devm_scmi_process_msg(dev, &msg); + if (ret) + return ret; + if (out.status) + return scmi_to_linux_errno(out.status); + + *attributes = out.attributes; + + return 0; +} + +/** + * scmi_base_discover_vendor_int - get vendor name + * @dev: SCMI device + * @vendor: Pointer to vendor name + * + * Obtain the vendor's name in @vendor. + * It is a caller's responsibility to free @vendor. + * + * Return: 0 on success, error code otherwise + */ +static int scmi_base_discover_vendor_int(struct udevice *dev, u8 **vendor) +{ + struct scmi_base_discover_vendor_out out; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_BASE, + .message_id = SCMI_BASE_DISCOVER_VENDOR, + .out_msg = (u8 *)&out, + .out_msg_sz = sizeof(out), + }; + int ret; + + if (!vendor) + return -EINVAL; + + ret = devm_scmi_process_msg(dev, &msg); + if (ret) + return ret; + if (out.status) + return scmi_to_linux_errno(out.status); + + *vendor = strdup(out.vendor_identifier); + if (!*vendor) + return -ENOMEM; + + return 0; +} + +/** + * scmi_base_discover_sub_vendor_int - get sub-vendor name + * @dev: SCMI device + * @sub_vendor: Pointer to sub-vendor name + * + * Obtain the sub-vendor's name in @sub_vendor. + * It is a caller's responsibility to free @sub_vendor. + * + * Return: 0 on success, error code otherwise + */ +static int scmi_base_discover_sub_vendor_int(struct udevice *dev, + u8 **sub_vendor) +{ + struct scmi_base_discover_vendor_out out; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_BASE, + .message_id = SCMI_BASE_DISCOVER_SUB_VENDOR, + .out_msg = (u8 *)&out, + .out_msg_sz = sizeof(out), + }; + int ret; + + if (!sub_vendor) + return -EINVAL; + + ret = devm_scmi_process_msg(dev, &msg); + if (ret) + return ret; + if (out.status) + return scmi_to_linux_errno(out.status); + + *sub_vendor = strdup(out.vendor_identifier); + if (!*sub_vendor) + return -ENOMEM; + + return 0; +} + +/** + * scmi_base_discover_impl_version_int - get implementation version + * @dev: SCMI device + * @impl_version: Pointer to implementation version + * + * Obtain the implementation version number in @impl_version. + * + * Return: 0 on success, error code otherwise + */ +static int scmi_base_discover_impl_version_int(struct udevice *dev, + u32 *impl_version) +{ + struct scmi_base_discover_impl_version_out out; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_BASE, + .message_id = SCMI_BASE_DISCOVER_IMPL_VERSION, + .out_msg = (u8 *)&out, + .out_msg_sz = sizeof(out), + }; + int ret; + + ret = devm_scmi_process_msg(dev, &msg); + if (ret) + return ret; + if (out.status) + return scmi_to_linux_errno(out.status); + + *impl_version = out.impl_version; + + return 0; +} + +/** + * scmi_base_discover_list_protocols_int - get list of protocols + * @dev: SCMI device + * @protocols: Pointer to array of SCMI protocols + * + * Obtain the list of protocols provided in @protocols. + * The number of elements in @protocols always match to the number of + * protocols returned by smci_protocol_attrs() when this function succeeds. + * It is a caller's responsibility to free @protocols. + * + * Return: the number of protocols in @protocols on success, error code otherwise + */ +static int scmi_base_discover_list_protocols_int(struct udevice *dev, + u8 **protocols) +{ + struct scmi_base_discover_list_protocols_out out; + int cur; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_BASE, + .message_id = SCMI_BASE_DISCOVER_LIST_PROTOCOLS, + .in_msg = (u8 *)&cur, + .in_msg_sz = sizeof(cur), + .out_msg = (u8 *)&out, + .out_msg_sz = sizeof(out), + }; + u32 num_agents, num_protocols; + u8 *buf; + int i, ret; + + ret = scmi_base_protocol_attrs(dev, &num_agents, &num_protocols); + if (ret) + return ret; + + buf = calloc(sizeof(u8), num_protocols); + if (!buf) + return -ENOMEM; + + cur = 0; + do { + ret = devm_scmi_process_msg(dev, &msg); + if (ret) + goto err; + if (out.status) { + ret = scmi_to_linux_errno(out.status); + goto err; + } + + for (i = 0; i < out.num_protocols; i++, cur++) + buf[cur] = out.protocols[i / 4] >> ((i % 4) * 8); + } while (cur < num_protocols); + + *protocols = buf; + + return num_protocols; +err: + free(buf); + + return ret; +} + +/** + * scmi_base_discover_agent_int - identify agent + * @dev: SCMI device + * @agent_id: SCMI agent ID + * @ret_agent_id: Pointer to SCMI agent ID + * @name: Pointer to SCMI agent name + * + * Obtain the agent's name in @name. If @agent_id is equal to 0xffffffff, + * this function returns the caller's agent id in @ret_agent_id. + * It is a caller's responsibility to free @name. + * + * Return: 0 on success, error code otherwise + */ +static int scmi_base_discover_agent_int(struct udevice *dev, u32 agent_id, + u32 *ret_agent_id, u8 **name) +{ + struct scmi_base_discover_agent_out out; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_BASE, + .message_id = SCMI_BASE_DISCOVER_AGENT, + .in_msg = (u8 *)&agent_id, + .in_msg_sz = sizeof(agent_id), + .out_msg = (u8 *)&out, + .out_msg_sz = sizeof(out), + }; + int ret; + + ret = devm_scmi_process_msg(dev, &msg); + if (ret) + return ret; + if (out.status) + return scmi_to_linux_errno(out.status); + + if (ret_agent_id) + *ret_agent_id = out.agent_id; + if (name) { + *name = strdup(out.name); + if (!*name) + return -ENOMEM; + } + + return 0; +} + +/** + * scmi_base_set_device_permissions_int - configure access permission to device + * @dev: SCMI device + * @agent_id: SCMI agent ID + * @device_id: ID of device to access + * @flags: A set of flags + * + * Ask for allowing or denying access permission to the device, @device_id. + * The meaning of @flags is defined in SCMI specification. + * + * Return: 0 on success, error code otherwise + */ +static int scmi_base_set_device_permissions_int(struct udevice *dev, u32 agent_id, + u32 device_id, u32 flags) +{ + struct scmi_base_set_device_permissions_in in = { + .agent_id = agent_id, + .device_id = device_id, + .flags = flags, + }; + s32 status; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_BASE, + .message_id = SCMI_BASE_SET_DEVICE_PERMISSIONS, + .in_msg = (u8 *)&in, + .in_msg_sz = sizeof(in), + .out_msg = (u8 *)&status, + .out_msg_sz = sizeof(status), + }; + int ret; + + ret = devm_scmi_process_msg(dev, &msg); + if (ret) + return ret; + if (status) + return scmi_to_linux_errno(status); + + return 0; +} + +/** + * scmi_base_set_protocol_permissions_int - configure access permission to + protocol on device + * @dev: SCMI device + * @agent_id: SCMI agent ID + * @device_id: ID of device to access + * @command_id: SCMI command ID + * @flags: A set of flags + * + * Ask for allowing or denying access permission to the protocol, @command_id, + * on the device, @device_id. + * The meaning of @flags is defined in SCMI specification. + * + * Return: 0 on success, error code otherwise + */ +static int scmi_base_set_protocol_permissions_int(struct udevice *dev, + u32 agent_id, u32 device_id, + u32 command_id, u32 flags) +{ + struct scmi_base_set_protocol_permissions_in in = { + .agent_id = agent_id, + .device_id = device_id, + .command_id = command_id, + .flags = flags, + }; + s32 status; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_BASE, + .message_id = SCMI_BASE_SET_PROTOCOL_PERMISSIONS, + .in_msg = (u8 *)&in, + .in_msg_sz = sizeof(in), + .out_msg = (u8 *)&status, + .out_msg_sz = sizeof(status), + }; + int ret; + + ret = devm_scmi_process_msg(dev, &msg); + if (ret) + return ret; + if (status) + return scmi_to_linux_errno(status); + + return 0; +} + +/** + * scmi_base_reset_agent_configuration_int - reset resource settings + * @dev: SCMI device + * @agent_id: SCMI agent ID + * @flags: A set of flags + * + * Ask for allowing or denying access permission to the protocol, @command_id, + * on the device, @device_id. + * The meaning of @flags is defined in SCMI specification. + * + * Return: 0 on success, error code otherwise + */ +static int scmi_base_reset_agent_configuration_int(struct udevice *dev, + u32 agent_id, u32 flags) +{ + struct scmi_base_reset_agent_configuration_in in = { + .agent_id = agent_id, + .flags = flags, + }; + s32 status; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_BASE, + .message_id = SCMI_BASE_RESET_AGENT_CONFIGURATION, + .in_msg = (u8 *)&in, + .in_msg_sz = sizeof(in), + .out_msg = (u8 *)&status, + .out_msg_sz = sizeof(status), + }; + int ret; + + ret = devm_scmi_process_msg(dev, &msg); + if (ret) + return ret; + if (status) + return scmi_to_linux_errno(status); + + return 0; +} + +/** + * scmi_base_probe - probe base protocol device + * @dev: SCMI device + * + * Probe the device for SCMI base protocol and initialize the private data. + * + * Return: 0 on success, error code otherwise + */ +static int scmi_base_probe(struct udevice *dev) +{ + int ret; + + ret = devm_scmi_of_get_channel(dev); + if (ret) { + dev_err(dev, "get_channel failed\n"); + return ret; + } + + return ret; +} + +struct scmi_base_ops scmi_base_ops = { + /* Commands */ + .protocol_version = scmi_base_protocol_version_int, + .protocol_attrs = scmi_protocol_attrs_int, + .protocol_message_attrs = scmi_protocol_message_attrs_int, + .base_discover_vendor = scmi_base_discover_vendor_int, + .base_discover_sub_vendor = scmi_base_discover_sub_vendor_int, + .base_discover_impl_version = scmi_base_discover_impl_version_int, + .base_discover_list_protocols = scmi_base_discover_list_protocols_int, + .base_discover_agent = scmi_base_discover_agent_int, + .base_notify_errors = NULL, + .base_set_device_permissions = scmi_base_set_device_permissions_int, + .base_set_protocol_permissions = scmi_base_set_protocol_permissions_int, + .base_reset_agent_configuration = + scmi_base_reset_agent_configuration_int, +}; + +int scmi_base_protocol_version(struct udevice *dev, u32 *version) +{ + const struct scmi_base_ops *ops = device_get_ops(dev); + + if (ops->protocol_version) + return (*ops->protocol_version)(dev, version); + + return -EOPNOTSUPP; +} + +int scmi_base_protocol_attrs(struct udevice *dev, u32 *num_agents, + u32 *num_protocols) +{ + const struct scmi_base_ops *ops = device_get_ops(dev); + + if (ops->protocol_attrs) + return (*ops->protocol_attrs)(dev, num_agents, num_protocols); + + return -EOPNOTSUPP; +} + +int scmi_base_protocol_message_attrs(struct udevice *dev, u32 message_id, + u32 *attributes) +{ + const struct scmi_base_ops *ops = device_get_ops(dev); + + if (ops->protocol_message_attrs) + return (*ops->protocol_message_attrs)(dev, message_id, + attributes); + + return -EOPNOTSUPP; +} + +int scmi_base_discover_vendor(struct udevice *dev, u8 **vendor) +{ + const struct scmi_base_ops *ops = device_get_ops(dev); + + if (ops->base_discover_vendor) + return (*ops->base_discover_vendor)(dev, vendor); + + return -EOPNOTSUPP; +} + +int scmi_base_discover_sub_vendor(struct udevice *dev, u8 **sub_vendor) +{ + const struct scmi_base_ops *ops = device_get_ops(dev); + + if (ops->base_discover_sub_vendor) + return (*ops->base_discover_sub_vendor)(dev, sub_vendor); + + return -EOPNOTSUPP; +} + +int scmi_base_discover_impl_version(struct udevice *dev, u32 *impl_version) +{ + const struct scmi_base_ops *ops = device_get_ops(dev); + + if (ops->base_discover_impl_version) + return (*ops->base_discover_impl_version)(dev, impl_version); + + return -EOPNOTSUPP; +} + +int scmi_base_discover_list_protocols(struct udevice *dev, u8 **protocols) +{ + const struct scmi_base_ops *ops = device_get_ops(dev); + + if (ops->base_discover_list_protocols) + return (*ops->base_discover_list_protocols)(dev, protocols); + + return -EOPNOTSUPP; +} + +int scmi_base_discover_agent(struct udevice *dev, u32 agent_id, + u32 *ret_agent_id, u8 **name) +{ + const struct scmi_base_ops *ops = device_get_ops(dev); + + if (ops->base_discover_agent) + return (*ops->base_discover_agent)(dev, agent_id, ret_agent_id, + name); + + return -EOPNOTSUPP; +} + +int scmi_base_notify_errors(struct udevice *dev, u32 enable) +{ + const struct scmi_base_ops *ops = device_get_ops(dev); + + if (ops->base_notify_errors) + return (*ops->base_notify_errors)(dev, enable); + + return -EOPNOTSUPP; +} + +int scmi_base_set_device_permissions(struct udevice *dev, u32 agent_id, + u32 device_id, u32 flags) +{ + const struct scmi_base_ops *ops = device_get_ops(dev); + + if (ops->base_set_device_permissions) + return (*ops->base_set_device_permissions)(dev, agent_id, + device_id, flags); + + return -EOPNOTSUPP; +} + +int scmi_base_set_protocol_permissions(struct udevice *dev, + u32 agent_id, u32 device_id, + u32 command_id, u32 flags) +{ + const struct scmi_base_ops *ops = device_get_ops(dev); + + if (ops->base_set_protocol_permissions) + return (*ops->base_set_protocol_permissions)(dev, agent_id, + device_id, + command_id, + flags); + + return -EOPNOTSUPP; +} + +int scmi_base_reset_agent_configuration(struct udevice *dev, u32 agent_id, + u32 flags) +{ + const struct scmi_base_ops *ops = device_get_ops(dev); + + if (ops->base_reset_agent_configuration) + return (*ops->base_reset_agent_configuration)(dev, agent_id, + flags); + + return -EOPNOTSUPP; +} + +U_BOOT_DRIVER(scmi_base_drv) = { + .id = UCLASS_SCMI_BASE, + .name = "scmi_base_drv", + .ops = &scmi_base_ops, + .probe = scmi_base_probe, +}; + +UCLASS_DRIVER(scmi_base) = { + .id = UCLASS_SCMI_BASE, + .name = "scmi_base", +}; diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index 0432c95c9edc..ab315803dad7 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -123,6 +123,7 @@ enum uclass_id { UCLASS_RNG, /* Random Number Generator */ UCLASS_RTC, /* Real time clock device */ UCLASS_SCMI_AGENT, /* Interface with an SCMI server */ + UCLASS_SCMI_BASE, /* Interface for SCMI Base protocol */ UCLASS_SCSI, /* SCSI device */ UCLASS_SERIAL, /* Serial UART */ UCLASS_SIMPLE_BUS, /* Bus with child devices */ diff --git a/include/scmi_protocols.h b/include/scmi_protocols.h index a220cb2a91ad..f41d3f317ce2 100644 --- a/include/scmi_protocols.h +++ b/include/scmi_protocols.h @@ -49,6 +49,357 @@ enum scmi_discovery_id { SCMI_PROTOCOL_MESSAGE_ATTRIBUTES = 0x2, }; +/* + * SCMI Base Protocol + */ +#define SCMI_BASE_PROTOCOL_VERSION 0x20000 + +enum scmi_base_message_id { + SCMI_BASE_DISCOVER_VENDOR = 0x3, + SCMI_BASE_DISCOVER_SUB_VENDOR = 0x4, + SCMI_BASE_DISCOVER_IMPL_VERSION = 0x5, + SCMI_BASE_DISCOVER_LIST_PROTOCOLS = 0x6, + SCMI_BASE_DISCOVER_AGENT = 0x7, + SCMI_BASE_NOTIFY_ERRORS = 0x8, + SCMI_BASE_SET_DEVICE_PERMISSIONS = 0x9, + SCMI_BASE_SET_PROTOCOL_PERMISSIONS = 0xa, + SCMI_BASE_RESET_AGENT_CONFIGURATION = 0xb, +}; + +#define SCMI_BASE_NAME_LENGTH_MAX 16 + +/** + * struct scmi_protocol_version_out - Response for SCMI_PROTOCOL_VERSION + * command + * @status: SCMI command status + * @version: Protocol version + */ +struct scmi_protocol_version_out { + s32 status; + u32 version; +}; + +/** + * struct scmi_protocol_attrs_out - Response for SCMI_PROTOCOL_ATTRIBUTES + * command + * @status: SCMI command status + * @attributes: Protocol attributes or implementation details + */ +struct scmi_protocol_attrs_out { + s32 status; + u32 attributes; +}; + +#define SCMI_PROTOCOL_ATTRS_NUM_AGENTS(attributes) \ + (((attributes) & GENMASK(15, 8)) >> 8) +#define SCMI_PROTOCOL_ATTRS_NUM_PROTOCOLS(attributes) \ + ((attributes) & GENMASK(7, 0)) + +/** + * struct scmi_protocol_msg_attrs_out - Response for + * SCMI_PROTOCOL_MESSAGE_ATTRIBUTES command + * @status: SCMI command status + * @attributes: Message-specific attributes + */ +struct scmi_protocol_msg_attrs_out { + s32 status; + u32 attributes; +}; + +/** + * struct scmi_base_discover_vendor_out - Response for + * SCMI_BASE_DISCOVER_VENDOR or + * SCMI_BASE_DISCOVER_SUB_VENDOR command + * @status: SCMI command status + * @vendor_identifier: Name of vendor or sub-vendor in string + */ +struct scmi_base_discover_vendor_out { + s32 status; + u8 vendor_identifier[SCMI_BASE_NAME_LENGTH_MAX]; +}; + +/** + * struct scmi_base_discover_impl_version_out - Response for + * SCMI_BASE_DISCOVER_IMPL_VERSION command + * @status: SCMI command status + * @impl_version: Vendor-specific implementation version + */ +struct scmi_base_discover_impl_version_out { + s32 status; + u32 impl_version; +}; + +/** + * struct scmi_base_discover_list_protocols_out - Response for + * SCMI_BASE_DISCOVER_LIST_PROTOCOLS command + * @status: SCMI command status + * @num_protocols: Number of SCMI protocols in @protocol + * @protocols: Array of packed SCMI protocol ID's + */ +struct scmi_base_discover_list_protocols_out { + s32 status; + u32 num_protocols; + u32 protocols[3]; +}; + +/** + * struct scmi_base_discover_agent_out - Response for + * SCMI_BASE_DISCOVER_AGENT command + * @status: SCMI command status + * @agent_id: SCMI agent ID + * @name: Name of agent in string + */ +struct scmi_base_discover_agent_out { + s32 status; + u32 agent_id; + u8 name[SCMI_BASE_NAME_LENGTH_MAX]; +}; + +#define SCMI_BASE_NOTIFY_ERRORS_ENABLE BIT(0) + +/** + * struct scmi_base_set_device_permissions_in - Parameters for + * SCMI_BASE_SET_DEVICE_PERMISSIONS command + * @agent_id: SCMI agent ID + * @device_id: device ID + * @flags: A set of flags + */ +struct scmi_base_set_device_permissions_in { + u32 agent_id; + u32 device_id; + u32 flags; +}; + +#define SCMI_BASE_SET_DEVICE_PERMISSIONS_ACCESS BIT(0) + +/** + * struct scmi_base_set_protocol_permissions_in - Parameters for + * SCMI_BASE_SET_PROTOCOL_PERMISSIONS command + * @agent_id: SCMI agent ID + * @device_id: device ID + * @command_id: command ID + * @flags: A set of flags + */ +struct scmi_base_set_protocol_permissions_in { + u32 agent_id; + u32 device_id; + u32 command_id; + u32 flags; +}; + +#define SCMI_BASE_SET_PROTOCOL_PERMISSIONS_COMMAND GENMASK(7, 0) +#define SCMI_BASE_SET_PROTOCOL_PERMISSIONS_ACCESS BIT(0) + +/** + * struct scmi_base_reset_agent_configuration_in - Parameters for + * SCMI_BASE_RESET_AGENT_CONFIGURATION command + * @agent_id: SCMI agent ID + * @flags: A set of flags + */ +struct scmi_base_reset_agent_configuration_in { + u32 agent_id; + u32 flags; +}; + +#define SCMI_BASE_RESET_ALL_ACCESS_PERMISSIONS BIT(0) + +/** + * struct scmi_base_ops - SCMI base protocol interfaces + */ +struct scmi_base_ops { + /** + * protocol_version - get Base protocol version + * @dev: SCMI device + * @version: Pointer to SCMI protocol version + * + * Obtain the protocol version number in @version for Base protocol. + * + * Return: 0 on success, error code otherwise + */ + int (*protocol_version)(struct udevice *dev, u32 *version); + /** + * protocol_attrs - get protocol attributes + * @dev: SCMI device + * @num_agents: Number of SCMI agents + * @num_protocols: Number of SCMI protocols + * + * Obtain the protocol attributes, the number of agents and the number + * of protocols, in @num_agents and @num_protocols respectively, that + * the device provides. + * + * Return: 0 on success, error code otherwise + */ + int (*protocol_attrs)(struct udevice *dev, u32 *num_agents, + u32 *num_protocols); + /** + * protocol_message_attrs - get message-specific attributes + * @dev: SCMI device + * @message_id: SCMI message ID + * @attributes: Message-specific attributes + * + * Obtain the message-specific attributes in @attributes. + * This command succeeds if the message is implemented and available. + * + * Return: 0 on success, error code otherwise + */ + int (*protocol_message_attrs)(struct udevice *dev, u32 message_id, + u32 *attributes); + /** + * base_discover_vendor - get vendor name + * @dev: SCMI device + * @vendor: Pointer to vendor name + * + * Obtain the vendor's name in @vendor. + * It is a caller's responsibility to free @vendor. + * + * Return: 0 on success, error code otherwise + */ + int (*base_discover_vendor)(struct udevice *dev, u8 **vendor); + /** + * base_discover_sub_vendor - get sub-vendor name + * @dev: SCMI device + * @sub_vendor: Pointer to sub-vendor name + * + * Obtain the sub-vendor's name in @sub_vendor. + * It is a caller's responsibility to free @sub_vendor. + * + * Return: 0 on success, error code otherwise + */ + int (*base_discover_sub_vendor)(struct udevice *dev, u8 **sub_vendor); + /** + * base_discover_impl_version - get implementation version + * @dev: SCMI device + * @impl_version: Pointer to implementation version + * + * Obtain the implementation version number in @impl_version. + * + * Return: 0 on success, error code otherwise + */ + int (*base_discover_impl_version)(struct udevice *dev, + u32 *impl_version); + /** + * base_discover_list_protocols - get list of protocols + * @dev: SCMI device + * @protocols: Pointer to array of SCMI protocols + * + * Obtain the list of protocols provided in @protocols. + * The number of elements in @protocols always match to the number of + * protocols returned by smci_protocol_attrs() when this function + * succeeds. + * It is a caller's responsibility to free @protocols. + * + * Return: the number of protocols in @protocols on success, + * error code otherwise + */ + int (*base_discover_list_protocols)(struct udevice *dev, + u8 **protocols); + /** + * base_discover_agent - identify agent + * @dev: SCMI device + * @agent_id: SCMI agent ID + * @ret_agent_id: Pointer to SCMI agent ID + * @name: Pointer to SCMI agent name + * + * Obtain the agent's name in @name. If @agent_id is equal to + * 0xffffffff, * this function returns the caller's agent id in + * @ret_agent_id. + * It is a caller's responsibility to free @name. + * + * Return: 0 on success, error code otherwise + */ + int (*base_discover_agent)(struct udevice *dev, u32 agent_id, + u32 *ret_agent_id, u8 **name); + /** + * base_notify_errors - configure error notification + * @dev: SCMI device + * @enable: Operation + * + * This function is not yet implemented. + * + * Return: always -EOPNOTSUPP + */ + int (*base_notify_errors)(struct udevice *dev, u32 enable); + /** + * base_set_device_permissions - configure access permission to device + * @dev: SCMI device + * @agent_id: SCMI agent ID + * @device_id: ID of device to access + * @flags: A set of flags + * + * Ask for allowing or denying access permission to the device, + * @device_id. The meaning of @flags is defined in SCMI specification. + * + * Return: 0 on success, error code otherwise + */ + int (*base_set_device_permissions)(struct udevice *dev, u32 agent_id, + u32 device_id, u32 flags); + /** + * base_set_protocol_permissions - configure access permission to + * protocol on device + * @dev: SCMI device + * @agent_id: SCMI agent ID + * @device_id: ID of device to access + * @command_id: command ID + * @flags: A set of flags + * + * Ask for allowing or denying access permission to the protocol, @command_id, + * on the device, @device_id. + * The meaning of @flags is defined in SCMI specification. + * + * Return: 0 on success, error code otherwise + */ + int (*base_set_protocol_permissions)(struct udevice *dev, u32 agent_id, + u32 device_id, u32 command_id, + u32 flags); + /** + * base_reset_agent_configuration - reset resource settings + * @dev: SCMI device + * @agent_id: SCMI agent ID + * @flags: A set of flags + * + * Ask for allowing or denying access permission to the protocol, @command_id, + * on the device, @device_id. + * The meaning of @flags is defined in SCMI specification. + * + * Return: 0 on success, error code otherwise + */ + int (*base_reset_agent_configuration)(struct udevice *dev, u32 agent_id, + u32 flags); +}; + +int scmi_base_protocol_version(struct udevice *dev, u32 *version); +int scmi_base_protocol_attrs(struct udevice *dev, u32 *num_agents, + u32 *num_protocols); +int scmi_base_protocol_message_attrs(struct udevice *dev, u32 message_id, + u32 *attributes); +int scmi_base_discover_vendor(struct udevice *dev, u8 **vendor); +int scmi_base_discover_sub_vendor(struct udevice *dev, u8 **sub_vendor); +int scmi_base_discover_impl_version(struct udevice *dev, u32 *impl_version); +int scmi_base_discover_list_protocols(struct udevice *dev, u8 **protocols); +int scmi_base_discover_agent(struct udevice *dev, u32 agent_id, + u32 *ret_agent_id, u8 **name); +int scmi_base_notify_errors(struct udevice *dev, u32 enable); +int scmi_base_set_device_permissions(struct udevice *dev, u32 agent_id, + u32 device_id, u32 flags); +int scmi_base_set_protocol_permissions(struct udevice *dev, + u32 agent_id, u32 device_id, + u32 command_id, u32 flags); +int scmi_base_reset_agent_configuration(struct udevice *dev, u32 agent_id, + u32 flags); + +/** + * scmi_generic_protocol_version - get protocol version + * @dev: SCMI device + * @id: SCMI protocol ID + * @version: Pointer to SCMI protocol version + * + * Obtain the protocol version number in @version. + * + * Return: 0 on success, error code otherwise + */ +int scmi_generic_protocol_version(struct udevice *dev, + enum scmi_std_protocol id, u32 *version); + /* * SCMI Clock Protocol */ From patchwork Fri Sep 8 02:51:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 720786 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp548402wrp; Thu, 7 Sep 2023 19:53:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF4BHtjf5DMBKH4lCGlKjAQk1wVAAF9vKAoLtG8M2xPj8s3YKmMqwhPRQLoQfo2yyydu15d X-Received: by 2002:a1c:4b0a:0:b0:400:c0e8:18c6 with SMTP id y10-20020a1c4b0a000000b00400c0e818c6mr1001441wma.18.1694141586089; Thu, 07 Sep 2023 19:53:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694141586; cv=none; d=google.com; s=arc-20160816; b=RB9MoRCzk0ieXUBDbKHd5J0KL0BLaJo/tpXArhBk0VghRfbJ44RGNsTIiOVA+XzL7W M/pamtB2dYbx28bdGu69p/J5Z6dCHGMOL/HYCvrUdbObXBL6C0htWwqazhe23sS9lw92 6JD+4AuzvTQNFOvuvogJuTP6z6lnGJAAzNP4fkrIldqE9cu4kc7Piaux9GInvFfaZrbE 3pRaEZK5BDb6XivnVHLBK/R+CDKPVFh2o6e8L1kH+s16BrWylOfeP6OhRX5/ktkC0eAo Z+abjD17W17P/zLzIJTrUfuHDWSmrk0yFT7w5P4uN+4XM5UC7XjwtAxy++eRaZJEJFQw iUGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=eUShx2iTkUy1YqhRliZ2KHnTEDC/P7z8JupwczPNw/U=; fh=K4dQhL74gef2glEqNOnE2YOBTqRi7qf0ycKBewrN6K8=; b=HDVCl6Tcw+GxavpH6v4ej65q6L5ibCOusm8ExgBu9fvHes7hB0+5ZcitpAFPJtbz83 GvfQ2Rxz770WflvB0TO3MQudncpwQq19LsK9pjR9mk81kbCQObqh2H8ChP87ZC/7u7kV ukR85V2GpD+LpRhb68IqSGWcAU8Obw2Y2DvKnw8RqLgXKQnXtvIlO1+uKG5sePqG7h6Y uLNVAT6zhYu4LSZKE+RhHv7cssLxs1wQwep6glhzVYJR4GluaG9+PG1E26wF3o9A5RDV KS8ob8hYlBoO5e3uVIeo1ynyuyYkjqvCRYoMght0dDxDhsQ6vHhLjRoKWf/BImElDxTo uxoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=J7NHdeqZ; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id w14-20020a05600c474e00b00401fe03071bsi342248wmo.213.2023.09.07.19.53.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 19:53:06 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=J7NHdeqZ; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1448C8676C; Fri, 8 Sep 2023 04:52:30 +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="J7NHdeqZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 14EDE868D7; Fri, 8 Sep 2023 04:52:28 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) (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 DE8AD86995 for ; Fri, 8 Sep 2023 04:52:24 +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-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-26fa19322b5so414889a91.0 for ; Thu, 07 Sep 2023 19:52:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694141543; x=1694746343; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eUShx2iTkUy1YqhRliZ2KHnTEDC/P7z8JupwczPNw/U=; b=J7NHdeqZcNpxfsSFH1XJdg1Pj/SSoFmo9JShtLwnalaehEdl+blEMY2dELIr/WClHr Kelr2S2Fi/teGjbLk/QfcR97yZ5ZFvdCjVOyDW8EyiL6BIKfr0aQVpmb65ph8Q18xgc5 StnljYuMO1MBiswHhTezMX+wbMRDbtvkUdSz8gi+kvaSbyMScMQyjNtJMz4Y+vwWLAt4 9/vNG/IBhKp8fZ2a2UfDYg7bF0rcnnwVDz8BmZLBe6mRq53qyJcQ7XZqngOk2PHFkAaX aJ4N2YwqGfV0erLY5UTri3xUeuT7dDD3/fv6UK2w60AGa3rVsgX2FFvQ8TLKRYAQEYzn 1KUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694141543; x=1694746343; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eUShx2iTkUy1YqhRliZ2KHnTEDC/P7z8JupwczPNw/U=; b=PYjmFobueM92P0nN8Yup5zXtC8M5P8XaYgO493UoGfQ2e2vcwEv15/GBC3Yl9sDO2i WQRRRH/jGJrDohuXXeLdAol8Ght998NMNsBtdn5RUJRNaEG+IVhgW+3Y4HjRxYGZoWgS 0hpxUfoyQlaKdODQDUi+1b7mAEp5cg3Q8IeAzZgweShxKZb93t0W8fLvvCzcMdz0UmhA CtJtup+KIZB6F/77tBb8/YC6bq1Ek6/jYczp7+QkbR9E8qXsomPfGt0Dpct9BAbxEqqW 3UiV5Cw8VTdYfZq+x8njjE94/HwzCTUxtmQoxwsphx3KJj05u75j5dxjXFILmDYWLnrs F4IA== X-Gm-Message-State: AOJu0YxdDMbSGmOBLDAZjy7JswxyGFGvzutyjee7b5h9bO6liMIwaxB/ bySR+ORGKOXhueUJRkxArhe36Q== X-Received: by 2002:a17:902:ec8b:b0:1c0:cbaf:6939 with SMTP id x11-20020a170902ec8b00b001c0cbaf6939mr1444481plg.3.1694141543014; Thu, 07 Sep 2023 19:52:23 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:2d89:7669:ac2d:f09e]) by smtp.gmail.com with ESMTPSA id n9-20020a170902e54900b001c0ce518e98sm417286plf.224.2023.09.07.19.52.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 19:52:22 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org Cc: etienne.carriere@st.com, u-boot@lists.denx.de, AKASHI Takahiro , Etienne Carriere Subject: [PATCH v3 03/13] firmware: scmi: move scmi_bind_protocols() backward Date: Fri, 8 Sep 2023 11:51:28 +0900 Message-Id: <20230908025138.44405-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230908025138.44405-1-takahiro.akashi@linaro.org> References: <20230908025138.44405-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 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 Move the location of scmi_bind_protocols() backward for changes in later patches. There is no change in functionality. Signed-off-by: AKASHI Takahiro Reviewed-by: Simon Glass Reviewed-by: Etienne Carriere --- drivers/firmware/scmi/scmi_agent-uclass.c | 59 +++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c b/drivers/firmware/scmi/scmi_agent-uclass.c index feb31809e715..94e54eeb066b 100644 --- a/drivers/firmware/scmi/scmi_agent-uclass.c +++ b/drivers/firmware/scmi/scmi_agent-uclass.c @@ -157,6 +157,65 @@ int devm_scmi_process_msg(struct udevice *dev, struct scmi_msg *msg) return scmi_process_msg(protocol->parent, priv->channel, msg); } +/* + * SCMI agent devices binds devices of various uclasses depeding on + * the FDT description. scmi_bind_protocol() is a generic bind sequence + * called by the uclass at bind stage, that is uclass post_bind. + */ +static int scmi_bind_protocols(struct udevice *dev) +{ + int ret = 0; + ofnode node; + const char *name; + + dev_for_each_subnode(node, dev) { + struct driver *drv = NULL; + u32 protocol_id; + + if (!ofnode_is_enabled(node)) + continue; + + if (ofnode_read_u32(node, "reg", &protocol_id)) + continue; + + name = ofnode_get_name(node); + switch (protocol_id) { + case SCMI_PROTOCOL_ID_CLOCK: + if (CONFIG_IS_ENABLED(CLK_SCMI)) + drv = DM_DRIVER_GET(scmi_clock); + break; + case SCMI_PROTOCOL_ID_RESET_DOMAIN: + if (IS_ENABLED(CONFIG_RESET_SCMI)) + drv = DM_DRIVER_GET(scmi_reset_domain); + break; + case SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN: + if (IS_ENABLED(CONFIG_DM_REGULATOR_SCMI)) { + node = ofnode_find_subnode(node, "regulators"); + if (!ofnode_valid(node)) { + dev_err(dev, "no regulators node\n"); + return -ENXIO; + } + drv = DM_DRIVER_GET(scmi_voltage_domain); + } + break; + default: + break; + } + + if (!drv) { + dev_dbg(dev, "Ignore unsupported SCMI protocol %#x\n", + protocol_id); + continue; + } + + ret = device_bind(dev, drv, name, NULL, node, NULL); + if (ret) + break; + } + + return ret; +} + UCLASS_DRIVER(scmi_agent) = { .id = UCLASS_SCMI_AGENT, .name = "scmi_agent", From patchwork Fri Sep 8 02:51:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 720787 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp548458wrp; Thu, 7 Sep 2023 19:53:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEvKgAFU/lRyOR90GyktGMcX4hkfaVNJ587XHOToTQQ38iOHks2OI9JpkZ+rYRzqX8czd7b X-Received: by 2002:a5d:6302:0:b0:316:f3cf:6f12 with SMTP id i2-20020a5d6302000000b00316f3cf6f12mr732538wru.48.1694141597140; Thu, 07 Sep 2023 19:53:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694141597; cv=none; d=google.com; s=arc-20160816; b=QdvXOJqutgNa3I/+5+q/MTvM1sPTRp4zjIqxP0hHKp37rFjPMjc6dSMd+Q9qgo08qS BmiHIORqjrvkf9zBkyl3LpvW14CIf8yAB2rDPpxbBwPPHjDlfFJInbhjS/r3yjJdST5/ 66jVQ/aTmh+9+hG6uukOviefFvE/d1fprZb2hDCwThVqEETDZYxN6PNihNwjqRq/LZOQ kN9cYvKVqAfKTHY4Pgp5OOgv7GDoBgSQbR642APDx6HBqxWtbbHP190g9lQ4t55dxoIR QTlgO6skaLOQVcmKBe62m8rez8nCugmKVJGQE/AZjkRuVyf5RsBjXO1k+F2vcsQMuOfS LRyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=S0hcDknwXYOSgl9hyW6D/+IX+JIjGvfNzNGDU+HObeU=; fh=K4dQhL74gef2glEqNOnE2YOBTqRi7qf0ycKBewrN6K8=; b=YbclTIe3zUhDzfirzfuL0x8JTNwLcKt+1cB/P3C2i9/RYGo6DjbFvGTdLhPIYX2830 zY6xMzbjtqejVX98ybDJbc5vHLWRn3mBrBESt3COx+I1AkRQ6D4eTbTh3JD7hdgOGUM1 Id4xOTeBMfOuoownzmBssUEFsi6NQcw841TLwh1qhRPmpZCJy/86QFtmjaTOOJuOZFNX kaPn+iyPIV7emTF8pkwG1PvR4qVqTQfG0v1CxAN2nt0reZfuzciMWRs60bNc2yRCkGs9 GMA5q3580mgk6RyewSxmGm+D6w8l62KR5y4SZndiPMSNWMlWryyUwk68oJfNPLgf0yL7 JjVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FfeypaAw; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id q5-20020a5d61c5000000b0031c80373a86si344980wrv.813.2023.09.07.19.53.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 19:53:17 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FfeypaAw; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 67FDE86A0A; Fri, 8 Sep 2023 04:52:31 +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="FfeypaAw"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DDB468645F; Fri, 8 Sep 2023 04:52:29 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) (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 D95598645F for ; Fri, 8 Sep 2023 04:52:26 +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-pl1-x630.google.com with SMTP id d9443c01a7336-1bf1876ef69so3578515ad.1 for ; Thu, 07 Sep 2023 19:52:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694141545; x=1694746345; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=S0hcDknwXYOSgl9hyW6D/+IX+JIjGvfNzNGDU+HObeU=; b=FfeypaAw1v6/uOlPQXmVJ9nZ1Jr7jhRrFfqayem7V/xVWC6xW95Y0dVAKzq5CdFC2R ZaI/9Oruw3fh/g3jzKNLi3MIojuUFRk+Mukit75TWRrBIEKwLFsW5dOK+xvpHvJUnj+7 5lU4WkyohJNyOx+BXHkcwvXuJ8Uru0CgTiB3Ktjo6vmFQMzhf2xSWxSn+GsPE0bPNQTR CJsCyF30HTVyvhyRu8gcqYC07HackXtpmW3qmy2Xk1xpR8yLzzOetDmjnbBqlSPab9kK 6Rx/iEvXZeiEKVZPk+UEMn3VmCL8w4wqylcbl1RmhAdV12+Ro7zdKNhtmJbKlVl581Y+ VUxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694141545; x=1694746345; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S0hcDknwXYOSgl9hyW6D/+IX+JIjGvfNzNGDU+HObeU=; b=jiCAHK4AqOPC9xI6qRXK7LvdYsiHoXKUJVUneRH1SFcec2zRj2mZP89+u+LNlro3kx wrj03eI8+8H+vXXObR1JxRMnZu/oEwfz18UTkJYsq3jUwTJxtosi0b38WxHdxa0LNhnx ipa7S+Dc38wG18k62ghN+kWu97oGNqGsnPB28iaVzKe2e+QX5/QmS9BFb6wRCzfbvvsa WFhDwql5EwItH5SJBtnAaIgZseNWYY9iIxBgwX/SZyWHNdhPy/78uFEJYRT07i4A9/yZ 4hfHCfpdIXREbP9DvfhdGdojV0Ij8zIRpQm1bc+LRTbgALw+/71tRZ2NapU1RloYwwAB YXvg== X-Gm-Message-State: AOJu0YzS5RUSQgQeWs8rF58QtOjN2a87uWkL/2F12EbmyG90YQZ+pK3v fyp56kYOi0gWLlixZQjXN7FZVQ== X-Received: by 2002:a17:903:2448:b0:1bf:1a9e:85f7 with SMTP id l8-20020a170903244800b001bf1a9e85f7mr1480379pls.1.1694141545070; Thu, 07 Sep 2023 19:52:25 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:2d89:7669:ac2d:f09e]) by smtp.gmail.com with ESMTPSA id n9-20020a170902e54900b001c0ce518e98sm417286plf.224.2023.09.07.19.52.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 19:52:24 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org Cc: etienne.carriere@st.com, u-boot@lists.denx.de, AKASHI Takahiro , Etienne Carriere Subject: [PATCH v3 04/13] firmware: scmi: framework for installing additional protocols Date: Fri, 8 Sep 2023 11:51:29 +0900 Message-Id: <20230908025138.44405-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230908025138.44405-1-takahiro.akashi@linaro.org> References: <20230908025138.44405-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 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 This framework allows SCMI protocols to be installed and bound to the agent so that the agent can manage and utilize them later. Signed-off-by: AKASHI Takahiro Reviewed-by: Simon Glass Reviewed-by: Etienne Carriere --- v3 * move "per_device_plat_auto" from a earlier patch * fix comments in "scmi_agent_priv" * modify an order of include files in scmi_agent.h v2 * check for availability of protocols --- drivers/firmware/scmi/scmi_agent-uclass.c | 101 +++++++++++++++++++++- include/scmi_agent-uclass.h | 15 +++- include/scmi_agent.h | 14 +++ 3 files changed, 126 insertions(+), 4 deletions(-) diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c b/drivers/firmware/scmi/scmi_agent-uclass.c index 94e54eeb066b..e823d105a3eb 100644 --- a/drivers/firmware/scmi/scmi_agent-uclass.c +++ b/drivers/firmware/scmi/scmi_agent-uclass.c @@ -38,6 +38,86 @@ static const struct error_code scmi_linux_errmap[] = { { .scmi = SCMI_PROTOCOL_ERROR, .errno = -EPROTO, }, }; +/* + * NOTE: The only one instance should exist according to + * the current specification and device tree bindings. + */ +struct udevice *scmi_agent; + +struct udevice *scmi_get_protocol(struct udevice *dev, + enum scmi_std_protocol id) +{ + struct scmi_agent_priv *priv; + struct udevice *proto; + + priv = dev_get_uclass_plat(dev); + if (!priv) { + dev_err(dev, "No priv data found\n"); + return NULL; + } + + switch (id) { + case SCMI_PROTOCOL_ID_CLOCK: + proto = priv->clock_dev; + break; + case SCMI_PROTOCOL_ID_RESET_DOMAIN: + proto = priv->resetdom_dev; + break; + case SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN: + proto = priv->voltagedom_dev; + break; + default: + dev_err(dev, "Protocol not supported\n"); + proto = NULL; + break; + } + if (proto && device_probe(proto)) + dev_err(dev, "Probe failed\n"); + + return proto; +} + +/** + * scmi_add_protocol - add protocol to agent + * @dev: SCMI agent device + * @proto_id: SCMI protocol ID + * @proto: SCMI protocol device + * + * Associate the protocol instance, @proto, to the agent, @dev, + * for later use. + * + * Return: 0 on success, error code otherwise + */ +static int scmi_add_protocol(struct udevice *dev, + enum scmi_std_protocol proto_id, + struct udevice *proto) +{ + struct scmi_agent_priv *priv; + + priv = dev_get_uclass_plat(dev); + if (!priv) { + dev_err(dev, "No priv data found\n"); + return -ENODEV; + } + + switch (proto_id) { + case SCMI_PROTOCOL_ID_CLOCK: + priv->clock_dev = proto; + break; + case SCMI_PROTOCOL_ID_RESET_DOMAIN: + priv->resetdom_dev = proto; + break; + case SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN: + priv->voltagedom_dev = proto; + break; + default: + dev_err(dev, "Protocol not supported\n"); + return -EPROTO; + } + + return 0; +} + int scmi_to_linux_errno(s32 scmi_code) { int n; @@ -164,12 +244,14 @@ int devm_scmi_process_msg(struct udevice *dev, struct scmi_msg *msg) */ static int scmi_bind_protocols(struct udevice *dev) { + struct udevice *agent; int ret = 0; ofnode node; const char *name; + struct driver *drv; + struct udevice *proto; dev_for_each_subnode(node, dev) { - struct driver *drv = NULL; u32 protocol_id; if (!ofnode_is_enabled(node)) @@ -178,6 +260,7 @@ static int scmi_bind_protocols(struct udevice *dev) if (ofnode_read_u32(node, "reg", &protocol_id)) continue; + drv = NULL; name = ofnode_get_name(node); switch (protocol_id) { case SCMI_PROTOCOL_ID_CLOCK: @@ -208,11 +291,22 @@ static int scmi_bind_protocols(struct udevice *dev) continue; } - ret = device_bind(dev, drv, name, NULL, node, NULL); - if (ret) + ret = device_bind(dev, drv, name, NULL, node, &proto); + if (ret) { + dev_err(dev, "failed to bind %s protocol\n", drv->name); break; + } + ret = scmi_add_protocol(dev, protocol_id, proto); + if (ret) { + dev_err(dev, "failed to add protocol: %s, ret: %d\n", + proto->name, ret); + break; + } } + if (!ret) + scmi_agent = dev; + return ret; } @@ -220,5 +314,6 @@ UCLASS_DRIVER(scmi_agent) = { .id = UCLASS_SCMI_AGENT, .name = "scmi_agent", .post_bind = scmi_bind_protocols, + .per_device_plat_auto = sizeof(struct scmi_agent_priv), .per_child_auto = sizeof(struct scmi_agent_proto_priv *), }; diff --git a/include/scmi_agent-uclass.h b/include/scmi_agent-uclass.h index b1c93532c0ea..3358c2b2d804 100644 --- a/include/scmi_agent-uclass.h +++ b/include/scmi_agent-uclass.h @@ -5,10 +5,23 @@ #ifndef _SCMI_AGENT_UCLASS_H #define _SCMI_AGENT_UCLASS_H -struct udevice; +#include + struct scmi_msg; struct scmi_channel; +/** + * struct scmi_agent_priv - private data maintained by agent instance + * @clock_dev: SCMI clock protocol device + * @resetdom_dev: SCMI reset domain protocol device + * @voltagedom_dev: SCMI voltage domain protocol device + */ +struct scmi_agent_priv { + struct udevice *clock_dev; + struct udevice *resetdom_dev; + struct udevice *voltagedom_dev; +}; + /** * struct scmi_transport_ops - The functions that a SCMI transport layer must implement. */ diff --git a/include/scmi_agent.h b/include/scmi_agent.h index 577892029ff8..755986d6c424 100644 --- a/include/scmi_agent.h +++ b/include/scmi_agent.h @@ -10,6 +10,7 @@ #ifndef SCMI_AGENT_H #define SCMI_AGENT_H +#include #include struct udevice; @@ -74,6 +75,19 @@ int devm_scmi_of_get_channel(struct udevice *dev); */ int devm_scmi_process_msg(struct udevice *dev, struct scmi_msg *msg); +/** + * scmi_get_protocol() - get protocol instance + * + * @dev: SCMI agent device + * @id: SCMI protocol ID + * + * Obtain the device instance for given protocol ID, @id. + * + * Return: Pointer to the device if found, null otherwise + */ +struct udevice *scmi_get_protocol(struct udevice *dev, + enum scmi_std_protocol id); + /** * scmi_to_linux_errno() - Convert an SCMI error code into a Linux errno code * From patchwork Fri Sep 8 02:51:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 720788 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp548497wrp; Thu, 7 Sep 2023 19:53:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF+JsLJx7W6b4fje0ESk+EjuKeSWlnR1w09XF+NIOcNCsVbXToSYJFxpxRpC1jBbzPD2nm+ X-Received: by 2002:a05:6000:141:b0:319:7abb:4112 with SMTP id r1-20020a056000014100b003197abb4112mr3001493wrx.21.1694141607279; Thu, 07 Sep 2023 19:53:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694141607; cv=none; d=google.com; s=arc-20160816; b=TbSpbA2gbyvbg4jYAUpWFA1phDhCtVH2b+8LEObi9hvKdUwirgFNMQVBtB1g74H7ub R59ehh9gRBKI82l4iaINkThbs1vJE7xzMERJOlrZIWIxEh4SwX5bjTqIfk9UoOxdQQK9 oI8s33f2yAoMpHNTh3bVF8KUxC5/h6Z+2SQo6Bb7snrJMq9Fla8s6Sn1eeGcfKx843er ndXhMPMsDLhFe3dkbdtORmBQd2rDoxAAWm8vZnVfWySIvljZ649cwnOlGNu3V0YMiOTv IKGhaE4e9L36HcvTndLv6+cgcOKxH94/4YYzVTjAmhmsgJ7F1iQDKa79QdrnGFnMDL3V Zt7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FFPJjDa20a8vFvRkRF/UxpvOVUFkHJ53fb9mlcp1AUY=; fh=K4dQhL74gef2glEqNOnE2YOBTqRi7qf0ycKBewrN6K8=; b=cLVtyNXD1COAk5bfcnf0l5yYgrZn3a7pTfQuLEO3j3froloDNtVs+CZXqhjmXd1jbw SRDwrM1b22JGpuVWv8VgUIB/MjeBifgpN7u8rEU3JYXspBD8O3mEnwQJTDH4YNOmZyne BP+46awxHIydrXoAp7v9Vqgx0vL38M9460wHcimg+03qUL4u658ILdyGDbc5x6qBUhBY hj+UAFwYGhWhdYMi1It2eX8b4FQsTtGbZFp0kOsYv8aV6faAmIOE1vOUoOSESKeXVZTF LF1VyxI1rsvIYqk2Y07HWMYTXBGti1TyJLp5yoxhtIa5X97wXLuo17B9otvI8wqBzuTI Z5NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yuBe6qSy; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id h3-20020a05600c314300b003fefe024f54si348529wmo.17.2023.09.07.19.53.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 19:53:27 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yuBe6qSy; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B84DB86A24; Fri, 8 Sep 2023 04:52:33 +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="yuBe6qSy"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E502586A1A; Fri, 8 Sep 2023 04:52:31 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) (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 D857F86995 for ; Fri, 8 Sep 2023 04:52:28 +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-pl1-x636.google.com with SMTP id d9443c01a7336-1bf7b5e1f06so3055835ad.0 for ; Thu, 07 Sep 2023 19:52:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694141547; x=1694746347; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FFPJjDa20a8vFvRkRF/UxpvOVUFkHJ53fb9mlcp1AUY=; b=yuBe6qSyS1zxPYYwR3L4cvXL3GudRk0ucOSkKDmdpPFFcu+CO0rj+jQXwsk7b/Rn7v bK245lUmlXpThkuxitTT4qocG9wS5PB/65R5KkvZHEgiptSPSnpQ3IfEGlQLBrqkiAGt lsf7g9Y3pjFR9WtM8AqVwGh++8l/1nSQH4A4+KCXJTGGZd9sFfSxfXa+GZCZTRpsEnJt pqy7fmgnH12tbuJlNvr9GOjQ7wxt8xiJe6623MtL7EXNGjDo1mhimvRY6YtSQhcnG0bl 4trR6Iw6Vu3uPS1IkEx0lgOzIpT2/79cpGOQaji734pfqKraqjtqyxa581oTpxEaDeEw L3Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694141547; x=1694746347; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FFPJjDa20a8vFvRkRF/UxpvOVUFkHJ53fb9mlcp1AUY=; b=K0hV/7oxljFhkKFQ4IQv6gGiVVovLdMmEW+HULhPOtdKBK7WujQSB8CgGzRzr8P8Dl xtEE9IdMjsM5eZKp3o+qFYZZWgFQnihymv18px61Wa6JUPIDqC7AoAeDjmSu7VA/ELTi 8yODsnTls+KydJ239MeSG8IExYtWWg/rvOqkTCLjVa1PWbbPsnBT1IbU9cBqzHAuFoZH e3+k3lpTPPfmGdoxJMN9pja9lql3Gca+u9tAY50NNd4ZBKhaxScqPx/VDdzNY9D0KvrH AXFNCbhZlCCYNb3pTVmwTFhx++/lrSqidu0Bgw/H4JlLGPhbIHHLAEhkhnHgBYEeR3+6 Svgg== X-Gm-Message-State: AOJu0Yy4QFkmoWpctGw17W3RDABlES5by3wkQDTD6Ww+ARVv6eycIlVT cenFNkiNFFLqdwAXj7qdUjTzRPfO40UJdqjg8qvzMw== X-Received: by 2002:a17:902:d48d:b0:1c2:c60:8387 with SMTP id c13-20020a170902d48d00b001c20c608387mr1544408plg.0.1694141547104; Thu, 07 Sep 2023 19:52:27 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:2d89:7669:ac2d:f09e]) by smtp.gmail.com with ESMTPSA id n9-20020a170902e54900b001c0ce518e98sm417286plf.224.2023.09.07.19.52.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 19:52:26 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org Cc: etienne.carriere@st.com, u-boot@lists.denx.de, AKASHI Takahiro , Etienne Carriere Subject: [PATCH v3 05/13] firmware: scmi: install base protocol to SCMI agent Date: Fri, 8 Sep 2023 11:51:30 +0900 Message-Id: <20230908025138.44405-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230908025138.44405-1-takahiro.akashi@linaro.org> References: <20230908025138.44405-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 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 SCMI base protocol is mandatory, and once SCMI node is found in a device tree, the protocol handle (udevice) is unconditionally installed to the agent. Then basic information will be retrieved from SCMI server via the protocol and saved into the agent instance's local storage. Signed-off-by: AKASHI Takahiro Reviewed-by: Simon Glass Reviewed-by: Etienne Carriere --- v3 * typo fix: add '@' for argument name in function description * eliminate dev_get_uclass_plat()'s repeated in inline * modify the code for dynamically allocated sub-vendor/agent names v2 * use helper functions, removing direct uses of ops --- drivers/firmware/scmi/scmi_agent-uclass.c | 116 ++++++++++++++++++++++ include/scmi_agent-uclass.h | 66 ++++++++++++ 2 files changed, 182 insertions(+) diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c b/drivers/firmware/scmi/scmi_agent-uclass.c index e823d105a3eb..87a667d60124 100644 --- a/drivers/firmware/scmi/scmi_agent-uclass.c +++ b/drivers/firmware/scmi/scmi_agent-uclass.c @@ -57,6 +57,9 @@ struct udevice *scmi_get_protocol(struct udevice *dev, } switch (id) { + case SCMI_PROTOCOL_ID_BASE: + proto = priv->base_dev; + break; case SCMI_PROTOCOL_ID_CLOCK: proto = priv->clock_dev; break; @@ -101,6 +104,9 @@ static int scmi_add_protocol(struct udevice *dev, } switch (proto_id) { + case SCMI_PROTOCOL_ID_BASE: + priv->base_dev = proto; + break; case SCMI_PROTOCOL_ID_CLOCK: priv->clock_dev = proto; break; @@ -237,6 +243,83 @@ int devm_scmi_process_msg(struct udevice *dev, struct scmi_msg *msg) return scmi_process_msg(protocol->parent, priv->channel, msg); } +/** + * scmi_fill_base_info - get base information about SCMI server + * @agent: SCMI agent device + * @dev: SCMI protocol device + * + * By using Base protocol commands, collect the base information + * about SCMI server. + * + * Return: 0 on success, error code otherwise + */ +static int scmi_fill_base_info(struct udevice *agent, struct udevice *dev) +{ + struct scmi_agent_priv *priv = dev_get_uclass_plat(agent); + int ret; + + ret = scmi_base_protocol_version(dev, &priv->version); + if (ret) { + dev_err(dev, "protocol_version() failed (%d)\n", ret); + return ret; + } + /* check for required version */ + if (priv->version < SCMI_BASE_PROTOCOL_VERSION) { + dev_err(dev, "base protocol version (%d) lower than expected\n", + priv->version); + return -EPROTO; + } + + ret = scmi_base_protocol_attrs(dev, &priv->num_agents, + &priv->num_protocols); + if (ret) { + dev_err(dev, "protocol_attrs() failed (%d)\n", ret); + return ret; + } + ret = scmi_base_discover_vendor(dev, &priv->vendor); + if (ret) { + dev_err(dev, "base_discover_vendor() failed (%d)\n", ret); + return ret; + } + ret = scmi_base_discover_sub_vendor(dev, &priv->sub_vendor); + if (ret) { + if (ret != -EOPNOTSUPP) { + dev_err(dev, "base_discover_sub_vendor() failed (%d)\n", + ret); + return ret; + } + priv->sub_vendor = "NA"; + } + ret = scmi_base_discover_impl_version(dev, &priv->impl_version); + if (ret) { + dev_err(dev, "base_discover_impl_version() failed (%d)\n", + ret); + return ret; + } + + priv->agent_id = 0xffffffff; /* to avoid false claim */ + ret = scmi_base_discover_agent(dev, 0xffffffff, + &priv->agent_id, &priv->agent_name); + if (ret) { + if (ret != -EOPNOTSUPP) { + dev_err(dev, + "base_discover_agent() failed for myself (%d)\n", + ret); + return ret; + } + priv->agent_name = "NA"; + } + + ret = scmi_base_discover_list_protocols(dev, &priv->protocols); + if (ret != priv->num_protocols) { + dev_err(dev, "base_discover_list_protocols() failed (%d)\n", + ret); + return ret; + } + + return 0; +} + /* * SCMI agent devices binds devices of various uclasses depeding on * the FDT description. scmi_bind_protocol() is a generic bind sequence @@ -251,6 +334,39 @@ static int scmi_bind_protocols(struct udevice *dev) struct driver *drv; struct udevice *proto; + if (!uclass_get_device(UCLASS_SCMI_AGENT, 1, &agent)) { + /* This is a second SCMI agent */ + dev_err(dev, "Cannot have more than one SCMI agent\n"); + return -EEXIST; + } + + /* initialize the device from device tree */ + drv = DM_DRIVER_GET(scmi_base_drv); + name = "scmi-base.0"; + ret = device_bind(dev, drv, name, NULL, ofnode_null(), &proto); + if (ret) { + dev_err(dev, "failed to bind base protocol\n"); + return ret; + } + ret = scmi_add_protocol(dev, SCMI_PROTOCOL_ID_BASE, proto); + if (ret) { + dev_err(dev, "failed to add protocol: %s, ret: %d\n", + proto->name, ret); + return ret; + } + + ret = device_probe(proto); + if (ret) { + dev_err(dev, "failed to probe base protocol\n"); + return ret; + } + + ret = scmi_fill_base_info(dev, proto); + if (ret) { + dev_err(dev, "failed to get base information\n"); + return ret; + } + dev_for_each_subnode(node, dev) { u32 protocol_id; diff --git a/include/scmi_agent-uclass.h b/include/scmi_agent-uclass.h index 3358c2b2d804..6fd6d54d6a5a 100644 --- a/include/scmi_agent-uclass.h +++ b/include/scmi_agent-uclass.h @@ -5,6 +5,7 @@ #ifndef _SCMI_AGENT_UCLASS_H #define _SCMI_AGENT_UCLASS_H +#include #include struct scmi_msg; @@ -12,16 +13,81 @@ struct scmi_channel; /** * struct scmi_agent_priv - private data maintained by agent instance + * @version: Version + * @num_agents: Number of agents + * @num_protocols: Number of protocols + * @impl_version: Implementation version + * @protocols: Array of protocol IDs + * @vendor: Vendor name + * @sub_vendor: Sub-vendor name + * @agent_name: Agent name + * agent_id: Identifier of agent + * @base_dev: SCMI base protocol device * @clock_dev: SCMI clock protocol device * @resetdom_dev: SCMI reset domain protocol device * @voltagedom_dev: SCMI voltage domain protocol device */ struct scmi_agent_priv { + u32 version; + u32 num_agents; + u32 num_protocols; + u32 impl_version; + u8 *protocols; + u8 *vendor; + u8 *sub_vendor; + u8 *agent_name; + u32 agent_id; + struct udevice *base_dev; struct udevice *clock_dev; struct udevice *resetdom_dev; struct udevice *voltagedom_dev; }; +static inline u32 scmi_version(struct udevice *dev) +{ + return ((struct scmi_agent_priv *)dev_get_uclass_plat(dev))->version; +} + +static inline u32 scmi_num_agents(struct udevice *dev) +{ + return ((struct scmi_agent_priv *)dev_get_uclass_plat(dev))->num_agents; +} + +static inline u32 scmi_num_protocols(struct udevice *dev) +{ + return ((struct scmi_agent_priv *)dev_get_uclass_plat(dev))->num_protocols; +} + +static inline u32 scmi_impl_version(struct udevice *dev) +{ + return ((struct scmi_agent_priv *)dev_get_uclass_plat(dev))->impl_version; +} + +static inline u8 *scmi_protocols(struct udevice *dev) +{ + return ((struct scmi_agent_priv *)dev_get_uclass_plat(dev))->protocols; +} + +static inline u8 *scmi_vendor(struct udevice *dev) +{ + return ((struct scmi_agent_priv *)dev_get_uclass_plat(dev))->vendor; +} + +static inline u8 *scmi_sub_vendor(struct udevice *dev) +{ + return ((struct scmi_agent_priv *)dev_get_uclass_plat(dev))->sub_vendor; +} + +static inline u8 *scmi_agent_name(struct udevice *dev) +{ + return ((struct scmi_agent_priv *)dev_get_uclass_plat(dev))->agent_name; +} + +static inline u32 scmi_agent_id(struct udevice *dev) +{ + return ((struct scmi_agent_priv *)dev_get_uclass_plat(dev))->agent_id; +} + /** * struct scmi_transport_ops - The functions that a SCMI transport layer must implement. */ From patchwork Fri Sep 8 02:51:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 720789 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp548570wrp; Thu, 7 Sep 2023 19:53:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHujHNR6Xsc6wKxvtnqiXRvVJxv2vC3G+qYp3y/zkBx9JizDBZe0b35lD5uSw6zt5yImLc5 X-Received: by 2002:a05:6000:1190:b0:319:6997:9432 with SMTP id g16-20020a056000119000b0031969979432mr710534wrx.1.1694141621642; Thu, 07 Sep 2023 19:53:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694141621; cv=none; d=google.com; s=arc-20160816; b=fQW8VFGHDFKWyUKwZIyRDvmoUKrgTzWDVYsnHKuvuOVf5i2WK5ngoztee86pC8aXt3 2YEvwuI7xfzo3i6CluQOMN3DJxoHOTDJZCmVhdRcRlRM1o6VkbBUFTRM6jivzTle8LIo 9Ai3ZDeoLP+yo697koB9Bv50TMeUi+hy9P1pXv53L59OoEldKpSXg5ro5xoUWXfOSaMV Tb+gbPtbNC5IFDbvvLmta+F5hD1a66LPS5twcdHLSsFqxKMAeV7fJq4MkSn4+IC0hSEY jhUboF2r/vs5+yQy0gHHcyajIRhX4r2Z1wJ+38DNPwE5ZKnsGvD0RldT5Guckyv3xe6m dBcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Luyf4+jN+xcEEas/3QA6pjJQYTZgtnyDFzxGv25LCKk=; fh=K4dQhL74gef2glEqNOnE2YOBTqRi7qf0ycKBewrN6K8=; b=SVD0c4h8VyD2WxmHckyQ1KVYte9HMFFLsFsZWp8DHP79HWrZxTbx03qh/cpoycBXBD e+BpHvGWbqw7J3vB6T/7zlpzf6ZOmSpjPRIYJa8yoJAt0EEgF9dNGs0BfVtCXEcdbM48 iCh6YOrGLvxQ0DUsdVUIUPMA4wDPMQz0u+IBGt08fPh4SwV8v4WpC5KidxFb+cO1JlpL 7KcB/da2O6pk1JoJQOtNM/poitDNbSM2Ob6K26vEIJqBFruLz6lkawfo6sMsEpzKcLp2 B9WMKmxUt7eedj3xgm7gblPO3h9rqgax1JGJMCM25JF+fAgmBrSZ9f5pVwN1LZC4g7g5 b4eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="zDx/B85r"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id f13-20020adfdb4d000000b0031807c1a37fsi353386wrj.748.2023.09.07.19.53.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 19:53:41 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="zDx/B85r"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 133B186A34; Fri, 8 Sep 2023 04:52:35 +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="zDx/B85r"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8536C86A24; Fri, 8 Sep 2023 04:52:33 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) (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 AAED3869F6 for ; Fri, 8 Sep 2023 04:52:30 +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-pl1-x62d.google.com with SMTP id d9443c01a7336-1bf11a7cf9fso3029595ad.1 for ; Thu, 07 Sep 2023 19:52:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694141549; x=1694746349; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Luyf4+jN+xcEEas/3QA6pjJQYTZgtnyDFzxGv25LCKk=; b=zDx/B85rgn+FbjPi6G16JlLovn+iuubz5QBixdYxnW0/+c7nOsAUOx3fTVz6FNY2ed T/IUr7y5ssUyoGpNXL8AtBqtp0jcLgIbzywTmWx2RVaKOj8RlYDu1eyXLgS/THMBEGF4 kwnXGPfof5xbePlEPlTTjyC7422ZopaihPxIvvs3M5qGEo2TMBFU6wYg+KXvuIOuBHO3 CFEdPJDP0VhkWBiYe1J2W4hsBal02dk6UJll+BPjDJAbXlGajzMlSn4OUtjGi6KDWWQ1 SZgENivoMHiYV2//N2KDPWYyf0IBaZMJPQoifGQRLeN6k49d8hF8q81mlwevExIrIqrm 2A8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694141549; x=1694746349; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Luyf4+jN+xcEEas/3QA6pjJQYTZgtnyDFzxGv25LCKk=; b=Rhi/6X3XE5qom6klRLMfWX8PvbT/YrZX8jYUv1JLwDjpMjVwM1d/LQVn73UWd5oNz5 cKPjsFhuxiclIJtyF1epnGPwbD2X21iL0twR0aU7duGn+Q/vGTdDfyQ/EcYS1nBrNSI4 q7hHBWjR7G6g9zMVyKVuas6aSqAJIBm8pDL+PIi55aiR40FgP051Y1nEf6GBykYrrv1Q 72rwmjpsxrDu64by3bwX1qzrmmD6v1D+IPOL1K4FiIhxXYXTEXVTVW8PLq9Mx6g3Jvr6 HMGoET5clKFd+H106kK8Ab959hkLNzi4RoayD/m27PqigEkBGDxMtBuU51XtyJyPvGvI jmYg== X-Gm-Message-State: AOJu0Yw3htCgxJEQ1x0yJOAZHV8LnbSIa4jyp7aNIHohthKtw8FPoUBo Bj2irBNQ8CzIRIa/vyEfS2Ph2w== X-Received: by 2002:a17:902:e5c1:b0:1b3:d8ac:8db3 with SMTP id u1-20020a170902e5c100b001b3d8ac8db3mr1439511plf.6.1694141549022; Thu, 07 Sep 2023 19:52:29 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:2d89:7669:ac2d:f09e]) by smtp.gmail.com with ESMTPSA id n9-20020a170902e54900b001c0ce518e98sm417286plf.224.2023.09.07.19.52.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 19:52:28 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org Cc: etienne.carriere@st.com, u-boot@lists.denx.de, AKASHI Takahiro , Etienne Carriere Subject: [PATCH v3 06/13] firmware: scmi: add a check against availability of protocols Date: Fri, 8 Sep 2023 11:51:31 +0900 Message-Id: <20230908025138.44405-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230908025138.44405-1-takahiro.akashi@linaro.org> References: <20230908025138.44405-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 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 Now that we have Base protocol support, we will be able to check if a given protocol is really supported by the SCMI server (firmware). Signed-off-by: AKASHI Takahiro Reviewed-by: Etienne Carriere --- v3 * new; import this patch from my followup patch set --- drivers/firmware/scmi/scmi_agent-uclass.c | 41 +++++++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c b/drivers/firmware/scmi/scmi_agent-uclass.c index 87a667d60124..54e17992af00 100644 --- a/drivers/firmware/scmi/scmi_agent-uclass.c +++ b/drivers/firmware/scmi/scmi_agent-uclass.c @@ -44,6 +44,38 @@ static const struct error_code scmi_linux_errmap[] = { */ struct udevice *scmi_agent; +/** + * scmi_protocol_is_supported - check availability of protocol + * @dev: SCMI agent device + * @proto_id: Identifier of protocol + * + * check if the protocol, @proto_id, is provided by the SCMI agent, + * @dev. + * + * Return: 0 on success, error code otherwise + */ +static bool scmi_protocol_is_supported(struct udevice *dev, + enum scmi_std_protocol proto_id) +{ + struct scmi_agent_priv *priv; + int i; + + if (proto_id == SCMI_PROTOCOL_ID_BASE) + return true; + + priv = dev_get_uclass_plat(dev); + if (!priv) { + dev_err(dev, "No priv data found\n"); + return false; + } + + for (i = 0; i < priv->num_protocols; i++) + if (priv->protocols[i] == proto_id) + return true; + + return false; +} + struct udevice *scmi_get_protocol(struct udevice *dev, enum scmi_std_protocol id) { @@ -380,15 +412,18 @@ static int scmi_bind_protocols(struct udevice *dev) name = ofnode_get_name(node); switch (protocol_id) { case SCMI_PROTOCOL_ID_CLOCK: - if (CONFIG_IS_ENABLED(CLK_SCMI)) + if (CONFIG_IS_ENABLED(CLK_SCMI) && + scmi_protocol_is_supported(dev, protocol_id)) drv = DM_DRIVER_GET(scmi_clock); break; case SCMI_PROTOCOL_ID_RESET_DOMAIN: - if (IS_ENABLED(CONFIG_RESET_SCMI)) + if (IS_ENABLED(CONFIG_RESET_SCMI) && + scmi_protocol_is_supported(dev, protocol_id)) drv = DM_DRIVER_GET(scmi_reset_domain); break; case SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN: - if (IS_ENABLED(CONFIG_DM_REGULATOR_SCMI)) { + if (IS_ENABLED(CONFIG_DM_REGULATOR_SCMI) && + scmi_protocol_is_supported(dev, protocol_id)) { node = ofnode_find_subnode(node, "regulators"); if (!ofnode_valid(node)) { dev_err(dev, "no regulators node\n"); From patchwork Fri Sep 8 02:51:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 720790 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp548583wrp; Thu, 7 Sep 2023 19:53:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHibqdHB2reXIvKmeJ6LJMDP0VMkvN7q7L6cbqvuSJ26SCWdMMvD2cdj/4FRfIDolFx7cv8 X-Received: by 2002:adf:f601:0:b0:317:5c18:f31d with SMTP id t1-20020adff601000000b003175c18f31dmr787762wrp.35.1694141627932; Thu, 07 Sep 2023 19:53:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694141627; cv=none; d=google.com; s=arc-20160816; b=FqHReSamshll7JQpQFGKFL/c20rOdgEiljGY6KCkxw7kN3vCKY1swdL9FNoFhrnkNR mF9xA5dHbD4W4Pdgewpg47JIzi3jydL46v0DVXm76LixQR1oBNrJrkfAFGqQG0kIq0Hu Ln95WyHUJItLF8ulA3169zIn/zaOiPiD2Gp22IvIlMCh21ZfAd94L8jk2MKUIsHrzAll lIbxCOGQcJxPp3StAE79kFTMAQDpeDhI1FYTg5hLm/QTcmwthnUkxVyX1EIsYe+DCaYx iLEA/9Ju84I80GSqGi6ScQcPNpp/UiQ64K17CGNA9iZMb7PXezfzX0wE6XTN2w7A7GzF SuFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vhAR65M4soRG9S95MgJJZMHxp3xYHMV9h+mVgJ4WbmE=; fh=K4dQhL74gef2glEqNOnE2YOBTqRi7qf0ycKBewrN6K8=; b=e0/AcDwf8Bx5+6+vNXbfqJGYm5ItV6dHommqykeJh6J19gpYCAUz0/T6+nce0brSTz WVjZlODHoz5719juBKe/e8mWlF6h/mwePciHK745Va4Z1qq9YCl4GB/q9FyUoLsLhYN1 EBKFWlJ0aWAlMauT9GYalD9SdLoL1ByGH/1ZNS/4iX76+8t33ZIQczCNbXFr8wgq4Cmm tWg2lzqTrrBEE/Vw+ckhVARdqDGexjISb0ex+PLJTIsU/GnQVy8hi/wgwChFZwGpix80 2TRDUDOGqsCHPA9bgI0L7tHkewObebl+q0fBvKsuJghqGh44gKvuzvMMEJ2UH1M7kggA tV5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h1kzt9h3; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id r6-20020a5d6946000000b0031952a55693si363109wrw.349.2023.09.07.19.53.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 19:53:47 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h1kzt9h3; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 65E3486A45; Fri, 8 Sep 2023 04:52:36 +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="h1kzt9h3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2136B86A38; Fri, 8 Sep 2023 04:52:35 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-oo1-xc36.google.com (mail-oo1-xc36.google.com [IPv6:2607:f8b0:4864:20::c36]) (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 5511B8645F for ; Fri, 8 Sep 2023 04:52:32 +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-oo1-xc36.google.com with SMTP id 006d021491bc7-57328758a72so330259eaf.1 for ; Thu, 07 Sep 2023 19:52:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694141551; x=1694746351; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vhAR65M4soRG9S95MgJJZMHxp3xYHMV9h+mVgJ4WbmE=; b=h1kzt9h3Xp6dnxt9kCCX04xeAGvIYu5KeHjwACvrn9ZrN2eG+zEewrgVfSCS+2yQ0T m/j5nii52a+Gorsc2v1rbtwSMA/pz93m1Jqab74R9Bt0/zrTPVj8JArA4Io60Bv+cftf 0ZiiOqhUkpZpHY9NgemCBqehH03+jCGZs9UueZZ9dDyXs5I2VrXRjVW8IVZ6CbS1whmf NZb/JKayg4SQ3e6h7Mlj43KKpIXCKytZn9o2m2jFFDLqouIdLqUP0jSaU+cd4aAuQwxx GESy69miNhb89FS59HXKE90zGwc1TCRSep+0IVTXAEG3FneP41UyFBdbbOWBpLHGJZ8H CskQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694141551; x=1694746351; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vhAR65M4soRG9S95MgJJZMHxp3xYHMV9h+mVgJ4WbmE=; b=Wc6GjXKuRTGgcsK/tTbm5DthHKEVeTHhBa56uA48MRxlRKR7amdg2VUe4dKaiv2xkQ yiLI7moE3da0rtAVtQUyeXWERFErubxEzL5U2kKiYagoPn/OqJZFqXQsmwMfw0ORpImd WKeOlA9TJVJ07WD1V24KGGvyhfwOJ9DIVWZq8fYwUQeCUsTMjkj4HM1FaxSI+Y4MM05q RZJxMV8YOiHOivNa66dU3vVdOvTjAosZIIR+woMUP7hmgZ6rhB2B/L6IQK/RwdtNXczl wbyiXX3525GT8+AE+YQZLMZtM4pNJUULlsOX+zUJk844ru9Zof7Gu4QGeZz0XVQtuLA4 kcCw== X-Gm-Message-State: AOJu0YyifFXqjzm3ydRn8WsmA0J0kCPSU0PE0XlsASaGqxTCCcDMdTw2 I/Br+Nclg7+fd62ggRYolZEDiw== X-Received: by 2002:a05:6808:1901:b0:3a7:5724:8bfd with SMTP id bf1-20020a056808190100b003a757248bfdmr1915054oib.1.1694141550916; Thu, 07 Sep 2023 19:52:30 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:2d89:7669:ac2d:f09e]) by smtp.gmail.com with ESMTPSA id n9-20020a170902e54900b001c0ce518e98sm417286plf.224.2023.09.07.19.52.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 19:52:30 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org Cc: etienne.carriere@st.com, u-boot@lists.denx.de, AKASHI Takahiro , Etienne Carriere Subject: [PATCH v3 07/13] sandbox: remove SCMI base node definition from test.dts Date: Fri, 8 Sep 2023 11:51:32 +0900 Message-Id: <20230908025138.44405-8-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230908025138.44405-1-takahiro.akashi@linaro.org> References: <20230908025138.44405-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 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 SCMI base protocol is mandatory and doesn't need to be listed in a device tree. Signed-off-by: AKASHI Takahiro Reviewed-by: Simon Glass Reviewed-by: Etienne Carriere --- arch/sandbox/dts/test.dts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index f351d5cb84b0..dc0bfdfb6e4b 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -693,10 +693,6 @@ #address-cells = <1>; #size-cells = <0>; - protocol@10 { - reg = <0x10>; - }; - clk_scmi: protocol@14 { reg = <0x14>; #clock-cells = <1>; From patchwork Fri Sep 8 02:51:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 720791 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp548619wrp; Thu, 7 Sep 2023 19:53:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFLKvkXSK2TNn4JCq2n+ZYop1K6ewoLAgMOc/GHh81zPQrbK/zV9QJVAhkwVTddqoMRbBxT X-Received: by 2002:a05:600c:1913:b0:402:f501:1c4 with SMTP id j19-20020a05600c191300b00402f50101c4mr863019wmq.0.1694141637975; Thu, 07 Sep 2023 19:53:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694141637; cv=none; d=google.com; s=arc-20160816; b=lPqOmAkUhwLdkTi7tZZRS/I9fiNN2Lg6a8NObRL2pgKudmZdySmbmdgBr24Kyno9o2 udiW8ZwnOeByWRQb/fn1G+7yL3C/cUxbwFEZlmTmSuSwgDxqKk23dfl9D/XjftaxRJAq kO7ZswKB6DNbiVNTFiAiHTzRaiFCDAIrRc4Vy95sjiOlOi9oJdXIRmx2/vAj+UcH5K8e XvsWss8mX8GKnkn8bwEs5cNKHFPG3kAcbot8j6jsMGKF1Ule2NppzCMixpjeI2MDST5b 2tlxx7/Rer2hqw23Cwk6QeFOomgzhR91cYtZna9yQe081+wBiVhW5WiEp/WiaINDFTKy BBxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0Hv50IzHy/EIOQJjJBGcRySaBfPZaPuknxojr+PCuWA=; fh=K4dQhL74gef2glEqNOnE2YOBTqRi7qf0ycKBewrN6K8=; b=Zmc9/LQH7TzoMQq6vE5/s9PsD8JMABPl8PQZKRLxkxUQGPsWIJGt/7lznc4wJeId7f EU0KteSg9EkU2Lls1e4X9xarv7jpTR1SA3/h+BxxZyAjmay/lYdeNWxyQztUEhsQM3k1 T46nG5wWGLS+55GhUKpqNaaMpcatosFbktbltWive0jfaPEYX/wzXCuj2Pu+yIsLf+F+ wxXeVuE2ZAzCqluQPVLlU1tRGbTIdEMoS26WcgV8uFFJrXqb5rbv4S4eB2VRiVtfM+nm McAxZAhqaIG379OWY5apVeHccALZXO14+JEko+uPM971C6ufFvnrtnaazZLrxrBA5qJy 0stQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=L1e+FLq1; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id y18-20020a5d6152000000b0031c71838a82si352721wrt.753.2023.09.07.19.53.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 19:53:57 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=L1e+FLq1; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B849986A3C; Fri, 8 Sep 2023 04:52:38 +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="L1e+FLq1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D37C386907; Fri, 8 Sep 2023 04:52:37 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) (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 A1F7D86A2B for ; Fri, 8 Sep 2023 04:52:34 +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-pl1-x631.google.com with SMTP id d9443c01a7336-1b89b0c73d7so3003535ad.1 for ; Thu, 07 Sep 2023 19:52:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694141553; x=1694746353; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0Hv50IzHy/EIOQJjJBGcRySaBfPZaPuknxojr+PCuWA=; b=L1e+FLq1QXqXHDmPSx3dDESADdkv3mNZuaku8CslKJL7xrtlofgFL2AuSt/JEeSttn 7oOhZOYIkr2D4ETPTX15dnarFfnsDsoCtleWbUE2b4Lhc7ak8rvd7me3gcrDS7ua9+wV z2gWa2AJ2ltvE/8mnIvs5QMW58W5xuTB1mP8EHaujZqfLVwbS3hHAM9ZVhyI9bqBhWTu sZBO6CK7IMg8rIOvIARBVCN8W42dHPYYCkH3mwCfBDDTc0TBiDNu1TeklCN0mJzkdgJv L3GJ3fz26rzsQZNHTE1spCqoTMJil4vbkeQTL6VP+laKJc2YVxrqN9nbK2AID4hB7m3H p6dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694141553; x=1694746353; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0Hv50IzHy/EIOQJjJBGcRySaBfPZaPuknxojr+PCuWA=; b=NIuXSreltnnstYM0G9kNkIrN7zob/3y21EA5Xkkp+3LRmTXVvT49RqAVeuaQIz727g M+2173LSMws6eYfjbl/A8BsnqIJF58NE2ySLqKARO5OxxUrEaYTbOqJUBnqQvGkoFCcX d2CK1OFTh8FJK8dnsfyFOgKQEWsTm3DS1beoVuFzmH802+ylYxtcf//+uEH4IbkM325N 3EPl4PBJsOpQfVCHOEtYfv/nHGJRBAS+g3eM/PD6gIxujz1m0CkLdQB9D+jaVankck7E uXyVVd+dG8ZoIIWOTss9cCjtv5/woBcEIKsq0PW0D7NR5mkGwStLb2NIU3MGsePWsr8X 8WKw== X-Gm-Message-State: AOJu0Ywr7w0q5mtdxadpcAme3M2RekFZ1YBxEfRcjPvkXnVjvvn6z74p P8DeJ/i8/VpxYGF68MGMAQDrlg== X-Received: by 2002:a17:902:e546:b0:1bb:9e6e:a9f3 with SMTP id n6-20020a170902e54600b001bb9e6ea9f3mr1400484plf.4.1694141552794; Thu, 07 Sep 2023 19:52:32 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:2d89:7669:ac2d:f09e]) by smtp.gmail.com with ESMTPSA id n9-20020a170902e54900b001c0ce518e98sm417286plf.224.2023.09.07.19.52.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 19:52:32 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org Cc: etienne.carriere@st.com, u-boot@lists.denx.de, AKASHI Takahiro , Etienne Carriere Subject: [PATCH v3 08/13] firmware: scmi: fake base protocol commands on sandbox Date: Fri, 8 Sep 2023 11:51:33 +0900 Message-Id: <20230908025138.44405-9-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230908025138.44405-1-takahiro.akashi@linaro.org> References: <20230908025138.44405-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 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 This is a simple implementation of SCMI base protocol for sandbox. The main use is in SCMI unit test. Signed-off-by: AKASHI Takahiro Reviewed-by: Simon Glass Reviewed-by: Etienne Carriere --- v3 * type fixes: s/udevice/dev/ in function descriptions --- drivers/firmware/scmi/sandbox-scmi_agent.c | 359 ++++++++++++++++++++- 1 file changed, 358 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/scmi/sandbox-scmi_agent.c b/drivers/firmware/scmi/sandbox-scmi_agent.c index 031882998dfa..42a5a1f37f8b 100644 --- a/drivers/firmware/scmi/sandbox-scmi_agent.c +++ b/drivers/firmware/scmi/sandbox-scmi_agent.c @@ -14,11 +14,14 @@ #include #include #include +#include +#include /* * The sandbox SCMI agent driver simulates to some extend a SCMI message * processing. It simulates few of the SCMI services for some of the * SCMI protocols embedded in U-Boot. Currently: + * - SCMI base protocol * - SCMI clock protocol emulates an agent exposing 2 clocks * - SCMI reset protocol emulates an agent exposing a reset controller * - SCMI voltage domain protocol emulates an agent exposing 2 regulators @@ -33,6 +36,21 @@ * various uclass devices, as clocks and reset controllers. */ +#define SANDBOX_SCMI_BASE_PROTOCOL_VERSION SCMI_BASE_PROTOCOL_VERSION +#define SANDBOX_SCMI_VENDOR "U-Boot" +#define SANDBOX_SCMI_SUB_VENDOR "Sandbox" +#define SANDBOX_SCMI_IMPL_VERSION 0x1 +#define SANDBOX_SCMI_AGENT_NAME "OSPM" +#define SANDBOX_SCMI_PLATFORM_NAME "platform" + +static u8 protocols[] = { + SCMI_PROTOCOL_ID_CLOCK, + SCMI_PROTOCOL_ID_RESET_DOMAIN, + SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN, +}; + +#define NUM_PROTOCOLS ARRAY_SIZE(protocols) + static struct sandbox_scmi_clk scmi_clk[] = { { .rate = 333 }, { .rate = 200 }, @@ -114,6 +132,316 @@ static struct sandbox_scmi_voltd *get_scmi_voltd_state(uint domain_id) * Sandbox SCMI agent ops */ +/* Base Protocol */ + +/** + * sandbox_scmi_base_protocol_version - implement SCMI_BASE_PROTOCOL_VERSION + * @dev: SCMI device + * @msg: SCMI message + * + * Implement SCMI_BASE_PROTOCOL_VERSION command. + */ +static int sandbox_scmi_base_protocol_version(struct udevice *dev, + struct scmi_msg *msg) +{ + struct scmi_protocol_version_out *out = NULL; + + if (!msg->out_msg || msg->out_msg_sz < sizeof(*out)) + return -EINVAL; + + out = (struct scmi_protocol_version_out *)msg->out_msg; + out->version = SANDBOX_SCMI_BASE_PROTOCOL_VERSION; + out->status = SCMI_SUCCESS; + + return 0; +} + +/** + * sandbox_scmi_base_protocol_attrs - implement SCMI_BASE_PROTOCOL_ATTRIBUTES + * @dev: SCMI device + * @msg: SCMI message + * + * Implement SCMI_BASE_PROTOCOL_ATTRIBUTES command. + */ +static int sandbox_scmi_base_protocol_attrs(struct udevice *dev, + struct scmi_msg *msg) +{ + struct scmi_protocol_attrs_out *out = NULL; + + if (!msg->out_msg || msg->out_msg_sz < sizeof(*out)) + return -EINVAL; + + out = (struct scmi_protocol_attrs_out *)msg->out_msg; + out->attributes = FIELD_PREP(0xff00, 2) | NUM_PROTOCOLS; + out->status = SCMI_SUCCESS; + + return 0; +} + +/** + * sandbox_scmi_base_message_attrs - implement + * SCMI_BASE_PROTOCOL_MESSAGE_ATTRIBUTES + * @dev: SCMI device + * @msg: SCMI message + * + * Implement SCMI_BASE_PROTOCOL_MESSAGE_ATTRIBUTES command. + */ +static int sandbox_scmi_base_message_attrs(struct udevice *dev, + struct scmi_msg *msg) +{ + u32 message_id; + struct scmi_protocol_msg_attrs_out *out = NULL; + + if (!msg->in_msg || msg->in_msg_sz < sizeof(message_id) || + !msg->out_msg || msg->out_msg_sz < sizeof(*out)) + return -EINVAL; + + message_id = *(u32 *)msg->in_msg; + out = (struct scmi_protocol_msg_attrs_out *)msg->out_msg; + + if (message_id >= SCMI_PROTOCOL_VERSION && + message_id <= SCMI_BASE_RESET_AGENT_CONFIGURATION && + message_id != SCMI_BASE_NOTIFY_ERRORS) { + out->attributes = 0; + out->status = SCMI_SUCCESS; + } else { + out->status = SCMI_NOT_FOUND; + } + + return 0; +} + +/** + * sandbox_scmi_base_discover_vendor - implement SCMI_BASE_DISCOVER_VENDOR + * @dev: SCMI device + * @msg: SCMI message + * + * Implement SCMI_BASE_DISCOVER_VENDOR command + */ +static int sandbox_scmi_base_discover_vendor(struct udevice *dev, + struct scmi_msg *msg) +{ + struct scmi_base_discover_vendor_out *out = NULL; + + if (!msg->out_msg || msg->out_msg_sz < sizeof(*out)) + return -EINVAL; + + out = (struct scmi_base_discover_vendor_out *)msg->out_msg; + strcpy(out->vendor_identifier, SANDBOX_SCMI_VENDOR); + out->status = SCMI_SUCCESS; + + return 0; +} + +/** + * sandbox_scmi_base_discover_sub_vendor - implement + * SCMI_BASE_DISCOVER_SUB_VENDOR + * @dev: SCMI device + * @msg: SCMI message + * + * Implement SCMI_BASE_DISCOVER_SUB_VENDOR command + */ +static int sandbox_scmi_base_discover_sub_vendor(struct udevice *dev, + struct scmi_msg *msg) +{ + struct scmi_base_discover_vendor_out *out = NULL; + + if (!msg->out_msg || msg->out_msg_sz < sizeof(*out)) + return -EINVAL; + + out = (struct scmi_base_discover_vendor_out *)msg->out_msg; + strcpy(out->vendor_identifier, SANDBOX_SCMI_SUB_VENDOR); + out->status = SCMI_SUCCESS; + + return 0; +} + +/** + * sandbox_scmi_base_discover_impl_version - implement + * SCMI_BASE_DISCOVER_IMPLEMENTATION_VERSION + * @dev: SCMI device + * @msg: SCMI message + * + * Implement SCMI_BASE_DISCOVER_IMPLEMENTATION_VERSION command + */ +static int sandbox_scmi_base_discover_impl_version(struct udevice *dev, + struct scmi_msg *msg) +{ + struct scmi_base_discover_impl_version_out *out = NULL; + + if (!msg->out_msg || msg->out_msg_sz < sizeof(*out)) + return -EINVAL; + + out = (struct scmi_base_discover_impl_version_out *)msg->out_msg; + out->impl_version = SANDBOX_SCMI_IMPL_VERSION; + out->status = SCMI_SUCCESS; + + return 0; +} + +/** + * sandbox_scmi_base_discover_list_protocols - implement + * SCMI_BASE_DISCOVER_LIST_PROTOCOLS + * @dev: SCMI device + * @msg: SCMI message + * + * Implement SCMI_BASE_DISCOVER_LIST_PROTOCOLS command + */ +static int sandbox_scmi_base_discover_list_protocols(struct udevice *dev, + struct scmi_msg *msg) +{ + struct scmi_base_discover_list_protocols_out *out = NULL; + + if (!msg->out_msg || msg->out_msg_sz < sizeof(*out)) + return -EINVAL; + + out = (struct scmi_base_discover_list_protocols_out *)msg->out_msg; + memcpy(out->protocols, protocols, sizeof(protocols)); + out->num_protocols = NUM_PROTOCOLS; + out->status = SCMI_SUCCESS; + + return 0; +} + +/** + * sandbox_scmi_base_discover_agent - implement SCMI_BASE_DISCOVER_AGENT + * @dev: SCMI device + * @msg: SCMI message + * + * Implement SCMI_BASE_DISCOVER_AGENT command + */ +static int sandbox_scmi_base_discover_agent(struct udevice *dev, + struct scmi_msg *msg) +{ + u32 agent_id; + struct scmi_base_discover_agent_out *out = NULL; + + if (!msg->in_msg || msg->in_msg_sz < sizeof(agent_id) || + !msg->out_msg || msg->out_msg_sz < sizeof(*out)) + return -EINVAL; + + agent_id = *(u32 *)msg->in_msg; + out = (struct scmi_base_discover_agent_out *)msg->out_msg; + out->status = SCMI_SUCCESS; + if (agent_id == 0xffffffff || agent_id == 1) { + out->agent_id = 1; + strcpy(out->name, SANDBOX_SCMI_AGENT_NAME); + } else if (!agent_id) { + out->agent_id = agent_id; + strcpy(out->name, SANDBOX_SCMI_PLATFORM_NAME); + } else { + out->status = SCMI_NOT_FOUND; + } + + return 0; +} + +/** + * sandbox_scmi_base_set_device_permissions - implement + * SCMI_BASE_SET_DEVICE_PERMISSIONS + * @dev: SCMI device + * @msg: SCMI message + * + * Implement SCMI_BASE_SET_DEVICE_PERMISSIONS command + */ +static int sandbox_scmi_base_set_device_permissions(struct udevice *dev, + struct scmi_msg *msg) +{ + struct scmi_base_set_device_permissions_in *in = NULL; + u32 *status; + + if (!msg->in_msg || msg->in_msg_sz < sizeof(*in) || + !msg->out_msg || msg->out_msg_sz < sizeof(*status)) + return -EINVAL; + + in = (struct scmi_base_set_device_permissions_in *)msg->in_msg; + status = (u32 *)msg->out_msg; + + if (in->agent_id != 1 || in->device_id != 0) + *status = SCMI_NOT_FOUND; + else if (in->flags & ~SCMI_BASE_SET_DEVICE_PERMISSIONS_ACCESS) + *status = SCMI_INVALID_PARAMETERS; + else if (in->flags & SCMI_BASE_SET_DEVICE_PERMISSIONS_ACCESS) + *status = SCMI_SUCCESS; + else + /* unset not allowed */ + *status = SCMI_DENIED; + + return 0; +} + +/** + * sandbox_scmi_base_set_protocol_permissions - implement + * SCMI_BASE_SET_PROTOCOL_PERMISSIONS + * @dev: SCMI device + * @msg: SCMI message + * + * Implement SCMI_BASE_SET_PROTOCOL_PERMISSIONS command + */ +static int sandbox_scmi_base_set_protocol_permissions(struct udevice *dev, + struct scmi_msg *msg) +{ + struct scmi_base_set_protocol_permissions_in *in = NULL; + u32 *status; + int i; + + if (!msg->in_msg || msg->in_msg_sz < sizeof(*in) || + !msg->out_msg || msg->out_msg_sz < sizeof(*status)) + return -EINVAL; + + in = (struct scmi_base_set_protocol_permissions_in *)msg->in_msg; + status = (u32 *)msg->out_msg; + + for (i = 0; i < ARRAY_SIZE(protocols); i++) + if (protocols[i] == in->command_id) + break; + if (in->agent_id != 1 || in->device_id != 0 || + i == ARRAY_SIZE(protocols)) + *status = SCMI_NOT_FOUND; + else if (in->flags & ~SCMI_BASE_SET_PROTOCOL_PERMISSIONS_ACCESS) + *status = SCMI_INVALID_PARAMETERS; + else if (in->flags & SCMI_BASE_SET_PROTOCOL_PERMISSIONS_ACCESS) + *status = SCMI_SUCCESS; + else + /* unset not allowed */ + *status = SCMI_DENIED; + + return 0; +} + +/** + * sandbox_scmi_base_reset_agent_configuration - implement + * SCMI_BASE_RESET_AGENT_CONFIGURATION + * @dev: SCMI device + * @msg: SCMI message + * + * Implement SCMI_BASE_RESET_AGENT_CONFIGURATION command + */ +static int sandbox_scmi_base_reset_agent_configuration(struct udevice *dev, + struct scmi_msg *msg) +{ + struct scmi_base_reset_agent_configuration_in *in = NULL; + u32 *status; + + if (!msg->in_msg || msg->in_msg_sz < sizeof(*in) || + !msg->out_msg || msg->out_msg_sz < sizeof(*status)) + return -EINVAL; + + in = (struct scmi_base_reset_agent_configuration_in *)msg->in_msg; + status = (u32 *)msg->out_msg; + + if (in->agent_id != 1) + *status = SCMI_NOT_FOUND; + else if (in->flags & ~SCMI_BASE_RESET_ALL_ACCESS_PERMISSIONS) + *status = SCMI_INVALID_PARAMETERS; + else + *status = SCMI_DENIED; + + return 0; +} + +/* Clock Protocol */ + static int sandbox_scmi_clock_protocol_attribs(struct udevice *dev, struct scmi_msg *msg) { @@ -475,6 +803,36 @@ static int sandbox_scmi_test_process_msg(struct udevice *dev, struct scmi_msg *msg) { switch (msg->protocol_id) { + case SCMI_PROTOCOL_ID_BASE: + switch (msg->message_id) { + case SCMI_PROTOCOL_VERSION: + return sandbox_scmi_base_protocol_version(dev, msg); + case SCMI_PROTOCOL_ATTRIBUTES: + return sandbox_scmi_base_protocol_attrs(dev, msg); + case SCMI_PROTOCOL_MESSAGE_ATTRIBUTES: + return sandbox_scmi_base_message_attrs(dev, msg); + case SCMI_BASE_DISCOVER_VENDOR: + return sandbox_scmi_base_discover_vendor(dev, msg); + case SCMI_BASE_DISCOVER_SUB_VENDOR: + return sandbox_scmi_base_discover_sub_vendor(dev, msg); + case SCMI_BASE_DISCOVER_IMPL_VERSION: + return sandbox_scmi_base_discover_impl_version(dev, msg); + case SCMI_BASE_DISCOVER_LIST_PROTOCOLS: + return sandbox_scmi_base_discover_list_protocols(dev, msg); + case SCMI_BASE_DISCOVER_AGENT: + return sandbox_scmi_base_discover_agent(dev, msg); + case SCMI_BASE_NOTIFY_ERRORS: + break; + case SCMI_BASE_SET_DEVICE_PERMISSIONS: + return sandbox_scmi_base_set_device_permissions(dev, msg); + case SCMI_BASE_SET_PROTOCOL_PERMISSIONS: + return sandbox_scmi_base_set_protocol_permissions(dev, msg); + case SCMI_BASE_RESET_AGENT_CONFIGURATION: + return sandbox_scmi_base_reset_agent_configuration(dev, msg); + default: + break; + } + break; case SCMI_PROTOCOL_ID_CLOCK: switch (msg->message_id) { case SCMI_PROTOCOL_ATTRIBUTES: @@ -517,7 +875,6 @@ static int sandbox_scmi_test_process_msg(struct udevice *dev, break; } break; - case SCMI_PROTOCOL_ID_BASE: case SCMI_PROTOCOL_ID_POWER_DOMAIN: case SCMI_PROTOCOL_ID_SYSTEM: case SCMI_PROTOCOL_ID_PERF: From patchwork Fri Sep 8 02:51:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 720792 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp548649wrp; Thu, 7 Sep 2023 19:54:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF/HfcwkjANhkUefxOpYQUxf+JL/Mp4GYSccq9uXGY7PaeT+4eOr+ZoS4Kvl7uGiqhfbN7E X-Received: by 2002:a1c:4c0d:0:b0:402:906:1e87 with SMTP id z13-20020a1c4c0d000000b0040209061e87mr1081969wmf.31.1694141647840; Thu, 07 Sep 2023 19:54:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694141647; cv=none; d=google.com; s=arc-20160816; b=CIICs6Sx1Q7t+JcTGymf6xGFfGPQwg3OA+fVNH6JRsfrDfqDo+NlbBuMmBiJcRW65Z 4R0yvGWggSAN/3NGE8bYDqBxg6s+nfkEVHtRtGuU423FhOk6EmVOFztJ3o0Vyb33rorE Z3/8quSID4XRur4tTNiTlCh/x9olH1+tN+6JaTlhHlostuUc6yceFQJgveSVhoHcWpo/ 8qsBM/q9GY8llRTTn6D1Jm0UKnows6uzREcCST21q6U5s8hwvwwnhUhUhZ9B49asPCyJ RfQW9nNh/ozQe0y8EBWrdCbeevQFmA8kRfxyUk5b7lCrJFv0DXAHpKKsVTI0+5Gb4pkN O//Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0cw+gCr9HDSitMmo/NFMCEk5FCyJsX7Ju3WfgGv1u50=; fh=K4dQhL74gef2glEqNOnE2YOBTqRi7qf0ycKBewrN6K8=; b=CZw2H0+AYQgft4xOsl198PexQfLeCp4unkM4YkTAN3N8AE/NRd0frVpaEN6fGyc9VS 3Ya68e+rcEV7VZNSNM0QEqGy80Ueow2gnW/fvWJRfrQ1NEcxy+wSVn3eSHuINnxA8Fwv 0Bv4nYRKDjvfBZXgYlHpJXIPG7vBsrh67k47pLnkEG7AsZmi8+SiWCA6NUq9mkcFNMW7 +T51Z6kjsAb02yvZryyURF21C7mga73yXk76WtkVA/9yOFz3cOB6RRPu4idKXmaeS3P9 a9+SJ6UaZ+C2/9OdK8ovHFNTdKG5UeA2e+7RtDpoDM+zJTwckiwGfmc4KlZlJLeaYZwz zj5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HGcZZbuO; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id j7-20020a5d6187000000b0031dc9a1c53asi352870wru.854.2023.09.07.19.54.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 19:54:07 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HGcZZbuO; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 173F1869D7; Fri, 8 Sep 2023 04:52:41 +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="HGcZZbuO"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 457DA869D7; Fri, 8 Sep 2023 04:52:39 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-oa1-x2e.google.com (mail-oa1-x2e.google.com [IPv6:2001:4860:4864:20::2e]) (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 429EA86995 for ; Fri, 8 Sep 2023 04:52:36 +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-oa1-x2e.google.com with SMTP id 586e51a60fabf-1d549d01c74so307287fac.1 for ; Thu, 07 Sep 2023 19:52:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694141555; x=1694746355; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0cw+gCr9HDSitMmo/NFMCEk5FCyJsX7Ju3WfgGv1u50=; b=HGcZZbuO0o68dDo9AfLToIJt4vCF4tdGXBFO82/D1txfpZJTJ8uPZrF18FUXfKbsbP ec8mMaUHuwjrFLBZllBcxLn5RQ6PzrKZsPU1B+gIUhBJYSZgcmoA342dBJ6fA2pt3glp /t7xdv28O2WOZBpHHMymlpEB08Sbc2L8ICEZZrIkNDrg8i5J6VTzzcOAZVu1T66CSgrj tRB6Xnc4VrhUHLEKApwGFL1ECPQJiF6ihlsamni0jaGJIT8qRdK+hEHwcMzNpe0uctOn O3D+PUFhd5GLf0Wk4jYtGJv6Hd4rFcnfQULgf+mM7Futq0+n38MAjFERhwkwp5AJFAha t/sQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694141555; x=1694746355; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0cw+gCr9HDSitMmo/NFMCEk5FCyJsX7Ju3WfgGv1u50=; b=TyYq4ViRxWq4Uxr1AhrY9BgqxOHq9HF6elkcr7U9f2k+dZqC13siP6joELV9r9Mwu/ h4WhandiIzcLL4ThW6pWDNpgcqgSvkUPl4Umdl5SUajYOUF41Q24BUhCyVb28U6nHoTr CiPSmvq+Nm1ZaZE/aQAvQKzUWN5CStQqFtEs0EY5cojoNbm3YRTUYmi8sCIFYzkJ0z+v ySFGUCvKGqx+SP4aaFyXwZLLew9EGxIcgeozCeyCPGD3dFdhEgN3ym8S+fCzXVkX3dj3 mJCxjfrT01wpyPuzpY4hSXXVTvXmV5iFGT0NKxXzCFJuxgvFXrHv0OYDdnJGYmwBroUb 9UqA== X-Gm-Message-State: AOJu0YwtRM4tAvgKcRkwftKQAqNKSyxaNrzFerTsn3p9ZXYf/9+bKy+J LkHfRzAFPzWgNoWInqiyGQkR9w== X-Received: by 2002:a05:6808:218f:b0:3a1:d457:83b5 with SMTP id be15-20020a056808218f00b003a1d45783b5mr1570743oib.3.1694141554762; Thu, 07 Sep 2023 19:52:34 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:2d89:7669:ac2d:f09e]) by smtp.gmail.com with ESMTPSA id n9-20020a170902e54900b001c0ce518e98sm417286plf.224.2023.09.07.19.52.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 19:52:34 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org Cc: etienne.carriere@st.com, u-boot@lists.denx.de, AKASHI Takahiro , Etienne Carriere Subject: [PATCH v3 09/13] test: dm: simplify SCMI unit test on sandbox Date: Fri, 8 Sep 2023 11:51:34 +0900 Message-Id: <20230908025138.44405-10-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230908025138.44405-1-takahiro.akashi@linaro.org> References: <20230908025138.44405-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 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 Adding SCMI base protocol makes it inconvenient to hold the agent instance (udevice) locally since the agent device will be re-created per each test. Just remove it and simplify the test flows. The test scenario is not changed at all. Signed-off-by: AKASHI Takahiro Reviewed-by: Simon Glass Reviewed-by: Etienne Carriere --- arch/sandbox/include/asm/scmi_test.h | 7 ++- drivers/firmware/scmi/sandbox-scmi_agent.c | 20 +------ drivers/firmware/scmi/scmi_agent-uclass.c | 3 - test/dm/scmi.c | 64 +++++++--------------- 4 files changed, 26 insertions(+), 68 deletions(-) diff --git a/arch/sandbox/include/asm/scmi_test.h b/arch/sandbox/include/asm/scmi_test.h index c72ec1e1cb25..2718336a9a50 100644 --- a/arch/sandbox/include/asm/scmi_test.h +++ b/arch/sandbox/include/asm/scmi_test.h @@ -89,10 +89,11 @@ struct sandbox_scmi_devices { #ifdef CONFIG_SCMI_FIRMWARE /** - * sandbox_scmi_service_ctx - Get the simulated SCMI services context + * sandbox_scmi_agent_ctx - Get the simulated SCMI agent context + * @dev: Reference to the test agent * @return: Reference to backend simulated resources state */ -struct sandbox_scmi_service *sandbox_scmi_service_ctx(void); +struct sandbox_scmi_agent *sandbox_scmi_agent_ctx(struct udevice *dev); /** * sandbox_scmi_devices_ctx - Get references to devices accessed through SCMI @@ -101,7 +102,7 @@ struct sandbox_scmi_service *sandbox_scmi_service_ctx(void); */ struct sandbox_scmi_devices *sandbox_scmi_devices_ctx(struct udevice *dev); #else -static inline struct sandbox_scmi_service *sandbox_scmi_service_ctx(void) +static struct sandbox_scmi_agent *sandbox_scmi_agent_ctx(struct udevice *dev) { return NULL; } diff --git a/drivers/firmware/scmi/sandbox-scmi_agent.c b/drivers/firmware/scmi/sandbox-scmi_agent.c index 42a5a1f37f8b..27d17809be43 100644 --- a/drivers/firmware/scmi/sandbox-scmi_agent.c +++ b/drivers/firmware/scmi/sandbox-scmi_agent.c @@ -66,11 +66,9 @@ static struct sandbox_scmi_voltd scmi_voltd[] = { { .id = 1, .voltage_uv = 1800000 }, }; -static struct sandbox_scmi_service sandbox_scmi_service_state; - -struct sandbox_scmi_service *sandbox_scmi_service_ctx(void) +struct sandbox_scmi_agent *sandbox_scmi_agent_ctx(struct udevice *dev) { - return &sandbox_scmi_service_state; + return dev_get_priv(dev); } static void debug_print_agent_state(struct udevice *dev, char *str) @@ -898,16 +896,8 @@ static int sandbox_scmi_test_process_msg(struct udevice *dev, static int sandbox_scmi_test_remove(struct udevice *dev) { - struct sandbox_scmi_agent *agent = dev_get_priv(dev); - - if (agent != sandbox_scmi_service_ctx()->agent) - return -EINVAL; - debug_print_agent_state(dev, "removed"); - /* We only need to dereference the agent in the context */ - sandbox_scmi_service_ctx()->agent = NULL; - return 0; } @@ -915,9 +905,6 @@ static int sandbox_scmi_test_probe(struct udevice *dev) { struct sandbox_scmi_agent *agent = dev_get_priv(dev); - if (sandbox_scmi_service_ctx()->agent) - return -EINVAL; - *agent = (struct sandbox_scmi_agent){ .clk = scmi_clk, .clk_count = ARRAY_SIZE(scmi_clk), @@ -929,9 +916,6 @@ static int sandbox_scmi_test_probe(struct udevice *dev) debug_print_agent_state(dev, "probed"); - /* Save reference for tests purpose */ - sandbox_scmi_service_ctx()->agent = agent; - return 0; }; diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c b/drivers/firmware/scmi/scmi_agent-uclass.c index 54e17992af00..b37acbb9f9db 100644 --- a/drivers/firmware/scmi/scmi_agent-uclass.c +++ b/drivers/firmware/scmi/scmi_agent-uclass.c @@ -455,9 +455,6 @@ static int scmi_bind_protocols(struct udevice *dev) } } - if (!ret) - scmi_agent = dev; - return ret; } diff --git a/test/dm/scmi.c b/test/dm/scmi.c index d87e2731ce42..881be3171b7c 100644 --- a/test/dm/scmi.c +++ b/test/dm/scmi.c @@ -23,22 +23,11 @@ #include #include -static int ut_assert_scmi_state_preprobe(struct unit_test_state *uts) -{ - struct sandbox_scmi_service *scmi_ctx = sandbox_scmi_service_ctx(); - - ut_assertnonnull(scmi_ctx); - ut_assertnull(scmi_ctx->agent); - - return 0; -} - static int ut_assert_scmi_state_postprobe(struct unit_test_state *uts, + struct sandbox_scmi_agent *agent, struct udevice *dev) { struct sandbox_scmi_devices *scmi_devices; - struct sandbox_scmi_service *scmi_ctx; - struct sandbox_scmi_agent *agent; /* Device references to check context against test sequence */ scmi_devices = sandbox_scmi_devices_ctx(dev); @@ -48,10 +37,6 @@ static int ut_assert_scmi_state_postprobe(struct unit_test_state *uts, ut_asserteq(2, scmi_devices->regul_count); /* State of the simulated SCMI server exposed */ - scmi_ctx = sandbox_scmi_service_ctx(); - ut_assertnonnull(scmi_ctx); - agent = scmi_ctx->agent; - ut_assertnonnull(agent); ut_asserteq(3, agent->clk_count); ut_assertnonnull(agent->clk); ut_asserteq(1, agent->reset_count); @@ -63,27 +48,32 @@ static int ut_assert_scmi_state_postprobe(struct unit_test_state *uts, } static int load_sandbox_scmi_test_devices(struct unit_test_state *uts, + struct sandbox_scmi_agent **ctx, struct udevice **dev) { - int ret; + struct udevice *agent_dev; - ret = ut_assert_scmi_state_preprobe(uts); - if (ret) - return ret; + ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi", + &agent_dev)); + ut_assertnonnull(agent_dev); + + *ctx = sandbox_scmi_agent_ctx(agent_dev); + ut_assertnonnull(*ctx); + /* probe */ ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "sandbox_scmi", dev)); ut_assertnonnull(*dev); - return ut_assert_scmi_state_postprobe(uts, *dev); + return ut_assert_scmi_state_postprobe(uts, *ctx, *dev); } static int release_sandbox_scmi_test_devices(struct unit_test_state *uts, struct udevice *dev) { + /* un-probe */ ut_assertok(device_remove(dev, DM_REMOVE_NORMAL)); - /* Not sure test devices are fully removed, agent may not be visible */ return 0; } @@ -93,10 +83,11 @@ static int release_sandbox_scmi_test_devices(struct unit_test_state *uts, */ static int dm_test_scmi_sandbox_agent(struct unit_test_state *uts) { + struct sandbox_scmi_agent *ctx; struct udevice *dev = NULL; int ret; - ret = load_sandbox_scmi_test_devices(uts, &dev); + ret = load_sandbox_scmi_test_devices(uts, &ctx, &dev); if (!ret) ret = release_sandbox_scmi_test_devices(uts, dev); @@ -106,23 +97,18 @@ DM_TEST(dm_test_scmi_sandbox_agent, UT_TESTF_SCAN_FDT); static int dm_test_scmi_clocks(struct unit_test_state *uts) { - struct sandbox_scmi_devices *scmi_devices; - struct sandbox_scmi_service *scmi_ctx; struct sandbox_scmi_agent *agent; + struct sandbox_scmi_devices *scmi_devices; struct udevice *dev; int ret_dev; int ret; - ret = load_sandbox_scmi_test_devices(uts, &dev); + ret = load_sandbox_scmi_test_devices(uts, &agent, &dev); if (ret) return ret; scmi_devices = sandbox_scmi_devices_ctx(dev); ut_assertnonnull(scmi_devices); - scmi_ctx = sandbox_scmi_service_ctx(); - ut_assertnonnull(scmi_ctx); - agent = scmi_ctx->agent; - ut_assertnonnull(agent); /* Test SCMI clocks rate manipulation */ ut_asserteq(333, agent->clk[0].rate); @@ -169,22 +155,17 @@ DM_TEST(dm_test_scmi_clocks, UT_TESTF_SCAN_FDT); static int dm_test_scmi_resets(struct unit_test_state *uts) { - struct sandbox_scmi_devices *scmi_devices; - struct sandbox_scmi_service *scmi_ctx; struct sandbox_scmi_agent *agent; + struct sandbox_scmi_devices *scmi_devices; struct udevice *dev = NULL; int ret; - ret = load_sandbox_scmi_test_devices(uts, &dev); + ret = load_sandbox_scmi_test_devices(uts, &agent, &dev); if (ret) return ret; scmi_devices = sandbox_scmi_devices_ctx(dev); ut_assertnonnull(scmi_devices); - scmi_ctx = sandbox_scmi_service_ctx(); - ut_assertnonnull(scmi_ctx); - agent = scmi_ctx->agent; - ut_assertnonnull(agent); /* Test SCMI resect controller manipulation */ ut_assert(!agent->reset[0].asserted); @@ -201,21 +182,16 @@ DM_TEST(dm_test_scmi_resets, UT_TESTF_SCAN_FDT); static int dm_test_scmi_voltage_domains(struct unit_test_state *uts) { - struct sandbox_scmi_devices *scmi_devices; - struct sandbox_scmi_service *scmi_ctx; struct sandbox_scmi_agent *agent; + struct sandbox_scmi_devices *scmi_devices; struct dm_regulator_uclass_plat *uc_pdata; struct udevice *dev; struct udevice *regul0_dev; - ut_assertok(load_sandbox_scmi_test_devices(uts, &dev)); + ut_assertok(load_sandbox_scmi_test_devices(uts, &agent, &dev)); scmi_devices = sandbox_scmi_devices_ctx(dev); ut_assertnonnull(scmi_devices); - scmi_ctx = sandbox_scmi_service_ctx(); - ut_assertnonnull(scmi_ctx); - agent = scmi_ctx->agent; - ut_assertnonnull(agent); /* Set/Get an SCMI voltage domain level */ regul0_dev = scmi_devices->regul[0]; From patchwork Fri Sep 8 02:51:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 720793 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp548682wrp; Thu, 7 Sep 2023 19:54:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHnrkId+HZK2X+osCLFMXkMqgcoAKvOnnGWS75pafxhGs8qek+zGymnTD50ET3mBQjTsoCT X-Received: by 2002:a05:6000:cd:b0:313:f399:6cea with SMTP id q13-20020a05600000cd00b00313f3996ceamr907318wrx.4.1694141657733; Thu, 07 Sep 2023 19:54:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694141657; cv=none; d=google.com; s=arc-20160816; b=jEKNLyajvrfONc6uGyN4QV4LI/jeSDxqI2k2UbyhiR+KLhTVn8ZLubX5Q3BSqYi2kf qV+SS9gIdVZshmIPHUfidSmI5J51fRBzjB1ET6GVm3uw8IAUNP5duyOtmvbXbYHcuPgB zej2Nm7N+SaRxwcV1Awc8c00OdXk7BYTkQOXfeBLmoI3rKvIpWbG+A/G2rlwlvTWk/Xm PnDY8OO7g2/CXtxkttAYvA+IJ96sAJ/fPyHCAep4XghRohXkKYDRrWyMOCsnGulzJoYp QiEAY9UTPcnNzpWs5unQk7lyMgn7q5WbULq8y8aU54CzZMx+GPKhFKt7w300PbB/lLtE d0hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=eIaAJycgoZjI+6NxJ0ZDkEzIUsAQGu51dDrbUXEUrF4=; fh=K4dQhL74gef2glEqNOnE2YOBTqRi7qf0ycKBewrN6K8=; b=d/NkMUktlWvfyIiYDSEXwicfl8HyZl9Vms7OqSfoRQEpwvLf9KhoR21g83n3R+Gevb OgxwOdnv8vrngnyt/Kd7PXsbmzS0vhQ64Hexnx9glTe6rHvhnJV5tVmNYeSy2wvGS67f 7Xvam1oydP1x4+S4dN81oF1KbMBQzs9H5MTayIvfS88Y7r6CyD1nDB2op0r5tlmoc1f+ q5M6XLM0uP6uY1OPBOelmkwZ5Ert4pzoDF3P5fQsRRSK/unyRRK/KCn1xmnR8WS0ZT8Y lrD6Ut+WpOnWsdxEh6x4vMdwHIFbitff+zOCxwoQbrmlW1WCcuCA3Xnkco1u1G6Jldpa wfiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CNrwkF4S; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id b13-20020a5d40cd000000b0031adbd6332fsi352490wrq.915.2023.09.07.19.54.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 19:54:17 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CNrwkF4S; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 67C9986A33; Fri, 8 Sep 2023 04:52:42 +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="CNrwkF4S"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CBBE686A2B; Fri, 8 Sep 2023 04:52:41 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) (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 68F1686A2F for ; Fri, 8 Sep 2023 04:52:38 +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-pl1-x62e.google.com with SMTP id d9443c01a7336-1bf11a7cf9fso3029725ad.1 for ; Thu, 07 Sep 2023 19:52:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694141557; x=1694746357; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eIaAJycgoZjI+6NxJ0ZDkEzIUsAQGu51dDrbUXEUrF4=; b=CNrwkF4S4iveHU7B3CpVTGe9uSx8po8nkGjwUoGPxfEZ6PwV4sinCtsEj3/rpz47ae KErDpKKH6DkHh00LBYQ6oTMKJg05hbjB0JU94I+BZkRtT21Mq41uhHVzVfKMWfmbLuMB MlRVeE3EvsgnUpsh1oW0cFI298hddy+3Vik5QyEYvDf9VDeDnSGmK6dZnIxaV1fQ41Rs CgHeoteiwxgyhxWnB7gfofrNf/n/7yHC4tocpG9nI7fxtydubtJyJ1v8tWlcNsJqX83m aM3DXiyy7497s3GDR5fNNGZwP6yaknUsW5Bfr9uLMrj10dWxdNGu7xouZahZmIA30PMx cMjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694141557; x=1694746357; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eIaAJycgoZjI+6NxJ0ZDkEzIUsAQGu51dDrbUXEUrF4=; b=dLqIpjoooVbDwB95ggu7D32kxXEoUZkyOYNmk6YV+mvcebXE2miybRSp5qTg5oPhJh EFC2AYBcbrUQb2p9YYKUV1POYwSoDjBKdWsDtMEJIWvFG9TDaKQIdDLr4wu7sL/zhv+J J3naIzeWhJ5ZIAxkIb0gq7DkBDMFRkL2IDW6tntPVW/KrYTB3H0I/U7sUfZMLyCwS5UC L8XrWPMLVzOynEn9jH83inY8wobMp9vk3ta0DlQg5HVa4MFpOMSdmXHRZ3zdioy7VjwF vA5UfGh/meMnDb61BEvQOiSdOIR9nUkriATKcBZCg1m1/8TNkLm2lZZreZ29TmNoMUjz jZvg== X-Gm-Message-State: AOJu0YyFC/CRp9KKvb2xvH4espBSyoo4oPY1EuRDxm87+7wwT0/5hVJV BNmXU5XwsrW9e8vPQGsm+7XMcCYvryLTKJpKvatkAA== X-Received: by 2002:a17:902:e849:b0:1bb:83ec:832 with SMTP id t9-20020a170902e84900b001bb83ec0832mr1528338plg.2.1694141556695; Thu, 07 Sep 2023 19:52:36 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:2d89:7669:ac2d:f09e]) by smtp.gmail.com with ESMTPSA id n9-20020a170902e54900b001c0ce518e98sm417286plf.224.2023.09.07.19.52.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 19:52:36 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org Cc: etienne.carriere@st.com, u-boot@lists.denx.de, AKASHI Takahiro , Etienne Carriere Subject: [PATCH v3 10/13] test: dm: add SCMI base protocol test Date: Fri, 8 Sep 2023 11:51:35 +0900 Message-Id: <20230908025138.44405-11-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230908025138.44405-1-takahiro.akashi@linaro.org> References: <20230908025138.44405-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 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 Added is a new unit test for SCMI base protocol, which will exercise all the commands provided by the protocol, except SCMI_BASE_NOTIFY_ERRORS. $ ut dm scmi_base It is assumed that test.dtb is used as sandbox's device tree. Signed-off-by: AKASHI Takahiro Reviewed-by: Etienne Carriere --- v3 * typo: s/scmi_base_protocol_attrs/scmi_base_protocol_message_attrs/ * modify the code for dynamically allocated vendor/agent names v2 * use helper functions, removing direct uses of ops --- test/dm/scmi.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/test/dm/scmi.c b/test/dm/scmi.c index 881be3171b7c..0785948186f0 100644 --- a/test/dm/scmi.c +++ b/test/dm/scmi.c @@ -16,6 +16,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -95,6 +98,115 @@ static int dm_test_scmi_sandbox_agent(struct unit_test_state *uts) } DM_TEST(dm_test_scmi_sandbox_agent, UT_TESTF_SCAN_FDT); +static int dm_test_scmi_base(struct unit_test_state *uts) +{ + struct udevice *agent_dev, *base; + struct scmi_agent_priv *priv; + u32 version, num_agents, num_protocols, impl_version; + u32 attributes, agent_id; + char *vendor, *agent_name; + u8 *protocols; + int ret; + + /* preparation */ + ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi", + &agent_dev)); + ut_assertnonnull(agent_dev); + ut_assertnonnull(priv = dev_get_uclass_plat(agent_dev)); + ut_assertnonnull(base = scmi_get_protocol(agent_dev, + SCMI_PROTOCOL_ID_BASE)); + + /* version */ + ret = scmi_base_protocol_version(base, &version); + ut_assertok(ret); + ut_asserteq(priv->version, version); + + /* protocol attributes */ + ret = scmi_base_protocol_attrs(base, &num_agents, &num_protocols); + ut_assertok(ret); + ut_asserteq(priv->num_agents, num_agents); + ut_asserteq(priv->num_protocols, num_protocols); + + /* discover vendor */ + ret = scmi_base_discover_vendor(base, &vendor); + ut_assertok(ret); + ut_asserteq_str(priv->vendor, vendor); + free(vendor); + + /* message attributes */ + ret = scmi_protocol_message_attrs(base, + SCMI_BASE_DISCOVER_SUB_VENDOR, + &attributes); + ut_assertok(ret); + ut_assertok(attributes); + + /* discover sub vendor */ + ret = scmi_base_discover_sub_vendor(base, &vendor); + ut_assertok(ret); + ut_asserteq_str(priv->sub_vendor, vendor); + free(vendor); + + /* impl version */ + ret = scmi_base_discover_impl_version(base, &impl_version); + ut_assertok(ret); + ut_asserteq(priv->impl_version, impl_version); + + /* discover agent (my self) */ + ret = scmi_base_discover_agent(base, 0xffffffff, &agent_id, + &agent_name); + ut_assertok(ret); + ut_asserteq(priv->agent_id, agent_id); + ut_asserteq_str(priv->agent_name, agent_name); + free(agent_name); + + /* discover protocols */ + ret = scmi_base_discover_list_protocols(base, &protocols); + ut_asserteq(num_protocols, ret); + ut_asserteq_mem(priv->protocols, protocols, sizeof(u8) * num_protocols); + free(protocols); + + /* + * NOTE: Sandbox SCMI driver handles device-0 only. It supports setting + * access and protocol permissions, but doesn't allow unsetting them nor + * resetting the configurations. + */ + /* set device permissions */ + ret = scmi_base_set_device_permissions(base, agent_id, 0, + SCMI_BASE_SET_DEVICE_PERMISSIONS_ACCESS); + ut_assertok(ret); /* SCMI_SUCCESS */ + ret = scmi_base_set_device_permissions(base, agent_id, 1, + SCMI_BASE_SET_DEVICE_PERMISSIONS_ACCESS); + ut_asserteq(-ENOENT, ret); /* SCMI_NOT_FOUND */ + ret = scmi_base_set_device_permissions(base, agent_id, 0, 0); + ut_asserteq(-EACCES, ret); /* SCMI_DENIED */ + + /* set protocol permissions */ + ret = scmi_base_set_protocol_permissions(base, agent_id, 0, + SCMI_PROTOCOL_ID_CLOCK, + SCMI_BASE_SET_PROTOCOL_PERMISSIONS_ACCESS); + ut_assertok(ret); /* SCMI_SUCCESS */ + ret = scmi_base_set_protocol_permissions(base, agent_id, 1, + SCMI_PROTOCOL_ID_CLOCK, + SCMI_BASE_SET_PROTOCOL_PERMISSIONS_ACCESS); + ut_asserteq(-ENOENT, ret); /* SCMI_NOT_FOUND */ + ret = scmi_base_set_protocol_permissions(base, agent_id, 0, + SCMI_PROTOCOL_ID_CLOCK, 0); + ut_asserteq(-EACCES, ret); /* SCMI_DENIED */ + + /* reset agent configuration */ + ret = scmi_base_reset_agent_configuration(base, agent_id, 0); + ut_asserteq(-EACCES, ret); /* SCMI_DENIED */ + ret = scmi_base_reset_agent_configuration(base, agent_id, + SCMI_BASE_RESET_ALL_ACCESS_PERMISSIONS); + ut_asserteq(-EACCES, ret); /* SCMI_DENIED */ + ret = scmi_base_reset_agent_configuration(base, agent_id, 0); + ut_asserteq(-EACCES, ret); /* SCMI_DENIED */ + + return 0; +} + +DM_TEST(dm_test_scmi_base, UT_TESTF_SCAN_FDT); + static int dm_test_scmi_clocks(struct unit_test_state *uts) { struct sandbox_scmi_agent *agent; From patchwork Fri Sep 8 02:51:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 720794 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp548717wrp; Thu, 7 Sep 2023 19:54:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFe51BsA4lCtpTo2/TOxfF7vf4N/8miuK9JmWV67oH4VcyXvW5Pv5GSmzJBIl6Wy3zD4nZu X-Received: by 2002:a05:600c:2946:b0:3fc:7eb:1119 with SMTP id n6-20020a05600c294600b003fc07eb1119mr1181583wmd.15.1694141667402; Thu, 07 Sep 2023 19:54:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694141667; cv=none; d=google.com; s=arc-20160816; b=Y/dmkbh9oYachOP1L67+xBUW6uvwEzFYBGbnq2NETdUqAs/BJrr2J1mEO4Mrj8PP74 RA3avRzl3qsoIG+hlxfsNMmArYS8Fh0PdPGdFA7mFyeKvcfCUEIfHMKPTCnk4fE6nkIP 41egbqiU3rYNcvlxSnfE65zoYdR8lHd6rvkraQ6O9SQU+9EfPWiVg1jo/4pwxZkzHbzh vQpCiH6IQacqGiEVzB1FgjPKf7O6RRrrJQSOPL7bbixHqPmHcEnqtqjNFfJmQ6hs1uq7 gSD8zaUc4Rsi48x56auyaXkQWnzkDEQiwAzfvPbIT3hsQIMIjc9BrrsmtVx2jkRC0gVG PFNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=q0FkoP3w1CPqPpr0ceh6OYlsga4yz8DeWrXbi96YnB0=; fh=K4dQhL74gef2glEqNOnE2YOBTqRi7qf0ycKBewrN6K8=; b=SKqVIrURZtgUCysFgBcR0OkyMIIw98XgPbpmgBn4UL3bpQrhMSPG3eEOvOKQKPpg8m L4R+YYO+x4jrn7jpnL7nelBhOU0Z9GxHfkZJYIib9Y55o0dE54Y3R1Z/3fjPahqFyE4O 6MTwj80GMsUEzaa2gfScnBw+c8aID+L35b8X4tRjtChJFA5or6Jm/sn4nLndbgXV2Ie+ pbRi3qggQWhY0UAFZT5pd/9BYyFJbnmDEuCJ+2oelWqZiKLL/E0iF/PQ72qiwyShJVm1 NfBgH0Hgt27rTPtNnGb9PKPXohO01RWHdFqWJu+TET5GwXdacrSEMfkyK9J5ExfInudn WEMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=R0LaUf6J; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id n39-20020a05600c502700b003fa800e8efcsi1744230wmr.95.2023.09.07.19.54.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 19:54:27 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=R0LaUf6J; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BE89A86A5A; Fri, 8 Sep 2023 04:52:44 +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="R0LaUf6J"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5FE8B86A3F; Fri, 8 Sep 2023 04:52:43 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) (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 4946B86995 for ; Fri, 8 Sep 2023 04:52:40 +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-pl1-x630.google.com with SMTP id d9443c01a7336-1c0a4333e03so3612995ad.0 for ; Thu, 07 Sep 2023 19:52:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694141558; x=1694746358; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=q0FkoP3w1CPqPpr0ceh6OYlsga4yz8DeWrXbi96YnB0=; b=R0LaUf6JDzAxfsLtwLzIbNMepnBnyZ3yzT/SwtHkxYULGrid/x+k4uukz9rE9JgBmk LOMNyO5bJHKe/XmHv0fwDtQ3rWbM056xXA1DK3ZA2fib6S5AT4K1Af3xztMdkeGx8mIW IT/FPV40SUoqXxCk9dzMVdNt8cnGseiTCfJQcMs2XlWoaMGpLBWNje2n7zhlCb819OLe G+OIn9E1BYj36qvRQpvELNdW1Hztr0yTxoSnUf0e5QIr3nRc/wx5QSxHSZVs5GOabz1b oX2jA8yTf7Dm6XUxjrPsZIP5VhhWZ7b9YAqc9RyckNYzPvIstcF1nNJO4FR+qBTtE7/B NHIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694141558; x=1694746358; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q0FkoP3w1CPqPpr0ceh6OYlsga4yz8DeWrXbi96YnB0=; b=bdPUqRbqE2+VaYPMbRQVlvyNq+1ohOcMmGD4Wj0Rr1XdQ/2zUSWSHF7lKJKWspBZga Gp/wREAgVHepLGbiBPclZlqRKddJb5dIpIeOoPJUoIYUevICN3LC2LJE1x63p7uoULEB ln7UPinxlCdh0az2Uy50cMrB87iAafwI8kNiSiYvR4AGIViVCKKd4qLFF9GTzEm3QMpx 80hmUiFtY5VFa4EDvpMS8X26Ht+eNCoNFXF6zvGPKZZQRW+5hQqsAyKMaTu8o4wImjK/ SAOu46j6zFi7mzh8LYnZKtWESVyvS5hyyscyiG7TVx0D9LhKLLFu4K4RZXu8HJlfbVGa SV6w== X-Gm-Message-State: AOJu0YyJCUqEYLYBEcKKQhWxwawc0QVe2RiCqny8XscFKoaD0XfOsw2R 6AzNTJ8qVgPDsBxdQcd5pchfpw== X-Received: by 2002:a17:902:f54f:b0:1c0:bf60:ba82 with SMTP id h15-20020a170902f54f00b001c0bf60ba82mr1406896plf.5.1694141558641; Thu, 07 Sep 2023 19:52:38 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:2d89:7669:ac2d:f09e]) by smtp.gmail.com with ESMTPSA id n9-20020a170902e54900b001c0ce518e98sm417286plf.224.2023.09.07.19.52.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 19:52:38 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org Cc: etienne.carriere@st.com, u-boot@lists.denx.de, AKASHI Takahiro , Etienne Carriere Subject: [PATCH v3 11/13] cmd: add scmi command for SCMI firmware Date: Fri, 8 Sep 2023 11:51:36 +0900 Message-Id: <20230908025138.44405-12-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230908025138.44405-1-takahiro.akashi@linaro.org> References: <20230908025138.44405-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 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 This command, "scmi", may provide a command line interface to various SCMI protocols. It supports at least initially SCMI base protocol and is intended mainly for debug purpose. Signed-off-by: AKASHI Takahiro Reviewed-by: Simon Glass Reviewed-by: Etienne Carriere --- v3 * describe that arguments are in hex at a help message * modify the code for dynamically allocated agent names v2 * remove sub command category, 'scmi base', for simplicity --- cmd/Kconfig | 9 ++ cmd/Makefile | 1 + cmd/scmi.c | 337 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 347 insertions(+) create mode 100644 cmd/scmi.c diff --git a/cmd/Kconfig b/cmd/Kconfig index 43ca10f69ccf..f46152ace7d8 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -2533,6 +2533,15 @@ 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 (System + Control and Management Interface) protocols available on Arm + platforms to manage system resources. endmenu menu "Filesystem commands" diff --git a/cmd/Makefile b/cmd/Makefile index 9bebf321c397..ad3810b17e93 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -158,6 +158,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..5efec8ad87fd --- /dev/null +++ b/cmd/scmi.c @@ -0,0 +1,337 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * SCMI (System Control and Management Interface) utility command + * + * Copyright (c) 2023 Linaro Limited + * Author: AKASHI Takahiro + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include /* uclass_get_device */ +#include +#include + +static struct udevice *agent; +static struct udevice *base_proto; + +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"}, +}; + +/** + * get_proto_name() - get the name of SCMI protocol + * + * @id: SCMI Protocol ID + * + * Get the printable name of the protocol, @id + * + * Return: Name string on success, NULL on failure + */ +static const char *get_proto_name(enum scmi_std_protocol id) +{ + 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_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_info(struct cmd_tbl *cmdtp, int flag, int argc, + char * const argv[]) +{ + u32 agent_id, num_protocols; + u8 *agent_name, *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 = scmi_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); + free(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", get_proto_name(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_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_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 = scmi_base_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 = scmi_base_set_device_permissions(base_proto, agent_id, + device_id, flags); + if (ret) { + printf("%s access to device:%u failed (%d)\n", + flags ? "Allowing" : "Denying", device_id, ret); + return CMD_RET_FAILURE; + } + + return CMD_RET_SUCCESS; +} + +/** + * do_scmi_set_proto() - set protocol permission to device + * + * @cmdtp: Command table + * @flag: Command flag + * @argc: Number of arguments + * @argv: Argument array + * + * Set protocol permission to device with SCMI_BASE_SET_PROTOCOL_PERMISSIONS + * + * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure + */ +static int do_scmi_set_proto(struct cmd_tbl *cmdtp, int flag, int argc, + char * const argv[]) +{ + u32 agent_id, device_id, protocol_id, flags, attributes; + char *end; + int ret; + + if (argc != 5) + 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; + + protocol_id = simple_strtoul(argv[3], &end, 16); + if (*end != '\0') + return CMD_RET_USAGE; + + flags = simple_strtoul(argv[4], &end, 16); + if (*end != '\0') + return CMD_RET_USAGE; + + ret = scmi_base_protocol_message_attrs(base_proto, + SCMI_BASE_SET_PROTOCOL_PERMISSIONS, + &attributes); + if (ret) { + printf("This operation is not supported\n"); + return CMD_RET_FAILURE; + } + + ret = scmi_base_set_protocol_permissions(base_proto, agent_id, + device_id, protocol_id, + flags); + if (ret) { + printf("%s access to protocol:0x%x on device:%u failed (%d)\n", + flags ? "Allowing" : "Denying", protocol_id, device_id, + ret); + return CMD_RET_FAILURE; + } + + return CMD_RET_SUCCESS; +} + +/** + * do_scmi_reset() - reset platform resource settings + * + * @cmdtp: Command table + * @flag: Command flag + * @argc: Number of arguments + * @argv: Argument array + * + * Reset platform resource settings with BASE_RESET_AGENT_CONFIGURATION + * + * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure + */ +static int do_scmi_reset(struct cmd_tbl *cmdtp, int flag, int argc, + char * const argv[]) +{ + u32 agent_id, flags, attributes; + char *end; + int ret; + + if (argc != 3) + return CMD_RET_USAGE; + + agent_id = simple_strtoul(argv[1], &end, 16); + if (*end != '\0') + return CMD_RET_USAGE; + + flags = simple_strtoul(argv[2], &end, 16); + if (*end != '\0') + return CMD_RET_USAGE; + + ret = scmi_base_protocol_message_attrs(base_proto, + SCMI_BASE_RESET_AGENT_CONFIGURATION, + &attributes); + if (ret) { + printf("Reset is not supported\n"); + return CMD_RET_FAILURE; + } + + ret = scmi_base_reset_agent_configuration(base_proto, agent_id, flags); + if (ret) { + printf("Reset failed (%d)\n", ret); + return CMD_RET_FAILURE; + } + + return CMD_RET_SUCCESS; +} + +static struct cmd_tbl cmd_scmi_sub[] = { + U_BOOT_CMD_MKENT(info, CONFIG_SYS_MAXARGS, 1, + do_scmi_info, "", ""), + U_BOOT_CMD_MKENT(perm_dev, CONFIG_SYS_MAXARGS, 1, + do_scmi_set_dev, "", ""), + U_BOOT_CMD_MKENT(perm_proto, CONFIG_SYS_MAXARGS, 1, + do_scmi_set_proto, "", ""), + U_BOOT_CMD_MKENT(reset, CONFIG_SYS_MAXARGS, 1, + do_scmi_reset, "", ""), +}; + +/** + * do_scmi() - SCMI utility + * + * @cmdtp: Command table + * @flag: Command flag + * @argc: Number of arguments + * @argv: Argument array + * + * Provide user interfaces to SCMI protocols. + * + * Return: CMD_RET_SUCCESS on success, + * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure + */ +static int do_scmi(struct cmd_tbl *cmdtp, int flag, + int argc, char *const argv[]) +{ + struct cmd_tbl *cp; + + if (argc < 2) + return CMD_RET_USAGE; + + argc--; argv++; + + if (!agent) { + if (uclass_get_device(UCLASS_SCMI_AGENT, 0, &agent)) { + printf("Cannot find any SCMI agent\n"); + return CMD_RET_FAILURE; + } + } + + if (!base_proto) + base_proto = scmi_get_protocol(agent, SCMI_PROTOCOL_ID_BASE); + if (!base_proto) { + printf("SCMI base protocol not found\n"); + return CMD_RET_FAILURE; + } + + cp = find_cmd_tbl(argv[0], cmd_scmi_sub, ARRAY_SIZE(cmd_scmi_sub)); + if (!cp) + return CMD_RET_USAGE; + + return cp->cmd(cmdtp, flag, argc, argv); +} + +static char scmi_help_text[] = + " - SCMI utility\n" + " info - get the info of SCMI services\n" + " perm_dev \n" + " - set access permission to device\n" + " perm_proto " + " \n" + " - set protocol permission to device\n" + " reset \n" + " - reset platform resource settings\n" + ""; + +U_BOOT_CMD(scmi, CONFIG_SYS_MAXARGS, 0, do_scmi, "SCMI utility", + scmi_help_text); From patchwork Fri Sep 8 02:51:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 720795 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp548760wrp; Thu, 7 Sep 2023 19:54:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFnzSyS94E5HGtSth8YaciGKXySJKHzKQzTssybRTItXive8M2jT15y5b7AE+YOpGIFpmuf X-Received: by 2002:adf:f712:0:b0:317:5351:e428 with SMTP id r18-20020adff712000000b003175351e428mr751420wrp.4.1694141678394; Thu, 07 Sep 2023 19:54:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694141678; cv=none; d=google.com; s=arc-20160816; b=YE1xwhYQkLiXK/g2KMxtpN2w8xlT/QCBJlPTob2g2pOp/5Qa7XNuKGk1eW+1nkhOLS V75niblLhjgNa2dJArVlVmPGqGGtSVaX6cs2ulyV5VkdZ6tv73uKFigrBvw0cvNt3/Me EFbMkfMhe1VHCex12pzSaV4U/Iy9L+CFzYI6qyF5cRPfkclmiacZUv5s/2cMIyQAtWGd ZCqWW19AYC9mpRFrusiPn3ALEgKUOSYVCFcaXNo4q4e/ykKXw6sRUaKjjurQi7/eEBVI z+md18Lddl33KzsKNrCfPKZ9ZD+v3uxwIeZtt8kG9aF7o87bojFjVtdfAcrRSc3eUX6F bBIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=R+nCrwralLYJWw3cK2cn/j0ATdvZUzxwirrlaBQWDDA=; fh=K4dQhL74gef2glEqNOnE2YOBTqRi7qf0ycKBewrN6K8=; b=HSUjZn5Bcvv4SltbrPpQSrZskTlj2wTauDiMfKUrYA+36TEGr9pSveFwiu2Lj0HoPK fBfiDsgkuN6E/IikY3GL7q9dXpRqDFw71b4LJ5ocQ8OaXAqLxG+nrEXAAF97Dd+JUsnO SGyoOEMU8FOJkSGok6zFLx0VLEbb1oWehmaKGJUO3jGFldcNsY2MxO2CzsKiVc4eKl+Y MBgspanz454gH97snUwYUVZox45rqGuLAoNQ39XgxYT5kfp5ugip8qDRkvPcnorJc3hP YcqkUYTssJ9kqsXU8gX70I2Zr7u8pJDsGtHNt1l94XKE1Zw8cwgaeX6GiV7C03olTa5f c9pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NhFJKcTR; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id e8-20020adfe388000000b0031984230fd4si354505wrm.293.2023.09.07.19.54.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 19:54:38 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NhFJKcTR; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 17FA586A56; Fri, 8 Sep 2023 04:52:47 +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="NhFJKcTR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 90C2086A63; Fri, 8 Sep 2023 04:52:45 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) (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 46E2D86A2B for ; Fri, 8 Sep 2023 04:52:42 +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-pl1-x631.google.com with SMTP id d9443c01a7336-1c0a4333e03so3613065ad.0 for ; Thu, 07 Sep 2023 19:52:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694141560; x=1694746360; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=R+nCrwralLYJWw3cK2cn/j0ATdvZUzxwirrlaBQWDDA=; b=NhFJKcTR513k0jpTVrCDZucwGSEO73AzKDNj29KI+GetNB8EtXxIaXirwn07M3+Zmg 5+s4ZN1Ni7t0Ch/ATJmsinQgInlfREBx/Iz20Y2NgutNRunw+Z+VCQDpZoqTce7VHJN8 uo1CsP3rQd1t38p/8HfbGPfwtrfCmWYVser3NzuduemA0+nrVkloFbHNbH+6/fHPoB96 U8U3Z6updrk4hTc6HC/kb7sa3igGR/dDhANfqMMCuGGYC8OGnVmrbR261Sa1MUaPzvZt IBwujm9oLiT/GvAEBdpRgQjebB9DUPPPKyblw6rBH7COO5lSzZI1Tyq2MA9nPUYfWwlp IcRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694141560; x=1694746360; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=R+nCrwralLYJWw3cK2cn/j0ATdvZUzxwirrlaBQWDDA=; b=hiJKtW3MxIhE75+ZE4+5ES5fQs4lp+/LCNttl0gUark0ZOwP+lpFeerriE7JZKJyMS TULIZe/HG21ZczNFTpbr6KqB037rXfvScOrd81DK6grYPgPWy++CFVIEi+PfZEOqpkUs GyYmhUAkft3l27kzkRKl97QAUh3wpIuazEIp7hW0cXP14ydUi61CVSRI5WI4tHYE/rjG OQFKy5WN9Ed8D0onibRnu+I9FHvNDkUIdm8RAYHMu7YIla+3cyRH/qKSFSkTV806xCPK EWwCDVM9gv5PMDA47BiGdHAWebTeANHiGdvgH+6a+ajsvEIHT/d2wpiomYCpa+K8h43m iRuQ== X-Gm-Message-State: AOJu0Yy5BmGMB9OKr4Co9toWR4v7hP6gSRfpg34J1dBEbrM81xsEF03x olBY3NxSUO99/ADf2zkeuYF/cg== X-Received: by 2002:a17:902:e751:b0:1c3:6f9e:6769 with SMTP id p17-20020a170902e75100b001c36f9e6769mr1413083plf.4.1694141560616; Thu, 07 Sep 2023 19:52:40 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:2d89:7669:ac2d:f09e]) by smtp.gmail.com with ESMTPSA id n9-20020a170902e54900b001c0ce518e98sm417286plf.224.2023.09.07.19.52.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 19:52:40 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org Cc: etienne.carriere@st.com, u-boot@lists.denx.de, AKASHI Takahiro , Etienne Carriere Subject: [PATCH v3 12/13] doc: cmd: add documentation for scmi Date: Fri, 8 Sep 2023 11:51:37 +0900 Message-Id: <20230908025138.44405-13-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230908025138.44405-1-takahiro.akashi@linaro.org> References: <20230908025138.44405-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 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 This is a help text for scmi command. Signed-off-by: AKASHI Takahiro Reviewed-by: Simon Glass Reviewed-by: Etienne Carriere --- v2 * add more descriptions about SCMI --- doc/usage/cmd/scmi.rst | 126 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 doc/usage/cmd/scmi.rst diff --git a/doc/usage/cmd/scmi.rst b/doc/usage/cmd/scmi.rst new file mode 100644 index 000000000000..aebcfe95101d --- /dev/null +++ b/doc/usage/cmd/scmi.rst @@ -0,0 +1,126 @@ +.. SPDX-License-Identifier: GPL-2.0+: + +scmi command +============ + +Synopsis +-------- + +:: + + scmi info + scmi perm_dev + scmi perm_proto + scmi reset + +Description +----------- + +Arm System Control and Management Interface (SCMI hereafter) is a set of +standardised interfaces to manage system resources, like clocks, power +domains, pin controls, reset and so on, in a system-wide manner. + +An entity which provides those services is called a SCMI firmware (or +SCMI server if you like) may be placed/implemented by EL3 software or +by a dedicated system control processor (SCP) or else. + +A user of SCMI interfaces, including U-Boot, is called a SCMI agent and +may issues commands, which are defined in each protocol for specific system +resources, to SCMI server via a communication channel, called a transport. +Those interfaces are independent from the server's implementation thanks to +a tranport layer. + +For more details, see the `SCMI specification`_. + +While most of system resources managed under SCMI protocols are implemented +and handled as standard U-Boot devices, for example clk_scmi, scmi command +provides additional management functionality against SCMI server. + +scmi info +~~~~~~~~~ + Show base information about SCMI server and supported protocols + +scmi perm_dev +~~~~~~~~~~~~~ + Allow or deny access permission to the device + +scmi perm_proto +~~~~~~~~~~~~~~~ + Allow or deny access to the protocol on the device + +scmi reset +~~~~~~~~~~ + Reset the already-configured permissions against the device + +Parameters are used as follows: + + + SCMI Agent ID, hex value + + + SCMI Device ID, hex value + + Please note that what a device means is not defined + in the specification. + + + SCMI Protocol ID, hex value + + It must not be 0x10 (base protocol) + + + Flags to control the action, hex value + + 0 to deny, 1 to allow. The other values are reserved and allowed + values may depend on the implemented version of SCMI server in + the future. See SCMI specification for more details. + +Example +------- + +Obtain basic information about SCMI server: + +:: + + => scmi info + SCMI device: scmi + protocol version: 0x20000 + # of agents: 3 + 0: platform + > 1: OSPM + 2: PSCI + # of protocols: 4 + Power domain management + Performance domain management + Clock management + Sensor management + vendor: Linaro + sub vendor: PMWG + impl version: 0x20b0000 + +Ask for access permission to device#0: + +:: + + => scmi perm_dev 1 0 1 + +Reset configurations with all access permission settings retained: + +:: + + => scmi reset 1 0 + +Configuration +------------- + +The scmi command is only available if CONFIG_CMD_SCMI=y. +Default n because this command is mainly for debug purpose. + +Return value +------------ + +The return value ($?) is set to 0 if the operation succeeded, +1 if the operation failed or -1 if the operation failed due to +a syntax error. + +.. _`SCMI specification`: https://developer.arm.com/documentation/den0056/e/?lang=en From patchwork Fri Sep 8 02:51:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 720796 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp548807wrp; Thu, 7 Sep 2023 19:54:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHw8uoVjlQ13W7fNepWPSU+yRu0A8ahJMx0+bq+hrDxIzIduaNXOEgxDfwiNuherO99A8AQ X-Received: by 2002:a05:6000:102:b0:317:57f0:fae with SMTP id o2-20020a056000010200b0031757f00faemr746745wrx.63.1694141689259; Thu, 07 Sep 2023 19:54:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694141689; cv=none; d=google.com; s=arc-20160816; b=iMrRAM24LuBZHFPQZx1OmXiwKnwr3XubVKkydzD8Pt8RyU+CCj9TOCDqGn/jomFzM0 BOWE9kAh1jL9AJ5zTRzX8CUXAu8Lt2h2jQG+Y8nuxe3+aaeU4F1QMlj9s8ibWi7tUvvG Y+HAzS6vgpU12UMKMPIWtkdUFtHsEvrLLfMzicJcBwHGfgas+VQlZULyCo+PCNRSBtR5 oDbkC4ExD51iiwjUtX4XIoqopRQiXog2BYzWCE19HSRTkgfhDNdwML1nUTD51YzvHE3p kTYy9pfTN4IVd/T+9dMiXNDrAX5sxFzQHtxiyQVqjwdHRa3f4ynSjeSvrZqMqbdX6N+u ieUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=84CqU0uEmfuQ0jWgwbyKzdUtEfOlVHcjpgoNiLdVSgc=; fh=K4dQhL74gef2glEqNOnE2YOBTqRi7qf0ycKBewrN6K8=; b=XR3+jQ6mQvg5DpYGd8mMV173SxK0Pjkfm4Ok7IPaw1k99oSQkyhvELucTQxVEOBfC8 FlmTHOT0wfkoQeW68ZqYKgAKBgC6qNl3FhF2Lv88qbv2sHuf4HLs/ATR4Prwf5AX4jA4 SpYifAlzUQZ07pzk5cn47kpH89y5wZo6gFI53ypj66qDl5xsOVzw56OpC3Ea2zZFXvp/ d/sG7PsdqCuikXs4Ht9RisTfvVWGCERAfqF1C3GC6n564AgtWBbILo2i7Ypx4waYXPBx /dggQLB9Fg8E2gyotdhunyFfSbjOi6+ZtWFRPgH6IoFMTeHn9RiE5ikZHrYM81RyD8TO ks2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wUJdpQMi; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id e5-20020a056000120500b00319784bc983si351771wrx.957.2023.09.07.19.54.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 19:54:49 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wUJdpQMi; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 654DE86A6A; Fri, 8 Sep 2023 04:52:47 +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="wUJdpQMi"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 04D4086A2F; Fri, 8 Sep 2023 04:52:47 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) (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 1BA14869B9 for ; Fri, 8 Sep 2023 04:52:44 +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-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-273b1ea30beso407531a91.1 for ; Thu, 07 Sep 2023 19:52:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694141562; x=1694746362; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=84CqU0uEmfuQ0jWgwbyKzdUtEfOlVHcjpgoNiLdVSgc=; b=wUJdpQMitVhnodRNq6SZ9fBhnwCtBgkATMMS6wZPHEwrYV9T5piAIHbj1QvSoPYpY8 erpIgQ/EkqgeUHGcvPiWeaMBxb1AHfvsmQfnkhblOmJzZqJV0/VtA2Hgr6w8zyG037xg ha07XCMsrem67fmzFhOT3F3YxCV1zhiRkgrGDjJu/wI9ER7Gfx+HDzdN7uBDdbeAD4q/ xCdmd9KC1ThZl6ApZr36TP1HgfNQFaXmMnP/MlN9Gq1cheNUT+2mjezwfgxvIfpwBkzH vzo9MFyG0S+F2UKJsd2xhaxs5zSwjZL7Tcakv0uPj0oUp/Yj3EF4O+5zkaUjKKxpWHCn scmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694141562; x=1694746362; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=84CqU0uEmfuQ0jWgwbyKzdUtEfOlVHcjpgoNiLdVSgc=; b=W395hqkpTOLmJP5yzrkBstaScvxmflI3bOkRPip6VULwslKiqOtVN+SIHwXBMStbtb jj8FDDaxIHuGMcgBA/DhNPay8L12ejc88bQTODFccKRY3ameVjPH8QFdzOK2WU6XYA4n kX0+dJ3kdU1OCkT0mjWbMuYP3qU4tCswGuUdyZWLByXcbfWDQDT8+eZDqo/bK7xD6Cuv 4MHJLwoC+6IXla5zieP9bMGY4XpuAG0tporPfIAiZbmiIhBXc91ey0bsxYgDZdT+3rLT UT9L4O2GW91p+Ujieg6M0RMYwqAHExBY9XWtEhnWmbBBMaSsakUA1Ngg+hRb4a+lbW+4 aMHg== X-Gm-Message-State: AOJu0YxVdqFBfWaUINMczVu24gLXGexcB63yUH1XHreAdXjO55ZONj4Z uqC6QAk/aqzda0mPCFMCvoX5OQ== X-Received: by 2002:a17:902:c94e:b0:1c3:4073:bf80 with SMTP id i14-20020a170902c94e00b001c34073bf80mr1573735pla.0.1694141562498; Thu, 07 Sep 2023 19:52:42 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:2d89:7669:ac2d:f09e]) by smtp.gmail.com with ESMTPSA id n9-20020a170902e54900b001c0ce518e98sm417286plf.224.2023.09.07.19.52.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 19:52:42 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org Cc: etienne.carriere@st.com, u-boot@lists.denx.de, AKASHI Takahiro , Etienne Carriere Subject: [PATCH v3 13/13] test: dm: add scmi command test Date: Fri, 8 Sep 2023 11:51:38 +0900 Message-Id: <20230908025138.44405-14-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230908025138.44405-1-takahiro.akashi@linaro.org> References: <20230908025138.44405-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 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 In this test, "scmi" command is tested against different sub-commands. Please note that scmi command is for debug purpose and is not intended in production system. Signed-off-by: AKASHI Takahiro Reviewed-by: Simon Glass Reviewed-by: Etienne Carriere --- v3 * change char to u8 in vendor/agent names v2 * use helper functions, removing direct uses of ops --- test/dm/scmi.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/test/dm/scmi.c b/test/dm/scmi.c index 0785948186f0..423b6ef70b29 100644 --- a/test/dm/scmi.c +++ b/test/dm/scmi.c @@ -104,8 +104,7 @@ static int dm_test_scmi_base(struct unit_test_state *uts) struct scmi_agent_priv *priv; u32 version, num_agents, num_protocols, impl_version; u32 attributes, agent_id; - char *vendor, *agent_name; - u8 *protocols; + u8 *vendor, *agent_name, *protocols; int ret; /* preparation */ @@ -134,9 +133,9 @@ static int dm_test_scmi_base(struct unit_test_state *uts) free(vendor); /* message attributes */ - ret = scmi_protocol_message_attrs(base, - SCMI_BASE_DISCOVER_SUB_VENDOR, - &attributes); + ret = scmi_base_protocol_message_attrs(base, + SCMI_BASE_DISCOVER_SUB_VENDOR, + &attributes); ut_assertok(ret); ut_assertok(attributes); @@ -207,6 +206,59 @@ static int dm_test_scmi_base(struct unit_test_state *uts) DM_TEST(dm_test_scmi_base, UT_TESTF_SCAN_FDT); +static int dm_test_scmi_cmd(struct unit_test_state *uts) +{ + struct udevice *agent_dev; + + /* preparation */ + ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi", + &agent_dev)); + ut_assertnonnull(agent_dev); + + /* scmi info */ + ut_assertok(run_command("scmi info", 0)); + + ut_assert_nextline("SCMI device: scmi"); + ut_assert_nextline(" protocol version: 0x20000"); + ut_assert_nextline(" # of agents: 2"); + ut_assert_nextline(" 0: platform"); + ut_assert_nextline(" > 1: OSPM"); + ut_assert_nextline(" # of protocols: 3"); + ut_assert_nextline(" Clock management"); + ut_assert_nextline(" Reset domain management"); + ut_assert_nextline(" Voltage domain management"); + ut_assert_nextline(" vendor: U-Boot"); + ut_assert_nextline(" sub vendor: Sandbox"); + ut_assert_nextline(" impl version: 0x1"); + + ut_assert_console_end(); + + /* scmi perm_dev */ + ut_assertok(run_command("scmi perm_dev 1 0 1", 0)); + ut_assert_console_end(); + + ut_assert(run_command("scmi perm_dev 1 0 0", 0)); + ut_assert_nextline("Denying access to device:0 failed (-13)"); + ut_assert_console_end(); + + /* scmi perm_proto */ + ut_assertok(run_command("scmi perm_proto 1 0 14 1", 0)); + ut_assert_console_end(); + + ut_assert(run_command("scmi perm_proto 1 0 14 0", 0)); + ut_assert_nextline("Denying access to protocol:0x14 on device:0 failed (-13)"); + ut_assert_console_end(); + + /* scmi reset */ + ut_assert(run_command("scmi reset 1 1", 0)); + ut_assert_nextline("Reset failed (-13)"); + ut_assert_console_end(); + + return 0; +} + +DM_TEST(dm_test_scmi_cmd, UT_TESTF_SCAN_FDT); + static int dm_test_scmi_clocks(struct unit_test_state *uts) { struct sandbox_scmi_agent *agent;