2009-05-27 23:10:18 +02:00
|
|
|
/**@file
|
|
|
|
Platform PEI driver
|
|
|
|
|
2010-04-28 14:43:04 +02:00
|
|
|
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
|
|
|
|
This program and the accompanying materials
|
2009-05-27 23:10:18 +02:00
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
//
|
|
|
|
// The package level header files this module uses
|
|
|
|
//
|
|
|
|
#include <PiPei.h>
|
|
|
|
|
|
|
|
//
|
|
|
|
// The Library classes this module consumes
|
|
|
|
//
|
|
|
|
#include <Library/DebugLib.h>
|
|
|
|
#include <Library/HobLib.h>
|
|
|
|
#include <Library/IoLib.h>
|
2009-09-07 22:18:17 +02:00
|
|
|
#include <Library/MemoryAllocationLib.h>
|
|
|
|
#include <Library/PcdLib.h>
|
2009-05-27 23:10:18 +02:00
|
|
|
#include <Library/PciLib.h>
|
|
|
|
#include <Library/PeimEntryPoint.h>
|
2011-03-22 02:55:08 +01:00
|
|
|
#include <Library/PeiServicesLib.h>
|
2009-05-27 23:10:18 +02:00
|
|
|
#include <Library/ResourcePublicationLib.h>
|
|
|
|
#include <Guid/MemoryTypeInformation.h>
|
2011-03-22 02:55:08 +01:00
|
|
|
#include <Ppi/MasterBootMode.h>
|
2009-05-27 23:10:18 +02:00
|
|
|
|
|
|
|
#include "Platform.h"
|
2011-01-21 17:50:31 +01:00
|
|
|
#include "Cmos.h"
|
2009-05-27 23:10:18 +02:00
|
|
|
|
|
|
|
EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] = {
|
|
|
|
{ EfiACPIMemoryNVS, 0x004 },
|
2010-07-16 21:04:41 +02:00
|
|
|
{ EfiACPIReclaimMemory, 0x008 },
|
2010-10-13 09:07:29 +02:00
|
|
|
{ EfiReservedMemoryType, 0x004 },
|
2010-07-16 21:04:41 +02:00
|
|
|
{ EfiRuntimeServicesData, 0x024 },
|
|
|
|
{ EfiRuntimeServicesCode, 0x030 },
|
|
|
|
{ EfiBootServicesCode, 0x180 },
|
|
|
|
{ EfiBootServicesData, 0xF00 },
|
2009-05-27 23:10:18 +02:00
|
|
|
{ EfiMaxMemoryType, 0x000 }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-03-22 02:55:08 +01:00
|
|
|
EFI_PEI_PPI_DESCRIPTOR mPpiBootMode[] = {
|
|
|
|
{
|
|
|
|
EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
|
|
|
|
&gEfiPeiMasterBootModePpiGuid,
|
|
|
|
NULL
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-05-27 23:10:18 +02:00
|
|
|
VOID
|
|
|
|
AddIoMemoryBaseSizeHob (
|
|
|
|
EFI_PHYSICAL_ADDRESS MemoryBase,
|
|
|
|
UINT64 MemorySize
|
|
|
|
)
|
|
|
|
{
|
2010-07-16 21:04:41 +02:00
|
|
|
BuildResourceDescriptorHob (
|
|
|
|
EFI_RESOURCE_MEMORY_MAPPED_IO,
|
2009-05-27 23:10:18 +02:00
|
|
|
EFI_RESOURCE_ATTRIBUTE_PRESENT |
|
|
|
|
EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
|
|
|
|
EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
|
2010-07-16 21:04:41 +02:00
|
|
|
EFI_RESOURCE_ATTRIBUTE_TESTED,
|
2009-05-27 23:10:18 +02:00
|
|
|
MemoryBase,
|
|
|
|
MemorySize
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VOID
|
|
|
|
AddIoMemoryRangeHob (
|
|
|
|
EFI_PHYSICAL_ADDRESS MemoryBase,
|
|
|
|
EFI_PHYSICAL_ADDRESS MemoryLimit
|
|
|
|
)
|
|
|
|
{
|
|
|
|
AddIoMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit - MemoryBase));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VOID
|
|
|
|
AddMemoryBaseSizeHob (
|
|
|
|
EFI_PHYSICAL_ADDRESS MemoryBase,
|
|
|
|
UINT64 MemorySize
|
|
|
|
)
|
|
|
|
{
|
2010-07-16 21:04:41 +02:00
|
|
|
BuildResourceDescriptorHob (
|
|
|
|
EFI_RESOURCE_SYSTEM_MEMORY,
|
2009-05-27 23:10:18 +02:00
|
|
|
EFI_RESOURCE_ATTRIBUTE_PRESENT |
|
|
|
|
EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
|
|
|
|
EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
|
|
|
|
EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
|
|
|
|
EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
|
|
|
|
EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
|
2010-07-16 21:04:41 +02:00
|
|
|
EFI_RESOURCE_ATTRIBUTE_TESTED,
|
2009-05-27 23:10:18 +02:00
|
|
|
MemoryBase,
|
|
|
|
MemorySize
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VOID
|
|
|
|
AddMemoryRangeHob (
|
|
|
|
EFI_PHYSICAL_ADDRESS MemoryBase,
|
|
|
|
EFI_PHYSICAL_ADDRESS MemoryLimit
|
|
|
|
)
|
|
|
|
{
|
|
|
|
AddMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit - MemoryBase));
|
|
|
|
}
|
|
|
|
|
2011-01-21 17:51:00 +01:00
|
|
|
|
|
|
|
VOID
|
|
|
|
AddUntestedMemoryBaseSizeHob (
|
|
|
|
EFI_PHYSICAL_ADDRESS MemoryBase,
|
|
|
|
UINT64 MemorySize
|
|
|
|
)
|
|
|
|
{
|
|
|
|
BuildResourceDescriptorHob (
|
|
|
|
EFI_RESOURCE_SYSTEM_MEMORY,
|
|
|
|
EFI_RESOURCE_ATTRIBUTE_PRESENT |
|
|
|
|
EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
|
|
|
|
EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
|
|
|
|
EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
|
|
|
|
EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
|
|
|
|
EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE,
|
|
|
|
MemoryBase,
|
|
|
|
MemorySize
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VOID
|
|
|
|
AddUntestedMemoryRangeHob (
|
|
|
|
EFI_PHYSICAL_ADDRESS MemoryBase,
|
|
|
|
EFI_PHYSICAL_ADDRESS MemoryLimit
|
|
|
|
)
|
|
|
|
{
|
|
|
|
AddUntestedMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit - MemoryBase));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-27 23:10:18 +02:00
|
|
|
VOID
|
|
|
|
MemMapInitialization (
|
2010-10-13 09:07:29 +02:00
|
|
|
EFI_PHYSICAL_ADDRESS TopOfMemory
|
2009-05-27 23:10:18 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Create Memory Type Information HOB
|
|
|
|
//
|
|
|
|
BuildGuidDataHob (
|
|
|
|
&gEfiMemoryTypeInformationGuid,
|
|
|
|
mDefaultMemoryTypeInformation,
|
|
|
|
sizeof(mDefaultMemoryTypeInformation)
|
|
|
|
);
|
|
|
|
|
2010-07-16 21:04:41 +02:00
|
|
|
//
|
|
|
|
// Add PCI IO Port space available for PCI resource allocations.
|
|
|
|
//
|
|
|
|
BuildResourceDescriptorHob (
|
|
|
|
EFI_RESOURCE_IO,
|
|
|
|
EFI_RESOURCE_ATTRIBUTE_PRESENT |
|
|
|
|
EFI_RESOURCE_ATTRIBUTE_INITIALIZED,
|
|
|
|
0x1000,
|
|
|
|
0xF000
|
|
|
|
);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Add PCI MMIO space available to PCI resource allocations
|
|
|
|
//
|
2010-10-13 09:07:29 +02:00
|
|
|
if (TopOfMemory < BASE_2GB) {
|
|
|
|
AddIoMemoryBaseSizeHob (BASE_2GB, 0xFEC00000 - BASE_2GB);
|
|
|
|
} else {
|
|
|
|
AddIoMemoryBaseSizeHob (TopOfMemory, 0xFEC00000 - TopOfMemory);
|
|
|
|
}
|
2010-07-16 21:04:41 +02:00
|
|
|
|
2009-05-27 23:10:18 +02:00
|
|
|
//
|
|
|
|
// Local APIC range
|
|
|
|
//
|
2010-10-13 09:07:29 +02:00
|
|
|
AddIoMemoryBaseSizeHob (0xFEC80000, SIZE_512KB);
|
2009-05-27 23:10:18 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// I/O APIC range
|
|
|
|
//
|
2010-10-13 09:07:29 +02:00
|
|
|
AddIoMemoryBaseSizeHob (0xFEC00000, SIZE_512KB);
|
2009-05-27 23:10:18 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Video memory + Legacy BIOS region
|
|
|
|
//
|
2010-10-13 09:07:29 +02:00
|
|
|
AddIoMemoryRangeHob (0x0A0000, BASE_1MB);
|
2009-05-27 23:10:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VOID
|
|
|
|
MiscInitialization (
|
|
|
|
)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Disable A20 Mask
|
|
|
|
//
|
2010-10-13 09:07:29 +02:00
|
|
|
IoOr8 (0x92, BIT1);
|
2009-05-27 23:10:18 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Build the CPU hob with 36-bit addressing and 16-bits of IO space.
|
|
|
|
//
|
|
|
|
BuildCpuHob (36, 16);
|
2011-01-13 06:46:24 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Set the PM I/O base address to 0x400
|
|
|
|
//
|
|
|
|
PciAndThenOr32 (PCI_LIB_ADDRESS (0, 1, 3, 0x40), (UINT32) ~0xfc0, 0x400);
|
2009-05-27 23:10:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-22 02:55:08 +01:00
|
|
|
VOID
|
|
|
|
BootModeInitialization (
|
|
|
|
)
|
|
|
|
{
|
2011-03-22 05:54:18 +01:00
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
Status = PeiServicesSetBootMode (BOOT_WITH_FULL_CONFIGURATION);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
Status = PeiServicesInstallPpi (mPpiBootMode);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
2011-03-22 02:55:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-07 22:18:17 +02:00
|
|
|
VOID
|
|
|
|
ReserveEmuVariableNvStore (
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_PHYSICAL_ADDRESS VariableStore;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Allocate storage for NV variables early on so it will be
|
|
|
|
// at a consistent address. Since VM memory is preserved
|
|
|
|
// across reboots, this allows the NV variable storage to survive
|
|
|
|
// a VM reboot.
|
|
|
|
//
|
|
|
|
VariableStore =
|
|
|
|
(EFI_PHYSICAL_ADDRESS)(UINTN)
|
2009-09-26 09:15:51 +02:00
|
|
|
AllocateRuntimePool (
|
2010-01-30 01:10:44 +01:00
|
|
|
2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize)
|
2009-09-26 09:15:51 +02:00
|
|
|
);
|
2009-09-07 22:18:17 +02:00
|
|
|
DEBUG ((EFI_D_INFO,
|
|
|
|
"Reserved variable store memory: 0x%lX; size: %dkb\n",
|
|
|
|
VariableStore,
|
2010-01-30 01:10:44 +01:00
|
|
|
(2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize)) / 1024
|
2009-09-07 22:18:17 +02:00
|
|
|
));
|
|
|
|
PcdSet64 (PcdEmuVariableNvStoreReserved, VariableStore);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 17:50:31 +01:00
|
|
|
VOID
|
|
|
|
DebugDumpCmos (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINTN Loop;
|
|
|
|
|
|
|
|
DEBUG ((EFI_D_INFO, "CMOS:\n"));
|
|
|
|
|
|
|
|
for (Loop = 0; Loop < 0x80; Loop++) {
|
|
|
|
if ((Loop % 0x10) == 0) {
|
|
|
|
DEBUG ((EFI_D_INFO, "%02x:", Loop));
|
|
|
|
}
|
|
|
|
DEBUG ((EFI_D_INFO, " %02x", CmosRead8 (Loop)));
|
|
|
|
if ((Loop % 0x10) == 0xf) {
|
|
|
|
DEBUG ((EFI_D_INFO, "\n"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-27 23:10:18 +02:00
|
|
|
/**
|
|
|
|
Perform Platform PEI initialization.
|
|
|
|
|
|
|
|
@param FileHandle Handle of the file being invoked.
|
|
|
|
@param PeiServices Describes the list of possible PEI Services.
|
|
|
|
|
|
|
|
@return EFI_SUCCESS The PEIM initialized successfully.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
InitializePlatform (
|
|
|
|
IN EFI_PEI_FILE_HANDLE FileHandle,
|
|
|
|
IN CONST EFI_PEI_SERVICES **PeiServices
|
|
|
|
)
|
|
|
|
{
|
2010-10-13 09:07:29 +02:00
|
|
|
EFI_PHYSICAL_ADDRESS TopOfMemory;
|
|
|
|
|
2009-05-27 23:10:18 +02:00
|
|
|
DEBUG ((EFI_D_ERROR, "Platform PEIM Loaded\n"));
|
|
|
|
|
2011-01-21 17:50:31 +01:00
|
|
|
DebugDumpCmos ();
|
|
|
|
|
2010-10-13 09:07:29 +02:00
|
|
|
TopOfMemory = MemDetect ();
|
2009-05-27 23:10:18 +02:00
|
|
|
|
2009-09-07 22:18:17 +02:00
|
|
|
ReserveEmuVariableNvStore ();
|
|
|
|
|
2009-05-27 23:10:18 +02:00
|
|
|
PeiFvInitialization ();
|
|
|
|
|
2010-10-13 09:07:29 +02:00
|
|
|
MemMapInitialization (TopOfMemory);
|
2009-05-27 23:10:18 +02:00
|
|
|
|
|
|
|
MiscInitialization ();
|
|
|
|
|
2011-03-22 02:55:08 +01:00
|
|
|
BootModeInitialization ();
|
|
|
|
|
2009-05-27 23:10:18 +02:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|