]> git.proxmox.com Git - mirror_edk2.git/commitdiff
IntelFrameworkModulePkg/KeyboardDxe: Use macro to enable/disable page 0
authorJian J Wang <jian.j.wang@intel.com>
Thu, 7 Dec 2017 09:00:50 +0000 (17:00 +0800)
committerStar Zeng <star.zeng@intel.com>
Fri, 8 Dec 2017 06:38:45 +0000 (14:38 +0800)
Current implementation uses following two methods

    EnableNullDetection()
    DisableNullDetection()

to enable/disable page 0. These two methods will check PCD
PcdNullPointerDetectionPropertyMask to know if the page 0 is disabled or not.
This is due to the fact that old GCD service doesn't provide paging related
attributes of memory block. Since this issue has been fixed, GCD services
can be used to determine the paging status of page 0. This is also make it
possible to just use a new macro

    ACCESS_PAGE0_CODE(
      <code accessing page 0>
    );

to replace above methods to do the same job, which also makes code more
readability.

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>
IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/BiosKeyboard.c
IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/KeyboardDxe.inf

index ebf03d30c1d448c94200a350f95789994782362b..ec525891dc7a5659af89d1151a008ee1cc84fd4f 100644 (file)
@@ -1732,98 +1732,6 @@ CheckKeyboardConnect (
   }\r
 }\r
 \r
-/**\r
-  Disable NULL pointer detection.\r
-**/\r
-VOID\r
-DisableNullDetection (\r
-  VOID\r
-  )\r
-{\r
-  EFI_STATUS                            Status;\r
-  EFI_GCD_MEMORY_SPACE_DESCRIPTOR       Desc;\r
-\r
-  if ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT0) == 0) {\r
-    return;\r
-  }\r
-\r
-  //\r
-  // Check current capabilities and attributes\r
-  //\r
-  Status = gDS->GetMemorySpaceDescriptor (0, &Desc);\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  //\r
-  // Try to add EFI_MEMORY_RP support if necessary\r
-  //\r
-  if ((Desc.Capabilities & EFI_MEMORY_RP) == 0) {\r
-    Desc.Capabilities |= EFI_MEMORY_RP;\r
-    Status = gDS->SetMemorySpaceCapabilities (0, EFI_PAGES_TO_SIZE(1),\r
-                                              Desc.Capabilities);\r
-    ASSERT_EFI_ERROR (Status);\r
-    if (EFI_ERROR (Status)) {\r
-      return;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Don't bother if EFI_MEMORY_RP is already cleared.\r
-  //\r
-  if ((Desc.Attributes & EFI_MEMORY_RP) != 0) {\r
-    Desc.Attributes &= ~EFI_MEMORY_RP;\r
-    Status = gDS->SetMemorySpaceAttributes (0, EFI_PAGES_TO_SIZE(1),\r
-                                            Desc.Attributes);\r
-    ASSERT_EFI_ERROR (Status);\r
-  } else {\r
-    DEBUG ((DEBUG_WARN, "!!! Page 0 is supposed to be disabled !!!\r\n"));\r
-  }\r
-}\r
-\r
-/**\r
-   Enable NULL pointer detection.\r
-**/\r
-VOID\r
-EnableNullDetection (\r
-  VOID\r
-  )\r
-{\r
-  EFI_STATUS                            Status;\r
-  EFI_GCD_MEMORY_SPACE_DESCRIPTOR       Desc;\r
-\r
-  if ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT0) == 0) {\r
-    return;\r
-  }\r
-\r
-  //\r
-  // Check current capabilities and attributes\r
-  //\r
-  Status = gDS->GetMemorySpaceDescriptor (0, &Desc);\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  //\r
-  // Try to add EFI_MEMORY_RP support if necessary\r
-  //\r
-  if ((Desc.Capabilities & EFI_MEMORY_RP) == 0) {\r
-    Desc.Capabilities |= EFI_MEMORY_RP;\r
-    Status = gDS->SetMemorySpaceCapabilities (0, EFI_PAGES_TO_SIZE(1),\r
-                                              Desc.Capabilities);\r
-    ASSERT_EFI_ERROR (Status);\r
-    if (EFI_ERROR (Status)) {\r
-      return;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Don't bother if EFI_MEMORY_RP is already set.\r
-  //\r
-  if ((Desc.Attributes & EFI_MEMORY_RP) == 0) {\r
-    Desc.Attributes |= EFI_MEMORY_RP;\r
-    Status = gDS->SetMemorySpaceAttributes (0, EFI_PAGES_TO_SIZE(1),\r
-                                            Desc.Attributes);\r
-    ASSERT_EFI_ERROR (Status);\r
-  }\r
-}\r
-\r
 /**\r
   Timer event handler: read a series of key stroke from 8042\r
   and put them into memory key buffer. \r
@@ -1931,16 +1839,13 @@ BiosKeyboardTimerHandler (
   //   0 Right Shift pressed\r
 \r
 \r
-  //\r
-  // Disable NULL pointer detection temporarily\r
-  //\r
-  DisableNullDetection ();\r
-\r
   //\r
   // Clear the CTRL and ALT BDA flag\r
   //\r
-  KbFlag1 = *((UINT8 *) (UINTN) 0x417);  // read the STATUS FLAGS 1\r
-  KbFlag2 = *((UINT8 *) (UINTN) 0x418); // read STATUS FLAGS 2\r
+  ACCESS_PAGE0_CODE (\r
+    KbFlag1 = *((UINT8 *) (UINTN) 0x417); // read the STATUS FLAGS 1\r
+    KbFlag2 = *((UINT8 *) (UINTN) 0x418); // read STATUS FLAGS 2\r
+  );\r
 \r
   DEBUG_CODE (\r
     {\r
@@ -2008,15 +1913,12 @@ BiosKeyboardTimerHandler (
   //\r
   // Clear left alt and left ctrl BDA flag\r
   //\r
-  KbFlag2 &= ~(KB_LEFT_ALT_PRESSED | KB_LEFT_CTRL_PRESSED);\r
-  *((UINT8 *) (UINTN) 0x418) = KbFlag2;\r
-  KbFlag1 &= ~0x0C;                      \r
-  *((UINT8 *) (UINTN) 0x417) = KbFlag1; \r
-\r
-  //\r
-  // Restore NULL pointer detection\r
-  //\r
-  EnableNullDetection ();\r
+  ACCESS_PAGE0_CODE (\r
+    KbFlag2 &= ~(KB_LEFT_ALT_PRESSED | KB_LEFT_CTRL_PRESSED);\r
+    *((UINT8 *) (UINTN) 0x418) = KbFlag2;\r
+    KbFlag1 &= ~0x0C;\r
+    *((UINT8 *) (UINTN) 0x417) = KbFlag1;\r
+  );\r
   \r
   //\r
   // Output EFI input key and shift/toggle state\r
index 596f4ced44caa4c465704d3165fe16d85951e07c..eaaedbfa9c538a20c8d641efcfa965ecbc820a6b 100644 (file)
@@ -74,7 +74,6 @@
 \r
 [Pcd]\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdFastPS2Detection                  ## SOMETIMES_CONSUMES\r
-  gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask  ## CONSUMES\r
 \r
 [UserExtensions.TianoCore."ExtraFiles"]\r
   KeyboardDxeExtra.uni\r