[PATCH v3 3/8] tpm: rng: Add driver model interface for TPM RNG device

Simon Glass sjg at chromium.org
Sat Mar 12 18:59:02 CET 2022


Hi Sughosh.

On Wed, 9 Mar 2022 at 04:18, Sughosh Ganu <sughosh.ganu at linaro.org> wrote:
>
> hi Simon,
>
> On Wed, 9 Mar 2022 at 11:30, Sughosh Ganu <sughosh.ganu at linaro.org> wrote:
> >
> > hi Simon,
> >
> > Thanks for looking into this. I now have a fair idea of the structure
> > that you are looking for this interface.
> >
> > On Wed, 9 Mar 2022 at 08:05, Simon Glass <sjg at chromium.org> wrote:
> > >
> > > Hi Sugosh,
> > >
> > > On Fri, 4 Mar 2022 at 06:35, Sughosh Ganu <sughosh.ganu at linaro.org> wrote:
> > > >
> > > > The TPM device has a builtin random number generator(RNG)
> > > > functionality. Expose the RNG functions of the TPM device to the
> > > > driver model so that they can be used by the EFI_RNG_PROTOCOL if the
> > > > protocol is installed.
> > > >
> > > > Also change the function arguments and return type of the random
> > > > number functions to comply with the driver model api.
> > > >
> > > > Signed-off-by: Sughosh Ganu <sughosh.ganu at linaro.org>
> > > > ---
> > > >
> > > > Changes since V2:
> > > >
> > > > * Export the existing tpm*_get_random functions to the driver model
> > > >   instead of moving them to the drivers/rng/ directory.
>
> <snip>
>
> > > > diff --git a/lib/tpm_api.c b/lib/tpm_api.c
> > > > index da48058abe..3584fda98c 100644
> > > > --- a/lib/tpm_api.c
> > > > +++ b/lib/tpm_api.c
> > > > @@ -6,6 +6,7 @@
> > > >  #include <common.h>
> > > >  #include <dm.h>
> > > >  #include <log.h>
> > > > +#include <rng.h>
> > > >  #include <tpm_api.h>
> > > >  #include <tpm-v1.h>
> > > >  #include <tpm-v2.h>
> > > > @@ -265,12 +266,26 @@ u32 tpm_get_permissions(struct udevice *dev, u32 index, u32 *perm)
> > > >                 return -ENOSYS;
> > > >  }
> > > >
> > > > +#if CONFIG_IS_ENABLED(DM_RNG)
> > > >  int tpm_get_random(struct udevice *dev, void *data, u32 count)
> > > >  {
> > > > +       int ret = -ENOSYS;
> > > > +       struct udevice *rng_dev;
> > > > +
> > > >         if (tpm_is_v1(dev))
> > > > -               return tpm1_get_random(dev, data, count);
> > > > +               ret = uclass_get_device_by_driver(UCLASS_RNG,
> > > > +                                                 DM_DRIVER_GET(tpm1_rng),
> > > > +                                                 &rng_dev);
> > >
> > > Er, tpm_get_random() should take a tpm device. The random device
> > > should be handled by the caller, which should call
> > > tpm_get_random(rand_dev->parent...
> >
> > Okay. I will make the changes as per your suggestion. Thanks for the
> > review of the patch.
>
> Having had a relook at this, the tpm_get_random is indeed getting the
> TPM device. Which is why the call to tpm_is_v1 is being called with
> the same 'dev' argument. So I believe this function is currently as
> per what you are looking for. Getting the TPM device as the first
> argument.

OK.

Regards,
Simon


More information about the U-Boot mailing list