]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBios.c
EmbeddedPkg: Removing ipf which is no longer supported from edk2.
[mirror_edk2.git] / IntelFrameworkModulePkg / Csm / LegacyBiosDxe / LegacyBios.c
index e009999fbd922450e29505e96bd1142faf2f2e38..8f14687b28335988844407e9e5fb3dd10afa80d0 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2018, 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\r
@@ -43,10 +43,10 @@ UINTN                 mStructureTablePages     = 0;
 BOOLEAN               mEndOfDxe                = FALSE;\r
 \r
 /**\r
-  Do an AllocatePages () of type AllocateMaxAddress for EfiBootServicesCode\r
-  memory.\r
+  Allocate memory for legacy usage.\r
 \r
-  @param  AllocateType               Allocated Legacy Memory Type\r
+  @param  AllocateType               The type of allocation to perform.\r
+  @param  MemoryType                 The type of memory to allocate.\r
   @param  StartPageAddress           Start address of range\r
   @param  Pages                      Number of pages to allocate\r
   @param  Result                     Result of allocation\r
@@ -58,6 +58,7 @@ BOOLEAN               mEndOfDxe                = FALSE;
 EFI_STATUS\r
 AllocateLegacyMemory (\r
   IN  EFI_ALLOCATE_TYPE         AllocateType,\r
+  IN  EFI_MEMORY_TYPE           MemoryType,\r
   IN  EFI_PHYSICAL_ADDRESS      StartPageAddress,\r
   IN  UINTN                     Pages,\r
   OUT EFI_PHYSICAL_ADDRESS      *Result\r
@@ -72,7 +73,7 @@ AllocateLegacyMemory (
   MemPage = (EFI_PHYSICAL_ADDRESS) (UINTN) StartPageAddress;\r
   Status = gBS->AllocatePages (\r
                   AllocateType,\r
-                  EfiBootServicesCode,\r
+                  MemoryType,\r
                   Pages,\r
                   &MemPage\r
                   );\r
@@ -270,7 +271,7 @@ ShadowAndStartLegacy16 (
     if (EFI_ERROR (Status)) {\r
       //\r
       // Bugbug: need to figure out whether C/D/E/F segment should be marked as reserved memory.\r
-      // \r
+      //\r
       DEBUG ((DEBUG_ERROR, "Failed to allocate the C/D/E/F segment Status = %r", Status));\r
     }\r
   }\r
@@ -414,7 +415,7 @@ ShadowAndStartLegacy16 (
   Private->Legacy8259->GetMask(Private->Legacy8259, &OldMask, NULL, NULL, NULL);\r
   NewMask = 0xFFFF;\r
   Private->Legacy8259->SetMask(Private->Legacy8259, &NewMask, NULL, NULL, NULL);\r
-  \r
+\r
   //\r
   // Call into Legacy16 code to do an INIT\r
   //\r
@@ -436,7 +437,7 @@ ShadowAndStartLegacy16 (
   // Restore original legacy interrupt mask value\r
   //\r
   Private->Legacy8259->SetMask(Private->Legacy8259, &OldMask, NULL, NULL, NULL);\r
-  \r
+\r
   if (Regs.X.AX != 0) {\r
     return EFI_DEVICE_ERROR;\r
   }\r
@@ -652,7 +653,7 @@ GetPciInterfaceVersion (
   UINT16                PciInterfaceVersion;\r
 \r
   PciInterfaceVersion = 0;\r
-  \r
+\r
   Reg.X.AX = 0xB101;\r
   Reg.E.EDI = 0;\r
 \r
@@ -692,7 +693,7 @@ InstallSmbiosEventCallback (
 {\r
   EFI_STATUS                  Status;\r
   SMBIOS_TABLE_ENTRY_POINT    *EntryPointStructure;\r
-  \r
+\r
   //\r
   // Get SMBIOS table from EFI configuration table\r
   //\r
@@ -703,7 +704,7 @@ InstallSmbiosEventCallback (
   if ((EFI_ERROR (Status)) || (mRuntimeSmbiosEntryPoint == NULL)) {\r
     return;\r
   }\r
-  \r
+\r
   EntryPointStructure = (SMBIOS_TABLE_ENTRY_POINT *) mRuntimeSmbiosEntryPoint;\r
 \r
   //\r
@@ -727,8 +728,8 @@ InstallSmbiosEventCallback (
     }\r
     DEBUG ((EFI_D_INFO, "Allocate memory for Smbios Entry Point Structure\n"));\r
   }\r
-  \r
-  if ((mStructureTableAddress != 0) && \r
+\r
+  if ((mStructureTableAddress != 0) &&\r
       (mStructureTablePages < EFI_SIZE_TO_PAGES ((UINT32)EntryPointStructure->TableLength))) {\r
     //\r
     // If original buffer is not enough for the new SMBIOS table, free original buffer and re-allocate\r
@@ -738,7 +739,7 @@ InstallSmbiosEventCallback (
     mStructureTablePages   = 0;\r
     DEBUG ((EFI_D_INFO, "Original size is not enough. Re-allocate the memory.\n"));\r
   }\r
-  \r
+\r
   if (mStructureTableAddress == 0) {\r
     //\r
     // Allocate reserved memory below 4GB.\r
@@ -754,7 +755,7 @@ InstallSmbiosEventCallback (
                     );\r
     if (EFI_ERROR (Status)) {\r
       gBS->FreePages (\r
-        mReserveSmbiosEntryPoint, \r
+        mReserveSmbiosEntryPoint,\r
         EFI_SIZE_TO_PAGES ((UINTN) (EntryPointStructure->EntryPointLength))\r
         );\r
       mReserveSmbiosEntryPoint = 0;\r
@@ -786,115 +787,6 @@ ToggleEndOfDxeStatus (
   return;\r
 }\r
 \r
-//\r
-// Legacy BIOS needs to access memory between 0-4095, which will cause page\r
-// fault exception if NULL pointer detection mechanism is enabled. Following\r
-// functions can be used to disable/enable NULL pointer detection before/after\r
-// accessing those memory.\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
-      ||\r
-      ((mEndOfDxe == TRUE)  &&\r
-       ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & (BIT7|BIT0))\r
-        == (BIT7|BIT0)))\r
-     ) {\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
-   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
-      ||\r
-      ((mEndOfDxe == TRUE)  &&\r
-       ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & (BIT7|BIT0))\r
-        == (BIT7|BIT0)))\r
-     ) {\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
   Install Driver to produce Legacy BIOS protocol.\r
 \r
@@ -951,7 +843,7 @@ LegacyBiosInstall (
     FreePool (SecureBoot);\r
     return EFI_SECURITY_VIOLATION;\r
   }\r
-  \r
+\r
   if (SecureBoot != NULL) {\r
     FreePool (SecureBoot);\r
   }\r
@@ -1083,6 +975,7 @@ LegacyBiosInstall (
   //\r
   AllocateLegacyMemory (\r
     AllocateAddress,\r
+    EfiReservedMemoryType,\r
     0,\r
     1,\r
     &MemoryAddress\r
@@ -1095,10 +988,10 @@ LegacyBiosInstall (
   // Initialize region from 0x0000 to 4k. This initializes interrupt vector\r
   // range.\r
   //\r
-  DisableNullDetection ();\r
-  gBS->SetMem ((VOID *) ClearPtr, 0x400, INITIAL_VALUE_BELOW_1K);\r
-  ZeroMem ((VOID *) ((UINTN)ClearPtr + 0x400), 0xC00);\r
-  EnableNullDetection ();\r
+  ACCESS_PAGE0_CODE (\r
+    gBS->SetMem ((VOID *) ClearPtr, 0x400, INITIAL_VALUE_BELOW_1K);\r
+    ZeroMem ((VOID *) ((UINTN)ClearPtr + 0x400), 0xC00);\r
+  );\r
 \r
   //\r
   // Allocate pages for OPROM usage\r
@@ -1108,6 +1001,7 @@ LegacyBiosInstall (
 \r
   Status = AllocateLegacyMemory (\r
              AllocateAddress,\r
+             EfiReservedMemoryType,\r
              CONVENTIONAL_MEMORY_TOP - MemorySize,\r
              EFI_SIZE_TO_PAGES (MemorySize),\r
              &MemoryAddress\r
@@ -1136,6 +1030,7 @@ LegacyBiosInstall (
   for (MemStart = MemoryAddress; MemStart < MemoryAddress + MemorySize; MemStart += 0x1000) {\r
     Status = AllocateLegacyMemory (\r
                AllocateAddress,\r
+               EfiBootServicesCode,\r
                MemStart,\r
                1,\r
                &StartAddress\r
@@ -1152,9 +1047,10 @@ LegacyBiosInstall (
   // Allocate low PMM memory and zero it out\r
   //\r
   MemorySize = PcdGet32 (PcdLowPmmMemorySize);\r
-  ASSERT ((MemorySize & 0xFFF) == 0);  \r
+  ASSERT ((MemorySize & 0xFFF) == 0);\r
   Status = AllocateLegacyMemory (\r
              AllocateMaxAddress,\r
+             EfiBootServicesCode,\r
              CONVENTIONAL_MEMORY_TOP,\r
              EFI_SIZE_TO_PAGES (MemorySize),\r
              &MemoryAddressUnder1MB\r
@@ -1168,6 +1064,7 @@ LegacyBiosInstall (
   //\r
   Status = AllocateLegacyMemory (\r
              AllocateMaxAddress,\r
+             EfiReservedMemoryType,\r
              CONVENTIONAL_MEMORY_TOP,\r
              (sizeof (LOW_MEMORY_THUNK) / EFI_PAGE_SIZE) + 2,\r
              &MemoryAddress\r
@@ -1192,9 +1089,10 @@ LegacyBiosInstall (
   ASSERT ((MemorySize & 0xFFF) == 0);\r
   //\r
   // Allocate high PMM Memory under 16 MB\r
-  //   \r
+  //\r
   Status = AllocateLegacyMemory (\r
              AllocateMaxAddress,\r
+             EfiBootServicesCode,\r
              0x1000000,\r
              EFI_SIZE_TO_PAGES (MemorySize),\r
              &MemoryAddress\r
@@ -1202,18 +1100,19 @@ LegacyBiosInstall (
   if (EFI_ERROR (Status)) {\r
     //\r
     // If it fails, allocate high PMM Memory under 4GB\r
-    //   \r
+    //\r
     Status = AllocateLegacyMemory (\r
                AllocateMaxAddress,\r
+               EfiBootServicesCode,\r
                0xFFFFFFFF,\r
                EFI_SIZE_TO_PAGES (MemorySize),\r
                &MemoryAddress\r
-               );    \r
+               );\r
   }\r
   if (!EFI_ERROR (Status)) {\r
     EfiToLegacy16InitTable->HiPmmMemory            = (UINT32) (EFI_PHYSICAL_ADDRESS) (UINTN) MemoryAddress;\r
     EfiToLegacy16InitTable->HiPmmMemorySizeInBytes = MemorySize;\r
-  } \r
+  }\r
 \r
   //\r
   //  ShutdownAPs();\r
@@ -1237,22 +1136,20 @@ LegacyBiosInstall (
   //\r
   // Save Unexpected interrupt vector so can restore it just prior to boot\r
   //\r
-  DisableNullDetection ();\r
-\r
-  BaseVectorMaster = (UINT32 *) (sizeof (UINT32) * PROTECTED_MODE_BASE_VECTOR_MASTER);\r
-  Private->BiosUnexpectedInt = BaseVectorMaster[0];\r
-  IntRedirCode = (UINT32) (UINTN) Private->IntThunk->InterruptRedirectionCode;\r
-  for (Index = 0; Index < 8; Index++) {\r
-    BaseVectorMaster[Index] = (EFI_SEGMENT (IntRedirCode + Index * 4) << 16) | EFI_OFFSET (IntRedirCode + Index * 4);\r
-  }\r
-\r
-  EnableNullDetection ();\r
+  ACCESS_PAGE0_CODE (\r
+    BaseVectorMaster = (UINT32 *) (sizeof (UINT32) * PROTECTED_MODE_BASE_VECTOR_MASTER);\r
+    Private->BiosUnexpectedInt = BaseVectorMaster[0];\r
+    IntRedirCode = (UINT32) (UINTN) Private->IntThunk->InterruptRedirectionCode;\r
+    for (Index = 0; Index < 8; Index++) {\r
+      BaseVectorMaster[Index] = (EFI_SEGMENT (IntRedirCode + Index * 4) << 16) | EFI_OFFSET (IntRedirCode + Index * 4);\r
+    }\r
+  );\r
 \r
   //\r
   // Save EFI value\r
   //\r
   Private->ThunkSeg = (UINT16) (EFI_SEGMENT (IntRedirCode));\r
-  \r
+\r
   //\r
   // Allocate reserved memory for SMBIOS table used in legacy boot if SMBIOS table exists\r
   //\r
@@ -1269,7 +1166,7 @@ LegacyBiosInstall (
                   &gEfiSmbiosTableGuid,\r
                   &InstallSmbiosEvent\r
                   );\r
-  ASSERT_EFI_ERROR (Status);  \r
+  ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
   // Create callback to update status of EndOfDxe, which is needed by NULL\r
@@ -1296,9 +1193,9 @@ LegacyBiosInstall (
                   &Private->LegacyBios\r
                   );\r
   Private->Csm16PciInterfaceVersion = GetPciInterfaceVersion (Private);\r
-  \r
-  DEBUG ((EFI_D_INFO, "CSM16 PCI BIOS Interface Version: %02x.%02x\n", \r
-          (UINT8) (Private->Csm16PciInterfaceVersion >> 8), \r
+\r
+  DEBUG ((EFI_D_INFO, "CSM16 PCI BIOS Interface Version: %02x.%02x\n",\r
+          (UINT8) (Private->Csm16PciInterfaceVersion >> 8),\r
           (UINT8) Private->Csm16PciInterfaceVersion\r
         ));\r
   ASSERT (Private->Csm16PciInterfaceVersion != 0);\r