summaryrefslogtreecommitdiff
path: root/Core/EM/OemActivation
diff options
context:
space:
mode:
authorraywu <raywu0301@gmail.com>2018-06-15 00:00:50 +0800
committerraywu <raywu0301@gmail.com>2018-06-15 00:00:50 +0800
commitb7c51c9cf4864df6aabb99a1ae843becd577237c (patch)
treeeebe9b0d0ca03062955223097e57da84dd618b9a /Core/EM/OemActivation
downloadzprj-b7c51c9cf4864df6aabb99a1ae843becd577237c.tar.xz
init. 1AQQW051HEADmaster
Diffstat (limited to 'Core/EM/OemActivation')
-rw-r--r--Core/EM/OemActivation/OemActivation.c505
-rw-r--r--Core/EM/OemActivation/OemActivation.chmbin0 -> 55618 bytes
-rw-r--r--Core/EM/OemActivation/OemActivation.cif16
-rw-r--r--Core/EM/OemActivation/OemActivation.dxs93
-rw-r--r--Core/EM/OemActivation/OemActivation.h194
-rw-r--r--Core/EM/OemActivation/OemActivation.mak159
-rw-r--r--Core/EM/OemActivation/OemActivation.sdl79
-rw-r--r--Core/EM/OemActivation/OemActivationHook.c116
-rw-r--r--Core/EM/OemActivation/SmmOemActivation.c491
-rw-r--r--Core/EM/OemActivation/SmmOemActivation.cif11
-rw-r--r--Core/EM/OemActivation/SmmOemActivation.dxs83
-rw-r--r--Core/EM/OemActivation/SmmOemActivation.mak75
-rw-r--r--Core/EM/OemActivation/SmmOemActivation.sdl32
13 files changed, 1854 insertions, 0 deletions
diff --git a/Core/EM/OemActivation/OemActivation.c b/Core/EM/OemActivation/OemActivation.c
new file mode 100644
index 0000000..efc55f6
--- /dev/null
+++ b/Core/EM/OemActivation/OemActivation.c
@@ -0,0 +1,505 @@
+//****************************************************************************
+//****************************************************************************
+//** **
+//** (C)Copyright 1985-2012, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone (770)-246-8600 **
+//** **
+//****************************************************************************
+//****************************************************************************
+
+//*****************************************************************************
+// $Header: /Alaska/SOURCE/Modules/OemActivation/OemActivation.c 19 5/22/12 4:27p Vyacheslava $
+//
+// $Revision: 19 $
+//
+// $Date: 5/22/12 4:27p $
+//*****************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/OemActivation/OemActivation.c $
+//
+// 19 5/22/12 4:27p Vyacheslava
+// [TAG] EIP90324
+// [Description] The OA3MSDMvariable variable has improper GUID.
+//
+// 18 2/23/12 12:19p Vyacheslava
+// Fixed build error for 32 bit mode.
+//
+// 17 1/12/12 9:20a Vyacheslava
+// [TAG] EIP80094
+// [Category] Bug Fix
+// [Severity] Critical
+// [Symptom] There are duplicated MSDM published in the ACPI in PI 1.2
+//
+// 16 10/28/11 5:37p Vyacheslava
+// [TAG] EIP64110
+// [Category] Improvement
+//
+// 15 9/26/11 11:19a Vyacheslava
+// [TAG] EIP64110
+// [Category] Spec Update
+// [Severity] Normal
+// [Description] changed protocol SmmCpuState to SmmCpuProtocol
+//
+// 14 9/23/11 3:16p Vyacheslava
+// [TAG] EIP64110
+// [Category] Spec Update
+// [Severity] Normal
+// [Description] Changed according to Aptio 4.6.5.x Components Porting
+// Guide (Conversion of the SMM Drivers).
+//
+// 13 8/08/11 10:15a Vyacheslava
+//
+// 12 8/03/11 2:24p Vyacheslava
+// [TAG] EIP64110
+// [Category] Spec Update
+// [Severity] Normal
+// [Description] Updated to be compliant with PI 1.2, and UEFI 2.3.1
+// specifications.
+//
+// 11 7/07/11 11:12a Vyacheslava
+// [TAG] EIP62009
+// [Category] Bug Fix
+// [Severity] Critical
+// [Symptom] if OEM_ACTIVATION_TABLE_LOCATION is not zero, the code does
+// not compile.
+//
+// 10 6/16/11 10:55a Vyacheslava
+// [TAG] EIP62009
+// [Category] New Feature
+// [Description] Preserve the OA30 key during the BIOS recovery path.
+//
+// 9 6/10/11 11:00a Vyacheslava
+//
+// 8 5/24/11 3:53p Vyacheslava
+// [TAG] EIP59717
+// [Category] New Feature
+// [Description] Changed SW SMI protocol according to request from the
+// Utility.
+//
+// 7 5/20/11 12:34p Vyacheslava
+// [TAG] EIP59717
+// [Category] New Feature
+// [Description] Added code that updates ACPI table in OS Runtime.
+//
+// 6 5/18/11 11:21a Vyacheslava
+// [TAG] EIP59717
+// [Category] New Feature
+// [Description] Implementation according comment#8 in the EIP#59717.
+//
+// 5 4/29/11 12:44p Vyacheslava
+// [TAG] EIP58139
+// [Category] New Feature
+// [Description] Added code to place Oem Activation Key in NCB.
+//
+// 4 12/17/10 1:46p Vyacheslava
+// [TAG] EIP48520
+// [Category] Improvement
+// [Description] - Deleted temporary structure for testing FID;
+// - Simplified MSDM structure;
+//
+// 3 12/16/10 5:02p Vyacheslava
+// - Added checking for FID version;
+// - Fixed bug with structure overflow;
+//
+// 2 11/19/10 4:18p Vyacheslava
+// [TAG] EIP48520
+// [Category] Improvement
+// [Description] - $FID structure should not be redefined but updated
+// where it belong: FwVersion.h in CSPLIB component
+// - the 49 bytes of $FID should be intialized with 0xff
+// - the loading of the MSDM from $FID should be done based on the length
+// of the MSDM field as specified in the $FID structure and not hardcoded
+// to 49 bytes
+// - checksum field should be initilized to 0x0 not 0x88 (which is the
+// checksum value of the example of the Microsoft spec)
+//
+// 1 11/18/10 1:15p Vyacheslava
+// Initial creation
+//
+//
+//*****************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: OemActivation.c
+//
+// Description: Microsoft OEM Activation 3.0
+//
+//<AMI_FHDR_END>
+//*****************************************************************************
+
+
+#include <AmiDxeLib.h>
+#include <Protocol/AcpiTable.h>
+#include <PPI/FwVersion.h>
+#include <AmiHobs.h>
+#include "OemActivation.h"
+
+
+
+//<AMI_PHDR_START>
+//----------------------------------------------------------------------------
+//
+// Procedure: LocateSectionResource
+//
+// Description: This function locate resource binary by GUID.
+//
+// Input:
+// pResourceGuid - pointer to recourse GUID
+// pResourceSectionGuid - pointer to recourse section GUID
+// Address - pointer to returning address of the resource
+//
+// Output: EFI_STATUS
+//
+//----------------------------------------------------------------------------
+//<AMI_PHDR_END>
+
+EFI_STATUS LocateSectionResource(
+ IN EFI_GUID *pResourceGuid,
+ IN EFI_GUID *pResourceSectionGuid,
+ OUT UINT8 **Address )
+{
+ EFI_STATUS Status;
+ EFI_HANDLE *HandleBuffer = NULL;
+ UINTN NumberOfHandles;
+ UINTN Index;
+ UINT32 Authentication;
+ UINTN i;
+ EFI_GUID *pGuid = NULL;
+ UINTN SectionSize;
+
+#if PI_SPECIFICATION_VERSION<0x0001000A
+ EFI_GUID EfiFirmwareVolumeProtocolGuid = EFI_FIRMWARE_VOLUME_PROTOCOL_GUID;
+ EFI_FIRMWARE_VOLUME_PROTOCOL *FwVolumeProtocol = NULL;
+#else
+ EFI_GUID EfiFirmwareVolumeProtocolGuid = EFI_FIRMWARE_VOLUME2_PROTOCOL_GUID;
+ EFI_FIRMWARE_VOLUME2_PROTOCOL *FwVolumeProtocol = NULL;
+#endif
+
+ // Locate the Firmware volume protocol
+ Status = pBS->LocateHandleBuffer(
+ ByProtocol,
+ &EfiFirmwareVolumeProtocolGuid,
+ NULL,
+ &NumberOfHandles,
+ &HandleBuffer
+ );
+ if (EFI_ERROR(Status))
+ return EFI_NOT_FOUND;
+
+ // Find and read raw data
+ for (Index = 0; Index < NumberOfHandles; Index++) {
+
+ Status = pBS->HandleProtocol(
+ HandleBuffer[Index],
+ &EfiFirmwareVolumeProtocolGuid,
+ &FwVolumeProtocol
+ );
+ if (EFI_ERROR(Status))
+ continue;
+
+ i = 0;
+ while(1) {
+ SectionSize = 0;
+ Status = FwVolumeProtocol->ReadSection(
+ FwVolumeProtocol,
+ pResourceGuid,
+ EFI_SECTION_FREEFORM_SUBTYPE_GUID,
+ i++,
+ &pGuid,
+ &SectionSize,
+ &Authentication
+ );
+ if (EFI_ERROR(Status))
+ break;
+ else if ( !guidcmp(pGuid, pResourceSectionGuid ) ) {
+ *Address = (UINT8*)pGuid;
+ goto LocateSectionResource_exit;
+ }
+ pBS->FreePool(pGuid);
+ pGuid = NULL;
+ }
+ }
+
+LocateSectionResource_exit:
+ pBS->FreePool(HandleBuffer);
+ return Status;
+}
+
+
+//<AMI_PHDR_START>
+//----------------------------------------------------------------------------
+//
+// Procedure: GetProductKey
+//
+// Description: This function locates the Product Key.
+//
+// Input: Address - pointer to returning address of the Product Key structure.
+//
+// Output: EFI_STATUS
+//
+//----------------------------------------------------------------------------
+//<AMI_PHDR_END>
+
+EFI_STATUS GetProductKey(
+ IN EFI_PHYSICAL_ADDRESS StartAddr,
+ IN EFI_PHYSICAL_ADDRESS EndAddr,
+ OUT UINT8 **Address )
+{
+ EFI_STATUS Status = EFI_NOT_FOUND;
+ EFI_GUID FidTableSectionGuid = FID_TABLE_SECTION_GUID;
+ EFI_PHYSICAL_ADDRESS i;
+
+ for ( i = StartAddr; i < EndAddr; i++ )
+ if ( !MemCmp((UINT8*)i, &FidTableSectionGuid, sizeof(EFI_GUID)) ) {
+
+ // skip the GUID
+ i += sizeof(EFI_GUID);
+
+ // Check version of the FID table
+ if ( ((FW_VERSION*)i)->StructVersion < FID_SUPPORTED_VERSION ) {
+ TRACE((TRACE_ALWAYS, "OEM Activation: FID table version %d unsupported!!!\n",((FW_VERSION*)i)->StructVersion));
+ Status = EFI_UNSUPPORTED;
+ break;
+ }
+
+ // skip the ACPI header
+ *Address = (UINT8*)((FW_VERSION*)i)->OemActivationKey;
+ TRACE((TRACE_ALWAYS, "OEM Activation: Product Key Address %X\n",*Address));
+
+ Status = EFI_SUCCESS;
+ break;
+ }
+ return Status;
+}
+
+
+//<AMI_PHDR_START>
+//----------------------------------------------------------------------------
+//
+// Procedure: PreserveProductKey
+//
+// Description: This function preserves the Product Key.
+//
+// Input: VOID
+//
+// Output: EFI_STATUS
+//
+//----------------------------------------------------------------------------
+//<AMI_PHDR_END>
+
+EFI_STATUS PreserveProductKey(VOID)
+{
+ EFI_STATUS Status = EFI_NOT_FOUND;
+ RECOVERY_IMAGE_HOB *RecoveryHob;
+ EFI_GUID HobListGuid = HOB_LIST_GUID;
+ EFI_GUID RecoveryHobGuid = AMI_RECOVERY_IMAGE_HOB_GUID;
+ EFI_CONFIGURATION_TABLE *Table = pST->ConfigurationTable;
+ UINTN i;
+ UINT8 *ProductKey;
+ UINT8 *ProductKeyPreserve;
+
+ // Find the Product Key place in the recovery HOB
+ for( i = 0; i < pST->NumberOfTableEntries; i++, Table++ ) {
+
+ if ( !MemCmp(&Table->VendorGuid, &HobListGuid, sizeof(EFI_GUID)) ) {
+
+ RecoveryHob = Table->VendorTable;
+ Status = FindNextHobByGuid(&RecoveryHobGuid, &RecoveryHob);
+ if (!EFI_ERROR(Status)) {
+
+#if OEM_ACTIVATION_TABLE_LOCATION == 0
+ // Get the Product Key pointer in the recovery HOB
+ Status = GetProductKey(
+ RecoveryHob->Address + FLASH_SIZE - FV_BB_SIZE,
+ RecoveryHob->Address + FLASH_SIZE - sizeof(EFI_GUID),
+ &ProductKeyPreserve
+ );
+ if (!EFI_ERROR(Status)) {
+ // Get the Product Key pointer in the Flash memory
+ Status = GetProductKey(FV_BB_BASE, FV_BB_END_ADDR, &ProductKey);
+ if (EFI_ERROR(Status))
+ break;
+ MemCpy( ProductKeyPreserve, ProductKey, sizeof(EFI_ACPI_MSDM_TABLE) - sizeof(ACPI_HDR) );
+ }
+#else
+ ProductKeyPreserve = (UINT8*)(RecoveryHob->Address + FLASH_SIZE - OEM_ACTIVATION_TABLE_OFFSET);
+ ProductKey = (UINT8*)OEM_ACTIVATION_TABLE_ADDRESS;
+ MemCpy( ProductKeyPreserve, ProductKey, sizeof(EFI_ACPI_MSDM_TABLE) - sizeof(ACPI_HDR) );
+ Status = EFI_SUCCESS;
+#endif
+ }
+ }
+ }
+ TRACE((TRACE_ALWAYS,"PreserveProductKey: Status %r\n",Status));
+ return Status;
+}
+
+
+//<AMI_PHDR_START>
+//----------------------------------------------------------------------------
+//
+// Procedure: OemActivation_EntryPoint
+//
+// Description: This function is the entry point of the eModule.
+//
+// Input:
+// ImageHandle - Image handle
+// *SystemTable - Pointer to the system table
+//
+// Output: EFI_STATUS
+//
+//----------------------------------------------------------------------------
+//<AMI_PHDR_END>
+
+EFI_STATUS EFIAPI OemActivation_EntryPoint(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable )
+{
+ EFI_STATUS Status;
+ EFI_GUID FidTableGuid = FID_TABLE_GUID;
+ EFI_GUID FidTableSectionGuid = FID_TABLE_SECTION_GUID;
+ FW_VERSION *Fid;
+ UINT8 *FidSection = NULL;
+ EFI_ACPI_MSDM_TABLE *Msdm = NULL;
+ EFI_OA3_MSDM_STRUCTURE MsdmVariable = {0};
+ EFI_GUID AmiGlobalVariableGuid = AMI_GLOBAL_VARIABLE_GUID;
+ UINTN i;
+
+ InitAmiLib(ImageHandle, SystemTable);
+
+ // Check if it's a Recovery Mode then preserve the Product Key
+ if (GetBootMode() == BOOT_IN_RECOVERY_MODE) {
+ Status = PreserveProductKey();
+ return Status;
+ }
+
+ // Locate the $FID table
+ Status = LocateSectionResource(
+ &FidTableGuid,
+ &FidTableSectionGuid,
+ &FidSection
+ );
+ if (EFI_ERROR(Status)) {
+ TRACE((TRACE_ALWAYS, "OEM Activation: FID table Not Found!!!\n"));
+ return Status;
+ }
+ Fid = (FW_VERSION*)(FidSection + sizeof(EFI_GUID)); // skip the GUID
+
+#if OEM_ACTIVATION_TABLE_LOCATION == 0
+ // Check version of the FID table
+ if ( Fid->StructVersion < FID_SUPPORTED_VERSION ) {
+ TRACE((TRACE_ALWAYS, "OEM Activation: FID table version %d is unsupported!!!\n",Fid->StructVersion));
+ return EFI_UNSUPPORTED;
+ }
+#endif
+
+ // Create MSDM table
+ Status = pBS->AllocatePool( EfiACPIMemoryNVS, sizeof(EFI_ACPI_MSDM_TABLE), &Msdm );
+ if (EFI_ERROR(Status))
+ return Status;
+ Msdm->Header.Signature = MSDM_SIG;
+ Msdm->Header.Length = sizeof(EFI_ACPI_MSDM_TABLE);
+ Msdm->Header.Revision = MSDM_REVISION;
+ Msdm->Header.OemRev = ACPI_OEM_REV;
+ Msdm->Header.CreatorId = CREATOR_ID_AMI;
+ Msdm->Header.CreatorRev = CREATOR_REV_MS;
+
+ // Copy OEM ID and OEM Table ID
+ MemCpy(
+ (UINT8*)&Msdm->Header.OemId,
+ (UINT8*)&Fid->OemId,
+ sizeof(Fid->OemId)
+ );
+ MemCpy(
+ (UINT8*)&Msdm->Header.OemTblId,
+ (UINT8*)&Fid->OemTableId,
+ sizeof(Fid->OemTableId)
+ );
+
+ // Copy OEM Activation Key
+ MemCpy(
+ (UINT8*)&Msdm->Version,
+#if OEM_ACTIVATION_TABLE_LOCATION == 0
+ (UINT8*)&Fid->OemActivationKey, // Copy Key from the FID structure
+#else
+ (UINT8*)OEM_ACTIVATION_TABLE_ADDRESS, // Copy Key from the NCB
+#endif
+ sizeof(EFI_ACPI_MSDM_TABLE) - sizeof(ACPI_HDR)
+ );
+ pBS->FreePool(FidSection);
+
+ // Check if there is empty Product Key
+ for ( i = 0; i < sizeof(Msdm->Data); i++ ) {
+
+ if ( Msdm->Data[i] != 0xFF ) {
+
+ EFI_ACPI_TABLE_PROTOCOL *AcpiTableProtocol = NULL;
+ UINTN TableKey = 0;
+
+ // Locate the ACPI support protocol
+ Status = pBS->LocateProtocol(
+ &gEfiAcpiTableProtocolGuid,
+ NULL,
+ &AcpiTableProtocol
+ );
+ if (EFI_ERROR(Status))
+ TRACE((TRACE_ALWAYS, "OEM Activation: Unable to locate AcpiSupportProtocol!\n"));
+
+ else {
+ // Publish MSDM ACPI table
+ Status = AcpiTableProtocol->InstallAcpiTable(
+ AcpiTableProtocol,
+ Msdm,
+ sizeof(EFI_ACPI_MSDM_TABLE),
+ &TableKey
+ );
+ if (EFI_ERROR(Status))
+ TRACE((TRACE_ALWAYS, "OEM Activation: SetAcpiTable failed!\n"));
+ else
+ TRACE((TRACE_ALWAYS, "OEM Activation: MSDM table has been published.\n"));
+ }
+ pBS->FreePool(Msdm);
+ return Status;
+ }
+ }
+
+ TRACE((TRACE_ALWAYS, "OEM Activation: Found empty Product Key.\n"));
+
+ MsdmVariable.MsdmAddress = (EFI_PHYSICAL_ADDRESS)Msdm;
+#if OEM_ACTIVATION_TABLE_LOCATION == 1
+ MsdmVariable.ProductKeyAddress = (EFI_PHYSICAL_ADDRESS)OEM_ACTIVATION_TABLE_ADDRESS;
+#endif
+
+ Status = pRS->SetVariable(
+ EFI_OA3_MSDM_VARIABLE,
+ &AmiGlobalVariableGuid,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
+ sizeof(EFI_OA3_MSDM_STRUCTURE),
+ &MsdmVariable
+ );
+ ASSERT_EFI_ERROR(Status);
+ TRACE((TRACE_ALWAYS, "OEM Activation: MsdmAddress=%X\n",MsdmVariable.MsdmAddress));
+
+ return Status;
+}
+
+
+//****************************************************************************
+//****************************************************************************
+//** **
+//** (C)Copyright 1985-2012, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone (770)-246-8600 **
+//** **
+//****************************************************************************
+//****************************************************************************
diff --git a/Core/EM/OemActivation/OemActivation.chm b/Core/EM/OemActivation/OemActivation.chm
new file mode 100644
index 0000000..b19ecde
--- /dev/null
+++ b/Core/EM/OemActivation/OemActivation.chm
Binary files differ
diff --git a/Core/EM/OemActivation/OemActivation.cif b/Core/EM/OemActivation/OemActivation.cif
new file mode 100644
index 0000000..bdf742e
--- /dev/null
+++ b/Core/EM/OemActivation/OemActivation.cif
@@ -0,0 +1,16 @@
+<component>
+ name = "OemActivation"
+ category = eModule
+ LocalRoot = "Core\EM\OemActivation\"
+ RefName = "OemActivation"
+[files]
+"OemActivation.mak"
+"OemActivation.sdl"
+"OemActivation.c"
+"OemActivation.h"
+"OemActivation.dxs"
+"OemActivation.chm"
+"OemActivationHook.c"
+[parts]
+"SmmOemActivation"
+<endComponent>
diff --git a/Core/EM/OemActivation/OemActivation.dxs b/Core/EM/OemActivation/OemActivation.dxs
new file mode 100644
index 0000000..ccd2490
--- /dev/null
+++ b/Core/EM/OemActivation/OemActivation.dxs
@@ -0,0 +1,93 @@
+//****************************************************************************
+//****************************************************************************
+//** **
+//** (C)Copyright 1985-2011, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone (770)-246-8600 **
+//** **
+//****************************************************************************
+//****************************************************************************
+
+//*****************************************************************************
+// $Header: /Alaska/SOURCE/Modules/OemActivation/OemActivation.dxs 6 1/12/12 9:21a Vyacheslava $
+//
+// $Revision: 6 $
+//
+// $Date: 1/12/12 9:21a $
+//*****************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/OemActivation/OemActivation.dxs $
+//
+// 6 1/12/12 9:21a Vyacheslava
+// Removed dependency on SMM protocols.
+//
+// 5 10/03/11 11:04a Vyacheslava
+// [TAG] EIP64110
+// [Category] Spec Update
+// [Severity] Normal
+// [Description] (7) IsRoceveryOverSerial, NetBootHotkey, OpromTxT,
+// SimpleBootFlag, SLP10, SlpSupport, SmiVariable
+//
+// 4 9/22/11 11:13a Vyacheslava
+// [TAG] EIP64110
+// [Category] Spec Update
+// [Severity] Normal
+// [Description] Changed according to Aptio 4.6.5.x Components Porting
+// Guide (Conversion of the SMM Drivers).
+//
+// 3 8/08/11 10:14a Vyacheslava
+// [TAG] EIP64110
+// [Category] Spec Update
+// [Severity] Normal
+// [Description] Updated to be compliant with PI 1.2, and UEFI 2.3.1
+// specifications.
+//
+// 2 5/20/11 12:35p Vyacheslava
+// [TAG] EIP59717
+// [Category] New Feature
+// [Description] Added SMM dependency.
+//
+// 1 11/22/10 10:10a Vyacheslava
+//
+//
+//
+//*****************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: OemActivation.dxs
+//
+// Description: This file is the dependency file for OemActivation eModule.
+//
+//<AMI_FHDR_END>
+//*****************************************************************************
+
+//---------------------------------------------------------------------------
+// Header files for GUID definitions
+//---------------------------------------------------------------------------
+
+
+#include <Protocol/AcpiTable.h>
+
+DEPENDENCY_START
+ EFI_ACPI_TABLE_PROTOCOL_GUID
+DEPENDENCY_END
+
+
+//****************************************************************************
+//****************************************************************************
+//** **
+//** (C)Copyright 1985-2011, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone (770)-246-8600 **
+//** **
+//****************************************************************************
+//****************************************************************************
diff --git a/Core/EM/OemActivation/OemActivation.h b/Core/EM/OemActivation/OemActivation.h
new file mode 100644
index 0000000..a325b5b
--- /dev/null
+++ b/Core/EM/OemActivation/OemActivation.h
@@ -0,0 +1,194 @@
+//****************************************************************************
+//****************************************************************************
+//** **
+//** (C)Copyright 1985-2011, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone (770)-246-8600 **
+//** **
+//****************************************************************************
+//****************************************************************************
+
+//*****************************************************************************
+// $Header: /Alaska/SOURCE/Modules/OemActivation/OemActivation.h 13 5/22/12 4:28p Vyacheslava $
+//
+// $Revision: 13 $
+//
+// $Date: 5/22/12 4:28p $
+//*****************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/OemActivation/OemActivation.h $
+//
+// 13 5/22/12 4:28p Vyacheslava
+// Added AMI_GLOBAL_VARIABLE_GUID definition.
+//
+// 12 1/12/12 9:22a Vyacheslava
+// The SW_SMI_OA3_FUNCTION_NUMBER token removed to SDL file.
+//
+// 11 9/29/11 4:18p Vyacheslava
+// [TAG] EIP70134
+// [Description] Changed definition of the SW_SMI_OA3_FUNCTION_NUMBER to
+// 0xDF.
+//
+// 10 8/08/11 10:14a Vyacheslava
+//
+// 9 6/16/11 10:56a Vyacheslava
+// [TAG] EIP62009
+// [Category] New Feature
+// [Description] Preserve the OA30 key during the BIOS recovery path.
+//
+// 8 6/10/11 10:57a Vyacheslava
+//
+// 7 5/26/11 11:10a Vyacheslava
+//
+// 6 5/20/11 12:35p Vyacheslava
+// [TAG] EIP59717
+// [Category] New Feature
+// [Description] added structure for updating ACPI.
+//
+// 5 5/18/11 11:34a Vyacheslava
+// [TAG] EIP59717
+// [Category] New Feature
+// [Description] Implementation according comment#8 in the EIP#59717.
+//
+// 4 12/17/10 1:45p Vyacheslava
+// [TAG] EIP48520
+// [Category] Improvement
+// [Description] - Deleted temporary structure for testing FID;
+// - Simplified MSDM structure;
+//
+// 3 12/16/10 5:03p Vyacheslava
+// Added definition for FID table version
+//
+// 2 11/19/10 4:19p Vyacheslava
+// [TAG] EIP48520
+// [Category] Improvement
+// [Description] EIP#48520 comment#2
+//
+// 1 11/18/10 1:15p Vyacheslava
+// Initial creation
+//
+//
+//*****************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: OemActivation.h
+//
+// Description: Header file for OEM Activation eModule.
+//
+//<AMI_FHDR_END>
+//*****************************************************************************
+
+#ifndef __MS_OEM_ACTIVATION_H
+#define __MS_OEM_ACTIVATION_H
+
+//----------------------------------------------------------------------------
+
+#include <EFI.h>
+#include <ACPI.h>
+
+//----------------------------------------------------------------------------
+
+#define MSDM_SIG 0x4D44534D // "MSDM" - M$ Digital Marker
+#define MSDM_REVISION 0x03 //
+#define MSDM_VERSION 0x01 //
+#define MSDM_DATA_TYPE 0x01 //
+#define FID_SUPPORTED_VERSION 0x04 // Supported version of the FID table
+
+#define FID_TABLE_GUID \
+ { 0x3fd1d3a2, 0x99f7, 0x420b, 0xbc, 0x69, 0x8b, 0xb1, 0xd4, 0x92, 0xa3, 0x32 }
+
+#define FID_TABLE_SECTION_GUID \
+ { 0x2ebe0275, 0x6458, 0x4af9, 0x91, 0xed, 0xd3, 0xf4, 0xed, 0xb1, 0x00, 0xaa }
+
+// This GUID should be defined in the next Core label (4.6.5.4 or greater)
+#ifndef AMI_GLOBAL_VARIABLE_GUID
+#define AMI_GLOBAL_VARIABLE_GUID \
+ {0x1368881,0xc4ad,0x4b1d,0xb6,0x31,0xd5,0x7a,0x8e,0xc8,0xdb,0x6b}
+#endif
+
+#define EFI_OA3_MSDM_VARIABLE L"OA3MSDMvariable"
+
+// if Product Key located in the NBC
+#if OEM_ACTIVATION_TABLE_LOCATION == 1
+#define FLASH_DEVICE_BASE_ADDRESS (0xFFFFFFFF-FLASH_SIZE+1)
+#define OEM_ACTIVATION_BLOCK_ADDRESS (OEM_ACTIVATION_TABLE_ADDRESS-FLASH_DEVICE_BASE_ADDRESS)
+#define OEM_ACTIVATION_BLOCK_END (OEM_ACTIVATION_BLOCK_ADDRESS+OEM_ACTIVATION_TABLE_SIZE)
+#define OEM_ACTIVATION_TABLE_OFFSET (0xFFFFFFFF-OEM_ACTIVATION_TABLE_ADDRESS+1)
+#endif
+
+#ifndef FV_BB_END_ADDR
+#define FV_BB_END_ADDR (0xFFFFFFFF-16-sizeof(EFI_GUID)+1)
+#endif
+
+#ifndef FV_BB_SIZE
+#define FV_BB_SIZE (0xFFFFFFFF-FV_BB_BASE+1)
+#endif
+
+//----------------------------------------------------------------------------
+
+#pragma pack (1)
+
+//<AMI_SHDR_START>
+//----------------------------------------------------------------------------
+//
+// Name: MSDM_STRUCTURE
+//
+// Description: This structure comes out of the document "M$ Digital Marker Pilot"
+//
+// Fields:
+// Name Length Description
+// ------------------------------------------------------------------
+// Header - Standard ACPI header
+// Version 4 0x1
+// Reserved 4 0x0
+// DataType 4 0x1
+// DataReserved 4 0x0
+// DataLength 4 0x1D
+// Data 29 5x5 Product Key, including "-" (BH3RN-B7FDM-C7WGT-4CR4X-6CKHM)
+//
+//----------------------------------------------------------------------------
+//<AMI_SHDR_END>
+
+typedef struct _EFI_ACPI_MSDM_TABLE {
+ ACPI_HDR Header;
+ UINT32 Version;
+ UINT32 Reserved;
+ UINT32 DataType;
+ UINT32 DataReserved;
+ UINT32 DataLength;
+ UINT8 Data[29];
+} EFI_ACPI_MSDM_TABLE;
+
+
+typedef struct _EFI_OA3_MSDM_STRUCTURE {
+ EFI_PHYSICAL_ADDRESS XsdtAddress;
+ EFI_PHYSICAL_ADDRESS MsdmAddress;
+ EFI_PHYSICAL_ADDRESS ProductKeyAddress;
+} EFI_OA3_MSDM_STRUCTURE;
+
+
+#pragma pack()
+
+//---------------------------------------------------------------------------
+
+#endif
+
+
+//****************************************************************************
+//****************************************************************************
+//** **
+//** (C)Copyright 1985-2011, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone (770)-246-8600 **
+//** **
+//****************************************************************************
+//****************************************************************************
diff --git a/Core/EM/OemActivation/OemActivation.mak b/Core/EM/OemActivation/OemActivation.mak
new file mode 100644
index 0000000..e149a85
--- /dev/null
+++ b/Core/EM/OemActivation/OemActivation.mak
@@ -0,0 +1,159 @@
+#*************************************************************************
+#*************************************************************************
+#** **
+#** (C)Copyright 1985-2011, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#*************************************************************************
+#*************************************************************************
+
+#*************************************************************************
+# $Header: /Alaska/SOURCE/Modules/OemActivation/OemActivation.mak 9 1/12/12 9:24a Vyacheslava $
+#
+# $Revision: 9 $
+#
+# $Date: 1/12/12 9:24a $
+#*************************************************************************
+# Revision History
+# ----------------
+# $Log: /Alaska/SOURCE/Modules/OemActivation/OemActivation.mak $
+#
+# 9 1/12/12 9:24a Vyacheslava
+# Removed dependency on SMM protocols. Changed type of module to
+# BS_DRIVER
+#
+# 8 10/18/11 10:00a Vyacheslava
+# [TAG] EIP70134
+# [Description] Changed GUID to let AFU know that SW SMI number is
+# changed.
+#
+# 7 10/03/11 11:04a Vyacheslava
+# [TAG] EIP64110
+# [Category] Spec Update
+# [Severity] Normal
+# [Description] (7) IsRoceveryOverSerial, NetBootHotkey, OpromTxT,
+# SimpleBootFlag, SLP10, SlpSupport, SmiVariable
+#
+# 6 9/22/11 11:22a Vyacheslava
+# [TAG] EIP64110
+# [Category] Spec Update
+# [Severity] Normal
+# [Description] Changed according to Aptio 4.6.5.x Components Porting
+# Guide.
+#
+# 5 7/07/11 11:18a Vyacheslava
+#
+# 4 5/26/11 11:33a Vyacheslava
+#
+# 3 4/29/11 12:42p Vyacheslava
+# [TAG] EIP58139
+# [Category] New Feature
+# [Description] Added macros to place Oem Activation Key in NCB.
+#
+# 2 12/17/10 1:43p Vyacheslava
+# [TAG] EIP48520
+# [Category] Improvement
+# [Description] Added checking for version of the CSP Library.
+#
+# 1 11/18/10 1:15p Vyacheslava
+# Initial creation
+#
+#
+#*************************************************************************
+#<AMI_FHDR_START>
+#
+# Name: OemActivation.mak
+#
+# Description: Make file for OemActivation eModule.
+#
+#<AMI_FHDR_END>
+#*************************************************************************
+
+!IF "$(OEM_ACTIVATION_TABLE_LOCATION)"=="0" && "$(CSP_LIB_MAJOR_VER)"=="00" && "$(CSP_LIB_MINOR_VER)"<"17"
+!ERROR To use OEM Activation 3.0 CSP Library must have version 00.17 or newer.
+!ENDIF
+
+!IFNDEF PI_SPECIFICATION_VERSION
+PI_SPECIFICATION_VERSION = 0
+!ENDIF
+
+all : OemActivation
+
+OemActivation : $(BUILD_DIR)\OemActivation.mak OemActivationBin
+
+$(BUILD_DIR)\OemActivation.mak : $(OemActivation_DIR)\$(@B).cif $(OemActivation_DIR)\$(@B).mak $(BUILD_RULES)
+ $(CIF2MAK) $(OemActivation_DIR)\$(@B).cif $(CIF2MAK_DEFAULTS)
+
+
+!IF "$(OEM_ACTIVATION_TABLE_LOCATION)"=="0"
+
+OemActivationBin : $(AMIDXELIB)
+ $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\
+ /f $(BUILD_DIR)\OemActivation.mak all\
+ GUID=76D5CF91-0C55-434E-97C2-D2825C82E610\
+ ENTRY_POINT=OemActivation_EntryPoint\
+ TYPE=BS_DRIVER\
+ DEPEX1=$(OemActivation_DIR)\OemActivation.dxs\
+ DEPEX1_TYPE=EFI_SECTION_DXE_DEPEX\
+ "EXT_HEADERS=$(BUILD_DIR)\Token.h"\
+ COMPRESS=1
+
+!ELSE
+
+OemActivationObjs = $(BUILD_DIR)\$(OemActivation_DIR)\OemActivation.obj
+
+OemActivationBin : $(AMIDXELIB)
+ $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\
+ /f $(BUILD_DIR)\OemActivation.mak all\
+ OBJECTS="$(OemActivationObjs)" \
+ GUID=76D5CF91-0C55-434E-97C2-D2825C82E610\
+ ENTRY_POINT=OemActivation_EntryPoint\
+ TYPE=BS_DRIVER\
+ DEPEX1=$(OemActivation_DIR)\OemActivation.dxs\
+ DEPEX1_TYPE=EFI_SECTION_DXE_DEPEX\
+ "EXT_HEADERS=$(BUILD_DIR)\Token.h"\
+ COMPRESS=1
+
+#---------------------------------------------------------------------------
+# Create Launch SCLEAN Pei Component
+#---------------------------------------------------------------------------
+OemActivationHook : $(BUILD_DIR)\OemActivation.mak OemActivationHookBin
+
+OemActivationHookObjs = $(BUILD_DIR)\$(OemActivation_DIR)\OemActivationHook.obj
+
+OemActivationHookBin : $(AMIDXELIB)
+ $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\
+ /f $(BUILD_DIR)\OemActivation.mak all\
+ "CFLAGS=$(CFLAGS:/W4=/W3) /I$(OFBD_DIR)" \
+ OBJECTS="$(OemActivationHookObjs)" \
+ NAME=OemActivation \
+ TYPE=LIBRARY LIBRARY_NAME=$(OEM_ACTIVATION_LIB)
+
+$(OEM_ACTIVATION_LIB) : OemActivationHook
+
+OEM_ACTIVATION_DESCRIPTOR=HOLE(\
+name=OEM_ACTIVATION, address=$(OEM_ACTIVATION_TABLE_ADDRESS),\
+offset=$(OEM_ACTIVATION_TABLE_ADDRESS)-$(FLASH_BASE),\
+size=$(OEM_ACTIVATION_TABLE_SIZE)\
+)
+
+!ENDIF
+
+#*************************************************************************
+#*************************************************************************
+#** **
+#** (C)Copyright 1985-2011, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#*************************************************************************
+#*************************************************************************
diff --git a/Core/EM/OemActivation/OemActivation.sdl b/Core/EM/OemActivation/OemActivation.sdl
new file mode 100644
index 0000000..2da7d1b
--- /dev/null
+++ b/Core/EM/OemActivation/OemActivation.sdl
@@ -0,0 +1,79 @@
+TOKEN
+ Name = "OemActivation_SUPPORT"
+ Value = "1"
+ Help = "Main switch to enable OemActivation support in Project"
+ TokenType = Boolean
+ TargetH = Yes
+ TargetMAK = Yes
+ Master = Yes
+End
+
+TOKEN
+ Name = "OEM_ACTIVATION_TABLE_LOCATION"
+ Value = "0"
+ Help = "OEM Activation Table location: \0 = FID Table.\1 = Non-Critical Block."
+ TokenType = Integer
+ TargetH = Yes
+ TargetMAK = Yes
+End
+
+TOKEN
+ Name = "OEM_ACTIVATION_TABLE_ADDRESS"
+ Value = "0xFFE10000"
+ TokenType = Integer
+ TargetMAK = Yes
+ TargetH = Yes
+ Token = "OEM_ACTIVATION_TABLE_LOCATION" "=" "1"
+End
+
+TOKEN
+ Name = "OEM_ACTIVATION_TABLE_SIZE"
+ Value = "0x10000"
+ TokenType = Integer
+ TargetMAK = Yes
+ TargetH = Yes
+ Token = "OEM_ACTIVATION_TABLE_LOCATION" "=" "1"
+End
+
+TOKEN
+ Name = "OEM_ACTIVATION_LIB"
+ Value = "$(BUILD_DIR)\OemActivation.lib"
+ TokenType = Expression
+ TargetMAK = Yes
+End
+
+PATH
+ Name = "OemActivation_DIR"
+End
+
+MODULE
+ Help = "Includes OemActivation.mak to Project"
+ File = "OemActivation.mak"
+End
+
+ELINK
+ Name = "$(BUILD_DIR)\OemActivation.lib"
+ Parent = "PRESERVE_LIB"
+ Token = "OEM_ACTIVATION_TABLE_LOCATION" "=" "1"
+ InvokeOrder = AfterParent
+End
+
+ELINK
+ Name = "$(BUILD_DIR)\OemActivation.ffs"
+ Parent = "FV_MAIN"
+ InvokeOrder = AfterParent
+End
+
+ELINK
+ Name = "$(OEM_ACTIVATION_DESCRIPTOR)"
+ Parent = "ROM_IMAGE"
+ Token = "OEM_ACTIVATION_TABLE_LOCATION" "=" "1"
+ InvokeOrder = AfterParent
+End
+
+ELINK
+ Name = "OemActivationUpdateBlockTypeId,"
+ Parent = "SMIFlashEndHandlerList"
+ Token = "OEM_ACTIVATION_TABLE_LOCATION" "=" "1"
+ InvokeOrder = AfterParent
+End
diff --git a/Core/EM/OemActivation/OemActivationHook.c b/Core/EM/OemActivation/OemActivationHook.c
new file mode 100644
index 0000000..9211bc4
--- /dev/null
+++ b/Core/EM/OemActivation/OemActivationHook.c
@@ -0,0 +1,116 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2011, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+
+//*****************************************************************************
+// $Header: /Alaska/SOURCE/Modules/OemActivation/OemActivationHook.c 3 6/10/11 10:57a Vyacheslava $
+//
+// $Revision: 3 $
+//
+// $Date: 6/10/11 10:57a $
+//*****************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/OemActivation/OemActivationHook.c $
+//
+// 3 6/10/11 10:57a Vyacheslava
+//
+// 2 5/26/11 11:34a Vyacheslava
+//
+// 1 4/29/11 12:39p Vyacheslava
+// [TAG] EIP58139
+// [Category] New Feature
+// [Description] Added SW SMI hook to place Oem Activation Key in NCB.
+//
+//
+//*****************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: OemActivationHook.c
+//
+// Description: SW SMI hook.
+//
+//<AMI_FHDR_END>
+//*****************************************************************************
+
+
+#include <AmiDxeLib.h>
+#include <Protocol/SmiFlash.h>
+#include "OemActivation.h"
+
+//----------------------------------------------------------------------------
+
+
+#if OEM_ACTIVATION_TABLE_LOCATION == 1
+
+//<AMI_PHDR_START>
+//----------------------------------------------------------------------------
+//
+// Procedure: OemActivationUpdateBlockTypeId
+//
+// Description: This function is SW SMI hook that sets Flash Block Description
+// type for AMI AFU utility. (EIP#58139)
+//
+// Input:
+// SwSmiNum - SW SMI value number
+// Buffer - Flash descriptor address
+//
+// Output: VOID
+//
+//----------------------------------------------------------------------------
+//<AMI_PHDR_END>
+
+VOID OemActivationUpdateBlockTypeId (
+ IN UINT8 SwSmiNum,
+ IN UINT64 Buffer )
+{
+ BLOCK_DESC *BlockDesc;
+ UINTN i;
+
+ // return if SW SMI value is not "Get Flash Info"
+ if (SwSmiNum != SMIFLASH_GET_FLASH_INFO)
+ return;
+
+ BlockDesc = (BLOCK_DESC*)&((INFO_BLOCK*)Buffer)->Blocks;
+
+ for (i = 0; i < ((INFO_BLOCK*)Buffer)->TotalBlocks; i++) {
+
+ TRACE((TRACE_ALWAYS,"OemActivationUpdateBlockTypeId: %08X(%08X), Block %08X\n",OEM_ACTIVATION_BLOCK_ADDRESS,OEM_ACTIVATION_BLOCK_END,BlockDesc[i].StartAddress));
+
+ if (BlockDesc[i].StartAddress < OEM_ACTIVATION_BLOCK_ADDRESS)
+ continue;
+
+ if (BlockDesc[i].StartAddress >= OEM_ACTIVATION_BLOCK_END)
+ continue;
+
+ TRACE((TRACE_ALWAYS,"OemActivationUpdateBlockTypeId: Found Blocks %08X\n",BlockDesc[i].StartAddress));
+
+ BlockDesc[i].Type = OA3_FLASH_BLOCK_DESC_TYPE;
+ }
+}
+
+#endif
+
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2011, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//************************************************************************* \ No newline at end of file
diff --git a/Core/EM/OemActivation/SmmOemActivation.c b/Core/EM/OemActivation/SmmOemActivation.c
new file mode 100644
index 0000000..df9502d
--- /dev/null
+++ b/Core/EM/OemActivation/SmmOemActivation.c
@@ -0,0 +1,491 @@
+//****************************************************************************
+//****************************************************************************
+//** **
+//** (C)Copyright 1985-2012, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone (770)-246-8600 **
+//** **
+//****************************************************************************
+//****************************************************************************
+
+//*****************************************************************************
+// $Header: /Alaska/SOURCE/Modules/OemActivation/SmmOemActivation.c 6 6/14/13 9:48a Vyacheslava $
+//
+// $Revision: 6 $
+//
+// $Date: 6/14/13 9:48a $
+//*****************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/OemActivation/SmmOemActivation.c $
+//
+// 6 6/14/13 9:48a Vyacheslava
+// [TAG] EIP125798
+// [Category] Improvement
+// [Description] Added security check for Runtime injection of Product
+// Key through SMI
+//
+// 5 5/22/12 4:31p Vyacheslava
+// The OA3MSDMvariable variable has improper GUID.
+//
+// 4 4/27/12 2:41p Vyacheslava
+//
+// 3 4/20/12 2:43p Vyacheslava
+// There is additional pointer to MSDM ACPI will be added to XSDT for each
+// time AFU used to inject the product key. This issue is only actual if
+// there is empty product key in the in the firmware.
+//
+// 2 1/31/12 11:46a Vyacheslava
+// Changed SMM SW Context pointer according with changes in the
+// SmmChildDispatcher.
+//
+// 1 1/12/12 9:36a Vyacheslava
+// Separated to the module part.
+//
+//
+//
+//*****************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: SmmOemActivation.c
+//
+// Description: This part of code allows to update ACPI in the OS Runtime through
+// the SW SMI for OEM Activation without rebooting the system.
+//
+//<AMI_FHDR_END>
+//*****************************************************************************
+
+
+#include <AmiDxeLib.h>
+#include <AmiSmm.h>
+#include "OemActivation.h"
+#include <AmiHobs.h>
+
+#if PI_SPECIFICATION_VERSION<0x0001000A
+ #include <Protocol/SmmSwDispatch.h>
+ #include <Protocol/SmmControl.h>
+#else
+ #include <Protocol/SmmSwDispatch2.h>
+ #include <Protocol/SmmControl2.h>
+ #include <Protocol/SmmCpu.h>
+#endif
+
+//---------------------------------------------------------------------------
+
+static EFI_PHYSICAL_ADDRESS gTsegAddress_ = 0;
+static UINT32 gTsegSize_ = 0;
+
+//---------------------------------------------------------------------------
+
+
+//<AMI_PHDR_START>
+//--------------------------------------------------------------------------
+//
+// Procedure: GetTsegVar
+//
+// Description: This function stores TSEG address and size.
+//
+// Input: VOID
+//
+// Output: VOID
+//
+//--------------------------------------------------------------------------
+//<AMI_PHDR_END>
+
+VOID GetTsegVar(VOID)
+{
+ EFI_STATUS Status;
+ EFI_GUID CpuInfoHobGuid = AMI_CPUINFO_HOB_GUID;
+ EFI_GUID HobListGuid = HOB_LIST_GUID;
+ CPUINFO_HOB *CpuInfoHob = (CPUINFO_HOB*)GetEfiConfigurationTable(pST,&HobListGuid);
+
+ if (CpuInfoHob == NULL)
+ return;
+
+ Status = FindNextHobByGuid(&CpuInfoHobGuid,&CpuInfoHob);
+ if (EFI_ERROR(Status))
+ return;
+
+ gTsegAddress_ = CpuInfoHob->TsegAddress;
+ gTsegSize_ = CpuInfoHob->TsegSize;
+}
+
+
+//<AMI_PHDR_START>
+//---------------------------------------------------------------------------
+//
+// Procedure: CheckAddressRange
+//
+// Description: Check address range to avoid TSEG area.
+//
+// Input:
+// Address - starting address
+// Range - length of the area
+//
+// Output:
+// EFI_SUCCESS - Access granted
+// EFI_SECURITY_VIOLATION - Access denied!
+//
+//---------------------------------------------------------------------------
+//<AMI_PHDR_END>
+
+EFI_STATUS CheckAddressRange( IN UINT8 *Address, IN UINTN Range )
+{
+ // if TSEG variables are not initialized then do not validate the access.
+ if ( gTsegAddress_ == 0 || gTsegSize_ == 0 )
+ return EFI_SUCCESS;
+
+ if ( ((EFI_PHYSICAL_ADDRESS)Address >= gTsegAddress_) &&
+ ((EFI_PHYSICAL_ADDRESS)Address <= (gTsegAddress_ + gTsegSize_)) )
+ return EFI_SECURITY_VIOLATION;
+
+ if ( (((EFI_PHYSICAL_ADDRESS)Address + Range) >= gTsegAddress_) &&
+ (((EFI_PHYSICAL_ADDRESS)Address + Range) <= (gTsegAddress_ + gTsegSize_)) )
+ return EFI_SECURITY_VIOLATION;
+
+ return EFI_SUCCESS;
+}
+
+
+//<AMI_PHDR_START>
+//---------------------------------------------------------------------------
+//
+// Name: ChsumTbl
+//
+// Description: This function calculates a checksum of table starting at
+// TblStart of length BytesCount and returns the checksum value.
+//
+// Input:
+// *TblStart - Starting address of the memory area to checksum.
+// BytesCount - Length in bytes of the memory area to checksum.
+//
+// Output:
+// Checksum value starting from TblStart and ending at TblStart + BytesCount.
+//
+//---------------------------------------------------------------------------
+//<AMI_PHDR_END>
+
+UINT8 ChsumTbl( IN UINT8* TblStart, IN UINT32 BytesCount )
+{
+ UINT8 Result = *TblStart;
+ UINTN i;
+
+ for ( i = 1; i < BytesCount; i++ )
+ Result += TblStart[i];
+ return 0 - Result;
+}
+
+
+//<AMI_PHDR_START>
+//---------------------------------------------------------------------------
+//
+// Procedure: Oa3UpdateAcpiTable
+//
+// Description: This function will update ACPI table for OA3.
+//
+// Input: ProductKey - pointer to the Product Key
+//
+// Output: EFI_STATUS
+//
+//---------------------------------------------------------------------------
+//<AMI_PHDR_END>
+
+EFI_STATUS Oa3UpdateAcpiTable( IN UINT8 *ProductKey )
+{
+ EFI_STATUS Status;
+ EFI_OA3_MSDM_STRUCTURE MsdmVariable = {0};
+ EFI_GUID AmiGlobalVariableGuid = AMI_GLOBAL_VARIABLE_GUID;
+ UINTN Size = sizeof(EFI_OA3_MSDM_STRUCTURE);
+ EFI_ACPI_MSDM_TABLE *MsdmTable;
+ ACPI_HDR *AcpiHdr;
+ UINT8 *Ptr;
+ EFI_PHYSICAL_ADDRESS *AcpiPtr;
+
+ if (ProductKey == NULL)
+ return EFI_INVALID_PARAMETER;
+
+ Status = CheckAddressRange(ProductKey, sizeof(MsdmTable->Data));
+ if (EFI_ERROR(Status))
+ return Status;
+
+ Status = pRS->GetVariable(
+ EFI_OA3_MSDM_VARIABLE,
+ &AmiGlobalVariableGuid,
+ NULL,
+ &Size,
+ &MsdmVariable
+ );
+ TRACE((TRACE_ALWAYS,"Oa3UpdateAcpiTable: XsdtAddr=%X, MsdmAddr=%X\n",MsdmVariable.XsdtAddress,MsdmVariable.MsdmAddress));
+ ASSERT_EFI_ERROR(Status);
+ if (EFI_ERROR(Status))
+ return Status;
+
+ if ( MsdmVariable.XsdtAddress == 0 || MsdmVariable.MsdmAddress == 0 )
+ return EFI_INVALID_PARAMETER;
+
+ // Validate MSDM table signature
+ MsdmTable = (EFI_ACPI_MSDM_TABLE*)(UINTN)MsdmVariable.MsdmAddress;
+ if (MsdmTable->Header.Signature != MSDM_SIG)
+ return EFI_INVALID_PARAMETER;
+
+ // Validate XSDT table signature
+ AcpiHdr = (ACPI_HDR*)(UINTN)MsdmVariable.XsdtAddress;
+ if (AcpiHdr->Signature != XSDT_SIG)
+ return EFI_INVALID_PARAMETER;
+
+ // Copy a new Product Key to MSDM Data array
+ MemCpy(
+ (UINT8*)&MsdmTable->Version,
+#if OEM_ACTIVATION_TABLE_LOCATION == 0
+ ProductKey,
+#else
+ (UINT8*)OEM_ACTIVATION_TABLE_ADDRESS, // Copy Key from the NCB
+#endif
+ sizeof(EFI_ACPI_MSDM_TABLE) - sizeof(ACPI_HDR) );
+
+ // Updates MSDM table checksum
+ MsdmTable->Header.Checksum = 0;
+ MsdmTable->Header.Checksum = ChsumTbl((UINT8*)MsdmTable, sizeof(EFI_ACPI_MSDM_TABLE));
+
+ // Check if pointer to MSDM ACPI table has been set already
+ Ptr = (UINT8*)AcpiHdr + AcpiHdr->Length - sizeof(EFI_PHYSICAL_ADDRESS);
+ AcpiPtr = (EFI_PHYSICAL_ADDRESS*)Ptr;
+ if ( *AcpiPtr != (EFI_PHYSICAL_ADDRESS)MsdmTable ) {
+
+ // Validate ACPI header's length. Check a range to avoid SMM
+ Ptr = (UINT8*)AcpiHdr + AcpiHdr->Length;
+ Status = CheckAddressRange(Ptr, sizeof(EFI_PHYSICAL_ADDRESS));
+ if (EFI_ERROR(Status))
+ return Status;
+
+ // Check destination if it's cleared by zero
+ AcpiPtr = (EFI_PHYSICAL_ADDRESS*)Ptr;
+ if (*AcpiPtr != 0)
+ return EFI_SECURITY_VIOLATION;
+
+ // Add address of MSDM table as the last pointer in XSDT
+ *AcpiPtr = (EFI_PHYSICAL_ADDRESS)MsdmTable;
+
+ // Updates Length filed of the XSDT table (increments by 8)
+ AcpiHdr->Length += sizeof(EFI_PHYSICAL_ADDRESS);
+
+ // Updates XSDT checksum
+ AcpiHdr->Checksum = 0;
+ AcpiHdr->Checksum = ChsumTbl((UINT8*)AcpiHdr, AcpiHdr->Length);
+ }
+
+ return EFI_SUCCESS;
+}
+
+
+//<AMI_PHDR_START>
+//---------------------------------------------------------------------------
+//
+// Procedure: SwSmiOa3Function
+//
+// Description:
+// Calling the SMI Interface
+// The caller will write AL (the value 0xee) to the SMI Command Port as
+// defined in the ACPI FADT.
+// The SMI handler will update the callers' buffer(s) and return.
+//
+// Input:
+// DispatchHandle
+// DispatchContext
+//
+// Output: VOID
+//
+// Notes:
+// The function will clear the carry bit if it is successful (CF = 0).
+// If the function is unsuccessful, it will set the carry bit and set the
+// error code in the AH register as indicated by the error table below.
+// The function returns the following data in the provided parameter block.
+//
+//---------------------------------------------------------------------------
+//<AMI_PHDR_END>
+
+#if PI_SPECIFICATION_VERSION<0x0001000A
+VOID SwSmiOa3Function(
+ IN EFI_HANDLE DispatchHandle,
+ IN EFI_SMM_SW_DISPATCH_CONTEXT *DispatchContext )
+{
+ EFI_GUID SwSmiCpuTriggerGuid = SW_SMI_CPU_TRIGGER_GUID;
+ UINTN CpuIndex = pSmst->CurrentlyExecutingCpu - 1;
+ UINTN Index;
+
+ // determine which CPU triggered SMI
+ for (Index = 0; Index < pSmst->NumberOfTableEntries; Index++)
+ if ( !guidcmp(&pSmst->SmmConfigurationTable[Index].VendorGuid, &SwSmiCpuTriggerGuid) ) {
+ CpuIndex = ((SW_SMI_CPU_TRIGGER*)pSmst->SmmConfigurationTable[Index].VendorTable)->Cpu;
+ break;
+ }
+
+ // Update the ACPI table
+ Oa3UpdateAcpiTable((UINT8*)(EFI_PHYSICAL_ADDRESS)pSmst->CpuSaveState[CpuIndex].Ia32SaveState.EBX);
+}
+
+#else
+
+EFI_STATUS SwSmiOa3Function(
+ IN EFI_HANDLE DispatchHandle,
+ IN CONST VOID *Context OPTIONAL,
+ IN OUT VOID *CommBuffer OPTIONAL,
+ IN OUT UINTN *CommBufferSize OPTIONAL )
+{
+ EFI_STATUS Status;
+ EFI_SMM_SW_CONTEXT *SmmSwContext = ((EFI_SMM_SW_CONTEXT*)CommBuffer);
+ EFI_GUID EfiSmmCpuProtocolGuid = EFI_SMM_CPU_PROTOCOL_GUID;
+ EFI_SMM_CPU_PROTOCOL *SmmCpuProtocol = NULL;
+ EFI_PHYSICAL_ADDRESS Register = 0;
+
+ Status = pSmst->SmmLocateProtocol(
+ &EfiSmmCpuProtocolGuid,
+ NULL,
+ &SmmCpuProtocol
+ );
+ ASSERT_EFI_ERROR(Status);
+ if (EFI_ERROR(Status))
+ return Status;
+
+ // Read the RBX register
+ Status = SmmCpuProtocol->ReadSaveState(
+ SmmCpuProtocol,
+ sizeof(UINT32),
+ EFI_SMM_SAVE_STATE_REGISTER_RBX,
+ SmmSwContext->SwSmiCpuIndex,
+ &Register
+ );
+ if (!EFI_ERROR(Status))
+ Oa3UpdateAcpiTable((UINT8*)Register); // Update the ACPI table
+
+ return Status;
+}
+#endif
+
+
+//<AMI_PHDR_START>
+//---------------------------------------------------------------------------
+//
+// Procedure: InSmmFunction
+//
+// Description: Registration of the SMI function
+//
+// Input:
+// ImageHandle - Image handle
+// SystemTable - Pointer to the system table
+//
+// Output: EFI_STATUS
+//
+//---------------------------------------------------------------------------
+//<AMI_PHDR_END>
+
+EFI_STATUS InSmmFunction(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable )
+{
+ EFI_STATUS Status;
+ EFI_HANDLE Handle = 0;
+
+#if PI_SPECIFICATION_VERSION<0x0001000A
+ EFI_GUID EfiSmmSwDispatchProtocolGuid = EFI_SMM_SW_DISPATCH_PROTOCOL_GUID;
+ EFI_SMM_SW_DISPATCH_PROTOCOL *SwDispatch = NULL;
+ EFI_SMM_SW_DISPATCH_CONTEXT SwContext;
+ Status = pBS->LocateProtocol(
+#else
+ EFI_GUID EfiSmmSwDispatchProtocolGuid = EFI_SMM_SW_DISPATCH2_PROTOCOL_GUID;
+ EFI_SMM_SW_DISPATCH2_PROTOCOL *SwDispatch = NULL;
+ EFI_SMM_SW_REGISTER_CONTEXT SwContext;
+ Status = pSmst->SmmLocateProtocol(
+#endif
+ &EfiSmmSwDispatchProtocolGuid,
+ NULL,
+ &SwDispatch
+ );
+ ASSERT_EFI_ERROR(Status);
+ if (EFI_ERROR(Status))
+ return Status;
+
+ SwContext.SwSmiInputValue = SW_SMI_OA3_FUNCTION_NUMBER;
+ Status = SwDispatch->Register(
+ SwDispatch,
+ SwSmiOa3Function,
+ &SwContext,
+ &Handle
+ );
+ ASSERT_EFI_ERROR(Status);
+ return Status;
+}
+
+
+//<AMI_PHDR_START>
+//----------------------------------------------------------------------------
+//
+// Procedure: SmmOemActivation_EntryPoint
+//
+// Description: This function is the entry point of the module.
+//
+// Input:
+// ImageHandle - Image handle
+// *SystemTable - Pointer to the system table
+//
+// Output: EFI_STATUS
+//
+//----------------------------------------------------------------------------
+//<AMI_PHDR_END>
+
+EFI_STATUS EFIAPI SmmOemActivation_EntryPoint(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable )
+{
+ EFI_STATUS Status;
+ EFI_OA3_MSDM_STRUCTURE MsdmVariable;
+ EFI_GUID AmiGlobalVariableGuid = AMI_GLOBAL_VARIABLE_GUID;
+ UINTN Size = sizeof(EFI_OA3_MSDM_STRUCTURE);
+
+ InitAmiLib(ImageHandle, SystemTable);
+
+ // Get TSEG address and TSEG size
+ GetTsegVar();
+
+ // Check if OA3 MSDM variable does exist
+ Status = pRS->GetVariable(
+ EFI_OA3_MSDM_VARIABLE,
+ &AmiGlobalVariableGuid,
+ NULL,
+ &Size,
+ &MsdmVariable
+ );
+ if (!EFI_ERROR(Status)) {
+
+ // then install the SMI handler
+ Status = InitSmmHandler(
+ ImageHandle,
+ SystemTable,
+ InSmmFunction,
+ NULL
+ );
+ TRACE((TRACE_ALWAYS,"OEM Activation: InitSmmHandler Status=%r\n",Status));
+ ASSERT_EFI_ERROR(Status);
+ }
+
+ return Status;
+}
+
+
+//****************************************************************************
+//****************************************************************************
+//** **
+//** (C)Copyright 1985-2012, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone (770)-246-8600 **
+//** **
+//****************************************************************************
+//****************************************************************************
diff --git a/Core/EM/OemActivation/SmmOemActivation.cif b/Core/EM/OemActivation/SmmOemActivation.cif
new file mode 100644
index 0000000..d803008
--- /dev/null
+++ b/Core/EM/OemActivation/SmmOemActivation.cif
@@ -0,0 +1,11 @@
+<component>
+ name = "SmmOemActivation"
+ category = ModulePart
+ LocalRoot = "Core\EM\OemActivation\"
+ RefName = "SmmOemActivation"
+[files]
+"SmmOemActivation.mak"
+"SmmOemActivation.sdl"
+"SmmOemActivation.c"
+"SmmOemActivation.dxs"
+<endComponent>
diff --git a/Core/EM/OemActivation/SmmOemActivation.dxs b/Core/EM/OemActivation/SmmOemActivation.dxs
new file mode 100644
index 0000000..01c5836
--- /dev/null
+++ b/Core/EM/OemActivation/SmmOemActivation.dxs
@@ -0,0 +1,83 @@
+//****************************************************************************
+//****************************************************************************
+//** **
+//** (C)Copyright 1985-2012, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone (770)-246-8600 **
+//** **
+//****************************************************************************
+//****************************************************************************
+
+//*****************************************************************************
+// $Header: /Alaska/SOURCE/Modules/OemActivation/SmmOemActivation.dxs 3 1/12/12 9:35a Vyacheslava $
+//
+// $Revision: 3 $
+//
+// $Date: 1/12/12 9:35a $
+//*****************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/OemActivation/SmmOemActivation.dxs $
+//
+// 3 1/12/12 9:35a Vyacheslava
+//
+//
+//
+//*****************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: SmmOemActivation.dxs
+//
+// Description: This file is the dependency file for OemActivation module.
+//
+//<AMI_FHDR_END>
+//*****************************************************************************
+
+//---------------------------------------------------------------------------
+// Header files for GUID definitions
+//---------------------------------------------------------------------------
+
+#if PI_SPECIFICATION_VERSION<0x0001000A
+//---------------------------------------------------------------------------
+
+#include <Protocol/SmmBase.h>
+#include <Protocol/SmmSwDispatch.h>
+
+DEPENDENCY_START
+ EFI_SMM_BASE_PROTOCOL_GUID AND
+ EFI_SMM_SW_DISPATCH_PROTOCOL_GUID
+DEPENDENCY_END
+
+//---------------------------------------------------------------------------
+#else
+//---------------------------------------------------------------------------
+
+#include <Protocol/SmmBase2.h>
+#include <Protocol/SmmSwDispatch2.h>
+
+DEPENDENCY_START
+ EFI_SMM_BASE2_PROTOCOL_GUID AND
+ EFI_SMM_SW_DISPATCH2_PROTOCOL_GUID
+DEPENDENCY_END
+
+//---------------------------------------------------------------------------
+#endif
+
+
+//****************************************************************************
+//****************************************************************************
+//** **
+//** (C)Copyright 1985-2012, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone (770)-246-8600 **
+//** **
+//****************************************************************************
+//****************************************************************************
diff --git a/Core/EM/OemActivation/SmmOemActivation.mak b/Core/EM/OemActivation/SmmOemActivation.mak
new file mode 100644
index 0000000..50b3663
--- /dev/null
+++ b/Core/EM/OemActivation/SmmOemActivation.mak
@@ -0,0 +1,75 @@
+#*************************************************************************
+#*************************************************************************
+#** **
+#** (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/OemActivation/SmmOemActivation.mak 1 1/12/12 9:36a Vyacheslava $
+#
+# $Revision: 1 $
+#
+# $Date: 1/12/12 9:36a $
+#*************************************************************************
+# Revision History
+# ----------------
+# $Log: /Alaska/SOURCE/Modules/OemActivation/SmmOemActivation.mak $
+#
+# 1 1/12/12 9:36a Vyacheslava
+# Separated to the module part.
+#
+#
+#
+#*************************************************************************
+#<AMI_FHDR_START>
+#
+# Name: SmmOemActivation.mak
+#
+# Description: Make file for SmmOemActivation module.
+#
+#<AMI_FHDR_END>
+#*************************************************************************
+
+all : SmmOemActivation
+
+SmmOemActivation : $(BUILD_DIR)\SmmOemActivation.mak SmmOemActivationBin
+
+$(BUILD_DIR)\SmmOemActivation.mak : $(OemActivation_DIR)\$(@B).cif $(OemActivation_DIR)\$(@B).mak $(BUILD_RULES)
+ $(CIF2MAK) $(OemActivation_DIR)\$(@B).cif $(CIF2MAK_DEFAULTS)
+
+SmmOemActivationBin : $(AMIDXELIB)
+ $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\
+ /f $(BUILD_DIR)\SmmOemActivation.mak all\
+ GUID=8434DA1F-5CEB-402e-A93C-038CBE0F3F0E\
+ ENTRY_POINT=SmmOemActivation_EntryPoint\
+!IF $(PI_SPECIFICATION_VERSION)<0x00001000A
+ TYPE=BS_DRIVER\
+!ELSE
+ TYPE=SMM_DRIVER\
+!ENDIF
+ DEPEX1=$(OemActivation_DIR)\SmmOemActivation.dxs\
+ DEPEX1_TYPE=EFI_SECTION_SMM_DEPEX\
+ "EXT_HEADERS=$(BUILD_DIR)\Token.h"\
+ COMPRESS=1
+
+#*************************************************************************
+#*************************************************************************
+#** **
+#** (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/Core/EM/OemActivation/SmmOemActivation.sdl b/Core/EM/OemActivation/SmmOemActivation.sdl
new file mode 100644
index 0000000..3234943
--- /dev/null
+++ b/Core/EM/OemActivation/SmmOemActivation.sdl
@@ -0,0 +1,32 @@
+TOKEN
+ Name = "SmmOemActivation_SUPPORT"
+ Value = "0"
+ Help = "Switch to enable Update ACPI in the OS Runtime through the SW SMI for OEM Activation without rebooting the system."
+ TokenType = Boolean
+ TargetH = Yes
+ TargetMAK = Yes
+ Master = Yes
+End
+
+TOKEN
+ Name = "SW_SMI_OA3_FUNCTION_NUMBER"
+ Value = "0xDF"
+ TokenType = Integer
+ TargetH = Yes
+ Token = "SmmOemActivation_SUPPORT" "=" "1"
+End
+
+PATH
+ Name = "OemActivation_DIR"
+End
+
+MODULE
+ Help = "Includes SmmOemActivation.mak to Project"
+ File = "SmmOemActivation.mak"
+End
+
+ELINK
+ Name = "$(BUILD_DIR)\SmmOemActivation.ffs"
+ Parent = "FV_MAIN"
+ InvokeOrder = AfterParent
+End