From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by mx.groups.io with SMTP id smtpd.web12.6479.1636422972294062458 for ; Mon, 08 Nov 2021 17:56:12 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20210112.gappssmtp.com header.s=20210112 header.b=X3Rh4bMC; spf=pass (domain: nuviainc.com, ip: 209.85.214.169, mailfrom: rebecca@nuviainc.com) Received: by mail-pl1-f169.google.com with SMTP id n8so18029863plf.4 for ; Mon, 08 Nov 2021 17:56:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nuviainc-com.20210112.gappssmtp.com; s=20210112; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=8uprqneR0gUY+pjOje4UMxhktVYFPOrU534rljlA6aE=; b=X3Rh4bMCdGkTPCPdbYt9MPmqOZ6k3DDMSg7Sl5oQDlA62L8CoKIoObMBwPsBLA+L0m SuQO9J0RgBovXZgGguXqPvchViZWGpPZTcbR6FTUTlhCXFTdJoB3u0dJhT8l+sjeblEp Y5+686fRPQdMO/fuDw4MIZObZfeNbcFdRBQKGTjOHy76DeKnQBC+HE+TO5OouEUeRKmw /5iLLvrfLUk8ckL0XInoTLTOHmPLbQ87WTDAareL/EwZEBY3sdO2QGG22eAfF6CZBDxE dpD5KXDGnzyqhF+MJkfY0AI3DUYNJl9lspY/OBNkyVxdh8L/S4x5mwtSquc4toG0uAm5 1mGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=8uprqneR0gUY+pjOje4UMxhktVYFPOrU534rljlA6aE=; b=UdsolC1RQjuwJea7ld4al5QyzBMuBvgtIahRrM39Mq3gZm/Zt2+gnHW/heeteKe1mW 7zzrBYWI+wi1xrd0uQ3LFkBAZqxxRWx02GBrEByqHaUAJfRpBYoByMrVnjK7ob1iLtxf Ps3U2xkEmaHh6QrEzXzPweAezeQ5FqO8+dsWo71s/+DoRXf1qF7MYIo3kOu7nlXnv4C3 BvGAL+BSh5a0ygnd8khR7FTh2E1dhA4a+8qf1E2o0eviAiIrsQmItV1BBsQt7xu4iU30 FfLhx+6VVGRpq9s7W6QM4+A0BYmPIj8rS9iuic1Rcrb54itSQSgH9W2VjY+qRin3xVHg MbRA== X-Gm-Message-State: AOAM530ydg1Rl1PQxdONDQlQfxP/4KNBjfZ0cwl++Mlv+qKN0A8zGohF oRQ/NQNJRbz7wT5ZcjALH0td4Q== X-Google-Smtp-Source: ABdhPJwqlpIfFYoM5VuH40gYe+1bhP66yw50ByHAcUj81WBhlN0yJk/7/LuN9N7WVpNdWgioT7Q5NA== X-Received: by 2002:a17:903:2288:b0:141:e76d:1b16 with SMTP id b8-20020a170903228800b00141e76d1b16mr3437747plh.21.1636422971648; Mon, 08 Nov 2021 17:56:11 -0800 (PST) Return-Path: Received: from [10.0.10.179] (c-174-52-16-57.hsd1.ut.comcast.net. [174.52.16.57]) by smtp.gmail.com with ESMTPSA id cv1sm535051pjb.48.2021.11.08.17.56.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 08 Nov 2021 17:56:11 -0800 (PST) Subject: Re: [PATCH v2 1/2] ArmPkg: Add SMC helper functions To: devel@edk2.groups.io, Sami Mujawar , Ard Biesheuvel , Gerd Hoffmann , Samer El-Haj-Mahmoud , Leif Lindholm References: <20211101221153.18620-1-rebecca@nuviainc.com> <20211101221153.18620-2-rebecca@nuviainc.com> From: "Rebecca Cran" Message-ID: Date: Mon, 8 Nov 2021 18:56:09 -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: <20211101221153.18620-2-rebecca@nuviainc.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Could I have some reviews on this please? -- 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; > +}