]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBios.c
IntelFrameworkModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / IntelFrameworkModulePkg / Csm / LegacyBiosDxe / LegacyBios.c
index 9466e3e4ddd5eef1ab021e123f6095fcc8486f69..05e3ffd2bbb86a9bbc7162a1c9bf48364941ffa2 100644 (file)
@@ -2,14 +2,7 @@
 \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
-of the BSD License which accompanies this distribution.  The\r
-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
@@ -43,7 +36,7 @@ UINTN                 mStructureTablePages     = 0;
 BOOLEAN               mEndOfDxe                = FALSE;\r
 \r
 /**\r
-  Allocate memory for legacy usage.\r
+  Allocate memory for legacy usage. The memory is executable.\r
 \r
   @param  AllocateType               The type of allocation to perform.\r
   @param  MemoryType                 The type of memory to allocate.\r
@@ -51,8 +44,8 @@ BOOLEAN               mEndOfDxe                = FALSE;
   @param  Pages                      Number of pages to allocate\r
   @param  Result                     Result of allocation\r
 \r
-  @retval EFI_SUCCESS                Legacy16 code loaded\r
-  @retval Other                      No protocol installed, unload driver.\r
+  @retval EFI_SUCCESS                Legacy memory is allocated successfully.\r
+  @retval Other                      Legacy memory is not allocated.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -64,8 +57,9 @@ AllocateLegacyMemory (
   OUT EFI_PHYSICAL_ADDRESS      *Result\r
   )\r
 {\r
-  EFI_STATUS            Status;\r
-  EFI_PHYSICAL_ADDRESS  MemPage;\r
+  EFI_STATUS                      Status;\r
+  EFI_PHYSICAL_ADDRESS            MemPage;\r
+  EFI_GCD_MEMORY_SPACE_DESCRIPTOR MemDesc;\r
 \r
   //\r
   // Allocate Pages of memory less <= StartPageAddress\r
@@ -81,12 +75,29 @@ AllocateLegacyMemory (
   // Do not ASSERT on Status error but let caller decide since some cases\r
   // memory is already taken but that is ok.\r
   //\r
+  if (!EFI_ERROR (Status)) {\r
+    if (MemoryType != EfiBootServicesCode) {\r
+      //\r
+      // Make sure that the buffer can be used to store code.\r
+      //\r
+      Status = gDS->GetMemorySpaceDescriptor (MemPage, &MemDesc);\r
+      if (!EFI_ERROR (Status) && (MemDesc.Attributes & EFI_MEMORY_XP) != 0) {\r
+        Status = gDS->SetMemorySpaceAttributes (\r
+                        MemPage,\r
+                        EFI_PAGES_TO_SIZE (Pages),\r
+                        MemDesc.Attributes & (~EFI_MEMORY_XP)\r
+                        );\r
+      }\r
+      if (EFI_ERROR (Status)) {\r
+        gBS->FreePages (MemPage, Pages);\r
+      }\r
+    }\r
+  }\r
+\r
   if (!EFI_ERROR (Status)) {\r
     *Result = (EFI_PHYSICAL_ADDRESS) (UINTN) MemPage;\r
   }\r
-  //\r
-  // If reach here the status = EFI_SUCCESS\r
-  //\r
+\r
   return Status;\r
 }\r
 \r
@@ -271,7 +282,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
@@ -415,7 +426,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
@@ -437,7 +448,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
@@ -653,7 +664,7 @@ GetPciInterfaceVersion (
   UINT16                PciInterfaceVersion;\r
 \r
   PciInterfaceVersion = 0;\r
-  \r
+\r
   Reg.X.AX = 0xB101;\r
   Reg.E.EDI = 0;\r
 \r
@@ -693,7 +704,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
@@ -704,7 +715,7 @@ InstallSmbiosEventCallback (
   if ((EFI_ERROR (Status)) || (mRuntimeSmbiosEntryPoint == NULL)) {\r
     return;\r
   }\r
-  \r
+\r
   EntryPointStructure = (SMBIOS_TABLE_ENTRY_POINT *) mRuntimeSmbiosEntryPoint;\r
 \r
   //\r
@@ -728,8 +739,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
@@ -739,7 +750,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
@@ -755,7 +766,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
@@ -843,7 +854,7 @@ LegacyBiosInstall (
     FreePool (SecureBoot);\r
     return EFI_SECURITY_VIOLATION;\r
   }\r
-  \r
+\r
   if (SecureBoot != NULL) {\r
     FreePool (SecureBoot);\r
   }\r
@@ -1047,7 +1058,7 @@ 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
@@ -1089,7 +1100,7 @@ LegacyBiosInstall (
   ASSERT ((MemorySize & 0xFFF) == 0);\r
   //\r
   // Allocate high PMM Memory under 16 MB\r
-  //   \r
+  //\r
   Status = AllocateLegacyMemory (\r
              AllocateMaxAddress,\r
              EfiBootServicesCode,\r
@@ -1100,19 +1111,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
@@ -1149,7 +1160,7 @@ LegacyBiosInstall (
   // 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
@@ -1166,7 +1177,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
@@ -1193,9 +1204,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