diff options
author | davidhuang <davidhuang@6f19259b-4bc3-4df7-8a09-765794883524> | 2009-12-23 06:52:37 +0000 |
---|---|---|
committer | davidhuang <davidhuang@6f19259b-4bc3-4df7-8a09-765794883524> | 2009-12-23 06:52:37 +0000 |
commit | ce00a23274a1599495134e1fb44a8de3e95b8d27 (patch) | |
tree | 4d0bcdaa95242e4e879dc1b89078ad9b560ee09f /IntelFrameworkModulePkg/Universal | |
parent | 4fd13cd57d83b23011ed017e6410de1f30c04694 (diff) | |
download | edk2-ce00a23274a1599495134e1fb44a8de3e95b8d27.tar.gz edk2-ce00a23274a1599495134e1fb44a8de3e95b8d27.tar.bz2 edk2-ce00a23274a1599495134e1fb44a8de3e95b8d27.zip |
PI 1.1 SMM Feature Check-in
1. Add SmmReportStatusCodeLib library instance.
2. Add StatusCodeHandler Smm part
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9593 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'IntelFrameworkModulePkg/Universal')
5 files changed, 541 insertions, 0 deletions
diff --git a/IntelFrameworkModulePkg/Universal/StatusCodeHandler/Smm/MemoryStatusCodeWorker.c b/IntelFrameworkModulePkg/Universal/StatusCodeHandler/Smm/MemoryStatusCodeWorker.c new file mode 100644 index 0000000000..5672ebcd0c --- /dev/null +++ b/IntelFrameworkModulePkg/Universal/StatusCodeHandler/Smm/MemoryStatusCodeWorker.c @@ -0,0 +1,114 @@ +/** @file
+ Runtime memory status code worker.
+
+ Copyright (c) 2006 - 2009, Intel Corporation
+ All rights reserved. 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 "StatusCodeHandlerSmm.h"
+
+RUNTIME_MEMORY_STATUSCODE_HEADER *mSmmMemoryStatusCodeTable;
+
+/**
+ Initialize SMM memory status code table as initialization for memory status code worker
+
+ @retval EFI_SUCCESS SMM memory status code table successfully initialized.
+
+**/
+EFI_STATUS
+MemoryStatusCodeInitializeWorker (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ //
+ // Allocate SMM memory status code pool.
+ //
+ Status = gSmst->SmmAllocatePool (
+ EfiRuntimeServicesData,
+ sizeof (RUNTIME_MEMORY_STATUSCODE_HEADER) + PcdGet16 (PcdStatusCodeMemorySize) * 1024,
+ (VOID**)&mSmmMemoryStatusCodeTable
+ );
+
+ ASSERT_EFI_ERROR(Status);
+ ASSERT (mSmmMemoryStatusCodeTable != NULL);
+
+ mSmmMemoryStatusCodeTable->RecordIndex = 0;
+ mSmmMemoryStatusCodeTable->NumberOfRecords = 0;
+ mSmmMemoryStatusCodeTable->MaxRecordsNumber =
+ (PcdGet16 (PcdStatusCodeMemorySize) * 1024) / sizeof (MEMORY_STATUSCODE_RECORD);
+
+ return EFI_SUCCESS;
+}
+
+
+/**
+ Report status code into runtime memory. If the runtime pool is full, roll back to the
+ first record and overwrite it.
+
+ @param CodeType Indicates the type of status code being reported.
+ @param Value Describes the current status of a hardware or software entity.
+ This included information about the class and subclass that is used to
+ classify the entity as well as an operation.
+ @param Instance The enumeration of a hardware or software entity within
+ the system. Valid instance numbers start with 1.
+ @param CallerId This optional parameter may be used to identify the caller.
+ This parameter allows the status code driver to apply different rules to
+ different callers.
+ @param Data This optional parameter may be used to pass additional data.
+
+ @retval EFI_SUCCESS Status code successfully recorded in runtime memory status code table.
+
+**/
+EFI_STATUS
+MemoryStatusCodeReportWorker (
+ IN EFI_STATUS_CODE_TYPE CodeType,
+ IN EFI_STATUS_CODE_VALUE Value,
+ IN UINT32 Instance,
+ IN EFI_GUID *CallerId,
+ IN EFI_STATUS_CODE_DATA *Data OPTIONAL
+ )
+{
+ MEMORY_STATUSCODE_RECORD *Record;
+
+ //
+ // Locate current record buffer.
+ //
+ Record = (MEMORY_STATUSCODE_RECORD *) (mSmmMemoryStatusCodeTable + 1);
+ Record = &Record[mSmmMemoryStatusCodeTable->RecordIndex++];
+
+ //
+ // Save status code.
+ //
+ Record->CodeType = CodeType;
+ Record->Value = Value;
+ Record->Instance = Instance;
+
+ //
+ // If record index equals to max record number, then wrap around record index to zero.
+ //
+ // The reader of status code should compare the number of records with max records number,
+ // If it is equal to or larger than the max number, then the wrap-around had happened,
+ // so the first record is pointed by record index.
+ // If it is less then max number, index of the first record is zero.
+ //
+ mSmmMemoryStatusCodeTable->NumberOfRecords++;
+ if (mSmmMemoryStatusCodeTable->RecordIndex == mSmmMemoryStatusCodeTable->MaxRecordsNumber) {
+ //
+ // Wrap around record index.
+ //
+ mSmmMemoryStatusCodeTable->RecordIndex = 0;
+ }
+
+ return EFI_SUCCESS;
+}
+
+
+
diff --git a/IntelFrameworkModulePkg/Universal/StatusCodeHandler/Smm/SerialStatusCodeWorker.c b/IntelFrameworkModulePkg/Universal/StatusCodeHandler/Smm/SerialStatusCodeWorker.c new file mode 100644 index 0000000000..3b408a2410 --- /dev/null +++ b/IntelFrameworkModulePkg/Universal/StatusCodeHandler/Smm/SerialStatusCodeWorker.c @@ -0,0 +1,148 @@ +/** @file
+ Serial I/O status code reporting worker.
+
+ Copyright (c) 2009, Intel Corporation
+ All rights reserved. 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 "StatusCodeHandlerSmm.h"
+
+/**
+ Convert status code value and extended data to readable ASCII string, send string to serial I/O device.
+
+ @param CodeType Indicates the type of status code being reported.
+ @param Value Describes the current status of a hardware or software entity.
+ This included information about the class and subclass that is used to
+ classify the entity as well as an operation.
+ @param Instance The enumeration of a hardware or software entity within
+ the system. Valid instance numbers start with 1.
+ @param CallerId This optional parameter may be used to identify the caller.
+ This parameter allows the status code driver to apply different rules to
+ different callers.
+ @param Data This optional parameter may be used to pass additional data.
+
+ @retval EFI_SUCCESS Status code reported to serial I/O successfully.
+ @retval EFI_DEVICE_ERROR EFI serial device cannot work after ExitBootService() is called.
+ @retval EFI_DEVICE_ERROR EFI serial device cannot work with TPL higher than TPL_CALLBACK.
+
+**/
+EFI_STATUS
+SerialStatusCodeReportWorker (
+ IN EFI_STATUS_CODE_TYPE CodeType,
+ IN EFI_STATUS_CODE_VALUE Value,
+ IN UINT32 Instance,
+ IN EFI_GUID *CallerId,
+ IN EFI_STATUS_CODE_DATA *Data OPTIONAL
+ )
+{
+ CHAR8 *Filename;
+ CHAR8 *Description;
+ CHAR8 *Format;
+ CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];
+ UINT32 ErrorLevel;
+ UINT32 LineNumber;
+ UINTN CharCount;
+ BASE_LIST Marker;
+
+ Buffer[0] = '\0';
+
+ if (Data != NULL &&
+ ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {
+ //
+ // Print ASSERT() information into output buffer.
+ //
+ CharCount = AsciiSPrint (
+ Buffer,
+ sizeof (Buffer),
+ "\n\rDXE_ASSERT!: %a (%d): %a\n\r",
+ Filename,
+ LineNumber,
+ Description
+ );
+ } else if (Data != NULL &&
+ ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {
+ //
+ // Print DEBUG() information into output buffer.
+ //
+ CharCount = AsciiBSPrint (
+ Buffer,
+ sizeof (Buffer),
+ Format,
+ Marker
+ );
+ } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
+ //
+ // Print ERROR information into output buffer.
+ //
+ CharCount = AsciiSPrint (
+ Buffer,
+ sizeof (Buffer),
+ "ERROR: C%x:V%x I%x",
+ CodeType,
+ Value,
+ Instance
+ );
+
+ if (CallerId != NULL) {
+ CharCount += AsciiSPrint (
+ &Buffer[CharCount - 1],
+ (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),
+ " %g",
+ CallerId
+ );
+ }
+
+ if (Data != NULL) {
+ CharCount += AsciiSPrint (
+ &Buffer[CharCount - 1],
+ (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),
+ " %x",
+ Data
+ );
+ }
+
+ CharCount += AsciiSPrint (
+ &Buffer[CharCount - 1],
+ (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),
+ "\n\r"
+ );
+ } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
+ //
+ // Print PROGRESS information into output buffer.
+ //
+ CharCount = AsciiSPrint (
+ Buffer,
+ sizeof (Buffer),
+ "PROGRESS CODE: V%x I%x\n\r",
+ Value,
+ Instance
+ );
+ } else {
+ //
+ // Code type is not defined.
+ //
+ CharCount = AsciiSPrint (
+ Buffer,
+ sizeof (Buffer),
+ "Undefined: C%x:V%x I%x\n\r",
+ CodeType,
+ Value,
+ Instance
+ );
+ }
+
+ //
+ // Call SerialPort Lib function to do print.
+ //
+ SerialPortWrite ((UINT8 *) Buffer, CharCount);
+
+ return EFI_SUCCESS;
+}
+
diff --git a/IntelFrameworkModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.c b/IntelFrameworkModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.c new file mode 100644 index 0000000000..fc6c7e9a5a --- /dev/null +++ b/IntelFrameworkModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.c @@ -0,0 +1,90 @@ +/** @file
+ Status Code Handler Driver which produces general handlers and hook them
+ onto the SMM status code router.
+
+ Copyright (c) 2009, Intel Corporation
+ All rights reserved. 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 "StatusCodeHandlerSmm.h"
+
+EFI_SMM_RSC_HANDLER_PROTOCOL *mRscHandlerProtocol = NULL;
+
+
+/**
+ Dispatch initialization request to sub status code devices based on
+ customized feature flags.
+
+**/
+VOID
+InitializationDispatcherWorker (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+
+ //
+ // If enable UseSerial, then initialize serial port.
+ // if enable UseRuntimeMemory, then initialize runtime memory status code worker.
+ //
+ if (FeaturePcdGet (PcdStatusCodeUseSerial)) {
+ //
+ // Call Serial Port Lib API to initialize serial port.
+ //
+ Status = SerialPortInitialize ();
+ ASSERT_EFI_ERROR (Status);
+ }
+ if (FeaturePcdGet (PcdStatusCodeUseMemory)) {
+ Status = MemoryStatusCodeInitializeWorker ();
+ ASSERT_EFI_ERROR (Status);
+ }
+}
+
+/**
+ Entry point of SMM Status Code Driver.
+
+ This function is the entry point of SMM Status Code Driver.
+
+ @param ImageHandle The firmware allocated handle for the EFI image.
+ @param SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS The entry point is executed successfully.
+
+**/
+EFI_STATUS
+EFIAPI
+StatusCodeHandlerSmmEntry (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+
+ Status = gSmst->SmmLocateProtocol (
+ &gEfiSmmRscHandlerProtocolGuid,
+ NULL,
+ (VOID **) &mRscHandlerProtocol
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ //
+ // Dispatch initialization request to supported devices
+ //
+ InitializationDispatcherWorker ();
+
+ if (FeaturePcdGet (PcdStatusCodeUseSerial)) {
+ mRscHandlerProtocol->Register (SerialStatusCodeReportWorker);
+ }
+ if (FeaturePcdGet (PcdStatusCodeUseMemory)) {
+ mRscHandlerProtocol->Register (MemoryStatusCodeReportWorker);
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/IntelFrameworkModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.h b/IntelFrameworkModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.h new file mode 100644 index 0000000000..3127a8cd13 --- /dev/null +++ b/IntelFrameworkModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.h @@ -0,0 +1,122 @@ +/** @file
+ Internal include file for Status Code Handler Driver.
+
+ Copyright (c) 2009, Intel Corporation
+ All rights reserved. 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 __STATUS_CODE_HANDLER_SMM_H__
+#define __STATUS_CODE_HANDLER_SMM_H__
+
+#include <Protocol/SmmReportStatusCodeHandler.h>
+
+#include <Guid/MemoryStatusCodeRecord.h>
+#include <Guid/StatusCodeDataTypeId.h>
+#include <Guid/StatusCodeDataTypeDebug.h>
+
+#include <Library/SynchronizationLib.h>
+#include <Library/DebugLib.h>
+#include <Library/ReportStatusCodeLib.h>
+#include <Library/PrintLib.h>
+#include <Library/PcdLib.h>
+#include <Library/UefiDriverEntryPoint.h>
+#include <Library/SmmServicesTableLib.h>
+#include <Library/SerialPortLib.h>
+
+//
+// Runtime memory status code worker definition
+//
+typedef struct {
+ UINT32 RecordIndex;
+ UINT32 NumberOfRecords;
+ UINT32 MaxRecordsNumber;
+} RUNTIME_MEMORY_STATUSCODE_HEADER;
+
+extern RUNTIME_MEMORY_STATUSCODE_HEADER *mSmmMemoryStatusCodeTable;
+
+/**
+ Locates Serial I/O Protocol as initialization for serial status code worker.
+
+ @retval EFI_SUCCESS Serial I/O Protocol is successfully located.
+
+**/
+EFI_STATUS
+EfiSerialStatusCodeInitializeWorker (
+ VOID
+ );
+
+
+/**
+ Convert status code value and extended data to readable ASCII string, send string to serial I/O device.
+
+ @param CodeType Indicates the type of status code being reported.
+ @param Value Describes the current status of a hardware or software entity.
+ This included information about the class and subclass that is used to
+ classify the entity as well as an operation.
+ @param Instance The enumeration of a hardware or software entity within
+ the system. Valid instance numbers start with 1.
+ @param CallerId This optional parameter may be used to identify the caller.
+ This parameter allows the status code driver to apply different rules to
+ different callers.
+ @param Data This optional parameter may be used to pass additional data.
+
+ @retval EFI_SUCCESS Status code reported to serial I/O successfully.
+ @retval EFI_DEVICE_ERROR EFI serial device cannot work after ExitBootService() is called.
+ @retval EFI_DEVICE_ERROR EFI serial device cannot work with TPL higher than TPL_CALLBACK.
+
+**/
+EFI_STATUS
+SerialStatusCodeReportWorker (
+ IN EFI_STATUS_CODE_TYPE CodeType,
+ IN EFI_STATUS_CODE_VALUE Value,
+ IN UINT32 Instance,
+ IN EFI_GUID *CallerId,
+ IN EFI_STATUS_CODE_DATA *Data OPTIONAL
+ );
+
+/**
+ Initialize runtime memory status code table as initialization for runtime memory status code worker
+
+ @retval EFI_SUCCESS Runtime memory status code table successfully initialized.
+
+**/
+EFI_STATUS
+MemoryStatusCodeInitializeWorker (
+ VOID
+ );
+
+/**
+ Report status code into runtime memory. If the runtime pool is full, roll back to the
+ first record and overwrite it.
+
+ @param CodeType Indicates the type of status code being reported.
+ @param Value Describes the current status of a hardware or software entity.
+ This included information about the class and subclass that is used to
+ classify the entity as well as an operation.
+ @param Instance The enumeration of a hardware or software entity within
+ the system. Valid instance numbers start with 1.
+ @param CallerId This optional parameter may be used to identify the caller.
+ This parameter allows the status code driver to apply different rules to
+ different callers.
+ @param Data This optional parameter may be used to pass additional data.
+
+ @retval EFI_SUCCESS Status code successfully recorded in runtime memory status code table.
+
+**/
+EFI_STATUS
+MemoryStatusCodeReportWorker (
+ IN EFI_STATUS_CODE_TYPE CodeType,
+ IN EFI_STATUS_CODE_VALUE Value,
+ IN UINT32 Instance,
+ IN EFI_GUID *CallerId,
+ IN EFI_STATUS_CODE_DATA *Data OPTIONAL
+ );
+
+#endif
diff --git a/IntelFrameworkModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf b/IntelFrameworkModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf new file mode 100644 index 0000000000..c886d5e4bf --- /dev/null +++ b/IntelFrameworkModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf @@ -0,0 +1,67 @@ +#/** @file
+# Status Code Handler Driver which produces general handlers and hook them
+# onto the SMM status code router.
+#
+# Copyright (c) 2009, Intel Corporation.
+#
+# All rights reserved. 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 = StatusCodeHandlerSmm
+ FILE_GUID = 79CD78D8-6EDC-4978-BD02-3299C387AB17
+ MODULE_TYPE = DXE_SMM_DRIVER
+ PI_SPECIFICATION_VERSION = 0x0001000A
+
+ ENTRY_POINT = StatusCodeHandlerSmmEntry
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources.common]
+ StatusCodeHandlerSmm.c
+ StatusCodeHandlerSmm.h
+ SerialStatusCodeWorker.c
+ MemoryStatusCodeWorker.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec
+
+[LibraryClasses]
+ SerialPortLib
+ SmmServicesTableLib
+ UefiDriverEntryPoint
+ PcdLib
+ PrintLib
+ ReportStatusCodeLib
+ DebugLib
+ SynchronizationLib
+
+[Guids]
+ gEfiStatusCodeDataTypeDebugGuid ## SOMETIMES_CONSUMES (Needed if Data Hub is supported for status code.)
+ gMemoryStatusCodeRecordGuid ## CONSUMES ## HOB
+
+[Protocols]
+ gEfiSmmRscHandlerProtocolGuid ## CONSUMES
+
+[FeaturePcd]
+ gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeUseMemory
+ gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeUseSerial
+
+[Pcd]
+ gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeMemorySize |128| PcdStatusCodeUseMemory
+
+[Depex]
+ gEfiSmmRscHandlerProtocolGuid
|