[PATCH v3] tee: optee: build the Arm-specific code only on Arm
Marouene Boubakri (OSS)
marouene.boubakri at oss.nxp.com
Thu Sep 24 03:40:30 PDT 2026
Agreed, folded in and posted as v4 https://lore.kernel.org/all/20260924105145.532787-1-marouene.boubakri@oss.nxp.com/, with the commit message adjusted. Thanks, Marouene
NXP Confidential
-----Original Message-----
From: Jens Wiklander <jens.wiklander at oss.qualcomm.com>
Sent: Wednesday, September 23, 2026 4:04 PM
To: Marouene Boubakri (OSS) <marouene.boubakri at oss.nxp.com>
Cc: jenswi at kernel.org; sumit.garg at kernel.org; op-tee at lists.trustedfirmware.org; linux-kernel at vger.kernel.org; linux-riscv at lists.infradead.org; amirreza.zarrabi at oss.qualcomm.com; peter.lin at sifive.com
Subject: Re: [PATCH v3] tee: optee: build the Arm-specific code only on Arm
[You don't often get email from jens.wiklander at oss.qualcomm.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
Hi,
On Tue, Sep 22, 2026 at 3:03 PM <marouene.boubakri at oss.nxp.com> wrote:
>
> From: Marouene Boubakri <marouene.boubakri at oss.nxp.com>
>
> The OP-TEE driver reaches OP-TEE through the SMC ABI or the FF-A ABI,
> both specific to Arm, yet builds both unconditionally together with
> the SMC Calling Convention definitions they rely on: ffa_abi.c is
> always compiled and only its registration is conditioned on
> IS_REACHABLE(CONFIG_ARM_FFA_TRANSPORT), and optee_private.h includes
> <linux/arm-smccc.h> and defines the SMC and FF-A specific types for
> every file of the driver. This is fine as long as the driver depends
> on HAVE_ARM_SMCCC, but it keeps the driver from being built for an
> architecture without SMCCC, such as RISC-V.
>
> Build smc_abi.c only when HAVE_ARM_SMCCC is set and ffa_abi.c only
> when the FF-A transport is reachable, and provide stubs for their
> registration otherwise, so that it fails with -EOPNOTSUPP as the FF-A
> ABI already does when the FF-A transport is not reachable. Keep the
> SMCCC header, the SMC invoke function type, the SMC and FF-A specific
> structures and the SMC RPC register parameters in optee_private.h
> under the same conditions, and drop the unused <linux/arm-smccc.h>
> include from notif.c.
>
> The FF-A parts are keyed on IS_REACHABLE() rather than IS_ENABLED() to
> preserve the behaviour of a built-in driver with a modular FF-A
> transport: kbuild does not link the optee-m objects into a built-in
> optee.o, so ffa_abi.c is left out exactly when the transport is not
> reachable and the stubs are used instead. The IS_REACHABLE() checks in
> optee_ffa_abi_register() and optee_ffa_abi_unregister() are always
> true once ffa_abi.c is only compiled in that case, so drop them.
>
> No functional change: OPTEE still depends on HAVE_ARM_SMCCC, and
> ffa_abi.c is still built whenever the FF-A ABI can be registered.
>
> Signed-off-by: Marouene Boubakri <marouene.boubakri at oss.nxp.com>
> ---
> Changes in v3:
> - Dropped the RPMI ABI placeholder and the RISC-V enablement patches,
> this is now a single patch (Jens).
> - Key the FF-A parts of optee_private.h on IS_REACHABLE() instead of
> IS_ENABLED(): with OPTEE=y and ARM_FFA_TRANSPORT=m kbuild drops
> ffa_abi.o from the built-in optee.o while optee_ffa_abi_register()
> was still declared, which does not link.
> - Drop the now always true IS_REACHABLE() checks in
> optee_ffa_abi_register() and optee_ffa_abi_unregister().
> - Describe the current FF-A conditional compilation accurately in the
> commit message.
> - Posted as a new thread with a proper subject prefix.
> v2:
> https://lore.kernel.org/op-tee/20260915020235.507302-2-marouene.boubak
> ri at oss.nxp.com/
>
> Changes in v2:
> - No code change, the testing section of the cover letter was completed.
> v1: https://lore.kernel.org/op-tee/20260914175435.118303-2-marouene.boubakri@oss.nxp.com/
> drivers/tee/optee/Makefile | 4 ++--
> drivers/tee/optee/ffa_abi.c | 8 ++-----
> drivers/tee/optee/notif.c | 1 -
> drivers/tee/optee/optee_private.h | 39
> ++++++++++++++++++++++++++++++-
> 4 files changed, 42 insertions(+), 10 deletions(-)
Looks good, but I think that while we're at it, we should add
--- a/drivers/tee/optee/Kconfig
+++ b/drivers/tee/optee/Kconfig
@@ -5,6 +5,7 @@ config OPTEE
depends on HAVE_ARM_SMCCC
depends on MMU
depends on RPMB || !RPMB
+ depends on ARM_FFA_TRANSPORT || !ARM_FFA_TRANSPORT
help
This implements the OP-TEE Trusted Execution Environment (TEE)
driver.
to make the optee driver a module if the FF-A transport is a module.
Cheers,
Jens
>
> diff --git a/drivers/tee/optee/Makefile b/drivers/tee/optee/Makefile
> index ad7049c..183cdde 100644
> --- a/drivers/tee/optee/Makefile
> +++ b/drivers/tee/optee/Makefile
> @@ -7,8 +7,8 @@ optee-objs += rpc.o
> optee-objs += protmem.o
> optee-objs += supp.o
> optee-objs += device.o
> -optee-objs += smc_abi.o
> -optee-objs += ffa_abi.o
> +optee-$(CONFIG_HAVE_ARM_SMCCC) += smc_abi.o
> +optee-$(CONFIG_ARM_FFA_TRANSPORT) += ffa_abi.o
>
> # for tracing framework to find optee_trace.h CFLAGS_smc_abi.o :=
> -I$(src) diff --git a/drivers/tee/optee/ffa_abi.c
> b/drivers/tee/optee/ffa_abi.c index 633715b..08236d8 100644
> --- a/drivers/tee/optee/ffa_abi.c
> +++ b/drivers/tee/optee/ffa_abi.c
> @@ -1212,14 +1212,10 @@ static struct ffa_driver optee_ffa_driver = {
>
> int optee_ffa_abi_register(void)
> {
> - if (IS_REACHABLE(CONFIG_ARM_FFA_TRANSPORT))
> - return ffa_register(&optee_ffa_driver);
> - else
> - return -EOPNOTSUPP;
> + return ffa_register(&optee_ffa_driver);
> }
>
> void optee_ffa_abi_unregister(void)
> {
> - if (IS_REACHABLE(CONFIG_ARM_FFA_TRANSPORT))
> - ffa_unregister(&optee_ffa_driver);
> + ffa_unregister(&optee_ffa_driver);
> }
> diff --git a/drivers/tee/optee/notif.c b/drivers/tee/optee/notif.c
> index 6e85f2f..6801422 100644
> --- a/drivers/tee/optee/notif.c
> +++ b/drivers/tee/optee/notif.c
> @@ -5,7 +5,6 @@
>
> #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
>
> -#include <linux/arm-smccc.h>
> #include <linux/errno.h>
> #include <linux/slab.h>
> #include <linux/spinlock.h>
> diff --git a/drivers/tee/optee/optee_private.h
> b/drivers/tee/optee/optee_private.h
> index aefe1e6..02d6f79 100644
> --- a/drivers/tee/optee/optee_private.h
> +++ b/drivers/tee/optee/optee_private.h
> @@ -6,7 +6,6 @@
> #ifndef OPTEE_PRIVATE_H
> #define OPTEE_PRIVATE_H
>
> -#include <linux/arm-smccc.h>
> #include <linux/notifier.h>
> #include <linux/rhashtable.h>
> #include <linux/rpmb.h>
> @@ -15,6 +14,10 @@
> #include <linux/types.h>
> #include "optee_msg.h"
>
> +#ifdef CONFIG_HAVE_ARM_SMCCC
> +#include <linux/arm-smccc.h>
> +#endif
> +
> #define DRIVER_NAME "optee"
>
> #define OPTEE_MAX_ARG_SIZE 1024
> @@ -42,10 +45,12 @@
> */
> #define OPTEE_DEFAULT_MAX_NOTIF_VALUE 255
>
> +#ifdef CONFIG_HAVE_ARM_SMCCC
> typedef void (optee_invoke_fn)(unsigned long, unsigned long, unsigned long,
> unsigned long, unsigned long, unsigned long,
> unsigned long, unsigned long,
> struct arm_smccc_res *);
> +#endif
>
> /**
> * struct optee_call_waiter - TEE entry may need to wait for a free
> TEE thread @@ -119,6 +124,7 @@ struct optee_supp {
> struct completion reqs_c;
> };
>
> +#ifdef CONFIG_HAVE_ARM_SMCCC
> /**
> * struct optee_pcpu - per cpu notif private struct passed to work functions
> * @optee: optee device reference
> @@ -149,7 +155,9 @@ struct optee_smc {
> struct work_struct notif_pcpu_work;
> unsigned int notif_cpuhp_state; };
> +#endif
>
> +#if IS_REACHABLE(CONFIG_ARM_FFA_TRANSPORT)
> /**
> * struct optee_ffa - FFA communication struct
> * @ffa_dev: FFA device, contains the destination id, the id of
> @@ -170,6 +178,7 @@ struct optee_ffa {
> struct workqueue_struct *notif_wq;
> struct work_struct notif_work;
> };
> +#endif
>
> struct optee;
>
> @@ -257,8 +266,12 @@ struct optee {
> const struct optee_ops *ops;
> struct tee_context *ctx;
> union {
> +#ifdef CONFIG_HAVE_ARM_SMCCC
> struct optee_smc smc;
> +#endif
> +#if IS_REACHABLE(CONFIG_ARM_FFA_TRANSPORT)
> struct optee_ffa ffa;
> +#endif
> };
> struct optee_shm_arg_cache shm_arg_cache;
> struct optee_call_queue call_queue;
> @@ -290,6 +303,7 @@ struct optee_context_data {
> struct list_head sess_list;
> };
>
> +#ifdef CONFIG_HAVE_ARM_SMCCC
> struct optee_rpc_param {
> u32 a0;
> u32 a1;
> @@ -300,6 +314,7 @@ struct optee_rpc_param {
> u32 a6;
> u32 a7;
> };
> +#endif
>
> /* Holds context that is preserved during one STD call */
> struct optee_call_ctx {
> @@ -422,9 +437,31 @@ static inline void reg_pair_from_64(u32 *reg0, u32 *reg1, u64 val)
> }
>
> /* Registration of the ABIs */
> +#ifdef CONFIG_HAVE_ARM_SMCCC
> int optee_smc_abi_register(void);
> void optee_smc_abi_unregister(void);
> +#else
> +static inline int optee_smc_abi_register(void)
> +{
> + return -EOPNOTSUPP;
> +}
> +
> +static inline void optee_smc_abi_unregister(void)
> +{
> +}
> +#endif
> +#if IS_REACHABLE(CONFIG_ARM_FFA_TRANSPORT)
> int optee_ffa_abi_register(void);
> void optee_ffa_abi_unregister(void);
> +#else
> +static inline int optee_ffa_abi_register(void)
> +{
> + return -EOPNOTSUPP;
> +}
> +
> +static inline void optee_ffa_abi_unregister(void)
> +{
> +}
> +#endif
>
> #endif /*OPTEE_PRIVATE_H*/
>
> base-commit: 827751b699b79a6e569983359c02dce67f81b94c
> --
> 2.43.0
>
More information about the linux-riscv
mailing list