From patchwork Wed Sep 9 16:44:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 249511 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:dcd:0:0:0:0 with SMTP id l13csp542211ilj; Wed, 9 Sep 2020 09:44:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzV5E1V973+jUQB4/pF8LD5O/jSJivWIwr7cdelXBrTnHhxHBCbZOEqeULQHhdqfv6HCISu X-Received: by 2002:a17:906:e0c7:: with SMTP id gl7mr4416780ejb.109.1599669897454; Wed, 09 Sep 2020 09:44:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599669897; cv=none; d=google.com; s=arc-20160816; b=rCrSIPM5C3K68na6qsxEsbi5v6EFzxijAwgCxrZQcUojxjC9yH392x04n2ocyePlU9 GVgRc+XHHhikDNZO2bfC/xOHpLSZJcuGk0AgZjftwyv0y+c/GsLr4qPR12/luhTgVvwt 6+ZE9of7zTwKomkGUVDTdtvBj8+FS7Cg1vt0gR2ODltyPBcDiyPPrQzV6hmsbZ3yG8pd f6+nDNQ2wsjuGoydHS+4kiTHS06CkRWsif3+09ApozlItjAtgf4zyro6+DOge7M5RwC6 HflwSTeaYG/ynAcd+DtAdyCkKWEQHjFct65Or4xia7C3fzhYe+QDHOYxnBFSuyirrGfC lsFg== 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:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=4w1f9prBTyEoA8F3lvTpIKLOYddglqBi1OpeVbnivEA=; b=ivCNbUReYE0QfmkNk2x6haq23rbU44/k7wbC3ur9bL0lWwv4l86T9H87cSR8KoYVsZ GnyoaK8/9ZPe4PUPy6xdXSfCJdNMsnUEo1dsSH9L5y2yAJuAgBJEjlcPv4phYBWrbFk1 HZtNxkTv2AxH1Ojmbm2P8eXK41yOuPj534AJ6gKH03uF5+IbKnYGK8q6yysOAkZcvXTi 81FOlGFeHZWiZ7F5pDlErigVZcozz4F6IhMEwsKbWNsLAh0CA2LLYJ4HpsVU9pRQyNHY 8JWtqBEsAmI2MMidJruhdvEcFZZIgt/Vyqf3v+5DZ573F57uASwoGnHv4F8TeQtnqTqD FZ4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=n3UzLWtC; 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 c12si1959971edk.238.2020.09.09.09.44.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 09:44:57 -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=n3UzLWtC; 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 A033982286; Wed, 9 Sep 2020 18:44:25 +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="n3UzLWtC"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 69AFD822D7; Wed, 9 Sep 2020 18:44: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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) (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 59E86821ED for ; Wed, 9 Sep 2020 18:44: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=etienne.carriere@linaro.org Received: by mail-wm1-x342.google.com with SMTP id b79so3057552wmb.4 for ; Wed, 09 Sep 2020 09:44:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4w1f9prBTyEoA8F3lvTpIKLOYddglqBi1OpeVbnivEA=; b=n3UzLWtCHuS+EMfdePMIP3rLsVH5h+TGI6zq94C6iMataSXhaA0fKe1Vmk8kE31/yO 2/Bd1GN5LR6pEx+ETqc+cbFCtADDSK/bP4lAX9R2Jz9L44jjzMfGQwu/QM/5ctuIwHuQ fVAj6igcVQBA7L+B/0noLrttFMYALDWkVlbPMtBBgKvsuh1peyPCXNJ6EZMKkRFyVHg6 +HLyysal6oXGLBhzGgakWgxvQ0JQTQNR0nxBW6sjvQUNvwbagBniFuRcki929IhMf+ey UxgzhRdc7V2SvGTF17zLnT+H1bZ45Op1azkns1hD+M5S0j8kcrZ+O8t3azwsEFE/ljJY I5aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4w1f9prBTyEoA8F3lvTpIKLOYddglqBi1OpeVbnivEA=; b=b1VdmfuJR8jniz3V+7pnMmYSJK2AnsSpJCJO2xwA52s7HQt8uHEfMEqCccM9+ly7Tc FnbR+uPv2eVeQkWcLcsCIPAPfsESSazDPkxzqE9GN5itzbOO0Vqcjj3suHy4f9L0gnn3 c2BqtB93StV34oujEEGsu4AkjqRIWirxgCe0ZsbZeYV8os+t4ZQBuY0pRzlXzADG6Vs2 HhUpv+GlLVt2WgK8D+KMzkvAeOJWQ7ee2JJIISBj0FtdcKgZsi11M0du1mUitI9bfGJA rSWe9MEqbtWxNBBfNVbvWTs2ZePpfVLA8cJY/teBD0P2ebylLbLutjNNqx4kUJBxOfJ+ IW1w== X-Gm-Message-State: AOAM533sGUeR8KJby++o6KbZMXE1afYw/6NAuWCvDKonmaWAo3fsrQRB FCKaCebdR9UyeGQ+H2lcFnbYNGYyIk7Bdt+HM80= X-Received: by 2002:a1c:a784:: with SMTP id q126mr4265262wme.38.1599669856844; Wed, 09 Sep 2020 09:44:16 -0700 (PDT) Received: from lmecxl0524.lme.st.com ([2a04:cec0:100d:d03f:c9d0:c7b0:9925:5cde]) by smtp.gmail.com with ESMTPSA id t15sm4468301wmj.15.2020.09.09.09.44.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 09:44:16 -0700 (PDT) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Simon Glass , Lukasz Majewski , Peng Fan , Sudeep Holla , Etienne Carriere Subject: [PATCH v4 3/8] firmware: scmi: support Arm SMCCC transport Date: Wed, 9 Sep 2020 18:44:02 +0200 Message-Id: <20200909164407.14327-3-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200909164407.14327-1-etienne.carriere@linaro.org> References: <20200909164407.14327-1-etienne.carriere@linaro.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean This change implements a SMCCC transport for SCMI exchanges. This implementation follows the Linux kernel as references implementation for SCMI message processing, using the SMT format for communication channel meta-data. Use of SMCCC transport in SCMI FDT bindings are defined in the Linux kernel DT bindings since v5.8. SMCCC with SMT is implemented in OP-TEE from tag 3.9.0 [2]. Links: [2] https://github.com/OP-TEE/optee_os/commit/a58c4d706d23 Signed-off-by: Etienne Carriere Cc: Simon Glass Cc: Peng Fan Cc: Sudeep Holla --- Changes in v4: - Update CONFIG_SCMI_FIRMWARE dependencies regarding CONFIG_ARM_SMCCC. - Remove useless cast hence remove helper dev2agent() to get dev private. - Fix header file inclusion ordering. Changes in v3: - This is a followup of the SCMI agent patches posted in https://patchwork.ozlabs.org/project/uboot/list/?series=196253 The v3 splits commits and introduces a new uclass as requested. - This patch implements the same Arm SMCCC SCMI agent as presented in v2 but in its own source file smccc_agent.c, and based in smt.h. --- drivers/firmware/scmi/Kconfig | 6 +- drivers/firmware/scmi/Makefile | 1 + drivers/firmware/scmi/smccc_agent.c | 89 +++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 drivers/firmware/scmi/smccc_agent.c -- 2.17.1 Reviewed-by: Simon Glass diff --git a/drivers/firmware/scmi/Kconfig b/drivers/firmware/scmi/Kconfig index c501bf4943..c3a109beac 100644 --- a/drivers/firmware/scmi/Kconfig +++ b/drivers/firmware/scmi/Kconfig @@ -2,7 +2,7 @@ config SCMI_FIRMWARE bool "Enable SCMI support" select FIRMWARE select OF_TRANSLATE - depends on SANDBOX || DM_MAILBOX + depends on SANDBOX || DM_MAILBOX || ARM_SMCCC help System Control and Management Interface (SCMI) is a communication protocol that defines standard interfaces for power, performance @@ -15,5 +15,5 @@ config SCMI_FIRMWARE Communications between agent (client) and the SCMI server are based on message exchange. Messages can be exchange over tranport - channels as a mailbox device with some piece of identified shared - memory. + channels as a mailbox device or an Arm SMCCC service with some + piece of identified shared memory. diff --git a/drivers/firmware/scmi/Makefile b/drivers/firmware/scmi/Makefile index d22f53efe7..2f782bbd55 100644 --- a/drivers/firmware/scmi/Makefile +++ b/drivers/firmware/scmi/Makefile @@ -1,4 +1,5 @@ obj-y += scmi_agent-uclass.o obj-y += smt.o +obj-$(CONFIG_ARM_SMCCC) += smccc_agent.o obj-$(CONFIG_DM_MAILBOX) += mailbox_agent.o obj-$(CONFIG_SANDBOX) += sandbox-scmi_agent.o diff --git a/drivers/firmware/scmi/smccc_agent.c b/drivers/firmware/scmi/smccc_agent.c new file mode 100644 index 0000000000..85dbf9195e --- /dev/null +++ b/drivers/firmware/scmi/smccc_agent.c @@ -0,0 +1,89 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2020 Linaro Limited. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "smt.h" + +#define SMCCC_RET_NOT_SUPPORTED ((unsigned long)-1) + +/** + * struct scmi_smccc_channel - Description of an SCMI SMCCC transport + * @func_id: SMCCC function ID used by the SCMI transport + * @smt: Shared memory buffer + */ +struct scmi_smccc_channel { + ulong func_id; + struct scmi_smt smt; +}; + +static int scmi_smccc_process_msg(struct udevice *dev, struct scmi_msg *msg) +{ + struct scmi_smccc_channel *chan = dev_get_priv(dev); + struct arm_smccc_res res; + int ret; + + ret = scmi_write_msg_to_smt(dev, &chan->smt, msg); + if (ret) + return ret; + + arm_smccc_smc(chan->func_id, 0, 0, 0, 0, 0, 0, 0, &res); + if (res.a0 == SMCCC_RET_NOT_SUPPORTED) + ret = -ENXIO; + else + ret = scmi_read_resp_from_smt(dev, &chan->smt, msg); + + scmi_clear_smt_channel(&chan->smt); + + return ret; +} + +static int scmi_smccc_probe(struct udevice *dev) +{ + struct scmi_smccc_channel *chan = dev_get_priv(dev); + u32 func_id; + int ret; + + if (dev_read_u32(dev, "arm,smc-id", &func_id)) { + dev_err(dev, "Missing property func-id\n"); + return -EINVAL; + } + + chan->func_id = func_id; + + ret = scmi_dt_get_smt_buffer(dev, &chan->smt); + if (ret) { + dev_err(dev, "Failed to get smt resources: %d\n", ret); + return ret; + } + + return 0; +} + +static const struct udevice_id scmi_smccc_ids[] = { + { .compatible = "arm,scmi-smc" }, + { } +}; + +static const struct scmi_agent_ops scmi_smccc_ops = { + .process_msg = scmi_smccc_process_msg, +}; + +U_BOOT_DRIVER(scmi_smccc) = { + .name = "scmi-over-smccc", + .id = UCLASS_SCMI_AGENT, + .of_match = scmi_smccc_ids, + .priv_auto_alloc_size = sizeof(struct scmi_smccc_channel), + .probe = scmi_smccc_probe, + .ops = &scmi_smccc_ops, +};