public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 0/2] CloudHv/arm: Add specific mem info lib
@ 2022-07-29  7:21 Jianyong Wu
  2022-07-29  7:21 ` [PATCH 1/2] CloudHv/arm: add PeiMemInfoLib Jianyong Wu
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Jianyong Wu @ 2022-07-29  7:21 UTC (permalink / raw)
  To: devel, Sami.Mujawar; +Cc: ard.biesheuvel, justin.he, jianyong.wu

Currently, the meminfo lib for CloudHv/arm is reusing QEMU's. As the memory
layout for cloud hypervisor is changed, it needs a new meminfo lib.

Signed-off-by: Jianyong Wu <jianyong.wu@arm.com>

Jianyong Wu (2):
  CloudHv/arm: add PeiMemInfoLib
  CloudHv/arm: switch PeiMemLib to its own

 ArmVirtPkg/ArmVirtCloudHv.dsc                 |   2 +-
 .../CloudHvVirtMemInfoLib.c                   | 251 ++++++++++++++++++
 .../CloudHvVirtMemInfoPeiLib.inf              |  46 ++++
 3 files changed, 298 insertions(+), 1 deletion(-)
 create mode 100755 ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoLib.c
 create mode 100755 ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoPeiLib.inf

-- 
2.17.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/2] CloudHv/arm: add PeiMemInfoLib
  2022-07-29  7:21 [PATCH 0/2] CloudHv/arm: Add specific mem info lib Jianyong Wu
@ 2022-07-29  7:21 ` Jianyong Wu
  2022-08-08 11:27   ` Sami Mujawar
  2022-07-29  7:21 ` [PATCH 2/2] CloudHv/arm: switch PeiMemLib to its own Jianyong Wu
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 11+ messages in thread
From: Jianyong Wu @ 2022-07-29  7:21 UTC (permalink / raw)
  To: devel, Sami.Mujawar; +Cc: ard.biesheuvel, justin.he, jianyong.wu

Memory layout in CLoud Hypervisor for arm is changed and is different
with Qemu, thus we should build its own PeiMemInfoLib.
The main change in the memory layout is that normal ram may not contiguous
under 4G. The top 64M under 4G is reserved for 32bit device.

What this patch does:
1. get all of the memory node from DT;
2. Init page table for each memory node;
3. Add all of the memory nodes to Hob;

Signed-off-by: Jianyong Wu <jianyong.wu@arm.com>
---
 .../CloudHvVirtMemInfoLib.c                   | 251 ++++++++++++++++++
 .../CloudHvVirtMemInfoPeiLib.inf              |  46 ++++
 2 files changed, 297 insertions(+)
 create mode 100755 ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoLib.c
 create mode 100755 ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoPeiLib.inf

