summaryrefslogtreecommitdiff
path: root/Board/EM/MeWrapper/AmtWrapper/Dxe
diff options
context:
space:
mode:
authorraywu <raywu0301@gmail.com>2018-06-15 00:00:50 +0800
committerraywu <raywu0301@gmail.com>2018-06-15 00:00:50 +0800
commitb7c51c9cf4864df6aabb99a1ae843becd577237c (patch)
treeeebe9b0d0ca03062955223097e57da84dd618b9a /Board/EM/MeWrapper/AmtWrapper/Dxe
downloadzprj-b7c51c9cf4864df6aabb99a1ae843becd577237c.tar.xz
init. 1AQQW051HEADmaster
Diffstat (limited to 'Board/EM/MeWrapper/AmtWrapper/Dxe')
-rw-r--r--Board/EM/MeWrapper/AmtWrapper/Dxe/AmtWrapperDxe.c883
-rw-r--r--Board/EM/MeWrapper/AmtWrapper/Dxe/AmtWrapperDxe.cif25
-rw-r--r--Board/EM/MeWrapper/AmtWrapper/Dxe/AmtWrapperDxe.dxs75
-rw-r--r--Board/EM/MeWrapper/AmtWrapper/Dxe/AmtWrapperDxe.h268
-rw-r--r--Board/EM/MeWrapper/AmtWrapper/Dxe/AmtWrapperDxe.mak117
-rw-r--r--Board/EM/MeWrapper/AmtWrapper/Dxe/AmtWrapperDxe.sdl57
-rw-r--r--Board/EM/MeWrapper/AmtWrapper/Dxe/AsfSupport.c1919
-rw-r--r--Board/EM/MeWrapper/AmtWrapper/Dxe/AsfSupport.h270
-rw-r--r--Board/EM/MeWrapper/AmtWrapper/Dxe/BdsBoot.c809
-rw-r--r--Board/EM/MeWrapper/AmtWrapper/Dxe/BdsConnect.c175
-rw-r--r--Board/EM/MeWrapper/AmtWrapper/Dxe/BdsConsole.c251
-rw-r--r--Board/EM/MeWrapper/AmtWrapper/Dxe/BdsLib.h459
-rw-r--r--Board/EM/MeWrapper/AmtWrapper/Dxe/BdsMisc.c594
-rw-r--r--Board/EM/MeWrapper/AmtWrapper/Dxe/BmMachine.h102
-rw-r--r--Board/EM/MeWrapper/AmtWrapper/Dxe/DevicePath.c1078
-rw-r--r--Board/EM/MeWrapper/AmtWrapper/Dxe/KvmSupport.c135
-rw-r--r--Board/EM/MeWrapper/AmtWrapper/Dxe/KvmSupport.h119
-rw-r--r--Board/EM/MeWrapper/AmtWrapper/Dxe/Performance.c431
-rw-r--r--Board/EM/MeWrapper/AmtWrapper/Dxe/Performance.h87
19 files changed, 7854 insertions, 0 deletions
diff --git a/Board/EM/MeWrapper/AmtWrapper/Dxe/AmtWrapperDxe.c b/Board/EM/MeWrapper/AmtWrapper/Dxe/AmtWrapperDxe.c
new file mode 100644
index 0000000..b5d4c0a
--- /dev/null
+++ b/Board/EM/MeWrapper/AmtWrapper/Dxe/AmtWrapperDxe.c
@@ -0,0 +1,883 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+//**********************************************************************
+//
+// $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/AmtWrapperDxe.c 10 6/18/14 3:08a Larryliu $
+//
+// $Revision: 10 $
+//
+// $Date: 6/18/14 3:08a $
+//
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/AmtWrapperDxe.c $
+//
+// 10 6/18/14 3:08a Larryliu
+// [TAG] EIP173999
+// [Category] Improvement
+// [Description] [HWR]Remove useless comments from Intel ME
+// component.(except RC)
+// [Files] AmtWrapperDxe.c
+//
+// 8 5/14/14 9:52p Tristinchou
+// [TAG] EIP167030
+// [Category] Improvement
+// [Description] Remove the variable runtime attribute and keep original
+// attributes.
+//
+// 7 9/12/13 5:26a Klzhan
+// [TAG] EIPNone
+// [Category] Improvement
+// [Description] Correct gSerialOverLanDevicePath
+//
+// 6 4/18/13 1:55a Klzhan
+// [TAG] EIP119190
+// [Category] Bug Fix
+// [Severity] Important
+// [Symptom] BIOS doesn't wait for KVM pass code input.
+// [RootCause] The Con Out Start protocol GUID is different in AMI and
+// ME RC.
+// [Solution] Install ME RC ConOut Protocol when AMI ConOut Protocol
+// installed.
+// [Files] AmtWrapperDxe.c
+// AmtWrapperDxe.h
+//
+// 5 4/08/13 3:06a Klzhan
+// [TAG] EIPNone
+// [Category] Improvement
+// [Description] Support New Security protocol.
+//
+// 4 10/30/12 8:33a Klzhan
+// Correct Secure IDER boot
+//
+// 3 8/14/12 7:24a Klzhan
+// Support UEFI IDER boot.
+//
+// 2 4/24/12 12:36a Klzhan
+// Update modulepart to latest
+//
+// 1 2/08/12 1:08a Klzhan
+// Initial Check in
+//
+// 3 6/21/11 3:42a Klzhan
+// Fix comnpiler error if PCI COM is 0.
+//
+// 2 3/29/11 3:18a Klzhan
+// Remove un-used code.
+//
+// 1 2/25/11 1:43a Klzhan
+// Initial Check-in
+//
+// 2 12/28/10 2:00a Klzhan
+// Improvement : Enable/Disable Terminal item for SOL redirection.
+//
+// 1 12/03/10 5:10a Klzhan
+// Initial Check-in.
+//
+//
+//**********************************************************************
+
+//<AMI_FHDR_START>
+//----------------------------------------------------------------------------
+//
+// Name: AmtWrapperDxe.c
+//
+// Description: Amt Wrapper Functions
+//
+//----------------------------------------------------------------------------
+//<AMI_FHDR_END>
+/*++
+Copyright (c) 2009 Intel Corporation. All rights reserved.
+This software and associated documentation (if any) is furnished
+under a license and may only be used or copied in accordance
+with the terms of the license. Except as permitted by such
+license, no part of this software or documentation may be
+reproduced, stored in a retrieval system, or transmitted in any
+form or by any means without the express written consent of
+Intel Corporation.
+--*/
+#if EFI_SPECIFICATION_VERSION>0x20000
+#include "token.h"
+#define _HII_H_
+#define _FORM_CALLBACK_H_
+#define _GLOBAL_VARIABLE_GUID_H_
+#ifndef GUID_VARIABLE_DECLARATION
+#define GUID_VARIABLE_DECLARATION(Variable, Guid) extern EFI_GUID Variable
+#endif
+#include "AmtWrapperDxe.h"
+#else
+#include "AmtWrapperDxe.h"
+#include "token.h"
+#define __UEFI_HII__H__
+#define __HII_PROTOCOL_H__
+#define _HII_H_
+#endif
+#if defined(Terminal_SUPPORT) && (Terminal_SUPPORT == 1)
+#include "Core\Em\Terminal\TerminalSetupVar.h"
+#endif
+#include <SetupDataDefinition.h>
+#if defined(CORE_COMBINED_VERSION) && CORE_COMBINED_VERSION >=0x4028e
+#include <Protocol\Security2.h>
+#else
+#include <Protocol\Security.h>
+#endif
+
+#include <Amt.h>
+#include EFI_GUID_DEFINITION(ConsoleOutDevice)
+
+#define SETUP_GUID { 0xEC87D643, 0xEBA4, 0x4BB5, 0xA1, 0xE5, 0x3F, 0x3E, 0x36, 0xB2, 0x0D, 0xA9 }
+
+AMT_WRAPPER_PROTOCOL AmtWrapperInstance = {
+ AmtWrapperInit,
+ AmtWrapperGet,
+ AmtWrapperSet,
+ AmtWrapperEnableSol,
+ AmtWrapperEnableIdeR,
+ AmtWrapperPauseBoot,
+ AmtWrapperEnterSetup,
+ //AsfSupportInit,
+ AmtWrapperBdsBootViaAsf,
+ BdsLibUpdateConsoleVariable,
+ ActiveManagementConsoleLocked,
+ AmtWrapperEnableKvm,
+ AmtWrapperInitializationKvm
+ };
+
+extern EFI_ACTIVE_MANAGEMENT_PROTOCOL *mActiveManagement;
+extern EFI_ASF_BOOT_OPTIONS *mAsfBootOptions;
+#if defined(LEGACYSREDIR_SUPPORT) && (LEGACYSREDIR_SUPPORT == 1)
+EFI_GUID gEfiLegacySredirProtocolGuid = EFI_LEGACY_SREDIR_PROTOCOL_GUID;
+#endif
+EFI_GUID gSetupGuid = SETUP_GUID;
+EFI_GUID gEfiAmtWrapperProtocolGuid = EFI_AMT_WRAPPER_PROTOCOL_GUID;
+EFI_GUID gEfiMeBiosExtensionSetupGuid = EFI_ME_BIOS_EXTENSION_SETUP_GUID;
+CHAR16 gEfiMeBiosExtensionSetupName[] = EFI_ME_BIOS_EXTENSION_SETUP_VARIABLE_NAME;
+
+PLATFORM_PCI_SERIAL_OVER_LAN_DEVICE_PATH gSerialOverLanDevicePath = {
+ gPciRootBridge,
+ {
+ HARDWARE_DEVICE_PATH,
+ HW_PCI_DP,
+ (UINT8)(sizeof(PCI_DEVICE_PATH)),
+ (UINT8)((sizeof(PCI_DEVICE_PATH)) >> 8),
+ SOL_FUNCTION_NUMBER,
+ ME_DEVICE_NUMBER
+ },
+ {
+ MESSAGING_DEVICE_PATH,
+ MSG_UART_DP,
+ (UINT8)(sizeof(UART_DEVICE_PATH)),
+ (UINT8)((sizeof(UART_DEVICE_PATH)) >> 8),
+ 0,
+ 115200,
+ 8,
+ 1,
+ 1
+ },
+ {
+ MESSAGING_DEVICE_PATH,
+ MSG_VENDOR_DP,
+ (UINT8)(sizeof(VENDOR_DEVICE_PATH)),
+ (UINT8)((sizeof(VENDOR_DEVICE_PATH)) >> 8),
+ DEVICE_PATH_MESSAGING_PC_ANSI
+ },
+ gEndEntire
+ };
+
+
+EFI_HANDLE mBdsImageHandle;
+UINT16 gPlatformBootTimeOutDefault = 1;
+
+
+//
+// Driver entry point
+//
+EFI_DRIVER_ENTRY_POINT (AmtWrapperDxeEntryPoint);
+
+//
+// Function implementations
+//
+#if defined(CORE_COMBINED_VERSION) && CORE_COMBINED_VERSION >=0x4028e
+EFI_STATUS EmptyFileAuthentication
+(
+ IN CONST EFI_SECURITY2_ARCH_PROTOCOL *This,
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *File,
+ IN VOID *FileBuffer,
+ IN UINTN FileSize,
+ IN BOOLEAN BootPolicy
+)
+#else
+EFI_STATUS EmptyFileAuthentication
+(
+ IN EFI_SECURITY_ARCH_PROTOCOL *This,
+ IN UINT32 AuthenticationStatus,
+ IN EFI_DEVICE_PATH_PROTOCOL *File
+)
+#endif
+{
+ if (File==NULL) return EFI_INVALID_PARAMETER;
+ return EFI_SUCCESS;
+}
+
+VOID
+EFIAPI
+InstallEDKConOutStartProtocol (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ )
+{
+
+ gBS->InstallProtocolInterface(
+ &mBdsImageHandle, &gEfiConsoleOutDeviceGuid, EFI_NATIVE_INTERFACE, NULL);
+
+ gBS->CloseEvent (Event);
+}
+
+EFI_STATUS
+EFIAPI
+AmtWrapperDxeEntryPoint (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+)
+/*++
+
+Routine Description:
+
+ Entry point for the Active Management Driver.
+
+Arguments:
+
+ ImageHandle Image handle of this driver.
+ SystemTable Global system service table.
+
+Returns:
+
+ EFI_SUCCESS Initialization complete.
+ EFI_UNSUPPORTED The chipset is unsupported by this driver.
+ EFI_OUT_OF_RESOURCES Do not have enough resources to initialize the driver.
+ EFI_DEVICE_ERROR Device error, driver exits abnormally.
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_EVENT ReadyToBootEvent;
+ EFI_GUID gSetupGuid = SETUP_GUID;
+ UINTN VariableSize = sizeof(SETUP_DATA);
+ SETUP_DATA SetupDataBuffer;
+ SETUP_DATA *SetupData = &SetupDataBuffer;
+ VOID *AfterConsolOutNotifyReg;
+ EFI_EVENT AfterConsolOutInstalledEvent;
+ EFI_GUID AmiConOutStartProtocolGuid = AMI_CONSOLE_OUT_DEVICES_STARTED_PROTOCOL_GUID;
+
+ mBdsImageHandle = ImageHandle;
+ //
+ // Initialize the EFI Driver Library
+ //
+ EfiInitializeDriverLib (ImageHandle, SystemTable);
+ INITIALIZE_SCRIPT (ImageHandle, SystemTable);
+
+ mAsfBootOptions = NULL;
+ mActiveManagement = NULL;
+
+ InitAmtWrapperLib();
+ //
+ // Install the EFI_ACTIVE_MANAGEMENT_PROTOCOL interface
+ //
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &ImageHandle,
+ &gEfiAmtWrapperProtocolGuid, &AmtWrapperInstance,
+ NULL
+ );
+
+ // This event is for KVM function, because ConOut Start GUID is different from AMI to ME RC.
+ Status = gBS->CreateEvent (
+ EFI_EVENT_NOTIFY_SIGNAL,
+ EFI_TPL_NOTIFY,
+ InstallEDKConOutStartProtocol,
+ NULL,
+ &AfterConsolOutInstalledEvent
+ );
+
+ Status = gBS->RegisterProtocolNotify (
+ &AmiConOutStartProtocolGuid,
+ AfterConsolOutInstalledEvent,
+ &AfterConsolOutNotifyReg
+ );
+
+#if defined(Terminal_SUPPORT) && (Terminal_SUPPORT == 1)
+ // Enable/Disable Sol redirection
+ SetSOLCOMEnable(AmtWrapperEnableSol());
+#endif
+ //
+ // Register Ready to Boot Event for AMT Wrapper
+ //
+#if defined(EFI_EVENT_SIGNAL_READY_TO_BOOT) && EFI_SPECIFICATION_VERSION<0x20000
+ Status = gBS->CreateEvent(
+ EFI_EVENT_SIGNAL_READY_TO_BOOT | EFI_EVENT_NOTIFY_SIGNAL_ALL,
+ EFI_TPL_CALLBACK,
+ AmtWrapperReadyToBoot,
+ (VOID *)&ImageHandle,
+ &ReadyToBootEvent
+ );
+#else
+ Status = EfiCreateEventReadyToBoot(
+ EFI_TPL_CALLBACK,
+ AmtWrapperReadyToBoot,
+ (VOID *)&ImageHandle,
+ &ReadyToBootEvent
+ );
+#endif
+
+ return Status;
+}
+
+#if defined(Terminal_SUPPORT) && (Terminal_SUPPORT == 1)
+//<AMI_PHDR_START>
+//----------------------------------------------------------------------------
+// Procedure: SetSOLCOMEnable
+//
+// Description: Enable/Disable SOL COM.
+//
+// Input:
+//
+// Output:
+//
+// Notes:
+//
+//----------------------------------------------------------------------------
+//<AMI_PHDR_END>
+VOID
+SetSOLCOMEnable(
+ IN BOOLEAN Enabled
+)
+{
+ UINT32 ComPort;
+ UINT32 SetupVarAttr;
+ UINTN SetupDataSize;
+ SETUP_DATA gSetupData;
+ EFI_STATUS Status;
+#if (TOTAL_PCI_SERIAL_PORTS > 0)
+ UINT32 i = 0;
+ EFI_GUID gTerminalVarGuid = TERMINAL_VAR_GUID;
+ UINTN PciSerialPortsLocationVarSize =
+ sizeof(PCI_SERIAL_PORTS_LOCATION_VAR);
+ UINT32 PciSerialPortsLocationVarAttributes=0;
+ PCI_SERIAL_PORTS_LOCATION_VAR PciSerialPortsLocationVar;
+ UINT32 gTotalSioSerialPorts = TOTAL_SIO_SERIAL_PORTS;
+ Status = gRT->GetVariable(L"PciSerialPortsLocationVar",
+ &gTerminalVarGuid,
+ &PciSerialPortsLocationVarAttributes,
+ &PciSerialPortsLocationVarSize,
+ &PciSerialPortsLocationVar);
+
+ if(EFI_ERROR(Status)) {
+ ComPort = gTotalSioSerialPorts;
+ }
+
+ ComPort = gTotalSioSerialPorts;
+
+ for (i = 0; i < TOTAL_PCI_SERIAL_PORTS; i++) {
+ if ((PciSerialPortsLocationVar.Device[i] == SOL_DEVICE_NUMBER) &&
+ (PciSerialPortsLocationVar.Function[i] == SOL_FUNCTION_NUMBER)) {
+ ComPort = gTotalSioSerialPorts+i;
+ break;
+ }
+ }
+#else
+ return;
+#endif
+
+ SetupVarAttr = 0;
+ SetupDataSize = sizeof(SETUP_DATA);
+ Status = gRT->GetVariable( \
+ L"Setup", \
+ &gSetupGuid, \
+ &SetupVarAttr, \
+ &SetupDataSize, \
+ &gSetupData );
+
+ if(Enabled)
+ gSetupData.ConsoleRedirectionEnable[ComPort] = 1;
+ else
+ gSetupData.ConsoleRedirectionEnable[ComPort] = 0;
+
+ Status = gRT->SetVariable( \
+ L"Setup", \
+ &gSetupGuid, \
+ SetupVarAttr, \
+ SetupDataSize, \
+ &gSetupData );
+}
+#endif
+
+EFI_STATUS
+BdsRefreshBbsTableForBoot (
+ IN BDS_COMMON_OPTION *Entry
+)
+{
+ return EFI_NOT_FOUND;
+}
+
+VOID
+PrintBbsTable (
+ IN BBS_TABLE *LocalBbsTable
+)
+{
+ UINT16 Idx;
+
+ DEBUG ((EFI_D_ERROR, "\n"));
+ DEBUG ((EFI_D_ERROR, " NO Prio bb/dd/ff cl/sc Type Stat segm:offs\n"));
+ DEBUG ((EFI_D_ERROR, "=============================================\n"));
+ for (Idx = 0; Idx < MAX_BBS_ENTRIES; Idx++)
+ {
+ if (LocalBbsTable[Idx].BootPriority == BBS_IGNORE_ENTRY)
+ {
+ continue;
+ }
+
+ DEBUG (
+ (EFI_D_ERROR,
+ " %02x: %04x %02x/%02x/%02x %02x/02%x %04x %04x %04x:%04x\n",
+ (UINTN) Idx,
+ (UINTN) LocalBbsTable[Idx].BootPriority,
+ (UINTN) LocalBbsTable[Idx].Bus,
+ (UINTN) LocalBbsTable[Idx].Device,
+ (UINTN) LocalBbsTable[Idx].Function,
+ (UINTN) LocalBbsTable[Idx].Class,
+ (UINTN) LocalBbsTable[Idx].SubClass,
+ (UINTN) LocalBbsTable[Idx].DeviceType,
+ (UINTN) * (UINT16 *) &LocalBbsTable[Idx].StatusFlags,
+ (UINTN) LocalBbsTable[Idx].BootHandlerSegment,
+ (UINTN) LocalBbsTable[Idx].BootHandlerOffset,
+ (UINTN) ((LocalBbsTable[Idx].MfgStringSegment << 4) + LocalBbsTable[Idx].MfgStringOffset),
+ (UINTN) ((LocalBbsTable[Idx].DescStringSegment << 4) + LocalBbsTable[Idx].DescStringOffset))
+ );
+ }
+
+ DEBUG ((EFI_D_ERROR, "\n"));
+}
+
+BOOLEAN
+AmtWrapperGet(
+ IN UINTN Index,
+ IN OUT VOID *pVar
+)
+{
+ BOOLEAN st = FALSE;
+
+ InitAmtWrapperLib();
+
+ if (Index == GET_SOL_DP) {
+ *((PLATFORM_PCI_SERIAL_OVER_LAN_DEVICE_PATH **)pVar) = &gSerialOverLanDevicePath;
+ st = TRUE;
+ } else if (Index == GET_TIME_OUT) {
+ *((UINT16 *)pVar) = BdsLibGetTimeout();
+ st = TRUE;
+ } else if (Index == GET_BOOT_OPTION) {
+ *((UINT16 *)pVar) = mAsfBootOptions->BootOptions;
+ st = TRUE;
+ } else if (Index == GET_IS_SOL) {
+ *((UINTN *)pVar) = IsSOL(*((EFI_HANDLE *)pVar));
+ st = TRUE;
+ } else if (Index == GET_IS_IDER) {
+ *((UINTN *)pVar) = IsIDER(*((EFI_HANDLE *)pVar));
+ st = TRUE;
+ }
+
+ return st;
+}
+
+UINTN IsSOL(
+ IN EFI_HANDLE Controller
+)
+{
+ EFI_STATUS Status;
+ EFI_PCI_IO_PROTOCOL *PciIo;
+ UINTN Segment=0;
+ UINTN Bus=0;
+ UINTN Device=0;
+ UINTN Function=0;
+ UINTN flag = FALSE;
+
+ Status = gBS->HandleProtocol(Controller,
+ &gEfiPciIoProtocolGuid,
+ &PciIo);
+ if (!EFI_ERROR(Status)) {
+ Status = PciIo->GetLocation(PciIo,
+ &Segment,
+ &Bus,
+ &Device,
+ &Function);
+ if (!EFI_ERROR(Status)) {
+ if (Device == SOL_DEVICE_NUMBER && Function == SOL_FUNCTION_NUMBER) {
+ flag = TRUE;
+ }
+ }
+ }
+
+ return flag;
+}
+
+UINTN IsIDER(
+ IN EFI_HANDLE Controller
+)
+{
+ EFI_STATUS Status;
+ EFI_PCI_IO_PROTOCOL *PciIo;
+ UINTN Segment=0;
+ UINTN Bus=0;
+ UINTN Device=0;
+ UINTN Function=0;
+ UINTN flag = FALSE;
+
+ Status = gBS->HandleProtocol(Controller,
+ &gEfiPciIoProtocolGuid,
+ &PciIo);
+ if (!EFI_ERROR(Status)) {
+ Status = PciIo->GetLocation(PciIo,
+ &Segment,
+ &Bus,
+ &Device,
+ &Function);
+ if (!EFI_ERROR(Status)) {
+ if (Device == IDER_DEVICE_NUMBER && Function == IDER_FUNCTION_NUMBER) {
+ flag = TRUE;
+ }
+ }
+ }
+
+ return flag;
+}
+
+UINT16 ConvertSetupDataToUART(
+ UINT8 Parity,
+ UINT8 DataBits,
+ UINT8 StopBits
+)
+{
+ UINT16 DataParityStopBit = 0;
+
+ switch (Parity) {
+ case NoParity:
+ DataParityStopBit &= ~(PAREN | EVENPAR | STICPAR);
+ break;
+ case EvenParity:
+ DataParityStopBit |= (PAREN | EVENPAR);
+ DataParityStopBit &= ~STICPAR;
+ break;
+ case OddParity:
+ DataParityStopBit |= PAREN;
+ DataParityStopBit &= ~(EVENPAR | STICPAR);
+ break;
+ case SpaceParity:
+ DataParityStopBit |= (PAREN | EVENPAR | STICPAR);
+ break;
+ case MarkParity:
+ DataParityStopBit |= (PAREN | STICPAR);
+ DataParityStopBit &= ~EVENPAR;
+ break;
+ }
+
+ // Set stop bits.
+ switch (StopBits) {
+ case OneStopBit :
+ DataParityStopBit &= ~STOPB;
+ break;
+ case OneFiveStopBits :
+ case TwoStopBits :
+ DataParityStopBit |= STOPB;
+ break;
+ }
+
+ // Set data bits.
+ DataParityStopBit &= ~SERIALDB;
+ DataParityStopBit |= (UINT8)((DataBits - 5) & 0x03);
+
+ return DataParityStopBit;
+}
+
+BOOLEAN
+AmtWrapperSet(
+ IN UINTN Index,
+ IN OUT VOID *pVar
+)
+{
+#if defined(LEGACYSREDIR_SUPPORT) && (LEGACYSREDIR_SUPPORT == 1)
+ EFI_LEGACY_SREDIR_PROTOCOL *pLegacySredir;
+ UINT64 PciAddress;
+ UINT32 SerialAddress;
+ UINT8 SerialIRQ;
+ EFI_STATUS Status;
+ EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;
+ BOOLEAN st = FALSE;
+
+ InitAmtWrapperLib();
+
+ if (Index == SET_BIOS_WDT_START) {
+ AsfStartWatchDog(ASF_START_BIOS_WDT);
+ st = TRUE;
+ }
+ else if (Index == SET_OS_WDT_START) {
+ AsfStartWatchDog(ASF_START_OS_WDT);
+ st = TRUE;
+ }
+ else if (Index == SET_WDT_STOP) {
+ AsfStopWatchDog();
+ st = TRUE;
+ }
+ else if (Index == SET_OS_SOL) {
+ Status = gBS->LocateProtocol(&gEfiLegacySredirProtocolGuid, NULL, &pLegacySredir);
+ ASSERT_EFI_ERROR(Status);
+
+ Status = gBS->LocateProtocol(&gEfiPciRootBridgeIoProtocolGuid, NULL, &PciRootBridgeIo);
+ ASSERT_EFI_ERROR(Status);
+
+ PciAddress = EFI_PCI_ADDRESS (SOL_BUS_NUMBER, SOL_DEVICE_NUMBER, SOL_FUNCTION_NUMBER, 0x10);
+ PciRootBridgeIo->Pci.Read (
+ PciRootBridgeIo,
+ EfiPciWidthUint32,
+ PciAddress,
+ 1,
+ &SerialAddress
+ );
+ SerialAddress &= ~1; // mask IO/MEM bit
+
+ PciAddress = EFI_PCI_ADDRESS (SOL_BUS_NUMBER, SOL_DEVICE_NUMBER, SOL_FUNCTION_NUMBER, 0x3C);
+ PciRootBridgeIo->Pci.Read (
+ PciRootBridgeIo,
+ EfiPciWidthUint8,
+ PciAddress,
+ 1,
+ &SerialIRQ
+ );
+/*
+ UID = TOTAL_SIO_SERIAL_PORTS;
+ gEfiComParameters.BaseAddress = (UINT16)SerialAddress;
+ gEfiComParameters.SerialIRQ = (UINT8)SerialIRQ;
+
+ VariableSize = sizeof(SETUP_DATA);
+ Status = gRT->GetVariable(
+ L"Setup",
+ &gSetupGuid,
+ NULL,
+ &VariableSize,
+ &SetupData);
+ ASSERT(!EFI_ERROR(Status));
+
+ gEfiComParameters.Baudrate = BaudRates[SetupData.BaudRate[UID]];
+ gEfiComParameters.TerminalType = TerminalTypes[SetupData.TerminalType[UID]];
+ gEfiComParameters.FlowControl = SetupData.FlowControl[UID];
+
+ gEfiComParameters.DataParityStop = ConvertSetupDataToUART(
+ SetupData.Parity[UID],
+ SetupData.DataBits[UID],
+ SetupData.StopBits[UID]);
+
+ if (SREDIR_DISPLAY_MODE == DISPLAY_BY_80x24)
+ gEfiComParameters.LegacyOsResolution = 0;
+ else if (SREDIR_DISPLAY_MODE == DISPLAY_BY_80x25)
+ gEfiComParameters.LegacyOsResolution = 1;
+ else
+ gEfiComParameters.LegacyOsResolution = SetupData.LegacyOsResolution[UID];
+*/
+ Status = pLegacySredir->EnableLegacySredir(pLegacySredir);
+
+ ASSERT_EFI_ERROR (Status);
+ st = TRUE;
+ }
+
+ return st;
+#else
+ return FALSE;
+#endif
+}
+
+EFI_STATUS
+AmtWrapperInit(
+ IN EFI_HANDLE ImageHandle,
+ IN OUT EFI_SYSTEM_TABLE *SystemTable
+)
+{
+ mBdsImageHandle = ImageHandle;
+ InitAmtWrapperLib();
+
+ return EFI_SUCCESS;
+}
+
+
+VOID
+InitAmtWrapperLib(VOID)
+{
+ if (mActiveManagement == NULL)
+ AmtLibInit();
+
+ if (mAsfBootOptions == NULL) {
+ BdsAsfInitialization();
+ }
+}
+
+BOOLEAN
+AmtWrapperEnableSol(
+ IN VOID
+)
+{
+ BOOLEAN st;
+
+ InitAmtWrapperLib();
+ st = ActiveManagementEnableSol();
+ if(((mAsfBootOptions->OemParameters) & 0x01) && (mAsfBootOptions != NULL))
+ st = TRUE;
+ else
+ st = FALSE;
+ return st;
+}
+
+BOOLEAN
+AmtWrapperEnableIdeR(
+ IN VOID
+)
+{
+ BOOLEAN st;
+ EFI_STATUS Status;
+#if defined(CORE_COMBINED_VERSION) && CORE_COMBINED_VERSION >=0x4028e
+ EFI_SECURITY2_ARCH_PROTOCOL *mSecurity;
+#else
+ EFI_SECURITY_ARCH_PROTOCOL *mSecurity;
+#endif
+
+ InitAmtWrapperLib();
+ st = ActiveManagementEnableIdeR();
+ if(!st)
+ return st;
+ // IDER enabled and Enforce Secure Boot enabled
+ if((mAsfBootOptions->SpecialCommandParam & ENFORCE_SECURE_BOOT)
+ != ENFORCE_SECURE_BOOT)
+ {
+#if defined(CORE_COMBINED_VERSION) && CORE_COMBINED_VERSION >=0x4028e
+ EFI_GUID gEfiSecurity2ArchProtocolGuid = EFI_SECURITY2_ARCH_PROTOCOL_GUID;
+ Status = gBS->LocateProtocol(&gEfiSecurity2ArchProtocolGuid,
+
+#else
+ Status = gBS->LocateProtocol(&gEfiSecurityArchProtocolGuid,
+#endif
+ NULL, &mSecurity);
+
+ if(EFI_ERROR(Status))
+ return st;
+ // Set a empty File Authentication to skip Secure check.
+ // This will not been restore, because IDER boot fail system HALT
+
+#if defined(CORE_COMBINED_VERSION) && CORE_COMBINED_VERSION >=0x4028e
+ mSecurity->FileAuthentication = EmptyFileAuthentication;
+#else
+ mSecurity->FileAuthenticationState = EmptyFileAuthentication;
+#endif
+ }
+
+ return st;
+}
+
+BOOLEAN
+AmtWrapperPauseBoot(
+ IN VOID
+)
+{
+ BOOLEAN st;
+
+ InitAmtWrapperLib();
+ st = ActiveManagementPauseBoot();
+
+ return st;
+}
+
+BOOLEAN
+AmtWrapperEnterSetup(
+ IN VOID
+)
+{
+ BOOLEAN st;
+
+ InitAmtWrapperLib();
+ st = ActiveManagementEnterSetup();
+
+ return st;
+}
+
+EFI_STATUS
+AmtWrapperBdsBootViaAsf(
+ IN VOID
+)
+{
+ EFI_STATUS Status = EFI_NOT_FOUND;
+
+ InitAmtWrapperLib();
+
+ if (mActiveManagement != NULL && mAsfBootOptions != NULL) {
+ Status = BdsBootViaAsf();
+ }
+
+ return Status;
+}
+
+
+
+EFI_STATUS
+AmtWrapperReadyToBoot(
+ EFI_EVENT Event,
+ VOID *ParentImageHandle
+)
+{
+ EFI_STATUS Status = EFI_SUCCESS;
+
+
+ return Status;
+}
+
+BOOLEAN
+AmtWrapperEnableKvm(
+ IN VOID
+)
+{
+ BOOLEAN Status;
+
+ Status = ActiveManagementEnableKvm();
+
+ return Status;
+}
+
+BOOLEAN
+AmtWrapperInitializationKvm(
+ IN VOID
+)
+{
+ BOOLEAN Status;
+
+ Status = BdsKvmInitialization();
+
+ return Status;
+}
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//************************************************************************* \ No newline at end of file
diff --git a/Board/EM/MeWrapper/AmtWrapper/Dxe/AmtWrapperDxe.cif b/Board/EM/MeWrapper/AmtWrapper/Dxe/AmtWrapperDxe.cif
new file mode 100644
index 0000000..91f7c3b
--- /dev/null
+++ b/Board/EM/MeWrapper/AmtWrapper/Dxe/AmtWrapperDxe.cif
@@ -0,0 +1,25 @@
+<component>
+ name = "AmtWrapperDxe"
+ category = ModulePart
+ LocalRoot = "Board\EM\MeWrapper\AmtWrapper\Dxe"
+ RefName = "AmtWrapperDxe"
+[files]
+"AmtWrapperDxe.sdl"
+"AmtWrapperDxe.c"
+"AmtWrapperDxe.h"
+"AmtWrapperDxe.mak"
+"AmtWrapperDxe.dxs"
+"AsfSupport.c"
+"AsfSupport.h"
+"DevicePath.c"
+"Performance.c"
+"Performance.h"
+"BdsBoot.c"
+"BdsConnect.c"
+"BdsConsole.c"
+"BdsLib.h"
+"BdsMisc.c"
+"BmMachine.h"
+"KvmSupport.c"
+"KvmSupport.h"
+<endComponent>
diff --git a/Board/EM/MeWrapper/AmtWrapper/Dxe/AmtWrapperDxe.dxs b/Board/EM/MeWrapper/AmtWrapper/Dxe/AmtWrapperDxe.dxs
new file mode 100644
index 0000000..4e8ab21
--- /dev/null
+++ b/Board/EM/MeWrapper/AmtWrapper/Dxe/AmtWrapperDxe.dxs
@@ -0,0 +1,75 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+//**********************************************************************
+//
+// $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/AmtWrapperDxe.dxs 1 2/08/12 1:08a Klzhan $
+//
+// $Revision: 1 $
+//
+// $Date: 2/08/12 1:08a $
+//
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/AmtWrapperDxe.dxs $
+//
+// 1 2/08/12 1:08a Klzhan
+// Initial Check in
+//
+// 1 2/25/11 1:43a Klzhan
+// Initial Check-in
+//
+// 1 12/03/10 5:10a Klzhan
+// Initial Check-in.
+//
+//
+//**********************************************************************
+
+//<AMI_FHDR_START>
+//----------------------------------------------------------------------------
+//
+// Name: AmtWrapperDxe.dxs
+//
+// Description: Dependency file for AMTWrapperDxe module.
+//
+//----------------------------------------------------------------------------
+//<AMI_FHDR_END>
+
+#include "EfiDepex.h"
+
+#include EFI_PROTOCOL_DEFINITION (BootScriptSave)
+#include EFI_PROTOCOL_DEPENDENCY (PciRootBridgeIo)
+#include EFI_PROTOCOL_DEFINITION (AlertStandardFormat)
+#include EFI_PROTOCOL_DEFINITION (ActiveManagement)
+
+DEPENDENCY_START
+ EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GUID AND
+ EFI_ACTIVE_MANAGEMENT_PROTOCOL_GUID AND
+ EFI_ALERT_STANDARD_FORMAT_PROTOCOL_GUID AND
+ EFI_BOOT_SCRIPT_SAVE_PROTOCOL_GUID
+DEPENDENCY_END
+
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//************************************************************************* \ No newline at end of file
diff --git a/Board/EM/MeWrapper/AmtWrapper/Dxe/AmtWrapperDxe.h b/Board/EM/MeWrapper/AmtWrapper/Dxe/AmtWrapperDxe.h
new file mode 100644
index 0000000..2bc4540
--- /dev/null
+++ b/Board/EM/MeWrapper/AmtWrapper/Dxe/AmtWrapperDxe.h
@@ -0,0 +1,268 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+//**********************************************************************
+//
+// $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/AmtWrapperDxe.h 3 4/18/13 1:55a Klzhan $
+//
+// $Revision: 3 $
+//
+// $Date: 4/18/13 1:55a $
+//
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/AmtWrapperDxe.h $
+//
+// 3 4/18/13 1:55a Klzhan
+// [TAG] EIP119190
+// [Category] Bug Fix
+// [Severity] Important
+// [Symptom] BIOS doesn't wait for KVM pass code input.
+// [RootCause] The Con Out Start protocol GUID is different in AMI and
+// ME RC.
+// [Solution] Install ME RC ConOut Protocol when AMI ConOut Protocol
+// installed.
+// [Files] AmtWrapperDxe.c
+// AmtWrapperDxe.h
+//
+// 2 4/24/12 12:36a Klzhan
+// Update modulepart to latest
+//
+// 1 2/08/12 1:08a Klzhan
+// Initial Check in
+//
+// 1 2/25/11 1:43a Klzhan
+// Initial Check-in
+//
+// 2 12/28/10 2:00a Klzhan
+// Improvement : Enable/Disable Terminal item for SOL redirection.
+//
+// 1 12/03/10 5:10a Klzhan
+// Initial Check-in.
+//
+//
+//**********************************************************************
+
+//<AMI_FHDR_START>
+//----------------------------------------------------------------------------
+//
+// Name: AmtWrapperDxe.h
+//
+// Description: Header file for Amt Wrapper Dxe module
+//
+//----------------------------------------------------------------------------
+//<AMI_FHDR_END>
+#ifndef _AMT_WRAPPER_DXE_H_
+#define _AMT_WRAPPER_DXE_H_
+
+#include "Efi.h"
+#include "EfiDriverLib.h"
+#include "EfiCommonLib.h"
+#include "BdsLib.h"
+#include "EfiScriptLib.h"
+#if defined(LEGACYSREDIR_SUPPORT) && (LEGACYSREDIR_SUPPORT == 1)
+#include "Protocol\LegacySredir.h"
+#endif
+#include "AmtLib.h"
+#include "MeAccess.h"
+
+#include EFI_PROTOCOL_CONSUMER (AmtPlatformPolicy)
+#include EFI_PROTOCOL_CONSUMER (AmtWrapper)
+#include EFI_PROTOCOL_CONSUMER (BootScriptSave)
+#include EFI_PROTOCOL_CONSUMER (PciRootBridgeIo)
+#include EFI_PROTOCOL_CONSUMER (ActiveManagement)
+#include EFI_PROTOCOL_CONSUMER (PciIo)
+#include EFI_PROTOCOL_CONSUMER (SerialIo)
+
+#include EFI_GUID_DEFINITION (MeBiosExtensionSetup)
+
+#define R_PCI_SVID 0x2C
+
+#define DISPLAY_SCREEN 0x01 // for LegacySredr CSM16
+#define SUPPORT8025 0x02 // for LegacySredr CSM16
+
+// define for SREDIR_DISPLAY_MODE
+#define DISPLAY_BY_SETUP 0x00
+#define DISPLAY_BY_80x24 0x01
+#define DISPLAY_BY_80x25 0x02
+
+#define STOPB 0x4 // Bit2: Number of Stop Bits
+#define PAREN 0x8 // Bit3: Parity Enable
+#define EVENPAR 0x10 // Bit4: Even Parity Select
+#define STICPAR 0x20 // Bit5: Sticky Parity
+#define SERIALDB 0x3 // Bit0-1: Number of Serial
+ //
+
+#define EFI_WIN_NT_THUNK_PROTOCOL_GUID \
+ { 0x58c518b1, 0x76f3, 0x11d4, 0xbc, 0xea, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 }
+
+#define EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID \
+ { 0x96eb4ad6, 0xa32a, 0x11d4, 0xbc, 0xfd, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 }
+
+#define EFI_WIN_NT_SERIAL_PORT_GUID \
+ { 0xc95a93d, 0xa006, 0x11d4, 0xbc, 0xfa, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 }
+
+#define AMI_CONSOLE_OUT_DEVICES_STARTED_PROTOCOL_GUID \
+ { 0xef9a3971, 0xc1a0, 0x4a93, 0xbd, 0x40, 0x5a, 0xa1, 0x65, 0xf2, 0xdc, 0x3a }
+
+typedef struct {
+ ACPI_HID_DEVICE_PATH PciRootBridge;
+ PCI_DEVICE_PATH SerialOverLAN;
+ UART_DEVICE_PATH Uart;
+ VENDOR_DEVICE_PATH TerminalType;
+ EFI_DEVICE_PATH_PROTOCOL End;
+} PLATFORM_PCI_SERIAL_OVER_LAN_DEVICE_PATH;
+
+#define gPciRootBridge \
+ { \
+ ACPI_DEVICE_PATH, \
+ ACPI_DP, \
+ (UINT8) (sizeof (ACPI_HID_DEVICE_PATH)), \
+ (UINT8) ((sizeof (ACPI_HID_DEVICE_PATH)) >> 8), \
+ EISA_PNP_ID (0x0A03), 0 \
+ }
+
+#define gEndEntire \
+ { \
+ END_DEVICE_PATH_TYPE,\
+ END_ENTIRE_DEVICE_PATH_SUBTYPE,\
+ END_DEVICE_PATH_LENGTH,\
+ 0\
+ }
+
+VOID
+SetSOLCOMEnable(
+ IN BOOLEAN Enabled
+);
+
+EFI_STATUS
+AmtWrapperInit(
+ IN EFI_HANDLE ImageHandle,
+ IN OUT EFI_SYSTEM_TABLE *SystemTable
+);
+
+BOOLEAN
+AmtWrapperGet(
+ UINTN Index,
+ VOID *pVar
+);
+
+BOOLEAN
+AmtWrapperSet(
+ UINTN Index,
+ VOID *pVar
+);
+
+BOOLEAN
+ActiveManagementPauseBoot (
+ IN VOID
+);
+
+BOOLEAN
+ActiveManagementEnterSetup (
+ IN VOID
+);
+
+BOOLEAN
+ActiveManagementEnableSol (
+ IN VOID
+);
+
+BOOLEAN
+ActiveManagementEnableIdeR (
+ IN VOID
+);
+
+EFI_STATUS
+BdsAsfInitialization (
+ IN VOID
+);
+
+EFI_STATUS
+BdsBootViaAsf (
+ IN VOID
+);
+
+VOID
+InitAmtWrapperLib(
+ IN VOID
+);
+
+BOOLEAN
+AmtWrapperEnableKvm(
+ IN VOID
+);
+
+BOOLEAN
+AmtWrapperInitializationKvm(
+ IN VOID
+);
+
+BOOLEAN
+AmtWrapperEnableSol(
+ IN VOID
+);
+
+BOOLEAN
+AmtWrapperEnableIdeR(
+ IN VOID
+);
+
+BOOLEAN
+AmtWrapperPauseBoot(
+ IN VOID
+);
+
+BOOLEAN
+AmtWrapperEnterSetup(
+ IN VOID
+);
+
+EFI_STATUS
+AmtWrapperBdsBootViaAsf(
+ IN VOID
+);
+
+EFI_STATUS
+AmtWrapperReadyToBoot(
+ EFI_EVENT Event,
+ VOID *ParentImageHandle
+);
+
+BOOLEAN
+BdsKvmInitialization (
+ IN VOID
+);
+
+UINTN IsSOL(
+ IN EFI_HANDLE Controller
+);
+
+UINTN IsIDER(
+ IN EFI_HANDLE Controller
+);
+#endif
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//************************************************************************* \ No newline at end of file
diff --git a/Board/EM/MeWrapper/AmtWrapper/Dxe/AmtWrapperDxe.mak b/Board/EM/MeWrapper/AmtWrapper/Dxe/AmtWrapperDxe.mak
new file mode 100644
index 0000000..21f25ce
--- /dev/null
+++ b/Board/EM/MeWrapper/AmtWrapper/Dxe/AmtWrapperDxe.mak
@@ -0,0 +1,117 @@
+#*************************************************************************
+#*************************************************************************
+#** **
+#** (C)Copyright 1985-2010, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#*************************************************************************
+#*************************************************************************
+#**********************************************************************
+#
+# $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/AmtWrapperDxe.mak 2 2/23/12 8:58a Klzhan $
+#
+# $Revision: 2 $
+#
+# $Date: 2/23/12 8:58a $
+#
+#**********************************************************************
+# Revision History
+# ----------------
+# $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/AmtWrapperDxe.mak $
+#
+# 2 2/23/12 8:58a Klzhan
+# Support New EDK
+#
+# 1 2/08/12 1:08a Klzhan
+# Initial Check in
+#
+# 2 9/15/11 2:12a Klzhan
+# Remove AMI Lib.
+#
+# 1 2/25/11 1:43a Klzhan
+# Initial Check-in
+#
+# 1 12/03/10 5:10a Klzhan
+# Initial Check-in.
+#
+#
+#**********************************************************************
+#
+#<AMI_FHDR_START>
+#----------------------------------------------------------------------------
+#
+# Name: AmtWrapperDxe.mak
+#
+# Description: Makfile for Amt Wrapper Dxe module
+#
+#----------------------------------------------------------------------------
+#<AMI_FHDR_END>
+EDK : AmtWrapperDxe
+
+AmtWrapperDxe : $(BUILD_DIR)\AmtWrapperDxe.mak AmtWrapperDxeBin
+
+$(BUILD_DIR)\AmtWrapperDxe.mak : $(AmtWrapperDxe_DIR)\$(@B).cif $(AmtWrapperDxe_DIR)\$(@B).mak $(BUILD_RULES)
+ $(CIF2MAK) $(AmtWrapperDxe_DIR)\$(@B).cif $(CIF2MAK_DEFAULTS)
+
+AmtWrapperDxe_INCLUDES=\
+ $(EDK_INCLUDES)\
+ $(MISCFRAMEWORK_INCLUDES)\
+ $(ME_INCLUDES)\
+ $(INTEL_MCH_INCLUDES)\
+ $(INTEL_PCH_INCLUDES)\
+ $(IndustryStandard_INCLUDES)\
+ $(EdkIIGlueLib_INCLUDES)\
+ /IInclude\
+ $(NB_INCLUDES)
+
+
+AmtWrapperDxe_LIBS=\
+ $(EFISCRIPTLIB)\
+ $(EFIDRIVERLIB)\
+ $(EFICOMMONLIB)\
+ $(PRINTLIB)\
+ $(EDKFRAMEWORKPROTOCOLLIB)\
+ $(EFIGUIDLIB)\
+ $(AmtProtocolLib_LIB)\
+ $(AmtLibDxe_LIB)\
+ $(MeLibDxe_LIB)\
+ $(AmtGuidLib_LIB)\
+ $(EdkIIGlueDxeReportStatusCodeLib_LIB)\
+ $(EdkIIGlueDxeDebugLibReportStatusCode_LIB)\
+ $(EdkIIGlueBaseLib_LIB)\
+!IF "$(x64_BUILD)"=="1"
+ $(EdkIIGlueBaseLibX64_LIB)\
+!ELSE
+ $(EdkIIGlueBaseLibIA32_LIB)\
+!ENDIF
+ $(EdkIIGlueDxeServicesTableLib_LIB)\
+
+AmtWrapperDxeBin : $(AmtWrapperDxe_LIBS)
+ $(MAKE) /$(MAKEFLAGS) $(EDK_DEFAULTS)\
+ /f $(BUILD_DIR)\AmtWrapperDxe.mak all\
+ GUID=D77C900D-A1C7-41c5-B989-0C3D37FCA432\
+ "MY_INCLUDES=$(AmtWrapperDxe_INCLUDES)" \
+ ENTRY_POINT=AmtWrapperDxeEntryPoint\
+ DEPEX1=$(AmtWrapperDxe_DIR)\AmtWrapperDxe.dxs\
+ DEPEX1_TYPE=EFI_SECTION_DXE_DEPEX\
+ TYPE=BS_DRIVER\
+ COMPRESS=1
+
+#*************************************************************************
+#*************************************************************************
+#** **
+#** (C)Copyright 1985-2010, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#*************************************************************************
+#*************************************************************************
diff --git a/Board/EM/MeWrapper/AmtWrapper/Dxe/AmtWrapperDxe.sdl b/Board/EM/MeWrapper/AmtWrapper/Dxe/AmtWrapperDxe.sdl
new file mode 100644
index 0000000..cf027e3
--- /dev/null
+++ b/Board/EM/MeWrapper/AmtWrapper/Dxe/AmtWrapperDxe.sdl
@@ -0,0 +1,57 @@
+TOKEN
+ Name = "AmtWrapperDxe_SUPPORT"
+ Value = "1"
+ Help = "Main switch to enable AMT Wrapper DXE support in Project"
+ TokenType = Boolean
+ TargetEQU = Yes
+ TargetMAK = Yes
+ Master = Yes
+End
+
+PATH
+ Name = "AmtWrapperDxe_DIR"
+End
+
+MODULE
+ Help = "Includes AmtWrapperDxe.mak to Project"
+ File = "AmtWrapperDxe.mak"
+End
+
+ELINK
+ Name = "$(BUILD_DIR)\AmtWrapperDxe.ffs"
+ Parent = "FV_MAIN"
+ InvokeOrder = AfterParent
+End
+
+TOKEN
+ Name = "SREDIR_DISPLAY_MODE"
+ Value = "0"
+ Help = "0:Legacy Redirection by Setup Setting\1:Force Legacy Redirection to 80x24\2:Force Legacy Redirection to 80x25"
+ TokenType = Integer
+ TargetH = Yes
+ Range = "0 - 2"
+End
+
+ELINK
+ Name = "{0x8086,0x1C3A},"
+ Parent = "InvalidPciComDeviceList"
+ InvokeOrder = AfterParent
+End
+
+ELINK
+ Name = "{0x8086,0x1C3B},"
+ Parent = "InvalidPciComDeviceList"
+ InvokeOrder = AfterParent
+End
+
+ELINK
+ Name = "{0x8086,0x1E3A},"
+ Parent = "InvalidPciComDeviceList"
+ InvokeOrder = AfterParent
+End
+
+ELINK
+ Name = "{0x8086,0x1E3B},"
+ Parent = "InvalidPciComDeviceList"
+ InvokeOrder = AfterParent
+End \ No newline at end of file
diff --git a/Board/EM/MeWrapper/AmtWrapper/Dxe/AsfSupport.c b/Board/EM/MeWrapper/AmtWrapper/Dxe/AsfSupport.c
new file mode 100644
index 0000000..425a608
--- /dev/null
+++ b/Board/EM/MeWrapper/AmtWrapper/Dxe/AsfSupport.c
@@ -0,0 +1,1919 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+//**********************************************************************
+//
+// $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/AsfSupport.c 10 5/14/14 9:52p Tristinchou $
+//
+// $Revision: 10 $
+//
+// $Date: 5/14/14 9:52p $
+//
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/AsfSupport.c $
+//
+// 10 5/14/14 9:52p Tristinchou
+// [TAG] EIP167030
+// [Category] Improvement
+// [Description] Remove the variable runtime attribute and keep original
+// attributes.
+//
+// 9 1/08/14 10:23p Tristinchou
+// [TAG] EIP144445
+// [Category] Bug Fix
+// [Severity] Normal
+// [Symptom] AMT IDER Floppy failed on HSW ULT
+// [RootCause] IDER Device ID is different on HSW ULT
+// [Solution] Determine the bus, device and function number directly
+//
+// 8 9/24/13 4:22a Klzhan
+// [TAG] EIPNone
+// [Category] Improvement
+// [Description] Raise TPL is not needed
+//
+// 7 4/08/13 3:10a Klzhan
+// [TAG] EIPNone
+// [Category] Bug Fix
+// [Severity] Important
+// [Symptom] TC015 fail
+//
+// 6 3/01/13 4:38a Klzhan
+// [TAG] EIPNone
+// [Category] Improvement
+// [Description] Boot to legacy when UEFI boot fail.
+// Correct secure boot fail behavior
+//
+// 5 2/25/13 7:05a Klzhan
+// [TAG] EIP113605
+// [Category] Improvement
+// [Description] Support IDER Floppy BOOT.
+//
+// 4 10/30/12 8:30a Klzhan
+// Improvement : Boot to Legacy when EFI boot fail.
+// Improvement : Correct Secure IDER Boot.
+//
+// 3 8/14/12 7:26a Klzhan
+// Support UEFI IDER boot.
+//
+// 2 4/24/12 12:36a Klzhan
+// Update modulepart to latest
+//
+// 1 2/08/12 1:08a Klzhan
+// Initial Check in
+//
+// 3 7/08/11 4:20a Klzhan
+//
+// 2 6/16/11 4:56a Klzhan
+// Update IDER related code.
+//
+// 1 2/25/11 1:43a Klzhan
+// Initial Check-in
+//
+// 1 12/03/10 5:10a Klzhan
+// Initial Check-in.
+//
+//
+//**********************************************************************
+
+//<AMI_FHDR_START>
+//----------------------------------------------------------------------------
+//
+// Name: AsfSupport.c
+//
+// Description:
+//
+//----------------------------------------------------------------------------
+//<AMI_FHDR_END>
+/*++
+ This file contains an 'Intel Peripheral Driver' and is
+ licensed for Intel CPUs and chipsets under the terms of your
+ license agreement with Intel or your vendor. This file may
+ be modified by the user, subject to additional terms of the
+ license agreement
+--*/
+
+/*++
+
+Copyright (c) 2005-2008 Intel Corporation. All rights reserved
+This software and associated documentation (if any) is furnished
+under a license and may only be used or copied in accordance
+with the terms of the license. Except as permitted by such
+license, no part of this software or documentation may be
+reproduced, stored in a retrieval system, or transmitted in any
+form or by any means without the express written consent of
+Intel Corporation.
+
+
+Module Name:
+
+ AsfSupport.c
+
+Abstract:
+
+ Support routines for ASF boot options in the BDS
+
+--*/
+
+#include "AsfSupport.h"
+
+#pragma pack(push,1)
+
+typedef struct {
+ UINT32 Attributes;
+ UINT16 FilePathListLength;
+} EFI_LOAD_OPTION;
+#pragma pack(pop)
+
+//
+// Global variables
+//
+EFI_ASF_BOOT_OPTIONS *mAsfBootOptions;
+
+static EFI_DEVICE_PATH_PROTOCOL EndDevicePath[] = {
+ END_DEVICE_PATH_TYPE,
+ END_ENTIRE_DEVICE_PATH_SUBTYPE,
+ END_DEVICE_PATH_LENGTH,
+ 0
+};
+
+//
+// Legacy Device Order
+//
+typedef struct {
+ UINT32 Type;
+ UINT16 Length;
+ UINT16 Device[1];
+} LEGACY_DEVICE_ORDER;
+
+#define LEGACY_DEV_ORDER_GUID \
+ { \
+ 0xA56074DB, 0x65FE, 0x45F7, 0xBD, 0x21, 0x2D, 0x2B, 0xDD, 0x8E, 0x96, 0x52 \
+ }
+
+EFI_GUID gLegacyDeviceOrderGuid = LEGACY_DEV_ORDER_GUID;
+
+EFI_STATUS
+BdsAsfInitialization (
+ IN VOID
+ )
+/*++
+
+Routine Description:
+
+ Retrieve the ASF boot options previously recorded by the ASF driver.
+
+Arguments:
+
+ None.
+
+Returns:
+
+ Initialize Boot Options global variable and AMT protocol
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_ALERT_STANDARD_FORMAT_PROTOCOL *Asf;
+
+ mAsfBootOptions = NULL;
+
+ //
+ // Amt Library Init
+ //
+ Status = AmtLibInit ();
+ if (EFI_ERROR (Status)) {
+ DEBUG ((EFI_D_ERROR, "Info : Error init AmtLibInit -> %r\n", Status));
+ return Status;
+ }
+ //
+ // Get Protocol for ASF
+ //
+ Status = gBS->LocateProtocol (
+ &gEfiAlertStandardFormatProtocolGuid,
+ NULL,
+ &Asf
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((EFI_D_ERROR, "Info : Error gettings ASF protocol -> %r\n", Status));
+ return Status;
+ }
+
+ Status = Asf->GetBootOptions (Asf, &mAsfBootOptions);
+
+ return Status;
+}
+
+BDS_COMMON_OPTION *
+BdsCreateBootOption (
+ IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
+ IN CHAR16 *Description
+ )
+/*++
+
+Routine Description:
+
+ This function will create a BootOption from the give device path and
+ description string.
+
+Arguments:
+
+ DevicePath - The device path which the option represent
+ Description - The description of the boot option
+
+Returns:
+
+ BDS_COMMON_OPTION - A BDS_COMMON_OPTION pointer
+
+--*/
+{
+ BDS_COMMON_OPTION *Option;
+
+ Option = EfiLibAllocateZeroPool (sizeof (BDS_COMMON_OPTION));
+ if (Option == NULL) {
+ return NULL;
+ }
+
+ Option->Signature = BDS_LOAD_OPTION_SIGNATURE;
+ Option->DevicePath = EfiLibAllocateZeroPool (EfiDevicePathSize (DevicePath));
+ EfiCopyMem (Option->DevicePath, DevicePath, EfiDevicePathSize (DevicePath));
+
+ Option->Attribute = LOAD_OPTION_ACTIVE;
+ Option->Description = EfiLibAllocateZeroPool (EfiStrSize (Description));
+ EfiCopyMem (Option->Description, Description, EfiStrSize (Description));
+
+ return Option;
+}
+
+EFI_DEVICE_PATH_PROTOCOL *
+BdsCreateShellDevicePath (
+ VOID
+ )
+/*++
+
+Routine Description:
+
+ This function will create a SHELL BootOption to boot.
+
+Arguments:
+
+ None.
+
+Returns:
+
+ Shell Device path for booting.
+
+--*/
+{
+ UINTN FvHandleCount;
+ EFI_HANDLE *FvHandleBuffer;
+ UINTN Index;
+ EFI_STATUS Status;
+#if (PI_SPECIFICATION_VERSION < 0x00010000)
+ EFI_FIRMWARE_VOLUME_PROTOCOL *Fv;
+#else
+ EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
+#endif
+ EFI_FV_FILETYPE Type;
+ UINTN Size;
+ EFI_FV_FILE_ATTRIBUTES Attributes;
+ UINT32 AuthenticationStatus;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ MEDIA_FW_VOL_FILEPATH_DEVICE_PATH ShellNode;
+
+ DevicePath = NULL;
+ Status = EFI_SUCCESS;
+
+ gBS->LocateHandleBuffer (
+ ByProtocol,
+ #if (PI_SPECIFICATION_VERSION < 0x00010000)
+ &gEfiFirmwareVolumeProtocolGuid,
+ #else
+ &gEfiFirmwareVolume2ProtocolGuid,
+ #endif
+ NULL,
+ &FvHandleCount,
+ &FvHandleBuffer
+ );
+
+ for (Index = 0; Index < FvHandleCount; Index++) {
+ gBS->HandleProtocol (
+ FvHandleBuffer[Index],
+ #if (PI_SPECIFICATION_VERSION < 0x00010000)
+ &gEfiFirmwareVolumeProtocolGuid,
+ #else
+ &gEfiFirmwareVolume2ProtocolGuid,
+ #endif
+ (VOID **) &Fv
+ );
+
+ Status = Fv->ReadFile (
+ Fv,
+ &gEfiShellFileGuid,
+ NULL,
+ &Size,
+ &Type,
+ &Attributes,
+ &AuthenticationStatus
+ );
+ if (EFI_ERROR (Status)) {
+ //
+ // Skip if no shell file in the FV
+ //
+ continue;
+ } else {
+ //
+ // Found the shell
+ //
+ break;
+ }
+ }
+
+ if (EFI_ERROR (Status)) {
+ //
+ // No shell present
+ //
+ if (FvHandleCount) {
+ gBS->FreePool (FvHandleBuffer);
+ }
+
+ return NULL;
+ }
+ //
+ // Build the shell boot option
+ //
+ DevicePath = EfiDevicePathFromHandle (FvHandleBuffer[Index]);
+
+ //
+ // Build the shell device path
+ //
+ ShellNode.Header.Type = MEDIA_DEVICE_PATH;
+ ShellNode.Header.SubType = MEDIA_FV_FILEPATH_DP;
+ SetDevicePathNodeLength (&ShellNode.Header, sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH));
+ EfiCopyMem (&ShellNode.NameGuid, &gEfiShellFileGuid, sizeof (EFI_GUID));
+ DevicePath = EfiAppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &ShellNode);
+
+ if (FvHandleCount) {
+ gBS->FreePool (FvHandleBuffer);
+ }
+
+ return DevicePath;
+}
+
+static
+EFI_DEVICE_PATH_PROTOCOL *
+BdsCreatePxeDevicePath (
+ IN UINT16 DeviceIndex
+ )
+/*++
+
+Routine Description:
+
+ This function will create a PXE BootOption to boot.
+
+Arguments:
+
+ DeviceIndex - PXE handle index
+
+Returns:
+
+ PXE Device path for booting.
+
+--*/
+{
+ UINTN Index;
+ EFI_STATUS Status;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ UINTN NumberLoadFileHandles;
+ EFI_HANDLE *LoadFileHandles;
+ VOID *ProtocolInstance;
+
+ DevicePath = NULL;
+ Status = EFI_SUCCESS;
+
+ //
+ // We want everything connected up for PXE
+ //
+ BdsLibConnectAllDriversToAllControllers ();
+
+ //
+ // Parse Network Boot Device
+ //
+ gBS->LocateHandleBuffer (
+ ByProtocol,
+ &gEfiSimpleNetworkProtocolGuid,
+ NULL,
+ &NumberLoadFileHandles,
+ &LoadFileHandles
+ );
+ for (Index = 0; Index < NumberLoadFileHandles; Index++) {
+ Status = gBS->HandleProtocol (
+ LoadFileHandles[Index],
+ &gEfiLoadFileProtocolGuid,
+ (VOID **) &ProtocolInstance
+ );
+ if (EFI_ERROR (Status)) {
+ //
+ // try next handle
+ //
+ continue;
+ } else {
+ if (Index == DeviceIndex) {
+ //
+ // Found a PXE handle
+ //
+ break;
+ } else {
+ Status = EFI_UNSUPPORTED;
+ }
+ }
+ }
+
+ if (EFI_ERROR (Status)) {
+ //
+ // No PXE present
+ //
+ if (NumberLoadFileHandles) {
+ gBS->FreePool (LoadFileHandles);
+ }
+
+ return NULL;
+ }
+ //
+ // Build the PXE device path
+ //
+ DevicePath = EfiDevicePathFromHandle (LoadFileHandles[Index]);
+
+ if (NumberLoadFileHandles) {
+ gBS->FreePool (LoadFileHandles);
+ }
+
+ return DevicePath;
+}
+
+static
+VOID
+GetAmtBusDevFcnVal (
+ OUT UINT32 *Bus,
+ OUT UINT32 *Device,
+ OUT UINT32 *Function
+ )
+/*++
+
+Routine Description:
+
+ This function will get Bus, Device and Function.
+
+Arguments:
+
+ Bus - AMT Bus
+ Device - AMT Device
+ Function - AMT Function
+
+Returns:
+
+ None.
+
+--*/
+{
+ UINT32 Index;
+ EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;
+ UINT64 Address;
+ DATA32_UNION Data32Union;
+ EFI_STATUS Status;
+
+ *Bus = 0;
+ *Device = 0;
+ *Function = 0;
+
+ //
+ // Locate root bridge IO protocol
+ //
+ Status = gBS->LocateProtocol (&gEfiPciRootBridgeIoProtocolGuid, NULL, &PciRootBridgeIo);
+ ASSERT_EFI_ERROR (Status);
+
+ //
+ // Need to fill in IDER bus dev function so find this for Tekoa i82573E here.
+ //
+ for (Index = 0; Index < 0x255; Index++) {
+ Address = EFI_PCI_ADDRESS (
+ Index,
+ ME_DEVICE_NUMBER, //
+ IDER_FUNCTION_NUMBER, // fun 2 IDER capability
+ PCI_VENDOR_ID_OFFSET
+ );
+ Status = PciRootBridgeIo->Pci.Read (
+ PciRootBridgeIo,
+ EfiPciWidthUint32,
+ Address,
+ 1,
+ &Data32Union
+ );
+ if ((Data32Union.Data16[0] == V_ME_IDER_VENDOR_ID) &&
+ (Data32Union.Data16[1] == V_ME_IDER_DEVICE_ID)) {
+ //
+ // LOM i82573E is always Device 0 and function 2 so or this 8 bit value of 0x02
+ // into bus number discovered. Bus # upper byte and Dev-Fcn lower byte.
+ //
+ *Bus = Index;
+ *Device = ME_DEVICE_NUMBER;
+ *Function = IDER_FUNCTION_NUMBER;
+ break;
+ }
+ }
+}
+
+UINTN
+GetFirstIndexByType (
+ UINT16 DevType
+ )
+/*++
+
+Routine Description:
+
+ Boot HDD by BIOS Default Priority
+
+Arguments:
+
+ DevType - Boot device whose device type
+
+Returns:
+
+ None
+
+--*/
+{
+ EFI_STATUS Status;
+ UINTN LegacyDevOrderSize;
+ LEGACY_DEVICE_ORDER *LegacyDevOrder;
+ UINTN Index;
+ UINT8 *p;
+ UINTN o;
+
+ Index = 0;
+ o = 0;
+
+ LegacyDevOrderSize = 0;
+ LegacyDevOrder = NULL;
+
+ Status = gRT->GetVariable (
+ L"LegacyDevOrder",
+ &gLegacyDeviceOrderGuid,
+ NULL,
+ &LegacyDevOrderSize,
+ NULL
+ );
+
+ if (Status == EFI_BUFFER_TOO_SMALL) {
+ LegacyDevOrder = EfiLibAllocateZeroPool (LegacyDevOrderSize);
+ if (LegacyDevOrder != NULL) {
+ Status = gRT->GetVariable (
+ L"LegacyDevOrder",
+ &gLegacyDeviceOrderGuid,
+ NULL,
+ &LegacyDevOrderSize,
+ LegacyDevOrder
+ );
+ if (!EFI_ERROR (Status)) {
+ p = (UINT8 *) LegacyDevOrder;
+ o = 0;
+ for (o = 0; o < LegacyDevOrderSize; o += sizeof (LegacyDevOrder->Type) + LegacyDevOrder->Length) {
+ LegacyDevOrder = (LEGACY_DEVICE_ORDER *) (p + o);
+ if (LegacyDevOrder->Type == DevType) {
+ Index = LegacyDevOrder->Device[0];
+ }
+ }
+ }
+ }
+ }
+
+ return Index;
+}
+
+static
+EFI_STATUS
+RefreshBbsTableForBoot (
+ IN UINT16 DeviceIndex,
+ IN UINT16 DevType,
+ IN UINT16 BbsCount,
+ IN OUT BBS_TABLE *BbsTable
+ )
+/*++
+
+Routine Description:
+
+ Update the table with our required boot device
+
+Arguments:
+
+ DeviceIndex - Boot device whose device index
+ DevType - Boot device whose device type
+ BbsCount - Number of BBS_TABLE structures
+ BbsTable - BBS entry
+
+Returns:
+
+ EFI_STATUS
+
+--*/
+{
+ EFI_STATUS Status;
+ UINTN Index;
+ UINT16 BootDeviceIndex;
+ UINT16 TempIndex;
+
+ Status = EFI_NOT_FOUND;
+ TempIndex = 1;
+
+ BootDeviceIndex = DeviceIndex;
+
+ //
+ // Find the first present boot device whose device type
+ // matches the DevType, we use it to boot first. This is different
+ // from the other Bbs table refresh since we are looking for the device type
+ // index instead of the first device to match the device type.
+ //
+ // And set other present boot devices' priority to BBS_UNPRIORITIZED_ENTRY
+ // their priority will be set by LegacyBiosPlatform protocol by default
+ //
+ if (DeviceIndex > 0) {
+ for (Index = 0; Index < BbsCount; Index++) {
+ if (BbsTable[Index].BootPriority == BBS_IGNORE_ENTRY) {
+ continue;
+ }
+
+ BbsTable[Index].BootPriority = BBS_DO_NOT_BOOT_FROM;
+
+ if (BbsTable[Index].DeviceType == DevType) {
+ if (TempIndex++ == DeviceIndex) {
+ BbsTable[Index].BootPriority = 0;
+ Status = EFI_SUCCESS;
+ continue;
+ }
+ }
+ }
+ } else {
+ //
+ // Boot HDD by BIOS Default Priority
+ //
+ Index = GetFirstIndexByType (DevType);
+ BbsTable[Index].BootPriority = 0;
+ Status = EFI_SUCCESS;
+ }
+
+ return Status;
+}
+
+static
+EFI_STATUS
+RefreshBbsTableForIdeRBoot (
+ IN UINT16 DeviceIndex,
+ IN UINT16 DevType,
+ IN UINT16 BbsCount,
+ IN OUT BBS_TABLE *BbsTable
+ )
+/*++
+
+Routine Description:
+
+ Update the table with IdeR boot device
+
+Arguments:
+
+ DeviceIndex - Boot device whose device index
+ DevType - Boot device whose device type
+ BbsCount - Number of BBS_TABLE structures
+ BbsTable - BBS entry
+
+Returns:
+
+ EFI_STATUS
+
+--*/
+{
+ EFI_STATUS Status;
+ UINTN Index;
+ BOOLEAN IderDeviceFound;
+
+ Status = EFI_NOT_FOUND;
+
+ IderDeviceFound = FALSE;
+
+ //
+ // Find the first present boot device whose device type
+ // matches the DevType, we use it to boot first.
+ //
+ // And set other present boot devices' priority to BBS_DO_NOT_BOOT_FROM
+ // their priority will be set by LegacyBiosPlatform protocol by default
+ //
+ for (Index = 0; Index < BbsCount; Index++) {
+ if (BBS_IGNORE_ENTRY == BbsTable[Index].BootPriority) {
+ continue;
+ }
+
+ BbsTable[Index].BootPriority = BBS_DO_NOT_BOOT_FROM;
+
+ if ( (BbsTable[Index].Bus == ME_BUS) &&
+ (BbsTable[Index].Device == ME_DEVICE_NUMBER) &&
+ (BbsTable[Index].Function == IDER_FUNCTION_NUMBER) ) {
+ if (DeviceIndex == 0 && IderDeviceFound != TRUE) {
+ BbsTable[Index].BootPriority = 0;
+ IderDeviceFound = TRUE;
+ Status = EFI_SUCCESS;
+ } else {
+ DeviceIndex--;
+ }
+
+ continue;
+ }
+ }
+
+ return Status;
+}
+static
+EFI_DEVICE_PATH_PROTOCOL *
+BuildDevicePathFromBootOrder
+(
+ VOID
+)
+{
+ UINT8 BootMediaType = 0;
+ UINT8 BootMediaSubType = 0;
+ BOOLEAN IDERBoot = FALSE, IDERFloppy = FALSE;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath = NULL;
+ UINT16 *BootOrder;
+ EFI_LOAD_OPTION *BootOption;
+ UINTN BootOrderSize;
+ UINTN BootOptionSize;
+ CHAR16 BootVarName[9];
+ UINTN i;
+ EFI_STATUS Status;
+ EFI_DEVICE_PATH_PROTOCOL *Dp, *DevicePathNode;
+ EFI_DEVICE_PATH_PROTOCOL *DummyDp;
+ UINTN BufferSize = 0;
+ if (ActiveManagementEnableIdeR ()) {
+ //
+ // Check if any media exist in Ider device
+ //
+ if (BdsCheckIderMedia ()) {
+
+ // IDER Floppy
+ if(mAsfBootOptions->SpecialCommandParam == 1)
+ {
+ IDERFloppy = TRUE;
+ }
+
+ // IDER CD
+ if((mAsfBootOptions->SpecialCommandParam == 0x101) ||
+ (mAsfBootOptions->SpecialCommandParam == 0x103))
+ {
+ BootMediaType = MEDIA_DEVICE_PATH;
+ BootMediaSubType = MEDIA_CDROM_DP;
+ }
+ IDERBoot = TRUE;
+ }
+ }else
+ {
+ switch (mAsfBootOptions->SpecialCommand) {
+ case FORCE_PXE:
+ if (mAsfBootOptions->SpecialCommandParam != 0) {
+ //
+ // ASF spec says 0 currently only option
+ //
+ return NULL;
+ }
+ BootMediaType = MESSAGING_DEVICE_PATH;
+ BootMediaSubType = MSG_MAC_ADDR_DP;
+ break;
+
+ case FORCE_HARDDRIVE:
+ case FORCE_SAFEMODE:
+ BootMediaType = MEDIA_DEVICE_PATH;
+ BootMediaSubType = MEDIA_HARDDRIVE_DP;
+ break;
+
+ case FORCE_DIAGNOSTICS:
+ if (mAsfBootOptions->SpecialCommandParam != 0) {
+ //
+ // ASF spec says 0 currently only option
+ //
+ return NULL;
+ }
+
+ DevicePath = BdsCreateShellDevicePath ();
+
+ //
+ // We want everything connected up for shell
+ //
+ BdsLibConnectAllDriversToAllControllers ();
+ break;
+
+ case FORCE_CDDVD:
+ BootMediaType = MEDIA_DEVICE_PATH;
+ BootMediaSubType = MEDIA_CDROM_DP;
+ break;
+
+ default:
+ return NULL;
+ break;
+ }
+ }//else IDER check
+ // Get Device Path from BootXXXX
+ BootOrder = NULL;
+ BootOption = NULL;
+ BootOrderSize = 0;
+
+ Status = gRT->GetVariable(
+ L"BootOrder",
+ &gEfiGlobalVariableGuid,
+ NULL,
+ &BootOrderSize,
+ NULL
+ );
+
+ if (Status == EFI_BUFFER_TOO_SMALL)
+ {
+ BootOrder = EfiLibAllocateZeroPool(BootOrderSize);
+ if (BootOrder != NULL)
+ {
+ Status = gRT->GetVariable(
+ L"BootOrder",
+ &gEfiGlobalVariableGuid,
+ NULL,
+ &BootOrderSize,
+ BootOrder
+ );
+ if (!EFI_ERROR(Status))
+ {
+ for (i=0; i<BootOrderSize/sizeof(UINT16); i++)
+ {
+ SPrint(BootVarName, sizeof(BootVarName), L"Boot%04x", BootOrder[i] );
+ BootOptionSize = 0;
+ Status = gRT->GetVariable(
+ BootVarName,
+ &gEfiGlobalVariableGuid,
+ NULL,
+ &BootOptionSize,
+ NULL
+ );
+ if (Status == EFI_BUFFER_TOO_SMALL)
+ {
+ BootOption = EfiLibAllocateZeroPool(BootOptionSize);
+ if (BootOption != NULL)
+ {
+ Status = gRT->GetVariable(
+ BootVarName,
+ &gEfiGlobalVariableGuid,
+ NULL,
+ &BootOptionSize,
+ BootOption);
+ if (!EFI_ERROR(Status))
+ {
+ Dp = (EFI_DEVICE_PATH_PROTOCOL *) (
+ //
+ // skip the header
+ //
+ (UINT8 *) (BootOption + 1)
+ //
+ // skip the string
+ //
+ + (EfiStrLen ((CHAR16 *) (BootOption + 1)) + 1) * sizeof (CHAR16));
+ DevicePathNode = Dp;
+ while (!EfiIsDevicePathEnd (DevicePathNode))
+ {
+ // Skip USB device
+ /*
+ if((DevicePathNode->Type == MESSAGING_DEVICE_PATH) &&
+ (DevicePathNode->SubType == MSG_USB_DP))
+ break;
+ */
+
+ if( IDERBoot &&
+ (DevicePathNode->Type == MESSAGING_DEVICE_PATH) &&
+ (DevicePathNode->SubType == MSG_SATA_DP))
+ break;
+
+ // Do something special for IDER Floppy,
+ // In AMT commander tool, If redirect to Floppy and CD image
+ // The device path are almost the same
+ if(IDERFloppy &&
+ (DevicePathNode->Type == MESSAGING_DEVICE_PATH) &&
+ (DevicePathNode->SubType == MSG_ATAPI_DP))
+ {
+ EFI_DEVICE_PATH_PROTOCOL *tDP =
+ EfiNextDevicePathNode (DevicePathNode);
+ // IDER CD image has Next Device Path Node, but Floppy doesn't
+ if(EfiIsDevicePathEnd (tDP))
+ {
+ // Correct Pointer of DP, Fix freepool hang issue
+ BufferSize =
+ (UINTN)((UINTN *)BootOptionSize -
+ ((UINTN *)Dp -
+ (UINTN *)BootOption))/sizeof(UINT8);
+
+ Status = gBS->AllocatePool(
+ EfiBootServicesData, BufferSize, &DummyDp );
+
+ if(!EFI_ERROR(Status))
+ {
+ gBS->CopyMem(
+ (VOID*)DummyDp, (VOID*)Dp, BufferSize );
+ }
+ else
+ {
+ Status = gBS->FreePool(BootOption);
+ Status = gBS->FreePool(BootOrder);
+ return NULL;
+ }
+ Status = gBS->FreePool(BootOption);
+ Status = gBS->FreePool(BootOrder);
+ return DummyDp;
+ }
+ break;
+ }
+ if((DevicePathNode->Type == BootMediaType) &&
+ (DevicePathNode->SubType == BootMediaSubType))
+ {
+ // Correct Pointer of DP, Fix freepool hang issue
+ BufferSize =
+ (UINTN)((UINTN *)BootOptionSize -
+ ((UINTN *)Dp -
+ (UINTN *)BootOption))/sizeof(UINT8);
+
+ Status = gBS->AllocatePool(
+ EfiBootServicesData, BufferSize, &DummyDp );
+
+ if(!EFI_ERROR(Status))
+ {
+ gBS->CopyMem(
+ (VOID*)DummyDp, (VOID*)Dp, BufferSize );
+ }
+ else
+ {
+ Status = gBS->FreePool(BootOption);
+ Status = gBS->FreePool(BootOrder);
+ return NULL;
+
+ }
+ Status = gBS->FreePool(BootOption);
+ Status = gBS->FreePool(BootOrder);
+ return DummyDp;
+ }
+
+ DevicePathNode = EfiNextDevicePathNode (DevicePathNode);
+ }
+ }
+ gBS->FreePool (BootOption);
+ }
+ }
+ }
+ }
+ gBS->FreePool (BootOrder);
+ }
+ }
+
+ return DevicePath;
+}
+static
+EFI_DEVICE_PATH_PROTOCOL *
+BdsCreateLegacyBootDevicePath (
+ IN UINT16 DeviceType,
+ IN UINT16 DeviceIndex,
+ IN BOOLEAN IdeRBoot
+ )
+/*++
+
+Routine Description:
+
+ Build the BBS Device Path for this boot selection
+
+Arguments:
+
+ DeviceType - Boot device whose device type
+ DeviceIndex - Boot device whose device index
+ IdeRBoot - If IdeRBoot is TRUE then check Ider device
+
+Returns:
+
+ EFI_STATUS
+
+--*/
+{
+ EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;
+ BBS_BBS_DEVICE_PATH BbsDevicePathNode;
+ BBS_TABLE *BbsTable;
+ UINT16 HddCount;
+ UINT16 BbsCount;
+ HDD_INFO *LocalHddInfo;
+ UINT16 Index;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ EFI_STATUS Status;
+
+ HddCount = 0;
+ BbsCount = 0;
+ LocalHddInfo = NULL;
+
+ Index = DeviceIndex;
+
+ //
+ // Make sure the Legacy Boot Protocol is available
+ //
+ Status = gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, &LegacyBios);
+ if (EFI_ERROR (Status)) {
+ return NULL;
+ }
+ //
+ // Get BBS table instance
+ //
+ Status = LegacyBios->GetBbsInfo (
+ LegacyBios,
+ &HddCount,
+ &LocalHddInfo,
+ &BbsCount,
+ &BbsTable
+ );
+ if (EFI_ERROR (Status)) {
+ return NULL;
+ }
+ //
+ // For debug
+ //
+ PrintBbsTable (BbsTable);
+
+ //
+ // Update the table with our required boot device
+ //
+ if (IdeRBoot) {
+ Status = RefreshBbsTableForIdeRBoot (
+ Index,
+ DeviceType,
+ BbsCount,
+ BbsTable
+ );
+ } else {
+ Status = RefreshBbsTableForBoot (
+ Index,
+ DeviceType,
+ BbsCount,
+ BbsTable
+ );
+ }
+ //
+ // For debug
+ //
+ PrintBbsTable (BbsTable);
+
+ if (EFI_ERROR (Status)) {
+ //
+ // Device not found - do normal boot
+ //
+ gST->ConOut->OutputString (
+ gST->ConOut,
+ L"Can't Find Boot Device by Boot Option !!\r\n"
+ );
+ while(1);
+ return NULL;
+ }
+ //
+ // Build the BBS Device Path for this boot selection
+ //
+ DevicePath = EfiLibAllocateZeroPool (sizeof (EFI_DEVICE_PATH_PROTOCOL));
+ if (DevicePath == NULL) {
+ return NULL;
+ }
+
+ BbsDevicePathNode.Header.Type = BBS_DEVICE_PATH;
+ BbsDevicePathNode.Header.SubType = BBS_BBS_DP;
+ SetDevicePathNodeLength (&BbsDevicePathNode.Header, sizeof (BBS_BBS_DEVICE_PATH));
+ BbsDevicePathNode.DeviceType = DeviceType;
+ BbsDevicePathNode.StatusFlag = 0;
+ BbsDevicePathNode.String[0] = 0;
+
+ DevicePath = EfiAppendDevicePathNode (
+ EndDevicePath,
+ (EFI_DEVICE_PATH_PROTOCOL *) &BbsDevicePathNode
+ );
+ if (NULL == DevicePath) {
+ return NULL;
+ }
+
+ return DevicePath;
+}
+
+EFI_STATUS
+AsfDoLegacyBoot (
+ IN BDS_COMMON_OPTION *Option
+ )
+/*++
+
+Routine Description:
+
+ Boot the legacy system with the boot option
+
+Arguments:
+
+ Option - The legacy boot option which have BBS device path
+
+Returns:
+
+ EFI_UNSUPPORTED - There is no legacybios protocol, do not support
+ legacy boot.
+
+ EFI_STATUS - Return the status of LegacyBios->LegacyBoot ().
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;
+
+ Status = gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, &LegacyBios);
+ if (EFI_ERROR (Status)) {
+ //
+ // If no LegacyBios protocol we do not support legacy boot
+ //
+ return EFI_UNSUPPORTED;
+ }
+ //
+ // Write boot to OS performance data to a file
+ //
+ WRITE_BOOT_TO_OS_PERFORMANCE_DATA;
+
+ DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Legacy Boot: %S\n", Option->Description));
+ return LegacyBios->LegacyBoot (
+ LegacyBios,
+ (BBS_BBS_DEVICE_PATH *) Option->DevicePath,
+ Option->LoadOptionsSize,
+ Option->LoadOptions
+ );
+}
+
+BOOLEAN CompareDP(
+ EFI_DEVICE_PATH_PROTOCOL *dp1,
+ EFI_DEVICE_PATH_PROTOCOL *dp2
+ )
+{
+ UINTN s1,s2;
+ BOOLEAN st = FALSE;
+
+ s1 = EfiDevicePathSize(dp1);
+
+ s2 = EfiDevicePathSize(dp2);
+
+ if (s1 == s2) {
+ if (EfiCompareMem(dp1, dp2, s1) == 0)
+ st = TRUE;
+ }
+
+ return st;
+}
+
+
+UINT16 GetBootCurrent(
+ IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
+)
+{
+ UINT16 *BootOrder;
+ EFI_LOAD_OPTION *BootOption;
+ UINTN BootOrderSize; //size of BootOrder Variable
+ UINTN BootOptionSize;
+ CHAR16 BootVarName[9];
+ UINTN i;
+ EFI_STATUS Status;
+ BOOLEAN st;
+ UINT16 BootCurrent;
+ EFI_DEVICE_PATH_PROTOCOL *Dp;
+
+ BootOrder = NULL;
+ BootOption = NULL;
+ BootCurrent = 0;
+ BootOrderSize = 0;
+
+ Status = gRT->GetVariable(
+ L"BootOrder",
+ &gEfiGlobalVariableGuid,
+ NULL,
+ &BootOrderSize,
+ NULL
+ );
+
+ if (Status == EFI_BUFFER_TOO_SMALL) {
+ BootOrder = EfiLibAllocateZeroPool(BootOrderSize);
+ if (BootOrder != NULL){
+ Status = gRT->GetVariable(
+ L"BootOrder",
+ &gEfiGlobalVariableGuid,
+ NULL,
+ &BootOrderSize,
+ BootOrder
+ );
+ if (!EFI_ERROR(Status)) {
+ for (i=0; i<BootOrderSize/sizeof(UINT16); i++){
+ SPrint(BootVarName, sizeof(BootVarName), L"Boot%04x", BootOrder[i] );
+ BootOptionSize = 0;
+ Status = gRT->GetVariable(
+ BootVarName,
+ &gEfiGlobalVariableGuid,
+ NULL,
+ &BootOptionSize,
+ NULL
+ );
+ if (Status == EFI_BUFFER_TOO_SMALL) {
+ BootOption = EfiLibAllocateZeroPool(BootOptionSize);
+ if (BootOption != NULL){
+ Status = gRT->GetVariable(
+ BootVarName,
+ &gEfiGlobalVariableGuid,
+ NULL,
+ &BootOptionSize,
+ BootOption
+ );
+ if (!EFI_ERROR(Status)) {
+ Dp = (EFI_DEVICE_PATH_PROTOCOL*)
+ ( //skip the header
+ (UINT8*)(BootOption+1)
+ //skip the string
+ +(EfiStrLen((CHAR16*)(BootOption+1))+1)*sizeof(CHAR16)
+ );
+ st = CompareDP(Dp, DevicePath);
+ if (st == TRUE) {
+ BootCurrent = BootOrder[i];
+ }
+ }
+ gBS->FreePool(BootOption);
+ }
+ }
+ }
+ }
+ gBS->FreePool(BootOrder);
+ }
+ }
+ return BootCurrent;
+}
+
+EFI_STATUS
+AsfBootViaBootOption (
+ IN BDS_COMMON_OPTION * Option,
+ IN EFI_DEVICE_PATH_PROTOCOL * DevicePath,
+ OUT UINTN *ExitDataSize,
+ OUT CHAR16 **ExitData OPTIONAL
+ )
+/*++
+
+Routine Description:
+
+ Process the boot option follow the EFI 1.1 specification and
+ special treat the legacy boot option with BBS_DEVICE_PATH.
+
+Arguments:
+
+ Option - The boot option need to be processed
+ DevicePath - The device path which describe where to load
+ the boot image or the legcy BBS device path
+ to boot the legacy OS
+ ExitDataSize - Returned directly from gBS->StartImage ()
+ ExitData - Returned directly from gBS->StartImage ()
+
+Returns:
+
+ EFI_SUCCESS - Status from gBS->StartImage (),
+ or BdsBootByDiskSignatureAndPartition ()
+ EFI_NOT_FOUND - If the Device Path is not found in the system
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_HANDLE Handle;
+ EFI_HANDLE ImageHandle;
+ EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL *FilePath;
+ EFI_LOADED_IMAGE_PROTOCOL *ImageInfo;
+ EFI_EVENT ReadyToBootEvent;
+ EFI_ACPI_S3_SAVE_PROTOCOL *AcpiS3Save;
+ UINT32 VarAttr;
+ UINTN VarSize;
+
+ *ExitDataSize = 0;
+ *ExitData = NULL;
+
+ //
+ // Notes: put EFI64 ROM Shadow Solution
+ //
+ EFI64_SHADOW_ALL_LEGACY_ROM ();
+
+ //
+ // Notes: this code can be remove after the s3 script table
+ // hook on the event EFI_EVENT_SIGNAL_READY_TO_BOOT or
+ // EFI_EVENT_SIGNAL_LEGACY_BOOT
+ //
+ Status = gBS->LocateProtocol (&gEfiAcpiS3SaveGuid, NULL, &AcpiS3Save);
+ if (!EFI_ERROR (Status)) {
+ AcpiS3Save->S3Save (AcpiS3Save, NULL);
+ }
+ //
+ // If it's Device Path that starts with a hard drive path,
+ // this routine will do the booting.
+ //
+ Status = BdsBootByDiskSignatureAndPartition (
+ Option,
+ (HARDDRIVE_DEVICE_PATH *) DevicePath,
+ Option->LoadOptionsSize,
+ Option->LoadOptions,
+ ExitDataSize,
+ ExitData
+ );
+ if (!EFI_ERROR (Status)) {
+ //
+ // If we found a disk signature and partition device path return success
+ //
+ return EFI_SUCCESS;
+ }
+ //
+ // Signal the EFI_EVENT_SIGNAL_READY_TO_BOOT event
+ //
+
+
+ Option->BootCurrent = GetBootCurrent(DevicePath);
+
+ //
+ // Get Variable Attribute
+ //
+ VarAttr = 0;
+ VarSize = 0;
+ Status = gRT->GetVariable(
+ L"BootCurrent",
+ &gEfiGlobalVariableGuid,
+ &VarAttr,
+ &VarSize,
+ NULL );
+ if( Status != EFI_BUFFER_TOO_SMALL )
+ {
+ VarAttr = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS;
+ VarSize = sizeof(UINT16);
+ }
+
+ //
+ // Set Boot Current
+ //
+ gRT->SetVariable(
+ L"BootCurrent",
+ &gEfiGlobalVariableGuid,
+ VarAttr,
+ VarSize,
+ &Option->BootCurrent );
+
+ //
+ // Abstract: Modified for EFI 2.0 required
+ //
+#if defined(EFI_EVENT_SIGNAL_READY_TO_BOOT) && EFI_SPECIFICATION_VERSION < 0x20000
+ Status = gBS->CreateEvent (
+ EFI_EVENT_SIGNAL_READY_TO_BOOT | EFI_EVENT_NOTIFY_SIGNAL_ALL,
+ EFI_TPL_CALLBACK,
+ NULL,
+ NULL,
+ &ReadyToBootEvent
+ );
+#else
+ Status = EfiCreateEventReadyToBoot (
+ EFI_TPL_CALLBACK,
+ NULL,
+ NULL,
+ &ReadyToBootEvent
+ );
+#endif
+ if (!EFI_ERROR (Status)) {
+ gBS->SignalEvent (ReadyToBootEvent);
+ gBS->CloseEvent (ReadyToBootEvent);
+ }
+
+ if ((DevicePathType (Option->DevicePath) == BBS_DEVICE_PATH) &&
+ (DevicePathSubType (Option->DevicePath) == BBS_BBS_DP)
+ ) {
+ //
+ // Check to see if we should legacy BOOT. If yes then do the legacy boot
+ //
+ return AsfDoLegacyBoot (Option);
+ }
+
+ DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Booting EFI 1.1 way %S\n", Option->Description));
+
+ Status = gBS->LoadImage (
+ TRUE,
+ mBdsImageHandle,
+ DevicePath,
+ NULL,
+ 0,
+ &ImageHandle
+ );
+
+ //
+ // If we didn't find an image, we may need to load the default
+ // boot behavior for the device.
+ //
+ if (EFI_ERROR (Status)) {
+ //
+ // Find a Simple File System protocol on the device path. If the remaining
+ // device path is set to end then no Files are being specified, so try
+ // the removable media file name.
+ //
+ TempDevicePath = DevicePath;
+ Status = gBS->LocateDevicePath (
+ &gEfiSimpleFileSystemProtocolGuid,
+ &TempDevicePath,
+ &Handle
+ );
+ if (!EFI_ERROR (Status) && IsDevicePathEnd (TempDevicePath)) {
+ FilePath = EfiFileDevicePath (Handle, DEFAULT_REMOVABLE_FILE_NAME);
+ if (FilePath) {
+ Status = gBS->LoadImage (
+ TRUE,
+ mBdsImageHandle,
+ FilePath,
+ NULL,
+ 0,
+ &ImageHandle
+ );
+ if (EFI_ERROR (Status)) {
+ // System Halt when IDER boot fail !!
+ if(ActiveManagementEnableIdeR () && ((Status == EFI_SECURITY_VIOLATION) || (Status == EFI_ACCESS_DENIED)))
+ {
+ gST->ConOut->OutputString (
+ gST->ConOut,
+ L"IDER Boot Fail, system halt !! \r\n");
+
+ while(1);
+ }
+ //
+ // The DevicePath failed, and it's not a valid
+ // removable media device.
+ //
+ goto Done;
+ }
+ }
+ } else {
+ Status = EFI_NOT_FOUND;
+ }
+ }
+
+ if (EFI_ERROR (Status)) {
+ //
+ // It there is any error from the Boot attempt exit now.
+ //
+ goto Done;
+ }
+ //
+ // Provide the image with it's load options
+ //
+ Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, &ImageInfo);
+ ASSERT_EFI_ERROR (Status);
+
+ if (Option->LoadOptionsSize != 0) {
+ ImageInfo->LoadOptionsSize = Option->LoadOptionsSize;
+ ImageInfo->LoadOptions = Option->LoadOptions;
+ }
+ //
+ // Before calling the image, enable the Watchdog Timer for
+ // the 5 Minute period
+ //
+ gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL);
+
+ Status = gBS->StartImage (ImageHandle, ExitDataSize, ExitData);
+ DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Image Return Status = %r\n", Status));
+ // System Halt when IDER boot fail !!
+ if(ActiveManagementEnableIdeR ())
+ {
+ gST->ConOut->OutputString (
+ gST->ConOut,
+ L"IDER Boot Fail, system halt !! \r\n");
+
+ while(1);
+ }
+
+ //
+ // Clear the Watchdog Timer after the image returns
+ //
+ gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL);
+
+Done:
+ //
+ // Clear Boot Current
+ //
+ gRT->SetVariable(
+ L"BootCurrent",
+ &gEfiGlobalVariableGuid,
+ VarAttr,
+ 0,
+ &Option->BootCurrent );
+
+ return Status;
+}
+
+EFI_STATUS
+BdsAsfBoot (
+ OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
+ )
+/*++
+
+Routine Description:
+
+ Found out ASF boot options.
+
+Arguments:
+
+ DevicePath - The device path which describe where to load
+ the boot image or the legcy BBS device path
+ to boot the legacy OS
+
+Returns:
+
+ EFI_STATUS
+
+--*/
+{
+ BOOLEAN EfiBoot;
+
+ EfiBoot = FALSE;
+
+ //
+ // First we check ASF boot options Special Command
+ //
+ switch (mAsfBootOptions->SpecialCommand) {
+ //
+ // No additional special command is included; the Special Command Parameter has no
+ // meaning.
+ //
+ case NOP:
+ break;
+
+ //
+ // The Special Command Parameter can be used to specify a PXE
+ // parameter. When the parameter value is 0, the system default PXE device is booted. All
+ // other values for the PXE parameter are reserved for future definition by this specification.
+ //
+ case FORCE_PXE:
+ if (mAsfBootOptions->SpecialCommandParam != 0) {
+ //
+ // ASF spec says 0 currently only option
+ //
+ return EFI_UNSUPPORTED;
+ }
+
+ if (EfiBoot == TRUE) {
+ *DevicePath = BdsCreatePxeDevicePath (mAsfBootOptions->SpecialCommandParam);
+ } else {
+ *DevicePath = BdsCreateLegacyBootDevicePath (BBS_EMBED_NETWORK, mAsfBootOptions->SpecialCommandParam, FALSE);
+ }
+ break;
+
+ //
+ // The Special Command Parameter identifies the boot-media index for
+ // the managed client. When the parameter value is 0, the default hard-drive is booted, when the
+ // parameter value is 1, the primary hard-drive is booted; when the value is 2, the secondary
+ // hard-drive is booted ¡V and so on.
+ //
+ case FORCE_HARDDRIVE:
+ //
+ // The Special Command Parameter identifies the boot-media
+ // index for the managed client. When the parameter value is 0, the default hard-drive is
+ // booted, when the parameter value is 1, the primary hard-drive is booted; when the value is 2,
+ // the secondary hard-drive is booted ¡V and so on.
+ //
+ case FORCE_SAFEMODE:
+ *DevicePath = BdsCreateLegacyBootDevicePath (BBS_TYPE_HARDDRIVE, mAsfBootOptions->SpecialCommandParam, FALSE);
+ break;
+
+ //
+ // The Special Command Parameter can be used to specify a
+ // diagnostic parameter. When the parameter value is 0, the default diagnostic media is booted.
+ // All other values for the diagnostic parameter are reserved for future definition by this
+ // specification.
+ //
+ case FORCE_DIAGNOSTICS:
+ if (mAsfBootOptions->SpecialCommandParam != 0) {
+ //
+ // ASF spec says 0 currently only option
+ //
+ return EFI_UNSUPPORTED;
+ }
+
+ *DevicePath = BdsCreateShellDevicePath ();
+
+ //
+ // We want everything connected up for shell
+ //
+ BdsLibConnectAllDriversToAllControllers ();
+ break;
+
+ //
+ // The Special Command Parameter identifies the boot-media index for
+ // the managed client. When the parameter value is 0, the default CD/DVD is booted, when the
+ // parameter value is 1, the primary CD/DVD is booted; when the value is 2, the secondary
+ // CD/DVD is booted ¡V and so on.
+ //
+ case FORCE_CDDVD:
+ *DevicePath = BdsCreateLegacyBootDevicePath (BBS_TYPE_CDROM, mAsfBootOptions->SpecialCommandParam, FALSE);
+ break;
+
+ default:
+ return EFI_UNSUPPORTED;
+ break;
+ }
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+BdsAmtBoot (
+ OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
+ )
+/*++
+
+Routine Description:
+
+ Check IdeR boot device and Asf boot device
+
+Arguments:
+
+ DevicePath - The device path which describe where to load
+ the boot image or the legcy BBS device path
+ to boot the legacy OS
+
+Returns:
+
+ EFI_STATUS
+
+--*/
+{
+ EFI_STATUS Status;
+
+ //
+ // OEM command values; the interpretation of the Special Command and associated Special
+ // Command Parameters is defined by the entity associated with the Enterprise ID.
+ //
+ if (ActiveManagementEnableIdeR ()) {
+ //
+ // Check if any media exist in Ider device
+ //
+ if (BdsCheckIderMedia ()) {
+ *DevicePath = BdsCreateLegacyBootDevicePath (
+ BBS_TYPE_CDROM,
+ (mAsfBootOptions->SpecialCommandParam & IDER_BOOT_DEVICE_MASK) >> IDER_BOOT_DEVICE_SHIFT,
+ TRUE
+ );
+ }
+
+ Status = EFI_SUCCESS;
+ } else {
+ Status = BdsAsfBoot (DevicePath);
+ }
+
+ return Status;
+}
+
+EFI_STATUS
+BdsBootViaAsf (
+ IN VOID
+ )
+/*++
+
+Routine Description:
+
+ Process ASF boot options and if available, attempt the boot
+
+Arguments:
+
+ None.
+
+Returns:
+
+ EFI_SUCCESS - The command completed successfully
+ Other - Error!!
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ BDS_COMMON_OPTION *BootOption;
+ UINTN ExitDataSize;
+ CHAR16 *ExitData;
+
+ Status = EFI_SUCCESS;
+ DevicePath = NULL;
+
+ //
+ // Check if ASF Boot Options is present.
+ //
+ if (mAsfBootOptions->SubCommand != ASF_BOOT_OPTIONS_PRESENT) {
+ return EFI_NOT_FOUND;
+ }
+
+ DevicePath = BuildDevicePathFromBootOrder();
+
+ if(DevicePath != NULL)
+ {
+
+ BootOption = BdsCreateBootOption (DevicePath, L"ASF Boot");
+ if (BootOption != NULL) {
+ Status = AsfBootViaBootOption (BootOption, BootOption->DevicePath, &ExitDataSize, &ExitData);
+ if (EFI_ERROR (Status)) {
+ gBS->FreePool (BootOption);
+ }
+
+ gBS->FreePool (DevicePath);
+ }
+ }
+ // UEFI BOOT fail, try Legacy Boot
+ switch (mAsfBootOptions->IanaId)
+ {
+ case ASF_INTEL_CONVERTED_IANA:
+ Status = BdsAmtBoot (&DevicePath);
+ break;
+
+ case ASF_INDUSTRY_CONVERTED_IANA:
+ Status = BdsAsfBoot (&DevicePath);
+ break;
+ }
+ //
+ // If device path was set, the we have a boot option to use
+ //
+ if (DevicePath == NULL) {
+ return EFI_UNSUPPORTED;
+ }
+
+ BootOption = BdsCreateBootOption (DevicePath, L"ASF Boot");
+ if (BootOption == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ Status = AsfBootViaBootOption (BootOption, BootOption->DevicePath, &ExitDataSize, &ExitData);
+ if (EFI_ERROR (Status)) {
+ gBS->FreePool (BootOption);
+ }
+
+ gBS->FreePool (DevicePath);
+
+ return Status;
+}
+
+BOOLEAN
+BdsCheckIderMedia (
+ IN VOID
+ )
+/*++
+
+Routine Description:
+ This will return if Media in IDE-R is present.
+
+Arguments:
+ None.
+
+Returns:
+ True Media is present.
+ False Media is not present.
+
+--*/
+{
+ UINTN HandleNum;
+ EFI_HANDLE *HandleBuf;
+ EFI_HANDLE Handle;
+ EFI_STATUS Status;
+ EFI_DEVICE_PATH_PROTOCOL *DPath;
+ UINTN Index;
+ UINTN EventIndex;
+ EFI_INPUT_KEY Key;
+ EFI_BLOCK_IO_PROTOCOL *BlkIo;
+ EFI_DISK_INFO_PROTOCOL *DiskInfo;
+ EFI_BLOCK_IO_MEDIA *BlkMedia;
+ VOID *Buffer;
+ UINT8 IdeBootDevice;
+ UINT32 IdeChannel;
+ UINT32 IdeDevice;
+
+ IdeBootDevice = ActiveManagementIderBootDeviceGet ();
+
+ DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Ide Channel Device Index = %d\n", IdeBootDevice));
+
+ //
+ // Make sure the Legacy Boot Protocol is available
+ //
+ Status = gBS->LocateHandleBuffer (
+ ByProtocol,
+ &gEfiBlockIoProtocolGuid,
+ NULL,
+ &HandleNum,
+ &HandleBuf
+ );
+ if (EFI_ERROR (Status)) {
+ return FALSE;
+ }
+
+ for (Index = 0; Index < HandleNum; Index++) {
+ Status = gBS->HandleProtocol (
+ HandleBuf[Index],
+ &gEfiDevicePathProtocolGuid,
+ &DPath
+ );
+ if (!EFI_ERROR (Status)) {
+ Status = gBS->LocateDevicePath (
+ &gEfiIderControllerDriverProtocolGuid,
+ &DPath,
+ &Handle
+ );
+ if (!EFI_ERROR (Status)) {
+ Status = gBS->HandleProtocol (
+ HandleBuf[Index],
+ &gEfiBlockIoProtocolGuid,
+ &BlkIo
+ );
+
+ Status = gBS->HandleProtocol (
+ HandleBuf[Index],
+ &gEfiDiskInfoProtocolGuid,
+ &DiskInfo
+ );
+
+ DiskInfo->WhichIde (DiskInfo, &IdeChannel, &IdeDevice);
+
+ if (IdeBootDevice != (UINT8) (IdeChannel * 2 + IdeDevice)) {
+ continue;
+ }
+
+ if (BlkIo->Media->MediaPresent) {
+ if (HandleBuf != NULL) {
+ gBS->FreePool (HandleBuf);
+ }
+ return TRUE;
+ } else {
+ while (TRUE) {
+ BlkMedia = BlkIo->Media;
+ Buffer = EfiLibAllocatePool (BlkMedia->BlockSize);
+ if (Buffer) {
+ BlkIo->ReadBlocks (
+ BlkIo,
+ BlkMedia->MediaId,
+ 0,
+ BlkMedia->BlockSize,
+ Buffer
+ );
+ gBS->FreePool (Buffer);
+ }
+
+ if (BlkMedia->MediaPresent) {
+ if (HandleBuf != NULL) {
+ gBS->FreePool (HandleBuf);
+ }
+ return TRUE;
+ }
+
+ gST->ConOut->OutputString (
+ gST->ConOut,
+ L"Boot disk missing, please insert boot disk and press ENTER\r\n"
+ );
+ Key.ScanCode = 0;
+ Key.UnicodeChar = 0;
+ gBS->RestoreTPL (EFI_TPL_APPLICATION);
+ while (!(Key.ScanCode == 0 && Key.UnicodeChar == L'\r')) {
+ Status = gBS->WaitForEvent (1, &(gST->ConIn->WaitForKey), &EventIndex);
+ gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
+ }
+
+ gBS->RaiseTPL (EFI_TPL_DRIVER);
+ }
+
+ if (HandleBuf != NULL) {
+ gBS->FreePool (HandleBuf);
+ }
+ return FALSE;
+ }
+ }
+ }
+ }
+
+ if (HandleBuf != NULL) {
+ gBS->FreePool (HandleBuf);
+ }
+ return FALSE;
+}
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
diff --git a/Board/EM/MeWrapper/AmtWrapper/Dxe/AsfSupport.h b/Board/EM/MeWrapper/AmtWrapper/Dxe/AsfSupport.h
new file mode 100644
index 0000000..050724f
--- /dev/null
+++ b/Board/EM/MeWrapper/AmtWrapper/Dxe/AsfSupport.h
@@ -0,0 +1,270 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+//**********************************************************************
+//
+// $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/AsfSupport.h 1 2/08/12 1:08a Klzhan $
+//
+// $Revision: 1 $
+//
+// $Date: 2/08/12 1:08a $
+//
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/AsfSupport.h $
+//
+// 1 2/08/12 1:08a Klzhan
+// Initial Check in
+//
+// 1 2/25/11 1:43a Klzhan
+// Initial Check-in
+//
+// 1 12/03/10 5:10a Klzhan
+// Initial Check-in.
+//
+//
+//**********************************************************************
+
+//<AMI_FHDR_START>
+//----------------------------------------------------------------------------
+//
+// Name: AsfSupport.h
+//
+// Description: ASF BDS Support include file
+//
+//----------------------------------------------------------------------------
+//<AMI_FHDR_END>
+/*++
+ This file contains an 'Intel Peripheral Driver' and is
+ licensed for Intel CPUs and chipsets under the terms of your
+ license agreement with Intel or your vendor. This file may
+ be modified by the user, subject to additional terms of the
+ license agreement
+--*/
+
+/*++
+
+Copyright (c) 2005-2008 Intel Corporation. All rights reserved
+This software and associated documentation (if any) is furnished
+under a license and may only be used or copied in accordance
+with the terms of the license. Except as permitted by such
+license, no part of this software or documentation may be
+reproduced, stored in a retrieval system, or transmitted in any
+form or by any means without the express written consent of
+Intel Corporation.
+
+
+Module Name:
+
+ AsfSupport.h
+
+Abstract:
+
+ ASF BDS Support include file
+
+--*/
+
+#ifndef _ASF_SUPPORT_H_
+#define _ASF_SUPPORT_H_
+
+#include "Tiano.h"
+#include "EfiDriverLib.h"
+#include "BdsLib.h"
+#include "Pci22.h"
+#include "Amt.h"
+#include "AmtLib.h"
+#include "MeAccess.h"
+
+#include EFI_PROTOCOL_DEFINITION (LegacyBios)
+#include EFI_PROTOCOL_DEFINITION (SimpleNetwork)
+#include EFI_PROTOCOL_DEFINITION (FirmwareVolume)
+#include EFI_PROTOCOL_DEFINITION (PciRootBridgeIo)
+#include EFI_PROTOCOL_DEFINITION (FormBrowser)
+
+#include EFI_PROTOCOL_CONSUMER (AlertStandardformat)
+#include EFI_PROTOCOL_CONSUMER (DiskInfo)
+
+#include EFI_PROTOCOL_DEFINITION (IderControllerDriver)
+
+typedef union {
+ UINT32 Data32;
+ UINT16 Data16[2];
+} DATA32_UNION;
+
+EFI_STATUS
+BdsAsfInitialization (
+ IN VOID
+ )
+/*++
+
+Routine Description:
+
+ Retrieve the ASF boot options previously recorded by the ASF driver.
+
+Arguments:
+
+ None.
+
+Returns:
+
+ Initialize Boot Options global variable and AMT protocol
+
+--*/
+;
+
+EFI_STATUS
+BdsBootViaAsf (
+ IN VOID
+ )
+/*++
+
+Routine Description:
+
+ Process ASF boot options and if available, attempt the boot
+
+Arguments:
+
+ None.
+
+Returns:
+
+ EFI_SUCCESS - The command completed successfully
+ Other - Error!!
+
+--*/
+;
+
+VOID
+PrintBbsTable (
+ IN BBS_TABLE *LocalBbsTable
+ )
+/*++
+
+Routine Description:
+
+ Dump all devices of BBS.
+
+Arguments:
+
+ LocalBbsTable - BBS table entry.
+
+Returns:
+
+ None.
+
+--*/
+;
+
+EFI_STATUS
+BdsLibDoLegacyBoot (
+ IN BDS_COMMON_OPTION *Option
+ )
+/*++
+
+Routine Description:
+
+ Boot the legacy system with the boot option
+
+Arguments:
+
+ Option - The legacy boot option which have BBS device path
+
+Returns:
+
+ EFI_UNSUPPORTED - There is no legacybios protocol, do not support
+ legacy boot.
+
+ EFI_STATUS - Return the status of LegacyBios->LegacyBoot ().
+
+--*/
+;
+
+BOOLEAN
+BdsCheckIderMedia (
+ IN VOID
+ )
+/*++
+
+Routine Description:
+ This will return if Media in IDE-R is present.
+
+Arguments:
+ None.
+
+Returns:
+ True Media is present.
+ False Media is not present.
+
+--*/
+;
+
+EFI_DEVICE_PATH_PROTOCOL *
+BdsCreateShellDevicePath (
+ IN VOID
+ )
+/*++
+
+Routine Description:
+
+ This function will create a SHELL BootOption to boot.
+
+Arguments:
+
+ None.
+
+Returns:
+
+ Shell Device path for booting.
+
+--*/
+;
+
+BDS_COMMON_OPTION *
+BdsCreateBootOption (
+ IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
+ IN CHAR16 *Description
+ )
+/*++
+
+Routine Description:
+
+ This function will create a BootOption from the give device path and
+ description string.
+
+Arguments:
+
+ DevicePath - The device path which the option represent
+ Description - The description of the boot option
+
+Returns:
+
+ BDS_COMMON_OPTION - A BDS_COMMON_OPTION pointer
+
+--*/
+;
+
+#endif
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//************************************************************************* \ No newline at end of file
diff --git a/Board/EM/MeWrapper/AmtWrapper/Dxe/BdsBoot.c b/Board/EM/MeWrapper/AmtWrapper/Dxe/BdsBoot.c
new file mode 100644
index 0000000..15a57b1
--- /dev/null
+++ b/Board/EM/MeWrapper/AmtWrapper/Dxe/BdsBoot.c
@@ -0,0 +1,809 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+//**********************************************************************
+//
+// $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/BdsBoot.c 2 5/14/14 9:52p Tristinchou $
+//
+// $Revision: 2 $
+//
+// $Date: 5/14/14 9:52p $
+//
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/BdsBoot.c $
+//
+// 2 5/14/14 9:52p Tristinchou
+// [TAG] EIP167030
+// [Category] Improvement
+// [Description] Remove the variable runtime attribute and keep original
+// attributes.
+//
+// 1 2/08/12 1:08a Klzhan
+// Initial Check in
+//
+// 1 2/25/11 1:43a Klzhan
+// Initial Check-in
+//
+// 1 12/03/10 5:10a Klzhan
+// Initial Check-in.
+//
+//
+//**********************************************************************
+
+//<AMI_FHDR_START>
+//----------------------------------------------------------------------------
+//
+// Name: BdsBoot.c
+//
+// Description: Create or Process Boot option by AMT.
+//
+//----------------------------------------------------------------------------
+//<AMI_FHDR_END>
+/*++
+
+Copyright (c) 2004, Intel Corporation
+All rights reserved. This program and the accompanying materials
+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.
+
+Module Name:
+
+ BdsBoot.c
+
+Abstract:
+
+ BDS Lib functions which relate with create or process the boot
+ option.
+
+--*/
+
+#include "BdsLib.h"
+
+BOOLEAN mEnumBootDevice = FALSE;
+
+EFI_STATUS
+BdsLibDoLegacyBoot (
+ IN BDS_COMMON_OPTION *Option
+ )
+/*++
+
+Routine Description:
+
+ Boot the legacy system with the boot option
+
+Arguments:
+
+ Option - The legacy boot option which have BBS device path
+
+Returns:
+
+ EFI_UNSUPPORTED - There is no legacybios protocol, do not support
+ legacy boot.
+
+ EFI_STATUS - Return the status of LegacyBios->LegacyBoot ().
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;
+
+ Status = gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, &LegacyBios);
+ if (EFI_ERROR (Status)) {
+ //
+ // If no LegacyBios protocol we do not support legacy boot
+ //
+ return EFI_UNSUPPORTED;
+ }
+ //
+ // Notes: if we seperate the int 19, then we don't need to refresh BBS
+ //
+ BdsRefreshBbsTableForBoot (Option);
+
+ //
+ // Write boot to OS performance data to a file
+ //
+ WRITE_BOOT_TO_OS_PERFORMANCE_DATA;
+
+ DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Legacy Boot: %S\n", Option->Description));
+ return LegacyBios->LegacyBoot (
+ LegacyBios,
+ (BBS_BBS_DEVICE_PATH *) Option->DevicePath,
+ Option->LoadOptionsSize,
+ Option->LoadOptions
+ );
+}
+
+EFI_STATUS
+BdsLibBootViaBootOption (
+ IN BDS_COMMON_OPTION * Option,
+ IN EFI_DEVICE_PATH_PROTOCOL * DevicePath,
+ OUT UINTN *ExitDataSize,
+ OUT CHAR16 **ExitData OPTIONAL
+ )
+/*++
+
+Routine Description:
+
+ Process the boot option follow the EFI 1.1 specification and
+ special treat the legacy boot option with BBS_DEVICE_PATH.
+
+Arguments:
+
+ Option - The boot option need to be processed
+
+ DevicePath - The device path which describe where to load
+ the boot image or the legcy BBS device path
+ to boot the legacy OS
+
+ ExitDataSize - Returned directly from gBS->StartImage ()
+
+ ExitData - Returned directly from gBS->StartImage ()
+
+Returns:
+
+ EFI_SUCCESS - Status from gBS->StartImage (),
+ or BdsBootByDiskSignatureAndPartition ()
+
+ EFI_NOT_FOUND - If the Device Path is not found in the system
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_HANDLE Handle;
+ EFI_HANDLE ImageHandle;
+ EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL *FilePath;
+ EFI_LOADED_IMAGE_PROTOCOL *ImageInfo;
+ EFI_EVENT ReadyToBootEvent;
+ EFI_ACPI_S3_SAVE_PROTOCOL *AcpiS3Save;
+ EFI_LIST_ENTRY TempBootLists;
+ UINT32 VarAttr;
+ UINTN VarSize;
+//;;## EFI_TCG_PLATFORM_PROTOCOL *TcgPlatformProtocol;
+
+ *ExitDataSize = 0;
+ *ExitData = NULL;
+
+ //
+ // Notes: put EFI64 ROM Shadow Solution
+ //
+ EFI64_SHADOW_ALL_LEGACY_ROM ();
+
+ //
+ // Notes: this code can be remove after the s3 script table
+ // hook on the event EFI_EVENT_SIGNAL_READY_TO_BOOT or
+ // EFI_EVENT_SIGNAL_LEGACY_BOOT
+ //
+ Status = gBS->LocateProtocol (&gEfiAcpiS3SaveGuid, NULL, &AcpiS3Save);
+ if (!EFI_ERROR (Status)) {
+ AcpiS3Save->S3Save (AcpiS3Save, NULL);
+ }
+ //
+ // If it's Device Path that starts with a hard drive path,
+ // this routine will do the booting.
+ //
+ Status = BdsBootByDiskSignatureAndPartition (
+ Option,
+ (HARDDRIVE_DEVICE_PATH *) DevicePath,
+ Option->LoadOptionsSize,
+ Option->LoadOptions,
+ ExitDataSize,
+ ExitData
+ );
+ if (!EFI_ERROR (Status)) {
+ //
+ // If we found a disk signature and partition device path return success
+ //
+ return EFI_SUCCESS;
+ }
+ //
+ // Signal the EFI_EVENT_SIGNAL_READY_TO_BOOT event
+ //
+
+// AMI Override: Replace
+// Abstract: Modified for EFI 2.0 required
+#if defined(EFI_EVENT_SIGNAL_READY_TO_BOOT) && EFI_SPECIFICATION_VERSION<0x20000
+ Status = gBS->CreateEvent(
+ EFI_EVENT_SIGNAL_READY_TO_BOOT | EFI_EVENT_NOTIFY_SIGNAL_ALL,
+ EFI_TPL_CALLBACK,
+ NULL,
+ NULL,
+ &ReadyToBootEvent
+ );
+#else
+ Status = EfiCreateEventReadyToBoot(
+ EFI_TPL_CALLBACK,
+ NULL,
+ NULL,
+ &ReadyToBootEvent
+ );
+#endif
+// AMI Override End
+ if (!EFI_ERROR (Status)) {
+ gBS->SignalEvent (ReadyToBootEvent);
+ gBS->CloseEvent (ReadyToBootEvent);
+ }
+ //
+ // Set Boot Current
+ //
+ VarAttr = 0;
+ VarSize = 0;
+
+ Status = gRT->GetVariable(
+ L"BootCurrent",
+ &gEfiGlobalVariableGuid,
+ &VarAttr,
+ &VarSize,
+ NULL );
+ if( EFI_ERROR(Status) && (Status != EFI_BUFFER_TOO_SMALL) )
+ {
+ VarAttr = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS;
+ VarSize = sizeof(UINT16);
+ }
+
+ gRT->SetVariable(
+ L"BootCurrent",
+ &gEfiGlobalVariableGuid,
+ VarAttr,
+ VarSize,
+ &Option->BootCurrent );
+
+ if ((DevicePathType (Option->DevicePath) == BBS_DEVICE_PATH) &&
+ (DevicePathSubType (Option->DevicePath) == BBS_BBS_DP)
+ ) {
+ //
+ // Check to see if we should legacy BOOT. If yes then do the legacy boot
+ //
+ return BdsLibDoLegacyBoot (Option);
+ }
+
+ //
+ // If the boot option point to Internal FV shell, make sure it is valid
+ //
+ Status = BdsLibUpdateFvFileDevicePath (&DevicePath, &gEfiShellFileGuid);
+ if (!EFI_ERROR(Status)) {
+ if (Option->DevicePath != NULL) {
+ gBS->FreePool(Option->DevicePath);
+ }
+ Option->DevicePath = EfiLibAllocateZeroPool (EfiDevicePathSize (DevicePath));
+ EfiCopyMem (Option->DevicePath, DevicePath, EfiDevicePathSize (DevicePath));
+ //
+ // Update the shell boot option
+ //
+ InitializeListHead (&TempBootLists);
+ BdsLibRegisterNewOption (&TempBootLists, DevicePath, L"EFI Internal Shell", L"BootOrder");
+ //
+ // free the temporary device path created by BdsLibUpdateFvFileDevicePath()
+ //
+ gBS->FreePool (DevicePath);
+ DevicePath = Option->DevicePath;
+ }
+/* //;;##
+ //
+ // Measure GPT Table
+ //
+ Status = gBS->LocateProtocol (
+ &gEfiTcgPlatformProtocolGuid,
+ NULL,
+ &TcgPlatformProtocol
+ );
+ if (!EFI_ERROR (Status)) {
+ Status = TcgPlatformProtocol->MeasureGptTable (DevicePath);
+ }
+*/ //;;##
+
+ //
+ // Drop the TPL level from EFI_TPL_DRIVER to EFI_TPL_APPLICATION
+ //
+ gBS->RestoreTPL (EFI_TPL_APPLICATION);
+
+ DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Booting EFI 1.1 way %S\n", Option->Description));
+
+ Status = gBS->LoadImage (
+ TRUE,
+ mBdsImageHandle,
+ DevicePath,
+ NULL,
+ 0,
+ &ImageHandle
+ );
+
+ //
+ // If we didn't find an image, we may need to load the default
+ // boot behavior for the device.
+ //
+ if (EFI_ERROR (Status)) {
+ //
+ // Find a Simple File System protocol on the device path. If the remaining
+ // device path is set to end then no Files are being specified, so try
+ // the removable media file name.
+ //
+ TempDevicePath = DevicePath;
+ Status = gBS->LocateDevicePath (
+ &gEfiSimpleFileSystemProtocolGuid,
+ &TempDevicePath,
+ &Handle
+ );
+ if (!EFI_ERROR (Status) && IsDevicePathEnd (TempDevicePath)) {
+ FilePath = EfiFileDevicePath (Handle, DEFAULT_REMOVABLE_FILE_NAME);
+ if (FilePath) {
+ Status = gBS->LoadImage (
+ TRUE,
+ mBdsImageHandle,
+ FilePath,
+ NULL,
+ 0,
+ &ImageHandle
+ );
+ if (EFI_ERROR (Status)) {
+ //
+ // The DevicePath failed, and it's not a valid
+ // removable media device.
+ //
+ goto Done;
+ }
+ }
+ } else {
+ Status = EFI_NOT_FOUND;
+ }
+ }
+
+ if (EFI_ERROR (Status)) {
+ //
+ // It there is any error from the Boot attempt exit now.
+ //
+ goto Done;
+ }
+ //
+ // Provide the image with it's load options
+ //
+ Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, &ImageInfo);
+ ASSERT_EFI_ERROR (Status);
+
+ if (Option->LoadOptionsSize != 0) {
+ ImageInfo->LoadOptionsSize = Option->LoadOptionsSize;
+ ImageInfo->LoadOptions = Option->LoadOptions;
+ }
+ //
+ // Before calling the image, enable the Watchdog Timer for
+ // the 5 Minute period
+ //
+ gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL);
+
+ Status = gBS->StartImage (ImageHandle, ExitDataSize, ExitData);
+ DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Image Return Status = %r\n", Status));
+
+ //
+ // Clear the Watchdog Timer after the image returns
+ //
+ gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL);
+
+Done:
+ //
+ // Clear Boot Current
+ //
+ gRT->SetVariable(
+ L"BootCurrent",
+ &gEfiGlobalVariableGuid,
+ VarAttr,
+ 0,
+ &Option->BootCurrent );
+
+ //
+ // Raise the TPL level back to EFI_TPL_DRIVER
+ //
+ gBS->RaiseTPL (EFI_TPL_DRIVER);
+
+ return Status;
+}
+
+EFI_STATUS
+BdsBootByDiskSignatureAndPartition (
+ IN BDS_COMMON_OPTION * Option,
+ IN HARDDRIVE_DEVICE_PATH * HardDriveDevicePath,
+ IN UINT32 LoadOptionsSize,
+ IN VOID *LoadOptions,
+ OUT UINTN *ExitDataSize,
+ OUT CHAR16 **ExitData OPTIONAL
+ )
+/*++
+
+Routine Description:
+
+ Check to see if a hard ware device path was passed in. If it was then search
+ all the block IO devices for the passed in hard drive device path.
+
+Arguments:
+
+ Option - The current processing boot option.
+
+ HardDriveDevicePath - EFI Device Path to boot, if it starts with a hard
+ drive device path.
+
+ LoadOptionsSize - Passed into gBS->StartImage ()
+ via the loaded image protocol.
+
+ LoadOptions - Passed into gBS->StartImage ()
+ via the loaded image protocol.
+
+ ExitDataSize - returned directly from gBS->StartImage ()
+
+ ExitData - returned directly from gBS->StartImage ()
+
+Returns:
+
+ EFI_SUCCESS - Status from gBS->StartImage (),
+ or BootByDiskSignatureAndPartition ()
+
+ EFI_NOT_FOUND - If the Device Path is not found in the system
+
+--*/
+{
+ EFI_STATUS Status;
+ UINTN BlockIoHandleCount;
+ EFI_HANDLE *BlockIoBuffer;
+ EFI_DEVICE_PATH_PROTOCOL *BlockIoDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL *BlockIoHdDevicePath;
+ HARDDRIVE_DEVICE_PATH *TmpHdPath;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
+ UINTN Index;
+ BOOLEAN DevicePathMatch;
+ HARDDRIVE_DEVICE_PATH *TempPath;
+
+ *ExitDataSize = 0;
+ *ExitData = NULL;
+
+ if ( !((DevicePathType (&HardDriveDevicePath->Header) == MEDIA_DEVICE_PATH) &&
+ (DevicePathSubType (&HardDriveDevicePath->Header) == MEDIA_HARDDRIVE_DP))
+ ) {
+ //
+ // If the HardDriveDevicePath does not start with a Hard Drive Device Path
+ // exit.
+ //
+ return EFI_NOT_FOUND;
+ }
+ //
+ // The boot device have already been connected
+ //
+ Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &BlockIoHandleCount, &BlockIoBuffer);
+ if (EFI_ERROR (Status) || BlockIoHandleCount == 0) {
+ //
+ // If there was an error or there are no device handles that support
+ // the BLOCK_IO Protocol, then return.
+ //
+ return EFI_NOT_FOUND;
+ }
+ //
+ // Loop through all the device handles that support the BLOCK_IO Protocol
+ //
+ for (Index = 0; Index < BlockIoHandleCount; Index++) {
+
+ Status = gBS->HandleProtocol (BlockIoBuffer[Index], &gEfiDevicePathProtocolGuid, (VOID *) &BlockIoDevicePath);
+ if (EFI_ERROR (Status) || BlockIoDevicePath == NULL) {
+ continue;
+ }
+ //
+ // Make PreviousDevicePath == the device path node before the end node
+ //
+ DevicePath = BlockIoDevicePath;
+ BlockIoHdDevicePath = NULL;
+
+ //
+ // find HardDriver device path node
+ //
+ while (!IsDevicePathEnd (DevicePath)) {
+ if ((DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) &&
+ (DevicePathSubType (DevicePath) == MEDIA_HARDDRIVE_DP)
+ ) {
+ BlockIoHdDevicePath = DevicePath;
+ break;
+ }
+
+ DevicePath = NextDevicePathNode (DevicePath);
+ }
+
+ if (BlockIoHdDevicePath == NULL) {
+ continue;
+ }
+ //
+ // See if the harddrive device path in blockio matches the orig Hard Drive Node
+ //
+ DevicePathMatch = FALSE;
+
+ TmpHdPath = (HARDDRIVE_DEVICE_PATH *) BlockIoHdDevicePath;
+ TempPath = (HARDDRIVE_DEVICE_PATH *) BdsLibUnpackDevicePath ((EFI_DEVICE_PATH_PROTOCOL *) HardDriveDevicePath);
+
+ //
+ // Only several fields will be checked. NOT whole NODE
+ //
+ if ( TmpHdPath->PartitionNumber == TempPath->PartitionNumber &&
+ TmpHdPath->MBRType == TempPath->MBRType &&
+ TmpHdPath->SignatureType == TempPath->SignatureType &&
+ EfiCompareGuid ((EFI_GUID *) TmpHdPath->Signature, (EFI_GUID *) TempPath->Signature)) {
+ //
+ // Get the matched device path
+ //
+ DevicePathMatch = TRUE;
+ }
+ //
+ // Only do the boot, when devicepath match
+ //
+ if (DevicePathMatch) {
+ //
+ // Combine the Block IO and Hard Drive Device path together and try
+ // to boot from it.
+ //
+ DevicePath = NextDevicePathNode ((EFI_DEVICE_PATH_PROTOCOL *) HardDriveDevicePath);
+ NewDevicePath = EfiAppendDevicePath (BlockIoDevicePath, DevicePath);
+
+ //
+ // Recursive boot with new device path
+ //
+ Status = BdsLibBootViaBootOption (Option, NewDevicePath, ExitDataSize, ExitData);
+ if (!EFI_ERROR (Status)) {
+ break;
+ }
+ }
+ }
+
+ gBS->FreePool (BlockIoBuffer);
+ return Status;
+}
+
+
+EFI_STATUS
+EFIAPI
+BdsLibUpdateFvFileDevicePath (
+ IN OUT EFI_DEVICE_PATH_PROTOCOL ** DevicePath,
+ IN EFI_GUID *FileGuid
+ )
+/*++
+
+Routine Description:
+ According to a file guild, check a Fv file device path is valid. If it is invalid,
+ try to return the valid device path.
+ FV address maybe changes for memory layout adjust from time to time, use this funciton
+ could promise the Fv file device path is right.
+
+Arguments:
+ DevicePath - on input, the Fv file device path need to check
+ on output, the updated valid Fv file device path
+
+ FileGuid - the Fv file guild
+
+Returns:
+ EFI_INVALID_PARAMETER - the input DevicePath or FileGuid is invalid parameter
+ EFI_UNSUPPORTED - the input DevicePath does not contain Fv file guild at all
+ EFI_ALREADY_STARTED - the input DevicePath has pointed to Fv file, it is valid
+ EFI_SUCCESS - has successfully updated the invalid DevicePath, and return the updated
+ device path in DevicePath
+
+--*/
+{
+ EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL *LastDeviceNode;
+ EFI_STATUS Status;
+ EFI_GUID *GuidPoint;
+ UINTN Index;
+ UINTN FvHandleCount;
+ EFI_HANDLE *FvHandleBuffer;
+ EFI_FV_FILETYPE Type;
+ UINTN Size;
+ EFI_FV_FILE_ATTRIBUTES Attributes;
+ UINT32 AuthenticationStatus;
+ BOOLEAN FindFvFile;
+ EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
+#if (PI_SPECIFICATION_VERSION < 0x00010000)
+ EFI_FIRMWARE_VOLUME_PROTOCOL *Fv;
+#else
+ EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
+#endif
+ MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FvFileNode;
+ EFI_HANDLE FoundFvHandle;
+ EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
+
+ if ((DevicePath == NULL) || (*DevicePath == NULL)) {
+ return EFI_INVALID_PARAMETER;
+ }
+ if (FileGuid == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+ //
+ // Check whether the device path point to the default the input Fv file
+ //
+ TempDevicePath = *DevicePath;
+ LastDeviceNode = TempDevicePath;
+ while (!EfiIsDevicePathEnd (TempDevicePath)) {
+ LastDeviceNode = TempDevicePath;
+ TempDevicePath = EfiNextDevicePathNode (TempDevicePath);
+ }
+ GuidPoint = EfiGetNameGuidFromFwVolDevicePathNode (
+ (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) LastDeviceNode
+ );
+ if (GuidPoint == NULL) {
+ //
+ // if this option does not points to a Fv file, just return EFI_UNSUPPORTED
+ //
+ return EFI_UNSUPPORTED;
+ }
+ if (!EfiCompareGuid (GuidPoint, FileGuid)) {
+ //
+ // If the Fv file is not the input file guid, just return EFI_UNSUPPORTED
+ //
+ return EFI_UNSUPPORTED;
+ }
+
+ //
+ // Check whether the input Fv file device path is valid
+ //
+ TempDevicePath = *DevicePath;
+ FoundFvHandle = NULL;
+ Status = gBS->LocateDevicePath (
+ #if (PI_SPECIFICATION_VERSION < 0x00010000)
+ &gEfiFirmwareVolumeProtocolGuid,
+ #else
+ &gEfiFirmwareVolume2ProtocolGuid,
+ #endif
+ &TempDevicePath,
+ &FoundFvHandle
+ );
+ if (!EFI_ERROR (Status)) {
+ Status = gBS->HandleProtocol (
+ FoundFvHandle,
+ #if (PI_SPECIFICATION_VERSION < 0x00010000)
+ &gEfiFirmwareVolumeProtocolGuid,
+ #else
+ &gEfiFirmwareVolume2ProtocolGuid,
+ #endif
+ (VOID **) &Fv
+ );
+ if (!EFI_ERROR (Status)) {
+ //
+ // Set FV ReadFile Buffer as NULL, only need to check whether input Fv file exist there
+ //
+ Status = Fv->ReadFile (
+ Fv,
+ FileGuid,
+ NULL,
+ &Size,
+ &Type,
+ &Attributes,
+ &AuthenticationStatus
+ );
+ if (!EFI_ERROR (Status)) {
+ return EFI_ALREADY_STARTED;
+ }
+ }
+ }
+
+ //
+ // Look for the input wanted FV file in current FV
+ // First, try to look for in Bds own FV. Bds and input wanted FV file usually are in the same FV
+ //
+ FindFvFile = FALSE;
+ FoundFvHandle = NULL;
+ Status = gBS->HandleProtocol (
+ mBdsImageHandle,
+ &gEfiLoadedImageProtocolGuid,
+ &LoadedImage
+ );
+ if (!EFI_ERROR (Status)) {
+ Status = gBS->HandleProtocol (
+ LoadedImage->DeviceHandle,
+ #if (PI_SPECIFICATION_VERSION < 0x00010000)
+ &gEfiFirmwareVolumeProtocolGuid,
+ #else
+ &gEfiFirmwareVolume2ProtocolGuid,
+ #endif
+ (VOID **) &Fv
+ );
+ if (!EFI_ERROR (Status)) {
+ Status = Fv->ReadFile (
+ Fv,
+ FileGuid,
+ NULL,
+ &Size,
+ &Type,
+ &Attributes,
+ &AuthenticationStatus
+ );
+ if (!EFI_ERROR (Status)) {
+ FindFvFile = TRUE;
+ FoundFvHandle = LoadedImage->DeviceHandle;
+ }
+ }
+ }
+ //
+ // Second, if fail to find, try to enumerate all FV
+ //
+ if (!FindFvFile) {
+ FvHandleBuffer = NULL;
+ gBS->LocateHandleBuffer (
+ ByProtocol,
+ #if (PI_SPECIFICATION_VERSION < 0x00010000)
+ &gEfiFirmwareVolumeProtocolGuid,
+ #else
+ &gEfiFirmwareVolume2ProtocolGuid,
+ #endif
+ NULL,
+ &FvHandleCount,
+ &FvHandleBuffer
+ );
+ for (Index = 0; Index < FvHandleCount; Index++) {
+ gBS->HandleProtocol (
+ FvHandleBuffer[Index],
+ #if (PI_SPECIFICATION_VERSION < 0x00010000)
+ &gEfiFirmwareVolumeProtocolGuid,
+ #else
+ &gEfiFirmwareVolume2ProtocolGuid,
+ #endif
+ (VOID **) &Fv
+ );
+
+ Status = Fv->ReadFile (
+ Fv,
+ FileGuid,
+ NULL,
+ &Size,
+ &Type,
+ &Attributes,
+ &AuthenticationStatus
+ );
+ if (EFI_ERROR (Status)) {
+ //
+ // Skip if input Fv file not in the FV
+ //
+ continue;
+ }
+ FindFvFile = TRUE;
+ FoundFvHandle = FvHandleBuffer[Index];
+ break;
+ }
+
+ if (FvHandleBuffer !=NULL ) {
+ gBS->FreePool (FvHandleBuffer);
+ }
+ }
+
+ if (FindFvFile) {
+ //
+ // Build the shell device path
+ //
+ NewDevicePath = EfiDevicePathFromHandle (FoundFvHandle);
+ EfiInitializeFwVolDevicepathNode (&FvFileNode, FileGuid);
+ NewDevicePath = EfiAppendDevicePathNode (NewDevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &FvFileNode);
+ *DevicePath = NewDevicePath;
+ return EFI_SUCCESS;
+ }
+ return EFI_NOT_FOUND;
+}
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//************************************************************************* \ No newline at end of file
diff --git a/Board/EM/MeWrapper/AmtWrapper/Dxe/BdsConnect.c b/Board/EM/MeWrapper/AmtWrapper/Dxe/BdsConnect.c
new file mode 100644
index 0000000..597727f
--- /dev/null
+++ b/Board/EM/MeWrapper/AmtWrapper/Dxe/BdsConnect.c
@@ -0,0 +1,175 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+//**********************************************************************
+//
+// $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/BdsConnect.c 1 2/08/12 1:08a Klzhan $
+//
+// $Revision: 1 $
+//
+// $Date: 2/08/12 1:08a $
+//
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/BdsConnect.c $
+//
+// 1 2/08/12 1:08a Klzhan
+// Initial Check in
+//
+// 1 2/25/11 1:43a Klzhan
+// Initial Check-in
+//
+// 1 12/03/10 5:10a Klzhan
+// Initial Check-in.
+//
+//
+//**********************************************************************
+
+//<AMI_FHDR_START>
+//----------------------------------------------------------------------------
+//
+// Name: BdsConnect.c
+//
+// Description: Connect the device for AMT Boot.
+//
+//----------------------------------------------------------------------------
+//<AMI_FHDR_END>
+/*++
+
+Copyright (c) 2004, Intel Corporation
+All rights reserved. This program and the accompanying materials
+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.
+
+Module Name:
+
+ BdsConnect.c
+
+Abstract:
+
+ BDS Lib functions which relate with connect the device
+
+--*/
+#include "BdsLib.h"
+#include "EdkIIGlueUefiLib.h"
+
+EFI_STATUS
+BdsLibConnectAllEfi (
+ VOID
+ )
+/*++
+
+Routine Description:
+
+ This function will connect all current system handles recursively. The
+ connection will finish until every handle's child handle created if it have.
+
+Arguments:
+
+ None
+
+Returns:
+
+ EFI_SUCCESS - All handles and it's child handle have been connected
+
+ EFI_STATUS - Return the status of gBS->LocateHandleBuffer().
+
+--*/
+{
+ EFI_STATUS Status;
+ UINTN HandleCount;
+ EFI_HANDLE *HandleBuffer;
+ UINTN Index;
+
+ Status = gBS->LocateHandleBuffer (
+ AllHandles,
+ NULL,
+ NULL,
+ &HandleCount,
+ &HandleBuffer
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ for (Index = 0; Index < HandleCount; Index++) {
+ Status = gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);
+ }
+
+ gBS->FreePool (HandleBuffer);
+
+ return EFI_SUCCESS;
+}
+
+VOID
+BdsLibConnectAllDriversToAllControllers (
+ VOID
+ )
+/*++
+
+Routine Description:
+
+ Connects all drivers to all controllers.
+ This function make sure all the current system driver will manage
+ the correspoinding controllers if have. And at the same time, make
+ sure all the system controllers have driver to manage it if have.
+
+Arguments:
+
+ None
+
+Returns:
+
+ None
+
+--*/
+{
+ EFI_STATUS Status;
+
+ Status = EfiGetSystemConfigurationTable (&gEfiDxeServicesTableGuid, (VOID**) &gDS);
+
+ do {
+ //
+ // Connect All EFI 1.10 drivers following EFI 1.10 algorithm
+ //
+ BdsLibConnectAllEfi ();
+
+ //
+ // Check to see if it's possible to dispatch an more DXE drivers.
+ // The BdsLibConnectAllEfi () may have made new DXE drivers show up.
+ // If anything is Dispatched Status == EFI_SUCCESS and we will try
+ // the connect again.
+ //
+ Status = gDS->Dispatch ();
+
+ } while (!EFI_ERROR (Status));
+
+}
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//************************************************************************* \ No newline at end of file
diff --git a/Board/EM/MeWrapper/AmtWrapper/Dxe/BdsConsole.c b/Board/EM/MeWrapper/AmtWrapper/Dxe/BdsConsole.c
new file mode 100644
index 0000000..b55a0a1
--- /dev/null
+++ b/Board/EM/MeWrapper/AmtWrapper/Dxe/BdsConsole.c
@@ -0,0 +1,251 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+//**********************************************************************
+//
+// $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/BdsConsole.c 2 5/14/14 9:53p Tristinchou $
+//
+// $Revision: 2 $
+//
+// $Date: 5/14/14 9:53p $
+//
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/BdsConsole.c $
+//
+// 2 5/14/14 9:53p Tristinchou
+// [TAG] EIP167030
+// [Category] Improvement
+// [Description] Remove the variable runtime attribute and keep original
+// attributes.
+//
+// 1 2/08/12 1:08a Klzhan
+// Initial Check in
+//
+// 1 2/25/11 1:43a Klzhan
+// Initial Check-in
+//
+// 1 12/03/10 5:10a Klzhan
+// Initial Check-in.
+//
+//
+//**********************************************************************
+
+//<AMI_FHDR_START>
+//----------------------------------------------------------------------------
+//
+// Name: BdsConsole.c
+//
+// Description: Connect the Console device for AMT.
+//
+//----------------------------------------------------------------------------
+//<AMI_FHDR_END>
+/*++
+
+Copyright (c) 2004, Intel Corporation
+All rights reserved. This program and the accompanying materials
+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.
+
+Module Name:
+
+ BdsConsole.c
+
+Abstract:
+
+ BDS Lib functions which contain all the code to connect console device
+
+--*/
+
+#include "BdsLib.h"
+#include "EfiPrintLib.h"
+
+EFI_STATUS
+BdsLibUpdateConsoleVariable (
+ IN CHAR16 *ConVarName,
+ IN EFI_DEVICE_PATH_PROTOCOL *CustomizedConDevicePath,
+ IN EFI_DEVICE_PATH_PROTOCOL *ExclusiveDevicePath
+ )
+/*++
+
+Routine Description:
+
+ This function update console variable based on ConVarName, it can
+ add or remove one specific console device path from the variable
+
+Arguments:
+
+ ConVarName - Console related variable name, ConIn, ConOut, ErrOut.
+
+ CustomizedConDevicePath - The console device path which will be added to
+ the console variable ConVarName, this parameter
+ can not be multi-instance.
+
+ ExclusiveDevicePath - The console device path which will be removed
+ from the console variable ConVarName, this
+ parameter can not be multi-instance.
+
+Returns:
+
+ EFI_UNSUPPORTED - Add or remove the same device path.
+
+ EFI_SUCCESS - Success add or remove the device path from
+ the console variable.
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_DEVICE_PATH_PROTOCOL *VarConsole;
+ UINTN DevicePathSize;
+ EFI_DEVICE_PATH_PROTOCOL *Instance;
+ EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
+ UINT32 VarAttr;
+ UINTN VarSize;
+
+
+ VarConsole = NULL;
+ DevicePathSize = 0;
+ NewDevicePath = NULL;
+ Status = EFI_UNSUPPORTED;
+
+ //
+ // Notes: check the device path point, here should check
+ // with compare memory
+ //
+ if (CustomizedConDevicePath == ExclusiveDevicePath) {
+ return EFI_UNSUPPORTED;
+ }
+ //
+ // Delete the ExclusiveDevicePath from current default console
+ //
+ VarConsole = BdsLibGetVariableAndSize (
+ ConVarName,
+ &gEfiGlobalVariableGuid,
+ &DevicePathSize
+ );
+
+ if (ExclusiveDevicePath != NULL && VarConsole != NULL) {
+ if (BdsLibMatchDevicePaths (VarConsole, ExclusiveDevicePath)) {
+
+ Instance = EfiDevicePathInstance (&VarConsole, &DevicePathSize);
+
+ while (VarConsole != NULL) {
+ if (EfiCompareMem (
+ Instance,
+ ExclusiveDevicePath,
+ DevicePathSize - sizeof (EFI_DEVICE_PATH_PROTOCOL)
+ ) == 0) {
+ //
+ // Remove the match part
+ //
+ NewDevicePath = EfiAppendDevicePathInstance (NewDevicePath, VarConsole);
+ break;
+ } else {
+ //
+ // Continue the next instance
+ //
+ NewDevicePath = EfiAppendDevicePathInstance (NewDevicePath, Instance);
+ }
+
+ Instance = EfiDevicePathInstance (&VarConsole, &DevicePathSize);
+ }
+ //
+ // Reset the console variable with new device path
+ //
+ VarAttr = 0;
+ VarSize = 0;
+
+ Status = gRT->GetVariable(
+ ConVarName,
+ &gEfiGlobalVariableGuid,
+ &VarAttr,
+ &VarSize,
+ NULL );
+ if( EFI_ERROR(Status) && Status != EFI_BUFFER_TOO_SMALL )
+ {
+ VarAttr = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE;
+ VarSize = EfiDevicePathSize( NewDevicePath );
+ }
+
+ gRT->SetVariable(
+ ConVarName,
+ &gEfiGlobalVariableGuid,
+ VarAttr,
+ VarSize,
+ NewDevicePath );
+ }
+ }
+ //
+ // Try to append customized device path
+ //
+ VarConsole = BdsLibGetVariableAndSize (
+ ConVarName,
+ &gEfiGlobalVariableGuid,
+ &DevicePathSize
+ );
+
+ if (CustomizedConDevicePath != NULL) {
+ if (!BdsLibMatchDevicePaths (VarConsole, CustomizedConDevicePath)) {
+ //
+ // In the first check, the default console variable will be null,
+ // just append current customized device path
+ //
+ VarConsole = EfiAppendDevicePathInstance (VarConsole, CustomizedConDevicePath);
+
+ //
+ // Update the variable of the default console
+ //
+ VarAttr = 0;
+ VarSize = 0;
+
+ Status = gRT->GetVariable(
+ ConVarName,
+ &gEfiGlobalVariableGuid,
+ &VarAttr,
+ &VarSize,
+ NULL );
+ if( EFI_ERROR(Status) && Status != EFI_BUFFER_TOO_SMALL )
+ {
+ VarAttr = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE;
+ VarSize = EfiDevicePathSize( NewDevicePath );
+ }
+
+ gRT->SetVariable(
+ ConVarName,
+ &gEfiGlobalVariableGuid,
+ VarAttr,
+ VarSize,
+ VarConsole );
+ }
+ }
+
+ return EFI_SUCCESS;
+}
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//************************************************************************* \ No newline at end of file
diff --git a/Board/EM/MeWrapper/AmtWrapper/Dxe/BdsLib.h b/Board/EM/MeWrapper/AmtWrapper/Dxe/BdsLib.h
new file mode 100644
index 0000000..5a4e10a
--- /dev/null
+++ b/Board/EM/MeWrapper/AmtWrapper/Dxe/BdsLib.h
@@ -0,0 +1,459 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+//**********************************************************************
+//
+// $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/BdsLib.h 1 2/08/12 1:08a Klzhan $
+//
+// $Revision: 1 $
+//
+// $Date: 2/08/12 1:08a $
+//
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/BdsLib.h $
+//
+// 1 2/08/12 1:08a Klzhan
+// Initial Check in
+//
+// 3 9/21/11 8:52a Klzhan
+// [TAG] EIP69500
+// [Category] Bug Fix
+// [Severity] Minor
+// [Symptom] Compiler error when DXE_PERFORMANCE is on
+// [RootCause] EDK Library doesn't support this function.
+// [Files] BdsLib.h
+// Performance.c
+//
+// 1 2/25/11 1:43a Klzhan
+// Initial Check-in
+//
+// 1 12/03/10 5:10a Klzhan
+// Initial Check-in.
+//
+//
+//**********************************************************************
+//<AMI_FHDR_START>
+//----------------------------------------------------------------------------
+//
+// Name: BdsConsole.h
+//
+// Description: BDS library definition, include the file and data structure
+//
+//----------------------------------------------------------------------------
+//<AMI_FHDR_END>
+/*++
+
+Copyright (c) 2004, Intel Corporation
+All rights reserved. This program and the accompanying materials
+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.
+
+Module Name:
+
+ BdsLib.h
+
+Abstract:
+
+ BDS library definition, include the file and data structure
+
+--*/
+
+#ifndef _BDS_LIB_H_
+#define _BDS_LIB_H_
+
+#include "Tiano.h"
+#include "EfiDriverLib.h"
+#include "EfiPrintLib.h"
+#include "BmMachine.h"
+#include "EfiHobLib.h"
+
+#include EFI_PROTOCOL_DEFINITION (SerialIo)
+#include EFI_PROTOCOL_DEFINITION (BlockIo)
+#include EFI_PROTOCOL_DEFINITION (LegacyBios)
+#include EFI_PROTOCOL_DEFINITION (AcpiS3Save)
+#include EFI_PROTOCOL_DEFINITION (LoadedImage)
+#include EFI_PROTOCOL_DEFINITION (SimpleFileSystem)
+#include EFI_PROTOCOL_DEFINITION (SimpleNetwork)
+#include EFI_PROTOCOL_DEFINITION (LoadFile)
+#include EFI_PROTOCOL_DEFINITION (PlatformDriverOverride)
+#include EFI_PROTOCOL_DEFINITION (ConsoleControl)
+#include EFI_PROTOCOL_DEFINITION (UgaDraw)
+#include EFI_PROTOCOL_DEFINITION (Hii)
+#include EFI_PROTOCOL_DEFINITION (FirmwareVolume)
+
+#include EFI_PROTOCOL_DEFINITION (TcgService)
+#include EFI_GUID_DEFINITION (PcAnsi)
+#include EFI_GUID_DEFINITION (Hob)
+#include EFI_GUID_DEFINITION (HotPlugDevice)
+#include EFI_GUID_DEFINITION (GlobalVariable)
+#include EFI_GUID_DEFINITION (EfiShell)
+#include EFI_GUID_DEFINITION (ConsoleInDevice)
+#include EFI_GUID_DEFINITION (ConsoleOutDevice)
+#include EFI_GUID_DEFINITION (StandardErrorDevice)
+
+//
+// Include the performance head file and defind macro to add perf data
+//
+#ifdef EFI_DXE_PERFORMANCE
+#include "Performance.h"
+#define WRITE_BOOT_TO_OS_PERFORMANCE_DATA WriteBootToOsPerformanceData ()
+#else
+#define WRITE_BOOT_TO_OS_PERFORMANCE_DATA
+#endif
+
+extern EFI_HANDLE mBdsImageHandle;
+
+//
+// Constants which are variable names used to access variables
+//
+#define VarLegacyDevOrder L"LegacyDevOrder"
+
+//
+// Data structures and defines
+//
+#define FRONT_PAGE_QUESTION_ID 0x0000
+#define FRONT_PAGE_DATA_WIDTH 0x01
+
+//
+// ConnectType
+//
+#define CONSOLE_OUT 0x00000001
+#define STD_ERROR 0x00000002
+#define CONSOLE_IN 0x00000004
+#define CONSOLE_ALL (CONSOLE_OUT | CONSOLE_IN | STD_ERROR)
+
+//
+// Load Option Attributes defined in EFI Specification
+//
+#define LOAD_OPTION_ACTIVE 0x00000001
+#define LOAD_OPTION_FORCE_RECONNECT 0x00000002
+#define IS_LOAD_OPTION_TYPE(_c, _Mask) (BOOLEAN) (((_c) & (_Mask)) != 0)
+
+//
+// Define Maxmim characters that will be accepted
+//
+#define MAX_CHAR 480
+#define MAX_CHAR_SIZE (MAX_CHAR * 2)
+
+#define MIN_ALIGNMENT_SIZE 4
+#define ALIGN_SIZE(a) ((a % MIN_ALIGNMENT_SIZE) ? MIN_ALIGNMENT_SIZE - (a % MIN_ALIGNMENT_SIZE) : 0)
+
+//
+// This data structure is the part of BDS_CONNECT_ENTRY that we can hard code.
+//
+#define BDS_LOAD_OPTION_SIGNATURE EFI_SIGNATURE_32 ('B', 'd', 'C', 'O')
+
+typedef struct {
+
+ UINTN Signature;
+ EFI_LIST_ENTRY Link;
+
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+
+ CHAR16 *OptionName;
+ UINTN OptionNumber;
+ UINT16 BootCurrent;
+ UINT32 Attribute;
+ CHAR16 *Description;
+ VOID *LoadOptions;
+ UINT32 LoadOptionsSize;
+
+} BDS_COMMON_OPTION;
+
+typedef struct {
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ UINTN ConnectType;
+} BDS_CONSOLE_CONNECT_ENTRY;
+
+//
+// Lib Functions
+//
+
+//
+// Bds boot relate lib functions
+//
+EFI_STATUS
+BdsLibUpdateBootOrderList (
+ IN EFI_LIST_ENTRY *BdsOptionList,
+ IN CHAR16 *VariableName
+ );
+
+VOID
+BdsLibBootNext (
+ VOID
+ );
+
+EFI_STATUS
+BdsLibBootViaBootOption (
+ IN BDS_COMMON_OPTION * Option,
+ IN EFI_DEVICE_PATH_PROTOCOL * DevicePath,
+ OUT UINTN *ExitDataSize,
+ OUT CHAR16 **ExitData OPTIONAL
+ );
+
+EFI_STATUS
+BdsLibEnumerateAllBootOption (
+ IN OUT EFI_LIST_ENTRY *BdsBootOptionList
+ );
+
+VOID
+BdsLibBuildOptionFromHandle (
+ IN EFI_HANDLE Handle,
+ IN EFI_LIST_ENTRY *BdsBootOptionList
+ );
+
+VOID
+BdsLibBuildOptionFromShell (
+ IN EFI_HANDLE Handle,
+ IN EFI_LIST_ENTRY *BdsBootOptionList
+ );
+
+//
+// Bds misc lib functions
+//
+UINT16
+BdsLibGetTimeout (
+ VOID
+ );
+
+EFI_STATUS
+BdsLibGetBootMode (
+ OUT EFI_BOOT_MODE *BootMode
+ );
+
+VOID
+BdsLibLoadDrivers (
+ IN EFI_LIST_ENTRY *BdsDriverLists
+ );
+
+EFI_STATUS
+BdsLibBuildOptionFromVar (
+ IN EFI_LIST_ENTRY *BdsCommonOptionList,
+ IN CHAR16 *VariableName
+ );
+
+VOID *
+BdsLibGetVariableAndSize (
+ IN CHAR16 *Name,
+ IN EFI_GUID *VendorGuid,
+ OUT UINTN *VariableSize
+ );
+
+EFI_STATUS
+BdsLibOutputStrings (
+ IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *ConOut,
+ ...
+ );
+
+BDS_COMMON_OPTION *
+BdsLibVariableToOption (
+ IN OUT EFI_LIST_ENTRY *BdsCommonOptionList,
+ IN CHAR16 *VariableName
+ );
+
+EFI_STATUS
+BdsLibRegisterNewOption (
+ IN EFI_LIST_ENTRY *BdsOptionList,
+ IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
+ IN CHAR16 *String,
+ IN CHAR16 *VariableName
+ );
+
+//
+// Bds connect or disconnect driver lib funcion
+//
+VOID
+BdsLibConnectAllDriversToAllControllers (
+ VOID
+ );
+
+VOID
+BdsLibConnectAll (
+ VOID
+ );
+
+EFI_STATUS
+BdsLibConnectDevicePath (
+ IN EFI_DEVICE_PATH_PROTOCOL *DevicePathToConnect
+ );
+
+EFI_STATUS
+BdsLibConnectAllEfi (
+ VOID
+ );
+
+EFI_STATUS
+BdsLibDisconnectAllEfi (
+ VOID
+ );
+
+//
+// Bds console relate lib functions
+//
+VOID
+BdsLibConnectAllConsoles (
+ VOID
+ );
+
+EFI_STATUS
+BdsLibConnectAllDefaultConsoles (
+ VOID
+ );
+
+EFI_STATUS
+BdsLibUpdateConsoleVariable (
+ IN CHAR16 *ConVarName,
+ IN EFI_DEVICE_PATH_PROTOCOL *CustomizedConDevicePath,
+ IN EFI_DEVICE_PATH_PROTOCOL *ExclusiveDevicePath
+ );
+
+EFI_STATUS
+BdsLibConnectConsoleVariable (
+ IN CHAR16 *ConVarName
+ );
+
+//
+// Bds device path relate lib functions
+//
+EFI_DEVICE_PATH_PROTOCOL *
+BdsLibUnpackDevicePath (
+ IN EFI_DEVICE_PATH_PROTOCOL *DevPath
+ );
+
+BOOLEAN
+BdsLibMatchDevicePaths (
+ IN EFI_DEVICE_PATH_PROTOCOL *Multi,
+ IN EFI_DEVICE_PATH_PROTOCOL *Single
+ );
+
+CHAR16 *
+DevicePathToStr (
+ EFI_DEVICE_PATH_PROTOCOL *DevPath
+ );
+
+VOID *
+EfiLibGetVariable (
+ IN CHAR16 *Name,
+ IN EFI_GUID *VendorGuid
+ );
+
+//
+// Internal definitions
+//
+typedef struct {
+ CHAR16 *str;
+ UINTN len;
+ UINTN maxlen;
+} POOL_PRINT;
+
+typedef struct {
+ UINT8 Type;
+ UINT8 SubType;
+ VOID (*Function) (POOL_PRINT *, VOID *);
+} DEVICE_PATH_STRING_TABLE;
+
+//
+// Internal functions
+//
+EFI_STATUS
+BdsBootByDiskSignatureAndPartition (
+ IN BDS_COMMON_OPTION * Option,
+ IN HARDDRIVE_DEVICE_PATH * HardDriveDevicePath,
+ IN UINT32 LoadOptionsSize,
+ IN VOID *LoadOptions,
+ OUT UINTN *ExitDataSize,
+ OUT CHAR16 **ExitData OPTIONAL
+ );
+
+//
+// Notes: EFI 64 shadow all option rom
+//
+#ifdef EFI64
+#define EFI64_SHADOW_ALL_LEGACY_ROM() ShadowAllOptionRom ();
+VOID
+ShadowAllOptionRom();
+#else
+#define EFI64_SHADOW_ALL_LEGACY_ROM()
+#endif
+
+//
+// BBS support macros and functions
+//
+
+#if defined(EFI32) || defined(EFIX64)
+#define REFRESH_LEGACY_BOOT_OPTIONS \
+ BdsDeleteAllInvalidLegacyBootOptions ();\
+ BdsAddNonExistingLegacyBootOptions (); \
+ BdsUpdateLegacyDevOrder ()
+#else
+#define REFRESH_LEGACY_BOOT_OPTIONS
+#endif
+
+EFI_STATUS
+BdsDeleteAllInvalidLegacyBootOptions (
+ VOID
+ );
+
+EFI_STATUS
+BdsAddNonExistingLegacyBootOptions (
+ VOID
+ );
+
+EFI_STATUS
+BdsUpdateLegacyDevOrder (
+ VOID
+ );
+
+EFI_STATUS
+BdsRefreshBbsTableForBoot (
+ IN BDS_COMMON_OPTION *Entry
+ );
+
+extern VOID
+WriteBootToOsPerformanceData (
+ VOID
+ );
+
+BOOLEAN
+BdsLibIsValidEFIBootOptDevicePath (
+ IN EFI_DEVICE_PATH_PROTOCOL *DevPath,
+ IN BOOLEAN CheckMedia
+ );
+
+EFI_STATUS
+EFIAPI
+BdsLibUpdateFvFileDevicePath (
+ IN OUT EFI_DEVICE_PATH_PROTOCOL ** DevicePath,
+ IN EFI_GUID *FileGuid
+ );
+
+#endif // _BDS_LIB_H_
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//************************************************************************* \ No newline at end of file
diff --git a/Board/EM/MeWrapper/AmtWrapper/Dxe/BdsMisc.c b/Board/EM/MeWrapper/AmtWrapper/Dxe/BdsMisc.c
new file mode 100644
index 0000000..2b23d21
--- /dev/null
+++ b/Board/EM/MeWrapper/AmtWrapper/Dxe/BdsMisc.c
@@ -0,0 +1,594 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+//**********************************************************************
+//
+// $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/BdsMisc.c 2 5/14/14 9:53p Tristinchou $
+//
+// $Revision: 2 $
+//
+// $Date: 5/14/14 9:53p $
+//
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/BdsMisc.c $
+//
+// 2 5/14/14 9:53p Tristinchou
+// [TAG] EIP167030
+// [Category] Improvement
+// [Description] Remove the variable runtime attribute and keep original
+// attributes.
+//
+// 1 2/08/12 1:08a Klzhan
+// Initial Check in
+//
+// 1 2/25/11 1:43a Klzhan
+// Initial Check-in
+//
+// 1 12/03/10 5:10a Klzhan
+// Initial Check-in.
+//
+//
+//**********************************************************************
+//<AMI_FHDR_START>
+//----------------------------------------------------------------------------
+//
+// Name: BdsMisc.h
+//
+// Description: Misc BDS library function
+//
+//----------------------------------------------------------------------------
+//<AMI_FHDR_END>
+/*++
+
+Copyright (c) 2004 - 2005, Intel Corporation
+All rights reserved. This program and the accompanying materials
+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.
+
+Module Name:
+
+ BdsMisc.c
+
+Abstract:
+
+ Misc BDS library function
+
+--*/
+
+#include "BdsLib.h"
+
+extern UINT16 gPlatformBootTimeOutDefault;
+
+UINT16
+BdsLibGetTimeout (
+ VOID
+ )
+/*++
+
+Routine Description:
+
+ Return the default value for system Timeout variable.
+
+Arguments:
+
+ None
+
+Returns:
+
+ Timeout value.
+
+--*/
+{
+ UINT16 Timeout;
+ UINT32 VarAttr;
+ UINTN Size;
+ EFI_STATUS Status;
+
+ //
+ // Return Timeout variable or 0xffff if no valid
+ // Timeout variable exists.
+ //
+ VarAttr = 0;
+ Size = sizeof(UINT16);
+ Status = gRT->GetVariable(
+ L"Timeout",
+ &gEfiGlobalVariableGuid,
+ &VarAttr,
+ &Size,
+ &Timeout );
+ if (!EFI_ERROR (Status)) {
+ return Timeout;
+ }
+
+ if( EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL) )
+ {
+ VarAttr = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE;
+ Size = sizeof(UINT16);
+ }
+ //
+ // To make the current EFI Automatic-Test activity possible, just add
+ // following code to make AutoBoot enabled when this variable is not
+ // present.
+ // This code should be removed later.
+ //
+ Timeout = gPlatformBootTimeOutDefault;
+
+ //
+ // Notes: Platform should set default variable if non exists on all error cases!!!
+ //
+ Status = gRT->SetVariable(
+ L"Timeout",
+ &gEfiGlobalVariableGuid,
+ VarAttr,
+ Size,
+ &Timeout );
+
+ return Timeout;
+}
+UINT16
+BdsLibGetFreeOptionNumber (
+ IN CHAR16 *VariableName
+ )
+/*++
+
+Routine Description:
+ Get the Option Number that does not used
+ Try to locate the specific option variable one by one untile find a free number
+
+Arguments:
+ VariableName - Indicate if the boot#### or driver#### option
+
+Returns:
+ The Minimal Free Option Number
+
+--*/
+{
+ UINT16 Number;
+ UINTN Index;
+ CHAR16 StrTemp[10];
+ UINT16 *OptionBuffer;
+ UINTN OptionSize;
+
+ //
+ // Try to find the minimum free number from 0, 1, 2, 3....
+ //
+ Index = 0;
+ do {
+ if (*VariableName == 'B') {
+ SPrint (StrTemp, sizeof (StrTemp), L"Boot%04x", Index);
+ } else {
+ SPrint (StrTemp, sizeof (StrTemp), L"Driver%04x", Index);
+ }
+ //
+ // try if the option number is used
+ //
+ OptionBuffer = BdsLibGetVariableAndSize (
+ StrTemp,
+ &gEfiGlobalVariableGuid,
+ &OptionSize
+ );
+ if (OptionBuffer == NULL) {
+ break;
+ }
+ Index++;
+ } while (1);
+
+ Number = (UINT16) Index;
+ return Number;
+}
+
+EFI_STATUS
+BdsLibRegisterNewOption (
+ IN EFI_LIST_ENTRY *BdsOptionList,
+ IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
+ IN CHAR16 *String,
+ IN CHAR16 *VariableName
+ )
+/*++
+
+Routine Description:
+
+ This function will register the new boot#### or driver#### option base on
+ the VariableName. The new registered boot#### or driver#### will be linked
+ to BdsOptionList and also update to the VariableName. After the boot#### or
+ driver#### updated, the BootOrder or DriverOrder will also be updated.
+
+Arguments:
+
+ BdsOptionList - The header of the boot#### or driver#### link list
+
+ DevicePath - The device path which the boot####
+ or driver#### option present
+
+ String - The description of the boot#### or driver####
+
+ VariableName - Indicate if the boot#### or driver#### option
+
+Returns:
+
+ EFI_SUCCESS - The boot#### or driver#### have been success registered
+
+ EFI_STATUS - Return the status of gRT->SetVariable ().
+
+--*/
+{
+ EFI_STATUS Status;
+ UINTN Index;
+ UINT16 MaxOptionNumber;
+ UINT16 RegisterOptionNumber;
+ UINT16 *TempOptionPtr;
+ UINTN TempOptionSize;
+ UINT16 *OptionOrderPtr;
+ VOID *OptionPtr;
+ UINTN OptionSize;
+ UINT8 *TempPtr;
+ EFI_DEVICE_PATH_PROTOCOL *OptionDevicePath;
+ CHAR16 *Description;
+ CHAR16 OptionName[10];
+ BOOLEAN UpdateDescription;
+ UINT16 BootOrderEntry;
+ UINTN OrderItemNum;
+ UINT32 VarAttr;
+ UINTN VarSize;
+
+
+ OptionPtr = NULL;
+ OptionSize = 0;
+ TempPtr = NULL;
+ OptionDevicePath = NULL;
+ Description = NULL;
+ MaxOptionNumber = 0;
+ OptionOrderPtr = NULL;
+ UpdateDescription = FALSE;
+ EfiZeroMem (OptionName, sizeof (OptionName));
+
+ TempOptionSize = 0;
+ TempOptionPtr = BdsLibGetVariableAndSize (
+ VariableName,
+ &gEfiGlobalVariableGuid,
+ &TempOptionSize
+ );
+
+ //
+ // Compare with current option variable
+ //
+ for (Index = 0; Index < TempOptionSize / sizeof (UINT16); Index++) {
+
+ if (*VariableName == 'B') {
+ SPrint (OptionName, sizeof (OptionName), L"Boot%04x", TempOptionPtr[Index]);
+ } else {
+ SPrint (OptionName, sizeof (OptionName), L"Driver%04x", TempOptionPtr[Index]);
+ }
+
+ OptionPtr = BdsLibGetVariableAndSize (
+ OptionName,
+ &gEfiGlobalVariableGuid,
+ &OptionSize
+ );
+ if (OptionPtr == NULL) {
+ continue;
+ }
+ TempPtr = OptionPtr;
+ TempPtr += sizeof (UINT32) + sizeof (UINT16);
+ Description = (CHAR16 *) TempPtr;
+ TempPtr += EfiStrSize ((CHAR16 *) TempPtr);
+ OptionDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;
+
+ //
+ // Notes: the description may will change base on the GetStringToken
+ //
+ if (EfiCompareMem (OptionDevicePath, DevicePath, EfiDevicePathSize (OptionDevicePath)) == 0) {
+ if (EfiCompareMem (Description, String, EfiStrSize (Description)) == 0) {
+ //
+ // Got the option, so just return
+ //
+ gBS->FreePool (OptionPtr);
+ gBS->FreePool (TempOptionPtr);
+ return EFI_SUCCESS;
+ } else {
+ //
+ // Option description changed, need update.
+ //
+ UpdateDescription = TRUE;
+ gBS->FreePool (OptionPtr);
+ break;
+ }
+ }
+
+ gBS->FreePool (OptionPtr);
+ }
+
+ OptionSize = sizeof (UINT32) + sizeof (UINT16) + EfiStrSize (String) + EfiDevicePathSize (DevicePath);
+ OptionPtr = EfiLibAllocateZeroPool (OptionSize);
+ TempPtr = OptionPtr;
+ *(UINT32 *) TempPtr = LOAD_OPTION_ACTIVE;
+ TempPtr += sizeof (UINT32);
+ *(UINT16 *) TempPtr = (UINT16) EfiDevicePathSize (DevicePath);
+ TempPtr += sizeof (UINT16);
+ EfiCopyMem (TempPtr, String, EfiStrSize (String));
+ TempPtr += EfiStrSize (String);
+ EfiCopyMem (TempPtr, DevicePath, EfiDevicePathSize (DevicePath));
+
+ if (UpdateDescription) {
+ //
+ // The number in option#### to be updated
+ //
+ RegisterOptionNumber = TempOptionPtr[Index];
+ } else {
+ //
+ // The new option#### number
+ //
+ RegisterOptionNumber = BdsLibGetFreeOptionNumber(VariableName);
+ }
+
+ if (*VariableName == 'B') {
+ SPrint (OptionName, sizeof (OptionName), L"Boot%04x", RegisterOptionNumber);
+ } else {
+ SPrint (OptionName, sizeof (OptionName), L"Driver%04x", RegisterOptionNumber);
+ }
+
+ VarAttr = 0;
+ VarSize = 0;
+
+ Status = gRT->GetVariable(
+ OptionName,
+ &gEfiGlobalVariableGuid,
+ &VarAttr,
+ &VarSize,
+ NULL );
+ if( EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL) )
+ {
+ VarAttr = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE;
+ VarSize = OptionSize;
+ }
+
+ Status = gRT->SetVariable (
+ OptionName,
+ &gEfiGlobalVariableGuid,
+ VarAttr,
+ VarSize,
+ OptionPtr );
+ //
+ // Return if only need to update a changed description or fail to set option.
+ //
+ if (EFI_ERROR (Status) || UpdateDescription) {
+ gBS->FreePool (OptionPtr);
+ gBS->FreePool (TempOptionPtr);
+ return Status;
+ }
+
+ gBS->FreePool (OptionPtr);
+
+ //
+ // Update the option order variable
+ //
+
+ //
+ // If no option order
+ //
+ if (TempOptionSize == 0) {
+ VarAttr = 0;
+ VarSize = 0;
+
+ Status = gRT->GetVariable(
+ VariableName,
+ &gEfiGlobalVariableGuid,
+ &VarAttr,
+ &VarSize,
+ NULL );
+ if( EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL) )
+ {
+ VarAttr = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE;
+ VarSize = sizeof(UINT16);
+ }
+
+ BootOrderEntry = 0;
+
+ Status = gRT->SetVariable(
+ VariableName,
+ &gEfiGlobalVariableGuid,
+ VarAttr,
+ VarSize,
+ &BootOrderEntry );
+ if (EFI_ERROR (Status)) {
+ gBS->FreePool (TempOptionPtr);
+ return Status;
+ }
+ return EFI_SUCCESS;
+ }
+ //
+ // Append the new option number to the original option order
+ //
+ OrderItemNum = (TempOptionSize / sizeof (UINT16)) + 1 ;
+ OptionOrderPtr = EfiLibAllocateZeroPool ( OrderItemNum * sizeof (UINT16));
+ EfiCopyMem (OptionOrderPtr, TempOptionPtr, (OrderItemNum - 1) * sizeof (UINT16));
+
+ OptionOrderPtr[Index] = RegisterOptionNumber;
+
+ VarAttr = 0;
+ VarSize = 0;
+
+ Status = gRT->GetVariable(
+ VariableName,
+ &gEfiGlobalVariableGuid,
+ &VarAttr,
+ &VarSize,
+ NULL );
+ if( EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL) )
+ {
+ VarAttr = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE;
+ VarSize = OrderItemNum * sizeof(UINT16);
+ }
+
+ Status = gRT->SetVariable(
+ VariableName,
+ &gEfiGlobalVariableGuid,
+ VarAttr,
+ VarSize,
+ OptionOrderPtr );
+ if (EFI_ERROR (Status)) {
+ gBS->FreePool (TempOptionPtr);
+ gBS->FreePool (OptionOrderPtr);
+ return Status;
+ }
+
+ gBS->FreePool (TempOptionPtr);
+ gBS->FreePool (OptionOrderPtr);
+
+ return EFI_SUCCESS;
+}
+
+
+VOID *
+BdsLibGetVariableAndSize (
+ IN CHAR16 *Name,
+ IN EFI_GUID *VendorGuid,
+ OUT UINTN *VariableSize
+ )
+/*++
+
+Routine Description:
+
+ Read the EFI variable (VendorGuid/Name) and return a dynamically allocated
+ buffer, and the size of the buffer. If failure return NULL.
+
+Arguments:
+
+ Name - String part of EFI variable name
+
+ VendorGuid - GUID part of EFI variable name
+
+ VariableSize - Returns the size of the EFI variable that was read
+
+Returns:
+
+ Dynamically allocated memory that contains a copy of the EFI variable.
+ Caller is responsible freeing the buffer.
+
+ NULL - Variable was not read
+
+--*/
+{
+ EFI_STATUS Status;
+ UINTN BufferSize;
+ VOID *Buffer;
+
+ Buffer = NULL;
+
+ //
+ // Pass in a zero size buffer to find the required buffer size.
+ //
+ BufferSize = 0;
+ Status = gRT->GetVariable (Name, VendorGuid, NULL, &BufferSize, Buffer);
+ if (Status == EFI_BUFFER_TOO_SMALL) {
+ //
+ // Allocate the buffer to return
+ //
+ Buffer = EfiLibAllocateZeroPool (BufferSize);
+ if (Buffer == NULL) {
+ return NULL;
+ }
+ //
+ // Read variable into the allocated buffer.
+ //
+ Status = gRT->GetVariable (Name, VendorGuid, NULL, &BufferSize, Buffer);
+ if (EFI_ERROR (Status)) {
+ BufferSize = 0;
+ }
+ }
+
+ *VariableSize = BufferSize;
+ return Buffer;
+}
+
+BOOLEAN
+BdsLibMatchDevicePaths (
+ IN EFI_DEVICE_PATH_PROTOCOL *Multi,
+ IN EFI_DEVICE_PATH_PROTOCOL *Single
+ )
+/*++
+
+Routine Description:
+
+ Function compares a device path data structure to that of all the nodes of a
+ second device path instance.
+
+Arguments:
+
+ Multi - A pointer to a multi-instance device path data structure.
+
+ Single - A pointer to a single-instance device path data structure.
+
+Returns:
+
+ TRUE - If the Single is contained within Multi
+
+ FALSE - The Single is not match within Multi
+
+
+--*/
+{
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePathInst;
+ UINTN Size;
+
+ if (!Multi || !Single) {
+ return FALSE;
+ }
+
+ DevicePath = Multi;
+ DevicePathInst = EfiDevicePathInstance (&DevicePath, &Size);
+ Size -= sizeof (EFI_DEVICE_PATH_PROTOCOL);
+
+ //
+ // Search for the match of 'Single' in 'Multi'
+ //
+ while (DevicePathInst != NULL) {
+ //
+ // If the single device path is found in multiple device paths,
+ // return success
+ //
+ if (Size == 0) {
+ return FALSE;
+ }
+
+ if (EfiCompareMem (Single, DevicePathInst, Size) == 0) {
+ return TRUE;
+ }
+
+ gBS->FreePool (DevicePathInst);
+ DevicePathInst = EfiDevicePathInstance (&DevicePath, &Size);
+ Size -= sizeof (EFI_DEVICE_PATH_PROTOCOL);
+ }
+
+ return FALSE;
+}
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//************************************************************************* \ No newline at end of file
diff --git a/Board/EM/MeWrapper/AmtWrapper/Dxe/BmMachine.h b/Board/EM/MeWrapper/AmtWrapper/Dxe/BmMachine.h
new file mode 100644
index 0000000..4ba1760
--- /dev/null
+++ b/Board/EM/MeWrapper/AmtWrapper/Dxe/BmMachine.h
@@ -0,0 +1,102 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+//**********************************************************************
+//
+// $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/BmMachine.h 2 10/30/12 8:23a Klzhan $
+//
+// $Revision: 2 $
+//
+// $Date: 10/30/12 8:23a $
+//
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/BmMachine.h $
+//
+// 2 10/30/12 8:23a Klzhan
+// [TAG] EIP92074
+// [Category] Bug Fix
+// [Severity] Important
+// [Symptom] AMT EFI Boot fail
+// [RootCause] File path incorrect.
+//
+// 1 2/08/12 1:08a Klzhan
+// Initial Check in
+//
+// 1 2/25/11 1:43a Klzhan
+// Initial Check-in
+//
+// 1 12/03/10 5:10a Klzhan
+// Initial Check-in.
+//
+//
+//**********************************************************************
+//<AMI_FHDR_START>
+//----------------------------------------------------------------------------
+//
+// Name: BmMachine.h
+//
+// Description: Boot Manager Machine type
+//
+//----------------------------------------------------------------------------
+//<AMI_FHDR_END>
+/*++
+
+Copyright (c) 2004, Intel Corporation
+All rights reserved. This program and the accompanying materials
+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.
+
+Module Name:
+
+ BmMachine.h
+
+Abstract:
+
+ Boot Manager Machine type
+
+
+
+Revision History
+
+--*/
+
+#ifndef _BM_MACHINE_H
+#define _BM_MACHINE_H
+#include "Token.h"
+
+#if x64_BUILD
+#define DEFAULT_REMOVABLE_FILE_NAME L"\\EFI\\BOOT\\BOOTX64.EFI"
+#else
+#define DEFAULT_REMOVABLE_FILE_NAME L"\\EFI\\BOOT\\BOOTIA32.EFI"
+#endif
+
+#endif
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//************************************************************************* \ No newline at end of file
diff --git a/Board/EM/MeWrapper/AmtWrapper/Dxe/DevicePath.c b/Board/EM/MeWrapper/AmtWrapper/Dxe/DevicePath.c
new file mode 100644
index 0000000..7fa871e
--- /dev/null
+++ b/Board/EM/MeWrapper/AmtWrapper/Dxe/DevicePath.c
@@ -0,0 +1,1078 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+//**********************************************************************
+//
+// $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/DevicePath.c 1 2/08/12 1:08a Klzhan $
+//
+// $Revision: 1 $
+//
+// $Date: 2/08/12 1:08a $
+//
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/DevicePath.c $
+//
+// 1 2/08/12 1:08a Klzhan
+// Initial Check in
+//
+// 1 2/25/11 1:43a Klzhan
+// Initial Check-in
+//
+// 1 12/03/10 5:10a Klzhan
+// Initial Check-in.
+//
+//
+//**********************************************************************
+//<AMI_FHDR_START>
+//----------------------------------------------------------------------------
+//
+// Name: DevicePath.h
+//
+// Description:
+// BDS internal function define the default device path string, it can be
+// replaced by platform device path.
+//
+//----------------------------------------------------------------------------
+//<AMI_FHDR_END>
+/*++
+
+Copyright (c) 2004, Intel Corporation
+All rights reserved. This program and the accompanying materials
+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.
+
+Module Name:
+
+ DevicePath.c
+
+Abstract:
+
+ BDS internal function define the default device path string, it can be
+ replaced by platform device path.
+
+--*/
+
+#include "Tiano.h"
+#include "EfiPrintLib.h"
+#include "bdslib.h"
+
+EFI_GUID UnknownDeviceGuid = UNKNOWN_DEVICE_GUID;
+
+EFI_GUID mEfiMsgPcAnsiGuid = DEVICE_PATH_MESSAGING_PC_ANSI;
+EFI_GUID mEfiMsgVt100Guid = DEVICE_PATH_MESSAGING_VT_100;
+EFI_GUID mEfiMsgVt100PlusGuid = DEVICE_PATH_MESSAGING_VT_100_PLUS;
+EFI_GUID mEfiMsgVt100Utf8Guid = DEVICE_PATH_MESSAGING_VT_UTF8;
+
+VOID *
+ReallocatePool (
+ IN VOID *OldPool,
+ IN UINTN OldSize,
+ IN UINTN NewSize
+)
+/*++
+
+Routine Description:
+
+ Adjusts the size of a previously allocated buffer.
+
+Arguments:
+
+ OldPool - A pointer to the buffer whose size is being adjusted.
+
+ OldSize - The size of the current buffer.
+
+ NewSize - The size of the new buffer.
+
+Returns:
+
+ EFI_SUCEESS - The requested number of bytes were allocated.
+
+ EFI_OUT_OF_RESOURCES - The pool requested could not be allocated.
+
+ EFI_INVALID_PARAMETER - The buffer was invalid.
+
+--*/
+{
+ VOID *NewPool;
+
+ NewPool = NULL;
+ if (NewSize)
+ {
+ NewPool = EfiLibAllocateZeroPool (NewSize);
+ }
+
+ if (OldPool)
+ {
+ if (NewPool)
+ {
+ EfiCopyMem (NewPool, OldPool, OldSize < NewSize ? OldSize : NewSize);
+ }
+
+ gBS->FreePool (OldPool);
+ }
+
+ return NewPool;
+}
+
+CHAR16 *
+CatPrint (
+ IN OUT POOL_PRINT *Str,
+ IN CHAR16 *fmt,
+ ...
+)
+/*++
+
+Routine Description:
+
+ Concatenates a formatted unicode string to allocated pool.
+ The caller must free the resulting buffer.
+
+Arguments:
+
+ Str - Tracks the allocated pool, size in use, and
+ amount of pool allocated.
+
+ fmt - The format string
+
+Returns:
+
+ Allocated buffer with the formatted string printed in it.
+ The caller must free the allocated buffer. The buffer
+ allocation is not packed.
+
+--*/
+{
+ UINT16 *AppendStr;
+ VA_LIST args;
+ UINTN strsize;
+
+ AppendStr = EfiLibAllocateZeroPool (0x1000);
+ if (AppendStr == NULL)
+ {
+ return Str->str;
+ }
+
+ VA_START (args, fmt);
+ VSPrint (AppendStr, 0x1000, fmt, args);
+ VA_END (args);
+ if (NULL == Str->str)
+ {
+ strsize = EfiStrSize (AppendStr);
+ Str->str = EfiLibAllocateZeroPool (strsize);
+ ASSERT (Str->str != NULL);
+ }
+ else
+ {
+ strsize = EfiStrSize (AppendStr) + EfiStrSize (Str->str) - sizeof (UINT16);
+ Str->str = ReallocatePool (
+ Str->str,
+ EfiStrSize (Str->str),
+ strsize
+ );
+ ASSERT (Str->str != NULL);
+ }
+
+ Str->maxlen = MAX_CHAR * sizeof (UINT16);
+ if (strsize < Str->maxlen)
+ {
+ EfiStrCat (Str->str, AppendStr);
+ Str->len = strsize - sizeof (UINT16);
+ }
+
+ gBS->FreePool (AppendStr);
+ return Str->str;
+}
+
+EFI_DEVICE_PATH_PROTOCOL *
+BdsLibUnpackDevicePath (
+ IN EFI_DEVICE_PATH_PROTOCOL *DevPath
+)
+/*++
+
+Routine Description:
+
+ Function unpacks a device path data structure so that all the nodes
+ of a device path are naturally aligned.
+
+Arguments:
+
+ DevPath - A pointer to a device path data structure
+
+Returns:
+
+ If the memory for the device path is successfully allocated, then a
+ pointer to the new device path is returned. Otherwise, NULL is returned.
+
+--*/
+{
+ EFI_DEVICE_PATH_PROTOCOL *Src;
+ EFI_DEVICE_PATH_PROTOCOL *Dest;
+ EFI_DEVICE_PATH_PROTOCOL *NewPath;
+ UINTN Size;
+
+ //
+ // Walk device path and round sizes to valid boundries
+ //
+ Src = DevPath;
+ Size = 0;
+ for (;;)
+ {
+ Size += DevicePathNodeLength (Src);
+ Size += ALIGN_SIZE (Size);
+
+ if (IsDevicePathEnd (Src))
+ {
+ break;
+ }
+
+ Src = NextDevicePathNode (Src);
+ }
+ //
+ // Allocate space for the unpacked path
+ //
+ NewPath = EfiLibAllocateZeroPool (Size);
+ if (NewPath)
+ {
+
+ ASSERT (((UINTN) NewPath) % MIN_ALIGNMENT_SIZE == 0);
+
+ //
+ // Copy each node
+ //
+ Src = DevPath;
+ Dest = NewPath;
+ for (;;)
+ {
+ Size = DevicePathNodeLength (Src);
+ EfiCopyMem (Dest, Src, Size);
+ Size += ALIGN_SIZE (Size);
+ SetDevicePathNodeLength (Dest, Size);
+ Dest->Type |= EFI_DP_TYPE_UNPACKED;
+ Dest = (EFI_DEVICE_PATH_PROTOCOL *) (((UINT8 *) Dest) + Size);
+
+ if (IsDevicePathEnd (Src))
+ {
+ break;
+ }
+
+ Src = NextDevicePathNode (Src);
+ }
+ }
+
+ return NewPath;
+}
+
+VOID
+DevPathPci (
+ IN OUT POOL_PRINT *Str,
+ IN VOID *DevPath
+)
+{
+ PCI_DEVICE_PATH *Pci;
+
+ Pci = DevPath;
+ CatPrint (Str, L"Pci(%x|%x)", Pci->Device, Pci->Function);
+}
+
+VOID
+DevPathPccard (
+ IN OUT POOL_PRINT *Str,
+ IN VOID *DevPath
+)
+{
+ PCCARD_DEVICE_PATH *Pccard;
+
+ Pccard = DevPath;
+ CatPrint (Str, L"Pcmcia(Function%x)", Pccard->FunctionNumber);
+}
+
+VOID
+DevPathMemMap (
+ IN OUT POOL_PRINT *Str,
+ IN VOID *DevPath
+)
+{
+ MEMMAP_DEVICE_PATH *MemMap;
+
+ MemMap = DevPath;
+ CatPrint (
+ Str,
+ L"MemMap(%d:%.lx-%.lx)",
+ MemMap->MemoryType,
+ MemMap->StartingAddress,
+ MemMap->EndingAddress
+ );
+}
+
+VOID
+DevPathController (
+ IN OUT POOL_PRINT *Str,
+ IN VOID *DevPath
+)
+{
+ CONTROLLER_DEVICE_PATH *Controller;
+
+ Controller = DevPath;
+ CatPrint (Str, L"Ctrl(%d)", Controller->Controller);
+}
+
+VOID
+DevPathVendor (
+ IN OUT POOL_PRINT *Str,
+ IN VOID *DevPath
+)
+/*++
+
+Routine Description:
+
+ Convert Vendor device path to device name
+
+Arguments:
+
+ Str - The buffer store device name
+ DevPath - Pointer to vendor device path
+
+Returns:
+
+ When it return, the device name have been stored in *Str.
+
+--*/
+{
+ VENDOR_DEVICE_PATH *Vendor;
+ CHAR16 *Type;
+ INT32 *Temp;
+
+ Vendor = DevPath;
+ Temp = (INT32 *) (&Vendor->Guid);
+
+ switch (DevicePathType (&Vendor->Header))
+ {
+ case HARDWARE_DEVICE_PATH:
+ //
+ // If the device is a winntbus device, we will give it a readable device name.
+ //
+ Type = L"Hw";
+ break;
+
+ case MESSAGING_DEVICE_PATH:
+ //
+ // If the device is a winntbus device, we will give it a readable device name.
+ //
+ if (EfiCompareGuid (&Vendor->Guid, &mEfiMsgPcAnsiGuid))
+ {
+ CatPrint (Str, L"%s", L"PC-ANSI");
+ return ;
+ }
+ else if (EfiCompareGuid (&Vendor->Guid, &mEfiMsgVt100Guid))
+ {
+ CatPrint (Str, L"%s", L"VT100");
+ return ;
+ }
+ else if (EfiCompareGuid (&Vendor->Guid, &mEfiMsgVt100PlusGuid))
+ {
+ CatPrint (Str, L"%s", L"VT100+");
+ return ;
+ }
+ else if (EfiCompareGuid (&Vendor->Guid, &mEfiMsgVt100Utf8Guid))
+ {
+ CatPrint (Str, L"%s", L"VT100-UTF8");
+ return ;
+ }
+ else
+ {
+ Type = L"Msg";
+ break;
+ }
+
+ case MEDIA_DEVICE_PATH:
+ Type = L"Media";
+ break;
+
+ default:
+ Type = L"?";
+ break;
+ }
+
+ CatPrint (Str, L"Ven%s(%g)", Type, &Vendor->Guid);
+}
+
+VOID
+DevPathAcpi (
+ IN OUT POOL_PRINT *Str,
+ IN VOID *DevPath
+)
+{
+ ACPI_HID_DEVICE_PATH *Acpi;
+
+ Acpi = DevPath;
+ if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST)
+ {
+ CatPrint (Str, L"Acpi(PNP%04x,%x)", EISA_ID_TO_NUM (Acpi->HID), Acpi->UID);
+ }
+ else
+ {
+ CatPrint (Str, L"Acpi(%08x,%x)", Acpi->HID, Acpi->UID);
+ }
+}
+
+VOID
+DevPathAtapi (
+ IN OUT POOL_PRINT *Str,
+ IN VOID *DevPath
+)
+{
+ ATAPI_DEVICE_PATH *Atapi;
+
+ Atapi = DevPath;
+ CatPrint (
+ Str,
+ L"Ata(%s,%s)",
+ Atapi->PrimarySecondary ? L"Secondary" : L"Primary",
+ Atapi->SlaveMaster ? L"Slave" : L"Master"
+ );
+}
+
+VOID
+DevPathScsi (
+ IN OUT POOL_PRINT *Str,
+ IN VOID *DevPath
+)
+{
+ SCSI_DEVICE_PATH *Scsi;
+
+ Scsi = DevPath;
+ CatPrint (Str, L"Scsi(Pun%x,Lun%x)", Scsi->Pun, Scsi->Lun);
+}
+
+VOID
+DevPathFibre (
+ IN OUT POOL_PRINT *Str,
+ IN VOID *DevPath
+)
+{
+ FIBRECHANNEL_DEVICE_PATH *Fibre;
+
+ Fibre = DevPath;
+ CatPrint (Str, L"Fibre(Wwn%lx,Lun%x)", Fibre->WWN, Fibre->Lun);
+}
+
+VOID
+DevPath1394 (
+ IN OUT POOL_PRINT *Str,
+ IN VOID *DevPath
+)
+{
+ F1394_DEVICE_PATH *F1394;
+
+ F1394 = DevPath;
+ CatPrint (Str, L"1394(%g)", &F1394->Guid);
+}
+
+VOID
+DevPathUsb (
+ IN OUT POOL_PRINT *Str,
+ IN VOID *DevPath
+)
+{
+ USB_DEVICE_PATH *Usb;
+
+ Usb = DevPath;
+ CatPrint (Str, L"Usb(%x, %x)", Usb->ParentPortNumber, Usb->InterfaceNumber);
+}
+
+VOID
+DevPathUsbClass (
+ IN OUT POOL_PRINT *Str,
+ IN VOID *DevPath
+)
+{
+ USB_CLASS_DEVICE_PATH *UsbClass;
+
+ UsbClass = DevPath;
+ CatPrint (
+ Str,
+ L"Usb Class(%x, %x, %x, %x, %x)",
+ UsbClass->VendorId,
+ UsbClass->ProductId,
+ UsbClass->DeviceClass,
+ UsbClass->DeviceSubClass,
+ UsbClass->DeviceProtocol
+ );
+}
+
+VOID
+DevPathI2O (
+ IN OUT POOL_PRINT *Str,
+ IN VOID *DevPath
+)
+{
+ I2O_DEVICE_PATH *I2O;
+
+ I2O = DevPath;
+ CatPrint (Str, L"I2O(%x)", I2O->Tid);
+}
+
+VOID
+DevPathMacAddr (
+ IN OUT POOL_PRINT *Str,
+ IN VOID *DevPath
+)
+{
+ MAC_ADDR_DEVICE_PATH *MAC;
+ UINTN HwAddressSize;
+ UINTN Index;
+
+ MAC = DevPath;
+
+ HwAddressSize = sizeof (EFI_MAC_ADDRESS);
+ if (MAC->IfType == 0x01 || MAC->IfType == 0x00)
+ {
+ HwAddressSize = 6;
+ }
+
+ CatPrint (Str, L"Mac(");
+
+ for (Index = 0; Index < HwAddressSize; Index++)
+ {
+ CatPrint (Str, L"%02x", MAC->MacAddress.Addr[Index]);
+ }
+
+ CatPrint (Str, L")");
+}
+
+VOID
+DevPathIPv4 (
+ IN OUT POOL_PRINT *Str,
+ IN VOID *DevPath
+)
+{
+ IPv4_DEVICE_PATH *IP;
+
+ IP = DevPath;
+ CatPrint (
+ Str,
+ L"IPv4(%d.%d.%d.%d:%d)",
+ IP->RemoteIpAddress.Addr[0],
+ IP->RemoteIpAddress.Addr[1],
+ IP->RemoteIpAddress.Addr[2],
+ IP->RemoteIpAddress.Addr[3],
+ IP->RemotePort
+ );
+}
+
+VOID
+DevPathIPv6 (
+ IN OUT POOL_PRINT *Str,
+ IN VOID *DevPath
+)
+{
+ IPv6_DEVICE_PATH *IP;
+
+ IP = DevPath;
+ CatPrint (Str, L"IP-v6(not-done)");
+}
+
+VOID
+DevPathInfiniBand (
+ IN OUT POOL_PRINT *Str,
+ IN VOID *DevPath
+)
+{
+ INFINIBAND_DEVICE_PATH *InfiniBand;
+
+ InfiniBand = DevPath;
+ CatPrint (Str, L"InfiniBand(not-done)");
+}
+
+VOID
+DevPathUart (
+ IN OUT POOL_PRINT *Str,
+ IN VOID *DevPath
+)
+{
+ UART_DEVICE_PATH *Uart;
+ CHAR8 Parity;
+
+ Uart = DevPath;
+ switch (Uart->Parity)
+ {
+ case 0:
+ Parity = 'D';
+ break;
+
+ case 1:
+ Parity = 'N';
+ break;
+
+ case 2:
+ Parity = 'E';
+ break;
+
+ case 3:
+ Parity = 'O';
+ break;
+
+ case 4:
+ Parity = 'M';
+ break;
+
+ case 5:
+ Parity = 'S';
+ break;
+
+ default:
+ Parity = 'x';
+ break;
+ }
+
+ if (Uart->BaudRate == 0)
+ {
+ CatPrint (Str, L"Uart(DEFAULT %c", Parity);
+ }
+ else
+ {
+ CatPrint (Str, L"Uart(%d %c", Uart->BaudRate, Parity);
+ }
+
+ if (Uart->DataBits == 0)
+ {
+ CatPrint (Str, L"D");
+ }
+ else
+ {
+ CatPrint (Str, L"%d", Uart->DataBits);
+ }
+
+ switch (Uart->StopBits)
+ {
+ case 0:
+ CatPrint (Str, L"D)");
+ break;
+
+ case 1:
+ CatPrint (Str, L"1)");
+ break;
+
+ case 2:
+ CatPrint (Str, L"1.5)");
+ break;
+
+ case 3:
+ CatPrint (Str, L"2)");
+ break;
+
+ default:
+ CatPrint (Str, L"x)");
+ break;
+ }
+}
+
+VOID
+DevPathHardDrive (
+ IN OUT POOL_PRINT *Str,
+ IN VOID *DevPath
+)
+{
+ HARDDRIVE_DEVICE_PATH *Hd;
+
+ Hd = DevPath;
+ switch (Hd->SignatureType)
+ {
+ case SIGNATURE_TYPE_MBR:
+ CatPrint (
+ Str,
+ L"HD(Part%d,Sig%08x)",
+ Hd->PartitionNumber,
+ *((UINT32 *) (&(Hd->Signature[0])))
+ );
+ break;
+
+ case SIGNATURE_TYPE_GUID:
+ CatPrint (
+ Str,
+ L"HD(Part%d,Sig%g)",
+ Hd->PartitionNumber,
+ (EFI_GUID *) &(Hd->Signature[0])
+ );
+ break;
+
+ default:
+ CatPrint (
+ Str,
+ L"HD(Part%d,MBRType=%02x,SigType=%02x)",
+ Hd->PartitionNumber,
+ Hd->MBRType,
+ Hd->SignatureType
+ );
+ break;
+ }
+}
+
+VOID
+DevPathCDROM (
+ IN OUT POOL_PRINT *Str,
+ IN VOID *DevPath
+)
+{
+ CDROM_DEVICE_PATH *Cd;
+
+ Cd = DevPath;
+ CatPrint (Str, L"CDROM(Entry%x)", Cd->BootEntry);
+}
+
+VOID
+DevPathFilePath (
+ IN OUT POOL_PRINT *Str,
+ IN VOID *DevPath
+)
+{
+ FILEPATH_DEVICE_PATH *Fp;
+
+ Fp = DevPath;
+ CatPrint (Str, L"%s", Fp->PathName);
+}
+
+VOID
+DevPathMediaProtocol (
+ IN OUT POOL_PRINT *Str,
+ IN VOID *DevPath
+)
+{
+ MEDIA_PROTOCOL_DEVICE_PATH *MediaProt;
+
+ MediaProt = DevPath;
+ CatPrint (Str, L"%g", &MediaProt->Protocol);
+}
+
+VOID
+DevPathFvFilePath (
+ IN OUT POOL_PRINT *Str,
+ IN VOID *DevPath
+)
+{
+ MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFilePath;
+
+ FvFilePath = DevPath;
+ CatPrint (Str, L"%g", &FvFilePath->NameGuid);
+}
+
+VOID
+DevPathBssBss (
+ IN OUT POOL_PRINT *Str,
+ IN VOID *DevPath
+)
+{
+ BBS_BBS_DEVICE_PATH *Bbs;
+ CHAR16 *Type;
+
+ Bbs = DevPath;
+ switch (Bbs->DeviceType)
+ {
+ case BBS_TYPE_FLOPPY:
+ Type = L"Floppy";
+ break;
+
+ case BBS_TYPE_HARDDRIVE:
+ Type = L"Harddrive";
+ break;
+
+ case BBS_TYPE_CDROM:
+ Type = L"CDROM";
+ break;
+
+ case BBS_TYPE_PCMCIA:
+ Type = L"PCMCIA";
+ break;
+
+ case BBS_TYPE_USB:
+ Type = L"Usb";
+ break;
+
+ case BBS_TYPE_EMBEDDED_NETWORK:
+ Type = L"Net";
+ break;
+
+ default:
+ Type = L"?";
+ break;
+ }
+ //
+ // Since current Print function hasn't implemented %a (for ansi string)
+ // we will only print Unicode strings.
+ //
+ CatPrint (Str, L"Legacy-%s", Type);
+}
+
+VOID
+DevPathEndInstance (
+ IN OUT POOL_PRINT *Str,
+ IN VOID *DevPath
+)
+{
+ CatPrint (Str, L",");
+}
+
+VOID
+DevPathNodeUnknown (
+ IN OUT POOL_PRINT *Str,
+ IN VOID *DevPath
+)
+{
+ CatPrint (Str, L"?");
+}
+
+DEVICE_PATH_STRING_TABLE DevPathTable[] = {
+ HARDWARE_DEVICE_PATH,
+ HW_PCI_DP,
+ DevPathPci,
+ HARDWARE_DEVICE_PATH,
+ HW_PCCARD_DP,
+ DevPathPccard,
+ HARDWARE_DEVICE_PATH,
+ HW_MEMMAP_DP,
+ DevPathMemMap,
+ HARDWARE_DEVICE_PATH,
+ HW_VENDOR_DP,
+ DevPathVendor,
+ HARDWARE_DEVICE_PATH,
+ HW_CONTROLLER_DP,
+ DevPathController,
+ ACPI_DEVICE_PATH,
+ ACPI_DP,
+ DevPathAcpi,
+ MESSAGING_DEVICE_PATH,
+ MSG_ATAPI_DP,
+ DevPathAtapi,
+ MESSAGING_DEVICE_PATH,
+ MSG_SCSI_DP,
+ DevPathScsi,
+ MESSAGING_DEVICE_PATH,
+ MSG_FIBRECHANNEL_DP,
+ DevPathFibre,
+ MESSAGING_DEVICE_PATH,
+ MSG_1394_DP,
+ DevPath1394,
+ MESSAGING_DEVICE_PATH,
+ MSG_USB_DP,
+ DevPathUsb,
+ MESSAGING_DEVICE_PATH,
+ MSG_USB_CLASS_DP,
+ DevPathUsbClass,
+ MESSAGING_DEVICE_PATH,
+ MSG_I2O_DP,
+ DevPathI2O,
+ MESSAGING_DEVICE_PATH,
+ MSG_MAC_ADDR_DP,
+ DevPathMacAddr,
+ MESSAGING_DEVICE_PATH,
+ MSG_IPv4_DP,
+ DevPathIPv4,
+ MESSAGING_DEVICE_PATH,
+ MSG_IPv6_DP,
+ DevPathIPv6,
+ MESSAGING_DEVICE_PATH,
+ MSG_INFINIBAND_DP,
+ DevPathInfiniBand,
+ MESSAGING_DEVICE_PATH,
+ MSG_UART_DP,
+ DevPathUart,
+ MESSAGING_DEVICE_PATH,
+ MSG_VENDOR_DP,
+ DevPathVendor,
+ MEDIA_DEVICE_PATH,
+ MEDIA_HARDDRIVE_DP,
+ DevPathHardDrive,
+ MEDIA_DEVICE_PATH,
+ MEDIA_CDROM_DP,
+ DevPathCDROM,
+ MEDIA_DEVICE_PATH,
+ MEDIA_VENDOR_DP,
+ DevPathVendor,
+ MEDIA_DEVICE_PATH,
+ MEDIA_FILEPATH_DP,
+ DevPathFilePath,
+ MEDIA_DEVICE_PATH,
+ MEDIA_PROTOCOL_DP,
+ DevPathMediaProtocol,
+ MEDIA_DEVICE_PATH,
+ MEDIA_FV_FILEPATH_DP,
+ DevPathFvFilePath,
+ BBS_DEVICE_PATH,
+ BBS_BBS_DP,
+ DevPathBssBss,
+ END_DEVICE_PATH_TYPE,
+ END_INSTANCE_DEVICE_PATH_SUBTYPE,
+ DevPathEndInstance,
+ 0,
+ 0,
+ NULL
+ };
+
+CHAR16 *
+DevicePathToStr (
+ IN EFI_DEVICE_PATH_PROTOCOL *DevPath
+)
+/*++
+
+ Turns the Device Path into a printable string. Allcoates
+ the string from pool. The caller must SafeFreePool the returned
+ string.
+
+--*/
+{
+ POOL_PRINT Str;
+ EFI_DEVICE_PATH_PROTOCOL *DevPathNode;
+ VOID (*DumpNode) (POOL_PRINT *, VOID *);
+
+ UINTN Index;
+ UINTN NewSize;
+
+ EfiZeroMem (&Str, sizeof (Str));
+
+ if (DevPath == NULL)
+ {
+ goto Done;
+ }
+ //
+ // Unpacked the device path
+ //
+ DevPath = BdsLibUnpackDevicePath (DevPath);
+ ASSERT (DevPath);
+
+ //
+ // Process each device path node
+ //
+ DevPathNode = DevPath;
+ while (!IsDevicePathEnd (DevPathNode))
+ {
+ //
+ // Find the handler to dump this device path node
+ //
+ DumpNode = NULL;
+ for (Index = 0; DevPathTable[Index].Function; Index += 1)
+ {
+
+ if (DevicePathType (DevPathNode) == DevPathTable[Index].Type &&
+ DevicePathSubType (DevPathNode) == DevPathTable[Index].SubType
+ )
+ {
+ DumpNode = DevPathTable[Index].Function;
+ break;
+ }
+ }
+ //
+ // If not found, use a generic function
+ //
+ if (!DumpNode)
+ {
+ DumpNode = DevPathNodeUnknown;
+ }
+ //
+ // Put a path seperator in if needed
+ //
+ if (Str.len && DumpNode != DevPathEndInstance)
+ {
+ CatPrint (&Str, L"/");
+ }
+ //
+ // Print this node of the device path
+ //
+ DumpNode (&Str, DevPathNode);
+
+ //
+ // Next device path node
+ //
+ DevPathNode = NextDevicePathNode (DevPathNode);
+ }
+ //
+ // Shrink pool used for string allocation
+ //
+ gBS->FreePool (DevPath);
+
+Done:
+ NewSize = (Str.len + 1) * sizeof (CHAR16);
+ Str.str = ReallocatePool (Str.str, NewSize, NewSize);
+ ASSERT (Str.str != NULL);
+ Str.str[Str.len] = 0;
+ return Str.str;
+}
+
+EFI_DEVICE_PATH_PROTOCOL *
+LibDuplicateDevicePathInstance (
+ IN EFI_DEVICE_PATH_PROTOCOL *DevPath
+)
+/*++
+
+Routine Description:
+
+ Function creates a device path data structure that identically matches the
+ device path passed in.
+
+Arguments:
+
+ DevPath - A pointer to a device path data structure.
+
+Returns:
+
+ The new copy of DevPath is created to identically match the input.
+ Otherwise, NULL is returned.
+
+--*/
+{
+ EFI_DEVICE_PATH_PROTOCOL *NewDevPath;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePathInst;
+ EFI_DEVICE_PATH_PROTOCOL *Temp;
+ UINTN Size;
+
+ //
+ // get the size of an instance from the input
+ //
+ Temp = DevPath;
+ DevicePathInst = EfiDevicePathInstance (&Temp, &Size);
+
+ //
+ // Make a copy
+ //
+ NewDevPath = NULL;
+ if (Size)
+ {
+ NewDevPath = EfiLibAllocateZeroPool (Size);
+ ASSERT (NewDevPath != NULL);
+ }
+
+ if (NewDevPath)
+ {
+ EfiCopyMem (NewDevPath, DevicePathInst, Size);
+ }
+
+ return NewDevPath;
+}
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
diff --git a/Board/EM/MeWrapper/AmtWrapper/Dxe/KvmSupport.c b/Board/EM/MeWrapper/AmtWrapper/Dxe/KvmSupport.c
new file mode 100644
index 0000000..dab3fe4
--- /dev/null
+++ b/Board/EM/MeWrapper/AmtWrapper/Dxe/KvmSupport.c
@@ -0,0 +1,135 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+//**********************************************************************
+//
+// $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/KvmSupport.c 1 2/08/12 1:08a Klzhan $
+//
+// $Revision: 1 $
+//
+// $Date: 2/08/12 1:08a $
+//
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/KvmSupport.c $
+//
+// 1 2/08/12 1:08a Klzhan
+// Initial Check in
+//
+// 1 2/25/11 1:44a Klzhan
+// Initial Check-in
+//
+// 1 12/03/10 5:10a Klzhan
+// Initial Check-in.
+//
+//
+//**********************************************************************
+//<AMI_FHDR_START>
+//----------------------------------------------------------------------------
+//
+// Name: KvmSupport.c
+//
+// Description: Support routines for KVM init in the BDS
+//
+//
+//----------------------------------------------------------------------------
+//<AMI_FHDR_END>
+/*++
+ This file contains an 'Intel Peripheral Driver' and is
+ licensed for Intel CPUs and chipsets under the terms of your
+ license agreement with Intel or your vendor. This file may
+ be modified by the user, subject to additional terms of the
+ license agreement
+--*/
+
+/*++
+
+Copyright (c) 2009 Intel Corporation. All rights reserved
+This software and associated documentation (if any) is furnished
+under a license and may only be used or copied in accordance
+with the terms of the license. Except as permitted by such
+license, no part of this software or documentation may be
+reproduced, stored in a retrieval system, or transmitted in any
+form or by any means without the express written consent of
+Intel Corporation.
+
+
+Module Name:
+
+ KvmSupport.c
+
+Abstract:
+
+ Support routines for KVM init in the BDS
+
+--*/
+// Remove for RC 0.8
+/*
+#include "KvmSupport.h"
+
+BOOLEAN
+BdsKvmInitialization (
+ IN VOID
+ )
+*/
+/*++
+
+Routine Description:
+
+ Request KVM message.
+
+Arguments:
+
+ None.
+
+Returns:
+
+ True KVM Boot Option is an active.
+
+--*/
+/*
+{
+ EFI_STATUS Status;
+ UINT32 ResponseCode;
+
+ if(ActiveManagementEnableKvm() == TRUE) {
+ Status = HeciQueryKvmRequest(QUERY_REQUEST, &ResponseCode);
+ if (EFI_ERROR (Status)) {
+ gST->ConOut->ClearScreen (gST->ConOut);
+ gST->ConOut->OutputString (gST->ConOut, L"Error!! Times up and the KVM session was cancelled!!");
+ Status = HeciQueryKvmRequest(CANCEL_REQUEST, &ResponseCode);
+ } else if (ResponseCode == KVM_SESSION_CANCELLED) {
+ gST->ConOut->ClearScreen (gST->ConOut);
+ gST->ConOut->OutputString (gST->ConOut, L"Error!! The request has rejected and the KVM session was cancelled!!");
+ } else {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+*/
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//************************************************************************* \ No newline at end of file
diff --git a/Board/EM/MeWrapper/AmtWrapper/Dxe/KvmSupport.h b/Board/EM/MeWrapper/AmtWrapper/Dxe/KvmSupport.h
new file mode 100644
index 0000000..2058d6b
--- /dev/null
+++ b/Board/EM/MeWrapper/AmtWrapper/Dxe/KvmSupport.h
@@ -0,0 +1,119 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+//**********************************************************************
+//
+// $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/KvmSupport.h 1 2/08/12 1:08a Klzhan $
+//
+// $Revision: 1 $
+//
+// $Date: 2/08/12 1:08a $
+//
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/KvmSupport.h $
+//
+// 1 2/08/12 1:08a Klzhan
+// Initial Check in
+//
+// 1 2/25/11 1:44a Klzhan
+// Initial Check-in
+//
+// 1 12/03/10 5:10a Klzhan
+// Initial Check-in.
+//
+//
+//**********************************************************************
+//<AMI_FHDR_START>
+//----------------------------------------------------------------------------
+//
+// Name: KvmSupport.h
+//
+// Description: KVM BDS Support include file
+//
+//
+//----------------------------------------------------------------------------
+//<AMI_FHDR_END>
+/*++
+ This file contains an 'Intel Peripheral Driver' and is
+ licensed for Intel CPUs and chipsets under the terms of your
+ license agreement with Intel or your vendor. This file may
+ be modified by the user, subject to additional terms of the
+ license agreement
+--*/
+
+/*++
+
+Copyright (c) 2009 Intel Corporation. All rights reserved
+This software and associated documentation (if any) is furnished
+under a license and may only be used or copied in accordance
+with the terms of the license. Except as permitted by such
+license, no part of this software or documentation may be
+reproduced, stored in a retrieval system, or transmitted in any
+form or by any means without the express written consent of
+Intel Corporation.
+
+
+Module Name:
+
+ KvmSupport.h
+
+Abstract:
+
+ KVM BDS Support include file
+
+--*/
+#ifndef _KVM_SUPPORT_H_
+#define _KVM_SUPPORT_H_
+
+#include "Tiano.h"
+#include "EfiDriverLib.h"
+#include "BdsLib.h"
+#include "AmtLib.h"
+#include "MeLib.h"
+
+BOOLEAN
+BdsKvmInitialization (
+ IN VOID
+ )
+/*++
+
+Routine Description:
+
+ Request KVM message.
+
+Arguments:
+
+ None.
+
+Returns:
+
+ True KVM Boot Option is an active.
+
+--*/
+;
+#endif
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//************************************************************************* \ No newline at end of file
diff --git a/Board/EM/MeWrapper/AmtWrapper/Dxe/Performance.c b/Board/EM/MeWrapper/AmtWrapper/Dxe/Performance.c
new file mode 100644
index 0000000..deb51a4
--- /dev/null
+++ b/Board/EM/MeWrapper/AmtWrapper/Dxe/Performance.c
@@ -0,0 +1,431 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+//**********************************************************************
+//
+// $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/Performance.c 3 5/14/14 9:53p Tristinchou $
+//
+// $Revision: 3 $
+//
+// $Date: 5/14/14 9:53p $
+//
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/Performance.c $
+//
+// 3 5/14/14 9:53p Tristinchou
+// [TAG] EIP167030
+// [Category] Improvement
+// [Description] Remove the variable runtime attribute and keep original
+// attributes.
+//
+// 2 9/19/12 6:35a Klzhan
+// Fix Build error when Performance is enabled.
+//
+// 1 2/08/12 1:08a Klzhan
+// Initial Check in
+//
+// 2 9/21/11 9:00a Klzhan
+// [TAG] EIP69500
+// [Category] Bug Fix
+// [Severity] Minor
+// [Symptom] Compiler Error when DXE_PERFORMANCE is on
+// [RootCause] EDK Library doesn't support this function.
+//
+// 1 2/25/11 1:44a Klzhan
+// Initial Check-in
+//
+// 1 12/03/10 5:10a Klzhan
+// Initial Check-in.
+//
+//
+//**********************************************************************
+//<AMI_FHDR_START>
+//----------------------------------------------------------------------------
+//
+// Name: Performance.c
+//
+// Description: help to get the system performance
+//
+//
+//----------------------------------------------------------------------------
+//<AMI_FHDR_END>
+/*++
+
+Copyright (c) 2004 - 2005, Intel Corporation
+All rights reserved. This program and the accompanying materials
+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.
+
+Module Name:
+
+ Performance.c
+
+Abstract:
+
+ This file include the file which can help to get the system
+ performance, all the function will only include if the performance
+ switch is set.
+
+--*/
+
+#include "Tiano.h"
+#include "EfiDriverLib.h"
+#include "EfiPrintLib.h"
+
+#ifndef GUID_VARIABLE_DECLARATION
+#define GUID_VARIABLE_DECLARATION(Variable, Guid) extern EFI_GUID Variable
+#endif
+
+//#define EFI_DXE_PERFORMANCE
+
+#ifdef EFI_DXE_PERFORMANCE
+#include "EfiImage.h"
+#include "Include\Protocol\Performance.h"
+
+VOID
+ConvertChar16ToChar8 (
+ IN CHAR8 *Dest,
+ IN CHAR16 *Src
+ )
+{
+ while (*Src) {
+ *Dest++ = (UINT8) (*Src++);
+ }
+
+ *Dest = 0;
+}
+#include <token.h>
+#include EFI_ARCH_PROTOCOL_CONSUMER (Cpu)
+#include EFI_GUID_DEFINITION (GlobalVariable)
+
+
+extern EFI_STATUS GetTimerValue ( UINT64 *TimerValue );//extern UINT64 GetCpuTimer ();
+extern UINT64 DivU64x32 (UINT64 Dividend,UINTN Divisor,UINTN *Remainder);
+extern CHAR8 *EfiAsciiStrCpy (CHAR8 *Destination,CHAR8 *Source );
+
+#define Div64(a,b,c) DivU64x32(a,b,c)
+#define Strcpy(a,b) EfiAsciiStrCpy(a,b)
+//**********************************************************************
+// PERFORMANCE FUNCTIONS AND STRUCTURES
+//**********************************************************************
+
+#define EFI_PERF_PEI_ENTRY_MAX_NUM 50
+
+typedef struct {
+ CHAR8 Token[EFI_PERF_PDBFILENAME_LENGTH];
+ UINT32 Duration;
+} EFI_PERF_DATA;
+
+typedef struct {
+ UINT64 BootToOs;
+ UINT64 S3Resume;
+ UINT32 S3EntryNum;
+ EFI_PERF_DATA S3Entry[EFI_PERF_PEI_ENTRY_MAX_NUM];
+ UINT64 CpuFreq;
+ UINT64 BDSRaw;
+ UINT32 Count;
+ UINT32 Signiture;
+} EFI_PERF_HEADER;
+//*************************************************************************
+//<AMI_PHDR_START>
+//
+// Name: WriteBootToOsPerformanceData
+//
+// Description:
+// VOID WriteBootToOsPerformanceData() allocates a block of memory and
+// writes performance data into it.
+//
+// Input:
+// VOID.
+//
+// Output:
+// VOID.
+//
+// Modified:
+//
+// Referrals:
+// GetCpuTimer
+// Div64
+// Strcpy
+//
+// Notes:
+// This function must only be called once; by default, it is called by BDS.
+//
+//<AMI_PHDR_END>
+//*************************************************************************
+VOID WriteBootToOsPerformanceData (){
+ static EFI_PHYSICAL_ADDRESS AcpiLowMemoryBase = 0;
+ static BOOLEAN FirstCall = TRUE;
+
+ EFI_STATUS Status;
+ EFI_CPU_ARCH_PROTOCOL *Cpu;
+ EFI_PERFORMANCE_PROTOCOL *DrvPerf;
+ UINT32 AcpiLowMemoryLength;
+ UINT32 LimitCount;
+ EFI_PERF_HEADER PerfHeader;
+ EFI_PERF_DATA PerfData;
+ EFI_GAUGE_DATA *DumpData;
+ EFI_HANDLE *Handles;
+ UINTN NoHandles;
+ UINT8 *Ptr;
+ UINT8 *PdbFileName;
+ UINT32 Index;
+ UINT64 Ticker;
+ UINT64 Freq;
+ UINT32 Duration;
+ UINT64 CurrentTicker;
+ UINT64 TimerPeriod;
+ EFI_GUID gEfiGlobalVariableGuid = EFI_GLOBAL_VARIABLE_GUID;
+ IN CHAR8 *Dest;
+ IN CHAR16 *Src;
+ UINT32 VarAttr;
+ UINTN VarSize;
+
+
+
+ // Retrive time stamp count as early as possilbe
+ GetTimerValue(&Ticker);//Ticker = GetCpuTimer (); //Bruce[c]
+
+ // Allocate a block of memory that contain performance data to OS for the first call
+ if(FirstCall)
+ {
+ Status = gBS->AllocatePages (
+ AllocateAnyPages,
+ EfiRuntimeServicesData,
+ 4,
+ &AcpiLowMemoryBase
+ );
+ if (EFI_ERROR (Status)) {
+ return ;
+ }
+ }
+
+ AcpiLowMemoryLength = EFI_PAGES_TO_SIZE(4);
+
+ Ptr = (UINT8 *) ((UINT32) AcpiLowMemoryBase + sizeof (EFI_PERF_HEADER));
+ LimitCount = (AcpiLowMemoryLength - sizeof (EFI_PERF_HEADER)) / sizeof (EFI_PERF_DATA);
+
+ // Get performance architecture protocol
+ Status = gBS->LocateProtocol (
+ &gEfiPerformanceProtocolGuid,
+ NULL,
+ &DrvPerf
+ );
+ if (EFI_ERROR (Status)) {
+ gBS->FreePages (AcpiLowMemoryBase, 4);
+ return ;
+ }
+ // Initialize performance data structure
+ gBS->SetMem (&PerfHeader, sizeof (EFI_PERF_HEADER), 0);
+
+ // Get CPU frequency
+ Status = gBS->LocateProtocol (
+ &gEfiCpuArchProtocolGuid,
+ NULL,
+ &Cpu
+ );
+ if (EFI_ERROR (Status)) {
+ gBS->FreePages (AcpiLowMemoryBase, 4);
+ return ;
+ }
+ // Get Cpu Frequency
+ Status = Cpu->GetTimerValue (Cpu, 0, &(CurrentTicker), &TimerPeriod);
+ if (EFI_ERROR (Status)) {
+ gBS->FreePages (AcpiLowMemoryBase, 4);
+ return ;
+ }
+
+ Freq = Div64(1000000000000, (UINTN) TimerPeriod, NULL);
+ PerfHeader.CpuFreq = Freq;
+
+ // Record current raw performance data
+ PerfHeader.BDSRaw = Ticker;
+
+ // Put Detailed performance data into memory
+ Handles = NULL;
+ Status = gBS->LocateHandleBuffer (
+ AllHandles,
+ NULL,
+ NULL,
+ &NoHandles,
+ &Handles
+ );
+ if (EFI_ERROR (Status)) {
+ gBS->FreePages (AcpiLowMemoryBase, 1);
+ return ;
+ }
+
+ // Get DXE drivers performance
+ for (Index = 0; Index < NoHandles; Index++) {
+ Ticker = 0;
+ PdbFileName = NULL;
+ DumpData = DrvPerf->GetGauge (
+ DrvPerf, // Context
+ NULL, // Handle
+ NULL, // Token
+ NULL, // Host
+ NULL // PrecGauge
+ );
+ while (DumpData) {
+ if (DumpData->Handle == Handles[Index]) {
+ PdbFileName = &(DumpData->PdbFileName[0]);
+ if (DumpData->StartTick < DumpData->EndTick) {
+ Ticker += (DumpData->EndTick - DumpData->StartTick);
+ }
+ }
+
+ DumpData = DrvPerf->GetGauge (
+ DrvPerf, // Context
+ NULL, // Handle
+ NULL, // Token
+ NULL, // Host
+ DumpData // PrecGauge
+ );
+ }
+
+ Duration = (UINT32) Div64 (
+ Ticker,
+ (UINT32) Freq,
+ NULL
+ );
+
+ if (Duration > 0) {
+ gBS->SetMem (&PerfData, sizeof (EFI_PERF_DATA), 0);
+
+ if (PdbFileName != NULL) {
+ Strcpy (PerfData.Token, PdbFileName);
+ }
+
+ PerfData.Duration = Duration;
+
+ gBS->CopyMem (Ptr, &PerfData, sizeof (EFI_PERF_DATA));
+ Ptr += sizeof (EFI_PERF_DATA);
+
+ PerfHeader.Count++;
+ if (PerfHeader.Count == LimitCount) {
+ goto Done;
+ }
+ }
+ }
+
+ gBS->FreePool (Handles);
+
+ // Get inserted performance data
+ DumpData = DrvPerf->GetGauge (
+ DrvPerf, // Context
+ NULL, // Handle
+ NULL, // Token
+ NULL, // Host
+ NULL // PrecGauge
+ );
+ while (DumpData) {
+ if ((DumpData->Handle) || (DumpData->StartTick > DumpData->EndTick)) {
+ DumpData = DrvPerf->GetGauge (
+ DrvPerf, // Context
+ NULL, // Handle
+ NULL, // Token
+ NULL, // Host
+ DumpData // PrecGauge
+ );
+ continue;
+ }
+
+ gBS->SetMem (&PerfData, sizeof (EFI_PERF_DATA), 0);
+
+ //convert CHAR16 string to CHAR8 string
+ Src = DumpData->Token;
+ Dest = (UINT8 *) PerfData.Token;
+ while (*Src) *Dest++ = (UINT8) (*Src++);
+ *Dest = 0;
+
+ PerfData.Duration = (UINT32) Div64 (
+ DumpData->EndTick - DumpData->StartTick,
+ (UINT32) Freq,
+ NULL
+ );
+
+ gBS->CopyMem(Ptr, &PerfData, sizeof (EFI_PERF_DATA));
+ Ptr += sizeof (EFI_PERF_DATA);
+
+ PerfHeader.Count++;
+ if (PerfHeader.Count == LimitCount) {
+ goto Done;
+ }
+
+ DumpData = DrvPerf->GetGauge (
+ DrvPerf, // Context
+ NULL, // Handle
+ NULL, // Token
+ NULL, // Host
+ DumpData // PrecGauge
+ );
+ }
+
+Done:
+ PerfHeader.Signiture = 0x66726550;
+
+ // Put performance data to memory
+ gBS->CopyMem (
+ (UINTN *) (UINTN) AcpiLowMemoryBase,
+ &PerfHeader,
+ sizeof (EFI_PERF_HEADER)
+ );
+
+ if(FirstCall)
+ {
+ VarAttr = 0;
+ VarSize = 0;
+
+ Status = gRT->GetVariable(
+ L"PerfDataMemAddr",
+ &gEfiGlobalVariableGuid,
+ &VarAttr,
+ &VarSize,
+ NULL );
+ if( EFI_ERROR(Status) && Status != EFI_BUFFER_TOO_SMALL )
+ {
+ VarAttr = EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS;
+ VarSize = sizeof(UINT32);
+ }
+
+ gRT->SetVariable (
+ L"PerfDataMemAddr",
+ &gEfiGlobalVariableGuid,
+ VarAttr,
+ VarSize,
+ (VOID *) &AcpiLowMemoryBase );
+
+ FirstCall = FALSE;
+ }
+}
+
+#endif
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
diff --git a/Board/EM/MeWrapper/AmtWrapper/Dxe/Performance.h b/Board/EM/MeWrapper/AmtWrapper/Dxe/Performance.h
new file mode 100644
index 0000000..4fffd9e
--- /dev/null
+++ b/Board/EM/MeWrapper/AmtWrapper/Dxe/Performance.h
@@ -0,0 +1,87 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+//**********************************************************************
+//
+// $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/Performance.h 1 2/08/12 1:08a Klzhan $
+//
+// $Revision: 1 $
+//
+// $Date: 2/08/12 1:08a $
+//
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtWrapperDxe/Performance.h $
+//
+// 1 2/08/12 1:08a Klzhan
+// Initial Check in
+//
+// 1 2/25/11 1:44a Klzhan
+// Initial Check-in
+//
+// 1 12/03/10 5:10a Klzhan
+// Initial Check-in.
+//
+//
+//**********************************************************************
+//<AMI_FHDR_START>
+//----------------------------------------------------------------------------
+//
+// Name: Performance.h
+//
+// Description: This file included the performance relete function header
+// and definition.
+//
+//
+//----------------------------------------------------------------------------
+//<AMI_FHDR_END>
+/*++
+
+Copyright (c) 2004, Intel Corporation
+All rights reserved. This program and the accompanying materials
+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.
+
+Module Name:
+
+ Performance.h
+
+Abstract:
+
+ This file included the performance relete function header and
+ definition.
+
+--*/
+
+#ifndef _PERF_H_
+#define _PERF_H_
+
+#endif
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//************************************************************************* \ No newline at end of file