From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by mx.groups.io with SMTP id smtpd.web08.10007.1639396187852755672 for ; Mon, 13 Dec 2021 03:49:48 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Vi7sOqQo; spf=pass (domain: kernel.org, ip: 145.40.73.55, mailfrom: ardb@kernel.org) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id A72AECE0F15 for ; Mon, 13 Dec 2021 11:49:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7712C34603 for ; Mon, 13 Dec 2021 11:49:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1639396181; bh=CH5jtf38bPKqwcSYhZ3J7sN049XZyQBDxL+0FE8qDX4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Vi7sOqQopvPkXCARI4IYZ/hGoyTli6oZwKGVEODtZCLlZjza5XTFFyQTdvR2FXjcB A12N8gez4v3/4dkibMt5dYX7gilfsheBMIvGBNWNsNkZV3jEAZ8cB0kZn1jQ2FDwCL 6v4HylJshZiNbtZigcef/10GDQX5LJtcaQaSIEaWDnJIIKI9BXzyb+JsPXQ2HSkrJM JDfsfpnwiIh+EQbq07dRQUDOQljZ5DbT7cuetE20kcO1+zKGLjJofoJWeeitU0kWyY L3JaSSq+cBLnBoXPNmqQdQyBGTKfhC7l5DJMCZg3MFIgc0PUppdf3IRJFlGx3Xorem cCOfu47UnX73Q== Received: by mail-ot1-f54.google.com with SMTP id u18-20020a9d7212000000b00560cb1dc10bso17093066otj.11 for ; Mon, 13 Dec 2021 03:49:41 -0800 (PST) X-Gm-Message-State: AOAM5331IYjcYEO80Hzq7OZYpdHDHx4s16iCPWXMUo/9V7KlK6uaO61f pZDoHD5zPE4xarzfwXMPzOmjuVmtZCd+JFjld5M= X-Google-Smtp-Source: ABdhPJydLyHCD3ePcu6cB+Jp9MoxXMF7HiExPHAAdb4cEbHjc7vMm6S7Nq1isuIe2JxhSHtPnyFBYw5EimRj3L+ZxGw= X-Received: by 2002:a05:6830:1445:: with SMTP id w5mr24736351otp.112.1639396180956; Mon, 13 Dec 2021 03:49:40 -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: From: "Ard Biesheuvel" Date: Mon, 13 Dec 2021 12:49:30 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 1/2] ArmPkg: Add SMC helper functions To: Rebecca Cran Cc: Leif Lindholm , Ard Biesheuvel , edk2-devel-groups-io , Sami Mujawar , Gerd Hoffmann , Samer El-Haj-Mahmoud Content-Type: text/plain; charset="UTF-8" On Thu, 9 Dec 2021 at 23:54, Rebecca Cran wrote: > > Now that the edk2 tree is unfrozen, I'd like to get this committed. > > Could anyone else review it please, or if it's ready commit it? > > I think this is fine to go in, but you'll need to rebase on top of the uncrustify changes in any case. Sami, Leif: any comments? > > On 11/9/21 5:15 AM, Ard Biesheuvel wrote: > > 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; > >>>> +}