From patchwork Tue Sep 6 09:37:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 602970 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp4362854mae; Tue, 6 Sep 2022 02:37:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR6iEKnjlBhBH/AQCjduKRq3wn8xJYb0q4ZgxKrt/ApKf9ftFs+hgZmQHf1XWyDDKJZlDAzW X-Received: by 2002:a17:906:1841:b0:73d:af70:7bfa with SMTP id w1-20020a170906184100b0073daf707bfamr38322841eje.49.1662457046751; Tue, 06 Sep 2022 02:37:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662457046; cv=none; d=google.com; s=arc-20160816; b=glXCR+B8sGFUM4kLdEf9xQANJdNZQIqQq1q34a+jQE9zJc9iVj0MysXvZ5RUgz5f+T d3clq47NCL20ny2s+m7f3/b0MsCRqDUl+tgXcmDqWXJgM9suv2uz/08HcJPA1HL3qPZF hSjDtXfYNfejqdX4DbP3thWnGwE/G5aXvoq9+TRnfphNmIiBCMVOMoHaIJRxwXTNpuru ol1lyr39rq1UvoQh5ahL+TEQ5stwmC7UUsO3l0WCGv89+26djzO798PcJ/S/MaYMzomc IjlorPjLQzzCDcwhCBNPPO3iEDwW7y7Ag5dk5EaEnu748JOeRIR71Nt8IpQwMyS4WJ/2 TsRA== 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=bvZnEkqCrkCmp9qJISWK0AIU8xy+Pk1MuXzxNLLBuoo=; b=fuGX4Oz7n4SE17aGgVk/dbEwir4Rj97UKQXw1NpnlwN/UpL7lNV9QIpOK93tTxJ9Ih krjwNUKgGxDw6ODu/xqD8Bv+zRwAWDc+UXderzJryijJacqklMjq5VqAtQ+BbzHVov7a 4oiow4OjchiktUkYomAXIA2gxpps0DcIjT82pqHKBQtN8Dwx2wwZAXSsgzpjx6eClx2G ttEQfAkqjME1/Rngx577pNSdpkYBRMUPdm/F5KW1I9W22mwv8ht/Sg/Y/UXjIiHoxf6J q36tohbnhSJcHvR+fzXxJLhBGF2GdWDXZYUdLqMcrh3YUKbU3EhkDW45Z3t8BfPNEwKZ TTiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eTGX89kh; 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 b7-20020a056402084700b004359f471717si11159859edz.0.2022.09.06.02.37.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 02:37:26 -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=eTGX89kh; 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 302368499C; Tue, 6 Sep 2022 11:37:24 +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="eTGX89kh"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6AFE884A14; Tue, 6 Sep 2022 11:37:22 +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-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) (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 C36FF84986 for ; Tue, 6 Sep 2022 11:37:19 +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=ilias.apalodimas@linaro.org Received: by mail-ej1-x631.google.com with SMTP id bj12so21773171ejb.13 for ; Tue, 06 Sep 2022 02:37:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=bvZnEkqCrkCmp9qJISWK0AIU8xy+Pk1MuXzxNLLBuoo=; b=eTGX89khZAyUsUY8tqosJxNGFzZTWfeKtgIaGwmg1XHbW0LIxQeK+DYGBt9dkgVAuD mP5SLrdZOzpEyuhwNhOy8pvg55DJKPbe/pGzGTsJii78P0Q28UGM7MPyIbloYbGifF1D 5cejFRW0TDXPgrv9VSLFTszsRnsFU8WpvkrsFokF/ljNyv7ayrU5tdfOQAQ9t18wph5V Al/+bmihLWR5YFuSsBuBW2Ip41EuwTgHaSIHv1nVUW0DfJxDLm/0i6fH7gGpcIW17Y+S fZmkGrMARsarSl9v2zNP6XFoiBhwv4/Jo8S0ijp8HfeFWS0YOQo4/+4m8/cAgaSM+Xg+ zG+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=bvZnEkqCrkCmp9qJISWK0AIU8xy+Pk1MuXzxNLLBuoo=; b=F24aBSImLd84Ny3Qul0vhDlCglCs4a1MjZAf33LUTUQPwRhhJY59Dgg3rOP0Q4mZHu Iw05SfwQEfmv5wfGRs1FTV3luGGd4nQgdgv5ZRBgAwsLx4YUrf1hGdynPFiLnczw4b25 VGVUERxbrwB7kP/RHlOZklloC6dFx4B8bts7433Mmhj9eUiAktuTmtE9xCQ5Eku8dvqc J3ufNepIHUk+xTTWLIXRjnCs6SyXMFO0GCovEhAeQCpll6lBrtrvSxX3AmYaL3XQTdLw yx2/W+Bb5T0XW1IZbuOT1T6teTHVc3HBUzzeeCQth2SS5LF2yyX9WYwIJ0vUlcFhumEI YnIw== X-Gm-Message-State: ACgBeo06cDuzbexCJH9pOm5oLaD1A6TBOY2NYxbYi1zriQ+aTzXTcU1y qfsUjdKWGuhivwKJCzlyvmXbn3y1C2BVdw== X-Received: by 2002:a17:906:4fd2:b0:742:133b:3522 with SMTP id i18-20020a1709064fd200b00742133b3522mr25572256ejw.21.1662457039426; Tue, 06 Sep 2022 02:37:19 -0700 (PDT) Received: from localhost.localdomain ([46.103.15.185]) by smtp.gmail.com with ESMTPSA id g2-20020a056402428200b004478be33bddsm7905546edc.15.2022.09.06.02.37.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 02:37:19 -0700 (PDT) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: etienne.carriere@linaro.org, Ilias Apalodimas , Jens Wiklander , Patrick Delaunay Subject: [PATCH v4] tee: optee: rework TA bus scanning code Date: Tue, 6 Sep 2022 12:37:03 +0300 Message-Id: <20220906093703.35658-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.37.2 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 Late versions of OP-TEE support a pseudo bus. TAs that behave as hardware blocks (e.g TPM, RNG etc) present themselves on a bus which we can scan. Unfortunately U-Boot doesn't support that yet. It's worth noting that we already have a workaround for RNG. The details are in commit 70812bb83da6 ("tee: optee: bind rng optee driver") So let's add a list of devices based on U-Boot Kconfig options that we will scan until we properly implement the tee-bus functionality. While at it change the behaviour of the tee core itself wrt to device binding. If some device binding fails, print a warning instead of disabling OP-TEE. Signed-off-by: Ilias Apalodimas Reviewed-by: Jens Wiklander Reviewed-by: Etienne Carriere Reviewed-by: Patrick Delaunay --- Changes since v3: - Use NULL instead of a child ptr on device_bind_driver(), since it's not really needed - Changed the style of the optee_bus_probe[] definition to {.drv_name = xxx, .dev_name = yyy } Changes since v2: - Fixed typo on driver name ftpm-tee -> ftpm_tee Changes since v1: - remove a macro and use ARRAY_SIZE directly drivers/tee/optee/core.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c index a89d62aaf0b3..c201a4635e6b 100644 --- a/drivers/tee/optee/core.c +++ b/drivers/tee/optee/core.c @@ -31,6 +31,18 @@ struct optee_pdata { optee_invoke_fn *invoke_fn; }; +static const struct { + const char *drv_name; + const char *dev_name; +} optee_bus_probe[] = { +#ifdef CONFIG_RNG_OPTEE + { .drv_name = "optee-rng", .dev_name = "optee-rng" }, +#endif +#ifdef CONFIG_TPM2_FTPM_TEE + { .drv_name = "ftpm_tee", .dev_name = "ftpm_tee" }, +#endif +}; + struct rpc_param { u32 a0; u32 a1; @@ -642,8 +654,7 @@ static int optee_probe(struct udevice *dev) { struct optee_pdata *pdata = dev_get_plat(dev); u32 sec_caps; - struct udevice *child; - int ret; + int ret, i; if (!is_optee_api(pdata->invoke_fn)) { dev_err(dev, "OP-TEE api uid mismatch\n"); @@ -672,10 +683,13 @@ static int optee_probe(struct udevice *dev) * 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)) { - ret = device_bind_driver(dev, "optee-rng", "optee-rng", &child); + + for (i = 0; i < ARRAY_SIZE(optee_bus_probe); i++) { + ret = device_bind_driver(dev, optee_bus_probe[i].drv_name, + optee_bus_probe[i].dev_name, NULL); if (ret) - return ret; + dev_warn(dev, "Failed to bind device %s\n", + optee_bus_probe[i].dev_name); } return 0;