]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPkg/Drivers/CpuDxe/CpuMmuCommon.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / ArmPkg / Drivers / CpuDxe / CpuMmuCommon.c
index 54d9b016333107be81fa07c6fb01996bb0652c07..2e73719dce04ceb5a3b18360e3537147a9d1298c 100644 (file)
@@ -3,13 +3,7 @@
 *  Copyright (c) 2013, ARM Limited. All rights reserved.\r
 *  Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
 *\r
-*  This program and the accompanying materials\r
-*  are licensed and made available under the terms and conditions of the BSD License\r
-*  which accompanies this distribution.  The full text of the license may be found at\r
-*  http://opensource.org/licenses/bsd-license.php\r
-*\r
-*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+*  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 *\r
 **/\r
 \r
 **/\r
 EFI_STATUS\r
 SearchGcdMemorySpaces (\r
-  IN EFI_GCD_MEMORY_SPACE_DESCRIPTOR    *MemorySpaceMap,\r
-  IN UINTN                               NumberOfDescriptors,\r
-  IN EFI_PHYSICAL_ADDRESS                BaseAddress,\r
-  IN UINT64                              Length,\r
-  OUT UINTN                             *StartIndex,\r
-  OUT UINTN                             *EndIndex\r
+  IN EFI_GCD_MEMORY_SPACE_DESCRIPTOR  *MemorySpaceMap,\r
+  IN UINTN                            NumberOfDescriptors,\r
+  IN EFI_PHYSICAL_ADDRESS             BaseAddress,\r
+  IN UINT64                           Length,\r
+  OUT UINTN                           *StartIndex,\r
+  OUT UINTN                           *EndIndex\r
   )\r
 {\r
-  UINTN           Index;\r
+  UINTN  Index;\r
 \r
   *StartIndex = 0;\r
   *EndIndex   = 0;\r
   for (Index = 0; Index < NumberOfDescriptors; Index++) {\r
     if ((BaseAddress >= MemorySpaceMap[Index].BaseAddress) &&\r
-        (BaseAddress < (MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length))) {\r
+        (BaseAddress < (MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length)))\r
+    {\r
       *StartIndex = Index;\r
     }\r
+\r
     if (((BaseAddress + Length - 1) >= MemorySpaceMap[Index].BaseAddress) &&\r
-        ((BaseAddress + Length - 1) < (MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length))) {\r
+        ((BaseAddress + Length - 1) < (MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length)))\r
+    {\r
       *EndIndex = Index;\r
       return EFI_SUCCESS;\r
     }\r
   }\r
+\r
   return EFI_NOT_FOUND;\r
 }\r
 \r
