From patchwork Mon Sep 7 14:49:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 249224 Delivered-To: patch@linaro.org Received: by 2002:a92:5b9c:0:0:0:0:0 with SMTP id c28csp3763302ilg; Mon, 7 Sep 2020 07:54:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTg5c7lVBkHIweo2x2zbFuQUpFzlnhvEdxExuGFsp30QUuBRrI9Or/T86jNgiODa7Vfyte X-Received: by 2002:a17:906:3785:: with SMTP id n5mr22754352ejc.218.1599490476478; Mon, 07 Sep 2020 07:54:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599490476; cv=none; d=google.com; s=arc-20160816; b=nbsgHsj/hfzKw8G419tNiIHCQLfWO3UK+EHDBRaSZHoSECkUBDePuUEK/aa72Is/v1 PdoWA1RYA+QfCvWWhLOie1OcrzBKwMkxldKPg/B2EQH2DPECIN/uI8l8RioTppSiKSz5 6vVeWUKjt+FV8uVcFTTbxAfEQNkH8XzaLqpKQbfpdo1/cVXtzPBpqnQlLC7fHp2566/o 4zjxtVFkzVC+H7XwMBbIQdZ/3qfycn9FodY6hQrzRCM0jacCYZj455O8YmZge3tFE+db T4TE0JD+YgjjWgCwmdG7Y8pgdTazz2KarkhiJXtABPyLzWS7uiKkTPnkOwaQSeMH6k7F pjog== 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=1LX+BKepia8BYQEkxinqN8WxnCKd17DC8akumlC1os8=; b=MJXfYFA/zeHLVRIWib+we1/PpRI6CbUD0AUvWsbje98q13x2aDUuUHwJWfa0rtG8N9 InLLpn3kXZtBe4fE0FvA38mibbFMZWjEoQULKRv4A5VuJEY6/5r1hmK6wpwXYCs48ehY 3IOrmU3PoD0LHrm2AnOgH3w+mpQHCS45e9Zme7U9SIul3uMazBIXHU5HdZ1Wyc6W8lrS PI/X2jQnpdy6i+zqGqqdpcFdIXnuIdu14eHsVw9Fy31A4IJ7DV/fsLSjXNb5lwbWLDO4 b5jgHhKMQvLk5iQt+Tqcn9ByCjCxwAQmKCqFP+WScO0Csrks5vKW75igLOQ0pa+rpAmb w1XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RVUss+Eo; 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 u20si10222072ejz.602.2020.09.07.07.54.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 07:54:36 -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=RVUss+Eo; 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 A29F582518; Mon, 7 Sep 2020 16:50:22 +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="RVUss+Eo"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EF147824F2; Mon, 7 Sep 2020 16:50:20 +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,T_SPF_HELO_TEMPERROR,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) (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 A098E82497 for ; Mon, 7 Sep 2020 16:50:09 +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-x343.google.com with SMTP id e11so12479619wme.0 for ; Mon, 07 Sep 2020 07:50:09 -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=1LX+BKepia8BYQEkxinqN8WxnCKd17DC8akumlC1os8=; b=RVUss+Eojs9G7BbsWuJ3gbTais/Li/8mhWu/ukHW/W1YYUc4oBkKnda4+x7YPFRYuq QM5ytjcpufQP1azTgXAdVVVcWakqgZVrZCCn4F1raBsiyRxNT/04tzObA4hlkOEZ0lyb 5xySfA2L1fw+UShWhSc/SZAbzigryJzkuHZHZbCgV15Z4kPQ3yo9FvNVhhy9s/AwjBXz 4pPO8SRA0BsFBz7goKOgWoKFmeIwRKrpXJ8XqqAtpBJTKouzeFar5+7ap84JwEVgXReP bqGinBLX57wBkLwSIiAFlvosHH+Mf3UbCVkuUZ5F0iN9m0wl41+m6767QLnnJpHIPp9F 3r1Q== 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=1LX+BKepia8BYQEkxinqN8WxnCKd17DC8akumlC1os8=; b=GQT0T3o8JA6k7sOJTAlxr5kIuaRdY7W/a80H/lfFhWnBAi/rNdElJzMQSgaYNoRafs pMHk61xn8/FBCGWGzQ8OXhaGzk4UvjqgA0x3PCqPkbxAUEQE97nIPD+VXzYl2wnm7N75 w7F/3BhNVTX/TK9f2hMFuILU4IVmJmIACzy9AotK0PnD12kqM7ITbiehu/TXA+mYtMpw 17gPbi30/doqH9Bp613DlXvUi3tBlu4UJf5A/87otE49Kzb2dDDk5bD9wfc3jquc2y9u Qtyi9a5yfY60jB7JmyXPLMvPK/gkyLio57VcVH9nR7wzPKyult0Wx4jDYBMyBRSeOGYE DhKA== X-Gm-Message-State: AOAM533cyvgY+U13KyzvH6TihcXW7LRhnkwfxmV1KHXCdRi98YSgZYBD fCFOqM63wRgq+YsQ0nV+iWJ5nAtcyYyez0jv X-Received: by 2002:a05:600c:2118:: with SMTP id u24mr6703353wml.59.1599490209113; Mon, 07 Sep 2020 07:50:09 -0700 (PDT) Received: from lmecxl0524.home (2a01cb058b850800c83354e95cb75046.ipv6.abo.wanadoo.fr. [2a01:cb05:8b85:800:c833:54e9:5cb7:5046]) by smtp.gmail.com with ESMTPSA id f19sm27484388wmh.44.2020.09.07.07.50.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 07:50:08 -0700 (PDT) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Simon Glass , Lukasz Majewski , Peng Fan , Sudeep Holla , Etienne Carriere Subject: [PATCH v3 3/8] firmware: scmi: support Arm SMCCC transport Date: Mon, 7 Sep 2020 16:49:55 +0200 Message-Id: <20200907145000.30587-3-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200907145000.30587-1-etienne.carriere@linaro.org> References: <20200907145000.30587-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 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 | 4 +- drivers/firmware/scmi/Makefile | 1 + drivers/firmware/scmi/smccc_agent.c | 95 +++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 2 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..335d09c821 100644 --- a/drivers/firmware/scmi/Kconfig +++ b/drivers/firmware/scmi/Kconfig @@ -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..90707710e2 --- /dev/null +++ b/drivers/firmware/scmi/smccc_agent.c @@ -0,0 +1,95 @@ +// 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 struct scmi_smccc_channel *scmi_smccc_get_priv(struct udevice *dev) +{ + return (struct scmi_smccc_channel *)dev_get_priv(dev); +} + +static int scmi_smccc_process_msg(struct udevice *dev, struct scmi_msg *msg) +{ + struct scmi_smccc_channel *chan = scmi_smccc_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 = scmi_smccc_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, +};