diff --git a/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoLib.c b/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoLib.c
new file mode 100755
index 0000000000..7ae24641d3
--- /dev/null
+++ b/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoLib.c
@@ -0,0 +1,251 @@
+/** @file
+
+  Copyright (c) 2022, Arm Limited. All rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiPei.h>
+
+#include <Base.h>
+#include <libfdt.h>
+#include <Library/ArmLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/PcdLib.h>
+
+#include<Library/PrePiLib.h>
+
+// The first memnory node is the one whose base address is the lowest.
+UINT64 FirMemNodeBase = 0, FirMemNodeSize = 0;
+//
+// Cloud Hypervisor may have more than one memory nodes. Even there is no limit for that,
+// I think 10 is enough in general.
+//
+#define CLOUDHV_MAX_MEM_NODE_NUM 10
+
+// Record memory node info (base address and size)
+struct CloudHvMemNodeInfo {
+  UINT64 Base;
+  UINT64 Size;
+};
+
+struct CloudHvMemNodeInfo CloudHvMemNode[CLOUDHV_MAX_MEM_NODE_NUM];
+
+RETURN_STATUS
+EFIAPI
+CloudHvVirtMemInfoPeiLibConstructor (
+  VOID
+  )
+{
+  VOID           *DeviceTreeBase;
+  EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttributes;
+  INT32          Node, Prev;
+  UINT64         CurBase, MemBase;
+  UINT64         CurSize;
+  CONST CHAR8    *Type;
+  INT32          Len;
+  CONST UINT64   *RegProp;
+  RETURN_STATUS  PcdStatus;
+  UINT8          Index;
+
+  ZeroMem (CloudHvMemNode, sizeof(CloudHvMemNode[0]) * CLOUDHV_MAX_MEM_NODE_NUM);
+
+  Index = 0;
+  MemBase = FixedPcdGet64 (PcdSystemMemoryBase);
+  ResourceAttributes = (
+                        EFI_RESOURCE_ATTRIBUTE_PRESENT |
+                        EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
+                        EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
+                        EFI_RESOURCE_ATTRIBUTE_TESTED
+                        );
+  DeviceTreeBase = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress);
+  ASSERT (DeviceTreeBase != NULL);
+
+  //
+  // Make sure we have a valid device tree blob
+  //
+  ASSERT (fdt_check_header (DeviceTreeBase) == 0);
+
+  //
+  // Look for the lowest memory node
+  //
+  for (Prev = 0; ; Prev = Node) {
+    Node = fdt_next_node (DeviceTreeBase, Prev, NULL);
+    if (Node < 0) {
+      break;
+    }
+
+    //
+    // Check for memory node
+    //
+    Type = fdt_getprop (DeviceTreeBase, Node, "device_type", &Len);
+    if (Type && (AsciiStrnCmp (Type, "memory", Len) == 0)) {
+      //
+      // Get the 'reg' property of this node. For now, we will assume
+      // two 8 byte quantities for base and size, respectively.
+      //
+      RegProp = fdt_getprop (DeviceTreeBase, Node, "reg", &Len);
+      if ((RegProp != 0) && (Len == (2 * sizeof (UINT64)))) {
+        CurBase = fdt64_to_cpu (ReadUnaligned64 (RegProp));
+        CurSize = fdt64_to_cpu (ReadUnaligned64 (RegProp + 1));
+
+        DEBUG ((
+          DEBUG_INFO,
+          "%a: System RAM @ 0x%lx - 0x%lx\n",
+          __FUNCTION__,
+          CurBase,
+          CurBase + CurSize - 1
+          ));
+
+        if (CurBase == MemBase) {
+            FirMemNodeBase = CurBase;
+            FirMemNodeSize = CurSize;
+        }
+
+        CloudHvMemNode[Index].Base = CurBase;
+        CloudHvMemNode[Index].Size = CurSize;
+        Index++;
+        // We should build Hob seperately for the memory node except the first one
+        if (CurBase != MemBase) {
+          BuildResourceDescriptorHob (
+            EFI_RESOURCE_SYSTEM_MEMORY,
+            ResourceAttributes,
+            CurBase,
+            CurSize
+            );
+        }
+        if (Index >= CLOUDHV_MAX_MEM_NODE_NUM) {
+          DEBUG ((
+            DEBUG_WARN,
+            "%a: memory node larger than %d will not be included into Memory System\n",
+            __FUNCTION__,
+            CLOUDHV_MAX_MEM_NODE_NUM
+            ));
+          break;
+        }
+      } else {
+        DEBUG ((
+          DEBUG_ERROR,
+          "%a: Failed to parse FDT memory node\n",
+          __FUNCTION__
+          ));
+      }
+    }
+  }
+
+  //
+  // Make sure the start of DRAM matches our expectation
+  //
+  ASSERT (FixedPcdGet64 (PcdSystemMemoryBase) == FirMemNodeBase);
+  PcdStatus = PcdSet64S (PcdSystemMemorySize, FirMemNodeSize);
+  ASSERT_RETURN_ERROR (PcdStatus);
+  ASSERT (
+    (((UINT64)PcdGet64 (PcdFdBaseAddress) +
+      (UINT64)PcdGet32 (PcdFdSize)) <= FirMemNodeBase) ||
+    ((UINT64)PcdGet64 (PcdFdBaseAddress) >= (FirMemNodeBase + FirMemNodeSize))
+    );
+
+  return RETURN_SUCCESS;
+}
+
+// Number of Virtual Memory Map Descriptors
+#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS  (4 + CLOUDHV_MAX_MEM_NODE_NUM)
+
+//
+// Core peripherals such as the UART, the GIC and the RTC are
+// all mapped in the 'miscellaneous device I/O' region, which we just map
+// in its entirety rather than device by device. Note that it does not
+// cover any of the NOR flash banks or PCI resource windows.
+//
+#define MACH_VIRT_PERIPH_BASE  0x00400000
+#define MACH_VIRT_PERIPH_SIZE  0x0FC00000
+
+//
+// The top of the 64M memory region under 4GB reserved for device
+//
+#define TOP_32BIT_DEVICE_BASE  0xFC000000
+#define TOP_32BIT_DEVICE_SIZE  0x04000000
+
+/**
+  Return the Virtual Memory Map of your platform
+
+  This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU
+  on your platform.
+
+  @param[out]   VirtualMemoryMap    Array of ARM_MEMORY_REGION_DESCRIPTOR
+                                    describing a Physical-to-Virtual Memory
+                                    mapping. This array must be ended by a
+                                    zero-filled entry. The allocated memory
+                                    will not be freed.
+
+**/
+VOID
+ArmVirtGetMemoryMap (
+  OUT ARM_MEMORY_REGION_DESCRIPTOR  **VirtualMemoryMap
+  )
+{
+  ARM_MEMORY_REGION_DESCRIPTOR  *VirtualMemoryTable;
+  UINT8 Index = 0, i = 0;
+
+  ASSERT (VirtualMemoryMap != NULL);
+
+  VirtualMemoryTable = AllocatePool (
+                         sizeof (ARM_MEMORY_REGION_DESCRIPTOR) *
+                         MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS
+                         );
+
+  if (VirtualMemoryTable == NULL) {
+    DEBUG ((DEBUG_ERROR, "%a: Error: Failed AllocatePool()\n", __FUNCTION__));
+    return;
+  }
+    // System DRAM
+  while (CloudHvMemNode[i].Size != 0) {
+    VirtualMemoryTable[Index].PhysicalBase = CloudHvMemNode[i].Base;
+    VirtualMemoryTable[Index].VirtualBase  = CloudHvMemNode[i].Base;
+    VirtualMemoryTable[Index].Length       = CloudHvMemNode[i].Size;
+    VirtualMemoryTable[Index].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
+
+    DEBUG ((
+      DEBUG_INFO,
+      "%a: Dumping System DRAM Memory Node%d Map:\n"
+      "\tPhysicalBase: 0x%lX\n"
+      "\tVirtualBase: 0x%lX\n"
+      "\tLength: 0x%lX\n",
+      __FUNCTION__,
+      i,
+      VirtualMemoryTable[Index].PhysicalBase,
+      VirtualMemoryTable[Index].VirtualBase,
+      VirtualMemoryTable[Index].Length
+      ));
+    Index++;
+    i++;
+  }
+  // Memory mapped peripherals (UART, RTC, GIC, virtio-mmio, etc)
+  VirtualMemoryTable[Index].PhysicalBase = MACH_VIRT_PERIPH_BASE;
+  VirtualMemoryTable[Index].VirtualBase  = MACH_VIRT_PERIPH_BASE;
+  VirtualMemoryTable[Index].Length       = MACH_VIRT_PERIPH_SIZE;
+  VirtualMemoryTable[Index].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
+  Index++;
+
+  // Map the FV region as normal executable memory
+  VirtualMemoryTable[Index].PhysicalBase = PcdGet64 (PcdFvBaseAddress);
+  VirtualMemoryTable[Index].VirtualBase  = VirtualMemoryTable[Index].PhysicalBase;
+  VirtualMemoryTable[Index].Length       = FixedPcdGet32 (PcdFvSize);
+  VirtualMemoryTable[Index].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
+  Index++;
+
+  // Memory mapped for 32bit device (like TPM)
+  VirtualMemoryTable[Index].PhysicalBase = TOP_32BIT_DEVICE_BASE;
+  VirtualMemoryTable[Index].VirtualBase  = TOP_32BIT_DEVICE_BASE;
+  VirtualMemoryTable[Index].Length       = TOP_32BIT_DEVICE_SIZE;
+  VirtualMemoryTable[Index].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
+  Index++;
+
+  // End of Table
+  ZeroMem (&VirtualMemoryTable[Index], sizeof (ARM_MEMORY_REGION_DESCRIPTOR));
+
+  *VirtualMemoryMap = VirtualMemoryTable;
+}
diff --git a/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoPeiLib.inf b/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoPeiLib.inf
new file mode 100755
index 0000000000..5dd96faadd
--- /dev/null
+++ b/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoPeiLib.inf
@@ -0,0 +1,46 @@
+#/* @file
+#
+#  Copyright (c) 2011-2015, ARM Limited. All rights reserved.
+#  Copyright (c) 2014-2017, Linaro Limited. All rights reserved.
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#*/
+
+[Defines]
+  INF_VERSION                    = 0x0001001A
+  BASE_NAME                      = QemuVirtMemInfoPeiLib
+  FILE_GUID                      = 0c4d10cf-d949-49b4-bd13-47a4ae22efce
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = ArmVirtMemInfoLib|PEIM
+  CONSTRUCTOR                    = CloudHvVirtMemInfoPeiLibConstructor
+
+[Sources]
+  CloudHvVirtMemInfoLib.c
+
+[Packages]
+  ArmPkg/ArmPkg.dec
+  ArmVirtPkg/ArmVirtPkg.dec
+  EmbeddedPkg/EmbeddedPkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  MdePkg/MdePkg.dec
+
+[LibraryClasses]
+  ArmLib
+  BaseMemoryLib
+  DebugLib
+  FdtLib
+  PcdLib
+  MemoryAllocationLib
+
+[Pcd]
+  gArmTokenSpaceGuid.PcdFdBaseAddress
+  gArmTokenSpaceGuid.PcdFvBaseAddress
+  gArmTokenSpaceGuid.PcdSystemMemoryBase
+  gArmTokenSpaceGuid.PcdSystemMemorySize
+
+[FixedPcd]
+  gArmTokenSpaceGuid.PcdFdSize
+  gArmTokenSpaceGuid.PcdFvSize
+  gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/2] CloudHv/arm: switch PeiMemLib to its own
  2022-07-29  7:21 [PATCH 0/2] CloudHv/arm: Add specific mem info lib Jianyong Wu
  2022-07-29  7:21 ` [PATCH 1/2] CloudHv/arm: add PeiMemInfoLib Jianyong Wu
@ 2022-07-29  7:21 ` Jianyong Wu
  2022-08-08 11:29   ` Sami Mujawar
       [not found] ` <17063BDF40129601.5552@groups.io>
       [not found] ` <17063BDFB8173BFA.24450@groups.io>
  3 siblings, 1 reply; 11+ messages in thread
From: Jianyong Wu @ 2022-07-29  7:21 UTC (permalink / raw)
  To: devel, Sami.Mujawar; +Cc: ard.biesheuvel, justin.he, jianyong.wu

As Cloud Hypervisor has its own PeiMemLib, change it in dsc file
accordingly.

Signed-off-by: Jianyong Wu <jianyong.wu@arm.com>
---
 ArmVirtPkg/ArmVirtCloudHv.dsc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ArmVirtPkg/ArmVirtCloudHv.dsc b/ArmVirtPkg/ArmVirtCloudHv.dsc
index 7559386a1d..7ca7a391d9 100644
--- a/ArmVirtPkg/ArmVirtCloudHv.dsc
+++ b/ArmVirtPkg/ArmVirtCloudHv.dsc
@@ -60,7 +60,7 @@
 !include MdePkg/MdeLibs.dsc.inc
 
 [LibraryClasses.common.PEIM]
-  ArmVirtMemInfoLib|ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf
+  ArmVirtMemInfoLib|ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoPeiLib.inf
 
 [LibraryClasses.common.DXE_DRIVER]
   ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [edk2-devel] [PATCH 1/2] CloudHv/arm: add PeiMemInfoLib
       [not found] ` <17063BDF40129601.5552@groups.io>
