From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by mx.groups.io with SMTP id smtpd.web11.1420.1635804741480970708 for ; Mon, 01 Nov 2021 15:12:21 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20210112.gappssmtp.com header.s=20210112 header.b=y8pc1447; spf=pass (domain: nuviainc.com, ip: 209.85.215.173, mailfrom: rebecca@nuviainc.com) Received: by mail-pg1-f173.google.com with SMTP id 75so18425495pga.3 for ; Mon, 01 Nov 2021 15:12:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nuviainc-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jAVtAsT5fBGzPi4GtoomQ9UvS7Y0cLDybe+pn3JSZG0=; b=y8pc1447Z8tH3zykEPRusFEi7bSwkUKXUgp6Hy2RYUMXGNYRtoj52FqTwsNOqqCjNZ a/LP6sYBgq1ajoCyG173JrVHziOJBeY2sSHvkT1ggpaWa4PScoTwqf/0MOR8/D+hb1eX p5bkAe0IvWkITqeT1OIX5qFFrCWMmK/lhYBSg1/7Z7b8gcCyjXXMgOyINe3yjnGk63pK 2TpzrT6tAWbib16/kahjdMtw8RHgDem+qfUiskNLTQakmEzXyeDtX7XykzifzMyiutC5 5ESXfcTQ8Ebry89Ng3FDCRA6fUA7XHJk9QAjqDBSXgCdYwZoM+LoQUKVtzGeeiMnQvge mQDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jAVtAsT5fBGzPi4GtoomQ9UvS7Y0cLDybe+pn3JSZG0=; b=MIJwsnOLwFiJ+/P3AJIH5qd8cYD3EOoK+Co1QiT/+uZe4USzk6+Ff9eL3IltC4gfig iZrvkaGVd1tkwUT/iDIHMXL5rZOGq/Ji9JX6ZAThnl42byZSvUhKGcgB5G4mJuBshjVl ZnGqwYESq0jFeqp2eIpaTMfXnmrXvlX7LyzjgDWy/Di5ku0zxRvLDwZ/A6lRn4nk1zX1 ocLvzH+8RelbSpkOzAvxl8XEENczQqLW9dR3Hm2v1EjN4gCqIO5O1S53QDFlC0ipvqPU 1KLneEOeab4MPThm8+LBC0pn1q6bA6730WHHL7Il6r7p1KvQIpOTWQIYgp8z8ky1D7ai CjVg== X-Gm-Message-State: AOAM532/74Qqb/gWTn/TF7+ucfCq2vUBR4eDlIpoyDWzw7UY5RobPqaG 0tCEPp/Zh2TSzN58JWBTuBPRt0hPr04MeneFX3br790TEq7WDSjyun7nK3eBdlcVqV4O086Oz7W zq8jHlXMRZmt7sYUfaqFBKiOIvUwQxzaEpx9fOa4lP3D+6NteiimoDvETWxoX06Wl+oYJGQ== X-Google-Smtp-Source: ABdhPJwY0w85iQSt0ODVMYfTpWgvhIxgYll6qsdgq8qTNB2h6VZD3xJcS0nxr94zUXZLHXN9JTGftQ== X-Received: by 2002:a05:6a00:1593:b0:481:1ffa:8c4a with SMTP id u19-20020a056a00159300b004811ffa8c4amr2516461pfk.80.1635804739623; Mon, 01 Nov 2021 15:12:19 -0700 (PDT) Return-Path: Received: from linbox.ba.nuviainc.com (c-174-52-16-57.hsd1.ut.comcast.net. [174.52.16.57]) by smtp.gmail.com with ESMTPSA id z10sm17028455pfh.106.2021.11.01.15.12.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 15:12:19 -0700 (PDT) From: "Rebecca Cran" To: devel@edk2.groups.io, Sami Mujawar , Ard Biesheuvel , Gerd Hoffmann , Samer El-Haj-Mahmoud , Leif Lindholm Cc: Rebecca Cran Subject: [PATCH v2 1/2] ArmPkg: Add SMC helper functions Date: Mon, 1 Nov 2021 16:11:52 -0600 Message-Id: <20211101221153.18620-2-rebecca@nuviainc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211101221153.18620-1-rebecca@nuviainc.com> References: <20211101221153.18620-1-rebecca@nuviainc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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; +} -- 2.31.1