From patchwork Wed Jul 26 08:38:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 706628 Delivered-To: patch@linaro.org Received: by 2002:a5d:464f:0:b0:317:2194:b2bc with SMTP id j15csp885096wrs; Wed, 26 Jul 2023 10:53:35 -0700 (PDT) X-Google-Smtp-Source: APBJJlH0Al71ktsDTL/1tE36f2Yr8L2om7tZQzTVU7SqBU7mIfqLHmh+srlyp9pOGuG6HAU4oN5q X-Received: by 2002:a5d:630b:0:b0:30f:b7b4:3e55 with SMTP id i11-20020a5d630b000000b0030fb7b43e55mr2003076wru.19.1690394015047; Wed, 26 Jul 2023 10:53:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690394015; cv=none; d=google.com; s=arc-20160816; b=phGIbSQAts7MWX3WD5vN3kBitJuKBM8HXJ6Ari2+gzNdDZbJ/HXJoxzoaPDNioqGc+ oRIxpZ4f5YkYoAeLsCJl13DeCCPh5IxNoqclE8owO0tmlL1TqASCAH75p3xtagD+OF/N 9y6tGRfArZxLMpqYmMcHxbPf7z9vn3vW2jeI+yMVgu9UVcm6kNHhFUWUCCaU+0RBHZxf EWehwitbggku1c/Jn3Zq8heHASCyk6GfwKWj5jzbmz7+yF8vDY80K8N7OF9k6C+iq71F /DoaWVAPwHcO1+ZfGA8IOx5f8A5VxmKX2BVyC/QpieBC+6btche7u0PWxKdLiKMcyDsb qLHg== 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=MB4vpu5rcbahIIwktElIVzrujb3dJDNygkbg7VBslpA=; fh=m4nYqZzoK9SCykCyJ/rhitDYsGwNiXM0bHxVQp6NtlE=; b=VlpNAKINOy+PCC4cGENCMLL6KtNO8i/GFWe+iEnO1zoKel7pbmayex/3P7ZkFQLNeH X5NP7zlrtGvcu5oJbOAh7EQCoINvWb3KL8y4P6OwVERXpfQtuABqCT798DWNVdTWZvVM uQeyttfrBJKxhyntGBTxs3/STajKMRrzxf8AG5dg5HehZ0oFfa2v0jDn3fyva7Q9UqvK 8X3iJi4E2x1maYI15mpBdU9mKsA4HL3GHvL6TAfM9TyOQXbEpZDViCh0/DNdKZPBkvx9 Bj7S4FD2C9AwUGbfCNpDPf0JuNn/6PbJwukgjOhYC3V5EIiM9ycpHPILbcyRO29tIE2D 0HEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Nhf9Td6u; 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 r17-20020adfce91000000b003142172ef0asi6919810wrn.76.2023.07.26.10.53.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 10:53:35 -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=Nhf9Td6u; 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 BFDB2867D9; Wed, 26 Jul 2023 19:53: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="Nhf9Td6u"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 569AB86828; Wed, 26 Jul 2023 19:53: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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-yw1-x112f.google.com (mail-yw1-x112f.google.com [IPv6:2607:f8b0:4864:20::112f]) (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 729AB8679B for ; Wed, 26 Jul 2023 19:53:26 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-yw1-x112f.google.com with SMTP id 00721157ae682-57a4c0324b5so126827b3.0 for ; Wed, 26 Jul 2023 10:53:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690394005; x=1690998805; 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=MB4vpu5rcbahIIwktElIVzrujb3dJDNygkbg7VBslpA=; b=Nhf9Td6u726lQLLTCkxswyCmPM0dttsT8m0ak5uWgVbq5wYLgFLlAsYk71TY3POsYX Wnj1LNngdWM/HAiT6PXyplkbVCqvVBABE8/jAs2bjgLweRYNIUIkodDGHh6e88sOyF0t 7NAhyVl8KwSXPzuU04K81aYrEgfIOqI6xKy3DWTSjPqz2r1arfUQbn7x6Zsg3eqVWmd/ QoOZ1pNVjwZ/oQu7BciEhgPkxQtU04NHm8kboWqi7SqK8v7JYFHGVc9cOmgAuwGzOtsN abDMzfDyk+0uhbc8JFX79Fx8k3EtUmkb/0KCQ5ELxvYU9MkeWyXEUhoD2QDwSWEJLydN mL0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690394005; x=1690998805; 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=MB4vpu5rcbahIIwktElIVzrujb3dJDNygkbg7VBslpA=; b=I2nQTVkKfrDs6SR6r3fxsf/FV4HhrriABK3JM8ro5OljkM7QRPsqZ1Lc8t1v7Nz8vM BwLK1a4Hv5yunlzNIXu7TsDaZvcl7tGP9w6iAn7P78e97Gq1Ohs06sQKcs10bEStr78c GZCZsmKblL2L/3l5IWl/hqS8h1BISEji/YAtlHDO9/5+ZkkSZpkgO9lEvPDcgUs15P1V BTSTmBUIy/o+FCPjGo6vygWeIVOCw6Djd0fvsefX11Vcg+eCLOOc9Hy3zcbRI9txxMmM +xNVBo4kdjFPeWHeRbCTlDW5b1DgznxfRLX5Hx9V4d5SApAeF3m3qxHD/7eBo4oHQUon Zf8A== X-Gm-Message-State: ABy/qLZBbm/SSphvlahmg4kD9FXKmkS/9qHZPEvzE0C7vu+09uRPeQDv Rr4t8BcJKOWqiepJRBdaUpGENoQz5R/cTl4CK9I= X-Received: by 2002:a17:90a:7c48:b0:268:38a7:842e with SMTP id e8-20020a17090a7c4800b0026838a7842emr1334844pjl.2.1690360742713; Wed, 26 Jul 2023 01:39:02 -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.38.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 01:38:54 -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 04/12] firmware: scmi: framework for installing additional protocols Date: Wed, 26 Jul 2023 17:38:00 +0900 Message-ID: <20230726083808.140780-5-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 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 --- 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 8693e4c447b7..2244fcf487e8 100644 --- a/drivers/firmware/scmi/scmi_agent-uclass.c +++ b/drivers/firmware/scmi/scmi_agent-uclass.c @@ -38,6 +38,86 @@ static const struct error_code scmi_linux_errmap[] = { { .scmi = SCMI_PROTOCOL_ERROR, .errno = -EPROTO, }, }; +/* + * NOTE: The only one instance should exist according to + * the current specification and device tree bindings. + */ +struct udevice *scmi_agent; + +struct udevice *scmi_get_protocol(struct udevice *dev, + enum scmi_std_protocol id) +{ + struct scmi_agent_priv *priv; + struct udevice *proto; + + priv = dev_get_uclass_plat(dev); + if (!priv) { + dev_err(dev, "No priv data found\n"); + return NULL; + } + + switch (id) { + case SCMI_PROTOCOL_ID_CLOCK: + proto = priv->clock_dev; + break; + case SCMI_PROTOCOL_ID_RESET_DOMAIN: + proto = priv->resetdom_dev; + break; + case SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN: + proto = priv->voltagedom_dev; + break; + default: + dev_err(dev, "Protocol not supported\n"); + proto = NULL; + break; + } + if (proto && device_probe(proto)) + dev_err(dev, "Probe failed\n"); + + return proto; +} + +/** + * scmi_add_protocol - add protocol to agent + * @dev: SCMI agent device + * @proto_id: SCMI protocol ID + * @proto: SCMI protocol device + * + * Associate the protocol instance, @proto, to the agent, @dev, + * for later use. + * + * Return: 0 on success, error code otherwise + */ +static int scmi_add_protocol(struct udevice *dev, + enum scmi_std_protocol proto_id, + struct udevice *proto) +{ + struct scmi_agent_priv *priv; + + priv = dev_get_uclass_plat(dev); + if (!priv) { + dev_err(dev, "No priv data found\n"); + return -ENODEV; + } + + switch (proto_id) { + case SCMI_PROTOCOL_ID_CLOCK: + priv->clock_dev = proto; + break; + case SCMI_PROTOCOL_ID_RESET_DOMAIN: + priv->resetdom_dev = proto; + break; + case SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN: + priv->voltagedom_dev = proto; + break; + default: + dev_err(dev, "Protocol not supported\n"); + return -EPROTO; + } + + return 0; +} + int scmi_to_linux_errno(s32 scmi_code) { int n; @@ -156,12 +236,14 @@ int devm_scmi_process_msg(struct udevice *dev, struct scmi_msg *msg) */ static int scmi_bind_protocols(struct udevice *dev) { + struct udevice *agent; int ret = 0; ofnode node; const char *name; + struct driver *drv; + struct udevice *proto; dev_for_each_subnode(node, dev) { - struct driver *drv = NULL; u32 protocol_id; if (!ofnode_is_enabled(node)) @@ -170,6 +252,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: @@ -200,11 +283,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; } diff --git a/include/scmi_agent-uclass.h b/include/scmi_agent-uclass.h index b1c93532c0ea..f9e7d3f51de1 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 + * @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 577892029ff8..a5e7cf0592bc 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; @@ -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 *