diff mbox series

tee: optee: rework TA bus scanning code

Message ID 20220823081141.344833-1-ilias.apalodimas@linaro.org
State New
Headers show
Series tee: optee: rework TA bus scanning code | expand

Commit Message

Ilias Apalodimas Aug. 23, 2022, 8:11 a.m. UTC
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.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
---
 drivers/tee/optee/core.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

Comments

Jens Wiklander Aug. 26, 2022, 8:46 a.m. UTC | #1
On Tue, Aug 23, 2022 at 10:11 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.
>
> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> ---
>  drivers/tee/optee/core.c | 22 +++++++++++++++++++---
>  1 file changed, 19 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c
> index a89d62aaf0b3..48a9b59171cb 100644
> --- a/drivers/tee/optee/core.c
> +++ b/drivers/tee/optee/core.c
> @@ -31,6 +31,20 @@ 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
> +};
> +
> +#define MAX_TEE_BUS_DEV_COUNT ARRAY_SIZE(optee_bus_probe)
> +
>  struct rpc_param {
>         u32     a0;
>         u32     a1;
> @@ -643,7 +657,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,8 +686,10 @@ 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 < MAX_TEE_BUS_DEV_COUNT; i++) {
> +               ret = device_bind_driver(dev, optee_bus_probe[i].drv_name,
> +                                        optee_bus_probe[i].dev_name, &child);
>                 if (ret)
>                         return ret;

I wonder which behaviour is most useful. Disable OP-TEE support
completely if there's some error when binding dependent drivers or to
just complain a bit but continue.

Cheers,
Jens


>
>         }
> --
> 2.34.1
>
Etienne Carriere Aug. 26, 2022, 9:07 a.m. UTC | #2
Hello Ilias, Jens,

On Fri, 26 Aug 2022 at 10:46, Jens Wiklander <jens.wiklander@linaro.org> wrote:
>
> On Tue, Aug 23, 2022 at 10:11 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.
> >
> > Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> > ---
> >  drivers/tee/optee/core.c | 22 +++++++++++++++++++---
> >  1 file changed, 19 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c
> > index a89d62aaf0b3..48a9b59171cb 100644
> > --- a/drivers/tee/optee/core.c
> > +++ b/drivers/tee/optee/core.c
> > @@ -31,6 +31,20 @@ 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
> > +};
> > +
> > +#define MAX_TEE_BUS_DEV_COUNT ARRAY_SIZE(optee_bus_probe)
> > +
> >  struct rpc_param {
> >         u32     a0;
> >         u32     a1;
> > @@ -643,7 +657,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,8 +686,10 @@ 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 < MAX_TEE_BUS_DEV_COUNT; i++) {

I would use ARRAY_SIZE(optee_bus_probe) straight here. Macro
indirection is not really useful imho.

> > +               ret = device_bind_driver(dev, optee_bus_probe[i].drv_name,
> > +                                        optee_bus_probe[i].dev_name, &child);
> >                 if (ret)
> >                         return ret;
>
> I wonder which behaviour is most useful. Disable OP-TEE support
> completely if there's some error when binding dependent drivers or to
> just complain a bit but continue.

I agree with you, this should better print the status and proceed with
the next driver.
There are other occurrences of such behaviour in U-Boot.

Br,
etienne


>
> Cheers,
> Jens
>
>
> >
> >         }
> > --
> > 2.34.1
> >
Ilias Apalodimas Aug. 26, 2022, 9:19 a.m. UTC | #3
Hey Etienne, Jens


[...]

> > > -       if (IS_ENABLED(CONFIG_RNG_OPTEE)) {
> > > -               ret = device_bind_driver(dev, "optee-rng", "optee-rng", &child);
> > > +
> > > +       for (i = 0; i < MAX_TEE_BUS_DEV_COUNT; i++) {
> 
> I would use ARRAY_SIZE(optee_bus_probe) straight here. Macro
> indirection is not really useful imho.

Sure 

> 
> > > +               ret = device_bind_driver(dev, optee_bus_probe[i].drv_name,
> > > +                                        optee_bus_probe[i].dev_name, &child);
> > >                 if (ret)
> > >                         return ret;
> >
> > I wonder which behaviour is most useful. Disable OP-TEE support
> > completely if there's some error when binding dependent drivers or to
> > just complain a bit but continue.
> 
> I agree with you, this should better print the status and proceed with
> the next driver.
> There are other occurrences of such behaviour in U-Boot.

I also agree, however this changes the behaviour of *existing* code, which
I tried to avoid.  Since you both think it's better, I'll just add a
log_err() on v2 and continue.

Thanks
/Ilias

> 
> Br,
> etienne
> 
> 
> >
> > Cheers,
> > Jens
> >
> >
> > >
> > >         }
> > > --
> > > 2.34.1
> > >
diff mbox series

Patch

diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c
index a89d62aaf0b3..48a9b59171cb 100644
--- a/drivers/tee/optee/core.c
+++ b/drivers/tee/optee/core.c
@@ -31,6 +31,20 @@  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
+};
+
+#define MAX_TEE_BUS_DEV_COUNT ARRAY_SIZE(optee_bus_probe)
+
 struct rpc_param {
 	u32	a0;
 	u32	a1;
@@ -643,7 +657,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,8 +686,10 @@  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 < MAX_TEE_BUS_DEV_COUNT; i++) {
+		ret = device_bind_driver(dev, optee_bus_probe[i].drv_name,
+					 optee_bus_probe[i].dev_name, &child);
 		if (ret)
 			return ret;
 	}