From patchwork Fri Jun 17 15:36:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 1644886 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=syipEGAj; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LPjqB3pPsz9sG0 for ; Sat, 18 Jun 2022 01:37:58 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5193D843F0; Fri, 17 Jun 2022 17:37: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="syipEGAj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E99898440B; Fri, 17 Jun 2022 17:37: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, 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 AF16B84319 for ; Fri, 17 Jun 2022 17:37: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-x430.google.com with SMTP id q9so6236287wrd.8 for ; Fri, 17 Jun 2022 08:37: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=C9QNHmZIhfZ+GobcR03ULZYs94+/K0SQBBGunHdDqIg=; b=syipEGAjJlw7eLWVMwWljuX+ZiOLCPyfyVSJ5bHlqpHoP6+DcABicR3lrBuMRo6RC6 wooYFZKssU5AX4xk5HC6L0u0VRwbVDP/2Zrw7vd3g94YQKMj5aEnJe1j1nyo0X/sbQzq YSE1iau6xQpIJgwRGiOuMDwPMNrZSL5iWJno2aVQO7+7DBx0eOJkDyrLjypYoseFHjZo Mdc5ysIVW8EzW/gbyA6cRuWwpjCgbAZgRrefwufU8246PYNY2z6l264/wFvAtpJFDu0l BMdbdsh68HScCrQtWymBNrxs5r8ZqaJpCMLqbP1lRK+W5s9TbQl5JIpcC94uWq9P7qXa CC2w== 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=C9QNHmZIhfZ+GobcR03ULZYs94+/K0SQBBGunHdDqIg=; b=WBu6iFoS2mo48XU/iGq/YzS1pFrOuWu99XMJwwzd94QFVD0HvjlU9+o+oXWguEvM5v f6ppHyf1XpgDJLtBOG4T6JrjMlVO8tRKMleDZFi8eYNk2c786DRFmGYVcoXcx37XhUYp hlmn/6S8q8l+28CgxKBgmQSlhICe8T5tOL9+P0AbYe6KCd2NVzKww/9NhP3ttflbmCsG TInf5aAL6oQtYm2ao4cjw9ksXBrIDyn0fhaYzBaBTerrtwd1MnvMLUEpvt7T7bEPU/6z LVlcmOVIt+yTtY6+F9pUPsntlFOL/2MsH4f5j5C2YG1loNzRchjizTDiwW16Xn6uKxik xeQQ== X-Gm-Message-State: AJIora8feSUjPlYs5AUGYuUxK3m9KfXjUx0Tp/DlJNiqWS6zIxQKw7CR pD2qDSK+FNHIwk85YEjlsBpKEBcvCjfs4Q== X-Google-Smtp-Source: AGRyM1vy5Lu4qPVCuiTILjK+LP95rgdgi1v9H9wdfrpuJB1BdtmioFS96EvFqQhhLhPfipCT4eZZHA== X-Received: by 2002:a05:6000:186f:b0:213:4ece:4086 with SMTP id d15-20020a056000186f00b002134ece4086mr10115009wri.438.1655480262927; Fri, 17 Jun 2022 08:37:42 -0700 (PDT) Received: from lmecxl1178.lme.st.com ([2a04:cec0:1019:294c:22b8:b283:9bfe:2096]) by smtp.gmail.com with ESMTPSA id m13-20020a5d4a0d000000b0021a2c923c72sm5069545wrq.69.2022.06.17.08.37.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jun 2022 08:37:42 -0700 (PDT) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Etienne Carriere , Patrick Delaunay Subject: [PATCH v4 1/3] drivers: tee: optee: remove unused probe local variable Date: Fri, 17 Jun 2022 17:36:51 +0200 Message-Id: <20220617153653.1307687-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 Reviewed-by: Patrick Delaunay Signed-off-by: Etienne Carriere --- 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 Fri Jun 17 15:36:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 1644887 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=wlMUZA3I; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LPjqF6rbmz9sG0 for ; Sat, 18 Jun 2022 01:38:01 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 295CA84405; Fri, 17 Jun 2022 17:37:50 +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="wlMUZA3I"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8072D843F2; Fri, 17 Jun 2022 17:37: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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) (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 BA2AA843F2 for ; Fri, 17 Jun 2022 17:37: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-wm1-x32d.google.com with SMTP id l2-20020a05600c4f0200b0039c55c50482so4583513wmq.0 for ; Fri, 17 Jun 2022 08:37: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=5O4w3CvMa6C//gylgKvaaQnnaaH9NXBwQY0vyJHobjA=; b=wlMUZA3IiAUuMzece6ov14+iEbi4AKQ/Cgj+IL3q6ftETjzAVZDLJEWqB+RE2r/ktM GMabjvEchfZ3qE3RAWqVg6/QIWfIVDUJqDsuVr9zWj73B97E4/JZ0/6zQmrLGKWkL/Qn jsXse2iNd7VELdLs0rNGZrIDd6OP2n8KE2ulXC1RDR3pymiMbVHJTWI1A7U7SYKRrMFN 1FQcnzGnsL4Rzh4krrhZFxUg8KQ7Y2ji0rgF16DmU14e4w7ALsMBFE610Oy5orKYzd4n bX/XBpKE6amRQOPmVpEgbfEo3TUecGK+eg/Whr8MmGxSvHMy+wYh1/mRP+XUdcYA8FBf OXbA== 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=5O4w3CvMa6C//gylgKvaaQnnaaH9NXBwQY0vyJHobjA=; b=IHIXmT0rAfe766wIUedgWZ92ZPf9l4JKmaA9VbHrisE8XUTPI4kXoOooW8wkwSqWZ2 BIXrhrdm6RNd4t59n/s4y/dCCfoCoYKwVXOaDXhnaXLGcYDO81uDdKkMrmsy2XbQ2BAp EADRZZiQqJ6/Xtw8lkBXBh53i8Zw1dYBYHKqknh+rDeX/V/ATRETR13iCcdlPJsVfQMB KPgt6jW3mgLTJABB4sut0UJJ5Pn5xVHbZdhcptGqzWcVfADRAkW4DbSs6ziV/BT5QZme BEL2WsIR1+2iiHhwm3sqB50HpljrGJNqjNeoOsEhO9pSaANPoaEH/L+r0YVPNJXTOjUZ dRYQ== X-Gm-Message-State: AJIora/9t8TpBU1LIGlxuYCy4TZInUNdYcEuv6Oj0LGxrS94477T/f6d 5l5GWlds5ugkpkQahwIb59L+LMKZ4wsOOw== X-Google-Smtp-Source: AGRyM1veW0uZMvllJP+miPFoWzOY5CDnp4g7hf7Ijx9ZRgqhQDXhPX3WvQ9zdTRWQ+/m6qQIy1wUbw== X-Received: by 2002:a7b:c4d4:0:b0:39c:5bb7:2210 with SMTP id g20-20020a7bc4d4000000b0039c5bb72210mr10663174wmk.99.1655480263936; Fri, 17 Jun 2022 08:37:43 -0700 (PDT) Received: from lmecxl1178.lme.st.com ([2a04:cec0:1019:294c:22b8:b283:9bfe:2096]) by smtp.gmail.com with ESMTPSA id m13-20020a5d4a0d000000b0021a2c923c72sm5069545wrq.69.2022.06.17.08.37.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jun 2022 08:37:43 -0700 (PDT) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Etienne Carriere , Jens Wiklander , Patrick Delaunay Subject: [PATCH v4 2/3] drivers: tee: optee: discover OP-TEE services Date: Fri, 17 Jun 2022 17:36:52 +0200 Message-Id: <20220617153653.1307687-2-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220617153653.1307687-1-etienne.carriere@linaro.org> References: <20220617153653.1307687-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 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..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..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 Fri Jun 17 15:36:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 1644888 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Kxj+1DWd; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LPjqZ10Rhz9sG0 for ; Sat, 18 Jun 2022 01:38:17 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0E39884419; Fri, 17 Jun 2022 17:37: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="Kxj+1DWd"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3F7DE843F2; Fri, 17 Jun 2022 17:37: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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) (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 A135484400 for ; Fri, 17 Jun 2022 17:37: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-wm1-x32b.google.com with SMTP id m16-20020a7bca50000000b0039c8a224c95so2590300wml.2 for ; Fri, 17 Jun 2022 08:37: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=FRtFCuAAMd0KZp44WuTAEljjQ3FEsQzSVsCbT01QCCU=; b=Kxj+1DWddEbjJ01MAyoP9pb7UVDNqw9+t1CYtXeb+Ri7CuHw/FkkeCnhp9sRRcCEjt PMolys5pASwz4qVyM5fba8ke4GXrryfse7HOBndzj1o2hP6r1iGHLwv61wtqi9trKk1I 9jS1KDVOlCfclk7PlrnKTOHcGTarHFVf589LeEUksWZiO4b6WGQ6NYK/xYnldXXCEvEU SCSi/W6yqPvuyWs80LQjFLwAAqrpav5sRKQzoVv5PqnZYqCaSEoQ6TIPHEfyArXa4Dmn We59ugRySsfvig0l5iG4wrn47QNiwjnd2yN2+0jE465oe6YnVmah7FoE6Uft4GSA+BJ0 NBGQ== 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=FRtFCuAAMd0KZp44WuTAEljjQ3FEsQzSVsCbT01QCCU=; b=U7iay55yE1Q0DLBcEHGW0PiyI0hWVK9vsMKqwS1EX2RCQNqEBd6OsSIduYm1fbu3Ho RvAWVSe78/tW7X4kd88RLNNXAm85Y4Nd4YPEC7Wm1Yn9TNHUCArrFZZbL1UUnO1ePf6U TP3JIN1FJVACjGMtQwxjbK3FbzaFgxigyahlZgjy6k1SUPuh2dSFj2Qs2go+dFnZw1SW nhiYfYRAU0VIE+iL3ZXojDXzoXmzUq6Yb+/qjZ4wJ3BtPfN4BivS9zIMcZOtevzbnfFj 5A7e5wWB+limYcBzPykSbb4bWLfZBIoNTRg5gZTUrc0RJ4OkX586bOGKWPlzFU5R1d45 9bcw== X-Gm-Message-State: AJIora8k73iUIO70cSmoxdBEgWkDv8CBrTtBOptqKJms/d28114FcC5P aTpe7iOwouyIUWwSj+eVD6fvhK+Ciq47/Q== X-Google-Smtp-Source: AGRyM1tpVXQWAtqUMmMPCvSJeJ4zXMX4FbULk606wmAPzQF7J2GFd8z0FbEy/GFFDOi84qiudRu2Xw== X-Received: by 2002:a05:600c:1990:b0:39c:9469:5217 with SMTP id t16-20020a05600c199000b0039c94695217mr10856098wmq.49.1655480264947; Fri, 17 Jun 2022 08:37:44 -0700 (PDT) Received: from lmecxl1178.lme.st.com ([2a04:cec0:1019:294c:22b8:b283:9bfe:2096]) by smtp.gmail.com with ESMTPSA id m13-20020a5d4a0d000000b0021a2c923c72sm5069545wrq.69.2022.06.17.08.37.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jun 2022 08:37:44 -0700 (PDT) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Etienne Carriere , Sughosh Ganu , Patrick Delaunay Subject: [PATCH v4 3/3] drivers: rng: optee_rng: register to CONFIG_OPTEE_SERVICE_DISCOVERY Date: Fri, 17 Jun 2022 17:36:53 +0200 Message-Id: <20220617153653.1307687-3-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220617153653.1307687-1-etienne.carriere@linaro.org> References: <20220617153653.1307687-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 --- 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 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..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,