Hi Alexey, On Mon, 11 Sept 2023 at 10:35, Alexey Romanov <avroma...@salutedevices.com> wrote: > > At the moment, we don't have a common API for working with > SM, only the smc_call() function. This approach is not generic > and difficult to configure and maintain. > > This patch adds UCLASS_SM with the generic API: > > - sm_call() > - sm_call_write() > - sm_call_read() > > These functions operate with struct pt_regs, which describes > Secure Monitor arguments. > > Signed-off-by: Alexey Romanov <avroma...@salutedevices.com> > --- > drivers/Kconfig | 2 ++ > drivers/Makefile | 1 + > drivers/sm/Kconfig | 2 ++ > drivers/sm/Makefile | 3 ++ > drivers/sm/sm-uclass.c | 55 ++++++++++++++++++++++++++++++++ > include/dm/uclass-id.h | 1 + > include/sm-uclass.h | 72 ++++++++++++++++++++++++++++++++++++++++++ > include/sm.h | 67 +++++++++++++++++++++++++++++++++++++++ > 8 files changed, 203 insertions(+) > create mode 100644 drivers/sm/Kconfig > create mode 100644 drivers/sm/Makefile > create mode 100644 drivers/sm/sm-uclass.c > create mode 100644 include/sm-uclass.h > create mode 100644 include/sm.h
Reviewed-by: Simon Glass <s...@chromium.org> nit below > > diff --git a/drivers/Kconfig b/drivers/Kconfig > index 75ac149d31..72e6405322 100644 > --- a/drivers/Kconfig > +++ b/drivers/Kconfig > @@ -112,6 +112,8 @@ source "drivers/scsi/Kconfig" > > source "drivers/serial/Kconfig" > > +source "drivers/sm/Kconfig" > + > source "drivers/smem/Kconfig" > > source "drivers/sound/Kconfig" > diff --git a/drivers/Makefile b/drivers/Makefile > index 6f1de58e00..b7bd3633b1 100644 > --- a/drivers/Makefile > +++ b/drivers/Makefile > @@ -124,3 +124,4 @@ obj-$(CONFIG_DM_RNG) += rng/ > endif > > obj-y += soc/ > +obj-y += sm/ > diff --git a/drivers/sm/Kconfig b/drivers/sm/Kconfig > new file mode 100644 > index 0000000000..6cc6d55578 > --- /dev/null > +++ b/drivers/sm/Kconfig > @@ -0,0 +1,2 @@ > +config SM > + bool "Enable Secure Monitor driver support" > diff --git a/drivers/sm/Makefile b/drivers/sm/Makefile > new file mode 100644 > index 0000000000..9f4683ba06 > --- /dev/null > +++ b/drivers/sm/Makefile > @@ -0,0 +1,3 @@ > +# SPDX-License-Identifier: GPL-2.0-only > + > +obj-y += sm-uclass.o > diff --git a/drivers/sm/sm-uclass.c b/drivers/sm/sm-uclass.c > new file mode 100644 > index 0000000000..78af857026 > --- /dev/null > +++ b/drivers/sm/sm-uclass.c > @@ -0,0 +1,55 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * Copyright (c) 2023 SberDevices, Inc. > + * > + * Author: Alexey Romanov <avroma...@salutedevices.com> > + */ > + > +#include <common.h> > +#include <dm.h> > +#include <errno.h> > +#include <sm-uclass.h> > + > +static const struct sm_ops *get_sm_ops(struct udevice *dev) > +{ > + return (const struct sm_ops *)dev->driver->ops; > +} > + > +int sm_call(struct udevice *dev, u32 cmd, s32 *ret, struct pt_regs *args) > +{ > + const struct sm_ops *ops = get_sm_ops(dev); > + > + if (ops->sm_call) > + return ops->sm_call(dev, cmd, ret, args); > + > + return -EPROTONOSUPPORT; We normally use -ENOSYS in U-Boot Regards, Simon