summaryrefslogtreecommitdiff
path: root/Silicon
diff options
context:
space:
mode:
authorGuo Mang <mang.guo@intel.com>2016-12-23 11:02:24 +0800
committerGuo Mang <mang.guo@intel.com>2016-12-26 19:15:06 +0800
commitee76ea9eb7f09d9c9ba6a194a817d1fb8913ceba (patch)
treed57d3866685555599c26d7f8efcd9704288f09ec /Silicon
parent42cba99a379661e55a4d10a15b6ba8dce6feeabe (diff)
downloadedk2-platforms-ee76ea9eb7f09d9c9ba6a194a817d1fb8913ceba.tar.xz
BroxtonSiPkg: Add SampleCode
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Guo Mang <mang.guo@intel.com>
Diffstat (limited to 'Silicon')
-rw-r--r--Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/SampleCode/BiosWriteProtect/Smm/ScBiosWriteProtect.c167
-rw-r--r--Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/SampleCode/BiosWriteProtect/Smm/ScBiosWriteProtect.h32
-rw-r--r--Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/SampleCode/BiosWriteProtect/Smm/ScBiosWriteProtect.inf58
-rw-r--r--Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/SampleCode/Include/Library/ScAslUpdateLib.h168
-rw-r--r--Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/SampleCode/Library/AslUpdate/Dxe/ScAslUpdateLib.c478
-rw-r--r--Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/SampleCode/Library/AslUpdate/Dxe/ScAslUpdateLib.inf37
-rw-r--r--Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/SampleCode/SampleCode.dec31
7 files changed, 971 insertions, 0 deletions
diff --git a/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/SampleCode/BiosWriteProtect/Smm/ScBiosWriteProtect.c b/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/SampleCode/BiosWriteProtect/Smm/ScBiosWriteProtect.c
new file mode 100644
index 0000000000..87dbf9c72b
--- /dev/null
+++ b/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/SampleCode/BiosWriteProtect/Smm/ScBiosWriteProtect.c
@@ -0,0 +1,167 @@
+/** @file
+ SC BIOS Write Protect Driver.
+
+ Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>
+
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include "ScBiosWriteProtect.h"
+
+//
+// Global variables
+//
+EFI_SMM_ICHN_DISPATCH_PROTOCOL *mIchnDispatch;
+EFI_SMM_SW_DISPATCH2_PROTOCOL *mSwDispatch;
+UINTN mPciSpiRegBase;
+
+/**
+ This hardware SMI handler will be run every time the BIOS Write Enable bit is set.
+
+ @param[in] DispatchHandle Not used
+ @param[in] DispatchContext Not used
+
+ @retval None
+
+**/
+VOID
+EFIAPI
+ScBiosWpCallback (
+ IN EFI_HANDLE DispatchHandle,
+ IN EFI_SMM_ICHN_DISPATCH_CONTEXT *DispatchContext
+ )
+{
+
+ //
+ // Disable BIOSWE bit to protect BIOS
+ //
+ MmioAnd8 ((UINTN) (mPciSpiRegBase + R_SPI_BCR), (UINT8) ~B_SPI_BCR_BIOSWE);
+
+ //
+ // Clear Sync SMI Status
+ //
+ MmioOr16 ((UINTN) (mPciSpiRegBase + R_SPI_BCR), (UINT16) B_SPI_BCR_SYNC_SS);
+}
+
+
+/**
+ Register an IchnBiosWp callback function to handle TCO BIOSWR SMI
+ SMM_BWP and BLE bits will be set here
+
+ @param[in] DispatchHandle Not used
+ @param[in] DispatchContext Not used
+
+ @retval None
+
+**/
+VOID
+EFIAPI
+ScBiosLockSwSmiCallback (
+ IN EFI_HANDLE DispatchHandle,
+ IN EFI_SMM_SW_REGISTER_CONTEXT *DispatchContext
+ )
+{
+ EFI_STATUS Status;
+ EFI_SMM_ICHN_DISPATCH_CONTEXT IchnContext;
+ EFI_HANDLE IchnHandle;
+
+ if (mIchnDispatch == NULL) {
+ return;
+ }
+
+ IchnHandle = NULL;
+
+ //
+ // Set SMM_BWP bit before registering IchnBiosWp
+ //
+ MmioOr8 ((UINTN) (mPciSpiRegBase + R_SPI_BCR), (UINT8) B_SPI_BCR_SMM_BWP);
+
+ //
+ // Register an IchnBiosWp callback function to handle TCO BIOSWR SMI
+ //
+ IchnContext.Type = IchnBiosWp;
+ Status = mIchnDispatch->Register (
+ mIchnDispatch,
+ ScBiosWpCallback,
+ &IchnContext,
+ &IchnHandle
+ );
+ ASSERT_EFI_ERROR (Status);
+}
+
+
+/**
+ Entry point for SC Bios Write Protect driver.
+
+ @param[in] ImageHandle Image handle of this driver.
+ @param[in] SystemTable Global system service table.
+
+ @retval EFI_SUCCESS Initialization complete.
+
+**/
+EFI_STATUS
+EFIAPI
+InstallScBiosWriteProtect (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+ SC_POLICY_HOB *ScPolicy;
+ EFI_HANDLE SwHandle;
+ EFI_SMM_SW_REGISTER_CONTEXT SwContext;
+ EFI_PEI_HOB_POINTERS HobPtr;
+ SC_LOCK_DOWN_CONFIG *LockDownConfig;
+
+ //
+ // Get Sc Platform Policy Hob
+ //
+ HobPtr.Guid = GetFirstGuidHob (&gScPolicyHobGuid);
+ ASSERT (HobPtr.Guid != NULL);
+ ScPolicy = (SC_POLICY_HOB *) GET_GUID_HOB_DATA (HobPtr.Guid);
+ Status = GetConfigBlock ((VOID *) ScPolicy, &gLockDownConfigGuid, (VOID *) &LockDownConfig);
+ ASSERT_EFI_ERROR (Status);
+
+ if ((LockDownConfig->BiosLock == TRUE)) {
+ mPciSpiRegBase = MmPciBase (
+ DEFAULT_PCI_BUS_NUMBER_SC,
+ PCI_DEVICE_NUMBER_SPI,
+ PCI_FUNCTION_NUMBER_SPI
+ );
+ //
+ // Get the ICHn protocol
+ //
+ mIchnDispatch = NULL;
+ Status = gSmst->SmmLocateProtocol (&gEfiSmmIchnDispatchProtocolGuid, NULL, (VOID **) &mIchnDispatch);
+ ASSERT_EFI_ERROR (Status);
+
+ //
+ // Locate the SC SMM SW dispatch protocol
+ //
+ SwHandle = NULL;
+ Status = gSmst->SmmLocateProtocol (&gEfiSmmSwDispatch2ProtocolGuid, NULL, (VOID **) &mSwDispatch);
+ ASSERT_EFI_ERROR (Status);
+
+ //
+ // Register BIOS Lock SW SMI handler
+ //
+ SwContext.SwSmiInputValue = LockDownConfig->BiosLockSwSmiNumber;
+ Status = mSwDispatch->Register (
+ mSwDispatch,
+ (EFI_SMM_HANDLER_ENTRY_POINT2) ScBiosLockSwSmiCallback,
+ &SwContext,
+ &SwHandle
+ );
+ ASSERT_EFI_ERROR (Status);
+ }
+
+ return EFI_SUCCESS;
+}
+
diff --git a/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/SampleCode/BiosWriteProtect/Smm/ScBiosWriteProtect.h b/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/SampleCode/BiosWriteProtect/Smm/ScBiosWriteProtect.h
new file mode 100644
index 0000000000..67fd7e3127
--- /dev/null
+++ b/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/SampleCode/BiosWriteProtect/Smm/ScBiosWriteProtect.h
@@ -0,0 +1,32 @@
+/** @file
+ Header file for the SC Bios Write Protect Driver.
+
+ Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>
+
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#ifndef _SC_BIOS_WRITE_PROTECT_H_
+#define _SC_BIOS_WRITE_PROTECT_H_
+
+#include <Library/IoLib.h>
+#include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+#include <ScAccess.h>
+#include <Protocol/SmmIchnDispatch.h>
+#include <Protocol/SmmSwDispatch2.h>
+#include <Private/Guid/ScPolicyHobGuid.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/SmmServicesTableLib.h>
+#include <Library/MmPciLib.h>
+#include <Library/ConfigBlockLib.h>
+
+#endif
+
diff --git a/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/SampleCode/BiosWriteProtect/Smm/ScBiosWriteProtect.inf b/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/SampleCode/BiosWriteProtect/Smm/ScBiosWriteProtect.inf
new file mode 100644
index 0000000000..b6c8949192
--- /dev/null
+++ b/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/SampleCode/BiosWriteProtect/Smm/ScBiosWriteProtect.inf
@@ -0,0 +1,58 @@
+## @file
+# ScBiosWriteProtect driver.
+#
+# Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php.
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = ScBiosWriteProtect
+ FILE_GUID = B8B8B609-0B6C-4b8c-A731-DE03A6C3F3DC
+ MODULE_TYPE = DXE_SMM_DRIVER
+ VERSION_STRING = 1.0
+ PI_SPECIFICATION_VERSION = 0x0001000A
+ ENTRY_POINT = InstallScBiosWriteProtect
+
+[sources]
+ ScBiosWriteProtect.h
+ ScBiosWriteProtect.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ BroxtonSiPkg/BroxtonSiPkg.dec
+ BroxtonSiPkg/BroxtonSiPrivate.dec
+
+[LibraryClasses]
+ BaseLib
+ DebugLib
+ IoLib
+ UefiDriverEntryPoint
+ HobLib
+ SmmServicesTableLib
+ MmPciLib
+ ConfigBlockLib
+
+[Guids]
+ gScPolicyHobGuid
+ gLockDownConfigGuid
+
+[Protocols]
+ gEfiSmmIchnDispatchProtocolGuid ## SOMETIMES_CONSUMES
+ gEfiSmmSwDispatch2ProtocolGuid ## SOMETIMES_CONSUMES
+
+[Depex]
+ gEfiSmmBase2ProtocolGuid AND
+ gEfiSmmIchnDispatchProtocolGuid AND
+ gEfiSmmSwDispatch2ProtocolGuid
+
+[Pcd]
+ gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress ## SOMETIMES_CONSUMES
diff --git a/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/SampleCode/Include/Library/ScAslUpdateLib.h b/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/SampleCode/Include/Library/ScAslUpdateLib.h
new file mode 100644
index 0000000000..7763669f71
--- /dev/null
+++ b/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/SampleCode/Include/Library/ScAslUpdateLib.h
@@ -0,0 +1,168 @@
+/** @file
+ ASL dynamic update library definitions.
+ This library provides dymanic update to various ASL structures.
+ There may be different libraries for different environments (PEI, BS, RT, SMM).
+ Make sure you meet the requirements for the library (protocol dependencies, use
+ restrictions, etc).
+
+ Copyright (c) 1999 - 2016, Intel Corporation. All rights reserved.<BR>
+
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#ifndef _ASL_UPDATE_LIB_H_
+#define _ASL_UPDATE_LIB_H_
+
+//
+// Include files
+//
+#include <PiDxe.h>
+#include <IndustryStandard/Acpi30.h>
+#include <Protocol/AcpiSupport.h>
+#include <Protocol/AcpiTable.h>
+
+//
+// AML parsing definitions
+//
+#define AML_NAME_OP 0x08
+#define AML_BUFFER_OP 0x11
+#define AML_DMA_FIXED_DESC_OP 0x55
+#define AML_DEVICE_OP 0x82
+#define AML_MEMORY32_FIXED_OP 0x86
+#define AML_DWORD_OP 0x87
+#define AML_INTERRUPT_DESC_OP 0x89
+
+/**
+ Initialize the ASL update library state.
+ This must be called prior to invoking other library functions.
+
+ @param[in] None
+
+ @retval EFI_SUCCESS The function completed successfully.
+
+**/
+EFI_STATUS
+InitializeScAslUpdateLib (
+ VOID
+ );
+
+/**
+ This procedure will update immediate value assigned to a Name
+
+ @param[in] AslSignature The signature of Operation Region that we want to update.
+ @param[in] Buffer source of data to be written over original aml
+ @param[in] Length length of data to be overwritten
+
+ @retval EFI_SUCCESS The function completed successfully.
+
+**/
+EFI_STATUS
+UpdateNameAslCode(
+ IN UINT32 AslSignature,
+ IN VOID *Buffer,
+ IN UINTN Length
+ );
+
+/**
+ This function locates an ACPI structure and updates it.
+ This function knows how to update operation regions and BUFA/BUFB resource structures.
+
+ This function may not be implemented in all instantiations of this library.
+
+ @param[in] AslSignature The signature of Operation Region that we want to update.
+ @param[in] BufferName signature of the Buffer inside OpRegion that we want to update
+ @param[in] MacroAmlEncoding type of entry inside Buffer.
+ @param[in] MacroEntryNumber number of entry of the above type
+ @param[in] Offset offset (in bytes) inside entry where update will be performed
+ @param[in] Buffer source of data to be written over original aml
+ @param[in] Length length of data to be overwritten
+
+ @retval EFI_SUCCESS The function completed successfully.
+
+**/
+EFI_STATUS
+UpdateResourceTemplateAslCode (
+ IN UINT32 AslSignature,
+ IN UINT32 BufferName,
+ IN UINT8 MacroAmlEncoding,
+ IN UINT8 MacroEntryNumber,
+ IN UINT8 Offset,
+ IN VOID *Buffer,
+ IN UINTN Length
+ );
+
+/**
+ This function uses the ACPI support protocol to locate an ACPI table using the .
+ It is really only useful for finding tables that only have a single instance,
+ e.g. FADT, FACS, MADT, etc. It is not good for locating SSDT, etc.
+ Matches are determined by finding the table with ACPI table that has
+ a matching signature and version.
+
+ @param[in] TableId Pointer to an ASCII string containing the Signature to match
+ @param[in, out] Table Updated with a pointer to the table
+ @param[in, out] Handle AcpiSupport protocol table handle for the table found
+ @param[in, out] Version On input, the version of the table desired,
+ on output, the versions the table belongs to
+ (see AcpiSupport protocol for details)
+
+ @retval EFI_SUCCESS The function completed successfully.
+
+**/
+EFI_STATUS
+LocateAcpiTableBySignature (
+ IN UINT32 Signature,
+ IN OUT EFI_ACPI_DESCRIPTION_HEADER **Table,
+ IN OUT UINTN *Handle,
+ IN OUT EFI_ACPI_TABLE_VERSION *Version
+ );
+
+/**
+ This function uses the ACPI support protocol to locate an ACPI SSDT table.
+ The table is located by searching for a matching OEM Table ID field.
+ Partial match searches are supported via the TableIdSize parameter.
+
+ @param[in] TableId Pointer to an ASCII string containing the OEM Table ID from the ACPI table header
+ @param[in] TableIdSize Length of the TableId to match. Table ID are 8 bytes long, this function
+ will consider it a match if the first TableIdSize bytes match
+ @param[in, out] Table Updated with a pointer to the table
+ @param[in, out] Handle AcpiSupport protocol table handle for the table found
+ @param[in, out] Version See AcpiSupport protocol, GetAcpiTable function for use
+
+ @retval EFI_SUCCESS The function completed successfully.
+
+**/
+EFI_STATUS
+LocateAcpiTableByOemTableId (
+ IN UINT8 *TableId,
+ IN UINT8 TableIdSize,
+ IN OUT EFI_ACPI_DESCRIPTION_HEADER **Table,
+ IN OUT UINTN *Handle,
+ IN OUT EFI_ACPI_TABLE_VERSION *Version
+ );
+
+/**
+ This function calculates and updates an UINT8 checksum.
+
+ @param[in] Buffer Pointer to buffer to checksum
+ @param[in] Size Number of bytes to checksum
+ @param[in] ChecksumOffset Offset to place the checksum result in
+
+ @retval EFI_SUCCESS The function completed successfully.
+
+**/
+EFI_STATUS
+AcpiChecksum (
+ IN VOID *Buffer,
+ IN UINTN Size,
+ IN UINTN ChecksumOffset
+ );
+
+#endif
+
diff --git a/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/SampleCode/Library/AslUpdate/Dxe/ScAslUpdateLib.c b/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/SampleCode/Library/AslUpdate/Dxe/ScAslUpdateLib.c
new file mode 100644
index 0000000000..f82844164a
--- /dev/null
+++ b/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/SampleCode/Library/AslUpdate/Dxe/ScAslUpdateLib.c
@@ -0,0 +1,478 @@
+/** @file
+ Boot service DXE ASL update library implementation.
+ These functions in this file can be called during DXE and cannot be called during runtime
+ or in SMM which should use a RT or SMM library.
+ This library uses the ACPI Support protocol.
+
+ Copyright (c) 2012 - 2016, Intel Corporation. All rights reserved.<BR>
+
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <Library/ScAslUpdateLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/DebugLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+
+//
+// Function implementations
+//
+static EFI_ACPI_SUPPORT_PROTOCOL *mAcpiSupport = NULL;
+static EFI_ACPI_TABLE_PROTOCOL *mAcpiTable = NULL;
+
+
+/**
+ Initialize the ASL update library state.
+ This must be called prior to invoking other library functions.
+
+ @param[in] None
+
+ @retval EFI_SUCCESS The function completed successfully.
+
+**/
+EFI_STATUS
+InitializeScAslUpdateLib (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+
+ //
+ // Locate ACPI tables
+ //
+ Status = gBS->LocateProtocol (&gEfiAcpiSupportProtocolGuid, NULL, (VOID **) &mAcpiSupport);
+ Status = gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, (VOID **) &mAcpiTable);
+ return Status;
+}
+
+
+/**
+ This procedure will update immediate value assigned to a Name
+
+ @param[in] AslSignature The signature of Operation Region that we want to update.
+ @param[in] Buffer source of data to be written over original aml
+ @param[in] Length length of data to be overwritten
+
+ @retval EFI_SUCCESS The function completed successfully.
+
+**/
+EFI_STATUS
+UpdateNameAslCode (
+ IN UINT32 AslSignature,
+ IN VOID *Buffer,
+ IN UINTN Length
+ )
+{
+ EFI_STATUS Status;
+ EFI_ACPI_DESCRIPTION_HEADER *Table;
+ EFI_ACPI_TABLE_VERSION Version;
+ UINT8 *CurrPtr;
+ UINT32 *Signature;
+ UINT8 *DsdtPointer;
+ UINT8 Index;
+ UINTN Handle;
+ UINT8 DataSize;
+
+ //
+ // Locate table with matching ID
+ //
+ Index = 0;
+
+ do {
+ Status = mAcpiSupport->GetAcpiTable (mAcpiSupport, Index, (VOID **) &Table, &Version, &Handle);
+ if (Status == EFI_NOT_FOUND) {
+ break;
+ }
+
+ ASSERT_EFI_ERROR (Status);
+ Index++;
+ } while (Table->Signature != EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE);
+
+ //
+ // Point to the beginning of the DSDT table
+ //
+ Index = 0;
+ CurrPtr = (UINT8 *) Table;
+
+ //
+ // Loop through the ASL looking for values that we must fix up.
+ //
+ for (DsdtPointer = CurrPtr; DsdtPointer <= (CurrPtr + ((EFI_ACPI_COMMON_HEADER *) CurrPtr)->Length); DsdtPointer++) {
+ //
+ // Get a pointer to compare for signature
+ //
+ Signature = (UINT32 *) DsdtPointer;
+ //
+ // Check if this is the Device Object signature we are looking for
+ //
+ if ((*Signature) == AslSignature) {
+ //
+ // Look for Name Encoding
+ //
+ if (*(DsdtPointer - 1) == AML_NAME_OP) {
+ //
+ // Check if size of new and old data is the same
+ //
+ DataSize = *(DsdtPointer + 4);
+ if ((Length == 1 && DataSize == 0xA) ||
+ (Length == 2 && DataSize == 0xB) ||
+ (Length == 4 && DataSize == 0xC) ) {
+ CopyMem (DsdtPointer + 5, Buffer, Length);
+ } else if (Length == 1 && ((*(UINT8 *)Buffer) == 0 || (*(UINT8 *)Buffer) == 1) && (DataSize == 0 || DataSize == 1)) {
+ CopyMem (DsdtPointer + 4, Buffer, Length);
+ } else {
+ FreePool (Table);
+ return EFI_BAD_BUFFER_SIZE;
+ }
+ Status = mAcpiTable->UninstallAcpiTable (
+ mAcpiTable,
+ Handle
+ );
+ Handle = 0;
+ Status = mAcpiTable->InstallAcpiTable (
+ mAcpiTable,
+ Table,
+ Table->Length,
+ &Handle
+ );
+ FreePool (Table);
+ return Status;
+ }
+ }
+ }
+ return EFI_NOT_FOUND;
+}
+
+
+/**
+ This procedure will update a Resource Descriptor Macro in
+ Resrouce Template buffer list.
+
+ @param[in] AslSignature The signature of Operation Region that we want to update.
+ @param[in] BufferName signature of the Buffer inside OpRegion that we want to update
+ @param[in] MacroAmlEncoding type of entry inside Buffer.
+ @param[in] MacroEntryNumber number of entry of the above type
+ @param[in] Offset offset (in bytes) inside entry where update will be performed
+ @param[in] Buffer source of data to be written over original aml
+ @param[in] Length length of data to be overwritten
+
+ @retval EFI_SUCCESS The function completed successfully.
+
+**/
+EFI_STATUS
+UpdateResourceTemplateAslCode (
+ IN UINT32 AslSignature,
+ IN UINT32 BufferName,
+ IN UINT8 MacroAmlEncoding,
+ IN UINT8 MacroEntryNumber,
+ IN UINT8 Offset,
+ IN VOID *Buffer,
+ IN UINTN Length
+ )
+{
+ EFI_STATUS Status;
+ EFI_ACPI_DESCRIPTION_HEADER *Table;
+ EFI_ACPI_TABLE_VERSION Version;
+ UINT8 *CurrPtr;
+ UINT8 *Operation;
+ UINT32 *Signature;
+ UINT8 *DsdtPointer;
+ UINT8 Index;
+ UINT8 *BufferLength;
+ UINTN Handle;
+ UINT16 AslLength;
+ BOOLEAN EntryFound;
+
+ //
+ // Locate table with matching ID
+ //
+ Index = 0;
+ AslLength = 0;
+ EntryFound = FALSE;
+
+ do {
+ Status = mAcpiSupport->GetAcpiTable (mAcpiSupport, Index, (VOID **) &Table, &Version, &Handle);
+ if (Status == EFI_NOT_FOUND) {
+ break;
+ }
+ ASSERT_EFI_ERROR (Status);
+ Index ++;
+ } while (Table->Signature != EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE);
+
+ //
+ // Point to the beginning of the DSDT table
+ //
+ Index = 0;
+ CurrPtr = (UINT8 *) Table;
+
+ //
+ // Loop through the ASL looking for values that we must fix up.
+ //
+ for (DsdtPointer = CurrPtr; DsdtPointer <= (CurrPtr + ((EFI_ACPI_COMMON_HEADER *) CurrPtr)->Length); DsdtPointer++) {
+ //
+ // Get a pointer to compare for signature
+ //
+ Signature = (UINT32 *) DsdtPointer;
+
+ //
+ // Check if this is the Device Object signature we are looking for
+ //
+ if ((*Signature) == AslSignature) {
+ //
+ // Read the Device Object block length
+ //
+ if (*(DsdtPointer - 2) == AML_DEVICE_OP) {
+ AslLength = *(DsdtPointer - 1);
+ } else if (*(DsdtPointer - 3) == AML_DEVICE_OP) {
+ AslLength = *(UINT16 *) (DsdtPointer - 2);
+ AslLength = (AslLength & 0x0F) + ((AslLength & 0x0FF00) >> 4);
+ }
+
+ //
+ // Conditional match. Search AML Encoding in Device.
+ //
+ for (Operation = DsdtPointer; Operation <= DsdtPointer + AslLength; Operation++) {
+ //
+ // Look for Name Encoding
+ //
+ while (Operation <= DsdtPointer + AslLength) {
+ if (*Operation == AML_NAME_OP) {
+ //
+ // Found Name AML Encoding
+ //
+ Operation ++;
+ if (*(UINT32 *) (Operation) == BufferName) {
+ //
+ // Found RBUF Resource Template object name
+ //
+ break;
+ }
+ }
+ Operation++;
+ }
+
+ if (Operation > DsdtPointer + AslLength ) {
+ FreePool (Table);
+ return EFI_NOT_FOUND;
+ }
+
+ //
+ // Now look for the Resource Template Object buffer opcode
+ //
+ while ((*Operation) != AML_BUFFER_OP) {
+ Operation++;
+ if (Operation > DsdtPointer + AslLength) {
+ FreePool (Table);
+ return EFI_NOT_FOUND;
+ }
+ }
+
+ //
+ // In a Resource Template Object the length of buffer
+ // list is 3 bytes after the buffer opcode
+ //
+ Operation += 3;
+ BufferLength = (*Operation) + Operation + 1;
+
+ //
+ // Now look for the Macro to be updated
+ //
+ while (Operation <= BufferLength) {
+ if ((*Operation == MacroAmlEncoding)) {
+ //
+ // We found a matching encoding however, the buffer list may have "n" number
+ // of same encoding entries. Let's narrow down to the "n"th entry.
+ //
+ Index++;
+ if (Index == MacroEntryNumber) {
+ //
+ // Get to the starting offset & end offset
+ //
+ Operation += Offset;
+
+ //
+ // Fixup the value at the offset
+ //
+ CopyMem ((VOID *) Operation, (VOID *) (Buffer), Length);
+
+ //
+ // Update the modified ACPI table
+ //
+ Status = mAcpiTable->UninstallAcpiTable (
+ mAcpiTable,
+ Handle
+ );
+ Handle = 0;
+ Status = mAcpiTable->InstallAcpiTable (
+ mAcpiTable,
+ Table,
+ Table->Length,
+ &Handle
+ );
+ FreePool (Table);
+ return Status;
+ }
+ }
+ Operation++;
+ }
+
+ if (Operation > DsdtPointer + AslLength) {
+ FreePool (Table);
+ return EFI_NOT_FOUND;
+ }
+ }
+ }
+ }
+
+ return EFI_NOT_FOUND;
+}
+
+
+/**
+ This function uses the ACPI support protocol to locate an ACPI table.
+ It is really only useful for finding tables that only have a single instance,
+ e.g. FADT, FACS, MADT, etc. It is not good for locating SSDT, etc.
+
+ @param[in] Signature Pointer to an ASCII string containing the OEM Table ID from the ACPI table header
+ @param[in, out] Table Updated with a pointer to the table
+ @param[in, out] Handle AcpiSupport protocol table handle for the table found
+ @param[in, out] Version The version of the table desired
+
+ @retval EFI_SUCCESS The function completed successfully.
+
+**/
+EFI_STATUS
+LocateAcpiTableBySignature (
+ IN UINT32 Signature,
+ IN OUT EFI_ACPI_DESCRIPTION_HEADER **Table,
+ IN OUT UINTN *Handle,
+ IN OUT EFI_ACPI_TABLE_VERSION *Version
+ )
+{
+ EFI_STATUS Status;
+ INTN Index;
+ EFI_ACPI_TABLE_VERSION DesiredVersion;
+
+ DesiredVersion = *Version;
+
+ //
+ // Locate table with matching ID
+ //
+ Index = 0;
+ do {
+ Status = mAcpiSupport->GetAcpiTable (mAcpiSupport, Index, (VOID **) Table, Version, Handle);
+ if (Status == EFI_NOT_FOUND) {
+ break;
+ }
+
+ ASSERT_EFI_ERROR (Status);
+ Index++;
+ } while ((*Table)->Signature != Signature || !(*Version & DesiredVersion));
+
+ //
+ // If we found the table, there will be no error.
+ //
+ return Status;
+}
+
+
+/**
+ This function uses the ACPI support protocol to locate an ACPI SSDT table.
+
+ @param[in] TableId Pointer to an ASCII string containing the OEM Table ID from the ACPI table header
+ @param[in] TableIdSize Length of the TableId to match. Table ID are 8 bytes long, this function
+ will consider it a match if the first TableIdSize bytes match
+ @param[in, out] Table Updated with a pointer to the table
+ @param[in, out] Handle AcpiSupport protocol table handle for the table found
+ @param[in, out] Version See AcpiSupport protocol, GetAcpiTable function for use
+
+ @retval EFI_SUCCESS The function completed successfully.
+
+**/
+EFI_STATUS
+LocateAcpiTableByOemTableId (
+ IN UINT8 *TableId,
+ IN UINT8 TableIdSize,
+ IN OUT EFI_ACPI_DESCRIPTION_HEADER **Table,
+ IN OUT UINTN *Handle,
+ IN OUT EFI_ACPI_TABLE_VERSION *Version
+ )
+{
+ EFI_STATUS Status;
+ INTN Index;
+
+ //
+ // Locate table with matching ID
+ //
+ Index = 0;
+ do {
+ Status = mAcpiSupport->GetAcpiTable (mAcpiSupport, Index, (VOID **) Table, Version, Handle);
+ if (Status == EFI_NOT_FOUND) {
+ break;
+ }
+
+ ASSERT_EFI_ERROR (Status);
+ Index++;
+ } while (CompareMem (&(*Table)->OemTableId, TableId, TableIdSize));
+
+ //
+ // If we found the table, there will be no error.
+ //
+ return Status;
+}
+
+
+/**
+ This function calculates and updates an UINT8 checksum.
+
+ @param[in] Buffer Pointer to buffer to checksum
+ @param[in] Size Number of bytes to checksum
+ @param[in] ChecksumOffset Offset to place the checksum result in
+
+ @retval EFI_SUCCESS The function completed successfully.
+
+**/
+EFI_STATUS
+AcpiChecksum (
+ IN VOID *Buffer,
+ IN UINTN Size,
+ IN UINTN ChecksumOffset
+ )
+{
+ UINT8 Sum;
+ UINT8 *Ptr;
+
+ Sum = 0;
+ //
+ // Initialize pointer
+ //
+ Ptr = Buffer;
+
+ //
+ // set checksum to 0 first
+ //
+ Ptr[ChecksumOffset] = 0;
+
+ //
+ // add all content of buffer
+ //
+ while (Size--) {
+ Sum = (UINT8) (Sum + (*Ptr++));
+ }
+ //
+ // set checksum
+ //
+ Ptr = Buffer;
+ Ptr[ChecksumOffset] = (UINT8) (0xff - Sum + 1);
+
+ return EFI_SUCCESS;
+}
+
diff --git a/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/SampleCode/Library/AslUpdate/Dxe/ScAslUpdateLib.inf b/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/SampleCode/Library/AslUpdate/Dxe/ScAslUpdateLib.inf
new file mode 100644
index 0000000000..02dc702bd5
--- /dev/null
+++ b/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/SampleCode/Library/AslUpdate/Dxe/ScAslUpdateLib.inf
@@ -0,0 +1,37 @@
+## @file
+# DXE SC ASL Update Lib.
+#
+# Copyright (c) 2012 - 2016, Intel Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php.
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+##
+
+[defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = ScAslUpdateLib
+ FILE_GUID = 3C374A8D-E9A1-49A8-968C-AB4F07D56613
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = ScAslUpdateLib
+
+[sources.common]
+ ScAslUpdateLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ BroxtonSiPkg/SouthCluster/SampleCode/SampleCode.dec
+ BroxtonSiPkg/BroxtonSiPkg.dec
+
+[LibraryClasses]
+ DebugLib
+ IoLib
+
+[Protocols]
+ gEfiAcpiSupportProtocolGuid ## CONSUMES
diff --git a/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/SampleCode/SampleCode.dec b/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/SampleCode/SampleCode.dec
new file mode 100644
index 0000000000..5d1738b780
--- /dev/null
+++ b/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/SampleCode/SampleCode.dec
@@ -0,0 +1,31 @@
+## @file
+# Module describe the entire platform configuration.
+#
+# Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php.
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+##
+
+[Defines]
+ DEC_SPECIFICATION = 0x00010005
+ PACKAGE_NAME = SampleCode
+ PACKAGE_GUID = 7200a805-b9f9-4d37-8bb6-7ea74c9c7f8d
+ PACKAGE_VERSION = 0.1
+
+[Includes]
+ Include
+
+[Protocols]
+
+[Ppis]
+ gPeiUsbControllerPpiGuid = {0x3bc1f6de, 0x693e, 0x4547, {0xa3, 0x0, 0x21, 0x82, 0x3c, 0xa4, 0x20, 0xb2}}
+
+[Guids]
+