From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by mx.groups.io with SMTP id smtpd.web10.638.1639090485102336027 for ; Thu, 09 Dec 2021 14:54:45 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20210112.gappssmtp.com header.s=20210112 header.b=tRBduZ+A; spf=pass (domain: nuviainc.com, ip: 209.85.216.54, mailfrom: rebecca@nuviainc.com) Received: by mail-pj1-f54.google.com with SMTP id p18-20020a17090ad31200b001a78bb52876so8083327pju.3 for ; Thu, 09 Dec 2021 14:54:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nuviainc-com.20210112.gappssmtp.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=+1eO9mUCkdSH/Q8H7SfebJ5e8RUWkMlFwL17TDYPbEY=; b=tRBduZ+AlgxT6+20lay9vgU5ulIpF/6N5B2Mx69bfFkLWLjVzbpKpmuH65TYAFJONK UE93utOxEPyzxp/iP4xH2tBX8//xKisuRZiPLFVHvzHj6WnRxzn6O4AtNlUxrAiLR9FV /X5bgqE8NU85GwsnJHMQBmssfQp5hsWVfraY9NGlx1L7K1saRHNtqVnxiDkchCS+XaP9 8zEyyQdxK9YAHv9+R/+IWcJg+M2/40XaM0WYjP7HF5J7XtDxn061NgJXvV8kbXnjSXBp as13tDYDPVtGFTdKsun+XCRIJZnsBtoVSsETxZcOBhpRhf97EBI/e+VE20M5+4dEbqUp CUkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=+1eO9mUCkdSH/Q8H7SfebJ5e8RUWkMlFwL17TDYPbEY=; b=mjAW447+i3je/eY/6tR1tsiIRzPeKn8U7RJlHx8oPTaFLz4+BNKhSkXQr2A9vJnvue QINcBcUJl1ccZgXOOHJrNEnW6iI3BNM3CTCKHry3MFz/5eDbPB5MlQYhrYukG7iUY34S knSQ3oA6rJn0SEcvgwhmcGYywDljA1nTFj+mWHDNio+k/bdsWEXky4juzr28jMvd4kay K/j8HOGkrDIA5TUaGiXAF/ZvAp+cezmh70ymOESyL9Q05kxq7SNTP2DbcpVf9bzUUKMk 10qrJySy5mmRZ4j8kAavgnBRaSaq5tHqlEF8rdrq5fZq3Iho7HN1ntOqCAvNLpyVsdZJ +dyw== X-Gm-Message-State: AOAM532MBR1rQiQFSg6I1nqy4cLxMpPCLCr+cMeMiwymvG+6SIJfFNhb OZqHr9rQExkiHhMvctIoxQq0yA== X-Google-Smtp-Source: ABdhPJw92avJNyPAJFWDXLJjdLIqOywfLMvyqV4nqDHm9iKuaYYL3xKJA3JYL1iswBihGIqv2t6mkQ== X-Received: by 2002:a17:902:b682:b0:143:7eb8:222 with SMTP id c2-20020a170902b68200b001437eb80222mr71378576pls.31.1639090484521; Thu, 09 Dec 2021 14:54:44 -0800 (PST) Return-Path: Received: from ?IPv6:2601:681:4300:69e:9e7b:efff:fe2b:884c? ([2601:681:4300:69e:9e7b:efff:fe2b:884c]) by smtp.gmail.com with ESMTPSA id f7sm137895pfj.41.2021.12.09.14.54.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 09 Dec 2021 14:54:44 -0800 (PST) Subject: Re: [PATCH v2 1/2] ArmPkg: Add SMC helper functions To: Ard Biesheuvel , Leif Lindholm Cc: Ard Biesheuvel , edk2-devel-groups-io , Sami Mujawar , Gerd Hoffmann , Samer El-Haj-Mahmoud References: <20211101221153.18620-1-rebecca@nuviainc.com> <20211101221153.18620-2-rebecca@nuviainc.com> <20211109115751.5inrccjr2ze4ql63@leviathan> From: "Rebecca Cran" Message-ID: Date: Thu, 9 Dec 2021 15:54:42 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US 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? Thanks. Rebecca Cran 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; >>>> +}