From patchwork Wed Jun 28 00:48:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 697202 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp4080087wrm; Tue, 27 Jun 2023 17:49:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ68poidTr2lUgY0gGlIAnT7GuaL8Ukeb6/5O4hIn5MAsDYmJ9E2ZLmMugljkVxnohRIIroe X-Received: by 2002:a05:6512:3d25:b0:4fb:7b2a:78de with SMTP id d37-20020a0565123d2500b004fb7b2a78demr5622224lfv.45.1687913394596; Tue, 27 Jun 2023 17:49:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687913394; cv=none; d=google.com; s=arc-20160816; b=Tuh+wYhDkgBz4cz/CNNYyixu7tsHRU3N1VbM278SoRfNk7tUqIJCvrEOHSbrR4lQSg CJ/GRHiSIhslQy+/pKXCX/s/J9DjFmmgjcnCvFDVk/UA5DJ8/MRl8egAsSxzzdHpyuIJ TjW1ca5Tfao7OFehv0S2wHPocqz2tZVEtjkx9PyKhhB8TwF52jjavF0xslwW8R1rV42b TbO7BT3Hb/X0gRTcpmLzaf+vkaEMpj/0r4MkcQWYGbUyL59fZfeByElVcxiG0/G6myyD STPBrDp+pGojfZ18iRqyHl8smjCEGvAobUvbEe2IU4twu8ye7LXTl71VGwO7fSVw0QDz ca1A== 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=V0v+A+makEI14KDnzMTnkzMrbzEEb7geWvIieba4deA=; fh=+s9SE2w9oguEKAMcR35TXtqntCOeVFhiK9u/Kju91lo=; b=j+taFUjQppQGMX4+xj9jjJfEr+rv9L4P3ItyAbEryoLCMnMM8cyn6axj3Ggb7DEUNS iVKRa9v1AeShEEVECcrqBz2mPwXhFaa8ZiFb+TebHHCI8OW6o4GTJqaG9Lij99ZLUHfa M14ym7tTiPjfzBS4YQGGJLwJQtm0tu0QU7QnfLL5Mnoq7vbIvyu4LpfMeZgt1nlNrDmK jkiq4RBUoNd/FVGnQh0NAWFgn1JuAtkjMDuplAO5ef1OGDloPO82oJLgL9iDCSZUCayN 4cDETczLCUsAW8JqMVvGFp7mukC/XZ09fFR8Wlk2OvUicTF/9C+ru9DLeazKhpqZsBcR ZrGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IeXock4M; 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 m17-20020a056512015100b004f621c06aa9si2621588lfo.586.2023.06.27.17.49.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 17:49:54 -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=IeXock4M; 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 1042086614; Wed, 28 Jun 2023 02:49:46 +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="IeXock4M"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B0A9B86609; Wed, 28 Jun 2023 02:49:42 +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-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) (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 25C23865EC for ; Wed, 28 Jun 2023 02:49: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-pl1-x633.google.com with SMTP id d9443c01a7336-1b8130e0ac6so3019385ad.1 for ; Tue, 27 Jun 2023 17:49:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687913374; x=1690505374; 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=V0v+A+makEI14KDnzMTnkzMrbzEEb7geWvIieba4deA=; b=IeXock4MwUjB4cAQeQkNW9LDwQxvMw+6S/cQsTdFNPhBcq0zWUgfK9+Vy/0ieiOdDQ oJ/p4Sni0yJ98ouyVRaqeu8Ky+sqceDn5RW9SVY75BQi/dJH6KdIIl/JnOjgX3A8Bc0C XhOloiXI/IJth0+C3W2iE/g5bFLcnNg672EzjpOwAE3Jig2ar/kjv8+LzTNUHWDOagGY kRzXVcmsyBLRxzM3qVWWGv9dLoELItyFhEF2q127YqGGvnqTihnmY3SyNISvT+KvcfO3 JatSV38rss5LEJT1Kq1bk4NYz+NSN632Pq3Gxj7VscUGr/c77UqLtzD0WDFKOnaEyDPN Sh4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687913374; x=1690505374; 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=V0v+A+makEI14KDnzMTnkzMrbzEEb7geWvIieba4deA=; b=fN9ZFxCsJCNBSQC0B7NGfSp8IFuGTpuYGw49bAfVnaJGQ5/wzkiuCKSFonXCIgO4Yb koKXtXSx73YKdFJjAQvw/E1RRj7wmcK4IGpwGcs/JS8Ldr9thF/tcKwf1F4MQwVlgQnk n6QM4NIPyY9kFIBfPFs1KxNaAHaEVCbbgj3tG7tFSGJ7r6i4Rz1k/a30OS4r+hmv17w3 Han7dwsqwFoGzBSQdpoKl5i/686KqZOjueDXMSGfPTqQljUZFO280LUOr+/U41jbMmUa S8VyzWvUhdzCYaIo6EXzC/qn07MSZeHBZBhFXDWUx8mTuz7RTkaXZR6kwZ6eEEXNCDsN uq0g== X-Gm-Message-State: AC+VfDxH33uum215JcPUXA8MBlx7W1FbK74i1CZ2eKtA7F2PN4YTXdb7 Xlz0aB3wlcogxPKPp9jbw3uNtg== X-Received: by 2002:a17:902:d552:b0:1b3:ec39:f42c with SMTP id z18-20020a170902d55200b001b3ec39f42cmr3343901plf.5.1687913374422; Tue, 27 Jun 2023 17:49:34 -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.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 17:49: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 Subject: [PATCH 02/10] firmware: scmi: framework for installing additional protocols Date: Wed, 28 Jun 2023 09:48:33 +0900 Message-ID: <20230628004841.21774-3-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 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 --- drivers/firmware/scmi/scmi_agent-uclass.c | 105 +++++++++++++++++++++- include/scmi_agent-uclass.h | 12 +++ include/scmi_agent.h | 14 +++ 3 files changed, 128 insertions(+), 3 deletions(-) diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c b/drivers/firmware/scmi/scmi_agent-uclass.c index 02de692d66f3..6fd948ae6ddf 100644 --- a/drivers/firmware/scmi/scmi_agent-uclass.c +++ b/drivers/firmware/scmi/scmi_agent-uclass.c @@ -37,6 +37,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 device + * @proto_id: Identifier of protocol + * @proto: Device of protocol instance + * + * Associate the protocol instance, @proto, to the agent, @dev, + * for later use. + * + * Return: 0 on success, error code otherwise + */ +static int scmi_add_protocol(struct udevice *dev, + enum scmi_std_protocol proto_id, + struct udevice *proto) +{ + struct scmi_agent_priv *priv; + + priv = dev_get_uclass_plat(dev); + if (!priv) { + dev_err(dev, "No priv data found\n"); + return -ENODEV; + } + + switch (proto_id) { + case SCMI_PROTOCOL_ID_CLOCK: + priv->clock_dev = proto; + break; + case SCMI_PROTOCOL_ID_RESET_DOMAIN: + priv->resetdom_dev = proto; + break; + case SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN: + priv->voltagedom_dev = proto; + break; + default: + dev_err(dev, "Protocol not supported\n"); + return -EPROTO; + } + + return 0; +} + int scmi_to_linux_errno(s32 scmi_code) { int n; @@ -61,9 +141,15 @@ static int scmi_bind_protocols(struct udevice *dev) int ret = 0; ofnode node; const char *name; + struct driver *drv; + struct udevice *proto; + + if (scmi_agent) { + dev_err(dev, "SCMI agent already exists: %s\n", dev->name); + return -EBUSY; + } dev_for_each_subnode(node, dev) { - struct driver *drv = NULL; u32 protocol_id; if (!ofnode_is_enabled(node)) @@ -72,6 +158,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: @@ -102,11 +189,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; } @@ -168,4 +266,5 @@ 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), }; diff --git a/include/scmi_agent-uclass.h b/include/scmi_agent-uclass.h index b1c93532c0ea..6c3d1321b1aa 100644 --- a/include/scmi_agent-uclass.h +++ b/include/scmi_agent-uclass.h @@ -9,6 +9,18 @@ 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 + */ +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 ee6286366df7..f77c10f7abfd 100644 --- a/include/scmi_agent.h +++ b/include/scmi_agent.h @@ -11,6 +11,7 @@ #define SCMI_AGENT_H #include +#include struct udevice; struct scmi_channel; @@ -69,6 +70,19 @@ int devm_scmi_of_get_channel(struct udevice *dev, struct scmi_channel **channel) int devm_scmi_process_msg(struct udevice *dev, struct scmi_channel *channel, struct scmi_msg *msg); +/** + * scmi_get_protocol() - get protocol instance + * + * @dev: SCMI device + * @id: Identifier of protocol + * + * 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 *