@ 2022-08-08  7:03   ` Jianyong Wu
  0 siblings, 0 replies; 11+ messages in thread
From: Jianyong Wu @ 2022-08-08  7:03 UTC (permalink / raw)
  To: devel@edk2.groups.io, Jianyong Wu, Sami Mujawar
  Cc: ard.biesheuvel@linaro.org, Justin He, Ard Biesheuvel,
	quic_llindhol@quicinc.com, kraxel@redhat.com

+cc: Ard Biesheuvel, Leif Lindholm, Gerd Hoffmann

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Jianyong
> Wu via groups.io
> Sent: Friday, July 29, 2022 3:22 PM
> To: devel@edk2.groups.io; Sami Mujawar <Sami.Mujawar@arm.com>
> Cc: ard.biesheuvel@linaro.org; Justin He <Justin.He@arm.com>; Jianyong
> Wu <Jianyong.Wu@arm.com>
> Subject: [edk2-devel] [PATCH 1/2] CloudHv/arm: add PeiMemInfoLib
>
> Memory layout in CLoud Hypervisor for arm is changed and is different with
> Qemu, thus we should build its own PeiMemInfoLib.
> The main change in the memory layout is that normal ram may not
> contiguous under 4G. The top 64M under 4G is reserved for 32bit device.
>
> What this patch does:
> 1. get all of the memory node from DT;
> 2. Init page table for each memory node; 3. Add all of the memory nodes to
> Hob;
>
> Signed-off-by: Jianyong Wu <jianyong.wu@arm.com>
> ---
>  .../CloudHvVirtMemInfoLib.c                   | 251 ++++++++++++++++++
>  .../CloudHvVirtMemInfoPeiLib.inf              |  46 ++++
>  2 files changed, 297 insertions(+)
>  create mode 100755
> ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoLib.c
>  create mode 100755
> ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoPeiLib.inf
>
> diff --git
> a/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoLib.c
> b/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoLib.c
> new file mode 100755
> index 0000000000..7ae24641d3
> --- /dev/null
> +++
> b/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoLib.c
> @@ -0,0 +1,251 @@
> +/** @file
> +
> +  Copyright (c) 2022, Arm Limited. All rights reserved.
> +
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiPei.h>
> +
> +#include <Base.h>
> +#include <libfdt.h>
> +#include <Library/ArmLib.h>
> +#include <Library/BaseMemoryLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/MemoryAllocationLib.h> #include <Library/PcdLib.h>
> +
> +#include<Library/PrePiLib.h>
> +
> +// The first memnory node is the one whose base address is the lowest.
> +UINT64 FirMemNodeBase = 0, FirMemNodeSize = 0; // // Cloud Hypervisor
> +may have more than one memory nodes. Even there is no limit for that,
> +// I think 10 is enough in general.
> +//
> +#define CLOUDHV_MAX_MEM_NODE_NUM 10
> +
> +// Record memory node info (base address and size) struct
> +CloudHvMemNodeInfo {
> +  UINT64 Base;
> +  UINT64 Size;
> +};
> +
> +struct CloudHvMemNodeInfo
> CloudHvMemNode[CLOUDHV_MAX_MEM_NODE_NUM];
> +
> +RETURN_STATUS
> +EFIAPI
> +CloudHvVirtMemInfoPeiLibConstructor (
> +  VOID
> +  )
> +{
> +  VOID           *DeviceTreeBase;
> +  EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttributes;
> +  INT32          Node, Prev;
> +  UINT64         CurBase, MemBase;
> +  UINT64         CurSize;
> +  CONST CHAR8    *Type;
> +  INT32          Len;
> +  CONST UINT64   *RegProp;
> +  RETURN_STATUS  PcdStatus;
> +  UINT8          Index;
> +
> +  ZeroMem (CloudHvMemNode, sizeof(CloudHvMemNode[0]) *
> + CLOUDHV_MAX_MEM_NODE_NUM);
> +
> +  Index = 0;
> +  MemBase = FixedPcdGet64 (PcdSystemMemoryBase);  ResourceAttributes
> =
> + (
> +                        EFI_RESOURCE_ATTRIBUTE_PRESENT |
> +                        EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
> +                        EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
> +                        EFI_RESOURCE_ATTRIBUTE_TESTED
> +                        );
> +  DeviceTreeBase = (VOID *)(UINTN)PcdGet64
> + (PcdDeviceTreeInitialBaseAddress);
> +  ASSERT (DeviceTreeBase != NULL);
> +
> +  //
> +  // Make sure we have a valid device tree blob  //  ASSERT
> + (fdt_check_header (DeviceTreeBase) == 0);
> +
> +  //
> +  // Look for the lowest memory node
> +  //
> +  for (Prev = 0; ; Prev = Node) {
> +    Node = fdt_next_node (DeviceTreeBase, Prev, NULL);
> +    if (Node < 0) {
> +      break;
> +    }
> +
> +    //
> +    // Check for memory node
> +    //
> +    Type = fdt_getprop (DeviceTreeBase, Node, "device_type", &Len);
> +    if (Type && (AsciiStrnCmp (Type, "memory", Len) == 0)) {
> +      //
> +      // Get the 'reg' property of this node. For now, we will assume
> +      // two 8 byte quantities for base and size, respectively.
> +      //
> +      RegProp = fdt_getprop (DeviceTreeBase, Node, "reg", &Len);
> +      if ((RegProp != 0) && (Len == (2 * sizeof (UINT64)))) {
> +        CurBase = fdt64_to_cpu (ReadUnaligned64 (RegProp));
> +        CurSize = fdt64_to_cpu (ReadUnaligned64 (RegProp + 1));
> +
> +        DEBUG ((
> +          DEBUG_INFO,
> +          "%a: System RAM @ 0x%lx - 0x%lx\n",
> +          __FUNCTION__,
> +          CurBase,
> +          CurBase + CurSize - 1
> +          ));
> +
> +        if (CurBase == MemBase) {
> +            FirMemNodeBase = CurBase;
> +            FirMemNodeSize = CurSize;
> +        }
> +
> +        CloudHvMemNode[Index].Base = CurBase;
> +        CloudHvMemNode[Index].Size = CurSize;
> +        Index++;
> +        // We should build Hob seperately for the memory node except the
> first one
> +        if (CurBase != MemBase) {
> +          BuildResourceDescriptorHob (
> +            EFI_RESOURCE_SYSTEM_MEMORY,
> +            ResourceAttributes,
> +            CurBase,
> +            CurSize
> +            );
> +        }
> +        if (Index >= CLOUDHV_MAX_MEM_NODE_NUM) {
> +          DEBUG ((
> +            DEBUG_WARN,
> +            "%a: memory node larger than %d will not be included into Memory
> System\n",
> +            __FUNCTION__,
> +            CLOUDHV_MAX_MEM_NODE_NUM
> +            ));
> +          break;
> +        }
> +      } else {
> +        DEBUG ((
> +          DEBUG_ERROR,
> +          "%a: Failed to parse FDT memory node\n",
> +          __FUNCTION__
> +          ));
> +      }
> +    }
> +  }
> +
> +  //
> +  // Make sure the start of DRAM matches our expectation  //  ASSERT
> + (FixedPcdGet64 (PcdSystemMemoryBase) == FirMemNodeBase);  PcdStatus
> =
> + PcdSet64S (PcdSystemMemorySize, FirMemNodeSize);
> ASSERT_RETURN_ERROR
> + (PcdStatus);  ASSERT (
> +    (((UINT64)PcdGet64 (PcdFdBaseAddress) +
> +      (UINT64)PcdGet32 (PcdFdSize)) <= FirMemNodeBase) ||
> +    ((UINT64)PcdGet64 (PcdFdBaseAddress) >= (FirMemNodeBase +
> FirMemNodeSize))
> +    );
> +
> +  return RETURN_SUCCESS;
> +}
> +
> +// Number of Virtual Memory Map Descriptors #define
> +MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS  (4 +
> CLOUDHV_MAX_MEM_NODE_NUM)
> +
> +//
> +// Core peripherals such as the UART, the GIC and the RTC are // all
> +mapped in the 'miscellaneous device I/O' region, which we just map //
> +in its entirety rather than device by device. Note that it does not //
> +cover any of the NOR flash banks or PCI resource windows.
> +//
> +#define MACH_VIRT_PERIPH_BASE  0x00400000 #define
> MACH_VIRT_PERIPH_SIZE
> +0x0FC00000
> +
> +//
> +// The top of the 64M memory region under 4GB reserved for device //
> +#define TOP_32BIT_DEVICE_BASE  0xFC000000 #define
> TOP_32BIT_DEVICE_SIZE
> +0x04000000
> +
> +/**
> +  Return the Virtual Memory Map of your platform
> +
> +  This Virtual Memory Map is used by MemoryInitPei Module to initialize
> + the MMU  on your platform.
> +
> +  @param[out]   VirtualMemoryMap    Array of
> ARM_MEMORY_REGION_DESCRIPTOR
> +                                    describing a Physical-to-Virtual Memory
> +                                    mapping. This array must be ended by a
> +                                    zero-filled entry. The allocated memory
> +                                    will not be freed.
> +
> +**/
> +VOID
> +ArmVirtGetMemoryMap (
> +  OUT ARM_MEMORY_REGION_DESCRIPTOR  **VirtualMemoryMap
> +  )
> +{
> +  ARM_MEMORY_REGION_DESCRIPTOR  *VirtualMemoryTable;
> +  UINT8 Index = 0, i = 0;
> +
> +  ASSERT (VirtualMemoryMap != NULL);
> +
> +  VirtualMemoryTable = AllocatePool (
> +                         sizeof (ARM_MEMORY_REGION_DESCRIPTOR) *
> +                         MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS
> +                         );
> +
> +  if (VirtualMemoryTable == NULL) {
> +    DEBUG ((DEBUG_ERROR, "%a: Error: Failed AllocatePool()\n",
> __FUNCTION__));
> +    return;
> +  }
> +    // System DRAM
> +  while (CloudHvMemNode[i].Size != 0) {
> +    VirtualMemoryTable[Index].PhysicalBase = CloudHvMemNode[i].Base;
> +    VirtualMemoryTable[Index].VirtualBase  = CloudHvMemNode[i].Base;
> +    VirtualMemoryTable[Index].Length       = CloudHvMemNode[i].Size;
> +    VirtualMemoryTable[Index].Attributes   =
> ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
> +
> +    DEBUG ((
> +      DEBUG_INFO,
> +      "%a: Dumping System DRAM Memory Node%d Map:\n"
> +      "\tPhysicalBase: 0x%lX\n"
> +      "\tVirtualBase: 0x%lX\n"
> +      "\tLength: 0x%lX\n",
> +      __FUNCTION__,
> +      i,
> +      VirtualMemoryTable[Index].PhysicalBase,
> +      VirtualMemoryTable[Index].VirtualBase,
> +      VirtualMemoryTable[Index].Length
> +      ));
> +    Index++;
> +    i++;
> +  }
> +  // Memory mapped peripherals (UART, RTC, GIC, virtio-mmio, etc)
> + VirtualMemoryTable[Index].PhysicalBase = MACH_VIRT_PERIPH_BASE;
> + VirtualMemoryTable[Index].VirtualBase  = MACH_VIRT_PERIPH_BASE;
> +  VirtualMemoryTable[Index].Length       = MACH_VIRT_PERIPH_SIZE;
> +  VirtualMemoryTable[Index].Attributes   =
> ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
> +  Index++;
> +
> +  // Map the FV region as normal executable memory
> + VirtualMemoryTable[Index].PhysicalBase = PcdGet64 (PcdFvBaseAddress);
> + VirtualMemoryTable[Index].VirtualBase  =
> VirtualMemoryTable[Index].PhysicalBase;
> +  VirtualMemoryTable[Index].Length       = FixedPcdGet32 (PcdFvSize);
> +  VirtualMemoryTable[Index].Attributes   =
> ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
> +  Index++;
> +
> +  // Memory mapped for 32bit device (like TPM)
> + VirtualMemoryTable[Index].PhysicalBase = TOP_32BIT_DEVICE_BASE;
> + VirtualMemoryTable[Index].VirtualBase  = TOP_32BIT_DEVICE_BASE;
> +  VirtualMemoryTable[Index].Length       = TOP_32BIT_DEVICE_SIZE;
> +  VirtualMemoryTable[Index].Attributes   =
> ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
> +  Index++;
> +
> +  // End of Table
> +  ZeroMem (&VirtualMemoryTable[Index], sizeof
> + (ARM_MEMORY_REGION_DESCRIPTOR));
> +
> +  *VirtualMemoryMap = VirtualMemoryTable; }
> diff --git
> a/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoPeiLib.in
> f
> b/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoPeiLib.i
> nf
> new file mode 100755
> index 0000000000..5dd96faadd
> --- /dev/null
> +++
> b/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoPeiLib.
> +++ inf
> @@ -0,0 +1,46 @@
> +#/* @file
> +#
> +#  Copyright (c) 2011-2015, ARM Limited. All rights reserved.
> +#  Copyright (c) 2014-2017, Linaro Limited. All rights reserved.
> +#
> +#  SPDX-License-Identifier: BSD-2-Clause-Patent # #*/
> +
> +[Defines]
> +  INF_VERSION                    = 0x0001001A
> +  BASE_NAME                      = QemuVirtMemInfoPeiLib
> +  FILE_GUID                      = 0c4d10cf-d949-49b4-bd13-47a4ae22efce
> +  MODULE_TYPE                    = BASE
> +  VERSION_STRING                 = 1.0
> +  LIBRARY_CLASS                  = ArmVirtMemInfoLib|PEIM
> +  CONSTRUCTOR                    = CloudHvVirtMemInfoPeiLibConstructor
> +
> +[Sources]
> +  CloudHvVirtMemInfoLib.c
> +
> +[Packages]
> +  ArmPkg/ArmPkg.dec
> +  ArmVirtPkg/ArmVirtPkg.dec
> +  EmbeddedPkg/EmbeddedPkg.dec
> +  MdeModulePkg/MdeModulePkg.dec
> +  MdePkg/MdePkg.dec
> +
> +[LibraryClasses]
> +  ArmLib
> +  BaseMemoryLib
> +  DebugLib
> +  FdtLib
> +  PcdLib
> +  MemoryAllocationLib
> +
> +[Pcd]
> +  gArmTokenSpaceGuid.PcdFdBaseAddress
> +  gArmTokenSpaceGuid.PcdFvBaseAddress
> +  gArmTokenSpaceGuid.PcdSystemMemoryBase
> +  gArmTokenSpaceGuid.PcdSystemMemorySize
> +
> +[FixedPcd]
> +  gArmTokenSpaceGuid.PcdFdSize
> +  gArmTokenSpaceGuid.PcdFvSize
> +  gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress
> --
> 2.17.1
>
>
>
> 
>

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [edk2-devel] [PATCH 2/2] CloudHv/arm: switch PeiMemLib to its own
       [not found] ` <17063BDFB8173BFA.24450@groups.io>