-\r
 /**\r
   Sets the attributes for a specified range in Gcd Memory Space Map.\r
 \r
@@ -80,11 +77,11 @@ SearchGcdMemorySpaces (
 **/\r
 EFI_STATUS\r
 SetGcdMemorySpaceAttributes (\r
-  IN EFI_GCD_MEMORY_SPACE_DESCRIPTOR    *MemorySpaceMap,\r
-  IN UINTN                               NumberOfDescriptors,\r
-  IN EFI_PHYSICAL_ADDRESS                BaseAddress,\r
-  IN UINT64                              Length,\r
-  IN UINT64                              Attributes\r
+  IN EFI_GCD_MEMORY_SPACE_DESCRIPTOR  *MemorySpaceMap,\r
+  IN UINTN                            NumberOfDescriptors,\r
+  IN EFI_PHYSICAL_ADDRESS             BaseAddress,\r
+  IN UINT64                           Length,\r
+  IN UINT64                           Attributes\r
   )\r
 {\r
   EFI_STATUS            Status;\r
@@ -94,14 +91,21 @@ SetGcdMemorySpaceAttributes (
   EFI_PHYSICAL_ADDRESS  RegionStart;\r
   UINT64                RegionLength;\r
 \r
-  DEBUG ((DEBUG_GCD, "SetGcdMemorySpaceAttributes[0x%lX; 0x%lX] = 0x%lX\n",\r
-      BaseAddress, BaseAddress + Length, Attributes));\r
+  DEBUG ((\r
+    DEBUG_GCD,\r
+    "SetGcdMemorySpaceAttributes[0x%lX; 0x%lX] = 0x%lX\n",\r
+    BaseAddress,\r
+    BaseAddress + Length,\r
+    Attributes\r
+    ));\r
 \r
   // We do not support a smaller granularity than 4KB on ARM Architecture\r
   if ((Length & EFI_PAGE_MASK) != 0) {\r
-    DEBUG ((DEBUG_WARN,\r
-            "Warning: We do not support smaller granularity than 4KB on ARM Architecture (passed length: 0x%lX).\n",\r
-            Length));\r
+    DEBUG ((\r
+      DEBUG_WARN,\r
+      "Warning: We do not support smaller granularity than 4KB on ARM Architecture (passed length: 0x%lX).\n",\r
+      Length\r
+      ));\r
   }\r
 \r
   //\r
@@ -126,6 +130,7 @@ SetGcdMemorySpaceAttributes (
     if (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeNonExistent) {\r
       continue;\r
     }\r
+\r
     //\r
     // Calculate the start and end address of the overlapping range\r
     //\r
@@ -134,11 +139,13 @@ SetGcdMemorySpaceAttributes (
     } else {\r
       RegionStart = MemorySpaceMap[Index].BaseAddress;\r
     }\r
+\r
     if ((BaseAddress + Length - 1) < (MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length)) {\r
       RegionLength = BaseAddress + Length - RegionStart;\r
     } else {\r
       RegionLength = MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length - RegionStart;\r
     }\r
+\r
     //\r
     // Set memory attributes according to MTRR attribute and the original attribute of descriptor\r
     //\r
@@ -176,10 +183,10 @@ SetGcdMemorySpaceAttributes (
 EFI_STATUS\r
 EFIAPI\r
 CpuSetMemoryAttributes (\r
-  IN EFI_CPU_ARCH_PROTOCOL    *This,\r
-  IN EFI_PHYSICAL_ADDRESS      BaseAddress,\r
-  IN UINT64                    Length,\r
-  IN UINT64                    EfiAttributes\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  IN EFI_PHYSICAL_ADDRESS   BaseAddress,\r
+  IN UINT64                 Length,\r
+  IN UINT64                 EfiAttributes\r
   )\r
 {\r
   EFI_STATUS  Status;\r
@@ -188,9 +195,13 @@ CpuSetMemoryAttributes (
   UINTN       RegionLength;\r
   UINTN       RegionArmAttributes;\r
 \r
+  if (mIsFlushingGCD) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
   if ((BaseAddress & (SIZE_4KB - 1)) != 0) {\r
     // Minimum granularity is SIZE_4KB (4KB on ARM)\r
-    DEBUG ((EFI_D_PAGE, "CpuSetMemoryAttributes(%lx, %lx, %lx): Minimum ganularity is SIZE_4KB\n", BaseAddress, Length, EfiAttributes));\r
+    DEBUG ((DEBUG_PAGE, "CpuSetMemoryAttributes(%lx, %lx, %lx): Minimum granularity is SIZE_4KB\n", BaseAddress, Length, EfiAttributes));\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
@@ -199,85 +210,15 @@ CpuSetMemoryAttributes (
 \r
   // Get the region starting from 'BaseAddress' and its 'Attribute'\r
   RegionBaseAddress = BaseAddress;\r
-  Status = GetMemoryRegion (&RegionBaseAddress, &RegionLength, &RegionArmAttributes);\r
+  Status            = GetMemoryRegion (&RegionBaseAddress, &RegionLength, &RegionArmAttributes);\r
 \r
   // Data & Instruction Caches are flushed when we set new memory attributes.\r
   // So, we only set the attributes if the new region is different.\r
   if (EFI_ERROR (Status) || (RegionArmAttributes != ArmAttributes) ||\r
       ((BaseAddress + Length) > (RegionBaseAddress + RegionLength)))\r
   {\r
-    return SetMemoryAttributes (BaseAddress, Length, EfiAttributes, 0);\r
+    return ArmSetMemoryAttributes (BaseAddress, Length, EfiAttributes);\r
   } else {\r
     return EFI_SUCCESS;\r
   }\r
 }\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-CpuConvertPagesToUncachedVirtualAddress (\r
-  IN  VIRTUAL_UNCACHED_PAGES_PROTOCOL  *This,\r
-  IN  EFI_PHYSICAL_ADDRESS              Address,\r
-  IN  UINTN                             Length,\r
-  IN  EFI_PHYSICAL_ADDRESS              VirtualMask,\r
-  OUT UINT64                           *Attributes     OPTIONAL\r
-  )\r
-{\r
-  EFI_STATUS                      Status;\r
-  EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor;\r
-\r
-  if (Attributes != NULL) {\r
-    Status = gDS->GetMemorySpaceDescriptor (Address, &GcdDescriptor);\r
-    if (!EFI_ERROR (Status)) {\r
-      *Attributes = GcdDescriptor.Attributes;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Make this address range page fault if accessed. If it is a DMA buffer than this would\r
-  // be the PCI address. Code should always use the CPU address, and we will or in VirtualMask\r
-  // to that address.\r
-  //\r
-  Status = SetMemoryAttributes (Address, Length, EFI_MEMORY_RO, 0);\r
-  if (!EFI_ERROR (Status)) {\r
-    Status = SetMemoryAttributes (Address | VirtualMask, Length, EFI_MEMORY_UC, VirtualMask);\r
-  }\r
-\r
-  DEBUG ((DEBUG_INFO | DEBUG_LOAD, "CpuConvertPagesToUncachedVirtualAddress()\n    Unmapped 0x%08lx Mapped 0x%08lx 0x%x bytes\n", Address, Address | VirtualMask, Length));\r
-\r
-  return Status;\r
-}\r
-\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-CpuReconvertPages (\r
-  IN  VIRTUAL_UNCACHED_PAGES_PROTOCOL  *This,\r
-  IN  EFI_PHYSICAL_ADDRESS              Address,\r
-  IN  UINTN                             Length,\r
-  IN  EFI_PHYSICAL_ADDRESS              VirtualMask,\r
-  IN  UINT64                            Attributes\r
-  )\r
-{\r
-  EFI_STATUS      Status;\r
-\r
-  DEBUG ((DEBUG_INFO | DEBUG_LOAD, "CpuReconvertPages(%lx, %x, %lx, %lx)\n", Address, Length, VirtualMask, Attributes));\r
-\r
-  //\r
-  // Unmap the aliased Address\r
-  //\r
-  Status = SetMemoryAttributes (Address | VirtualMask, Length, EFI_MEMORY_RO, 0);\r
-  if (!EFI_ERROR (Status)) {\r
-    //\r
-    // Restore atttributes\r
-    //\r
-    Status = SetMemoryAttributes (Address, Length, Attributes, 0);\r
-  }\r
-\r
-  return Status;\r
-}\r
-\r
-\r
-VIRTUAL_UNCACHED_PAGES_PROTOCOL  gVirtualUncachedPages = {\r
-  CpuConvertPagesToUncachedVirtualAddress,\r
-  CpuReconvertPages\r
-};\r