From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by mx.groups.io with SMTP id smtpd.web12.11217.1636460158567219977 for ; Tue, 09 Nov 2021 04:15:58 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=h6WFP639; spf=pass (domain: kernel.org, ip: 198.145.29.99, mailfrom: ardb@kernel.org) Received: by mail.kernel.org (Postfix) with ESMTPSA id DA53861152 for ; Tue, 9 Nov 2021 12:15:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636460157; bh=qKje9Bu3v3N25o0Cl+9i3FGDwq2M1TAmf6kDnH9mfXI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=h6WFP639/DgEL/aSDVPonfpiHkNryEGniCXaez7vDvFxxF7OvBf4NHo+Z6CuQGEBC xz/m4RZ26wyw5LkASR/LlaZrxna4LfgyU4XccTvhkd9oIDU5esprC6D8L974syHPDl zWomLKXhbU/U4WzeYYVqa7aNUCzf5NXrBKFRUF3Nf+QLTDPzlm+WZr+HuVlPrLCYAt WAcPxqTqBB3A9T9ZDC8/y+XQYNq53bpOwwABKGjjx5RAwPGEZt49XLgCNuBOwT1aTA kuxN4rHhdGWNVee9kV5BKIihNDtbHJAE+E/2rrColgljftu4ynJuom5l6FnVpienQE ipfsKyDMrpVHg== Received: by mail-oi1-f177.google.com with SMTP id o83so33335532oif.4 for ; Tue, 09 Nov 2021 04:15:57 -0800 (PST) X-Gm-Message-State: AOAM531/+8ZIk/4jj5lZ5k/XD4fi57vEG3zyoDtPa6C8FejoiMKVoOWV Ca0e8c8hQqBe9cbd9zkROwHbJUksuyOxjSz73zY= X-Google-Smtp-Source: ABdhPJz2iKnmSEoM9hG63YyeR/b475fUFDMfeVxZ2ajSv3GrK4EiyhRfZ/rsE7WWIEI8ngUfLbuXwEDyjDnTq84+u/s= X-Received: by 2002:aca:ad95:: with SMTP id w143mr4208988oie.47.1636460156774; Tue, 09 Nov 2021 04:15:56 -0800 (PST) MIME-Version: 1.0 References: <20211101221153.18620-1-rebecca@nuviainc.com> <20211101221153.18620-2-rebecca@nuviainc.com> <20211109115751.5inrccjr2ze4ql63@leviathan> In-Reply-To: <20211109115751.5inrccjr2ze4ql63@leviathan> From: "Ard Biesheuvel" Date: Tue, 9 Nov 2021 13:15:45 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 1/2] ArmPkg: Add SMC helper functions To: Leif Lindholm Cc: Rebecca Cran , Ard Biesheuvel , edk2-devel-groups-io , Sami Mujawar , Gerd Hoffmann , Samer El-Haj-Mahmoud Content-Type: text/plain; charset="UTF-8" On Tue, 9 Nov 2021 at 12:57, Leif Lindholm wrote: > > On Mon, Nov 08, 2021 at 18:56:09 -0700, Rebecca Cran wrote: > > Could I have some reviews on this please? > > I'm all for it. It's clunky, but less clunky than the situation > without, and it improves readability at call sites. > > Ard had some reservations for v1 not actually adding any users. > Ard - do you like it any better now Rebecca's added some? > Yeah, this is fine. TBH, I am not going to have time to look into this in detail again, so if you're both happy, then I am too. Acked-by: Ard Biesheuvel > > On 11/1/21 4:11 PM, Rebecca Cran wrote: > > > Add functions ArmCallSmc0/1/2/3 to do SMC calls with 0, 1, 2 or 3 > > > arguments. > > > The functions return up to 3 values. > > > > > > Signed-off-by: Rebecca Cran > > > --- > > > ArmPkg/Include/Library/ArmSmcLib.h | 73 ++++++++++++ > > > ArmPkg/Library/ArmSmcLib/ArmSmc.c | 122 ++++++++++++++++++++ > > > ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf | 3 + > > > ArmPkg/Library/ArmSmcLibNull/ArmSmcLibNull.c | 85 ++++++++++++++ > > > 4 files changed, 283 insertions(+) > > > > > > diff --git a/ArmPkg/Include/Library/ArmSmcLib.h b/ArmPkg/Include/Library/ArmSmcLib.h > > > index ced60b3c1147..343ae7f40ad2 100644 > > > --- a/ArmPkg/Include/Library/ArmSmcLib.h > > > +++ b/ArmPkg/Include/Library/ArmSmcLib.h > > > @@ -1,5 +1,6 @@ > > > /** @file > > > * > > > +* Copyright (c) 2021, NUVIA Inc. All rights reserved.
> > > * Copyright (c) 2012-2014, ARM Limited. All rights reserved. > > > * > > > * SPDX-License-Identifier: BSD-2-Clause-Patent > > > @@ -37,4 +38,76 @@ ArmCallSmc ( > > > IN OUT ARM_SMC_ARGS *Args > > > ); > > > +/** Trigger an SMC call with 3 arguments. > > > + > > > + @param Function The SMC function. > > > + @param Arg1 Argument/result. > > > + @param Arg2 Argument/result. > > > + @param Arg3 Argument/result. > > > + > > > + @return The SMC error code. > > > + > > > +**/ > > > +UINTN > > > +ArmCallSmc3 ( > > > + IN UINTN Function, > > > + IN OUT UINTN *Arg1, > > > + IN OUT UINTN *Arg2, > > > + IN OUT UINTN *Arg3 > > > + ); > > > + > > > +/** Trigger an SMC call with 2 arguments. > > > + > > > + @param Function The SMC function. > > > + @param Arg1 Argument/result. > > > + @param Arg2 Argument/result. > > > + @param Arg3 Result. > > > + > > > + @return The SMC error code. > > > + > > > +**/ > > > +UINTN > > > +ArmCallSmc2 ( > > > + IN UINTN Function, > > > + IN OUT UINTN *Arg1, > > > + IN OUT UINTN *Arg2, > > > + OUT UINTN *Arg3 > > > + ); > > > + > > > +/** Trigger an SMC call with 1 argument. > > > + > > > + @param Function The SMC function. > > > + @param Arg1 Argument/result. > > > + @param Arg2 Result. > > > + @param Arg3 Result. > > > + > > > + @return The SMC error code. > > > + > > > +**/ > > > +UINTN > > > +ArmCallSmc1 ( > > > + IN UINTN Function, > > > + IN OUT UINTN *Arg1, > > > + OUT UINTN *Arg2, > > > + OUT UINTN *Arg3 > > > + ); > > > + > > > +/** Trigger an SMC call with 0 arguments. > > > + > > > + @param Function The SMC function. > > > + @param Arg1 Result. > > > + @param Arg2 Result. > > > + @param Arg3 Result. > > > + > > > + @return The SMC error code. > > > + > > > +**/ > > > +UINTN > > > +ArmCallSmc0 ( > > > + IN UINTN Function, > > > + OUT UINTN *Arg1, > > > + OUT UINTN *Arg2, > > > + OUT UINTN *Arg3 > > > + ); > > > + > > > #endif // ARM_SMC_LIB_H_ > > > diff --git a/ArmPkg/Library/ArmSmcLib/ArmSmc.c b/ArmPkg/Library/ArmSmcLib/ArmSmc.c > > > new file mode 100644 > > > index 000000000000..d596003a857e > > > --- /dev/null > > > +++ b/ArmPkg/Library/ArmSmcLib/ArmSmc.c > > > @@ -0,0 +1,122 @@ > > > +/** @file > > > + SMC helper functions. > > > + > > > + Copyright (c) 2021, NUVIA Inc. All rights reserved.
> > > + > > > + SPDX-License-Identifier: BSD-2-Clause-Patent > > > + > > > +**/ > > > + > > > +#include > > > + > > > +/** Triggers an SMC call with 3 arguments. > > > + > > > + @param Function The SMC function. > > > + @param Arg1 Argument/result. > > > + @param Arg2 Argument/result. > > > + @param Arg3 Argument/result. > > > + > > > + @return The SMC error code. > > > +**/ > > > +UINTN > > > +ArmCallSmc3 ( > > > + IN UINTN Function, > > > + IN OUT UINTN *Arg1, > > > + IN OUT UINTN *Arg2, > > > + IN OUT UINTN *Arg3 > > > + ) > > > +{ > > > + ARM_SMC_ARGS Args; > > > + UINTN ErrorCode; > > > + > > > + Args.Arg0 = Function; > > > + > > > + if (Arg1 != NULL) { > > > + Args.Arg1 = *Arg1; > > > + } > > > + if (Arg2 != NULL) { > > > + Args.Arg2 = *Arg2; > > > + } > > > + if (Arg3 != NULL) { > > > + Args.Arg3 = *Arg3; > > > + } > > > + > > > + ArmCallSmc (&Args); > > > + > > > + ErrorCode = Args.Arg0; > > > + > > > + if (Arg1 != NULL) { > > > + *Arg1 = Args.Arg1; > > > + } > > > + if (Arg2 != NULL) { > > > + *Arg2 = Args.Arg2; > > > + } > > > + if (Arg3 != NULL) { > > > + *Arg3 = Args.Arg3; > > > + } > > > + > > > + return ErrorCode; > > > +} > > > + > > > +/** Trigger an SMC call with 2 arguments. > > > + > > > + @param Function The SMC function. > > > + @param Arg1 Argument/result. > > > + @param Arg2 Argument/result. > > > + @param Arg3 Result. > > > + > > > + @return The SMC error code. > > > + > > > +**/ > > > +UINTN > > > +ArmCallSmc2 ( > > > + IN UINTN Function, > > > + IN OUT UINTN *Arg1, > > > + IN OUT UINTN *Arg2, > > > + OUT UINTN *Arg3 > > > + ) > > > +{ > > > + return ArmCallSmc3 (Function, Arg1, Arg2, Arg3); > > > +} > > > + > > > +/** Trigger an SMC call with 1 argument. > > > + > > > + @param Function The SMC function. > > > + @param Arg1 Argument/result. > > > + @param Arg2 Result. > > > + @param Arg3 Result. > > > + > > > + @return The SMC error code. > > > + > > > +**/ > > > +UINTN > > > +ArmCallSmc1 ( > > > + IN UINTN Function, > > > + IN OUT UINTN *Arg1, > > > + OUT UINTN *Arg2, > > > + OUT UINTN *Arg3 > > > + ) > > > +{ > > > + return ArmCallSmc3 (Function, Arg1, Arg2, Arg3); > > > +} > > > + > > > +/** Trigger an SMC call with 0 arguments. > > > + > > > + @param Function The SMC function. > > > + @param Arg1 Result. > > > + @param Arg2 Result. > > > + @param Arg3 Result. > > > + > > > + @return The SMC error code. > > > + > > > +**/ > > > +UINTN > > > +ArmCallSmc0 ( > > > + IN UINTN Function, > > > + OUT UINTN *Arg1, > > > + OUT UINTN *Arg2, > > > + OUT UINTN *Arg3 > > > + ) > > > +{ > > > + return ArmCallSmc3 (Function, Arg1, Arg2, Arg3); > > > +} > > > diff --git a/ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf b/ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf > > > index 4f4b09f4528a..a89f9203fb7e 100644 > > > --- a/ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf > > > +++ b/ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf > > > @@ -20,6 +20,9 @@ > > > [Sources.AARCH64] > > > AArch64/ArmSmc.S > > > +[Sources] > > > + ArmSmc.c > > > + > > > [Packages] > > > MdePkg/MdePkg.dec > > > ArmPkg/ArmPkg.dec > > > diff --git a/ArmPkg/Library/ArmSmcLibNull/ArmSmcLibNull.c b/ArmPkg/Library/ArmSmcLibNull/ArmSmcLibNull.c > > > index 2d79aadaf1fa..ca1b8830a119 100644 > > > --- a/ArmPkg/Library/ArmSmcLibNull/ArmSmcLibNull.c > > > +++ b/ArmPkg/Library/ArmSmcLibNull/ArmSmcLibNull.c > > > @@ -1,4 +1,5 @@ > > > // > > > +// Copyright (c) 2021, NUVIA Inc. All rights reserved. > > > // Copyright (c) 2016, Linaro Limited. All rights reserved. > > > // > > > // SPDX-License-Identifier: BSD-2-Clause-Patent > > > @@ -7,6 +8,7 @@ > > > #include > > > #include > > > +#include > > > VOID > > > ArmCallSmc ( > > > @@ -14,3 +16,86 @@ ArmCallSmc ( > > > ) > > > { > > > } > > > + > > > +/** Triggers an SMC call with 3 arguments. > > > + > > > + @param Function The SMC function. > > > + @param Arg1 Argument/result. > > > + @param Arg2 Argument/result. > > > + @param Arg3 Argument/result. > > > + > > > + @return The SMC error code. > > > +**/ > > > +UINTN > > > +ArmCallSmc3 ( > > > + IN UINTN Function, > > > + IN OUT UINTN *Arg1, > > > + IN OUT UINTN *Arg2, > > > + IN OUT UINTN *Arg3 > > > + ) > > > +{ > > > + return SMC_ARCH_CALL_NOT_SUPPORTED; > > > +} > > > + > > > +/** Trigger an SMC call with 2 arguments. > > > + > > > + @param Function The SMC function. > > > + @param Arg1 Argument/result. > > > + @param Arg2 Argument/result. > > > + @param Arg3 Result. > > > + > > > + @return The SMC error code. > > > + > > > +**/ > > > +UINTN > > > +ArmCallSmc2 ( > > > + IN UINTN Function, > > > + IN OUT UINTN *Arg1, > > > + IN OUT UINTN *Arg2, > > > + OUT UINTN *Arg3 > > > + ) > > > +{ > > > + return SMC_ARCH_CALL_NOT_SUPPORTED; > > > +} > > > + > > > +/** Trigger an SMC call with 1 argument. > > > + > > > + @param Function The SMC function. > > > + @param Arg1 Argument/result. > > > + @param Arg2 Result. > > > + @param Arg3 Result. > > > + > > > + @return The SMC error code. > > > + > > > +**/ > > > +UINTN > > > +ArmCallSmc1 ( > > > + IN UINTN Function, > > > + IN OUT UINTN *Arg1, > > > + OUT UINTN *Arg2, > > > + OUT UINTN *Arg3 > > > + ) > > > +{ > > > + return SMC_ARCH_CALL_NOT_SUPPORTED; > > > +} > > > + > > > +/** Trigger an SMC call with 0 arguments. > > > + > > > + @param Function The SMC function. > > > + @param Arg1 Result. > > > + @param Arg2 Result. > > > + @param Arg3 Result. > > > + > > > + @return The SMC error code. > > > + > > > +**/ > > > +UINTN > > > +ArmCallSmc0 ( > > > + IN UINTN Function, > > > + OUT UINTN *Arg1, > > > + OUT UINTN *Arg2, > > > + OUT UINTN *Arg3 > > > + ) > > > +{ > > > + return SMC_ARCH_CALL_NOT_SUPPORTED; > > > +}