@ 2022-08-08  7:04   ` Jianyong Wu
  0 siblings, 0 replies; 11+ messages in thread
From: Jianyong Wu @ 2022-08-08  7:04 UTC (permalink / raw)
  To: devel@edk2.groups.io, Sami Mujawar
  Cc: Justin He, Ard Biesheuvel, quic_llindhol@quicinc.com,
	kraxel@redhat.com, Jianyong Wu

+cc: Ard Biesheuvel, Leif Lindholm, Gerd Hoffmann

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Jianyong
> Wu via groups.io
> Sent: Friday, July 29, 2022 3:22 PM
> To: devel@edk2.groups.io; Sami Mujawar <Sami.Mujawar@arm.com>
> Cc: ard.biesheuvel@linaro.org; Justin He <Justin.He@arm.com>; Jianyong
> Wu <Jianyong.Wu@arm.com>
> Subject: [edk2-devel] [PATCH 2/2] CloudHv/arm: switch PeiMemLib to its own
>
> As Cloud Hypervisor has its own PeiMemLib, change it in dsc file accordingly.
>
> Signed-off-by: Jianyong Wu <jianyong.wu@arm.com>
> ---
>  ArmVirtPkg/ArmVirtCloudHv.dsc | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/ArmVirtPkg/ArmVirtCloudHv.dsc
> b/ArmVirtPkg/ArmVirtCloudHv.dsc index 7559386a1d..7ca7a391d9 100644
> --- a/ArmVirtPkg/ArmVirtCloudHv.dsc
> +++ b/ArmVirtPkg/ArmVirtCloudHv.dsc
> @@ -60,7 +60,7 @@
>  !include MdePkg/MdeLibs.dsc.inc
>
>  [LibraryClasses.common.PEIM]
> -
> ArmVirtMemInfoLib|ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMe
> mInfoPeiLib.inf
> +
> +
> ArmVirtMemInfoLib|ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVi
> rt
> + MemInfoPeiLib.inf
>
>  [LibraryClasses.common.DXE_DRIVER]
>
> ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/Dxe
> ReportStatusCodeLib.inf
> --
> 2.17.1
>
>
>
> 
>

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/2] CloudHv/arm: add PeiMemInfoLib
  2022-07-29  7:21 ` [PATCH 1/2] CloudHv/arm: add PeiMemInfoLib Jianyong Wu
