From patchwork Tue May 31 16:09:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 577454 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:330b:0:0:0:0 with SMTP id f11csp1301712mag; Tue, 31 May 2022 09:11:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwaXOLDVF8TMCB+oXD0oMz39mk9QK0+3A+VDkP+1y8vPE4u6SGBbgvRa73mfmFv4EA7EVii X-Received: by 2002:a02:a70b:0:b0:32e:2457:6a44 with SMTP id k11-20020a02a70b000000b0032e24576a44mr32206062jam.232.1654013489510; Tue, 31 May 2022 09:11:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654013489; cv=none; d=google.com; s=arc-20160816; b=tQmOCPB3j53nfwWfiurg+xTXAodQWpjjvihb+Vaa/l6Si0BFlIjIG3jTFqOqqrMwC1 nQYL0YaEK4objmbIe9kljyRaw8la9+u5NXWK9t5ADUIQ7/kibeDKV8PfLQBjHwaSXTG8 sCf2m3d7PLWbDDFQRfN+C0pKeUxlMmwQT3QF0NDxFIb6FvJZSBK0NEuMCx8jihtYFqE+ p52Y9zPQuX5Hzmmb9a3njazcGtnMuh9ntdEl+Y9Zf4Xh60Q0XuulWU4vbk7oR/2VPSum ZSYCuKbnEbD2KtR9qXDIj+jxwAsCXDlODM0D8+fPUDTZaz6oPDAWEGcHdG5SiwcwDJAl dUAA== 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=VmQ+NBzdBbI1MtBJIweUrEcpTgG/Mb6wMhltSYi2ho8=; b=MouI+/HOMHv43t2ZFe/K6c5rOHsM77oSxQXFvnELuoifodDk4yps3hvuRw2KMpnEqY qS9vtMDoQIjLUs1wt4IZ9TvxJVuvYe3OXc1qn29Ll3/R+fdd6Oiv1hTA1LIgFwJlIQ7t x8Fe5Gftg1ZBHrGz7+FBMMV/WC7TykIZav2gjB+YjF4Olq/OvIJMblJ3uqutnqoioQOl GeD1bmzjJN2/nIuQ3Dmk9lZU6ftFJ+gGTulD8D0WHSHE6b/SMYvE5L8h15t+J6DDC29P Giv3fU8dqeas3GmqcAbCxdWKQZsI0XyPpt6LR+dB9dYFTIIDdB82y23rbaErYW7Lssbi ju+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DBQkSWix; 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 n123-20020a6bbd81000000b00660cf61c704si17747944iof.1.2022.05.31.09.11.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 May 2022 09:11:29 -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=DBQkSWix; 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 0490E842AE; Tue, 31 May 2022 18:10:28 +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="DBQkSWix"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 17C8C83E63; Tue, 31 May 2022 18:09:55 +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-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) (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 7FC9583E43 for ; Tue, 31 May 2022 18:09: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=etienne.carriere@linaro.org Received: by mail-wm1-x335.google.com with SMTP id d5-20020a05600c34c500b0039776acee62so1172049wmq.1 for ; Tue, 31 May 2022 09:09:46 -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 :mime-version:content-transfer-encoding; bh=VmQ+NBzdBbI1MtBJIweUrEcpTgG/Mb6wMhltSYi2ho8=; b=DBQkSWix76ktdftAqnxPxsmCVXY+qrZ1fqkS6FkJI9SONgZZQgpCgnvabMKBl8KgaP scnrAjV1r57RqmtEycdvdOPRWsw33c5nWSQkaqsoh3i/6NXswLeOpYVRXTvAVTO+LeDj 5deIcbUT+ESV2WXtTPraFTgQUynT0HFvXXZ3WpuIlc4gsU0A2MzpVMjNoEKMu/wzC6NS Zf/Chm1B8JwacVDFOxPXw5mMpDQFT4LCaF56oX7P4u1tmFb0U0SD1eZC3Os6OOwp8Mm8 m7Exr9WdG6+jbBdu7UorRH8GkK/vDLEQLW37El71C7Fu2TJ/cRD/ylBBzO+CK7nWAvn3 fJ0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VmQ+NBzdBbI1MtBJIweUrEcpTgG/Mb6wMhltSYi2ho8=; b=rSRU7koXjZ+91tayvGSkIc/iL6u9tJIMEE+noPmvQ9O9eXgHI95dMaz5awKikm4GjG +mvkjr4n/IbOkmTIPFJ9ZGZvsPbP1UIE/4k+JRZCUem294r3Fmkgg88OCZkA3QEDWVd/ a5OdKKZV0CcdI0AeuGFW+x++UtpPtZFKDCP/QfV2DABQWm1WhGW3t5b5IVnygW77zqm8 /y/qcgdzRaoFqsHBP+UgqnhzjVn3alva1oiKeOP8FDm+qRE2YCrfd9YB2xWpfPY8UnmT 8N1ktUTHtout82vEl/PlsWXLuXtoI48Rzx2/+lYBkok8qsCPLo8IMgqdLimZjYt1F7/i t9fA== X-Gm-Message-State: AOAM533EA3Hq2/b/5s82BvBCrc65Fhql0fvphMILzKimI7TfIjCZWJ4+ quGjxB1887+VMTrBcMAheW89DsK2HlskIA== X-Received: by 2002:a05:600c:2e15:b0:39c:10cd:50d0 with SMTP id o21-20020a05600c2e1500b0039c10cd50d0mr9626189wmf.170.1654013385852; Tue, 31 May 2022 09:09:45 -0700 (PDT) Received: from lmecxl1178.lme.st.com ([2a04:cec0:117a:a94e:9569:2e63:8a35:2cc5]) by smtp.gmail.com with ESMTPSA id r23-20020a05600c321700b0039aa4d054f8sm2884035wmp.5.2022.05.31.09.09.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 May 2022 09:09:45 -0700 (PDT) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Patrick Delaunay , Patrice Chotard , etienne.carriere@linaro.org Subject: [PATCH v2 09/14] firmware: scmi: optee transport: implement multi-channel Date: Tue, 31 May 2022 18:09:24 +0200 Message-Id: <20220531160929.931150-10-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220531160929.931150-1-etienne.carriere@linaro.org> References: <20220531160929.931150-1-etienne.carriere@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.5 at phobos.denx.de X-Virus-Status: Clean Implements multi SCMI channel support in OP-TEE SCMI transport. An SCMI protocol may use a dedicated channel, specified by the DT. Signed-off-by: Etienne Carriere --- No change since v1. --- drivers/firmware/scmi/optee_agent.c | 76 ++++++++++++++++++++++++----- 1 file changed, 63 insertions(+), 13 deletions(-) diff --git a/drivers/firmware/scmi/optee_agent.c b/drivers/firmware/scmi/optee_agent.c index 771fa25e989..da5c2ec9754 100644 --- a/drivers/firmware/scmi/optee_agent.c +++ b/drivers/firmware/scmi/optee_agent.c @@ -35,6 +35,14 @@ struct scmi_optee_channel { bool dyn_shm; }; +/** + * struct scmi_channel - Channel instance referenced in SCMI drivers + * @ref: Reference to local channel instance + **/ +struct scmi_channel { + struct scmi_optee_channel ref; +}; + /** * struct channel_session - Aggreates SCMI service session context references * @tee: OP-TEE device to invoke @@ -132,10 +140,10 @@ enum optee_smci_pta_cmd { #define PTA_SCMI_CAPS_MASK (PTA_SCMI_CAPS_SMT_HEADER | \ PTA_SCMI_CAPS_MSG_HEADER) -static int open_channel(struct udevice *dev, struct channel_session *sess) +static int open_channel(struct udevice *dev, struct scmi_optee_channel *chan, + struct channel_session *sess) { const struct tee_optee_ta_uuid uuid = TA_SCMI_UUID; - struct scmi_optee_channel *chan = dev_get_plat(dev); struct tee_open_session_arg sess_arg = { }; struct tee_invoke_arg cmd_arg = { }; struct tee_param param[1] = { }; @@ -187,10 +195,9 @@ static void close_channel(struct channel_session *sess) tee_close_session(sess->tee, sess->tee_session); } -static int invoke_cmd(struct udevice *dev, struct channel_session *sess, - struct scmi_msg *msg) +static int invoke_cmd(struct udevice *dev, struct scmi_optee_channel *chan, + struct channel_session *sess, struct scmi_msg *msg) { - struct scmi_optee_channel *chan = dev_get_plat(dev); struct tee_invoke_arg arg = { }; struct tee_param param[3] = { }; int ret; @@ -237,9 +244,9 @@ static int invoke_cmd(struct udevice *dev, struct channel_session *sess, return ret; } -static int prepare_shm(struct udevice *dev, struct channel_session *sess) +static int prepare_shm(struct udevice *dev, struct scmi_optee_channel *chan, + struct channel_session *sess) { - struct scmi_optee_channel *chan = dev_get_plat(dev); int ret; /* Static shm is already prepared by the firmware: nothing to do */ @@ -274,15 +281,19 @@ static int scmi_optee_process_msg(struct udevice *dev, struct channel_session sess = { }; int ret; - ret = open_channel(dev, &sess); + /* Support SCMI drivers upgraded to of_get_channel operator */ + if (channel) + chan = &channel->ref; + + ret = open_channel(dev, chan, &sess); if (ret) return ret; - ret = prepare_shm(dev, &sess); + ret = prepare_shm(dev, chan, &sess); if (ret) goto out; - ret = invoke_cmd(dev, &sess, msg); + ret = invoke_cmd(dev, chan, &sess, msg); release_shm(dev, &sess); @@ -292,9 +303,8 @@ out: return ret; } -static int scmi_optee_of_to_plat(struct udevice *dev) +static int setup_channel(struct udevice *dev, struct scmi_optee_channel *chan) { - struct scmi_optee_channel *chan = dev_get_plat(dev); int ret; if (dev_read_u32(dev, "linaro,optee-channel-id", &chan->channel_id)) { @@ -316,13 +326,52 @@ static int scmi_optee_of_to_plat(struct udevice *dev) return 0; } +static int scmi_optee_get_channel(struct udevice *dev, + struct scmi_channel **channel) +{ + struct scmi_optee_channel *base_chan = dev_get_plat(dev->parent); + struct scmi_optee_channel *chan; + u32 channel_id; + int ret; + + if (dev_read_u32(dev, "linaro,optee-channel-id", &channel_id)) { + /* Uses agent base channel */ + *channel = container_of(base_chan, struct scmi_channel, ref); + + return 0; + } + + /* Setup a dedicated channel */ + chan = calloc(1, sizeof(*chan)); + if (!chan) + return -ENOMEM; + + ret = setup_channel(dev, chan); + if (ret) { + free(chan); + return ret; + } + + *channel = container_of(chan, struct scmi_channel, ref); + + return 0; +} + +static int scmi_optee_of_to_plat(struct udevice *dev) +{ + struct scmi_optee_channel *chan = dev_get_plat(dev); + + return setup_channel(dev, chan); +} + static int scmi_optee_probe(struct udevice *dev) { + struct scmi_optee_channel *chan = dev_get_plat(dev); struct channel_session sess; int ret; /* Check OP-TEE service acknowledges the SCMI channel */ - ret = open_channel(dev, &sess); + ret = open_channel(dev, chan, &sess); if (!ret) close_channel(&sess); @@ -335,6 +384,7 @@ static const struct udevice_id scmi_optee_ids[] = { }; static const struct scmi_agent_ops scmi_optee_ops = { + .of_get_channel = scmi_optee_get_channel, .process_msg = scmi_optee_process_msg, };