]> git.proxmox.com Git - mirror_edk2.git/commitdiff
IntelFrameworkPkg/LegacyBios.h: Add a macro to guarantee page 0 access
authorJian J Wang <jian.j.wang@intel.com>
Tue, 5 Dec 2017 07:57:38 +0000 (15:57 +0800)
committerStar Zeng <star.zeng@intel.com>
Fri, 8 Dec 2017 06:38:44 +0000 (14:38 +0800)
Due to the introduction of NULL pointer detection feature, page 0 will be
disabled if the feature is enabled, which will cause legacy code failed to
update legacy data in page 0. This macro is introduced to make sure the
page 0 is enabled before those code and restore the original status of it
afterwards.

Another reason to introduce this macro is to eliminate the dependency on
the PcdNullPointerDetectionPropertyMask. Because this is a new PCD, it
could cause some backward compatibility issue for some old packages.

This macro will simply check if the page 0 is disabled or not. If it's
disabled, it will enable it before code updating page 0 and disable it
afterwards. Otherwise, this macro will do nothing to page 0.

The usage of the macro will be look like (similar to DEBUG_CODE macro):

    ACCESS_PAGE0_CODE(
      <code accessing page 0>
    );

Cc: Liming Gao <liming.gao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
IntelFrameworkPkg/Include/Protocol/LegacyBios.h

index 641f101bcedeb27902828cd0fb1827294e57bca0..00a149e38783c24089e0ba0afbc4186c7af3da55 100644 (file)
@@ -1518,6 +1518,42 @@ struct _EFI_LEGACY_BIOS_PROTOCOL {
   EFI_LEGACY_BIOS_BOOT_UNCONVENTIONAL_DEVICE  BootUnconventionalDevice;\r
 };\r
 \r
+//\r
+// Legacy BIOS needs to access memory in page 0 (0-4095), which is disabled if\r
+// NULL pointer detection feature is enabled. Following macro can be used to\r
+// enable/disable page 0 before/after accessing it.\r
+//\r
+#define ACCESS_PAGE0_CODE(statements)                           \\r
+  do {                                                          \\r
+    EFI_STATUS                            Status_;              \\r
+    EFI_GCD_MEMORY_SPACE_DESCRIPTOR       Desc_;                \\r
+                                                                \\r
+    Desc_.Attributes = 0;                                       \\r
+    Status_ = gDS->GetMemorySpaceDescriptor (0, &Desc_);        \\r
+    ASSERT_EFI_ERROR (Status_);                                 \\r
+    if ((Desc_.Attributes & EFI_MEMORY_RP) != 0) {              \\r
+      Status_ = gDS->SetMemorySpaceAttributes (                 \\r
+                      0,                                        \\r
+                      EFI_PAGES_TO_SIZE(1),                     \\r
+                      Desc_.Attributes & ~(UINT64)EFI_MEMORY_RP \\r
+                      );                                        \\r
+      ASSERT_EFI_ERROR (Status_);                               \\r
+    }                                                           \\r
+                                                                \\r
+    {                                                           \\r
+      statements;                                               \\r
+    }                                                           \\r
+                                                                \\r
+    if ((Desc_.Attributes & EFI_MEMORY_RP) != 0) {              \\r
+      Status_ = gDS->SetMemorySpaceAttributes (                 \\r
+                      0,                                        \\r
+                      EFI_PAGES_TO_SIZE(1),                     \\r
+                      Desc_.Attributes                          \\r
+                      );                                        \\r
+      ASSERT_EFI_ERROR (Status_);                               \\r
+    }                                                           \\r
+  } while (FALSE)\r
+\r
 extern EFI_GUID gEfiLegacyBiosProtocolGuid;\r
 \r
 #endif\r