u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] tee: optee: rework TA bus scanning code
@ 2022-08-29  6:33 Ilias Apalodimas
  2022-08-31  5:59 ` Jens Wiklander
  0 siblings, 1 reply; 5+ messages in thread
From: Ilias Apalodimas @ 2022-08-29  6:33 UTC (permalink / raw)
  To: u-boot
  Cc: etienne.carriere, Ilias Apalodimas, Jens Wiklander, Patrick Delaunay

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 <ilias.apalodimas@linaro.org>
---
Changes since v1:
- remove a macro and use ARRAY_SIZE directly
- print a warning instead of disabling op-tee if a driver binding fails

 drivers/tee/optee/core.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c
index a89d62aaf0b3..3cc92f09d299 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
+	{ "optee-rng", "optee-rng" },
+#endif
+#ifdef CONFIG_TPM2_FTPM_TEE
+	{ "ftpm-tee", "ftpm-tee" },
+#endif
+};
+
 struct rpc_param {
 	u32	a0;
 	u32	a1;
@@ -643,7 +655,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 +684,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, &child);
 		if (ret)
-			return ret;
+			dev_warn(dev, "Failed to bind device %s\n",
+				 optee_bus_probe[i].dev_name);
 	}
 
 	return 0;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] tee: optee: rework TA bus scanning code
  2022-08-29  6:33 [PATCH v2] tee: optee: rework TA bus scanning code Ilias Apalodimas
@ 2022-08-31  5:59 ` Jens Wiklander
  2022-09-02 19:11   ` Ilias Apalodimas
  0 siblings, 1 reply; 5+ messages in thread
From: Jens Wiklander @ 2022-08-31  5:59 UTC (permalink / raw)
  To: Ilias Apalodimas; +Cc: u-boot, etienne.carriere, Patrick Delaunay

On Mon, Aug 29, 2022 at 8:34 AM Ilias Apalodimas
<ilias.apalodimas@linaro.org> wrote:
>
> 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 <ilias.apalodimas@linaro.org>
> ---

Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>

Cheers,
Jens

> Changes since v1:
> - remove a macro and use ARRAY_SIZE directly
> - print a warning instead of disabling op-tee if a driver binding fails
>
>  drivers/tee/optee/core.c | 23 +++++++++++++++++++----
>  1 file changed, 19 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c
> index a89d62aaf0b3..3cc92f09d299 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
> +       { "optee-rng", "optee-rng" },
> +#endif
> +#ifdef CONFIG_TPM2_FTPM_TEE
> +       { "ftpm-tee", "ftpm-tee" },
> +#endif
> +};
> +
>  struct rpc_param {
>         u32     a0;
>         u32     a1;
> @@ -643,7 +655,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 +684,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, &child);
>                 if (ret)
> -                       return ret;
> +                       dev_warn(dev, "Failed to bind device %s\n",
> +                                optee_bus_probe[i].dev_name);
>         }
>
>         return 0;
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] tee: optee: rework TA bus scanning code
  2022-08-31  5:59 ` Jens Wiklander
@ 2022-09-02 19:11   ` Ilias Apalodimas
  2022-09-05  9:23     ` Etienne Carriere
  2022-09-06  6:20     ` Jens Wiklander
  0 siblings, 2 replies; 5+ messages in thread
From: Ilias Apalodimas @ 2022-09-02 19:11 UTC (permalink / raw)
  To: Jens Wiklander; +Cc: u-boot, etienne.carriere, Patrick Delaunay

Thanks Jens

On Wed, 31 Aug 2022 at 08:59, Jens Wiklander <jens.wiklander@linaro.org> wrote:
>
> On Mon, Aug 29, 2022 at 8:34 AM Ilias Apalodimas
> <ilias.apalodimas@linaro.org> wrote:
> >
> > 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 <ilias.apalodimas@linaro.org>
> > ---
>
> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>

There's a typo in that patch. For the tpm to work the string needs to
be ftpm_tee instead of ftpm-tee.  I'll send a v3, shall I keep your
RB?

Cheers
/Ilias
>
> Cheers,
> Jens
>
> > Changes since v1:
> > - remove a macro and use ARRAY_SIZE directly
> > - print a warning instead of disabling op-tee if a driver binding fails
> >
> >  drivers/tee/optee/core.c | 23 +++++++++++++++++++----
> >  1 file changed, 19 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c
> > index a89d62aaf0b3..3cc92f09d299 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
> > +       { "optee-rng", "optee-rng" },
> > +#endif
> > +#ifdef CONFIG_TPM2_FTPM_TEE
> > +       { "ftpm-tee", "ftpm-tee" },
> > +#endif
> > +};
> > +
> >  struct rpc_param {
> >         u32     a0;
> >         u32     a1;
> > @@ -643,7 +655,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 +684,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, &child);
> >                 if (ret)
> > -                       return ret;
> > +                       dev_warn(dev, "Failed to bind device %s\n",
> > +                                optee_bus_probe[i].dev_name);
> >         }
> >
> >         return 0;
> > --
> > 2.34.1
> >

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] tee: optee: rework TA bus scanning code
  2022-09-02 19:11   ` Ilias Apalodimas
