From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by mx.groups.io with SMTP id smtpd.web12.15278.1639420271138496566 for ; Mon, 13 Dec 2021 10:31:11 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20210112.gappssmtp.com header.s=20210112 header.b=sjwp3chj; spf=pass (domain: nuviainc.com, ip: 209.85.216.42, mailfrom: rebecca@nuviainc.com) Received: by mail-pj1-f42.google.com with SMTP id gx15-20020a17090b124f00b001a695f3734aso14105819pjb.0 for ; Mon, 13 Dec 2021 10:31:11 -0800 (PST) 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=sRauBLAtTFQMxiGpjvAKflVaRRB5RhzzoG10jWnCH6s=; b=sjwp3chjYaUMTzh59OuXH5iriiOb51AJkY+7eWi9rFWOG+S4JH9Wtnrx3SnR8IpWIa ENMsgWXHelXXGAnZw1pmlnpvjqkJRZKzBkWV7Tz2IGhWZvDRwizNCUl0pEE7IXUMFFZQ J1CQTs8zixHeduK8xa4jX3mg7KCUj3fO/q748lmq5LlbkRXiCQMGtO90bGgEOtYuI7sp WwMVjzBSgeZAmNB9QQCRg5nMh+uAD6SZ/VLv1pk9KuEGYx4MurX2S8F0WemdaKJgrp8D /FhutC7du1FpBh0owSZwVWpn/eAcdr437wJXzn2hNmCprtHi51w8Anug9TEwvKhwsZ/F 6u+A== 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=sRauBLAtTFQMxiGpjvAKflVaRRB5RhzzoG10jWnCH6s=; b=PfmpBD8iPo0bcihpxiJw8nqcVAxw4Gh4SwhnD9NptHOOMFjUQoU/tU3KaVF56QJFsa tvZzF3f98cMkJo5jzbd2zYkz5BcCXt1qdZyOrDGMLqm80Qf9bNiprXp+ERagPG5FhWch WaepCXI3rgm82qzC1ErpftNGi3oJVJeBfy/SYZZWyPouOiV+2SbhdWb/5aWDanQpbwUq id4rlBuSpFcvd+SgAIXbqXJenp9cdKVAzakcR1jyjFf28dJW5wjmPeJlnQf129uSCNYW ECwUa13nUl7bf2z9bgIIjgIdqP21aaemHtypRXdwHxIIepTWz/EfRrwG+DNO61XN9fDJ dL6w== X-Gm-Message-State: AOAM530MgqE8NrOvGZgjbh21LpyyJC5NgO2PFl3r1gRb3U9RN1Sb3r0n Ebz/x3wm2cMt+CdegHai5fp6IQdcHmFd04VDzfkCIX97pPsX7Q8o+H3gWCzQAav3ZhR4YCPaKAp ylBH811rD8KXH87ponrI4a9+BOek+7U2B9YKhb9Xebb6jh+yWj9FG02u0bFLid11Am5DpdA== X-Google-Smtp-Source: ABdhPJxC/3cgTtUBUq6aN8F2evE0jgYDubzH1aP/J7Yav5xghrVOgSXzSjXj6wlw5dJvgYXGTLK7IA== X-Received: by 2002:a17:902:e544:b0:144:e3fa:3c2e with SMTP id n4-20020a170902e54400b00144e3fa3c2emr356836plf.17.1639420270046; Mon, 13 Dec 2021 10:31:10 -0800 (PST) Return-Path: Received: from linbox.ba.nuviainc.com ([2601:681:4300:69e:9e7b:efff:fe2b:884c]) by smtp.gmail.com with ESMTPSA id g15sm15530529pfj.144.2021.12.13.10.31.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Dec 2021 10:31:09 -0800 (PST) From: "Rebecca Cran" To: devel@edk2.groups.io, Ard Biesheuvel , Gerd Hoffmann , Samer El-Haj-Mahmoud , Leif Lindholm , nd , Sami Mujawar Cc: Rebecca Cran Subject: [PATCH v3 1/2] ArmPkg: Add SMC helper functions Date: Mon, 13 Dec 2021 11:30:55 -0700 Message-Id: <20211213183056.31444-2-rebecca@nuviainc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211213183056.31444-1-rebecca@nuviainc.com> References: <20211213183056.31444-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 Reviewed-by: Sami Mujawar --- ArmPkg/Include/Library/ArmSmcLib.h | 73 +++++++++++ ArmPkg/Library/ArmSmcLib/ArmSmc.c | 129 ++++++++++++++++++++ ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf | 3 + ArmPkg/Library/ArmSmcLibNull/ArmSmcLibNull.c | 85 +++++++++++++ 4 files changed, 290 insertions(+) diff --git a/ArmPkg/Include/Library/ArmSmcLib.h b/ArmPkg/Include/Library/ArmSmcLib.h index f5b45f0a8cdf..beef0175c35c 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 OPTIONAL, + IN OUT UINTN *Arg2 OPTIONAL, + IN OUT UINTN *Arg3 OPTIONAL + ); + +/** 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 OPTIONAL, + IN OUT UINTN *Arg2 OPTIONAL, + OUT UINTN *Arg3 OPTIONAL + ); + +/** 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 OPTIONAL, + OUT UINTN *Arg2 OPTIONAL, + OUT UINTN *Arg3 OPTIONAL + ); + +/** 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 OPTIONAL, + OUT UINTN *Arg2 OPTIONAL, + OUT UINTN *Arg3 OPTIONAL + ); + #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..254507e21916 --- /dev/null +++ b/ArmPkg/Library/ArmSmcLib/ArmSmc.c @@ -0,0 +1,129 @@ +/** @file + SMC helper functions. + + Copyright (c) 2021, NUVIA Inc. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#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 OPTIONAL, + IN OUT UINTN *Arg2 OPTIONAL, + IN OUT UINTN *Arg3 OPTIONAL + ) +{ + ARM_SMC_ARGS Args; + UINTN ErrorCode; + + ZeroMem (&Args, sizeof (ARM_SMC_ARGS)); + + 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 OPTIONAL, + IN OUT UINTN *Arg2 OPTIONAL, + OUT UINTN *Arg3 OPTIONAL + ) +{ + 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 OPTIONAL, + OUT UINTN *Arg2 OPTIONAL, + OUT UINTN *Arg3 OPTIONAL + ) +{ + 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 OPTIONAL, + OUT UINTN *Arg2 OPTIONAL, + OUT UINTN *Arg3 OPTIONAL + ) +{ + 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 3c1adef8ebe6..28514e43c2de 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 OPTIONAL, + IN OUT UINTN *Arg2 OPTIONAL, + IN OUT UINTN *Arg3 OPTIONAL + ) +{ + 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 OPTIONAL, + IN OUT UINTN *Arg2 OPTIONAL, + OUT UINTN *Arg3 OPTIONAL + ) +{ + 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 OPTIONAL, + OUT UINTN *Arg2 OPTIONAL, + OUT UINTN *Arg3 OPTIONAL + ) +{ + 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 OPTIONAL, + OUT UINTN *Arg2 OPTIONAL, + OUT UINTN *Arg3 OPTIONAL + ) +{ + return SMC_ARCH_CALL_NOT_SUPPORTED; +} -- 2.31.1