From patchwork Fri Jun 3 10:26:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 578487 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5806:0:0:0:0 with SMTP id j6csp1368531max; Fri, 3 Jun 2022 03:30:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwrp3CaS0WdU5f1uGX/KH6xP+ho68IMJwaVaRy/SUPdy7x2FFNIxxcCOGS2VdvuYqSOCgu6 X-Received: by 2002:a5d:83da:0:b0:65b:1cd:fab2 with SMTP id u26-20020a5d83da000000b0065b01cdfab2mr4341530ior.5.1654252218120; Fri, 03 Jun 2022 03:30:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654252218; cv=none; d=google.com; s=arc-20160816; b=rXwovaEM90Inv4ejLirTn6uba02ce6hoUuy3/F5JdKwcItYaDnd04HrCMAx/SCzyCG qyFNc80rh+OkemN/StTGfXGc0iGtRuq0T4nim5OBUlY9wwQzpapTR6tVrVJkmnNgWdY8 GZBbiq0mVek+EDDjsx6BftRBt7s/G7YSrXPuBcc9oX0zBo3GQRQvGcjvDvPIxmEF0rtn jdIuG2t9FD4BwZQGhRozLKv8n+Z6JLXcKYDpZFQzqhdBrTxbmSIYsYhFTrNQafXovHjx 7Ufn9m68R9VCfr2JjQzFNcDaq+l1ZLnIepZMllK3snYi4n9ztAmo0sWyooDKh4ISzqQH aHFg== 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=EfgNqysyEbKTOg2u+n8S0HbzrT9MyXDZFfi6Xyynp1g=; b=jVBwDrpXaal3Nqpqm7/sUPuhbOdqnvOPAq47/exX9a0kDRFOaBHSkhvy8prnVAd6jK 7NlmVCy7OU0rf6ppfw5c28HL+xPz0b7IVnNhq5Z+oYRL4Ry7vQgqNOHOybwAvbnP01wB a2eZ+BCpR5tIQ3SBcy7Pfbm4Iz1JQhd2LMHOJGIpnCpXVtWEJRZJO8d42EL6aYOcuRel 57F8pQlfPXPGnhj5tU2Mcnjxj94sHj8vqjFurcTGfpfIMZvjbafVjHqM7iBRJtewlp2G Tbyb/qx4x8l3Ws9EzcvUtuAv/wU7OyTOflxDPtnv8tMmwTIVhqKVx82v6bc78S5/nMaw KlTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Y2+pvCFb; 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 b1-20020a056638150100b0032e4c46c80asi10189929jat.115.2022.06.03.03.30.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 03:30:17 -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=Y2+pvCFb; 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 BB15283E9A; Fri, 3 Jun 2022 12:30:10 +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="Y2+pvCFb"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 263E183E60; Fri, 3 Jun 2022 12:30:07 +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-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) (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 10B6D83E60 for ; Fri, 3 Jun 2022 12:30: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=etienne.carriere@linaro.org Received: by mail-wm1-x32c.google.com with SMTP id q15so741210wmj.2 for ; Fri, 03 Jun 2022 03:30:03 -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=EfgNqysyEbKTOg2u+n8S0HbzrT9MyXDZFfi6Xyynp1g=; b=Y2+pvCFbfHeEHCdZTnAsJo1zqgKNdEdoeac4cvhnx9Djs81klG46Y5ha0OfD5ffjbr mIxzWmv9tAXm1PU9GDh7cSoUM4RwzLlK80ymTjYmu8ouLapYPMqBibgylS9WxYBJC48x k6VHesMaemyYOdoPjhucFk+cMqnxsohlXpNk/xPBECOOLAPzeBwccFIbzqkhdgkc1aYN LeJ8Y9pAtr6s1Tc5Ho9/3PkHJqBdjMhYovr31WQ1l/SUGHgZB0EkjZotPeRUSeX5T76a Y3hUP2m96ssgdcQ/+16Xt7wgaJggLIDMDEjFZtScbzny3tXue89HROympozyP9pRop+M GvHw== 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=EfgNqysyEbKTOg2u+n8S0HbzrT9MyXDZFfi6Xyynp1g=; b=DqDZigmlTTmMSoh7nNTZGIWgF3djcLWpUTd4mD48hxzUrmtedHeMZw9D8uo61/y1DE D4Yt4jk0SXPLcUpPicnlQwVAV2FThUB1Z/zZRoRuS+78PMYRgaCqNEESAnA+whnGFYIf DvAMV86SR1+LAJNOB/LGQAzYT0lGnA6Kflv+QOAkYUBUmoXJm+qcAS9wVT4ARIjXuEGi dVm5W8ULu2ZiUisvuzaIIb+y9QorobgYZRwyRCAbZQcb5AeSmdaYlGLBvmq9AVNv/I6K SSL0wjVJLsZoEPoPUp1xyePxgdZfN8KeP2+yoqVyO2gxlD5ILiH0+WDS+l5IOjnbQQqT 0P3Q== X-Gm-Message-State: AOAM531NHAOLhJWiwsqFnu5P+iXhFKvBmT8rqqGLt628BQ5qoa0Tx39U yu6zpb/jsBQFkHFjf+yRUD8r4S2bSA8/GQ== X-Received: by 2002:a05:600c:3d0e:b0:39c:281e:6cf5 with SMTP id bh14-20020a05600c3d0e00b0039c281e6cf5mr7292629wmb.160.1654252202281; Fri, 03 Jun 2022 03:30:02 -0700 (PDT) Received: from lmecxl1178.lme.st.com ([2a04:cec0:10bb:3bc2:7476:fed6:d8ef:5c31]) by smtp.gmail.com with ESMTPSA id b8-20020a056000054800b002137b2a233fsm4685404wrf.36.2022.06.03.03.30.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 03:30:01 -0700 (PDT) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Etienne Carriere , Patrick Delaunay Subject: [PATCH v2 1/3] drivers: tee: optee: remove unused probe local variable Date: Fri, 3 Jun 2022 12:26:59 +0200 Message-Id: <20220603102701.2316720-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 --- 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 Fri Jun 3 10:27:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 578488 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5806:0:0:0:0 with SMTP id j6csp1368752max; Fri, 3 Jun 2022 03:30:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztMnXsx24eYecaTwtAdqG4T5XNKgU94fXpmvQwBiT2DRvSUt7Dhh9yB4chlw6ZZGkOn/cS X-Received: by 2002:a6b:7845:0:b0:64c:9acc:9f1a with SMTP id h5-20020a6b7845000000b0064c9acc9f1amr4468801iop.103.1654252232270; Fri, 03 Jun 2022 03:30:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654252232; cv=none; d=google.com; s=arc-20160816; b=esqYT0hPLVF4HLfvs8tD6HMwJCxMQIccaKAG7MPlJ6fzU5+l2WXmIuJ0lpFYqb/c70 qJxOnkwAh5deHJ06QbBvGSOw8/3N+NetAvyhokr1Acm+L1p7+XY0WuZMM3dHYzzafOe6 VMvrqm7WVvMRqf2QNx94asPTXCgHU+PbAAhsZvNSMtdb3vWsWNG1ANPK0FUigUtRahYD iYrEZOjRyU7Na75RTUEKPh0SfF9UW5Jh4/24ikrHyqV5wx7ReAk0McyAao+ztLWIEaJU npHEe4ntAPE1ov4CeTj06GiOapqf6Bt92VlsbkVrqrDaM0vp3HYbSFlhIePGVAYCESkl PYcg== 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=rgO1EG/gfUz6ijfGwqrXD99RmkrPrsVsTR4xkNNj/34=; b=yKGUSyhXXBu8htpKk5+kTuHVSDDFx4LMJA/5QCbIZgYjrbz9SH3FSZq/uaZvx4RDv2 M5cSqvXnfbDIgPzOXzLlDX1Gp2Ere2s/LsxYRMRBVE6HVEKP5roopGvpWp0TXKnEFv8h EKIF6M47jZB/IaR2tlyEEWInzRng6GSkEAOiZGKsjfirpMn7OOa5wuz/JPb1KNF3VRA+ DXVd31PB66udqXGhsZUWcxqTspYbV8JUi3q+ndxlY2JyP1lih9qYmL7znoReg80HnAKS ugU56yBGt3Jp2H8sabH+WzwlRqOBvNRB8skx5UC5Pv+G31r1+jDKHJQNkLDppfxJ+o4v vC2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jUcUO2jV; 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 w8-20020a056638138800b00330af4406f1si10820664jad.18.2022.06.03.03.30.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 03:30:32 -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=jUcUO2jV; 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 C413784184; Fri, 3 Jun 2022 12:30:16 +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="jUcUO2jV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 400D083E60; Fri, 3 Jun 2022 12:30:09 +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-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) (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 4329883E9A for ; Fri, 3 Jun 2022 12:30:04 +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-x32f.google.com with SMTP id n124-20020a1c2782000000b003972dfca96cso4098875wmn.4 for ; Fri, 03 Jun 2022 03:30:04 -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=rgO1EG/gfUz6ijfGwqrXD99RmkrPrsVsTR4xkNNj/34=; b=jUcUO2jVRYQctHtE3XBANK90GdCTbIaHevHHBxFiSLmsKl7GZYoUFisL9Fz0qG/Zfb ER9dP3iybztT0Hmlzop+VMNoIvuS+OJSdWbE68wlJBRu7wugyg8kL3icRAN61nXH4cRL 3K19piKRlXYDu3DxB4OA0j921pDcL5dUsKBsVU0UB3Rgu8/0PMVYu80rvk+JHmhQRAQ8 d/h8dacINtwpESApRAlwfojERWPEivi7hEt77eFRxymsZWJzwGyjZZkxH2HWugP+2VVi V3RE4ZNc16M4E6B+Jjyk71EEIATPYLcnY4RvsxYyaF/bJDJG1Mx7wUgqlwcS6b3ydRuD z+GA== 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=rgO1EG/gfUz6ijfGwqrXD99RmkrPrsVsTR4xkNNj/34=; b=gHaqlWmKxyKWS8iKSQH/a3fwG2jVUTuo44FZ1v6v+xAVNIND+p/f/4hbbf8QYZuOhX QAs+JAVOLiNI4YhPJWCHNzTQcfwPR78aFc1a/BQquiNO5Iq7/oHdWD+1mv9mzXSAymOq GR/qB7k+auh5ivgCcKcrqk6p0tIf/qyXHY+Q9oQ+rAYZXwuCmqduYd8lez4tezGpvruO 5VQrH1a432H21J2p/0fmW/wFhb7nr9yrc8FUZNaADpeiDD3QsD/d2K/e3IiWuCrFPjUY eypsGbOSPACCBIF4liJhXrCcKrYQjSFHxBBt2nzBtwbdiA0XY5SCssoilbh8kLj/fM9X p7JQ== X-Gm-Message-State: AOAM531/uI58ay97vhAuILRq6Fq4nWEYuWwbU6yc5lgwlfqnU9MTaD9H cEL+WDRivOQl+nYcjGncoUUL9gr64ipbxA== X-Received: by 2002:a05:600c:4ca1:b0:397:8b29:255a with SMTP id g33-20020a05600c4ca100b003978b29255amr8030573wmp.139.1654252203324; Fri, 03 Jun 2022 03:30:03 -0700 (PDT) Received: from lmecxl1178.lme.st.com ([2a04:cec0:10bb:3bc2:7476:fed6:d8ef:5c31]) by smtp.gmail.com with ESMTPSA id b8-20020a056000054800b002137b2a233fsm4685404wrf.36.2022.06.03.03.30.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 03:30:02 -0700 (PDT) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Etienne Carriere , Jens Wiklander , Patrick Delaunay Subject: [PATCH v2 2/3] drivers: tee: optee: discover OP-TEE services Date: Fri, 3 Jun 2022 12:27:00 +0200 Message-Id: <20220603102701.2316720-2-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220603102701.2316720-1-etienne.carriere@linaro.org> References: <20220603102701.2316720-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 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 | 175 ++++++++++++++++++++++++++++++++++-- include/tee/optee_service.h | 29 ++++++ 3 files changed, 207 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..9a90760379 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,138 @@ 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) + tee_shm_free(*shm); + else + *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 +790,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 +827,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 +855,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..31732979da --- /dev/null +++ b/include/tee/optee_service.h @@ -0,0 +1,29 @@ +/* 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) + +#define OPTEE_SERVICE_DRIVER_GET(__name) \ + ll_entry_get(struct optee_service, __name, optee_service) + +#endif /* _OPTEE_SERVICE_H */ From patchwork Fri Jun 3 10:27:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 578489 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5806:0:0:0:0 with SMTP id j6csp1368943max; Fri, 3 Jun 2022 03:30:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypACcy4Yz7jD5kMrNflGST5AiK7DKediMV2wn+WHayJV9ipc9DWu2YtxaUX7RLzNdroZsl X-Received: by 2002:a6b:ea09:0:b0:668:c4ba:5beb with SMTP id m9-20020a6bea09000000b00668c4ba5bebmr4555147ioc.77.1654252243850; Fri, 03 Jun 2022 03:30:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654252243; cv=none; d=google.com; s=arc-20160816; b=r5X6I3UGsZXx8+aMy7EjIdCg4o5hSots6pMzqiNwhJ3YoYGVdo5qLm6EZCM0SrTQpo YEwzV+LS1xIJa9AzHwk5zWG5p+eJ4Ah6zI2Op1GcBqh1nbLig8zEI/jtMe8NeERxWjSk 83itqO3hNiq5RkFNjNpNb/HVflifrT/BBJPahZmI2qXjGdSkik6u9dQVCMcZGs45KUC4 vQQ6CsSx330esSXBdwuP2is2OugjXtz8A/DNivzil0//ehot6oJ+33V8RKj/Vg19OlIU yDN2fNP/u96T7TF92jJemsn3eqVjezi7uhoisOf8pv4KKibRF5/yahTXe8tZvriXKFvo eNlg== 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=Pf6ZXtJzmRJC3z6KfbpzwXxZ0Z+z8duSJR7CzXh7xg8=; b=dnjTKzTjbUOuwdnV+pl0wa3AVi2PaB9k9tw7d80dliEQ14Dvx7374q2p4q733wPd2X z/9/M1PijBHGkTuRYWuoRZQh2B4n+fbojXkce7KQ677shx8eA2P+pEGJOpdQc2tzM0SO FV2oo7j9WJFa9jcTUuy/pT9MDxGaH7sqR2fw2ycfpPKS7fXeMVmItXN2qphV5uAVBMAE Mga8nTPXRFBV+f3e4dSBMn2NKOSku+14CashznU0RwhPYRTG9Dxtap4XRNr2SqHFDkrV iiFUAa7LOelfc9XiH5oafTSpVwPwi9vKvkH8UZ0V/DYwbR2NN/MxA7+23GT8D2EroVGa 24Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H4xFJCxf; 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 l3-20020a056638144300b00331373d76d5si9936792jad.108.2022.06.03.03.30.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 03:30:43 -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=H4xFJCxf; 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 5D58884300; Fri, 3 Jun 2022 12:30: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="H4xFJCxf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 652DB83E60; Fri, 3 Jun 2022 12:30:10 +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-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) (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 6F2FE83EFE for ; Fri, 3 Jun 2022 12:30:05 +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-x32c.google.com with SMTP id a10so1341371wmj.5 for ; Fri, 03 Jun 2022 03:30:05 -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=Pf6ZXtJzmRJC3z6KfbpzwXxZ0Z+z8duSJR7CzXh7xg8=; b=H4xFJCxfsqniq8OHRVZQXWKbImIqnIiTo//87VluG/3yuYuTYKK5Mvop1qghMjqGKH 8aeKsNv0S3Q5y2sQ/Hqs1CkEsI3jVaaFo3ciCm/TM9zi6v7267z52GPwOjNk4k+t94D4 c20d3uc2GDkUW50QL897OvumSbO6I5CcQzXxUW5uwQoIk2UM+duREaK4e0YvtvVb7ARB oOlXUx2aHHeLfDCAb/knxnaUJ5alPxkersFolkzmTxmzq3buCuc6oEMg7W+ZHsqraE3j zEx/t4Qi099iOxsFudMcZoGXIPdxDQeX3AIjsey+3ADFXzbvDyWgBemQs51LeQNmOKQ5 V/bA== 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=Pf6ZXtJzmRJC3z6KfbpzwXxZ0Z+z8duSJR7CzXh7xg8=; b=TC7oatY7kMRTe4Yg9OfxZMIeA7IXEfk2S55crClZbNgvVCdDX3gGV+RzO7N2AHGxfD MyXQxydgrjrLPgKHkyFbOGB8BIqKwB7WQxEtGYSYLh0y4nLtOhl0EDtEVVU2tHWt+bai vA8HyqJh9FlNqjyLZPQ8qPRzjvGntFkGAGq9tpW+UtyLOhvW4IJ7UeQvoI+pnwurClLq IyVlI2JOLKIMr63gU+9BDZ/kZ2jjSKqN31HAUs6BsEZYR5uLOWyOEHYTHzMsh/IQ/wD+ k6iN93VH48F1JNHqgi6EtX8et1jvS+/Xzeuennt+e1lB6biCezJ2F4bnrf/23FKgcRHd A9tA== X-Gm-Message-State: AOAM533lqkKRLdDhOmndQTd89234rNPrfn6peXQr+qBdlYKkNz5V/0dr Q9xE18GwBGxxHx7t7to/mhjL03kzZ0FQlQ== X-Received: by 2002:a7b:c932:0:b0:399:c7a6:44c4 with SMTP id h18-20020a7bc932000000b00399c7a644c4mr28414891wml.5.1654252204313; Fri, 03 Jun 2022 03:30:04 -0700 (PDT) Received: from lmecxl1178.lme.st.com ([2a04:cec0:10bb:3bc2:7476:fed6:d8ef:5c31]) by smtp.gmail.com with ESMTPSA id b8-20020a056000054800b002137b2a233fsm4685404wrf.36.2022.06.03.03.30.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 03:30:03 -0700 (PDT) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Etienne Carriere , Sughosh Ganu , Patrick Delaunay Subject: [PATCH v2 3/3] drivers: rng: optee_rng: register to CONFIG_OPTEE_SERVICE_DISCOVERY Date: Fri, 3 Jun 2022 12:27:01 +0200 Message-Id: <20220603102701.2316720-3-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220603102701.2316720-1-etienne.carriere@linaro.org> References: <20220603102701.2316720-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 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,