@ 2022-09-05  9:23     ` Etienne Carriere
  2022-09-06  6:20     ` Jens Wiklander
  1 sibling, 0 replies; 5+ messages in thread
From: Etienne Carriere @ 2022-09-05  9:23 UTC (permalink / raw)
  To: Ilias Apalodimas; +Cc: Jens Wiklander, u-boot, Patrick Delaunay

Hi Ilias,

Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> with minor comments.

On Fri, 2 Sept 2022 at 21:11, Ilias Apalodimas
<ilias.apalodimas@linaro.org> wrote:
>
> Thanks Jens
>
> On Wed, 31 Aug 2022 at 08:59, Jens Wiklander <jens.wiklander@linaro.org> wrote:
> >
> > On Mon, Aug 29, 2022 at 8:34 AM Ilias Apalodimas
> > <ilias.apalodimas@linaro.org> wrote:
> > >
> > > 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 <ilias.apalodimas@linaro.org>
> > > ---
> >
> > Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
>
> There's a typo in that patch. For the tpm to work the string needs to
> be ftpm_tee instead of ftpm-tee.  I'll send a v3, shall I keep your
> RB?
>
> Cheers
> /Ilias
> >
> > Cheers,
> > Jens
> >
> > > Changes since v1:
> > > - remove a macro and use ARRAY_SIZE directly
> > > - print a warning instead of disabling op-tee if a driver binding fails
> > >
> > >  drivers/tee/optee/core.c | 23 +++++++++++++++++++----
> > >  1 file changed, 19 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c
> > > index a89d62aaf0b3..3cc92f09d299 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
> > > +       { "optee-rng", "optee-rng" },

By the way, prefer:
+       { .drv_name = "optee-rng", .dev_name = "optee-rng" },


> > > +#endif
> > > +#ifdef CONFIG_TPM2_FTPM_TEE
> > > +       { "ftpm-tee", "ftpm-tee" },
> > > +#endif
> > > +};
> > > +
> > >  struct rpc_param {
> > >         u32     a0;
> > >         u32     a1;
> > > @@ -643,7 +655,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 +684,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, &child);

Can drop child here. NULL is fine.

> > >                 if (ret)
> > > -                       return ret;
> > > +                       dev_warn(dev, "Failed to bind device %s\n",
> > > +                                optee_bus_probe[i].dev_name);
> > >         }
> > >
> > >         return 0;
> > > --
> > > 2.34.1
> > >

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] tee: optee: rework TA bus scanning code
  2022-09-02 19:11   ` Ilias Apalodimas
  2022-09-05  9:23     ` Etienne Carriere
@ 2022-09-06  6:20     ` Jens Wiklander
  1 sibling, 0 replies; 5+ messages in thread
From: Jens Wiklander @ 2022-09-06  6:20 UTC (permalink / raw)
  To: Ilias Apalodimas; +Cc: u-boot, etienne.carriere, Patrick Delaunay

On Fri, Sep 2, 2022 at 9:11 PM Ilias Apalodimas
<ilias.apalodimas@linaro.org> wrote:
>
> Thanks Jens
>
> On Wed, 31 Aug 2022 at 08:59, Jens Wiklander <jens.wiklander@linaro.org> wrote:
> >
> > On Mon, Aug 29, 2022 at 8:34 AM Ilias Apalodimas
> > <ilias.apalodimas@linaro.org> wrote:
> > >
> > > 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 <ilias.apalodimas@linaro.org>
> > > ---
> >
> > Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
>
> There's a typo in that patch. For the tpm to work the string needs to
> be ftpm_tee instead of ftpm-tee.  I'll send a v3, shall I keep your
> RB?

Yes, please.

Cheers,
Jens

>
> Cheers
> /Ilias
> >
> > Cheers,
> > Jens
> >
> > > Changes since v1:
> > > - remove a macro and use ARRAY_SIZE directly
> > > - print a warning instead of disabling op-tee if a driver binding fails
> > >
> > >  drivers/tee/optee/core.c | 23 +++++++++++++++++++----
> > >  1 file changed, 19 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c
> > > index a89d62aaf0b3..3cc92f09d299 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
> > > +       { "optee-rng", "optee-rng" },
> > > +#endif
> > > +#ifdef CONFIG_TPM2_FTPM_TEE
> > > +       { "ftpm-tee", "ftpm-tee" },
> > > +#endif
> > > +};
> > > +
> > >  struct rpc_param {
> > >         u32     a0;
> > >         u32     a1;
> > > @@ -643,7 +655,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 +684,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, &child);
> > >                 if (ret)
> > > -                       return ret;
> > > +                       dev_warn(dev, "Failed to bind device %s\n",
> > > +                                optee_bus_probe[i].dev_name);
> > >         }
> > >
> > >         return 0;
> > > --
> > > 2.34.1
> > >

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-09-06  6:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-29  6:33 [PATCH v2] tee: optee: rework TA bus scanning code Ilias Apalodimas
2022-08-31  5:59 ` Jens Wiklander
2022-09-02 19:11   ` Ilias Apalodimas
2022-09-05  9:23     ` Etienne Carriere
2022-09-06  6:20     ` Jens Wiklander

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).