diff options
Diffstat (limited to 'Board/EM/RapidStartWrapper/Library')
21 files changed, 4218 insertions, 0 deletions
diff --git a/Board/EM/RapidStartWrapper/Library/RapidStartCommonLib/RapidStartCommonLib.c b/Board/EM/RapidStartWrapper/Library/RapidStartCommonLib/RapidStartCommonLib.c new file mode 100644 index 0000000..666f3a7 --- /dev/null +++ b/Board/EM/RapidStartWrapper/Library/RapidStartCommonLib/RapidStartCommonLib.c @@ -0,0 +1,916 @@ +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2012, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** + +//********************************************************************** +// $Header: /Alaska/SOURCE/Modules/Intel Fast Flash Standby/iRST_SharkBay/RapidStartWrapper/RapidStartCommonLib/RapidStartCommonLib.c 2 11/20/12 2:46a Bensonlai $ +// +// $Revision: 2 $ +// +// $Date: 11/20/12 2:46a $ +//********************************************************************** +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/Intel Fast Flash Standby/iRST_SharkBay/RapidStartWrapper/RapidStartCommonLib/RapidStartCommonLib.c $ +// +// 2 11/20/12 2:46a Bensonlai +// [TAG] EIP107013 +// [Category] Improvement +// [Description] Update Shark Bay Rapid Start Reference Code Version +// 0.8.0.0 +// [Files] RapidStartCommonLib.sdl +// RapidStartCommonLib.mak +// RapidStartCommonLib.c +// RapidStartCommonLib.h +// RapidStartCommonLib.inf +// RapidStartCommonLib.cif +// +// 1 10/15/12 4:40a Bensonlai +// [TAG] None +// [Category] Improvement +// [Description] [Category] Improvement +// [Severity] Important +// [Description] Rename all IFFS sting to Rapid Start. +// [Files] Board\EM\RapidStartWrapper\*.*, ReferenceCode\RapidStart\*.* +// [Files] RapidStartCommonLib.cif +// RapidStartCommonLib.sdl +// RapidStartCommonLib.mak +// RapidStartCommonLib.c +// RapidStartCommonLib.h +// RapidStartCommonLib.inf +// +//********************************************************************** +//<AMI_FHDR_START> +// +// Name: RapidStartCommonLib.c +// +// Description: RapidStart Common code library. +// +//<AMI_FHDR_END> +//********************************************************************** + +#if !defined(EDK_RELEASE_VERSION) || (EDK_RELEASE_VERSION < 0x00020000) +#include "EdkIIGlueBase.h" +#include "EfiCommon.h" +#include <PchRegs.h> +#include "RapidStartCommonLib.h" +#include "PchPlatformLib.h" +#endif +#define R_PCH_RTC_INDEX_ALT 0x74 +#define R_PCH_RTC_TARGET_ALT 0x75 +#define R_PCH_RTC_EXT_INDEX_ALT 0x76 +#define R_PCH_RTC_EXT_TARGET_ALT 0x77 + +#define R_PCH_RTC_REGC 0x0C +#define B_PCH_RTC_REGC_AF 0x20 + +#define RTC_INDEX_MASK 0x7F +#define RTC_BANK_SIZE 0x80 + +#define R_PCH_RTC_SECOND 0x00 +#define R_PCH_RTC_ALARM_SECOND 0x01 +#define R_PCH_RTC_MINUTE 0x02 +#define R_PCH_RTC_ALARM_MINUTE 0x03 +#define R_PCH_RTC_HOUR 0x04 +#define R_PCH_RTC_ALARM_HOUR 0x05 +#define R_PCH_RTC_DAY_OF_WEEK 0x06 +#define R_PCH_RTC_DAY_OF_MONTH 0x07 +#define R_PCH_RTC_MONTH 0x08 +#define R_PCH_RTC_YEAR 0x09 + +/// +/// Non-volatile RapidStart flag must be kept within locked CMOS range +/// to prevent triggering RapidStart resume by manipulating CMOS in OS runtime, +/// and mitigate attacks on SMRAM image content. +/// +#ifndef FFS_NV_FLAG_REG +#define FFS_NV_FLAG_REG 0x88 +#endif +/// +/// Some runtime configuration settings (e.g. enabled wake events must be +/// available to determine RapidStart transition before memory is initialized. +/// This CMOS register is used to store these settings, thus must be +/// within unlocked range. +/// +#ifndef FFS_NV_CONFIG_REG +#define FFS_NV_CONFIG_REG 0x47 +#endif +/// +/// Defines for KSC common code +/// Timeout if KSC command/data fails +/// +#define KSC_TIME_OUT 0x20000 +#define KSC_WAIT_PERIOD 15 +/// +/// The Keyboard and System management Controller (KSC) implements a standard 8042 keyboard +/// controller interface at ports 0x60/0x64 and a ACPI compliant system management controller +/// at ports 0x62/0x66. Port 0x66 is the command and status port, port 0x62 is the data port. +/// +#define KSC_D_PORT 0x62 +#define KSC_C_PORT 0x66 + +// +// Status Port 0x62 +// +#define KSC_S_OVR_TMP 0x80 ///< Current CPU temperature exceeds the threshold +#define KSC_S_SMI_EVT 0x40 ///< SMI event is pending +#define KSC_S_SCI_EVT 0x20 ///< SCI event is pending +#define KSC_S_BURST 0x10 ///< KSC is in burst mode or normal mode +#define KSC_S_CMD 0x08 ///< Byte in data register is command/data +#define KSC_S_IGN 0x04 ///< Ignored +#define KSC_S_IBF 0x02 ///< Input buffer is full/empty +#define KSC_S_OBF 0x01 ///< Output buffer is full/empty +#define KSC_CMD_SET_CRITICAL_BATTERY_WAKE_THRESHOLD 0x34 +#define DISABLE_CRITICAL_BATTERY_WAKE 0 +#define MINIMAL_CRITICAL_BATTERY_WAKE_THRESHOLD 15 +#define KSC_CMD_GET_WAKE_STATUS 0x35 +#define KSC_WAKE_STATUS_CRITICAL_BATTERY 1 +#define KSC_CMD_CLEAR_WAKE_STATUS 0x36 + +/** + Read specific RTC/CMOS RAM + + @param[in] Location Point to RTC/CMOS RAM offset for read + + @retval The data of specific location in RTC/CMOS RAM. +**/ +UINT8 +RtcRead ( + IN UINT8 Location + ) +{ + UINT8 RtcIndexPort; + UINT8 RtcDataPort; + + /// + /// CMOS access registers (using alternative access not to handle NMI bit) + /// + if (Location < RTC_BANK_SIZE) { + /// + /// First bank + /// + RtcIndexPort = R_PCH_RTC_INDEX_ALT; + RtcDataPort = R_PCH_RTC_TARGET_ALT; + } else { + /// + /// Second bank + /// + RtcIndexPort = R_PCH_RTC_EXT_INDEX_ALT; + RtcDataPort = R_PCH_RTC_EXT_TARGET_ALT; + } + + IoWrite8 (RtcIndexPort, Location & RTC_INDEX_MASK); + return IoRead8 (RtcDataPort); +} + +/** + Write specific RTC/CMOS RAM + + @param[in] Location Point to RTC/CMOS RAM offset for write + @param[in] Value The data that will be written to RTC/CMOS RAM +**/ +VOID +RtcWrite ( + IN UINT8 Location, + IN UINT8 Value + ) +{ + UINT8 RtcIndexPort; + UINT8 RtcDataPort; + + /// + /// CMOS access registers (using alternative access not to handle NMI bit) + /// + if (Location < RTC_BANK_SIZE) { + /// + /// First bank + /// + RtcIndexPort = R_PCH_RTC_INDEX_ALT; + RtcDataPort = R_PCH_RTC_TARGET_ALT; + } else { + /// + /// Second bank + /// + RtcIndexPort = R_PCH_RTC_EXT_INDEX_ALT; + RtcDataPort = R_PCH_RTC_EXT_TARGET_ALT; + } + + IoWrite8 (RtcIndexPort, Location & RTC_INDEX_MASK); + IoWrite8 (RtcDataPort, Value); +} + +/** + Read word from specific RTC/CMOS RAM + + @param[in] Location Point to RTC/CMOS RAM offset for read + + @retval The data of specific location in RTC/CMOS RAM. +**/ +UINT16 +RtcRead16 ( + IN UINT8 Location + ) +{ + return RtcRead (Location) | (RtcRead (Location + 1) << 8); +} + +/** + Write word to specific RTC/CMOS RAM + + @param[in] Location Point to RTC/CMOS RAM offset for write + @param[in] Value The data that will be written to RTC/CMOS RAM +**/ +VOID +RtcWrite16 ( + IN UINT8 Location, + IN UINT16 Value + ) +{ + RtcWrite (Location, (UINT8) Value); + RtcWrite (Location + 1, (UINT8) (Value >> 8)); +} + +/** + Initialize RTC Timer +**/ +VOID +RtcInit ( + VOID + ) +{ + UINT8 RegB; + RegB = RtcRead (R_PCH_RTC_REGB); + RegB |= B_PCH_RTC_REGB_HOURFORM; + RegB &= ~B_PCH_RTC_REGB_DM; + RtcWrite (R_PCH_RTC_REGB, RegB); +} + +/** + Wait for updating RTC process finished. +**/ +STATIC +VOID +RtcWaitEndOfUpdate ( + VOID + ) +{ + while (RtcRead (R_PCH_RTC_REGA) & B_PCH_RTC_REGA_UIP) { + } +} + +/** + Get current RTC time + + @param[out] tm RTC time structure including Second, Minute and Hour. + + @retval EFI_SUCCESS Operation successfully and RTC_TIME structure contained current time. +**/ +EFI_STATUS +RtcGetTime ( + OUT RTC_TIME *tm + ) +{ + ASSERT (tm != NULL); + RtcWaitEndOfUpdate (); + tm->Second = BcdToDecimal8 (RtcRead (R_PCH_RTC_SECOND)); + tm->Minute = BcdToDecimal8 (RtcRead (R_PCH_RTC_MINUTE)); + tm->Hour = BcdToDecimal8 (RtcRead (R_PCH_RTC_HOUR)); + tm->Date = BcdToDecimal8 (RtcRead (R_PCH_RTC_DAY_OF_MONTH)); + tm->Month = BcdToDecimal8 (RtcRead (R_PCH_RTC_MONTH)); + tm->Year = (UINT16) BcdToDecimal8 (RtcRead (R_PCH_RTC_YEAR)) + 2000; + return EFI_SUCCESS; +} + +/** + Check if RTC Alarm has been enabled. + + @retval TRUE RTC Alarm is enabled + @retval FALSE RTC Alarm is not enabled +**/ +BOOLEAN +RtcIsAlarmEnabled ( + VOID + ) +{ + return (RtcRead (R_PCH_RTC_REGB) & B_PCH_RTC_REGB_AIE) != 0; +} + +/** + Get current RTC Alarm time. + + @param[out] tm A structure which will be updated with current RTC Alarm time + + @retval EFI_NOT_STARTED RTC Alarm has not been enabled yet. + @retval EFI_SUCCESS RTC Alarm enabled and RTC_TIME structure contain current Alarm time setting. +**/ +EFI_STATUS +RtcGetAlarm ( + OUT RTC_TIME *tm + ) +{ + ASSERT (tm != NULL); + if (!RtcIsAlarmEnabled ()) { + return EFI_NOT_STARTED; + } + + RtcWaitEndOfUpdate (); + tm->Second = BcdToDecimal8 (RtcRead (R_PCH_RTC_ALARM_SECOND)); + tm->Minute = BcdToDecimal8 (RtcRead (R_PCH_RTC_ALARM_MINUTE)); + tm->Hour = BcdToDecimal8 (RtcRead (R_PCH_RTC_ALARM_HOUR)); + tm->Date = BcdToDecimal8 (RtcRead (R_PCH_RTC_REGD) & 0x3F); + tm->Month = 0; + tm->Year = 0; + return EFI_SUCCESS; +} + +/** + Set RTC Alarm with specific time + + @param[in] tm A time interval structure which will be used to setup an RTC Alarm + + @retval EFI_SUCCESS RTC Alarm has been enabled with specific time interval +**/ +EFI_STATUS +RtcSetAlarm ( + IN RTC_TIME *tm + ) +{ + UINT8 RegB; + + ASSERT (tm != NULL); + + RegB = RtcRead (R_PCH_RTC_REGB); + + RtcWaitEndOfUpdate (); + + /// + /// Inhibit update cycle + /// + RtcWrite (R_PCH_RTC_REGB, RegB | B_PCH_RTC_REGB_SET); + + RtcWrite (R_PCH_RTC_ALARM_SECOND, DecimalToBcd8 (tm->Second)); + RtcWrite (R_PCH_RTC_ALARM_MINUTE, DecimalToBcd8 (tm->Minute)); + RtcWrite (R_PCH_RTC_ALARM_HOUR, DecimalToBcd8 (tm->Hour)); + RtcWrite (R_PCH_RTC_REGD, DecimalToBcd8 (tm->Date)); + + /// + /// Allow update cycle and enable wake alarm + /// + RegB &= ~B_PCH_RTC_REGB_SET; + RtcWrite (R_PCH_RTC_REGB, RegB | B_PCH_RTC_REGB_AIE); + + return EFI_SUCCESS; +} + +/** + Check if CRB KSC controller present or not. + + @retval EFI_SUCCESS - CRB KSC present. + @retval EFI_DEVICE_ERROR - CRB KSC not present. +**/ +STATIC +EFI_STATUS +CheckKscPresence ( + VOID + ) +{ + if (IoRead8 (KSC_C_PORT) == 0xff) { + return EFI_DEVICE_ERROR; + } else { + return EFI_SUCCESS; + } +} + +/** + Receives status from Keyboard System Controller. + + @param[in] KscStatus - Status byte to receive + + @retval EFI_SUCCESS - Always success + @retval EFI_DEVICE_ERROR - KSC not present +**/ +STATIC +EFI_STATUS +ReceiveKscStatus ( + UINT8 *KscStatus + ) +{ + /// + /// Verify if KscLib has been initialized, NOT if EC dose not exist. + /// + if (CheckKscPresence () != EFI_SUCCESS) { + return EFI_DEVICE_ERROR; + } + /// + /// Read and return the status + /// + *KscStatus = IoRead8 (KSC_C_PORT); + + return EFI_SUCCESS; +} + +/** + Sends command to Keyboard System Controller. + + @param[in] Command - Command byte to send + + @retval EFI_SUCCESS - Command success + @retval EFI_DEVICE_ERROR - Command error +**/ +STATIC +EFI_STATUS +SendKscCommand ( + UINT8 Command + ) +{ + UINTN Index; + UINT8 KscStatus; + + KscStatus = 0; + /// + /// Verify if KscLib has been initialized, NOT if EC dose not exist. + /// + if (CheckKscPresence () != EFI_SUCCESS) { + return EFI_DEVICE_ERROR; + } + + Index = 0; + + /// + /// Wait for KSC to be ready (with a timeout) + /// + ReceiveKscStatus (&KscStatus); + while (((KscStatus & KSC_S_IBF) != 0) && (Index < KSC_TIME_OUT)) { + PchPmTimerStall (KSC_WAIT_PERIOD); + ReceiveKscStatus (&KscStatus); + Index++; + } + + if (Index >= KSC_TIME_OUT) { + return EFI_DEVICE_ERROR; + } + /// + /// Send the KSC command + /// + IoWrite8 (KSC_C_PORT, Command); + + return EFI_SUCCESS; +} + +/** + Sends data to Keyboard System Controller. + + @param[in] Data - Data byte to send + + @retval EFI_SUCCESS - Success + @retval EFI_DEVICE_ERROR - Error +**/ +STATIC +EFI_STATUS +SendKscData ( + UINT8 Data + ) +{ + UINTN Index; + UINT8 KscStatus; + + /// + /// Verify if KscLib has been initialized, NOT if EC dose not exist. + /// + if (CheckKscPresence () != EFI_SUCCESS) { + return EFI_DEVICE_ERROR; + } + + Index = 0; + + /// + /// Wait for KSC to be ready (with a timeout) + /// + ReceiveKscStatus (&KscStatus); + while (((KscStatus & KSC_S_IBF) != 0) && (Index < KSC_TIME_OUT)) { + PchPmTimerStall (KSC_WAIT_PERIOD); + ReceiveKscStatus (&KscStatus); + Index++; + } + + if (Index >= KSC_TIME_OUT) { + return EFI_DEVICE_ERROR; + } + /// + /// Send the data and return + /// + IoWrite8 (KSC_D_PORT, Data); + return EFI_SUCCESS; +} + +/** + Receives data from Keyboard System Controller. + + @param[in] Data - Data byte received + + @retval EFI_SUCCESS - Read success + @retval EFI_DEVICE_ERROR - Read error +**/ +STATIC +EFI_STATUS +ReceiveKscData ( + UINT8 *Data + ) +{ + UINTN Index; + UINT8 KscStatus; + + /// + /// Verify if KscLib has been initialized, NOT if EC dose not exist. + /// + if (CheckKscPresence () != EFI_SUCCESS) { + return EFI_DEVICE_ERROR; + } + + Index = 0; + + /// + /// Wait for KSC to be ready (with a timeout) + /// + ReceiveKscStatus (&KscStatus); + while (((KscStatus & KSC_S_OBF) == 0) && (Index < KSC_TIME_OUT)) { + PchPmTimerStall (KSC_WAIT_PERIOD); + ReceiveKscStatus (&KscStatus); + Index++; + } + + if (Index >= KSC_TIME_OUT) { + return EFI_DEVICE_ERROR; + } + /// + /// Read KSC data and return + /// + *Data = IoRead8 (KSC_D_PORT); + + return EFI_SUCCESS; +} + +/** + Enable or disable critical battery wakeup event. + + @param[in] Enabled - Enable or disable Critical Battery wakeup event. +**/ +VOID +RapidStartInitializeCriticalBatteryWakeupEvent ( + IN BOOLEAN Enabled + ) +{ + UINT8 Threshold; + /// + /// If platform doesn't have KSC controller, skip all KSC commands. + /// + if (CheckKscPresence () != EFI_SUCCESS) { + return ; + } + /// + /// This function can be modified to always enable critical battery event if platform design required. + /// If platform code already handled critical battery wakeup event, refer to spec and ensure required + /// Minimal battery capacity threshold implemented for RapidStart Entry transition. + /// + if (Enabled == FALSE) { + /// + /// Disable critical battery wake event. + /// + Threshold = DISABLE_CRITICAL_BATTERY_WAKE; + } else { + // + // Enable critical battery wake event. + // + Threshold = RtcRead (FFS_CBTH_DATA_REG); + } + + SendKscCommand (KSC_CMD_SET_CRITICAL_BATTERY_WAKE_THRESHOLD); + SendKscData (Threshold); +} + +/** + Check if current wakeup is because of critical low battery. + + @retval TRUE - Current wakeup source is critical low battery event. + @retval FALSE - The wakeup source is not critical low battery event. +**/ +BOOLEAN +RapidStartCheckCriticalBatteryWakeupEvent ( + VOID + ) +{ + UINT8 WakeStatus; + + /// + /// If platform doesn't have KSC controller, return FALSE + /// + if (CheckKscPresence () != EFI_SUCCESS) { + return FALSE; + } + + SendKscCommand (KSC_CMD_GET_WAKE_STATUS); + /// + /// if get wake status failed, return false + /// + if (ReceiveKscData (&WakeStatus) != EFI_SUCCESS) { + return FALSE; + } + + if (WakeStatus & KSC_WAKE_STATUS_CRITICAL_BATTERY) { + return TRUE; + } else { + return FALSE; + } +} + +/** + Clear all wakeup status. +**/ +VOID +RapidStartClearAllKscWakeStatus ( + VOID + ) +{ + /// + /// If platform doesn't have KSC controller, skip all KSC commands. + /// + if (CheckKscPresence () != EFI_SUCCESS) { + return ; + } + + SendKscCommand (KSC_CMD_CLEAR_WAKE_STATUS); +} + +#ifdef RAPID_START_WHOLE_MEMORY_CHECK +/** + Calculate CRC32 value for inputed data + + @param[in] Data - data to calc on CRC + @param[in] DataSize - data size + @param[in] Crc32 - crc value. + @param[in] RapidStartData - A data buffer stored RapidStart internal non-volatile information. + @param[in] CrcTable - The base CRC table + + @retval EFI_INVALID_PARAMETER inputed parameters are invalid + @retval EFI_SUCCESS Process successfully and CRC value has been passed by Crc32 parameter. +**/ +EFI_STATUS +RapidStartCalculateCrc32 ( + IN UINT8 *Data, + IN UINT32 DataSize, + IN UINT32 *Crc32, + IN RAPID_START_PERSISTENT_DATA *RapidStartData, + IN UINT32 *CrcTable + ) +{ + UINT32 i; + UINT32 crc; + + crc = (UINT32) -1; + + if (!DataSize || !Crc32) { + return EFI_INVALID_PARAMETER; + } + /// + /// Calculate the CRC + /// + for (i = 0; i < DataSize; i++) { + if (((Data + i) >= (UINT8 *) (UINTN) RapidStartData->AcpiReservedMemoryBase) && + ((Data + i) < (UINT8 *) (UINTN) (RapidStartData->AcpiReservedMemoryBase + RapidStartData->AcpiReservedMemorySize)) + ) { + continue; + } + + if (((Data + i) < (UINT8 *) (UINTN) RapidStartData->RapidStartMem) || + ((Data + i) >= (UINT8 *) (UINTN) (RapidStartData->RapidStartMem + RapidStartData->RapidStartMemSize)) + ) { + crc = (crc >> 8) ^ CrcTable[(UINT8) crc ^ ((UINT8 *) Data)[i]]; + } + } + + *Crc32 = ~crc; + + return EFI_SUCCESS; +} + +/** + Log CRC32 mismatched address and length + + @param[in] MismatchedBaseAddress - Memory address caused mismatched CRC32 + @param[in] MismatchedDataSize - memory length for calculating CRC32 + + @retval EFI_SUCCESS Process successfully +**/ +EFI_STATUS +LogCrc32MismatchedAddress ( + UINTN MismatchedBaseAddress, + UINT32 MismatchedDataSize + ) +{ + return EFI_SUCCESS; +} + +/** + Log or compare CRC32 value for specific memory range. + + @param[in] IsComparingCrc32 - FALSE to save CRC32 value into buffer. TRUE to compare CRC32 value with pre-saved value in buffer. + @param[in] BaseAddress - Base memory address for logging or checking CRC32 + @param[in] EndAddress - End memory address for logging or checking CRC32 + @param[in] RapidStartData - A data buffer stored RapidStart internal non-volatile information. +**/ +VOID +SaveOrCompareCrc32 ( + IN BOOLEAN IsComparingCrc32, + IN UINTN BaseAddress, + IN UINTN EndAddress, + IN RAPID_START_PERSISTENT_DATA *RapidStartData + ) +{ + UINT32 *Crc32Record; + UINT32 *Crc32RecordPointer; + UINT32 Crc32; + UINT32 DataSize; + volatile UINTN Crc32MismatchedAddress; + volatile UINT32 Crc32MismatchedSize; + UINT32 Crc32RecordSizeInDword; + UINT32 CrcTable[256]; + UINT32 i; + UINT32 j; + + /// + /// init the CRC base table + /// + for (i = 0; i < 256; i++) { + CrcTable[i] = i; + for (j = 8; j > 0; j--) { + CrcTable[i] = (CrcTable[i] & 1) ? (CrcTable[i] >> 1) ^ 0xedb88320 : CrcTable[i] >> 1; + } + } + + Crc32Record = RAPID_START_CRC32_RECORD_PTR (RapidStartData); + Crc32RecordPointer = Crc32Record + (UINT32) DivU64x32 (BaseAddress, MEMORY_CRC32_GRANULARITY); + Crc32RecordSizeInDword = (UINT32) RShiftU64 (RapidStartData->Crc32RecordSize, 2); + while (BaseAddress < EndAddress) { + ASSERT (Crc32RecordPointer < (Crc32Record + Crc32RecordSizeInDword)); + if ((EndAddress - BaseAddress) >= MEMORY_CRC32_GRANULARITY) { + DataSize = MEMORY_CRC32_GRANULARITY; + } else { + DataSize = (UINT32) (EndAddress - BaseAddress); + } + /// + /// indicate which address is handling + /// + IoWrite16 (0x80, (UINT16) DivU64x32 (BaseAddress, MEMORY_CRC32_GRANULARITY)); + RapidStartCalculateCrc32 ((UINT8 *) BaseAddress, DataSize, &Crc32, RapidStartData, CrcTable); + if (IsComparingCrc32) { + /// + /// Send debug message and log error when mismatch data is found + /// + if (Crc32 != *(Crc32RecordPointer)) { + if (sizeof (BaseAddress) == 4) { + DEBUG ((EFI_D_ERROR, "CRC_CHECK: Address=%08X, ", BaseAddress)); + } else { + DEBUG ((EFI_D_ERROR, "CRC_CHECK: Address=%010lX, ", BaseAddress)); + } + + DEBUG ((EFI_D_ERROR, "Size=%08X, ", DataSize)); + DEBUG ((EFI_D_ERROR, "current CRC32=%08X, Expected CRC32=%08X, ", Crc32, *(Crc32RecordPointer))); + DEBUG ((EFI_D_ERROR, "Crc32Pointer=%08X\n", Crc32RecordPointer)); + DEBUG ((EFI_D_ERROR, "\nFound mismatched CRC32!!\n\n")); + Crc32MismatchedAddress = BaseAddress; + Crc32MismatchedSize = DataSize; + LogCrc32MismatchedAddress (Crc32MismatchedAddress, Crc32MismatchedSize); + } + } else { + /// + /// Save CRC result for comparison during RapidStart exit + /// + *(Crc32RecordPointer) = Crc32; + } + + BaseAddress += MEMORY_CRC32_GRANULARITY; + Crc32RecordPointer++; + } +} + +#endif + +/** + Gets RapidStart non-volatile flag. + + @param[out] Value - RapidStart non-volatile flag + + @retval EFI_SUCCESS - Return the RapidStart flag in Value argument. +**/ +EFI_STATUS +RapidStartGetFlag ( + OUT UINT8 *Value + ) +{ + *Value = RtcRead (FFS_NV_FLAG_REG); + return EFI_SUCCESS; +} + +/** + Sets RapidStart non-volatile flag. + + @param[in] Value - RapidStart flag state + + @retval EFI_SUCCESS - Flag is set. +**/ +EFI_STATUS +RapidStartSetFlag ( + IN UINT8 Value + ) +{ + RtcWrite (FFS_NV_FLAG_REG, Value); + return EFI_SUCCESS; +} + +/** + Retrieves non-volatile RapidStart settings. + + @param[out] Value - RapidStart non-volatile settings + + @retval EFI_SUCCESS +**/ +EFI_STATUS +RapidStartGetConfig ( + OUT UINT8 *Value + ) +{ + *Value = RtcRead (FFS_NV_CONFIG_REG); + return EFI_SUCCESS; +} + +/** + Sets non-volatile RapidStart settings. + + @param[in] Value - RapidStart non-volatile settings + + @retval EFI_SUCCESS +**/ +EFI_STATUS +RapidStartSetConfig ( + IN UINT8 Value + ) +{ + RtcWrite (FFS_NV_CONFIG_REG, Value); + return EFI_SUCCESS; +} + +/** + This callback is executed at the end of RapidStart Entry events initialization. (Inside sleep SMI handler) + + @param[in] TransitionStatus - Status of initialization for RapidStart Entry events. +**/ +VOID +AfterInitializingEntryEvent ( + IN EFI_STATUS TransitionStatus + ) +{ +} + +/** + Check whether RapidStart Resume. + + @retval TRUE - Rapid Start Entry flow has completed successfully +**/ +BOOLEAN +RapidStartResumeCheck ( + VOID +) +{ + EFI_STATUS Status; + BOOLEAN RapidStartFlag; + + Status = RapidStartGetFlag (&RapidStartFlag); + if ( !EFI_ERROR (Status) && ((RapidStartFlag & RAPID_START_FLAG_ENTRY_DONE) != 0)) { + return TRUE; + } + + return FALSE; +} +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2012, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//************************************************************************* diff --git a/Board/EM/RapidStartWrapper/Library/RapidStartCommonLib/RapidStartCommonLib.cif b/Board/EM/RapidStartWrapper/Library/RapidStartCommonLib/RapidStartCommonLib.cif new file mode 100644 index 0000000..0294a74 --- /dev/null +++ b/Board/EM/RapidStartWrapper/Library/RapidStartCommonLib/RapidStartCommonLib.cif @@ -0,0 +1,12 @@ +<component> + name = "RapidStartCommonLib" + category = ModulePart + LocalRoot = "Board\EM\RapidStartWrapper\Library\RapidStartCommonLib" + RefName = "RapidStartCommonLib" +[files] +"RapidStartCommonLib.sdl" +"RapidStartCommonLib.mak" +"RapidStartCommonLib.c" +"RapidStartCommonLib.h" +"RapidStartCommonLib.inf" +<endComponent> diff --git a/Board/EM/RapidStartWrapper/Library/RapidStartCommonLib/RapidStartCommonLib.h b/Board/EM/RapidStartWrapper/Library/RapidStartCommonLib/RapidStartCommonLib.h new file mode 100644 index 0000000..2788e2f --- /dev/null +++ b/Board/EM/RapidStartWrapper/Library/RapidStartCommonLib/RapidStartCommonLib.h @@ -0,0 +1,374 @@ +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2012, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** + +//********************************************************************** +// $Header: /Alaska/SOURCE/Modules/Intel Fast Flash Standby/iRST_SharkBay/RapidStartWrapper/RapidStartCommonLib/RapidStartCommonLib.h 2 11/20/12 2:46a Bensonlai $ +// +// $Revision: 2 $ +// +// $Date: 11/20/12 2:46a $ +//********************************************************************** +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/Intel Fast Flash Standby/iRST_SharkBay/RapidStartWrapper/RapidStartCommonLib/RapidStartCommonLib.h $ +// +// 2 11/20/12 2:46a Bensonlai +// [TAG] EIP107013 +// [Category] Improvement +// [Description] Update Shark Bay Rapid Start Reference Code Version +// 0.8.0.0 +// [Files] RapidStartCommonLib.sdl +// RapidStartCommonLib.mak +// RapidStartCommonLib.c +// RapidStartCommonLib.h +// RapidStartCommonLib.inf +// RapidStartCommonLib.cif +// +// 1 10/15/12 4:40a Bensonlai +// [TAG] None +// [Category] Improvement +// [Description] [Category] Improvement +// [Severity] Important +// [Description] Rename all IFFS sting to Rapid Start. +// [Files] Board\EM\RapidStartWrapper\*.*, ReferenceCode\RapidStart\*.* +// [Files] RapidStartCommonLib.cif +// RapidStartCommonLib.sdl +// RapidStartCommonLib.mak +// RapidStartCommonLib.c +// RapidStartCommonLib.h +// RapidStartCommonLib.inf +// +//********************************************************************** +//<AMI_FHDR_START> +// +// Name: RapidStartCommonLib.h +// +// Description: Defines and prototypes for the library module. +// +//<AMI_FHDR_END> +//********************************************************************** + +#ifndef _RAPID_START_LIB_H_ +#define _RAPID_START_LIB_H_ +#include <RapidStartConfig.h> +#include <RapidStartData.h> + +/** + Read specific RTC/CMOS RAM + + @param[in] Location Point to RTC/CMOS RAM offset for read + + @retval The data of specific location in RTC/CMOS RAM. +**/ +UINT8 +RtcRead ( + IN UINT8 Location + ); + +/** + Write specific RTC/CMOS RAM + + @param[in] Location Point to RTC/CMOS RAM offset for write + @param[in] Value The data that will be written to RTC/CMOS RAM +**/ +VOID +RtcWrite ( + IN UINT8 Location, + IN UINT8 Value + ); + +/** + Read word from specific RTC/CMOS RAM + + @param[in] Location Point to RTC/CMOS RAM offset for read + + @retval The data of specific location in RTC/CMOS RAM. +**/ +UINT16 +RtcRead16 ( + IN UINT8 Location + ); + +/** + Write word to specific RTC/CMOS RAM + + @param[in] Location Point to RTC/CMOS RAM offset for write + @param[in] Value The data that will be written to RTC/CMOS RAM +**/ +VOID +RtcWrite16 ( + IN UINT8 Location, + IN UINT16 Value + ); + +/** + Initialize RTC Timer +**/ +VOID +RtcInit ( + VOID + ); + +/** + Get current RTC time + + @param[out] tm RTC time structure including Second, Minute and Hour. + + @retval EFI_SUCCESS Operation successfully and RTC_TIME structure contained current time. +**/ +EFI_STATUS +RtcGetTime ( + OUT RTC_TIME *tm + ); + +/** + Check if RTC Alarm has been enabled. + + @retval TRUE RTC Alarm is enabled + @retval FALSE RTC Alarm is not enabled +**/ +BOOLEAN +RtcIsAlarmEnabled ( + VOID + ); + +/** + Get current RTC Alarm time. + + @param[out] tm A structure which will be updated with current RTC Alarm time + + @retval EFI_NOT_STARTED RTC Alarm has not been enabled yet. + @retval EFI_SUCCESS RTC Alarm enabled and RTC_TIME structure contain current Alarm time setting. +**/ +EFI_STATUS +RtcGetAlarm ( + OUT RTC_TIME *tm + ); + +/** + Set RTC Alarm with specific time + + @param[in] tm A time interval structure which will be used to setup an RTC Alarm + + @retval EFI_SUCCESS RTC Alarm has been enabled with specific time interval +**/ +EFI_STATUS +RtcSetAlarm ( + IN RTC_TIME *tm + ); + +/** + Enable or disable critical battery wakeup event. + + This function enables/disables critical battery wakeup event on KSC controller. + This KSC specific command will not be sent if KSC not present. Porting is + required to match platform design. + + @param[in] Enabled - Enable or disable Critical Battery wakeup event. +**/ +VOID +RapidStartInitializeCriticalBatteryWakeupEvent ( + IN BOOLEAN Enabled + ); + +/** + Check if current wakeup is because of critical low battery. + + This function checks if current S3 resume caused by critical battery wakeup + event. This KSC specific command will not be sent if KSC not present. Porting is + required to match platform design. + + @retval TRUE - Current wakeup source is critical low battery event. + @retval FALSE - The wakeup source is not critical low battery event. +**/ +BOOLEAN +RapidStartCheckCriticalBatteryWakeupEvent ( + VOID + ); + +/** + Clear all wakeup status. + + This function clears all wakeup status bits on KSC controller. This KSC specific + command will not be sent if KSC not present. Porting is required to match + platform design. +**/ +VOID +RapidStartClearAllKscWakeStatus ( + VOID + ); + +#ifdef RAPID_START_WHOLE_MEMORY_CHECK +/** + Log CRC32 mismatched address and length + + This is optional OEM hook function. It can be used to log any CRC32 mismatched memory chunk if needed. + + @param[in] MismatchedBaseAddress - Memory address caused mismatched CRC32 + @param[in] MismatchedDataSize - memory length for calculating CRC32 + + @retval EFI_SUCCESS Process successfully +**/ +EFI_STATUS +LogCrc32MismatchedAddress ( + UINTN MismatchedBaseAddress, + UINT32 MismatchedDataSize + ); + +/** + Log or compare CRC32 value for specific memory range. Each 16MB block will have one CRC32 value. + + This function checks the memory integrity between Rapid Start Entry and Resume. + It calculates CRC32 for each memory chunk during Rapid Start Entry, and when + Rapid Start Resume it compares each memory chunk CRC32 value with previously + saved value to see if any mismatch found. Basically the debug mode BIOS can + display all information regarding mismatched memory address. In non-debug mode + BIOS, the mismatched memory address and size can be logged if needed. Refer to + section "Porting recommendation" for more information. + + @param[in] IsComparingCrc32 - FALSE to save CRC32 value into buffer. TRUE to compare CRC32 value with pre-saved value in buffer. + @param[in] BaseAddress - Base memory address for logging or checking CRC32 + @param[in] EndAddress - End memory address for logging or checking CRC32 + @param[in] RapidStartData - A data buffer stored RapidStart internal non-volatile information. +**/ +VOID +SaveOrCompareCrc32 ( + IN BOOLEAN IsComparingCrc32, + IN UINTN BaseAddress, + IN UINTN EndAddress, + IN RAPID_START_PERSISTENT_DATA *RapidStartData + ); +#endif +/** + Gets RapidStart non-volatile flag. + + Bit0 (RAPID_START_FLAG_ENTRY_DONE): + - Rapid Start Entry flow has completed successfully. + - Next boot will perform Rapid Start Resume. + Bit1 (RAPID_START_FLAG_STORE_CHANGE): + - Rapid Start Store change detected in Rapid Start Resume flow. + - Rapid Start Resume should be aborted. + + This function will get Rapid Start non-volatile flag which controls overall + Rapid Start transition behavior. If Rapid Start Entry already performed in last + boot (Rapid Start Flag bit1 was set) the Rapid Start Exit transition can be + executed in current boot. After got the Rapid Start Entry state it is + recommended to clear this flag (Rapid Start Flag bit1) after drive lock password + has been retrieved and scrubbed from non-volatile memory (if drive-lock feature + enabled). There are several ways to store Rapid Start Flag and it is platform + specific. It must be stored in non-volatile memory and one of the methods is to + use CMOS RAM. + + @param[out] Value - RapidStart non-volatile flag + + @retval EFI_SUCCESS - Return the RapidStart flag in Value argument. +**/ +EFI_STATUS +RapidStartGetFlag ( + OUT UINT8 *Value + ); + +/** + Sets RapidStart non-volatile flag. + + Bit0 (RAPID_START_FLAG_ENTRY_DONE): + - Rapid Start Entry flow has completed successfully. + - Next boot will perform Rapid Start Resume. + Bit1 (RAPID_START_FLAG_STORE_CHANGE): + - Rapid Start Store change detected in Rapid Start Resume flow. + - Rapid Start Resume should be aborted. + + This function will set Rapid Start non-volatile flag which controls overall + Rapid Start transition behavior. In end of Rapid Start Entry it will set bit0 to + indicate next boot may perform Rapid Start Resume. It will also be used to clear + Rapid Start Flag when required information has been retrieved. + + @param[in] Value - RapidStart flag state + + @retval EFI_SUCCESS - Flag is set. +**/ +EFI_STATUS +RapidStartSetFlag ( + IN UINT8 Value + ); + +/** + Retrieves non-volatile RapidStart settings. + + @param[out] Value - RapidStart non-volatile settings + + @retval EFI_SUCCESS +**/ +EFI_STATUS +RapidStartGetConfig ( + OUT UINT8 *Value + ); + +/** + Sets non-volatile RapidStart settings. + + @param[in] Value - RapidStart non-volatile settings + + @retval EFI_SUCCESS +**/ +EFI_STATUS +RapidStartSetConfig ( + IN UINT8 Value + ); + +/** + This callback is executed at the end of RapidStart Entry events initialization. (Inside sleep SMI handler) + + This function will be called in the end of sleep SMI handler which initializes + Rapid Start Entry trigger events (RTC alarm timer or critical battery wakeup + threshold). It can be used to log the status of initialization like Entry + cancellation or Entry aborted due to a sooner wakeup timer has be initialized by + OS/application. In these cases Rapid Start trigger events will not be + initialized and system will directly enter standard S3 state. + + This function can be used to log any error status of initializing Rapid Start + Entry trigger events in sleep SMI handler and then inform users for why Rapid + Start Entry not happened. + + @param[in] TransitionStatus - Status of initialization for RapidStart Entry events. +**/ +VOID +AfterInitializingEntryEvent ( + IN EFI_STATUS TransitionStatus + ); + +/** + Check whether RapidStart Resume. + + @retval TRUE - Rapid Start Entry flow has completed successfully +**/ +BOOLEAN +RapidStartResumeCheck ( + VOID +); +#endif + +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2012, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** diff --git a/Board/EM/RapidStartWrapper/Library/RapidStartCommonLib/RapidStartCommonLib.inf b/Board/EM/RapidStartWrapper/Library/RapidStartCommonLib/RapidStartCommonLib.inf new file mode 100644 index 0000000..adebfa2 --- /dev/null +++ b/Board/EM/RapidStartWrapper/Library/RapidStartCommonLib/RapidStartCommonLib.inf @@ -0,0 +1,54 @@ +## @file +# Component description file for the RapidStart Common code PEIM/SMM/DXE library +# +#@copyright +# Copyright (c) 2004 - 2012 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. +# +# This file contains a 'Sample Driver' and is licensed as such +# under the terms of your license agreement with Intel or your +# vendor. This file may be modified by the user, subject to +# the additional terms of the license agreement +# + +[defines] +BASE_NAME = RapidStartCommonLib +COMPONENT_TYPE = LIBRARY + +[sources.common] + RapidStartCommonLib.h + RapidStartCommonLib.c + +[includes.common] + . + $(EDK_SOURCE)/Foundation/Library/Pei/Include + $(EDK_SOURCE)/Foundation/Efi + $(EDK_SOURCE)/Foundation/Include + $(EDK_SOURCE)/Foundation/Efi/Include + $(EDK_SOURCE)/Foundation/Framework/Include + $(EFI_SOURCE)/$(PROJECT_PCH_ROOT)/Include + $(EFI_SOURCE)/$(PROJECT_PCH_ROOT) + $(EFI_SOURCE)/$(PROJECT_PCH_ROOT)/Include/Library + $(EFI_SOURCE)/$(PROJECT_RAPID_START_ROOT) + $(EFI_SOURCE)/$(PROJECT_RAPID_START_ROOT)/Include +# +# EDK II Glue Library utilizes some standard headers from EDK +# + $(EFI_SOURCE) + $(EDK_SOURCE)/Foundation + $(EDK_SOURCE)/Foundation/Framework + $(EDK_SOURCE)/Foundation/Include/IndustryStandard + $(EDK_SOURCE)/Foundation/Core/Dxe + $(EDK_SOURCE)/Foundation/Include/Pei + $(EDK_SOURCE)/Foundation/Library/Dxe/Include + $(EDK_SOURCE)/Foundation/Library/EdkIIGlueLib/Include + +[nmake.common] +C_STD_INCLUDE= + diff --git a/Board/EM/RapidStartWrapper/Library/RapidStartCommonLib/RapidStartCommonLib.mak b/Board/EM/RapidStartWrapper/Library/RapidStartCommonLib/RapidStartCommonLib.mak new file mode 100644 index 0000000..7b2d2df --- /dev/null +++ b/Board/EM/RapidStartWrapper/Library/RapidStartCommonLib/RapidStartCommonLib.mak @@ -0,0 +1,103 @@ +#********************************************************************** +#********************************************************************** +#** ** +#** (C)Copyright 1985-2012, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#********************************************************************** +#********************************************************************** + +#********************************************************************** +# $Header: /Alaska/SOURCE/Modules/Intel Fast Flash Standby/iRST_SharkBay/RapidStartWrapper/RapidStartCommonLib/RapidStartCommonLib.mak 1 10/15/12 4:40a Bensonlai $ +# +# $Revision: 1 $ +# +# $Date: 10/15/12 4:40a $ +#********************************************************************** +# Revision History +# ---------------- +# $Log: /Alaska/SOURCE/Modules/Intel Fast Flash Standby/iRST_SharkBay/RapidStartWrapper/RapidStartCommonLib/RapidStartCommonLib.mak $ +# +# 1 10/15/12 4:40a Bensonlai +# [TAG] None +# [Category] Improvement +# [Description] [Category] Improvement +# [Severity] Important +# [Description] Rename all IFFS sting to Rapid Start. +# [Files] Board\EM\RapidStartWrapper\*.*, ReferenceCode\RapidStart\*.* +# [Files] RapidStartCommonLib.cif +# RapidStartCommonLib.sdl +# RapidStartCommonLib.mak +# RapidStartCommonLib.c +# RapidStartCommonLib.h +# RapidStartCommonLib.inf +# +#********************************************************************** +#<AMI_FHDR_START> +# +# Name: RapidStartCommonLib.mak +# +# Description: Component description file for the RapidStart Common code PEIM/SMM/DXE library. +# +#<AMI_FHDR_END> +#********************************************************************** + +all : RapidStartCommonSmmLib RapidStartCommonDxeLib RapidStartCommonPeiLib + +$(RapidStartCommonSmmLib_LIB) : RapidStartCommonSmmLib +$(RapidStartCommonDxeLib_LIB) : RapidStartCommonDxeLib +$(RapidStartCommonPeiLib_LIB) : RapidStartCommonPeiLib + +RapidStartCommonSmmLib : $(BUILD_DIR)\RapidStartCommonLib.mak RapidStartCommonSmmLibBin +RapidStartCommonDxeLib : $(BUILD_DIR)\RapidStartCommonLib.mak RapidStartCommonDxeLibBin +RapidStartCommonPeiLib : $(BUILD_DIR)\RapidStartCommonLib.mak RapidStartCommonPeiLibBin + +$(BUILD_DIR)\RapidStartCommonLib.mak : $(RapidStartCommonLib_DIR)\$(@B).cif $(RapidStartCommonLib_DIR)\$(@B).mak $(BUILD_RULES) + $(CIF2MAK) $(RapidStartCommonLib_DIR)\$(@B).cif $(CIF2MAK_DEFAULTS) + +RapidStartCommonSmmLibBin : $(PchPlatformLib) + $(MAKE) /$(MAKEFLAGS) $(EDKIIGLUE_DEFAULTS)\ + /f $(BUILD_DIR)\RapidStartCommonLib.mak all\ + "MY_INCLUDES=$(EDK_INCLUDES) $(EdkIIGlueLib_INCLUDES) $(NB_INCLUDES) $(INTEL_PCH_INCLUDES) $(RAPIDSTART_INCLUDES)" \ + TYPE=LIBRARY \ + LIBRARIES=\ + LIBRARY_NAME=$(RapidStartCommonSmmLib_LIB) + +RapidStartCommonDxeLibBin : + $(MAKE) /$(MAKEFLAGS) $(EDKIIGLUE_DEFAULTS)\ + /f $(BUILD_DIR)\RapidStartCommonLib.mak all\ + "MY_INCLUDES=$(EDK_INCLUDES) $(EdkIIGlueLib_INCLUDES) $(NB_INCLUDES) $(INTEL_PCH_INCLUDES) $(RAPIDSTART_INCLUDES)" \ + TYPE=LIBRARY \ + LIBRARIES=\ + LIBRARY_NAME=$(RapidStartCommonDxeLib_LIB) + +RapidStartCommonPeiLibBin : +!IF "$(x64_BUILD)"=="1" + $(MAKE) /$(MAKEFLAGS) $(EDKIIGLUE_DEFAULTS) BUILD_DIR=$(BUILD_DIR)\IA32\ +!ELSE + $(MAKE) /$(MAKEFLAGS) $(EDKIIGLUE_DEFAULTS)\ +!ENDIF + /f $(BUILD_DIR)\RapidStartCommonLib.mak all\ + "MY_INCLUDES=/I$(BUILD_DIR) $(EDK_INCLUDES) $(EdkIIGlueLib_INCLUDES) $(NB_INCLUDES) $(INTEL_PCH_INCLUDES) $(RAPIDSTART_INCLUDES)" \ + TYPE=PEI_LIBRARY \ + LIBRARIES=\ + LIBRARY_NAME=$(RapidStartCommonPeiLib_LIB) + +#************************************************************************* +#************************************************************************* +#** ** +#** (C)Copyright 1985-2012, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#************************************************************************* +#************************************************************************* diff --git a/Board/EM/RapidStartWrapper/Library/RapidStartCommonLib/RapidStartCommonLib.sdl b/Board/EM/RapidStartWrapper/Library/RapidStartCommonLib/RapidStartCommonLib.sdl new file mode 100644 index 0000000..947adba --- /dev/null +++ b/Board/EM/RapidStartWrapper/Library/RapidStartCommonLib/RapidStartCommonLib.sdl @@ -0,0 +1,121 @@ +#********************************************************************** +#********************************************************************** +#** ** +#** (C)Copyright 1985-2012, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#********************************************************************** +#********************************************************************** + +#********************************************************************** +# $Header: /Alaska/SOURCE/Modules/Intel Fast Flash Standby/iRST_SharkBay/RapidStartWrapper/RapidStartCommonLib/RapidStartCommonLib.sdl 1 10/15/12 4:40a Bensonlai $ +# +# $Revision: 1 $ +# +# $Date: 10/15/12 4:40a $ +#********************************************************************** +# Revision History +# ---------------- +# $Log: /Alaska/SOURCE/Modules/Intel Fast Flash Standby/iRST_SharkBay/RapidStartWrapper/RapidStartCommonLib/RapidStartCommonLib.sdl $ +# +# 1 10/15/12 4:40a Bensonlai +# [TAG] None +# [Category] Improvement +# [Description] [Category] Improvement +# [Severity] Important +# [Description] Rename all IFFS sting to Rapid Start. +# [Files] Board\EM\RapidStartWrapper\*.*, ReferenceCode\RapidStart\*.* +# [Files] RapidStartCommonLib.cif +# RapidStartCommonLib.sdl +# RapidStartCommonLib.mak +# RapidStartCommonLib.c +# RapidStartCommonLib.h +# RapidStartCommonLib.inf +# +#********************************************************************** +#<AMI_FHDR_START> +# +# Name: RapidStartCommonLib.sdl +# +# Description: SDL file for the RapidStart library. +# +#<AMI_FHDR_END> +#********************************************************************** + +TOKEN + Name = "INTEL_MPG_RapidStartCommonLib_SUPPORT" + Value = "1" + Help = "Main switch to enable INTEL_MPG_RapidStartCommonLib support in Project" + TokenType = Boolean + TargetEQU = Yes + TargetMAK = Yes + Master = Yes +End + +PATH + Name = "RapidStartCommonLib_DIR" +End + +MODULE + Help = "Includes RapidStartCommonLib.mak to Project" + File = "RapidStartCommonLib.mak" +End + + +ELINK + Name = "RapidStartCommonSmmLib_LIB" + InvokeOrder = ReplaceParent +End + +ELINK + Name = "$(BUILD_DIR)\RapidStartCommonSmmLib.lib" + Parent = "RapidStartCommonSmmLib_LIB" + InvokeOrder = AfterParent +End + +ELINK + Name = "RapidStartCommonDxeLib_LIB" + InvokeOrder = ReplaceParent +End + +ELINK + Name = "$(BUILD_DIR)\RapidStartCommonDxeLib.lib" + Parent = "RapidStartCommonDxeLib_LIB" + InvokeOrder = AfterParent +End + +ELINK + Name = "RapidStartCommonPeiLib_LIB" + InvokeOrder = ReplaceParent +End + +ELINK + Name = "$(BUILD_DIR)\RapidStartCommonPeiLib.lib" + Parent = "RapidStartCommonPeiLib_LIB" + InvokeOrder = AfterParent +End + +ELINK + Name = "/I$(RapidStartCommonLib_DIR)" + Parent = "RAPIDSTART_INCLUDES" + InvokeOrder = AfterParent +End + +#********************************************************************** +#********************************************************************** +#** ** +#** (C)Copyright 1985-2012, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#********************************************************************** +#********************************************************************** diff --git a/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Dxe/RapidStartDxeLib.c b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Dxe/RapidStartDxeLib.c new file mode 100644 index 0000000..c062033 --- /dev/null +++ b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Dxe/RapidStartDxeLib.c @@ -0,0 +1,722 @@ +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2012, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** + +//********************************************************************** +// $Header: /Alaska/SOURCE/Modules/Intel Fast Flash Standby/iRST_SharkBay/RapidStartWrapper/RapidStartDxeLib/RapidStartDxeLib.c 5 3/14/14 9:56a Joshchou $ +// +// $Revision: 5 $ +// +// $Date: 3/14/14 9:56a $ +//********************************************************************** +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/Intel Fast Flash Standby/iRST_SharkBay/RapidStartWrapper/RapidStartDxeLib/RapidStartDxeLib.c $ +// +// 5 3/14/14 9:56a Joshchou +// +// 4 8/05/13 3:02a Joshchou +// [TAG] EIP130093 +// [Category] Bug Fix +// [Severity] Important +// [Symptom] System will hang at CP 0xA2 when plug in special mSATA SSD +// and Intel Rapid Start Technology support +// [RootCause] The buffer size isn't enough. +// [Solution] Modify the size when allocate. +// +// 3 2/20/13 1:47a Bensonlai +// [TAG] EIP115468 +// [Category] Bug Fix +// [Severity] Important +// [Symptom] [SharkBay][Rapid Start] Rapid Start can't work using GPT +// partition when enabled RAID mode +// [RootCause] Rapid Start can't work using GPT partition when enabled +// RAID mode +// [Files] RapidStartDxeLib.c +// +// 2 12/07/12 1:25a Bensonlai +// [TAG] EIP108737 +// [Category] Bug Fix +// [Severity] Normal +// [Symptom] When system in the RAID mode without the partition of the +// RapidStart, RapidStart menu still show "No Valid Partition" in the +// setup. +// [RootCause] We didn't check the RAID mode. +// [Solution] Add the RAID mode for checking whether in the RAID mode. +// [Files] RapidStartDxeLib.c +// +// 1 10/15/12 4:41a Bensonlai +// [TAG] None +// [Category] Improvement +// [Description] [Category] Improvement +// [Severity] Important +// [Description] Rename all IFFS sting to Rapid Start. +// [Files] Board\EM\RapidStartWrapper\*.*, ReferenceCode\RapidStart\*.* +// +// [Files] RapidStartDxeLib.cif +// RapidStartDxeLib.sdl +// RapidStartDxeLib.mak +// RapidStartDxeLib.c +// RapidStartDxeLib.h +// RapidStartDxeLib.inf +// +//********************************************************************** +//<AMI_FHDR_START> +// +// Name: RapidStartDxeLib.c +// +// Description: RapidStart Dxe Platform Library. +// +//<AMI_FHDR_END> +//********************************************************************** + +#if !defined(EDK_RELEASE_VERSION) || (EDK_RELEASE_VERSION < 0x00020000) +#include "EdkIIGlueDxe.h" + +#include EFI_PROTOCOL_CONSUMER (BlockIo) +#include EFI_PROTOCOL_CONSUMER (DiskIo) +#include EFI_PROTOCOL_CONSUMER (RapidStartPlatformPolicy) +#include <SaAccess.h> +#include <PchAccess.h> +#include <UefiGpt.h> +#include <mbr.h> +#include "RapidStartDxeLib.h" +#endif + +//AMIOVERRIDE_BEGIN +#define SIGNATURE_16(A, B) ((A) | (B << 8)) +#define SIGNATURE_32(A, B, C, D) (SIGNATURE_16 (A, B) | (SIGNATURE_16 (C, D) << 16)) +#define SIGNATURE_64(A, B, C, D, E, F, G, H) \ + (SIGNATURE_32 (A, B, C, D) | ((UINT64) (SIGNATURE_32 (E, F, G, H)) << 32)) +//AMIOVERRIDE_END + +#define RAPID_START_PART_TYPE_MBR 0x84 /* Hibernation partition -- APM 1.1f */ +#define PCH_EFI_RAID_DRIVER_EXECUTION_GUID \ + { 0x99D5757C, 0xD906, 0x11E0, 0x8D, 0x78, 0x8D, 0xE4, 0x48, 0x24, 0x01, 0x9B }; + +EFI_GUID gRapidStartGptGuid = RAPID_START_GPT_GUID; +UINT8 gDriveNum = 0x80; +EFI_GUID gPchEfiRaidDriverExecutionGuid = PCH_EFI_RAID_DRIVER_EXECUTION_GUID; +BOOLEAN gPchEfiRaidDriver = FALSE; + +/** + Search device path by specific Type and SubType + + @param[in,out] DevicePath - A pointer to the device path + @param[in] Type - Device path type + @param[in] SubType - Device path SubType + + @retval EFI_DEVICE_PATH_PROTOCOL - Device path found and the pointer of device path returned + @retval NULL - Specific device path not found +**/ +STATIC +EFI_DEVICE_PATH_PROTOCOL * +SearchDevicePath ( + IN OUT EFI_DEVICE_PATH_PROTOCOL *DevicePath, + IN UINT8 Type, + IN UINT8 SubType + ) +{ + if (DevicePath == NULL) { + return NULL; + } + + while (!IsDevicePathEnd (DevicePath)) { + if ((DevicePathType (DevicePath) == Type) && (DevicePathSubType (DevicePath) == SubType)) { + return DevicePath; + } + + DevicePath = NextDevicePathNode (DevicePath); + } + + return NULL; +} + +STATIC +EFI_STATUS +RetrieveSataPortNumberInt13 ( + IN OUT UINT8 *PortNumber, + IN BOOLEAN GPTDetect + ) +{ + UINTN Index; + BOOLEAN CarryFlag; + EFI_IA32_REGISTER_SET Regs; + EFI_LEGACY_BIOS_PROTOCOL *LegacyBios; + EFI_PHYSICAL_ADDRESS TheRealModeBuffer; + VOID* Int13Buffer = NULL; + EFI_STATUS Status; + UINT8 MaxDriveCount; + + Status = gBS->LocateProtocol(&gEfiLegacyBiosProtocolGuid, NULL, &LegacyBios); + ASSERT_EFI_ERROR(Status); + + // allocate conventional memory for int code + TheRealModeBuffer = 0x00000000000FFFFF; + Status = (gBS->AllocatePages)( + AllocateMaxAddress, + EfiBootServicesData, + 1, + &TheRealModeBuffer); + ASSERT_EFI_ERROR(Status); + + Int13Buffer = (VOID*)TheRealModeBuffer; + // clear 4K page + (gBS->SetMem)(Int13Buffer, 1024 * 4, 0); + + MaxDriveCount = *(UINT8*)0x475; +//#### DEBUG ((EFI_D_ERROR, "MaxDriveCount = %x\n", MaxDriveCount)); + + for (Index = 0; Index < MaxDriveCount; Index++) { + *(UINT16*)Int13Buffer = 0x004A; + // Get physical hard disk information by ATA identify command + Regs.X.DS = EFI_SEGMENT(Int13Buffer); + Regs.X.SI = EFI_OFFSET(Int13Buffer); + Regs.H.AH = 0x48; + + if (GPTDetect) + Regs.H.DL = 0x80 + (UINT8)Index; + else + Regs.H.DL = gDriveNum; + + DEBUG ((EFI_D_ERROR, "Drive Number = %x\n", Regs.H.DL)); + + LegacyBios->Int86 (LegacyBios, 0x13, &Regs); + CarryFlag = (BOOLEAN)Regs.X.Flags.CF; + if ((!CarryFlag) && (Regs.H.AH == 0)) { + + DEBUG ((EFI_D_ERROR, "0x28 = %x\n", *((UINT8*)(Int13Buffer)+0x28))); + DEBUG ((EFI_D_ERROR, "0x29 = %x\n", *((UINT8*)(Int13Buffer)+0x29))); + DEBUG ((EFI_D_ERROR, "0x2A = %x\n", *((UINT8*)(Int13Buffer)+0x2A))); + DEBUG ((EFI_D_ERROR, "0x2B = %x\n", *((UINT8*)(Int13Buffer)+0x2B))); + DEBUG ((EFI_D_ERROR, "0x3C = %x\n", *((UINT8*)(Int13Buffer)+0x3C))); + + if ((*((UINT8*)(Int13Buffer)+0x28) == 'R') && \ + (*((UINT8*)(Int13Buffer)+0x29) == 'A') && \ + (*((UINT8*)(Int13Buffer)+0x2A) == 'I') && \ + (*((UINT8*)(Int13Buffer)+0x2B) == 'D')) { + switch (*((UINT8*)(Int13Buffer)+0x3c)) { + case 0x01: + *PortNumber = 0; + break; + case 0x02: + *PortNumber = 1; + break; + case 0x04: + *PortNumber = 2; + break; + case 0x08: + *PortNumber = 3; + break; + case 0x10: + *PortNumber = 4; + break; + case 0x20: + *PortNumber = 5; + break; + default: + *PortNumber = 0; + break; + } + } + } + if (!GPTDetect) break; + } + if (Int13Buffer) (gBS->FreePages) (TheRealModeBuffer, 1); + + return Status; +} + +/** + Scan and check if GPT type RapidStart Store present. + + @param[in] Device - Device handle + @param[in] DevicePath - A pointer to the device path + @param[out] StoreSectors - Size of RapidStart store partition + @param[out] StoreLbaAddr - Address of RapidStart store partition + + @retval EFI_SUCCESS - GPT type RapidStart Store found. + @retval EFI_NOT_FOUND - GPT type RapidStart Store not found. +**/ +STATIC +EFI_STATUS +ScanForRapidStartGptPartition ( + IN EFI_HANDLE Device, + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, + OUT UINT32 *StoreSectors, + OUT UINT64 *StoreLbaAddr + ) +{ + EFI_STATUS Status; + EFI_BLOCK_IO_PROTOCOL *BlockIo; + EFI_DISK_IO_PROTOCOL *DiskIo; + EFI_PARTITION_TABLE_HEADER *PrimaryHeader; + EFI_PARTITION_ENTRY *PartitionEntry; + UINT32 Index; + + Status = gBS->HandleProtocol (Device, &gEfiBlockIoProtocolGuid, (VOID*)&BlockIo); + if (EFI_ERROR (Status)) { + return EFI_UNSUPPORTED; + } + + Status = gBS->HandleProtocol (Device, &gEfiDiskIoProtocolGuid, (VOID*)&DiskIo); + if (EFI_ERROR (Status)) { + return EFI_UNSUPPORTED; + } + // + // Read the EFI Partition Table Header + // + PrimaryHeader = (EFI_PARTITION_TABLE_HEADER *) AllocatePool (BlockIo->Media->BlockSize); + if (PrimaryHeader == NULL) { + return EFI_OUT_OF_RESOURCES; + } + Status = DiskIo->ReadDisk ( + DiskIo, + BlockIo->Media->MediaId, + 1 * BlockIo->Media->BlockSize, + BlockIo->Media->BlockSize, + (UINT8 *)PrimaryHeader + ); + if (EFI_ERROR (Status)) { + FreePool (PrimaryHeader); + return EFI_DEVICE_ERROR; + } +//AMIOVERRIDE_BEGIN + if(PrimaryHeader->Header.Signature != EFI_PTAB_HEADER_ID ){//Check for "EFI PART" signature + FreePool (PrimaryHeader); + return EFI_NOT_FOUND; + } +//AMIOVERRIDE_END + // + // Read the partition entry. + // +//AMIOVERRIDE_BEGIN + // PartitionEntry = AllocatePool (PrimaryHeader->NumberOfPartitionEntries * sizeof (EFI_PARTITION_ENTRY)); + PartitionEntry = AllocatePool (PrimaryHeader->NumberOfPartitionEntries * PrimaryHeader->SizeOfPartitionEntry); +//AMIOVERRIDE_END + if (PartitionEntry == NULL) { + FreePool (PrimaryHeader); + return EFI_OUT_OF_RESOURCES; + } + Status = DiskIo->ReadDisk ( + DiskIo, + BlockIo->Media->MediaId, + MultU64x32(PrimaryHeader->PartitionEntryLBA, BlockIo->Media->BlockSize), + PrimaryHeader->NumberOfPartitionEntries * PrimaryHeader->SizeOfPartitionEntry, + PartitionEntry + ); + if (EFI_ERROR (Status)) { + FreePool (PrimaryHeader); + FreePool (PartitionEntry); + return EFI_DEVICE_ERROR; + } + + // + // Count the valid partition + // + for (Index = 0; Index < PrimaryHeader->NumberOfPartitionEntries; Index++) { + if (CompareGuid (&PartitionEntry[Index].PartitionTypeGUID, &gRapidStartGptGuid)) { + *StoreLbaAddr = PartitionEntry[Index].StartingLBA; + *StoreSectors = (UINT32) (PartitionEntry[Index].EndingLBA - PartitionEntry[Index].StartingLBA + 1); + DEBUG ( + (EFI_D_INFO, + "Found RapidStart GPT partition: start=%x size=%x\n", + *StoreLbaAddr, + *StoreSectors) + ); + FreePool (PrimaryHeader); + FreePool (PartitionEntry); + return EFI_SUCCESS; + } + } + + FreePool (PrimaryHeader); + FreePool (PartitionEntry); + return EFI_NOT_FOUND; +} + +/** + Scan and check if MBR type RapidStart Store present. + + @param[in] Device - Device handle + @param[out] StoreSectors - Size of RapidStart store partition + @param[out] StoreLbaAddr - Address of RapidStart store partition + + @retval EFI_SUCCESS - MBR type RapidStart Store found. + @retval EFI_NOT_FOUND - MBR type RapidStart Store not found. +**/ +STATIC +EFI_STATUS +ScanForRapidStartMbrPartition ( + IN EFI_HANDLE Device, + OUT UINT32 *StoreSectors, + OUT UINT64 *StoreLbaAddr + ) +{ + EFI_STATUS Status; + EFI_BLOCK_IO_PROTOCOL *BlockIo; + UINTN Idx; + UINT8 OsType; + + MASTER_BOOT_RECORD BootRecord; + MASTER_BOOT_RECORD *Mbr; + MASTER_BOOT_RECORD ExtBootRecord; + MASTER_BOOT_RECORD *ExtPart; + EFI_LBA Lba; + + Mbr = &BootRecord; + + Status = gBS->HandleProtocol (Device, &gEfiBlockIoProtocolGuid, (VOID *) &BlockIo); + ASSERT_EFI_ERROR (Status); + ASSERT (BlockIo != NULL); + + /// + /// read the MBR + /// + Status = BlockIo->ReadBlocks (BlockIo, BlockIo->Media->MediaId, 0, sizeof (*Mbr), Mbr); + if (Status != EFI_SUCCESS) { + DEBUG ((EFI_D_ERROR, "Cannot read MBR\n")); + return Status; + } + + if (Mbr->Sig != MBR_SIGNATURE) { + DEBUG ((EFI_D_ERROR, "Bad MBR\n")); + if (!BlockIo->Media->RemovableMedia) + gDriveNum++; + return EFI_NOT_FOUND; + } + + for (Idx = 0; Idx < NUM_MBR_PARTITIONS; Idx++) { + OsType = Mbr->PartRec[Idx].OSType; + + /// + /// ignore partitions whose OSType or Size is zero + /// + if ((OsType == 0) || (Mbr->PartRec[Idx].SizeInLba == 0)) { + continue; + } + + if (OsType == RAPID_START_PART_TYPE_MBR) { + DEBUG ( + (EFI_D_INFO, + "Found RapidStart MBR partition: start=%x size=%x\n", + Mbr->PartRec[Idx].StartingLba, + Mbr->PartRec[Idx].SizeInLba) + ); + *StoreLbaAddr = Mbr->PartRec[Idx].StartingLba; + *StoreSectors = Mbr->PartRec[Idx].SizeInLba; + return EFI_SUCCESS; + } + + // Now that a valid partition is found process it + if ((Mbr->PartRec[Idx].OSType == EXTENDED_PARTITION) || + (Mbr->PartRec[Idx].OSType == WIN95_EXTENDED_PARTITION)) { + + ExtPart = &ExtBootRecord; + + // defines where to start reading the next MBR/partition + // table from + Lba = Mbr->PartRec[Idx].StartingLba; + + // loop through logical partitions: any number of + // possible partitions + while (TRUE) { + + // if the table points back to itself, exit + if ( Lba == 0) { + break; + } + + // get Partition table from the first block of the device + Status = BlockIo->ReadBlocks(BlockIo, BlockIo->Media->MediaId, + Lba, sizeof (*ExtPart), ExtPart); + + if (EFI_ERROR(Status)) { + return Status; + } + + // make sure this is a valid partition + if (ExtPart->PartRec[0].OSType == NO_PARTITION) { + break; + } + + // check for problems that make the partition invalid + if ((Lba + ExtPart->PartRec[0].SizeInLba) > + (Mbr->PartRec[Idx].StartingLba + + Mbr->PartRec[Idx].SizeInLba)) { + + break; + } + + OsType = ExtPart->PartRec[0].OSType; + + if (OsType == RAPID_START_PART_TYPE_MBR) { + DEBUG ( + (EFI_D_INFO, + "Found RapidStart MBR partition: start=%x size=%x\n", + Mbr->PartRec[Idx].StartingLba, + Mbr->PartRec[Idx].SizeInLba) + ); + + *StoreLbaAddr = ExtPart->PartRec[0].StartingLba + Lba; + *StoreSectors = ExtPart->PartRec[0].SizeInLba; + return EFI_SUCCESS; + } + + // check to see if the next partition is an extended partition + if ((ExtPart->PartRec[1].OSType != EXTENDED_PARTITION) && + (ExtPart->PartRec[1].OSType != WIN95_EXTENDED_PARTITION) ) { + break; + } + + // get set up for the next partition. The Starting Lba + // address is a relative address inside the extended + // partition add the starting address of the extended + // partition to get the actual LBA where it starts + Lba = ExtPart->PartRec[1].StartingLba + + Mbr->PartRec[Idx].StartingLba; + } + } + } + + if (!BlockIo->Media->RemovableMedia) + gDriveNum++; + + return EFI_NOT_FOUND; +} + +/** + Verify if this device path was RapidStart store partition. Get SATA port number if it was. + + @param[in] AhciMode - TRUE means current SATA operation mode is AHCI, otherwise it is RAID + @param[in,out] DevicePath - A pointer to the device path + @param[in,out] PortNumber - Port Number connecting to this drive + + @retval EFI_SUCCESS - This is RapidStart Store partition and Port Number retrieved successfully. + @retval EFI_NOT_FOUND - This is not RapidStart Store +**/ +STATIC +EFI_STATUS +VerifyDevicePath ( + IN BOOLEAN AhciMode, + IN OUT EFI_DEVICE_PATH_PROTOCOL *DevicePath, + IN OUT UINT8 *PortNumber + ) +{ + EFI_STATUS Status; + UINT8 Index; + + Status = EFI_NOT_FOUND; + + DevicePath = SearchDevicePath (DevicePath, MESSAGING_DEVICE_PATH, MSG_SATA_DP); + if ((SATA_DEVICE_PATH *) DevicePath != NULL) { +#if (EFI_SPECIFICATION_VERSION >= 0x0002000A) + * PortNumber = (UINT8) ((SATA_DEVICE_PATH *) DevicePath)->HBAPortNumber; +#else + *PortNumber = (UINT8) ((SATA_DEVICE_PATH *) DevicePath)->HbaPortNumber; +#endif + Status = EFI_SUCCESS; + } + + // Support Intel RST SATA UEFI Driver + if (gPchEfiRaidDriver) { + for (Index = 0; Index < 6; Index++) { + if (*PortNumber & (1 << Index)) { + *PortNumber = Index; + break; + } + } + } + + + if (Status == EFI_SUCCESS) { + DEBUG ((EFI_D_INFO, "Port number=%X\n", *PortNumber)); + } + + return Status; +} + +/** + Look through all device handles to detect if any GPT/MBR type RapidStart Store present + + @param[in] AhciMode - TRUE means current SATA operation mode is AHCI, otherwise it is RAID + @param[in] RapidStartPolicy - RapidStart Platform Policy protocol + @param[out] StoreSectors - Size of RapidStart store partition + @param[out] StoreLbaAddr - Address of RapidStart store partition + @param[out] StoreSataPort - Port number for RapidStart store partition + + @retval EFI_SUCCESS - RapidStart Store found + @retval EFI_NOT_FOUND - RapidStart Store not found +**/ +STATIC +EFI_STATUS +DetectRapidStartPartition ( + IN BOOLEAN AhciMode, + IN RAPID_START_PLATFORM_POLICY_PROTOCOL *RapidStartPolicy, + OUT UINT32 *StoreSectors, + OUT UINT64 *StoreLbaAddr, + OUT UINT8 *StoreSataPort + ) +{ + EFI_STATUS Status; + UINTN HandleCount; + EFI_HANDLE *HandleBuffer; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + UINTN Index; + + Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &HandleCount, &HandleBuffer); + if (!EFI_ERROR (Status)) { + // + // Loop through all the device handles that support the BLOCK_IO Protocol + // + for (Index = 0; Index < HandleCount; Index++) { + Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiDevicePathProtocolGuid, (VOID *) &DevicePath); + if (EFI_ERROR (Status) || DevicePath == NULL) { + continue; + } + + if (VerifyDevicePath (AhciMode, DevicePath, StoreSataPort) == EFI_SUCCESS || (AhciMode == 0)) { //Raid mode + Status = ScanForRapidStartGptPartition (HandleBuffer[Index], DevicePath, StoreSectors, StoreLbaAddr); + if (Status == EFI_SUCCESS) { + if ( (!AhciMode) && (!gPchEfiRaidDriver) ) RetrieveSataPortNumberInt13(StoreSataPort, TRUE); + DEBUG ((EFI_D_INFO, "Found Gpt RapidStart Store on SATA port=%d\n", *StoreSataPort)); + break; + } + Status = ScanForRapidStartMbrPartition (HandleBuffer[Index], StoreSectors, StoreLbaAddr); + if (Status == EFI_SUCCESS) { + + if ( (!AhciMode) && (!gPchEfiRaidDriver) ) RetrieveSataPortNumberInt13(StoreSataPort, FALSE); + + DEBUG ((EFI_D_INFO, "Found Mbr RapidStart Store on SATA port=%d\n", *StoreSataPort)); + break; + } + } + } + + FreePool (HandleBuffer); + } + + return Status; +} + +/** + Search if any type of RapidStart Store partition present + + @param[in] RapidStartPolicy - RapidStart Platform Policy protocol + @param[out] StoreSectors - Size of RapidStart store partition + @param[out] StoreLbaAddr - Address of RapidStart store partition + @param[out] StoreSataPort - Port number for RapidStart store partition + + @retval EFI_SUCCESS - GPT or MBR type RapidStart Store found + @retval EFI_NOT_FOUND - GPT or MBR type RapidStart Store not found +**/ +EFI_STATUS +SearchRapidStartStore ( + IN RAPID_START_PLATFORM_POLICY_PROTOCOL *RapidStartPolicy, + OUT UINT32 *StoreSectors, + OUT UINT64 *StoreLbaAddr, + OUT UINT8 *StoreSataPort + ) +{ + BOOLEAN AhciMode; + EFI_STATUS Status; + VOID *Empty; + + *StoreSectors = 0; + *StoreLbaAddr = 0; + *StoreSataPort = 0; + + // + // Get current SATA operation mode (only AHCI or RAID mode is supported) + // + AhciMode = (MmioRead8 ( + MmPciAddress ( + 0, + DEFAULT_PCI_BUS_NUMBER_PCH, + PCI_DEVICE_NUMBER_PCH_SATA, + PCI_FUNCTION_NUMBER_PCH_SATA, + R_PCH_SATA_SUB_CLASS_CODE) + ) == V_PCH_SATA_SUB_CLASS_CODE_AHCI); + + Status = gBS->LocateProtocol(&gPchEfiRaidDriverExecutionGuid, NULL, &Empty); + if (Status == EFI_SUCCESS) gPchEfiRaidDriver = TRUE; + + Status = DetectRapidStartPartition (AhciMode, RapidStartPolicy, StoreSectors, StoreLbaAddr, StoreSataPort); + + return Status; +} + +/** + Generate RapidStart Store UID + + @retval UINT64 as RapidStart Store UID +**/ +UINT64 +GenerateRapidStartStoreUid ( + VOID + ) +{ + UINT64 Uid; + UINT32 HpetBase; + UINT32 HpetSetting; + + Uid = AsmReadTsc (); + + HpetSetting = MmioRead32 (PCH_RCRB_BASE + R_PCH_RCRB_HPTC); + if (HpetSetting & B_PCH_RCRB_HPTC_AE) { + HpetBase = R_PCH_PCH_HPET_CONFIG + (HpetSetting & B_PCH_RCRB_HPTC_AS) * 0x1000; + Uid ^= (LShiftU64 ((*(UINT64 *) (UINTN) (HpetBase + 0xF0)), 32)); + } else { + // + // Use certain random memory content as part of UID. + // + Uid ^= (LShiftU64 ((*(UINT64 *) (UINTN) (0xF5C00)), 32)); + } + + return Uid; +} + +VOID +EnableHibernate ( + VOID + ) +/*++ + +Routine Description: + + Re-enable Hibernation when RapidStart enabled but RapidStart Store not present. + +Arguments: + + None + +Returns: + + None + +--*/ +{ +} +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2012, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//************************************************************************* diff --git a/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Dxe/RapidStartDxeLib.cif b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Dxe/RapidStartDxeLib.cif new file mode 100644 index 0000000..88a8a56 --- /dev/null +++ b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Dxe/RapidStartDxeLib.cif @@ -0,0 +1,12 @@ +<component> + name = "RapidStartDxeLib" + category = ModulePart + LocalRoot = "Board\EM\RapidStartWrapper\Library\RapidStartPlatformLib\Dxe" + RefName = "RapidStartDxeLib" +[files] +"RapidStartDxeLib.sdl" +"RapidStartDxeLib.mak" +"RapidStartDxeLib.c" +"RapidStartDxeLib.h" +"RapidStartDxeLib.inf" +<endComponent> diff --git a/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Dxe/RapidStartDxeLib.h b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Dxe/RapidStartDxeLib.h new file mode 100644 index 0000000..6685bc4 --- /dev/null +++ b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Dxe/RapidStartDxeLib.h @@ -0,0 +1,137 @@ +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2012, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** + +//********************************************************************** +// $Header: /Alaska/SOURCE/Modules/Intel Fast Flash Standby/iRST_SharkBay/RapidStartWrapper/RapidStartDxeLib/RapidStartDxeLib.h 2 3/14/14 9:56a Joshchou $ +// +// $Revision: 2 $ +// +// $Date: 3/14/14 9:56a $ +//********************************************************************** +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/Intel Fast Flash Standby/iRST_SharkBay/RapidStartWrapper/RapidStartDxeLib/RapidStartDxeLib.h $ +// +// 2 3/14/14 9:56a Joshchou +// +// 1 10/15/12 4:41a Bensonlai +// [TAG] None +// [Category] Improvement +// [Description] [Category] Improvement +// [Severity] Important +// [Description] Rename all IFFS sting to Rapid Start. +// [Files] Board\EM\RapidStartWrapper\*.*, ReferenceCode\RapidStart\*.* +// +// [Files] RapidStartDxeLib.cif +// RapidStartDxeLib.sdl +// RapidStartDxeLib.mak +// RapidStartDxeLib.c +// RapidStartDxeLib.h +// RapidStartDxeLib.inf +// +//********************************************************************** +//<AMI_FHDR_START> +// +// Name: RapidStartDxeLib.h +// +// Description: RapidStart Dxe Platform Library header file. +// +//<AMI_FHDR_END> +//********************************************************************** + +#ifndef _RAPID_START_DXE_LIB_H_ +#define _RAPID_START_DXE_LIB_H_ +#if !defined(EDK_RELEASE_VERSION) || (EDK_RELEASE_VERSION < 0x00020000) +#include EFI_PROTOCOL_CONSUMER (RapidStartPlatformPolicy) +#endif + +#define RAPID_START_PART_TYPE_MBR 0x84 /* Hibernation partition -- APM 1.1f */ +/// +/// Partition Name: Intel RapidStart Reserved +/// GUID: D3BFE2DE-3DAF-11DF-BA40-E3A556D89593 +/// +#define RAPID_START_GPT_GUID \ + { \ + 0xD3BFE2DE, 0x3DAF, 0x11DF, 0xba, 0x40, 0xe3, 0xa5, 0x56, 0xd8, 0x95, 0x93 \ + } + +/** + Search if any type of RapidStart Store partition present + + This function will search all connected/initialized SSD and see if any valid and + supported Rapid Start Store present or not. It will scan both GPT and MBR type + partitions and return the required information for accessing Rapid Start Store. + If no valid/supported Rapid Start Store found the Rapid Start will be disabled. + The method and algorithm for searching Rapid Start Store could be implemented by + platform design. + + @param[in] RapidStartPolicy - RapidStart Platform Policy protocol + @param[out] StoreSectors - Size of RapidStart store partition + @param[out] StoreLbaAddr - Address of RapidStart store partition + @param[out] StoreSataPort - Port number for RapidStart store partition + + @retval EFI_SUCCESS - GPT or MBR type RapidStart Store found + @retval EFI_NOT_FOUND - GPT or MBR type RapidStart Store not found +**/ +EFI_STATUS +SearchRapidStartStore ( + IN RAPID_START_PLATFORM_POLICY_PROTOCOL *RapidStartPolicy, + OUT UINT32 *StoreSectors, + OUT UINT64 *StoreLbaAddr, + OUT UINT8 *StoreSataPort + ); + +/** + Generate RapidStart Store UID + + This function will generate a unique ID which will be stored into Rapid Start + Store for identifying Rapid Start Store changing condition. When Rapid Start + Store changed during Rapid Start Resume, the Rapid Start Resume should be + aborted. By default this ID is combining the CPU TSC and HPET counter. This UID + will only be generated when Rapid Start Persistent Data not present or Rapid + Start Store has changed in previous resume. + + @retval UINT64 as RapidStart Store UID +**/ +UINT64 +GenerateRapidStartStoreUid ( + VOID + ); + +/** + Re-enable Hibernation when RapidStart enabled but RapidStart Store not present. + + It's recommended to disable ACPI Hibernate support when Rapid Start feature + enabled. In this case, if Rapid Start Store not present or invalid (Rapid Start + will not be executed), ACPI Hibernate should be re-enabled. This function + required porting to fit platform implementation. +**/ +VOID +EnableHibernate ( + VOID + ); +#endif +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2012, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//************************************************************************* diff --git a/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Dxe/RapidStartDxeLib.inf b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Dxe/RapidStartDxeLib.inf new file mode 100644 index 0000000..f72934d --- /dev/null +++ b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Dxe/RapidStartDxeLib.inf @@ -0,0 +1,56 @@ +## @file +# Component description file for the RapidStartDxeLib +# +#@copyright +# Copyright (c) 1999 - 2012 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. +# +# This file contains a 'Sample Driver' and is licensed as such +# under the terms of your license agreement with Intel or your +# vendor. This file may be modified by the user, subject to +# the additional terms of the license agreement +# + +[defines] +BASE_NAME = RapidStartDxeLib +COMPONENT_TYPE = LIBRARY + +[sources.common] + RapidStartDxeLib.c + RapidStartDxeLib.h + +[includes.common] + . + $(EDK_SOURCE)/Foundation + $(EDK_SOURCE)/Foundation/Include + $(EDK_SOURCE)/Foundation/Efi + $(EDK_SOURCE)/Foundation/Efi/Include + $(EDK_SOURCE)/Foundation/Framework + $(EDK_SOURCE)/Foundation/Framework/Include + $(EDK_SOURCE)/Foundation/Library/EdkIIGlueLib/Include + $(EDK_SOURCE)/Foundation/Library/EdkIIGlueLib/Include/Pcd + $(EDK_SOURCE)/Foundation/Include/IndustryStandard + $(EDK_SOURCE)/Foundation/Library/Dxe/Include + $(EDK_SOURCE)/Foundation/Core/Dxe + $(EDK_SOURCE)/Foundation/Cpu/Pentium/Include + $(EFI_SOURCE)/$(PROJECT_PCH_ROOT)/Protocol + $(EFI_SOURCE)/$(PROJECT_PCH_ROOT)/Include + $(EFI_SOURCE)/$(PROJECT_PCH_ROOT) + $(EFI_SOURCE)/$(PROJECT_RAPID_START_ROOT) + $(EFI_SOURCE)/$(PROJECT_RAPID_START_ROOT)/Include + $(EFI_SOURCE)/$(PROJECT_RAPID_START_ROOT)/Samplecode + $(EFI_SOURCE)/$(PROJECT_RAPID_START_ROOT)/Samplecode/Include + $(EFI_SOURCE)/$(PROJECT_RAPID_START_ROOT)/Samplecode/Library/RapidStartCommonLib + $(EFI_SOURCE)/$(PROJECT_SA_ROOT)/Include + $(EFI_SOURCE)/$(PROJECT_SA_ROOT)/Guid/AcpiVariable + +[nmake.common] +C_FLAGS = $(C_FLAGS) + +C_STD_INCLUDE=
\ No newline at end of file diff --git a/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Dxe/RapidStartDxeLib.mak b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Dxe/RapidStartDxeLib.mak new file mode 100644 index 0000000..00c4388 --- /dev/null +++ b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Dxe/RapidStartDxeLib.mak @@ -0,0 +1,78 @@ +#********************************************************************** +#********************************************************************** +#** ** +#** (C)Copyright 1985-2012, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#********************************************************************** +#********************************************************************** + +#********************************************************************** +# $Header: /Alaska/SOURCE/Modules/Intel Fast Flash Standby/iRST_SharkBay/RapidStartWrapper/RapidStartDxeLib/RapidStartDxeLib.mak 1 10/15/12 4:41a Bensonlai $ +# +# $Revision: 1 $ +# +# $Date: 10/15/12 4:41a $ +#********************************************************************** +# Revision History +# ---------------- +# $Log: /Alaska/SOURCE/Modules/Intel Fast Flash Standby/iRST_SharkBay/RapidStartWrapper/RapidStartDxeLib/RapidStartDxeLib.mak $ +# +# 1 10/15/12 4:41a Bensonlai +# [TAG] None +# [Category] Improvement +# [Description] [Category] Improvement +# [Severity] Important +# [Description] Rename all IFFS sting to Rapid Start. +# [Files] Board\EM\RapidStartWrapper\*.*, ReferenceCode\RapidStart\*.* +# +# [Files] RapidStartDxeLib.cif +# RapidStartDxeLib.sdl +# RapidStartDxeLib.mak +# RapidStartDxeLib.c +# RapidStartDxeLib.h +# RapidStartDxeLib.inf +# +#********************************************************************** +#<AMI_FHDR_START> +# +# Name: RapidStartDxeLib.mak +# +# Description: Component description file for the RapidStartDxeLib. +# +#<AMI_FHDR_END> +#********************************************************************** + +all : RapidStartDxeLib + +$(RapidStartDxeLib_LIB) : RapidStartDxeLib + +RapidStartDxeLib : $(BUILD_DIR)\RapidStartDxeLib.mak RapidStartDxeLibBin + +$(BUILD_DIR)\RapidStartDxeLib.mak : $(RapidStartDxeLib_DIR)\$(@B).cif $(RapidStartDxeLib_DIR)\$(@B).mak $(BUILD_RULES) + $(CIF2MAK) $(RapidStartDxeLib_DIR)\$(@B).cif $(CIF2MAK_DEFAULTS) + +RapidStartDxeLibBin : + $(MAKE) /$(MAKEFLAGS) $(EDKIIGLUE_DEFAULTS)\ + /f $(BUILD_DIR)\RapidStartDxeLib.mak all\ + "MY_INCLUDES=$(EDK_INCLUDES) $(EdkIIGlueLib_INCLUDES) $(INTEL_MCH_INCLUDES) $(INTEL_PCH_INCLUDES) $(RAPIDSTART_INCLUDES)" \ + TYPE=LIBRARY \ + LIBRARY_NAME=$(RapidStartDxeLib_LIB) +#************************************************************************* +#************************************************************************* +#** ** +#** (C)Copyright 1985-2012, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#************************************************************************* +#************************************************************************* diff --git a/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Dxe/RapidStartDxeLib.sdl b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Dxe/RapidStartDxeLib.sdl new file mode 100644 index 0000000..02fd98b --- /dev/null +++ b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Dxe/RapidStartDxeLib.sdl @@ -0,0 +1,98 @@ +#********************************************************************** +#********************************************************************** +#** ** +#** (C)Copyright 1985-2012, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#********************************************************************** +#********************************************************************** + +#********************************************************************** +# $Header: /Alaska/SOURCE/Modules/Intel Fast Flash Standby/iRST_SharkBay/RapidStartWrapper/RapidStartDxeLib/RapidStartDxeLib.sdl 1 10/15/12 4:41a Bensonlai $ +# +# $Revision: 1 $ +# +# $Date: 10/15/12 4:41a $ +#********************************************************************** +# Revision History +# ---------------- +# $Log: /Alaska/SOURCE/Modules/Intel Fast Flash Standby/iRST_SharkBay/RapidStartWrapper/RapidStartDxeLib/RapidStartDxeLib.sdl $ +# +# 1 10/15/12 4:41a Bensonlai +# [TAG] None +# [Category] Improvement +# [Description] [Category] Improvement +# [Severity] Important +# [Description] Rename all IFFS sting to Rapid Start. +# [Files] Board\EM\RapidStartWrapper\*.*, ReferenceCode\RapidStart\*.* +# +# [Files] RapidStartDxeLib.cif +# RapidStartDxeLib.sdl +# RapidStartDxeLib.mak +# RapidStartDxeLib.c +# RapidStartDxeLib.h +# RapidStartDxeLib.inf +# +#********************************************************************** +#<AMI_FHDR_START> +# +# Name: RapidStartDxeLib.sdl +# +# Description: SDL file for the RapidStartDxeLib. +# +#<AMI_FHDR_END> +#********************************************************************** + +TOKEN + Name = "RapidStartDxeLib_SUPPORT" + Value = "1" + Help = "Main switch to enable RapidStartDxeLib support in Project" + TokenType = Boolean + TargetEQU = Yes + TargetMAK = Yes + Master = Yes +End + +PATH + Name = "RapidStartDxeLib_DIR" +End + +MODULE + Help = "Includes RapidStartDxeLib.mak to Project" + File = "RapidStartDxeLib.mak" +End + +ELINK + Name = "RapidStartDxeLib_LIB" + InvokeOrder = ReplaceParent +End + +ELINK + Name = "$(BUILD_DIR)\RapidStartDxeLib.lib" + Parent = "RapidStartDxeLib_LIB" + InvokeOrder = AfterParent +End + +ELINK + Name = "/I$(RapidStartDxeLib_DIR)" + Parent = "RAPIDSTART_INCLUDES" + InvokeOrder = AfterParent +End +#************************************************************************* +#************************************************************************* +#** ** +#** (C)Copyright 1985-2012, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#************************************************************************* +#************************************************************************* diff --git a/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Pei/OpensslLib.lib b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Pei/OpensslLib.lib Binary files differnew file mode 100644 index 0000000..290a4fa --- /dev/null +++ b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Pei/OpensslLib.lib diff --git a/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Pei/PeiCryptLib.lib b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Pei/PeiCryptLib.lib Binary files differnew file mode 100644 index 0000000..b05426c --- /dev/null +++ b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Pei/PeiCryptLib.lib diff --git a/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Pei/RapidStartPeiLib.c b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Pei/RapidStartPeiLib.c new file mode 100644 index 0000000..61d7f52 --- /dev/null +++ b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Pei/RapidStartPeiLib.c @@ -0,0 +1,970 @@ +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2013, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** + +//********************************************************************** +// $Header: /Alaska/SOURCE/Modules/Intel Fast Flash Standby/iRST_SharkBay/RapidStartWrapper/RapidStartPeiLib/RapidStartPeiLib.c 5 7/15/13 6:32a Joshchou $ +// +// $Revision: 5 $ +// +// $Date: 7/15/13 6:32a $ +//********************************************************************** +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/Intel Fast Flash Standby/iRST_SharkBay/RapidStartWrapper/RapidStartPeiLib/RapidStartPeiLib.c $ +// +// 5 7/15/13 6:32a Joshchou +// [TAG] EIP129090 +// [Category] Bug Fix +// [Severity] Important +// [Symptom] Platform automatically wakes itself after entering S4 when +// doing Rapid Start flow +// [RootCause] The Update of PCH RC 1.6.0 in PchSmmSx.c will put XHCI +// into incorrect state on ULT platfrom. +// [Solution] Added code in the Rapid Start Entry phase, to put XHCI +// into the correct state i.e. D3 to fix the auto wake-up issue. +// +// 4 6/21/13 6:03a Joshchou +// [TAG] EIP126792 +// [Category] Bug Fix +// [Severity] Minor +// [Symptom] Can't do AMI capsule when Intel Rapid Start eanble +// [RootCause] CMOS RapidStartFlag does not clear. +// [Solution] Clear RapidStartFlag when cold boot. +// +// 3 3/14/13 11:41p Bensonlai +// [TAG] EIP118122 +// [Category] Spec Update +// [Severity] Normal +// [Description] [SBY] Intel Rapid Start Technology Framework Reference +// Code Production Version 1.3.0 +// [Files] RapidStartPeiLib.c +// +// 2 12/18/12 12:19a Bensonlai +// [TAG] EIP109701 +// [Category] Spec Update +// [Severity] Normal +// [Description] Updated to Shark Bay Rapid Start Reference Code +// Version 0.8.1 +// [Files] RapidStartPeiLib.c, RapidStartPeiLib.h +// +// 1 10/15/12 4:41a Bensonlai +// [TAG] EIPNone +// [Category] Improvement +// [Description] [Category] Improvement +// [Severity] Important +// [Description] Rename all IFFS sting to Rapid Start. +// [Files] Board\EM\RapidStartWrapper\*.*, ReferenceCode\RapidStart\*.* +// [Files] RapidStartPeiLib.cif +// RapidStartPeiLib.sdl +// RapidStartPeiLib.mak +// RapidStartPeiLib.c +// RapidStartPeiLib.h +// RapidStartPeiLib.inf +// RapidStartPeiLib.lib +// PeiCryptLib.lib +// OpensslLib.lib +// +//********************************************************************** +//<AMI_FHDR_START> +// +// Name: RapidStartPeiLib.c +// +// Description: RapidStart Platform PEI library. +// +//<AMI_FHDR_END> +//********************************************************************** + +#if !defined(EDK_RELEASE_VERSION) || (EDK_RELEASE_VERSION < 0x00020000) +#include "EdkIIGluePeim.h" +#include "RapidStartConfig.h" +#include "RapidStartPeiLib.h" +#include "RapidStartCommonLib.h" +#include <SaAccess.h> +#include <PchRegs.h> +#include <PchPlatformLib.h> +#endif +#ifndef SW_SMI_IO_ADDRESS +#define SW_SMI_IO_ADDRESS 0xB2 +#endif + +#ifndef SW_SMI_ACPI_ENABLE +#define SW_SMI_ACPI_ENABLE 0xA0 +#endif + +//AMI_OVERRIDE_FOR_RAPID_START +#ifndef FFS_NV_CONFIG_REG +#define FFS_NV_CONFIG_REG 0x47 +#endif +//AMI_OVERRIDE_FOR_RAPID_START + +#define HDD_PWD_ENCRYPTION_KEY "H?p1mA*k920_84o3d^!z@L.x4$kY64" + +#pragma pack(1) +typedef struct _HDDSECDATA +{ + UINT16 UserMaster; + UINT32 PasswordLength; + UINT8 HddUserPassword[ATA_PASSWORD_LEN]; + UINT8 HddMasterPassword[ATA_PASSWORD_LEN]; +} HDDSECDATA; +#pragma pack() + +#define DEFAULT_PCI_BUS_NUMBER_PCH 0 +#define PCI_DEVICE_NUMBER_PCH_SATA 31 +#define PCI_FUNCTION_NUMBER_PCH_SATA 2 + +#define IDE_SECURITY_PWNV_GUID \ +{ 0x69967a8c, 0x1159, 0x4522, 0xaa, 0x89, 0x74, 0xcd, 0xc6, 0xe5, 0x99, 0xa0} + +/** + Enables ACPI mode after RapidStart resume. + + @param[in] PeiServices - Pointer to PEI Services Table. + + @retval EFI_SUCCESS - enabled ACPI mode +**/ +EFI_STATUS +RapidStartEnableAcpi ( + IN EFI_PEI_SERVICES **PeiServices + ) +{ +#ifdef RAPID_START_WHOLE_MEMORY_CHECK + DEBUG ((EFI_D_INFO, "[RapidStart] SMI port=%X, RapidStart SWSMI cmd=%X\n", SW_SMI_IO_ADDRESS, SW_SMI_WHOLE_MEMORY_CHECK)); + IoWrite8 (SW_SMI_IO_ADDRESS, SW_SMI_WHOLE_MEMORY_CHECK); +#endif + DEBUG ((EFI_D_INFO, "[RapidStart] SMI port=%X, ACPI_ENABLE cmd=%X\n", SW_SMI_IO_ADDRESS, SW_SMI_ACPI_ENABLE)); + IoWrite8 (SW_SMI_IO_ADDRESS, SW_SMI_ACPI_ENABLE); + return EFI_SUCCESS; +} + +//<AMI_PHDR_START> +//--------------------------------------------------------------------------- +// +// Procedure: ConvertHddDataIdToString +// +// Description: Converts Integer HDD Data Id to String. +// +// Input: +// IN UINT32 DataId, +// OUT CHAR16 *String +// Output: +// None +// +// +//--------------------------------------------------------------------------- +//<AMI_PHDR_END> +VOID ConvertHddDataIdToString( + IN UINT32 DataId, + OUT CHAR16 *String ) +{ + UINTN Num, i; + Num = EfiValueToString (String, DataId, 0, 0); + + for ( i = 0; i < Num; i++ ) + { + DEBUG((EFI_D_ERROR, "HDD Passowrd: String[%x] = %x. \n", i, String[i])); + } + + return; +} + +//<AMI_PHDR_START> +//--------------------------------------------------------------------------- +// +// Procedure: EncodeDecodePassword +// +// Description: Encodes/Decodes Password. +// +// Input: +// IN UINT8 *InputString, +// OUT UINT8 *OutputString, +// IN UINT32 StringLen +// Output: +// None +// +//--------------------------------------------------------------------------- +//<AMI_PHDR_END> +VOID EncodeDecodePassword( + IN EFI_PEI_SERVICES **PeiServices, + IN UINT8 *InputString, + OUT UINT8 *OutputString, + IN UINT32 StringLength ) +{ + UINT8 *Key; + UINT32 i; + UINT32 KeyIndex; + UINT32 KeyLength; + + if ((InputString == NULL) || (StringLength == 0)) + { + return; + } + + KeyLength = (UINT32)(EfiAsciiStrLen( HDD_PWD_ENCRYPTION_KEY)); + + Key = AllocateZeroPool (KeyLength); + CopyMem ((VOID *) Key, (VOID *) HDD_PWD_ENCRYPTION_KEY, (UINTN) KeyLength); + ASSERT (Key != NULL); + + for ( i = 0, KeyIndex = 0; i < StringLength; i++, KeyIndex++ ) + { + if ( KeyIndex == (KeyLength - 1)) + { + KeyIndex = 0; + } + OutputString[i] = (UINT8) ( InputString[i] ^ Key[KeyIndex] ); + } + + return; +} + +/** + This callback is provided to support drive password locking interoperability with RapidStart. + It is called before RapidStart transition is to occur. If SSD partiotion is located on password + locked drive this function must copy the password to the output buffer. + Size of the buffer equals ATA_PASSWORD_LEN. + + Normally the drive password is kept in SMRAM so it can be used to unlock the drive at S3 resume, + thus during RapidStartEntry the password from SMRAM shall be returned. However at RapidStartExit the content + of SMRAM is not yet available so the password has to be preserved in a non-volatile memory + during RapidStartEntry (in RapidStartAfterTransition callback) and retrieved by this function. + + For security reasons the password must be scrubbed from non-volatile memory on RapidStartExit before + returning from this function. On RapidStartEntry the password must not be stored to non-volatile memory + sooner than RapidStartAfterTransition is called (that is after RapidStart non-volatile flag is set). + + @param[in] PeiServices - Pointer to PEI Services Table + @param[in] Transition - RapidStart transition being performed + @param[in] SataPort - locked SATA port + @param[out] Password - output buffer to place the password in + @param[out] FreezeLock - set to TRUE to freeze drive lock, set to FALSE otherwise + + @retval EFI_SUCCESS - Unlock password copied to the buffer + @retval EFI_NOT_FOUND - No password provided (will break the transition) +**/ +EFI_STATUS +RapidStartGetDriveUnlockPassword ( + IN EFI_PEI_SERVICES **PeiServices, + IN RAPID_START_TRANSITION Transition, + IN UINT8 SataPort, + OUT UINT8 *Password, + OUT BOOLEAN *FreezeLock + ) +{ + EFI_STATUS Status; + EFI_PEI_READ_ONLY_VARIABLE_PPI *ReadOnlyVariable; + UINT16 wBDF; + UINT16 wPortPMModeFlag; + UINT8 DeviceorPMPort = 0xff; + BOOLEAN ModeFlag = TRUE; //TRUE is AHCI mode, FALSE is IDE mode. + UINT32 HddDataId; + CHAR16 *HddSecutiyData = NULL; + UINTN HddSecDataSize = sizeof (HDDSECDATA); + HDDSECDATA *HddSecData; + UINT16 Control; + UINTN i; + UINT8 CryptBuffer[ATA_PASSWORD_LEN]; + EFI_GUID gIdeSecurityPwNvguid = IDE_SECURITY_PWNV_GUID; + + Status = PeiServicesLocatePpi (&gEfiPeiReadOnlyVariablePpiGuid, 0, NULL, &ReadOnlyVariable); + ASSERT_EFI_ERROR (Status); + + wBDF = (UINT16)((DEFAULT_PCI_BUS_NUMBER_PCH << 8) \ + | (PCI_DEVICE_NUMBER_PCH_SATA << 3) \ + | PCI_FUNCTION_NUMBER_PCH_SATA ); + wPortPMModeFlag = (UINT16)((SataPort << 12) \ + | (DeviceorPMPort << 4) \ + | ((UINT8)ModeFlag)); + + HddDataId = (UINT32)(((UINT16)wBDF << 16) + ((UINT16)wPortPMModeFlag)); + DEBUG ((EFI_D_ERROR, "[RapidStart] HddDataId=%X\n", HddDataId)); + + HddSecutiyData = AllocateZeroPool(ATA_PASSWORD_LEN); + + ConvertHddDataIdToString (HddDataId, HddSecutiyData); + + HddSecData = AllocateZeroPool(HddSecDataSize); + + Status = ReadOnlyVariable->PeiGetVariable ( + GetPeiServicesTablePointer (), + HddSecutiyData, + &gIdeSecurityPwNvguid, + NULL, + &HddSecDataSize, + HddSecData + ); + DEBUG ((EFI_D_ERROR, "[RapidStart] PeiGetVariable Status=%r\n", Status)); + if (EFI_ERROR (Status)) { + return EFI_NOT_FOUND; + } + + Control = HddSecData->UserMaster; + + DEBUG ((EFI_D_ERROR, "[RapidStart] Control=%x\n", Control)); + + if ( Control & 0x01 ) + { + for ( i = 0; i < sizeof (HddSecData->HddMasterPassword); i++ ) + { + CryptBuffer[i] = HddSecData->HddMasterPassword[i]; + } + + EncodeDecodePassword (PeiServices, CryptBuffer, Password, HddSecData->PasswordLength); + } + else { + for ( i = 0; i < sizeof (HddSecData->HddUserPassword); i++ ) + { + DEBUG ((EFI_D_ERROR, "[RapidStart] HddSecData->HddUserPassword[%x]= %x.\n", i, HddSecData->HddUserPassword[i])); + CryptBuffer[i] = HddSecData->HddUserPassword[i]; + } + + EncodeDecodePassword (PeiServices, CryptBuffer, Password, HddSecData->PasswordLength); + } + + *FreezeLock = TRUE; + + return EFI_SUCCESS; +} + +/** + This callback is executed before RapidStart transition is performed, but after RapidStart transition conditions has been met. + + @param[in] PeiServices - Pointer to PEI Services Table + @param[in] Transition - RapidStart transition being performed + @param[in] SataPort - SATA port of RapidStart storage drive + + @retval EFI_SUCCESS - RapidStart transition will follow + @retval EFI_ABORTED - RapidStart transition will not be performed +**/ +EFI_STATUS +RapidStartBeforeTransition ( + IN EFI_PEI_SERVICES **PeiServices, + IN RAPID_START_TRANSITION Transition, + IN UINT8 SataPort + ) +{ + return EFI_SUCCESS; +} + +/** + This callback is executed at the end of RapidStart transition whether succesfull ot not. + + If RapidStart partition is located on password locked drive the drive password must be + copied to non-volatile memory during RapidStartEntry in this function, so it is available + on RapidStartExit (see RapidStartGetDriveUnlockPassword). + + @param[in] PeiServices - Pointer to PEI Services Table + @param[in] Transition - RapidStart transition being performed + @param[in] TransitionStatus - Status of the RapidStart transition + @param[in] SataPort - SATA port of RapidStart storage drive +**/ +VOID +RapidStartAfterTransition ( + IN EFI_PEI_SERVICES **PeiServices, + IN RAPID_START_TRANSITION Transition, + IN EFI_STATUS TransitionStatus, + IN UINT8 SataPort + ) +{ + //AMI_OVERRIDE_FOR_RAPID_START + //Clear CMOS RapidStartFlag in PEI + RtcWrite (FFS_NV_CONFIG_REG, 0); + //AMI_OVERRIDE_FOR_RAPID_START +} + +#ifndef RAPID_START_NO_SMRAM_INTEGRITY_CHECK +/** + Saves SMRAM Secure Hash to non-volatile secure location. + + @param[in] Hash[] - hash value + + @retval EFI_SUCCESS - Hash value saved successfully + @retval EFI_NOT_FOUND - Hash value not found +**/ +EFI_STATUS +RapidStartSaveSecureHash ( + IN UINT8 Hash[RAPID_START_SECURE_HASH_LENGTH] + ) +{ + UINT8 Index; + + DEBUG ((EFI_D_ERROR, "RapidStartSaveSecureHash()\n")); + + for (Index = 0; Index < RAPID_START_SECURE_HASH_LENGTH; Index++) { + // Save SMRAM hash value + RtcWrite (FFS_SMRAM_HASH_DATA_REG + Index, Hash[Index]); + } + + return EFI_SUCCESS; +} + +/** + Retrieves and removes SMRAM hash from non-volatile memory + + @param[out] Hash[] - hash value + + @retval EFI_SUCCESS - Hash value has been restored and cleared successfully + @retval EFI_NOT_FOUND - Hash value not found +**/ +EFI_STATUS +RapidStartRestoreAndClearSecureHash ( + OUT UINT8 Hash[RAPID_START_SECURE_HASH_LENGTH] + ) +{ + UINT8 Index; + + DEBUG ((EFI_D_ERROR, "RapidStartRestoreAndClearSecureHash()\n")); + + for (Index = 0; Index < RAPID_START_SECURE_HASH_LENGTH; Index++) { + // Retrieve SMRAM hash value + Hash[Index] = RtcRead (FFS_SMRAM_HASH_DATA_REG + Index); + // Remove SMRAM value + RtcWrite (FFS_SMRAM_HASH_DATA_REG + Index, 0); + } + return EFI_SUCCESS; +} + +#endif + +/** + Provide a hook for OEM to cancel RapidStart flow. + This function may impact RapidStart Entry performance since it's polled frequently. + + @retval FALSE - Do not cancel RapidStart flow + @retval TRUE - The RapidStart Entry flow should be canceled and do S3 resume back to OS +**/ +BOOLEAN +RapidStartShouldCancelEntry ( + VOID + ) +{ + return FALSE; +} + +/// +/// Device IDs for WLAN RSR Workaround +/// +UINT16 mWlanSkusDeviceIdsTable[] = { + 0x422B, 0x4238, // 6300 - Puma Peak 3 + 0x0082, 0x0085, // 6205 - Taylor Peak + 0x0890, 0x0891, // 2200 - Marble Peak + 0x0887, 0x0888, // 2230 - Jackson Peak 1 + 0x088F, 0x088E, // 6235 - Jackson Peak 2 + 0x008A, 0x008B, // 1030 - Rainbow Peak 1 + 0x0091, 0x0090, // 6230 - Rainbow Peak 2 + 0x0885, 0x0886, // 6150 - Kelsey Peak + 0x0087, 0x0089, // 6250 - Kilmer Peak +}; + +/// +/// Device IDs for WLAN D3 Workaround +/// +UINT16 mWlanSkusDeviceIdsTable2[] = { + 0x08B3, 0x08B4, // 3160 - Wilkins Peak 1 + 0x08B1, 0x08B2, // 7260 - Wilkins Peak 2 +}; + +/** + This function is work around for NetDetect and WakeOnLan when RapidStart enabled. + + @retval EFI_SUCCESS - Operation successfully performed +**/ +EFI_STATUS +RapidStartWANetDetect ( + IN EFI_PEI_SERVICES **PeiServices, + IN UINT32 WlanMmioSpace + ) +{ + UINT8 RpFunction; + UINTN RpBase; + UINT8 SecBusNum; + UINT8 SecSubBusNum; + UINT8 EpBusNum; + UINTN EpBase; + UINTN WlanSkusDeviceIdIndex; + UINT8 CapPtr; + UINT8 NxtPtr; + UINT8 CapID; + UINT8 PMCreg; + UINT8 PMCSR; + UINT32 Timeout; + PEI_STALL_PPI *StallPpi; + EFI_STATUS Status; + + DEBUG ((EFI_D_INFO, "RapidStartWANetDetect Start\n")); + + Status = PeiServicesLocatePpi (&gPeiStallPpiGuid, 0, NULL, (VOID **) &StallPpi); + ASSERT_EFI_ERROR (Status); + + // + // Scan PCH PCI-EX slots (Root Port) : Device 28 Function 0~7 + // + for (RpFunction = 0; RpFunction < GetPchMaxPciePortNum (); RpFunction ++) { + RpBase = MmPciAddress (0, DEFAULT_PCI_BUS_NUMBER_PCH, PCI_DEVICE_NUMBER_PCH_PCIE_ROOT_PORTS, RpFunction, 0); + DEBUG ((EFI_D_INFO, "RapidStartWANetDetect: PCI-EX slot %x ...\n", RpFunction)); + + if ((MmioRead16 (RpBase + R_PCH_PCIE_SLSTS) & B_PCH_PCIE_SLSTS_PDS) != 0 && MmioRead16 (RpBase + R_PCH_PCIE_VENDOR_ID) == V_PCH_PCIE_VENDOR_ID) { + + /// + /// Set WLAN PortBus = 1 to Read Endpoint. + /// + MmioAndThenOr32(RpBase + R_PCH_PCIE_BNUM, 0xFF0000FF, 0x00010100); + + // + // Get the downstream Bus number + // + SecBusNum = (UINT8) (MmioRead32 (RpBase + R_PCH_PCIE_BNUM) >> 8); + SecSubBusNum = (UINT8) (MmioRead32 (RpBase + R_PCH_PCIE_BNUM) >> 16); + + for (EpBusNum = SecBusNum; EpBusNum <= SecSubBusNum; EpBusNum++) { + EpBase = MmPciAddress (0, EpBusNum, 0, 0, 0); + DEBUG ((EFI_D_INFO, "RapidStartWANetDetect: downstream Bus %x\n", EpBusNum)); + + /// + /// A config write is required in order for the device to re-capture the Bus number, + /// according to PCI Express Base Specification, 2.2.6.2 + /// Write to a read-only register VendorID to not cause any side effects. + /// + MmioWrite16 (EpBase + R_PCH_PCIE_VENDOR_ID, 0); + + // + // WLAN RSR Workaround + // + for (WlanSkusDeviceIdIndex = 0; WlanSkusDeviceIdIndex < sizeof (mWlanSkusDeviceIdsTable) / sizeof (mWlanSkusDeviceIdsTable[0]); WlanSkusDeviceIdIndex++) { + if (mWlanSkusDeviceIdsTable[WlanSkusDeviceIdIndex] == MmioRead16 (EpBase + R_PCH_PCIE_DEVICE_ID)) { + DEBUG ((EFI_D_INFO, "RapidStartWANetDetect: Found a device to support RSR and device ID is %x\n", MmioRead16 (EpBase + R_PCH_PCIE_DEVICE_ID))); + + // + // Find out PMCSR register + // + CapPtr = MmioRead8 (EpBase + R_PCH_PCIE_CAPP); + CapID = MmioRead8 (EpBase + CapPtr); + NxtPtr = (UINT8) (MmioRead16 (EpBase + CapPtr) >> 8); + PMCreg = CapPtr; + + while (CapID != 0x01) { + CapID = MmioRead8 (EpBase + NxtPtr); + if (CapID == 0x01) { + PMCreg = NxtPtr; + break; + } + NxtPtr = (UINT8) (MmioRead16 (EpBase + NxtPtr) >> 8); + + if (NxtPtr == 0){ + PMCreg = 0; + break; + } + } + + if (PMCreg != 0) { + PMCSR = PMCreg + 0x04; + + // + // Check whether PME enabled + // + if (MmioRead16 (EpBase + PMCSR) & BIT8) { + DEBUG ((EFI_D_INFO, "RapidStartWANetDetect: This device PME has been enabled\n")); + + // + // Disabled PME + // + MmioAnd16 ((UINTN) (EpBase + PMCSR), (UINT16) (~BIT8)); + + // + // Set the WLAN device to D0 + // + MmioAnd8 ((UINTN) (EpBase + PMCSR), (UINT8)(~(BIT0 + BIT1))); + StallPpi->Stall (PeiServices, StallPpi, STALL_1_MICROSECONDS * 30); + + // + // Disable PCIE memory map access + // + MmioAnd16 ((UINTN) (RpBase + R_PCH_PCIE_PCICMD), (UINT16) (~B_PCH_PCIE_PCICMD_MSE)); + + // + // Define PCIE MMIO BAR contains a valid address value + // + MmioWrite32 (RpBase + R_PCH_PCIE_MBL, (WlanMmioSpace & B_PCH_PCIE_MBL_ML) + ((WlanMmioSpace & B_PCH_PCIE_MBL_ML) >> 16)); + MmioWrite32 (RpBase + R_PCH_PCIE_PMBL, 0x0001FF1); + + // + // Enable PCIE memory map access + // + MmioOr16 ((UINTN) (RpBase + R_PCH_PCIE_PCICMD), (UINT16) B_PCH_PCIE_PCICMD_MSE); + DEBUG ((EFI_D_INFO, "RapidStartWANetDetect: Enabled PCIE memory map and MMIO Bar is %x\n", MmioRead32 (RpBase + R_PCH_PCIE_MBL))); + + // + // Disable WLAN memory map access + // + MmioAnd16 ((UINTN) (EpBase + R_PCH_LAN_CMD), (UINT16) (~B_PCH_LAN_CMD_MSE)); + + // + // Define WLAN MMIO BAR contains a valid address value + // + MmioWrite32 (EpBase + R_PCH_LAN_MEM_BASE_A, WlanMmioSpace); + + // + // Enable WLAN memory map access + // + MmioOr16 ((UINTN) (EpBase + R_PCH_LAN_CMD), (UINT16) B_PCH_LAN_CMD_MSE); + + WlanMmioSpace = MmioRead32 (EpBase + R_PCH_LAN_MEM_BASE_A) & B_PCH_LAN_MBARA_BA; + + DEBUG ((EFI_D_INFO, "RapidStartWANetDetect: Enabled memory map and MMIO Bar is %x\n", WlanMmioSpace)); + // + // BIOS notify the uCode that RSR flow is needed + // + MmioWrite32 ((WlanMmioSpace + 0x58), 0x40); + // + // BIOS waiting for uCode to do the all necessary preparation and set a timer of 100 ms. + // + Timeout = 0; + while ((MmioRead32 (WlanMmioSpace + 0x54) & BIT7) == 0 && Timeout < MAX_UCODE_TIMEOUT) { + StallPpi->Stall (PeiServices, StallPpi, STALL_1_MICROSECONDS); + Timeout++; + } + + DEBUG ((EFI_D_INFO, "RapidStartWANetDetect: The Timeout value is %x and Register 0x54 is %x\n", Timeout, MmioRead32 (WlanMmioSpace + 0x54))); + if (Timeout < MAX_UCODE_TIMEOUT) { + StallPpi->Stall (PeiServices, StallPpi, STALL_1_MICROSECONDS * 100); + // + // Perform WLAN Shared HW reset + // + MmioWrite32 ((WlanMmioSpace + 0x20), BIT7); + StallPpi->Stall (PeiServices, StallPpi, STALL_1_MICROSECONDS * 50); + // + // Re-Enable MAC Clock + // + MmioWrite32 ((WlanMmioSpace + 0x24), BIT2); + StallPpi->Stall (PeiServices, StallPpi, STALL_1_MICROSECONDS * 50000); + // + // De-Reset the MAC + // + MmioAnd32 ((UINTN) (WlanMmioSpace + 0x20), (UINT32) (~BIT0)); + StallPpi->Stall (PeiServices, StallPpi, STALL_1_MICROSECONDS * 50); + + // + // Enabled PME again + // + MmioOr16 ((EpBase + PMCSR), BIT8); + // + // Persistence ON + // + MmioOr32 ((WlanMmioSpace + 0x00), BIT30); + + // + // Set the WLAN device to D3 + // + MmioOr8 ((UINTN) (EpBase + PMCSR), BIT0 + BIT1); + + DEBUG ((EFI_D_INFO, "RapidStartWANetDetect: RSR is successfully\n")); + } + } + } + } + } + + // + // WLAN D3 Workaround + // + for (WlanSkusDeviceIdIndex = 0; WlanSkusDeviceIdIndex < sizeof (mWlanSkusDeviceIdsTable2) / sizeof (mWlanSkusDeviceIdsTable2[0]); WlanSkusDeviceIdIndex++) { + if (mWlanSkusDeviceIdsTable2[WlanSkusDeviceIdIndex] == MmioRead16 (EpBase + R_PCH_PCIE_DEVICE_ID)) { + DEBUG ((EFI_D_INFO, "RapidStartWANetDetect: Found a device to support D3 and device ID is %x\n", MmioRead16 (EpBase + R_PCH_PCIE_DEVICE_ID))); + + // + // Find out PMCSR register + // + CapPtr = MmioRead8 (EpBase + R_PCH_PCIE_CAPP); + CapID = MmioRead8 (EpBase + CapPtr); + NxtPtr = (UINT8) (MmioRead16 (EpBase + CapPtr) >> 8); + PMCreg = CapPtr; + + while (CapID != 0x01) { + CapID = MmioRead8 (EpBase + NxtPtr); + if (CapID == 0x01) { + PMCreg = NxtPtr; + break; + } + NxtPtr = (UINT8) (MmioRead16 (EpBase + NxtPtr) >> 8); + + if (NxtPtr == 0){ + PMCreg = 0; + break; + } + } + + if (PMCreg != 0) { + PMCSR = PMCreg + 0x04; + + // + // Check whether PME enabled + // + if (MmioRead16 (EpBase + PMCSR) & BIT8) { + DEBUG ((EFI_D_INFO, "RapidStartWANetDetect: This device PME has been enabled\n")); + + // + // Set the WLAN device to D3 + // + MmioOr8 ((UINTN) (EpBase + PMCSR), BIT0 + BIT1); + + DEBUG ((EFI_D_INFO, "RapidStartWANetDetect: D3 is successfully\n")); + } + } + } + } + + /// + /// Restore bus numbers on the WLAN bridge. + /// + MmioAnd32(RpBase + R_PCH_PCIE_BNUM, 0xFF0000FF); + } + } + } + DEBUG ((EFI_D_INFO, "RapidStartWANetDetect End\n")); + + return EFI_SUCCESS; +} + +/** + This callback is executed to clear all PEM events before Rapid Start enter S4. + + @retval EFI_SUCCESS - Operation successfully performed +**/ +EFI_STATUS +RapidStartClearOemPmeEvent ( + VOID + ) +{ + UINT16 EhciPme, Ehci2Pme, xHciPme; + UINT8 Index; + UINT16 PCIePme[8]; + UINT16 GigaLanPme; + + DEBUG ((EFI_D_INFO, "RapidStartClearOemPmeEvent Start\n")); + + // + // Save Ehci, Ehci2 and xHci Power Control Status register + // + EhciPme = MmioRead16 ( + MmPciAddress ( + 0, + DEFAULT_PCI_BUS_NUMBER_PCH, + PCI_DEVICE_NUMBER_PCH_USB, + PCI_FUNCTION_NUMBER_PCH_EHCI, + R_PCH_EHCI_PWR_CNTL_STS) + ); + Ehci2Pme = MmioRead16 ( + MmPciAddress ( + 0, + DEFAULT_PCI_BUS_NUMBER_PCH, + PCI_DEVICE_NUMBER_PCH_USB_EXT, + PCI_FUNCTION_NUMBER_PCH_EHCI2, + R_PCH_EHCI_PWR_CNTL_STS) + ); + xHciPme = MmioRead16 ( + MmPciAddress ( + 0, + DEFAULT_PCI_BUS_NUMBER_PCH, + PCI_DEVICE_NUMBER_PCH_XHCI, + PCI_FUNCTION_NUMBER_PCH_XHCI, + R_PCH_XHCI_PWR_CNTL_STS) + ); + // + // Disabled Ehci, Ehcu2 and xHci PME & Clear PME status + // + MmioWrite16 ( + MmPciAddress ( + 0, + DEFAULT_PCI_BUS_NUMBER_PCH, + PCI_DEVICE_NUMBER_PCH_USB, + PCI_FUNCTION_NUMBER_PCH_EHCI, + R_PCH_EHCI_PWR_CNTL_STS), + ((EhciPme & ~B_PCH_EHCI_PWR_CNTL_STS_PME_EN) | B_PCH_EHCI_PWR_CNTL_STS_PME_STS) + ); + MmioWrite16 ( + MmPciAddress ( + 0, + DEFAULT_PCI_BUS_NUMBER_PCH, + PCI_DEVICE_NUMBER_PCH_USB_EXT, + PCI_FUNCTION_NUMBER_PCH_EHCI2, + R_PCH_EHCI_PWR_CNTL_STS), + ((Ehci2Pme & ~B_PCH_EHCI_PWR_CNTL_STS_PME_EN) | B_PCH_EHCI_PWR_CNTL_STS_PME_STS) + ); + MmioWrite16 ( + MmPciAddress ( + 0, + DEFAULT_PCI_BUS_NUMBER_PCH, + PCI_DEVICE_NUMBER_PCH_XHCI, + PCI_FUNCTION_NUMBER_PCH_XHCI, + R_PCH_XHCI_PWR_CNTL_STS), + ((xHciPme & ~B_PCH_XHCI_PWR_CNTL_STS_PME_EN) | B_PCH_XHCI_PWR_CNTL_STS_PME_STS) + ); + + for (Index = 0; Index <= PCI_FUNCTION_NUMBER_PCH_PCIE_ROOT_PORT_8; Index++) { + // + // Save PCIEs Power Control Status register + // + PCIePme[Index] = MmioRead16 ( + MmPciAddress ( + 0, + DEFAULT_PCI_BUS_NUMBER_PCH, + PCI_DEVICE_NUMBER_PCH_PCIE_ROOT_PORTS, + (PCI_FUNCTION_NUMBER_PCH_PCIE_ROOT_PORT_1 + Index), + R_PCH_PCIE_PMCS) + ); + // + // Disabled PCIEs PME & Clear PME status + // + MmioWrite16 ( + MmPciAddress ( + 0, + DEFAULT_PCI_BUS_NUMBER_PCH, + PCI_DEVICE_NUMBER_PCH_PCIE_ROOT_PORTS, + (PCI_FUNCTION_NUMBER_PCH_PCIE_ROOT_PORT_1 + Index), + R_PCH_PCIE_PMCS), + ((PCIePme[Index] & ~B_PCH_PCIE_PMCS_PMEE) | B_PCH_PCIE_PMCS_PMES) + ); + } + + // + // Save Giga Lan Power Control Status register + // + GigaLanPme = MmioRead16 ( + MmPciAddress ( + 0, + DEFAULT_PCI_BUS_NUMBER_PCH, + PCI_DEVICE_NUMBER_PCH_LAN, + PCI_FUNCTION_NUMBER_PCH_LAN, + R_PCH_LAN_PMCS) + ); + // + // Disabled Giga Lan PME & Clear PME status + // + MmioWrite16 ( + MmPciAddress ( + 0, + DEFAULT_PCI_BUS_NUMBER_PCH, + PCI_DEVICE_NUMBER_PCH_LAN, + PCI_FUNCTION_NUMBER_PCH_LAN, + R_PCH_LAN_PMCS), + ((GigaLanPme & ~B_PCH_LAN_PMCS_PMEE) | B_PCH_LAN_PMCS_PMES) + ); + + // + // Restore Ehci, Ehci2 and xHci Power Control Status register + // + MmioWrite16 ( + MmPciAddress ( + 0, + DEFAULT_PCI_BUS_NUMBER_PCH, + PCI_DEVICE_NUMBER_PCH_USB, + PCI_FUNCTION_NUMBER_PCH_EHCI, + R_PCH_EHCI_PWR_CNTL_STS), + EhciPme + ); + MmioWrite16 ( + MmPciAddress ( + 0, + DEFAULT_PCI_BUS_NUMBER_PCH, + PCI_DEVICE_NUMBER_PCH_USB_EXT, + PCI_FUNCTION_NUMBER_PCH_EHCI2, + R_PCH_EHCI_PWR_CNTL_STS), + Ehci2Pme + ); + MmioWrite16 ( + MmPciAddress ( + 0, + DEFAULT_PCI_BUS_NUMBER_PCH, + PCI_DEVICE_NUMBER_PCH_XHCI, + PCI_FUNCTION_NUMBER_PCH_XHCI, + R_PCH_XHCI_PWR_CNTL_STS), + xHciPme + ); + + // + // XHCI's previous state is D3(this is woken from S3). In the RapidStartEntry, + // when preparing to enter into S4, put XHCI into D3(fix the auto wake-up issue). + // + MmioWrite16 ( + MmPciAddress ( + 0, + DEFAULT_PCI_BUS_NUMBER_PCH, + PCI_DEVICE_NUMBER_PCH_XHCI, + PCI_FUNCTION_NUMBER_PCH_XHCI, + R_PCH_XHCI_PWR_CNTL_STS), + (xHciPme | V_PCH_XHCI_PWR_CNTL_STS_PWR_STS_D3) + ); + + // + // Restore PCIEs Power Control Status register + // + + for (Index = 0; Index <= PCI_FUNCTION_NUMBER_PCH_PCIE_ROOT_PORT_8; Index++) { + MmioWrite16 ( + MmPciAddress ( + 0, + DEFAULT_PCI_BUS_NUMBER_PCH, + PCI_DEVICE_NUMBER_PCH_PCIE_ROOT_PORTS, + (PCI_FUNCTION_NUMBER_PCH_PCIE_ROOT_PORT_1 + Index), + R_PCH_PCIE_PMCS), + PCIePme[Index] + ); + } + + // + // Restore Giga Lan Power Control Status register + // + MmioWrite16 ( + MmPciAddress ( + 0, + DEFAULT_PCI_BUS_NUMBER_PCH, + PCI_DEVICE_NUMBER_PCH_LAN, + PCI_FUNCTION_NUMBER_PCH_LAN, + R_PCH_LAN_PMCS), + GigaLanPme + ); + + DEBUG ((EFI_D_INFO, "RapidStartClearOemPmeEvent End\n")); + + return EFI_SUCCESS; +} + +/** + Provide a hook for OEM to cancel RapidStart Instant-On function. + This function may impact RapidStart Resume performance since it's polled frequently. + + @retval FALSE - Do not cancel RapidStart Instant-On + @retval TRUE - The RapidStart Resume will have no Instant-On function +**/ +BOOLEAN +RapidStartUnattendedWake ( + VOID + ) +{ + + return FALSE; +} +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2013, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** diff --git a/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Pei/RapidStartPeiLib.cif b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Pei/RapidStartPeiLib.cif new file mode 100644 index 0000000..8469e48 --- /dev/null +++ b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Pei/RapidStartPeiLib.cif @@ -0,0 +1,15 @@ +<component> + name = "RapidStartPeiLib" + category = ModulePart + LocalRoot = "Board\EM\RapidStartWrapper\Library\RapidStartPlatformLib\Pei" + RefName = "RapidStartPeiLib" +[files] +"RapidStartPeiLib.sdl" +"RapidStartPeiLib.mak" +"RapidStartPeiLib.c" +"RapidStartPeiLib.h" +"RapidStartPeiLib.inf" +"RapidStartPeiLib.lib" +"PeiCryptLib.lib" +"OpensslLib.lib" +<endComponent> diff --git a/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Pei/RapidStartPeiLib.h b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Pei/RapidStartPeiLib.h new file mode 100644 index 0000000..7eb2422 --- /dev/null +++ b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Pei/RapidStartPeiLib.h @@ -0,0 +1,306 @@ +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2012, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** + +//********************************************************************** +// $Header: /Alaska/SOURCE/Modules/Intel Fast Flash Standby/iRST_SharkBay/RapidStartWrapper/RapidStartPeiLib/RapidStartPeiLib.h 2 12/18/12 12:19a Bensonlai $ +// +// $Revision: 2 $ +// +// $Date: 12/18/12 12:19a $ +//********************************************************************** +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/Intel Fast Flash Standby/iRST_SharkBay/RapidStartWrapper/RapidStartPeiLib/RapidStartPeiLib.h $ +// +// 2 12/18/12 12:19a Bensonlai +// [TAG] EIP109701 +// [Category] Spec Update +// [Severity] Normal +// [Description] Updated to Shark Bay Rapid Start Reference Code +// Version 0.8.1 +// [Files] RapidStartPeiLib.c, RapidStartPeiLib.h +// +// 1 10/15/12 4:41a Bensonlai +// [TAG] EIPNone +// [Category] Improvement +// [Description] [Category] Improvement +// [Severity] Important +// [Description] Rename all IFFS sting to Rapid Start. +// [Files] Board\EM\RapidStartWrapper\*.*, ReferenceCode\RapidStart\*.* +// [Files] RapidStartPeiLib.cif +// RapidStartPeiLib.sdl +// RapidStartPeiLib.mak +// RapidStartPeiLib.c +// RapidStartPeiLib.h +// RapidStartPeiLib.inf +// RapidStartPeiLib.lib +// PeiCryptLib.lib +// OpensslLib.lib +// +//********************************************************************** +//<AMI_FHDR_START> +// +// Name: RapidStartPeiLib.h +// +// Description: Defines and prototypes for the library module. +// +//<AMI_FHDR_END> +//********************************************************************** + +#ifndef _RAPID_START_PEI_LIB_H_ +#define _RAPID_START_PEI_LIB_H_ + +#if !defined(EDK_RELEASE_VERSION) || (EDK_RELEASE_VERSION < 0x00020000) +#include "RapidStartConfig.h" +#include EFI_PPI_DEFINITION (RapidStart) +#endif + +#ifndef RAPID_START_NO_SMRAM_INTEGRITY_CHECK +// +// Secure hash definitions for SMRAM integrity check +// +#include "BaseCryptLib.h" +#define RAPID_START_SECURE_HASH_LENGTH SHA256_DIGEST_SIZE +#define IfsSecureHashGetContextSize() (Sha256GetContextSize ()) +#define RapidStartSecureHashInit(state) (Sha256Init (state)) +#define RapidStartSecureHashUpdate(state, data, len) (Sha256Update ((state), (data), (len))) +#define RapidStartSecureHashFinal(state, output) (Sha256Final ((state), (output))) + +/** + Saves SMRAM Secure Hash to non-volatile secure location. + + Only available when "RAPID_START_NO_SMRAM_INTEGRITY_CHECK" not defined. This + function requires porting to support SMRAM Hash algorithm. + + This function will save SMRAM Hash value into non-volatile memory, platform code + has to provide the available non-volatile memory space and modify this function + to save SMRAM Hash value into that space. Reference code by default uses SHA256 + hashing algorithm in UDK2010 "Crypto library". See section "Porting + Recommendation" for more information. The hash needs to be as strong as the + one used to produce security measurements stored in the TPM, so as to not weaken + the overall security level provided by the platform. + "RAPID_START_SECURE_HASH_LENGTH" is defined as "SHA256_DIGEST_SIZE", + which is defined as 32 in BaseCryptLib.h See "Porting Recommendation" + section in this document for SMRAM Hashing implementation. + + @param[in] Hash[] - hash value + + @retval EFI_SUCCESS - Hash value has been saved successfully + @retval EFI_NOT_FOUND - Hash value not found +**/ +EFI_STATUS +RapidStartSaveSecureHash ( + IN UINT8 Hash[RAPID_START_SECURE_HASH_LENGTH] + ); + +/** + Retrieves and removes SMRAM hash from non-volatile memory + + Only available when "RAPID_START_NO_SMRAM_INTEGRITY_CHECK" not defined. This + function requires porting to support SMRAM Hash algorithm. + + This function will retrieve SMRAM Hash value from non-volatile memory and then + remove it from non-volatile memory. Platform code has to provide the available + non-volatile memory space and modify this function to retrieve SMRAM Hash value + from that space. After hash value retrieved, the hash value has to be scrubbed + from non-volatile memory immediately. Reference code by default uses SHA256 + hashing algorithm in UDK2010 "Crypto library". See section "Porting + Recommendation" for more information. The hash needs to be as strong as the + one used to produce security measurements stored in the TPM, so as to not weaken + the overall security level provided by the platform. + "RAPID_START_SECURE_HASH_LENGTH" is defined as "SHA256_DIGEST_SIZE", + which is defined as 32 in BaseCryptLib.h + + @param[out] Hash[] - hash value + + @retval EFI_SUCCESS - Hash value has been restored and cleared successfully + @retval EFI_NOT_FOUND - Hash value not found +**/ +EFI_STATUS +RapidStartRestoreAndClearSecureHash ( + OUT UINT8 Hash[RAPID_START_SECURE_HASH_LENGTH] + ); + +#endif /* RAPID_START_NO_SMRAM_INTEGRITY_CHECK */ + +/** + Enables ACPI mode after RapidStart resume. + + This function will do the platform specific initialization for switching to ACPI + mode by issuing ACPI_ENABLE SWSMI in the end of Rapid Start Exit transition. OS + will treat Rapid Start Exit as same as regular S3 resume so it will not + re-initialize certain tasks, like ACPI_ENABLE SMI will be skipped by OS, but + those tasks still required for Rapid Start Exit because it could be resume from + S4 or G3 state. This function may need some porting to fit platform design. + + @param[in] PeiServices - Pointer to PEI Services Table. + + @retval EFI_SUCCESS - enabled ACPI mode +**/ +EFI_STATUS +RapidStartEnableAcpi ( + IN EFI_PEI_SERVICES **PeiServices + ); + +/** + This callback is provided to support drive password locking interoperability with RapidStart. + It is called before RapidStart transition is to occur. If SSD partiotion is located on password + locked drive this function must copy the password to the output buffer. + Size of the buffer equals ATA_PASSWORD_LEN. + + Normally the drive password is kept in SMRAM so it can be used to unlock the drive at S3 resume, + thus during RapidStartEntry the password from SMRAM shall be returned. However at RapidStartExit the content + of SMRAM is not yet available so the password has to be preserved in a non-volatile memory + during RapidStartEntry (in RapidStartAfterTransition callback) and retrieved by this function. + + For security reasons the password must be scrubbed from non-volatile memory on RapidStartExit before + returning from this function. On RapidStartEntry the password must not be stored to non-volatile memory + sooner than RapidStartAfterTransition is called (that is after RapidStart non-volatile flag is set). + + @param[in] PeiServices - Pointer to PEI Services Table + @param[in] Transition - RapidStart transition being performed + @param[in] SataPort - locked SATA port + @param[out] Password - output buffer to place the password in + @param[out] FreezeLock - set to TRUE to freeze drive lock, set to FALSE otherwise + + @retval EFI_SUCCESS - Unlock password copied to the buffer + @retval EFI_NOT_FOUND - No password provided (will break the transition) +**/ +EFI_STATUS +RapidStartGetDriveUnlockPassword ( + IN EFI_PEI_SERVICES **PeiServices, + IN RAPID_START_TRANSITION Transition, + IN UINT8 SataPort, + OUT UINT8 *Password, + OUT BOOLEAN *FreezeLock + ); + +/** + This callback is executed before RapidStart transition is performed, but after RapidStart transition conditions has been met. + + This callback is executed before Rapid Start transition is performed, but after + Rapid Start transition conditions have been met. This callback provides + capability to cancel Rapid Start transition if required by platform specific + condition. + + @param[in] PeiServices - Pointer to PEI Services Table + @param[in] Transition - RapidStart transition being performed + @param[in] SataPort - SATA port of RapidStart storage drive + + @retval EFI_SUCCESS - RapidStart transition will follow + @retval EFI_ABORTED - RapidStart transition will not be performed +**/ +EFI_STATUS +RapidStartBeforeTransition ( + IN EFI_PEI_SERVICES **PeiServices, + IN RAPID_START_TRANSITION Transition, + IN UINT8 SataPort + ); + +/** + This callback is executed at the end of RapidStart transition whether succesfull ot not. + + If RapidStart partition is located on password locked drive the drive password must be + copied to non-volatile memory during RapidStartEntry in this function, so it is available + on RapidStartExit (see RapidStartGetDriveUnlockPassword). + + @param[in] PeiServices - Pointer to PEI Services Table + @param[in] Transition - RapidStart transition being performed + @param[in] TransitionStatus - Status of the RapidStart transition + @param[in] SataPort - SATA port of RapidStart storage drive +**/ +VOID +RapidStartAfterTransition ( + IN EFI_PEI_SERVICES **PeiServices, + IN RAPID_START_TRANSITION Transition, + IN EFI_STATUS TransitionStatus, + IN UINT8 SataPort + ); + +/** + Provide a hook for OEM to cancel RapidStart flow. + This function may impact RapidStart Entry performance since it's polled frequently. + + This routine is a callback for platform designer to cancel the Rapid Start Entry + process and do S3 resume back to OS immediately (e.g. Lid opening). Since the + time for Rapid Start Entry might be long and user might want to cancel it for + any urgent scenario. This required condition check for when the Rapid Start + Entry should be canceled. Note: This callback will be polled frequently during + Rapid Start Entry process, so the implementation may impact Rapid Start Entry + performance. + + A callback for platform designer to cancel Rapid Start Entry process when + specific condition happened (e.g. Lid opening). This is optional, required + porting and might impact Rapid Start Entry performance. + + @retval FALSE - Do not cancel RapidStart flow + @retval TRUE - The RapidStart Entry flow should be canceled and do S3 resume back to OS +**/ +BOOLEAN +RapidStartShouldCancelEntry ( + VOID + ); + +/** + This callback is executed to clear all PEM events before Rapid Start enter S4. + + @retval EFI_SUCCESS - Operation successfully performed +**/ +EFI_STATUS +RapidStartClearOemPmeEvent ( + VOID + ); + +// +// Max uCode time out is 100 Milli second +// +#define MAX_UCODE_TIMEOUT 100000 +#define STALL_1_MICROSECONDS 1 + +/** + This function is work around for NetDetect and WakeOnLan when RapidStart enabled. + + @param EFI_SUCCESS - Operation successfully performed +**/ +EFI_STATUS +RapidStartWANetDetect ( + IN EFI_PEI_SERVICES **PeiServices, + IN UINT32 WlanMmioSpace + ); + +/** + Provide a hook for OEM to cancel RapidStart Instant-On function. + This function may impact RapidStart Resume performance since it's polled frequently. + + @retval FALSE - Do not cancel RapidStart Instant-On + @retval TRUE - The RapidStart Resume will have no Instant-On function +**/ +BOOLEAN +RapidStartUnattendedWake ( + VOID + ); +#endif +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2012, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//************************************************************************* diff --git a/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Pei/RapidStartPeiLib.inf b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Pei/RapidStartPeiLib.inf new file mode 100644 index 0000000..1737737 --- /dev/null +++ b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Pei/RapidStartPeiLib.inf @@ -0,0 +1,63 @@ +## @file +# Component description file for the RapidStart Peim library +# +#@copyright +# Copyright (c) 2004 - 2012 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. +# +# This file contains a 'Sample Driver' and is licensed as such +# under the terms of your license agreement with Intel or your +# vendor. This file may be modified by the user, subject to +# the additional terms of the license agreement +# + +[defines] +BASE_NAME = RapidStartPeiLib +COMPONENT_TYPE = LIBRARY + +[sources.common] + RapidStartPeiLib.h + RapidStartPeiLib.c + +[includes.common] + . + $(EDK_SOURCE)/Foundation/Library/Pei/Include + $(EDK_SOURCE)/Foundation/Efi + $(EDK_SOURCE)/Foundation/Include + $(EDK_SOURCE)/Foundation/Efi/Include + $(EDK_SOURCE)/Foundation/Framework/Include + $(EFI_SOURCE)/$(PROJECT_PCH_ROOT)/Include/Library + $(EFI_SOURCE)/$(PROJECT_PCH_ROOT)/Include + $(EFI_SOURCE)/$(PROJECT_PCH_ROOT) + $(EFI_SOURCE)/$(PROJECT_RAPID_START_ROOT)/Samplecode/Library/RapidStartCommonLib + $(EFI_SOURCE)/$(PROJECT_RAPID_START_ROOT) + $(EFI_SOURCE)/$(PROJECT_RAPID_START_ROOT)/Include + $(EFI_SOURCE)/$(PROJECT_ME_ROOT) + $(EFI_SOURCE)/$(PROJECT_ME_ROOT)/Library/MeKernel/Include + $(EFI_SOURCE)/$(PROJECT_SA_ROOT)/Include + +# +# EDK II Glue Library utilizes some standard headers from EDK +# + $(EFI_SOURCE) + $(EDK_SOURCE)/Foundation + $(EDK_SOURCE)/Foundation/Framework + $(EDK_SOURCE)/Foundation/Include/IndustryStandard + $(EDK_SOURCE)/Foundation/Core/Dxe + $(EDK_SOURCE)/Foundation/Include/Pei + $(EDK_SOURCE)/Foundation/Library/Dxe/Include + $(EDK_SOURCE)/Foundation/Library/EdkIIGlueLib/Include + $(EFI_SOURCE)/Include + +[libraries.common] + PchPlatformLib + +[nmake.common] +C_STD_INCLUDE= + diff --git a/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Pei/RapidStartPeiLib.lib b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Pei/RapidStartPeiLib.lib Binary files differnew file mode 100644 index 0000000..e308456 --- /dev/null +++ b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Pei/RapidStartPeiLib.lib diff --git a/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Pei/RapidStartPeiLib.mak b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Pei/RapidStartPeiLib.mak new file mode 100644 index 0000000..ef8eef4 --- /dev/null +++ b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Pei/RapidStartPeiLib.mak @@ -0,0 +1,80 @@ +#********************************************************************** +#********************************************************************** +#** ** +#** (C)Copyright 1985-2012, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#********************************************************************** +#********************************************************************** + +#********************************************************************** +# $Header: /Alaska/SOURCE/Modules/Intel Fast Flash Standby/iRST_SharkBay/RapidStartWrapper/RapidStartPeiLib/RapidStartPeiLib.mak 1 10/15/12 4:41a Bensonlai $ +# +# $Revision: 1 $ +# +# $Date: 10/15/12 4:41a $ +#********************************************************************** +# Revision History +# ---------------- +# $Log: /Alaska/SOURCE/Modules/Intel Fast Flash Standby/iRST_SharkBay/RapidStartWrapper/RapidStartPeiLib/RapidStartPeiLib.mak $ +# +# 1 10/15/12 4:41a Bensonlai +# [TAG] EIPNone +# [Category] Improvement +# [Description] [Category] Improvement +# [Severity] Important +# [Description] Rename all IFFS sting to Rapid Start. +# [Files] Board\EM\RapidStartWrapper\*.*, ReferenceCode\RapidStart\*.* +# [Files] RapidStartPeiLib.cif +# RapidStartPeiLib.sdl +# RapidStartPeiLib.mak +# RapidStartPeiLib.c +# RapidStartPeiLib.h +# RapidStartPeiLib.inf +# RapidStartPeiLib.lib +# PeiCryptLib.lib +# OpensslLib.lib +# +#********************************************************************** +#<AMI_FHDR_START> +# +# Name: RapidStartPeiLib.mak +# +# Description: Component description file for the RapidStart Peim library +# +#<AMI_FHDR_END> +#********************************************************************** + +all : RapidStartPeiLib + +$(RapidStartPeiLib_LIB) : RapidStartPeiLib + +RapidStartPeiLib : $(BUILD_DIR)\RapidStartPeiLib.mak RapidStartPeiLibBin + +$(BUILD_DIR)\RapidStartPeiLib.mak : $(RapidStartPeiLib_DIR)\$(@B).cif $(RapidStartPeiLib_DIR)\$(@B).mak $(BUILD_RULES) + $(CIF2MAK) $(RapidStartPeiLib_DIR)\$(@B).cif $(CIF2MAK_DEFAULTS) + +RapidStartPeiLibBin : + $(MAKE) /$(MAKEFLAGS) $(EDKIIGLUE_DEFAULTS)\ + /f $(BUILD_DIR)\RapidStartPeiLib.mak all\ + "MY_INCLUDES=$(EDK_INCLUDES) $(EdkIIGlueLib_INCLUDES) $(NB_INCLUDES) $(INTEL_MCH_INCLUDES) $(INTEL_PCH_INCLUDES) $(RAPIDSTART_INCLUDES)" \ + TYPE=PEI_LIBRARY \ + LIBRARY_NAME=$(RapidStartPeiLib_LIB) +#************************************************************************* +#************************************************************************* +#** ** +#** (C)Copyright 1985-2012, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#************************************************************************* +#************************************************************************* diff --git a/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Pei/RapidStartPeiLib.sdl b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Pei/RapidStartPeiLib.sdl new file mode 100644 index 0000000..7ea853b --- /dev/null +++ b/Board/EM/RapidStartWrapper/Library/RapidStartPlatformLib/Pei/RapidStartPeiLib.sdl @@ -0,0 +1,101 @@ +#********************************************************************** +#********************************************************************** +#** ** +#** (C)Copyright 1985-2012, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#********************************************************************** +#********************************************************************** + +#********************************************************************** +# $Header: /Alaska/SOURCE/Modules/Intel Fast Flash Standby/iRST_SharkBay/RapidStartWrapper/RapidStartPeiLib/RapidStartPeiLib.sdl 1 10/15/12 4:41a Bensonlai $ +# +# $Revision: 1 $ +# +# $Date: 10/15/12 4:41a $ +#********************************************************************** +# Revision History +# ---------------- +# $Log: /Alaska/SOURCE/Modules/Intel Fast Flash Standby/iRST_SharkBay/RapidStartWrapper/RapidStartPeiLib/RapidStartPeiLib.sdl $ +# +# 1 10/15/12 4:41a Bensonlai +# [TAG] EIPNone +# [Category] Improvement +# [Description] [Category] Improvement +# [Severity] Important +# [Description] Rename all IFFS sting to Rapid Start. +# [Files] Board\EM\RapidStartWrapper\*.*, ReferenceCode\RapidStart\*.* +# [Files] RapidStartPeiLib.cif +# RapidStartPeiLib.sdl +# RapidStartPeiLib.mak +# RapidStartPeiLib.c +# RapidStartPeiLib.h +# RapidStartPeiLib.inf +# RapidStartPeiLib.lib +# PeiCryptLib.lib +# OpensslLib.lib +# +#********************************************************************** +#<AMI_FHDR_START> +# +# Name: RapidStartPeiLib.sdl +# +# Description: SDL file for the RapidStart Peim library +# +#<AMI_FHDR_END> +#********************************************************************** + +TOKEN + Name = "RapidStartPeiLib_SUPPORT" + Value = "1" + Help = "Main switch to enable RapidStartPeiLib support in Project" + TokenType = Boolean + TargetEQU = Yes + TargetMAK = Yes + Master = Yes +End + +PATH + Name = "RapidStartPeiLib_DIR" +End + +MODULE + Help = "Includes RapidStartPeiLib.mak to Project" + File = "RapidStartPeiLib.mak" +End + +ELINK + Name = "RapidStartPeiLib_LIB" + InvokeOrder = ReplaceParent +End + +ELINK + Name = "$(BUILD_DIR)\RapidStartPeiLib.lib" + Parent = "RapidStartPeiLib_LIB" + InvokeOrder = AfterParent +End + +ELINK + Name = "/I$(RapidStartPeiLib_DIR)" + Parent = "RAPIDSTART_INCLUDES" + InvokeOrder = AfterParent +End + +#************************************************************************* +#************************************************************************* +#** ** +#** (C)Copyright 1985-2012, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#************************************************************************* +#************************************************************************* |