13af9b38827fff65fc7e303eec07448b6d04d5f0fxli/** @file
23af9b38827fff65fc7e303eec07448b6d04d5f0fxli  Internal include file for Status Code Handler Driver.
33af9b38827fff65fc7e303eec07448b6d04d5f0fxli
490eaa3c1e022e2b676da65cb41aa66136a18b4ealzeng  Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
5e5eed7d3641d71d7ea539e5379ea9c6a5cd97004hhtian  This program and the accompanying materials
63af9b38827fff65fc7e303eec07448b6d04d5f0fxli  are licensed and made available under the terms and conditions of the BSD License
73af9b38827fff65fc7e303eec07448b6d04d5f0fxli  which accompanies this distribution.  The full text of the license may be found at
83af9b38827fff65fc7e303eec07448b6d04d5f0fxli  http://opensource.org/licenses/bsd-license.php
93af9b38827fff65fc7e303eec07448b6d04d5f0fxli
103af9b38827fff65fc7e303eec07448b6d04d5f0fxli  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
113af9b38827fff65fc7e303eec07448b6d04d5f0fxli  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
123af9b38827fff65fc7e303eec07448b6d04d5f0fxli
133af9b38827fff65fc7e303eec07448b6d04d5f0fxli**/
143af9b38827fff65fc7e303eec07448b6d04d5f0fxli
153af9b38827fff65fc7e303eec07448b6d04d5f0fxli#ifndef __STATUS_CODE_HANDLER_SMM_H__
163af9b38827fff65fc7e303eec07448b6d04d5f0fxli#define __STATUS_CODE_HANDLER_SMM_H__
173af9b38827fff65fc7e303eec07448b6d04d5f0fxli
183af9b38827fff65fc7e303eec07448b6d04d5f0fxli#include <Protocol/SmmReportStatusCodeHandler.h>
193af9b38827fff65fc7e303eec07448b6d04d5f0fxli
203af9b38827fff65fc7e303eec07448b6d04d5f0fxli#include <Guid/MemoryStatusCodeRecord.h>
213af9b38827fff65fc7e303eec07448b6d04d5f0fxli#include <Guid/StatusCodeDataTypeId.h>
223af9b38827fff65fc7e303eec07448b6d04d5f0fxli#include <Guid/StatusCodeDataTypeDebug.h>
233af9b38827fff65fc7e303eec07448b6d04d5f0fxli
243af9b38827fff65fc7e303eec07448b6d04d5f0fxli#include <Library/SynchronizationLib.h>
253af9b38827fff65fc7e303eec07448b6d04d5f0fxli#include <Library/DebugLib.h>
263af9b38827fff65fc7e303eec07448b6d04d5f0fxli#include <Library/ReportStatusCodeLib.h>
273af9b38827fff65fc7e303eec07448b6d04d5f0fxli#include <Library/PrintLib.h>
283af9b38827fff65fc7e303eec07448b6d04d5f0fxli#include <Library/PcdLib.h>
293af9b38827fff65fc7e303eec07448b6d04d5f0fxli#include <Library/UefiDriverEntryPoint.h>
303af9b38827fff65fc7e303eec07448b6d04d5f0fxli#include <Library/SmmServicesTableLib.h>
313af9b38827fff65fc7e303eec07448b6d04d5f0fxli#include <Library/SerialPortLib.h>
32d3308de7f5f477508fcd742d1a6287dc23b77ecamdkinney#include <Library/MemoryAllocationLib.h>
3396a2516355feae4bf10009fe28722c689af7a3e6xli#include <Library/BaseMemoryLib.h>
343af9b38827fff65fc7e303eec07448b6d04d5f0fxli
353af9b38827fff65fc7e303eec07448b6d04d5f0fxli//
3690eaa3c1e022e2b676da65cb41aa66136a18b4ealzeng// Define the maximum message length
3790eaa3c1e022e2b676da65cb41aa66136a18b4ealzeng//
3890eaa3c1e022e2b676da65cb41aa66136a18b4ealzeng#define MAX_DEBUG_MESSAGE_LENGTH 0x100
3990eaa3c1e022e2b676da65cb41aa66136a18b4ealzeng
4090eaa3c1e022e2b676da65cb41aa66136a18b4ealzeng//
413af9b38827fff65fc7e303eec07448b6d04d5f0fxli// Runtime memory status code worker definition
423af9b38827fff65fc7e303eec07448b6d04d5f0fxli//
433af9b38827fff65fc7e303eec07448b6d04d5f0fxlitypedef struct {
443af9b38827fff65fc7e303eec07448b6d04d5f0fxli  UINT32   RecordIndex;
453af9b38827fff65fc7e303eec07448b6d04d5f0fxli  UINT32   NumberOfRecords;
463af9b38827fff65fc7e303eec07448b6d04d5f0fxli  UINT32   MaxRecordsNumber;
473af9b38827fff65fc7e303eec07448b6d04d5f0fxli} RUNTIME_MEMORY_STATUSCODE_HEADER;
483af9b38827fff65fc7e303eec07448b6d04d5f0fxli
493af9b38827fff65fc7e303eec07448b6d04d5f0fxliextern RUNTIME_MEMORY_STATUSCODE_HEADER  *mSmmMemoryStatusCodeTable;
503af9b38827fff65fc7e303eec07448b6d04d5f0fxli
513af9b38827fff65fc7e303eec07448b6d04d5f0fxli/**
523af9b38827fff65fc7e303eec07448b6d04d5f0fxli  Locates Serial I/O Protocol as initialization for serial status code worker.
533af9b38827fff65fc7e303eec07448b6d04d5f0fxli
543af9b38827fff65fc7e303eec07448b6d04d5f0fxli  @retval EFI_SUCCESS  Serial I/O Protocol is successfully located.
553af9b38827fff65fc7e303eec07448b6d04d5f0fxli
563af9b38827fff65fc7e303eec07448b6d04d5f0fxli**/
573af9b38827fff65fc7e303eec07448b6d04d5f0fxliEFI_STATUS
583af9b38827fff65fc7e303eec07448b6d04d5f0fxliEfiSerialStatusCodeInitializeWorker (
593af9b38827fff65fc7e303eec07448b6d04d5f0fxli  VOID
603af9b38827fff65fc7e303eec07448b6d04d5f0fxli  );
613af9b38827fff65fc7e303eec07448b6d04d5f0fxli
623af9b38827fff65fc7e303eec07448b6d04d5f0fxli
633af9b38827fff65fc7e303eec07448b6d04d5f0fxli/**
643af9b38827fff65fc7e303eec07448b6d04d5f0fxli  Convert status code value and extended data to readable ASCII string, send string to serial I/O device.
653af9b38827fff65fc7e303eec07448b6d04d5f0fxli
663af9b38827fff65fc7e303eec07448b6d04d5f0fxli  @param  CodeType         Indicates the type of status code being reported.
673af9b38827fff65fc7e303eec07448b6d04d5f0fxli  @param  Value            Describes the current status of a hardware or software entity.
683af9b38827fff65fc7e303eec07448b6d04d5f0fxli                           This included information about the class and subclass that is used to
693af9b38827fff65fc7e303eec07448b6d04d5f0fxli                           classify the entity as well as an operation.
703af9b38827fff65fc7e303eec07448b6d04d5f0fxli  @param  Instance         The enumeration of a hardware or software entity within
713af9b38827fff65fc7e303eec07448b6d04d5f0fxli                           the system. Valid instance numbers start with 1.
723af9b38827fff65fc7e303eec07448b6d04d5f0fxli  @param  CallerId         This optional parameter may be used to identify the caller.
733af9b38827fff65fc7e303eec07448b6d04d5f0fxli                           This parameter allows the status code driver to apply different rules to
743af9b38827fff65fc7e303eec07448b6d04d5f0fxli                           different callers.
753af9b38827fff65fc7e303eec07448b6d04d5f0fxli  @param  Data             This optional parameter may be used to pass additional data.
763af9b38827fff65fc7e303eec07448b6d04d5f0fxli
773af9b38827fff65fc7e303eec07448b6d04d5f0fxli  @retval EFI_SUCCESS      Status code reported to serial I/O successfully.
783af9b38827fff65fc7e303eec07448b6d04d5f0fxli  @retval EFI_DEVICE_ERROR EFI serial device cannot work after ExitBootService() is called.
793af9b38827fff65fc7e303eec07448b6d04d5f0fxli  @retval EFI_DEVICE_ERROR EFI serial device cannot work with TPL higher than TPL_CALLBACK.
803af9b38827fff65fc7e303eec07448b6d04d5f0fxli
813af9b38827fff65fc7e303eec07448b6d04d5f0fxli**/
823af9b38827fff65fc7e303eec07448b6d04d5f0fxliEFI_STATUS
83e798cd87ca9a3a30c4cea50c5f5de84e10a8bc5ageekboyEFIAPI
843af9b38827fff65fc7e303eec07448b6d04d5f0fxliSerialStatusCodeReportWorker (
853af9b38827fff65fc7e303eec07448b6d04d5f0fxli  IN EFI_STATUS_CODE_TYPE     CodeType,
863af9b38827fff65fc7e303eec07448b6d04d5f0fxli  IN EFI_STATUS_CODE_VALUE    Value,
873af9b38827fff65fc7e303eec07448b6d04d5f0fxli  IN UINT32                   Instance,
883af9b38827fff65fc7e303eec07448b6d04d5f0fxli  IN EFI_GUID                 *CallerId,
893af9b38827fff65fc7e303eec07448b6d04d5f0fxli  IN EFI_STATUS_CODE_DATA     *Data OPTIONAL
903af9b38827fff65fc7e303eec07448b6d04d5f0fxli  );
913af9b38827fff65fc7e303eec07448b6d04d5f0fxli
923af9b38827fff65fc7e303eec07448b6d04d5f0fxli/**
933af9b38827fff65fc7e303eec07448b6d04d5f0fxli  Initialize runtime memory status code table as initialization for runtime memory status code worker
943af9b38827fff65fc7e303eec07448b6d04d5f0fxli
953af9b38827fff65fc7e303eec07448b6d04d5f0fxli  @retval EFI_SUCCESS  Runtime memory status code table successfully initialized.
963af9b38827fff65fc7e303eec07448b6d04d5f0fxli
973af9b38827fff65fc7e303eec07448b6d04d5f0fxli**/
983af9b38827fff65fc7e303eec07448b6d04d5f0fxliEFI_STATUS
993af9b38827fff65fc7e303eec07448b6d04d5f0fxliMemoryStatusCodeInitializeWorker (
1003af9b38827fff65fc7e303eec07448b6d04d5f0fxli  VOID
1013af9b38827fff65fc7e303eec07448b6d04d5f0fxli  );
1023af9b38827fff65fc7e303eec07448b6d04d5f0fxli
1033af9b38827fff65fc7e303eec07448b6d04d5f0fxli/**
1043af9b38827fff65fc7e303eec07448b6d04d5f0fxli  Report status code into runtime memory. If the runtime pool is full, roll back to the
1053af9b38827fff65fc7e303eec07448b6d04d5f0fxli  first record and overwrite it.
1063af9b38827fff65fc7e303eec07448b6d04d5f0fxli
1073af9b38827fff65fc7e303eec07448b6d04d5f0fxli  @param  CodeType                Indicates the type of status code being reported.
1083af9b38827fff65fc7e303eec07448b6d04d5f0fxli  @param  Value                   Describes the current status of a hardware or software entity.
1093af9b38827fff65fc7e303eec07448b6d04d5f0fxli                                  This included information about the class and subclass that is used to
1103af9b38827fff65fc7e303eec07448b6d04d5f0fxli                                  classify the entity as well as an operation.
1113af9b38827fff65fc7e303eec07448b6d04d5f0fxli  @param  Instance                The enumeration of a hardware or software entity within
1123af9b38827fff65fc7e303eec07448b6d04d5f0fxli                                  the system. Valid instance numbers start with 1.
1133af9b38827fff65fc7e303eec07448b6d04d5f0fxli  @param  CallerId                This optional parameter may be used to identify the caller.
1143af9b38827fff65fc7e303eec07448b6d04d5f0fxli                                  This parameter allows the status code driver to apply different rules to
1153af9b38827fff65fc7e303eec07448b6d04d5f0fxli                                  different callers.
1163af9b38827fff65fc7e303eec07448b6d04d5f0fxli  @param  Data                    This optional parameter may be used to pass additional data.
1173af9b38827fff65fc7e303eec07448b6d04d5f0fxli
1183af9b38827fff65fc7e303eec07448b6d04d5f0fxli  @retval EFI_SUCCESS             Status code successfully recorded in runtime memory status code table.
1193af9b38827fff65fc7e303eec07448b6d04d5f0fxli
1203af9b38827fff65fc7e303eec07448b6d04d5f0fxli**/
1213af9b38827fff65fc7e303eec07448b6d04d5f0fxliEFI_STATUS
122e798cd87ca9a3a30c4cea50c5f5de84e10a8bc5ageekboyEFIAPI
1233af9b38827fff65fc7e303eec07448b6d04d5f0fxliMemoryStatusCodeReportWorker (
1243af9b38827fff65fc7e303eec07448b6d04d5f0fxli  IN EFI_STATUS_CODE_TYPE               CodeType,
1253af9b38827fff65fc7e303eec07448b6d04d5f0fxli  IN EFI_STATUS_CODE_VALUE              Value,
1263af9b38827fff65fc7e303eec07448b6d04d5f0fxli  IN UINT32                             Instance,
1273af9b38827fff65fc7e303eec07448b6d04d5f0fxli  IN EFI_GUID                           *CallerId,
1283af9b38827fff65fc7e303eec07448b6d04d5f0fxli  IN EFI_STATUS_CODE_DATA               *Data OPTIONAL
1293af9b38827fff65fc7e303eec07448b6d04d5f0fxli  );
1303af9b38827fff65fc7e303eec07448b6d04d5f0fxli
1313af9b38827fff65fc7e303eec07448b6d04d5f0fxli#endif
132