@ 2022-08-08 11:27   ` Sami Mujawar
  2022-08-09  8:31     ` Jianyong Wu
       [not found]     ` <1709A00AB94047B2.29555@groups.io>
  0 siblings, 2 replies; 11+ messages in thread
From: Sami Mujawar @ 2022-08-08 11:27 UTC (permalink / raw)
  To: Jianyong Wu, devel; +Cc: ard.biesheuvel, justin.he, nd@arm.com

[-- Attachment #1: Type: text/plain, Size: 12817 bytes --]

Hi Jianyong,

Thank you for this patch.

Please find my response inline marked [SAMI].

Regards,

Sami Mujawar

On 29/07/2022 08:21 am, Jianyong Wu wrote:
> Memory layout in CLoud Hypervisor for arm is changed and is different
> with Qemu, thus we should build its own PeiMemInfoLib.
> The main change in the memory layout is that normal ram may not contiguous
> under 4G. The top 64M under 4G is reserved for 32bit device.
>
> What this patch does:
> 1. get all of the memory node from DT;
> 2. Init page table for each memory node;
> 3. Add all of the memory nodes to Hob;
>
> Signed-off-by: Jianyong Wu<jianyong.wu@arm.com>
> ---
>   .../CloudHvVirtMemInfoLib.c                   | 251 ++++++++++++++++++
>   .../CloudHvVirtMemInfoPeiLib.inf              |  46 ++++
>   2 files changed, 297 insertions(+)
>   create mode 100755 ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoLib.c
>   create mode 100755 ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoPeiLib.inf
>
> diff --git a/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoLib.c b/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoLib.c
> new file mode 100755
> index 0000000000..7ae24641d3
> --- /dev/null
> +++ b/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoLib.c
> @@ -0,0 +1,251 @@
> +/** @file
> +
> +  Copyright (c) 2022, Arm Limited. All rights reserved.
> +
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiPei.h>
> +
> +#include <Base.h>
> +#include <libfdt.h>
> +#include <Library/ArmLib.h>
> +#include <Library/BaseMemoryLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/MemoryAllocationLib.h>
> +#include <Library/PcdLib.h>
> +
> +#include<Library/PrePiLib.h>
> +
> +// The first memnory node is the one whose base address is the lowest.
> +UINT64 FirMemNodeBase = 0, FirMemNodeSize = 0;
[SAMI] Is it possible to move the above variables within the scope of 
CloudHvVirtMemInfoPeiLibConstructor() ?
> +//
> +// Cloud Hypervisor may have more than one memory nodes. Even there is no limit for that,
> +// I think 10 is enough in general.
> +//
> +#define CLOUDHV_MAX_MEM_NODE_NUM 10
> +
> +// Record memory node info (base address and size)
> +struct CloudHvMemNodeInfo {
> +  UINT64 Base;
> +  UINT64 Size;
> +};

[SAMI] The edk2 coding guidelines require definition of a typedef for 
structures, see section 5.6.3.[1,2,3] at 
https://edk2-docs.gitbook.io/edk-ii-c-coding-standards-specification/5_source_files/56_declarations_and_types#5.6.3.1-structures-shall-not-be-directly-declared.

> +
> +struct CloudHvMemNodeInfo CloudHvMemNode[CLOUDHV_MAX_MEM_NODE_NUM];
> +
> +RETURN_STATUS
> +EFIAPI
> +CloudHvVirtMemInfoPeiLibConstructor (
> +  VOID
> +  )
> +{
> +  VOID           *DeviceTreeBase;
> +  EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttributes;
> +  INT32          Node, Prev;
> +  UINT64         CurBase, MemBase;
> +  UINT64         CurSize;
> +  CONST CHAR8    *Type;
> +  INT32          Len;
> +  CONST UINT64   *RegProp;
> +  RETURN_STATUS  PcdStatus;
> +  UINT8          Index;
> +
> +  ZeroMem (CloudHvMemNode, sizeof(CloudHvMemNode[0]) * CLOUDHV_MAX_MEM_NODE_NUM);
[SAMI] Will sizeof (CloudHvMemNode) should be sufficient above? Also can 
you run uncrustify on your patches, please?
> +
> +  Index = 0;
> +  MemBase = FixedPcdGet64 (PcdSystemMemoryBase);
> +  ResourceAttributes = (
> +                        EFI_RESOURCE_ATTRIBUTE_PRESENT |
> +                        EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
> +                        EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
> +                        EFI_RESOURCE_ATTRIBUTE_TESTED
> +                        );
> +  DeviceTreeBase = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress);
> +  ASSERT (DeviceTreeBase != NULL);
> +
> +  //
> +  // Make sure we have a valid device tree blob
> +  //
> +  ASSERT (fdt_check_header (DeviceTreeBase) == 0);
[SAMI] I think the two ASSERTs above must return an error, otherwise 
they would result in a crash in release builds.
> +
> +  //
> +  // Look for the lowest memory node
> +  //
> +  for (Prev = 0; ; Prev = Node) {
> +    Node = fdt_next_node (DeviceTreeBase, Prev, NULL);
> +    if (Node < 0) {
> +      break;
> +    }
> +
> +    //
> +    // Check for memory node
> +    //
> +    Type = fdt_getprop (DeviceTreeBase, Node, "device_type", &Len);
> +    if (Type && (AsciiStrnCmp (Type, "memory", Len) == 0)) {
> +      //
> +      // Get the 'reg' property of this node. For now, we will assume
> +      // two 8 byte quantities for base and size, respectively.
> +      //
> +      RegProp = fdt_getprop (DeviceTreeBase, Node, "reg", &Len);
> +      if ((RegProp != 0) && (Len == (2 * sizeof (UINT64)))) {
> +        CurBase = fdt64_to_cpu (ReadUnaligned64 (RegProp));
> +        CurSize = fdt64_to_cpu (ReadUnaligned64 (RegProp + 1));
> +
> +        DEBUG ((
> +          DEBUG_INFO,
> +          "%a: System RAM @ 0x%lx - 0x%lx\n",
> +          __FUNCTION__,
> +          CurBase,
> +          CurBase + CurSize - 1
> +          ));
> +
> +        if (CurBase == MemBase) {
> +            FirMemNodeBase = CurBase;
> +            FirMemNodeSize = CurSize;
> +        }
> +
> +        CloudHvMemNode[Index].Base = CurBase;
> +        CloudHvMemNode[Index].Size = CurSize;
> +        Index++;
> +        // We should build Hob seperately for the memory node except the first one
> +        if (CurBase != MemBase) {
[SAMI] Can this be made an else statement of the previous 'if (CurBase 
== MemBase)' statement  by reordeing the few statements above?
> +          BuildResourceDescriptorHob (
> +            EFI_RESOURCE_SYSTEM_MEMORY,
> +            ResourceAttributes,
> +            CurBase,
> +            CurSize
> +            );
> +        }
> +        if (Index >= CLOUDHV_MAX_MEM_NODE_NUM) {
> +          DEBUG ((
> +            DEBUG_WARN,
> +            "%a: memory node larger than %d will not be included into Memory System\n",
> +            __FUNCTION__,
> +            CLOUDHV_MAX_MEM_NODE_NUM
> +            ));
> +          break;
> +        }
> +      } else {
> +        DEBUG ((
> +          DEBUG_ERROR,
> +          "%a: Failed to parse FDT memory node\n",
> +          __FUNCTION__
> +          ));
> +      }
> +    }
> +  }
> +
> +  //
> +  // Make sure the start of DRAM matches our expectation
> +  //
> +  ASSERT (FixedPcdGet64 (PcdSystemMemoryBase) == FirMemNodeBase);
[SAMI] This assert is checking that the a memory node with 
PcdSystemMemoryBasehas been found in the DT. If not found an error must 
be returned.
> +  PcdStatus = PcdSet64S (PcdSystemMemorySize, FirMemNodeSize);
> +  ASSERT_RETURN_ERROR (PcdStatus);
> +  ASSERT (
> +    (((UINT64)PcdGet64 (PcdFdBaseAddress) +
> +      (UINT64)PcdGet32 (PcdFdSize)) <= FirMemNodeBase) ||
> +    ((UINT64)PcdGet64 (PcdFdBaseAddress) >= (FirMemNodeBase + FirMemNodeSize))
> +    );
> +
> +  return RETURN_SUCCESS;
> +}
> +
> +// Number of Virtual Memory Map Descriptors
> +#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS  (4 + CLOUDHV_MAX_MEM_NODE_NUM)
> +
> +//
> +// Core peripherals such as the UART, the GIC and the RTC are
> +// all mapped in the 'miscellaneous device I/O' region, which we just map
> +// in its entirety rather than device by device. Note that it does not
> +// cover any of the NOR flash banks or PCI resource windows.
> +//
> +#define MACH_VIRT_PERIPH_BASE  0x00400000
> +#define MACH_VIRT_PERIPH_SIZE  0x0FC00000
> +
> +//
> +// The top of the 64M memory region under 4GB reserved for device
> +//
> +#define TOP_32BIT_DEVICE_BASE  0xFC000000
> +#define TOP_32BIT_DEVICE_SIZE  0x04000000
> +
[SAMI] Is it possible to move the all the defines in this file and the 
structure definition to a separate header file, please?
> +/**
> +  Return the Virtual Memory Map of your platform
> +
> +  This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU
> +  on your platform.
> +
> +  @param[out]   VirtualMemoryMap    Array of ARM_MEMORY_REGION_DESCRIPTOR
> +                                    describing a Physical-to-Virtual Memory
> +                                    mapping. This array must be ended by a
> +                                    zero-filled entry. The allocated memory
> +                                    will not be freed.
> +
> +**/
> +VOID
> +ArmVirtGetMemoryMap (
> +  OUT ARM_MEMORY_REGION_DESCRIPTOR  **VirtualMemoryMap
> +  )
> +{
> +  ARM_MEMORY_REGION_DESCRIPTOR  *VirtualMemoryTable;
> +  UINT8 Index = 0, i = 0;
[SAMI] Please change variable name 'i' to MemNodeIndex.
> +
> +  ASSERT (VirtualMemoryMap != NULL);
> +
> +  VirtualMemoryTable = AllocatePool (
> +                         sizeof (ARM_MEMORY_REGION_DESCRIPTOR) *
> +                         MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS
> +                         );
> +
> +  if (VirtualMemoryTable == NULL) {
> +    DEBUG ((DEBUG_ERROR, "%a: Error: Failed AllocatePool()\n", __FUNCTION__));
> +    return;
> +  }
> +    // System DRAM
> +  while (CloudHvMemNode[i].Size != 0) {
> +    VirtualMemoryTable[Index].PhysicalBase = CloudHvMemNode[i].Base;
> +    VirtualMemoryTable[Index].VirtualBase  = CloudHvMemNode[i].Base;
> +    VirtualMemoryTable[Index].Length       = CloudHvMemNode[i].Size;
> +    VirtualMemoryTable[Index].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
> +
> +    DEBUG ((
> +      DEBUG_INFO,
> +      "%a: Dumping System DRAM Memory Node%d Map:\n"
> +      "\tPhysicalBase: 0x%lX\n"
> +      "\tVirtualBase: 0x%lX\n"
> +      "\tLength: 0x%lX\n",
> +      __FUNCTION__,
> +      i,
> +      VirtualMemoryTable[Index].PhysicalBase,
> +      VirtualMemoryTable[Index].VirtualBase,
> +      VirtualMemoryTable[Index].Length
> +      ));
> +    Index++;
> +    i++;
> +  }
> +  // Memory mapped peripherals (UART, RTC, GIC, virtio-mmio, etc)
> +  VirtualMemoryTable[Index].PhysicalBase = MACH_VIRT_PERIPH_BASE;
> +  VirtualMemoryTable[Index].VirtualBase  = MACH_VIRT_PERIPH_BASE;
> +  VirtualMemoryTable[Index].Length       = MACH_VIRT_PERIPH_SIZE;
> +  VirtualMemoryTable[Index].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
> +  Index++;
> +
> +  // Map the FV region as normal executable memory
> +  VirtualMemoryTable[Index].PhysicalBase = PcdGet64 (PcdFvBaseAddress);
> +  VirtualMemoryTable[Index].VirtualBase  = VirtualMemoryTable[Index].PhysicalBase;
> +  VirtualMemoryTable[Index].Length       = FixedPcdGet32 (PcdFvSize);
> +  VirtualMemoryTable[Index].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
> +  Index++;
> +
> +  // Memory mapped for 32bit device (like TPM)
> +  VirtualMemoryTable[Index].PhysicalBase = TOP_32BIT_DEVICE_BASE;
> +  VirtualMemoryTable[Index].VirtualBase  = TOP_32BIT_DEVICE_BASE;
> +  VirtualMemoryTable[Index].Length       = TOP_32BIT_DEVICE_SIZE;
> +  VirtualMemoryTable[Index].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
> +  Index++;
> +
> +  // End of Table
> +  ZeroMem (&VirtualMemoryTable[Index], sizeof (ARM_MEMORY_REGION_DESCRIPTOR));
> +
> +  *VirtualMemoryMap = VirtualMemoryTable;
> +}
> diff --git a/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoPeiLib.inf b/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoPeiLib.inf
> new file mode 100755
> index 0000000000..5dd96faadd
> --- /dev/null
> +++ b/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoPeiLib.inf
> @@ -0,0 +1,46 @@
> +#/* @file
> +#
> +#  Copyright (c) 2011-2015, ARM Limited. All rights reserved.
> +#  Copyright (c) 2014-2017, Linaro Limited. All rights reserved.
> +#
> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
> +#
> +#*/
> +
> +[Defines]
> +  INF_VERSION                    = 0x0001001A
[SAMI] Please set version as 0x0001001B.
> +  BASE_NAME                      = QemuVirtMemInfoPeiLib
> +  FILE_GUID                      = 0c4d10cf-d949-49b4-bd13-47a4ae22efce
[SAMI] This GUID is conflicting with 
ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf. Please 
define a new GUID.
> +  MODULE_TYPE                    = BASE
> +  VERSION_STRING                 = 1.0
> +  LIBRARY_CLASS                  = ArmVirtMemInfoLib|PEIM
> +  CONSTRUCTOR                    = CloudHvVirtMemInfoPeiLibConstructor
> +
> +[Sources]
> +  CloudHvVirtMemInfoLib.c
> +
> +[Packages]
> +  ArmPkg/ArmPkg.dec
> +  ArmVirtPkg/ArmVirtPkg.dec
> +  EmbeddedPkg/EmbeddedPkg.dec
> +  MdeModulePkg/MdeModulePkg.dec
> +  MdePkg/MdePkg.dec
> +
> +[LibraryClasses]
> +  ArmLib
> +  BaseMemoryLib
> +  DebugLib
> +  FdtLib
> +  PcdLib
> +  MemoryAllocationLib
[SAMI] Please sort in alphabetical order.
> +
> +[Pcd]
> +  gArmTokenSpaceGuid.PcdFdBaseAddress
> +  gArmTokenSpaceGuid.PcdFvBaseAddress
> +  gArmTokenSpaceGuid.PcdSystemMemoryBase
> +  gArmTokenSpaceGuid.PcdSystemMemorySize
> +
> +[FixedPcd]
> +  gArmTokenSpaceGuid.PcdFdSize
> +  gArmTokenSpaceGuid.PcdFvSize
> +  gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress

[-- Attachment #2: Type: text/html, Size: 15584 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] CloudHv/arm: switch PeiMemLib to its own
  2022-07-29  7:21 ` [PATCH 2/2] CloudHv/arm: switch PeiMemLib to its own Jianyong Wu
