]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/Gcd/Gcd.c
MdePkg/MdeModulePkg: Implement the missing SetMemorySpaceCapabilities function.
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Gcd / Gcd.c
index 5292d368c5a0a89a1aa6dd795fedf754dd86821b..7268465f36584e1a60dd6f6af90cbcc1bbb07412 100644 (file)
@@ -3,7 +3,7 @@
   The GCD services are used to manage the memory and I/O regions that\r
   are accessible to the CPU that is executing the DXE core.\r
 \r
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\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
@@ -148,7 +148,7 @@ CoreDumpGcdMemorySpaceMap (
     UINTN                            Index;\r
    \r
     Status = CoreGetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);\r
-    ASSERT_EFI_ERROR (Status);\r
+    ASSERT (Status == EFI_SUCCESS && MemorySpaceMap != NULL);\r
 \r
     if (InitialMap) {\r
       DEBUG ((DEBUG_GCD, "GCD:Initial GCD Memory Space Map\n"));\r
@@ -190,7 +190,7 @@ CoreDumpGcdIoSpaceMap (
     UINTN                        Index;\r
     \r
     Status = CoreGetIoSpaceMap (&NumberOfDescriptors, &IoSpaceMap);\r
-    ASSERT_EFI_ERROR (Status);\r
+    ASSERT (Status == EFI_SUCCESS && IoSpaceMap != NULL);\r
     \r
     if (InitialMap) {\r
       DEBUG ((DEBUG_GCD, "GCD:Initial GCD I/O Space Map\n"));\r
@@ -689,7 +689,8 @@ ConverToCpuArchAttributes (
   @retval EFI_NOT_FOUND          Free a non-using space or remove a non-exist\r
                                  space, and so on.\r
   @retval EFI_OUT_OF_RESOURCES   No buffer could be allocated.\r
-\r
+  @retval EFI_NOT_AVAILABLE_YET  The attributes cannot be set because CPU architectural protocol\r
+                                 is not available yet.\r
 **/\r
 EFI_STATUS\r
 CoreConvertSpace (\r
@@ -797,7 +798,7 @@ CoreConvertSpace (
       }\r
       break;\r
     //\r
-    // Set attribute operations\r
+    // Set attributes operation\r
     //\r
     case GCD_SET_ATTRIBUTES_MEMORY_OPERATION:\r
       if ((Attributes & EFI_MEMORY_RUNTIME) != 0) {\r
@@ -811,6 +812,23 @@ CoreConvertSpace (
         goto Done;\r
       }\r
       break;\r
+    //
+    // Set capabilities operation
+    //
+    case GCD_SET_CAPABILITIES_MEMORY_OPERATION:
+      if ((BaseAddress & EFI_PAGE_MASK) != 0 || (Length & EFI_PAGE_MASK) != 0) {
+        Status = EFI_INVALID_PARAMETER;
+
+        goto Done;
+      }\r
+      //
+      // Current attributes must still be supported with new capabilities\r
+      //
+      if ((Capabilities & Entry->Attributes) != Entry->Attributes) {
+        Status = EFI_UNSUPPORTED;
+        goto Done;
+      }
+      break;\r
     }\r
     Link = Link->ForwardLink;\r
   }\r
@@ -831,16 +849,20 @@ CoreConvertSpace (
     //\r
     CpuArchAttributes = ConverToCpuArchAttributes (Attributes);\r
     if (CpuArchAttributes != INVALID_CPU_ARCH_ATTRIBUTES) {\r
-      if (gCpu != NULL) {\r
+      if (gCpu == NULL) {\r
+        Status = EFI_NOT_AVAILABLE_YET;\r
+      } else {\r
         Status = gCpu->SetMemoryAttributes (\r
                          gCpu,\r
                          BaseAddress,\r
                          Length,\r
                          CpuArchAttributes\r
                          );\r
-        if (EFI_ERROR (Status)) {\r
-          goto Done;\r
-        }\r
+      }\r
+      if (EFI_ERROR (Status)) {\r
+        CoreFreePool (TopEntry);\r
+        CoreFreePool (BottomEntry);\r
+        goto Done;\r
       }\r
     }\r
   }\r
@@ -886,11 +908,17 @@ CoreConvertSpace (
       Entry->GcdIoType = EfiGcdIoTypeNonExistent;\r
       break;\r
     //\r
-    // Set attribute operations\r
+    // Set attributes operation\r
     //\r
     case GCD_SET_ATTRIBUTES_MEMORY_OPERATION:\r
       Entry->Attributes = Attributes;\r
       break;\r
+    //\r
+    // Set capabilities operation\r
+    //\r
+    case GCD_SET_CAPABILITIES_MEMORY_OPERATION:
+      Entry->Capabilities = Capabilities;
+      break;\r
     }\r
     Link = Link->ForwardLink;\r
   }\r
@@ -1007,15 +1035,15 @@ CoreAllocateSpace (
   //\r
   // Make sure parameters are valid\r
   //\r
-  if (GcdAllocateType < 0 || GcdAllocateType >= EfiGcdMaxAllocateType) {\r
+  if ((UINT32)GcdAllocateType >= EfiGcdMaxAllocateType) {\r
     DEBUG ((DEBUG_GCD, "  Status = %r\n", EFI_INVALID_PARAMETER));\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  if (GcdMemoryType < 0 || GcdMemoryType >= EfiGcdMemoryTypeMaximum) {\r
+  if ((UINT32)GcdMemoryType >= EfiGcdMemoryTypeMaximum) {\r
     DEBUG ((DEBUG_GCD, "  Status = %r\n", EFI_INVALID_PARAMETER));\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  if (GcdIoType < 0 || GcdIoType >= EfiGcdIoTypeMaximum) {\r
+  if ((UINT32)GcdIoType >= EfiGcdIoTypeMaximum) {\r
     DEBUG ((DEBUG_GCD, "  Status = %r\n", EFI_INVALID_PARAMETER));\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -1524,8 +1552,18 @@ CoreGetMemorySpaceDescriptor (
   @param  Length                 Specified length\r
   @param  Attributes             Specified attributes\r
 \r
-  @retval EFI_SUCCESS            Successfully set attribute of a segment of\r
-                                 memory space.\r
+  @retval EFI_SUCCESS           The attributes were set for the memory region.\r
+  @retval EFI_INVALID_PARAMETER Length is zero. \r
+  @retval EFI_UNSUPPORTED       The processor does not support one or more bytes of the memory\r
+                                resource range specified by BaseAddress and Length.\r
+  @retval EFI_UNSUPPORTED       The bit mask of attributes is not support for the memory resource\r
+                                range specified by BaseAddress and Length.\r
+  @retval EFI_ACCESS_DEFINED    The attributes for the memory resource range specified by\r
+                                BaseAddress and Length cannot be modified.\r
+  @retval EFI_OUT_OF_RESOURCES  There are not enough system resources to modify the attributes of\r
+                                the memory resource range.\r
+  @retval EFI_NOT_AVAILABLE_YET The attributes cannot be set because CPU architectural protocol is\r
+                                not available yet.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1543,6 +1581,45 @@ CoreSetMemorySpaceAttributes (
 }\r
 \r
 \r
+/**\r
+  Modifies the capabilities for a memory region in the global coherency domain of the\r
+  processor.\r
+\r
+  @param  BaseAddress      The physical address that is the start address of a memory region.\r
+  @param  Length           The size in bytes of the memory region.\r
+  @param  Capabilities     The bit mask of capabilities that the memory region supports.\r
+\r
+  @retval EFI_SUCCESS           The capabilities were set for the memory region.\r
+  @retval EFI_INVALID_PARAMETER Length is zero.\r
+  @retval EFI_UNSUPPORTED       The capabilities specified by Capabilities do not include the\r
+                                memory region attributes currently in use.\r
+  @retval EFI_ACCESS_DENIED     The capabilities for the memory resource range specified by\r
+                                BaseAddress and Length cannot be modified.\r
+  @retval EFI_OUT_OF_RESOURCES  There are not enough system resources to modify the capabilities\r
+                                of the memory resource range.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CoreSetMemorySpaceCapabilities (\r
+  IN EFI_PHYSICAL_ADDRESS  BaseAddress,\r
+  IN UINT64                Length,\r
+  IN UINT64                Capabilities\r
+  )\r
+{\r
+  EFI_STATUS    Status;
+
+  DEBUG ((DEBUG_GCD, "GCD:CoreSetMemorySpaceCapabilities(Base=%016lx,Length=%016lx)\n", BaseAddress, Length));\r
+  DEBUG ((DEBUG_GCD, "  Capabilities  = %016lx\n", Capabilities));
+
+  Status = CoreConvertSpace (GCD_SET_CAPABILITIES_MEMORY_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, Capabilities, 0);
+  if (!EFI_ERROR(Status)) {\r
+    CoreUpdateMemoryAttributes(BaseAddress, RShiftU64(Length, EFI_PAGE_SHIFT), Capabilities);
+  }
+
+  return Status;\r
+}\r
+\r
+\r
 /**\r
   Returns a map of the memory resources in the global coherency domain of the\r
   processor.\r