]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBios.c
Change the PcdSrIovSystemPageSize from type of [PcdFixedAtBuild] to [PcdFixedAtBuild...
[mirror_edk2.git] / IntelFrameworkModulePkg / Csm / LegacyBiosDxe / LegacyBios.c
index 75add5e39ded6f9712569fc35d54fb8aa1afd7f5..99a76c9f21acdd7b12f340621615c91122af8104 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2012, 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
@@ -29,11 +29,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 //\r
 LEGACY_BIOS_INSTANCE  mPrivateData;\r
 \r
-//\r
-// The end of OPROM shadow address\r
-//\r
-UINTN                 mEndOpromShadowAddress = 0;\r
-\r
 /**\r
   Do an AllocatePages () of type AllocateMaxAddress for EfiBootServicesCode\r
   memory.\r
@@ -387,23 +382,6 @@ ShadowAndStartLegacy16 (
   //\r
   Table->EfiSystemTable = (UINT32) (UINTN) gST;\r
 \r
-  //\r
-  // Get the end of OPROM shadow address\r
-  //\r
-  Status = Private->LegacyBiosPlatform->GetPlatformInfo (\r
-                                          Private->LegacyBiosPlatform,\r
-                                          EfiGetPlatformEndOpromShadowAddr,\r
-                                          NULL,\r
-                                          NULL,\r
-                                          &mEndOpromShadowAddress,\r
-                                          NULL,\r
-                                          0,\r
-                                          0\r
-                                          );\r
-  if (EFI_ERROR (Status)) {\r
-    mEndOpromShadowAddress = 0xDFFFF;\r
-  }\r
-\r
   //\r
   // IPF CSM integration -Bug\r
   //\r
@@ -704,6 +682,7 @@ LegacyBiosInstall (
   LEGACY_BIOS_INSTANCE               *Private;\r
   EFI_TO_COMPATIBILITY16_INIT_TABLE  *EfiToLegacy16InitTable;\r
   EFI_PHYSICAL_ADDRESS               MemoryAddress;\r
+  EFI_PHYSICAL_ADDRESS               EbdaReservedBaseAddress;\r
   VOID                               *MemoryPtr;\r
   EFI_PHYSICAL_ADDRESS               MemoryAddressUnder1MB;\r
   UINTN                              Index;\r
@@ -717,6 +696,7 @@ LegacyBiosInstall (
   UINT32                             MemorySize;\r
   EFI_GCD_MEMORY_SPACE_DESCRIPTOR    Descriptor;\r
   UINT64                             Length;\r
+  UINT8                              *SecureBoot;\r
 \r
   //\r
   // Load this driver's image to memory\r
@@ -726,6 +706,20 @@ LegacyBiosInstall (
     return Status;\r
   }\r
 \r
+  //\r
+  // When UEFI Secure Boot is enabled, CSM module will not start any more.\r
+  //\r
+  SecureBoot = NULL;\r
+  GetEfiGlobalVariable2 (EFI_SECURE_BOOT_MODE_NAME, (VOID**)&SecureBoot, NULL);\r
+  if ((SecureBoot != NULL) && (*SecureBoot == SECURE_BOOT_MODE_ENABLE)) {\r
+    FreePool (SecureBoot);\r
+    return EFI_SECURITY_VIOLATION;\r
+  }\r
+  \r
+  if (SecureBoot != NULL) {\r
+    FreePool (SecureBoot);\r
+  }\r
+\r
   Private = &mPrivateData;\r
   ZeroMem (Private, sizeof (LEGACY_BIOS_INSTANCE));\r
 \r
@@ -736,6 +730,9 @@ LegacyBiosInstall (
   Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **) &Private->Cpu);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  Status = gBS->LocateProtocol (&gEfiTimerArchProtocolGuid, NULL, (VOID **) &Private->Timer);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   Status = gBS->LocateProtocol (&gEfiLegacyRegion2ProtocolGuid, NULL, (VOID **) &Private->LegacyRegion);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
@@ -884,9 +881,21 @@ LegacyBiosInstall (
   //\r
   // Allocate all 32k chunks from 0x60000 ~ 0x88000 for Legacy OPROMs that\r
   // don't use PMM but look for zeroed memory. Note that various non-BBS\r
-  // SCSIs expect different areas to be free\r
+  // OpROMs expect different areas to be free\r
+  //\r
+  EbdaReservedBaseAddress = MemoryAddress;\r
+  MemoryAddress = PcdGet32 (PcdOpromReservedMemoryBase);\r
+  MemorySize    = PcdGet32 (PcdOpromReservedMemorySize);\r
   //\r
-  for (MemStart = 0x60000; MemStart < 0x88000; MemStart += 0x1000) {\r
+  // Check if base address and size for reserved memory are 4KB aligned.\r
+  //\r
+  ASSERT ((MemoryAddress & 0xFFF) == 0);\r
+  ASSERT ((MemorySize & 0xFFF) == 0);\r
+  //\r
+  // Check if the reserved memory is below EBDA reserved range.\r
+  //\r
+  ASSERT ((MemoryAddress < EbdaReservedBaseAddress) && ((MemoryAddress + MemorySize - 1) < EbdaReservedBaseAddress));\r
+  for (MemStart = MemoryAddress; MemStart < MemoryAddress + MemorySize; MemStart += 0x1000) {\r
     Status = AllocateLegacyMemory (\r
                AllocateAddress,\r
                MemStart,\r
@@ -902,17 +911,19 @@ LegacyBiosInstall (
   }\r
 \r
   //\r
-  // Allocate a 64k area (16 4k pages) for 16-bit code for scratch pad and zero it out\r
+  // Allocate low PMM memory and zero it out\r
   //\r
+  MemorySize = PcdGet32 (PcdLowPmmMemorySize);\r
+  ASSERT ((MemorySize & 0xFFF) == 0);  \r
   Status = AllocateLegacyMemory (\r
              AllocateMaxAddress,\r
              CONVENTIONAL_MEMORY_TOP,\r
-             16,\r
+             EFI_SIZE_TO_PAGES (MemorySize),\r
              &MemoryAddressUnder1MB\r
              );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  ZeroMem ((VOID *) ((UINTN) MemoryAddressUnder1MB), 0x10000);\r
+  ZeroMem ((VOID *) ((UINTN) MemoryAddressUnder1MB), MemorySize);\r
 \r
   //\r
   // Allocate space for thunker and Init Thunker\r
@@ -937,21 +948,34 @@ LegacyBiosInstall (
   //\r
   EfiToLegacy16InitTable->BiosLessThan1MB         = (UINT32) MemoryAddressUnder1MB;\r
   EfiToLegacy16InitTable->LowPmmMemory            = (UINT32) MemoryAddressUnder1MB;\r
-  EfiToLegacy16InitTable->LowPmmMemorySizeInBytes = 0x10000;\r
+  EfiToLegacy16InitTable->LowPmmMemorySizeInBytes = MemorySize;\r
 \r
+  MemorySize = PcdGet32 (PcdHighPmmMemorySize);\r
+  ASSERT ((MemorySize & 0xFFF) == 0);\r
   //\r
-  // Allocate 4 MB of PMM Memory under 16 MB\r
-  //\r
+  // Allocate high PMM Memory under 16 MB\r
+  //   \r
   Status = AllocateLegacyMemory (\r
              AllocateMaxAddress,\r
              0x1000000,\r
-             0x400,\r
+             EFI_SIZE_TO_PAGES (MemorySize),\r
              &MemoryAddress\r
              );\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // If it fails, allocate high PMM Memory under 4GB\r
+    //   \r
+    Status = AllocateLegacyMemory (\r
+               AllocateMaxAddress,\r
+               0xFFFFFFFF,\r
+               EFI_SIZE_TO_PAGES (MemorySize),\r
+               &MemoryAddress\r
+               );    \r
+  }\r
   if (!EFI_ERROR (Status)) {\r
     EfiToLegacy16InitTable->HiPmmMemory            = (UINT32) (EFI_PHYSICAL_ADDRESS) (UINTN) MemoryAddress;\r
-    EfiToLegacy16InitTable->HiPmmMemorySizeInBytes = PMM_MEMORY_SIZE;\r
-  }\r
+    EfiToLegacy16InitTable->HiPmmMemorySizeInBytes = MemorySize;\r
+  } \r
 \r
   //\r
   //  ShutdownAPs();\r