@ 2022-08-08 11:29   ` Sami Mujawar
  0 siblings, 0 replies; 11+ messages in thread
From: Sami Mujawar @ 2022-08-08 11:29 UTC (permalink / raw)
  To: Jianyong Wu, devel; +Cc: ard.biesheuvel, justin.he, nd@arm.com

Hi Jianyong,

Thank you for this patch.

This change looks good to me.

Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>

Regards,

Sami Mujawar

On 29/07/2022 08:21 am, Jianyong Wu wrote:
> As Cloud Hypervisor has its own PeiMemLib, change it in dsc file
> accordingly.
>
> Signed-off-by: Jianyong Wu <jianyong.wu@arm.com>
> ---
>   ArmVirtPkg/ArmVirtCloudHv.dsc | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/ArmVirtPkg/ArmVirtCloudHv.dsc b/ArmVirtPkg/ArmVirtCloudHv.dsc
> index 7559386a1d..7ca7a391d9 100644
> --- a/ArmVirtPkg/ArmVirtCloudHv.dsc
> +++ b/ArmVirtPkg/ArmVirtCloudHv.dsc
> @@ -60,7 +60,7 @@
>   !include MdePkg/MdeLibs.dsc.inc
>   
>   [LibraryClasses.common.PEIM]
> -  ArmVirtMemInfoLib|ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf
> +  ArmVirtMemInfoLib|ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoPeiLib.inf
>   
>   [LibraryClasses.common.DXE_DRIVER]
>     ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/2] CloudHv/arm: add PeiMemInfoLib
  2022-08-08 11:27   ` Sami Mujawar
