From patchwork Tue Sep 26 06:57: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: 726379 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp2779857wrm; Mon, 25 Sep 2023 23:58:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHjnyPKvUWteWONWy/dvxxdtP4jmsEQpn2B4HGb4sSzuYnGhiG9F+0T3qh7uv+buaJ5OaDc X-Received: by 2002:adf:e9cc:0:b0:320:5ad:2b9c with SMTP id l12-20020adfe9cc000000b0032005ad2b9cmr7486522wrn.2.1695711499471; Mon, 25 Sep 2023 23:58:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695711499; cv=none; d=google.com; s=arc-20160816; b=RrGm5AoWkrguvSL3zwTBVPSU+tzqo7psvdOsGrOmIYvld9FoA2Bbobx3iG2w90BJh8 QcctmT0FODbVQ+HQlfD3Fkg/Y/SBRnmaT9P/ngSlP1kg3UX7WimBIw96pmWa+IwapBp9 JkRmazXuv1J8PsR7OIxymGj38CWXhcUqvHUrDUynUUYbZhYfgRSLTUPBoFldGDCFIHl8 lZgVdFjdiwS+euKBgWj6HHJiGcbCWB21WC3H84d2SdJXsmkdDxwx+AGWKX7eQiQhz69i f0Bo9ea33ajkBoNvm38RnI7ToRdLFY3PQo34o7/4SjvJD9Rda9b2+zp0dh7hyy0wvIDq ggcw== 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=n6VDMasliyXa+AMSCtxy5ac1148B+v+ipn/6wlLQKy0=; fh=+s9SE2w9oguEKAMcR35TXtqntCOeVFhiK9u/Kju91lo=; b=s7vlBLmwCurXO32s7hazGbecWqPCatAAcJG2etFPqZcBz2eVhBPWjbEZ6MaRQZHhBr lR8GGIBmkRYU+ITObTvCELrOs3sekesgONce3n3BUz7WdLAGx/6iYenBjBa3ZUxA5qCS WRnjCVCPJVt7A+cA1mQThPftsWWcxGzGoA39wYTESaBHHtZARjn4FwseSkUmme+CrAOp grHazN1s+osuoRxBUPLR8MOA5z5/ZYOY8xvlw24dZr+G9DLfaLoVzfV81xQGlN+piaof WRT6HkoErqttZ54un8F6gUP66loqpY/73rOkv0wOIydzMTrpzm7GkZWjHCjczp1mEL9G yPcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZS4rY1Dz; 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 j9-20020adfea49000000b0032331540da5si898239wrn.593.2023.09.25.23.58.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:58:19 -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=ZS4rY1Dz; 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 81A9986C11; Tue, 26 Sep 2023 08:58:17 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="ZS4rY1Dz"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 63A0686C0D; Tue, 26 Sep 2023 08:58:16 +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-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) (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 8370886C11 for ; Tue, 26 Sep 2023 08:58:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-690d935dbc2so1879788b3a.1 for ; Mon, 25 Sep 2023 23:58:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695711492; x=1696316292; 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=n6VDMasliyXa+AMSCtxy5ac1148B+v+ipn/6wlLQKy0=; b=ZS4rY1DzyutEYP9pmripDd4+pKjKIepeRU/Bnd8lIfftwdc5oAwGVLmmKPGG6WnCFd H6TFVpRXRcBzHojcFN9zNUyMEHl8hf1thb6k5JJSZBoN59FMzqo4nWkA/04d+lv62hTO /X8r2CG+h646XdTf2gjwz5J2ZuNMoh0IdQyNNvLwpeaWtXcsB6nif4thZ/PYj9xrGCE+ PZlOS+7lT7/22L0BSbRtSs8RtNTHaccoOz2ccZu3TN576HAUePrm0OkAoAghUI1cNDA1 gID/s3TQ45ho0dHAlFZRKLsg1TxDNAgDJ6ZlEEPJwRixzt9WzRC3tQul+8OGDC19wSa/ gYQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695711492; x=1696316292; 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=n6VDMasliyXa+AMSCtxy5ac1148B+v+ipn/6wlLQKy0=; b=m9UudwA1OyJ8Ao8fEoFStxoZ+g+YsZ2egC2iweBJkmAClfx0amWv01xnflA84WEGpR 37vKOtZVPJ0b8NVyi/vihJTzWdWTraME5tuVmIUwJ1NWLJr+EetVMAEQ911loF3abCqN KrWZO5LVrLnsFxClWGpdV6t3lGtobR110Va2kWD7Eac1FvFva1BOesLN1B8dzqmCjvoh FgwTSHUtIuUyHdRNA4wZDH0KqENExlqm/32YQJ0bXyecRLjI+vYDTVcJ04wkzOERAV6U /a7c9RtMpV3vhkSBWnbInoHSGrqWEzkUdfcDIJihrS4OSU9VIgUOJJm1ZCpWgSFEWqzX /7Fg== X-Gm-Message-State: AOJu0YyyaUKo6CGFzF8j1B3qkDoIeaHONbxlv8ANGVL4/fvMAeFI5K4o plFj/d3TW/go14PSFlEJ6OwzgSEhm49+tYNnbnZfAQ== X-Received: by 2002:a05:6a00:1d20:b0:68f:c309:9736 with SMTP id a32-20020a056a001d2000b0068fc3099736mr9138378pfx.3.1695711491709; Mon, 25 Sep 2023 23:58:11 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:6585:aea6:5002:a825]) by smtp.gmail.com with ESMTPSA id s2-20020a639242000000b0057825bd3448sm8758874pgn.51.2023.09.25.23.58.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:58:11 -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 v5 01/16] scmi: refactor the code to hide a channel from devices Date: Tue, 26 Sep 2023 15:57:35 +0900 Message-Id: <20230926065750.734440-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230926065750.734440-1-takahiro.akashi@linaro.org> References: <20230926065750.734440-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 Reviewed-by: Etienne Carriere --- v5 * correct the size for per_child_auto v4 * revive scmi_bind_protocols which was accidentally removed * remove .per_child_auto from the driver declaration as it is not needed 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 | 105 ++++++++++++++++------ drivers/power/regulator/scmi_regulator.c | 26 ++---- drivers/reset/reset-scmi.c | 19 +--- include/scmi_agent.h | 15 ++-- 5 files changed, 104 insertions(+), 88 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..ec58ccd2bc5d 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 @@ -110,18 +111,23 @@ static int scmi_bind_protocols(struct udevice *dev) return ret; } -static struct udevice *find_scmi_transport_device(struct udevice *dev) +static struct udevice *find_scmi_protocol_device(struct udevice *dev) { - struct udevice *parent = dev; + struct udevice *parent = NULL, *protocol; - do { - parent = dev_get_parent(parent); - } while (parent && device_get_uclass_id(parent) != UCLASS_SCMI_AGENT); + for (protocol = dev; protocol; protocol = parent) { + parent = dev_get_parent(protocol); + if (!parent || + device_get_uclass_id(parent) == UCLASS_SCMI_AGENT) + break; + } - 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 +135,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..9c72c35d039e 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) 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 Tue Sep 26 06:57: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: 726380 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp2779903wrm; Mon, 25 Sep 2023 23:58:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGaNXCg0kkxn7CECvagUvYQAUTRZ04Prx+JEB9Mx3Dr54Cgutu4TTwIsOZPxt3DwgjDBOsH X-Received: by 2002:a1c:7710:0:b0:3fe:1f93:8cf4 with SMTP id t16-20020a1c7710000000b003fe1f938cf4mr8119573wmi.8.1695711509385; Mon, 25 Sep 2023 23:58:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695711509; cv=none; d=google.com; s=arc-20160816; b=g0rVfN09cwAiIB2F8Az0oZ8uS/6aZAgW+74xYkSNrsTD2VXo3wIMZpUbSHSqrRqu91 +nSE3B5UmrEY0hV0cwD8Vee//Mf+CbynD/otDgM3wA0d2FKFyCas/rkFei3hb3ry1Eif k4XRmvR5AasCXc9KA8lypXs4Z60ZT+vYQFWAxoDYC0A+75hhDYwCahkG4cEEhXRLfGCB f/nqO3IOtISR9J7pLiWkqzZGsV6K4I1gQ9OBFLLHBRPTgj1hsBemH9ecvrg5qrISzPrS t5fKPqiJbUlJKgQIj7aRm6q/b7ZUzqy/CLFTRwiUgLM7Y0Ckhb6M3q49fbJvRDlCx7Oa H/+w== 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=5WXeaDc5fixDobj9hHcc7iI7eRYEh2B18lEtPO1VmOU=; fh=+s9SE2w9oguEKAMcR35TXtqntCOeVFhiK9u/Kju91lo=; b=a0UsAXqmcBSGr/cYxpZ3UrziYbzDsrPt3zU02YAJnrZBoTlZHl/MpYUc/AVj+siCl/ sF3pe5V9/Oae+ZyAElSY13nZk5lvPwR1VbRyNnIGeFYZvrg9S9GKb87XuYXFrpodWOZD XcjfnyRmRmDwck7J4UCRylkmlRIsstYqOAezwvbogRA7Px5KOtxp7j85qc5XIKhrQ2aa Jd8MkEpTT0vSt7UoElgeiww5oqcITQtAmbqt8pq5ZJ5sMo1wBzlD3ohvf/vF9JzMIPnP hmKxemn7nnJW6ApaU3YI4kdgwbg1YpY133lq4Fg6w7J1zSsuNNcpaA2N8T50eG3bZIwZ aTXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Kbiyq2+b; 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 iv13-20020a05600c548d00b00402fe7642f4si6496093wmb.223.2023.09.25.23.58.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:58:29 -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=Kbiyq2+b; 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 E31B686C32; Tue, 26 Sep 2023 08:58:18 +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="Kbiyq2+b"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2790286C32; Tue, 26 Sep 2023 08:58:18 +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-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) (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 D257B86B95 for ; Tue, 26 Sep 2023 08:58:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-690d935dbc2so1879797b3a.1 for ; Mon, 25 Sep 2023 23:58:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695711494; x=1696316294; 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=5WXeaDc5fixDobj9hHcc7iI7eRYEh2B18lEtPO1VmOU=; b=Kbiyq2+by/O7XdDhen/Gs1UdMQNFOKLTIiKFSa6oBSmXIG0yTVThYAbLbcpxz30ZH5 LaEMaAZe8huN8xTi2rIVUvLv1e19ULroMWQ9XylvJSkWQFNh97jr0Gp0Xop4xmyaK5o2 YWHcN3YHrfg9HjlxyKU8vuo6x6HjczJu8G/9L82ZMEiNPxyTpnJdOzNz7oTmG6bCL3GV wUSYuHt+Pjx+U4Poq5xloA2QOe/OevV7lCK/3a3aKFsLY/YsxdB/SdnJucNFYFP6McEg N3SxEqGjlxnZU53X9wrcQZ13s/nfhME15CoHgl9RKaqC0o3g3FNBe0rvm+Rt1BBEThd2 6Rng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695711494; x=1696316294; 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=5WXeaDc5fixDobj9hHcc7iI7eRYEh2B18lEtPO1VmOU=; b=KwEmvLUbVoq/S5Ldci6nX7CIQS7/MceqXYy3ltZOMuv7Z5d5e0LXeaT6jgS6Vab0pv GPZN4PtVX86VOZCB6CocPWCQaVOBYty2vmmup38s49QoX+gIfhxC1ZrSFpMztKZewU6l IlrchSPBcQmWd74XEgD5xxbW5yWmI5gKOffbVp44yFwZ45LJsZtA8rwEpEavgq+gVfmv SB0jlZWT9RUk4H3I65cODqStZ9O0DCNjaKfa3JG8wsP28yNxa9Dfi94gEsTrI9aas8B0 Qa247bq/72Vv7zScrKIeBAVJ83vhv38/j6KW2WSQQEJzNmtuJ45spvRTA7+ATEIDDlFn RRbA== X-Gm-Message-State: AOJu0YzcLxK6kJ6AfeHJc4COqwr4RJJscVqQY0uxbXOjBebeEAxvtmVk VrCvYTeeFr7peAyLyj7UULxKwg== X-Received: by 2002:a05:6a21:6d86:b0:15d:6fd3:8e74 with SMTP id wl6-20020a056a216d8600b0015d6fd38e74mr11942934pzb.3.1695711494049; Mon, 25 Sep 2023 23:58:14 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:6585:aea6:5002:a825]) by smtp.gmail.com with ESMTPSA id s2-20020a639242000000b0057825bd3448sm8758874pgn.51.2023.09.25.23.58.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:58:13 -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 v5 02/16] firmware: scmi: use a protocol's own channel if assigned Date: Tue, 26 Sep 2023 15:57:36 +0900 Message-Id: <20230926065750.734440-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230926065750.734440-1-takahiro.akashi@linaro.org> References: <20230926065750.734440-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 specification allows any protocol to have its own channel for the transport. While the current SCMI driver may assign its channel from a device tree, the core function, devm_scmi_process_msg(), doesn't use a protocol's channel, but always use an agent's channel. With this commit, devm_scmi_process_msg() tries to find and use a protocol's channel. If it doesn't exist, use an agent's. Signed-off-by: AKASHI Takahiro Reviewed-by: Etienne Carriere --- v5 * new commit (fixing a potential bug) --- drivers/firmware/scmi/mailbox_agent.c | 5 +++-- drivers/firmware/scmi/optee_agent.c | 5 +++-- drivers/firmware/scmi/scmi_agent-uclass.c | 7 ++++--- drivers/firmware/scmi/smccc_agent.c | 5 +++-- include/scmi_agent-uclass.h | 8 +++++--- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/drivers/firmware/scmi/mailbox_agent.c b/drivers/firmware/scmi/mailbox_agent.c index 8277c1860606..7ad3e8da9f08 100644 --- a/drivers/firmware/scmi/mailbox_agent.c +++ b/drivers/firmware/scmi/mailbox_agent.c @@ -94,13 +94,14 @@ static int setup_channel(struct udevice *dev, struct scmi_mbox_channel *chan) } static int scmi_mbox_get_channel(struct udevice *dev, + struct udevice *protocol, struct scmi_channel **channel) { struct scmi_mbox_channel *base_chan = dev_get_plat(dev); struct scmi_mbox_channel *chan; int ret; - if (!dev_read_prop(dev, "shmem", NULL)) { + if (!dev_read_prop(protocol, "shmem", NULL)) { /* Uses agent base channel */ *channel = container_of(base_chan, struct scmi_channel, ref); @@ -112,7 +113,7 @@ static int scmi_mbox_get_channel(struct udevice *dev, return -ENOMEM; /* Setup a dedicated channel for the protocol */ - ret = setup_channel(dev, chan); + ret = setup_channel(protocol, chan); if (ret) { free(chan); return ret; diff --git a/drivers/firmware/scmi/optee_agent.c b/drivers/firmware/scmi/optee_agent.c index db927fb21405..e3e462774045 100644 --- a/drivers/firmware/scmi/optee_agent.c +++ b/drivers/firmware/scmi/optee_agent.c @@ -324,6 +324,7 @@ static int setup_channel(struct udevice *dev, struct scmi_optee_channel *chan) } static int scmi_optee_get_channel(struct udevice *dev, + struct udevice *protocol, struct scmi_channel **channel) { struct scmi_optee_channel *base_chan = dev_get_plat(dev); @@ -331,7 +332,7 @@ static int scmi_optee_get_channel(struct udevice *dev, u32 channel_id; int ret; - if (dev_read_u32(dev, "linaro,optee-channel-id", &channel_id)) { + if (dev_read_u32(protocol, "linaro,optee-channel-id", &channel_id)) { /* Uses agent base channel */ *channel = container_of(base_chan, struct scmi_channel, ref); @@ -343,7 +344,7 @@ static int scmi_optee_get_channel(struct udevice *dev, if (!chan) return -ENOMEM; - ret = setup_channel(dev, chan); + ret = setup_channel(protocol, chan); if (ret) { free(chan); return ret; diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c b/drivers/firmware/scmi/scmi_agent-uclass.c index ec58ccd2bc5d..a28692f39f4d 100644 --- a/drivers/firmware/scmi/scmi_agent-uclass.c +++ b/drivers/firmware/scmi/scmi_agent-uclass.c @@ -144,13 +144,14 @@ static const struct scmi_agent_ops *transport_dev_ops(struct udevice *dev) * 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) +static int scmi_of_get_channel(struct udevice *dev, struct udevice *protocol, + struct scmi_channel **channel) { const struct scmi_agent_ops *ops; ops = transport_dev_ops(dev); if (ops->of_get_channel) - return ops->of_get_channel(dev, channel); + return ops->of_get_channel(dev, protocol, channel); else return -EPROTONOSUPPORT; } @@ -166,7 +167,7 @@ int devm_scmi_of_get_channel(struct udevice *dev) return -ENODEV; priv = dev_get_parent_priv(protocol); - ret = scmi_of_get_channel(protocol->parent, &priv->channel); + ret = scmi_of_get_channel(protocol->parent, protocol, &priv->channel); if (ret == -EPROTONOSUPPORT) { /* Drivers without a get_channel operator don't need a channel ref */ priv->channel = NULL; diff --git a/drivers/firmware/scmi/smccc_agent.c b/drivers/firmware/scmi/smccc_agent.c index 6a52cd75d67b..972c6addde21 100644 --- a/drivers/firmware/scmi/smccc_agent.c +++ b/drivers/firmware/scmi/smccc_agent.c @@ -81,6 +81,7 @@ static int setup_channel(struct udevice *dev, struct scmi_smccc_channel *chan) } static int scmi_smccc_get_channel(struct udevice *dev, + struct udevice *protocol, struct scmi_channel **channel) { struct scmi_smccc_channel *base_chan = dev_get_plat(dev); @@ -88,7 +89,7 @@ static int scmi_smccc_get_channel(struct udevice *dev, u32 func_id; int ret; - if (dev_read_u32(dev, "arm,smc-id", &func_id)) { + if (dev_read_u32(protocol, "arm,smc-id", &func_id)) { /* Uses agent base channel */ *channel = container_of(base_chan, struct scmi_channel, ref); @@ -100,7 +101,7 @@ static int scmi_smccc_get_channel(struct udevice *dev, if (!chan) return -ENOMEM; - ret = setup_channel(dev, chan); + ret = setup_channel(protocol, chan); if (ret) { free(chan); return ret; diff --git a/include/scmi_agent-uclass.h b/include/scmi_agent-uclass.h index b1c93532c0ea..eee46c880a56 100644 --- a/include/scmi_agent-uclass.h +++ b/include/scmi_agent-uclass.h @@ -16,16 +16,18 @@ struct scmi_agent_ops { /* * of_get_channel - Get SCMI channel from SCMI agent device tree node * - * @dev: SCMI protocol device using the transport + * @dev: SCMI agent device using the transport + * @protocol: SCMI protocol device using the transport * @channel: Output reference to SCMI channel upon success * Return 0 upon success and a negative errno on failure */ - int (*of_get_channel)(struct udevice *dev, struct scmi_channel **channel); + int (*of_get_channel)(struct udevice *dev, struct udevice *protocol, + struct scmi_channel **channel); /* * process_msg - Request transport to get the SCMI message processed * - * @dev: SCMI protocol device using the transport + * @dev: SCMI agent device using the transport * @msg: SCMI message to be transmitted */ int (*process_msg)(struct udevice *dev, struct scmi_channel *channel, From patchwork Tue Sep 26 06:57: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: 726381 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp2779946wrm; Mon, 25 Sep 2023 23:58:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH0Fc4v31P17qTrzr/63MR62L0mMvogW9q23ufLXkit9Vp6Y5yBKNfI0fPK9/3cdaOCI8g+ X-Received: by 2002:a5d:67c7:0:b0:314:1230:29b0 with SMTP id n7-20020a5d67c7000000b00314123029b0mr7108524wrw.52.1695711519826; Mon, 25 Sep 2023 23:58:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695711519; cv=none; d=google.com; s=arc-20160816; b=vcEBoAcA1Vh88P1LR8ZSg5Xz0Mw4d7/Gw5IXWLHl7TVGleKED/rlv5KVa6S8/kWLUv du2iRnGoZiHBC77NDglzIble71p3SHs9mk2No5tiZMMtNXPK1N5dKhLLth+owyU/r1Zg Jj6MN8EUOO7yD3wBbibqzeoL6vaFRSqqUOCG0aEBIxjQgxECll6O8tkwk/9y0jeQ/igp 7fK0vEjebizonrgfKvrVLyFNDkNubt4C09LV+urnj0QmKeXgggikpHJk/tYYeZNaKx3/ OWnezQ1cGs+pnsmmTLy/r92bHJJDQ0yF1ZkiGYH4yz8GUZ+vFHeJOuPyyNv2P0/kxKVL v1vg== 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=9w6NtVmxhTP8bJl1pLz+4m/B3yXvXCTMKNDuB9SU9KQ=; fh=+s9SE2w9oguEKAMcR35TXtqntCOeVFhiK9u/Kju91lo=; b=ntJ25dwvh07UDNmimrUV2gDI1N0rvUmHg1d/tBxyNYvpuNz/9LPn/j9QqWH7f6prhg PiuYxtHc/j6eG8VLpegbSGGzG4zWjAeXPrdUJj1XtdS9Nw0hxQjs6ruKjMxcbkb8Or1M 4FXaQU9Ztv1yy4f7B6wLaBwxi5X528TuOMFgnRT5vb9yK0hsisL/+Egnt56YerHb7Ww3 6a9B++1Wg/ocmR8aKyOdsmFZiYlT6qzAJpqaSWnB+ij8UZaj9QUBniY+ZXDqTacLJzj7 WE4Q9lN8krhxH9N8nTVJhASdnO9roIjFATygp6JfNngQS+el18oF+p6FAn9iipXdDqH1 iZFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=t8iWSi3V; 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 m5-20020a5d56c5000000b0031ad4d5132asi5597965wrw.155.2023.09.25.23.58.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:58:39 -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=t8iWSi3V; 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 4C4E286C2D; Tue, 26 Sep 2023 08:58:21 +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="t8iWSi3V"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5636086C67; Tue, 26 Sep 2023 08:58:20 +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-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) (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 1A70986C2D for ; Tue, 26 Sep 2023 08:58:18 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-690fe1d9ba1so1882009b3a.0 for ; Mon, 25 Sep 2023 23:58:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695711496; x=1696316296; 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=9w6NtVmxhTP8bJl1pLz+4m/B3yXvXCTMKNDuB9SU9KQ=; b=t8iWSi3Vb0N1G/im1ig3tBt8jqQewfm0cvyqbphoIjoXEPcXH7zcBLIsrYZt0Ku2UV +wovZuRVM7s+lvbxJ0lKm6B/KR5hgsxafF41kiWu+ZuBn/QyjB0gjux/XIKDwDxi4qvg aLIJPaiJQtL114lvqj+7hIPKMi67GE/7s0XcZ29kMdxZ+hSn6hURtroZk9Ubsz6WkfEh u4MItp3ClrwWjSfQM0HXCV6DLZjtwjLz3ByrUHjjXnCoDdTJV4+1LYvq0Ymp2/HsaMbe 6ZEVC64g5n14VQLih2NVxYvTroU2dSVtmjF1nwdF0Boe5oIEO32P/IrhBwPMWlWiBz5t la2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695711496; x=1696316296; 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=9w6NtVmxhTP8bJl1pLz+4m/B3yXvXCTMKNDuB9SU9KQ=; b=WBrci5gQ316Um+o4O9Y+aZZzLd4o4YM1n+b2OWrjWWoyvyH0Eqwv6FvEkG91bE77sT Nq8cNpVomrCI5GDlpx6iPP0oPUE5tfm90DdjvYknGhNpCF82TO5qqBRKcindTxj+pyXH i3Wma1ndXXgIzmnESlW8KGo+ixt/kGjEEgutyiiWoJUVZ1q1COg6ytI7nRtIcVS02S+e b4mXa2ufpUGBSAQoZOE6+ljg//j44pMx5i+sgEy5He8HEsQmAqFEVU5hTSO+/yfM7sPv d32RudJNgiyDgyKoEkWG+mcKfGMheYGfiuUAW/NTR9lvPG1EU363AGLsdJzRcoN06Ui6 7Z9w== X-Gm-Message-State: AOJu0YxsqkltnmxTcgFJPsnT7TPxYnYpMkZ6jE4y1l9PYS9RKA5Q44lZ Tswg3swL3EDeR9QWUHz2anbCFA== X-Received: by 2002:a05:6a00:d66:b0:68e:3eff:e93a with SMTP id n38-20020a056a000d6600b0068e3effe93amr9155829pfv.2.1695711496344; Mon, 25 Sep 2023 23:58:16 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:6585:aea6:5002:a825]) by smtp.gmail.com with ESMTPSA id s2-20020a639242000000b0057825bd3448sm8758874pgn.51.2023.09.25.23.58.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:58:15 -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 v5 03/16] firmware: scmi: support dummy channels for sandbox agent Date: Tue, 26 Sep 2023 15:57:37 +0900 Message-Id: <20230926065750.734440-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230926065750.734440-1-takahiro.akashi@linaro.org> References: <20230926065750.734440-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 sandbox scmi agent, channels are not used at all. But in this patch, dummy channels are supported in order to test protocol-specific channels. Signed-off-by: AKASHI Takahiro Reviewed-by: Simon Glass Reviewed-by: Etienne Carriere --- v5 * new commit --- arch/sandbox/include/asm/scmi_test.h | 13 ++++ drivers/firmware/scmi/sandbox-scmi_agent.c | 90 ++++++++++++++++++++++ 2 files changed, 103 insertions(+) diff --git a/arch/sandbox/include/asm/scmi_test.h b/arch/sandbox/include/asm/scmi_test.h index c72ec1e1cb25..75cb462a5584 100644 --- a/arch/sandbox/include/asm/scmi_test.h +++ b/arch/sandbox/include/asm/scmi_test.h @@ -88,6 +88,14 @@ struct sandbox_scmi_devices { }; #ifdef CONFIG_SCMI_FIRMWARE +/** + * sandbox_scmi_channel_id - Get the channel id + * @dev: Reference to the SCMI protocol device + * + * Return: Channel id + */ +unsigned int sandbox_scmi_channel_id(struct udevice *dev); + /** * sandbox_scmi_service_ctx - Get the simulated SCMI services context * @return: Reference to backend simulated resources state @@ -101,6 +109,11 @@ struct sandbox_scmi_service *sandbox_scmi_service_ctx(void); */ struct sandbox_scmi_devices *sandbox_scmi_devices_ctx(struct udevice *dev); #else +inline unsigned int sandbox_scmi_channel_id(struct udevice *dev); +{ + return 0; +} + static inline struct sandbox_scmi_service *sandbox_scmi_service_ctx(void) { return NULL; diff --git a/drivers/firmware/scmi/sandbox-scmi_agent.c b/drivers/firmware/scmi/sandbox-scmi_agent.c index 031882998dfa..394df043918f 100644 --- a/drivers/firmware/scmi/sandbox-scmi_agent.c +++ b/drivers/firmware/scmi/sandbox-scmi_agent.c @@ -33,6 +33,26 @@ * various uclass devices, as clocks and reset controllers. */ +/** + * struct sandbox_channel - Description of sandbox transport + * @channel_id: Channel identifier + * + * Dummy channel. This will be used to test if a protocol-specific + * channel is properly used. + * Id 0 means a channel for the sandbox agent. + */ +struct sandbox_channel { + unsigned int channel_id; +}; + +/** + * struct scmi_channel - Channel instance referenced in SCMI drivers + * @ref: Reference to local channel instance + **/ +struct scmi_channel { + struct sandbox_channel ref; +}; + static struct sandbox_scmi_clk scmi_clk[] = { { .rate = 333 }, { .rate = 200 }, @@ -470,6 +490,73 @@ static int sandbox_scmi_voltd_level_get(struct udevice *dev, return 0; } +/** + * sandbox_scmi_of_get_channel - assigne a channel + * @dev: SCMI agent device + * @protocol: SCMI protocol device + * @channel: Pointer to channel info + * + * Assign a channel for the protocol, @protocol, in @channel, + * based on a device tree's property. + * + * Return: 0 on success, error code on failure + */ +static int sandbox_scmi_of_get_channel(struct udevice *dev, + struct udevice *protocol, + struct scmi_channel **channel) +{ + struct sandbox_channel *agent_chan = dev_get_plat(dev); + struct sandbox_channel *chan; + u32 channel_id; + + if (dev_read_u32(protocol, "linaro,sandbox-channel-id", &channel_id)) { + /* Uses agent channel */ + *channel = container_of(agent_chan, struct scmi_channel, ref); + + return 0; + } + + /* Setup a dedicated channel */ + chan = calloc(1, sizeof(*chan)); + if (!chan) + return -ENOMEM; + + chan->channel_id = channel_id; + + *channel = container_of(chan, struct scmi_channel, ref); + + return 0; +} + +/** + * sandbox_scmi_of_to_plat - assigne a channel to agent + * @dev: SCMI agent device + * + * Assign a channel for the agent, @protocol. + * + * Return: always 0 + */ +static int sandbox_scmi_of_to_plat(struct udevice *dev) +{ + struct sandbox_channel *chan = dev_get_plat(dev); + + /* The channel for agent is always 0 */ + chan->channel_id = 0; + + return 0; +} + +unsigned int sandbox_scmi_channel_id(struct udevice *dev) +{ + struct scmi_agent_proto_priv *priv; + struct sandbox_channel *chan; + + priv = dev_get_parent_priv(dev); + chan = (struct sandbox_channel *)&priv->channel->ref; + + return chan->channel_id; +} + static int sandbox_scmi_test_process_msg(struct udevice *dev, struct scmi_channel *channel, struct scmi_msg *msg) @@ -584,6 +671,7 @@ static const struct udevice_id sandbox_scmi_test_ids[] = { }; struct scmi_agent_ops sandbox_scmi_test_ops = { + .of_get_channel = sandbox_scmi_of_get_channel, .process_msg = sandbox_scmi_test_process_msg, }; @@ -592,6 +680,8 @@ U_BOOT_DRIVER(sandbox_scmi_agent) = { .id = UCLASS_SCMI_AGENT, .of_match = sandbox_scmi_test_ids, .priv_auto = sizeof(struct sandbox_scmi_agent), + .plat_auto = sizeof(struct sandbox_channel), + .of_to_plat = sandbox_scmi_of_to_plat, .probe = sandbox_scmi_test_probe, .remove = sandbox_scmi_test_remove, .ops = &sandbox_scmi_test_ops, From patchwork Tue Sep 26 06:57: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: 726382 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp2780001wrm; Mon, 25 Sep 2023 23:58:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGYcSj1tyyw8GYTRjJV6b8cs0H6MCzhxs+4VVJ9HurjHwtU1FRXDl+ZWnUBdXpT3rVdFFP2 X-Received: by 2002:a5d:4285:0:b0:31f:f753:9938 with SMTP id k5-20020a5d4285000000b0031ff7539938mr7300899wrq.58.1695711531409; Mon, 25 Sep 2023 23:58:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695711531; cv=none; d=google.com; s=arc-20160816; b=AskrccCji1dHhc8udIwbyLi+rmx880cMBBlqwyfByxkpYYvYraSCXlkHdGbui5kT6t TJiexyfYDjynoFNzhuyWIiMGKLt3lvb22k38CZOggdTcaj6HhoDnApuzephaCbA3hMOH Zch0zvRwFQ1i52blSSVyqoYnqf2fLaOGGfd0kPwBhtUa+ihmIbUPaYvfAPD1S+lMZz2V hA0n8E/5sycn+zIeophozlSCSVqB/dYq0VEYd5VBaxRtLjr5JtK0TSuWgUuwr1EylRvi DZ81YJJmBkcfR+1yhnYMzB7AjxolODslmYBXg0sO0Tba5HquUStKkz7xNoCNqlOxQev8 1kQg== 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=ik3nT2QALNs6ZxffYnItFAFu0LxTa/+AMnaipd9inek=; fh=+s9SE2w9oguEKAMcR35TXtqntCOeVFhiK9u/Kju91lo=; b=FTdsvZTfBhBBIARfRJwdtfX5BDUbsV6FKY8z8Gb+MRrj5Pt86QsNM+g0e6rvwMGn3k 0vrOuQgly0KyK4LOYUF+a0AWnA9bVTbd8FklKjQo1oRf/JK3X1ncUiIwRy3NpzY7oBlM qjakMZlgvXX6ABeryA6HbcdFH0QiOTSq1uJS3m/Zi+rpQe/eLimxAyzFZJapOoTsT6Fy MSOM/4M25M0ixhk3JFph9MA3D6qjjgVkKvQSYdXULPDua34sXUzLfKQWOdDIgawjnO7Q AXKaj6gdh7M7/8oaeJKgaGtj2ttH8L3XN/Z6mzSQXTuiDeaDatHrnjLs8VvwofGIs3ix RIHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="tfze/bZ8"; 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 n14-20020adfe34e000000b00323338b4895si725714wrj.669.2023.09.25.23.58.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:58:51 -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="tfze/bZ8"; 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 A851B86C5D; Tue, 26 Sep 2023 08:58:23 +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="tfze/bZ8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6241F86CC2; Tue, 26 Sep 2023 08:58:22 +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-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) (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 4622186C5D for ; Tue, 26 Sep 2023 08:58: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-oi1-x234.google.com with SMTP id 5614622812f47-3ae08c64f68so918040b6e.1 for ; Mon, 25 Sep 2023 23:58:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695711499; x=1696316299; 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=ik3nT2QALNs6ZxffYnItFAFu0LxTa/+AMnaipd9inek=; b=tfze/bZ8OWUfLLyrBZYxCtKVpKL7nAbjMEs/asZDTgweTQolgyL++1RbBm8JW1qdjY NUWJTs6NX4CCP7bUxArC1tG2tVAW+Xnu2eT8bvdYVy6tNdSlh7PIJaqzNRhrURmxaatI rZBEDTMvAovejjD2PR+JckCDW7kCAfMZhafI//xQmqRPuZqwsrFtMRTmnROhm6mrpf4+ 9Gdg1tWmPNpLpv6eKhpXc9mq44tTIzBWFqzlzOwhIg/oKcYyGMmX+flhitRJ21iO3vrZ U/XPg6C76ERO5IMRiw7zIHTqPfDnqHjcBOYj4tv0GdbhhskBEGs03R9icZH413AMt6ml hqbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695711499; x=1696316299; 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=ik3nT2QALNs6ZxffYnItFAFu0LxTa/+AMnaipd9inek=; b=AbkrizcW8k+9ynH2IzIiWUioX3E0ZuGhaRYZwxyPEdrGrNx9WMDjQHxRYuPZgrSDwS 1Ays2i7cMwknaDPZNPnWyqN4ciMleVaRLY9kGD5QvvL0IJBqqKABMPjR4If8dDS5kz/h jS+TjC9lGe0OtQ9XC1VBGi880WrfYi2xd8Qbku7XB60BZSOYBM3soCLgOy6SfTTDwgln hufaZ2qL4Kce4dJE1/NcwhIA3he4lxlU37C2HzwlKz9zJKv3R0wmxdBKRx3zFFu0vq0G gzYoKGbU8zud/EydzTntFI6n5sPMt7dlhsGgHIABvmA9E1qi57oYSVKodtqo6bUx8G22 14Ig== X-Gm-Message-State: AOJu0YwwB854PfeLl24lRBy7m6YWuD9uHOLae4CJ2OlVWVS3TrQpfN3k jxmp+ychzdLwei47vI+iwvCFRQ== X-Received: by 2002:a05:6808:6410:b0:3ad:ae0d:f845 with SMTP id fg16-20020a056808641000b003adae0df845mr9826905oib.5.1695711498687; Mon, 25 Sep 2023 23:58:18 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:6585:aea6:5002:a825]) by smtp.gmail.com with ESMTPSA id s2-20020a639242000000b0057825bd3448sm8758874pgn.51.2023.09.25.23.58.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:58: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 v5 04/16] test: dm: add protocol-specific channel test Date: Tue, 26 Sep 2023 15:57:38 +0900 Message-Id: <20230926065750.734440-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230926065750.734440-1-takahiro.akashi@linaro.org> References: <20230926065750.734440-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 Any SCMI protocol may have its own channel. Test this feature on sandbox as the necessary framework was added in a prior commit. Signed-off-by: AKASHI Takahiro Reviewed-by: Simon Glass Reviewed-by: Etienne Carriere --- v5 * new commit --- arch/sandbox/dts/test.dts | 1 + test/dm/scmi.c | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index f351d5cb84b0..5e2bf8623dff 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -700,6 +700,7 @@ clk_scmi: protocol@14 { reg = <0x14>; #clock-cells = <1>; + linaro,sandbox-channel-id = <0x14>; }; reset_scmi: protocol@16 { diff --git a/test/dm/scmi.c b/test/dm/scmi.c index d87e2731ce42..e4fb1bc635cb 100644 --- a/test/dm/scmi.c +++ b/test/dm/scmi.c @@ -109,7 +109,7 @@ 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 udevice *dev; + struct udevice *agent_dev, *clock_dev, *dev; int ret_dev; int ret; @@ -124,6 +124,14 @@ static int dm_test_scmi_clocks(struct unit_test_state *uts) agent = scmi_ctx->agent; ut_assertnonnull(agent); + /* Sandbox SCMI clock protocol has its own channel */ + ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi", + &agent_dev)); + ut_assertnonnull(agent_dev); + clock_dev = scmi_get_protocol(agent_dev, SCMI_PROTOCOL_ID_CLOCK); + ut_assertnonnull(clock_dev); + ut_asserteq(0x14, sandbox_scmi_channel_id(clock_dev)); + /* Test SCMI clocks rate manipulation */ ut_asserteq(333, agent->clk[0].rate); ut_asserteq(200, agent->clk[1].rate); @@ -172,7 +180,7 @@ 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 udevice *dev = NULL; + struct udevice *agent_dev, *reset_dev, *dev = NULL; int ret; ret = load_sandbox_scmi_test_devices(uts, &dev); @@ -186,6 +194,14 @@ static int dm_test_scmi_resets(struct unit_test_state *uts) agent = scmi_ctx->agent; ut_assertnonnull(agent); + /* Sandbox SCMI reset protocol doesn't have its own channel */ + ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi", + &agent_dev)); + ut_assertnonnull(agent_dev); + reset_dev = scmi_get_protocol(agent_dev, SCMI_PROTOCOL_ID_RESET_DOMAIN); + ut_assertnonnull(reset_dev); + ut_asserteq(0x0, sandbox_scmi_channel_id(reset_dev)); + /* Test SCMI resect controller manipulation */ ut_assert(!agent->reset[0].asserted); From patchwork Tue Sep 26 06:57:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 726383 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp2780054wrm; Mon, 25 Sep 2023 23:59:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH5qYqNsQe8QEMNGWc+p9EqJ8QVSjqq30Zj1Wck3lPy2oIWZDsIEzsDKdLRFTkV8/hXpgqt X-Received: by 2002:a05:6000:1a54:b0:31f:8999:c3fe with SMTP id t20-20020a0560001a5400b0031f8999c3femr6997248wry.69.1695711544012; Mon, 25 Sep 2023 23:59:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695711543; cv=none; d=google.com; s=arc-20160816; b=bQyVquJ19C0qUqQ4X+J+UNW318HHJHB4qvNUBN/HlQQOuEAhrNBIpCrrPBXFpIFl7f zIbCITzoqzrhW4HPs1RDYZwHucEQSPXZthXic0MDgPi48P2UAoLu8LlVkiFMLv9Shd1g aUixB8naoNRTTgkQq6+a7WdiK7V1zbCUns1sTOaYbqud54rkTQiCkrp7bYxY0LRrfJU5 jrBHMwRIzqHQgRbn+BD8zgvX7Qq9rLoeBlfncJ07PdSHMu2nvooH3glNSMGVZqVMGax+ vjVkljAa8k/AYbirSfZ8IZHaiIJrwwtynrJKlhZsWN6bpGOFg7jfUtqxElGR9pPh3c7T n6Ig== 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=7+fZ4uPuiJv98MxMUKuAL1DCCAodc37tEgHYeQrzqcI=; fh=+s9SE2w9oguEKAMcR35TXtqntCOeVFhiK9u/Kju91lo=; b=RRMSJf8d+5n6vgLE8mLbaraoLYEkQO09NWNRVEDlmqRz3ObokUB+YTxWkK/qLUHKIQ ahM7ppcsD/gO/Q6ZJ6Mfs+FVyPzl8A9eem/sse9Cp/BPMrj8ijzdA1G5qML6XncAggUE kwMzfb8X3V8JxcY3FTaxbRRexhyRcgwE/3m/IV5PC0wMEB0qnLjeCiq8J+ihjauGxsum fKvplMzomHowdBR2QrFfybx4+M/JAItiJdc/N/aKIGkO0lFW2jUCdFZOdaafalPVSqb/ jjo66whBU3QFfzgRJIhcxCYY2uieiBt54ZpnFTyptb8/GwVfDdz3RVmgafZlOglt8ca6 6byg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=J3pyei+G; 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 v13-20020a5d610d000000b00320004878c7si5640157wrt.116.2023.09.25.23.59.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:59:03 -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=J3pyei+G; 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 1B1DD86C0D; Tue, 26 Sep 2023 08:58: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=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="J3pyei+G"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CB41686C06; Tue, 26 Sep 2023 08:58:25 +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-x31.google.com (mail-oa1-x31.google.com [IPv6:2001:4860:4864:20::31]) (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 D39B986C0D for ; Tue, 26 Sep 2023 08:58: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-oa1-x31.google.com with SMTP id 586e51a60fabf-1dd26c41fc8so361311fac.1 for ; Mon, 25 Sep 2023 23:58:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695711501; x=1696316301; 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=7+fZ4uPuiJv98MxMUKuAL1DCCAodc37tEgHYeQrzqcI=; b=J3pyei+GFYDCQD2FyrFV/bfO5xcmbFKuX8pmii7j1jvDWqM4R0VrAdtofhNNqq8cyZ 26eM3N5gpoki/c+CcbEFacyNC0wKceTTeKYh8I+7pmuT1eu72k9pHvLd7k6X97xI1CLM Np00BldlFFY6X7Nu47B+BLL2FB3sR/yXnFKkSXxUw9uYyPf0o2A91TfIzt7ln3LOhvI/ UGk/H3ybMZscjEN2WZNJ4ZCKJYWIP5V0uzi8wEPQcfbHe7h5Ce/++IFsYWQqKXrgEMV7 8RqqrppB6JsTSY5mqBz1jyx1c7uQH8PRBVuuSEk1HGQdftPnavuTqW0C13spBg6rA0bF WKFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695711501; x=1696316301; 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=7+fZ4uPuiJv98MxMUKuAL1DCCAodc37tEgHYeQrzqcI=; b=Pq+lyNArO1Has5WVX2+UcvZGDfvBiNVHIyGUrkQwlCSv6FQSRQmPsKPKUwfx5n6gux p/jKF7Tiq8Ghn9Km+gJsC+xi/yzOOygNzLx/w+RfGHHhl2AQmP7sOcRIdauGWjBot4jO /RRsNiy/DQhH0wojq1PMac2jWtDVlZfOrlnCEnZwzgTn9JhYmKt+ypPIO5X7Dg5U5CsI mhWIJ0T3ggs67Jd36Lgx+QygRPVhv5a40qtkK3AvKb3InZ1aeA+coxd4BIhMS+kFv47r bK8+MOsoDoF4DuaFHswBprcoZbXdt2DC0vUmeq6J/PH8WcjkGcSAAvCJ7Hz2/EtzN7uj Wd7A== X-Gm-Message-State: AOJu0YzHBEsFluAe4r99eDZIqblh9fQkK7LuJBvHA742TjGROBtRHMK7 CG9ZDdjMpjxf7beNK6c+TIoh6w== X-Received: by 2002:a05:6870:17a2:b0:1bf:9fa2:bfa3 with SMTP id r34-20020a05687017a200b001bf9fa2bfa3mr8077359oae.1.1695711501134; Mon, 25 Sep 2023 23:58:21 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:6585:aea6:5002:a825]) by smtp.gmail.com with ESMTPSA id s2-20020a639242000000b0057825bd3448sm8758874pgn.51.2023.09.25.23.58.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:58: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 v5 05/16] firmware: scmi: implement SCMI base protocol Date: Tue, 26 Sep 2023 15:57:39 +0900 Message-Id: <20230926065750.734440-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230926065750.734440-1-takahiro.akashi@linaro.org> References: <20230926065750.734440-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 Reviewed-by: Etienne Carriere with comments addressed or not. --- 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 | 657 +++++++++++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/scmi_protocols.h | 351 ++++++++++++++++++ 4 files changed, 1010 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..dba143e1ff5d --- /dev/null +++ b/drivers/firmware/scmi/base.c @@ -0,0 +1,657 @@ +// 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 on failure + */ +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 on failure + */ +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 on failure + */ +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 on failure + */ +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 on failure + */ +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 on failure + */ +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 on failure + */ +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 on + * failure + */ +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 on failure + */ +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 on failure + */ +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 on failure + */ +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 on failure + */ +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 on failure + */ +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..ee551b38deb4 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 on failure + */ + 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 on failure + */ + 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 on failure + */ + 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 on failure + */ + 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 on failure + */ + 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 on failure + */ + 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 on failure + */ + 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 on failure + */ + 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 on failure + */ + 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 on failure + */ + 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 on failure + */ + 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 on failure + */ +int scmi_generic_protocol_version(struct udevice *dev, + enum scmi_std_protocol id, u32 *version); + /* * SCMI Clock Protocol */ From patchwork Tue Sep 26 06:57:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 726384 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp2780093wrm; Mon, 25 Sep 2023 23:59:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGpPSGXPn8C1j+YykpVeIUr40GoWrOZWfGvikxhdz0It9l8397E6a4lb6l3O0WOBSxDxkm6 X-Received: by 2002:a5d:618c:0:b0:319:7c0f:d920 with SMTP id j12-20020a5d618c000000b003197c0fd920mr7576273wru.57.1695711555621; Mon, 25 Sep 2023 23:59:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695711555; cv=none; d=google.com; s=arc-20160816; b=SqIFb6Da07KaM6OFxEV1ljAVUQfQGObH3Rt1O5VAZi4h+Tz4uGSptiC/POPHVdvuUz +lTdX9zuOXcirsMAMx2s+FCoxJwX0cU1PAzT8yER7gYEAC4mWXZy79QrxGr7sBHHnq/C 4VMEAofcaGe+JQ8B1dAoLZ2R6vFRKSffmY/hUi5m3dHb09jZuszLzNEUaUEBxuwF+6LO zURkxU9z7UMr6j00Auv6geYniS9sL7IxCQFvnULMAa1Zj2/djtSq1CiEEHJ2W+Zyar40 yAOYunmrFRRu4NS7oOdgo0jr6i2AEGn78W6kGF/zPRMuOkVFz14ZCEiSEO/A3iUev0Hf y62A== 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=pCRhEiNZjXNhx0qdWTCaYuD1CA83EGtZrc+sEunGweE=; fh=K4dQhL74gef2glEqNOnE2YOBTqRi7qf0ycKBewrN6K8=; b=NQR1otuq5Kzn17gnKaYfGJ5JiB7uMN79APxjWFyhxjhXzFbKvI88l979LZ/HnQ9RJq rqxeU4ZkAjCMvsktCjsCKsf9+VjdDuKfwavM2zXLQdfse51bg5vYiPvtD/StxttmGNR/ EBYwi+iEW+fk0uqVpww54//eWPwbv/NZWY8gwfJgwGQZCDbwZeO1igr4d/dwY5mKxZ59 92dDsJRbzpbG/IJTQMFHITnGHh7OgTV2Fp/2C5YwQ7PKMRN7Zn0XrRVZax5DWCErOHIp C2LyJ8nr1120UCAffS0oPi0ekRvdwxY9EYY6cG4PsU/GSAxqa/dCJuvwmWNQ8YF/jXRR dHwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=p9XZkP41; 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 o6-20020a5d4086000000b0032152f6bdaasi5811568wrp.267.2023.09.25.23.59.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:59:15 -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=p9XZkP41; 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 7AF3B86D22; Tue, 26 Sep 2023 08:58: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="p9XZkP41"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B576886D22; Tue, 26 Sep 2023 08:58: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-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) (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 D12F986D2D for ; Tue, 26 Sep 2023 08:58: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-ot1-x333.google.com with SMTP id 46e09a7af769-6bc57401cb9so1111453a34.0 for ; Mon, 25 Sep 2023 23:58:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695711503; x=1696316303; 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=pCRhEiNZjXNhx0qdWTCaYuD1CA83EGtZrc+sEunGweE=; b=p9XZkP41mjbMZ7Y09Bq7ia9sbxECWmPpb5I593F2YPeF8JlG5q/ZTqTlA01PojMZsT KhBYc0nL3d2SE9H+iZ3egLLUCTpkv0ko4+V2MBUg7lMzUtuPpQo+8wkCTXr/cmCKpDZ2 Wm227k36jBjP+iKFYxD/L+klHTRHTO12570lbkwwtu/Rd7ors9bQenqcgjmFgtXtJs7R ac/Lhp7WGt/1ot7PJPWwOhzL9VHdt5SR61tm8MMwwWawSmXZuUaOTz/4Tk8lfqGCDcGu +NMF0+WMN6lCiSe8VayTdR0tDqlOUkEAPKw5xNBqYZHtsx2+h+9eF/nh8oTRL2XY7lAd fP9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695711503; x=1696316303; 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=pCRhEiNZjXNhx0qdWTCaYuD1CA83EGtZrc+sEunGweE=; b=b+ylRg4EwdoJbBSacDAYC1vn50+Aoq4d71P54kUCT8z5cPToEGbyXpOQTe4emQDo3F /MeK0YibIw9SQdNk1GTd0hW2hqKhdsbk/T9QrFSip8e38s9xVXbMdyM4A2RVBu1I0Scl rlj4iMRuwK6WBc579iOQv+0m/YAlJFWl4fWzjlVslgUUK3tnnqoSjWH51XuFa4i8ERgr sdW69CAun2boM3czigkztHm4OLuIPjMELzWeG7x1HUpf1A7CLZA9Vub/ZA11qWyCwZ9A kLkx57snZlxrIC8lLvBADRsdoeKJdWYjiYYUj5sDVGqWVErXlBisVd+yoG/Y1vdMTBEX VkEg== X-Gm-Message-State: AOJu0Yy1/ksk1jJUZNLMFD0pRa7gEIh0WlleozfBTiZuHgi0ww5HDoht d1W2RmEHzr0SdvQmdRPIv8SpaA== X-Received: by 2002:a05:6830:308b:b0:6b7:36af:1937 with SMTP id g11-20020a056830308b00b006b736af1937mr7686681ots.0.1695711503389; Mon, 25 Sep 2023 23:58:23 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:6585:aea6:5002:a825]) by smtp.gmail.com with ESMTPSA id s2-20020a639242000000b0057825bd3448sm8758874pgn.51.2023.09.25.23.58.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:58: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 v5 06/16] firmware: scmi: move scmi_bind_protocols() backward Date: Tue, 26 Sep 2023 15:57:40 +0900 Message-Id: <20230926065750.734440-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230926065750.734440-1-takahiro.akashi@linaro.org> References: <20230926065750.734440-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 --- v4 * remove scmi_bind_protocols() from the original place. See patch#1 * s/depeding/depending/ --- drivers/firmware/scmi/scmi_agent-uclass.c | 118 +++++++++++----------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c b/drivers/firmware/scmi/scmi_agent-uclass.c index a28692f39f4d..1fa1e9eef966 100644 --- a/drivers/firmware/scmi/scmi_agent-uclass.c +++ b/drivers/firmware/scmi/scmi_agent-uclass.c @@ -52,65 +52,6 @@ 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) -{ - 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; -} - static struct udevice *find_scmi_protocol_device(struct udevice *dev) { struct udevice *parent = NULL, *protocol; @@ -217,6 +158,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 depending 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 Tue Sep 26 06:57:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 726385 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp2780139wrm; Mon, 25 Sep 2023 23:59:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQXz6ZHzRWd2ff7C9W+VFuDgkFmwVrwTw8ZjS8fmBFdNS4R3VgPpIeJwisXBwpznMhaj5O X-Received: by 2002:a7b:c7d5:0:b0:3fe:5501:d284 with SMTP id z21-20020a7bc7d5000000b003fe5501d284mr7431527wmk.11.1695711566621; Mon, 25 Sep 2023 23:59:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695711566; cv=none; d=google.com; s=arc-20160816; b=tVFqLiRPiskQWyQI/xqdto0LUj6wwosZsKSVGpAahndgTnzomm666vDiwYz04arIqs G0WUbJ6QqT82TkKcUwwugYC6S/KaCR7KRv8Q/DsVHjWAOYjlNlj4rRgsx2U5VGqwIMPx x9/RffAuholHTGailazu6aBooClvN8DFX/J+Tm0S9h8qSxhxzrYegwKirx37HL6HSbI2 S/4wueiC4LzWCGXVDZeGKVy7QSTE0JA0XAMEfwyXkPxcEkiD+DYWMgfDPnH7JvGvqGJO KlKIKCYM1WqmicCYr2eQFKeeFz5hELJogO2o6FjMMAHiNMGRCOTZQ7cldJPziCjB3SOH KIbw== 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=cLRWsm6IYFzlIfmeMDJ8a5yW5HlQGLkW5IyvUDi5CKg=; fh=K4dQhL74gef2glEqNOnE2YOBTqRi7qf0ycKBewrN6K8=; b=0nx1uGDW3jItiuj/mTzPKgU7DggaJg8C+4OlZ/cWXDq2uvWdp6cLPfIZ/6eemMDVoz P+QDUhUh65Wa0wO+685oLfeORKgfa3g6X+1dwjSH/M4IkRoOiuxt8x4GH4OVHoGIBCWi vRhtYMwJPTnlZ7GkK/Jq1TiSPYrOQTs4eXnyeEmAeG4yAsAztUIyMuRuGJvzZp+RMaI1 jgx7qzo63eXF1pcfCsnQETrmtrWZnIFO1G4hLfAbK2OjxFOinUn9k3xcHSxV5fmc/Yht UNkFQzu/HCCIizwxyX8CZ8HOecWWbN4bpswTXW9hUNmgvevgCKzWsI1IscL0Q8X+rGQm bqNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VVGpMFRn; 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 x21-20020a05600c2d1500b004030e699cddsi343516wmf.25.2023.09.25.23.59.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:59:26 -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=VVGpMFRn; 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 0E84686D3B; Tue, 26 Sep 2023 08:58: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="VVGpMFRn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5241C86D38; Tue, 26 Sep 2023 08:58: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-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) (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 16DE786CBC for ; Tue, 26 Sep 2023 08:58:27 +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-ot1-x332.google.com with SMTP id 46e09a7af769-6c2107685cbso927190a34.0 for ; Mon, 25 Sep 2023 23:58:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695711505; x=1696316305; 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=cLRWsm6IYFzlIfmeMDJ8a5yW5HlQGLkW5IyvUDi5CKg=; b=VVGpMFRnTeA+9RCSyaIn06zG5z9ROJPIqXMsc2sJwccKdMZO4bavzMYERvXKjIL60Q fWV4Jog00DtHd+D0McVFjh91xMylMFX/x+W/51M41eKbueeCcTy18C+5rV949o0dVOPB moDfc6+arcobEN79uJjV8znRHFsqtdPdkMCqO3p2KJlr1rczTsBauq1LH9Ve2V8PuhAc PPk+a+TxuYSFOyGc9IPVLPN3j000ehMOUD4YkRO/F8V/fakC6avSzh9eUL0kKncdCxMq 25XbY4K42HvgOUDV0IPcmpztXEf2bdRj1LYG5SMOBFWD1VROz2d49uOVleZCArZJ4V4K 9YUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695711505; x=1696316305; 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=cLRWsm6IYFzlIfmeMDJ8a5yW5HlQGLkW5IyvUDi5CKg=; b=jmjQjJgCrfVIeE4HBIBIq9iG/URluBFbxro0Lbrtzm7kS+tDkgO1XPOnjyJl+VoYHg m3+FtaopHjE8GYw6EBg5zFRj1sFZiARt3fjHo5jqd7oQnNnFCMuz5aw77uAtDcQnVBKs OUwaPHKNaeCw2O4moVRZ1hUcUUrlplOIW5r/TThwSw1AoefiV8YUGfET22PH3ULA4I0u 9IW1Y8DZochYH4dZZachs+c7ik8nHeGjcZJYt1RhMN2NKwXgDGilfs66+H/vEzAoO3dh eGNwZjjk8aLPGTl71ELnWX5CWTlepqohKXOYCBsYQlV9wgArf0Fk3eU17HeEz3fppt+5 jE/A== X-Gm-Message-State: AOJu0YxXBaGIjXWEF6mL4MnQeArctkEggDyHSgIjqmrUCwgCbxsoNGwd IL/lgpUcHVCx9iTy0c1rdLak3Q== X-Received: by 2002:a9d:4c03:0:b0:6bf:500f:b570 with SMTP id l3-20020a9d4c03000000b006bf500fb570mr8284624otf.3.1695711505640; Mon, 25 Sep 2023 23:58:25 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:6585:aea6:5002:a825]) by smtp.gmail.com with ESMTPSA id s2-20020a639242000000b0057825bd3448sm8758874pgn.51.2023.09.25.23.58.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:58:25 -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 v5 07/16] firmware: scmi: framework for installing additional protocols Date: Tue, 26 Sep 2023 15:57:41 +0900 Message-Id: <20230926065750.734440-8-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230926065750.734440-1-takahiro.akashi@linaro.org> References: <20230926065750.734440-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 --- V4 * remove 'agent' variable as it should be added in the following commit 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 | 100 +++++++++++++++++++++- include/scmi_agent-uclass.h | 15 +++- include/scmi_agent.h | 14 +++ 3 files changed, 125 insertions(+), 4 deletions(-) diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c b/drivers/firmware/scmi/scmi_agent-uclass.c index 1fa1e9eef966..482cdaf0c6db 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 on failure + */ +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; @@ -168,9 +248,10 @@ static int scmi_bind_protocols(struct udevice *dev) 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)) @@ -179,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: @@ -209,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; } @@ -221,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 eee46c880a56..258aa0f37596 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 Tue Sep 26 06:57:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 726386 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp2780169wrm; Mon, 25 Sep 2023 23:59:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGgZZy+jDkzaqDcWlHPELmnnh9e49B4cxYflmvaSKH48mPBzVi2j/FacPaqkg/+sfqNJ2q+ X-Received: by 2002:adf:fa4d:0:b0:31a:d266:3d62 with SMTP id y13-20020adffa4d000000b0031ad2663d62mr7594200wrr.54.1695711576886; Mon, 25 Sep 2023 23:59:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695711576; cv=none; d=google.com; s=arc-20160816; b=asAeU1jS2y4hiIqvGLm/hM4OMAoFrjgvlZuWYv6NGiNM1d2TwS1CQvv1l1sQ2dR/0k YLHEaS40QvRF1ipCGa7hjAyWnE0cxozDttJhjRy5w09YzlrNxwpSzzuLAyF2lm+WkKG5 lfsC+OsbZdK538jA6GUa444b0TWZB4Z/ecU5stpznRWr4TR8Fk7gLUIpw1QRbOgRsK12 mFvqD9g6NeCjelh+xrlcVYTgIkMxXbdiJgqT+AtTzhhRs50O590BNWhxprW9EioSQCnZ irEF6+F/Tkqom5Jx/gZMg2Bd6d98Oo/sV56FNxJ3zvIbxjCrS72QWAjjtZ0PiktF+8iK +B2g== 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=w0VkA5ZEvMMrQPxzvrsI3HC9P2fb4sVO3QHTMu1u/8Y=; fh=K4dQhL74gef2glEqNOnE2YOBTqRi7qf0ycKBewrN6K8=; b=Hhmq2PTI31wBvb5J31RAcUDbRh3Ef/gowqzYiIVzO1v/otHcSdWRPeMJXFLbrHAFAd aNYOY25LFWoG7P6jbEtKd2BNzCy11eBbpe/B2xuAcK/V1rOLu3J+f5SZC/YUNkIaZ6zK XD8Ux/+utiYCfo2mDNiX3y7BP9nr7/mL8HdI0H6LCVspvMUmSHZQZGOtmD7dNEZMNp4x 2r0kgndzi30mQ+SPsDLMVutFFgsqeE9/SqPmv1DmBCEayMXIHY5T6TtjppY551IF4jFm 0CndWW7EjkmkJ/6xgHr44QlZ7ValZR+3mBGB9yxljdbezPXPtuW52ZfCDekGIoJxmqeS GtAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WU0HI5qV; 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 k9-20020a5d4289000000b003217d86dfc6si6135095wrq.188.2023.09.25.23.59.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:59:36 -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=WU0HI5qV; 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 79C0886D38; Tue, 26 Sep 2023 08:58: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="WU0HI5qV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5D40686D4C; Tue, 26 Sep 2023 08:58:32 +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-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) (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 DDA9D86CBC for ; Tue, 26 Sep 2023 08:58:29 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-690f2719ab2so1943882b3a.0 for ; Mon, 25 Sep 2023 23:58:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695711508; x=1696316308; 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=w0VkA5ZEvMMrQPxzvrsI3HC9P2fb4sVO3QHTMu1u/8Y=; b=WU0HI5qVvpoBvMZY2InS5qGNUBxU6oOcNp1K3k1KrSyazmY20m5wgR5Llzwr/pAebp avo4Y8mVaVa+jejNnXSiiK9iGF6LUcRTO8MhiheUmdopQn3F2qONO9QcHKB5oF2K+80J SPnRr7zZApDZRVXw344wpjDHvBHOgiDKaFuuRVh/1wAL3jYBRqk5gw5ii/wOfbWe+Nl6 X7Vngq3RvYYzdHnmLkBudiGTkpbfNVTeFpcmOwXDxb+CG617hNo1eCtxsjcaYCTaDnMz VRqa9nQL6MPtvSqvm5ukNP5WW9DBRPaX5U5XQnRxT/Km7H80kH3pNhnTjU2qjeZJe44D /HBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695711508; x=1696316308; 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=w0VkA5ZEvMMrQPxzvrsI3HC9P2fb4sVO3QHTMu1u/8Y=; b=ULoyUELOkauDERzorZpxUWLj9idX0TS4SfeiRTPaSyX8esttxrcsCwXM0liUyVbZwT 4GUcbR5xfjloYMejJe0E3ovAY6mDeTvEQWN+A5Lco9qEDHQyMs70X0XqdbBJpeXDx9TZ jbkMnxIU+SuNO1fbusotvS+uE5DE2KItyW6kG5i9VPhfzM+iKSyxDEXFYeachZWz53MQ B0eZUlzqi19grWU9WY3Qh2okWEBqMJgbsFPddnLotEuiy+ibov9I+Qeu0qHMZ8Xxy5pW lOujHFuC1SR2efO+NojURGIOq8/VyRDUBwA426K2VUe15yxBbgv36ztkt2OLXKjUW7az eBmg== X-Gm-Message-State: AOJu0YxMU26jWzNhUJoCRnzU93Oi0WZlG4vrsBIUaAykCybvKtgIHFqM 44cHzJ4gPqvt2Eio5mDOVAjfew== X-Received: by 2002:a05:6a00:1d18:b0:68f:be13:6c16 with SMTP id a24-20020a056a001d1800b0068fbe136c16mr9969708pfx.2.1695711508240; Mon, 25 Sep 2023 23:58:28 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:6585:aea6:5002:a825]) by smtp.gmail.com with ESMTPSA id s2-20020a639242000000b0057825bd3448sm8758874pgn.51.2023.09.25.23.58.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:58:27 -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 v5 08/16] firmware: scmi: fake base protocol commands on sandbox Date: Tue, 26 Sep 2023 15:57:42 +0900 Message-Id: <20230926065750.734440-9-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230926065750.734440-1-takahiro.akashi@linaro.org> References: <20230926065750.734440-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 --- v4 * move this patch forward in this series before installing base protocol to avoid collapsing existing SCMI test. 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 394df043918f..716bbf97d5c9 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,13 @@ * 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" + /** * struct sandbox_channel - Description of sandbox transport * @channel_id: Channel identifier @@ -53,6 +63,14 @@ struct scmi_channel { struct sandbox_channel ref; }; +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 }, @@ -134,6 +152,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) { @@ -562,6 +890,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: @@ -604,7 +962,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 Tue Sep 26 06:57:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 726387 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp2780216wrm; Mon, 25 Sep 2023 23:59:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGp+tULSlx+j4ItMhtEuLsXv4dJ8vyNWKZ/xu5rJbiVsXgWLOeBu58KPInlmk7kcIoL4N6s X-Received: by 2002:adf:f8c4:0:b0:314:4237:8832 with SMTP id f4-20020adff8c4000000b0031442378832mr7828397wrq.48.1695711587421; Mon, 25 Sep 2023 23:59:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695711587; cv=none; d=google.com; s=arc-20160816; b=R92HIoWj1t/YlpDNzpp0HIZVTK2cMFGnOyOPiehJTHlHIkTUAh/EFhwSeR87uddaMr ZUTeoN8AV7a3syjKgNS82JU9PEMKURVguh7kBKeB9krINOSI9/hrISHh6TqT4Luwgopl m9vJZmBdxAaWGwsQubaRp+G7GG6ucraHsYKeq1llptrTyMr5Msvkparh4ovhRCI7Bm7V bi+3496VZZ4eksBpfzylGGABcp9hoipeTIJpGXF+jG7+G0gJZMmrHiKbhkT+UpPGvVq7 tt6WqzjZ3YuBE2irD/LANVxm9Ghds/NmAMW01RvySRETJAIJ+xznCmMnnC6qwf8p3Sh8 zjSQ== 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=2rkVWVPg//wDy6E/QDf0dDFeyFNwMuQ2Qpw4+CUtJYE=; fh=K4dQhL74gef2glEqNOnE2YOBTqRi7qf0ycKBewrN6K8=; b=ra3j52ymqfF9Xt4/gol1ToK3ODjrZ2nU4GgowfahlOfYQEI4Jmfjy98ASHLHg1nhjU /aeVTuzJg5yoVdQpugfBhPI37/aLA9Q5YzoIGqAKa4WOXORqfi1Ci7VjaROu7QwL7F6D JO4paAoU8MGmvMPoV22FucvjMUq+xbsIolwzjhX/I4eAkFliUnq7Pi5xoF7DvaHiaKwL EVt/7dcf9HuhU8YUjLF5VXRg0zCcrX3gIUWta7UIz4EQ3nZQZjC6FBkYw9YJa7DRflWr Qf0aUYSdAHcbvs/9HrgxexKsYTN0HSKLQm9YP6zDbdOApWZhI7KNCnf23JaGR7gT4+wM VPqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="SAvaK/tp"; 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 b16-20020a5d40d0000000b00314317f3b84si5796146wrq.331.2023.09.25.23.59.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:59:47 -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="SAvaK/tp"; 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 D67EB86D09; Tue, 26 Sep 2023 08:58: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="SAvaK/tp"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7847986D42; Tue, 26 Sep 2023 08:58:34 +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-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) (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 EE56F86D47 for ; Tue, 26 Sep 2023 08:58: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=takahiro.akashi@linaro.org Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-3ae473c0bd6so399743b6e.0 for ; Mon, 25 Sep 2023 23:58:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695711510; x=1696316310; 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=2rkVWVPg//wDy6E/QDf0dDFeyFNwMuQ2Qpw4+CUtJYE=; b=SAvaK/tpTDfQKj8yghXrn0WV6o7olZ0HhvvYOwTVC0N0lTChCQNavxCKIBjKgjNybM l443OUzsOW6Mlzv+ZpqIuStqG1QG0t6PAbwTUrLCERDR4XtHA3UZ819KsP1vz2v/RCwC ouzPhJiYMbvcfiSA9vaHsVG2q2bfleu7wD9NeglsbkgxKgz8Oh7Gxw2Crpe923WOZLGe FFmuto276xpvBmf0r7hATUBbeQJCBdY5nrK19GmP4PFU3N7NUgiP36t1bOv3NYxNIRuT MD0nzh/l0hdBCAxr37TPaRPM9bRhzC6OOYI3kP+l6vbSsGMVpNUKbv1Yw1TbckuMc5qg IWNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695711510; x=1696316310; 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=2rkVWVPg//wDy6E/QDf0dDFeyFNwMuQ2Qpw4+CUtJYE=; b=ewe0eV6HQksy0Pqghs+mryAbXHOijb9NeHEj33kz/ys3YU39l8OP4crZgp7/aBtIQr AYFuCo+EYwDFVZ92SXmckaG5Om6Sve8Ex0wqUWL6txmo79TEXTekiTUAZ3KH1tQjib7D X2UMll9pRixDHx3oy/2dP5wshlw6TC0tEXatk19YQavGkYGC/2BBydqVToQkJdEwYbiD CNAIFSmBoaYz8UArDmqy+z5Q3t8rMGasV6C4FhUnfnW7m9zAj/QfHu2Xs9Pfiv05wbEb 36K+Rbjd8/cVB1eMYV1yQBQu5fEMkBO7m+zrER8IS+wMLTkYaQQeQErXUmqiCreRIp/Z yqTA== X-Gm-Message-State: AOJu0YygrKpqdtDOO5kgS0wLGZ2BNIHi+gYKxiKwsccEO73Vr3sBLiSG NH4vziJrdSVfyqYxfLOj5EJdTQ== X-Received: by 2002:a9d:7f83:0:b0:6b9:d3bd:3985 with SMTP id t3-20020a9d7f83000000b006b9d3bd3985mr8840578otp.1.1695711510530; Mon, 25 Sep 2023 23:58:30 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:6585:aea6:5002:a825]) by smtp.gmail.com with ESMTPSA id s2-20020a639242000000b0057825bd3448sm8758874pgn.51.2023.09.25.23.58.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:58: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 v5 09/16] test: dm: simplify SCMI unit test on sandbox Date: Tue, 26 Sep 2023 15:57:43 +0900 Message-Id: <20230926065750.734440-10-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230926065750.734440-1-takahiro.akashi@linaro.org> References: <20230926065750.734440-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 --- v4 * move this patch forward in this series before installing base protocol to avoid collapsing existing SCMI test. --- arch/sandbox/include/asm/scmi_test.h | 6 +- drivers/firmware/scmi/sandbox-scmi_agent.c | 20 +------ test/dm/scmi.c | 64 +++++++--------------- 3 files changed, 26 insertions(+), 64 deletions(-) diff --git a/arch/sandbox/include/asm/scmi_test.h b/arch/sandbox/include/asm/scmi_test.h index 75cb462a5584..ccb0df6c148f 100644 --- a/arch/sandbox/include/asm/scmi_test.h +++ b/arch/sandbox/include/asm/scmi_test.h @@ -98,9 +98,11 @@ unsigned int sandbox_scmi_channel_id(struct udevice *dev); /** * 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 @@ -114,7 +116,7 @@ inline unsigned int sandbox_scmi_channel_id(struct udevice *dev); return 0; } -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 716bbf97d5c9..eb567dd900d7 100644 --- a/drivers/firmware/scmi/sandbox-scmi_agent.c +++ b/drivers/firmware/scmi/sandbox-scmi_agent.c @@ -86,11 +86,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) @@ -985,16 +983,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; } @@ -1002,9 +992,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), @@ -1016,9 +1003,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/test/dm/scmi.c b/test/dm/scmi.c index e4fb1bc635cb..913b6aba96ba 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 *agent_dev, *clock_dev, *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); /* Sandbox SCMI clock protocol has its own channel */ ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi", @@ -177,22 +163,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 *agent_dev, *reset_dev, *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); /* Sandbox SCMI reset protocol doesn't have its own channel */ ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi", @@ -217,21 +198,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 Tue Sep 26 06:57:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 726388 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp2780256wrm; Mon, 25 Sep 2023 23:59:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH7kDESrL2fMdxNSY3TOuG3d/evEnDUrUsZoB9zJvGgehJMk+z6UqCw4Zb2BliBdLFMV/T2 X-Received: by 2002:a7b:c84f:0:b0:3fe:1232:93fa with SMTP id c15-20020a7bc84f000000b003fe123293famr8101614wml.22.1695711596884; Mon, 25 Sep 2023 23:59:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695711596; cv=none; d=google.com; s=arc-20160816; b=CoNNkB9ESGeb3z9WImwvLdRm3DAo/gtFIKwQraLnHUDr/yDxZLvxO7+FsV0znGppKA 0k7XosJnoKzyeCJWeCWKddbt8soGNAzDhTMHQdZkoMACf9sxS4wEtl7prUtSWbEzXBtS HdK8GZBr4j1Yea83/NDSDACBGJV/hrMWUA28sfOrVhVACknhXN4bt5qiF9GS1+khGrt0 6FXdH94s2nCyWBU1a9gQL13j7WRbsZv2/q0INXWWav24BwnqmLo2EjJdjZTawYSJXH2t F47ukg2tZPohcb2jWx088HQaGRIwKaA5FduYpFBdVEx0bn8BB5kadhCvvUx8BvWiImpf QKRg== 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=yTq0+4rs1fOEBlwVehGWVMd6VipT0yIG14Yr57pn63k=; fh=K4dQhL74gef2glEqNOnE2YOBTqRi7qf0ycKBewrN6K8=; b=ikDbCQio67cr3fb4k0V6gaaSjl8ZM7yySVTL2PIJghjiYNvZr9uKD57NJehBWTGvIo +IT1LXrkAWMakcvmavEOkmuQo4g+GwtR2foEUKhGtBp9dtqldUqmADCf41gwOfLjHqEV AocP/ClpiT3iTAZW1pX3MClP6ObbMGnBhli9gSLY2FSFRgwF2s9qMcPCowbwtxPqSE7Y d4bShOJywkWc+5AxFSYI2U2kr0zrrkfnrjjxCMOktA3Iy8H1wIPG1AFfR2q3cHr4HrvB JuyXGYq34AX2/LQlF5SFmThRy+Qz1LDo9JdgZ4swI91dpj9NLoOBlFJfS92U1v2YKtGB Qqow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bF65pAk9; 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 c15-20020a7bc84f000000b0040535f7411asi6023443wml.87.2023.09.25.23.59.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:59:56 -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=bF65pAk9; 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 468EB86D4F; Tue, 26 Sep 2023 08:58: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="bF65pAk9"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 744E686D4A; Tue, 26 Sep 2023 08:58:36 +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-yb1-xb2e.google.com (mail-yb1-xb2e.google.com [IPv6:2607:f8b0:4864:20::b2e]) (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 31BCE86D53 for ; Tue, 26 Sep 2023 08:58: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-yb1-xb2e.google.com with SMTP id 3f1490d57ef6-d849df4f20fso2093554276.1 for ; Mon, 25 Sep 2023 23:58:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695711513; x=1696316313; 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=yTq0+4rs1fOEBlwVehGWVMd6VipT0yIG14Yr57pn63k=; b=bF65pAk9NIr5w3abZ467g+K1SwMj7yFqeZp1ruWPLdclL1HnnoRuYxWn4jkv/jX+8+ dTE+ODUciT/oV/5nBi1J5cI1tXqzDpURagH8tNOkM+H3ldy8jaceOAKa7qrvhD0xGaV0 EnTQz+r0jDPb7kp2kiQx2kuyw0VMOEsbbSWjnEnqFw1x8HvhiBBClX4zB+/QgdkMQ8Wm Dv3aAaDyvQ0jjim9cZ7lnvbGfGeqi5+hC4u20mqNlmB4YUICwtxK+tPC//CN+mRyldQs 0KO5ixZuIINDSGys00e76Unw67PDRiGA+dMMzwSGQXqyhPgjc4QTqY06JfLTJZYS/GsE SuEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695711513; x=1696316313; 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=yTq0+4rs1fOEBlwVehGWVMd6VipT0yIG14Yr57pn63k=; b=qg/slTYMOojbVqXyytimBT2c9zvuoI2w/Wsbv8nOw1xy801Jc8wen8W09VFN7F5mFE X0rRTXO/qpuddQOYUreObA47CwcfpRZRt/a/1mtxXh5gpd+ZuzgtyLYyTMflpim5h7Ne f/f6OBt3pfIzr2lJbZqgHYJA5Zw7caBykhqBHa0QW4mcviZMDbPQC/P67dERBoweFee+ fDwuwpHIWlj2k0UkUyMbbJa9verEGlMZS7kBSFrQCsX6OeKDGBd7/S85x3L+1plINAbO SmYmwPE+g6UGKz7nHNDjpU//TstOphoRbPey93zO+YmagyTClRYv0S9pmZQ/EFQsOgfa ad4w== X-Gm-Message-State: AOJu0Yx+FqEWAcQCCEqwVmsg4Ugt8uPbBKfq0VHe0WLOT3XQLNlMDXA4 aOagIXRSH85hd/CXHkG6d2ie9g== X-Received: by 2002:a25:ce54:0:b0:d78:228f:1068 with SMTP id x81-20020a25ce54000000b00d78228f1068mr5596118ybe.3.1695711512822; Mon, 25 Sep 2023 23:58:32 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:6585:aea6:5002:a825]) by smtp.gmail.com with ESMTPSA id s2-20020a639242000000b0057825bd3448sm8758874pgn.51.2023.09.25.23.58.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:58: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 v5 10/16] firmware: scmi: install base protocol to SCMI agent Date: Tue, 26 Sep 2023 15:57:44 +0900 Message-Id: <20230926065750.734440-11-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230926065750.734440-1-takahiro.akashi@linaro.org> References: <20230926065750.734440-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 --- v4 * remove 'scmi_agent' global variable as it is never utilized * add 'agent' variable in scmi_bind_protocols() * return an appropriate error (EPROTO) when scmi_base_discover_list_protocols() fails * fix misc typos 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 | 127 ++++++++++++++++++++-- include/scmi_agent-uclass.h | 66 +++++++++++ 2 files changed, 183 insertions(+), 10 deletions(-) diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c b/drivers/firmware/scmi/scmi_agent-uclass.c index 482cdaf0c6db..b1a9c36310c1 100644 --- a/drivers/firmware/scmi/scmi_agent-uclass.c +++ b/drivers/firmware/scmi/scmi_agent-uclass.c @@ -38,12 +38,6 @@ 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) { @@ -57,6 +51,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 +98,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; @@ -238,6 +238,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 on failure + */ +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; + } + + 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_id = 0xffffffff; + 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 -EPROTO; + } + + return 0; +} + /* * SCMI agent devices binds devices of various uclasses depending on * the FDT description. scmi_bind_protocol() is a generic bind sequence @@ -249,7 +326,40 @@ static int scmi_bind_protocols(struct udevice *dev) ofnode node; const char *name; struct driver *drv; - struct udevice *proto; + struct udevice *agent, *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; @@ -304,9 +414,6 @@ static int scmi_bind_protocols(struct udevice *dev) } } - if (!ret) - scmi_agent = dev; - return ret; } diff --git a/include/scmi_agent-uclass.h b/include/scmi_agent-uclass.h index 258aa0f37596..35d96069645e 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 Tue Sep 26 06:57:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 726389 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp2780324wrm; Tue, 26 Sep 2023 00:00:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGB5BzTNj2iEWhKRL/nVSmGrVe2MQzG+4nJbWQbKGa9LyhzTykjjl3B4yt5L8Bzy4DuUENG X-Received: by 2002:a5d:4577:0:b0:31f:f9de:6a4e with SMTP id a23-20020a5d4577000000b0031ff9de6a4emr7389344wrc.69.1695711607080; Tue, 26 Sep 2023 00:00:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695711607; cv=none; d=google.com; s=arc-20160816; b=Mrp/et9J5Zxxo3/hG/8PErdabz2rtIMbqOctyTDJinV4oYIO7ePKXn94h0ax9hJqQF cau4DuGTNLfoqjF3twm1mD1qnF9uuV3XvFonF5fuADoUWts3Jh+jtvquwc/isM24HELN e48X8Ybv207lfl7ftbseNkuivvSjZpUeHZQDdW1GbQloyztHSsdPHrK7J1o9V7ZjJVK7 268GdFE/xvdes/z1SySvtPtX6q79W8B1gRUc9X3hDEh73J/GhkqdHaY1v5areuNavEgy 1jlR9oOjHrNgbO/RZZ5YfdIxpaFWbyquqT5aWCig4VBVmu59B1dMNL1nlGvrwZcAEKZ2 gHpA== 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=vXcB1ML+GNN0PvOeGj9YekhiQKMztwG+L5FTsmlR42k=; fh=K4dQhL74gef2glEqNOnE2YOBTqRi7qf0ycKBewrN6K8=; b=ArRW0LSE+3QYjp4jiFfEQBPYZnHz5Y9R31XpiU4xkghb/kedxNsjLsvkMAS5J+nYgA Ye9jAC7Rep/ms4ikbAPBQQ+8gVHkpb24rYRLBjVdEELbMD+TdW2lcsk4Udp0gfL4Hmig depD7bOOnz/PK1jq7+URyyJJA/Zwf3fhh8rBYmrnUYASpWplmVUD1TVQ/vy9eZul5Lab fE7dKgfOjfM4tfRws15JBDRof9No32Ns/c8P7qW90FD95/YwAvduIDC+QMYzKhWvXe1t VEFPw7aYDpG5LHDEV3HNJVy4aWQwmbQc78sh9HQKPEUwoUI04W8ndLETdg845HSvKot9 inDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MyYf8Ibm; 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 a8-20020adfeec8000000b0032168aadfa6si5627143wrp.990.2023.09.26.00.00.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 00:00: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=MyYf8Ibm; 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 A858186D56; Tue, 26 Sep 2023 08:58:39 +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="MyYf8Ibm"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0D59B86D56; Tue, 26 Sep 2023 08:58: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-x31.google.com (mail-oa1-x31.google.com [IPv6:2001:4860:4864:20::31]) (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 E658286C00 for ; Tue, 26 Sep 2023 08:58: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-x31.google.com with SMTP id 586e51a60fabf-1dd22266f51so362830fac.0 for ; Mon, 25 Sep 2023 23:58:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695711515; x=1696316315; 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=vXcB1ML+GNN0PvOeGj9YekhiQKMztwG+L5FTsmlR42k=; b=MyYf8IbmcMj4tBd0lVHJnyWtpkiQn9F+H66ajdKdlKxGOd6+F2+wfmi15HNJxkvXQU tX4n2Co2zEePxXu3C0qQxkhHZFvz4wWgpAs1x67KHc3Nf6yL9/JMmsULVJ1PHY+t5Rse 6JFMQVIKKtS3w6g3mqWFch5EoM2jRwKjMt9bmCqrOhuJuvPYs++LaDdlY/c9XgaVICHF Z+F747oAnls7eCkIeVgH5arA/OoYwGrlXd88MuQQw+7k4TZGvUBVcTYpU5QKHT+X0QhT vC6NzVsum8+Nkp3oe89K3t2L3QnrdxuwzLSGDbC1uMZlnNiiKpGicpIufmgvhKx4wDCD Sjtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695711515; x=1696316315; 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=vXcB1ML+GNN0PvOeGj9YekhiQKMztwG+L5FTsmlR42k=; b=irTW5ZammWLa4AJtLsVwfu0/pk9wMADEe5mJ+y/cf9VpcF+6wppnbD/2dLGKH3YgK+ +KG9G1kTwJ30OIzX5ZJQ2WjGZMgCacGzlr9krfqFi7nzbiVqVNoHlp6SsU8zDczb84hy Xol3V1eBTCItSRRFuTOB5UxDcxjXDLLBIc3jV0T2NxqmhkKE+jU26K8shzXPgLxHXO9I o8EKXOv4/xCVTLDPbytnw+/lsHvC02QT3FGgtWYeEqS4Rn9zColOwakKMvmTKNcJOzPX Zweq+1C37nYyP/fRqTTH1UKbVGvioV/ZTJ7tzpMOIGdG9zO9PwWFRha9pmG+pcG632SE CwVg== X-Gm-Message-State: AOJu0YzAwkCDEEBALJYiob7LMNInM2jZjB8/l/WP8PhrRp9KonzwJ2Xs efMljHJOaDw9zzziz/3Lb1Gn9g== X-Received: by 2002:a05:6358:c12a:b0:142:d40a:82a9 with SMTP id fh42-20020a056358c12a00b00142d40a82a9mr6903848rwb.2.1695711515366; Mon, 25 Sep 2023 23:58:35 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:6585:aea6:5002:a825]) by smtp.gmail.com with ESMTPSA id s2-20020a639242000000b0057825bd3448sm8758874pgn.51.2023.09.25.23.58.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:58: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 v5 11/16] firmware: scmi: add a check against availability of protocols Date: Tue, 26 Sep 2023 15:57:45 +0900 Message-Id: <20230926065750.734440-12-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230926065750.734440-1-takahiro.akashi@linaro.org> References: <20230926065750.734440-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 Reviewed-by: Simon Glass --- 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 b1a9c36310c1..6f585b96f740 100644 --- a/drivers/firmware/scmi/scmi_agent-uclass.c +++ b/drivers/firmware/scmi/scmi_agent-uclass.c @@ -38,6 +38,38 @@ static const struct error_code scmi_linux_errmap[] = { { .scmi = SCMI_PROTOCOL_ERROR, .errno = -EPROTO, }, }; +/** + * 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) { @@ -374,15 +406,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 Tue Sep 26 06:57:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 726390 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp2780417wrm; Tue, 26 Sep 2023 00:00:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHQkGoc+xqtcItgbz4n+EGSnWskb7TIm/8uNC0+sgvsraz59qDgNyrgvwCkRBIOaWXLoSYk X-Received: by 2002:a05:600c:1c10:b0:405:959e:dc7c with SMTP id j16-20020a05600c1c1000b00405959edc7cmr3107794wms.30.1695711619195; Tue, 26 Sep 2023 00:00:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695711619; cv=none; d=google.com; s=arc-20160816; b=KcvsmebXlTJwscYMQJtS/kSs9qkS3BoGbrrrrhnQUzGG3BgY4fzVRGAUZ00xiDn3ze Ax6/FPyx3ZOXJ8OMTyhsb34s67jKQkulIjWHpF8a9m+qMZToQih3rj9uoK2BZDgkN9dY jkX4fsr7TAmYSCkYxEKd7LNH4EWcXEy0F2+9CcnKgkMzXzbkqdDtUyZjGOngptUwtuTr Q/lR6q5BbP6Mz0ODMzTwrJX1Gc20cCJ8ErqPFOG6pMrlaWpZLP1BKLoBMWn+fxVnewsR uR6zIy9MpeRfq2pgQ4GCJvrZmk1ULKBhIAhVXo7ipQ2lL+1N2ZvTlBZ0YnNMwU47+xFq M79w== 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=GhuiLnSkd0r2pmrfb876f/HtkofBDp54nLWt1Hr6m10=; fh=K4dQhL74gef2glEqNOnE2YOBTqRi7qf0ycKBewrN6K8=; b=ZRTY0KOFuzPCVM3XMcTR0IEPO9LvVmkOE+IlhRRCP8ku1mpC4vSCxDiQuIZ7UVfjf8 CW5oKttZ+nQnjb9guw5HhaVh8sNnqPmUOc+fYpMQlDAEb6qnnXnbjF5/BfpJOM0L+jqd gg9HJvOTHeA+Fe++hcLXSt47MtlZQx+XDXUmPjP4LPzzgTZcWaFHj53quCqF+b/rp9k+ c9TR9KPLTbChmVeTRUomNxj/GmpxAw8Y7ERaliQMcvX0onCHLgY8HMLE5IiUFJW0uZcZ TLg04tErHS5+o6N8/asMVbzXA+rdVRj8/TUFIto7TaigjexgZWga2zjOUL/Hy8caSDV8 x2TQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=urqT0lUG; 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 e17-20020adff351000000b003232290c2c4si2437598wrp.1016.2023.09.26.00.00.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 00:00:19 -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=urqT0lUG; 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 13A0786D5E; Tue, 26 Sep 2023 08:58:43 +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="urqT0lUG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9A6C186CBC; Tue, 26 Sep 2023 08:58: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-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) (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 7D7F586C00 for ; Tue, 26 Sep 2023 08:58:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6926d5ad926so1330558b3a.1 for ; Mon, 25 Sep 2023 23:58:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695711518; x=1696316318; 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=GhuiLnSkd0r2pmrfb876f/HtkofBDp54nLWt1Hr6m10=; b=urqT0lUGOG36960yyVhvdxL96fYVgvddYJxY6pgTpiklJYk6ErQoSPrApBxNV0peBA +F5nhURetB+0BPkLEGB01paQi+e/ST/0ONU74+oZThO3LhyaIO3ZrFiHyLjVYaNF5TJ/ A82QAK1RyfKhtasBCp9BaVQsxGSmJbJZc1rXaTcmmybLFi2BQ6KL4afKNmakTJHrdeoz Eb8GWXmMLSLmC9rSUlzwTVdbxzJIOci7SeLCq6PYcF6ICqd3Hh3FWuuW3pWetQGlphPO N7HPQoQGpPr6HntNO11HnoQFiPcQc0yhsqH4Nu3vKoIF0oDo4nDrtGJOA2OnNdsyiKXG k9TQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695711518; x=1696316318; 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=GhuiLnSkd0r2pmrfb876f/HtkofBDp54nLWt1Hr6m10=; b=o9jK0Ribf6WIOc4l6v+jt9peIwnZGNx+yEu8eDfM5+rXmSRtR3qri7oRmYxAP5mE8t 4gxLzd1vHR08xnIEXo8WZBGdcRFojzUxX4Uf9PG3sCOlvUZxGBc4VSGTqHcUjNv1g7ur rMq/TmH0jhk1O+UEEjQ0r4OGG/2kyppqnLsKvnnT5O7dkN9NxURSrY5vNjB8iEqrDCCE m1Fnjj84XgzXEWurgkLApc49gmhejDQYulMBQKP1vc30VGBu2NR69qtFx/8xmUxcck/m ngPCTg2ndxbAMaXr9h51mQTUb0+I9NfDhmUd8/Sn9ZEHthicgdCAv5hrvzesWWkuzT4c QGpQ== X-Gm-Message-State: AOJu0YzazxwRLMXThPbF9L7q/b4LzbnR0JJeshDqQSTIlwkNs9CicXmz l3BfeC+oadQSbIdUtXYV7qljhg== X-Received: by 2002:a05:6a00:134e:b0:690:d0d4:6fb0 with SMTP id k14-20020a056a00134e00b00690d0d46fb0mr10680682pfu.3.1695711517794; Mon, 25 Sep 2023 23:58:37 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:6585:aea6:5002:a825]) by smtp.gmail.com with ESMTPSA id s2-20020a639242000000b0057825bd3448sm8758874pgn.51.2023.09.25.23.58.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:58:37 -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 v5 12/16] sandbox: remove SCMI base node definition from test.dts Date: Tue, 26 Sep 2023 15:57:46 +0900 Message-Id: <20230926065750.734440-13-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230926065750.734440-1-takahiro.akashi@linaro.org> References: <20230926065750.734440-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 5e2bf8623dff..36de6a37cf6d 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 Tue Sep 26 06:57:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 726391 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp2780556wrm; Tue, 26 Sep 2023 00:00:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFZrnH6thWxQIWAiNbuxvmBiYuHguXAdZe1nMj9QC/qhpuJWnmgZAGvOczE4wQD/Jp/ObJm X-Received: by 2002:a05:600c:2108:b0:404:7480:d821 with SMTP id u8-20020a05600c210800b004047480d821mr7470588wml.37.1695711631590; Tue, 26 Sep 2023 00:00:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695711631; cv=none; d=google.com; s=arc-20160816; b=umEwyMEHZtw95WMSB9P3RPipum70e4uehZfbLjz6cAdHyfyEs+ZiNQEOyESKHufl13 ZTKBr6SJNlZPsnLb/gTKizPJPIofFlXNSI41kg0qCWnv/rdVVir+XpVHfoyaWGFGuxlw uYZv0vsSa3zsl4nnqsf4AixoykdBCTcuekpve+IlpBs3mEWjKZ9pBpqxCLy4JtbYeDgz HB1TOE9IIwOVr4Xq8GFC15g97zTOulV9AV2y4POO6t8iMS8EmEQuFx/f9GoGQDOk6tdW w0I5bGtSFr8LTu6ch1zft/G83aFuZDB29SYMkfanFZ1I9D+BGLM1SEvUPE2R6R22N5gq TjHQ== 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=79hlaO5yMrun8ZQmi4+Nlo82zoh8/1PuAEZB0NjCPmw=; fh=K4dQhL74gef2glEqNOnE2YOBTqRi7qf0ycKBewrN6K8=; b=HwPZ8At7IY0TPskDv7WK5+tx8evA407T77GeJ1Phy/6o+gWAr0W1FGc2quTPnhLfl5 LVRVqFRhTBxRtWoAn5Yawfd8+jTwq2XoLWaCdSSYK9JXdch02vWKepOzPNNzFbt+i7us YxXZIfiMj4/vodQJFqxizVNfTlJY9bMu8JfXF58dJ+vpVcfrUc+GLJwJokNpopUjf4Di AODgWa0auYzU0AwuXth6tfq+R3vSQGq7zJIfu1bIceSAnH/r+WnICV4SWwvDXUI72Mnd Ox93NsraTQJ217E2qJpPdR4C6o6biThWTQh3s/LG0yUCrE6sAl6pdUReGCskyCN/36Fy cZzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=P5aPk6Uk; 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 fc10-20020a05600c524a00b00400f8f92c08si6492446wmb.52.2023.09.26.00.00.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 00:00:31 -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=P5aPk6Uk; 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 6967286D67; Tue, 26 Sep 2023 08:58:45 +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="P5aPk6Uk"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 54A8786D4C; Tue, 26 Sep 2023 08:58:44 +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-x2d.google.com (mail-oa1-x2d.google.com [IPv6:2001:4860:4864:20::2d]) (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 1A58886C00 for ; Tue, 26 Sep 2023 08:58: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-oa1-x2d.google.com with SMTP id 586e51a60fabf-1dd26c41fc8so361383fac.1 for ; Mon, 25 Sep 2023 23:58:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695711520; x=1696316320; 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=79hlaO5yMrun8ZQmi4+Nlo82zoh8/1PuAEZB0NjCPmw=; b=P5aPk6UkmcAIAoo/gJwV3B7ApZo4qIHO1TAgQEiUkjsnUknSbnaTJT7HMiwFeqzZDd EE5I+4zQeAyjTlbVZXr1eE1RatNgRTh6SU1+uqhZeHJz7FbqvYSnTq8XgdRE53dzSvfs GrKXIofmONhClwZFF+WsvGeId3pSpYd+/Iak5NtdT7mQic+o9iCYkPFXf8Hkc4+FBVaj 5eU0fduw0ehXPA4tBvSP40p6sWdfROjo1QEAL41pfTx6t9BqhAcBpeoDNErBz3qKBYvg Il1zGoyAaUbbgPMocY92D8TxuNCZFkfL88BCDkQ0Z+IZkiX2EZlrunPhwBG7fWe0+xxh TA5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695711520; x=1696316320; 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=79hlaO5yMrun8ZQmi4+Nlo82zoh8/1PuAEZB0NjCPmw=; b=k2/GG2sUZLNOUIpwscCEDYejnTRnz/B/Wg+Muvjwb7GlUSzpgwfsbGb8CeUQ9Vszzu UzlWohk3xu7hhyhxY/EU6TPpjOGtWK586uJGJpMtMXmybcshYg6ecAZhgPg/c+1699pe BaymigqKZ8aM9xUwWDmXqbHCVa5dqLJL/Bq57SaI6lPWMyf9Llb42REeaZ557RrsbQ+c 90uFTPGTcGlsa/MMyipXP897muRY2smUIM6MaDry3GjwK+xGH9HbaFa2jgI/rmSV1Mez vRRWdYFTGapZeQ5iP4hVT8hOB0KIR/6gQUEk6EgOysdcWthrid7J+na6B2qa7u1io4co W+3Q== X-Gm-Message-State: AOJu0Yxy82U7QjTzVcDwwTG25vfiS15yw56kbOy3rMkI+Jo4Kw2xClxc uPJ3QnqIO9IfJv+HkYp2F5aLQQ== X-Received: by 2002:a05:6359:5a2:b0:13c:b9a8:fe5b with SMTP id ee34-20020a05635905a200b0013cb9a8fe5bmr6556810rwb.3.1695711520552; Mon, 25 Sep 2023 23:58:40 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:6585:aea6:5002:a825]) by smtp.gmail.com with ESMTPSA id s2-20020a639242000000b0057825bd3448sm8758874pgn.51.2023.09.25.23.58.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:58: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 v5 13/16] test: dm: add SCMI base protocol test Date: Tue, 26 Sep 2023 15:57:47 +0900 Message-Id: <20230926065750.734440-14-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230926065750.734440-1-takahiro.akashi@linaro.org> References: <20230926065750.734440-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 Reviewed-by: Simon Glass --- v4 * fix a typo fix in v3 s/scmi_protocol_message_attrs/scmi_base_protocol_message_attrs/ 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 | 111 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/test/dm/scmi.c b/test/dm/scmi.c index 913b6aba96ba..d4ff60e00069 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,114 @@ 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; + u8 *vendor, *agent_name, *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_base_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 Tue Sep 26 06:57:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 726392 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp2780643wrm; Tue, 26 Sep 2023 00:00:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH5hYPkj/s+kB8NH5Szr70+m7KUyOmOBwzB+fb/rgMPFVU3FcaEV7CfyLLUgtIDSPf/tlua X-Received: by 2002:a5d:69c2:0:b0:31f:e02b:18ae with SMTP id s2-20020a5d69c2000000b0031fe02b18aemr1108460wrw.24.1695711642750; Tue, 26 Sep 2023 00:00:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695711642; cv=none; d=google.com; s=arc-20160816; b=skJCYbMdNGCeo34FemVrSnDNc6iMGR+V/7+qHUEn/o1qlXUSLig2zKpM+uvkJX+MWh HJigc6jF7MWtP6ngKC9QuRc/gDmQKhjko2T7UZfksEeCR1xgRn60xbMVSq7DpCtZa0XA vSooer1kn91hqY4JG5tY2cbZDBI6UhdHo96pLX1AKJ0X2KBjCITtEfk7XDe8W5F7X3+q ciYISHE9GqiA9/6NGGif+i2JZe/4b4mpnsRa3yfKWAICLHyOnRqsEj1rXOfmYVFeC2m6 gLYh802gUOtOQ4mWjD/bLIOIaMXgSHTknDxkTqJOFGZf81sS+3tGc/1WHQPxHEQTOVDi Q3bw== 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=nRiolMsv6ZPS6Jc/2YUFJaWwlvUCKU7oQX9CQdpO8zlGibUA+0l/Ds5s46TQ72dZrz p0HG9QCxlVn51nC9abi164otQc7z0e2L4UeTs+PZcJL5HIhEsC93jC9ZNEG7dn7W6Xwn bo67AZnP4UpCU7ic7SFLUlrl6rFG83CwlTJ4REmoERlwPtYYhJqfVmxkGPCOsicg9WhD 20MuzOHQ2qhqubUcb6Z12LC6uAzvA+Q9oBleu15xMwNxZwQ573a1Nvd6qE9/g7jML8HZ 3gj8Ko6VB+yJKrb+hV1VQtj/uJC54b3hiCVzBx/iFUKyCx9CaHzA38p1Liy+JnZONX5w xbiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZO8d3Ife; 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 a12-20020a5d508c000000b003232259a4ffsi2427293wrt.953.2023.09.26.00.00.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 00:00:42 -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=ZO8d3Ife; 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 D0CD886D4C; Tue, 26 Sep 2023 08:58: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="ZO8d3Ife"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2EE8386C00; Tue, 26 Sep 2023 08:58: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-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) (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 A9C0C86D65 for ; Tue, 26 Sep 2023 08:58: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-oi1-x236.google.com with SMTP id 5614622812f47-3ae4bd149d2so303245b6e.0 for ; Mon, 25 Sep 2023 23:58:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695711523; x=1696316323; 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=ZO8d3IfeLelxeM1dM7AGCIvmTV7xKepNr4cZ7HaDw32sK89Wi9CJNW0+ep4MZkG4Is kNEIcdU6yc7Who4BSXxuF/nuHAifus6XTGqYXCyv/DqXX7SXOnnOUoXzMtvh+aUJvTms t0dyy0JgLFSbuWJ8tDay81AE39uMNhOzjiF3CcwoVk8QdzUwNb0t7oVeloTZibVaj94I eQRQHk2nWI1Zvo/bKQ1HRddiYp36XQ6n2p5U2JpjuAjmYd3CcalNaZLCq06UW8F1veri 1oZwTo5Pc85quO/qpRWoCmwr+dYho2GGTqj1YZBHLZsLLogT4c2nRcqPtNh+z6tSoPUR h5Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695711523; x=1696316323; 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=ejmynjy+Ezwg4Nnibeudd1RQ8OhY/cAU6Zmrp9SV+NyF1yfRyuwaaHuRzlXZcyYegK Gh4SRKxgkiDu0tih921nPSTwZO5Li9YEaJE1AKiP/fgPlOhmu7RPMiEV7KqqxciXtzi0 I63bP3k68mzrFrq7whCSr3nR5N/Y8AzThPTDDdbdy9q7kbXceA8ZXoVWdYh0ynH2iMtc OOfFVVzhEj6PPAfZpZaYOWMBF+diWQawsbxbdVUH7ygMdh33TTT2KY4Gb4kVb2jAkPJ/ Vn4QhpBJf77cOsSBuXRU+P+L0ON67iJYJDnPIsOtQaxmi1mfplBig6Z9pnuWOox9ugmv R14Q== X-Gm-Message-State: AOJu0YxCY5YAQpH6Eiy+rTejeZZI7yj/V9MmRXWzIc2IaHDjsLgHSc17 9TW5PxGDzyCRMVdP+WRFL2fq/Q== X-Received: by 2002:a05:6870:3126:b0:1a7:f79c:2fbc with SMTP id v38-20020a056870312600b001a7f79c2fbcmr8157466oaa.0.1695711523166; Mon, 25 Sep 2023 23:58:43 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:6585:aea6:5002:a825]) by smtp.gmail.com with ESMTPSA id s2-20020a639242000000b0057825bd3448sm8758874pgn.51.2023.09.25.23.58.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:58: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 v5 14/16] cmd: add scmi command for SCMI firmware Date: Tue, 26 Sep 2023 15:57:48 +0900 Message-Id: <20230926065750.734440-15-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230926065750.734440-1-takahiro.akashi@linaro.org> References: <20230926065750.734440-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 Tue Sep 26 06:57:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 726393 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp2780803wrm; Tue, 26 Sep 2023 00:01:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHgvbkZ3eaOP21euJ4KEoZXLJRCrt8Gdq8SbjhDkJYQyaRKt7LaVt2AoY4uti4NdSBuz71d X-Received: by 2002:adf:e60e:0:b0:31f:f644:de09 with SMTP id p14-20020adfe60e000000b0031ff644de09mr7525279wrm.6.1695711662913; Tue, 26 Sep 2023 00:01:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695711662; cv=none; d=google.com; s=arc-20160816; b=IlfyRpphYTHTj32fORtT2+Urcd3wfYtZhFGrodph7P9iM2+bFkLTlaDuOP1bFZKIYv GlQI1z7MT2vAxcapAKWlWu33Nm6fvIyUNYkBQDAt1m5koHgz3qqXXTsQ/11hjHAkIHgT ZpjfwmQZ9e51SA5jrog1zO1qtVA95vNJFW9av8ATXKbvOvGofy43XXai2Upi55Cg/VMY tdzndQJc2AMrBXUYKaoh/YJz7RwcXDIOFO7sSADrctKhNovq5alfyOWikoKONXhanek2 IKDEron499eXq1Cl/NPEva9MdFFEfvdTR/+EARf8kteRS3N2g3oTkU4YjSTf7sciYGQN i18A== 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=lXHBt+K1km+W4GFANm6SDROKpTpvRqogPRSMXl325s0=; fh=K4dQhL74gef2glEqNOnE2YOBTqRi7qf0ycKBewrN6K8=; b=H8T9cvYtTqT8adGMJuJhbFj9FEQlkJkaKOaiTaqDVoAOsbkoSM1eTZrrhFwKZv/CiU DNxeUtGw/tofPr2GCSehDN3aE3bJhvZO4e1XBQiE7AYfF/7OYEEuHWO+Tz8270mU+ln0 p7XnDPnnvP+8RjpUGVOb6Njr3yWGjwfcE6M/Pl+PdAtYikHNMCpBPUF7775aomJ6DilQ bMppxqp4S1ZPq0yTzSIoC4LhREb1AIKxgvH/tG6q3XnXuiMCNT/svmUCacMktjnK7cVq AjvesKlohOqwscgZJ930Mh7EuX3+NvNhpVIaXT7e5TlltXnSRYJSywzlppVYOzRfQT4h 9lXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=d1knW6Qe; 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 i16-20020adffdd0000000b003195236845esi3584734wrs.246.2023.09.26.00.01.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 00:01:02 -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=d1knW6Qe; 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 E540686D4A; Tue, 26 Sep 2023 08:58:50 +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="d1knW6Qe"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E006286D71; Tue, 26 Sep 2023 08:58:49 +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-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) (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 5FFD886C00 for ; Tue, 26 Sep 2023 08:58: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=takahiro.akashi@linaro.org Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-690f8e63777so1514249b3a.0 for ; Mon, 25 Sep 2023 23:58:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695711526; x=1696316326; 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=lXHBt+K1km+W4GFANm6SDROKpTpvRqogPRSMXl325s0=; b=d1knW6QeWFex2NdIhAwIrUkb/95yeFYz3lVWBJzhP/ZE+N1VlzVDtgtnd3t0199US0 OBWuMWVPw+R4iw4LGyOsYQx3AyNRAx8cwzdfho0zn0vEZviJfUEt+/SNWE23m2+Y2ucT esU+hJSBMyL32UDs7WQEMRaxz28dN3jt5gR/LpaZnQLGFsyDluE8KLvq0aA0vO1mi0u9 pz0GEXyvatC6YxfD9oxQ809Vr5KKCtF3IO0kh3HM0m9qHos5dwXv/PvDQ+dvr81LJLn5 RJyr99bcs3YNhu1Vvm1cbRKR8Kph+cVyA6zRJJs7s98OrutKXAKt1aEoaKsjJD6RFCob 4aTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695711526; x=1696316326; 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=lXHBt+K1km+W4GFANm6SDROKpTpvRqogPRSMXl325s0=; b=porm47pt43L5GmpKKM8X/xyE//XleamYJoTggECzdeb4761lX6FkvG+7GkgcxdZPAF gDPI8AXrC5GEm1LLGElHrZN0ypd/RJ4w7sJayhKOH9myh2fKmSnT2gAEEc/+GItkmkWZ FiSdd0pgXxOZTGCtEOH+sJY2+rKELB6JDfGL2r1CxhW3w3hgcVTuoq6aYxCBekGUi4J1 hCpVhz2FSH8+H94sR7t2G5TfvhvV+Z4ls/uOn8X8zrf7bX5ChMPHf1i69ph8NXJbGisQ HJyIxcISt9MxcdmVsK/KfaOxTH6/OSIUQIs4eCvPYo4Q/S+WshXRklunhEVXh9KCJzyr qUbQ== X-Gm-Message-State: AOJu0YwYX6kgXg2sH7UsqgAkxC5zJNJid3kmxVZHlzKr1uAQYXD9UK5I ux74Yb2iHiYsjxOLJdicqrPBDw== X-Received: by 2002:a05:6a00:134e:b0:690:d0d4:6fb0 with SMTP id k14-20020a056a00134e00b00690d0d46fb0mr10680882pfu.3.1695711525641; Mon, 25 Sep 2023 23:58:45 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:6585:aea6:5002:a825]) by smtp.gmail.com with ESMTPSA id s2-20020a639242000000b0057825bd3448sm8758874pgn.51.2023.09.25.23.58.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:58:45 -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 v5 15/16] doc: cmd: add documentation for scmi Date: Tue, 26 Sep 2023 15:57:49 +0900 Message-Id: <20230926065750.734440-16-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230926065750.734440-1-takahiro.akashi@linaro.org> References: <20230926065750.734440-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 --- v4 * s/tranport/transport/ 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..9ea7e0e41dad --- /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 transport 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 Tue Sep 26 06:57:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 726394 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp2780933wrm; Tue, 26 Sep 2023 00:01:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXy+dZx5I02ljWA7JwX60Zj6mKe+9kD7DppQbpG++et2gDY17rGn6P8a/mnan2igO9nDa6 X-Received: by 2002:a1c:6a0c:0:b0:402:8c7e:ba5 with SMTP id f12-20020a1c6a0c000000b004028c7e0ba5mr7776900wmc.18.1695711677338; Tue, 26 Sep 2023 00:01:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695711677; cv=none; d=google.com; s=arc-20160816; b=ozbCq/7fgiVFK2KnxNt3gCt799rR438AYaFR4igwE9E2u4pbzogz9xr6uFYMeHVikb DjtYRP3EOfbafnHiAnkPKpQ5P0WJrwu/2PGmqHA+jmsq+8oSjd1hbPFUQdqCdsx+GmEZ Z/VmUQkZRZGV3bYUMrQWL8/TnkxrFhS40eNIQBSTyLyUtppVdCMrhuXwouM/NYtOC0Ja iwIwg0dI2EnQvWnfzBYBwpqsR8E7QdEQ9vJFzXLrN2O/w8m0Svu+4xgZSPZV/kjHjy5H szKmqYv45zIXQAU0NbHWSGVScsWubA1qtCjgUP0a4dwBxHXbReFKmaF5pwWwr+jhHB0L 0wKA== 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=GLIlsAiaYGyWD9uAANY4anGfvdQ5dSKKNYsox/E0Q4A=; fh=K4dQhL74gef2glEqNOnE2YOBTqRi7qf0ycKBewrN6K8=; b=dS6y/LidLs5fpgvkhdBriKr6QQ9AjxWXK6FP+uIs3JSniLq+qLEuQ7yrLz7oM9ZyrI PD1W+/N2FC1zUxuQyhfmDgtrmN1uI8TjcumJAOp/3RatO5vJrGCjsI4IvhWj1vXeZ+A2 sRXvEuRpX2B3NjOq0xsvh/5RwpL/2VYk990yM/NWY1Uy+XMLewt+3AmMYKNFRkQx7T6Q xi/E3yPW4rhg2pPFJYLlOBKsE1HaIc+H+DuB7wgK9mmieb0qqT2s38gEBi0ou5raV1XR cRBF25Lcl0JVS8VOujvZeE9noqvbTJvmEEmdz0UlTs13NhikQq93O8D4nFGI+kDZ2UyY ZllQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kBbGLzNd; 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 x3-20020a1c7c03000000b00402d0259525si6326097wmc.75.2023.09.26.00.01.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 00:01: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=kBbGLzNd; 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 4B5BD86CBC; Tue, 26 Sep 2023 08:58:53 +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="kBbGLzNd"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 124C686D7D; Tue, 26 Sep 2023 08:58:52 +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-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) (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 DAFFE86D7B for ; Tue, 26 Sep 2023 08:58:49 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-690f8e63777so1514256b3a.0 for ; Mon, 25 Sep 2023 23:58:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695711528; x=1696316328; 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=GLIlsAiaYGyWD9uAANY4anGfvdQ5dSKKNYsox/E0Q4A=; b=kBbGLzNddXDq/PITS5+T+chrbowFeIXEBTJ/HiERox2O3pcq/cONpPh77F6sKZYvPJ RLOIN79C4dOQab40ng+Md031GG4b6DBdHIh8zskAVaYZ2vG9zxnMFAY+45ufzX5C/8/7 50b7MnlmsvKixZOt/fF8smNU8Fkm/bDp+6gJDt90aGubNpkPEeWp2cUPg6B91MTtVC4Q GgnpwqWdtIAIHWgTSkAymKEt6fmSC7h2/HTIS6A8fO4HlwejTIbftLi4Dg5FvBm1J1DK zkqPsUEjHRMNIuc5wIJMR8vjLzS6U81PvJmTHsc8qcB8hS/L+tX8z8WybSM1MI437XxN Ag9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695711528; x=1696316328; 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=GLIlsAiaYGyWD9uAANY4anGfvdQ5dSKKNYsox/E0Q4A=; b=c0b+Lhyh1wc5M2dY2OuEzZm8Xv2P52f4qZjV4hroO31Hlk4yZBoJlDXYBSMSgmZ2uN HbL3geURAkOB1wc+qBrf7QTgvpTIatRbs1t7g/VsdBgWH+JQS4cUCUUISN7hdKARkVap IAmhiF3zvA8KASDwtBbmBbnjsLToDsidCLk78IQ9rTsx8N8IDnQtFRcklCB9oQ5iW5FZ kCDZSfqjieruoi2tJ2wScFjoJTNubzeMlo34+3TkAjoSWmyN8yRF8epCz5zWlNIgPahQ 5I2MkMg2jI3DNgjt+VSDPVjuTvcVi5mIr/AamkyeQSSJrRfZZAxRoO5odNqh84UeaZ04 b3Vw== X-Gm-Message-State: AOJu0YyYbth+ApxsEmc7c2mYKjooh4HtEN7huvTgOvMSR2pfxQwIt5YW BZxVlLxXTBwoXdgwQBujNO4pQQ== X-Received: by 2002:a05:6a00:b56:b0:68e:369b:a123 with SMTP id p22-20020a056a000b5600b0068e369ba123mr10727796pfo.1.1695711528189; Mon, 25 Sep 2023 23:58:48 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:6585:aea6:5002:a825]) by smtp.gmail.com with ESMTPSA id s2-20020a639242000000b0057825bd3448sm8758874pgn.51.2023.09.25.23.58.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:58:47 -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 v5 16/16] test: dm: add scmi command test Date: Tue, 26 Sep 2023 15:57:50 +0900 Message-Id: <20230926065750.734440-17-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230926065750.734440-1-takahiro.akashi@linaro.org> References: <20230926065750.734440-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 --- v4 * move 'base'-related changes to the prior commit * add CONFIG_CMD_SCMI to sandbox_defconfig v3 * change char to u8 in vendor/agent names v2 * use helper functions, removing direct uses of ops --- configs/sandbox_defconfig | 1 + test/dm/scmi.c | 53 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 1cd1c2ed7cd5..3906476bb4fc 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -122,6 +122,7 @@ CONFIG_CMD_REGULATOR=y CONFIG_CMD_AES=y CONFIG_CMD_TPM=y CONFIG_CMD_TPM_TEST=y +CONFIG_CMD_SCMI=y CONFIG_CMD_BTRFS=y CONFIG_CMD_CBFS=y CONFIG_CMD_CRAMFS=y diff --git a/test/dm/scmi.c b/test/dm/scmi.c index d4ff60e00069..949e49bd2c35 100644 --- a/test/dm/scmi.c +++ b/test/dm/scmi.c @@ -206,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;