/** @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
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
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
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
//\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
+ // 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
- for (MemStart = 0x60000; MemStart < 0x88000; MemStart += 0x1000) {\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
EfiToLegacy16InitTable->LowPmmMemory = (UINT32) MemoryAddressUnder1MB;\r
EfiToLegacy16InitTable->LowPmmMemorySizeInBytes = MemorySize;\r
\r
+ MemorySize = PcdGet32 (PcdHighPmmMemorySize);\r
+ ASSERT ((MemorySize & 0xFFF) == 0);\r
//\r
// Allocate high PMM Memory under 16 MB\r
- //\r
- MemorySize = PcdGet32 (PcdHighPmmMemorySize);\r
- ASSERT ((MemorySize & 0xFFF) == 0); \r
+ // \r
Status = AllocateLegacyMemory (\r
AllocateMaxAddress,\r
0x1000000,\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 = MemorySize;\r
- }\r
+ } \r
\r
//\r
// ShutdownAPs();\r