From b7c51c9cf4864df6aabb99a1ae843becd577237c Mon Sep 17 00:00:00 2001 From: raywu Date: Fri, 15 Jun 2018 00:00:50 +0800 Subject: init. 1AQQW051 --- .../Library/Dxe/EfiRegTableLib/EfiRegTableLib.c | 313 +++++++++++++++++++++ .../Library/Dxe/EfiRegTableLib/EfiRegTableLib.cif | 10 + .../Library/Dxe/EfiRegTableLib/EfiRegTableLib.mak | 80 ++++++ .../Library/Dxe/EfiRegTableLib/EfiRegTableLib.sdl | 36 +++ .../Smm/EfiSmmDriverLib/EfiSmmDriverLib.cif | 12 + .../Smm/EfiSmmDriverLib/EfiSmmDriverLib.mak | 70 +++++ .../Smm/EfiSmmDriverLib/EfiSmmDriverLib.sdl | 36 +++ .../Library/Smm/EfiSmmDriverLib/LibGlobals.c | 45 +++ .../Library/Smm/EfiSmmDriverLib/SmmDriverLib.c | 244 ++++++++++++++++ MiscFramework/Library/Smm/EfiSmmDriverLib/debug.c | 169 +++++++++++ 10 files changed, 1015 insertions(+) create mode 100644 MiscFramework/Library/Dxe/EfiRegTableLib/EfiRegTableLib.c create mode 100644 MiscFramework/Library/Dxe/EfiRegTableLib/EfiRegTableLib.cif create mode 100644 MiscFramework/Library/Dxe/EfiRegTableLib/EfiRegTableLib.mak create mode 100644 MiscFramework/Library/Dxe/EfiRegTableLib/EfiRegTableLib.sdl create mode 100644 MiscFramework/Library/Smm/EfiSmmDriverLib/EfiSmmDriverLib.cif create mode 100644 MiscFramework/Library/Smm/EfiSmmDriverLib/EfiSmmDriverLib.mak create mode 100644 MiscFramework/Library/Smm/EfiSmmDriverLib/EfiSmmDriverLib.sdl create mode 100644 MiscFramework/Library/Smm/EfiSmmDriverLib/LibGlobals.c create mode 100644 MiscFramework/Library/Smm/EfiSmmDriverLib/SmmDriverLib.c create mode 100644 MiscFramework/Library/Smm/EfiSmmDriverLib/debug.c (limited to 'MiscFramework/Library') diff --git a/MiscFramework/Library/Dxe/EfiRegTableLib/EfiRegTableLib.c b/MiscFramework/Library/Dxe/EfiRegTableLib/EfiRegTableLib.c new file mode 100644 index 0000000..ee8afab --- /dev/null +++ b/MiscFramework/Library/Dxe/EfiRegTableLib/EfiRegTableLib.c @@ -0,0 +1,313 @@ +/*++ + 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 +--*/ +/*++ + +Copyright (c) 1999 - 2003 Intel Corporation. All rights reserved +This software and associated documentation (if any) is furnished +under a license and may only be used or copied in accordance +with the terms of the license. Except as permitted by such +license, no part of this software or documentation may be +reproduced, stored in a retrieval system, or transmitted in any +form or by any means without the express written consent of +Intel Corporation. + + +Module Name: + + EfiRegTableLib.c + +Abstract: + + Lib function for table driven register initialization. + +Revision History + +--*/ + +#include "Tiano.h" +#include "EfiDriverLib.h" +#include "EfiRegTableLib.h" +#include "EfiDebug.h" + +// +// Local Functions +// +STATIC +VOID +PciWrite ( + EFI_REG_TABLE_PCI_WRITE *Entry, + EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo + ) +/*++ + +Routine Description: + Local worker function to process PCI_WRITE table entries. Performs write and + may also call BootScriptSave protocol if indicated in the Entry flags + +Arguments: + Entry - A pointer to the PCI_WRITE entry to process + + PciRootBridgeIo - A pointer to the instance of PciRootBridgeIo that is used + when processing the entry. + +Returns: + Nothing. + +--*/ +{ + EFI_STATUS Status; + + Status = PciRootBridgeIo->Pci.Write ( + PciRootBridgeIo, + (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) (OPCODE_EXTRA_DATA (Entry->OpCode)), + (UINT64) Entry->PciAddress, + 1, + &Entry->Data + ); + ASSERT_EFI_ERROR (Status); + + if (OPCODE_FLAGS (Entry->OpCode) & OPCODE_FLAG_S3SAVE) { + Status = BootScriptSavePciCfgWrite ( + EFI_ACPI_S3_RESUME_SCRIPT_TABLE, + (EFI_BOOT_SCRIPT_WIDTH) (OPCODE_EXTRA_DATA (Entry->OpCode)), + (UINT64) Entry->PciAddress, + 1, + &Entry->Data + ); + ASSERT_EFI_ERROR (Status); + } +} + +STATIC +VOID +PciReadModifyWrite ( + EFI_REG_TABLE_PCI_READ_MODIFY_WRITE *Entry, + EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo + ) +/*++ + +Routine Description: + Local worker function to process PCI_READ_MODIFY_WRITE table entries. + Performs RMW write and may also call BootScriptSave protocol if indicated in + the Entry flags. + +Arguments: + Entry - A pointer to the PCI_READ_MODIFY_WRITE entry to process. + + PciRootBridgeIo - A pointer to the instance of PciRootBridgeIo that is used + when processing the entry. + +Returns: + Nothing. + +--*/ +{ + EFI_STATUS Status; + UINT32 TempData; + + Status = PciRootBridgeIo->Pci.Read ( + PciRootBridgeIo, + (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) (OPCODE_EXTRA_DATA (Entry->OpCode)), + (UINT64) Entry->PciAddress, + 1, + &TempData + ); + ASSERT_EFI_ERROR (Status); + + Entry->OrMask &= Entry->AndMask; + TempData &= ~Entry->AndMask; + TempData |= Entry->OrMask; + + Status = PciRootBridgeIo->Pci.Write ( + PciRootBridgeIo, + (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) (OPCODE_EXTRA_DATA (Entry->OpCode)), + (UINT64) Entry->PciAddress, + 1, + &TempData + ); + ASSERT_EFI_ERROR (Status); + + if (OPCODE_FLAGS (Entry->OpCode) & OPCODE_FLAG_S3SAVE) { + Status = BootScriptSavePciCfgReadWrite ( + EFI_ACPI_S3_RESUME_SCRIPT_TABLE, + (EFI_BOOT_SCRIPT_WIDTH) (OPCODE_EXTRA_DATA (Entry->OpCode)), + (UINT64) Entry->PciAddress, + &Entry->OrMask, + &Entry->AndMask + ); + ASSERT_EFI_ERROR (Status); + } +} + +STATIC +VOID +MemReadModifyWrite ( + EFI_REG_TABLE_MEM_READ_MODIFY_WRITE *Entry, + EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo + ) +/*++ + +Routine Description: + Local worker function to process MEM_READ_MODIFY_WRITE table entries. + Performs RMW write and may also call BootScriptSave protocol if indicated in + the Entry flags. + +Arguments: + Entry - A pointer to the MEM_READ_MODIFY_WRITE entry to process. + + PciRootBridgeIo - A pointer to the instance of PciRootBridgeIo that is used + when processing the entry. + +Returns: + Nothing. + +--*/ +{ + EFI_STATUS Status; + UINT32 TempData; + + Status = PciRootBridgeIo->Mem.Read ( + PciRootBridgeIo, + (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) (OPCODE_EXTRA_DATA (Entry->OpCode)), + (UINT64) Entry->MemAddress, + 1, + &TempData + ); + ASSERT_EFI_ERROR (Status); + + Entry->OrMask &= Entry->AndMask; + TempData &= ~Entry->AndMask; + TempData |= Entry->OrMask; + + Status = PciRootBridgeIo->Mem.Write ( + PciRootBridgeIo, + (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) (OPCODE_EXTRA_DATA (Entry->OpCode)), + (UINT64) Entry->MemAddress, + 1, + &TempData + ); + ASSERT_EFI_ERROR (Status); + + if (OPCODE_FLAGS (Entry->OpCode) & OPCODE_FLAG_S3SAVE) { + Status = BootScriptSaveMemReadWrite ( + EFI_ACPI_S3_RESUME_SCRIPT_TABLE, + (EFI_BOOT_SCRIPT_WIDTH) (OPCODE_EXTRA_DATA (Entry->OpCode)), + Entry->MemAddress, + &Entry->OrMask, + &Entry->AndMask + ); + ASSERT_EFI_ERROR (Status); + } +} +// +// Exported functions +// +VOID +ProcessRegTablePci ( + EFI_REG_TABLE *RegTableEntry, + EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo, + EFI_CPU_IO_PROTOCOL *CpuIo + ) +/*++ + +Routine Description: + Processes register table assuming which may contain PCI, IO, MEM, and STALL + entries. + + No parameter checking is done so the caller must be careful about omitting + values for PciRootBridgeIo or CpuIo parameters. If the regtable does + not contain any PCI accesses, it is safe to omit the PciRootBridgeIo (supply + NULL). If the regtable does not contain any IO or Mem entries, it is safe to + omit the CpuIo (supply NULL). + + The RegTableEntry parameter is not checked, but is required. + + gBS is assumed to have been defined and is used when processing stalls. + + The function processes each entry sequentially until an OP_TERMINATE_TABLE + entry is encountered. + +Arguments: + RegTableEntry - A pointer to the register table to process + + PciRootBridgeIo - A pointer to the instance of PciRootBridgeIo that is used + when processing PCI table entries + + CpuIo - A pointer to the instance of CpuIo that is used when processing IO and + MEM table entries + +Returns: + Nothing. + +--*/ +{ + while (OPCODE_BASE (RegTableEntry->Generic.OpCode) != OP_TERMINATE_TABLE) { + switch (OPCODE_BASE (RegTableEntry->Generic.OpCode)) { + case OP_PCI_WRITE: + PciWrite ((EFI_REG_TABLE_PCI_WRITE *) RegTableEntry, PciRootBridgeIo); + break; + + case OP_PCI_READ_MODIFY_WRITE: + PciReadModifyWrite ((EFI_REG_TABLE_PCI_READ_MODIFY_WRITE *) RegTableEntry, PciRootBridgeIo); + break; + + case OP_MEM_READ_MODIFY_WRITE: + MemReadModifyWrite ((EFI_REG_TABLE_MEM_READ_MODIFY_WRITE *) RegTableEntry, PciRootBridgeIo); + break; + + default: + DEBUG ((EFI_D_ERROR, "RegTable ERROR: Unknown RegTable OpCode (%x)\n", OPCODE_BASE (RegTableEntry->Generic.OpCode))); + ASSERT (0); + break; + } + + RegTableEntry++; + } +} + +VOID +ProcessRegTableCpu ( + EFI_REG_TABLE *RegTableEntry, + EFI_CPU_IO_PROTOCOL *CpuIo + ) +/*++ + +Routine Description: + Processes register table assuming which may contain IO, MEM, and STALL + entries, but must NOT contain any PCI entries. Any PCI entries cause an + ASSERT in a DEBUG build and are skipped in a free build. + + No parameter checking is done. Both RegTableEntry and CpuIo parameters are + required. + + gBS is assumed to have been defined and is used when processing stalls. + + The function processes each entry sequentially until an OP_TERMINATE_TABLE + entry is encountered. + +Arguments: + RegTableEntry - A pointer to the register table to process + + CpuIo - A pointer to the instance of CpuIo that is used when processing IO and + MEM table entries + +Returns: + Nothing. + +--*/ +{ + while (OPCODE_BASE (RegTableEntry->Generic.OpCode) != OP_TERMINATE_TABLE) { + switch (OPCODE_BASE (RegTableEntry->Generic.OpCode)) { + default: + DEBUG ((EFI_D_ERROR, "RegTable ERROR: Unknown RegTable OpCode (%x)\n", OPCODE_BASE (RegTableEntry->Generic.OpCode))); + ASSERT (0); + break; + } + + RegTableEntry++; + } +} diff --git a/MiscFramework/Library/Dxe/EfiRegTableLib/EfiRegTableLib.cif b/MiscFramework/Library/Dxe/EfiRegTableLib/EfiRegTableLib.cif new file mode 100644 index 0000000..d3e2fc4 --- /dev/null +++ b/MiscFramework/Library/Dxe/EfiRegTableLib/EfiRegTableLib.cif @@ -0,0 +1,10 @@ + + name = "EfiRegTableLib" + category = ModulePart + LocalRoot = "MiscFramework\Library\Dxe\EfiRegTableLib" + RefName = "EfiRegTableLib" +[files] +"EfiRegTableLib.sdl" +"EfiRegTableLib.mak" +"EfiRegTableLib.c" + diff --git a/MiscFramework/Library/Dxe/EfiRegTableLib/EfiRegTableLib.mak b/MiscFramework/Library/Dxe/EfiRegTableLib/EfiRegTableLib.mak new file mode 100644 index 0000000..4c7f8fa --- /dev/null +++ b/MiscFramework/Library/Dxe/EfiRegTableLib/EfiRegTableLib.mak @@ -0,0 +1,80 @@ +#********************************************************************** +#********************************************************************** +#** ** +#** (C)Copyright 1985-2006, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 6145-F Northbelt Pkwy, Norcross, GA 30071 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#********************************************************************** +#********************************************************************** + +#********************************************************************** +# $Header: /Alaska/SOURCE/Modules/MPG/Calpella/MiscFramework/EfiRegTableLib/EfiRegTableLib.mak 1 10/15/08 2:19p Fasihm $ +# +# $Revision: 1 $ +# +# $Date: 10/15/08 2:19p $ +#********************************************************************** +# Revision History +# ---------------- +# $Log: /Alaska/SOURCE/Modules/MPG/Calpella/MiscFramework/EfiRegTableLib/EfiRegTableLib.mak $ +# +# 1 10/15/08 2:19p Fasihm +# Initial check-in for the Calpella Crb MiscFramework module used. +# +# 1 8/26/08 2:08p Fasihm +# This is the first CRB drop used for the PowerOn of the Calpella CRB +# platform (RedFort) +# With this project one needs to add the correct CPU Microcodes. +# +# 2 9/11/06 7:20p Fasihm +# Changed the CFLAGS to MY_LIBRARY for the Build process. +# +# 1 6/27/06 6:06p Felixp +# +# 1 6/05/06 6:31p Fasihm +# Initial check-in for the MiscFramework module placed in the Edk part on +# SSF. +# +# 1 5/12/06 3:12p Felixp +# +#********************************************************************** +# +# +# Name: EfiRegTableLib.mak +# +# Description: +# +# +#********************************************************************** +Framework : EfiRegTableLib + +$(BUILD_DIR)\EfiRegTableLib.lib : EfiRegTableLib + +EfiRegTableLib : $(BUILD_DIR)\EfiRegTableLib.mak EfiRegTableLibBin + +$(BUILD_DIR)\EfiRegTableLib.mak : $(EfiRegTableLib_DIR)\$(@B).cif $(EfiRegTableLib_DIR)\$(@B).mak $(BUILD_RULES) + $(CIF2MAK) $(EfiRegTableLib_DIR)\$(@B).cif $(CIF2MAK_DEFAULTS) + +EfiRegTableLibBin : + $(MAKE) /$(MAKEFLAGS) $(EDK_DEFAULTS)\ + /f $(BUILD_DIR)\EfiRegTableLib.mak all\ + "MY_INCLUDES=$(EDK_INCLUDES) $(MISCFRAMEWORK_INCLUDES)" \ + TYPE=LIBRARY \ +#********************************************************************** +#********************************************************************** +#** ** +#** (C)Copyright 1985-2006, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 6145-F Northbelt Pkwy, Norcross, GA 30071 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#********************************************************************** +#********************************************************************** \ No newline at end of file diff --git a/MiscFramework/Library/Dxe/EfiRegTableLib/EfiRegTableLib.sdl b/MiscFramework/Library/Dxe/EfiRegTableLib/EfiRegTableLib.sdl new file mode 100644 index 0000000..fdacee8 --- /dev/null +++ b/MiscFramework/Library/Dxe/EfiRegTableLib/EfiRegTableLib.sdl @@ -0,0 +1,36 @@ +TOKEN + Name = "EfiRegTableLib_SUPPORT" + Value = "1" + Help = "Main switch to enable EfiRegTableLib support in Project" + TokenType = Boolean + TargetEQU = Yes + TargetMAK = Yes + Master = Yes +End + +TOKEN + Name = "EfiRegTableLib" + Value = "$(BUILD_DIR)\EfiRegTableLib.lib" + TokenType = Expression + TargetMAK = Yes +End + +PATH + Name = "EfiRegTableLib_DIR" +End + +MODULE + Help = "Includes EfiRegTableLib.mak to Project" + File = "EfiRegTableLib.mak" +End + +ELINK + Name = "EfiRegTable_LIB" + InvokeOrder = ReplaceParent +End + +ELINK + Name = "$(BUILD_DIR)\EfiRegTable.lib" + Parent = "EfiRegTable_LIB" + InvokeOrder = AfterParent +End \ No newline at end of file diff --git a/MiscFramework/Library/Smm/EfiSmmDriverLib/EfiSmmDriverLib.cif b/MiscFramework/Library/Smm/EfiSmmDriverLib/EfiSmmDriverLib.cif new file mode 100644 index 0000000..d908ace --- /dev/null +++ b/MiscFramework/Library/Smm/EfiSmmDriverLib/EfiSmmDriverLib.cif @@ -0,0 +1,12 @@ + + name = "EfiSmmDriverLib" + category = ModulePart + LocalRoot = "MiscFramework\Library\Smm\EfiSmmDriverLib" + RefName = "EfiSmmDriverLib" +[files] +"EfiSmmDriverLib.sdl" +"EfiSmmDriverLib.mak" +"SmmDriverLib.c" +"LibGlobals.c" +"debug.c" + diff --git a/MiscFramework/Library/Smm/EfiSmmDriverLib/EfiSmmDriverLib.mak b/MiscFramework/Library/Smm/EfiSmmDriverLib/EfiSmmDriverLib.mak new file mode 100644 index 0000000..6a52cc0 --- /dev/null +++ b/MiscFramework/Library/Smm/EfiSmmDriverLib/EfiSmmDriverLib.mak @@ -0,0 +1,70 @@ +#********************************************************************** +#********************************************************************** +#** ** +#** (C)Copyright 1985-2006, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 6145-F Northbelt Pkwy, Norcross, GA 30071 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#********************************************************************** +#********************************************************************** + +#********************************************************************** +# $Header: /Alaska/SOURCE/Modules/MPG/Calpella/MiscFramework/EfiSmmDriverLib/EfiSmmDriverLib.mak 1 10/15/08 2:20p Fasihm $ +# +# $Revision: 1 $ +# +# $Date: 10/15/08 2:20p $ +#********************************************************************** +# Revision History +# ---------------- +# $Log: /Alaska/SOURCE/Modules/MPG/Calpella/MiscFramework/EfiSmmDriverLib/EfiSmmDriverLib.mak $ +# +# 1 10/15/08 2:20p Fasihm +# Initial check-in for the Calpella Crb MiscFramework module. +# +# 1 8/26/08 2:08p Fasihm +# This is the first CRB drop used for the PowerOn of the Calpella CRB +# platform (RedFort) +# With this project one needs to add the correct CPU Microcodes. +# +# +#********************************************************************** +# +# +# Name: EfiSmmDriverLib.mak +# +# Description: +# +# +#********************************************************************** +Framework : EfiSmmDriverLib + +$(BUILD_DIR)\EfiSmmDriverLib.lib : EfiSmmDriverLib + +EfiSmmDriverLib : $(BUILD_DIR)\EfiSmmDriverLib.mak EfiSmmDriverLibBin + +$(BUILD_DIR)\EfiSmmDriverLib.mak : $(EfiSmmDriverLib_DIR)\$(@B).cif $(EfiSmmDriverLib_DIR)\$(@B).mak $(BUILD_RULES) + $(CIF2MAK) $(EfiSmmDriverLib_DIR)\$(@B).cif $(CIF2MAK_DEFAULTS) + +EfiSmmDriverLibBin : + $(MAKE) /$(MAKEFLAGS) $(EDK_DEFAULTS)\ + /f $(BUILD_DIR)\EfiSmmDriverLib.mak all\ + "MY_INCLUDES=$(EDK_INCLUDES) $(MISCFRAMEWORK_INCLUDES)" \ + TYPE=LIBRARY \ +#********************************************************************** +#********************************************************************** +#** ** +#** (C)Copyright 1985-2006, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 6145-F Northbelt Pkwy, Norcross, GA 30071 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#********************************************************************** +#********************************************************************** \ No newline at end of file diff --git a/MiscFramework/Library/Smm/EfiSmmDriverLib/EfiSmmDriverLib.sdl b/MiscFramework/Library/Smm/EfiSmmDriverLib/EfiSmmDriverLib.sdl new file mode 100644 index 0000000..6234397 --- /dev/null +++ b/MiscFramework/Library/Smm/EfiSmmDriverLib/EfiSmmDriverLib.sdl @@ -0,0 +1,36 @@ +TOKEN + Name = "EfiSmmDriverLib_SUPPORT" + Value = "1" + Help = "Main switch to enable EfiSmmDriverLib support in Project" + TokenType = Boolean + TargetEQU = Yes + TargetMAK = Yes + Master = Yes +End + +TOKEN + Name = "EfiSmmDriverLib" + Value = "$(BUILD_DIR)\EfiSmmDriverLib.lib" + TokenType = Expression + TargetMAK = Yes +End + +MODULE + Help = "Includes EfiSmmDriverLib.mak to Project" + File = "EfiSmmDriverLib.mak" +End + +PATH + Name = "EfiSmmDriverLib_DIR" +End + +ELINK + Name = "EfiSmmDriverLib_LIB" + InvokeOrder = ReplaceParent +End + +ELINK + Name = "$(BUILD_DIR)\EfiSmmDriverLib.lib" + Parent = "EfiSmmDriverLib_LIB" + InvokeOrder = AfterParent +End \ No newline at end of file diff --git a/MiscFramework/Library/Smm/EfiSmmDriverLib/LibGlobals.c b/MiscFramework/Library/Smm/EfiSmmDriverLib/LibGlobals.c new file mode 100644 index 0000000..b163e98 --- /dev/null +++ b/MiscFramework/Library/Smm/EfiSmmDriverLib/LibGlobals.c @@ -0,0 +1,45 @@ +/*++ + This file contains 'Framework Code' and is licensed as such + under the terms of your license agreement with Intel or your + vendor. This file may not be modified, except as allowed by + additional terms of your license agreement. +--*/ +/*++ + +Copyright (c) 1999 - 2002 Intel Corporation. All rights reserved +This software and associated documentation (if any) is furnished +under a license and may only be used or copied in accordance +with the terms of the license. Except as permitted by such +license, no part of this software or documentation may be +reproduced, stored in a retrieval system, or transmitted in any +form or by any means without the express written consent of +Intel Corporation. + + +Module Name: + + LibGlobals.c + +Abstract: + + Globals used in EFI SMM Driver Lib. They are initialized in EfiSmmDriverLib.c. + Each seperatly linked module has it's own copy of these globals. + + gBS - Boot Services table pointer + gRT - Runt Time services table pointer + gST - System Table pointer + + gErrorLevel - Debug error level. + +--*/ + +#include "Tiano.h" +#include EFI_PROTOCOL_DEFINITION (SmmBase) +#include EFI_PROTOCOL_DEFINITION (SmmStatusCode) + +EFI_BOOT_SERVICES *gBS; +EFI_RUNTIME_SERVICES *gRT; +EFI_SYSTEM_TABLE *gST; +EFI_SMM_BASE_PROTOCOL *gSMM; +EFI_SMM_STATUS_CODE_PROTOCOL *mSmmDebug; +UINTN gErrorLevel = EFI_DBUG_MASK | EFI_D_LOAD; diff --git a/MiscFramework/Library/Smm/EfiSmmDriverLib/SmmDriverLib.c b/MiscFramework/Library/Smm/EfiSmmDriverLib/SmmDriverLib.c new file mode 100644 index 0000000..bb3d8de --- /dev/null +++ b/MiscFramework/Library/Smm/EfiSmmDriverLib/SmmDriverLib.c @@ -0,0 +1,244 @@ +/*++ + This file contains 'Framework Code' and is licensed as such + under the terms of your license agreement with Intel or your + vendor. This file may not be modified, except as allowed by + additional terms of your license agreement. +--*/ +/*++ + +Copyright (c) 1999 - 2002 Intel Corporation. All rights reserved +This software and associated documentation (if any) is furnished +under a license and may only be used or copied in accordance +with the terms of the license. Except as permitted by such +license, no part of this software or documentation may be +reproduced, stored in a retrieval system, or transmitted in any +form or by any means without the express written consent of +Intel Corporation. + + +Module Name: + + MgmtModeRuntimeUtils.c + +Abstract: + + Light weight lib to support EFI 2.0 SMM based drivers. + +--*/ + +// GC_TODO: fix comment to set correct module name: SmmDriverLib.c +#include "Tiano.h" +#include "EfiCommonLib.h" +#include "EfiSmmDriverLib.h" +#include EFI_PROTOCOL_DEFINITION (LoadedImage) + +EFI_DEVICE_PATH_PROTOCOL * +EfiAppendDevicePath ( + IN EFI_DEVICE_PATH_PROTOCOL *Src1, + IN EFI_DEVICE_PATH_PROTOCOL *Src2 + ); + +EFI_STATUS +EfiInitializeSmmDriverLib ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable, + IN OUT BOOLEAN *InSmm + ) +/*++ + +Routine Description: + + Intialize runtime Driver Lib if it has not yet been initialized. + +Arguments: + + (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT) + + GoVirtualChildEvent - Caller can register a virtual notification event. + +Returns: + + EFI_STATUS always returns EFI_SUCCESS + +--*/ +// GC_TODO: ImageHandle - add argument and description to function comment +// GC_TODO: SystemTable - add argument and description to function comment +// GC_TODO: InSmm - add argument and description to function comment +{ + EFI_STATUS Status; + EFI_HANDLE Handle; + EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; + EFI_DEVICE_PATH_PROTOCOL *CompleteFilePath; + EFI_DEVICE_PATH_PROTOCOL *ImageDevicePath; + + gSMM = NULL; + mSmmDebug = NULL; + + if ((SystemTable != NULL) && (SystemTable->BootServices != NULL)) { + + gST = SystemTable; + gBS = SystemTable->BootServices; + gRT = SystemTable->RuntimeServices; + + // + // It is OK if the SmmStatusCode Protocol is not found, don't check the status. + // + Status = gBS->LocateProtocol (&gEfiSmmStatusCodeProtocolGuid, NULL, &mSmmDebug); + + Status = gBS->LocateProtocol (&gEfiSmmBaseProtocolGuid, NULL, &gSMM); + if (EFI_ERROR (Status)) { + return Status; + } + + gSMM->InSmm (gSMM, InSmm); + + if (!(*InSmm)) { + // + // Not in SMM, initialization code is running under DXE environment + // + // + // Load this driver's image to memory + // + if (ImageHandle != NULL) { + Status = gBS->HandleProtocol ( + ImageHandle, + &gEfiLoadedImageProtocolGuid, + (VOID *) &LoadedImage + ); + + if (EFI_ERROR (Status)) { + return Status; + } + + gBS->HandleProtocol ( + LoadedImage->DeviceHandle, + &gEfiDevicePathProtocolGuid, + (VOID *) &ImageDevicePath + ); + + if (EFI_ERROR (Status)) { + return Status; + } + + CompleteFilePath = EfiAppendDevicePath ( + ImageDevicePath, + LoadedImage->FilePath + ); + // + // Load the image in memory to SMRAM; it will automatically generate the + // SMI. + // + Status = gSMM->Register (gSMM, CompleteFilePath, NULL, 0, &Handle, FALSE); + if (EFI_ERROR (Status)) { + return Status; + } + } + } + } + + return EFI_SUCCESS; + +} + +UINTN +EfiDevicePathSize ( + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath + ) +/*++ + +Routine Description: + + GC_TODO: Add function description + +Arguments: + + DevicePath - GC_TODO: add argument description + +Returns: + + GC_TODO: add return values + +--*/ +{ + EFI_DEVICE_PATH_PROTOCOL *Start; + + if (NULL == DevicePath) { + return 0; + } + // + // Search for the end of the device path structure + // + Start = DevicePath; + while (!EfiIsDevicePathEnd (DevicePath)) { + DevicePath = EfiNextDevicePathNode (DevicePath); + } + // + // Compute the size and add back in the size of the end device path structure + // + return ((UINTN) DevicePath - (UINTN) Start) + sizeof (EFI_DEVICE_PATH_PROTOCOL); +} + +EFI_DEVICE_PATH_PROTOCOL * +EfiAppendDevicePath ( + IN EFI_DEVICE_PATH_PROTOCOL *Src1, + IN EFI_DEVICE_PATH_PROTOCOL *Src2 + ) +/*++ + +Routine Description: + Function is used to append a Src1 and Src2 together. + +Arguments: + Src1 - A pointer to a device path data structure. + + Src2 - A pointer to a device path data structure. + +Returns: + + A pointer to the new device path is returned. + NULL is returned if space for the new device path could not be allocated from pool. + It is up to the caller to free the memory used by Src1 and Src2 if they are no longer needed. + +--*/ +{ + EFI_STATUS Status; + UINTN Size; + UINTN Size1; + UINTN Size2; + EFI_DEVICE_PATH_PROTOCOL *NewDevicePath; + EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath; + + // + // Allocate space for the combined device path. It only has one end node of + // length EFI_DEVICE_PATH_PROTOCOL + // + Size1 = EfiDevicePathSize (Src1); + Size2 = EfiDevicePathSize (Src2); + Size = Size1 + Size2; + + if (Size1 != 0 && Size2 != 0) { + Size -= sizeof (EFI_DEVICE_PATH_PROTOCOL); + } + + Status = gBS->AllocatePool (EfiBootServicesData, Size, (VOID **) &NewDevicePath); + + if (EFI_ERROR (Status)) { + return NULL; + } + + gBS->CopyMem (NewDevicePath, Src1, Size1); + + // + // Over write Src1 EndNode and do the copy + // + if (Size1 != 0) { + SecondDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) ((CHAR8 *) NewDevicePath + (Size1 - sizeof (EFI_DEVICE_PATH_PROTOCOL))); + } else { + SecondDevicePath = NewDevicePath; + + } + + gBS->CopyMem (SecondDevicePath, Src2, Size2); + + return NewDevicePath; +} diff --git a/MiscFramework/Library/Smm/EfiSmmDriverLib/debug.c b/MiscFramework/Library/Smm/EfiSmmDriverLib/debug.c new file mode 100644 index 0000000..842f3ab --- /dev/null +++ b/MiscFramework/Library/Smm/EfiSmmDriverLib/debug.c @@ -0,0 +1,169 @@ +/*++ + This file contains 'Framework Code' and is licensed as such + under the terms of your license agreement with Intel or your + vendor. This file may not be modified, except as allowed by + additional terms of your license agreement. +--*/ +/*++ + +Copyright (c) 1999 - 2002 Intel Corporation. All rights reserved +This software and associated documentation (if any) is furnished +under a license and may only be used or copied in accordance +with the terms of the license. Except as permitted by such +license, no part of this software or documentation may be +reproduced, stored in a retrieval system, or transmitted in any +form or by any means without the express written consent of +Intel Corporation. + + +Module Name: + + Debug.c + +Abstract: + + Support for Debug primatives. + +--*/ + +#include "Tiano.h" +#include "EfiCommonLib.h" +#include "EfiSmmDriverLib.h" +#include EFI_GUID_DEFINITION (StatusCodeCallerId) +#include EFI_GUID_DEFINITION (StatusCodeDataTypeId) + +#define EFI_STATUS_CODE_DATA_MAX_SIZE64 (EFI_STATUS_CODE_DATA_MAX_SIZE / 8) + +VOID +EfiDebugAssert ( + IN CHAR8 *FileName, + IN INTN LineNumber, + IN CHAR8 *Description + ) +/*++ + +Routine Description: + + Worker function for ASSERT (). If Error Logging hub is loaded log ASSERT + information. If Error Logging hub is not loaded DEADLOOP (). + +Arguments: + + FileName - File name of failing routine. + + LineNumber - Line number of failing ASSERT(). + + Description - Description, usually the assertion, + +Returns: + + None + +--*/ +{ + + UINT64 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE64]; + + if (mSmmDebug != NULL) { + EfiDebugAssertWorker (FileName, LineNumber, Description, sizeof (Buffer), Buffer); + mSmmDebug->ReportStatusCode ( + mSmmDebug, + (EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED), + (EFI_SOFTWARE_SMM_DRIVER | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE), + 0, + &gEfiCallerIdGuid, + (EFI_STATUS_CODE_DATA *) Buffer + ); + } + // + // don't return, this is an assert. + // + EFI_DEADLOOP (); +} + +VOID +EfiDebugVPrint ( + IN UINTN ErrorLevel, + IN CHAR8 *Format, + IN VA_LIST Marker + ) +/*++ + +Routine Description: + + Worker function for DEBUG(). If Error Logging hub is loaded log ASSERT + information. If Error Logging hub is not loaded do nothing. + +Arguments: + + ErrorLevel - If error level is set do the debug print. + + Format - String to use for the print, followed by Print arguments. + + Marker - VarArgs + +Returns: + + None + +--*/ +{ + UINT64 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE64]; + + if (!(gErrorLevel & ErrorLevel)) { + return ; + } + + EfiDebugVPrintWorker (ErrorLevel, Format, Marker, sizeof (Buffer), Buffer); + + if (mSmmDebug != NULL) { + mSmmDebug->ReportStatusCode ( + mSmmDebug, + EFI_DEBUG_CODE, + (EFI_SOFTWARE_SMM_DRIVER | EFI_DC_UNSPECIFIED), + 0, + &gEfiCallerIdGuid, + (EFI_STATUS_CODE_DATA *) Buffer + ); + } + + return ; +} + +VOID +EfiDebugPrint ( + IN UINTN ErrorLevel, + IN CHAR8 *Format, + ... + ) +/*++ + +Routine Description: + + Worker function for DEBUG(). If Error Logging hub is loaded log ASSERT + information. If Error Logging hub is not loaded do nothing. + + We use UINT64 buffers due to IPF alignment concerns. + +Arguments: + + ErrorLevel - If error level is set do the debug print. + + Format - String to use for the print, followed by Print arguments. + + ... - VAR args for Format + +Returns: + + None + +--*/ +{ + VA_LIST Marker; + + VA_START (Marker, Format); + + EfiDebugVPrint (ErrorLevel, Format, Marker); + + VA_END (Marker); +} -- cgit v1.2.3