Add a Null instance of ArmCcaLib so that guest firmware that does
not support Arm CCA can link to this Null version of the library.

Also include it in ArmVirt.dsc.inc so that it is linked for the
non-Arm CCA firmware builds.

Cc: Ard Biesheuvel <ardb+tianoc...@kernel.org>
Cc: Leif Lindholm <quic_llind...@quicinc.com>
Cc: Gerd Hoffmann <kra...@redhat.com>
Signed-off-by: Sami Mujawar <sami.muja...@arm.com>
---
 ArmVirtPkg/ArmVirt.dsc.inc                         |   4 +-
 ArmVirtPkg/Library/ArmCcaLibNull/ArmCcaLibNull.c   | 117 ++++++++++++++++++++
 ArmVirtPkg/Library/ArmCcaLibNull/ArmCcaLibNull.inf |  28 +++++
 3 files changed, 148 insertions(+), 1 deletion(-)

diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc
index 
8c1063fb73f81e69e866549a2ba9b12945c83d9c..c8a29dd8ebc88107c4caab4f826001d9b0c2e7f7
 100644
--- a/ArmVirtPkg/ArmVirt.dsc.inc
+++ b/ArmVirtPkg/ArmVirt.dsc.inc
@@ -1,5 +1,5 @@
 #
-#  Copyright (c) 2011 - 2022, ARM Limited. All rights reserved.
+#  Copyright (c) 2011 - 2023, ARM Limited. All rights reserved.
 #  Copyright (c) 2014, Linaro Limited. All rights reserved.
 #  Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.
 #  Copyright (c) Microsoft Corporation.
@@ -180,6 +180,8 @@ [LibraryClasses.common]
 
   
ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.inf
 
+  ArmCcaLib|ArmVirtPkg/Library/ArmCcaLibNull/ArmCcaLibNull.inf
+
 [LibraryClasses.common.SEC]
   PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
   BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
