From patchwork Wed Jun 28 00:48:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 697205 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp4080276wrm; Tue, 27 Jun 2023 17:50:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6++OqgQ5iGS+Ahp5or0ROwHZalrgJM38lVJCdEDpVkfT+5Mo8v5ksdDOBmLrk4rNFPX0vT X-Received: by 2002:a2e:8296:0:b0:2b5:a31d:499 with SMTP id y22-20020a2e8296000000b002b5a31d0499mr8034605ljg.52.1687913440078; Tue, 27 Jun 2023 17:50:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687913440; cv=none; d=google.com; s=arc-20160816; b=dCpbcIs+cN2Hi8AeUQgPATht1hKZA5iB41l6/iCgcq7KMKZGTerxW86HU9vCLL33At 15Yn16UhMu/xIA8oyEuk4IxCDlee6oPYQEq6xMNLp5oHQjAmlhtHIm1T+JwKK4N8VGDw 6ZLvU9s14hUasX8trpzeC3pP/e+pv4oZKtl11Dwwp/tLCrM0RQhZRyr+8Uuu9vW3EUpY /2fswZqC/8zz/H3KS6efOwt40gnVDeORGHmtpBFDnJEurI34lTDkgFDPnviIEbBS3Qng aSHS0khVouvF+D7EW8k/B0mR6YaegHm99A1abXrY9fLPisQB6nPtfcC5uanGVpUBCY5h daXQ== 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=bpKIVM96FQ93bUibcxiCrv3RPvrCyPoHlPBsZOOUS2Q=; fh=+s9SE2w9oguEKAMcR35TXtqntCOeVFhiK9u/Kju91lo=; b=quwMhE/SxSI061kN+b4U+PcF2RUefjAOfcsa/LBF9CBYHvaKqWrpXFKHLdPqZjBpZD 9PcVCWDaYVpbRa65TcbwbhUp9LNGnOUB3ouR7hF/ltaTX8Jb19fuSkUx2ExCsSgCPf9V hOICAKlpjHZDX96w1a+SCRiPsgOvJOGgvnoFkl4ZZXU7zPCsJxHvsc+gU189IfzKG2dy r1wX9IPZt9by8HOKOHgncvtJNdpRherRY2MIf/6hRcyEVncOaYRT21kaFghP1Bbq91xc YMus3bDCh9D6kYD6COfGlxcswS5HN7i5mJXZtvtKbMMtco3IA2QQAvAHWpWuBRutEkIm lymQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sHWhsBws; 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 j17-20020a2eb711000000b002b6a7ea1543si1343226ljo.600.2023.06.27.17.50.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 17:50:40 -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=sHWhsBws; 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 53A678661B; Wed, 28 Jun 2023 02:50: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="sHWhsBws"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6B08A865F1; Wed, 28 Jun 2023 02:49:56 +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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) (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 99882865FF for ; Wed, 28 Jun 2023 02:49:38 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1b3ecb17721so9825625ad.0 for ; Tue, 27 Jun 2023 17:49:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687913377; x=1690505377; 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=bpKIVM96FQ93bUibcxiCrv3RPvrCyPoHlPBsZOOUS2Q=; b=sHWhsBwsusI/j1FRN/ri+McDyn0smfWMwP0NqjURaUWShaB30k3WegOvRYmCd7mC48 4kBUaJ+z8ryL/BGF/aHnRF/M5mEzYSGJhCGHYnll1wKiEjt1JdAc4fL1yJ7++bYh7ZjV ygpsTo7ZDPX26Zc15T/Rso4RJYp87cq2y2cAjzr+RAnluHsMizIei+7P5IKVMWknbfsu BF5Qcw+yM+6rZ7Cpj4gGR7biNPbnPcQGY+timTf1OhW8/3eL2q7EjyrG7ILYX+VInos2 vVcnZsF71vEheWA/aZ4ViPDIj7y32LgXkqAMHSzNIo+0r4wgAtw3I6FYY976qQztPTmr tDSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687913377; x=1690505377; 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=bpKIVM96FQ93bUibcxiCrv3RPvrCyPoHlPBsZOOUS2Q=; b=FU5e2to/gTMkTm5citV7CUTbz1PMZPNEoUKx6GWyDIS1oW1VyTNEZfSj9CZ2sYP5Bo 3kO/Xi6bPUVqvsBseCnZ1BcD4pBMdmDag5Wqt/FILP5+8zU0OXF8gQEHa0kmMBkAljGu zdORhKoOs3VEhoxljVtfsKcVGMJTzWWWR8PQisdnC7hwzg84XjRrto28gT9u5HIxKxVw guBVRvo4UonXr+XI2/M+kEVXdkDR4/5Oa4Ci+ayJ3Xi23+hYpewyeoZhAQMAHj9VPZFz EsjTRzw8Ru1jgVk6dbnjjR1+CmJTzhXt7N6NHT1BpWc2gL1i2fed0Kv++WaJNCWiZhgf XFpw== X-Gm-Message-State: AC+VfDwsrmeaGnID6LOs1Ty6VUILIUEi0ZchQcD59XwkW3eYRJgcLcxy dZ9hB2YpMRMPg78PZbFymh1sOv0f2epWFsPTeUY= X-Received: by 2002:a17:902:d489:b0:1ae:7ba2:1a7e with SMTP id c9-20020a170902d48900b001ae7ba21a7emr39553719plg.6.1687913376547; Tue, 27 Jun 2023 17:49:36 -0700 (PDT) Received: from laputa.. ([2400:4050:c3e1:100:58b2:60ed:38ea:8b1f]) by smtp.gmail.com with ESMTPSA id u13-20020a170903124d00b001b3fb2f0296sm6517278plh.120.2023.06.27.17.49.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 17:49:36 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org Cc: etienne.carriere@st.com, u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH 03/10] firmware: scmi: install base protocol to SCMI agent Date: Wed, 28 Jun 2023 09:48:34 +0900 Message-ID: <20230628004841.21774-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230628004841.21774-1-takahiro.akashi@linaro.org> References: <20230628004841.21774-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 --- drivers/firmware/scmi/base.c | 6 ++ drivers/firmware/scmi/scmi_agent-uclass.c | 104 ++++++++++++++++++++++ include/scmi_agent-uclass.h | 78 +++++++++++++++- include/scmi_agent.h | 10 +++ 4 files changed, 195 insertions(+), 3 deletions(-) diff --git a/drivers/firmware/scmi/base.c b/drivers/firmware/scmi/base.c index 04018eb6ecf3..224e0ca7a915 100644 --- a/drivers/firmware/scmi/base.c +++ b/drivers/firmware/scmi/base.c @@ -484,6 +484,12 @@ static int scmi_base_probe(struct udevice *dev) return ret; } + ret = scmi_fill_base_info(dev->parent); + if (ret) { + dev_err(dev, "get information failed\n"); + return ret; + } + return ret; } diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c b/drivers/firmware/scmi/scmi_agent-uclass.c index 6fd948ae6ddf..ec15580cc947 100644 --- a/drivers/firmware/scmi/scmi_agent-uclass.c +++ b/drivers/firmware/scmi/scmi_agent-uclass.c @@ -56,6 +56,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; @@ -100,6 +103,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; @@ -149,6 +155,20 @@ static int scmi_bind_protocols(struct udevice *dev) return -EBUSY; } + 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; + } + dev_for_each_subnode(node, dev) { u32 protocol_id; @@ -262,6 +282,90 @@ int devm_scmi_process_msg(struct udevice *dev, struct scmi_channel *channel, return -EPROTONOSUPPORT; } +int scmi_fill_base_info(struct udevice *dev) +{ + struct scmi_agent_priv *priv; + struct udevice *base; + const struct scmi_base_ops *ops; + int ret; + + priv = dev_get_uclass_plat(dev); + + base = priv->base_dev; + if (!base) { + dev_err(dev, "Base protocol not found\n"); + return -EPROTO; + } + + ops = dev_get_driver_ops(base); + if (!ops) { + dev_err(base, "Operations in Base protocol not found\n"); + return -EPROTO; + } + ret = (*ops->protocol_version)(base, &priv->version); + if (ret) { + dev_err(base, "protocol_version() failed (%d)\n", ret); + return ret; + } + /* check for required version */ + if (priv->version < SCMI_BASE_PROTOCOL_VERSION) { + dev_err(base, "base protocol version (%d) lower than expected\n", + priv->version); + return -EPROTO; + } + + ret = (*ops->protocol_attrs)(base, &priv->num_agents, + &priv->num_protocols); + if (ret) { + dev_err(base, "protocol_attrs() failed (%d)\n", ret); + return ret; + } + ret = (*ops->base_discover_vendor)(base, priv->vendor); + if (ret) { + dev_err(base, "base_discover_vendor() failed (%d)\n", ret); + return ret; + } + ret = (*ops->base_discover_sub_vendor)(base, priv->sub_vendor); + if (ret) { + if (ret != -EOPNOTSUPP) { + dev_err(base, "base_discover_sub_vendor() failed (%d)\n", + ret); + return ret; + } + strcpy(priv->sub_vendor, "NA"); + } + ret = (*ops->base_discover_impl_version)(base, + &priv->impl_version); + if (ret) { + dev_err(base, "base_discover_impl_version() failed (%d)\n", + ret); + return ret; + } + + priv->agent_id = 0xffffffff; /* to avoid false claim */ + ret = (*ops->base_discover_agent)(base, 0xffffffff, + &priv->agent_id, priv->agent_name); + if (ret) { + if (ret != -EOPNOTSUPP) { + dev_err(base, + "base_discover_agent() failed for myself (%d)\n", + ret); + return ret; + } + priv->agent_name[0] = '\0'; + } + + ret = (*ops->base_discover_list_protocols)(base, + &priv->protocols); + if (ret != priv->num_protocols) { + dev_err(base, "base_discover_list_protocols() failed (%d)\n", + ret); + return ret; + } + + return 0; +} + UCLASS_DRIVER(scmi_agent) = { .id = UCLASS_SCMI_AGENT, .name = "scmi_agent", diff --git a/include/scmi_agent-uclass.h b/include/scmi_agent-uclass.h index 6c3d1321b1aa..8ead08b38fb1 100644 --- a/include/scmi_agent-uclass.h +++ b/include/scmi_agent-uclass.h @@ -5,22 +5,94 @@ #ifndef _SCMI_AGENT_UCLASS_H #define _SCMI_AGENT_UCLASS_H +#include + struct udevice; struct scmi_msg; struct scmi_channel; /** * struct scmi_agent_priv - private data maintained by agent instance - * @clock_dev: SCMI clock protocol device - * @clock_dev: SCMI reset domain protocol device - * @clock_dev: SCMI voltage domain protocol device + * @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 block protocol device + * @clock_dev: SCMI reset domain protocol device + * @clock_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[SCMI_BASE_NAME_LENGTH_MAX]; + u8 sub_vendor[SCMI_BASE_NAME_LENGTH_MAX]; + u8 agent_name[SCMI_BASE_NAME_LENGTH_MAX]; + 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; +} + +static inline struct udevice *scmi_base_dev(struct udevice *dev) +{ + return ((struct scmi_agent_priv *)dev_get_uclass_plat(dev))->base_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 f77c10f7abfd..07e99f19726e 100644 --- a/include/scmi_agent.h +++ b/include/scmi_agent.h @@ -91,4 +91,14 @@ struct udevice *scmi_get_protocol(struct udevice *dev, */ int scmi_to_linux_errno(s32 scmi_errno); +/** + * scmi_fill_base_info - fill information about services by SCMI server + * @dev: SCMI device + * + * Fill basic information about services provided by SCMI server + * + * Return: 0 on success, error code otherwise + */ +int scmi_fill_base_info(struct udevice *dev); + #endif /* SCMI_H */