From patchwork Tue Jun 7 10:21: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: 579316 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5806:0:0:0:0 with SMTP id j6csp4917037max; Tue, 7 Jun 2022 03:22:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyA9VpFauI0t2LTY80KTRmevbrIyNtqRoXYb/rTKSIHTg5RVuoICvxZuS0qiX/fnhj6WNNf X-Received: by 2002:a05:6602:27cd:b0:669:3d8d:4d77 with SMTP id l13-20020a05660227cd00b006693d8d4d77mr6982402ios.216.1654597357265; Tue, 07 Jun 2022 03:22:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654597357; cv=none; d=google.com; s=arc-20160816; b=xhd1PkpxIFSQHA9/jcgm4gBBCmm4wfULcVT/A1lJyJ5GXcbhcIuwZIvv3bBgQvStny ziIsOzNTuqHITGB7kx3PKKixoFG+iyRZ0XEg6WdxpYgGF878/3oVbppvApyKzDDITNci 0uFHUbu2RQpzscCcnqZwSMG9zmWTsu7rCTn7SyQFTc5AuEUxkqt/yiakptWUBhwmSWMk nSFLmHjrAP+Zf2p9PyBRHe6F7zTD6FBvfLzG11HN9uGn/hHchH9ZGgVJYwarlrskupS5 +ahRb2MnDM6WJa8M1/fqNBM8NKp+iGxlhAyI/dCmKM8uaKLovKnlIhvenbJ5evxjao/l lCAw== 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:message-id:date:subject:cc:to:from:dkim-signature; bh=/YkO9B2tSZZ2QjAj0Bt97FwadVx4RySY8/ATpvvmJUI=; b=RlLCkHBQjdILPaKCwxOBrxSn2hIL/yRc5Vklw+dxue5RLhUD5KhzZzi9BT6mvBfk4o 1DTO7Hp6Krlqls4nzkWATrgc1bUgWF1PfkKhBVktyxtTs/CbsLSeAdDZoJyz0ph8XA/6 nE39rNkgET2ZSfa2m3jsFVOaIa+uHelO6Xp9qq2DD4scr0qnYrk+P/5IzfrtOb6lJUOT UbFxg4Y7YZ2OrkYxXEZLtzyAGrWQfpmnPFmuZpokFLaAWTqiVV64NRoQPnCnNsum1qhT 1Oh6DLLgvsvVBtmT0bVQCK7saRBsgpDBqQrLttYMZly0ZnWXtOtjiqQT/AfnqVDaR+mf IGzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fBdCrGzX; 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 p11-20020a056e0206cb00b002d152cc99c2si16924715ils.167.2022.06.07.03.22.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 03:22:37 -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=fBdCrGzX; 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 3B6EB842EA; Tue, 7 Jun 2022 12:22: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="fBdCrGzX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E641684343; Tue, 7 Jun 2022 12:22:28 +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-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) (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 32DC0805FE for ; Tue, 7 Jun 2022 12:22: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=etienne.carriere@linaro.org Received: by mail-wm1-x330.google.com with SMTP id r123-20020a1c2b81000000b0039c1439c33cso9268447wmr.5 for ; Tue, 07 Jun 2022 03:22:26 -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:mime-version :content-transfer-encoding; bh=/YkO9B2tSZZ2QjAj0Bt97FwadVx4RySY8/ATpvvmJUI=; b=fBdCrGzX/y1CSwwqKR2SGpAWoE55w0EtDHRq3C3rtUEui+W7sCnpYbPntM+rvZXFXA XpUF6O5LdfMGRgFDGkbCSB+zgezdftAM4JiHwBqrPNG9wmU2Fqe3ja6LGNdt+cFAMjsZ XXKxjZcunyCrE2W/g3c4fPCTT0v8MDeZmh86RAhItADSWpzCnz1cxKly6cXU4Iq4Zx5p ZQYi5L/JXSqHKuKWLeBm/17BnQgTwfWcAAOHwcsBxTU1IOxQJYcG0lYFbRuqwb0lLv+9 rcnNvqSfDX+BJncroxpl6lEeEjGgFscWTg2OXnLxN2k8D24NTh2DshKl3E6Sq/GG7xoD ZFSQ== 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:mime-version :content-transfer-encoding; bh=/YkO9B2tSZZ2QjAj0Bt97FwadVx4RySY8/ATpvvmJUI=; b=rjuKqZMuv4RL1LNJyCOqBfiqPqMtkKHqBjJgWoLQn9mR1wMtICbK7tgZ6hjbhDsoSX PRwY4eTLj9oiSqVgKWH15NraO0JRkXxZK8lrrbEXarujNKiYohcyhPBFRCk6OwBy6XHI bzXiUlg9QSxXE2BqLiPSwLK/lTp0fowPym8aOcARsjOXuIf7oVQamekBGizht0tvEtjv 95ULoRgNRpdBXX6CBfcetYDf8Xn95exfW3A/BbIoVbJCwDn8+tHzBGXoaBR07Bslrsl6 biMuq2hhIl6Ilji9dT/kPd4d6SaNdMKzrnC1OXnVto5IBNssYIU8QMwzeZgjVdVmqZ7X 9SSA== X-Gm-Message-State: AOAM5331LBztQaZOPxfMbE9HxcYKywpdIJHQihThKs7EIfrXB0xMlPd9 1mzAb3VURYbLMI7Xw1sPQ9EJMCtWjuYTVg== X-Received: by 2002:a05:600c:4f04:b0:39c:54bb:28cd with SMTP id l4-20020a05600c4f0400b0039c54bb28cdmr7829038wmq.107.1654597345408; Tue, 07 Jun 2022 03:22:25 -0700 (PDT) Received: from lmecxl1178.lme.st.com ([2a04:cec0:1181:a1da:3be2:1ef1:b537:8871]) by smtp.gmail.com with ESMTPSA id k7-20020a5d6d47000000b0020e5e906e47sm17373273wri.75.2022.06.07.03.22.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 03:22:24 -0700 (PDT) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Etienne Carriere , Patrick Delaunay Subject: [PATCH v3 1/3] drivers: tee: optee: remove unused probe local variable Date: Tue, 7 Jun 2022 12:21:24 +0200 Message-Id: <20220607102126.2605773-1-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.25.1 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 Removes local variable child in optee_probe() that is not used. Cc: Patrick Delaunay Signed-off-by: Etienne Carriere Reviewed-by: Patrick Delaunay Reviewed-by: Ilias Apalodimas --- No change since v2. New change not in v1 series. --- drivers/tee/optee/core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c index a89d62aaf0..c1f5fc4c7a 100644 --- a/drivers/tee/optee/core.c +++ b/drivers/tee/optee/core.c @@ -642,7 +642,6 @@ static int optee_probe(struct udevice *dev) { struct optee_pdata *pdata = dev_get_plat(dev); u32 sec_caps; - struct udevice *child; int ret; if (!is_optee_api(pdata->invoke_fn)) { @@ -673,7 +672,7 @@ static int optee_probe(struct udevice *dev) * only bind the drivers associated to the supported OP-TEE TA */ if (IS_ENABLED(CONFIG_RNG_OPTEE)) { - ret = device_bind_driver(dev, "optee-rng", "optee-rng", &child); + ret = device_bind_driver(dev, "optee-rng", "optee-rng", NULL); if (ret) return ret; } From patchwork Tue Jun 7 10:21:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 579318 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5806:0:0:0:0 with SMTP id j6csp4917426max; Tue, 7 Jun 2022 03:23:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxl6OpmO4qay350VLqqSd3p4eA9pWiYF9at0b9NVEPOidD84c4oUEI/hI0N7mruxHV2l50w X-Received: by 2002:a02:cd36:0:b0:331:56a4:7a32 with SMTP id h22-20020a02cd36000000b0033156a47a32mr15285754jaq.209.1654597385456; Tue, 07 Jun 2022 03:23:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654597385; cv=none; d=google.com; s=arc-20160816; b=NMrkh977hdcda+Eanj/rUvP/7lEm3H4TdttaNlOJVLeEekaxpVMYVdaVemXeT2Ocsb rorzkGfUEFtx82f+n9EvNKngHKD2wxe6NpzR7HcjC1w+QlMP/EU06+5d6QEo9HXFb3lC ug2JlgII9qRjMAMS7xEoDcHjDG+S690e1YbaCx1zksEnpJ0wTRQFRnb4FwjW1nBIUD7z lc9Hfcb2ZJ09E7qQVfbpjJWIW2JAK+9WEzapKjTd5qH7XcwVbKJPw6QLIxhn7BAJTrPN LQ+MADVqypUwdocThJXvpdUsDogIPVuCONLfx/PKZyaA+pGrEOCUwHHoF7u84e8fGJ6w 2pGg== 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=82Zvz2g+JT0mKYpRs4JlpZGFz2tLH3HymajgbZR08Bk=; b=AWqrSAUNSEHDdc1YSR8sDh6yd/tBW9uTZPQwKHtAqBT3ZTueQJCabQki2lMtG7SCBc O5Ze8jtozBSpf2QhOv6LWImAlC1F0n52Db3Fzt4rG8r9imvgOkHnnbKBkIlg2J6cf5/Q 2OVoYigk/lMMFqX5yOUca5GsttrlsQNkYXUPrnNMlw7i0rhgWXwDOPf7+JDWkMx9F8uL /3TQNIqB2jHwiAoWKtf9FTjxixFOIjDQPbzNb4T/lQplI/q4/2gx8kcG43Sk1lVWHMJ1 UKV2xJapwWlPttdcVlf/vLK5/vRji5xxabSgfdJBlbOgk17sYuEkxx5NnNuE3d57k+aG Vifg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=anbudd1W; 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 u6-20020a056e02170600b002d3da8d76cfsi21651535ill.156.2022.06.07.03.23.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 03:23:05 -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=anbudd1W; 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 20F5984319; Tue, 7 Jun 2022 12:22:43 +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="anbudd1W"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 54D4C84343; Tue, 7 Jun 2022 12:22:33 +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-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) (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 87A558430F for ; Tue, 7 Jun 2022 12:22:27 +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-wr1-x42d.google.com with SMTP id m26so12052619wrb.4 for ; Tue, 07 Jun 2022 03:22:27 -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=82Zvz2g+JT0mKYpRs4JlpZGFz2tLH3HymajgbZR08Bk=; b=anbudd1WBnvBh+bVCw2bv0yIUniU1x+KCTx8xlZo+EkXJqYbpIEWnovQiAXIm5EeH2 6kLdoMxHfKvZaDItdZnkw8laSV2zpoxezvsROvw/c3oZ3jpFYBITzxzkt2RcUBBJRk16 NwQTWNvx6MC+VwBF/befvAUqBY1z5p6etxOsRHriZvGZxJiv7tzwYnon/YSXJ+2H+XJC Yb540Lsb5v1QMRXJsCEf8KkAqQ/a586xAGsI4J28u956klVDtZ3hXJWcrE5m8JJOcb6X jhFeMFgxQlNrZF+OihDiThOfW3bXgqs1WNZTKOl5bvRKlBXidmpLNcTyG5Q1SBNP5D7R XrIw== 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=82Zvz2g+JT0mKYpRs4JlpZGFz2tLH3HymajgbZR08Bk=; b=v7QoZqYvXg1+6iyJ4NHZdbkbfF/BbRmfZror+WApFCodsq6dTpQu7POdbPzIYs2wZd 3kczzaHgtPSf/QWGawlY+vwpLl96s6cdH2dx01OL9eDH6+h5PNPwPXpEoPFYWlNWDZyB 3pEuuXb4czBdK4weR1L2kff/eTt1Cu0fTwxr2dQPNgbJDTheAFPEGxYqyRSY2xcmfgO/ WlFgoj/mFTOGtr6lLX/WEjqCNM81KGS4TlVXyKW0p3HOlbKITVg+HGz4gtJVErwBpGka Su8Xz4b+PWJFVEJiVV52kiPJKLP3jhS2GbNIhAKzvvFwejIhCF35sJvVCxllq5WuSSEG a87g== X-Gm-Message-State: AOAM5337Ys6HWn5E5o+SRlSSLYcz6GL6BT3Jzk7FFSBaiAqilTS7KBBN M2l0oXK2KTvL+BnMekLRQsCFNVtB2p427Q== X-Received: by 2002:a5d:4886:0:b0:20d:527:f98b with SMTP id g6-20020a5d4886000000b0020d0527f98bmr27685025wrq.70.1654597346702; Tue, 07 Jun 2022 03:22:26 -0700 (PDT) Received: from lmecxl1178.lme.st.com ([2a04:cec0:1181:a1da:3be2:1ef1:b537:8871]) by smtp.gmail.com with ESMTPSA id k7-20020a5d6d47000000b0020e5e906e47sm17373273wri.75.2022.06.07.03.22.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 03:22:26 -0700 (PDT) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Etienne Carriere , Jens Wiklander , Patrick Delaunay Subject: [PATCH v3 2/3] drivers: tee: optee: discover OP-TEE services Date: Tue, 7 Jun 2022 12:21:25 +0200 Message-Id: <20220607102126.2605773-2-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220607102126.2605773-1-etienne.carriere@linaro.org> References: <20220607102126.2605773-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 This change defines resources for OP-TEE service drivers to register themselves for being bound to when OP-TEE firmware reports the related service is supported. OP-TEE services are discovered during optee driver probe sequence which mandates optee driver is always probe once bound. Discovery of optee services and binding to related U-Boot drivers is embedded upon configuration switch CONFIG_OPTEE_SERVICE_DISCOVERY. Cc: Jens Wiklander Cc: Patrick Delaunay Signed-off-by: Etienne Carriere Reviewed-by: Patrick Delaunay --- Changes since v2: - Release allocated shared memory from bind_service_drivers() only. - Remove definition of useless macro OPTEE_SERVICE_DRIVER_GET(). Changes since v1: - Remove all #ifdef CONFIG_OPTEE_SERVICE_DISCOVERY directives and replace with if (IS_ENABLED()) where applicable. - Incidentally rename local function open_session() to open_enum_session() and remove local function close_session() for clarity. - Update commit log to highlight that "optee driver is always probe once bound" when CONFIG_OPTEE_SERVICE_DISCOVERY is enable. --- drivers/tee/optee/Kconfig | 8 ++ drivers/tee/optee/core.c | 171 ++++++++++++++++++++++++++++++++++-- include/tee/optee_service.h | 26 ++++++ 3 files changed, 200 insertions(+), 5 deletions(-) create mode 100644 include/tee/optee_service.h diff --git a/drivers/tee/optee/Kconfig b/drivers/tee/optee/Kconfig index d03028070b..9dc65b0501 100644 --- a/drivers/tee/optee/Kconfig +++ b/drivers/tee/optee/Kconfig @@ -37,6 +37,14 @@ config OPTEE_TA_SCP03 help Enables support for controlling (enabling, provisioning) the Secure Channel Protocol 03 operation in the OP-TEE SCP03 TA. + +config OPTEE_SERVICE_DISCOVERY + bool "OP-TEE service discovery" + default y + help + This implements automated driver binding of OP-TEE service drivers by + requesting OP-TEE firmware to enumerate its hosted services. + endmenu endif diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c index c1f5fc4c7a..41fa615b35 100644 --- a/drivers/tee/optee/core.c +++ b/drivers/tee/optee/core.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "optee_smc.h" #include "optee_msg.h" @@ -22,6 +23,25 @@ #define PAGELIST_ENTRIES_PER_PAGE \ ((OPTEE_MSG_NONCONTIG_PAGE_SIZE / sizeof(u64)) - 1) +/* + * PTA_DEVICE_ENUM interface exposed by OP-TEE to discover enumerated services + */ +#define PTA_DEVICE_ENUM { 0x7011a688, 0xddde, 0x4053, \ + { 0xa5, 0xa9, 0x7b, 0x3c, 0x4d, 0xdf, 0x13, 0xb8 } } +/* + * PTA_CMD_GET_DEVICES - List services without supplicant dependencies + * + * [out] memref[0]: List of the UUIDs of service enumerated by OP-TEE + */ +#define PTA_CMD_GET_DEVICES 0x0 + +/* + * PTA_CMD_GET_DEVICES_SUPP - List services depending on tee supplicant + * + * [out] memref[0]: List of the UUIDs of service enumerated by OP-TEE + */ +#define PTA_CMD_GET_DEVICES_SUPP 0x1 + typedef void (optee_invoke_fn)(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, @@ -42,6 +62,134 @@ struct rpc_param { u32 a7; }; +static struct optee_service *find_service_driver(const struct tee_optee_ta_uuid *uuid) +{ + struct optee_service *service; + u8 loc_uuid[TEE_UUID_LEN]; + size_t service_cnt, idx; + + service_cnt = ll_entry_count(struct optee_service, optee_service); + service = ll_entry_start(struct optee_service, optee_service); + + for (idx = 0; idx < service_cnt; idx++, service++) { + tee_optee_ta_uuid_to_octets(loc_uuid, &service->uuid); + if (!memcmp(uuid, loc_uuid, sizeof(uuid))) + return service; + } + + return NULL; +} + +static int bind_service_list(struct udevice *dev, struct tee_shm *service_list, size_t count) +{ + const struct tee_optee_ta_uuid *service_uuid = (const void *)service_list->addr; + struct optee_service *service; + size_t idx; + int ret; + + for (idx = 0; idx < count; idx++) { + service = find_service_driver(service_uuid + idx); + if (!service) + continue; + + ret = device_bind_driver(dev, service->driver_name, service->driver_name, NULL); + if (ret) { + dev_warn(dev, "%s was not bound: %d, ignored\n", service->driver_name, ret); + continue; + } + } + + return 0; +} + +static int __enum_services(struct udevice *dev, struct tee_shm *shm, u32 *shm_size, u32 tee_sess) +{ + struct tee_invoke_arg arg = { }; + struct tee_param param = { }; + int ret = 0; + + arg.func = PTA_CMD_GET_DEVICES; + arg.session = tee_sess; + + /* Fill invoke cmd params */ + param.attr = TEE_PARAM_ATTR_TYPE_MEMREF_OUTPUT; + param.u.memref.shm = shm; + param.u.memref.size = *shm_size; + + ret = tee_invoke_func(dev, &arg, 1, ¶m); + if (ret || (arg.ret && arg.ret != TEE_ERROR_SHORT_BUFFER)) { + dev_err(dev, "PTA_CMD_GET_DEVICES invoke function err: 0x%x\n", arg.ret); + return -EINVAL; + } + + *shm_size = param.u.memref.size; + + return 0; +} + +static int enum_services(struct udevice *dev, struct tee_shm **shm, size_t *count, u32 tee_sess) +{ + size_t shm_size = 0; + int ret; + + ret = __enum_services(dev, NULL, &shm_size, tee_sess); + if (ret) + return ret; + + ret = tee_shm_alloc(dev, shm_size, 0, shm); + if (ret) { + dev_err(dev, "Failed to allocated shared memory: %d\n", ret); + return ret; + } + + ret = __enum_services(dev, *shm, &shm_size, tee_sess); + if (!ret) + *count = shm_size / sizeof(struct tee_optee_ta_uuid); + + return ret; +} + +static int open_enum_session(struct udevice *dev, u32 *tee_sess) +{ + const struct tee_optee_ta_uuid pta_uuid = PTA_DEVICE_ENUM; + struct tee_open_session_arg arg = { }; + int ret; + + tee_optee_ta_uuid_to_octets(arg.uuid, &pta_uuid); + + ret = tee_open_session(dev, &arg, 0, NULL); + if (ret || arg.ret) { + if (!ret) + ret = -EIO; + return ret; + } + + *tee_sess = arg.session; + + return 0; +} + +static int bind_service_drivers(struct udevice *dev) +{ + struct tee_shm *service_list = NULL; + size_t service_count; + u32 tee_sess; + int ret; + + ret = open_enum_session(dev, &tee_sess); + if (ret) + return ret; + + ret = enum_services(dev, &service_list, &service_count, tee_sess); + if (!ret) + ret = bind_service_list(dev, service_list, service_count); + + tee_shm_free(service_list); + tee_close_session(dev, tee_sess); + + return ret; +} + /** * reg_pair_to_ptr() - Make a pointer of 2 32-bit values * @reg0: High bits of the pointer @@ -638,6 +786,14 @@ static int optee_of_to_plat(struct udevice *dev) return 0; } +static int optee_bind(struct udevice *dev) +{ + if (IS_ENABLED(CONFIG_OPTEE_SERVICE_DISCOVERY)) + dev_or_flags(dev, DM_FLAG_PROBE_AFTER_BIND); + + return 0; +} + static int optee_probe(struct udevice *dev) { struct optee_pdata *pdata = dev_get_plat(dev); @@ -667,11 +823,15 @@ static int optee_probe(struct udevice *dev) return -ENOENT; } - /* - * in U-Boot, the discovery of TA on the TEE bus is not supported: - * only bind the drivers associated to the supported OP-TEE TA - */ - if (IS_ENABLED(CONFIG_RNG_OPTEE)) { + if (IS_ENABLED(CONFIG_OPTEE_SERVICE_DISCOVERY)) { + ret = bind_service_drivers(dev); + if (ret) + return ret; + } else if (IS_ENABLED(CONFIG_RNG_OPTEE)) { + /* + * Discovery of TAs on the TEE bus is not supported in U-Boot: + * only bind the drivers associated to the supported OP-TEE TA + */ ret = device_bind_driver(dev, "optee-rng", "optee-rng", NULL); if (ret) return ret; @@ -691,6 +851,7 @@ U_BOOT_DRIVER(optee) = { .of_match = optee_match, .of_to_plat = optee_of_to_plat, .probe = optee_probe, + .bind = optee_bind, .ops = &optee_ops, .plat_auto = sizeof(struct optee_pdata), .priv_auto = sizeof(struct optee_private), diff --git a/include/tee/optee_service.h b/include/tee/optee_service.h new file mode 100644 index 0000000000..527e767e7d --- /dev/null +++ b/include/tee/optee_service.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * (C) Copyright 2022 Linaro Limited + */ + +#ifndef _OPTEE_SERVICE_H +#define _OPTEE_SERVICE_H + +/* + * struct optee_service - Discoverable OP-TEE service + * + * @driver_name - Name of the related driver + * @uuid - UUID of the OP-TEE service related to the driver + * + * Use macro OPTEE_SERVICE_DRIVER() to register a driver related to an + * OP-TEE service discovered when driver asks OP-TEE services enumaration. + */ +struct optee_service { + const char *driver_name; + const struct tee_optee_ta_uuid uuid; +}; + +#define OPTEE_SERVICE_DRIVER(__name) \ + ll_entry_declare(struct optee_service, __name, optee_service) + +#endif /* _OPTEE_SERVICE_H */ From patchwork Tue Jun 7 10:21:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 579317 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5806:0:0:0:0 with SMTP id j6csp4917259max; Tue, 7 Jun 2022 03:22:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJ4rTvP/zPS+YxWZKE/jXNnR61PjdrZN9ln0D0q0ElSNJQxdCzViUzMAtlF/TiCl+kmSFs X-Received: by 2002:a05:6638:3183:b0:330:ea5a:6217 with SMTP id z3-20020a056638318300b00330ea5a6217mr15808734jak.54.1654597372734; Tue, 07 Jun 2022 03:22:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654597372; cv=none; d=google.com; s=arc-20160816; b=WvbGaJGILlPDimqQJYFqTr1cUT/mZapqW6jbyA6buKGiK/ESgKtl1WuwIvsPWyMynk UwjAIYigWkz9CXT7DweaNrnBrXMa9qeXu3kAkhP1MQ4O1BUc9v6me1IxjGQVuZDmTZCJ yIYmsVWN+WiPUpVZ1fSG3CTTGcfCarbCjhwgb+z8lXGdE0XBiUcHf+h6sH9gJnvzr13v 0bph65LufTJGlNBimbma6MyBb+U5dfZxLI0znAgd+4ikqwStCDO9QmvSehYQ7EV7nZIZ qPrm3INgvc6qmehLbAx65tZJ7aikeELhOfd24PYqMsyt4SO37mIMrSTnCedzrrfVCWsx npog== 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=bvEgz1YuhJWcZRjLIkc4JPJiShuz7FUgGtVMvVS951A=; b=gl+eNqiNw0Z7dyH1HNyuQrstDaA6qj4l5B2GySKt73qqq9oBx4G4vr7FDbKhh+tV/f mL4gWBY/5+rdY28kWMaVQ8xmnyJt/mh7U1e9Ll4+qJwxHGK12E2bhjlm7/USV8goG7Ya 90YXDxfMJmK6t3do7qA+VVQXfOqWVu+K5/4sGG/czUTmZNMLpnvOZLY0lsSKKpF4SjX9 1K/RpmCjRUByhs/05x5jNyKAdXW4zDAJhBsQ6PHe5hn1JwF8G8ps8NsZCVTxSOqe4q5Y 7/TBVW+0tm6AMOwWEP8Gw8cEFwt7mdAGen4Z611NTIvg1Q5QB6L4HRuJXI/yIpDfd6Hx 05ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=g14JjiBc; 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 s193-20020a0251ca000000b00331bbce91f4si3605902jaa.149.2022.06.07.03.22.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 03:22:52 -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=g14JjiBc; 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 845288437C; Tue, 7 Jun 2022 12:22:36 +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="g14JjiBc"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CF36F84343; Tue, 7 Jun 2022 12:22:31 +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-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) (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 4F13B842F8 for ; Tue, 7 Jun 2022 12:22: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=etienne.carriere@linaro.org Received: by mail-wr1-x430.google.com with SMTP id u3so23494363wrg.3 for ; Tue, 07 Jun 2022 03:22:28 -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=bvEgz1YuhJWcZRjLIkc4JPJiShuz7FUgGtVMvVS951A=; b=g14JjiBc1m9hzAXyqtRQCySusovfzWXZPY08gE4Hwz/gLeMOETZcU97cB8ygAY1hjg 1I/08kreY00OWxuFps3BcIr85Cc698lx83VY3XOa4nY4sqWW22EVEpyNnnNeb1UPSaJ9 OyhH3DaVll6TYVXHVmMwouoTBgMJVCexmGzHxJpSIiFBs1T1QGznuVkA3CdwENrOw+IJ C0w1D+X02nwdhTCJr7+vvJ1AHDwZSuN1pTICmqzHUHZ0JsiptOtc+VFS7BT7RQ9khfWQ UqbxmY2+60C2036Z7pURSaRCpYy3QJOJQTUBcUmP/xAAHldKpGOq7FNdO6laurX4qHfz hfgA== 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=bvEgz1YuhJWcZRjLIkc4JPJiShuz7FUgGtVMvVS951A=; b=CGQPx4iAMqHLPMa0N9RUDhDeE+MwbaVni7YJzUSFuKi6P2CAEx05KJg75aDSAExSY9 I1vzzcdDJGxxPQZ95b3zys5OlKlMoB1JPBDHEIV6lGi7bqnxJgBl2iUfBLFSbAryto0n ITPIZilFSEMHYHoPfy/tQ8gceeOMdAzjqsB4fapSVs3USi43bEHVhdEVxn5HpVafY39U Lch/MbDtj4HxM17uYChE0uoqsPi/VNmD2aLsvNr03F0jHu6U9iuBf7OPw3NeygOZPolu Nz7XjTD9NlgHXjS3KTs3fgrouipoY19aJ5eO8U1Su8+2HYjEuEAiQBNv2Sa7FbqpnIFA bfIA== X-Gm-Message-State: AOAM533AHUDPWkAu+eFsGqaLaOMwvOGfrz+94ohpQTodbB6ugXvMYXI7 VtwbSKAWtTzLz/eoZKRI85OR5rGcYU+8dg== X-Received: by 2002:adf:d1ed:0:b0:215:98d7:2a93 with SMTP id g13-20020adfd1ed000000b0021598d72a93mr19374722wrd.637.1654597347667; Tue, 07 Jun 2022 03:22:27 -0700 (PDT) Received: from lmecxl1178.lme.st.com ([2a04:cec0:1181:a1da:3be2:1ef1:b537:8871]) by smtp.gmail.com with ESMTPSA id k7-20020a5d6d47000000b0020e5e906e47sm17373273wri.75.2022.06.07.03.22.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 03:22:27 -0700 (PDT) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Etienne Carriere , Sughosh Ganu , Patrick Delaunay Subject: [PATCH v3 3/3] drivers: rng: optee_rng: register to CONFIG_OPTEE_SERVICE_DISCOVERY Date: Tue, 7 Jun 2022 12:21:26 +0200 Message-Id: <20220607102126.2605773-3-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220607102126.2605773-1-etienne.carriere@linaro.org> References: <20220607102126.2605773-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 Changes optee_rng driver to register itself has a OP-TEE service so that a device is bound for the driver when OP-TEE enumerates the PTA RNG service. Cc: Sughosh Ganu Cc: Patrick Delaunay Signed-off-by: Etienne Carriere Reviewed-by: Patrick Delaunay --- No change since v2. No change since v1. --- drivers/rng/Kconfig | 1 + drivers/rng/optee_rng.c | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/rng/Kconfig b/drivers/rng/Kconfig index c10f7d345b..14e95a6213 100644 --- a/drivers/rng/Kconfig +++ b/drivers/rng/Kconfig @@ -34,6 +34,7 @@ config RNG_MSM config RNG_OPTEE bool "OP-TEE based Random Number Generator support" depends on DM_RNG && OPTEE + default y if OPTEE_SERVICE_DISCOVERY help This driver provides support for the OP-TEE based Random Number Generator on ARM SoCs where hardware entropy sources are not diff --git a/drivers/rng/optee_rng.c b/drivers/rng/optee_rng.c index aa8ce864d3..90d9434395 100644 --- a/drivers/rng/optee_rng.c +++ b/drivers/rng/optee_rng.c @@ -11,6 +11,9 @@ #include #include #include +#include + +#define DRIVER_NAME "optee-rng" #define TEE_ERROR_HEALTH_TEST_FAIL 0x00000001 @@ -35,6 +38,13 @@ #define TA_HWRNG_UUID { 0xab7a617c, 0xb8e7, 0x4d8f, \ { 0x83, 0x01, 0xd0, 0x9b, 0x61, 0x03, 0x6b, 0x64 } } +#ifdef CONFIG_OPTEE_SERVICE_DISCOVERY +OPTEE_SERVICE_DRIVER(optee_rng) = { + .uuid = TA_HWRNG_UUID, + .driver_name = DRIVER_NAME, +}; +#endif + /** open_session_ta_hwrng() - Open session with hwrng Trusted App * * @dev: device @@ -177,7 +187,7 @@ static const struct dm_rng_ops optee_rng_ops = { }; U_BOOT_DRIVER(optee_rng) = { - .name = "optee-rng", + .name = DRIVER_NAME, .id = UCLASS_RNG, .ops = &optee_rng_ops, .probe = optee_rng_probe,