From patchwork Fri May 13 06:26:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 572073 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:66c4:0:0:0:0 with SMTP id x4csp198090mal; Thu, 12 May 2022 23:30:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3KXUi79BIzyvD37iR+lPMFIvGTEagXB66ZoWadCQ3HDVmjJaWEl7jkBionyCCKuS2Km2B X-Received: by 2002:a17:907:2d24:b0:6f4:3152:3d1a with SMTP id gs36-20020a1709072d2400b006f431523d1amr2870842ejc.324.1652423416940; Thu, 12 May 2022 23:30:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652423416; cv=none; d=google.com; s=arc-20160816; b=nj9beV4RLP9uOCE4xmnNYC7HNjnU6ltmVRqyVdye8KPidtiMFWtqV7lhEuadsTESIu nwE6IEawHGH6CDCysa+a3CK6E2CkL4NkKiUqJLIuFLs5GzwrpOlZKeZMyMAF4oYoBsRV dVs09DII798duIzm8vn/0+9UqAWlMckq5WIgQnOBhcJImVk+/DaR787O0jLOtnw0XfzP n8V9Zn6rnP2qme8vqgeCvqTJH4xekW9rTAmY/OMZ9bs+0F5gm6z6LtyMZ4aT0xV81W/q A3vfVyCR4VgsIB1fURdGHWGp4HU/R+5XaInyv1ELpT3TOUdY5fWLBA13L6u5QVaQKTAE Ltgg== 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=ZzPYYKXq07NjOsbh/QsTJ+bAeJ/a0q0aVDyUvSJeXiI=; b=GvFU5GdElSxT/ME3y0dG/lQQC4I9WFd8XP8t5tuD2wpXBuKrePZTSDctDZ3gKEOXMe Q8wGBIf5ihu6XOTQ5E8BFCnXjAq3aEH8q40iWeTtX3LYSdKM8ghyNw5vRCCbKKjcHAPh 2U/N7LZV+gkEWuX3XuYWZZgNLj5co0xvR+jTsf4unUxORh9CDZaoX53SLXjtrDG9Rg2U TRQKZBX2Mmd+a6j/xqfEOWgeSa6VIw1mxa8yeWmilhft78ShWEn4pcgU0J5opObrzBwL XenNVNwmpdisVhYTRUOJPAeZtYOOmknPrnpsJxRBjPuCrIbbBSstybhNEzJECACpw59R OIew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qTRL4buU; 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 oz14-20020a1709077d8e00b006f3bb6fe60asi1418387ejc.275.2022.05.12.23.30.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 23:30:16 -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=qTRL4buU; 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 E0FEC83F53; Fri, 13 May 2022 08:29:03 +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="qTRL4buU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1A7DD83EE0; Fri, 13 May 2022 08:28:39 +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-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) (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 4A08483E43 for ; Fri, 13 May 2022 08:28:34 +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-x332.google.com with SMTP id k126so4224335wme.2 for ; Thu, 12 May 2022 23:28:34 -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=ZzPYYKXq07NjOsbh/QsTJ+bAeJ/a0q0aVDyUvSJeXiI=; b=qTRL4buUlf42R0HB7WFRAh/0bOi2BUXXI49DU8bShuhfpu9SFZa4oiiPwEvSnwvQ57 qlHdcvCLRRYJWlpZkYiP1t5LPcFoi185Ep4k2kFfk98+r68T7+wYbg+vV8UotVEtqomj oOy1s48IVCEvx7o2miPcLrqwK69kA8vNnbIUkIE+lA2kWqqI+hroP3tgtyGXg8J8t8jm sHYFqDdVPROHbXG+mYWqHVeTvMKLKR6RT480AYu5s+KyJ8SCcqUzBoWT+vTzX4gNNjVZ IBFrqVXEdSUXF3w2WWC20bZjqw2PqG3OI35I8IohtRHxnkgbfXFPqMQuLCDDl2W5jHV+ ruOQ== 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=ZzPYYKXq07NjOsbh/QsTJ+bAeJ/a0q0aVDyUvSJeXiI=; b=qbmBL/hKbx9BpUHeYSTUwCjThyZC91cxotTcXkhSwbVh5EwURxi6prdp7z9TRV/XEM r258F1nJGbBur6lY64Kz1IJCMrzAzeXGfOOQkLaVf43Wp4/Cr3/+1BpzJf5gL9RU46Us D7tfQb3PWy0/8vVMyY3Eh7Cq5syE0IVDV1f0Ocsevx+AlKhGlmUc5u1WyNVTs399UTQb Q1ODWH1pNLdxqoGW90q0yoCHYCJzwCte31OwXGPCWMT2+TbmsKM57cBkZ4g3YRb1+nEX OSAnXss4NVplro3gwytfiuRcVBsqi5VU2SM6v5Ts0udP25n95Ab3DoGmaXTJrNBVvaic adSg== X-Gm-Message-State: AOAM533f4oHCWvFFt6GbFd2fF/d3alKsc4OtEBEHsp0DKECkEFOL6LLb xB+Zj6PG0rhk965vi+stntf2ryp3RnphUg== X-Received: by 2002:a05:600c:4e91:b0:394:8d30:d6dd with SMTP id f17-20020a05600c4e9100b003948d30d6ddmr2983353wmq.21.1652423313436; Thu, 12 May 2022 23:28:33 -0700 (PDT) Received: from lmecxl1178.lme.st.com ([2a04:cec0:1194:a3aa:dc31:6fc0:bd75:771a]) by smtp.gmail.com with ESMTPSA id s18-20020a7bc0d2000000b003942a244eebsm1414235wmh.48.2022.05.12.23.28.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 23:28:33 -0700 (PDT) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Patrick Delaunay , Patrice Chotard , Etienne Carriere Subject: [PATCH 09/14] firmware: scmi: optee transport: implement multi-channel Date: Fri, 13 May 2022 08:26:17 +0200 Message-Id: <20220513062622.155433-10-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220513062622.155433-1-etienne.carriere@linaro.org> References: <20220513062622.155433-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 --- 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, };