diff options
author | raywu <raywu0301@gmail.com> | 2018-06-15 00:00:50 +0800 |
---|---|---|
committer | raywu <raywu0301@gmail.com> | 2018-06-15 00:00:50 +0800 |
commit | b7c51c9cf4864df6aabb99a1ae843becd577237c (patch) | |
tree | eebe9b0d0ca03062955223097e57da84dd618b9a /MiscFramework/Library/Smm/EfiSmmDriverLib | |
download | zprj-master.tar.xz |
Diffstat (limited to 'MiscFramework/Library/Smm/EfiSmmDriverLib')
6 files changed, 576 insertions, 0 deletions
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 @@ +<component> + name = "EfiSmmDriverLib" + category = ModulePart + LocalRoot = "MiscFramework\Library\Smm\EfiSmmDriverLib" + RefName = "EfiSmmDriverLib" +[files] +"EfiSmmDriverLib.sdl" +"EfiSmmDriverLib.mak" +"SmmDriverLib.c" +"LibGlobals.c" +"debug.c" +<endComponent> 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. +# +# +#********************************************************************** +#<AMI_FHDR_START> +# +# Name: EfiSmmDriverLib.mak +# +# Description: +# +#<AMI_FHDR_END> +#********************************************************************** +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); +} |