From patchwork Wed Jul 26 08:38:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 706629 Delivered-To: patch@linaro.org Received: by 2002:a5d:464f:0:b0:317:2194:b2bc with SMTP id j15csp890424wrs; Wed, 26 Jul 2023 11:03:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlEOb+8pgnOwcvNpsT5NFipd14I+O4KVD+Sk1oS6JWI+YlupMtXNh56NOO6MBpCBUfHIjWeL X-Received: by 2002:a05:600c:218e:b0:3fd:2dcc:bc19 with SMTP id e14-20020a05600c218e00b003fd2dccbc19mr2020169wme.15.1690394623063; Wed, 26 Jul 2023 11:03:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690394623; cv=none; d=google.com; s=arc-20160816; b=V1aLpnEb3QorDAlH6FaKjdljKeM7Rm++ShApiV8wqvR2JEm6K2lgZQgLaTg6i9Id+A KI0yZ0EFWC5LoKgospBmWQ0+n/udVlJDDrXyKgq2SWiLK/UYWNZM6OKktl04wl4VU8hT SHpbz5vsSQIdKkGPC7MqW8Wr148fu0BDIyfE13YojPFcBPDZkI7Zo8Rt7M1S9SNLZ9d5 6JR0vQqsW78K4L829nRiJP6OOawIvy7NrrwOfkj6DY+FuumOry0VBt41XSOEEgC2bOlU uSSkNpcnhog5cmC8D6iwylyFKCahhaiHJ6SvebbGHbh/P6LGJ1JgvJwPtbKKx49GIs2f Nixg== 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=fJqxFGPmspZQ1w69S5YvKnsB8/uHEtmJtJNnPWotLTA=; fh=m4nYqZzoK9SCykCyJ/rhitDYsGwNiXM0bHxVQp6NtlE=; b=ledN+toCRfIyy8p6N1OInuXIyaWVaaxr6O5+LU9j/zEI/4hEJj/xnMwpT5tOlIJaGz OgCxxlo4zbTHWvT4La6KLWTCwA/KblFpAv4NaS1wWYR7AfU0W71rRQoWCyH49aryY8Ui XMcqVv0uWapKzxTpfx5MzRiRDtiinZBjeg/fA5r8NXIs4IJvUM2mW1Isgtc+FVWsk7oZ wMxSEdm9sHQWUfgK50tuEthgTi+PPMTSlQsnG+2pRFcliF7WZ1djJ4b1BcN61A/VwKa7 pWQEq7CwmtiwanKAz+bzJa+dIHdiW+ki0DdQWuECZZD2gkb4DmNR68tNXpBTROvWOq6Y VKYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eaRuTXlA; 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 v11-20020a1cf70b000000b003fbad317a57si1177972wmh.90.2023.07.26.11.03.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 11:03:43 -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=eaRuTXlA; 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 2FBB8867F7; Wed, 26 Jul 2023 20:03:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=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="eaRuTXlA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 19345867D6; Wed, 26 Jul 2023 20:03: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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) (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 EE3CC86842 for ; Wed, 26 Jul 2023 20:03: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-oi1-x22f.google.com with SMTP id 5614622812f47-3a1e8fe2cbbso37360b6e.0 for ; Wed, 26 Jul 2023 11:03:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690394613; x=1690999413; 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=fJqxFGPmspZQ1w69S5YvKnsB8/uHEtmJtJNnPWotLTA=; b=eaRuTXlAk0HKi8PRpzPh3QvDhUXPu6Fm4J43lUnw1ZewY2y41ah4Qj68V9UvmOETdC oSul1imKjyfA+/zMHOwDZDGmoBTGm4+QGJ66tEclNvC0G/MG/E3ZWa3p2upUUAoO0TDG tQBWD5Ud/uEB7bCouDa4XMAnTE0WqirI/5SN+4o/YkTcZR4Kl2oCpFM8BnvQWryUUDVL N8kL+lhTMtJPgGekVRj8Xy6YzBKMpgj0y0kNGZKFPCxl8upWizI4Aoo/gTxw57rZZoLW XQrwKsRfZhFd2PtRBH7reqRT4l481RfYdTTTNo3/RtQrmu808GftKNBI605Qc9dOtw8S AW9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690394613; x=1690999413; 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=fJqxFGPmspZQ1w69S5YvKnsB8/uHEtmJtJNnPWotLTA=; b=SpjW1fo7OEQUmYQMkQHSwr8cmV9PNUuT2K7+UWbADaLwNbYleuaga/vjtLd5YNDlCH c7xZ7EE5mTEu/mE6F31mSPkz3Vdl/geeHjMFRDiPSHUbslpWUM2Z78po5szXMo4IC+Sc MuYQIynAPJfe/pbs5CSJpU27eVUYSae7JZUcKmc5CyiPELP36d5mpuhlIPQ2+pdEWhkV zlimssYZvCOsI2mPb9g0H9K77rNGvHkr6iJ4/281ru3r+xDI3uKx6okKqQCxYMah/ggp o6UpMgq1i0X4105VGJA/xzrZfxhb9OF2r9TVFJkZlF4DdSYj34kwMKywPIbADevqudRa H0sw== X-Gm-Message-State: ABy/qLYqx8qAD87BOvPM7YoVY1LUx0CK9FUwn9CpBvesLlIaRu/UtMVY eIxlDqOVUjgfwaHid6Cbct6r9OY+vdpQ+zq2Ph4= X-Received: by 2002:a17:90a:3b45:b0:268:1e3b:14c9 with SMTP id t5-20020a17090a3b4500b002681e3b14c9mr1418178pjf.2.1690360753914; Wed, 26 Jul 2023 01:39:13 -0700 (PDT) Received: from laputa.. ([2400:4050:c3e1:100:b3f9:1d29:2d48:cb41]) by smtp.gmail.com with ESMTPSA id 16-20020a17090a191000b00263c6b44dd8sm865986pjg.15.2023.07.26.01.39.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 01:39:05 -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 v2 05/12] firmware: scmi: install base protocol to SCMI agent Date: Wed, 26 Jul 2023 17:38:01 +0900 Message-ID: <20230726083808.140780-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230726083808.140780-1-takahiro.akashi@linaro.org> References: <20230726083808.140780-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 --- v2 * use helper functions, removing direct uses of ops --- drivers/firmware/scmi/scmi_agent-uclass.c | 116 ++++++++++++++++++++++ include/scmi_agent-uclass.h | 70 ++++++++++++- 2 files changed, 184 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c b/drivers/firmware/scmi/scmi_agent-uclass.c index 2244fcf487e8..279c2c218913 100644 --- a/drivers/firmware/scmi/scmi_agent-uclass.c +++ b/drivers/firmware/scmi/scmi_agent-uclass.c @@ -57,6 +57,9 @@ struct udevice *scmi_get_protocol(struct udevice *dev, } switch (id) { + case SCMI_PROTOCOL_ID_BASE: + proto = priv->base_dev; + break; case SCMI_PROTOCOL_ID_CLOCK: proto = priv->clock_dev; break; @@ -101,6 +104,9 @@ static int scmi_add_protocol(struct udevice *dev, } switch (proto_id) { + case SCMI_PROTOCOL_ID_BASE: + priv->base_dev = proto; + break; case SCMI_PROTOCOL_ID_CLOCK: priv->clock_dev = proto; break; @@ -229,6 +235,83 @@ int devm_scmi_process_msg(struct udevice *dev, struct scmi_msg *msg) return scmi_process_msg(parent, priv->channel, msg); } +/** + * scmi_fill_base_info - get base information about SCMI server + * @agent: SCMI agent device + * @dev: SCMI protocol device + * + * By using Base protocol commands, collect the base information + * about SCMI server. + * + * Return: 0 on success, error code otherwise + */ +static int scmi_fill_base_info(struct udevice *agent, struct udevice *dev) +{ + struct scmi_agent_priv *priv = dev_get_uclass_plat(agent); + int ret; + + ret = scmi_base_protocol_version(dev, &priv->version); + if (ret) { + dev_err(dev, "protocol_version() failed (%d)\n", ret); + return ret; + } + /* check for required version */ + if (priv->version < SCMI_BASE_PROTOCOL_VERSION) { + dev_err(dev, "base protocol version (%d) lower than expected\n", + priv->version); + return -EPROTO; + } + + ret = scmi_base_protocol_attrs(dev, &priv->num_agents, + &priv->num_protocols); + if (ret) { + dev_err(dev, "protocol_attrs() failed (%d)\n", ret); + return ret; + } + ret = scmi_base_discover_vendor(dev, priv->vendor); + if (ret) { + dev_err(dev, "base_discover_vendor() failed (%d)\n", ret); + return ret; + } + ret = scmi_base_discover_sub_vendor(dev, priv->sub_vendor); + if (ret) { + if (ret != -EOPNOTSUPP) { + dev_err(dev, "base_discover_sub_vendor() failed (%d)\n", + ret); + return ret; + } + strcpy(priv->sub_vendor, "NA"); + } + ret = scmi_base_discover_impl_version(dev, &priv->impl_version); + if (ret) { + dev_err(dev, "base_discover_impl_version() failed (%d)\n", + ret); + return ret; + } + + priv->agent_id = 0xffffffff; /* to avoid false claim */ + ret = scmi_base_discover_agent(dev, 0xffffffff, + &priv->agent_id, priv->agent_name); + if (ret) { + if (ret != -EOPNOTSUPP) { + dev_err(dev, + "base_discover_agent() failed for myself (%d)\n", + ret); + return ret; + } + priv->agent_name[0] = '\0'; + } + + ret = scmi_base_discover_list_protocols(dev, &priv->protocols); + if (ret != priv->num_protocols) { + dev_err(dev, "base_discover_list_protocols() failed (%d)\n", + ret); + return ret; + } + + return 0; +} + /* * SCMI agent devices binds devices of various uclasses depeding on * the FDT description. scmi_bind_protocol() is a generic bind sequence @@ -243,6 +326,39 @@ static int scmi_bind_protocols(struct udevice *dev) struct driver *drv; struct udevice *proto; + if (!uclass_get_device(UCLASS_SCMI_AGENT, 1, &agent)) { + /* This is a second SCMI agent */ + dev_err(dev, "Cannot have more than one SCMI agent\n"); + return -EEXIST; + } + + /* initialize the device from device tree */ + drv = DM_DRIVER_GET(scmi_base_drv); + name = "scmi-base.0"; + ret = device_bind(dev, drv, name, NULL, ofnode_null(), &proto); + if (ret) { + dev_err(dev, "failed to bind base protocol\n"); + return ret; + } + ret = scmi_add_protocol(dev, SCMI_PROTOCOL_ID_BASE, proto); + if (ret) { + dev_err(dev, "failed to add protocol: %s, ret: %d\n", + proto->name, ret); + return ret; + } + + ret = device_probe(proto); + if (ret) { + dev_err(dev, "failed to probe base protocol\n"); + return ret; + } + + ret = scmi_fill_base_info(dev, proto); + if (ret) { + dev_err(dev, "failed to get base information\n"); + return ret; + } + dev_for_each_subnode(node, dev) { u32 protocol_id; diff --git a/include/scmi_agent-uclass.h b/include/scmi_agent-uclass.h index f9e7d3f51de1..0043a93c8d90 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 - * @clock_dev: SCMI reset domain protocol device - * @clock_dev: SCMI voltage domain 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[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; +} + /** * struct scmi_transport_ops - The functions that a SCMI transport layer must implement. */