diff --git a/ArmVirtPkg/Library/ArmCcaLibNull/ArmCcaLibNull.c 
b/ArmVirtPkg/Library/ArmCcaLibNull/ArmCcaLibNull.c
new file mode 100644
index 
0000000000000000000000000000000000000000..e5e645e148d485fc324e060ec27fbc3607fe8aae
--- /dev/null
+++ b/ArmVirtPkg/Library/ArmCcaLibNull/ArmCcaLibNull.c
@@ -0,0 +1,117 @@
+/** @file
+  Null implemmentation of the ArmCcaLib library.
+
+  Copyright (c) 2022 - 2023, Arm Limited. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Glossary:
+    - Rsi or RSI   - Realm Service Interface
+    - IPA          - Intermediate Physical Address
+    - RIPAS        - Realm IPA state
+**/
+#include <Library/ArmCcaLib.h>
+
+/**
+  Check if running in a Realm.
+
+    @retval TRUE    The execution is within the context of a Realm.
+    @retval FALSE   The execution is not within the context of a Realm.
+**/
+BOOLEAN
+EFIAPI
+IsRealm (
+  VOID
+  )
+{
+  return FALSE;
+}
+
+/**
+  Configure the protection attribute for the page tables
+  describing the memory region.
+
+  The IPA space of a Realm is divided into two halves:
+    - Protected IPA space and
+    - Unprotected IPA space.
+
+  Software in a Realm should treat the most significant bit of an
+  IPA as a protection attribute.
+
+  A Protected IPA is an address in the lower half of a Realms IPA
+  space. The most significant bit of a Protected IPA is 0.
+
+  An Unprotected IPA is an address in the upper half of a Realms
+  IPA space. The most significant bit of an Unprotected IPA is 1.
+
+  Note:
+  - Configuring the memory region as Unprotected IPA enables the
+    Realm to share the memory region with the Host.
+  - This function updates the page table entries to reflect the
+    protection attribute.
+  - A separate call to transition the memory range using the Realm
+    Service Interface (RSI) RSI_IPA_STATE_SET command is additionally
+    required and is expected to be done outside this function.
+
+    @param [in]  BaseAddress  Base address of the memory region.
+    @param [in]  Length       Length of the memory region.
+    @param [in]  IpaWidth     IPA width of the Realm.
+    @param [in]  Share        If TRUE, set the most significant
+                              bit of the IPA to configure the memory
+                              region as Unprotected IPA.
+                              If FALSE, clear the most significant
+                              bit of the IPA to configure the memory
+                              region as Protected IPA.
+
+    @retval RETURN_SUCCESS            IPA protection attribute updated.
+    @retval RETURN_INVALID_PARAMETER  A parameter is invalid.
+    @retval RETURN_UNSUPPORTED        The request is not initiated in a
+                                      Realm.
+**/
+RETURN_STATUS
+EFIAPI
+ArmCcaSetMemoryProtectAttribute (
+  IN EFI_PHYSICAL_ADDRESS  BaseAddress,
+  IN UINT64                Length,
+  IN UINT64                IpaWidth,
+  IN BOOLEAN               Share
+  )
+{
+  return RETURN_UNSUPPORTED;
+}
+
+/**
+  Return the IPA width of the Realm.
+
+  The IPA width of the Realm is used to configure the protection attribute
+  for memory regions, see ArmCcaSetMemoryProtectAttribute().
+
+  The IPA width of the Realm is present in the Realm config which is read
+  when the ArmCcaInitPeiLib library hook function ArmCcaInitialize () is
+  called in the PrePi phase. ArmCcaInitialize () stores the IPA width of
+  the Realm in a GUID HOB gArmCcaIpaWidthGuid.
+
+  This function searches the GUID HOB gArmCcaIpaWidthGuid and returns the
+  IPA width value stored therein.
+
+  Note:
+  - This function must only be called after ArmCcaInitialize () has setup
+    the GUID HOB gArmCcaIpaWidthGuid.
+
+    @param [out] IpaWidth  IPA width of the Realm.
+
+    @retval RETURN_SUCCESS            Success.
+    @retval RETURN_INVALID_PARAMETER  A parameter is invalid.
+    @retval RETURN_NOT_FOUND          The GUID HOB gArmCcaIpaWidthGuid is not
+                                      found and could mean that this function
+                                      was called before ArmCcaInitialize ()
+                                      has created and initialised the GUID
+                                      HOB gArmCcaIpaWidthGuid.
+**/
+RETURN_STATUS
+EFIAPI
+GetIpaWidth (
+  OUT UINT64  *IpaWidth
+  )
+{
+  return RETURN_UNSUPPORTED;
+}
diff --git a/ArmVirtPkg/Library/ArmCcaLibNull/ArmCcaLibNull.inf 
b/ArmVirtPkg/Library/ArmCcaLibNull/ArmCcaLibNull.inf
new file mode 100644
index 
0000000000000000000000000000000000000000..8f6c251afb14da48db45ba78d96d1d497e3fe8eb
--- /dev/null
+++ b/ArmVirtPkg/Library/ArmCcaLibNull/ArmCcaLibNull.inf
@@ -0,0 +1,28 @@
+## @file
+#  Null implemmentation of the ArmCcaLib library.
+#
+#  Copyright (c) 2022 - 2023, Arm Limited. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x0001001B
+  BASE_NAME                      = ArmCcaLib
+  FILE_GUID                      = 9E3F7AAA-10A6-4513-A960-B87F4D7DCFC5
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = ArmCcaLib
+
+[Sources]
+  ArmCcaLibNull.c
+
+
+[Packages]
+  ArmVirtPkg/ArmVirtPkg.dec
+  MdePkg/MdePkg.dec
+
+[LibraryClasses]
+  BaseLib
+
-- 
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117673): https://edk2.groups.io/g/devel/message/117673
Mute This Topic: https://groups.io/mt/105483411/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to