From patchwork Tue Jul 26 14:21:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 593445 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b811:0:0:0:0 with SMTP id fc17csp3594346mab; Tue, 26 Jul 2022 07:22:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sMA+w5VCQriQvnvUvcBEhLWTl6NUy+/uSpZuX9MPth2CSxhrtXDF5BbyWb4TIz3HoONFgI X-Received: by 2002:a02:9101:0:b0:341:a089:e855 with SMTP id a1-20020a029101000000b00341a089e855mr6614862jag.230.1658845371843; Tue, 26 Jul 2022 07:22:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658845371; cv=none; d=google.com; s=arc-20160816; b=KgXZS2zaUOjTpS4HsmAZz6J8L7ZsYxQmNXPXq3hXS4RqQX6+wiafqGYm5l5Zqle/F8 hYDFAHU/L36wXpuqbXLwXAxvHSHMf0XYOtLemaVNko2bUQg5hfxNmCuijT3FvIHb4Phy AEP0PCqhmUMrYUPcXNfaWynw0MgJEWtu9kxY3Ewz0+QsFwrqOnCb2J2Rs/F4G6g+7Ygb X2Z4GjB7vUU7RTM8Lx3DkxLzNam1vlPuAzrGPglPEEbfQ154IYpo6KEoW90K559D9WAP jzjkbaN6/MDt6ArbAF9zWS9xIV+en0UTOK7mmCQ+jOwoUtUD4E7/+k1OuMwUg3cXBkUi HaDw== 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=KQEDcbr2oIiaTwcTlqctO0kETc5KYbMWOcW4TA0FsWg=; b=V9t0AOO9B+QF6+B/uOfIlg/FhvGUVv8h1lLi20J8PVJvLcH4g4T9RWF8fsUnhHeLrA uFMC4/LgMQUVHpzwGp0yuA8TwLOt5vDAuihRhorXYRKUh1SGKL1OSxg3e1OYGpWjieBT N738p/bFC9yijJGioIj5g+Uh6FMSZ+AlqJ5bWSHJRy0O+IhTSrVoAoGh8/EzxNV1HKM3 adr2IMKddG/Pouv5+cxQOLNQxUxN7E5v48oi2ZIsNHd8LoVE0mYEuSHBRYfQ0XuXET2L 0ebn+CkKvUiP17Swa0dMvWwsJPZwbgCMcxbDqsCDaRTzticTUL4ikSl7OtyYX04F1Ch7 pjFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="DrC/BXtD"; 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 f17-20020a05660215d100b0067bb74b090asi13708631iow.112.2022.07.26.07.22.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 07:22:51 -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="DrC/BXtD"; 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 E337F84144; Tue, 26 Jul 2022 16:22:47 +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="DrC/BXtD"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CCE6D8418B; Tue, 26 Jul 2022 16:22:45 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) (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 7D3F58407F for ; Tue, 26 Jul 2022 16: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=etienne.carriere@linaro.org Received: by mail-wr1-x436.google.com with SMTP id bn9so9503517wrb.9 for ; Tue, 26 Jul 2022 07:22:43 -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=KQEDcbr2oIiaTwcTlqctO0kETc5KYbMWOcW4TA0FsWg=; b=DrC/BXtDXj9bqZhN346wPmkQevQ49yXo+4zQ+27UTszktQFnw/Wx5xF3QH5AyBavHV ANP25BdGl2DZmVI8f26TEeYPOlFzZJfJ815D4E5gqw6g+WJcjfOhou1IJywfxcm9YF/T MEW++MCfBOfJ6F3KCIQUL36W1uT9PZm+pa/vdok6S1ExHK+NQUCLlQqUDEoDZbJ6WO2i bMrZDMYv13hWpVTbvpoPbhEBr0a8AnNG/twuagR421cW5m2R0v3AfD7bjxwsJCA/SsOk AzrYbDv3Bs6FcdcukaQLMK4x3Cf3mug/QsiIu+h34txDe+Ez5jme7wg1qIY17kQ9hScS etpg== 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=KQEDcbr2oIiaTwcTlqctO0kETc5KYbMWOcW4TA0FsWg=; b=mde8w3YXhe1jeQDMYa2wfwDJThDPtIJyA8xYaTub/UKOQaJeBhFJ5nqksFu7PNTMdl 2wxkOvRTkL0UyF3NVv2EVf7qfBjzQP1ccue5DoUZHEiZm/6dlsMupz8vIT+qd/FPLREE 64caEaosiRJoJki1wVVoRuT+0tJJ1jLCUeAFy24Z9qs3+2KA4E6kvte5qO1HFHjkk8N8 EEP851jMgaWZqCAkcELjU9/VqV4aMe+16RoTv3kbuBgZGoxOxjhFEFwtExEQIs2D6z1A Szt4Hwxkpg+TptN/okrKYW36i72lFa8lWbimcK53qvIq/nc9OCwyyaCngdu5DWb6g+jI dyjw== X-Gm-Message-State: AJIora8p3JO1BukzVqWYCP5IwGEkLbx0hVNa5yDEiqBvwvlydJlYbmJ7 v88RKf6e60zdS/IFrNvfQO0CDgVsNa7/Xg== X-Received: by 2002:adf:f0c1:0:b0:21d:ed10:5811 with SMTP id x1-20020adff0c1000000b0021ded105811mr10873297wro.656.1658845362719; Tue, 26 Jul 2022 07:22:42 -0700 (PDT) Received: from lmecxl1178.lme.st.com ([2a04:cec0:119c:31fb:8cfb:f47b:e69f:3313]) by smtp.gmail.com with ESMTPSA id i5-20020a1c3b05000000b003a31d200a7dsm18902950wma.9.2022.07.26.07.22.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 07:22:42 -0700 (PDT) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Etienne Carriere , Patrick Delaunay Subject: [PATCH v5 1/3] drivers: tee: optee: remove unused probe local variable Date: Tue, 26 Jul 2022 16:21:41 +0200 Message-Id: <20220726142143.1739265-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.6 at phobos.denx.de X-Virus-Status: Clean Removes local variable child in optee_probe() that is not used. Cc: Patrick Delaunay Reviewed-by: Patrick Delaunay Signed-off-by: Etienne Carriere --- - No change since v4 Changes since v3: - Applied Patrick's R-b tag. 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 Jul 26 14:21:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 593446 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b811:0:0:0:0 with SMTP id fc17csp3594523mab; Tue, 26 Jul 2022 07:23:04 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sYrK4hs7cXWf50h2lP0UngHr1+RzaMoLau7UPVko/CroA1hx5SkBHFGk+1zEqa+xZ8lRQ9 X-Received: by 2002:a6b:c408:0:b0:67c:6fbe:7169 with SMTP id y8-20020a6bc408000000b0067c6fbe7169mr6268734ioa.111.1658845384051; Tue, 26 Jul 2022 07:23:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658845384; cv=none; d=google.com; s=arc-20160816; b=QLK55jU56aj9NLgEp3R13Fnvb29HWvkemjPImen5OP/sNWDZOF0RgpW6l6Xx8Q1Fz2 Mf8d2FR/5Er5hkdJ7DYt2eeyxUloo/NmQ8CoOmUd1beu3wVfduxIETG5mHgQEPwoiQhO QkJfkBAwAF6Zjc+ZkCQHDuhY/eSiFFmg5ibiO9Xt0CWnT0Od+isi9DB5sHVWzgsvTNNa 7kpGCVbUXVsSXZ+f78A4WK3eq+Qno+KMEYPloapOtEHZX8Ny++aqVBCwuBYIVq9wzH6d DWYGsutPlmERACWkKoVwDndQiU0K+McF5o1I2id14SGf3Ru42GC5lIfQTEcvGD1Y3JdR dp1g== 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=vtGvKD186bOkllofcUkUPlvm+lnPHPl4GlFr76eNh4E=; b=wcui+oI8tijQhcK+M7hkX/zW5b1v1ulyc2BOy9zewwIepxTLbHo6MmJIBrs/1tOmyM WECtS4pHcj6QombK/eAMUcGlgKlmvcaRv/B89Se4TSQed9OX75XVwo/YBoEatqPD0cFT mU0IhRh0RsrlhuzP95+OBpBmgFRwAMdQffmeP69hu9H9boL1Hde1UyiDNoZ+Yxc+gjlH /2QDIfiDMZ1Nc6+1NvOUou/V7z/gaJWh8df+pNHDKHtRzh+cbhBmekP6RggXkLdWK/OD TTj7hygsx1aL6r/uLNk76qYVfhZYa2MkwSReOwvYngcTM8u0iHQhwmn3vprIkCMSsChh YSaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BJuyVWLq; 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 b9-20020a056e02184900b002dd8d4d3910si1770427ilv.123.2022.07.26.07.23.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 07:23:04 -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=BJuyVWLq; 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 1D52380112; Tue, 26 Jul 2022 16:22:51 +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="BJuyVWLq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9F7F58418B; Tue, 26 Jul 2022 16:22:47 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) (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 B7E5C840FE for ; Tue, 26 Jul 2022 16:22:44 +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-x431.google.com with SMTP id k12so2655194wrm.13 for ; Tue, 26 Jul 2022 07:22:44 -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=vtGvKD186bOkllofcUkUPlvm+lnPHPl4GlFr76eNh4E=; b=BJuyVWLqKELpV7wnEGf+da7hJtal5AYQR2eJ2CiaftIi29x2qPuqSEfYJ2TplD/n3s ZvcSNe6IkZIxm80e7TBif9wI8M1WnhYWjkh65QaFSw5yxLDBUbl1ixH9t7/JAd/hgR6n zCJ14cBkSipeu6jQdE8htKAH6zxXpx++agXF9buZvBSXPqMZeikxZYNfBnW1JLecF690 koNuJRKsqFlRpXXh9/gi4Qbz+EnKrgx4zy9rLnft0OBOarpw48lqydrpfCzhz5V1XsOu Td1DTYCiAr60kPm55tb6doGO/ctNF6wclUJakvdhQrIozg/F0+s2jJ8P6TtgKo6cN/Gl 5yvA== 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=vtGvKD186bOkllofcUkUPlvm+lnPHPl4GlFr76eNh4E=; b=0+8iD6x7ihh4djtiPXigYJEo5cMQMTRgrxJsil7nDnPl6pwmFauQCmxqjizfBbJO2e eYw8Umu6x7RSqxKw9qi568LUo0ah1cDb0IN5zZbOklqXV0QDQHbnRjIoWF3eICLeNZKB WJ9sFVZYMAC1l7fo/V7wG16s/8UWqGtDTTK+AbUnMLnbnE04USdRKECu1SeLxaqkejmX pSETfYTn7yBLjPJdhFaNdIoyCqi5vnlSUg0/c5xH5Jf0IIM719I+ZXy+K/145/qP9ApG XBEbV6G95TGiI6Kgyhrk96zb2dl9j24GQu8B3tm5Bc+3+dqhy3JwYoQ4sk01mwTpHbrT kYTQ== X-Gm-Message-State: AJIora80t3wRm1LgxICvIm3QLcjRBJKml3d+lNNCMV8gVdjsyMuC4S5c mHRyDDkB6oIzqT+g/21qL0YzVaMjGNZdsQ== X-Received: by 2002:a5d:5582:0:b0:21e:9c12:4d65 with SMTP id i2-20020a5d5582000000b0021e9c124d65mr2791315wrv.175.1658845363885; Tue, 26 Jul 2022 07:22:43 -0700 (PDT) Received: from lmecxl1178.lme.st.com ([2a04:cec0:119c:31fb:8cfb:f47b:e69f:3313]) by smtp.gmail.com with ESMTPSA id i5-20020a1c3b05000000b003a31d200a7dsm18902950wma.9.2022.07.26.07.22.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 07:22:43 -0700 (PDT) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Etienne Carriere , Jens Wiklander , Patrick Delaunay Subject: [PATCH v5 2/3] drivers: tee: optee: discover OP-TEE services Date: Tue, 26 Jul 2022 16:21:42 +0200 Message-Id: <20220726142143.1739265-2-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220726142143.1739265-1-etienne.carriere@linaro.org> References: <20220726142143.1739265-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.6 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 v4: - Fix incompatible argument type for __enum_services() reported by 64bit builds. Changes since v3: - Stub OPTEE_SERVICE_DRIVER() macro when CONFIG_OPTEE_SERVICE_DISCOVERY is disable. 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 | 34 +++++++ 3 files changed, 208 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..9240277579 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, size_t *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..fca468af7c --- /dev/null +++ b/include/tee/optee_service.h @@ -0,0 +1,34 @@ +/* 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; +}; + +#ifdef CONFIG_OPTEE_SERVICE_DISCOVERY +#define OPTEE_SERVICE_DRIVER(__name, __uuid, __drv_name) \ + ll_entry_declare(struct optee_service, __name, optee_service) = { \ + .uuid = __uuid, \ + .driver_name = __drv_name, \ + } +#else +#define OPTEE_SERVICE_DRIVER(__name, __uuid, __drv_name) \ + static int __name##__COUNTER__ __always_unused +#endif + +#endif /* _OPTEE_SERVICE_H */ From patchwork Tue Jul 26 14:21:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 593447 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b811:0:0:0:0 with SMTP id fc17csp3594706mab; Tue, 26 Jul 2022 07:23:17 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vkwIIM5+yJ9H5FAsH4ZJD4pFZqeMT/BLEkiQHGhv6g3bo7K02R8k33rWUARqXsVaPQ9j7q X-Received: by 2002:a05:6638:14cd:b0:341:46ad:f3da with SMTP id l13-20020a05663814cd00b0034146adf3damr7372570jak.36.1658845397088; Tue, 26 Jul 2022 07:23:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658845397; cv=none; d=google.com; s=arc-20160816; b=S0Wwv8oIRKD7Ko12WeEzgy8tpMk5FkZxzu/LDL3WNmwNXx4IB4z3hOCt6Rxv2oJCOq zhlhPrZRR/oSEFvoGApHzpnfCXgM/gDyMEl7PP8MmrenZs10aNpbC9ZjelWHK+Qq9n/H Ju8+LnJ+ocyNlUUhEXbT3vTiVjiQgoy/6jqi4weVIn1SUoxOUv89NNC20iyP97ro7zRz Km2xaefhHMwCTj9t4feTWEdM22dVieQTypI9Rw410hfzXSGaBxOq3AJgHhoMEDkbszM5 zZCcqtwpZfuWGrKMjW5JVWu55pX4wcr1g1lGK8ICyYCZnYG2+XK01BJq96HIJv2melC7 PcCA== 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=tsvpMjxBGT1rUOOnYbawjw0PRatF/sKB7VjZ6cYY2WU=; b=gwr5POEMN/Bol9Ms0noyAM8Jp6jzq4A0E40xdFkI8UDsD2+zwIqhDKwt41OynkDmCs XM0a1PEyS2DXlxyFQ9TtJvv/01N5BhhApCbk+tneKY2M6Ct15bBVS6FCHLL1FjBecCkk mw2WElM1/UZxSS+9OC2/nDe3l5mzwHQoWkedNfNOG/QPWO2qYBBL3fkKoGcTcW77JxmK Ww5bDgyravO62OzIkQdctCL5F1EiMGRAOo0ytZN5N2upUb0pJDLOWNXDzEEFZ+ZaCENi +e1e5SUhuXclQrHgIsmU2E7yG6ETXFuCK3C3kc+3TQPCm+9Xfu8nzN745flmm1Am6f2R hwxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jiQ6N0bv; 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 t20-20020a026414000000b0033eba21756esi754443jac.74.2022.07.26.07.23.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 07:23:17 -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=jiQ6N0bv; 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 A410584051; Tue, 26 Jul 2022 16:22:52 +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="jiQ6N0bv"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 748448418E; Tue, 26 Jul 2022 16:22:48 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) (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 015768407F for ; Tue, 26 Jul 2022 16:22:45 +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-x42b.google.com with SMTP id h8so20369533wrw.1 for ; Tue, 26 Jul 2022 07:22:45 -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=tsvpMjxBGT1rUOOnYbawjw0PRatF/sKB7VjZ6cYY2WU=; b=jiQ6N0bvBRV1BH27r0EA9zCaV1MCqCfjIjqxru2VYopTp1tbjkLYcQXtGxvZuV9FVn qyldix1wBLPUXWkHUlqZX2RkYeXFD2PFXHtB6np3Qq1Z3jksAeszFjgWtGK50pCpTMIs 7GNWAjgT9cp6oma1y7jZxfN239pBey5HodhzowG4rCn+pdQfRi5W2RZtTiGbtySt5xOZ msakP85wfckUp1FCCiNEMspeDcFcLdOtUUd1ydG/daQKFXjNDuvks0lJ8jfPXo+xo6iT M/l4I4DaE6Vzsw4aZb5MrmcvQ+6wStUgGcO+kK/SL6MyRfosaZ9vVDq/lsr0Jt2Far9h 7VLA== 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=tsvpMjxBGT1rUOOnYbawjw0PRatF/sKB7VjZ6cYY2WU=; b=abiqXruYC3ShE10yhjmCZ16Yss3Nw40I7WhGH2j0vjdy4IL6gOLMeJ+2d3Jcc1BseM F/m/LXb8X3jb2bpv8yYlD19gtxAjo0Ur/l+3aa7zxZSgiCCB+34oBA9KJgboLjk3UoOA XAEbf1g7R+zFcNP/MIJ2nQmj+iRQlXIEYh4dfRAhTwn9k12EymNHmRCXM3vwm7tJFerJ 17FlpZzKfTDJbVq6co4xE/087p3jskk6mCRVaooBbcwmfOCjy1+krf3iRA8f2JZjh5au L2iysVDoJb4SHVdvGOqenIAtZKDmXWleHN5J5e+Bl6xwks7A0fZXi+rEiiEO4KZHTjJK IMHw== X-Gm-Message-State: AJIora/sGuG/PySAPI4ex55L1E5HJfUCE7MbOvyY2BgWbzRw1hnvNtEZ u8eLNO1pi+2ZCJbYPGQqJJRzbIkdDneD2A== X-Received: by 2002:a5d:6d8a:0:b0:21d:a6f3:f458 with SMTP id l10-20020a5d6d8a000000b0021da6f3f458mr11378552wrs.574.1658845365230; Tue, 26 Jul 2022 07:22:45 -0700 (PDT) Received: from lmecxl1178.lme.st.com ([2a04:cec0:119c:31fb:8cfb:f47b:e69f:3313]) by smtp.gmail.com with ESMTPSA id i5-20020a1c3b05000000b003a31d200a7dsm18902950wma.9.2022.07.26.07.22.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 07:22:44 -0700 (PDT) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Etienne Carriere , Sughosh Ganu , Patrick Delaunay Subject: [PATCH v5 3/3] drivers: rng: optee_rng: register to CONFIG_OPTEE_SERVICE_DISCOVERY Date: Tue, 26 Jul 2022 16:21:43 +0200 Message-Id: <20220726142143.1739265-3-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220726142143.1739265-1-etienne.carriere@linaro.org> References: <20220726142143.1739265-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.6 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 v4. Changes since v3: - Unconditionally register driver with OPTEE_SERVICE_DRIVER() since the macro is now stubbed when CONFIG_OPTEE_SERVICE_DISCOVERY is disable. No change since v2. No change since v1. --- drivers/rng/Kconfig | 1 + drivers/rng/optee_rng.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/rng/Kconfig b/drivers/rng/Kconfig index 21a9ff0195..0cbb40add6 100644 --- a/drivers/rng/Kconfig +++ b/drivers/rng/Kconfig @@ -41,6 +41,7 @@ config RNG_NPCM 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..410dfc053f 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,8 @@ #define TA_HWRNG_UUID { 0xab7a617c, 0xb8e7, 0x4d8f, \ { 0x83, 0x01, 0xd0, 0x9b, 0x61, 0x03, 0x6b, 0x64 } } +OPTEE_SERVICE_DRIVER(optee_rng, TA_HWRNG_UUID, DRIVER_NAME); + /** open_session_ta_hwrng() - Open session with hwrng Trusted App * * @dev: device @@ -177,7 +182,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,