From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) by mx.groups.io with SMTP id smtpd.web12.11057.1636459076254541972 for ; Tue, 09 Nov 2021 03:57:56 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20210112.gappssmtp.com header.s=20210112 header.b=nXeJuH0H; spf=pass (domain: nuviainc.com, ip: 209.85.221.49, mailfrom: leif@nuviainc.com) Received: by mail-wr1-f49.google.com with SMTP id d5so32546596wrc.1 for ; Tue, 09 Nov 2021 03:57:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nuviainc-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Hfkuy29iRp0fRHLj+vglBkm1+dFuSflvtd6oxeE1utY=; b=nXeJuH0HUnDO79p9hgI+maJY2+M+kKf5kkhShk2SFYsAMaoH6jY7QP498YPiCqk+41 CRDQtbFdfk8FTkp7iPAZ7Pezql/aSwOpRONgnfPXxA634rYk1RMo6UanF3hhNidvhcAP g3ySd++AtTddNy1lNcLFaCFZD6ucCVVLyz2XVxzY9XOflY7ApeUg8gEI3IKFNkG+FOqS oFgJY80bf+dd0AmyvlUaxfy4NQzTERl7CFzcbRL5xUgfy8ilulu8hgBrutm7q8IQZgGL odLMVLOSXQz6V5yIbkf52iDPnqLF+RhUYwXSvUuiATfQcLWutIQtPvGUlMHV2Y+K1XcS nfxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Hfkuy29iRp0fRHLj+vglBkm1+dFuSflvtd6oxeE1utY=; b=oIOq7B+S/Od+PztjCpAUsIlbaCeAqVsZKzKw6vDe41NDyeQb+ULqbamFgH4U7R5Fu9 c7H6SKimmlNzEX+FYOURP4hHFe7QK28Hj6fLi53ZIzmGgNmpQdQgvALCaY28cWFnuhMq iAbp0GRdc2girKSE/AsdOJVDhnMrVIt/gyHCIDdawstEvBZ6UgG9RbJLghj9HnSxSKQT RvDCpac0EpA9Y6ubYC7RTUHb9zappGqkPePCHX+p2t7PDathNoaw8t1UuFtrZ+7f2uRM xolvIko2/Ipz7iiH5ZoiiwwF2tUchQzZVaq5bnu1+6EzFOIe+S6S2tdaeNdoINDn15iE sGVw== X-Gm-Message-State: AOAM530CRI6UAt58CPR5XjvKRWunKlVni9sVOaGWZru3TuTeu4gEGUlN WFmrkWDvFgywc2Mc5JEuhVnzeQ== X-Google-Smtp-Source: ABdhPJx7jbgF+VVp5q493tKpolTn0mNaVoqBE1lh+rqQA43sReWwuvpe8/jKkCdHYeE4BD4QV5zDww== X-Received: by 2002:a5d:4d81:: with SMTP id b1mr8937562wru.366.1636459074588; Tue, 09 Nov 2021 03:57:54 -0800 (PST) Return-Path: Received: from leviathan (cpc92314-cmbg19-2-0-cust559.5-4.cable.virginm.net. [82.11.186.48]) by smtp.gmail.com with ESMTPSA id o63sm2549208wme.2.2021.11.09.03.57.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 03:57:54 -0800 (PST) Date: Tue, 9 Nov 2021 11:57:51 +0000 From: "Leif Lindholm" To: Rebecca Cran , Ard Biesheuvel Cc: devel@edk2.groups.io, Sami Mujawar , Gerd Hoffmann , Samer El-Haj-Mahmoud Subject: Re: [PATCH v2 1/2] ArmPkg: Add SMC helper functions Message-ID: <20211109115751.5inrccjr2ze4ql63@leviathan> References: <20211101221153.18620-1-rebecca@nuviainc.com> <20211101221153.18620-2-rebecca@nuviainc.com> MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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? / Leif > Rebecca Cran > > > 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; > > +}