@ 2022-08-09  8:31     ` Jianyong Wu
       [not found]     ` <1709A00AB94047B2.29555@groups.io>
  1 sibling, 0 replies; 11+ messages in thread
From: Jianyong Wu @ 2022-08-09  8:31 UTC (permalink / raw)
  To: Sami Mujawar, devel@edk2.groups.io
  Cc: ard.biesheuvel@linaro.org, Justin He, nd

[-- Attachment #1: Type: text/plain, Size: 1006 bytes --]

Hi Sami,

Thanks for review. All the comments are Ok for me. Just one inline reply:

+

+struct CloudHvMemNodeInfo CloudHvMemNode[CLOUDHV_MAX_MEM_NODE_NUM];

+

+RETURN_STATUS

+EFIAPI

+CloudHvVirtMemInfoPeiLibConstructor (

+  VOID

+  )

+{

+  VOID           *DeviceTreeBase;

+  EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttributes;

+  INT32          Node, Prev;

+  UINT64         CurBase, MemBase;

+  UINT64         CurSize;

+  CONST CHAR8    *Type;

+  INT32          Len;

+  CONST UINT64   *RegProp;

+  RETURN_STATUS  PcdStatus;

+  UINT8          Index;

+

+  ZeroMem (CloudHvMemNode, sizeof(CloudHvMemNode[0]) * CLOUDHV_MAX_MEM_NODE_NUM);
[SAMI] Will sizeof (CloudHvMemNode) should be sufficient above? Also, can you run uncrustify on your patches, please?

[Jong] The local uncrustify test environment is not ready. But I think “sizeof” here is OK, as this struct contains only two u64 variables, thus no padding here.

Thanks
Jianyong


[-- Attachment #2: Type: text/html, Size: 4258 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [edk2-devel] [PATCH 1/2] CloudHv/arm: add PeiMemInfoLib
       [not found]     ` <1709A00AB94047B2.29555@groups.io>
@ 2022-08-18  5:22       ` Jianyong Wu
  2022-08-18 11:40         ` Sami Mujawar
  0 siblings, 1 reply; 11+ messages in thread
From: Jianyong Wu @ 2022-08-18  5:22 UTC (permalink / raw)
  To: devel@edk2.groups.io, Jianyong Wu, Sami Mujawar
  Cc: Ard Biesheuvel, Justin He, nd

[-- Attachment #1: Type: text/plain, Size: 1078 bytes --]

Hi Sami,

Thanks for review. All the comments are Ok for me. Just one inline reply:


+

+struct CloudHvMemNodeInfo CloudHvMemNode[CLOUDHV_MAX_MEM_NODE_NUM];

+

+RETURN_STATUS

+EFIAPI

+CloudHvVirtMemInfoPeiLibConstructor (

+  VOID

+  )

+{

+  VOID           *DeviceTreeBase;

+  EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttributes;

+  INT32          Node, Prev;

+  UINT64         CurBase, MemBase;

+  UINT64         CurSize;

+  CONST CHAR8    *Type;

+  INT32          Len;

+  CONST UINT64   *RegProp;

+  RETURN_STATUS  PcdStatus;

+  UINT8          Index;

+

+  ZeroMem (CloudHvMemNode, sizeof(CloudHvMemNode[0]) * CLOUDHV_MAX_MEM_NODE_NUM);
[SAMI] Will sizeof (CloudHvMemNode) should be sufficient above? Also, can you run uncrustify on your patches, please?

[Jong] The local uncrustify test environment is not ready. But I think “sizeof” here is OK, as this struct contains only two u64 variables, thus no padding here. If sizeof is not preference here, is there any suggestion from you?

Thanks
Jianyong



[-- Attachment #2: Type: text/html, Size: 4520 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [edk2-devel] [PATCH 1/2] CloudHv/arm: add PeiMemInfoLib
  2022-08-18  5:22       ` [edk2-devel] " Jianyong Wu
@ 2022-08-18 11:40         ` Sami Mujawar
  2022-08-19  7:41           ` Jianyong Wu
  0 siblings, 1 reply; 11+ messages in thread
From: Sami Mujawar @ 2022-08-18 11:40 UTC (permalink / raw)
  To: Jianyong Wu, devel@edk2.groups.io; +Cc: Ard Biesheuvel, Justin He, nd

[-- Attachment #1: Type: text/plain, Size: 1774 bytes --]

Hi Jianyong,

Please find my response inline marked [SAMI].

Regards,

Sami Mujawar

From: Jianyong Wu <Jianyong.Wu@arm.com>
Date: Thursday, 18 August 2022 at 06:22
To: "devel@edk2.groups.io" <devel@edk2.groups.io>, Jianyong Wu <Jianyong.Wu@arm.com>, Sami Mujawar <Sami.Mujawar@arm.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>, Justin He <Justin.He@arm.com>, nd <nd@arm.com>
Subject: RE: [edk2-devel] [PATCH 1/2] CloudHv/arm: add PeiMemInfoLib

Hi Sami,

Thanks for review. All the comments are Ok for me. Just one inline reply:


+

+struct CloudHvMemNodeInfo CloudHvMemNode[CLOUDHV_MAX_MEM_NODE_NUM];

+

+RETURN_STATUS

+EFIAPI

+CloudHvVirtMemInfoPeiLibConstructor (

+  VOID

+  )

+{

+  VOID           *DeviceTreeBase;

+  EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttributes;

+  INT32          Node, Prev;

+  UINT64         CurBase, MemBase;

+  UINT64         CurSize;

+  CONST CHAR8    *Type;

+  INT32          Len;

+  CONST UINT64   *RegProp;

+  RETURN_STATUS  PcdStatus;

+  UINT8          Index;

+

+  ZeroMem (CloudHvMemNode, sizeof(CloudHvMemNode[0]) * CLOUDHV_MAX_MEM_NODE_NUM);
[SAMI] Will sizeof (CloudHvMemNode) should be sufficient above? Also, can you run uncrustify on your patches, please?

[Jong] The local uncrustify test environment is not ready. But I think “sizeof” here is OK, as this struct contains only two u64 variables, thus no padding here. If sizeof is not preference here, is there any suggestion from you?
[SAMI] I think you could just use

+  ZeroMem (CloudHvMemNode, sizeof(CloudHvMemNode));

Also, let me know if you need any help to get uncrustify working locally. I will dig out the relevant information for you.

[/SAMI]


Thanks
Jianyong



[-- Attachment #2: Type: text/html, Size: 7324 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [edk2-devel] [PATCH 1/2] CloudHv/arm: add PeiMemInfoLib
  2022-08-18 11:40         ` Sami Mujawar
@ 2022-08-19  7:41           ` Jianyong Wu
  0 siblings, 0 replies; 11+ messages in thread
From: Jianyong Wu @ 2022-08-19  7:41 UTC (permalink / raw)
  To: Sami Mujawar, devel@edk2.groups.io; +Cc: Ard Biesheuvel, Justin He, nd

[-- Attachment #1: Type: text/plain, Size: 2368 bytes --]

Thanks Sami. I will fix them all and send the v2 later.

From: Sami Mujawar <Sami.Mujawar@arm.com>
Sent: Thursday, August 18, 2022 7:41 PM
To: Jianyong Wu <Jianyong.Wu@arm.com>; devel@edk2.groups.io
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>; Justin He <Justin.He@arm.com>; nd <nd@arm.com>
Subject: Re: [edk2-devel] [PATCH 1/2] CloudHv/arm: add PeiMemInfoLib

Hi Jianyong,

Please find my response inline marked [SAMI].

Regards,

Sami Mujawar

From: Jianyong Wu <Jianyong.Wu@arm.com<mailto:Jianyong.Wu@arm.com>>
Date: Thursday, 18 August 2022 at 06:22
To: "devel@edk2.groups.io<mailto:devel@edk2.groups.io>" <devel@edk2.groups.io<mailto:devel@edk2.groups.io>>, Jianyong Wu <Jianyong.Wu@arm.com<mailto:Jianyong.Wu@arm.com>>, Sami Mujawar <Sami.Mujawar@arm.com<mailto:Sami.Mujawar@arm.com>>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org<mailto:ardb+tianocore@kernel.org>>, Justin He <Justin.He@arm.com<mailto:Justin.He@arm.com>>, nd <nd@arm.com<mailto:nd@arm.com>>
Subject: RE: [edk2-devel] [PATCH 1/2] CloudHv/arm: add PeiMemInfoLib

Hi Sami,

Thanks for review. All the comments are Ok for me. Just one inline reply:


+

+struct CloudHvMemNodeInfo CloudHvMemNode[CLOUDHV_MAX_MEM_NODE_NUM];

+

+RETURN_STATUS

+EFIAPI

+CloudHvVirtMemInfoPeiLibConstructor (

+  VOID

+  )

+{

+  VOID           *DeviceTreeBase;

+  EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttributes;

+  INT32          Node, Prev;

+  UINT64         CurBase, MemBase;

+  UINT64         CurSize;

+  CONST CHAR8    *Type;

+  INT32          Len;

+  CONST UINT64   *RegProp;

+  RETURN_STATUS  PcdStatus;

+  UINT8          Index;

+

+  ZeroMem (CloudHvMemNode, sizeof(CloudHvMemNode[0]) * CLOUDHV_MAX_MEM_NODE_NUM);
[SAMI] Will sizeof (CloudHvMemNode) should be sufficient above? Also, can you run uncrustify on your patches, please?

[Jong] The local uncrustify test environment is not ready. But I think “sizeof” here is OK, as this struct contains only two u64 variables, thus no padding here. If sizeof is not preference here, is there any suggestion from you?
[SAMI] I think you could just use

+  ZeroMem (CloudHvMemNode, sizeof(CloudHvMemNode));

Also, let me know if you need any help to get uncrustify working locally. I will dig out the relevant information for you.

[/SAMI]


Thanks
Jianyong



[-- Attachment #2: Type: text/html, Size: 7681 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-08-19  7:41 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-29  7:21 [PATCH 0/2] CloudHv/arm: Add specific mem info lib Jianyong Wu
2022-07-29  7:21 ` [PATCH 1/2] CloudHv/arm: add PeiMemInfoLib Jianyong Wu
2022-08-08 11:27   ` Sami Mujawar
2022-08-09  8:31     ` Jianyong Wu
     [not found]     ` <1709A00AB94047B2.29555@groups.io>
2022-08-18  5:22       ` [edk2-devel] " Jianyong Wu
2022-08-18 11:40         ` Sami Mujawar
2022-08-19  7:41           ` Jianyong Wu
2022-07-29  7:21 ` [PATCH 2/2] CloudHv/arm: switch PeiMemLib to its own Jianyong Wu
2022-08-08 11:29   ` Sami Mujawar
     [not found] ` <17063BDF40129601.5552@groups.io>
2022-08-08  7:03   ` [edk2-devel] [PATCH 1/2] CloudHv/arm: add PeiMemInfoLib Jianyong Wu
     [not found] ` <17063BDFB8173BFA.24450@groups.io>
2022-08-08  7:04   ` [edk2-devel] [PATCH 2/2] CloudHv/arm: switch PeiMemLib to its own Jianyong Wu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox